]> git.sur5r.net Git - cc65/blob - libsrc/atari/ucase_fn.s
Any field without a name is legal but useless in a union.
[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 .ifdef  DYNAMIC_DD
24         .import __defdev
25 .endif
26 .endif
27         .importzp tmp3,ptr4,sp
28         .import _strupr,subysp
29         .export ucase_fn
30
31 .proc   ucase_fn
32
33         ; we make sure that the filename doesn't contain lowercase letters
34         ; we copy the filename we got onto the stack, uppercase it and use this
35         ; one to open the iocb
36         ; we're using tmp3, ptr4
37
38         ; save the original pointer
39         sta     ptr4
40         stx     ptr4+1
41
42 .ifdef  DEFAULT_DEVICE
43         ldy     #1
44         sty     tmp2            ; initialize flag: device present in passed string
45         lda     #':'
46         cmp     (ptr4),y
47         beq     hasdev
48         iny
49         cmp     (ptr4),y
50         beq     hasdev
51         sta     tmp2            ; set flag: no device in passed string
52 hasdev:
53 .endif
54
55         ; now we need the length of the name
56         ldy     #0
57 loop:   lda     (ptr4),y
58         beq     str_end
59         cmp     #ATEOL          ; we also accept Atari EOF char as end of string
60         beq     str_end
61         iny
62         bne     loop            ; not longer than 255 chars (127 real limit)
63 toolong:sec                     ; indicate error
64         rts
65
66 str_end:iny                     ; room for terminating zero
67         cpy     #128            ; we only can handle lenght < 128
68         bcs     toolong
69         sty     tmp3            ; save size
70         jsr     subysp          ; make room on the stack
71
72         ; copy filename to the temp. place on the stack
73         lda     #0              ; end-of-string
74         sta     (sp),y          ; Y still contains length + 1
75         dey
76 loop2:  lda     (ptr4),y
77         sta     (sp),y
78         dey
79         bpl     loop2           ; bpl: this way we only support a max. length of 127
80
81 .ifdef  DEFAULT_DEVICE
82         lda     tmp2
83         cmp     #1              ; was device present in passed string?
84         beq     hasdev2         ; yes, don't prepend something
85
86         inc     tmp3            ; no, prepend "D:"
87         inc     tmp3            ; adjust stack size used
88         inc     tmp3
89         ldy     #3
90         jsr     subysp          ; adjust stack pointer
91         ldy     #2
92         lda     #':'
93         sta     (sp),y          ; insert ':'
94         dey
95 .ifdef  DYNAMIC_DD
96         lda     __defdev+1
97 .else
98         lda     #'0'+DEFAULT_DEVICE
99 .endif
100         sta     (sp),y          ; insert device number
101         dey
102         lda     #'D'
103         sta     (sp),y          ; insert 'D'
104 hasdev2:
105 .endif
106         ; uppercase the temp. filename
107         ldx     sp+1
108         lda     sp
109         jsr     _strupr
110
111         ; leave A and X pointing to the modified filename
112         lda     sp
113         ldx     sp+1
114         clc                     ; indicate success
115         rts
116
117 .endproc