Skip to content

Commit a33c234

Browse files
committed
[addmem] AddReplayMem 1.7 - Add dummy RAM node for Replay ROM
1 parent 19bc5a6 commit a33c234

File tree

2 files changed

+104
-3
lines changed

2 files changed

+104
-3
lines changed

addmem/AddReplayMem

300 Bytes
Binary file not shown.

addmem/addmem.asm

Lines changed: 104 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,9 @@ MEMF_REPLAY equ (1<<14)
3434
VERSION = 1
3535
REVISION= 6
3636

37-
dc.b 0,'$VER: AddReplayMem 1.6 (14.2.2020) Replay XRAM',0
37+
dc.b 0,'$VER: AddReplayMem 1.7 (19.2.2020) Replay XRAM',0
3838
even
39-
VERSTRING dc.b 'AddReplayMem 1.6 (14.2.2020) Replay XRAM',13,10,0
39+
VERSTRING dc.b 'AddReplayMem 1.7 (19.2.2020) Replay XRAM',13,10,0
4040
even
4141

4242
cnop 0,4
@@ -54,13 +54,16 @@ romtag: dc.w RTC_MATCHWORD
5454
tagname: dc.b 'AddReplayMem',0
5555
even
5656

57+
MIN_ROM_SIZE = (4*1024)
58+
MAX_ROM_SIZE = (1024*1024)
5759

5860
cnop 0,4
5961
S:
6062
kprintf "INIT: %s",#VERSTRING
6163

6264
movem.l d2-d6/a2-a6,-(sp)
6365

66+
; 1.7 - Add a dummy memory node for the $00F0.0000 replay.rom memory region (to prevent mmu.library cache-inhibit state)
6467
; 1.6 - Fix memory trashing when probing; Change to RTF_SINGLETASK (before Exec); Add logging
6568
; 1.5 - Make ROMable
6669
; 1.4 - Add console logging; Fix building with vasm.
@@ -69,8 +72,22 @@ S:
6972
; 1.1 - Detect 24 bit (000/010/EC020) memory space (by detecting mirroring of CHIP above the 16M barrier)
7073
; 1.0 - Probe memory to make sure it's actually present
7174

72-
; Check if already registered
75+
; Check if ROM is mapped as RAM
7376
movea.l $4.w,a6
77+
lea $00f01000,a1
78+
jsr _LVOTypeOfMem(a6)
79+
tst.l d0
80+
bne .already_mapped
81+
82+
bsr MapROMasRAM
83+
tst.l d0
84+
bmi .quit_checksum
85+
86+
kprintf <" rom is %ld bytes",10>,d0
87+
88+
.already_mapped
89+
90+
; Check if already registered
7491
lea $01001000,a1
7592
jsr _LVOTypeOfMem(a6)
7693
tst.l d0
@@ -197,6 +214,8 @@ S:
197214
lea memory_added(pc),a5
198215
bra.b .quit
199216

217+
.quit_checksum lea checksum_failed(pc),a5
218+
bra.b .quit
200219
.quit_present lea already_there(pc),a5
201220
bra.b .quit
202221
.quit_24bit lea cpu_is_24bit(pc),a5
@@ -229,12 +248,94 @@ S:
229248

230249
name dc.b 'replay xram memory',0
231250
name_end
251+
romname dc.b 'replay.rom memory',0
252+
romname_end
232253
dos dc.b 'dos.library',0
254+
checksum_failed dc.b 'rom checksum failed',10,0
233255
already_there dc.b 'memory is already available',10,0
234256
cpu_is_24bit dc.b 'cpu uses a 24bit address bus (68000/010/EC020)',10,0
235257
probing_failed dc.b 'memory probing failed',10,0
236258
alloc_failed dc.b 'memory allocation failed',10,0
237259
memory_added dc.b 'memory region added',10,0
238260

261+
cnop 0,4
262+
263+
MapROMasRAM:
264+
; Find replay ROM size
265+
lea $00f00000,a0
266+
move.l #MIN_ROM_SIZE,d0
267+
move.l #MAX_ROM_SIZE,d1
268+
269+
; a0.l = ROM start
270+
; d0.l = start ROM size (16 bytes min)
271+
; d1.l = end ROM size (1MB max)
272+
273+
move.l d0,d7
274+
moveq #0,d5
275+
moveq #0,d6
276+
.cont lsr.l #4,d7
277+
bra.b .start
278+
.loop: rept 4
279+
add.l (a0)+,d5
280+
addx.l d6,d5
281+
endr
282+
.start dbf d7,.loop
283+
284+
not.l d5
285+
beq.b .sumok
286+
not.l d5
287+
288+
move.l d0,d7
289+
add.l d0,d0
290+
cmp.l d1,d0
291+
bne.b .cont
292+
.error moveq.l #-1,d0
293+
rts
294+
.sumok move.l d0,d2
295+
296+
; Allocate a dummy memlist header + memlist name + 'free'list
297+
moveq.l #MH_SIZE+MC_SIZE+(romname_end-romname),d0
298+
moveq.l #0,d1
299+
jsr _LVOAllocMem(a6)
300+
tst.l d0
301+
beq .error
302+
303+
; Fill out the memlist header based on the ROM details
304+
move.l d0,a0
305+
clr.l LN_SUCC(a0)
306+
clr.l LN_PRED(a0)
307+
move.b #NT_MEMORY,LN_TYPE(a0)
308+
move.b #-128,LN_PRI(a0)
309+
move.w #0,MH_ATTRIBUTES(a0)
310+
311+
; This is the 'empty' freelist node
312+
lea MH_SIZE(a0),a1
313+
move.l a1,MH_FIRST(a0)
314+
clr.l (a1)+ ; MC_NEXT
315+
clr.l (a1)+ ; MC_BYTES
316+
317+
; Set the ROM memory name
318+
move.l a1,LN_NAME(a0)
319+
lea romname(pc),a2
320+
moveq.l #romname_end-romname,d1
321+
.name move.b (a2)+,(a1)+
322+
dbf d1,.name
323+
324+
; Set the memlist lower and upper bound (matching ROM)
325+
lea $00f00000,a1
326+
move.l a1,MH_LOWER(a0)
327+
move.l a1,MH_UPPER(a0)
328+
add.l d2,MH_UPPER(a0)
329+
clr.l MH_FREE(a0)
330+
331+
; Use the *private* execbase member 'MemList' to enqueue the ROM memlist
332+
move.l a0,a1
333+
lea.l MemList(a6),a0
334+
jsr _LVOForbid(a6)
335+
jsr _LVOEnqueue(a6)
336+
jsr _LVOPermit(a6)
337+
338+
move.l d2,d0 ; ROM size
339+
rts
239340
end
240341

0 commit comments

Comments
 (0)