-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathloader.inc
194 lines (169 loc) · 3.92 KB
/
loader.inc
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
;BSD 2-Clause License
;
;Copyright (c) 2021-2023, Stefan Jakobsson
;All rights reserved.
;Redistribution and use in source and binary forms, with or without
;modification, are permitted provided that the following conditions are met:
;
;1. Redistributions of source code must retain the above copyright notice, this
; list of conditions and the following disclaimer.
;
;2. Redistributions in binary form must reproduce the above copyright notice,
; this list of conditions and the following disclaimer in the documentation
; and/or other materials provided with the distribution.
;
;THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
;AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
;IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
;DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
;FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
;DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
;SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
;CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
;OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
;OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
;******************************************************************************
;Function name: loader_run
;Purpose......: Loads the source file
;Input........: Nothing
;Output.......: Nothing
;Errors.......: Nothing
.proc loader_run
;Set default response code = OK
lda #0
ldx #<msg_ok
ldy #>msg_ok
sec
jsr response_set
;Prepare pass 1
lda #1
sta line_pass
jsr symbol_init
jsr token_init
jsr controlcode_init
jsr line_init
jsr file_init
jsr symfile_init
ldx #<file_main_name
ldy #>file_main_name
lda file_main_len
jsr file_open
cmp #0
beq pass1_loop
jmp exit
;Read and process each line
pass1_loop:
jsr file_readln
cmp #2
beq err1a
cmp #3
beq err1b
jsr line_pass1
bcs err1a
lda file_cur_num
cmp #2
bcs pass1_loop
bra eof1
err1a:
jsr file_set_status_as_response
bra exit
err1b:
clc
lda #RESPONSE_LINE_TOO_LONG
jsr response_set
bra exit
eof1:
;Prepare pass 2
lda #2
sta line_pass
lda symfile_active
beq :+
jsr symfile_header2
bcs err2a
: jsr line_init
jsr file_init
ldx #<file_main_name
ldy #>file_main_name
lda file_main_len
jsr file_open
cmp #0
bne exit
;Read and process each line again
pass2_loop:
jsr file_readln
cmp #2
beq err2a
cmp #3
beq err2b
jsr line_pass2
bcs err2a
lda file_cur_num
cmp #2
bcs pass2_loop
bra eof2
err2a:
jsr file_set_status_as_response
bra eof2
err2b:
clc
lda #RESPONSE_LINE_TOO_LONG
jsr response_set
eof2:
;Set BASIC pointers
lda line_code
sta KERNAL_VARTAB
sta KERNAL_ARYTAB
sta KERNAL_STREND
lda line_code+1
sta KERNAL_VARTAB+1
sta KERNAL_ARYTAB+1
sta KERNAL_STREND+1
exit:
jsr symfile_close
jsr file_init
bridge_setaddr KERNAL_CLRCHN
bridge_call
saveas:
lda #BASLOAD_RAM1
sta RAM_SEL
lda saveas_len
beq :+
bridge_setaddr KERNAL_SETNAM
ldx #<saveas_name
ldy #>saveas_name
lda saveas_len
bridge_call
bridge_setaddr KERNAL_SETLFS
lda #1
ldx #8
ldy #1
bridge_call
bridge_setaddr KERNAL_SAVE
lda #$01
sta TEMP1
lda #$08
sta TEMP1+1
lda #TEMP1
ldx line_code
ldy line_code+1
bridge_call
jsr file_status
cmp #0
beq :+
bridge_setaddr KERNAL_CHROUT
lda #13
bridge_call
lda #<file_buf
sta TEMP1
lda #>file_buf
sta TEMP1+1
ldy #0
loop:
lda (TEMP1),y
cmp #0
beq :+
bridge_call
iny
bne loop
: rts
.endproc