AxibugEmuOnline/virtuanessrc097-master/NES/PadEX/EXPAD_Gyromite.cpp

96 lines
3.7 KiB
C++
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

//////////////////////////////////////////////////////////////////////////
// Gyromite
//////////////////////////////////////////////////////////////////////////
INT EXPAD_Gyromite::CheckSignal()
{
RGBQUAD palette[256];
RGBQUAD pixel;
// throttling detection issues
DirectDraw.GetPaletteData( palette );
pixel = palette[BGPAL[0]];
for( INT lcv=1; lcv<16; lcv++ ) {
// reject non-solid screens
if( memcmp( &(palette[BGPAL[lcv]]), &pixel, sizeof(RGBQUAD) ) != 0 ) {
return 0xF00;
}
}
// check for a black or green screen
return ( pixel.rgbGreen > 0x10 ) ? 1:0;
}
void EXPAD_Gyromite::Reset()
{
bits = 0;
arms = 0;
spot = 0;
// Initialize light on/off sequences
code[0] = 0x0EE8; // Open arm
code[1] = 0x0FA8; // Close arm
code[2] = 0x1AE8; // Test robot
code[3] = 0x0AAA; // Unused
code[4] = 0x1BA8; // Raise arm
code[5] = 0x1BE8; // Lower arm
code[6] = 0x0BA8; // Turn left
code[7] = 0x0AE8; // Turn right
}
void EXPAD_Gyromite::Strobe()
{
nes->pad->pad2bit &= ~0xFF;
nes->pad->pad2bit |= arms;
}
void EXPAD_Gyromite::Sync()
{
// INT signal = CheckSignal( 129 );
INT signal = CheckSignal();
// build our message
if( signal > 0xFF ) {
bits = 0;
spot = 0;
}
else {
bits |= (signal << spot);
spot++;
// Check for a test message: BBBBBB[test]
if( spot==6 && bits==0 ) {
spot = 0;
}
}
// decode message
if( spot==13 ) {
for( INT i=0; i<8; i++ ) {
if( bits == code[i] ) {
arms ^= (1<<i);
}
}
spot = 0;
bits = 0;
}
}
void EXPAD_Gyromite::SetSyncData( INT type, LONG data )
{
bits = ((WORD)( data &0x0000FFFF));
arms = ((BYTE)((data>>16)&0x000000FF));
spot = (BYTE)(data>>24);
}
LONG EXPAD_Gyromite::GetSyncData( INT type )
{
LONG data = 0;
data = (bits&0xFFFF)|
((arms&0xFF)<<16)|
(spot<<24);
return data;
}