wolf3d

The original open source release of Wolfenstein 3D
Log | Files | Refs

ID_SD_A.ASM (9220B)


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