2000-05-28 13:40:48 +00:00
|
|
|
;
|
|
|
|
; Ullrich von Bassewitz, 27.09.1998
|
|
|
|
;
|
2018-11-06 10:13:23 +00:00
|
|
|
; void __fastcall__ set_brk (unsigned Addr);
|
2000-05-28 13:40:48 +00:00
|
|
|
; void reset_brk (void);
|
|
|
|
;
|
|
|
|
|
2013-05-09 11:56:54 +00:00
|
|
|
.export _set_brk, _reset_brk
|
|
|
|
.destructor _reset_brk
|
2004-03-13 21:41:30 +00:00
|
|
|
|
|
|
|
; Be sure to export the following variables absolute
|
2013-05-09 11:56:54 +00:00
|
|
|
.export _brk_a: abs, _brk_x: abs, _brk_y: abs
|
2004-03-13 21:41:30 +00:00
|
|
|
.export _brk_sr: abs, _brk_pc: abs
|
2000-05-28 13:40:48 +00:00
|
|
|
|
2013-05-09 11:56:54 +00:00
|
|
|
.include "apple2.inc"
|
2000-05-28 13:40:48 +00:00
|
|
|
|
|
|
|
_brk_a = $45
|
|
|
|
_brk_x = $46
|
|
|
|
_brk_y = $47
|
|
|
|
_brk_sr = $48
|
|
|
|
_brk_sp = $49
|
|
|
|
_brk_pc = $3A
|
|
|
|
|
|
|
|
.bss
|
2013-05-09 11:56:54 +00:00
|
|
|
oldvec: .res 2 ; Old vector
|
2000-05-28 13:40:48 +00:00
|
|
|
|
|
|
|
|
|
|
|
.data
|
2013-05-09 11:56:54 +00:00
|
|
|
uservec: jmp $FFFF ; Patched at runtime
|
2000-05-28 13:40:48 +00:00
|
|
|
|
|
|
|
|
|
|
|
.code
|
|
|
|
|
|
|
|
; Set the break vector
|
2013-05-09 11:56:54 +00:00
|
|
|
.proc _set_brk
|
2000-05-28 13:40:48 +00:00
|
|
|
|
2013-05-09 11:56:54 +00:00
|
|
|
sta uservec+1
|
|
|
|
stx uservec+2 ; Set the user vector
|
2000-05-28 13:40:48 +00:00
|
|
|
|
2013-05-09 11:56:54 +00:00
|
|
|
lda oldvec
|
|
|
|
ora oldvec+1 ; Did we save the vector already?
|
|
|
|
bne L1 ; Jump if we installed the handler already
|
2000-05-28 13:40:48 +00:00
|
|
|
|
2013-05-09 11:56:54 +00:00
|
|
|
lda BRKVec
|
|
|
|
sta oldvec
|
|
|
|
lda BRKVec+1
|
|
|
|
sta oldvec+1 ; Save the old vector
|
2000-05-28 13:40:48 +00:00
|
|
|
|
2013-05-09 11:56:54 +00:00
|
|
|
L1: lda #<brk_handler ; Set the break vector to our routine
|
|
|
|
ldx #>brk_handler
|
|
|
|
sta BRKVec
|
|
|
|
stx BRKVec+1
|
|
|
|
rts
|
2000-05-28 13:40:48 +00:00
|
|
|
|
|
|
|
.endproc
|
|
|
|
|
|
|
|
|
|
|
|
; Reset the break vector
|
2013-05-09 11:56:54 +00:00
|
|
|
.proc _reset_brk
|
|
|
|
|
|
|
|
lda oldvec
|
|
|
|
ldx oldvec+1
|
|
|
|
beq @L9 ; Jump if vector not installed
|
|
|
|
sta BRKVec
|
|
|
|
stx BRKVec+1
|
|
|
|
lda #$00
|
|
|
|
sta oldvec ; Clear the old vector
|
|
|
|
stx oldvec+1
|
|
|
|
@L9: rts
|
2000-05-28 13:40:48 +00:00
|
|
|
|
|
|
|
.endproc
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
; Break handler, called if a break occurs
|
|
|
|
|
2013-05-09 11:56:54 +00:00
|
|
|
.proc brk_handler
|
2000-05-28 13:40:48 +00:00
|
|
|
|
2013-05-09 11:56:54 +00:00
|
|
|
sec
|
|
|
|
lda _brk_pc
|
|
|
|
sbc #$02 ; Point to start of brk
|
|
|
|
sta _brk_pc
|
|
|
|
lda _brk_pc+1
|
|
|
|
sbc #$00
|
|
|
|
sta _brk_pc+1
|
2000-05-28 13:40:48 +00:00
|
|
|
|
2013-05-09 11:56:54 +00:00
|
|
|
clc
|
|
|
|
lda _brk_sp
|
|
|
|
adc #$04 ; Adjust stack pointer
|
|
|
|
sta _brk_sp
|
2000-05-28 13:40:48 +00:00
|
|
|
|
2013-05-09 11:56:54 +00:00
|
|
|
lda _brk_sr ; Clear brk
|
|
|
|
and #$EF
|
|
|
|
sta _brk_sr
|
2000-05-28 13:40:48 +00:00
|
|
|
|
2013-05-09 11:56:54 +00:00
|
|
|
jsr uservec ; Call the user's routine
|
2000-05-28 13:40:48 +00:00
|
|
|
|
2013-05-09 11:56:54 +00:00
|
|
|
lda _brk_pc+1
|
|
|
|
pha
|
|
|
|
lda _brk_pc
|
|
|
|
pha
|
|
|
|
lda _brk_sr
|
|
|
|
pha
|
2000-05-28 13:40:48 +00:00
|
|
|
|
2013-05-09 11:56:54 +00:00
|
|
|
ldx _brk_x
|
|
|
|
ldy _brk_y
|
|
|
|
lda _brk_a
|
2000-12-01 17:58:40 +00:00
|
|
|
|
2013-05-09 11:56:54 +00:00
|
|
|
rti ; Jump back...
|
2000-05-28 13:40:48 +00:00
|
|
|
|
|
|
|
.endproc
|
2000-12-01 17:58:40 +00:00
|
|
|
|