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

Last change on this file since 580 was 580, checked in by krille_n_@…, 9 years ago

Changes:

  • XTIDECFG: Fixed a bug from r459 where the menu option for selection of default boot drive would be missing if the BIOS had been built without MODULE_HOTKEYS. The menu option is now visible if either or both of MODULE_HOTKEYS and MODULE_BOOT_MENU is available.
  • BIOS: Disabled ATA-ID validation by adding a new define (NO_ATAID_VALIDATION) and making it the default for all builds since at least two WD Caviar drive models are incompatible with it.
  • Fixed the "No Fixed Disk Present in FDISK"-bug introduced in r551 which means the Tiny build now works without including MODULE_DRIVEXLATE.
  • Fixed a bug from r528 where pressing hotkey F6 would not initiate detection of serial drives.
  • Fixed a bug from r186 in DisplayFormatCompressed.asm where the boot menu would print the IRQ in hexadecimal format when it should be in decimal format.
  • Optimizations and fixes.
File size: 4.8 KB
RevLine 
[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]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
[41]29; Section containing code
30SECTION .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]49ALIGN UTIL_SIZE_JUMP_ALIGN
[41]50Size_GetSizeToAXAndCharToDLfromBXDXAXwithMagnitudeInCX:
[142]51%ifndef USE_186     ; If 8086/8088
52    push    di
53%endif
[41]54    push    si
55
[369]56ALIGN 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
72    xchg    si, cx                      ; CX = Remainder (0...1023), SI = Magnitude
[41]73
[141]74    ; Convert remainder to tenths
[142]75    xchg    bx, ax                      ; Store AX
[580]76    mov     al, 5                       ; AH = 0
[491]77    mul     cx                          ; DX:AX = remainder * (10 / 2)
78%ifdef USE_186
79    shr     ax, 9                       ; Divide AX by (1024 / 2)
80%else
81    shr     ax, 1
82    mov     al, ah
83    cbw
84%endif
[142]85    xchg    cx, ax                      ; CX = tenths
[141]86    xchg    ax, bx
87
88    ; Convert magnitude to character
89    mov     dl, [cs:si+.rgbMagnitudeToChar]
90
[41]91    pop     si
[142]92%ifndef USE_186
93    pop     di
94%endif
[41]95    ret
[141]96.rgbMagnitudeToChar:    db  " kMGTP"
[41]97
98;--------------------------------------------------------------------
99; Size_DivideSizeInBXDXAXby1024andIncrementMagnitudeInCX
100;   Parameters:
101;       BX:DX:AX:   Size
[580]102;       CX:         Magnitude in BYTE_MULTIPLES (must be 254 or less)
[41]103;   Returns:
104;       BX:DX:AX:   Size in magnitude
105;       SI:         Remainder (0...1023)
[85]106;       CX:         Magnitude in BYTE_MULTIPLES
[41]107;   Corrupts registers:
108;       Nothing
109;--------------------------------------------------------------------
[369]110ALIGN UTIL_SIZE_JUMP_ALIGN
[41]111Size_DivideSizeInBXDXAXby1024andIncrementMagnitudeInCX:
[580]112    inc     cx                      ; Increment magnitude
113    mov     si, 1023
114    and     si, ax                  ; Remainder now in SI
115    ; Fall to Size_DivideSizeInBXDXAXby1024
116%endif ; INCLUDE_MENU_LIBRARY
117
118;--------------------------------------------------------------------
119; Size_DivideSizeInBXDXAXby1024
120;   Parameters:
121;       BX:DX:AX:   Size
122;       CX:         Must be 255 or less
123;   Returns:
124;       BX:DX:AX:   Size divided by 1024
125;   Corrupts registers:
126;       Nothing
127;--------------------------------------------------------------------
128ALIGN UTIL_SIZE_JUMP_ALIGN
129Size_DivideSizeInBXDXAXby1024:
130%ifdef USE_386
131    shrd    ax, dx, 10
132    shrd    dx, bx, 10
133    shr     bx, 10
134%else
[41]135    push    cx
[580]136    mov     cl, 10
[369]137ALIGN UTIL_SIZE_JUMP_ALIGN
[41]138.ShiftLoop:
139    call    Size_DivideBXDXAXbyTwo
140    loop    .ShiftLoop
[580]141    pop     cx
[567]142%endif
[41]143    ret
144
145;--------------------------------------------------------------------
146; Size_ConvertSectorCountInBXDXAXtoKiB
147; Size_DivideBXDXAXbyTwo
148;   Parameters:
149;       BX:DX:AX:   Total sector count
150;   Returns:
151;       BX:DX:AX:   Total size in kiB
152;       CF:         Remainder from division
153;   Corrupts registers:
154;       Nothing
155;--------------------------------------------------------------------
[580]156%ifdef EXCLUDE_FROM_XTIDE_UNIVERSAL_BIOS
157    %ifdef USE_386
158        %define EXCLUDE
159    %endif
160    %ifdef MODULE_BOOT_MENU
161        %undef EXCLUDE
162    %endif
163%endif
164
165%ifndef EXCLUDE
[369]166ALIGN UTIL_SIZE_JUMP_ALIGN
[491]167Size_ConvertSectorCountInBXDXAXtoKiB:   ; unused entrypoint ok
[41]168Size_DivideBXDXAXbyTwo:
169    shr     bx, 1                   ; Divide sector count by 2...
170    rcr     dx, 1                   ; ...to get disk size in...
171    rcr     ax, 1                   ; ...kiB
172    ret
[580]173%endif
174%undef EXCLUDE
Note: See TracBrowser for help on using the repository browser.