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

Last change on this file since 577 was 567, checked in by krille_n_@…, 11 years ago

Changes:

  • Renamed MODULE_FEATURE_SETS to MODULE_POWER_MANAGEMENT.
  • Renamed MODULE_VERY_LATE_INITIALIZATION to MODULE_VERY_LATE_INIT and removed it from the official builds.
  • Removed the code that skips detection of slave drives on XT-CF controllers since slave drives can be used with Lo-tech ISA CompactFlash boards.
  • Added autodetection of the SVC ADP50L controller to XTIDECFG.
  • The autodetection of XT-CF controllers now requires MODULE_8BIT_IDE_ADVANCED in the loaded BIOS.
  • Fixed a bug in XTIDECFG from r502 where the "Base (cmd block) address" menu option would be displayed when a serial device was selected as the IDE controller.
  • XTIDECFG would display the "Enable interrupt" menu option for the XTIDE r1 but not for the XTIDE r2. It's now displayed for both controller types.
  • Disabled the "Internal Write Cache" menu option in the Master/Slave Drive menus for serial device type drives.
  • Optimizations and other fixes.
File size: 4.1 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 test bx, bx ; Bits 32...47 in use?
60 jnz SHORT Size_DivideSizeInBXDXAXby1024andIncrementMagnitudeInCX
61 test dx, dx ; Bits 16...31 in use?
62 jnz SHORT Size_DivideSizeInBXDXAXby1024andIncrementMagnitudeInCX
63 cmp ax, 10000 ; 5 digits needed?
64 jae SHORT Size_DivideSizeInBXDXAXby1024andIncrementMagnitudeInCX
65 add sp, BYTE 2 ; Clean return address from stack
66 xchg si, cx ; CX = Remainder (0...1023), SI = Magnitude
67
68 ; Convert remainder to tenths
69 xchg bx, ax ; Store AX
70 mov ax, 5
71 mul cx ; DX:AX = remainder * (10 / 2)
72%ifdef USE_186
73 shr ax, 9 ; Divide AX by (1024 / 2)
74%else
75 shr ax, 1
76 mov al, ah
77 cbw
78%endif
79 xchg cx, ax ; CX = tenths
80 xchg ax, bx
81
82 ; Convert magnitude to character
83 mov dl, [cs:si+.rgbMagnitudeToChar]
84
85 pop si
86%ifndef USE_186
87 pop di
88%endif
89 ret
90.rgbMagnitudeToChar: db " kMGTP"
91%endif
92
93;--------------------------------------------------------------------
94; Size_DivideSizeInBXDXAXby1024andIncrementMagnitudeInCX
95; Parameters:
96; BX:DX:AX: Size
97; CX: Magnitude in BYTE_MULTIPLES
98; Returns:
99; BX:DX:AX: Size in magnitude
100; SI: Remainder (0...1023)
101; CX: Magnitude in BYTE_MULTIPLES
102; Corrupts registers:
103; Nothing
104;--------------------------------------------------------------------
105ALIGN UTIL_SIZE_JUMP_ALIGN
106Size_DivideSizeInBXDXAXby1024andIncrementMagnitudeInCX:
107 push cx
108 xor si, si ; Zero remainder
109 mov cl, 10 ; Divide by 1024
110ALIGN UTIL_SIZE_JUMP_ALIGN
111.ShiftLoop:
112 call Size_DivideBXDXAXbyTwo
113 rcr si, 1 ; Update remainder
114 loop .ShiftLoop
115%ifdef USE_186
116 shr si, 6 ; Remainder to SI beginning
117%else
118 mov cl, 6
119 shr si, cl
120%endif
121 pop cx
122 inc cx ; Increment magnitude
123 ret
124
125;--------------------------------------------------------------------
126; Size_ConvertSectorCountInBXDXAXtoKiB
127; Size_DivideBXDXAXbyTwo
128; Parameters:
129; BX:DX:AX: Total sector count
130; Returns:
131; BX:DX:AX: Total size in kiB
132; CF: Remainder from division
133; Corrupts registers:
134; Nothing
135;--------------------------------------------------------------------
136ALIGN UTIL_SIZE_JUMP_ALIGN
137Size_ConvertSectorCountInBXDXAXtoKiB: ; unused entrypoint ok
138Size_DivideBXDXAXbyTwo:
139 shr bx, 1 ; Divide sector count by 2...
140 rcr dx, 1 ; ...to get disk size in...
141 rcr ax, 1 ; ...kiB
142 ret
Note: See TracBrowser for help on using the repository browser.