if test $cell -ne 2 ; then
echo "/Ha3sm/code/16/soft/tohex wants cell to be 2"
fi

L bytetohex16
                                # number in A
                                # address of high nybble in DI, 2 added
      push B
      push SI
	= A to B
	AND 0xf0 to B
	downshift 4 to B
	= @  $digit B to B
	= byte B to @ DI
	1+ DI

	AND 0xf to A
	+ $digit to A
	= A to SI
        = @ SI to B
	= byte A to @  DI
	1+ DI
      pull SI
      pull B
return


L bytetobinary16
                              # number in A
                              # address of high nybble in DI, 8 added
				# coded mostly to avoid interior labels,
				# which happens to unroll loops.
      push B
	maskbyte A

	= A to B
	downshift 7 to B
	= byte @ $digit B to B
	= byte B to @ DI
	1+ DI

        = A to B
        downshift 6 to B
 	AND 1 to B
        = byte @ $digit B to B
        = byte B to @ DI
	1+ DI

        = A to B
        downshift 5 to B
 	AND 1 to B
        = byte @ $digit B to B
        = byte B to @  DI
	1+ DI

        = A to B
        downshift 4 to B
 	AND 1 to B
        = byte @ $digit B to B
        = byte B to @  DI
	1+ DI

        = A to B
        downshift 3 to B
 	AND 1 to B
        = byte @ $digit B to B
        = byte B to @  DI
	1+ DI

        = A to B
        downshift 2 to B
 	AND 1 to B
        = byte @ $digit B to B
        = byte B to @  DI
	1+ DI

        = A to B
        downshift 1 to B
 	AND 1 to B
        = byte @ $digit B to B
        = byte B to @  DI	
	1+ DI

        = A to B
        #downshift 0
 	AND 1 to B
        = byte @ $digit B to B
        = byte B to @  DI
	1+ DI

      pull B
return


# digit is in global/soft/text

