Skip to content

Commit

Permalink
Support mouse wheel.
Browse files Browse the repository at this point in the history
  • Loading branch information
sorgelig committed Jun 30, 2020
1 parent 77f9a2a commit 131132c
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
5 changes: 5 additions & 0 deletions hps_ext.v
Expand Up @@ -109,6 +109,11 @@ always@(posedge clk_sys) begin
// third byte contains the buttons
mouse_buttons <= io_din[2:0];
end
4: begin
// wheel
kbd_mouse_data <= io_din[7:0];
kbd_mouse_level <= ~kbd_mouse_level;
end
endcase

UIO_KEYBOARD:
Expand Down
16 changes: 13 additions & 3 deletions rtl/userio.v
Expand Up @@ -98,7 +98,6 @@ reg [15:0] _sjoy2; // synchronized joystick 2 signals
reg [15:0] _djoy2; // synchronized joystick 2 signals
reg [15:0] potreg; // POTGO write
wire [15:0] mouse0dat; // mouse counters
wire [7:0] mouse0scr = 0; // mouse scroller
reg [15:0] dmouse0dat; // docking mouse counters
reg [15:0] dmouse1dat; // docking mouse counters
wire _mleft; // left mouse button
Expand Down Expand Up @@ -285,22 +284,33 @@ assign test_data = data_in[15:0];
//// mouse ////
reg [ 7:0] xcount;
reg [ 7:0] ycount;
reg [ 7:0] mouse0scr;

// mouse counters
always @(posedge clk) begin
reg old_level;
reg wheel;

old_level <= kms_level;

if(reset) begin
xcount <= 0;
ycount <= 0;
mouse0scr <= 0;
wheel <= 0;
end else if (test_load && clk7_en) begin
ycount[7:2] <= test_data[15:10];
xcount[7:2] <= test_data[7:2];
end else if (old_level ^ kms_level) begin
if(kbd_mouse_type == 0) xcount[7:0] <= xcount[7:0] + kbd_mouse_data;
if(kbd_mouse_type == 1) ycount[7:0] <= ycount[7:0] + kbd_mouse_data;
if(kbd_mouse_type == 0) begin
wheel <= 0;
xcount[7:0] <= xcount[7:0] + kbd_mouse_data;
end
if(kbd_mouse_type == 1) begin
wheel <= 1;
if(wheel) mouse0scr <= mouse0scr + kbd_mouse_data;
else ycount[7:0] <= ycount[7:0] + kbd_mouse_data;
end
end
end

Expand Down

0 comments on commit 131132c

Please sign in to comment.