6502 Assembly Language (Week 2 Lab)
In this lab, we took our first baby steps in the 6502 universe.
The idea was to mess around with the 6502 simulator, and finish by drawing four different coloured lines around the edges of the given square field.
Here is a link to the simulator: http://6502.cdot.systems/
I came up with some pretty simple code to accomplish this, and I've written some comments in the code to explain my thought process.
define GREEN $5
define BLUE $6
define YELLOW $7
define PURPLE $8
; set low and high bits for the beginning of the screen
define start_lowbit $00 ; low
define start_highbit $02 ; high
; 0200 is the address of the first pixel
define first_pixel_lowbit $0 ;
define first_pixel_highbit $1 ;
define index_at_end_of_row $20 ; this is decimal 32, because the screen is 32px wide
; because 6502 is little-endian, 2 byte values are stored with low bit first
lda #start_lowbit ;
sta first_pixel_lowbit ; sta stores value of register A into RAM
lda #start_highbit
sta first_pixel_highbit
;4 lines above represent 'zero addressing mode', since within first 265 bytes ($0000-$00FF)
ldy #$00 ; set index to 0
horizontal:
lda #GREEN
sta (first_pixel_lowbit), y ; store value of register A into the first pixel, offset by y
lda #PURPLE
sta $05E0, y ; color the bottom left pixel with the y offset
iny
cpy #index_at_end_of_row
bne horizontal;
ldx #$04 ;four pages per screen
color_sides:
lda #YELLOW
sta (first_pixel_lowbit),y
lda first_pixel_lowbit
clc
adc #$1f
sta first_pixel_lowbit ; the pointer is now on the next pixel
lda #BLUE
sta (first_pixel_lowbit),y
lda first_pixel_lowbit
adc #$01
sta first_pixel_lowbit
bcc color_sides
inc first_pixel_highbit
dex;
bne color_sides
As a first 6502 learning exercise, I found this one pretty tricky but I had a lot of enjoyment learning about lda, sta, high bits, low bits, and hex values. I'm looking forward to the next lab!
Comments
Post a Comment