OpenCores
URL https://opencores.org/ocsvn/ag_6502/ag_6502/trunk

Subversion Repositories ag_6502

[/] [ag_6502/] [trunk/] [fighter/] [ag_video.v] - Blame information for rev 5

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 3 olegodints
`timescale 1ns / 1ps
2
//////////////////////////////////////////////////////////////////////////////////
3
// Company:   BMSTU
4
// Engineer:  Oleg Odintsov
5
// 
6
// Create Date:    11:44:32 02/24/2012 
7
// Design Name: 
8
// Module Name:    ag_video 
9
// Project Name:    Agat Hardware Project
10
// Target Devices: 
11
// Tool versions: 
12
// Description: 
13
//
14
// Dependencies: 
15
//
16
// Revision: 
17
// Revision 0.01 - File Created
18
// Additional Comments: 
19
//
20
//////////////////////////////////////////////////////////////////////////////////
21
 
22
module FONT_ROM(input[10:0] adr, input cs, output[7:0] DO);
23
        reg[7:0] mem[0:2047];
24
        assign DO = cs?mem[adr]:8'bZ;
25
        initial begin
26
                `include "agathe7.v"
27
        end
28
endmodule
29
 
30
 
31
module ag_video(input clk50,
32
                        input[7:0] vmode,
33
                        output clk_vram,
34
                        output[13:0] AB2, input[15:0] DI2,
35
                        output[4:0] vga_bus);
36
        parameter
37
                HGR_WHITE = 4'b1111, // RGBX
38
                HGR_BLACK = 4'b0000,
39
                TEXT_COLOR= 4'b1111,
40
                TEXT_BACK = 4'b0000;
41
 
42
        wire clk25;
43
        assign clk_vram = ~clk25;
44
 
45
        wire[0:15] rDI2 = DI2;
46
 
47
//      assign AB2 = 14'b0;
48
 
49
        clk_div#2 cd2(clk50, clk25);
50
 
51
 
52
        wire [9:0] hpos;
53
        wire [8:0] vpos;
54
        wire video_on;
55
 
56
        reg[8:0] hpos1;
57
        reg[7:0] vpos1;
58
 
59
        wire[1:0] VTYPE = vmode[1:0];
60
        // for 64K+ - variant
61
//      wire[2:0] PAGE_ADDR = {vmode[6], vmode[6]? 1'b0: vmode[5], vmode[4]};
62
        // for 32K-variant
63
        wire[2:0] PAGE_ADDR = {0, vmode[5], vmode[4]};
64
        wire[1:0] SUBPAGE_ADDR = vmode[3:2];
65
 
