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