MEM_alloc

SGDK only sub forum

Moderator: Stef

Post Reply
bioloid
Very interested
Posts: 140
Joined: Fri May 18, 2012 8:22 pm

MEM_alloc

Post by bioloid » Mon Apr 22, 2019 9:21 am

Hello,

I've a MEM_alloc which is failing but my project is nearly empty, is there some build option I could have broken or something ?

hotrodx
Very interested
Posts: 50
Joined: Thu Mar 21, 2019 1:23 pm

Re: MEM_alloc

Post by hotrodx » Mon Apr 22, 2019 10:00 am

Did you call MEM_init() before you called MEM_alloc() ?

bioloid
Very interested
Posts: 140
Joined: Fri May 18, 2012 8:22 pm

Re: MEM_alloc

Post by bioloid » Mon Apr 22, 2019 10:51 am

not sure, i guess not will try thanks

bioloid
Very interested
Posts: 140
Joined: Fri May 18, 2012 8:22 pm

Re: MEM_alloc

Post by bioloid » Mon Apr 22, 2019 7:15 pm

hey, burning the vdp here, it works fine of Fusion but got stuck in real genny, trying VDP-Init but does not work, cleaver way to reset the thing ? need i call wait dma completion ?

hotrodx
Very interested
Posts: 50
Joined: Thu Mar 21, 2019 1:23 pm

Re: MEM_alloc

Post by hotrodx » Mon Apr 22, 2019 7:48 pm

I'm trying to decipher what you mean. If you were trying to push reset on the Genny, that's the equivalent of a Soft Reset. Variables are not re-initialized on soft resets.

To do a "hard reset", replace you main function like this:

Code: Select all

int main(u16 hard) {
    if (!hard) {
        SYS_hardReset();
    }

    // rest of the code here	
}
The behavior would be as if you run the program for the first time whenever you push the reset button.

bioloid
Very interested
Posts: 140
Joined: Fri May 18, 2012 8:22 pm

Re: MEM_alloc

Post by bioloid » Tue Apr 23, 2019 10:52 am

I havent SYS_hardReset in my sgdk version, will upgrade later.
Demo mainly works now, but reset still broken, not a problem...

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

Re: MEM_alloc

Post by Chilly Willy » Tue Apr 23, 2019 3:46 pm

In SGDK, a hard reset clears the work ram, then copies the data segment from rom into work ram (taking care of all those preset variables). A soft reset skips both those steps, so preset variables won't have their preset value, and the rest of memory won't be clear. Calling SYS_hardReset() forces a hard reset, thus clearing ram and setting all preset vars. So if your game uses something like

Code: Select all

    short init_flag = 0; // start not initialized
    
    ...
    if (!init_flag)
    {
        // do init
        ...
        init_flag = 1;
    }
then it won't work on a soft reset since init_flag will already be 1. A hard reset would set it back to 0 and then the init routine would run again.

bioloid
Very interested
Posts: 140
Joined: Fri May 18, 2012 8:22 pm

Re: MEM_alloc

Post by bioloid » Wed Apr 24, 2019 5:14 pm

ok thanks.

Post Reply