66
        wire VTYPE_HGR = (VTYPE == 2'b11);
67
        wire VTYPE_MGR = (VTYPE == 2'b01);
68
        wire VTYPE_LGR = (VTYPE == 2'b00);
69
        wire VTYPE_TXT = (VTYPE == 2'b10);
70
        wire VTYPE_T32 = VTYPE_TXT && !vmode[7];
71
        wire VTYPE_T64 = VTYPE_TXT && vmode[7];
72
        wire VTYPE_T64_INV = VTYPE_T64 && !SUBPAGE_ADDR[0];
73
 
74
        wire[13:0] HGR_ADDR = {PAGE_ADDR[1:0], vpos1, hpos1[8:5]};
75
        wire[3:0] HGR_BITNO = hpos1[4:1];
76
        wire HGR_BIT = rDI2[HGR_BITNO];
77
        wire[3:0] HGR_COLOR = HGR_BIT? HGR_WHITE: HGR_BLACK;
78
 
79
        wire[13:0] MGR_ADDR = {PAGE_ADDR[1:0], vpos1[7:1], hpos1[8:4]};
80
        wire[1:0] MGR_BLOCKNO = hpos1[3:2];
81
 
82
        wire[13:0] LGR_ADDR = {PAGE_ADDR[1:0], SUBPAGE_ADDR, vpos1[7:2], hpos1[8:5]};
83
        wire[1:0] LGR_BLOCKNO = hpos1[4:3];
84
 
85
        wire[1:0] GR_BLOCKNO = VTYPE_MGR?MGR_BLOCKNO:
86
                                                                                                LGR_BLOCKNO;
87
 
88
        wire[3:0] GR_COLOR = (GR_BLOCKNO == 2'b00)? {DI2[12], DI2[13], DI2[14], DI2[15]}:
89
                                                                (GR_BLOCKNO == 2'b01)? {DI2[8], DI2[9], DI2[10], DI2[11]}:
90
                                                                (GR_BLOCKNO == 2'b10)? {DI2[4], DI2[5], DI2[6], DI2[7]}:
91
                                                                                                                                {DI2[0], DI2[1], DI2[2], DI2[3]};
92
 
93
        wire[13:0] TEXT_ADDR = {PAGE_ADDR[1:0], SUBPAGE_ADDR, vpos1[7:3], hpos1[8:4]};
94
 
95
 
96
        wire h_phase = hpos1[1:0]?0:1;
97
        reg[0:0] h_cnt = 0;
98
        wire[0:0] h_delay = h_phase?1'd1:1'd0;
99
 
100
        wire v_phase = vpos1[2:0]?1:0;
101
        reg[0:0] v_cnt = 0;
102
        wire[0:0] v_delay = v_phase?1'd1:1'd0;
103
 
104
        wire[7:0] font_char;
105
        wire[2:0] font_y, font_x;
106
        wire[10:0] font_ab = {font_char, font_y};
107
        wire[0:7] font_db;// = 8'b0;
108
        wire font_pix = font_db[font_x];
109
 
110
        FONT_ROM font(font_ab, 1, font_db);
111
 
112
 
113
        integer flash_cnt = 0;
114
        reg flash_reg = 0;
115
        wire    inverse = VTYPE_T64?VTYPE_T64_INV:!{DI2[5],DI2[3]},
116
                        flash = VTYPE_T64?font_db[7]:!{DI2[5],~DI2[3]};
117
        wire inv_mode = inverse || (flash && flash_reg);
118
 
119
 
120
        assign font_x = VTYPE_T64?hpos1[2:0]:hpos1[3:1];
121
        assign font_y = vpos1[2:0];
122
        assign font_char = (VTYPE_T64 && hpos1[3])? DI2[7:0]: DI2[15:8];
123
        wire[3:0] T_COLOR = VTYPE_T64? TEXT_COLOR: {DI2[0], DI2[1], DI2[2], DI2[4]};
124
 
125
        assign AB2 = VTYPE_HGR? HGR_ADDR:
126
                                        VTYPE_MGR? MGR_ADDR:
127
                                        VTYPE_LGR? LGR_ADDR:
128
                                        TEXT_ADDR;
129
 
130
        wire[2:0] color = VTYPE_HGR? HGR_COLOR[3:1]:
131
                                                        (VTYPE_MGR | VTYPE_LGR)? GR_COLOR[3:1]:
132
                                                        ((font_pix^inv_mode)?T_COLOR[3:1]: TEXT_BACK);
133
 
134
        reg[2:0] color_reg;
135
 
136
        always @(posedge clk25) begin
137
                if (!vga_bus[1]) begin
138
                        hpos1 <= 0;
139
                        h_cnt <= 1;
140
                end else if (video_on) begin
141
                        if (!h_cnt) begin
142
                                h_cnt <= h_delay;
143
                                hpos1 <= hpos1 + 1;
144
                        end else h_cnt <= h_cnt - 1;
145
                end
146
        end
147
 
148
        always @(posedge clk25) color_reg <= color;
149
 
150
        always @(posedge video_on) begin
151
                if (!vpos) begin
152
                        vpos1 <= 0;
153
                        v_cnt <= 1;
154
                end else begin
155
                        if (!v_cnt) begin
156
                                v_cnt <= v_delay;
157
                                vpos1 <= vpos1 + 1;
158
                        end else v_cnt <= v_cnt - 1;
159
                end
160
        end
161
 
162
        always @(posedge vga_bus[0]) begin
163
                if (flash_cnt) flash_cnt <= flash_cnt - 1;
164
                else begin
165
                        flash_cnt <= 11;
166
                        flash_reg <= ~flash_reg;
167
                end
168
        end
169
 
170
        assign {vga_bus[4], vga_bus[3], vga_bus[2]} = video_on?color_reg:3'b000;
171
 
172
        video_counters cnt(clk25, vga_bus[0], vga_bus[1], video_on, hpos, vpos);
173
endmodule

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.