aboutsummaryrefslogtreecommitdiff
path: root/src-z80/core
diff options
context:
space:
mode:
Diffstat (limited to 'src-z80/core')
-rw-r--r--src-z80/core/bgm.z806
-rw-r--r--src-z80/core/direct.z8030
-rw-r--r--src-z80/core/main.z8035
-rw-r--r--src-z80/core/sfx.z8010
-rw-r--r--src-z80/core/vars.z806
5 files changed, 81 insertions, 6 deletions
diff --git a/src-z80/core/bgm.z80 b/src-z80/core/bgm.z80
index 2f57a73..338a7a6 100644
--- a/src-z80/core/bgm.z80
+++ b/src-z80/core/bgm.z80
@@ -97,6 +97,8 @@ ResumeBGM:
;****************************************************************************
; ProcessBGM
; Processes a tick for a BGM
+;----------------------------------------------------------------------------
+; breaks: all
;****************************************************************************
ProcessBGM:
@@ -153,6 +155,7 @@ ProcessBGMSkip:
cp $FE
jp z, SetDelayBGM ; Event $FE: set delay
cp $FF
+ProcessBGMEventFF:
jp z, StopBGMEvent ; Event $FF: stop BGM
cp $FC
jp z, LoopBGM ; Event $FC: loop BGM
@@ -192,8 +195,11 @@ ProcessBGMSkip:
cp $F8 ; Events $F0-$F7: set FM parameters
jp c, SetFMParamBGM
+ cp $FA ; Events $F8-$F9: set FM register
+ jp c, SetFMRegBGM
PollPCM ; FFFFFFFFF bad event >:(
+ProcessBGMEnd:
jp StopBGMEvent ; End of subroutine
ProcessBGMSkip2: ; This is where we land after a locked event
diff --git a/src-z80/core/direct.z80 b/src-z80/core/direct.z80
new file mode 100644
index 0000000..d796ddf
--- /dev/null
+++ b/src-z80/core/direct.z80
@@ -0,0 +1,30 @@
+;****************************************************************************
+; ProcessDirect
+; Processes the direct event stream.
+;----------------------------------------------------------------------------
+; breaks: all
+;****************************************************************************
+
+ProcessDirect:
+ ld a, ($1F00) ; Are there even events to process?
+ inc a
+ ret z
+
+ PollPCM
+
+ ld hl, ProcessDirectEnd ; Override $FF event
+ ld (ProcessBGMEventFF+1), hl
+
+ ld hl, $1F00 ; Where event data is stored
+ ld a, (RAM_LastBank) ; To avoid wasting time with bank
+ ld c, a ; switching
+
+ jp ProcessBGMRun ; Start processing the event
+
+ProcessDirectEnd:
+ ld hl, StopBGMEvent ; Restore $FF event
+ ld (ProcessBGMEventFF+1), hl
+ ld a, $FF ; Reset the stream
+ ld ($1F00), a
+
+ ret ; Return to the main loop
diff --git a/src-z80/core/main.z80 b/src-z80/core/main.z80
index da323f4..4eb6e5a 100644
--- a/src-z80/core/main.z80
+++ b/src-z80/core/main.z80
@@ -90,6 +90,8 @@ EntryPoint:
;****************************************************************************
; PollPCM
; Used to update PCM while not idle
+;----------------------------------------------------------------------------
+; breaks: af
;****************************************************************************
PollPCM: macro
@@ -154,21 +156,31 @@ IdleLoop:
;****************************************************************************
DoTick:
- ld a, (ix+0)
- bit 0, a
- call nz, UpdatePCM
+; ld a, (ix+0)
+; bit 0, a
+; call nz, UpdatePCM
- ld (ix+0), $27
+ PollPCM
+
+ ld (ix+0), $27 ; Retrigger the timer
ld (ix+1), $2F
PollPCM
+
+ ld a, ($1FF1) ; Refresh volume if needed
+ or a
+ call nz, RefreshVolume
DoTick_SFX: ; Process SFXs
jp DoTick_SFXSkip
DoTick_SFXSkip:
PollPCM
+
+ call ProcessDirect ; Process direct events
+ PollPCM
+
DoTick_BGM: ; Process BGMs
jp DoTick_BGMSkip
DoTick_BGMSkip:
@@ -257,6 +269,19 @@ LoadList:
;****************************************************************************
; GetParam
; Subroutine for getting the parameter byte
+;----------------------------------------------------------------------------
+; input c .... current bank
+; input hl ... current address
+;----------------------------------------------------------------------------
+; output b .... value
+; output c .... new bank
+; output hl ... new address
+;----------------------------------------------------------------------------
+; breaks: af
+;----------------------------------------------------------------------------
+; note: the C value gets incremented *only* when HL hits $0000 (this is
+; relevant if you consider using it to fetch from Z80 RAM, which should
+; never result in HL becoming $0000).
;****************************************************************************
GetParam:
@@ -270,7 +295,7 @@ GetParam:
BankSwitch
pop hl
.noswitchp:
- ld b, (hl) ; Get volume
+ ld b, (hl) ; Get value
inc l ; Get next address
jp nz, .nonewbankp
diff --git a/src-z80/core/sfx.z80 b/src-z80/core/sfx.z80
index 1c62873..4bca4c7 100644
--- a/src-z80/core/sfx.z80
+++ b/src-z80/core/sfx.z80
@@ -1,6 +1,8 @@
;****************************************************************************
; PlaySFX [command $02]
; Plays a SFX
+;----------------------------------------------------------------------------
+; breaks: all
;****************************************************************************
PlaySFX:
@@ -48,6 +50,8 @@ PlaySFX:
;****************************************************************************
; ProcessSFX
; Processes a tick for a SFX
+;----------------------------------------------------------------------------
+; breaks: all
;****************************************************************************
ProcessSFX:
@@ -147,10 +151,14 @@ ProcessSFXRun:
cp $F8 ; Events $F0-$F7: set FM parameters
jp c, SetFMParamSFX
+ cp $FA ; Events $F8-$F9: set FM register
+ jp c, SetFMRegSFX
;****************************************************************************
; StopSFX* [command $03, event $FF]
; Stops SFX playback
+;----------------------------------------------------------------------------
+; breaks: all
;****************************************************************************
StopSFXEvent:
@@ -186,6 +194,8 @@ StopSFX:
;****************************************************************************
; ClearSFX
; Clears SFX resources
+;----------------------------------------------------------------------------
+; breaks: all
;****************************************************************************
ClearSFX:
diff --git a/src-z80/core/vars.z80 b/src-z80/core/vars.z80
index 959711b..cd7162d 100644
--- a/src-z80/core/vars.z80
+++ b/src-z80/core/vars.z80
@@ -17,6 +17,7 @@ RAM_BGMFMInstr: ds 8 ; FM instruments used by BGM
RAM_BGMFMVol: ds 8 ; FM volumes used by BGM
RAM_BGMFMPan: ds 8, $C0 ; FM panning used by BGM
+RAM_FMVol: ds 8 ; FM volume of each channel
RAM_FMData: ds 8*5 ; FM info (for volume handling)
; ds 8*1 ... Register $B0
; ds 8*1 ... Register $40
@@ -25,6 +26,7 @@ RAM_FMData: ds 8*5 ; FM info (for volume handling)
; ds 8*1 ... Register $4C
RAM_Locked: ds 12 ; Locked channels
+RAM_PSGNote: ds 4 ; Current PSG notes
RAM_LastBank: ds 1 ; Last accessed bank
@@ -64,9 +66,11 @@ RAM_PointerList: equ $1C00
; 68000 communication variables
;****************************************************************************
-RAM_Stack: equ $1FF0 ; Where stack starts
+RAM_Stack: equ $1FE0 ; Where stack starts
+RAM_GlobalVol: equ $1FE0 ; Global volume for all channels
RAM_Status: equ $1FF0 ; Current playback status
+RAM_RefreshVol: equ $1FF1 ; Set to refresh all volumes
RAM_Command: equ $1FFF ; Command type
RAM_ComAddr: equ $1FFD ; Command address parameter
RAM_ComBank: equ $1FFC ; Command bank parameter