]> git.sur5r.net Git - cc65/blob - libsrc/telemon30/_open.s
Correcting some bugs
[cc65] / libsrc / telemon30 / _open.s
1         .export         _open
2                 .import                 addysp,popax
3                 .importzp sp,tmp2,tmp3,tmp1
4                 ; int open (const char* name, int flags, ...);    /* May take a mode argument */
5     .include        "telemon30.inc"
6         .include                "errno.inc"
7         .include        "fcntl.inc"     
8         
9 .proc _open
10 ; Throw away any additional parameters passed through the ellipsis
11
12         dey                     ; Parm count < 4 shouldn't be needed to be...
13         dey                     ; ...checked (it generates a c compiler warning)
14         dey
15         dey
16         beq     parmok          ; Branch if parameter count ok
17         jsr     addysp          ; Fix stack, throw away unused parameters
18
19 ; Parameters ok. Pop the flags and save them into tmp3
20
21 parmok: jsr     popax           ; Get flagss
22                 sta             tmp3 ; save flags
23                 
24                 ;AND            #O_RDONLY
25                 ;beq    READONLY
26                 ;lda tmp3
27                 ;AND #O_WRONLY
28                 ;beq WRITEONLY
29                 ;jmp next
30
31 ;READONLY:
32 ;               lda #'r'
33 ;               BRK_TELEMON XWR0
34 ;               jmp next
35 ;WRITEONLY:     
36 ;               lda #'w'
37 ;               BRK_TELEMON XWR0        
38                 
39 ;next:          
40 ; Get the filename from stack and parse it. Bail out if is not ok
41
42         jsr     popax           ; Get name
43                 
44                 
45                 ldy tmp3 ; Get flags
46                 
47                 
48                 BRK_TELEMON XOPEN
49                 
50        ; jsr     fnparse         ; Parse it
51         ;tax
52         ;bne     oserror         ; Bail out if problem with name
53
54 ; Get a free file handle and remember it in tmp2
55
56       ;  jsr     freefd
57         ;lda     #EMFILE         ; Load error code
58         ;bcs     seterrno        ; Jump in case of errors
59         ;stx     tmp2
60 ;
61                 
62                 
63                 rts
64 .endproc
65                 
66