General Insanity (Genesis + PVR)

If you have any questions on programming, this is the place to ask them, whether you're a newbie or an experienced programmer. Discussion on programming in general is also welcome. We will help you with programming homework, but we will not do your work for you! Any porting requests must be made in Developmental Ideas.
Post Reply
Storminator16
DCEmu Veteran
DCEmu Veteran
Posts: 850
https://www.artistsworkshop.eu/meble-kuchenne-na-wymiar-warszawa-gdzie-zamowic/
Joined: Mon Sep 01, 2003 11:12 am
Location: NC/Iraq
Has thanked: 0
Been thanked: 0
Contact:

Post by Storminator16 »

Ah, I added the menu to what I have already and I've noticed the sound buffer isn't being emptied before loading another rom. I was playing Thunderforce 3 with a nasty little loop from Sonic 1.
Ian Micheal
Soul Sold for DCEmu
Soul Sold for DCEmu
Posts: 4865
Joined: Fri Jul 11, 2003 9:56 pm
Has thanked: 2 times
Been thanked: 4 times

Post by Ian Micheal »

I dont think the sound was shutdown just write a small shut down function when you return to the menu that should work fine. Depends if your using the Gens FM sound emulator or standard genesis plus FM emulator this is both.

Of course ive not tryed it yet never had a menu or loading more then one rom in a row.
Dreamcast forever!!!
BlackAura
DC Developer
DC Developer
Posts: 9951
Joined: Sun Dec 30, 2001 9:02 am
Has thanked: 0
Been thanked: 1 time

Post by BlackAura »

ice88 - I have the twiddling code down to:

Code: Select all

#define TWIDTAB(x) ( (x&1)|((x&2)<<1)|((x&4)<<2) )
#define TWIDOUT(x, y) ( TWIDTAB((y)) | (TWIDTAB((x)) << 1) )

void twiddle_4bit_md(uint8 *src, pvr_ptr_t *dst)
{
	int x, y;
	uint8 * pixels;
	uint16 * vtex;
	pixels = (uint8 *) src;
	vtex = (uint16*)dst;

	for (y=0; y<8; y += 2)
	{
		int yv1 = y<<3;
		int yv2 = yv1+8;
		for (x=0; x<8; x += 2)
		{
			int sx = x ^ 2;
			vtex[TWIDOUT(x>>1, y>>1)] =
				((pixels[(sx+yv1) >>1]&15)<<8) | ((pixels[(sx+yv2) >>1]&15)<<12) |
				((pixels[(sx+yv1) >>1]>>4)   ) | ((pixels[(sx+yv2) >>1]>>4)<<4);
		}
	}
}
Mostly, that's going through the code, finding redundant calculations, and getting rid of them. I did write a small program which generated some code to twiddle 8x8 pixel tiles, but it wasn't any faster (as far as I could see). Modifying it to use store queues is probably the next step. That way, it'll be twiddling to an internal buffer (in the CPU, so it should be nice and fast) and then sending it over to VRAM while we're busy twiddling the next one.

By the way, I've made some graphical fixes to it. Background colours now work (although they look a little brighter than the foreground colours), it blanks out the border, blanking the screen now works, and 32-cell mode looks a little less crappy than it previously did. Personally, I think 640x480 does actually look better than 320x240, but only because I think the Dreamcast is doing something weird with 320x240 mode. And you can't see the dithering in 640x480, but it's a lot more noticable in 320x240

Still not worked out how to do windowing though. I could do a heavily bodged-up version which might just about be enough to get some games working. It certainly won't be accurate, but it might be enough to get some status bars showing up.
Storminator16
DCEmu Veteran
DCEmu Veteran
Posts: 850
Joined: Mon Sep 01, 2003 11:12 am
Location: NC/Iraq
Has thanked: 0
Been thanked: 0
Contact:

Post by Storminator16 »

