add CoreInputComm/CoreOutputComm, remove Query system, hook up nes video config options

This commit is contained in:
zeromus 2011-06-11 22:15:08 +00:00
parent 11b33fcc33
commit c0988feaa3
18 changed files with 141 additions and 93 deletions

View File

@ -190,6 +190,7 @@
<Compile Include="Interfaces\Base Implementations\NullController.cs" />
<Compile Include="Interfaces\Base Implementations\NullEmulator.cs" />
<Compile Include="Interfaces\Base Implementations\SmdGame.cs" />
<Compile Include="Interfaces\CoreComms.cs" />
<Compile Include="Sound\Utilities\BufferedAsync.cs" />
<Compile Include="Sound\Utilities\Metaspu.cs" />
<Compile Include="Interfaces\IController.cs" />

View File

@ -313,6 +313,7 @@ namespace BizHawk.Emulation.Consoles.Calculator
public TI83()
{
CoreOutputComm = new CoreOutputComm();
cpu.ReadMemory = ReadMemory;
cpu.WriteMemory = WriteMemory;
cpu.ReadHardware = ReadHardware;
@ -333,6 +334,10 @@ namespace BizHawk.Emulation.Consoles.Calculator
cpu.NonMaskableInterrupt = false;
}
public CoreInputComm CoreInputComm { get; set; }
public CoreOutputComm CoreOutputComm { get; private set; }
protected byte[] vram = new byte[0x300];
class MyVideoProvider : IVideoProvider
{
@ -569,12 +574,6 @@ namespace BizHawk.Emulation.Consoles.Calculator
public IList<MemoryDomain> MemoryDomains { get { return memoryDomains; } }
public MemoryDomain MainMemory { get { return memoryDomains[0]; } }
public object Query(EmulatorQuery query)
{
return null;
}
public void Dispose() { }
}
}

View File

@ -262,6 +262,7 @@ namespace BizHawk.Emulation.Consoles.Gameboy
public Gameboy()
{
CoreOutputComm = new CoreOutputComm();
}
public void LoadGame(IGame game)
@ -637,6 +638,10 @@ namespace BizHawk.Emulation.Consoles.Gameboy
//Cpu.ExecuteCycles(4096);
}
public CoreInputComm CoreInputComm { get; set; }
public CoreOutputComm CoreOutputComm { get; private set; }
public IVideoProvider VideoProvider
{
get { return new NullEmulator(); }
@ -850,12 +855,6 @@ namespace BizHawk.Emulation.Consoles.Gameboy
public IList<MemoryDomain> MemoryDomains { get { throw new NotImplementedException(); } }
public MemoryDomain MainMemory { get { throw new NotImplementedException(); } }
public object Query(EmulatorQuery query)
{
return null;
}
public void Dispose() {}
}
}

View File

