OSDN Git Service

updated copyleft and need to test and fix newer version of open watcom
[proj16/16.git] / src / sountest.c
1 /* Project 16 Source Code~\r
2  * Copyright (C) 2012-2022 sparky4 & pngwen & andrius4669 & joncampbell123 & yakui-lover\r
3  *\r
4  * This file is part of Project 16.\r
5  *\r
6  * Project 16 is free software; you can redistribute it and/or modify\r
7  * it under the terms of the GNU General Public License as published by\r
8  * the Free Software Foundation; either version 3 of the License, or\r
9  * (at your option) any later version.\r
10  *\r
11  * Project 16 is distributed in the hope that it will be useful,\r
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
14  * GNU General Public License for more details.\r
15  *\r
16  * You should have received a copy of the GNU General Public License\r
17  * along with this program.  If not, see <http://www.gnu.org/licenses/>, or\r
18  * write to the Free Software Foundation, Inc., 51 Franklin Street,\r
19  * Fifth Floor, Boston, MA 02110-1301 USA.\r
20  *\r
21  */\r
22 \r
23 #include <stdio.h>\r
24 \r
25 #include "src/lib/16_in.h"\r
26 #include "src/lib/16_snd.h"\r
27 //#include <hw/8254/8254.h>             /* 8254 timer */\r
28 //#include <hw/adlib/adlib.h>\r
29 \r
30 static unsigned int musical_scale[18] = {\r
31         0x1B0,                  /* E */\r
32         0x1CA,                  /* F */\r
33         0x1E5,                  /* f# */\r
34         0x202,                  /* G */\r
35         0x220,                  /* G# */\r
36         0x241,                  /* A */\r
37         0x263,                  /* A# */\r
38         0x287,                  /* B */\r
39         0x2AE,                  /* C */\r
40 \r
41         0x2B0,                  /* E */\r
42         0x2CA,                  /* F */\r
43         0x2E5,                  /* f# */\r
44         0x302,                  /* G */\r
45         0x320,                  /* G# */\r
46         0x341,                  /* A */\r
47         0x363,                  /* A# */\r
48         0x387,                  /* B */\r
49         0x3AE,                  /* C */\r
50 };\r
51 \r
52 void main(int argc, char near *argv[])\r
53 {\r
54         static global_game_variables_t gvar;\r
55         word i;\r
56         boolean                 done;\r
57         ScanCode                scan;\r
58 //      static FMInstrument testInst =\r
59 //{\r
60 //0x00, 0x01,   /* modulator frequency multiple... 0x20 */\r
61 //0x00, 0x00,   /* modulator frequency level...    0x40 */\r
62 //0xF0, 0xF0,   /* modulator attack/decay...       0x60 */\r
63 //0x73, 0x73,   /* modulator sustain/release...    0x80 */\r
64 //0x03, 0x00,   /* output waveform distortion      0xE0 */\r
65 //0x36,                         /* feedback algorithm and strength 0xC0 */\r
66 //};\r
67 \r
68         //FMReset();\r
69         //FMSetVoice(0, &testInst);\r
70         if(!init_adlib())\r
71         {\r
72                 printf("Cannot init library\n");\r
73                 exit(-1);\r
74         }\r
75         IN_Startup(&gvar);\r
76 \r
77         if (adlib_fm_voices > 9)\r
78                 printf("OPL3!\n");\r
79 //              vga_bios_set_80x50_text();\r
80 \r
81         memset(adlib_fm,0,sizeof(adlib_fm));\r
82         memset(&adlib_reg_bd,0,sizeof(adlib_reg_bd));\r
83         for (i=0;i < adlib_fm_voices;i++) {\r
84                 struct adlib_fm_operator *f;\r
85                 f = &adlib_fm[i].mod;\r
86                 f->ch_a = f->ch_b = f->ch_c = f->ch_d = 1;\r
87                 f = &adlib_fm[i].car;\r
88                 f->ch_a = f->ch_b = f->ch_c = f->ch_d = 1;\r
89         }\r
90 \r
91         for (i=0;i < /*adlib_fm_voices*/1;i++) {\r
92                 struct adlib_fm_operator *f;\r
93 \r
94                 f = &adlib_fm[i].mod;\r
95                 f->mod_multiple = 1;\r
96                 f->total_level = 63 - 16;\r
97                 f->attack_rate = 15;\r
98                 f->decay_rate = 0;\r
99                 f->sustain_level = 7;\r
100                 f->release_rate = 7;\r
101                 f->f_number = musical_scale[i%18];\r
102                 f->octave = 4;\r
103                 f->key_on = 0;\r
104 \r
105                 f = &adlib_fm[i].car;\r
106                 f->mod_multiple = 1;\r
107                 f->total_level = 63 - 16;\r
108                 f->attack_rate = 15;\r
109                 f->decay_rate = 0;\r
110                 f->sustain_level = 7;\r
111                 f->release_rate = 7;\r
112                 f->f_number = 0;\r
113                 f->octave = 0;\r
114                 f->key_on = 0;\r
115         }\r
116 \r
117         adlib_apply_all();\r
118 \r
119         printf("press Z!  to noise\npress ESC to quit");\r
120         printf("\np");\r
121         for (done = false;!done;)\r
122         {\r
123                 while (!(scan = gvar.in.inst->LastScan))\r
124                 {}\r
125 //                      SD_Poll();\r
126 \r
127                 IN_ClearKey(scan);\r
128                 switch (scan)\r
129                 {\r
130                         case sc_Escape:\r
131                                 done = true;\r
132                         break;\r
133                         case sc_Z:\r
134                                 adlib_fm[0].mod.key_on = 1;\r
135                                 //FMKeyOn(0, 0x106, 4);\r
136                         break;\r
137                         default:\r
138                                 adlib_fm[0].mod.key_on = 0;\r
139                                 //FMKeyOff(0);\r
140                         break;\r
141                 }\r
142                 if(adlib_fm[0].mod.key_on) printf("e");\r
143                 adlib_update_groupA0(0,&adlib_fm[0]);\r
144         }\r
145         printf("!\n");\r
146         shutdown_adlib();\r
147         IN_Shutdown(&gvar);\r
148 }\r