Rev 8054 | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
2288 | clevermous | 1 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
2 | ;; ;; |
||
10051 | ace_dent | 3 | ;; Copyright (C) KolibriOS team 2004-2024. All rights reserved. ;; |
2288 | clevermous | 4 | ;; Distributed under terms of the GNU General Public License ;; |
5 | ;; ;; |
||
6 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
||
7 | |||
8 | |||
4700 | mario79 | 9 | ;----------------------------------------------------------------------------- |
2288 | clevermous | 10 | ;********************************************************** |
8054 | rgimad | 11 | ; Direct work with CD (ATAPI) device |
2288 | clevermous | 12 | ;********************************************************** |
8053 | rgimad | 13 | ; Author of a part of the source code - Kulakov Vladimir Gennadievich |
14 | ; Adaptation, revision and development - Mario79, |
||
2288 | clevermous | 15 | |
8053 | rgimad | 16 | ; Maximum number of repeats of a read operation |
7136 | dunkaist | 17 | MaxRetr = 10 |
8053 | rgimad | 18 | ; Maximum waiting time for ready to receive a command |
19 | ; (in ticks) |
||
7136 | dunkaist | 20 | BSYWaitTime = 1000 ;2 |
21 | NoTickWaitTime = 0xfffff |
||
22 | CDBlockSize = 2048 |
||
2288 | clevermous | 23 | ;******************************************** |
8054 | rgimad | 24 | ;* READING SECTOR WITH REPEATS * |
25 | ;* Repeated reads on failures * |
||
2288 | clevermous | 26 | ;******************************************** |
27 | ReadCDWRetr: |
||
28 | ;----------------------------------------------------------- |
||
29 | ; input : eax = block to read |
||
30 | ; ebx = destination |
||
31 | ;----------------------------------------------------------- |
||
32 | pushad |
||
33 | mov eax, [CDSectorAddress] |
||
34 | mov ebx, [CDDataBuf_pointer] |
||
35 | call cd_calculate_cache |
||
36 | xor edi, edi |
||
37 | add esi, 8 |
||
38 | inc edi |
||
4700 | mario79 | 39 | ;-------------------------------------- |
40 | align 4 |
||
2288 | clevermous | 41 | .hdreadcache: |
42 | cmp [esi], eax ; correct sector |
||
43 | je .yeshdcache |
||
4700 | mario79 | 44 | |
2288 | clevermous | 45 | add esi, 8 |
46 | inc edi |
||
47 | dec ecx |
||
48 | jnz .hdreadcache |
||
4700 | mario79 | 49 | |
2288 | clevermous | 50 | call find_empty_slot_CD_cache ; ret in edi |
51 | |||
52 | push edi |
||
53 | push eax |
||
54 | call cd_calculate_cache_2 |
||
55 | shl edi, 11 |
||
56 | add edi, eax |
||
57 | mov [CDDataBuf_pointer], edi |
||
58 | pop eax |
||
59 | pop edi |
||
60 | |||
61 | call ReadCDWRetr_1 |
||
62 | cmp [DevErrorCode], 0 |
||
63 | jne .exit |
||
64 | |||
65 | mov [CDDataBuf_pointer], ebx |
||
66 | call cd_calculate_cache_1 |
||
67 | lea esi, [edi*8+esi] |
||
68 | mov [esi], eax ; sector number |
||
4700 | mario79 | 69 | ;-------------------------------------- |
2288 | clevermous | 70 | .yeshdcache: |
71 | mov esi, edi |
||
4700 | mario79 | 72 | shl esi, 11 ;9 |
2288 | clevermous | 73 | push eax |
74 | call cd_calculate_cache_2 |
||
75 | add esi, eax |
||
76 | pop eax |
||
4700 | mario79 | 77 | mov edi, ebx ;[CDDataBuf_pointer] |
78 | mov ecx, 512 ;/4 |
||
2288 | clevermous | 79 | cld |
80 | rep movsd ; move data |
||
4700 | mario79 | 81 | ;-------------------------------------- |
2288 | clevermous | 82 | .exit: |
83 | popad |
||
84 | ret |
||
4700 | mario79 | 85 | ;----------------------------------------------------------------------------- |
2288 | clevermous | 86 | ReadCDWRetr_1: |
87 | pushad |
||
8054 | rgimad | 88 | ; Loop until the command is successful or the number of attempts is over |
4700 | mario79 | 89 | mov ecx, MaxRetr |
90 | ;-------------------------------------- |
||
91 | align 4 |
||
2288 | clevermous | 92 | @@NextRetr: |
8054 | rgimad | 93 | ; Send a command |
2288 | clevermous | 94 | ;************************************************* |
8054 | rgimad | 95 | ;* FULL READ OF COMPACT DISK SECTOR * |
96 | ;* User data, subchannel * |
||
97 | ;* information and control information are read * |
||
98 | ;* Input parameters are passed through global * |
||
99 | ;* variables: * |
||
100 | ;* ChannelNumber - channel number; * |
||
101 | ;* DiskNumber - disc number on channel; * |
||
102 | ;* CDSectorAddress - address of reading sector. * |
||
103 | ;* The data is read into the CDDataBuf array. * |
||
2288 | clevermous | 104 | ;************************************************* |
105 | ;ReadCD: |
||
106 | push ecx |
||
8054 | rgimad | 107 | ; Flush the packet command buffer |
2288 | clevermous | 108 | call clear_packet_buffer |
8054 | rgimad | 109 | ; Generate a packet command to read a data sector |
110 | ; Set the command code Read CD |
||
4700 | mario79 | 111 | mov [PacketCommand], byte 0x28 ;0xBE |
8054 | rgimad | 112 | ; Set the sector address |
4700 | mario79 | 113 | mov ax, word [CDSectorAddress+2] |
114 | xchg al, ah |
||
115 | mov word [PacketCommand+2], ax |
||
116 | mov ax, word [CDSectorAddress] |
||
117 | xchg al, ah |
||
118 | mov word [PacketCommand+4], ax |
||
8054 | rgimad | 119 | ; Set the number of sectors to read |
2288 | clevermous | 120 | mov [PacketCommand+8], byte 1 |
8054 | rgimad | 121 | ; Send a command |
2288 | clevermous | 122 | call SendPacketDatCommand |
123 | pop ecx |
||
124 | |||
125 | test eax, eax |
||
126 | jz @@End_4 |
||
127 | |||
128 | or ecx, ecx ;{SPraid.simba} (for cd load) |
||
129 | jz @@End_4 |
||
4700 | mario79 | 130 | |
2288 | clevermous | 131 | dec ecx |
132 | |||
133 | cmp [timer_ticks_enable], 0 |
||
134 | jne @f |
||
4700 | mario79 | 135 | |
2288 | clevermous | 136 | mov eax, NoTickWaitTime |
4700 | mario79 | 137 | ;-------------------------------------- |
138 | align 4 |
||
2288 | clevermous | 139 | .wait: |
140 | dec eax |
||
141 | jz @@NextRetr |
||
4700 | mario79 | 142 | |
2288 | clevermous | 143 | jmp .wait |
4700 | mario79 | 144 | ;-------------------------------------- |
145 | align 4 |
||
2288 | clevermous | 146 | @@: |
147 | loop @@NextRetr |
||
4700 | mario79 | 148 | ;-------------------------------------- |
2288 | clevermous | 149 | @@End_4: |
150 | mov dword [DevErrorCode], eax |
||
151 | popad |
||
152 | ret |
||
4700 | mario79 | 153 | ;----------------------------------------------------------------------------- |
8054 | rgimad | 154 | ; General purpose procedures to execute packet commands in PIO Mode |
155 | ; Maximum allowable waiting time for the device to respond to a packet command (in ticks) |
||
4700 | mario79 | 156 | ;----------------------------------------------------------------------------- |
8054 | rgimad | 157 | MaxCDWaitTime = 1000 ;200 ;10 seconds |
2288 | clevermous | 158 | uglobal |
8054 | rgimad | 159 | ; Memory area for generating a packet command |
2288 | clevermous | 160 | PacketCommand: |
161 | rb 12 ;DB 12 DUP (?) |
||
8054 | rgimad | 162 | ; address of reading data sector |
4700 | mario79 | 163 | CDSectorAddress: dd ? |
8054 | rgimad | 164 | ; Start time of the next disk operation |
4700 | mario79 | 165 | TickCounter_1 dd 0 |
8054 | rgimad | 166 | ; Time to start waiting for device readiness |
4700 | mario79 | 167 | WURStartTime dd 0 |
8054 | rgimad | 168 | ; pointer to buffer to read data into |
2288 | clevermous | 169 | CDDataBuf_pointer dd 0 |
170 | endg |
||
4700 | mario79 | 171 | ;----------------------------------------------------------------------------- |
2288 | clevermous | 172 | ;**************************************************** |
8054 | rgimad | 173 | ;* SEND TO ATAPI DEVICE PACKET COMMAND, * |
174 | ;* THAT MEANS TRASMIT ONE DATA SECTOR OF SIZE * |
||
175 | ;* 2048 BYTE FROM DEVICE TO HOST * |
||
176 | ;* Input parameters are passed through global * |
||
177 | ;* variables: * |
||
178 | ;* ChannelNumber - channel number; * |
||
179 | ;* DiskNumber - disk number on channel. * |
||
180 | ;* PacketCommand - 12-byte command packet; * |
||
181 | ;* CDBlockSize - size of receiving data block. * |
||
2288 | clevermous | 182 | ; return eax DevErrorCode |
183 | ;**************************************************** |
||
184 | SendPacketDatCommand: |
||
185 | xor eax, eax |
||
8054 | rgimad | 186 | ; Set CHS mode |
2288 | clevermous | 187 | mov byte [ATAAddressMode], al |
8054 | rgimad | 188 | ; Send ATA command to send packet command |
2288 | clevermous | 189 | mov byte [ATAFeatures], al |
190 | mov byte [ATASectorCount], al |
||
191 | mov byte [ATASectorNumber], al |
||
8054 | rgimad | 192 | ; Load the size of the sending block |
2288 | clevermous | 193 | mov [ATAHead], al |
194 | mov [ATACylinder], CDBlockSize |
||
4700 | mario79 | 195 | mov [ATACommand], 0xA0 |
2288 | clevermous | 196 | call SendCommandToHDD_1 |
197 | test eax, eax |
||
8054 | rgimad | 198 | jnz @@End_8 ; finish, saving the error code |
199 | ; Waiting for the drive to be ready to receive a packet command |
||
4700 | mario79 | 200 | mov dx, [ATABasePortAddr] |
8054 | rgimad | 201 | add dx, 7 ; port 1x7h |
2288 | clevermous | 202 | mov ecx, NoTickWaitTime |
4700 | mario79 | 203 | ;-------------------------------------- |
204 | align 4 |
||
2288 | clevermous | 205 | @@WaitDevice0: |
206 | cmp [timer_ticks_enable], 0 |
||
207 | jne @f |
||
4700 | mario79 | 208 | |
2288 | clevermous | 209 | dec ecx |
210 | jz @@Err1_1 |
||
4700 | mario79 | 211 | |
2288 | clevermous | 212 | jmp .test |
4700 | mario79 | 213 | ;-------------------------------------- |
214 | align 4 |
||
2288 | clevermous | 215 | @@: |
216 | call change_task |
||
8054 | rgimad | 217 | ; Check command execution time |
4700 | mario79 | 218 | mov eax, [timer_ticks] |
219 | sub eax, [TickCounter_1] |
||
220 | cmp eax, BSYWaitTime |
||
8054 | rgimad | 221 | ja @@Err1_1 ; time out error |
222 | ; Check readiness |
||
4700 | mario79 | 223 | ;-------------------------------------- |
224 | align 4 |
||
2288 | clevermous | 225 | .test: |
4700 | mario79 | 226 | in al, dx |
8054 | rgimad | 227 | test al, 0x80 ; BSY signal state |
2288 | clevermous | 228 | jnz @@WaitDevice0 |
4700 | mario79 | 229 | |
8054 | rgimad | 230 | test al, 1 ; ERR signal state |
2288 | clevermous | 231 | jnz @@Err6 |
4700 | mario79 | 232 | |
8054 | rgimad | 233 | test al, 0x8 ; DRQ signal state |
2288 | clevermous | 234 | jz @@WaitDevice0 |
8054 | rgimad | 235 | ; Send a packet command |
2288 | clevermous | 236 | cli |
4700 | mario79 | 237 | mov dx, [ATABasePortAddr] |
238 | mov ax, [PacketCommand] |
||
239 | out dx, ax |
||
240 | mov ax, [PacketCommand+2] |
||
241 | out dx, ax |
||
242 | mov ax, [PacketCommand+4] |
||
243 | out dx, ax |
||
244 | mov ax, [PacketCommand+6] |
||
245 | out dx, ax |
||
246 | mov ax, [PacketCommand+8] |
||
247 | out dx, ax |
||
248 | mov ax, [PacketCommand+10] |
||
249 | out dx, ax |
||
2288 | clevermous | 250 | sti |
8054 | rgimad | 251 | ; Waiting for data to be ready |
4700 | mario79 | 252 | mov dx, [ATABasePortAddr] |
8054 | rgimad | 253 | add dx, 7 ; port 1x7h |
2288 | clevermous | 254 | mov ecx, NoTickWaitTime |
4700 | mario79 | 255 | ;-------------------------------------- |
256 | align 4 |
||
2288 | clevermous | 257 | @@WaitDevice1: |
258 | cmp [timer_ticks_enable], 0 |
||
259 | jne @f |
||
4700 | mario79 | 260 | |
2288 | clevermous | 261 | dec ecx |
262 | jz @@Err1_1 |
||
4700 | mario79 | 263 | |
2288 | clevermous | 264 | jmp .test_1 |
4700 | mario79 | 265 | ;-------------------------------------- |
266 | align 4 |
||
2288 | clevermous | 267 | @@: |
268 | call change_task |
||
8054 | rgimad | 269 | ; Check command execution time |
4700 | mario79 | 270 | mov eax, [timer_ticks] |
271 | sub eax, [TickCounter_1] |
||
272 | cmp eax, MaxCDWaitTime |
||
8054 | rgimad | 273 | ja @@Err1_1 ; time out error |
274 | ; Check readiness |
||
4700 | mario79 | 275 | ;-------------------------------------- |
276 | align 4 |
||
2288 | clevermous | 277 | .test_1: |
4700 | mario79 | 278 | in al, dx |
8054 | rgimad | 279 | test al, 0x80 ; BSY signal state |
2288 | clevermous | 280 | jnz @@WaitDevice1 |
4700 | mario79 | 281 | |
8054 | rgimad | 282 | test al, 1 ; ERR signal state |
2288 | clevermous | 283 | jnz @@Err6_temp |
4700 | mario79 | 284 | |
8054 | rgimad | 285 | test al, 0x8 ; DRQ signal state |
2288 | clevermous | 286 | jz @@WaitDevice1 |
8054 | rgimad | 287 | ; Receive data block from controller |
4700 | mario79 | 288 | mov edi, [CDDataBuf_pointer] |
8054 | rgimad | 289 | ; Load controller's data register address |
4700 | mario79 | 290 | mov dx, [ATABasePortAddr] |
8054 | rgimad | 291 | ; Load the block size in bytes into the counter |
2288 | clevermous | 292 | xor ecx, ecx |
4700 | mario79 | 293 | mov cx, CDBlockSize |
8054 | rgimad | 294 | ; Calculate block size in 16-bit words |
295 | shr cx, 1 ; divide block size by 2 |
||
296 | ; Receive data block |
||
2288 | clevermous | 297 | cli |
298 | cld |
||
299 | rep insw |
||
300 | sti |
||
4700 | mario79 | 301 | ;-------------------------------------- |
8054 | rgimad | 302 | ; Successful completion of data receive |
2288 | clevermous | 303 | @@End_8: |
304 | xor eax, eax |
||
305 | ret |
||
4700 | mario79 | 306 | ;-------------------------------------- |
8054 | rgimad | 307 | ; Write error code |
2288 | clevermous | 308 | @@Err1_1: |
309 | xor eax, eax |
||
310 | inc eax |
||
311 | ret |
||
4700 | mario79 | 312 | ;-------------------------------------- |
2288 | clevermous | 313 | @@Err6_temp: |
314 | mov eax, 7 |
||
315 | ret |
||
4700 | mario79 | 316 | ;-------------------------------------- |
2288 | clevermous | 317 | @@Err6: |
318 | mov eax, 6 |
||
319 | ret |
||
4700 | mario79 | 320 | ;----------------------------------------------------------------------------- |
2288 | clevermous | 321 | ;*********************************************** |
8054 | rgimad | 322 | ;* SEND TO ATAPI DEVICE PACKET COMMAND, * |
323 | ;* THAT DOESNT MEAN TRANSMIT DATA * |
||
324 | ;* Input parameters are passed through global * |
||
325 | ;* variables: * |
||
326 | ;* ChannelNumber - channel number; * |
||
327 | ;* DiskNumber - disk number on channel. * |
||
328 | ;* PacketCommand - 12-byte command packet. * |
||
2288 | clevermous | 329 | ;*********************************************** |
330 | SendPacketNoDatCommand: |
||
331 | pushad |
||
332 | xor eax, eax |
||
8054 | rgimad | 333 | ; Set CHS mode |
2288 | clevermous | 334 | mov byte [ATAAddressMode], al |
8054 | rgimad | 335 | ; Send ATA command to send packet command |
2288 | clevermous | 336 | mov byte [ATAFeatures], al |
337 | mov byte [ATASectorCount], al |
||
338 | mov byte [ATASectorNumber], al |
||
339 | mov word [ATACylinder], ax |
||
340 | mov byte [ATAHead], al |
||
4700 | mario79 | 341 | mov [ATACommand], 0xA0 |
2288 | clevermous | 342 | call SendCommandToHDD_1 |
343 | test eax, eax |
||
8054 | rgimad | 344 | jnz @@End_9 ; finish, saving the error code |
345 | ; Waiting for the drive to be ready to receive a packet command |
||
4700 | mario79 | 346 | mov dx, [ATABasePortAddr] |
8054 | rgimad | 347 | add dx, 7 ; port 1x7h |
4700 | mario79 | 348 | ;-------------------------------------- |
349 | align 4 |
||
2288 | clevermous | 350 | @@WaitDevice0_1: |
351 | call change_task |
||
8054 | rgimad | 352 | ; Check waiting time |
4700 | mario79 | 353 | mov eax, [timer_ticks] |
354 | sub eax, [TickCounter_1] |
||
355 | cmp eax, BSYWaitTime |
||
8054 | rgimad | 356 | ja @@Err1_3 ; time out error |
357 | ; Check readiness |
||
4700 | mario79 | 358 | in al, dx |
8054 | rgimad | 359 | test al, 0x80 ; BSY signal state |
2288 | clevermous | 360 | jnz @@WaitDevice0_1 |
4700 | mario79 | 361 | |
8054 | rgimad | 362 | test al, 1 ; ERR signal state |
2288 | clevermous | 363 | jnz @@Err6_1 |
4700 | mario79 | 364 | |
8054 | rgimad | 365 | test al, 0x8 ; DRQ signal state |
2288 | clevermous | 366 | jz @@WaitDevice0_1 |
8054 | rgimad | 367 | ; Send packet command |
2288 | clevermous | 368 | ; cli |
4700 | mario79 | 369 | mov dx, [ATABasePortAddr] |
370 | mov ax, word [PacketCommand] |
||
371 | out dx, ax |
||
372 | mov ax, word [PacketCommand+2] |
||
373 | out dx, ax |
||
374 | mov ax, word [PacketCommand+4] |
||
375 | out dx, ax |
||
376 | mov ax, word [PacketCommand+6] |
||
377 | out dx, ax |
||
378 | mov ax, word [PacketCommand+8] |
||
379 | out dx, ax |
||
380 | mov ax, word [PacketCommand+10] |
||
381 | out dx, ax |
||
2288 | clevermous | 382 | ; sti |
383 | cmp [ignore_CD_eject_wait], 1 |
||
384 | je @@clear_DEC |
||
8054 | rgimad | 385 | ; Waiting for confirmation of command receive |
4700 | mario79 | 386 | mov dx, [ATABasePortAddr] |
8054 | rgimad | 387 | add dx, 7 ; port 1x7h |
4700 | mario79 | 388 | ;-------------------------------------- |
389 | align 4 |
||
2288 | clevermous | 390 | @@WaitDevice1_1: |
391 | call change_task |
||
8054 | rgimad | 392 | ; Check command execution time |
4700 | mario79 | 393 | mov eax, [timer_ticks] |
394 | sub eax, [TickCounter_1] |
||
395 | cmp eax, MaxCDWaitTime |
||
8054 | rgimad | 396 | ja @@Err1_3 ; time out error |
397 | ; Wait for device release |
||
4700 | mario79 | 398 | in al, dx |
8054 | rgimad | 399 | test al, 0x80 ; BSY signal state |
2288 | clevermous | 400 | jnz @@WaitDevice1_1 |
4700 | mario79 | 401 | |
8054 | rgimad | 402 | test al, 1 ; ERR signal state |
2288 | clevermous | 403 | jnz @@Err6_1 |
4700 | mario79 | 404 | |
8054 | rgimad | 405 | test al, 0x40 ; DRDY signal state |
2288 | clevermous | 406 | jz @@WaitDevice1_1 |
4700 | mario79 | 407 | ;-------------------------------------- |
2288 | clevermous | 408 | @@clear_DEC: |
409 | and [DevErrorCode], 0 |
||
410 | popad |
||
411 | ret |
||
4700 | mario79 | 412 | ;-------------------------------------- |
8054 | rgimad | 413 | ; Write error code |
2288 | clevermous | 414 | @@Err1_3: |
415 | xor eax, eax |
||
416 | inc eax |
||
417 | jmp @@End_9 |
||
4700 | mario79 | 418 | ;-------------------------------------- |
2288 | clevermous | 419 | @@Err6_1: |
420 | mov eax, 6 |
||
4700 | mario79 | 421 | ;-------------------------------------- |
2288 | clevermous | 422 | @@End_9: |
423 | mov [DevErrorCode], eax |
||
424 | popad |
||
425 | ret |
||
4700 | mario79 | 426 | ;----------------------------------------------------------------------------- |
2288 | clevermous | 427 | ;**************************************************** |
8054 | rgimad | 428 | ;* SEND COMMAND TO GIVEN DISK * |
429 | ;* Input parameters are passed through the global * |
||
430 | ;* variables: * |
||
431 | ;* ChannelNumber - channel number (1 or 2); * |
||
432 | ;* DiskNumber - disk number (0 or 1); * |
||
433 | ;* ATAFeatures - "features"; * |
||
434 | ;* ATASectorCount - sector count; * |
||
435 | ;* ATASectorNumber - initial sector number; * |
||
436 | ;* ATACylinder - initial cylinder number; * |
||
437 | ;* ATAHead - initial head number; * |
||
438 | ;* ATAAddressMode - addressing mode (0-CHS, 1-LBA); * |
||
439 | ;* ATACommand - command code. * |
||
440 | ;* If the function finished successfully: * |
||
441 | ;* in ATABasePortAddr - base address of HDD; * |
||
442 | ;* in DevErrorCode - zero. * |
||
443 | ;* If error has occured then in DevErrorCode will * |
||
444 | ;* be the error code. * |
||
2288 | clevermous | 445 | ;**************************************************** |
446 | SendCommandToHDD_1: |
||
8054 | rgimad | 447 | ; Check the addressing mode code |
2288 | clevermous | 448 | cmp [ATAAddressMode], 1 |
449 | ja @@Err2_4 |
||
8054 | rgimad | 450 | ; Check the channel number correctness |
6464 | pathoswith | 451 | movzx ebx, [ChannelNumber] |
452 | dec ebx |
||
453 | cmp ebx, 1 |
||
2288 | clevermous | 454 | ja @@Err3_4 |
8054 | rgimad | 455 | ; Set the base address |
4700 | mario79 | 456 | shl ebx, 2 |
457 | mov eax, [cdpos] |
||
458 | dec eax |
||
459 | shr eax, 2 |
||
460 | imul eax, sizeof.IDE_DATA |
||
461 | add eax, IDE_controller_1 |
||
462 | add eax, ebx |
||
463 | mov ax, [eax+IDE_DATA.BAR0_val] |
||
464 | mov [ATABasePortAddr], ax |
||
8054 | rgimad | 465 | ; Waiting for HDD ready to receive a command |
466 | ; Choose desired disk |
||
4700 | mario79 | 467 | mov dx, [ATABasePortAddr] |
8054 | rgimad | 468 | add dx, 6 ; address of the heads register |
4700 | mario79 | 469 | mov al, [DiskNumber] |
8054 | rgimad | 470 | cmp al, 1 ; check the disk number |
2288 | clevermous | 471 | ja @@Err4_4 |
4700 | mario79 | 472 | |
473 | shl al, 4 |
||
474 | or al, 10100000b |
||
475 | out dx, al |
||
8054 | rgimad | 476 | ; Waiting for disk ready |
4700 | mario79 | 477 | inc dx |
2288 | clevermous | 478 | mov eax, [timer_ticks] |
479 | mov [TickCounter_1], eax |
||
480 | mov ecx, NoTickWaitTime |
||
4700 | mario79 | 481 | ;-------------------------------------- |
482 | align 4 |
||
2288 | clevermous | 483 | @@WaitHDReady_2: |
484 | cmp [timer_ticks_enable], 0 |
||
485 | jne @f |
||
4700 | mario79 | 486 | |
2288 | clevermous | 487 | dec ecx |
488 | jz @@Err1_4 |
||
4700 | mario79 | 489 | |
2288 | clevermous | 490 | jmp .test |
4700 | mario79 | 491 | ;-------------------------------------- |
492 | align 4 |
||
2288 | clevermous | 493 | @@: |
494 | call change_task |
||
8054 | rgimad | 495 | ; Check waiting time |
2288 | clevermous | 496 | mov eax, [timer_ticks] |
497 | sub eax, [TickCounter_1] |
||
8054 | rgimad | 498 | cmp eax, BSYWaitTime ;300 ; wait for 3 seconds |
499 | ja @@Err1_4 ; time out error |
||
4700 | mario79 | 500 | ;-------------------------------------- |
501 | align 4 |
||
2288 | clevermous | 502 | .test: |
8054 | rgimad | 503 | in al, dx ; Read the state register |
504 | ; Check the state of BSY signal |
||
4700 | mario79 | 505 | test al, 0x80 |
2288 | clevermous | 506 | jnz @@WaitHDReady_2 |
8054 | rgimad | 507 | ; Check the state of DRQ signal |
4700 | mario79 | 508 | test al, 0x8 |
2288 | clevermous | 509 | jnz @@WaitHDReady_2 |
8054 | rgimad | 510 | ; load command to controller's registers |
2288 | clevermous | 511 | cli |
4700 | mario79 | 512 | mov dx, [ATABasePortAddr] |
8054 | rgimad | 513 | inc dx ; "features" register |
4700 | mario79 | 514 | mov al, [ATAFeatures] |
515 | out dx, al |
||
8054 | rgimad | 516 | inc dx ; sector counter |
4700 | mario79 | 517 | mov al, [ATASectorCount] |
518 | out dx, al |
||
8054 | rgimad | 519 | inc dx ; sector number register |
4700 | mario79 | 520 | mov al, [ATASectorNumber] |
521 | out dx, al |
||
8054 | rgimad | 522 | inc dx ; cylinder number (low byte) |
4700 | mario79 | 523 | mov ax, [ATACylinder] |
524 | out dx, al |
||
8054 | rgimad | 525 | inc dx ; cylinder number (high byte) |
4700 | mario79 | 526 | mov al, ah |
527 | out dx, al |
||
8054 | rgimad | 528 | inc dx ; head number / disk number |
4700 | mario79 | 529 | mov al, [DiskNumber] |
530 | shl al, 4 |
||
8054 | rgimad | 531 | cmp [ATAHead], 0xF ; check head number |
2288 | clevermous | 532 | ja @@Err5_4 |
4700 | mario79 | 533 | |
534 | or al, [ATAHead] |
||
535 | or al, 10100000b |
||
536 | mov ah, [ATAAddressMode] |
||
537 | shl ah, 6 |
||
538 | or al, ah |
||
539 | out dx, al |
||
8054 | rgimad | 540 | ; Send command |
4700 | mario79 | 541 | mov al, [ATACommand] |
8054 | rgimad | 542 | inc dx ; command register |
4700 | mario79 | 543 | out dx, al |
2288 | clevermous | 544 | sti |
4700 | mario79 | 545 | ;-------------------------------------- |
2288 | clevermous | 546 | @@End_10: |
547 | xor eax, eax |
||
548 | ret |
||
4700 | mario79 | 549 | ;-------------------------------------- |
8054 | rgimad | 550 | ; Write error code |
2288 | clevermous | 551 | @@Err1_4: |
552 | xor eax, eax |
||
553 | inc eax |
||
554 | ret |
||
4700 | mario79 | 555 | ;-------------------------------------- |
2288 | clevermous | 556 | @@Err2_4: |
557 | mov eax, 2 |
||
558 | ret |
||
4700 | mario79 | 559 | ;-------------------------------------- |
2288 | clevermous | 560 | @@Err3_4: |
561 | mov eax, 3 |
||
562 | ret |
||
4700 | mario79 | 563 | ;-------------------------------------- |
2288 | clevermous | 564 | @@Err4_4: |
565 | mov eax, 4 |
||
566 | ret |
||
4700 | mario79 | 567 | ;-------------------------------------- |
2288 | clevermous | 568 | @@Err5_4: |
569 | mov eax, 5 |
||
570 | ret |
||
4700 | mario79 | 571 | ;----------------------------------------------------------------------------- |
2288 | clevermous | 572 | ;************************************************* |
8054 | rgimad | 573 | ;* WAIT FOR THE DEVICE IS READY FOR WORK * |
574 | ;* Input parameters are passed through global * |
||
575 | ;* variables: * |
||
576 | ;* ChannelNumber - channel number; * |
||
577 | ;* DiskNumber - disk number on channel. * |
||
2288 | clevermous | 578 | ;************************************************* |
579 | WaitUnitReady: |
||
580 | pusha |
||
8054 | rgimad | 581 | ; Remember the peration start time |
4700 | mario79 | 582 | mov eax, [timer_ticks] |
583 | mov [WURStartTime], eax |
||
8054 | rgimad | 584 | ; Clear the packet command buffer |
2288 | clevermous | 585 | call clear_packet_buffer |
8054 | rgimad | 586 | ; Generate TEST UNIT READY command |
4700 | mario79 | 587 | mov [PacketCommand], word 0 |
8054 | rgimad | 588 | ; waiting loop for device readiness |
2288 | clevermous | 589 | mov ecx, NoTickWaitTime |
4700 | mario79 | 590 | ;-------------------------------------- |
591 | align 4 |
||
2288 | clevermous | 592 | @@SendCommand: |
8054 | rgimad | 593 | ; Send readiness check command |
2288 | clevermous | 594 | call SendPacketNoDatCommand |
595 | cmp [timer_ticks_enable], 0 |
||
596 | jne @f |
||
4700 | mario79 | 597 | |
2288 | clevermous | 598 | cmp [DevErrorCode], 0 |
599 | je @@End_11 |
||
4700 | mario79 | 600 | |
2288 | clevermous | 601 | dec ecx |
602 | jz .Error |
||
4700 | mario79 | 603 | |
2288 | clevermous | 604 | jmp @@SendCommand |
4700 | mario79 | 605 | ;-------------------------------------- |
606 | align 4 |
||
2288 | clevermous | 607 | @@: |
608 | call change_task |
||
8054 | rgimad | 609 | ; Check the error code |
2288 | clevermous | 610 | cmp [DevErrorCode], 0 |
611 | je @@End_11 |
||
8054 | rgimad | 612 | ; Check waiting time |
4700 | mario79 | 613 | mov eax, [timer_ticks] |
614 | sub eax, [WURStartTime] |
||
615 | cmp eax, MaxCDWaitTime |
||
2288 | clevermous | 616 | jb @@SendCommand |
4700 | mario79 | 617 | ;-------------------------------------- |
2288 | clevermous | 618 | .Error: |
8054 | rgimad | 619 | ; time out error |
2288 | clevermous | 620 | mov [DevErrorCode], 1 |
4700 | mario79 | 621 | ;-------------------------------------- |
2288 | clevermous | 622 | @@End_11: |
623 | popa |
||
624 | ret |
||
4700 | mario79 | 625 | ;----------------------------------------------------------------------------- |
2288 | clevermous | 626 | ;************************************************* |
8054 | rgimad | 627 | ;* FORBID DISK CHANGE * |
628 | ;* Input parameters are passed through global * |
||
629 | ;* variables: * |
||
630 | ;* ChannelNumber - channel number; * |
||
631 | ;* DiskNumber - disk number on channel. * |
||
2288 | clevermous | 632 | ;************************************************* |
633 | prevent_medium_removal: |
||
634 | pusha |
||
8054 | rgimad | 635 | ; Clear the packet command buffer |
2288 | clevermous | 636 | call clear_packet_buffer |
8054 | rgimad | 637 | ; Set command code |
2288 | clevermous | 638 | mov [PacketCommand], byte 0x1E |
8054 | rgimad | 639 | ; Set "Forbid" code |
2288 | clevermous | 640 | mov [PacketCommand+4], byte 11b |
8054 | rgimad | 641 | ; Send command |
2288 | clevermous | 642 | call SendPacketNoDatCommand |
643 | mov eax, ATAPI_IDE0_lock |
||
644 | add eax, [cdpos] |
||
645 | dec eax |
||
646 | mov [eax], byte 1 |
||
647 | popa |
||
648 | ret |
||
4700 | mario79 | 649 | ;----------------------------------------------------------------------------- |
2288 | clevermous | 650 | ;************************************************* |
8054 | rgimad | 651 | ;* ALLOW DISK CHANGE * |
652 | ;* Input parameters are passed through global * |
||
653 | ;* variables: * |
||
654 | ;* ChannelNumber - channel number; * |
||
655 | ;* DiskNumber - disk number on channel. * |
||
2288 | clevermous | 656 | ;************************************************* |
657 | allow_medium_removal: |
||
658 | pusha |
||
8054 | rgimad | 659 | ; Clear the packet command buffer |
2288 | clevermous | 660 | call clear_packet_buffer |
8054 | rgimad | 661 | ; Set command code |
2288 | clevermous | 662 | mov [PacketCommand], byte 0x1E |
8054 | rgimad | 663 | ; unset "Forbid" code |
4700 | mario79 | 664 | mov [PacketCommand+4], byte 0 |
8054 | rgimad | 665 | ; Send command |
2288 | clevermous | 666 | call SendPacketNoDatCommand |
667 | mov eax, ATAPI_IDE0_lock |
||
668 | add eax, [cdpos] |
||
669 | dec eax |
||
670 | mov [eax], byte 0 |
||
671 | popa |
||
672 | ret |
||
4700 | mario79 | 673 | ;----------------------------------------------------------------------------- |
2288 | clevermous | 674 | ;************************************************* |
8054 | rgimad | 675 | ;* LOAD DISK TO THE DRIVE * |
676 | ;* Input parameters are passed through global * |
||
677 | ;* variables: * |
||
678 | ;* ChannelNumber - channel number; * |
||
679 | ;* DiskNumber - disk number on channel. * |
||
2288 | clevermous | 680 | ;************************************************* |
681 | LoadMedium: |
||
682 | pusha |
||
8054 | rgimad | 683 | ; Clear the packet command buffer |
2288 | clevermous | 684 | call clear_packet_buffer |
8054 | rgimad | 685 | ; Generate START/STOP UNIT command |
686 | ; Set command code |
||
4700 | mario79 | 687 | mov [PacketCommand], word 0x1B |
8054 | rgimad | 688 | ; Set disk loading operation |
2288 | clevermous | 689 | mov [PacketCommand+4], word 00000011b |
8054 | rgimad | 690 | ; Send command |
2288 | clevermous | 691 | call SendPacketNoDatCommand |
692 | popa |
||
693 | ret |
||
4700 | mario79 | 694 | ;----------------------------------------------------------------------------- |
2288 | clevermous | 695 | ;************************************************* |
8054 | rgimad | 696 | ;* REMOVE THE DISK FROM THE DRIVE * |
697 | ;* Input parameters are passed through global * |
||
698 | ;* variables: * |
||
699 | ;* ChannelNumber - channel number; * |
||
700 | ;* DiskNumber - disk number on channel. * |
||
2288 | clevermous | 701 | ;************************************************* |
702 | EjectMedium: |
||
703 | pusha |
||
8054 | rgimad | 704 | ; Clear the packet command buffer |
2288 | clevermous | 705 | call clear_packet_buffer |
8054 | rgimad | 706 | ; Generate START/STOP UNIT command |
707 | ; Set command code |
||
4700 | mario79 | 708 | mov [PacketCommand], word 0x1B |
8054 | rgimad | 709 | ; Set the operation to eject disk |
2288 | clevermous | 710 | mov [PacketCommand+4], word 00000010b |
8054 | rgimad | 711 | ; Send command |
2288 | clevermous | 712 | call SendPacketNoDatCommand |
713 | popa |
||
714 | ret |
||
4700 | mario79 | 715 | ;----------------------------------------------------------------------------- |
2288 | clevermous | 716 | ;************************************************* |
8054 | rgimad | 717 | ;* Check the event of pressing the eject button * |
718 | ;* * |
||
719 | ;* Input parameters are passed through global * |
||
720 | ;* variables: * |
||
721 | ;* ChannelNumber - channel number; * |
||
722 | ;* DiskNumber - disk number on channel. * |
||
2288 | clevermous | 723 | ;************************************************* |
3534 | clevermous | 724 | proc check_ATAPI_device_event_has_work? |
725 | mov eax, [timer_ticks] |
||
726 | sub eax, [timer_ATAPI_check] |
||
727 | cmp eax, 100 |
||
728 | jb .no |
||
4700 | mario79 | 729 | |
3534 | clevermous | 730 | xor eax, eax |
731 | inc eax |
||
732 | ret |
||
4700 | mario79 | 733 | ;-------------------------------------- |
3534 | clevermous | 734 | .no: |
735 | xor eax, eax |
||
736 | ret |
||
737 | endp |
||
4700 | mario79 | 738 | ;----------------------------------------------------------------------------- |
2288 | clevermous | 739 | align 4 |
740 | check_ATAPI_device_event: |
||
741 | pusha |
||
742 | mov eax, [timer_ticks] |
||
743 | sub eax, [timer_ATAPI_check] |
||
744 | cmp eax, 100 |
||
745 | jb .end_1 |
||
4700 | mario79 | 746 | |
4734 | mario79 | 747 | pushfd |
2288 | clevermous | 748 | mov al, [DRIVE_DATA+1] |
749 | and al, 11b |
||
750 | cmp al, 10b |
||
751 | jz .ide3 |
||
4700 | mario79 | 752 | ;-------------------------------------- |
2288 | clevermous | 753 | .ide2_1: |
754 | mov al, [DRIVE_DATA+1] |
||
755 | and al, 1100b |
||
756 | cmp al, 1000b |
||
757 | jz .ide2 |
||
4700 | mario79 | 758 | ;-------------------------------------- |
2288 | clevermous | 759 | .ide1_1: |
760 | mov al, [DRIVE_DATA+1] |
||
761 | and al, 110000b |
||
762 | cmp al, 100000b |
||
763 | jz .ide1 |
||
4700 | mario79 | 764 | ;-------------------------------------- |
2288 | clevermous | 765 | .ide0_1: |
766 | mov al, [DRIVE_DATA+1] |
||
767 | and al, 11000000b |
||
768 | cmp al, 10000000b |
||
769 | jz .ide0 |
||
4700 | mario79 | 770 | ;-------------------------------------- |
771 | .ide7_1: |
||
772 | mov al, [DRIVE_DATA+6] |
||
773 | and al, 11b |
||
774 | cmp al, 10b |
||
775 | jz .ide7 |
||
776 | ;-------------------------------------- |
||
777 | .ide6_1: |
||
778 | mov al, [DRIVE_DATA+6] |
||
779 | and al, 1100b |
||
780 | cmp al, 1000b |
||
781 | jz .ide6 |
||
782 | ;-------------------------------------- |
||
783 | .ide5_1: |
||
784 | mov al, [DRIVE_DATA+6] |
||
785 | and al, 110000b |
||
786 | cmp al, 100000b |
||
787 | jz .ide5 |
||
788 | ;-------------------------------------- |
||
789 | .ide4_1: |
||
790 | mov al, [DRIVE_DATA+6] |
||
791 | and al, 11000000b |
||
792 | cmp al, 10000000b |
||
793 | jz .ide4 |
||
794 | ;-------------------------------------- |
||
795 | .ide11_1: |
||
796 | mov al, [DRIVE_DATA+11] |
||
797 | and al, 11b |
||
798 | cmp al, 10b |
||
799 | jz .ide11 |
||
800 | ;-------------------------------------- |
||
801 | .ide10_1: |
||
802 | mov al, [DRIVE_DATA+11] |
||
803 | and al, 1100b |
||
804 | cmp al, 1000b |
||
805 | jz .ide10 |
||
806 | ;-------------------------------------- |
||
807 | .ide9_1: |
||
808 | mov al, [DRIVE_DATA+11] |
||
809 | and al, 110000b |
||
810 | cmp al, 100000b |
||
811 | jz .ide9 |
||
812 | ;-------------------------------------- |
||
813 | .ide8_1: |
||
814 | mov al, [DRIVE_DATA+11] |
||
815 | and al, 11000000b |
||
816 | cmp al, 10000000b |
||
817 | jz .ide8 |
||
818 | ;-------------------------------------- |
||
2288 | clevermous | 819 | .end: |
4734 | mario79 | 820 | popfd |
2288 | clevermous | 821 | mov eax, [timer_ticks] |
822 | mov [timer_ATAPI_check], eax |
||
4700 | mario79 | 823 | ;-------------------------------------- |
2288 | clevermous | 824 | .end_1: |
825 | popa |
||
826 | ret |
||
4700 | mario79 | 827 | ;----------------------------------------------------------------------------- |
2288 | clevermous | 828 | .ide3: |
829 | cli |
||
830 | cmp [ATAPI_IDE3_lock], 1 |
||
831 | jne .ide2_1 |
||
4700 | mario79 | 832 | |
2288 | clevermous | 833 | cmp [cd_status], 0 |
834 | jne .end |
||
4700 | mario79 | 835 | |
3742 | clevermous | 836 | mov ecx, ide_channel2_mutex |
837 | call mutex_lock |
||
2288 | clevermous | 838 | call reserve_ok2 |
839 | mov [ChannelNumber], 2 |
||
840 | mov [DiskNumber], 1 |
||
841 | mov [cdpos], 4 |
||
842 | call GetEvent_StatusNotification |
||
843 | cmp [CDDataBuf+4], byte 1 |
||
4700 | mario79 | 844 | jne @f |
845 | |||
2288 | clevermous | 846 | call .eject |
4700 | mario79 | 847 | ;-------------------------------------- |
848 | @@: |
||
2288 | clevermous | 849 | call syscall_cdaudio.free |
850 | jmp .ide2_1 |
||
4700 | mario79 | 851 | ;----------------------------------------------------------------------------- |
2288 | clevermous | 852 | .ide2: |
853 | cli |
||
854 | cmp [ATAPI_IDE2_lock], 1 |
||
855 | jne .ide1_1 |
||
4700 | mario79 | 856 | |
2288 | clevermous | 857 | cmp [cd_status], 0 |
858 | jne .end |
||
4700 | mario79 | 859 | |
3742 | clevermous | 860 | mov ecx, ide_channel2_mutex |
861 | call mutex_lock |
||
2288 | clevermous | 862 | call reserve_ok2 |
863 | mov [ChannelNumber], 2 |
||
864 | mov [DiskNumber], 0 |
||
865 | mov [cdpos], 3 |
||
866 | call GetEvent_StatusNotification |
||
867 | cmp [CDDataBuf+4], byte 1 |
||
4700 | mario79 | 868 | jne @f |
869 | |||
2288 | clevermous | 870 | call .eject |
4700 | mario79 | 871 | ;-------------------------------------- |
872 | @@: |
||
2288 | clevermous | 873 | call syscall_cdaudio.free |
874 | jmp .ide1_1 |
||
4700 | mario79 | 875 | ;----------------------------------------------------------------------------- |
2288 | clevermous | 876 | .ide1: |
877 | cli |
||
878 | cmp [ATAPI_IDE1_lock], 1 |
||
879 | jne .ide0_1 |
||
4700 | mario79 | 880 | |
2288 | clevermous | 881 | cmp [cd_status], 0 |
882 | jne .end |
||
4700 | mario79 | 883 | |
3742 | clevermous | 884 | mov ecx, ide_channel1_mutex |
885 | call mutex_lock |
||
2288 | clevermous | 886 | call reserve_ok2 |
887 | mov [ChannelNumber], 1 |
||
888 | mov [DiskNumber], 1 |
||
889 | mov [cdpos], 2 |
||
890 | call GetEvent_StatusNotification |
||
891 | cmp [CDDataBuf+4], byte 1 |
||
4700 | mario79 | 892 | jne @f |
893 | |||
2288 | clevermous | 894 | call .eject |
4700 | mario79 | 895 | ;-------------------------------------- |
896 | @@: |
||
2288 | clevermous | 897 | call syscall_cdaudio.free |
898 | jmp .ide0_1 |
||
4700 | mario79 | 899 | ;----------------------------------------------------------------------------- |
2288 | clevermous | 900 | .ide0: |
901 | cli |
||
902 | cmp [ATAPI_IDE0_lock], 1 |
||
4734 | mario79 | 903 | jne .ide7_1 |
4700 | mario79 | 904 | |
2288 | clevermous | 905 | cmp [cd_status], 0 |
906 | jne .end |
||
4700 | mario79 | 907 | |
3742 | clevermous | 908 | mov ecx, ide_channel1_mutex |
909 | call mutex_lock |
||
2288 | clevermous | 910 | call reserve_ok2 |
911 | mov [ChannelNumber], 1 |
||
912 | mov [DiskNumber], 0 |
||
913 | mov [cdpos], 1 |
||
914 | call GetEvent_StatusNotification |
||
915 | cmp [CDDataBuf+4], byte 1 |
||
4700 | mario79 | 916 | jne @f |
917 | |||
918 | call .eject |
||
919 | ;-------------------------------------- |
||
920 | @@: |
||
2288 | clevermous | 921 | call syscall_cdaudio.free |
4734 | mario79 | 922 | jmp .ide7_1 |
4700 | mario79 | 923 | ;----------------------------------------------------------------------------- |
924 | .ide7: |
||
925 | cli |
||
926 | cmp [ATAPI_IDE7_lock], 1 |
||
4734 | mario79 | 927 | jne .ide6_1 |
4700 | mario79 | 928 | |
929 | cmp [cd_status], 0 |
||
930 | jne .end |
||
931 | |||
932 | mov ecx, ide_channel4_mutex |
||
933 | call mutex_lock |
||
934 | call reserve_ok2 |
||
935 | mov [ChannelNumber], 2 |
||
936 | mov [DiskNumber], 1 |
||
937 | mov [cdpos], 8 |
||
938 | call GetEvent_StatusNotification |
||
939 | cmp [CDDataBuf+4], byte 1 |
||
940 | jne @f |
||
941 | |||
2288 | clevermous | 942 | call .eject |
4700 | mario79 | 943 | ;-------------------------------------- |
944 | @@: |
||
2288 | clevermous | 945 | call syscall_cdaudio.free |
4734 | mario79 | 946 | jmp .ide6_1 |
4700 | mario79 | 947 | ;----------------------------------------------------------------------------- |
948 | .ide6: |
||
949 | cli |
||
950 | cmp [ATAPI_IDE6_lock], 1 |
||
4734 | mario79 | 951 | jne .ide5_1 |
4700 | mario79 | 952 | |
953 | cmp [cd_status], 0 |
||
954 | jne .end |
||
955 | |||
956 | mov ecx, ide_channel4_mutex |
||
957 | call mutex_lock |
||
958 | call reserve_ok2 |
||
959 | mov [ChannelNumber], 2 |
||
960 | mov [DiskNumber], 0 |
||
961 | mov [cdpos], 7 |
||
962 | call GetEvent_StatusNotification |
||
963 | cmp [CDDataBuf+4], byte 1 |
||
964 | jne @f |
||
965 | |||
966 | call .eject |
||
967 | ;-------------------------------------- |
||
968 | @@: |
||
969 | call syscall_cdaudio.free |
||
4734 | mario79 | 970 | jmp .ide5_1 |
4700 | mario79 | 971 | ;----------------------------------------------------------------------------- |
972 | .ide5: |
||
973 | cli |
||
974 | cmp [ATAPI_IDE5_lock], 1 |
||
4734 | mario79 | 975 | jne .ide4_1 |
4700 | mario79 | 976 | |
977 | cmp [cd_status], 0 |
||
978 | jne .end |
||
979 | |||
980 | mov ecx, ide_channel3_mutex |
||
981 | call mutex_lock |
||
982 | call reserve_ok2 |
||
983 | mov [ChannelNumber], 1 |
||
984 | mov [DiskNumber], 1 |
||
985 | mov [cdpos], 6 |
||
986 | call GetEvent_StatusNotification |
||
987 | cmp [CDDataBuf+4], byte 1 |
||
988 | jne @f |
||
989 | |||
990 | call .eject |
||
991 | ;-------------------------------------- |
||
992 | @@: |
||
993 | call syscall_cdaudio.free |
||
4734 | mario79 | 994 | jmp .ide4_1 |
4700 | mario79 | 995 | ;----------------------------------------------------------------------------- |
996 | .ide4: |
||
997 | cli |
||
998 | cmp [ATAPI_IDE4_lock], 1 |
||
4734 | mario79 | 999 | jne .ide11_1 |
4700 | mario79 | 1000 | |
1001 | cmp [cd_status], 0 |
||
1002 | jne .end |
||
1003 | |||
1004 | mov ecx, ide_channel3_mutex |
||
1005 | call mutex_lock |
||
1006 | call reserve_ok2 |
||
1007 | mov [ChannelNumber], 1 |
||
1008 | mov [DiskNumber], 0 |
||
1009 | mov [cdpos], 5 |
||
1010 | call GetEvent_StatusNotification |
||
1011 | cmp [CDDataBuf+4], byte 1 |
||
1012 | jne @f |
||
1013 | |||
1014 | call .eject |
||
1015 | ;-------------------------------------- |
||
1016 | @@: |
||
1017 | call syscall_cdaudio.free |
||
4734 | mario79 | 1018 | jmp .ide11_1 |
4700 | mario79 | 1019 | ;----------------------------------------------------------------------------- |
1020 | .ide11: |
||
1021 | cli |
||
1022 | cmp [ATAPI_IDE11_lock], 1 |
||
4734 | mario79 | 1023 | jne .ide10_1 |
2288 | clevermous | 1024 | |
4700 | mario79 | 1025 | cmp [cd_status], 0 |
1026 | jne .end |
||
1027 | |||
1028 | mov ecx, ide_channel6_mutex |
||
1029 | call mutex_lock |
||
1030 | call reserve_ok2 |
||
1031 | mov [ChannelNumber], 2 |
||
1032 | mov [DiskNumber], 1 |
||
1033 | mov [cdpos], 12 |
||
1034 | call GetEvent_StatusNotification |
||
1035 | cmp [CDDataBuf+4], byte 1 |
||
1036 | jne @f |
||
1037 | |||
1038 | call .eject |
||
1039 | ;-------------------------------------- |
||
1040 | @@: |
||
1041 | call syscall_cdaudio.free |
||
4734 | mario79 | 1042 | jmp .ide10_1 |
4700 | mario79 | 1043 | ;----------------------------------------------------------------------------- |
1044 | .ide10: |
||
1045 | cli |
||
1046 | cmp [ATAPI_IDE10_lock], 1 |
||
4734 | mario79 | 1047 | jne .ide9_1 |
4700 | mario79 | 1048 | |
1049 | cmp [cd_status], 0 |
||
1050 | jne .end |
||
1051 | |||
1052 | mov ecx, ide_channel6_mutex |
||
1053 | call mutex_lock |
||
1054 | call reserve_ok2 |
||
1055 | mov [ChannelNumber], 2 |
||
1056 | mov [DiskNumber], 0 |
||
1057 | mov [cdpos], 11 |
||
1058 | call GetEvent_StatusNotification |
||
1059 | cmp [CDDataBuf+4], byte 1 |
||
1060 | jne @f |
||
1061 | |||
1062 | call .eject |
||
1063 | ;-------------------------------------- |
||
1064 | @@: |
||
1065 | call syscall_cdaudio.free |
||
4734 | mario79 | 1066 | jmp .ide9_1 |
4700 | mario79 | 1067 | ;----------------------------------------------------------------------------- |
1068 | .ide9: |
||
1069 | cli |
||
1070 | cmp [ATAPI_IDE9_lock], 1 |
||
4734 | mario79 | 1071 | jne .ide8_1 |
4700 | mario79 | 1072 | |
1073 | cmp [cd_status], 0 |
||
1074 | jne .end |
||
1075 | |||
1076 | mov ecx, ide_channel5_mutex |
||
1077 | call mutex_lock |
||
1078 | call reserve_ok2 |
||
1079 | mov [ChannelNumber], 1 |
||
1080 | mov [DiskNumber], 1 |
||
1081 | mov [cdpos], 10 |
||
1082 | call GetEvent_StatusNotification |
||
1083 | cmp [CDDataBuf+4], byte 1 |
||
1084 | jne @f |
||
1085 | |||
1086 | call .eject |
||
1087 | ;-------------------------------------- |
||
1088 | @@: |
||
1089 | call syscall_cdaudio.free |
||
4734 | mario79 | 1090 | jmp .ide8_1 |
4700 | mario79 | 1091 | ;----------------------------------------------------------------------------- |
1092 | .ide8: |
||
1093 | cli |
||
1094 | cmp [ATAPI_IDE8_lock], 1 |
||
1095 | jne .end |
||
1096 | |||
1097 | cmp [cd_status], 0 |
||
1098 | jne .end |
||
1099 | |||
1100 | mov ecx, ide_channel5_mutex |
||
1101 | call mutex_lock |
||
1102 | call reserve_ok2 |
||
1103 | mov [ChannelNumber], 1 |
||
1104 | mov [DiskNumber], 0 |
||
1105 | mov [cdpos], 9 |
||
1106 | call GetEvent_StatusNotification |
||
1107 | cmp [CDDataBuf+4], byte 1 |
||
1108 | jne @f |
||
1109 | |||
1110 | call .eject |
||
1111 | ;-------------------------------------- |
||
1112 | @@: |
||
1113 | call syscall_cdaudio.free |
||
1114 | jmp .end |
||
1115 | ;----------------------------------------------------------------------------- |
||
2288 | clevermous | 1116 | .eject: |
1117 | call clear_CD_cache |
||
1118 | call allow_medium_removal |
||
1119 | mov [ignore_CD_eject_wait], 1 |
||
1120 | call EjectMedium |
||
1121 | mov [ignore_CD_eject_wait], 0 |
||
1122 | ret |
||
4700 | mario79 | 1123 | ;----------------------------------------------------------------------------- |
2288 | clevermous | 1124 | iglobal |
1125 | timer_ATAPI_check dd 0 |
||
1126 | ATAPI_IDE0_lock db 0 |
||
1127 | ATAPI_IDE1_lock db 0 |
||
1128 | ATAPI_IDE2_lock db 0 |
||
1129 | ATAPI_IDE3_lock db 0 |
||
4700 | mario79 | 1130 | ATAPI_IDE4_lock db 0 |
1131 | ATAPI_IDE5_lock db 0 |
||
1132 | ATAPI_IDE6_lock db 0 |
||
1133 | ATAPI_IDE7_lock db 0 |
||
1134 | ATAPI_IDE8_lock db 0 |
||
1135 | ATAPI_IDE9_lock db 0 |
||
1136 | ATAPI_IDE10_lock db 0 |
||
1137 | ATAPI_IDE11_lock db 0 |
||
2288 | clevermous | 1138 | ignore_CD_eject_wait db 0 |
1139 | endg |
||
4700 | mario79 | 1140 | ;----------------------------------------------------------------------------- |
2288 | clevermous | 1141 | ;************************************************* |
8054 | rgimad | 1142 | ;* Get an event or device status message * |
1143 | ;* * |
||
1144 | ;* Input parameters are passed through global * |
||
1145 | ;* variables: * |
||
1146 | ;* ChannelNumber - channel number; * |
||
1147 | ;* DiskNumber - disk number on channel * |
||
2288 | clevermous | 1148 | ;************************************************* |
1149 | GetEvent_StatusNotification: |
||
1150 | pusha |
||
1151 | mov [CDDataBuf_pointer], CDDataBuf |
||
8054 | rgimad | 1152 | ; Clear the packet command buffer |
2288 | clevermous | 1153 | call clear_packet_buffer |
8054 | rgimad | 1154 | ; Set command code |
2288 | clevermous | 1155 | mov [PacketCommand], byte 4Ah |
1156 | mov [PacketCommand+1], byte 00000001b |
||
8054 | rgimad | 1157 | ; Set message class request |
2288 | clevermous | 1158 | mov [PacketCommand+4], byte 00010000b |
8054 | rgimad | 1159 | ; Size of allocated area |
2288 | clevermous | 1160 | mov [PacketCommand+7], byte 8h |
1161 | mov [PacketCommand+8], byte 0h |
||
8054 | rgimad | 1162 | ; Send command |
2288 | clevermous | 1163 | call SendPacketDatCommand |
1164 | popa |
||
1165 | ret |
||
4700 | mario79 | 1166 | ;----------------------------------------------------------------------------- |
2288 | clevermous | 1167 | ;************************************************* |
8054 | rgimad | 1168 | ; Read information from TOC (Table of contents) * |
1169 | ;* Input parameters are passed through global * |
||
1170 | ;* variables: * |
||
1171 | ;* ChannelNumber - channel number; * |
||
1172 | ;* DiskNumber - disk number on channel * |
||
2288 | clevermous | 1173 | ;************************************************* |
1174 | Read_TOC: |
||
1175 | pusha |
||
1176 | mov [CDDataBuf_pointer], CDDataBuf |
||
8054 | rgimad | 1177 | ; Clear the packet command buffer |
2288 | clevermous | 1178 | call clear_packet_buffer |
8054 | rgimad | 1179 | ; Generate a packet command to read a data sector |
2288 | clevermous | 1180 | mov [PacketCommand], byte 0x43 |
8054 | rgimad | 1181 | ; Set format |
2288 | clevermous | 1182 | mov [PacketCommand+2], byte 1 |
8054 | rgimad | 1183 | ; Size of allocated area |
2288 | clevermous | 1184 | mov [PacketCommand+7], byte 0xFF |
1185 | mov [PacketCommand+8], byte 0h |
||
8054 | rgimad | 1186 | ; Send a command |
2288 | clevermous | 1187 | call SendPacketDatCommand |
1188 | popa |
||
1189 | ret |
||
4700 | mario79 | 1190 | ;----------------------------------------------------------------------------- |
8054 | rgimad | 1191 | ;***************************************************** |
1192 | ;* DETERMINE THE TOTAL NUMBER OF SECTORS ON THE DISK * |
||
1193 | ;* Input parameters are passed through global * |
||
1194 | ;* variables: * |
||
1195 | ;* ChannelNumber - channel number; * |
||
1196 | ;* DiskNumber - disk number on channel * |
||
1197 | ;***************************************************** |
||
2288 | clevermous | 1198 | ;ReadCapacity: |
1199 | ; pusha |
||
8054 | rgimad | 1200 | ;; Clear the packet command buffer |
2288 | clevermous | 1201 | ; call clear_packet_buffer |
8054 | rgimad | 1202 | ;; Set the buffer size in bytes |
2288 | clevermous | 1203 | ; mov [CDBlockSize],8 |
8054 | rgimad | 1204 | ;; Generate READ CAPACITY command |
2288 | clevermous | 1205 | ; mov [PacketCommand],word 25h |
8054 | rgimad | 1206 | ;; Send command |
2288 | clevermous | 1207 | ; call SendPacketDatCommand |
1208 | ; popa |
||
1209 | ; ret |
||
4700 | mario79 | 1210 | ;----------------------------------------------------------------------------- |
2288 | clevermous | 1211 | clear_packet_buffer: |
8054 | rgimad | 1212 | ; Clear the packet command buffer |
2288 | clevermous | 1213 | and [PacketCommand], dword 0 |
1214 | and [PacketCommand+4], dword 0 |
||
1215 | and [PacketCommand+8], dword 0 |
||
1216 | ret |
||
4700 | mario79 | 1217 | ;----------------------------------------------------------------------------- |