-
Notifications
You must be signed in to change notification settings - Fork 30
/
romsplit.S
538 lines (437 loc) · 8.76 KB
/
romsplit.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
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
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
;APSFFD31A8FFFD31A8FFFD31A8FFFD31A8FFFD31A8FFFD31A8FFFD31A8FFFD31A8FFFD31A8F58544B4C
t
; Simple program
; loads file "DiagROM" and saves three files:
; 16bit.bin - byteswapped image for burning 16 bit eproms
; 32bitHI.bin - byteswapped image of high word for burning 32 bit eproms
; 32bitLO.bin - byteswapped image of low word for burning 32 bit eproms
MEMF_FAST = 4
SIZE = 512*1024
SIZE64K = 64*1024
move.l 4.w,a6
lea Dos,a1
jsr -408(a6) ;Open DOS library
move.l d0,DOSBase
lea InitTxt,a0
bsr Print
lea infile,a0
bsr LoadFile
cmp.b #0,end
bne Error
move.l d0,inadr
move.l #SIZE,d1
move.l d1,FileSize
move.l #512*1024,d0
bsr AllocateMemory ; My own memoryallocateroutine that can be easly freed with just one function for all allocations.
cmp.b #0,d0
beq outofmem
move.l d0,workadr
bsr CopyAll
bsr ByteSwap
lea Filename16,a0
bsr SaveFile
cmp.l #0,d0
bne Error
bsr CopyHigh
bsr ByteSwap
lea Filename32hi,a0
bsr SaveFile
cmp.l #0,d0
bne Error
bsr CopyLo
bsr ByteSwap
lea Filename32lo,a0
bsr SaveFile
cmp.l #0,d0
bne Error
lea infilea1k,a0
bsr LoadFile
cmp.b #0,end
bne Error
move.l d0,inadr
move.l #SIZE64K/2,FileSize
bsr CopyEven
lea FilenameA1kEven,a0
bsr SaveFile
cmp.l #0,d0
bne Error
bsr CopyOdd
lea FilenameA1kOdd,a0
bsr SaveFile
cmp.l #0,d0
bne Error
bsr FreeAllocated
clr.l d0
clr.l d1
rts
Error:
bchg #1,$bfe001
move.b #1,end
bsr FreeAllocated
move.l #40,d0
clr.l d1
rts
outofmem:
lea outmem,a0
bsr Print
bra Error
CopyAll:
clr.l d0
move.l inadr,a0
move.l workadr,a1
.loop:
move.l (a0)+,(a1)+
add.l #4,d0
cmp.l #SIZE,d0
blt .loop
rts
CopyHigh:
clr.l d0
move.l inadr,a0
move.l workadr,a1
move.l a1,a2
add.l #SIZE/2,a2
.loop:
move.w (a0),d1
move.w d1,(a1)+
move.w d1,(a2)+
addi.l #4,a0
add.l #4,d0
cmp.l #SIZE,d0
blt .loop
rts
CopyLo:
clr.l d0
move.l inadr,a0
move.l workadr,a1
move.l a1,a2
add.l #SIZE/2,a2
.loop:
move.w 2(a0),d1
move.w d1,(a1)+
move.w d1,(a2)+
addi.l #4,a0
add.l #4,d0
cmp.l #SIZE,d0
blt .loop
rts
ByteSwap:
clr.l d0
move.l workadr,a0
.loop:
move.b (a0),d1
move.b 1(a0),d2
move.b d2,(a0)+
move.b d1,(a0)+
add.l #2,d0
cmp.l #SIZE,d0
blt .loop
rts
CopyEven:
clr.l d0
move.l inadr,a0
move.l workadr,a1
.loop:
move.b (a0),(a1)+
addi.l #2,a0
add.l #2,d0
cmp.l #SIZE64K,d0
blt .loop
rts
CopyOdd:
clr.l d0
move.l inadr,a0
move.l workadr,a1
.loop:
move.b 1(a0),(a1)+
addi.l #2,a0
add.l #2,d0
cmp.l #SIZE64K,d0
blt .loop
rts
;----------------------------------------
AllocateMemory: ;Allocate memory AND adds
;in the Allocated memorylist
;for easy deallocation.
;IN: D0=Memoryblock wanted
; D1=memoryType wanted
;OUT:D0=Memoryposition|0=Error
movem.l a0-a6/d1-d7,-(a7)
add.l #8,D0 ;Adds bytes for handling
bsr.s AllocMem
beq.s .Error
lea Allocated_Memory_Pos,a0
.Loop: move.l (a0),a1
cmp.l #0,(a1)
beq.w .NextBlock
move.l a1,a0
bra.s .Loop ;Loop until next free block
.NextBlock:
move.l d0,(a0)
move.l a0,d1
move.l d0,a0
move.l #Allocated_Memory_Pos+4,(a0)
move.l d1,4(a0)
add.l #8,d0
.Error: movem.l (a7)+,a0-a6/d1-d7
rts
;----------------------------------------
AllocMem: ;Allocates memory
move.l $4,a6 ;IN: D0=memoryblock wanted
; D1=MemoryType wanted
;OUT: D0=Where the memory is
cmp.l #0,d0 ; 0=ERROR
beq.s .MemErr
jsr -684(a6)
.MemErr:
rts
FreeMem: ;Free Memory
move.l $4,a6 ;IN: D0 = WHERE
move.l d0,a1
jsr -690(a6)
rts
;----------------------------------------
FreeAllocated: ;Free all allocated blocks
;with AllocateMemory
;NO IN or OUT variables
;It just does it!
;(It's a kinda MAGIC tadaatada)
movem.l a0-a6/d0-d7,-(a7)
lea Allocated_Memory_Pos,a0
move.l (a0),a1
cmp.l #0,(a1)
beq.s .End ;No Blocks allocated atall!
move.l (a0),a0
.Loop: cmp.l #0,(a0)
beq.s .End ;Last Block done
move.l (a0),a2
move.l a0,d0
bsr FreeMem
move.l a2,a0
bra.s .Loop
.End: movem.l (a7)+,a0-a6/d0-d7
rts
;----------------------------------------
FreeBlock: ;Free a memoryblock from
;memorylist allocated with
;AllocateMemory
; IN: D0=Where
;OUT: D0: 0=Error (not found)
movem.l a0-a6/d1-d7,-(a7)
lea Allocated_Memory_Pos,a0
sub.l #8,d0
move.l (a0),a0
.Loop: cmp.l a0,d0
beq.s .ThatsIT ;We got the block
cmp.l #0,(a0)
beq.s .Error ;BlockNotFound
move.l (a0),a0
bra.s .Loop
.ThatsIT:
move.l (a0),a1 ;get adr to the NEXT block.
move.l 4(a0),a2 ;get the adr to the block before.
cmp.l #0,(a1)
beq.s .NextNull ;this is the LAST block
move.l a1,(a2)
move.l a2,4(a1)
.Free:
bsr FreeMem
.Ok: bset #1,d0
.NotOk:
movem.l (a7)+,a0-a6/d1-d7
rts
.NextNull:
move.l a1,(a2)
bra.s .Free
.Error: clr.l d0
bra.s .NotOk
Allocated_Memory_Pos:
dc.l *+4,0 ;Position of alloc mem list
Print: ; Prints string in A0
movem.l a1-a6/d1-d7,-(a7)
; OLutput: D0 = length
move.l DOSBase,a6
clr.l d7
move.l a0,d2
.loop:
add.l #1,d7
cmp.b #0,(a0)+
bne.s .loop
move.l d7,d3
jsr -60(a6)
move.l d0,d1
jsr -48(a6)
move.l d7,d0
movem.l (a7)+,a1-a6/d1-d7
rts
LoadFile: ;Loads a file into memory
move.l a0,d7
lea .Loadtext,a0
jsr Print
move.l d7,a0
jsr Print
lea .Loadnewline,a0
jsr Print
move.l d7,a0
bsr CheckLen ;Allocated memory with the
beq.s .Error ;AllocateMemory routine.
;IN: A0 = Pointer to Filename
move.l d0,.LoadLength ;Out: D0=Memoryposition
bsr AllocateMemory ; D1=FileLength
beq.s .Error2
move.l d0,.LoadInto
move.l $4,a6
lea Dos,a1 ;IN: File=Filename (incl. path)
jsr -408(a6) ; LoadInto=Where to load to
move.l d0,a6 ; LoadLength=Filelength
move.l FileName,d1
move.l #00001005,d2
jsr -30(a6)
beq .Error
move.l d0,.Peekare
move.l d0,d1
move.l .LoadInto,d2
move.l .LoadLength,d3
jsr -42(a6)
move.l .Peekare,d1
jsr -36(a6)
beq.s .Error
move.l .LoadLength,d1
move.l .LoadInto,d0
rts
.Error:
lea .Loaderror,a0
jsr Print
move.b #1,end
rts
.Error2:
lea .Loadmem,a0
jsr Print
move.b #1,end
rts
.Peekare:
dc.l 0
.LoadInto:
dc.l 0
.LoadLength:
dc.l 0
.Loadtext:
dc.b "Loading file: ",0
.Loadnewline:
dc.b $a,0
.Loaderror:
dc.b $a,"ERROR LOADING FILE - EXITING",$a,0
.Loadmem:
dc.b $a,"ERROR - OUT OF MEMORY - EXITING",$a,0
EVEN
SaveFile:
move.l a0,a5
lea .Savetext,a0
bsr Print
move.l a5,a0
bsr Print
lea .Savenewline,a0
bsr Print
move.l $4,a6
lea Dos,a1
jsr -408(a6)
move.l d0,a6
move.l a5,d1
move.l #1006,d2
jsr -30(a6)
beq .Error
move.l d0,.Peekare
move.l d0,d1
move.l workadr,d2
move.l FileSize,d3
jsr -48(a6)
move.l .Peekare,d1
jsr -36(a6)
clr.l d0
rts
.Error:
lea .Errortext,a0
bsr Print
move.l #-1,d0
move.b #1,end
rts
.Peekare:
dc.l 0
.Savetext:
dc.b "Saving file: ",0
.Savenewline:
dc.b $a,0
.Errortext:
dc.b $a,"ERROR SAVING FILE",$a,0
FileSize:
dc.l 0
;----------------------------------------
CheckLen: ;Checks length of file
move.l a0,FileName
move.l $4,a6 ;IN: A0=Pointer to filename
lea Dos,a1 ;OUT: D0=Length
jsr -408(a6) ; A0=File structure
move.l d0,a6
move.l FileName,d1 ;Filename
move.l #-2,d2
jsr -84(a6)
beq .Error
move.l d0,.Lock
move.l d0,d1
move.l #.FileInfo,d2
jsr -102(a6)
move.l .Lock,d1
jsr -90(a6)
lea .FileInfo,a0
cmp.w #$1111,-2(a0)
bne .yeah
addi.l #2,a0
.yeah:
move.l 122(a0),d0
rts
.Error:
move.l #0,d0
rts
.Lock: dc.l 0
dc.w $1111
;Dummy! DO NOT HAVE ANYTHING HERE
.FileInfo:
blk.l 300,0
Dos: dc.b "dos.library",0
FileName:
dc.l 0
DOSBase:
dc.l 0
inadr:
dc.l 0
workadr:
dc.l 0
end:
dc.l 0
Filename16:
dc.b "diagrom/16bit.bin",0
Filename32hi:
dc.b "diagrom/32bitHI.bin",0
Filename32lo:
dc.b "diagrom/32bitLO.bin",0
FilenameA1kEven:
dc.b "diagrom/A1kEVEN.bin",0
FilenameA1kOdd:
dc.b "diagrom/A1kODD.bin",0
InitTxt:
dc.b "Filesplitter V0.2 by John (Chucky) Hertell",$a,$a
dc.b "Simply reads the file indata.bin that should be a binary file for Kickstart ROM and splits it for burning",$a
dc.b "This software assumes 512MB Roms and will make 32 bit roms 2x512MB files with duplicate data",$a,$a
dc.b "Produces 3 files:",$a
dc.b " 16bit.bin - byteswapped image for burning 16 bit eproms",$a
dc.b " 32bitHI.bin - byteswapped image of high word for burning images for 32Bit",$a
dc.b " 32bitLO.bin - byteswapped image of low word for burning images for 32Bit",$a,$a
dc.b "AND if DiagROMA1k file exists it also creates:",$a,$a
dc.b " A1kEVEN.bin - Image for EVEN bytes",$a
dc.b " A1kODD.bin - Image for ODD bytes",$a,$a,0
infile:
dc.b "diagrom/DiagROM",0
infilea1k:
dc.b "diagrom/DiagROMA1k",0
outmem:
dc.b " -- ERROR: out of fastmem for work-buffer",$a,0