File tree Expand file tree Collapse file tree 3 files changed +36
-8
lines changed
Expand file tree Collapse file tree 3 files changed +36
-8
lines changed Original file line number Diff line number Diff line change @@ -65,8 +65,5 @@ snd_command_01_prepare_for_rom_switch::
6565;;; Reset sound driver
6666;;; reset stack and start the sound driver
6767snd_command_03_reset_driver::
68- di
69- ld sp , # 0xffff
70- ld hl , #snd_start_driver
71- push hl
72- retn
68+ ld bc , # 0
69+ jp snd_init_driver_from_nmi
Original file line number Diff line number Diff line change 2424 .include "ports.inc"
2525 .include "ym2610.inc"
2626
27- . equ MAX_PENDING_COMMANDS , 64
27+ . equ START_OF_STACK , 0xfffd
28+ . equ MAX_PENDING_COMMANDS , 64
2829
2930
3031
@@ -121,6 +122,19 @@ init_z80_and_wait:
121122 ret
122123
123124
125+ ;;; Intialize and start the sound driver
126+ ;;; This function is called during a NMI, this is the last
127+ ;;; function called from the NMI before starting the driver
128+ ;;; ------
129+ ;;; [ bc ]: optional hook, called after the driver is initialized
130+ snd_init_driver_from_nmi::
131+ di
132+ ld (#POST_INIT_HOOK) , bc
133+ ld sp , #START_OF_STACK
134+ ld hl , #snd_start_driver
135+ push hl
136+ retn
137+
124138
125139;;; Sound driver
126140;;; ------------
@@ -150,6 +164,17 @@ snd_start_driver::
150164 ld (command_fifo_current) , a
151165 ld (command_fifo_pending) , a
152166
167+ ;; if there is a post-hook function configured, run it
168+ ;; now before entering the main loop
169+ ld hl , (#POST_INIT_HOOK)
170+ ld a , h
171+ or l
172+ jr z , snd_mainloop
173+ ld bc , #snd_mainloop
174+ push bc
175+ push hl
176+ ret
177+
153178snd_mainloop:
154179 ;; process pending commands if any
155180 call snd_process_pending_commands
Original file line number Diff line number Diff line change @@ -37,13 +37,19 @@ cmd_jmptable_padding:
3737 .endm
3838
3939 ;; private helper to generate z80 opcode to stay idle in RAM
40+ .lclequ RESET_WAIT_PC , 0xfffe
41+ .lclequ OPCODE_JR_TO_SELF , 0xfe18
4042 .macro prepare_wait_in_ram_opcodes
4143 ;; create a jmp-to-self instruction at the top of the RAM
4244 ;; to ensure the 68k can bank-switch z80 code without impact
43- ld bc , # 0xfe18 ; jr <self>
44- ld (# 0xfffe ) , bc
45+ ld bc , #OPCODE_JR_TO_SELF ; jr <self>
46+ ld (#RESET_WAIT_PC ) , bc
4547 ;; ;; prepare the stack to pop into the jump-to-self in RAM
4648 ld hl , # 0xfffe
4749 ld sp , hl
4850 push hl
4951 .endm
52+
53+ ;; address of an optional hook function that gets called
54+ ;; once the driver finished its initialization
55+ .lclequ POST_INIT_HOOK , RESET_WAIT_PC
You can’t perform that action at this time.
0 commit comments