From 04ef6cb35b353cab37d21f832abd0abc9ad44203 Mon Sep 17 00:00:00 2001 From: scawful Date: Tue, 5 Dec 2023 03:47:24 -0500 Subject: [PATCH] Add step mode to z3ed cli emulator --- src/cli/command_handler.h | 32 ++++++++++++++++++++++++++++---- 1 file changed, 28 insertions(+), 4 deletions(-) diff --git a/src/cli/command_handler.h b/src/cli/command_handler.h index 9675dc22..f4cf7b15 100644 --- a/src/cli/command_handler.h +++ b/src/cli/command_handler.h @@ -282,13 +282,37 @@ class Emulator : public CommandHandler { std::string filename = arg_vec[0]; RETURN_IF_ERROR(rom_.LoadFromFile(filename)) + bool step = false; + if (arg_vec[1].empty()) { + snes.SetCpuMode(0); + } else { + snes.SetCpuMode(1); + step = true; + } + snes.SetupMemory(rom_); snes.Init(rom_); - int i = 0; - while (i < 80000) { - snes.Run(); - i++; + if (!step) { + int i = 0; + while (i < 80000) { + snes.Run(); + i++; + } + } else { + // This loop should take in input from the keyboard, such as pressing + // space to step through the loop and pressing x to end the execution. + bool stepping = true; + std::cout << "Press space to step, x to exit" << std::endl; + while (stepping) { + char input; + std::cin.get(input); + if (input == 'x') { + break; + } else { + snes.StepRun(); + } + } } return absl::OkStatus();