DDR like demo

Announce (tech) demos or games releases

Moderator: Mask of Destiny

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

Post by Chilly Willy » Sat Aug 25, 2012 6:57 pm

Yeah, if you were in assembly, you could write words or longs using movep.w or movep.l, which writes each byte of the word or long to every other byte location, but you cannot do that in C. You would need to do this to write a word:

Code: Select all

*(vu8*)(0x200003) = 500 >> 8;
*(vu8*)(0x200005) = 500 & 255;
The first line writes the MSB of the word, and the second writes the LSB of the word. You would have a similar issue reading the word from memory. If it were me, I'd make a set of assembly functions in a separate file to handle this... have an sram.s file with functions like this

Code: Select all

| extern void sram_enable(void);
    .global sram_enable
sram_enable:
    move.b  #1,0xA103F1
    rts

| extern void sram_disable(void);
    .global sram_disable
sram_enable:
    move.b  #0,0xA103F1
    rts

| extern u8 sram_rd_byte(int offset);
    .global sram_rd_byte
sram_rd_byte:
    move.l  4(sp),d1
    add.l   d1,d1
    lea     0x200001,a0
    moveq   #0,d0
    move.b  (a0,d1.l),d0
    rts

| extern u16 sram_rd_word(int offset);
    .global sram_rd_word
sram_rd_word:
    move.l  4(sp),d1
    add.l   d1,d1
    lea     0x200001,a0
    lea     (a0,d1.l),a0
    moveq   #0,d0
    movep.w 0(a0),d0
    rts

| extern u32 sram_rd_long(int offset);
    .global sram_rd_long
sram_rd_long:
    move.l  4(sp),d1
    add.l   d1,d1
    lea     0x200001,a0
    lea     (a0,d1.l),a0
    movep.l 0(a0),d0
    rts

| extern void sram_wr_byte(int offset, u8 val);
    .global sram_wr_byte
sram_wr_byte:
    move.l  4(sp),d1
    add.l   d1,d1
    move.l  8(sp),d0 /* values on stack are always long */
    lea     0x200001,a0
    move.b  d0,(a0,d1.l)
    rts

| extern void sram_wr_word(int offset, u16 val);
    .global sram_wr_word
sram_wr_word:
    move.l  4(sp),d1
    add.l   d1,d1
    move.l  8(sp),d0 /* values on stack are always long */
    lea     0x200001,a0
    lea     (a0,d1.l),a0
    movep.w d0,0(a0)
    rts

| extern void sram_wr_long(int offset, u32 val);
    .global sram_wr_long
sram_wr_long:
    move.l  4(sp),d1
    add.l   d1,d1
    move.l  8(sp),d0 /* values on stack are always long */
    lea     0x200001,a0
    lea     (a0,d1.l),a0
    movep.l d0,0(a0)
    rts
Notes: to use them, you'd need to use the comment lines from the assembly for your protos in the C file, like this

Code: Select all

extern void sram_enable(void);
extern void sram_disable(void);
extern u8 sram_rd_byte(int offset);
extern u16 sram_rd_word(int offset);
extern u32 sram_rd_long(int offset);
extern void sram_wr_byte(int offset, u8 val);
extern void sram_wr_word(int offset, u16 val);
extern void sram_wr_long(int offset, u32 val);
and now you have C functions to call. Notice that the offset doesn't need to be doubled ahead of time - the function does that. So your code above would become

Code: Select all

    sram_enable();
    if (sram_rd_byte(0) != 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;}
        }
        sram_wr_byte(0, 250);             //indique qu'une sauvegarde existe
        sram_wr_word(1, 500);             //best score stage 1 réglé à 500
        sram_wr_word(3, 500);             //best score stage 2 réglé à 500
        sram_wr_word(5, 500);             //best score stage 3 réglé à 500

    }
    sram_disable();

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

Post by oofwill » Sat Aug 25, 2012 9:20 pm

You're my god :shock:

I've really have to learn asm...

i've created a sram.s with your code, then, a sram.h with void...
here is the result of compiling...

Code: Select all

sram.s|16|Error: syntax error -- statement `move.l 4(sp),d1' ignored|
sram.s|17|Error: operands mismatch -- statement `add.l d1,d1' ignored|
sram.s|18|Error: operands mismatch -- statement `lea 0x200001,a0' ignored|
sram.s|19|Error: operands mismatch -- statement `moveq #0,d0' ignored|
sram.s|20|Error: syntax error -- statement `move.b (a0,d1.l),d0' ignored|
||=== Build finished: 5 errors, 0 warnings ===|

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

Post by Chilly Willy » Sat Aug 25, 2012 10:15 pm

oofwill wrote:You're my god :shock:

I've really have to learn asm...

i've created a sram.s with your code, then, a sram.h with void...
here is the result of compiling...

Code: Select all

sram.s|16|Error: syntax error -- statement `move.l 4(sp),d1' ignored|
sram.s|17|Error: operands mismatch -- statement `add.l d1,d1' ignored|
sram.s|18|Error: operands mismatch -- statement `lea 0x200001,a0' ignored|
sram.s|19|Error: operands mismatch -- statement `moveq #0,d0' ignored|
sram.s|20|Error: syntax error -- statement `move.b (a0,d1.l),d0' ignored|
||=== Build finished: 5 errors, 0 warnings ===|
What are you compiling with? My code is gas syntax (gcc as). You also need to use the assembler flags "-m68000 --register-prefix-optional". My guess is it's choking on the register names because you aren't using --register-prefix-optional. Notice how your first error is on the first opcode with a register.

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

Post by sega16 » Sat Aug 25, 2012 10:21 pm

When I was using inline assembly in my project all registers address and sp (which is basically a7) need to have a % symbol before them could that be it?

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

