Skip to content

Commit 463f036

Browse files
authored
Merge pull request #4 from erique/add-usb
Add auto-booting Poseidon USB stack, as ROM
2 parents 38e2189 + df33cd4 commit 463f036

20 files changed

+647
-28
lines changed

addmem/AddReplayMem

300 Bytes
Binary file not shown.

addmem/Makefile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,14 @@ VASM_FLAGS := -quiet -Fhunkexe -kick1hunks -nosym -m68000
22

33
TARGET := AddReplayMem
44
SOURCE := addmem.asm
5+
INCLUDES := kprintf.i
56
LISTFILE := $(addsuffix .txt,$(basename $(TARGET)))
67

78
all: $(TARGET)
89
@echo ""
910

1011
$(TARGET): Makefile | buildenv
12+
$(TARGET): $(INCLUDES)
1113
$(TARGET): $(SOURCE)
1214
$(VASM) $< -o $@ -L $(LISTFILE) $(VASM_FLAGS) -I $(INC_ASM)
1315

addmem/addmem.asm

Lines changed: 157 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -15,58 +15,78 @@
1515

1616
; vasmm68k_mot -Fhunkexe -kick1hunks addmem.asm -L addmem.list -nosym -m68000 -o AddReplayMem -I ~/Documents/amiga-root/SYS/Code/NDK_3.9/Include/include_i
1717

18+
;ENABLE_KPRINTF
19+
20+
include exec/memory.i
1821
include exec/nodes.i
1922
include exec/resident.i
23+
include exec/exec.i
24+
include lvo/exec_lib.i
25+
include kprintf.i
2026

21-
_LVOAllocMem equ -198
22-
_LVOFreeMem equ -210
23-
_LVOTypeOfMem equ -534
24-
_LVOAddMemList equ -618
25-
_LVOOpenLibrary equ -552
26-
_LVOCloseLibrary equ -414
2727
_LVOPutStr equ -948
28-
MEMF_PUBLIC equ (1<<0)
29-
MEMF_CHIP equ (1<<1)
30-
MEMF_FAST equ (1<<2)
3128
MEMF_REPLAY equ (1<<14)
3229

3330
jmp S
3431
moveq.l #-1,d0
3532
rts
3633

3734
VERSION = 1
38-
REVISION= 5
3935

40-
dc.b 0,'$VER: AddReplayMem 1.5 (20.9.2018) Replay XRAM',0
41-
VERSTRING dc.b 'AddReplayMem 1.5 (20.9.2018) Replay XRAM',13,10,0
36+
dc.b 0,'$VER: AddReplayMem 1.7 (19.2.2020) Replay XRAM',0
4237
even
43-
38+
VERSTRING dc.b 'AddReplayMem 1.7 (19.2.2020) Replay XRAM',13,10,0
39+
even
40+
41+
cnop 0,4
4442
romtag: dc.w RTC_MATCHWORD
4543
dc.l romtag
4644
dc.l end
47-
dc.b RTF_COLDSTART
45+
dc.b RTF_SINGLETASK
4846
dc.b VERSION
4947
dc.b NT_UNKNOWN
50-
dc.b 0
48+
dc.b 108
5149
dc.l tagname
5250
dc.l VERSTRING
5351
dc.l S
5452

5553
tagname: dc.b 'AddReplayMem',0
5654
even
57-
55+
56+
MIN_ROM_SIZE = (4*1024)
57+
MAX_ROM_SIZE = (1024*1024)
58+
59+
cnop 0,4
5860
S:
61+
kprintf "INIT: %s",#VERSTRING
62+
5963
movem.l d2-d6/a2-a6,-(sp)
6064

65+
; 1.7 - Add a dummy memory node for the $00F0.0000 replay.rom memory region (to prevent mmu.library cache-inhibit state)
66+
; 1.6 - Fix memory trashing when probing; Change to RTF_SINGLETASK (before Exec); Add logging
6167
; 1.5 - Make ROMable
6268
; 1.4 - Add console logging; Fix building with vasm.
6369
; 1.3 - Label the memory region as REPLAY memory (unused bit 14)
6470
; 1.2 - Probe the memory region to see if it's already been added (using exec.library/TypeOfMem())
6571
; 1.1 - Detect 24 bit (000/010/EC020) memory space (by detecting mirroring of CHIP above the 16M barrier)
6672
; 1.0 - Probe memory to make sure it's actually present
6773

