peanut-gb: detect when ROM has halted forever

Signed-off-by: Mahyar Koshkouei <mk@deltabeard.com>
This commit is contained in:
Mahyar Koshkouei
2022-03-23 23:40:51 +00:00
parent 41c55df139
commit 25d1e99571
2 changed files with 23 additions and 2 deletions
+8
View File
@@ -490,6 +490,8 @@ struct gb_s
uint8_t joypad;
};
unsigned ended : 1;
/* Implementation defined data. Set to NULL if not required. */
void *priv;
} direct;
@@ -2200,6 +2202,11 @@ void __gb_step_cpu(struct gb_s *gb)
case 0x76: /* HALT */
/* TODO: Emulate HALT bug? */
gb->gb_halt = 1;
if(gb->gb_reg.IE == 0)
{
gb->direct.ended = 1;
return;
}
break;
case 0x77: /* LD (HL), A */
@@ -3636,6 +3643,7 @@ void gb_reset(struct gb_s *gb)
gb->gb_reg.IE = 0x00;
gb->direct.joypad = 0xFF;
gb->direct.ended = 0;
gb->gb_reg.P1 = 0xCF;
memset(gb->vram, 0x00, VRAM_SIZE);
+15 -2
View File
@@ -128,11 +128,24 @@ int main(void)
gb_init_serial(&gb, gb_serial_tx, gb_serial_rx);
while(1)
gb_run_frame(&gb);
uint_fast32_t instrs = 0;
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:
stdio_flush();
while(1)
__wfi();