DDR like demo

Announce (tech) demos or games releases

Moderator: Mask of Destiny

oofwill
Very interested
Posts: 173
Joined: Mon May 03, 2010 6:12 pm
Location: France - Niort

DDR like demo

Post by oofwill » Wed Aug 15, 2012 2:42 pm

J've just coded a DDR-like with SGDK and i wanted to have your impressions and comments about it.

Image

For the moment there is only one level playable.
The thème is emerald hill from Sonic 2. (but my cam recorder don't recognized my sound card :|)

I know this BGM is under copyright but this is for the moment only a demo and i'm too bad at music to make my own ^^

If i continue the game i maybe will need help from music mens (or womans :P)

I almost forgot the most important : no rom for the moment but just a video : http://youtu.be/fnkgEfY-Yyg

now i have a question : is there any way to save score (in order to use it with a original pcb then) with SGDK?

bgvanbur
Interested
Posts: 46
Joined: Fri Jun 22, 2012 11:13 pm

Post by bgvanbur » Wed Aug 15, 2012 4:57 pm

Looks like a good start so far! On a real system with a standard controller you cannot press left and right at the same time so some of the moves can't be done. Do you plan on using a real dance pad or just a standard controller?

oofwill
Very interested
Posts: 173
Joined: Mon May 03, 2010 6:12 pm
Location: France - Niort

Post by oofwill » Wed Aug 15, 2012 7:08 pm

In fact, Joypad is mapped as this :

Left : Left
Down : B
Up : Up
Right : C

So it's playable with a standard controller :D
With a keyboard this take a little time to be good but it's really playable.

I will maybe add an option menu where we could choose between several joypad config...

I would like to use a dance pad but it doesn't exist for Genesis so i had to hack a standard paddle to integrate it in a dansce pad. No problem, easier than coding this game :lol:

sega16
Very interested
Posts: 251
Joined: Sat Jan 29, 2011 3:16 pm
Location: U.S.A.

Re: DDR like demo

Post by sega16 » Wed Aug 15, 2012 9:38 pm

oofwill wrote: now i have a question : is there any way to save score (in order to use it with a original pcb then) with SGDK?
Yes you could make a pcb with sram and cr2032 battery but if you just want to save the score it would make the pcb cost less to come up with a password system. An idea I had was to xor encrypt the score and have a simple hash as part of the password that is xor encrypted with another value. This will prevent players from trying to get a higher score by entering a false password.

Chilly Willy
Very interested
Posts: 2984
Joined: Fri Aug 17, 2007 9:33 pm

Re: DDR like demo

Post by Chilly Willy » Wed Aug 15, 2012 10:52 pm

sega16 wrote:
oofwill wrote: now i have a question : is there any way to save score (in order to use it with a original pcb then) with SGDK?
Yes you could make a pcb with sram and cr2032 battery but if you just want to save the score it would make the pcb cost less to come up with a password system. An idea I had was to xor encrypt the score and have a simple hash as part of the password that is xor encrypted with another value. This will prevent players from trying to get a higher score by entering a false password.
I think he means how do you read/write sram using SGDK. There's no built in support - you have to edit the header in rom_head.c, then use pointers to access the sram.

The rom header is normally this (from rom_head.c)

Code: Select all

    char console[16];               /* Console Name (16) */
    char copyright[16];             /* Copyright Information (16) */
    char title_local[48];           /* Domestic Name (48) */
    char title_int[48];             /* Overseas Name (48) */
    char serial[16];                /* Serial Number (2, 14) */
    u16 checksum;                   /* Checksum (2) */
    char IOSupport[16];             /* I/O Support (16) */
    u32 rom_start;                  /* ROM Start Address (4) */
    u32 rom_end;                    /* ROM End Address (4) */
    u32 ram_start;                  /* Start of Backup RAM (4) */
    u32 ram_end;                    /* End of Backup RAM (4) */
    char modem_support[24];         /* Modem Support (24) */
    char notes[40];                 /* Memo (40) */
    char region[16];                /* Country Support (16) */
When using sram, it should be

Code: Select all

    char console[16];               /* Console Name (16) */
    char copyright[16];             /* Copyright Information (16) */
    char title_local[48];           /* Domestic Name (48) */
    char title_int[48];             /* Overseas Name (48) */
    char serial[16];                /* Serial Number (2, 14) */
    u16 checksum;                   /* Checksum (2) */
    char IOSupport[16];             /* I/O Support (16) */
    u32 rom_start;                  /* ROM Start Address (4) */
    u32 rom_end;                    /* ROM End Address (4) */
    u32 ram_start;                  /* Start of Backup RAM (4) */
    u32 ram_end;                    /* End of Backup RAM (4) */
    char sram_sig[2];               /* "RA" for save ram (2) */
    u16 sram_type;                  /* 0xF820 for save ram on odd bytes (2) */
    u32 sram_start;                 /* SRAM start address - normally 0x200001 (4) */
    u32 sram_end;                   /* SRAM end address - start + 2*sram_size (4) */
    char modem_support[12];         /* Modem Support (12) */
    char notes[40];                 /* Memo (40) */
    char region[16];                /* Country Support (16) */
Then as long as your rom is less than or equal to 2MBytes, you simply turn on the sram and then read/write it directly.

turn on sram

Code: Select all

    *(vu8*)0xA130F1 = 1; /* enable sram */
If your rom is bigger than 2MBytes, you need to turn off the sram unless you are using it. When you do use it, you need to disable ints, turn on the sram, read/write it, turn off the sram, then enable ints.

turn off sram

Code: Select all

    *(vu8*)0xA130F1 = 0; /* disable sram  */
Note - you can turn on the sram but have it write-protected (read only) by doing

Code: Select all

    *(vu8*)0xA130F1 = 3; /* enable sram, write-protected */
Setting it to 2 disables the sram and write-protects it. Most folks don't worry about the write-protect status and just use 0/1. (Note - also, some PCBs don't support write-protection)

