]> git.sur5r.net Git - cc65/blob - libsrc/atari/ucase_fn.s
Parse the name passed to opendir().
[cc65] / libsrc / atari / ucase_fn.s
1 ;
2 ; Christian Groessler, Dec-2001
3 ;
4 ; ucase_fn
5 ; helper routine to convert a string (file name) to uppercase
6 ; used by open.s and remove.s
7 ;
8 ; Calling parameters:
9 ;       AX   - points to filename
10 ; Return parameters:
11 ;       C    - 0/1 for OK/Error (filename too long)
12 ;       AX   - points to uppercased version of the filename on the stack
13 ;       tmp3 - amount of bytes used on the stack (needed for cleanup)
14 ; Uses:
15 ;       ptr4 - scratch pointer used to remember original AX pointer
16 ;
17 ;
18
19         .include        "atari.inc"
20
21 .ifdef  DEFAULT_DEVICE
22         .importzp tmp2
23         .import __defdev
24 .endif
25         .importzp tmp3,ptr4,sp
26         .import subysp,addysp
27         .export ucase_fn
28
29 .proc   ucase_fn
30
31         ; we make sure that the filename doesn't contain lowercase letters
32         ; we copy the filename we got onto the stack, uppercase it and use this
33         ; one to open the iocb
34         ; we're using tmp3, ptr4
35
36         ; save the original pointer
37         sta     ptr4
38         stx     ptr4+1
39
40 .ifdef  DEFAULT_DEVICE
41         ldy     #1
42         sty     tmp2            ; initialize flag: device present in passed string
43         lda     #':'
44         cmp     (ptr4),y
45         beq     hasdev
46         iny
47         cmp     (ptr4),y
48         beq     hasdev
49         sta     tmp2            ; set flag: no device in passed string
50 hasdev:
51 .endif
52
53         ldy     #128
54         sty     tmp3            ; save size
55         jsr     subysp          ; make room on the stack
56
57         ; copy filename to the temp. place on the stack, also uppercasing it
58         ldy     #0
59
60 loop2:  lda     (ptr4),y
61         sta     (sp),y
62         beq     copy_end
63         bmi     L1              ; Not lowercase (also, invalid, should reject)
64         cmp     #'a'
65         bcc     L1              ; Not lowercase
66         and     #$DF            ; make upper case char, assume ASCII chars
67         sta     (sp),y          ; store back
68 L1:
69         iny
70         bpl     loop2           ; bpl: this way we only support a max. length of 127
71
72         ; Filename too long
73         jsr     addysp          ; restore the stack
74         sec                     ; indicate error
75         rts
76
77 copy_end:
78
79 .ifdef  DEFAULT_DEVICE
80         lda     tmp2
81         cmp     #1              ; was device present in passed string?
82         beq     hasdev2         ; yes, don't prepend something
83
84         ldy     #128+3          ; no, prepend "D:" (or other device)
85         sty     tmp3            ; adjust stack size used
86         ldy     #3
87         jsr     subysp          ; adjust stack pointer
88         dey
89 cpdev:  lda     __defdev,y
90         sta     (sp),y          ; insert device name, number and ':'
91         dey
92         bpl     cpdev
93 hasdev2:
94 .endif
95
96         ; leave A and X pointing to the modified filename
97         lda     sp
98         ldx     sp+1
99         clc                     ; indicate success
100         rts
101
102 .endproc