Esempio n. 1
0
void enable_port(void)
{
 unsigned long dat32;

 w32(HcRhP1,0x00000102);
 w32(HcRhP2,0x00000102);
 w32(HcRhStatus,0x00010000);	//set Global Power

 w32(HcRhA,0x20000102);
 w32(HcRhB,0x00000000);

 dat32=r32(HcRhP2);
 if((dat32&0x00000001)==1)
 {
  set_port_speed(2,0);
  if(((dat32)&(0x00000200))!=0)
  {
   set_port_speed(2,1);
  }
 }

 dat32=r32(HcRhP1);
 if((dat32&0x00000001)==1)
 {
  set_port_speed(1,0);
  if(((dat32)&(0x00000200))!=0)
  {
   set_port_speed(1,1);
  }
 }
}
Esempio n. 2
0
void set_operational(void)
{
//if (g_is_PCI == TRUE)	
 w16(HcHWCfg		, 0x302d	);	// set INT1 to Active LOW, Level Triggered
//else 	w16(HcHWCfg		, 0x342D	);
 w32(HcFmItv  		, 0x25002EDF);
 w32(HcControl		, 0x00000680);
}
Esempio n. 3
0
bool    ADMMemioAvi::writeWavStruct(const WAVHeader &hdr)
{
    w16(	encoding);	
    w16(	channels);					/* 1 = mono, 2 = stereo */
    w32(	frequency);				/* One of 11025, 22050, or 44100 48000 Hz */
    w32(	byterate);					/* Average bytes per second */
    w16(	blockalign);				/* Bytes per sample block */
    w16(	bitspersample);		/* One of 8, 1 */
    return true;
}
/**
    \fn writeWavHeader
*/
bool riffWritter::writeWavHeader(const char *tag,WAVHeader *hdr)
{
uint32_t fcc;
    fcc = fourCC::get((uint8_t *)tag);
    ADM_assert(fcc);
    write32(fcc);
    write32(sizeof(*hdr));
#define w16(x) write16(hdr->x)
#define w32(x) write32(hdr->x)
    
    w16(	encoding);	
    w16(	channels);					/* 1 = mono, 2 = stereo */
    w32(	frequency);				/* One of 11025, 22050, or 44100 48000 Hz */
    w32(	byterate);					/* Average bytes per second */
    w16(	blockalign);				/* Bytes per sample block */
    w16(	bitspersample);		/* One of 8, 12, 16, or 4 for ADPCM */
    return true;
}
Esempio n. 5
0
void check_ports(void)
{
 unsigned long control,irq_status,status1,status2;

 control   =r32(HcControl);
 irq_status=r32(HcIntStatus);
 status1   =r32(HcRhP1);
 status2   =r32(HcRhP2);

  if((status1&0x00000001)==1)
  {
   w32(HcRhP1,0x00000102);
   if((status1&0x00000200)!=0)
   {
	printf("\nLS Device connected to Port 1     ");
	set_port_speed(1,1);
   }
   else
   {
	printf("\nFS Device connected to Port 1     ");
 	set_port_speed(1,0);
   }
  }

  if((status2&0x00000001)==1)
  {
   w32(HcRhP2,0x00000102);
   if((status2&0x00000200)!=0)
   {
	printf("\nLS Device connected to Port 2     ");
	set_port_speed(2,1);
   }
   else
   {
	printf("\nFS Device connected to Port 2     ");
	set_port_speed(2,0);
   }
  }

 printf("\nControl    Register = %8lX.",control);
 printf("\nInt Status Register = %8lX.",irq_status);
 printf("\nP1  Status Register = %8lX.",status1);
 printf("\nP2  Status Register = %8lX.",status2);
}
Esempio n. 6
0
bool    ADMMemioAvi::writeBihStruct(const ADM_BITMAPINFOHEADER &hdr)
{
    w32( 	biSize);
    w32(  	biWidth);
    w32(  	biHeight);
    w16( 	biPlanes);
    w16( 	biBitCount);
    w32( 	biCompression);
    w32( 	biSizeImage);
    w32(  	biXPelsPerMeter);
    w32(  	biYPelsPerMeter);
    w32( 	biClrUsed);
    w32( 	biClrImportant);
    return true;
}
Esempio n. 7
0
u32 Mic::DMA(u32 Command,
	u32* buffer_in, u32 buffer_in_len,
	u32* buffer_out, u32& buffer_out_len)
{
	u8* buffer_out_b = (u8*)buffer_out;

	// Buffer overflow
	if (buffer_in_len > 8)
		return CommandUnknown;

	switch (Command)
	{
	case GetStatus:
		//functionality info
		w32(m_FuncType);
		w32(m_FuncDef[0]);
		w32(m_FuncDef[1]);
		w32(m_FuncDef[2]);
		w8(m_Region);
		w8(m_Direction);
		wString(m_strName, 30);
		wString(m_License, 60);
		w16(m_mAstandby);
		w16(m_mAmax);
		DEBUG_LOG("GetStatus\n");
		return DeviceInfo;

	case GetStatusAll:
		w32(m_FuncType);
		w32(m_FuncDef[0]);
		w32(m_FuncDef[1]);
		w32(m_FuncDef[2]);
		w8(m_Region);
		w8(m_Direction);
		wString(m_strName, 30);
		wString(m_License, 60);
		w16(m_mAstandby);
		w16(m_mAmax);
		wString(m_strNameEx, 172); // TODO verify
		DEBUG_LOG("GetStatusAll\n");
		return DeviceInfoEx;

	case GetCondition:
		return DataTransfer;

	default:
		printf("UNKNOWN MAPLE COMMAND %d (sent to %s)\n", Command, m_strName);
		return CommandUnknown;
	}
}
Esempio n. 8
0
void CPacket::blowfishPad()
{
	w32(0x00);

	int padding = WritePointer % 8;
	if (padding != 0)
	{
		for (int i = padding; i < 8; i++)
		{
			w8(0x00);
		}
	}
};
Esempio n. 9
0
bool    ADMMemioAvi::writeMainHeaderStruct(const MainAVIHeader &hdr)
{
    w32(dwMicroSecPerFrame);	// frame display rate (or 0L)
    w32(dwMaxBytesPerSec);	// max. transfer rate
    w32(dwPaddingGranularity);	// pad to multiples of this
					// size; normally 2K.
    w32(dwFlags);		// the ever-present flags
    w32(dwTotalFrames);		// # frames in file
    w32(dwInitialFrames);
    w32(dwStreams);
    w32(dwSuggestedBufferSize);

    w32(dwWidth);
    w32(dwHeight);

   
    write32(0);
    write32(0);
    write32(0);
    write32(0);
    return true;
}
Esempio n. 10
0
u32 Maxi::DMA(u32 Command,
			  u32* buffer_in, u32 buffer_in_len,
			  u32* buffer_out, u32& buffer_out_len)
{
	// Update the xpad the thread uses...
	EnterCriticalSection(&m_status.section);
	m_status.currentXPad = m_xpad;
	LeaveCriticalSection(&m_status.section);

	u8* buffer_out_b = (u8*)buffer_out;

	switch (Command)
	{
	case GetStatus:
		//functionality info
		w32(m_FuncType);
		w32(m_FuncDef[0]);
		w32(m_FuncDef[1]);
		w32(m_FuncDef[2]);
		w8(m_Region);
		w8(m_Direction);
		wString(m_strName, 30);
		wString(m_License, 60);
		w16(m_mAstandby);
		w16(m_mAmax);
		DEBUG_LOG("GetStatus\n");
		return DeviceInfo;

	case GetStatusAll:
		w32(m_FuncType);
		w32(m_FuncDef[0]);
		w32(m_FuncDef[1]);
		w32(m_FuncDef[2]);
		w8(m_Region);
		w8(m_Direction);
		wString(m_strName, 30);
		wString(m_License, 60);
		w16(m_mAstandby);
		w16(m_mAmax);
		wString(m_strNameEx, 40);
		DEBUG_LOG("GetStatusAll\n");
		return DeviceInfoEx;

	case GetCondition:
		// This command should return ALL vibration sources' settings. we only have one at the moment...
		w32(m_FuncType);
		w32(m_status.srcSettings.U32);
		DEBUG_LOG("GetCondition\n");
		//w32(purupuru_cond.srcSettings[VN].U32);
		return DataTransfer;

	case GetMediaInfo:
		{
			if (!m_status.srcSettings.VN) // there are no vibration sources?!?!
				return TransmitAgain;
			w32(m_FuncType);
			w32(m_status.srcSettings.U32);
			u8 source = (*(++buffer_in) & 0x000000FF);
			DEBUG_LOG("GetMediaInfo for source 0x%02x\n", source);
		}
		return DataTransfer;

	case BlockRead:
		if (*(++buffer_in) == 0) // It's not looking for waveform data
		{
			// Read back the AutoStop settings
			w32(m_FuncType);
			w32(0);			// VN(1), Phase(1), Block No.(2)
			w16(0x0200);	// ASR for VN 1
			w8(m_status.AST);
		}
		else
		{
			printf("BlockRead for waveform!\n");
			printf("REPORT THIS\n");
			return CommandUnknown;
		}
		return DataTransfer;

	case BlockWrite:
		{
			// GAH this can also be used to set auto stop time so we have to support it
			if (*(++buffer_in) == 0) // It's not trying to send waveform data
			{
				int numAST = (buffer_in_len-6)/4; // Doesn't include VN(1), Phase(1), Block Number(2), or ASR(2)
				// example ASR and AST (as the game sends): 0x000c0200
				buffer_in++;
				u16 ASR = (u16)*(buffer_in) & 0x0000FFFF; // don't swap ASR because I am lazy
				if (numAST == 1 && ASR == 0x0200) // yeah, we'll handle it
				{
					EnterCriticalSection(&m_status.section);
					m_status.AST = (*(buffer_in) & 0x00FF0000) >> 16;
					LeaveCriticalSection(&m_status.section);

					DEBUG_LOG("BlockWrite set AutoStop: %f seconds\n", m_status.AST * .25);
				}
				else
				{
					printf("BlockWrite set numAST: %i ASR: 0x%04x\n", numAST, ASR);
					printf("REPORT THIS\n");
					return TransmitAgain;
				}
			}
Esempio n. 11
0
bool    ADMMemioAvi::writeStreamHeaderStruct(const AVIStreamHeader &hdr)
{
    w32(	fccType);
	w32(	fccHandler);
	w32(	dwFlags);	/* Contains AVITF_* flags */
	w16(	wPriority);	/* dwPriority - splited for audio */
	w16(	wLanguage);
	w32(	dwInitialFrames);
	w32(	dwScale);
	w32(	dwRate);		/* dwRate / dwScale == samples/second */
	w32(	dwStart);
	w32(	dwLength);	/* In units above... */
	w32(	dwSuggestedBufferSize);
	w32(	dwQuality);
	w32(	dwSampleSize);
	w16( rcFrame.left);
    w16( rcFrame.top);
    w16( rcFrame.right);
    w16( rcFrame.bottom);
    return true;
}
Esempio n. 12
0
void port_monitor(void)
{
 unsigned long control,irq_status,status1,status2;
 unsigned int start_y=10;
 unsigned int user_in;

// clrscr();

 set_operational();

 w32(HcRhP1,0x00000102);
 w32(HcRhP2,0x00000102);
 w32(HcRhA,0x20000002);
 w32(HcRhB,0x00000000);
 w32(HcRhStatus,0x00010000);	//set Global Power

 do
 {
  control   =r32(HcControl);
  irq_status=r32(HcIntStatus);
  status1   =r32(HcRhP1);
  status2   =r32(HcRhP2);

  if((status1&0x00000001)==1)
  {
//   gotoxy(20,start_y+6);
   w32(HcRhP1,0x00000102);
   if((status1&0x00000200)!=0)
   {
	printf("LS Device connected to Port 1");
	set_port_speed(1,1);
   }
   else
   {
	printf("FS Device connected to Port 1");
	set_port_speed(1,0);
   }
  }

  else
  {
//   gotoxy(20,start_y+6);
   printf("                                      ");
  }

  if((status2&0x00000001)==1)
  {
//   gotoxy(20,start_y+7);
   w32(HcRhP2,0x00000102);
   if((status2&0x00000200)!=0)
   {
	printf("LS Device connected to Port 2");
	set_port_speed(2,1);
   }
   else
   {
	printf("FS Device connected to Port 2");
	set_port_speed(2,0);
   }
  }

  else
  {
//   gotoxy(20,start_y+7);
   printf("                                      ");
  }

//  gotoxy(20,start_y);
  printf("Port Status Monitor");
 // gotoxy(20,start_y-1);
  printf("OTGStatus  Register = %8X.\n",r16(0x67));
 // gotoxy(20,start_y+1);
  printf("OTGControl Register = %8X.\n",r16(0x62));
//  gotoxy(20,start_y+2);
  printf("Control    Register = %8lX.\n",control);
//  gotoxy(20,start_y+3);
  printf("Int Status Register = %8lX.\n",irq_status);
//  gotoxy(20,start_y+4);
  printf("P1  Status Register = %8lX.\n",status1);
//  gotoxy(20,start_y+5);
  printf("P2  Status Register = %8lX.\n",status2);
//  gotoxy(20,start_y+8);
  printf("Press '1' to go back to main menu\n");

  user_in='1';//read_key(0);
 }
 while(user_in!='1');
}
Esempio n. 13
0
unsigned int assign_address(unsigned int addr1, unsigned int addr2, int mode)
{
 unsigned long rhp1,rhp2;
 unsigned int status;
 unsigned int ccode=0;

 rhp1=r32(HcRhP1);
 rhp2=r32(HcRhP2);

 enable_port();

// gotoxy(1,5);

 if(mode==1)
 {
  printf("\nRhP1 = %8lX  RhP2 = %8lX",rhp1,rhp2);
  printf("\nPort1Speed = %2d",get_port_speed(1));
  printf("\nPort2Speed = %2d",get_port_speed(2));
 }

 if(  ((rhp1&0x01)==1)  &&  ((rhp2&0x01)==1)  )
 {
  if(mode==1)printf("\nBoth ports has USB device connected.");

  w32(HcRhP1,0x00000010); //Resets port 1
//  delay(500);
  w32(HcRhP2,0x00000010); //Resets port 2

  ccode=set_address(0,1,1);
  status=0x0100|(ccode<<12);

  enable_port();

//  delay(200);
  ccode=set_address(0,2,2);

  status=0x0001|(ccode<<4);
 }

 else if(  ((rhp1&0x01)==1)  &&  ((rhp2&0x01)==0)  )
 {
  if(mode==1)printf("\nPort 1 has USB device connected, assigning address 1...");
   ccode=set_address(0,1,1);

  status=0x0100|(ccode<<12);
 }

 else if(  ((rhp1&0x01)==0)  &&  ((rhp2&0x01)==1)  )
 {
  if(mode==1)printf("\nPort 2 has USB device connected, assigning address 2...");
   ccode=set_address(0,2,2);

  status=0x0001|(ccode<<4);
 }

 else
 {
  if(mode==1)printf("\nNo device connected to ISP1362, aborting enumeration...");

  status=0x0000;
 }

 return(status);
}
Esempio n. 14
0
	void ExecuteLoop(void)
	{
		static void *instbl[65536];
		static syntab syntbl[65536];
		static char littab[][20]={"","#1","#2","#4","CCR","SR","USP","","D%1d","A%1d","(A%1d)","(A%1d)+","-(A%1d)",
						"$%04x(A%1d)","$%02x(A%1d,%1s%1d)", "$%04x.W", "$%08x.L","$%04x(PC)","$%02x(PC,%1s%1d)" };
	
		static char OpCode[]="\0Invalid\0a_line\0abcd\0add.b\0add.l\0add.w\0adda.l\0adda.w\0addi.b\0addi.l\0addi.w\0addq.b\0addq.l\0addq.w\0addx.b\0addx.l\0addx.w\0and.b\0and.l\0and.w\0andi\0andi.b\0andi.l\0andi.w\0asl\0asl.b\0asl.l\0asl.w\0asr\0asr.b\0asr.l\0asr.w\0bcc.l\0bcc.s\0bcc_BAD\0bccc.s\0bchg\0bchg.s\0bclr\0bclr.s\0bcs.s\0beq.l\0beq.s\0bge.s\0bgt.s\0bhi.s\0ble.s\0bls.s\0blt.s\0bmi.s\0bne.l\0bne.s\0bpl.s\0bra.l\0bra.s\0bset\0bset.s\0bsr\0btst\0btst.s\0bvc.s\0bvs.s\0chk.w\0clr.b\0clr.l\0clr.w\0cmp.b\0cmp.l\0cmp.w\0cmpa.l\0cmpa.w\0cmpi.b\0cmpi.l\0cmpi.w\0cmpm.b\0cmpm.l\0cmpm.w\0dbcc\0dbcs\0dbeq\0dbf\0dbge\0dbgt\0dbhi\0dble\0dbls\0dblt\0dbmi\0dbne\0dbpl\0dbt\0dbvc\0dbvs\0divs.w\0divu.w\0eor.b\0eor.l\0eor.w\0eori\0eori.b\0eori.l\0eori.w\0exg_a\0exg_ad\0exg_d\0ext.l\0ext.w\0f_line\0illegal\0jmp\0jsr\0lea\0link\0lsl\0lsl.b\0lsl.l\0lsl.w\0lsr\0lsr.b\0lsr.l\0lsr.w\0move\0move.b\0move.l\0move.w\0movea.l\0movea.w\0movem.l\0movem.w\0movep.l\0movep.w\0moveq\0muls.w\0mulu.w\0nbcd\0neg.b\0neg.l\0neg.w\0negx.b\0negx.l\0negx.w\0nop\0not.b\0not.l\0not.w\0or.b\0or.l\0or.w\0ori\0ori.b\0ori.l\0ori.w\0pea\0reset\0rol\0rol.b\0rol.l\0rol.w\0ror\0ror.b\0ror.l\0ror.w\0roxl\0roxl.b\0roxl.l\0roxl.w\0roxr\0roxr.b\0roxr.l\0roxr.w\0rte\0rtr\0rts\0sCC\0sbcd\0scc\0scs\0seq\0sf\0sge\0sgt\0shi\0sle\0sls\0slt\0smi\0sne\0spl\0st\0stop\0sub.b\0sub.l\0sub.w\0s ubi.b\0subi.l\0subi.w\0subq.b\0subq.l\0subq.w\0subx.b\0subx.l\0subx.w\0svc\0svs\0swap\0tas\0trap\0trap#0\0trap#1\0trap#2\0trap#3\0trap#4\0trapv\0tst.b\0tst.l\0tst.w\0unlk\0\0";


		register void **itab;


	#if  1 /*MANYREGS*/
		#ifndef G_reg
			#ifdef NEW_AREG
				w32*  reg=g_reg;
			#else
				w32 *aReg=reg+8;
				w32* reg=aReg-8;
			#endif
		#endif
		w32 (**GetEA)(ashort) /*REGP1*/ = iexl_GetEA;
		rw8  (**GetFromEA_b)(void) = iexl_GetFromEA_b;
		rw16 (**GetFromEA_w)(void) = iexl_GetFromEA_w;
		rw32 (**GetFromEA_l)(void) = iexl_GetFromEA_l;
		void (**PutToEA_b)(ashort,aw8) /*REGP2*/ = iexl_PutToEA_b;
		void (**PutToEA_w)(ashort,aw16) /*REGP2*/ = iexl_PutToEA_w;
		void (**PutToEA_l)(ashort,aw32) /*REGP2*/ = iexl_PutToEA_l;
		Cond (**ConditionTrue)(void) = ll_ConditionTrue;

		w32 *theROM=ll_theROM;
	#else
		#define GetFromEA_b iexl_GetFromEA_b
		#define GetFromEA_w iexl_GetFromEA_w
		#define GetFromEA_l iexl_GetFromEA_l
		#define PutToEA_b iexl_PutToEA_b
		#define PutToEA_w iexl_PutToEA_w
		#define PutToEA_l iexl_PutToEA_l
	#endif

	code=0;   /* loop possibly sets only 16 bits ! */

	itab=instbl;
	
	#define IE_XL

	goto run_it; 
	
	/*#include "iexl_general.h"*/

	#include "instructions_ao.c"    /* include instructions */
	#include "instructions_pz.c"
	/*#include "iexl_ug.h"*/

	run_it:
	if (unlikely(!instbl_valid))
	  {
	#define IE_XL_II 
	#include "Init.c"
	    /*XSetTable(instbl);*/
	    instbl_valid=1;
	  }
	theROM=ll_theROM;
	ENTER_IEXL;                  /* load vars into regs etc .*/

	nextI: 
	if (likely(--nInst>=0))
	  {
	#ifdef TRACE
	    if (pc>=tracelo) DoTrace();
	#endif
	    /*DbgInfo();*/
	    
	#if defined(ASSGN_486)
	    goto *itab[ASSGN_486()];
	#else
	    goto *itab[ASSGN_CODE(RW(pc++))];
	#endif
	  } 
	
	#if 0
	if (regEmux)
	  {
	    nInst= (extraFlag ? 0 : reInst);     
	    vm_regemu();
 
	    goto nextI;
	  }
	#endif 

	if (doPoll) dosignal();

	if(extraFlag)
	  {
	    nInst=nInst2;
	    ExceptionProcessing();
	    if(nInst>0) goto nextI;
	  }
}
u32 FASTCALL ControllerDMA(void* device_instance, u32 Command,u32* buffer_in, u32 buffer_in_len, u32* buffer_out, u32& buffer_out_len)
{
	u8*buffer_out_b=(u8*)buffer_out;
	u32 port=((maple_device_instance*)device_instance)->port>>6;

	// Enabled check ain't necessary. Only the plugin's active ports are checked. :)
	// Update input information.
	GetJoyStatus(port);

	switch (Command)
	{
		case 1:		
		{												
			w32(1<<24);      //Controller function
			w32(0xFE060F00); //values a real dc controller returns
			w32(0);
			w32(0);	

			w8(0xFF); //1	area code ( 0xFF = all regions)			
			w8(0);    //1	connector direction , i think 0 means 'on top'

			wStrings(Joy_strName, Joy_strBrand); //30 and 60 chars respectively, pad with ' '						
									
			w16(0x01AE); // Standby current consumption			
			w16(0x01F4); // Maximum current consumption

			return 5; // 5 = Device Info.
		}		

		case 9:
		{			
			w32(1 << 24);	//its a reply about controller ;p
						
			// Set buttons
			u16 kcode = 0xFFFF;

			if( joystate[port].control[CTL_A_BUTTON] )	kcode ^= key_CONT_A;
			if( joystate[port].control[CTL_B_BUTTON] )	kcode ^= key_CONT_B;
			if( joystate[port].control[CTL_X_BUTTON] )	kcode ^= key_CONT_X;
			if( joystate[port].control[CTL_Y_BUTTON] )	kcode ^= key_CONT_Y;			
			if( joystate[port].control[CTL_START]    )	kcode ^= key_CONT_START;
												
			if( joystate[port].control[CTL_D_PAD_UP]    )	kcode ^= key_CONT_DPAD_UP;
			if( joystate[port].control[CTL_D_PAD_DOWN]  )	kcode ^= key_CONT_DPAD_DOWN;			
			if( joystate[port].control[CTL_D_PAD_LEFT]  )	kcode ^= key_CONT_DPAD_LEFT;			
			if( joystate[port].control[CTL_D_PAD_RIGHT] )	kcode ^= key_CONT_DPAD_RIGHT;								

			w16(kcode | 0xF901); //0xF901 -> buttons that are allways up on a dc
			
			// Set triggers		
			w8(joystate[port].control[CTL_R_SHOULDER]);										
			w8(joystate[port].control[CTL_L_SHOULDER]);				
	
			// Set Analog sticks (Main)
			w16(GetAnalog1(port));

			//x/y2 are missing on DC		
			w8(0x80); 			
			w8(0x80); 

			return 8;
		}		

		default:
			printf("PuruPuru -> UNKNOWN MAPLE COMMAND %d\n", Command);
			return 7;
	}
}
Esempio n. 16
0
//////////////////////////////////////////////////////////////////////////////////////////
// NAOMI JAMMA DMA
// ---------------
u32 FASTCALL ControllerDMA_NAOMI(void* device_instance,u32 Command,u32* buffer_in,u32 buffer_in_len,u32* buffer_out,u32& buffer_out_len)
{
	u8*buffer_out_b=(u8*)buffer_out;
	u8*buffer_in_b=(u8*)buffer_in;
	buffer_out_len=0;

	u16 kcode[4]={0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF};

	if(joysticks[0].enabled)
		GetJoyStatus(0);
	else
		memset(joystate[0].control, 0, sizeof(joystate[0].control));

	if(joysticks[1].enabled)	
		GetJoyStatus(1);
	else
		memset(joystate[1].control, 0, sizeof(joystate[1].control));

	switch (Command)
	{
	case 0x86:
		{
			u32 subcode=*(u8*)buffer_in;

			switch(subcode)
			{
			case 0x15:
			case 0x33:
				{
					buffer_out[0]=0xffffffff;
					buffer_out[1]=0xffffffff;					

					if(joystate[0].control[CTLN_SERVICE2] || 
					   joystate[1].control[CTLN_SERVICE2])	buffer_out[0]&=~(1<<0x1b);
					
					if(joystate[0].control[CTLN_TEST2] || 
					   joystate[1].control[CTLN_TEST2])		buffer_out[0]&=~(1<<0x1a);
					
					if(State.Mode==0 && subcode!=0x33)	//Get Caps
					{
						buffer_out_b[0x11+1]=0x8E;	//Valid data check
						buffer_out_b[0x11+2]=0x01;
						buffer_out_b[0x11+3]=0x00;
						buffer_out_b[0x11+4]=0xFF;
						buffer_out_b[0x11+5]=0xE0;
						buffer_out_b[0x11+8]=0x01;

						switch(State.Cmd)
						{
							//Reset, in : 2 bytes, out : 0
							case 0xF0:
								break;

							//Find nodes?
							//In addressing Slave address, in : 2 bytes, out : 1
							case 0xF1:
								{
									buffer_out_len=4*4;
								}
								break;

							//Speed Change, in : 2 bytes, out : 0
							case 0xF2:
								break;

							//Name
							//"In the I / O ID" "Reading each slave ID data"
							//"NAMCO LTD.; I / O PCB-1000; ver1.0; for domestic only, no analog input"
							//in : 1 byte, out : max 102
							case 0x10:
								{
									static char ID1[102]="nullDC Team; I/O Plugin-1; ver0.2; for nullDC or other emus";
									buffer_out_b[0x8+0x10]=(BYTE)strlen(ID1)+3;
									for(int i=0;ID1[i]!=0;++i)
									{
										buffer_out_b[0x8+0x13+i]=ID1[i];
									}
								}
								break;

							//CMD Version
							//REV in command|Format command to read the (revision)|One|Two 
							//in : 1 byte, out : 2 bytes
							case 0x11:
								{
									buffer_out_b[0x8+0x13]=0x13;
								}
								break;

							//JVS Version
							//In JV REV|JAMMA VIDEO standard reading (revision)|One|Two 
							//in : 1 byte, out : 2 bytes
							case 0x12:
								{
									buffer_out_b[0x8+0x13]=0x30;
								}
								break;

							//COM Version
							//VER in the communication system|Read a communication system compliant version of |One|Two
							//in : 1 byte, out : 2 bytes
							case 0x13:
								{
									buffer_out_b[0x8+0x13]=0x10;
								}
								break;

							//Features
							//Check in feature |Each features a slave to read |One |6 to
							//in : 1 byte, out : 6 + (?)
							case 0x14:
								{
									unsigned char *FeatPtr=buffer_out_b+0x8+0x13;
									buffer_out_b[0x8+0x9+0x3]=0x0;
									buffer_out_b[0x8+0x9+0x9]=0x1;
									#define ADDFEAT(Feature,Count1,Count2,Count3)	*FeatPtr++=Feature; *FeatPtr++=Count1; *FeatPtr++=Count2; *FeatPtr++=Count3;
									ADDFEAT(1,2,12,0);	//Feat 1=Digital Inputs.  2 Players. 10 bits
									ADDFEAT(2,2,0,0);	//Feat 2=Coin inputs. 2 Inputs
									ADDFEAT(3,2,0,0);	//Feat 3=Analog. 2 Chans

									ADDFEAT(0,0,0,0);	//End of list
								}
								break;

							default:
								printf("unknown CAP %X\n",State.Cmd);
							return 0;
						}
						buffer_out_len=4*4;
					}
					else if(State.Mode==1 || State.Mode==2 || subcode==0x33)	//Get Data
					{
						unsigned char glbl=0x00;
						unsigned char p1_1=0x00;
						unsigned char p1_2=0x00;
						unsigned char p2_1=0x00;
						unsigned char p2_2=0x00;	
						static unsigned char LastKey[256];
						static unsigned short coin1=0x0000;
						static unsigned short coin2=0x0000;	
						
						if(joystate[0].control[CTLN_TEST1] || 
						   joystate[1].control[CTLN_TEST1])   glbl|=0x80;

						if(joystate[0].control[CTLN_SERVICE1])	  p1_1|=0x40;																										
						if(joystate[0].control[CTLN_START])   p1_1|=0x80; 
						
						if(joystate[0].control[CTLN_D_UP]   ) p1_1|=0x20;
						if(joystate[0].control[CTLN_D_DOWN] ) p1_1|=0x10;
						if(joystate[0].control[CTLN_D_LEFT] ) p1_1|=0x08;
						if(joystate[0].control[CTLN_D_RIGHT]) p1_1|=0x04;						
												
						if(joystate[0].control[CTLN_BUTTON1]) p1_1|=0x02;
						if(joystate[0].control[CTLN_BUTTON2]) p1_1|=0x01;
						if(joystate[0].control[CTLN_BUTTON3]) p1_2|=0x80;
						if(joystate[0].control[CTLN_BUTTON4]) p1_2|=0x40;																			
						if(joystate[0].control[CTLN_BUTTON5]) p1_2|=0x20;
						if(joystate[0].control[CTLN_BUTTON6]) p1_2|=0x10;

						// Player 2
						if(joystate[1].control[CTLN_SERVICE1])	  p2_1|=0x40;																										
						if(joystate[1].control[CTLN_START])   p2_1|=0x80; 
						
						if(joystate[1].control[CTLN_D_UP]   ) p2_1|=0x20;
						if(joystate[1].control[CTLN_D_DOWN] ) p2_1|=0x10;
						if(joystate[1].control[CTLN_D_LEFT] ) p2_1|=0x08;
						if(joystate[1].control[CTLN_D_RIGHT]) p2_1|=0x04;						
												
						if(joystate[1].control[CTLN_BUTTON1]) p2_1|=0x02;
						if(joystate[1].control[CTLN_BUTTON2]) p2_1|=0x01;
						if(joystate[1].control[CTLN_BUTTON3]) p2_2|=0x80;
						if(joystate[1].control[CTLN_BUTTON4]) p2_2|=0x40;																			
						if(joystate[1].control[CTLN_BUTTON5]) p2_2|=0x20;
						if(joystate[1].control[CTLN_BUTTON6]) p2_2|=0x10;
							
						static bool old_coin1 = false;
						static bool old_coin2 = false;

						if(!old_coin1 && joystate[0].control[CTLN_COIN]) // Coin key
						{
							coin1++;
							old_coin1 = true;
						}	
						else if(old_coin1 && !joystate[0].control[CTLN_COIN]) // Coin key
							old_coin1 = false;
						
						if(!old_coin2 && joystate[1].control[CTLN_COIN]) // Coin key
						{
							coin2++;
							old_coin2 = true;
						}
						else if(old_coin2 && !joystate[1].control[CTLN_COIN]) // Coin key													
							old_coin2 = false;
						

						buffer_out_b[0x11+0]=0x00;
						buffer_out_b[0x11+1]=0x8E;	//Valid data check
						buffer_out_b[0x11+2]=0x01;
						buffer_out_b[0x11+3]=0x00;
						buffer_out_b[0x11+4]=0xFF;
						buffer_out_b[0x11+5]=0xE0;
						buffer_out_b[0x11+8]=0x01;

						//memset(OutData+8+0x11,0x00,0x100);

						buffer_out_b[8+0x12+0]=1;
						buffer_out_b[8+0x12+1]=glbl;
						buffer_out_b[8+0x12+2]=p1_1;
						buffer_out_b[8+0x12+3]=p1_2;						
						buffer_out_b[8+0x12+4]=p2_1;
						buffer_out_b[8+0x12+5]=p2_2;	
						buffer_out_b[8+0x12+6]=1;
						buffer_out_b[8+0x12+7]=coin1>>8;
						buffer_out_b[8+0x12+8]=coin1&0xff;						
						buffer_out_b[8+0x12+9]=coin2>>8;
						buffer_out_b[8+0x12+10]=coin2&0xff;						
						buffer_out_b[8+0x12+11]=1;
						buffer_out_b[8+0x12+12]=0x00;
						buffer_out_b[8+0x12+13]=0x00;
						buffer_out_b[8+0x12+14]=0x00;
						buffer_out_b[8+0x12+15]=0x00;
						buffer_out_b[8+0x12+16]=0x00;
						buffer_out_b[8+0x12+17]=0x00;
						buffer_out_b[8+0x12+18]=0x00;
						buffer_out_b[8+0x12+19]=0x00;
						buffer_out_b[8+0x12+20]=0x00;						

						if(State.Mode==1)
						{
							buffer_out_b[0x11+0x7]=19;
							buffer_out_b[0x11+0x4]=19+5;
						}
						else
						{
							buffer_out_b[0x11+0x7]=17;
							buffer_out_b[0x11+0x4]=17-1;
						}

						//OutLen=8+0x11+16;
						buffer_out_len=8+0x12+20;
					}
				}
				return 8;
					
			case 0x17:	//Select Subdevice
				{
					State.Mode=0;
					State.Cmd=buffer_in_b[8];
					State.Node=buffer_in_b[9];
					buffer_out_len=0;
				}
				return (7);
				
			case 0x27:	//Transfer request
				{
					State.Mode=1;
					State.Cmd=buffer_in_b[8];
					State.Node=buffer_in_b[9];
					buffer_out_len=0;
				}
				return (7);
			case 0x21:		//Transfer request with repeat
				{
					State.Mode=2;
					State.Cmd=buffer_in_b[8];
					State.Node=buffer_in_b[9];
					buffer_out_len=0;
				}
				return (7);

			case 0x0B:	//EEPROM write
				{
					int address=buffer_in_b[1];
					int size=buffer_in_b[2];
					//printf("EEprom write %08X %08X\n",address,size);
					//printState(Command,buffer_in,buffer_in_len);
					memcpy(EEPROM+address,buffer_in_b+4,size);

					wchar eeprom_file[512];
					host.ConfigLoadStr(L"emu",L"gamefile",eeprom_file,L"");
					wcscat_s(eeprom_file,L".eeprom");
					FILE* f;
					_wfopen_s(&f,eeprom_file,L"wb");
					if (f)
					{
						fwrite(EEPROM,1,0x80,f);
						fclose(f);
						wprintf(L"SAVED EEPROM to %s\n",eeprom_file);
					}
				}
				return (7);
			case 0x3:	//EEPROM read
				{
					if (!EEPROM_loaded)
					{
						EEPROM_loaded=true;
						wchar eeprom_file[512];
						host.ConfigLoadStr(L"emu",L"gamefile",eeprom_file,L"");
						wcscat_s(eeprom_file,L".eeprom");
						FILE* f;
						_wfopen_s(&f,eeprom_file,L"rb");
						if (f)
						{
							fread(EEPROM,1,0x80,f);
							fclose(f);
							wprintf(L"LOADED EEPROM from %s\n",eeprom_file);
						}
					}
					//printf("EEprom READ ?\n");
					int address=buffer_in_b[1];
					//printState(Command,buffer_in,buffer_in_len);
					memcpy(buffer_out,EEPROM+address,0x80);
					buffer_out_len=0x80;
				}
				return 8;
				//IF I return all FF, then board runs in low res
			case 0x31:
				{
					buffer_out[0]=0xffffffff;
					buffer_out[1]=0xffffffff;
				}
				return (8);
								
			default:
				printf("PuruPuru => Unknown 0x86: Sub 0x%X - State: 0x%X Mode: 0x%X Node: 0x%X\n",subcode,State.Cmd,State.Mode,State.Node);
				printState(Command,buffer_in,buffer_in_len);
			}

			return 8;//MAPLE_RESPONSE_DATATRF
		}
		break;
	case 0x82:
		{
			const char *ID="315-6149    COPYRIGHT SEGA E\x83\x00\x20\x05NTERPRISES CO,LTD.  ";
			memset(buffer_out_b,0x20,256);
			memcpy(buffer_out_b,ID,0x38-4);
			buffer_out_len=256;
			return (0x83);
		}
	/*typedef struct {
		DWORD		func;//4
		DWORD		function_data[3];//3*4
		u8		area_code;//1
		u8		connector_direction;//1
		char		product_name[30];//30*1
		char		product_license[60];//60*1
		WORD		standby_power;//2
		WORD		max_power;//2
	} maple_devinfo_t;*/
	case 1: 
		{			
			w32(1 << 24); // Caps						
			w32( 0xfe060f00); //struct data
			w32( 0);
			w32( 0);			
			w8(0xFF); //1	area code
			
			w8(0); //1	direction
			
			wStrings(Joy_strName, Joy_strBrand_2);
			
			//ptr_out += 60;			
			w16(0xAE01); //2			
			w16(0xF401); //2
		}
		return 5;

	case 9:
		{
			w32(1 << 24); //struct data
						
			w16(kcode[0] | 0xF901); //2
							
			w8(0x0); //triggers
			w8(0x0); 
						
			w8(0x80); // Analog XY
			w8(0x80); 
						
			w8(0x80); // XY2
			w8(0x80); 

			//are these needed ?
			//1
			//WriteMem8(ptr_out, 10); ptr_out += 1;
			//1
			//WriteMem8(ptr_out, 10); ptr_out += 1;
		}
		return 8;

	default:
		printf("PuruPuru => unknown MAPLE Frame: ");
		printState(Command,buffer_in,buffer_in_len);
		return 7;		
	}