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

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

Changes to XTIDE Universal BIOS:

  • Moved BIOS title and version strings to Version.inc.
  • Moved LBA to L-CHS conversion function to LbaAssist.asm.
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_GetLCHStoAXBLBH
45;   Parameters:
46;       DS:DI:  Ptr to Disk Parameter Table
47;   Returns:
48;       AX:     Number of L-CHS cylinders
49;       BL:     Number of L-CHS heads
50;       BH:     Number of L-CHS sectors per track
51;   Corrupts registers:
52;       CX, DX
53;--------------------------------------------------------------------
54AccessDPT_GetLCHStoAXBLBH:
55    ; Return LBA-assisted CHS if LBA addressing used
56    test    BYTE [di+DPT.bFlagsLow], FLG_DRVNHEAD_LBA
57    jz      SHORT .ConvertPchsToLchs
58
59    call    AccessDPT_GetLbaSectorCountToBXDXAX
60    call    LbaAssist_ConvertSectorCountFromBXDXAXtoLbaAssistedCHSinDXAXBLBH
61    LIMIT_LBA_CYLINDERS_IN_DXAX_TO_LCHS_CYLINDERS
62    ret
63
64.ConvertPchsToLchs:
65    mov     ax, [di+DPT.wPchsCylinders]
66    mov     bx, [di+DPT.wPchsHeadsAndSectors]
67    ; Fall to AccessDPT_ShiftPCHinAXBLtoLCH
68
69
70;--------------------------------------------------------------------
71; AccessDPT_ShiftPCHinAXBLtoLCH
72;   Parameters:
73;       AX:     P-CHS cylinders (1...16383)
74;       BL:     P-CHS heads (1...16)
75;   Returns:
76;       AX:     Number of L-CHS cylinders (1...1024)
77;       BL:     Number of L-CHS heads (1...255)
78;       CX:     Number of bits shifted (4 at most)
79;   Corrupts registers:
80;       Nothing
81;--------------------------------------------------------------------
82AccessDPT_ShiftPCHinAXBLtoLCH:
83    xor     cx, cx
84.ShiftLoop:
85    cmp     ax, MAX_LCHS_CYLINDERS      ; Need to shift?
86    jbe     SHORT .Return               ;  If not, return
87    inc     cx                          ; Increment shift count
88    shr     ax, 1                       ; Halve cylinders
89    shl     bl, 1                       ; Double heads
90    jnz     SHORT .ShiftLoop            ; Falls through only on the last (4th) iteration and only if BL was 16 on entry
91    dec     bl                          ; DOS doesn't support drives with 256 heads so we limit heads to 255
92    ; We can save a byte here by using DEC BX if we don't care about BH
93.Return:
94    ret
95
96
97;--------------------------------------------------------------------
98; AccessDPT_GetLbaSectorCountToBXDXAX
99;   Parameters:
100;       DS:DI:  Ptr to Disk Parameter Table
101;   Returns:
102;       BX:DX:AX:   48-bit sector count
103;   Corrupts registers:
104;       Nothing
105;--------------------------------------------------------------------
106AccessDPT_GetLbaSectorCountToBXDXAX:
107    mov     ax, [di+DPT.twLbaSectors]
108    mov     dx, [di+DPT.twLbaSectors+2]
109    mov     bx, [di+DPT.twLbaSectors+4]
110    ret
111
112
113;--------------------------------------------------------------------
114; Returns pointer to DRVPARAMS for master or slave drive.
115;
116; AccessDPT_GetPointerToDRVPARAMStoCSBX
117;   Parameters:
118;       DS:DI:  Ptr to Disk Parameter Table
119;   Returns:
120;       CS:BX:  Ptr to DRVPARAMS
121;   Corrupts registers:
122;       Nothing
123;--------------------------------------------------------------------
124ALIGN JUMP_ALIGN
125AccessDPT_GetPointerToDRVPARAMStoCSBX:
126    eMOVZX  bx, [di+DPT.bIdevarsOffset]         ; CS:BX points to IDEVARS
127    add     bx, BYTE IDEVARS.drvParamsMaster    ; CS:BX points to Master Drive DRVPARAMS
128    test    BYTE [di+DPT.bFlagsLow], FLGL_DPT_SLAVE
129    jz      SHORT .ReturnPointerToDRVPARAMS
130    add     bx, BYTE DRVPARAMS_size             ; CS:BX points to Slave Drive DRVPARAMS
131.ReturnPointerToDRVPARAMS:
132    ret
133
134;--------------------------------------------------------------------
135; AccessDPT_GetUnshiftedAddressModeToALZF
136;   Parameters:
137;       DS:DI:  Ptr to Disk Parameter Table
138;   Returns:
139;       AL:     Addressing Mode (L-CHS, P-CHS, LBA28, LBA48)
140;               unshifted (still shifted where it is in bFlagsLow)
141;       ZF:     Set based on value in AL
142;   Corrupts registers:
143;       AL
144;--------------------------------------------------------------------
145;
146; Converted to a macro since only called in two places, and the call/ret overhead
147; is not worth it for these two instructions (4 bytes total)
148;
149%macro AccessDPT_GetUnshiftedAddressModeToALZF 0
150    mov     al, [di+DPT.bFlagsLow]
151    and     al, MASKL_DPT_ADDRESSING_MODE
152%endmacro
Note: See TracBrowser for help on using the repository browser.