Rudimentary SFX playback.

This commit is contained in:
Randy Thiemann 2023-10-16 13:27:08 +02:00
parent 4d46396e37
commit 89e311ac5d
6 changed files with 388 additions and 9 deletions

View File

@ -19,10 +19,6 @@ Main::
xor a, a xor a, a
ldh [rLCDC], a ldh [rLCDC], a
; Save some power and turn off the audio.
xor a, a
ldh [rNR52], a
; We use a single set of tiles for the entire game, so we copy it at the start. ; We use a single set of tiles for the entire game, so we copy it at the start.
ld de, Tiles ld de, Tiles
ld hl, _VRAM ld hl, _VRAM
@ -67,6 +63,9 @@ Main::
EventLoop:: EventLoop::
; Play the sound effect, if any.
call SFXPlay
; Wrangle inputs and timers at the start of every frame. ; Wrangle inputs and timers at the start of every frame.
call GetInput call GetInput
call HandleTimers call HandleTimers
@ -109,6 +108,7 @@ InitializeVariables:
call ScoreInit call ScoreInit
call LevelInit call LevelInit
call FieldInit call FieldInit
call SFXInit
ret ret

BIN
src/res/sources/sfx.fur Normal file

Binary file not shown.

BIN
src/res/sources/sfx.vgm Normal file

Binary file not shown.

279
src/res/sources/sfxregs.txt Normal file
View File

