Subversion Repositories Kolibri OS

Rev

Rev 188 | Go to most recent revision | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 188 Rev 198
1
format MS COFF
1
format MS COFF
2
 
2
 
3
 
3
 
4
include 'proc32.inc'
4
include 'proc32.inc'
5
 
5
 
6
DEBUG	    equ 1
6
DEBUG	    equ 1
7
 
7
 
8
REMAP_IRQ   equ 0
8
REMAP_IRQ   equ 0
9
 
9
 
10
;irq 0,1,2,8,12,13 íåäîñòóïíû
10
;irq 0,1,2,8,12,13 íåäîñòóïíû
11
;               FEDCBA9876543210
11
;               FEDCBA9876543210
12
VALID_IRQ   equ 1100111011111000b
12
VALID_IRQ   equ 1100111011111000b
13
ATTCH_IRQ   equ 0000111010101000b
13
ATTCH_IRQ   equ 0000111010101000b
14
 
14
 
15
IRQ_LINE    equ 0
15
IRQ_LINE    equ 0
16
 
16
 
17
CPU_FREQ    equ  2600d
17
CPU_FREQ    equ  2600d
18
 
18
 
19
BIT0  EQU 0x00000001
19
BIT0  EQU 0x00000001
20
BIT1  EQU 0x00000002
20
BIT1  EQU 0x00000002
21
BIT2  EQU 0x00000004
21
BIT2  EQU 0x00000004
22
BIT3  EQU 0x00000008
22
BIT3  EQU 0x00000008
23
BIT4  EQU 0x00000010
23
BIT4  EQU 0x00000010
24
BIT5  EQU 0x00000020
24
BIT5  EQU 0x00000020
25
BIT6  EQU 0x00000040
25
BIT6  EQU 0x00000040
26
BIT7  EQU 0x00000080
26
BIT7  EQU 0x00000080
27
BIT8  EQU 0x00000100
27
BIT8  EQU 0x00000100
28
BIT9  EQU 0x00000200
28
BIT9  EQU 0x00000200
29
BIT10 EQU 0x00000400
29
BIT10 EQU 0x00000400
30
BIT11 EQU 0x00000800
30
BIT11 EQU 0x00000800
31
BIT12 EQU 0x00001000
31
BIT12 EQU 0x00001000
32
BIT13 EQU 0x00002000
32
BIT13 EQU 0x00002000
33
BIT14 EQU 0x00004000
33
BIT14 EQU 0x00004000
34
BIT15 EQU 0x00008000
34
BIT15 EQU 0x00008000
35
BIT16 EQU 0x00010000
35
BIT16 EQU 0x00010000
36
BIT17 EQU 0x00020000
36
BIT17 EQU 0x00020000
37
BIT18 EQU 0x00040000
37
BIT18 EQU 0x00040000
38
BIT19 EQU 0x00080000
38
BIT19 EQU 0x00080000
39
BIT20 EQU 0x00100000
39
BIT20 EQU 0x00100000
40
BIT21 EQU 0x00200000
40
BIT21 EQU 0x00200000
41
BIT22 EQU 0x00400000
41
BIT22 EQU 0x00400000
42
BIT23 EQU 0x00800000
42
BIT23 EQU 0x00800000
43
BIT24 EQU 0x00100000
43
BIT24 EQU 0x00100000
44
BIT25 EQU 0x02000000
44
BIT25 EQU 0x02000000
45
BIT26 EQU 0x04000000
45
BIT26 EQU 0x04000000
46
BIT27 EQU 0x08000000
46
BIT27 EQU 0x08000000
47
BIT28 EQU 0x10000000
47
BIT28 EQU 0x10000000
48
BIT29 EQU 0x20000000
48
BIT29 EQU 0x20000000
49
BIT30 EQU 0x40000000
49
BIT30 EQU 0x40000000
50
BIT31 EQU 0x80000000
50
BIT31 EQU 0x80000000
51
 
51
 
52
VID_INTEL	  equ 0x8086
52
VID_INTEL	  equ 0x8086
53
VID_NVIDIA        equ 0x10DE
53
VID_NVIDIA        equ 0x10DE
54
 
54
 
55
CTRL_ICH	  equ 0x2415
55
CTRL_ICH	  equ 0x2415
56
CTRL_ICH0	  equ 0x2425
56
CTRL_ICH0	  equ 0x2425
57
CTRL_ICH2	  equ 0x2435
57
CTRL_ICH2	  equ 0x2435
58
CTRL_ICH3	  equ 0x2445
58
CTRL_ICH3	  equ 0x2445
59
CTRL_ICH4	  equ 0x24C5
59
CTRL_ICH4	  equ 0x24C5
60
CTRL_ICH5	  equ 0x24D5
60
CTRL_ICH5	  equ 0x24D5
61
CTRL_ICH6	  equ 0x266E
61
CTRL_ICH6	  equ 0x266E
62
CTRL_ICH7	  equ 0x27DE
62
CTRL_ICH7	  equ 0x27DE
63
 
63
 
64
CTRL_NFORCE       equ 0x01B1
64
CTRL_NFORCE       equ 0x01B1
65
CTRL_NFORCE2      equ 0x006A
65
CTRL_NFORCE2      equ 0x006A
66
CTRL_NFORCE3      equ 0x00DA
66
CTRL_NFORCE3      equ 0x00DA
67
 
67
CTRL_MCP04        equ 0x003A
-
 
68
CTRL_CK804        equ 0x0059
-
 
69
CTRL_CK8          equ 0x008A
-
 
70
CTRL_CK8S         equ 0x00EA
-
 
71
CTRL_MCP51        equ 0x026B
-
 
72
 
68
 
73
 
69
PCM_OUT_BDL	  equ  0x10	 ; PCM out buffer descriptors list
74
PCM_OUT_BDL	  equ  0x10	 ; PCM out buffer descriptors list
70
PCM_OUT_CR_REG	  equ  0x1b	 ; PCM out Control Register
75
PCM_OUT_CR_REG	  equ  0x1b	 ; PCM out Control Register
71
PCM_OUT_LVI_REG   equ  0x15	 ; PCM last valid index
76
PCM_OUT_LVI_REG   equ  0x15	 ; PCM last valid index
72
PCM_OUT_SR_REG	  equ  0x16	 ; PCM out Status register
77
PCM_OUT_SR_REG	  equ  0x16	 ; PCM out Status register
73
PCM_OUT_PIV_REG   equ  0x1a
78
PCM_OUT_PIV_REG   equ  0x1a
74
PCM_OUT_CIV_REG   equ  0x14	 ; PCM out current index
79
PCM_OUT_CIV_REG   equ  0x14	 ; PCM out current index
75
 
80
 
76
PCM_IN_CR_REG	  equ  0x0b	 ; PCM in Control Register
81
PCM_IN_CR_REG	  equ  0x0b	 ; PCM in Control Register
77
MC_IN_CR_REG	  equ  0x2b	 ; MIC in Control Register
82
MC_IN_CR_REG	  equ  0x2b	 ; MIC in Control Register
78
RR		  equ  BIT1	 ; reset registers.  Nukes all regs
83
RR		  equ  BIT1	 ; reset registers.  Nukes all regs
79
 
84
 
80
CODEC_MASTER_VOL_REG		equ	0x02
85
CODEC_MASTER_VOL_REG		equ	0x02
81
CODEC_AUX_VOL			equ	0x04	;
86
CODEC_AUX_VOL			equ	0x04	;
82
CODEC_PCM_OUT_REG		equ	18h	; PCM output volume
87
CODEC_PCM_OUT_REG		equ	18h	; PCM output volume
83
CODEC_EXT_AUDIO_REG		equ	28h	; extended audio
88
CODEC_EXT_AUDIO_REG		equ	28h	; extended audio
84
CODEC_EXT_AUDIO_CTRL_REG	equ	2ah	; extended audio control
89
CODEC_EXT_AUDIO_CTRL_REG	equ	2ah	; extended audio control
85
CODEC_PCM_FRONT_DACRATE_REG	equ	2ch	; PCM out sample rate
90
CODEC_PCM_FRONT_DACRATE_REG	equ	2ch	; PCM out sample rate
86
CODEC_PCM_SURND_DACRATE_REG	equ	2eh	; surround sound sample rate
91
CODEC_PCM_SURND_DACRATE_REG	equ	2eh	; surround sound sample rate
87
CODEC_PCM_LFE_DACRATE_REG	equ	30h	; LFE sample rate
92
CODEC_PCM_LFE_DACRATE_REG	equ	30h	; LFE sample rate
88
 
93
 
89
GLOB_CTRL      equ  0x2C	;   Global Control
94
GLOB_CTRL      equ  0x2C	;   Global Control
90
CTRL_STAT	equ  0x30	 ;   Global Status
95
CTRL_STAT	equ  0x30	 ;   Global Status
91
CTRL_CAS	equ  0x34	 ;   Codec Access Semiphore
96
CTRL_CAS	equ  0x34	 ;   Codec Access Semiphore
92
 
97
 
93
CAS_FLAG	equ  0x01	 ;   Codec Access Semiphore Bit
98
CAS_FLAG	equ  0x01	 ;   Codec Access Semiphore Bit
94
 
99
 
95
CTRL_ST_CREADY	equ  BIT8+BIT9+BIT28 ;   Primary Codec Ready
100
CTRL_ST_CREADY	equ  BIT8+BIT9+BIT28 ;   Primary Codec Ready
96
 
101
 
97
CTRL_ST_RCS	equ  0x00008000  ;   Read Completion Status
102
CTRL_ST_RCS	equ  0x00008000  ;   Read Completion Status
98
 
103
 
99
CTRL_CNT_CRIE	equ  BIT4+BIT5+BIT6  ;   Codecs Resume Interrupt Enable
104
CTRL_CNT_CRIE	equ  BIT4+BIT5+BIT6  ;   Codecs Resume Interrupt Enable
100
CTRL_CNT_AC_OFF equ  0x00000008  ;   ACLINK Off
105
CTRL_CNT_AC_OFF equ  0x00000008  ;   ACLINK Off
101
CTRL_CNT_WARM	equ  0x00000004  ;   AC97 Warm Reset
106
CTRL_CNT_WARM	equ  0x00000004  ;   AC97 Warm Reset
102
CTRL_CNT_COLD	equ  0x00000002  ;   AC97 Cold Reset
107
CTRL_CNT_COLD	equ  0x00000002  ;   AC97 Cold Reset
103
CTRL_CNT_GIE	equ  0x00000001  ;   GPI Interrupt Enable
108
CTRL_CNT_GIE	equ  0x00000001  ;   GPI Interrupt Enable
104
 
109
 
105
CODEC_REG_POWERDOWN   equ 0x26
110
CODEC_REG_POWERDOWN   equ 0x26
106
CODEC_REG_ST	      equ 0x26
111
CODEC_REG_ST	      equ 0x26
107
 
112
 
108
DEV_PLAY	      equ  1
113
DEV_PLAY	      equ  1
109
DEV_STOP	      equ  2
114
DEV_STOP	      equ  2
110
DEV_CALLBACK	      equ  3
115
DEV_CALLBACK	      equ  3
111
DEV_SET_BUFF	      equ  4
116
DEV_SET_BUFF	      equ  4
112
DEV_NOTIFY	      equ  5
117
DEV_NOTIFY	      equ  5
113
DEV_SET_MASTERVOL     equ  6
118
DEV_SET_MASTERVOL     equ  6
114
DEV_GET_MASTERVOL     equ  7
119
DEV_GET_MASTERVOL     equ  7
115
DEV_GET_INFO	      equ  8
120
DEV_GET_INFO	      equ  8
116
 
121
 
