]> git.sur5r.net Git - cc65/blob - libsrc/atari/rwcommon.s
remove not longer needed import of tmp2 and tmp3
[cc65] / libsrc / atari / rwcommon.s
1 ;
2 ; common iocb setup routine for read, write
3 ; expects __fastcall__ parameters (int fd, void *buf, int count)
4 ;
5         .include "atari.inc"
6         .include "errno.inc"
7         .import popax
8         .import __errno,__oserror
9         .import fdtoiocb
10
11         .export __rwsetup
12
13
14 __rwsetup:
15
16         pha                     ; push size in stack
17         txa
18         pha
19         jsr     popax           ; get buffer address
20         pha
21         txa
22         pha
23         jsr     popax           ; get handle
24         jsr     fdtoiocb        ; convert to iocb
25         bmi     iocberr         ; negative (X=$FF or A>$7F) on error.
26         tax
27         pla                     ; store address
28         sta     ICBAH,x
29         pla
30         sta     ICBAL,x
31         pla                     ; store length
32         sta     ICBLH,x
33         pla
34         sta     ICBLL,x
35         ora     ICBLH,x         ; returns Z if length is 0
36         rts
37
38 iocberr:pla
39         pla
40         pla
41         pla
42         ldx     #$FF            ; indicate error + clear ZF
43         rts
44
45 ;
46 ; this routine updates errno.  do a JMP here right after calling
47 ; CIOV.  we expect status in Y.
48 ;
49         .export __do_oserror,__inviocb
50 __do_oserror:
51         sty     __oserror       ; save os dependent error code
52 retminus:
53         lda     #$FF
54         tax                     ; return -1
55         rts
56
57 ;
58 ; sets EINVAL error code and returns -1
59 ;
60
61 __inviocb:
62         lda     #<EINVAL
63         jsr     __seterrno
64         jmp     retminus        ; return -1