]> git.sur5r.net Git - cc65/blob - libsrc/atari/rwcommon.s
This commit was generated by cvs2svn to compensate for changes in r2,
[cc65] / libsrc / atari / rwcommon.s
1 ;
2 ; common iocb setup routine for read, write
3 ; expects parameters (int fd,void *buf,int count)
4 ;
5         .include "atari.inc"
6         .include "../common/errno.inc"
7         .importzp tmp2,tmp3
8         .import incsp6,ldaxysp
9         .import __errno,__oserror
10         .import fdtoiocb
11         
12         .export __rwsetup
13
14 __rwsetup:
15         
16         ldy     #5
17         jsr     ldaxysp         ; get fd
18         jsr     fdtoiocb        ; convert to iocb
19         bmi     iocberr
20 ;       asl     a               ; iocb #  -->  iocb index
21 ;       asl     a
22 ;       asl     a
23 ;       asl     a
24         sta     tmp3            ; save it
25         ldy     #1
26         jsr     ldaxysp         ; get size
27         php                     ; save cond codes, for zero-ness
28         stx     tmp2
29         ldx     tmp3            ; iocb
30         cpx     #$80            ; iocb must be 0...7
31         bcs     iocberr 
32         sta     ICBLL,x
33         lda     tmp2            ; size hi
34         sta     ICBLH,x
35         ldy     #3              ; get buf addr (was 2 in orig. version)
36         jsr     ldaxysp
37         stx     tmp2
38         ldx     tmp3
39         sta     ICBAL,x
40         lda     tmp2
41         sta     ICBAH,x
42         jsr     incsp6          ; pop args
43         plp
44         rts
45
46 iocberr:jsr     incsp6          ; pop args
47         plp                     ; throw away
48         ldx     #$FF            ; indicate error + clear ZF
49         rts
50
51         
52 ;
53 ; this routine updates errno.  do a JMP here right after calling
54 ; CIOV.  we expect status in Y.
55 ;
56         .export __do_oserror,__seterrno,__inviocb
57 __do_oserror:
58         sty     __oserror       ; save os dependent error code
59 retminus:       
60         lda     #$FF
61         tax                     ; return -1
62         rts
63
64 __seterrno:
65         sta     __errno
66         stx     __errno+1
67         rts
68
69 ;
70 ; sets EINVAL error code and returns -1
71 ;
72
73 __inviocb:
74         lda     #<EINVAL
75         ldx     #>EINVAL
76         jsr     __seterrno
77         jmp     retminus        ; return -1