'snd_stream_clear()' or 'gpdc_snd_stream_clear()' solves the sound playing after selecting another rom (or after exiting current rom). This should go in the menu in the place of 'snd_stream_shutdown()'
Warmtoe
DC Developer
DC Developer
Posts: 453
Joined: Thu May 16, 2002 8:29 am
Location: ice88's house
Has thanked: 0
Been thanked: 0
Contact:

Post by Warmtoe »

BlackAura wrote:...Modifying it to use store queues is probably the next step. That way, it'll be twiddling to an internal buffer (in the CPU, so it should be nice and fast) and then sending it over to VRAM while we're busy twiddling the next one.
Yes - pretty slick that'll be I reckon, you really have cut down the twiddle function an impressive amount - that must make a noticeable difference... I would think so anyway.
BlackAura wrote:By the way, I've made some graphical fixes to it. Background colours now work (although they look a little brighter than the foreground colours)
Interesting - can we fix that with the vertex_colour value being something other than 0xFFFFFFFF - you may have noticed, I hard-coded that value instead of using vertex_colour... if you didn't notice and used this mechanism to fix it, apologies - it was my doing.
BlackAura wrote:it blanks out the border, blanking the screen now works, and 32-cell mode looks a little less crappy than it previously did.
OK - if you have code changes, any chance you can upload them somewhere?
BlackAura wrote:Personally, I think 640x480 does actually look better than 320x240, but only because I think the Dreamcast is doing something weird with 320x240 mode. And you can't see the dithering in 640x480, but it's a lot more noticable in 320x240
Interesting - I could not see much difference in truth - the main difference for my money is that it works nicely in CHANKAST with 640x480 and doesn't with 320x240.
BlackAura wrote:Still not worked out how to do windowing though. I could do a heavily bodged-up version which might just about be enough to get some games working. It certainly won't be accurate, but it might be enough to get some status bars showing up.
Ah - status bars - I wondered what windowed mode actually was.

Anyway, great - this is just whizzing along, we should all work together more often!!!! As soon as you have some code to make available, please update - I'm ready to take up the overnight challenge tonight!!!!
BlackAura
DC Developer
DC Developer
Posts: 9951
Joined: Sun Dec 30, 2001 9:02 am
Has thanked: 0
Been thanked: 1 time

Post by BlackAura »

Yes - pretty slick that'll be I reckon, you really have cut down the twiddle function an impressive amount - that must make a noticeable difference... I would think so anyway.
It makes a bit of a difference, but not a lot. Rocket Knight Adventures (probably the least demanding game I have that's still fun) works full speed almost all the time, except where theres a load of explosions on screen, but the game itself slows down then, so you don't notice.
Interesting - can we fix that with the vertex_colour value being something other than 0xFFFFFFFF - you may have noticed, I hard-coded that value instead of using vertex_colour... if you didn't notice and used this mechanism to fix it, apologies - it was my doing.
Maybe. It's actually brighter now.

The reason I had vertex_colour was for later. Some MD games will render the low-priority background layers at half brightness, but only if a bit in one of the registers is set. I don't know what bit that is, so...
OK - if you have code changes, any chance you can upload them somewhere?
No. Still working on it (see below)
Ah - status bars - I wondered what windowed mode actually was.
Speaking of which, I've done a really dodgy implementation of these. It works for status bars, but it certainly won't work if a game uses a window as part of the actual game. Basically, it draws the window plane over the top of plane A. It's supposed to replace plane A (as in - plane A is never drawn, and the window replaces it) but that's too much effort right now. So status bars (appear to) work, at least in Rocket Knight.

I'll make a couple more changes, and then re-upload it.
speud
DCEmu Uncool Newbie
DCEmu Uncool Newbie
Posts: 1459
Joined: Sat Dec 27, 2003 10:40 pm
Has thanked: 0
Been thanked: 0
Contact:

Post by speud »

i thinks its too early for a bug report, but just in case its useful i noticed a few games that have specifical graffical problems that need to be fixed:

sonic 2: in 2players mode the screen is a real garbage :)
shining force and zombie ate my neighbours: the screen is not centered properly, its "pushed" to the left and the right side is displaying some "unused" sprites.
outrun: the multidirectionnal scrolling doesnt seem to work properly in this game, the road is barely visible.
afterburner: on the horizon this makes a "stairs" effect instead of a diagonal line, depending on how much you rotate the plane.
aladdin and cool spot (probably other virgin games as well): the hero's sprite is a bit more buggy than in other games.

