Subversion Repositories Kolibri OS

Rev

Rev 1623 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
1548 Asper 1
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2
;;                                                              ;;
3
;; Copyright (C) KolibriOS team 2004-2007. All rights reserved. ;;
4
;; Distributed under terms of the GNU General Public License    ;;
5
;;                                                              ;;
6
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7
 
8
format MS COFF
9
 
10
DEBUG		equ 1
11
 
12
include 'proc32.inc'
13
include 'imports.inc'
14
 
15
API_VERSION	equ 0x01000100
16
 
17
USE_COM_IRQ	equ 0	 ;make irq 3 and irq 4 available for PCI devices
18
IRQ_REMAP	equ 0
19
IRQ_LINE	equ 0
20
 
21
 
22
;irq 0,1,2,8,12,13 недоступны
23
;                   FEDCBA9876543210
24
VALID_IRQ	equ 1100111011111000b
25
ATTCH_IRQ	equ 0000111010100000b
26
 
27
if USE_COM_IRQ
28
ATTCH_IRQ	equ 0000111010111000b
29
end if
30
 
31
CPU_FREQ	equ  2600d
32
 
33
BIT0  EQU 0x00000001
34
BIT1  EQU 0x00000002
35
BIT5  EQU 0x00000020
36
BIT10 EQU 0x00000400
37
 
38
VID_VIA 	  equ 0x1106
39
 
40
CTRL_VT82C686	  equ 0x3058
41
CTRL_VT8233_5	  equ 0x3059
42
 
43
 
44
CODEC_MASTER_VOL_REG	     equ 0x02
45
CODEC_AUX_VOL		     equ 0x04 ;
46
CODEC_PCM_OUT_REG	     equ 0x18 ; PCM output volume
47
CODEC_EXT_AUDIO_REG	     equ 0x28 ; extended audio
48
CODEC_EXT_AUDIO_CTRL_REG     equ 0x2a ; extended audio control
49
CODEC_PCM_FRONT_DACRATE_REG  equ 0x2c ; PCM out sample rate
50
CODEC_PCM_SURND_DACRATE_REG  equ 0x2e ; surround sound sample rate
51
CODEC_PCM_LFE_DACRATE_REG    equ 0x30 ; LFE sample rate
52
 
53
 
54
;VIA host controller registers set
55
;; common offsets
56
VIA_REG_OFFSET_STATUS	     equ   0x00    ;; byte - channel status
57
  VIA_REG_STAT_ACTIVE		   equ	 0x80	 ;; RO
58
  VIA_REG_STAT_PAUSED		   equ	 0x40	 ;; RO
59
  VIA_REG_STAT_TRIGGER_QUEUED	   equ	 0x08	 ;; RO
60
  VIA_REG_STAT_STOPPED		   equ	 0x04	 ;; RWC
61
  VIA_REG_STAT_EOL		   equ	 0x02	 ;; RWC
62
  VIA_REG_STAT_FLAG		   equ	 0x01	 ;; RWC
63
VIA_REG_OFFSET_CONTROL	     equ   0x01    ;; byte - channel control
64
  VIA_REG_CTRL_START		   equ	 0x80	 ;; WO
65
  VIA_REG_CTRL_TERMINATE	   equ	 0x40	 ;; WO
66
  VIA_REG_CTRL_AUTOSTART	   equ	 0x20
67
  VIA_REG_CTRL_PAUSE		   equ	 0x08	 ;; RW
68
  VIA_REG_CTRL_INT_STOP 	   equ	 0x04
69
  VIA_REG_CTRL_INT_EOL		   equ	 0x02
70
  VIA_REG_CTRL_INT_FLAG 	   equ	 0x01
71
  VIA_REG_CTRL_RESET		   equ	 0x01	 ;; RW - probably reset? undocumented
72
  VIA_REG_CTRL_INT		   equ	(VIA_REG_CTRL_INT_FLAG or \
73
					 VIA_REG_CTRL_INT_EOL or \
74
					 VIA_REG_CTRL_AUTOSTART)
75
VIA_REG_OFFSET_TYPE	     equ   0x02    ;; byte - channel type (686 only)
76
  VIA_REG_TYPE_AUTOSTART	   equ	 0x80	 ;; RW - autostart at EOL
77
  VIA_REG_TYPE_16BIT		   equ	 0x20	 ;; RW
78
  VIA_REG_TYPE_STEREO		   equ	 0x10	 ;; RW
79
  VIA_REG_TYPE_INT_LLINE	   equ	 0x00
80
  VIA_REG_TYPE_INT_LSAMPLE	   equ	 0x04
81
  VIA_REG_TYPE_INT_LESSONE	   equ	 0x08
82
  VIA_REG_TYPE_INT_MASK 	   equ	 0x0c
83
  VIA_REG_TYPE_INT_EOL		   equ	 0x02
84
  VIA_REG_TYPE_INT_FLAG 	   equ	 0x01
85
VIA_REG_OFFSET_TABLE_PTR     equ   0x04    ;; dword - channel table pointer
86
VIA_REG_OFFSET_CURR_PTR      equ   0x04    ;; dword - channel current pointer
87
VIA_REG_OFFSET_STOP_IDX      equ   0x08    ;; dword - stop index, channel type, sample rate
88
  VIA8233_REG_TYPE_16BIT	   equ	 0x00200000	 ;; RW
89
  VIA8233_REG_TYPE_STEREO	   equ	 0x00100000	 ;; RW
90
VIA_REG_OFFSET_CURR_COUNT    equ   0x0c    ;; dword - channel current count (24 bit)
91
VIA_REG_OFFSET_CURR_INDEX    equ   0x0f    ;; byte - channel current index (for via8233 only)
92
 
93
 
94
VIADEV_PLAYBACK 	equ   0x00
95
VIADEV_CAPTURE		equ   0x10
96
VIADEV_FM		equ   0x20
97
 
98
;; AC'97 ;;
99
VIA_REG_AC97		 equ   0x80    ; dword
100
  VIA_REG_AC97_CODEC_ID_MASK	   equ	0xC0000000 ;(3<<30)
101
  VIA_REG_AC97_CODEC_ID_SHIFT	   equ	30
102
  VIA_REG_AC97_CODEC_ID_PRIMARY    equ	0x00
103
  VIA_REG_AC97_CODEC_ID_SECONDARY  equ	0x01
104
  VIA_REG_AC97_SECONDARY_VALID	   equ	0x08000000 ;(1<<27)
105
  VIA_REG_AC97_PRIMARY_VALID	   equ	0x02000000 ;(1<<25)
106
  VIA_REG_AC97_BUSY		   equ	0x01000000 ;(1<<24)
107
  VIA_REG_AC97_READ		   equ	0x00800000 ;(1<<23)
