1 module video(input pixclk,
13 /* Max coordinate size in bits - 1 */
16 /* Fixed CRTC params for now. Based on a 640x480 VGA signal with
17 * added borders to center the Mac's 512x342.
19 * The added border is 64 pixels left and right and 69 pixels top
22 * The constants are used as count-down and thus include a -1 to
23 * account for the 0 state.
25 parameter hdisp_frontp = 8 - 1;
26 parameter hdisp_hsync = 96 - 1;
27 parameter hdisp_backp = 40 - 1;
28 parameter hdisp_lbord = 8 + 64 - 1;
29 parameter hdisp_display = 512 - 1;
30 parameter hdisp_rbord = 8 + 64 - 1;
32 parameter vdisp_frontp = 2 - 1;
33 parameter vdisp_vsync = 2 - 1;
34 parameter vdisp_backp = 25 - 1;
35 parameter vdisp_tbord = 8 + 69 - 1;
36 parameter vdisp_display = 342 - 1;
37 parameter vdisp_bbord = 8 + 69 - 1;
39 /* Corresponding stages */
40 localparam hstage_frontp = 0;
41 localparam hstage_hsync = 1;
42 localparam hstage_backp = 2;
43 localparam hstage_lbord = 3;
44 localparam hstage_display = 4;
45 localparam hstage_rbord = 5;
47 localparam vstage_frontp = 0;
48 localparam vstage_vsync = 1;
49 localparam vstage_backp = 2;
50 localparam vstage_tbord = 3;
51 localparam vstage_display = 4;
52 localparam vstage_bbord = 5;
54 /* Running h/v counters */
57 reg [csize:0] hnextcnt;
58 reg [csize:0] vnextcnt;
73 /* Request/ack protocol helpers */
76 /* Obtain the new count for the next stage */
79 hstage_frontp: hnextcnt = hdisp_hsync;
80 hstage_hsync: hnextcnt = hdisp_backp;
81 hstage_backp: hnextcnt = hdisp_lbord;
82 hstage_lbord: hnextcnt = hdisp_display;
83 hstage_display: hnextcnt = hdisp_rbord;
84 hstage_rbord: hnextcnt = hdisp_frontp;
85 default: hnextcnt = hdisp_frontp;
90 vstage_frontp: vnextcnt = vdisp_vsync;
91 vstage_vsync: vnextcnt = vdisp_backp;
92 vstage_backp: vnextcnt = vdisp_tbord;
93 vstage_tbord: vnextcnt = vdisp_display;
94 vstage_display: vnextcnt = vdisp_bbord;
95 vstage_bbord: vnextcnt = vdisp_frontp;
96 default: vnextcnt = vdisp_frontp;
101 always@(posedge pixclk or posedge reset) begin
104 hstage <= hstage_frontp;
108 if (hstage == hstage_rbord)
109 hstage <= hstage_frontp;
111 hstage <= hstage + 1;
118 always@(posedge pixclk or posedge reset) begin
121 vstage <= vstage_frontp;
123 if (hstage == hstage_rbord && hcnt == 0) begin
126 if (vstage == vstage_bbord)
127 vstage <= vstage_frontp;
129 vstage <= vstage + 1;
138 assign vid_on = hstage == hstage_display &&
139 vstage == vstage_display;
141 /* Pixel request, async clear */
142 assign pix_req_reset = reset | ack_pix;
144 /* Generate pixel request. NOTE: This relies on the display
145 * width being a multiple of 16
147 always@(posedge pixclk or posedge pix_req_reset) begin
148 if (pix_req_reset) begin
151 if (vstage == vstage_display) begin
152 if (hstage == hstage_backp && hcnt == 0) begin
154 end else if (hstage == hstage_display &&
155 hcnt[3:0] == 4'b1111 &&
165 always@(posedge pixclk or posedge reset) begin
172 pix_shift[15:1] <= pix_shift[14:0];
177 always@(posedge pixclk or posedge reset) begin
183 _hsync_r <= ~(hstage == hstage_hsync);
184 _vsync_r <= ~(vstage == vstage_vsync);
185 pix_r <= vid_on & ~pix_shift[15];
190 assign _hsync = _hsync_r;
191 assign _vsync = _vsync_r;
192 assign red = { pix_r, pix_r, pix_r, pix_r };
193 assign green = { pix_r, pix_r, pix_r, pix_r };
194 assign blue = { pix_r, pix_r, pix_r, pix_r };
195 assign hblank = hstage != hstage_display;