Subversion Repositories Kolibri OS

Rev

Rev 5363 | Only display areas with differences | Regard 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
DEBUG_IRQ       equ 0
12
DEBUG_IRQ       equ 0
13
 
13
 
14
API_VERSION     equ 0x01000100
14
API_VERSION     equ 0x01000100
15
 
-
 
16
USE_COM_IRQ     equ 0    ;make irq 3 and irq 4 available for PCI devices
15
 
17
 
16
 
18
;irq 0,1,2,8,12,13 недоступны
17
;irq 0,13 unavailable
19
;                   FEDCBA9876543210
-
 
20
VALID_IRQ       equ 1100111011111000b
-
 
21
ATTCH_IRQ       equ 0000111010100000b
-
 
22
 
-
 
23
if USE_COM_IRQ
-
 
24
ATTCH_IRQ       equ 0000111010111000b
18
;                   FEDCBA9876543210
25
end if
19
VALID_IRQ       equ 1101111111111110b
26
 
20
 
27
CPU_FREQ        equ  2000d
21
CPU_FREQ        equ  2000d
28
 
22
 
29
BIT0  EQU 0x00000001
23
BIT0  EQU 0x00000001
30
BIT1  EQU 0x00000002
24
BIT1  EQU 0x00000002
31
BIT2  EQU 0x00000004
25
BIT2  EQU 0x00000004
32
BIT3  EQU 0x00000008
26
BIT3  EQU 0x00000008
33
BIT4  EQU 0x00000010
27
BIT4  EQU 0x00000010
34
BIT5  EQU 0x00000020
28
BIT5  EQU 0x00000020
35
BIT6  EQU 0x00000040
29
BIT6  EQU 0x00000040
36
BIT7  EQU 0x00000080
30
BIT7  EQU 0x00000080
37
BIT8  EQU 0x00000100
31
BIT8  EQU 0x00000100
38
BIT9  EQU 0x00000200
32
BIT9  EQU 0x00000200
39
BIT10 EQU 0x00000400
33
BIT10 EQU 0x00000400
40
BIT11 EQU 0x00000800
34
BIT11 EQU 0x00000800
41
BIT12 EQU 0x00001000
35
BIT12 EQU 0x00001000
42
BIT13 EQU 0x00002000
36
BIT13 EQU 0x00002000
43
BIT14 EQU 0x00004000
37
BIT14 EQU 0x00004000
44
BIT15 EQU 0x00008000
38
BIT15 EQU 0x00008000
45
BIT16 EQU 0x00010000
39
BIT16 EQU 0x00010000
46
BIT17 EQU 0x00020000
40
BIT17 EQU 0x00020000
47
BIT18 EQU 0x00040000
41
BIT18 EQU 0x00040000
48
BIT19 EQU 0x00080000
42
BIT19 EQU 0x00080000
49
BIT20 EQU 0x00100000
43
BIT20 EQU 0x00100000
50
BIT21 EQU 0x00200000
44
BIT21 EQU 0x00200000
51
BIT22 EQU 0x00400000
45
BIT22 EQU 0x00400000
52
BIT23 EQU 0x00800000
46
BIT23 EQU 0x00800000
53
BIT24 EQU 0x00100000
47
BIT24 EQU 0x00100000
54
BIT25 EQU 0x02000000
48
BIT25 EQU 0x02000000
55
BIT26 EQU 0x04000000
49
BIT26 EQU 0x04000000
56
BIT27 EQU 0x08000000
50
BIT27 EQU 0x08000000
57
BIT28 EQU 0x10000000
51
BIT28 EQU 0x10000000
58
BIT29 EQU 0x20000000
52
BIT29 EQU 0x20000000
59
BIT30 EQU 0x40000000
53
BIT30 EQU 0x40000000
60
BIT31 EQU 0x80000000
54
BIT31 EQU 0x80000000
61
 
55
 
62
VID_FM801         equ 0x1319
56
VID_FM801         equ 0x1319
63
CTRL_FM801        equ 0x0801
57
CTRL_FM801        equ 0x0801
64
 
58
 
65
FM_PCM_VOLUME         equ 0x00
59
FM_PCM_VOLUME         equ 0x00
66
FM_FM_VOLUME          equ 0x02
60
FM_FM_VOLUME          equ 0x02
67
FM_I2S_VOLUME         equ 0x04
61
FM_I2S_VOLUME         equ 0x04
68
FM_RECORD_SOURCE      equ 0x06
62
FM_RECORD_SOURCE      equ 0x06
69
 
63
 
70
FM_PLAY_CTL           equ 0x08
64
FM_PLAY_CTL           equ 0x08
71
FM_PLAY_RATE_MASK     equ 0x0f00
65
FM_PLAY_RATE_MASK     equ 0x0f00
72
FM_PLAY_BUF1_LAST     equ 0x0001
66
FM_PLAY_BUF1_LAST     equ 0x0001
73
FM_PLAY_BUF2_LAST     equ 0x0002
67
FM_PLAY_BUF2_LAST     equ 0x0002
74
FM_PLAY_START         equ 0x0020
68
FM_PLAY_START         equ 0x0020
75
FM_PLAY_PAUSE         equ 0x0040
69
FM_PLAY_PAUSE         equ 0x0040
76
FM_PLAY_STOPNOW       equ 0x0080
70
FM_PLAY_STOPNOW       equ 0x0080
77
FM_PLAY_16BIT         equ 0x4000
71
FM_PLAY_16BIT         equ 0x4000
78
FM_PLAY_STEREO        equ 0x8000
72
FM_PLAY_STEREO        equ 0x8000
79
 
73
 
80
FM_PLAY_DMALEN        equ 0x0a
74
FM_PLAY_DMALEN        equ 0x0a
81
FM_PLAY_DMABUF1       equ 0x0c
75
FM_PLAY_DMABUF1       equ 0x0c
82
FM_PLAY_DMABUF2       equ 0x10
76
FM_PLAY_DMABUF2       equ 0x10
83
 
77
 
84
FM_REC_CTL            equ 0x14
78
FM_REC_CTL            equ 0x14
85
FM_REC_RATE_MASK      equ 0x0f00
79
FM_REC_RATE_MASK      equ 0x0f00
86
FM_REC_BUF1_LAST      equ 0x0001
80
FM_REC_BUF1_LAST      equ 0x0001
87
FM_REC_BUF2_LAST      equ 0x0002
81
FM_REC_BUF2_LAST      equ 0x0002
88
FM_REC_START          equ 0x0020
82
FM_REC_START          equ 0x0020
89
FM_REC_PAUSE          equ 0x0040
83
FM_REC_PAUSE          equ 0x0040
90
FM_REC_STOPNOW        equ 0x0080
84
FM_REC_STOPNOW        equ 0x0080
91
FM_REC_16BIT          equ 0x4000
85
FM_REC_16BIT          equ 0x4000
92
FM_REC_STEREO         equ 0x8000
86
FM_REC_STEREO         equ 0x8000
93
 
87
 
94
FM_REC_DMALEN         equ 0x16
88
FM_REC_DMALEN         equ 0x16
95
FM_REC_DMABUF1        equ 0x18
89
FM_REC_DMABUF1        equ 0x18
96
FM_REC_DMABUF2        equ 0x1c
90
FM_REC_DMABUF2        equ 0x1c
97
 
91
 
98
FM_CODEC_CTL          equ 0x22
92
FM_CODEC_CTL          equ 0x22
99
FM_VOLUME             equ 0x26
93
FM_VOLUME             equ 0x26
100
FM_VOLUME_MUTE        equ 0x8000
94
FM_VOLUME_MUTE        equ 0x8000
101
 
95
 
102
FM_CODEC_CMD          equ 0x2a
96
FM_CODEC_CMD          equ 0x2a
103
FM_CODEC_CMD_READ     equ 0x0080
97
FM_CODEC_CMD_READ     equ 0x0080
104
FM_CODEC_CMD_VALID    equ 0x0100
98
FM_CODEC_CMD_VALID    equ 0x0100
105
FM_CODEC_CMD_BUSY     equ 0x0200
99
FM_CODEC_CMD_BUSY     equ 0x0200
106
 
100
 
107
FM_CODEC_DATA         equ 0x2c
101
FM_CODEC_DATA         equ 0x2c
108
 
102
 
109
FM_IO_CTL             equ 0x52
103
FM_IO_CTL             equ 0x52
110
FM_CARD_CTL           equ 0x54
104
FM_CARD_CTL           equ 0x54
111
 
105
 
112
FM_INTMASK            equ 0x56
106
FM_INTMASK            equ 0x56
113
FM_INTMASK_PLAY       equ 0x0001
107
FM_INTMASK_PLAY       equ 0x0001
114
FM_INTMASK_REC        equ 0x0002
108
FM_INTMASK_REC        equ 0x0002
115
FM_INTMASK_VOL        equ 0x0040
109
FM_INTMASK_VOL        equ 0x0040
116
FM_INTMASK_MPU        equ 0x0080
110
FM_INTMASK_MPU        equ 0x0080
117
 
