Subversion Repositories Kolibri OS

Rev

Rev 5363 | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

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