data/full_repos/permissive/113002755/verilog/Asteroids.v
 line:597: before: "."
1: b"%Error: data/full_repos/permissive/113002755/verilog/Asteroids.v:253: Cannot find file containing module: 'vgaClk'\nvgaClk u2\n^~~~~~\n        ... Looked in:\n             data/full_repos/permissive/113002755/verilog,data/full_repos/permissive/113002755/vgaClk\n             data/full_repos/permissive/113002755/verilog,data/full_repos/permissive/113002755/vgaClk.v\n             data/full_repos/permissive/113002755/verilog,data/full_repos/permissive/113002755/vgaClk.sv\n             vgaClk\n             vgaClk.v\n             vgaClk.sv\n             obj_dir/vgaClk\n             obj_dir/vgaClk.v\n             obj_dir/vgaClk.sv\n%Error: data/full_repos/permissive/113002755/verilog/Asteroids.v:274: Cannot find file containing module: 'VGA_Ctrl'\nVGA_Ctrl u3\n^~~~~~~~\n%Error: data/full_repos/permissive/113002755/verilog/Asteroids.v:293: Cannot find file containing module: 'VGA_Drive'\nVGA_Drive u4\n^~~~~~~~~\n%Error: data/full_repos/permissive/113002755/verilog/Asteroids.v:373: Cannot find file containing module: 'Digit'\nDigit d1 (\n^~~~~\n%Error: data/full_repos/permissive/113002755/verilog/Asteroids.v:391: Cannot find file containing module: 'Digit'\nDigit d2 (\n^~~~~\n%Error: data/full_repos/permissive/113002755/verilog/Asteroids.v:409: Cannot find file containing module: 'Digit'\nDigit d3 (\n^~~~~\n%Error: data/full_repos/permissive/113002755/verilog/Asteroids.v:427: Cannot find file containing module: 'Digit'\nDigit d4 (\n^~~~~\n%Error: data/full_repos/permissive/113002755/verilog/Asteroids.v:445: Cannot find file containing module: 'Digit'\nDigit d5 (\n^~~~~\n%Error: data/full_repos/permissive/113002755/verilog/Asteroids.v:463: Cannot find file containing module: 'Digit'\nDigit d6 (\n^~~~~\n%Error: data/full_repos/permissive/113002755/verilog/Asteroids.v:491: Cannot find file containing module: 'Hex2BCD'\nHex2BCD h2d(\n^~~~~~~\n%Error: data/full_repos/permissive/113002755/verilog/Asteroids.v:521: Cannot find file containing module: 'memClk'\nmemClk mk (\n^~~~~~\n%Error: data/full_repos/permissive/113002755/verilog/Asteroids.v:530: Cannot find file containing module: 'GameOver'\nGameOver go (\n^~~~~~~~\n%Error: data/full_repos/permissive/113002755/verilog/Asteroids.v:549: Cannot find file containing module: 'keyboard'\n keyboard kb(mClk, PS2_KBCLK, PS2_KBDAT, RST, scancode, VB);\n ^~~~~~~~\n%Error: data/full_repos/permissive/113002755/verilog/Asteroids.v:581: Cannot find file containing module: 'CommandShip'\nCommandShip ship\n^~~~~~~~~~~\n%Error: data/full_repos/permissive/113002755/verilog/Asteroids.v:600: Cannot find file containing module: 'CommandShip'\nCommandShip spare1\n^~~~~~~~~~~\n%Error: data/full_repos/permissive/113002755/verilog/Asteroids.v:618: Cannot find file containing module: 'CommandShip'\nCommandShip spare2\n^~~~~~~~~~~\n%Error: data/full_repos/permissive/113002755/verilog/Asteroids.v:636: Cannot find file containing module: 'CommandShip'\nCommandShip spare3\n^~~~~~~~~~~\n%Error: data/full_repos/permissive/113002755/verilog/Asteroids.v:659: Cannot find file containing module: 'spareShipDecode'\nspareShipDecode ssd (\n^~~~~~~~~~~~~~~\n%Error: data/full_repos/permissive/113002755/verilog/Asteroids.v:731: Cannot find file containing module: 'oneshot'\noneshot os(fireBtn, mClk, fire);\n^~~~~~~\n%Error: data/full_repos/permissive/113002755/verilog/Asteroids.v:750: Cannot find file containing module: 'fireDecode'\nfireDecode fd (\n^~~~~~~~~~\n%Error: data/full_repos/permissive/113002755/verilog/Asteroids.v:762: Cannot find file containing module: 'Torpedo'\nTorpedo t0\n^~~~~~~\n%Error: data/full_repos/permissive/113002755/verilog/Asteroids.v:777: Cannot find file containing module: 'Torpedo'\nTorpedo t1\n^~~~~~~\n%Error: data/full_repos/permissive/113002755/verilog/Asteroids.v:792: Cannot find file containing module: 'Torpedo'\nTorpedo t2\n^~~~~~~\n%Error: data/full_repos/permissive/113002755/verilog/Asteroids.v:807: Cannot find file containing module: 'Torpedo'\nTorpedo t3\n^~~~~~~\n%Error: data/full_repos/permissive/113002755/verilog/Asteroids.v:822: Cannot find file containing module: 'Torpedo'\nTorpedo t4\n^~~~~~~\n%Error: data/full_repos/permissive/113002755/verilog/Asteroids.v:837: Cannot find file containing module: 'Torpedo'\n Torpedo t5\n ^~~~~~~\n%Error: data/full_repos/permissive/113002755/verilog/Asteroids.v:852: Cannot find file containing module: 'Torpedo'\n Torpedo t6\n ^~~~~~~\n%Error: data/full_repos/permissive/113002755/verilog/Asteroids.v:867: Cannot find file containing module: 'Torpedo'\n Torpedo t7\n ^~~~~~~\n%Error: data/full_repos/permissive/113002755/verilog/Asteroids.v:889: Cannot find file containing module: 'asteroid_placer'\n asteroid_placer ap (\n ^~~~~~~~~~~~~~~\n%Error: data/full_repos/permissive/113002755/verilog/Asteroids.v:911: Cannot find file containing module: 'asteroid_controller'\nasteroid_controller cont (\n^~~~~~~~~~~~~~~~~~~\n%Error: data/full_repos/permissive/113002755/verilog/Asteroids.v:925: Cannot find file containing module: 'asteroid_decode'\nasteroid_decode ast (\n^~~~~~~~~~~~~~~\n%Error: data/full_repos/permissive/113002755/verilog/Asteroids.v:951: Cannot find file containing module: 'asteroid_8x8'\n asteroid_8x8 a0\n ^~~~~~~~~~~~\n%Error: data/full_repos/permissive/113002755/verilog/Asteroids.v:969: Cannot find file containing module: 'asteroid_8x8'\n  asteroid_8x8 a1\n  ^~~~~~~~~~~~\n%Error: data/full_repos/permissive/113002755/verilog/Asteroids.v:988: Cannot find file containing module: 'asteroid_8x8'\n  asteroid_8x8 a2\n  ^~~~~~~~~~~~\n%Error: data/full_repos/permissive/113002755/verilog/Asteroids.v:1007: Cannot find file containing module: 'asteroid_8x8'\n  asteroid_8x8 a3\n  ^~~~~~~~~~~~\n%Error: data/full_repos/permissive/113002755/verilog/Asteroids.v:1025: Cannot find file containing module: 'asteroid_8x8'\n   asteroid_8x8 a4\n   ^~~~~~~~~~~~\n%Error: data/full_repos/permissive/113002755/verilog/Asteroids.v:1043: Cannot find file containing module: 'asteroid_8x8'\n   asteroid_8x8 a5\n   ^~~~~~~~~~~~\n%Error: data/full_repos/permissive/113002755/verilog/Asteroids.v:1061: Cannot find file containing module: 'asteroid_8x8'\n   asteroid_8x8 a6\n   ^~~~~~~~~~~~\n%Error: data/full_repos/permissive/113002755/verilog/Asteroids.v:1079: Cannot find file containing module: 'asteroid_8x8'\n   asteroid_8x8 a7\n   ^~~~~~~~~~~~\n%Error: data/full_repos/permissive/113002755/verilog/Asteroids.v:1097: Cannot find file containing module: 'asteroid_8x8'\n  asteroid_8x8 a8\n  ^~~~~~~~~~~~\n%Error: data/full_repos/permissive/113002755/verilog/Asteroids.v:1115: Cannot find file containing module: 'asteroid_8x8'\n  asteroid_8x8 a9\n  ^~~~~~~~~~~~\n%Error: data/full_repos/permissive/113002755/verilog/Asteroids.v:1134: Cannot find file containing module: 'asteroid_8x8'\n  asteroid_8x8 a10\n  ^~~~~~~~~~~~\n%Error: data/full_repos/permissive/113002755/verilog/Asteroids.v:1153: Cannot find file containing module: 'asteroid_8x8'\n  asteroid_8x8 a11\n  ^~~~~~~~~~~~\n%Error: data/full_repos/permissive/113002755/verilog/Asteroids.v:1171: Cannot find file containing module: 'asteroid_8x8'\n   asteroid_8x8 a12\n   ^~~~~~~~~~~~\n%Error: data/full_repos/permissive/113002755/verilog/Asteroids.v:1189: Cannot find file containing module: 'asteroid_8x8'\n   asteroid_8x8 a13\n   ^~~~~~~~~~~~\n%Error: data/full_repos/permissive/113002755/verilog/Asteroids.v:1207: Cannot find file containing module: 'asteroid_8x8'\n   asteroid_8x8 a14\n   ^~~~~~~~~~~~\n%Error: data/full_repos/permissive/113002755/verilog/Asteroids.v:1225: Cannot find file containing module: 'asteroid_8x8'\n   asteroid_8x8 a15\n   ^~~~~~~~~~~~\n%Error: Exiting due to 47 error(s)\n"
module Asteroids (





		CLOCK_50,
		CLOCK_50_2,

		BUTTON,

		SW,

		HEX0_D,
		HEX0_DP,
		HEX1_D,
		HEX1_DP,
		HEX2_D,
		HEX2_DP,
		HEX3_D,
		HEX3_DP,

		LEDG,

		UART_TXD,
		UART_RXD,
		UART_CTS,
		UART_RTS,

		DRAM_DQ,
		DRAM_ADDR,
		DRAM_LDQM,
		DRAM_UDQM,
		DRAM_WE_N,
		DRAM_CAS_N,
		DRAM_RAS_N,
		DRAM_CS_N,
		DRAM_BA_0,
		DRAM_BA_1,
		DRAM_CLK,
		DRAM_CKE,

		FL_DQ,
		FL_DQ15_AM1,
		FL_ADDR,
		FL_WE_N,
		FL_RST_N,
		FL_OE_N,
		FL_CE_N,
		FL_WP_N,
		FL_BYTE_N,
		FL_RY,

		LCD_BLON,
		LCD_RW,
		LCD_EN,
		LCD_RS,
		LCD_DATA,

		SD_DAT0,
		SD_DAT3,
		SD_CMD,
		SD_CLK,
		SD_WP_N,

		PS2_KBDAT,
		PS2_KBCLK,
		PS2_MSDAT,
		PS2_MSCLK,

		VGA_HS,
		VGA_VS,
		VGA_R,
		VGA_G,
		VGA_B,

		GPIO0_CLKIN,
		GPIO0_CLKOUT,
		GPIO0_D,
		GPIO1_CLKIN,
		GPIO1_CLKOUT,
		GPIO1_D
	);


