Subversion Repositories pentevo

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
1029 chrv 1
`include "../include/tune.v"
2
 
3
// PentEvo project (c) NedoPC 2008-2009
4
//
5
// Z80 memory manager: routes ROM/RAM accesses, makes wait-states for 14MHz or stall condition, etc.
6
//
7
//
8
// fclk    _/`\_/`\_/`\_/`\_/`\_/`\_/`\_/`\_/`\_/`\_/`\_/`\_/`\_/`\_/`\_/`\_/`\_/`\_/`\_/`\_/`\_/`\_/`\_/`\_/`\_/`\_/`\_/`\_/`\_/`\_/`\
9
//          |   |   |   |   |   |   |   |   |   |   |   |   |   |   |   |   |   |   |   |   |   |   |   |   |   |   |   |   |   |   |
10
// zclk     /```\___/```\___/```\___/```````\_______/```````\_______/```````````````\_______________/```````````````\_______________/`
11
//          |   |   |   |   |   |   |   |   |   |   |   |   |   |   |   |   |   |   |   |   |   |   |   |   |   |   |   |   |   |   |
12
// zpos     `\___/```\___/```\___/```\___________/```\___________/```\___________________________/```\___________________________/```\
13
//          |   |   |   |   |   |   |   |   |   |   |   |   |   |   |   |   |   |   |   |   |   |   |   |   |   |   |   |   |   |   |
14
// zneg     _/```\___/```\___/```\_______/```\___________/```\___________________/```\___________________________/```\________________
15
 
16
module zmem(
17
 
18
        input fclk,
19
        input rst_n,
20
 
21
        input zpos, //
22
        input zneg, // strobes which show positive and negative edges of zclk; this is to stay in single clock domain
23
 
24
        input cend,  // DRAM cycle end
25
        input pre_cend, // pre cycle end
26
 
27
 
28
        input [15:0] za,
29
 
30
        input [7:0] zd_in, // won't emit anything to Z80 bus, data bus mux is another module
31
        output reg [7:0] zd_out, // output to Z80 bus
32
 
33
        output zd_ena, // out bus to the Z80
34
 
35
        input m1_n,
36
        input rfsh_n,
37
        input mreq_n,
38
        input iorq_n,
39
        input rd_n,
40
        input wr_n,
41
 
42
 
43
 
44
 
45
        input win0_romnram, // four windows, each 16k,
46
        input win1_romnram, // ==1 - there is rom,
47
        input win2_romnram, // ==0 - there is ram
48
        input win3_romnram, //
49
 
50
        input [7:0] win0_page, // which 16k page is in given window
51
        input [7:0] win1_page, //
52
        input [7:0] win2_page, //
53
        input [7:0] win3_page, //
54
 
55
 
56
 
57
        input dos, // for lame TR-DOS rom switching
58
 
59
        output reg [4:0] rompg, // output for ROM paging
60
        output romoe_n,
61
        output romwe_n,
62
        output csrom,
63
 
64
 
65
        output cpu_req,
66
        output cpu_rnw,
67
        output [20:0] cpu_addr,
68
        output [7:0] cpu_wrdata,
69
        output cpu_wrbsel,
70
 
71
        input [15:0] cpu_rddata,
72
        input cpu_strobe
73
 
74
);
75
 
76
 
77
        wire [1:0] win;
78
        reg [7:0] page;
79
        reg romnram;
80
 
81
        wire ramreq;
82
 
83
        wire ramwr,ramrd;
84
 
85
        reg ramrd_reg,ramwr_reg,ramrd_prereg;
86
 
87
 
88
        // make paging
89
        assign win[1:0] = za[15:14];
90
 
91
        always @*
92
        begin
93
                case( win )
94
                2'b00:
95
                begin
96
                        page    = win0_page;
97
                        romnram = win0_romnram;
98
                end
99
 
100
                2'b01:
101
                begin
102
                        page    = win1_page;
103
                        romnram = win1_romnram;
104
                end
105
 
106
                2'b10:
107
                begin
108
                        page    = win2_page;
109
                        romnram = win2_romnram;
110
                end
111
 
112
                2'b11:
113
                begin
114
                        page    = win3_page;
115
                        romnram = win3_romnram;
116
                end
117
                endcase
118
        end
119
 
120
 
121
        // rom paging
122
        always @*
123
        begin
124
                rompg[4:2] = page[4:2];
125
 
126
//              if( dos ) // ATM rom model
127
//                      rompg[1:0] = 2'b01;
128
//              else
129
                        rompg[1:0] = page[1:0];
130
        end
131
 
132
 
133
 
134
 
135
        assign romwe_n = 1'b1;  // no rom write support for now
136
        assign romoe_n = rd_n | mreq_n; // temporary
137
 
138
        assign csrom = romnram; // positive polarity!
139
 
140
 
141
 
142
        // DRAM accesses
143
 
144
        assign ramreq = (~mreq_n) && (~romnram) && rfsh_n;
145
 
146
        assign ramrd = ramreq & (~rd_n);
147
        assign ramwr = ramreq & (~wr_n);
148
 
149
 
150
        assign zd_ena = ramrd;
151
        assign cpu_wrdata = zd_in;
152
 
153
        assign cpu_wrbsel = za[0];
154
        assign cpu_addr[20:0] = { page[7:0], za[13:1] };
155
 
156
        always @* if( cpu_strobe ) // WARNUNG! ACHTING! LATCH!!!
157
                zd_out <= cpu_wrbsel ? cpu_rddata[7:0] : cpu_rddata[15:8];
158
 
159
 
160
//      always @(posedge fclk) if( pre_cend )
161
//              ramrd_prereg <= ramrd;
162
//      assign cpu_rnw = ramrd_prereg; // is it correct???
163
//
164
// removed because it could be source of problems for NMOS Z80
165
//
166
// new one:
167
//
168
        assign cpu_rnw = ramrd;
169
 
170
 
171
        always @(posedge fclk) if( cend )
172
        begin
173
                ramrd_reg <= ramrd;
174
                ramwr_reg <= ramwr;
175
        end
176
 
177
        assign cpu_req = ( ramrd & (~ramrd_reg) ) | ( ramwr & (~ramwr_reg) );
178
 
179
 
180
 
181
endmodule
182