Code: Select all
Matt@steamloller /usr/local/pspdev/psp/sdk/samples/pi
$ psp-gcc -I. -I/usr/local/pspdev/psp/sdk/include -O2 -G0 -Wall -L. -L/usr/local/pspdev/psp/sdk/lib main.o -lpspdebug -lpsplibc -lpspkernel -lm -o pi.elf
/usr/local/pspdev/lib/gcc/psp/4.0.0/../../../../psp/lib/crt0.o: In function `__e
ntrytable':
crt0.S:(.rodata.sceResident+0xc): undefined reference to `module_info'
/usr/local/pspdev/lib/gcc/psp/4.0.0/../../../../psp/lib/libm.a(w_sqrt.o): In function `sqrt':
../../../../../newlib/libm/math/w_sqrt.c:83: undefined reference to `__errno'
../../../../../newlib/libm/math/w_sqrt.c:86: undefined reference to `__errno'
collect2: ld returned 1 exit statusCode: Select all
#include <pspkernel.h>
#include <pspdebug.h>
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include <stdarg.h>
#include <math.h>
#define O_RDONLY    0x0001
#define O_WRONLY    0x0002
#define O_RDWR      0x0003
#define O_NBLOCK    0x0010
#define O_APPEND    0x0100
#define O_CREAT     0x0200
#define O_TRUNC     0x0400
#define O_NOWAIT    0x8000 
int file = 0;
int LogOpen(char *path) {
	file = sceIoOpen(path, PSP_O_CREAT|PSP_O_RDWR|PSP_O_TRUNC, 0777);
	return file;
}
int LogClose() {
	if(file)
		sceIoClose(file);
	return 0;
}
int LogPrintf(char *fmt, ...) {
	va_list opt;
  
	char buff[2048];
	int bufsz;
  
	va_start(opt, fmt);
	bufsz = vsnprintf( buff, (size_t) sizeof(buff), fmt, opt);
	sceIoWrite(file, buff, bufsz);
	return 0;
}
double find(double x,double a) {
	double y;
	y=sqrt((a*a)-(x*x));
	return y;
};
int main() {
	file = LogOpen("ms0:/pi.txt");
	double ind,delta,rad,dec,sum=0.0,x,y,xnow,ynow,length;
	rad = 300;
	printf("Radius = 300\n");
	LogPrintf("Radius = 300\n");
	dec = 0.1;
	printf("Decrease in x = 0.1\n");
	LogPrintf("Decrease in x = 0.1\n");
	x=rad;
	y=0.0;
	delta=rad/100.0;
	ind=1.0;
	for(xnow=rad;xnow>=0.0;xnow=xnow-dec) {
		ynow=find(xnow,rad);
		length=sqrt(((x-xnow)*(x-xnow))+((ynow-y)*(ynow-y)));
		sum=sum+length;
		x=xnow;
		y=ynow;
		if(xnow<=rad-(ind*delta)) {
			printf("\n%.0lf of 100 completed.",ind);
			LogPrintf("\n%.0lf of 100 completed.",ind);
			ind=ind+1.0;
		};
	};
	LogPrintf("Pi=%.10lf",2.0*sum/rad);
	LogClose();
	printf("\nPi=%.10lf",2.0*sum/rad);
	sceKernelExitGame();
	return(0);
};
