-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathBOOTWRT.S
More file actions
281 lines (227 loc) · 5.11 KB
/
BOOTWRT.S
File metadata and controls
281 lines (227 loc) · 5.11 KB
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
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
_prg_base
bra main
section text
main
move.l 4(sp),a0 * base page
* lea _stackend,sp
move.l #$100,d0 * length of basepage
add.l $c(a0),d0 * length of TEXT
add.l $14(a0),d0 * length of DATA
add.l $1c(a0),d0 * length of BSS
move.l d0,-(sp)
move.l a0,-(sp)
clr.w -(sp)
move.w #$4a,-(sp) * mshrink
trap #1
lea 12(sp),sp
pea _info
move.w #$9,-(sp) * print line
trap #1
addq.l #6,sp
jsr _cache * read CLOCK.BIN into memory
cmp.w #0,d0
bge.s .cached
* error on open
pea _errmsg
move.w #$9,-(sp) * print line
trap #1
addq.l #6,sp
move.w #7,-(sp) * cin
trap #1
addq.l #2,sp
bra _exit2
.cached pea _cached
move.w #$9,-(sp) * print line
trap #1
addq.l #6,sp
_again
.exec jsr _executable
cmp.b #0,d0
beq .notexec
* boot sector already executable, warn
pea _warn
move.w #$9,-(sp) * print line
trap #1
addq.l #6,sp
.notexec
pea _ask
move.w #$9,-(sp) * print line
trap #1
addq.l #6,sp
move.w #7,-(sp) * cin
trap #1
addq.l #2,sp
cmp.b #'y',d0
bne.s _abort
* if the disk was changed, re-check executable status
move.w #0,-(sp)
move.w #9,-(sp)
trap #13
addq.l #4,sp
cmp.b #0,d0 * Getting a lot of false positives from
beq.s .ok * "may have been changed" (1)
* But only checking for 2 misses a lot
* of disk changes. Due to the HxC??
pea _changed
move.w #$9,-(sp) * print line
trap #1
addq.l #6,sp
bra .exec
.ok pea _writing
move.w #$9,-(sp) * print line
trap #1
addq.l #6,sp
pea _install
move.w #38,-(sp)
trap #14
addq.l #6,sp
pea _done
move.w #$9,-(sp) * print line
trap #1
addq.l #6,sp
_exit move.w #7,-(sp) * cin
trap #1
addq.l #2,sp
cmp #'y',d0
beq _again
_exit2 move.w #0,-(sp)
move.w #$4c,-(sp) * p_term
trap #1
_abort
pea _aborted
move.w #$9,-(sp) * print line
trap #1
addq.l #6,sp
bra.s _exit
* Check if the boot sector is already executable
* return value in d0. 0 = not executable, 1 = executable
_executable
move.w #1,-(sp)
move.w #0,-(sp)
move.w #0,-(sp)
move.w #1,-(sp)
move.w #0,-(sp)
move.l #0,-(sp)
move.l #_temp,-(sp)
move.w #8,-(sp)
trap #14
lea 20(sp),sp
move.w _temp+510,d7
move.w #1,-(sp)
move.w #-1,-(sp)
move.l #-1,-(sp)
move.l #_temp,-(sp)
move.w #$12,-(sp)
trap #14
lea 14(sp),sp
moveq #0,d0
cmp.w _temp+510,d7
bne.s .exit
moveq #1,d0
.exit
rts
* Loads CACHE.BIN from disk (and skips TOS .prg header)
* returns error value from f_open in d0
_cache
move.w #0,-(sp)
move.l #_fname,-(sp)
move.w #$3d,-(sp) * f_open
trap #1
addq.l #8,sp
tst.w d0
bmi.s _error
move.w d0,_fhandle
move.w #0,-(sp) * f_seek
move.w _fhandle,-(sp)
move.l #28,-(sp)
move.w #$42,-(sp)
trap #1
lea 10(sp),sp
move.l #_sector+30,-(sp)
move.l #480,-(sp)
move.w _fhandle,-(sp)
move.w #$3f,-(sp) * f_read
trap #1
lea 12(sp),sp
move.w _fhandle,-(sp)
move.w #$3e,-(sp)
trap #1
addq.l #4,sp
_error rts
**
* gemdos $19 - get current drive
* bios 7 - get device parameter block
* xbios 8 - read sectors
* xbios 9 - write sectors
* xbios $12 - build prototype boot sector
**
_install
move.w #1,-(sp)
move.w #0,-(sp)
move.w #0,-(sp)
move.w #1,-(sp)
move.w #0,-(sp)
move.l #0,-(sp)
move.l #_temp,-(sp)
move.w #8,-(sp)
trap #14
lea 20(sp),sp
move.w #$601c,_temp * bra to code
* move.w #$4e75,_temp * rts
lea _sector+30,a0
lea _temp+30,a1
move.l #480/4-1,d0
.l1 move.l (a0)+,(a1)+
dbf d0,.l1
move.w #1,-(sp)
move.w #-1,-(sp)
move.l #-1,-(sp)
move.l #_temp,-(sp)
move.w #$12,-(sp)
trap #14
lea 14(sp),sp
move.w #1,-(sp)
move.w #0,-(sp)
move.w #0,-(sp)
move.w #1,-(sp)
move.w #0,-(sp)
move.l #0,-(sp)
move.l #_temp,-(sp)
move #9,-(sp)
trap #14
lea 20(sp),sp
rts
section data
_fname dc.b 'CLOCK.BIN',0
_info
dc.b 27,'E'
dc.b ' This utility is part of the Dallas DS1216 RTC + Y2K fix package',$d,$a
dc.b ' written by Troed/SYNC. It will write the file CLOCK.BIN which',$d,$a
dc.b ' should reside in the same directory to the boot sector of this',$d,$a
dc.b ' or another disk in drive A:. You can also simply put DALLRTC.PRG',$d,$a
dc.b ' in an AUTO folder if you do not want to use the boot sector.',$d,$a
dc.b $d,$a,0
_cached dc.b ' CLOCK.BIN has now been cached in memory, feel free to switch disk.',$d,$a
dc.b $d,$a,0
_ask dc.b ' Write CLOCK.BIN to bootsector in drive A:? (y/[n])',$d,$a
dc.b $d,$a,0
_warn dc.b ' ',27,'p',' WARNING ',27,'q',' The current boot sector is already executable. Make sure',$d,$a
dc.b ' you know what you''re about to overwrite!',$d,$a
dc.b $d,$a,0
_changed
dc.b ' Disk change detected - rechecking ...',$d,$a
dc.b $d,$a,0
_writing
dc.b ' Writing bootsector ... ',0
_done dc.b 'done. Press SPACE to exit or ''y'' to write another',$d,$a
dc.b $d,$a,0
_aborted
dc.b ' Aborted. Press SPACE to exit or ''y'' to write another',$d,$a
dc.b $d,$a,0
_errmsg dc.b ' CLOCK.BIN could not be opened. Press any key to exit.',0
even
section bss
_fhandle ds.w 1
_sector ds.b 512
_temp ds.b 512
_prg_end