5 ms·
On the 2600, you can use a fourth register, the stack pointer. The 2600 as a machine has no interrupts, so if a section of code doesn't push/pop/call anything,
by T-hawk 6y ago
On the 2600, you can use a fourth register, the stack pointer. The 2600 as a machine has no interrupts, so if a section of code doesn't push/pop/call anything, stack memory is never touched and you can do whatever you want with the stack pointer register.
There's more tricks with the stack pointer on this machine too. Set it to point to the top of a sequence of video registers, and then you can rapidly write values to that sequence of registers just by issuing push instructions, which are faster than load/store/decrement!
- EvanAnderson 6y agoThat stack trick is ingenious. I've done next to no 2600 programming but I've done enough 6502 to appreciate that one. I am remound of the perennial HN favorite: http://blog.moertel.com/posts/2013-12-14-great-old-timey-game-programming-hack.html http://blog.moertel.com/posts/2013-12-14-great-old-timey-gam...
- T-hawk 6y agoI'll give you more detail of one way to use that trick then. The single-bit missile and ball objects are turned on or off by writing to their activation register, controlled by bit 1 of that register. Why bit 1, why not 0 or 7? Because that lines up with the zero flag in the 6502's flags register. What you do is set the stack pointer to that video register, compare on the object's Y-coordinate, then push the flags register to turn the object on or off! So the code needs no shifts or conditions or branches. It's even cycle invariant which is a great property on this machine. The video hardware was deliberately designed to do this (by chip legend Jay Miner), and Combat's code does. Also, the registers for the two missiles and the ball are adjacent, so you can do this trick to all of them in succession without resetting the stack pointer.
- EvanAnderson 6y agoThanks for sharing that. That's a neat piece of trivia. I'm already very impressed by Jay Miner's work, and this just adds to that. It makes sense that the TIA would be designed hand-in-glove for the 6507. BTW - I saw in your other comments that you wrote INV+. This counts as my little brush with "celebrity" for the day. >smile<
- pwg 6y ago> Set it to point to the top of a sequence of video registers, and then you can rapidly write values to that sequence of registers just by issuing push instructions How did that work on the 2600? The 6502's stack pointer is also only 8-bits, just like the other registers, and hardwired to use page 1 as the upper byte of the ultimate 16-bit stack address. Were the video registers mapped into the page 1 address zone?
- T-hawk 6y agoYes. It's really that everything exists in both pages. The video registers exist at 0x00 through 0x3F and the RAM is at 0x80 through 0xFF, both in zero-page for the fast access instructions and in page 1 for the stack pointer. It's not so much a mapping as a lack of mapping. The hardware simply doesn't decode address line 8. So accessing 0x002F and 0x012F are the same video register for example. If you push something to 0x01FF, you can read it from 0x00FF. There are more duplications within the address space as well. Address lines 13 and above don't exist in hardware on the 2600, so 0x20FF and 0x40FF and 0x60FF etc also access the same thing. The video registers from 0x00 through 0x3F are also duplicated from 0x40 through 0x7F, by not decoding address line 6 either. The important one is address line 12, which enables the cartridge ROM instead of the video/RAM; in fact that line is wired directly to the chip-enable pin on the cartridge slot.