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,
48 MulDivDCM dcm25(xtal, clk25);
49 defparam dcm25.div = 4;
50 defparam dcm25.mul = 2;
52 SyncGen sync(clk25, vs, hs, x, y, border);
69 CharSet cs(cschar, csrow, csdata);
70 VideoRAM vram(clk25, vraddr + vscroll, vrdata, vwaddr, vwdata, vwr);
71 VDisplay dpy(clk25, x, y, vraddr, vrdata, cschar, csrow, csdata, odata);
72 SerRX rx(clk25, serwr, serdata, serrx);
73 SerTX tx(clk25, 0, 0, sertx);
74 RXState rxsm(clk25, vwr, vwaddr, vwdata, vscroll, serwr, serdata);
76 always @(posedge clk25) begin
77 red <= border ? 0 : {3{odata}};
78 green <= border ? 0 : {3{odata}};
79 blue <= border ? 0 : {2{odata}};
86 output reg [11:0] x, y,
90 parameter XFPORCH = 16;
92 parameter XBPORCH = 48;
95 parameter YFPORCH = 10;
97 parameter YBPORCH = 29;
99 always @(posedge pixclk)
101 if (x >= (XRES + XFPORCH + XSYNC + XBPORCH))
103 if (y >= (YRES + YFPORCH + YSYNC + YBPORCH))
110 hs <= (x >= (XRES + XFPORCH)) && (x < (XRES + XFPORCH + XSYNC));
111 vs <= (y >= (YRES + YFPORCH)) && (y < (YRES + YFPORCH + YSYNC));
112 border <= (x > XRES) || (y > YRES);
119 output wire [7:0] data);
121 reg [7:0] rom [(256 * 8 - 1):0];
124 $readmemb("ibmpc1.mem", rom);
126 assign data = rom[{char, row}];
132 output reg [7:0] rdata,
137 reg [7:0] ram [2047 : 0];
139 always @(posedge pixclk)
142 always @(posedge pixclk)
151 output wire [10:0] raddr,
153 output wire [7:0] cschar,
154 output wire [2:0] csrow,
158 wire [7:0] col = x[11:3];
159 wire [5:0] row = y[9:3];
163 assign raddr = ({row,4'b0} + {row,6'b0} + {4'h0,col});
164 assign cschar = rchar;
165 assign csrow = y[2:0];
167 always @(posedge pixclk)
170 always @(posedge pixclk)
171 data = ((xdly < 80 * 8) && (y < 25 * 8)) ? csdata[7 - xdly[2:0]] : 0;
174 `define IN_CLK 25000000
175 `define OUT_CLK 57600
176 `define CLK_DIV (`IN_CLK / `OUT_CLK)
181 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 serial = 1);
233 reg [7:0] tx_data = 0;
234 reg [15:0] tx_clkdiv = 0;
235 reg [3:0] tx_state = 4'b0000;
237 wire tx_newdata = wr && !tx_busy;
239 always @(posedge pixclk)
245 end else if (tx_clkdiv == 0) begin
246 tx_state <= tx_state + 1;
249 4'b0000: serial <= 0;
250 4'b0001: serial <= tx_data[0];
251 4'b0010: serial <= tx_data[1];
252 4'b0011: serial <= tx_data[2];
253 4'b0100: serial <= tx_data[3];
254 4'b0101: serial <= tx_data[4];
255 4'b0110: serial <= tx_data[5];
256 4'b0111: serial <= tx_data[6];
257 4'b1000: serial <= tx_data[7];
258 4'b1001: serial <= 1;
259 4'b1010: tx_busy <= 0;
264 if(tx_newdata || (tx_clkdiv == `CLK_DIV))
267 tx_clkdiv <= tx_clkdiv + 1;
274 output reg [10:0] vwaddr = 0,
275 output reg [7:0] vwdata = 0,
276 output reg [10:0] vscroll = 0,
278 input [7:0] serdata);
280 parameter STATE_IDLE = 4'b0000;
281 parameter STATE_NEWLINE = 4'b0001;
282 parameter STATE_CLEAR = 4'b0010;
284 reg [3:0] state = STATE_CLEAR;
289 reg [10:0] clearstart = 0;
290 reg [10:0] clearend = 11'b11111111111;
292 always @(posedge clk25)
294 STATE_IDLE: if (serwr) begin
295 if (serdata == 8'h0A) begin
296 state <= STATE_NEWLINE;
298 end else if (serdata == 8'h0D) begin
301 end else if (serdata == 8'h0C) begin
303 clearend <= 11'b11111111111;
307 state <= STATE_CLEAR;
310 vwaddr <= ({y,4'b0} + {y,6'b0} + {4'h0,x}) + vscroll;
314 state <= STATE_NEWLINE;
323 vscroll <= vscroll + 80;
324 clearstart <= (25 * 80) + vscroll;
325 clearend <= (26*80) + vscroll;
326 state <= STATE_CLEAR;
335 vwaddr <= clearstart;
337 clearstart <= clearstart + 1;
338 if (clearstart == clearend)