also i think in 640x480 the sprites that should be hidden and are displayed by accident one more frame are more noticable than in 320x240 (for example the "sega" logo in phantasy star 4).
http://blueswirl.fr.st - DC Online Tools and Downloads

thx to Wack0 for the avatar ;)
Storminator16
DCEmu Veteran
DCEmu Veteran
Posts: 850
Joined: Mon Sep 01, 2003 11:12 am
Location: NC/Iraq
Has thanked: 0
Been thanked: 0
Contact:

Post by Storminator16 »

Btw, did anyone try any of the flags Reaper suggested? I tried them all at once and didn't notice any differences or improvements. Maybe I should check one at a time, and try differnt orders.

Btw, good work you guys. I truly love the Genny :D
BlackAura
DC Developer
DC Developer
Posts: 9951
Joined: Sun Dec 30, 2001 9:02 am
Has thanked: 0
Been thanked: 1 time

Post by BlackAura »

Alright, I'm going to bed now (it's 3AM, so...)

Here's what I've done:

Fixed 32-cell mode (it's not full screen, but it's centered and there's no garbage on the screen anymore)
Drawn window borders
Added (crappy) windowing emulation
A load of tweaks here and there

Stuff that still needs doing soon-ish:
xrender_draw_ntx and xrender_draw_ntw need some speedups
Twiddling code needs to be rewritten to use store queues
Change the CPU core to Stef's C68K emulator
Integrate Speud's menu
Better controller interface
That weird sprite corruption thing needs fixing

For the menu, the menu code should be in a separate file. My current codebase has a file for it (menu.c), but no menu as yet. The codebase also doesn't support switching resolution on the fly, so that might need to be taken out.

For the controller interface, we should integrate ice88's modifications, but with a couple of differences. First, we should re-scan the maple bus periodically, so we can see if someone's plugged in / removed a controller. Second, that information should be passed to the MegaDrive. In main.c there's a bit that calls io_rescan (see io.c), and that's how you connect devices to the MD's controller ports.

If anyone else wants to do some hacking on the VDP core itself, feel free. I've been mostly using this document (which was written by Charles MacDonald, who also wrote Genesis Plus) and the GenPlus software VDP for reference.
sonic 2: in 2players mode the screen is a real garbage
Needs interlaced video mode. As far as I know, this is the only game that uses it...
shining force and zombie ate my neighbours: the screen is not centered properly, its "pushed" to the left and the right side is displaying some "unused" sprites.
32-cell mode. Kinda fixed (it's now centered and no garbage displayed on screen). Ideally, it'd be stretched to full screen, but it isn't yet.
outrun: the multidirectionnal scrolling doesnt seem to work properly in this game, the road is barely visible.
afterburner: on the horizon this makes a "stairs" effect instead of a diagonal line, depending on how much you rotate the plane.
Needs scanline-accurate renderer, which this isn't. Road Rash or similar games will be just as bad.
aladdin and cool spot (probably other virgin games as well): the hero's sprite is a bit more buggy than in other games.
This is the buggy sprite thing again. I know exactly why this is happening, but I can't fix it yet.
BlackAura
DC Developer
DC Developer
Posts: 9951
Joined: Sun Dec 30, 2001 9:02 am
Has thanked: 0
Been thanked: 1 time

Post by BlackAura »

After much trouble trying to upload this thing (files.frashii.com isn't working properly, my university's authentication server appears to be down...), and having it dribble up at 1K/s...

http://files.frashii.com/~sp00nz/Doom/f ... -2.tar.bz2
Warmtoe
DC Developer
DC Developer
Posts: 453
Joined: Thu May 16, 2002 8:29 am
Location: ice88's house
Has thanked: 0
Been thanked: 0
Contact:

Post by Warmtoe »

Didn't get as much done as I'd hoped to tonight - but I did manage to split the menu out to menu.c / menu.h - improved the controls in the menu (repeat) - re-introduced a couple of speedups that were not there - and some other stuff.

The result is actually pretty damned good!

Anyway - this applies as a delta on-top of gpdc-pvr-2.tar.bz2 to give you what I currently have...

http://homepage.ntlworld.com/ian_edward ... armtoe.zip

I must change my nick back to warmtoe some time - warmtoe is the name!
speud
DCEmu Uncool Newbie
DCEmu Uncool Newbie
Posts: 1459
Joined: Sat Dec 27, 2003 10:40 pm
Has thanked: 0
Been thanked: 0
Contact:

Post by speud »

argh thats what i did too ^^;
nevermind, you did a better job and thats not like i worked hard on it anyway.

btw, i dont know yet if thats because of something i changed in the source (i dont think so) but it looks slower now. sonic 1 is not as smooth as before and sonic 2 is really slow sometimes.
besides shining force 2 freezes after the sega logo and shining force 1 exits the app at the same moment.
zombies' bug has been partially fixed, the main screen is centered correctly, but when the game starts the screen goes back to the left and there is some unwanted sprites hiding the center of the screen.

will i tried to replace snd_stream_shutdown() with one of the functions you pointed and the compiler told me about implicit declaration, i never had any problem with snd_stream_shutdown() personnally.
http://blueswirl.fr.st - DC Online Tools and Downloads

thx to Wack0 for the avatar ;)
Storminator16
DCEmu Veteran
DCEmu Veteran
Posts: 850
Joined: Mon Sep 01, 2003 11:12 am
Location: NC/Iraq
Has thanked: 0
Been thanked: 0
Contact:

Post by Storminator16 »

Ah, yeah, Warmtoe change change his code to "gpdc" to all of the snd_stream stuff becuase he was getting errors because of the functions already defined in KOS, so that's what I've been using because I was getting the same thing. Dunno if it still in his current source but use 'gpdc_snd_stream_clear' or if you don't have this problem use 'snd_stream_clear' as defined in snd_stream.h.

I added the earlier code of Blackaura's to the mess I have and I must say the fixes were excellent. I'll add Warmtoe's new stuff and I'm trying to get uncompressed saves working, then I'll try to work on compressed saves :)

EDIT: Btw, I am using an SVN version of KOS from last month. Might be a version issue with the snd_stream, eh?
Last edited by Storminator16 on Wed Jun 23, 2004 5:54 pm, edited 1 time in total.
DcSteve
Modder Of Rage
Modder Of Rage
Posts: 805
Joined: Mon Mar 18, 2002 12:41 pm
Location: Midwest
Has thanked: 0
Been thanked: 0
Contact:

Post by DcSteve »

ice-. so now the games always run 100% without sound or 95-100, as opposed to 90-100? Anyhow, i would appreciate it if someone compiled a binary of this ..
speud
DCEmu Uncool Newbie
DCEmu Uncool Newbie
Posts: 1459
Joined: Sat Dec 27, 2003 10:40 pm
Has thanked: 0
Been thanked: 0
Contact:

Post by speud »

nevermind that was probably something i changed in dc_options by accident, i just tried blackaura's latest release without menu and its as fast as before (maybe faster but i cant see the difference for now).

so warmtoe did you use this source or did you make your own changes? i like the improvements you made to the menu, though i think the controls are too fast, luckily the delay is easy to change.

will i think warmtoe's release uses gpdc_snd_stream_shutdown(), i think i saw the implicit declaration warning while compiling, but it looks like its not causing any trouble.
http://blueswirl.fr.st - DC Online Tools and Downloads

thx to Wack0 for the avatar ;)
Storminator16
DCEmu Veteran
DCEmu Veteran
Posts: 850
Joined: Mon Sep 01, 2003 11:12 am
Location: NC/Iraq
Has thanked: 0
Been thanked: 0
Contact:

