BSNES Region Override (#3169)

* region override for bsnes

* hook up SnesInitData right. still needs region override sync setting

* settings stuff, also need to make sure sameboy is using the right region for sgb

* and build

* clearer struct definition; move struct to header file

Co-authored-by: Morilli <35152647+Morilli@users.noreply.github.com>
This commit is contained in:
CasualPokePlayer 2022-03-04 05:21:53 -08:00 committed by GitHub
parent 8e233a0e3b
commit 114124c82e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
12 changed files with 787 additions and 712 deletions

Binary file not shown.

View File

@ -49,6 +49,8 @@
this.Obj1Checkbox = new System.Windows.Forms.CheckBox(); this.Obj1Checkbox = new System.Windows.Forms.CheckBox();
this.EntropyBox = new System.Windows.Forms.ComboBox(); this.EntropyBox = new System.Windows.Forms.ComboBox();
this.lblEntropy = new BizHawk.WinForms.Controls.LocLabelEx(); this.lblEntropy = new BizHawk.WinForms.Controls.LocLabelEx();
this.RegionBox = new System.Windows.Forms.ComboBox();
this.lblRegion = new BizHawk.WinForms.Controls.LocLabelEx();
this.cbGameHotfixes = new System.Windows.Forms.CheckBox(); this.cbGameHotfixes = new System.Windows.Forms.CheckBox();
this.cbFastPPU = new System.Windows.Forms.CheckBox(); this.cbFastPPU = new System.Windows.Forms.CheckBox();
this.cbCropSGBFrame = new System.Windows.Forms.CheckBox(); this.cbCropSGBFrame = new System.Windows.Forms.CheckBox();
@ -59,7 +61,7 @@
// btnOk // btnOk
// //
this.btnOk.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); this.btnOk.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.btnOk.Location = new System.Drawing.Point(136, 303); this.btnOk.Location = new System.Drawing.Point(136, 321);
this.btnOk.Name = "btnOk"; this.btnOk.Name = "btnOk";
this.btnOk.Size = new System.Drawing.Size(75, 23); this.btnOk.Size = new System.Drawing.Size(75, 23);
this.btnOk.TabIndex = 0; this.btnOk.TabIndex = 0;
@ -71,7 +73,7 @@
// //
this.btnCancel.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); this.btnCancel.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.btnCancel.DialogResult = System.Windows.Forms.DialogResult.Cancel; this.btnCancel.DialogResult = System.Windows.Forms.DialogResult.Cancel;
this.btnCancel.Location = new System.Drawing.Point(217, 303); this.btnCancel.Location = new System.Drawing.Point(217, 321);
this.btnCancel.Name = "btnCancel"; this.btnCancel.Name = "btnCancel";
this.btnCancel.Size = new System.Drawing.Size(75, 23); this.btnCancel.Size = new System.Drawing.Size(75, 23);
this.btnCancel.TabIndex = 1; this.btnCancel.TabIndex = 1;
@ -115,7 +117,7 @@
this.groupBox1.Controls.Add(this.Obj3Checkbox); this.groupBox1.Controls.Add(this.Obj3Checkbox);
this.groupBox1.Controls.Add(this.Obj2Checkbox); this.groupBox1.Controls.Add(this.Obj2Checkbox);
this.groupBox1.Controls.Add(this.Obj1Checkbox); this.groupBox1.Controls.Add(this.Obj1Checkbox);
this.groupBox1.Location = new System.Drawing.Point(18, 165); this.groupBox1.Location = new System.Drawing.Point(18, 183);
this.groupBox1.Name = "groupBox1"; this.groupBox1.Name = "groupBox1";
this.groupBox1.Size = new System.Drawing.Size(274, 132); this.groupBox1.Size = new System.Drawing.Size(274, 132);
this.groupBox1.TabIndex = 11; this.groupBox1.TabIndex = 11;
@ -265,21 +267,40 @@
"None", "None",
"Low", "Low",
"High"}); "High"});
this.EntropyBox.Location = new System.Drawing.Point(164, 138); this.EntropyBox.Location = new System.Drawing.Point(18, 150);
this.EntropyBox.Name = "EntropyBox"; this.EntropyBox.Name = "EntropyBox";
this.EntropyBox.Size = new System.Drawing.Size(128, 21); this.EntropyBox.Size = new System.Drawing.Size(128, 21);
this.EntropyBox.TabIndex = 14; this.EntropyBox.TabIndex = 14;
// //
// lblEntropy // lblEntropy
// //
this.lblEntropy.Location = new System.Drawing.Point(249, 117); this.lblEntropy.Location = new System.Drawing.Point(15, 134);
this.lblEntropy.Name = "lblEntropy"; this.lblEntropy.Name = "lblEntropy";
this.lblEntropy.Text = "Entropy"; this.lblEntropy.Text = "Entropy";
// //
// RegionBox
//
this.RegionBox.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
this.RegionBox.FormattingEnabled = true;
this.RegionBox.Items.AddRange(new object[] {
"Auto",
"NTSC",
"PAL"});
this.RegionBox.Location = new System.Drawing.Point(159, 150);
this.RegionBox.Name = "RegionBox";
this.RegionBox.Size = new System.Drawing.Size(128, 21);
this.RegionBox.TabIndex = 15;
//
// lblRegion
//
this.lblRegion.Location = new System.Drawing.Point(156, 134);
this.lblRegion.Name = "lblRegion";
this.lblRegion.Text = "Region";
//
// cbGameHotfixes // cbGameHotfixes
// //
this.cbGameHotfixes.AutoSize = true; this.cbGameHotfixes.AutoSize = true;
this.cbGameHotfixes.Location = new System.Drawing.Point(18, 111); this.cbGameHotfixes.Location = new System.Drawing.Point(18, 107);
this.cbGameHotfixes.Name = "cbGameHotfixes"; this.cbGameHotfixes.Name = "cbGameHotfixes";
this.cbGameHotfixes.Size = new System.Drawing.Size(93, 17); this.cbGameHotfixes.Size = new System.Drawing.Size(93, 17);
this.cbGameHotfixes.TabIndex = 22; this.cbGameHotfixes.TabIndex = 22;
@ -289,7 +310,7 @@
// cbFastPPU // cbFastPPU
// //
this.cbFastPPU.AutoSize = true; this.cbFastPPU.AutoSize = true;
this.cbFastPPU.Location = new System.Drawing.Point(18, 138); this.cbFastPPU.Location = new System.Drawing.Point(159, 107);
this.cbFastPPU.Name = "cbFastPPU"; this.cbFastPPU.Name = "cbFastPPU";
this.cbFastPPU.Size = new System.Drawing.Size(90, 17); this.cbFastPPU.Size = new System.Drawing.Size(90, 17);
this.cbFastPPU.TabIndex = 23; this.cbFastPPU.TabIndex = 23;
@ -310,7 +331,7 @@
// cbUseSGB2 // cbUseSGB2
// //
this.cbUseSGB2.AutoSize = true; this.cbUseSGB2.AutoSize = true;
this.cbUseSGB2.Location = new System.Drawing.Point(129, 84); this.cbUseSGB2.Location = new System.Drawing.Point(159, 84);
this.cbUseSGB2.Name = "cbUseSGB2"; this.cbUseSGB2.Name = "cbUseSGB2";
this.cbUseSGB2.Size = new System.Drawing.Size(76, 17); this.cbUseSGB2.Size = new System.Drawing.Size(76, 17);
this.cbUseSGB2.TabIndex = 30; this.cbUseSGB2.TabIndex = 30;
@ -323,13 +344,15 @@
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.CancelButton = this.btnCancel; this.CancelButton = this.btnCancel;
this.ClientSize = new System.Drawing.Size(304, 338); this.ClientSize = new System.Drawing.Size(304, 356);
this.Controls.Add(this.cbUseSGB2); this.Controls.Add(this.cbUseSGB2);
this.Controls.Add(this.cbCropSGBFrame); this.Controls.Add(this.cbCropSGBFrame);
this.Controls.Add(this.cbFastPPU); this.Controls.Add(this.cbFastPPU);
this.Controls.Add(this.cbGameHotfixes); this.Controls.Add(this.cbGameHotfixes);
this.Controls.Add(this.lblEntropy); this.Controls.Add(this.lblEntropy);
this.Controls.Add(this.EntropyBox); this.Controls.Add(this.EntropyBox);
this.Controls.Add(this.lblRegion);
this.Controls.Add(this.RegionBox);
this.Controls.Add(this.groupBox1); this.Controls.Add(this.groupBox1);
this.Controls.Add(this.lblDoubleSize); this.Controls.Add(this.lblDoubleSize);
this.Controls.Add(this.cbDoubleSize); this.Controls.Add(this.cbDoubleSize);
@ -366,6 +389,8 @@
private System.Windows.Forms.CheckBox Obj1Checkbox; private System.Windows.Forms.CheckBox Obj1Checkbox;
private System.Windows.Forms.ComboBox EntropyBox; private System.Windows.Forms.ComboBox EntropyBox;
private WinForms.Controls.LocLabelEx lblEntropy; private WinForms.Controls.LocLabelEx lblEntropy;
private System.Windows.Forms.ComboBox RegionBox;
private WinForms.Controls.LocLabelEx lblRegion;
private System.Windows.Forms.CheckBox cbGameHotfixes; private System.Windows.Forms.CheckBox cbGameHotfixes;
private System.Windows.Forms.CheckBox cbFastPPU; private System.Windows.Forms.CheckBox cbFastPPU;
private System.Windows.Forms.CheckBox Bg1_0Checkbox; private System.Windows.Forms.CheckBox Bg1_0Checkbox;

