10
20
30
40
50
60 MODE7
70 :
80 DIM CODE 1023
90 DIM data 10399+4:STORE=data+4
100 DIM CLOCK 4
110 :
120 :
130 ?&72=STORE MOD 256
140 ?&73=STORE DIV 256
150 notecountl=&74
160 notecounth=&75
170 pointer=&70
180 pointerh=&71
190 OSWORD=&FFF1
200 OSBYTE=&FFF4
210 midi=&FCF1
220 status=&FCF0
230 last=&7F:?last=&90
240 :
250 :
260 FOR I%=0 TO 2 STEP2
270 P%=CODE
280 [OPT I%
290 .firstnote
300 LDA #0
310 STA CLOCK
320 STA CLOCK+1
330 STA CLOCK+2
340 STA CLOCK+3
350 STA CLOCK+4
360 STA notecountl
370 STA notecounth
380 LDA &72
390 STA &70
400 LDA &73
410 STA &71
420 .start
430 LDA status
440 AND #1
450 BEQ start
460 LDA #2
470 LDX #CLOCK MOD 256
480 LDY #CLOCK DIV 256
490 JSR OSWORD
500 :
510 :
520 .getnote
530 LDX #0
540 LDY #0
550 LDA midi
560 BMI comm_byte
570 PHA:LDA last
580 STA (pointer),Y
590 JSR increment
600 PLA:BPL note_got
610 .comm_byte
620 STA last
630 STA (pointer),Y
640 JSR increment
650 .note
660 LDA status
670 AND #1
680 BEQ note
690 LDA midi
700 .note_got
710 STA (pointer),Y
720 JSR increment
730 .tail
740 LDA status
750 AND #1
760 BEQ tail
770 LDA midi
780 STA (pointer),Y
790 JSR increment
800 JSR addnote
810 JSR timing
820 .next
830 LDA #255
840 CMP &78
850 BEQ tobasic
860 LDA status
870 AND #1
880 BEQ next
890 JMP getnote
900 :
910 :
920 .increment
930 INC &70
940 BNE nocarry
950 INC &71
960 .nocarry
970 RTS
980 :
990 :
1000 .key
1010 PHP
1020 LDA #255
1030 STA &78
1040 PLA
1050 RTS
1060 :
1070 :
1080 .timing
1090 LDA #1
1100 LDX #CLOCK MOD 256
1110 LDY #CLOCK DIV 256
1120 JSR OSWORD
1130 LDY #0
1140 LDA CLOCK
1150 STA (pointer),Y
1160 JSR increment
1170 LDA CLOCK+1
1180 STA (pointer),Y
1190 JSR increment
1200 RTS
1210 :
1220 :
1230 .addnote
1240 INC notecountl
1250 BNE nohi
1260 INC notecounth
1270 LDA notecounth
1280 CMP #8
1290 BNE nohi
1300 BRK
1310 EQUB 100
1320 EQUS "Note store full"
1330 BRK
1340 .nohi
1350 RTS
1360 :
1370 :
1380 .tobasic
1390 BRK
1400 EQUB 102
1410 EQUS "Key pressed"
1420 BRK
1430 :
1440 :
1450 .wait
1460 LDA #&91
1470 LDX #0
1480 LDY #0
1490 JSR OSBYTE
1500 BCC tobasic
1510 LDX #CLOCK MOD 256
1520 LDY #CLOCK DIV 256
1530 LDA #1
1540 JSR OSWORD
1550 LDY #4
1560 LDA CLOCK+1
1570 CMP (pointer),Y
1580 BEQ lobyte
1590 BCS outwait
1600 BCC wait
1610 .lobyte
1620 DEY
1630 LDA CLOCK
1640 CMP (pointer),Y
1650 BCC wait
1660 .outwait
1670 RTS
1680 :
1690 .firstplay
1700 :
1710 LDA #0
1720 STA CLOCK
1730 STA CLOCK+1
1740 STA CLOCK+2
1750 STA CLOCK+3
1760 STA CLOCK+4
1770 LDA &72
1780 STA &70
1790 LDA &73
1800 STA &71
1810 LDA &74
1820 STA &76
1830 LDA &75
1840 STA &77
1850 LDA #2
1860 LDX #CLOCK MOD 256
1870 LDY #CLOCK DIV 256
1880 JSR OSWORD
1890 JSR nextnote
1900 .playnote
1910 JSR wait
1920 LDA status
1930 AND #2
1940 BEQ playnote
1950 LDY #0
1960 LDA (pointer),Y
1970 STA midi
1980 JSR increment
1990 .noteval
2000 LDA status
2010 AND #2
2020 BEQ noteval
2030 LDA (pointer),Y
2040 STA midi
2050 JSR increment
2060 .thirdval
2070 LDA status
2080 AND #2
2090 BEQ thirdval
2100 LDA (pointer),Y
2110 STA midi
2120 JSR increment
2130 JSR increment
2140 JSR increment
2150 JSR nextnote
2160 JMP playnote
2170 :
2180 :
2190 .nextnote
2200 DEC &76
2210 LDA &76
2220 CMP #255
2230 BNE nextout
2240 DEC &77
2250 LDA &77
2260 CMP #255
2270 BNE nextout
2280 BRK
2290 EQUB 101
2300 EQUS "All notes played"
2310 BRK
2320 .nextout
2330 RTS
2340 ]
2350 NEXT I%
2360 :
2370 :
2380 ON ERROR GOTO 2650
2390 :
2400 :
2410 CLS
2420 ?status=3
2430 ?status=21
2440 ?&220=key MOD 256:?&221=key DIV 256
2450 REPEAT
2460 PRINTTAB(5,1)"EE MIDI Tracker"
2470 PRINTTAB(5,4)"Press R to record"
2480 PRINTTAB(5,6)"Press P to playback"
2490 PRINTTAB(5,8)"Press L to load file"
2500 PRINTTAB(5,10)"Press S to save file"
2510 PRINTTAB(5,12)"Press any key to stop recording"'TAB(5)"or playing back, except Esc"
2520 PRINTTAB(5,15)"Press Escape to quit program"
2530 IF(!&74 AND&FFFF)>0 PRINTTAB(5,17);!&74 AND&FFFF;" events stored"
2540 :
2550 K=GET
2560 K=K AND 223
2570 IF K=82 PROCrecord
2580 IF K=80 PROCplay
2590 IF K=10 PROCosc:CLS
2600 IF K=76 PROCload:CLS
2610 IF K=83 PROCsave:CLS
2620 UNTILFALSE
2630 :
2640 :
2650 IF ERR=17 END
2660 *FX13,2
2670 ?&78=0
2680 IF ERR=100 PROCnotes:GOTO2450
2690 IF ERR=101 PROCclearline:GOTO2450
2700 IF ERR=102 AND K=82 PROCnotes:GOTO2450
2710 IF ERR=102 AND K=80 PROCclearline:GOTO2450
2720 REPORT:PRINT" at line ";ERL
2730 PRINT"Press a key";
2740 REPEATUNTILGET
2750 GOTO2410
2760 :
2770 :
2780 DEFPROCrecord
2790 *FX14,2
2800 PRINTTAB(5,20)"Recording..."
2810 ?status=3
2820 ?status=21
2830 CALL firstnote
2840 ENDPROC
2850 :
2860 :
2870 DEFPROCplay
2880 IF ?&75=0 AND ?&74=0 PROCempty:ENDPROC
2890 *FX14,2
2900 PRINTTAB(5,20)"Playing..."
2910 CALL firstplay
2920 ENDPROC
2930 :
2940 :
2950 DEFPROCnotes
2960 notecount=(256*?&75+?&74)
2970 PRINTTAB(5,20);notecount;" events stored"
2980 *FX21
2990 PRINTTAB(5,21)"Press any key"
3000 REPEATUNTILGET
3010 PROCclearline
3020 ENDPROC
3030 :
3040 :
3050 DEFPROCclearline
3060 PRINTTAB(5,20)SPC20
3070 PRINTTAB(5,21)SPC20
3080 VDU31,5,20
3090 ENDPROC
3100 :
3110 :
3120 DEFPROCempty
3130 PRINTTAB(5,20)"Nothing recorded"
3140 PRINTTAB(5,21)"Press any key"
3150 REPEATUNTILGET
3160 PROCclearline
3170 ENDPROC
3180 :
3190 :
3200 DEFPROCosc:LOCAL A$
3210 REPEATINPUTLINE"*"A$:OSCLIA$:UNTILA$="":ENDPROC
3220 :
3230 :
3240 DEFPROCload
3250 INPUT"Load file: "A$
3260 OSCLI"LOAD "+A$+" "+STR$~data
3270 ?&74=?data:?&75=data?1
3280 ENDPROC
3290 :
3300 :
3310 DEFPROCsave
3320 INPUT"Save file: "A$
3330 !data=!&74:data?2=0:data?3=0
3340 OSCLI"SAVE "+A$+" "+STR$~data+"+"+STR$~(2+5*!data)
3350 ENDPROC
3360 DEFPROCx
3370 FOR P=0 TO 1
3380 P%=&900
3390 [OPTP*3
3400 .loop
3410 LDA &FCF0:AND #1:BEQ loop
3420 LDA &FCF1:JSR pr_hex
3430 BIT &FF:BPL loop
3440 RTS
3450 .pr_hex
3460 PHA:LSR A:LSR A:LSR A:LSR A
3470 JSR pr_nyb:PLA
3480 .pr_nyb
3490 AND #15:CMP #10:BCC pr_ok
3500 ADC #6:.pr_ok
3510 ADC #48:JMP &FFEE
3520 ]NEXT
3530 ENDPROC