*++ ****** STUB EXTERNAL REFERENCES ****** XREF ..DIN,..DOUT,..JSR,..RTS,..CTOX,..CREP XREF ..DPR,..DPW,..CLRAB,..MUL,..INIT,..VREP *+ * 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 SPC 3 * NAM MAXBG2 IDNT 1,1 * TTL MAXBUG TTL MAXBUG A1.0 - conversion subroutines * IDNT ** WARNING ** * NOT SUPPORTED : USE "NAM" DIRECTIVE * * SPC 1 SPC 1 * XREF OPCHAR XREF OPCHAR * XDEF CB1HEX,OP1HEX,CB2HEX,OP2HEX,CB4HEX,OP4HEX,C1HXBN,C2HXBN,C4HXBN XDEF CB1HEX,OP1HEX,CB2HEX,OP2HEX,CB4HEX,OP4HEX,C1HXBN,C2HXBN,C4HXBN * SPC 3 SPC 3 * ASCII character equates: * EQU 0 NULL EQU 0 * EQU 4 EOT EQU 4 (CTRL-D) * EQU 7 BELL EQU 7 * EQU $A LF EQU $A line feed * EQU $D CR EQU $D carriage return * EQU $C FF EQU $C form feed * EQU $17 ETB EQU $17 (CTRL-W) * EQU $18 CAN EQU $18 cancel (CTRL-X) * EQU $20 SPACE EQU $20 * EQU $7F DEL EQU $7F rubout (delete) * SPC 1 SPC 1 * M6809 equates: * EQU %00000100 SETZ EQU %00000100 set Z bit mask (ORCC #SETZ) * EQU %11111011 CLRZ EQU %11111011 clear Z bit mask (ANDCC #CLRZ) * PAGE 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 SPC 1 * ANDA #$F CB1HEX AND.B #$F,D0 remove anything in the m.s. half byte ** WARNING ** * C-BIT CLEARED * * CMPA #9 CMP.B #9,D0 * BLS CB1HX1 BLS CB1HX1 branch if number is 0-9 * ADDA #7 ADD.B #7,D0 number is 10-15 so add 7 to make it A-F * SPC 1 SPC 1 * ADDA #'0 CB1HX1 ADD.B #'0',D0 add the ASCII offset * RTS BSR ..RTS * SPC 5 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 SPC 1 * PSHS A OP1HEX MOVEM.L D0,-(A6) save the binary number * BSR CB1HEX BSR CB1HEX convert the number to its ASCII equivalent * BSR OPCHAR BSR OPCHAR and output it to the system terminal * PULS A,PC MOVEM.L (A6)+,D0 restore the binary number and exit MOVE.L (A6)+,A3 JMP (A3) ** ERROR ** Invalid second (index) register * LDA A,Z EXAMPLE ERROR * SPC 5 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 SPC 1 * TFR A,B CB2HEX MOVE.L D0,D1 save the binary number BSR ..CLRAB * BSR CB1HEX BSR CB1HEX convert the l.s. half byte * EXG A,B EXG.L D0,D1 save the l.s. ASCII character in B; original 8- * bit number to A * LSRA LSR.B #1,D0 shift the m.s. half byte into the l.s half byte ** WARNING ** * V-BIT CLEARED * * LSRA LSR.B #1,D0 ** WARNING ** * V-BIT CLEARED * * LSRA LSR.B #1,D0 ** WARNING ** * V-BIT CLEARED * * LSRA LSR.B #1,D0 ** WARNING ** * V-BIT CLEARED * * BSR CB1HEX BSR CB1HEX * RTS BSR ..RTS leave the m.s. ASCII character in A ** ERROR ** PC not supported * TFR X,PC ANOTHER EXAMPLE ERROR! * PAGE 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 SPC 1 * PSHS D OP2HEX MOVEM.L D0/D1,-(A6) save the binary number * BSR CB2HEX BSR CB2HEX convert the number to its ASCII equivalents * BSR OPCHAR BSR OPCHAR output the m.s. ASCII number * TFR B,A MOVE.L D1,D0 BSR ..CLRAB * BSR OPCHAR BSR OPCHAR output the l.s. ASCII number * PULS D,PC MOVEM.L (A6)+,D0/D1 restore the binary number and exit MOVE.L (A6)+,A3 JMP (A3) * SPC 5 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 SPC 1 * TFR X,D CB4HEX BSR ..DIN A:B contains the number MOVE.L A0,D2 BSR ..CLRAB BSR ..DOUT * PSHS A MOVEM.L D0,-(A6) save the m.s. byte * TFR B,A MOVE.L D1,D0 BSR ..CLRAB * BSR CB2HEX BSR CB2HEX convert the l.s byte (in A) to its ASCII charac * ter equivalents * TFR D,X BSR ..DIN save the 2 l.s. characters in X MOVE.L D2,A0 BSR ..CLRAB BSR ..DOUT * PULS A MOVEM.L (A6)+,D0 restore the m.s byte * BSR CB2HEX BSR CB2HEX convert the m.s. byte to its ASCII character eq * uivalents * RTS BSR ..RTS leaving them in A:B * SPC 5 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 SPC 1 * PSHS D,X OP4HEX MOVEM.L D0/D1/A0,-(A6) save the binary number * BSR CB4HEX BSR CB4HEX convert the 16-bit number to 4 hexadecimal char * acters * BSR OPCHAR BSR OPCHAR output the m.s. character * TFR B,A MOVE.L D1,D0 BSR ..CLRAB * BSR OPCHAR BSR OPCHAR output the m.s.-1 character * TFR X,D BSR ..DIN MOVE.L A0,D2 BSR ..CLRAB BSR ..DOUT * BSR OPCHAR BSR OPCHAR output the l.s.+1 character * TFR B,A MOVE.L D1,D0 BSR ..CLRAB * BSR OPCHAR BSR OPCHAR output the l.s. character * PULS D,X,PC MOVEM.L (A6)+,D0/D1/A0 restore the binary number and exit MOVE.L (A6)+,A3 JMP (A3) * PAGE 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 SPC 1 * CMPA #'0 C1HXBN CMP.B #'0',D0 * BLO C1HXB2 BCS C1HXB2 branch if less than "0" (not hexadecimal) * CMPA #'9 CMP.B #'9',D0 * BLS C1HXB1 BLS C1HXB1 branch if "0" - "9" (is hexadecimal) * CMPA #'A CMP.B #'A',D0 * BLO C1HXB2 BCS C1HXB2 branch if ":" - "@" (not hexadecimal) * CMPA #'F CMP.B #'F',D0 * BHI C1HXB2 BHI C1HXB2 branch if greater than "F" (not hexadecimal) * SUBA #7 SUB.B #7,D0 character is "A" - "F"; so make it 10-15 * SPC 1 SPC 1 * SUBA #'0 C1HXB1 SUB.B #'0',D0 remove the ASCII offset * ORCC #SETZ ORI.B #SETZ,CCR Z=1; the character is hexadecimal ** WARNING ** * E-BIT NOT SUPPORTED * * RTS BSR ..RTS normal exit: A = the 4-bit binary number * SPC 1 SPC 1 * ANDCC #CLRZ C1HXB2 ANDI.B #CLRZ,CCR Z=0; the character is not hexadecimal ** WARNING ** * E-BIT NOT SUPPORTED * * RTS BSR ..RTS abnormal exit: A = the ASCII character * SPC 5 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 SPC 1 * PSHS B C2HXBN MOVEM.L D1,-(A6) * LDA ,X+ MOVE.B (A0)+,D0 fetch the 1st. charcter and point to the 2nd. o * ne ** WARNING ** * C-BIT CLR * * BSR C1HXBN BSR C1HXBN convert the character to binary * BNE C2HXB1 BNE C2HXB1 branch if the character is not hexadecimal * TFR A,B MOVE.L D0,D1 save the binary number BSR ..CLRAB * LSLB LSL.B #1,D1 shift the 4-bit binary number from the l.s. hal * f-byte ** WARNING ** * V-BIT CLEARED * * LSLB LSL.B #1,D1 into the m.s. half-byte ** WARNING ** * V-BIT CLEARED * * LSLB LSL.B #1,D1 ** WARNING ** * V-BIT CLEARED * * LSLB LSL.B #1,D1 ** WARNING ** * V-BIT CLEARED * * LDA ,X+ MOVE.B (A0)+,D0 fetch the 2nd. character and update the pointer ** WARNING ** * C-BIT CLR * * BSR C1HXBN BSR C1HXBN convert the character to binary * BNE C2HXB1 BNE C2HXB1 branch if the character is not hexadecimal * PSHS B MOVEM.L D1,-(A6) * ADDA ,S+ ADD.B (A6)+,D0 add A to B (combining the 2 numbers) leaving re * sult in acc.A * ORCC #SETZ ORI.B #SETZ,CCR Z=1; both characters are hexadecimal ** WARNING ** * E-BIT NOT SUPPORTED * * PULS B,PC MOVEM.L (A6)+,D1 exit leaving the 8-bit binary number in A MOVE.L (A6)+,A3 JMP (A3) * SPC 1 SPC 1 * LEAX -1,X C2HXB1 LEA.L -1(A0),A0 'backspace' the pointer to the non-hex characte * r ** WARNING ** * Z-BIT NOT MODIFIED * * ANDCC #CLRZ ANDI.B #CLRZ,CCR Z=0; non-hexadecimal character was found ** WARNING ** * E-BIT NOT SUPPORTED * * PULS B,PC MOVEM.L (A6)+,D1 abnormal exit MOVE.L (A6)+,A3 JMP (A3) * SPC 5 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 SPC 1 * BSR C2HXBN C4HXBN BSR C2HXBN convert the first two characters to binary * PSHS A MOVEM.L D0,-(A6) save the result (m.s. byte of the 16-bit number * ) * BNE C4HXB1 BNE C4HXB1 branch if a non-hexadecmal character was found * BSR C2HXBN BSR C2HXBN convert the second two characters to binary * BNE C4HXB1 BNE C4HXB1 branch if a non-hexadecimal character was found * TFR A,B MOVE.L D0,D1 leave the l.s byte of the 16-bit number in B BSR ..CLRAB * ORCC #SETZ ORI.B #SETZ,CCR Z=1; all characters are hexadecimal ** WARNING ** * E-BIT NOT SUPPORTED * * PULS A,PC MOVEM.L (A6)+,D0 exit leaving the m.s. byte in A (i.e. 16-bit nu * mber in D) MOVE.L (A6)+,A3 JMP (A3) * SPC 1 SPC 1 * ANDCC #CLRZ C4HXB1 ANDI.B #CLRZ,CCR Z=0; a non-hexadecimal character was found ** WARNING ** * E-BIT NOT SUPPORTED * * PULS A,PC MOVEM.L (A6)+,D0 exit: D is indeterminate MOVE.L (A6)+,A3 JMP (A3) * SPC 3 SPC 3 * END END