diff --git a/libsrc/plus4/break.s b/libsrc/plus4/break.s index c51cc4b07..52c77127c 100644 --- a/libsrc/plus4/break.s +++ b/libsrc/plus4/break.s @@ -6,8 +6,8 @@ ; .export _set_brk, _reset_brk - .destructor _reset_brk .export _brk_a, _brk_x, _brk_y, _brk_sr, _brk_pc + .import brk_jmp .include "plus4.inc" @@ -19,11 +19,11 @@ _brk_y: .res 1 _brk_sr: .res 1 _brk_pc: .res 2 -oldvec: .res 2 ; Old vector +oldvec: .res 2 ; Old vector .data -uservec: jmp $FFFF ; Patched at runtime +uservec: jmp $FFFF ; Patched at runtime .code @@ -32,21 +32,12 @@ uservec: jmp $FFFF ; Patched at runtime .proc _set_brk sta uservec+1 - stx uservec+2 ; Set the user vector + stx uservec+2 ; Set the user vector - lda oldvec - ora oldvec+1 ; Did we save the vector already? - bne L1 ; Jump if we installed the handler already - - lda BRKVec - sta oldvec - lda BRKVec+1 - sta oldvec+1 ; Save the old vector - -L1: lda #brk_handler - sta BRKVec - stx BRKVec+1 + lda #brk_handler + sta brk_jmp+2 rts .endproc @@ -55,26 +46,20 @@ L1: lda #IRQStub + sei + sta IRQVec + stx IRQVec+1 + cli + ; Pass an empty command line - jsr push0 ; argc +NoIRQ1: jsr push0 ; argc jsr push0 ; argv ldy #4 ; Argument size jsr _main ; call the users code -; Call module destructors. This is also the _exit entry. +; Back from main (this is also the _exit entry). Reset the IRQ vector if +; we chained it. -_exit: jsr donelib ; Run module destructors +_exit: lda #<__IRQFUNC_COUNT__ + beq NoIRQ2 + lda IRQInd+1 + ldx IRQInd+2 + sei + sta IRQVec + stx IRQVec+1 + cli + +; Run module destructors. + +NoIRQ2: jsr donelib ; Run module destructors ; Restore system stuff @@ -118,29 +152,65 @@ IRQ: pha pha tsx ; Get the stack pointer lda $0103,x ; Get the saved status register - tax - lda #>irqret ; Push new return address + tax ; Save for later + and #$10 ; Test for BRK bit + bne dobreak + lda #>irq_ret ; Push new return address pha - lda #__IRQFUNC_TABLE__ + jsr condes ; Call the IRQ functions + sta ENABLE_ROM + jmp IRQInd ; Jump to the saved IRQ vector + ; ------------------------------------------------------------------------ ; Data .data -zpsave: .res zpspace +zpsave: .res zpspace + +; BRK handling +brk_jmp: jmp $0000 .bss -spsave: .res 1 +spsave: .res 1 + diff --git a/libsrc/plus4/plus4.inc b/libsrc/plus4/plus4.inc index 680a9611a..b1d67d00f 100644 --- a/libsrc/plus4/plus4.inc +++ b/libsrc/plus4/plus4.inc @@ -70,7 +70,7 @@ TED_RAMSEL = $FF3F ; --------------------------------------------------------------------------- ; RAM/ROM selection addresses -ENABLE_ROM = $FF3E -ENABLE_RAM = $FF3F +ENABLE_ROM = TED_ROMSEL +ENABLE_RAM = TED_RAMSEL