-
Notifications
You must be signed in to change notification settings - Fork 0
/
basis.system.s
200 lines (156 loc) · 4.45 KB
/
basis.system.s
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
;;; ============================================================
;;; BASIS.SYSTEM relay for DOS3.3.LAUNCHER
;;; ============================================================
.setcpu "6502"
.include "apple2.inc"
.include "prodos.inc"
neworg := $1000 ; Relocated to...
filename_buffer := $1800 ; Saved
filename_prefix := $1880 ; Unchanged
launcher_prefix := $1900 ; Potentially shortened
io_buf := $1C00
sys_start_address := $2000
kMaxSysLength = ($BF00 - sys_start_address)
.org sys_start_address
;;; ============================================================
;;; Interpeter protocol
;;; http://www.easy68k.com/paulrsm/6502/PDOS8TRM.HTM#5.1.5.1
jmp start
.byte $EE, $EE ; signature
.byte 65 ; pathname buffer length ($2005)
str_path:
.res 65 ; pathname buffer ($2006)
.proc get_prefix_params1
param_count: .byte 1
pathname: .addr filename_prefix
.endproc
.proc get_prefix_params2
param_count: .byte 1
pathname: .addr launcher_prefix
.endproc
;;; ============================================================
start:
;;; Save filename
ldx str_path
: lda str_path,x
sta filename_buffer,x
dex
bpl :-
;;; Save prefix
MLI_CALL GET_PREFIX, get_prefix_params1
MLI_CALL GET_PREFIX, get_prefix_params2
;;; Relocation to $1000 since launcher will overwrite us at $2000
ldx #reloc_end - reloc_start
: lda reloc_start-1,x
sta neworg-1,x
dex
bne :-
jmp newstart
reloc_start:
.org neworg
launcher_filename:
PASCAL_STRING "DOS3.3.LAUNCHER"
.proc get_file_info_params
param_count: .byte $A
pathname: .addr filename_buffer
access: .byte 0
file_type: .byte 0
aux_type: .word 0
storage_type: .byte 0
blocks_used: .word 0
mod_date: .word 0
mod_time: .word 0
create_date: .word 0
create_time: .word 0
.endproc
.proc open_params
param_count: .byte 3
path: .addr launcher_filename
buffer: .addr io_buf
ref_num: .byte 0
.endproc
.proc read_params
param_count: .byte 4
ref_num: .byte 1
buffer: .word sys_start_address
request: .word kMaxSysLength
trans: .word 0
.endproc
.proc close_params
param_count: .byte 1
ref_num: .byte 0
.endproc
.proc set_prefix_params
param_count: .byte 1
pathname: .addr launcher_prefix
.endproc
newstart:
;;; Check file type is in $F1...$F4
MLI_CALL GET_FILE_INFO, get_file_info_params
bcs quit
lda get_file_info_params::file_type
cmp #$F1
bcc quit
cmp #$F4+1
bcs quit
;;; Find DOS3.3.LAUNCHER
check_for_launcher:
MLI_CALL OPEN, open_params
beq load_launcher
ldy launcher_prefix ; Pop path segment.
: lda launcher_prefix,y
cmp #'/'
beq update_prefix
dey
cpy #1
bne :-
beq quit ; always
update_prefix: ; Update prefix and try again.
dey
sty launcher_prefix
MLI_CALL SET_PREFIX, set_prefix_params
jmp check_for_launcher
;;; Load launcher
load_launcher:
lda open_params::ref_num
sta read_params::ref_num
MLI_CALL READ, read_params
bcs quit
MLI_CALL CLOSE, close_params
bcs quit
;;; Populate startup pathname buffer
startup_buffer := $2006
;; Prefix
ldx filename_prefix
: lda filename_prefix,x
sta startup_buffer,x
dex
bpl :-
;; Append filename
ldx filename_prefix
inx
ldy #0
: lda filename_buffer+1,y
sta startup_buffer,x
iny
inx
cpy filename_buffer
bne :-
dex
stx startup_buffer
;;; Invoke launcher
jmp sys_start_address
;;; In case of error, QUIT to ProDOS
quit:
MLI_CALL QUIT, quit_params
brk
.proc quit_params
param_count: .byte 4
.byte 0
.word 0
.byte 0
.word 0
.endproc
.org reloc_start + * - neworg
reloc_end:
.assert (reloc_end - reloc_start) < $100, error, "more than one page, oops"