-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathTNDYTRK.PAS
596 lines (461 loc) · 13.1 KB
/
TNDYTRK.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
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
{$G-,N-,E-}
{$S-,R-}
(*{-$M32768,0,655360}*)
{
Tracker for TNDY and TLPT Tandy 3-Voice sound devices
Version 1.2
by Jan Knipperts
A tracker for the TI SN76496A sound generator chip.
Project pages:
https://github.com/JKnipperts/TNDY-Tracker
https://www.vogons.org/viewtopic.php?f=62&t=76603
https://dosreloaded.de/forum/index.php?thread/3616-tndy-tracker-für-tandy-3-voice-sound
}
Program TNDYTracker;
uses dos,
global,
keyboard,
textmode,
menu,
control,
modules,
IE,
tndy,
play,
tracker,
PIT;
{================= IRQ / Timing ========================}
Procedure Poll_Player;
begin
if not pause then
begin
if timing.ticks > 0 then
begin
dec(timing.ticks);
Update_fx(0);
Update_fx(1);
Update_fx(2);
if editor.channels = 5 then
Update_fx(3);
end
else
begin
Play_row(Player.row); {Play new row}
Update_Pos; {Update position}
timing.ticks := Player.speed-1;
end;
end
else
begin
if editor.play_note then
begin
if (editor.playticks < editor.playtime) then
inc(editor.playticks)
else
begin
Mute_all;
editor.play_note := false;
end;
end;
if editor.play_row then
begin
if editor.playticks > 0 then
begin
dec(editor.playticks);
Update_fx(0);
Update_fx(1);
Update_fx(2);
if editor.channels = 5 then
Update_fx(3);
end
else
Editor.Play_Row := false;
end;
end;
end;
Procedure TNDYint; interrupt;
begin
Poll_Player;
if Timing.clock_tick > 0 then
begin
asm
cli
mov al,20h
out 20h,al
end;
end
else
begin
asm
pushf
call [oldint08];
end;
end;
Timing.clock_tick := Timing.clock_tick+Timer.Clock_Counter;
If (Timing.clock_tick >= 1) then Timing.clock_tick := 0;
end;
procedure init_irq;
begin
GetIntVec($08,@oldint08);
SetIntVec($08,@TNDYint);
end;
procedure done_irq;
begin
SetIntVec($08,@oldint08);
Resettimer; {Reset timer to its default state (18.2 Hz)}
end;
{================= Handle command line options ========================}
Function FindOption(lookup : string) : boolean;
var cnt : byte;
s : string;
begin
FindOption := false;
for cnt := 1 to paramcount do
begin
if length(paramstr(cnt)) > length(lookup) then
s := copy(uppercase(paramstr(cnt)),1,length(lookup))
else
s := uppercase(paramstr(cnt));
if pos(uppercase(lookup),s) > 0 then
begin
FindOption := true;
break;
end;
end;
end;
Procedure Check_Commandline;
begin
if FindOption('/?') or FindOption('?') then
begin
clrscr;
writeln(title);
writeln('');
writeln('Possible comand line parameters: ');
writeln('');
writeln(' /MDA - Forces monochrome display ');
writeln(' /COLOR - Forces color display ');
writeln('');
writeln('Or you can enter a Filename to load the song directly at the start.');
writeln('Filename and options can also be combined.');
writeln('Example: TNDYTRK.EXE C:\SONGS\TUNE.TND /MDA');
writeln('');
halt(0);
end;
if FindOption('/MDA') then
begin
ChangeVSeg($B000);
end;
if FindOption('/COLOR') then
begin
ChangeVSeg($B800);
end;
end;
{============ The save exit proc ==============}
procedure Save_Exit; Far;
begin
done_irq; {Set original interrupt}
Mute_All; {Mute all sound output}
fillchar(buffer.screen1^,4000,0); {clean up memory}
fillchar(buffer.screen2^,4000,0);
fillchar(buffer.blankscreen^,4000,0);
fillchar(buffer.oldscreen^,4000,0);
fillchar(buffer.pbuffer^,7040,0);
fillchar(buffer.pbuffer1^,7040,0);
freemem(buffer.screen1,4000); {Free buffers / allocated memory}
freemem(buffer.screen2,4000);
freemem(buffer.blankscreen,4000);
freemem(buffer.oldscreen,4000);
freemem(buffer.pbuffer,7040);
freemem(buffer.pbuffer1,7040);
Clear_Pattern_Data; {Clean up patterns and release additional allocate memory}
dispose(patterns[0]); {also for pattern 0}
ExitProc := OldExitProc; {run the original exit proc}
end;
{============ The default configuration ====================}
Procedure Set_default_config;
begin
TANDY.IOport := $0C0;
Editor.channels := 5;
SNDcfg.Correct := true;
SNDcfg.Tempo := 60;
SNDcfg.Speed := 0; {Auto detect speed}
SNDcfg.ClockFreq := 1;
MODcfg.ch4 := 2; {PC Speaker}
MODcfg.Tempo := 50;
MODcfg.Speed := 6;
MODcfg.VolScale := 1; {direct scaling}
ptn.tracemode := true;
end;
{============ Initialization of screen modes, sound, variables.. ==============}
Procedure Initialization;
begin
TLPT.lpt := false;
if TANDY.IOport <= 3 then {Init TNDLPT if selected}
begin
TLPT.lpt := true;
if not TLPT_Init(TANDY.IOport) then
begin
TANDY.IOport := $0C0;
TLPT.lpt := false;
end;
end;
TANDY_Mute_all;
{Set the initial values for our variables....}
Editor.d_tempo := 50; {Default tempo is 50 Hz}
Editor.d_speed := 6; {Default speed 6 = 125 BPM}
Player.speed := 6;
Player.tempo := 50;
Editor.D_tempo := Player.tempo;
Editor.D_speed := Player.speed;
Editor.Playtime := Player.tempo div 4;
Editor.orderview := -2;
Editor.octave := 4;
Editor.chan := 1;
Editor.noisetype := 0;
Editor.play_row := false;
Editor.play_note := false;
Editor.saved := true;
Player.position := 0;
Player.row := 0;
Editor.curr_vol := 0;
Player.songlength := 1;
Player.maxpattern := 0;
ptn.tracemode := true;
active_menu := 1;
pedit := true;
quit := false;
noteedit := true;
clipboard.inuse := false;
patternplay := false;
fillchar(order,sizeof(order),0);
fillchar(msg_buffer,sizeof(msg_buffer),0);
fillchar(p_msg,sizeof(p_msg),0);
fillchar(volume,sizeof(volume),15);
fillchar(freq,sizeof(freq),0);
fillchar(current,sizeof(current),0);
fillchar(meter,sizeof(meter),0);
msg_size := 0;
{Depending on the number of channels,
the edit window is larger or smaller...}
if Editor.channels = 5 then
begin
Editor.p_xp := 4;
Editor.p_yp := 6;
end
else
begin
Editor.p_xp := 14;
Editor.p_yp := 6;
end;
{Alloc additional screen buffer...}
getmem(buffer.screen1,4000);
getmem(buffer.blankscreen,4000);
getmem(buffer.screen2,4000);
getmem(buffer.oldscreen,4000);
getmem(buffer.pbuffer,7040);
getmem(buffer.pbuffer1,7040);
if (buffer.screen1 = nil) or
(buffer.screen2 = nil) or
(buffer.oldscreen = nil) or
(buffer.blankscreen = nil) or
(buffer.pbuffer = nil) or
(buffer.pbuffer1 = nil) or
(maxavail < sizeof(TNDYPattern)) then
begin
clrscr;
writeln('');
writeln('Not enough memory!');
writeln('');
halt(1);
end;
fillchar(buffer.screen1^,4000,0);
fillchar(buffer.screen2^,4000,0);
fillchar(buffer.blankscreen^,4000,0);
fillchar(buffer.oldscreen^,4000,0);
fillchar(buffer.pbuffer^,7040,0);
fillchar(buffer.pbuffer1^,7040,0);
OldExitProc := ExitProc; {Save the old and install the}
ExitProc := @Save_Exit; {new exit procedure}
pause := true;
set_timer(Player.tempo); {Reset timer to new frequency}
init_irq;
if txtscreen.VidSeg = $B800 then {color display}
begin
Palette.window_color := 0; {set sheme for color screens}
Palette.menu_color := 1;
Palette.mark_color := 4;
Palette.text_color1 := 15;
Palette.text_color2 := 14;
Palette.text_color3 := 4;
Monochrome := false;
asm {enter 80x25 16 color text mode}
xor ah,ah
mov al,3
int 10h
end;
end
else {..and for monochrome}
begin
Palette.window_color := 0;
Palette.menu_color := 7;
Palette.mark_color := 7;
Palette.text_color1 := 7;
Palette.text_color2 := 7;
Palette.text_color3 := 7;
Monochrome := true;
asm
xor ah,ah
mov al,7
int 10h
end;
end;
cursor(false);
writeto(buffer.screen1); {all write functions go to buffer}
InitMenuScreen(menu_title[1]+' '+ {Draw the menu bar}
menu_title[2]+' '+
menu_title[3]+' '+
menu_title[4]+' '+
menu_title[5]+' '+
menu_title[6],Palette.text_color1,Palette.menu_color);
centeredline(25,Palette.text_color1,Palette.menu_color,title); {..and the title}
move(buffer.screen1^,buffer.blankscreen^,4000); {save this screen as "basic"}
move(buffer.screen1^,buffer.oldscreen^,4000);
end;
Procedure Read_Configuration;
begin
if fileexist('TNDYTRK.CFG') then {is there a configuration file?}
begin
assign(f,'TNDYTRK.CFG'); {Yes? Then read it...}
reset(f,1);
if filesize(f) <> (sizeof(SNDcfg)+Sizeof(MODcfg)+4) then
begin
close(f); {wrong size? -> set default values}
Set_default_config;
end
else
begin
{$I-}
blockread(f,TANDY.IOport,sizeof(TANDY.IOport));
blockread(f,TANDY.useC1,sizeof(TANDY.useC1));
blockread(f,Editor.channels,sizeof(Editor.channels));
blockread(f,SNDcfg,sizeof(SNDcfg));
blockread(f,MODcfg,sizeof(MODcfg));
close(f);
{$I+}
If IOResult <> 0 then {Reading failed? -> set default values}
begin
Set_default_config;
end;
end;
end
else {there is no cfg file? -> set default values}
begin
Set_default_config;
end;
end;
Procedure Save_Configuration;
begin
{$I-}
assign(f,'TNDYTRK.CFG'); {save actual configuration}
rewrite(f,1);
blockwrite(f,TANDY.IOport,sizeof(TANDY.IOport));
blockwrite(f,TANDY.useC1,sizeof(TANDY.useC1));
blockwrite(f,Editor.channels,sizeof(Editor.channels));
blockwrite(f,SNDcfg,sizeof(SNDcfg));
blockwrite(f,MODcfg,sizeof(MODcfg));
close(f);
{$I+}
if IOresult <> 0 then
begin
writeln('ERROR: Cannot save current settings! Failed to write configuration file.');
writeln('');
halt(1);
end;
end;
{============== Main program ==============}
begin
Check_Commandline;
Read_Configuration;
Clear_Pattern_Data;
Initialization;
if (pos('.TND',uppercase(paramstr(1))) > 0) or
(pos('.SND',uppercase(paramstr(1))) > 0) or
(pos('.MOD',uppercase(paramstr(1))) > 0) then
begin
if (pos('.TND',uppercase(paramstr(1))) > 0) then
LoadTNDY(paramstr(1));
if (pos('.SND',uppercase(paramstr(1))) > 0) then
Import_SND(paramstr(1));
if (pos('.MOD',uppercase(paramstr(1))) > 0) then
Import_MOD(paramstr(1));
Proceed_Errors;
writeto(buffer.screen1);
displaybuffer(buffer.screen1);
if error = 0 then
begin
Player.position := 0;
Player.Pattern_num := order[Player.position];
Player.row := 0;
Editor.chan := 1;
end;
end;
Update_Pattern_Screenbuffer(Buffer.Pbuffer,Player.pattern_num,0,63);
writeto(buffer.screen1);
Draw_Pattern_Window(false);
Draw_Editor_Window(false);
gotoxy(Editor.p_xp+4,14);
Update_Pattern(-8,true);
Clear_Keypress;
repeat {The main loop...}
if is_key_pressed then
begin
Get_Key;
if mainmenu then
Control_Menu
else
begin
if pause then
Control_Pattern_Editor
else
Control_Player
end;
end;
if (pause = false) then {while playing...}
begin
if ptn.bufferswap then {time to swap patterns front and buckbuffer?}
begin
SwapBuffers(buffer.pbuffer,buffer.pbuffer1);
ptn.bufferswap := false;
end;
if ptn.tracemode = true then
begin
if ptn.ptnupdate then
begin
Update_Order(false,true);
Update_Pattern(Player.row-8,true);
ptn.ptnupdate := false;
end;
end;
if ptn.infoupdate then {time to update screen contents?}
begin
Update_Player_State(true);
ptn.infoupdate := false;
end;
end;
until (quit);
pause := true;
TANDY_Mute_all;
Clear_Keypress;
writeto(ptr(txtscreen.vidseg,0));
Save_Configuration;
clrscr;
writeln('Have a nice day and thank you for using TNDY-Tracker!');
writeln('Greetings go to all members of DOSReloaded.de and Vogons.org and special');
writeln('thanks to Matze and Serge for their great hardware projects!');
writeln('');
writeln('TNDY-Tracker is open source. Visit https://github.com/JKnipperts/TNDY-Tracker');
writeln('for the latest version or if you are interested in the source code.');
writeln('');
Cursor(true);
Change_cursor(6,7);
end.