@ -38,6 +38,7 @@ namespace BizHawk.Emulation.Consoles.Nintendo
public NES()
{
CoreOutputComm = new CoreOutputComm();
BootGodDB.Initialize();
SetPalette(Palettes.FCEUX_Standard);
videoProvider = new MyVideoProvider(this);
@ -126,6 +127,9 @@ namespace BizHawk.Emulation.Consoles.Nintendo
NESWatch[] watches;
}
public CoreInputComm CoreInputComm { get; set; }
public CoreOutputComm CoreOutputComm { get; private set; }
class MyVideoProvider : IVideoProvider
{
NES emu;
@ -137,10 +141,17 @@ namespace BizHawk.Emulation.Consoles.Nintendo
int[] pixels = new int[256 * 240];
public int[] GetVideoBuffer()
{
int backdrop = emu.CoreInputComm.NES_BackdropColor;
bool useBackdrop = (backdrop & 0xFF000000) != 0;
//TODO - we could recalculate this on the fly (and invalidate/recalculate it when the palette is changed)
for (int i = 0; i < 256*240; i++)
{
pixels[i] = emu.palette_compiled[emu.ppu.xbuf[i]];
short pixel = emu.ppu.xbuf[i];
if((pixel&0x8000)!=0 && useBackdrop)
{
pixels[i] = backdrop;
}
else pixels[i] = emu.palette_compiled[pixel&0x7FFF];
}
return pixels;
}
@ -326,12 +337,6 @@ namespace BizHawk.Emulation.Consoles.Nintendo
public IList<MemoryDomain> MemoryDomains { get { return memoryDomains; } }
public MemoryDomain MainMemory { get { return memoryDomains[0]; } }
public object Query(EmulatorQuery query)
{
return null;
}
public string GameName { get { return game_name; } }
public enum EDetectionOrigin

View File

@ -157,8 +157,8 @@ namespace BizHawk.Emulation.Consoles.Nintendo
int rasterpos = xstart;
//check all the conditions that can cause things to render in these 8px
bool renderspritenow = reg_2001.show_obj && (xt > 0 || reg_2001.show_obj_leftmost);
bool renderbgnow = reg_2001.show_bg && (xt > 0 || reg_2001.show_bg_leftmost);
bool renderspritenow = reg_2001.show_obj && (xt > 0 || reg_2001.show_obj_leftmost) && nes.CoreInputComm.NES_ShowOBJ;
bool renderbgnow = reg_2001.show_bg && (xt > 0 || reg_2001.show_bg_leftmost) && nes.CoreInputComm.NES_ShowBG;
for (int xp = 0; xp < 8; xp++, rasterpos++)
{
@ -176,10 +176,15 @@ namespace BizHawk.Emulation.Consoles.Nintendo
byte pt_0 = bgdata[bgtile].pt_0;
byte pt_1 = bgdata[bgtile].pt_1;
pixel = ((pt_0 >> (7 - bgpx)) & 1) | (((pt_1 >> (7 - bgpx)) & 1) << 1);
if(pixel != 0)
pixel |= bgdata[bgtile].at;
if (pixel != 0)
pixel |= bgdata[bgtile].at;
pixelcolor = PALRAM[pixel];
}
else
{
pixelcolor = PALRAM[pixel];
pixelcolor |= 0x8000;
}
pixelcolor = PALRAM[pixel];
//look for a sprite to be drawn
bool havepixel = false;
@ -272,9 +277,12 @@ namespace BizHawk.Emulation.Consoles.Nintendo
//set the flag and bail out.
if (oamcount >= 8 && reg_2001.PPUON)
{
Reg2002_objoverflow = true;
if (SPRITELIMIT)
//should we set this flag anyway??
if (!nes.CoreInputComm.NES_UnlimitedSprites)
{
Reg2002_objoverflow = true;
break;
}
}
//just copy some bytes into the internal sprite buffer

View File

@ -41,6 +41,7 @@ namespace BizHawk.Emulation.Consoles.TurboGrafx
public PCEngine(NecSystemType type)
{
CoreOutputComm = new CoreOutputComm();
Type = type;
Controller = NullController.GetNullController();
Cpu = new HuC6280();
@ -124,6 +125,9 @@ namespace BizHawk.Emulation.Consoles.TurboGrafx
islag = false;
}
public CoreInputComm CoreInputComm { get; set; }
public CoreOutputComm CoreOutputComm { get; private set; }
public IVideoProvider VideoProvider
{
get { return (IVideoProvider) VPC ?? VDC1; }
@ -298,17 +302,6 @@ namespace BizHawk.Emulation.Consoles.TurboGrafx
public IList<MemoryDomain> MemoryDomains { get { return memoryDomains; } }
public MemoryDomain MainMemory { get { return memoryDomains[0]; } }
public object Query(EmulatorQuery query)
{
switch (query)
{
case EmulatorQuery.VsyncRate:
return 60.0;
default:
return null;
}
}
public void Dispose() {}
}
}

View File

