Target SC3000 and ROM's

Post Reply
helmha
Member
Posts: 10
Joined: Sun Sep 12, 2021 10:37 am

Target SC3000 and ROM's

Post by helmha »

Hello all

I'm having slight trouble getting ROM's working with Sega SC3000 as the target. I'm using a z88dk nightly. Compile command is zcc +sc3000 -subtype=rom -create-app -o game game.c. I found the cause to be in z88dk/lib/target/sc3000/classic/rom.asm:

Code: Select all

	...
	defc	ROM_Start  = $0000
	defc	RAM_Start  = $C000
	defc	RAM_Length = $0800
	defc	Stack_Top  = $c400
	...
I guess Stack_Top is okay as it is for the SG1000. But on the SC3000 Stack_Top is at the middle of RAM. When I execute a compiled ROM in an emulator (emulicious/mame) it goes into a restart loop. That happens because crt0_init_bss(code_crt_init_head) overwrites from RAM_Start past Stack_Top ($c400) messing up the stack with zeroes resulting that a RET goes always to $0000.

I can fix it by changing Stack_Top to $C800 in the rom.asm but I guess that's not the right way to go and it obviously won't work with SG1000 anymore.

So, is this a typo/bug or am I doing something wrong here?
User avatar
dom
Well known member
Posts: 2072
Joined: Sun Jul 15, 2007 10:01 pm

Re: Target SC3000 and ROM's

Post by dom »

As you've found the default setup is to create a binary that works on both the sc3000 and the sg1000.

For sc3000 projects you can set the stack pointer as part of the compilation (either by a command line option or a separate pragma file): -pragma-define:REGISTER_SP=nnnn

I'm quite happy to create another subtype for the sc3000 that does this default - just let me know what SP should be and I can do it.
helmha
Member
Posts: 10
Joined: Sun Sep 12, 2021 10:37 am

Re: Target SC3000 and ROM's

Post by helmha »

Oh nice! I tested by putting -pragma-define:REGISTER_SP=0xc7f0 into my Makefile and that did the trick :)

I've used 0xc7f0 for the stackpointer since I started using SDCC and it has worked just fine with ROM's and surely it works with z88dk too.

In my opinion there's no need for another subtype, that pragma-trick is enough. So thanks for your help.
User avatar
dom
Well known member
Posts: 2072
Joined: Sun Jul 15, 2007 10:01 pm

Re: Target SC3000 and ROM's

Post by dom »

That's great, I've updated the wiki to have that information.

I presume you've come across this option -compiler=sdcc which combines everything together?
helmha
Member
Posts: 10
Joined: Sun Sep 12, 2021 10:37 am

Re: Target SC3000 and ROM's

Post by helmha »

Thanks for updating the wiki.

Yes I know about -compiler=sdcc but haven't used it
Post Reply