Line 52... |
Line 52... |
);
|
);
|
|
|
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
//
|
//
|
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
reg [4:0] keys [0:7]; // 8 rows of 5 bits each
|
reg [4:0] keys [0:7]; // 8 rows of 5 bits each: contains 0 for a pressed key at a specific location, 1 otherwise
|
|
|
reg released; // Tracks "released" scan code (F0)
|
reg released; // Tracks "released" scan code (F0): contains 0 when a key is pressed, 1 otherwise
|
reg extended; // Tracks "extended" scan code (E0)
|
reg extended; // Tracks "extended" scan code (E0)
|
reg shifted; // Tracks local "shifted" state
|
reg shifted; // Tracks local "shifted" state
|
|
|
// Calculate a "key is pressed" signal
|
// Calculate a "key is pressed" signal
|
assign pressed = ~(&keys[7] & &keys[6] & &keys[5] & &keys[4] & &keys[3] & &keys[2] & &keys[1] & &keys[0]);
|
assign pressed = ~(&keys[7] & &keys[6] & &keys[5] & &keys[4] & &keys[3] & &keys[2] & &keys[1] & &keys[0]);
|
Line 89... |
Line 89... |
keys[5] <= '1;
|
keys[5] <= '1;
|
keys[6] <= '1;
|
keys[6] <= '1;
|
keys[7] <= '1;
|
keys[7] <= '1;
|
end else
|
end else
|
if (scan_code_ready) begin
|
if (scan_code_ready) begin
|
if (scan_code==8'hE0)
|
if (scan_code==8'hE0) // Extended code prefix byte
|
extended <= 1;
|
extended <= 1;
|
else if (scan_code==8'hF0)
|
else if (scan_code==8'hF0) // Break code prefix byte
|
released <= 1;
|
released <= 1;
|
else begin
|
else begin
|
// Cancel release/extended flags for the next clock
|
// Cancel release/extended flags for the next clock
|
extended <= 0;
|
extended <= 0;
|
released <= 0;
|
released <= 0;
|
Line 121... |
Line 121... |
end
|
end
|
endcase
|
endcase
|
end
|
end
|
else begin
|
else begin
|
// For each PS/2 scan-code, set the ZX keyboard matrix state
|
// For each PS/2 scan-code, set the ZX keyboard matrix state
|
// 'released' contains 0 when a key is pressed; 1 otherwise
|
|
case (scan_code)
|
case (scan_code)
|
8'h12: shifted <= !released; // Local SHIFT key (left)
|
8'h12: shifted <= !released; // Local SHIFT key (left)
|
8'h59: shifted <= !released; // Local SHIFT key (right)
|
8'h59: shifted <= !released; // Local SHIFT key (right)
|
|
|
8'h14: keys[0][0] <= released; // CAPS SHIFT = Left or right Ctrl
|
8'h14: keys[0][0] <= released; // CAPS SHIFT = Left or right Ctrl
|
Line 183... |
Line 182... |
end
|
end
|
8'h76: begin // ESC -> BREAK
|
8'h76: begin // ESC -> BREAK
|
keys[0][0] <= released; // CAPS SHIFT
|
keys[0][0] <= released; // CAPS SHIFT
|
keys[7][0] <= released; // SPACE
|
keys[7][0] <= released; // SPACE
|
end
|
end
|
|
// With shifted keys, we need to make inactive (set to 1) other corresponding key
|
|
// Otherwise, it will stay active if the shift was released first
|
8'h4E: begin // - or (shifted) _
|
8'h4E: begin // - or (shifted) _
|
if (!shifted) begin
|
|
keys[7][1] <= released; // SYMBOL SHIFT (Red)
|
keys[7][1] <= released; // SYMBOL SHIFT (Red)
|
keys[6][3] <= released; // J
|
keys[4][0] <= shifted ? released : 1; // 0
|
end
|
keys[6][3] <= shifted ? 1 : released; // J
|
else begin
|
|
keys[7][1] <= released; // SYMBOL SHIFT (Red)
|
|
keys[4][0] <= released; // 0
|
|
end
|
|
end
|
end
|
8'h55: begin // = or (shifted) +
|
8'h55: begin // = or (shifted) +
|
if (!shifted) begin
|
|
keys[7][1] <= released; // SYMBOL SHIFT (Red)
|
keys[7][1] <= released; // SYMBOL SHIFT (Red)
|
keys[6][1] <= released; // L
|
keys[6][2] <= shifted ? released : 1; // K
|
end
|
keys[6][1] <= shifted ? 1 : released; // L
|
else begin
|
|
keys[7][1] <= released; // SYMBOL SHIFT (Red)
|
|
keys[6][2] <= released; // K
|
|
end
|
|
end
|
end
|
8'h52: begin // ' or (shifted) "
|
8'h52: begin // ' or (shifted) "
|
if (!shifted) begin
|
|
keys[7][1] <= released; // SYMBOL SHIFT (Red)
|
keys[7][1] <= released; // SYMBOL SHIFT (Red)
|
keys[4][3] <= released; // 7
|
keys[5][0] <= shifted ? released : 1; // P
|
end
|
keys[4][3] <= shifted ? 1 : released; // 7
|
else begin
|
|
keys[7][1] <= released; // SYMBOL SHIFT (Red)
|
|
keys[5][0] <= released; // P
|
|
end
|
|
end
|
end
|
8'h4C: begin // ; or (shifted) :
|
8'h4C: begin // ; or (shifted) :
|
if (!shifted) begin
|
|
keys[7][1] <= released; // SYMBOL SHIFT (Red)
|
keys[7][1] <= released; // SYMBOL SHIFT (Red)
|
keys[5][1] <= released; // O
|
keys[0][1] <= shifted ? released : 1; // Z
|
end
|
keys[5][1] <= shifted ? 1 : released; // O
|
else begin
|
|
keys[7][1] <= released; // SYMBOL SHIFT (Red)
|
|
keys[0][1] <= released; // Z
|
|
end
|
|
end
|
end
|
8'h41: begin // , or (shifted) <
|
8'h41: begin // , or (shifted) <
|
if (!shifted) begin
|
|
keys[7][1] <= released; // SYMBOL SHIFT (Red)
|
keys[7][1] <= released; // SYMBOL SHIFT (Red)
|
keys[7][3] <= released; // N
|
keys[2][3] <= shifted ? released : 1; // R
|
end
|
keys[7][3] <= shifted ? 1 : released; // N
|
else begin
|
|
keys[7][1] <= released; // SYMBOL SHIFT (Red)
|
|
keys[2][3] <= released; // R
|
|
end
|
|
end
|
end
|
8'h49: begin // . or (shifted) >
|
8'h49: begin // . or (shifted) >
|
if (!shifted) begin
|
|
keys[7][1] <= released; // SYMBOL SHIFT (Red)
|
|
keys[7][2] <= released; // M
|
|
end
|
|
else begin
|
|
keys[7][1] <= released; // SYMBOL SHIFT (Red)
|
keys[7][1] <= released; // SYMBOL SHIFT (Red)
|
keys[2][4] <= released; // T
|
keys[2][4] <= shifted ? released : 1; // T
|
end
|
keys[7][2] <= shifted ? 1 : released; // M
|
end
|
end
|
8'h4A: begin // / or (shifted) ?
|
8'h4A: begin // / or (shifted) ?
|
if (!shifted) begin
|
|
keys[7][1] <= released; // SYMBOL SHIFT (Red)
|
keys[7][1] <= released; // SYMBOL SHIFT (Red)
|
keys[0][4] <= released; // V
|
keys[0][3] <= shifted ? released : 1; // C
|
end
|
keys[0][4] <= shifted ? 1 : released; // V
|
else begin
|
|
keys[7][1] <= released; // SYMBOL SHIFT (Red)
|
|
keys[0][3] <= released; // C
|
|
end
|
|
end
|
end
|
endcase
|
endcase
|
end
|
end
|
end
|
end
|
end
|
end
|