Lots of noob questions

SGDK only sub forum

Moderator: Stef

tryphon
Very interested
Posts: 316
Joined: Sat Aug 17, 2013 9:38 pm
Location: France

Post by tryphon » Tue Mar 10, 2015 10:24 am

So there's need for developping a version for each processor?
I'd have understood this when processor were really slow, but now, is it worth the pain?

KillaMaaki
Very interested
Posts: 84
Joined: Sat Feb 28, 2015 9:22 pm

Post by KillaMaaki » Sat Mar 14, 2015 10:40 pm

Making lots of progress on this.

Here's a test I've been working on.

https://dl.dropboxusercontent.com/u/991 ... ld_KLD.zip

/KLDSource is the source code in my custom language (.kld files). It's got the main file (main.kld), a GenLib.kld file which wraps around genesis.h functions into handy modules (currently, only two functions wrapped - VDP_drawText and VDP_waitVSync), GameEngine.kld which is the basis of the core game stuff (managing spawned game entities and whatnot - not yet finished), and GameEntityBase.kld which has a base class for game entities.

/CSource has the main.c which it compiles down to (at the moment, I just compile everything into one monolithic C file). Kinda fugly, but it works (at the moment, all it really does is print "Game Engine Initialized" to the screen, but it does compile and run so that's good!)

Man, I'm really happy about the syntax of KLD. So much better than C :D

KillaMaaki
Very interested
Posts: 84
Joined: Sat Feb 28, 2015 9:22 pm

Post by KillaMaaki » Tue Mar 17, 2015 10:32 pm

So I've been messing around with Sega CD Mode 1 stuff in SGDK and my KLD.

I ended up adding in support for importing C files. Then, I ended up implementing memcmp (or, rather, copy-pasting from the official implementation).

Then I copied some code over from Chilly Willy's Mode 1 player example for detecting the Sega CD bios (porting to KLD):

Code: Select all

import( "Core/GameEngine.kld" );

function main() : int
{
	var bios : u8*;
	bios = cast<u8*>( 0x415800 );

	// check for presence of Sega CD bios (at either 0x415800, or 0x416000)
	if( memcmp( bios + 0x6D, "SEGA", 4 ) != 0 ) //memcmp returns zero if the bytes match
	{
		bios = cast<u8*>( 0x416000 );
		
		if( memcmp( bios + 0x6D, "SEGA", 4 ) != 0 )
		{
			// Sega CD bios was not found
			Graphics.DrawText( "Sega CD not detected!", 10, 10 );
			
			// now guess what we're going to do?
			// https://www.youtube.com/watch?v=kBoesEFWZnM
			while( true )
			{
				Graphics.WaitVSync();
			}
		}
	}

	// Sega CD bios was found ("bios" now points to start of Sega CD bios)
	Graphics.DrawText( "Sega CD detected! Hooray!", 10, 10 );

	GameEngine.Init();

	while( true )
	{
		GameEngine.Tick();
	}

	return 0;
}
Tested in Kega Fusion and works like an absolute charm. Upon first booting, it displays "Sega CD not detected". After booting Sega CD (via CTRL-B), it then resets and displays "Sega CD detected, hooray!" as expected.

Next up: doing actually useful things with the CD :D

KillaMaaki
Very interested
Posts: 84
Joined: Sat Feb 28, 2015 9:22 pm

Post by KillaMaaki » Wed Mar 18, 2015 12:52 am

Hm, now I'm encountering issues with porting some assembly files over from Chilly Willy's demo. Obviously it works there, because it compiled for him and the demo actually works.
However, when I try to use the .S files (pared down for my needs) in my own project, I get a ton of errors. For instance, this:

Code: Select all

| SEGA MegaDrive support code
| by Chilly Willy

| short set_sr(short new_sr);
| set SR, return previous SR
| entry: arg = SR value
| exit:  d0 = previous SR value
        .global set_sr
set_sr:
        moveq   #0,d0
        move.w  sr,d0
        move.l  4(sp),d1
        move.w  d1,sr
        rts

| void write_byte(void *dst, unsigned char val)
        .global write_byte
write_byte:
        movea.l 4(sp),a0
        move.l  8(sp),d0
        move.b  d0,(a0)
        rts

| void write_word(void *dst, unsigned short val)
        .global write_word
write_word:
        movea.l 4(sp),a0
        move.l  8(sp),d0
        move.w  d0,(a0)
        rts

| void write_long(void *dst, unsigned int val)
        .global write_long
write_long:
        movea.l 4(sp),a0
        move.l  8(sp),d0
        move.l  d0,(a0)
        rts

| unsigned char read_byte(void *src)
        .global read_byte
read_byte:
        movea.l 4(sp),a0
        move.b  (a0),d0
        rts

| unsigned short read_word(void *src)
        .global read_word
read_word:
        movea.l 4(sp),a0
        move.w  (a0),d0
        rts

| unsigned int read_long(void *src)
        .global read_long
read_long:
        movea.l 4(sp),a0
        move.l  (a0),d0
        rts
Spits out an "operand mismatch" on that first "moveq" statement, followed by syntax errors for basically every subsequent instruction in the file.

Am I missing something here? Is the assembly syntax different between what Chilly Willy uses and what SGDK uses?

Post Reply