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.

README.md 5.7 KiB

9 years ago
9 years ago
9 years ago
8 years ago
4 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. crater
  2. ======
  3. **crater** is an emulator for the [Sega Game Gear][game gear], with an included
  4. [Z80][z80] assembler/disassembler, written in C.
  5. <img src="/docs/tailsadventure.png?raw=true" title="Tails Adventure (1995)" alt="Tails Adventure (1995)" width="320px">
  6. [game gear]: https://en.wikipedia.org/wiki/Sega_Game_Gear
  7. [z80]: https://en.wikipedia.org/wiki/Zilog_Z80
  8. Why?
  9. ----
  10. While the internet is full of emulators for retro game systems, writing one is
  11. nevertheless a fun learning project.
  12. crater is named after [31 Crateris][crateris], a star that was – for a short
  13. time in 1974 – misidentified as [a moon of Mercury][moon]. Mercury was Sega's
  14. codename for the Game Gear during development.
  15. [crateris]: http://www.astrostudio.org/xhip.php?hip=58587
  16. [moon]: https://en.wikipedia.org/wiki/Mercury%27s_moon
  17. Installing
  18. ----------
  19. Only OS X and Linux are tested. You'll need a modern compiler that supports C11
  20. ([clang][clang] preferred) and [SDL 2][sdl2]. Using Homebrew, you can
  21. `brew install sdl2`; using apt, you can `apt-get install libsdl2-dev`.
  22. Run `make` to create `./crater`. To build the development version with debug
  23. symbols and no optimizations, run `make DEBUG=1`, which creates `./crater-dev`.
  24. crater has a number of test cases. Run the entire suite with `make test`;
  25. individual components can be tested by doing `make test-{component}`, where
  26. `{component}` is one of `cpu`, `vdp`, `psg`, `asm`, `dis`, or `integrate`.
  27. [clang]: http://clang.llvm.org/
  28. [sdl2]: https://www.libsdl.org/
  29. Usage
  30. -----
  31. Running `./crater` without arguments will display a list of ROM images located
  32. in the `roms/` directory, and then ask the user to pick one, or enter their own
  33. ROM path. You can provide a path directly with `./crater path/to/rom`.
  34. Add or symlink ROMs to `roms/` at your leisure. Note that they must end in
  35. `.gg` or `.bin` to be auto-detected.
  36. Add `--fullscreen` (`-f`) to enable fullscreen mode, or `--scale <n>`
  37. (`-x <n>`) to scale the game screen by an integer factor in windowed mode (this
  38. only sets the starting configuration; the window should be resizeable).
  39. For games that support it, crater will save cartridge RAM ("battery saves";
  40. these are distinct from save states, which are not yet supported) to a file
  41. named `<rom>.sav`, where `<rom>` is the path to the ROM file. You can set a
  42. custom save location with `--save <path>` (`-s <path>`) or disable saving
  43. entirely with `--no-save`.
  44. Add `--debug` (`-g`) to show logging information while running. Pass it twice
  45. (`-gg`) to show more detailed logs, including an emulator trace.
  46. crater tries to reproduce the Game Gear's native display resolution, which had
  47. a pixel aspect ratio (PAR) of [8:7][par]; this means the pixels were slightly
  48. wider than square, unlike modern LCD displays with a 1:1 PAR. Add `--square`
  49. (`-q`) to force square pixels.
  50. `./crater -h` gives (fairly basic) command-line usage, and `./crater -v` gives
  51. the current version.
  52. [par]: https://pineight.com/mw/index.php?title=Dot_clock_rates
  53. ### Input
  54. crater supports keyboard and joystick/controller input.
  55. For keyboards, custom mappings are not yet supported. There are two primary
  56. configurations I like:
  57. - `Return`/`Esc` for `Start`; `WASD` for D-pad; `J` for `1`/left trigger;
  58. `K` for `2`/right trigger
  59. - `Return`/`Esc` for `Start`; arrow keys for D-pad; `Z` for `1`/left trigger;
  60. `X` for `2`/right trigger
  61. You can switch between them freely.
  62. For controllers, crater uses SDL controller mappings. Many common controllers
  63. are supported out of the box, but you may define your own mappings by creating
  64. a file named `gamecontrollerdb.txt` in the working directory. For more info,
  65. see [this community mapping database][gcdb].
  66. [gcdb]: https://github.com/gabomdq/SDL_GameControllerDB
  67. ### Assembler/Disassembler
  68. crater has built-in support for converting Z80 assembly into ROM images, as
  69. well as attempting the reverse process (i.e., disassembling).
  70. `--assemble <input> [<output>]` (`-a`) converts source code into a `.gg` binary
  71. that can be run by crater. `--disassemble <input> [<output>]` (`-d`) executes
  72. the opposite operation. If no output file is given, crater will use the name of
  73. the input file, with the extension replaced with `.gg` for `-a` and `.asm` for
  74. `-d`. By default, this will never overwrite the original filename; pass
  75. `--overwrite` (`-r`) to let crater do so.
  76. Status
  77. ------
  78. The emulator is almost fully functional, lacking only audio support, a few
  79. uncommon CPU instructions, and some advanced graphics features. Most games are
  80. playable with only minor bugs. Future goals include full save states and a more
  81. sophisticated debugging mode.
  82. The assembler is complete. Future goals include more documentation, macros, and
  83. additional directives.
  84. The disassembler works, but can't differentiate between code and data yet, so
  85. it's not very useful.
  86. The testing infrastructure is limited. The assembler has decent coverage, other
  87. components minimal.
  88. Credits
  89. -------
  90. Special thanks to [SMS Power!][sms_power]'s excellent [development][sms_dev]
  91. section, which has been invaluable in figuring out many of the Game Gear's
  92. details, including ROM header structure and the memory mapping system. Various
  93. source code comments reference their pages.
  94. Also thanks to [Thomas Scherrer's Z80 website][scherrer] for many useful
  95. resources about the Game Gear's CPU, including info about
  96. [undocumented opcodes][undoc_ops] and [flags][undoc_flags]. Finally, credit
  97. goes to [ClrHome][clrhome] for their helpful Z80 [instruction table][clrtab].
  98. [sms_power]: http://www.smspower.org/
  99. [sms_dev]: http://www.smspower.org/Development/Index
  100. [scherrer]: http://z80.info/
  101. [undoc_ops]: http://www.z80.info/z80undoc.htm
  102. [undoc_flags]: http://z80.info/z80sflag.htm
  103. [clrhome]: http://clrhome.org/
  104. [clrtab]: http://clrhome.org/table/