forked from idrougge/blitz_ptplayer
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathblitz_ptplayer.asm
281 lines (234 loc) · 5.94 KB
/
blitz_ptplayer.asm
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
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
; Amiga Blitz Basic Library wrapper of PT Player by Frank Wille (PHX) in 2013, 2016-2024.
; Converted to BlitzBasic library by E-Penguin based on work by idrougge
; Wrapper concept and macros by earok
include "blitz.i"
; Blitz Libraries used
audiolib equ 116
banklib equ 76
; This Blitz library
ptplayerlib equ 48
libheader ptplayerlib,0,0,blitz_finit,0
astatement
args word,byte
libs banklib,$1080
subs MTInit_bank,0,0
args long,long,byte
libs
subs MTInit,0,0
name "MTInit","Bank#, startpos | module addr, instr addr, startpos (inserts module into player)",0
astatement
args byte
libs
subs MTInstall,0,0
name "MTInstall","Install player routine. PAL=true, NTSC=false",0
astatement
args byte
libs
subs MTPlay,0,0
name "MTPlay","On/Off for module playback",0
astatement
args
libs
subs MTRemove,0,0
name "MTRemove","Remove player from system",0
astatement
args
libs
subs MTEnd,0,0
name "MTEnd","Stop playing current module",0
astatement
args long,word,word,word
libs
subs MTSoundFX,0,0
args word,word
libs audiolib,$1080
subs MTSoundFX_soundobject,0,0
name "MTSoundFX","Sound#, volume (0..64)| sample_addr.l, length.w, period.w, volume.w"
afunction long
args long
libs
subs MTPlayFx,0,0
name "MTPlayFx","SfxStructurePointer, returns SfxChanStatus pointer"
astatement
args word
libs
subs MTMasterVolume,0,0
name "MTMasterVolume","Master volume (0..64) for all music channels."
astatement
args byte
libs
subs MTMusicMask,0,0
name "MTMusicMask","Set bits 0-3 to reserve channels for music only."
astatement
args byte
libs
subs MTMusicChannels,0,0
name "MTMusicChannels","number of channels dedicated to music."
afunction byte
args
libs
subs MTE8Trigger,0,0
name "MTE8Trigger","Value of the last E8 command."
astatement
args long
libs
subs MTLoopFx,0,0
name "MTLoopFx","SfxStructurePointer"
astatement
args byte
libs
subs MTStopFx,0,0
name "MTStopFx","channel to stop FX loop"
astatement
args word,byte
libs
subs MTSampleVolume,0,0
name "MTSampleVolume", "Redefine a sample's volume"
astatement
args byte
libs
subs MTChannelMask,0,0
name "MTChannelMask", "Clear bits 0-3 to mute channel for music"
astatement
args byte
libs
subs MTSetSongEnd,0,0
name "MTSetSongEnd","Set value of the mt_SongEnd flag to 0xFF to end after it has finished"
afunction byte
args
libs
subs MTIsEnabled,0,0
name "MTIsEnabled","Get status of playback"
blitz_finit:
nullsub _blitz_mt_lib_finit,0,0 ; Call deinit routine on exit
libfin ; End of Blitz library header
; Deinitialisation for Blitz so that user doesn't have to call MTRemove
_blitz_mt_lib_finit:
bra _mt_remove_cia
;--------------------
; Macros by earok / Scorpion
; https://github.com/earok/ptplayer_blitzwrapper_scorpion
storeAddressRegisters macro
movem.l a4-a6,-(sp) ; Save registers for Blitz 2
lea CUSTOM,a6 ;Store the custom register in A6
endm
storeAddressRegistersVBR macro
movem.l a4-a6,-(sp) ; Save registers for Blitz 2
;Load vector base into A0
sub.l a0,a0
move.l 4.w,a6
btst #0,297(a6) ; check for 68010
beq .novbr
lea getvbr(pc),a5
jsr -30(a6) ; Supervisor()
.novbr: lea CUSTOM,a6
endM
restoreAddressRegisters macro
movem.l (sp)+,a4-a6 ; Restore registers for Blitz
rts ;Return to Blitz
endm
;--------------------
; VBR Hack by phx
; https://eab.abime.net/showpost.php?p=1516508&postcount=7
;----- Get VBR 68010+ ---
mc68010
getvbr:
movec vbr,a0
rte
mc68000
;------------------------
; Install a CIA-B interrupt for calling mt_music.
MTInstall:
storeAddressRegistersVBR
jsr _mt_install_cia
restoreAddressRegisters
MTRemove:
storeAddressRegisters
jsr _mt_remove_cia
restoreAddressRegisters
;---------------------------------------------------------------------------
;_mt_init:
; Initialize new module.
; Reset speed to 6, tempo to 125 and start at given song position.
; Master volume is at 64 (maximum).
; --- Init for Blitz ----
MTInit_bank:
move.l #0,a1 ; Set sample pointer to NULL
move.b d1,d0 ; Set starting position
move.l (a0),a0 ; Set module address
bra MTInit_done
MTInit:
move.l D0,A0 ; a0 = module pointer
move.l D1,A1 ; a1 = sample pointer (NULL means samples are stored within the module)
move.w D2,D0 ; d0 = initial song position
MTInit_done:
storeAddressRegisters
jsr _mt_init
restoreAddressRegisters
MTEnd:
storeAddressRegisters
jsr _mt_end
restoreAddressRegisters
MTPlay:
move.b d0,_mt_Enable
rts
MTIsEnabled:
move.b _mt_Enable,d0
rts
MTSetSongEnd:
; Set mt_SongEnd to 0xFF to stop after current song is played
move.b d0,mt_SongEnd(a4)
rts
;-------------------------------------
MTSoundFX_soundobject:
move.w d1,d2 ; volume
move.w 4(a0),d1 ; period
move.w 6(a0),d0 ; length
move.l (a0),a0 ; sample data
bra MTSoundFX_done
MTSoundFX:
move.l D0,A0 ;a0 = sample pointer
move.w D1,D0 ;d0.w = sample length in words
move.w D2,D1 ;d1.w = sample period
Move.w D3,D2 ;d2.w = sample volume
MTSoundFX_done:
storeAddressRegisters
jsr _mt_soundfx
restoreAddressRegisters
MTPlayFx:
storeAddressRegisters
move.l D0,A0 ;a0=SfxStructurePointer
jsr _mt_playfx
restoreAddressRegisters
MTLoopFx:
storeAddressRegisters
move.l D0,A0 ;a0=SfxStructurePointer
jsr _mt_loopfx
restoreAddressRegisters
MTStopFx:
storeAddressRegisters
jsr _mt_stopfx
restoreAddressRegisters
MTMusicMask:
storeAddressRegisters
jsr _mt_musicmask
restoreAddressRegisters
MTMasterVolume:
storeAddressRegisters
jsr _mt_mastervol
restoreAddressRegisters
MTSampleVolume:
storeAddressRegisters
jsr _mt_samplevol
restoreAddressRegisters
MTChannelMask:
storeAddressRegisters
jsr _mt_channelmask
restoreAddressRegisters
MTMusicChannels:
move.b d0,_mt_MusicChannels
rts
MTE8Trigger:
move.b _mt_E8Trigger,d0
rts
include "ptplayer.asm"