111
 
118
FM_INTSTATUS          equ 0x5a
112
FM_INTSTATUS          equ 0x5a
119
FM_INTSTATUS_PLAY     equ 0x0100
113
FM_INTSTATUS_PLAY     equ 0x0100
120
FM_INTSTATUS_REC      equ 0x0200
114
FM_INTSTATUS_REC      equ 0x0200
121
FM_INTSTATUS_VOL      equ 0x4000
115
FM_INTSTATUS_VOL      equ 0x4000
122
FM_INTSTATUS_MPU      equ 0x8000
116
FM_INTSTATUS_MPU      equ 0x8000
123
 
117
 
124
CODEC_MASTER_VOL_REG         equ 0x02 ;
118
CODEC_MASTER_VOL_REG         equ 0x02 ;
125
CODEC_AUX_VOL                equ 0x04 ;
119
CODEC_AUX_VOL                equ 0x04 ;
126
CODEC_PCM_OUT_REG            equ 0x18 ; PCM output volume
120
CODEC_PCM_OUT_REG            equ 0x18 ; PCM output volume
127
CODEC_EXT_AUDIO_REG          equ 0x28 ; extended audio
121
CODEC_EXT_AUDIO_REG          equ 0x28 ; extended audio
128
CODEC_EXT_AUDIO_CTRL_REG     equ 0x2a ; extended audio control
122
CODEC_EXT_AUDIO_CTRL_REG     equ 0x2a ; extended audio control
129
CODEC_PCM_FRONT_DACRATE_REG  equ 0x2c ; PCM out sample rate
123
CODEC_PCM_FRONT_DACRATE_REG  equ 0x2c ; PCM out sample rate
130
CODEC_PCM_SURND_DACRATE_REG  equ 0x2e ; surround sound sample rate
124
CODEC_PCM_SURND_DACRATE_REG  equ 0x2e ; surround sound sample rate
131
CODEC_PCM_LFE_DACRATE_REG    equ 0x30 ; LFE sample rate
125
CODEC_PCM_LFE_DACRATE_REG    equ 0x30 ; LFE sample rate
132
 
126
 
133
SRV_GETVERSION        equ  0
127
SRV_GETVERSION        equ  0
134
DEV_PLAY              equ  1
128
DEV_PLAY              equ  1
135
DEV_STOP              equ  2
129
DEV_STOP              equ  2
136
DEV_CALLBACK          equ  3
130
DEV_CALLBACK          equ  3
137
DEV_SET_BUFF          equ  4
131
DEV_SET_BUFF          equ  4
138
DEV_NOTIFY            equ  5
132
DEV_NOTIFY            equ  5
139
DEV_SET_MASTERVOL     equ  6
133
DEV_SET_MASTERVOL     equ  6
140
DEV_GET_MASTERVOL     equ  7
134
DEV_GET_MASTERVOL     equ  7
141
DEV_GET_INFO          equ  8
135
DEV_GET_INFO          equ  8
142
 
136
 
143
struc AC_CNTRL    ;AC controller base class
137
struc AC_CNTRL    ;AC controller base class
144
{ .bus                dd ?
138
{ .bus                dd ?
145
  .devfn              dd ?
139
  .devfn              dd ?
146
 
140
 
147
  .vendor             dd ?
141
  .vendor             dd ?
148
  .dev_id             dd ?
142
  .dev_id             dd ?
149
  .pci_cmd            dd ?
143
  .pci_cmd            dd ?
150
  .pci_stat           dd ?
144
  .pci_stat           dd ?
151
 
145
 
152
  .codec_io_base      dd ?
146
  .codec_io_base      dd ?
153
  .codec_mem_base     dd ?
147
  .codec_mem_base     dd ?
154
 
148
 
155
  .ctrl_io_base       dd ?
149
  .ctrl_io_base       dd ?
156
  .ctrl_mem_base      dd ?
150
  .ctrl_mem_base      dd ?
157
  .cfg_reg            dd ?
151
  .cfg_reg            dd ?
158
  .int_line           dd ?
152
  .int_line           dd ?
159
 
153
 
160
  .vendor_ids         dd ?    ;vendor id string
154
  .vendor_ids         dd ?    ;vendor id string
161
  .ctrl_ids           dd ?    ;hub id string
155
  .ctrl_ids           dd ?    ;hub id string
162
 
156
 
163
  .buffer             dd ?
157
  .buffer             dd ?
164
 
158
 
165
  .notify_pos         dd ?
159
  .notify_pos         dd ?
166
  .notify_task        dd ?
160
  .notify_task        dd ?
167
 
161
 
168
  .lvi_reg            dd ?
162
  .lvi_reg            dd ?
169
  .ctrl_setup         dd ?
163
  .ctrl_setup         dd ?
170
  .user_callback      dd ?
164
  .user_callback      dd ?
171
  .codec_read16       dd ?
165
  .codec_read16       dd ?
172
  .codec_write16      dd ?
166
  .codec_write16      dd ?
173
 
167
 
174
  .ctrl_read8         dd ?
168
  .ctrl_read8         dd ?
175
  .ctrl_read16        dd ?
169
  .ctrl_read16        dd ?
176
  .ctrl_read32        dd ?
170
  .ctrl_read32        dd ?
177
 
171
 
178
  .ctrl_write8        dd ?
172
  .ctrl_write8        dd ?
179
  .ctrl_write16       dd ?
173
  .ctrl_write16       dd ?
180
  .ctrl_write32       dd ?
174
  .ctrl_write32       dd ?
181
}
175
}
182
 
176
 
