]> 4ch.mooo.com Git - 16.git/blob - 16/ID_SD_A.ASM
added the vgmtools scource
[16.git] / 16 / ID_SD_A.ASM
1 ;\r
2 ;       ID_SD_A.ASM\r
3 ;       Id Sound Manager assembly stuff\r
4 \r
5         .8086\r
6         IDEAL\r
7         MODEL   MEDIUM,C\r
8         JUMPS\r
9 \r
10         INCLUDE 'ID_SD.EQU'\r
11 \r
12 DEBUG   =       0\r
13 \r
14         EXTRN   SDL_DigitizedDone:FAR\r
15         EXTRN   alOut:FAR\r
16 \r
17 ;============================================================================\r
18 \r
19 DATASEG\r
20 \r
21         EXTRN   sqActive:WORD\r
22         EXTRN   ssSample:DWORD\r
23         EXTRN   ssLengthLeft:WORD\r
24         EXTRN   ssControl:WORD\r
25         EXTRN   ssStatus:WORD\r
26         EXTRN   ssData:WORD\r
27         EXTRN   ssOn:BYTE\r
28         EXTRN   ssOff:BYTE\r
29 \r
30         EXTRN   pcSound:DWORD\r
31         EXTRN   pcLengthLeft:WORD\r
32         EXTRN   pcLastSample:BYTE\r
33         EXTRN   pcSoundLookup:WORD\r
34 \r
35         EXTRN   alSound:DWORD\r
36         EXTRN   alBlock:WORD\r
37         EXTRN   alLengthLeft:WORD\r
38         EXTRN   alTimeCount:DWORD\r
39 \r
40         EXTRN   sqHack:DWORD\r
41         EXTRN   sqHackPtr:DWORD\r
42         EXTRN   sqHackLen:WORD\r
43         EXTRN   sqHackSeqLen:WORD\r
44         EXTRN   sqHackTime:DWORD\r
45 \r
46         EXTRN   HackCount:WORD\r
47         EXTRN   TimeCount:WORD\r
48         EXTRN   LocalTime:WORD\r
49 \r
50         EXTRN   TimerCount:WORD\r
51         EXTRN   TimerDivisor:WORD\r
52         EXTRN   t0OldService:DWORD\r
53 \r
54         EXTRN   SoundMode:WORD\r
55         EXTRN   DigiMode:WORD\r
56 \r
57         EXTRN   SoundNumber:WORD\r
58         EXTRN   SoundPriority:WORD\r
59 \r
60 count_time      dw      ?\r
61 count_fx        dw      ?\r
62 \r
63 pcdtab  db      00b,00b,00b,00b,00b,00b,00b,00b,00b,00b,00b,00b,00b,00b,00b,00b\r
64                 db      00b,00b,00b,00b,00b,00b,00b,00b,00b,00b,00b,00b,00b,00b,00b,00b\r
65                 db      00b,00b,00b,00b,00b,00b,00b,00b,00b,00b,00b,00b,00b,00b,00b,00b\r
66                 db      00b,00b,00b,00b,00b,00b,00b,00b,00b,00b,00b,00b,00b,00b,00b,00b\r
67                 db      00b,00b,00b,00b,00b,00b,00b,00b,00b,00b,00b,00b,00b,00b,00b,00b\r
68                 db      00b,00b,00b,00b,00b,00b,00b,00b,00b,00b,00b,00b,00b,00b,00b,00b\r
69                 db      00b,00b,00b,00b,00b,00b,00b,00b,00b,00b,00b,00b,00b,00b,00b,00b\r
70                 db      00b,00b,00b,00b,00b,00b,00b,00b,00b,00b,00b,00b,00b,00b,00b,00b\r
71                 db      10b,10b,10b,10b,10b,10b,10b,10b,10b,10b,10b,10b,10b,10b,10b,10b\r
72                 db      10b,10b,10b,10b,10b,10b,10b,10b,10b,10b,10b,10b,10b,10b,10b,10b\r
73                 db      10b,10b,10b,10b,10b,10b,10b,10b,10b,10b,10b,10b,10b,10b,10b,10b\r
74                 db      10b,10b,10b,10b,10b,10b,10b,10b,10b,10b,10b,10b,10b,10b,10b,10b\r
75                 db      10b,10b,10b,10b,10b,10b,10b,10b,10b,10b,10b,10b,10b,10b,10b,10b\r
76                 db      10b,10b,10b,10b,10b,10b,10b,10b,10b,10b,10b,10b,10b,10b,10b,10b\r
77                 db      10b,10b,10b,10b,10b,10b,10b,10b,10b,10b,10b,10b,10b,10b,10b,10b\r
78                 db      10b,10b,10b,10b,10b,10b,10b,10b,10b,10b,10b,10b,10b,10b,10b,10b\r
79 \r
80 \r
81 ;============================================================================\r
82 \r
83 CODESEG\r
84 \r
85 MyDS    dw      ?\r
86 \r
87 pcindicate      dw      ?\r
88 extreme         dw      ?\r
89 \r
90         PROC    SDL_SetDS\r
91         PUBLIC  SDL_SetDS\r
92 \r
93         mov     ax,ds\r
94         mov     [cs:MyDS],ds\r
95         ret\r
96 \r
97         ENDP\r
98 \r
99 ;\r
100 ;       COMMONSTART\r
101 ;       Macro used for common prefix code\r
102 ;\r
103         MACRO   COMMONSTART\r
104         IF DEBUG\r
105         push dx\r
106         push ax\r
107         mov     dx,STATUS_REGISTER_1\r
108         in      al,dx\r
109         mov     dx,ATR_INDEX\r
110         mov     al,ATR_OVERSCAN\r
111         out     dx,al\r
112         mov     al,4    ; red\r
113         out     dx,al\r
114         ENDIF\r
115 \r
116         push ds\r
117         push ax\r
118 \r
119         mov     ds,[cs:MyDS]\r
120         inc     [HackCount]\r
121         ENDM\r
122 \r
123 ;\r
124 ;       DOFX\r
125 ;       Macro used to do the sound effects code\r
126 ;\r
127         MACRO   DOFX\r
128         les     di,[pcSound]                            ; PC sound effects\r
129         mov     ax,es\r
130         or      ax,di\r
131         jz      @@nopc                                          ; nil pointer - no PC sound effect going\r
132 \r
133         mov     bl,[es:di]                                      ; Get the byte\r
134         inc     [WORD PTR pcSound]                      ; Increment pointer\r
135         cmp     [pcLastSample],bl                       ; Is this sample the same as last?\r
136         jz      @@pcsame                                        ; Yep - don't do anything\r
137         mov     [pcLastSample],bl                       ; No, save it for next time\r
138 \r
139         or      bl,bl\r
140         jz      @@pcoff                                         ; If 0, turn sounds off\r
141         xor     bh,bh\r
142         shl     bx,1\r
143         mov     bx,[pcSoundLookup+bx]           ; Use byte as index into frequency table\r
144 \r
145         mov     al,0b6h                                         ; Write to channel 2 (speaker) timer\r
146         out     pcTAccess,al\r
147         mov     al,bl\r
148         out     pcTimer,al                                      ; Low byte\r
149         mov     al,bh\r
150         out     pcTimer,al                                      ; High byte\r
151 \r
152         in      al,pcSpeaker                            ; Turn the speaker & gate on\r
153         or      al,3\r
154         out     pcSpeaker,al\r
155 \r
156         jmp @@pcsame\r
157 \r
158 @@pcoff:\r
159         in      al,pcSpeaker                            ; Turn the speaker & gate off\r
160         and     al,0fch                                         ; ~3\r
161         out     pcSpeaker,al\r
162 \r
163 @@pcsame:\r
164         dec     [pcLengthLeft]                          ; Decrement length\r
165         jnz     @@nopc                                          ; If not 0, we're not done with the sound\r
166 \r
167         mov     ax,0\r
168         mov     [WORD PTR pcSound],ax           ; Zero the pointer\r
169         mov     [WORD PTR pcSound + 2],ax\r
170         mov     [SoundNumber],ax                ; Indicate no sound\r
171         mov     [SoundPriority],ax                      ;  with no priority\r
172 \r
173         in      al,pcSpeaker                            ; Turn the speaker off\r
174         and     al,0fdh                                         ; ~2\r
175         out     pcSpeaker,al\r
176 @@nopc:\r
177 \r
178         les     di,[alSound]                            ; AdLib sound effects\r
179         mov     ax,es\r
180         or      ax,di\r
181         jz      @@noal                                          ; nil pointer - no AdLib effect going\r
182 \r
183         xor     ah,ah\r
184         mov     al,[es:di]\r
185         or      al,al\r
186         jz      @@aldone\r
187 \r
188         CALL alOut C,alFreqL,ax\r
189         mov     ax,[alBlock]\r
190 \r
191 @@aldone:\r
192         CALL alOut C,alFreqH,ax\r
193         inc     [WORD PTR alSound]\r
194         dec     [alLengthLeft]\r
195         jnz     @@noal\r
196 \r
197         mov     ax,0\r
198         mov     [WORD PTR alSound],ax           ; Zero the pointer\r
199         mov     [WORD PTR alSound + 2],ax\r
200         mov     [SoundNumber],ax                ; Indicate no sound\r
201         mov     [SoundPriority],ax                      ;  with no priority\r
202         CALL alOut C,alFreqH,ax                 ; Turn off the sound\r
203 @@noal:\r
204 \r
205         ENDM\r
206 \r
207 ;\r
208 ;\r
209 ;\r
210         MACRO   TIME\r
211         cmp     [count_time],2\r
212         jb      @@notime\r
213         add     [LocalTime],1\r
214         adc     [LocalTime+2],0\r
215         add     [TimeCount],1\r
216         adc     [TimeCount+2],0\r
217         mov     [count_time],0\r
218 @@notime:\r
219         ENDM\r
220 \r
221 ;\r
222 ;       COMMONEND\r
223 ;       Macro used for common suffix code\r
224 ;\r
225         MACRO   COMMONEND\r
226 @@fullexit:\r
227         pop     es\r
228         ;popa\r
229         pop di\r
230         pop si\r
231         pop bp\r
232         pop [oldsp]\r
233         pop bx\r
234         pop dx\r
235         pop cx\r
236         pop ax\r
237 \r
238 @@nosave:\r
239         mov     ax,[TimerDivisor]\r
240         add     [TimerCount],ax\r
241         jnc     @@myack\r
242 \r
243         pushf\r
244         call [t0OldService]\r
245         jmp     @@out\r
246 \r
247 @@myack:\r
248         mov     al,20h\r
249         out     20h,al\r
250 \r
251 @@out:\r
252         pop     ax\r
253         pop     ds\r
254 \r
255         IF DEBUG\r
256         mov     dx,STATUS_REGISTER_1\r
257         in      al,dx\r
258         mov     dx,ATR_INDEX\r
259         mov     al,ATR_OVERSCAN\r
260         out     dx,al\r
261         mov     al,3    ; blue\r
262         out     dx,al\r
263         mov     al,20h  ; normal\r
264         out     dx,al\r
265         pop     ax\r
266         pop     dx\r
267         ENDIF\r
268 \r
269         iret\r
270         ENDM\r
271 \r
272 ;\r
273 ;       SDL_IndicatePC\r
274 ;\r
275         PROC    SDL_IndicatePC on:WORD\r
276         PUBLIC  SDL_IndicatePC\r
277 \r
278         mov     ax,[on]\r
279         mov     [cs:pcindicate],ax\r
280         ret\r
281 \r
282         ENDP\r
283 \r
284 ;\r
285 ;       SDL_t0ExtremeAsmService\r
286 ;       Timer 0 ISR 7000Hz interrupts\r
287 ;\r
288         PROC    SDL_t0ExtremeAsmService\r
289         PUBLIC  SDL_t0ExtremeAsmService\r
290 \r
291         push ax\r
292         mov     al,[BYTE PTR cs:pcindicate]\r
293         or      al,al\r
294         jz      @@done\r
295 \r
296         push ds\r
297         push es\r
298         ;pusha\r
299         jmp @@skipme\r
300         oldsp dw ?\r
301 @@skipme:\r
302         mov [oldsp], sp\r
303         push ax\r
304         push cx\r
305         push dx\r
306         push bx\r
307         push [oldsp]\r
308         push bp\r
309         push si\r
310         push di\r
311 \r
312         mov     ds,[cs:MyDS]\r
313 \r
314         les     di,[pcSound]\r
315         mov     ax,es\r
316         or      ax,di\r
317         jz      @@donereg                                       ; nil pointer\r
318 \r
319         mov     bl,[es:di]                                      ; Get the byte\r
320         inc     [WORD PTR pcSound]                      ; Increment pointer\r
321 \r
322         and     bl,11100000b                            ; Nuke some of the precision (DEBUG - do this in the table)\r
323 \r
324         xor     bh,bh\r
325         mov     ah,[pcdtab+bx]                          ; Translate the byte\r
326 \r
327         in      al,pcSpeaker\r
328         and     al,11111100b\r
329         or      al,ah\r
330         out     pcSpeaker,al\r
331 \r
332         dec     [pcLengthLeft]\r
333         jnz     @@donereg\r
334 \r
335         mov     [WORD PTR pcSound],0            ; We're done with this sample\r
336         mov     [WORD PTR pcSound+2],0\r
337 \r
338         in      al,pcSpeaker\r
339         and     al,11111100b\r
340         out     pcSpeaker,al\r
341 \r
342         call SDL_DigitizedDone\r
343 \r
344 @@donereg:\r
345         ;popa\r
346         pop di\r
347         pop si\r
348         pop bp\r
349         pop [oldsp]\r
350         pop bx\r
351         pop dx\r
352         pop cx\r
353         pop ax\r
354         pop     es\r
355         pop     ds\r
356 \r
357 @@done:\r
358         inc     [cs:extreme]\r
359         cmp     [cs:extreme],10\r
360         jae     @@tofast\r
361 \r
362         mov     al,20h\r
363         out     20h,al\r
364         pop     ax\r
365         iret\r
366 \r
367 @@tofast:\r
368         mov     [cs:extreme],0\r
369         pop     ax\r
370 \r
371 ;       jmp     SDL_t0FastAsmService                    ; Drops through to SDL_t0FastAsmService\r
372 \r
373         ENDP\r
374 \r
375 ;\r
376 ;       SDL_t0FastAsmService\r
377 ;       Timer 0 ISR for 700Hz interrupts\r
378 ;\r
379         PROC    SDL_t0FastAsmService\r
380         PUBLIC  SDL_t0FastAsmService\r
381 \r
382         COMMONSTART\r
383 \r
384         inc     [count_fx]                                              ; Time to do PC/AdLib effects & time?\r
385         cmp     [count_fx],5\r
386         jae     @@dofull\r
387 \r
388         mov     ax,[sqActive]                                   ; Is the sequencer active?\r
389         or      ax,ax\r
390         jnz     @@dofull\r
391 \r
392         mov     ax,[WORD PTR ssSample]                  ; Is there a sample for the Sound Src?\r
393         or      ax,[WORD PTR ssSample+2]\r
394         jz      @@nosave\r
395 \r
396 @@dofull:\r
397         ;pusha\r
398         mov [oldsp], sp\r
399         push ax\r
400         push cx\r
401         push dx\r
402         push bx\r
403         push [oldsp]\r
404         push bp\r
405         push si\r
406         push di\r
407         push es\r
408 \r
409         cmp     [count_fx],5\r
410         jb      @@nofx\r
411         mov     [count_fx],0\r
412         DOFX\r
413 \r
414         inc     [count_time]\r
415         TIME\r
416 @@nofx:\r
417 \r
418         mov     ax,[sqActive]\r
419         or      ax,ax\r
420         jz      @@nosq\r
421 \r
422         mov     ax,[sqHackLen]\r
423         or      ax,ax\r
424         jz      @@sqdone\r
425 \r
426         les     di,[sqHackPtr]\r
427 @@sqloop:\r
428         mov     ax,[WORD PTR sqHackTime+2]\r
429         cmp     ax,[WORD PTR alTimeCount+2]\r
430         ja      @@sqdone\r
431         mov     ax,[WORD PTR sqHackTime]\r
432         cmp     ax,[WORD PTR alTimeCount]\r
433         ja      @@sqdone\r
434 \r
435         mov     ax,[es:di+2]                                    ; Get time to next event\r
436         add     ax,[WORD PTR alTimeCount]\r
437         mov     [WORD PTR sqHackTime],ax\r
438         mov     ax,[WORD PTR alTimeCount+2]\r
439         adc     ax,0\r
440         mov     [WORD PTR sqHackTime+2],ax\r
441 \r
442         mov     ax,[es:di]                                              ; Get register/value pair\r
443         xor     bh,bh\r
444         mov     bl,ah\r
445         xor     ah,ah\r
446         CALL alOut C,ax,bx\r
447 \r
448         add     di,4\r
449         mov     [WORD PTR sqHackPtr],di\r
450 \r
451         sub     [sqHackLen],4\r
452         jnz     @@sqloop\r
453 \r
454 @@sqdone:\r
455         add     [WORD PTR alTimeCount],1\r
456         adc     [WORD PTR alTimeCount+2],0\r
457         mov     ax,[sqHackLen]\r
458         or      ax,ax\r
459         jnz     @@nosq\r
460 \r
461         mov     ax,[WORD PTR sqHack]            ; Copy pointer\r
462         mov     [WORD PTR sqHackPtr],ax\r
463         mov     ax,[WORD PTR sqHack+2]\r
464         mov     [WORD PTR sqHackPtr+2],ax\r
465 \r
466         mov     ax,[sqHackSeqLen]                       ; Copy length\r
467         mov     [sqHackLen],ax\r
468 \r
469         mov     ax,0\r
470         mov     [WORD PTR alTimeCount],ax       ; Reset time counts\r
471         mov     [WORD PTR alTimeCount+2],ax\r
472         mov     [WORD PTR sqHackTime],ax\r
473         mov     [WORD PTR sqHackTime+2],ax\r
474 @@nosq:\r
475 \r
476         les     di,[ssSample]                   ; Get pointer to Sound Source sample\r
477         mov     ax,es\r
478         or      ax,di\r
479         jz      @@ssdone                                ; If nil, skip this\r
480 \r
481 @@ssloop:\r
482         mov     dx,[ssStatus]                   ; Check to see if FIFO has any empty slots\r
483         in      al,dx\r
484         test al,40h\r
485         jnz     @@ssdone                                ; Nope - don't push any more data out\r
486 \r
487         mov     dx,[ssData]\r
488         mov     al,[es:di]                              ; al = *ssSample\r
489         out     dx,al                                   ; Pump the value out\r
490 \r
491         mov     dx,[ssControl]                  ; Pulse printer select\r
492         mov     al,[ssOff]\r
493         out     dx,al\r
494         push ax\r
495         pop     ax\r
496         mov     al,[ssOn]\r
497         out     dx,al\r
498 \r
499         push ax                                         ; Delay a short while\r
500         pop     ax\r
501 \r
502         inc     di\r
503         mov     [WORD PTR ssSample],di  ; ssSample++\r
504 \r
505         dec     [ssLengthLeft]\r
506         jnz @@ssloop\r
507 \r
508         mov     [WORD PTR ssSample],0   ; We're done with this sample\r
509         mov     [WORD PTR ssSample+2],0\r
510 \r
511         call SDL_DigitizedDone\r
512 @@ssdone:\r
513 \r
514         COMMONEND\r
515 \r
516         ENDP\r
517 \r
518 ;\r
519 ;       SDL_t0SlowAsmService\r
520 ;       Timer 0 ISR for 140Hz interrupts\r
521 ;\r
522         PROC    SDL_t0SlowAsmService\r
523         PUBLIC  SDL_t0SlowAsmService\r
524 \r
525         IF DEBUG\r
526         push dx\r
527         push ax\r
528         mov     dx,STATUS_REGISTER_1\r
529         in      al,dx\r
530         mov     dx,ATR_INDEX\r
531         mov     al,ATR_OVERSCAN\r
532         out     dx,al\r
533         mov     al,4    ; red\r
534         out     dx,al\r
535         ENDIF\r
536 \r
537         push ds\r
538         push ax\r
539 \r
540         mov     ds,[cs:MyDS]\r
541 \r
542         inc     [count_time]\r
543         TIME\r
544 \r
545         mov     ax,[WORD PTR pcSound]           ; Is there a PC sound effect going?\r
546         or      ax,[WORD PTR pcSound+2]\r
547         jnz     @@dofull\r
548 \r
549         mov     ax,[WORD PTR alSound]           ; Is there an AdLib sound effect going?\r
550         or      ax,[WORD PTR alSound+2]\r
551         jz      @@nosave\r
552 \r
553 @@dofull:\r
554         ;pusha\r
555         mov [oldsp], sp\r
556         push ax\r
557         push cx\r
558         push dx\r
559         push bx\r
560         push [oldsp]\r
561         push bp\r
562         push si\r
563         push di\r
564         push es\r
565 \r
566         DOFX\r
567 \r
568         COMMONEND\r
569 \r
570         ENDP\r
571 \r
572         END\r