OSDN Git Service

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