Page 1 of 1

Spectravideo 328: Converting a .cas to cart

Posted: Mon Nov 22, 2021 4:40 pm
by XiA
Hi, especially to fpganoob - thank you so much for this core! The SVI-328 was my first computer, and being able to use it in MiSTer makes me so happy!

However, load times from tape are a little annoying, so I thought I would convert some of those classic Mass Tael games (Ninja, SASA, etc) to cartridges. Ninja loads at $8800 to $c7ff, so I made a dump of the entire RAM in BlueMSX and cut off the first 32k, then I added a CALL $8800 at offset 0 - but no, that didn't work.

How does loading a cartridge work in the SVI core? Looking at other carts, I can't see any obvious load addresses, or even get any obvious clues to where they're placed in RAM space.

Any help would be greatly appreciated!

XiA

Re: Spectravideo 328: Converting a .cas to cart

Posted: Wed Nov 24, 2021 2:21 am
by lister_of_smeg
Carts get mapped at the bottom of the address space ($0000-$7ffff for a 32k cart). They need to start with the opcodes for DI and LD SP,xxxx (F3 31) in order to run.

So you need to copy the data from the cart to RAM. But that's not all - the game makes calls to the BASIC ROM, so that needs to be mapped back in before running the game code. But you can't do that while the PC is still below $8000 or you'll just end up executing random code from the BASIC ROM. So you need to add some code in RAM that performs the final OUT required to map in BASIC and jumps to the game code. As luck would have it the game code starts by immediately zeroing nine bytes starting at $fe74, so we can safely place this code there.

This code should build you a ROM from the cassette data:-

Code: Select all

		org	$0000

latch:		equ	$88
write:		equ	$8c
read:		equ	$90

psgreg:		equ	$07
portb:		equ	$0f

entry:		equ	$fe74
dest:		equ	$8800
stack:		equ	$f21c

		; rom init
		di
		ld	sp, stack

		; push game entry point to stack
		ld	de, dest
		push	de

		; copy data to ram
		ld	bc, pad-data
		ld	hl, data
		ldir

		; set up code in ram to map in basic rom
		ld	hl, $8cd3	; out (write), a
		ld	(entry), hl
		ld	a, $c9 		; ret
		ld	(entry+2), a

		; select basic rom in lower address space
		ld	a, psgreg
		out	(latch), a
		ld	a, $bf
		out	(write), a

		ld	a, portb
		out	(latch), a
		in	a, (read)
		xor	%00000001

		; jump to ram	
		jp	entry

		; game data from cassette
data:		incbin	"ninja.dat"

		; pad with ones up to 32k
pad:		defs	$8000-$, $ff
Note that 'ninja.dat' should be just the game data from $8800 to $c7ff, NOT the whole 32k of RAM from $8000-$ffff

Re: Spectravideo 328: Converting a .cas to cart

Posted: Wed Nov 24, 2021 3:04 pm
by XiA
Holy crap, that was a more complete answer than I could possibly have asked for!

Thank you so much for this, it is MUCH appreciated!


Cheers,

XiA

Re: Spectravideo 328: Converting a .cas to cart

Posted: Wed Nov 24, 2021 3:07 pm
by XiA
Oh, just a quick follow-up question: What assembler is this for? The

Code: Select all

defs	$8000-$, $ff
bit makes perfect sense, but doesn't match the syntax of my assembler. Thanks again!


XiA

Re: Spectravideo 328: Converting a .cas to cart

Posted: Wed Nov 24, 2021 3:18 pm
by lister_of_smeg
XiA wrote: Wed Nov 24, 2021 3:07 pm Oh, just a quick follow-up question: What assembler is this for? The

Code: Select all

defs	$8000-$, $ff
bit makes perfect sense, but doesn't match the syntax of my assembler. Thanks again!


XiA
I know it works in zasm and z80asm but I've tried to make the syntax and directives as generic as possible so it should work in most Z80 assemblers.

Re: Spectravideo 328: Converting a .cas to cart

Posted: Wed Nov 24, 2021 4:36 pm
by XiA
Just a quick thank you, and to let you know it all worked perfectly here! You are truly a gentleman and a scholar.

Now then, how to convince Games Done Quick to accept SASA speedruns...


XiA

Re: Spectravideo 328: Converting a .cas to cart

Posted: Wed Nov 24, 2021 7:05 pm
by LamerDeluxe
I didn't even expect that this would be possible, really cool.