Ejemplo n.º 1
0
//TODO rewrite for libretro
void pollInputs() {
	VPADData vpad;
	int error;
	
	VPADRead(0, &vpad, 1, &error);
	
	if (error) {
		return;
	}
	
	currentData.homePressed = vpad.btns_h & VPAD_BUTTON_HOME; //For UI
	currentData.buttonsPressed = vpad.btns_h;
}
Ejemplo n.º 2
0
static void wpad_poll(void)
{
   VPADStatus vpad;
   VPADReadError error;

   VPADRead(PAD_GAMEPAD, &vpad, 1, &error);

   if (error)
      return;

   update_button_state(&button_state, vpad.hold);
   update_analog_state(analog_state, &vpad);
   update_touch_state(analog_state, &button_state, &vpad);
   check_panic_button(vpad.hold);
}
Ejemplo n.º 3
0
static void wiiu_joypad_poll(void)
{
   VPADStatus vpad;
   VPADReadError vpadError;
   VPADRead(0, &vpad, 1, &vpadError);

   if(vpadError)
      return;

   pad_state = 0;
   pad_state |= (vpad.hold & VPAD_BUTTON_LEFT) ? (UINT64_C(1) << RETRO_DEVICE_ID_JOYPAD_LEFT) : 0;
   pad_state |= (vpad.hold & VPAD_BUTTON_DOWN) ? (UINT64_C(1) << RETRO_DEVICE_ID_JOYPAD_DOWN) : 0;
   pad_state |= (vpad.hold & VPAD_BUTTON_RIGHT) ? (UINT64_C(1) << RETRO_DEVICE_ID_JOYPAD_RIGHT) : 0;
   pad_state |= (vpad.hold & VPAD_BUTTON_UP) ? (UINT64_C(1) << RETRO_DEVICE_ID_JOYPAD_UP) : 0;
   pad_state |= (vpad.hold & VPAD_BUTTON_PLUS) ? (UINT64_C(1) << RETRO_DEVICE_ID_JOYPAD_START) : 0;
   pad_state |= (vpad.hold & VPAD_BUTTON_MINUS) ? (UINT64_C(1) << RETRO_DEVICE_ID_JOYPAD_SELECT) : 0;
   pad_state |= (vpad.hold & VPAD_BUTTON_X) ? (UINT64_C(1) << RETRO_DEVICE_ID_JOYPAD_X) : 0;
   pad_state |= (vpad.hold & VPAD_BUTTON_Y) ? (UINT64_C(1) << RETRO_DEVICE_ID_JOYPAD_Y) : 0;
   pad_state |= (vpad.hold & VPAD_BUTTON_B) ? (UINT64_C(1) << RETRO_DEVICE_ID_JOYPAD_B) : 0;
   pad_state |= (vpad.hold & VPAD_BUTTON_A) ? (UINT64_C(1) << RETRO_DEVICE_ID_JOYPAD_A) : 0;
   pad_state |= (vpad.hold & VPAD_BUTTON_R) ? (UINT64_C(1) << RETRO_DEVICE_ID_JOYPAD_R) : 0;
   pad_state |= (vpad.hold & VPAD_BUTTON_L) ? (UINT64_C(1) << RETRO_DEVICE_ID_JOYPAD_L) : 0;
   pad_state |= (vpad.hold & VPAD_BUTTON_ZR) ? (UINT64_C(1) << RETRO_DEVICE_ID_JOYPAD_R2) : 0;
   pad_state |= (vpad.hold & VPAD_BUTTON_ZL) ? (UINT64_C(1) << RETRO_DEVICE_ID_JOYPAD_L2) : 0;
   pad_state |= (vpad.hold & VPAD_BUTTON_STICK_R) ? (UINT64_C(1) << RETRO_DEVICE_ID_JOYPAD_R3) : 0;
   pad_state |= (vpad.hold & VPAD_BUTTON_STICK_L) ? (UINT64_C(1) << RETRO_DEVICE_ID_JOYPAD_L3) : 0;

   analog_state[0][RETRO_DEVICE_INDEX_ANALOG_LEFT] [RETRO_DEVICE_ID_ANALOG_X]  =  vpad.leftStick.x * 0x7FF0;
   analog_state[0][RETRO_DEVICE_INDEX_ANALOG_LEFT] [RETRO_DEVICE_ID_ANALOG_Y]  = -vpad.leftStick.y * 0x7FF0;
   analog_state[0][RETRO_DEVICE_INDEX_ANALOG_RIGHT] [RETRO_DEVICE_ID_ANALOG_X] =  vpad.rightStick.x * 0x7FF0;
   analog_state[0][RETRO_DEVICE_INDEX_ANALOG_RIGHT] [RETRO_DEVICE_ID_ANALOG_Y] = -vpad.rightStick.y * 0x7FF0;

   BIT64_CLEAR(lifecycle_state, RARCH_MENU_TOGGLE);

   if(((vpad.tpNormal.touched) && (vpad.tpNormal.x > 200) && (vpad.tpNormal.validity) == 0) ||
      (vpad.trigger & VPAD_BUTTON_HOME))
      BIT64_SET(lifecycle_state, RARCH_MENU_TOGGLE);

   /* panic button */
   if((vpad.hold & VPAD_BUTTON_R) &&
      (vpad.hold & VPAD_BUTTON_L) &&
      (vpad.hold & VPAD_BUTTON_STICK_R) &&
      (vpad.hold & VPAD_BUTTON_STICK_L))
      command_event(CMD_EVENT_QUIT, NULL);
}
Ejemplo n.º 4
0
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();
		}
    }

}
Ejemplo n.º 5
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();
}
Ejemplo n.º 6
0
int main(int argc, char **argv)
{	
    OSScreenInit();
    OSReport("Screen initted\n");
    
    ProcUIInit(&SaveCallback);

	/****************************>             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;
	OSReport("Globals initialized\n");
	
	/****************************>            VPAD Loop            <****************************/
	int error;
	VPADStatus vpad_data;
	while (AppRunning())
	{
	    if(!initialized) continue;
	    
		VPADRead(0, &vpad_data, 1, &error);
		//Get the status of the gamepad
		myPongGlobals.button = vpad_data.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)
		{
		    OSReport("Game reset\n");
			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;
	}
	
	return 0;
}
Ejemplo n.º 7
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();
}
Ejemplo n.º 8
0
Archivo: main.c Proyecto: ajd4096/ddd
/* Entry point */
int Menu_Main(void)
{
    //!*******************************************************************
    //!                   Initialize function pointers                   *
    //!*******************************************************************
    //! do OS (for acquire) and sockets first so we got logging
    InitOSFunctionPointers();
    InitSocketFunctionPointers();
    InitFSFunctionPointers();
    InitVPadFunctionPointers();
    InitSysFunctionPointers();
    InitAocFunctionPointers();

    log_init("192.168.178.3");
    log_deinit();
    log_init("192.168.178.3");
    log_printf("Started %s\n", cosAppXmlInfoStruct.rpx_name);

    if(strcasecmp("men.rpx", cosAppXmlInfoStruct.rpx_name) == 0)
    {
        CheckPendingMetaDump();
        return EXIT_RELAUNCH_ON_LOAD;
    }
    else if(strlen(cosAppXmlInfoStruct.rpx_name) > 0 && strcasecmp("ffl_app.rpx", cosAppXmlInfoStruct.rpx_name) != 0)
    {
        StartDumper();
        return EXIT_RELAUNCH_ON_LOAD;
    }

    // initialize memory tables once on start
    memoryInitAreaTable();
    rpxRplTableInit();
    SetupKernelCallback();
    PatchMethodHooks();

    memoryInitialize();

    VPADInit();

    // Prepare screen
    int screen_buf0_size = 0;
    int screen_buf1_size = 0;

    // Init screen and screen buffers
    OSScreenInit();
    screen_buf0_size = OSScreenGetBufferSizeEx(0);
    screen_buf1_size = OSScreenGetBufferSizeEx(1);

    unsigned char *screenBuffer = MEM1_alloc(screen_buf0_size + screen_buf1_size, 0x40);

    OSScreenSetBufferEx(0, screenBuffer);
    OSScreenSetBufferEx(1, (screenBuffer + screen_buf0_size));

    OSScreenEnableEx(0, 1);
    OSScreenEnableEx(1, 1);

    char msg[80];
    uint8_t sel_ip = 3;
    int launchMethod = 0;
    int update_screen = 1;
    int vpadError = -1;
    VPADData vpad_data;
    u_serv_ip ip;
    ip.full = GetServerIp();
    int delay = 0;

    while (1)
    {
        // Read vpad
        VPADRead(0, &vpad_data, 1, &vpadError);

        if(update_screen)
        {
            OSScreenClearBufferEx(0, 0);
            OSScreenClearBufferEx(1, 0);

            // Print message
            PRINT_TEXT2(14, 1, "-- DDD v0.2 by Dimok --");
            PRINT_TEXT2(0, 5, "1.    Setup IP address of server application.");

            // Print ip digit selector
            uint8_t x_shift = 17 + 4 * sel_ip;
            PRINT_TEXT2(x_shift, 6, "vvv");

            PRINT_TEXT2(0, 7, "      Server IP: %3d.%3d.%3d.%3d", ip.digit[0], ip.digit[1], ip.digit[2], ip.digit[3]);

            PRINT_TEXT2(0, 10, "2.   Press A to install dumper and try to launch disc.");
            PRINT_TEXT2(0, 11, "  or Press X to install dumper and return to system menu.");

            PRINT_TEXT2(0, 13, "3.   Start the title to be dumped.");

            PRINT_TEXT2(0, 17, "Press home button to exit ...");


            OSScreenFlipBuffersEx(0);
            OSScreenFlipBuffersEx(1);
        }

        u32 pressedBtns = vpad_data.btns_d | vpad_data.btns_h;

        // Check for buttons
        // Home Button
        if (pressedBtns & VPAD_BUTTON_HOME) {
            launchMethod = 0;
            break;
        }
        // A Button
        if (pressedBtns & VPAD_BUTTON_A) {
            SetServerIp(ip.full);
            launchMethod = 1;
            break;
        }
        // A Button
        if (pressedBtns & VPAD_BUTTON_X) {
            SetServerIp(ip.full);
            launchMethod = 2;
            break;
        }
        // Left/Right Buttons
        if (vpad_data.btns_d & VPAD_BUTTON_LEFT )
        {
            if(sel_ip == 0)
                sel_ip = 3;
            else
                --sel_ip;
        }

        if (vpad_data.btns_d & VPAD_BUTTON_RIGHT)
        {
            sel_ip = ((sel_ip + 1) % 4);
        }

        // Up/Down Buttons
        if (pressedBtns & VPAD_BUTTON_UP)
        {
            if(--delay <= 0) {
                ip.digit[sel_ip]++;
                delay = (vpad_data.btns_d & VPAD_BUTTON_UP) ? 6 : 0;
            }
        }
        else if (pressedBtns & VPAD_BUTTON_DOWN)
        {
            if(--delay <= 0) {
                ip.digit[sel_ip]--;
                delay = (vpad_data.btns_d & VPAD_BUTTON_DOWN) ? 6 : 0;
            }
        }
        else {
            delay = 0;
        }

        // Button pressed ?
        update_screen = (pressedBtns & (VPAD_BUTTON_LEFT | VPAD_BUTTON_RIGHT | VPAD_BUTTON_UP | VPAD_BUTTON_DOWN)) ? 1 : 0;
        usleep(20000);
    }

	MEM1_free(screenBuffer);
	screenBuffer = NULL;

    log_deinit();

    memoryRelease();

    if(launchMethod == 0)
    {
        RestoreInstructions();
        return EXIT_SUCCESS;
    }
    else if(launchMethod == 1)
    {
        char buf_vol_odd[20];
        snprintf(buf_vol_odd, sizeof(buf_vol_odd), "%s", "/vol/storage_odd03");
        _SYSLaunchTitleByPathFromLauncher(buf_vol_odd, 18, 0);
    }
    else
    {
        SYSLaunchMenu();
    }

    return EXIT_RELAUNCH_ON_LOAD;
}
Ejemplo n.º 9
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();
}
Ejemplo n.º 10
0
void _entryPoint()
{
	struct Services services;
	
	/****************************>           Get Handles           <****************************/
	//Get a handle to coreinit.rpl
	OSDynLoad_Acquire("coreinit.rpl", &services.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);

	// Draw functions
	OSDynLoad_FindExport(services.coreinit_handle, 0, "OSScreenPutPixelEx", &services.OSScreenPutPixelEx);
	OSDynLoad_FindExport(services.coreinit_handle, 0, "DCFlushRange", &services.DCFlushRange);
	OSDynLoad_FindExport(services.coreinit_handle, 0, "OSScreenFlipBuffersEx", &services.OSScreenFlipBuffersEx);
	OSDynLoad_FindExport(services.coreinit_handle, 0, "OSScreenGetBufferSizeEx", &services.OSScreenGetBufferSizeEx);
	OSDynLoad_FindExport(services.coreinit_handle, 0, "OSScreenPutFontEx", &services.OSScreenPutFontEx);
	OSDynLoad_FindExport(services.coreinit_handle, 0, "OSScreenClearBufferEx", &services.OSScreenClearBufferEx);
	//OS functions
	OSDynLoad_FindExport(services.coreinit_handle, 0, "_Exit", &_Exit);
	cleanSlate(&services);
	
	/****************************>             Globals             <****************************/
	struct SpaceGlobals mySpaceGlobals;
	//Flag for restarting the entire game.
	mySpaceGlobals.restart = 1;
	mySpaceGlobals.services = &services;

	// initial state is title screen
	mySpaceGlobals.state = 1;
	mySpaceGlobals.titleScreenRefresh = 1;

	//Flags for render states
	mySpaceGlobals.renderResetFlag = 0;
	mySpaceGlobals.menuChoice = 0; // 0 is play, 1 is password
	
	// setup the password list
	unsigned int pwSeed = 27;
	int x;
	for (x=0; x<100; x++)
		mySpaceGlobals.passwordList[x] = (int)(prand(&pwSeed)*100000);
	
	// set the starting time
	int64_t (*OSGetTime)();
    OSDynLoad_FindExport(services.coreinit_handle, 0, "OSGetTime", &OSGetTime);
	mySpaceGlobals.seed = OSGetTime();
	
	/****************************>            VPAD Loop            <****************************/
	int error;
	VPADData vpad_data;
	
	// decompress compressed things into their arrays, final argument is the transparent color in their palette
	decompress_sprite(3061, 200, 100, compressed_title, mySpaceGlobals.title, 39);
	decompress_sprite(511, 36, 36, compressed_ship, mySpaceGlobals.orig_ship, 14);
	decompress_sprite(206, 23, 23, compressed_enemy, mySpaceGlobals.enemy, 9);
	
	// setup palette and transparent index
	mySpaceGlobals.curPalette = ship_palette;
	mySpaceGlobals.transIndex = 14;
	
	// initialize starfield for this game
	initStars(&mySpaceGlobals);
	
	mySpaceGlobals.invalid = 1;
		
	while (1)
	{
		VPADRead(0, &vpad_data, 1, &error);
		
		//Get the status of the gamepad
		mySpaceGlobals.button = vpad_data.btn_hold;
		
		mySpaceGlobals.rstick = vpad_data.rstick;
		mySpaceGlobals.lstick = vpad_data.lstick;
		
		mySpaceGlobals.touched = vpad_data.tpdata.touched;
		if (mySpaceGlobals.touched == 1)
		{
			mySpaceGlobals.touchX = ((vpad_data.tpdata.x / 9) - 11);
			mySpaceGlobals.touchY = ((3930 - vpad_data.tpdata.y) / 16);
		}
		
		if (mySpaceGlobals.restart == 1)
		{
			reset(&mySpaceGlobals);
			mySpaceGlobals.restart = 0;
		}
		
		if (mySpaceGlobals.state == 1) // title screen
		{
			displayTitle(&mySpaceGlobals);
			doMenuAction(&mySpaceGlobals);
		}
		else if (mySpaceGlobals.state == 2) // password screen
		{
			displayPasswordScreen(&mySpaceGlobals);
			doPasswordMenuAction(&mySpaceGlobals);
		}
		else if (mySpaceGlobals.state == 3) // pause screen
		{
			displayPause(&mySpaceGlobals);
			doMenuAction(&mySpaceGlobals);
		}
		else if  (mySpaceGlobals.state == 4) // game over screen
		{
			displayGameOver(&mySpaceGlobals);
			doMenuAction(&mySpaceGlobals);
		}
		else 	// game play
		{
			//Update location of player1 and 2 paddles
			p1Move(&mySpaceGlobals);

			// perform any shooting
			p1Shoot(&mySpaceGlobals);
			
			// handle any collisions
			handleCollisions(&mySpaceGlobals);
			
			// do explosions
			handleExplosions(&mySpaceGlobals);
			
			// if we're out of lives, break
			if (mySpaceGlobals.lives <= 0 && mySpaceGlobals.state == 4)
				continue;
			
			// add any new enemies
			addNewEnemies(&mySpaceGlobals);
			
			//Render the scene
			render(&mySpaceGlobals);
			
			// check for pausing
			checkPause(&mySpaceGlobals);
		}
		//To exit the game
		if (mySpaceGlobals.button&BUTTON_HOME)
		{
			break;
		}

	}
	cleanSlate(mySpaceGlobals.services);
	_Exit();
}