source: xtideuniversalbios/trunk/Assembly_Library/Src/Util/Size.asm@ 588

Last change on this file since 588 was 580, checked in by krille_n_@…, 10 years ago

Changes:

  • XTIDECFG: Fixed a bug from r459 where the menu option for selection of default boot drive would be missing if the BIOS had been built without MODULE_HOTKEYS. The menu option is now visible if either or both of MODULE_HOTKEYS and MODULE_BOOT_MENU is available.
  • BIOS: Disabled ATA-ID validation by adding a new define (NO_ATAID_VALIDATION) and making it the default for all builds since at least two WD Caviar drive models are incompatible with it.
  • Fixed the "No Fixed Disk Present in FDISK"-bug introduced in r551 which means the Tiny build now works without including MODULE_DRIVEXLATE.
  • Fixed a bug from r528 where pressing hotkey F6 would not initiate detection of serial drives.
  • Fixed a bug from r186 in DisplayFormatCompressed.asm where the boot menu would print the IRQ in hexadecimal format when it should be in decimal format.
  • Optimizations and fixes.
File size: 4.8 KB
Line 
1; Project name : Assembly Library
2; Description : Functions for size calculations.
3
4;
5; XTIDE Universal BIOS and Associated Tools
6; Copyright (C) 2009-2010 by Tomi Tilli, 2011-2013 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
20%ifdef INCLUDE_MENU_LIBRARY
21struc BYTE_MULTIPLES
22 .B resb 1
23 .kiB resb 1
24 .MiB resb 1
25 .GiB resb 1
26 .TiB resb 1
27endstruc
28
29; Section containing code
30SECTION .text
31
32;--------------------------------------------------------------------
33; Size_GetSizeToAXAndCharToDLfromBXDXAXwithMagnitudeInCX
34; Parameters:
35; BX:DX:AX: Size in magnitude
36; CX: Magnitude in BYTE_MULTIPLES
37; Returns:
38; AX: Size in magnitude
39; CX: Tenths
40; DL: Magnitude character:
41; 'k' = *1024 B = kiB
42; 'M' = *1024 kiB = MiB
43; 'G' = *1024 MiB = GiB
44; 'T' = *1024 GiB = TiB
45; 'P' = *1024 TiB = PiB
46; Corrupts registers:
47; BX, DH
48;--------------------------------------------------------------------
49ALIGN UTIL_SIZE_JUMP_ALIGN
50Size_GetSizeToAXAndCharToDLfromBXDXAXwithMagnitudeInCX:
51%ifndef USE_186 ; If 8086/8088
52 push di
53%endif
54 push si
55
56ALIGN UTIL_SIZE_JUMP_ALIGN
57.MagnitudeConversionLoop:
58 ePUSH_T di, .MagnitudeConversionLoop; DI corrupted only on 8086/8088 build
59%ifdef USE_186
60 test bx, bx ; Bits 32...47 in use?
61 jnz SHORT Size_DivideSizeInBXDXAXby1024andIncrementMagnitudeInCX
62 test dx, dx ; Bits 16...31 in use?
63 jnz SHORT Size_DivideSizeInBXDXAXby1024andIncrementMagnitudeInCX
64%else ; 808x
65 mov di, bx
66 or di, dx
67 jnz SHORT Size_DivideSizeInBXDXAXby1024andIncrementMagnitudeInCX
68%endif
69 cmp ax, 10000 ; 5 digits needed?
70 jae SHORT Size_DivideSizeInBXDXAXby1024andIncrementMagnitudeInCX
71 add sp, BYTE 2 ; Clean return address from stack
72 xchg si, cx ; CX = Remainder (0...1023), SI = Magnitude
73
74 ; Convert remainder to tenths
75 xchg bx, ax ; Store AX
76 mov al, 5 ; AH = 0
77 mul cx ; DX:AX = remainder * (10 / 2)
78%ifdef USE_186
79 shr ax, 9 ; Divide AX by (1024 / 2)
80%else
81 shr ax, 1
82 mov al, ah
83 cbw
84%endif
85 xchg cx, ax ; CX = tenths
86 xchg ax, bx
87
88 ; Convert magnitude to character
89 mov dl, [cs:si+.rgbMagnitudeToChar]
90
91 pop si
92%ifndef USE_186
93 pop di
94%endif
95 ret
96.rgbMagnitudeToChar: db " kMGTP"
97
98;--------------------------------------------------------------------
99; Size_DivideSizeInBXDXAXby1024andIncrementMagnitudeInCX
100; Parameters:
101; BX:DX:AX: Size
102; CX: Magnitude in BYTE_MULTIPLES (must be 254 or less)
103; Returns:
104; BX:DX:AX: Size in magnitude
105; SI: Remainder (0...1023)
106; CX: Magnitude in BYTE_MULTIPLES
107; Corrupts registers:
108; Nothing
109;--------------------------------------------------------------------
110ALIGN UTIL_SIZE_JUMP_ALIGN
111Size_DivideSizeInBXDXAXby1024andIncrementMagnitudeInCX:
112 inc cx ; Increment magnitude
113 mov si, 1023
114 and si, ax ; Remainder now in SI
115 ; Fall to Size_DivideSizeInBXDXAXby1024
116%endif ; INCLUDE_MENU_LIBRARY
117
118;--------------------------------------------------------------------
119; Size_DivideSizeInBXDXAXby1024
120; Parameters:
121; BX:DX:AX: Size
122; CX: Must be 255 or less
123; Returns:
124; BX:DX:AX: Size divided by 1024
125; Corrupts registers:
126; Nothing
127;--------------------------------------------------------------------
128ALIGN UTIL_SIZE_JUMP_ALIGN
129Size_DivideSizeInBXDXAXby1024:
130%ifdef USE_386
131 shrd ax, dx, 10
132 shrd dx, bx, 10
133 shr bx, 10
134%else
135 push cx
136 mov cl, 10
137ALIGN UTIL_SIZE_JUMP_ALIGN
138.ShiftLoop:
139 call Size_DivideBXDXAXbyTwo
140 loop .ShiftLoop
141 pop cx
142%endif
143 ret
144
145;--------------------------------------------------------------------
146; Size_ConvertSectorCountInBXDXAXtoKiB
147; Size_DivideBXDXAXbyTwo
148; Parameters:
149; BX:DX:AX: Total sector count
150; Returns:
151; BX:DX:AX: Total size in kiB
152; CF: Remainder from division
153; Corrupts registers:
154; Nothing
155;--------------------------------------------------------------------
156%ifdef EXCLUDE_FROM_XTIDE_UNIVERSAL_BIOS
157 %ifdef USE_386
158 %define EXCLUDE
159 %endif
160 %ifdef MODULE_BOOT_MENU
161 %undef EXCLUDE
162 %endif
163%endif
164
165%ifndef EXCLUDE
166ALIGN UTIL_SIZE_JUMP_ALIGN
167Size_ConvertSectorCountInBXDXAXtoKiB: ; unused entrypoint ok
168Size_DivideBXDXAXbyTwo:
169 shr bx, 1 ; Divide sector count by 2...
170 rcr dx, 1 ; ...to get disk size in...
171 rcr ax, 1 ; ...kiB
172 ret
173%endif
174%undef EXCLUDE
Note: See TracBrowser for help on using the repository browser.