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.
 
 
 
 
 

82 lines
1.6 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. #pragma once
  4. #include <stdbool.h>
  5. #include <stdint.h>
  6. #include "io.h"
  7. #include "mmu.h"
  8. #define Z80_EXC_NOT_POWERED 0
  9. #define Z80_EXC_UNIMPLEMENTED_OPCODE 1
  10. #define Z80_EXC_IO_ERROR 2
  11. /* Structs */
  12. #ifdef __BIG_ENDIAN__
  13. #define REG1(hi, lo) hi
  14. #define REG2(hi, lo) lo
  15. #else
  16. #define REG1(hi, lo) lo
  17. #define REG2(hi, lo) hi
  18. #endif
  19. #define REG_PAIR(hi, lo, pair) \
  20. union { \
  21. struct { \
  22. uint8_t REG1(hi, lo); \
  23. uint8_t REG2(hi, lo); \
  24. }; \
  25. uint16_t pair; \
  26. };
  27. typedef struct {
  28. REG_PAIR(a, f, af)
  29. REG_PAIR(b, c, bc)
  30. REG_PAIR(d, e, de)
  31. REG_PAIR(h, l, hl)
  32. REG_PAIR(a_, f_, af_)
  33. REG_PAIR(b_, c_, bc_)
  34. REG_PAIR(d_, e_, de_)
  35. REG_PAIR(h_, l_, hl_)
  36. REG_PAIR(ixh, ixl, ix)
  37. REG_PAIR(iyh, iyl, iy)
  38. uint16_t sp, pc;
  39. uint8_t i, r;
  40. bool im_a, im_b;
  41. bool iff1, iff2;
  42. } Z80RegFile;
  43. typedef struct {
  44. bool fresh;
  45. uint16_t last_addr;
  46. uint64_t counter;
  47. } Z80TraceInfo;
  48. typedef struct {
  49. Z80RegFile regs;
  50. MMU *mmu;
  51. IO *io;
  52. bool except;
  53. uint8_t exc_code, exc_data;
  54. uint16_t *last_index;
  55. double pending_cycles;
  56. Z80TraceInfo trace;
  57. } Z80;
  58. #undef REG_PAIR
  59. #undef REG1
  60. #undef REG2
  61. /* Functions */
  62. void z80_init(Z80*, MMU*, IO*);
  63. void z80_power(Z80*);
  64. bool z80_do_cycles(Z80*, double);
  65. void z80_dump_registers(const Z80*);