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