Esempio n. 1
0
int poweroffInit()
{
	int res;
	static int _init_count = -1;

	if(_init_count == _iop_reboot_count)
		return 0;
	_init_count = _iop_reboot_count;

	while(((res = SifBindRpc(&cd0, PWROFF_IRX, 0)) >= 0) && (cd0.server == NULL))
		nopdelay();

	ee_thread_t thread;
	ee_thread_status_t thisThread;

	ee_sema_t sema;

	// Terminate and delete any previously created threads
	if (powerOffThreadId >= 0) {
		TerminateThread(powerOffThreadId);
		DeleteThread(powerOffThreadId);
		powerOffThreadId = -1;
	}

	// Delete any previously created semaphores
	if (PowerOffSema >= 0)
	{
		DeleteSema(PowerOffSema);
		PowerOffSema = -1;
	}

	sema.init_count = 0;
	sema.max_count = 1;
	sema.option = 0;
	PowerOffSema = CreateSema(&sema);

	ReferThreadStatus(GetThreadId(), &thisThread);

	if (thisThread.current_priority == 0) {
		ChangeThreadPriority(GetThreadId(), 51);
		thread.initial_priority = 50;
	} else
		thread.initial_priority = thisThread.current_priority - 1;

	thread.stack_size = 512 * 16;
	thread.gp_reg = &_gp;
	thread.func = PowerOffThread;
	thread.stack = (void *)poffThreadStack;
	powerOffThreadId = CreateThread(&thread);
	StartThread(powerOffThreadId, NULL);
	
	DIntr();
	SifAddCmdHandler(POFF_SIF_CMD, _poff_intr_callback, NULL);
	EIntr();

	int autoShutdown = 0;
	SifCallRpc(&cd0, PWROFF_ENABLE_AUTO_SHUTOFF, 0, NULL, 0, &autoShutdown, sizeof(autoShutdown), 0, 0);
	
	return res;
}
Esempio n. 2
0
int InitThread(void)
{
	ee_sema_t sema;
	ee_thread_t thread;

	sema.max_count = 255;
	sema.init_count = 0;
	sema.option = (u32)"KernelTopThread";
	if((topSema = CreateSema(&sema)) < 0)
		return -1;

	thread.func = &topThread;
	thread.stack = stack;
	thread.stack_size = sizeof(stack);
	thread.gp_reg = &_gp;
	thread.option = (u32)"KernelTopThread";
	thread.initial_priority = 0;
	if((topId = CreateThread(&thread)) < 0)
	{
		DeleteSema(topSema);
		return -1;
	}

	topArg.requestOut = 0;
	topArg.requestIn = 0;
	StartThread(topId, &topArg);

	ChangeThreadPriority(GetThreadId(), 1);

	return topId;
}
Esempio n. 3
0
void ioInit(void) {
	gIOTerminate = 0;
	gHandlerCount = 0;
	gReqList = NULL;
	gReqEnd = NULL;
	
	gDispatcherThreadID = 0;
	gIOThreadId = 0;
	
	gQueueSema.init_count = 1;
	gQueueSema.max_count = 1;
	gQueueSema.option = 0;

	gProcSemaId = CreateSema(&gQueueSema);
	gEndSemaId = CreateSema(&gQueueSema);
	gIOPrintfSemaId = CreateSema(&gQueueSema);
	
	ChangeThreadPriority (  GetThreadId (), 29 );

	// default custom simple action handler
	ioRegisterHandler(IO_CUSTOM_SIMPLEACTION, &ioSimpleActionHandler);
	
	memset(&gIOThread, 0, sizeof(gIOThread));
	
	gIOThread.func         = (void *)ioThreadDispatcher;
	gIOThread.stack        = disp_stack;
	gIOThread.stack_size   = THREAD_STACK_SIZE;
	gIOThread.gp_reg       = &_gp;
	gIOThread.initial_priority = 0;
	
	alarmID = SetAlarm( 625, &ioAlarmFunc, NULL); 
	
	// this one manages the thread switching in alarm intervals
	gDispatcherThreadID = CreateThread(&gIOThread);
	StartThread(gDispatcherThreadID, NULL);

	gIOThread.func         = (void *)ioWorkerThread;
	gIOThread.stack        = thread_stack;
	gIOThread.initial_priority = 30;

	isIORunning = 1;
	gIOThreadId = CreateThread(&gIOThread);
	StartThread(gIOThreadId, NULL);
	
	ChangeThreadPriority (  GetThreadId (), 30 );
}
Esempio n. 4
0
void Ps2SaveFileManager::quit(void) {
	_systemQuit = true;
	ee_thread_t statSave, statThis;
	ReferThreadStatus(GetThreadId(), &statThis);
	ChangeThreadPriority(_autoSaveTid, statThis.current_priority - 1);

	do {	// wait until thread called ExitThread()
		SignalSema(_autoSaveSignal);
		ReferThreadStatus(_autoSaveTid, &statSave);
	} while (statSave.status != 0x10);

	DeleteThread(_autoSaveTid);
    free(_autoSaveStack);
}
Esempio n. 5
0
int ioBlockOps(int block) {
	ee_thread_status_t status;
	int ThreadID;

	if (block && !isIOBlocked) {
		isIOBlocked = 1;

		ThreadID=GetThreadId();
		ReferThreadStatus(ThreadID, &status);
		ChangeThreadPriority(ThreadID, 90);

		// wait for all io to finish
		while (ioHasPendingRequests()) {};

		ChangeThreadPriority(ThreadID, status.current_priority);

		// now all io should be blocked
	} else if (!block && isIOBlocked) {
		isIOBlocked = 0;
	}

	return IO_OK;
}
Esempio n. 6
0
s32 sceCdInitCallbackThread(s32 priority, void *stackAddr, s32 stackSize)
{
	// if callback thread has already been initialised, just change its priority
	if (callbackThreadId != 0) {
		ChangeThreadPriority(callbackThreadId, priority);
		return 0;
	}
	// initialise callback thread
	sceCdThreadId = GetThreadId();
	ReferThreadStatus(sceCdThreadId, &sceCdThreadParam);
	callbackThreadParam.stack_size = stackSize;
	callbackThreadParam.gp_reg = &_gp;
	callbackThreadParam.func = sceCdCallbackLoop;
	callbackThreadParam.stack = stackAddr;
	callbackThreadParam.initial_priority = priority;
	callbackThreadId = CreateThread(&callbackThreadParam);
	StartThread(callbackThreadId, 0);

	return 1;
}
Esempio n. 7
0
void poweroffChangeThreadPriority(int priority)
{
	ChangeThreadPriority(powerOffThreadId, priority);
}
Esempio n. 8
0
int main(int argc, char *argv[])
#endif
{


#ifdef PSP
    SetupCallbacks();
    scePowerSetClockFrequency(333, 333, 166);
#endif

    for (int i=0; i<FLAG_COUNT; i++) {
		GAME_FLAGS[i] = false;
	}
	UNUSED(argc);

    string argvString = "";
#ifndef WII
    argvString = string(argv[0]);
#else
    if (!fatInitDefault()) {
        printf("fatInitDefault ERROR #1");
        std::fflush(stdout);
        timer.delay(500);
        exit(-1);
    }
#endif


    get_filepath();
    // fallback in case getcwd returns null
    if (FILEPATH.size() == 0) {
        std::cout << "Could not read path, fallback to using argv" << std::endl;
        FILEPATH = argvString.substr(0, argvString.size()-EXEC_NAME.size());
    }
    std::cout << "main - argvString: '" << argvString << "', FILEPATH: '" << FILEPATH << "'" << std::endl; std::fflush(stdout);



#ifdef PLAYSTATION2
    std::cout << "PS2.DEBUG #1" << std::endl; std::fflush(stdout);

    #ifndef PS2LINK
    SifIopReset(NULL, 0); // clean previous loading of irx by apps like ulaunchElf. Comment this line to get cout on ps2link
    #endif

    printf("DEBUG.PS2 #1.1\n");

	/* SP193: Being creative (Do something while waiting for the slow IOP to be reset). =D */
	int main_id = GetThreadId();
    ChangeThreadPriority(main_id, 72);
    std::cout << "PS2.DEBUG #1.1" << std::endl; std::fflush(stdout);
    printf("DEBUG.PS2 #1.2\n");

    #ifndef PS2LINK
    while(SifIopSync()) {
        std::cout << "PS2.SifIopSync()" << std::endl;
    }
    #endif
	/* Initialize and connect to all SIF services on the IOP. */
	SifInitRpc(0);
	SifInitIopHeap();
	SifLoadFileInit();
	fioInit();
    printf("DEBUG.PS2 #1.3\n");

	/* Apply the SBV LMB patch to allow modules to be loaded from a buffer in EE RAM. */
	sbv_patch_enable_lmb();

    // --- DEBUG --- //
    //FILEPATH = "cdfs:/";
    // --- DEBUG --- //

    std::cout << "PS2.DEBUG #2" << std::endl; std::fflush(stdout);

    if (FILEPATH.find("mass:") != std::string::npos) {
        printf("DEBUG.PS2 #1.4\n");
        std::cout << "PS2.DEBUG Load USB" << std::endl; std::fflush(stdout);
        PS2_load_USB();
    }

    if (FILEPATH.find("cdfs") != std::string::npos || FILEPATH.find("cdrom") != std::string::npos) {
        printf("DEBUG.PS2 #1.5\n");
        std::cout << "PS2.DEBUG Load CDROM" << std::endl; std::fflush(stdout);
        FILEPATH = "cdfs:";
        PS2_load_CDROM();
    }
    printf("DEBUG.PS2 #2\n");




    std::cout << "PS2.DEBUG #3" << std::endl; std::fflush(stdout);
#endif




	// check command-line paramethers
	if (argc > 1) {
		for (int i=1; i<argc; i++) {
			std::string temp_argv(argv[i]);
			if (temp_argv == "--fullscreen") {

			} else if (temp_argv == "--quickload") {
				GAME_FLAGS[FLAG_QUICKLOAD] = true;
			} else if (temp_argv == "--invencible") { // player have infinite HP
				GAME_FLAGS[FLAG_INVENCIBLE] = true;
			} else if (temp_argv == "--allweapons") { // player have all weapons available even if
				GAME_FLAGS[FLAG_ALLWEAPONS] = true;
			} else if (temp_argv == "--infinitejump") { // player can jump again and again
				GAME_FLAGS[FLAG_INFINITE_JUMP] = true;
			}
		}
	}

    std::cout << "PS2.DEBUG #7" << std::endl; std::fflush(stdout);

    //fio.check_conversion();
	fio.read_game(game_data);


    //GAME_FLAGS[FLAG_INFINITE_HP] = true; // DEBUG


    gameControl.get_drop_item_ids();
	soundManager.init_audio_system();

// PS2 version have to load config AFTER SDL_Init due to SDK issues
#ifdef LINUX
    SAVEPATH = std::string(getenv("HOME")) + "/.rockbot/";
    mkdir(SAVEPATH.c_str(), 0777);
    //std::cout << "SAVEPATH: " << SAVEPATH << ", mkdir-res: " << res << ", errno: " << errno << std::endl;
#elif WIN32
    SAVEPATH =  std::string(getenv("APPDATA")) + "/rockbot";
    std::cout << "SAVEPATH: " << SAVEPATH << std::endl;
    _mkdir(SAVEPATH.c_str());
#else
    SAVEPATH = FILEPATH;
#endif

#ifndef PLAYSTATION2
    fio.load_config(game_config);
#endif

	// INIT GRAPHICS
	if (graphLib.initGraphics() != true) {
        printf("ERROR intializing graphic\n");
		return -1;
	}

    // define SAVEPATH
    #ifdef PLAYSTATION2
        PS2_load_MC();
        SAVEPATH = "mc0:Rockbot/";

        if (fioMkdir(SAVEPATH.c_str()) < 0) {
            std::cout << "main - warning: could not create '" << SAVEPATH << "' folder" << std::endl; std::fflush(stdout);
            /// @TODO - check if directory exists
        } else {
            std::cout << "Folder '" << SAVEPATH << "' created" << std::endl; std::fflush(stdout);
        }

    #endif
    have_save = fio.save_exists();

    #ifndef DEBUG_OUTPUT // redirect output to null
        std::string cout_file = "/dev/null";
        std::ofstream out(cout_file.c_str());
        std::cout.rdbuf(out.rdbuf());
    #else
        // --- REDIRECT STDOUT TO A FILE --- //
        #if defined(PSP) || defined(WII) || defined(ANDROID) || defined(DINGUX) || defined(PLAYSTATION2)
            //std::string cout_file = SAVEPATH + "/stdout.txt";
            std::string cout_file = FILEPATH + "/stdout.txt";
            std::streambuf *coutbuf = std::cout.rdbuf();
            std::ofstream out(cout_file.c_str());
            std::cout.rdbuf(out.rdbuf()); //redirect std::cout to out.txt!
        #endif
    #endif


    graphLib.preload();
#ifdef PLAYSTATION2
    fio.load_config(game_config);
    PS2_create_save_icons();
#endif
    draw_lib.preload();

    gameControl.currentStage = APEBOT;





	// INIT GAME
	if (GAME_FLAGS[FLAG_QUICKLOAD] == false) {
		if (gameControl.showIntro() == false) {
            std::cout << "ERROR SHOWING INTRO" << std::endl;
			return 0;
		}
	} else {
        gameControl.quick_load_game();
        //ending end_obj;
        //end_obj.start();
        //return 1;
    }

	input.clean();
	input.p1_input[BTN_START] = 0;
	input.waitTime(200);
	input.clean();

    bool run_game = true;



    while (run_game) {
        #if !defined(PSP) && !defined(DINGUX)
            timer.start_ticker();
        #endif


		#ifdef PLAYSTATION2
			RotateThreadReadyQueue(_MIXER_THREAD_PRIORITY);
        #endif


		gameControl.showGame();
#ifdef DEBUG_SHOW_FPS
        gameControl.fps_count();
#endif
        draw_lib.update_screen();
        if (input.p1_input[BTN_QUIT] == 1) {
            //std::cout << "LEAVE #3" << std::endl;
            std::fflush(stdout);
            gameControl.leave_game();
        }
        unsigned int now_ticks = timer.get_ticks();
        if (now_ticks < (1000 / FRAMES_PER_SECOND)) {
            timer.delay((1000 / FRAMES_PER_SECOND) - now_ticks);
        }

    }
	/// @TODO: sdl quit sub-systems


	
#ifdef PSP
    sceKernelExitGame();
    return 0;
#else
    SDL_Quit();
#endif
	
	return 1;
}