Page 1 of 1

VDP Plane Priority Bug in Dgen-SDL

Posted: Sat Sep 15, 2012 12:30 am
by vext01
I'm new here. Hello.

I have been trying to track down an annoying VDP bug in dgen-sdl. I first asked on assemblergames and they pointed me here.

I hope it is OK to just paste my original post:

Look at the attached screenshot. Notice the player sprite is partially over the scores.

The plane priority on the emulator is as follows:

---8<---
// Draw, from the bottom up
// Low priority
draw_plane_back1(line);
draw_plane_back0(line);
draw_window(line, 0);
draw_sprites(line, 0);
// High priority
draw_plane_front1(line);
draw_plane_front0(line);
draw_window(line, 1);
draw_sprites(line, 1);
---8<---

I think plane 0 is plane A here and 1 = B.

What we are seeing here is a low priority sprite rendering over the low priority window plane. It looks wrong and is (this doesn't happen on the real thing).

By drawing the window planes last, ie:

---8<---
// Draw, from the bottom up
// Low priority
draw_plane_back1(line);
draw_plane_back0(line);
draw_sprites(line, 0);
draw_window(line, 0);
// High priority
draw_plane_front1(line);
draw_plane_front0(line);
draw_sprites(line, 1);
draw_window(line, 1);
---8<---

then the game *appears* correctly.

Yet if we consult some docs (http://emu-docs.org/Genesis/Graphics/genvdp.txt):

---8<---
(back) (front)
A > B > C > D > E' > F' > G'

' = Denotes high priority
A = Backdrop color
B = Low priority plane B
C = Low priority plane A
D = Low priority sprites
E = High priority plane B
F = High priority plane A
G = High priority sprites
---8<---

And we are given some info about the interaction of window too:

---8<---
The window plane operates differently from plane A or B. It can be thought
of a 'replacement' for plane A which is used under certain conditions.
That said, plane A cannot be displayed in any area where plane W is
located, it is impossible for them to overlap.
---8<---

This implies the following plane ordering to me:

---8<---
Backdrop color
Low priority plane B
Low priority plane A
Low priority window
Low priority sprites
High priority plane B
High priority plane A
High priority window
High priority sprites
---8<---

This is exactly the ordering that causes the issue in the first place?!

Can someone clarify this. Should the window always be on top? Any ideas what this is all about?

Image

Posted: Sat Sep 15, 2012 5:15 am
by TmEE co.(TM)
Better idea would be A / W not A after W or the other way. Where there is W there is no A, but otherwise W behaves exactly like A, just it is not scrollable.

Posted: Sat Sep 15, 2012 7:28 am
by vext01
That makes sense.

So now all I have to do is decypher dgen's VDP implementation and add a function that extracts a box bound which plane A must not draw into.

I wonder if I calculate this bound once per screen refresh. Depends if the window can change dimensions mid-screen redresh.

Cheers!

Posted: Sat Sep 15, 2012 7:48 am
by TmEE co.(TM)
You can change window in midscreen, but I don't think any game actually does it.

Posted: Sat Sep 15, 2012 8:51 am
by Stef
Simple question but, why are you using DGen when you have Genesis Plus SDL which is far far more accurate than the outdated DGen ?

Posted: Sat Sep 15, 2012 9:48 am
by vext01
I appreciate that dgen is not the best emulator in town, but it is still under development. Mostly by zamaz, but i've done some bits myself too.

I initially chose dgen-sdl because it was fast and portable -- the only emulator that built and ran fast on my OpenBSD machines. Having said that, I tried the mednafen dev sources yesterday and I have to say, it's genesis emulation is pretty good.

Isn't gens-plus for the gamecube and wii anyway? I got as far as looking at the build system and decided it didn't look like it will run on unix.

Posted: Sat Sep 15, 2012 10:51 am
by Stef
vext01 wrote:I appreciate that dgen is not the best emulator in town, but it is still under development. Mostly by zamaz, but i've done some bits myself too.

I initially chose dgen-sdl because it was fast and portable -- the only emulator that built and ran fast on my OpenBSD machines. Having said that, I tried the mednafen dev sources yesterday and I have to say, it's genesis emulation is pretty good.

Isn't gens-plus for the gamecube and wii anyway? I got as far as looking at the build system and decided it didn't look like it will run on unix.
Genesis Plus was initially designed for PC but with easy portability in mind so we quickly saw port to video game system as dreamcast, gamecube, wii, xbox...
You can find a SDL version in the download section of Genesis Plus GX site :
http://code.google.com/p/genplus-gx/downloads/list
May be it is not the best choice for your OpenBSD machine as accuracy cost time but i remember DGen was not that fast as soon you choose the scanline renderer (which is needed for many games to work correctly).

Also i dunno if you plan to fix all graphics bugs you can meet with DGen but if that is what you want, the one you are pointing is only one of the many which exists in DGen... as far i remember DGen does not emulate the highlight / shadow effect, sprite masking, sprite list vdp cache feature...
but if you only want to fix that specific SOR2 bug then you can fix the window / plan A rendering easily i guess :)

Posted: Sat Sep 15, 2012 11:09 am
by vext01
Yeh there's a load of stuff which does not work in dgen. The EA logo is one I find most annoying. Zamaz tells me this is DMA timing issues.

Anyway, we will see how it goes... Time is hard to come by these days.

Thanks

Posted: Sat Sep 15, 2012 6:43 pm
by MetalliC
vext01 wrote:Isn't gens-plus for the gamecube and wii anyway? I got as far as looking at the build system and decided it didn't look like it will run on unix.
genesis plus gx is not only for gc/wii. I'll recommend check RetroArch project, it is multiplatform/open-source and uses genesis plus core for genesis/megadrive emulation.

Posted: Sat Sep 15, 2012 9:55 pm
by Stef
vext01 wrote:Yeh there's a load of stuff which does not work in dgen. The EA logo is one I find most annoying. Zamaz tells me this is DMA timing issues.

Anyway, we will see how it goes... Time is hard to come by these days.

Thanks
The EA logo is just a problem with write to VDP CTRL port. I don't remember the detail but i know this has something to do with VDP internal command state (first or second command word about to be written).
But now you're speaking about, the DMA timing is another issue of DGen indeed.

Posted: Tue Oct 02, 2012 9:03 am
by vext01
I managed to hook up with Charles MacDonald on IRC and he correctly diagnosed the issue as a sprite masking problem.

Code: Select all

/*
 * Search for the highest priority sprite with x = 0. Call this sprite s0.
 * Any sprite with a lower priority than s0 (therefore higher index in
 * the array) is not drawn on the scanlines that s0 occupies on the
 * y-axis. This is called sprite masking and is used by games like Streets
 * of Rage and Lotus Turbo Challenge.
 */
Fixed in dgen-sdl trunk :) Thanks to all for input.

PS.

I would be interested to know more about the EA logo bug if anyone knows anything about that.[/code]