117
struc AC_CNTRL		    ;AC controller base class
122
struc AC_CNTRL		    ;AC controller base class
118
{ .bus                dd ?
123
{ .bus                dd ?
119
  .devfn              dd ?
124
  .devfn              dd ?
120
 
125
 
121
  .vendor             dd ?
126
  .vendor             dd ?
122
  .dev_id             dd ?
127
  .dev_id             dd ?
123
  .pci_cmd            dd ?
128
  .pci_cmd            dd ?
124
  .pci_stat           dd ?
129
  .pci_stat           dd ?
125
 
130
 
126
  .codec_io_base      dd ?
131
  .codec_io_base      dd ?
127
  .codec_mem_base     dd ?
132
  .codec_mem_base     dd ?
128
 
133
 
129
  .ctrl_io_base       dd ?
134
  .ctrl_io_base       dd ?
130
  .ctrl_mem_base      dd ?
135
  .ctrl_mem_base      dd ?
131
  .cfg_reg            dd ?
136
  .cfg_reg            dd ?
132
  .int_line           dd ?
137
  .int_line           dd ?
133
 
138
 
134
  .vendor_ids         dd ?    ;vendor id string
139
  .vendor_ids         dd ?    ;vendor id string
135
  .ctrl_ids           dd ?    ;hub id string
140
  .ctrl_ids           dd ?    ;hub id string
136
 
141
 
137
  .buffer             dd ?
142
  .buffer             dd ?
138
 
143
 
139
  .notify_pos         dd ?
144
  .notify_pos         dd ?
140
  .notify_task        dd ?
145
  .notify_task        dd ?
141
 
146
 
142
  .lvi_reg            dd ?
147
  .lvi_reg            dd ?
143
  .ctrl_setup         dd ?
148
  .ctrl_setup         dd ?
144
  .user_callback      dd ?
149
  .user_callback      dd ?
145
  .codec_read16       dd ?
150
  .codec_read16       dd ?
146
  .codec_write16      dd ?
151
  .codec_write16      dd ?
147
 
152
 
148
  .ctrl_read8         dd ?
153
  .ctrl_read8         dd ?
149
  .ctrl_read16        dd ?
154
  .ctrl_read16        dd ?
150
  .ctrl_read32        dd ?
155
  .ctrl_read32        dd ?
151
 
156
 
152
  .ctrl_write8        dd ?
157
  .ctrl_write8        dd ?
153
  .ctrl_write16       dd ?
158
  .ctrl_write16       dd ?
154
  .ctrl_write32       dd ?
159
  .ctrl_write32       dd ?
155
}
160
}
156
 
161
 
157
struc CODEC		   ;Audio Chip base class
162
struc CODEC		   ;Audio Chip base class
158
{
163
{
159
  .chip_id            dd ?
164
  .chip_id            dd ?
160
  .flags              dd ?
165
  .flags              dd ?
161
  .status             dd ?
166
  .status             dd ?
162
 
167
 
163
  .ac_vendor_ids      dd ?    ;ac vendor id string
168
  .ac_vendor_ids      dd ?    ;ac vendor id string
164
  .chip_ids           dd ?    ;chip model string
169
  .chip_ids           dd ?    ;chip model string
165
 
170
 
166
  .shadow_flag        dd ?
171
  .shadow_flag        dd ?
167
                      dd ?
172
                      dd ?
168
 
173
 
169
  .regs               dw ?     ; codec registers
174
  .regs               dw ?     ; codec registers
170
  .reg_master_vol     dw ?     ;0x02
175
  .reg_master_vol     dw ?     ;0x02
171
  .reg_aux_out_vol    dw ?     ;0x04
176
  .reg_aux_out_vol    dw ?     ;0x04
172
  .reg_mone_vol       dw ?     ;0x06
177
  .reg_mone_vol       dw ?     ;0x06
173
  .reg_master_tone    dw ?     ;0x08
178
  .reg_master_tone    dw ?     ;0x08
174
  .reg_beep_vol       dw ?     ;0x0A
179
  .reg_beep_vol       dw ?     ;0x0A
175
  .reg_phone_vol      dw ?     ;0x0C
180
  .reg_phone_vol      dw ?     ;0x0C
176
  .reg_mic_vol        dw ?     ;0x0E
181
  .reg_mic_vol        dw ?     ;0x0E
177
  .reg_line_in_vol    dw ?     ;0x10
182
  .reg_line_in_vol    dw ?     ;0x10
178
  .reg_cd_vol         dw ?     ;0x12
183
  .reg_cd_vol         dw ?     ;0x12
179
  .reg_video_vol      dw ?     ;0x14
184
  .reg_video_vol      dw ?     ;0x14
180
  .reg_aux_in_vol     dw ?     ;0x16
185
  .reg_aux_in_vol     dw ?     ;0x16
181
  .reg_pcm_out_vol    dw ?     ;0x18
186
  .reg_pcm_out_vol    dw ?     ;0x18
182
  .reg_rec_select     dw ?     ;0x1A
187
  .reg_rec_select     dw ?     ;0x1A
183
  .reg_rec_gain       dw ?     ;0x1C
188
  .reg_rec_gain       dw ?     ;0x1C
184
  .reg_rec_gain_mic   dw ?     ;0x1E
189
  .reg_rec_gain_mic   dw ?     ;0x1E
185
  .reg_gen            dw ?     ;0x20
190
  .reg_gen            dw ?     ;0x20
186
  .reg_3d_ctrl        dw ?     ;0X22
191
  .reg_3d_ctrl        dw ?     ;0X22
187
  .reg_page           dw ?     ;0X24
192
  .reg_page           dw ?     ;0X24
188
  .reg_powerdown      dw ?     ;0x26
193
  .reg_powerdown      dw ?     ;0x26
189
  .reg_ext_audio      dw ?     ;0x28
194
  .reg_ext_audio      dw ?     ;0x28
190
  .reg_ext_st         dw ?     ;0x2a
195
  .reg_ext_st         dw ?     ;0x2a
191
  .reg_pcm_front_rate dw ?     ;0x2c
196
  .reg_pcm_front_rate dw ?     ;0x2c
192
  .reg_pcm_surr_rate  dw ?     ;0x2e
197
  .reg_pcm_surr_rate  dw ?     ;0x2e
193
  .reg_lfe_rate       dw ?     ;0x30
198
  .reg_lfe_rate       dw ?     ;0x30
194
  .reg_pcm_in_rate    dw ?     ;0x32
199
  .reg_pcm_in_rate    dw ?     ;0x32
195
                      dw ?     ;0x34
200
                      dw ?     ;0x34
196
  .reg_cent_lfe_vol   dw ?     ;0x36
201
  .reg_cent_lfe_vol   dw ?     ;0x36
197
  .reg_surr_vol       dw ?     ;0x38
202
  .reg_surr_vol       dw ?     ;0x38
198
  .reg_spdif_ctrl     dw ?     ;0x3A
203
  .reg_spdif_ctrl     dw ?     ;0x3A
199
                      dw ?     ;0x3C
204
                      dw ?     ;0x3C
200
                      dw ?     ;0x3E
205
                      dw ?     ;0x3E
201
                      dw ?     ;0x40
206
                      dw ?     ;0x40
202
                      dw ?     ;0x42
207
                      dw ?     ;0x42
203
                      dw ?     ;0x44
208
                      dw ?     ;0x44
204
                      dw ?     ;0x46
209
                      dw ?     ;0x46
205
                      dw ?     ;0x48
210
                      dw ?     ;0x48
206
                      dw ?     ;0x4A
211
                      dw ?     ;0x4A
207
                      dw ?     ;0x4C
212
                      dw ?     ;0x4C
208
                      dw ?     ;0x4E
213
                      dw ?     ;0x4E
209
                      dw ?     ;0x50
214
                      dw ?     ;0x50
210
                      dw ?     ;0x52
215
                      dw ?     ;0x52
211
                      dw ?     ;0x54
216
                      dw ?     ;0x54
212
                      dw ?     ;0x56
217
                      dw ?     ;0x56
213
                      dw ?     ;0x58
218
                      dw ?     ;0x58
214
                      dw ?     ;0x5A
219
                      dw ?     ;0x5A
215
                      dw ?     ;0x5C
220
                      dw ?     ;0x5C
216
                      dw ?     ;0x5E
221
                      dw ?     ;0x5E
217
  .reg_page_0         dw ?     ;0x60
222
  .reg_page_0         dw ?     ;0x60
218
  .reg_page_1         dw ?     ;0x62
223
  .reg_page_1         dw ?     ;0x62
219
  .reg_page_2         dw ?     ;0x64
224
  .reg_page_2         dw ?     ;0x64
220
  .reg_page_3         dw ?     ;0x66
225
  .reg_page_3         dw ?     ;0x66
221
  .reg_page_4         dw ?     ;0x68
226
  .reg_page_4         dw ?     ;0x68
222
  .reg_page_5         dw ?     ;0x6A
227
  .reg_page_5         dw ?     ;0x6A
223
  .reg_page_6         dw ?     ;0x6C
228
  .reg_page_6         dw ?     ;0x6C
224
  .reg_page_7         dw ?     ;0x6E
229
  .reg_page_7         dw ?     ;0x6E
225
                      dw ?     ;0x70
230
                      dw ?     ;0x70
226
                      dw ?     ;0x72
231
                      dw ?     ;0x72
227
                      dw ?     ;0x74
232
                      dw ?     ;0x74
228
                      dw ?     ;0x76
233
                      dw ?     ;0x76
229
                      dw ?     ;0x78
234
                      dw ?     ;0x78
230
                      dw ?     ;0x7A
235
                      dw ?     ;0x7A
231
  .reg_vendor_id_1    dw ?     ;0x7C
236
  .reg_vendor_id_1    dw ?     ;0x7C
232
  .reg_vendor_id_2    dw ?     ;0x7E
237
  .reg_vendor_id_2    dw ?     ;0x7E
233
 
238
 
234
 
239
 
235
  .reset              dd ?    ;virual
240
  .reset              dd ?    ;virual
236
  .set_master_vol     dd ?
241
  .set_master_vol     dd ?
237
}
242
}
238
 
243
 
239
struc CTRL_INFO
244
struc CTRL_INFO
240
{   .pci_cmd	    dd	?
245
{   .pci_cmd	    dd	?
241
    .irq	    dd	?
246
    .irq	    dd	?
242
    .glob_cntrl     dd	?
247
    .glob_cntrl     dd	?
243
    .glob_sta	    dd	?
248
    .glob_sta	    dd	?
244
    .codec_io_base  dd	?
249
    .codec_io_base  dd	?
245
    .ctrl_io_base   dd	?
250
    .ctrl_io_base   dd	?
246
    .codec_mem_base dd	?
251
    .codec_mem_base dd	?
247
    .ctrl_mem_base  dd	?
252
    .ctrl_mem_base  dd	?
248
    .codec_id       dd  ?
253
    .codec_id       dd  ?
249
}
254
}
250
 
255
 
251
struc IOCTL
256
struc IOCTL
252
{  .handle           dd ?
257
{  .handle           dd ?
253
   .io_code          dd ?
258
   .io_code          dd ?
254
   .input            dd ?
259
   .input            dd ?
255
   .inp_size         dd ?
260
   .inp_size         dd ?
256
   .output           dd ?
261
   .output           dd ?
257
   .out_size         dd ?
262
   .out_size         dd ?
258
}
263
}
259
 
264
 
260
virtual at 0
265
virtual at 0
261
  IOCTL IOCTL
266
  IOCTL IOCTL
262
end virtual
267
end virtual
263
 
268
 
264
EVENT_NOTIFY	      equ 0x00000200
269
EVENT_NOTIFY	      equ 0x00000200
265
 
270
 
266
OS_BASE 	      equ 0;  0x80400000
271
OS_BASE 	      equ 0;  0x80400000
267
new_app_base	      equ 0x60400000;   0x01000000
272
new_app_base	      equ 0x60400000;   0x01000000
268
PROC_BASE	      equ OS_BASE+0x0080000
273
PROC_BASE	      equ OS_BASE+0x0080000
269
 
274
 
