Alternate Chess Kernel Solved
In my last attempt at a chess kernel with playfield graphics, I came up with a technique that would only work with about 27K of code. Since then I've made some advances that make a 4K kernel possible. One trick I developed was a new 32 pixel asymmetrical playfield configuration that takes four loads and six stores. (I believe it's new at least.)
The playfield remains transposed rather than reflected, but unlike before I load the same byte for the right PF0 and PF2 data. The high nybble goes to PF0 and the low nybble goes to PF2. The byte is stored to PF0 first, is AND'ed with #$0F and then stored to PF2. Setting X to #$0F and using the SAX instruction, which stores the value A & X, saves a couple cycles. I already had set X to white for my color changes, and by a fortunate coincidence white is #$0F. In additon, this value can be used to clear PF0 on the left side. This playfield configuration uses a few more cycles than the simple 32 pixel reflection, but the timing is more flexible and frees time to do all the color changes.
; X = #$0F (White) ; Y = #$00 (Black) ;dynamic_code; starts on cycle 3 pla ; load PF2 left side sta PF2-15,X ; left side. Use index to spend a cycle pla ; load PF0 and PF2 for right side stx PF0,Y ; clears PF0 on left side sta temp-15,X ; use indexed addressing to spend an extra cycle stx COLUPF ; color piece 1 sta PF0 ; right side stx COLUPF ; color piece 2 lda pf1_right ; load PF1 right side. The operand is inc'd below. stx COLUPF ; color piece 3 sta PF1 ; right side stx COLUPF ; color piece 4 stx COLUPF+64,Y ; color piece 5; COLUPF+64 mirrors COLUPF lda #$00 ; <-- temp is the address of the operand here. sty COLUPF+64-15,X; color piece 6 sax PF2 ; right side stx COLUPF ; color piece 7 stx COLUPF+64,Y ; color piece 8 pla ; load PF1 left side sta PF1 ; left side inc pf1_right_addr bne dynamic_code; last byte for pf1_right must be $ff brk
The RAM can be allocated as follows:
32 bytes to store the board position (1 nybble for each square)
42 bytes of self-modifying code (includes temp variable)
52 bytes for temporary storage of playfield data
2 bytes for everything else

29 Comments
Recommended Comments