1 |
2 |
alfik |
/*
|
2 |
|
|
* Copyright 2010, Aleksander Osman, alfik@poczta.fm. All rights reserved.
|
3 |
|
|
*
|
4 |
|
|
* Redistribution and use in source and binary forms, with or without modification, are
|
5 |
|
|
* permitted provided that the following conditions are met:
|
6 |
|
|
*
|
7 |
|
|
* 1. Redistributions of source code must retain the above copyright notice, this list of
|
8 |
|
|
* conditions and the following disclaimer.
|
9 |
|
|
*
|
10 |
|
|
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
|
11 |
|
|
* of conditions and the following disclaimer in the documentation and/or other materials
|
12 |
|
|
* provided with the distribution.
|
13 |
|
|
*
|
14 |
|
|
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
|
15 |
|
|
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
|
16 |
|
|
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR
|
17 |
|
|
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
18 |
|
|
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
19 |
|
|
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
20 |
|
|
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
21 |
|
|
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
22 |
|
|
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
23 |
|
|
*/
|
24 |
|
|
|
25 |
|
|
/*! \file
|
26 |
|
|
* \brief PS/2 keyboard driver.
|
27 |
|
|
*/
|
28 |
|
|
|
29 |
|
|
/*! \brief \copybrief drv_keyboard.v
|
30 |
|
|
*/
|
31 |
|
|
module drv_keyboard(
|
32 |
|
|
//% \name Clock and reset
|
33 |
|
|
//% @{
|
34 |
|
|
input clk_30,
|
35 |
|
|
input reset_n,
|
36 |
|
|
//% @}
|
37 |
|
|
|
38 |
|
|
//% \name On-Screen-Display management interface
|
39 |
|
|
//% @{
|
40 |
|
|
output reg request_osd,
|
41 |
|
|
input enable_joystick_1,
|
42 |
|
|
//% @}
|
43 |
|
|
|
44 |
|
|
//% \name drv_keyboard interface
|
45 |
|
|
//% @{
|
46 |
|
|
input keyboard_ready,
|
47 |
|
|
output keyboard_event,
|
48 |
|
|
output [7:0] keyboard_scancode,
|
49 |
|
|
|
50 |
|
|
// joystick on port 1
|
51 |
|
|
output reg joystick_1_up,
|
52 |
|
|
output reg joystick_1_down,
|
53 |
|
|
output reg joystick_1_left,
|
54 |
|
|
output reg joystick_1_right,
|
55 |
|
|
output reg joystick_1_fire,
|
56 |
|
|
//% @}
|
57 |
|
|
|
58 |
|
|
//% \name PS/2 keyboard hardware interface
|
59 |
|
|
//% @{
|
60 |
|
|
inout ps2_kbclk,
|
61 |
|
|
inout ps2_kbdat
|
62 |
|
|
//% @}
|
63 |
|
|
);
|
64 |
|
|
|
65 |
|
|
/*
|
66 |
|
|
|
67 |
|
|
PS/2 Protocol:
|
68 |
|
|
********************************************************************************
|
69 |
|
|
(Data, Clock)
|
70 |
|
|
Idle: (1'bZ, 1'bZ)
|
71 |
|
|
Inhibit: (1'bZ, 1'b0)
|
72 |
|
|
Request: (1'b0, 1'bZ)
|
73 |
|
|
|
74 |
|
|
Device to Host:
|
75 |
|
|
if(last_clock == 1'b1 && clock == 1'b0) Read data
|
76 |
|
|
Data frame: 0, 8 data bits LSB first, odd parity, 1
|
77 |
|
|
|
78 |
|
|
Host to Device:
|
79 |
|
|
State: Inhibit for 100 microseconds, Clock <= 1'b0
|
80 |
|
|
State: Request Data <= 1'b0
|
81 |
|
|
if(last_clock == 1'b1 && clock == 1'b0) Write data Data <= bit
|
82 |
|
|
Data frame: 0, 8 data bits, odd parity
|
83 |
|
|
if(last_clock == 1'b1 && clock == 1'b0) Release data
|
84 |
|
|
if(last_clock == 1'b1 && clock == 1'b0) Read data acknowlege (0)
|
85 |
|
|
Wait for Idle
|
86 |
|
|
|
87 |
|
|
Keyboard:
|
88 |
|
|
********************************************************************************
|
89 |
|
|
Power-on:
|
90 |
|
|
Keyboard: 0xAA (BAT OK) or 0xFC (Error)
|
91 |
|
|
|
92 |
|
|
Make and break code:
|
93 |
|
|
Keyboard: 0x12 (Shift make code)
|
94 |
|
|
Keyboard: 0xF0 (Shift break code 1)
|
95 |
|
|
Keyboard: 0x12 (Shift break code 2)
|
96 |
|
|
|
97 |
|
|
Errors:
|
98 |
|
|
Keyboard: 0xFE (Resend)
|
99 |
|
|
|
100 |
|
|
Set LEDs:
|
101 |
|
|
Host: 0xED
|
102 |
|
|
Keyboard: 0xFA (Aknowlege)
|
103 |
|
|
Host: 0,0,0,0,0, Caps Lock, Num Lock, Scroll Lock
|
104 |
|
|
Keyboard: 0xFA (Aknowlege)
|
105 |
|
|
|
106 |
|
|
|
107 |
|
|
Mouse:
|
108 |
|
|
********************************************************************************
|
109 |
|
|
Power-on:
|
110 |
|
|
Mouse: 0xAA (BAT OK) or 0xFC (Error)
|
111 |
|
|
Mouse: 0x00 (ID)
|
112 |
|
|
|
113 |
|
|
Enable reporting:
|
114 |
|
|
Host: 0xF4 (Enable Data Reporting)
|
115 |
|
|
Mouse: 0xFA (Aknowlege)
|
116 |
|
|
|
117 |
|
|
Report:
|
118 |
|
|
Mouse: Y overflow, X overflow, Y sign, X sign, 1, Middle, Right, Left
|
119 |
|
|
Mouse: X movement
|
120 |
|
|
Mouse: Y movement
|
121 |
|
|
|
122 |
|
|
Errors:
|
123 |
|
|
Mouse: 0xFE (Resend) or 0xFC (Error)
|
124 |
|
|
Host: 0xFE (Resend) or 0xFC (Error)
|
125 |
|
|
|
126 |
|
|
********************************************************************************
|
127 |
|
|
|
128 |
|
|
*/
|
129 |
|
|
|
130 |
|
|
// ---------------- DEBUG
|
131 |
|
|
/*
|
132 |
|
|
wire debug_write;
|
133 |
|
|
assign debug_write = (new_ps2 == 1'b0 && amiga_new == 1'b0 && cnt_counter == 16'd0 && amiga_avail > 4'd0);
|
134 |
|
|
|
135 |
|
|
reg [7:0] debug_addr;
|
136 |
|
|
always @(posedge clk_30 or negedge reset_n) begin
|
137 |
|
|
if(reset_n == 1'b0) debug_addr <= 8'd0;
|
138 |
|
|
else if(debug_write == 1'b1 && debug_addr < 8'd255) debug_addr <= debug_addr + 8'd1;
|
139 |
|
|
end
|
140 |
|
|
|
141 |
|
|
altsyncram debug_ram_inst(
|
142 |
|
|
.clock0(clk_30),
|
143 |
|
|
|
144 |
|
|
.address_a(debug_addr),
|
145 |
|
|
.wren_a(debug_write == 1'b1),
|
146 |
|
|
.data_a(amiga_keycodes[95:88]),
|
147 |
|
|
.q_a()
|
148 |
|
|
);
|
149 |
|
|
defparam
|
150 |
|
|
debug_ram_inst.operation_mode = "SINGLE_PORT",
|
151 |
|
|
debug_ram_inst.width_a = 8,
|
152 |
|
|
debug_ram_inst.lpm_hint = "ENABLE_RUNTIME_MOD=YES,INSTANCE_NAME=kb",
|
153 |
|
|
debug_ram_inst.widthad_a = 8;
|
154 |
|
|
*/
|
155 |
|
|
//--------------------- DEBUG
|
156 |
|
|
|
157 |
|
|
|
158 |
|
|
// caps lock bit7: 0 - turn on light, 1 - turn off light
|
159 |
|
|
// 6-5-4-3-2-1-0-7
|
160 |
|
|
// Make Pause, no break pause: { 8'hE1, 8'h14, 8'h77, 8'hE1, 8'hF0, 8'h14, 8'hF0, 8'h77 }
|
161 |
|
|
|
162 |
|
|
|
163 |
|
|
assign ps2_kbclk = 1'bZ;
|
164 |
|
|
assign ps2_kbdat = 1'bZ;
|
165 |
|
|
|
166 |
|
|
reg [15:0] mv;
|
167 |
|
|
reg mv_wait;
|
168 |
|
|
reg was_ps2_kbclk;
|
169 |
|
|
always @(posedge clk_30 or negedge reset_n) begin
|
170 |
|
|
if(reset_n == 1'b0) begin
|
171 |
|
|
mv <= 16'd0;
|
172 |
|
|
mv_wait <= 1'b0;
|
173 |
|
|
was_ps2_kbclk <= 1'b0;
|
174 |
|
|
end
|
175 |
|
|
else begin
|
176 |
|
|
mv <= { mv[14:0], ps2_kbclk };
|
177 |
|
|
|
178 |
|
|
if(mv_wait == 1'b0 && mv[15:12] == 4'b1111 && mv[3:0] == 4'b0000) begin
|
179 |
|
|
was_ps2_kbclk <= 1'b1;
|
180 |
|
|
mv_wait <= 1'b1;
|
181 |
|
|
end
|
182 |
|
|
else if(mv_wait == 1'b1 && mv[15:0] == 16'h0000) begin
|
183 |
|
|
mv_wait <= 1'b0;
|
184 |
|
|
was_ps2_kbclk <= 1'b0;
|
185 |
|
|
end
|
186 |
|
|
else begin
|
187 |
|
|
was_ps2_kbclk <= 1'b0;
|
188 |
|
|
end
|
189 |
|
|
end
|
190 |
|
|
end
|
191 |
|
|
|
192 |
|
|
wire new_ps2;
|
193 |
|
|
assign new_ps2 = (was_ps2_kbclk == 1'b1 && kbdat_counter == 4'd10 && kbdat[0] == 1'b0 && ps2_kbdat == 1'b1 && kbdat_parity == 1'b1);
|
194 |
|
|
|
195 |
|
|
reg [9:0] kbdat;
|
196 |
|
|
reg [3:0] kbdat_counter;
|
197 |
|
|
reg [23:0] timeout;
|
198 |
|
|
reg kbdat_parity;
|
199 |
|
|
|
200 |
|
|
always @(posedge clk_30 or negedge reset_n) begin
|
201 |
|
|
if(reset_n == 1'b0) begin
|
202 |
|
|
kbdat <= 10'd0;
|
203 |
|
|
kbdat_counter <= 4'd0;
|
204 |
|
|
kbdat_parity <= 1'b0;
|
205 |
|
|
timeout <= 24'd0;
|
206 |
|
|
end
|
207 |
|
|
else begin
|
208 |
|
|
|
209 |
|
|
if(kbdat_counter != 4'd0 && timeout != 24'hFFFFFF) timeout <= timeout + 24'd1;
|
210 |
|
|
else if(kbdat_counter == 4'd0) timeout <= 24'd0;
|
211 |
|
|
|
212 |
|
|
if(was_ps2_kbclk == 1'b1) begin
|
213 |
|
|
kbdat <= { ps2_kbdat, kbdat[9:1] };
|
214 |
|
|
|
215 |
|
|
if(kbdat_counter == 4'd10) begin
|
216 |
|
|
kbdat_counter <= 4'd0;
|
217 |
|
|
end
|
218 |
|
|
else begin
|
219 |
|
|
kbdat_counter <= kbdat_counter + 4'd1;
|
220 |
|
|
if(kbdat_counter == 4'd0) kbdat_parity <= 1'b0;
|
221 |
|
|
else if(ps2_kbdat == 1'b1) kbdat_parity <= !kbdat_parity;
|
222 |
|
|
end
|
223 |
|
|
end
|
224 |
|
|
else if(timeout == 24'hFFFFFF) begin
|
225 |
|
|
kbdat_counter <= 4'd0;
|
226 |
|
|
end
|
227 |
|
|
end
|
228 |
|
|
end
|
229 |
|
|
|
230 |
|
|
wire pressed;
|
231 |
|
|
altsyncram pressed_code_inst(
|
232 |
|
|
.clock0(clk_30),
|
233 |
|
|
|
234 |
|
|
.address_a(amiga_keycode[6:0]),
|
235 |
|
|
.wren_a(new_ps2 == 1'b0 && amiga_new == 1'b1 && delay == 1'b1),
|
236 |
|
|
.data_a(amiga_keycode[7] == 1'b0),
|
237 |
|
|
.q_a(pressed)
|
238 |
|
|
);
|
239 |
|
|
defparam
|
240 |
|
|
pressed_code_inst.operation_mode = "SINGLE_PORT",
|
241 |
|
|
pressed_code_inst.width_a = 1,
|
242 |
|
|
pressed_code_inst.widthad_a = 7;
|
243 |
|
|
|
244 |
|
|
|
245 |
|
|
reg [95:0] amiga_keycodes;
|
246 |
|
|
reg [3:0] amiga_avail;
|
247 |
|
|
reg [7:0] amiga_keycode;
|
248 |
|
|
reg amiga_new;
|
249 |
|
|
reg caps_lock;
|
250 |
|
|
reg delay;
|
251 |
|
|
|
252 |
|
|
reg [2:0] state;
|
253 |
|
|
parameter [2:0]
|
254 |
|
|
S_FIRST = 3'd0,
|
255 |
|
|
S_E0 = 3'd1,
|
256 |
|
|
S_E0_12 = 3'd2,
|
257 |
|
|
S_E0_12_E0 = 3'd3,
|
258 |
|
|
S_E0_F0_7C = 3'd4,
|
259 |
|
|
S_E0_F0_7C_E0 = 3'd5,
|
260 |
|
|
S_E0_F0_7C_E0_F0 = 3'd6;
|
261 |
|
|
|
262 |
|
|
assign keyboard_event = (new_ps2 == 1'b0 && amiga_new == 1'b0 && keyboard_ready == 1'b1 && amiga_avail > 4'd0);
|
263 |
|
|
assign keyboard_scancode = { amiga_keycodes[94:88], amiga_keycodes[95] };
|
264 |
|
|
|
265 |
|
|
always @(posedge clk_30 or negedge reset_n) begin
|
266 |
|
|
if(reset_n == 1'b0) begin
|
267 |
|
|
amiga_keycodes <= { 8'hFD, 8'hFE, 80'h0 };
|
268 |
|
|
amiga_avail <= 4'd2;
|
269 |
|
|
|
270 |
|
|
amiga_new <= 1'b0;
|
271 |
|
|
amiga_keycode <= 8'd0;
|
272 |
|
|
caps_lock <= 1'b0;
|
273 |
|
|
delay <= 1'b0;
|
274 |
|
|
state <= S_FIRST;
|
275 |
|
|
|
276 |
|
|
request_osd <= 1'b0;
|
277 |
|
|
joystick_1_up <= 1'b0;
|
278 |
|
|
joystick_1_down <= 1'b0;
|
279 |
|
|
joystick_1_left <= 1'b0;
|
280 |
|
|
joystick_1_right <= 1'b0;
|
281 |
|
|
joystick_1_fire <= 1'b0;
|
282 |
|
|
end
|
283 |
|
|
else begin
|
284 |
|
|
|
285 |
|
|
if(new_ps2 == 1'b1) begin
|
286 |
|
|
delay <= 1'b0;
|
287 |
|
|
|
288 |
|
|
if(state == S_FIRST) begin
|
289 |
|
|
if(kbdat[8:1] == 8'hF0 && amiga_keycode[7] == 1'b0) begin
|
290 |
|
|
amiga_keycode[7] <= 1'b1;
|
291 |
|
|
end
|
292 |
|
|
else if(kbdat[8:1] == 8'hE0) begin
|
293 |
|
|
state <= S_E0;
|
294 |
|
|
end
|
295 |
|
|
else if(kbdat[8:1] == 8'h58) begin
|
296 |
|
|
{ amiga_new, amiga_keycode[6:0] } <= { 1'b1, AKC_CAPS };
|
297 |
|
|
|
298 |
|
|
if(caps_lock == 1'b0 && amiga_keycode[7] == 1'b1) begin
|
299 |
|
|
amiga_keycode[7] <= 1'b0;
|
300 |
|
|
caps_lock <= 1'b1;
|
301 |
|
|
end
|
302 |
|
|
else if(caps_lock == 1'b1 && amiga_keycode[7] == 1'b0) begin
|
303 |
|
|
amiga_keycode[7] <= 1'b1;
|
304 |
|
|
end
|
305 |
|
|
else if(caps_lock == 1'b1 && amiga_keycode[7] == 1'b1) begin
|
306 |
|
|
caps_lock <= 1'b0;
|
307 |
|
|
end
|
308 |
|
|
end
|
309 |
|
|
else begin
|
310 |
|
|
case(kbdat[8:1])
|
311 |
|
|
8'h76: { amiga_new, amiga_keycode[6:0] } <= { 1'b1, AKC_ESC };
|
312 |
|
|
8'h05: { amiga_new, amiga_keycode[6:0] } <= { 1'b1, AKC_F1 };
|
313 |
|
|
8'h06: { amiga_new, amiga_keycode[6:0] } <= { 1'b1, AKC_F2 };
|
314 |
|
|
8'h04: { amiga_new, amiga_keycode[6:0] } <= { 1'b1, AKC_F3 };
|
315 |
|
|
8'h0C: { amiga_new, amiga_keycode[6:0] } <= { 1'b1, AKC_F4 };
|
316 |
|
|
8'h03: { amiga_new, amiga_keycode[6:0] } <= { 1'b1, AKC_F5 };
|
317 |
|
|
8'h0B: { amiga_new, amiga_keycode[6:0] } <= { 1'b1, AKC_F6 };
|
318 |
|
|
8'h83: { amiga_new, amiga_keycode[6:0] } <= { 1'b1, AKC_F7 };
|
319 |
|
|
8'h0A: { amiga_new, amiga_keycode[6:0] } <= { 1'b1, AKC_F8 };
|
320 |
|
|
8'h01: { amiga_new, amiga_keycode[6:0] } <= { 1'b1, AKC_F9 };
|
321 |
|
|
8'h09: { amiga_new, amiga_keycode[6:0] } <= { 1'b1, AKC_F10 };
|
322 |
|
|
8'h78: { amiga_new, amiga_keycode[6:0] } <= { 1'b1, AKC_LAMIGA }; //F11
|
323 |
|
|
8'h07: { amiga_new, amiga_keycode[6:0] } <= { 1'b1, AKC_RAMIGA }; //F12
|
324 |
|
|
8'h0E: { amiga_new, amiga_keycode[6:0] } <= { 1'b1, AKC_APO };
|
325 |
|
|
8'h16: { amiga_new, amiga_keycode[6:0] } <= { 1'b1, AKC_1 };
|
326 |
|
|
8'h1E: { amiga_new, amiga_keycode[6:0] } <= { 1'b1, AKC_2 };
|
327 |
|
|
8'h26: { amiga_new, amiga_keycode[6:0] } <= { 1'b1, AKC_3 };
|
328 |
|
|
8'h25: { amiga_new, amiga_keycode[6:0] } <= { 1'b1, AKC_4 };
|
329 |
|
|
8'h2E: { amiga_new, amiga_keycode[6:0] } <= { 1'b1, AKC_5 };
|
330 |
|
|
8'h36: { amiga_new, amiga_keycode[6:0] } <= { 1'b1, AKC_6 };
|
331 |
|
|
8'h3D: { amiga_new, amiga_keycode[6:0] } <= { 1'b1, AKC_7 };
|
332 |
|
|
8'h3E: { amiga_new, amiga_keycode[6:0] } <= { 1'b1, AKC_8 };
|
333 |
|
|
8'h46: { amiga_new, amiga_keycode[6:0] } <= { 1'b1, AKC_9 };
|
334 |
|
|
8'h45: { amiga_new, amiga_keycode[6:0] } <= { 1'b1, AKC_0 };
|
335 |
|
|
8'h4E: { amiga_new, amiga_keycode[6:0] } <= { 1'b1, AKC_MIN };
|
336 |
|
|
8'h55: { amiga_new, amiga_keycode[6:0] } <= { 1'b1, AKC_EQL };
|
337 |
|
|
8'h5D: { amiga_new, amiga_keycode[6:0] } <= { 1'b1, AKC_BSLA };
|
338 |
|
|
8'h66: { amiga_new, amiga_keycode[6:0] } <= { 1'b1, AKC_BACK };
|
339 |
|
|
8'h0D: { amiga_new, amiga_keycode[6:0] } <= { 1'b1, AKC_TAB };
|
340 |
|
|
8'h15: { amiga_new, amiga_keycode[6:0] } <= { 1'b1, AKC_Q };
|
341 |
|
|
8'h1D: { amiga_new, amiga_keycode[6:0] } <= { 1'b1, AKC_W };
|
342 |
|
|
8'h24: { amiga_new, amiga_keycode[6:0] } <= { 1'b1, AKC_E };
|
343 |
|
|
8'h2D: { amiga_new, amiga_keycode[6:0] } <= { 1'b1, AKC_R };
|
344 |
|
|
8'h2C: { amiga_new, amiga_keycode[6:0] } <= { 1'b1, AKC_T };
|
345 |
|
|
8'h35: { amiga_new, amiga_keycode[6:0] } <= { 1'b1, AKC_Y };
|
346 |
|
|
8'h3C: { amiga_new, amiga_keycode[6:0] } <= { 1'b1, AKC_U };
|
347 |
|
|
8'h43: { amiga_new, amiga_keycode[6:0] } <= { 1'b1, AKC_I };
|
348 |
|
|
8'h44: { amiga_new, amiga_keycode[6:0] } <= { 1'b1, AKC_O };
|
349 |
|
|
8'h4D: { amiga_new, amiga_keycode[6:0] } <= { 1'b1, AKC_P };
|
350 |
|
|
8'h54: { amiga_new, amiga_keycode[6:0] } <= { 1'b1, AKC_SBRAL };
|
351 |
|
|
8'h5B: { amiga_new, amiga_keycode[6:0] } <= { 1'b1, AKC_SBRAR };
|
352 |
|
|
8'h5A: { amiga_new, amiga_keycode[6:0] } <= { 1'b1, AKC_ENTER };
|
353 |
|
|
8'h14: { amiga_new, amiga_keycode[6:0] } <= { 1'b1, AKC_CTRL };
|
354 |
|
|
8'h1C: { amiga_new, amiga_keycode[6:0] } <= { 1'b1, AKC_A };
|
355 |
|
|
8'h1B: { amiga_new, amiga_keycode[6:0] } <= { 1'b1, AKC_S };
|
356 |
|
|
8'h23: { amiga_new, amiga_keycode[6:0] } <= { 1'b1, AKC_D };
|
357 |
|
|
8'h2B: { amiga_new, amiga_keycode[6:0] } <= { 1'b1, AKC_F };
|
358 |
|
|
8'h34: { amiga_new, amiga_keycode[6:0] } <= { 1'b1, AKC_G };
|
359 |
|
|
8'h33: { amiga_new, amiga_keycode[6:0] } <= { 1'b1, AKC_H };
|
360 |
|
|
8'h3B: { amiga_new, amiga_keycode[6:0] } <= { 1'b1, AKC_J };
|
361 |
|
|
8'h42: { amiga_new, amiga_keycode[6:0] } <= { 1'b1, AKC_K };
|
362 |
|
|
8'h4B: { amiga_new, amiga_keycode[6:0] } <= { 1'b1, AKC_L };
|
363 |
|
|
8'h4C: { amiga_new, amiga_keycode[6:0] } <= { 1'b1, AKC_SEMIC };
|
364 |
|
|
8'h52: { amiga_new, amiga_keycode[6:0] } <= { 1'b1, AKC_SQUO };
|
365 |
|
|
8'h12: { amiga_new, amiga_keycode[6:0] } <= { 1'b1, AKC_LSHIFT };
|
366 |
|
|
8'h1A: { amiga_new, amiga_keycode[6:0] } <= { 1'b1, AKC_Z };
|
367 |
|
|
8'h22: { amiga_new, amiga_keycode[6:0] } <= { 1'b1, AKC_X };
|
368 |
|
|
8'h21: { amiga_new, amiga_keycode[6:0] } <= { 1'b1, AKC_C };
|
369 |
|
|
8'h2A: { amiga_new, amiga_keycode[6:0] } <= { 1'b1, AKC_V };
|
370 |
|
|
8'h32: { amiga_new, amiga_keycode[6:0] } <= { 1'b1, AKC_B };
|
371 |
|
|
8'h31: { amiga_new, amiga_keycode[6:0] } <= { 1'b1, AKC_N };
|
372 |
|
|
8'h3A: { amiga_new, amiga_keycode[6:0] } <= { 1'b1, AKC_M };
|
373 |
|
|
8'h41: { amiga_new, amiga_keycode[6:0] } <= { 1'b1, AKC_COMMA };
|
374 |
|
|
8'h49: { amiga_new, amiga_keycode[6:0] } <= { 1'b1, AKC_DOT };
|
375 |
|
|
8'h4A: { amiga_new, amiga_keycode[6:0] } <= { 1'b1, AKC_SLA };
|
376 |
|
|
8'h59: { amiga_new, amiga_keycode[6:0] } <= { 1'b1, AKC_RSHIFT };
|
377 |
|
|
8'h11: { amiga_new, amiga_keycode[6:0] } <= { 1'b1, AKC_LALT };
|
378 |
|
|
8'h7C: { amiga_new, amiga_keycode[6:0] } <= { 1'b1, AKC_NUM_MULT };
|
379 |
|
|
8'h6C: { amiga_new, amiga_keycode[6:0] } <= { 1'b1, AKC_NUM_7 };
|
380 |
|
|
8'h75: { amiga_new, amiga_keycode[6:0] } <= { 1'b1, AKC_NUM_8 };
|
381 |
|
|
8'h7D: { amiga_new, amiga_keycode[6:0] } <= { 1'b1, AKC_NUM_9 };
|
382 |
|
|
8'h7B: { amiga_new, amiga_keycode[6:0] } <= { 1'b1, AKC_NUM_MIN };
|
383 |
|
|
8'h6B: { amiga_new, amiga_keycode[6:0] } <= { 1'b1, AKC_NUM_4 };
|
384 |
|
|
8'h73: { amiga_new, amiga_keycode[6:0] } <= { 1'b1, AKC_NUM_5 };
|
385 |
|
|
8'h74: { amiga_new, amiga_keycode[6:0] } <= { 1'b1, AKC_NUM_6 };
|
386 |
|
|
8'h79: { amiga_new, amiga_keycode[6:0] } <= { 1'b1, AKC_NUM_PLUS };
|
387 |
|
|
8'h69: { amiga_new, amiga_keycode[6:0] } <= { 1'b1, AKC_NUM_1 };
|
388 |
|
|
8'h72: { amiga_new, amiga_keycode[6:0] } <= { 1'b1, AKC_NUM_2 };
|
389 |
|
|
8'h7A: { amiga_new, amiga_keycode[6:0] } <= { 1'b1, AKC_NUM_3 };
|
390 |
|
|
8'h29: { amiga_new, amiga_keycode[6:0] } <= { 1'b1, AKC_SPACE };
|
391 |
|
|
8'h70: { amiga_new, amiga_keycode[6:0] } <= { 1'b1, AKC_NUM_0 };
|
392 |
|
|
8'h71: { amiga_new, amiga_keycode[6:0] } <= { 1'b1, AKC_NUM_DOT };
|
393 |
|
|
default: begin
|
394 |
|
|
{ amiga_new, amiga_keycode[7] } <= 2'b00;
|
395 |
|
|
state <= S_FIRST;
|
396 |
|
|
end
|
397 |
|
|
endcase
|
398 |
|
|
end
|
399 |
|
|
end
|
400 |
|
|
else if(state == S_E0) begin
|
401 |
|
|
if(kbdat[8:1] == 8'hF0 && amiga_keycode[7] == 1'b0) begin
|
402 |
|
|
amiga_keycode[7] <= 1'b1;
|
403 |
|
|
end
|
404 |
|
|
else if(kbdat[8:1] == 8'h12 && amiga_keycode[7] == 1'b0) begin
|
405 |
|
|
state <= S_E0_12;
|
406 |
|
|
end
|
407 |
|
|
else if(kbdat[8:1] == 8'h7C && amiga_keycode[7] == 1'b1) begin
|
408 |
|
|
state <= S_E0_F0_7C;
|
409 |
|
|
end
|
410 |
|
|
else if( kbdat[8:1] == 8'h6C ||
|
411 |
|
|
(enable_joystick_1 == 1'b1 && (kbdat[8:1] == 8'h14 || kbdat[8:1] == 8'h75 || kbdat[8:1] == 8'h72 || kbdat[8:1] == 8'h6B || kbdat[8:1] == 8'h74)) )
|
412 |
|
|
begin
|
413 |
|
|
if(kbdat[8:1] == 8'h6C) request_osd <= ~amiga_keycode[7]; //home
|
414 |
|
|
if(kbdat[8:1] == 8'h14) joystick_1_fire <= ~amiga_keycode[7]; //right ctrl
|
415 |
|
|
if(kbdat[8:1] == 8'h75) joystick_1_up <= ~amiga_keycode[7]; //up
|
416 |
|
|
if(kbdat[8:1] == 8'h72) joystick_1_down <= ~amiga_keycode[7]; //down
|
417 |
|
|
if(kbdat[8:1] == 8'h6B) joystick_1_left <= ~amiga_keycode[7]; //left
|
418 |
|
|
if(kbdat[8:1] == 8'h74) joystick_1_right <= ~amiga_keycode[7]; //right
|
419 |
|
|
|
420 |
|
|
{ amiga_new, amiga_keycode[7] } <= 2'b00;
|
421 |
|
|
state <= S_FIRST;
|
422 |
|
|
end
|
423 |
|
|
else begin
|
424 |
|
|
case(kbdat[8:1])
|
425 |
|
|
8'h11: { amiga_new, amiga_keycode[6:0] } <= { 1'b1, AKC_RALT };
|
426 |
|
|
8'h5B: { amiga_new, amiga_keycode[6:0] } <= { 1'b1, AKC_LAMIGA }; //left Windows
|
427 |
|
|
8'h5C: { amiga_new, amiga_keycode[6:0] } <= { 1'b1, AKC_RAMIGA }; //right Windows
|
428 |
|
|
8'h71: { amiga_new, amiga_keycode[6:0] } <= { 1'b1, AKC_DEL };
|
429 |
|
|
8'h75: { amiga_new, amiga_keycode[6:0] } <= { 1'b1, AKC_UP };
|
430 |
|
|
8'h6B: { amiga_new, amiga_keycode[6:0] } <= { 1'b1, AKC_LEFT };
|
431 |
|
|
8'h72: { amiga_new, amiga_keycode[6:0] } <= { 1'b1, AKC_DOWN };
|
432 |
|
|
8'h74: { amiga_new, amiga_keycode[6:0] } <= { 1'b1, AKC_RIGHT };
|
433 |
|
|
8'h7D: { amiga_new, amiga_keycode[6:0] } <= { 1'b1, AKC_NUM_LBRA }; // pageUp
|
434 |
|
|
8'h7A: { amiga_new, amiga_keycode[6:0] } <= { 1'b1, AKC_NUM_RBRA }; // pageDown
|
435 |
|
|
8'h4A: { amiga_new, amiga_keycode[6:0] } <= { 1'b1, AKC_NUM_SLA };
|
436 |
|
|
8'h5A: { amiga_new, amiga_keycode[6:0] } <= { 1'b1, AKC_NUM_ENTER };
|
437 |
|
|
default: begin
|
438 |
|
|
{ amiga_new, amiga_keycode[7] } <= 2'b00;
|
439 |
|
|
state <= S_FIRST;
|
440 |
|
|
end
|
441 |
|
|
endcase
|
442 |
|
|
end
|
443 |
|
|
end
|
444 |
|
|
else if(state == S_E0_12) begin
|
445 |
|
|
if(kbdat[8:1] == 8'hE0) begin
|
446 |
|
|
state <= S_E0_12_E0;
|
447 |
|
|
end
|
448 |
|
|
else begin
|
449 |
|
|
{ amiga_new, amiga_keycode[7] } <= 2'b00;
|
450 |
|
|
state <= S_FIRST;
|
451 |
|
|
end
|
452 |
|
|
end
|
453 |
|
|
else if(state == S_E0_12_E0) begin
|
454 |
|
|
if(kbdat[8:1] == 8'h7C) begin
|
455 |
|
|
{ amiga_new, amiga_keycode[6:0] } <= { 1'b1, AKC_HELP }; // make PrintScreen
|
456 |
|
|
end
|
457 |
|
|
else begin
|
458 |
|
|
{ amiga_new, amiga_keycode[7] } <= 2'b00;
|
459 |
|
|
state <= S_FIRST;
|
460 |
|
|
end
|
461 |
|
|
end
|
462 |
|
|
|
463 |
|
|
else if(state == S_E0_F0_7C) begin
|
464 |
|
|
if(kbdat[8:1] == 8'hE0) begin
|
465 |
|
|
state <= S_E0_F0_7C_E0;
|
466 |
|
|
end
|
467 |
|
|
else begin
|
468 |
|
|
{ amiga_new, amiga_keycode[7] } <= 2'b00;
|
469 |
|
|
state <= S_FIRST;
|
470 |
|
|
end
|
471 |
|
|
end
|
472 |
|
|
else if(state == S_E0_F0_7C_E0) begin
|
473 |
|
|
if(kbdat[8:1] == 8'hF0) begin
|
474 |
|
|
state <= S_E0_F0_7C_E0_F0;
|
475 |
|
|
end
|
476 |
|
|
else begin
|
477 |
|
|
{ amiga_new, amiga_keycode[7] } <= 2'b00;
|
478 |
|
|
state <= S_FIRST;
|
479 |
|
|
end
|
480 |
|
|
end
|
481 |
|
|
else if(state == S_E0_F0_7C_E0_F0) begin
|
482 |
|
|
if(kbdat[8:1] == 8'h12) begin
|
483 |
|
|
{ amiga_new, amiga_keycode[6:0] } <= { 1'b1, AKC_HELP }; // break PrintScreen
|
484 |
|
|
end
|
485 |
|
|
else begin
|
486 |
|
|
{ amiga_new, amiga_keycode[7] } <= 2'b00;
|
487 |
|
|
state <= S_FIRST;
|
488 |
|
|
end
|
489 |
|
|
end
|
490 |
|
|
end
|
491 |
|
|
else if(amiga_new == 1'b1 && delay == 1'b0) begin
|
492 |
|
|
delay <= 1'b1;
|
493 |
|
|
state <= S_FIRST;
|
494 |
|
|
end
|
495 |
|
|
else if(amiga_new == 1'b1 && delay == 1'b1) begin
|
496 |
|
|
amiga_new <= 1'b0;
|
497 |
|
|
amiga_keycode <= 8'd0;
|
498 |
|
|
delay <= 1'b0;
|
499 |
|
|
|
500 |
|
|
if(pressed == 1'b0 || amiga_keycode[7] == 1'b1) begin
|
501 |
|
|
|
502 |
|
|
if(amiga_avail >= 4'd0 && amiga_avail <= 4'd11) amiga_avail <= amiga_avail + 4'd1;
|
503 |
|
|
|
504 |
|
|
case(amiga_avail)
|
505 |
|
|
4'd0: amiga_keycodes[95:88] <= amiga_keycode;
|
506 |
|
|
4'd1: amiga_keycodes[87:80] <= amiga_keycode;
|
507 |
|
|
4'd2: amiga_keycodes[79:72] <= amiga_keycode;
|
508 |
|
|
4'd3: amiga_keycodes[71:64] <= amiga_keycode;
|
509 |
|
|
4'd4: amiga_keycodes[63:56] <= amiga_keycode;
|
510 |
|
|
4'd5: amiga_keycodes[55:48] <= amiga_keycode;
|
511 |
|
|
4'd6: amiga_keycodes[47:40] <= amiga_keycode;
|
512 |
|
|
4'd7: amiga_keycodes[39:32] <= amiga_keycode;
|
513 |
|
|
4'd8: amiga_keycodes[31:24] <= amiga_keycode;
|
514 |
|
|
4'd9: amiga_keycodes[23:16] <= amiga_keycode;
|
515 |
|
|
4'd10: amiga_keycodes[15:8] <= amiga_keycode;
|
516 |
|
|
4'd11: amiga_keycodes[7:0] <= 8'hFA;
|
517 |
|
|
endcase
|
518 |
|
|
end
|
519 |
|
|
end
|
520 |
|
|
else if(keyboard_ready == 1'b1 && amiga_avail > 4'd0) begin
|
521 |
|
|
amiga_avail <= amiga_avail - 4'd1;
|
522 |
|
|
amiga_keycodes <= { amiga_keycodes[87:0], 8'd0 };
|
523 |
|
|
end
|
524 |
|
|
end
|
525 |
|
|
end
|
526 |
|
|
|
527 |
|
|
parameter [6:0]
|
528 |
|
|
AKC_ESC = 7'h45,
|
529 |
|
|
AKC_F1 = 7'h50,
|
530 |
|
|
AKC_F2 = 7'h51,
|
531 |
|
|
AKC_F3 = 7'h52,
|
532 |
|
|
AKC_F4 = 7'h53,
|
533 |
|
|
AKC_F5 = 7'h54,
|
534 |
|
|
AKC_F6 = 7'h55,
|
535 |
|
|
AKC_F7 = 7'h56,
|
536 |
|
|
AKC_F8 = 7'h57,
|
537 |
|
|
AKC_F9 = 7'h58,
|
538 |
|
|
AKC_F10 = 7'h59,
|
539 |
|
|
AKC_APO = 7'h00, //`
|
540 |
|
|
AKC_BACK = 7'h41,
|
541 |
|
|
AKC_1 = 7'h01,
|
542 |
|
|
AKC_2 = 7'h02,
|
543 |
|
|
AKC_3 = 7'h03,
|
544 |
|
|
AKC_4 = 7'h04,
|
545 |
|
|
AKC_5 = 7'h05,
|
546 |
|
|
AKC_6 = 7'h06,
|
547 |
|
|
AKC_7 = 7'h07,
|
548 |
|
|
AKC_8 = 7'h08,
|
549 |
|
|
AKC_9 = 7'h09,
|
550 |
|
|
AKC_0 = 7'h0A,
|
551 |
|
|
AKC_MIN = 7'h0B, //-
|
552 |
|
|
AKC_EQL = 7'h0C, //=
|
553 |
|
|
AKC_BSLA = 7'h0D, //\\
|
554 |
|
|
AKC_TAB = 7'h42,
|
555 |
|
|
AKC_Q = 7'h10,
|
556 |
|
|
AKC_W = 7'h11,
|
557 |
|
|
AKC_E = 7'h12,
|
558 |
|
|
AKC_R = 7'h13,
|
559 |
|
|
AKC_T = 7'h14,
|
560 |
|
|
AKC_Y = 7'h15,
|
561 |
|
|
AKC_U = 7'h16,
|
562 |
|
|
AKC_I = 7'h17,
|
563 |
|
|
AKC_O = 7'h18,
|
564 |
|
|
AKC_P = 7'h19,
|
565 |
|
|
AKC_SBRAL = 7'h1A, //[
|
566 |
|
|
AKC_SBRAR = 7'h1B, //]
|
567 |
|
|
AKC_ENTER = 7'h44,
|
568 |
|
|
AKC_CTRL = 7'h63,
|
569 |
|
|
AKC_CAPS = 7'h62,
|
570 |
|
|
AKC_A = 7'h20,
|
571 |
|
|
AKC_S = 7'h21,
|
572 |
|
|
AKC_D = 7'h22,
|
573 |
|
|
AKC_F = 7'h23,
|
574 |
|
|
AKC_G = 7'h24,
|
575 |
|
|
AKC_H = 7'h25,
|
576 |
|
|
AKC_J = 7'h26,
|
577 |
|
|
AKC_K = 7'h27,
|
578 |
|
|
AKC_L = 7'h28,
|
579 |
|
|
AKC_SEMIC = 7'h29, //;
|
580 |
|
|
AKC_SQUO = 7'h2A, //'
|
581 |
|
|
AKC_LSHIFT = 7'h60,
|
582 |
|
|
AKC_Z = 7'h31,
|
583 |
|
|
AKC_X = 7'h32,
|
584 |
|
|
AKC_C = 7'h33,
|
585 |
|
|
AKC_V = 7'h34,
|
586 |
|
|
AKC_B = 7'h35,
|
587 |
|
|
AKC_N = 7'h36,
|
588 |
|
|
AKC_M = 7'h37,
|
589 |
|
|
AKC_COMMA = 7'h38, //,
|
590 |
|
|
AKC_DOT = 7'h39, //.
|
591 |
|
|
AKC_SLA = 7'h3A, ///
|
592 |
|
|
AKC_RSHIFT = 7'h61,
|
593 |
|
|
AKC_LALT = 7'h64,
|
594 |
|
|
AKC_LAMIGA = 7'h66,
|
595 |
|
|
AKC_SPACE = 7'h40,
|
596 |
|
|
AKC_RAMIGA = 7'h67,
|
597 |
|
|
AKC_RALT = 7'h65,
|
598 |
|
|
AKC_DEL = 7'h46,
|
599 |
|
|
AKC_HELP = 7'h5F,
|
600 |
|
|
AKC_UP = 7'h4C,
|
601 |
|
|
AKC_LEFT = 7'h4F,
|
602 |
|
|
AKC_DOWN = 7'h4D,
|
603 |
|
|
AKC_RIGHT = 7'h4E,
|
604 |
|
|
AKC_NUM_LBRA = 7'h5A, //(
|
605 |
|
|
AKC_NUM_RBRA = 7'h5B, //)
|
606 |
|
|
AKC_NUM_SLA = 7'h5C, ///
|
607 |
|
|
AKC_NUM_MULT = 7'h5D, //*
|
608 |
|
|
AKC_NUM_7 = 7'h3D,
|
609 |
|
|
AKC_NUM_8 = 7'h3E,
|
610 |
|
|
AKC_NUM_9 = 7'h3F,
|
611 |
|
|
AKC_NUM_MIN = 7'h4A, //-
|
612 |
|
|
AKC_NUM_4 = 7'h4D,
|
613 |
|
|
AKC_NUM_5 = 7'h4E,
|
614 |
|
|
AKC_NUM_6 = 7'h4F,
|
615 |
|
|
AKC_NUM_PLUS = 7'h5E, //+
|
616 |
|
|
AKC_NUM_1 = 7'h1D,
|
617 |
|
|
AKC_NUM_2 = 7'h1E,
|
618 |
|
|
AKC_NUM_3 = 7'h1F,
|
619 |
|
|
AKC_NUM_ENTER = 7'h43,
|
620 |
|
|
AKC_NUM_0 = 7'h0F,
|
621 |
|
|
AKC_NUM_DOT = 7'h3C; //.
|
622 |
|
|
|
623 |
|
|
endmodule
|