]> 4ch.mooo.com Git - 16.git/blob - src/lib/16_snd.c
bakapee!
[16.git] / src / lib / 16_snd.c
1 /* Project 16 Source Code~
2  * Copyright (C) 2012-2015 sparky4 & pngwen & andrius4669
3  *
4  * This file is part of Project 16.
5  *
6  * Project 16 is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * Project 16 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  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program.  If not, see <http://www.gnu.org/licenses/>, or
19  * write to the Free Software Foundation, Inc., 51 Franklin Street,
20  * Fifth Floor, Boston, MA 02110-1301 USA.
21  *
22  */
23
24 #include "src/lib/16_snd.h"
25
26 void opl2out(word reg, word data)
27 {\r
28         __asm
29         {\r
30                 mov     ax,reg\r
31                 mov     dx,word ptr [ADLIB_FM_ADDRESS]\r
32                 or      ah,ah\r
33                 jz      @@1\r
34                 add     dx,2\r
35 @@1:    out     dx,al\r
36                 mov     cx,6\r
37 @@2:    in      al,dx\r
38                 loop    @@2\r
39                 inc     dl\r
40                 mov     ax,data\r
41                 out     dx,al\r
42                 dec     dl\r
43                 mov     cx,36\r
44 @@3:    in      al,dx\r
45                 loop    @@3\r
46         }
47 }\r
48 \r
49 void opl3out(word reg, word data)
50 {\r
51         __asm
52         {\r
53                 mov     ax,reg\r
54                 mov     dx,word ptr [ADLIB_FM_ADDRESS]\r
55                 or      ah,ah\r
56                 jz      @@1\r
57                 add     dx,2\r
58 @@1:    out     dx,al\r
59                 inc     dl\r
60                 mov     ax,data\r
61                 out     dx,al\r
62                 dec     dl\r
63                 mov     cx,26\r
64 @@2:    in      al,dx\r
65                 loop    @@2\r
66         }
67 }\r
68 \r
69 void opl3exp(word data)
70 {\r
71         __asm
72         {\r
73                 mov     ax,data\r
74                 mov     dx,word ptr [ADLIB_FM_ADDRESS]\r
75                 add     dx,2\r
76                 out     dx,al\r
77                 mov     cx,6\r
78 @@1:    in      al,dx\r
79                 loop    @@1\r
80                 inc     dl\r
81                 mov     al,ah\r
82                 out     dx,al\r
83                 mov     cx,36\r
84 @@2:    in      al,dx\r
85                 loop    @@2
86         }\r
87 }
88
89 /* Function: FMResest *******************************************************\r
90 *\r
91 *     Description:        quick and dirty sound card reset (zeros all\r
92 *                         registers).\r
93 *\r
94 */\r
95 void FMReset(void/*int percusiveMode*/)
96 {\r
97         int i;\r
98 \r
99         /* zero all registers */\r
100         for(i = MIN_REGISTER; i < MAX_REGISTER+1; i++) opl2out(i, 0);\r
101 \r
102         /* allow FM chips to control the waveform of each operator */\r
103         opl2out(0x01, 0x20);\r
104 \r
105         /* set rhythm enabled (6 melodic voices, 5 percussive) */\r
106         opl2out(0xBD, 0x20);\r
107 \r
108         //FMSetPercusiveMode(percusiveMode);\r
109 } /* End of FMReset */