am i having some gigantic brain**** here or is bounce on the nmi line overflowing it's own return address or something
whenever i assert nmi it seems to be jumping/returning to random stuff. (and yes all the other stuff is there to make sure it never jumps into some irq/nmi routine before it has finished post.
anything 'shipped with the system' that should do irq will be handled by the system -before- checking for the eventual user program stuff
the flags register doesn't need to be preserved before all the conditional branches as it is my understanding that a monitor (should the user handler be a monitor) will always pull the last one of the stack and push it back rather than use the current one. after all the one you want to display in the status register line is the one from -before- the nmi or brk occured
and yes all of the conditional branches do seem to be needed after all the user could pull nmi during the initialisation shortly after powerup without the memory and i/o having been initialized yet, an irq or nmi could occur -while- the user code is writing his vector to 0202 or 0204 (that's what the extra byte with the 2 flags is for as well as bit 7 that should always be 0 so the whole situation of the 3 bytes containing that stuff 'randomly' during a powerup before memtest initializes the ram (our emulator nicely has zeroes all over the place upon power up but irl that looks different, as it's a cpu emulator and not a 'transistor level' emulator it does however not have an irq or nmi 'line' we can pull and/or cause bounce on
and the periphials are initialzed are rather unlikely to happen) also it prevents it from executing -any- irq/nmi if the memory test failed for all the obvious reasons)
;--- USER IRQ HANDLER
; - REQUIRES MEMTEST TO HAVE PASSED
; - POINTER IN USER NMI HANDLER VECTOR $0202 (LSB) AND $0203 (MSB) NOT ZERO AND NOT IN ROM (>=$8000)
; - BIT 1 OF $0206 TO BE SET TO 1
; - BIT 7 of $0206 SHOULD ALWAYS BE 0
.IRQHANDLER
PHA ; WE'LL BE USING THE A-REGISTER HERE
LDA $0200 ; RAMTEST LSB DONE SHOULD BE $00 ?
BNE ~IRQNMIHANDLERDONE
LDA $0201 ; RAMTEST MSB DONE SHOULD BE $80 ?
CMP #$80
BNE ~IRQNMIHANDLERDONE
LDA $0206 ; USER NMI/IRQ ENABLE MASK BYTE
BMI ~IRQNMIHANDLERDONE ; BIT 7 SHOULD ALWAYS BE 0
AND #$01 ; CUSTOM IRQ HANDLER SET?
BEQ ~IRQNMIHANDLERDONE
LDA $0202 ; CUSTOM IRQ HANDLER LSB SHOULD NOT BE ZERO
BEQ ~IRQNMIHANDLERDONE
LDA $0203 ; CUSTOM IRQ HANDLER MSB SHOULD NOT BE ZERO
BEQ ~IRQNMIHANDLERDONE
BMI ~IRQNMIHANDLERDONE ; ALSO SHOULD NOT BE IN ROM (MSB >= $80)
PLA ; RESTORE A-REGISTER - FLAGS REGISTER DOESN'T MATTER AS NONE OF THIS IMPACTS BREAK/IRQ FLAGS
JMP ($0202) ; JUMP TO ADDRESS IN USER IRQ VECTOR
;--- USER NMI HANDLER
; - REQUIRES MEMTEST TO HAVE PASSED
; - POINTER IN USER NMI HANDLER VECTOR $0202 (LSB) AND $0203 (MSB) NOT ZERO AND NOT IN ROM (>=$8000)
; - BIT 2 OF $0206 TO BE SET TO 1
; - BIT 7 of $0206 SHOULD ALWAYS BE 0
.NMIHANDLER
PHA ; WE'LL BE USING THE A-REGISTER HERE
LDA $0200 ; RAMTEST LSB DONE SHOULD BE $00 ?
BNE ~IRQNMIHANDLERDONE
LDA $0201 ; RAMTEST MSB DONE SHOULD BE $80 ?
CMP #$80
BNE ~IRQNMIHANDLERDONE
LDA $0206 ; USER NMI/IRQ ENABLE MASK BYTE
BMI ~IRQNMIHANDLERDONE ; BIT 7 SHOULD ALWAYS BE 0
AND #$02 ; CUSTOM NMI HANDLER SET?
BEQ ~IRQNMIHANDLERDONE
LDA $0204 ; CUSTOM NMI HANDLER LSB SHOULD NOT BE ZERO
BEQ ~IRQNMIHANDLERDONE
LDA $0205 ; CUSTOM NMI HANDLER MSB SHOULD NOT BE ZERO
BEQ ~IRQNMIHANDLERDONE
BMI ~IRQNMIHANDLERDONE ; ALSO SHOULD NOT BE IN ROM (MSB >= $80)
PLA ; RESTORE A-REGISTER - FLAGS REGISTER DOESN'T MATTER AS NONE OF THIS IMPACTS BREAK/IRQ FLAGS
JMP ($0204) ; JUMP TO ADDRESS IN USER NMI VECTOR
;--- RETURN FUNCTION FOR USER NMI AND IRQ HANDLERS THAT DIDN'T MEET THE REQUIREMENTS
.IRQNMIHANDLERDONE
PLA ; RESTORE A-REGISTER - FLAGS REGISTER DOESN'T MATTER AS NONE OF THIS IMPACTS BREAK/IRQ FLAGS
RTI
SIZ $7FFA
;--- CPU VECTORS
.VECTORNMI
DWO !NMIHANDLER
.VECTORRST
DWO !COLDSTART
.VECTORIRQ
DWO !IRQHANDLER