-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy patheditInstrument.asm
441 lines (390 loc) · 7.9 KB
/
editInstrument.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
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
;---------------------------------------------------------------
; EDIT Instrument
;---------------------------------------------------------------
editInstrument:
.IF SRAM_MAP=32
lda #SRAM_INSTRUMENT_BANK
jsr setMMC1r1
.ENDIF
ldx editorCurrentInstrument
lda editInstrumentAddressLo,x
sta instrumentVector
lda editInstrumentAddressHi,x
sta instrumentVector+1
ldy instrumentCursorY ;use Y (row) as index because only one column
lda writeScreen
beq @a
jsr writeInstrumentScreen
dec writeScreen
beq @a
jsr writeInstrumentHeaderFooter
lda #$01
sta dmaUpdateHeader
sta dmaUpdateTitle
lda #$00
sta writeScreen
@a: jsr globalKeys ;global keys
lda writeScreen ;if mode has changed, this flag will be !=0
beq @b
jmp editInstrumentExit ;if changed, don't do any more keys
@b: jsr processKeys
.IF SRAM_MAP=32
lda #SRAM_INSTRUMENT_BANK
jsr setMMC1r1
.ENDIF
ldy instrumentCursorY ;use Y (row) as index because only one column
jsr instrumentKeysHoldA_UDLR
jsr instrumentKeysTapA
jsr instrumentKeysTapB
jsr instrumentKeysHoldSelect_UDLR
jsr moveAroundEditor
editInstrumentExit:
updateCursor instrumentCursorX,instrumentCursorY,instrumentCursorColumns,instrumentCursorRows,instrumentColumnCursorType
jmp editorLoop
instrumentKeysHoldSelect_UDLR:
;rts ;*new controls*
lda PAD1_sel
beq @x
lda PAD1_fireb
ora PAD1_firea
bne @x
lda PAD1_dud
ora keysRepeatUD
beq @noUD
clc
adc editorCurrentInstrument
bpl @a
lda #$00
beq @b
@a: cmp #NUMBER_OF_INSTRUMENTS
bcs @x
@b: sta editorCurrentInstrument
lda #$02
sta writeScreen
rts
@noUD: lda PAD1_dlr
beq @x
bmi instrumentCopyData
jsr instrumentPasteData
@x: rts
instrumentCopyData:
lda editorMode
sta copyBufferObjectType
ldx editorCurrentInstrument
stx copyBufferObject
lda editInstrumentAddressLo,x
sta tmp0
lda editInstrumentAddressHi,x
sta tmp1
ldy #$00
sty copyBufferStartIndex
@copyLoop: lda (tmp0),y
sta copyBuffer,y
iny
cpy #(STEPS_PER_INSTRUMENT*BYTES_PER_INSTRUMENT_STEP)
bcc @copyLoop
sty copyBufferLength
@x:
jsr editorUpdateCopyInfo
rts
instrumentPasteData:
lda copyBufferObjectType
bmi @x ;nothing to copy
cmp editorMode
bne @x ;wrong object type
ldx editorCurrentInstrument
lda editInstrumentAddressLo,x
sta tmp0
lda editInstrumentAddressHi,x
sta tmp1
ldy #$00
@b: lda copyBuffer,y
sta (tmp0),y
iny
cpy copyBufferLength
bcc @b
@a: lda #$01
sta writeScreen
rts
@x: lda #ERROR_PASTE
sta errorMessageNumber
rts
instrumentKeysTapB:
lda PAD1_sel
beq @x
lda keysTapB
beq @x
lda instrumentClearValues,y
sta (instrumentVector),y
sta editBuffer
jsr editInstrumentUpdateScreenValue
@x: rts
instrumentKeysTapA:
lda keysTapA
beq @x
.IF 0=1
lda PAD1_fireb
beq @notDel
lda instrumentClearValues,y
sta (instrumentVector),y
sta editBuffer
jsr editInstrumentUpdateScreenValue
rts
.ENDIF
@notDel: lda PAD1_sel
beq @notClone
ldy instrumentCursorY ;use Y (row) as index because only one column
cpy #INSTRUMENT_ROW_DUTY
bne @notCloneDuty
lda (instrumentVector),y
cmp #$04 ;if Duty < 4 then not Duty Table
bcc @x
sbc #$04 ;subtract 4 to get Duty Table number
jsr instrumentCloneDuty
bcs @x ;carry set if pattern not cloned
ldy instrumentCursorY
clc
adc #$04
sta editBuffer
jmp @notClone
@notCloneDuty: cpy #INSTRUMENT_ROW_TABLE
bne @x
lda (instrumentVector),y
cmp #$FF
beq @x
jsr instrumentCloneTable
bcs @x
ldy instrumentCursorY
sta editBuffer
@notClone: ;lda keysHoldA
;beq @x
;lda editBuffer
;dec editBufferFlag
;sta (instrumentVector),y
;jsr editInstrumentUpdateScreenValue
@x: rts
instrumentKeysHoldA_UDLR:
lda PAD1_fireb;keysHoldB
beq @noB
rts
@noB: lda PAD1_firea;keysHoldA ;hold A + U/D/L/R = modify value
bne @holdA
lda editBufferFlag
beq @x
lda editBuffer
sta (instrumentVector),y
@notEditing: lda #$00
sta editBufferFlag
beq @x
@holdA: lda editBufferFlag
bne @editing
inc editBufferFlag
lda (instrumentVector),y
sta editBuffer
@editing: lda keysRepeatLR
ora PAD1_dlr
bne @addValue
lda keysRepeatUD
ora PAD1_dud
beq @x
bpl @negative
lda instrumentPositiveAdd,y
jmp @addValue
@negative: lda instrumentNegativeAdd,y
@addValue: clc
adc editBuffer
cpy #INSTRUMENT_ROW_GATE
beq @notTop0
cpy #INSTRUMENT_ROW_PSWEEP
beq @notTop0
cpy #INSTRUMENT_ROW_PSWEEPQ
beq @notTop0
cpy #INSTRUMENT_ROW_SWEEP
beq @notTop0
cpy #INSTRUMENT_ROW_DETUNE
beq @notTop0
and #$FF
bpl @notNeg0
lda #$00
beq @notTop0
@notNeg0: cmp instrumentMaxValues,y
bcc @notTop0
lda instrumentMaxValues,y
sec
sbc #$01
@notTop0: sta editBuffer
jsr editInstrumentUpdateScreenValue
@x: rts
instrumentCloneDuty:
rts
instrumentCloneTable:
rts
instrumentClearValues:
.BYTE $00 ;envelope
.BYTE $0F ;level
.BYTE 0 ;gate
.BYTE $00 ;duty
.BYTE $FF ;table
.BYTE 0 ;psweep
.BYTE 0 ;psweep q
.BYTE 0 ;sweep
.BYTE $FF ;vib
.BYTE 0 ;detune
.BYTE 0 ;hard
.BYTE $FF ;echo
instrumentPositiveAdd:
.BYTE $01 ;envelope
.BYTE $01 ;level
.BYTE $10 ;gate
.BYTE $01 ;duty
.BYTE $01 ;table
.BYTE $10 ;psweep
.BYTE $10 ;psweepq
.BYTE $10 ;sweep
.BYTE $01 ;vib
.BYTE $10 ;detune
.BYTE $01 ;hard
.BYTE $01 ;echo
instrumentNegativeAdd:
.BYTE -1 ;envelope
.BYTE -1 ;level
.BYTE -16 ;gate
.BYTE -1 ;duty
.BYTE -1 ;table
.BYTE -16 ;psweep
.BYTE -16 ;psweepq
.BYTE -16 ;sweep
.BYTE -1 ;vib
.BYTE -16 ;detune
.BYTE -1 ;hard
.BYTE -1 ;echo
instrumentMaxValues:
.BYTE NUMBER_OF_ENVELOPES
.BYTE $10 ;level
.BYTE 0 ;gate
.BYTE NUMBER_OF_DUTY_TABLES+$04
.BYTE NUMBER_OF_TABLES
.BYTE 0 ;psweep
.BYTE 0 ;psweepq
.BYTE 0 ;sweep
.BYTE NUMBER_OF_VIBRATOS
.BYTE 0 ;detune
.BYTE $10 ;hard
.BYTE NUMBER_OF_ECHOES ;echo
writeInstrumentScreen:
ldx #$00
lda #CHR_SPACE
@a: sta rowBuffer,x
inx
cpx #$20
bcc @a
lda #<windowInstrument
sta tmp0
lda #>windowInstrument
sta tmp1
ldy #$00
@c: lda (tmp0),y
sta windowBuffer,y
iny
cpy #(14*16)
bcc @c
ldx editorCurrentInstrument
lda editInstrumentAddressLo,x
sta tmp0
lda editInstrumentAddressHi,x
sta tmp1
ldx #$00
ldy #$00
@b: lda instrumentRowTable,y
tax
lda (tmp0),y
cpy #INSTRUMENT_ROW_DUTY
bne @notDuty
jsr instrumentPrintDuty
jmp @d
@notDuty: cpy #INSTRUMENT_ROW_TABLE
beq @table
cpy #INSTRUMENT_ROW_VIBRATO
beq @table
cpy #INSTRUMENT_ROW_ECHO
beq @table
;cpy #INSTRUMENT_ROW_AUX
;beq @table
@normal: jsr phexWindow
jmp @d
@table: cmp #$FF
bne @normal
printEmptyCell
@d: iny
cpy #instrumentModeRows
bcc @b
rts
writeInstrumentHeaderFooter:
ldx #$00 ;write header and title bars to buffer
@c: lda titleInstrument,x
sta titleBuffer,x
lda headerInstrument,x
sta headerBuffer,x
inx
cpx #$11
bne @c
ldx #$0D ;print current chain number in title bar
lda editorCurrentInstrument
jsr phexTitle
rts
editInstrumentUpdateScreenValue:
pha
lda instrumentRowTable,y
tax
pla
cpy #INSTRUMENT_ROW_DUTY
bne @notDuty
jsr instrumentPrintDuty
rts
@notDuty: cpy #INSTRUMENT_ROW_VIBRATO
beq @table
cpy #INSTRUMENT_ROW_TABLE
beq @table
cpy #INSTRUMENT_ROW_ECHO
beq @table
@normal: jsr phexWindow
rts
@table: cmp #$FF
bne @normal
printEmptyCell
rts
instrumentPrintDuty:
cmp #$04
bcs @hex
asl a
clc
adc #CHR_DUTY_00
sta windowBuffer,x
inx
adc #$01
sta windowBuffer,x
inx
rts
@hex: sbc #$04
jmp phexWindow
instrumentRowTable:
.REPEAT 16,i
.BYTE 9 + 14 + (i * 14)
.ENDREPEAT
instrumentCursorColumns:
.BYTE $53 + (9 * 8)
instrumentCursorRows:
.REPEAT 16,i
.BYTE $30 + (i * 8)
.ENDREPEAT
rowOffsetInstrument:
.REPEAT 16,i
.BYTE i*14
.ENDREPEAT
columnOffsetInstrument:
.BYTE 0
;
;0 = no cursor, 1=8x8, 2=8x16, 3=8x24
;
instrumentColumnCursorType:
.BYTE 2