fix gameboy synchronization thanks to @LIJI32
This commit is contained in:
parent
45e0a75491
commit
91816c30b5
@ -66,6 +66,7 @@ GB_gameboy_t gb1;
|
|||||||
GB_gameboy_t gb2;
|
GB_gameboy_t gb2;
|
||||||
extern const unsigned char dmg_boot[], cgb_boot[], agb_boot[];
|
extern const unsigned char dmg_boot[], cgb_boot[], agb_boot[];
|
||||||
extern const unsigned dmg_boot_length, cgb_boot_length, agb_boot_length;
|
extern const unsigned dmg_boot_length, cgb_boot_length, agb_boot_length;
|
||||||
|
bool vblank1_occurred = false, vblank2_occurred = false;
|
||||||
|
|
||||||
static void fallback_log(enum retro_log_level level, const char *fmt, ...)
|
static void fallback_log(enum retro_log_level level, const char *fmt, ...)
|
||||||
{
|
{
|
||||||
@ -119,12 +120,14 @@ static void audio_callback(void *gb)
|
|||||||
|
|
||||||
static void vblank1(GB_gameboy_t *gb)
|
static void vblank1(GB_gameboy_t *gb)
|
||||||
{
|
{
|
||||||
|
vblank1_occurred = true;
|
||||||
GB_update_keys_status(gb, 0);
|
GB_update_keys_status(gb, 0);
|
||||||
audio_callback(gb);
|
audio_callback(gb);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void vblank2(GB_gameboy_t *gb)
|
static void vblank2(GB_gameboy_t *gb)
|
||||||
{
|
{
|
||||||
|
vblank2_occurred = true;
|
||||||
GB_update_keys_status(gb, 1);
|
GB_update_keys_status(gb, 1);
|
||||||
//audio_callback(gb);
|
//audio_callback(gb);
|
||||||
}
|
}
|
||||||
@ -241,24 +244,30 @@ void retro_reset(void)
|
|||||||
GB_reset(&gb2);
|
GB_reset(&gb2);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static uint8_t byte_to_send1 = 0xFF, byte_to_send2 = 0xFF;
|
||||||
|
|
||||||
static void serial_start1(GB_gameboy_t *gb, uint8_t byte_received)
|
static void serial_start1(GB_gameboy_t *gb, uint8_t byte_received)
|
||||||
{
|
{
|
||||||
GB_serial_set_data(&gb2, byte_received);
|
byte_to_send1 = byte_received;
|
||||||
}
|
}
|
||||||
|
|
||||||
static uint8_t serial_end1(GB_gameboy_t *gb)
|
static uint8_t serial_end1(GB_gameboy_t *gb)
|
||||||
{
|
{
|
||||||
return GB_serial_get_data(&gb2);
|
uint8_t ret = GB_serial_get_data(&gb2);
|
||||||
|
GB_serial_set_data(&gb2, byte_to_send1);
|
||||||
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void serial_start2(GB_gameboy_t *gb, uint8_t byte_received)
|
static void serial_start2(GB_gameboy_t *gb, uint8_t byte_received)
|
||||||
{
|
{
|
||||||
GB_serial_set_data(&gb1, byte_received);
|
byte_to_send2 = byte_received;
|
||||||
}
|
}
|
||||||
|
|
||||||
static uint8_t serial_end2(GB_gameboy_t *gb)
|
static uint8_t serial_end2(GB_gameboy_t *gb)
|
||||||
{
|
{
|
||||||
return GB_serial_get_data(&gb1);
|
uint8_t ret = GB_serial_get_data(&gb1);
|
||||||
|
GB_serial_set_data(&gb1, byte_to_send2);
|
||||||
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void init_for_current_model(void)
|
static void init_for_current_model(void)
|
||||||
@ -450,8 +459,16 @@ void retro_run(void)
|
|||||||
if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE_UPDATE, &updated) && updated)
|
if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE_UPDATE, &updated) && updated)
|
||||||
check_variables();
|
check_variables();
|
||||||
|
|
||||||
GB_run_frame(&gb1);
|
vblank1_occurred = vblank2_occurred = false;
|
||||||
GB_run_frame(&gb2);
|
signed delta = 0;
|
||||||
|
while (!vblank1_occurred || !vblank2_occurred) {
|
||||||
|
if (delta >= 0) {
|
||||||
|
delta -= GB_run(&gb1);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
delta += GB_run(&gb2);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
video_cb(frame_buf, VIDEO_WIDTH, VIDEO_HEIGHT * 2, VIDEO_WIDTH * sizeof(uint32_t));
|
video_cb(frame_buf, VIDEO_WIDTH, VIDEO_HEIGHT * 2, VIDEO_WIDTH * sizeof(uint32_t));
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user