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.
 
 
 
 
 

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