.TITLE ENCODE ... encode binary data and store in .ASCIZ string .IDENT /030982/ .ENABL LC ; ; ; Written by Ray Di Marco ; 3-Sep-82 ; ;---------------------------------------------------------------------------- ; ; This module contains the definition for the ENCODE macro and the code for ; ENCODE routine. The ENCODE routine is called with R0 and R1 holding the ; address of an ENCODE table and a .ASCIZ string respectively. The routine ; will output the string via the .TTYOUT emt as if a .PRINT was performed ; on it; the only difference is that the ???? characters in the string ; will be replaced by the ascii equivalent of the specified numbers. ; ; Notes The string to be output may be terminated by a or by ; a negative byte ; ; The entries in the ENCODE table a generated with the ENCODE macro; ; the table is terminated by a zero word. ; .SBTTL Macro - "ENCODE" ... encode binary data ; ; This macro is used to setup a table; the table consists of two word ; entries; the first word is the address of a number; the second word ; is the format specifier that is used is as per the CNAF macro. ; .MACRO ENCODE FIELD,ADDRESS ZZZZZZ = 0 ZZZZZB = 0 ZZZZZR = 0 .IRPC X, ZZZZZA = -1 .IIF IDN,X,H,ZZZZZA = 3 .IIF IDN,X,D,ZZZZZA = 3 .IIF IDN,X,O,ZZZZZA = 3 .IF NE,ZZZZZA+1 .IF EQ,ZZZZZR .IIF IDN,X,H,ZZZZZR=2 .IIF IDN,X,D,ZZZZZR=1 .ENDC .ENDC .IIF IDN,X,S,ZZZZZA = 2 .IIF IDN,X,F,ZZZZZA = 1 .IF EQ,ZZZZZA+1 .ERROR FIELD ; ILLEGAL F I E L D SPECIFIER .MEXIT .ENDC ZZZZZZ = + ZZZZZA ZZZZZB = ZZZZZB + 1 .ENDR .IF GT,ZZZZZB-7 .ERROR FIELD ; F I E L D SIZE TO LARGE .MEXIT .ENDC ZZZZZZ = ZZZZZZ*4 .WORD ZZZZZZ!ZZZZZR,ADDRESS .ENDM ENCODE ; ; .SBTTL Routine - "ENCODE" ... encode data ; .MCALL .TTYOUT,.PRINT,.PUSH,.POP ; fetch macros .GLOBL ENCODE,CNAF .PSECT CODE ; ; This routine is called with R0 holding the address of an encoding table ; and R1 pointing to a .ASCIZ string. The routine will encode the data in ; the table and store the resulting characters in the string. All registers ; are preserved. ; ; ENCODE: .PUSH ; save registers SUB #12,SP ; reserve room on stack MOV SP,R5 ; R5 -> string buffer MOV R0,R3 ; R3 -> table MOV R1,R4 ; R4 -> string BR 1100$ ; enter loop ; 1000$: .TTYOUT ; output character 1100$: MOVB (R4)+,R0 ; R0 = next character BEQ 6000$ ; skip if BMI 6100$ ; skip if <200> CMPB R0,#'? ; field marker? BNE 1000$ ; no -> process TST (R3) ; EOT? BEQ 1000$ ; yes -> ignore ; 2000$: CMPB (R4)+,#'? ; end of field? BEQ 2000$ ; no -> loop DEC R4 ; rewind pointer MOV (R3)+,R0 ; R0 = format MOV R5,R1 ; R1 -> buffer MOV @(R3)+,R2 ; R2 = number CALL CNAF ; convert to ascii MOVB #200,(R1) ; terminate .PRINT R5 ; print BR 1100$ ; loop ; 6000$: .TTYOUT #15 ; output .TTYOUT #12 ; output 6100$: 7000$: ADD #12,SP ; reslease buffer .POP ; restore registers RETURN ; all done ; .END