*+ * MODULE: MAXBUG2 * VERSION: A1.0 * DATE: 14th. July 1981 * SOURCE FILE NAME: MAXBUG2.SA * SOURCE LANGUAGE: M6809 assembler * TARGET SYSTEM: M6809 MPU based system * PROGRAMMER: Andy Barth * FUNCTION: Part of MAXbug - a debug monitor program. This module * contains conversion subroutines. They are: * CB1HEX - convert a 4-bit binary number to a hexadecimal char. * OP1HEX - output a hexadecimal character. * CB2HEX - convert an 8-bit binary number to 2 hexadecimal chars. * OP2HEX - output 2 hexadecimal characters. * CB4HEX - convert a 16-bit binary number to 4 hexadecimal chars. * OP4HEX - output 4 hexadecimal characters. * C1HXBN - convert a hexadecimal char to a 4-bit binary number. * C2HXBN - convert 2 hexadecimal chars to an 8-bit binary number. * C2HXBN - convert 4 hexadecimal chars to a 16-bit binary number. *- SPC 3 NAM MAXBG2 TTL MAXBUG A1.0 - conversion subroutines IDNT MAXBUG A1.0 - conversion subroutines SPC 1 XREF OPCHAR XDEF CB1HEX,OP1HEX,CB2HEX,OP2HEX,CB4HEX,OP4HEX,C1HXBN,C2HXBN,C4HXBN SPC 3 * ASCII character equates: NULL EQU 0 EOT EQU 4 (CTRL-D) BELL EQU 7 LF EQU $A line feed CR EQU $D carriage return FF EQU $C form feed ETB EQU $17 (CTRL-W) CAN EQU $18 cancel (CTRL-X) SPACE EQU $20 DEL EQU $7F rubout (delete) SPC 1 * M6809 equates: SETZ EQU %00000100 set Z bit mask (ORCC #SETZ) CLRZ EQU %11111011 clear Z bit mask (ANDCC #CLRZ) PAGE *+ * SUBROUTINE: CB1HEX * Convert a 4-bit binary number to a hexadecimal ASCII character. * ENTRY PARAMETERS: A = the 4-bit binary number (right justified). * EXIT CONDITIONS: A contains the hexadecimal character. * CC is indeterminate. *- SPC 1 CB1HEX ANDA #$F remove anything in the m.s. half byte CMPA #9 BLS CB1HX1 branch if number is 0-9 ADDA #7 number is 10-15 so add 7 to make it A-F SPC 1 CB1HX1 ADDA #'0 add the ASCII offset RTS SPC 5 *+ * SUBROUTINE: OP1HEX * Output to the system terminal a 4-bit binary number as a hexadecimal * ASCII character. * ENTRY PARAMETERS: A = the 4-bit binary number (right justified). * U = the pointer to the global variables. * EXIT CONDITIONS: A and U are unchanged. * CC is indeterminate. *- SPC 1 OP1HEX PSHS A save the binary number BSR CB1HEX convert the number to its ASCII equivalent LBSR OPCHAR and output it to the system terminal PULS A,PC restore the binary number and exit LDA A,Z EXAMPLE ERROR SPC 5 *+ * SUBROUTINE: CB2HEX * Converts an 8-bit binary number to 2 hexadecimal ASCII characters. * ENTRY PARAMETERS: A = the 8-bit binary number. * EXIT CONDITIONS: A = the m.s. ASCII character. * B = the l.s. ASCII character. * CC is indeterminate. *- SPC 1 CB2HEX TFR A,B save the binary number BSR CB1HEX convert the l.s. half byte EXG A,B save the l.s. ASCII character in B; original 8-bit number to A LSRA shift the m.s. half byte into the l.s half byte LSRA LSRA LSRA BSR CB1HEX RTS leave the m.s. ASCII character in A TFR X,PC ANOTHER EXAMPLE ERROR! PAGE *+ * SUBROUTINE: OP2HEX * Output an 8-bit binary number as 2 hexadecimal ASCII characters. * ENTRY PARAMETERS: A = the 8-bit binary number. * U = the pointer to the global variables. * EXIT CONDITIONS: A and U are unchanged. * CC is indeterminate. *- SPC 1 OP2HEX PSHS D save the binary number BSR CB2HEX convert the number to its ASCII equivalents LBSR OPCHAR output the m.s. ASCII number TFR B,A LBSR OPCHAR output the l.s. ASCII number PULS D,PC restore the binary number and exit SPC 5 *+ * SUBROUTINE: CB4HEX * Convert a 16-bit binary number to 4 hexadecimal ASCII characters. * ENTRY PARAMETERS: X = the 16-bit binary number. * EXIT CONDITIONS: A contains the m.s ASCII character. * B contains the m.s.-1 ASCII character. * X contains the l.s.+1 and the l.s. ASCII character. * CC is indeterminate. *- SPC 1 CB4HEX TFR X,D A:B contains the number PSHS A save the m.s. byte TFR B,A BSR CB2HEX convert the l.s byte (in A) to its ASCII character equivalents TFR D,X save the 2 l.s. characters in X PULS A restore the m.s byte BSR CB2HEX convert the m.s. byte to its ASCII character equivalents RTS leaving them in A:B SPC 5 *+ * SUBROUTINE: OP4HEX * Output to the system terminal a 16-bit binary number as 4 hexadecimal * ASCII characters. * ENTRY PARAMETERS: X = the 16-bit binary number. * U = the pointer to the global variables. * EXIT CONDITIONS: X and U are unchanged. * CC is indeterminate. *- SPC 1 OP4HEX PSHS D,X save the binary number BSR CB4HEX convert the 16-bit number to 4 hexadecimal characters LBSR OPCHAR output the m.s. character TFR B,A LBSR OPCHAR output the m.s.-1 character TFR X,D LBSR OPCHAR output the l.s.+1 character TFR B,A LBSR OPCHAR output the l.s. character PULS D,X,PC restore the binary number and exit PAGE *+ * SUBROUTINE: C1HXBN * Convert a hexadecimal ASCII character to a 4-bit binary number. * ENTRY PARAMETERS: A = the ASCII character. * EXIT CONDITIONS: If the character is hexadecimal: A contains the 4-bit * A contains the 4-bit binary number; * Z = 1. * Otherwise A is unchanged and Z = 0. * The rest of CC is indeterminate. *- SPC 1 C1HXBN CMPA #'0 BLO C1HXB2 branch if less than "0" (not hexadecimal) CMPA #'9 BLS C1HXB1 branch if "0" - "9" (is hexadecimal) CMPA #'A BLO C1HXB2 branch if ":" - "@" (not hexadecimal) CMPA #'F BHI C1HXB2 branch if greater than "F" (not hexadecimal) SUBA #7 character is "A" - "F"; so make it 10-15 SPC 1 C1HXB1 SUBA #'0 remove the ASCII offset ORCC #SETZ Z=1; the character is hexadecimal RTS normal exit: A = the 4-bit binary number SPC 1 C1HXB2 ANDCC #CLRZ Z=0; the character is not hexadecimal RTS abnormal exit: A = the ASCII character SPC 5 *+ * SUBROUTINE: C2HXBN * Convert 2 hexadecimal ASCII characters to an 8-bit binary number. * ENTRY PARAMETERS: X = the address of the first character. * EXIT CONDITIONS: If both characters are hexadecimal: * A contains the 8-bit binary number; * X contains the address+1 of the 2nd. character; * Z = 1. * If a character is not hexadecimal: * A is indeterminate; * X contains the address of the 1st. non-hex character. * Z = 0. * The rest of CC is indeterminate. *- SPC 1 C2HXBN PSHS B LDA ,X+ fetch the 1st. charcter and point to the 2nd. one BSR C1HXBN convert the character to binary BNE C2HXB1 branch if the character is not hexadecimal TFR A,B save the binary number LSLB shift the 4-bit binary number from the l.s. half-byte LSLB into the m.s. half-byte LSLB LSLB LDA ,X+ fetch the 2nd. character and update the pointer BSR C1HXBN convert the character to binary BNE C2HXB1 branch if the character is not hexadecimal PSHS B ADDA ,S+ add A to B (combining the 2 numbers) leaving result in acc.A ORCC #SETZ Z=1; both characters are hexadecimal PULS B,PC exit leaving the 8-bit binary number in A SPC 1 C2HXB1 LEAX -1,X 'backspace' the pointer to the non-hex character ANDCC #CLRZ Z=0; non-hexadecimal character was found PULS B,PC abnormal exit SPC 5 *+ * SUBROUTINE: C4HXBN * Convert 4 hexadecimal ASCII characters to a 16-bit binary number. * ENTRY PARAMETERS: X = the address of the first character. * EXIT CONDITIONS: If all characters are hexadecimal: * D contains the 16-bit binary number; * X contains the address+1 of the 4th. character; * Z = 1. * If a character is not hexadecimal: * D is indeterminate; * X contains the address of the 1st. non-hex character. * Z = 0. * The rest of CC is indeterminate. *- SPC 1 C4HXBN BSR C2HXBN convert the first two characters to binary PSHS A save the result (m.s. byte of the 16-bit number) BNE C4HXB1 branch if a non-hexadecmal character was found BSR C2HXBN convert the second two characters to binary BNE C4HXB1 branch if a non-hexadecimal character was found TFR A,B leave the l.s byte of the 16-bit number in B ORCC #SETZ Z=1; all characters are hexadecimal PULS A,PC exit leaving the m.s. byte in A (i.e. 16-bit number in D) SPC 1 C4HXB1 ANDCC #CLRZ Z=0; a non-hexadecimal character was found PULS A,PC exit: D is indeterminate SPC 3 END