OpenCores
URL https://opencores.org/ocsvn/2d_game_console/2d_game_console/trunk

Subversion Repositories 2d_game_console

[/] [2d_game_console/] [trunk/] [Processor_Quartus/] [Sprite_Shape_Reader.v.bak] - Rev 2

Compare with Previous | Blame | View Log

module Sprite_Shape_Reader(
        clk,
        rst,
        level_counter,
        data_in,
        sprite_id,
        sprite_y,
        V_pos_in,
        H_pos_in,
        
        sprite_shape_out,
        wren_out,
        addr_out,
        level_counter_enable,
        level_counter_reset,
        EstadoAtual
);


        input clk;
        input rst;
        input   [6:0]           level_counter;
        input   [9:0]           H_pos_in;
        input   [9:0]           V_pos_in;
        input   [15:0]  data_in;
        
        input   [383:0] sprite_id;
        input   [639:0] sprite_y;
        
        
        output                  wren_out;
        output  reg     level_counter_enable;
        output  reg     level_counter_reset;
        output  reg     [15:0]  addr_out;
        
        output  [1023:0]        sprite_shape_out;
        
        reg     [5:0]   level_sprite_id;
        reg     [9:0]   level_sprite_y;
        
        reg     [1023:0]        line_A_shape;
        reg     [1023:0]        line_B_shape;
        reg                             line_flag;
        
        parameter       line_A  = 1'b0;
        parameter       line_B  = 1'b1;
        
        assign wren_out = 1'b0;
        assign sprite_shape_out = (line_flag == line_A)? line_B_shape : line_A_shape;
        
        
        /*################################################################*/
        /*############  MAQUINA DE ESTADO                                                       ############*/
        /*############                                                                                                          ############*/
        /*############  LEITURA DOS SHAPES                                                      ############*/
        /*############  SALVOS NA DATA_SEGMENT_RAM                              ############*/
        /*################################################################*/
        
        output  reg     [4:0]           EstadoAtual;
                                reg     [4:0]           EstadoFuturo;

        // Estados
        parameter       Reset                                           = 5'b00000;     // Reset                                                = 0
        parameter       Wait_Line                               = 5'b00001;     // Wait_Line                            = 1
        parameter       Change_Line                             = 5'b00010;     // Change_Line                          = 2
        parameter       Counter_Reset_Off               = 5'b00011;     // Counter_Reset_Off            = 3
        parameter       Get_Level_Info                  = 5'b00100;     // Get_Level_Info                       = 4
        parameter       Test_Shape                              = 5'b00101;     // Test_Shape                           = 5
        parameter       Set_Shape_Address               = 5'b00110;     // Set_Shape_Address            = 6
        parameter       Read_Shape                              = 5'b00111;     // Read_Shape                           = 7
        parameter       Change_Level                    = 5'b01000;     // Change_Level                 = 8
        parameter       Counter_Enable_Off      = 5'b01001;     // Counter_Enable_Off   = 9
        parameter       Test_Level                              = 5'b01010;     // Test_Level                           = 10

        
        // Decodificador de proximo estado
        always @ (V_pos_in, H_pos_in, sprite_y, level_sprite_y, level_counter, EstadoAtual)
        begin
                case (EstadoAtual)
                
                        // Estado 0
                        Reset:
                        begin
                                if(V_pos_in == 31 && H_pos_in == 0)
                                        EstadoFuturo = Wait_Line;
                                        
                                else
                                        EstadoFuturo = Reset;
                        end
                        
                        // Estado 1
                        Wait_Line:
                        begin
                                if(V_pos_in >= 32 && V_pos_in <= 511 && H_pos_in == 0)
                                        EstadoFuturo = Change_Line;
                                else
                                        EstadoFuturo = Wait_Line;
                        end
                        
                        // Estado 2
                        Change_Line:
                        begin
                                EstadoFuturo = Counter_Reset_Off;
                        end
                        
                        // Estado 3
                        Counter_Reset_Off:
                        begin
                                EstadoFuturo = Get_Level_Info;
                        end
                        
                        // Estado 4
                        Get_Level_Info:
                        begin
                                EstadoFuturo = Test_Shape;
                        end
                                                
                        // Estado 5
                        Test_Shape:
                        begin
                                if(V_pos_in >= level_sprite_y-1 && V_pos_in <= level_sprite_y+14)
                                        EstadoFuturo = Set_Shape_Address;
                                else
                                        EstadoFuturo = Change_Level;
                        end
                                                
                        // Estado 6
                        Set_Shape_Address:
                        begin
                                EstadoFuturo = Read_Shape;
                        end
                        
                        // Estado 7
                        Read_Shape:
                        begin
                                EstadoFuturo = Change_Level;
                        end
                        
                        // Estado 8
                        Change_Level:
                        begin
                                EstadoFuturo = Counter_Enable_Off;
                        end
                        
                        // Estado 9
                        Counter_Enable_Off:
                        begin
                                EstadoFuturo = Test_Level;
                        end
                        
                        // Estado 10
                        Test_Level:
                        begin
                                if(level_counter <= 63 && V_pos_in <= 511)
                                        EstadoFuturo = Counter_Reset_Off;
                                else if(level_counter > 63 && V_pos_in > 511)
                                        EstadoFuturo = Reset;
                                else
                                        EstadoFuturo = Wait_Line;
                        end
                        
                        default:
                        begin
                                EstadoFuturo = Reset;
                        end

                endcase

        end


        // Decodificador de saida
        always @ (posedge clk)
        begin
                case (EstadoAtual)
        
                        // Estado 0
                        Reset:
                        begin
                                level_counter_enable <= 1'b0;
                                level_counter_reset <= 1'b1;
                                line_flag <= line_B;
                        end
                        
                        // Estado 1
                        Wait_Line:
                        begin
                                level_counter_enable <= 1'b0;
                                level_counter_reset <= 1'b1;
                        end
                        
                        // Estado 2
                        Change_Line:
                        begin
                                if (line_flag == line_A)
                                        line_flag <= line_B;
                                else
                                        line_flag <= line_A;
                        end
                        
                        // Estado 3
                        Counter_Reset_Off:
                        begin
                                level_counter_enable <= 1'b0;
                                level_counter_reset <= 1'b0;
                        end
                        
                        // Estado 4
                        Get_Level_Info:
                        begin
                                level_sprite_id <= sprite_id[level_counter*6 +: 6];
                                level_sprite_y <= sprite_y[level_counter*10 +: 10];
                        end
                        
                        // Estado 5
                        Test_Shape:
                        begin
                                
                        end
                
                        // Estado 6
                        Set_Shape_Address:
                        begin
                                addr_out <= (level_sprite_id*5'h10) + (V_pos_in - level_sprite_y + 1'b1);
                        end
                        
                        // Estado 7
                        Read_Shape:
                        begin
                                if(line_flag == line_A)
                                        line_A_shape[level_counter*16 +: 16] <= data_in[15:0];
                                else
                                        line_B_shape[level_counter*16 +: 16] <= data_in[15:0];
                        end
                        
                        // Estado 8
                        Change_Level:
                        begin
                                level_counter_enable <= 1'b1;
                                level_counter_reset <= 1'b0;
                        end
                        
                        // Estado 9
                        Counter_Enable_Off:
                        begin
                                level_counter_enable <= 1'b0;
                                level_counter_reset <= 1'b0;
                        end
                        
                        // Estado 10
                        Test_Level:
                        begin
                                
                        end
                        
                        default:
                        begin
                                level_counter_enable <= 1'b0;
                                level_counter_reset <= 1'b1;
                                line_flag <= line_B;
                        end
        
                endcase
        end


        // Atualizacao de registrador de estado e logica de reset
        always @ (posedge clk)
        begin

                if (rst)
                begin
                        EstadoAtual     <= Reset;
                end
        
                else
                begin
                        EstadoAtual     <=      EstadoFuturo;
                end
        
        end

        /*################################################################*/
        /*################################################################*/

        
        
endmodule

Compare with Previous | Blame | View Log

powered by: WebSVN 2.1.0

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