Mirror of CollapseOS
Du kannst nicht mehr als 25 Themen auswählen Themen müssen entweder mit einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

164 Zeilen
4.4KB

  1. // This unit has been copied from libz80 into Collapse OS and was slighly changed
  2. /* =============================================================================
  3. * libz80 - Z80 emulation library
  4. * =============================================================================
  5. *
  6. * (C) Gabriel Gambetta (gabriel.gambetta@gmail.com) 2000 - 2012
  7. *
  8. * Version 2.1.0
  9. *
  10. * -----------------------------------------------------------------------------
  11. *
  12. * This program is free software; you can redistribute it and/or modify
  13. * it under the terms of the GNU General Public License as published by
  14. * the Free Software Foundation; either version 2 of the License, or
  15. * (at your option) any later version.
  16. *
  17. * This program is distributed in the hope that it will be useful,
  18. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  19. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  20. * GNU General Public License for more details.
  21. *
  22. * You should have received a copy of the GNU General Public License
  23. * along with this program; if not, write to the Free Software
  24. * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  25. */
  26. #pragma once
  27. #include <stdio.h>
  28. typedef unsigned short ushort;
  29. typedef unsigned char byte;
  30. /** Function type to emulate data read. */
  31. typedef byte (*Z80DataIn) (int param, ushort address);
  32. /** Function type to emulate data write. */
  33. typedef void (*Z80DataOut) (int param, ushort address, byte data);
  34. /**
  35. * A Z80 register set.
  36. * An union is used since we want independent access to the high and low bytes of the 16-bit registers.
  37. */
  38. typedef union
  39. {
  40. /** Word registers. */
  41. struct
  42. {
  43. ushort AF, BC, DE, HL, IX, IY, SP;
  44. } wr;
  45. /** Byte registers. Note that SP can't be accessed partially. */
  46. struct
  47. {
  48. byte F, A, C, B, E, D, L, H, IXl, IXh, IYl, IYh;
  49. } br;
  50. } Z80Regs;
  51. /** The Z80 flags */
  52. typedef enum
  53. {
  54. F_C = 1, /**< Carry */
  55. F_N = 2, /**< Sub / Add */
  56. F_PV = 4, /**< Parity / Overflow */
  57. F_3 = 8, /**< Reserved */
  58. F_H = 16, /**< Half carry */
  59. F_5 = 32, /**< Reserved */
  60. F_Z = 64, /**< Zero */
  61. F_S = 128 /**< Sign */
  62. } Z80Flags;
  63. /** A Z80 execution context. */
  64. typedef struct
  65. {
  66. Z80Regs R1; /**< Main register set (R) */
  67. Z80Regs R2; /**< Alternate register set (R') */
  68. ushort PC; /**< Program counter */
  69. byte R; /**< Refresh */
  70. byte I;
  71. byte IFF1; /**< Interrupt Flipflop 1 */
  72. byte IFF2; /**< Interrupt Flipflop 2 */
  73. byte IM; /**< Instruction mode */
  74. Z80DataIn memRead;
  75. Z80DataOut memWrite;
  76. int memParam;
  77. Z80DataIn ioRead;
  78. Z80DataOut ioWrite;
  79. int ioParam;
  80. byte halted;
  81. unsigned tstates;
  82. /* Below are implementation details which may change without
  83. * warning; they should not be relied upon by any user of this
  84. * library.
  85. */
  86. /* If true, an NMI has been requested. */
  87. byte nmi_req;
  88. /* If true, a maskable interrupt has been requested. */
  89. byte int_req;
  90. /* If true, defer checking maskable interrupts for one
  91. * instruction. This is used to keep an interrupt from happening
  92. * immediately after an IE instruction. */
  93. byte defer_int;
  94. /* When a maskable interrupt has been requested, the interrupt
  95. * vector. For interrupt mode 1, it's the opcode to execute. For
  96. * interrupt mode 2, it's the LSB of the interrupt vector address.
  97. * Not used for interrupt mode 0.
  98. */
  99. byte int_vector;
  100. /* If true, then execute the opcode in int_vector. */
  101. byte exec_int_vector;
  102. } Z80Context;
  103. /** Execute the next instruction. */
  104. void Z80Execute (Z80Context* ctx);
  105. /** Execute enough instructions to use at least tstates cycles.
  106. * Returns the number of tstates actually executed. Note: Resets
  107. * ctx->tstates.*/
  108. unsigned Z80ExecuteTStates(Z80Context* ctx, unsigned tstates);
  109. /** Decode the next instruction to be executed.
  110. * dump and decode can be NULL if such information is not needed
  111. *
  112. * @param dump A buffer which receives the hex dump
  113. * @param decode A buffer which receives the decoded instruction
  114. */
  115. void Z80Debug (Z80Context* ctx, char* dump, char* decode);
  116. /** Resets the processor. */
  117. void Z80RESET (Z80Context* ctx);
  118. /** Generates a hardware interrupt.
  119. * Some interrupt modes read a value from the data bus; this value must be provided in this function call, even
  120. * if the processor ignores that value in the current interrupt mode.
  121. *
  122. * @param value The value to read from the data bus
  123. */
  124. void Z80INT (Z80Context* ctx, byte value);
  125. /** Generates a non-maskable interrupt. */
  126. void Z80NMI (Z80Context* ctx);