@ -52,6 +52,8 @@ namespace BizHawk.Emulation.Consoles.Sega
public Genesis(bool sega360)
{
CoreOutputComm = new CoreOutputComm();
if (sega360) MainCPU = new MC68K(this);
_MainCPU = new M68000();
SoundCPU = new Z80A();
@ -127,9 +129,14 @@ namespace BizHawk.Emulation.Consoles.Sega
}
}
PSG.EndFrame(SoundCPU.TotalExecutedCycles);
}
}
public IVideoProvider VideoProvider
public CoreInputComm CoreInputComm { get; set; }
public CoreOutputComm CoreOutputComm { get; private set; }
public IVideoProvider VideoProvider
{
get { return VDP; }
}
@ -191,11 +198,6 @@ namespace BizHawk.Emulation.Consoles.Sega
public MemoryDomain MainMemory { get { throw new NotImplementedException(); } }
public object Query(EmulatorQuery query)
{
return null;
}
public void Dispose() {}
}
}

View File

@ -58,6 +58,11 @@ namespace BizHawk.Emulation.Consoles.Sega
public DisplayType DisplayType { get; set; }
public bool DeterministicEmulation { get; set; }
public SMS()
{
CoreOutputComm = new CoreOutputComm();
}
public void Init()
{
if (Controller == null)
@ -111,6 +116,7 @@ namespace BizHawk.Emulation.Consoles.Sega
RomBanks = (byte)(RomData.Length/BankSize);
Options = game.GetOptions();
DisplayType = DisplayType.NTSC;
CoreOutputComm.VsyncRate = DisplayType == DisplayType.NTSC ? 60d : 50d;
foreach (string option in Options)
{
var args = option.Split('=');
@ -324,6 +330,8 @@ namespace BizHawk.Emulation.Consoles.Sega
}
public IVideoProvider VideoProvider { get { return Vdp; } }
public CoreInputComm CoreInputComm { get; set; }
public CoreOutputComm CoreOutputComm { get; private set; }
private ISoundProvider ActiveSoundProvider;
public ISoundProvider SoundProvider { get { return ActiveSoundProvider; } }
@ -372,14 +380,6 @@ namespace BizHawk.Emulation.Consoles.Sega
public IList<MemoryDomain> MemoryDomains { get { return memoryDomains; } }
public MemoryDomain MainMemory { get { return memoryDomains[0]; } }
// TODO I have concerns about this .Query thing- at least for target fps, but I leave it for now
public object Query(EmulatorQuery query)
{
if (query == EmulatorQuery.VsyncRate)
return DisplayType == DisplayType.NTSC ? 60d : 50d;
return null;
}
public void Dispose() {}
}
}

View File

@ -11,6 +11,8 @@ namespace BizHawk
private int[] frameBuffer = new int[256 * 192];
private Random rand = new Random();
public CoreInputComm CoreInputComm { get; set; }
public CoreOutputComm CoreOutputComm { get; private set; }
public IVideoProvider VideoProvider { get { return this; } }
public ISoundProvider SoundProvider { get { return this; } }
public NullEmulator()
@ -51,10 +53,6 @@ namespace BizHawk
public IList<MemoryDomain> MemoryDomains { get { return memoryDomains; } }
public MemoryDomain MainMemory { get { return memoryDomains[0]; } }
public void Dispose() { }
public object Query(EmulatorQuery query)
{
return null;
}
}
public class NullSound : ISoundProvider

View File

@ -0,0 +1,17 @@
using System.Collections.Generic;
namespace BizHawk
{
public class CoreInputComm
{
public int NES_BackdropColor;
public bool NES_UnlimitedSprites;
public bool NES_ShowBG, NES_ShowOBJ;
}
public class CoreOutputComm
{
public double VsyncRate = 60;
}
}

View File

@ -33,8 +33,9 @@ namespace BizHawk
void LoadStateBinary(BinaryReader reader);
byte[] SaveStateBinary();
//arbitrary extensible query mechanism
object Query(EmulatorQuery query);
//arbitrary extensible core comm mechanism
CoreInputComm CoreInputComm { get; set; }
CoreOutputComm CoreOutputComm { get; }
// ----- Client Debugging API stuff -----
IList<MemoryDomain> MemoryDomains { get; }
@ -100,9 +101,4 @@ namespace BizHawk
public enum Endian { Big, Little, Unknown }
public enum DisplayType { NTSC, PAL }
public enum EmulatorQuery
{
VsyncRate
}
}

