-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSNDLIB.C
455 lines (224 loc) · 7.03 KB
/
SNDLIB.C
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
// I N C L U D E S ///////////////////////////////////////////////////////////
#include <io.h>
#include <stdio.h>
#include <stdlib.h>
#include <dos.h>
#include <bios.h>
#include <fcntl.h>
#include "sndlib.h"
// G L O B A L S ////////////////////////////////////////////////////////////
char __far *driver_ptr;
unsigned version;
char __huge *data_ptr;
unsigned ct_voice_status;
// F U N C T I O N S /////////////////////////////////////////////////////////
void Voc_Get_Version(void)
{
// gets the version of the driver and prints it out
_asm
{
mov bx,0 ; function 0 get version number
call driver_ptr ; call the driver
mov version,ax ; store in version variable
} // end inline asm
printf("\nVersion of Driver = %X.0%X",((version>>8) & 0x00ff), (version&0x00ff));
} // end Voc_Get_Version
//////////////////////////////////////////////////////////////////////////////
int Voc_Init_Driver(void)
{
// intialize the driver and return the status
int status;
_asm
{
mov bx,3 ; function 3 initialize the driver
call driver_ptr ; call the driver
mov status,ax ; store in version variable
} // end inline asm
// return status
printf("\nDriver Initialized");
return(status);
} // end Voc_Init_Driver
//////////////////////////////////////////////////////////////////////////////
int Voc_Terminate_Driver(void)
{
// terminate the driver
_asm
{
mov bx,9 ; function 9 terminate the driver
call driver_ptr ; call the driver
} // end inline asm
// de-allocate memory
_dos_freemem(_FP_SEG(driver_ptr));
printf("\nDriver Terminated");
} // end Voc_Terminate_Driver
//////////////////////////////////////////////////////////////////////////////
void Voc_Set_Port(unsigned int port)
{
// sets the I/O port of the sound blaster
_asm
{
mov bx,1 ; function 1 set port address
mov ax,port ; move the port number into ax
call driver_ptr ; call the driver
} // end inline asm
} // Voc_Set_Port
//////////////////////////////////////////////////////////////////////////////
void Voc_Set_Speaker(unsigned int on)
{
// turns the speaker on or off
_asm
{
mov bx,4 ; function 4 turn speaker on or off
mov ax,on ; move the on/off flag into ax
call driver_ptr ; call the driver
} // end inline asm
} // Voc_Set_Speaker
/////////////////////////////////////////////////////////////////////////////
int Voc_Play_Sound(unsigned char far *addr,unsigned char header_length)
{
// plays a pre-loaded VOC file
unsigned segm,offm;
segm = _FP_SEG(addr);
offm = _FP_OFF(addr) + header_length;
_asm
{
mov bx,6 ; function 6 play a VOC file
mov ax, segm ; can only mov a register into segment so we need this
mov es, ax ; es gets the segment
mov di, offm ; di gets offset
call driver_ptr ; call the driver
} // end inline asm
} // end Voc_Play_Sound
/////////////////////////////////////////////////////////////////////////////
int Voc_Stop_Sound(void)
{
// stops a sound that is playing
_asm
{
mov bx,8 ; function 8 stop a sound
call driver_ptr ; call the driver
} // end inline asm
} // end Voc_Stop_Sound
/////////////////////////////////////////////////////////////////////////////
int Voc_Pause_Sound(void)
{
// pauses a sound that is playing
_asm
{
mov bx,10 ; function 10 pause a sound
call driver_ptr ; call the driver
} // end inline asm
} // end Voc_Pause_Sound
/////////////////////////////////////////////////////////////////////////////
int Voc_Continue_Sound(void)
{
// continue a paused sound a sound that is playing
_asm
{
mov bx,11 ; function 11 continue play
call driver_ptr ; call the driver
} // end inline asm
} // end Voc_Continue_Sound
/////////////////////////////////////////////////////////////////////////////
int Voc_Break_Sound(void)
{
// break a sound loop
_asm
{
mov bx,12 ; function 12 break loop
call driver_ptr ; call the driver
} // end inline asm
} // end Voc_Break_Sound
/////////////////////////////////////////////////////////////////////////////
void Voc_Set_DMA(unsigned int dma)
{
_asm
{
mov bx,2 ; function 2 set DMA interupt number
mov ax,dma ; move the dma number into ax
call driver_ptr ; call the driver
} // end inline asm
} // Voc_Set_DMA
//////////////////////////////////////////////////////////////////////////////
void Voc_Set_Status_Addr(char far *status)
{
unsigned segm,offm;
segm = _FP_SEG(status);
offm = _FP_OFF(status);
_asm
{
mov bx,5 ; function 5 set status varible address
mov es, segm ; es gets the segment
mov di, offm ; di gets offset
call driver_ptr ; call the driver
} // end inline asm
} // Voc_Set_Status_Addr
//////////////////////////////////////////////////////////////////////////////
void Voc_Load_Driver(void)
{
// loads the ct-voice.drv
int driver_handle;
unsigned errno,segment,offset,num_para,bytes_read;
// open the driver file
_dos_open("CT-VOICE.DRV", _O_RDONLY, &driver_handle);
// allocate the memory
num_para = 1 + (filelength(driver_handle))/16;
_dos_allocmem(num_para,&segment);
// point driver pointer to data area
_FP_SEG(driver_ptr) = segment;
_FP_OFF(driver_ptr) = 0;
// load in the driver code
data_ptr = driver_ptr;
do
{
_dos_read(driver_handle,data_ptr, 0x4000, &bytes_read);
data_ptr += bytes_read;
} while(bytes_read==0x4000);
// close the file
_dos_close(driver_handle);
} // end Voc_Load_Driver
//////////////////////////////////////////////////////////////////////////////
char far *Voc_Load_Sound(char *filename, unsigned char *header_length)
{
// loads a sound off disk into memory and points a pointer to it
char far *temp_ptr;
char far *data_ptr;
unsigned int sum;
int sound_handle,t;
unsigned errno,segment,offset,num_para,bytes_read;
// open the sound file
_dos_open(filename, _O_RDONLY, &sound_handle);
// allocate the memory
num_para = 1 + (filelength(sound_handle))/16;
_dos_allocmem(num_para,&segment);
// point data pointer to allocated data area
_FP_SEG(data_ptr) = segment;
_FP_OFF(data_ptr) = 0;
// load in the sound data
temp_ptr = data_ptr;
do
{
_dos_read(sound_handle,temp_ptr, 0x4000, &bytes_read);
temp_ptr += bytes_read;
sum+=bytes_read;
} while(bytes_read==0x4000);
// make sure it's a voc file
if ((data_ptr[0] != 'C') || (data_ptr[1] != 'r'))
{
printf("\n%s is not a voc file!",filename);
_dos_freemem(_FP_SEG(data_ptr));
return(0);
} // end if voc file
*header_length = (unsigned char)data_ptr[20];
// close the file
_dos_close(sound_handle);
return(data_ptr);
} // end Voc_Load_Sound
//////////////////////////////////////////////////////////////////////////////
void Voc_Unload_Sound(char far *sound_ptr)
{
// delete the sound from memory
_dos_freemem(_FP_SEG(sound_ptr));
} // end Voc_Unload_Sound
//////////////////////////////////////////////////////////////////////////////