/* * Hardware Sprite and Supporting Modules * * by Brendan Doms, Sean McBride, Brian Shih, and Mikell Taylor * (Olin College - Computer Architecture - Fall 2005) * */ module hardware_sprite(Reset, R, G, B, A, clk, pclk, row, col, active, posx, posy, fliph, flipv, color); input active, fliph, flipv, clk, pclk; input [9:0] col, posx; input [8:0] row, posy; input color, Reset; output R, G, B, A; wire sR, sG, sB, sA; reg [3:0] xcoord, ycoord; reg [2:0] shape; reg [22:0] shapecounter; reg drawing; parameter WIDTH = 10'd16, HEIGHT = 10'd16; sprite_memory spritemem0 (Reset, sR, sG, sB, sA, clk, pclk, xcoord, ycoord, shape); and a0 (R, sR, drawing); and a1 (G, sG, drawing); and a2 (B, sB, drawing); and a3 (A, sA, drawing); // Initialize values always @(posedge clk) begin if (Reset) begin // Initialize things shapecounter = 0; if (color == 0) shape = 0; else if (color == 1) shape = 2; end else begin // Change the shape shapecounter = shapecounter + 1; if (shapecounter == 0) begin if (shape == 0) shape = 1; else if (shape == 1) shape = 0; else if (shape == 2) shape = 3; else if (shape == 3) shape = 2; end end end always @(posedge pclk) begin drawing = (active && (col >= posx) && (col < posx + WIDTH) && (row >= posy) && (row < posy + HEIGHT)); // Make sure NEXT pixel is being requested xcoord = col-posx+1; // Current row requested ycoord = row-posy; end endmodule // Video selector, essentially a 3 bit mux module video_selector(ROut, GOut, BOut, RIn, GIn, BIn, R, G, B, A); output ROut, GOut, BOut; input RIn, GIn, BIn, R, G, B, A; Mux2 mR (ROut, RIn, R, A); Mux2 mG (GOut, GIn, G, A); Mux2 mB (BOut, BIn, B, A); endmodule module Mux2 (OUT, A, B, S); // OUT=A if S=0, OUT=B if S=1 output OUT; input A, B, S; wire notS, andA, andB; not Inv0 (notS, S); and And0 (andA, A, notS); and And1 (andB, B, S); or Or1 (OUT, andA, andB); endmodule // 16x16 sprite memory, has 6 shapes saved module sprite_memory(Reset, R, G, B, A, clk, pclk, xcoord, ycoord, shape); input [3:0] xcoord, ycoord; input [2:0] shape; input clk, pclk, Reset; output R, G, B, A; reg R, G, B, A; reg [63:0] shaperow; // Sprite Shape 1 (Red Ghost 1) reg [63:0] shape1mem[15:0]; // Sprite Shape 2 (Red Ghost 2) reg [63:0] shape2mem[15:0]; // Sprite Shape 3 (Cyan Ghost 1) reg [63:0] shape3mem[15:0]; // Sprite Shape 4 (Cyan Ghost 2) reg [63:0] shape4mem[15:0]; // Initialize always @(posedge clk) begin if (Reset) begin // Initialize shape 1 shape1mem[0] = 64'b0000000000000000100110011001100110011001100110010000000000000000; shape1mem[1] = 64'b0000000000001001100110011001100110011001100110011001000000000000; shape1mem[2] = 64'b0000000010011001100110011001100110011001100110011001100100000000; shape1mem[3] = 64'b0000100110011001111111111001100110011001111111111001100110010000; shape1mem[4] = 64'b1001100110011111111111111111100110011111111111111111100110011001; shape1mem[5] = 64'b1001100110011111001111111111100110011111001111111111100110011001; shape1mem[6] = 64'b1001100110011111001111111111100110011111001111111111100110011001; shape1mem[7] = 64'b1001100110011001001111111001100110011001001111111001100110011001; shape1mem[8] = 64'b1001100110011001100110011001100110011001100110011001100110011001; shape1mem[9] = 64'b1001100110011001100110011001100110011001100110011001100110011001; shape1mem[10] = 64'b1001100110011001100110011001100110011001100110011001100110011001; shape1mem[11] = 64'b1001100110011001100110011001100110011001100110011001100110011001; shape1mem[12] = 64'b1001100110011001100110011001100110011001100110011001100110011001; shape1mem[13] = 64'b1001100110010000100110011001100110010000100110011001100110010000; shape1mem[14] = 64'b1001100100000000000010011001100100000000000010011001100100000000; shape1mem[15] = 64'b1001000000000000000000001001000000000000000000001001000000000000; // Initialize shape 2 shape2mem[0] = 64'b0000000000000000100110011001100110011001100110010000000000000000; shape2mem[1] = 64'b0000000000001001100110011001100110011001100110011001000000000000; shape2mem[2] = 64'b0000000010011001100110011001100110011001100110011001100100000000; shape2mem[3] = 64'b0000100110011001111111111001100110011001111111111001100110010000; shape2mem[4] = 64'b1001100110011111111111111111100110011111111111111111100110011001; shape2mem[5] = 64'b1001100110011111001111111111100110011111001111111111100110011001; shape2mem[6] = 64'b1001100110011111001111111111100110011111001111111111100110011001; shape2mem[7] = 64'b1001100110011001001111111001100110011001001111111001100110011001; shape2mem[8] = 64'b1001100110011001100110011001100110011001100110011001100110011001; shape2mem[9] = 64'b1001100110011001100110011001100110011001100110011001100110011001; shape2mem[10] = 64'b1001100110011001100110011001100110011001100110011001100110011001; shape2mem[11] = 64'b1001100110011001100110011001100110011001100110011001100110011001; shape2mem[12] = 64'b1001100110011001100110011001100110011001100110011001100110011001; shape2mem[13] = 64'b0000100110011001100110010000100110011001100110010000100110011001; shape2mem[14] = 64'b0000000010011001100100000000000010011001100100000000000010011001; shape2mem[15] = 64'b0000000000001001000000000000000000001001000000000000000000001001; // Initialize shape 3 shape3mem[0] = 64'b0000000000000000011101110111011101110111011101110000000000000000; shape3mem[1] = 64'b0000000000000111011101110111011101110111011101110111000000000000; shape3mem[2] = 64'b0000000001110111011101110111011101110111011101110111011100000000; shape3mem[3] = 64'b0000011101110111111111110111011101110111111111110111011101110000; shape3mem[4] = 64'b0111011101111111111111111111011101111111111111111111011101110111; shape3mem[5] = 64'b0111011101111111001111111111011101111111001111111111011101110111; shape3mem[6] = 64'b0111011101111111001111111111011101111111001111111111011101110111; shape3mem[7] = 64'b0111011101110111001111110111011101110111001111110111011101110111; shape3mem[8] = 64'b0111011101110111011101110111011101110111011101110111011101110111; shape3mem[9] = 64'b0111011101110111011101110111011101110111011101110111011101110111; shape3mem[10] = 64'b0111011101110111011101110111011101110111011101110111011101110111; shape3mem[11] = 64'b0111011101110111011101110111011101110111011101110111011101110111; shape3mem[12] = 64'b0111011101110111011101110111011101110111011101110111011101110111; shape3mem[13] = 64'b0111011101110000011101110111011101110000011101110111011101110000; shape3mem[14] = 64'b0111011100000000000001110111011100000000000001110111011100000000; shape3mem[15] = 64'b0111000000000000000000000111000000000000000000000111000000000000; // Initialize shape 4 shape4mem[0] = 64'b0000000000000000011101110111011101110111011101110000000000000000; shape4mem[1] = 64'b0000000000000111011101110111011101110111011101110111000000000000; shape4mem[2] = 64'b0000000001110111011101110111011101110111011101110111011100000000; shape4mem[3] = 64'b0000011101110111111111110111011101110111111111110111011101110000; shape4mem[4] = 64'b0111011101111111111111111111011101111111111111111111011101110111; shape4mem[5] = 64'b0111011101111111001111111111011101111111001111111111011101110111; shape4mem[6] = 64'b0111011101111111001111111111011101111111001111111111011101110111; shape4mem[7] = 64'b0111011101110111001111110111011101110111001111110111011101110111; shape4mem[8] = 64'b0111011101110111011101110111011101110111011101110111011101110111; shape4mem[9] = 64'b0111011101110111011101110111011101110111011101110111011101110111; shape4mem[10] = 64'b0111011101110111011101110111011101110111011101110111011101110111; shape4mem[11] = 64'b0111011101110111011101110111011101110111011101110111011101110111; shape4mem[12] = 64'b0111011101110111011101110111011101110111011101110111011101110111; shape4mem[13] = 64'b0000011101110111011101110000011101110111011101110000011101110111; shape4mem[14] = 64'b0000000001110111011100000000000001110111011100000000000001110111; shape4mem[15] = 64'b0000000000000111000000000000000000000111000000000000000000000111; end end // Assign signals to proper outputs always @(posedge pclk) begin if (shape == 0) shaperow = shape1mem[ycoord]; if (shape == 1) shaperow = shape2mem[ycoord]; if (shape == 2) shaperow = shape3mem[ycoord]; if (shape == 3) shaperow = shape4mem[ycoord]; R = shaperow[(xcoord*4)+3]; G = shaperow[(xcoord*4)+2]; B = shaperow[(xcoord*4)+1]; A = shaperow[xcoord*4]; end endmodule