12 // synthesis attribute ram_style of rom is block
13 reg [7:0] rom [1023:0];
14 initial $readmemh("rom.hex", rom);
16 wire decode = address[15:13] == 0;
17 always @(posedge clk) begin
18 rdlatch <= rd && decode;
19 odata <= rom[address[10:0]];
21 assign data = rdlatch ? odata : 8'bzzzzzzzz;
31 reg [7:0] addrlatch = 0;
32 reg romno = 0, romnotmp = 0;
33 reg [7:0] brom0 [255:0];
34 reg [7:0] brom1 [255:0];
36 initial $readmemh("fpgaboot.hex", brom0);
37 initial $readmemh("gbboot.hex", brom1);
39 wire decode = address[15:8] == 0;
40 wire [7:0] odata = (romno == 0) ? brom0[addrlatch] : brom1[addrlatch];
41 always @(posedge clk) begin
42 rdlatch <= rd && decode;
43 addrlatch <= address[7:0];
44 if (wr && decode) romnotmp <= data[0];
45 if (rd && address == 16'h0000) romno <= romnotmp; /* Latch when the program restarts. */
47 assign data = rdlatch ? odata : 8'bzzzzzzzz;
56 reg [7:0] ram [127:0];
58 wire decode = (address >= 16'hFF80) && (address <= 16'hFFFE);
61 assign data = rdlatch ? odata : 8'bzzzzzzzz;
65 rdlatch <= rd && decode;
66 if (decode) // This has to go this way. The only way XST knows how to do
67 begin // block ram is chip select, write enable, and always
68 if (wr) // reading. "else if rd" does not cut it ...
69 ram[address[6:0]] <= data;
70 odata <= ram[address[6:0]];
80 output wire cr_nADV, cr_nCE, cr_nOE, cr_nWE, cr_CRE, cr_nLB, cr_nUB, cr_CLK,
81 output wire [22:0] cr_A,
84 parameter ADDR_PROGADDRH = 16'hFF60;
85 parameter ADDR_PROGADDRM = 16'hFF61;
86 parameter ADDR_PROGADDRL = 16'hFF62;
87 parameter ADDR_PROGDATA = 16'hFF63;
89 reg rdlatch = 0, wrlatch = 0;
90 reg [15:0] addrlatch = 0;
91 reg [7:0] datalatch = 0;
93 reg [7:0] progaddrh, progaddrm, progaddrl;
97 assign cr_nADV = 0; /* Addresses are always valid! :D */
98 assign cr_nCE = 0; /* The chip is enabled */
99 assign cr_nLB = 0; /* Lower byte is enabled */
100 assign cr_nUB = 0; /* Upper byte is enabled */
101 assign cr_CRE = 0; /* Data writes, not config */
102 assign cr_CLK = 0; /* Clock? I think not! */
104 wire decode = (addrlatch[15:14] == 2'b00) /* extrom */ || (addrlatch[15:13] == 3'b101) /* extram */ || (addrlatch == ADDR_PROGDATA);
106 assign cr_nOE = decode ? ~rdlatch : 1;
107 assign cr_nWE = decode ? ~wrlatch : 1;
109 assign cr_DQ = (~cr_nOE) ? 16'bzzzzzzzzzzzzzzzz : {8'b0, datalatch};
110 assign cr_A = (addrlatch[15:14] == 2'b00) ? /* extrom */ {9'b0,addrlatch[13:0]} :
111 (addrlatch[15:13] == 3'b101) ? {1'b1, 9'b0, addrlatch[12:0]} :
112 (addrlatch == ADDR_PROGDATA) ? progaddr :
117 always @(posedge clk) begin
119 ADDR_PROGADDRH: if (wr) progaddrh <= data;
120 ADDR_PROGADDRM: if (wr) progaddrm <= data;
121 ADDR_PROGADDRL: if (wr) progaddrl <= data;
122 ADDR_PROGDATA: if (rd || wr) begin
123 progaddr <= {progaddrh[6:0], progaddrm[7:0], progaddr[7:0]};
124 {progaddrh[6:0], progaddrm[7:0], progaddr[7:0]} <= {progaddrh[6:0], progaddrm[7:0], progaddr[7:0]} + 23'b1;
129 addrlatch <= address;
133 assign data = (rdlatch && decode) ?
134 (addrlatch == ADDR_PROGADDRH) ? progaddrh :
135 (addrlatch == ADDR_PROGADDRM) ? progaddrm :
136 (addrlatch == ADDR_PROGADDRL) ? progaddrl :
142 input [15:0] address,
147 // synthesis attribute ram_style of ram is block
148 reg [7:0] ram [8191:0];
150 wire decode = (address >= 16'hC000) && (address <= 16'hFDFF); /* This includes echo RAM. */
153 assign data = rdlatch ? odata : 8'bzzzzzzzz;
155 always @(posedge clk)
157 rdlatch <= rd && decode;
158 if (decode) // This has to go this way. The only way XST knows how to do
159 begin // block ram is chip select, write enable, and always
160 if (wr) // reading. "else if rd" does not cut it ...
161 ram[address[12:0]] <= data;
162 odata <= ram[address[12:0]];
168 input [15:0] address,
172 input [7:0] switches,
173 output reg [7:0] ledout = 0);
175 wire decode = address == 16'hFF51;
178 assign data = rdlatch ? odata : 8'bzzzzzzzz;
180 always @(posedge clk)
182 rdlatch <= rd && decode;
185 else if (decode && wr)
191 module Dumpable(input [2:0] r, g, input [1:0] b, input hs, vs, vgaclk);
197 output reg vgaclk = 0,
201 input [7:0] switches,
203 output wire [7:0] leds,
206 output wire [3:0] digits,
207 output wire [7:0] seven,
208 output wire cr_nADV, cr_nCE, cr_nOE, cr_nWE, cr_CRE, cr_nLB, cr_nUB, cr_CLK,
209 output wire [22:0] cr_A,
213 output wire [2:0] r, g,
215 output wire soundl, soundr);
218 always #62 clk <= ~clk;
219 always #100 vgaclk <= ~vgaclk;
221 Dumpable dump(r,g,b,hs,vs,vgaclk);
228 wire [7:0] switches = 8'b0;
229 wire [3:0] buttons = 4'b0;
231 wire xtalb, clk, vgaclk;
232 IBUFG iclkbuf(.O(xtalb), .I(xtal));
233 CPUDCM dcm (.CLKIN_IN(xtalb), .CLKFX_OUT(clk));
234 pixDCM pixdcm (.CLKIN_IN(xtalb), .CLKFX_OUT(vgaclk));
237 wire [15:0] addr [1:0];
238 wire [7:0] data [1:0];
239 wire wr [1:0], rd [1:0];
241 wire irq, tmrirq, lcdcirq, vblankirq;
247 .bus0address(addr[0]),
251 .bus1address(addr[1]),
292 wire lcdhs, lcdvs, lcdclk;
293 wire [2:0] lcdr, lcdg;
303 .vblankirq(vblankirq),
332 (state == 2'b00) ? 4'b0010 :
333 (state == 2'b01) ? 4'b0001 :
334 (state == 2'b10) ? 4'b1000 :
347 UART nouart ( /* no u */
403 .snd_data_r(soundr));