]> git.sur5r.net Git - cc65/blob - libsrc/cbm/rwcommon.s
fixed optimization bug where array index is 16-bit, e.g. arr16[i & 0x7f7f]
[cc65] / libsrc / cbm / rwcommon.s
1 ;
2 ; Ullrich von Bassewitz, 17.11.2002
3 ;
4 ; Common stuff for the read/write routines
5 ;
6
7         .export         rwcommon
8
9         .import         popax, popptr1
10         .importzp       ptr1, ptr2, ptr3, tmp2
11
12         .include        "errno.inc"
13         .include        "filedes.inc"
14
15
16 ;--------------------------------------------------------------------------
17 ; rwcommon: Pop the parameters from stack, preprocess them and place them
18 ; into zero page locations. Return carry set if the handle is invalid,
19 ; return carry clear if it is ok. If the carry is clear, the handle is
20 ; returned in A.
21
22 .proc   rwcommon
23
24         eor     #$FF
25         sta     ptr2
26         txa
27         eor     #$FF
28         sta     ptr2+1          ; Remember -count-1
29
30         jsr     popptr1         ; Get buf to ptr1, Y=0 by call
31
32         sty     ptr3
33         sty     ptr3+1          ; Clear ptr3
34
35         jsr     popax           ; Get the handle
36         cpx     #$01
37         bcs     @L9
38         cmp     #MAX_FDS        ; Set carry if fd too large
39         sta     tmp2
40 @L9:    rts                     ; Return with result in carry
41
42 .endproc
43
44