108
  VIA_REG_AC97_CMD_SHIFT	   equ	16
109
  VIA_REG_AC97_CMD_MASK 	   equ	0x7E
110
  VIA_REG_AC97_DATA_SHIFT	   equ	0
111
  VIA_REG_AC97_DATA_MASK	   equ	0xFFFF
112
 
113
VIA_REG_SGD_SHADOW	 equ   0x84    ; dword
114
 
115
;; via8233-specific registers ;;
116
VIA_REG_OFS_PLAYBACK_VOLUME_L	equ  0x02    ;; byte
117
VIA_REG_OFS_PLAYBACK_VOLUME_R	equ  0x03    ;; byte
118
VIA_REG_OFS_MULTPLAY_FORMAT	equ  0x02    ;; byte - format and channels
119
  VIA_REG_MULTPLAY_FMT_8BIT	     equ  0x00
120
  VIA_REG_MULTPLAY_FMT_16BIT	     equ  0x80
121
  VIA_REG_MULTPLAY_FMT_CH_MASK	     equ  0x70	  ;; # channels << 4 (valid = 1,2,4,6)
122
VIA_REG_OFS_CAPTURE_FIFO	equ  0x02    ;; byte - bit 6 = fifo  enable
123
  VIA_REG_CAPTURE_FIFO_ENABLE	     equ  0x40
124
 
125
VIA_DXS_MAX_VOLUME		equ  31      ;; max. volume (attenuation) of reg 0x32/33
126
 
127
VIA_TBL_BIT_FLAG	  equ	0x40000000
128
VIA_TBL_BIT_EOL 	  equ	0x80000000
129
 
130
;; pci space ;;
131
VIA_ACLINK_STAT 	  equ	0x40
132
  ;...
133
  VIA_ACLINK_C00_READY		   equ	 0x01 ; primary codec ready
134
VIA_ACLINK_CTRL 	  equ	0x41
135
  VIA_ACLINK_CTRL_ENABLE	   equ	 0x80 ; 0: disable, 1: enable
136
  VIA_ACLINK_CTRL_RESET 	   equ	 0x40 ; 0: assert, 1: de-assert
137
  VIA_ACLINK_CTRL_SYNC		   equ	 0x20 ; 0: release SYNC, 1: force SYNC hi
138
  VIA_ACLINK_CTRL_SDO		   equ	 0x10 ; 0: release SDO, 1: force SDO hi
139
  VIA_ACLINK_CTRL_VRA		   equ	 0x08 ; 0: disable VRA, 1: enable VRA
140
  VIA_ACLINK_CTRL_PCM		   equ	 0x04 ; 0: disable PCM, 1: enable PCM
141
  VIA_ACLINK_CTRL_FM		   equ	 0x02 ; via686 only
142
  VIA_ACLINK_CTRL_SB		   equ	 0x01 ; via686 only
143
  VIA_ACLINK_CTRL_INIT		   equ	(VIA_ACLINK_CTRL_ENABLE or \
144
					 VIA_ACLINK_CTRL_RESET or \
145
					 VIA_ACLINK_CTRL_PCM or \
146
					 VIA_ACLINK_CTRL_VRA)
147
VIA_FUNC_ENABLE 	  equ	0x42
148
  VIA_FUNC_MIDI_PNP		   equ	 0x80 ; FIXME: it's 0x40 in the datasheet!
149
  VIA_FUNC_MIDI_IRQMASK 	   equ	 0x40 ; FIXME: not documented!
150
  VIA_FUNC_RX2C_WRITE		   equ	 0x20
151
  VIA_FUNC_SB_FIFO_EMPTY	   equ	 0x10
152
  VIA_FUNC_ENABLE_GAME		   equ	 0x08
153
  VIA_FUNC_ENABLE_FM		   equ	 0x04
154
  VIA_FUNC_ENABLE_MIDI		   equ	 0x02
155
  VIA_FUNC_ENABLE_SB		   equ	 0x01
156
VIA_PNP_CONTROL 	  equ	0x43
157
VIA_FM_NMI_CTRL 	  equ	0x48
158
VIA8233_VOLCHG_CTRL	  equ	0x48
159
VIA8233_SPDIF_CTRL	  equ	0x49
160
  VIA8233_SPDIF_DX3		   equ	 0x08
161
  VIA8233_SPDIF_SLOT_MASK	   equ	 0x03
162
  VIA8233_SPDIF_SLOT_1011	   equ	 0x00
163
  VIA8233_SPDIF_SLOT_34 	   equ	 0x01
164
  VIA8233_SPDIF_SLOT_78 	   equ	 0x02
165
  VIA8233_SPDIF_SLOT_69 	   equ	 0x03
166
;] Asper
167
 
168
 
169
SRV_GETVERSION	      equ  0
170
DEV_PLAY	      equ  1
171
DEV_STOP	      equ  2
172
DEV_CALLBACK	      equ  3
173
DEV_SET_BUFF	      equ  4
174
DEV_NOTIFY	      equ  5
175
DEV_SET_MASTERVOL     equ  6
176
DEV_GET_MASTERVOL     equ  7
177
DEV_GET_INFO	      equ  8
178
 
179
struc AC_CNTRL		    ;AC controller base class
180
{ .bus		      dd ?
181
  .devfn	      dd ?
182
 
183
  .vendor	      dd ?
184
  .dev_id	      dd ?
185
  .pci_cmd	      dd ?
186
  .pci_stat	      dd ?
187
 
188
  .codec_io_base      dd ?
189
  .codec_mem_base     dd ?
190
 
191
  .ctrl_io_base       dd ?
192
  .ctrl_mem_base      dd ?
193
  .cfg_reg	      dd ?
194
  .int_line	      dd ?
195
 
196
  .vendor_ids	      dd ?    ;vendor id string
197
  .ctrl_ids	      dd ?    ;hub id string
198
 
199
  .buffer	      dd ?
200
 
201
  .notify_pos	      dd ?
202
  .notify_task	      dd ?
203
 
204
  .lvi_reg	      dd ?
205
  .ctrl_setup	      dd ?
206
  .user_callback      dd ?
207
  .codec_read16       dd ?
208
  .codec_write16      dd ?
209
 
210
  .ctrl_read8	      dd ?
211
  .ctrl_read16	      dd ?
212
  .ctrl_read32	      dd ?
213
 
214
  .ctrl_write8	      dd ?
215
  .ctrl_write16       dd ?
216
  .ctrl_write32       dd ?
217
}
218
 
