summaryrefslogtreecommitdiff
path: root/Source/TestSuite/FPU/source/dolphintest_fpu.cpp
blob: d465b0c6145d6157b3692cccca5cce2e5dcb95c8 (plain)
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <malloc.h>
#include <ogcsys.h>
#include <gccore.h>
#include <stdarg.h>
#include <ctype.h>
#include <math.h>
#include <wiiuse/wpad.h>

// Pull in the assembly functions.
extern "C" {
void TestFRES1(u32 *fpscr, float *result, float *result2);
};

int doreload=0, dooff=0;
void reload() {	doreload=1; }
void shutdown() { dooff=1; }


void Compare(const char *a, const char *b) {
	if (!strcmp(a, b)) {
		printf("SUCCESS - %s\n", a);
	} else {
		printf("FAIL - %s != \n"
			   "       %s\n", a, b);
	}
}

void TestDivision() {
	double a, b, c, d, e;
	a = 1.0;
	b = 0.0;
	c = a / b;
	d = b / a;
	e = sqrt(-1);
	char temp[100];
	sprintf(temp, "%1.1f %1.1f %1.1f %1.1f %1.1f", a, b, c, d, e);
	Compare(temp, "1.0 0.0 inf 0.0 nan");
}

void TestFres() {
	u32 fpscr[2];
	float out, out2;
	TestFRES1(fpscr, &out, &out2);
	char temp[100];
	sprintf(temp, "%08x %1.1f %1.1f", fpscr[1], out, out2);
	Compare(temp, "86002004 inf 0.0");
}

void TestNormalize() {
	//float a[3] = {2,2,2};
	//d_guVecNormalize(a);
	//printf("%f %f %f\n", a[0], a[1], a[2]);
}


int main(int argc, char **argv) {
	void *xfb[2];
	int fbi = 0;
	GXRModeObj *rmode = NULL;

	VIDEO_Init();
	PAD_Init();
	WPAD_Init();

	rmode = VIDEO_GetPreferredMode(NULL);

	// double buffering, prevents flickering (is it needed for LCD TV? i don't have one to test)
	xfb[0] = MEM_K0_TO_K1(SYS_AllocateFramebuffer(rmode));
	xfb[1] = MEM_K0_TO_K1(SYS_AllocateFramebuffer(rmode));

	VIDEO_Configure(rmode);
	VIDEO_SetNextFramebuffer(xfb[0]);
	VIDEO_SetBlack(FALSE);
	VIDEO_Flush();
	VIDEO_WaitVSync();
	if (rmode->viTVMode & VI_NON_INTERLACE) VIDEO_WaitVSync();

	SYS_SetResetCallback(reload);
	SYS_SetPowerCallback(shutdown);

	WPAD_SetDataFormat(0, WPAD_FMT_BTNS_ACC_IR);
	WPAD_SetVRes(0, rmode->fbWidth, rmode->xfbHeight);

	CON_Init(xfb[fbi],0,0,rmode->fbWidth,rmode->xfbHeight,rmode->fbWidth*VI_DISPLAY_PIX_SZ);

	printf(" ");
	printf("Tests\n\n");

	TestDivision();
	TestFres();

	while (!doreload && !dooff) {
		WPAD_ScanPads();
		if (WPAD_ButtonsDown(0) & WPAD_BUTTON_HOME)
			exit(0);

		VIDEO_SetNextFramebuffer(xfb[fbi]);
		VIDEO_Flush();
		VIDEO_WaitVSync();
	}
	if(doreload) return 0;
	if(dooff) SYS_ResetSystem(SYS_SHUTDOWN,0,0);

	return 0;
}