So I've been given an assignment where we have to make a symbol using colored pixels using an 6502 assembly emulator. I don't quite understand how this grid works. Could someone please explain how this grid works and maybe give and example?
here is the link to the emulator: https://skilldrick.github.io/easy6502/#first-program
and the grid I'm to work with: https://i.sstatic.net/QuqPi.png
I think Michael's command is correct; avoiding use of 'x' and 'y' for potential register ambiguity reasons, address $0200 + (q*32) + p
contains the pixel at (p, q) for p and q in the range 0 to 31, and in each byte the low four bits determine the pixel colour.
So e.g. $0200
is the pixel in the top left, $0201
is the pixel one to the right of the top left, and $0220
is the pixel one below the top left.
In 6502 terms one possible straightforward implementation of a generic plot subroutine could use indexed indirect addressing, storing $0200 + (q*32)
into a zero-page location and then indexing by p
to hit a particular horizontal position within that row. Off the top of my head, and without having checked exactly what syntax that assembler uses and hard-coding the use of zero-page addresses $80 and $81:
;
; Plot; stores the colour in A to the pixel at (y, x).
; So, yes: x and y are backwards.
;
; Clobbers x.
;
Plot:
; Arbitrarily, this adds x to ($200 >> 5) and
; then shifts the whole lot left by 5. That's
; rather than shifting x by 5 and then doing a
; one-byte add to the upper byte, I guess.
pha
txa
clc
adc #$10 ; $10 = $200 >> 5
sta $80
lda #$00
sta $81
; Multiply by 32. You could unroll this if
; that's what your priorities imply.
ldx #5
.rollLoop
asl $80
rol $81
dex
bne rollLoop
pla
sta ($80), y
rts