Page 1 of 1

Thanks for GC/Wii support, I made a thing... ^_ ^

Posted: Sat Mar 10, 2018 9:38 pm
by eleriaqueen
Hello, I like doing little projects here and there. One of my small dreams was making a Section ID calculator (which basically gives you the color the game would assign to your character name in Phantasy Star Online Ep. 1&2 and earlier games) that would run on a gamecube and wii. So I did, thanks to this devkit.
GC version uses up/down on the controller to choose a letter, A to "save" a letter, and X / Y to display your Section ID, in (slightly inaccurate) color using esape sequences.
Wii version only has keyboard support.
(Only tested in Dolphin Emu so far /sadface)

I decided to make a very small financial contribution to the devkitpro today.

You rock!


Here's a link to my thing : https://github.com/eleriaqueen/wiiSeccy
(My knowledge of the C language is "a bit" limited, code isn't pretty, but advices/comments are always appreciated)
2018-03-05_18-45-15.gif
Slightly outdated Gif of Gamecube Version
(17.43 KiB) Not downloaded yet

Re: Thanks for GC/Wii support, I made a thing... ^_ ^

Posted: Tue Jun 12, 2018 3:00 pm
by WinterMute
Thanks for the donation, much appreciated.

Some quick tips.

The template makefiles for Wii and Gamecube are deliberately very similar to allow building the same code for Wii & Cube with minor changes. It's mainly swapping include $(DEVKITPPC)/gamecube_rules for include $(DEVKITPPC)/wii_rules in the makefile.

In your source you can then use #ifdef on __wii__ and __gamecube__ to differentiate code intended for different platforms.

I can do you a PR at some point with the build tidied up a bit so you can build both with the same source if you like?

Re: Thanks for GC/Wii support, I made a thing... ^_ ^

Posted: Sun Apr 14, 2019 4:58 pm
by eleriaqueen
Hi, quite some time has passed, I updated my homebrew's code a few times and followed your advice about #ifdef __wii__

Here's the code.

Code: Select all

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <malloc.h>
#include <ogcsys.h>
#include <gccore.h>

#ifdef __wii__
#include <wiiuse/wpad.h>
#endif

#include <unistd.h>

static void *xfb = NULL;
static GXRModeObj *rmode = NULL;

void *Initialise();

bool quitapp = false;

#define PSO_NAME_SIZE_MAX 12
#define PSO_LEGACY_VALUE 5

char *pso_sectionid[] = {"Pinkal", "Redria", "Oran", "Yellowboze", "Whitill", "Viridia", "Greenill", "Skyly", "Bluefull", "Purplenum"};

void countdwn(unsigned int count);
unsigned int is_str_ascii(char *str);
unsigned int pso_strcpt(char *input_str, unsigned int cval);
void printheader();

extern void __SYS_ReadROM(void *buf, u32 len, u32 offset);

int main(int argc, char **argv)
{
	char buf[13];
	memset(buf, 0, sizeof(buf));
	char letter = 'A';
	unsigned int c = 0;
	char *secId;

	char *down = "\x1b[1B";
	char *up = "\x1b[1A";
	char *left = "\b";

#define LUPL() printf("%s%s%c%s", left, up, letter + 1, left) // Left, Up, PrintChar, Left
#define DDPU() printf("%s%s%c%s", down, down, letter - 1, up) // Down, Down, PrintChar, Up

#define LUSL() printf("%s%s %s", left, up, left) // Left, Up, PrintSpace, Left
#define DDSU() printf("%s%s %s", down, down, up) // Down, Down, PrintSpace, Up

#define CON_CLR() printf("\x1b[2J") // Console_Clear

	xfb = Initialise();

#ifdef __wii__
	// This function initialises the attached controllers
	WPAD_Init();
#endif

	printheader();

	printf("\n              > %c", letter);

	LUPL();
	DDPU();

	while (1)
	{

		PAD_ScanPads();
		u32 buttonsDown = PAD_ButtonsDown(0);

		if ((buttonsDown & PAD_BUTTON_A) && (c < 12))
		{

			LUSL();
			DDSU();

			printf("%c", letter);

			if (letter < 126)
				LUPL();
			else
				LUSL();

			if (letter > 33)
				DDPU();
			else
				DDSU();
			buf[c] = letter;
			c++;
		}

		if ((buttonsDown & PAD_BUTTON_B) && (c > 0))
		{
			printf("%s%s %s%s", left, up, left, down);
			printf("%s %s%s", down, left, up);
			printf(" %s", left);

			if (letter < 126)
				LUPL();
			else
				LUSL();

			if (letter > 33)
				DDPU();
			else
				DDSU();

			printf("%s", left);
			printf("%c", letter);

			buf[c - 1] = '\0';
			c--;
		}

		if (((buttonsDown & PAD_BUTTON_Y) || (buttonsDown & PAD_BUTTON_X)) && (c > 0))
		{
			LUSL();
			DDSU();

			printf("\b = ");

			secId = pso_sectionid[pso_strcpt(buf, PSO_LEGACY_VALUE)];

			printf("%s\n\n\n\n%s%s", secId, left, up); // secId, 4 Newlines, then Left Up
			// printf("\x1b[39m"); // Restore foreground color
			printf("              > %c", letter);

			if (letter < 126)
				LUPL();
			else
				LUSL();

			if (letter > 33)
				DDPU();
			else
				DDSU();

			c = 0;
			memset(buf, 0, sizeof(buf));
		}

		if ((buttonsDown & PAD_BUTTON_UP) && (letter < 126))
		{
			letter++;
			printf("\b%c", letter);

			if (letter < 126)
				LUPL();
			else
				LUSL();

			DDPU();
		}
		if ((buttonsDown & PAD_BUTTON_DOWN) && (letter > 32))
		{
			letter--;
			printf("\b%c", letter);

			LUPL();

			if (letter > 33)
				DDPU();
			else
				DDSU();
		}

		if (buttonsDown & PAD_BUTTON_START)
		{
			CON_CLR();

			printheader();

			c = 0;
			memset(buf, 0, sizeof(buf));
			printf("\n              > %c", letter);
		}
		VIDEO_WaitVSync();

#ifdef __wii__
		if ((buttonsDown & WPAD_BUTTON_HOME) | quitapp)
		{
			printf("Quitting in:\n");
			countdwn(3);
			exit(0);
		}
#endif
	}

	return 0;
}

void *Initialise()
{

	void *framebuffer;

	VIDEO_Init();
	PAD_Init();

	static char IPLInfo[256];
	__SYS_ReadROM(IPLInfo, 256, 0);

	PAD_ScanPads();

#ifdef __wii__
	rmode = VIDEO_GetPreferredMode(NULL);
#elif __gc__

	// L Trigger held down ignores the fact that there's a component cable plugged in.
	if (VIDEO_HaveComponentCable() && !(PAD_ButtonsDown(0) & PAD_TRIGGER_L))
	{
		if ((strstr(IPLInfo, "PAL") != NULL))
		{
			rmode = &TVEurgb60Hz480Prog; //Progressive 480p
		}
		else
		{
			rmode = &TVNtsc480Prog; //Progressive 480p
		}
	}
	else
	{
		//try to use the IPL region
		if (strstr(IPLInfo, "PAL") != NULL)
		{
			rmode = &TVPal576IntDfScale; //PAL
		}
		else if (strstr(IPLInfo, "NTSC") != NULL)
		{
			rmode = &TVNtsc480IntDf; //NTSC
		}
		else
		{
			rmode = VIDEO_GetPreferredMode(NULL); //Last mode used
		}
	}
#endif

	framebuffer = MEM_K0_TO_K1(SYS_AllocateFramebuffer(rmode));
	console_init(framebuffer, 20, 20, rmode->fbWidth, rmode->xfbHeight, rmode->fbWidth * VI_DISPLAY_PIX_SZ);

	VIDEO_Configure(rmode);

	/*** Set the framebuffer to be displayed at next VBlank ***/
	VIDEO_SetNextFramebuffer(framebuffer);

	VIDEO_SetBlack(FALSE);

	/*** Update the video for next vblank ***/
	VIDEO_Flush();

	VIDEO_WaitVSync(); /*** Wait for VBL ***/
	if (rmode->viTVMode & VI_NON_INTERLACE) VIDEO_WaitVSync();

	return framebuffer;
}

void printheader()
{
	// 80 characters
	// printf("123456789 123456789 123456789 123456789 123456789 123456789 123456789  123456789 \n");
	printf("              ---------------------------------------------------                \n");
	printf("              -              Section ID Tool for GC             -                \n");
	printf("              ---------------------------------------------------                \n\n");
	printf("                                                                                 \n");
	printf("              [A] memorises a letter/character.                                  \n");
	printf("              [X] and [Y] print the Section ID which corresponds                 \n");
	printf("              to what you memorised.                                             \n");
	printf("              [Start] clears the screen.                                         \n");
	printf("              [B] deletes last input letter/character.                           \n\n");
}

void countdwn(unsigned int count)
{
	for (unsigned int i = (count); i > 0; i--)
	{
		printf("%u...\n", i);
		sleep(1);
	}
}

unsigned int pso_strcpt(char *input_str, unsigned int cval)
{
	unsigned int sum = 0;
	char *c = input_str;
	while (*c)
	{
		sum += (*c);
		c++;
	}
	return ((sum + cval) % 10);
}

Re: Thanks for GC/Wii support, I made a thing... ^_ ^

Posted: Sun Apr 14, 2019 7:31 pm
by eleriaqueen
Err, code in those code tags is wrong, sorry, If someone wants to take a peek rather go to my github :)