]> git.sur5r.net Git - cc65/blob - libsrc/atari/ucase_fn.s
lseek: Implement additional feedback from PR #723.
[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 ;       tmp2 - 0/$80 for don't/do prepend default device if no device
11 ;              is present in the passed string (only .ifdef DEFAULT_DEVICE)
12 ; Return parameters:
13 ;       C    - 0/1 for OK/Error (filename too long)
14 ;       AX   - points to uppercased version of the filename on the stack
15 ;       tmp3 - amount of bytes used on the stack (needed for cleanup)
16 ; Uses:
17 ;       ptr4 - scratch pointer used to remember original AX pointer
18 ;
19 ;
20
21         .include        "atari.inc"
22
23 .ifdef  DEFAULT_DEVICE
24         .importzp tmp2
25         .import __defdev
26 .endif
27         .importzp tmp3,ptr4,sp
28         .import subysp,addysp
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         lda     tmp2
44         beq     hasdev          ; don't fiddle with device part
45         ; bit #0 of tmp2 is used as an additional flag whether device name is present in passed string (1 = present, 0 = not present)
46         ldy     #1
47         inc     tmp2            ; initialize flag: device present
48         lda     #':'
49         cmp     (ptr4),y
50         beq     hasdev
51         iny
52         cmp     (ptr4),y
53         beq     hasdev
54         dec     tmp2            ; set flag: no device in passed string
55 hasdev:
56 .endif
57
58         ldy     #128
59         sty     tmp3            ; save size
60         jsr     subysp          ; make room on the stack
61
62         ; copy filename to the temp. place on the stack, while uppercasing it
63         ldy     #0
64
65 loop2:  lda     (ptr4),y
66         sta     (sp),y
67         beq     copy_end
68         bmi     L1              ; Not lowercase (also, invalid, should reject)
69         cmp     #'a'
70         bcc     L1              ; Not lowercase
71         and     #$DF            ; make upper case char, assume ASCII chars
72         sta     (sp),y          ; store back
73 L1:
74         iny
75         bpl     loop2           ; bpl: this way we only support a max. length of 127
76
77         ; Filename too long
78         jsr     addysp          ; restore the stack
79         sec                     ; indicate error
80         rts
81
82 copy_end:
83
84 .ifdef  DEFAULT_DEVICE
85         lda     #1
86         bit     tmp2            ; is a device present in the string?
87         bne     hasdev2         ; yes, don't prepend something
88         bpl     hasdev2         ; check input parameter (tmp2 != $80)
89
90         ldy     #128+3          ; no, prepend "Dn:" (__defdev)
91         sty     tmp3            ; adjust stack size used
92         ldy     #3
93         jsr     subysp          ; adjust stack pointer
94         dey
95 cpdev:  lda     __defdev,y
96         sta     (sp),y          ; insert device name, number and ':'
97         dey
98         bpl     cpdev
99 hasdev2:
100 .endif
101
102         ; leave A and X pointing to the modified filename
103         lda     sp
104         ldx     sp+1
105         clc                     ; indicate success
106         rts
107
108 .endproc