.title getch ;+ ; c = getch(c, int) ; ; gets the next character on ratfor unit int ; ; returns it in variable c and as value of the function ; ; if error occurs or EOF on the file, the value EOF is returned ;- ap=%5 c=2 int=4 ; ; .mcall qiow$s,get$ ; ; .psect $r.roi,con,ro,rel,lcl,i .enabl lsb getch:: mov @int(ap),r0 ; get ratfor unit number == lun call r$gfbk ; get RFDB address in r1 bcs 100$ ; c set => invalid unit number bit #rf.clo,(r1) ; is the file open? bne 100$ ; NO bit #rf.raw,(r1) ; rawmode terminal? beq 10$ ; NO mov #1,r0 ; number of chars to read mov c(ap),r2 ; address of buffer call r$tget ; fetch the raw character bcs 110$ ; c set == ERR | TMO movb @c(ap),r0 ; return character bic #177600,r0 ; mask to 7 bits br 110$ ; return the stuff 10$: bit #rf.mod,(r1) ; inputmode? bne 20$ ; YES cmpb #rdwr$r,r.acc(r1) ; READWRITE unit? bne 100$ ; NO, error clr r.byte(r1) ; no bytes left in record bis #rf.mod,(r1) ; set to inputmode 20$: call r$cget ; get next character in r0 bcc 110$ ; c clear => success cmp r0,#tmo ; timeout on read? beq 110$ ; YES, return(TMO) 100$: mov #eof,r0 ; return(EOF) 110$: movb r0,@c(ap) ; return character to user return .page .sbttl r$cget - get next cooked character into r0 ;+ ; this routine is called by getch and getlin ; ; inputs: ; r1 RFDB address ; ; outputs: ; r0 next character ; c bit set if error or end-of-file ; c bit clear if OK ; r2 is mangled ;- r$cget:: tst r.byte(r1) ; any bytes left in record? bgt 30$ ; YES mov r.buf0(r1),r2 ; buffer address in r2 bit #rf.tty,(r1) ; is this a terminal? beq 21$ ; NO mov #maxbuf,r0 ; size of buffer call r$tget ; fetch the buffer bcs 40$ ; c set ==> error or timeout br 22$ ; branch to common code 21$: mov r.fdb(r1),r0 ; address of FDB in r0 get$ ,r2,#maxbuf ; get next record bcs 40$ ; c set => error or end-of-file mov f.nrbd(r0),r0 ; number of bytes read 22$: mov r2,r.bufp(r1) ; save address in RFDB bit #rf.ctl,(r1) ; LIST or FORT carriage control? beq 25$ ; NO add r0,r2 ; address of first free byte in buffer movb #newlin,(r2) ; place NEWLINE at end of buffer inc r0 ; increase count 25$: mov r0,r.byte(r1) ; number of bytes in record 30$: movb @r.bufp(r1),r0 ; character to return dec r.byte(r1) ; decrement no of bytes left inc r.bufp(r1) ; bump pointer clc ; c clear => OK 40$: return .page .sbttl r$tget - read from terminal, both cooked and raw ;+ ; this routine is called by getch and readf ; ; inputs: ; r0 size of buffer for reading ; r1 RFDB address ; r2 buffer to read into ; ; outputs: ; c set ==> error ; r0 will contain EOF | TMO ; c clear ==> success ; r0 will contain the number of characters read ; ; all other registers are maintained across the call ;- r$tget:: call r$savr ; save all registers movb r.lun(r1),r3 ; lun for qiow mov r.timo(r1),r4 ; time out value mov #io.rlb!tf.tmo,-(sp) ; default function code bit #rf.raw!rf.rne,(r1) ; RAW or READ/NOECHO? beq 50$ ; NO bis #tf.rne,(sp) ; or in sub-function bit bit #rf.raw,(r1) ; RAW tty? beq 50$ ; NO bis #tf.ral,(sp) ; or in sub-function bit 50$: mov (sp)+,r1 ; have function code in register qiow$s r1,r3,r$ioef,,#r$iosb,, mov #tmo,r0 ; assume timeout cmpb #is.tmo,r$iosb ; is it? beq 55$ ; NO mov #eof,r0 ; assume error cmpb #is.suc,r$iosb ; successful? bne 55$ ; NO mov r$iosb+2,r0 ; number of chars read 55$: clc ; assume successful mov r0,2(sp) ; return r0 to user bge 60$ ; if >= 0, success sec ; set c bit to indicate error 60$: return .end