OpenCores
URL https://opencores.org/ocsvn/tv80/tv80/trunk

Subversion Repositories tv80

[/] [tv80/] [trunk/] [rtl/] [core/] [tv80n.v] - Blame information for rev 45

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 45 ghutchis
//
2
// TV80 8-Bit Microprocessor Core
3
// Based on the VHDL T80 core by Daniel Wallner (jesus@opencores.org)
4
//
5
// Copyright (c) 2004 Guy Hutchison (ghutchis@opencores.org)
6
//
7
// Permission is hereby granted, free of charge, to any person obtaining a 
8
// copy of this software and associated documentation files (the "Software"), 
9
// to deal in the Software without restriction, including without limitation 
10
// the rights to use, copy, modify, merge, publish, distribute, sublicense, 
11
// and/or sell copies of the Software, and to permit persons to whom the 
12
// Software is furnished to do so, subject to the following conditions:
13
//
14
// The above copyright notice and this permission notice shall be included 
15
// in all copies or substantial portions of the Software.
16
//
17
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 
18
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 
19
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 
20
// IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 
21
// CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 
22
// TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 
23
// SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24
 
25
// Negative-edge based wrapper allows memory wait_n signal to work
26
// correctly without resorting to asynchronous logic.
27
 
28
module tv80n (/*AUTOARG*/
29
  // Outputs
30
  m1_n, mreq_n, iorq_n, rd_n, wr_n, rfsh_n, halt_n, busak_n, A, do,
31
  // Inputs
32
  reset_n, clk, wait_n, int_n, nmi_n, busrq_n, di
33
  );
34
 
35
  parameter Mode = 0;    // 0 => Z80, 1 => Fast Z80, 2 => 8080, 3 => GB
36
  parameter T2Write = 0; // 0 => wr_n active in T3, /=0 => wr_n active in T2
37
  parameter IOWait  = 1; // 0 => Single cycle I/O, 1 => Std I/O cycle
38
 
39
 
40
  input         reset_n;
41
  input         clk;
42
  input         wait_n;
43
  input         int_n;
44
  input         nmi_n;
45
  input         busrq_n;
46
  output        m1_n;
47
  output        mreq_n;
48
  output        iorq_n;
49
  output        rd_n;
50
  output        wr_n;
51
  output        rfsh_n;
52
  output        halt_n;
53
  output        busak_n;
54
  output [15:0] A;
55
  input [7:0]   di;
56
  output [7:0]  do;
57
 
58
  reg           mreq_n;
59
  reg           iorq_n;
60
  reg           rd_n;
61
  reg           wr_n;
62
  reg           nxt_mreq_n;
63
  reg           nxt_iorq_n;
64
  reg           nxt_rd_n;
65
  reg           nxt_wr_n;
66
 
67
  wire          cen;
68
  wire          intcycle_n;
69
  wire          no_read;
70
  wire          write;
71
  wire          iorq;
72
  reg [7:0]     di_reg;
73
  wire [6:0]    mcycle;
74
  wire [6:0]    tstate;
75
 
76
  assign    cen = 1;
77
 
78
  tv80_core #(Mode, IOWait) i_tv80_core
79
    (
80
     .cen (cen),
81
     .m1_n (m1_n),
82
     .iorq (iorq),
83
     .no_read (no_read),
84
     .write (write),
85
     .rfsh_n (rfsh_n),
86
     .halt_n (halt_n),
87
     .wait_n (wait_n),
88
     .int_n (int_n),
89
     .nmi_n (nmi_n),
90
     .reset_n (reset_n),
91
     .busrq_n (busrq_n),
92
     .busak_n (busak_n),
93
     .clk (clk),
94
     .IntE (),
95
     .stop (),
96
     .A (A),
97
     .dinst (di),
98
     .di (di_reg),
99
     .do (do),
100
     .mc (mcycle),
101
     .ts (tstate),
102
     .intcycle_n (intcycle_n)
103
     );
104
 
105
  always @*
106
    begin
107
      nxt_mreq_n = 1;
108
      nxt_rd_n   = 1;
109
      nxt_iorq_n = 1;
110
      nxt_wr_n   = 1;
111
 
112
      if (mcycle[0])
113
        begin
114
          if (tstate[1] || tstate[2])
115
            begin
116
              nxt_rd_n = ~ intcycle_n;
117
              nxt_mreq_n = ~ intcycle_n;
118
              nxt_iorq_n = intcycle_n;
119
            end
120
        end // if (mcycle[0])          
121
      else
122
        begin
123
          if ((tstate[1] || tstate[2]) && !no_read && !write)
124
            begin
125
              nxt_rd_n = 1'b0;
126
              nxt_iorq_n = ~ iorq;
127
              nxt_mreq_n = iorq;
128
            end
129
          if (T2Write == 0)
130
            begin
131
              if (tstate[2] && write)
132
                begin
133
                  nxt_wr_n = 1'b0;
134
                  nxt_iorq_n = ~ iorq;
135
                  nxt_mreq_n = iorq;
136
                end
137
            end
138
          else
139
            begin
140
              if ((tstate[1] || (tstate[2] && !wait_n)) && write)
141
                begin
142
                  nxt_wr_n = 1'b0;
143
                  nxt_iorq_n = ~ iorq;
144
                  nxt_mreq_n = iorq;
145
                end
146
            end // else: !if(T2write == 0)          
147
        end // else: !if(mcycle[0])
148
    end // always @ *
149
 
150
  always @(negedge clk)
151
    begin
152
      if (!reset_n)
153
        begin
154
          rd_n   <= #1 1'b1;
155
          wr_n   <= #1 1'b1;
156
          iorq_n <= #1 1'b1;
157
          mreq_n <= #1 1'b1;
158
        end
159
      else
160
        begin
161
          rd_n <= #1 nxt_rd_n;
162
          wr_n <= #1 nxt_wr_n;
163
          iorq_n <= #1 nxt_iorq_n;
164
          mreq_n <= #1 nxt_mreq_n;
165
        end // else: !if(!reset_n)
166
    end // always @ (posedge clk or negedge reset_n)
167
 
168
  always @(posedge clk)
169
    begin
170
      if (!reset_n)
171
        begin
172
          di_reg <= #1 0;
173
        end
174
      else
175
        begin
176
          if (tstate[2] && wait_n == 1'b1)
177
            di_reg <= #1 di;
178
        end // else: !if(!reset_n)
179
    end // always @ (posedge clk)
180
 
181
endmodule // t80n
182
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.