]> git.sur5r.net Git - cc65/blob - libsrc/atari/rwcommon.s
__seterrno is now a common function available on all platforms with slightly
[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         .importzp tmp2,tmp3
8         .import incsp4,ldax0sp,ldaxysp
9         .import __errno,__oserror
10         .import fdtoiocb
11
12         .export __rwsetup
13
14 __rwsetup:
15
16         sta     tmp2
17         stx     tmp3            ; remember size
18         ldy     #3
19         jsr     ldaxysp         ; get fd
20         jsr     fdtoiocb        ; convert to iocb
21         bmi     iocberr
22         tax
23         cpx     #$80            ; iocb must be 0...7
24         bcs     iocberr
25         lda     tmp2
26         sta     ICBLL,x
27         lda     tmp3            ; size hi
28         sta     ICBLH,x
29         stx     tmp3
30         jsr     ldax0sp         ; get buf addr
31         stx     tmp2
32         ldx     tmp3
33         sta     ICBAL,x
34         lda     tmp2
35         sta     ICBAH,x
36         jsr     incsp4          ; pop args
37         lda     ICBLL,x
38         ora     ICBLH,x         ; return with Z if length was 0
39         rts
40
41 iocberr:jsr     incsp4          ; pop args
42         ldx     #$FF            ; indicate error + clear ZF
43         rts
44
45
46 ;
47 ; this routine updates errno.  do a JMP here right after calling
48 ; CIOV.  we expect status in Y.
49 ;
50         .export __do_oserror,__inviocb
51 __do_oserror:
52         sty     __oserror       ; save os dependent error code
53 retminus:
54         lda     #$FF
55         tax                     ; return -1
56         rts
57
58 ;
59 ; sets EINVAL error code and returns -1
60 ;
61
62 __inviocb:
63         lda     #<EINVAL
64         jsr     __seterrno
65         jmp     retminus        ; return -1