2014-11-22 00:04:11 +00:00
|
|
|
;
|
|
|
|
; Peter Ferrie, 21.11.2014
|
|
|
|
;
|
|
|
|
; off_t __fastcall__ lseek(int fd, off_t offset, int whence);
|
|
|
|
;
|
|
|
|
|
|
|
|
.export _lseek
|
2018-05-20 13:30:18 +00:00
|
|
|
.import popax, popptr1
|
2018-08-20 07:56:01 +00:00
|
|
|
.macpack cpu
|
2014-11-22 00:04:11 +00:00
|
|
|
|
|
|
|
.include "zeropage.inc"
|
|
|
|
.include "errno.inc"
|
|
|
|
.include "mli.inc"
|
|
|
|
.include "filedes.inc"
|
|
|
|
|
|
|
|
_lseek:
|
|
|
|
; Save whence
|
|
|
|
sta tmp1
|
|
|
|
stx tmp2
|
|
|
|
|
|
|
|
; Get and save offset
|
2018-05-20 13:30:18 +00:00
|
|
|
jsr popptr1
|
2014-11-22 00:04:11 +00:00
|
|
|
jsr popax
|
|
|
|
sta ptr2
|
2018-08-20 15:45:40 +00:00
|
|
|
stx ptr2+1
|
2014-11-22 00:04:11 +00:00
|
|
|
|
|
|
|
; Get and process fd
|
|
|
|
jsr popax
|
|
|
|
jsr getfd ; Returns A, Y and C
|
|
|
|
bcs errno
|
|
|
|
|
|
|
|
; Check for device
|
|
|
|
cmp #$80
|
|
|
|
bcs einval
|
|
|
|
|
|
|
|
; Valid whence values are 0..2
|
|
|
|
ldx tmp2
|
|
|
|
bne einval
|
|
|
|
ldx tmp1
|
|
|
|
cpx #3
|
|
|
|
bcs einval
|
|
|
|
|
|
|
|
; Set fd
|
2014-11-24 18:07:16 +00:00
|
|
|
sta mliparam + MLI::MARK::REF_NUM
|
2014-11-22 00:04:11 +00:00
|
|
|
|
|
|
|
txa
|
|
|
|
beq cur
|
|
|
|
lda #GET_EOF_CALL
|
|
|
|
dex
|
|
|
|
beq end
|
|
|
|
|
|
|
|
; SEEK_SET
|
|
|
|
dex
|
|
|
|
txa
|
|
|
|
tay
|
|
|
|
beq seek_common
|
|
|
|
|
|
|
|
; SEEK_CUR
|
|
|
|
cur:
|
|
|
|
lda #GET_MARK_CALL
|
|
|
|
|
|
|
|
; SEEK_END
|
|
|
|
end:
|
2014-11-24 18:07:16 +00:00
|
|
|
; MARK_COUNT must == EOF_COUNT, otherwise unexpected behaviour
|
|
|
|
.assert MARK_COUNT = EOF_COUNT, error
|
|
|
|
ldx #MARK_COUNT
|
2014-11-22 00:04:11 +00:00
|
|
|
jsr callmli
|
|
|
|
bcs oserr
|
|
|
|
lda mliparam + MLI::MARK::POSITION
|
|
|
|
ldx mliparam + MLI::MARK::POSITION+1
|
|
|
|
ldy mliparam + MLI::MARK::POSITION+2
|
|
|
|
|
|
|
|
seek_common:
|
|
|
|
adc ptr1
|
|
|
|
sta mliparam + MLI::MARK::POSITION
|
|
|
|
txa
|
|
|
|
adc ptr1+1
|
|
|
|
sta mliparam + MLI::MARK::POSITION+1
|
|
|
|
tya
|
|
|
|
adc ptr2
|
|
|
|
sta mliparam + MLI::MARK::POSITION+2
|
2018-08-20 15:45:40 +00:00
|
|
|
lda #$00
|
|
|
|
adc ptr2+1
|
|
|
|
bne einval ; less than 0 or greater than 2^24 - 1
|
2014-11-22 00:04:11 +00:00
|
|
|
|
|
|
|
; Set file pointer
|
|
|
|
lda #SET_MARK_CALL
|
|
|
|
ldx #MARK_COUNT
|
|
|
|
jsr callmli
|
|
|
|
bcs oserr
|
|
|
|
|
2018-08-19 23:04:42 +00:00
|
|
|
; Need to return the position in EAX
|
2018-08-20 07:56:01 +00:00
|
|
|
.if (.cpu .bitand ::CPU_ISET_65SC02)
|
2018-08-20 07:10:51 +00:00
|
|
|
stz sreg+1
|
2018-08-20 07:56:01 +00:00
|
|
|
.else
|
|
|
|
lda #$00
|
2018-08-19 23:04:42 +00:00
|
|
|
sta sreg+1
|
2018-08-20 07:56:01 +00:00
|
|
|
.endif
|
2018-08-19 23:04:42 +00:00
|
|
|
lda mliparam + MLI::MARK::POSITION+2
|
|
|
|
sta sreg
|
|
|
|
ldx mliparam + MLI::MARK::POSITION+1
|
|
|
|
lda mliparam + MLI::MARK::POSITION
|
|
|
|
|
2014-11-22 00:04:11 +00:00
|
|
|
rts
|
|
|
|
|
|
|
|
; Load errno code
|
|
|
|
einval: lda #EINVAL
|
|
|
|
|
|
|
|
; Set __errno
|
2022-08-28 20:37:33 +00:00
|
|
|
errno: jsr ___directerrno ; leaves -1 in AX
|
2018-08-20 15:45:40 +00:00
|
|
|
stx sreg ; extend return value to 32 bits
|
2018-08-20 07:56:01 +00:00
|
|
|
stx sreg+1
|
2018-08-20 15:45:40 +00:00
|
|
|
rts
|
2014-11-22 00:04:11 +00:00
|
|
|
|
2022-08-28 19:52:53 +00:00
|
|
|
; Set ___oserror
|
2022-08-28 20:37:33 +00:00
|
|
|
oserr: jsr ___mappederrno ; leaves -1 in AX
|
2018-08-20 15:45:40 +00:00
|
|
|
stx sreg ; extend return value to 32 bits
|
2018-08-20 07:56:01 +00:00
|
|
|
stx sreg+1
|
2018-08-20 15:45:40 +00:00
|
|
|
rts
|