.TITLE ZPRINT .IDENT /V1.3/ ; ++ ; This is the Z-machine emulator printer routines. ; (c) 2000 by Johnny Billquist ; ; History: ; ; X1.0 00-10-27 23:00 BQT Initial coding started. ; V1.1 00-11-03 16:15 BQT Added error checks after calls. ; V1.2 05-02-22 23:15 BQT Rewrote code for better and tidier handling. ; V1.3 08-09-04 16:30 BQT Changed GETSCR calling setup. ; -- .INCLUDE /ZMAC/ ; .PSECT DATA,D,RW ; PRBUF: .BLKB 80. PREND: .WORD 0 PRPTR: .WORD PRBUF ; PRFLG: .WORD 0 ; Script flags. ; .PSECT TEXT,D,RO ; QNAM: .ASCIZ /Transcript to file: / FAIL: .ASCIZ /Transcript failed./<15><12> ABOTXT: .ASCIZ /Transcript aborted./<15><12> ; .PSECT CODE,I,RO ; ; PRNCHR - Print character. ; ; In: R1 - Character to print. ; PRNCHR:: JSR R2,$SAVVR ; Save registers. MOV ZEROP,R0 ; Check flag. BIT #400,20(R0) ; Transcript on? (100h,10h) BNE 1$ ; Yes. RETURN ; No. 1$: ; CMP OLDFON,#1 ; If font isn't 1, we don't print... ; BNE 25$ BIT #1,PRFLG ; Do we have a file open? BNE 10$ ; Yes. CALL PRNOPN ; No. Open file. BCC 10$ ; Worked fine... 5$: RETURN ; Ummm... Bad. Drop it. ; ; Time to put character in buffer, and work from there. ; 10$: MOV PRPTR,R2 ; Get pointer. CMPB R1,#15 ; Check if printable... BNE 20$ ; ; We have a CR. Let's print the line we have. ; CLR -(SP) ; To fake the same as wrap, we push a 0 ; for residual string. BR 35$ ; And continue there. ; 20$: CMPB R1,#12 ; LF? BEQ 5$ ; Yes. Just drop it. ; ; Now we have a plain char to print. ; CMPB R1,#' ; Space? BNE 21$ ; No. BIT #2,PRFLG ; Yes. Are we gobbling? BNE 5$ ; Yes. Ignore char. 21$: BIC #2,PRFLG ; No. Clear gobble. MOVB R1,(R2)+ ; Save it in buffer. CMP R2,#PREND ; Do we have a full buffer? BLOS 40$ ; No. Proceed. ; ; We have a full buffer. We should wrap. ; BIS #2,PRFLG ; Assume we want to gobble. CLR R0 ; Count how many saved. 30$: INC R0 ; Bump count. MOVB -(R2),-(SP) ; Save one more. CMPB (R2),#40 ; Space? BNE 30$ ; No. Repeat. DEC R0 ; Yes. Remove space from count. MOV R0,(SP) ; Save count. 35$: CLRB (R2) ; Mark end of buffer. MOV #PRBUF,R0 ; Get start of buffer. SUB R0,R2 ; And length. MOV R2,R1 ; Setup length in R1. CALL SCRBLK ; Put scripting text. BCS 90$ ; Error... MOV R0,R2 ; Pointer in R2. MOV (SP)+,R0 ; Get count back. BEQ 40$ BIC #2,PRFLG ; We have chars carry over. No gobble. 37$: MOVB (SP)+,(R2)+ ; Restore text. SOB R0,37$ ; Repeat for all characters. ; 40$: MOV R2,PRPTR ; Save new pointer. RETURN ; ; Scripting failed... ; 90$: MOV (SP)+,R0 ; Restore stack... ASL R0 ADD R0,SP CALL SCRCLO ; Close file. BIC #1,PRFLG ; Clear open flag. MOV #ABOTXT,R0 ; Error message. CALL SCRTXT ; Print message. MOV ZEROP,R0 ; Clear scripting flag. BIC #400,20(R0) ; (100h,10h) RETURN ; ; PRNOPN - Open transcript file. ; ; R0 - Zero page. ; PRNOPN: JSR R2,$SAVVR ; Save registers. BIC #400,20(R0) ; Clear script flag. (100h,10h) MOV #QNAM,R0 ; Prompt... CALL SCRTXT CLR TMO ; No timeout. MOV #FNAM,R0 ; Read filename. MOV R0,R1 MOV #FNAML-1,R2 CALL GETSTR CLRB (R0) ; Terminate filename. MOV R0,R1 MOV #FNAM,R0 ; Get pointer to filename. SUB R0,R1 ; Get length of filename. CALL SCROPN ; Open scripting file. BCS 10$ ; Fail. BIS #1,PRFLG ; Success. Indicate that file is open. MOV ZEROP,R2 BIS #400,20(R2) ; Restore script flag. (100h,10h) RETURN ; ; Open failed. ; 10$: MOV #FAIL,R0 CALL SCRTXT ; Print message. SEC RETURN ; ; PRSTOP - Stop transcription and close file. ; PRSTOP:: BIT #1,PRFLG ; Are we transcribing? BNE 1$ ; Yes. RETURN ; No. ; 1$: BIC #1,PRFLG ; Clear open flag. MOV PRPTR,R1 ; Yes. Get pointer. CLRB (R1) MOV #PRBUF,R0 SUB R0,R1 BEQ 10$ ; Buffer was empty. CALL SCRBLK ; Something in there. Flush it. 10$: CALLR SCRCLO ; Close file. ; .END