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

Subversion Repositories othellogame

[/] [othellogame/] [trunk/] [rtl/] [vga_controller.v] - Blame information for rev 2

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 marius_mtm
`timescale 1ns / 1ps
2
//////////////////////////////////////////////////////////////////////////////////
3
// Company: 
4
// Engineer: 
5
// 
6
// Create Date:    23:41:15 04/12/2009 
7
// Design Name: 
8
// Module Name:    vga_controller 
9
// Project Name: The FPGA Othello Game
10
// Target Devices: Spartan3E
11
// Tool versions: 
12
// Description: 
13
//      ro: Acest modul va desena tabla de joc: Va primi la intrare tabelele R,B,M
14
//          -- cele 3 dimensiuni ale jocului Reversi :) ,si va genera valorile RGB 
15
//          corespunzatoare, si doar in momentul in care hv_sync permite asta.
16
//
17
// Dependencies: hv_sync
18
//
19
// Revision: 
20
// Revision 0.01 - File Created
21
// Additional Comments: 
22
//      Marius TIVADAR.
23
//////////////////////////////////////////////////////////////////////////////////
24
module vga_controller(clk,
25
                                                         vga_h_sync,
26
                                                         vga_v_sync,
27
                                                         vga_R,
28
                                                         vga_G,
29
                                                         vga_B,
30
                                                         boardR,
31
                                                         boardB,
32
                                                         boardM,
33
                                                         coordX,
34
                                                         coordY);
35
 
36
/* global clock */
37
input clk;
38
/* Reversi board: R, B, M */
39
input [63:0] boardR;
40
input [63:0] boardB;
41
input [63:0] boardM;
42
/* pozition in board X,Y */
43
input [2:0] coordX;
44
input [2:0] coordY;
45
 
46
/* outputs vga H/V sync, and R,G,B */
47
output vga_h_sync, vga_v_sync, vga_R, vga_G, vga_B;
48
 
49
 
50
/* X,Y screen counters */
51
wire [9:0] cntX;
52
wire [8:0] cntY;
53
 
54
/* registers for R,G,B */
55
reg R, G, B;
56
 
57
reg [2:0] i;
58
reg [2:0] j;
59
 
60
parameter SQUARE_SIZE     = 32;
61
parameter SQUARES         = 8;
62
parameter SQUARE_X_BORDER = 29;
63
parameter SQUARE_Y_BORDER = 28;
64
parameter BOARD_X_OFFSET  = 0;
65
parameter BOARD_Y_OFFSET  = 0;
66
 
67
 
68
/* we instantiate H/V generator */
69
hvsync_gen vga_sync(
70
                                           .clk(clk),
71
                                                .h_sync(vga_h_sync),
72
                                                .v_sync(vga_v_sync),
73
                                                .wcntX(cntX),  // screen counters
74
                                                .wcntY(cntY)
75
                                                );
76
 
77
 
78
 /* draw the board */
79
 always @ (posedge clk)
80
 begin
81
        if (
82
                   (cntX > BOARD_X_OFFSET)
83
                && (cntX < SQUARES * SQUARE_SIZE)
84
                && (cntY > BOARD_Y_OFFSET)
85
                && (cntY < SQUARES * SQUARE_SIZE)
86
                && (cntX % SQUARE_SIZE < SQUARE_X_BORDER)
87
                && (cntY % SQUARE_SIZE < SQUARE_Y_BORDER)
88
 
89
                )
90
          begin
91
                i  <= cntX / SQUARE_SIZE;
92
                j  <= cntY / SQUARE_SIZE;
93
 
94
      /* of course, this could be done all in one equation, but is more visible like this */
95
      /* if i,j = our position, draw the white square */
96
                if ( i == coordX && j == coordY ) begin
97
                        R <= 1;
98
                        B <= 1;
99
                        G <= 1;
100
                end
101
                /* else, draw yellow squares (where current player is allowed to move */
102
                else if ( boardM[j*8 + i] == 1'b1 ) begin
103
                        R <= 1;
104
                        B <= 0;
105
                        G <= 1;
106
                end
107
                /* draw empty squares and/or blue/red squares */
108
                else begin
109
                        R <=  boardR[j*8 + i];
110
                        B <=  boardB[j*8 + i];
111
                        G <= (boardR[j*8 + i] == 0) && (boardB[j*8 + i] == 0);
112
                end
113
        end
114
        /* nothing */
115
        else begin
116
                R <= 0;
117
                B <= 0;
118
                G <= 0;
119
        end
120
 end
121
 
122
/* assign output */
123
assign vga_R = R;
124
assign vga_G = G;
125
assign vga_B = B;
126
 
127
 
128
endmodule

powered by: WebSVN 2.1.0

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