Chetiry Technical Notes
If you haven't seen it in the homebrew forum yet, I have posted a demo of a well-known Russian block game. The kernel manages 10 independently colored blocks at 8 pixels wide. (Well, 9 pixels for the far right one.)
Although there are only 4 COLUxx registers in the TIA, VBLANK offers an often overlooked 5th color (always black).
There are four colors available for the first 4 cells: background, playfield, player 0, and player 1. There are also three registers that can be pre-loaded with new colors. Then there is just barely enough time to load and store the last three colors, only because I am running code in RAM and using immediate addressing. Finally, to close off the edges of the play area, I turn VBLANK on and off.
In order to turn on VBLANK on the right side, I chose color values whose bit #1 were set. Then whatever value was saved to COLUPF on the right could also be saved to VBLANK. Turning it off on the left side was more of a challenge. I ended up using PHP, knowing that none of the color values loaded were zero, and bit 1 of the status register would be clear.
I also experimented with SHX to clear VBLANK. It has the advantage of using fewer cycles and freeing the SP, but the disadvantage is that it is a little understood illegal opcode that may not be entirely stable. So far, my tests with SHX have been successful, but I'll stick to PHP unless I find another use for the SP.
Currenlty it takes two scanlines to update the colors for the next row. I wish I could have done it in one line, but the block data has to be compressed to fit in 128 bytes of RAM, and I don't see any way to unpack and store 10 colors in only 76 cycles.
Without further ado, here is the code for coloring the blocks, part of an unwrapped loop.
;------------------------------------------ pla lda #<BackToRom1 sta SelfMod+22 lda color4; sta COLUP1; block 4 lda color1 sta COLUBK; block 1 lda color2 sta COLUPF; block 2 lda color3 sta COLUP0; block 3 lda color5 sleep 4 jmp SelfMod BackToRom1 ;-------------------------------------------- SelfModCode; byte count php; 0; turn off vblank sta COLUBK; 1 2; block 5 stx COLUPF; 3 4; block 6 sty COLUP0; 5 6; block 7 lda #COLOR0; 7 8 sta COLUP1; 9 10; block 8 lda #COLOR0; 11 12 sta COLUBK; 13 14; block 9 lda #COLOR0; 15 16 sta COLUPF; 17 18; block 10 sta VBLANK; 19 20 jmp BackToRom1; 21 22 23 ;-------------------------------------------
EDIT: Added a screenshot using DEC VBLANK. (I tried this on hardware too.)
EDIT2: Check out what INC VBLANK does!

10 Comments
Recommended Comments