-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy patheditSong.asm
640 lines (580 loc) · 10.1 KB
/
editSong.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
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
;---------------------------------------------------------------
; EDIT SONG
;---------------------------------------------------------------
editSong:
.IF SRAM_MAP=32
lda #SRAM_SONG_BANK
jsr setMMC1r1
.ENDIF
lda songCursorX ;get index into actual data to modify values
sta editorCurrentTrack
;tax
;lda editTrackAddressLo,x
;sta trackVector
;lda editTrackAddressHi,x
;sta trackVector+1
asl a
tax
lda songVectors,x
sta trackVector
lda songVectors+1,x
sta trackVector+1
lda songFirstRow
clc
adc songCursorY
sta songTrackIndex
tay
lda writeScreen ;need to write screen?
beq @a
bpl @thisTime
and #$7F
sta writeScreen
bpl @a
@thisTime: jsr writeSongScreen ;yes
dec writeScreen ;if writeScreen was 1, only write main window, else
beq @a ; write header and title too
jsr writeSongHeaderFooter
dec writeScreen ;reset screen writing flag
lda #$01
sta dmaUpdateHeader
sta dmaUpdateTitle
jmp editorLoop
@a: jsr globalKeys ;global keys
lda writeScreen ;if mode has changed, this flag will be !=0
beq @b
jmp editSongExit ;if changed, don't do any more keys
@b: jsr processKeys
.IF SRAM_MAP=32
lda #SRAM_SONG_BANK
jsr setMMC1r1
.ENDIF
ldy songTrackIndex
ldx songCursorX
jsr songKeysHoldA_UDLR
jsr songKeysTapA
jsr songKeysTapB
jsr songKeysDoubleTapA
jsr songKeysHoldAB_TapUDLR
jsr songKeysHoldB_UD
jsr moveAroundEditor ;global routine for moving around editors
editSongExit:
updateCursor songCursorX,songCursorY,songCursorColumns,songCursorRows,songColumnCursorType
jsr songPlayMarkers
jmp editorLoop
songKeysHoldB_UD: lda keysHoldB
beq @x
lda PAD1_firea
bne @x
lda PAD1_sel
bne @x
lda PAD1_dud
beq @x
lda editorCurrentSong
clc
adc PAD1_dud
bmi @x
cmp #NUMBER_OF_SONGS
bcs @x
sta editorCurrentSong
lda #$02
sta writeScreen
@noUD:
@x: rts
songKeysHoldAB_TapUDLR:
lda keysHoldA
beq @x
lda keysHoldB
beq @x
lda PAD1_dud
beq @noUD
bpl @down
jsr songDeleteRow
lda songFirstRow
clc
adc songCursorY
tay
lda (trackVector),y
cmp #$FF
beq @a
;sta editSongLastValue,x
sta editSongLastValue
@a: sta editBuffer
lda #$81 ;write next time
sta writeScreen
lda #$01
sta editBufferFlag
rts
@down: jsr songInsertRow
lda songFirstRow
clc
adc songCursorY
tay
lda (trackVector),y
sta editBuffer
lda #$81 ;write next time
sta writeScreen
lda #$01
sta editBufferFlag
rts
@noUD: lda PAD1_dlr
beq @x
@x: rts
songDeleteRow:
lda songFirstRow
clc
adc songCursorY
tay
cpy #STEPS_PER_TRACK-1
beq @x
@a: iny
lda (songVectors+$00),y
pha
lda (songVectors+$02),y
pha
lda (songVectors+$04),y
pha
lda (songVectors+$06),y
pha
lda (songVectors+$08),y
dey
sta (songVectors+$08),y
pla
sta (songVectors+$06),y
pla
sta (songVectors+$04),y
pla
sta (songVectors+$02),y
pla
sta (songVectors+$00),y
iny
cpy #STEPS_PER_TRACK-1
bcc @a
lda #$FF
sta (songVectors+$00),y
sta (songVectors+$02),y
sta (songVectors+$04),y
sta (songVectors+$06),y
sta (songVectors+$08),y
@x:
rts
songInsertRow:
lda songFirstRow
clc
adc songCursorY
cmp #STEPS_PER_TRACK-1
beq @x
sta tmp0
ldy #STEPS_PER_TRACK-1
@a: dey
lda (songVectors+$00),y
pha
lda (songVectors+$02),y
pha
lda (songVectors+$04),y
pha
lda (songVectors+$06),y
pha
lda (songVectors+$08),y
iny
sta (songVectors+$08),y
pla
sta (songVectors+$06),y
pla
sta (songVectors+$04),y
pla
sta (songVectors+$02),y
pla
sta (songVectors+$00),y
dey
cpy tmp0
beq @x
bcs @a
@x: rts
songPlayMarkers:
lda writeScreen
beq @go
;rts
@go: ldx #$00
@a: lda plyrPlaying
and SetBits,x
bne @show
@noShow: inx
cpx #$05
bcc @a
rts
@show: lda songFirstRow
clc
adc #$10
sta tmp0
lda plyrTrackIndex,x
cmp songFirstRow
bcc @noShow
cpy tmp0
bcs @noShow
sec
sbc songFirstRow
tay
lda songCursorRows,y
sec
sbc #$01
pha
txa
asl a
asl a
tay
lda #SPR_RIGHT_ARROW
sta SPR05_CHAR,y
pla
sta SPR05_Y,y
lda twentyFour,x
clc
adc #$4B
sta SPR05_X,y
jmp @noShow
twentyFour: .BYTE 0*24,1*24,2*24,3*24,4*24
songKeysHoldA_UDLR:
ldx songCursorX
lda PAD1_fireb;keysHoldB
ora PAD1_sel
beq @noB
rts
@noB: lda keysHoldA ;hold A + U/D/L/R = modify value
bne @holdA
lda editBufferFlag
beq @x
lda editBuffer
sta (trackVector),y
@notEditing: lda #$00
sta editBufferFlag
beq @x
@holdA: lda editBufferFlag
bne @editing
inc editBufferFlag
lda (trackVector),y
cmp #$FF
bne @notEmpty
;lda editSongLastValue,x
lda editSongLastValue
@notEmpty: sta editBuffer
jsr editSongUpdateScreenValue
ldx songCursorX
@editing: lda keysRepeatLR
ora PAD1_dlr
bne @addValue
lda keysRepeatUD
ora PAD1_dud
beq @x
bpl @subBig
lda songAddBig,x
jmp @addValue
@subBig: lda songSubBig,x
@addValue: clc
adc editBuffer
bpl @notNeg
lda #$00
beq @notTop
@notNeg: cmp #NUMBER_OF_CHAINS
bcc @notTop
lda #NUMBER_OF_CHAINS-1
@notTop: sta editBuffer
jsr editSongUpdateScreenValue
@x: rts
songKeysDoubleTapA: lda keysDoubleTapA
beq @x
lda PAD1_fireb
ora PAD1_sel
bne @x
ldx songCursorX
;lda editSongLastValue,x
lda editSongLastValue
jsr songFindNextUnusedChain
bmi @x
ldx songCursorX
;sta editSongLastValue,x
sta editSongLastValue
sta (trackVector),y
jsr editSongUpdateScreenValue
lda (trackVector),y
tax
.IF SRAM_MAP=32
lda #SRAM_HEADER_BANK
jsr setMMC1r1
.ENDIF
lda SRAM_CHAIN_FLAGS,x
ora #$01
sta SRAM_CHAIN_FLAGS,x
.IF SRAM_MAP=32
lda #SRAM_SONG_BANK
jsr setMMC1r1
.ENDIF
@x: rts
songKeysTapB: lda PAD1_sel
beq @x
lda keysTapB
beq @x
lda #$FF
sta (trackVector),y
sta editBuffer
jsr editSongUpdateScreenValue
@x: rts
songKeysTapA: ldx songCursorX
lda keysTapA
beq @a
.IF 0=1
@b: lda PAD1_fireb
beq @notDel
lda #$FF
sta (trackVector),y
sta editBuffer
jsr editSongUpdateScreenValue
rts
.ENDIF
@notDel: lda PAD1_sel
beq @notClone
ldy songTrackIndex
lda (trackVector),y
cmp #$FF
beq @a
jsr songCloneChain
bcs @x ;carry set if pattern not cloned
ldx songCursorX
ldy songTrackIndex
;sta editSongLastValue,x
sta editSongLastValue
@notClone: .IF SRAM_MAP=32
lda #SRAM_SONG_BANK
jsr setMMC1r1
.ENDIF
;lda editSongLastValue,x
lda editSongLastValue
sta (trackVector),y
sta editBuffer
jsr editSongUpdateScreenValue
lda (trackVector),y
tax
.IF SRAM_MAP=32
lda #SRAM_HEADER_BANK
jsr setMMC1r1
.ENDIF
lda SRAM_CHAIN_FLAGS,x
ora #$01
sta SRAM_CHAIN_FLAGS,x
.IF SRAM_MAP=32
lda #SRAM_SONG_BANK
jsr setMMC1r1
.ENDIF
@a: rts
@x: lda #ERROR_NO_FREE_CHAINS
sta errorMessageNumber
.IF SRAM_MAP=32
lda #SRAM_SONG_BANK
jsr setMMC1r1
.ENDIF
rts
songCloneChain: lda #$00
sta tmp0
@a: jsr songFindNextUnusedChain
bmi @noUnused
sta tmp0
jsr songIsChainEmpty
bcc @unused
inc tmp0
lda tmp0
cmp #NUMBER_OF_CHAINS
bcc @a
@noUnused: sec
rts
@unused: ldy songTrackIndex
.IF SRAM_MAP=32
lda #SRAM_SONG_BANK
jsr setMMC1r1
.ENDIF
lda (trackVector),y
tax
lda editChainAddressLo,x
sta tmp1
lda editChainAddressHi,x
sta tmp2
.IF SRAM_MAP=32
lda #SRAM_CHAIN_BANK
jsr setMMC1r1
.ENDIF
ldy #$00
@b: lda (tmp1),y
sta (chainVector),y
iny
cpy #(STEPS_PER_CHAIN * BYTES_PER_CHAIN_STEP)
bcc @b
.IF SRAM_MAP=32
lda #SRAM_SONG_BANK
jsr setMMC1r1
.ENDIF
clc
lda tmp0
rts
;IN : A=chain to check
;OUT
songIsChainEmpty: tax
lda editChainAddressLo,x
sta chainVector
lda editChainAddressHi,x
sta chainVector+1
.IF SRAM_MAP=32
lda #SRAM_CHAIN_BANK
jsr setMMC1r1
.ENDIF
ldy #$00
@a: lda (chainVector),y
bpl @notEmpty
iny
iny
cpy #(STEPS_PER_CHAIN * BYTES_PER_CHAIN_STEP)
bcc @a
clc
rts
@notEmpty: sec
rts
;
;In : A=pattern number to start search from
;OUT : A = free pattern, if $FF then no free pattern
;
songFindNextUnusedChain:
pha
.IF SRAM_MAP=32
lda #SRAM_HEADER_BANK
jsr setMMC1r1
.ENDIF
pla
tax
ldx #$00
@a: lda SRAM_CHAIN_FLAGS,x
beq @x
inx
cpx #NUMBER_OF_CHAINS
bcc @a
ldx #$FF
@x: .IF SRAM_MAP=32
lda #SRAM_SONG_BANK
jsr setMMC1r1
.ENDIF
txa
rts
songAddSmall:
.BYTE 1,1,1,1,1
songSubSmall: .BYTE -1-1-1-1-1
songAddBig: .BYTE 16,16,16,16,16
songSubBig: .BYTE -16,-16,-16,-16,-16
editSongUpdateScreenValue:
pha
ldx songCursorY
lda rowOffsetSong,x
ldx songCursorX
clc
adc columnOffsetSong,x
tax
pla
cmp #$FF
bne @normal
printEmptyCell
rts
@normal: stx tmp0
ldx songCursorX
;sta editSongLastValue,x
sta editSongLastValue
ldx tmp0
jsr phexWindow
@c: rts
writeSongScreen:
ldx #$00
ldy songFirstRow ;first write row numbers to buffer
@a: tya
jsr phexRow
iny
cpx #$20
bcc @a
lda songFirstRow
tay
ldx #$00
@b: lda (songVectors+$00),y
cmp #NUMBER_OF_CHAINS
bcc @b1
printEmptyCell
jmp @b2
@b1: jsr phexWindow
@b2:
lda #CHR_SPACE
sta windowBuffer,x
inx
lda (songVectors+$02),y
cmp #NUMBER_OF_CHAINS
bcc @b3
printEmptyCell
jmp @b4
@b3: jsr phexWindow
@b4:
lda #CHR_SPACE
sta windowBuffer,x
inx
lda (songVectors+$04),y
cmp #NUMBER_OF_CHAINS
bcc @b5
printEmptyCell
jmp @b6
@b5: jsr phexWindow
@b6:
lda #CHR_SPACE
sta windowBuffer,x
inx
lda (songVectors+$06),y
cmp #NUMBER_OF_CHAINS
bcc @b7
printEmptyCell
jmp @b8
@b7: jsr phexWindow
@b8:
lda #CHR_SPACE
sta windowBuffer,x
inx
lda (songVectors+$08),y
cmp #NUMBER_OF_CHAINS
bcc @b9
printEmptyCell
jmp @b10
@b9: jsr phexWindow
@b10: iny
cpx #224
bcs @x
jmp @b
@x: rts
writeSongHeaderFooter:
ldx #$00 ;write header and title bars to buffer
@c: lda titleSong,x
sta titleBuffer,x
lda headerSong,x
sta headerBuffer,x
inx
cpx #$11
bne @c
ldx #$07 ;print current chain number in title bar
lda editorCurrentSong
jsr phexTitle
rts
songCursorColumns:
.REPEAT 5,i
.BYTE $53+(i*24)
.ENDREPEAT
songCursorRows:
.REPEAT 16,i
.BYTE $28+(i*8)
.ENDREPEAT
rowOffsetSong:
.REPEAT 16,i
.BYTE i*14
.ENDREPEAT
columnOffsetSong:
.BYTE 0,3,6,9,12
;
;0 = no cursor, 1=8x8, 2=8x16, 3=8x24
;
songColumnCursorType:
.BYTE 2,2,2,2,2