source: xtideuniversalbios/trunk/XTIDE_Universal_BIOS/Src/Handlers/Int13h/Common/HCapacity.asm@ 75

Last change on this file since 75 was 32, checked in by Tomi Tilli, 14 years ago

Correct number of drives is now returned from AH=08h even when it is redirected to foreign BIOS.

File size: 4.8 KB
Line 
1; File name : HCapacity.asm
2; Project name : IDE BIOS
3; Created date : 16.3.2010
4; Last update : 3.8.2010
5; Author : Tomi Tilli
6; Description : Functions for hard disk capacity calculations.
7
8; Section containing code
9SECTION .text
10
11;--------------------------------------------------------------------
12; Calculates sector count from L-CHS values returned by INT 13h, AH=08h.
13;
14; HCapacity_GetSectorCountFromForeignAH08h:
15; HCapacity_GetSectorCountFromOurAH08h:
16; Parameters:
17; DL: Drive number
18; DS: RAMVARS segment
19; Returns:
20; DX:AX: Total sector count
21; BX: Zero
22; Corrupts registers:
23; CX
24;--------------------------------------------------------------------
25ALIGN JUMP_ALIGN
26HCapacity_GetSectorCountFromForeignAH08h:
27 mov ah, 08h ; Get Drive Parameters
28 call Int13h_CallPreviousInt13hHandler
29 jmp SHORT HCapacity_ConvertAH08hReturnValuesToSectorCount
30
31ALIGN JUMP_ALIGN
32HCapacity_GetSectorCountFromOurAH08h:
33 push di
34 call AH8h_GetDriveParameters
35 pop di
36 ; Fall to HCapacity_ConvertAH08hReturnValuesToSectorCount
37
38ALIGN JUMP_ALIGN
39HCapacity_ConvertAH08hReturnValuesToSectorCount:
40 call HAddress_ExtractLCHSFromBiosParams
41 xor ax, ax ; Zero AX
42 inc cx ; Max cylinder number to cylinder count
43 xchg al, bh ; AX=Max head number, BX=Sectors per track
44 inc ax ; AX=Head count
45 mul bx ; AX=Head count * Sectors per track
46 mul cx ; DX:AX = Total sector count
47 xor bx, bx ; Zero BX for 48-bit sector count
48 ret
49
50
51;--------------------------------------------------------------------
52; Converts sector count to hard disk size.
53;
54; HCapacity_ConvertSectorCountToSize:
55; Parameters:
56; BX:DX:AX: Total sector count
57; Returns:
58; AX: Size in magnitude
59; SI: Tenths
60; CX: Magnitude character:
61; 'k' = *1024 B = kiB
62; 'M' = *1024 kiB = MiB
63; 'G' = *1024 MiB = GiB
64; 'T' = *1024 GiB = TiB
65; 'P' = *1024 TiB = PiB
66; Corrupts registers:
67; BX, DX
68;--------------------------------------------------------------------
69ALIGN JUMP_ALIGN
70HCapacity_ConvertSectorCountToSize:
71 call HCapacity_ConvertSectorCountToKiB
72 mov cx, 1 ; Magnitude is 1 for kiB
73ALIGN JUMP_ALIGN
74.MagnitudeLoop:
75 test bx, bx ; Bits 32...47 in use?
76 jnz SHORT .ShiftByMagnitude ; If so, jump to shift
77 test dx, dx ; Bits 16...31 in use?
78 jnz SHORT .ShiftByMagnitude ; If so, jump to shift
79 cmp ax, 10000 ; 5 digits needed?
80 jb SHORT .ShiftComplete ; If less, all done
81ALIGN JUMP_ALIGN
82.ShiftByMagnitude:
83 call HCapacity_ShiftForNextMagnitude
84 jmp SHORT .MagnitudeLoop
85ALIGN JUMP_ALIGN
86.ShiftComplete:
87 mov bx, cx ; Copy shift count to BX
88 mov cl, [cs:bx+.rgbMagnitudeToChar]
89 jmp SHORT HCapacity_ConvertSizeRemainderToTenths
90ALIGN WORD_ALIGN
91.rgbMagnitudeToChar: db " kMGTP"
92
93;--------------------------------------------------------------------
94; Converts 48-bit sector count to size in kiB.
95;
96; HCapacity_ConvertSectorCountToKiB:
97; Parameters:
98; BX:DX:AX: Total sector count
99; Returns:
100; BX:DX:AX: Total size in kiB
101; CF: Remainder from division
102; Corrupts registers:
103; Nothing
104;--------------------------------------------------------------------
105ALIGN JUMP_ALIGN
106HCapacity_ConvertSectorCountToKiB:
107HCapacity_DivideSizeByTwo:
108 shr bx, 1 ; Divide sector count by 2...
109 rcr dx, 1 ; ...to get disk size in...
110 rcr ax, 1 ; ...kiB
111 ret
112
113;--------------------------------------------------------------------
114; Divides size by 1024 and increments magnitude.
115;
116; HCapacity_ShiftForNextMagnitude:
117; Parameters:
118; BX:DX:AX: Size in magnitude
119; CX: Magnitude (0=B, 1=kiB, 2=MiB...)
120; Returns:
121; BX:DX:AX: Size in magnitude
122; SI: Remainder (0...1023)
123; CX: Magnitude (1=kiB, 2=MiB...)
124; Corrupts registers:
125; Nothing
126;--------------------------------------------------------------------
127ALIGN JUMP_ALIGN
128HCapacity_ShiftForNextMagnitude:
129 push cx
130 xor si, si ; Zero remainder
131 mov cl, 10 ; Divide by 1024
132ALIGN JUMP_ALIGN
133.ShiftLoop:
134 call HCapacity_DivideSizeByTwo
135 rcr si, 1 ; Update remainder
136 loop .ShiftLoop
137 eSHR_IM si, 6 ; Remainder to SI beginning
138 pop cx
139 inc cx ; Increment shift count
140 ret
141
142;--------------------------------------------------------------------
143; Converts remainder from HCapacity_ShiftForNextMagnitude to tenths.
144;
145; HCapacity_ConvertSizeRemainderToTenths:
146; Parameters:
147; BX:DX:AX: Size in magnitude
148; SI: Remainder from last magnitude division (0...1023)
149; Returns:
150; BX:DX:AX: Size in magnitude
151; SI: Tenths
152; Corrupts registers:
153; Nothing
154;--------------------------------------------------------------------
155ALIGN JUMP_ALIGN
156HCapacity_ConvertSizeRemainderToTenths:
157 push dx
158 push ax
159
160 mov ax, 10
161 mul si ; DX:AX = remainder * 10
162 eSHR_IM ax, 10 ; Divide AX by 1024
163 xchg si, ax ; SI = tenths
164
165 pop ax
166 pop dx
167 ret
Note: See TracBrowser for help on using the repository browser.