Sharp MZ-700: Program crashes at char textP1[25]; declaration

Post Reply
User avatar
RobertK
Well known member
Posts: 347
Joined: Mon Feb 26, 2018 12:58 pm

Sharp MZ-700: Program crashes at char textP1[25]; declaration

Post by RobertK »

I have a problem with my cross-platform game H-Tron running on the Sharp MZ-700 target. It compiles ok, but the program crashes at a specific point.

At the beginning of my InitPlayfield() function (which sets up the game screen), there are a few variable declarations:

Code: Select all

  int x,y;
  char textP1[25];
  char textP2[25];
When the program reaches the first char textP1[25] declaration, it crashes. Any idea why?

I tried to reproduce the problem with a little test program that also makes such a declaration, but there the problem does not occur.

You can compile my source file htron.c for the Sharp MZ using the latest nightly build like this:

Code: Select all

zcc +mz -clib=ansi -lm -create-app htron.c -o htron_sharpmz
User avatar
dom
Well known member
Posts: 2076
Joined: Sun Jul 15, 2007 10:01 pm

Post by dom »

Sorry, I've been out of commission for a few days, slowly coming back to life!

I can see that it compiles just to a single sp adjustment of 54 bytes. My first hunch would be that you're running out of stack space (I've no idea what the available stack is on an MZ without some research), so it might be worth compiling with the atexit size removed - by default on the MZ that's taking up 64 bytes of stack. You should be able to do this with: #pragma output CLIB_EXIT_STACK_SIZE = 0 in the source code.
User avatar
RobertK
Well known member
Posts: 347
Joined: Mon Feb 26, 2018 12:58 pm

Post by RobertK »

Your guess was correct! Adding...

Code: Select all

#if defined(__SHARPMZ__)        // Sharp MZ
        #pragma output CLIB_EXIT_STACK_SIZE = 0
#endif
...has solved the problem, thanks! I have updated the Sourceforge project, now eleven target systems are supported. :cool:

Image
User avatar
dom
Well known member
Posts: 2076
Joined: Sun Jul 15, 2007 10:01 pm

Post by dom »

That's good, I think a brief disassembly of the ROM shows that there's 240 bytes of stack available - it looks like sp is at 0x10f0 on entry. Given that we're taking over the whole machine I think we could define REGISTER_SP as 0xd000 since that's the top of paged in memory and then there's no limit anywhere.

For your case, I don't think there's any benefit in protecting that #pragma as just for the MZ - I'm guessing you're not using atexit() so it might as well be 0 for all targets.
Post Reply