Video problems on hw

SGDK only sub forum

Moderator: Stef

cero
Very interested
Posts: 338
Joined: Mon Nov 30, 2015 1:55 pm

Video problems on hw

Post by cero » Thu Dec 17, 2015 9:30 am

I have a larger rom, 2.6mb, that works perfectly in several emulators, but when run on hardware, the video is corrupted in many ways (sometimes tiles in wrong parts, sometimes black screen), though the game runs fine - music continues to play and sound effects happen as they should.

I protect VDP accesses by disabling interrupts, and when doing bigger screen setup, also by VDP_setEnable(0). I read I should disable SRAM when the ROM is over 2mb, and indeed the first line in main() is SRAM_disable().

This has me pretty baffled. What could cause it to fail on hw, when several emulators have no issue?

ComradeOj
Interested
Posts: 27
Joined: Sun Jun 28, 2015 4:18 pm
Contact:

Re: Video problems on hw

Post by ComradeOj » Thu Dec 17, 2015 12:08 pm

Are you clearing out the 68K's RAM first? Or does SGDK do it for you?

When I was doing homebrew stuff, everything worked fine in every emulator. I eventually got an everdrive, and ran some of my stuff on it. I learned the hard way that you can't expect RAM, registers, or anything else to be cleared beforehand.
Visit my web site at http://www.mode5.net/!

cero
Very interested
Posts: 338
Joined: Mon Nov 30, 2015 1:55 pm

Re: Video problems on hw

Post by cero » Thu Dec 17, 2015 1:34 pm

SGDK does it for me, in boot/sega.s.

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

Re: Video problems on hw

Post by Stef » Thu Dec 17, 2015 4:06 pm

Interrupts problems would happen on emulator as well but it's true that given your problems i would have think about that in first place.
What kind of flash cart are you using ? possible that some data are corrupted while transferring ?
The SRAM problem would only happen for data above 0x200000 address range.

cero
Very interested
Posts: 338
Joined: Mon Nov 30, 2015 1:55 pm

Re: Video problems on hw

Post by cero » Thu Dec 17, 2015 4:18 pm

It's not a flashcart, but a programmed chip. Other big roms work.

I'll try to make a small test ROM I can share.

mikejmoffitt
Very interested
Posts: 86
Joined: Fri Sep 25, 2015 4:16 pm

Re: Video problems on hw

Post by mikejmoffitt » Thu Dec 17, 2015 6:08 pm

Make sure you are not doing any non-blocking VRAM DMA operations without waiting for a previous DMA completion.

cero
Very interested
Posts: 338
Joined: Mon Nov 30, 2015 1:55 pm

Re: Video problems on hw

Post by cero » Thu Dec 17, 2015 6:12 pm

My original ROM does not use DMA at all after loading all tiles at startup, so I don't think DMA is the issue.

Okay, I have a redistributable test ROM that shows the issue here:
https://github.com/clbr/gentest/raw/master/game.bin.xz

Sources are in the same repo:
https://github.com/clbr/gentest

I'd appreciate if you could try it on your hw. And maybe build it too, so we can isolate whether it's something in my toolchain (but in that case, it should affect emulators too?).

mikejmoffitt
Very interested
Posts: 86
Joined: Fri Sep 25, 2015 4:16 pm

Re: Video problems on hw

Post by mikejmoffitt » Thu Dec 17, 2015 10:04 pm

These stand out immediately:

Code: Select all

	VDP_clearPlan(VDP_PLAN_A, 1);
	VDP_clearPlan(VDP_PLAN_B, 1);
Try waiting for DMA completion after each clearPlan. These are non-blocking DMA operations, where you are filling with zero. I remember having a similar problem in a project of mine. I think the palette setting one might also use DMA but I do not remember.

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

Re: Video problems on hw

Post by Stef » Thu Dec 17, 2015 11:08 pm

Only DMA fill can be a problem as DMA copy operation locks the main CPU.
Indeed using clearPlan(..) with DMA can be a problem as it *does* use the DMA fill here !

cero
Very interested
Posts: 338
Joined: Mon Nov 30, 2015 1:55 pm

Re: Video problems on hw

Post by cero » Fri Dec 18, 2015 9:43 am

That's extremely surprising, because nowhere in the docs does it say that. I assumed even when using DMA it would block. I would argue it's the job of the SDK to be safe here, doing the blocking internally, or at the very least documenting it with heavy warnings.

I don't have access to hw right now, can you test?

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

Re: Video problems on hw

Post by Stef » Fri Dec 18, 2015 1:42 pm

Well the SDK was doing that before but definitely was not a good idea as you might want the method to not block execution.
It can be really interesting to take advantage of background VRAM fill operation while the 68k is doing other stuff :)
You can use VDP_waitDMACompletion() after each VDP_clearPlan() operation...
Thinking about it, i should eventually replace the 'use_dma' parameter by 'wait' so it always use DMA but also to wait for completion if wanted :)

cero
Very interested
Posts: 338
Joined: Mon Nov 30, 2015 1:55 pm

Re: Video problems on hw

Post by cero » Fri Dec 18, 2015 2:07 pm

Can you confirm the current ROM has issues on hw, and that fixes it?

Also, this really needs to be documented. Every dangerous function needs to have big warnings.

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

Re: Video problems on hw

Post by Stef » Fri Dec 18, 2015 2:29 pm

That will be documented don't worry, i will change the use_dma by wait parameter and explain the difference.
Where is the download to test the rom ?

cero
Very interested
Posts: 338
Joined: Mon Nov 30, 2015 1:55 pm

Re: Video problems on hw

Post by cero » Fri Dec 18, 2015 3:54 pm

A couple posts above:
cero wrote:Okay, I have a redistributable test ROM that shows the issue here:
https://github.com/clbr/gentest/raw/master/game.bin.xz

Sources are in the same repo:
https://github.com/clbr/gentest

I'd appreciate if you could try it on your hw. And maybe build it too, so we can isolate whether it's something in my toolchain (but in that case, it should affect emulators too?).
I understood the use_dma parameter as "do it faster if no other DMA is in progress". Am I wrong?

cero
Very interested
Posts: 338
Joined: Mon Nov 30, 2015 1:55 pm

Re: Video problems on hw

Post by cero » Fri Dec 18, 2015 6:05 pm

Hm, would it be too much overhead to add VDP_waitDMACompletion() to the start of every VDP function, thereby making all functions safe to use, and also allowing user code to do non-VDP things when the DMA fill is going on?

If it was made an inline function, that'd be just one or two instructions.

Post Reply