270
public START
275
public START
271
public STOP
276
public STOP
272
public service_proc
277
public service_proc
273
 
278
 
274
extrn AttachIntHandler
279
extrn AttachIntHandler
275
extrn SysMsgBoardStr
280
extrn SysMsgBoardStr
276
extrn PciApi
281
extrn PciApi
277
extrn PciRead32
282
extrn PciRead32
278
extrn PciRead8
283
extrn PciRead8
279
extrn PciWrite8
284
extrn PciWrite8
280
extrn AllocKernelSpace
285
extrn AllocKernelSpace
281
extrn MapPage
286
extrn MapPage
282
extrn RegService
287
extrn RegService
283
extrn KernelAlloc
288
extrn KernelAlloc
284
extrn GetPgAddr
289
extrn GetPgAddr
285
extrn GetCurrentTask
290
extrn GetCurrentTask
286
 
291
 
287
section '.flat' code readable align 16
292
section '.flat' code readable align 16
288
 
293
 
289
START:
294
START:
290
     if DEBUG
295
     if DEBUG
291
	   mov esi, msgInit
296
	   mov esi, msgInit
292
           call SysMsgBoardStr
297
           call SysMsgBoardStr
293
     end if
298
     end if
294
 
299
 
295
	   call detect_controller
300
	   call detect_controller
296
	   test eax, eax
301
	   test eax, eax
297
           jz .fail
302
           jz .fail
298
 
303
 
299
     if DEBUG
304
     if DEBUG
300
	   mov esi,[ctrl.vendor_ids]
305
	   mov esi,[ctrl.vendor_ids]
301
           call SysMsgBoardStr
306
           call SysMsgBoardStr
302
	   mov	  esi, [ctrl.ctrl_ids]
307
	   mov	  esi, [ctrl.ctrl_ids]
303
           call SysMsgBoardStr
308
           call SysMsgBoardStr
304
 
309
 
305
     end if
310
     end if
306
 
311
 
307
           call init_controller
312
           call init_controller
308
           test eax, eax
313
           test eax, eax
309
           jz .fail
314
           jz .fail
310
 
315
 
311
     if DEBUG
316
     if DEBUG
312
           mov esi, msgInitCodec
317
           mov esi, msgInitCodec
313
           call SysMsgBoardStr
318
           call SysMsgBoardStr
314
     end if
319
     end if
315
 
320
 
316
           call init_codec
321
           call init_codec
317
           test eax, eax
322
           test eax, eax
318
           jz .fail
323
           jz .fail
319
 
324
 
320
     if DEBUG
325
     if DEBUG
321
	   mov esi, [codec.ac_vendor_ids]
326
	   mov esi, [codec.ac_vendor_ids]
322
           call SysMsgBoardStr
327
           call SysMsgBoardStr
323
 
328
 
324
	   mov esi, [codec.chip_ids]
329
	   mov esi, [codec.chip_ids]
325
           call SysMsgBoardStr
330
           call SysMsgBoardStr
326
     end if
331
     end if
327
 
332
 
328
           call reset_controller
333
           call reset_controller
329
           call setup_codec
334
           call setup_codec
330
 
335
 
331
           mov esi, msgPrimBuff
336
           mov esi, msgPrimBuff
332
           call SysMsgBoardStr
337
           call SysMsgBoardStr
333
 
338
 
334
           call create_primary_buff
339
           call create_primary_buff
335
 
340
 
336
;     if REMAP_IRQ
341
;     if REMAP_IRQ
337
 
342
 
338
;           call get_LPC_bus
343
;           call get_LPC_bus
339
;           cmp eax, -1
344
;           cmp eax, -1
340
;           jz .fail
345
;           jz .fail
341
 
346
 
342
;           mov [lpc_bus], 0  ;eax
347
;           mov [lpc_bus], 0  ;eax
343
;           call remap_irq
348
;           call remap_irq
344
;     end if
349
;     end if
345
 
350
 
346
           mov eax, VALID_IRQ
351
           mov eax, VALID_IRQ
347
           mov ebx, [ctrl.int_line]
352
           mov ebx, [ctrl.int_line]
348
           mov esi, msgInvIRQ
353
           mov esi, msgInvIRQ
349
           bt eax, ebx
354
           bt eax, ebx
350
           jnc .fail
355
           jnc .fail
351
           mov eax, ATTCH_IRQ
356
           mov eax, ATTCH_IRQ
352
           mov esi, msgAttchIRQ
357
           mov esi, msgAttchIRQ
353
           bt eax, ebx
358
           bt eax, ebx
354
           jnc .fail
359
           jnc .fail
355
 
360
 
356
           stdcall AttachIntHandler, ebx, ac97_irq
361
           stdcall AttachIntHandler, ebx, ac97_irq
357
           stdcall RegService, sz_sound_srv, service_proc
362
           stdcall RegService, sz_sound_srv, service_proc
358
	   ret
363
	   ret
359
.fail:
364
.fail:
360
     if DEBUG
365
     if DEBUG
361
	   mov esi, msgFail
366
	   mov esi, msgFail
362
           call SysMsgBoardStr
367
           call SysMsgBoardStr
363
     end if
368
     end if
364
	   xor eax, eax
369
	   xor eax, eax
365
STOP:
370
STOP:
366
           ret
371
           ret
367
 
372
 
368
handle     equ  IOCTL.handle
373
handle     equ  IOCTL.handle
369
io_code    equ  IOCTL.io_code
374
io_code    equ  IOCTL.io_code
370
input      equ  IOCTL.input
375
input      equ  IOCTL.input
371
inp_size   equ  IOCTL.inp_size
376
inp_size   equ  IOCTL.inp_size
372
output     equ  IOCTL.output
377
output     equ  IOCTL.output
373
out_size   equ  IOCTL.out_size
378
out_size   equ  IOCTL.out_size
374
 
379
 
375
align 4
380
align 4
376
proc service_proc stdcall, ioctl:dword
381
proc service_proc stdcall, ioctl:dword
377
 
382
 
378
           mov edi, [ioctl]
383
           mov edi, [ioctl]
379
           mov eax, [edi+io_code]
384
           mov eax, [edi+io_code]
380
	   cmp eax, DEV_PLAY
385
	   cmp eax, DEV_PLAY
381
	   jne @F
386
	   jne @F
382
     if DEBUG
387
     if DEBUG
383
	   mov esi, msgPlay
388
	   mov esi, msgPlay
384
           call SysMsgBoardStr
389
           call SysMsgBoardStr
385
     end if
390
     end if
386
	   call play
391
	   call play
387
	   ret
392
	   ret
388
@@:
393
@@:
389
	   cmp eax, DEV_STOP
394
	   cmp eax, DEV_STOP
390
	   jne @F
395
	   jne @F
391
     if DEBUG
396
     if DEBUG
392
	   mov esi, msgStop
397
	   mov esi, msgStop
393
           call SysMsgBoardStr
398
           call SysMsgBoardStr
394
     end if
399
     end if
395
	   call stop
400
	   call stop
396
	   ret
401
	   ret
397
@@:
402
@@:
398
	   cmp eax, DEV_CALLBACK
403
	   cmp eax, DEV_CALLBACK
399
	   jne @F
404
	   jne @F
400
           mov ebx, [edi+input]
405
           mov ebx, [edi+input]
401
           stdcall set_callback, [ebx]
406
           stdcall set_callback, [ebx]
402
	   ret
407
	   ret
403
@@:
408
@@:
404
	   cmp eax, DEV_SET_MASTERVOL
409
	   cmp eax, DEV_SET_MASTERVOL
405
	   jne @F
410
	   jne @F
406
           mov ebx, [edi+input]
411
           mov ebx, [edi+input]
407
           stdcall set_master_vol, [ebx]
412
           stdcall set_master_vol, [ebx]
408
	   ret
413
	   ret
409
@@:
414
@@:
410
	   cmp eax, DEV_GET_MASTERVOL
415
	   cmp eax, DEV_GET_MASTERVOL
411
	   jne @F
416
	   jne @F
412
           mov ebx, [edi+output]
417
           mov ebx, [edi+output]
413
           test ebx, ebx
418
           test ebx, ebx
414
           jz .fail
419
           jz .fail
415
 
420
 
416
           stdcall get_master_vol, ebx
421
           stdcall get_master_vol, ebx
417
	   ret
422
	   ret
418
@@:
423
@@:
419
	   cmp eax, DEV_GET_INFO
424
	   cmp eax, DEV_GET_INFO
420
	   jne @F
425
	   jne @F
421
           mov ebx, [edi+output]
426
           mov ebx, [edi+output]
422
	   stdcall get_dev_info, ebx
427
	   stdcall get_dev_info, ebx
423
	   ret
428
	   ret
424
@@:
429
@@:
425
.fail:
430
.fail:
426
	   xor eax, eax
431
	   xor eax, eax
427
	   ret
432
	   ret
428
endp
433
endp
429
 
434
 
430
restore   handle
435
restore   handle
431
restore   io_code
436
restore   io_code
432
restore   input
437
restore   input
433
restore   inp_size
438
restore   inp_size
434
restore   output
439
restore   output
435
restore   out_size
440
restore   out_size
436
 
441
 
437
 
442
 
438
align 4
443
align 4
439
proc remap_irq                         ;for Intel chipsets ONLY !!!
444
proc remap_irq                         ;for Intel chipsets ONLY !!!
440
	   mov eax, VALID_IRQ
445
	   mov eax, VALID_IRQ
441
	   bt eax, IRQ_LINE
446
	   bt eax, IRQ_LINE
442
	   jnc .exit
447
	   jnc .exit
443
 
448
 
444
	   mov edx, 0x4D0
449
	   mov edx, 0x4D0
445
	   in ax,dx
450
	   in ax,dx
446
	   bts ax, IRQ_LINE
451
	   bts ax, IRQ_LINE
447
	   out dx, aX
452
	   out dx, aX
448
 
453
 
449
           stdcall PciWrite8, dword 0, dword 0xF8, dword 0x61, dword IRQ_LINE
454
           stdcall PciWrite8, dword 0, dword 0xF8, dword 0x61, dword IRQ_LINE
450
	   mov [ctrl.int_line], IRQ_LINE
455
	   mov [ctrl.int_line], IRQ_LINE
451
 
456
 
452
.exit:
457
.exit:
453
	   ret
458
	   ret
454
endp
459
endp
455
 
460
 
456
align 4
461
align 4
457
proc ac97_irq
462
proc ac97_irq
458
 
463
 
459
;     if DEBUG
464
;     if DEBUG
460
;           mov esi, msgIRQ
465
;           mov esi, msgIRQ
461
;           call SysMsgBoardStr
466
;           call SysMsgBoardStr
462
;     end if
467
;     end if
463
 
468
 
464
	   mov edx, PCM_OUT_CR_REG
469
	   mov edx, PCM_OUT_CR_REG
465
	   mov al, 0x14
470
	   mov al, 0x14
466
	   call [ctrl.ctrl_write8]
471
	   call [ctrl.ctrl_write8]
467
 
472
 
468
	   mov ax, 0x1c
473
	   mov ax, 0x1c
469
	   mov edx, PCM_OUT_SR_REG
474
	   mov edx, PCM_OUT_SR_REG
470
	   call [ctrl.ctrl_write16]
475
	   call [ctrl.ctrl_write16]
471
 
476
 
472
	   mov edx, PCM_OUT_CIV_REG
477
	   mov edx, PCM_OUT_CIV_REG
473
	   call [ctrl.ctrl_read8]
478
	   call [ctrl.ctrl_read8]
474
 
479
 
475
	   and eax, 0x1F
480
	   and eax, 0x1F
476
	   cmp eax, [civ_val]
481
	   cmp eax, [civ_val]
477
	   je .skip
482
	   je .skip
478
 
483
 
479
	   mov [civ_val], eax
484
	   mov [civ_val], eax
480
	   dec eax
485
	   dec eax
481
	   and eax, 0x1F