183
struc CODEC   ;Audio Chip base class
177
struc CODEC   ;Audio Chip base class
184
{
178
{
185
  .chip_id            dd ?
179
  .chip_id            dd ?
186
  .flags              dd ?
180
  .flags              dd ?
187
  .status             dd ?
181
  .status             dd ?
188
 
182
 
189
  .ac_vendor_ids      dd ?    ;ac vendor id string
183
  .ac_vendor_ids      dd ?    ;ac vendor id string
190
  .chip_ids           dd ?    ;chip model string
184
  .chip_ids           dd ?    ;chip model string
191
 
185
 
192
  .shadow_flag        dd ?
186
  .shadow_flag        dd ?
193
                      dd ?
187
                      dd ?
194
 
188
 
195
  .regs               dw ?     ; codec registers
189
  .regs               dw ?     ; codec registers
196
  .reg_master_vol     dw ?     ;0x02
190
  .reg_master_vol     dw ?     ;0x02
197
  .reg_aux_out_vol    dw ?     ;0x04
191
  .reg_aux_out_vol    dw ?     ;0x04
198
  .reg_mone_vol       dw ?     ;0x06
192
  .reg_mone_vol       dw ?     ;0x06
199
  .reg_master_tone    dw ?     ;0x08
193
  .reg_master_tone    dw ?     ;0x08
200
  .reg_beep_vol       dw ?     ;0x0A
194
  .reg_beep_vol       dw ?     ;0x0A
201
  .reg_phone_vol      dw ?     ;0x0C
195
  .reg_phone_vol      dw ?     ;0x0C
202
  .reg_mic_vol        dw ?     ;0x0E
196
  .reg_mic_vol        dw ?     ;0x0E
203
  .reg_line_in_vol    dw ?     ;0x10
197
  .reg_line_in_vol    dw ?     ;0x10
204
  .reg_cd_vol         dw ?     ;0x12
198
  .reg_cd_vol         dw ?     ;0x12
205
  .reg_video_vol      dw ?     ;0x14
199
  .reg_video_vol      dw ?     ;0x14
206
  .reg_aux_in_vol     dw ?     ;0x16
200
  .reg_aux_in_vol     dw ?     ;0x16
207
  .reg_pcm_out_vol    dw ?     ;0x18
201
  .reg_pcm_out_vol    dw ?     ;0x18
208
  .reg_rec_select     dw ?     ;0x1A
202
  .reg_rec_select     dw ?     ;0x1A
209
  .reg_rec_gain       dw ?     ;0x1C
203
  .reg_rec_gain       dw ?     ;0x1C
210
  .reg_rec_gain_mic   dw ?     ;0x1E
204
  .reg_rec_gain_mic   dw ?     ;0x1E
211
  .reg_gen            dw ?     ;0x20
205
  .reg_gen            dw ?     ;0x20
212
  .reg_3d_ctrl        dw ?     ;0X22
206
  .reg_3d_ctrl        dw ?     ;0X22
213
  .reg_page           dw ?     ;0X24
207
  .reg_page           dw ?     ;0X24
214
  .reg_powerdown      dw ?     ;0x26
208
  .reg_powerdown      dw ?     ;0x26
215
  .reg_ext_audio      dw ?     ;0x28
209
  .reg_ext_audio      dw ?     ;0x28
216
  .reg_ext_st         dw ?     ;0x2a
210
  .reg_ext_st         dw ?     ;0x2a
217
  .reg_pcm_front_rate dw ?     ;0x2c
211
  .reg_pcm_front_rate dw ?     ;0x2c
218
  .reg_pcm_surr_rate  dw ?     ;0x2e
212
  .reg_pcm_surr_rate  dw ?     ;0x2e
219
  .reg_lfe_rate       dw ?     ;0x30
213
  .reg_lfe_rate       dw ?     ;0x30
220
  .reg_pcm_in_rate    dw ?     ;0x32
214
  .reg_pcm_in_rate    dw ?     ;0x32
221
                      dw ?     ;0x34
215
                      dw ?     ;0x34
222
  .reg_cent_lfe_vol   dw ?     ;0x36
216
  .reg_cent_lfe_vol   dw ?     ;0x36
223
  .reg_surr_vol       dw ?     ;0x38
217
  .reg_surr_vol       dw ?     ;0x38
224
  .reg_spdif_ctrl     dw ?     ;0x3A
218
  .reg_spdif_ctrl     dw ?     ;0x3A
225
                      dw ?     ;0x3C
219
                      dw ?     ;0x3C
226
                      dw ?     ;0x3E
220
                      dw ?     ;0x3E
227
                      dw ?     ;0x40
221
                      dw ?     ;0x40
228
                      dw ?     ;0x42
222
                      dw ?     ;0x42
229
                      dw ?     ;0x44
223
                      dw ?     ;0x44
230
                      dw ?     ;0x46
224
                      dw ?     ;0x46
231
                      dw ?     ;0x48
225
                      dw ?     ;0x48
232
                      dw ?     ;0x4A
226
                      dw ?     ;0x4A
233
                      dw ?     ;0x4C
227
                      dw ?     ;0x4C
234
                      dw ?     ;0x4E
228
                      dw ?     ;0x4E
235
                      dw ?     ;0x50
229
                      dw ?     ;0x50
236
                      dw ?     ;0x52
230
                      dw ?     ;0x52
237
                      dw ?     ;0x54
231
                      dw ?     ;0x54
238
                      dw ?     ;0x56
232
                      dw ?     ;0x56
239
                      dw ?     ;0x58
233
                      dw ?     ;0x58
240
                      dw ?     ;0x5A
234
                      dw ?     ;0x5A
241
                      dw ?     ;0x5C
235
                      dw ?     ;0x5C
242
                      dw ?     ;0x5E
236
                      dw ?     ;0x5E
243
  .reg_page_0         dw ?     ;0x60
237
  .reg_page_0         dw ?     ;0x60
244
  .reg_page_1         dw ?     ;0x62
238
  .reg_page_1         dw ?     ;0x62
245
  .reg_page_2         dw ?     ;0x64
239
  .reg_page_2         dw ?     ;0x64
246
  .reg_page_3         dw ?     ;0x66
240
  .reg_page_3         dw ?     ;0x66
247
  .reg_page_4         dw ?     ;0x68
241
  .reg_page_4         dw ?     ;0x68
248
  .reg_page_5         dw ?     ;0x6A
242
  .reg_page_5         dw ?     ;0x6A
249
  .reg_page_6         dw ?     ;0x6C
243
  .reg_page_6         dw ?     ;0x6C
250
  .reg_page_7         dw ?     ;0x6E
244
  .reg_page_7         dw ?     ;0x6E
251
                      dw ?     ;0x70
245
                      dw ?     ;0x70
252
                      dw ?     ;0x72
246
                      dw ?     ;0x72
253
                      dw ?     ;0x74
247
                      dw ?     ;0x74
254
                      dw ?     ;0x76
248
                      dw ?     ;0x76
255
                      dw ?     ;0x78
249
                      dw ?     ;0x78
256
                      dw ?     ;0x7A
250
                      dw ?     ;0x7A
257
  .reg_vendor_id_1    dw ?     ;0x7C
251
  .reg_vendor_id_1    dw ?     ;0x7C
258
  .reg_vendor_id_2    dw ?     ;0x7E
252
  .reg_vendor_id_2    dw ?     ;0x7E
259
 
253
 
260
 
254
 
261
  .reset              dd ?    ;virual
255
  .reset              dd ?    ;virual
262
  .set_master_vol     dd ?
256
  .set_master_vol     dd ?
263
}
257
}
264
 
258
 
265
struc CTRL_INFO
259
struc CTRL_INFO
266
{   .pci_cmd          dd ?
260
{   .pci_cmd          dd ?
267
    .irq              dd ?
261
    .irq              dd ?
268
    .glob_cntrl       dd ?
262
    .glob_cntrl       dd ?
269
    .glob_sta         dd ?
263
    .glob_sta         dd ?
270
    .codec_io_base    dd ?
264
    .codec_io_base    dd ?
271
    .ctrl_io_base     dd ?
265
    .ctrl_io_base     dd ?
272
    .codec_mem_base   dd ?
266
    .codec_mem_base   dd ?
273
    .ctrl_mem_base    dd ?
267
    .ctrl_mem_base    dd ?
274
    .codec_id         dd ?
268
    .codec_id         dd ?
275
}
269
}
276
 
270
 
277
EVENT_NOTIFY      equ 0x00000200
271
EVENT_NOTIFY      equ 0x00000200
278
 
272
 
279
section '.flat' code readable writable executable
273
section '.flat' code readable writable executable
280
include '../struct.inc'
274
include '../struct.inc'
281
include '../macros.inc'
275
include '../macros.inc'
282
include '../proc32.inc'
276
include '../proc32.inc'
283
include '../peimport.inc'
277
include '../peimport.inc'
284
 
278
 
285
proc START c uses ebx esi edi, state:dword, cmdline:dword
279
proc START c uses ebx esi edi, state:dword, cmdline:dword
286
 
280
 
287
        cmp     [state], 1
281
        cmp     [state], 1
288
        jne     .stop
282
        jne     .stop
289
 
283
 
290
     if DEBUG
284
     if DEBUG
291
        mov     eax, START
285
        mov     eax, START
292
        call    dword2str
286
        call    dword2str
293
        invoke  SysMsgBoardStr
287
        invoke  SysMsgBoardStr
294
        mov     esi, msgInit
288
        mov     esi, msgInit
295
        invoke  SysMsgBoardStr
289
        invoke  SysMsgBoardStr
296
     end if
290
     end if
297
 
291
 
298
        call    detect_controller
292
        call    detect_controller
299
        test    eax, eax
293
        test    eax, eax
300
        jz      .fail
294
        jz      .fail
301
 
295
 
302
     if DEBUG
296
     if DEBUG
303
        mov     esi, [ctrl.vendor_ids]
297
        mov     esi, [ctrl.vendor_ids]
304
        invoke  SysMsgBoardStr
298
        invoke  SysMsgBoardStr
305
        mov     esi, [ctrl.ctrl_ids]
299
        mov     esi, [ctrl.ctrl_ids]
306
        invoke  SysMsgBoardStr
300
        invoke  SysMsgBoardStr
307
 
301
 
308
     end if
302
     end if
309
 
303
 
310
        call    init_controller
304
        call    init_controller
311
        test    eax, eax
305
        test    eax, eax
312
        jz      .fail
306
        jz      .fail
313
 
307
 
314
        call    init_codec
308
        call    init_codec
315
        test    eax, eax
309
        test    eax, eax
316
        jz      .fail
310
        jz      .fail
317
 
311
 
318
        call    reset_controller
312
        call    reset_controller
319
        call    setup_codec
313
        call    setup_codec
320
 
314
 
321
        mov     esi, msgPrimBuff
315
        mov     esi, msgPrimBuff
322
        invoke  SysMsgBoardStr
316
        invoke  SysMsgBoardStr
323
        call    create_primary_buff
317
        call    create_primary_buff
324
 
318
 
325
        mov     esi, msgDone
319
        mov     esi, msgDone
326
        invoke  SysMsgBoardStr
320
        invoke  SysMsgBoardStr
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, dword 0
328
        invoke  AttachIntHandler, ebx, ac97_irq, dword 0
339
.reg:
329
.reg:
340
 
330
 
341
        invoke  RegService, sz_sound_srv, service_proc
331
        invoke  RegService, sz_sound_srv, service_proc
342
        ret
332
        ret
343
.fail:
333
.fail:
344
   if DEBUG
334
   if DEBUG
345
        mov     esi, msgFail
335
        mov     esi, msgFail
346
        invoke  SysMsgBoardStr
336
        invoke  SysMsgBoardStr
347
   end if
337
   end if
348
        xor     eax, eax
