-
Notifications
You must be signed in to change notification settings - Fork 0
/
MIDICar Player.pas
184 lines (152 loc) · 3.42 KB
/
MIDICar Player.pas
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
{$LIBRARYPATH midfile/}
{$DEFINE ROMOFF}
Uses
MC6850,
MIDI_FIFO,
MIDFiles,
sysutils,
Misc,
CIO;
{$I-}
const
DLIST_ADDR = $3400;
SCREEN_ADDR = $3430;
SCREEN_STATUS = SCREEN_ADDR+25*40;
TRACK_DATA_ADDR = $3E00;
MIDI_DATA_ADDR = $4000;
FREE_MEM = (($8000-$4000)+($d000-$a000)+($ff00-$e000)) div 1024;
{$r selftest.rc}
var
chptr:array[0..39] of word;
scradr:Word;
// {$I mc6850_irq.inc}
{$i helpers.inc}
procedure clearStatus;
begin
fillchar(pointer(SCREEN_STATUS),40,128);
end;
procedure init;
var
totalXMS:word;
x,y:byte;
begin
{$IFDEF USE_FIFO}
FIFO_Reset;
{$ENDIF}
// copy charset definition
move(pointer($e000),pointer($3000),$400);
poke(709,15); poke(710,0);
poke($2F4,$30);
fillchar(pointer(SCREEN_ADDR),1040,0);
dpoke($230,DLIST_ADDR);
fillchar(pointer(SCREEN_ADDR),40,128);
scradr:=SCREEN_ADDR+1; PutText('MIDICar Player RC1'~*);
scradr:=SCREEN_ADDR+31; PutText('2022 GSD'~*);
clearStatus;
// detect memory
totalXMS:=DetectMem*16;
asm lda #$fe \ sta $100 end;
// writeLn('Available memory: ',FREE_MEM+totalXMS,' KB');
MIDTracks:=Pointer(TRACK_DATA_ADDR);
MIDData:=Pointer(MIDI_DATA_ADDR);
for cTrk:=0 to 39 do
begin
x:=cTrk div 20; y:=cTrk mod 20;
chPtr[cTrk]:=SCREEN_ADDR+80+80+x*20+y*40;
end;
end;
procedure loadPrc(v:byte);
var
i:byte;
begin
scradr:=SCREEN_STATUS+10;
putInt(v-1); poke(scradr,$8f); inc(scradr);
putInt(totalTracks);
end;
procedure checkParams;
var
fn:PString;
err:shortint;
begin
if paramCount=1 then
begin
fn:=ParamStr(1);
scradr:=SCREEN_STATUS+1; PutText('Loading'~*);
puttextinvert:=128;
loadProcess:=@loadPrc;
err:=LoadMid(fn);
if err<>0 then
begin
scradr:=SCREEN_STATUS+1;
if err>0 then
case err of
ERR_UNSUPPORTED_FORMAT: PutText('Unsupported format'~*);
ERR_NOT_ENOUGHT_MEMORY: PutText('Not enought memory'~*);
end
else
begin
PutText('I/O Error #'~*); putInt(err);
end;
while keyb=255 do ;
keyb:=255;
exit2DOS;
end;
end
else
begin
totalTracks:=1;
end;
end;
begin
init;
checkParams;
//
clearStatus;
scradr:=SCREEN_STATUS+1; PutText('Playing'~*);
// initialize MIDICar (MC6850)
MC6850_Reset;
MC6850_Init(CD_64+WS_OddParity+WS_8bits+IRQ_Receive);
// initialize IRQ for MC6850
// oldIRQ:=VIMIRQ; asm SEI end; VIMIRQ:=@MC6850_IRQ; asm CLI end;
Reset_MIDI; // reset MIDI
_totalTicks:=0; // reset song ticks
setTempo; // set song tempo
// Player loop
cTrk:=totalTracks;
Repeat
processMIDI;
// scradr:=chptr[cTrk];
// PutByteHex(_bank); inc(scradr,3);
// PutWordHex(_adr); inc(scradr,6);
// PutLongHex(_trackTime); // _delta
{$IFDEF USE_FIFO}
FIFO_PushDirect2MC6850;
{$ENDIF}
if keyb<>255 then
begin
case keyb of
k_esc: break;
k_p:
begin
_timerStatus:=_timerStatus xor f_counter;
scradr:=SCREEN_STATUS+1;
if _timerStatus and f_counter=0 then
PutText('Playing'~*)
else
PutText('Pause '~*);
end;
end;
keyb:=255;
end;
until (PlayingTracks=0);
// Write(#156);
// End player loop
// poke(559,34);
// dpoke($9c24,$9c40);
Reset_MIDI;
// restore IRQ vector
// asm SEI end; VIMIRQ:=oldIRQ; asm CLI end;
// resotre Timer vector
setIntVec(iTim1,oldTimerVec);
exit2DOS;
end.