-
Notifications
You must be signed in to change notification settings - Fork 0
/
elfn_load_save.a
229 lines (196 loc) · 4.25 KB
/
elfn_load_save.a
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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
;==============================================================================
; DEMON - copy(l)eft 2018 http://harald.ist.org/
; tabsize=8
;==============================================================================
;==============================================================================
!zone ELFN_LOAD
;==============================================================================
.addr = $f7
.fn_y = $fb
.to_addr_given = $fc
.fptr = $fd
.strbuf = TAPE_BUFFER
.error JMP line_show_error
elfn_load
;------------------------------------------------------------------------------
LDY # 1
JSR line_expect_quoted ; Check for quoted file name
BCS .error
.check_quot1 LDA .strbuf+1 ; Verify opening quotation mark ;;?
!convtab SCR { CMP #'"' }
BEQ .check_quot2
LDY # 1
BNE .error ; Will always jump
.check_quot2 LDA .strbuf-1,Y ; Verify closing quotation mark ;;?
!convtab SCR { CMP #'"' }
BEQ .check_fnlength
DEY
JMP .error
.check_fnlength STY .fn_y ; Check for a space after quoted fn
CPY # 4
BCS .check_space
DEY
JMP .error
.check_space LDA .strbuf,Y ; Verify space after fn ;;?
!convtab SCR { CMP #' ' }
BNE .error
INY
JSR line_expect_int8 ; Get device number
BCS .error
STA dos_device
JSR line_expect_int16 ; Get optional load address
BCS .no_load_addr
STX .addr
STA .addr+1
LDA #$ff
JMP .start_load
.no_load_addr LDA #$00
;------------------------------------------------------------------------------
.start_load STA .to_addr_given
LDY .fn_y ; Find end of file name
DEY
TYA
CLC
ADC #<.strbuf
STA .fptr
LDA #>.strbuf
STA .fptr+1
LDA # 0
TAY
STA (.fptr),Y ; Write EOS
LDA #<.strbuf+2
STA .fptr
LDA #>.strbuf+2
STA .fptr+1
LDY # 0 ; Convert parameter to PETSCII fname
.loop_convert LDA (.fptr),Y
BEQ .convert_done
JSR screen_to_petscii
JSR to_upper_case
JSR petscii_to_screen
STA (.fptr),Y
INY
BNE .loop_convert
.convert_done
;------------------------------------------------------------------------------
; Call Toolbox load file function
.load LDA .to_addr_given
BEQ .skip_load_addr
LDA .addr
PHA
LDA .addr+1
PHA
.skip_load_addr LDA #<.strbuf+2
PHA
LDA #>.strbuf+2
PHA
LDA dos_device
PHA
LDA .to_addr_given
BEQ .load_auto
JSR load_from_file
JMP .load_done
.load_auto JSR load_from_file_auto
.load_done
JSR puts_newline
!ifdef TB_DISK_ERROR {
JSR get_disk_error
}
JSR puts
CLC
RTS
;==============================================================================
!zone ELFN_SAVE
;==============================================================================
.addr = $f7
.end = $f9
.fn_y = $fb
.fptr = $fd
.strbuf = TAPE_BUFFER
.error JMP line_show_error
elfn_save
;------------------------------------------------------------------------------
LDY # 1
JSR line_expect_quoted
BCS .error
.check_quot1 LDA .strbuf+1
!convtab SCR { CMP #'"' }
BEQ .check_quot2
LDY # 1
BNE .error ; Will always jump
.check_quot2 LDA .strbuf-1,Y
!convtab SCR { CMP #'"' }
BEQ .check_fnlength
DEY
JMP .error
.check_fnlength STY .fn_y
CPY # 4
BCS .check_space
DEY
JMP .error
.check_space LDA .strbuf,Y
!convtab SCR { CMP #' ' }
BNE .error
INY
JSR line_expect_int8
BCS .error
STA dos_device
JSR line_expect_int16
BCS .error
STX .addr
STA .addr+1
JSR line_expect_int16
BCS .error
STX .end
STA .end+1
;------------------------------------------------------------------------------
.start_save LDY .fn_y ; Find end of file name
DEY
TYA
CLC
ADC #<.strbuf
STA .fptr
LDA #>.strbuf
STA .fptr+1
LDA # 0
TAY
STA (.fptr),Y ; Write EOS
LDA #<.strbuf+2
STA .fptr
LDA #>.strbuf+2
STA .fptr+1
LDY # 0
.loop_convert LDA (.fptr),Y
BEQ .convert_done
JSR screen_to_petscii
JSR to_upper_case
JSR petscii_to_screen
STA (.fptr),Y
INY
BNE .loop_convert
.convert_done
;------------------------------------------------------------------------------
.load LDA .addr
PHA
LDA .addr+1
PHA
LDA .end
PHA
LDA .end+1
PHA
LDA #<.strbuf+2
PHA
LDA #>.strbuf+2
PHA
LDA dos_device
PHA
JSR save_to_file
JSR puts_newline
!ifdef TB_DISK_ERROR {
JSR get_disk_error
}
JSR puts
CLC
RTS
;==============================================================================
!eof