Solution:I'm an idiot and forgot to clear the stack. Here's my new start where I clear the stack, if anyone else needs it.
; Modified start of the original program.
START: ; The start of the program.
ldx #$FF ; "Clear" X. This gets set to 0 later, right now this is the end point of the RAM and register clearing.
lda #0 ; Clear accumulator. Gets cleared again later.
CLEAR1: ; Clear all RAM, EXCEPT X-bytes from last!
sta 0, x ; Store accumulator at 0-page, at RAM address X.
dex ; Decrement X.
bne CLEAR1 ; If X is not 0, loop to CLEAR1.
ldx #$FF ; Setup for stack clear.
CLEAR2: ; Clear the stack.
dex ; Decrement X.
txs ; Put X to the current stack pointer? That's weird. I don't understand why you'd do that.
; Commenting out above seemed to work, but I wouldn't recommend it just in case. macro.h uses things I'm not apparently not aware about.
pha ; Push accumulator to stack, incrementing the stackpointer presumably.
bne CLEAR2 ; If we're not done clearing the stack, loop back to CLEAR2.
Original post:
Hi all! I hate to ask, but I'm currently facing a pretty big problem. I have a 2K rom that looks like this in assembly.
.include "atari.i" ; Atari register positions ported to WLA-DX.
; ROM info setup.
; This is for a 2K non-banked rom.
.ROMBANKMAP
BANKSTOTAL 1
BANKSIZE $0800
BANKS 1
.ENDRO
.MEMORYMAP
DEFAULTSLOT 0
SLOTSIZE $0800
SLOT 0 $f000
.ENDME
.BANK 0 SLOT 0
START: ; The start of the program.
ldx #$FF ; "Clear" X. This gets set to 0 later, right now this is the end point of the RAM and register clearing.
lda #0 ; Clear accumulator. Gets cleared again later.
CLEAR: ; Clear all RAM, EXCEPT the last byte!
sta 0, x ; Store accumulator at 0-page, at RAM address X.
dex ; Decrement X.
bne CLEAR ; If X is not 0, loop to CLEAR.
SETUP: ; Final preparations.
ldx #0
ldy #0
lda #0
LOOP1: ; The first loop.
; Do some random things.
adc #10
adc $EF
jsr LOOP2 ; Just jump to the draw logic when everything else is done.
CONT: sta $8e
lda #33
adc #64
adc #$01
adc inpt5
sta $84
ldx inpt4
stx $EF
jmp LOOP1 ; And the loop begins anew
LOOP2:
adc #30
adc $84
rts ; Okay, this loop's done! Return!
; Set the interrupts. Don't forget to do this! Final address-6!
.ORGA $F7FA
.dw START ; NMI
.dw START ; RESET
.dw START ; IRQ
The ROM loads up fine, but when I JSR to LOOP2, things get interesting. This is because RTS does NOT return to where CONT: is(compiled to $F016,) but rather an address in the $2XXX range. It's not consistent exactly where it's jumping, it's just somewhere in the $2XXX range.
My only guess is that it's a problem with the stack being given junk data shortly after the JSR, but none of these commands should be transferring to the stack. Does anyone have an idea of what's going sideways here?
I've attached a copy of the compiled ROM for examination, incase you don't want to fiddle with WLA-DX.
rom.a26