338
        xor     eax, eax
349
        ret
339
        ret
350
.fail_msg:
340
.fail_msg:
351
        invoke  SysMsgBoardStr
341
        invoke  SysMsgBoardStr
352
        xor     eax, eax
342
        xor     eax, eax
353
        ret
343
        ret
354
.stop:
344
.stop:
355
        call    stop
345
        call    stop
356
        xor     eax, eax
346
        xor     eax, eax
357
        ret
347
        ret
358
endp
348
endp
359
 
349
 
360
handle     equ  IOCTL.handle
350
handle     equ  IOCTL.handle
361
io_code    equ  IOCTL.io_code
351
io_code    equ  IOCTL.io_code
362
input      equ  IOCTL.input
352
input      equ  IOCTL.input
363
inp_size   equ  IOCTL.inp_size
353
inp_size   equ  IOCTL.inp_size
364
output     equ  IOCTL.output
354
output     equ  IOCTL.output
365
out_size   equ  IOCTL.out_size
355
out_size   equ  IOCTL.out_size
366
 
356
 
367
align 4
357
align 4
368
proc service_proc stdcall, ioctl:dword
358
proc service_proc stdcall, ioctl:dword
369
 
359
 
370
        mov     edi, [ioctl]
360
        mov     edi, [ioctl]
371
        mov     eax, [edi+io_code]
361
        mov     eax, [edi+io_code]
372
 
362
 
373
        cmp     eax, SRV_GETVERSION
363
        cmp     eax, SRV_GETVERSION
374
        jne     @F
364
        jne     @F
375
 
365
 
376
        mov     eax, [edi+output]
366
        mov     eax, [edi+output]
377
        cmp     [edi+out_size], 4
367
        cmp     [edi+out_size], 4
378
        jne     .fail
368
        jne     .fail
379
 
369
 
380
        mov     [eax], dword API_VERSION
370
        mov     [eax], dword API_VERSION
381
        xor     eax, eax
371
        xor     eax, eax
382
        ret
372
        ret
383
@@:
373
@@:
384
        cmp     eax, DEV_PLAY
374
        cmp     eax, DEV_PLAY
385
        jne     @F
375
        jne     @F
386
     if DEBUG
376
     if DEBUG
387
        mov     esi, msgPlay
377
        mov     esi, msgPlay
388
        invoke  SysMsgBoardStr
378
        invoke  SysMsgBoardStr
389
     end if
379
     end if
390
        call    play
380
        call    play
391
        ret
381
        ret
392
@@:
382
@@:
393
        cmp     eax, DEV_STOP
383
        cmp     eax, DEV_STOP
394
        jne     @F
384
        jne     @F
395
     if DEBUG
385
     if DEBUG
396
        mov     esi, msgStop
386
        mov     esi, msgStop
397
        invoke  SysMsgBoardStr
387
        invoke  SysMsgBoardStr
398
     end if
388
     end if
399
        call    stop
389
        call    stop
400
        ret
390
        ret
401
@@:
391
@@:
402
        cmp     eax, DEV_CALLBACK
392
        cmp     eax, DEV_CALLBACK
403
        jne     @F
393
        jne     @F
404
        mov     ebx, [edi+input]
394
        mov     ebx, [edi+input]
405
        stdcall set_callback, [ebx]
395
        stdcall set_callback, [ebx]
406
        ret
396
        ret
407
@@:
397
@@:
408
        cmp     eax, DEV_SET_MASTERVOL
398
        cmp     eax, DEV_SET_MASTERVOL
409
        jne     @F
399
        jne     @F
410
        mov     eax, [edi+input]
400
        mov     eax, [edi+input]
411
        mov     eax, [eax]
401
        mov     eax, [eax]
412
        call    set_master_vol      ;eax= vol
402
        call    set_master_vol      ;eax= vol
413
        ret
403
        ret
414
@@:
404
@@:
415
        cmp     eax, DEV_GET_MASTERVOL
405
        cmp     eax, DEV_GET_MASTERVOL
416
        jne     @F
406
        jne     @F
417
        mov     ebx, [edi+output]
407
        mov     ebx, [edi+output]
418
        stdcall get_master_vol, ebx
408
        stdcall get_master_vol, ebx
419
        ret
409
        ret
420
;@@:
410
;@@:
421
;           cmp eax, DEV_GET_INFO
411
;           cmp eax, DEV_GET_INFO
422
;           jne @F
412
;           jne @F
423
;           mov ebx, [edi+output]
413
;           mov ebx, [edi+output]
424
;           stdcall get_dev_info, ebx
414
;           stdcall get_dev_info, ebx
425
;           ret
415
;           ret
426
@@:
416
@@:
427
.fail:
417
.fail:
428
        or      eax, -1
418
        or      eax, -1
429
        ret
419
        ret
430
endp
420
endp
431
 
421
 
432
restore   handle
422
restore   handle
433
restore   io_code
423
restore   io_code
434
restore   input
424
restore   input
435
restore   inp_size
425
restore   inp_size
436
restore   output
426
restore   output
437
restore   out_size
427
restore   out_size
438
 
428
 
439
align 4
429
align 4
440
proc fill_buffer
430
proc fill_buffer
441
 
431
 
442
        cmp     [ctrl.user_callback], 0
432
        cmp     [ctrl.user_callback], 0
443
        je      .exit
433
        je      .exit
444
 
434
 
445
        mov     esi, [ctrl.buffer]
435
        mov     esi, [ctrl.buffer]
446
        mov     eax, int_flip_flop
436
        mov     eax, int_flip_flop
447
        inc     dword [eax]
437
        inc     dword [eax]
448
        test    dword [eax], 1
438
        test    dword [eax], 1
449
        je      @f
439
        je      @f
450
        add     esi, 0x4000
440
        add     esi, 0x4000
451
@@:
441
@@:
452
        stdcall [ctrl.user_callback], esi
442
        stdcall [ctrl.user_callback], esi
453
 
443
 
454
        mov     edx, FM_PLAY_DMABUF1
444
        mov     edx, FM_PLAY_DMABUF1
455
        mov     eax, [buffer_pgaddr]
445
        mov     eax, [buffer_pgaddr]
456
        mov     esi, int_flip_flop
446
        mov     esi, int_flip_flop
457
        test    dword [esi], 1
447
        test    dword [esi], 1
458
        je      @f
448
        je      @f
459
        mov     edx, FM_PLAY_DMABUF2
449
        mov     edx, FM_PLAY_DMABUF2
460
        add     eax, 0x4000
450
        add     eax, 0x4000
461
@@:
451
@@:
462
        call    [ctrl.ctrl_write32]
452
        call    [ctrl.ctrl_write32]
463
 
453
 
464
.exit:
454
.exit:
465
        ret
455
        ret
466
endp
456
endp
467
 
457
 
468
align 4
458
align 4
469
proc ac97_irq
459
proc ac97_irq
470
 
460
 
471
     if DEBUG_IRQ
461
     if DEBUG_IRQ
472
        mov     esi, msgIRQ
462
        mov     esi, msgIRQ
473
        invoke  SysMsgBoardStr
463
        invoke  SysMsgBoardStr
474
     end if
464
     end if
475
 
465
 
476
        mov     edx, FM_INTSTATUS
466
        mov     edx, FM_INTSTATUS
477
        call    [ctrl.ctrl_read16]
467
        call    [ctrl.ctrl_read16]
478
 
468
 
479
        test    eax, FM_INTSTATUS_PLAY
469
        test    eax, FM_INTSTATUS_PLAY
480
        je      .exit
470
        je      .exit
481
 
471
 
482
        push    eax
472
        push    eax
483
        call    fill_buffer
473
        call    fill_buffer
484
        pop     eax
474
        pop     eax
485
 
475
 
486
.exit:
476
.exit:
487
        mov     edx, FM_INTSTATUS
477
        mov     edx, FM_INTSTATUS
488
        call    [ctrl.ctrl_write16]
478
        call    [ctrl.ctrl_write16]
489
 
479
 
490
        ret
480
        ret
491
endp
481
endp
492
 
482
 
493
align 4
483
align 4
494
proc create_primary_buff
484
proc create_primary_buff
495
 
485
 
496
        invoke  KernelAlloc, 0x10000
486
        invoke  KernelAlloc, 0x10000
497
        mov     [ctrl.buffer], eax
487
        mov     [ctrl.buffer], eax
498
 
488
 
499
        mov     edi, eax
489
        mov     edi, eax
500
        mov     ecx, 0x10000/4
490
        mov     ecx, 0x10000/4
501
        xor     eax, eax
491
        xor     eax, eax
502
        cld
492
        cld
503
        rep stosd
493
        rep stosd
504
 
494
 
505
        mov     eax, [ctrl.buffer]
495
        mov     eax, [ctrl.buffer]