View File

@ -12,6 +12,7 @@ namespace BizHawk.MultiClient
public static IRenderer RenderPanel;
public static Config Config;
public static IEmulator Emulator;
public static CoreInputComm CoreInputComm;
public static RomGame Game;
public static Controller ClientControls;
public static Controller SMSControls;

View File

@ -705,6 +705,7 @@ namespace BizHawk.MultiClient
{
NESGraphicsConfig g = new NESGraphicsConfig();
g.ShowDialog();
SyncCoreInputComm();
}
}
}

View File

@ -77,6 +77,8 @@ namespace BizHawk.MultiClient
return Util.ReadAllBytes(NesCartFile.GetStream());
};
Global.MainForm = this;
Global.CoreInputComm = new CoreInputComm();
SyncCoreInputComm();
Database.LoadDatabase(PathManager.GetExePathAbsolute() + "\\gamedb.txt");
@ -214,6 +216,14 @@ namespace BizHawk.MultiClient
InputLog = new Movie(PathManager.MakeAbsolutePath(Global.Config.MoviesPath, "") + "\\log.tas", m);
}
void SyncCoreInputComm()
{
Global.CoreInputComm.NES_BackdropColor = Global.Config.NESBackgroundColor;
Global.CoreInputComm.NES_UnlimitedSprites = Global.Config.NESAllowMoreThanEightSprites;
Global.CoreInputComm.NES_ShowBG = Global.Config.NESDispBackground;
Global.CoreInputComm.NES_ShowOBJ = Global.Config.NESDispSprites;
}
void SyncPresentationMode()
{
bool gdi = Global.Config.ForceGDI;
@ -786,6 +796,7 @@ namespace BizHawk.MultiClient
try
{
nextEmulator.CoreInputComm = Global.CoreInputComm;
nextEmulator.LoadGame(game);
}
catch (Exception ex)
@ -825,10 +836,7 @@ namespace BizHawk.MultiClient
//setup the throttle based on platform's specifications
//(one day later for some systems we will need to modify it at runtime as the display mode changes)
{
object o = Global.Emulator.Query(EmulatorQuery.VsyncRate);
if (o is double)
throttle.SetCoreFps((double)o);
else throttle.SetCoreFps(60);
throttle.SetCoreFps( Global.Emulator.CoreOutputComm.VsyncRate);
SyncThrottle();
}
RamSearch1.Restart();
@ -1931,7 +1939,7 @@ namespace BizHawk.MultiClient
private void loadConfigToolStripMenuItem_Click(object sender, EventArgs e)
{
Global.Config = ConfigService.Load<Config>("config.ini");
Global.Config = ConfigService.Load<Config>(PathManager.DefaultIniPath);
Global.RenderPanel.AddMessage("Saved loaded");
}
@ -1953,7 +1961,7 @@ namespace BizHawk.MultiClient
RamSearch1.SaveConfigSettings();
if (!HexEditor1.IsDisposed)
HexEditor1.SaveConfigSettings();
ConfigService.Save("config.ini", Global.Config);
ConfigService.Save(PathManager.DefaultIniPath, Global.Config);
}
private void PreviousSlot()

View File

