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.
 
 
 
 
 

87 lines
1.9 KiB

  1. /* Copyright (C) 2014-2015 Ben Kurtovic <ben.kurtovic@gmail.com>
  2. Released under the terms of the MIT License. See LICENSE for details. */
  3. #include <stdlib.h>
  4. #include "gamegear.h"
  5. #include "logging.h"
  6. /*
  7. Create and return a pointer to a new GameGear object.
  8. If memory could not be allocated, OUT_OF_MEMORY() is triggered.
  9. */
  10. GameGear* gamegear_create()
  11. {
  12. GameGear *gg = malloc(sizeof(GameGear));
  13. if (!gg)
  14. OUT_OF_MEMORY()
  15. // mmu_init(&gg->mmu, ...);
  16. z80_init(&gg->cpu, CPU_CLOCK_SPEED);
  17. gg->powered = false;
  18. return gg;
  19. }
  20. /*
  21. Destroy a previously-allocated GameGear object.
  22. Does *not* destroy any loaded ROM objects.
  23. */
  24. void gamegear_destroy(GameGear *gg)
  25. {
  26. free(gg);
  27. }
  28. /*
  29. Load a ROM image into the GameGear object.
  30. Does *not* steal a reference to the ROM object. Calling this function while
  31. the GameGear is powered on has no effect.
  32. */
  33. void gamegear_load(GameGear *gg, ROM *rom)
  34. {
  35. if (gg->powered)
  36. return;
  37. // mmu_hard_map(&gg->mmu, rom->data, ..., ...);
  38. }
  39. /*
  40. Set the GameGear object's power state (true = on; false = off).
  41. Powering on the GameGear executes boot code (e.g. clearing memory and
  42. setting initial register values) and starts the clock. Powering it off
  43. stops the clock.
  44. Setting the power state to its current value has no effect.
  45. */
  46. void gamegear_power(GameGear *gg, bool state)
  47. {
  48. if (gg->powered == state)
  49. return;
  50. if (state) {
  51. // mmu_power(&gg->mmu);
  52. z80_power(&gg->cpu);
  53. }
  54. gg->powered = state;
  55. }
  56. /*
  57. Update the simulation of the GameGear.
  58. This function simulates the number of clock cycles corresponding to the
  59. time since the last call to gamegear_simulate() or gamegear_power() if the
  60. system was just powered on. If the system is powered off, this function
  61. does nothing.
  62. */
  63. void gamegear_simulate(GameGear *gg)
  64. {
  65. if (!gg->powered)
  66. return;
  67. // TODO
  68. // z80_do_cycles(&gg->cpu, ...);
  69. }