2 ; Christian Groessler, May 2002
4 ; this file provides the lseek() function
6 ; off_t __fastcall__ lseek(int fd, off_t offset, int whence);
11 .import incsp6,__oserror
12 .import __inviocb,ldax0sp,ldaxysp,fdtoiocb
15 .importzp sreg,ptr1,ptr2,ptr3,ptr4
16 .importzp tmp1,tmp2,tmp3
21 ; seeking not supported, return -1 and ENOSYS errno value
24 jsr __directerrno ; returns with $FFFF in AX
41 cpx #0 ; sanity check whence parameter
43 cmp #3 ; valid values are 0..2
45 sta tmp1 ; remember whence
49 jsr fdtoiocb ; convert to iocb in A, fd_table index in X
51 sta tmp3 ; remember iocb
53 jsr chk_supp ; check, whether seeking is supported by DOS/Disk
75 l01: lda ICAX3,x ; low byte of position
77 lda ICAX4,x ; med byte of position
79 lda ICAX5,x ; high byte of position
87 lda #39 ; get file size
92 ; error returned from CIO
97 jsr __mappederrno ; returns with $FFFF in AX
102 ; check for offset 0, SEEK_CUR (get current position)
104 jsr ldaxysp ; get upper word
107 jsr ldax0sp ; get lower word
113 lda tmp1 ; whence (0 = SEEK_CUR)
116 ; offset 0, SEEK_CUR: return current fp
127 ; return exactly the position DOS has
135 lda ICAX5,x ; high byte of position
137 lda ICAX3,x ; low byte of position
139 lda ICAX4,x ; med byte of position
146 parmerr1: jmp parmerr
148 ; we have to call POINT
149 seek: jsr ldax0sp ; get lower word of new offset
162 bne parmerr1 ; resulting value too large
179 ; check, whether seeking is supported
181 ; X: index into fd_table
183 ; On non-SpartaDOS, seeking is not supported.
184 ; We check, whether CIO function 39 (get file size) returns OK.
185 ; If yes, NOTE and POINT work with real file offset.
186 ; If not, NOTE and POINT work with the standard ScNum/Offset values.
187 ; We remember a successful check in fd_table.ft_flag, bit 3.
190 lda fd_table+ft_flag,x
200 lda DOS+1 ; get SpartaDOS version
202 bcs supp1 ; SD-X (ver 4.xx) supports seeking on all disks
203 ldx tmp3 ; iocb to use
204 lda #39 ; get file size
207 bmi notsupp ; error code ? should be 168 (invalid command)
209 ; seeking is supported on this DOS/Disk combination
214 ora fd_table+ft_flag,x
215 sta fd_table+ft_flag,x