1 module MulDivDCM(input xtal, output clk);
7 BUFG CLKFX_BUFG_INST (.I(CLKFX_BUF),
9 DCM_SP DCM_SP_INST (.CLKFB(GND_BIT),
17 defparam DCM_SP_INST.CLK_FEEDBACK = "NONE";
18 defparam DCM_SP_INST.CLKDV_DIVIDE = 2.0;
19 defparam DCM_SP_INST.CLKFX_DIVIDE = div;
20 defparam DCM_SP_INST.CLKFX_MULTIPLY = mul;
21 defparam DCM_SP_INST.CLKIN_DIVIDE_BY_2 = "FALSE";
22 defparam DCM_SP_INST.CLKIN_PERIOD = 20.000;
23 defparam DCM_SP_INST.CLKOUT_PHASE_SHIFT = "NONE";
24 defparam DCM_SP_INST.DESKEW_ADJUST = "SYSTEM_SYNCHRONOUS";
25 defparam DCM_SP_INST.DFS_FREQUENCY_MODE = "LOW";
26 defparam DCM_SP_INST.DLL_FREQUENCY_MODE = "LOW";
27 defparam DCM_SP_INST.DUTY_CYCLE_CORRECTION = "TRUE";
28 defparam DCM_SP_INST.FACTORY_JF = 16'hC080;
29 defparam DCM_SP_INST.PHASE_SHIFT = 0;
30 defparam DCM_SP_INST.STARTUP_WAIT = "TRUE";
37 output reg [2:0] green,
38 output reg [1:0] blue,
47 MulDivDCM dcm25(xtal, clk25);
48 defparam dcm25.div = 4;
49 defparam dcm25.mul = 2;
51 SyncGen sync(clk25, vs, hs, x, y, border);
68 CharSet cs(cschar, csrow, csdata);
69 VideoRAM vram(clk25, vraddr + vscroll, vrdata, vwaddr, vwdata, vwr);
70 VDisplay dpy(clk25, x, y, vraddr, vrdata, cschar, csrow, csdata, odata);
71 SerRX rx(clk25, serwr, serdata, serrx);
72 RXState rxsm(clk25, vwr, vwaddr, vwdata, vscroll, serwr, serdata);
74 always @(posedge clk25) begin
75 red <= border ? 0 : {3{odata}};
76 green <= border ? 0 : {3{odata}};
77 blue <= border ? 0 : {2{odata}};
84 output reg [11:0] x, y,
88 parameter XFPORCH = 16;
90 parameter XBPORCH = 48;
93 parameter YFPORCH = 10;
95 parameter YBPORCH = 29;
97 always @(posedge pixclk)
99 if (x >= (XRES + XFPORCH + XSYNC + XBPORCH))
101 if (y >= (YRES + YFPORCH + YSYNC + YBPORCH))
108 hs <= (x >= (XRES + XFPORCH)) && (x < (XRES + XFPORCH + XSYNC));
109 vs <= (y >= (YRES + YFPORCH)) && (y < (YRES + YFPORCH + YSYNC));
110 border <= (x > XRES) || (y > YRES);
117 output wire [7:0] data);
119 reg [7:0] rom [(256 * 8 - 1):0];
122 $readmemb("ibmpc1.mem", rom);
124 assign data = rom[{char, row}];
130 output reg [7:0] rdata,
135 reg [7:0] ram [2047 : 0];
137 always @(posedge pixclk)
140 always @(posedge pixclk)
149 output wire [10:0] raddr,
151 output wire [7:0] cschar,
152 output wire [2:0] csrow,
157 wire [7:0] col = x[11:3];
158 wire [5:0] row = y[9:3];
162 assign raddr = ({row,4'b0} + {row,6'b0} + {4'h0,col});
163 assign cschar = rchar;
164 assign csrow = y[2:0];
166 always @(posedge pixclk)
169 always @(posedge pixclk)
170 data = ((xdly < 80 * 8) && (y < 25 * 8)) ? csdata[7 - xdly[2:0]] : 0;
173 `define IN_CLK 25000000
174 `define OUT_CLK 57600
175 `define CLK_DIV (`IN_CLK / `OUT_CLK)
180 output reg [7:0] wchar = 0,
184 reg [15:0] rx_clkdiv = 0;
185 reg [3:0] rx_state = 4'b0000;
186 reg [7:0] rx_data_tmp;
189 always @(posedge pixclk)
191 if ((rx_state == 0) && (serialrx == 0) /*&& (rx_hasdata == 0)*/) /* Kick off. */
193 else if ((rx_state != 4'b0000) && (rx_clkdiv == 0)) begin
194 if (rx_state != 4'b1010)
195 rx_state <= rx_state + 1;
199 4'b0001: begin end /* Twiddle thumbs -- this is the end of the half bit. */
200 4'b0010: rx_data_tmp[0] <= serialrx;
201 4'b0011: rx_data_tmp[1] <= serialrx;
202 4'b0100: rx_data_tmp[2] <= serialrx;
203 4'b0101: rx_data_tmp[3] <= serialrx;
204 4'b0110: rx_data_tmp[4] <= serialrx;
205 4'b0111: rx_data_tmp[5] <= serialrx;
206 4'b1000: rx_data_tmp[6] <= serialrx;
207 4'b1001: rx_data_tmp[7] <= serialrx;
208 4'b1010: if (serialrx == 1) begin
210 wchar <= rx_data_tmp;
218 if ((rx_state == 0) && (serialrx == 0) /*&& (rx_hasdata == 0)*/) /* Wait half a period before advancing. */
219 rx_clkdiv <= `CLK_DIV / 2 + `CLK_DIV / 4;
220 else if (rx_clkdiv == `CLK_DIV)
223 rx_clkdiv <= rx_clkdiv + 1;
231 output reg [10:0] vwaddr = 0,
232 output reg [7:0] vwdata = 0,
233 output reg [10:0] vscroll = 0,
235 input [7:0] serdata);
237 parameter STATE_IDLE = 4'b0000;
238 parameter STATE_NEWLINE = 4'b0001;
239 parameter STATE_CLEAR = 4'b0010;
241 reg [3:0] state = STATE_CLEAR;
246 reg [10:0] clearstart = 0;
247 reg [10:0] clearend = 11'b11111111111;
249 always @(posedge clk25)
251 STATE_IDLE: if (serwr) begin
252 if (serdata == 8'h0A) begin
253 state <= STATE_NEWLINE;
255 end else if (serdata == 8'h0D) begin
258 end else if (serdata == 8'h0C) begin
260 clearend <= 11'b11111111111;
264 state <= STATE_CLEAR;
267 vwaddr <= ({y,4'b0} + {y,6'b0} + {4'h0,x}) + vscroll;
271 state <= STATE_NEWLINE;
280 vscroll <= vscroll + 80;
281 clearstart <= (25 * 80) + vscroll;
282 clearend <= (26*80) + vscroll;
283 state <= STATE_CLEAR;
292 vwaddr <= clearstart;
294 clearstart <= clearstart + 1;
295 if (clearstart == clearend)