| 1 |
2 |
robfinch |
// ============================================================================
|
| 2 |
|
|
// Scan Code Converter
|
| 3 |
|
|
// - Convert PS2 style scancodes to ascii
|
| 4 |
|
|
//
|
| 5 |
|
|
// 2010 Robert Finch
|
| 6 |
|
|
// robfinch<remove>@FPGAfield.ca
|
| 7 |
|
|
//
|
| 8 |
|
|
//
|
| 9 |
|
|
// This source code is available for evaluation and validation purposes
|
| 10 |
|
|
// only. This copyright statement and disclaimer must remain present in
|
| 11 |
|
|
// the file.
|
| 12 |
|
|
//
|
| 13 |
|
|
//
|
| 14 |
|
|
// NO WARRANTY.
|
| 15 |
|
|
// THIS Work, IS PROVIDEDED "AS IS" WITH NO WARRANTIES OF ANY KIND, WHETHER
|
| 16 |
|
|
// EXPRESS OR IMPLIED. The user must assume the entire risk of using the
|
| 17 |
|
|
// Work.
|
| 18 |
|
|
//
|
| 19 |
|
|
// IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ANY
|
| 20 |
|
|
// INCIDENTAL, CONSEQUENTIAL, OR PUNITIVE DAMAGES WHATSOEVER RELATING TO
|
| 21 |
|
|
// THE USE OF THIS WORK, OR YOUR RELATIONSHIP WITH THE AUTHOR.
|
| 22 |
|
|
//
|
| 23 |
|
|
// IN ADDITION, IN NO EVENT DOES THE AUTHOR AUTHORIZE YOU TO USE THE WORK
|
| 24 |
|
|
// IN APPLICATIONS OR SYSTEMS WHERE THE WORK'S FAILURE TO PERFORM CAN
|
| 25 |
|
|
// REASONABLY BE EXPECTED TO RESULT IN A SIGNIFICANT PHYSICAL INJURY, OR IN
|
| 26 |
|
|
// LOSS OF LIFE. ANY SUCH USE BY YOU IS ENTIRELY AT YOUR OWN RISK, AND YOU
|
| 27 |
|
|
// AGREE TO HOLD THE AUTHOR AND CONTRIBUTORS HARMLESS FROM ANY CLAIMS OR
|
| 28 |
|
|
// LOSSES RELATING TO SUCH UNAUTHORIZED USE.
|
| 29 |
|
|
//
|
| 30 |
|
|
//
|
| 31 |
|
|
// Convert a PS2 scancode to ascii
|
| 32 |
|
|
//
|
| 33 |
|
|
// Verilog 1995
|
| 34 |
|
|
// Webpack 9.2i xc3s1200-4fg320
|
| 35 |
|
|
// 86 slices / 151 LUTs / 13.164 ns
|
| 36 |
|
|
//
|
| 37 |
|
|
// ============================================================================
|
| 38 |
|
|
|
| 39 |
|
|
module PS2ScanToAscii(shift, ctrl, alt, extend, sc, ascii);
|
| 40 |
|
|
input shift; // shift indicator
|
| 41 |
|
|
input ctrl;
|
| 42 |
|
|
input alt;
|
| 43 |
|
|
input extend; // extended scancode
|
| 44 |
|
|
input [7:0] sc; // scan code
|
| 45 |
|
|
output [7:0] ascii; // acsii equivalent
|
| 46 |
|
|
reg [7:0] ascii;
|
| 47 |
|
|
|
| 48 |
|
|
|
| 49 |
|
|
always @(sc or shift or ctrl or extend)
|
| 50 |
|
|
begin
|
| 51 |
|
|
if (extend) begin
|
| 52 |
|
|
case (sc)
|
| 53 |
|
|
8'h75: ascii <= 8'h90; // up
|
| 54 |
|
|
8'h74: ascii <= 8'h91; // right
|
| 55 |
|
|
8'h72: ascii <= 8'h92; // down
|
| 56 |
|
|
8'h6b: ascii <= 8'h93; // left
|
| 57 |
|
|
8'h6c: ascii <= 8'h94; // home
|
| 58 |
|
|
8'h69: ascii <= 8'h95; // end
|
| 59 |
|
|
8'h7d: ascii <= 8'h96; // pg up
|
| 60 |
|
|
8'h7a: ascii <= 8'h97; // pg down
|
| 61 |
|
|
8'h70: ascii <= 8'h98; // insert
|
| 62 |
|
|
8'h71: ascii <= 8'h99; // delete
|
| 63 |
|
|
8'h05: ascii <= 8'ha1; // F1
|
| 64 |
|
|
8'h06: ascii <= 8'ha2; // F2
|
| 65 |
|
|
8'h04: ascii <= 8'ha3; // F3
|
| 66 |
|
|
default: ascii <= 8'h2e;
|
| 67 |
|
|
endcase
|
| 68 |
|
|
end
|
| 69 |
|
|
else if (ctrl) begin
|
| 70 |
|
|
case (sc)
|
| 71 |
|
|
8'h0d: ascii <= 8'h09;
|
| 72 |
|
|
8'h0e: ascii <= 8'h7e; // ~
|
| 73 |
|
|
8'h15: ascii <= 8'h11; // Q
|
| 74 |
|
|
8'h16: ascii <= 8'h21; // !
|
| 75 |
|
|
8'h1b: ascii <= 8'h13; // S
|
| 76 |
|
|
8'h1a: ascii <= 8'h1a; // Z
|
| 77 |
|
|
8'h1c: ascii <= 8'h01; // A
|
| 78 |
|
|
8'h1d: ascii <= 8'h17; // W
|
| 79 |
|
|
8'h1e: ascii <= 8'h40; // @
|
| 80 |
|
|
8'h21: ascii <= 8'h03; // C
|
| 81 |
|
|
8'h22: ascii <= 8'h18; // X
|
| 82 |
|
|
8'h23: ascii <= 8'h04; // D
|
| 83 |
|
|
8'h24: ascii <= 8'h05; // E
|
| 84 |
|
|
8'h25: ascii <= 8'h24; // $
|
| 85 |
|
|
8'h26: ascii <= 8'h23; // #
|
| 86 |
|
|
8'h29: ascii <= 8'h20; // space
|
| 87 |
|
|
8'h2a: ascii <= 8'h16; // V
|
| 88 |
|
|
8'h2b: ascii <= 8'h06; // F
|
| 89 |
|
|
8'h2c: ascii <= 8'h14; // T
|
| 90 |
|
|
8'h2d: ascii <= 8'h12; // R
|
| 91 |
|
|
8'h2e: ascii <= 8'h25; // %
|
| 92 |
|
|
8'h31: ascii <= 8'h0e; // N
|
| 93 |
|
|
8'h32: ascii <= 8'h02; // B
|
| 94 |
|
|
8'h33: ascii <= 8'h08; // H
|
| 95 |
|
|
8'h34: ascii <= 8'h07; // G
|
| 96 |
|
|
8'h35: ascii <= 8'h19; // Y
|
| 97 |
|
|
8'h36: ascii <= 8'h5e; // ^
|
| 98 |
|
|
8'h3a: ascii <= 8'h0d; // M
|
| 99 |
|
|
8'h3b: ascii <= 8'h0a; // J
|
| 100 |
|
|
8'h3c: ascii <= 8'h15; // U
|
| 101 |
|
|
8'h3d: ascii <= 8'h26; // &
|
| 102 |
|
|
8'h3e: ascii <= 8'h2a; // *
|
| 103 |
|
|
8'h41: ascii <= 8'h3c; // <
|
| 104 |
|
|
8'h42: ascii <= 8'h0b; // K
|
| 105 |
|
|
8'h43: ascii <= 8'h09; // I
|
| 106 |
|
|
8'h44: ascii <= 8'h0f; // O
|
| 107 |
|
|
8'h45: ascii <= 8'h29; // )
|
| 108 |
|
|
8'h46: ascii <= 8'h28; // (
|
| 109 |
|
|
8'h49: ascii <= 8'h3e; // >
|
| 110 |
|
|
8'h4a: ascii <= 8'h3f; // ?
|
| 111 |
|
|
8'h4b: ascii <= 8'h0c; // L
|
| 112 |
|
|
8'h4c: ascii <= 8'h3a; // :
|
| 113 |
|
|
8'h4d: ascii <= 8'h10; // P
|
| 114 |
|
|
8'h4e: ascii <= 8'h5f; // _
|
| 115 |
|
|
8'h52: ascii <= 8'h22; // "
|
| 116 |
|
|
8'h54: ascii <= 8'h7b; // {
|
| 117 |
|
|
8'h55: ascii <= 8'h2b; // +
|
| 118 |
|
|
8'h5a: ascii <= 8'h0d;
|
| 119 |
|
|
8'h5b: ascii <= 8'h7d; // }
|
| 120 |
|
|
8'h5d: ascii <= 8'h7c; // |
|
| 121 |
|
|
8'h66: ascii <= 8'h08;
|
| 122 |
|
|
8'h76: ascii <= 8'h1b;
|
| 123 |
|
|
8'h71: ascii <= 8'h7f; // del
|
| 124 |
|
|
default: ascii <= 8'h2e;
|
| 125 |
|
|
endcase
|
| 126 |
|
|
end
|
| 127 |
|
|
else if (shift) begin
|
| 128 |
|
|
case (sc)
|
| 129 |
|
|
8'h0d: ascii <= 8'h09;
|
| 130 |
|
|
8'h0e: ascii <= 8'h7e; // ~
|
| 131 |
|
|
8'h15: ascii <= 8'h51; // Q
|
| 132 |
|
|
8'h16: ascii <= 8'h21; // !
|
| 133 |
|
|
8'h1b: ascii <= 8'h53; // S
|
| 134 |
|
|
8'h1a: ascii <= 8'h5a; // Z
|
| 135 |
|
|
8'h1c: ascii <= 8'h41; // A
|
| 136 |
|
|
8'h1d: ascii <= 8'h57; // W
|
| 137 |
|
|
8'h1e: ascii <= 8'h40; // @
|
| 138 |
|
|
8'h21: ascii <= 8'h43; // C
|
| 139 |
|
|
8'h22: ascii <= 8'h58; // X
|
| 140 |
|
|
8'h23: ascii <= 8'h44; // D
|
| 141 |
|
|
8'h24: ascii <= 8'h45; // E
|
| 142 |
|
|
8'h25: ascii <= 8'h24; // $
|
| 143 |
|
|
8'h26: ascii <= 8'h23; // #
|
| 144 |
|
|
8'h29: ascii <= 8'h20; // space
|
| 145 |
|
|
8'h2a: ascii <= 8'h56; // V
|
| 146 |
|
|
8'h2b: ascii <= 8'h46; // F
|
| 147 |
|
|
8'h2c: ascii <= 8'h54; // T
|
| 148 |
|
|
8'h2d: ascii <= 8'h52; // R
|
| 149 |
|
|
8'h2e: ascii <= 8'h25; // %
|
| 150 |
|
|
8'h31: ascii <= 8'h4e; // N
|
| 151 |
|
|
8'h32: ascii <= 8'h42; // B
|
| 152 |
|
|
8'h33: ascii <= 8'h48; // H
|
| 153 |
|
|
8'h34: ascii <= 8'h47; // G
|
| 154 |
|
|
8'h35: ascii <= 8'h59; // Y
|
| 155 |
|
|
8'h36: ascii <= 8'h5e; // ^
|
| 156 |
|
|
8'h3a: ascii <= 8'h4d; // M
|
| 157 |
|
|
8'h3b: ascii <= 8'h4a; // J
|
| 158 |
|
|
8'h3c: ascii <= 8'h55; // U
|
| 159 |
|
|
8'h3d: ascii <= 8'h26; // &
|
| 160 |
|
|
8'h3e: ascii <= 8'h2a; // *
|
| 161 |
|
|
8'h41: ascii <= 8'h3c; // <
|
| 162 |
|
|
8'h42: ascii <= 8'h4b; // K
|
| 163 |
|
|
8'h43: ascii <= 8'h49; // I
|
| 164 |
|
|
8'h44: ascii <= 8'h4f; // O
|
| 165 |
|
|
8'h45: ascii <= 8'h29; // )
|
| 166 |
|
|
8'h46: ascii <= 8'h28; // (
|
| 167 |
|
|
8'h49: ascii <= 8'h3e; // >
|
| 168 |
|
|
8'h4a: ascii <= 8'h3f; // ?
|
| 169 |
|
|
8'h4b: ascii <= 8'h4c; // L
|
| 170 |
|
|
8'h4c: ascii <= 8'h3a; // :
|
| 171 |
|
|
8'h4d: ascii <= 8'h50; // P
|
| 172 |
|
|
8'h4e: ascii <= 8'h5f; // _
|
| 173 |
|
|
8'h52: ascii <= 8'h22; // "
|
| 174 |
|
|
8'h54: ascii <= 8'h7b; // {
|
| 175 |
|
|
8'h55: ascii <= 8'h2b; // +
|
| 176 |
|
|
8'h5a: ascii <= 8'h0d;
|
| 177 |
|
|
8'h5b: ascii <= 8'h7d; // }
|
| 178 |
|
|
8'h5d: ascii <= 8'h7c; // |
|
| 179 |
|
|
8'h66: ascii <= 8'h08;
|
| 180 |
|
|
8'h76: ascii <= 8'h1b;
|
| 181 |
|
|
8'h71: ascii <= 8'h7f; // del
|
| 182 |
|
|
default: ascii <= 8'h2e;
|
| 183 |
|
|
endcase
|
| 184 |
|
|
end
|
| 185 |
|
|
else begin
|
| 186 |
|
|
case (sc)
|
| 187 |
|
|
8'h0d: ascii <= 8'h09; // tab
|
| 188 |
|
|
8'h0e: ascii <= 8'h60; // `
|
| 189 |
|
|
8'h15: ascii <= 8'h71; // q
|
| 190 |
|
|
8'h16: ascii <= 8'h31; // 1
|
| 191 |
|
|
8'h1a: ascii <= 8'h7a; // z
|
| 192 |
|
|
8'h1b: ascii <= 8'h73; // s
|
| 193 |
|
|
8'h1c: ascii <= 8'h61; // a
|
| 194 |
|
|
8'h1d: ascii <= 8'h77; // w
|
| 195 |
|
|
8'h1e: ascii <= 8'h32; // 2
|
| 196 |
|
|
8'h21: ascii <= 8'h63; // c
|
| 197 |
|
|
8'h22: ascii <= 8'h78; // x
|
| 198 |
|
|
8'h23: ascii <= 8'h64; // d
|
| 199 |
|
|
8'h24: ascii <= 8'h65; // e
|
| 200 |
|
|
8'h25: ascii <= 8'h34; // 4
|
| 201 |
|
|
8'h26: ascii <= 8'h33; // 3
|
| 202 |
|
|
8'h29: ascii <= 8'h20; // space
|
| 203 |
|
|
8'h2a: ascii <= 8'h76; // v
|
| 204 |
|
|
8'h2b: ascii <= 8'h66; // f
|
| 205 |
|
|
8'h2c: ascii <= 8'h74; // t
|
| 206 |
|
|
8'h2d: ascii <= 8'h72; // r
|
| 207 |
|
|
8'h2e: ascii <= 8'h35; // 5
|
| 208 |
|
|
8'h31: ascii <= 8'h6e; // n
|
| 209 |
|
|
8'h32: ascii <= 8'h62; // b
|
| 210 |
|
|
8'h33: ascii <= 8'h68; // h
|
| 211 |
|
|
8'h34: ascii <= 8'h67; // g
|
| 212 |
|
|
8'h35: ascii <= 8'h79; // y
|
| 213 |
|
|
8'h36: ascii <= 8'h36; // 6
|
| 214 |
|
|
8'h3a: ascii <= 8'h6d; // m
|
| 215 |
|
|
8'h3b: ascii <= 8'h6a; // j
|
| 216 |
|
|
8'h3c: ascii <= 8'h75; // u
|
| 217 |
|
|
8'h3d: ascii <= 8'h37; // 7
|
| 218 |
|
|
8'h3e: ascii <= 8'h38; // 8
|
| 219 |
|
|
8'h41: ascii <= 8'h2c; // ,
|
| 220 |
|
|
8'h42: ascii <= 8'h6b; // k
|
| 221 |
|
|
8'h43: ascii <= 8'h69; // i
|
| 222 |
|
|
8'h44: ascii <= 8'h6f; // o
|
| 223 |
|
|
8'h45: ascii <= 8'h30; // 0
|
| 224 |
|
|
8'h46: ascii <= 8'h39; // 9
|
| 225 |
|
|
8'h49: ascii <= 8'h2e; // .
|
| 226 |
|
|
8'h4a: ascii <= 8'h2f; // /
|
| 227 |
|
|
8'h4b: ascii <= 8'h6c; // l
|
| 228 |
|
|
8'h4c: ascii <= 8'h3b; // ;
|
| 229 |
|
|
8'h4d: ascii <= 8'h70; // p
|
| 230 |
|
|
8'h4e: ascii <= 8'h2d; // -
|
| 231 |
|
|
8'h52: ascii <= 8'h27; // '
|
| 232 |
|
|
8'h54: ascii <= 8'h5b; // [
|
| 233 |
|
|
8'h55: ascii <= 8'h3d; // =
|
| 234 |
|
|
8'h5a: ascii <= 8'h0d; // carriage return
|
| 235 |
|
|
8'h5b: ascii <= 8'h5d; // ]
|
| 236 |
|
|
8'h5d: ascii <= 8'h5c; // \
|
| 237 |
|
|
8'h63: ascii <= 8'h90; // up {set 3}
|
| 238 |
|
|
8'h66: ascii <= 8'h08; // backspace
|
| 239 |
|
|
8'h71: ascii <= 8'h7f; // del
|
| 240 |
|
|
8'h76: ascii <= 8'h1b; // escape
|
| 241 |
|
|
default: ascii <= 8'h2e; // '.' used for unlisted characters.
|
| 242 |
|
|
endcase
|
| 243 |
|
|
end
|
| 244 |
|
|
end
|
| 245 |
|
|
|
| 246 |
|
|
endmodule
|