GBHawk: bug fixes
This commit is contained in:
parent
e45943c26a
commit
69409ff729
|
@ -109,7 +109,13 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBHawkNew
|
|||
|
||||
public void Dispose()
|
||||
{
|
||||
DisposeSound();
|
||||
|
||||
if (GB_Pntr != IntPtr.Zero)
|
||||
{
|
||||
LibGBHawk.GB_destroy(GB_Pntr);
|
||||
GB_Pntr = IntPtr.Zero;
|
||||
}
|
||||
}
|
||||
|
||||
#region Video provider
|
||||
|
@ -139,12 +145,15 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBHawkNew
|
|||
|
||||
#region Audio
|
||||
|
||||
public BlipBuffer blip = new BlipBuffer(4500);
|
||||
public BlipBuffer blip_L = new BlipBuffer(9000);
|
||||
public BlipBuffer blip_R = new BlipBuffer(9000);
|
||||
|
||||
public int[] Aud = new int[9000];
|
||||
public uint num_samp;
|
||||
public int[] Aud_L = new int[9000];
|
||||
public int[] Aud_R = new int[9000];
|
||||
public uint num_samp_L;
|
||||
public uint num_samp_R;
|
||||
|
||||
const int blipbuffsize = 4500;
|
||||
const int blipbuffsize = 9000;
|
||||
|
||||
public bool CanProvideAsync => false;
|
||||
|
||||
|
@ -165,24 +174,45 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBHawkNew
|
|||
|
||||
public void GetSamplesSync(out short[] samples, out int nsamp)
|
||||
{
|
||||
uint f_clock = LibGBHawk.GB_get_audio(GB_Pntr, Aud, ref num_samp);
|
||||
uint f_clock = LibGBHawk.GB_get_audio(GB_Pntr, Aud_L, ref num_samp_L, Aud_R, ref num_samp_R);
|
||||
|
||||
for (int i = 0; i < num_samp; i++)
|
||||
for (int i = 0; i < num_samp_L; i++)
|
||||
{
|
||||
blip.AddDelta((uint)Aud[i * 2], Aud[i * 2 + 1]);
|
||||
blip_L.AddDelta((uint)Aud_L[i * 2], Aud_L[i * 2 + 1]);
|
||||
}
|
||||
|
||||
blip.EndFrame(f_clock);
|
||||
for (int i = 0; i < num_samp_R; i++)
|
||||
{
|
||||
blip_R.AddDelta((uint)Aud_R[i * 2], Aud_R[i * 2 + 1]);
|
||||
}
|
||||
|
||||
nsamp = blip.SamplesAvailable();
|
||||
blip_L.EndFrame(f_clock);
|
||||
blip_R.EndFrame(f_clock);
|
||||
|
||||
nsamp = blip_L.SamplesAvailable();
|
||||
samples = new short[nsamp * 2];
|
||||
|
||||
blip.ReadSamples(samples, nsamp, true);
|
||||
if (nsamp != 0)
|
||||
{
|
||||
blip_L.ReadSamplesLeft(samples, nsamp);
|
||||
blip_R.ReadSamplesRight(samples, nsamp);
|
||||
}
|
||||
}
|
||||
|
||||
public void DiscardSamples()
|
||||
{
|
||||
blip.Clear();
|
||||
blip_L.Clear();
|
||||
blip_R.Clear();
|
||||
}
|
||||
|
||||
public void DisposeSound()
|
||||
{
|
||||
blip_L.Clear();
|
||||
blip_R.Clear();
|
||||
blip_L.Dispose();
|
||||
blip_R.Dispose();
|
||||
blip_L = null;
|
||||
blip_R = null;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
|
|
@ -77,7 +77,8 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBHawkNew
|
|||
LibGBHawk.GB_load_bios(GB_Pntr, _bios, is_GBC, _syncSettings.GBACGB);
|
||||
LibGBHawk.GB_load(GB_Pntr, rom, (uint)rom.Length, MD5_temp, (uint)_syncSettings.RTCInitialTime, (uint)_syncSettings.RTCOffset);
|
||||
|
||||
blip.SetRates(3579545, 44100);
|
||||
blip_L.SetRates(4194304, 44100);
|
||||
blip_R.SetRates(4194304, 44100);
|
||||
|
||||
(ServiceProvider as BasicServiceProvider).Register<ISoundProvider>(this);
|
||||
|
||||
|
|
|
@ -83,7 +83,7 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBHawkNew
|
|||
/// <param name="aud_buf">where to send left audio to</param>
|
||||
/// <param name="n_samp">number of left samples</param>
|
||||
[DllImport("GBHawk.dll", CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern uint GB_get_audio(IntPtr core, int[] aud_buf, ref uint n_samp);
|
||||
public static extern uint GB_get_audio(IntPtr core, int[] aud_buf_L, ref uint n_samp_L, int[] aud_buf_R, ref uint n_samp_R);
|
||||
|
||||
#endregion
|
||||
|
||||
|
@ -102,7 +102,7 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBHawkNew
|
|||
/// </summary>
|
||||
/// <param name="core">opaque state pointer</param>
|
||||
/// <param name="loader">load buffer</param>
|
||||
[DllImport("MSXHAWK.dll", CallingConvention = CallingConvention.Cdecl)]
|
||||
[DllImport("GBHAWK.dll", CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern void GB_load_state(IntPtr core, byte[] loader);
|
||||
|
||||
#endregion
|
||||
|
|
|
@ -62,6 +62,7 @@ namespace GBHawk
|
|||
}
|
||||
|
||||
MemMap.ppu_pntr = &ppu[0];
|
||||
ppu->mem_ctrl = &MemMap;
|
||||
|
||||
// initialize the proper mapper
|
||||
Setup_Mapper(MD5, RTC_initial, RTC_offset);
|
||||
|
@ -133,7 +134,21 @@ namespace GBHawk
|
|||
|
||||
bool FrameAdvance(uint8_t new_controller_1, uint32_t new_accx, uint32_t new_accy, bool render, bool rendersound)
|
||||
{
|
||||
for (int i = 0; i < 70224; i++)
|
||||
int temp_check = 0;
|
||||
/*
|
||||
if (cpu.TotalExecutedCycles < 23805935) {
|
||||
temp_check = 70224;
|
||||
}
|
||||
else if (cpu.TotalExecutedCycles < 23853139) {
|
||||
temp_check = 200;
|
||||
}
|
||||
else {
|
||||
temp_check = 5;
|
||||
}
|
||||
*/
|
||||
temp_check = 70224;
|
||||
|
||||
for (int i = 0; i < temp_check; i++)
|
||||
{
|
||||
// These things do not change speed in GBC double spped mode
|
||||
psg.tick();
|
||||
|
@ -337,7 +352,13 @@ namespace GBHawk
|
|||
std::memcpy(dst, src, sizeof int32_t * psg.num_samples_R * 2);
|
||||
n_samp_R[0] = psg.num_samples_R;
|
||||
|
||||
return psg.master_audio_clock;
|
||||
uint32_t temp_int = psg.master_audio_clock;
|
||||
psg.master_audio_clock = 0;
|
||||
|
||||
psg.num_samples_L = 0;
|
||||
psg.num_samples_R = 0;
|
||||
|
||||
return temp_int;
|
||||
}
|
||||
|
||||
void Setup_Mapper(string MD5, uint32_t RTC_initial, uint32_t RTC_offset)
|
||||
|
@ -561,8 +582,8 @@ namespace GBHawk
|
|||
{
|
||||
saver = ppu->SaveState(saver);
|
||||
saver = cpu.SaveState(saver);
|
||||
saver = psg.SaveState(saver);
|
||||
saver = MemMap.SaveState(saver);
|
||||
saver = MemMap.SaveState(saver);
|
||||
saver = psg.SaveState(saver);
|
||||
saver = timer.SaveState(saver);
|
||||
saver = serialport.SaveState(saver);
|
||||
saver = mapper->SaveState(saver);
|
||||
|
@ -572,11 +593,11 @@ namespace GBHawk
|
|||
{
|
||||
loader = ppu->LoadState(loader);
|
||||
loader = cpu.LoadState(loader);
|
||||
loader = MemMap.LoadState(loader);
|
||||
loader = psg.LoadState(loader);
|
||||
loader = MemMap.LoadState(loader);
|
||||
loader = timer.SaveState(loader);
|
||||
loader = serialport.SaveState(loader);
|
||||
loader = mapper->SaveState(loader);
|
||||
loader = timer.LoadState(loader);
|
||||
loader = serialport.LoadState(loader);
|
||||
loader = mapper->LoadState(loader);
|
||||
}
|
||||
|
||||
#pragma endregion
|
||||
|
|
|
@ -728,20 +728,20 @@ namespace GBHawk
|
|||
|
||||
if (L_final != latched_sample_L)
|
||||
{
|
||||
samples_L[num_samples_L * 2] = master_audio_clock;
|
||||
samples_L[num_samples_L * 2 + 1] = L_final - latched_sample_L;
|
||||
//samples_L[num_samples_L * 2] = master_audio_clock;
|
||||
//samples_L[num_samples_L * 2 + 1] = L_final - latched_sample_L;
|
||||
|
||||
num_samples_L++;
|
||||
//num_samples_L++;
|
||||
|
||||
latched_sample_L = L_final;
|
||||
}
|
||||
|
||||
if (R_final != latched_sample_R)
|
||||
{
|
||||
samples_R[num_samples_R * 2] = master_audio_clock;
|
||||
samples_R[num_samples_R * 2 + 1] = R_final - latched_sample_R;
|
||||
//samples_R[num_samples_R * 2] = master_audio_clock;
|
||||
//samples_R[num_samples_R * 2 + 1] = R_final - latched_sample_R;
|
||||
|
||||
num_samples_R++;
|
||||
//num_samples_R++;
|
||||
|
||||
latched_sample_R = R_final;
|
||||
}
|
||||
|
|
|
@ -2974,8 +2974,8 @@ namespace GBHawk
|
|||
|
||||
*saver = (uint8_t)(TotalExecutedCycles & 0xFF); saver++; *saver = (uint8_t)((TotalExecutedCycles >> 8) & 0xFF); saver++;
|
||||
*saver = (uint8_t)((TotalExecutedCycles >> 16) & 0xFF); saver++; *saver = (uint8_t)((TotalExecutedCycles >> 24) & 0xFF); saver++;
|
||||
*saver = (uint8_t)((TotalExecutedCycles >> 16) & 0x32); saver++; *saver = (uint8_t)((TotalExecutedCycles >> 40) & 0xFF); saver++;
|
||||
*saver = (uint8_t)((TotalExecutedCycles >> 16) & 0x48); saver++; *saver = (uint8_t)((TotalExecutedCycles >> 56) & 0xFF); saver++;
|
||||
*saver = (uint8_t)((TotalExecutedCycles >> 32) & 0xFF); saver++; *saver = (uint8_t)((TotalExecutedCycles >> 40) & 0xFF); saver++;
|
||||
*saver = (uint8_t)((TotalExecutedCycles >> 48) & 0xFF); saver++; *saver = (uint8_t)((TotalExecutedCycles >> 56) & 0xFF); saver++;
|
||||
|
||||
return saver;
|
||||
}
|
||||
|
@ -2989,6 +2989,7 @@ namespace GBHawk
|
|||
jammed = *loader == 1; loader++;
|
||||
was_FlagI = *loader == 1; loader++;
|
||||
FlagI = *loader == 1; loader++;
|
||||
halted = *loader == 1; loader++;
|
||||
|
||||
opcode = *loader; loader++;
|
||||
LY = *loader; loader++;
|
||||
|
|
|
@ -1620,7 +1620,7 @@ namespace GBHawk
|
|||
// So transfers nominally from higher memory areas are actually still from there (i.e. FF -> DF)
|
||||
uint8_t DMA_actual = DMA_addr;
|
||||
if (DMA_addr > 0xDF) { DMA_actual &= 0xDF; }
|
||||
DMA_byte = ReadMemory((uint32_t)((DMA_actual << 8) + DMA_inc));
|
||||
DMA_byte = ReadMemory(((uint32_t)(DMA_actual << 8) + DMA_inc));
|
||||
DMA_start = true;
|
||||
}
|
||||
else if ((DMA_clock % 4) == 3)
|
||||
|
@ -3095,7 +3095,7 @@ namespace GBHawk
|
|||
void DMA_tick()
|
||||
{
|
||||
// Note that DMA is halted when the CPU is halted
|
||||
if (DMA_start && !cpu_halted)
|
||||
if (DMA_start && !cpu_halted[0])
|
||||
{
|
||||
if (DMA_clock >= 4)
|
||||
{
|
||||
|
@ -4688,7 +4688,7 @@ namespace GBHawk
|
|||
void DMA_tick()
|
||||
{
|
||||
// Note that DMA is halted when the CPU is halted
|
||||
if (DMA_start && !cpu_halted)
|
||||
if (DMA_start && !cpu_halted[0])
|
||||
{
|
||||
if (DMA_clock >= 4)
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue