]> Joshua Wise's Git repositories - fpgaboy.git/commitdiff
added butans
authorChristopher Zihao Lu <czl@gurgle.weh.andrew.cmu.edu>
Fri, 9 May 2008 09:53:20 +0000 (05:53 -0400)
committerChristopher Zihao Lu <czl@gurgle.weh.andrew.cmu.edu>
Fri, 9 May 2008 09:53:20 +0000 (05:53 -0400)
Buttons.v [new file with mode: 0644]

diff --git a/Buttons.v b/Buttons.v
new file mode 100644 (file)
index 0000000..6caecd6
--- /dev/null
+++ b/Buttons.v
@@ -0,0 +1,32 @@
+`define ADDR_P1 16'hFF10
+
+/* note: buttons are 'pressed' when the input is high */
+
+module Buttons(
+       input core_clk,
+       input wr,
+       input rd,
+       input [15:0] addr,
+       inout [7:0] data,
+       input [7:0] buttons
+       output reg int
+       );
+
+       reg [7:0] p1;
+       reg [3:0] oldp1013;
+
+       assign data = (rd && (addr == `ADDR_P1)) ? p1 : 8'bzzzzzzzz;
+
+       wire p1013 = (p1[4] ? 4'b1111 : ~buttons[3:0]) | (p1[5] ? 4'b1111 : ~buttons[7:4]);
+
+       always @ (negedge core_clk) begin
+               if(wr) begin
+                       case(addr)
+                       `ADDR_P1: p1[5:4] <= data[5:4];
+                       endcase
+               end
+               p1[3:0] <= p1013;
+               oldp1013 <= p1013;
+               int <= | (oldp1013 & (oldp1013 ^ p1013));
+       end
+endmodule
This page took 0.029951 seconds and 4 git commands to generate.