From 0c204725bc2d5b1d50b097c21c1d5c9082c6101a Mon Sep 17 00:00:00 2001 From: peterferrie Date: Fri, 21 Nov 2014 16:04:11 -0800 Subject: [PATCH 1/2] implement ProDOS seek --- libsrc/apple2/lseek.s | 96 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 96 insertions(+) create mode 100644 libsrc/apple2/lseek.s diff --git a/libsrc/apple2/lseek.s b/libsrc/apple2/lseek.s new file mode 100644 index 000000000..058e6f53d --- /dev/null +++ b/libsrc/apple2/lseek.s @@ -0,0 +1,96 @@ +; +; Peter Ferrie, 21.11.2014 +; +; off_t __fastcall__ lseek(int fd, off_t offset, int whence); +; + + .export _lseek + .import popax + + .include "zeropage.inc" + .include "errno.inc" + .include "mli.inc" + .include "filedes.inc" + +_lseek: + ; Save whence + sta tmp1 + stx tmp2 + + ; Get and save offset + jsr popax + sta ptr1 + stx ptr1+1 + jsr popax + sta ptr2 + + ; 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 + sta mliparam + MLI::RW::REF_NUM + + 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: + ldx #MARK_COUNT ; conveniently same as EOF_COUNT + 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 + + ; Set file pointer + lda #SET_MARK_CALL + ldx #MARK_COUNT + jsr callmli + bcs oserr + + rts + + ; Load errno code +einval: lda #EINVAL + + ; Set __errno +errno: jmp __directerrno + + ; Set __oserror +oserr: jmp __mappederrno From bbd419f365d4229094bd33a61dae66bcef0f4370 Mon Sep 17 00:00:00 2001 From: peterferrie Date: Mon, 24 Nov 2014 10:07:16 -0800 Subject: [PATCH 2/2] assert parm count --- libsrc/apple2/lseek.s | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/libsrc/apple2/lseek.s b/libsrc/apple2/lseek.s index 058e6f53d..73f4136be 100644 --- a/libsrc/apple2/lseek.s +++ b/libsrc/apple2/lseek.s @@ -41,7 +41,7 @@ _lseek: bcs einval ; Set fd - sta mliparam + MLI::RW::REF_NUM + sta mliparam + MLI::MARK::REF_NUM txa beq cur @@ -61,7 +61,9 @@ cur: ; SEEK_END end: - ldx #MARK_COUNT ; conveniently same as EOF_COUNT + ; MARK_COUNT must == EOF_COUNT, otherwise unexpected behaviour + .assert MARK_COUNT = EOF_COUNT, error + ldx #MARK_COUNT jsr callmli bcs oserr lda mliparam + MLI::MARK::POSITION