]> git.sur5r.net Git - cc65/blob - libsrc/atari/ucase_fn.s
Remove the ",r" spec
[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         .importzp tmp3,ptr4,sp
22         .import _strupr,subysp
23         .export ucase_fn
24
25 ucase_fn:       .proc
26
27         ; we make sure that the filename doesn't contain lowercase letters
28         ; we copy the filename we got onto the stack, uppercase it and use this
29         ; one to open the iocb
30         ; we're using tmp3, ptr4
31
32         ; save the original pointer
33         sta     ptr4
34         stx     ptr4+1
35
36         ; now we need the length of the name
37         ldy     #0
38 loop:   lda     (ptr4),y
39         beq     str_end
40         cmp     #ATEOL          ; we also accept Atari EOF char as end of string
41         beq     str_end
42         iny
43         bne     loop            ; not longer than 255 chars (127 real limit)
44 toolong:sec                     ; indicate error
45         rts
46
47 str_end:iny                     ; room for terminating zero
48         cpy     #128            ; we only can handle lenght < 128
49         bcs     toolong
50         sty     tmp3            ; save size
51         jsr     subysp          ; make room on the stack
52
53         ; copy filename to the temp. place on the stack
54         lda     #0              ; end-of-string
55         sta     (sp),y          ; Y still contains length + 1
56         dey
57 loop2:  lda     (ptr4),y
58         sta     (sp),y
59         dey
60         bpl     loop2           ; bpl: this way we only support a max. length of 127
61
62         ; uppercase the temp. filename
63         ldx     sp+1
64         lda     sp
65         jsr     _strupr
66
67         ; leave X and Y pointing to the modified filename
68         lda     sp
69         ldx     sp+1
70         clc                     ; indicate success
71         rts
72
73 ucase_fn:       .endproc