-
Notifications
You must be signed in to change notification settings - Fork 0
/
tte_loader.asm
294 lines (227 loc) · 6.97 KB
/
tte_loader.asm
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
282
283
284
285
286
287
288
289
290
291
292
293
;-----------------------------------------------------------
;
; TTE Cache Loader
;
; Coded by h0ffman
; uses 4489 byte loader and zx0 packer
;
; To use caching, apply the min / max ram range in the
; two longwords at "ExtraRam"
;
; if the file on the disk is marked as cacheable, the file
; is loaded into the cache memory and unpacked to the destination
; on subsequent loads, it will just unpack the file
;
;-----------------------------------------------------------
SCORE_TRACK = (80*2)-1
SCORE_BYTE = SCORE_TRACK*$1600
SCORE_SIZE = $168
SCORE_ADDRESS = $575c
TestMode = 0 ; 0 builds just loader / 1 builds with test rig
FileCount = 25 ; total files on disk
FileTableSize = FileCount*4*4 ; file table byte size
;-----------------------------------------------------------
;
; test rig code
;
;-----------------------------------------------------------
section loader,code_c
IF TestMode=1
Tester:
;lea RamBuffer,a0
;move.l a0,ExtraRam
;add.l #$80000,a0
;move.l a0,ExtraRam+4
move.w #$7fff,$dff096
move.w #$7fff,$dff09a
moveq #$a,d0
move.l #TestArea,d2
jsr RtypeLoader
lea TestArea,a0
move.w #$ffff,d7
.clear
clr.l (a0)+
dbra d7,.clear
moveq #$a,d0
move.l #TestArea,d2
jsr RtypeLoader
lea TestArea,a0
nop
.stop
bra .stop
ENDIF
;-----------------------------------------------------------
;
; Loader
;
;-----------------------------------------------------------
jumps:
bra.w RtypeLoader
bra.w HiscoreLoader
bra.w HiscoreSaver
ExtraRam:
dc.l 0 ; current position
dc.l 0 ; maximum address
ScoreTest:
dc.l 0
HiscoreLoader:
move.l #SCORE_BYTE,d0
moveq #4,d1
moveq #0,d2
lea ScoreTest(pc),a0
lea MFMBuffer(pc),a1
bsr LOADER
tst.l d0
bne .skip
tst.l (a0)
beq .skip
move.l #SCORE_BYTE,d0
lea SCORE_ADDRESS,a0
move.l #SCORE_SIZE,d1
bsr LOADER
.skip
rts
HiscoreSaver:
move.w LoaderTrack(pc),d0
lea TrackVars+CurrentTrk(pc),a0
move.w d0,(a0)
lea SCORE_ADDRESS,a0
lea MFMBuffer(pc),a1
bsr TrackSave
lea LoaderTrack(pc),a0
move.w #SCORE_TRACK,(a0)
rts
; d0 - filename long
; d1 - load address
RtypeLoader:
movem.l d0-d7/a0-a6,-(sp)
IF TestMode=1
lea MFMBuffer,a4
ELSE
lea MFMBuffer(pc),a4
ENDIF
move.l d2,d6 ; backup load address
and.w #$ff,d0 ; convert track number to file id
lea HEX(pc),a1
moveq #4-1,d7
.hexloop
rol.w #4,d0
lsl.l #8,d5
move.w d0,d1
and.w #$f,d1
move.b (a1,d1.w),d5 ; file id
dbra d7,.hexloop
lea FileTable(pc),a0
tst.l (a0)
bne .tableok
movem.l d0/d2,-(sp)
move.l a4,a1 ; MFM Buffer
move.l #$400,d0
move.l #FileTableSize,d1
moveq #0,d2
bsr LOADER
tst.l d0
bne LoadError
movem.l (sp)+,d0/d2
.tableok
moveq #FileCount-1,d7
.search
cmp.l (a0)+,d5
beq .found
lea 3*4(a0),a0
dbra d7,.search
bra LoadError
.found
move.l (a0)+,d0 ; disk position
move.l (a0)+,d1 ; length of data to load
move.l (a0)+,d3 ; unpacked size
move.l d1,d4 ; is it cacheable
and.l #$ffffff,d1 ; remove any config bits from length param
lea ExtraRam(pc),a5
move.l (a5),d2
beq .standardload ; no extra ram
rol.l #8,d4
btst #0,d4
beq .standardload ; not cacheable
btst #1,d4
beq .cacheload ; perform a load into the cache
move.l d0,a0
move.l d6,a1
bsr zx0_decompress
bra .exit
.cacheload
move.l 4(a5),d4
add.l d1,d2
cmp.l d4,d2
bcc .standardload ; no free ram
move.l (a5),d5 ; new load address
move.l d2,(a5) ; store next address
or.l #1<<25,-(4*2)(a0) ; set cached flag
move.l d5,-(4*3)(a0) ; set ram position of cached file
move.l d5,a0 ; load address
move.l a4,a1 ; mfm location
moveq #0,d2 ; drive 0
bsr LOADER
tst.l d0
bne LoadError
move.l d5,a0
move.l d6,a1
bsr zx0_decompress
bra .exit
.standardload
move.l d6,a0 ; load address
move.l a4,a1 ; MFM Buffer
moveq #0,d2 ; drive 0
bsr LOADER
tst.l d0
bne LoadError
move.l a0,a1
add.l d3,a0 ; end of unpacked area
move.l (a0)+,-(sp) ; backup the 8 bytes from safe area
move.l (a0)+,-(sp) ; a0 = end of packed data dest
move.l a0,a5 ; save this for later
add.l d1,a1 ; a1 = end of packed data source
.move ; move the file up after loading (because mfm and unpack overlap!)
move.b -(a1),-(a0)
subq.l #1,d1
bne .move ; end of this a0 should contain packed data
move.l d6,a1 ; destination
movem.l d5/d6/a5,-(sp) ; save file name and destination
bsr zx0_decompress
movem.l (sp)+,d5/d6/a5
move.l (sp)+,-(a5) ; restore 8 bytes from safety area
move.l (sp)+,-(a5)
.exit
movem.l (sp)+,d0-d7/a0-a6
moveq #0,d0
rts
HEX:
dc.b "0123456789ABCDEF"
LoadError:
move.w #$f00,$dff180
move.w #$000,$dff180
bra LoadError
include "newloader.asm"
include "unzx0_68000.s"
include "trackdisk.asm"
FileTable:
dcb.b FileTableSize
dc.b "END!"
;-----------------------------------------------------------
;
; Ram testing areas
;
;-----------------------------------------------------------
IF TestMode=0
MFMBuffer:
ELSE
section diskbuffer,bss_c
MFMBuffer:
ds.w $2000
section testarea,bss
TestArea:
ds.b $80000
section rambuffer,bss
RamBuffer:
ds.b $80000
ENDIF