219
struc CODEC		   ;Audio Chip base class
220
{
221
  .chip_id	      dd ?
222
  .flags	      dd ?
223
  .status	      dd ?
224
 
225
  .ac_vendor_ids      dd ?    ;ac vendor id string
226
  .chip_ids	      dd ?    ;chip model string
227
 
228
  .shadow_flag	      dd ?
229
		      dd ?
230
 
231
  .regs 	      dw ?     ; codec registers
232
  .reg_master_vol     dw ?     ;0x02
233
  .reg_aux_out_vol    dw ?     ;0x04
234
  .reg_mone_vol       dw ?     ;0x06
235
  .reg_master_tone    dw ?     ;0x08
236
  .reg_beep_vol       dw ?     ;0x0A
237
  .reg_phone_vol      dw ?     ;0x0C
238
  .reg_mic_vol	      dw ?     ;0x0E
239
  .reg_line_in_vol    dw ?     ;0x10
240
  .reg_cd_vol	      dw ?     ;0x12
241
  .reg_video_vol      dw ?     ;0x14
242
  .reg_aux_in_vol     dw ?     ;0x16
243
  .reg_pcm_out_vol    dw ?     ;0x18
244
  .reg_rec_select     dw ?     ;0x1A
245
  .reg_rec_gain       dw ?     ;0x1C
246
  .reg_rec_gain_mic   dw ?     ;0x1E
247
  .reg_gen	      dw ?     ;0x20
248
  .reg_3d_ctrl	      dw ?     ;0X22
249
  .reg_page	      dw ?     ;0X24
250
  .reg_powerdown      dw ?     ;0x26
251
  .reg_ext_audio      dw ?     ;0x28
252
  .reg_ext_st	      dw ?     ;0x2a
253
  .reg_pcm_front_rate dw ?     ;0x2c
254
  .reg_pcm_surr_rate  dw ?     ;0x2e
255
  .reg_lfe_rate       dw ?     ;0x30
256
  .reg_pcm_in_rate    dw ?     ;0x32
257
		      dw ?     ;0x34
258
  .reg_cent_lfe_vol   dw ?     ;0x36
259
  .reg_surr_vol       dw ?     ;0x38
260
  .reg_spdif_ctrl     dw ?     ;0x3A
261
		      dw ?     ;0x3C
262
		      dw ?     ;0x3E
263
		      dw ?     ;0x40
264
		      dw ?     ;0x42
265
		      dw ?     ;0x44
266
		      dw ?     ;0x46
267
		      dw ?     ;0x48
268
		      dw ?     ;0x4A
269
		      dw ?     ;0x4C
270
		      dw ?     ;0x4E
271
		      dw ?     ;0x50
272
		      dw ?     ;0x52
273
		      dw ?     ;0x54
274
		      dw ?     ;0x56
275
		      dw ?     ;0x58
276
		      dw ?     ;0x5A
277
		      dw ?     ;0x5C
278
		      dw ?     ;0x5E
279
  .reg_page_0	      dw ?     ;0x60
280
  .reg_page_1	      dw ?     ;0x62
281
  .reg_page_2	      dw ?     ;0x64
282
  .reg_page_3	      dw ?     ;0x66
283
  .reg_page_4	      dw ?     ;0x68
284
  .reg_page_5	      dw ?     ;0x6A
285
  .reg_page_6	      dw ?     ;0x6C
286
  .reg_page_7	      dw ?     ;0x6E
287
		      dw ?     ;0x70
288
		      dw ?     ;0x72
289
		      dw ?     ;0x74
290
		      dw ?     ;0x76
291
		      dw ?     ;0x78
292
		      dw ?     ;0x7A
293
  .reg_vendor_id_1    dw ?     ;0x7C
294
  .reg_vendor_id_2    dw ?     ;0x7E
295
 
296
 
297
  .reset	      dd ?    ;virual
298
  .set_master_vol     dd ?
299
}
300
 
301
struc CTRL_INFO
302
{   .pci_cmd	      dd ?
303
    .irq	      dd ?
304
    .glob_cntrl       dd ?
305
    .glob_sta	      dd ?
306
    .codec_io_base    dd ?
307
    .ctrl_io_base     dd ?
308
    .codec_mem_base   dd ?
309
    .ctrl_mem_base    dd ?
310
    .codec_id	      dd ?
311
}
312
 
313
struc IOCTL
314
{  .handle	      dd ?
315
   .io_code	      dd ?
316
   .input	      dd ?
317
   .inp_size	      dd ?
318
   .output	      dd ?
319
   .out_size	      dd ?
320
}
321
 
322
virtual at 0
323
  IOCTL IOCTL
324
end virtual
325
 
326
EVENT_NOTIFY	equ 0x00000200
327
 
328
public START
329
public service_proc
330
public version
331
 
332
section '.flat' code readable align 16
333
 
334
proc START stdcall, state:dword
335
 
336
	   cmp	 [state], 1
337
	   jne	 .stop
338
 
339
     if DEBUG
340
	   mov	 esi, msgInit
341
	   call  SysMsgBoardStr
342
     end if
343
 
344
	   call     detect_controller
345
	   test     eax, eax
346
	   jz	    .fail
347
 
348
     if DEBUG
349
	   mov	 esi,[ctrl.vendor_ids]
350
	   call  SysMsgBoardStr
351
	   mov	 esi, [ctrl.ctrl_ids]
352
	   call  SysMsgBoardStr
353
     end if
354
 
355
	   call     init_controller
356
	   test     eax, eax
357
	   jz	    .fail
358
 
359
	   call     init_codec
360
	   test     eax, eax
361
	   jz	    .fail
362
 
363
	   call     setup_codec
364
 
365
	   mov	    esi, msgPrimBuff
366
	   call     SysMsgBoardStr
367
	   call     create_primary_buff
368
	   mov	    esi, msgDone
369
	   call     SysMsgBoardStr
370
 
371
  if IRQ_REMAP
372
	   pushf
373
	   cli
374
 
375
	   mov	    ebx, [ctrl.int_line]
376
	   in	    al, 0xA1
377
	   mov	    ah, al
378
	   in	    al, 0x21
379
	   test     ebx, ebx
380
	   jz	    .skip
381
	   bts	    ax, bx			;mask old line
382
.skip:
383
	   bts	    ax, IRQ_LINE		;mask new ine
384
	   out	    0x21, al
385
	   mov	    al, ah
386
	   out	    0xA1, al
387
 
388
	   stdcall  PciWrite8, 0, 0xF8, 0x61, IRQ_LINE	;remap IRQ
389
 
390
	   mov	    dx, 0x4d0			;8259 ELCR1
391
	   in	    al, dx
392
	   bts	    ax, IRQ_LINE
393
	   out	    dx, al			;set level-triggered mode
394
	   mov	    [ctrl.int_line], IRQ_LINE
395
	   popf
396
	   mov	    esi, msgRemap