@ -0,0 +1,279 @@
$02, $00,
$04, $80,
$07, $00,
$09, $80,
$0C, $00,
$0E, $80,
$11, $00,
$13, $80,
$00, $00,
$16, $8F,
$15, $FF,
$14, $77,
$02, $F0,
$07, $F0,
$01, $BF,
$01, $BF,
$02, $F0,
$03, $AC,
$04, $85,
$06, $7F,
$06, $7F,
$07, $80,
$08, $14,
$09, $87,
$FF,
$FF,
$01, $BF,
$01, $BF,
$02, $F0,
$03, $ED,
$04, $85,
$06, $7F,
$06, $7F,
$07, $80,
$08, $2D,
$09, $87,
$FF,
$FF,
$01, $BF,
$01, $BF,
$02, $F0,
$03, $27,
$04, $86,
$06, $7F,
$06, $7F,
$07, $80,
$08, $44,
$09, $87,
$FF,
$FF,
$01, $BF,
$01, $BF,
$02, $F0,
$03, $AC,
$04, $85,
$06, $7F,
$06, $7F,
$07, $80,
$08, $14,
$09, $87,
$FF,
$FF,
$01, $BF,
$01, $BF,
$02, $F0,
$03, $ED,
$04, $85,
$06, $7F,
$06, $7F,
$07, $80,
$08, $2D,
$09, $87,
$FF,
$FF,
$01, $BF,
$01, $BF,
$02, $F0,
$03, $27,
$04, $86,
$06, $7F,
$06, $7F,
$07, $80,
$08, $44,
$09, $87,
$FF,
$FF,
$01, $BF,
$01, $BF,
$02, $F0,
$03, $5B,
$04, $86,
$06, $7F,
$06, $7F,
$07, $80,
$08, $59,
$09, $87,
$FF,
$FF,
$01, $BF,
$01, $BF,
$02, $F0,
$03, $AC,
$04, $85,
$06, $7F,
$06, $7F,
$07, $80,
$08, $14,
$09, $87,
$FF,
$FF,
$01, $BF,
$01, $BF,
$02, $F0,
$03, $27,
$04, $86,
$06, $7F,
$06, $7F,
$07, $80,
$08, $44,
$09, $87,
$FF,
$FF,
$01, $BF,
$01, $BF,
$02, $F0,
$03, $72,
$04, $86,
$06, $7F,
$06, $7F,
$07, $80,
$08, $62,
$09, $87,
$FF,
$FF,
$01, $BF,
$01, $BF,
$02, $F0,
$03, $D6,
$04, $86,
$06, $7F,
$06, $7F,
$07, $80,
$08, $8A,
$09, $87,
$FF,
$FF,
$01, $BF,
$01, $BF,
$02, $F0,
$03, $14,
$04, $87,
$06, $7F,
$06, $7F,
$07, $80,
$08, $A2,
$09, $87,
$FF,
$FF,
$01, $BF,
$01, $BF,
$02, $F0,
$03, $39,
$04, $87,
$06, $7F,
$06, $7F,
$07, $80,
$08, $B1,
$09, $87,
$FF,
$FF,
$01, $BF,
$01, $BF,
$02, $F0,
$03, $4F,
$04, $87,
$06, $7F,
$06, $7F,
$07, $80,
$08, $BA,
$09, $87,
$FF,
$FF,
$01, $BF,
$01, $BF,
$02, $F0,
$03, $62,
$04, $87,
$06, $7F,
$06, $7F,
$07, $80,
$08, $C1,
$09, $87,
$FF,
$FF,
$07, $F0,
$01, $BF,
$01, $BF,
$02, $D0,
$03, $6B,
$04, $87,
$06, $BF,
$06, $BF,
$07, $D0,
$08, $39,
$09, $87,
$FF, $FF,
$01, $BF,
$01, $BF,
$02, $D0,
$03, $6B,
$04, $87,
$06, $BF,
$06, $BF,
$07, $D0,
$08, $39,
$09, $87,
$FF, $FF,
$01, $BF,
$01, $BF,
$02, $D0,
$03, $6B,
$04, $87,
$06, $BF,
$06, $BF,
$07, $D0,
$08, $39,
$09, $87,
$FF, $FF, $FF, $FF, $FF, $FF,
$01, $BF,
$01, $BF,
$02, $10,
$03, $6B,
$04, $87,
$06, $BF,
$06, $BF,
$07, $10,
$08, $39,
$09, $87,
$FF, $FF,
$01, $BF,
$01, $BF,
$02, $10,
$03, $6B,
$04, $87,
$06, $BF,
$06, $BF,
$07, $10,
$08, $39,
$09, $87,
$FF, $FF,
$01, $BF,
$01, $BF,
$02, $10,
$03, $6B,
$04, $87,
$06, $BF,
$06, $BF,
$07, $10,
$08, $39,
$09, $87,
$FF, $FF, $FF, $FF,
$01, $BF,
$01, $BF,
$02, $00,
$03, $6B,
$04, $87,
$06, $BF,
$06, $BF,
$07, $00,
$08, $39,
$09, $87,
$FF, $FF, $FF, $FF,
$02, $08,
$03, $6B,
$04, $87,
$07, $08,
$08, $39,
$09, $87,
$FF, $FE,

100
src/sfx.asm Normal file
View File

