source: xtideuniversalbios/trunk/XTIDE_Universal_BIOS/Src/VariablesAndDPTs/AccessDPT.asm@ 186

Last change on this file since 186 was 181, checked in by krille_n_@…, 13 years ago

Changes to all parts of the project:

  • Size optimizations.
  • Added a define (EXCLUDE_FROM_XTIDECFG) to exclude unused library code from XTIDECFG.
  • Tried to minimize time spent with interrupts disabled.
  • Some minor attempts to improve speed (reordering instructions etc).
  • Tried to improve readability, did some cleanup and fixed some errors in comments.
File size: 4.8 KB
Line 
1; Project name : XTIDE Universal BIOS
2; Description : Functions for accessing DPT data.
3
4; Section containing code
5SECTION .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;--------------------------------------------------------------------
16ALIGN JUMP_ALIGN
17AccessDPT_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;--------------------------------------------------------------------
33ALIGN JUMP_ALIGN
34AccessDPT_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;--------------------------------------------------------------------
52ALIGN JUMP_ALIGN
53AccessDPT_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;--------------------------------------------------------------------
71AccessDPT_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 jz SHORT AccessDPT_ShiftPCHinBXDXtoLCH
81
82 cmp WORD [di+DPT.dwCylinders+2], BYTE 0
83 jnz SHORT .Return_MAX_LCHS_CYLINDERS
84
85 ; Limit cylinders to 1024
86 cmp bx, MAX_LCHS_CYLINDERS
87 jb SHORT .Return
88ALIGN JUMP_ALIGN
89.Return_MAX_LCHS_CYLINDERS:
90 mov bx, MAX_LCHS_CYLINDERS
91ALIGN JUMP_ALIGN, ret
92.Return:
93 ret
94
95
96;--------------------------------------------------------------------
97; AccessDPT_ShiftPCHinBXDXtoLCH
98; Parameters:
99; BX: P-CHS cylinders (1...16383)
100; DX: P-CHS heads (1...16)
101; Returns:
102; BX: Number of L-CHS cylinders (1...1024)
103; DX: Number of L-CHS heads (1...255)
104; CX: Number of bits shifted
105; Corrupts registers:
106; Nothing
107;--------------------------------------------------------------------
108AccessDPT_ShiftPCHinBXDXtoLCH:
109 xor cx, cx
110.ShiftLoop:
111 cmp bx, MAX_LCHS_CYLINDERS ; Need to shift?
112 jbe SHORT .LimitHeadsTo255 ; If not, return
113 inc cx ; Increment shift count
114 shr bx, 1 ; Halve cylinders
115 shl dx, 1 ; Double heads
116 jmp SHORT .ShiftLoop
117.LimitHeadsTo255: ; DOS does not support drives with 256 heads
118 sub dl, dh ; DH set only when 256 logical heads
119 xor dh, dh
120 ret
121
122
123;--------------------------------------------------------------------
124; AccessDPT_TestIdeVarsFlagsForMasterOrSlaveDrive
125; Parameters:
126; AX: Bitmask to test DRVPARAMS.wFlags
127; DS:DI: Ptr to Disk Parameter Table
128; Returns:
129; ZF: Set if tested bit was zero
130; Cleared if tested bit was non-zero
131; CF: 0
132; Corrupts registers:
133; BX
134;--------------------------------------------------------------------
135ALIGN JUMP_ALIGN
136AccessDPT_TestIdeVarsFlagsForMasterOrSlaveDrive:
137 call AccessDPT_GetPointerToDRVPARAMStoCSBX
138 test [cs:bx+DRVPARAMS.wFlags], ax
139 ret
140
141;--------------------------------------------------------------------
142; Returns pointer to DRVPARAMS for master or slave drive.
143;
144; AccessDPT_GetPointerToDRVPARAMStoCSBX
145; Parameters:
146; DS:DI: Ptr to Disk Parameter Table
147; Returns:
148; CS:BX: Ptr to DRVPARAMS
149; Corrupts registers:
150; Nothing
151;--------------------------------------------------------------------
152ALIGN JUMP_ALIGN
153AccessDPT_GetPointerToDRVPARAMStoCSBX:
154 eMOVZX bx, [di+DPT.bIdevarsOffset] ; CS:BX points to IDEVARS
155 add bx, BYTE IDEVARS.drvParamsMaster ; CS:BX points to Master Drive DRVPARAMS
156 test BYTE [di+DPT.bFlagsLow], FLGL_DPT_SLAVE
157 jz SHORT .ReturnPointerToDRVPARAMS
158 add bx, BYTE DRVPARAMS_size ; CS:BX points to Slave Drive DRVPARAMS
159.ReturnPointerToDRVPARAMS:
160 ret
Note: See TracBrowser for help on using the repository browser.