Ejemplo n.º 1
0
////////////////////////////////////////////////////////////////////////////////////////
// Multiple lines message box
////////////////////////////////////////////////////////////////////////////////////////
int msgBoxLines(const char *msg,int delay_vblank) {
	int len,width;
	unsigned char c;
	char str[256];
	int i,j,x,y,lines,ret;
	
	if (!msg) return -1;
  if (!(msg[0])) return -1;
	
	pgCopyScreen();
	
	lines=1;	
	j=0;
	len=0;
	width=0;
	while ((c=msg[len])) {
		if (((c>=0x80) && (c<0xa0)) || (c>=0xe0)) {
			len++;
		} else {
			if (c=='\n') {
				lines++;			
				if (width<(len-j)) width=len-j;
				j=len+1;
			}
		}
		len++;
	}	
	if (width<(len-j)) width=len-j;
	if (!width) width=strlen(msg);
	
	y=(272-lines*12)/2;
	x=(480-width*6)/2;
	
	pgFillBox(x-12-1,y-6-1,x+width*6+12+1,y+lines*12+6,BOX_COLOR);
	pgDrawFrame(x-12,y-6,x+width*6+12,y+lines*12+6-1,FRAME_COLOR);
	
	len=0;
	for (i=0;i<lines;i++){
		j=0;
		while ((c=msg[len])) {
			if (((c>=0x80) && (c<0xa0)) || (c>=0xe0)) {
				str[j++]=msg[len++];
			} else {
				if (c=='\n') break;
			}
			str[j++]=msg[len++];
		}
		if (msg[len]=='\n') len++;
		str[j]=0;
		mh_printCenter(y,str,TEXT_COLOR);
		ret=y;
		y+=12;
	}


	pgScreenFlipV();
	if (delay_vblank>0) pgWaitVn(delay_vblank);
	return ret;
}
Ejemplo n.º 2
0
void Draw_All(void) {
	int			i,col;

	pgFillvram(0);
	
    strncpy(path_tmp, doomwaddir2, 128);

    mh_print(5, 5, "Please choose a game to launch (Press Circle to select)", rgb2col(255, 255, 255), 0, 0);
    mh_print(310, 245, "Vita Doom - Release 1", rgb2col(255, 0, 0), 0, 0);
    mh_print(245, 270, "based on DoomPSP-0.04 S.S. b5", rgb2col(255, 255, 0), 0, 0);

    /*char errtext[64];
    sprintf(errtext, "Error: 0x%x", res);

    mh_print(10, 300, errtext, RGBA8(255, 0, 0, 2555), 0, 0);*/

    if (dlist_num == 0)
    {
        mh_print(32, 40, "No WADs found... Put WADs in:", rgb2col(255, 0, 0), 0, 0);
        mh_print(32, 60, path_tmp, rgb2col(255, 0, 0), 0, 0);
    }
    else
    {
        i = dlist_start;
        while (i < (dlist_start + PATHLIST_H)) {
            if (i < dlist_num) {
                col = rgb2col(255, 255, 255);
                if (dlist[i].type & TYPE_DIR) {
                    col = rgb2col(255, 255, 0);
                }
                if (i == dlist_curpos) {
                    col = rgb2col(255, 0, 0);
                }
                strncpy(path_tmp, dlist[i].name, 40);
                mh_print(32, ((i - dlist_start) + 2) * 20, path_tmp, col, 0, 0);
            }
            i++;
        }
    }

    pgScreenFlipV();
}
Ejemplo n.º 3
0
void osk_get_string(char *buffer, int max)
{
    strcpy(g_osk_buffer,buffer);
    while (1)
    {
	clear_screen();
	draw_osk();
	pgScreenFlipV();
	int keys = Read_Key();

	int osk_r = osk_process_key(keys);

	if (osk_r)
	{
	    if (osk_r>0)
		strncpy(buffer,g_osk_buffer,max);
	    break;
	}
    }
}
Ejemplo n.º 4
0
void draw_strings(char **strings, int nfiles,
			    int x, int y, int display_start_index,
			    int n_display, int selection)
{
    int i;

    for (i=display_start_index;i<display_start_index+n_display;i++)
    {
	if (i>=nfiles) break;
	
	if (i == selection)
	{
	    msxPutString(x,y,yellow,"->");
	    msxPutString(x+2,y,yellow,strings[i]);
	}
	else
	{
	    msxPutString(x+2,y,cyan,strings[i]);
	}
	y++;
    }

    pgScreenFlipV();
}
Ejemplo n.º 5
0
////////////////////////////////////////////////////////////////////////////////////////
// Message box
////////////////////////////////////////////////////////////////////////////////////////
void msgBox(const char *msg,int delay_vblank) {
	int len;
	char str[60];
	
	pgCopyScreen();
	
	memcpy(str,msg,50);
	str[50]=0;
	len=strlen(msg);
	if (len>=50) {
		str[50-3]=str[50-2]=str[50-1]='.';
		len=49;
	}
	len*=8;

	pgFillBox(240-len/2-20-1,136-12-1,240+len/2+20+1,136+18+1,BOX_COLOR);
	pgDrawFrame(240-len/2-20,136-12,240+len/2+20,136+18,FRAME_COLOR);

	pgPrintCenter(17,TEXT_COLOR,str);

	pgScreenFlipV();
	if (delay_vblank<=0) delay_vblank=1;
	pgWaitVn(delay_vblank);
}
Ejemplo n.º 6
0
void ButtonChange(char tempstring[][MAX_TEMP_STRING], const char* buttons[], const char* tempkeystring[]) {
	
	pgFillvram(0);

	int i = 0;
	int die = 0;
	int col;
	int tempact = 0;
	char tempselect[27];
	
	for (i=0; i<MAX_CONTROL; i++) {

	    if (d_controls[i] == CKEY_WEAPON) die = 0;
	    else if (d_controls[i] == KEY_ENTER) die = 1;
	    else if (d_controls[i] == KEY_ESCAPE) die = 2;
	    else if (d_controls[i] == ' ') die = 3;
	    else if (d_controls[i] == CKEY_MOVE) die = 4;
	    else if (d_controls[i] == KEY_TAB) die = 5;
	    else if (d_controls[i] == KEY_RSHIFT) die = 6;
	    else if (d_controls[i] == KEY_RCTRL) die = 7;
	    else if (d_controls[i] == ',') die = 8;
	    else if (d_controls[i] == '.') die = 9;
	    else if (d_controls[i] == 222) die = 10;
	    else if (d_controls[i] == 266) die = 11;
	    else if (d_controls[i] == 333) die = 12;
	
	    col = rgb2col(255,255,255);
	
	    if (i==d_clist_curpos) {
	        col = rgb2col(255,0,0);
	    }
	
        sprintf(tempstring[i], "%s = %s", buttons[i], tempkeystring[die]);
        mh_print(5, ((i + 1) * 20), tempstring[i], col, 0, 0);
	}
	
	if (d_controls[d_clist_curpos] == CKEY_WEAPON) die = 0;
	else if (d_controls[d_clist_curpos] == KEY_ENTER) die = 1;
	else if (d_controls[d_clist_curpos] == KEY_ESCAPE) die = 2;
	else if (d_controls[d_clist_curpos] == ' ') die = 3;
	else if (d_controls[d_clist_curpos] == CKEY_MOVE) die = 4;
	else if (d_controls[d_clist_curpos] == KEY_TAB) die = 5;
	else if (d_controls[d_clist_curpos] == KEY_RSHIFT) die = 6;
	else if (d_controls[d_clist_curpos] == KEY_RCTRL) die = 7;
	else if (d_controls[d_clist_curpos] == ',') die = 8;
	else if (d_controls[d_clist_curpos] == '.') die = 9;
	else if (d_controls[d_clist_curpos] == 222) die = 10;
	else if (d_controls[d_clist_curpos] == 266) die = 11;
	else if (d_controls[d_clist_curpos] == 333) die = 12;
	
	sprintf(tempselect, "Make selection for %s", tempkeystring[die]);
    mh_print(5, 255, tempselect, rgb2col(50, 255, 50), 0, 0);
		
	pgScreenFlipV();

	unsigned long key;
	control_bef_ctl = now_pad;
	
	while (1) {
	    key = Read_Key3();
	    if (key != 0) break;
	    pgWaitV();
	}
	
	if (d_controls[die] == CKEY_WEAPON || d_controls[die] == CKEY_MOVE) {
	    tempact = d_controls[4];
	    d_controls[4] = d_controls[0];
	    d_controls[0] = tempact;
	    
	    if (d_controls[0] == CKEY_MOVE) {
	        analog = 1;
	    }
	    else {
	        analog = 0;
	    }
	}
	else if (key & SCE_CTRL_START) {
	    tempact = d_controls[1];
	    d_controls[1] = d_controls[d_clist_curpos];
	    d_controls[d_clist_curpos] = tempact;
	}
	else if (key & SCE_CTRL_SELECT) {
	    tempact = d_controls[2];
	    d_controls[2] = d_controls[d_clist_curpos];
	    d_controls[d_clist_curpos] = tempact;
	}
	else if (key & SCE_CTRL_CROSS) {
	    tempact = d_controls[3];
	    d_controls[3] = d_controls[d_clist_curpos];
	    d_controls[d_clist_curpos] = tempact;
	}
	else if (key & SCE_CTRL_TRIANGLE) {
	    tempact = d_controls[5];
	    d_controls[5] = d_controls[d_clist_curpos];
	    d_controls[d_clist_curpos] = tempact;
	}
	else if (key & SCE_CTRL_SQUARE) {
	    tempact = d_controls[6];
	    d_controls[6] = d_controls[d_clist_curpos];
	    d_controls[d_clist_curpos] = tempact;
	}
	else if (key & SCE_CTRL_CIRCLE) {
	    tempact = d_controls[7];
	    d_controls[7] = d_controls[d_clist_curpos];
	    d_controls[d_clist_curpos] = tempact;
	}
    else if (key & SCE_CTRL_LTRIGGER) {
	    tempact = d_controls[8];
	    d_controls[8] = d_controls[d_clist_curpos];
	    d_controls[d_clist_curpos] = tempact;
	}
    else if (key & SCE_CTRL_RTRIGGER) {
	    tempact = d_controls[9];
	    d_controls[9] = d_controls[d_clist_curpos];
	    d_controls[d_clist_curpos] = tempact;
	}
	
	control_bef_ctl = key;
	
}
Ejemplo n.º 7
0
void NewPrompter() {
	char* buttons[MAX_CONTROL];
	char tempstring[MAX_CONTROL][MAX_TEMP_STRING];
	char* tempkeystring[MAX_CONTROL+2];
	tempkeystring[0] = "WEAPON";
	tempkeystring[1] = "ENTER";
	tempkeystring[2] = "ESC";
	tempkeystring[3] = "USE";
	tempkeystring[4] = "MOVE";
	tempkeystring[5] = "MAP";
	tempkeystring[6] = "RUN";
	tempkeystring[7] = "FIRE";
	tempkeystring[8] = "M_LEFT";
	tempkeystring[9] = "M_RIGHT";
    //tempkeystring[10] = "222";
    //tempkeystring[11] = "266";
    //tempkeystring[12] = "333";
	buttons[0] = "ANALOG   ";
	buttons[1] = "START    ";
	buttons[2] = "SELECT   ";
	buttons[3] = "CROSS    ";
	buttons[4] = "DPAD     ";
	buttons[5] = "TRIANGLE ";
	buttons[6] = "SQUARE   ";
	buttons[7] = "CIRCLE   ";
	buttons[8] = "L_TRIG   ";
	buttons[9] = "R_TRIG   ";
	//buttons[10] = "CPU_CLOCK";
	
	control_bef_ctl = 0;
	pgScreenFrame(2,0);
	pgFillvram(0);
	pgScreenFlipV();
	while (1) {
	    pgFillvram(0);
	    int i = 0;
	    int die = 0;
	    int col;
	    for (i=0; i<MAX_CONTROL; i++) {
	    
		if (d_controls[i] == CKEY_WEAPON) die = 0;
		else if (d_controls[i] == KEY_ENTER) die = 1;
		else if (d_controls[i] == KEY_ESCAPE) die = 2;
		else if (d_controls[i] == ' ') die = 3;
		else if (d_controls[i] == CKEY_MOVE) die = 4;
		else if (d_controls[i] == KEY_TAB) die = 5;
		else if (d_controls[i] == KEY_RSHIFT) die = 6;
		else if (d_controls[i] == KEY_RCTRL) die = 7;
		else if (d_controls[i] == ',') die = 8;
		else if (d_controls[i] == '.') die = 9;
		else if (d_controls[i] == 222) die = 10;
		else if (d_controls[i] == 266) die = 11;
		else if (d_controls[i] == 333) die = 12;
	
		col = rgb2col(255,255,255);
	
		if (i==d_clist_curpos) {
		    col = rgb2col(255,0,0);
		}
	
		sprintf(tempstring[i], "%s = %s",buttons[i],tempkeystring[die]);
        mh_print(5, ((i + 2) * 20), tempstring[i], col, 0, 0);
	    }
	    if (d_clist_curpos != 10) {
	        mh_print(5,255,"X: Exit | O: Change | Triangle: Save To File",rgb2col(50,255,50),0,0);
	    }
	    else {
	        mh_print(5,255,"X: Exit | O: Increment | Square: Decrement | Triangle: Save To File",rgb2col(50,255,50),0,0);
	    }
	    pgScreenFlipV();
	
	    if (control_bef_ctl == 0) {
	        Read_Key2();
	        pgWaitV();
	    }
	    else {
	        unsigned long ankey;
	        while (1) {
	    	    ankey = Read_Key3();
	    	if (ankey != 0) break;
	    	    pgWaitV();
	    	}
	    	new_pad = old_pad = now_pad = ankey;
	    	control_bef_ctl = 0;
	    }
	    
	   
	    if (new_pad & SCE_CTRL_UP) {
		if (d_clist_curpos > 0) {
			d_clist_curpos--;
			if (d_clist_curpos < d_clist_start) { d_clist_start = d_clist_curpos; }
		}
	    }
	    else if (new_pad & SCE_CTRL_DOWN) {
		if (d_clist_curpos < (MAX_CONTROL-1)) {
			d_clist_curpos++;
			if (d_clist_curpos >= (d_clist_start+MAX_CONTROL-1)) { d_clist_start++; }
		}
	    }
	
	    else if (new_pad & SCE_CTRL_CIRCLE) {
	    if (d_clist_curpos != 10) {
	        ButtonChange(tempstring, buttons, tempkeystring);
	    }
	    else {
	        change_cpu_clock(1);  // increment
	    }
	    }
	
	    else if (new_pad & SCE_CTRL_TRIANGLE) {
	    SaveToFile(tempstring, buttons, tempkeystring);
	    }
	    
	    else if (new_pad & SCE_CTRL_SQUARE) {
	    if (d_clist_curpos == 10)
	        change_cpu_clock(0); // decrement
	    }
	    
	    else if (new_pad & SCE_CTRL_CROSS) {
	    break;
	    }
	}
	
}
Ejemplo n.º 8
0
////////////////////////////////////////////////////////////////////////////////////
// This is just a quick and easy procedure to wait for a PSP to join, the following
// is what is done in Lumines:
//
//   - Wait for a PSP to join
//   - Add the PSP to the list of machines available
//   - Wait for the user to select a PSP
//   - Call sceMatchingSelectTarget
//   - The other PSP will receive MATCHING_SELECTED event
//   - The other PSP displays a message to accept or cancel
//   - If accepted the other PSP calls sceMatchingSelectTarget
//   - The first PSP receives MATCHING_ESTABLISHED
// 
// In lumines they then close the connection and start a new adhoc connection
// with just those two machines in it.
///////////////////////////////////////////////////////////////////////////////////
int adhocSelect(void)
{
	SceCtrlData m_PspPad;
	int err = 0;
	char mac[10];
	char name[256];
	int waitAccept = 0;
	int currentState = PSP_LISTING;
	int oldButtons = 0;
	char tempStr[100];
	char str[256];
	
	sceDisplaySetMode( 0, SCREEN_WIDTH, SCREEN_HEIGHT );
	sceDisplaySetFrameBuf( (char*)VRAM_ADDR, 512, 1, 1 );
	pgFillAllvram(0);pgScreenFrame(2,0);

	for(;;)
	{
		sceCtrlReadBufferPositive(&m_PspPad, 1);
		//pspDebugScreenSetTextColor(0xFFFF);

		switch(currentState)
		{
			case PSP_LISTING:
			{
				//pspDebugScreenInit();
				//pspDebugScreenPrintf("Select a server to connect to, or triangle to return\n\n\n");
				pgFillAllvram(0);pgScreenFrame(2,0);
				mh_print(0,0,"Select a server to connect to, or triangle to return",0xFFFF);
				
				DisplayPspList();
				
				pgScreenFlipV();

				g_Server = 0;

				if(m_PspPad.Buttons != oldButtons)
				{
					if(m_PspPad.Buttons & PSP_CTRL_UP)
					{
						UpList();
					}

					if(m_PspPad.Buttons & PSP_CTRL_DOWN)
					{
						DownList();
					}

					if(m_PspPad.Buttons & PSP_CTRL_CROSS)
					{
						if(GetPspEntry(mac, name) > 0)
						{
							currentState = PSP_SELECTING;
							sceNetAdhocMatchingSelectTarget(matchingId, mac, 0, 0);
						}
					}

					if(m_PspPad.Buttons & PSP_CTRL_TRIANGLE)
						return -1;
				}		
				if(matchChanged)
				{
					if(g_matchEvent == MATCHING_SELECTED)
					{
						memcpy(mac, g_mac, 6);
						strcpy(name, g_matchOptData);
						currentState = PSP_SELECTED;
					}
				}
				break;
			}
			case PSP_SELECTING:
			{
				//pspDebugScreenInit();
				pgFillAllvram(0);pgScreenFrame(2,0);				
				
				sceNetEtherNtostr(mac, tempStr);
				//printf("Waiting for %s to accept the connection\nTo cancel press O\n", tempStr);
				sprintf(str,"Waiting for %s to accept the connection\nTo cancel press O\n", tempStr);
				mh_print(0,0,str,0xFFFF);
				pgScreenFlipV();

				if(m_PspPad.Buttons != oldButtons)
				{
					if(m_PspPad.Buttons & PSP_CTRL_CIRCLE)
					{
						sceNetAdhocMatchingCancelTarget(matchingId, mac);
						currentState = PSP_LISTING;
					}
				}

				if(matchChanged)
				{
					if(g_matchEvent == MATCHING_SELECTED)
					{
						sceNetAdhocMatchingCancelTarget(matchingId, mac);
					}
					else if(g_matchEvent == MATCHING_ESTABLISHED)
					{
						currentState = PSP_ESTABLISHED;
					}
					else if(g_matchEvent == MATCHING_REJECTED)
					{
						currentState = PSP_LISTING;
					}
				}
				break;
			}
			case PSP_SELECTED:
			{
				g_Server = 1;

				//pspDebugScreenInit();
				pgFillAllvram(0);pgScreenFrame(2,0);
				
				sceNetEtherNtostr(mac, tempStr);
				sprintf(str,"%s has requested a connection\nTo accept the connection press X, to cancel press O\n", tempStr);
				mh_print(0,0,str,0xFFFF);
				pgScreenFlipV();

				if(m_PspPad.Buttons != oldButtons)
				{
					if(m_PspPad.Buttons & PSP_CTRL_CIRCLE)
					{
						sceNetAdhocMatchingCancelTarget(matchingId, mac);
						currentState = PSP_LISTING;
					}
					if(m_PspPad.Buttons & PSP_CTRL_CROSS)
					{
						sceNetAdhocMatchingSelectTarget(matchingId, mac, 0, 0);
						currentState = PSP_WAIT_EST;
					}
				}

				if(matchChanged)
				{
					if(g_matchEvent == MATCHING_CANCELED)
					{
						currentState = PSP_LISTING;
					}
				}
				break;
			}
			case PSP_WAIT_EST:
			{
				if(matchChanged)
				{
					if(g_matchEvent == MATCHING_ESTABLISHED)
					{
						currentState = PSP_ESTABLISHED;
					}
				}
				break;
			}
		}

		matchChanged = 0;
		oldButtons = m_PspPad.Buttons;

		if(currentState == PSP_ESTABLISHED)
			break;

		sceDisplayWaitVblankStart();
	}

	char macAddr[10];
	char *tempMac;
	if(g_Server)
	{
		sceWlanGetEtherAddr(macAddr);
		tempMac = macAddr;
	}
	else
	{
		tempMac = mac;
	}

	sceNetEtherNtostr(tempMac, tempStr);

	char ssid[10];
	sprintf(ssid, "%c%c%c%c%c%c", tempStr[9], tempStr[10], tempStr[12], tempStr[13], 
			tempStr[15], tempStr[16]);
	adhocReconnect(ssid);

	// We only get here if both PSP's have agreed to connect
	//pspDebugScreenInit();
	//pspDebugScreenPrintf("Connected\n");
	pgFillAllvram(0);pgScreenFrame(2,0);
	mh_print(0,0,"Connected",0xFFFF);
	pgScreenFlipV();

	return 0;
}
Ejemplo n.º 9
0
int main(int argc, char** argv)
{
#ifdef USE_DEBUGNET
    int ret = debugNetInit("255.255.255.255", 18194, DEBUG);
    printf("debugNetInit: %d", ret);
#endif

    printf("DOOM started\n");

    setbuf(stdout, NULL);

    int res = scePowerSetArmClockFrequency(50);
    if (res != 0x0)
    {
        printf("scePowerSetArmClockFrequency failed! (0x%08x) (Normal if not using PSM Unity 1.06. No clock speed change for you.)\n", res);
    }

    myargc = 0;
    myargv = 0;

    doomwaddir = PSP2_DIR("Documents/");
    strcpy_s(doomwaddir2, 256, doomwaddir);
    strcat(doomwaddir2, "WADS/");

    printf("WAD folder: %s\n", doomwaddir2);

	//pspAudioInit();
	//pspAudioSetChannelCallback(0, (void *)&sound_callback);

	//_DisableFPUExceptions();
//	pspDebugScreenInit();

	//sceCtrlSetSamplingCycle(0);

	//int result = sceCtrlSetSamplingMode(PSP2_CTRL_MODE_ANALOG);
 //   if (result < 0)
 //   {
 //       printf("sceCtrlSetSamplingMode : 0x%x", result);
 //   }

	//SetupCallbacks();
        pgInit();
        pgScreenFrame(2,0);
        pgFillvram(0);

    Get_DirList(doomwaddir2);
    dlist_start  = 0;
    dlist_curpos = 0;
    now_depth    = 0;

while(1) {
    Draw_All();
switch(Control()) {
		case 1:
			Get_DirList(doomwaddir2);
			break;
		case 2:
                        pgFillvram(0);
                        strcpy_s(target, 264, doomwaddir2);
                        strcat(target, dlist[dlist_curpos].name);

                        pgScreenFlipV();
                        //pspDebugScreenInit();

    D_DoomMain (); 
        }
    }    

    return 0;

}
Ejemplo n.º 10
0
// Picks an IP address - int[4]
int IP_picker(int* address)
{
    u32 buttonsLast = 0;
    int bRedraw = 1;
    int iPick = 0;
    int ipaddr[4];

    if (address == NULL)
        return -1; // nowhere to store the IP!

    // copy the address
    for (iPick = 0;iPick<4;iPick++) ipaddr[iPick]=address[iPick];
    iPick = 0;
    
    sceCtrlSetSamplingCycle(0);
    sceCtrlSetSamplingMode(0); // digital

    char number[5];
    while (1)
    {
        int i;
        SceCtrlData pad;
        u32 buttonsNew;


        if (bRedraw)
        {
            pgFillvram(0);
            pgPrint4AtPixel(X_TITLE, X_TITLE, COLOR_GREY50, "Server IP");
            for (i = 0; i < 4; i++)
            {
                u32 color1 = COLOR_GREY25;
                if (i == iPick)
		{
                    color1 = COLOR_GREY75;
                    // underline selected number
                    pgPrint2AtPixel(i*16*4+32, MIDSCREEN+16, COLOR_WHITE, "---");
                }
                sprintf(number,"%3d",ipaddr[i]);
                if (i < 3) {
		    number[3]='.';
		    number[4]=0;
                }
                pgPrint2AtPixel(i*16*4+32, MIDSCREEN, color1, number);
            }
            pgScreenFlipV();
            bRedraw = 0;
        }

        // handle inputs
        sceCtrlReadBufferPositive(&pad, 1);
        buttonsNew = pad.Buttons & ~buttonsLast;
        buttonsLast = pad.Buttons;
        if (buttonsNew & PSP_CTRL_RIGHT)
        {
            iPick++;
            if (iPick >= 4)
                iPick = 0;
            bRedraw = 1;
        }
        else if (buttonsNew & PSP_CTRL_LEFT)
        {
            iPick--;
            if (iPick < 0)
                iPick = 3;
            bRedraw = 1;
        }
        else if (buttonsLast & PSP_CTRL_UP) {
             ipaddr[iPick]++;
             if (ipaddr[iPick]>255) ipaddr[iPick]=0;
             bRedraw = 1;
        }
        else if (buttonsLast & PSP_CTRL_DOWN) {
             ipaddr[iPick]--;
             if (ipaddr[iPick]<0) ipaddr[iPick]=255;
             bRedraw = 1;
        }
        else if (buttonsNew & (PSP_CTRL_CIRCLE | PSP_CTRL_CROSS))
        {
                break; // picked !
        }
        else if (buttonsNew & PSP_CTRL_TRIANGLE)
        {
            iPick = -1; // cancel
            break;
        }
    }

    // show_confirmation: show final selection for a short time
    pgFillvram(0);
    pgPrint4AtPixel(X_TITLE, Y_TITLE, COLOR_GREY50, "Server IP");
    if (iPick != -1) {
	int i;
	for (i=0;i<4;i++) address[i]=ipaddr[i];
    }
    
    for (iPick = 0; iPick<4; iPick++) {
        sprintf(number,"%3d",address[iPick]);
    	if (iPick < 3) {
	    number[3]='.';
	    number[4]=0;
        }
        pgPrint2AtPixel(iPick*16*4+32, MIDSCREEN, COLOR_WHITE, number);
    }
    pgScreenFlipV();
    pgWaitVn(50);

    return 0;
}
Ejemplo n.º 11
0
int my_picker(const PICKER* pickerP)
{
    int iPick = pickerP->pick_start;
    u32 buttonsLast = 0;
    int bRedraw = 1;

    if (pickerP->pick_count == 0)
        return -1; // nothing to pick

    sceCtrlSetSamplingCycle(0);
    sceCtrlSetSamplingMode(0); // digital

    while (1)
    {
        int i;
        SceCtrlData pad;
        u32 buttonsNew;

        if (pickerP->pick_count == 1)
        {
            // auto-pick if only one
            iPick = 0;
            break;
        }

        if (bRedraw)
        {
            pgFillvram(0);
            pgPrint4AtPixel(X_TITLE, X_TITLE, COLOR_GREY50, pickerP->szTitle);
            for (i = 0; i < pickerP->pick_count; i++)
            {
                PICKER_INFO const* pickP = &pickerP->picks[i];
                u32 color1 = COLOR_GREY25;
                u32 color2 = COLOR_GREY12;
                int y2;
                if (i == iPick)
                {
                    color1 = COLOR_GREY75;
                    color2 = COLOR_GREY50;
                    pgPrint4AtPixel(0, Y_PICK(i), COLOR_WHITE, STR_PICK);
                }
                pgPrint4AtPixel(X_PICK, Y_PICK(i), color1, pickP->szBig);
                y2 = Y_PICK_FINEPRINT(i);
                if (i != MAX_PICK-1)
                    y2 += 2;    // space it out a little
                pgPrint1AtPixel(X_PICK_FINEPRINT, y2, color2, pickP->szFinePrint);
            }
            pgScreenFlipV();
            bRedraw = 0;
        }

        // handle up/down inputs
        sceCtrlReadBufferPositive(&pad, 1); 
        buttonsNew = pad.Buttons & ~buttonsLast;
        buttonsLast = pad.Buttons;
        if (buttonsNew & PSP_CTRL_DOWN)
        {
            iPick++;
            if (iPick >= pickerP->pick_count)
                iPick = pickerP->pick_count-1;
            bRedraw = 1;
        }
        else if (buttonsNew & PSP_CTRL_UP)
        {
            iPick--;
            if (iPick < 0)
                iPick = 0;
            bRedraw = 1;
        }
        else if (buttonsNew & (PSP_CTRL_CIRCLE | PSP_CTRL_CROSS))
        {
            if (iPick >= 0 && iPick < pickerP->pick_count)
                break; // picked !
        }
        else if (buttonsNew & PSP_CTRL_TRIANGLE)
        {
            iPick = -1; // cancel
            break;
        }
    }

    // show_confirmation: show final selection for a short time
    pgFillvram(0);
    pgPrint4AtPixel(X_TITLE, Y_TITLE, COLOR_GREY50, pickerP->szTitle);
    if (iPick != -1)
        pgPrint4AtPixel(X_PICK, Y_PICK(iPick), COLOR_WHITE, pickerP->picks[iPick].szBig);
    else
        pgPrint4AtPixel(X_PICK, Y_PICK(2), COLOR_WHITE, "[Cancel]");
    pgScreenFlipV();
    pgWaitVn(50);

    return iPick;
}