Пример #1
0
void ReadControllerCommand (int Control, BYTE * Command) {
	switch (Command[2]) {
	case 0x01: // read controller
		if (Controllers[Control].Present == TRUE) {
#ifndef EXTERNAL_RELEASE
			if (Command[0] != 1) { DisplayError("What am I meant to do with this Controller Command"); }
			if (Command[1] != 4) { DisplayError("What am I meant to do with this Controller Command"); }
#endif
			if (GetKeys) {
				BUTTONS Keys;
				
				GetKeys(Control,&Keys);
				*(DWORD *)&Command[3] = Keys.Value;
			} else {
				*(DWORD *)&Command[3] = 0;
			}
		}
		break;
	case 0x02: //read from controller pack
		if (Controllers[Control].Present == TRUE) {
			switch (Controllers[Control].Plugin) {
			case PLUGIN_RAW: if (ControllerCommand) { ReadController(Control, Command); } break;
			}
		} 
		break;
	case 0x03: //write controller pak
		if (Controllers[Control].Present == TRUE) {
			switch (Controllers[Control].Plugin) {
			case PLUGIN_RAW: if (ControllerCommand) { ReadController(Control, Command); } break;
			}
		}
		break;
	}
}
Пример #2
0
int main(void)
{
	uchar   i = 1;
	uchar	hidCurrentMode = 255;
	char remainingData=0;
	uchar offset=0;

	HardwareInit();
	usbInit();

	// Set up descriptor
	hidMode = HIDM_1P;
	ReadController(1);
	SetHIDMode();

    for(;;){                /* main event loop */
        usbPoll();
        if(usbInterruptIsReady()){
            /* called after every poll of the interrupt endpoint */
			ReadController(i);
			RemapButtons(&(reportBuffer.b1), &(reportBuffer.b2));
			RemapButtons(&(reportBufferWheel.b1), &(reportBufferWheel.b2));
			remainingData=reportBufferLength;
			offset=0;
			// handle report with more than 8 byte length (for NegCon and future expansion)
			do {
				if (remainingData<=8) {
					usbSetInterrupt(reportBufferAddress+offset, remainingData);
					remainingData=0;
				}
				else {	
					usbSetInterrupt(reportBufferAddress+offset, 8);				
					offset+=8;
					remainingData-=8;
					do {
						usbPoll();
					} while (!usbInterruptIsReady());	
				}
			} while (remainingData>0);				
				
			i++;
			if (i > hidNumReports) i = 1;
			if (hidCurrentMode != hidMode)
			{
				SetHIDMode();
				hidCurrentMode = hidMode;
			}
        }
    }

    return 0;
}
Пример #3
0
int main(void)
{
	uchar   i = 1;
	uchar	hidCurrentMode = 255;
	char remainingData=0;
	uchar offset=0;

	HardwareInit();
	usbInit();

	// Set up descriptor
	hidMode = HIDM_1P;
	ReadController(1);
	SetHIDMode();

//	uchar j = 1; //for speed test only
	
    for(;;){                /* main event loop */
        usbPoll();
        if(usbInterruptIsReady()){
            /* called after every poll of the interrupt endpoint */
			ReadController(i);
			
			switch (hidCurrentMode)
			{
				case HIDM_1P:
					RemapController(&(reportBuffer.x), &(reportBuffer.y), 
						&(reportBuffer.rx), &(reportBuffer.ry),
						&(reportBuffer.b1), &(reportBuffer.b2));
					break;
				case HIDM_2P:
					RemapController(&(reportBuffer.x), &(reportBuffer.y), 
						&(reportBuffer.rx), &(reportBuffer.ry),
						&(reportBuffer.b1), &(reportBuffer.b2));
					break;
				case HIDM_NEGCON:
					RemapController(&(reportBufferNegCon.x), &(reportBufferNegCon.y), 
						&(reportBufferNegCon.rx), &(reportBufferNegCon.ry),
						&(reportBufferNegCon.b1), &(reportBufferNegCon.b2));
					break;
			}

			remainingData=reportBufferLength;
			offset=0;

// For speed test, uncommnent the next three lines and the line "uchar j=0" above
//			reportBuffer.x=(j%4)*10; //for speed test only
//			reportBufferNegCon.x=(j%4)*10; //for speed test only
//			j++; //for speed test only
		
			// handle report with more than 8 byte length (for NegCon and future expansion)
			do {
				if (remainingData<=8) {
					usbSetInterrupt(reportBufferAddress+offset, remainingData);
					remainingData=0;
				}
				else {	
					usbSetInterrupt(reportBufferAddress+offset, 8);				
					offset+=8;
					remainingData-=8;
					do {
						usbPoll();
					} while (!usbInterruptIsReady());	
				}
			} while (remainingData>0);				

			i++;
			if (i > hidNumReports) i = 1;
			if (hidCurrentMode != hidMode)
			{
				SetHIDMode();
				hidCurrentMode = hidMode;
			}
        }
    }

    return 0;
}
Пример #4
0
			void ReadChunks()
			{
				Context context;

				while (!stream.Eof())
				{
					dword id = stream.Read32();
					const dword length = stream.Read32();
					NST_VERIFY( length <= SIZE_1K * 4096UL );

					switch (id)
					{
						case AsciiId<'N','A','M','E'>::V: id = (context( 0, id ) ? ReadName       (         ) : 0); break;
						case AsciiId<'R','E','A','D'>::V: id = (context( 1, id ) ? ReadComment    (         ) : 0); break;
						case AsciiId<'D','I','N','F'>::V: id = (context( 2, id ) ? ReadDumper     (         ) : 0); break;
						case AsciiId<'T','V','C','I'>::V: id = (context( 3, id ) ? ReadSystem     ( context ) : 0); break;
						case AsciiId<'B','A','T','R'>::V: id = (context( 4, id ) ? ReadBattery    (         ) : 0); break;
						case AsciiId<'M','A','P','R'>::V: id = (context( 5, id ) ? ReadBoard      (         ) : 0); break;
						case AsciiId<'M','I','R','R'>::V: id = (context( 6, id ) ? ReadMirroring  (         ) : 0); break;
						case AsciiId<'C','T','R','L'>::V: id = (context( 7, id ) ? ReadController (         ) : 0); break;
						case AsciiId<'V','R','O','R'>::V: id = (context( 8, id ) ? ReadChrRam     (         ) : 0); break;

						default: switch (id & 0x00FFFFFF)
						{
							case AsciiId<'P','C','K'>::V:
							case AsciiId<'C','C','K'>::V:
							case AsciiId<'P','R','G'>::V:
							case AsciiId<'C','H','R'>::V:
							{
								uint index = id >> 24 & 0xFF;

								if (index >= Ascii<'0'>::V && index <= Ascii<'9'>::V)
								{
									index -= Ascii<'0'>::V;
								}
								else if (index >= Ascii<'A'>::V && index <= Ascii<'F'>::V)
								{
									index = index - Ascii<'A'>::V + 10;
								}
								else
								{
									index = ~0U;
								}

								if (index < 16)
								{
									switch (dword part = (id & 0x00FFFFFF))
									{
										case AsciiId<'P','C','K'>::V:
										case AsciiId<'C','C','K'>::V:

											part = (part == AsciiId<'C','C','K'>::V);
											id = (context( 9 + (part << 4) + index, id) ? ReadChecksum( part, index, context.roms[part][index] ) : 0);
											break;

										case AsciiId<'P','R','G'>::V:
										case AsciiId<'C','H','R'>::V:

											part = (part == AsciiId<'C','H','R'>::V);
											id = (context( 9 + 32 + (part << 4) + index, id ) ? ReadRom( part, index, length, context.roms[part] ) : 0);
											break;
									}

									break;
								}
							}

							default:

								id = ReadUnknown( id );
								break;
						}
					}

					if (id < length)
					{
						for (id = length - id; id > 0x7FFFFFFF; id -= 0x7FFFFFFF)
							stream.Seek( 0x7FFFFFFF );

						if (id)
							stream.Seek( id );
					}
					else if (id > length)
					{
						throw RESULT_ERR_CORRUPT_FILE;
					}
				}

				for (uint i=0; i < 2; ++i)
				{
					uint count = 0;
					dword size = 0;

					for (uint j=0; j < 16; ++j)
					{
						if (const dword n=context.roms[i][j].data.Size())
						{
							count++;
							size += n;
						}
					}

					if (count)
					{
						Profile::Board::Roms& rom = (i ? profile.board.chr : profile.board.prg);
						rom.resize( count );

						Ram& dst = (i ? chr : prg);
						dst.Set( size );

						if (!rom.empty())
						{
							for (Profile::Board::Pins::const_iterator it(rom.front().pins.begin()), end(rom.front().pins.end()); it != end; ++it)
								dst.Pin(it->number) = it->function.c_str();
						}

						size = 0;

						for (uint j=0, k=0; j < 16; ++j)
						{
							const Context::Rom& src = context.roms[i][j];

							if (src.data.Size())
							{
								rom[k].id = k;
								rom[k].size = src.data.Size();
								rom[k].hash.Assign( NULL, src.crc );
								k++;

								std::memcpy( dst.Mem(size), src.data.Mem(), src.data.Size() );
								size += src.data.Size();
							}
						}
					}
				}

				if (profileEx.nmt == ProfileEx::NMT_HORIZONTAL)
				{
					profile.board.solderPads = Profile::Board::SOLDERPAD_V;
				}
				else if (profileEx.nmt == ProfileEx::NMT_HORIZONTAL)
				{
					profile.board.solderPads = Profile::Board::SOLDERPAD_H;
				}

				switch (context.system)
				{
					case Context::SYSTEM_NTSC:

						if (favoredSystem == FAVORED_FAMICOM)
						{
							profile.system.type = Profile::System::FAMICOM;
						}
						if (favoredSystem == FAVORED_DENDY)
						{
							profile.system.type = Profile::System::DENDY;
							profile.system.cpu = Profile::System::CPU_DENDY;
							profile.system.ppu = Profile::System::PPU_DENDY;
						}
						else
						{
							profile.system.type = Profile::System::NES_NTSC;
						}
						break;

					default:

						profile.multiRegion = true;

						if (favoredSystem == FAVORED_FAMICOM)
						{
							profile.system.type = Profile::System::FAMICOM;
							break;
						}
						else if (favoredSystem != FAVORED_NES_PAL && favoredSystem != FAVORED_DENDY)
						{
							profile.system.type = Profile::System::NES_NTSC;
							break;
						}

					case Context::SYSTEM_PAL:

						if (favoredSystem == FAVORED_DENDY)
						{
							profile.system.type = Profile::System::DENDY;
							profile.system.cpu = Profile::System::CPU_DENDY;
							profile.system.ppu = Profile::System::PPU_DENDY;
						}
						else
						{
							profile.system.type = Profile::System::NES_PAL;
							profile.system.cpu = Profile::System::CPU_RP2A07;
							profile.system.ppu = Profile::System::PPU_RP2C07;
						}
						break;
				}
			}
