Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //-------------------------------------------------------------------------
- // Ball.sv --
- // Viral Mehta --
- // Spring 2005 --
- // --
- // Modified by Stephen Kempf 03-01-2006 --
- // 03-12-2007 --
- // Translated by Joe Meng 07-07-2013 --
- // Modified by Po-Han Huang 12-08-2017 --
- // Spring 2018 Distribution --
- // --
- // For use with ECE 385 Lab 8 --
- // UIUC ECE Department --
- //-------------------------------------------------------------------------
- module PinkGhost ( //input logic [9:0] Ghost_X_start_TEST, Ghost_Y_start_TEST,
- input [2:0] mem_out [0:135575],
- input logic [7:0] SW,
- input Clk, // 50 MHz clock
- Reset, // Active-high reset signal
- frame_clk, // The clock indicating a new frame (~60Hz)
- input [9:0] DrawX, DrawY, // Current pixel coordinates
- // output logic is_pacMan , // Whether current pixel belongs to pacman or background
- output [18:0] address,
- output [9:0] PinkGhost_X_out,
- output [9:0] PinkGhost_Y_out
- );
- assign PinkGhost_X_out = Ghost_X_start;
- assign PinkGhost_Y_out = Ghost_Y_start;
- //Desired start location of drawn sprite
- logic [9:0] Ghost_X_OGstart = 10'd283; // Center position on the X axis
- logic [9:0] Ghost_Y_OGstart = 10'd111;
- logic [9:0] Ghost_X_start = 10'd283; // Center position on the X axis
- logic [9:0] Ghost_Y_start = 10'd111; // Center position on the Y axis
- //Pac to the right
- parameter [9:0] Ghost_X_eyesRight = 10'd3;
- parameter [9:0] Ghost_Y_eyesRight = 10'd143;
- parameter [9:0] Ghost_X_eyesMoreRight = 10'd20; // offset horizontal
- parameter [9:0] Ghost_Y_eyesMoreRight = 10'd143; // offset vertical
- //Pac to the left
- parameter [9:0] Ghost_X_eyesLeft = 10'd37;
- parameter [9:0] Ghost_Y_eyesLeft = 10'd143;
- parameter [9:0] Ghost_X_eyesMoreLeft = 10'd54; // offset horizontal
- parameter [9:0] Ghost_Y_eyesMoreLeft = 10'd143;
- //Pac to UP
- parameter [9:0] Ghost_X_eyesUp = 10'd71;
- parameter [9:0] Ghost_Y_eyesUp = 10'd143;
- parameter [9:0] Ghost_X_eyesMoreUp = 10'd88; // offset horizontal
- parameter [9:0] Ghost_Y_eyesMoreUp = 10'd143; // offset vertical
- //Pac to Down
- parameter [9:0] Ghost_X_eyesDown = 10'd105;
- parameter [9:0] Ghost_Y_eyesDown = 10'd143;
- parameter [9:0] Ghost_X_eyesMoreDown = 10'd122; // offset horizontal
- parameter [9:0] Ghost_Y_eyesMoreDown = 10'd143;
- //Closed Used by Everyone
- parameter [9:0] Ghost_X_closed = 10'd2; // offset horizontal
- parameter [9:0] Ghost_Y_closed = 10'd85; // offset vertical
- //For Right
- logic [9:0] new_x_eyesRight; // offset horizontal
- logic [9:0] new_y_eyesRight; // offset vertical
- logic [9:0] new_x_eyesMoreRight; // offset horizontal
- logic [9:0] new_y_eyesMoreRight; // offset vertical
- //For Left
- logic [9:0] new_x_eyesLeft; // offset horizontal
- logic [9:0] new_y_eyesLeft; // offset vertical
- logic [9:0] new_x_eyesMoreLeft; // offset horizontal
- logic [9:0] new_y_eyesMoreLeft; // offset vertical
- //For Up
- logic [9:0] new_x_eyesUp; // offset horizontal
- logic [9:0] new_y_eyesUp; // offset vertical
- logic [9:0] new_x_eyesMoreUp; // offset horizontal
- logic [9:0] new_y_eyesMoreUp; // offset vertical
- //For Down
- logic [9:0] new_x_eyesDown; // offset horizontal
- logic [9:0] new_y_eyesDown; // offset vertical
- logic [9:0] new_x_eyesMoreDown; // offset horizontal
- logic [9:0] new_y_eyesMoreDown; // offset vertical
- parameter [9:0] Ghost_X_Min = 10'd0; // Leftmost point on the X axis
- parameter [9:0] Ghost_X_Max = 10'd639; // Rightmost point on the X axis
- parameter [9:0] Ghost_Y_Min = 10'd0; // Topmost point on the Y axis
- parameter [9:0] Ghost_Y_Max = 10'd479; // Bottommost point on the Y axis
- parameter [9:0] Ghost_X_Step = 10'd1; // Step size on the X axis
- parameter [9:0] Ghost_Y_Step = 10'd1; // Step size on the Y axis
- logic [6:0] flash_counter = 7'b0000000;
- logic [6:0] counter_TOTAL = 7'b1111111;
- ///Update going right
- logic [18:0] eyesRight;
- logic [18:0] eyesMoreRight;
- assign new_x_eyesRight = DrawX - Ghost_X_start + Ghost_X_eyesRight;
- assign new_y_eyesRight = DrawY - Ghost_Y_start + Ghost_Y_eyesRight;
- assign new_x_eyesMoreRight = DrawX - Ghost_X_start + Ghost_X_eyesMoreRight;
- assign new_y_eyesMoreRight = DrawY - Ghost_Y_start + Ghost_Y_eyesMoreRight;
- ///Update going left
- logic [18:0] eyesLeft;
- logic [18:0] eyesMoreLeft;
- assign new_x_eyesLeft = DrawX - Ghost_X_start + Ghost_X_eyesLeft;
- assign new_y_eyesLeft = DrawY - Ghost_Y_start + Ghost_Y_eyesLeft;
- assign new_x_eyesMoreLeft = DrawX - Ghost_X_start + Ghost_X_eyesMoreLeft;
- assign new_y_eyesMoreLeft = DrawY - Ghost_Y_start + Ghost_Y_eyesMoreLeft;
- ///Update going Up
- logic [18:0] eyesUp;
- logic [18:0] eyesMoreUp;
- assign new_x_eyesUp = DrawX - Ghost_X_start + Ghost_X_eyesUp;
- assign new_y_eyesUp = DrawY - Ghost_Y_start + Ghost_Y_eyesUp;
- assign new_x_eyesMoreUp = DrawX - Ghost_X_start + Ghost_X_eyesMoreUp;
- assign new_y_eyesMoreUp = DrawY - Ghost_Y_start + Ghost_Y_eyesMoreUp;
- ///Update going Down
- logic [18:0] eyesDown;
- logic [18:0] eyesMoreDown;
- assign new_x_eyesDown = DrawX - Ghost_X_start + Ghost_X_eyesDown;
- assign new_y_eyesDown = DrawY - Ghost_Y_start + Ghost_Y_eyesDown;
- assign new_x_eyesMoreDown = DrawX - Ghost_X_start + Ghost_X_eyesMoreDown;
- assign new_y_eyesMoreDown = DrawY - Ghost_Y_start + Ghost_Y_eyesMoreDown;
- //Right Addresses
- assign eyesRight = (new_y_eyesRight * 538) + new_x_eyesRight;
- assign eyesMoreRight = (new_y_eyesMoreRight * 538) + new_x_eyesMoreRight;
- //Left Addresses
- assign eyesLeft = (new_y_eyesLeft * 538) + new_x_eyesLeft;
- assign eyesMoreLeft = (new_y_eyesMoreLeft * 538) + new_x_eyesMoreLeft;
- //Up Addresses
- assign eyesUp = (new_y_eyesUp * 538) + new_x_eyesUp;
- assign eyesMoreUp = (new_y_eyesMoreUp * 538) + new_x_eyesMoreUp;
- //Down Addresses
- assign eyesDown = (new_y_eyesDown * 538) + new_x_eyesDown;
- assign eyesMoreDown = (new_y_eyesMoreDown * 538) + new_x_eyesMoreDown;
- always_ff @ (posedge frame_clk)
- begin
- //Ghost_Y_start <= Ghost_Y_start +1;
- flash_counter <= flash_counter + 1'b1;
- if(flash_counter == counter_TOTAL)
- begin
- flash_counter <= 0;
- end
- end
- always_comb
- begin
- if(currDirec_in == 4'b0000)
- begin
- if((DrawX >= Ghost_X_start) && (DrawX <=Ghost_X_start + 13) && (DrawY >= Ghost_Y_start) && (DrawY <= Ghost_Y_start+13) )
- address = eyesMoreRight;
- else
- address = 19'd0;
- end
- else if(currDirec == 4'b0010)
- begin
- if( (DrawX >= Ghost_X_start) && (DrawX <= Ghost_X_start + 13) && (DrawY >= Ghost_Y_start) && (DrawY <= Ghost_Y_start + 13) && (flash_counter < 7'b0101001 ) )
- address = eyesMoreRight;
- else if((DrawX >= Ghost_X_start) && (DrawX <= Ghost_X_start + 13) && (DrawY >= Ghost_Y_start) && (DrawY <= Ghost_Y_start + 13) && (flash_counter < 7'b1010010 ))
- address = eyesRight;
- else if((DrawX >= Ghost_X_start) && (DrawX <= Ghost_X_start + 13) && (DrawY >= Ghost_Y_start) && (DrawY <= Ghost_Y_start+13) && (flash_counter > 7'b1010010 ))
- address = eyesRight;
- else
- begin
- address = 19'd0;
- end
- end
- else if(currDirec == 4'b1000 )
- begin
- if( (DrawX >= Ghost_X_start) && (DrawX <= Ghost_X_start + 13) && (DrawY >= Ghost_Y_start) && (DrawY <= Ghost_Y_start+13) && (flash_counter < 7'b0101001 ) )
- address = eyesMoreLeft;
- else if((DrawX >= Ghost_X_start) && (DrawX <= Ghost_X_start + 13) && (DrawY >= Ghost_Y_start) && (DrawY <= Ghost_Y_start+13) && (flash_counter < 7'b1010010 ))
- address = eyesLeft;
- else if((DrawX >= Ghost_X_start) && (DrawX <= Ghost_X_start + 13) && (DrawY >= Ghost_Y_start) && (DrawY <= Ghost_Y_start+13) && (flash_counter > 7'b1010010 ))
- address = eyesLeft;
- else
- begin
- address = 19'd0;
- end
- end
- else if(currDirec == 4'b0001 )
- begin
- if( (DrawX >= Ghost_X_start) && (DrawX <= Ghost_X_start + 13) && (DrawY >= Ghost_Y_start) && (DrawY <= Ghost_Y_start+13) && (flash_counter < 7'b0101001 ) )
- address = eyesMoreDown;
- else if((DrawX >= Ghost_X_start) && (DrawX <= Ghost_X_start + 13) && (DrawY >= Ghost_Y_start) && (DrawY <= Ghost_Y_start+13) && (flash_counter < 7'b1010010 ))
- address = eyesDown;
- else if((DrawX >= Ghost_X_start) && (DrawX <= Ghost_X_start + 13) && (DrawY >= Ghost_Y_start) && (DrawY <= Ghost_Y_start+13) && (flash_counter > 7'b1010010 ))
- address = eyesDown;
- else
- begin
- address = 19'd0;
- end
- end
- //
- else if(currDirec == 4'b0100 )
- begin
- if( (DrawX >= Ghost_X_start) && (DrawX <= Ghost_X_start + 13) && (DrawY >= Ghost_Y_start) && (DrawY <= Ghost_Y_start+13) && (flash_counter < 7'b0101001 ) )
- address = eyesMoreUp;
- else if((DrawX >= Ghost_X_start) && (DrawX <= Ghost_X_start + 13) && (DrawY >= Ghost_Y_start) && (DrawY <= Ghost_Y_start+13) && (flash_counter < 7'b1010010 ))
- address = eyesUp;
- else if((DrawX >= Ghost_X_start) && (DrawX <= Ghost_X_start + 13) && (DrawY >= Ghost_Y_start) && (DrawY <= Ghost_Y_start+13) && (flash_counter > 7'b1010010 ))
- address = eyesUp;
- else
- begin
- address = 19'd0;
- end
- end
- else
- begin
- address = 19'd0;
- end
- end
- //
- // //////// Do not modify the always_ff blocks. ////////
- // Detect rising edge of frame_clk
- logic frame_clk_delayed, frame_clk_rising_edge;
- always_ff @ (posedge Clk) begin
- frame_clk_delayed <= frame_clk;
- frame_clk_rising_edge <= (frame_clk == 1'b1) && (frame_clk_delayed == 1'b0);
- end
- logic [9:0] Ghost_Y_start_in;
- logic [9:0] Ghost_X_start_in;
- logic [3:0] currDirec;
- logic [3:0] currDirec_in;
- // Update registers
- always_ff @ (posedge Clk)
- begin
- if (Reset)
- begin
- Ghost_X_start <= Ghost_X_OGstart;
- Ghost_Y_start <= Ghost_Y_OGstart;
- currDirec <= 4'b0000;
- end
- else
- begin
- Ghost_Y_start <= Ghost_Y_start_in;
- Ghost_X_start <= Ghost_X_start_in;
- currDirec <= currDirec_in;
- end
- end
- //////// Do not modify the always_ff blocks. ////////
- // You need to modify always_comb block.
- always_comb
- begin
- // By default, keep motion and position unchanged
- Ghost_Y_start_in = Ghost_Y_start;
- Ghost_X_start_in = Ghost_X_start;
- currDirec_in = currDirec;
- // Update position and motion only at rising edge of frame clock
- if (frame_clk_rising_edge)
- begin
- unique case(SW)
- 8'h52: // w (up)
- begin
- if( (mem_out[((Ghost_Y_start - 1) * 538) + (Ghost_X_start)] != 5'd5) ||
- (Ghost_Y_start - 1 >= 102 && Ghost_X_start >= 284 && Ghost_X_start <= 302 ) )
- currDirec_in = 4'b0100;
- end
- 8'h4F://right
- begin
- if((mem_out[((Ghost_Y_start ) * 538) + (Ghost_X_start + 14)] != 5'd5))
- currDirec_in = 4'b0010;
- end
- 8'h51://down
- begin
- if((mem_out[((Ghost_Y_start + 14 ) * 538) + (Ghost_X_start )] != 5'd5))
- currDirec_in = 4'b0001;
- end
- 8'h50://left
- begin
- if((mem_out[((Ghost_Y_start) * 538) + (Ghost_X_start - 1)] != 5'd5))
- currDirec_in = 4'b1000;
- end
- default:
- begin
- Ghost_Y_start_in = Ghost_Y_start;
- currDirec_in = currDirec;
- end
- endcase
- if(currDirec_in == 4'b0100)
- begin
- if((mem_out[((Ghost_Y_start - 1) * 538) + (Ghost_X_start)] != 5'd5) ||
- (Ghost_Y_start - 1 >= 102 && Ghost_X_start >= 284 && Ghost_X_start <= 302 ))
- Ghost_Y_start_in = Ghost_Y_start - 1;
- else
- currDirec_in = 4'b0000;
- end
- else if(currDirec_in == 4'b0010)
- begin
- if( (mem_out[((Ghost_Y_start ) * 538) + (Ghost_X_start + 14)] != 5'd5))
- Ghost_X_start_in = Ghost_X_start + 1;
- else
- currDirec_in = 4'b0000;
- end
- else if(currDirec_in == 4'b0001)
- begin
- if( (mem_out[((Ghost_Y_start + 14 ) * 538) + (Ghost_X_start )] != 5'd5))
- Ghost_Y_start_in = Ghost_Y_start + 1;
- else
- currDirec_in = 4'b0000;
- end
- else if(currDirec_in == 4'b1000)
- begin
- if((mem_out[((Ghost_Y_start) * 538) + (Ghost_X_start - 1)] != 5'd5))
- Ghost_X_start_in = Ghost_X_start - 1;
- else
- currDirec_in = 4'b0000;
- end
- ///////
- ////////
- end
- end
- endmodule
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement