.MCALL .GTLIN .CSISPC .DSTAT .LOOKUP .ENTER .READW .WRITW .MCALL .SPFUN .WAIT .CLOSE .PRINT .SERR .HERR .MCALL .QSET .HRESET .FETCH .SETTOP .SRESET .ENABL LC .TITLE CP - GENERAL-PURPOSE COPY ;+++ ; ; Developed by: Lachman Associates, Inc. (MWB) ; 645 Blackhawk Drive ; Westmont, IL 60559 ; ; (312) 986 8840 ; ; ; Permission is granted to use this software under the following ; conditions: ; 1) It is not sold, or distributed for profit. ; 2) That these comments acknowledging the author ; remain intact. ; ;--- BLKFAC = 10. ; Default blocking factor. QCOUNT = 3. ; Additional queue block count. .MACRO ERRMSG MSG,?STRING,?OK .ENABL LSB BCC OK JSR R5,ERROR .WORD STRING .PSECT STRNGS STRING: .ASCIZ /'MSG'/ .PSECT OK: .ENDM ERRMSG ;************************ ;* cp * ;************************ ; ;General-purpose copy. ; ; ; CP: MOV @#50,PRGEND ; Save -> initial free memory. AGAIN: CALL INIT ; Initialize. CALL PROC ; Process. CALL TERM ; Terminate. BR AGAIN ; Reinitialize for more. ;************************ ;* init * ;************************ ; ;Initialize. ; ; ; INIT: .SRESET ; Clean up. MOV PRGEND,MEMFRE ; Reset -> free memory. CLRB IMT ; Reset input-from-magtape flag. CLRB OMT ; Reset output-to-magtape flag. CLRB OIMG ; Reset output image copy flag. CLR IBLK ; Reset input block number. CLR OBLK ; Reset output block number. CLR BLKLIM ; Reset transfer length. CLR ISEQ ; Reset input file sequence number. MOV #-1,OSEQ ; Reset output file sequence number. MOV #BLKFAC,BLOCKF ; Reset blocking factor. .SERR ; We'll handle hard errors. .QSET #QSPACE,#QCOUNT ; Allocate additional queue blocks. ERRMSG ; Check for error. MOV SP,R4 ; Save SP. .CSISPC #OUTSPC,#DEFEXT ; Obtain filespecs. ERRMSG ; Check for error. MOV (SP)+,R5 ; Load option count. OPTNXT: DEC R5 ; Any more options? BMI OPTEND ; No- go restore SP. MOV (SP)+,R3 ; Load option description. CMPB R3,#'M ; File sequence number? BEQ OPTSEQ ; Yes- go process it. CMPB R3,#'B ; Blocking factor? BEQ OPTFAC ; Yes- go process it. CMPB R3,#'V ; Display version number? BEQ OPTVER ; Yes- go do it. CMPB R3,#'I ; Image copy? BEQ OPTIMG ; Yes- go process it. CMPB R3,#'L ; Length specification? BEQ OPTLEN ; Yes- go process it. CMPB R3,#'S ; Starting block number? BEQ OPTSTA ; Yes- go process it. SEC ; Force error. ERRMSG ; Display message and abort. OPTSEQ: MOV #-1,R2 ; Load default option value. SWAB R3 ; Value given? BPL SEQDFL ; No- continue with default. MOV (SP)+,R2 ; Load explicit sequence number. SEQDFL: BICB #200,R3 ; Channel zero? BEQ OSQOUT ; Yes- go store output seqnum. MOV R2,ISEQ ; Store input file sequence number. BR OPTNXT ; Go do next option. OSQOUT: MOV R2,OSEQ ; Store output file sequence number. BR OPTNXT ; Go do next option. OPTIMG: SWAB R3 ; Value specified? BPL IMGNOV ; No- continue. TST (SP)+ ; Yes- bypass value. IMGNOV: BICB #200,R3 ; Channel zero? BNE OPTNXT ; No- ignore flag. CLR OFSPEC+2 ; Clear output filename. CLR OFSPEC+4 ; Clear second word of output filename. CLR OFSPEC+6 ; Clear output filename extension. BR OPTNXT ; Go get next option. OPTFAC: SWAB R3 ; Value specified? BPL OPTNXT ; No- ignore option. BIC #^C177,@SP ; Limit to positive byte-integer. MOV (SP)+,BLOCKF ; Store explicit blocking factor. BR OPTNXT ; Go get next option. OPTVER: .PRINT #VERSN ; Display version identification. BR OPTNXT ; Go get next option. OPTLEN: TST R3 ; Value specified? BPL OPTNXT ; No- ignore option. MOV (SP)+,BLKLIM ; Store transfer limit. BR OPTNXT ; Go get next option. OPTSTA: SWAB R3 ; Value specified? BPL OPTNXT ; No- ignore option. BICB #200,R3 ; Channel zero? BEQ OPTSTO ; Yes- go store output starting block. MOV (SP)+,IBLK ; Store initial input block number. BR OPTNXT ; Go get next option. OPTSTO: MOV (SP)+,OBLK ; Store initial output block number. BR OPTNXT ; Go get next option. OPTEND: MOV R4,SP ; Restore SP from before CSISPC. .DSTAT #RETSPC,#IFSPEC ; Obtain input device status. ERRMSG ; Check for error. TST RETSPC+4 ; Resident handler? BNE HAVEIH ; Yes- skip FETCH request. MOV MEMFRE,R5 ; Load -> space for device handler. MOV RETSPC+2,R0 ; Load handler size. CALL SETTOP ; Allocate additional memory. .FETCH R5,#IFSPEC ; Load input device handler. ERRMSG ; Check for error. HAVEIH: TST BLKLIM ; Explicit block count? BNE KEEPBL ; Yes- hold on to it. MOV RETSPC+6.,BLKLIM ; Store input device size. KEEPBL: CMPB RETSPC,#11 ; Reading TU10 magtape? BNE LOOKUP ; No- continue. INCB IMT ; Yes- indicate input from magtape. LOOKUP: .LOOKUP #AREA,#3,#IFSPEC,ISEQ ; Open input file. ERRMSG ; Check for error. .DSTAT #RETSPC,#OFSPEC ; Obtain output device status. ERRMSG ; Check for error. TST RETSPC+4 ; Resident handler? BNE HAVEOH ; Yes- skip FETCH processing. MOV MEMFRE,R5 ; Load -> space for device driver. MOV RETSPC+2,R0 ; Load handler size. CALL SETTOP ; Ensure availability of memory. .FETCH R5,#OFSPEC ; Load output device driver. ERRMSG ; Check for error. HAVEOH: CMPB RETSPC,#11 ; Output to TU10 magtape? BNE NOTOMT ; No- continue. INCB OMT ; Yes- indicate output to magtape. NOTOMT: TST OFSPEC+2 ; Output filename specified? BNE ENTER ; Yes- go ENTER output file. .GTLIN #INBUF,#SURE ; Verify before destroying something. ERRMSG ; Check for error. CMPB INBUF,#'Y ; OK to continue? BEQ DSTROY ; Yes- go open output device. SEC ; Force error. ERRMSG ; Exit with message. DSTROY: .LOOKUP #AREA,#0,#OFSPEC ; Open output device. ERRMSG ; Check for error. BR OPENED ; Skip file-structured output setup. ENTER: .ENTER #AREA,#0,#OFSPEC,OFSPEC+10,OSEQ; Open output file. ERRMSG ; Check for error. OPENED: MOV BLOCKF,R0 ; Load records/block. SWAB R0 ; Compute words/buffer. ASL R0 ; Compute bytes/buffer. MOV MEMFRE,BUFADR ; Initialize -> I/O buffer. CALL SETTOP ; Allocate buffer space. RETURN ; Return. ;************************ ;* settop * ;************************ ; ;Allocate R0 additional bytes of memory. ; ; ; SETTOP: ADD MEMFRE,R0 ; Compute new -> end of memory. BCS MEMOVR ; Check for address space overflow. MOV R0,-(SP) ; Save -> requested end of memory. .SETTOP R0 ; Request memory from monitor. ERRMSG ; Check for error. CMP R0,(SP)+ ; Enough memory available? MEMOVR: ERRMSG ; No- display message and abort. MOV R0,MEMFRE ; Update -> end of memory. RETURN ; Return. ;************************ ;* proc * ;************************ ; ;Process. ; ; ; PROC: CALL READ ; Read a block - EOF? BEQ DONE ; Yes- go finish up. CALL WRITE ; Write a block. BR PROC ; Go get next block. DONE: RETURN ; Return. ;************************ ;* read * ;************************ ; ;Read a block. ; ; ; READ: TSTB IMT ; Input from magtape? BNE READMT ; Yes- go use SPFUN call. MOV BLOCKF,R5 ; Load blocking factor. CMP R5,BLKLIM ; Full block remaining? BLOS READFS ; Yes- ready to issue READW. MOV BLKLIM,R5 ; Load records remaining - zero? BEQ EOF ; Yes- end of device reached. READFS: SWAB R5 ; Multiply by words/record. .READW #AREA,#3,BUFADR,R5,IBLK ; Read block of input - successful? BCC READOK ; Yes- skip EOF check. TSTB @#52 ; End of file? BEQ EOF ; Yes- go finish up. SEC ; Force error condition. ERRMSG ; Process error. READOK: SWAB R5 ; Divide by words/record. ADD R5,IBLK ; Update input block number. SUB R5,BLKLIM ; Update remaining block count. SWAB R5 ; Restore count of words read. BR READRT ; Go return. READMT: MOV BLOCKF,R5 ; Load blocking factor. SWAB R5 ; Compute normal block size. .SPFUN #AREA,#3,#370,BUFADR,R5,#SPFBLK ; Read block - successful? BCC SPFROK ; Yes- skip special checks. TSTB @#52 ; Hard error? BNE SPFRHD ; Yes- more checks neccessary. CMP SPFBLK,#2 ; Tape mark detected? BNE EOF ; Yes- normal end of file. SEC ; Force error. ERRMSG ; Abort with message. SPFRHD: CMP SPFBLK,#6 ; Short block read? BEQ SPFRSH ; Yes- go adjust blocksize. SEC ; Force error. ERRMSG ; Abort with message. SPFRSH: SUB SPFBLK+2,R5 ; Compute words actually read. SPFROK: READRT: TST R5 ; Test input data length. RETURN ; Return. EOF: CLR R5 ; No data read. RETURN ; Return. ;************************ ;* write * ;************************ ; ;Write a block (number of words in R5). ; ; ; WRITE: TSTB OMT ; Output to magtape? BNE WRITMT ; Yes- go use SPFUN call. .WRITW #AREA,#0,BUFADR,R5,OBLK ; Write output data. ERRMSG ; Check for error. SWAB R5 ; Divide by words/record. ADD R5,OBLK ; Update output block number. BR WRITRT ; Go finish up. WRITMT: .SPFUN #AREA,#0,#371,BUFADR,R5,#SPFBLK ; Write block. ERRMSG ; Check for error. WRITRT: RETURN ; Return. ;************************ ;* term * ;************************ ; ;Finish up. ; ; ; TERM: .CLOSE #0 ; Close output channel. ERRMSG ; Check for error. .CLOSE #3 ; Close input channel. ERRMSG ; Check for error. RETURN ; Return. ;************************ ;* error * ;************************ ; ;Error handler. ; ; ; ERROR: .HRESET ; Hold everything. .PRINT #ERRHDR ; Display error header. MOV @R5,R0 ; Load -> message. .PRINT ; Display message. MOV #CP,SP ; Reset SP. JMP AGAIN ; Get out. ;************************ ;* outspc * ;************************ ; ;RAD50 filespecs from CSISPC. ; ; ; OUTSPC: OFSPEC: .BLKW 5. ; Output filespec. .BLKW 5.*2. ; Channels 1 and 2. IFSPEC: .BLKW 4. ; Input filespec. .BLKW 4.*6. ; Channels 4-9. ;************************ ;* qspace * ;************************ ; ;Additional queue elements. ; ; ; QSPACE: .BLKW 10*QCOUNT ; Additional queue blocks for QSET. ;************************ ;* retspc * ;************************ ; ;Device status (.DSTATUS) destination. ; ; ; RETSPC: .BLKW 4. ; Device status. ;************************ ;* filest * ;************************ ; ;File status information. ; ; ; BLKLIM: .BLKW 1. ; Blocks remaining on input device. IBLK: .WORD 0 ; Input block number. OBLK: .WORD 0 ; Output block number. IMT: .BYTE 0 ; Indicates input from magtape. OMT: .BYTE 0 ; Indicates output to magtape. .BYTE 0 ; *Unused. OIMG: .BYTE 0 ; Indicates image-mode output. ISEQ: .WORD 0 ; Input file sequence number. OSEQ: .WORD -1 ; Output file sequence number. ;************************ ;* misc * ;************************ ; ;Miscellaneous variables. ; ; ; AREA: .BLKW 16. ; EMT argument block. INBUF: .BLKB 100. ; Terminal input buffer. SPFBLK: .BLKW 4. ; SPFUN request status block. BUFADR: .BLKW 1 ; -> I/O buffer. BLOCKF: .WORD BLKFAC ; Blocking factor. PRGEND: .WORD 0 ; -> Initial free memory. MEMFRE: .WORD 0 ; -> Current free memory. ;************************ ;* const * ;************************ ; ;Constants. ; ; ; DEFEXT: .WORD 0,0,0,0 ; Default extensions for CSISPC. SURE: .ASCII "Image copy -- Are you SURE? "<200> ; Verification prompt. ERRHDR: .ASCII "?CP-F-"<200> ; Error prefix. VERSN: .ASCIZ "CP Version 1.2.0" ; Version identification. .EVEN .END CP