; This routine translates hexadecimal numbers into a 16-bit integer value. ; Feel free to use without attribution. ; By Todd S. Elliott ; Originally written in LADS in 1988. ; Local equates buffer2 =*; This variable contains hexadecimal numbers composed in an PETASCII ; string and is five bytes long. result1 =*+5; A word field, this contains the eventual 16-bit integer value. hextodec =*+7 lda #0 sta result1 sta result1+1 tax - asl result1 rol result1+1 asl result1 rol result1+1 asl result1 rol result1+1 asl result1 rol result1+1 lda buffer2,x; gets a byte from the hex string located in BUFFER2 cmp #65 ; if it's lower than 65, then it's not an alphanumeric, and bcc + ; don't subtract 7 from it. sbc #7 ; if so, then subtract 7 to remove alphanumeric. + and #15 ; ands the result and stores it as a byte integer ora result1 sta result1 inx cpx #4 bne - ; And the routine is basically done. The RESULT1 word field contains a 16-bit ; integer value for further manipulation. ; The next routine then converts decimal numbers, a 16-bit integer value, into ; a 5-byte PETASCII hexadecimal string. ; Feel free to use without attribution. ; By Todd S. Elliott ; Originally written in LADS in 1988. ; Local equates res =*; This contains a stored integer value. A word field. hexstring =*+2; this contains a five-byte representation of an hexadecimal ; string. ysave =*+7; temporary storage location for the .Y register. hex1 =*+8 .asc "0123456789abcdef" dectohex =*+24 lda #36; petascii for dollar sign sta hexstring; stores it. ldx #$01 ldy #$01 sty ysave - lda res,x; gets the stored integer value and pushes it into the stack pha lsr lsr lsr lsr; get the upper nybble for processing. tay; Since the accumulator now contains an offset for the hex pointer, this lda hex1,y; is transferred to the .Y register for retrieval. ldy ysave sta hexstring,y; stores the upper nybble hexadecimal value. pla and #$0f; retrieves the lower nybble for processing. tay lda hex1,y; gets the corresponding hexadecimal value. inc ysave; ldy ysave; retrieves the .Y register. sta hexstring,y; now store the lower nybble hexadecimal value. inc ysave dex; get the low byte value of the word field, RES variable. bpl - rts ; The routine is done. The HEXSTRING contains the hexadecimal petascii string ; for later processing.