Skip to content

Commit

Permalink
Native IRQ: Call the KERNAL emulated IRQ code directly in native mode…
Browse files Browse the repository at this point in the history
… if the emulated IRQ vector hasn't been replaced
  • Loading branch information
Fulgen301 authored and mooinglemur committed Mar 1, 2024
1 parent 0efb7ec commit 30d89cf
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 5 deletions.
15 changes: 14 additions & 1 deletion kernal/cbm/irq.s
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,18 @@
.import joystick_scan
.import cursor_blink
.import led_update
.export panic
.import __interrupt_65c816_native_kernal_impl_ret
.import ps2data_fetch
.export panic
.export irq_emulated_impl

.include "banks.inc"
.include "io.inc"

; VBLANK IRQ handler
;
key
.macro irq_impl
jsr ps2data_fetch
jsr mouse_scan ;scan mouse (do this first to avoid sprite tearing)
jsr joystick_scan
Expand All @@ -35,6 +38,16 @@ key

lda #1
sta VERA_ISR ;ack VERA VBLANK
.endmacro

irq_emulated_impl:
irq_impl
jmp __interrupt_65c816_native_kernal_impl_ret

; VBLANK IRQ handler
;
key
irq_impl

ply
plx
Expand Down
18 changes: 14 additions & 4 deletions kernal/drivers/x16/65c816/interrupt.s
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
.import iclall, igetin
.import cbinv, cinv, nminv
.import __irq, __irq_65c816_saved, __irq_native_ret
.import key, irq_emulated_impl

.import goto_user, reg_a, reg_x, reg_y, softclock_timer_update, scrorg
.import iecop, ieabort, inirq, inbrk, innmi, incop, inabort
Expand All @@ -9,7 +10,7 @@

.export c816_clall_thunk, c816_abort_emulated, c816_cop_emulated, c816_irqb, c816_getin_thunk
.export nnirq, nnbrk, nnnmi, nncop, nnabort
.export __irq_65c816_first
.export __irq_65c816_first, __interrupt_65c816_native_kernal_impl_ret

rom_bank = 1

Expand Down Expand Up @@ -53,7 +54,7 @@ rom_bank = 1
.I8
.endmacro

.macro irq_brk_common_impl addr
.macro irq_brk_common_impl addr, emulated_kernal_vector, emulated_kernal_impl
.A16
.I16
tsx
Expand All @@ -65,7 +66,15 @@ rom_bank = 1
tcs
: phx ; store old stack pointer on new stack

pea __interrupt_65c816_native_ret ; set up CBM IRQ stack frame
.ifnblank emulated_kernal_impl
lda addr
cmp #emulated_kernal_vector
bne :+
sep #$30
jmp emulated_kernal_impl
.endif

: pea __interrupt_65c816_native_ret ; set up CBM IRQ stack frame
sec
xce ; enter emulation mode
.A8
Expand Down Expand Up @@ -142,14 +151,15 @@ __irq_65c816_first:
jmp __irq_65c816_saved

nnirq:
irq_brk_common_impl cinv
irq_brk_common_impl cinv, key, irq_emulated_impl

nnbrk:
irq_brk_common_impl cbinv

__interrupt_65c816_native_ret:
clc
xce ; exit emulation mode
__interrupt_65c816_native_kernal_impl_ret:
rep #$31 ; 16-bit accumulator, clear carry
pla ; pull old stack pointer
tcs ; restore stack pointer
Expand Down

0 comments on commit 30d89cf

Please sign in to comment.