[41] | 1 | ; Project name : Assembly Library
|
---|
| 2 | ; Description : Functions for size calculations.
|
---|
| 3 |
|
---|
[376] | 4 | ;
|
---|
[491] | 5 | ; XTIDE Universal BIOS and Associated Tools
|
---|
[526] | 6 | ; Copyright (C) 2009-2010 by Tomi Tilli, 2011-2013 by XTIDE Universal BIOS Team.
|
---|
[376] | 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.
|
---|
[491] | 12 | ;
|
---|
[376] | 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
|
---|
[491] | 16 | ; GNU General Public License for more details.
|
---|
[376] | 17 | ; Visit http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
|
---|
[491] | 18 | ;
|
---|
[376] | 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
|
---|
[580] | 59 | %ifdef USE_186
|
---|
[142] | 60 | test bx, bx ; Bits 32...47 in use?
|
---|
[41] | 61 | jnz SHORT Size_DivideSizeInBXDXAXby1024andIncrementMagnitudeInCX
|
---|
[142] | 62 | test dx, dx ; Bits 16...31 in use?
|
---|
[41] | 63 | jnz SHORT Size_DivideSizeInBXDXAXby1024andIncrementMagnitudeInCX
|
---|
[580] | 64 | %else ; 808x
|
---|
| 65 | mov di, bx
|
---|
| 66 | or di, dx
|
---|
| 67 | jnz SHORT Size_DivideSizeInBXDXAXby1024andIncrementMagnitudeInCX
|
---|
| 68 | %endif
|
---|
[142] | 69 | cmp ax, 10000 ; 5 digits needed?
|
---|
[41] | 70 | jae SHORT Size_DivideSizeInBXDXAXby1024andIncrementMagnitudeInCX
|
---|
[142] | 71 | add sp, BYTE 2 ; Clean return address from stack
|
---|
[41] | 72 |
|
---|
[141] | 73 | ; Convert remainder to tenths
|
---|
[592] | 74 | mov bx, 640
|
---|
| 75 | xchg bx, ax ; BX = Size, AX = (10 / 1024) * 65536
|
---|
| 76 | mul si ; DX = Remainder * (10 / 1024)
|
---|
| 77 | xchg dx, ax
|
---|
| 78 | xchg cx, ax ; CX = Tenths, AX = Magnitude
|
---|
| 79 | xchg bx, ax ; AX = Size, BX = Magnitude
|
---|
[141] | 80 |
|
---|
| 81 | ; Convert magnitude to character
|
---|
[592] | 82 | mov dl, [cs:bx+.rgbMagnitudeToChar]
|
---|
[141] | 83 |
|
---|
[41] | 84 | pop si
|
---|
[142] | 85 | %ifndef USE_186
|
---|
| 86 | pop di
|
---|
| 87 | %endif
|
---|
[41] | 88 | ret
|
---|
[141] | 89 | .rgbMagnitudeToChar: db " kMGTP"
|
---|
[41] | 90 |
|
---|
| 91 | ;--------------------------------------------------------------------
|
---|
| 92 | ; Size_DivideSizeInBXDXAXby1024andIncrementMagnitudeInCX
|
---|
| 93 | ; Parameters:
|
---|
| 94 | ; BX:DX:AX: Size
|
---|
[580] | 95 | ; CX: Magnitude in BYTE_MULTIPLES (must be 254 or less)
|
---|
[41] | 96 | ; Returns:
|
---|
| 97 | ; BX:DX:AX: Size in magnitude
|
---|
| 98 | ; SI: Remainder (0...1023)
|
---|
[85] | 99 | ; CX: Magnitude in BYTE_MULTIPLES
|
---|
[41] | 100 | ; Corrupts registers:
|
---|
| 101 | ; Nothing
|
---|
| 102 | ;--------------------------------------------------------------------
|
---|
[369] | 103 | ALIGN UTIL_SIZE_JUMP_ALIGN
|
---|
[41] | 104 | Size_DivideSizeInBXDXAXby1024andIncrementMagnitudeInCX:
|
---|
[580] | 105 | inc cx ; Increment magnitude
|
---|
| 106 | mov si, 1023
|
---|
| 107 | and si, ax ; Remainder now in SI
|
---|
| 108 | ; Fall to Size_DivideSizeInBXDXAXby1024
|
---|
| 109 | %endif ; INCLUDE_MENU_LIBRARY
|
---|
| 110 |
|
---|
| 111 | ;--------------------------------------------------------------------
|
---|
| 112 | ; Size_DivideSizeInBXDXAXby1024
|
---|
| 113 | ; Parameters:
|
---|
| 114 | ; BX:DX:AX: Size
|
---|
| 115 | ; CX: Must be 255 or less
|
---|
| 116 | ; Returns:
|
---|
| 117 | ; BX:DX:AX: Size divided by 1024
|
---|
| 118 | ; Corrupts registers:
|
---|
| 119 | ; Nothing
|
---|
| 120 | ;--------------------------------------------------------------------
|
---|
| 121 | ALIGN UTIL_SIZE_JUMP_ALIGN
|
---|
| 122 | Size_DivideSizeInBXDXAXby1024:
|
---|
| 123 | %ifdef USE_386
|
---|
| 124 | shrd ax, dx, 10
|
---|
| 125 | shrd dx, bx, 10
|
---|
| 126 | shr bx, 10
|
---|
| 127 | %else
|
---|
[41] | 128 | push cx
|
---|
[580] | 129 | mov cl, 10
|
---|
[369] | 130 | ALIGN UTIL_SIZE_JUMP_ALIGN
|
---|
[41] | 131 | .ShiftLoop:
|
---|
| 132 | call Size_DivideBXDXAXbyTwo
|
---|
| 133 | loop .ShiftLoop
|
---|
[580] | 134 | pop cx
|
---|
[567] | 135 | %endif
|
---|
[41] | 136 | ret
|
---|
| 137 |
|
---|
| 138 | ;--------------------------------------------------------------------
|
---|
| 139 | ; Size_ConvertSectorCountInBXDXAXtoKiB
|
---|
| 140 | ; Size_DivideBXDXAXbyTwo
|
---|
| 141 | ; Parameters:
|
---|
| 142 | ; BX:DX:AX: Total sector count
|
---|
| 143 | ; Returns:
|
---|
| 144 | ; BX:DX:AX: Total size in kiB
|
---|
| 145 | ; CF: Remainder from division
|
---|
| 146 | ; Corrupts registers:
|
---|
| 147 | ; Nothing
|
---|
| 148 | ;--------------------------------------------------------------------
|
---|
[592] | 149 | %ifdef EXCLUDE_FROM_XUB
|
---|
[580] | 150 | %ifdef USE_386
|
---|
| 151 | %define EXCLUDE
|
---|
| 152 | %endif
|
---|
| 153 | %ifdef MODULE_BOOT_MENU
|
---|
| 154 | %undef EXCLUDE
|
---|
| 155 | %endif
|
---|
| 156 | %endif
|
---|
| 157 |
|
---|
| 158 | %ifndef EXCLUDE
|
---|
[369] | 159 | ALIGN UTIL_SIZE_JUMP_ALIGN
|
---|
[491] | 160 | Size_ConvertSectorCountInBXDXAXtoKiB: ; unused entrypoint ok
|
---|
[41] | 161 | Size_DivideBXDXAXbyTwo:
|
---|
| 162 | shr bx, 1 ; Divide sector count by 2...
|
---|
| 163 | rcr dx, 1 ; ...to get disk size in...
|
---|
| 164 | rcr ax, 1 ; ...kiB
|
---|
| 165 | ret
|
---|
[580] | 166 | %endif
|
---|
| 167 | %undef EXCLUDE
|
---|