You are not logged in.
Lost Password?


Register To Post



 Bottom   Previous Topic   Next Topic

#1
Call stack and nested function calls
Posted on: 2014/1/16 20:26
Nintendoid!
Joined 2006/3/15
Ecuador
236 Posts
PVBCC 3rdCoderLong Time User (13 Years)
Hi guys, I'm experience some very strange behavior while running my code on the VB, however all works just fine in both Rboy and Rdragon .

The problem seems to be related to nested function calls and the size of the call stack, for example:

void callNested5(int* dummy){
vbPrint(0, 1, 5, "5", 0);
callNested2(dummy);
}

void callNested4(int* dummy){
vbPrint(0, 1, 4, "4", 0);
callNested5(dummy);
}

void callNested3(int* dummy){
vbPrint(0, 1, 3, "3", 0);
callNested4(dummy); // if this call is allowed the game crashes on the VB
}

void callNested2(int* dummy){
vbPrint(0, 1, 2, "2", 0);
callNested3(dummy);
}

void callNested1(int* dummy){
vbPrint(0, 1, 1, "1", 0);
callNested2(dummy);
}

int callRecursive(int number){

//vbjPrintInt(number, 1, 20);
return 0 == number? 0: callRecursive(--number);
}

int main(void){

vbDisplayOn();

copymem((void*)CharSeg3+(254*16), (void*)ASCII_CH2, 258 << 4);

WA[31].head = WRLD_ON;
WA[31].w = 384;
WA[31].h = 224;
WA[30].head = WRLD_END;

VIP_REGS[BRTA] = 32;
VIP_REGS[BRTB] = 64;
VIP_REGS[BRTC] = 32;

int dummy = 0;

while(1) {
callNested1(&dummy);
callRecursive(2);

}
}

As soon as I put in the call to callNested4 from callNested3 the screen just stays black on the VB.

The recursive call crashes the program too but only in the VB.

I'm compiling with GCCVB 4, does anyone else experience the same problem?

BTW: I've tried a barebones test program with only libgccvb and the problem does not arises, neither by calling callNested1 nor callRecursive so I suspect that it has to do with the size of my engine, but it buffles me that in the emulator the code works.

Is there any way to know how the stack and the .bss sections are related? I have some big structs in the .bss.

Jorgeche
Top

#2
Re: Call stack and nested function calls
Posted on: 2014/1/17 0:38
Nintendoid!
Joined 2006/3/15
Ecuador
236 Posts
PVBCC 3rdCoderLong Time User (13 Years)
Using Rboy's debugger I've made some sense of the memory status, and how the stack relates to the .bss section.

I have reduced the RAM footprint to 15612 bytes, but still it crashes on the real hardware.

The RAM dump doesn't show anything strange.

Attach file:


txt sections.txt Size: 61.92 KB; Hits: 190
bin ram_sys.bin Size: 64.00 KB; Hits: 92
vb skeleton.vb Size: 256.00 KB; Hits: 109
Edited by jorgeche on 2014/1/17 0:56
Top

#3
Re: Call stack and nested function calls
Posted on: 2014/1/21 5:37
Nintendoid!
Joined 2006/3/15
Ecuador
236 Posts
PVBCC 3rdCoderLong Time User (13 Years)
Solved:

http://www.planetvb.com/modules/newbb ... t_id=27088#forumpost27088
Top

 Top   Previous Topic   Next Topic


Register To Post