A small project to teach myself uses for the stack
Posted: Fri Dec 20, 2019 2:34 am
All this really does is draw a square by drawing one line, storing the pixel location low byte as it does then moving the line down and drawing it backwards by popping the pixel location's low bytes out of the stack.
Again, this is designed for the Easy6502 virtual machine:
http://skilldrick.github.io/easy6502/
I'm just making this to practice using the stack for programs, since I'm not sure how to use it effectively yet. I know how it works, but I'm still figuring out how to make it useful to me.
Again, this is designed for the Easy6502 virtual machine:
http://skilldrick.github.io/easy6502/
Code: Select all
;Initialize Starting Values
LDX #$08 ;Setting starting low byte
STX $01
LDX #$03 ;Setting Starting high byte
STX $02
LDX #$08 ;Setting draw limit
push: ;Starting Push Loop
LDA #$01 ;Setting pixel color
STA ($01),y ;Draw Pixel
TYA ;Transfer Offset to A
PHA ;Push A to Stack
INY ;Increment Offset in Y
CMP #$0f ;Check if Offset = 16
BNE push ;If not, loop again
CLC ;If Offset = 16, ClearCcarry
LDA $01 ;Then, Add vertical offset of 32 to Low Byte
ADC #$20
STA $01
pull: ;Starting Pull Loop
PLA ;Popping Offset Value from Stack
TAY ;Transfer Offset from A to Y
LDA #$01 ;Resetting Pixel Color
STA ($01),y ;Draw Pixel
CPY #$00 ;Check if more Offset Values in Stack
BNE pull ;If not, loop again
CLC ;If Stack is Empty, Clear Carry
LDA $01 ;Then, Add vertical offset of 32 to Low Byte
ADC #$20
STA $01
BCC cdown ;Check if Carry Set
;If not, Skip incrementing high byte
INC $02 ;Increment High Byte
cdown: ;Decrement Draw Limit Count
DEX
BNE push ;If Draw Limit = 0, End
;Else, Return to Push Loop
BRK ;End