View File

@ -20,6 +20,7 @@ namespace BizHawk.Client.EmuHawk
AlwaysDoubleSize = s.AlwaysDoubleSize, AlwaysDoubleSize = s.AlwaysDoubleSize,
CropSGBFrame = s.CropSGBFrame, CropSGBFrame = s.CropSGBFrame,
Entropy = ss.Entropy, Entropy = ss.Entropy,
RegionOverride = ss.RegionOverride,
Hotfixes = ss.Hotfixes, Hotfixes = ss.Hotfixes,
FastPPU = ss.FastPPU, FastPPU = ss.FastPPU,
UseSGB2 = ss.UseSGB2, UseSGB2 = ss.UseSGB2,
@ -43,6 +44,7 @@ namespace BizHawk.Client.EmuHawk
s.AlwaysDoubleSize = dlg.AlwaysDoubleSize; s.AlwaysDoubleSize = dlg.AlwaysDoubleSize;
s.CropSGBFrame = dlg.CropSGBFrame; s.CropSGBFrame = dlg.CropSGBFrame;
ss.Entropy = dlg.Entropy; ss.Entropy = dlg.Entropy;
ss.RegionOverride = dlg.RegionOverride;
ss.Hotfixes = dlg.Hotfixes; ss.Hotfixes = dlg.Hotfixes;
ss.FastPPU = dlg.FastPPU; ss.FastPPU = dlg.FastPPU;
ss.UseSGB2 = dlg.UseSGB2; ss.UseSGB2 = dlg.UseSGB2;
@ -100,6 +102,12 @@ namespace BizHawk.Client.EmuHawk
init => EntropyBox.SelectedIndex = (int) value; init => EntropyBox.SelectedIndex = (int) value;
} }
private BsnesApi.REGION_OVERRIDE RegionOverride
{
get => (BsnesApi.REGION_OVERRIDE)RegionBox.SelectedIndex;
init => RegionBox.SelectedIndex = (int)value;
}
private bool ShowObj1 { get => Obj1Checkbox.Checked; init => Obj1Checkbox.Checked = value; } private bool ShowObj1 { get => Obj1Checkbox.Checked; init => Obj1Checkbox.Checked = value; }
private bool ShowObj2 { get => Obj2Checkbox.Checked; init => Obj2Checkbox.Checked = value; } private bool ShowObj2 { get => Obj2Checkbox.Checked; init => Obj2Checkbox.Checked = value; }
private bool ShowObj3 { get => Obj3Checkbox.Checked; init => Obj3Checkbox.Checked = value; } private bool ShowObj3 { get => Obj3Checkbox.Checked; init => Obj3Checkbox.Checked = value; }

