]> 4ch.mooo.com Git - 16.git/blob - src/lib/midi.h
16_pm worked on~
[16.git] / src / lib / midi.h
1 /* midi.h\r
2  *\r
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
7  *\r
8  * This code is licensed under the LGPL.\r
9  * <insert LGPL legal text here>\r
10  *\r
11  * Compiles for intended target environments:\r
12  *   - MS-DOS [pure DOS mode, or Windows or OS/2 DOS Box]\r
13  */\r
14 \r
15 #ifndef __MIDI__\r
16 #define __MIDI__\r
17 \r
18 #include <stdio.h>\r
19 #include <conio.h> /* this is where Open Watcom hides the outp() etc. functions */\r
20 #include <stdlib.h>\r
21 #include <string.h>\r
22 #include <unistd.h>\r
23 #include <malloc.h>\r
24 #include <ctype.h>\r
25 #include <fcntl.h>\r
26 #include <math.h>\r
27 #include <dos.h>\r
28 \r
29 //#include "src/lib/doslib/vga.h"\r
30 #include "src/lib/doslib/dos.h"\r
31 #include "src/lib/16_head.h"\r
32 #include "src/lib/doslib/8254.h"                /* 8254 timer */\r
33 #include "src/lib/doslib/8259.h"\r
34 //#include "src/lib/doslib/vgagui.h"\r
35 //#include "src/lib/doslib/vgatty.h"\r
36 #include "src/lib/doslib/adlib.h"\r
37 \r
38 /* one per OPL channel */\r
39 struct midi_note {\r
40         unsigned char           note_number;\r
41         unsigned char           note_velocity;\r
42         unsigned char           note_track;     /* from what MIDI track */\r
43         unsigned char           note_channel;   /* from what MIDI channel */\r
44         unsigned int            busy:1;         /* if occupied */\r
45 };\r
46 \r
47 struct midi_channel {\r
48         unsigned char           program;\r
49 };\r
50 \r
51 struct midi_track {\r
52         /* track data, raw */\r
53         unsigned char*          raw;            /* raw data base */\r
54         unsigned char*          fence;          /* raw data end (last byte + 1) */\r
55         unsigned char*          read;           /* raw data read ptr */\r
56         /* state */\r
57         unsigned long           us_per_quarter_note; /* Microseconds per quarter note (def 120 BPM) */\r
58         unsigned long           us_tick_cnt_mtpq; /* Microseconds advanced (up to 10000 us or one unit at 100Hz) x ticks per quarter note */\r
59         unsigned long           wait;\r
60         unsigned char           last_status;    /* MIDI last status byte */\r
61         unsigned int            eof:1;          /* we hit the end of the track */\r
62 };\r
63 \r
64 #define MIDI_MAX_CHANNELS       16\r
65 #define MIDI_MAX_TRACKS         64\r
66 \r
67 extern struct midi_note         midi_notes[ADLIB_FM_VOICES];\r
68 extern struct midi_channel              midi_ch[MIDI_MAX_CHANNELS];\r
69 extern struct midi_track                midi_trk[MIDI_MAX_TRACKS];\r
70 \r
71 static void (interrupt *old_irq0)();\r
72 static volatile unsigned long irq0_ticks=0;\r
73 static volatile unsigned int irq0_cnt=0,irq0_add=0,irq0_max=0;\r
74 static volatile unsigned char   midi_playing=0;\r
75 \r
76 int load_midi_file(const char *path);\r
77 void interrupt irq0();\r
78 void adlib_shut_up();\r
79 void midi_reset_tracks();\r
80 void midi_reset_channels();\r
81 void midi_tick();\r
82 \r
83 #endif /* __MIDI__ */\r