397
	   call     SysMsgBoardStr
398
  end if
399
 
400
	   mov	    eax, VALID_IRQ
401
	   mov	    ebx, [ctrl.int_line]
402
	   mov	    esi, msgInvIRQ
403
	   bt	    eax, ebx
404
	   jnc	    .fail_msg
405
	   mov	    eax, ATTCH_IRQ
406
	   mov	    esi, msgAttchIRQ
407
	   bt	    eax, ebx
408
	   jnc	    .fail_msg
409
 
410
	   stdcall  AttachIntHandler, ebx, ac97_irq_VIA, dword 0
411
.reg:
412
	   stdcall  RegService, sz_sound_srv, service_proc
413
	   ret
414
.fail:
415
     if DEBUG
416
	   mov	 esi, msgFail
417
	   call  SysMsgBoardStr
418
     end if
419
	   xor	    eax, eax
420
	   ret
421
.fail_msg:
422
	   call     SysMsgBoardStr
423
	   xor	    eax, eax
424
	   ret
425
.stop:
426
	   call     stop
427
	   xor	    eax, eax
428
	   ret
429
endp
430
 
431
handle	   equ	IOCTL.handle
432
io_code    equ	IOCTL.io_code
433
input	   equ	IOCTL.input
434
inp_size   equ	IOCTL.inp_size
435
output	   equ	IOCTL.output
436
out_size   equ	IOCTL.out_size
437
 
438
align 4
439
proc service_proc stdcall, ioctl:dword
440
 
441
	   mov	    edi, [ioctl]
442
	   mov	    eax, [edi+io_code]
443
 
444
	   cmp	    eax, SRV_GETVERSION
445
	   jne	    @F
446
	   mov	    eax, [edi+output]
447
	   cmp	    [edi+out_size], 4
448
	   jne	    .fail
449
 
450
	   mov	    [eax], dword API_VERSION
451
	   xor	    eax, eax
452
	   ret
453
@@:
454
	   cmp	    eax, DEV_PLAY
455
	   jne	    @F
456
     if DEBUG
457
	   mov	esi, msgPlay
458
	   call SysMsgBoardStr
459
     end if
460
	   call     play
461
	   ret
462
@@:
463
	   cmp	    eax, DEV_STOP
464
	   jne	    @F
465
     if DEBUG
466
	   mov	esi, msgStop
467
	   call SysMsgBoardStr
468
     end if
469
	   call     stop
470
	   ret
471
@@:
472
	   cmp	    eax, DEV_CALLBACK
473
	   jne	    @F
474
	   mov	    ebx, [edi+input]
475
	   stdcall  set_callback, [ebx]
476
	   ret
477
@@:
478
	   cmp	    eax, DEV_SET_MASTERVOL
479
	   jne	    @F
480
	   mov	    eax, [edi+input]
481
	   mov	    eax, [eax]
482
	   call     set_master_vol	;eax= vol
483
	   ret
484
@@:
485
	   cmp	    eax, DEV_GET_MASTERVOL
486
	   jne	    @F
487
	   mov	    ebx, [edi+output]
488
	   stdcall  get_master_vol, ebx
489
	   ret
490
@@:
491
	   cmp	    eax, DEV_GET_INFO
492
	   jne	    @F
493
	   mov	    ebx, [edi+output]
494
	   stdcall  get_dev_info, ebx
495
	   ret
496
@@:
497
.fail:
498
	   or	    eax, -1
499
	   ret
500
endp
501
 
502
restore   handle
503
restore   io_code
504
restore   input
505
restore   inp_size
506
restore   output
507
restore   out_size
508
 
509
 
510
align 4
511
proc ac97_irq_VIA
512
	   locals
513
	     status db 0
514
	   endl
515
 
516
	   mov	    edx, VIADEV_PLAYBACK   +VIA_REG_OFFSET_STATUS
517
	   call     [ctrl.ctrl_read8]
518
	   test     al, VIA_REG_STAT_ACTIVE
519
	   jz	    @f
520
 
521
	   and	    al, VIA_REG_STAT_EOL or VIA_REG_STAT_FLAG or VIA_REG_STAT_STOPPED
522
	   mov	    byte [status], al
523
 
524
	   mov	    ebx, dword [buff_list]
525
	   cmp	    [ctrl.user_callback], 0
526
	   je	    @f
527
	   stdcall  [ctrl.user_callback], ebx
528
       @@:
529
	   mov	    al, byte [status]		;; ack ;;
530
	   mov	    edx, VIADEV_PLAYBACK   +VIA_REG_OFFSET_STATUS
531
	   call     [ctrl.ctrl_write8]
532
 
533
	   ret
534
endp
535
 
536
 
537
align 4
538
proc create_primary_buff
539
 
540
	   stdcall  KernelAlloc, 0x10000
541
	   mov	    [ctrl.buffer], eax
542
 
543
	   mov	    edi, eax
544
	   mov	    ecx, 0x10000/4
545
	   xor	    eax, eax
546
	   cld
547
	   rep	    stosd
548
 
549
	   mov	    eax, [ctrl.buffer]
550
	   call     GetPgAddr
551
	   mov	    edi, pcmout_bdl
552
	   stosd
553
	   mov	    eax, 0x80004000
554
	   stosd
555
 
556
	   mov	    edi, buff_list
557
	   mov	    eax, [ctrl.buffer]
558
	   mov	    ecx, 4
559
@@:
560
	   mov	    [edi], eax
561
	   mov	    [edi+16], eax
562
	   mov	    [edi+32], eax
563
	   mov	    [edi+48], eax
564
	   mov	    [edi+64], eax
565
	   mov	    [edi+80], eax
566
	   mov	    [edi+96], eax
567
	   mov	    [edi+112], eax
568
 
569
	   ;add      eax, 0x4000
570
	   add	    edi, 4
571
	   loop     @B
572
 
573
	   stdcall  channel_reset, VIADEV_PLAYBACK
574
	   stdcall  codec_check_ready
575
 
576
	   mov	    eax, pcmout_bdl
577
	   mov	    ebx, eax
578
	   call     GetPgAddr
579
	   and	    ebx, 0xFFF
580
	   add	    eax, ebx
581
 
582
	   mov	    edx, VIADEV_PLAYBACK  +VIA_REG_OFFSET_TABLE_PTR
583
	   call     [ctrl.ctrl_write32]
584
 
585
	   stdcall  codec_check_ready
586
 
587
	   mov	    edx, VIADEV_PLAYBACK  +VIA_REG_OFS_PLAYBACK_VOLUME_L
588
	   mov	    eax, 7;31
589
	   call     [ctrl.ctrl_write8]
590
 
591
	   mov	    edx, VIADEV_PLAYBACK  +VIA_REG_OFS_PLAYBACK_VOLUME_R