486
	   and eax, 0x1F
482
	   mov [ctrl.lvi_reg], eax
487
	   mov [ctrl.lvi_reg], eax
483
 
488
 
484
	   mov edx, PCM_OUT_LVI_REG
489
	   mov edx, PCM_OUT_LVI_REG
485
	   call [ctrl.ctrl_write8]
490
	   call [ctrl.ctrl_write8]
486
 
491
 
487
	   mov edx, PCM_OUT_CR_REG
492
	   mov edx, PCM_OUT_CR_REG
488
	   mov ax, 0x1D
493
	   mov ax, 0x1D
489
	   call [ctrl.ctrl_write8]
494
	   call [ctrl.ctrl_write8]
490
 
495
 
491
	   mov eax, [civ_val]
496
	   mov eax, [civ_val]
492
	   add eax, 2
497
	   add eax, 2
493
	   and eax, 31
498
	   and eax, 31
494
	   mov ebx, dword [buff_list+eax*4]
499
	   mov ebx, dword [buff_list+eax*4]
495
 
500
 
496
	   cmp [ctrl.user_callback], 0
501
	   cmp [ctrl.user_callback], 0
497
	   je @f
502
	   je @f
498
 
503
 
499
	   stdcall [ctrl.user_callback], ebx
504
	   stdcall [ctrl.user_callback], ebx
500
@@:
505
@@:
501
	   ret
506
	   ret
502
 
507
 
503
.skip:
508
.skip:
504
	   mov edx, PCM_OUT_CR_REG
509
	   mov edx, PCM_OUT_CR_REG
505
	   mov ax, 0x1D
510
	   mov ax, 0x1D
506
	   call [ctrl.ctrl_write8]
511
	   call [ctrl.ctrl_write8]
507
	   ret
512
	   ret
508
endp
513
endp
509
 
514
 
510
align 4
515
align 4
511
proc create_primary_buff
516
proc create_primary_buff
512
 
517
 
513
           stdcall KernelAlloc, 0x10000
518
           stdcall KernelAlloc, 0x10000
514
	   mov [ctrl.buffer], eax
519
	   mov [ctrl.buffer], eax
515
 
520
 
516
	   mov edi, eax
521
	   mov edi, eax
517
	   mov ecx, 0x10000/4
522
	   mov ecx, 0x10000/4
518
	   xor eax, eax
523
	   xor eax, eax
519
           cld
524
           cld
520
	   rep stosd
525
	   rep stosd
521
 
526
 
522
           stdcall GetPgAddr, [ctrl.buffer]
527
           stdcall GetPgAddr, [ctrl.buffer]
523
 
528
 
524
	   mov ebx, 0xC0002000
529
	   mov ebx, 0xC0002000
525
	   mov ecx, 4
530
	   mov ecx, 4
526
	   mov edi, pcmout_bdl
531
	   mov edi, pcmout_bdl
527
@@:
532
@@:
528
	   mov [edi], eax
533
	   mov [edi], eax
529
	   mov [edi+4], ebx
534
	   mov [edi+4], ebx
530
 
535
 
531
	   mov [edi+32], eax
536
	   mov [edi+32], eax
532
	   mov [edi+4+32], ebx
537
	   mov [edi+4+32], ebx
533
 
538
 
534
	   mov [edi+64], eax
539
	   mov [edi+64], eax
535
	   mov [edi+4+64], ebx
540
	   mov [edi+4+64], ebx
536
 
541
 
537
	   mov [edi+96], eax
542
	   mov [edi+96], eax
538
	   mov [edi+4+96], ebx
543
	   mov [edi+4+96], ebx
539
 
544
 
540
	   mov [edi+128], eax
545
	   mov [edi+128], eax
541
	   mov [edi+4+128], ebx
546
	   mov [edi+4+128], ebx
542
 
547
 
543
	   mov [edi+160], eax
548
	   mov [edi+160], eax
544
	   mov [edi+4+160], ebx
549
	   mov [edi+4+160], ebx
545
 
550
 
546
	   mov [edi+192], eax
551
	   mov [edi+192], eax
547
	   mov [edi+4+192], ebx
552
	   mov [edi+4+192], ebx
548
 
553
 
549
	   mov [edi+224], eax
554
	   mov [edi+224], eax
550
	   mov [edi+4+224], ebx
555
	   mov [edi+4+224], ebx
551
 
556
 
552
	   add eax, 0x4000
557
	   add eax, 0x4000
553
	   add edi, 8
558
	   add edi, 8
554
	   loop @B
559
	   loop @B
555
 
560
 
556
	   mov edi, buff_list
561
	   mov edi, buff_list
557
	   mov eax, [ctrl.buffer]
562
	   mov eax, [ctrl.buffer]
558
	   mov ecx, 4
563
	   mov ecx, 4
559
@@:
564
@@:
560
	   mov [edi], eax
565
	   mov [edi], eax
561
	   mov [edi+16], eax
566
	   mov [edi+16], eax
562
	   mov [edi+32], eax
567
	   mov [edi+32], eax
563
	   mov [edi+48], eax
568
	   mov [edi+48], eax
564
	   mov [edi+64], eax
569
	   mov [edi+64], eax
565
	   mov [edi+80], eax
570
	   mov [edi+80], eax
566
	   mov [edi+96], eax
571
	   mov [edi+96], eax
567
	   mov [edi+112], eax
572
	   mov [edi+112], eax
568
 
573
 
569
	   add eax, 0x4000
574
	   add eax, 0x4000
570
	   add edi, 4
575
	   add edi, 4
571
	   loop @B
576
	   loop @B
572
 
577
 
573
	   mov ecx, pcmout_bdl
578
	   mov ecx, pcmout_bdl
574
           stdcall GetPgAddr, ecx
579
           stdcall GetPgAddr, ecx
575
	   and ecx, 0xFFF
580
	   and ecx, 0xFFF
576
	   add eax, ecx
581
	   add eax, ecx
577
 
582
 
578
	   mov edx, PCM_OUT_BDL
583
	   mov edx, PCM_OUT_BDL
579
	   call [ctrl.ctrl_write32]
584
	   call [ctrl.ctrl_write32]
580
 
585
 
581
	   mov eax, 16
586
	   mov eax, 16
582
	   mov [ctrl.lvi_reg], eax
587
	   mov [ctrl.lvi_reg], eax
583
	   mov edx, PCM_OUT_LVI_REG
588
	   mov edx, PCM_OUT_LVI_REG
584
	   call [ctrl.ctrl_write8]
589
	   call [ctrl.ctrl_write8]
585
 
590
 
586
	   ret
591
	   ret
587
endp
592
endp
588
 
593
 
589
align 4
594
align 4
590
proc detect_controller
595
proc detect_controller
591
	   locals
596
	   locals
592
	     last_bus dd ?
597
	     last_bus dd ?
593
	     bus      dd ?
598
	     bus      dd ?
594
	     devfn    dd ?
599
	     devfn    dd ?
595
	   endl
600
	   endl
596
 
601
 
597
	   xor eax, eax
602
	   xor eax, eax
598
	   mov [bus], eax
603
	   mov [bus], eax
599
	   inc eax
604
	   inc eax
600
           call PciApi
605
           call PciApi
601
	   cmp eax, -1
606
	   cmp eax, -1
602
	   je .err
607
	   je .err
603
 
608
 
604
	   mov [last_bus], eax
609
	   mov [last_bus], eax
605
 
610
 
606
.next_bus:
611
.next_bus:
607
	   and [devfn], 0
612
	   and [devfn], 0
608
.next_dev:
613
.next_dev:
609
           stdcall PciRead32, [bus], [devfn], dword 0
614
           stdcall PciRead32, [bus], [devfn], dword 0
610
	   test eax, eax
615
	   test eax, eax
611
	   jz .next
616
	   jz .next
612
	   cmp eax, -1
617
	   cmp eax, -1
613
	   je .next
618
	   je .next
614
 
619
 
615
	   mov edi, devices
620
	   mov edi, devices
616
@@:
621
@@:
617
	   mov ebx, [edi]
622
	   mov ebx, [edi]
618
	   test ebx, ebx
623
	   test ebx, ebx
619
	   jz .next
624
	   jz .next
620
 
625
 
621
	   cmp eax, ebx
626
	   cmp eax, ebx
622
	   je .found
627
	   je .found
623
	   add edi, 12
628
	   add edi, 12
624
	   jmp @B
629
	   jmp @B
625
 
630
 
626
.next:	   inc [devfn]
631
.next:	   inc [devfn]
627
	   cmp [devfn], 256
632
	   cmp [devfn], 256
628
	   jb  .next_dev
633
	   jb  .next_dev
629
	   mov eax, [bus]
634
	   mov eax, [bus]
630
	   inc eax
635
	   inc eax
631
	   mov [bus], eax
636
	   mov [bus], eax
632
	   cmp eax, [last_bus]
637
	   cmp eax, [last_bus]
633
	   jna .next_bus
638
	   jna .next_bus
634
	   xor eax, eax
639
	   xor eax, eax
635
	   ret
640
	   ret
636
.found:
641
.found:
637
	   mov ebx, [bus]
642
	   mov ebx, [bus]
638
	   mov [ctrl.bus], ebx
643
	   mov [ctrl.bus], ebx
639
 
644
 
640
	   mov ecx, [devfn]
645
	   mov ecx, [devfn]
641
	   mov [ctrl.devfn], ecx
646
	   mov [ctrl.devfn], ecx
642
 
647
 
643
	   mov edx, eax
648
	   mov edx, eax
644
	   and edx, 0xFFFF
649
	   and edx, 0xFFFF
645
	   mov [ctrl.vendor], edx
650
	   mov [ctrl.vendor], edx
646
	   shr eax, 16
651
	   shr eax, 16
647
	   mov [ctrl.dev_id], eax
652
	   mov [ctrl.dev_id], eax
648
 
653
 
649
	   mov ebx, [edi+4]
654
	   mov ebx, [edi+4]
650
	   mov [ctrl.ctrl_ids], ebx
655
	   mov [ctrl.ctrl_ids], ebx
651
	   mov esi, [edi+8]
656
	   mov esi, [edi+8]
652
	   mov [ctrl.ctrl_setup], esi
657
	   mov [ctrl.ctrl_setup], esi
653
 
658
 
654
           cmp ebx, VID_INTEL
659
           cmp ebx, VID_INTEL
655
           jne @F
660
           jne @F
656
	   mov [ctrl.vendor_ids], msg_Intel
661
	   mov [ctrl.vendor_ids], msg_Intel
657
           ret
662
           ret
658
@@:
663
@@:
659
           cmp ebx, VID_NVIDIA
664
           cmp ebx, VID_NVIDIA
660
           jne @F
665
           jne @F
661
           mov [ctrl.vendor_ids], msg_NVidia
666
           mov [ctrl.vendor_ids], msg_NVidia
662
@@:
667
@@:
663
           mov [ctrl.vendor_ids], 0     ;something  wrong ?
668
           mov [ctrl.vendor_ids], 0     ;something  wrong ?
664
	   ret
669
	   ret
665
.err:
670
.err:
666
	   xor eax, eax
671
	   xor eax, eax
667
	   ret
672
	   ret
668
endp
673
endp
669
 
674
 
670
align 4
675
align 4
671
proc get_LPC_bus                ;for Intel chipsets ONLY !!!
676
proc get_LPC_bus                ;for Intel chipsets ONLY !!!
672
	   locals
677
	   locals
673
	     last_bus dd ?
678
	     last_bus dd ?
674
	     bus      dd ?
679
	     bus      dd ?
675
	   endl
680
	   endl
676
 
681
 
677
	   xor eax, eax
682
	   xor eax, eax
678
	   mov [bus], eax
683
	   mov [bus], eax
679
	   inc eax
684
	   inc eax
680
	   call [PciApi]
685
	   call [PciApi]
681
	   cmp eax, -1
686
	   cmp eax, -1
