NEW AUTO REM Wait until printer free - WAIT REM This is a utility designed for a user to invoke when he or she REM requires a listing and the printer is currently busy. REM REM The command line syntax = *wait 'string' REM REM REM The string is to be inserted into the KB buffer when the REM printer becomes free; the printer server number is to be set up REM if it is supplied; the network printer destination is to be selected REM as a matter of course. DIM Code 255 OSWORD = &FFF1 OSBYTE = &FFF4 OSASCI = &FFE3 OSNEWL = &FFE7 OSARGS = &FFDA OSRDCH = &FFE0 GSINIT = &FFC2 GSREAD = &FFC5 ZP = &A8 ;zero page work area LINE = &F2 STRING = 31 FOR Pass = 4 TO 6 STEP 2 O% = Code P% = &900 ;lives in the cassette buffers [OPT Pass .Entry Lda #1 Ldx #ZP Ldy #0 Jsr OSARGS ;read command line pointer \ now read past the first string bit Lda ZP Sta LINE Lda ZP+1 Sta LINE+1 Lda (ZP),Y Cmp #ASC("=") Jsr PREAD .NOPS Ldx #(-1) AND &FF Sec Jsr GSINIT ;read until CR or 2nd quote .SKIP Jsr GSREAD Inx Php Cpx #STRING Bcc AOK Brk EQUB &40: EQUS "String too long": EQUB &00 .AOK Plp Sta TEXT,X ;read the string into TEXT Bcc SKIP ;until terminator Stx TOTAL ;number of characters in the string Jsr PSREAD ;read the printer server number Lda PSCB+1 Sta RXCB+3 Sta TXCB+2 Lda PSCB+2 Sta RXCB+4 Sta TXCB+3 ;copy the PS into the control blocks .LOOP Lda #0 Sta RXCB ;reset for each loop Sta COUNT Sta LENGTH ;initial offset within TEXT Lda #&11 Ldx #RXCB Ldy #(RXCB) DIV 256 Jsr OSWORD ;open an Rxcb Lda RXCB ;check all ok Bne RXOPEN Brk EQUB &FE: EQUS "Unable to open Rxcb": EQUB &00 .RXOPEN Lda #&10 Sta COUNT+2 ;'seconds' counter Ldx #TXCB Ldy #(TXCB) DIV 256 Jsr OSWORD ;initiate Tx Lda TXCB ;check Tx initiated ok Bne TXOK Lda #&80 Sta TXCB Bne RXOPEN ;try again .TXOK Lda #50 Jsr OSBYTE Txa Bmi TXOK ;poll Tx to completion Beq POLL Jsr ESC ;poll escape flag Dec COUNT Bne RXOPEN ;once more (with feeling) Jsr DELRX ;clean up before error Brk EQUB &A2: EQUS "Not listening": EQUB &00 \ PS has now been sent the packet, so poll for a reply .POLL Ldx RXCB ;rx number Lda #51 Jsr OSBYTE Txa Bmi RX ;caught a packet Jsr WAIT Bne POLL ;poll for a bit Jsr DELRX ;clean up before error Brk EQUB &A7: EQUS "No Reply": EQUB &00 .RX Jsr DELRX Lda RXBUF Beq CLEAR ;all ok here Cmp #2 Bne SKIP3 Brk EQUB &A0: EQUS "Jammed": EQUB &00 .SKIP3 Lda #2 Sta COUNT+2 .SKIP4 Jsr WAIT ;wait for a couple of seconds Bne SKIP4 Jmp LOOP ;do it all over again .CLEAR Lda #5 Ldx #4 Jsr OSBYTE ;select net printer destination .CLEAR1 Ldx LENGTH Cpx TOTAL Beq EXIT ;all chars dealt with yet ? Ldy TEXT,X Ldx #0 ;key board buffer here Lda #138 Jsr OSBYTE Inc LENGTH Bne CLEAR1 ;put the chars into the KB buffer .EXIT Rts ;and return to the user .DELRX Ldx RXCB Lda #52 Jmp OSBYTE ;delete rxcb .PREAD Bne PEKOK2 ;only read if valid specifier Sty PSCB+2 ;Y passed as zero here .PREAD1 Iny Lda (ZP),Y Cmp #&20 Beq PREAD1 Jsr PECIN Bcc PEKOK1 ;found a '.' Sta PSCB+2 Iny Jsr PECIN .PEKOK1 Beq PEKOK Sta PSCB+1 Lda #3 Sta PSCB .PSREAD Sty ZP+4 Ldx #PSCB Ldy #(PSCB) DIV 256 Lda #&13 Jsr OSWORD ;set the PS number Ldy ZP+4 .PEKOK2 Lda #2 Sta PSCB ;ready to read it again .PEKOK Rts .PECIN Lda #0 Sta ZP+2 .PECIN1 Lda (ZP),Y Cmp #&40 Bcs PECIN3 Cmp #ASC(".") Beq PECIN2 Bmi PECIN3 And #&0F Sta ZP+3 ;addition routine Asl ZP+2 Lda ZP+2 AslA AslA Adc ZP+2 Adc ZP+3 Sta ZP+2 Iny Bne PECIN1 .PECIN3 Clc .PECIN2 Lda ZP+2 ;return A as number read .PECIN4 Rts .ESC Bit &FF ;look at top bit Bpl PECIN4 Jsr DELRX ;clean up before error Brk EQUB &11: EQUS "Escape": EQUB &00 .WAIT Jsr ESC ;poll escape Dec COUNT Bne WAITX Dec COUNT+1 Bne WAITX Dec COUNT+2 .WAITX Rts ;returns Z if timeout TXCB = &80 EQUB &9F EQUW &0000 EQUW TXBUF EQUW &FFFF EQUW TXBUFE EQUW &FFFF RXCB = &00 EQUB &7F EQUB &9E EQUW &0000 EQUW RXBUF EQUW &FFFF EQUW RXBUFE EQUW &FFFF .TXBUF EQUS "PRINT ": EQUB 1 .TXBUFE EQUB TXBUF+7 .TOTAL EQUB TXBUFE .LENGTH EQUB TOTAL+1 .RXBUF EQUB LENGTH+1 .RXBUFE = RXBUF+4 .COUNT EQUB RXBUFE .PSCB EQUB COUNT .TEXT EQUB PSCB+3 ] NEXT Pass OSCLI ("SAVE Wait2 "+STR$~(Code)+" +100")