View File

@ -39,8 +39,7 @@ namespace BizHawk.Emulation.Cores.Nintendo.BSNES
public abstract void snes_set_callbacks(IntPtr[] snesCallbacks); public abstract void snes_set_callbacks(IntPtr[] snesCallbacks);
[BizImport(CallingConvention.Cdecl)] [BizImport(CallingConvention.Cdecl)]
public abstract void snes_init(BsnesApi.ENTROPY entropy, BsnesApi.BSNES_INPUT_DEVICE left, public abstract void snes_init(ref BsnesApi.SnesInitData initData);
BsnesApi.BSNES_INPUT_DEVICE right, ushort mergedBools);// bool hotfixes, bool fastPPU);
[BizImport(CallingConvention.Cdecl)] [BizImport(CallingConvention.Cdecl)]
public abstract void snes_power(); public abstract void snes_power();
[BizImport(CallingConvention.Cdecl)] [BizImport(CallingConvention.Cdecl)]
@ -216,6 +215,17 @@ namespace BizHawk.Emulation.Cores.Nintendo.BSNES
} }
} }
[StructLayout(LayoutKind.Sequential)]
public struct SnesInitData
{
public ENTROPY entropy;
public BSNES_INPUT_DEVICE left_port;
public BSNES_INPUT_DEVICE right_port;
public bool hotfixes;
public bool fast_ppu;
public REGION_OVERRIDE region_override;
}
public void Seal() public void Seal()
{ {
exe.Seal(); exe.Seal();

View File

@ -61,5 +61,12 @@
NTSC = 0, NTSC = 0,
PAL = 1 PAL = 1
} }
public enum REGION_OVERRIDE : uint
{
Auto,
NTSC,
PAL
}
} }
} }