506
        invoke  GetPgAddr
496
        invoke  GetPgAddr
507
        mov     [buffer_pgaddr], eax
497
        mov     [buffer_pgaddr], eax
508
 
498
 
509
        ret
499
        ret
510
endp
500
endp
511
 
501
 
512
align 4
502
align 4
513
proc detect_controller
503
proc detect_controller
514
           locals
504
           locals
515
             last_bus dd ?
505
             last_bus dd ?
516
             bus      dd ?
506
             bus      dd ?
517
             devfn    dd ?
507
             devfn    dd ?
518
           endl
508
           endl
519
 
509
 
520
        xor     eax, eax
510
        xor     eax, eax
521
        mov     [bus], eax
511
        mov     [bus], eax
522
        inc     eax
512
        inc     eax
523
        invoke  PciApi
513
        invoke  PciApi
524
        cmp     eax, -1
514
        cmp     eax, -1
525
        je      .err
515
        je      .err
526
 
516
 
527
        mov     [last_bus], eax
517
        mov     [last_bus], eax
528
 
518
 
529
.next_bus:
519
.next_bus:
530
        and     [devfn], 0
520
        and     [devfn], 0
531
.next_dev:
521
.next_dev:
532
        invoke  PciRead32, [bus], [devfn], dword 0
522
        invoke  PciRead32, [bus], [devfn], dword 0
533
        test    eax, eax
523
        test    eax, eax
534
        jz      .next
524
        jz      .next
535
        cmp     eax, -1
525
        cmp     eax, -1
536
        je      .next
526
        je      .next
537
 
527
 
538
        push    eax
528
        push    eax
539
        invoke  PciRead32, [bus], [devfn], dword 0x09
529
        invoke  PciRead32, [bus], [devfn], dword 0x09
540
        and     eax, 0xffffff
530
        and     eax, 0xffffff
541
        cmp     eax, 0x060100 ;pci-isa
531
        cmp     eax, 0x060100 ;pci-isa
542
        jne     .no_bridge
532
        jne     .no_bridge
543
 
533
 
544
        mov     eax, [bus]
534
        mov     eax, [bus]
545
        mov     [brg_bus], eax
535
        mov     [brg_bus], eax
546
        mov     eax, [devfn]
536
        mov     eax, [devfn]
547
        mov     [brg_devfn], eax
537
        mov     [brg_devfn], eax
548
.no_bridge:
538
.no_bridge:
549
        pop     eax
539
        pop     eax
550
 
540
 
551
        mov     edi, devices
541
        mov     edi, devices
552
@@:
542
@@:
553
        mov     ebx, [edi]
543
        mov     ebx, [edi]
554
        test    ebx, ebx
544
        test    ebx, ebx
555
        jz      .next
545
        jz      .next
556
 
546
 
557
        cmp     eax, ebx
547
        cmp     eax, ebx
558
        je      .found
548
        je      .found
559
        add     edi, 12
549
        add     edi, 12
560
        jmp     @B
550
        jmp     @B
561
.next:
551
.next:
562
        inc     [devfn]
552
        inc     [devfn]
563
        cmp     [devfn], 256
553
        cmp     [devfn], 256
564
        jb      .next_dev
554
        jb      .next_dev
565
        mov     eax, [bus]
555
        mov     eax, [bus]
566
        inc     eax
556
        inc     eax
567
        mov     [bus], eax
557
        mov     [bus], eax
568
        cmp     eax, [last_bus]
558
        cmp     eax, [last_bus]
569
        jna     .next_bus
559
        jna     .next_bus
570
        xor     eax, eax
560
        xor     eax, eax
571
        ret
561
        ret
572
.found:
562
.found:
573
        mov     ebx, [bus]
563
        mov     ebx, [bus]
574
        mov     [ctrl.bus], ebx
564
        mov     [ctrl.bus], ebx
575
 
565
 
576
        mov     ecx, [devfn]
566
        mov     ecx, [devfn]
577
        mov     [ctrl.devfn], ecx
567
        mov     [ctrl.devfn], ecx
578
 
568
 
579
        mov     edx, eax
569
        mov     edx, eax
580
        and     edx, 0xFFFF
570
        and     edx, 0xFFFF
581
        mov     [ctrl.vendor], edx
571
        mov     [ctrl.vendor], edx
582
        shr     eax, 16
572
        shr     eax, 16
583
        mov     [ctrl.dev_id], eax
573
        mov     [ctrl.dev_id], eax
584
 
574
 
585
        mov     ebx, [edi+4]
575
        mov     ebx, [edi+4]
586
        mov     [ctrl.ctrl_ids], ebx
576
        mov     [ctrl.ctrl_ids], ebx
587
        mov     [ctrl.vendor_ids], msg_FM
577
        mov     [ctrl.vendor_ids], msg_FM
588
 
578
 
589
        mov     esi, [edi+8]
579
        mov     esi, [edi+8]
590
        mov     [ctrl.ctrl_setup], esi
580
        mov     [ctrl.ctrl_setup], esi
591
        ret
581
        ret
592
.err:
582
.err:
593
        xor     eax, eax
583
        xor     eax, eax
594
        ret
584
        ret
595
endp
585
endp
596
 
586
 
597
align 4
587
align 4
598
proc init_controller
588
proc init_controller
599
 
589
 
600
        invoke  PciRead32, [ctrl.bus], [ctrl.devfn], 4
590
        invoke  PciRead32, [ctrl.bus], [ctrl.devfn], 4
601
        mov     ebx, eax
591
        mov     ebx, eax
602
        and     eax, 0xFFFF
592
        and     eax, 0xFFFF
603
        mov     [ctrl.pci_cmd], eax
593
        mov     [ctrl.pci_cmd], eax
604
        shr     ebx, 16
594
        shr     ebx, 16
605
        mov     [ctrl.pci_stat], ebx
595
        mov     [ctrl.pci_stat], ebx
606
 
596
 
607
        mov     esi, msgPciCmd
597
        mov     esi, msgPciCmd
608
        invoke  SysMsgBoardStr
598
        invoke  SysMsgBoardStr
609
        call    dword2str
599
        call    dword2str
610
        invoke  SysMsgBoardStr
600
        invoke  SysMsgBoardStr
611
 
601
 
612
        mov     esi, msgPciStat
602
        mov     esi, msgPciStat
613
        invoke  SysMsgBoardStr
603
        invoke  SysMsgBoardStr
614
        mov     eax, [ctrl.pci_stat]
604
        mov     eax, [ctrl.pci_stat]
615
        call    dword2str
605
        call    dword2str
616
        invoke  SysMsgBoardStr
606
        invoke  SysMsgBoardStr
617
 
607
 
618
        mov     esi, msgCtrlIsaIo
608
        mov     esi, msgCtrlIsaIo
619
        invoke  SysMsgBoardStr
609
        invoke  SysMsgBoardStr
620
 
610
 
621
        invoke  PciRead32, [ctrl.bus], [ctrl.devfn], 0x10
611
        invoke  PciRead32, [ctrl.bus], [ctrl.devfn], 0x10
622
 
612
 
623
        call    dword2str
613
        call    dword2str
624
        invoke  SysMsgBoardStr
614
        invoke  SysMsgBoardStr
625
 
615
 
626
        and     eax, 0xFFFE
616
        and     eax, 0xFFFE
627
        mov     [ctrl.ctrl_io_base], eax
617
        mov     [ctrl.ctrl_io_base], eax
628
 
618
 
629
        mov     esi, msgIrqNum
619
        mov     esi, msgIrqNum
630
        invoke  SysMsgBoardStr
620
        invoke  SysMsgBoardStr
631
 
621
 
632
        invoke  PciRead32, [ctrl.bus], [ctrl.devfn], 0x3C
622
        invoke  PciRead32, [ctrl.bus], [ctrl.devfn], 0x3C
633
        and     eax, 0xFF
623
        and     eax, 0xFF
634
        mov     [ctrl.int_line], eax
624
        mov     [ctrl.int_line], eax
635
 
625
 
636
        call    dword2str
626
        call    dword2str
637
        invoke  SysMsgBoardStr
627
        invoke  SysMsgBoardStr
638
 
628
 
639
        call    [ctrl.ctrl_setup]
629
        call    [ctrl.ctrl_setup]
640
        xor     eax, eax
630
        xor     eax, eax
641
        inc     eax
631
        inc     eax
642
        ret
632
        ret
643
endp
633
endp
644
 
634
 
645
align 4
635
align 4
646
proc set_FM
636
proc set_FM
647
        mov     [ctrl.codec_read16], codec_io_r16    ;virtual
637
        mov     [ctrl.codec_read16], codec_io_r16    ;virtual
648
        mov     [ctrl.codec_write16], codec_io_w16   ;virtual
638
        mov     [ctrl.codec_write16], codec_io_w16   ;virtual
