rehabilitate the GB core: fix videoprovider and input system

This commit is contained in:
zeromus 2012-05-18 18:28:12 +00:00
parent 9c5f56308b
commit 42715fdca7
4 changed files with 59 additions and 38 deletions

View File

@ -4,7 +4,7 @@ using BizHawk.Emulation.CPUs.Z80GB;
namespace BizHawk.Emulation.Consoles.Gameboy
{
public partial class Gameboy : IEmulator
public partial class Gameboy : IEmulator, IVideoProvider
{
private int _lagcount = 0;
@ -703,17 +703,16 @@ namespace BizHawk.Emulation.Consoles.Gameboy
public void FrameAdvance(bool render)
{
lagged = true;
Controller.UpdateControls(Frame++);
Cpu.ExecuteCycles(4096);
if (lagged)
//40960 is not the right number.
for (int i = 0; i < 40960; i++)
{
_lagcount++;
islag = true;
SingleStepInto();
}
else
islag = false;
//to make sure input is working
Console.WriteLine(Controller.IsPressed("Up"));
}
public CoreInputComm CoreInputComm { get; set; }
@ -721,9 +720,35 @@ namespace BizHawk.Emulation.Consoles.Gameboy
public IVideoProvider VideoProvider
{
get { return new NullEmulator(); }
get { return this; }
}
public int[] GetVideoBuffer()
{
//TODO - these need to be run once per scanline and accumulated into a 160*144 byte buffer held by the core
//then, in the call to GetVideoBuffer(), it gets adapted to gray according to the palette and returned
//(i.e. no real GB logic happens during GetVideoBuffer())
int[] buf = new int[160 * 144];
var linebuf = new byte[160];
int i = 0;
for (int y = 0; y < 144; y++)
{
RenderBGLine(y, linebuf, true);
RenderOBJLine(y, linebuf, true);
for (int x = 0; x < 160; x++)
{
int gray = linebuf[x]<<6;
gray |= (gray << 8) | (gray << 16);
buf[i++] = unchecked(gray | (int)0xFF000000);
}
}
return buf;
}
public int BufferWidth { get { return 160; } }
public int BufferHeight { get { return 144; } }
public int BackgroundColor { get { return 0; } }
public ISoundProvider SoundProvider
{
get { return new NullEmulator(); }

View File

@ -17,7 +17,8 @@ namespace BizHawk.MultiClient
NESController[1] = new NESControllerTemplate(false);
NESController[2] = new NESControllerTemplate(false);
NESController[3] = new NESControllerTemplate(false);
GameBoyController = new NESControllerTemplate(true);
GBController[0] = new GBControllerTemplate(true);
GBAutoController[0] = new GBControllerTemplate(true);
TI83Controller[0] = new TI83ControllerTemplate(true);
GenesisController[0] = new GenControllerTemplate(true);
@ -43,7 +44,6 @@ namespace BizHawk.MultiClient
PCEAutoController[3] = new PCEControllerTemplate(false);
PCEAutoController[4] = new PCEControllerTemplate(false);
GameBoyAutoController = new NESControllerTemplate(false);
ColecoController = new ColecoVisionControllerTemplate(true);
}
@ -503,10 +503,6 @@ namespace BizHawk.MultiClient
//ColecoVision
public ColecoVisionControllerTemplate ColecoController = new ColecoVisionControllerTemplate(true);
//GameBoy Settings
public NESControllerTemplate GameBoyController = new NESControllerTemplate(true);
public NESControllerTemplate GameBoyAutoController = new NESControllerTemplate();
//NES settings
//public string NESReset = "Backspace";
public NESControllerTemplate[] NESController = new NESControllerTemplate[4];
@ -516,8 +512,8 @@ namespace BizHawk.MultiClient
public TI83ControllerTemplate[] TI83Controller = new TI83ControllerTemplate[1];
//GB settings
public GBControllerTemplate GBController = new GBControllerTemplate();
public GBControllerTemplate GBAutoController = new GBControllerTemplate();
public GBControllerTemplate[] GBController = new GBControllerTemplate[1];
public GBControllerTemplate[] GBAutoController = new GBControllerTemplate[1];
//GIF Animator Settings
public int GifAnimatorNumFrames;

View File

@ -678,26 +678,26 @@ namespace BizHawk.MultiClient
Global.AutofireNESControls = anesControls;
var gbControls = new Controller(Gameboy.GbController);
gbControls.BindMulti("Up", Global.Config.GBController.Up);
gbControls.BindMulti("Down", Global.Config.GBController.Down);
gbControls.BindMulti("Left", Global.Config.GBController.Left);
gbControls.BindMulti("Right", Global.Config.GBController.Right);
gbControls.BindMulti("A", Global.Config.GBController.A);
gbControls.BindMulti("B", Global.Config.GBController.B);
gbControls.BindMulti("Select", Global.Config.GBController.Select);
gbControls.BindMulti("Start", Global.Config.GBController.Start);
gbControls.BindMulti("Up", Global.Config.GBController[0].Up);
gbControls.BindMulti("Down", Global.Config.GBController[0].Down);
gbControls.BindMulti("Left", Global.Config.GBController[0].Left);
gbControls.BindMulti("Right", Global.Config.GBController[0].Right);
gbControls.BindMulti("A", Global.Config.GBController[0].A);
gbControls.BindMulti("B", Global.Config.GBController[0].B);
gbControls.BindMulti("Select", Global.Config.GBController[0].Select);
gbControls.BindMulti("Start", Global.Config.GBController[0].Start);
Global.GBControls = gbControls;
var agbControls = new AutofireController(Gameboy.GbController);
agbControls.Autofire = true;
agbControls.BindMulti("Up", Global.Config.GBAutoController.Up);
agbControls.BindMulti("Down", Global.Config.GBAutoController.Down);
agbControls.BindMulti("Left", Global.Config.GBAutoController.Left);
agbControls.BindMulti("Right", Global.Config.GBAutoController.Right);
agbControls.BindMulti("A", Global.Config.GBAutoController.A);
agbControls.BindMulti("B", Global.Config.GBAutoController.B);
agbControls.BindMulti("Select", Global.Config.GBAutoController.Select);
agbControls.BindMulti("Start", Global.Config.GBAutoController.Start);
agbControls.BindMulti("Up", Global.Config.GBAutoController[0].Up);
agbControls.BindMulti("Down", Global.Config.GBAutoController[0].Down);
agbControls.BindMulti("Left", Global.Config.GBAutoController[0].Left);
agbControls.BindMulti("Right", Global.Config.GBAutoController[0].Right);
agbControls.BindMulti("A", Global.Config.GBAutoController[0].A);
agbControls.BindMulti("B", Global.Config.GBAutoController[0].B);
agbControls.BindMulti("Select", Global.Config.GBAutoController[0].Select);
agbControls.BindMulti("Start", Global.Config.GBAutoController[0].Start);
Global.AutofireGBControls = agbControls;
var genControls = new Controller(Genesis.GenesisController);

View File

@ -103,8 +103,8 @@ namespace BizHawk.MultiClient
break;
case "Gameboy":
ControllerImage.Image = BizHawk.MultiClient.Properties.Resources.GBController;
controller = new NESControllerTemplate[1] { Global.Config.GameBoyController };
autoController = new NESControllerTemplate[1] { Global.Config.GameBoyAutoController };
controller = Global.Config.GBController;
autoController = Global.Config.GBAutoController;
break;
case "NES":
ControllerImage.Image = BizHawk.MultiClient.Properties.Resources.NESController;
@ -275,8 +275,8 @@ namespace BizHawk.MultiClient
autoController = Global.Config.Atari2600AutoController;
break;
case "Gameboy":
controller = new NESControllerTemplate[1] { Global.Config.GameBoyController };
autoController = new NESControllerTemplate[1] { Global.Config.GameBoyAutoController };
controller = Global.Config.GBController;
autoController = Global.Config.GBAutoController;
break;
case "NES":
controller = Global.Config.NESController;