682
	   je .err
687
	   je .err
683
 
688
 
684
	   mov [last_bus], eax
689
	   mov [last_bus], eax
685
.next_bus:
690
.next_bus:
686
           stdcall PciRead32, [bus], dword 0xF8, dword 0
691
           stdcall PciRead32, [bus], dword 0xF8, dword 0
687
	   test eax, eax
692
	   test eax, eax
688
	   jz .next
693
	   jz .next
689
	   cmp eax, -1
694
	   cmp eax, -1
690
	   je .next
695
	   je .next
691
 
696
 
692
	   cmp eax, 0x24D08086
697
	   cmp eax, 0x24D08086
693
	   je .found
698
	   je .found
694
.next:
699
.next:
695
	   mov eax, [bus]
700
	   mov eax, [bus]
696
	   inc eax
701
	   inc eax
697
	   cmp eax, [last_bus]
702
	   cmp eax, [last_bus]
698
	   mov [bus], eax
703
	   mov [bus], eax
699
	   jna .next_bus
704
	   jna .next_bus
700
.err:
705
.err:
701
	   xor eax, eax
706
	   xor eax, eax
702
	   dec eax
707
	   dec eax
703
	   ret
708
	   ret
704
.found:
709
.found:
705
	   mov eax, [bus]
710
	   mov eax, [bus]
706
	   ret
711
	   ret
707
endp
712
endp
708
 
713
 
709
align 4
714
align 4
710
proc init_controller
715
proc init_controller
711
 
716
 
712
           stdcall PciRead32, [ctrl.bus], [ctrl.devfn], dword 4
717
           stdcall PciRead32, [ctrl.bus], [ctrl.devfn], dword 4
713
	   mov ebx, eax
718
	   mov ebx, eax
714
	   and eax, 0xFFFF
719
	   and eax, 0xFFFF
715
	   mov [ctrl.pci_cmd], eax
720
	   mov [ctrl.pci_cmd], eax
716
	   shr ebx, 16
721
	   shr ebx, 16
717
	   mov [ctrl.pci_stat], ebx
722
	   mov [ctrl.pci_stat], ebx
718
 
723
 
719
           stdcall PciRead32, [ctrl.bus], [ctrl.devfn], dword 0x10
724
           stdcall PciRead32, [ctrl.bus], [ctrl.devfn], dword 0x10
720
	   and eax,0xFFFE
725
	   and eax,0xFFFE
721
	   mov [ctrl.codec_io_base], eax
726
	   mov [ctrl.codec_io_base], eax
722
 
727
 
723
           stdcall PciRead32, [ctrl.bus], [ctrl.devfn], dword 0x14
728
           stdcall PciRead32, [ctrl.bus], [ctrl.devfn], dword 0x14
724
	   and eax, 0xFFC0
729
	   and eax, 0xFFC0
725
	   mov [ctrl.ctrl_io_base], eax
730
	   mov [ctrl.ctrl_io_base], eax
726
 
731
 
727
           stdcall PciRead32, [ctrl.bus], [ctrl.devfn], dword 0x18
732
           stdcall PciRead32, [ctrl.bus], [ctrl.devfn], dword 0x18
728
	   mov [ctrl.codec_mem_base], eax
733
	   mov [ctrl.codec_mem_base], eax
729
 
734
 
730
           stdcall PciRead32, [ctrl.bus], [ctrl.devfn], dword 0x1C
735
           stdcall PciRead32, [ctrl.bus], [ctrl.devfn], dword 0x1C
731
	   mov [ctrl.ctrl_mem_base], eax
736
	   mov [ctrl.ctrl_mem_base], eax
732
 
737
 
733
           stdcall PciRead32, [ctrl.bus], [ctrl.devfn], dword 0x3C
738
           stdcall PciRead32, [ctrl.bus], [ctrl.devfn], dword 0x3C
734
	   and eax, 0xFF
739
	   and eax, 0xFF
735
	   mov [ctrl.int_line], eax
740
	   mov [ctrl.int_line], eax
736
 
741
 
737
           stdcall PciRead8, [ctrl.bus], [ctrl.devfn], dword 0x41
742
           stdcall PciRead8, [ctrl.bus], [ctrl.devfn], dword 0x41
738
	   and eax, 0xFF
743
	   and eax, 0xFF
739
	   mov [ctrl.cfg_reg], eax
744
	   mov [ctrl.cfg_reg], eax
740
 
745
 
741
	   call [ctrl.ctrl_setup]
746
	   call [ctrl.ctrl_setup]
742
	   xor eax, eax
747
	   xor eax, eax
743
	   inc eax
748
	   inc eax
744
	   ret
749
	   ret
745
endp
750
endp
746
 
751
 
747
align 4
752
align 4
748
proc set_ICH
753
proc set_ICH
749
	   mov [ctrl.codec_read16],  codec_io_r16    ;virtual
754
	   mov [ctrl.codec_read16],  codec_io_r16    ;virtual
750
	   mov [ctrl.codec_write16], codec_io_w16    ;virtual
755
	   mov [ctrl.codec_write16], codec_io_w16    ;virtual
751
 
756
 
752
	   mov [ctrl.ctrl_read8 ],  ctrl_io_r8	     ;virtual
757
	   mov [ctrl.ctrl_read8 ],  ctrl_io_r8	     ;virtual
753
	   mov [ctrl.ctrl_read16],  ctrl_io_r16      ;virtual
758
	   mov [ctrl.ctrl_read16],  ctrl_io_r16      ;virtual
754
	   mov [ctrl.ctrl_read32],  ctrl_io_r32      ;virtual
759
	   mov [ctrl.ctrl_read32],  ctrl_io_r32      ;virtual
755
 
760
 
756
	   mov [ctrl.ctrl_write8 ], ctrl_io_w8	     ;virtual
761
	   mov [ctrl.ctrl_write8 ], ctrl_io_w8	     ;virtual
757
	   mov [ctrl.ctrl_write16], ctrl_io_w16      ;virtual
762
	   mov [ctrl.ctrl_write16], ctrl_io_w16      ;virtual
758
	   mov [ctrl.ctrl_write32], ctrl_io_w32      ;virtual
763
	   mov [ctrl.ctrl_write32], ctrl_io_w32      ;virtual
759
	   ret
764
	   ret
760
endp
765
endp
761
 
766
 
762
PG_SW                equ 0x003
767
PG_SW                equ 0x003
763
PG_NOCACHE           equ 0x018
768
PG_NOCACHE           equ 0x018
764
 
769
 
765
align 4
770
align 4
766
proc set_ICH4
771
proc set_ICH4
767
           stdcall AllocKernelSpace, dword 0x2000
772
           stdcall AllocKernelSpace, dword 0x2000
768
	   mov edi, eax
773
	   mov edi, eax
769
           stdcall MapPage, edi,[ctrl.codec_mem_base],PG_SW+PG_NOCACHE
774
           stdcall MapPage, edi,[ctrl.codec_mem_base],PG_SW+PG_NOCACHE
770
	   mov [ctrl.codec_mem_base], edi
775
	   mov [ctrl.codec_mem_base], edi
771
	   add edi, 0x1000
776
	   add edi, 0x1000
772
           stdcall MapPage, edi, [ctrl.ctrl_mem_base],PG_SW+PG_NOCACHE
777
           stdcall MapPage, edi, [ctrl.ctrl_mem_base],PG_SW+PG_NOCACHE
773
	   mov [ctrl.ctrl_mem_base], edi
778
	   mov [ctrl.ctrl_mem_base], edi
774
 
779
 
775
	   mov [ctrl.codec_read16],  codec_mem_r16    ;virtual
780
	   mov [ctrl.codec_read16],  codec_mem_r16    ;virtual
776
	   mov [ctrl.codec_write16], codec_mem_w16    ;virtual
781
	   mov [ctrl.codec_write16], codec_mem_w16    ;virtual
777
 
782
 
778
	   mov [ctrl.ctrl_read8 ],  ctrl_mem_r8       ;virtual
783
	   mov [ctrl.ctrl_read8 ],  ctrl_mem_r8       ;virtual
779
	   mov [ctrl.ctrl_read16],  ctrl_mem_r16      ;virtual
784
	   mov [ctrl.ctrl_read16],  ctrl_mem_r16      ;virtual
780
	   mov [ctrl.ctrl_read32],  ctrl_mem_r32      ;virtual
785
	   mov [ctrl.ctrl_read32],  ctrl_mem_r32      ;virtual
781
 
786
 
782
	   mov [ctrl.ctrl_write8 ], ctrl_mem_w8       ;virtual
787
	   mov [ctrl.ctrl_write8 ], ctrl_mem_w8       ;virtual
783
	   mov [ctrl.ctrl_write16], ctrl_mem_w16      ;virtual
788
	   mov [ctrl.ctrl_write16], ctrl_mem_w16      ;virtual
784
	   mov [ctrl.ctrl_write32], ctrl_mem_w32      ;virtual
789
	   mov [ctrl.ctrl_write32], ctrl_mem_w32      ;virtual
785
	   ret
790
	   ret
786
endp
791
endp
787
 
792
 
788
align 4
793
align 4
789
proc reset_controller
794
proc reset_controller
790
 
795
 
791
	   xor eax, eax
796
	   xor eax, eax
792
	   mov edx, PCM_IN_CR_REG
797
	   mov edx, PCM_IN_CR_REG
793
	   call [ctrl.ctrl_write8]
798
	   call [ctrl.ctrl_write8]
794
 
799
 
795
	   mov edx, PCM_OUT_CR_REG
800
	   mov edx, PCM_OUT_CR_REG
796
	   call [ctrl.ctrl_write8]
801
	   call [ctrl.ctrl_write8]
797
 
802
 
798
	   mov edx, MC_IN_CR_REG
803
	   mov edx, MC_IN_CR_REG
799
	   call [ctrl.ctrl_write8]
804
	   call [ctrl.ctrl_write8]
800
 
805
 
801
	   mov eax, RR
806
	   mov eax, RR
802
	   mov edx, PCM_IN_CR_REG
807
	   mov edx, PCM_IN_CR_REG
803
	   call [ctrl.ctrl_write8]
808
	   call [ctrl.ctrl_write8]
804
 
809
 
805
	   mov edx, PCM_OUT_CR_REG
810
	   mov edx, PCM_OUT_CR_REG
806
	   call [ctrl.ctrl_write8]
811
	   call [ctrl.ctrl_write8]
807
 
812
 
808
	   mov	edx, MC_IN_CR_REG
813
	   mov	edx, MC_IN_CR_REG
809
	   call [ctrl.ctrl_write8]
814
	   call [ctrl.ctrl_write8]
810
 
815
 
811
	   ret
816
	   ret
812
endp
817
endp
813
 
818
 
814
align 4
819
align 4
815
proc init_codec
820
proc init_codec
816
	   locals
821
	   locals
817
	     counter dd ?
822
	     counter dd ?
818
	   endl
823
	   endl
819
 
824
 
820
	   call reset_codec
825
	   call reset_codec
821
	   and eax, eax
826
	   and eax, eax
822
	   jz .err
827
	   jz .err
823
 
828
 
824
	   xor edx, edx 		  ;ac_reg_0
829
	   xor edx, edx 		  ;ac_reg_0
825
	   call [ctrl.codec_write16]
830
	   call [ctrl.codec_write16]
826
 
831
 
827
	   xor eax, eax
832
	   xor eax, eax
828
	   mov edx, CODEC_REG_POWERDOWN
833
	   mov edx, CODEC_REG_POWERDOWN
829
	   call [ctrl.codec_write16]
834
	   call [ctrl.codec_write16]
830
 
835
 
831
	   mov [counter], 200	    ; total 200*5 ms = 1s
836
	   mov [counter], 200	    ; total 200*5 ms = 1s
832
.wait:
837
.wait:
833
	   mov edx, CODEC_REG_POWERDOWN
