.title Serial Line cl unit handler ; DECUS C Calling Format ; ; jsr r5,csv$ ;save r2,r3, and r4 ; ;r5 is parameter base ; ;c$pmtr(r5) is first argument ; ;c$pmtr+2(r5) is second argument ; ;... ; ;return args in r0 ; ... ; user code ; ... ; ; jmp cret$ ;restore r2-r5 and return ; ; csv$ and cret$ need be used only if r2-r5 need to be ; saved or you wish to use the r5 stack frame ; .mcall .close .rsum arg1 = 2 CLCTRL = 14 ;Channel # for CL unit control CLIUNT = 15 ;Channel # for CL unit input CLOUNT = 16 ;Channel # for CL unit output CLRXNF = 201 ;SPFUN code to clear XOFF / send XON CLRBYT = 203 ;SPFUN code to read CL with byte count CLSOPT = 250 ;SPFUN code to set CL options CLCOPT = 251 ;SPFUN code to clear CL options CLABRT = 257 ;SPFUN code to abort this jobs pending i/o CLIPND = 261 ;SPFUN code to get # chars pending CL input CLWBYT = 263 ;SPFUN code to write CL with byte count CLRST = 265 ;SPFUN code to reset CL unit .sbttl CL Unit Initialization .psect c$code sl.init:: mov #-1,-(sp) ;error return mov arg1+2(sp),r0 ;get unit number cmp r0,#7 bhi 1$ mov #^rCL0,clspec ;restore spec add r0,clspec ;compute unit jsr pc,sl.abort ;abort any current i/o mov #lkaloc,r0 ;allocate CL unit emt 375 bcs 1$ ;allocation error - exit mov #lkctla,r0 ;.lookup emt 375 bcs 1$ ;device error - exit mov #lkinpa,r0 ;.lookup emt 375 bcs 1$ ;device error - exit mov #lkoupa,r0 ;.lookup emt 375 bcs 1$ ;device error - exit mov #clrset,r0 ;.spfun emt 375 bcs 1$ ;initialization error - exit mov #clset,r0 ;.spfun emt 375 bcs 1$ ;initialization error - exit mov #clclr,r0 ;.spfun emt 375 bcs 1$ ;initialization error - exit clr oupact ;clear output clr inpact ;clear input jsr pc,$cptln ;startup CL input inc inpflg jsr pc,$mrkto ;startup CL input timeout clr (sp) 1$: mov (sp)+,r0 rts pc .psect c$data lkaloc: .byte 0,156 ;allocate CL unit .word clspec lkctla: .byte CLCTRL,1 ;lookup .word clspec .word 0 lkinpa: .byte CLIUNT,1 ;lookup .word clspec .word 0 lkoupa: .byte CLOUNT,1 ;lookup .word clspec .word 0 clspec: .rad50 /CL0/ ;cl unit specification .word 0,0,0 clrset: .byte CLCTRL,32 ;.spfun for CLRST .word 0 .word 0 .word 0 .byte 377,CLRST .word 0 ; CL unit flags, (1) set, (0) noset ;000001 FORM Send form feed characters ;000002 TAB Send tab characters ;000004 LC Send lower case letters ;000010 LFOUT Send line feed characters ;000020 LFIN Accept line feed characters ;000040 FORM0 Send form feed on block 0 write ;000100 BINOUT Send binary output characters ;000200 BININ Accept binary input characters ;000400 CR Send carriage return characters ;001000 CTRL Send control characters ;002000 DTR Raise Data Terminal Ready (DTR) ;004000 EIGHTBIT Accept and send 8 bit characters clset: .byte CLCTRL,32 ;.spfun for CLSOPT .word 0 .word 1$ .word 0 .byte 377,CLSOPT .word 0 1$: .word 001437 ;set these flags clclr: .byte CLCTRL,32 ;.spfun for CLCOPT .word 0 .word 1$ .word 0 .byte 377,CLCOPT .word 0 1$: .word 006340 ;clear these flags .sbttl CL Unit Abort I/O .psect c$code sl.abort:: mov #clabt,r0 ;abort i/o emt 375 mov #$cmkta,r0 ;abort .mrkt request emt 375 mov #$cmktb,r0 ;abort .mrkt request emt 375 .close #CLCTRL ;close the channel .close #CLIUNT ;close the channel .close #CLOUNT ;close the channel rts pc .psect c$data clabt: .byte CLCTRL,32 ;.spfun for CLABRT .word 0 .word 0 .word 0 .byte 377,CLABRT .word 0 .page .sbttl CL Input a String ; bytes = sl_gets(buffer, maxbytes); .psect c$code sl.gets:: jsr r5,csv$ clr -(sp) ;null character count tst c$pmtr+2(r5) ;buffer length beq 4$ ;bad argument (=0) tst inpact ;active ? bne 4$ ;yes - no characters mov c$pmtr(r5),r0 ;buffer address tstb chrinp ;character ? beq 1$ ;no - skip movb chrinp,(r0)+ ;copy character clrb chrinp inc (sp) ;a character 1$: clrb (r0) ;terminate string mov r0,slbufr ;buffer address clr slbyts mov #slgcnt,r0 ;any pending characters ? emt 375 mov c$pmtr+2(r5),r1 ;max bytes in buffer mov slbyts,r2 ;if no characters - finished beq 3$ cmp r1,r2 ;select smallest of blos 2$ ;slbyts or maxbytes mov r2,r1 2$: mov r1,slbyts ;characters to read add r1,(sp) ;characters returned add slbufr,r1 ;terminate string clrb (r1) mov #slgstr,r0 ;place characters in buffer emt 375 3$: tst (sp) ;any characters ? bne 4$ ;yes - skip jsr pc,$cptln ;else start single character input 4$: mov (sp)+,r0 ;return a NULL / CHARACTER COUNT jmp cret$ slgcnt: .byte CLIUNT,32 ;.spfun for CLIPND .word 0 .word slbyts .word 0 .byte 377,CLIPND .word 0 slgstr: .byte CLIUNT,32 ;.spfun for CLRBYT .word 1 slbufr: .word 0 slbyts: .word 0 .byte 377,CLRBYT .word 0 .page .sbttl Asynchronous CL Input .psect c$code $cptln: inc inpact ;active mov #$cmkta,r0 ;abort .mrkt request emt 375 mov #clgchr,r0 ;set up single character activation emt 375 ;CL input completion request rts pc clinpc: clr inpact ;clear active bit #001001,r0 ;abort ? bne 2$ inc inpflg tst re.spnd bgt 1$ .rsum ;resume any suspension inc re.spnd 1$: mov #3,$mrktm ;reset time br $mrkti ;start up .mrkt 2$: rts pc $mrkte: clr clbyts mov #clgcnt,r0 ;any pending characters ? emt 375 tst clbyts ;if none - finished beq $mktxt inc inpflg tst re.spnd bgt $mrkti .rsum ;resume any suspension inc re.spnd $mrkti: mov #$mrkta,r0 ;set up next time interrupt emt 375 ;.mrkt request sec ;now increase the rol $mrktm ;wait time to a maximum bic #^C17,$mrktm ;of 15./60. ths of a second $mktxt: rts pc .psect c$data $mrkta: .byte 0,22 ;.mrkt emt .word 1$ ;time to wait address .word $mrkte ;entry point .word 2 ;id = 2 1$: .word 0 $mrktm: .word 17 ;15/60 ths of a second $cmkta: .byte 0,23 ;.cmkt .word 2 ;id = 2 .word 1$ 1$: .word 0,0 ;remaining time clgchr: .byte CLIUNT,32 ;.spfun for CLRBYT .word 1 .word chrinp .word 1 .byte 377,CLRBYT .word clinpc clgcnt: .byte CLIUNT,32 ;.spfun for CLIPND .word 0 .word clbyts .word 0 .byte 377,CLIPND .word 0 inpflg: .word 0 ;characters input flag inpact: .word 0 ;active chrinp: .word 0 ;single character input clbyts: .word 0 ;bytes waiting in CL silo .page .sbttl CL Input Timeout .psect c$code $mrkto: tst inpflg ;characters recieved ? bne 1$ ;yes - skip mov #clrhnd,r0 ;no - clear XOFF / send XON emt 375 1$: clr inpflg ;clear flag mov #$mrktb,r0 ;set up next time interrupt emt 375 ;.mrkt request rts pc .psect c$data clrhnd: .byte CLCTRL,32 ;.spfun for CLRXNF .word 0 .word 0 .word 0 .byte 377,CLRXNF .word 0 $mrktb: .byte 0,22 ;.mrkt emt .word 1$ ;time to wait address .word $mrkto ;entry point .word 3 ;id = 3 1$: .word 0 .word 5*60. ;5 seconds $cmktb: .byte 0,23 ;.cmkt .word 3 ;id = 3 .word 1$ 1$: .word 0,0 ;remaining time .page .sbttl CL Output .psect c$code sl.putc:: tst oupact ;active ? bne 1$ ;yes - exit mov #1,oupact ;active movb arg1(sp),chroup ;place character mov #clpchr,r0 ;send character emt 375 mov arg1(sp),r0 ;character rts pc 1$: mov #-1,r0 ;EOF rts pc cloupc: clr oupact ;finished rts pc .psect c$data clpchr: .byte CLOUNT,32 ;.spfun for CLWBYT .word 1 .word chroup clocnt: .word 1 .byte 377,CLWBYT .word cloupc chroup: .word 0 ;output character oupact: .word 0 ;active flag .end