649
 
639
 
650
        mov     [ctrl.ctrl_read8 ], ctrl_io_r8      ;virtual
640
        mov     [ctrl.ctrl_read8 ], ctrl_io_r8      ;virtual
651
        mov     [ctrl.ctrl_read16], ctrl_io_r16      ;virtual
641
        mov     [ctrl.ctrl_read16], ctrl_io_r16      ;virtual
652
        mov     [ctrl.ctrl_read32], ctrl_io_r32      ;virtual
642
        mov     [ctrl.ctrl_read32], ctrl_io_r32      ;virtual
653
 
643
 
654
        mov     [ctrl.ctrl_write8 ], ctrl_io_w8     ;virtual
644
        mov     [ctrl.ctrl_write8 ], ctrl_io_w8     ;virtual
655
        mov     [ctrl.ctrl_write16], ctrl_io_w16     ;virtual
645
        mov     [ctrl.ctrl_write16], ctrl_io_w16     ;virtual
656
        mov     [ctrl.ctrl_write32], ctrl_io_w32     ;virtual
646
        mov     [ctrl.ctrl_write32], ctrl_io_w32     ;virtual
657
        ret
647
        ret
658
endp
648
endp
659
 
649
 
660
align 4
650
align 4
661
proc reset_controller
651
proc reset_controller
662
 
652
 
663
        mov     esi, msgInitCtrl
653
        mov     esi, msgInitCtrl
664
        invoke  SysMsgBoardStr
654
        invoke  SysMsgBoardStr
665
 
655
 
666
        mov     edx, FM_CARD_CTL
656
        mov     edx, FM_CARD_CTL
667
        call    [ctrl.ctrl_read8]
657
        call    [ctrl.ctrl_read8]
668
        push    eax
658
        push    eax
669
        or      al, 1
659
        or      al, 1
670
        mov     edx, FM_CARD_CTL
660
        mov     edx, FM_CARD_CTL
671
        call    [ctrl.ctrl_write8]
661
        call    [ctrl.ctrl_write8]
672
        mov     eax, 10
662
        mov     eax, 10
673
        call    StallExec
663
        call    StallExec
674
        pop     eax
664
        pop     eax
675
        and     al, 0xFE
665
        and     al, 0xFE
676
        mov     edx, FM_CARD_CTL
666
        mov     edx, FM_CARD_CTL
677
        call    [ctrl.ctrl_write8]
667
        call    [ctrl.ctrl_write8]
678
        mov     eax, 10
668
        mov     eax, 10
679
        call    StallExec
669
        call    StallExec
680
 
670
 
681
        mov     eax, 0x0404
671
        mov     eax, 0x0404
682
        mov     edx, FM_PCM_VOLUME
672
        mov     edx, FM_PCM_VOLUME
683
        call    [ctrl.ctrl_write16]
673
        call    [ctrl.ctrl_write16]
684
        mov     edx, FM_FM_VOLUME
674
        mov     edx, FM_FM_VOLUME
685
        call    [ctrl.ctrl_write16]
675
        call    [ctrl.ctrl_write16]
686
        mov     edx, FM_I2S_VOLUME
676
        mov     edx, FM_I2S_VOLUME
687
        call    [ctrl.ctrl_write16]
677
        call    [ctrl.ctrl_write16]
688
 
678
 
689
        mov     edx, FM_INTMASK
679
        mov     edx, FM_INTMASK
690
        call    [ctrl.ctrl_read16]
680
        call    [ctrl.ctrl_read16]
691
        and     eax, not FM_INTMASK_PLAY
681
        and     eax, not FM_INTMASK_PLAY
692
        or      eax, FM_INTMASK_REC or FM_INTMASK_MPU or FM_INTMASK_VOL
682
        or      eax, FM_INTMASK_REC or FM_INTMASK_MPU or FM_INTMASK_VOL
693
        mov     edx, FM_INTMASK
683
        mov     edx, FM_INTMASK
694
        call    [ctrl.ctrl_write16]
684
        call    [ctrl.ctrl_write16]
695
 
685
 
696
        mov     eax, FM_INTMASK_PLAY or FM_INTMASK_REC or FM_INTMASK_MPU or FM_INTMASK_VOL
686
        mov     eax, FM_INTMASK_PLAY or FM_INTMASK_REC or FM_INTMASK_MPU or FM_INTMASK_VOL
697
        mov     edx, FM_INTSTATUS
687
        mov     edx, FM_INTSTATUS
698
        call    [ctrl.ctrl_write16]
688
        call    [ctrl.ctrl_write16]
699
 
689
 
700
        ret
690
        ret
701
endp
691
endp
702
 
692
 
703
align 4
693
align 4
704
proc init_codec
694
proc init_codec
705
 
695
 
706
        mov     esi, msgInitCodec
696
        mov     esi, msgInitCodec
707
        invoke  SysMsgBoardStr
697
        invoke  SysMsgBoardStr
708
 
698
 
709
        mov     al, FM_CODEC_CMD_READ
699
        mov     al, FM_CODEC_CMD_READ
710
        mov     edx, FM_CODEC_CMD
700
        mov     edx, FM_CODEC_CMD
711
        call    [ctrl.ctrl_write8]
701
        call    [ctrl.ctrl_write8]
712
 
702
 
713
        call    reset_codec
703
        call    reset_codec
714
 
704
 
715
        call    detect_codec
705
        call    detect_codec
716
 
706
 
717
        xor     eax, eax
707
        xor     eax, eax
718
        inc     eax
708
        inc     eax
719
        ret
709
        ret
720
endp
710
endp
721
 
711
 
722
align 4
712
align 4
723
proc reset_codec
713
proc reset_codec
724
 
714
 
725
        mov     ecx, 255
715
        mov     ecx, 255
726
.L1:
716
.L1:
727
        mov     edx, FM_CODEC_CMD
717
        mov     edx, FM_CODEC_CMD
728
        call    [ctrl.ctrl_read16]
718
        call    [ctrl.ctrl_read16]
729
        test    ah, FM_CODEC_CMD_VALID shr 8
719
        test    ah, FM_CODEC_CMD_VALID shr 8
730
        jne     .L2
720
        jne     .L2
731
        loop    .L1
721
        loop    .L1
732
.L2:
722
.L2:
733
        mov     edx, FM_CODEC_CTL
723
        mov     edx, FM_CODEC_CTL
734
        call    [ctrl.ctrl_read8]
724
        call    [ctrl.ctrl_read8]
735
        push    eax
725
        push    eax
736
        or      al, 0x20
726
        or      al, 0x20
737
        mov     edx, FM_CODEC_CTL
727
        mov     edx, FM_CODEC_CTL
738
        call    [ctrl.ctrl_write8]
728
        call    [ctrl.ctrl_write8]
739
        pop     eax
729
        pop     eax
740
        and     al, 0xDF
730
        and     al, 0xDF
741
        mov     edx, FM_CODEC_CTL
731
        mov     edx, FM_CODEC_CTL
742
        call    [ctrl.ctrl_write8]
732
        call    [ctrl.ctrl_write8]
743
 
733
 
744
        xor     eax, eax
734
        xor     eax, eax
745
        inc     eax
735
        inc     eax
746
        ret
736
        ret
747
endp
737
endp
748
 
738
 
749
align 4
739
align 4
750
play:
740
play:
751
        mov     eax, 0x4000-1
741
        mov     eax, 0x4000-1
752
        mov     edx, FM_PLAY_DMALEN
742
        mov     edx, FM_PLAY_DMALEN
753
        call    [ctrl.ctrl_write16]
743
        call    [ctrl.ctrl_write16]
754
 
744
 
755
        call    fill_buffer
745
        call    fill_buffer
756
 
746
 
757
        mov     eax, FM_PLAY_START or FM_PLAY_STOPNOW or FM_PLAY_STEREO or FM_PLAY_16BIT or 0xA00
747
        mov     eax, FM_PLAY_START or FM_PLAY_STOPNOW or FM_PLAY_STEREO or FM_PLAY_16BIT or 0xA00
758
        mov     edx, FM_PLAY_CTL
748
        mov     edx, FM_PLAY_CTL
759
        call    [ctrl.ctrl_write16]
749
        call    [ctrl.ctrl_write16]
760
 
750
 
761
        xor     eax, eax
751
        xor     eax, eax
762
        ret
752
        ret
763
 
753
 
764
align 4
754
align 4
765
stop:
755
stop:
766
        mov     edx, FM_PLAY_CTL
756
        mov     edx, FM_PLAY_CTL
767
        call    [ctrl.ctrl_read16]
757
        call    [ctrl.ctrl_read16]
768
        and     eax, not (FM_PLAY_START or FM_PLAY_STOPNOW)
758
        and     eax, not (FM_PLAY_START or FM_PLAY_STOPNOW)