input				CLOCK_50;
input				CLOCK_50_2;

input	 [2:0]	BUTTON;

input	 [9:0]	SW;

output [6:0]	HEX0_D;
output			HEX0_DP;
output [6:0]	HEX1_D;
output			HEX1_DP;
output [6:0]	HEX2_D;
output			HEX2_DP;
output [6:0]	HEX3_D;
output			HEX3_DP;

output [9:0]	LEDG;

output			UART_TXD;
input		 		UART_RXD;
output			UART_CTS;
input				UART_RTS;

inout	 [15:0]	DRAM_DQ;
output [12:0]	DRAM_ADDR;
output			DRAM_LDQM;
output			DRAM_UDQM;
output			DRAM_WE_N;
output			DRAM_CAS_N;
output			DRAM_RAS_N;
output			DRAM_CS_N;
output			DRAM_BA_0;
output			DRAM_BA_1;
output			DRAM_CLK;
output			DRAM_CKE;

inout	 [14:0]	FL_DQ;
inout				FL_DQ15_AM1;
output [21:0]	FL_ADDR;
output			FL_WE_N;
output			FL_RST_N;
output			FL_OE_N;
output			FL_CE_N;
output			FL_WP_N;
output			FL_BYTE_N;
input				FL_RY;

inout	 [7:0]	LCD_DATA;
output			LCD_BLON;
output			LCD_RW;
output			LCD_EN;
output			LCD_RS;

inout				SD_DAT0;
inout				SD_DAT3;
inout				SD_CMD;
output			SD_CLK;
input				SD_WP_N;

inout		 		PS2_KBDAT;
inout				PS2_KBCLK;
inout			 	PS2_MSDAT;
inout				PS2_MSCLK;

output			VGA_HS;
output			VGA_VS;
output [3:0]	VGA_R;
output [3:0]	VGA_G;
output [3:0]	VGA_B;

input	 [1:0]	GPIO0_CLKIN;
output [1:0]	GPIO0_CLKOUT;
inout	 [31:0]	GPIO0_D;
input	 [1:0]	GPIO1_CLKIN;
output [1:0]	GPIO1_CLKOUT;
inout	 [31:0]	GPIO1_D;





assign			DRAM_DQ			=	16'hzzzz;
assign			FL_DQ				=	15'hzzzz;
assign			LCD_DATA			=	8'hzz;
assign			SD_DAT0			=	1'hz;
assign			SD_DAT3			=	1'hz;
assign			SD_CMD			=	1'hz;
assign			PS2_MSDAT		=	1'hz;
assign			PS2_MSCLK		=	1'hz;
assign			GPIO0_D			=	32'hzzzzzzzz;
assign			GPIO1_D			=	32'hzzzzzzzz;

assign			HEX0_D			=	7'h7F;
assign			HEX0_DP			=	1'h1;
assign			HEX1_D			=	7'h7F;
assign			HEX1_DP			=	1'h1;
assign			HEX2_D			=	7'h7F;
assign			HEX2_DP			=	1'h1;
assign			HEX3_D			=	7'h7F;
assign			HEX3_DP			=	1'h1;



wire 				RST;

assign RST = BUTTON[0];


wire 	 [3:0]	VGA_R;
wire   [3:0]	VGA_G;
wire   [3:0]	VGA_B;
wire 				VGA_HS;
wire 				VGA_VS;



wire 				pClk;



reg [2:0] angle;


initial
begin
	fireCnt = 0;
	rstcnt = 0;
end









vgaClk u2
	( 
		.inclk0(CLOCK_50), 
		.c0(pClk)
	);


wire	[10:0]		mVGA_X;
wire	[10:0]		mVGA_Y;
wire	[3:0]		mOSD_R;
wire	[3:0]		mOSD_G;
wire	[3:0]		mOSD_B;
wire	[3:0]		sVGA_R;
wire	[3:0]		sVGA_G;
wire	[3:0]		sVGA_B;

assign	VGA_R = sVGA_R;
assign	VGA_G = sVGA_G;
assign	VGA_B = sVGA_B;


VGA_Ctrl	u3
(
	.oCurrent_X(mVGA_X),
	.oCurrent_Y(mVGA_Y),
	.iRed(mOSD_R),
	.iGreen(mOSD_G),
	.iBlue(mOSD_B),

	.oVGA_R(sVGA_R),
	.oVGA_G(sVGA_G),
	.oVGA_B(sVGA_B),
	.oVGA_HS(VGA_HS),
	.oVGA_VS(VGA_VS),

	.iCLK(pClk),
	.iRST_N(RST)
);


VGA_Drive	u4
(
	.oRed(mOSD_R),
	.oGreen(mOSD_G),
	.oBlue(mOSD_B),
	.iVGA_X(mVGA_X),
	.iVGA_Y(mVGA_Y),
	.iVGA_CLK(pClk),

	.iDrawPixel(drawPixel),

	.iON_R(15),
	.iON_G(15),
	.iON_B(15),
	.iOFF_R(0),
	.iOFF_G(0),
	.iOFF_B(8),

	.iRST_n(RST)
);





wire spareShips;
wire spare1_PX, spare2_PX, spare3_PX;
assign spareShips = spare1_PX || spare2_PX || spare3_PX;


wire drawShip;
wire ship_PX;
assign drawShip = ship_PX;


wire drawTorpedo;
wire torp0_PX, torp1_PX, torp2_PX, torp3_PX, torp4_PX, torp5_PX, torp6_PX, torp7_PX;
assign drawTorpedo = torp0_PX || torp1_PX || torp2_PX || torp3_PX || torp4_PX || torp5_PX || torp6_PX || torp7_PX;


