dos33fsprogs/bot_demo/interrupt_handler.s

147 lines
2.4 KiB
ArmAsm
Raw Normal View History

2020-11-15 04:18:51 +00:00
;================================
;================================
; mockingboard interrupt handler
;================================
;================================
; On Apple II/6502 the interrupt handler jumps to address in 0xfffe
; This is in the ROM, which saves the registers
; on older IIe it saved A to $45 (which could mess with DISK II)
; newer IIe doesn't do that.
; It then calculates if it is a BRK or not (which trashes A)
; Then it sets up the stack like an interrupt and calls 0x3fe
; Note: the IIc is much more complicated
; its firmware tries to decode the proper source
; based on various things, including screen hole values
; we bypass that by switching out ROM and replacing the
; $fffe vector with this, but that does mean we have
; to be sure status flag and accumulator set properly
interrupt_handler:
php ; save status flags
pha ; save A ; 3
; A is saved in $45 by firmware
txa
pha ; save X
tya
pha ; save Y
; inc $0404 ; debug (flashes char onscreen)
.include "pt3_lib_irq_handler.s"
jmp exit_interrupt
;=================================
; Finally done with this interrupt
;=================================
quiet_exit:
stx DONE_PLAYING
jsr clear_ay_both
ldx #$ff ; also mute the channel
stx AY_REGISTERS+7 ; just in case
exit_interrupt:
; update time
inc ticks
lda ticks
cmp #50
bne no_tick_oflo
lda #0
sta ticks
inc seconds
no_tick_oflo:
2020-11-17 20:59:06 +00:00
; if done, no timeout
lda command
cmp #DONE
beq handle_credits
2020-11-15 04:18:51 +00:00
; trigger at timeout value
lda seconds
cmp timeout
2020-11-17 20:33:00 +00:00
bne handle_credits
2020-11-15 04:18:51 +00:00
inc trigger
lda which
asl
tax
lda todo_list,x
sta command
2020-11-17 20:33:00 +00:00
cmp #DO_CREDITS
bne itsnot
jsr switch_to_credits
lda command
itsnot:
2020-11-15 04:18:51 +00:00
cmp #DONE
2020-11-17 18:11:41 +00:00
beq handle_credits
2020-11-15 04:18:51 +00:00
lda todo_list+1,x
sta timeout
; point to next
inc which
; reset seconds
lda #0
sta seconds
; HUGE HACK
; return to our code instead of BASIC
ldx original_stack
txs
2020-11-16 05:12:56 +00:00
lda #>command_loop
2020-11-15 04:18:51 +00:00
pha
2020-11-16 05:12:56 +00:00
lda #<command_loop
2020-11-15 04:18:51 +00:00
pha
lda #0 ; program status word
pha
rti
2020-11-17 18:11:41 +00:00
handle_credits:
2020-11-17 20:33:00 +00:00
lda command
cmp #DONE
bne done_match
2020-11-17 18:11:41 +00:00
jsr display_credits
2020-11-15 04:18:51 +00:00
done_match:
pla
tay ; restore Y
pla
tax ; restore X
pla ; restore a ; 4
; on II+/IIe (but not IIc) we need to do this?
interrupt_smc:
lda $45 ; restore A
plp
rti ; return from interrupt ; 6
;============
; typical
; ???? cycles
seconds: .byte $00
ticks: .byte $00