592
	   mov	    eax, 7;31
593
	   call     [ctrl.ctrl_write8]
594
 
595
	   mov	    edx, VIADEV_PLAYBACK  +VIA_REG_OFFSET_STOP_IDX
596
	   mov	    eax, VIA8233_REG_TYPE_16BIT or VIA8233_REG_TYPE_STEREO or 0xfffff or 0xff000000
597
	   mov	  [ctrl.lvi_reg], 16;0xF;eax
598
	   call     [ctrl.ctrl_write32]
599
 
600
	   stdcall  codec_check_ready
601
	   ret
602
endp
603
 
604
 
605
proc channel_reset channel:dword
606
	   mov	    esi, dword [channel]
607
	   mov	    edx, esi
608
	   add	    edx, VIA_REG_OFFSET_CONTROL
609
	   mov	    eax, VIA_REG_CTRL_PAUSE or VIA_REG_CTRL_TERMINATE or VIA_REG_CTRL_RESET
610
	   call     [ctrl.ctrl_write8]
611
 
612
	   mov	    edx, esi
613
	   add	    edx, VIA_REG_OFFSET_CONTROL
614
	   call     [ctrl.ctrl_read8]
615
 
616
	   mov	    eax, 50000	 ; wait 50 ms
617
	   call     StallExec
618
	   ; disable interrupts
619
	   mov	    edx, esi
620
	   add	    edx, VIA_REG_OFFSET_CONTROL
621
	   xor	    eax, eax
622
	   call     [ctrl.ctrl_write8]
623
 
624
	   ; clear interrupts
625
	   mov	    edx, esi
626
	   add	    edx, VIA_REG_OFFSET_STATUS
627
	   mov	    eax, 0x03
628
	   call     [ctrl.ctrl_write8]
629
 
630
	;outb(0x00, VIADEV_REG(viadev, OFFSET_TYPE)); /* for via686 */
631
	  ; mov      edx, esi                  ;; for via686
632
	  ; add      edx, VIA_REG_OFFSET_TYPE
633
	  ; mov      eax, 0x03
634
	  ; call     [ctrl.ctrl_write8]
635
 
636
	;; outl(0, VIADEV_REG(viadev, OFFSET_CURR_PTR));
637
	   ;mov      edx, esi
638
	   ;add      edx, VIA_REG_OFFSET_CURR_PTR
639
	   ;xor      eax, eax
640
	   ;call     [ctrl.ctrl_write8]
641
 
642
	   ret
643
endp
644
 
645
 
646
align 4
647
proc detect_controller
648
	   locals
649
	     last_bus dd ?
650
	     bus      dd ?
651
	     devfn    dd ?
652
	   endl
653
 
654
	   xor eax, eax
655
	   mov [bus], eax
656
	   inc eax
657
	   call PciApi
658
	   cmp eax, -1
659
	   je .err
660
 
661
	   mov [last_bus], eax
662
 
663
.next_bus:
664
	   and [devfn], 0
665
.next_dev:
666
	   stdcall PciRead32, [bus], [devfn], dword 0
667
	   test eax, eax
668
	   jz .next
669
	   cmp eax, -1
670
	   je .next
671
 
672
	   mov edi, devices
673
@@:
674
	   mov ebx, [edi]
675
	   test ebx, ebx
676
	   jz .next
677
 
678
	   cmp eax, ebx
679
	   je .found
680
	   add edi, 12
681
	   jmp @B
682
.next:
683
	   inc [devfn]
684
	   cmp [devfn], 256
685
	   jb .next_dev
686
	   mov eax, [bus]
687
	   inc eax
688
	   mov [bus], eax
689
	   cmp eax, [last_bus]
690
	   jna .next_bus
691
	   xor eax, eax
692
	   ret
693
.found:
694
	   mov ebx, [bus]
695
	   mov [ctrl.bus], ebx
696
 
697
	   mov ecx, [devfn]
698
	   mov [ctrl.devfn], ecx
699
 
700
	   mov edx, eax
701
	   and edx, 0xFFFF
702
	   mov [ctrl.vendor], edx
703
	   shr eax, 16
704
	   mov [ctrl.dev_id], eax
705
 
706
	   mov ebx, [edi+4]
707
	   mov [ctrl.ctrl_ids], ebx
708
	   mov esi, [edi+8]
709
	   mov [ctrl.ctrl_setup], esi
710
 
711
	   cmp edx, VID_VIA
712
	   jne @F
713
	   mov [ctrl.vendor_ids], msg_VIA
714
	   ret
715
@@:
716
 
717
.err:
718
	   xor eax, eax
719
	   mov [ctrl.vendor_ids], eax	  ;something  wrong ?
720
	   ret
721
endp
722
 
723
align 4
724
proc init_controller
725
 
726
	   stdcall  PciRead32, [ctrl.bus], [ctrl.devfn], dword 4
727
	   mov	    ebx, eax
728
	   and	    eax, 0xFFFF
729
	   mov	    [ctrl.pci_cmd], eax
730
	   shr	    ebx, 16
731
	   mov	    [ctrl.pci_stat], ebx
732
 
733
	   mov	    esi, msgPciCmd
734
	   call     SysMsgBoardStr
735
	   call     dword2str
736
	   call     SysMsgBoardStr
737
 
738
	   mov	    esi, msgPciStat
739
	   call     SysMsgBoardStr
740
	   mov	    eax, [ctrl.pci_stat]
741
	   call     dword2str
742
	   call     SysMsgBoardStr
743
 
744
	   mov	    esi, msgCtrlIsaIo
745
	   call     SysMsgBoardStr
746
	   stdcall  PciRead32, [ctrl.bus], [ctrl.devfn], dword 0x10
747
	   call     dword2str
748
	   call     SysMsgBoardStr
749
 
750
	   and	    eax, 0xFFC0
751
	   mov	    [ctrl.ctrl_io_base], eax
752
 
753
.default:
754
	   stdcall  PciRead32, [ctrl.bus], [ctrl.devfn], dword 0x3C
755
	   and	    eax, 0xFF
756
@@:
757
	   mov	    [ctrl.int_line], eax
758
 
759
	   ;stdcall  PciRead8, [ctrl.bus], [ctrl.devfn], dword VIA_FUNC_ENABLE ;0x42
760
	   ;mov      byte [old_legacy], al
761
 
762
	   ;stdcall  PciRead8, [ctrl.bus], [ctrl.devfn], dword VIA_PNP_CONTROL ;0x43
763
	   ;mov      byte [old_legacy_cfg], al
764
 
765
	   ;mov      al, VIA_FUNC_ENABLE_SB or VIA_FUNC_ENABLE_FM
