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] - Rev 2
Compare with Previous | Blame | View Log
module Sprite_Shape_Reader( clock, reset, mem_grant, sprite_id, sprite_y, mem_q, V_pos, H_pos, mem_addr, mem_wren, mem_req, sprite_shape, level_counter, level_sprite_id, level_sprite_y, line_A_shape, line_B_shape, line_flag, EstadoAtual, EstadoFuturo, cpu_sleep ); input clock; input reset; input mem_grant; input [9:0] H_pos; input [9:0] V_pos; input [15:0] mem_q; input [383:0] sprite_id; input [639:0] sprite_y; output reg cpu_sleep; output reg mem_req; output reg mem_wren; output reg [6:0] level_counter; output reg [5:0] level_sprite_id; output reg [9:0] level_sprite_y; output reg [15:0] mem_addr; output reg [1023:0] line_A_shape; output reg [1023:0] line_B_shape; output reg line_flag; output [1023:0] sprite_shape; parameter line_A = 1'b0; parameter line_B = 1'b1; assign sprite_shape = (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; output 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 Get_Level_Info = 5'b00011; // Get_Level_Info = 3 parameter Set_Shape_Address = 5'b00100; // Set_Shape_Address = 4 parameter Wait_Mem_1 = 5'b00101; // Wait_Mem_1 = 5 parameter Wait_Mem_2 = 5'b00110; // Wait_Mem_2 = 6 parameter Read_Shape = 5'b00111; // Read_Shape = 7 parameter Change_Level = 5'b01000; // Change_Level = 8 // Decodificador de proximo estado always @ (*) begin case (EstadoAtual) // Estado 0 Reset: begin if (V_pos == 31 && H_pos == 0) EstadoFuturo = Wait_Line; else EstadoFuturo = Reset; end // Estado 1 Wait_Line: begin if (V_pos >= 32 && V_pos <= 511 && H_pos == 0) EstadoFuturo = Change_Line; else EstadoFuturo = Wait_Line; end // Estado 2 Change_Line: begin EstadoFuturo = Get_Level_Info; end // Estado 3 Get_Level_Info: begin if ( (V_pos >= level_sprite_y-1) && (V_pos <= level_sprite_y+14) ) EstadoFuturo = Set_Shape_Address; else EstadoFuturo = Change_Level; end // Estado 4 Set_Shape_Address: begin if (mem_grant) EstadoFuturo = Wait_Mem_1; else EstadoFuturo = Set_Shape_Address; end // Estado 5 Wait_Mem_1: begin EstadoFuturo = Wait_Mem_2; end // Estado 6 Wait_Mem_2: begin EstadoFuturo = Read_Shape; end // Estado 7 Read_Shape: begin EstadoFuturo = Change_Level; end // Estado 8 Change_Level: begin if ( (level_counter <= 63) && (V_pos <= 511) ) EstadoFuturo = Get_Level_Info; else if ( (level_counter > 63) && (V_pos >= 511) ) EstadoFuturo = Reset; else EstadoFuturo = Wait_Line; end default: begin EstadoFuturo = Reset; end endcase end // Decodificador de saida always @ (*) begin // Default Assignments cpu_sleep = 1; mem_req = 0; mem_wren = 0; case (EstadoAtual) // Estado 0 Reset: begin cpu_sleep = 0; end // Estado 1 Wait_Line: begin end // Estado 2 Change_Line: begin end // Estado 3 Get_Level_Info: begin end // Estado 4 Set_Shape_Address: begin mem_req = 1; end // Estado 5 Wait_Mem_1: begin mem_req = 1; end // Estado 6 Wait_Mem_2: begin mem_req = 1; end // Estado 7 Read_Shape: begin mem_req = 1; end // Estado 8 Change_Level: begin end default: begin end endcase end // Atualizacao de registrador de estado e logica de reset always @ (posedge clock) begin if (reset) begin EstadoAtual <= Reset; end else begin EstadoAtual <= EstadoFuturo; // Estado 0 = Reset if (EstadoFuturo == Reset) begin level_counter <= 7'b0000000; line_flag <= line_B; end // Estado 1 = Wait_Line if (EstadoFuturo == Wait_Line) begin level_counter <= 7'b0000000; end // Estado 2 = Change_Line if (EstadoFuturo == Change_Line) begin if (line_flag == line_A) line_flag <= line_B; else line_flag <= line_A; end // Estado 3 = Get_Level_Info if (EstadoFuturo == Get_Level_Info) begin level_sprite_id <= sprite_id[level_counter*6 +: 6]; level_sprite_y <= sprite_y[level_counter*10 +: 10]; end // Estado 4 = Set_Shape_Address if (EstadoFuturo == Set_Shape_Address) begin mem_addr <= (level_sprite_id*5'h10) + (V_pos - level_sprite_y + 1'b1); end // Estado 7 = Read_Shape if (EstadoFuturo == Read_Shape) begin if(line_flag == line_A) line_A_shape[level_counter*16 +: 16] <= mem_q[15:0]; else line_B_shape[level_counter*16 +: 16] <= mem_q[15:0]; end // Estado 8 = Change_Level if (EstadoFuturo == Change_Level) begin level_counter <= level_counter + 1'b1; end end end /*################################################################*/ /*################################################################*/ endmodule