Rev 668 | Details | Compare with Previous | Last modification | View Log | RSS feed
| Rev | Author | Line No. | Line |
|---|---|---|---|
| 668 | lvd | 1 | // ZX-Evo Base Configuration (c) NedoPC 2008,2009,2010,2011,2012,2013,2014 |
| 2 | // |
||
| 3 | // generates vertical blank, sync and window. |
||
| 134 | ddp | 4 | |
| 668 | lvd | 5 | /* |
| 6 | This file is part of ZX-Evo Base Configuration firmware. |
||
| 7 | |||
| 8 | ZX-Evo Base Configuration firmware is free software: |
||
| 9 | you can redistribute it and/or modify it under the terms of |
||
| 10 | the GNU General Public License as published by |
||
| 11 | the Free Software Foundation, either version 3 of the License, or |
||
| 12 | (at your option) any later version. |
||
| 13 | |||
| 14 | ZX-Evo Base Configuration firmware is distributed in the hope that |
||
| 15 | it will be useful, but WITHOUT ANY WARRANTY; without even |
||
| 16 | the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
||
| 17 | See the GNU General Public License for more details. |
||
| 18 | |||
| 19 | You should have received a copy of the GNU General Public License |
||
| 20 | along with ZX-Evo Base Configuration firmware. |
||
| 21 | If not, see <http://www.gnu.org/licenses/>. |
||
| 22 | */ |
||
| 23 | |||
| 24 | |||
| 25 | // H is period of horizontal sync; |
||
| 134 | ddp | 26 | // from the last non-blanked line: |
| 27 | // 3H is pre-blank, |
||
| 28 | // 2.xxH is vertical sync (slightly more than 2H, all hsync edges preserved) |
||
| 29 | // vblank is total of 25H |
||
| 30 | |||
| 668 | lvd | 31 | `include "../include/tune.v" |
| 32 | |||
| 317 | lvd | 33 | module video_sync_v( |
| 134 | ddp | 34 | |
| 282 | lvd | 35 | input wire clk, |
| 134 | ddp | 36 | |
| 282 | lvd | 37 | input wire hsync_start, // synchronizing signal |
| 38 | input wire line_start, // to end vsync some time after hsync has ended |
||
| 134 | ddp | 39 | |
| 282 | lvd | 40 | input wire hint_start, |
| 134 | ddp | 41 | |
| 42 | |||
| 43 | |||
| 282 | lvd | 44 | // atm video mode input |
| 45 | input wire mode_atm_n_pent, |
||
| 134 | ddp | 46 | |
| 684 | lvd | 47 | input wire [ 1:0] modes_raster, |
| 282 | lvd | 48 | |
| 49 | |||
| 50 | output reg vblank, |
||
| 51 | output reg vsync, |
||
| 52 | |||
| 53 | output reg int_start, // one-shot positive pulse marking beginning of INT for Z80 |
||
| 54 | |||
| 55 | output reg vpix // vertical picture marker: active when there is line with pixels in it, not just a border. changes with hsync edge |
||
| 134 | ddp | 56 | ); |
| 57 | |||
| 58 | |||
| 59 | |||
| 60 | |||
| 61 | |||
| 62 | localparam VBLNK_BEG = 9'd00; |
||
| 63 | |||
| 684 | lvd | 64 | localparam VSYNC_BEG_50HZ = 9'd08; |
| 65 | localparam VSYNC_END_50HZ = 9'd11; |
||
| 66 | localparam VBLNK_END_50HZ = 9'd32; |
||
| 67 | |||
| 68 | localparam VSYNC_BEG_60HZ = 9'd04; |
||
| 69 | localparam VSYNC_END_60HZ = 9'd07; |
||
| 70 | localparam VBLNK_END_60HZ = 9'd22; |
||
| 134 | ddp | 71 | |
| 684 | lvd | 72 | |
| 73 | /* // pentagon (x192) |
||
| 608 | ddp | 74 | localparam VPIX_BEG_PENT = 9'd080; |
| 75 | localparam VPIX_END_PENT = 9'd272; |
||
| 134 | ddp | 76 | |
| 282 | lvd | 77 | // ATM (x200) |
| 608 | ddp | 78 | localparam VPIX_BEG_ATM = 9'd076; |
| 79 | localparam VPIX_END_ATM = 9'd276; |
||
| 684 | lvd | 80 | */ |
| 282 | lvd | 81 | |
| 684 | lvd | 82 | localparam VPIX_BEG_PENTAGON = 9'd076; // for pentagon raster: actual begin is for x200 s, add 4 for x192 modes |
| 83 | localparam VPIX_END_PENTAGON = 9'd272; // actual end is for x192 modes, add 4 for x200 modes. |
||
| 134 | ddp | 84 | |
| 684 | lvd | 85 | localparam VPIX_BEG_60HZ = 9'd042; |
| 86 | localparam VPIX_END_60HZ = 9'd238; |
||
| 87 | |||
| 88 | localparam VPIX_BEG_48K = 9'd060; |
||
| 89 | localparam VPIX_END_48K = 9'd256; |
||
| 90 | |||
| 91 | localparam VPIX_BEG_128K = 9'd059; |
||
| 92 | localparam VPIX_END_128K = 9'd255; |
||
| 93 | |||
| 94 | /* // ntsc |
||
| 608 | ddp | 95 | // pentagon (x192) |
| 96 | localparam VPIX60_BEG_PENT = 9'd046; |
||
| 97 | localparam VPIX60_END_PENT = 9'd238; |
||
| 98 | // ATM (x200) |
||
| 99 | localparam VPIX60_BEG_ATM = 9'd042; |
||
| 100 | localparam VPIX60_END_ATM = 9'd242; |
||
| 684 | lvd | 101 | */ // |
| 134 | ddp | 102 | |
| 684 | lvd | 103 | localparam VPERIOD_PENTAGON = 9'd320; |
| 104 | localparam VPERIOD_60HZ = 9'd262; |
||
| 105 | localparam VPERIOD_48K = 9'd312; |
||
| 106 | localparam VPERIOD_128K = 9'd311; |
||
| 107 | |||
| 108 | |||
| 109 | localparam INT_BEG = 9'd0; |
||
| 110 | localparam INT_BEG_48K = 9'd1; |
||
| 111 | localparam INT_BEG_128K = 9'd1; |
||
| 112 | |||
| 113 | |||
| 114 | |||
| 134 | ddp | 115 | reg [8:0] vcount; |
| 116 | |||
| 684 | lvd | 117 | reg [8:0] vperiod; |
| 118 | reg [8:0] vpix_beg; |
||
| 119 | reg [8:0] vpix_end; |
||
| 134 | ddp | 120 | |
| 121 | |||
| 122 | |||
| 684 | lvd | 123 | initial // for simulation only |
| 134 | ddp | 124 | begin |
| 125 | vcount = 9'd0; |
||
| 126 | vsync = 1'b0; |
||
| 127 | vblank = 1'b0; |
||
| 128 | vpix = 1'b0; |
||
| 129 | int_start = 1'b0; |
||
| 684 | lvd | 130 | vperiod = 'd0; |
| 131 | vpix_beg = 'd0; |
||
| 132 | vpix_end = 'd0; |
||
| 134 | ddp | 133 | end |
| 134 | |||
| 684 | lvd | 135 | always @(posedge clk) |
| 136 | case( modes_raster ) |
||
| 137 | default: vperiod <= VPERIOD_PENTAGON - 9'd1; |
||
| 138 | 2'b01: vperiod <= VPERIOD_60HZ - 9'd1; |
||
| 139 | 2'b10: vperiod <= VPERIOD_48K - 9'd1; |
||
| 140 | 2'b11: vperiod <= VPERIOD_128K - 9'd1; |
||
| 141 | endcase |
||
| 142 | |||
| 143 | always @(posedge clk) |
||
| 144 | case( modes_raster ) |
||
| 145 | default: vpix_beg <= VPIX_BEG_PENTAGON; |
||
| 146 | 2'b01: vpix_beg <= VPIX_BEG_60HZ ; |
||
| 147 | 2'b10: vpix_beg <= VPIX_BEG_48K ; |
||
| 148 | 2'b11: vpix_beg <= VPIX_BEG_128K ; |
||
| 149 | endcase |
||
| 150 | |||
| 151 | always @(posedge clk) |
||
| 152 | case( modes_raster ) |
||
| 153 | default: vpix_end <= VPIX_END_PENTAGON; |
||
| 154 | 2'b01: vpix_end <= VPIX_END_60HZ ; |
||
| 155 | 2'b10: vpix_end <= VPIX_END_48K ; |
||
| 156 | 2'b11: vpix_end <= VPIX_END_128K ; |
||
| 157 | endcase |
||
| 158 | |||
| 159 | |||
| 134 | ddp | 160 | always @(posedge clk) if( hsync_start ) |
| 161 | begin |
||
| 684 | lvd | 162 | if( vcount==vperiod ) |
| 608 | ddp | 163 | begin |
| 134 | ddp | 164 | vcount <= 9'd0; |
| 608 | ddp | 165 | end |
| 134 | ddp | 166 | else |
| 167 | vcount <= vcount + 9'd1; |
||
| 168 | end |
||
| 169 | |||
| 170 | |||
| 171 | |||
| 172 | always @(posedge clk) if( hsync_start ) |
||
| 173 | begin |
||
| 174 | if( vcount==VBLNK_BEG ) |
||
| 175 | vblank <= 1'b1; |
||
| 684 | lvd | 176 | else if( vcount==( (modes_raster==2'b01) ? VBLNK_END_60HZ : VBLNK_END_50HZ ) ) |
| 134 | ddp | 177 | vblank <= 1'b0; |
| 178 | end |
||
| 179 | |||
| 180 | |||
| 181 | always @(posedge clk) |
||
| 182 | begin |
||
| 684 | lvd | 183 | if( vcount==( modes_raster==2'b01 ? VSYNC_BEG_60HZ : VSYNC_BEG_50HZ ) && hsync_start ) |
| 134 | ddp | 184 | vsync <= 1'b1; |
| 684 | lvd | 185 | else if( vcount==( modes_raster==2'b01 ? VSYNC_END_60HZ : VSYNC_END_50HZ ) && line_start ) |
| 134 | ddp | 186 | vsync <= 1'b0; |
| 187 | end |
||
| 188 | |||
| 189 | |||
| 190 | always @(posedge clk) |
||
| 191 | begin |
||
| 684 | lvd | 192 | //if( hint_start && vcount==( modes_raster[1] ? (modes_raster[0] ? INT_BEG_128K : INT_BEG_48K) : INT_BEG ) ) |
| 193 | if( hint_start && vcount==( modes_raster[1] ? (modes_raster[0] ? INT_BEG_128K : INT_BEG_48K) : INT_BEG ) ) |
||
| 134 | ddp | 194 | int_start <= 1'b1; |
| 195 | else |
||
| 196 | int_start <= 1'b0; |
||
| 197 | end |
||
| 198 | |||
| 199 | |||
| 200 | |||
| 201 | always @(posedge clk) if( hsync_start ) |
||
| 202 | begin |
||
| 684 | lvd | 203 | if( vcount==(vpix_beg + (9'd4 & {9{~mode_atm_n_pent}})) ) |
| 134 | ddp | 204 | vpix <= 1'b1; |
| 684 | lvd | 205 | else if( vcount==(vpix_end + (9'd4 & {9{mode_atm_n_pent}})) ) |
| 134 | ddp | 206 | vpix <= 1'b0; |
| 207 | end |
||
| 208 | |||
| 209 | |||
| 210 | endmodule |
||
| 211 |