769
        or      eax, FM_PLAY_BUF1_LAST or FM_PLAY_BUF2_LAST
759
        or      eax, FM_PLAY_BUF1_LAST or FM_PLAY_BUF2_LAST
770
        mov     edx, FM_PLAY_CTL
760
        mov     edx, FM_PLAY_CTL
771
        call    [ctrl.ctrl_write16]
761
        call    [ctrl.ctrl_write16]
772
 
762
 
773
        xor     eax, eax
763
        xor     eax, eax
774
        ret
764
        ret
775
 
765
 
776
align 4
766
align 4
777
proc get_dev_info stdcall, p_info:dword
767
proc get_dev_info stdcall, p_info:dword
778
           virtual at esi
768
           virtual at esi
779
             CTRL_INFO CTRL_INFO
769
             CTRL_INFO CTRL_INFO
780
           end virtual
770
           end virtual
781
 
771
 
782
        mov     esi, [p_info]
772
        mov     esi, [p_info]
783
        mov     eax, [ctrl.int_line]
773
        mov     eax, [ctrl.int_line]
784
        mov     ebx, [ctrl.codec_io_base]
774
        mov     ebx, [ctrl.codec_io_base]
785
        mov     ecx, [ctrl.ctrl_io_base]
775
        mov     ecx, [ctrl.ctrl_io_base]
786
        mov     edx, [ctrl.codec_mem_base]
776
        mov     edx, [ctrl.codec_mem_base]
787
        mov     edi, [ctrl.ctrl_mem_base]
777
        mov     edi, [ctrl.ctrl_mem_base]
788
 
778
 
789
        mov     [CTRL_INFO.irq], eax
779
        mov     [CTRL_INFO.irq], eax
790
        mov     [CTRL_INFO.codec_io_base], ebx
780
        mov     [CTRL_INFO.codec_io_base], ebx
791
        mov     [CTRL_INFO.ctrl_io_base], ecx
781
        mov     [CTRL_INFO.ctrl_io_base], ecx
792
        mov     [CTRL_INFO.codec_mem_base], edx
782
        mov     [CTRL_INFO.codec_mem_base], edx
793
        mov     [CTRL_INFO.ctrl_mem_base], edi
783
        mov     [CTRL_INFO.ctrl_mem_base], edi
794
 
784
 
795
        mov     eax, [codec.chip_id]
785
        mov     eax, [codec.chip_id]
796
        mov     [CTRL_INFO.codec_id], eax
786
        mov     [CTRL_INFO.codec_id], eax
797
 
787
 
798
        mov     ebx, [ctrl.pci_cmd]
788
        mov     ebx, [ctrl.pci_cmd]
799
        mov     [CTRL_INFO.pci_cmd], ebx
789
        mov     [CTRL_INFO.pci_cmd], ebx
800
        ret
790
        ret
801
endp
791
endp
802
 
792
 
803
align 4
793
align 4
804
proc set_callback stdcall, handler:dword
794
proc set_callback stdcall, handler:dword
805
        mov     eax, [handler]
795
        mov     eax, [handler]
806
        mov     [ctrl.user_callback], eax
796
        mov     [ctrl.user_callback], eax
807
        ret
797
        ret
808
endp
798
endp
809
 
799
 
810
align 4
800
align 4
811
proc codec_read stdcall, ac_reg:dword   ; reg = edx, reval = eax
801
proc codec_read stdcall, ac_reg:dword   ; reg = edx, reval = eax
812
 
802
 
813
        mov     edx, [ac_reg]
803
        mov     edx, [ac_reg]
814
 
804
 
815
        mov     ebx, edx
805
        mov     ebx, edx
816
        shr     ebx, 1
806
        shr     ebx, 1
817
        bt      [codec.shadow_flag], ebx
807
        bt      [codec.shadow_flag], ebx
818
        jc      .use_shadow
808
        jc      .use_shadow
819
 
809
 
820
        call    [ctrl.codec_read16]  ;change edx !!!
810
        call    [ctrl.codec_read16]  ;change edx !!!
821
        mov     ecx, eax
811
        mov     ecx, eax
822
 
812
 
823
.read_ok:
813
.read_ok:
824
        mov     edx, [ac_reg]
814
        mov     edx, [ac_reg]
825
        mov     [codec.regs+edx], cx
815
        mov     [codec.regs+edx], cx
826
        bts     [codec.shadow_flag], ebx
816
        bts     [codec.shadow_flag], ebx
827
        mov     eax, ecx
817
        mov     eax, ecx
828
        ret
818
        ret
829
.use_shadow:
819
.use_shadow:
830
        movzx   eax, word [codec.regs+edx]
820
        movzx   eax, word [codec.regs+edx]
831
        ret
821
        ret
832
 
822
 
833
endp
823
endp
834
 
824
 
835
align 4
825
align 4
836
proc codec_write stdcall, ac_reg:dword
826
proc codec_write stdcall, ac_reg:dword
837
 
827
 
838
        mov     esi, [ac_reg]
828
        mov     esi, [ac_reg]
839
 
829
 
840
        mov     edx, esi
830
        mov     edx, esi
841
 
831
 
842
        call    [ctrl.codec_write16]
832
        call    [ctrl.codec_write16]
843
 
833
 
844
        mov     [codec.regs+esi], ax
834
        mov     [codec.regs+esi], ax
845
        shr     esi, 1
835
        shr     esi, 1
846
        bts     [codec.shadow_flag], esi
836
        bts     [codec.shadow_flag], esi
847
 
837
 
848
        ret
838
        ret
849
endp
839
endp
850
 
840
 
851
align 4
841
align 4
852
proc check_semafore
842
proc check_semafore
853
align 4
843
align 4
854
.ok:
844
.ok:
855
        xor     eax, eax
845
        xor     eax, eax
856
        inc     eax
846
        inc     eax
857
        ret
847
        ret
858
endp
848
endp
859
 
849
 
860
align 4
850
align 4
861
proc StallExec
851
proc StallExec
862
        push    ecx
852
        push    ecx
863
        push    edx
853
        push    edx
864
        push    ebx
854
        push    ebx
865
        push    eax
855
        push    eax
866
 
856
 
867
        mov     ecx, CPU_FREQ
857
        mov     ecx, CPU_FREQ
868
        mul     ecx
858
        mul     ecx
869
        mov     ebx, eax      ;low
859
        mov     ebx, eax      ;low
870
        mov     ecx, edx      ;high
860
        mov     ecx, edx      ;high
871
        rdtsc
861
        rdtsc
872
        add     ebx, eax
862
        add     ebx, eax
873
        adc     ecx, edx
863
        adc     ecx, edx
874
@@:
864
@@:
875
        rdtsc
865
        rdtsc
876
        sub     eax, ebx
866
        sub     eax, ebx
877
        sbb     edx, ecx
867
        sbb     edx, ecx
878
        js      @B
868
        js      @B
879
 
869
 
880
        pop     eax
870
        pop     eax
881
        pop     ebx
871
        pop     ebx
882
        pop     edx
872
        pop     edx
883
        pop     ecx
873
        pop     ecx
884
        ret
874
        ret
885
endp
875
endp
886
 
876
 
887
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
877
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
888
;          CONTROLLER IO functions
878
;          CONTROLLER IO functions
889
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
879
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
890
 
880
 
891
align 4
881
align 4
892
proc codec_io_r16
882
proc codec_io_r16
893
 
883
 
894
        push    edx
884
        push    edx
895
        mov     ecx, 255
885
        mov     ecx, 255
896
.L1:
886
.L1:
897
        mov     edx, FM_CODEC_CMD
887
        mov     edx, FM_CODEC_CMD
898
        call    [ctrl.ctrl_read16]
888
        call    [ctrl.ctrl_read16]
899
        test    ah, FM_CODEC_CMD_BUSY shr 8
889
        test    ah, FM_CODEC_CMD_BUSY shr 8
900
        je      .L2
890
        je      .L2
901
        loop    .L1
891
        loop    .L1
902
.L2:
892
.L2:
903
        pop     eax
893
        pop     eax
904
        or      al, FM_CODEC_CMD_READ
894
        or      al, FM_CODEC_CMD_READ
905
        mov     edx, FM_CODEC_CMD
895
        mov     edx, FM_CODEC_CMD
906
        call    [ctrl.ctrl_write8]
896
        call    [ctrl.ctrl_write8]
907
 
897
 
908
        mov     ecx, 255
898
        mov     ecx, 255
909
.L3:
899
.L3:
910
        mov     edx, FM_CODEC_CMD
900
        mov     edx, FM_CODEC_CMD
911
        call    [ctrl.ctrl_read16]
901
        call    [ctrl.ctrl_read16]
912
        test    ah, FM_CODEC_CMD_VALID shr 8
902
        test    ah, FM_CODEC_CMD_VALID shr 8
