#include <pspkernel.h>
#include <pspdebug.h>
#include <pspctrl.h>
#include <stdio.h>
#include <string.h>
#include <psppower.h>
#include <pspiofilemgr.h>
//#include "number.h"
//#include "switch.h"
//#include "menu.h"
PSP_MODULE_INFO("PPP", 0, 1, 0);
PSP_MAIN_THREAD_ATTR(PSP_THREAD_ATTR_USER);
#define printf pspDebugScreenPrintf
int passpass = 1; // When it's true, password will be checked, else, don't checked.
//char PPP_ver[] = "0.2"; // PSP Protection Password (PPP) version.
//int sm = 0;
int switch_mode = 1;
int aax = 20; //40; 
int bbx = 25; //45; 
int ccx = 30;//50;
int ddx = 35;
int switch_result = 0;

// Pass 1.
int pass_recovery = 0;
#define Recovery "flash0:/kd/recovery.prx"
void WelcomeScreen(int set)
{
     passpass = set; switch_mode = set;
     scePowerLock(0); // Lock power button.
     if(ReadConfig("ms0:/psp/system/ppp_configfile.txt", "effect = yes", 13) == 1)
     WelcomeScreen_Letters();
     else
     WelcomeWithout();
     
      
     printf("\n\
     Coded by Becus.\n");
    
    
    
    printf("\n\n\n\n\n\n\n\
    Set the password :\n\n");
    printf("\n\
    *******************************************\n\
    **** Becus25's                         ****\n\
    ****           PSP Protection Password ****\n\
    *******************************************\n\n");
    pspDebugScreenSetTextColor(0xFFFFF1);
    pspDebugScreenSetXY(20, 20); printf("0");
    pspDebugScreenSetTextColor(0x111FFF);
    pspDebugScreenSetXY(25, 20); printf("0");
    pspDebugScreenSetXY(30, 20); printf("0");
    pspDebugScreenSetXY(35, 20); printf("0");
    
    
} 
void PassWord()
{
     SceCtrlData pad;
     //Ctrl_data_pad :
     do
     {
         sceCtrlReadBufferPositive(&pad, 1);    
         
                 if((pad.Buttons & PSP_CTRL_CIRCLE) && (switch_mode == 5))
                 {
                        pspDebugScreenClear();
                        WelcomeScreen(1);
                        scePowerTick(0);
                        }
                        
         if(pad.Buttons & PSP_CTRL_UP)
         {
                        if(switch_mode == 1)
                        { switch_now(1, switch_now-1, -1); }
                        if(switch_mode == 2)
                        { switch_now(2, switch_now-1, -1); }
                        else if(switch_mode == 3)
                        { switch_now(3, switch_now-1, -1); }
                        else if(switch_mode == 4)
                        { switch_now(4, switch_now-1, -1); }
                        }    
         if(pad.Buttons & PSP_CTRL_DOWN)
         {
                        //sceKernelDelayThread(10000);
                        if(switch_mode == 1)
                        { switch_now(1, switch_now+1, 1); }
                        if(switch_mode == 2)
                        { switch_now(2, switch_now+1, 1); }
                        else if(switch_mode == 3)
                        { switch_now(3, switch_now+1, 1); }
                        else if(switch_mode == 4)
                        { switch_now(4, switch_now+1, 1); }
         }
         if(pad.Buttons & PSP_CTRL_CROSS)
         {
                        sceKernelDelayThread(700000); // 0,7 seconds
                        switch(switch_mode)
                        {
                                          case 1 :
                                          switch_mode = 2;
                                          break;
                                          case 2 :
                                          switch_mode = 3;
                                          break;
                                          case 3 :
                                          switch_mode = 4;
                                          break;
                                          case 4 :
                                          pspDebugScreenClear();
                                          printf("Checking password...");
                                          switch_mode = 5;
                                          
                                          strcat_strings();
                                          Read_final_Password();                           
                                          passpass = 0;
                                          
                                          break;
                        }
                       
        }
        
        
        
        /*if(pad.Buttons & PSP_CTRL_HOME)
        sceKernelExitGame(); // Only used for test the application.*/
                                          
                                                                                   
                 
                 
                 
       sceKernelDelayThread(100000);  
     } while(passpass == 1);
     
                 
}
            
int main()
{
    
    pspDebugScreenInit();
   
    pspDebugScreenSetTextColor(0x111FFF); // Red.
   
    WelcomeScreen(1);
    
    PassWord();
    
    sceKernelSleepThread();
    return 0;
}
