Beispiel #1
0
/**
 * control_update:  Update the current controller status.
 *
 * [Parameters]
 *     None
 * [Return value]
 *     None
 */
void control_update(void)
{
    SceCtrlData pad_data;
    sceCtrlPeekBufferPositive(&pad_data, 1);

    last_buttons = buttons;
    buttons = pad_data.Buttons;

    /* If the directional pad isn't being used, check the analog pad instead */
    if (!(buttons & 0x00F0)) {
        if (pad_data.Lx < 32) {
            buttons |= PSP_CTRL_LEFT;
        } else if (pad_data.Lx >= 224) {
            buttons |= PSP_CTRL_RIGHT;
        }
        if (pad_data.Ly < 32) {
            buttons |= PSP_CTRL_UP;
        } else if (pad_data.Ly >= 224) {
            buttons |= PSP_CTRL_DOWN;
        }
    }

    /* The OS doesn't seem to reset the screensaver timeout when the
     * analog pad is moved, so take care of that ourselves */
    if (pad_data.Lx < 32 || pad_data.Lx >= 224
     || pad_data.Ly < 32 || pad_data.Ly >= 224
    ) {
        scePowerTick(0);
    }
}
Beispiel #2
0
void frame_start(void)
{
	scePowerTick(0);
	sceDisplayWaitVblank();
	proDebugScreenSetOffset((int)get_drawing_buffer() - 0x44000000);
	memset(get_drawing_buffer(), 0, 512*272*4);
}
Beispiel #3
0
int T_Decoder(SceSize _args, void *_argp)
{
	int retVal;
	int oldButtons = 0;
	SceCtrlData pad;
#if DEBUG_TIMING
	int start, end;
	char s[200];
#endif

	int iInitAudio = 1;
	SceInt32 iVideoStatus = 0;
	int videoFrameCount = 0;
	int audioFrameCount = 0;

	SceInt32 unknown = 0;

	int iThreadsRunning = 0;

	SceInt32 m_iAudioCurrentTimeStamp = 0;
	SceInt32 m_iVideoCurrentTimeStamp = 0;
	SceInt32 m_iVideoLastTimeStamp = 0;

	DecoderThreadData* D = *((DecoderThreadData**)_argp);

	SceUInt32 m_iLastPacketsWritten = D->Reader->m_Ringbuffer->iUnk1;
	SceInt32  m_iLastPacketsAvailable = sceMpegRingbufferAvailableSize(D->Reader->m_Ringbuffer);

	D->Connector->initConnector();

	for(;;)
	{
		sceKernelDelayThread(1);

		scePowerTick(0);

		sceCtrlReadBufferPositive(&pad, 1);
		int buttonDown = (oldButtons ^ pad.Buttons) & pad.Buttons;

		if (buttonDown & PSP_CTRL_CIRCLE)
		{
			break;
		}

		if( iThreadsRunning == 0 &&
			IsRingbufferFull(D->Reader) &&
			D->Video->m_iNumBuffers == D->Video->m_iFullBuffers)
		{
			iThreadsRunning = 1;
			sceKernelSignalSema(D->Video->m_SemaphoreStart, 1);
			sceKernelSignalSema(D->Audio->m_SemaphoreStart, 1);
		}

		if(D->Reader->m_Status == ReaderThreadData::READER_ABORT)
		{
			break;
		}
		else if(D->Reader->m_Status == ReaderThreadData::READER_EOF)
		{
			retVal = sceMpegRingbufferAvailableSize(D->Reader->m_Ringbuffer);

			if(retVal == D->Reader->m_RingbufferPackets)
				break;
		}

		if(!IsRingbufferFull(D->Reader))
		{
			sceKernelWaitSema(D->Reader->m_Semaphore, 1, 0);

			if(D->Reader->m_Status == ReaderThreadData::READER_ABORT)
				break;
		}

		if (DEBUG_USERDATA)
		{
			SceInt32 unknown2[2];
			SceUInt32 i;
			unknown2[0] = 0x12345678;
			unknown2[1] = 0xABCDEF98;
			retVal = sceMpegGetUserdataAu(&D->m_Mpeg, D->m_MpegStreamUserdata, D->m_MpegAuUserdata, unknown2);

			u8 *esBuffer = (u8 *) D->m_MpegAuUserdata->iEsBuffer;
			SceUInt32 esSize = D->m_MpegAuUserdata->iAuSize;

			sprintf(s, "sceMpegGetUserdataAu result 0x%08X", retVal);
			debug(s);

			if (retVal == 0)
			{
				sprintf(s, "sceMpegGetUserdataAu unknown[0]=0x%08X, unknown[1]=0x%08X, esBuffer=0x%08X, esSize=0x%X", unknown2[0], unknown2[1], D->m_MpegAuUserdata->iEsBuffer, esSize);
				debug(s);
				debug(D->m_MpegAuUserdata);
				for (i = 0; i < esSize; i += 8)
				{
					sprintf(s, "0x%08X: %02X %02X %02X %02X %02X %02X %02X %02X", D->m_MpegAuUserdata->iEsBuffer + i, esBuffer[i], esBuffer[i+1], esBuffer[i+2], esBuffer[i+3], esBuffer[i+4], esBuffer[i+5], esBuffer[i+6], esBuffer[i+7]);
					debug(s);
				}
			}
		}

		if(D->Audio->m_iFullBuffers < D->Audio->m_iNumBuffers)
		{
#if DEBUG_TIMING
			start = sceKernelGetSystemTimeLow();
#endif
			retVal = sceMpegGetAtracAu(&D->m_Mpeg, D->m_MpegStreamAtrac, D->m_MpegAuAtrac, &unknown);
#if DEBUG_TIMING
			end = sceKernelGetSystemTimeLow();
			sprintf(s, "Duration sceMpegGetAtracAu %d, return %X, presentation timeStamp %d (%d), decode timeStamp %d", end - start, retVal, D->m_MpegAuAtrac->iPts, m_iAudioCurrentTimeStamp + D->m_iAudioFrameDuration, D->m_MpegAuAtrac->iDts);
			debug(s);
			debug(D->m_MpegAuAtrac);
			debug(D->Reader->m_Ringbuffer);
#endif
			if(retVal != 0)
			{
				if(!IsRingbufferFull(D->Reader))
				{
					sceKernelWaitSema(D->Reader->m_Semaphore, 1, 0);

					if(D->Reader->m_Status == ReaderThreadData::READER_ABORT)
						break;
				}
			}
			else
			{
				if(m_iAudioCurrentTimeStamp >= D->m_iLastTimeStamp - D->m_iVideoFrameDuration)
					break;

#if DEBUG_TIMING
				start = sceKernelGetSystemTimeLow();
#endif
				retVal = sceMpegAtracDecode(&D->m_Mpeg, D->m_MpegAuAtrac, D->Audio->m_pAudioBuffer[D->Audio->m_iDecodeBuffer], iInitAudio);
#if DEBUG_TIMING
				end = sceKernelGetSystemTimeLow();
				sprintf(s, "Duration sceMpegAtracDecode %d, return %X", end - start, retVal);
				debug(s);
				debug(D->Reader->m_Ringbuffer);
#endif
				if(retVal != 0)
				{
					sprintf(D->m_LastError, "sceMpegAtracDecode() failed: 0x%08X", retVal);
					break;
				}

				if(D->m_MpegAuAtrac->iPts == 0xFFFFFFFF)
					m_iAudioCurrentTimeStamp += D->m_iAudioFrameDuration;
				else
					m_iAudioCurrentTimeStamp = D->m_MpegAuAtrac->iPts;

				if(m_iAudioCurrentTimeStamp <= 0x15F90 /* video start ts */ - D->m_iAudioFrameDuration)
					iInitAudio = 1;

				D->Audio->m_iBufferTimeStamp[D->Audio->m_iDecodeBuffer] = m_iAudioCurrentTimeStamp;

				if(iInitAudio == 0)
				{
					D->Connector->sendAudioFrame(audioFrameCount, D->Audio->m_pAudioBuffer[D->Audio->m_iDecodeBuffer], D->m_MpegAtracOutSize, m_iAudioCurrentTimeStamp);
					audioFrameCount++;

					sceKernelWaitSema(D->Audio->m_SemaphoreLock, 1, 0);

					D->Audio->m_iFullBuffers++;

					sceKernelSignalSema(D->Audio->m_SemaphoreLock, 1);

					D->Audio->m_iDecodeBuffer = (D->Audio->m_iDecodeBuffer + 1) % D->Audio->m_iNumBuffers;
				}

				iInitAudio = 0;
			}
		}

		if(!IsRingbufferFull(D->Reader))
		{
			sceKernelWaitSema(D->Reader->m_Semaphore, 1, 0);

			if(D->Reader->m_Status == ReaderThreadData::READER_ABORT)
				break;
		}

		if(D->Video->m_iFullBuffers < D->Video->m_iNumBuffers)
		{
#if DEBUG_TIMING
			start = sceKernelGetSystemTimeLow();
#endif
			retVal = sceMpegGetAvcAu(&D->m_Mpeg, D->m_MpegStreamAVC, D->m_MpegAuAVC, &unknown);
#if DEBUG_TIMING
			end = sceKernelGetSystemTimeLow();
			sprintf(s, "Duration sceMpegGetAvcAu %d, return %X, presentation timeStamp %d (%d), decode timeStamp %d", end - start, retVal, D->m_MpegAuAVC->iPts, m_iVideoCurrentTimeStamp + 3004, D->m_MpegAuAVC->iDts);
			debug(s);
			debug(D->m_MpegAuAVC);
			debug(D->Reader->m_Ringbuffer);
#endif
			if((SceUInt32)retVal == 0x80618001)
			{
				if(!IsRingbufferFull(D->Reader))
				{
					sceKernelWaitSema(D->Reader->m_Semaphore, 1, 0);

					if(D->Reader->m_Status == ReaderThreadData::READER_ABORT)
						break;
				}
			}
			else if(retVal != 0)
			{
				sprintf(D->m_LastError, "sceMpegGetAvcAu() failed: 0x%08X", retVal);
				break;
			}
			else
			{
				if(m_iVideoCurrentTimeStamp >= D->m_iLastTimeStamp - D->m_iVideoFrameDuration)
					break;

#if DEBUG_TIMING
				start = sceKernelGetSystemTimeLow();
#endif
				retVal = sceMpegAvcDecode(&D->m_Mpeg, D->m_MpegAuAVC, BUFFER_WIDTH, &D->Video->m_pVideoBuffer[D->Video->m_iPlayBuffer], &iVideoStatus);
#if DEBUG_TIMING
				end = sceKernelGetSystemTimeLow();
				sprintf(s, "Duration sceMpegAvcDecode %d, return %X", end - start, retVal);
				debug(s);
				debug(D->Reader->m_Ringbuffer);
#endif
				if(retVal != 0)
				{
					sprintf(D->m_LastError, "sceMpegAvcDecode() failed: 0x%08X", retVal);
					break;
				}

				if(D->m_MpegAuAVC->iPts == 0xFFFFFFFF)
					m_iVideoCurrentTimeStamp += 0x0BBC;
				else
					m_iVideoCurrentTimeStamp = D->m_MpegAuAVC->iPts;

				if(iVideoStatus == 1)
				{
					SceUInt32 m_iPacketsWritten = D->Reader->m_Ringbuffer->iUnk1;
					SceInt32  m_iPacketsAvailable = sceMpegRingbufferAvailableSize(D->Reader->m_Ringbuffer);

					SceInt32  m_iDeltaPacketsWritten = m_iPacketsWritten - m_iLastPacketsWritten;
					if (m_iDeltaPacketsWritten < 0)
					{
						m_iDeltaPacketsWritten += D->Reader->m_Ringbuffer->iPackets;
					}
					SceInt32 m_iDeltaPacketsAvailable = m_iPacketsAvailable - m_iLastPacketsAvailable;
					SceInt32 m_iConsumedPackets = m_iDeltaPacketsAvailable + m_iDeltaPacketsWritten;

					m_iLastPacketsWritten = m_iPacketsWritten;
					m_iLastPacketsAvailable = m_iPacketsAvailable;

					D->Connector->sendVideoFrame(videoFrameCount, D->Video->m_pVideoBuffer[D->Video->m_iPlayBuffer], m_iVideoCurrentTimeStamp, D->Reader, m_iConsumedPackets);
					videoFrameCount++;

					D->Video->m_iBufferTimeStamp[D->Video->m_iPlayBuffer] = m_iVideoLastTimeStamp;

					sceKernelWaitSema(D->Video->m_SemaphoreLock, 1, 0);

					D->Video->m_iFullBuffers++;

					sceKernelSignalSema(D->Video->m_SemaphoreLock, 1);
				}

				m_iVideoLastTimeStamp = m_iVideoCurrentTimeStamp;
			}
		}

		if(!IsRingbufferFull(D->Reader))
		{
			sceKernelWaitSema(D->Reader->m_Semaphore, 1, 0);

			if(D->Reader->m_Status == ReaderThreadData::READER_ABORT)
				break;
		}

	}

	D->Connector->exitConnector();

	sceKernelSignalSema(D->Audio->m_SemaphoreStart, 1);
	sceKernelSignalSema(D->Video->m_SemaphoreStart, 1);

	D->Reader->m_Status = ReaderThreadData::READER_ABORT;

	D->Audio->m_iAbort = 1;

	while(D->Video->m_iFullBuffers > 0)
	{
		sceKernelWaitSema(D->Video->m_SemaphoreWait, 1, 0);
		sceKernelSignalSema(D->Video->m_SemaphoreLock, 1);
	}

	sceMpegAvcDecodeStop(&D->m_Mpeg, BUFFER_WIDTH, D->Video->m_pVideoBuffer, &iVideoStatus);

	if(iVideoStatus > 0)
	{
		sceKernelWaitSema(D->Video->m_SemaphoreLock, 1, 0);

		D->Video->m_iFullBuffers++;

		sceKernelSignalSema(D->Video->m_SemaphoreLock, 1);
	}

	D->Video->m_iAbort = 1;

	sceMpegFlushAllStream(&D->m_Mpeg);

	sceKernelExitThread(0);

	return 0;
}
static int lua_powerTick(lua_State *L)
{
    if (lua_gettop(L) != 0) return luaL_error(L, "System.powerTick() takes no arguments");
    scePowerTick(0);
    return 0;
}
Beispiel #5
0
static void pmp_input(volatile struct pmp_play_struct *p, SceCtrlData *previous_controller)
	{
	scePowerTick(0);


	SceCtrlData controller;
	sceCtrlReadBufferPositive(&controller, 1);
	if(1)
		{
		if (((controller.Buttons & PSP_CTRL_TRIANGLE) == 0) && (previous_controller->Buttons & PSP_CTRL_TRIANGLE))
			{
			p->return_request = 1;
			//add by cooleyes 2007/01/16
			p->return_result = "exit: manual";
			//add end
			}
		else
			{
			if (p->paused == 1)
				{
				p->seek = 0;

				if ((controller.Buttons & PSP_CTRL_SQUARE) && ((previous_controller->Buttons & PSP_CTRL_SQUARE) == 0))
					{
					p->paused = 0;
					}
				else if ((controller.Buttons & PSP_CTRL_CIRCLE) && ((previous_controller->Buttons & PSP_CTRL_CIRCLE) == 0)) 
					{
					make_screenshot();
					}
				}
			else
				{
				if (controller.Buttons & PSP_CTRL_CROSS)
					{
					if (controller.Buttons & PSP_CTRL_RIGHT)
						{
						p->seek = 2;
						}
					else if (controller.Buttons & PSP_CTRL_LEFT)
						{
						p->seek = -2;
						}
					else
						{
						p->seek = 0;

						if ((controller.Buttons & PSP_CTRL_UP) && ((previous_controller->Buttons & PSP_CTRL_UP) == 0))
							{
							if (p->zoom != 200)
								{
								p->zoom += 5;
								}
							}
						else if ((controller.Buttons & PSP_CTRL_DOWN) && ((previous_controller->Buttons & PSP_CTRL_DOWN) == 0))
							{
							if (p->zoom != 100)
								{
								p->zoom -= 5;
								}
							}
						else if ((controller.Buttons & PSP_CTRL_RTRIGGER) && ((previous_controller->Buttons & PSP_CTRL_RTRIGGER) == 0))
							{
							if (p->loop == 0)
								{
								p->loop = 1;
								}
							else
								{
								p->loop = 0;
								}
							}
						else if ((controller.Buttons & PSP_CTRL_LTRIGGER) && ((previous_controller->Buttons & PSP_CTRL_LTRIGGER) == 0))
							{
							if (p->subtitle_count)
								{
								p->subtitle = (p->subtitle + 1)%(p->subtitle_count+1);
								if (p->subtitle)
									snprintf(info_string,512,"[i]%s[/i]", subtitle_parser[p->subtitle-1].filename);
								else
									snprintf(info_string,512,"[i]no subtitle[/i]");
								info_count = 60;
								}
							}
						//remove by cooleyes 2007/02/01
						/*/
						else if ((controller.Buttons & PSP_CTRL_SELECT) && ((previous_controller->Buttons & PSP_CTRL_SELECT) == 0))
							{
							p->subtitle_format ^= 1;
							if (p->subtitle_format)
								snprintf(info_string,512,"[i]UTF-8[/i]");
							else
								snprintf(info_string,512,"[i]ASCII[/i]");
							info_count = 60;
							}
						//*/
						//remove end
						else if ((controller.Buttons & PSP_CTRL_SQUARE) && ((previous_controller->Buttons & PSP_CTRL_SQUARE) == 0))
							{
							p->subtitle_fontcolor = (p->subtitle_fontcolor+1)%NUMBER_OF_FONTCOLORS;
							gu_font_color_set( FONTCOLORS[p->subtitle_fontcolor] );
							}
						else if ((controller.Buttons & PSP_CTRL_CIRCLE) && ((previous_controller->Buttons & PSP_CTRL_CIRCLE) == 0))
							{
							p->subtitle_bordercolor = (p->subtitle_bordercolor+1)%NUMBER_OF_BORDERCOLORS;
							gu_font_border_color_set( BORDERCOLORS[p->subtitle_bordercolor] );
							}
						//add by cooleyes 2007/02/01
						else if ((controller.Buttons & PSP_CTRL_SELECT) && ((previous_controller->Buttons & PSP_CTRL_SELECT) == 0))
							{
							if(p->audio_channel > -1)
								{
								p->audio_channel--;
								}
							else
								{
								p->audio_channel = 1;
								}
							}
						//add end
						else if ((controller.Buttons & PSP_CTRL_START) && ((previous_controller->Buttons & PSP_CTRL_START) == 0)) 
							{
							gu_lcd_output_inversion_set();
							}
						}
					}
				else if ((controller.Buttons & PSP_CTRL_SQUARE) && ((previous_controller->Buttons & PSP_CTRL_SQUARE) == 0))
					{
					p->paused = 1;
					p->seek   = 0;
					}
				else if (controller.Buttons & PSP_CTRL_RIGHT)
					{
					p->seek = 1;
					}
				else if (controller.Buttons & PSP_CTRL_LEFT)
					{
					p->seek = -1;
					}
				else if ((controller.Buttons & PSP_CTRL_SELECT) && ((previous_controller->Buttons & PSP_CTRL_SELECT) == 0))
					{
					if (p->audio_stream + 1 == p->decoder.reader.file.header.audio.number_of_streams)
						{
						p->audio_stream = 0;
						}
					else
						{
						p->audio_stream ++;
						}
					}
				else if ((controller.Buttons & PSP_CTRL_UP) && ((previous_controller->Buttons & PSP_CTRL_UP) == 0))
					{
					if (p->volume_boost != 6)
						{
						p->volume_boost ++;
						}
					pcm_set_normalize_ratio(p->volume_boost);
					}
				else if ((controller.Buttons & PSP_CTRL_DOWN) && ((previous_controller->Buttons & PSP_CTRL_DOWN) == 0))
					{
					if (p->volume_boost != 0)
						{
						p->volume_boost --;
						}
					pcm_set_normalize_ratio(p->volume_boost);
					}
				else if ((controller.Buttons & PSP_CTRL_RTRIGGER) && ((previous_controller->Buttons & PSP_CTRL_RTRIGGER) == 0))
					{
					if (p->luminosity_boost != (number_of_luminosity_boosts - 1))
						{
						p->luminosity_boost ++;
						}
					}
				else if ((controller.Buttons & PSP_CTRL_LTRIGGER) && ((previous_controller->Buttons & PSP_CTRL_LTRIGGER) == 0))
					{
					if (p->luminosity_boost != 0)
						{
						p->luminosity_boost --;
						}
					}
				else if ((controller.Buttons & PSP_CTRL_START) && ((previous_controller->Buttons & PSP_CTRL_START) == 0))
					{
					if (p->aspect_ratio != (number_of_aspect_ratios - 1))
						{
						p->aspect_ratio ++;
						}
					else
						{
						p->aspect_ratio = 0;
						}
					}
				else if ((controller.Buttons & PSP_CTRL_CIRCLE) && ((previous_controller->Buttons & PSP_CTRL_CIRCLE) == 0))
					{
					if (p->show_interface == 0)
						{
						p->show_interface = 1;
						}
					else
						{
						p->show_interface = 0;
						}
					}
				else
					{
					p->seek = 0;
					}
				}
			}
		}


	*previous_controller = controller;
	}
