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
13 .import __seterrno,__dos_type
15 .importzp sreg,ptr1,ptr2,ptr3,ptr4
16 .importzp tmp1,tmp2,tmp3
21 ; seeking not supported, return -1 and ENOSYS errno value
46 cpx #0 ; sanity check whence parameter
48 cmp #3 ; valid values are 0..2
50 sta tmp1 ; remember whence
54 jsr fdtoiocb ; convert to iocb in A, fd_table index in X
56 sta tmp3 ; remember iocb
58 jsr chk_supp ; check, whether seeking is supported by DOS/Disk
80 l01: lda ICAX3,x ; low byte of position
82 lda ICAX4,x ; med byte of position
84 lda ICAX5,x ; high byte of position
92 lda #39 ; get file size
97 ; error returned from CIO
101 ; check for offset 0, SEEK_CUR (get current position)
103 jsr ldaxysp ; get upper word
106 jsr ldax0sp ; get lower word
112 lda tmp1 ; whence (0 = SEEK_CUR)
115 ; offset 0, SEEK_CUR: return current fp
126 ; return exactly the position DOS has
134 lda ICAX5,x ; high byte of position
136 lda ICAX3,x ; low byte of position
138 lda ICAX4,x ; med byte of position
145 parmerr1: jmp parmerr
147 ; we have to call POINT
148 seek: jsr ldax0sp ; get lower word of new offset
161 bne parmerr1 ; resulting value too large
178 ; check, whether seeking is supported
180 ; X: index into fd_table
182 ; On non-SpartaDOS, seeking is not supported.
183 ; We check, whether CIO function 39 (get file size) returns OK.
184 ; If yes, NOTE and POINT work with real file offset.
185 ; If not, NOTE and POINT work with the standard ScNum/Offset values.
186 ; We remember a successful check in fd_table.ft_flag, bit 3.
189 lda fd_table+ft_flag,x
199 lda DOS+1 ; get SpartaDOS version
201 bcs supp1 ; SD-X (ver 4.xx) supports seeking on all disks
202 ldx tmp3 ; iocb to use
203 lda #39 ; get file size
206 bmi notsupp ; error code ? should be 168 (invalid command)
208 ; seeking is supported on this DOS/Disk combination
213 ora fd_table+ft_flag,x
214 sta fd_table+ft_flag,x