-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.asm
1961 lines (1734 loc) · 52.5 KB
/
main.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
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
; marcel timm, rhinodevel, 2020mar17
; ---------------
; --- defines ---
; ---------------
dec_addr1 = 1;main/1000
dec_addr2 = 0;(main/100) MOD $a
dec_addr3 = 6;(main/10) MOD $a
dec_addr4 = 0;main MOD $a
; to be used with flag_pre variable:
;
flag_pre_pat_n = 1
flag_pre_pat_n_neg = 255 - flag_pre_pat_n
flag_pre_pat_l = 2
flag_pre_pat_l_neg = 255 - flag_pre_pat_l
flag_pre_rec = 4
flag_pre_rec_neg = 255 - flag_pre_rec
flag_pre_play = 8
flag_pre_play_neg = 255 - flag_pre_play
flag_pre_speed = 16
flag_pre_speed_neg = 255 - flag_pre_speed
flag_pre_loop = 32
flag_pre_loop_neg = 255 - flag_pre_loop
flag_pre_vibr = 64
flag_pre_vibr_neg = 255 - flag_pre_vibr
; to be used with flag_upd variable:
;
flag_upd_pat = 1
flag_upd_pat_neg = 255 - flag_upd_pat
;
flag_upd_rec = 4
flag_upd_rec_neg = 255 - flag_upd_rec
;
flag_upd_play = 8
flag_upd_play_neg = 255 - flag_upd_play
;
flag_upd_speed = 16
flag_upd_speed_neg = 255 - flag_upd_speed
;
flag_upd_loop = 32
flag_upd_loop_neg = 255 - flag_upd_loop
;
flag_upd_vibr = 64
flag_upd_vibr_neg = 255 - flag_upd_vibr
; to be used with variable named mode:
;
mode_normal = 0
mode_rec = 1
mode_play = 2
rec_is_waiting = $ee ; value indicates rec. mode waiting for first note.
note_none = $ff ; represents a pause "note" / no note.
; --------------
; --- macros ---
; --------------
defm macro_handle_note_but
ldx #</1
stx zero_word_buf1$
ldx #>/1
stx zero_word_buf1$ + 1
jsr handle_note_but
endm
; ----------------------
; --- basic "loader" ---
; ----------------------
* = sob$
word bas_next
word 7581
byte $9e ; sys token
byte chr_0$ + dec_addr1
byte chr_0$ + dec_addr2
byte chr_0$ + dec_addr3
byte chr_0$ + dec_addr4
byte ":"
byte $8f; rem token
text " (c) 2022, rhinodevel"
byte 0
bas_next word 0
; -----------------
; --- functions ---
; -----------------
; ************
; *** main ***
; ************
main cld ; (at least not necessary because of operating system)
; initialization stuff to be done before disabling interrupt service
; routine (because "jsr chrout$" does somehow cause waiting for retrace
; flag to not work correctly):
;
jsr init_basic
jsr init_linelen
jsr init_graphic80
clrscr$
sei
jsr init
wait_for_retrace_flag$ ; to make sure that first iterations starts when
; flag just got set to one (draw started).
infloop ; infinite loop.
wait_for_retrace_flag$
lda #note_none ; reset found notes to none.
sta fndnote1
sta fndnote2
; ********************
; *** key handling ***
; ********************
bit linelen$ + 1
bvc keyhandling40
jmp keyhandling80
; *******************************
; *** for 40 column machines: ***
; *******************************
keyhandling40
; *** row 0: ***
lda #0 ; set keyboard row to check (seems to be the way to do
sta pia1porta$ ; this, just "overwrite" whole port a with row nr.
; 0-9).
lda pia1portb$ ; loads row's data.
macro_handle_note_but notebut40_dis2$
macro_handle_note_but notebut40_fis2$
macro_handle_note_but notebut40_ais2$
; file
;
; <left arrow>
;
and #$20
bne filecheckdone40
;lda #31 + 128 ; 31 = <left arrow>. this is
;sta screen_ram$ + vram_offset40_file$ ; more or less academic (no one
; sees this..).
jmp file
filecheckdone40
; *** row 1: ***
lda #1
sta pia1porta$
lda pia1portb$
macro_handle_note_but notebut40_cis2$
macro_handle_note_but notebut40_gis2$
; exit
;
; )
;
and #$10
bne exitcheckdone40
;lda #41 + 128 ; 41 = ')'. this is more or less
;sta screen_ram$ + vram_offset40_exit$ ; academic (no one sees this..).
jmp exit
exitcheckdone40
; *** row 2: ***
lda #2
sta pia1porta$
lda pia1portb$
macro_handle_note_but notebut40_c02b$ ; (2 buttons used)
macro_handle_note_but notebut40_e002$
macro_handle_note_but notebut40_g002$
macro_handle_note_but notebut40_b002$
; record
;
; o
;
and #$10
beq pres2_10
lda flag_pre ; disable is-pressed flag.
and #flag_pre_rec_neg
sta flag_pre
lda mode ; keep reversed on screen, if record mode is already enabled.
cmp #mode_rec
beq done2_10
lda #'o'
sta screen_ram$ + vram_offset40_reco$
jmp done2_10
pres2_10 lda flag_pre
and #flag_pre_rec
bne done2_10 ; skips, if press already is processed.
lda flag_pre
ora #flag_pre_rec
sta flag_pre ; remember current key press to be already processed.
lda flag_upd
ora #flag_upd_rec
sta flag_upd ; request update.
lda #$0f + 128 ; $0f = 'o'.
sta screen_ram$ + vram_offset40_reco$
done2_10
; *** row 3: ***
lda #3
sta pia1porta$
lda pia1portb$
macro_handle_note_but notebut40_d002$
macro_handle_note_but notebut40_f002$
macro_handle_note_but notebut40_a002$
macro_handle_note_but notebut40_c003$ ; (highest note)
; play
;
; p
;
and #$10
beq pres3_10
lda flag_pre ; disable is-pressed flag.
and #flag_pre_play_neg
sta flag_pre
lda mode ; keep reversed on screen, if play mode is already enabled.
cmp #mode_play
beq done3_10
lda #'p'
sta screen_ram$ + vram_offset40_play$
jmp done3_10
pres3_10 lda flag_pre
and #flag_pre_play
bne done3_10 ; skips, if press already is processed.
lda flag_pre
ora #flag_pre_play
sta flag_pre ; remember current key press to be already processed.
lda flag_upd
ora #flag_upd_play
sta flag_upd ; request update.
lda #$10 + 128 ; $10 = 'p'.
sta screen_ram$ + vram_offset40_play$
done3_10
; *** row 4: ***
lda #4
sta pia1porta$
lda pia1portb$
macro_handle_note_but notebut40_dis1$
macro_handle_note_but notebut40_fis1$
macro_handle_note_but notebut40_ais1$
; loop
;
; l
;
and #$10
beq pres4_10
lda flag_pre ; disable is-pressed flag.
and #flag_pre_loop_neg
sta flag_pre
lda loop_val ; keep rev. on screen, if loop playback is alr. enabled.
bne done4_10 ; 0 = loop is disabled, $80 = loop is enabled.
lda #'l'
sta screen_ram$ + vram_offset40_loop$
jmp done4_10
pres4_10 lda flag_pre
and #flag_pre_loop
bne done4_10 ; skips, if press already is processed.
lda flag_pre
ora #flag_pre_loop
sta flag_pre ; remember current key press to be already processed.
lda flag_upd
ora #flag_upd_loop
sta flag_upd ; request update.
lda #$0c + 128 ; $0c = 'l'.
sta screen_ram$ + vram_offset40_loop$
done4_10
; *** row 5: ***
lda #5
sta pia1porta$
lda pia1portb$
macro_handle_note_but notebut40_cis1$
macro_handle_note_but notebut40_gis1$
; speed
;
; k
;
tax
and #8
beq pres5_08
lda flag_pre ; disable is-pressed flag.
and #flag_pre_speed_neg
sta flag_pre
lda #'k'
sta screen_ram$ + vram_offset40_spee$
jmp done5_08
pres5_08 lda flag_pre
and #flag_pre_speed
bne done5_08 ; skips, if press already is processed.
lda flag_pre
ora #flag_pre_speed
sta flag_pre ; remember current key press to be already processed.
lda flag_upd
ora #flag_upd_speed
sta flag_upd ; request update.
lda #$0b + 128 ; $0b = 'k'.
sta screen_ram$ + vram_offset40_spee$
done5_08 txa
; vibrato
;
; :
;
and #$10
beq pres5_10
lda flag_pre ; disable is-pressed flag.
and #flag_pre_vibr_neg
sta flag_pre
lda vibr_val ; keep rev. on screen, if vibrato is already enabled.
bne done5_10 ; 0 = vibrato is disabled, 1 = vibrato is enabled.
lda #':'
sta screen_ram$ + vram_offset40_vibr$
jmp done5_10
pres5_10 lda flag_pre
and #flag_pre_vibr
bne done5_10 ; skips, if press already is processed.
lda flag_pre
ora #flag_pre_vibr
sta flag_pre ; remember current key press to be already processed.
lda flag_upd
ora #flag_upd_vibr
sta flag_upd ; request update.
lda #58 + 128 ; 58 = ':'.
sta screen_ram$ + vram_offset40_vibr$
done5_10
; *** row 6: ***
lda #6
sta pia1porta$
lda pia1portb$
macro_handle_note_but notebut40_c001$ ; (lowest note)
macro_handle_note_but notebut40_e001$
macro_handle_note_but notebut40_g001$
macro_handle_note_but notebut40_b001$
; last-pattern
;
; ;
;
and #$10
beq pres6_10
lda flag_pre
and #flag_pre_pat_l_neg
sta flag_pre
lda #$3b ; $3b = ';'.
sta screen_ram$ + vram_offset40_patl$
jmp done6_10
pres6_10 lda flag_pre
and #flag_pre_pat_l
bne done6_10
lda flag_pre
ora #flag_pre_pat_l
sta flag_pre ; remember current key press to be already processed.
lda flag_upd
ora #flag_upd_pat
sta flag_upd ; request update.
dec patt_val
lda #$ff
cmp patt_val
bne set_pattern_l
lda #pattern_count$ - 1
sta patt_val
set_pattern_l
ldy patt_val
lda patterns$,y
sta pattern$
lda #$3b + 128 ; $3b = ';'.
sta screen_ram$ + vram_offset40_patl$
done6_10
; *** row 7: ***
lda #7
sta pia1porta$
lda pia1portb$
macro_handle_note_but notebut40_d001$
macro_handle_note_but notebut40_f001$
macro_handle_note_but notebut40_a001$
macro_handle_note_but notebut40_c02a$ ; (2 buttons used)
; next-pattern
;
; ?
;
and #$10
beq pres7_10
lda flag_pre ; disable is-pressed flag.
and #flag_pre_pat_n_neg
sta flag_pre
lda #'?'
sta screen_ram$ + vram_offset40_patn$
jmp done7_10
pres7_10 lda flag_pre
and #flag_pre_pat_n
bne done7_10 ; skips, if press already is processed.
lda flag_pre
ora #flag_pre_pat_n
sta flag_pre ; remember current key press to be already processed.
lda flag_upd
ora #flag_upd_pat
sta flag_upd ; request update.
inc patt_val
lda #pattern_count$
cmp patt_val
bne set_pattern_n
lda #0
sta patt_val
set_pattern_n
ldy patt_val
lda patterns$,y
sta pattern$
lda #$3f + 128 ; $3f = '?'.
sta screen_ram$ + vram_offset40_patn$
done7_10
jmp keyhandling_done
; *******************************
; *** for 80 column machines: ***
; *******************************
keyhandling80
; *** row 0: ***
lda #0
sta pia1porta$
lda pia1portb$
macro_handle_note_but notebut80_cis2$
macro_handle_note_but notebut80_fis2$
; *** row 1: ***
lda #1
sta pia1porta$
lda pia1portb$
macro_handle_note_but notebut80_ais2$
; exit
;
; '0'
;
and #8
bne exitcheckdone80
;lda #48 + 128 ; 48 = '0'. this is more or less
;sta screen_ram$ + vram_offset80_exit$ ; academic (no one sees this..).
jmp exit
exitcheckdone80
; *** row 2: ***
lda #2
sta pia1porta$
lda pia1portb$
macro_handle_note_but notebut80_cis1$
macro_handle_note_but notebut80_gis1$
; speed
;
; k
;
tax
and #$20
beq pres2_20_80
lda flag_pre ; disable is-pressed flag.
and #flag_pre_speed_neg
sta flag_pre
lda #'k'
sta screen_ram$ + vram_offset80_spee$
jmp don2_20_80
pres2_20_80
lda flag_pre
and #flag_pre_speed
bne don2_20_80 ; skips, if press already is processed.
lda flag_pre
ora #flag_pre_speed
sta flag_pre ; remember current key press to be already processed.
lda flag_upd
ora #flag_upd_speed
sta flag_upd ; request update.
lda #$0b + 128 ; $0b = 'k'.
sta screen_ram$ + vram_offset80_spee$
don2_20_80
txa
; vibrato
;
; ;
;
and #$40
beq pres2_40_80
lda flag_pre ; disable is-pressed flag.
and #flag_pre_vibr_neg
sta flag_pre
lda vibr_val ; keep rev. on screen, if vibrato is already enabled.
bne done2_40_80 ; 0 = vibrato is disabled, 1 = vibrato is enabled.
lda #59 ; 59 = ';'.
sta screen_ram$ + vram_offset80_vibr$
jmp done2_40_80
pres2_40_80
lda flag_pre
and #flag_pre_vibr
bne done2_40_80 ; skips, if press already is processed.
lda flag_pre
ora #flag_pre_vibr
sta flag_pre ; remember current key press to be already processed.
lda flag_upd
ora #flag_upd_vibr
sta flag_upd ; request update.
lda #59 + 128 ; 59 = ';'.
sta screen_ram$ + vram_offset80_vibr$
done2_40_80
; *** row 3: ***
lda #3
sta pia1porta$
lda pia1portb$
macro_handle_note_but notebut80_dis1$
macro_handle_note_but notebut80_fis1$
macro_handle_note_but notebut80_ais1$
; loop
;
; l
;
and #$20
beq pres3_20_80
lda flag_pre ; disable is-pressed flag.
and #flag_pre_loop_neg
sta flag_pre
lda loop_val ; keep rev. on screen, if loop playback is alr. enabled.
bne done3_20_80 ; 0 = loop is disabled, $80 = loop is enabled.
lda #'l'
sta screen_ram$ + vram_offset80_loop$
jmp done3_20_80
pres3_20_80
lda flag_pre
and #flag_pre_loop
bne done3_20_80 ; skips, if press already is processed.
lda flag_pre
ora #flag_pre_loop
sta flag_pre ; remember current key press to be already processed.
lda flag_upd
ora #flag_upd_loop
sta flag_upd ; request update.
lda #$0c + 128 ; $0c = 'l'.
sta screen_ram$ + vram_offset80_loop$
done3_20_80
; *** row 4: ***
lda #4
sta pia1porta$
lda pia1portb$
macro_handle_note_but notebut80_d002$
macro_handle_note_but notebut80_f002$
macro_handle_note_but notebut80_a002$
macro_handle_note_but notebut80_c003$
; play
;
; p
;
and #$40
beq pres4_40_80
lda flag_pre ; disable is-pressed flag.
and #flag_pre_play_neg
sta flag_pre
lda mode ; keep reversed on screen, if play mode is already enabled.
cmp #mode_play
beq done4_40_80
lda #'p'
sta screen_ram$ + vram_offset80_play$
jmp done4_40_80
pres4_40_80
lda flag_pre
and #flag_pre_play
bne done4_40_80 ; skips, if press already is processed.
lda flag_pre
ora #flag_pre_play
sta flag_pre ; remember current key press to be already processed.
lda flag_upd
ora #flag_upd_play
sta flag_upd ; request update.
lda #$10 + 128 ; $10 = 'p'.
sta screen_ram$ + vram_offset80_play$
done4_40_80
; *** row 5: ***
lda #5
sta pia1porta$
lda pia1portb$
macro_handle_note_but notebut80_c02b$
macro_handle_note_but notebut80_e002$
macro_handle_note_but notebut80_g002$
macro_handle_note_but notebut80_b002$
; record
;
; o
;
and #$20
beq pres5_20_80
lda flag_pre ; disable is-pressed flag.
and #flag_pre_rec_neg
sta flag_pre
lda mode ; keep reversed on screen, if record mode is already enabled.
cmp #mode_rec
beq done5_20_80
lda #'o'
sta screen_ram$ + vram_offset80_reco$
jmp done5_20_80
pres5_20_80
lda flag_pre
and #flag_pre_rec
bne done5_20_80 ; skips, if press already is processed.
lda flag_pre
ora #flag_pre_rec
sta flag_pre ; remember current key press to be already processed.
lda flag_upd
ora #flag_upd_rec
sta flag_upd ; request update.
lda #$0f + 128 ; $0f = 'o'.
sta screen_ram$ + vram_offset80_reco$
done5_20_80
; *** row 6: ***
lda #6
sta pia1porta$
lda pia1portb$
macro_handle_note_but notebut80_e001$
macro_handle_note_but notebut80_g001$
; last-pattern
;
; .
;
and #8
beq pres6_8_80
lda flag_pre
and #flag_pre_pat_l_neg
sta flag_pre
lda #'.'
sta screen_ram$ + vram_offset80_patl$
jmp done6_8_80
pres6_8_80
lda flag_pre
and #flag_pre_pat_l
bne done6_8_80
lda flag_pre
ora #flag_pre_pat_l
sta flag_pre ; remember current key press to be already processed.
lda flag_upd
ora #flag_upd_pat
sta flag_upd ; request update.
dec patt_val
lda #$ff
cmp patt_val
bne set_pattern_l_80
lda #pattern_count$ - 1
sta patt_val
set_pattern_l_80
ldy patt_val
lda patterns$,y
sta pattern$
lda #46 + 128 ; 46 = '.'.
sta screen_ram$ + vram_offset80_patl$
done6_8_80
; *** row 7: ***
lda #7
sta pia1porta$
lda pia1portb$
macro_handle_note_but notebut80_c001$
macro_handle_note_but notebut80_f001$
macro_handle_note_but notebut80_a001$
macro_handle_note_but notebut80_c02a$
; *** row 8: ***
lda #8
sta pia1porta$
lda pia1portb$
macro_handle_note_but notebut80_d001$
macro_handle_note_but notebut80_b001$
; next-pattern
;
; /
;
and #$40
beq pres8_40_80
lda flag_pre ; disable is-pressed flag.
and #flag_pre_pat_n_neg
sta flag_pre
lda #'/'
sta screen_ram$ + vram_offset80_patn$
jmp done8_40_80
pres8_40_80
lda flag_pre
and #flag_pre_pat_n
bne done8_40_80 ; skips, if press already is processed.
lda flag_pre
ora #flag_pre_pat_n
sta flag_pre ; remember current key press to be already processed.
lda flag_upd
ora #flag_upd_pat
sta flag_upd ; request update.
inc patt_val
lda #pattern_count$
cmp patt_val
bne set_pattern_n_80
lda #0
sta patt_val
set_pattern_n_80
ldy patt_val
lda patterns$,y
sta pattern$
lda #47 + 128 ; 47 = '/'.
sta screen_ram$ + vram_offset80_patn$
done8_40_80
; *** row 9: ***
lda #9
sta pia1porta$
lda pia1portb$
macro_handle_note_but notebut80_dis2$
macro_handle_note_but notebut80_gis2$
; file
;
; ':'
;
and #$20
bne filecheckdone80
;lda #58 + 128 ; 58 = ':'. this is more or less
;sta screen_ram$ + vram_offset80_file$ ; academic (no one sees this..).
jmp file
filecheckdone80
keyhandling_done
; ---
; change/update mode, if necessary:
;
lda flag_upd
and #flag_upd_play
beq mode_chk_rec ; no update because of play button necessary.
;
; update because of play button:
;
lda flag_upd
and #flag_upd_play_neg ; play button is handled.
and #flag_upd_rec_neg ; record but. is handled (play button overrules).
sta flag_upd
;
lda mode
beq play_enable ; switch from normal to play mode (normal mode = 0).
cmp #mode_rec
beq mode_no_upd ; must be in record mode, do nothing.
;
; disable play mode:
;
bne normal_enable ; (always branches, as play mode value is not 0)
;
; enable play mode (must be in normal mode):
;
play_enable
lda #<tune$
sta tune_ptr$
lda #>tune$
sta tune_ptr$ + 1
lda #1
sta countdwn
lda #0
sta countdwn + 1
sta note_nr
sta note_nr + 1
lda #mode_play
bne mode_upd ; (always branches, because play mode value is not zero)
;
; check, if record mode is enabled (play update must not be necessary):
;
mode_chk_rec
lda flag_upd
and #flag_upd_rec
beq mode_no_upd ; no update because of record button necessary.
;
; update because of record button:
;
lda flag_upd
and #flag_upd_rec_neg ; record button is handled.
sta flag_upd
;
lda mode
beq rec_enable ; switch from normal to record mode (normal = 0).
cmp #mode_play
beq mode_no_upd ; must be in play mode, do nothing.
;
; disable record mode:
;
lda note_nr
bne store_eot_and_count
lda note_nr + 1
beq normal_enable
store_eot_and_count
ldy #0
lda #0 ; end of tune marker.
sta (tune_ptr$),y
iny
sta (tune_ptr$),y
lda note_nr
sta note_cnt
lda note_nr + 1
sta note_cnt + 1
normal_enable
jsr drawnotecount
lda #mode_normal
beq mode_upd ; (always branches, because normal mode value is zero)
;
; enable record mode (must be in normal mode):
;
rec_enable
;lda #0 ; (a is always 0, here)
sta note_nr
sta note_nr + 1
; (don't show 0 as note nr., keep showing current note/pause count)
;
lda #rec_is_waiting ; indicates waiting for first note to be played by
sta rec_note ; user to start recording via timer.
lda #mode_rec
mode_upd
sta mode
mode_no_upd
; change speed, if necessary:
;
lda flag_upd
and #flag_upd_speed
beq speed_no_upd ; no update because of speed button necessary.
;
; update because of speed button:
;
lda flag_upd
and #flag_upd_speed_neg ; speed button is handled.
sta flag_upd
;
inc spee_val
lda #5 ; hard-coded speed maximum is this minus 1.
cmp spee_val
bne speed_draw
speed_to_one
lda #1
sta spee_val
speed_draw
jsr drawspeed
speed_no_upd
; enable/disable loop playback, if necessary:
;
lda flag_upd
and #flag_upd_loop
beq loop_no_upd ; no update because of loop button necessary.
;
; update because of loop button:
;
lda flag_upd
and #flag_upd_loop_neg ; loop button is handled.
sta flag_upd
;
lda loop_val
eor #$80 ; toggles loop enabled/disabled.
sta loop_val
loop_no_upd
; enable/disable vibrato, if necessary:
;
lda flag_upd
and #flag_upd_vibr
beq vibr_no_upd ; no update because of vibrato button necessary.
;
; update because of vibrato button:
;
lda flag_upd
and #flag_upd_vibr_neg ; vibrato button is handled.
sta flag_upd
;
lda vibr_val
eor #$80 ; toggles vibrato enabled/disabled.
sta vibr_val
;
bne vibr_no_upd ; if vibrato got disabled
lda playingn ; and there is a note
cmp #note_none ; currently
beq vibr_no_upd ; playing,
tay ; immediately (kind of hard-coded to do this here..)
lda notes$,y ; load notes' timer 2 low byte value
sta timer2_low$ ; and update register to disable vibrato offset that
; might be active.
vibr_no_upd
; do play mode stuff (before playing note), if play mode is active:
;
lda mode
cmp #mode_play
beq play_mode
jmp play_mode_stuff_end
;
; play mode:
;
play_mode
lda playingn
sta fndnote1
lda #note_none
sta fndnote2
;
ldy spee_val
countdown_dec
lda countdwn
bne countdown_dec_lsb ; skip dec. msb, because lsb is not zero.
dec countdwn + 1 ; dec. msb, because lsb will underflow.
countdown_dec_lsb
dec countdwn ; dec. lsb.
bne countdown_y_dec
lda countdwn + 1
beq countdown_next_note ; countdown already at zero, stop dec.
countdown_y_dec
dey
bne countdown_dec
;
lda countdwn
bne play_mode_stuff_end
lda countdwn + 1
bne play_mode_stuff_end
;
; next note of tune (if there is one), please:
;
countdown_next_note
ldy #0
lda (tune_ptr$),y ; load next note's length's low byte.
sta countdwn
inc tune_ptr$ ; incr. tune pointer to next note's length's high byte.
bne play_tune_ptr_inc_done1
inc tune_ptr$ + 1
play_tune_ptr_inc_done1
lda (tune_ptr$),y ; load next note's length's high byte.
sta countdwn + 1
bne play_next_note ; it really is a note's length, if high byte not 0.
lda countdwn