913
        jne     .L4
903
        jne     .L4
914
        loop    .L3
904
        loop    .L3
915
.L4:
905
.L4:
916
        mov     edx, FM_CODEC_DATA
906
        mov     edx, FM_CODEC_DATA
917
        call    [ctrl.ctrl_read16]
907
        call    [ctrl.ctrl_read16]
918
 
908
 
919
        ret
909
        ret
920
endp
910
endp
921
 
911
 
922
align 4
912
align 4
923
proc codec_io_w16
913
proc codec_io_w16
924
 
914
 
925
        push    edx
915
        push    edx
926
        push    eax
916
        push    eax
927
        mov     ecx, 255
917
        mov     ecx, 255
928
.L1:
918
.L1:
929
        mov     edx, FM_CODEC_CMD
919
        mov     edx, FM_CODEC_CMD
930
        call    [ctrl.ctrl_read16]
920
        call    [ctrl.ctrl_read16]
931
        test    ah, FM_CODEC_CMD_BUSY shr 8
921
        test    ah, FM_CODEC_CMD_BUSY shr 8
932
        je      .L2
922
        je      .L2
933
        loop    .L1
923
        loop    .L1
934
.L2:
924
.L2:
935
        pop     eax
925
        pop     eax
936
        mov     edx, FM_CODEC_DATA
926
        mov     edx, FM_CODEC_DATA
937
        call    [ctrl.ctrl_write16]
927
        call    [ctrl.ctrl_write16]
938
 
928
 
939
        pop     eax
929
        pop     eax
940
        mov     edx, FM_CODEC_CMD
930
        mov     edx, FM_CODEC_CMD
941
        call    [ctrl.ctrl_write16]
931
        call    [ctrl.ctrl_write16]
942
 
932
 
943
        ret
933
        ret
944
endp
934
endp
945
 
935
 
946
align 4
936
align 4
947
proc ctrl_io_r8
937
proc ctrl_io_r8
948
        add     edx, [ctrl.ctrl_io_base]
938
        add     edx, [ctrl.ctrl_io_base]
949
        in      al, dx
939
        in      al, dx
950
        ret
940
        ret
951
endp
941
endp
952
 
942
 
953
align 4
943
align 4
954
proc ctrl_io_r16
944
proc ctrl_io_r16
955
        add     edx, [ctrl.ctrl_io_base]
945
        add     edx, [ctrl.ctrl_io_base]
956
        in      ax, dx
946
        in      ax, dx
957
        ret
947
        ret
958
endp
948
endp
959
 
949
 
960
align 4
950
align 4
961
proc ctrl_io_r32
951
proc ctrl_io_r32
962
        add     edx, [ctrl.ctrl_io_base]
952
        add     edx, [ctrl.ctrl_io_base]
963
        in      eax, dx
953
        in      eax, dx
964
        ret
954
        ret
965
endp
955
endp
966
 
956
 
967
align 4
957
align 4
968
proc ctrl_io_w8
958
proc ctrl_io_w8
969
        add     edx, [ctrl.ctrl_io_base]
959
        add     edx, [ctrl.ctrl_io_base]
970
        out     dx, al
960
        out     dx, al
971
        ret
961
        ret
972
endp
962
endp
973
 
963
 
974
align 4
964
align 4
975
proc ctrl_io_w16
965
proc ctrl_io_w16
976
        add     edx, [ctrl.ctrl_io_base]
966
        add     edx, [ctrl.ctrl_io_base]
977
        out     dx, ax
967
        out     dx, ax
978
        ret
968
        ret
979
endp
969
endp
980
 
970
 
981
align 4
971
align 4
982
proc ctrl_io_w32
972
proc ctrl_io_w32
983
        add     edx, [ctrl.ctrl_io_base]
973
        add     edx, [ctrl.ctrl_io_base]
984
        out     dx, eax
974
        out     dx, eax
985
        ret
975
        ret
986
endp
976
endp
987
 
977
 
988
align 4
978
align 4
989
dword2str:
979
dword2str:
990
        mov     esi, hex_buff
980
        mov     esi, hex_buff
991
        mov     ecx, -8
981
        mov     ecx, -8
992
@@:
982
@@:
993
        rol     eax, 4
983
        rol     eax, 4
994
        mov     ebx, eax
984
        mov     ebx, eax
995
        and     ebx, 0x0F
985
        and     ebx, 0x0F
996
        mov     bl, [ebx+hexletters]
986
        mov     bl, [ebx+hexletters]
997
        mov     [8+esi+ecx], bl
987
        mov     [8+esi+ecx], bl
998
        inc     ecx
988
        inc     ecx
999
        jnz     @B
989
        jnz     @B
1000
        ret
990
        ret
1001
 
991
 
1002
hexletters   db '0123456789ABCDEF'
992
hexletters   db '0123456789ABCDEF'
1003
hex_buff     db 8 dup(0),13,10,0
993
hex_buff     db 8 dup(0),13,10,0
1004
brg_bus      dd ?
994
brg_bus      dd ?
1005
brg_devfn    dd ?
995
brg_devfn    dd ?
1006
include "codec.inc"
996
include "codec.inc"
1007
 
997
 
1008
align 4
998
align 4
1009
devices dd (CTRL_FM801 shl 16)+VID_FM801, msg_FM801, set_FM
999
devices dd (CTRL_FM801 shl 16)+VID_FM801, msg_FM801, set_FM
1010
        dd 0
1000
        dd 0
1011
 
1001
 
1012
msg_FM801    db 'FM801 AC97 controller',13,10, 0
1002
msg_FM801    db 'FM801 AC97 controller',13,10, 0
1013
msg_FM       db 'Forte Media',13,10, 0
1003
msg_FM       db 'Forte Media',13,10, 0
1014
 
1004
 
1015
sz_sound_srv db 'SOUND',0
1005
sz_sound_srv db 'SOUND',0
1016
 
1006
 
1017
msgInit       db 'detect hardware...',13,10,0
1007
msgInit       db 'detect hardware...',13,10,0
1018
msgFail       db 'device not found',13,10,0
1008
msgFail       db 'device not found',13,10,0
1019
msgAttchIRQ   db 'IRQ line not supported', 13,10, 0
-
 
1020
msgInvIRQ     db 'IRQ line not assigned or invalid', 13,10, 0
1009
msgInvIRQ     db 'IRQ line not assigned or invalid', 13,10, 0
1021
msgPlay       db 'start play', 13,10,0
1010
msgPlay       db 'start play', 13,10,0
1022
msgStop       db 'stop play',  13,10,0
1011
msgStop       db 'stop play',  13,10,0
1023
;msgNotify    db 'call notify',13,10,0
1012
;msgNotify    db 'call notify',13,10,0
1024
msgIRQ        db 'AC97 IRQ', 13,10,0
1013
msgIRQ        db 'AC97 IRQ', 13,10,0
1025
msgInitCtrl  db 'init controller',13,10,0
1014
msgInitCtrl  db 'init controller',13,10,0
1026
msgInitCodec db 'init codec',13,10,0
1015
msgInitCodec db 'init codec',13,10,0
1027
msgPrimBuff   db 'create primary buffer ...',0
1016
msgPrimBuff   db 'create primary buffer ...',0
1028
msgDone       db 'done',13,10,0
1017
msgDone       db 'done',13,10,0
1029
;msgReg       db 'set service handler',13,10,0
1018
;msgReg       db 'set service handler',13,10,0
1030
;msgOk        db 'service installed',13,10,0
1019
;msgOk        db 'service installed',13,10,0
1031
;msgStatus    db 'global status   ',0
1020
;msgStatus    db 'global status   ',0
1032
;msgControl   db 'global control  ',0
1021
;msgControl   db 'global control  ',0
1033
msgPciCmd     db 'PCI command     ',0
1022
msgPciCmd     db 'PCI command     ',0
1034
msgPciStat    db 'PCI status      ',0
1023
msgPciStat    db 'PCI status      ',0
1035
msgCtrlIsaIo  db 'controller io base   ',0
1024
msgCtrlIsaIo  db 'controller io base   ',0
1036
msgIrqNum     db 'IRQ default          ',0
1025
msgIrqNum     db 'IRQ default          ',0
1037
;msgIrqMap    db 'AC97 irq map as      ',0
1026
;msgIrqMap    db 'AC97 irq map as      ',0
1038
 
1027
 
1039
align 4
1028
align 4
1040
data fixups
1029
data fixups
1041
end data
1030
end data
1042
 
1031
 
1043
codec CODEC
1032
codec CODEC
1044
ctrl AC_CNTRL
1033
ctrl AC_CNTRL
1045
 
1034
 
1046
int_flip_flop      rd 1
1035
int_flip_flop      rd 1
1047
buffer_pgaddr      rd 1
1036
buffer_pgaddr      rd 1