@ -41,13 +41,13 @@
this.groupBox3 = new System.Windows.Forms.GroupBox();
this.ChangeBGColor = new System.Windows.Forms.Button();
this.BackGroundColorNumber = new System.Windows.Forms.TextBox();
this.label3 = new System.Windows.Forms.Label();
this.label2 = new System.Windows.Forms.Label();
this.groupBox4 = new System.Windows.Forms.GroupBox();
this.BackgroundColorPanel = new System.Windows.Forms.Panel();
this.DispBackground = new System.Windows.Forms.CheckBox();
this.DispSprites = new System.Windows.Forms.CheckBox();
this.BGColorDialog = new System.Windows.Forms.ColorDialog();
this.checkUseBackdropColor = new System.Windows.Forms.CheckBox();
this.groupBox1.SuspendLayout();
this.groupBox2.SuspendLayout();
this.groupBox3.SuspendLayout();
@ -157,6 +157,7 @@
// ClipLeftAndRightCheckBox
//
this.ClipLeftAndRightCheckBox.AutoSize = true;
this.ClipLeftAndRightCheckBox.Enabled = false;
this.ClipLeftAndRightCheckBox.Location = new System.Drawing.Point(9, 42);
this.ClipLeftAndRightCheckBox.Name = "ClipLeftAndRightCheckBox";
this.ClipLeftAndRightCheckBox.Size = new System.Drawing.Size(186, 17);
@ -168,9 +169,9 @@
//
this.groupBox3.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.groupBox3.Controls.Add(this.checkUseBackdropColor);
this.groupBox3.Controls.Add(this.ChangeBGColor);
this.groupBox3.Controls.Add(this.BackGroundColorNumber);
this.groupBox3.Controls.Add(this.label3);
this.groupBox3.Controls.Add(this.label2);
this.groupBox3.Controls.Add(this.groupBox4);
this.groupBox3.Controls.Add(this.DispBackground);
@ -180,11 +181,11 @@
this.groupBox3.Size = new System.Drawing.Size(352, 128);
this.groupBox3.TabIndex = 5;
this.groupBox3.TabStop = false;
this.groupBox3.Text = "Background and Sprites";
this.groupBox3.Text = "BG and Sprites";
//
// ChangeBGColor
//
this.ChangeBGColor.Location = new System.Drawing.Point(136, 98);
this.ChangeBGColor.Location = new System.Drawing.Point(112, 98);
this.ChangeBGColor.Name = "ChangeBGColor";
this.ChangeBGColor.Size = new System.Drawing.Size(52, 23);
this.ChangeBGColor.TabIndex = 35;
@ -194,30 +195,21 @@
//
// BackGroundColorNumber
//
this.BackGroundColorNumber.Location = new System.Drawing.Point(62, 100);
this.BackGroundColorNumber.Location = new System.Drawing.Point(47, 100);
this.BackGroundColorNumber.MaxLength = 8;
this.BackGroundColorNumber.Name = "BackGroundColorNumber";
this.BackGroundColorNumber.ReadOnly = true;
this.BackGroundColorNumber.Size = new System.Drawing.Size(59, 20);
this.BackGroundColorNumber.TabIndex = 5;
//
// label3
//
this.label3.AutoSize = true;
this.label3.Location = new System.Drawing.Point(43, 102);
this.label3.Name = "label3";
this.label3.Size = new System.Drawing.Size(18, 13);
this.label3.TabIndex = 4;
this.label3.Text = "0x";
//
// label2
//
this.label2.AutoSize = true;
this.label2.Location = new System.Drawing.Point(9, 79);
this.label2.Name = "label2";
this.label2.Size = new System.Drawing.Size(246, 13);
this.label2.Size = new System.Drawing.Size(178, 13);
this.label2.TabIndex = 3;
this.label2.Text = "Background color when Backgrounds are disabled";
this.label2.Text = "Backdrop color when BG is disabled";
//
// groupBox4
//
@ -242,9 +234,9 @@
this.DispBackground.CheckState = System.Windows.Forms.CheckState.Checked;
this.DispBackground.Location = new System.Drawing.Point(9, 42);
this.DispBackground.Name = "DispBackground";
this.DispBackground.Size = new System.Drawing.Size(121, 17);
this.DispBackground.Size = new System.Drawing.Size(78, 17);
this.DispBackground.TabIndex = 30;
this.DispBackground.Text = "Display Background";
this.DispBackground.Text = "Display BG";
this.DispBackground.UseVisualStyleBackColor = true;
//
// DispSprites
@ -259,6 +251,18 @@
this.DispSprites.Text = "Display Sprites";
this.DispSprites.UseVisualStyleBackColor = true;
//
// checkUseBackdropColor
//
this.checkUseBackdropColor.AutoSize = true;
this.checkUseBackdropColor.Checked = true;
this.checkUseBackdropColor.CheckState = System.Windows.Forms.CheckState.Checked;
this.checkUseBackdropColor.Location = new System.Drawing.Point(170, 100);
this.checkUseBackdropColor.Name = "checkUseBackdropColor";
this.checkUseBackdropColor.Size = new System.Drawing.Size(59, 17);
this.checkUseBackdropColor.TabIndex = 36;
this.checkUseBackdropColor.Text = "Enable";
this.checkUseBackdropColor.UseVisualStyleBackColor = true;
//
// NESGraphicsConfig
//
this.AcceptButton = this.OK;
@ -306,9 +310,9 @@
private System.Windows.Forms.GroupBox groupBox4;
private System.Windows.Forms.Panel BackgroundColorPanel;
private System.Windows.Forms.Label label2;
private System.Windows.Forms.Label label3;
private System.Windows.Forms.TextBox BackGroundColorNumber;
private System.Windows.Forms.Button ChangeBGColor;
private System.Windows.Forms.ColorDialog BGColorDialog;
private System.Windows.Forms.CheckBox checkUseBackdropColor;
}
}

