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

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

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

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