I decided to learn assembly and 6502 seems like a good platform to learn on. Here's my first program; I'm following the guide on http://skilldrick.github.io/easy6502. My modification to the original program is the addition of the `nextline` routine and the two accompanying lines at the start. The `STA` calls inside `firstloop` and `secondloop` that paints the pixels were also modified to use indirect indexed adressing to know which line to paint to, in addition to which horizontal pixel (which is tracked in register Y).
You can compare it to the version at http://skilldrick.github.io/easy6502/#stack (first program in that section of the page) to see the difference.
What would you seasoned 6502 developers do to make it easier to understand and follow?
Code: Select all
; ------------------------------------------------------------------------
; Write a colorful pattern to a 32x32 pixel display.
;
; Modified from http://skilldrick.github.io/easy6502/#stack.
;
; This version paints the whole screen instead of just the first line, as
; the original program does. To run the program, go to the address above and
; paste this code into the editor.
;
; NOTE: Memory locations $200 through $5ff (1024 bytes) are the screen
; pixels. To go to the next line, therefore add #$20. Values $0 - $f are
; the different colors that each pixel can be set to.
; ------------------------------------------------------------------------
; store address to current line at $00 (16-bit), start at #$0200
LDY #$02
STY $01
main:
LDX #$00 ; pixel color value
LDY #$00 ; pixel location on the current line
firstloop:
TXA
STA ($00),Y
PHA
INX
INY
CPY #$10
BNE firstloop ; loop until Y is $10
secondloop:
PLA
STA ($00),Y
INY
CPY #$20 ; loop until Y is $20
BNE secondloop
nextline:
; add $20 to address $00 to go to next line
LDA $00
CLC
ADC #$20
STA $00
BCC main
INC $01
; stop if beyond memory mapped to screen
LDA $01
CMP #$06
BCC main
BRK