View File

@ -27,6 +27,7 @@ namespace BizHawk.Emulation.Cores.Nintendo.BSNES
|| o.RightPort != _syncSettings.RightPort || o.RightPort != _syncSettings.RightPort
|| o.LimitAnalogChangeSensitivity != _syncSettings.LimitAnalogChangeSensitivity || o.LimitAnalogChangeSensitivity != _syncSettings.LimitAnalogChangeSensitivity
|| o.Entropy != _syncSettings.Entropy || o.Entropy != _syncSettings.Entropy
|| o.RegionOverride != _syncSettings.RegionOverride
|| o.Hotfixes != _syncSettings.Hotfixes || o.Hotfixes != _syncSettings.Hotfixes
|| o.FastPPU != _syncSettings.FastPPU || o.FastPPU != _syncSettings.FastPPU
|| o.UseSGB2 != _syncSettings.UseSGB2; || o.UseSGB2 != _syncSettings.UseSGB2;
@ -72,6 +73,8 @@ namespace BizHawk.Emulation.Cores.Nintendo.BSNES
public BsnesApi.ENTROPY Entropy { get; set; } = BsnesApi.ENTROPY.Low; public BsnesApi.ENTROPY Entropy { get; set; } = BsnesApi.ENTROPY.Low;
public BsnesApi.REGION_OVERRIDE RegionOverride { get; set; } = BsnesApi.REGION_OVERRIDE.Auto;
public bool Hotfixes { get; set; } = true; public bool Hotfixes { get; set; } = true;
public bool FastPPU { get; set; } = true; public bool FastPPU { get; set; } = true;

View File

@ -71,8 +71,16 @@ namespace BizHawk.Emulation.Cores.Nintendo.BSNES
generate_palette(); generate_palette();
// TODO: massive random hack till waterboxhost gets fixed to support 5+ args // TODO: massive random hack till waterboxhost gets fixed to support 5+ args
ushort mergedBools = (ushort) ((_syncSettings.Hotfixes ? 1 << 8 : 0) | (_syncSettings.FastPPU ? 1 : 0)); BsnesApi.SnesInitData snesInitData = new()
Api.core.snes_init(_syncSettings.Entropy, _syncSettings.LeftPort, _syncSettings.RightPort, mergedBools); {
entropy = _syncSettings.Entropy,
left_port = _syncSettings.LeftPort,
right_port = _syncSettings.RightPort,
hotfixes = _syncSettings.Hotfixes,
fast_ppu = _syncSettings.FastPPU,
region_override = _syncSettings.RegionOverride,
};
Api.core.snes_init(ref snesInitData);
Api.SetCallbacks(callbacks); Api.SetCallbacks(callbacks);
// start up audio resampler // start up audio resampler

View File

