Tetris inner loop MOS6510 / C=64
Introduction
Once in a century code can make me really proud. Especially when it is concise and no byte can be stripped off. The last time was in 1991. Major things still to come in the third millenium.
ldx #3 ; 2
draw lda chars,x ; 3
ldy blocks,x ; 3
sta (screenptr),y ; 2
colorit lda #color ; 2
sta (colorramptr),y ; 2
dex ; 2
bpl draw ; 2
... ; total: 18 bytes
blocks byte 0, 1, 41, 42, ...
chars byte 192, 238, 237, 192, ...
The lookups to chars and blocks are initialized with an offset to a block/rotation with SMC. The same for color.
; block in x (0..6) rotation in y (0..3)
calcblock stx colorit+1
tya
asl
asl
asl
asl
stx draw+1
tax
stx draw+4
...
; TODO this code needs testing and review

The screen matrix of the VIC-II has 25 lines of 40 characters each with a linear memory layout.
0 | 1 | 2 | 3 | 4 | 5 | ... |
40 | 41 | 42 | 43 | 44 | 45 | ... |
80 | 81 | 82 | 83 | 84 | 85 | ... |
120 | 121 | 122 | 123 | 124 | 125 | ... |
In C it would like this:
char *blocks = { 0, 1, 41, 42, ... };
char *chars = { 192, 238, 237, 192, ... };
for(int x_reg = 4; x_reg--;) {
char y_reg = blocks[x_reg];
screen[y_reg] = chars[x_reg];
color_ram[y_reg] = color;
}
Of course something will prove that at least one byte can be stripped off...