]> git.sur5r.net Git - cc65/blobdiff - libsrc/atari/rwcommon.s
DIO functions always set _oserror.
[cc65] / libsrc / atari / rwcommon.s
index afdbb443b0d9433c7c911db5f99b72637aa9bbe6..349c7be019e2afa56efafedfa92ed06c3d93ff12 100644 (file)
@@ -1,71 +1,43 @@
 ;
 ; common iocb setup routine for read, write
-; expects parameters (int fd,void *buf,int count)
+; expects __fastcall__ parameters (int fd, void *buf, int count)
 ;
-        .include "atari.inc"
-               .include "errno.inc"
-        .importzp tmp2,tmp3
-        .import incsp6,ldax0sp,ldaxysp
-       .import __errno,__oserror
+       .include "atari.inc"
+       .include "errno.inc"
+       .import popax
        .import fdtoiocb
 
-        .export __rwsetup
+       .export __rwsetup
+
 
 __rwsetup:
 
-        ldy     #5
-        jsr     ldaxysp         ; get fd
+       pha                     ; push size in stack
+       txa
+       pha
+       jsr     popax           ; get buffer address
+       pha
+       txa
+       pha
+       jsr     popax           ; get handle
        jsr     fdtoiocb        ; convert to iocb
-       bmi     iocberr
-        sta     tmp3            ; save it
-        jsr     ldax0sp         ; get size
-        stx     tmp2
-        ldx     tmp3            ; iocb
-       cpx     #$80            ; iocb must be 0...7
-       bcs     iocberr
-        sta     ICBLL,x
-        lda     tmp2            ; size hi
-        sta     ICBLH,x
-        ldy     #3              ; get buf addr (was 2 in orig. version)
-        jsr     ldaxysp
-        stx     tmp2
-        ldx     tmp3
-        sta     ICBAL,x
-        lda     tmp2
-        sta     ICBAH,x
-       jsr     incsp6          ; pop args
-       lda     ICBLL,x
-       ora     ICBLH,x         ; return with Z if length was 0
-        rts
-
-iocberr:jsr     incsp6          ; pop args
-       ldx     #$FF            ; indicate error + clear ZF
+       bmi     iocberr         ; negative (X=$FF or A>$7F) on error.
+       tax
+       pla                     ; store address
+       sta     ICBAH,x
+       pla
+       sta     ICBAL,x
+       pla                     ; store length
+       sta     ICBLH,x
+       pla
+       sta     ICBLL,x
+       ora     ICBLH,x         ; returns Z if length is 0
        rts
 
-
-;
-; this routine updates errno.  do a JMP here right after calling
-; CIOV.  we expect status in Y.
-;
-        .export __do_oserror,__seterrno,__inviocb
-__do_oserror:
-       sty     __oserror       ; save os dependent error code
-retminus:
-       lda     #$FF
-       tax                     ; return -1
+iocberr:pla
+       pla
+       pla
+       pla
+       ldx     #$FF            ; indicate error + clear ZF
        rts
 
-__seterrno:
-        sta     __errno
-        stx     __errno+1
-        rts
-
-;
-; sets EINVAL error code and returns -1
-;
-
-__inviocb:
-       lda     #<EINVAL
-       ldx     #>EINVAL
-       jsr     __seterrno
-       jmp     retminus        ; return -1