Skip to content

Commit cb468ba

Browse files
pull in latest sameboy master, add stub camera pixel callback to prevent nondeterminism, wire disabling joypad bounce as a sync setting, various cleanup
1 parent e2a36c7 commit cb468ba

File tree

7 files changed

+44
-29
lines changed

7 files changed

+44
-29
lines changed

Assets/dll/libsameboy.dll

8 KB
Binary file not shown.

Assets/dll/libsameboy.so

4 KB
Binary file not shown.

src/BizHawk.Emulation.Cores/Consoles/Nintendo/SameBoy/LibSameBoy.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ public enum MemoryAreas : uint
4242
}
4343

4444
[BizImport(cc)]
45-
public abstract IntPtr sameboy_create(byte[] romdata, int romlength, byte[] biosdata, int bioslength, Sameboy.SameboySyncSettings.GBModel model, bool realtime);
45+
public abstract IntPtr sameboy_create(byte[] romdata, int romlength, byte[] biosdata, int bioslength, Sameboy.SameboySyncSettings.GBModel model, bool realtime, bool nobounce);
4646

4747
[BizImport(cc)]
4848
public abstract void sameboy_destroy(IntPtr core);

src/BizHawk.Emulation.Cores/Consoles/Nintendo/SameBoy/SameBoy.ISettable.cs

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -151,11 +151,14 @@ public SameboySettings()
151151
_customPal = new[] { 0x00ffffff, 0x00aaaaaa, 0x00555555, 0x00000000, 0x00ffffff, };
152152
}
153153

154-
public SameboySettings Clone() => MemberwiseClone() as SameboySettings;
154+
public SameboySettings Clone()
155+
=> (SameboySettings)MemberwiseClone();
155156

156-
public int[] GetCustomPalette() => _customPal.Clone() as int[];
157+
public int[] GetCustomPalette()
158+
=> (int[])_customPal.Clone();
157159

158-
public void SetCustomPalette(int[] pal) => _customPal = pal.Clone() as int[];
160+
public void SetCustomPalette(int[] pal)
161+
=> _customPal = (int[])pal.Clone();
159162
}
160163

161164
public class SameboySyncSettings
@@ -210,11 +213,19 @@ public enum GBModel : int
210213
[DefaultValue(0)]
211214
public int RTCDivisorOffset { get; set; }
212215

213-
public SameboySyncSettings() => SettingsUtil.SetDefaultValues(this);
216+
[DisplayName("Disable Joypad Bounce")]
217+
[Description("Disables emulation of the bounce from a physical joypad.")]
218+
[DefaultValue(true)]
219+
public bool NoJoypadBounce { get; set; }
220+
221+
public SameboySyncSettings()
222+
=> SettingsUtil.SetDefaultValues(this);
214223

215-
public SameboySyncSettings Clone() => MemberwiseClone() as SameboySyncSettings;
224+
public SameboySyncSettings Clone()
225+
=> (SameboySyncSettings)MemberwiseClone();
216226

217-
public static bool NeedsReboot(SameboySyncSettings x, SameboySyncSettings y) => !DeepEquality.DeepEquals(x, y);
227+
public static bool NeedsReboot(SameboySyncSettings x, SameboySyncSettings y)
228+
=> !DeepEquality.DeepEquals(x, y);
218229
}
219230
}
220231
}

src/BizHawk.Emulation.Cores/Consoles/Nintendo/SameBoy/SameBoy.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ namespace BizHawk.Emulation.Cores.Nintendo.Sameboy
1212
/// <summary>
1313
/// a gameboy/gameboy color emulator wrapped around native C libsameboy
1414
/// </summary>
15-
[PortedCore(CoreNames.Sameboy, "LIJI32", "0.14.7", "https://github.com/LIJI32/SameBoy")]
15+
[PortedCore(CoreNames.Sameboy, "LIJI32", "0.15.1", "https://github.com/LIJI32/SameBoy")]
1616
[ServiceNotApplicable(new[] { typeof(IDriveLight) })]
1717
public partial class Sameboy : ICycleTiming, IInputPollable, ILinkable, IRomInfo, IBoardInfo, IGameboyCommon
1818
{
@@ -84,7 +84,7 @@ _syncSettings.ConsoleMode is SameboySyncSettings.GBModel.GB_MODEL_AGB
8484
DeterministicEmulation = true;
8585
}
8686

87-
SameboyState = LibSameboy.sameboy_create(file, file.Length, bios, bios.Length, model, realtime);
87+
SameboyState = LibSameboy.sameboy_create(file, file.Length, bios, bios.Length, model, realtime, _syncSettings.NoJoypadBounce);
8888

8989
InitMemoryDomains();
9090
InitMemoryCallbacks();

submodules/sameboy/BizInterface.c