Пример #5
0
int main (){


	HardwareInit();

	RF24 radio = RF24();
	// Radio pipe addresses for the 2 nodes to communicate.
	const uint64_t pipes[2] = { 0xF0F0F0F0BELL, 0xF0F0F0F0EFLL };

	setup_watchdog(wdt_64ms);

	//
	// Setup and configure rf radio
	//
	radio.begin();

	radio.setChannel(100);

	// optionally, increase the delay between retries & # of retries
	radio.setRetries(15,15);

	// optionally, reduce the payload size.  seems to
	// improve reliability
	radio.setPayloadSize(sizeof(report_t));

	radio.setDataRate(RF24_250KBPS);
	radio.openWritingPipe(pipes[0]);
	radio.openReadingPipe(1,pipes[1]);
	radio.startListening();
	radio.stopListening();

	//unsigned long  pa = 0;
	uint8_t counter = 0;


	//check eeprom
	if (eeprom_read_byte(0)==EEPROM_MAGIC_NUMBER){
		minx=(char)eeprom_read_byte((uint8_t*)1);
		maxx=(char)eeprom_read_byte((uint8_t*)2);
		miny=(char)eeprom_read_byte((uint8_t*)3);
		maxy=(char)eeprom_read_byte((uint8_t*)4);
		minrx=(char)eeprom_read_byte((uint8_t*)5);
		maxrx=(char)eeprom_read_byte((uint8_t*)6);
		minry=(char)eeprom_read_byte((uint8_t*)7);
		maxry=(char)eeprom_read_byte((uint8_t*)8);
		calibrated=true;

#ifdef DEBUG
		print_string("read eeprom magic number");
		char temp[100];
		sprintf(temp,"minx:%d maxx:%d minry:%d maxry:%d \n",minx,maxx,minry,maxry);
		print_string(temp);
		_delay_ms(2000);
#endif

	}


	while(1){

		ReadController();
#ifdef DEBUG
		char temp[100];
		print_string("before convert\n");
		sprintf(temp,"hat:%u x:%d y:%d rx:%d ry:%d b1:%u b2:%u\n",reportBuffer.hat,(int8_t)reportBuffer.x,(int8_t)reportBuffer.y,(int8_t)reportBuffer.rx,(int8_t)reportBuffer.ry,reportBuffer.b1,reportBuffer.b2);
		print_string(temp);
#endif

		convertAxes();

#ifdef DEBUG
		sprintf(temp,"hat:%u x:%d y:%d rx:%d ry:%d b1:%u b2:%u\n",reportBuffer.hat,(int8_t)reportBuffer.x,(int8_t)reportBuffer.y,(int8_t)reportBuffer.rx,(int8_t)reportBuffer.ry,reportBuffer.b1,reportBuffer.b2);
		print_string(temp);
#endif

		//Calibration
		if(A_PRESSED && B_PRESSED && Z_PRESSED && L_PRESSED && R_PRESSED){
			calibrate();
		}

		counter=(counter+1)%20;
		sendData(counter==0,radio);


		do_sleep();
	}
	//never reached
	return 0;
}
Пример #6
0
void calibrate()
{

#ifdef DEBUG
	print_string("calibration entered\n");
#endif
	PORTD |= (1 << LED2);
	PORTD |= (1 << LED1);

	maxx=0;
	minx=255;
	maxy=0;
	miny=255;
	maxrx=0;
	minrx=255;
	maxry=0;
	minry=255;

	while (1)
	{
		ReadController();
		if (START_PRESSED)
			break;

		if (reportBuffer.x > maxx)
		{
			maxx = reportBuffer.x;
		}
		if (reportBuffer.rx > maxrx)
		{
			maxrx =  reportBuffer.rx;
		}
		if ( reportBuffer.y > maxy)
		{
			maxy =  reportBuffer.y;
		}
		if ( reportBuffer.ry > maxry)
		{
			maxry =  reportBuffer.ry;
		}
		if ( reportBuffer.x < minx)
		{
			minx =  reportBuffer.x;
		}
		if ( reportBuffer.rx < minrx)
		{
			minrx =  reportBuffer.rx;
		}
		if ( reportBuffer.y < miny)
		{
			miny =  reportBuffer.y;
		}
		if ( reportBuffer.ry < minry)
		{
			minry =  reportBuffer.ry;
		}

		PORTD ^= (1 << LED2);
		_delay_ms(64);
	}
	calibrated = true;

	if (eeprom_read_byte(0)!=EEPROM_MAGIC_NUMBER){
		eeprom_write_byte(0,EEPROM_MAGIC_NUMBER);
	}
	eeprom_write_byte((uint8_t*)1,(uint8_t)minx);
	eeprom_write_byte((uint8_t*)2,(uint8_t)maxx);
	eeprom_write_byte((uint8_t*)3,(uint8_t)miny);
	eeprom_write_byte((uint8_t*)4,(uint8_t)maxy);
	eeprom_write_byte((uint8_t*)5,(uint8_t)minrx);
	eeprom_write_byte((uint8_t*)6,(uint8_t)maxrx);
	eeprom_write_byte((uint8_t*)7,(uint8_t)minry);
	eeprom_write_byte((uint8_t*)8,(uint8_t)maxry);
	calibrated=true;

#ifdef DEBUG
		char temp[100];
		sprintf(temp,"min:%d %d max:%d %d minr;%d %d maxr: %d %d\n",minx,miny,maxx,maxy,minrx,minry,maxrx,maxry);
		print_string(temp);
#endif



	PORTD &= ~(1 << LED2);
	PORTD &= ~(1 << LED1);
}
Пример #7
0
void PifRamRead (void) {
	int Channel, CurPos;

	Channel = 0;
	CurPos  = 0;
	
	if (PIF_Ram[0x3F] == 0x2) {
		int cnt = 0;
		char buff[256];
		if (pif2valid == FALSE)
			LoadPIF2 ();
		while (Pif2Reply[0][cnt] != -1) {
			if (Pif2Reply[0][cnt] == *(unsigned __int64 *)&PIF_Ram[48]) {
				if (Pif2Reply[1][cnt] == *(unsigned __int64 *)&PIF_Ram[56]) {
					PIF_Ram[46] = PIF_Ram[47] = 0x00;
					*(unsigned __int64 *)&PIF_Ram[48] = Pif2Reply[2][cnt];
					*(unsigned __int64 *)&PIF_Ram[56] = Pif2Reply[3][cnt];
					cnt = -1;
					break;
				}
			}
			cnt++;
		}
		if (cnt != -1) {
			char buff2[256];
			int count;

			sprintf (buff, "%s :(\r\n\r\nInfo:\r\nP1=%08X%08X P2=%08X%08X\r\n", GS(MSG_PIF2_ERROR),
				*(DWORD *)&PIF_Ram[52],
				*(DWORD *)&PIF_Ram[48],
				*(DWORD *)&PIF_Ram[60],
				*(DWORD *)&PIF_Ram[56]);
			for (count = 48; count < 64; count++) {
				if (count % 4 == 0) { 
					strcat(buff,count == 48?"0x":", 0x");
				}
				sprintf(buff2,"%02X",PIF_Ram[count]);
				strcat(buff,buff2);
			}
			if (!inFullScreen) {
				MessageBox (NULL, buff, GS(MSG_PIF2_TITLE), MB_OK);
			}
		}
		/*
            PIF_Ram[48] = 0x3E; PIF_Ram[49] = 0xC6; PIF_Ram[50] = 0xC0; PIF_Ram[51] = 0x4E;
            PIF_Ram[52] = 0xBD; PIF_Ram[53] = 0x37; PIF_Ram[54] = 0x15; PIF_Ram[55] = 0x55;
            PIF_Ram[56] = 0x5A; PIF_Ram[57] = 0x8C; PIF_Ram[58] = 0x2A; PIF_Ram[59] = 0x8C;
            PIF_Ram[60] = 0xD3; PIF_Ram[61] = 0x71; PIF_Ram[62] = 0x71; PIF_Ram[63] = 0x00;
		*/

		CurPos = 0x40;
	}

	do {
		switch(PIF_Ram[CurPos]) {
		case 0x00: 
			Channel += 1; 
			if (Channel > 6) { CurPos = 0x40; }
			break;
		case 0xFE: CurPos = 0x40; break;
		case 0xFF: break;
		case 0xB4: case 0x56: case 0xB8: break; /* ??? */
		default:
			if ((PIF_Ram[CurPos] & 0xC0) == 0) {
				if (Channel < 4) {
					if (Controllers[Channel].Present && Controllers[Channel].RawData) {
						if (ReadController) { ReadController(Channel,&PIF_Ram[CurPos]); }
					} else {
						ReadControllerCommand(Channel,&PIF_Ram[CurPos]);
					}
				} 
				CurPos += PIF_Ram[CurPos] + (PIF_Ram[CurPos + 1] & 0x3F) + 1;
				Channel += 1;
			} else {
				if (ShowPifRamErrors) { DisplayError("Unknown Command in PifRamRead(%X)",PIF_Ram[CurPos]); }
				CurPos = 0x40;
			}
			break;
		}
		CurPos += 1;
	} while( CurPos < 0x40 );
	if (ReadController) { ReadController(-1,NULL); }
}