1 | ; Project name : XTIDE Universal BIOS
|
---|
2 | ; Description : Functions for accessing DPT data.
|
---|
3 |
|
---|
4 | ; Section containing code
|
---|
5 | SECTION .text
|
---|
6 |
|
---|
7 | ;--------------------------------------------------------------------
|
---|
8 | ; AccessDPT_GetDriveSelectByteToAL
|
---|
9 | ; Parameters:
|
---|
10 | ; DS:DI: Ptr to Disk Parameter Table
|
---|
11 | ; Returns:
|
---|
12 | ; AL: Drive Select Byte
|
---|
13 | ; Corrupts registers:
|
---|
14 | ; Nothing
|
---|
15 | ;--------------------------------------------------------------------
|
---|
16 | ALIGN JUMP_ALIGN
|
---|
17 | AccessDPT_GetDriveSelectByteToAL:
|
---|
18 | mov al, [di+DPT.wFlags]
|
---|
19 | and al, FLG_DRVNHEAD_LBA | FLG_DRVNHEAD_DRV
|
---|
20 | or al, MASK_DRVNHEAD_SET ; Bits set to 1 for old drives
|
---|
21 | ret
|
---|
22 |
|
---|
23 |
|
---|
24 | ;--------------------------------------------------------------------
|
---|
25 | ; AccessDPT_GetDeviceControlByteToAL
|
---|
26 | ; Parameters:
|
---|
27 | ; DS:DI: Ptr to Disk Parameter Table
|
---|
28 | ; Returns:
|
---|
29 | ; AL: Device Control Byte
|
---|
30 | ; Corrupts registers:
|
---|
31 | ; Nothing
|
---|
32 | ;--------------------------------------------------------------------
|
---|
33 | ALIGN JUMP_ALIGN
|
---|
34 | AccessDPT_GetDeviceControlByteToAL:
|
---|
35 | xor al, al
|
---|
36 | test BYTE [di+DPT.bFlagsLow], FLGL_DPT_ENABLE_IRQ
|
---|
37 | jnz SHORT .EnableDeviceIrq
|
---|
38 | or al, FLG_DEVCONTROL_nIEN ; Disable IRQ
|
---|
39 | .EnableDeviceIrq:
|
---|
40 | ret
|
---|
41 |
|
---|
42 |
|
---|
43 | ;--------------------------------------------------------------------
|
---|
44 | ; AccessDPT_GetAddressingModeForWordLookToBX
|
---|
45 | ; Parameters:
|
---|
46 | ; DS:DI: Ptr to Disk Parameter Table
|
---|
47 | ; Returns:
|
---|
48 | ; BX: Addressing Mode (L-CHS, P-CHS, LBA28, LBA48) shifted for WORD lookup
|
---|
49 | ; Corrupts registers:
|
---|
50 | ; Nothing
|
---|
51 | ;--------------------------------------------------------------------
|
---|
52 | ALIGN JUMP_ALIGN
|
---|
53 | AccessDPT_GetAddressingModeForWordLookToBX:
|
---|
54 | mov bl, [di+DPT.bFlagsLow]
|
---|
55 | and bx, BYTE MASKL_DPT_ADDRESSING_MODE
|
---|
56 | eSHR_IM bx, ADDRESSING_MODE_FIELD_POSITION-1
|
---|
57 | ret
|
---|
58 |
|
---|
59 |
|
---|
60 | ;--------------------------------------------------------------------
|
---|
61 | ; AccessDPT_GetLCHS
|
---|
62 | ; Parameters:
|
---|
63 | ; DS:DI: Ptr to Disk Parameter Table
|
---|
64 | ; Returns:
|
---|
65 | ; AX: Number of L-CHS sectors per track
|
---|
66 | ; BX: Number of L-CHS cylinders
|
---|
67 | ; DX: Number of L-CHS heads
|
---|
68 | ; Corrupts registers:
|
---|
69 | ; CX
|
---|
70 | ;--------------------------------------------------------------------
|
---|
71 | AccessDPT_GetLCHS:
|
---|
72 | ; Load CHS from DPT
|
---|
73 | eMOVZX ax, BYTE [di+DPT.bSectors]
|
---|
74 | mov bx, [di+DPT.dwCylinders]
|
---|
75 | cwd
|
---|
76 | mov dl, [di+DPT.bHeads]
|
---|
77 |
|
---|
78 | ; Only need to limit sectors for LBA assist
|
---|
79 | test BYTE [di+DPT.bFlagsLow], FLG_DRVNHEAD_LBA
|
---|
80 | jnz SHORT .ReturnLbaAssistedLCHS
|
---|
81 |
|
---|
82 | ; P-CHS to L-CHS translation when necessary
|
---|
83 | jmp SHORT AccessDPT_ShiftPCHinBXDXtoLCH
|
---|
84 |
|
---|
85 | .ReturnLbaAssistedLCHS:
|
---|
86 | cmp WORD [di+DPT.dwCylinders+2], BYTE 0
|
---|
87 | jz SHORT .LimitCylindersTo1024
|
---|
88 | mov bx, MAX_LCHS_CYLINDERS
|
---|
89 | .LimitCylindersTo1024:
|
---|
90 | MIN_U bx, MAX_LCHS_CYLINDERS
|
---|
91 | ret
|
---|
92 |
|
---|
93 |
|
---|
94 | ;--------------------------------------------------------------------
|
---|
95 | ; AccessDPT_ShiftPCHinBXDXtoLCH
|
---|
96 | ; Parameters:
|
---|
97 | ; BX: P-CHS cylinders (1...16383)
|
---|
98 | ; DX: P-CHS heads (1...16)
|
---|
99 | ; Returns:
|
---|
100 | ; BX: Number of L-CHS cylinders (1...1024)
|
---|
101 | ; DX: Number of L-CHS heads (1...255)
|
---|
102 | ; CX: Number of bits shifted
|
---|
103 | ; Corrupts registers:
|
---|
104 | ; Nothing
|
---|
105 | ;--------------------------------------------------------------------
|
---|
106 | AccessDPT_ShiftPCHinBXDXtoLCH:
|
---|
107 | xor cx, cx
|
---|
108 | .ShiftLoop:
|
---|
109 | cmp bx, MAX_LCHS_CYLINDERS ; Need to shift?
|
---|
110 | jbe SHORT .LimitHeadsTo255 ; If not, return
|
---|
111 | inc cx ; Increment shift count
|
---|
112 | shr bx, 1 ; Halve cylinders
|
---|
113 | shl dx, 1 ; Double heads
|
---|
114 | jmp SHORT .ShiftLoop
|
---|
115 | .LimitHeadsTo255: ; DOS does not support drives with 256 heads
|
---|
116 | sub dl, dh ; BH set only when 256 logical heads
|
---|
117 | xor dh, dh
|
---|
118 | ret
|
---|
119 |
|
---|
120 |
|
---|
121 | ;--------------------------------------------------------------------
|
---|
122 | ; AccessDPT_TestIdeVarsFlagsForMasterOrSlaveDrive
|
---|
123 | ; Parameters:
|
---|
124 | ; AX: Bitmask to test DRVPARAMS.wFlags
|
---|
125 | ; DS:DI: Ptr to Disk Parameter Table
|
---|
126 | ; Returns:
|
---|
127 | ; ZF: Set if tested bit was zero
|
---|
128 | ; Cleared if tested bit was non-zero
|
---|
129 | ; CF: 0
|
---|
130 | ; Corrupts registers:
|
---|
131 | ; BX
|
---|
132 | ;--------------------------------------------------------------------
|
---|
133 | ALIGN JUMP_ALIGN
|
---|
134 | AccessDPT_TestIdeVarsFlagsForMasterOrSlaveDrive:
|
---|
135 | call AccessDPT_GetPointerToDRVPARAMStoCSBX
|
---|
136 | test [cs:bx+DRVPARAMS.wFlags], ax
|
---|
137 | ret
|
---|
138 |
|
---|
139 | ;--------------------------------------------------------------------
|
---|
140 | ; Returns pointer to DRVPARAMS for master or slave drive.
|
---|
141 | ;
|
---|
142 | ; AccessDPT_GetPointerToDRVPARAMStoCSBX
|
---|
143 | ; Parameters:
|
---|
144 | ; DS:DI: Ptr to Disk Parameter Table
|
---|
145 | ; Returns:
|
---|
146 | ; CS:BX: Ptr to DRVPARAMS
|
---|
147 | ; Corrupts registers:
|
---|
148 | ; Nothing
|
---|
149 | ;--------------------------------------------------------------------
|
---|
150 | ALIGN JUMP_ALIGN
|
---|
151 | AccessDPT_GetPointerToDRVPARAMStoCSBX:
|
---|
152 | eMOVZX bx, [di+DPT.bIdevarsOffset] ; CS:BX points to IDEVARS
|
---|
153 | add bx, BYTE IDEVARS.drvParamsMaster ; CS:BX points to Master Drive DRVPARAMS
|
---|
154 | test BYTE [di+DPT.bFlagsLow], FLGL_DPT_SLAVE
|
---|
155 | jz SHORT .ReturnPointerToDRVPARAMS
|
---|
156 | add bx, BYTE DRVPARAMS_size ; CS:BX points to Slave Drive DRVPARAMS
|
---|
157 | .ReturnPointerToDRVPARAMS:
|
---|
158 | ret
|
---|