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 __seterrno ; set __errno, return zero in A
44 cpx #0 ; sanity check whence parameter
46 cmp #3 ; valid values are 0..2
48 sta tmp1 ; remember whence
52 jsr fdtoiocb ; convert to iocb in A, fd_table index in X
54 sta tmp3 ; remember iocb
56 jsr chk_supp ; check, whether seeking is supported by DOS/Disk
78 l01: lda ICAX3,x ; low byte of position
80 lda ICAX4,x ; med byte of position
82 lda ICAX5,x ; high byte of position
90 lda #39 ; get file size
95 ; error returned from CIO
99 ; check for offset 0, SEEK_CUR (get current position)
101 jsr ldaxysp ; get upper word
104 jsr ldax0sp ; get lower word
110 lda tmp1 ; whence (0 = SEEK_CUR)
113 ; offset 0, SEEK_CUR: return current fp
124 ; return exactly the position DOS has
132 lda ICAX5,x ; high byte of position
134 lda ICAX3,x ; low byte of position
136 lda ICAX4,x ; med byte of position
143 parmerr1: jmp parmerr
145 ; we have to call POINT
146 seek: jsr ldax0sp ; get lower word of new offset
159 bne parmerr1 ; resulting value too large
176 ; check, whether seeking is supported
178 ; X: index into fd_table
180 ; On non-SpartaDOS, seeking is not supported.
181 ; We check, whether CIO function 39 (get file size) returns OK.
182 ; If yes, NOTE and POINT work with real file offset.
183 ; If not, NOTE and POINT work with the standard ScNum/Offset values.
184 ; We remember a successful check in fd_table.ft_flag, bit 3.
187 lda fd_table+ft_flag,x
197 lda DOS+1 ; get SpartaDOS version
199 bcs supp1 ; SD-X (ver 4.xx) supports seeking on all disks
200 ldx tmp3 ; iocb to use
201 lda #39 ; get file size
204 bmi notsupp ; error code ? should be 168 (invalid command)
206 ; seeking is supported on this DOS/Disk combination
211 ora fd_table+ft_flag,x
212 sta fd_table+ft_flag,x