]> Joshua Wise's Git repositories - fpgaboy.git/blobdiff - Buttons.v
Working input in GB BASIC!
[fpgaboy.git] / Buttons.v
index 6caecd64e164cb987ef340a34618518ec5899eb1..f81060c873ccc36c6ccaf76250238a3bcdeea21f 100644 (file)
--- a/Buttons.v
+++ b/Buttons.v
@@ -1,4 +1,4 @@
-`define ADDR_P1 16'hFF10
+`define ADDR_P1 16'hFF00
 
 /* note: buttons are 'pressed' when the input is high */
 
@@ -8,23 +8,28 @@ module Buttons(
        input rd,
        input [15:0] addr,
        inout [7:0] data,
-       input [7:0] buttons
+       input [7:0] buttons,
        output reg int
        );
 
+       reg rdlatch;
+       reg [15:0] addrlatch;
+
        reg [7:0] p1;
        reg [3:0] oldp1013;
 
-       assign data = (rd && (addr == `ADDR_P1)) ? p1 : 8'bzzzzzzzz;
+       assign data = (rdlatch && (addrlatch == `ADDR_P1)) ? p1 : 8'bzzzzzzzz;
 
-       wire p1013 = (p1[4] ? 4'b1111 : ~buttons[3:0]) | (p1[5] ? 4'b1111 : ~buttons[7:4]);
+       wire [3:0] p1013 = (p1[4] ? 4'b1111 : ~buttons[3:0]) & (p1[5] ? 4'b1111 : ~buttons[7:4]);
 
-       always @ (negedge core_clk) begin
+       always @ (posedge core_clk) begin
                if(wr) begin
                        case(addr)
                        `ADDR_P1: p1[5:4] <= data[5:4];
                        endcase
                end
+               rdlatch <= rd;
+               addrlatch <= addr;
                p1[3:0] <= p1013;
                oldp1013 <= p1013;
                int <= | (oldp1013 & (oldp1013 ^ p1013));
This page took 0.028943 seconds and 4 git commands to generate.