📄 amadisp.cpp
字号:
pwc.cc1.dwClock = CC1_CLOCK_ACTIVE;
pwc.cc1.dwMode = CC1_GIO0;
PCC_ClockControl(&pwc, sizeof(POWER_CONTROL_CONFIG), &dwWork);
// Activates the HD64404 GPIO5/6 then sets them to output.
*pdwInactive &= 0xFFFFFF9F; // Activate HD64404 GPIO5/6
*pdwDirection |= 0x00000060; // Set them to output
// Programs ICD2053B.
SendPCGCommand(14, 0x1e05); // Enable loading program word
SendPCGCommand(nBits, dwData); // Load program word
SendPCGCommand(14, 0x1e04); // Disable program word
Sleep(10); // 10ms wait is required for output stabilization.
SendPCGCommand(14, 0x1e00); // Select VCO for output
// Turns off clock for GPIO module.
pwc.cc1.dwClock = CC1_CLOCK_STOP;
PCC_ClockControl(&pwc, sizeof(POWER_CONTROL_CONFIG), &dwWork);
bRet = TRUE;
}
}
__finally {
SetEvent(hGPIOEvent);
CloseHandle(hGPIOEvent);
}
return bRet;
}
BOOL AMADisp::SetRegisters(int nModeId)
{
POWER_CONTROL_CONFIG pcc;
BOOL bRet;
DEBUGMSG(GPE_ZONE_INIT,
(TEXT("AMADisp: Entering SetRegisters...\r\n")));
/* First we need to setup tile-to-linear address translation. */
m_pMPXIFRegs[MPXIF_DTMR] = AMADispMode[nModeId].MPXIFRegs[MPXIF_DTMR];
m_pMPXIFRegs[MPXIF_LTAD] = AMADispMode[nModeId].MPXIFRegs[MPXIF_LTAD];
m_pMPXIFRegs[MPXIF_LTAM] = AMADispMode[nModeId].MPXIFRegs[MPXIF_LTAM];
/* Turn on operating clock for DisplayOut and GE module */
memset((PVOID)&pcc, 0, sizeof(POWER_CONTROL_CONFIG));
pcc.bValidCControl2 = TRUE;
pcc.cc2.dwClock = CC2_CLOCK_ACTIVE;
pcc.cc2.dwMode = CC2_DO;
bRet = PCC_ClockControl(&pcc, sizeof(POWER_CONTROL_CONFIG), NULL); // DisplayOut
if (!bRet) {
RETAILMSG(1,
(TEXT("SetRegisters: Failed to turn on DisplayOut clock.\r\n")));
return FALSE;
}
pcc.cc2.dwMode = CC2_REND;
bRet = PCC_ClockControl(&pcc, sizeof(POWER_CONTROL_CONFIG), NULL); // GE
if (!bRet) {
RETAILMSG(1,
(TEXT("SetRegisters: Failed to turn on GraphicsEngine clock.\r\n")));
return FALSE;
}
Sleep(10); // for clock stabilization
m_pDisplayOutRegs[DO_SYSR ] = AMADispMode[nModeId].DORegs[DO_SYSR ];
m_pDisplayOutRegs[DO_SRCR ] = AMADispMode[nModeId].DORegs[DO_SRCR ];
m_pGraphicsEngineRegs[GE_RCR ] = AMADispMode[nModeId].GERegs[GE_RCR ];
m_pGraphicsEngineRegs[GE_SRCR ] = AMADispMode[nModeId].GERegs[GE_SRCR ];
m_pDisplayOutRegs[DO_PLL ] = AMADispMode[nModeId].DORegs[DO_PLL ];
m_pDisplayOutRegs[DO_ECR ] = AMADispMode[nModeId].DORegs[DO_ECR ];
m_pDisplayOutRegs[DO_IER ] = AMADispMode[nModeId].DORegs[DO_IER ];
m_pDisplayOutRegs[DO_DSMR ] = AMADispMode[nModeId].DORegs[DO_DSMR ];
m_pDisplayOutRegs[DO_REMR ] = AMADispMode[nModeId].DORegs[DO_REMR ];
m_pDisplayOutRegs[DO_DUFG ] = AMADispMode[nModeId].DORegs[DO_DUFG ];
m_pDisplayOutRegs[DO_DSX ] = AMADispMode[nModeId].DORegs[DO_DSX ];
m_pDisplayOutRegs[DO_DSY ] = AMADispMode[nModeId].DORegs[DO_DSY ];
m_pDisplayOutRegs[DO_DSAR0H ] = AMADispMode[nModeId].DORegs[DO_DSAR0H ];
m_pDisplayOutRegs[DO_DSAR0L ] = AMADispMode[nModeId].DORegs[DO_DSAR0L ];
m_pDisplayOutRegs[DO_DSAR1H ] = AMADispMode[nModeId].DORegs[DO_DSAR1H ];
m_pDisplayOutRegs[DO_DSAR1L ] = AMADispMode[nModeId].DORegs[DO_DSAR1L ];
m_pGraphicsEngineRegs[GE_DLSARH ] = AMADispMode[nModeId].GERegs[GE_DLSARH ];
m_pGraphicsEngineRegs[GE_DLSARL ] = AMADispMode[nModeId].GERegs[GE_DLSARL ];
m_pGraphicsEngineRegs[GE_SSAR ] = AMADispMode[nModeId].GERegs[GE_SSAR ];
m_pGraphicsEngineRegs[GE_WSAR ] = AMADispMode[nModeId].GERegs[GE_WSAR ];
m_pDisplayOutRegs[DO_HDS ] = AMADispMode[nModeId].DORegs[DO_HDS ];
m_pDisplayOutRegs[DO_HDE ] = AMADispMode[nModeId].DORegs[DO_HDE ];
m_pDisplayOutRegs[DO_VDS ] = AMADispMode[nModeId].DORegs[DO_VDS ];
m_pDisplayOutRegs[DO_VDE ] = AMADispMode[nModeId].DORegs[DO_VDE ];
m_pDisplayOutRegs[DO_HSWR ] = AMADispMode[nModeId].DORegs[DO_HSWR ];
m_pDisplayOutRegs[DO_HCR ] = AMADispMode[nModeId].DORegs[DO_HCR ];
m_pDisplayOutRegs[DO_VSP ] = AMADispMode[nModeId].DORegs[DO_VSP ];
m_pDisplayOutRegs[DO_VCR ] = AMADispMode[nModeId].DORegs[DO_VCR ];
m_pDisplayOutRegs[DO_DOORH ] = AMADispMode[nModeId].DORegs[DO_DOORH ];
m_pDisplayOutRegs[DO_DOORL ] = AMADispMode[nModeId].DORegs[DO_DOORL ];
m_pDisplayOutRegs[DO_LBGSX ] = AMADispMode[nModeId].DORegs[DO_LBGSX ];
m_pDisplayOutRegs[DO_LBGSY ] = AMADispMode[nModeId].DORegs[DO_LBGSY ];
m_pDisplayOutRegs[DO_RBGSX ] = AMADispMode[nModeId].DORegs[DO_RBGSX ];
m_pDisplayOutRegs[DO_RBGSY ] = AMADispMode[nModeId].DORegs[DO_RBGSY ];
m_pDisplayOutRegs[DO_EQWR ] = AMADispMode[nModeId].DORegs[DO_EQWR ];
m_pDisplayOutRegs[DO_SPWR ] = AMADispMode[nModeId].DORegs[DO_SPWR ];
m_pDisplayOutRegs[DO_DSMR2 ] = AMADispMode[nModeId].DORegs[DO_DSMR2 ];
m_pDisplayOutRegs[DO_HVP ] = AMADispMode[nModeId].DORegs[DO_HVP ];
m_pDisplayOutRegs[DO_VVP ] = AMADispMode[nModeId].DORegs[DO_VVP ];
m_pDisplayOutRegs[DO_VSAR0H ] = AMADispMode[nModeId].DORegs[DO_VSAR0H ];
m_pDisplayOutRegs[DO_VSAR0L ] = AMADispMode[nModeId].DORegs[DO_VSAR0L ];
m_pDisplayOutRegs[DO_VSAR1H ] = AMADispMode[nModeId].DORegs[DO_VSAR1H ];
m_pDisplayOutRegs[DO_VSAR1L ] = AMADispMode[nModeId].DORegs[DO_VSAR1L ];
m_pDisplayOutRegs[DO_VSAR2H ] = AMADispMode[nModeId].DORegs[DO_VSAR2H ];
m_pDisplayOutRegs[DO_VSAR2L ] = AMADispMode[nModeId].DORegs[DO_VSAR2L ];
m_pDisplayOutRegs[DO_VSIZEX ] = AMADispMode[nModeId].DORegs[DO_VSIZEX ];
m_pDisplayOutRegs[DO_VSIZEY ] = AMADispMode[nModeId].DORegs[DO_VSIZEY ];
m_pDisplayOutRegs[DO_VIMR ] = AMADispMode[nModeId].DORegs[DO_VIMR ];
m_pDisplayOutRegs[DO_HCS1 ] = AMADispMode[nModeId].DORegs[DO_HCS1 ];
m_pDisplayOutRegs[DO_VCS1 ] = AMADispMode[nModeId].DORegs[DO_VCS1 ];
m_pDisplayOutRegs[DO_HCS2 ] = AMADispMode[nModeId].DORegs[DO_HCS2 ];
m_pDisplayOutRegs[DO_VCS2 ] = AMADispMode[nModeId].DORegs[DO_VCS2 ];
m_pDisplayOutRegs[DO_CSAR1 ] = AMADispMode[nModeId].DORegs[DO_CSAR1 ];
m_pDisplayOutRegs[DO_CSAR2 ] = AMADispMode[nModeId].DORegs[DO_CSAR2 ];
m_pDisplayOutRegs[DO_WRPY ] = AMADispMode[nModeId].DORegs[DO_WRPY ];
m_pDisplayOutRegs[DO_DBR1 ] = AMADispMode[nModeId].DORegs[DO_DBR1 ];
m_pDisplayOutRegs[DO_DBR2 ] = AMADispMode[nModeId].DORegs[DO_DBR2 ];
m_pDisplayOutRegs[DO_TRNFGR ] = AMADispMode[nModeId].DORegs[DO_TRNFGR ];
m_pDisplayOutRegs[DO_TRNC1R ] = AMADispMode[nModeId].DORegs[DO_TRNC1R ];
m_pDisplayOutRegs[DO_TRNC2R ] = AMADispMode[nModeId].DORegs[DO_TRNC2R ];
m_pGraphicsEngineRegs[GE_RSAR ] = AMADispMode[nModeId].GERegs[GE_RSAR ];
Sleep(50); /* At least 1 VSYNC time needed for clear DO/GE reset */
m_pDisplayOutRegs[DO_SYSR ] &= 0xFFFFBFFF; // clear DRES
m_pDisplayOutRegs[DO_SYSR ] |= 0x00002000; // set DEN
m_pGraphicsEngineRegs[GE_RCR ] &= 0x7FFFFFFF; // clear SRES
DEBUGMSG(GPE_ZONE_INIT,
(TEXT("AMADisp: SetRegisters finished.\r\n")));
return TRUE;
}
SCODE AMADisp::SetMode( int modeId, HPALETTE *pPalette )
{
DWORD dwLine, dwStride, dwLen;
DEBUGMSG(GPE_ZONE_ENTER,(TEXT("AMADisp::SetMode\r\n")));
if (modeId >= NUMDISPMODES)
return E_INVALIDARG;
m_nScreenWidth = AMADispMode[modeId].gpeMode.width;
m_nScreenHeight = AMADispMode[modeId].gpeMode.height;
if (AMADispMode[modeId].gpeMode.Bpp == 8)
m_nScreenStride = 1024;
else if (AMADispMode[modeId].gpeMode.Bpp == 16)
m_nScreenStride = 2048;
m_pMode = &AMADispMode[modeId].gpeMode;
// If the externnal clock generator ICD2053B is used, initialize it before
// setup HD64404 display registers.
SetClock(modeId); // This does nothing when not needed.
// Initialize registers.
SetRegisters(modeId);
m_pPrimarySurface = new GPESurf(
m_nScreenWidth,
m_nScreenHeight,
(void*)m_pVideoMemory, /* TEMPORARY */
m_nScreenStride,
AMADispMode[modeId].gpeMode.format);
if (pPalette) { /* 16bpp bitfield palette */
if (AMADispMode[modeId].gpeMode.Bpp == 16) {
*pPalette = EngCreatePalette(
PAL_BITFIELDS,
0,
NULL,
0xF800,
0x07E0,
0x001F
);
// Because the color palette is a shared resource, palette setting
// is required even the screen mode is set to 16bpp.
// Actually, HD64404 hardware cursors use color palette.
SetPalette(_rgbIdentity, 0, PALETTE_SIZE); // PALETTE_SIZE = 256
}
else /* 8bpp indexed palette */
*pPalette = EngCreatePalette(
PAL_INDEXED,
PALETTE_SIZE,
(ULONG *)_rgbIdentity,
0,
0,
0
);
// SetPalette is internally called.
}
// Clear up frame buffer
dwStride = (DWORD)m_nScreenStride;
dwLen = m_nScreenWidth * AMADispMode[modeId].gpeMode.Bpp / 8;
for (dwLine = 0; dwLine < (DWORD)m_nScreenHeight; dwLine++)
memset((PVOID)((DWORD)m_pVideoMemory + dwLine * dwStride), 0, dwLen);
return S_OK;
}
SCODE AMADisp::GetModeInfo
(
GPEMode *pMode,
int modeNo
)
{
DEBUGMSG(GPE_ZONE_ENTER,
(TEXT("AMADisp::GetModeInfo\r\n")));
if (modeNo >= NUMDISPMODES)
return E_INVALIDARG;
*pMode = AMADispMode[modeNo].gpeMode;
return S_OK;
}
int AMADisp::NumModes()
{
DEBUGMSG(GPE_ZONE_ENTER,
(TEXT("AMADisp::NumModes\r\n")));
return NUMDISPMODES;
}
SCODE AMADisp::SetPointerShape(GPESurf *pMask, GPESurf *pColorSurf,
INT xHot, INT yHot, INT cX, INT cY)
{
int i, row, col;
int bitMask;
DWORD dwIndexA, dwIndexB;
BYTE bAND, bXOR;
BYTE bValA, bValB;
DEBUGMSG( GPE_ZONE_CURSOR,
(TEXT("DispOut::SetPointerShape(0x%X, 0x%X, %d, %d, %d, %d)\r\n"),
pMask, pColorSurf, xHot, yHot, cX, cY));
if (!pMask ) {
// Turn off the cursor.
DEBUGMSG (GPE_ZONE_CURSOR, (TEXT("SetPointerShape OFF\r\n")));
m_pDisplayOutRegs[DO_DSMR2] &= 0xFFFFFFFD; // turn off cursor1
} else {
// Set the new pattern and turn on.
DEBUGMSG (GPE_ZONE_CURSOR, (TEXT("SetPointerShape ON\r\n")));
for (row = 0; row < DO_CURSORHEIGHT; row++) {
for (col = 0; col < DO_CURSORWIDTH / 8; col++) {
if (row < cY && col < cX / 8) {
bAND = ((unsigned char *)pMask->Buffer()+row*pMask->Stride())[col];
bXOR = ((unsigned char *)pMask->Buffer()+(cY+row)*pMask->Stride())[col];
}
else {
bAND = 255;
bXOR = 0;
}
dwIndexA = row * DO_CURSORWIDTH + col * 8; // linear-based calculation,
dwIndexB = dwIndexA + DO_CURSORBYTES; // converted to CPU offset later.
for (bitMask=0x0080, i=0; i < 8; bitMask >>=1, i++) {
if (bAND & bitMask) {
if (bXOR & bitMask) { // AND=1, XOR=1 : blink (instead of XOR)
bValA = 255; // white
bValB = 0; // non-transparent black
}
else { // AND=1, XOR=0 : transparent
bValA = CURSOR_TRANSPARENT_COLOR;// transparent on cursor1
bValB = CURSOR_TRANSPARENT_COLOR;// transparent on cursor1
}
}
else {
if (bXOR & bitMask) { // AND=0, XOR=1 : white
bValA = 255; // white
bValB = 255; // white
}
else { // AND=0, XOR=0 : black
bValA = 0; // non-transparent black
bValB = 0; // non-transparent black
}
}
if (m_nScreenStride == 512) { // 8bpp/512w
m_pCursorPattern[dwIndexA & 0x03FFE01F
| (dwIndexA & 0x01E0) << 4
| (dwIndexA & 0x1E00) >> 4] = bValA;
m_pCursorPattern[dwIndexB & 0x03FFE01F
| (dwIndexB & 0x01E0) << 4
| (dwIndexB & 0x1E00) >> 4] = bValB;
}
else if (m_nScreenStride == 1024) { // 8bpp/1024w or 16bpp/512w
m_pCursorPattern[dwIndexA & 0x03FFC01F
| (dwIndexA & 0x01E0) << 5
| (dwIndexA & 0x3E00) >> 4] = bValA;
m_pCursorPattern[dwIndexB & 0x03FFC01F
| (dwIndexB & 0x01E0) << 5
| (dwIndexB & 0x3E00) >> 4] = bValB;
}
else if (m_nScreenStride == 2048) { // 16bpp/512w
m_pCursorPattern[dwIndexA & 0x03FF801F
| (dwIndexA & 0x01E0) << 6
| (dwIndexA & 0x7E00) >> 4] = bValA;
m_pCursorPattern[dwIndexB & 0x03FF801F
| (dwIndexB & 0x01E0) << 6
| (dwIndexB & 0x7E00) >> 4] = bValB;
}
else { // Other, unsupported stride.
RETAILMSG(1,
(TEXT("SetPointerShape: Unsupported stride %d.\r\n"),
m_nScreenStride));
return E_FAIL;
}
dwIndexA++;
dwIndexB++;
}
}
}
gxHot = xHot;
gyHot = yHot;
m_pDisplayOutRegs[DO_DSMR2] |= 0x00000002; // turn on cursor1
}
return S_OK;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -