Subversion Repositories pentevo

Rev

Rev 543 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
334 lvd 1
`include "../include/tune.v"
2
 
3
// Pentevo project (c) NedoPC 2011
4
//
5
// renders fetched video data to the pixels
6
 
7
module video_render(
8
 
9
        input  wire        clk, // 28 MHz clock
10
 
11
 
12
        input  wire [63:0] pic_bits, // video data from fetcher
13
 
336 lvd 14
        input  wire        fetch_sync, // synchronizes pixel rendering -
15
                                       // coincides with cbeg!!!
16
 
17
        input  wire        cbeg,
334 lvd 18
        input  wire        post_cbeg, // pixel strobed and
336 lvd 19
        input  wire        pre_cend,
334 lvd 20
        input  wire        cend,      // general sync
336 lvd 21
 
334 lvd 22
        input  wire        int_start, // for flash gen
325 lvd 23
 
336 lvd 24
        input  wire [ 2:0] typos, // Y pos in text symbols
325 lvd 25
 
334 lvd 26
        output wire [ 3:0] pixels, // output pixels
27
 
28
 
336 lvd 29
 
395 lvd 30
        input  wire [10:0] fnt_a,
31
        input  wire [ 7:0] fnt_d,
32
        input  wire        fnt_wr,
33
 
34
 
35
 
36
 
334 lvd 37
        input  wire        mode_atm_n_pent, // decoded modes
336 lvd 38
 
334 lvd 39
        input  wire        mode_zx,         //
40
        input  wire        mode_p_16c,      //
41
        input  wire        mode_p_hmclr,    //
42
                                            //
43
        input  wire        mode_a_hmclr,    //
44
        input  wire        mode_a_16c,      //
45
        input  wire        mode_a_text,     //
336 lvd 46
 
543 lvd 47
        input  wire        mode_pixf_14,    //
48
 
49
 
50
        output wire [ 7:0] fontrom_readback
334 lvd 51
);
52
 
53
 
325 lvd 54
        reg [4:0] flash_ctr;
55
        wire flash;
336 lvd 56
 
325 lvd 57
        initial
58
        begin
59
                flash_ctr = 0;
60
        end
336 lvd 61
 
325 lvd 62
        always @(posedge clk) if( int_start )
63
        begin
64
                flash_ctr <= flash_ctr + 1;
65
        end
66
        assign flash = flash_ctr[4];
67
 
68
 
69
 
334 lvd 70
 
336 lvd 71
 
334 lvd 72
        // fetched data divided in bytes
73
        wire [7:0] bits [0:7];
74
 
75
        assign bits[0] = pic_bits[ 7:0 ];
76
        assign bits[1] = pic_bits[15:8 ];
77
        assign bits[2] = pic_bits[23:16];
78
        assign bits[3] = pic_bits[31:24];
79
        assign bits[4] = pic_bits[39:32];
80
        assign bits[5] = pic_bits[47:40];
81
        assign bits[6] = pic_bits[55:48];
82
        assign bits[7] = pic_bits[63:56];
83
 
84
 
85
 
336 lvd 86
        reg [1:0] gnum; // pixel group number
87
        reg [2:0] pnum; // pixel number
88
        wire [1:0] gadd;
89
        wire [2:0] padd;
90
        wire ginc;
334 lvd 91
 
336 lvd 92
        wire modes_16c;
334 lvd 93
 
339 lvd 94
        wire modes_zxattr;
338 lvd 95
 
339 lvd 96
 
334 lvd 97
        wire   ena_pix;
339 lvd 98
        assign ena_pix = cend | (mode_pixf_14 & post_cbeg);
334 lvd 99
 
336 lvd 100
 
101
        assign modes_16c = mode_p_16c | mode_a_16c;
102
 
339 lvd 103
        assign modes_zxattr = mode_zx | mode_p_hmclr;
104
 
336 lvd 105
        assign {ginc, padd} = {1'b0, pnum} + {2'b00, modes_16c, ~modes_16c};
106
 
334 lvd 107
        always @(posedge clk) if( ena_pix )
336 lvd 108
        if( fetch_sync )
109
                pnum <= 3'b000;
110
        else
111
                pnum <= padd;
334 lvd 112
 
113
 
339 lvd 114
        assign gadd = gnum + ( {modes_zxattr,~modes_zxattr} & {2{ginc}} );
336 lvd 115
 
116
        always @(posedge clk) if( ena_pix )
117
        if( fetch_sync )
118
                gnum <= 2'b00;
119
        else
120
                gnum <= gadd;
121
 
122
 
123
 
124
 
125
        wire [15:0] pgroup; // pixel group
395 lvd 126
        wire [7:0] pixbyte, symbyte, attrbyte;
336 lvd 127
        wire [7:0] pix16_2 [0:1];
128
        wire [3:0] pix16   [0:3];
129
 
130
        wire pixbit; // pixel bit, for attr modes
131
        wire [3:0] pix0, pix1; // colors for bit=0 and bit=1, for attr modes
132
 
337 lvd 133
        wire [3:0] apix, c16pix;
134
 
135
 
336 lvd 136
        assign pgroup = { bits[ {gnum[0], 1'b0, gnum[1]} ] ,
137
                          bits[ {gnum[0], 1'b1, gnum[1]} ] };
138
 
139
        assign pixbyte  = pgroup[15:8];
140
        assign attrbyte = pgroup[ 7:0];
141
 
142
 
143
        assign pix16_2[0] = pgroup[ 7:0];
144
        assign pix16_2[1] = pgroup[15:8];
145
 
146
        assign pix16[0] = { pix16_2[0][6], pix16_2[0][2:0] };
147
        assign pix16[1] = { pix16_2[0][7], pix16_2[0][5:3] };
148
        assign pix16[2] = { pix16_2[1][6], pix16_2[1][2:0] };
149
        assign pix16[3] = { pix16_2[1][7], pix16_2[1][5:3] };
150
 
151
 
338 lvd 152
        assign pixbit = mode_a_text ? symbyte[~pnum] : pixbyte[~pnum];
336 lvd 153
 
339 lvd 154
        assign pix0 = { (modes_zxattr ? attrbyte[6] : attrbyte[7]), attrbyte[5:3] }; // paper
337 lvd 155
        assign pix1 = { attrbyte[6], attrbyte[2:0] }; // ink
336 lvd 156
 
157
 
339 lvd 158
        assign apix = ( pixbit^(modes_zxattr & flash & attrbyte[7]) ) ? pix1 : pix0;
338 lvd 159
 
337 lvd 160
        assign c16pix = pix16[ pnum[2:1] ];
336 lvd 161
 
162
 
163
 
337 lvd 164
        assign pixels = modes_16c ? c16pix : apix;
165
 
166
 
395 lvd 167
 
168
 
169
        wire rom_ena;
350 lvd 170
        assign rom_ena = ena_pix & ginc;
349 lvd 171
 
395 lvd 172
        video_fontrom video_fontrom(
336 lvd 173
 
395 lvd 174
                .clock (clk ),
396 lvd 175
                /*.enable(1'b1),*/
395 lvd 176
 
177
                .data     (fnt_d ),
178
                .wraddress(fnt_a ),
179
                .wren     (fnt_wr),
180
 
181
                .rdaddress( {pixbyte, typos} ),
182
                .rden     ( rom_ena          ),
183
                .q        ( symbyte          )
184
        );
185
 
186
 
543 lvd 187
        assign fontrom_readback = symbyte;
188
 
189
 
334 lvd 190
endmodule
191