Keyboard code cleanup
- BX_CPU_LEVEL < 3 doesn't exist in Bochs - verbose debug output removed - tab2space and minor coding style changes
This commit is contained in:
parent
a208a86aa0
commit
98545762b6
@ -53,8 +53,6 @@
|
||||
#include "scancodes.h"
|
||||
|
||||
#define LOG_THIS theKeyboard->
|
||||
#define VERBOSE_KBD_DEBUG 0
|
||||
|
||||
|
||||
bx_keyb_c *theKeyboard = NULL;
|
||||
|
||||
@ -67,7 +65,7 @@ int libkeyboard_LTX_plugin_init(plugin_t *plugin, plugintype_t type, int argc, c
|
||||
bx_devices.pluginKeyboard = theKeyboard;
|
||||
// Register this device.
|
||||
BX_REGISTER_DEVICE_DEVMODEL(plugin, type, theKeyboard, BX_PLUGIN_KEYBOARD);
|
||||
return(0); // Success
|
||||
return 0; // Success
|
||||
}
|
||||
|
||||
void libkeyboard_LTX_plugin_fini(void)
|
||||
@ -382,8 +380,7 @@ Bit32u bx_keyb_c::read(Bit32u address, unsigned io_len)
|
||||
activate_timer();
|
||||
BX_DEBUG(("[mouse] read from 0x%02x returns 0x%02x", address, val));
|
||||
return val;
|
||||
}
|
||||
else if (BX_KEY_THIS s.kbd_controller.outb) { /* kbd byte available */
|
||||
} else if (BX_KEY_THIS s.kbd_controller.outb) { /* kbd byte available */
|
||||
val = BX_KEY_THIS s.kbd_controller.kbd_output_buffer;
|
||||
BX_KEY_THIS s.kbd_controller.outb = 0;
|
||||
BX_KEY_THIS s.kbd_controller.auxb = 0;
|
||||
@ -401,7 +398,7 @@ Bit32u bx_keyb_c::read(Bit32u address, unsigned io_len)
|
||||
// move Q elements towards head of queue by one
|
||||
BX_KEY_THIS s.controller_Q[i] = BX_KEY_THIS s.controller_Q[i+1];
|
||||
}
|
||||
BX_DEBUG(("s.controller_Qsize: %02X",BX_KEY_THIS s.controller_Qsize));
|
||||
BX_DEBUG(("s.controller_Qsize: %02X",BX_KEY_THIS s.controller_Qsize));
|
||||
BX_KEY_THIS s.controller_Qsize--;
|
||||
}
|
||||
|
||||
@ -409,16 +406,12 @@ Bit32u bx_keyb_c::read(Bit32u address, unsigned io_len)
|
||||
activate_timer();
|
||||
BX_DEBUG(("READ(%02x) = %02x", (unsigned) address, (unsigned) val));
|
||||
return val;
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
BX_DEBUG(("num_elements = %d", BX_KEY_THIS s.kbd_internal_buffer.num_elements));
|
||||
BX_DEBUG(("read from port 60h with outb empty"));
|
||||
return BX_KEY_THIS s.kbd_controller.kbd_output_buffer;
|
||||
}
|
||||
}
|
||||
|
||||
#if BX_CPU_LEVEL >= 2
|
||||
else if (address == 0x64) { /* status register */
|
||||
} else if (address == 0x64) { /* status register */
|
||||
val = (BX_KEY_THIS s.kbd_controller.pare << 7) |
|
||||
(BX_KEY_THIS s.kbd_controller.tim << 6) |
|
||||
(BX_KEY_THIS s.kbd_controller.auxb << 5) |
|
||||
@ -431,14 +424,6 @@ Bit32u bx_keyb_c::read(Bit32u address, unsigned io_len)
|
||||
return val;
|
||||
}
|
||||
|
||||
#else /* BX_CPU_LEVEL > 0 */
|
||||
/* XT MODE, System 8255 Mode Register */
|
||||
else if (address == 0x64) { /* status register */
|
||||
BX_DEBUG(("IO read from port 64h, system 8255 mode register"));
|
||||
return BX_KEY_THIS s.kbd_controller.outb;
|
||||
}
|
||||
#endif /* BX_CPU_LEVEL > 0 */
|
||||
|
||||
BX_PANIC(("unknown address in io read to keyboard port %x",
|
||||
(unsigned) address));
|
||||
return 0; /* keep compiler happy */
|
||||
@ -498,8 +483,8 @@ void bx_keyb_c::write(Bit32u address, Bit32u value, unsigned io_len)
|
||||
if (!scan_convert)
|
||||
BX_INFO(("keyboard: scan convert turned off"));
|
||||
|
||||
// (mch) NT needs this
|
||||
BX_KEY_THIS s.kbd_controller.scancodes_translate = scan_convert;
|
||||
// (mch) NT needs this
|
||||
BX_KEY_THIS s.kbd_controller.scancodes_translate = scan_convert;
|
||||
}
|
||||
break;
|
||||
case 0xcb: // write keyboard controller mode
|
||||
@ -507,7 +492,7 @@ void bx_keyb_c::write(Bit32u address, Bit32u value, unsigned io_len)
|
||||
break;
|
||||
case 0xd1: // write output port
|
||||
BX_DEBUG(("write output port with value %02xh", (unsigned) value));
|
||||
BX_DEBUG(("write output port : %sable A20",(value & 0x02)?"en":"dis"));
|
||||
BX_DEBUG(("write output port : %sable A20",(value & 0x02)?"en":"dis"));
|
||||
BX_SET_ENABLE_A20((value & 0x02) != 0);
|
||||
if (!(value & 0x01)) {
|
||||
BX_INFO(("write output port : processor reset requested!"));
|
||||
@ -526,10 +511,10 @@ void bx_keyb_c::write(Bit32u address, Bit32u value, unsigned io_len)
|
||||
controller_enQ(value, 1);
|
||||
break;
|
||||
|
||||
case 0xd2:
|
||||
// Queue in keyboard output buffer
|
||||
controller_enQ(value, 0);
|
||||
break;
|
||||
case 0xd2:
|
||||
// Queue in keyboard output buffer
|
||||
controller_enQ(value, 0);
|
||||
break;
|
||||
|
||||
default:
|
||||
BX_PANIC(("=== unsupported write to port 60h(lastcomm=%02x): %02x",
|
||||
@ -605,17 +590,17 @@ void bx_keyb_c::write(Bit32u address, Bit32u value, unsigned io_len)
|
||||
break;
|
||||
case 0xaa: // motherboard controller self test
|
||||
BX_DEBUG(("Self Test"));
|
||||
if (kbd_initialized == 0) {
|
||||
BX_KEY_THIS s.controller_Qsize = 0;
|
||||
BX_KEY_THIS s.kbd_controller.outb = 0;
|
||||
kbd_initialized++;
|
||||
}
|
||||
if (kbd_initialized == 0) {
|
||||
BX_KEY_THIS s.controller_Qsize = 0;
|
||||
BX_KEY_THIS s.kbd_controller.outb = 0;
|
||||
kbd_initialized++;
|
||||
}
|
||||
// controller output buffer must be empty
|
||||
if (BX_KEY_THIS s.kbd_controller.outb) {
|
||||
BX_ERROR(("kbd: OUTB set and command 0x%02x encountered", value));
|
||||
break;
|
||||
}
|
||||
// (mch) Why is this commented out??? Enabling
|
||||
// (mch) Why is this commented out??? Enabling
|
||||
BX_KEY_THIS s.kbd_controller.sysf = 1; // self test complete
|
||||
controller_enQ(0x55, 0); // controller OK
|
||||
break;
|
||||
@ -676,9 +661,9 @@ void bx_keyb_c::write(Bit32u address, Bit32u value, unsigned io_len)
|
||||
break;
|
||||
|
||||
case 0xd3: // write mouse output buffer
|
||||
//FIXME: Why was this a panic?
|
||||
//FIXME: Why was this a panic?
|
||||
BX_DEBUG(("io write 0x64: command = 0xD3(write mouse outb)"));
|
||||
// following byte to port 60h written to output port as mouse write.
|
||||
// following byte to port 60h written to output port as mouse write.
|
||||
BX_KEY_THIS s.kbd_controller.expecting_port60h = 1;
|
||||
break;
|
||||
|
||||
@ -689,15 +674,15 @@ void bx_keyb_c::write(Bit32u address, Bit32u value, unsigned io_len)
|
||||
break;
|
||||
|
||||
case 0xd2: // write keyboard output buffer
|
||||
BX_DEBUG(("io write 0x64: write keyboard output buffer"));
|
||||
BX_KEY_THIS s.kbd_controller.expecting_port60h = 1;
|
||||
break;
|
||||
BX_DEBUG(("io write 0x64: write keyboard output buffer"));
|
||||
BX_KEY_THIS s.kbd_controller.expecting_port60h = 1;
|
||||
break;
|
||||
case 0xdd: // Disable A20 Address Line
|
||||
BX_SET_ENABLE_A20(0);
|
||||
break;
|
||||
BX_SET_ENABLE_A20(0);
|
||||
break;
|
||||
case 0xdf: // Enable A20 Address Line
|
||||
BX_SET_ENABLE_A20(1);
|
||||
break;
|
||||
BX_SET_ENABLE_A20(1);
|
||||
break;
|
||||
case 0xc1: // Continuous Input Port Poll, Low
|
||||
case 0xc2: // Continuous Input Port Poll, High
|
||||
case 0xe0: // Read Test Inputs
|
||||
@ -829,13 +814,12 @@ void bx_keyb_c::gen_scancode(Bit32u key)
|
||||
if (scancode[i] == 0xF0)
|
||||
escaped=0x80;
|
||||
else {
|
||||
BX_DEBUG(("gen_scancode(): writing translated %02x",translation8042[scancode[i] ] | escaped));
|
||||
BX_DEBUG(("gen_scancode(): writing translated %02x",translation8042[scancode[i] ] | escaped));
|
||||
kbd_enQ(translation8042[scancode[i]] | escaped);
|
||||
escaped=0x00;
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
// Send raw data
|
||||
for (i=0; i<strlen((const char *)scancode); i++) {
|
||||
BX_DEBUG(("gen_scancode(): writing raw %02x",scancode[i]));
|
||||
@ -863,7 +847,7 @@ bx_keyb_c::set_kbd_clock_enable(Bit8u value)
|
||||
}
|
||||
}
|
||||
|
||||
void bx_keyb_c::set_aux_clock_enable(Bit8u value)
|
||||
void bx_keyb_c::set_aux_clock_enable(Bit8u value)
|
||||
{
|
||||
bx_bool prev_aux_clock_enabled;
|
||||
|
||||
@ -1230,15 +1214,15 @@ unsigned bx_keyb_c::periodic(Bit32u usec_delta)
|
||||
if (BX_KEY_THIS s.kbd_controller.aux_clock_enabled && BX_KEY_THIS s.mouse_internal_buffer.num_elements) {
|
||||
BX_DEBUG(("service_keyboard: key(from mouse) in internal buffer waiting"));
|
||||
BX_KEY_THIS s.kbd_controller.aux_output_buffer =
|
||||
BX_KEY_THIS s.mouse_internal_buffer.buffer[BX_KEY_THIS s.mouse_internal_buffer.head];
|
||||
BX_KEY_THIS s.mouse_internal_buffer.buffer[BX_KEY_THIS s.mouse_internal_buffer.head];
|
||||
|
||||
BX_KEY_THIS s.kbd_controller.outb = 1;
|
||||
BX_KEY_THIS s.kbd_controller.auxb = 1;
|
||||
BX_KEY_THIS s.mouse_internal_buffer.head = (BX_KEY_THIS s.mouse_internal_buffer.head + 1) %
|
||||
BX_MOUSE_BUFF_SIZE;
|
||||
BX_MOUSE_BUFF_SIZE;
|
||||
BX_KEY_THIS s.mouse_internal_buffer.num_elements--;
|
||||
if (BX_KEY_THIS s.kbd_controller.allow_irq12)
|
||||
BX_KEY_THIS s.kbd_controller.irq12_requested = 1;
|
||||
BX_KEY_THIS s.kbd_controller.irq12_requested = 1;
|
||||
} else {
|
||||
BX_DEBUG(("service_keyboard(): no keys waiting"));
|
||||
}
|
||||
@ -1488,38 +1472,35 @@ void bx_keyb_c::create_mouse_packet(bx_bool force_enq)
|
||||
{
|
||||
Bit8u b1, b2, b3, b4;
|
||||
|
||||
if(BX_KEY_THIS s.mouse_internal_buffer.num_elements && !force_enq)
|
||||
if (BX_KEY_THIS s.mouse_internal_buffer.num_elements && !force_enq)
|
||||
return;
|
||||
|
||||
Bit16s delta_x = BX_KEY_THIS s.mouse.delayed_dx;
|
||||
Bit16s delta_y = BX_KEY_THIS s.mouse.delayed_dy;
|
||||
Bit8u button_state=BX_KEY_THIS s.mouse.button_status | 0x08;
|
||||
|
||||
if(!force_enq && !delta_x && !delta_y) {
|
||||
if (!force_enq && !delta_x && !delta_y) {
|
||||
return;
|
||||
}
|
||||
|
||||
if(delta_x>254) delta_x=254;
|
||||
if(delta_x<-254) delta_x=-254;
|
||||
if(delta_y>254) delta_y=254;
|
||||
if(delta_y<-254) delta_y=-254;
|
||||
if (delta_x>254) delta_x=254;
|
||||
if (delta_x<-254) delta_x=-254;
|
||||
if (delta_y>254) delta_y=254;
|
||||
if (delta_y<-254) delta_y=-254;
|
||||
|
||||
b1 = (button_state & 0x0f) | 0x08; // bit3 always set
|
||||
|
||||
if ((delta_x>=0) && (delta_x<=255)) {
|
||||
b2 = (Bit8u) delta_x;
|
||||
BX_KEY_THIS s.mouse.delayed_dx-=delta_x;
|
||||
}
|
||||
else if (delta_x > 255) {
|
||||
} else if (delta_x > 255) {
|
||||
b2 = (Bit8u) 0xff;
|
||||
BX_KEY_THIS s.mouse.delayed_dx-=255;
|
||||
}
|
||||
else if (delta_x >= -256) {
|
||||
} else if (delta_x >= -256) {
|
||||
b2 = (Bit8u) delta_x;
|
||||
b1 |= 0x10;
|
||||
BX_KEY_THIS s.mouse.delayed_dx-=delta_x;
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
b2 = (Bit8u) 0x00;
|
||||
b1 |= 0x10;
|
||||
BX_KEY_THIS s.mouse.delayed_dx+=256;
|
||||
@ -1528,17 +1509,14 @@ void bx_keyb_c::create_mouse_packet(bx_bool force_enq)
|
||||
if ((delta_y>=0) && (delta_y<=255)) {
|
||||
b3 = (Bit8u) delta_y;
|
||||
BX_KEY_THIS s.mouse.delayed_dy-=delta_y;
|
||||
}
|
||||
else if (delta_y > 255) {
|
||||
} else if (delta_y > 255) {
|
||||
b3 = (Bit8u) 0xff;
|
||||
BX_KEY_THIS s.mouse.delayed_dy-=255;
|
||||
}
|
||||
else if (delta_y >= -256) {
|
||||
} else if (delta_y >= -256) {
|
||||
b3 = (Bit8u) delta_y;
|
||||
b1 |= 0x20;
|
||||
BX_KEY_THIS s.mouse.delayed_dy-=delta_y;
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
b3 = (Bit8u) 0x00;
|
||||
b1 |= 0x20;
|
||||
BX_KEY_THIS s.mouse.delayed_dy+=256;
|
||||
@ -1595,11 +1573,6 @@ void bx_keyb_c::mouse_motion(int delta_x, int delta_y, int delta_z, unsigned but
|
||||
if (!BX_KEY_THIS s.mouse.im_mode)
|
||||
delta_z = 0;
|
||||
|
||||
#ifdef VERBOSE_KBD_DEBUG
|
||||
if (delta_x != 0 || delta_y != 0 || delta_z != 0)
|
||||
BX_DEBUG(("[mouse] Dx=%d Dy=%d Dz=%d", delta_x, delta_y, delta_z));
|
||||
#endif /* ifdef VERBOSE_KBD_DEBUG */
|
||||
|
||||
if ((delta_x==0) && (delta_y==0) && (delta_z==0) && (BX_KEY_THIS s.mouse.button_status == (button_state & 0x7))) {
|
||||
BX_DEBUG(("Ignoring useless mouse_motion call:"));
|
||||
BX_DEBUG(("This should be fixed in the gui code."));
|
||||
@ -1612,16 +1585,16 @@ void bx_keyb_c::mouse_motion(int delta_x, int delta_y, int delta_z, unsigned but
|
||||
|
||||
BX_KEY_THIS s.mouse.button_status = button_state & 0x7;
|
||||
|
||||
if(delta_x>255) delta_x=255;
|
||||
if(delta_y>255) delta_y=255;
|
||||
if(delta_x<-256) delta_x=-256;
|
||||
if(delta_y<-256) delta_y=-256;
|
||||
if (delta_x>255) delta_x=255;
|
||||
if (delta_y>255) delta_y=255;
|
||||
if (delta_x<-256) delta_x=-256;
|
||||
if (delta_y<-256) delta_y=-256;
|
||||
|
||||
BX_KEY_THIS s.mouse.delayed_dx+=delta_x;
|
||||
BX_KEY_THIS s.mouse.delayed_dy+=delta_y;
|
||||
BX_KEY_THIS s.mouse.delayed_dz = delta_z;
|
||||
|
||||
if((BX_KEY_THIS s.mouse.delayed_dx>255)||
|
||||
if ((BX_KEY_THIS s.mouse.delayed_dx>255)||
|
||||
(BX_KEY_THIS s.mouse.delayed_dx<-256)||
|
||||
(BX_KEY_THIS s.mouse.delayed_dy>255)||
|
||||
(BX_KEY_THIS s.mouse.delayed_dy<-256)) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user