| 1 | ; AiR-BOOT (c) Copyright 1998-2008 M. Kiewitz
|
|---|
| 2 | ;
|
|---|
| 3 | ; This file is part of AiR-BOOT
|
|---|
| 4 | ;
|
|---|
| 5 | ; AiR-BOOT is free software: you can redistribute it and/or modify it under
|
|---|
| 6 | ; the terms of the GNU General Public License as published by the Free
|
|---|
| 7 | ; Software Foundation, either version 3 of the License, or (at your option)
|
|---|
| 8 | ; any later version.
|
|---|
| 9 | ;
|
|---|
| 10 | ; AiR-BOOT is distributed in the hope that it will be useful, but WITHOUT ANY
|
|---|
| 11 | ; WARRANTY: without even the implied warranty of MERCHANTABILITY or FITNESS
|
|---|
| 12 | ; FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
|
|---|
| 13 | ; details.
|
|---|
| 14 | ;
|
|---|
| 15 | ; You should have received a copy of the GNU General Public License along with
|
|---|
| 16 | ; AiR-BOOT. If not, see <http://www.gnu.org/licenses/>.
|
|---|
| 17 | ;
|
|---|
| 18 | ;---------------------------------------------------------------------------
|
|---|
| 19 | ; AiR-BOOT / CONVERSION
|
|---|
| 20 | ;---------------------------------------------------------------------------
|
|---|
| 21 |
|
|---|
| 22 |
|
|---|
| 23 | ; ----------------------
|
|---|
| 24 | ; Rousseau: # CONV.ASM #
|
|---|
| 25 | ; ----------------------
|
|---|
| 26 | ; This module contains various conversion routines.
|
|---|
| 27 | ; Some have to do with bin to ascii, others with translation.
|
|---|
| 28 |
|
|---|
| 29 |
|
|---|
| 30 | IFDEF ModuleNames
|
|---|
| 31 | DB 'CONV',0
|
|---|
| 32 | ENDIF
|
|---|
| 33 |
|
|---|
| 34 | ; Convert a byte in AL to it's Hex Ascii value.
|
|---|
| 35 | ; In: AL - value to convert
|
|---|
| 36 | ; Out: AX - two (Hex) Ascii digits
|
|---|
| 37 | ; Destroyed: none
|
|---|
| 38 | CONV_BinToAsc Proc Near
|
|---|
| 39 | mov ah,al ; Save value to process high nibble later
|
|---|
| 40 | and al,0fh ; Mask low nibble
|
|---|
| 41 | add al,'0' ; Convert to ASCII
|
|---|
| 42 | cmp al,'9' ; Is it in the range of '0' - '9' ?
|
|---|
| 43 | jbe CONV_BinToAsc_DecDigit_1 ; Yep, done
|
|---|
| 44 | add al,7 ; Nope, adjust to Hex Ascii
|
|---|
| 45 | CONV_BinToAsc_DecDigit_1:
|
|---|
| 46 | xchg al,ah ; Exchange with saved value to process high nibble
|
|---|
| 47 | shr al,4 ; Move high nibble to low nibble (80186+)
|
|---|
| 48 | ;shr al
|
|---|
| 49 | ;shr al
|
|---|
| 50 | ;shr al
|
|---|
| 51 | add al,'0' ; Convert to ASCII
|
|---|
| 52 | cmp al,'9' ; Is it in the range of '0' - '9' ?
|
|---|
| 53 | jbe CONV_BinToAsc_DecDigit_2
|
|---|
| 54 | add al,7 ; Nope, adjust to Hex Ascii
|
|---|
| 55 | CONV_BinToAsc_DecDigit_2:
|
|---|
| 56 | xchg al,ah ; Correct order, AX now contains the two (hex) digits
|
|---|
| 57 | ret
|
|---|
| 58 | CONV_BinToAsc Endp
|
|---|
| 59 |
|
|---|
| 60 |
|
|---|
| 61 |
|
|---|
| 62 | ; See if a character is printable.
|
|---|
| 63 | ; Replace with a '.' if not.
|
|---|
| 64 | ; In: AL - char to print
|
|---|
| 65 | ; AH - char to print if AL is non-printable
|
|---|
| 66 | ; Out: AL - char printed (could be dot)
|
|---|
| 67 | ; Destroyed: none
|
|---|
| 68 | CONV_ConvertToPrintable Proc Near
|
|---|
| 69 | cmp al,20h
|
|---|
| 70 | jb CONV_ConvertToPrintable_NP ; Below space, so not printable
|
|---|
| 71 | cmp al,7eh ; Above tilde, so not printable
|
|---|
| 72 | ja CONV_ConvertToPrintable_NP
|
|---|
| 73 | jmp CONV_ConvertToPrintable_End ; Go output it
|
|---|
| 74 | CONV_ConvertToPrintable_NP:
|
|---|
| 75 | mov al,ah ; Use the replacement character
|
|---|
| 76 | CONV_ConvertToPrintable_End:
|
|---|
| 77 | ret
|
|---|
| 78 | CONV_ConvertToPrintable EndP
|
|---|
| 79 |
|
|---|
| 80 |
|
|---|
| 81 |
|
|---|
| 82 | ; Convert CHS values to LBA address
|
|---|
| 83 | ; Formula: LBA = ((c * H) + h) * S + s -1
|
|---|
| 84 | ; c,h,s: requested
|
|---|
| 85 | ; H,S: heads per cylinder and sectors per track
|
|---|
| 86 | ; In: DX:AX - Cylinder
|
|---|
| 87 | ; BX - Head
|
|---|
| 88 | ; CX - Sector
|
|---|
| 89 | ; Out: BX:CX:DX:AX - LBA address (64-bits)
|
|---|
| 90 | ; ZF=1 if upper 32-bits are zero (LBA32)
|
|---|
| 91 | ; Destroyed: none
|
|---|
| 92 | CONV_CHS2LBA Proc Near
|
|---|
| 93 | local req_cyl:dword
|
|---|
| 94 | local req_head:word
|
|---|
| 95 | local req_sec:word
|
|---|
| 96 | local lba:qword
|
|---|
| 97 |
|
|---|
| 98 | ; Save parameters
|
|---|
| 99 | mov word ptr [req_cyl],ax ; save low cyl
|
|---|
| 100 | mov word ptr [req_cyl+2],dx ; save high cyl
|
|---|
| 101 | mov [req_head],bx ; save head
|
|---|
| 102 | test cx,cx
|
|---|
| 103 | jnz CONV_CHS2LBA_sec_ok
|
|---|
| 104 | mov cx,1 ; cannot have sector 0, so change to 1
|
|---|
| 105 | CONV_CHS2LBA_sec_ok:
|
|---|
| 106 | dec cx ; prepare for calculation later
|
|---|
| 107 | mov [req_sec],cx ; save sec
|
|---|
| 108 |
|
|---|
| 109 | ; Clear return value
|
|---|
| 110 | xor ax,ax
|
|---|
| 111 | mov word ptr [lba+6],ax
|
|---|
| 112 | mov word ptr [lba+4],ax
|
|---|
| 113 | mov word ptr [lba+2],ax
|
|---|
| 114 | mov word ptr [lba+0],ax
|
|---|
| 115 |
|
|---|
| 116 | ; Cyls * Heads
|
|---|
| 117 | mov dx,word ptr [req_cyl+2] ; high word of requested cylinder
|
|---|
| 118 | mov ax,word ptr [req_cyl+0] ; low word of requested cylinder
|
|---|
| 119 | xor bx,bx ; zero for 32-bit math
|
|---|
| 120 | mov cx,word ptr [BIOS_Heads] ; number of heads
|
|---|
| 121 | call MATH_Mul32
|
|---|
| 122 |
|
|---|
| 123 | ; WE DISCARD HIGH 32-BITS HERE BECAUSE CALCULATION
|
|---|
| 124 | ; WOULD REQUIRE 64-bits MATH.
|
|---|
| 125 | ; THIS WILL BE FIXED LATER.
|
|---|
| 126 | ; THIS MEANS LBA >2TiB IS NOT SUPPORTED YET.
|
|---|
| 127 |
|
|---|
| 128 | ; Add requested head
|
|---|
| 129 | add ax,[req_head]
|
|---|
| 130 | adc dx,0
|
|---|
| 131 | ;adc cx,0
|
|---|
| 132 | ;adc bx,0
|
|---|
| 133 |
|
|---|
| 134 | ; * Secs
|
|---|
| 135 | xor bx,bx
|
|---|
| 136 | mov cx,word ptr [TrueSecs]
|
|---|
| 137 | call MATH_Mul32
|
|---|
| 138 |
|
|---|
| 139 | ; Add requested sec
|
|---|
| 140 | add ax,[req_sec]
|
|---|
| 141 | adc dx,0
|
|---|
| 142 | ;adc cx,0
|
|---|
| 143 | ;adc bx,0
|
|---|
| 144 |
|
|---|
| 145 | xor bx,bx
|
|---|
| 146 | xor cx,cx
|
|---|
| 147 |
|
|---|
| 148 | ; Set ZF if high upper 32-bits are zero
|
|---|
| 149 | or bx,cx
|
|---|
| 150 |
|
|---|
| 151 | ret
|
|---|
| 152 | CONV_CHS2LBA EndP
|
|---|
| 153 |
|
|---|
| 154 |
|
|---|
| 155 | CONV_LBA2CYLS Proc Near
|
|---|
| 156 |
|
|---|
| 157 |
|
|---|
| 158 | ret
|
|---|
| 159 | CONV_LBA2CYLS Endp
|
|---|
| 160 |
|
|---|
| 161 | ; Convert a character to upper-case
|
|---|
| 162 | CONV_ToUpper Proc Near
|
|---|
| 163 | cmp al,'a'
|
|---|
| 164 | jb CONV_ToUpperSkip1
|
|---|
| 165 | cmp al,'z'
|
|---|
| 166 | ja CONV_ToUpperSkip1
|
|---|
| 167 | sub al,20h
|
|---|
| 168 | CONV_ToUpperSkip1:
|
|---|
| 169 | ret
|
|---|
| 170 | CONV_ToUpper EndP
|
|---|