]> git.sur5r.net Git - cc65/blob - libsrc/apple2/filename.s
1bf17af501699d3b48346903756a55ba074804f7
[cc65] / libsrc / apple2 / filename.s
1 ;
2 ; Oliver Schmidt, 30.12.2004
3 ;
4 ; File name handling for ProDOS 8 file I/O
5 ;
6
7         .export         pushname, popname
8         .import         subysp, addysp, decsp1
9
10         .include        "zeropage.inc"
11         .include        "mli.inc"
12
13 pushname:
14         sta     ptr1
15         stx     ptr1+1
16
17         ; Alloc pathname buffer
18         ldy     #64+1           ; Max pathname length + zero
19         jsr     subysp
20
21         ; Check for full pathname
22         ldy     #$00
23         lda     (ptr1),y
24         cmp     #'/'
25         beq     copy
26
27         ; Check for system prefix
28         lda     PFIXPTR
29         bne     copy
30
31         ; Use unit number of most recent accessed device
32         lda     DEVNUM
33         sta     mliparam + MLI::ON_LINE::UNIT_NUM
34
35         ; Use allocated pathname buffer
36         lda     sp
37         ldx     sp+1
38         sta     mliparam + MLI::ON_LINE::DATA_BUFFER
39         stx     mliparam + MLI::ON_LINE::DATA_BUFFER+1
40
41         ; Get volume name
42         lda     #ON_LINE_CALL
43         ldx     #ON_LINE_COUNT
44         jsr     callmli
45         bcs     addsp65
46
47         ; Get volume name length
48         lda     (sp),y
49         and     #15             ; Max volume name length
50
51         ; Bracket volume name with slashes to form prefix
52         sta     tmp1
53         lda     #'/'
54         sta     (sp),y
55         ldy     tmp1
56         iny                     ; Leading slash
57         sta     (sp),y
58         iny                     ; Trailing slash
59
60         ; Adjust source pointer for copy
61         sty     tmp1
62         lda     ptr1
63         sec
64         sbc     tmp1
65         bcs     :+
66         dec     ptr1+1
67 :       sta     ptr1
68
69         ; Copy source to allocated pathname buffer
70 copy:   lda     (ptr1),y
71         sta     (sp),y
72         beq     setlen
73         iny
74         cpy     #64+1           ; Max pathname length + zero
75         bcc     copy
76
77         ; Load oserror code
78         lda     #$40            ; "Invalid pathname"
79
80         ; Free pathname buffer
81 addsp65:ldy     #64+1
82         bne     addsp           ; Branch always
83
84         ; Alloc and set length byte
85 setlen: tya
86         jsr     decsp1          ; Preserves A
87         ldy     #$00
88         sta     (sp),y
89
90         ; Return success
91         tya
92         rts
93
94 popname:
95         ; Cleanup stack
96         ldy     #1 + 64+1       ; Length byte + max pathname length + zero
97 addsp:  jmp     addysp          ; Preserves A