Page 3 of 4

Re: Sprite sorting

Posted: Tue Jan 15, 2019 8:53 am
by Stef
Did you try to run with the "debug" library to see if some errors were thrown (allocation or stuff like that) at some point ?
Also when did these exceptions happened ? After several minutes of gameplay ? or it can happen quite quickly ?

Re: Sprite sorting

Posted: Tue Jan 15, 2019 10:46 am
by mix256
Unfortunately I only get these kind of errors on real hardware. Don't think I ever saw it in any emulator nor on the retroad machine.
When it happens can be really random. I can play the game for hours without it happening but sometimes it can happen just after a few minutes.

Re: Sprite sorting

Posted: Tue Jan 15, 2019 11:17 am
by Stef
You may try to play a long time with Gens KMod in debug mode maintaining the output message dialog open, just to see if some warnings or errors happen from time to time (that doesn't necessary end to an exception). If absolutely no log appears after playing one or several hours then it will be quite difficult to track the bug :-/

Re: Sprite sorting

Posted: Wed Jan 16, 2019 7:31 am
by mix256
Had quite a long session in gens kmod yesterday, running a debug build. But the error didn't happen. I will try some more tonight. :)

Re: Sprite sorting

Posted: Wed Jan 16, 2019 8:35 am
by Stef
i hope you will be able to have at least some information from the debug lib in GensKMod, otherwise you (we) will have a hard time in finding the source of the bug ^^

Re: Sprite sorting

Posted: Mon Jan 21, 2019 6:54 am
by mix256
I've been running several long runs in genskmod the last couple of days without getting any kind of error. On a real megadrive it can happen at any time. Seems like there could be an mem-init issue? Like I've forgotten to initialize a variable that should be zero. Gets a random value on real hw but is zero in emulators?
Any input regarding this is hilghly appreciated. :)

Re: Sprite sorting

Posted: Mon Jan 21, 2019 8:58 am
by Stef
This can be the reason but it can also be timing differences between the emulator and real hardware which lead to some weird issues like that.

Something you can try eventually is too comment the RAM initialization code from SGDK sega.s file :

Code: Select all

ClearRam:
   * move.l %d0,(%a0)+
but i wonder if some parts of SGDK relies on having ram cleared... still that is something you can try.

You may eventually try to turn this flag ON in the config.h file from the library (son't forget to recompile the lib then) :

Code: Select all

#define HALT_Z80_ON_DMA   1
This is to force Z80 halt during DMA. To be honest it would be better to avoid it but you can try that to see if it does any difference.
By the way, what kind of cart are you using to test your code ?

Re: Sprite sorting

Posted: Mon Jan 21, 2019 11:38 am
by mix256
Thanks! I hex edited with NOPs in the clear ram loop and have a release build running here at work now. :)

Could the rom file have "random" values if .text have variables that is not initialized?
I was thinking that I have some variables in .text that isn't set properly, that would be in the "copy initialized variables from ROM to Work RAM" part, right. Or are these always zeroes?

Will try the HALT_Z80_ON_DMA when I get back home.

Re: Sprite sorting

Posted: Mon Jan 21, 2019 11:57 am
by Stef
Normally variables in .text section should be properly initialized, i think it would be helpful to try to randomize the RAM and test on emulator to see if it does any difference (having the clear RAM doing randomize RAM instead or something like that ^^).

Re: Sprite sorting

Posted: Mon Jan 21, 2019 9:35 pm
by mix256
All sorts of strange behaviors when setting "randomizing" the ram. My gamepad input reading goes bonkers. :)
Perfect test. Thanks!

Re: Sprite sorting

Posted: Tue Jan 22, 2019 8:31 am
by Stef
Did you randomized the RAM at the same location as clearRAM loop in the sega.s file ? it's important to keep it here (otherwise you can erase some internals variables). Weird that your gamepad reading goes wrong, maybe there is some uninitialized vars in there.

Re: Sprite sorting

Posted: Tue Jan 22, 2019 10:59 am
by mix256
Yep, I just started D0 with 0x011111111 and increased it for each iteration in the loop.
And yes, there were uninitialized vars in my input handling and also at a few other places. :oops:

Still won't help me track down the strange bug. But at least the code is nicer now. :)
Also I didn't try with the HALT_Z80_ON_DMA, will do that tonight. This will affect the music playback somehow, I reckon?

Thanks!

Re: Sprite sorting

Posted: Tue Jan 22, 2019 1:09 pm
by Stef
Yeah enabling this flag will degrade PCM playback quality definitely, it's why it would be better to avoid using it but you can test to see if it makes any difference. About RAM randomization, i may eventually do it by default in SGDK to help in spotting "unitialized variable" bug :)

Re: Sprite sorting

Posted: Tue Jan 22, 2019 2:19 pm
by mix256
If it would turn out to be more stable with the HALT_Z80_ON_DMA flag, what would I then do? :)

Re: Sprite sorting

Posted: Tue Jan 22, 2019 5:13 pm
by Stef
Pry so it won't happen :p
No if that is really the case then we need to understand why and how to sort it without using this flag :)