Ejemplo n.º 1
0
void update_pif_write()
{
   int i=0, channel=0;
#ifdef DEBUG_PIF
   printf("write\n");
   print_pif();
#endif
   if (PIF_RAMb[0x3F] > 1)
     {
	switch (PIF_RAMb[0x3F])
	  {
	   case 0x02:
	     for (i=0; i<sizeof(pif2_lut)/32; i++)
	       {
		  if (!memcmp(PIF_RAMb + 64-2*8, pif2_lut[i][0], 16))
		    {
		       memcpy(PIF_RAMb + 64-2*8, pif2_lut[i][1], 16);
		       return;
		    }
	       }
	     printf("unknown pif2 code:\n");
	     for (i=(64-2*8)/8; i<(64/8); i++)
	       printf("%x %x %x %x | %x %x %x %x\n",
		      PIF_RAMb[i*8+0], PIF_RAMb[i*8+1],PIF_RAMb[i*8+2], PIF_RAMb[i*8+3],
		      PIF_RAMb[i*8+4], PIF_RAMb[i*8+5],PIF_RAMb[i*8+6], PIF_RAMb[i*8+7]);
	     break;
	   case 0x08:
	     PIF_RAMb[0x3F] = 0;
	     break;
	   default:
	     printf("error in update_pif_write : %x\n", PIF_RAMb[0x3F]);
	  }
	return;
     }
   while (i<0x40)
     {
	switch(PIF_RAMb[i])
	  {
	   case 0x00:
	     channel++;
	     if (channel > 6) i=0x40;
	     break;
	   case 0xFF:
	     break;
	   default:

	     if (!(PIF_RAMb[i] & 0xC0))
	       {
		  if (channel < 4)
		    {
		       if (Controls[channel].Present && 
			   Controls[channel].RawData)
			 controllerCommand(channel, &PIF_RAMb[i]);
		       else
			 internal_ControllerCommand(channel, &PIF_RAMb[i]);
		    }
		  else if (channel == 4)
		    EepromCommand(&PIF_RAMb[i]);
		  else
		    printf("channel >= 4 in update_pif_write\n");
		  i += PIF_RAMb[i] + (PIF_RAMb[(i+1)] & 0x3F) + 1;
		  channel++;
	       }
	     else
	       i=0x40; 
	  }
	i++;
     }
 
   //PIF_RAMb[0x3F] = 0;
   controllerCommand(-1, NULL);
#ifdef DEBUG_PIF
   print_pif();
#endif
}
Ejemplo n.º 2
0
void PifRamWrite (void) {
	int Channel, CurPos;

	Channel = 0;

	if( PIF_Ram[0x3F] > 0x1) { 
		switch (PIF_Ram[0x3F]) {
		case 0x08: 
			PIF_Ram[0x3F] = 0; 
			MI_INTR_REG |= MI_INTR_SI;
			SI_STATUS_REG |= SI_STATUS_INTERRUPT;
			CheckInterrupts();
			break;
		case 0x10:
			memset(PifRom,0,0x7C0);
			break;
		case 0x30:
			PIF_Ram[0x3F] = 0x80;		
			break;
		case 0xC0:
			memset(PIF_Ram,0,0x40);
			break;
		default:
			if (ShowPifRamErrors) { DisplayError("Unkown PifRam control: %d",PIF_Ram[0x3F]); }
		}
		return;
	}

	for (CurPos = 0; CurPos < 0x40; CurPos++){
		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 (ControllerCommand) { ControllerCommand(Channel,&PIF_Ram[CurPos]); }
					} else {
						ProcessControllerCommand(Channel,&PIF_Ram[CurPos]);
					}
				} else if (Channel == 4) {
					EepromCommand(&PIF_Ram[CurPos]);
				} else {
#ifndef EXTERNAL_RELEASE
					DisplayError("Command on channel 5?");
#endif
				}
				CurPos += PIF_Ram[CurPos] + (PIF_Ram[CurPos + 1] & 0x3F) + 1;
				Channel += 1;
			} else {
				if (ShowPifRamErrors) { DisplayError("Unknown Command in PifRamWrite(%X)",PIF_Ram[CurPos]); }
				CurPos = 0x40;
			}
			break;
		}
	}
	PIF_Ram[0x3F] = 0;
	if (ControllerCommand) { ControllerCommand(-1,NULL); }
}