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);
66 CharSet cs(cschar, csrow, csdata);
67 VideoRAM vram(clk25, vraddr, vrdata, vwaddr, vwdata, vwr);
68 VDisplay dpy(clk25, x, y, vraddr, vrdata, cschar, csrow, csdata, odata);
69 SerRX rx(clk25, vwr, vwaddr, vwdata, serrx);
71 always @(posedge clk25) begin
72 red <= border ? 0 : {3{odata}};
73 green <= border ? 0 : {3{odata}};
74 blue <= border ? 0 : {2{odata}};
81 output reg [11:0] x, y,
85 parameter XFPORCH = 16;
87 parameter XBPORCH = 48;
90 parameter YFPORCH = 10;
92 parameter YBPORCH = 29;
94 always @(posedge pixclk)
96 if (x >= (XRES + XFPORCH + XSYNC + XBPORCH))
98 if (y >= (YRES + YFPORCH + YSYNC + YBPORCH))
105 hs <= (x >= (XRES + XFPORCH)) && (x < (XRES + XFPORCH + XSYNC));
106 vs <= (y >= (YRES + YFPORCH)) && (y < (YRES + YFPORCH + YSYNC));
107 border <= (x > XRES) || (y > YRES);
114 output wire [7:0] data);
116 reg [7:0] rom [(256 * 8 - 1):0];
119 $readmemb("ibmpc1.mem", rom);
121 assign data = rom[{char, row}];
127 output reg [7:0] rdata,
132 reg [7:0] ram [80*25-1 : 0];
134 always @(posedge pixclk)
137 always @(posedge pixclk)
146 output wire [11:0] raddr,
148 output wire [7:0] cschar,
149 output wire [2:0] csrow,
154 wire [7:0] col = x[11:3];
155 wire [5:0] row = y[9:3];
159 assign raddr = ({row,4'b0} + {row,6'b0} + {4'h0,col});
160 assign cschar = rchar;
161 assign csrow = y[2:0];
163 always @(posedge pixclk)
166 always @(posedge pixclk)
167 data = ((xdly < 80 * 8) && (y < 25 * 8)) ? csdata[7 - xdly[2:0]] : 0;
170 `define IN_CLK 25000000
171 `define OUT_CLK 57600
172 `define CLK_DIV (`IN_CLK / `OUT_CLK)
177 output reg [11:0] waddr = 0,
178 output reg [7:0] wchar = 0,
182 reg [15:0] rx_clkdiv = 0;
183 reg [3:0] rx_state = 4'b0000;
184 reg [7:0] rx_data_tmp;
187 always @(posedge pixclk)
189 if ((rx_state == 0) && (serialrx == 0) /*&& (rx_hasdata == 0)*/) /* Kick off. */
191 else if ((rx_state != 4'b0000) && (rx_clkdiv == 0)) begin
192 if (rx_state != 4'b1010)
193 rx_state <= rx_state + 1;
197 4'b0001: begin end /* Twiddle thumbs -- this is the end of the half bit. */
198 4'b0010: rx_data_tmp[0] <= serialrx;
199 4'b0011: rx_data_tmp[1] <= serialrx;
200 4'b0100: rx_data_tmp[2] <= serialrx;
201 4'b0101: rx_data_tmp[3] <= serialrx;
202 4'b0110: rx_data_tmp[4] <= serialrx;
203 4'b0111: rx_data_tmp[5] <= serialrx;
204 4'b1000: rx_data_tmp[6] <= serialrx;
205 4'b1001: rx_data_tmp[7] <= serialrx;
206 4'b1010: if (serialrx == 1) begin
208 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;