Debian Codegraph @

prboom2/src/MUSIC/opl.h

raw
1 // Emacs style mode select -*- C -*-
2 //-----------------------------------------------------------------------------
3 //
4 // Copyright(C) 2009 Simon Howard
5 //
6 // This program is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU General Public License
8 // as published by the Free Software Foundation; either version 2
9 // of the License, or (at your option) any later version.
10 //
11 // This program is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
15 //
16 // You should have received a copy of the GNU General Public License
17 // along with this program; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
19 // 02111-1307, USA.
20 //
21 // DESCRIPTION:
22 // OPL interface.
23 //
24 //-----------------------------------------------------------------------------
25
26
27 #ifndef OPL_OPL_H
28 #define OPL_OPL_H
29
30 typedef void (*opl_callback_t)(void *data);
31
32 typedef enum
33 {
34 OPL_REGISTER_PORT = 0,
35 OPL_DATA_PORT = 1,
36 OPL_REGISTER_PORT_OPL3 = 2
37 } opl_port_t;
38
39 #define OPL_NUM_OPERATORS 21
40 #define OPL_NUM_VOICES 9
41
42 #define OPL_REG_WAVEFORM_ENABLE 0x01
43 #define OPL_REG_TIMER1 0x02
44 #define OPL_REG_TIMER2 0x03
45 #define OPL_REG_TIMER_CTRL 0x04
46 #define OPL_REG_FM_MODE 0x08
47 #define OPL_REG_NEW 0x105
48
49 // Operator registers (21 of each):
50
51 #define OPL_REGS_TREMOLO 0x20
52 #define OPL_REGS_LEVEL 0x40
53 #define OPL_REGS_ATTACK 0x60
54 #define OPL_REGS_SUSTAIN 0x80
55 #define OPL_REGS_WAVEFORM 0xE0
56
57 // Voice registers (9 of each):
58
59 #define OPL_REGS_FREQ_1 0xA0
60 #define OPL_REGS_FREQ_2 0xB0
61 #define OPL_REGS_FEEDBACK 0xC0
62
63 // Times
64
65 #define OPL_SECOND ((uint64_t) 1000 * 1000)
66
67 //
68 // Low-level functions.
69 //
70
71 // Initialize the OPL subsystem.
72
73 int OPL_Init(unsigned int port_base);
74
75 // Shut down the OPL subsystem.
76
77 void OPL_Shutdown(void);
78
79
80 // Write to one of the OPL I/O ports:
81
82 void OPL_WritePort(opl_port_t port, unsigned int value);
83
84 // Read from one of the OPL I/O ports:
85
86 unsigned int OPL_ReadPort(opl_port_t port);
87
88 //
89 // Higher-level functions.
90 //
91
92 // Read the cuurrent status byte of the OPL chip.
93
94 unsigned int OPL_ReadStatus(void);
95
96 // Write to an OPL register.
97
98 void OPL_WriteRegister(int reg, int value);
99
100 // Perform a detection sequence to determine that an
101 // OPL chip is present.
102
103 int OPL_Detect(void);
104
105 // Initialize all registers, performed on startup.
106
107 void OPL_InitRegisters(int opl3);
108
109
110 // Block until the specified number of milliseconds have elapsed.
111
112 void OPL_Delay(unsigned int ms);
113
114 // Pause the OPL callbacks.
115
116 void OPL_SetPaused(int paused);
117
118
119 extern unsigned int opl_sample_rate;
120
121 void OPL_Render_Samples (void *dest, unsigned nsamp);
122
123
124 void OPL_SetCallback(uint64_t us, opl_callback_t callback, void *data);
125
126 void OPL_ClearCallbacks(void);
127
128 void OPL_AdjustCallbacks(float tempo);
129
130 #endif