Post by Storminator16 »

Hmmm, snd_stream_shutdown doesn't work for me at all. So, you don't have a problem playing 2 games back to back with sound enabled? This was the problem I was having before I changed it: when I quit a rom the sound continues to play.
User avatar
Christuserloeser
Moderator
Moderator
Posts: 5948
Joined: Thu Aug 28, 2003 12:16 am
Location: DCEvolution.net
Has thanked: 10 times
Been thanked: 0
Contact:

Post by Christuserloeser »

BlackAura wrote:Here's what I've done:

Fixed 32-cell mode (it's not full screen, but it's centered and there's no garbage on the screen anymore)
Drawn window borders
Added (crappy) windowing emulation
A load of tweaks here and there

sonic 2: in 2players mode the screen is a real garbage
Needs interlaced video mode. As far as I know, this is the only game that uses it...
You might be correct but not sure with that... I'll check other games!
Possible: Wiz'n'Liz ... no! It's common res like Sonic3's vs mode

I know: Dashin' Desperados by Data East! There aren't many that's for sure. These ones didn't work with SegaGen either.
BlackAura wrote:
outrun: the multidirectionnal scrolling doesnt seem to work properly in this game, the road is barely visible.
afterburner: on the horizon this makes a "stairs" effect instead of a diagonal line, depending on how much you rotate the plane.
Needs scanline-accurate renderer, which this isn't. Road Rash or similar games will be just as bad.
I bet. Now this sounds like SegaGen :) Unbelievable that you achieved the same level! ...and they had better equipment and were paid for their work :o