View File

@ -42,7 +42,8 @@ namespace BizHawk.MultiClient
PalettePath.Text = Global.Config.NESPaletteFile;
DispSprites.Checked = Global.Config.NESDispSprites;
DispBackground.Checked = Global.Config.NESDispBackground;
BGColorDialog.Color = Color.FromArgb(Global.Config.NESBackgroundColor);
BGColorDialog.Color = Color.FromArgb(unchecked(Global.Config.NESBackgroundColor | (int)0xFF000000));
checkUseBackdropColor.Checked = (Global.Config.NESBackgroundColor & 0xFF000000) != 0;
SetColorBox();
}
@ -89,6 +90,9 @@ namespace BizHawk.MultiClient
Global.Config.NESAutoLoadPalette = AutoLoadPalette.Checked;
Global.Config.NESDispSprites = DispSprites.Checked;
Global.Config.NESDispBackground = DispBackground.Checked;
Global.Config.NESBackgroundColor = BGColorDialog.Color.ToArgb();
if (!checkUseBackdropColor.Checked)
Global.Config.NESBackgroundColor &= 0x00FFFFFF;
this.Close();
}
@ -96,7 +100,7 @@ namespace BizHawk.MultiClient
private void SetColorBox()
{
int color = BGColorDialog.Color.ToArgb();
BackGroundColorNumber.Text = String.Format("{0:X8}", color);
BackGroundColorNumber.Text = String.Format("#{0:X8}", color).Substring(2,6);
BackgroundColorPanel.BackColor = BGColorDialog.Color;
}

View File

@ -14,7 +14,7 @@ namespace BizHawk.MultiClient
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Global.Config = ConfigService.Load<Config>(PathManager.GetExePathAbsolute() + "\\config.ini");
Global.Config = ConfigService.Load<Config>(PathManager.DefaultIniPath);
try { Global.DSound = new DirectSound(); }
catch {

View File

@ -18,10 +18,22 @@ namespace BizHawk.MultiClient
return p;
}
/// <summary>
/// Makes a path relative to the %exe% dir
/// </summary>
public static string MakeProgramRelativePath(string path) { return MakeAbsolutePath("%exe%/" + path, ""); }
/// <summary>
/// The location of the default INI file
/// </summary>
public static string DefaultIniPath { get { return MakeProgramRelativePath("config.ini"); } }
/// <summary>
/// Gets absolute base as derived from EXE
/// </summary>
/// <returns></returns>
public static string GetBasePathAbsolute()
{
//Gets absolute base as derived from EXE
if (Global.Config.BasePath.Length < 1) //If empty, then EXE path
return GetExePathAbsolute();