       mov     (sp)+,r0 / return to routine that called writei
       jmp     ret
tstdeve: / check whether permanent error has occured on special file
         / I/O
       mov     cdev,r1 / only works on tape; r1 has device #
       tstb    deverr(r1) / test error bit of device
       bne     1f / error
       rts     r0 / device okay
1:
       clrb    deverr(r1) / clear error

error10:
       jmp     error / see 'error' routine

dioreg:
       mov     u.count,r3 / move char count to r3
       cmp     r3,$512. / more than 512. char?
       blos    1f / no, branch
       mov     $512.,r3 / yes, just take 512.
1:
       mov     u.base,r2 / put users base in r2
       add     r3,u.nread / add the number to be read to u.nread
       sub     r3,u.count / update count
       add     r3,u.base / update base
       rts     r0 / return

preread:
       jsr     r0,bufaloc / get a free I/O buffer (r1 has block number)
       br      1f / branch if block already in a I/O buffer
       bis     $2000,(r5) / set read bit (bit 100 in I/O buffer)
       jsr     r0,poke / perform the read
1:
       clr     *$ps / ps = 0
       rts     r0

dskrd:
       jsr     r0,bufaloc / shuffle off to bufaloc; get a free I/O buffer
               br 1f
       bis     $2000,(r5) / set bit 10 of word 1 of I/O queue entry
                          / for buffer
       jsr     r0,poke / just assigned in bufaloc, bit 10=1 says read
1:
       clr     *$ps
       bit     $22000,(r5) / if either bits 10, or 13 are 1; jump to idle
       beq     1f
       jsr     r0,idle; s.wait+2
       br      1b
1:
       add     $8,r5 / r5 points to first word of data in block just read
                     / in
       rts     r0

wslot:
       jsr     r0,bufaloc / get a free I/O buffer; pointer to first
               br 1f / word in buffer in r5