wire drawAstroid, drawAstroidU, drawAstroidL;
wire asto0_PX, asto1_PX, asto2_PX, asto3_PX, asto4_PX, asto5_PX, asto6_PX, asto7_PX;
wire asto8_PX, asto9_PX, asto10_PX, asto11_PX, asto12_PX, asto13_PX, asto14_PX, asto15_PX;
assign drawAstroidL = asto0_PX || asto1_PX || asto2_PX || asto3_PX || asto4_PX || asto5_PX || asto6_PX || asto7_PX;
assign drawAstroidU = asto8_PX || asto9_PX || asto10_PX || asto11_PX || asto12_PX || asto13_PX || asto14_PX || asto15_PX;
assign drawAstroid = drawAstroidL || drawAstroidU;






wire	drawPixel;
assign drawPixel = drawShip || drawAstroid || drawTorpedo || spareShips || drawNum || endGame;










wire shipAstCol;
wire torpAstCol;

assign shipAstCol = drawShip && drawAstroid;
assign torpAstCol = drawAstroid && drawTorpedo;








wire [3:0] digit1, digit2, digit3, digit4, digit5, digit6;


Digit d1 (
	.iClk(mClk),

	.iPosX(600),
	.iPosY(10),

	.iVGA_X(mVGA_X),
	.iVGA_Y(mVGA_Y),

	.iDigit(digit1),

	.oDrawNum(drawNum1),

	.iBlank(1)

);


Digit d2 (
	.iClk(mClk),

	.iPosX(584),
	.iPosY(10),

	.iVGA_X(mVGA_X),
	.iVGA_Y(mVGA_Y),

	.iDigit(digit2),

	.oDrawNum(drawNum2),

	.iBlank(1)

);


Digit d3 (
	.iClk(mClk),

	.iPosX(568),
	.iPosY(10),

	.iVGA_X(mVGA_X),
	.iVGA_Y(mVGA_Y),

	.iDigit(digit3),

	.oDrawNum(drawNum3),

	.iBlank(1)

);


Digit d4 (
	.iClk(mClk),

	.iPosX(552),
	.iPosY(10),

	.iVGA_X(mVGA_X),
	.iVGA_Y(mVGA_Y),

	.iDigit(digit4),

	.oDrawNum(drawNum4),

	.iBlank(1)

);


Digit d5 (
	.iClk(mClk),

	.iPosX(536),
	.iPosY(10),

	.iVGA_X(mVGA_X),
	.iVGA_Y(mVGA_Y),

	.iDigit(digit5),

	.oDrawNum(drawNum5),

	.iBlank(1)

);


Digit d6 (
	.iClk(mClk),

	.iPosX(520),
	.iPosY(10),

	.iVGA_X(mVGA_X),
	.iVGA_Y(mVGA_Y),

	.iDigit(digit6),

	.oDrawNum(drawNum6),

	.iBlank(1)

);


wire drawNum1, drawNum2, drawNum3, drawNum4, drawNum5, drawNum6;
wire drawNum;
assign drawNum = drawNum1 || drawNum2 || drawNum3 || drawNum4 || drawNum5 || drawNum6;

wire points = addPoints0 || addPoints1 || addPoints2 || addPoints3 || addPoints4 || addPoints5 || addPoints6 || addPoints7 || addPoints8 || addPoints9 || addPoints10 || addPoints11 || addPoints12 || addPoints13 || addPoints14 || addPoints15;
wire addPoints0 , addPoints1 , addPoints2 , addPoints3 , addPoints4 , addPoints5 , addPoints6 , addPoints7 , addPoints8 , addPoints9 , addPoints10 , addPoints11 , addPoints12 , addPoints13 , addPoints14 , addPoints15;
reg [19:0]	PointCount;



Hex2BCD h2d(
	.iClk(mClk),
	.iHexPoints(PointCount),
	.oDigit1(digit1),
	.oDigit2(digit2),
	.oDigit3(digit3),
	.oDigit4(digit4),
	.oDigit5(digit5),
	.oDigit6(digit6)
);
	

	always@ (posedge points or negedge RST)
	begin
		if(!RST)
		begin
			PointCount = 0;
		end
		else
		begin
			PointCount = PointCount + 25;
		end
	end







memClk mk (
	.inclk0(CLOCK_50),
	.c0(mClk)
);

wire mClk;



GameOver go (
	.iRst(RST),
	.iClk(mClk),
	.iVGA_X(mVGA_X),
	.iVGA_Y(mVGA_Y),
	.iGameOver(gameOver),
	.oDrawGameOver(endGame)
);

wire endGame;





	wire VB;
	wire [7:0] scancode;


	keyboard kb(mClk, PS2_KBCLK, PS2_KBDAT, RST, scancode, VB);
	
	reg [7:0] keyBrdOut;
	reg fireUp, fireDn;
	
	assign fireBtn = fireUp ^ fireDn;
	
	always@(posedge VB)
	begin
		keyBrdOut = scancode;
		
		case(keyBrdOut)
			8'b01101011: angle = angle + 1'b1;
			8'b01110100: angle = angle - 1'b1;
			8'b00101001: fireUp = ~fireUp;
			default: ;
		endcase
		
	end
	
	always@(negedge VB)
	begin
		case(keyBrdOut)
			8'b00101001: fireDn = ~fireDn;
			default: ;
		endcase
	end
	




CommandShip ship
	(

		.iRst(RST),
		.iMemClk(mClk),
		.iPClk(pClk),
		.iAngle(angle),
		.iRestart(newShip),

		.iVGA_X(mVGA_X),
		.iVGA_Y(mVGA_Y),
		.oDrawPixel(ship_PX),
		.iCollision(shipAstCol),
		.oActive(shipAlive)
	);

defparam spare1.POS_X = 10;
defparam spare1.POS_Y = 10;	

CommandShip spare1
	(

		.iRst(RST),
		.iMemClk(mClk),
		.iPClk(pClk),
		.iAngle(0),
		.iRestart(0),

		.iVGA_X(mVGA_X),
		.iVGA_Y(mVGA_Y),
		.oDrawPixel(spare1_PX),
		.iCollision(stopS1)
	);

defparam spare2.POS_X = 30;
defparam spare2.POS_Y = 10;
	
CommandShip spare2
	(

		.iRst(RST),
		.iMemClk(mClk),
		.iPClk(pClk),
		.iAngle(0),
		.iRestart(0),

		.iVGA_X(mVGA_X),
		.iVGA_Y(mVGA_Y),
		.oDrawPixel(spare2_PX),
		.iCollision(stopS2)
	);
	
defparam spare3.POS_X = 50;
defparam spare3.POS_Y = 10;
	
CommandShip spare3
	(

		.iRst(RST),
		.iMemClk(mClk),
		.iPClk(pClk),
		.iAngle(0),
		.iRestart(0),

		.iVGA_X(mVGA_X),
		.iVGA_Y(mVGA_Y),
		.oDrawPixel(spare3_PX),
		.iCollision(stopS3)
	);

wire stopS0;
wire stopS1;
wire stopS2;
wire stopS3;




spareShipDecode ssd (
	shipCnt,
	stopS0,
	stopS1,
	stopS2,
	stopS3
);

wire 			shipAlive;
reg 			newShip;
reg [1:0]	shipCnt;
reg [31:0] 	rstcnt;
reg 			gameOver;







