.iif ndf rsx rsx = 1 ;Assume rsx11m .title fseek Reposition file pointer (seek) ; ; The information in this document is subject to change ; without notice and should not be construed as a commitment ; by Digital Equipment Corporation or by DECUS. ; ; Neither Digital Equipment Corporation, DECUS, nor the authors ; assume any responsibility for the use or reliability of this ; document or the described software. ; ; Copyright (C) 1980, DECUS ; ; ; General permission to copy or modify, but not for profit, is ; hereby granted, provided that the above copyright notice is ; included and reference made to the fact that reproduction ; privileges were granted by DECUS. ; .ident /000005/ ; ;+ ; ; Index Reposition file pointer (seek) ; ; Usage ; ; fseek(iop, offset, param); ; FILE *iop; /* What device to seek */ ; long offset; /* New read position */ ; int param; /* Zero for abs. seek */ ; ; Description ; ; fseek() moves the i/o read pointer to the indicated position. ; The position must have been returned by ftell(). Param ; must be zero. The file/device must be seekable. ; ; fseek() returns zero if correct, EOF if an error occurs. ; If no error occurred, error and eof flags are reset. ; ; flseek() is an alternate entry with identical parameters ; and actions. ; ; Bugs ; ;- ; ; Edit history ; 000001 13-Mar-80 MM Initial edit ; 000002 27-Jun-80 MM $$get returns -1 on error ; 000003 01-Aug-80 MM Track IOV change ; 000004 ??-Feb-81 RBD Clear V$BCNT to force the seek. Bug. ; 000005 17-Jun-81 RBD Clear V$BCNT only on RSX! ; .psect .prog. flseek:: fseek:: jsr r5,csv$ mov c$pmtr+0(r5),r4 ;r4 -> iop mov #-1,r0 ;expect the worst tst c$pmtr+6(r5) ;parameter = 0? bne 30$ ;nope, die. .if ne rsx bit #vf$rec+vf$mod,(r4) ;will it seek? ;03 bne 30$ ;nope. mov c$pmtr+2(r5),r1 ;r1 := high-order vbn mov c$pmtr+4(r5),r2 ;r2 := low-order vbn mov r2,r3 ;r3 := byte offset in block bic #^C777,r3 ;now it does mov #9.,r0 ;do a long shift 10$: asr r1 ;of the ror r2 ;long block dec r0 ;number bgt 10$ ; bit #vf$fil,(r4) ;File or device beq 20$ ;Br if device add #1,r2 ;File, make origin adc r1 ;1 20$: mov r4,r0 ;r0 -> fdb add #v$fdb,r0 ;now it does call .point ;seek away clr v$bcnt(r4) ;force the seek ;04/05 .iff bit #vf$rec+vf$tty+vf$mod,(r4) ;will it seek? ;03 bne 30$ ;not a chance ; ; Since this is a stream i/o package, we don't bother to ; check the busy bit and flush the current buffer. ; mov c$pmtr+2(r5),r0 ;Block number to get tst v$bptr(r4) ;Is the buffer empty? beq 10$ ;Yes, always read inc r0 ;Check against current (i.e. next) block cmp r0,v$bnbr(r4) ;Trying to get the block that's in? beq 20$ ;Yes, skip the read dec r0 ;No, reget the correct number ; 10$: call $$get ;Go for it tst r0 ;ok return? bmi 30$ ;no, die. ;02 ; 20$: mov c$pmtr+4(r5),r0 ;Buffer index mov #512.,v$bcnt(r4) ;Setup free count sub r0,v$bcnt(r4) ;Load free count add r4,r0 ;Build pointer add #v$buff,r0 ;to the free byte mov r0,v$bptr(r4) ;and put it away. ; .endc clr r0 ;good return ;05-- 30$: tst r0 ;Ok return? bne 40$ ;Br if not bic #vf$eor,(r4) ;Clear error and eof flags mov #-1,v$uget(r4) ;No unget char. now ; 40$: jmp cret$ ;back we go. .end