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

Last change on this file since 374 was 369, checked in by gregli@…, 13 years ago

Removed align directives for initalization code and added define for align in boot-time calls to the assembly library (defaulting to 1), resulting in a significant savings for the AT and 386 builds. Fixed a bug with switch command line handling in the serial server. Put in CR characters in licesnse.txt, so that it properly displays on Windows. In the configurator, added default values for user supplied CHS and LBA values, defaulting to values within range when those features are enabled. Updated the copyright message in the configurator as the literal word Copyright is important.

File size: 3.2 KB
RevLine 
[41]1; Project name : Assembly Library
2; Description : Functions for size calculations.
3
[85]4struc BYTE_MULTIPLES
5 .B resb 1
6 .kiB resb 1
7 .MiB resb 1
8 .GiB resb 1
9 .TiB resb 1
10endstruc
11
[41]12; Section containing code
13SECTION .text
14
15;--------------------------------------------------------------------
[85]16; Size_GetSizeToAXAndCharToDLfromBXDXAXwithMagnitudeInCX
[41]17; Parameters:
18; BX:DX:AX: Size in magnitude
[85]19; CX: Magnitude in BYTE_MULTIPLES
[41]20; Returns:
21; AX: Size in magnitude
22; CX: Tenths
23; DL: Magnitude character:
24; 'k' = *1024 B = kiB
25; 'M' = *1024 kiB = MiB
26; 'G' = *1024 MiB = GiB
27; 'T' = *1024 GiB = TiB
28; 'P' = *1024 TiB = PiB
29; Corrupts registers:
30; BX, DH
31;--------------------------------------------------------------------
[369]32ALIGN UTIL_SIZE_JUMP_ALIGN
[41]33Size_GetSizeToAXAndCharToDLfromBXDXAXwithMagnitudeInCX:
[142]34%ifndef USE_186 ; If 8086/8088
35 push di
36%endif
[41]37 push si
38
[369]39ALIGN UTIL_SIZE_JUMP_ALIGN
[41]40.MagnitudeConversionLoop:
[142]41 ePUSH_T di, .MagnitudeConversionLoop; DI corrupted only on 8086/8088 build
42 test bx, bx ; Bits 32...47 in use?
[41]43 jnz SHORT Size_DivideSizeInBXDXAXby1024andIncrementMagnitudeInCX
[142]44 test dx, dx ; Bits 16...31 in use?
[41]45 jnz SHORT Size_DivideSizeInBXDXAXby1024andIncrementMagnitudeInCX
[142]46 cmp ax, 10000 ; 5 digits needed?
[41]47 jae SHORT Size_DivideSizeInBXDXAXby1024andIncrementMagnitudeInCX
[142]48 add sp, BYTE 2 ; Clean return address from stack
49 xchg si, cx ; CX = Remainder (0...1023), SI = Magnitude
[41]50
[141]51 ; Convert remainder to tenths
[142]52 xchg bx, ax ; Store AX
[141]53 mov ax, 10
[142]54 mul cx ; DX:AX = remainder * 10
55 eSHR_IM ax, 10 ; Divide AX by 1024
56 xchg cx, ax ; CX = tenths
[141]57 xchg ax, bx
58
59 ; Convert magnitude to character
60 mov dl, [cs:si+.rgbMagnitudeToChar]
61
[41]62 pop si
[142]63%ifndef USE_186
64 pop di
65%endif
[41]66 ret
[141]67.rgbMagnitudeToChar: db " kMGTP"
[41]68
[141]69
[41]70;--------------------------------------------------------------------
71; Size_DivideSizeInBXDXAXby1024andIncrementMagnitudeInCX
72; Parameters:
73; BX:DX:AX: Size
[85]74; CX: Magnitude in BYTE_MULTIPLES
[41]75; Returns:
76; BX:DX:AX: Size in magnitude
77; SI: Remainder (0...1023)
[85]78; CX: Magnitude in BYTE_MULTIPLES
[41]79; Corrupts registers:
80; Nothing
81;--------------------------------------------------------------------
[369]82ALIGN UTIL_SIZE_JUMP_ALIGN
[41]83Size_DivideSizeInBXDXAXby1024andIncrementMagnitudeInCX:
84 push cx
85 xor si, si ; Zero remainder
86 mov cl, 10 ; Divide by 1024
[369]87ALIGN UTIL_SIZE_JUMP_ALIGN
[41]88.ShiftLoop:
89 call Size_DivideBXDXAXbyTwo
90 rcr si, 1 ; Update remainder
91 loop .ShiftLoop
92 eSHR_IM si, 6 ; Remainder to SI beginning
93 pop cx
94 inc cx ; Increment magnitude
95 ret
96
97
98;--------------------------------------------------------------------
99; Size_ConvertSectorCountInBXDXAXtoKiB
100; Size_DivideBXDXAXbyTwo
101; Parameters:
102; BX:DX:AX: Total sector count
103; Returns:
104; BX:DX:AX: Total size in kiB
105; CF: Remainder from division
106; Corrupts registers:
107; Nothing
108;--------------------------------------------------------------------
[369]109ALIGN UTIL_SIZE_JUMP_ALIGN
[41]110Size_ConvertSectorCountInBXDXAXtoKiB:
111Size_DivideBXDXAXbyTwo:
112 shr bx, 1 ; Divide sector count by 2...
113 rcr dx, 1 ; ...to get disk size in...
114 rcr ax, 1 ; ...kiB
115 ret
Note: See TracBrowser for help on using the repository browser.