view lib/alib/hex_bin.a @ 2772:0a3f4d8ea6d5

Found ENDC in wrong location in dwread.asm and dwwrite.asm. Corrected. Moved the native 6309 code in dwread.asm and dwwrite.asm into the H6309 labeled area and changed IFEQ H6309 to IFNE H6309. Also moved the 57600bps 6809 code to the default location. This change had been done in the old dwread.asm and dwwrite.asm files to make it easier to follow. Though these two files were overwritten from the HDBDOS project dwread.asm and dwwrite.asm files. So this conversion needed to be done again so it made the source easier to follow.
author drencor-xeen
date Wed, 23 Jan 2013 12:36:55 -0600
parents 7d70b7e1cb21
children aaba193af04f
line wrap: on
line source

*****************************************

* Hexadecimal string to BINARY conversion

* OTHER MODULES REQUIRED: TO_UPPER, IS_TERMIN, IS_XDIGIT

* ENTRY: X=start of a hex string terminated by a space,
*          comma, CR, or NULL.

* EXIT: D=binary number
*       CC carry set iferror (too large, non-numeric)
*       Y=terminator position or error char.


 nam Convert Hex String to Binary
 ttl Assembler Library Module

 psect HEX_BIN,0,0,0,0,0


HEX_BIN:
 clra init number
 clrb
 pshs d,x
 tfr d,y digit counter

loop
 ldb ,x+ get next digit
 lbsr TO_UPPER convert to uppercase
 lbsr IS_TERMIN end of string?
 beq exit yes, go home
 lbsr IS_XDIGIT make sure it's valid digit
 bne error not 0..9, a..f
 cmpb #'9 convert to binary value
 bls notAtoF
 subb #7 fix a..f
notAtoF
 subb #'0 convert to binary 0..15

* now shift the digit to bits 7..4

 lslb
 lslb
 lslb
 lslb

* now shift the value in to the result

 lda #4 number of bits
l1
 lslb digit bit to carry
 rol 1,s carry bit to result
 rol 0,s
 deca done 4?
 bne l1 no, loop

 leay 1,y number of digits done
 cmpy #4 
 bhi error more than 4
 bra loop keep going


exit
 clrb clear carry=no error
 sty -2,s test y (count)
 bne done no digits?

error
 clr 0,s
 clr 1,s
 orcc #1 set carry

done
 leay -1,x terminator/error pos
 puls d,x,pc

 endsect