📄 ps2p465.cpp
字号:
/*
Copyright(c) 1998,1999 SIC/Hitachi,Ltd.
Copyright(c) 1998,1999 3RD Rail Engineering.
Module Name:
ps2p465.cpp
Revision History:
26th April 1999 Released
16th June 1999 Revised
1999-Oct-19 cea Change "magic" number delay to call to BusyWait
in DRVLIB.LIB. This is a CPU clock frequency
dependent wait function.
*/
#include <windows.h>
#include <ceddk.h>
//#include "mobytel.h"
#include <pkfuncs.h>
#include "cc.h"
#include "ps2p465.hpp"
#include "dbgzones.hpp"
/* Wait before timing out a write to the HD64465.*/
#define WRITE_TIMEOUT (50000)
static unsigned int Delay_30uS;
static unsigned int Delay_90uS;
static unsigned int Delay_180uS;
static unsigned int Delay_2000uS;
//
// Commands sent to the keyboard.
//
static const UINT8 cmdKeybdReset = 0xFF;
static const UINT8 cmdKeybdLights = 0xED;
//
// Commands sent to the mouse.
//
static const UINT8 cmdMouseReadId = 0xF2;
static const UINT8 cmdMouseEnable = 0xF4;
static const UINT8 cmdMouseSampleRate = 0xF3;
static const UINT8 cmdMouseDisable = 0xF5;
static const UINT8 cmdMouseReset = 0xFF;
// Pointer to memory registers.
PVBYTE v_pIoRegs;
UINT32 MouseInterruptControl;
UINT32 KeyboardInterruptControl;
extern DWORD dwHD64465Base;
/*++
Ps2P465::
MouseTest:
This routine tests for a mouse present on the HD64465 PS/2 mouse (AUX) port.
It's not a very good method. If the mouse interrupts are active
this function will fail. This function should only be called from
the initializer prior to the interrupt enable.
Returns true if a mouse is found.
--*/
BOOL
Ps2P465::
MouseTest(
void
)
{
BOOL bRet = FALSE;
UINT8 ui8Data;
//NKDbgPrintfW(L"ps2p465.cpp Mouse test entry\r\n");
if (MouseInterruptControl) {
//NKDbgPrintfW(L"ps2p465.cpp Mouse test MouseInterruptControl non-zerp\r\n");
bRet = TRUE;
}
else {
//NKDbgPrintfW(L"ps2p465.cpp Mouse command DISABLE\r\n");
if ( !MouseCommandPut(cmdMouseDisable) ) // Send Disable command
{
// goto leave;
}
//NKDbgPrintfW(L"ps2p465.cpp Mouse command READ ID\r\n");
/* Enable the Mouse input again. */
REG16(v_pIoRegs, MOUSE_CSR) = MOUSE_CLK_EN;
if ( !MouseCommandPut(cmdMouseReadId) ) // Send Read ID command
{
// goto leave;
}
//NKDbgPrintfW(L"ps2p465.cpp Mouse waiting for ID code\r\n");
/* Enable the Mouse input again. */
REG16(v_pIoRegs, MOUSE_CSR) = MOUSE_CLK_EN;
if ( !MousePollRead(&ui8Data) ) // Read ID byte
{
// goto leave;
}
//NKDbgPrintfW(L"ps2p465.cpp Mouse READ ID returned: %02X\r\n",ui8Data);
//NKDbgPrintfW(L"ps2p465.cpp Mouse command READ ID\r\n");
/* Enable the Mouse input again. */
REG16(v_pIoRegs, MOUSE_CSR) = MOUSE_CLK_EN;
if ( !MouseCommandPut(cmdMouseReadId) ) // Send Read ID command
{
// goto leave;
}
//NKDbgPrintfW(L"ps2p465.cpp Mouse waiting for ID code\r\n");
/* Enable the Mouse input again. */
REG16(v_pIoRegs, MOUSE_CSR) = MOUSE_CLK_EN;
if ( !MousePollRead(&ui8Data) ) // Read ID byte
{
// goto leave;
}
//NKDbgPrintfW(L"ps2p465.cpp Mouse READ ID returned: %02X\r\n",ui8Data);
//NKDbgPrintfW(L"ps2p465.cpp Mouse command SET SAMPLE RATE\r\n");
/* Enable the Mouse input again. */
REG16(v_pIoRegs, MOUSE_CSR) = MOUSE_CLK_EN;
if ( !MouseCommandPut(cmdMouseSampleRate) ) // Set sample rate command
{
// goto leave;
}
//NKDbgPrintfW(L"ps2p465.cpp Mouse data for SET SAMPLE RATE\r\n");
/* Enable the Mouse input again. */
REG16(v_pIoRegs, MOUSE_CSR) = MOUSE_CLK_EN;
if ( !MouseCommandPut(0x28) ) // Set sample rate to 40 per second
{
// goto leave;
}
//NKDbgPrintfW(L"ps2p465.cpp Mouse command ENABLE\r\n");
/* Enable the Mouse input again. */
REG16(v_pIoRegs, MOUSE_CSR) = MOUSE_CLK_EN;
if ( !MouseCommandPut(cmdMouseEnable) ) // Send Enable command
{
goto leave;
}
bRet = TRUE;
}
leave:
/* Enable the Mouse input again. */
REG16(v_pIoRegs, MOUSE_CSR) = MOUSE_CLK_EN;
if ( !bRet )
{
//NKDbgPrintfW(L"ps2p465.cpp Mouse not found: %02X\r\n",ui8Data);
}
//NKDbgPrintfW(L"ps2p465.cpp Mouse test exit\r\n");
return bRet;
}
/*++
Ps2P465::
MouseReset:
Sends the mouse reset command to the mouse and reads the response.
Returns true if the success response is read.
--*/
BOOL
Ps2P465::
MouseReset(
void
)
{
BOOL bRet = FALSE;
// UINT8 ui8Data;
/*
* Mouse reset removed. Always returns TRUE.
*/
bRet = TRUE;
return bRet;
}
/*++
Ps2P465::
MouseDataRead:
Reads data from the HD64465 output port.
--*/
BOOL
Ps2P465::
MouseDataRead(
UINT8 *pui8Data
)
{
*pui8Data = (UINT8)(REG16(v_pIoRegs, MOUSE_CSR));
// REG16(v_pIoRegs, MOUSE_ISR) = MOUSE_RDRF;
return TRUE;
}
/*++
Ps2P465::
MousePollRead:
This routine reads data from the HD64465 PS/2 mouse (AUX) port.
It's not a very good method. If the mouse interrupts are active
this function will fail. This function should only be called from
the initializer prior to the interrupt enable.
--*/
BOOL
Ps2P465::
MousePollRead(
UINT8 *pui8
)
{
BOOL bRet = FALSE;
UINT8 ui8Status;
UINT32 cSleeps = 100; // Rather arbitrary.
if(MouseInterruptControl == 0) {
MouseInterruptControl = 2;
while ( cSleeps )
{
ui8Status = (UINT8)(REG16(v_pIoRegs, MOUSE_ISR));
if ( ui8Status & MOUSE_RDRF )
{
break;
}
else
{
Sleep(10);
cSleeps--;
}
}
// May as well read it even if we failed.
*pui8 = (UINT8)(REG16(v_pIoRegs, MOUSE_CSR));
REG16(v_pIoRegs, MOUSE_ISR) = MOUSE_RDRF;
if ( cSleeps )
{
bRet = TRUE;
}
else
{
ERRORMSG(1,(TEXT("Ps2P465::MousePollRead: too long waiting for mouse response.\r\n")));
}
MouseInterruptControl = 0;
}
return bRet;
}
/*++
Ps2P465::
MouseInterruptEnable:
Enables HD64465 auxiliary interrupts.
--*/
BOOL
Ps2P465::
MouseInterruptEnable(
void
)
{
UINT16 k;
while (MouseInterruptControl == 2) Sleep(20);
MouseInterruptControl = 1;
// Ack the interrupt.
k = (REG16(v_pIoRegs, MOUSE_CSR));
// Write 1 to clear RDRF bit
REG16(v_pIoRegs, MOUSE_ISR) = MOUSE_RDRF;
// Set the register properly to receive
REG16(v_pIoRegs, MOUSE_CSR) = MOUSE_CLK_EN;
return TRUE;
}
/*++
Ps2P465::
KeybdInterruptEnable:
Enables HD64465 keyboard interrupts.
--*/
BOOL
Ps2P465::
KeybdInterruptEnable(
void
)
{
UINT16 k;
while(KeyboardInterruptControl == 2) Sleep(20);
KeyboardInterruptControl = 1;
// Ack the interrupt.
k = (REG16(v_pIoRegs, KB_CSR));
// Write 1 to clear RDRF bit
REG16(v_pIoRegs, KB_ISR) = KB_RDRF;
// Set the register properly to receive
REG16(v_pIoRegs, KB_CSR) = KB_CLK_EN;
return TRUE;
}
/*++
Ps2P465::
KeyboardInterfaceTest:
Writes the keyboard interface test command to the HD64465 command register
and reads the response.
Returns true if the success response is read.
--*/
BOOL
Ps2P465::
KeyboardInterfaceTest(
void
)
{
BOOL bRet = FALSE;
UINT8 ui8Data;
//NKDbgPrintfW(L"ps2p465.cpp Keyboard test entry\r\n");
if (KeyboardInterruptControl) {
bRet = TRUE;
//NKDbgPrintfW(L"ps2p465.cpp Keyboard test KeyboardInterruptControl non-zero\r\n");
}
else {
bRet = TRUE; // This is here for debug (** cea 6/15/99)
//NKDbgPrintfW(L"ps2p465.cpp Keyboard command RESET\r\n");
if ( !KeyboardCommandPut(cmdKeybdReset) ) // Send RESET command
{
goto leave;
}
//NKDbgPrintfW(L"ps2p465.cpp Keyboard waiting for RESET BAT code\r\n");
/* Enable the Keyboard input again. */
REG16(v_pIoRegs, KB_CSR) = KB_CLK_EN;
if ( !KeyboardPollRead(&ui8Data) ) // Read BAT byte
{
goto leave;
}
//NKDbgPrintfW(L"ps2p465.cpp Keyboard BAT returned: %02X\r\n",ui8Data);
bRet = TRUE;
}
leave:
/* Enable the Keyboard input again. */
REG16(v_pIoRegs, KB_CSR) = KB_CLK_EN;
if ( !bRet )
{
//NKDbgPrintfW(L"ps2p465.cpp Keyboard not found: %02X\r\n",ui8Data);
}
//NKDbgPrintfW(L"ps2p465.cpp Keyboard test exit\r\n");
return bRet;
}
/*++
Ps2P465::
KeyboardReset:
Sends the keyboard reset command to the keyboard and reads the response.
Returns true if the success response is read.
--*/
BOOL
Ps2P465::
KeyboardReset(
void
)
{
BOOL bRet = FALSE;
// UINT8 ui8Data;
/*
* Keyboard reset removed. Always returns flase.
*/
return bRet;
}
/*++
Ps2P465::
KeyboardLights:
Sets the keyboard indicator lights.
--*/
void
Ps2P465::
KeyboardLights(
unsigned int fLights
)
{
//NKDbgPrintfW(L"ps2p465.cpp KeyboardLights(%02X)\r\n",fLights);
if ( !KeyboardCommandPut(cmdKeybdLights) )
{
//NKDbgPrintfW(L"ps2p465.cpp KeyboardLights command put failed\r\n");
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -