; -------------------------------------------------------------- ; INPUTS: ; d0.b - Byte value ; ; RETURNS: ; d0.w - ASCII characters to represent byte ; (high byte is high nybble, low byte is low nybble) ; ; TRASHES: ; d1 ; ; NOTES: ; The 68k stack, whenever pushed or popped by one byte in an ; instruction, increments or decrements by two bytes in order ; to prevent subsequent 16/32-bit reads or writes from odd ; addresses. The lines ; ; move.b .ascii_table(pc,d0.w),-(sp) ; move.w (sp)+,d0 ; ; take advantage of this as a shortcut for bit-shifting ; by 8 (multiplication by $100), saving a few cycles. This ; gain is increased by the following line ; ; move.b .ascii_table(pc,d1.w),d0 ; ; doing away with the need to clear the lower byte of the ; resulting word (as the stack may contain any data at ; the time of operation). ; ; ; This function follows the convention of using d0-d3 and ; a0-a3 as "scratch" registers (able to be overwritten at ; any time). If retaining the contents of d1 is desired, ; add the lines ; ; move.l d1,-(sp) ; ; and ; ; move.l (sp)+,d1 ; ; to the beginning and end of the function respectively. ; Alternatively, do this (or another method of copying) ; before and after calling the function. ; -------------------------------------------------------------- ByteToASCII: moveq #$0F,d1 and.b d0,d1 lsr.b #4,d0 andi.w #$000F,d0 move.b .ascii_table(pc,d0.w),-(sp) move.w (sp)+,d0 move.b .ascii_table(pc,d1.w),d0 rts ; return ((ascii_table[(byte & 0xF0) >> 4] << 8) | ascii_table[byte & 0x0F]); .ascii_table: dc.b "0" dc.b "1" dc.b "2" dc.b "3" dc.b "4" dc.b "5" dc.b "6" dc.b "7" dc.b "8" dc.b "9" dc.b "A" dc.b "B" dc.b "C" dc.b "D" dc.b "E" dc.b "F"