static void write_p64(Bitu port,Bitu val,Bitu iolen) { if (keyb.reset) return; switch (val) { case 0x20: /* read command byte */ /* TODO: If biosps2=true and aux=false, mask AUX port bits as if AUX isn't there */ KEYBOARD_Add8042Response( (keyb.cb_xlat << 6) | ((!keyb.auxactive) << 5) | ((!keyb.active) << 4) | (keyb.cb_sys << 2) | (keyb.cb_irq12 << 1) | (keyb.cb_irq1?1:0)); break; case 0x60: keyb.command=CMD_SETCOMMAND; break; case 0x90: case 0x91: case 0x92: case 0x93: case 0x94: case 0x95: case 0x96: case 0x97: case 0x98: case 0x99: case 0x9a: case 0x9b: case 0x9c: case 0x9d: case 0x9e: case 0x9f: /* TODO: If bit 0 == 0, trigger system reset */ break; case 0xa7: /* disable aux */ /* TODO: If biosps2=true and aux=false do not respond */ if (keyb.enable_aux) { //keyb.auxactive=false; //LOG(LOG_KEYBOARD,LOG_NORMAL)("AUX De-Activated"); } break; case 0xa8: /* enable aux */ /* TODO: If biosps2=true and aux=false do not respond */ if (keyb.enable_aux) { keyb.auxactive=true; if (keyb.used && !keyb.scheduled && !keyb.p60changed) { keyb.scheduled=true; PIC_AddEvent(KEYBOARD_TransferBuffer,KEYDELAY); } LOG(LOG_KEYBOARD,LOG_NORMAL)("AUX Activated"); } break; case 0xa9: /* mouse interface test */ /* TODO: If biosps2=true and aux=false do not respond */ KEYBOARD_Add8042Response(0x00); /* OK */ break; case 0xaa: /* Self test */ keyb.active=false; /* on real h/w it also seems to disable the keyboard */ KEYBOARD_Add8042Response(0xaa); /* OK */ break; case 0xab: /* interface test */ keyb.active=false; /* on real h/w it also seems to disable the keyboard */ KEYBOARD_Add8042Response(0x00); /* no error */ break; case 0xae: /* Activate keyboard */ keyb.active=true; if (keyb.used && !keyb.scheduled && !keyb.p60changed) { keyb.scheduled=true; PIC_AddEvent(KEYBOARD_TransferBuffer,KEYDELAY); } LOG(LOG_KEYBOARD,LOG_NORMAL)("Activated"); break; case 0xad: /* Deactivate keyboard */ keyb.active=false; LOG(LOG_KEYBOARD,LOG_NORMAL)("De-Activated"); break; case 0xc0: /* read input buffer */ KEYBOARD_Add8042Response(0x40); break; case 0xd0: /* Outport on buffer */ KEYBOARD_SetPort60((MEM_A20_Enabled() ? 0x02 : 0) | 0x01/*some programs read the output port then write it back*/); break; case 0xd1: /* Write to outport */ keyb.command=CMD_SETOUTPORT; break; case 0xd2: /* write output register */ keyb.command=CMD_WRITEOUTPUT; break; case 0xd3: /* write AUX output */ if (keyb.enable_aux) keyb.command=CMD_WRITEAUXOUT; else if (aux_warning++ == 0) LOG(LOG_KEYBOARD,LOG_ERROR)("Program is writing 8042 AUX. If you intend to use PS/2 mouse emulation you may consider adding aux=1 to your dosbox.conf"); break; case 0xd4: /* send byte to AUX */ if (keyb.enable_aux) keyb.command=CMD_WRITEAUX; else if (aux_warning++ == 0) LOG(LOG_KEYBOARD,LOG_ERROR)("Program is writing 8042 AUX. If you intend to use PS/2 mouse emulation you may consider adding aux=1 to your dosbox.conf"); break; case 0xe0: /* read test port */ KEYBOARD_Add8042Response(0x00); break; case 0xf0: case 0xf1: case 0xf2: case 0xf3: case 0xf4: case 0xf5: case 0xf6: case 0xf7: case 0xf8: case 0xf9: case 0xfa: case 0xfb: case 0xfc: case 0xfd: case 0xfe: case 0xff: /* pulse output register */ if (!(val & 1)) { if (allow_keyb_reset) { LOG_MSG("Restart by keyboard controller requested\n"); On_Software_CPU_Reset(); } else { LOG_MSG("WARNING: Keyboard output port written (pulsed) with bit 1 clear. Is the guest OS or application attempting to reset the system?\n"); } } break; default: LOG(LOG_KEYBOARD,LOG_ERROR)("Port 64 write with val %d",(int)val); break; } }
static void KEYBOARD_ResetDelay(Bitu val) { keyb.reset=false; KEYBOARD_SetLEDs(0); KEYBOARD_Add8042Response(0x00); /* BAT */ }
static void write_p60(Bitu port,Bitu val,Bitu iolen) { switch (keyb.command) { case CMD_NONE: /* None */ if (keyb.reset) return; /* No active command this would normally get sent to the keyboard then */ KEYBOARD_ClrBuffer(); switch (val) { case 0xed: /* Set Leds */ keyb.command=CMD_SETLEDS; KEYBOARD_AddBuffer(0xfa); /* Acknowledge */ break; case 0xee: /* Echo */ KEYBOARD_AddBuffer(0xee); /* JC: The correct response is 0xEE, not 0xFA */ break; case 0xf0: /* set scancode set */ keyb.command=CMD_SETSCANSET; KEYBOARD_AddBuffer(0xfa); /* Acknowledge */ break; case 0xf2: /* Identify keyboard */ KEYBOARD_AddBuffer(0xfa); /* Acknowledge */ KEYBOARD_AddBuffer(0xab); /* ID */ KEYBOARD_AddBuffer(0x83); break; case 0xf3: /* Typematic rate programming */ keyb.command=CMD_SETTYPERATE; KEYBOARD_AddBuffer(0xfa); /* Acknowledge */ break; case 0xf4: /* Enable keyboard,clear buffer, start scanning */ LOG(LOG_KEYBOARD,LOG_NORMAL)("Clear buffer, enable scanning"); KEYBOARD_AddBuffer(0xfa); /* Acknowledge */ keyb.scanning=true; break; case 0xf5: /* Reset keyboard and disable scanning */ LOG(LOG_KEYBOARD,LOG_NORMAL)("Reset, disable scanning"); keyb.scanning=false; KEYBOARD_AddBuffer(0xfa); /* Acknowledge */ break; case 0xf6: /* Reset keyboard and enable scanning */ LOG(LOG_KEYBOARD,LOG_NORMAL)("Reset, enable scanning"); keyb.scanning=true; /* JC: Original DOSBox code was wrong, this command enables scanning */ KEYBOARD_AddBuffer(0xfa); /* Acknowledge */ break; case 0xff: /* keyboard resets take a long time (about 250ms), most keyboards flash the LEDs during reset */ KEYBOARD_Reset(); KEYBOARD_Add8042Response(0xFA); /* ACK */ KEYBOARD_Add8042Response(0xAA); /* SELF TEST OK (TODO: Need delay!) */ keyb.reset=true; KEYBOARD_SetLEDs(7); /* most keyboard I test with tend to flash the LEDs during reset */ PIC_AddEvent(KEYBOARD_ResetDelay,RESETDELAY); break; default: /* Just always acknowledge strange commands */ LOG(LOG_KEYBOARD,LOG_ERROR)("60:Unhandled command %X",(int)val); KEYBOARD_AddBuffer(0xfa); /* Acknowledge */ } return; case CMD_SETSCANSET: keyb.command=CMD_NONE; if (val == 0) { /* just asking */ if (keyb.cb_xlat) { switch (keyb.scanset) { case 1: KEYBOARD_AddBuffer(0x43); break; case 2: KEYBOARD_AddBuffer(0x41); break; case 3: KEYBOARD_AddBuffer(0x3F); break; } } else { KEYBOARD_AddBuffer(keyb.scanset); } KEYBOARD_AddBuffer(0xfa); /* Acknowledge */ } else { KEYBOARD_AddBuffer(0xfa); /* Acknowledge */ KEYBOARD_AddBuffer(0xfa); /* Acknowledge again */ if (val > 3) val = 3; keyb.scanset = val; } break; case CMD_WRITEAUX: keyb.command=CMD_NONE; KEYBOARD_AUX_Write(val); break; case CMD_WRITEOUTPUT: keyb.command=CMD_NONE; KEYBOARD_ClrBuffer(); KEYBOARD_AddBuffer(val); /* and now you return the byte as if it were typed in */ break; case CMD_WRITEAUXOUT: KEYBOARD_AddBuffer(AUX|val); /* stuff into AUX output */ break; case CMD_SETOUTPORT: if (!(val & 1)) { if (allow_keyb_reset) { LOG_MSG("Restart by keyboard controller requested\n"); On_Software_CPU_Reset(); } else { LOG_MSG("WARNING: Keyboard output port written with bit 1 clear. Is the guest OS or application attempting to reset the system?\n"); } } MEM_A20_Enable((val & 2)>0); keyb.command = CMD_NONE; break; case CMD_SETTYPERATE: if (keyb.reset) return; { static const int delay[] = { 250, 500, 750, 1000 }; static const int repeat[] = { 33,37,42,46,50,54,58,63,67,75,83,92,100, 109,118,125,133,149,167,182,200,217,233, 250,270,303,333,370,400,435,476,500 }; keyb.repeat.pause = delay[(val >> 5) & 3]; keyb.repeat.rate = repeat[val & 0x1f]; keyb.command = CMD_NONE; KEYBOARD_ClrBuffer(); KEYBOARD_AddBuffer(0xfa); /* Acknowledge */ } break; case CMD_SETLEDS: if (keyb.reset) return; keyb.command=CMD_NONE; KEYBOARD_ClrBuffer(); KEYBOARD_AddBuffer(0xfa); /* Acknowledge */ KEYBOARD_SetLEDs(val&7); break; case CMD_SETCOMMAND: /* 8042 command, not keyboard */ /* TODO: If biosps2=true and aux=false, disallow the guest OS from changing AUX port parameters including IRQ */ keyb.command=CMD_NONE; keyb.cb_xlat = (val >> 6) & 1; keyb.auxactive = !((val >> 5) & 1); keyb.active = !((val >> 4) & 1); keyb.cb_sys = (val >> 2) & 1; keyb.cb_irq12 = (val >> 1) & 1; keyb.cb_irq1 = (val >> 0) & 1; if (keyb.used && !keyb.scheduled && !keyb.p60changed && keyb.active) { keyb.scheduled=true; PIC_AddEvent(KEYBOARD_TransferBuffer,KEYDELAY); } break; } }