forked from arnaud-carre/LSPlayer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
LightSpeedPlayer.asm
281 lines (253 loc) · 7.43 KB
/
LightSpeedPlayer.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
;*****************************************************************
;
; Light Speed Player v1.13
; Fastest Amiga MOD player ever :)
; Written By Arnaud Carré (aka Leonard / OXYGENE)
; https://github.com/arnaud-carre/LSPlayer
; twitter: @leonard_coder
;
; "small & fast" player version ( average time: 1 scanline )
; Less than 512 bytes of code!
; You can also use generated "insane" player code for half scanline replayer (-insane option)
;
; LSP_MusicInit Initialize a LSP driver + relocate score&bank music data
; LSP_MusicPlayTick Play a LSP music (call it per frame)
; LSP_MusicGetPos Get mod seq pos (see -getpos option in LSPConvert)
; LSP_MusicSetPos Set mod seq pos (see -setpos option in LSPConvert)
;
;*****************************************************************
;------------------------------------------------------------------
;
; LSP_MusicInit
;
; In: a0: LSP music data(any memory)
; a1: LSP sound bank(chip memory)
; a2: DMACON low byte address (should be odd address!)
; Out:a0: music BPM pointer (16bits)
; d0: music len in tick count
;
;------------------------------------------------------------------
LSP_MusicInit:
cmpi.l #'LSP1',(a0)+
bne .dataError
move.l (a0)+,d0 ; unique id
cmp.l (a1),d0 ; check that sample bank is this one
bne .dataError
lea LSP_State(pc),a3
move.l a2,m_dmaconPatch(a3)
move.w #$8000,-1(a2) ; Be sure DMACon word is $8000 (note: a2 should be ODD address)
cmpi.w #$010b,(a0)+ ; v1.10 minimal major & minor version of latest compatible LSPConvert.exe
blt .dataError
movea.l a0,a4 ; relocation flag ad
addq.w #2,a0 ; skip relocation flag
move.w (a0)+,m_currentBpm(a3) ; default BPM
move.w (a0)+,m_escCodeRewind(a3)
move.w (a0)+,m_escCodeSetBpm(a3)
move.w (a0)+,m_escCodeGetPos(a3)
move.l (a0)+,-(a7) ; music len in frame ticks
move.w (a0)+,d0 ; instrument count
lea -12(a0),a2 ; LSP data has -12 offset on instrument tab ( to win 2 cycles in insane player :) )
move.l a2,m_lspInstruments(a3) ; instrument tab addr ( minus 4 )
subq.w #1,d0
move.l a1,d1
movea.l a0,a1 ; keep relocated flag
.relocLoop: tst.b (a4) ; relocation guard
bne.s .relocated
add.l d1,(a0)
add.l d1,6(a0)
.relocated: lea 12(a0),a0
dbf d0,.relocLoop
move.w (a0)+,d0 ; codes table size
move.l a0,m_codeTableAddr(a3) ; code table
add.w d0,d0
add.w d0,a0
; read sequence timing infos (if any)
move.w (a0)+,m_seqCount(a3)
beq.s .noSeq
move.l a0,m_seqTable(a3)
clr.w m_currentSeq(a3)
move.w m_seqCount(a3),d0
moveq #0,d1
move.w d0,d1
lsl.w #3,d1 ; 8 bytes per entry
add.w #12,d1 ; add 3 last 32bits (word stream size, byte stream loop, word stream loop)
add.l a0,d1 ; word stream data address
subq.w #1,d0
.seqRel: tst.b (a4)
bne.s .skipRel
add.l d1,(a0)
add.l d1,4(a0)
.skipRel: addq.w #8,a0
dbf d0,.seqRel
.noSeq: move.l (a0)+,d0 ; word stream size
move.l (a0)+,d1 ; byte stream loop point
move.l (a0)+,d2 ; word stream loop point
st (a4) ; mark this music score as "relocated"
move.l a0,m_wordStream(a3)
lea 0(a0,d0.l),a1 ; byte stream
move.l a1,m_byteStream(a3)
add.l d2,a0
add.l d1,a1
move.l a0,m_wordStreamLoop(a3)
move.l a1,m_byteStreamLoop(a3)
bset.b #1,$bfe001 ; disabling this fucking Low pass filter!!
lea m_currentBpm(a3),a0
move.l (a7)+,d0 ; music len in frame ticks
rts
.dataError: illegal
;------------------------------------------------------------------
;
; LSP_MusicPlayTick
;
; In: a6: should be $dff0a0
; Scratched regs: d0/d1/d2/a0/a1/a2/a3/a4/a5
; Out:None
;
;------------------------------------------------------------------
LSP_MusicPlayTick:
lea LSP_State(pc),a1
move.l (a1),a0 ; byte stream
move.l m_codeTableAddr(a1),a2 ; code table
.process: moveq #0,d0
.cloop: move.b (a0)+,d0
beq .cextended
add.w d0,d0
move.w 0(a2,d0.w),d0 ; code
beq .noInst
.cmdExec: add.b d0,d0
bcc.s .noVd
move.b (a0)+,$d9-$a0(a6)
.noVd: add.b d0,d0
bcc.s .noVc
move.b (a0)+,$c9-$a0(a6)
.noVc: add.b d0,d0
bcc.s .noVb
move.b (a0)+,$b9-$a0(a6)
.noVb: add.b d0,d0
bcc.s .noVa
move.b (a0)+,$a9-$a0(a6)
.noVa:
move.l a0,(a1)+ ; store byte stream ptr
move.l (a1),a0 ; word stream
tst.b d0
beq.s .noPa
add.b d0,d0
bcc.s .noPd
move.w (a0)+,$d6-$a0(a6)
.noPd: add.b d0,d0
bcc.s .noPc
move.w (a0)+,$c6-$a0(a6)
.noPc: add.b d0,d0
bcc.s .noPb
move.w (a0)+,$b6-$a0(a6)
.noPb: add.b d0,d0
bcc.s .noPa
move.w (a0)+,$a6-$a0(a6)
.noPa:
tst.w d0
beq.s .noInst
moveq #0,d1
move.l m_lspInstruments-4(a1),a2 ; instrument table
lea .resetv+12(pc),a4
lea 3*16(a6),a5
moveq #4-1,d2
.vloop: add.w d0,d0
bcs.s .setIns
add.w d0,d0
bcc.s .skip
move.l (a4),a3
move.l (a3)+,(a5)
move.w (a3)+,4(a5)
bra.s .skip
.setIns: add.w (a0)+,a2
add.w d0,d0
bcc.s .noReset
bset d2,d1
move.w d1,$96-$a0(a6)
.noReset: move.l (a2)+,(a5)
move.w (a2)+,4(a5)
move.l a2,(a4)
.skip: subq.w #4,a4
lea -16(a5),a5
dbf d2,.vloop
move.l m_dmaconPatch-4(a1),a3 ; dmacon patch
move.b d1,(a3) ; dmacon
.noInst: move.l a0,(a1) ; store word stream (or byte stream if coming from early out)
rts
.cextended: addi.w #$100,d0
move.b (a0)+,d0
beq.s .cextended
add.w d0,d0
move.w 0(a2,d0.w),d0 ; code
cmp.w m_escCodeRewind(a1),d0
beq.s .r_rewind
cmp.w m_escCodeSetBpm(a1),d0
beq.s .r_chgbpm
cmp.w m_escCodeGetPos(a1),d0
bne .cmdExec
.r_setPos: move.b (a0)+,(m_currentSeq+1)(a1)
bra .process
.r_rewind:
move.l m_byteStreamLoop(a1),a0
move.l m_wordStreamLoop(a1),m_wordStream(a1)
bra .process
.r_chgbpm: move.b (a0)+,(m_currentBpm+1)(a1) ; BPM
bra .process
.resetv: dc.l 0,0,0,0
;------------------------------------------------------------------
;
; LSP_MusicSetPos
;
; In: d0: seq position (from 0 to last seq of the song)
; Out:None
;
; Force the replay pointer to a seq position. If music wasn't converted
; using -setpos option, this func does nothing
;
;------------------------------------------------------------------
LSP_MusicSetPos:
lea LSP_State(pc),a3
move.w m_seqCount(a3),d1
beq.s .noTimingInfo
cmp.w d1,d0
bge.s .noTimingInfo
move.w d0,m_currentSeq(a3)
move.l m_seqTable(a3),a0
lsl.w #3,d0
add.w d0,a0
move.l (a0)+,m_wordStream(a3)
move.l (a0)+,m_byteStream(a3)
.noTimingInfo:
rts
;------------------------------------------------------------------
;
; LSP_MusicGetPos
;
; In: None
; Out: d0: seq position (from 0 to last seq of the song)
;
; Get the current seq position. If music wasn't converted with
; -getpos option, this func just returns 0
;
;------------------------------------------------------------------
LSP_MusicGetPos:
move.w (LSP_State+m_currentSeq)(pc),d0
rts
rsreset
m_byteStream: rs.l 1 ; 0 byte stream
m_wordStream: rs.l 1 ; 4 word stream
m_dmaconPatch: rs.l 1 ; 8 m_lfmDmaConPatch
m_codeTableAddr: rs.l 1 ; 12 code table addr
m_escCodeRewind: rs.w 1 ; 16 rewind special escape code
m_escCodeSetBpm: rs.w 1 ; 18 set BPM escape code
m_lspInstruments: rs.l 1 ; 20 LSP instruments table addr
m_relocDone: rs.w 1 ; 24 reloc done flag
m_currentBpm: rs.w 1 ; 26 current BPM
m_byteStreamLoop: rs.l 1 ; 28 byte stream loop point
m_wordStreamLoop: rs.l 1 ; 32 word stream loop point
m_seqCount: rs.w 1
m_seqTable: rs.l 1
m_currentSeq: rs.w 1
m_escCodeGetPos: rs.w 1
sizeof_LSPVars: rs.w 0
LSP_State: ds.b sizeof_LSPVars