To read/write the sram, read/write bytes at odd positions.

read

Code: Select all

u8 read_sram(int offset)
{
    return *(vu8*)(0x200001 + offset*2);
}
write

Code: Select all

void write_sram(int offset, u8 val)
{
    *(vu8*)(0x200001 + offset*2) = val;
}

oofwill
Very interested
Posts: 173
Joined: Mon May 03, 2010 6:12 pm
Location: France - Niort

Post by oofwill » Thu Aug 16, 2012 11:51 am

Wow! many thanks for those usefull infos!

Indeed, i've already realized cartmods on pcb with Sram.
My question, as you noticed Chilly Willy, is how to use this Sram with SGDK.

- for rom header, this will be easy, ok.
- my rom will surely be heavier than 2MB, so i would have to turn on and off sram when i want to use it : ok

To read & write i'm not sure now.

Example : i want to store the score for sonic level : wich offset range can i use?
how many bytes will take an integer?

I will do test this evening, thanks again for your help ;)

Stef
Very interested
Posts: 3131
Joined: Thu Nov 30, 2006 9:46 pm
Location: France - Sevres
Contact:

Post by Stef » Thu Aug 16, 2012 6:49 pm

Thanks also Chilly, i will use what you posted to include prelemenary support to SRAM in SGDK :)

oofwill
Very interested
Posts: 173
Joined: Mon May 03, 2010 6:12 pm
Location: France - Niort

Post by oofwill » Thu Aug 16, 2012 7:34 pm

I'm doing test now.

What means "0xF820 for save ram on odd bytes"?
What is "odd bytes"?

So. I'm testing the save but my code is surely bad.

Code: Select all

write_sram(0, score);
    i = read_sram(0);

    intToStr(i, varichar, 5);
    VDP_drawText(varichar, 2, 25);
score is int and equal to 400
VDP_drawText give me 00012 on screen.