@ -0,0 +1,100 @@
IF !DEF(SFX_ASM)
DEF SFX_ASM EQU 1
INCLUDE "globals.asm"
SECTION "Sound Effect Data", ROM0
sSFXNextPieceI::
db $02, $F0, $07, $F0, $01, $BF, $01, $BF, $02, $F0, $03, $AC, $04, $85, $06, $7F, $06, $7F, $07, $80, $08, $14, $09, $87, $FF, $FF, $01, $BF, $01, $BF, $02, $F0, $03, $ED, $04, $85,
db $06, $7F, $06, $7F, $07, $80, $08, $2D, $09, $87, $FF, $FF, $01, $BF, $01, $BF, $02, $F0, $03, $27, $04, $86, $06, $7F, $06, $7F, $07, $80, $08, $44, $09, $87, $FF, $FF, $01, $BF,
db $01, $BF, $02, $F0, $03, $AC, $04, $85, $06, $7F, $06, $7F, $07, $80, $08, $14, $09, $87, $FF, $FF, $01, $BF, $01, $BF, $02, $F0, $03, $ED, $04, $85, $06, $7F, $06, $7F, $07, $80,
db $08, $2D, $09, $87, $FF, $FF, $01, $BF, $01, $BF, $02, $F0, $03, $27, $04, $86, $06, $7F, $06, $7F, $07, $80, $08, $44, $09, $87, $FF, $FF, $01, $BF, $01, $BF, $02, $F0, $03, $5B,
db $04, $86, $06, $7F, $06, $7F, $07, $80, $08, $59, $09, $87, $FF, $FF, $01, $BF, $01, $BF, $02, $F0, $03, $AC, $04, $85, $06, $7F, $06, $7F, $07, $80, $08, $14, $09, $87, $FF, $FF,
db $01, $BF, $01, $BF, $02, $F0, $03, $27, $04, $86, $06, $7F, $06, $7F, $07, $80, $08, $44, $09, $87, $FF, $FF, $01, $BF, $01, $BF, $02, $F0, $03, $72, $04, $86, $06, $7F, $06, $7F,
db $07, $80, $08, $62, $09, $87, $FF, $FF, $01, $BF, $01, $BF, $02, $F0, $03, $D6, $04, $86, $06, $7F, $06, $7F, $07, $80, $08, $8A, $09, $87, $FF, $FF, $01, $BF, $01, $BF, $02, $F0,
db $03, $14, $04, $87, $06, $7F, $06, $7F, $07, $80, $08, $A2, $09, $87, $FF, $FF, $01, $BF, $01, $BF, $02, $F0, $03, $39, $04, $87, $06, $7F, $06, $7F, $07, $80, $08, $B1, $09, $87,
db $FF, $FF, $01, $BF, $01, $BF, $02, $F0, $03, $4F, $04, $87, $06, $7F, $06, $7F, $07, $80, $08, $BA, $09, $87, $FF, $FF, $01, $BF, $01, $BF, $02, $F0, $03, $62, $04, $87, $06, $7F,
db $06, $7F, $07, $80, $08, $C1, $09, $87, $FF, $FF, $07, $F0, $01, $BF, $01, $BF, $02, $D0, $03, $6B, $04, $87, $06, $BF, $06, $BF, $07, $D0, $08, $39, $09, $87, $FF, $FF, $01, $BF,
db $01, $BF, $02, $D0, $03, $6B, $04, $87, $06, $BF, $06, $BF, $07, $D0, $08, $39, $09, $87, $FF, $FF, $01, $BF, $01, $BF, $02, $D0, $03, $6B, $04, $87, $06, $BF, $06, $BF, $07, $D0,
db $08, $39, $09, $87, $FF, $FF, $FF, $FF, $FF, $FF, $01, $BF, $01, $BF, $02, $10, $03, $6B, $04, $87, $06, $BF, $06, $BF, $07, $10, $08, $39, $09, $87, $FF, $FF, $01, $BF, $01, $BF,
db $02, $10, $03, $6B, $04, $87, $06, $BF, $06, $BF, $07, $10, $08, $39, $09, $87, $FF, $FF, $01, $BF, $01, $BF, $02, $10, $03, $6B, $04, $87, $06, $BF, $06, $BF, $07, $10, $08, $39,
db $09, $87, $FF, $FF, $FF, $FF, $01, $BF, $01, $BF, $02, $00, $03, $6B, $04, $87, $06, $BF, $06, $BF, $07, $00, $08, $39, $09, $87, $FF, $FF, $FF, $FF, $02, $08, $03, $6B, $04, $87,
db $07, $08, $08, $39, $09, $87, $FE
SECTION "SFX Variables", HRAM
hPlayhead:: ds 2
SECTION "SFX Functions", ROM0
SFXInit::
; Audio on, volume on, and enable all channels.
ld a, $80
ldh [rNR52], a
ld a, $FF
ldh [rNR51], a
ld a, $77
ldh [rNR50], a
;xor a, a
;ldh [hPlayhead], a
;ldh [hPlayhead+1], a
ld a, LOW(sSFXNextPieceI)
ldh [hPlayhead], a
ld a, HIGH(sSFXNextPieceI)
ldh [hPlayhead+1], a
ret
SFXPlay::
; Load the playhead position into HL.
ldh a, [hPlayhead]
ld l, a
ldh a, [hPlayhead+1]
ld h, a
; Nothing to do if it's a null ptr.
or a, l
ret z
; Otherwise, get the register to write to.
.getRegister
ld a, [hl]
inc hl
; If it's $FE, then we're done.
cp a, $FE
jr nz, :+
xor a, a
ldh [hPlayhead], a
ldh [hPlayhead+1], a
ret
; If it's $FF, then we're done for this frame.
: cp a, $FF
jr z, .savePlayhead
; Otherwise, put the register in C.
add a, $10
ld c, a
; Get the value to write.
ld a, [hl]
inc hl
; Write it and loop.
ldh [$ff00+c], a
jr .getRegister
.savePlayhead
ld a, l
ldh [hPlayhead], a
ld a, h
ldh [hPlayhead+1], a
ret
ENDC

