aboutsummaryrefslogtreecommitdiff
path: root/src-z80/player/misc.z80
blob: fa823ab247e54a165022956691ecfb77f505c6ed (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
;****************************************************************************
; SetDelay* [event $FE, events $D0-$DF]
; Adds a delay in playback
;----------------------------------------------------------------------------
; breaks: c, de, hl
;****************************************************************************

SetDelaySFX:
    call SetDelay               ; We're just a wrapper
    jp DoTick_SFXSkip           ; End of subroutine

SetDelayBGM:
    call SetDelay               ; We're just a wrapper
    jp DoTick_BGMSkip           ; End of subroutine

SetDelaySFXShort:
    and $0F
    inc a
    ld b, a
    call SetDelayShort          ; We're just a wrapper
    jp DoTick_SFXSkip           ; End of subroutine

SetDelayBGMShort:
    and $0F
    inc a
    ld b, a
    call SetDelayShort          ; We're just a wrapper
    jp DoTick_BGMSkip           ; End of subroutine

SetDelay:
    PollPCM
    call GetParam               ; Get delay
    PollPCM

SetDelayShort:
    ex de, hl
    ld (hl), d                  ; Store new address
    dec l
    ld (hl), e
    dec l
    ld (hl), c

    PollPCM

    dec l                       ; Store new delay
    ld (hl), b

    ret                         ; End of subroutine

;****************************************************************************
; SetFlags [event $FA]
; Sets some of the flags.
;----------------------------------------------------------------------------
; breaks: c, de, hl
;****************************************************************************

SetFlagsSFX:
    call SetFlags
    jp ProcessSFXRun

SetFlagsBGM:
    call SetFlags
    jp ProcessBGMRun

SetFlags:
    PollPCM                     ; Get which flags to set
    call GetParam
    PollPCM
    
    ld a, (RAM_Flags)           ; Set the flags
    or b
    ld (RAM_Flags), a
    
    ret                         ; End of subroutine

;****************************************************************************
; ClearFlags [event $FB]
; Clears some of the flags.
;----------------------------------------------------------------------------
; breaks: c, de, hl
;****************************************************************************

ClearFlagsSFX:
    call ClearFlags
    jp ProcessSFXRun

ClearFlagsBGM:
    call ClearFlags
    jp ProcessBGMRun

ClearFlags:
    PollPCM                     ; Get which flags to clear
    call GetParam
    PollPCM
    
    ld a, (RAM_Flags)           ; Clear the flags
    and b
    ld (RAM_Flags), a
    
    ret                         ; End of subroutine

;****************************************************************************
; RefreshVolume
; Reloads the volume for all channels.
;----------------------------------------------------------------------------
; breaks: all
;****************************************************************************

RefreshVolume:
    ld hl, $1FF0                ; Update FM volume
    ld de, RAM_FMVol
    ld c, 8
.fixfmvol:
    ld a, (de)
    ld b, (hl)
    add b
    jp p, .fixfmvolok
    ld a, $7F
.fixfmvolok:
    ld b, a
    ld a, l
    and $07
    call SetFMVolTempLoad
    inc l
    inc e
    dec c
    PollPCM
    jr nz, .fixfmvol
    
    ld hl, $1FE8                ; Update PSG volume
    ld de, RAM_PSGData+1
    ld bc, $0410
.fixpsgvol:
    ld a, (hl)
    ld (de), a
    inc l
    ld a, e
    add a, c
    ld e, a
    PollPCM
    djnz .fixpsgvol
    
    xor a                       ; Mark that volume was refreshed
    ld ($1FF1), a
    
    ret                         ; End of subroutine