forked from jotego/jtcores
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjtgng_tilemap.v
More file actions
171 lines (147 loc) · 4.73 KB
/
jtgng_tilemap.v
File metadata and controls
171 lines (147 loc) · 4.73 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
/* This file is part of JT_GNG.
JT_GNG program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
JT_GNG program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with JT_GNG. If not, see <http://www.gnu.org/licenses/>.
Author: Jose Tejada Gomez. Twitter: @topapate
Version: 1.0
Date: 27-10-2017 */
// 2-word tile memory
//////////////////////////////////////////////////////////////////
// Original board behaviour
// Commando / G&G / 1942 / 1943
// Scroll: when CPU tries to access hold the CPU until H==4, then
// release the CPU and keep it in control of the bus until
// the CPU releases the CS signal
`timescale 1ns/1ps
module jtgng_tilemap #(parameter
DW = 8,
SELBIT = 2,
INVERT_SCAN = 0,
DATAREAD = 3'd2,
SCANW = 10,
BUSY_ON_H0 = 0, // if 1, the busy signal is asserted only at H0 posedge, otherwise it uses the regular clock
SIMID = ""
) (
input clk,
input pxl_cen /* synthesis direct_enable = 1 */,
input Asel, // This is the address bit that selects
// between the low and high tile map
input [1:0] dseln,
input [SCANW-1:0] AB,
input [7:0] V,
input [7:0] H,
input flip,
input [DW-1:0] din,
output reg [DW-1:0] dout,
// Bus arbitrion
input cs,
input wr_n,
output reg busy,
// Pause screen
input pause,
output reg [SCANW-1:0] scan,
input [7:0] msg_low,
input [7:0] msg_high,
// Current tile
output reg [7:0] dout_low,
output reg [7:0] dout_high
);
reg scan_sel = 1'b1;
always @(*) begin
if( SCANW <= 10) begin
scan = (INVERT_SCAN ? { {SCANW{flip}}^{H[7:3],V[7:3]}}
: { {SCANW{flip}}^{V[7:3],H[7:3]}}) >> (10-SCANW);
end else begin
scan = { V[7:2], H[7:2] }; // SCANW assumed to be 12
end
end
reg [SCANW-1:0] addr;
reg we_low, we_high;
wire [7:0] mem_low, mem_high;
reg last_H0;
wire posedge_H0 = BUSY_ON_H0 ? (!last_H0 && H[0] && pxl_cen) : 1'b1;
always @(posedge clk) begin : busy_latch
last_H0 <= H[0];
if( cs && scan_sel && posedge_H0 )
busy <= 1'b1;
else busy <= 1'b0;
end
always @(posedge clk) if(pxl_cen) begin : scan_select
if( !cs )
scan_sel <= 1'b1;
else if(H[2:0]==DATAREAD)
scan_sel <= 1'b0;
end
reg [7:0] udlatch, ldlatch;
reg last_scan;
always @(posedge clk) begin : mem_mux
reg last_Asel;
if( scan_sel ) begin
addr <= scan;
we_low <= 1'b0;
we_high <= 1'b0;
end else begin
addr <= AB;
if( DW == 16 ) begin
we_low <= cs && !wr_n && !dseln[0];
we_high <= cs && !wr_n && !dseln[1];
udlatch <= din[15:8];
ldlatch <= din[7:0];
end else begin
we_low <= cs && !wr_n && !Asel;
we_high <= cs && !wr_n && Asel;
udlatch <= din;
ldlatch <= din;
end
last_Asel <= Asel;
end
// Output latch
last_scan <= scan_sel;
if( !last_scan )
if(DW==8)
dout <= last_Asel ? mem_high : mem_low;
else
dout <= { mem_high, mem_low };
end
// Use these macros to add simulation files
// like ', .simhexfile("sim.hex")' or
// ', .simfile("sim.bin")'
`ifndef JTCHAR_UPPER_SIMFILE
`define JTCHAR_UPPER_SIMFILE
`endif
`ifndef JTCHAR_LOWER_SIMFILE
`define JTCHAR_LOWER_SIMFILE
`endif
jtgng_ram #(.aw(SCANW) `JTCHAR_LOWER_SIMFILE) u_ram_low(
.clk ( clk ),
.cen ( 1'b1 ),
.data ( ldlatch ),
.addr ( addr ),
.we ( we_low ),
.q ( mem_low )
);
// attributes
// the default value for synthesis will display a ROM load message using
// the palette attributes
jtgng_ram #(.aw(SCANW) `JTCHAR_UPPER_SIMFILE) u_ram_high(
.clk ( clk ),
.cen ( 1'b1 ),
.data ( udlatch ),
.addr ( addr ),
.we ( we_high ),
.q ( mem_high )
);
always @(posedge clk) begin
if(last_scan) begin
dout_low <= pause ? msg_low : mem_low;
dout_high <= pause ? msg_high : mem_high;
end
end
endmodule