How to call native thingies

Discuss the development of new homebrew software, tools and libraries.

Moderators: cheriff, TyRaNiD

Post Reply
Flip333
Posts: 7
Joined: Mon Oct 20, 2008 4:41 am

How to call native thingies

Post by Flip333 »

How would someone call a native message box or Yes/No question in their own game in C?
J.F.
Posts: 2906
Joined: Sun Feb 22, 2004 11:41 am

Post by J.F. »

I use the native stuff like that in the init code of my TV version of SDL and PSPGL. Look for the recent thread on that.
Flip333
Posts: 7
Joined: Mon Oct 20, 2008 4:41 am

Post by Flip333 »

This thread?
http://forums.ps2dev.org/viewtopic.php? ... t=sdl+pspg
I didn't see anything in it.

What would I need to include and what are the functions?
J.F.
Posts: 2906
Joined: Sun Feb 22, 2004 11:41 am

Post by J.F. »

Yes, that's the thread. Look at the code added to SDL in src/video/psp/SDL_pspvideo.c. These are the main routines:

Code: Select all

static pspUtilityMsgDialogParams dialog;

static void SetupGu(void)
{
    sceGuInit();

    sceGuStart(GU_DIRECT, list);
    sceGuDrawBuffer(GU_PSM_8888, (void*)0, 512);
    sceGuDispBuffer(480, 272, (void*)0x88000, 512);
    sceGuDepthBuffer((void*)0x110000, 512);
    sceGuOffset(2048 - (480/2), 2048 - (272/2));
    sceGuViewport(2048, 2048, 480, 272);
    sceGuDepthRange(0xc350, 0x2710);
    sceGuScissor(0, 0, 480, 272);
    sceGuEnable(GU_SCISSOR_TEST);
    sceGuDepthFunc(GU_GEQUAL);
    sceGuEnable(GU_DEPTH_TEST);
    sceGuFrontFace(GU_CW);
    sceGuShadeModel(GU_SMOOTH);
    sceGuEnable(GU_CULL_FACE);
    sceGuEnable(GU_CLIP_PLANES);
    sceGuFinish();
    sceGuSync(0, 0);

    sceDisplayWaitVblankStart();
    sceGuDisplay(GU_TRUE);
}

static void ConfigureDialog(pspUtilityMsgDialogParams *dialog, size_t dialog_size)
{
    memset(dialog, 0, dialog_size);

    dialog->base.size = dialog_size;
    sceUtilityGetSystemParamInt(PSP_SYSTEMPARAM_ID_INT_LANGUAGE,
				&dialog->base.language); // Prompt language
    sceUtilityGetSystemParamInt(PSP_SYSTEMPARAM_ID_INT_UNKNOWN,
				&dialog->base.buttonSwap); // X/O button swap

    dialog->base.graphicsThread = 0x11;
    dialog->base.accessThread = 0x13;
    dialog->base.fontThread = 0x12;
    dialog->base.soundThread = 0x10;
}

static void ShowMessageDialog(const char *message, int enableYesno)
{
    ConfigureDialog(&dialog, sizeof(dialog));
    dialog.mode = PSP_UTILITY_MSGDIALOG_MODE_TEXT;
	dialog.options = PSP_UTILITY_MSGDIALOG_OPTION_TEXT;

	if(enableYesno)
		dialog.options |= PSP_UTILITY_MSGDIALOG_OPTION_YESNO_BUTTONS|PSP_UTILITY_MSGDIALOG_OPTION_DEFAULT_NO;

    strcpy(dialog.message, message);

    sceUtilityMsgDialogInitStart(&dialog);

    for(;;)
    {
	    sceGuStart(GU_DIRECT,list);

	    // clear screen
	    sceGuClearColor(0xff554433);
	    sceGuClearDepth(0);
	    sceGuClear(GU_COLOR_BUFFER_BIT|GU_DEPTH_BUFFER_BIT);

	    sceGuFinish();
	    sceGuSync(0,0);

		switch(sceUtilityMsgDialogGetStatus()) {
			case 2:
	    	sceUtilityMsgDialogUpdate(1);
	    	break;

			case 3:
	    	sceUtilityMsgDialogShutdownStart();
	    	break;

			case 0:
	    	return;

		}

		//sceDisplayWaitVblankStart();
		sceDisplayWaitVblankStart();
		sceGuSwapBuffers();
    }
}
and are called like this:

