T80_Pack.vhd 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222
  1. -- ****
  2. -- T80(b) core. In an effort to merge and maintain bug fixes ....
  3. --
  4. --
  5. -- Ver 303 add undocumented DDCB and FDCB opcodes by TobiFlex 20.04.2010
  6. -- Ver 300 started tidyup
  7. -- MikeJ March 2005
  8. -- Latest version from www.fpgaarcade.com (original www.opencores.org)
  9. --
  10. -- ****
  11. --
  12. -- Z80 compatible microprocessor core
  13. --
  14. -- Version : 0242
  15. --
  16. -- Copyright (c) 2001-2002 Daniel Wallner (jesus@opencores.org)
  17. --
  18. -- All rights reserved
  19. --
  20. -- Redistribution and use in source and synthezised forms, with or without
  21. -- modification, are permitted provided that the following conditions are met:
  22. --
  23. -- Redistributions of source code must retain the above copyright notice,
  24. -- this list of conditions and the following disclaimer.
  25. --
  26. -- Redistributions in synthesized form must reproduce the above copyright
  27. -- notice, this list of conditions and the following disclaimer in the
  28. -- documentation and/or other materials provided with the distribution.
  29. --
  30. -- Neither the name of the author nor the names of other contributors may
  31. -- be used to endorse or promote products derived from this software without
  32. -- specific prior written permission.
  33. --
  34. -- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  35. -- AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  36. -- THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  37. -- PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE
  38. -- LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  39. -- CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  40. -- SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  41. -- INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  42. -- CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  43. -- ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  44. -- POSSIBILITY OF SUCH DAMAGE.
  45. --
  46. -- Please report bugs to the author, but before you do so, please
  47. -- make sure that this is not a derivative work and that
  48. -- you have the latest version of this file.
  49. --
  50. -- The latest version of this file can be found at:
  51. -- http://www.opencores.org/cvsweb.shtml/t80/
  52. --
  53. -- Limitations :
  54. --
  55. -- File history :
  56. --
  57. library IEEE;
  58. use IEEE.std_logic_1164.all;
  59. package T80_Pack is
  60. constant T80_TAG_MEM: std_logic_vector(1 downto 0) := "01";
  61. constant T80_TAG_IO: std_logic_vector(1 downto 0) := "10";
  62. component T80
  63. generic(
  64. Mode : integer := 0; -- 0 => Z80, 1 => Fast Z80, 2 => 8080, 3 => GB
  65. IOWait : integer := 0; -- 1 => Single cycle I/O, 1 => Std I/O cycle
  66. Flag_C : integer := 0;
  67. Flag_N : integer := 1;
  68. Flag_P : integer := 2;
  69. Flag_X : integer := 3;
  70. Flag_H : integer := 4;
  71. Flag_Y : integer := 5;
  72. Flag_Z : integer := 6;
  73. Flag_S : integer := 7
  74. );
  75. port(
  76. RESET_n : in std_logic;
  77. CLK_n : in std_logic;
  78. CEN : in std_logic;
  79. WAIT_n : in std_logic;
  80. INT_n : in std_logic;
  81. NMI_n : in std_logic;
  82. BUSRQ_n : in std_logic;
  83. M1_n : out std_logic;
  84. IORQ : out std_logic;
  85. NoRead : out std_logic;
  86. Write : out std_logic;
  87. RFSH_n : out std_logic;
  88. HALT_n : out std_logic;
  89. BUSAK_n : out std_logic;
  90. A : out std_logic_vector(15 downto 0);
  91. DInst : in std_logic_vector(7 downto 0);
  92. DI : in std_logic_vector(7 downto 0);
  93. DO : out std_logic_vector(7 downto 0);
  94. MC : out std_logic_vector(2 downto 0);
  95. TS : out std_logic_vector(2 downto 0);
  96. IntCycle_n : out std_logic;
  97. IntE : out std_logic;
  98. Stop : out std_logic
  99. );
  100. end component;
  101. component T80_Reg
  102. port(
  103. Clk : in std_logic;
  104. CEN : in std_logic;
  105. WEH : in std_logic;
  106. WEL : in std_logic;
  107. AddrA : in std_logic_vector(2 downto 0);
  108. AddrB : in std_logic_vector(2 downto 0);
  109. AddrC : in std_logic_vector(2 downto 0);
  110. DIH : in std_logic_vector(7 downto 0);
  111. DIL : in std_logic_vector(7 downto 0);
  112. DOAH : out std_logic_vector(7 downto 0);
  113. DOAL : out std_logic_vector(7 downto 0);
  114. DOBH : out std_logic_vector(7 downto 0);
  115. DOBL : out std_logic_vector(7 downto 0);
  116. DOCH : out std_logic_vector(7 downto 0);
  117. DOCL : out std_logic_vector(7 downto 0)
  118. );
  119. end component;
  120. component T80_MCode
  121. generic(
  122. Mode : integer := 0;
  123. Flag_C : integer := 0;
  124. Flag_N : integer := 1;
  125. Flag_P : integer := 2;
  126. Flag_X : integer := 3;
  127. Flag_H : integer := 4;
  128. Flag_Y : integer := 5;
  129. Flag_Z : integer := 6;
  130. Flag_S : integer := 7
  131. );
  132. port(
  133. IR : in std_logic_vector(7 downto 0);
  134. ISet : in std_logic_vector(1 downto 0);
  135. MCycle : in std_logic_vector(2 downto 0);
  136. F : in std_logic_vector(7 downto 0);
  137. NMICycle : in std_logic;
  138. IntCycle : in std_logic;
  139. XY_State : in std_logic_vector(1 downto 0);
  140. MCycles : out std_logic_vector(2 downto 0);
  141. TStates : out std_logic_vector(2 downto 0);
  142. Prefix : out std_logic_vector(1 downto 0); -- None,BC,ED,DD/FD
  143. Inc_PC : out std_logic;
  144. Inc_WZ : out std_logic;
  145. IncDec_16 : out std_logic_vector(3 downto 0); -- BC,DE,HL,SP 0 is inc
  146. Read_To_Reg : out std_logic;
  147. Read_To_Acc : out std_logic;
  148. Set_BusA_To : out std_logic_vector(3 downto 0); -- B,C,D,E,H,L,DI/DB,A,SP(L),SP(M),0,F
  149. Set_BusB_To : out std_logic_vector(3 downto 0); -- B,C,D,E,H,L,DI,A,SP(L),SP(M),1,F,PC(L),PC(M),0
  150. ALU_Op : out std_logic_vector(3 downto 0);
  151. -- ADD, ADC, SUB, SBC, AND, XOR, OR, CP, ROT, BIT, SET, RES, DAA, RLD, RRD, None
  152. Save_ALU : out std_logic;
  153. PreserveC : out std_logic;
  154. Arith16 : out std_logic;
  155. Set_Addr_To : out std_logic_vector(2 downto 0); -- aNone,aXY,aIOA,aSP,aBC,aDE,aZI
  156. IORQ : out std_logic;
  157. Jump : out std_logic;
  158. JumpE : out std_logic;
  159. JumpXY : out std_logic;
  160. Call : out std_logic;
  161. RstP : out std_logic;
  162. LDZ : out std_logic;
  163. LDW : out std_logic;
  164. LDSPHL : out std_logic;
  165. Special_LD : out std_logic_vector(2 downto 0); -- A,I;A,R;I,A;R,A;None
  166. ExchangeDH : out std_logic;
  167. ExchangeRp : out std_logic;
  168. ExchangeAF : out std_logic;
  169. ExchangeRS : out std_logic;
  170. I_DJNZ : out std_logic;
  171. I_CPL : out std_logic;
  172. I_CCF : out std_logic;
  173. I_SCF : out std_logic;
  174. I_RETN : out std_logic;
  175. I_BT : out std_logic;
  176. I_BC : out std_logic;
  177. I_BTR : out std_logic;
  178. I_RLD : out std_logic;
  179. I_RRD : out std_logic;
  180. I_INRC : out std_logic;
  181. SetDI : out std_logic;
  182. SetEI : out std_logic;
  183. IMode : out std_logic_vector(1 downto 0);
  184. Halt : out std_logic;
  185. NoRead : out std_logic;
  186. Write : out std_logic;
  187. XYbit_undoc : out std_logic
  188. );
  189. end component;
  190. component T80_ALU
  191. generic(
  192. Mode : integer := 0;
  193. Flag_C : integer := 0;
  194. Flag_N : integer := 1;
  195. Flag_P : integer := 2;
  196. Flag_X : integer := 3;
  197. Flag_H : integer := 4;
  198. Flag_Y : integer := 5;
  199. Flag_Z : integer := 6;
  200. Flag_S : integer := 7
  201. );
  202. port(
  203. Arith16 : in std_logic;
  204. Z16 : in std_logic;
  205. ALU_Op : in std_logic_vector(3 downto 0);
  206. IR : in std_logic_vector(5 downto 0);
  207. ISet : in std_logic_vector(1 downto 0);
  208. BusA : in std_logic_vector(7 downto 0);
  209. BusB : in std_logic_vector(7 downto 0);
  210. F_In : in std_logic_vector(7 downto 0);
  211. Q : out std_logic_vector(7 downto 0);
  212. F_Out : out std_logic_vector(7 downto 0)
  213. );
  214. end component;
  215. end;