838
	   mov edx, CODEC_REG_POWERDOWN
834
	   call [ctrl.codec_read16]
839
	   call [ctrl.codec_read16]
835
	   and eax, 0x0F
840
	   and eax, 0x0F
836
	   cmp eax, 0x0F
841
	   cmp eax, 0x0F
837
	   jz .ready
842
	   jz .ready
838
 
843
 
839
	   mov eax, 5000	  ; wait 5 ms
844
	   mov eax, 5000	  ; wait 5 ms
840
	   call StallExec
845
	   call StallExec
841
	   sub [counter] , 1
846
	   sub [counter] , 1
842
	   jnz .wait
847
	   jnz .wait
843
.err:
848
.err:
844
	   xor eax, eax        ; timeout error
849
	   xor eax, eax        ; timeout error
845
	   ret
850
	   ret
846
.ready:
851
.ready:
847
	   call detect_codec
852
	   call detect_codec
848
 
853
 
849
	   xor eax, eax
854
	   xor eax, eax
850
	   inc eax
855
	   inc eax
851
	   ret
856
	   ret
852
endp
857
endp
853
 
858
 
854
align 4
859
align 4
855
proc reset_codec
860
proc reset_codec
856
	   mov edx, GLOB_CTRL
861
	   mov edx, GLOB_CTRL
857
	   call [ctrl.ctrl_read32]
862
	   call [ctrl.ctrl_read32]
858
 
863
 
859
           test eax, 0x02
864
           test eax, 0x02
860
           jz .cold
865
           jz .cold
861
 
866
 
862
           call warm_reset
867
           call warm_reset
863
           jnc .ok
868
           jnc .ok
864
.cold:
869
.cold:
865
	   call cold_reset
870
	   call cold_reset
866
	   jnc .ok
871
	   jnc .ok
867
 
872
 
868
     if DEBUG
873
     if DEBUG
869
	   mov esi, msgCFail
874
	   mov esi, msgCFail
870
           call SysMsgBoardStr
875
           call SysMsgBoardStr
871
     end if
876
     end if
872
	   xor eax, eax 	   ; timeout error
877
	   xor eax, eax 	   ; timeout error
873
	   ret
878
	   ret
874
.ok:
879
.ok:
875
     if DEBUG
880
     if DEBUG
876
           mov esi, msgResetOk
881
           mov esi, msgResetOk
877
           call SysMsgBoardStr
882
           call SysMsgBoardStr
878
     end if
883
     end if
879
 
884
 
880
           xor eax, eax
885
           xor eax, eax
881
	   inc eax
886
	   inc eax
882
	   ret
887
	   ret
883
endp
888
endp
884
 
889
 
885
align 4
890
align 4
886
proc warm_reset
891
proc warm_reset
887
	   locals
892
	   locals
888
	     counter dd ?
893
	     counter dd ?
889
	   endl
894
	   endl
890
 
895
 
891
	   mov eax, 0x06
896
	   mov eax, 0x06
892
	   mov edx, GLOB_CTRL
897
	   mov edx, GLOB_CTRL
893
	   call [ctrl.ctrl_write32]
898
	   call [ctrl.ctrl_write32]
894
 
899
 
895
     if DEBUG
900
     if DEBUG
896
	   mov esi, msgWarm
901
	   mov esi, msgWarm
897
           call SysMsgBoardStr
902
           call SysMsgBoardStr
898
     end if
903
     end if
899
 
904
 
900
	   mov [counter], 10	   ; total 10*100 ms = 1s
905
	   mov [counter], 10	   ; total 10*100 ms = 1s
901
.wait:
906
.wait:
902
	   mov eax, 100000	   ; wait 100 ms
907
	   mov eax, 100000	   ; wait 100 ms
903
	   call StallExec
908
	   call StallExec
904
 
909
 
905
	   mov edx, GLOB_CTRL
910
	   mov edx, GLOB_CTRL
906
	   call [ctrl.ctrl_read32]
911
	   call [ctrl.ctrl_read32]
907
	   test eax, 4
912
	   test eax, 4
908
	   jz .ok
913
	   jz .ok
909
	   sub [counter], 1
914
	   sub [counter], 1
910
	   jnz .wait
915
	   jnz .wait
911
 
916
 
912
     if DEBUG
917
     if DEBUG
913
	   mov esi, msgWRFail
918
	   mov esi, msgWRFail
914
           call SysMsgBoardStr
919
           call SysMsgBoardStr
915
     end if
920
     end if
916
 
921
 
917
	   stc
922
	   stc
918
	   ret
923
	   ret
919
.ok:
924
.ok:
920
	   mov edx, CTRL_STAT
925
	   mov edx, CTRL_STAT
921
	   call [ctrl.ctrl_read32]
926
	   call [ctrl.ctrl_read32]
922
	   and eax, CTRL_ST_CREADY
927
	   and eax, CTRL_ST_CREADY
923
           jz .fail
928
           jz .fail
924
           clc
929
           clc
925
	   ret
930
	   ret
926
.fail:
931
.fail:
927
           stc
932
           stc
928
	   ret
933
	   ret
929
endp
934
endp
930
 
935
 
931
align 4
936
align 4
932
proc cold_reset
937
proc cold_reset
933
	   locals
938
	   locals
934
	     counter dd ?
939
	     counter dd ?
935
	   endl
940
	   endl
936
 
941
 
937
	   xor eax, eax
942
	   xor eax, eax
938
	   mov edx, GLOB_CTRL
943
	   mov edx, GLOB_CTRL
939
	   call [ctrl.ctrl_write32]
944
	   call [ctrl.ctrl_write32]
940
 
945
 
941
     if DEBUG
946
     if DEBUG
942
	   mov esi, msgCold
947
	   mov esi, msgCold
943
           call SysMsgBoardStr
948
           call SysMsgBoardStr
944
     end if
949
     end if
945
 
950
 
946
	   mov eax, 1000000	   ; wait 1 s
951
	   mov eax, 1000000	   ; wait 1 s
947
	   call StallExec
952
	   call StallExec
948
 
953
 
949
	   mov eax, 2
954
	   mov eax, 2
950
	   mov edx, GLOB_CTRL
955
	   mov edx, GLOB_CTRL
951
	   call [ctrl.ctrl_write32]
956
	   call [ctrl.ctrl_write32]
952
 
957
 
953
	   mov [counter], 10	   ; total 10*100 ms = 1s
958
	   mov [counter], 10	   ; total 10*100 ms = 1s
954
.wait:
959
.wait:
955
	   mov eax, 100000	   ; wait 100 ms
960
	   mov eax, 100000	   ; wait 100 ms
956
	   call StallExec
961
	   call StallExec
957
 
962
 
958
	   mov edx, GLOB_CTRL
963
	   mov edx, GLOB_CTRL
959
	   call [ctrl.ctrl_read32]
964
	   call [ctrl.ctrl_read32]
960
	   test eax, 4
965
	   test eax, 4
961
	   jz .ok
966
	   jz .ok
962
	   sub [counter], 1
967
	   sub [counter], 1
963
	   jnz .wait
968
	   jnz .wait
964
 
969
 
965
     if DEBUG
970
     if DEBUG
966
	   mov esi, msgCRFail
971
	   mov esi, msgCRFail
967
           call SysMsgBoardStr
972
           call SysMsgBoardStr
968
     end if
973
     end if
969
	   stc
974
	   stc
970
	   ret
975
	   ret
971
.ok:
976
.ok:
972
	   mov edx, CTRL_STAT
977
	   mov edx, CTRL_STAT
973
	   call [ctrl.ctrl_read32]
978
	   call [ctrl.ctrl_read32]
974
	   and eax, CTRL_ST_CREADY
979
	   and eax, CTRL_ST_CREADY
975
           jz .fail
980
           jz .fail
976
           clc
981
           clc
977
	   ret
982
	   ret
978
.fail:
983
.fail:
979
           stc
984
           stc
980
	   ret
985
	   ret
981
endp
986
endp
982
 
987
 
983
align 4
988
align 4
984
proc play
989
proc play
985
 
990
 
986
	   mov eax, 16
991
	   mov eax, 16
987
	   mov [ctrl.lvi_reg], eax
992
	   mov [ctrl.lvi_reg], eax
988
	   mov edx, PCM_OUT_LVI_REG
993
	   mov edx, PCM_OUT_LVI_REG
989
	   call [ctrl.ctrl_write8]
994
	   call [ctrl.ctrl_write8]
990
 
995
 
991
	   mov edx, PCM_OUT_CR_REG
996
	   mov edx, PCM_OUT_CR_REG
992
	   mov ax, 0x1D
997
	   mov ax, 0x1D
993
	   call [ctrl.ctrl_write8]
998
	   call [ctrl.ctrl_write8]
994
	   ret
999
	   ret
995
endp
1000
endp
996
 
1001
 
997
align 4
1002
align 4
998
proc stop
1003
proc stop
999
	   mov edx, PCM_OUT_CR_REG
1004
	   mov edx, PCM_OUT_CR_REG
1000
	   mov ax, 0x14
1005
	   mov ax, 0x14
1001
	   call [ctrl.ctrl_write8]
1006
	   call [ctrl.ctrl_write8]
1002
 
1007
 
1003
	   mov eax, 16
1008
	   mov eax, 16
1004
	   mov [ctrl.lvi_reg], eax
1009
	   mov [ctrl.lvi_reg], eax
1005
	   mov edx, PCM_OUT_LVI_REG
1010
	   mov edx, PCM_OUT_LVI_REG
1006
	   call [ctrl.ctrl_write8]
1011
	   call [ctrl.ctrl_write8]
1007
 
1012
 
1008
	   ret
1013
	   ret
1009
endp
1014
endp
1010
 
1015
 
1011
align 4
1016
align 4
1012
proc get_dev_info stdcall, p_info:dword
1017
proc get_dev_info stdcall, p_info:dword
1013
	   virtual at esi
1018
	   virtual at esi
1014
	     CTRL_INFO CTRL_INFO
1019
	     CTRL_INFO CTRL_INFO
1015
	   end virtual
1020
	   end virtual
1016
 
1021
 
1017
	   mov esi, [p_info]
1022
	   mov esi, [p_info]
1018
	   mov eax, [ctrl.int_line]
1023
	   mov eax, [ctrl.int_line]
1019
	   mov ebx, [ctrl.codec_io_base]
1024
	   mov ebx, [ctrl.codec_io_base]
1020
	   mov ecx, [ctrl.ctrl_io_base]
1025
	   mov ecx, [ctrl.ctrl_io_base]
1021
	   mov edx, [ctrl.codec_mem_base]
1026
	   mov edx, [ctrl.codec_mem_base]
1022
	   mov edi, [ctrl.ctrl_mem_base]
1027
	   mov edi, [ctrl.ctrl_mem_base]
1023
 
1028
 
1024
	   mov [CTRL_INFO.irq], eax
1029
	   mov [CTRL_INFO.irq], eax
1025
	   mov [CTRL_INFO.codec_io_base], ebx
1030
	   mov [CTRL_INFO.codec_io_base], ebx
1026
	   mov [CTRL_INFO.ctrl_io_base], ecx
1031
	   mov [CTRL_INFO.ctrl_io_base], ecx
1027
	   mov [CTRL_INFO.codec_mem_base], edx
1032
	   mov [CTRL_INFO.codec_mem_base], edx
1028
	   mov [CTRL_INFO.ctrl_mem_base], edi
1033
	   mov [CTRL_INFO.ctrl_mem_base], edi
1029
 
1034
 
1030
           mov eax, [codec.chip_id]
1035
           mov eax, [codec.chip_id]
1031
           mov [CTRL_INFO.codec_id], eax
1036
           mov [CTRL_INFO.codec_id], eax
1032
 
1037
 
1033
	   mov edx, GLOB_CTRL
1038
	   mov edx, GLOB_CTRL
1034
           call [ctrl.ctrl_read32]
1039
           call [ctrl.ctrl_read32]
