Changeset 87


Ignore:
Timestamp:
Apr 8, 2017, 12:26:23 AM (8 years ago)
Author:
Ben Rietbroek
Message:

Added function to convert a byte to packed BCD [v1.1.1-testing]

This enabled displaying small numbers (0>=n<=255) as decimal values.
The function returns a 16-bit value with the number of decimal digits
in the high nibble and the decimal digits in the remaining nibbles.

CAUTION:
This is a testbuild !
AirBoot uses the BIOS to access disks and a small coding error can trash
partition tables or other vital disk structures. You are advised to make
backups of TRACK0 and EBRs before using this testbuild. More info at:
https://rousseaux.github.io/netlabs.air-boot/pdf/AirBoot-v1.1.0-manual.pdf

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/bootcode/regular/conv.asm

    r57 r87  
    6060
    6161
     62; Convert a byte in AL to it's packed BCD value in AX.
     63; In:          AL - value to convert
     64; Out:         AX - |digitcount|digit2|digit1|digit0|
     65; Destroyed:   none
     66CONV_BinToPBCD  Proc  Near uses cx
     67
     68        ; Use AAM to convert to unpacked BCD
     69        mov     ch, 1           ; There always is at least one digit
     70        aam                     ; Convert byte to unpacked BCD
     71        test    ah, ah          ; If AH is zero, the value was below 10d
     72
     73        ; Just one digit, we're done
     74        jz      CONV_BinToPBCD_done
     75
     76        ; There are more digits
     77        inc     ch              ; Increment digit count
     78        cmp     ah, 9           ; If AH is above 9, there is a third digit
     79
     80        ; There are three digits, AH needs to be processed too
     81        ja      CONV_BinToPBCD_three_digits
     82
     83        ; There are two digits, AH contains second digit
     84        shl     ah, 4           ; Correct the unpacked BCD nibble location
     85        or      al, ah          ; Now we have a 2 digit packed BCD
     86        xor     ah, ah          ; No third digit
     87
     88        ; Two digits, we're done
     89        jmp     CONV_BinToPBCD_done
     90
     91    CONV_BinToPBCD_three_digits:
     92        ; There are three digits, process AH
     93        inc     ch              ; Increment digit count
     94        mov     cl, al          ; Store the first digit
     95        mov     al, ah          ; Value in AH needs to be processed also
     96        aam                     ; Convert byte to unpacked BCD
     97        shl     al, 4           ; Correct the unpacked BCD nibble location
     98        or      al, cl          ; Merge the first BCD digit
     99
     100        ; Three digits, we're done
     101        jmp     CONV_BinToPBCD_done
     102
     103    CONV_BinToPBCD_done:
     104        ; Compose the packed BCD value with the digit count in high nibble
     105        shl     ch, 4           ; Move count to correct nibble
     106        or      ah, ch          ; Count is now in high nibble of AX
     107        test    ax, 0fffh       ; Set ZF if all digits are 0
     108
     109        ret
     110CONV_BinToPBCD  Endp
     111
     112
     113
    62114; See if a character is printable.
    63115; Replace with a '.' if not.
Note: See TracChangeset for help on using the changeset viewer.