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

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

WIDE checkin... Added copyright and license information to sorce files, as per the GPL instructions for usage.

File size: 6.0 KB
RevLine 
[99]1; Project name : XTIDE Universal BIOS
[3]2; Description : Functions for accessing DPT data.
3
[376]4;
5; XTIDE Universal BIOS and Associated Tools
6; Copyright (C) 2009-2010 by Tomi Tilli, 2011-2012 by XTIDE Universal BIOS Team.
7;
8; This program is free software; you can redistribute it and/or modify
9; it under the terms of the GNU General Public License as published by
10; the Free Software Foundation; either version 2 of the License, or
11; (at your option) any later version.
12;
13; This program is distributed in the hope that it will be useful,
14; but WITHOUT ANY WARRANTY; without even the implied warranty of
15; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16; GNU General Public License for more details.
17; Visit http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
18;
19
[3]20; Section containing code
21SECTION .text
22
[364]23%ifdef MODULE_ADVANCED_ATA
[3]24;--------------------------------------------------------------------
[364]25; AccessDPT_GetIdeBasePortToBX
26; Parameters:
27; DS:DI: Ptr to Disk Parameter Table
28; Returns:
29; BX: IDE Base Port Address
30; Corrupts registers:
31; Nothing
32;--------------------------------------------------------------------
33ALIGN JUMP_ALIGN
34AccessDPT_GetIdeBasePortToBX:
35 eMOVZX bx, [di+DPT.bIdevarsOffset] ; CS:BX points to IDEVARS
36 mov bx, [cs:bx+IDEVARS.wPort]
37 ret
38
39%endif
40
41
42;--------------------------------------------------------------------
[150]43; AccessDPT_GetDriveSelectByteToAL
44; Parameters:
45; DS:DI: Ptr to Disk Parameter Table
46; Returns:
47; AL: Drive Select Byte
48; Corrupts registers:
49; Nothing
50;--------------------------------------------------------------------
51ALIGN JUMP_ALIGN
52AccessDPT_GetDriveSelectByteToAL:
53 mov al, [di+DPT.wFlags]
54 and al, FLG_DRVNHEAD_LBA | FLG_DRVNHEAD_DRV
55 or al, MASK_DRVNHEAD_SET ; Bits set to 1 for old drives
56 ret
57
58
59;--------------------------------------------------------------------
60; AccessDPT_GetDeviceControlByteToAL
61; Parameters:
62; DS:DI: Ptr to Disk Parameter Table
63; Returns:
64; AL: Device Control Byte
65; Corrupts registers:
66; Nothing
67;--------------------------------------------------------------------
68ALIGN JUMP_ALIGN
69AccessDPT_GetDeviceControlByteToAL:
70 xor al, al
[158]71 test BYTE [di+DPT.bFlagsLow], FLGL_DPT_ENABLE_IRQ
[150]72 jnz SHORT .EnableDeviceIrq
73 or al, FLG_DEVCONTROL_nIEN ; Disable IRQ
74.EnableDeviceIrq:
75 ret
76
[227]77
[150]78;--------------------------------------------------------------------
[227]79; AccessDPT_GetLCHStoAXBLBH
[3]80; Parameters:
81; DS:DI: Ptr to Disk Parameter Table
82; Returns:
[227]83; AX: Number of L-CHS cylinders
84; BL: Number of L-CHS heads
85; BH: Number of L-CHS sectors per track
[3]86; Corrupts registers:
[227]87; CX, DX
[3]88;--------------------------------------------------------------------
[227]89AccessDPT_GetLCHStoAXBLBH:
90 ; Return LBA-assisted CHS if LBA addressing used
[173]91 test BYTE [di+DPT.bFlagsLow], FLG_DRVNHEAD_LBA
[227]92 jz SHORT .ConvertPchsToLchs
[173]93
[227]94 call AccessDPT_GetLbaSectorCountToBXDXAX
[358]95 call LbaAssist_ConvertSectorCountFromBXDXAXtoLbaAssistedCHSinDXAXBLBH
96 LIMIT_LBA_CYLINDERS_IN_DXAX_TO_LCHS_CYLINDERS
[227]97 ret
[173]98
[227]99.ConvertPchsToLchs:
100 mov ax, [di+DPT.wPchsCylinders]
101 mov bx, [di+DPT.wPchsHeadsAndSectors]
[230]102 ; Fall to AccessDPT_ShiftPCHinAXBLtoLCH
[227]103
104
105;--------------------------------------------------------------------
106; AccessDPT_ShiftPCHinAXBLtoLCH
[173]107; Parameters:
[227]108; AX: P-CHS cylinders (1...16383)
109; BL: P-CHS heads (1...16)
[173]110; Returns:
[227]111; AX: Number of L-CHS cylinders (1...1024)
112; BL: Number of L-CHS heads (1...255)
[230]113; CX: Number of bits shifted (4 at most)
[173]114; Corrupts registers:
115; Nothing
116;--------------------------------------------------------------------
[227]117AccessDPT_ShiftPCHinAXBLtoLCH:
[173]118 xor cx, cx
119.ShiftLoop:
[227]120 cmp ax, MAX_LCHS_CYLINDERS ; Need to shift?
[231]121 jbe SHORT .Return ; If not, return
[173]122 inc cx ; Increment shift count
[227]123 shr ax, 1 ; Halve cylinders
124 shl bl, 1 ; Double heads
[231]125 jnz SHORT .ShiftLoop ; Falls through only on the last (4th) iteration and only if BL was 16 on entry
126 dec bl ; DOS doesn't support drives with 256 heads so we limit heads to 255
127 ; We can save a byte here by using DEC BX if we don't care about BH
128.Return:
[173]129 ret
130
[227]131
[173]132;--------------------------------------------------------------------
[230]133; AccessDPT_GetLbaSectorCountToBXDXAX
134; Parameters:
135; DS:DI: Ptr to Disk Parameter Table
136; Returns:
137; BX:DX:AX: 48-bit sector count
138; Corrupts registers:
139; Nothing
140;--------------------------------------------------------------------
141AccessDPT_GetLbaSectorCountToBXDXAX:
142 mov ax, [di+DPT.twLbaSectors]
143 mov dx, [di+DPT.twLbaSectors+2]
144 mov bx, [di+DPT.twLbaSectors+4]
145 ret
146
147
148;--------------------------------------------------------------------
[3]149; Returns pointer to DRVPARAMS for master or slave drive.
150;
151; AccessDPT_GetPointerToDRVPARAMStoCSBX
152; Parameters:
153; DS:DI: Ptr to Disk Parameter Table
154; Returns:
155; CS:BX: Ptr to DRVPARAMS
156; Corrupts registers:
157; Nothing
158;--------------------------------------------------------------------
159ALIGN JUMP_ALIGN
160AccessDPT_GetPointerToDRVPARAMStoCSBX:
[150]161 eMOVZX bx, [di+DPT.bIdevarsOffset] ; CS:BX points to IDEVARS
162 add bx, BYTE IDEVARS.drvParamsMaster ; CS:BX points to Master Drive DRVPARAMS
[158]163 test BYTE [di+DPT.bFlagsLow], FLGL_DPT_SLAVE
[150]164 jz SHORT .ReturnPointerToDRVPARAMS
165 add bx, BYTE DRVPARAMS_size ; CS:BX points to Slave Drive DRVPARAMS
166.ReturnPointerToDRVPARAMS:
[3]167 ret
[200]168
169;--------------------------------------------------------------------
170; AccessDPT_GetUnshiftedAddressModeToALZF
171; Parameters:
172; DS:DI: Ptr to Disk Parameter Table
173; Returns:
[230]174; AL: Addressing Mode (L-CHS, P-CHS, LBA28, LBA48)
[200]175; unshifted (still shifted where it is in bFlagsLow)
176; ZF: Set based on value in AL
177; Corrupts registers:
178; AL
179;--------------------------------------------------------------------
[230]180;
181; Converted to a macro since only called in two places, and the call/ret overhead
[200]182; is not worth it for these two instructions (4 bytes total)
183;
184%macro AccessDPT_GetUnshiftedAddressModeToALZF 0
185 mov al, [di+DPT.bFlagsLow]
186 and al, MASKL_DPT_ADDRESSING_MODE
187%endmacro
Note: See TracBrowser for help on using the repository browser.