-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplayer.asm
377 lines (286 loc) · 12.7 KB
/
player.asm
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
;
; Intel 81x ICHx .wav player for DOS.
;
;
; Notice: This program was generated for the ICH2 southbridge AC97 audio
; device. It is assumed that ICH0 and ICH1's are compatible.
;
; The software does a PCI scan looking for the ICH2 device ID (2445)
; and only this device. Code will have to be modified to support
; other ICH devices.
;
.DOSSEG
.MODEL small, c, os_dos
.386
.CODE
INCLUDE constant.inc
INCLUDE ich2ac97.inc
extern setFree:NEAR
extern pciBusDetect:NEAR
extern pciFindDevice:NEAR
extern pciRegRead32:NEAR
extern pciRegRead16:NEAR
extern pciRegRead8:NEAR
extern pciRegWrite8:NEAR
extern codecConfig:NEAR
extern memAlloc:NEAR
extern processCmdline:NEAR
extern openFile:NEAR
extern closeFile:NEAR
extern filehandle:WORD
extern playWav:NEAR
extern getSampleRate:NEAR
extern print16BitHexValue:NEAR
; player internal variables and other equates.
FILESIZE equ 64 * 1024 ; 64k file buffer size.
.STARTUP
; memory allocation
call setFree ; deallocate unused DOS mem
; allocate 256 bytes of data for DCM_OUT Buffer Descriptor List. (BDL)
mov ax, BDL_SIZE / 16
call memAlloc
mov ds:[BDL_BUFFER], ax ; segment
; allocate 2 buffers, 64k each for now.
mov ax, FILESIZE / 16 ; 64k for .WAV file
call memAlloc
mov ds:[WAV_BUFFER1], ax ; segment
mov ax, FILESIZE / 16
call memAlloc
mov ds:[WAV_BUFFER2], ax
call pciBusDetect
jz pci_bios_detected
pci_bios_not_detected:
lea dx, noPciBiosMsg
call printData
jmp exit
pci_bios_detected:
; Detect/reset AC97
; I have an ICH2 on my board, you might have an ICH0 or ICH4 or whatever.
; You may need to change this ICH2 device ID scan to match your hardware, or
; better yet, change it to support multiple devices.
;
; UPDATE 2020-05-23: Support for the regular ICH implementation has been
; successfully tested with emulated AC'97 ICH devices in
; both QEMU and VirtualBox VMs.
; ICH0 hasn't been tested yet at this point, but since its
; age technology-wise is between ICH and ICH2, it's
; reasonable to assume that it will work as well.
; Support for ICH3 through ICH7 has been added as well, as
; well as ESB (an ICH5 variant) and the 82440MX (440MX)
; mobile chipset. All currently untested. We'll scan
; for all these variants. (Can take up to 10 seconds, at
; least in DOSBox and QEMU. Suggestions to speed up the
; detection process would be greatly appreciated.)
; In the future, this "whitelist" may be expanded to include
; additional compatible AC'97 variants, not just from Intel.
; If anybody reading this comment happens to have an actual
; PC with any ICH AC'97 implementation and would be willing
; to test this software with it, that would be great! :)
;
; Check for an ICH southbridge
lea dx, ichDetectedMsg
mov eax, (ICH_DID shl 16) + INTEL_VID
call pciFindDevice
jnc @f
; Check for an ICH0 southbridge
lea dx, ich0DetectedMsg
mov eax, (ICH0_DID shl 16) + INTEL_VID
call pciFindDevice
jnc @f
; Check for an ICH2 southbridge
lea dx, ich2DetectedMsg
mov eax, (ICH2_DID shl 16) + INTEL_VID
call pciFindDevice
jnc @f
; Check for an ICH3 southbridge
lea dx, ich3DetectedMsg
mov eax, (ICH3_DID shl 16) + INTEL_VID
call pciFindDevice
jnc @f
; Check for an ICH4 southbridge
lea dx, ich4DetectedMsg
mov eax, (ICH4_DID shl 16) + INTEL_VID
call pciFindDevice
jnc @f
; Check for an ICH5 southbridge
lea dx, ich5DetectedMsg
mov eax, (ICH5_DID shl 16) + INTEL_VID
call pciFindDevice
jnc @f
; Check for an Enterprise Southbridge (ESB)
lea dx, esbDetectedMsg
mov eax, (ESB_DID shl 16) + INTEL_VID
call pciFindDevice
jnc @f
; Check for an ICH6 southbridge
lea dx, ich6DetectedMsg
mov eax, (ICH6_DID shl 16) + INTEL_VID
call pciFindDevice
jnc @f
; Check for an ICH7 southbridge
lea dx, ich7DetectedMsg
mov eax, (ICH7_DID shl 16) + INTEL_VID
call pciFindDevice
jnc @f
; Check for a 440MX chipset
lea dx, immx440DetectedMsg
mov eax, (I440MX_DID shl 16) + INTEL_VID
call pciFindDevice
jnc @f
; Check for a SiS7012 AC'97 Sound Controller
lea dx, sis7012DetectedMsg
mov eax, (SIS_7012_DID shl 16) + SIS_VID
call pciFindDevice
jnc @f
; couldn't find any supported audio device!
push cs
pop ds
lea dx, noDevMsg
mov ah, 9
int 21h
jmp exit
noDevMsg db "Error: Unable to find any supported AC'97 audio device!",CR,LF,"$"
@@:
; Store the detected device and vendor ID (should still be in eax)
mov dword ptr[DETECTED_PCI_DEV],eax
; Report whatever device has been detected at this point
; (dx should now be pointing to the message corresponding to the detected device)
call printData
; get PCI subsystem info
mov al, PCI_SUBSYS_REG
call pciRegRead32
; Print PCI subsystem info in EAX
push eax ; push PCI address
mov eax,edx ; mov PCI subsystem info to eax
push edx
lea dx, subsystemVendorIdMsg
call printData ; needs only DX pointing to variable
call print16BitHexValue ; prints whatever is in AX right now
pop edx
rol edx,16 ; move the high word of EDX to DX
mov ax,dx
lea dx, subsystemIdMsg
call printData ; needs only DX pointing to variable
call print16BitHexValue ; prints whatever is in AX right now
pop eax ; pop PCI address
; get ICH base address regs for mixer and bus master
mov al, NAMBAR_REG
call pciRegRead16 ; read PCI registers 10-11
and dx, IO_ADDR_MASK ; mask off BIT0
mov ds:[NAMBAR], dx ; save audio mixer base addy
mov al, NABMBAR_REG
call pciRegRead16
and dx, IO_ADDR_MASK
mov ds:[NABMBAR], dx ; save bus master base addy
mov al, PCI_CMD_REG
call pciRegRead8 ; read PCI command register
or dl, IO_ENA+BM_ENA ; enable IO and bus master
call pciRegWrite8
; check the command line for a file to play
push ds
call processCmdline ; get the filename
; keep the change_volume parameter in BH, for calling codecConfig later
mov bh,ah
; open the file
mov al, OPEN ; open existing file
call openFile ; no error? ok.
pop ds
jnc @f
; file not found!
push cs
pop ds
lea dx, noFileErrMsg
mov ah, 9
int 21h
jmp exit
noFileErrMsg db "Error: file not found.",CR,LF,"$"
@@:
call getSampleRate ; read the sample rate
; pass it onto codec.
; setup the Codec (actually mixer registers)
call codecConfig ; unmute codec, set rates.
;
; position file pointer to start in actual wav data
; MUCH improvement should really be done here to check if sample size is
; supported, make sure there are 2 channels, etc.
;
mov ah, 42h
mov al, 0 ; from start of file
mov bx, cs:[filehandle]
xor cx, cx
mov dx, 44 ; jump past .wav/riff header
int 21h
; play the .wav file. Most of the good stuff is in here.
call playWav
; close the .wav file and exit.
call closeFile
exit:
mov ax, 4c00h
int 21h
; Entry: DX points to variable in the .DATA section of this file (the variable you with to be printed to screen)
printData proc public
pusha
mov ax,@data
mov ds,ax
mov ah, 9
int 21h
popa
ret
printData endp
.DATA
public BDL_BUFFER ; 256 byte buffer for descriptor list
public WAV_BUFFER1,WAV_BUFFER2 ; 64k buffers for wav file storage
public NAMBAR ; PCI BAR for mixer registers
public NABMBAR ; PCI BAR for bus master registers
public DETECTED_PCI_DEV ; The detected PCI device, device+vendor ID
BDL_BUFFER dw 0 ; segment of our 256byte BDL buffer
WAV_BUFFER1 dw 0 ; segment of our WAV storage
WAV_BUFFER2 dw 0 ; segment of 2nd wav buffer
NAMBAR dw 0 ; BAR for mixer
NABMBAR dw 0 ; BAR for bus master regs
DETECTED_PCI_DEV dd 0 ; The detected PCI device, device+vendor ID
ichDetectedMsg db "Intel 82801AA AC'97 Audio Controller (ICH) detected.",CR,LF,
"PCI Vendor ID : 8086h",CR,LF,
"PCI Device ID : 2415h",CR,LF,"$"
ich0DetectedMsg db "Intel 82801AB AC'97 Audio Controller (ICH0) detected.",CR,LF,
"(Untested model, let me know on GitHub whether it works or not!)",CR,LF,
"PCI Vendor ID : 8086h",CR,LF,
"PCI Device ID : 2425h",CR,LF,"$"
ich2DetectedMsg db "82801BA/BAM AC'97 Audio Controller (ICH2) detected.",CR,LF,
"PCI Vendor ID : 8086h",CR,LF,
"PCI Device ID : 2445h",CR,LF,"$"
ich3DetectedMsg db "82801CA/CAM AC'97 Audio Controller (ICH3) detected.",CR,LF,
"PCI Vendor ID : 8086h",CR,LF,
"PCI Device ID : 2485h",CR,LF,"$"
ich4DetectedMsg db "82801DB/DBL/DBM AC'97 Audio Controller (ICH4) detected.",CR,LF,
"(Untested model, let me know on GitHub whether it works or not!)",CR,LF,
"PCI Vendor ID : 8086h",CR,LF,
"PCI Device ID : 24c5h",CR,LF,"$"
ich5DetectedMsg db "82801EB/ER AC'97 Audio Controller (ICH5) detected.",CR,LF,
"(Untested model, let me know on GitHub whether it works or not!)",CR,LF,
"PCI Vendor ID : 8086h",CR,LF,
"PCI Device ID : 24d5h",CR,LF,"$"
esbDetectedMsg db "6300ESB AC'97 Audio Controller (ESB) detected.",CR,LF,
"(Untested model, let me know on GitHub whether it works or not!)",CR,LF,
"PCI Vendor ID : 8086h",CR,LF,
"PCI Device ID : 25a6h",CR,LF,"$"
ich6DetectedMsg db "82801FB/FBM/FR/FW/FRW AC'97 Audio Controller (ICH6) detected.",CR,LF,
"(Untested model, let me know on GitHub whether it works or not!)",CR,LF,
"PCI Vendor ID : 8086h",CR,LF,
"PCI Device ID : 266eh",CR,LF,"$"
ich7DetectedMsg db "82801GB/GBM/GR/GH/GHM AC'97 Audio Controller (ICH7) detected.",CR,LF,
"(Untested model, let me know on GitHub whether it works or not!)",CR,LF,
"PCI Vendor ID : 8086h",CR,LF,
"PCI Device ID : 27deh",CR,LF,"$"
immx440DetectedMsg db "82440MX AC'97 Audio Controller (MX440) detected.",CR,LF,
"(Untested model, let me know on GitHub whether it works or not!)",CR,LF,
"PCI Vendor ID : 8086h",CR,LF,
"PCI Device ID : 7195h",CR,LF,"$"
sis7012DetectedMsg db "SiS7012 AC'97 Sound Controller detected.",CR,LF,
"(Untested model, let me know on GitHub whether it works or not!)",CR,LF,
"PCI Vendor ID : 1039h",CR,LF,
"PCI Device ID : 7012h",CR,LF,"$"
subsystemIdMsg db "Device Subsystem ID : $"
subsystemVendorIdMsg db "Device Subsystem Vendor ID: $"
noPciBiosMsg db "No PCI bus detected in this system.",CR,LF,"$"
End