* HEX2ASCI.H
* Kam Leang and Walter Barnum    4-4-98
*
* Header file for Motorola MC6811E2 Botboard
*----------------------------------------------------------------------------
* This header file converts 16-bit Hex value located in RAM_HEXM and
* RAM_HEXL to ASCII format.  The output is sent to the reserved RAM location
* for which character values are stored for the LCDPRNT function.
* This function will look for the MSB in RAM_HEXM and LSB in RAM_HEXL.
* The total number of digits will be 5 plus space holders.
*----------------------------------------------------------------------------

RAM_HEXM	EQU	$10	;Define the MSB location in RAM
RAM_HEXL	EQU	$11	;Define the LSB location in RAM
SPACE		EQU	$20	;Define ASCII value for "space"

*--------------------------Subroutine----------------------------------------

hex2asci        EQU     *
        LDY     #$0000                  ;Load Y with #$0000 for increment

* 1st Digit        
        LDD     RAM_HEXM                ;Load 16-bit value into ACCD   
        LDX     #$2710                  ;Load 10,000Dec into X
        IDIV                            ;Divide D/X, quotient-->X, rem-->D
        PSHA                            ;Push ACCD onto stack to save 
        PSHB                            ;remainder for later use
        STX     RAM_HEXM                ;Store X into RAM to get LSB quotient
        LDAA    RAM_HEXL                ;Load LSB from RAM, this is 1st digit
        LDAB    #$30                    ;Load ASCII shift of $30 into ACCB
        ABA                             ;Add 1st digit to shift for display
        STAA    RAMTOP,Y                ;Store ASCII character in RAMTOP+Y
        PULB                            ;Pull ACCD off stack for another use
        PULA                            ;This step is manadatory even if
                                        ;there are no other uses for ACCD.
                                        ;Since the RTS command depends on
                                        ;on value that was pushed on the
                                        ;stack, not pulling registers from
                                        ;the stack if they were pushed could
                                        ;cause the CPU to loose track of where
                                        ;it is and can't return from a
                                        ;subroutine.
                                        

* 2nd Digit
        INY                             ;Increment Y 
        LDX     #$03E8                  ;Load 1000 Dec into X
        IDIV                            ;Divide D/X, quotient-->X, rem-->D
        PSHA
        PSHB
        STX     RAM_HEXM
        LDAA    RAM_HEXL
        LDAB    #$30
        ABA
        STAA    RAMTOP,Y
        PULB
        PULA

* 3rd Digit
        INY
        LDX     #$0064                  ;Load 100 Dec into X
        IDIV                            ;Divide D/X, quotient-->X, rem-->D
        PSHA
        PSHB
        STX     RAM_HEXM
        LDAA    RAM_HEXL
        LDAB    #$30
        ABA
        STAA    RAMTOP,Y
        PULB
        PULA

* 4th Digit
        INY
        LDX     #$000A                  ;Load 10 Dec into X
        IDIV                            ;Divide D/X, quotient-->X, rem-->D
        PSHA
        PSHB
        STX     RAM_HEXM
        LDAA    RAM_HEXL
        LDAB    #$30
        ABA
        STAA    RAMTOP,Y
        PULB
        PULA

* 5th Digit
        INY
        LDX     #$0001                  ;Load 1 Dec into X
        IDIV                            ;Divide D/X, quotient-->X, rem-->D
        PSHA
        PSHB
        STX     RAM_HEXM
        LDAA    RAM_HEXL
        LDAB    #$30
        ABA
        STAA    RAMTOP,Y
        PULB
        PULA
        RTS                             ;Return from subroutine
