Skip to content

Commit 34ea937

Browse files
committed
nullsound: update initialization to allow music during attract mode
By convention, the BIOS calls NMI with command 02 to play a jingle music during while the system ROM runs its attract mode animation. Add the ability to call a user function right after nullsound initialization, so one can play a user-provided NSS stream during the attract mode.
1 parent 617a93b commit 34ea937

File tree

3 files changed

+36
-8
lines changed

3 files changed

+36
-8
lines changed

nullsound/bios-commands.s

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff 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
6767
snd_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

nullsound/entrypoint.s

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@
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+
153178
snd_mainloop:
154179
;; process pending commands if any
155180
call snd_process_pending_commands

nullsound/helpers.inc

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff 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

0 commit comments

Comments
 (0)