always@(posedge mClk or negedge RST)
begin
	if(!RST)
	begin
		shipCnt = 0;
		newShip = 1'b0;
		rstcnt = 0;
		gameOver = 1'b0;
	end
	else if(shipCnt != 2'b01)
	begin
		if(!shipAlive)
		begin
			rstcnt = rstcnt + 1'b1;
			if (rstcnt == 32'h09ffffff)
			begin
				newShip = 1'b1;
			end
			else
			begin
			end
		end
		else if (newShip ==1)
		begin
			newShip = 1'b0;
			rstcnt = 0;
			shipCnt = shipCnt - 1'b1;
		end
		else
		begin
		end
	end
	else
	begin
		if(!shipAlive)
		begin
			gameOver = 1'b1;
		end
		else
		begin

		end
	end
end


assign LEDG[1:0] = shipCnt;





oneshot os(fireBtn, mClk, fire);
wire fireBtn;


reg [2:0] fireCnt;
always@(posedge fire)
begin
	if (shipAlive)
	begin
		fireCnt = fireCnt + 1'b1;
	end
	else
	begin
	end
end

wire fire, fire0, fire1, fire2, fire3, fire4, fire5, fire6, fire7;


fireDecode fd (
	fireCnt, 
	fire0, 
	fire1, 
	fire2, 
	fire3, 
	fire4, 
	fire5, 
	fire6, 
	fire7
);
	
Torpedo t0
	(
		.iRst(RST),
		.iMemClk(mClk),
		.iPClk(pClk),

		.iDir(angle),
		.iFireTorpedo(fire0),

		.iVGA_X(mVGA_X),
		.iVGA_Y(mVGA_Y),
		.oDrawPixel(torp0_PX),
		.iCollision(torpAstCol)
	);

Torpedo t1
	(
		.iRst(RST),
		.iMemClk(mClk),
		.iPClk(pClk),

		.iDir(angle),
		.iFireTorpedo(fire1),

		.iVGA_X(mVGA_X),
		.iVGA_Y(mVGA_Y),
		.oDrawPixel(torp1_PX),
		.iCollision(torpAstCol)
	);

Torpedo t2
	(
		.iRst(RST),
		.iMemClk(mClk),
		.iPClk(pClk),

		.iDir(angle),
		.iFireTorpedo(fire2),

		.iVGA_X(mVGA_X),
		.iVGA_Y(mVGA_Y),
		.oDrawPixel(torp2_PX),
		.iCollision(torpAstCol)
	);

Torpedo t3
	(
		.iRst(RST),
		.iMemClk(mClk),
		.iPClk(pClk),

		.iDir(angle),
		.iFireTorpedo(fire3),

		.iVGA_X(mVGA_X),
		.iVGA_Y(mVGA_Y),
		.oDrawPixel(torp3_PX),
		.iCollision(torpAstCol)
	);

Torpedo t4
	(
		.iRst(RST),
		.iMemClk(mClk),
		.iPClk(pClk),

		.iDir(angle),
		.iFireTorpedo(fire4),

		.iVGA_X(mVGA_X),
		.iVGA_Y(mVGA_Y),
		.oDrawPixel(torp4_PX),
		.iCollision(torpAstCol)
	);

	Torpedo t5
	(
		.iRst(RST),
		.iMemClk(mClk),
		.iPClk(pClk),

		.iDir(angle),
		.iFireTorpedo(fire5),

		.iVGA_X(mVGA_X),
		.iVGA_Y(mVGA_Y),
		.oDrawPixel(torp5_PX),
		.iCollision(torpAstCol)
	);

	Torpedo t6
	(
		.iRst(RST),
		.iMemClk(mClk),
		.iPClk(pClk),

		.iDir(angle),
		.iFireTorpedo(fire6),

		.iVGA_X(mVGA_X),
		.iVGA_Y(mVGA_Y),
		.oDrawPixel(torp6_PX),
		.iCollision(torpAstCol)
	);

	Torpedo t7
	(
		.iRst(RST),
		.iMemClk(mClk),
		.iPClk(pClk),

		.iDir(angle),
		.iFireTorpedo(fire7),

		.iVGA_X(mVGA_X),
		.iVGA_Y(mVGA_Y),
		.oDrawPixel(torp7_PX),
		.iCollision(torpAstCol)
	);
	
	






	asteroid_placer ap (
		.iClk(mClk),
		.iRst(RST),
		.oDir(direction),
		.oPosX(astoridX),
		.oPosY(astoridY),
		.oSize(astSize)
	
	);
	
	wire [2:0] direction;
	wire [10:0] astoridX;
	wire [10:0] astoridY;
	wire [1:0]	astSize;
	

	
	reg [3:0] aID;
	wire launch;
	


asteroid_controller cont (
	.clk(mClk),
	.rst(RST),
	.fire_out(launch)

);
	

always@(posedge launch)
begin
	aID = aID + 1'b1;
end


asteroid_decode ast (
	aID, 
	aFire0, 
	aFire1, 
	aFire2, 
	aFire3, 
	aFire4, 
	aFire5, 
	aFire6, 
	aFire7, 
	aFire8, 
	aFire9, 
	aFire10, 
	aFire11, 
	aFire12, 
	aFire13, 
	aFire14, 
	aFire15
);



wire aFire0, aFire1, aFire2, aFire3, aFire4, aFire5, aFire6, aFire7, aFire8, aFire9;
wire aFire10, aFire11, aFire12, aFire13, aFire14, aFire15;

	
	asteroid_8x8 a0
	(
		.iRst(RST),
		.iMemClk(mClk),
		.iPClk(pClk),
		.iDir(direction),
		.iPosY(astoridY),
		.iPosX(astoridX),
		.iFireAsteroid(aFire0),
		.iTorpColl(torpAstCol),
		.iCollision(torpAstCol || shipAstCol),
		.iVGA_X(mVGA_X),
		.iVGA_Y(mVGA_Y),
		.oDrawPixel(asto0_PX),
		.oCntPoints(addPoints0),
		.iSize(astSize)
	);
	
		asteroid_8x8 a1
	(
		.iRst(RST),
		.iMemClk(mClk),
		.iPClk(pClk),
		.iDir(direction),
		.iPosY(astoridY),
		.iPosX(astoridX),
		.iFireAsteroid(aFire1),
		.iCollision(torpAstCol || shipAstCol),
		.iTorpColl(torpAstCol),
		.iVGA_X(mVGA_X),
		.iVGA_Y(mVGA_Y),
		.oDrawPixel(asto1_PX),
		.oCntPoints(addPoints1),
		.iSize(astSize)
	);
	
	
		asteroid_8x8 a2
	(
		.iRst(RST),
		.iMemClk(mClk),
		.iPClk(pClk),
		.iDir(direction),
		.iPosY(astoridY),
		.iPosX(astoridX),
		.iFireAsteroid(aFire2),
		.iCollision(torpAstCol || shipAstCol),
		.iTorpColl(torpAstCol),
		.iVGA_X(mVGA_X),
		.iVGA_Y(mVGA_Y),
		.oDrawPixel(asto2_PX),
		.oCntPoints(addPoints2),
		.iSize(astSize)
	);
	
	
		asteroid_8x8 a3
	(
		.iRst(RST),
		.iMemClk(mClk),
		.iPClk(pClk),
		.iDir(direction),
		.iPosY(astoridY),
		.iPosX(astoridX),
		.iFireAsteroid(aFire3),
		.iCollision(torpAstCol || shipAstCol),
		.iTorpColl(torpAstCol),
		.iVGA_X(mVGA_X),
		.iVGA_Y(mVGA_Y),
		.oDrawPixel(asto3_PX),
		.oCntPoints(addPoints3),
		.iSize(astSize)
	);
	
			asteroid_8x8 a4
	(
		.iRst(RST),
		.iMemClk(mClk),
		.iPClk(pClk),
		.iDir(direction),
		.iPosY(astoridY),
		.iPosX(astoridX),
		.iFireAsteroid(aFire4),
		.iCollision(torpAstCol || shipAstCol),
		.iTorpColl(torpAstCol),
		.iVGA_X(mVGA_X),
		.iVGA_Y(mVGA_Y),
		.oDrawPixel(asto4_PX),
		.oCntPoints(addPoints4),
		.iSize(astSize)
	);
	
			asteroid_8x8 a5
	(
		.iRst(RST),
		.iMemClk(mClk),
		.iPClk(pClk),
		.iDir(direction),
		.iPosY(astoridY),
		.iPosX(astoridX),
		.iFireAsteroid(aFire5),
		.iCollision(torpAstCol || shipAstCol),
		.iTorpColl(torpAstCol),
		.iVGA_X(mVGA_X),
		.iVGA_Y(mVGA_Y),
		.oDrawPixel(asto5_PX),
		.oCntPoints(addPoints5),
		.iSize(astSize)
	);
	
			asteroid_8x8 a6
	(
		.iRst(RST),
		.iMemClk(mClk),
		.iPClk(pClk),
		.iDir(direction),
		.iPosY(astoridY),
		.iPosX(astoridX),
		.iFireAsteroid(aFire6),
		.iCollision(torpAstCol || shipAstCol),
		.iTorpColl(torpAstCol),
		.iVGA_X(mVGA_X),
		.iVGA_Y(mVGA_Y),
		.oDrawPixel(asto6_PX),
		.oCntPoints(addPoints6),
		.iSize(astSize)
	);
	
			asteroid_8x8 a7
	(
		.iRst(RST),
		.iMemClk(mClk),
		.iPClk(pClk),
		.iDir(direction),
		.iPosY(astoridY),
		.iPosX(astoridX),
		.iFireAsteroid(aFire7),
		.iCollision(torpAstCol || shipAstCol),
		.iTorpColl(torpAstCol),
		.iVGA_X(mVGA_X),
		.iVGA_Y(mVGA_Y),
		.oDrawPixel(asto7_PX),
		.oCntPoints(addPoints7),
		.iSize(astSize)
	);
	
		asteroid_8x8 a8
	(
		.iRst(RST),
		.iMemClk(mClk),
		.iPClk(pClk),
		.iDir(direction),
		.iPosY(astoridY),
		.iPosX(astoridX),
		.iFireAsteroid(aFire8),
		.iCollision(torpAstCol || shipAstCol),
		.iTorpColl(torpAstCol),
		.iVGA_X(mVGA_X),
		.iVGA_Y(mVGA_Y),
		.oDrawPixel(asto8_PX),
		.oCntPoints(addPoints8),
		.iSize(astSize)
	);
	
		asteroid_8x8 a9
	(
		.iRst(RST),
		.iMemClk(mClk),
		.iPClk(pClk),
		.iDir(direction),
		.iPosY(astoridY),
		.iPosX(astoridX),
		.iFireAsteroid(aFire9),
		.iCollision(torpAstCol || shipAstCol),
		.iTorpColl(torpAstCol),
		.iVGA_X(mVGA_X),
		.iVGA_Y(mVGA_Y),
		.oDrawPixel(asto9_PX),
		.oCntPoints(addPoints9),
		.iSize(astSize)
	);
	
	
		asteroid_8x8 a10
	(
		.iRst(RST),
		.iMemClk(mClk),
		.iPClk(pClk),
		.iDir(direction),
		.iPosY(astoridY),
		.iPosX(astoridX),
		.iFireAsteroid(aFire10),
		.iCollision(torpAstCol || shipAstCol),
		.iTorpColl(torpAstCol),
		.iVGA_X(mVGA_X),
		.iVGA_Y(mVGA_Y),
		.oDrawPixel(asto10_PX),
		.oCntPoints(addPoints10),
		.iSize(astSize)
	);
	
	
		asteroid_8x8 a11
	(
		.iRst(RST),
		.iMemClk(mClk),
		.iPClk(pClk),
		.iDir(direction),
		.iPosY(astoridY),
		.iPosX(astoridX),
		.iFireAsteroid(aFire11),
		.iCollision(torpAstCol || shipAstCol),
		.iTorpColl(torpAstCol),
		.iVGA_X(mVGA_X),
		.iVGA_Y(mVGA_Y),
		.oDrawPixel(asto11_PX),
		.oCntPoints(addPoints11),
		.iSize(astSize)
	);
	
			asteroid_8x8 a12
	(
		.iRst(RST),
		.iMemClk(mClk),
		.iPClk(pClk),
		.iDir(direction),
		.iPosY(astoridY),
		.iPosX(astoridX),
		.iFireAsteroid(aFire12),
		.iCollision(torpAstCol || shipAstCol),
		.iTorpColl(torpAstCol),
		.iVGA_X(mVGA_X),
		.iVGA_Y(mVGA_Y),
		.oDrawPixel(asto12_PX),
		.oCntPoints(addPoints12),
		.iSize(astSize)
	);
	
			asteroid_8x8 a13
	(
		.iRst(RST),
		.iMemClk(mClk),
		.iPClk(pClk),
		.iDir(direction),
		.iPosY(astoridY),
		.iPosX(astoridX),
		.iFireAsteroid(aFire13),
		.iCollision(torpAstCol || shipAstCol),
		.iTorpColl(torpAstCol),
		.iVGA_X(mVGA_X),
		.iVGA_Y(mVGA_Y),
		.oDrawPixel(asto13_PX),
		.oCntPoints(addPoints13),
		.iSize(astSize)
	);
	
			asteroid_8x8 a14
	(
		.iRst(RST),
		.iMemClk(mClk),
		.iPClk(pClk),
		.iDir(direction),
		.iPosY(astoridY),
		.iPosX(astoridX),
		.iFireAsteroid(aFire14),
		.iCollision(torpAstCol || shipAstCol),
		.iTorpColl(torpAstCol),
		.iVGA_X(mVGA_X),
		.iVGA_Y(mVGA_Y),
		.oDrawPixel(asto14_PX),
		.oCntPoints(addPoints14),
		.iSize(astSize)
	);
	
			asteroid_8x8 a15
	(
		.iRst(RST),
		.iMemClk(mClk),
		.iPClk(pClk),
		.iDir(direction),
		.iPosY(astoridY),
		.iPosX(astoridX),
		.iFireAsteroid(aFire15),
		.iCollision(torpAstCol || shipAstCol),
		.iTorpColl(torpAstCol),
		.iVGA_X(mVGA_X),
		.iVGA_Y(mVGA_Y),
		.oDrawPixel(asto15_PX),
		.oCntPoints(addPoints15),
		.iSize(astSize)
	);
	
endmodule
module Asteroids (





		CLOCK_50,
		CLOCK_50_2,

		BUTTON,

		SW,

		HEX0_D,
		HEX0_DP,
		HEX1_D,
		HEX1_DP,
		HEX2_D,
		HEX2_DP,
		HEX3_D,
		HEX3_DP,

		LEDG,

		UART_TXD,
		UART_RXD,
		UART_CTS,
		UART_RTS,

		DRAM_DQ,
		DRAM_ADDR,
		DRAM_LDQM,
		DRAM_UDQM,
		DRAM_WE_N,
		DRAM_CAS_N,
		DRAM_RAS_N,
		DRAM_CS_N,
		DRAM_BA_0,
		DRAM_BA_1,
		DRAM_CLK,
		DRAM_CKE,

		FL_DQ,
		FL_DQ15_AM1,
		FL_ADDR,
		FL_WE_N,
		FL_RST_N,
		FL_OE_N,
		FL_CE_N,
		FL_WP_N,
		FL_BYTE_N,
		FL_RY,

		LCD_BLON,
		LCD_RW,
		LCD_EN,
		LCD_RS,
		LCD_DATA,

		SD_DAT0,
		SD_DAT3,
		SD_CMD,
		SD_CLK,
		SD_WP_N,

		PS2_KBDAT,
		PS2_KBCLK,
		PS2_MSDAT,
		PS2_MSCLK,

		VGA_HS,
		VGA_VS,
		VGA_R,
		VGA_G,
		VGA_B,

		GPIO0_CLKIN,
		GPIO0_CLKOUT,
		GPIO0_D,
		GPIO1_CLKIN,
		GPIO1_CLKOUT,
		GPIO1_D
	);



input				CLOCK_50;
input				CLOCK_50_2;

input	 [2:0]	BUTTON;

input	 [9:0]	SW;

output [6:0]	HEX0_D;
output			HEX0_DP;
output [6:0]	HEX1_D;
output			HEX1_DP;
output [6:0]	HEX2_D;
output			HEX2_DP;
output [6:0]	HEX3_D;
output			HEX3_DP;

output [9:0]	LEDG;

output			UART_TXD;
input		 		UART_RXD;
output			UART_CTS;
input				UART_RTS;

inout	 [15:0]	DRAM_DQ;
output [12:0]	DRAM_ADDR;
output			DRAM_LDQM;
output			DRAM_UDQM;
output			DRAM_WE_N;
output			DRAM_CAS_N;
output			DRAM_RAS_N;
output			DRAM_CS_N;
output			DRAM_BA_0;
output			DRAM_BA_1;
output			DRAM_CLK;
output			DRAM_CKE;

inout	 [14:0]	FL_DQ;
inout				FL_DQ15_AM1;
output [21:0]	FL_ADDR;
output			FL_WE_N;
output			FL_RST_N;
output			FL_OE_N;
output			FL_CE_N;
output			FL_WP_N;
output			FL_BYTE_N;
input				FL_RY;

inout	 [7:0]	LCD_DATA;
output			LCD_BLON;
output			LCD_RW;
output			LCD_EN;
output			LCD_RS;

inout				SD_DAT0;
inout				SD_DAT3;
inout				SD_CMD;
output			SD_CLK;
input				SD_WP_N;

inout		 		PS2_KBDAT;
inout				PS2_KBCLK;
inout			 	PS2_MSDAT;
inout				PS2_MSCLK;

output			VGA_HS;
output			VGA_VS;
output [3:0]	VGA_R;
output [3:0]	VGA_G;
output [3:0]	VGA_B;

input	 [1:0]	GPIO0_CLKIN;
output [1:0]	GPIO0_CLKOUT;
inout	 [31:0]	GPIO0_D;
input	 [1:0]	GPIO1_CLKIN;
output [1:0]	GPIO1_CLKOUT;
inout	 [31:0]	GPIO1_D;





assign			DRAM_DQ			=	16'hzzzz;
assign			FL_DQ				=	15'hzzzz;
assign			LCD_DATA			=	8'hzz;
assign			SD_DAT0			=	1'hz;
assign			SD_DAT3			=	1'hz;
assign			SD_CMD			=	1'hz;
assign			PS2_MSDAT		=	1'hz;
assign			PS2_MSCLK		=	1'hz;
assign			GPIO0_D			=	32'hzzzzzzzz;
assign			GPIO1_D			=	32'hzzzzzzzz;

assign			HEX0_D			=	7'h7F;
assign			HEX0_DP			=	1'h1;
assign			HEX1_D			=	7'h7F;
assign			HEX1_DP			=	1'h1;
assign			HEX2_D			=	7'h7F;
assign			HEX2_DP			=	1'h1;
assign			HEX3_D			=	7'h7F;
assign			HEX3_DP			=	1'h1;



wire 				RST;

assign RST = BUTTON[0];


wire 	 [3:0]	VGA_R;
wire   [3:0]	VGA_G;
wire   [3:0]	VGA_B;
wire 				VGA_HS;
wire 				VGA_VS;



wire 				pClk;



reg [2:0] angle;


initial
begin
	fireCnt = 0;
	rstcnt = 0;
end









vgaClk u2
	( 
		.inclk0(CLOCK_50), 
		.c0(pClk)
	);


wire	[10:0]		mVGA_X;
wire	[10:0]		mVGA_Y;
wire	[3:0]		mOSD_R;
wire	[3:0]		mOSD_G;
wire	[3:0]		mOSD_B;
wire	[3:0]		sVGA_R;
wire	[3:0]		sVGA_G;
wire	[3:0]		sVGA_B;

assign	VGA_R = sVGA_R;
assign	VGA_G = sVGA_G;
assign	VGA_B = sVGA_B;


VGA_Ctrl	u3
(
	.oCurrent_X(mVGA_X),
	.oCurrent_Y(mVGA_Y),
	.iRed(mOSD_R),
	.iGreen(mOSD_G),
	.iBlue(mOSD_B),

	.oVGA_R(sVGA_R),
	.oVGA_G(sVGA_G),
	.oVGA_B(sVGA_B),
	.oVGA_HS(VGA_HS),
	.oVGA_VS(VGA_VS),

	.iCLK(pClk),
	.iRST_N(RST)
);


VGA_Drive	u4
(
	.oRed(mOSD_R),
	.oGreen(mOSD_G),
	.oBlue(mOSD_B),
	.iVGA_X(mVGA_X),
	.iVGA_Y(mVGA_Y),
	.iVGA_CLK(pClk),

	.iDrawPixel(drawPixel),

	.iON_R(15),
	.iON_G(15),
	.iON_B(15),
	.iOFF_R(0),
	.iOFF_G(0),
	.iOFF_B(8),

	.iRST_n(RST)
);





wire spareShips;
wire spare1_PX, spare2_PX, spare3_PX;
assign spareShips = spare1_PX || spare2_PX || spare3_PX;


wire drawShip;
wire ship_PX;
assign drawShip = ship_PX;


wire drawTorpedo;
wire torp0_PX, torp1_PX, torp2_PX, torp3_PX, torp4_PX, torp5_PX, torp6_PX, torp7_PX;
assign drawTorpedo = torp0_PX || torp1_PX || torp2_PX || torp3_PX || torp4_PX || torp5_PX || torp6_PX || torp7_PX;


wire drawAstroid, drawAstroidU, drawAstroidL;
wire asto0_PX, asto1_PX, asto2_PX, asto3_PX, asto4_PX, asto5_PX, asto6_PX, asto7_PX;
wire asto8_PX, asto9_PX, asto10_PX, asto11_PX, asto12_PX, asto13_PX, asto14_PX, asto15_PX;
assign drawAstroidL = asto0_PX || asto1_PX || asto2_PX || asto3_PX || asto4_PX || asto5_PX || asto6_PX || asto7_PX;
assign drawAstroidU = asto8_PX || asto9_PX || asto10_PX || asto11_PX || asto12_PX || asto13_PX || asto14_PX || asto15_PX;
assign drawAstroid = drawAstroidL || drawAstroidU;






wire	drawPixel;
assign drawPixel = drawShip || drawAstroid || drawTorpedo || spareShips || drawNum || endGame;










wire shipAstCol;
wire torpAstCol;

assign shipAstCol = drawShip && drawAstroid;
assign torpAstCol = drawAstroid && drawTorpedo;








wire [3:0] digit1, digit2, digit3, digit4, digit5, digit6;


Digit d1 (
	.iClk(mClk),

	.iPosX(600),
	.iPosY(10),

	.iVGA_X(mVGA_X),
	.iVGA_Y(mVGA_Y),

	.iDigit(digit1),

	.oDrawNum(drawNum1),

	.iBlank(1)

);


Digit d2 (
	.iClk(mClk),

	.iPosX(584),
	.iPosY(10),

	.iVGA_X(mVGA_X),
	.iVGA_Y(mVGA_Y),

	.iDigit(digit2),

	.oDrawNum(drawNum2),

	.iBlank(1)

);


Digit d3 (
	.iClk(mClk),

	.iPosX(568),
	.iPosY(10),

	.iVGA_X(mVGA_X),
	.iVGA_Y(mVGA_Y),

	.iDigit(digit3),

	.oDrawNum(drawNum3),

	.iBlank(1)

);


Digit d4 (
	.iClk(mClk),

	.iPosX(552),
	.iPosY(10),

	.iVGA_X(mVGA_X),
	.iVGA_Y(mVGA_Y),

	.iDigit(digit4),

	.oDrawNum(drawNum4),

	.iBlank(1)

);


Digit d5 (
	.iClk(mClk),

	.iPosX(536),
	.iPosY(10),

	.iVGA_X(mVGA_X),
	.iVGA_Y(mVGA_Y),

	.iDigit(digit5),

	.oDrawNum(drawNum5),

	.iBlank(1)

);


Digit d6 (
	.iClk(mClk),

	.iPosX(520),
	.iPosY(10),

	.iVGA_X(mVGA_X),
	.iVGA_Y(mVGA_Y),

	.iDigit(digit6),

	.oDrawNum(drawNum6),

	.iBlank(1)

);


wire drawNum1, drawNum2, drawNum3, drawNum4, drawNum5, drawNum6;
wire drawNum;
assign drawNum = drawNum1 || drawNum2 || drawNum3 || drawNum4 || drawNum5 || drawNum6;

wire points = addPoints0 || addPoints1 || addPoints2 || addPoints3 || addPoints4 || addPoints5 || addPoints6 || addPoints7 || addPoints8 || addPoints9 || addPoints10 || addPoints11 || addPoints12 || addPoints13 || addPoints14 || addPoints15;
wire addPoints0 , addPoints1 , addPoints2 , addPoints3 , addPoints4 , addPoints5 , addPoints6 , addPoints7 , addPoints8 , addPoints9 , addPoints10 , addPoints11 , addPoints12 , addPoints13 , addPoints14 , addPoints15;
reg [19:0]	PointCount;



Hex2BCD h2d(
	.iClk(mClk),
	.iHexPoints(PointCount),
	.oDigit1(digit1),
	.oDigit2(digit2),
	.oDigit3(digit3),
	.oDigit4(digit4),
	.oDigit5(digit5),
	.oDigit6(digit6)
);
	

	always@ (posedge points or negedge RST)
	begin
		if(!RST)
		begin
			PointCount = 0;
		end
		else
		begin
			PointCount = PointCount + 25;
		end
	end







memClk mk (
	.inclk0(CLOCK_50),
	.c0(mClk)
);

wire mClk;



GameOver go (
	.iRst(RST),
	.iClk(mClk),
	.iVGA_X(mVGA_X),
	.iVGA_Y(mVGA_Y),
	.iGameOver(gameOver),
	.oDrawGameOver(endGame)
);

wire endGame;





	wire VB;
	wire [7:0] scancode;


	keyboard kb(mClk, PS2_KBCLK, PS2_KBDAT, RST, scancode, VB);
	
	reg [7:0] keyBrdOut;
	reg fireUp, fireDn;
	
	assign fireBtn = fireUp ^ fireDn;
	
	always@(posedge VB)
	begin
		keyBrdOut = scancode;
		
		case(keyBrdOut)
			8'b01101011: angle = angle + 1'b1;
			8'b01110100: angle = angle - 1'b1;
			8'b00101001: fireUp = ~fireUp;
			default: ;
		endcase
		
	end
	
	always@(negedge VB)
	begin
		case(keyBrdOut)
			8'b00101001: fireDn = ~fireDn;
			default: ;
		endcase
	end
	




CommandShip ship
	(

		.iRst(RST),
		.iMemClk(mClk),
		.iPClk(pClk),
		.iAngle(angle),
		.iRestart(newShip),

		.iVGA_X(mVGA_X),
		.iVGA_Y(mVGA_Y),
		.oDrawPixel(ship_PX),
		.iCollision(shipAstCol),
		.oActive(shipAlive)
	);

defparam spare1.POS_X = 10;
defparam spare1.POS_Y = 10;	

CommandShip spare1
	(

		.iRst(RST),
		.iMemClk(mClk),
		.iPClk(pClk),
		.iAngle(0),
		.iRestart(0),

		.iVGA_X(mVGA_X),
		.iVGA_Y(mVGA_Y),
		.oDrawPixel(spare1_PX),
		.iCollision(stopS1)
	);

defparam spare2.POS_X = 30;
defparam spare2.POS_Y = 10;
	
CommandShip spare2
	(

		.iRst(RST),
		.iMemClk(mClk),
		.iPClk(pClk),
		.iAngle(0),
		.iRestart(0),

		.iVGA_X(mVGA_X),
		.iVGA_Y(mVGA_Y),
		.oDrawPixel(spare2_PX),
		.iCollision(stopS2)
	);
	
defparam spare3.POS_X = 50;
defparam spare3.POS_Y = 10;
	
CommandShip spare3
	(

		.iRst(RST),
		.iMemClk(mClk),
		.iPClk(pClk),
		.iAngle(0),
		.iRestart(0),

		.iVGA_X(mVGA_X),
		.iVGA_Y(mVGA_Y),
		.oDrawPixel(spare3_PX),
		.iCollision(stopS3)
	);

wire stopS0;
wire stopS1;
wire stopS2;
wire stopS3;




spareShipDecode ssd (
	shipCnt,
	stopS0,
	stopS1,
	stopS2,
	stopS3
);

wire 			shipAlive;
reg 			newShip;
reg [1:0]	shipCnt;
reg [31:0] 	rstcnt;
reg 			gameOver;







always@(posedge mClk or negedge RST)
begin
	if(!RST)
	begin
		shipCnt = 0;
		newShip = 1'b0;
		rstcnt = 0;
		gameOver = 1'b0;
	end
	else if(shipCnt != 2'b01)
	begin
		if(!shipAlive)
		begin
			rstcnt = rstcnt + 1'b1;
			if (rstcnt == 32'h09ffffff)
			begin
				newShip = 1'b1;
			end
			else
			begin
			end
		end
		else if (newShip ==1)
		begin
			newShip = 1'b0;
			rstcnt = 0;
			shipCnt = shipCnt - 1'b1;
		end
		else
		begin
		end
	end
	else
	begin
		if(!shipAlive)
		begin
			gameOver = 1'b1;
		end
		else
		begin

		end
	end
end


assign LEDG[1:0] = shipCnt;





oneshot os(fireBtn, mClk, fire);
wire fireBtn;


reg [2:0] fireCnt;
always@(posedge fire)
begin
	if (shipAlive)
	begin
		fireCnt = fireCnt + 1'b1;
	end
	else
	begin
	end
end

wire fire, fire0, fire1, fire2, fire3, fire4, fire5, fire6, fire7;


fireDecode fd (
	fireCnt, 
	fire0, 
	fire1, 
	fire2, 
	fire3, 
	fire4, 
	fire5, 
	fire6, 
	fire7
);
	
Torpedo t0
	(
		.iRst(RST),
		.iMemClk(mClk),
		.iPClk(pClk),

		.iDir(angle),
		.iFireTorpedo(fire0),

		.iVGA_X(mVGA_X),
		.iVGA_Y(mVGA_Y),
		.oDrawPixel(torp0_PX),
		.iCollision(torpAstCol)
	);

Torpedo t1
	(
		.iRst(RST),
		.iMemClk(mClk),
		.iPClk(pClk),

		.iDir(angle),
		.iFireTorpedo(fire1),

		.iVGA_X(mVGA_X),
		.iVGA_Y(mVGA_Y),
		.oDrawPixel(torp1_PX),
		.iCollision(torpAstCol)
	);

Torpedo t2
	(
		.iRst(RST),
		.iMemClk(mClk),
		.iPClk(pClk),

		.iDir(angle),
		.iFireTorpedo(fire2),

		.iVGA_X(mVGA_X),
		.iVGA_Y(mVGA_Y),
		.oDrawPixel(torp2_PX),
		.iCollision(torpAstCol)
	);

Torpedo t3
	(
		.iRst(RST),
		.iMemClk(mClk),
		.iPClk(pClk),

		.iDir(angle),
		.iFireTorpedo(fire3),

		.iVGA_X(mVGA_X),
		.iVGA_Y(mVGA_Y),
		.oDrawPixel(torp3_PX),
		.iCollision(torpAstCol)
	);

Torpedo t4
	(
		.iRst(RST),
		.iMemClk(mClk),
		.iPClk(pClk),

		.iDir(angle),
		.iFireTorpedo(fire4),

		.iVGA_X(mVGA_X),
		.iVGA_Y(mVGA_Y),
		.oDrawPixel(torp4_PX),
		.iCollision(torpAstCol)
	);

	Torpedo t5
	(
		.iRst(RST),
		.iMemClk(mClk),
		.iPClk(pClk),

		.iDir(angle),
		.iFireTorpedo(fire5),

		.iVGA_X(mVGA_X),
		.iVGA_Y(mVGA_Y),
		.oDrawPixel(torp5_PX),
		.iCollision(torpAstCol)
	);

	Torpedo t6
	(
		.iRst(RST),
		.iMemClk(mClk),
		.iPClk(pClk),

		.iDir(angle),
		.iFireTorpedo(fire6),

		.iVGA_X(mVGA_X),
		.iVGA_Y(mVGA_Y),
		.oDrawPixel(torp6_PX),
		.iCollision(torpAstCol)
	);

	Torpedo t7
	(
		.iRst(RST),
		.iMemClk(mClk),
		.iPClk(pClk),

		.iDir(angle),
		.iFireTorpedo(fire7),

		.iVGA_X(mVGA_X),
		.iVGA_Y(mVGA_Y),
		.oDrawPixel(torp7_PX),
		.iCollision(torpAstCol)
	);
	
	






	asteroid_placer ap (
		.iClk(mClk),
		.iRst(RST),
		.oDir(direction),
		.oPosX(astoridX),
		.oPosY(astoridY),
		.oSize(astSize)
	
	);
	
	wire [2:0] direction;
	wire [10:0] astoridX;
	wire [10:0] astoridY;
	wire [1:0]	astSize;
	

	
	reg [3:0] aID;
	wire launch;
	


asteroid_controller cont (
	.clk(mClk),
	.rst(RST),
	.fire_out(launch)

);
	

always@(posedge launch)
begin
	aID = aID + 1'b1;
end


asteroid_decode ast (
	aID, 
	aFire0, 
	aFire1, 
	aFire2, 
	aFire3, 
	aFire4, 
	aFire5, 
	aFire6, 
	aFire7, 
	aFire8, 
	aFire9, 
	aFire10, 
	aFire11, 
	aFire12, 
	aFire13, 
	aFire14, 
	aFire15
);



wire aFire0, aFire1, aFire2, aFire3, aFire4, aFire5, aFire6, aFire7, aFire8, aFire9;
wire aFire10, aFire11, aFire12, aFire13, aFire14, aFire15;

	
	asteroid_8x8 a0
	(
		.iRst(RST),
		.iMemClk(mClk),
		.iPClk(pClk),
		.iDir(direction),
		.iPosY(astoridY),
		.iPosX(astoridX),
		.iFireAsteroid(aFire0),
		.iTorpColl(torpAstCol),
		.iCollision(torpAstCol || shipAstCol),
		.iVGA_X(mVGA_X),
		.iVGA_Y(mVGA_Y),
		.oDrawPixel(asto0_PX),
		.oCntPoints(addPoints0),
		.iSize(astSize)
	);
	
		asteroid_8x8 a1
	(
		.iRst(RST),
		.iMemClk(mClk),
		.iPClk(pClk),
		.iDir(direction),
		.iPosY(astoridY),
		.iPosX(astoridX),
		.iFireAsteroid(aFire1),
		.iCollision(torpAstCol || shipAstCol),
		.iTorpColl(torpAstCol),
		.iVGA_X(mVGA_X),
		.iVGA_Y(mVGA_Y),
		.oDrawPixel(asto1_PX),
		.oCntPoints(addPoints1),
		.iSize(astSize)
	);
	
	
		asteroid_8x8 a2
	(
		.iRst(RST),
		.iMemClk(mClk),
		.iPClk(pClk),
		.iDir(direction),
		.iPosY(astoridY),
		.iPosX(astoridX),
		.iFireAsteroid(aFire2),
		.iCollision(torpAstCol || shipAstCol),
		.iTorpColl(torpAstCol),
		.iVGA_X(mVGA_X),
		.iVGA_Y(mVGA_Y),
		.oDrawPixel(asto2_PX),
		.oCntPoints(addPoints2),
		.iSize(astSize)
	);
	
	
		asteroid_8x8 a3
	(
		.iRst(RST),
		.iMemClk(mClk),
		.iPClk(pClk),
		.iDir(direction),
		.iPosY(astoridY),
		.iPosX(astoridX),
		.iFireAsteroid(aFire3),
		.iCollision(torpAstCol || shipAstCol),
		.iTorpColl(torpAstCol),
		.iVGA_X(mVGA_X),
		.iVGA_Y(mVGA_Y),
		.oDrawPixel(asto3_PX),
		.oCntPoints(addPoints3),
		.iSize(astSize)
	);
	
			asteroid_8x8 a4
	(
		.iRst(RST),
		.iMemClk(mClk),
		.iPClk(pClk),
		.iDir(direction),
		.iPosY(astoridY),
		.iPosX(astoridX),
		.iFireAsteroid(aFire4),
		.iCollision(torpAstCol || shipAstCol),
		.iTorpColl(torpAstCol),
		.iVGA_X(mVGA_X),
		.iVGA_Y(mVGA_Y),
		.oDrawPixel(asto4_PX),
		.oCntPoints(addPoints4),
		.iSize(astSize)
	);
	
			asteroid_8x8 a5
	(
		.iRst(RST),
		.iMemClk(mClk),
		.iPClk(pClk),
		.iDir(direction),
		.iPosY(astoridY),
		.iPosX(astoridX),
		.iFireAsteroid(aFire5),
		.iCollision(torpAstCol || shipAstCol),
		.iTorpColl(torpAstCol),
		.iVGA_X(mVGA_X),
		.iVGA_Y(mVGA_Y),
		.oDrawPixel(asto5_PX),
		.oCntPoints(addPoints5),
		.iSize(astSize)
	);
	
			asteroid_8x8 a6
	(
		.iRst(RST),
		.iMemClk(mClk),
		.iPClk(pClk),
		.iDir(direction),
		.iPosY(astoridY),
		.iPosX(astoridX),
		.iFireAsteroid(aFire6),
		.iCollision(torpAstCol || shipAstCol),
		.iTorpColl(torpAstCol),
		.iVGA_X(mVGA_X),
		.iVGA_Y(mVGA_Y),
		.oDrawPixel(asto6_PX),
		.oCntPoints(addPoints6),
		.iSize(astSize)
	);
	
			asteroid_8x8 a7
	(
		.iRst(RST),
		.iMemClk(mClk),
		.iPClk(pClk),
		.iDir(direction),
		.iPosY(astoridY),
		.iPosX(astoridX),
		.iFireAsteroid(aFire7),
		.iCollision(torpAstCol || shipAstCol),
		.iTorpColl(torpAstCol),
		.iVGA_X(mVGA_X),
		.iVGA_Y(mVGA_Y),
		.oDrawPixel(asto7_PX),
		.oCntPoints(addPoints7),
		.iSize(astSize)
	);
	
		asteroid_8x8 a8
	(
		.iRst(RST),
		.iMemClk(mClk),
		.iPClk(pClk),
		.iDir(direction),
		.iPosY(astoridY),
		.iPosX(astoridX),
		.iFireAsteroid(aFire8),
		.iCollision(torpAstCol || shipAstCol),
		.iTorpColl(torpAstCol),
		.iVGA_X(mVGA_X),
		.iVGA_Y(mVGA_Y),
		.oDrawPixel(asto8_PX),
		.oCntPoints(addPoints8),
		.iSize(astSize)
	);
	
		asteroid_8x8 a9
	(
		.iRst(RST),
		.iMemClk(mClk),
		.iPClk(pClk),
		.iDir(direction),
		.iPosY(astoridY),
		.iPosX(astoridX),
		.iFireAsteroid(aFire9),
		.iCollision(torpAstCol || shipAstCol),
		.iTorpColl(torpAstCol),
		.iVGA_X(mVGA_X),
		.iVGA_Y(mVGA_Y),
		.oDrawPixel(asto9_PX),
		.oCntPoints(addPoints9),
		.iSize(astSize)
	);
	
	
		asteroid_8x8 a10
	(
		.iRst(RST),
		.iMemClk(mClk),
		.iPClk(pClk),
		.iDir(direction),
		.iPosY(astoridY),
		.iPosX(astoridX),
		.iFireAsteroid(aFire10),
		.iCollision(torpAstCol || shipAstCol),
		.iTorpColl(torpAstCol),
		.iVGA_X(mVGA_X),
		.iVGA_Y(mVGA_Y),
		.oDrawPixel(asto10_PX),
		.oCntPoints(addPoints10),
		.iSize(astSize)
	);
	
	
		asteroid_8x8 a11
	(
		.iRst(RST),
		.iMemClk(mClk),
		.iPClk(pClk),
		.iDir(direction),
		.iPosY(astoridY),
		.iPosX(astoridX),
		.iFireAsteroid(aFire11),
		.iCollision(torpAstCol || shipAstCol),
		.iTorpColl(torpAstCol),
		.iVGA_X(mVGA_X),
		.iVGA_Y(mVGA_Y),
		.oDrawPixel(asto11_PX),
		.oCntPoints(addPoints11),
		.iSize(astSize)
	);
	
			asteroid_8x8 a12
	(
		.iRst(RST),
		.iMemClk(mClk),
		.iPClk(pClk),
		.iDir(direction),
		.iPosY(astoridY),
		.iPosX(astoridX),
		.iFireAsteroid(aFire12),
		.iCollision(torpAstCol || shipAstCol),
		.iTorpColl(torpAstCol),
		.iVGA_X(mVGA_X),
		.iVGA_Y(mVGA_Y),
		.oDrawPixel(asto12_PX),
		.oCntPoints(addPoints12),
		.iSize(astSize)
	);
	
			asteroid_8x8 a13
	(
		.iRst(RST),
		.iMemClk(mClk),
		.iPClk(pClk),
		.iDir(direction),
		.iPosY(astoridY),
		.iPosX(astoridX),
		.iFireAsteroid(aFire13),
		.iCollision(torpAstCol || shipAstCol),
		.iTorpColl(torpAstCol),
		.iVGA_X(mVGA_X),
		.iVGA_Y(mVGA_Y),
		.oDrawPixel(asto13_PX),
		.oCntPoints(addPoints13),
		.iSize(astSize)
	);
	
			asteroid_8x8 a14
	(
		.iRst(RST),
		.iMemClk(mClk),
		.iPClk(pClk),
		.iDir(direction),
		.iPosY(astoridY),
		.iPosX(astoridX),
		.iFireAsteroid(aFire14),
		.iCollision(torpAstCol || shipAstCol),
		.iTorpColl(torpAstCol),
		.iVGA_X(mVGA_X),
		.iVGA_Y(mVGA_Y),
		.oDrawPixel(asto14_PX),
		.oCntPoints(addPoints14),
		.iSize(astSize)
	);
	
			asteroid_8x8 a15
	(
		.iRst(RST),
		.iMemClk(mClk),
		.iPClk(pClk),
		.iDir(direction),
		.iPosY(astoridY),
		.iPosX(astoridX),
		.iFireAsteroid(aFire15),
		.iCollision(torpAstCol || shipAstCol),
		.iTorpColl(torpAstCol),
		.iVGA_X(mVGA_X),
		.iVGA_Y(mVGA_Y),
		.oDrawPixel(asto15_PX),
		.oCntPoints(addPoints15),
		.iSize(astSize)
	);
	
endmodule