68-
; Check if already registered
74+
; Check if ROM is mapped as RAM
6975
movea.l $4.w,a6
76+
lea $00f01000,a1
77+
jsr _LVOTypeOfMem(a6)
78+
tst.l d0
79+
bne .already_mapped
80+
81+
bsr MapROMasRAM
82+
tst.l d0
83+
bmi .quit_checksum
84+
85+
kprintf <" rom is %ld bytes",10>,d0
86+
87+
.already_mapped
88+
89+
; Check if already registered
7090
lea $01001000,a1
7191
jsr _LVOTypeOfMem(a6)
7292
tst.l d0
@@ -124,26 +144,52 @@ S:
124144

125145
neg.b d4
126146
cmp.b #32,d4
127-
bne.b .quit_24bit
147+
bne .quit_24bit
128148

129149
; Probe the memory to see if it's there
150+
jsr _LVODisable(a6)
151+
130152
lea $01000000,a0
131153
moveq.l #$30-1,d7
132-
.probe movem.l d0-d3,(a0)
154+
.probe
155+
; save memory contents
156+
movem.l (a0),d4/d5/a4/a5
157+
movem.l d4/d5/a4/a5,-(sp)
158+
movem.l $4000(a0),d4/d5/a4/a5
159+
movem.l d4/d5/a4/a5,-(sp)
160+
161+
; write known values
162+
movem.l d0-d3,(a0)
163+
164+
; write noise at 16KB ahead
133165
lea $4000(a0),a1
134166
movem.l $4.w,a2-a5
135167
movem.l a2-a5,(a1)
168+
169+
; make sure the original write is valid
136170
move.l a0,a1
137171
cmp.l (a1)+,d0
138-
bne.b .quit_probing
172+
bne.b .probe_failed
139173
cmp.l (a1)+,d1
140-
bne.b .quit_probing
174+
bne.b .probe_failed
141175
cmp.l (a1)+,d2
142-
bne.b .quit_probing
176+
bne.b .probe_failed
143177
cmp.l (a1)+,d3
144-
bne.b .quit_probing
178+
179+
.probe_failed
180+
; restore memory contents
181+
movem.l (sp)+,d4/d5/a4/a5
182+
movem.l d4/d5/a4/a5,$4000(a0)
183+
movem.l (sp)+,d4/d5/a4/a5
184+
movem.l d4/d5/a4/a5,(a0)
185+
145186
add.l #$00100000,a0
146-
dbf d7,.probe
187+
dbne d7,.probe
188+
189+
jsr _LVOEnable(a6)
190+
191+
tst.b d7
192+
bpl.b .quit_probing
147193

148194
moveq.l #name_end-name,d0
149195
moveq.l #0,d1
@@ -167,6 +213,8 @@ S:
167213
lea memory_added(pc),a5
168214
bra.b .quit
169215

216+
.quit_checksum lea checksum_failed(pc),a5
217+
bra.b .quit
170218
.quit_present lea already_there(pc),a5
171219
bra.b .quit
172220
.quit_24bit lea cpu_is_24bit(pc),a5
@@ -175,7 +223,9 @@ S:
175223
bra.b .quit
176224
.quit_alloc lea alloc_failed(pc),a5
177225

178-
.quit lea dos(pc),a1
226+
.quit
227+
kprintf " %s",a5
228+
lea dos(pc),a1
179229
moveq.l #36,d0 ; putstr is kick 2.x+
180230
movea.l $4.w,a6
181231
jsr _LVOOpenLibrary(a6)
@@ -197,12 +247,94 @@ S:
197247

198248
name dc.b 'replay xram memory',0
199249
name_end
250+
romname dc.b 'replay.rom memory',0
251+
romname_end
200252
dos dc.b 'dos.library',0
253+
checksum_failed dc.b 'rom checksum failed',10,0
201254
already_there dc.b 'memory is already available',10,0
202255
cpu_is_24bit dc.b 'cpu uses a 24bit address bus (68000/010/EC020)',10,0
203256
probing_failed dc.b 'memory probing failed',10,0
204257
alloc_failed dc.b 'memory allocation failed',10,0
205258
memory_added dc.b 'memory region added',10,0
206259

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

