An emulator, assembler, and disassembler for the Sega Game Gear
Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

iomanager.c 1.2 KiB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. /* Copyright (C) 2014-2016 Ben Kurtovic <ben.kurtovic@gmail.com>
  2. Released under the terms of the MIT License. See LICENSE for details. */
  3. #include <signal.h>
  4. #include <stdbool.h>
  5. #include <unistd.h>
  6. #include "iomanager.h"
  7. #include "logging.h"
  8. static volatile bool caught_signal;
  9. /*
  10. Signal handler for SIGINT.
  11. */
  12. static void handle_sigint(int sig)
  13. {
  14. (void) sig; // We don't care
  15. caught_signal = true;
  16. }
  17. /*
  18. Emulate a Game Gear. Handle I/O with the host computer.
  19. Block until emulation is finished.
  20. */
  21. void iomanager_emulate(GameGear *gg)
  22. {
  23. caught_signal = false;
  24. signal(SIGINT, handle_sigint);
  25. DEBUG("IOManager powering GameGear")
  26. gamegear_power(gg, true);
  27. // TODO: use SDL events
  28. while (!caught_signal) {
  29. if (gamegear_simulate(gg)) {
  30. ERROR("caught exception: %s", gamegear_get_exception(gg))
  31. if (DEBUG_LEVEL)
  32. z80_dump_registers(&gg->cpu);
  33. break;
  34. }
  35. usleep(1000 * 1000 / 60);
  36. }
  37. if (caught_signal) {
  38. WARN("caught signal, stopping...")
  39. if (DEBUG_LEVEL)
  40. z80_dump_registers(&gg->cpu);
  41. }
  42. DEBUG("IOManager unpowering GameGear")
  43. gamegear_power(gg, false);
  44. signal(SIGINT, SIG_DFL);
  45. }