766
	   ;xor      al, 0xFF
767
	   ;and      al, byte [old_legacy]
768
	   ;and      eax, 0xFF
769
	   ;stdcall  PciWrite8, [ctrl.bus], [ctrl.devfn], dword VIA_FUNC_ENABLE, eax ;0x42
770
	   ;mov      byte [old_legacy], al
771
 
772
	   call     [ctrl.ctrl_setup]
773
	   xor	    eax, eax
774
	   inc	    eax
775
	   ret
776
endp
777
 
778
align 4
779
proc set_VIA
780
	   mov	    [ctrl.codec_read16],  codec_io_r16	  ;virtual
781
	   mov	    [ctrl.codec_write16], codec_io_w16	  ;virtual
782
 
783
	   mov	    [ctrl.ctrl_read8 ],  ctrl_io_r8	  ;virtual
784
	   mov	    [ctrl.ctrl_read16],  ctrl_io_r16	  ;virtual
785
	   mov	    [ctrl.ctrl_read32],  ctrl_io_r32	  ;virtual
786
 
787
	   mov	    [ctrl.ctrl_write8 ], ctrl_io_w8	  ;virtual
788
	   mov	    [ctrl.ctrl_write16], ctrl_io_w16	  ;virtual
789
	   mov	    [ctrl.ctrl_write32], ctrl_io_w32	  ;virtual
790
	   ret
791
endp
792
 
793
 
794
align 4
795
proc init_codec
796
	   locals
797
	     counter dd ?
798
	   endl
799
 
800
	   mov	    esi, msgControl
801
	   call     SysMsgBoardStr
802
	   stdcall  PciRead8, [ctrl.bus], [ctrl.devfn], dword VIA_ACLINK_CTRL
803
	   and	    eax, 0xFF
804
	   call     dword2str
805
	   call     SysMsgBoardStr
806
 
807
	   mov	    esi, msgStatus
808
	   call     SysMsgBoardStr
809
	   stdcall  PciRead8, [ctrl.bus], [ctrl.devfn], dword VIA_ACLINK_STAT
810
	   and	    eax, 0xFF
811
	   push     eax
812
	   call     dword2str
813
	   call     SysMsgBoardStr
814
	   pop	    eax
815
 
816
	   test     eax, VIA_ACLINK_C00_READY
817
	   jz	    .ready
818
 
819
	   call     reset_codec
820
	   test     eax, eax
821
	   jz	    .err
822
 
823
.ready:
824
	   xor	    edx, edx	 ; ac_reg_0
825
	   call     [ctrl.codec_write16]
826
	   jmp	    .done
827
 
828
.err:
829
	   xor	    eax, eax	      ; timeout error
830
	   ret
831
 
832
.done:
833
	   call     detect_codec
834
 
835
	   xor	    eax, eax
836
	   inc	    eax
837
	   ret
838
endp
839
 
840
align 4
841
proc reset_codec
842
	   stdcall  PciWrite8, [ctrl.bus], [ctrl.devfn], dword VIA_ACLINK_CTRL, \
843
			       VIA_ACLINK_CTRL_ENABLE or VIA_ACLINK_CTRL_RESET or VIA_ACLINK_CTRL_SYNC
844
	   mov	    eax, 100000    ; wait 100 ms
845
	   call     StallExec
846
.cold:
847
	   call     cold_reset
848
	   jnc	    .ok
849
 
850
     if DEBUG
851
	   mov	 esi, msgCFail
852
	   call  SysMsgBoardStr
853
     end if
854
	   xor	    eax, eax	 ; timeout error
855
	   ret
856
.ok:
857
     if DEBUG
858
	   mov	 esi, msgResetOk
859
	   call  SysMsgBoardStr
860
     end if
861
	   xor	    eax, eax
862
	   inc	    eax
863
	   ret
864
endp
865
 
866
 
867
align 4
868
proc cold_reset
869
	   locals
870
	     counter dd ?
871
	   endl
872
 
873
	   stdcall  PciWrite8, [ctrl.bus], [ctrl.devfn], dword VIA_ACLINK_CTRL, dword 0
874
 
875
     if DEBUG
876
	   mov	 esi, msgCold
877
	   call  SysMsgBoardStr
878
     end if
879
 
880
	   mov	    eax, 100000     ; wait 100 ms ;400000     ; wait 400 ms
881
	   call     StallExec
882
 
883
	   ;; ACLink on, deassert ACLink reset, VSR, SGD data out
884
	   ;; note - FM data out has trouble with non VRA codecs !!
885
	   stdcall  PciWrite8, [ctrl.bus], [ctrl.devfn], dword VIA_ACLINK_CTRL, dword VIA_ACLINK_CTRL_INIT
886
 
887
	   mov	    [counter], 16    ; total 20*100 ms = 2s
888
.wait:
889
	   stdcall  PciRead8, [ctrl.bus], [ctrl.devfn], dword VIA_ACLINK_STAT
890
	   test     eax, VIA_ACLINK_C00_READY
891
	   jnz	    .ok
892
 
893
	   mov	    eax, 100000    ; wait 100 ms
894
	   call     StallExec
895
 
896
	   dec	    [counter]
897
	   jnz	    .wait
898
 
899
     if DEBUG
900
	   mov	 esi, msgCRFail
901
	   call  SysMsgBoardStr
902
     end if
903
 
904
.fail:
905
	   stc
906
	   ret
907
.ok:
908
	   mov	    esi, msgControl
909
	   call     SysMsgBoardStr
910
	   stdcall  PciRead8, [ctrl.bus], [ctrl.devfn], dword VIA_ACLINK_CTRL
911
	   call     dword2str
912
	   call     SysMsgBoardStr
913
 
914
	   mov	    esi, msgStatus
915
	   call     SysMsgBoardStr
916
	   stdcall  PciRead8, [ctrl.bus], [ctrl.devfn], dword VIA_ACLINK_STAT
917
	   and	    eax, 0xFF
918
	   push     eax
919
	   call     dword2str
920
	   call     SysMsgBoardStr
921
	   pop	    eax
922
 
923
	   test     eax, VIA_ACLINK_C00_READY ;CTRL_ST_CREADY
924
	   jz	    .fail
925
	   clc
926
	   ret
927
endp
928
 
929
align 4
930
play:
931
	   mov	    edx, VIADEV_PLAYBACK   +VIA_REG_OFFSET_STOP_IDX
932
	   mov	    eax, VIA8233_REG_TYPE_16BIT or VIA8233_REG_TYPE_STEREO or 0xfffff or 0xff000000
933
	   mov	 [ctrl.lvi_reg], 16
934
	   call     [ctrl.ctrl_write32]
935
 
936
	   mov	    eax, VIA_REG_CTRL_INT