Code: Select all

	if (pad.Buttons & PSP_CTRL_TRIANGLE)
	{
		SetupGu();
		if (PSP_TV_CABLE > 0)
		{
			ShowMessageDialog("Use TV output?", 1);
			if(dialog.buttonPressed == PSP_UTILITY_MSGDIALOG_RESULT_NO)
			{
				PSP_TV_CABLE = 0;
				PSP_TV_LACED = 0;
				PSP_DSP_ASPECT = 1;
				PSP_DSP_WIDE = 1;
			}
			else
			{
				if (PSP_TV_CABLE == 2)
				{
					ShowMessageDialog("Use interlaced output?", 1);
					if(dialog.buttonPressed == PSP_UTILITY_MSGDIALOG_RESULT_YES)
						PSP_TV_LACED = 1;
				}
				ShowMessageDialog("Using 16:9 (HDTV) display?", 1);
				if(dialog.buttonPressed == PSP_UTILITY_MSGDIALOG_RESULT_NO)
					PSP_DSP_ASPECT = 0;
			}
		}
		ShowMessageDialog("Display as Widescreen?", 1);
		if(dialog.buttonPressed == PSP_UTILITY_MSGDIALOG_RESULT_NO)
			PSP_DSP_WIDE = 0;
		/* write preferences */
		FILE *fd;
		char temp[256];

		fd = fopen("SDL_VID_PREFS", "w");
		if (fd != NULL)
		{
			fwrite ("-vmode", 1, 6, fd);
			fwrite ("\n", 1, 1, fd);
			sprintf(temp, "%d", PSP_TV_CABLE);
			fwrite (temp, 1, strlen(temp), fd);
			fwrite ("\n", 1, 1, fd);
			fwrite ("-laced", 1, 6, fd);
			fwrite ("\n", 1, 1, fd);
			sprintf(temp, "%d", PSP_TV_LACED);
			fwrite (temp, 1, strlen(temp), fd);
			fwrite ("\n", 1, 1, fd);
			fwrite ("-aspect", 1, 7, fd);
			fwrite ("\n", 1, 1, fd);
			sprintf(temp, "%d", PSP_DSP_ASPECT);
			fwrite (temp, 1, strlen(temp), fd);
			fwrite ("\n", 1, 1, fd);
			fwrite ("-wide", 1, 5, fd);
			fwrite ("\n", 1, 1, fd);
			sprintf(temp, "%d", PSP_DSP_WIDE);
			fwrite (temp, 1, strlen(temp), fd);
			fwrite ("\n", 1, 1, fd);
			fclose(fd);
		}
	}
Insert_witty_name
Posts: 376
Joined: Wed May 10, 2006 11:31 pm

Post by Insert_witty_name »

There's a sample in the SDK.

samples/utility/msgdialog
Geijer
Posts: 3
Joined: Wed Aug 18, 2004 8:39 am

Post by Geijer »

J.F. wrote: ...

Code: Select all

...
    for(;;)
    {
	    sceGuStart(GU_DIRECT,list);

	    // clear screen
	    sceGuClearColor(0xff554433);
	    sceGuClearDepth(0);
	    sceGuClear(GU_COLOR_BUFFER_BIT|GU_DEPTH_BUFFER_BIT);

	    sceGuFinish();
	    sceGuSync(0,0);

		switch(sceUtilityMsgDialogGetStatus()) {
			case 2:
	    	sceUtilityMsgDialogUpdate(1);
	    	break;

			case 3:
	    	sceUtilityMsgDialogShutdownStart();
	    	break;

			case 0:
	    	return;

		}

		//sceDisplayWaitVblankStart();
		sceDisplayWaitVblankStart();
		sceGuSwapBuffers();
    }
...
Just recently experimented a little with the dialogs and found a potential problem with this code and the code in samples/utility/msgdialog if the comment in the SDK is correct:

Code: Select all

/**
 * Remove a message dialog currently active.  After calling this
 * function you need to keep calling GetStatus and Update until
 * you get a status of 4.
 */
void sceUtilityMsgDialogShutdownStart(void);
Insert_witty_name
Posts: 376
Joined: Wed May 10, 2006 11:31 pm

Post by Insert_witty_name »

The sample is the correct, the comment isn't ;)
Flip333
Posts: 7
Joined: Mon Oct 20, 2008 4:41 am

Post by Flip333 »

Hey, thanks for that.
I tried using the code he gave me and I couldn't get it to work.
I looked myself, but I guess I didn't look hard enough because I never found the sample. Thanks for the directory. I'll have a look at it.
Post Reply