Lines changed: 23 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ typedef struct
2929
GB_gameboy_t gb;
3030
blip_t* blip_l;
3131
blip_t* blip_r;
32-
GB_sample_t sampleBuf[1024 * 8];
3332
GB_sample_t sampleLatch;
3433
u32 nsamps;
3534
u32 vbuf[256 * 224];
@@ -57,8 +56,19 @@ static u8 PeekIO(biz_t* biz, u8 addr)
5756
static void sample_cb(GB_gameboy_t *gb, GB_sample_t* sample)
5857
{
5958
biz_t* biz = (biz_t*)gb;
60-
biz->sampleBuf[biz->nsamps].left = sample->left;
61-
biz->sampleBuf[biz->nsamps].right = sample->right;
59+
60+
if (biz->sampleLatch.left != sample->left)
61+
{
62+
blip_add_delta(biz->blip_l, biz->nsamps, biz->sampleLatch.left - sample->left);
63+
biz->sampleLatch.left = sample->left;
64+
}
65+
66+
if (biz->sampleLatch.right != sample->right)
67+
{
68+
blip_add_delta(biz->blip_r, biz->nsamps, biz->sampleLatch.right - sample->right);
69+
biz->sampleLatch.right = sample->right;
70+
}
71+
6272
biz->nsamps++;
6373
}
6474

@@ -72,6 +82,12 @@ static void vblank_cb(GB_gameboy_t *gb, GB_vblank_type_t type)
7282
((biz_t*)gb)->vblank_occured = true;
7383
}
7484

85+
static u8 camera_pixel_cb(GB_gameboy_t *gb, u8 x, u8 y)
86+
{
87+
// stub for now (also needed for determinism)
88+
return 0;
89+
}
90+
7591
static u8 ReadCallbackRelay(GB_gameboy_t* gb, u16 addr, u8 data)
7692
{
7793
((biz_t*)gb)->read_cb(addr);
@@ -111,7 +127,7 @@ static void ScanlineCallbackRelay(GB_gameboy_t* gb, u8 line)
111127
}
112128
}
113129

114-
EXPORT biz_t* sameboy_create(u8* romdata, u32 romlen, u8* biosdata, u32 bioslen, GB_model_t model, bool realtime)
130+
EXPORT biz_t* sameboy_create(u8* romdata, u32 romlen, u8* biosdata, u32 bioslen, GB_model_t model, bool realtime, bool nobounce)
115131
{
116132
biz_t* biz = calloc(1, sizeof (biz_t));
117133
GB_random_seed(0);
@@ -122,7 +138,10 @@ EXPORT biz_t* sameboy_create(u8* romdata, u32 romlen, u8* biosdata, u32 bioslen,
122138
GB_apu_set_sample_callback(&biz->gb, sample_cb);
123139
GB_set_rgb_encode_callback(&biz->gb, rgb_cb);
124140
GB_set_vblank_callback(&biz->gb, vblank_cb);
141+
GB_set_camera_get_pixel_callback(&biz->gb, camera_pixel_cb);
142+
GB_set_pixels_output(&biz->gb, biz->vbuf);
125143
GB_set_rtc_mode(&biz->gb, realtime ? GB_RTC_MODE_SYNC_TO_HOST : GB_RTC_MODE_ACCURATE);
144+
GB_set_emulate_joypad_bouncing(&biz->gb, !nobounce);
126145
GB_set_allow_illegal_inputs(&biz->gb, true);
127146
biz->blip_l = blip_new(1024);
128147
biz->blip_r = blip_new(1024);
@@ -156,7 +175,6 @@ EXPORT void sameboy_frameadvance(biz_t* biz, GB_key_mask_t keys, u16 x, u16 y, s
156175
{
157176
GB_set_accelerometer_values(&biz->gb, FromRawToG(x), FromRawToG(y));
158177
}
159-
GB_set_pixels_output(&biz->gb, biz->vbuf);
160178
GB_set_border_mode(&biz->gb, border ? GB_BORDER_ALWAYS : GB_BORDER_NEVER);
161179
GB_set_rendering_disabled(&biz->gb, !render);
162180

@@ -182,20 +200,6 @@ EXPORT void sameboy_frameadvance(biz_t* biz, GB_key_mask_t keys, u16 x, u16 y, s
182200
}
183201
while (!biz->vblank_occured && cycles < 35112);
184202

185-
for (u32 i = 0; i < biz->nsamps; i++)
186-
{
187-
if (biz->sampleLatch.left != biz->sampleBuf[i].left)
188-
{
189-
blip_add_delta(biz->blip_l, i, biz->sampleLatch.left - biz->sampleBuf[i].left);
190-
biz->sampleLatch.left = biz->sampleBuf[i].left;
191-
}
192-
if (biz->sampleLatch.right != biz->sampleBuf[i].right)
193-
{
194-
blip_add_delta(biz->blip_r, i, biz->sampleLatch.right - biz->sampleBuf[i].right);
195-
biz->sampleLatch.right = biz->sampleBuf[i].right;
196-
}
197-
}
198-
199203
blip_end_frame(biz->blip_l, biz->nsamps);
200204
blip_end_frame(biz->blip_r, biz->nsamps);
201205
biz->nsamps = 0;

0 commit comments

Comments
 (0)