Flipping screen in emulator

The Uzebox now have a fully functional emulator! Download and discuss it here.
Post Reply
User avatar
DaveyPocket
Posts: 378
Joined: Sun Sep 14, 2008 8:33 pm
Contact:

Flipping screen in emulator

Post by DaveyPocket »

I'm modifying the source code for the Uzebox emulator in an attempt to flip the orientation of the screen in the emulator window. I need it for testing a game I am writing for the Uzebox JAMMA. The game will be vertically oriented. Normally how I test development is by flipping the TV sideways. I wish to test on computer but I don't want to flip my entire laptop sideways :lol:

From what I was observing in code, I believe this has something to do with drawing pixels on the SDL layer:

Code: Select all

while (cycles)
		{
			if (current_cycle >= 0 && current_cycle < 1440 && (current_cycle&1)){ //1440
               		current_scanline[current_cycle>>1] = pixel;
				next_scanline[current_cycle>>1] = pixel; 
            }
			++current_cycle;
			--cycles;
		}
I'm not quite sure how to get the code to scan the vertically instead of horizontally. Maybe someone who knows better could help? I know that current_scanline is a pointer to an address in memory (the SDL screen layer) but I'm not quite sure how to get it scanning in another direction.
User avatar
uze6666
Site Admin
Posts: 4801
Joined: Tue Aug 12, 2008 9:13 pm
Location: Montreal, Canada
Contact:

Re: Flipping screen in emulator

Post by uze6666 »

Not so sure how to do that either, but if you find out, a vertical mode would be a nice option for uzem! :)
User avatar
DaveyPocket
Posts: 378
Joined: Sun Sep 14, 2008 8:33 pm
Contact:

Re: Flipping screen in emulator

Post by DaveyPocket »

Progress over time:

Image
Image
Image
Image

Just need to fix two more problems then it's good to go!
User avatar
D3thAdd3r
Posts: 3221
Joined: Wed Apr 29, 2009 10:00 am
Location: Minneapolis, United States

Re: Flipping screen in emulator

Post by D3thAdd3r »

Nice work!
User avatar
uze6666
Site Admin
Posts: 4801
Joined: Tue Aug 12, 2008 9:13 pm
Location: Montreal, Canada
Contact:

Re: Flipping screen in emulator

Post by uze6666 »

You're the man! :D
User avatar
DaveyPocket
Posts: 378
Joined: Sun Sep 14, 2008 8:33 pm
Contact:

Re: Flipping screen in emulator

Post by DaveyPocket »

Successfully flipped the screen! :D

Image

Changes in code:

Replace this:

Code: Select all

++scanline_count;
            current_cycle = left_edge;

            current_scanline = (u32*)((u8*)screen->pixels + scanline_count * 2 * screen->pitch + inset);
            if (interlaced)
            {
                if (frameCounter & 1)
                    current_scanline += (screen->pitch>>2);
                next_scanline = current_scanline;
            }
            else
                next_scanline = current_scanline + (screen->pitch>>2);

            if (scanline_count == 224) 
            {
                if (SDL_MUSTLOCK(screen))
                    SDL_UnlockSurface(screen);
                if (frameCounter & 1)
                    SDL_Flip(screen);
With this:

Code: Select all

--scanline_count;
            current_cycle = left_edge;
            current_scanline = (u32*)((u8*)screen->pixels);
            if(scanline_count > 0)
                current_scanline = (u32*)(current_scanline + (scanline_count<<1)-1);
            if (interlaced)
            {
                if (frameCounter & 1)
                    current_scanline += (screen->pitch>>2);
                next_scanline = current_scanline;
            }
            else if(scanline_count > 0)
                next_scanline = (u32*)(current_scanline - 1);
            

            if (scanline_count == 0)
            {
                if (SDL_MUSTLOCK(screen))
                    SDL_UnlockSurface(screen);
                if (frameCounter & 1)
                    SDL_Flip(screen);
Replace this:

Code: Select all

if (scanline_count >= 0 && current_cycle < 1440)
	{
		while (cycles)
		{
			if (current_cycle >= 0 && current_cycle < 1440 && (current_cycle&1))
				current_scanline[current_cycle>>1] = 
				next_scanline[current_cycle>>1] = pixel;
			++current_cycle;
			--cycles;
		}
	}
With this:

Code: Select all

if (scanline_count >= 0 && current_cycle < 1440) //This needs ot be kept at 1440 so the cycles are done correctly
	{
		while (cycles)
		{
			if (current_cycle >= 0 && current_cycle < 1439 && current_cycle&1){
                current_scanline[current_cycle*(screen->pitch/8)-224] = pixel;
                next_scanline[current_cycle*(screen->pitch/8)-224] = pixel;
            }
			++current_cycle;
			--cycles;
		}
	}
Replace this:

Code: Select all

current_cycle = -999999;
	scanline_top = -33;
	scanline_count = -999;
	//Syncronized with the kernel, this value now results in the image 
	//being perfectly centered in both the emulator and a real TV
	left_edge = -166;
With this:

Code: Select all

current_cycle = -999999;
	scanline_top = 257;
	scanline_count = -999;
	//Syncronized with the kernel, this value now results in the image
	//being perfectly centered in both the emulator and a real TV
	left_edge = -167;
Attached is the avr8.cpp file. Backup existing avr8.cpp, replace with this, then compile. Run emulator and the screen should be flipped! If the screen doesn't load, something is wrong with the code.

Note: I did not modify code to work with full screen mode or interlaced mode. I can guarantee these modes will not work.
Attachments
avr8.cpp.zip
(20.5 KiB) Downloaded 553 times
User avatar
D3thAdd3r
Posts: 3221
Joined: Wed Apr 29, 2009 10:00 am
Location: Minneapolis, United States

Re: Flipping screen in emulator

Post by D3thAdd3r »

In the screen shot I noticed your mac uzem is running at 50.301 mhz, is the timing still working ok with different roms? Mine only goes above 28.x when I try to work on a video mode :lol: Anyways you could set it up as a command line switch and it could be a standard option for uzem. I'm sure it would be useful for people doing UJAMMA development.
User avatar
uze6666
Site Admin
Posts: 4801
Joined: Tue Aug 12, 2008 9:13 pm
Location: Montreal, Canada
Contact:

Re: Flipping screen in emulator

Post by uze6666 »

Awesome! Have to add this to the todo list and have a switch on Uzem or a flag in the UZM file to indicate screen should be rotated.
User avatar
DaveyPocket
Posts: 378
Joined: Sun Sep 14, 2008 8:33 pm
Contact:

Re: Flipping screen in emulator

Post by DaveyPocket »

D3thAdd3r wrote:In the screen shot I noticed your mac uzem is running at 50.301 mhz, is the timing still working ok with different roms? Mine only goes above 28.x when I try to work on a video mode :lol: Anyways you could set it up as a command line switch and it could be a standard option for uzem. I'm sure it would be useful for people doing UJAMMA development.
I disabled audio by using -n on startup. This causes the frequency and framerate to go out of control because the framelock relies on sound generation.
User avatar
D3thAdd3r
Posts: 3221
Joined: Wed Apr 29, 2009 10:00 am
Location: Minneapolis, United States

Re: Flipping screen in emulator

Post by D3thAdd3r »

I really wanted to be able to play Smokey and the Bandit in emulation. The code changed quite a bit since 2012 and the code above was not a direct plugin, and apparently didn't work fullscreen?

EDIT:
a flexible solution has been created including automatic .uze file triggering of behavior. Moved to a separate topic here
Last edited by D3thAdd3r on Tue Nov 14, 2023 3:37 pm, edited 1 time in total.
Post Reply