예제 #1
0
static int my_attach_cb(HIDClient *p_client, HIDDevice *p_device, unsigned int attach)
{
	char buf[64];
	__os_snprintf(buf,64,"%s:%04x %04x",attach?"attach":"detach",SWAP16(p_device->vid),SWAP16(p_device->pid));
	charprintf(buf);
	if( attach && SWAP16(p_device->vid) == 0x057e && SWAP16(p_device->pid) == 0x0337 )
	{
		unsigned int coreinit_handle;
		OSDynLoad_Acquire("coreinit.rpl", &coreinit_handle);
		void*(*OSAllocFromSystem)(unsigned int v1, unsigned int v2);
		OSDynLoad_FindExport(coreinit_handle,0,"OSAllocFromSystem",&OSAllocFromSystem);
		void(*memset)(void *dst, unsigned char wat, unsigned int len);
		OSDynLoad_FindExport(coreinit_handle,0,"memset",&memset);
		unsigned char *buf = OSAllocFromSystem(64,64);
		memset(buf,0,64);
		buf[0] = 0x13;
		struct my_cb_user *usr = OSAllocFromSystem(64,64);
		usr->buf = buf;
		unsigned int nsyshid_handle;
		OSDynLoad_Acquire("nsyshid.rpl", &nsyshid_handle);
		usr->nsyshid_handle = nsyshid_handle;
		OSDynLoad_FindExport(usr->nsyshid_handle,0,"HIDRead",&usr->HIDRead);
		OSDynLoad_FindExport(usr->nsyshid_handle,0,"HIDWrite",&usr->HIDWrite);
		usr->transfersize = p_device->max_packet_size_rx;
		int(*HIDWrite)(unsigned int handle, unsigned char *p_buffer, unsigned int buffer_length, HIDCallback hc, void *p_user) = usr->HIDWrite;
		HIDWrite(p_device->handle, usr->buf, 1, my_write_cb, usr);
		return DEVICE_USED;
	}
	return DEVICE_UNUSED;
}
예제 #2
0
void _entryPoint()
{
	/****************************>           Get Handles           <****************************/
	//Get a handle to coreinit.rpl
	unsigned int coreinit_handle;
	OSDynLoad_Acquire("coreinit.rpl", &coreinit_handle);
	unsigned int nsyshid_handle;
	OSDynLoad_Acquire("nsyshid.rpl", &nsyshid_handle);
	/****************************>       External Prototypes       <****************************/
	//OS functions
	void(*_Exit)();
	int(*HIDAddClient)(HIDClient *p_client, HIDAttachCallback attach_callback);
	int(*HIDDelClient)(HIDClient *p_client);
	/****************************>             Exports             <****************************/
	//OS functions
	OSDynLoad_FindExport(coreinit_handle, 0, "_Exit", &_Exit);

	OSDynLoad_FindExport(nsyshid_handle, 0, "HIDAddClient", &HIDAddClient);
	OSDynLoad_FindExport(nsyshid_handle, 0, "HIDDelClient", &HIDDelClient);

	HIDClient fd;
	HIDAddClient(&fd, my_attach_cb);
	while(1) ;
	HIDDelClient(&fd);
	//WARNING: DO NOT CHANGE THIS. YOU MUST CLEAR THE FRAMEBUFFERS AND IMMEDIATELY CALL EXIT FROM THIS FUNCTION. RETURNING TO LOADER CAUSES FREEZE.
	int ii=0;
	for(ii;ii<2;ii++)
	{
		fillScreen(0,0,0,0);
		flipBuffers();
	}
	_Exit();
}
예제 #3
0
/* Register a USB class driver */
int UhsClassDrvReg(int uhs_handle, UhsInterfaceFilter *filter, void *context, int (*cb)(void *ctx, UhsInterfaceProfile *profile))
{
	/* Symbol loading */
	unsigned int coreinit_handle;
	OSDynLoad_Acquire("coreinit.rpl", &coreinit_handle);
	void* (*memcpy)(void *dest, void *src, uint32_t length);
	int (*IOS_Ioctl)(int fd, int request, void *inbuf, int inlen, void *outbuf, int outlen);
	OSDynLoad_FindExport(coreinit_handle, false, "memcpy", &memcpy);
	OSDynLoad_FindExport(coreinit_handle, false, "IOS_Ioctl", &IOS_Ioctl);

	/* Allocate and fill in the request buffer */
	uint32_t reqbuf[6];
	reqbuf[0] = (uint32_t)context;
	reqbuf[1] = (uint32_t)cb;
	memcpy(&reqbuf[2], filter, sizeof(UhsInterfaceFilter));

	/* Perform the ioctl() request */
	int ret = -1;
	IOS_Ioctl(uhs_handle, 0x01, reqbuf, 0x18, &ret, 4);

	/* Set up the callback to be executed */
	wait_uhs_event(uhs_handle);

	return ret;
}
예제 #4
0
void _start()
{
	asm(
		"lis %r1, 0x1ab5 ;"
		"ori %r1, %r1, 0xd138 ;"
	);
	unsigned int coreinit_handle;
	OSDynLoad_Acquire("coreinit", &coreinit_handle);
	unsigned int(*MEMGetTotalFreeSizeForExpHeap)(void*expHeap);
	OSDynLoad_FindExport(coreinit_handle, 0, "MEMGetTotalFreeSizeForExpHeap", &MEMGetTotalFreeSizeForExpHeap);
	unsigned char *str;
	void *expHeap = (void*)0;
	float expSize = 0.f;
	/* this area appears semi-safe to search through */
	for(str = (unsigned char*)0x15000000; str < (unsigned char*)0x25000000; str+=4)
	{
		if(*(unsigned int*)str == 0x45585048)
		{
			void *tmpHeap = str;
			float tmpSize = (float)MEMGetTotalFreeSizeForExpHeap(tmpHeap);
			if(tmpSize > expSize)
			{
				expHeap = tmpHeap;
				expSize = tmpSize;
			}
		}
	}
	if(expHeap != (void*)0)
	{
		char buf[64];
		__os_snprintf(buf,64,"Biggest ExpHeap is %08x with %.2fMB left", expHeap, expSize/1024/1024);
		OSFatal(buf);
	}
	OSFatal("No Heaps found!");
}
예제 #5
0
파일: uhs.c 프로젝트: Gskartwii/libwiiu
/* Submit a bulk request to an endpoint */
int UhsSubmitBulkRequest(int uhs_handle, uint32_t if_handle, uint8_t endpoint, int direction, void *buffer, int length, int timeout)
{
	/* Symbol loading */
	unsigned int coreinit_handle;
	OSDynLoad_Acquire("coreinit.rpl", &coreinit_handle);
	void* (*memset)(void *buffer, int value, unsigned length);
	int (*IOS_Ioctlv)(int fd, int request, int cnt_in, int cnt_out, struct iovec *vecbuf);
	OSDynLoad_FindExport(coreinit_handle, false, "memset", &memset);
	OSDynLoad_FindExport(coreinit_handle, false, "IOS_Ioctlv", &IOS_Ioctlv);

	/* Allocate and fill in the request buffer */
	char reqbuf[0xa1];
	memset(&reqbuf[0], 0, sizeof(reqbuf));
	*((uint32_t*)&reqbuf[0x00]) = if_handle;
	reqbuf[0x04] = endpoint;
	*((uint32_t*)&reqbuf[0x05]) = timeout;
	*((uint32_t*)&reqbuf[0x09]) = 3;
	*((uint32_t*)&reqbuf[0x0d]) = direction;
	*((uint32_t*)&reqbuf[0x11]) = length;

	/* Allocate and fill in the I/O vectors */
	struct iovec vecbuf[2];
	memset(&vecbuf[0], 0, sizeof(struct iovec) * 2);
	vecbuf[0].buffer = &reqbuf[0];
	vecbuf[0].len = sizeof(reqbuf);
	vecbuf[1].buffer = buffer;
	vecbuf[1].len = length;

	/* Perform the ioctlv() request */
	if (direction == ENDPOINT_TRANSFER_OUT) return IOS_Ioctlv(uhs_handle, 0xe, 0, 2, &vecbuf[0]);
	else if (direction == ENDPOINT_TRANSFER_IN) return IOS_Ioctlv(uhs_handle, 0xe, 1, 1, &vecbuf[0]);
	else return -1;
}
예제 #6
0
파일: loader.c 프로젝트: Gskartwii/libwiiu
/* Start of our code */
void _start()
{
  /* Load a good stack */
  asm(
      "lis %r1, 0x1ab5 ;"
      "ori %r1, %r1, 0xd138 ;"
  );
 
  /* Get a handle to coreinit.rpl */
  unsigned int coreinit_handle;
  OSDynLoad_Acquire("coreinit.rpl", &coreinit_handle);

  /* OS memory allocation functions */
  void* (*OSAllocFromSystem)(uint32_t size, int align);

  /* OS thread functions */
  bool (*OSCreateThread)(void *thread, void *entry, int argc, void *args, uint32_t stack, uint32_t stack_size, int32_t priority, uint16_t attr);
  int32_t (*OSResumeThread)(void *thread);

  /* Exit function */
  void (*_Exit)();

  /* Read the addresses of the functions */
  OSDynLoad_FindExport(coreinit_handle, 0, "OSAllocFromSystem", &OSAllocFromSystem);
  OSDynLoad_FindExport(coreinit_handle, 0, "OSCreateThread", &OSCreateThread);
  OSDynLoad_FindExport(coreinit_handle, 0, "OSResumeThread", &OSResumeThread);
  OSDynLoad_FindExport(coreinit_handle, 0, "_Exit", &_Exit);

  /* Create a string argument */
  char *str = OSAllocFromSystem(6, 1);
  str[0] = 'H';
  str[1] = 'e';
  str[2] = 'l';
  str[3] = 'l';
  str[4] = 'o';
  str[5] = 0;

  /* Allocate a stack for the thread */
  uint32_t stack = (uint32_t) OSAllocFromSystem(0x1000, 0x10);
  stack += 0x1000;

  /* Create the thread */
  void *thread = OSAllocFromSystem(OSTHREAD_SIZE, 8);
  bool ret = OSCreateThread(thread, OSFatal, (int)str, null, stack, 0x1000, 0, 1);
  if (ret == false)
  {
	  OSFatal("Failed to create thread");
  }

  /* Schedule it for execution */
  OSResumeThread(thread);

  /* Infinite loop */
  while(1);
}
예제 #7
0
파일: uhs.c 프로젝트: Gskartwii/libwiiu
/* Determine which USB device interfaces are plugged in and available */
int UhsQueryInterfaces(int uhs_handle, UhsInterfaceFilter *filter, UhsInterfaceProfile *profiles, int max_profiles)
{
	/* Symbol loading */
	unsigned int coreinit_handle;
	OSDynLoad_Acquire("coreinit.rpl", &coreinit_handle);
	int (*IOS_Ioctl)(int fd, int request, void *inbuf, int inlen, void *outbuf, int outlen);
	OSDynLoad_FindExport(coreinit_handle, false, "IOS_Ioctl", &IOS_Ioctl);

	/* Perform the ioctl() request */
	return IOS_Ioctl(uhs_handle, 0x11, filter, 0x10, profiles, max_profiles * 0x16c);
}
예제 #8
0
void InitSysFunctionPointers(void)
{
    unsigned int *funcPointer = 0;
    unsigned int sysapp_handle;
    OSDynLoad_Acquire("sysapp.rpl", &sysapp_handle);

    OS_FIND_EXPORT(sysapp_handle, _SYSLaunchTitleByPathFromLauncher);
    OS_FIND_EXPORT(sysapp_handle, SYSRelaunchTitle);
    OS_FIND_EXPORT(sysapp_handle, SYSLaunchMenu);
    OS_FIND_EXPORT(sysapp_handle, SYSLaunchMiiStudio);
}
예제 #9
0
void InitSocketFunctionPointers(void)
{
    unsigned int nsysnet_handle;
    unsigned int *funcPointer = 0;
    OSDynLoad_Acquire("nsysnet.rpl", &nsysnet_handle);

    unsigned int nn_ac_handle;
    int(*ACInitialize)();
    int(*ACGetStartupId) (unsigned int *id);
    int(*ACConnectWithConfigId) (unsigned int id);
    int(*ACGetAssignedAddress) (u32 * ip);
    OSDynLoad_Acquire("nn_ac.rpl", &nn_ac_handle);
    OSDynLoad_FindExport(nn_ac_handle, 0, "ACInitialize", &ACInitialize);
    OSDynLoad_FindExport(nn_ac_handle, 0, "ACGetStartupId", &ACGetStartupId);
    OSDynLoad_FindExport(nn_ac_handle, 0, "ACConnectWithConfigId",&ACConnectWithConfigId);
    OSDynLoad_FindExport(nn_ac_handle, 0, "ACGetAssignedAddress",&ACGetAssignedAddress);

    OS_FIND_EXPORT(nsysnet_handle, socket_lib_init);
    OS_FIND_EXPORT(nsysnet_handle, socket_lib_finish);
    OS_FIND_EXPORT(nsysnet_handle, socket);
    OS_FIND_EXPORT(nsysnet_handle, socketclose);
    OS_FIND_EXPORT(nsysnet_handle, connect);
    OS_FIND_EXPORT(nsysnet_handle, bind);
    OS_FIND_EXPORT(nsysnet_handle, listen);
    OS_FIND_EXPORT(nsysnet_handle, accept);
    OS_FIND_EXPORT(nsysnet_handle, send);
    OS_FIND_EXPORT(nsysnet_handle, recv);
    OS_FIND_EXPORT(nsysnet_handle, sendto);
    OS_FIND_EXPORT(nsysnet_handle, setsockopt);
    OS_FIND_EXPORT(nsysnet_handle, inet_ntoa);
    OS_FIND_EXPORT(nsysnet_handle, inet_aton);

    unsigned int nn_startupid;
    ACInitialize();
    ACGetStartupId(&nn_startupid);
    ACConnectWithConfigId(nn_startupid);
    ACGetAssignedAddress(&hostIpAddress);

    socket_lib_init();
}
예제 #10
0
파일: uhs.c 프로젝트: Gskartwii/libwiiu
/* Open a specific controller under /dev/uhs */
int UhsOpenController(int controller_num)
{
	/* Symbol loading */
	unsigned int coreinit_handle;
	OSDynLoad_Acquire("coreinit.rpl", &coreinit_handle);
	int (*IOS_Open)(char *path, int mode);
	OSDynLoad_FindExport(coreinit_handle, false, "IOS_Open", &IOS_Open);

	/* Build the path name and return a handle */
	char path[32];
	__os_snprintf(path, 32, "/dev/uhs/%d", controller_num);
	return IOS_Open(path, 0);
}
예제 #11
0
/* Wait asynchronously for a UHS event */
static int wait_uhs_event(int uhs_handle)
{
	/* Symbol loading */
	unsigned int coreinit_handle;
	OSDynLoad_Acquire("coreinit.rpl", &coreinit_handle);
	int (*IOS_IoctlAsync)(int fd, int request, void *inbuf, int inlen, void *outbuf, int outlen, void (*cb)(int,void*), void *context);
	OSDynLoad_FindExport(coreinit_handle, false, "IOS_IoctlAsync", &IOS_IoctlAsync);

	/* Allocate and fill in the request buffers */
	uint32_t reqbuf[8];
	reqbuf[0] = (uint32_t)-1;
	reqbuf[1] = 0;

	/* Perform the ioctl() request */
	uint32_t outbuf[0x180/4];
	return IOS_IoctlAsync(uhs_handle, 0x03, reqbuf, 8, outbuf, 0x180, &uhs_event_cb, (void*)uhs_handle);
}
예제 #12
0
/* Acquire a USB device interface for use */
int UhsAcquireInterface(int uhs_handle, uint32_t if_handle, void *unk1, int (*callback)(int arg0, int arg1, int arg2))
{
	/* Symbol loading */
	unsigned int coreinit_handle;
	OSDynLoad_Acquire("coreinit.rpl", &coreinit_handle);
	int (*IOS_Ioctl)(int fd, int request, void *inbuf, int inlen, void *outbuf, int outlen);
	OSDynLoad_FindExport(coreinit_handle, false, "IOS_Ioctl", &IOS_Ioctl);

	/* Allocate and fill in the request buffer */
	uint32_t reqbuf[3];
	reqbuf[0] = if_handle;
	reqbuf[1] = (uint32_t)unk1;
	reqbuf[2] = (uint32_t)callback;

	/* Perform the ioctl() request */
	return IOS_Ioctl(uhs_handle, 0x4, &reqbuf[0], 0xc, 0, 0);
}
예제 #13
0
/* Administer a USB device */
int UhsAdministerDevice(int uhs_handle, uint32_t if_handle, int arg2, int arg3)
{
	/* Symbol loading */
	unsigned int coreinit_handle;
	OSDynLoad_Acquire("coreinit.rpl", &coreinit_handle);
	int (*IOS_Ioctl)(int fd, int request, void *inbuf, int inlen, void *outbuf, int outlen);
	OSDynLoad_FindExport(coreinit_handle, false, "IOS_Ioctl", &IOS_Ioctl);

	/* Allocate and fill in the request buffer */
	uint32_t reqbuf[3];
	reqbuf[0] = (uint32_t)arg2;
	reqbuf[1] = if_handle;
	reqbuf[2] = (uint32_t)arg3;

	/* Perform the ioctl() request */
	return IOS_Ioctl(uhs_handle, 0x12, &reqbuf[0], 0xc, 0, 0);
}
예제 #14
0
/* Release a currently-held USB device interface */
int UhsReleaseInterface(int uhs_handle, uint32_t if_handle, bool no_reacquire)
{
	/* Symbol loading */
	unsigned int coreinit_handle;
	OSDynLoad_Acquire("coreinit.rpl", &coreinit_handle);
	int (*IOS_Ioctl)(int fd, int request, void *inbuf, int inlen, void *outbuf, int outlen);
	OSDynLoad_FindExport(coreinit_handle, false, "IOS_Ioctl", &IOS_Ioctl);

	/* Allocate and fill in the request buffer */
	uint32_t reqbuf[3];
	reqbuf[0] = if_handle;
	reqbuf[1] = (uint32_t)no_reacquire;
	reqbuf[2] = 0;

	/* Perform the ioctl() request */
	return IOS_Ioctl(uhs_handle, 0x5, &reqbuf[0], 0xc, 0, 0);
}
예제 #15
0
/* Submit a control request to endpoint 0 */
int UhsSubmitControlRequest(int uhs_handle, uint32_t if_handle, void *buffer, uint8_t bRequest, uint8_t bmRequestType, uint16_t wValue, uint16_t wIndex, uint16_t wLength, int timeout)
{
	/* Symbol loading */
	unsigned int coreinit_handle;
	OSDynLoad_Acquire("coreinit.rpl", &coreinit_handle);
	void* (*memset)(void *buffer, int value, unsigned length);
	int (*IOS_Ioctlv)(int fd, int request, int cnt_in, int cnt_out, struct iovec *vecbuf);
	OSDynLoad_FindExport(coreinit_handle, false, "memset", &memset);
	OSDynLoad_FindExport(coreinit_handle, false, "IOS_Ioctlv", &IOS_Ioctlv);

	/* Allocate and fill in the request buffer */
	uint8_t reqbuf[0xa1];
	memset(&reqbuf[0], 0, sizeof(reqbuf));
	*((uint32_t*)&reqbuf[0x00]) = if_handle;
	reqbuf[0x04] = 0;						/* Endpoint 0 */
	*((uint32_t*)&reqbuf[0x05]) = timeout;
	*((uint32_t*)&reqbuf[0x09]) = 1;		/* Transfer type */
	reqbuf[0x0d] = bRequest;
	reqbuf[0x0e] = bmRequestType;
	*((uint16_t*)&reqbuf[0x0f]) = wValue;
	*((uint16_t*)&reqbuf[0x11]) = wIndex;
	*((uint16_t*)&reqbuf[0x13]) = wLength;

	/* Allocate and fill in the I/O vectors */
	struct iovec vecbuf[2];
	memset(&vecbuf[0], 0, sizeof(struct iovec) * 2);
	vecbuf[0].buffer = &reqbuf[0];
	vecbuf[0].len = sizeof(reqbuf);
	vecbuf[0].unknown8[3] = 1;
	vecbuf[1].buffer = buffer;
	vecbuf[1].len = (int)wLength;
	vecbuf[1].unknown8[3] = 1;

	/* Perform the ioctlv() request */
	if (bmRequestType & (1 << 7)) return IOS_Ioctlv(uhs_handle, 0xc, 1, 1, &vecbuf[0]);
	else return IOS_Ioctlv(uhs_handle, 0xc, 0, 2, &vecbuf[0]);
}
예제 #16
0
void _entryPoint()
{
	/****************************>           Get Handles           <****************************/
	//Get a handle to coreinit.rpl
	unsigned int coreinit_handle;
	OSDynLoad_Acquire("coreinit.rpl", &coreinit_handle);
	//Get a handle to vpad.rpl */
	unsigned int vpad_handle;
	OSDynLoad_Acquire("vpad.rpl", &vpad_handle);
	/****************************>       External Prototypes       <****************************/
	//VPAD functions
	int(*VPADRead)(int controller, VPADData *buffer, unsigned int num, int *error);
	//OS functions
	void(*_Exit)();
	/****************************>             Exports             <****************************/
	//VPAD functions
	OSDynLoad_FindExport(vpad_handle, 0, "VPADRead", &VPADRead);
	//OS functions
	OSDynLoad_FindExport(coreinit_handle, 0, "_Exit", &_Exit);
	/****************************>             Globals             <****************************/
	struct pongGlobals myPongGlobals;
	//Flag for restarting the entire game.
	myPongGlobals.restart = 1;
	//scale of game
	myPongGlobals.scale=1;
	//Default locations for paddles and ball location and movement dx/dy
	myPongGlobals.p1X_default=40*myPongGlobals.scale;
	myPongGlobals.p2X_default=340*myPongGlobals.scale;
	myPongGlobals.ballX_default=200*myPongGlobals.scale;
	myPongGlobals.p1Y_default=150*myPongGlobals.scale;
	myPongGlobals.p2Y_default=150*myPongGlobals.scale;
	myPongGlobals.ballY_default=120*myPongGlobals.scale;
	//Sizes of objects
	myPongGlobals.p1X_size=20*myPongGlobals.scale;
	myPongGlobals.p1Y_size=60*myPongGlobals.scale;
	myPongGlobals.ballX_size=8*myPongGlobals.scale;
	myPongGlobals.ballY_size=8*myPongGlobals.scale;
	myPongGlobals.p2X_size=20*myPongGlobals.scale;
	myPongGlobals.p2Y_size=60*myPongGlobals.scale;
	//Boundry of play area (screen)
	myPongGlobals.xMinBoundry=0*myPongGlobals.scale;
	myPongGlobals.xMaxBoundry=400*myPongGlobals.scale;
	myPongGlobals.yMinBoundry=0*myPongGlobals.scale;
	myPongGlobals.yMaxBoundry=240*myPongGlobals.scale;
	
	myPongGlobals.winX=11*2*myPongGlobals.scale;
	myPongGlobals.winY=5*2*myPongGlobals.scale;
	myPongGlobals.score1X=13*2*myPongGlobals.scale;
	myPongGlobals.score2X=15*2*myPongGlobals.scale;
	myPongGlobals.score1Y=0*myPongGlobals.scale;
	myPongGlobals.score2Y=0*myPongGlobals.scale;
	//Game engine globals
	myPongGlobals.direction = 1;
	myPongGlobals.button = 0;
	myPongGlobals.paddleColorR=0xFF;
	myPongGlobals.paddleColorG=0x00;
	myPongGlobals.paddleColorB=0x00;
	myPongGlobals.ballColorR=0x00;
	myPongGlobals.ballColorG=0xFF;
	myPongGlobals.ballColorB=0x00;
	myPongGlobals.ballTrailColorR=0x00;
	myPongGlobals.ballTrailColorG=0x00;
	myPongGlobals.ballTrailColorB=0xFF;
	myPongGlobals.backgroundColorR=0x00;
	myPongGlobals.backgroundColorG=0x00;
	myPongGlobals.backgroundColorB=0x00;
	myPongGlobals.count = 0;
	//Keep track of score
	myPongGlobals.score1 = 0;
	myPongGlobals.score2 = 0;
	myPongGlobals.scoreWin = 9;
	//Game engine globals
	myPongGlobals.direction = 1;
	myPongGlobals.button = 0;
	myPongGlobals.paddleColorR=0xFF;
	myPongGlobals.paddleColorG=0x00;
	myPongGlobals.paddleColorB=0x00;
	myPongGlobals.ballColorR=0x00;
	myPongGlobals.ballColorG=0xFF;
	myPongGlobals.ballColorB=0x00;
	myPongGlobals.ballTrailColorR=0x00;
	myPongGlobals.ballTrailColorG=0x00;
	myPongGlobals.ballTrailColorB=0xFF;
	myPongGlobals.backgroundColorR=0x00;
	myPongGlobals.backgroundColorG=0x00;
	myPongGlobals.backgroundColorB=0x00;
	myPongGlobals.count = 0;
	//Keep track of score
	myPongGlobals.score1 = 0;
	myPongGlobals.scoreWin = 9;
	//Used for collision
	myPongGlobals.flag = 0;

	//Flag to determine if p1 should be rendered along with p1's movement direction
	myPongGlobals.renderP1Flag = 0;
	//Flags for render states
	myPongGlobals.renderResetFlag = 0;
	myPongGlobals.renderBallFlag = 0;
	myPongGlobals.renderWinFlag = 0;
	myPongGlobals.renderScoreFlag = 0;
	/****************************>            VPAD Loop            <****************************/
	int error;
	VPADData vpad_data;
	while (1)
	{
		VPADRead(0, &vpad_data, 1, &error);
		//Get the status of the gamepad
		myPongGlobals.button = vpad_data.btn_hold;
		//If the game has been restarted, reset the game (we do this one time in the beginning to set everything up)
		if (myPongGlobals.restart == 1)
		{
			reset(&myPongGlobals);
			myPongGlobals.restart = 0;
		}		
		//Set old positions.
		updatePosition(&myPongGlobals);

		//Update location of player1 and 2 paddles
		p1Move(&myPongGlobals);
		p2Move(&myPongGlobals);

		//Update location of the ball
		moveBall(&myPongGlobals);
		//Check if their are any collisions between the ball and the paddles.
		checkCollision(&myPongGlobals);
		//Render the scene
		myPongGlobals.renderBallFlag = 1;
		render(&myPongGlobals);

		//Increment the counter (used for physicals calcuations)
		myPongGlobals.count+=1;

		//To exit the game
		if (myPongGlobals.button&BUTTON_HOME)
		{
		break;
		}
	}
	//WARNING: DO NOT CHANGE THIS. YOU MUST CLEAR THE FRAMEBUFFERS AND IMMEDIATELY CALL EXIT FROM THIS FUNCTION. RETURNING TO LOADER CAUSES FREEZE.
	int ii=0;
	for(ii;ii<2;ii++)
	{
		fillScreen(0,0,0,0);
		flipBuffers();
	}
	_Exit();
}
예제 #17
0
파일: loader.c 프로젝트: CreeperMario/cave
void _main()
{
    /****************************>            Fix Stack            <****************************/
    //Load a good stack
    asm(
        "lis %r1, 0x1ab5 ;"
        "ori %r1, %r1, 0xd138 ;"
        );
    /****************************>           Get Handles           <****************************/
    //Get a handle to coreinit.rpl
    unsigned int coreinit_handle, vpad_handle, sysapp_handle, avm_handle;
    OSDynLoad_Acquire("coreinit.rpl", &coreinit_handle);
    OSDynLoad_Acquire("vpad.rpl", &vpad_handle);
    OSDynLoad_Acquire("sysapp.rpl", &sysapp_handle);
    // CreeperMario: Get a handle to the audio/video manager - avm.rpl
    OSDynLoad_Acquire("avm.rpl", &avm_handle);

    // STUFF
    VPADData vpad_data;
    int(*VPADRead)(int controller, VPADData *buffer, unsigned int num, int *err);
    OSDynLoad_FindExport(vpad_handle, 0, "VPADRead", &VPADRead);

    // Sysapp stuff
    int(*SYSLaunchMenu)();
    OSDynLoad_FindExport(sysapp_handle, 0, "SYSLaunchMenu", &SYSLaunchMenu);

	// please dont break stuff...
	int(*SYSLaunchTitle) (int bit1, int bit2);
	OSDynLoad_FindExport(sysapp_handle, 0, "SYSLaunchTitle", &SYSLaunchTitle);
	int(*_Exit)();
	OSDynLoad_FindExport(coreinit_handle, 0, "_Exit", &_Exit);

    /****************************>       External Prototypes       <****************************/
    //OSScreen functions
    void(*OSScreenInit)();
    unsigned int(*OSScreenGetBufferSizeEx)(unsigned int bufferNum);
    unsigned int(*OSScreenSetBufferEx)(unsigned int bufferNum, void * addr);
    //OS Memory functions
	void*(*memset)(void * dest, uint32_t value, uint32_t bytes);
    void*(*OSAllocFromSystem)(uint32_t size, int align);
    void(*OSFreeToSystem)(void *ptr);
    //IM functions
    int(*IM_Open)();
    int(*IM_Close)(int fd);
    int(*IM_SetDeviceState)(int fd, void *mem, int state, int a, int b);
    // CreeperMario: TV Screen scaling functions
    bool(*AVMSetTVScale)(int width, int height);
    /****************************>             Exports             <****************************/
    //OSScreen functions
    OSDynLoad_FindExport(coreinit_handle, 0, "OSScreenInit", &OSScreenInit);
    OSDynLoad_FindExport(coreinit_handle, 0, "OSScreenGetBufferSizeEx", &OSScreenGetBufferSizeEx);
    OSDynLoad_FindExport(coreinit_handle, 0, "OSScreenSetBufferEx", &OSScreenSetBufferEx);
    //OS Memory functions
    OSDynLoad_FindExport(coreinit_handle, 0, "memset", &memset);
    OSDynLoad_FindExport(coreinit_handle, 0, "OSAllocFromSystem", &OSAllocFromSystem);
    OSDynLoad_FindExport(coreinit_handle, 0, "OSFreeToSystem", &OSFreeToSystem);
    //IM functions
    OSDynLoad_FindExport(coreinit_handle, 0, "IM_Open", &IM_Open);
    OSDynLoad_FindExport(coreinit_handle, 0, "IM_Close", &IM_Close);
    OSDynLoad_FindExport(coreinit_handle, 0, "IM_SetDeviceState", &IM_SetDeviceState);
    // CreeperMario: TV Screen scaling functions
    OSDynLoad_FindExport(avm_handle, 0, "AVMSetTVScale", &AVMSetTVScale);

    /*** CreeperMario: Set the TV screen to the proper 'scale factor'. ***/
    AVMSetTVScale(854, 480);

    /****************************>          Initial Setup          <****************************/
    //Restart system to get lib access
    int fd = IM_Open();
    void *mem = OSAllocFromSystem(0x100, 64);
    memset(mem, 0, 0x100);
    //set restart flag to force quit browser
    IM_SetDeviceState(fd, mem, 3, 0, 0);
    IM_Close(fd);
    OSFreeToSystem(mem);
    //wait a bit for browser end
    unsigned int t1 = 0x15000000;
    while(t1--) ;
    //Call the Screen initilzation function.
    OSScreenInit();
    //Grab the buffer size for each screen (TV and gamepad)
    int buf0_size = OSScreenGetBufferSizeEx(0);
    int buf1_size = OSScreenGetBufferSizeEx(1);
    //Set the buffer area.
    OSScreenSetBufferEx(0, (void *)0xF4000000);
    OSScreenSetBufferEx(1, (void *)0xF4000000 + buf0_size);
    //Clear both framebuffers.
    doclearstuff();

	// Define struct for global variables!
	struct cGlobals caveGlobals;

	// Variables n stuff!
	caveGlobals.food = 0;
	caveGlobals.row = 1;
	caveGlobals.col = 1;
	caveGlobals.level = 1;
	caveGlobals.dogsteps = 0;
	caveGlobals.dogalive = 1;
	caveGlobals.mysteps = 0;
	caveGlobals.maxhealth = 10;
	caveGlobals.curhealth = 10;

	// Start at level 1 (obviously!)
	changelevel(&caveGlobals);

	// Draw Buffers and Initial Screen
	__os_snprintf(caveGlobals.mystat, 64, " ");
	doclearstuff();
	drawstuff(&caveGlobals);
	flipBuffers();

    int err;

    while(1) {
		VPADRead(0, &vpad_data, 1, &err);

		// Quit
		if (vpad_data.btn_trigger & BUTTON_HOME) {
			doclearstuff();
			__os_snprintf(caveGlobals.endgame, 256, "Thanks for Playing!\nYour Final Level: %d \n\n\nBy: SonyUSA", caveGlobals.level);
			drawString(0, 0, caveGlobals.endgame);
			flipBuffers();
			t1 = 0x50000000;
			while(t1--) ;
			//Maybe fix for exit crash?
			doclearstuff();
			flipBuffers();
			doclearstuff();
			flipBuffers();
			//Ape escape!
			SYSLaunchMenu();
			_Exit();
		}
		//Grab Stuff (A)
		if (vpad_data.btn_release & BUTTON_A) {
			//Checks for Food
			if (caveGlobals.nMapArray[caveGlobals.col][caveGlobals.row] == 8) {
				doclearstuff();
				__os_snprintf(caveGlobals.mystat, 64, "Got it!");
				drawString(25, 17, caveGlobals.mystat);
				caveGlobals.food += 1;
				caveGlobals.nMapArray[caveGlobals.col][caveGlobals.row] = 2;
				drawstuff(&caveGlobals);
				flipBuffers();
			}
			//Check for Potions
			if (caveGlobals.nMapArray[caveGlobals.col][caveGlobals.row] == 11) {
				doclearstuff();
				__os_snprintf(caveGlobals.mystat, 64, "*Gulp!*");
				drawString(25, 17, caveGlobals.mystat);
				caveGlobals.curhealth += 5;
				caveGlobals.nMapArray[caveGlobals.col][caveGlobals.row] = 2;
				//Make sure we don't go over health limit
				if (caveGlobals.curhealth > caveGlobals.maxhealth) { caveGlobals.curhealth = caveGlobals.maxhealth; }
				drawstuff(&caveGlobals);
				dog(&caveGlobals);
				flipBuffers();
			}
			//Checks for Stairs
			if (caveGlobals.nMapArray[caveGlobals.col][caveGlobals.row] == 9) {
				caveGlobals.level += 1;
				doclearstuff();
				changelevel(&caveGlobals);
				drawstuff(&caveGlobals);
				flipBuffers();
			}
		}
		//Search for Hidden Traps and Doors
		if (vpad_data.btn_trigger & BUTTON_Y) {
			doclearstuff();
			drawstuff(&caveGlobals);
			dog(&caveGlobals);
			//Ask the player which way to search
			__os_snprintf(caveGlobals.mystat, 64, "Search Which Way?");
			drawString(22, 17, caveGlobals.mystat);
			flipBuffers();
			//Lets use a while loop so players cant just hold down search while they are walking! Cheating gits!
			while(2) {
				VPADRead(0, &vpad_data, 1, &err);
				// Search Up
				if (vpad_data.btn_release & BUTTON_UP) {
					// Traps
					if (ishtrap(&caveGlobals, caveGlobals.row, caveGlobals.col -1 ) == true ) {
						doclearstuff();
						__os_snprintf(caveGlobals.mystat, 64, "It's a trap!");
						drawString(25, 17, caveGlobals.mystat);
						caveGlobals.nMapArray[caveGlobals.col -1][caveGlobals.row] = 6;
						drawstuff(&caveGlobals);
						flipBuffers();
						break;
					}
					// Doors
					if (ishdoor(&caveGlobals, caveGlobals.row, caveGlobals.col -1 ) == true ) {
						doclearstuff();
						__os_snprintf(caveGlobals.mystat, 64, "A Secret Door!");
						drawString(22, 17, caveGlobals.mystat);
						caveGlobals.nMapArray[caveGlobals.col -1][caveGlobals.row] = 4;
						drawstuff(&caveGlobals);
						flipBuffers();
						break;
					}
					// If nothing is found...
					doclearstuff();
					drawstuff(&caveGlobals);
					__os_snprintf(caveGlobals.mystat, 64, "Nothing There!");
					drawString(23, 17, caveGlobals.mystat);
					flipBuffers();
					break;
				}
				// Search Down
				if (vpad_data.btn_release & BUTTON_DOWN) {
					// Traps
					if (ishtrap(&caveGlobals, caveGlobals.row, caveGlobals.col +1 ) == true ) {
						doclearstuff();
						__os_snprintf(caveGlobals.mystat, 64, "It's a trap!");
						drawString(25, 17, caveGlobals.mystat);
						caveGlobals.nMapArray[caveGlobals.col +1][caveGlobals.row] = 6;
						drawstuff(&caveGlobals);
						flipBuffers();
						break;
					}
					// Doors
					if (ishdoor(&caveGlobals, caveGlobals.row, caveGlobals.col +1 ) == true ) {
						doclearstuff();
						__os_snprintf(caveGlobals.mystat, 64, "A Secret Door!");
						drawString(22, 17, caveGlobals.mystat);
						caveGlobals.nMapArray[caveGlobals.col +1][caveGlobals.row] = 4;
						drawstuff(&caveGlobals);
						flipBuffers();
						break;
					}
					// If nothing is found...
					doclearstuff();
					drawstuff(&caveGlobals);
					__os_snprintf(caveGlobals.mystat, 64, "Nothing There!");
					drawString(23, 17, caveGlobals.mystat);
					flipBuffers();
					break;
				}
				// Search Right
				if (vpad_data.btn_release & BUTTON_RIGHT) {
					// Traps
					if (ishtrap(&caveGlobals, caveGlobals.row +1 , caveGlobals.col ) == true ) {
						doclearstuff();
						__os_snprintf(caveGlobals.mystat, 64, "It's a trap!");
						drawString(25, 17, caveGlobals.mystat);
						caveGlobals.nMapArray[caveGlobals.col][caveGlobals.row +1] = 6;
						drawstuff(&caveGlobals);
						flipBuffers();
						break;
					}
					// Doors
					if (ishdoor(&caveGlobals, caveGlobals.row +1 , caveGlobals.col ) == true ) {
						doclearstuff();
						__os_snprintf(caveGlobals.mystat, 64, "A Secret Door!");
						drawString(22, 17, caveGlobals.mystat);
						caveGlobals.nMapArray[caveGlobals.col][caveGlobals.row +1] = 4;
						drawstuff(&caveGlobals);
						flipBuffers();
						break;
					}
					// If nothing is found...
					doclearstuff();
					drawstuff(&caveGlobals);
					__os_snprintf(caveGlobals.mystat, 64, "Nothing There!");
					drawString(23, 17, caveGlobals.mystat);
					flipBuffers();
					break;
				}
				// Search Left
				if (vpad_data.btn_release & BUTTON_LEFT) {
					// Traps
					if (ishtrap(&caveGlobals, caveGlobals.row -1 , caveGlobals.col ) == true ) {
						doclearstuff();
						__os_snprintf(caveGlobals.mystat, 64, "It's a trap!");
						drawString(25, 17, caveGlobals.mystat);
						caveGlobals.nMapArray[caveGlobals.col][caveGlobals.row -1] = 6;
						drawstuff(&caveGlobals);
						flipBuffers();
						break;
					}
					// Doors
					if (ishdoor(&caveGlobals, caveGlobals.row -1 , caveGlobals.col ) == true ) {
						doclearstuff();
						__os_snprintf(caveGlobals.mystat, 64, "A Secret Door!");
						drawString(22, 17, caveGlobals.mystat);
						caveGlobals.nMapArray[caveGlobals.col][caveGlobals.row -1] = 4;
						drawstuff(&caveGlobals);
						flipBuffers();
						break;
					}
					// If nothing is found...
					doclearstuff();
					drawstuff(&caveGlobals);
					__os_snprintf(caveGlobals.mystat, 64, "Nothing There!");
					drawString(23, 17, caveGlobals.mystat);
					flipBuffers();
					break;
				}
			}
		}
		//Open and Close Doors (X + Direction)
		if (vpad_data.btn_hold & BUTTON_X) {
			if (vpad_data.btn_trigger & BUTTON_DOWN) {
				if (isclosedoor(&caveGlobals, caveGlobals.row, caveGlobals.col +1 ) == true ) {
					doclearstuff();
					drawstuff(&caveGlobals);
					caveGlobals.nMapArray[caveGlobals.col +1][caveGlobals.row] = 5;
					flipBuffers();
				}
				else if (isopendoor(&caveGlobals, caveGlobals.row, caveGlobals.col +1 ) == true ) {
					doclearstuff();
					drawstuff(&caveGlobals);
					caveGlobals.nMapArray[caveGlobals.col +1][caveGlobals.row] = 4;
					flipBuffers();
				}
			}
			if (vpad_data.btn_trigger & BUTTON_UP) {
				if (isclosedoor(&caveGlobals, caveGlobals.row, caveGlobals.col -1 ) == true ) {
					doclearstuff();
					drawstuff(&caveGlobals);
					caveGlobals.nMapArray[caveGlobals.col -1][caveGlobals.row] = 5;
					flipBuffers();
				}
				else if (isopendoor(&caveGlobals, caveGlobals.row, caveGlobals.col -1 ) == true ) {
					doclearstuff();
					drawstuff(&caveGlobals);
					caveGlobals.nMapArray[caveGlobals.col -1][caveGlobals.row] = 4;
					flipBuffers();
				}
			}
			if (vpad_data.btn_trigger & BUTTON_LEFT) {
				if (isclosedoor(&caveGlobals, caveGlobals.row -1 , caveGlobals.col ) == true ) {
					doclearstuff();
					drawstuff(&caveGlobals);
					caveGlobals.nMapArray[caveGlobals.col][caveGlobals.row -1] = 5;
					flipBuffers();
				}
				else if (isopendoor(&caveGlobals, caveGlobals.row -1 , caveGlobals.col ) == true ) {
					doclearstuff();
					drawstuff(&caveGlobals);
					caveGlobals.nMapArray[caveGlobals.col][caveGlobals.row -1] = 4;
					flipBuffers();
				}
			}
			if (vpad_data.btn_trigger & BUTTON_RIGHT) {
				if (isclosedoor(&caveGlobals, caveGlobals.row +1 , caveGlobals.col ) == true ) {
					doclearstuff();
					drawstuff(&caveGlobals);
					caveGlobals.nMapArray[caveGlobals.col][caveGlobals.row +1] = 5;
					flipBuffers();
				}
				else if (isopendoor(&caveGlobals, caveGlobals.row +1 , caveGlobals.col ) == true ) {
					doclearstuff();
					drawstuff(&caveGlobals);
					caveGlobals.nMapArray[caveGlobals.col][caveGlobals.row +1] = 4;
					flipBuffers();
				}
			}
		}
		// Movement
		//Down
		if (vpad_data.btn_trigger & BUTTON_DOWN) {
			if (canmove(&caveGlobals, caveGlobals.row, caveGlobals.col +1 ) == true ) {
				doclearstuff();
				dog(&caveGlobals);
				caveGlobals.col += 1;
				drawstuff(&caveGlobals);
				if (istrap(&caveGlobals, caveGlobals.row, caveGlobals.col ) == true ) {
					__os_snprintf(caveGlobals.mystat, 64, "Ouch!");
					drawString(25, 17, caveGlobals.mystat);
					caveGlobals.curhealth -= 1;
				}
				if (ishtrap(&caveGlobals, caveGlobals.row, caveGlobals.col ) == true ) {
					__os_snprintf(caveGlobals.mystat, 64, "Ouch!");
					drawString(25, 17, caveGlobals.mystat);
					caveGlobals.curhealth -= 1;
					caveGlobals.nMapArray[caveGlobals.col][caveGlobals.row] = 6;
				}
				flipBuffers();
			}
		}
		//Up
		if (vpad_data.btn_trigger & BUTTON_UP) {
			if (canmove(&caveGlobals, caveGlobals.row, caveGlobals.col -1 ) == true ) {
				doclearstuff();
				dog(&caveGlobals);
				caveGlobals.col -= 1;
				drawstuff(&caveGlobals);
				if (istrap(&caveGlobals, caveGlobals.row, caveGlobals.col ) == true ) {
					__os_snprintf(caveGlobals.mystat, 64, "Ouch!");
					drawString(25, 17, caveGlobals.mystat);
					caveGlobals.curhealth -= 1;
				}
				if (ishtrap(&caveGlobals, caveGlobals.row, caveGlobals.col ) == true ) {
					__os_snprintf(caveGlobals.mystat, 64, "Ouch!");
					drawString(25, 17, caveGlobals.mystat);
					caveGlobals.curhealth -= 1;
					caveGlobals.nMapArray[caveGlobals.col][caveGlobals.row] = 6;
				}
				flipBuffers();
			}
		}
		//Left
		if (vpad_data.btn_trigger & BUTTON_LEFT) {
			if (canmove(&caveGlobals, caveGlobals.row -1 , caveGlobals.col ) == true ) {
				doclearstuff();
				dog(&caveGlobals);
				caveGlobals.row -= 1;
				drawstuff(&caveGlobals);
				if (istrap(&caveGlobals, caveGlobals.row, caveGlobals.col ) == true ) {
					__os_snprintf(caveGlobals.mystat, 64, "Ouch!");
					drawString(25, 17, caveGlobals.mystat);
					caveGlobals.curhealth -= 1;
				}
				if (ishtrap(&caveGlobals, caveGlobals.row, caveGlobals.col ) == true ) {
					__os_snprintf(caveGlobals.mystat, 64, "Ouch!");
					drawString(25, 17, caveGlobals.mystat);
					caveGlobals.curhealth -= 1;
					caveGlobals.nMapArray[caveGlobals.col][caveGlobals.row] = 6;
				}
				flipBuffers();
			}
		}
		//Right
		if (vpad_data.btn_trigger & BUTTON_RIGHT) {
			if (canmove(&caveGlobals, caveGlobals.row +1 , caveGlobals.col ) == true ) {
				doclearstuff();
				dog(&caveGlobals);
				caveGlobals.row += 1;
				drawstuff(&caveGlobals);
				if (istrap(&caveGlobals, caveGlobals.row, caveGlobals.col ) == true ) {
					__os_snprintf(caveGlobals.mystat, 64, "Ouch!");
					drawString(25, 17, caveGlobals.mystat);
					caveGlobals.curhealth -= 1;
				}
				if (ishtrap(&caveGlobals, caveGlobals.row, caveGlobals.col ) == true ) {
					__os_snprintf(caveGlobals.mystat, 64, "Ouch!");
					drawString(25, 17, caveGlobals.mystat);
					caveGlobals.curhealth -= 1;
					caveGlobals.nMapArray[caveGlobals.col][caveGlobals.row] = 6;
				}
				flipBuffers();
			}
		}
		//Feed the doggy
		if (vpad_data.btn_trigger & BUTTON_PLUS) {
			if (caveGlobals.dogalive == 1) {
				if (caveGlobals.food >= 1) {
					doclearstuff();
					__os_snprintf(caveGlobals.mystat, 64, "*crunch* Woof!");
					drawString(24, 17, caveGlobals.mystat);
					caveGlobals.food -= 1;
					caveGlobals.dogsteps -= 60;
					//Make sure we don't go negative in dog health
					if (caveGlobals.dogsteps <= 0) { caveGlobals.dogsteps = 0;}
					drawstuff(&caveGlobals);
					dog(&caveGlobals);
					flipBuffers();
				}
			}

		}
		// Check if the player is dead
		if(caveGlobals.curhealth == 0) {
			doclearstuff();
			__os_snprintf(caveGlobals.endgame, 256, "You're Dead!\nNow how will you get iosu? :/ \n\nThanks for Playing! \n\n\nBy: SonyUSA");
			drawString(0, 0, caveGlobals.endgame);
			flipBuffers();
			t1 = 0x80000000;
			while(t1--) ;
			SYSLaunchMenu();
			_Exit();
		}
		// Cheat and go to next level with Minus key
		if(vpad_data.btn_release & BUTTON_MINUS) {
				caveGlobals.level += 1;
				doclearstuff();
				changelevel(&caveGlobals);
				drawstuff(&caveGlobals);
				flipBuffers();
		}
    }

}
예제 #18
0
void InitAcquireCurl(void)
{
    OSDynLoad_Acquire("nlibcurl", &libcurl_handle);
}
예제 #19
0
int GameLauncher::loadGameToMemory(const discHeader *header)
{
    if(!header)
        return INVALID_INPUT;

    //! initialize the RPL/RPX table first entry to zero + 1 byte for name zero termination
    //! just in case no RPL/RPX are found, though it wont boot then anyway
    memset(RPX_RPL_ARRAY, 0, sizeof(s_rpx_rpl) + 1);

	DirList rpxList(header->gamepath + RPX_RPL_PATH, ".rpx", DirList::Files);

	if(rpxList.GetFilecount() == 0)
    {
        log_printf("RPX file not found!\n");
        return RPX_NOT_FOUND;
    }
	if(rpxList.GetFilecount() != 1)
    {
        log_printf("Warning: Too many RPX files in the folder! Found %i files! Using first one.\n", rpxList.GetFilecount());
        //return TOO_MANY_RPX_NOT_FOUND;
    }

    u32 entryIndex = 0;
    std::string rpxName;
    std::vector<std::string> rplImportList;

    DirList rplList(header->gamepath + RPX_RPL_PATH, ".rpl", DirList::Files);

    int result = LoadRpxRplToMem(rpxList.GetFilepath(0), rpxList.GetFilename(0), true, entryIndex++, rplImportList);
    if(result < 0)
    {
        log_printf("Failed loading RPX file %s, error %i\n", rpxList.GetFilepath(0), result);
        return result;
    }

    rpxName = rpxList.GetFilename(0);

    //! get all imports from the RPX
    GetRpxImports((s_rpx_rpl *)(RPX_RPL_ARRAY), rplImportList);

    for(int i = 0; i < rplList.GetFilecount(); i++)
    {
        result = LoadRpxRplToMem(rplList.GetFilepath(i), rplList.GetFilename(i), false, entryIndex++, rplImportList);
        if(result < 0)
        {
            log_printf("Failed loading RPL file %s, error %i\n", rplList.GetFilepath(0), result);
            return result;
        }
    }

    //! TODO: clean this path creation up
    std::string game_dir = header->gamepath;
    size_t pos = game_dir.rfind('/');

    if(pos != std::string::npos)
        game_dir = game_dir.substr(pos + 1);

    //! set the save game path from the gamenames path
    std::string saveGamePath = CSettings::getValueAsString(CSettings::GameSavePath) + "/" + game_dir;
    std::string saveGamePathCommon;
    std::string saveGamePathUser;

    if(CSettings::getValueAsU8(CSettings::GameSaveMode) == GAME_SAVES_SHARED)
    {
        saveGamePathUser = "******";
        saveGamePathCommon = "c";
    }
    else
    {
        /* get persistent ID - thanks to Maschell */
        unsigned int nn_act_handle;
        unsigned long (*GetPersistentIdEx)(unsigned char);
        int (*GetSlotNo)(void);
        void (*nn_Initialize)(void);
        void (*nn_Finalize)(void);
        OSDynLoad_Acquire("nn_act.rpl", &nn_act_handle);
        OSDynLoad_FindExport(nn_act_handle, 0, "GetPersistentIdEx__Q2_2nn3actFUc", &GetPersistentIdEx);
        OSDynLoad_FindExport(nn_act_handle, 0, "GetSlotNo__Q2_2nn3actFv", &GetSlotNo);
        OSDynLoad_FindExport(nn_act_handle, 0, "Initialize__Q2_2nn3actFv", &nn_Initialize);
        OSDynLoad_FindExport(nn_act_handle, 0, "Finalize__Q2_2nn3actFv", &nn_Finalize);

        nn_Initialize(); // To be sure that it is really Initialized

        unsigned char slotno = GetSlotNo();
        unsigned int persistentID = GetPersistentIdEx(slotno);
        nn_Finalize(); //must be called an equal number of times to nn_Initialize

        char persistentIdString[10];
        snprintf(persistentIdString, sizeof(persistentIdString), "%08X", persistentID);

        saveGamePathUser = persistentIdString;
        saveGamePathCommon = "common";
    }

    CreateSubfolder((saveGamePath + "/" + saveGamePathUser).c_str());
    CreateSubfolder((saveGamePath + "/" + saveGamePathCommon).c_str());

    std::string tempPath = CSettings::getValueAsString(CSettings::GamePath);
    //! remove "sd:" and replace with "/vol/external01"
    pos = tempPath.find('/');
    if(pos != std::string::npos)
        tempPath = std::string(CAFE_OS_SD_PATH) + tempPath.substr(pos);

    game_paths_t *game_paths = (game_paths_t *)GAME_PATH_STRUCT;

    //! set pointer to firth path and copy it
    game_paths->os_game_path_base = (char*)(game_paths + 1);
    strcpy(game_paths->os_game_path_base, tempPath.c_str());

    //! set pointer to next path and copy it
    game_paths->os_save_path_base = game_paths->os_game_path_base + tempPath.size() + 1;

    tempPath = CSettings::getValueAsString(CSettings::GameSavePath);
    //! remove "sd:" and replace with "/vol/external01"
    pos = tempPath.find('/');
    if(pos != std::string::npos)
        tempPath = std::string(CAFE_OS_SD_PATH) + tempPath.substr(pos);

    strcpy(game_paths->os_save_path_base, tempPath.c_str());

    //! set pointer to next path and copy it
    game_paths->game_dir = game_paths->os_save_path_base + tempPath.size() + 1;
    strcpy(game_paths->game_dir, game_dir.c_str());

    //! set pointer to next path and copy it
    game_paths->save_dir_common = game_paths->game_dir + game_dir.size() + 1;
    strcpy(game_paths->save_dir_common, saveGamePathCommon.c_str());

    //! set pointer to next path and copy it
    game_paths->save_dir_user = game_paths->save_dir_common + saveGamePathCommon.size() + 1;
    strcpy(game_paths->save_dir_user, saveGamePathUser.c_str());

    log_printf("game_paths->os_game_path_base: %s\n", game_paths->os_game_path_base);
    log_printf("game_paths->os_save_path_base: %s\n", game_paths->os_save_path_base);
    log_printf("game_paths->game_dir:          %s\n", game_paths->game_dir);
    log_printf("game_paths->save_dir_common:   %s\n", game_paths->save_dir_common);
    log_printf("game_paths->save_dir_user:     %s\n", game_paths->save_dir_user);

    LoadXmlParameters(&cosAppXmlInfoStruct, rpxName.c_str(), (header->gamepath + RPX_RPL_PATH).c_str());

    DCFlushRange((void*)&cosAppXmlInfoStruct, sizeof(ReducedCosAppXmlInfo));

    log_printf("XML Launching Parameters\n");
    log_printf("rpx_name:        %s\n", cosAppXmlInfoStruct.rpx_name);
    log_printf("version_cos_xml: %i\n", cosAppXmlInfoStruct.version_cos_xml);
    log_printf("os_version:      %08X%08X\n", (unsigned int)(cosAppXmlInfoStruct.os_version >> 32), (unsigned int)(cosAppXmlInfoStruct.os_version & 0xFFFFFFFF));
    log_printf("title_id:        %08X%08X\n", (unsigned int)(cosAppXmlInfoStruct.title_id >> 32), (unsigned int)(cosAppXmlInfoStruct.title_id & 0xFFFFFFFF));
    log_printf("app_type:        %08X\n", cosAppXmlInfoStruct.app_type);
    log_printf("cmdFlags:        %08X\n", cosAppXmlInfoStruct.cmdFlags);
    log_printf("max_size:        %08X\n", cosAppXmlInfoStruct.max_size);
    log_printf("avail_size:      %08X\n", cosAppXmlInfoStruct.avail_size);
    log_printf("codegen_size:    %08X\n", cosAppXmlInfoStruct.codegen_size);
    log_printf("codegen_core:    %08X\n", cosAppXmlInfoStruct.codegen_core);
    log_printf("max_codesize:    %08X\n", cosAppXmlInfoStruct.max_codesize);
    log_printf("overlay_arena:   %08X\n", cosAppXmlInfoStruct.overlay_arena);
    log_printf("sdk_version:     %i\n", cosAppXmlInfoStruct.sdk_version);
    log_printf("title_version:   %08X\n", cosAppXmlInfoStruct.title_version);

    return 0;
}
예제 #20
0
void GameLauncher::GetRpxImports(s_rpx_rpl *rpx_data, std::vector<std::string> & rplImports)
{
    std::string strBuffer;
    strBuffer.resize(0x1000);

    // get the header information of the RPX
    if(!GetMemorySegment(rpx_data, 0, 0x1000, (unsigned char *)&strBuffer[0]))
        return;

    // Who needs error checks...
    // Get section number
    int shstrndx = *(unsigned short*)(&strBuffer[RPX_SH_STRNDX_OFFSET]);
    // Get section offset
    int section_offset = *(unsigned int*)(&strBuffer[RPX_SHT_START + (shstrndx * RPX_SHT_ENTRY_SIZE) + RPX_SHDR_OFFSET_OFFSET]);
    // Get section size
    int section_size = *(unsigned int*)(&strBuffer[RPX_SHT_START + (shstrndx * RPX_SHT_ENTRY_SIZE) + RPX_SHDR_SIZE_OFFSET]);
    // Get section flags
    int section_flags = *(unsigned int*)(&strBuffer[RPX_SHT_START + (shstrndx * RPX_SHT_ENTRY_SIZE) + RPX_SHDR_FLAGS_OFFSET]);

    // Align read to 64 for SD access (section offset already aligned to 64 @ elf/rpx?!)
    int section_offset_aligned = (section_offset / 64) * 64;
    int section_alignment = section_offset - section_offset_aligned;
    int section_size_aligned = ((section_alignment + section_size) / 64) * 64 + 64;

    std::string section_data;
    section_data.resize(section_size_aligned);

    // get the header information of the RPX
    if(!GetMemorySegment(rpx_data, section_offset_aligned, section_size_aligned, (unsigned char *)&section_data[0]))
        return;

    //Check if inflate is needed (ZLIB flag)
    if (section_flags & RPX_SHDR_ZLIB_FLAG)
    {
        // Section is compressed, inflate
        int section_size_inflated = *(unsigned int*)(&section_data[section_alignment]);
        std::string inflatedData;
        inflatedData.resize(section_size_inflated);

        unsigned int zlib_handle;
        OSDynLoad_Acquire("zlib125", &zlib_handle);

        /* Zlib functions */
        int(*ZinflateInit_)(z_streamp strm, const char *version, int stream_size);
        int(*Zinflate)(z_streamp strm, int flush);
        int(*ZinflateEnd)(z_streamp strm);

        OSDynLoad_FindExport(zlib_handle, 0, "inflateInit_", &ZinflateInit_);
        OSDynLoad_FindExport(zlib_handle, 0, "inflate", &Zinflate);
        OSDynLoad_FindExport(zlib_handle, 0, "inflateEnd", &ZinflateEnd);

        int ret = 0;
        z_stream s;
        memset(&s, 0, sizeof(s));

        s.zalloc = Z_NULL;
        s.zfree = Z_NULL;
        s.opaque = Z_NULL;

        ret = ZinflateInit_(&s, ZLIB_VERSION, sizeof(s));
        if (ret != Z_OK)
            return;

        s.avail_in = section_size - 0x04;
        s.next_in = (Bytef *)(&section_data[0] + section_alignment + 0x04);

        s.avail_out = section_size_inflated;
        s.next_out = (Bytef *)&inflatedData[0];

        ret = Zinflate(&s, Z_FINISH);
        if (ret != Z_OK && ret != Z_STREAM_END)
            return;

        ZinflateEnd(&s);
        section_data.swap(inflatedData);
    }

    // Parse imports
    size_t offset = 0;
    do
    {
        if (strncmp(&section_data[offset+1], ".fimport_", 9) == 0)
        {
            rplImports.push_back(std::string(&section_data[offset+1+9]));
        }
        offset++;
        while (section_data[offset] != 0) {
            offset++;
        }
    } while(offset + 1 < section_data.size());
}
예제 #21
0
void InitAcquireACP(void)
{
    OSDynLoad_Acquire("nn_acp.rpl", &acp_handle);
}
예제 #22
0
파일: loader.c 프로젝트: vgmoose/space
void _start()
{
	/****************************>            Fix Stack            <****************************/
	//Load a good stack
	asm(
		"lis %r1, 0x1ab5 ;"
		"ori %r1, %r1, 0xd138 ;"
		);
	/****************************>           Get Handles           <****************************/
	//Get a handle to coreinit.rpl
	unsigned int coreinit_handle, avm_handle;
	OSDynLoad_Acquire("coreinit.rpl", &coreinit_handle);
	// CreeperMario: Get a handle to the audio/video manager - avm.rpl
	OSDynLoad_Acquire("avm.rpl", &avm_handle);
	/****************************>       External Prototypes       <****************************/
	//OSScreen functions
	void(*OSScreenInit)();
	unsigned int(*OSScreenGetBufferSizeEx)(unsigned int bufferNum);
	unsigned int(*OSScreenSetBufferEx)(unsigned int bufferNum, void * addr);
	//OS Memory functions
	void*(*memset)(void * dest, uint32_t value, uint32_t bytes);
	void*(*OSAllocFromSystem)(uint32_t size, int align);
	void(*OSFreeToSystem)(void *ptr);
	//IM functions
	int(*IM_Open)();
	int(*IM_Close)(int fd);
	int(*IM_SetDeviceState)(int fd, void *mem, int state, int a, int b);
	// CreeperMario: Audio/Video manager functions
	bool(*AVMSetTVScale)(int width, int height);
	/****************************>             Exports             <****************************/
	//OSScreen functions
	OSDynLoad_FindExport(coreinit_handle, 0, "OSScreenInit", &OSScreenInit);
	OSDynLoad_FindExport(coreinit_handle, 0, "OSScreenGetBufferSizeEx", &OSScreenGetBufferSizeEx);
	OSDynLoad_FindExport(coreinit_handle, 0, "OSScreenSetBufferEx", &OSScreenSetBufferEx);
	//OS Memory functions
	OSDynLoad_FindExport(coreinit_handle, 0, "memset", &memset);
	OSDynLoad_FindExport(coreinit_handle, 0, "OSAllocFromSystem", &OSAllocFromSystem);
	OSDynLoad_FindExport(coreinit_handle, 0, "OSFreeToSystem", &OSFreeToSystem);
	//IM functions
	OSDynLoad_FindExport(coreinit_handle, 0, "IM_Open", &IM_Open);
	OSDynLoad_FindExport(coreinit_handle, 0, "IM_Close", &IM_Close);
	OSDynLoad_FindExport(coreinit_handle, 0, "IM_SetDeviceState", &IM_SetDeviceState);
	// CreeperMario: Audio/Video manager functions
	OSDynLoad_FindExport(avm_handle, 0, "AVMSetTVScale", &AVMSetTVScale);

	/*** CreeperMario: Set the TV Screen's 'scale factor'. ***/
	AVMSetTVScale(854, 480);

	/****************************>          Initial Setup          <****************************/
	//Restart system to get lib access
	int fd = IM_Open();
	void *mem = OSAllocFromSystem(0x100, 64);
	memset(mem, 0, 0x100);
	//set restart flag to force quit browser
	IM_SetDeviceState(fd, mem, 3, 0, 0);
	IM_Close(fd);
	OSFreeToSystem(mem);
	//wait a bit for browser end
	unsigned int t1 = 0x1FFFFFFF;
	while(t1--) ;
	//Call the Screen initilzation function.
	OSScreenInit();
	//Grab the buffer size for each screen (TV and gamepad)
	int buf0_size = OSScreenGetBufferSizeEx(0);
	int buf1_size = OSScreenGetBufferSizeEx(1);
	//Set the buffer area.
	OSScreenSetBufferEx(0, (void *)0xF4000000);
	OSScreenSetBufferEx(1, (void *)0xF4000000 + buf0_size);
	//Clear both framebuffers.
	// I don't do this here, and do it at the start of entry point to use my services struct
//	int ii = 0;
//	for (ii; ii < 2; ii++)
//	{
//		fillScreen(0,0,0,0);
//		flipBuffers();
//	}
	//Jump to entry point.
	_entryPoint();
}
예제 #23
0
void _entryPoint()
{
	/****************************>           Get Handles           <****************************/
	//Get a handle to coreinit.rpl
	unsigned int coreinit_handle;
	OSDynLoad_Acquire("coreinit.rpl", &coreinit_handle);
	//Get a handle to vpad.rpl */
	unsigned int vpad_handle;
	OSDynLoad_Acquire("vpad.rpl", &vpad_handle);
	/****************************>       External Prototypes       <****************************/
	//VPAD functions
	int(*VPADRead)(int controller, VPADData *buffer, unsigned int num, int *error);
	//OS functions
	void(*_Exit)();
	/****************************>             Exports             <****************************/
	//VPAD functions
	OSDynLoad_FindExport(vpad_handle, 0, "VPADRead", &VPADRead);
	//OS functions
	OSDynLoad_FindExport(coreinit_handle, 0, "_Exit", &_Exit);
	/****************************>             Function            <****************************/
	int error;
	VPADData vpad_data;
	int xpos, ypos;
	int q = 1;
	int r = 128;
	int g = 128;
	int b = 255;
	int color = 2;
	
	/* enum colors {
		color_white;
		color_grey;
		color_lightblue;
		color_lightgreen;
		color_lightred;
	}; all available choices */
	while (1)
	{
		VPADRead(0, &vpad_data, 1, &error);
		if (vpad_data.tpdata.touched == 1)
		{
			xpos = ((vpad_data.tpdata.x / 9) - 11);
			ypos = ((3930 - vpad_data.tpdata.y) / 16);

			drawPixel(xpos, ypos, r, g, b, 255);
			flipBuffers();
			drawPixel(xpos, ypos, r, g, b, 255);
			flipBuffers();
		}
		
		if (vpad_data.btn_trigger & BUTTON_LEFT) //seems to pick random one, no idea why
		{
			if (color == 0) //white
			{
				color = 4; //light red
			} else {
				color -= 1; //go down one
			}
			
			if (color == 0){ //white
				r = 255;
				g = 255;
				b = 255;
			}
			if (color == 1){ //grey
				r = 128;
				g = 128;
				b = 128;
			}
			if (color == 2){ //light blue
				r = 128;
				g = 128;
				b = 255;
			}
			if (color == 3){ //light green
				r = 128;
				g = 255;
				b = 128;
			}
			if (color == 4){ //light red
				r = 255;
				g = 128;
				b = 128;
			}
		}
		
		if (vpad_data.btn_trigger & BUTTON_RIGHT) //seems to pick random one, no idea why
		{
			if (color == 4) //light red
			{
				color = 0;  //white
			} else {
				color += 1; //go up one
			}
			
			if (color == 0){ //white
				r = 255;
				g = 255;
				b = 255;
			}
			if (color == 1){ //grey
				r = 128;
				g = 128;
				b = 128;
			}
			if (color == 2){ //light blue
				r = 128;
				g = 128;
				b = 255;
			}
			if (color == 3){ //light green
				r = 128;
				g = 255;
				b = 128;
			}
			if (color == 4){ //light red
				r = 255;
				g = 128;
				b = 128;
			}
		}
		
		if (vpad_data.btn_hold & BUTTON_PLUS)
		{
			fillScreen(0, 0, 0, 255); // black
			flipBuffers();
			fillScreen(0, 0, 0, 255); // second buffer
			flipBuffers();
		}

		if (vpad_data.btn_trigger & BUTTON_HOME)
		{
		break; //pls exit
		}
	}
	//WARNING: DO NOT CHANGE THIS. YOU MUST CLEAR THE FRAMEBUFFERS AND IMMEDIATELY CALL EXIT FROM THIS FUNCTION. RETURNING TO LOADER CAUSES FREEZE.
	int ii=0;
	for(ii;ii<2;ii++)
	{
		fillScreen(0,0,0,0);
		flipBuffers();
	}
	_Exit();
}
예제 #24
0
void InitAcquireSys(void)
{
    OSDynLoad_Acquire("sysapp.rpl", &sysapp_handle);
}
예제 #25
0
void _start()
{
  /* Load a good stack */
  asm(
      "lis %r1, 0x1ab5 ;"
      "ori %r1, %r1, 0xd138 ;"
  );
 
  /* Get a handle to coreinit.rpl, dmae.rpl, and nsysnet.rpl */
  unsigned int coreinit_handle, dmae_handle, nsysnet_handle;
  OSDynLoad_Acquire("coreinit.rpl", &coreinit_handle);
  OSDynLoad_Acquire("dmae.rpl", &dmae_handle);
  OSDynLoad_Acquire("nsysnet.rpl", &nsysnet_handle);

  /* Cache, DMA, and socket functions */
  void (*DCFlushRange)(void *addr, unsigned int length);
  void (*DCInvalidateRange)(void *addr, unsigned int length);
  unsigned long long (*DMAECopyMem)(void *dst, void *src, unsigned int nwords, int endian);
  int (*DMAEWaitDone)(unsigned long long ret);
  int (*socket)(int family, int type, int proto);
  int (*connect)(int fd, struct sockaddr *addr, int addrlen);
  int (*send)(int fd, const void *buffer, int len, int flags);

  /* Read the addresses of the functions */
  OSDynLoad_FindExport(coreinit_handle, 0, "DCFlushRange", &DCFlushRange);
  OSDynLoad_FindExport(coreinit_handle, 0, "DCInvalidateRange", &DCInvalidateRange);
  OSDynLoad_FindExport(dmae_handle, 0, "DMAECopyMem", &DMAECopyMem);
  OSDynLoad_FindExport(dmae_handle, 0, "DMAEWaitDone", &DMAEWaitDone);
  OSDynLoad_FindExport(nsysnet_handle, 0, "socket", &socket);
  OSDynLoad_FindExport(nsysnet_handle, 0, "connect", &connect);
  OSDynLoad_FindExport(nsysnet_handle, 0, "send", &send);

  /* Set up our socket address structure */
  struct sockaddr sin;
  sin.sin_family = AF_INET;
  sin.sin_port = 12345;
  sin.sin_addr.s_addr = PC_IP;
  int i;
  for (i = 0; i < 8; i++)
  {
    sin.sin_zero[i] = 0;
  }

  /* Connect to the PC */
  int pc = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
  int status = connect(pc, &sin, 0x10);
  if (status) OSFatal("Error connecting to PC server");

  /* Cache stuff */
  DCFlushRange(0x01000000, 0x20);
  DCInvalidateRange(0x1dd7b820, 0x20);

  /* Do the copy */
  int success = DMAEWaitDone(DMAECopyMem(0x1dd7b820, 0x01000000, 2, 0));
  if (success)
  {
	  send(pc, "Success", 8, 0);
  }
  else
  {
	  send(pc, "Fail", 5, 0);
  }
  while(1);
}
예제 #26
0
void InitAcquireVPad(void)
{
    OSDynLoad_Acquire("vpad.rpl", &vpad_handle);
    OSDynLoad_Acquire("vpadbase.rpl", &vpadbase_handle);
}
예제 #27
0
void _start()
{
	/* Get a handle to coreinit.rpl */
	unsigned int coreinit_handle;
	OSDynLoad_Acquire("coreinit.rpl", &coreinit_handle);
	//OS memory functions
	void* (*memcpy)(void *dest, void *src, uint32_t length);
	void* (*memset)(void * dest, uint32_t value, uint32_t bytes);
	void* (*OSAllocFromSystem)(uint32_t size, int align);
	void (*OSFreeToSystem)(void *ptr);
	OSDynLoad_FindExport(coreinit_handle, 0, "memcpy", &memcpy);
	OSDynLoad_FindExport(coreinit_handle, 0, "memset", &memset);
	OSDynLoad_FindExport(coreinit_handle, 0, "OSAllocFromSystem", &OSAllocFromSystem);
	OSDynLoad_FindExport(coreinit_handle, 0, "OSFreeToSystem", &OSFreeToSystem);
	
	void (*OSCoherencyBarrier)();
	OSDynLoad_FindExport(coreinit_handle, 0, "OSCoherencyBarrier", &OSCoherencyBarrier);
	
	void (*_Exit)();
	OSDynLoad_FindExport(coreinit_handle, 0, "_Exit", &_Exit);
	
	//DC memory functions
	void (*DCFlushRangeNoSync)(void *buffer, uint32_t length);
	void (*DCInvalidateRange)(void *buffer, uint32_t length);
  	OSDynLoad_FindExport(coreinit_handle, 0, "DCFlushRangeNoSync", &DCFlushRangeNoSync);
	OSDynLoad_FindExport(coreinit_handle, 0, "DCInvalidateRange", &DCInvalidateRange);
	
	//LC memory functions
	void* (*LCAlloc)( uint32_t bytes );
	void (*LCDealloc)();
	uint32_t (*LCHardwareIsAvailable)();
	uint32_t (*LCIsDMAEnabled)();
	void (*LCEnableDMA)();
	void (*LCDisableDMA)();
	void (*LCLoadDMABlocks)(void* lc_addr, void* src_addr, uint32_t blocks);
	void (*LCStoreDMABlocks)(void* dest_addr, void* lc_addr, uint32_t blocks);
	void (*LCWaitDMAQueue)( uint32_t length );
	OSDynLoad_FindExport(coreinit_handle, 0, "LCAlloc", &LCAlloc);
	OSDynLoad_FindExport(coreinit_handle, 0, "LCDealloc", &LCDealloc);
	OSDynLoad_FindExport(coreinit_handle, 0, "LCHardwareIsAvailable", &LCHardwareIsAvailable);
	OSDynLoad_FindExport(coreinit_handle, 0, "LCIsDMAEnabled", &LCIsDMAEnabled);
	OSDynLoad_FindExport(coreinit_handle, 0, "LCEnableDMA", &LCEnableDMA);
	OSDynLoad_FindExport(coreinit_handle, 0, "LCDisableDMA", &LCDisableDMA);
	OSDynLoad_FindExport(coreinit_handle, 0, "LCLoadDMABlocks", &LCLoadDMABlocks);
	OSDynLoad_FindExport(coreinit_handle, 0, "LCStoreDMABlocks", &LCStoreDMABlocks);
	OSDynLoad_FindExport(coreinit_handle, 0, "LCWaitDMAQueue", &LCWaitDMAQueue);
		
	//Used for keeping track of vairables to print to screen
	char output[1000];
	
	//Alloc 64 byte alligned space
	void* src_addr=OSAllocFromSystem(512,64);
	void* dest_addr=OSAllocFromSystem(512,64);
	
	//Store some debug values
	__os_snprintf(output, 1000, "src_addr:%02x,",(uint32_t)src_addr);
	__os_snprintf(output+strlen(output), 255, "dest_addr: %02x,", (uint32_t)dest_addr);
	
	//Number of 32bit blocks to copy. Must be multiple of 2 between [0,127]
	uint32_t blocks=2; //2 32bit blocks
	
	//Do something to the source
	memset(src_addr,1,64);
	
	//Grab values for debug
	uint32_t * src_val=src_addr;
	uint32_t * dest_val=dest_addr;
	__os_snprintf(output+strlen(output), 255, "Old src_val: %02x\n",src_val[0]);
	__os_snprintf(output+strlen(output), 255, "Old dest_val: %02x,",dest_val[0]);
	
	//Get some locked cache address space
	void *lc_addr=LCAlloc(512); //512 Minmum. Must be multiple of 512.
	
	//Calculate size from blocks to flush/invalidate range properly
	uint32_t size;
	//If blocks is set to 0, the transaction will default to 128 blocks
	if(blocks==0)
	{
		size=32*128;
	}
	else
	{
		size=32*blocks;
	}
	//Flush the range at the source to ensure cache gets written back to memory.
	DCFlushRangeNoSync(src_addr,size);
	//Invalidate the range at the destination
	DCInvalidateRange(dest_addr,size);
	//Sync
	OSCoherencyBarrier();
	
	//Check to see of DMA hardware is avaliable
	if(LCHardwareIsAvailable()!=1)
	{
		OSFatal("Hardware is not avaliable.");
	}

	//Gets the current state of DMA, so we can restore it after our copy
	uint32_t dmaState=LCIsDMAEnabled();

	//Checks to see if DMA is enabled, if not it will try to enable it.
	if(dmaState!=1)
	{
		LCEnableDMA();
		dmaState=LCIsDMAEnabled();
		if(dmaState!=1)
		{
			OSFatal("Can't enable DMA");
		}
	}
	
	//Load memory to locked cache
	LCLoadDMABlocks(lc_addr,src_addr,blocks);
	LCWaitDMAQueue(0);
	
	//Store memory from locked cache
	LCStoreDMABlocks(dest_addr,lc_addr,blocks);
	LCWaitDMAQueue(0);

	//If DMA was not previously enabled, then disable it to restore state.
	if(dmaState!=1)
	{
		LCDisableDMA();
		dmaState=LCIsDMAEnabled();
		//If DMA failed to disable, return error code
		if(dmaState!=1)
		{
			OSFatal("Couldn't Disable DMA");
		}
	}
	__os_snprintf(output+strlen(output), 255, "New src_val: %02x,",src_val[0]);
	__os_snprintf(output+strlen(output), 255, "New dest_val: %02x,",dest_val[0]);
	
	//Cleanup
	LCDealloc(lc_addr);
	OSFreeToSystem(dest_addr);
	OSFreeToSystem(src_addr);
    OSFatal(output);
}
예제 #28
0
void InitGX2FunctionPointers(void)
{
    unsigned int *funcPointer = 0;
    unsigned int gx2_handle;
    OSDynLoad_Acquire("gx2.rpl", &gx2_handle);

    OS_FIND_EXPORT(gx2_handle, GX2Init);
    OS_FIND_EXPORT(gx2_handle, GX2Shutdown);
    OS_FIND_EXPORT(gx2_handle, GX2Flush);
    OS_FIND_EXPORT(gx2_handle, GX2GetMainCoreId);
    OS_FIND_EXPORT(gx2_handle, GX2DrawDone);
    OS_FIND_EXPORT(gx2_handle, GX2ClearColor);
    OS_FIND_EXPORT(gx2_handle, GX2SetViewport);
    OS_FIND_EXPORT(gx2_handle, GX2SetScissor);
    OS_FIND_EXPORT(gx2_handle, GX2SetContextState);
    OS_FIND_EXPORT(gx2_handle, GX2DrawEx);
    OS_FIND_EXPORT(gx2_handle, GX2DrawIndexedEx);
    OS_FIND_EXPORT(gx2_handle, GX2ClearDepthStencilEx);
    OS_FIND_EXPORT(gx2_handle, GX2CopyColorBufferToScanBuffer);
    OS_FIND_EXPORT(gx2_handle, GX2SwapScanBuffers);
    OS_FIND_EXPORT(gx2_handle, GX2SetTVEnable);
    OS_FIND_EXPORT(gx2_handle, GX2SetSwapInterval);
    OS_FIND_EXPORT(gx2_handle, GX2GetSwapInterval);
    OS_FIND_EXPORT(gx2_handle, GX2WaitForVsync);
    OS_FIND_EXPORT(gx2_handle, GX2CalcTVSize);
    OS_FIND_EXPORT(gx2_handle, GX2Invalidate);
    OS_FIND_EXPORT(gx2_handle, GX2SetTVBuffer);
    OS_FIND_EXPORT(gx2_handle, GX2CalcSurfaceSizeAndAlignment);
    OS_FIND_EXPORT(gx2_handle, GX2InitDepthBufferRegs);
    OS_FIND_EXPORT(gx2_handle, GX2InitColorBufferRegs);
    OS_FIND_EXPORT(gx2_handle, GX2CalcColorBufferAuxInfo);
    OS_FIND_EXPORT(gx2_handle, GX2CalcDepthBufferHiZInfo);
    OS_FIND_EXPORT(gx2_handle, GX2InitDepthBufferHiZEnable);
//    OS_FIND_EXPORT(gx2_handle, GX2SetSpecialState);
    OS_FIND_EXPORT(gx2_handle, GX2SetupContextStateEx);
    OS_FIND_EXPORT(gx2_handle, GX2SetColorBuffer);
    OS_FIND_EXPORT(gx2_handle, GX2SetDepthBuffer);
    OS_FIND_EXPORT(gx2_handle, GX2SetAttribBuffer);
    OS_FIND_EXPORT(gx2_handle, GX2InitTextureRegs);
    OS_FIND_EXPORT(gx2_handle, GX2InitSampler);
    OS_FIND_EXPORT(gx2_handle, GX2CalcFetchShaderSizeEx);
    OS_FIND_EXPORT(gx2_handle, GX2InitFetchShaderEx);
    OS_FIND_EXPORT(gx2_handle, GX2SetFetchShader);
    OS_FIND_EXPORT(gx2_handle, GX2SetVertexUniformReg);
    OS_FIND_EXPORT(gx2_handle, GX2SetPixelUniformReg);
    OS_FIND_EXPORT(gx2_handle, GX2SetPixelTexture);
    OS_FIND_EXPORT(gx2_handle, GX2SetVertexTexture);
    OS_FIND_EXPORT(gx2_handle, GX2SetPixelSampler);
    OS_FIND_EXPORT(gx2_handle, GX2SetVertexSampler);
    OS_FIND_EXPORT(gx2_handle, GX2SetPixelShader);
    OS_FIND_EXPORT(gx2_handle, GX2SetVertexShader);
    OS_FIND_EXPORT(gx2_handle, GX2InitSamplerZMFilter);
//    OS_FIND_EXPORT(gx2_handle, GX2SetClearDepth);
//    OS_FIND_EXPORT(gx2_handle, GX2SetClearStencil);
    OS_FIND_EXPORT(gx2_handle, GX2SetColorControl);
    OS_FIND_EXPORT(gx2_handle, GX2SetDepthOnlyControl);
    OS_FIND_EXPORT(gx2_handle, GX2SetBlendControl);
    OS_FIND_EXPORT(gx2_handle, GX2CalcDRCSize);
    OS_FIND_EXPORT(gx2_handle, GX2SetDRCBuffer);
    OS_FIND_EXPORT(gx2_handle, GX2SetDRCScale);
    OS_FIND_EXPORT(gx2_handle, GX2SetDRCEnable);
    OS_FIND_EXPORT(gx2_handle, GX2SetPolygonControl);
    OS_FIND_EXPORT(gx2_handle, GX2SetCullOnlyControl);
    OS_FIND_EXPORT(gx2_handle, GX2SetDepthStencilControl);
    OS_FIND_EXPORT(gx2_handle, GX2SetStencilMask);
    OS_FIND_EXPORT(gx2_handle, GX2SetLineWidth);
    OS_FIND_EXPORT(gx2_handle, GX2SetDRCGamma);
    OS_FIND_EXPORT(gx2_handle, GX2SetTVGamma);
    OS_FIND_EXPORT(gx2_handle, GX2GetSystemTVScanMode);
    OS_FIND_EXPORT(gx2_handle, GX2GetSystemDRCScanMode);
    OS_FIND_EXPORT(gx2_handle, GX2RSetAllocator);
}
예제 #29
0
파일: loader.c 프로젝트: dibas/smashd
void _start() 
{
    /* Load a good stack */
    asm(
        "lis %r1, 0x1ab5 ;"
        "ori %r1, %r1, 0xd138 ;"
    );

	/* Get a handle to coreinit.rpl */
	uint32_t coreinit_h;
	OSDynLoad_Acquire("coreinit.rpl", &coreinit_h);

	/* Memory allocation and FS functions */
	void* (*OSAllocFromSystem)(uint32_t size, int align);
	int (*FSInit)();
	int (*FSAddClient)(void *client, int unk1);
	int (*FSInitCmdBlock)(void *cmd);
	int (*FSOpenDir)(void *client, void *cmd, char *path, uint32_t *dir_handle, int unk1);
	int (*FSReadDir)(void *client, void *cmd, uint32_t dir_handle, void *buffer, int unk1);
	
	int (*FSGetMountSource)(void *client, void *cmd, int type, mount_source *source, int unk1);
	int (*FSMount)(void *client, void *cmd, mount_source *source, char *mountpath, uint32_t pathlength, int unk1);
	int (*FSOpenFile)(void *client, void *cmd, char *filepath, char *amode, uint32_t *file_handle, int unk1);
	int (*FSReadFile)(void *client, void *cmd, void *buffer, uint32_t size, uint32_t length, uint32_t file_handle, int unk1, int unk2);

	OSDynLoad_FindExport(coreinit_h, 0, "OSAllocFromSystem", &OSAllocFromSystem);
	OSDynLoad_FindExport(coreinit_h, 0, "FSInit", &FSInit);
	OSDynLoad_FindExport(coreinit_h, 0, "FSAddClient", &FSAddClient);
	OSDynLoad_FindExport(coreinit_h, 0, "FSInitCmdBlock", &FSInitCmdBlock);
	OSDynLoad_FindExport(coreinit_h, 0, "FSOpenDir", &FSOpenDir);
	OSDynLoad_FindExport(coreinit_h, 0, "FSReadDir", &FSReadDir);

	OSDynLoad_FindExport(coreinit_h, 0, "FSGetMountSource", &FSGetMountSource);
	OSDynLoad_FindExport(coreinit_h, 0, "FSMount", &FSMount);
	OSDynLoad_FindExport(coreinit_h, 0, "FSOpenFile", &FSOpenFile);
	OSDynLoad_FindExport(coreinit_h, 0, "FSReadFile", &FSReadFile);

	FSInit();

	/* Set up the client and command blocks */
	void *client = OSAllocFromSystem(0x1700, 0x20);
	void *cmd = OSAllocFromSystem(0xA80, 0x20);
	if (!(client && cmd)) OSFatal("Failed to allocate client and command block");

	FSAddClient(client, 0);
	FSInitCmdBlock(cmd);

	// todo: check permissions and throw exception if no mounting permissions available

	// OSLockMutex - Probably not. It's a single thread, nothing else can access this, Cross-F does this here
	mount_source m_source; // allocate mount source

	int ms_result = FSGetMountSource(client, cmd, 0, &m_source, 0); // type 0 = external device

	if(ms_result != 0) {
		char buf[256];
		__os_snprintf(buf, 256, "FSGetMountSource returned error code %d", ms_result);
		OSFatal(buf);
	}

	char mountPath[128]; // usually /vol/external01
	int m_result = FSMount(client, cmd, &m_source, mountPath, sizeof(mountPath), -1); 

	if(m_result != 0) {
		char buf[256];
		__os_snprintf(buf, 256, "FSMount returned error code %d", m_result);
		OSFatal(buf);
	}
	// OSUnlockMutex

	char defaultMountPath[] = "/vol/external01";

	if(!strcmp(mountPath, defaultMountPath)) {
		char buf[256];
		__os_snprintf(buf, 256, "FSMount returned nonstandard mount path: %s", mountPath);
		OSFatal(buf);
	}

	uint32_t file_handle;
	int open_result = FSOpenFile(client, cmd, "/vol/external01/SMASHD.txt", "r", &file_handle, 0);

	if(open_result != 0) {
		char buf[256];
		__os_snprintf(buf, 256, "FSOpenFile returned error code %d", open_result);
		OSFatal(buf);
	}

	uint32_t *file_buffer = OSAllocFromSystem(0x200, 0x20);
	int read_result = FSReadFile(client, cmd, file_buffer, 1, 25, file_handle, 0, -1); // todo: is size correct? one char one byte; read whole file, not just a few bytes

	if(read_result != 0) {
		char buf[256];
		__os_snprintf(buf, 256, "FSReadFile returned error code %d", read_result);
		OSFatal(buf);
	}

	char *message = (char*)&file_buffer[25];
	OSFatal(message);
}
예제 #30
0
void _entryPoint()
{
	/****************************>           Get Handles           <****************************/
	//Get a handle to coreinit.rpl
	unsigned int coreinit_handle;
	OSDynLoad_Acquire("coreinit.rpl", &coreinit_handle);
	//Get a handle to vpad.rpl */
	unsigned int vpad_handle;
	OSDynLoad_Acquire("vpad.rpl", &vpad_handle);
	/****************************>       External Prototypes       <****************************/
	//VPAD functions
	int(*VPADRead)(int controller, VPADData *buffer, unsigned int num, int *error);
	//OS functions
	void(*_Exit)();
	/****************************>             Exports             <****************************/
	//VPAD functions
	OSDynLoad_FindExport(vpad_handle, 0, "VPADRead", &VPADRead);
	//OS functions
	OSDynLoad_FindExport(coreinit_handle, 0, "_Exit", &_Exit);
	/****************************>             Globals             <****************************/
	struct renderFlags flags;
	flags.y=0;
	flags.x=0;
	flags.a=0;
	flags.b=0;
	__os_snprintf(flags.aPressed, 32, "A button pressed");
	__os_snprintf(flags.bPressed, 32, "B button pressed");
	__os_snprintf(flags.xPressed, 32, "X button pressed");
	__os_snprintf(flags.yPressed, 32, "Y button pressed");
	/****************************>            VPAD Loop            <****************************/

	/* Enter the VPAD loop */
	int error;
	VPADData vpad_data;
	//Read initial vpad status
	VPADRead(0, &vpad_data, 1, &error);
	
	while(1)
	{
		VPADRead(0, &vpad_data, 1, &error);

		//button A
		if (vpad_data.btn_hold & BUTTON_A)
			flags.a=1;
	
		//button B
		if (vpad_data.btn_hold & BUTTON_B)
			flags.b=1;

		//button X
		if (vpad_data.btn_hold & BUTTON_X)
			flags.x=1;

		//button Y
		if (vpad_data.btn_hold & BUTTON_Y)
			flags.y=1;

		//end
		if(vpad_data.btn_hold & BUTTON_HOME)
			break;

		render(&flags);
	}
	//WARNING: DO NOT CHANGE THIS. YOU MUST CLEAR THE FRAMEBUFFERS AND IMMEDIATELY CALL EXIT FROM THIS FUNCTION. RETURNING TO LOADER CAUSES FREEZE.
	int ii=0;
	for(ii;ii<2;ii++)
	{
		fillScreen(0,0,0,0);
		flipBuffers();
	}
	_Exit();
}