Ignore:
Timestamp:
Jan 27, 2011, 8:14:13 AM (13 years ago)
Author:
aitotat
google:author:
aitotat
Message:

Changes to XTIDE Universal BIOS:

  • Now uses new libraries (untested)
  • Non-working since code size is too large
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/XTIDE_Universal_BIOS/Src/Handlers/Int13h/Common/HCapacity.asm

    r32 r88  
    1 ; File name     :   HCapacity.asm
    2 ; Project name  :   IDE BIOS
    3 ; Created date  :   16.3.2010
    4 ; Last update   :   3.8.2010
    5 ; Author        :   Tomi Tilli
     1; Project name  :   XTIDE Universal BIOS
    62; Description   :   Functions for hard disk capacity calculations.
    73
     
    4743    xor     bx, bx          ; Zero BX for 48-bit sector count
    4844    ret
    49 
    50 
    51 ;--------------------------------------------------------------------
    52 ; Converts sector count to hard disk size.
    53 ;
    54 ; HCapacity_ConvertSectorCountToSize:
    55 ;   Parameters:
    56 ;       BX:DX:AX:   Total sector count
    57 ;   Returns:
    58 ;       AX:         Size in magnitude
    59 ;       SI:         Tenths
    60 ;       CX:         Magnitude character:
    61 ;                       'k' = *1024   B = kiB
    62 ;                       'M' = *1024 kiB = MiB
    63 ;                       'G' = *1024 MiB = GiB
    64 ;                       'T' = *1024 GiB = TiB
    65 ;                       'P' = *1024 TiB = PiB
    66 ;   Corrupts registers:
    67 ;       BX, DX
    68 ;--------------------------------------------------------------------
    69 ALIGN JUMP_ALIGN
    70 HCapacity_ConvertSectorCountToSize:
    71     call    HCapacity_ConvertSectorCountToKiB
    72     mov     cx, 1                   ; Magnitude is 1 for kiB
    73 ALIGN JUMP_ALIGN
    74 .MagnitudeLoop:
    75     test    bx, bx                  ; Bits 32...47 in use?
    76     jnz     SHORT .ShiftByMagnitude ;  If so, jump to shift
    77     test    dx, dx                  ; Bits 16...31 in use?
    78     jnz     SHORT .ShiftByMagnitude ;  If so, jump to shift
    79     cmp     ax, 10000               ; 5 digits needed?
    80     jb      SHORT .ShiftComplete    ;  If less, all done
    81 ALIGN JUMP_ALIGN
    82 .ShiftByMagnitude:
    83     call    HCapacity_ShiftForNextMagnitude
    84     jmp     SHORT .MagnitudeLoop
    85 ALIGN JUMP_ALIGN
    86 .ShiftComplete:
    87     mov     bx, cx                  ; Copy shift count to BX
    88     mov     cl, [cs:bx+.rgbMagnitudeToChar]
    89     jmp     SHORT HCapacity_ConvertSizeRemainderToTenths
    90 ALIGN WORD_ALIGN
    91 .rgbMagnitudeToChar:    db  " kMGTP"
    92 
    93 ;--------------------------------------------------------------------
    94 ; Converts 48-bit sector count to size in kiB.
    95 ;
    96 ; HCapacity_ConvertSectorCountToKiB:
    97 ;   Parameters:
    98 ;       BX:DX:AX:   Total sector count
    99 ;   Returns:
    100 ;       BX:DX:AX:   Total size in kiB
    101 ;       CF:         Remainder from division
    102 ;   Corrupts registers:
    103 ;       Nothing
    104 ;--------------------------------------------------------------------
    105 ALIGN JUMP_ALIGN
    106 HCapacity_ConvertSectorCountToKiB:
    107 HCapacity_DivideSizeByTwo:
    108     shr     bx, 1                   ; Divide sector count by 2...
    109     rcr     dx, 1                   ; ...to get disk size in...
    110     rcr     ax, 1                   ; ...kiB
    111     ret
    112 
    113 ;--------------------------------------------------------------------
    114 ; Divides size by 1024 and increments magnitude.
    115 ;
    116 ; HCapacity_ShiftForNextMagnitude:
    117 ;   Parameters:
    118 ;       BX:DX:AX:   Size in magnitude
    119 ;       CX:         Magnitude (0=B, 1=kiB, 2=MiB...)
    120 ;   Returns:
    121 ;       BX:DX:AX:   Size in magnitude
    122 ;       SI:         Remainder (0...1023)
    123 ;       CX:         Magnitude (1=kiB, 2=MiB...)
    124 ;   Corrupts registers:
    125 ;       Nothing
    126 ;--------------------------------------------------------------------
    127 ALIGN JUMP_ALIGN
    128 HCapacity_ShiftForNextMagnitude:
    129     push    cx
    130     xor     si, si                  ; Zero remainder
    131     mov     cl, 10                  ; Divide by 1024
    132 ALIGN JUMP_ALIGN
    133 .ShiftLoop:
    134     call    HCapacity_DivideSizeByTwo
    135     rcr     si, 1                   ; Update remainder
    136     loop    .ShiftLoop
    137     eSHR_IM si, 6                   ; Remainder to SI beginning
    138     pop     cx
    139     inc     cx                      ; Increment shift count
    140     ret
    141 
    142 ;--------------------------------------------------------------------
    143 ; Converts remainder from HCapacity_ShiftForNextMagnitude to tenths.
    144 ;
    145 ; HCapacity_ConvertSizeRemainderToTenths:
    146 ;   Parameters:
    147 ;       BX:DX:AX:   Size in magnitude
    148 ;       SI:         Remainder from last magnitude division (0...1023)
    149 ;   Returns:
    150 ;       BX:DX:AX:   Size in magnitude
    151 ;       SI:         Tenths
    152 ;   Corrupts registers:
    153 ;       Nothing
    154 ;--------------------------------------------------------------------
    155 ALIGN JUMP_ALIGN
    156 HCapacity_ConvertSizeRemainderToTenths:
    157     push    dx
    158     push    ax
    159 
    160     mov     ax, 10
    161     mul     si                  ; DX:AX = remainder * 10
    162     eSHR_IM ax, 10              ; Divide AX by 1024
    163     xchg    si, ax              ; SI = tenths
    164 
    165     pop     ax
    166     pop     dx
    167     ret
Note: See TracChangeset for help on using the changeset viewer.