Make a 48kb game using SDCC, great but how ?

Page 2/2
1 |

By Grauw

Ascended (10313)

Grauw's picture

06-12-2021, 01:05

aoineko wrote:
Grauw wrote:

I really like santiontanon’s approach.

It is not too difficult to place data anywhere in C, but it is much more complicated to do it with code.
That's why I recommend to use the page 0 only for data and to access it by the interslot BIOS reading function.

Ah here I don’t know enough about the limits of C. But code is also data; LDIR+RET is ED B0 C9. Isn’t it possible then to place that at the start of page 0?

The downside of reading byte-by-byte with RDSLT is that it’s pretty slow. Although it may suit the needs! In that case I totally agree it is the preferable simplest solution. But I think using CALSLT to call into a little copy routine is an elegant solution if more speed is needed.

By gdx

Enlighted (5017)

gdx's picture

06-12-2021, 08:34

Here is standard routines that can be useful to determine the slots for 32K RAM and a ROM that starts from the page 1. They should be executed at ROM boot.

RSLREG	equ	00138h	; Read primary Slot REGister
EXPTBL	equ	0FCC1h	; Extended slot flag for page 0

	org	04010h

; Search Main-RAM slot routine on page 3 (0C000h~0FFFFh)

def_RAMAD3:

	call	RSLREG
	and	0C0h
	rlca
	rlca			; A = Primary slot
	ld	c,a
	ld	b,0
	ld	hl,EXPTBL
	add	hl,bc
	ld	a,(hl)
	and	80h
	jr	z,No_SS3	; Jump if slot is not secondary (page 3)

	ld	hl,SLTTBL
	add	hl,bc
	ld	a,(hl)		; A = Value of current decondary slots register
	and	0C0h		; Keep the bits for page 3
	rrca
	rrca
	rrca
	rrca			; Bits 2-3 of A = Current secondary slot (page 3)
	or	080h		; Set the bit 7
No_SS3:
	or	c
	ld	(0C001h),a	; Stores the Main-RAM slot number of page 3

; Search Main-RAM slot routine on page 2 (08000h~0BFFFh) (useless on 8/16K RAM MSXs)

def_RAMAD2:

	call	RSLREG
	and	030h
	rrca
	rrca
	rrca
	rrca			; A = primary slot
	ld	c,a
	ld	b,0
	ld	hl,EXPTBL
	add	hl,bc
	ld	a,(hl)
	and	80h
	jr	z,No_SS2	; Jump if slot is not secondary (page 2)

	ld	hl,SLTTBL
	add	hl,bc
	ld	a,(hl)		; A = value of current decondary slots register
	and	30h		; Keep the bits for page 2
	rrca
	rrca			; Bits 2-3 of A = current secondary slot (page 2)
	or	080h		; Set the bit 7
No_SS2:
	or	c
	ld	(0C002h),a	; Stores the Main-RAM slot number of page 2 

; Search current ROM slot routine

	call	RSLREG
	rrca
	rrca
	and	3
	ld	c,a
	ld	b,0
	ld	hl,EXPTBL
	add	hl,bc
	ld	a,(hl)
	and	80h
	or	c
	ld	c,a
	inc	l
	inc	l
	inc	l
	inc	l
	ld	a,(hl)
	and	0Ch
	or	c		; a = Slot ROM
	ld	(0C000h),a	; Stores the ROM slot number

; Beginning of your program ...

Slot numbers are stored at addresses C000h~C002h but you can of course put them elsewhere.

By aoineko

Champion (260)

aoineko's picture

06-12-2021, 21:16

Grauw wrote:

It is not too difficult to place data anywhere in C, but it is much more complicated to do it with code.
That's why I recommend to use the page 0 only for data and to access it by the interslot BIOS reading function.

You are right. Using C we can put data (so also code) at any place using a directive (__at).
However, I don't know of a way to automatically place a function at a given address.
I know that JMeric is not very comfortable with assembler; that's why I proposed a "simpler" solution.

By Grauw

Ascended (10313)

Grauw's picture

06-12-2021, 21:31

That totally makes sense.

By geijoenr

Champion (281)

geijoenr's picture

07-12-2021, 00:48

Running a 48K ROM in C is indeed a bit of a pain, and I have found the most practical approach is to use the lower 16Kb to just store game data.

The data can be consumed by switching slot inside a critical section with interrupts disabled. Copying to RAM is impractical but VDP transfers and direct decompression is possible as long as you ensure interrupts remain disabled during the whole process.

You can find an example on how I do this over here:
https://github.com/retrodeluxe/rlengine-msx/tree/master/test...

Why would it be useful to release a 48K ROM?
The only reason I can think of is because you do not need external hardware to run it in most MSX.

Now, being realistic, C code is much less size efficient than ASM and it is really difficult to fit a game into 48K unless is pretty simple. So I would recommend using a mapped ROM.

By JMeric

Resident (51)

JMeric's picture

07-12-2021, 21:53

@geijoenr
You're right, programming in C make the code longer compared to ASM (I've used ASM when I used to code on amiga/falcon). But in C, development time is shorter in C than in ASM.
So I think C+ASM could be a great 'balance'
The only reason I want to add more Kb is for music(s)+replayer. There is a lack of music in my games Smile

Aoineko & Graw, I'm going to study this

aoineko wrote:
Grauw wrote:

It is not too difficult to place data anywhere in C, but it is much more complicated to do it with code.
That's why I recommend to use the page 0 only for data and to access it by the interslot BIOS reading function.

You are right. Using C we can put data (so also code) at any place using a directive (__at).
However, I don't know of a way to automatically place a function at a given address.
I know that JMeric is not very comfortable with assembler; that's why I proposed a "simpler" solution.

Thanks a lot guys
I will study all your advices Smile

By ducasp

Champion (477)

ducasp's picture

08-12-2021, 22:32

Have you tried Danilo Angelo Visual Studio templates?

https://github.com/DamnedAngel/MSX-Templates-for-VisualStudi...

It supports ROM's...

By default, using Konamiman / Fusion-C CRT's, you will get MSX-DOS binaries sitting at 0x0100 on...

Page 2/2
1 |