I've started a bug report today, lots of games tested but most bugs I've recognized are already fixed now like you've mentioned above :) Have a look though maybe it still helps in some ways?

http://www.dcemu.co.uk/cgi-bin/yabb/YaB ... 1088028089

I'll finish that list today but I'll test that Street Fighter thing tomorrow (don't have it on my current test disc.

@ Ice88: Yes, change it back to Warmtoe! Cool name that is...


*currently listens to: Gens (Win32) - Mega Turrican (C. H?lsbeck)*
Insane homebrew collector.
speud
DCEmu Uncool Newbie
DCEmu Uncool Newbie
Posts: 1459
Joined: Sat Dec 27, 2003 10:40 pm
Has thanked: 0
Been thanked: 0
Contact:

Post by speud »

hmmm thats not really a good idea to compare it with segagen to me :? the goal is to avoid mentioning it in the future if im not wrong.

will yes when i went back to the menu the sound was stopped, first it wasnt thats why i added snd_stream_shutdown(), that solved the problem for me. i used kos-1.2.0 so that might be the problem.
http://blueswirl.fr.st - DC Online Tools and Downloads

thx to Wack0 for the avatar ;)
BlackAura
DC Developer
DC Developer
Posts: 9951
Joined: Sun Dec 30, 2001 9:02 am
Has thanked: 0
Been thanked: 1 time

Post by BlackAura »

Well... it does have a few similarities to the Smash Pack, actually. Obviously not as "finished" yet, but it's progressing a hell of a lot faster than I thought it would. Give it a couple of weeks, and we'll never need to mention it again. I hope.

warmtoe - Thanks! I'll grab your code, and have a look at it.
Ian Micheal
Soul Sold for DCEmu
Soul Sold for DCEmu
Posts: 4865
Joined: Fri Jul 11, 2003 9:56 pm
Has thanked: 2 times
Been thanked: 4 times

Post by Ian Micheal »

Compiler flags will have little effect when most of the bottle neck has been removed. Try compiling the cpu core at -02 since -03 will make it slower.

Standard version will show more speed change then this version with compiler settings.

-02 might be faster on this code looking at it.
Last edited by Ian Micheal on Wed Jun 23, 2004 8:31 pm, edited 1 time in total.
Dreamcast forever!!!
Post Reply