Sprite sorting

SGDK only sub forum

Moderator: Stef

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

Re: Sprite sorting

Post by Stef » Tue Jan 15, 2019 8:53 am

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 ?

mix256
Very interested
Posts: 189
Joined: Thu Jan 25, 2018 2:08 pm
Location: Sweden
Contact:

Re: Sprite sorting

Post by mix256 » Tue Jan 15, 2019 10:46 am

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.

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

Re: Sprite sorting

Post by Stef » Tue Jan 15, 2019 11:17 am

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 :-/

mix256
Very interested
Posts: 189
Joined: Thu Jan 25, 2018 2:08 pm
Location: Sweden
Contact:

Re: Sprite sorting

Post by mix256 » Wed Jan 16, 2019 7:31 am

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. :)

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

Re: Sprite sorting

Post by Stef » Wed Jan 16, 2019 8:35 am

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 ^^

mix256
Very interested
Posts: 189
Joined: Thu Jan 25, 2018 2:08 pm
Location: Sweden
Contact:

Re: Sprite sorting

Post by mix256 » Mon Jan 21, 2019 6:54 am

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. :)

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

Re: Sprite sorting

Post by Stef » Mon Jan 21, 2019 8:58 am

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 ?

mix256
Very interested
Posts: 189
Joined: Thu Jan 25, 2018 2:08 pm
Location: Sweden
Contact:

Re: Sprite sorting

Post by mix256 » Mon Jan 21, 2019 11:38 am

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.

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

Re: Sprite sorting

Post by Stef » Mon Jan 21, 2019 11:57 am

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 ^^).

mix256
Very interested
Posts: 189
Joined: Thu Jan 25, 2018 2:08 pm
Location: Sweden
Contact:

Re: Sprite sorting

Post by mix256 » Mon Jan 21, 2019 9:35 pm

All sorts of strange behaviors when setting "randomizing" the ram. My gamepad input reading goes bonkers. :)
Perfect test. Thanks!

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

Re: Sprite sorting

Post by Stef » Tue Jan 22, 2019 8:31 am

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.

mix256
Very interested
Posts: 189
Joined: Thu Jan 25, 2018 2:08 pm
Location: Sweden
Contact:

Re: Sprite sorting

Post by mix256 » Tue Jan 22, 2019 10:59 am

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!

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

Re: Sprite sorting

Post by Stef » Tue Jan 22, 2019 1:09 pm

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 :)

mix256
Very interested
Posts: 189
Joined: Thu Jan 25, 2018 2:08 pm
Location: Sweden
Contact:

Re: Sprite sorting

Post by mix256 » Tue Jan 22, 2019 2:19 pm

If it would turn out to be more stable with the HALT_Z80_ON_DMA flag, what would I then do? :)

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

Re: Sprite sorting

Post by Stef » Tue Jan 22, 2019 5:13 pm

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 :)

Post Reply