View File

@ -1,5 +1,5 @@
#Emulicious settings file #Emulicious settings file
#Mon Oct 16 07:51:58 CEST 2023 #Mon Oct 16 13:24:33 CEST 2023
WindowEventViewerWindowHeight=861 WindowEventViewerWindowHeight=861
WindowEventViewerWindowDivider=309 WindowEventViewerWindowDivider=309
WindowMemoryTracerWindowY=631 WindowMemoryTracerWindowY=631
@ -72,7 +72,7 @@ InterruptBreakpointEnabled=false
OutlineWidth=425 OutlineWidth=425
DebuggerEventFiltersGameBoy= DebuggerEventFiltersGameBoy=
GameBoyErrorBreakpointSuspend9=true GameBoyErrorBreakpointSuspend9=true
WindowMemoryEditorOpen=true WindowMemoryEditorOpen=false
GameBoyErrorBreakpointSuspend8=true GameBoyErrorBreakpointSuspend8=true
GameBoyErrorBreakpointSuspend7=true GameBoyErrorBreakpointSuspend7=true
WindowPaletteViewerY=619 WindowPaletteViewerY=619
@ -99,7 +99,7 @@ Gamepad1Key30=-1
BankSwapAtPCBreakpointEnabled=false BankSwapAtPCBreakpointEnabled=false
DebuggerMemorySelectedTab=HRAM DebuggerMemorySelectedTab=HRAM
WindowVideoViewerOpen=false WindowVideoViewerOpen=false
WindowMemoryEditorTabVisibleRect=0,160,583,384 WindowMemoryEditorTabVisibleRect=0,0,583,128
Gamepad1Key29=-1 Gamepad1Key29=-1
Gamepad1Key28=-1 Gamepad1Key28=-1
Gamepad1Key27=-1 Gamepad1Key27=-1
@ -135,7 +135,7 @@ Gamepad1Key13=-1
Gamepad1Key12=-1 Gamepad1Key12=-1
Gamepad1Key11=-1 Gamepad1Key11=-1
Gamepad1Key10=-1 Gamepad1Key10=-1
WindowMemoryEditorSelectedAddress=160 WindowMemoryEditorSelectedAddress=16
WindowMemoryEditorWidth=665 WindowMemoryEditorWidth=665
GameBoyErrorBreakpointCondition9= GameBoyErrorBreakpointCondition9=
GameBoyErrorBreakpointCondition8= GameBoyErrorBreakpointCondition8=
@ -154,7 +154,7 @@ Gamepad0Key35=-1
Gamepad0Key34=-1 Gamepad0Key34=-1
Gamepad0Key33=-1 Gamepad0Key33=-1
Gamepad0Key32=-1 Gamepad0Key32=-1
WindowMemoryEditorSelectedTab=RAM WindowMemoryEditorSelectedTab=I/O
Gamepad0Key31=-1 Gamepad0Key31=-1
Gamepad0Key30=-1 Gamepad0Key30=-1
SMSGamepadAThreshold=50 SMSGamepadAThreshold=50