Maybe a problem with my adress? (i don't really know what offset is :oops: )
or with my variables? (int shouldn't work?)

my rom_head.c:

Code: Select all

const struct
{
    char console[16];               /* Console Name (16) */
    char copyright[16];             /* Copyright Information (16) */
    char title_local[48];           /* Domestic Name (48) */
    char title_int[48];             /* Overseas Name (48) */
    char serial[16];                /* Serial Number (2, 14) */
    u16 checksum;                   /* Checksum (2) */
    char IOSupport[16];             /* I/O Support (16) */
    u32 rom_start;                  /* ROM Start Address (4) */
    u32 rom_end;                    /* ROM End Address (4) */
    u32 ram_start;                  /* Start of Backup RAM (4) */
    u32 ram_end;                    /* End of Backup RAM (4) */
    char sram_sig[2];               /* "RA" for save ram (2) */
    u16 sram_type;                  /* 0xF820 for save ram on odd bytes (2) */
    u32 sram_start;                 /* SRAM start address - normally 0x200001 (4) */
    u32 sram_end;                   /* SRAM end address - start + 2*sram_size (4) */
    char modem_support[24];         /* Modem Support (24) */
    char notes[40];                 /* Memo (40) */
    char region[16];                /* Country Support (16) */
} rom_header = {
    "SEGA MEGA DRIVE ",
    "(C)FLEMTEAM 2011",
    "SAMPLE PROGRAM                                  ",
    "SAMPLE PROGRAM                                  ",
    "GM 00000000-00",
    0x0000,
    "JD              ",
    0x00000000,
    0x00020000,
    0x00FF0000,
    0x00FFFFFF,
    "RA",
    0xF820,
    0x00200001,
    0x00200100,
    "                        ",
    "DEMONSTRATION PROGRAM                   ",
    "JUE             "
};
EDIT : ok, it's certainly variable type.

I don't really know difference between int & u8...
Last edited by oofwill on Thu Aug 16, 2012 8:06 pm, edited 2 times in total.

Chilly Willy
Very interested
Posts: 2984
Joined: Fri Aug 17, 2007 9:33 pm

Post by Chilly Willy » Thu Aug 16, 2012 8:01 pm

oofwill wrote:I'm doing test now.

What means "0xF820 for save ram on odd bytes"?
What is "odd bytes"?
Bytes on ONLY odd addresses... notice the read function (for example)

Code: Select all

u8 read_sram(int offset)
{
    return *(vu8*)(0x200001 + offset*2);
}
See how the address is 0x200001 + offset*2? That will ALWAYS be odd. 0x200001, 0x200003, 0x200005, etc. Trying to read/write even addresses like 0x200000, 0x200002, 0x200004, etc will result in nothing as there is no sram on even addresses. Note - in assembly, the movep opcode is handy for reading/writing words and longs from/to sram. In C, you have to break the read/writes into individual byte operations which are the functions I posted.

reading a word in assembly

Code: Select all

    movep.w 0(a0),d0
where a0 is 0x200001, 0x200003, whatever.

reading a word in C

Code: Select all

    u16 val;
    val = read_sram(ptr)<<8 | read_sram(ptr+2);
where ptr is 0x200001, 0x200003, whatever. Note how the second byte is at ptr+2, not ptr+1. ODD ADDRESSES ONLY!

The offset is whatever the programmer decides. Make a list of variables you need to save and how big they are. That will tell you how much sram each save slot will need. If you allow (for example) four different saves, you would need four slots, or at least four time the space needed to save the variables, plus a description of the save (if you use one).

Chilly Willy
Very interested
Posts: 2984
Joined: Fri Aug 17, 2007 9:33 pm

Post by Chilly Willy » Thu Aug 16, 2012 8:03 pm

Stef wrote:Thanks also Chilly, i will use what you posted to include prelemenary support to SRAM in SGDK :)
You might want to make word and long versions of read/write_sram so that you can use movep to make it easier on the user to read/write words and longs.

oofwill
Very interested
Posts: 173
Joined: Mon May 03, 2010 6:12 pm
Location: France - Niort

Post by oofwill » Thu Aug 16, 2012 8:10 pm

... thanks for your help! :)

My problemS are :

- i'm noob in coding
- i'm bad in english

:lol:

So i don't even know what is even or odd bytes :lol:

i will read a little C/C++ tutorials :lol:

edit : odd = impair? :idea:

oofwill
Very interested
Posts: 173
Joined: Mon May 03, 2010 6:12 pm
Location: France - Niort

Post by oofwill » Thu Aug 16, 2012 9:58 pm

Ok.

After several hours of reading, it finally works!

First, i've learned interesting things about variables types :lol:
Then, i saw that i forgot to enable sram, that's why it didn't work!

I'm sorry for disturbing you with stupid questions, i know that it could be really annoying, so forgive me if sometimes my questions seems to be senseless, it's just i'm starting from 0...

oofwill
Very interested
Posts: 173
Joined: Mon May 03, 2010 6:12 pm
Location: France - Niort

Post by oofwill » Sat Aug 25, 2012 1:46 pm

I've another problem with save:

I use those command lines

Code: Select all

    *(vu8*)0xA130F1 = 1; /* enable sram */
    if (*(vu8*)(0x200001) != 250)
    {
        j=15;
        VDP_drawText("First time running Dance Impact", 3, 3);
        VDP_drawText("Reset memory", 3, 7);
        for(i=0; i<5000; i++)
        {
            VDP_drawText(".", j, 7);
            if (i==4990 && j<20) {j++; i=0;}
        }
        *(vu8*)(0x200001) = 250;              //indique qu'une sauvegarde existe
        *(vu16*)(0x200003) = 500;             //best score stage 1 réglé à 500
        *(vu16*)(0x200007) = 500;             //best score stage 2 réglé à 500
        *(vu16*)(0x200011) = 500;             //best score stage 3 réglé à 500


    }
    *(vu8*)0xA130F1 = 0; /* disable sram */
It works perfectly with Gens, but Regen gave me the following message : "ADDRESS ERROR !"

On real Hardware, after the message "produced by or under...", i've a black screen.

What could be the problem?

TmEE co.(TM)
Very interested
Posts: 2440
Joined: Tue Dec 05, 2006 1:37 pm
Location: Estonia, Rapla City
Contact:

Post by TmEE co.(TM) » Sat Aug 25, 2012 2:27 pm

You cannot read words or longs from an odd address
Mida sa loed ? Nagunii aru ei saa ;)
http://www.tmeeco.eu
Files of all broken links and images of mine are found here : http://www.tmeeco.eu/FileDen

oofwill
Very interested
Posts: 173
Joined: Mon May 03, 2010 6:12 pm
Location: France - Niort

Post by oofwill » Sat Aug 25, 2012 2:38 pm

Ok, i think i've undertood.

i will use another way to store hi score.

Thanks :)

Post Reply