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;
95 assign cr_nADV = 0; /* Addresses are always valid! :D */
96 assign cr_nCE = 0; /* The chip is enabled */
97 assign cr_nLB = 0; /* Lower byte is enabled */
98 assign cr_nUB = 0; /* Upper byte is enabled */
99 assign cr_CRE = 0; /* Data writes, not config */
100 assign cr_CLK = 0; /* Clock? I think not! */
102 wire decode = (addrlatch[15:14] == 2'b00) /* extrom */ || (addrlatch[15:13] == 3'b101) /* extram */ || (addrlatch == ADDR_PROGDATA);
104 assign cr_nOE = decode ? ~rdlatch : 1;
105 assign cr_nWE = decode ? ~wrlatch : 1;
107 assign cr_DQ = (~cr_nOE) ? 16'bzzzzzzzzzzzzzzzz : {8'b0, datalatch};
108 assign cr_A = (addrlatch[15:14] == 2'b00) ? /* extrom */ {9'b0,addrlatch[13:0]} :
109 (addrlatch[15:13] == 3'b101) ? {1'b1, 9'b0, addrlatch[12:0]} :
110 (addrlatch == ADDR_PROGDATA) ? {progaddrh[6:0], progaddrm[7:0], progaddrl[7:0]} :
115 always @(posedge clk) begin
117 ADDR_PROGADDRH: if (wr) progaddrh <= data;
118 ADDR_PROGADDRM: if (wr) progaddrm <= data;
119 ADDR_PROGADDRL: if (wr) progaddrl <= data;
123 addrlatch <= address;
127 assign data = (rdlatch && decode) ?
128 (addrlatch == ADDR_PROGADDRH) ? progaddrh :
129 (addrlatch == ADDR_PROGADDRM) ? progaddrm :
130 (addrlatch == ADDR_PROGADDRL) ? progaddrl :
136 input [15:0] address,
141 // synthesis attribute ram_style of ram is block
142 reg [7:0] ram [8191:0];
144 wire decode = (address >= 16'hC000) && (address <= 16'hFDFF); /* This includes echo RAM. */
147 assign data = rdlatch ? odata : 8'bzzzzzzzz;
149 always @(posedge clk)
151 rdlatch <= rd && decode;
152 if (decode) // This has to go this way. The only way XST knows how to do
153 begin // block ram is chip select, write enable, and always
154 if (wr) // reading. "else if rd" does not cut it ...
155 ram[address[12:0]] <= data;
156 odata <= ram[address[12:0]];
162 input [15:0] address,
166 input [7:0] switches,
167 output reg [7:0] ledout = 0);
169 wire decode = address == 16'hFF51;
172 assign data = rdlatch ? odata : 8'bzzzzzzzz;
174 always @(posedge clk)
176 rdlatch <= rd && decode;
179 else if (decode && wr)
185 module Dumpable(input [2:0] r, g, input [1:0] b, input hs, vs, vgaclk);
191 output reg vgaclk = 0,
195 input [7:0] switches,
197 output wire [7:0] leds,
199 output wire [3:0] digits,
200 output wire [7:0] seven,
201 output wire cr_nADV, cr_nCE, cr_nOE, cr_nWE, cr_CRE, cr_nLB, cr_nUB, cr_CLK,
202 output wire [22:0] cr_A,
206 output wire [2:0] r, g,
208 output wire soundl, soundr);
211 always #62 clk <= ~clk;
212 always #100 vgaclk <= ~vgaclk;
214 Dumpable dump(r,g,b,hs,vs,vgaclk);
220 wire [7:0] switches = 8'b0;
221 wire [3:0] buttons = 4'b0;
223 wire xtalb, clk, vgaclk;
224 IBUFG iclkbuf(.O(xtalb), .I(xtal));
225 CPUDCM dcm (.CLKIN_IN(xtalb), .CLKFX_OUT(clk));
226 pixDCM pixdcm (.CLKIN_IN(xtalb), .CLKFX_OUT(vgaclk));
229 wire [15:0] addr [1:0];
230 wire [7:0] data [1:0];
231 wire wr [1:0], rd [1:0];
233 wire irq, tmrirq, lcdcirq, vblankirq;
239 .bus0address(addr[0]),
243 .bus1address(addr[1]),
284 wire lcdhs, lcdvs, lcdclk;
285 wire [2:0] lcdr, lcdg;
295 .vblankirq(vblankirq),
324 (state == 2'b00) ? 4'b0010 :
325 (state == 2'b01) ? 4'b0001 :
326 (state == 2'b10) ? 4'b1000 :
339 UART nouart ( /* no u */
394 .snd_data_r(soundr));