937
	   or	    eax, VIA_REG_CTRL_START
938
	   mov	    edx, VIADEV_PLAYBACK   +VIA_REG_OFFSET_CONTROL
939
	   call     [ctrl.ctrl_write8]
940
 
941
	   xor	    eax, eax
942
	   ret
943
 
944
align 4
945
stop:
946
	   mov	    eax, VIA_REG_CTRL_INT
947
	   or	    eax, VIA_REG_CTRL_TERMINATE
948
	   mov	    edx, VIADEV_PLAYBACK   +VIA_REG_OFFSET_CONTROL
949
	   call     [ctrl.ctrl_write8]
950
 
951
	   stdcall  channel_reset, VIADEV_PLAYBACK
952
	   xor	    eax, eax
953
	   ret
954
 
955
align 4
956
proc get_dev_info stdcall, p_info:dword
957
	   virtual at esi
958
	     CTRL_INFO CTRL_INFO
959
	   end virtual
960
 
961
	   mov	    esi, [p_info]
962
	   mov	    eax, [ctrl.int_line]
963
	   mov	    ecx, [ctrl.ctrl_io_base]
964
	   mov	    [CTRL_INFO.irq], eax
965
	   mov	    [CTRL_INFO.ctrl_io_base], ecx
966
 
967
	   xor	    eax, eax
968
	   ;mov      edx, VIADEV_PLAYBACK   +VIA_REG_OFFSET_TABLE_PTR
969
	   ;call     [ctrl.ctrl_read32]
970
	   mov	    [CTRL_INFO.codec_io_base], eax
971
	   ;mov      edx, VIADEV_PLAYBACK   +VIA_REG_OFFSET_STOP_IDX
972
	   ;call     [ctrl.ctrl_read32]
973
	   mov	    [CTRL_INFO.codec_mem_base], eax
974
	   ;mov      edx, VIADEV_PLAYBACK   +VIA_REG_OFFSET_CURR_COUNT
975
	   ;call     [ctrl.ctrl_read32]
976
	   mov	    [CTRL_INFO.ctrl_mem_base], eax
977
 
978
	   mov	    eax, [codec.chip_id]
979
	   mov	    [CTRL_INFO.codec_id], eax
980
 
981
	   mov	    edx, VIADEV_PLAYBACK   +VIA_REG_OFFSET_CONTROL
982
	   call     [ctrl.ctrl_read8]
983
	   and	    eax, 0xFF
984
	   mov	    [CTRL_INFO.glob_cntrl], eax
985
 
986
	   mov	    edx, VIADEV_PLAYBACK   +VIA_REG_OFFSET_STATUS
987
	   call     [ctrl.ctrl_read8]
988
	   and	    eax, 0xFF
989
	   mov	    [CTRL_INFO.glob_sta], eax
990
 
991
	   mov	    ebx, [ctrl.pci_cmd]
992
	   mov	    [CTRL_INFO.pci_cmd], ebx
993
	   ret
994
endp
995
 
996
align 4
997
proc set_callback stdcall, handler:dword
998
	   mov	    eax, [handler]
999
	   mov	    [ctrl.user_callback], eax
1000
	   ret
1001
endp
1002
 
1003
 
1004
align 4
1005
proc codec_check_ready stdcall
1006
	   locals
1007
	     counter dd ?
1008
	   endl
1009
 
1010
	   mov	    [counter], 1000	; total 1000*1 ms = 1s
1011
.wait:
1012
	   call     [ctrl.codec_read16]
1013
	   test     eax, VIA_REG_AC97_BUSY
1014
	   jz	    .ok
1015
 
1016
	   mov	    eax, 1000	; wait 1 ms
1017
	   call     StallExec
1018
 
1019
	   sub	    [counter] , 1
1020
	   jnz	    .wait
1021
.err:
1022
	   mov	    eax, -1
1023
	   ret
1024
.ok:
1025
	   and	    eax, 0xFFFF
1026
	   ret
1027
endp
1028
 
1029
 
1030
align 4
1031
proc codec_valid stdcall
1032
	   stdcall  codec_check_ready
1033
	   ret
1034
endp
1035
 
1036
align 4
1037
proc codec_read stdcall, ac_reg:dword	   ; reg = edx, reval = eax
1038
	   locals
1039
	     counter dd ?
1040
	   endl
1041
 
1042
	   ;Use only primary codec.
1043
	   mov	    eax, [ac_reg]
1044
	   and	    eax, 0x7F
1045
	   shl	    eax, VIA_REG_AC97_CMD_SHIFT
1046
	   or	    eax, VIA_REG_AC97_PRIMARY_VALID or VIA_REG_AC97_READ
1047
 
1048
	   mov	    [counter], 3     ; total 3*20 ms = 60ms
1049
.wait:
1050
	   push     eax
1051
	   call     [ctrl.codec_write16]
1052
 
1053
	   mov	    eax, 20000	 ; wait 20 ms
1054
	   call     StallExec
1055
 
1056
	   stdcall  codec_valid,
1057
	   cmp	    eax, 0
1058
	   pop	    eax
1059
	   jge	    .ok
1060
 
1061
	   sub	    [counter] , 1
1062
	   jnz	    .wait
1063
	   jmp	    .err
1064
 
1065
.ok:
1066
	   mov	    eax, 25000	 ; wait 25 ms
1067
	   call     StallExec
1068
 
1069
	   call     [ctrl.codec_read16]  ;change edx !!!
1070
	   and	    eax, 0xFFFF
1071
	   ret
1072
.err:
1073
     if DEBUG
1074
	   mov	 esi, msgCInvalid
1075
	   call  SysMsgBoardStr
1076
     end if
1077
	   mov	    eax, -1	   ; invalid codec error
1078
	   ret
1079
endp
1080
 
1081
align 4
1082
proc codec_write stdcall, ac_reg:dword
1083
	   ;Use only primary codec.
1084
	   mov	    esi, [ac_reg]
1085
	   mov	    edx, esi
1086
	   shl	    edx, VIA_REG_AC97_CMD_SHIFT
1087
 
1088
	   shl	    eax, VIA_REG_AC97_DATA_SHIFT
1089
	   or	    edx, eax
1090
 
1091
	   mov	    eax, VIA_REG_AC97_CODEC_ID_PRIMARY ;not VIA_REG_AC97_CODEC_ID_PRIMARY
1092
	   shl	    eax, VIA_REG_AC97_CODEC_ID_SHIFT
1093
	   or	    edx, eax
1094
 
1095
	   mov	    eax, edx
1096
	   mov	    edx, esi
1097
	   call     [ctrl.codec_write16]
1098
	   mov	    [codec.regs+esi], ax
1099
 
