Commit 233e36ae authored by Amanda Cameron's avatar Amanda Cameron
Browse files

Let's avoid clobbering the C/C++ softregs in the ZeroPage when we get an irq/nmi.

parent bded4e39
Loading
Loading
Loading
Loading

src/asm/dma.S

0 → 100644
+23 −0
Original line number Diff line number Diff line
.macro _setup_dma src, dest, size
    lda #<src
    sta $E041
    lda #>src
    sta $E042

    lda #<dest
    sta $E043
    lda #>dest
    sta $E044

    lda #<size
    sta $E045
    lda #>size
    sta $E045
.endmacro

.macro dma_copy src, dest, size
    _setup_dma src, dest, size

    ; Execute the DMA.
    stz $E040
.endmacro
 No newline at end of file

src/asm/state.inc

0 → 100644
+25 −0
Original line number Diff line number Diff line
.include "asm/dma.S"

.macro save_state addr
    pha
    phx
    phy

    ; DMA the Zero Page to the slot.
    dma_copy $0000, addr, $100
.endmacro

.macro load_state addr
    ; DMA the slot to the zero page.
    dma_copy addr, $0000, $100

    ply
    plx
    pla
.endmacro


.macro state_slot label
label:
    .res $100
.endmacro
 No newline at end of file
+11 −16
Original line number Diff line number Diff line
.setcpu "65c02"
.include "asm/debug.inc"
.include "asm/3op-bits.inc"
.include "asm/state.inc"

.segment "DATA"
.bss

state_slot irq_state
state_slot nmi_state

.code
.import _handle_timer_a: absolute, _handle_timer_b: absolute
.import _handle_keyboard: absolute, _handle_signal: absolute
.import _handle_software_irq: absolute

.segment "CODE"
.importzp _tmp0

; Check the handler's non-null, if so call it.
@@ -75,9 +80,7 @@ init_irq:
    rts

irq:
    pha
    phx
    phy
    save_state irq_state

    debug_tag #$D0

@@ -146,21 +149,13 @@ irq:
@end:
    debug_tag #$DF

    ply
    plx
    pla

    load_state irq_state
    rti

nmi:
    pha
    phx
    phy
    save_state nmi_state

    debug_tag #$DD

    ply
    plx
    pla

    load_state nmi_state
    rti
 No newline at end of file