An emulator, assembler, and disassembler for the Sega Game Gear
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

54 lines
1.1 KiB

  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 "emulator.h"
  5. #include "logging.h"
  6. static GameGear *global_gg;
  7. /*
  8. Signal handler for SIGINT.
  9. */
  10. static void handle_sigint(int sig)
  11. {
  12. (void) sig;
  13. if (global_gg)
  14. gamegear_power_off(global_gg);
  15. }
  16. /*
  17. GameGear callback: handle SDL logic at the end of a frame.
  18. */
  19. static void draw_frame(GameGear *gg)
  20. {
  21. (void) gg;
  22. // TODO: SDL draw / switch buffers here
  23. }
  24. /*
  25. Emulate a Game Gear. Handle I/O with the host computer.
  26. Block until emulation is finished.
  27. */
  28. void emulate(GameGear *gg)
  29. {
  30. global_gg = gg;
  31. signal(SIGINT, handle_sigint);
  32. gamegear_set_callback(gg, draw_frame);
  33. gamegear_simulate(gg);
  34. if (gamegear_get_exception(gg))
  35. ERROR("caught exception: %s", gamegear_get_exception(gg))
  36. else
  37. WARN("caught signal, stopping...")
  38. if (DEBUG_LEVEL)
  39. gamegear_print_state(gg);
  40. gamegear_clear_callback(gg);
  41. signal(SIGINT, SIG_DFL);
  42. global_gg = NULL;
  43. }