1035
	   mov [CTRL_INFO.glob_cntrl], eax
1040
	   mov [CTRL_INFO.glob_cntrl], eax
1036
 
1041
 
1037
	   mov edx, CTRL_STAT
1042
	   mov edx, CTRL_STAT
1038
           call [ctrl.ctrl_read32]
1043
           call [ctrl.ctrl_read32]
1039
	   mov [CTRL_INFO.glob_sta], eax
1044
	   mov [CTRL_INFO.glob_sta], eax
1040
 
1045
 
1041
	   mov ebx, [ctrl.pci_cmd]
1046
	   mov ebx, [ctrl.pci_cmd]
1042
	   mov [CTRL_INFO.pci_cmd], ebx
1047
	   mov [CTRL_INFO.pci_cmd], ebx
1043
 
1048
 
1044
	   ret
1049
	   ret
1045
endp
1050
endp
1046
 
1051
 
1047
align 4
1052
align 4
1048
proc set_callback stdcall, handler:dword
1053
proc set_callback stdcall, handler:dword
1049
	   mov eax, [handler]
1054
	   mov eax, [handler]
1050
	   mov [ctrl.user_callback], eax
1055
	   mov [ctrl.user_callback], eax
1051
	   ret
1056
	   ret
1052
endp
1057
endp
1053
 
1058
 
1054
align 4
1059
align 4
1055
proc codec_read stdcall, ac_reg:dword	   ; reg = edx, reval = eax
1060
proc codec_read stdcall, ac_reg:dword	   ; reg = edx, reval = eax
1056
 
1061
 
1057
	   mov edx, [ac_reg]
1062
	   mov edx, [ac_reg]
1058
 
1063
 
1059
	   mov ebx, edx
1064
	   mov ebx, edx
1060
	   shr ebx, 1
1065
	   shr ebx, 1
1061
	   bt [codec.shadow_flag], ebx
1066
	   bt [codec.shadow_flag], ebx
1062
	   jc .use_shadow
1067
	   jc .use_shadow
1063
 
1068
 
1064
	   call [ctrl.codec_read16]  ;change edx !!!
1069
	   call [ctrl.codec_read16]  ;change edx !!!
1065
	   mov ecx, eax
1070
	   mov ecx, eax
1066
 
1071
 
1067
	   mov edx, CTRL_STAT
1072
	   mov edx, CTRL_STAT
1068
	   call [ctrl.ctrl_read32]
1073
	   call [ctrl.ctrl_read32]
1069
	   test eax, CTRL_ST_RCS
1074
	   test eax, CTRL_ST_RCS
1070
	   jz .read_ok
1075
	   jz .read_ok
1071
 
1076
 
1072
	   mov edx, CTRL_STAT
1077
	   mov edx, CTRL_STAT
1073
	   call [ctrl.ctrl_write32]
1078
	   call [ctrl.ctrl_write32]
1074
	   xor eax,eax
1079
	   xor eax,eax
1075
	   not eax		;timeout
1080
	   not eax		;timeout
1076
	   ret
1081
	   ret
1077
.read_ok:
1082
.read_ok:
1078
	   mov edx, [ac_reg]
1083
	   mov edx, [ac_reg]
1079
	   mov [codec.regs+edx], cx
1084
	   mov [codec.regs+edx], cx
1080
	   bts [codec.shadow_flag], ebx
1085
	   bts [codec.shadow_flag], ebx
1081
	   mov eax, ecx
1086
	   mov eax, ecx
1082
	   ret
1087
	   ret
1083
.use_shadow:
1088
.use_shadow:
1084
	   movzx eax, word [codec.regs+edx]
1089
	   movzx eax, word [codec.regs+edx]
1085
	   ret
1090
	   ret
1086
endp
1091
endp
1087
 
1092
 
1088
align 4
1093
align 4
1089
proc codec_write stdcall, ac_reg:dword
1094
proc codec_write stdcall, ac_reg:dword
1090
	   push eax
1095
	   push eax
1091
	   call check_semafore
1096
	   call check_semafore
1092
	   and eax, eax
1097
	   and eax, eax
1093
	   jz .err
1098
	   jz .err
1094
	   pop eax
1099
	   pop eax
1095
 
1100
 
1096
	   mov esi, [ac_reg]
1101
	   mov esi, [ac_reg]
1097
	   mov edx, esi
1102
	   mov edx, esi
1098
	   call [ctrl.codec_write16]
1103
	   call [ctrl.codec_write16]
1099
	   mov [codec.regs+esi], ax
1104
	   mov [codec.regs+esi], ax
1100
	   shr esi, 1
1105
	   shr esi, 1
1101
	   bts [codec.shadow_flag], esi
1106
	   bts [codec.shadow_flag], esi
1102
	   ret
1107
	   ret
1103
.err:
1108
.err:
1104
	   pop eax
1109
	   pop eax
1105
	   ret
1110
	   ret
1106
endp
1111
endp
1107
 
1112
 
1108
align 4
1113
align 4
1109
proc codec_check_ready
1114
proc codec_check_ready
1110
 
1115
 
1111
	  mov edx, CTRL_ST
1116
	  mov edx, CTRL_ST
1112
	  call [ctrl.ctrl_read32]
1117
	  call [ctrl.ctrl_read32]
1113
	  and eax, CTRL_ST_CREADY
1118
	  and eax, CTRL_ST_CREADY
1114
	  jz .not_ready
1119
	  jz .not_ready
1115
 
1120
 
1116
	  xor eax, wax
1121
	  xor eax, wax
1117
	  inc eax
1122
	  inc eax
1118
	  ret
1123
	  ret
1119
 
1124
 
1120
align 4
1125
align 4
1121
.not_ready:
1126
.not_ready:
1122
	  xor eax, eax
1127
	  xor eax, eax
1123
	  ret
1128
	  ret
1124
endp
1129
endp
1125
 
1130
 
1126
align 4
1131
align 4
1127
proc check_semafore
1132
proc check_semafore
1128
	   local counter:DWORD
1133
	   local counter:DWORD
1129
 
1134
 
1130
	   mov [counter], 100
1135
	   mov [counter], 100
1131
.l1:
1136
.l1:
1132
	   mov edx, CTRL_CAS
1137
	   mov edx, CTRL_CAS
1133
	   call [ctrl.ctrl_read8]
1138
	   call [ctrl.ctrl_read8]
1134
	   and eax, CAS_FLAG
1139
	   and eax, CAS_FLAG
1135
	   jz .ok
1140
	   jz .ok
1136
 
1141
 
1137
	   mov eax, 1
1142
	   mov eax, 1
1138
	   call StallExec
1143
	   call StallExec
1139
	   sub [counter], 1
1144
	   sub [counter], 1
1140
	   jnz .l1
1145
	   jnz .l1
1141
	   xor eax, eax
1146
	   xor eax, eax
1142
	   ret
1147
	   ret
1143
align 4
1148
align 4
1144
.ok:
1149
.ok:
1145
	   xor eax,eax
1150
	   xor eax,eax
1146
	   inc eax
1151
	   inc eax
1147
	   ret
1152
	   ret
1148
endp
1153
endp
1149
 
1154
 
1150
align 4
1155
align 4
1151
proc StallExec
1156
proc StallExec
1152
	   push ecx
1157
	   push ecx
1153
	   push edx
1158
	   push edx
1154
	   push ebx
1159
	   push ebx
1155
	   push eax
1160
	   push eax
1156
 
1161
 
1157
	   mov ecx, CPU_FREQ
1162
	   mov ecx, CPU_FREQ
1158
	   mul ecx
1163
	   mul ecx
1159
	   mov ebx, eax       ;low
1164
	   mov ebx, eax       ;low
1160
	   mov ecx, edx       ;high
1165
	   mov ecx, edx       ;high
1161
	   rdtsc
1166
	   rdtsc
1162
	   add ebx, eax
1167
	   add ebx, eax
1163
	   adc ecx,edx
1168
	   adc ecx,edx
1164
@@:
1169
@@:
1165
	   rdtsc
1170
	   rdtsc
1166
	   sub eax, ebx
1171
	   sub eax, ebx
1167
	   sbb edx, ecx
1172
	   sbb edx, ecx
1168
	   jb @B
1173
	   jb @B
1169
 
1174
 
1170
	   pop eax
1175
	   pop eax
1171
	   pop ebx
1176
	   pop ebx
1172
	   pop edx
1177
	   pop edx
1173
	   pop ecx
1178
	   pop ecx
1174
	   ret
1179
	   ret
1175
endp
1180
endp
1176
 
1181
 
1177
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1182
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1178
;          CONTROLLER IO functions
1183
;          CONTROLLER IO functions
1179
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1184
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1180
 
1185
 
1181
align 4
1186
align 4
1182
proc codec_io_r16
1187
proc codec_io_r16
1183
	add edx, [ctrl.codec_io_base]
1188
	add edx, [ctrl.codec_io_base]
1184
	in  ax, dx
1189
	in  ax, dx
1185
	ret
1190
	ret
1186
endp
1191
endp
1187
 
1192
 
1188
align 4
1193
align 4
1189
proc codec_io_w16
1194
proc codec_io_w16
1190
	add edx, [ctrl.codec_io_base]
1195
	add edx, [ctrl.codec_io_base]
1191
	out dx, ax
1196
	out dx, ax
1192
	ret
1197
	ret
1193
endp
1198
endp
1194
 
1199
 
1195
align 4
1200
align 4
1196
proc ctrl_io_r8
1201
proc ctrl_io_r8
1197
	add edx, [ctrl.ctrl_io_base]
1202
	add edx, [ctrl.ctrl_io_base]
1198
	in  al, dx
1203
	in  al, dx
1199
	ret
1204
	ret
1200
endp
1205
endp
1201
 
1206
 
1202
align 4
1207
align 4
1203
proc ctrl_io_r16
1208
proc ctrl_io_r16
1204
	add edx, [ctrl.ctrl_io_base]
1209
	add edx, [ctrl.ctrl_io_base]
1205
	in  ax, dx
1210
	in  ax, dx
1206
	ret
1211
	ret
1207
endp
1212
endp
1208
 
1213
 
1209
align 4
1214
align 4
1210
proc ctrl_io_r32
1215
proc ctrl_io_r32
1211
	add edx, [ctrl.ctrl_io_base]
1216
	add edx, [ctrl.ctrl_io_base]
1212
	in  eax, dx
1217
	in  eax, dx
1213
	ret
1218
	ret
1214
endp
1219
endp
1215
 
1220
 
1216
align 4
1221
align 4
1217
proc ctrl_io_w8
1222
proc ctrl_io_w8
1218
	add edx, [ctrl.ctrl_io_base]
1223
	add edx, [ctrl.ctrl_io_base]
1219
	out dx, al
1224
	out dx, al
1220
	ret
1225
	ret
1221
endp
1226
endp
1222
 
1227
 
1223
align 4
1228
align 4
1224
proc ctrl_io_w16
1229
proc ctrl_io_w16
1225
	add edx, [ctrl.ctrl_io_base]
1230
	add edx, [ctrl.ctrl_io_base]
1226
	out dx, ax
1231
	out dx, ax
1227
	ret
1232
	ret
1228
endp
1233
endp
1229
 
1234
 
1230
align 4
1235
align 4
1231
proc ctrl_io_w32
1236
proc ctrl_io_w32
1232
	add edx, [ctrl.ctrl_io_base]
1237
	add edx, [ctrl.ctrl_io_base]
1233
	out dx, eax
1238
	out dx, eax
1234
	ret
1239
	ret
1235
endp
1240
endp
1236
 
1241
 
1237
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1242
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1238
;         MEMORY MAPPED IO    (os depended)
1243
;         MEMORY MAPPED IO    (os depended)
1239
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1244
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1240
 
1245
 
1241
align 4
1246
align 4
1242
proc codec_mem_r16
1247
proc codec_mem_r16
1243
	add edx, [ctrl.codec_mem_base]
