Successfully flipped the screen!
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.