summaryrefslogtreecommitdiff
path: root/libpsx/src/util.c
blob: a9c792192a90b4a043317e844ac9f54037e96275 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
// util.c
// PSXSDK utility functions

// This is not a core part of the PSXSDK

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <psxutil.h>

const char *psxsdk_btn_names[] =
							     { "L2", "R2", "L1", "R1", "Triangle", "Circle", "Cross",
								 "Square", "Select", "Res1", "Res2", "Start",
								 "Up", "Right", "Down", "Left"};
								 
char *PSX_GetButtonName(unsigned short button, char *out, unsigned int out_len)
{
	int x;
	
	if(out_len)out[0] = 0;
	
	for(x = 0; x < 16; x++)
	{
		if(button & (1<<x))
		{
			strncat(out, psxsdk_btn_names[x], out_len);
			out_len -= strlen(out);
			strncat(out, "&", out_len);
			out_len--;
		}
	}
		
	if(strlen(out))
	{
		if(out[strlen(out) - 1] == '&')
			out[strlen(out) - 1] = 0;
	}
	else
		strncpy(out, "None", out_len);
	
	return out;
}