1248
	add edx, [ctrl.codec_mem_base]
1244
	mov ax, word [edx]
1249
	mov ax, word [edx]
1245
	ret
1250
	ret
1246
endp
1251
endp
1247
 
1252
 
1248
align 4
1253
align 4
1249
proc codec_mem_w16
1254
proc codec_mem_w16
1250
	add edx, [ctrl.codec_mem_base]
1255
	add edx, [ctrl.codec_mem_base]
1251
	mov word [edx], ax
1256
	mov word [edx], ax
1252
	ret
1257
	ret
1253
endp
1258
endp
1254
 
1259
 
1255
align 4
1260
align 4
1256
proc ctrl_mem_r8
1261
proc ctrl_mem_r8
1257
	add edx, [ctrl.ctrl_mem_base]
1262
	add edx, [ctrl.ctrl_mem_base]
1258
	mov al, [edx]
1263
	mov al, [edx]
1259
	ret
1264
	ret
1260
endp
1265
endp
1261
 
1266
 
1262
align 4
1267
align 4
1263
proc ctrl_mem_r16
1268
proc ctrl_mem_r16
1264
	add edx, [ctrl.ctrl_mem_base]
1269
	add edx, [ctrl.ctrl_mem_base]
1265
	mov ax, [edx]
1270
	mov ax, [edx]
1266
	ret
1271
	ret
1267
endp
1272
endp
1268
 
1273
 
1269
align 4
1274
align 4
1270
proc ctrl_mem_r32
1275
proc ctrl_mem_r32
1271
	add edx, [ctrl.ctrl_mem_base]
1276
	add edx, [ctrl.ctrl_mem_base]
1272
	mov eax, [edx]
1277
	mov eax, [edx]
1273
	ret
1278
	ret
1274
endp
1279
endp
1275
 
1280
 
1276
align 4
1281
align 4
1277
proc ctrl_mem_w8
1282
proc ctrl_mem_w8
1278
	add edx, [ctrl.ctrl_mem_base]
1283
	add edx, [ctrl.ctrl_mem_base]
1279
	mov [edx], al
1284
	mov [edx], al
1280
 
1285
 
1281
	ret
1286
	ret
1282
endp
1287
endp
1283
 
1288
 
1284
align 4
1289
align 4
1285
proc ctrl_mem_w16
1290
proc ctrl_mem_w16
1286
	add edx, [ctrl.ctrl_mem_base]
1291
	add edx, [ctrl.ctrl_mem_base]
1287
	mov [edx], ax
1292
	mov [edx], ax
1288
	ret
1293
	ret
1289
endp
1294
endp
1290
 
1295
 
1291
align 4
1296
align 4
1292
proc ctrl_mem_w32
1297
proc ctrl_mem_w32
1293
	add edx, [ctrl.ctrl_mem_base]
1298
	add edx, [ctrl.ctrl_mem_base]
1294
	mov [edx], eax
1299
	mov [edx], eax
1295
	ret
1300
	ret
1296
endp
1301
endp
1297
 
1302
 
1298
 
1303
 
1299
include "codec.inc"
1304
include "codec.inc"
1300
 
1305
 
1301
align 4
1306
align 4
1302
devices dd (CTRL_ICH  shl 16)+VID_INTEL,msg_ICH, set_ICH
1307
devices dd (CTRL_ICH  shl 16)+VID_INTEL,msg_ICH, set_ICH
1303
	dd (CTRL_ICH0 shl 16)+VID_INTEL,msg_ICH0,set_ICH
1308
	dd (CTRL_ICH0 shl 16)+VID_INTEL,msg_ICH0,set_ICH
1304
	dd (CTRL_ICH2 shl 16)+VID_INTEL,msg_ICH2,set_ICH
1309
	dd (CTRL_ICH2 shl 16)+VID_INTEL,msg_ICH2,set_ICH
1305
	dd (CTRL_ICH3 shl 16)+VID_INTEL,msg_ICH3,set_ICH
1310
	dd (CTRL_ICH3 shl 16)+VID_INTEL,msg_ICH3,set_ICH
1306
        dd (CTRL_ICH4 shl 16)+VID_INTEL,msg_ICH4,set_ICH4
1311
        dd (CTRL_ICH4 shl 16)+VID_INTEL,msg_ICH4,set_ICH4
1307
        dd (CTRL_ICH5 shl 16)+VID_INTEL,msg_ICH5,set_ICH4
1312
        dd (CTRL_ICH5 shl 16)+VID_INTEL,msg_ICH5,set_ICH4
1308
        dd (CTRL_ICH6 shl 16)+VID_INTEL,msg_ICH6,set_ICH4
1313
        dd (CTRL_ICH6 shl 16)+VID_INTEL,msg_ICH6,set_ICH4
1309
        dd (CTRL_ICH7 shl 16)+VID_INTEL,msg_ICH7,set_ICH4
1314
        dd (CTRL_ICH7 shl 16)+VID_INTEL,msg_ICH7,set_ICH4
1310
 
1315
 
1311
        dd (CTRL_NFORCE  shl 16)+VID_NVIDIA,msg_NForce, set_ICH
1316
        dd (CTRL_NFORCE  shl 16)+VID_NVIDIA,msg_NForce, set_ICH
1312
        dd (CTRL_NFORCE2 shl 16)+VID_NVIDIA,msg_NForce2,set_ICH
1317
        dd (CTRL_NFORCE2 shl 16)+VID_NVIDIA,msg_NForce2,set_ICH
1313
        dd (CTRL_NFORCE3 shl 16)+VID_NVIDIA,msg_NForce3,set_ICH
1318
        dd (CTRL_NFORCE3 shl 16)+VID_NVIDIA,msg_NForce3,set_ICH
1314
 
1319
        dd (CTRL_MCP04   shl 16)+VID_NVIDIA,msg_MCP04,set_ICH
-
 
1320
        dd (CTRL_CK804   shl 16)+VID_NVIDIA,msg_CK804,set_ICH
-
 
1321
        dd (CTRL_CK8     shl 16)+VID_NVIDIA,msg_CK8,set_ICH
-
 
1322
        dd (CTRL_CK8S    shl 16)+VID_NVIDIA,msg_CK8S,set_ICH
-
 
1323
        dd (CTRL_MCP51   shl 16)+VID_NVIDIA,msg_MCP51,set_ICH
-
 
1324
 
1315
        dd 0    ;terminator
1325
        dd 0    ;terminator
1316
 
1326
 
1317
msg_ICH      db 'Intel ICH',  13,10, 0
1327
msg_ICH      db 'Intel ICH',  13,10, 0
1318
msg_ICH0     db 'Intel ICH0', 13,10, 0
1328
msg_ICH0     db 'Intel ICH0', 13,10, 0
1319
msg_ICH2     db 'Intel ICH2', 13,10, 0
1329
msg_ICH2     db 'Intel ICH2', 13,10, 0
1320
msg_ICH3     db 'Intel ICH3', 13,10, 0
1330
msg_ICH3     db 'Intel ICH3', 13,10, 0
1321
msg_ICH4     db 'Intel ICH4', 13,10, 0
1331
msg_ICH4     db 'Intel ICH4', 13,10, 0
1322
msg_ICH5     db 'Intel ICH5', 13,10, 0
1332
msg_ICH5     db 'Intel ICH5', 13,10, 0
1323
msg_ICH6     db 'Intel ICH6', 13,10, 0
1333
msg_ICH6     db 'Intel ICH6', 13,10, 0
1324
msg_ICH7     db 'Intel ICH7', 13,10, 0
1334
msg_ICH7     db 'Intel ICH7', 13,10, 0
1325
msg_Intel    db 'Intel Corp. ', 0
1335
msg_Intel    db 'Intel Corp. ', 0
1326
 
1336
 
1327
msg_NForce   db 'NForce',   13,10, 0
1337
msg_NForce   db 'NForce',      13,10, 0
1328
msg_NForce2  db 'NForce 2', 13,10, 0
1338
msg_NForce2  db 'NForce 2',    13,10, 0
1329
msg_NForce3  db 'NForce 3', 13,10, 0
1339
msg_NForce3  db 'NForce 3',    13,10, 0
1330
msg_NVidia   db 'NVidea', 0
1340
msg_MCP04    db 'NForce MCP04',13,10, 0
-
 
1341
msg_CK804    db 'NForce CK804',13,10, 0
-
 
1342
msg_CK8      db 'NForce CK8',  13,10, 0
-
 
1343
msg_CK8S     db 'NForce CK8S', 13,10, 0
-
 
1344
msg_MCP51    db 'NForce MCP51',13,10, 0
-
 
1345
 
-
 
1346
msg_NVidia   db 'NVidia', 0
1331
 
1347
 
1332
szKernel	    db 'KERNEL', 0
1348
szKernel	    db 'KERNEL', 0
1333
sz_sound_srv	    db 'SOUND',0
1349
sz_sound_srv	    db 'SOUND',0
1334
 
1350
 
1335
msgInit      db 'detect hardware...',13,10,0
1351
msgInit      db 'detect hardware...',13,10,0
1336
msgFail      db 'device not found',13,10,0
1352
msgFail      db 'device not found',13,10,0
1337
msgAttchIRQ  db 'IRQ line not supported', 13,10, 0
1353
msgAttchIRQ  db 'IRQ line not supported', 13,10, 0
1338
msgInvIRQ    db 'IRQ line not assigned or invalid', 13,10, 0
1354
msgInvIRQ    db 'IRQ line not assigned or invalid', 13,10, 0
1339
msgPlay      db 'start play', 13,10,0
1355
msgPlay      db 'start play', 13,10,0
1340
msgStop      db 'stop play',  13,10,0
1356
msgStop      db 'stop play',  13,10,0
1341
msgNotify    db 'call notify',13,10,0
1357
msgNotify    db 'call notify',13,10,0
1342
msgIRQ	     db 'AC97 IRQ', 13,10,0
1358
msgIRQ	     db 'AC97 IRQ', 13,10,0
1343
msgInitCtrl  db 'init controller',13,10,0
1359
msgInitCtrl  db 'init controller',13,10,0
1344
msgInitCodec db 'init codec',13,10,0
1360
msgInitCodec db 'init codec',13,10,0
1345
msgPrimBuff  db 'create primary buffer',13,10,0
1361
msgPrimBuff  db 'create primary buffer',13,10,0
1346
msgReg	     db 'set service handler',13,10,0
1362
msgReg	     db 'set service handler',13,10,0
1347
msgOk	     db 'service installed',13,10,0
1363
msgOk	     db 'service installed',13,10,0
1348
msgCold      db 'cold reset',13,10,0
1364
msgCold      db 'cold reset',13,10,0
1349
msgWarm      db 'warm reset',13,10,0
1365
msgWarm      db 'warm reset',13,10,0
1350
msgWRFail    db 'warm reset failed',13,10,0
1366
msgWRFail    db 'warm reset failed',13,10,0
1351
msgCRFail    db 'cold reset failed',13,10,0
1367
msgCRFail    db 'cold reset failed',13,10,0
1352
msgCFail     db 'codec not ready',13,10,0
1368
msgCFail     db 'codec not ready',13,10,0
1353
msgResetOk   db 'reset complete',13,10,0
1369
msgResetOk   db 'reset complete',13,10,0
1354
 
1370
 
1355
section '.data' data readable writable align 16
1371
section '.data' data readable writable align 16
1356
 
1372
 
1357
pcmout_bdl       rq 32
1373
pcmout_bdl       rq 32
1358
buff_list        rd 32
1374
buff_list        rd 32
1359
 
1375
 
1360
codec CODEC
1376
codec CODEC
1361
ctrl AC_CNTRL
1377
ctrl AC_CNTRL
1362
 
1378
 
1363
lpc_bus  rd 1
1379
lpc_bus  rd 1
1364
civ_val  rd 1
1380
civ_val  rd 1