Rev 543 | 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 |
| 334 | lvd | 2 | // |
| 3 | // address generation module for video data fetching |
||
| 333 | lvd | 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 | `include "../include/tune.v" |
||
| 25 | |||
| 334 | lvd | 26 | module video_addrgen( |
| 27 | |||
| 28 | input wire clk, // 28 MHz clock |
||
| 29 | |||
| 30 | |||
| 31 | output reg [20:0] video_addr, // DRAM arbiter signals |
||
| 32 | input wire video_next, // |
||
| 33 | |||
| 34 | |||
| 35 | input wire line_start, // some video sync signals |
||
| 36 | input wire int_start, // |
||
| 37 | input wire vpix, // |
||
| 38 | |||
| 39 | input wire scr_page, // which screen to use |
||
| 40 | |||
| 41 | |||
| 42 | input wire mode_atm_n_pent, // decoded modes |
||
| 43 | input wire mode_zx, // |
||
| 44 | input wire mode_p_16c, // |
||
| 45 | input wire mode_p_hmclr, // |
||
| 46 | // |
||
| 47 | input wire mode_a_hmclr, // |
||
| 48 | input wire mode_a_16c, // |
||
| 335 | lvd | 49 | input wire mode_a_text, // |
| 528 | lvd | 50 | input wire mode_a_txt_1page,// |
| 334 | lvd | 51 | |
| 335 | lvd | 52 | output wire [ 2:0] typos // Y position in text mode symbols |
| 334 | lvd | 53 | ); |
| 54 | |||
| 55 | wire mode_ag; |
||
| 56 | |||
| 57 | assign mode_ag = mode_a_16c | mode_a_hmclr; |
||
| 58 | |||
| 59 | |||
| 60 | |||
| 61 | wire line_init, frame_init; |
||
| 62 | |||
| 63 | wire gnext,tnext,ldaddr; |
||
| 64 | |||
| 360 | lvd | 65 | reg line_start_r; |
| 333 | lvd | 66 | reg frame_init_r; |
| 334 | lvd | 67 | reg line_init_r; |
| 333 | lvd | 68 | |
| 360 | lvd | 69 | always @(posedge clk) |
| 70 | line_start_r <= line_start; |
||
| 71 | |||
| 72 | assign line_init = line_start_r & vpix; |
||
| 334 | lvd | 73 | assign frame_init = int_start; |
| 332 | lvd | 74 | |
| 334 | lvd | 75 | reg [13:0] gctr; |
| 333 | lvd | 76 | |
| 334 | lvd | 77 | reg [7:0] tyctr; // text Y counter |
| 78 | reg [6:0] txctr; // text X counter |
||
| 333 | lvd | 79 | |
| 512 | lvd | 80 | reg not_used; |
| 81 | |||
| 82 | |||
| 83 | |||
| 84 | |||
| 85 | always @(posedge clk) |
||
| 333 | lvd | 86 | frame_init_r <= frame_init; |
| 87 | |||
| 334 | lvd | 88 | always @(posedge clk) |
| 89 | line_init_r <= line_init; |
||
| 333 | lvd | 90 | |
| 91 | |||
| 334 | lvd | 92 | assign gnext = video_next | frame_init_r; |
| 93 | assign tnext = video_next | line_init_r; |
||
| 94 | assign ldaddr = mode_a_text ? tnext : gnext; |
||
| 95 | |||
| 96 | // gfx counter |
||
| 467 | lvd | 97 | // |
| 98 | initial gctr <= 0; |
||
| 99 | // |
||
| 334 | lvd | 100 | always @(posedge clk) |
| 101 | if( frame_init ) |
||
| 102 | gctr <= 0; |
||
| 103 | else if( gnext ) |
||
| 104 | gctr <= gctr + 1; |
||
| 105 | |||
| 106 | |||
| 107 | // text counters |
||
| 108 | always @(posedge clk) |
||
| 109 | if( frame_init ) |
||
| 360 | lvd | 110 | tyctr <= 8'b0011_0111; |
| 334 | lvd | 111 | else if( line_init ) |
| 112 | tyctr <= tyctr + 1; |
||
| 113 | |||
| 114 | always @(posedge clk) |
||
| 115 | if( line_init ) |
||
| 348 | lvd | 116 | txctr <= 7'b000_0000; |
| 334 | lvd | 117 | else if( tnext ) |
| 118 | txctr <= txctr + 1; |
||
| 119 | |||
| 120 | |||
| 335 | lvd | 121 | assign typos = tyctr[2:0]; |
| 334 | lvd | 122 | |
| 335 | lvd | 123 | |
| 334 | lvd | 124 | // zx mode: |
| 125 | // [0] - attr or pix |
||
| 126 | // [4:1] - horiz pos 0..15 (words) |
||
| 127 | // [12:5] - vert pos |
||
| 128 | |||
| 129 | wire [20:0] addr_zx; // standard zx mode |
||
| 130 | wire [20:0] addr_phm; // pentagon hardware multicolor |
||
| 131 | wire [20:0] addr_p16c; // pentagon 16c |
||
| 132 | |||
| 133 | wire [20:0] addr_ag; // atm gfx: 16c (x320) or hard multicolor (x640) - same sequence! |
||
| 134 | |||
| 337 | lvd | 135 | wire [20:0] addr_at; // atm text |
| 334 | lvd | 136 | |
| 137 | wire [11:0] addr_zx_pix; |
||
| 138 | wire [11:0] addr_zx_attr; |
||
| 139 | wire [11:0] addr_zx_p16c; |
||
| 140 | |||
| 141 | |||
| 142 | assign addr_zx_pix = { gctr[12:11], gctr[7:5], gctr[10:8], gctr[4:1] }; |
||
| 143 | |||
| 144 | assign addr_zx_attr = { 3'b110, gctr[12:8], gctr[4:1] }; |
||
| 145 | |||
| 146 | assign addr_zx_p16c = { gctr[13:12], gctr[8:6], gctr[11:9], gctr[5:2] }; |
||
| 147 | |||
| 148 | |||
| 149 | assign addr_zx = { 6'b000001, scr_page, 2'b10, ( gctr[0] ? addr_zx_attr : addr_zx_pix ) }; |
||
| 150 | |||
| 151 | assign addr_phm = { 6'b000001, scr_page, 1'b1, gctr[0], addr_zx_pix }; |
||
| 152 | |||
| 335 | lvd | 153 | assign addr_p16c = { 6'b000001, scr_page, ~gctr[0], gctr[1], addr_zx_p16c }; |
| 334 | lvd | 154 | |
| 155 | |||
| 335 | lvd | 156 | assign addr_ag = { 5'b00000, ~gctr[0], scr_page, 1'b1, gctr[1], gctr[13:2] }; |
| 334 | lvd | 157 | |
| 528 | lvd | 158 | // 5 or 1 +0 or +2 ~4,0 +0k or +2k |
| 159 | // assign addr_at = { 5'b00000, ~txctr[0], scr_page, 1'b1, txctr[1], 2'b00, tyctr[7:3], txctr[6:2] }; |
||
| 160 | // assign addt_et = { 5'b00001, 1'b0 , scr_page, 1'b0, txctr[0], txctr[1], 0, --//00 }; |
||
| 334 | lvd | 161 | |
| 528 | lvd | 162 | assign addr_at = { 4'b0000, |
| 163 | mode_a_txt_1page, // if 1page, 8 and 10 pages instead of 5,1 and 7,3 |
||
| 164 | mode_a_txt_1page ? 1'b0 : ~txctr[0], // 5 or 1 pages for usual mode |
||
| 165 | scr_page, // actually not used |
||
| 166 | ~mode_a_txt_1page, // 5,1 (not 4,0) pages for usual mode |
||
| 167 | mode_a_txt_1page ? txctr[0] : txctr[1], // 0,+2 interleave for even-odd or 0,+1 for 1page |
||
| 168 | mode_a_txt_1page ? txctr[1] : 1'b0, // sym/attr interleave 0,+1 for 1page |
||
| 169 | 1'b0, |
||
| 170 | tyctr[7:3], |
||
| 171 | txctr[6:2] |
||
| 172 | }; |
||
| 334 | lvd | 173 | |
| 528 | lvd | 174 | |
| 175 | |||
| 176 | |||
| 177 | |||
| 178 | |||
| 179 | |||
| 180 | |||
| 181 | |||
| 182 | |||
| 183 | |||
| 467 | lvd | 184 | initial video_addr <= 0; |
| 185 | // |
||
| 334 | lvd | 186 | always @(posedge clk) if( ldaddr ) |
| 187 | begin |
||
| 512 | lvd | 188 | { video_addr[20:15], not_used, video_addr[13:0] } <= |
| 334 | lvd | 189 | ( {21{mode_zx }} & addr_zx ) | |
| 190 | ( {21{mode_p_16c }} & addr_p16c) | |
||
| 191 | ( {21{mode_p_hmclr}} & addr_phm ) | |
||
| 192 | ( {21{mode_ag }} & addr_ag ) | |
||
| 337 | lvd | 193 | ( {21{mode_a_text }} & addr_at ) ; |
| 334 | lvd | 194 | end |
| 195 | |||
| 513 | lvd | 196 | always @(posedge clk) |
| 197 | video_addr[14] <= scr_page; |
||
| 334 | lvd | 198 | |
| 513 | lvd | 199 | |
| 200 | |||
| 334 | lvd | 201 | endmodule |
| 202 |