File: ucase_fn.s

package info (click to toggle)
cc65 2.19-2
  • links: PTS
  • area: main
  • in suites: forky, sid, trixie
  • size: 20,268 kB
  • sloc: ansic: 117,151; asm: 66,339; pascal: 4,248; makefile: 1,009; perl: 607
file content (108 lines) | stat: -rw-r--r-- 3,290 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
;
; Christian Groessler, Dec-2001
;
; ucase_fn
; helper routine to convert a string (file name) to uppercase
; used by open.s and remove.s
;
; Calling parameters:
;       AX   - points to filename
;       tmp2 - 0/$80 for don't/do prepend default device if no device
;              is present in the passed string (only .ifdef DEFAULT_DEVICE)
; Return parameters:
;       C    - 0/1 for OK/Error (filename too long)
;       AX   - points to uppercased version of the filename on the stack
;       tmp3 - amount of bytes used on the stack (needed for cleanup)
; Uses:
;       ptr4 - scratch pointer used to remember original AX pointer
;
;

        .include        "atari.inc"

.ifdef  DEFAULT_DEVICE
        .importzp tmp2
        .import __defdev
.endif
        .importzp tmp3,ptr4,sp
        .import subysp,addysp
        .export ucase_fn

.proc   ucase_fn

        ; we make sure that the filename doesn't contain lowercase letters
        ; we copy the filename we got onto the stack, uppercase it and use this
        ; one to open the iocb
        ; we're using tmp3, ptr4

        ; save the original pointer
        sta     ptr4
        stx     ptr4+1

.ifdef  DEFAULT_DEVICE
        lda     tmp2
        beq     hasdev          ; don't fiddle with device part
        ; bit #0 of tmp2 is used as an additional flag whether device name is present in passed string (1 = present, 0 = not present)
        ldy     #1
        inc     tmp2            ; initialize flag: device present
        lda     #':'
        cmp     (ptr4),y
        beq     hasdev
        iny
        cmp     (ptr4),y
        beq     hasdev
        dec     tmp2            ; set flag: no device in passed string
hasdev:
.endif

        ldy     #128
        sty     tmp3            ; save size
        jsr     subysp          ; make room on the stack

        ; copy filename to the temp. place on the stack, while uppercasing it
        ldy     #0

loop2:  lda     (ptr4),y
        sta     (sp),y
        beq     copy_end
        bmi     L1              ; Not lowercase (also, invalid, should reject)
        cmp     #'a'
        bcc     L1              ; Not lowercase
        and     #$DF            ; make upper case char, assume ASCII chars
        sta     (sp),y          ; store back
L1:
        iny
        bpl     loop2           ; bpl: this way we only support a max. length of 127

        ; Filename too long
        jsr     addysp          ; restore the stack
        sec                     ; indicate error
        rts

copy_end:

.ifdef  DEFAULT_DEVICE
        lda     #1
        bit     tmp2            ; is a device present in the string?
        bne     hasdev2         ; yes, don't prepend something
        bpl     hasdev2         ; check input parameter (tmp2 != $80)

        ldy     #128+3          ; no, prepend "Dn:" (__defdev)
        sty     tmp3            ; adjust stack size used
        ldy     #3
        jsr     subysp          ; adjust stack pointer
        dey
cpdev:  lda     __defdev,y
        sta     (sp),y          ; insert device name, number and ':'
        dey
        bpl     cpdev
hasdev2:
.endif

        ; leave A and X pointing to the modified filename
        lda     sp
        ldx     sp+1
        clc                     ; indicate success
        rts

.endproc