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

Last change on this file since 191 was 191, checked in by gregli@…, 12 years ago

Space optimization in Address.asm, includes bug fix for BootMenuPrintCfg.asm (was using a word index instead of a byte index).

File size: 4.7 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_GetAddressingModeToAXZF
45;   Parameters:
46;       DS:DI:  Ptr to Disk Parameter Table
47;   Returns:
48;       AX:     Addressing Mode (L-CHS, P-CHS, LBA28, LBA48)
49;       ZF:     Set if AX=0
50;   Corrupts registers:
51;       Nothing
52;--------------------------------------------------------------------
53ALIGN JUMP_ALIGN
54AccessDPT_GetAddressingModeToAXZF:
55    mov     al, [di+DPT.bFlagsLow]
56    and     ax, BYTE MASKL_DPT_ADDRESSING_MODE 
57    eSHR_IM ax, ADDRESSING_MODE_FIELD_POSITION
58    ret
59
60
61;--------------------------------------------------------------------
62; AccessDPT_GetLCHS
63;   Parameters:
64;       DS:DI:  Ptr to Disk Parameter Table
65;   Returns:
66;       AX:     Number of L-CHS sectors per track
67;       BX:     Number of L-CHS cylinders
68;       DX:     Number of L-CHS heads
69;   Corrupts registers:
70;       CX
71;--------------------------------------------------------------------
72AccessDPT_GetLCHS:
73    ; Load CHS from DPT
74    eMOVZX  ax, BYTE [di+DPT.bSectors]
75    mov     bx, [di+DPT.dwCylinders]
76    cwd
77    mov     dl, [di+DPT.bHeads]
78
79    ; Only need to limit sectors for LBA assist
80    test    BYTE [di+DPT.bFlagsLow], FLG_DRVNHEAD_LBA
81    jz      SHORT AccessDPT_ShiftPCHinBXDXtoLCH
82
83    cmp     WORD [di+DPT.dwCylinders+2], BYTE 0
84    jnz     SHORT .Return_MAX_LCHS_CYLINDERS
85
86    ; Limit cylinders to 1024
87    cmp     bx, MAX_LCHS_CYLINDERS
88    jb      SHORT .Return
89ALIGN JUMP_ALIGN
90.Return_MAX_LCHS_CYLINDERS:
91    mov     bx, MAX_LCHS_CYLINDERS
92ALIGN JUMP_ALIGN, ret
93.Return:
94    ret
95
96
97;--------------------------------------------------------------------
98; AccessDPT_ShiftPCHinBXDXtoLCH
99;   Parameters:
100;       BX:     P-CHS cylinders (1...16383)
101;       DX:     P-CHS heads (1...16)
102;   Returns:
103;       BX:     Number of L-CHS cylinders (1...1024)
104;       DX:     Number of L-CHS heads (1...255)
105;       CX:     Number of bits shifted
106;   Corrupts registers:
107;       Nothing
108;--------------------------------------------------------------------
109AccessDPT_ShiftPCHinBXDXtoLCH:
110    xor     cx, cx
111.ShiftLoop:
112    cmp     bx, MAX_LCHS_CYLINDERS      ; Need to shift?
113    jbe     SHORT .LimitHeadsTo255      ;  If not, return
114    inc     cx                          ; Increment shift count
115    shr     bx, 1                       ; Halve cylinders
116    shl     dx, 1                       ; Double heads
117    jmp     SHORT .ShiftLoop
118.LimitHeadsTo255:                       ; DOS does not support drives with 256 heads
119    sub     dl, dh                      ; DH set only when 256 logical heads
120    xor     dh, dh
121    ret
122
123
124;--------------------------------------------------------------------
125; AccessDPT_TestIdeVarsFlagsForMasterOrSlaveDrive
126;   Parameters:
127;       AX:     Bitmask to test DRVPARAMS.wFlags
128;       DS:DI:  Ptr to Disk Parameter Table
129;   Returns:
130;       ZF:     Set if tested bit was zero
131;               Cleared if tested bit was non-zero
132;       CF:     0
133;   Corrupts registers:
134;       BX
135;--------------------------------------------------------------------
136ALIGN JUMP_ALIGN
137AccessDPT_TestIdeVarsFlagsForMasterOrSlaveDrive:
138    call    AccessDPT_GetPointerToDRVPARAMStoCSBX
139    test    [cs:bx+DRVPARAMS.wFlags], ax
140    ret
141
142;--------------------------------------------------------------------
143; Returns pointer to DRVPARAMS for master or slave drive.
144;
145; AccessDPT_GetPointerToDRVPARAMStoCSBX
146;   Parameters:
147;       DS:DI:  Ptr to Disk Parameter Table
148;   Returns:
149;       CS:BX:  Ptr to DRVPARAMS
150;   Corrupts registers:
151;       Nothing
152;--------------------------------------------------------------------
153ALIGN JUMP_ALIGN
154AccessDPT_GetPointerToDRVPARAMStoCSBX:
155    eMOVZX  bx, [di+DPT.bIdevarsOffset]         ; CS:BX points to IDEVARS
156    add     bx, BYTE IDEVARS.drvParamsMaster    ; CS:BX points to Master Drive DRVPARAMS
157    test    BYTE [di+DPT.bFlagsLow], FLGL_DPT_SLAVE
158    jz      SHORT .ReturnPointerToDRVPARAMS
159    add     bx, BYTE DRVPARAMS_size             ; CS:BX points to Slave Drive DRVPARAMS
160.ReturnPointerToDRVPARAMS:
161    ret
Note: See TracBrowser for help on using the repository browser.