Afternoon all!
I'm new to 6502 assembly but i'm having a weird issue that has me at my wits end. Here is the code i've written
Code:
PROCESSOR 6502
;-------------------------------------------------
;-------------DANI-I-SYSTEM-ROM-------------------
;-------------------------------------------------
;-------------EQUATES-----------------------------
VRAM: EQU $8000
VRAM_H: EQU $80
VRAM_L: EQU $00
VRAM_CMD: EQU VRAM + $F00
VRAM_CHARSLOC: EQU VRAM + $F10
VRAM_CHARSBUF: EQU VRAM + $F20
;-------------EO-EQUATES--------------------------
ORG $C000
RESET:
LDX #$FF ; Initialize the Stack Pointer
TXS ; Transfer X to Stack
SETUP_BLANKCHAR:
LDA #$00 ; Store Null in Accu
LDY #$00 ; Set Y to 00
LDX #$00 ; Set X to 00
LOOP_BLANKSTORE:
STA VRAM_CHARSBUF,X ; Store Accu into VRAM_CHARSBUF+X
INX
CPX #$08
BNE LOOP_BLANKSTORE
STA VRAM_CHARSLOC ; Set the Character Store Location
LDA #$01 ; Set the Character Store Command
STA VRAM_CMD
CHECK_CMDCOMPLETE:
LDX VRAM_CMD ; Keep Loading and Check VRAM_CMD to see if VGA picked up Character
CPX #$00
BNE CHECK_CMDCOMPLETE ; Keep Checking if it's not been set to 00
BLANKOUT_START:
LDA #$00 ; Set Accu to 0
LDX #$00 ; Set X Counter to 0
LDY #$00 ; Set Y Counter to 0
LDA #VRAM_L ; Load Accu to Low Byte of VRAM
STA $05 ; Store it in Zero Page 5
LDA #VRAM_H ; Load Accu to High Byte of VRAM
STA $06 ; Store it in Zero Page 6
LOOP_BLANKOUT:
LDA #$00 ; Set Accu To 0
STA ($05),Y ; Store it in VRAM + Y
CPY #$B0 ; Does Y eq B0 ?
BEQ CHECK_X ; it does? Got to Check_X
LOOP_CONTINUE:
CPY #$FF ; X is not 04 and Y is not B0 Is Y FF?
INY ; Increase Y
BNE LOOP_BLANKOUT ; It's not FF yet Go to LOOP_BLANKOUT
LOOP_INC_X: ; Y = FF
LDY #$00 ; Set Y back to 0
INX ; Add 1 to X
INC $06 ; Add 1 to Address 6
JMP LOOP_BLANKOUT ; Back to the LOOP_BLANKOUT
CHECK_X:
CPX #$04 ; Is X 04? Making this 2820?
BNE LOOP_CONTINUE
LOOP_DONE:
JMP BLANKOUT_START ; we hit 2820 - done
VECTORS:
ORG $FFFA ; 6502 Starts reading it's vectors here
.word LOOP_DONE ; NMI
.word RESET ; RESET
.word LOOP_DONE ; BRK
END
The problem is with the indirect addressing when "STA ($05),Y", it all works as expecting until Y = the High Byte Address, "06", when that happens 05 gets overwritten with the value of address 06 and then it continues to count as expected. If I change the ZP addresses it does the same with the new address's. For example when I had the addresses set to 10 and 11, whenever Y = 11 the value of 10 was overwritten with the value of 11 and then it continues to count as expected. When I run this code in a simulator it works fine. Any help in any direction would be huge, as this has brought my project to a halt for the time being.
Thanks!