Beispiel #6
0
void startServer()
{
	int             i, sock;
	struct			sockaddr_in	  server;
	struct          sockaddr_in   client;
	char			buffer[BUFFER_SIZE];
	unsigned int	buffer_len = 0;
	unsigned int    client_len = 0;
	unsigned int	server_len = 0;
	int             bytesTX = 0;
	int             bytesRX = 0;
	uint16_t		port;

	if((sock = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP)) < 0) goto Error;

	port = SERVER_PORT;

	/* Create sockaddr structure */
	memset(&server, 0, sizeof(server));
	server.sin_family      = AF_INET;
	server.sin_addr.s_addr = htonl(INADDR_ANY);
	server.sin_port        = htons(port);

	/* Bind the socket */
	server_len = sizeof(server);
	if(bind(sock, (struct sockaddr *) &server, server_len) < 0) goto Error;

	/* Run until cancelled */
	while(wifiMode)
	{
		/* Keeps Wifi from turning off */
		scePowerTick(1);
		/* Receive datagram from client */
		client_len = sizeof(client);
		bytesRX = recvfrom(sock, buffer, BUFFER_SIZE, 0, (struct sockaddr *) &client, (void*) &client_len);
		if(bytesRX < 0)
		{
			writeToLogFile("Critical Error failed to receive message from client!\n");
			wifiError = 1;
		}

		//if(bytesRX > 0) pspList[1].buttons = atol(buffer);


		//if(bytesRX == 3)
		//{
		//	strcat(buffer,"\n\nAppended!!!");
		//	strcat(buffer,"\n\nI");
		//	strcat(buffer,"\n\nLove My Muffin and My Chloe!!!");
		//	strcat(buffer,"\n\nXoXoXoXoXoXoX");
		//}

		//sprintf(buffer, "%lu", getPad(0));
		buffer_len = strlen(buffer);
		if(buffer_len > 0) writeToLogFile("Buffer: %lu\n",buffer);
		bytesTX = sendto(sock, buffer, buffer_len, 0, (struct sockaddr *) &client, sizeof(client));

		if(bytesTX < buffer_len)
		{
			writeToLogFile("Data Sent: %d\nBuffer Size: %d\nBuffer Data: %s\n", bytesTX, buffer_len, buffer);
			wifiError = 1;
		}
		for(i=0; i<buffer_len; i++) buffer[i] = 0;
	}

Error:
	wifiError = 1;
	return;
}