[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 |
|
---|
[489] | 20 | %ifdef INCLUDE_MENU_LIBRARY
|
---|
[85] | 21 | struc BYTE_MULTIPLES
|
---|
| 22 | .B resb 1
|
---|
| 23 | .kiB resb 1
|
---|
| 24 | .MiB resb 1
|
---|
| 25 | .GiB resb 1
|
---|
| 26 | .TiB resb 1
|
---|
| 27 | endstruc
|
---|
| 28 |
|
---|
[41] | 29 | ; Section containing code
|
---|
| 30 | SECTION .text
|
---|
| 31 |
|
---|
| 32 | ;--------------------------------------------------------------------
|
---|
[85] | 33 | ; Size_GetSizeToAXAndCharToDLfromBXDXAXwithMagnitudeInCX
|
---|
[41] | 34 | ; Parameters:
|
---|
| 35 | ; BX:DX:AX: Size in magnitude
|
---|
[85] | 36 | ; CX: Magnitude in BYTE_MULTIPLES
|
---|
[41] | 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 | ;--------------------------------------------------------------------
|
---|
[369] | 49 | ALIGN UTIL_SIZE_JUMP_ALIGN
|
---|
[41] | 50 | Size_GetSizeToAXAndCharToDLfromBXDXAXwithMagnitudeInCX:
|
---|
[142] | 51 | %ifndef USE_186 ; If 8086/8088
|
---|
| 52 | push di
|
---|
| 53 | %endif
|
---|
[41] | 54 | push si
|
---|
| 55 |
|
---|
[369] | 56 | ALIGN UTIL_SIZE_JUMP_ALIGN
|
---|
[41] | 57 | .MagnitudeConversionLoop:
|
---|
[142] | 58 | ePUSH_T di, .MagnitudeConversionLoop; DI corrupted only on 8086/8088 build
|
---|
| 59 | test bx, bx ; Bits 32...47 in use?
|
---|
[41] | 60 | jnz SHORT Size_DivideSizeInBXDXAXby1024andIncrementMagnitudeInCX
|
---|
[142] | 61 | test dx, dx ; Bits 16...31 in use?
|
---|
[41] | 62 | jnz SHORT Size_DivideSizeInBXDXAXby1024andIncrementMagnitudeInCX
|
---|
[142] | 63 | cmp ax, 10000 ; 5 digits needed?
|
---|
[41] | 64 | jae SHORT Size_DivideSizeInBXDXAXby1024andIncrementMagnitudeInCX
|
---|
[142] | 65 | add sp, BYTE 2 ; Clean return address from stack
|
---|
| 66 | xchg si, cx ; CX = Remainder (0...1023), SI = Magnitude
|
---|
[41] | 67 |
|
---|
[141] | 68 | ; Convert remainder to tenths
|
---|
[142] | 69 | xchg bx, ax ; Store AX
|
---|
[141] | 70 | mov ax, 10
|
---|
[142] | 71 | mul cx ; DX:AX = remainder * 10
|
---|
| 72 | eSHR_IM ax, 10 ; Divide AX by 1024
|
---|
| 73 | xchg cx, ax ; CX = tenths
|
---|
[141] | 74 | xchg ax, bx
|
---|
| 75 |
|
---|
| 76 | ; Convert magnitude to character
|
---|
| 77 | mov dl, [cs:si+.rgbMagnitudeToChar]
|
---|
| 78 |
|
---|
[41] | 79 | pop si
|
---|
[142] | 80 | %ifndef USE_186
|
---|
| 81 | pop di
|
---|
| 82 | %endif
|
---|
[41] | 83 | ret
|
---|
[141] | 84 | .rgbMagnitudeToChar: db " kMGTP"
|
---|
[489] | 85 | %endif
|
---|
[41] | 86 |
|
---|
| 87 | ;--------------------------------------------------------------------
|
---|
| 88 | ; Size_DivideSizeInBXDXAXby1024andIncrementMagnitudeInCX
|
---|
| 89 | ; Parameters:
|
---|
| 90 | ; BX:DX:AX: Size
|
---|
[85] | 91 | ; CX: Magnitude in BYTE_MULTIPLES
|
---|
[41] | 92 | ; Returns:
|
---|
| 93 | ; BX:DX:AX: Size in magnitude
|
---|
| 94 | ; SI: Remainder (0...1023)
|
---|
[85] | 95 | ; CX: Magnitude in BYTE_MULTIPLES
|
---|
[41] | 96 | ; Corrupts registers:
|
---|
| 97 | ; Nothing
|
---|
| 98 | ;--------------------------------------------------------------------
|
---|
[369] | 99 | ALIGN UTIL_SIZE_JUMP_ALIGN
|
---|
[41] | 100 | Size_DivideSizeInBXDXAXby1024andIncrementMagnitudeInCX:
|
---|
| 101 | push cx
|
---|
| 102 | xor si, si ; Zero remainder
|
---|
| 103 | mov cl, 10 ; Divide by 1024
|
---|
[369] | 104 | ALIGN UTIL_SIZE_JUMP_ALIGN
|
---|
[41] | 105 | .ShiftLoop:
|
---|
| 106 | call Size_DivideBXDXAXbyTwo
|
---|
| 107 | rcr si, 1 ; Update remainder
|
---|
| 108 | loop .ShiftLoop
|
---|
| 109 | eSHR_IM si, 6 ; Remainder to SI beginning
|
---|
| 110 | pop cx
|
---|
| 111 | inc cx ; Increment magnitude
|
---|
| 112 | ret
|
---|
| 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] | 125 | ALIGN UTIL_SIZE_JUMP_ALIGN
|
---|
[489] | 126 | Size_ConvertSectorCountInBXDXAXtoKiB: ; unused entrypoint ok
|
---|
[41] | 127 | Size_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
|
---|