1100
	   stdcall  codec_check_ready
1101
	   cmp	    eax, 0
1102
	   jl	    .err
1103
.ok:
1104
	   ret
1105
.err:
1106
     if DEBUG
1107
	   mov	  esi, msgCFail
1108
	   call   SysMsgBoardStr
1109
     end if
1110
	   ;mov      eax, -1        ; codec not ready error
1111
	   ret
1112
endp
1113
 
1114
align 4
1115
proc StallExec
1116
	   push     ecx
1117
	   push     edx
1118
	   push     ebx
1119
	   push     eax
1120
 
1121
	   mov	    ecx, CPU_FREQ
1122
	   mul	    ecx
1123
	   mov	    ebx, eax	   ;low
1124
	   mov	    ecx, edx	   ;high
1125
	   rdtsc
1126
	   add	    ebx, eax
1127
	   adc	    ecx, edx
1128
@@:
1129
	   rdtsc
1130
	   sub	    eax, ebx
1131
	   sbb	    edx, ecx
1132
	   js	    @B
1133
 
1134
	   pop	    eax
1135
	   pop	    ebx
1136
	   pop	    edx
1137
	   pop	    ecx
1138
	   ret
1139
endp
1140
 
1141
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1142
;          CONTROLLER IO functions
1143
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1144
 
1145
align 4
1146
proc codec_io_r16 ;r32
1147
	   mov	    edx, [ctrl.ctrl_io_base]
1148
	   add	    edx, VIA_REG_AC97
1149
	   in	    eax, dx
1150
	   ret
1151
endp
1152
 
1153
align 4
1154
proc codec_io_w16 ;w32
1155
	   mov	    edx, [ctrl.ctrl_io_base]
1156
	   add	    edx, VIA_REG_AC97
1157
	   out	    dx,  eax
1158
	   ret
1159
endp
1160
 
1161
align 4
1162
proc ctrl_io_r8
1163
	   add	    edx, [ctrl.ctrl_io_base]
1164
	   in	    al, dx
1165
	   ret
1166
endp
1167
 
1168
align 4
1169
proc ctrl_io_r16
1170
	   add	    edx, [ctrl.ctrl_io_base]
1171
	   in	    ax, dx
1172
	   ret
1173
endp
1174
 
1175
align 4
1176
proc ctrl_io_r32
1177
	   add	    edx, [ctrl.ctrl_io_base]
1178
	   in	    eax, dx
1179
	   ret
1180
endp
1181
 
1182
align 4
1183
proc ctrl_io_w8
1184
	   add	    edx, [ctrl.ctrl_io_base]
1185
	   out	    dx, al
1186
	   ret
1187
endp
1188
 
1189
align 4
1190
proc ctrl_io_w16
1191
	   add	    edx, [ctrl.ctrl_io_base]
1192
	   out	    dx, ax
1193
	   ret
1194
endp
1195
 
1196
align 4
1197
proc ctrl_io_w32
1198
	   add	    edx, [ctrl.ctrl_io_base]
1199
	   out	    dx, eax
1200
	   ret
1201
endp
1202
 
1203
 
1204
align 4
1205
dword2str:
1206
	   push     eax ebx ecx
1207
	   mov	    esi, hex_buff
1208
	   mov	    ecx, -8
1209
   @@:
1210
	   rol	    eax, 4
1211
	   mov	    ebx, eax
1212
	   and	    ebx, 0x0F
1213
	   mov	    bl, [ebx+hexletters]
1214
	   mov	    [8+esi+ecx], bl
1215
	   inc	    ecx
1216
	   jnz	    @B
1217
	   pop	    ecx ebx eax
1218
	   ret
1219
 
1220
hexletters   db '0123456789ABCDEF'
1221
hex_buff     db 8 dup(0),13,10,0
1222
 
1223
 
1224
include "codec.inc"
1225
 
1226
align 4
1227
devices dd (CTRL_VT82C686  shl 16)+VID_VIA,msg_VT82C686,set_VIA
1228
	dd (CTRL_VT8233_5  shl 16)+VID_VIA,msg_VT8233,set_VIA
1229
	dd 0	;terminator
1230
 
1231
 
1232
version      dd (5 shl 16) or (API_VERSION and 0xFFFF)
1233
 
1234
msg_VT82C686 db 'VT82C686', 13,10, 0
1235
msg_VT8233   db 'VT8233',   13,10, 0
1236
msg_VIA      db 'VIA'	,   13,10, 0
1237
 
1238
szKernel	    db 'KERNEL', 0
1239
sz_sound_srv	    db 'SOUND',0
1240
 
1241
msgInit      db 'detect hardware...',13,10,0
1242
msgFail      db 'device not found',13,10,0
1243
msgAttchIRQ  db 'IRQ line not supported', 13,10, 0
1244
msgInvIRQ    db 'IRQ line not assigned or invalid', 13,10, 0
1245
msgPlay      db 'start play', 13,10,0
1246
msgStop      db 'stop play',  13,10,0
1247
;msgIRQ       db 'AC97 IRQ', 13,10,0
1248
;msgInitCtrl  db 'init controller',13,10,0
1249
;msgInitCodec db 'init codec',13,10,0
1250
msgPrimBuff  db 'create primary buffer ...',0
1251
msgDone      db 'done',13,10,0
1252
msgRemap     db 'Remap IRQ',13,10,0
1253
;msgReg       db 'set service handler',13,10,0
1254
;msgOk        db 'service installed',13,10,0
1255
msgCold      db 'cold reset',13,10,0
1256
;msgWarm      db 'warm reset',13,10,0
1257
;msgWRFail    db 'warm reset failed',13,10,0
1258
msgCRFail    db 'cold reset failed',13,10,0
1259
msgCFail     db 'codec not ready',13,10,0
1260
msgCInvalid  db 'codec is not valid',13,10,0 ;Asper
1261
msgResetOk   db 'reset complete',13,10,0
1262
msgStatus    db 'global status   ',0
1263
msgControl   db 'global control  ',0
1264
msgPciCmd    db 'PCI command     ',0
1265
msgPciStat   db 'PCI status      ',0
1266
msgCtrlIsaIo db 'controller io base   ',0
1267
;msgMixIsaIo  db 'codec io base        ',0
1268
;msgCtrlMMIo  db 'controller mmio base ',0
1269
;msgMixMMIo   db 'codec mmio base      ',0
1270
;msgIrqMap    db 'AC97 irq map as      ',0
1271
 
1272
 
1273
section '.data' data readable writable align 16
1274
 
1275
pcmout_bdl	 rq 32
1276
buff_list	 rd 32
1277
 
1278
codec CODEC
1279
ctrl AC_CNTRL
1280
 
1281
chip_type	 rb 1