peanut-gb: detect when ROM has halted forever
Signed-off-by: Mahyar Koshkouei <mk@deltabeard.com>
This commit is contained in:
@@ -490,6 +490,8 @@ struct gb_s
|
|||||||
uint8_t joypad;
|
uint8_t joypad;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
unsigned ended : 1;
|
||||||
|
|
||||||
/* Implementation defined data. Set to NULL if not required. */
|
/* Implementation defined data. Set to NULL if not required. */
|
||||||
void *priv;
|
void *priv;
|
||||||
} direct;
|
} direct;
|
||||||
@@ -2200,6 +2202,11 @@ void __gb_step_cpu(struct gb_s *gb)
|
|||||||
case 0x76: /* HALT */
|
case 0x76: /* HALT */
|
||||||
/* TODO: Emulate HALT bug? */
|
/* TODO: Emulate HALT bug? */
|
||||||
gb->gb_halt = 1;
|
gb->gb_halt = 1;
|
||||||
|
if(gb->gb_reg.IE == 0)
|
||||||
|
{
|
||||||
|
gb->direct.ended = 1;
|
||||||
|
return;
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 0x77: /* LD (HL), A */
|
case 0x77: /* LD (HL), A */
|
||||||
@@ -3636,6 +3643,7 @@ void gb_reset(struct gb_s *gb)
|
|||||||
gb->gb_reg.IE = 0x00;
|
gb->gb_reg.IE = 0x00;
|
||||||
|
|
||||||
gb->direct.joypad = 0xFF;
|
gb->direct.joypad = 0xFF;
|
||||||
|
gb->direct.ended = 0;
|
||||||
gb->gb_reg.P1 = 0xCF;
|
gb->gb_reg.P1 = 0xCF;
|
||||||
|
|
||||||
memset(gb->vram, 0x00, VRAM_SIZE);
|
memset(gb->vram, 0x00, VRAM_SIZE);
|
||||||
|
|||||||
+15
-2
@@ -128,11 +128,24 @@ int main(void)
|
|||||||
|
|
||||||
gb_init_serial(&gb, gb_serial_tx, gb_serial_rx);
|
gb_init_serial(&gb, gb_serial_tx, gb_serial_rx);
|
||||||
|
|
||||||
while(1)
|
uint_fast32_t instrs = 0;
|
||||||
gb_run_frame(&gb);
|
uint64_t start_time = time_us_64();
|
||||||
|
uint64_t end_time;
|
||||||
|
while(!gb.direct.ended)
|
||||||
|
{
|
||||||
|
__gb_step_cpu(&gb);
|
||||||
|
instrs++;
|
||||||
|
}
|
||||||
|
|
||||||
|
end_time = time_us_64();
|
||||||
|
|
||||||
|
puts("\nEmulation Ended");
|
||||||
|
printf("Instructions: %u\n"
|
||||||
|
"Time: %llu us\n", instrs, end_time-start_time);
|
||||||
|
|
||||||
/* Sleep forever. */
|
/* Sleep forever. */
|
||||||
sleep:
|
sleep:
|
||||||
|
stdio_flush();
|
||||||
while(1)
|
while(1)
|
||||||
__wfi();
|
__wfi();
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user