3 * Adlib OPL2/OPL3 FM synthesizer chipset test program.
4 * Play MIDI file using the OPLx synthesizer (well, poorly anyway)
5 * (C) 2010-2012 Jonathan Campbell.
6 * Hackipedia DOS library.
8 * This code is licensed under the LGPL.
9 * <insert LGPL legal text here>
11 * Compiles for intended target environments:
12 * - MS-DOS [pure DOS mode, or Windows or OS/2 DOS Box]
15 #include "src/lib/midi.h"
17 int main(int argc,char **argv) {
21 printf("ADLIB FM test program\n");
23 printf("You must specify a MIDI file to play\n");
28 printf("Cannot init VGA\n");
32 printf("Cannot init library\n");
35 if (!probe_8254()) { /* we need the timer to keep time with the music */
36 printf("8254 timer not found\n");
40 for (i=0;i < MIDI_MAX_TRACKS;i++) {
41 midi_trk[i].raw = NULL;
42 midi_trk[i].read = NULL;
43 midi_trk[i].fence = NULL;
46 if (load_midi_file(argv[1]) == 0) {
47 printf("Failed to load MIDI\n");
51 write_8254_system_timer(T8254_REF_CLOCK_HZ / 100); /* tick faster at 100Hz please */
54 irq0_max = 1000; /* about 18.2Hz */
55 old_irq0 = _dos_getvect(8);/*IRQ0*/
59 midi_reset_channels();
62 irq0_ticks = ptick = 0;
70 adv = irq0_ticks - ptick;
72 if (adv >= 100UL) adv = 100UL;
84 if (c == 0) c = getch() << 8;
95 _dos_setvect(8,old_irq0);
96 write_8254_system_timer(0); /* back to normal 18.2Hz */
98 for (i=0;i < MIDI_MAX_TRACKS;i++) {
99 if (midi_trk[i].raw) {
100 #if TARGET_MSDOS == 16 && (defined(__LARGE__) || defined(__COMPACT__))
101 _dos_freemem(FP_SEG(midi_trk[i].raw)); /* NTS: Because we allocated with _dos_allocmem */
103 free(midi_trk[i].raw);
105 midi_trk[i].raw = NULL;
107 midi_trk[i].fence = NULL;
108 midi_trk[i].read = NULL;