]> git.sur5r.net Git - cc65/blob - libsrc/atari/ucase_fn.s
Add "joystick mouse" driver and default mouse callback routine (not
[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         ; bit #0 of tmp2 is used as a flag whether device name is present in passed string (1 = present, 0 = not present)
44         ldy     #1
45         inc     tmp2            ; initialize flag: device present
46         lda     #':'
47         cmp     (ptr4),y
48         beq     hasdev
49         iny
50         cmp     (ptr4),y
51         beq     hasdev
52         dec     tmp2            ; set flag: no device in passed string
53 hasdev:
54 .endif
55
56         ldy     #128
57         sty     tmp3            ; save size
58         jsr     subysp          ; make room on the stack
59
60         ; copy filename to the temp. place on the stack, while uppercasing it
61         ldy     #0
62
63 loop2:  lda     (ptr4),y
64         sta     (sp),y
65         beq     copy_end
66         bmi     L1              ; Not lowercase (also, invalid, should reject)
67         cmp     #'a'
68         bcc     L1              ; Not lowercase
69         and     #$DF            ; make upper case char, assume ASCII chars
70         sta     (sp),y          ; store back
71 L1:
72         iny
73         bpl     loop2           ; bpl: this way we only support a max. length of 127
74
75         ; Filename too long
76         jsr     addysp          ; restore the stack
77         sec                     ; indicate error
78         rts
79
80 copy_end:
81
82 .ifdef  DEFAULT_DEVICE
83         lda     #1
84         bit     tmp2
85         bne     hasdev2         ; yes, don't prepend something
86         bpl     hasdev2
87
88         ldy     #128+3          ; no, prepend "D:" (or other device)
89         sty     tmp3            ; adjust stack size used
90         ldy     #3
91         jsr     subysp          ; adjust stack pointer
92         dey
93 cpdev:  lda     __defdev,y
94         sta     (sp),y          ; insert device name, number and ':'
95         dey
96         bpl     cpdev
97 hasdev2:
98 .endif
99
100         ; leave A and X pointing to the modified filename
101         lda     sp
102         ldx     sp+1
103         clc                     ; indicate success
104         rts
105
106 .endproc