; =============================================================================
;
; Litos - Text string
;
; =============================================================================
CODE_SECTION 32
; -----------------------------------------------------------------------------
; Convert HEX ASCII character to number
; -----------------------------------------------------------------------------
; INPUT: AL = HEX character ("0" to "9", "A" to "F", "a" to "f")
; OUTPUT: AL = number 0 to 15 (if NC) or AL not changed (if CY)
; CY = invalid HEX character (AL not changed)
; -----------------------------------------------------------------------------
; ------------- Check digit
CharHexToBin: cmp al,"0" ; check number MIN
jb CharHexToBin9 ; invalid character
cmp al,"9" ; check number MAX
jbe CharHexToBin7 ; character is OK
; ------------- Check capital letter
cmp al,"A" ; check letter MIN
jb CharHexToBin9 ; invalid character
cmp al,"F" ; check letter MAX
jbe CharHexToBin6 ; character is OK
; ------------- Check small letter
cmp al,"a" ; check letter MIN
jb CharHexToBin9 ; invalid character
cmp al,"f" ; check letter MAX
ja CharHexToBin8 ; invalid character
; ------------- Convert small letter to BIN (it clears CF)
sub al,"0"+("a"-("9"+1)) ; convert ASCII to BIN
ret ; here is NC
; ------------- Convert capital letter to BIN (it clears CF)
CharHexToBin6: sub al,"0"+("A"-("9"+1)) ; convert ASCII to BIN
ret ; here is NC
; ------------- Convert ASCII digit to BIN (it clears CF)
CharHexToBin7: sub al,"0" ; convert ASCII to BIN
ret ; here is NC
; ------------- Invalid HEX character
CharHexToBin8: stc ; set error flag
CharHexToBin9: ret
; -----------------------------------------------------------------------------
; Convert ASCII digit to number
; -----------------------------------------------------------------------------
; INPUT: AL = ASCII digit character ("0" to "9")
; OUTPUT: AL = number 0 to 9 (if NC) or AL not changed (if CY)
; CY = invalid digit character (AL not changed)
; -----------------------------------------------------------------------------
; ------------- Check digit
CharDigToBin: cmp al,"0" ; check number MIN
jb CharDigToBin9 ; invalid character
cmp al,"9" ; check number MAX
ja CharDigToBin8 ; invalid character
; ------------- Convert ASCII digit to BIN (it clears CF)
sub al,"0" ; convert ASCII to BIN
ret ; here is NC
; ------------- Invalid HEX character
CharDigToBin8: stc ; set error flag
CharDigToBin9: ret
; -----------------------------------------------------------------------------
; Data
; -----------------------------------------------------------------------------
DATA_SECTION
; ------------- Empty texts
align 4, db 0
EmptySText: STEXT ''
align 4, db 0
EmptyMText: MTEXT ''
align 4, db 0
EmptyLText: LTEXT ''
align 4, db 0
EmptyText: TXT ''
|