1
2SECTION code_driver
3
4PUBLIC ide_drive_id
5
6EXTERN __IO_IDE_COMMAND
7
8EXTERN __IO_IDE_HEAD
9
10EXTERN __IDE_CMD_ID
11
12EXTERN ide_wait_ready, ide_wait_drq
13EXTERN ide_test_error
14
15EXTERN ide_write_byte
16EXTERN ide_read_block
17
18EXTERN ideBuffer
19
20;------------------------------------------------------------------------------
21; Routines that talk with the IDE drive, these should be called by
22; the main program.
23
24; do the identify drive command, and return with the buffer
25; filled with info about the drive.
26
27; the buffer to fill is in HL
28
29ide_drive_id:
30    push af
31    push de
32    call ide_wait_ready
33    jr nc, error
34    ld e, 11100000b
35    ld a, __IO_IDE_HEAD
36    call ide_write_byte     ;select the master device, LBA mode
37    call ide_wait_ready
38    jr nc, error
39    ld e, __IDE_CMD_ID
40    ld a, __IO_IDE_COMMAND
41    call ide_write_byte     ;issue the command
42    call ide_wait_ready     ;make sure drive is ready to proceed
43    jr nc, error
44    call ide_wait_drq       ;wait until it's got the data
45    jr nc, error
46    call ide_read_block     ;grab the data buffer in (HL++)
47    pop de
48    pop af
49    scf                     ;carry = 1 on return = operation ok
50    ret
51
52error:
53    pop de
54    pop af
55    jp ide_test_error       ;carry = 0 on return = operation failed
56
57