addmem/kprintf.i

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
;
2+
; WWW.FPGAArcade.COM
3+
;
4+
; REPLAY Retro Gaming Platform
5+
; No Emulation No Compromise
6+
;
7+
; AddReplayMem - Memory configuration tool for the REPLAY Amiga core
8+
; Copyright (C) FPGAArcade community
9+
;
10+
; Contributors : Mike Johnson, Jim Drew, Erik Hemming
11+
;
12+
; This software is licensed under LPGLv2.1 ; see LICENSE file
13+
;
14+
;
15+
16+
kprintf MACRO
17+
IFD ENABLE_KPRINTF
18+
19+
ifnc "","\9"
20+
move.l \9,-(sp)
21+
endc
22+
ifnc "","\8"
23+
move.l \8,-(sp)
24+
endc
25+
ifnc "","\7"
26+
move.l \7,-(sp)
27+
endc
28+
ifnc "","\6"
29+
move.l \6,-(sp)
30+
endc
31+
ifnc "","\5"
32+
move.l \5,-(sp)
33+
endc
34+
ifnc "","\4"
35+
move.l \4,-(sp)
36+
endc
37+
ifnc "","\3"
38+
move.l \3,-(sp)
39+
endc
40+
ifnc "","\2"
41+
move.l \2,-(sp)
42+
endc
43+
44+
jsr _kprintf
45+
46+
dc.b \1,0
47+
even
48+
49+
adda.w #(NARG-1)*4,sp
50+
51+
.skip\@
52+
ENDC
53+
ENDM
54+
55+
IFD ENABLE_KPRINTF
56+
bra.b _kprintf_end
57+
_kprintf: movem.l d0-d1/a0-a3/a6,-(sp)
58+
move.l $4.w,a6
59+
move.l 28(sp),a0
60+
lea 32(sp),a1
61+
lea .putch(pc),a2
62+
move.l a6,a3
63+
jsr -522(a6) ; _LVORawDoFmt
64+
65+
move.l 28(sp),a0
66+
.end: move.b (a0)+,d0
67+
bne.b .end
68+
move.l a0,d0
69+
addq.l #1,d0
70+
and.l #$fffffffe,d0
71+
move.l d0,28(sp)
72+
movem.l (sp)+,d0-d1/a0-a3/a6
73+
rts
74+
75+
.putch: movem.l d0-d1/a0-a1/a6,-(sp)
76+
move.l $4.w,a6
77+
jsr -516(a6) ; _LVORawPutChar (execPrivate9)
78+
movem.l (sp)+,d0-d1/a0-a1/a6
79+
rts
80+
_kprintf_end:
81+
ENDC
82+

build_rom.sh

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
11
#!/bin/bash
2-
romtool -v build -o replay.rom -t ext -s 64 -e f00000 -a f00010 -r 01.04 bootrom/bootrom.bin addmem/AddReplayMem rtc/battclock.resource usb/usb_eth.autoconfig usb/replayusb.device
2+
set -e
3+
4+
romtool -v build -o replay.rom -t ext -s 64 -e f00000 -a f00010 -r 01.05 -f bootrom/bootrom.bin addmem/AddReplayMem poseidon/PoseidonLoader rtc/battclock.resource usb/usb_eth.autoconfig usb/replayusb.device
35
printf "000001: 11" | xxd -r - replay.rom
4-
#romtool info replay.rom
6+
romtool copy -c replay.rom replay.rom
7+
romtool info replay.rom
58
romtool scan replay.rom
69
#romtool dump replay.rom | less
10+
11+
romtool -v build -o poseidon.rom -t ext -s 512 -e 3f80000 -a 3f80000 -r 01.00 -f poseidon/hid.class poseidon/hub.class poseidon/input.device poseidon/massstorage.class poseidon/poseidon.library poseidon/PsdStackloader
12+
romtool scan poseidon.rom
13+
romtool info poseidon.rom

poseidon.rom

512 KB
Binary file not shown.

0 commit comments

Comments
 (0)