Post by Chilly Willy » Sat Aug 25, 2012 10:44 pm

sega16 wrote:When I was using inline assembly in my project all registers address and sp (which is basically a7) need to have a % symbol before them could that be it?
You can either add % in front of the register names or add "--register-prefix-optional" to the assembly flags.

KanedaFr
Administrateur
Posts: 1139
Joined: Tue Aug 29, 2006 10:56 am
Contact:

Post by KanedaFr » Sat Aug 25, 2012 11:31 pm

another contribution from Chilly Willy to SGDK ? ;)

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

Post by Stef » Sat Aug 25, 2012 11:34 pm

Yep i already recopied the functions almost as he gave them :p

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

Post by Chilly Willy » Sun Aug 26, 2012 3:39 am

Hey, even simple functions have their place. Not everything is lightgun support complex. :D

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

Post by oofwill » Sun Aug 26, 2012 7:54 am

I don't know wich compiler i'm using.

I follow the tuto on wiki in order to use SGDK with code blocks. Nothing more.

i'll try to add % in front of register name, i'll tell you the result ;)

bastien
Very interested
Posts: 208
Joined: Mon Jun 25, 2007 7:19 pm
Location: Besançon,France
Contact:

Post by bastien » Sun Aug 26, 2012 8:00 am

Hi all,
I know you can use ASM syntaxe directly with SGDK:
here is the syntaxe exemple:

Code: Select all

asm(
"       nop\n"
"       move   #0x2700,%sr\n"
"       move.l (0),%a7\n"
"       move.l (4),%a0\n"
"       jmp    (%a0)\n"
);

So maybe with this method it's possible to make an include with SRAM asm function?
oofwill wrote:I don't know wich compiler i'm using.
SGDK use gcc

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

Post by oofwill » Sun Aug 26, 2012 8:07 am

Thanks all !

Bastien, i think it's possible, but yesterday, i tested this method and it seems it wasn't working. (cause i haven't %)

In your code, register are preceded by % symbol.

Indeed, the 2 methods seems to be working.
I have add % and the compiler don't return me any error.

However, this code doesn't work :

Code: Select all

sram_enable();
    if (sram_rd_byte(0) != 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;}
        }
        sram_wr_byte(0, 250);             //indique qu'une sauvegarde existe
        sram_wr_word(1, 500);             //best score stage 1 réglé à 500
        sram_wr_word(3, 500);             //best score stage 2 réglé à 500
        sram_wr_word(5, 500);             //best score stage 3 réglé à 500

    }
    sram_disable(); 
When byte @ 0x200001 is not equal at 250, we are enterring in the loop, the first time.
Then we are writing 250 at this address (sram_wr_byte(0, 250); )
When i do a reset, game are suppose not to enter the loop, but it always enter the loop... i don't know why...

EDIT : it's working!! :D
Chilly willy, you made a little mistake in your code :

Code: Select all

sram_enable:
    move.b  #1,0xA103F1
    rts 
it's 0xA130F1 and not 0xA103F1

You know what? i'm happy.
^^

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

Post by oofwill » Sun Aug 26, 2012 11:09 am

Ok, so save is working.

In order to test my demo on real hardware, i burned it on eprom (27c322) and put it on a standard sram pcb (i'm problably a spammer) (i don't own flash cart)

i usually use this pcb and it works everytime, but this time not.

I suppose my pcb is wired to work with game 512 to 4096ko or 512 to 2048 with save.

Here my rom is 3.75Mo and don't want to boot on my pcb.

I've always black screen after "produced by bla bla bla"

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

Post by oofwill » Sun Aug 26, 2012 2:43 pm

New :

- i burned an eprom and put it on a i'm problably a spammer 97 pcb. it's working only if i modify wire to sram.

Address decoder is commanded by pin B9 on cartridge connector.
i cut this link and link B9 to A20 (pin 32) on eprom.
Ok, it boot but there are several problems.

first, save don't work. Indeed, sram address is certainly bad now since decoder is commanded now by pin B10 on cartridge connector.
Then, i have glitches, i suppose they appear every time game try to access sram (on the menu, game read hi-score to draw them on screen)

the result on RH is :

http://youtu.be/0o7MsUFcQXc

Edit : i think i can't use 27c322 (4Mo) prom with save...

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

Post by Chilly Willy » Sun Aug 26, 2012 6:39 pm

oofwill wrote: EDIT : it's working!! :D
Chilly willy, you made a little mistake in your code :

Code: Select all

sram_enable:
    move.b  #1,0xA103F1
    rts 
it's 0xA130F1 and not 0xA103F1

You know what? i'm happy.
^^
Whoopsi! See? Even the best of us make mistakes. :D

Yes, that's a common problem I have - pressing keys out of order while typing. It's because I'm strongly left-brain dominant (right handed). So keys under the right hand (touch typing) tend to be press a little harder and faster than keys under the left hand. And that means that sometimes keys under the right hand (like 0 ) wind up before keys under the left hand (like 3 ) when they should be the other way around. Nice catch there.

You'll noticed sram_disable() has the same mistake... it was cut-n-paste with the 1 changed to 0.

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

Post by oofwill » Mon Aug 27, 2012 10:29 am

I had seen for sram_disable();
I knew this was copy-paste since there is a "enable" in the sram_disable(); code :mrgreen:

I've the same problem. some time i put letters in wrong order since my right hand is typing faster :lol:

In all case, you really help me with this.

However, i wanted to build a 64MEG cartridge with sram, but i don't find the correct scheme for this...

I decide to build a 64MEG cartridge without sram, but your code will be usefull for a next program :)

thanks again :)

Photo of my 64MEG (8Mo) cartridge test :)

Image

Post Reply