@ -84,7 +84,7 @@ auto ICD::load() -> bool {
GB_random_set_enabled(configuration.hacks.entropy != "None"); GB_random_set_enabled(configuration.hacks.entropy != "None");
if(Frequency == 0) { if(Frequency == 0) {
GB_init(&sameboy, GB_MODEL_SGB_NO_SFC); GB_init(&sameboy, Region::PAL() ? GB_MODEL_SGB_PAL_NO_SFC : GB_MODEL_SGB_NTSC_NO_SFC);
GB_load_boot_rom_from_buffer(&sameboy, (const unsigned char*)&SGB1BootROM[0], 256); GB_load_boot_rom_from_buffer(&sameboy, (const unsigned char*)&SGB1BootROM[0], 256);
} else { } else {
GB_init(&sameboy, GB_MODEL_SGB2_NO_SFC); GB_init(&sameboy, GB_MODEL_SGB2_NO_SFC);

View File

@ -122,16 +122,14 @@ EXPORT void snes_set_callbacks(SnesCallbacks* callbacks)
snesCallbacks = SnesCallbacks(*callbacks); snesCallbacks = SnesCallbacks(*callbacks);
} }
EXPORT void snes_init(int entropy, uint left_port, uint right_port, uint16_t merged_bools)// bool hotfixes, bool fast_ppu) EXPORT void snes_init(SnesInitData* init_data)
{ {
bool hotfixes = merged_bools >> 8;
bool fast_ppu = merged_bools & 1;
fprintf(stderr, "snes_init was called!\n"); fprintf(stderr, "snes_init was called!\n");
emulator = new SuperFamicom::Interface; emulator = new SuperFamicom::Interface;
program = new Program; program = new Program;
string entropy_string; string entropy_string;
switch (entropy) switch (init_data->entropy)
{ {
case 0: entropy_string = "None"; break; case 0: entropy_string = "None"; break;
case 1: entropy_string = "Low"; break; case 1: entropy_string = "Low"; break;
@ -139,15 +137,17 @@ EXPORT void snes_init(int entropy, uint left_port, uint right_port, uint16_t mer
} }
emulator->configure("Hacks/Entropy", entropy_string); emulator->configure("Hacks/Entropy", entropy_string);
emulator->connect(ID::Port::Controller1, left_port); emulator->connect(ID::Port::Controller1, init_data->left_port);
emulator->connect(ID::Port::Controller2, right_port); emulator->connect(ID::Port::Controller2, init_data->right_port);
emulator->configure("Hacks/Hotfixes", hotfixes); emulator->configure("Hacks/Hotfixes", init_data->hotfixes);
emulator->configure("Hacks/PPU/Fast", fast_ppu); emulator->configure("Hacks/PPU/Fast", init_data->fast_ppu);
emulator->configure("Video/BlurEmulation", false); // blurs the video when not using fast ppu. I don't like it so I disable it here :) emulator->configure("Video/BlurEmulation", false); // blurs the video when not using fast ppu. I don't like it so I disable it here :)
// needed in order to get audio sync working. should probably figure out what exactly this does or how to change that properly // needed in order to get audio sync working. should probably figure out what exactly this does or how to change that properly
Emulator::audio.setFrequency(SAMPLE_RATE); Emulator::audio.setFrequency(SAMPLE_RATE);
program->regionOverride = init_data->region_override;
} }
EXPORT void snes_power(void) EXPORT void snes_power(void)

View File

@ -28,6 +28,15 @@ enum SNES_MEMORY {
}; };
struct SnesInitData {
int entropy;
unsigned left_port;
unsigned right_port;
bool hotfixes;
bool fast_ppu;
int region_override;
};
struct LayerEnables struct LayerEnables
{ {
bool BG1_Prio0, BG1_Prio1; bool BG1_Prio0, BG1_Prio1;

View File

@ -42,6 +42,7 @@ struct Program : Emulator::Platform
bool overscan = false; bool overscan = false;
uint16_t backdropColor; uint16_t backdropColor;
int regionOverride = 0;
public: public:
struct Game { struct Game {
@ -361,7 +362,11 @@ auto Program::loadSuperFamicom() -> bool
auto heuristics = Heuristics::SuperFamicom(rom, superFamicom.location); auto heuristics = Heuristics::SuperFamicom(rom, superFamicom.location);
superFamicom.title = heuristics.title(); superFamicom.title = heuristics.title();
superFamicom.region = heuristics.videoRegion(); switch (regionOverride) {
case 0: superFamicom.region = heuristics.videoRegion(); break;
case 1: superFamicom.region = "NTSC"; break;
case 2: superFamicom.region = "PAL"; break;
}
superFamicom.manifest = heuristics.manifest(); superFamicom.manifest = heuristics.manifest();
hackPatchMemory(rom); hackPatchMemory(rom);