mirror of
https://github.com/RaySollium99/picodrive.git
synced 2025-09-05 15:27:46 -04:00
initial import
git-svn-id: file:///home/notaz/opt/svn/PicoDrive@2 be3aeb3a-fb24-0410-a615-afba39da0efa
This commit is contained in:
parent
2cadbd5e56
commit
cc68a136aa
341 changed files with 180839 additions and 0 deletions
93
platform/gp2x/940.c
Normal file
93
platform/gp2x/940.c
Normal file
|
@ -0,0 +1,93 @@
|
|||
#include "940shared.h"
|
||||
|
||||
/* this code assumes that we live @ 0x3000000 bank */
|
||||
//static volatile unsigned short *gp2x_memregs = (void *) 0x0xbd000000;
|
||||
//static volatile unsigned long *gp2x_memregl = (void *) 0x0xbd000000;
|
||||
|
||||
static _940_data_t *shared_data = (_940_data_t *) 0x100000;
|
||||
static _940_ctl_t *shared_ctl = (_940_ctl_t *) 0x200000;
|
||||
YM2612 *ym2612_940;
|
||||
int *mix_buffer;
|
||||
|
||||
// from init.s
|
||||
void wait_irq(void);
|
||||
void spend_cycles(int c);
|
||||
void cache_clean(void);
|
||||
void cache_clean_flush(void);
|
||||
|
||||
// asm volatile ("mov r0, #0" ::: "r0");
|
||||
// asm volatile ("mcr p15, 0, r0, c7, c6, 0" ::: "r0"); /* flush dcache */
|
||||
// asm volatile ("mcr p15, 0, r0, c7, c10, 4" ::: "r0"); /* drain write buffer */
|
||||
|
||||
void Main940(int startvector)
|
||||
{
|
||||
ym2612_940 = &shared_data->ym2612;
|
||||
mix_buffer = shared_data->mix_buffer;
|
||||
|
||||
// debug
|
||||
shared_ctl->vstarts[startvector]++;
|
||||
asm volatile ("mcr p15, 0, r0, c7, c10, 4" ::: "r0");
|
||||
|
||||
/* unmask IRQs */
|
||||
|
||||
for (;; shared_ctl->loopc++)
|
||||
{
|
||||
/*
|
||||
while (!shared_ctl->busy)
|
||||
{
|
||||
//shared_ctl->waitc++;
|
||||
spend_cycles(256);
|
||||
}
|
||||
*/
|
||||
if (!shared_ctl->busy)
|
||||
{
|
||||
wait_irq();
|
||||
}
|
||||
|
||||
switch (shared_ctl->job)
|
||||
{
|
||||
case JOB940_YM2612INIT:
|
||||
shared_ctl->writebuff0[0] = shared_ctl->writebuff1[0] = 0xffff;
|
||||
YM2612Init_(shared_ctl->baseclock, shared_ctl->rate);
|
||||
break;
|
||||
|
||||
case JOB940_YM2612RESETCHIP:
|
||||
YM2612ResetChip_();
|
||||
break;
|
||||
|
||||
case JOB940_PICOSTATELOAD:
|
||||
YM2612PicoStateLoad_();
|
||||
break;
|
||||
|
||||
case JOB940_YM2612UPDATEONE: {
|
||||
int i, dw, *wbuff;
|
||||
if (shared_ctl->writebuffsel == 1) {
|
||||
wbuff = (int *) shared_ctl->writebuff1;
|
||||
} else {
|
||||
wbuff = (int *) shared_ctl->writebuff0;
|
||||
}
|
||||
|
||||
/* playback all writes */
|
||||
for (i = 2048/2; i > 0; i--) {
|
||||
UINT16 d;
|
||||
dw = *wbuff++;
|
||||
d = dw;
|
||||
if (d == 0xffff) break;
|
||||
YM2612Write_(d >> 8, d);
|
||||
d = (dw>>16);
|
||||
if (d == 0xffff) break;
|
||||
YM2612Write_(d >> 8, d);
|
||||
}
|
||||
|
||||
YM2612UpdateOne_(0, shared_ctl->length, shared_ctl->stereo);
|
||||
// cache_clean_flush();
|
||||
cache_clean();
|
||||
// asm volatile ("mov r0, #0" ::: "r0");
|
||||
// asm volatile ("mcr p15, 0, r0, c7, c10, 4" ::: "r0"); /* drain write buffer, should be done on nonbuffered write */
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
shared_ctl->busy = 0;
|
||||
}
|
||||
}
|
451
platform/gp2x/940ctl_ym2612.c
Normal file
451
platform/gp2x/940ctl_ym2612.c
Normal file
|
@ -0,0 +1,451 @@
|
|||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
#include <sys/mman.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <fcntl.h>
|
||||
#include <errno.h>
|
||||
|
||||
#include "940shared.h"
|
||||
#include "gp2x.h"
|
||||
#include "emu.h"
|
||||
#include "menu.h"
|
||||
#include "asmutils.h"
|
||||
|
||||
/* we will need some gp2x internals here */
|
||||
extern volatile unsigned short *gp2x_memregs; /* from minimal library rlyeh */
|
||||
extern volatile unsigned long *gp2x_memregl;
|
||||
|
||||
static unsigned char *shared_mem = 0;
|
||||
static _940_data_t *shared_data = 0;
|
||||
static _940_ctl_t *shared_ctl = 0;
|
||||
|
||||
int crashed_940 = 0;
|
||||
|
||||
|
||||
/***********************************************************/
|
||||
|
||||
#define MAXOUT (+32767)
|
||||
#define MINOUT (-32768)
|
||||
|
||||
/* limitter */
|
||||
#define Limit(val, max,min) { \
|
||||
if ( val > max ) val = max; \
|
||||
else if ( val < min ) val = min; \
|
||||
}
|
||||
|
||||
/* these will be managed locally on our side */
|
||||
extern int *ym2612_dacen;
|
||||
extern INT32 *ym2612_dacout;
|
||||
extern void *ym2612_regs;
|
||||
|
||||
static UINT8 *REGS = 0; /* we will also keep local copy of regs for savestates and such */
|
||||
static INT32 addr_A1; /* address line A1 */
|
||||
static int dacen;
|
||||
static INT32 dacout;
|
||||
static UINT8 ST_address; /* address register */
|
||||
static UINT8 ST_status; /* status flag */
|
||||
static UINT8 ST_mode; /* mode CSM / 3SLOT */
|
||||
static int ST_TA; /* timer a */
|
||||
static int ST_TAC; /* timer a maxval */
|
||||
static int ST_TAT; /* timer a ticker */
|
||||
static UINT8 ST_TB; /* timer b */
|
||||
static int ST_TBC; /* timer b maxval */
|
||||
static int ST_TBT; /* timer b ticker */
|
||||
|
||||
static int writebuff_ptr = 0;
|
||||
|
||||
|
||||
/* OPN Mode Register Write */
|
||||
static void set_timers( int v )
|
||||
{
|
||||
/* b7 = CSM MODE */
|
||||
/* b6 = 3 slot mode */
|
||||
/* b5 = reset b */
|
||||
/* b4 = reset a */
|
||||
/* b3 = timer enable b */
|
||||
/* b2 = timer enable a */
|
||||
/* b1 = load b */
|
||||
/* b0 = load a */
|
||||
ST_mode = v;
|
||||
|
||||
/* reset Timer b flag */
|
||||
if( v & 0x20 )
|
||||
ST_status &= ~2;
|
||||
|
||||
/* reset Timer a flag */
|
||||
if( v & 0x10 )
|
||||
ST_status &= ~1;
|
||||
}
|
||||
|
||||
/* YM2612 write */
|
||||
/* a = address */
|
||||
/* v = value */
|
||||
/* returns 1 if sample affecting state changed */
|
||||
int YM2612Write_940(unsigned int a, unsigned int v)
|
||||
{
|
||||
int addr; //, ret=1;
|
||||
|
||||
v &= 0xff; /* adjust to 8 bit bus */
|
||||
a &= 3;
|
||||
|
||||
switch( a ) {
|
||||
case 0: /* address port 0 */
|
||||
ST_address = v;
|
||||
addr_A1 = 0;
|
||||
//ret=0;
|
||||
break;
|
||||
|
||||
case 1: /* data port 0 */
|
||||
if (addr_A1 != 0) {
|
||||
return 0; /* verified on real YM2608 */
|
||||
}
|
||||
|
||||
addr = ST_address;
|
||||
REGS[addr] = v;
|
||||
|
||||
switch( addr & 0xf0 )
|
||||
{
|
||||
case 0x20: /* 0x20-0x2f Mode */
|
||||
switch( addr )
|
||||
{
|
||||
case 0x24: { // timer A High 8
|
||||
int TAnew = (ST_TA & 0x03)|(((int)v)<<2);
|
||||
if(ST_TA != TAnew) {
|
||||
// we should reset ticker only if new value is written. Outrun requires this.
|
||||
ST_TA = TAnew;
|
||||
ST_TAC = (1024-TAnew)*18;
|
||||
ST_TAT = 0;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
case 0x25: { // timer A Low 2
|
||||
int TAnew = (ST_TA & 0x3fc)|(v&3);
|
||||
if(ST_TA != TAnew) {
|
||||
ST_TA = TAnew;
|
||||
ST_TAC = (1024-TAnew)*18;
|
||||
ST_TAT = 0;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
case 0x26: // timer B
|
||||
if(ST_TB != v) {
|
||||
ST_TB = v;
|
||||
ST_TBC = (256-v)<<4;
|
||||
ST_TBC *= 18;
|
||||
ST_TBT = 0;
|
||||
}
|
||||
return 0;
|
||||
case 0x27: /* mode, timer control */
|
||||
set_timers( v );
|
||||
break; // other side needs ST.mode for 3slot mode
|
||||
case 0x2a: /* DAC data (YM2612) */
|
||||
dacout = ((int)v - 0x80) << 6; /* level unknown (notaz: 8 seems to be too much) */
|
||||
return 0;
|
||||
case 0x2b: /* DAC Sel (YM2612) */
|
||||
/* b7 = dac enable */
|
||||
dacen = v & 0x80;
|
||||
break; // other side has to know this
|
||||
default:
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
break;
|
||||
|
||||
case 2: /* address port 1 */
|
||||
ST_address = v;
|
||||
addr_A1 = 1;
|
||||
//ret=0;
|
||||
break;
|
||||
|
||||
case 3: /* data port 1 */
|
||||
if (addr_A1 != 1) {
|
||||
return 0; /* verified on real YM2608 */
|
||||
}
|
||||
|
||||
addr = ST_address | 0x100;
|
||||
REGS[addr] = v;
|
||||
break;
|
||||
}
|
||||
|
||||
if(currentConfig.EmuOpt & 4) {
|
||||
/* queue this write for 940 */
|
||||
if (writebuff_ptr < 2047) {
|
||||
if (shared_ctl->writebuffsel == 1) {
|
||||
shared_ctl->writebuff0[writebuff_ptr++] = (a<<8)|v;
|
||||
} else {
|
||||
shared_ctl->writebuff1[writebuff_ptr++] = (a<<8)|v;
|
||||
}
|
||||
} else {
|
||||
printf("warning: writebuff_ptr > 2047\n");
|
||||
}
|
||||
}
|
||||
|
||||
return 0; // cause the engine to do updates once per frame only
|
||||
}
|
||||
|
||||
UINT8 YM2612Read_940(void)
|
||||
{
|
||||
return ST_status;
|
||||
}
|
||||
|
||||
|
||||
int YM2612PicoTick_940(int n)
|
||||
{
|
||||
//int ret = 0;
|
||||
|
||||
// timer A
|
||||
if(ST_mode & 0x01 && (ST_TAT+=64*n) >= ST_TAC) {
|
||||
ST_TAT -= ST_TAC;
|
||||
if(ST_mode & 0x04) ST_status |= 1;
|
||||
// CSM mode total level latch and auto key on
|
||||
/* FIXME
|
||||
if(ST_mode & 0x80) {
|
||||
CSMKeyControll( &(ym2612_940->CH[2]) ); // Vectorman2, etc.
|
||||
ret = 1;
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
// timer B
|
||||
if(ST_mode & 0x02 && (ST_TBT+=64*n) >= ST_TBC) {
|
||||
ST_TBT -= ST_TBC;
|
||||
if(ST_mode & 0x08) ST_status |= 2;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
static void wait_busy_940(void)
|
||||
{
|
||||
int i;
|
||||
#if 0
|
||||
printf("940 busy, entering wait loop.. (cnt: %i, wc: %i, ve: ", shared_ctl->loopc, shared_ctl->waitc);
|
||||
for (i = 0; i < 8; i++)
|
||||
printf("%i ", shared_ctl->vstarts[i]);
|
||||
printf(")\n");
|
||||
|
||||
for (i = 0; shared_ctl->busy; i++)
|
||||
{
|
||||
spend_cycles(1024); /* needs tuning */
|
||||
}
|
||||
printf("wait iterations: %i\n", i);
|
||||
#else
|
||||
for (i = 0; shared_ctl->busy && i < 0x10000; i++)
|
||||
spend_cycles(4*1024);
|
||||
if (i < 0x10000) return;
|
||||
|
||||
/* 940 crashed */
|
||||
printf("940 crashed (cnt: %i, wc: %i, ve: ", shared_ctl->loopc, shared_ctl->waitc);
|
||||
for (i = 0; i < 8; i++)
|
||||
printf("%i ", shared_ctl->vstarts[i]);
|
||||
printf(")\n");
|
||||
strcpy(menuErrorMsg, "940 crashed.");
|
||||
engineState = PGS_Menu;
|
||||
crashed_940 = 1;
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
static void add_job_940(int job)
|
||||
{
|
||||
shared_ctl->job = job;
|
||||
shared_ctl->busy = 1;
|
||||
gp2x_memregs[0x3B3E>>1] = 0xffff; // cause an IRQ for 940
|
||||
}
|
||||
|
||||
|
||||
void YM2612PicoStateLoad_940(void)
|
||||
{
|
||||
int i, old_A1 = addr_A1;
|
||||
|
||||
if (shared_ctl->busy) wait_busy_940();
|
||||
|
||||
// feed all the registers and update internal state
|
||||
for(i = 0; i < 0x100; i++) {
|
||||
YM2612Write_940(0, i);
|
||||
YM2612Write_940(1, REGS[i]);
|
||||
}
|
||||
for(i = 0; i < 0x100; i++) {
|
||||
YM2612Write_940(2, i);
|
||||
YM2612Write_940(3, REGS[i|0x100]);
|
||||
}
|
||||
|
||||
addr_A1 = old_A1;
|
||||
|
||||
add_job_940(JOB940_PICOSTATELOAD);
|
||||
}
|
||||
|
||||
|
||||
static void internal_reset(void)
|
||||
{
|
||||
writebuff_ptr = 0;
|
||||
ST_mode = 0;
|
||||
ST_status = 0; /* normal mode */
|
||||
ST_TA = 0;
|
||||
ST_TAC = 0;
|
||||
ST_TB = 0;
|
||||
ST_TBC = 0;
|
||||
dacen = 0;
|
||||
}
|
||||
|
||||
|
||||
extern char **g_argv;
|
||||
|
||||
/* none of the functions in this file should be called before this one */
|
||||
void YM2612Init_940(int baseclock, int rate)
|
||||
{
|
||||
printf("YM2612Init_940()\n");
|
||||
//printf("sizeof(*shared_data): %i (%x)\n", sizeof(*shared_data), sizeof(*shared_data));
|
||||
//printf("sizeof(*shared_ctl): %i (%x)\n", sizeof(*shared_ctl), sizeof(*shared_ctl));
|
||||
|
||||
Reset940(1);
|
||||
Pause940(1);
|
||||
|
||||
gp2x_memregs[0x3B46>>1] = 0xffff; // clear pending DUALCPU interrupts for 940
|
||||
gp2x_memregs[0x3B42>>1] = 0xffff; // enable DUALCPU interrupts for 940
|
||||
|
||||
gp2x_memregl[0x4508>>2] = ~(1<<26); // unmask DUALCPU ints in the undocumented 940's interrupt controller
|
||||
|
||||
if (shared_mem == NULL)
|
||||
{
|
||||
shared_mem = (unsigned char *) mmap(0, 0x210000, PROT_READ|PROT_WRITE, MAP_SHARED, memdev, 0x3000000);
|
||||
if(shared_mem == MAP_FAILED)
|
||||
{
|
||||
printf("mmap(shared_data) failed with %i\n", errno);
|
||||
exit(1);
|
||||
}
|
||||
shared_data = (_940_data_t *) (shared_mem+0x100000);
|
||||
/* this area must not get buffered on either side */
|
||||
shared_ctl = (_940_ctl_t *) (shared_mem+0x200000);
|
||||
crashed_940 = 1;
|
||||
}
|
||||
|
||||
if (crashed_940)
|
||||
{
|
||||
unsigned char ucData[1024];
|
||||
int nRead, i, nLen = 0;
|
||||
char binpath[1024];
|
||||
FILE *fp;
|
||||
|
||||
strncpy(binpath, g_argv[0], 1023);
|
||||
binpath[1023] = 0;
|
||||
for (i = strlen(binpath); i > 0; i--)
|
||||
if (binpath[i] == '/') { binpath[i] = 0; break; }
|
||||
strcat(binpath, "/code940.bin");
|
||||
|
||||
fp = fopen(binpath, "rb");
|
||||
if(!fp)
|
||||
{
|
||||
memset(gp2x_screen, 0, 320*240);
|
||||
gp2x_text_out8(10, 100, "failed to open required file:");
|
||||
gp2x_text_out8(10, 110, "code940.bin");
|
||||
gp2x_video_flip();
|
||||
printf("failed to open %s\n", binpath);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
while(1)
|
||||
{
|
||||
nRead = fread(ucData, 1, 1024, fp);
|
||||
if(nRead <= 0)
|
||||
break;
|
||||
memcpy(shared_mem + nLen, ucData, nRead);
|
||||
nLen += nRead;
|
||||
}
|
||||
fclose(fp);
|
||||
crashed_940 = 0;
|
||||
}
|
||||
|
||||
memset(shared_data, 0, sizeof(*shared_data));
|
||||
memset(shared_ctl, 0, sizeof(*shared_ctl));
|
||||
|
||||
REGS = YM2612GetRegs();
|
||||
|
||||
ym2612_dacen = &dacen;
|
||||
ym2612_dacout = &dacout;
|
||||
|
||||
internal_reset();
|
||||
|
||||
/* now cause 940 to init it's ym2612 stuff */
|
||||
shared_ctl->baseclock = baseclock;
|
||||
shared_ctl->rate = rate;
|
||||
shared_ctl->job = JOB940_YM2612INIT;
|
||||
shared_ctl->busy = 1;
|
||||
|
||||
/* start the 940 */
|
||||
Reset940(0);
|
||||
Pause940(0);
|
||||
|
||||
// YM2612ResetChip_940(); // will be done on JOB940_YM2612INIT
|
||||
}
|
||||
|
||||
|
||||
void YM2612ResetChip_940(void)
|
||||
{
|
||||
printf("YM2612ResetChip_940()\n");
|
||||
if (shared_data == NULL) {
|
||||
printf("YM2612ResetChip_940: reset before init?\n");
|
||||
return;
|
||||
}
|
||||
|
||||
if (shared_ctl->busy) wait_busy_940();
|
||||
|
||||
internal_reset();
|
||||
|
||||
add_job_940(JOB940_YM2612RESETCHIP);
|
||||
}
|
||||
|
||||
|
||||
void YM2612UpdateOne_940(short *buffer, int length, int stereo)
|
||||
{
|
||||
int i, *mix_buffer = shared_data->mix_buffer;
|
||||
|
||||
//printf("YM2612UpdateOne_940()\n");
|
||||
if (shared_ctl->busy) wait_busy_940();
|
||||
|
||||
//printf("940 (cnt: %i, wc: %i, ve: ", shared_ctl->loopc, shared_ctl->waitc);
|
||||
//for (i = 0; i < 8; i++)
|
||||
// printf("%i ", shared_ctl->vstarts[i]);
|
||||
//printf(")\n");
|
||||
|
||||
/* mix data from previous go */
|
||||
if (stereo) {
|
||||
int *mb = mix_buffer;
|
||||
for (i = length; i > 0; i--) {
|
||||
int l, r;
|
||||
l = r = *buffer;
|
||||
l += *mb++, r += *mb++;
|
||||
Limit( l, MAXOUT, MINOUT );
|
||||
Limit( r, MAXOUT, MINOUT );
|
||||
*buffer++ = l; *buffer++ = r;
|
||||
}
|
||||
} else {
|
||||
for (i = 0; i < length; i++) {
|
||||
int l = mix_buffer[i];
|
||||
l += buffer[i];
|
||||
Limit( l, MAXOUT, MINOUT );
|
||||
buffer[i] = l;
|
||||
}
|
||||
}
|
||||
|
||||
//printf("new writes: %i\n", writebuff_ptr);
|
||||
if (shared_ctl->writebuffsel == 1) {
|
||||
shared_ctl->writebuff0[writebuff_ptr] = 0xffff;
|
||||
} else {
|
||||
shared_ctl->writebuff1[writebuff_ptr] = 0xffff;
|
||||
}
|
||||
writebuff_ptr = 0;
|
||||
|
||||
/* give 940 another job */
|
||||
shared_ctl->writebuffsel ^= 1;
|
||||
shared_ctl->length = length;
|
||||
shared_ctl->stereo = stereo;
|
||||
add_job_940(JOB940_YM2612UPDATEONE);
|
||||
//spend_cycles(512);
|
||||
//printf("SRCPND: %08lx, INTMODE: %08lx, INTMASK: %08lx, INTPEND: %08lx\n",
|
||||
// gp2x_memregl[0x4500>>2], gp2x_memregl[0x4504>>2], gp2x_memregl[0x4508>>2], gp2x_memregl[0x4510>>2]);
|
||||
}
|
9
platform/gp2x/940ctl_ym2612.h
Normal file
9
platform/gp2x/940ctl_ym2612.h
Normal file
|
@ -0,0 +1,9 @@
|
|||
void YM2612Init_940(int baseclock, int rate);
|
||||
void YM2612ResetChip_940(void);
|
||||
void YM2612UpdateOne_940(short *buffer, int length, int stereo);
|
||||
|
||||
int YM2612Write_940(unsigned int a, unsigned int v);
|
||||
unsigned char YM2612Read_940(void);
|
||||
|
||||
int YM2612PicoTick_940(int n);
|
||||
void YM2612PicoStateLoad_940(void);
|
174
platform/gp2x/940init.s
Normal file
174
platform/gp2x/940init.s
Normal file
|
@ -0,0 +1,174 @@
|
|||
.global code940
|
||||
|
||||
code940: @ interrupt table:
|
||||
b .b_reset @ reset
|
||||
b .b_undef @ undefined instructions
|
||||
b .b_swi @ software interrupt
|
||||
b .b_pabort @ prefetch abort
|
||||
b .b_dabort @ data abort
|
||||
b .b_reserved @ reserved
|
||||
b .b_irq @ IRQ
|
||||
b .b_fiq @ FIQ
|
||||
|
||||
@ test
|
||||
.b_reset:
|
||||
mov r12, #0
|
||||
b .Begin
|
||||
.b_undef:
|
||||
mov r12, #1
|
||||
b .Begin
|
||||
.b_swi:
|
||||
mov r12, #2
|
||||
b .Begin
|
||||
.b_pabort:
|
||||
mov r12, #3
|
||||
b .Begin
|
||||
.b_dabort:
|
||||
mov r12, #4
|
||||
b .Begin
|
||||
.b_reserved:
|
||||
mov r12, #5
|
||||
b .Begin
|
||||
.b_irq:
|
||||
mov r12, #6
|
||||
mov sp, #0x100000 @ reset stack
|
||||
sub sp, sp, #4
|
||||
mov r1, #0xbd000000 @ assume we live @ 0x3000000 bank
|
||||
orr r2, r1, #0x3B00
|
||||
orr r2, r2, #0x0046
|
||||
mvn r3, #0
|
||||
strh r3, [r2] @ clear any pending interrupts from the DUALCPU unit
|
||||
orr r2, r1, #0x4500
|
||||
str r3, [r2] @ clear all pending interrupts in irq controller's SRCPND register
|
||||
orr r2, r2, #0x0010
|
||||
str r3, [r2] @ clear all pending interrupts in irq controller's INTPND register
|
||||
b .Enter
|
||||
.b_fiq:
|
||||
mov r12, #7
|
||||
b .Begin
|
||||
|
||||
.Begin:
|
||||
mov sp, #0x100000 @ set the stack top (1M)
|
||||
sub sp, sp, #4 @ minus 4
|
||||
|
||||
@ set up memory region 0 -- the whole 4GB address space
|
||||
mov r0, #(0x1f<<1)|1 @ region data
|
||||
mcr p15, 0, r0, c6, c0, 0 @ opcode2 ~ data/instr
|
||||
mcr p15, 0, r0, c6, c0, 1
|
||||
|
||||
@ set up region 1 which is the first 2 megabytes.
|
||||
mov r0, #(0x14<<1)|1 @ region data
|
||||
mcr p15, 0, r0, c6, c1, 0
|
||||
mcr p15, 0, r0, c6, c1, 1
|
||||
|
||||
@ set up region 2: 64k 0x200000-0x210000
|
||||
mov r0, #(0x0f<<1)|1
|
||||
orr r0, r0, #0x200000
|
||||
mcr p15, 0, r0, c6, c2, 0
|
||||
mcr p15, 0, r0, c6, c2, 1
|
||||
|
||||
@ set up region 3: 64k 0xbd000000-0xbd010000 (hw control registers)
|
||||
mov r0, #(0x0f<<1)|1
|
||||
orr r0, r0, #0xbd000000
|
||||
mcr p15, 0, r0, c6, c3, 0
|
||||
mcr p15, 0, r0, c6, c3, 1
|
||||
|
||||
@ set region 1 to be cacheable (so the first 2M will be cacheable)
|
||||
mov r0, #2
|
||||
mcr p15, 0, r0, c2, c0, 0
|
||||
mcr p15, 0, r0, c2, c0, 1
|
||||
|
||||
@ set region 1 to be bufferable too (only data)
|
||||
mcr p15, 0, r0, c3, c0, 0
|
||||
|
||||
@ set protection, allow accsess only to regions 1 and 2
|
||||
mov r0, #(3<<6)|(3<<4)|(3<<2)|(0) @ data: [full, full, full, no access] for regions [3 2 1 0]
|
||||
mcr p15, 0, r0, c5, c0, 0
|
||||
mov r0, #(0<<6)|(0<<4)|(3<<2)|(0) @ instructions: [no access, no, full, no]
|
||||
mcr p15, 0, r0, c5, c0, 1
|
||||
|
||||
mrc p15, 0, r0, c1, c0, 0 @ fetch current control reg
|
||||
orr r0, r0, #1 @ 0x00000001: enable protection unit
|
||||
orr r0, r0, #4 @ 0x00000004: enable D cache
|
||||
orr r0, r0, #0x1000 @ 0x00001000: enable I cache
|
||||
orr r0, r0, #0xC0000000 @ 0xC0000000: async+fastbus
|
||||
mcr p15, 0, r0, c1, c0, 0 @ set control reg
|
||||
|
||||
@ flush (invalidate) the cache (just in case)
|
||||
mov r0, #0
|
||||
mcr p15, 0, r0, c7, c6, 0
|
||||
|
||||
.Enter:
|
||||
mov r0, r12
|
||||
bl Main940
|
||||
|
||||
@ we should never get here
|
||||
.b_deadloop:
|
||||
b .b_deadloop
|
||||
|
||||
|
||||
|
||||
@ so asm utils are also defined here:
|
||||
.global spend_cycles @ c
|
||||
|
||||
spend_cycles:
|
||||
mov r0, r0, lsr #2 @ 4 cycles/iteration
|
||||
sub r0, r0, #2 @ entry/exit/init
|
||||
.sc_loop:
|
||||
subs r0, r0, #1
|
||||
bpl .sc_loop
|
||||
|
||||
bx lr
|
||||
|
||||
|
||||
@ clean-flush function from ARM940T technical reference manual
|
||||
.global cache_clean_flush
|
||||
|
||||
cache_clean_flush:
|
||||
mov r1, #0 @ init line counter
|
||||
ccf_outer_loop:
|
||||
mov r0, #0 @ segment counter
|
||||
ccf_inner_loop:
|
||||
orr r2, r1, r0 @ make segment and line address
|
||||
mcr p15, 0, r2, c7, c14, 2 @ clean and flush that line
|
||||
add r0, r0, #0x10 @ incremet secment counter
|
||||
cmp r0, #0x40 @ complete all 4 segments?
|
||||
bne ccf_inner_loop
|
||||
add r1, r1, #0x04000000 @ increment line counter
|
||||
cmp r1, #0 @ complete all lines?
|
||||
bne ccf_outer_loop
|
||||
bx lr
|
||||
|
||||
|
||||
@ clean-only version
|
||||
.global cache_clean
|
||||
|
||||
cache_clean:
|
||||
mov r1, #0 @ init line counter
|
||||
cf_outer_loop:
|
||||
mov r0, #0 @ segment counter
|
||||
cf_inner_loop:
|
||||
orr r2, r1, r0 @ make segment and line address
|
||||
mcr p15, 0, r2, c7, c10, 2 @ clean that line
|
||||
add r0, r0, #0x10 @ incremet secment counter
|
||||
cmp r0, #0x40 @ complete all 4 segments?
|
||||
bne cf_inner_loop
|
||||
add r1, r1, #0x04000000 @ increment line counter
|
||||
cmp r1, #0 @ complete all lines?
|
||||
bne cf_outer_loop
|
||||
bx lr
|
||||
|
||||
|
||||
.global wait_irq
|
||||
|
||||
wait_irq:
|
||||
mrs r0, cpsr
|
||||
bic r0, r0, #0x80
|
||||
msr cpsr_c, r0 @ enable interrupts
|
||||
|
||||
mov r0, #0
|
||||
mcr p15, 0, r0, c7, c0, 4 @ wait for IRQ
|
||||
@ mcr p15, 0, r0, c15, c8, 2
|
||||
b .b_reserved
|
||||
|
||||
.pool
|
33
platform/gp2x/940shared.h
Normal file
33
platform/gp2x/940shared.h
Normal file
|
@ -0,0 +1,33 @@
|
|||
#include "../../Pico/sound/ym2612.h"
|
||||
|
||||
enum _940_job_t {
|
||||
JOB940_YM2612INIT = 1,
|
||||
JOB940_YM2612RESETCHIP,
|
||||
JOB940_YM2612UPDATEONE,
|
||||
JOB940_PICOSTATELOAD,
|
||||
JOB940_NUMJOBS
|
||||
};
|
||||
|
||||
|
||||
typedef struct
|
||||
{
|
||||
YM2612 ym2612; /* current state of the emulated YM2612 */
|
||||
int mix_buffer[44100/50*2]; /* this is where the YM2612 samples will be mixed to */
|
||||
} _940_data_t;
|
||||
|
||||
|
||||
typedef struct
|
||||
{
|
||||
int job; /* a job for second core */
|
||||
int busy; /* busy status of the 940 core */
|
||||
int length; /* number of samples to mix (882 max) */
|
||||
int stereo; /* mix samples as stereo, doubles sample count automatically */
|
||||
int baseclock; /* ym2612 settings */
|
||||
int rate;
|
||||
int writebuffsel; /* which write buffer to use (from 940 side) */
|
||||
UINT16 writebuff0[2048]; /* 1024 for savestates, 1024 extra */
|
||||
UINT16 writebuff1[2048];
|
||||
int vstarts[8]; /* debug: number of starts from each of 8 vectors */
|
||||
int loopc; /* debug: main loop counter */
|
||||
int waitc; /* debug: wait loop counter */
|
||||
} _940_ctl_t;
|
191
platform/gp2x/Makefile
Normal file
191
platform/gp2x/Makefile
Normal file
|
@ -0,0 +1,191 @@
|
|||
|
||||
# you may or may not need to change this
|
||||
#devkit_path = x:/stuff/dev/devkitgp2x/
|
||||
devkit_path = /usr/local/devkitPro/devkitGP2X/
|
||||
lgcc_path = $(devkit_path)lib/gcc/arm-linux/4.0.3/
|
||||
CROSS = arm-linux-
|
||||
#CROSS = $(devkit_path)bin/arm-linux-
|
||||
|
||||
# settings
|
||||
dprint = 1
|
||||
#mz80 = 1
|
||||
#debug_cyclone = 1
|
||||
asm_memory = 1
|
||||
asm_render = 1
|
||||
asm_ym2612 = 1
|
||||
#profile = 1
|
||||
#use_musashi = 1
|
||||
#up = 1
|
||||
|
||||
DEFINC = -I../.. -I. -D__GP2X__ -D_UNZIP_SUPPORT # -DBENCHMARK
|
||||
COPT_COMMON = -static -s -O3 -ftracer -fstrength-reduce -Wall -funroll-loops -fomit-frame-pointer -fstrict-aliasing -ffast-math
|
||||
ifeq "$(profile)" "1"
|
||||
COPT_COMMON += -fprofile-generate
|
||||
endif
|
||||
ifeq "$(profile)" "2"
|
||||
COPT_COMMON += -fprofile-use
|
||||
endif
|
||||
COPT = $(COPT_COMMON) -mtune=arm920t
|
||||
ASOPT = -mcpu=arm920t -mfloat-abi=soft
|
||||
GCC = $(CROSS)gcc
|
||||
STRIP = $(CROSS)strip
|
||||
AS = $(CROSS)as
|
||||
LD = $(CROSS)ld
|
||||
OBJCOPY = $(CROSS)objcopy
|
||||
|
||||
# frontend
|
||||
OBJS += main.o menu.o gp2x.o usbjoy.o emu.o squidgehack.o asmutils.o cpuctrl.o
|
||||
# 940 core control
|
||||
OBJS += 940ctl_ym2612.o
|
||||
# Pico
|
||||
OBJS += ../../Pico/Area.o ../../Pico/Cart.o ../../Pico/Utils.o ../../Pico/Memory.o ../../Pico/Misc.o \
|
||||
../../Pico/Pico.o ../../Pico/Sek.o ../../Pico/VideoPort.o ../../Pico/Draw2.o ../../Pico/Draw.o
|
||||
# asm stuff
|
||||
ifeq "$(asm_render)" "1"
|
||||
DEFINC += -D_ASM_DRAW_C
|
||||
OBJS += ../../Pico/draw_asm.o ../../Pico/draw2_asm.o
|
||||
endif
|
||||
ifeq "$(asm_memory)" "1"
|
||||
DEFINC += -D_ASM_MEMORY_C
|
||||
OBJS += ../../Pico/memory_asm.o
|
||||
endif
|
||||
ifeq "$(asm_ym2612)" "1"
|
||||
DEFINC += -D_ASM_YM2612_C
|
||||
OBJS += ../../Pico/sound/ym2612_asm.o
|
||||
endif
|
||||
# Pico - sound
|
||||
OBJS += ../../Pico/sound/sound.o ../../Pico/sound/sn76496.o ../../Pico/sound/ym2612.o
|
||||
# zlib
|
||||
OBJS += ../../zlib/gzio.o ../../zlib/inffast.o ../../zlib/inflate.o ../../zlib/inftrees.o ../../zlib/trees.o \
|
||||
../../zlib/deflate.o ../../zlib/crc32.o ../../zlib/adler32.o ../../zlib/zutil.o ../../zlib/compress.o
|
||||
# unzip
|
||||
OBJS += ../../unzip/unzip.o
|
||||
# CPU cores
|
||||
ifeq "$(use_musashi)" "1"
|
||||
DEFINC += -DEMU_M68K
|
||||
OBJS += _build\m68kcpu.o _build\m68kopac.o _build\m68kopdm.o _build\m68kopnz.o _build\m68kops.o
|
||||
else
|
||||
DEFINC += -DEMU_C68K
|
||||
OBJS += ../../cpu/Cyclone/proj/Cyclone.o
|
||||
endif
|
||||
# drz80/mz80
|
||||
ifeq "$(mz80)" "1"
|
||||
DEFINC += -D_USE_MZ80
|
||||
OBJS += ../../cpu/mz80/mz80.o
|
||||
else
|
||||
DEFINC += -D_USE_DRZ80
|
||||
OBJS += ../../cpu/DrZ80/drz80.o
|
||||
endif
|
||||
|
||||
all: PicoDrive.gpe code940.bin
|
||||
|
||||
PicoDrive.gpe : $(OBJS)
|
||||
@echo $@
|
||||
@$(GCC) $(COPT) $(OBJS) $(PRELIBS) -lm -o $@
|
||||
@$(STRIP) $@
|
||||
# @$(GCC) $(COPT) $(OBJS) $(PRELIBS) -lm -o PicoDrive_.gpe
|
||||
# @gpecomp PicoDrive_.gpe $@
|
||||
ifeq "$(up)" "1"
|
||||
@cmd //C copy $@ \\\\10.0.1.2\\gp2x\\mnt\\sd\\games\\PicoDrive\\
|
||||
endif
|
||||
|
||||
up: up940
|
||||
@cmd //C copy PicoDrive.gpe \\\\10.0.1.2\\gp2x\\mnt\\sd\\games\\PicoDrive\\
|
||||
up940:
|
||||
@cmd //C copy code940.bin \\\\10.0.1.2\\gp2x\\mnt\\sd\\games\\PicoDrive\\
|
||||
|
||||
testrefr.gpe : test.o gp2x.o asmutils.o
|
||||
@echo $@
|
||||
@$(GCC) $(COPT) $^ $(PRELIBS) -o $@
|
||||
@$(STRIP) $@
|
||||
|
||||
.c.o:
|
||||
@echo $<
|
||||
@$(GCC) $(COPT) $(DEFINC) -c $< -o $@
|
||||
.s.o:
|
||||
@echo $<
|
||||
@$(GCC) $(COPT) $(DEFINC) -c $< -o $@
|
||||
|
||||
../../Pico/draw_asm.o : ../../Pico/Draw.s
|
||||
@echo $<
|
||||
@$(AS) $(ASOPT) $< -o $@
|
||||
../../Pico/draw2_asm.o : ../../Pico/Draw2.s
|
||||
@echo $<
|
||||
@$(AS) $(ASOPT) $< -o $@
|
||||
../../Pico/memory_asm.o : ../../Pico/Memory.s
|
||||
@echo $<
|
||||
@$(AS) $(ASOPT) $< -o $@
|
||||
../../Pico/sound/ym2612_asm.o : ../../Pico/sound/ym2612.s
|
||||
@echo $<
|
||||
@$(AS) $(ASOPT) $< -o $@
|
||||
|
||||
# build Cyclone
|
||||
../../cpu/Cyclone/proj/Cyclone.s :
|
||||
@echo building Cyclone...
|
||||
@make -C ../../cpu/Cyclone/proj -f Makefile.linux
|
||||
|
||||
|
||||
# stuff for 940 core
|
||||
|
||||
# init, emu_control, emu
|
||||
OBJS940 += 940init.o 940.o 940ym2612.o
|
||||
# the asm code seems to be faster when run on 920, but not on 940 for some reason
|
||||
# OBJS940 += ../../Pico/sound/ym2612_asm.o
|
||||
|
||||
# uClibc library code
|
||||
OBJS940 += uClibc/memset.o uClibc/s_floor.o uClibc/e_pow.o uClibc/e_sqrt.o uClibc/s_fabs.o
|
||||
OBJS940 += uClibc/s_scalbn.o uClibc/s_copysign.o uClibc/k_sin.o uClibc/k_cos.o uClibc/s_sin.o
|
||||
OBJS940 += uClibc/e_rem_pio2.o uClibc/k_rem_pio2.o uClibc/e_log.o uClibc/wrappers.o
|
||||
|
||||
code940.bin : code940.gpe
|
||||
@echo $@
|
||||
@$(OBJCOPY) -O binary $< $@
|
||||
|
||||
code940.gpe : $(OBJS940)
|
||||
@echo $@
|
||||
@$(LD) -static -e code940 -Ttext 0x0 $^ -L$(lgcc_path) -lgcc -o $@
|
||||
|
||||
940ym2612.o : ../../Pico/sound/ym2612.c
|
||||
@echo $@
|
||||
@$(GCC) $(COPT_COMMON) -mtune=arm940t $(DEFINC) -DEXTERNAL_YM2612 -c $< -o $@
|
||||
|
||||
|
||||
# cleanup
|
||||
clean: clean_pd clean_940
|
||||
tidy: tidy_pd tidy_940
|
||||
|
||||
clean_pd: tidy_pd
|
||||
@$(RM) PicoDrive.gpe
|
||||
tidy_pd:
|
||||
@$(RM) $(OBJS)
|
||||
# @make -C ../../cpu/Cyclone/proj -f Makefile.linux clean
|
||||
|
||||
clean_940: tidy_940
|
||||
@$(RM) code940.bin
|
||||
tidy_940:
|
||||
@$(RM) code940.gpe $(OBJS940)
|
||||
|
||||
clean_prof:
|
||||
find ../.. -name '*.gcno' -delete
|
||||
find ../.. -name '*.gcda' -delete
|
||||
|
||||
# test
|
||||
usbjoy.o : usbjoy.c
|
||||
@echo $<
|
||||
@$(GCC) $(COPT) $(DEFINC) -fno-profile-generate -c $< -o $@
|
||||
|
||||
../../Pico/Cart.o : ../../Pico/Cart.c
|
||||
@echo $<
|
||||
@$(GCC) $(COPT) $(DEFINC) -fno-profile-generate -c $< -o $@
|
||||
|
||||
../../zlib/trees.o : ../../zlib/trees.c
|
||||
@echo $<
|
||||
@$(GCC) $(COPT) $(DEFINC) -fno-profile-generate -c $< -o $@
|
||||
|
||||
uClibc/e_pow.o : uClibc/e_pow.c
|
||||
@echo $<
|
||||
@$(GCC) $(COPT) $(DEFINC) -fno-profile-generate -c $< -o $@
|
||||
|
||||
uClibc/e_sqrt.o : uClibc/e_sqrt.c
|
||||
@echo $<
|
||||
@$(GCC) $(COPT) $(DEFINC) -fno-profile-generate -c $< -o $@
|
12
platform/gp2x/asmutils.h
Normal file
12
platform/gp2x/asmutils.h
Normal file
|
@ -0,0 +1,12 @@
|
|||
// (c) Copyright 2006 notaz, All rights reserved.
|
||||
// Free for non-commercial use.
|
||||
|
||||
// For commercial use, separate licencing terms must be obtained.
|
||||
|
||||
void vidConvCpyRGB32 (void *to, void *from, int pixels);
|
||||
void vidConvCpyRGB32sh(void *to, void *from, int pixels);
|
||||
void vidConvCpyRGB32hi(void *to, void *from, int pixels);
|
||||
void vidCpyM2_40col(void *dest, void *src);
|
||||
void vidCpyM2_32col(void *dest, void *src);
|
||||
void vidCpyM2_32col_nobord(void *dest, void *src);
|
||||
void spend_cycles(int c); // utility
|
210
platform/gp2x/asmutils.s
Normal file
210
platform/gp2x/asmutils.s
Normal file
|
@ -0,0 +1,210 @@
|
|||
@ some color conversion and blitting routines
|
||||
|
||||
@ (c) Copyright 2006, notaz
|
||||
@ All Rights Reserved
|
||||
|
||||
|
||||
@ Convert 0000bbb0 ggg0rrr0 0000bbb0 ggg0rrr0
|
||||
@ to 00000000 rrr00000 ggg00000 bbb00000 ...
|
||||
|
||||
@ lr = 0x00e000e0, out: r3=lower_pix, r2=higher_pix; trashes rin
|
||||
@ if sh==2, r8=0x00404040 (sh!=0 destroys flags!)
|
||||
.macro convRGB32_2 rin sh=0
|
||||
and r2, lr, \rin, lsr #4 @ blue
|
||||
and r3, \rin, lr
|
||||
orr r2, r2, r3, lsl #8 @ g0b0g0b0
|
||||
|
||||
mov r3, r2, lsl #16 @ g0b00000
|
||||
and \rin,lr, \rin, ror #12 @ 00r000r0 (reversed)
|
||||
orr r3, r3, \rin, lsr #16 @ g0b000r0
|
||||
.if \sh == 1
|
||||
mov r3, r3, ror #17 @ shadow mode
|
||||
.elseif \sh == 2
|
||||
adds r3, r3, #0x40000000 @ green
|
||||
orrcs r3, r3, #0xe0000000
|
||||
mov r3, r3, ror #8
|
||||
adds r3, r3, #0x40000000
|
||||
orrcs r3, r3, #0xe0000000
|
||||
mov r3, r3, ror #16
|
||||
adds r3, r3, #0x40000000
|
||||
orrcs r3, r3, #0xe0000000
|
||||
mov r3, r3, ror #24
|
||||
.else
|
||||
mov r3, r3, ror #16 @ r3=low
|
||||
.endif
|
||||
|
||||
orr r3, r3, r3, lsr #3
|
||||
str r3, [r0], #4
|
||||
|
||||
mov r2, r2, lsr #16
|
||||
orr r2, r2, \rin, lsl #16
|
||||
.if \sh == 1
|
||||
mov r2, r2, lsr #1
|
||||
.elseif \sh == 2
|
||||
mov r2, r2, ror #8
|
||||
adds r2, r2, #0x40000000 @ blue
|
||||
orrcs r2, r2, #0xe0000000
|
||||
mov r2, r2, ror #8
|
||||
adds r2, r2, #0x40000000
|
||||
orrcs r2, r2, #0xe0000000
|
||||
mov r2, r2, ror #8
|
||||
adds r2, r2, #0x40000000
|
||||
orrcs r2, r2, #0xe0000000
|
||||
mov r2, r2, ror #8
|
||||
.endif
|
||||
|
||||
orr r2, r2, r2, lsr #3
|
||||
str r2, [r0], #4
|
||||
.endm
|
||||
|
||||
|
||||
.global vidConvCpyRGB32 @ void *to, void *from, int pixels
|
||||
|
||||
vidConvCpyRGB32:
|
||||
stmfd sp!, {r4-r7,lr}
|
||||
|
||||
mov r12, r2, lsr #3 @ repeats
|
||||
mov lr, #0x00e00000
|
||||
orr lr, lr, #0x00e0
|
||||
|
||||
.loopRGB32:
|
||||
subs r12, r12, #1
|
||||
|
||||
ldmia r1!, {r4-r7}
|
||||
convRGB32_2 r4
|
||||
convRGB32_2 r5
|
||||
convRGB32_2 r6
|
||||
convRGB32_2 r7
|
||||
|
||||
bgt .loopRGB32
|
||||
|
||||
ldmfd sp!, {r4-r7,lr}
|
||||
bx lr
|
||||
|
||||
|
||||
.global vidConvCpyRGB32sh @ void *to, void *from, int pixels
|
||||
|
||||
vidConvCpyRGB32sh:
|
||||
stmfd sp!, {r4-r7,lr}
|
||||
|
||||
mov r12, r2, lsr #3 @ repeats
|
||||
mov lr, #0x00e00000
|
||||
orr lr, lr, #0x00e0
|
||||
|
||||
.loopRGB32sh:
|
||||
subs r12, r12, #1
|
||||
|
||||
ldmia r1!, {r4-r7}
|
||||
convRGB32_2 r4, 1
|
||||
convRGB32_2 r5, 1
|
||||
convRGB32_2 r6, 1
|
||||
convRGB32_2 r7, 1
|
||||
|
||||
bgt .loopRGB32sh
|
||||
|
||||
ldmfd sp!, {r4-r7,lr}
|
||||
bx lr
|
||||
|
||||
|
||||
.global vidConvCpyRGB32hi @ void *to, void *from, int pixels
|
||||
|
||||
vidConvCpyRGB32hi:
|
||||
stmfd sp!, {r4-r7,lr}
|
||||
|
||||
mov r12, r2, lsr #3 @ repeats
|
||||
mov lr, #0x00e00000
|
||||
orr lr, lr, #0x00e0
|
||||
|
||||
.loopRGB32hi:
|
||||
ldmia r1!, {r4-r7}
|
||||
convRGB32_2 r4, 2
|
||||
convRGB32_2 r5, 2
|
||||
convRGB32_2 r6, 2
|
||||
convRGB32_2 r7, 2
|
||||
|
||||
subs r12, r12, #1
|
||||
bgt .loopRGB32hi
|
||||
|
||||
ldmfd sp!, {r4-r7,lr}
|
||||
bx lr
|
||||
|
||||
|
||||
@ @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
|
||||
|
||||
|
||||
@ mode2 blitter for 40 cols
|
||||
.global vidCpyM2_40col @ void *dest, void *src
|
||||
|
||||
vidCpyM2_40col:
|
||||
stmfd sp!, {r4-r6,lr}
|
||||
|
||||
mov r12, #224 @ lines
|
||||
add r1, r1, #8
|
||||
|
||||
vidCpyM2_40_loop_out:
|
||||
mov r6, #10
|
||||
vidCpyM2_40_loop:
|
||||
subs r6, r6, #1
|
||||
ldmia r1!, {r2-r5}
|
||||
stmia r0!, {r2-r5}
|
||||
ldmia r1!, {r2-r5}
|
||||
stmia r0!, {r2-r5}
|
||||
bne vidCpyM2_40_loop
|
||||
subs r12,r12,#1
|
||||
add r1, r1, #8
|
||||
bne vidCpyM2_40_loop_out
|
||||
|
||||
ldmfd sp!, {r4-r6,lr}
|
||||
bx lr
|
||||
|
||||
|
||||
@ mode2 blitter for 32 cols
|
||||
.global vidCpyM2_32col @ void *dest, void *src
|
||||
|
||||
vidCpyM2_32col:
|
||||
stmfd sp!, {r4-r6,lr}
|
||||
|
||||
mov r12, #224 @ lines
|
||||
add r1, r1, #8
|
||||
add r0, r0, #32
|
||||
|
||||
vidCpyM2_32_loop_out:
|
||||
mov r6, #8
|
||||
vidCpyM2_32_loop:
|
||||
subs r6, r6, #1
|
||||
ldmia r1!, {r2-r5}
|
||||
stmia r0!, {r2-r5}
|
||||
ldmia r1!, {r2-r5}
|
||||
stmia r0!, {r2-r5}
|
||||
bne vidCpyM2_32_loop
|
||||
subs r12,r12,#1
|
||||
add r0, r0, #64
|
||||
add r1, r1, #8+64
|
||||
bne vidCpyM2_32_loop_out
|
||||
|
||||
ldmfd sp!, {r4-r6,lr}
|
||||
bx lr
|
||||
|
||||
|
||||
@ mode2 blitter for 32 cols with no borders
|
||||
.global vidCpyM2_32col_nobord @ void *dest, void *src
|
||||
|
||||
vidCpyM2_32col_nobord:
|
||||
stmfd sp!, {r4-r6,lr}
|
||||
|
||||
mov r12, #224 @ lines
|
||||
add r1, r1, #8
|
||||
b vidCpyM2_32_loop_out
|
||||
|
||||
|
||||
@ test
|
||||
.global spend_cycles @ c
|
||||
|
||||
spend_cycles:
|
||||
mov r0, r0, lsr #2 @ 4 cycles/iteration
|
||||
sub r0, r0, #2 @ entry/exit/init
|
||||
.sc_loop:
|
||||
subs r0, r0, #1
|
||||
bpl .sc_loop
|
||||
|
||||
bx lr
|
138
platform/gp2x/config.txt
Normal file
138
platform/gp2x/config.txt
Normal file
|
@ -0,0 +1,138 @@
|
|||
As PicoDrive is multiplatform emulator, this is GP2X specific part of readme
|
||||
about configuration.
|
||||
|
||||
|
||||
Configuration
|
||||
-------------
|
||||
|
||||
1. "Renderer"
|
||||
8bit fast:
|
||||
This enables alternative heavily optimized tile-based renderer, which renders
|
||||
pixels not line-by-line (this is what accurate renderers do), but in 8x8 tiles,
|
||||
which is much faster. But because of the way it works it can't render any
|
||||
mid-frame image changes (raster effects), so it is useful only with some games.
|
||||
|
||||
Other two are accurate line-based renderers. The 8bit is faster but does not
|
||||
run well with some games like Street Racer.
|
||||
|
||||
2. "Accurate timing"
|
||||
This adds some more emulation precision, but slows the emulation down. Whithout
|
||||
this option some games do not boot (Red Zone for example), others have sound
|
||||
problems.
|
||||
|
||||
3. "Accurate sprites"
|
||||
This option improves emulation of sprite priorities, it also enables emulation
|
||||
of sprite collision bit. If you see one sprite being drawn incorrectly above
|
||||
the other (often seen in Sonic 3D Blast), you can enable this to fix the problem.
|
||||
This only works with the default renderer (see first option).
|
||||
|
||||
4. "Show FPS"
|
||||
Self-explanatory. Format is XX/YY, where XX is the number of rendered frames and
|
||||
YY is the number of emulated frames per second.
|
||||
|
||||
5. "Frameskip"
|
||||
How many frames to skip rendering before displaying another.
|
||||
"Auto" is recommended.
|
||||
|
||||
6. "Enable sound"
|
||||
Does what it says. You must enable at least YM2612 or SN76496 (in advanced options,
|
||||
see below) for this to make sense.
|
||||
|
||||
7. "Sound Quality"
|
||||
Sound rate and stereo mode. If you want 44100Hz sound, it is recommended to enable
|
||||
the second core (next option).
|
||||
|
||||
8. "Use ARM940 core for sound"
|
||||
This option causes PicoDrive to use ARM940T core (GP2X's second CPU) for sound
|
||||
(i.e. to generate YM2612 samples) to improve performance noticeably.
|
||||
|
||||
9. "6 button pad"
|
||||
If you enable this, games will think that 6 button gamepad is connected. If you
|
||||
go and reconfigure your keys, you will be able to bind X,Y,Z and mode actions.
|
||||
|
||||
10. "Genesis Region"
|
||||
This option lets you force the game to think it is running on machine from the
|
||||
specified region.
|
||||
|
||||
11. "Use SRAM savestates"
|
||||
This will automatically read/write SRAM savestates for games which are using them.
|
||||
SRAM is saved whenever you pause your game or exit the emulator.
|
||||
|
||||
12. "GP2X CPU clocks"
|
||||
Here you can change clocks of both GP2X's CPUs. Larger values increase performance.
|
||||
There is no separate option for the second CPU because both CPUs use the same clock
|
||||
source. Setting this option to 200 will cause PicoDrive NOT to change GP2X's clocks
|
||||
at all.
|
||||
|
||||
13. "[advanced options]"
|
||||
Enters advanced options menu (see below).
|
||||
|
||||
14. "Save cfg as default"
|
||||
If you save your config here it will be loaded on next ROM load, but only if there
|
||||
is no game specific config saved (which will be loaded in that case).
|
||||
|
||||
15. "Save cfg for current game only"
|
||||
Whenever you load current ROM again these settings will be loaded (squidgehack and
|
||||
RAM settings will not take effect until emulator is restarted).
|
||||
|
||||
Advanced configuration
|
||||
----------------------
|
||||
|
||||
Enter [advanced options] in config menu to see these options.
|
||||
|
||||
1. "Scale 32 column mode"
|
||||
This enables hardware scaling for lower-res genesis mode (where width is
|
||||
32 8-pixel tiles, instead of 40 in other mode).
|
||||
|
||||
2. "Gamma correction"
|
||||
Alters image gamma through GP2X hardware. Larger values make image to look brighter,
|
||||
lower - darker (default is 1.0).
|
||||
|
||||
3. "Emulate Z80"
|
||||
Enables emulation of Z80 chip, which was mostly used to drive the other sound chips.
|
||||
Some games do complex sync with it, so you must enable it even if you don't use
|
||||
sound to be able to play them.
|
||||
|
||||
4. "Emulate YM2612 (FM)"
|
||||
This enables emulation of six-channel FM sound synthesizer chip, which was used to
|
||||
produce sound effects and music.
|
||||
|
||||
5. "Emulate SN76496 (PSG)"
|
||||
This enables emulation of additional sound chip for additional effects.
|
||||
|
||||
Note: if you change sound settings AFTER loading a ROM, you may need to reset
|
||||
game to get sound. This is because most games initialize sound chips on
|
||||
startup, and this data is lost when sound chips are being enabled/disabled.
|
||||
|
||||
6. "gzip savestates"
|
||||
This will always apply gzip compression on your savestates, allowing you to
|
||||
save some space and load/save time.
|
||||
|
||||
7. "USB joy controls player X"
|
||||
If you are able to use USB joysticks with your GP2X, this options selects which
|
||||
player the joystick controls.
|
||||
|
||||
8. "Don't save config on exit"
|
||||
This will disable config autowrite on exit (which might cause SD card corruption
|
||||
according to DaveC).
|
||||
|
||||
9. "craigix's RAM timings"
|
||||
This overclocks the GP2X RAM chips, but may cause instability. Recommended if you
|
||||
use the second core for sound. Needs emulator restart to take effect.
|
||||
See this thread:
|
||||
http://www.gp32x.com/board/index.php?showtopic=32319
|
||||
|
||||
10. "squidgehack"
|
||||
Well known way to improve the GP2X performance. You must restart the emulator
|
||||
for the change of this option to take effect.
|
||||
|
||||
|
||||
Key configuration
|
||||
-----------------
|
||||
|
||||
When you select "Configure controls" from the menu, you enter a key configuration
|
||||
mode, where you use SELECT to change an action, and then press a key you like to
|
||||
bind to that action. You can press the same key again to unbind. Select "DONE"
|
||||
action and press any key to finish.
|
||||
|
||||
|
156
platform/gp2x/cpuctrl.c
Normal file
156
platform/gp2x/cpuctrl.c
Normal file
|
@ -0,0 +1,156 @@
|
|||
/* cpuctrl for GP2X
|
||||
Copyright (C) 2005 Hermes/PS2Reality
|
||||
the gamma-routine was provided by theoddbot
|
||||
parts (c) Rlyehs Work & (C) 2006 god_at_hell
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
*/
|
||||
|
||||
|
||||
#include <sys/mman.h>
|
||||
#include <math.h>
|
||||
#include "cpuctrl.h"
|
||||
|
||||
|
||||
/* system registers */
|
||||
static struct
|
||||
{
|
||||
unsigned short SYSCLKENREG,SYSCSETREG,FPLLVSETREG,DUALINT920,DUALINT940,DUALCTRL940,MEMTIMEX0,MEMTIMEX1;
|
||||
}
|
||||
system_reg;
|
||||
|
||||
static unsigned short dispclockdiv;
|
||||
|
||||
static volatile unsigned short *MEM_REG;
|
||||
|
||||
#define SYS_CLK_FREQ 7372800
|
||||
|
||||
|
||||
void cpuctrl_init(void)
|
||||
{
|
||||
extern volatile unsigned short *gp2x_memregs; /* from minimal library rlyeh */
|
||||
MEM_REG=&gp2x_memregs[0];
|
||||
system_reg.SYSCSETREG=MEM_REG[0x91c>>1];
|
||||
system_reg.FPLLVSETREG=MEM_REG[0x912>>1];
|
||||
system_reg.SYSCLKENREG=MEM_REG[0x904>>1];
|
||||
system_reg.DUALINT920=MEM_REG[0x3B40>>1];
|
||||
system_reg.DUALINT940=MEM_REG[0x3B42>>1];
|
||||
system_reg.DUALCTRL940=MEM_REG[0x3B48>>1];
|
||||
system_reg.MEMTIMEX0=MEM_REG[0x3802>>1];
|
||||
system_reg.MEMTIMEX1=MEM_REG[0x3804>>1];
|
||||
dispclockdiv=MEM_REG[0x924>>1];
|
||||
}
|
||||
|
||||
|
||||
void cpuctrl_deinit(void)
|
||||
{
|
||||
MEM_REG[0x91c>>1]=system_reg.SYSCSETREG;
|
||||
MEM_REG[0x910>>1]=system_reg.FPLLVSETREG;
|
||||
MEM_REG[0x3B40>>1]=system_reg.DUALINT920;
|
||||
MEM_REG[0x3B42>>1]=system_reg.DUALINT940;
|
||||
MEM_REG[0x3B48>>1]=system_reg.DUALCTRL940;
|
||||
MEM_REG[0x904>>1]=system_reg.SYSCLKENREG;
|
||||
MEM_REG[0x924>>1]=dispclockdiv;
|
||||
MEM_REG[0x3802>>1]=system_reg.MEMTIMEX0;
|
||||
MEM_REG[0x3804>>1]=system_reg.MEMTIMEX1 /*| 0x9000*/;
|
||||
}
|
||||
|
||||
|
||||
void set_display_clock_div(unsigned div)
|
||||
{
|
||||
div=((div & 63) | 64)<<8;
|
||||
MEM_REG[0x924>>1]=(MEM_REG[0x924>>1] & ~(255<<8)) | div;
|
||||
}
|
||||
|
||||
|
||||
void set_FCLK(unsigned MHZ)
|
||||
{
|
||||
unsigned v;
|
||||
unsigned mdiv,pdiv=3,scale=0;
|
||||
MHZ*=1000000;
|
||||
mdiv=(MHZ*pdiv)/SYS_CLK_FREQ;
|
||||
mdiv=((mdiv-8)<<8) & 0xff00;
|
||||
pdiv=((pdiv-2)<<2) & 0xfc;
|
||||
scale&=3;
|
||||
v=mdiv | pdiv | scale;
|
||||
MEM_REG[0x910>>1]=v;
|
||||
}
|
||||
|
||||
|
||||
void set_920_Div(unsigned short div)
|
||||
{
|
||||
unsigned short v;
|
||||
v = MEM_REG[0x91c>>1] & (~0x3);
|
||||
MEM_REG[0x91c>>1] = (div & 0x7) | v;
|
||||
}
|
||||
|
||||
|
||||
void set_DCLK_Div( unsigned short div )
|
||||
{
|
||||
unsigned short v;
|
||||
v = (unsigned short)( MEM_REG[0x91c>>1] & (~(0x7 << 6)) );
|
||||
MEM_REG[0x91c>>1] = ((div & 0x7) << 6) | v;
|
||||
}
|
||||
|
||||
/*
|
||||
void Disable_940(void)
|
||||
{
|
||||
MEM_REG[0x3B42>>1];
|
||||
MEM_REG[0x3B42>>1]=0;
|
||||
MEM_REG[0x3B46>>1]=0xffff;
|
||||
MEM_REG[0x3B48>>1]|= (1 << 7);
|
||||
MEM_REG[0x904>>1]&=0xfffe;
|
||||
}
|
||||
*/
|
||||
|
||||
void set_RAM_Timings(int tRC, int tRAS, int tWR, int tMRD, int tRFC, int tRP, int tRCD)
|
||||
{
|
||||
tRC -= 1; tRAS -= 1; tWR -= 1; tMRD -= 1; tRFC -= 1; tRP -= 1; tRCD -= 1; // ???
|
||||
MEM_REG[0x3802>>1] = ((tMRD & 0xF) << 12) | ((tRFC & 0xF) << 8) | ((tRP & 0xF) << 4) | (tRCD & 0xF);
|
||||
MEM_REG[0x3804>>1] = /*0x9000 |*/ ((tRC & 0xF) << 8) | ((tRAS & 0xF) << 4) | (tWR & 0xF);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
void gp2x_video_wait_vsync(void)
|
||||
{
|
||||
MEM_REG[0x2846>>1]=(MEM_REG[0x2846>>1] | 0x20) & ~2;
|
||||
while(!(MEM_REG[0x2846>>1] & 2));
|
||||
}
|
||||
*/
|
||||
|
||||
void set_gamma(int g100)
|
||||
{
|
||||
float gamma = (float) g100 / 100;
|
||||
int i;
|
||||
//printf ("set gamma = %f\r\n",gamma);
|
||||
gamma = 1/gamma;
|
||||
|
||||
//enable gamma
|
||||
MEM_REG[0x2880>>1]&=~(1<<12);
|
||||
|
||||
MEM_REG[0x295C>>1]=0;
|
||||
for(i=0; i<256; i++)
|
||||
{
|
||||
unsigned char g;
|
||||
unsigned short s;
|
||||
g =(unsigned char)(255.0*pow(i/255.0,gamma));
|
||||
s = (g<<8) | g;
|
||||
MEM_REG[0x295E>>1]= s;
|
||||
MEM_REG[0x295E>>1]= g;
|
||||
}
|
||||
}
|
||||
|
340
platform/gp2x/cpuctrl.gpl.txt
Normal file
340
platform/gp2x/cpuctrl.gpl.txt
Normal file
|
@ -0,0 +1,340 @@
|
|||
GNU GENERAL PUBLIC LICENSE
|
||||
Version 2, June 1991
|
||||
|
||||
Copyright (C) 1989, 1991 Free Software Foundation, Inc.
|
||||
51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
Everyone is permitted to copy and distribute verbatim copies
|
||||
of this license document, but changing it is not allowed.
|
||||
|
||||
Preamble
|
||||
|
||||
The licenses for most software are designed to take away your
|
||||
freedom to share and change it. By contrast, the GNU General Public
|
||||
License is intended to guarantee your freedom to share and change free
|
||||
software--to make sure the software is free for all its users. This
|
||||
General Public License applies to most of the Free Software
|
||||
Foundation's software and to any other program whose authors commit to
|
||||
using it. (Some other Free Software Foundation software is covered by
|
||||
the GNU Library General Public License instead.) You can apply it to
|
||||
your programs, too.
|
||||
|
||||
When we speak of free software, we are referring to freedom, not
|
||||
price. Our General Public Licenses are designed to make sure that you
|
||||
have the freedom to distribute copies of free software (and charge for
|
||||
this service if you wish), that you receive source code or can get it
|
||||
if you want it, that you can change the software or use pieces of it
|
||||
in new free programs; and that you know you can do these things.
|
||||
|
||||
To protect your rights, we need to make restrictions that forbid
|
||||
anyone to deny you these rights or to ask you to surrender the rights.
|
||||
These restrictions translate to certain responsibilities for you if you
|
||||
distribute copies of the software, or if you modify it.
|
||||
|
||||
For example, if you distribute copies of such a program, whether
|
||||
gratis or for a fee, you must give the recipients all the rights that
|
||||
you have. You must make sure that they, too, receive or can get the
|
||||
source code. And you must show them these terms so they know their
|
||||
rights.
|
||||
|
||||
We protect your rights with two steps: (1) copyright the software, and
|
||||
(2) offer you this license which gives you legal permission to copy,
|
||||
distribute and/or modify the software.
|
||||
|
||||
Also, for each author's protection and ours, we want to make certain
|
||||
that everyone understands that there is no warranty for this free
|
||||
software. If the software is modified by someone else and passed on, we
|
||||
want its recipients to know that what they have is not the original, so
|
||||
that any problems introduced by others will not reflect on the original
|
||||
authors' reputations.
|
||||
|
||||
Finally, any free program is threatened constantly by software
|
||||
patents. We wish to avoid the danger that redistributors of a free
|
||||
program will individually obtain patent licenses, in effect making the
|
||||
program proprietary. To prevent this, we have made it clear that any
|
||||
patent must be licensed for everyone's free use or not licensed at all.
|
||||
|
||||
The precise terms and conditions for copying, distribution and
|
||||
modification follow.
|
||||
|
||||
GNU GENERAL PUBLIC LICENSE
|
||||
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
|
||||
|
||||
0. This License applies to any program or other work which contains
|
||||
a notice placed by the copyright holder saying it may be distributed
|
||||
under the terms of this General Public License. The "Program", below,
|
||||
refers to any such program or work, and a "work based on the Program"
|
||||
means either the Program or any derivative work under copyright law:
|
||||
that is to say, a work containing the Program or a portion of it,
|
||||
either verbatim or with modifications and/or translated into another
|
||||
language. (Hereinafter, translation is included without limitation in
|
||||
the term "modification".) Each licensee is addressed as "you".
|
||||
|
||||
Activities other than copying, distribution and modification are not
|
||||
covered by this License; they are outside its scope. The act of
|
||||
running the Program is not restricted, and the output from the Program
|
||||
is covered only if its contents constitute a work based on the
|
||||
Program (independent of having been made by running the Program).
|
||||
Whether that is true depends on what the Program does.
|
||||
|
||||
1. You may copy and distribute verbatim copies of the Program's
|
||||
source code as you receive it, in any medium, provided that you
|
||||
conspicuously and appropriately publish on each copy an appropriate
|
||||
copyright notice and disclaimer of warranty; keep intact all the
|
||||
notices that refer to this License and to the absence of any warranty;
|
||||
and give any other recipients of the Program a copy of this License
|
||||
along with the Program.
|
||||
|
||||
You may charge a fee for the physical act of transferring a copy, and
|
||||
you may at your option offer warranty protection in exchange for a fee.
|
||||
|
||||
2. You may modify your copy or copies of the Program or any portion
|
||||
of it, thus forming a work based on the Program, and copy and
|
||||
distribute such modifications or work under the terms of Section 1
|
||||
above, provided that you also meet all of these conditions:
|
||||
|
||||
a) You must cause the modified files to carry prominent notices
|
||||
stating that you changed the files and the date of any change.
|
||||
|
||||
b) You must cause any work that you distribute or publish, that in
|
||||
whole or in part contains or is derived from the Program or any
|
||||
part thereof, to be licensed as a whole at no charge to all third
|
||||
parties under the terms of this License.
|
||||
|
||||
c) If the modified program normally reads commands interactively
|
||||
when run, you must cause it, when started running for such
|
||||
interactive use in the most ordinary way, to print or display an
|
||||
announcement including an appropriate copyright notice and a
|
||||
notice that there is no warranty (or else, saying that you provide
|
||||
a warranty) and that users may redistribute the program under
|
||||
these conditions, and telling the user how to view a copy of this
|
||||
License. (Exception: if the Program itself is interactive but
|
||||
does not normally print such an announcement, your work based on
|
||||
the Program is not required to print an announcement.)
|
||||
|
||||
These requirements apply to the modified work as a whole. If
|
||||
identifiable sections of that work are not derived from the Program,
|
||||
and can be reasonably considered independent and separate works in
|
||||
themselves, then this License, and its terms, do not apply to those
|
||||
sections when you distribute them as separate works. But when you
|
||||
distribute the same sections as part of a whole which is a work based
|
||||
on the Program, the distribution of the whole must be on the terms of
|
||||
this License, whose permissions for other licensees extend to the
|
||||
entire whole, and thus to each and every part regardless of who wrote it.
|
||||
|
||||
Thus, it is not the intent of this section to claim rights or contest
|
||||
your rights to work written entirely by you; rather, the intent is to
|
||||
exercise the right to control the distribution of derivative or
|
||||
collective works based on the Program.
|
||||
|
||||
In addition, mere aggregation of another work not based on the Program
|
||||
with the Program (or with a work based on the Program) on a volume of
|
||||
a storage or distribution medium does not bring the other work under
|
||||
the scope of this License.
|
||||
|
||||
3. You may copy and distribute the Program (or a work based on it,
|
||||
under Section 2) in object code or executable form under the terms of
|
||||
Sections 1 and 2 above provided that you also do one of the following:
|
||||
|
||||
a) Accompany it with the complete corresponding machine-readable
|
||||
source code, which must be distributed under the terms of Sections
|
||||
1 and 2 above on a medium customarily used for software interchange; or,
|
||||
|
||||
b) Accompany it with a written offer, valid for at least three
|
||||
years, to give any third party, for a charge no more than your
|
||||
cost of physically performing source distribution, a complete
|
||||
machine-readable copy of the corresponding source code, to be
|
||||
distributed under the terms of Sections 1 and 2 above on a medium
|
||||
customarily used for software interchange; or,
|
||||
|
||||
c) Accompany it with the information you received as to the offer
|
||||
to distribute corresponding source code. (This alternative is
|
||||
allowed only for noncommercial distribution and only if you
|
||||
received the program in object code or executable form with such
|
||||
an offer, in accord with Subsection b above.)
|
||||
|
||||
The source code for a work means the preferred form of the work for
|
||||
making modifications to it. For an executable work, complete source
|
||||
code means all the source code for all modules it contains, plus any
|
||||
associated interface definition files, plus the scripts used to
|
||||
control compilation and installation of the executable. However, as a
|
||||
special exception, the source code distributed need not include
|
||||
anything that is normally distributed (in either source or binary
|
||||
form) with the major components (compiler, kernel, and so on) of the
|
||||
operating system on which the executable runs, unless that component
|
||||
itself accompanies the executable.
|
||||
|
||||
If distribution of executable or object code is made by offering
|
||||
access to copy from a designated place, then offering equivalent
|
||||
access to copy the source code from the same place counts as
|
||||
distribution of the source code, even though third parties are not
|
||||
compelled to copy the source along with the object code.
|
||||
|
||||
4. You may not copy, modify, sublicense, or distribute the Program
|
||||
except as expressly provided under this License. Any attempt
|
||||
otherwise to copy, modify, sublicense or distribute the Program is
|
||||
void, and will automatically terminate your rights under this License.
|
||||
However, parties who have received copies, or rights, from you under
|
||||
this License will not have their licenses terminated so long as such
|
||||
parties remain in full compliance.
|
||||
|
||||
5. You are not required to accept this License, since you have not
|
||||
signed it. However, nothing else grants you permission to modify or
|
||||
distribute the Program or its derivative works. These actions are
|
||||
prohibited by law if you do not accept this License. Therefore, by
|
||||
modifying or distributing the Program (or any work based on the
|
||||
Program), you indicate your acceptance of this License to do so, and
|
||||
all its terms and conditions for copying, distributing or modifying
|
||||
the Program or works based on it.
|
||||
|
||||
6. Each time you redistribute the Program (or any work based on the
|
||||
Program), the recipient automatically receives a license from the
|
||||
original licensor to copy, distribute or modify the Program subject to
|
||||
these terms and conditions. You may not impose any further
|
||||
restrictions on the recipients' exercise of the rights granted herein.
|
||||
You are not responsible for enforcing compliance by third parties to
|
||||
this License.
|
||||
|
||||
7. If, as a consequence of a court judgment or allegation of patent
|
||||
infringement or for any other reason (not limited to patent issues),
|
||||
conditions are imposed on you (whether by court order, agreement or
|
||||
otherwise) that contradict the conditions of this License, they do not
|
||||
excuse you from the conditions of this License. If you cannot
|
||||
distribute so as to satisfy simultaneously your obligations under this
|
||||
License and any other pertinent obligations, then as a consequence you
|
||||
may not distribute the Program at all. For example, if a patent
|
||||
license would not permit royalty-free redistribution of the Program by
|
||||
all those who receive copies directly or indirectly through you, then
|
||||
the only way you could satisfy both it and this License would be to
|
||||
refrain entirely from distribution of the Program.
|
||||
|
||||
If any portion of this section is held invalid or unenforceable under
|
||||
any particular circumstance, the balance of the section is intended to
|
||||
apply and the section as a whole is intended to apply in other
|
||||
circumstances.
|
||||
|
||||
It is not the purpose of this section to induce you to infringe any
|
||||
patents or other property right claims or to contest validity of any
|
||||
such claims; this section has the sole purpose of protecting the
|
||||
integrity of the free software distribution system, which is
|
||||
implemented by public license practices. Many people have made
|
||||
generous contributions to the wide range of software distributed
|
||||
through that system in reliance on consistent application of that
|
||||
system; it is up to the author/donor to decide if he or she is willing
|
||||
to distribute software through any other system and a licensee cannot
|
||||
impose that choice.
|
||||
|
||||
This section is intended to make thoroughly clear what is believed to
|
||||
be a consequence of the rest of this License.
|
||||
|
||||
8. If the distribution and/or use of the Program is restricted in
|
||||
certain countries either by patents or by copyrighted interfaces, the
|
||||
original copyright holder who places the Program under this License
|
||||
may add an explicit geographical distribution limitation excluding
|
||||
those countries, so that distribution is permitted only in or among
|
||||
countries not thus excluded. In such case, this License incorporates
|
||||
the limitation as if written in the body of this License.
|
||||
|
||||
9. The Free Software Foundation may publish revised and/or new versions
|
||||
of the General Public License from time to time. Such new versions will
|
||||
be similar in spirit to the present version, but may differ in detail to
|
||||
address new problems or concerns.
|
||||
|
||||
Each version is given a distinguishing version number. If the Program
|
||||
specifies a version number of this License which applies to it and "any
|
||||
later version", you have the option of following the terms and conditions
|
||||
either of that version or of any later version published by the Free
|
||||
Software Foundation. If the Program does not specify a version number of
|
||||
this License, you may choose any version ever published by the Free Software
|
||||
Foundation.
|
||||
|
||||
10. If you wish to incorporate parts of the Program into other free
|
||||
programs whose distribution conditions are different, write to the author
|
||||
to ask for permission. For software which is copyrighted by the Free
|
||||
Software Foundation, write to the Free Software Foundation; we sometimes
|
||||
make exceptions for this. Our decision will be guided by the two goals
|
||||
of preserving the free status of all derivatives of our free software and
|
||||
of promoting the sharing and reuse of software generally.
|
||||
|
||||
NO WARRANTY
|
||||
|
||||
11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
|
||||
FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
|
||||
OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
|
||||
PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
|
||||
OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS
|
||||
TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE
|
||||
PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
|
||||
REPAIR OR CORRECTION.
|
||||
|
||||
12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
|
||||
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
|
||||
REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
|
||||
INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
|
||||
OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
|
||||
TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
|
||||
YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
|
||||
PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
|
||||
POSSIBILITY OF SUCH DAMAGES.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
|
||||
How to Apply These Terms to Your New Programs
|
||||
|
||||
If you develop a new program, and you want it to be of the greatest
|
||||
possible use to the public, the best way to achieve this is to make it
|
||||
free software which everyone can redistribute and change under these terms.
|
||||
|
||||
To do so, attach the following notices to the program. It is safest
|
||||
to attach them to the start of each source file to most effectively
|
||||
convey the exclusion of warranty; and each file should have at least
|
||||
the "copyright" line and a pointer to where the full notice is found.
|
||||
|
||||
<one line to give the program's name and a brief idea of what it does.>
|
||||
Copyright (C) <year> <name of author>
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
|
||||
Also add information on how to contact you by electronic and paper mail.
|
||||
|
||||
If the program is interactive, make it output a short notice like this
|
||||
when it starts in an interactive mode:
|
||||
|
||||
Gnomovision version 69, Copyright (C) year name of author
|
||||
Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
|
||||
This is free software, and you are welcome to redistribute it
|
||||
under certain conditions; type `show c' for details.
|
||||
|
||||
The hypothetical commands `show w' and `show c' should show the appropriate
|
||||
parts of the General Public License. Of course, the commands you use may
|
||||
be called something other than `show w' and `show c'; they could even be
|
||||
mouse-clicks or menu items--whatever suits your program.
|
||||
|
||||
You should also get your employer (if you work as a programmer) or your
|
||||
school, if any, to sign a "copyright disclaimer" for the program, if
|
||||
necessary. Here is a sample; alter the names:
|
||||
|
||||
Yoyodyne, Inc., hereby disclaims all copyright interest in the program
|
||||
`Gnomovision' (which makes passes at compilers) written by James Hacker.
|
||||
|
||||
<signature of Ty Coon>, 1 April 1989
|
||||
Ty Coon, President of Vice
|
||||
|
||||
This General Public License does not permit incorporating your program into
|
||||
proprietary programs. If your program is a subroutine library, you may
|
||||
consider it more useful to permit linking proprietary applications with the
|
||||
library. If this is what you want to do, use the GNU Library General
|
||||
Public License instead of this License.
|
16
platform/gp2x/cpuctrl.h
Normal file
16
platform/gp2x/cpuctrl.h
Normal file
|
@ -0,0 +1,16 @@
|
|||
#ifndef __CPUCTRL_H__
|
||||
#define __CPUCTRL_H__
|
||||
|
||||
extern void cpuctrl_init(void); /* call this at first */
|
||||
extern void save_system_regs(void); /* save some registers */
|
||||
extern void cpuctrl_deinit(void);
|
||||
extern void set_display_clock_div(unsigned div);
|
||||
extern void set_FCLK(unsigned MHZ); /* adjust the clock frequency (in Mhz units) */
|
||||
extern void set_920_Div(unsigned short div); /* 0 to 7 divider (freq=FCLK/(1+div)) */
|
||||
extern void set_DCLK_Div(unsigned short div); /* 0 to 7 divider (freq=FCLK/(1+div)) */
|
||||
//extern void Disable_940(void); /* 940t down */
|
||||
//extern void gp2x_video_wait_vsync(void);
|
||||
extern void set_RAM_Timings(int tRC, int tRAS, int tWR, int tMRD, int tRFC, int tRP, int tRCD);
|
||||
extern void set_gamma(int g100);
|
||||
|
||||
#endif
|
1121
platform/gp2x/emu.c
Normal file
1121
platform/gp2x/emu.c
Normal file
File diff suppressed because it is too large
Load diff
46
platform/gp2x/emu.h
Normal file
46
platform/gp2x/emu.h
Normal file
|
@ -0,0 +1,46 @@
|
|||
// (c) Copyright 2006 notaz, All rights reserved.
|
||||
// Free for non-commercial use.
|
||||
|
||||
// For commercial use, separate licencing terms must be obtained.
|
||||
|
||||
|
||||
|
||||
// engine states
|
||||
enum TPicoGameState {
|
||||
PGS_Paused = 1,
|
||||
PGS_Running,
|
||||
PGS_Quit,
|
||||
PGS_KeyConfig,
|
||||
PGS_ReloadRom,
|
||||
PGS_Menu,
|
||||
};
|
||||
|
||||
typedef struct {
|
||||
char lastRomFile[512];
|
||||
int EmuOpt; // LSb->MSb: use_sram, show_fps, enable_sound, gzip_saves,
|
||||
// squidgehack, save_cfg_on_exit, <unused>, 16_bit_mode
|
||||
// craigix_ram, confirm_save
|
||||
int PicoOpt; // used for config saving only, see Pico.h
|
||||
int PsndRate; // ditto
|
||||
int PicoRegion; // ditto
|
||||
int Frameskip;
|
||||
int CPUclock;
|
||||
int KeyBinds[32];
|
||||
int volume;
|
||||
int gamma;
|
||||
int JoyBinds[4][32];
|
||||
} currentConfig_t;
|
||||
|
||||
extern char romFileName[];
|
||||
extern int engineState;
|
||||
extern currentConfig_t currentConfig;
|
||||
|
||||
|
||||
int emu_ReloadRom(void);
|
||||
void emu_Init(void);
|
||||
void emu_Deinit(void);
|
||||
int emu_SaveLoadGame(int load, int sram);
|
||||
void emu_Loop(void);
|
||||
void emu_ResetGame(void);
|
||||
int emu_ReadConfig(int game);
|
||||
int emu_WriteConfig(int game);
|
311
platform/gp2x/gp2x.c
Normal file
311
platform/gp2x/gp2x.c
Normal file
|
@ -0,0 +1,311 @@
|
|||
/**
|
||||
* All this is mostly based on rlyeh's minimal library.
|
||||
* Copied here to review all his code and understand what's going on.
|
||||
**/
|
||||
|
||||
/*
|
||||
|
||||
GP2X minimal library v0.A by rlyeh, (c) 2005. emulnation.info@rlyeh (swap it!)
|
||||
|
||||
Thanks to Squidge, Robster, snaff, Reesy and NK, for the help & previous work! :-)
|
||||
|
||||
License
|
||||
=======
|
||||
|
||||
Free for non-commercial projects (it would be nice receiving a mail from you).
|
||||
Other cases, ask me first.
|
||||
|
||||
GamePark Holdings is not allowed to use this library and/or use parts from it.
|
||||
|
||||
*/
|
||||
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
#include <sys/mman.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <sys/soundcard.h>
|
||||
#include <fcntl.h>
|
||||
#include <errno.h>
|
||||
|
||||
#include "gp2x.h"
|
||||
#include "usbjoy.h"
|
||||
|
||||
volatile unsigned short *gp2x_memregs;
|
||||
//static
|
||||
volatile unsigned long *gp2x_memregl;
|
||||
static void *gp2x_screens[4];
|
||||
static int screensel = 0;
|
||||
//static
|
||||
int memdev = 0;
|
||||
static int sounddev = 0, mixerdev = 0;
|
||||
|
||||
void *gp2x_screen;
|
||||
|
||||
#define FRAMEBUFF_ADDR0 0x4000000-640*480
|
||||
#define FRAMEBUFF_ADDR1 0x4000000-640*480*2
|
||||
#define FRAMEBUFF_ADDR2 0x4000000-640*480*3
|
||||
#define FRAMEBUFF_ADDR3 0x4000000-640*480*4
|
||||
|
||||
static const int gp2x_screenaddrs[] = { FRAMEBUFF_ADDR0, FRAMEBUFF_ADDR1, FRAMEBUFF_ADDR2, FRAMEBUFF_ADDR3 };
|
||||
|
||||
|
||||
/* video stuff */
|
||||
void gp2x_video_flip(void)
|
||||
{
|
||||
unsigned int address = gp2x_screenaddrs[screensel&3];
|
||||
|
||||
/* test */
|
||||
/* {
|
||||
int i; char *p=gp2x_screen;
|
||||
for (i=0; i < 240; i++) { memset(p+i*320, 0, 32); }
|
||||
}*/
|
||||
|
||||
gp2x_memregs[0x290E>>1]=(unsigned short)(address);
|
||||
gp2x_memregs[0x2910>>1]=(unsigned short)(address >> 16);
|
||||
gp2x_memregs[0x2912>>1]=(unsigned short)(address);
|
||||
gp2x_memregs[0x2914>>1]=(unsigned short)(address >> 16);
|
||||
|
||||
// jump to other buffer:
|
||||
gp2x_screen = gp2x_screens[++screensel&3];
|
||||
}
|
||||
|
||||
|
||||
void gp2x_video_changemode(int bpp)
|
||||
{
|
||||
gp2x_memregs[0x28DA>>1]=(((bpp+1)/8)<<9)|0xAB; /*8/15/16/24bpp...*/
|
||||
gp2x_memregs[0x290C>>1]=320*((bpp+1)/8); /*line width in bytes*/
|
||||
|
||||
gp2x_memset_all_buffers(0, 0, 640*480);
|
||||
gp2x_video_flip();
|
||||
}
|
||||
|
||||
|
||||
void gp2x_video_setpalette(int *pal, int len)
|
||||
{
|
||||
unsigned short *g=(unsigned short *)pal;
|
||||
volatile unsigned short *memreg = &gp2x_memregs[0x295A>>1];
|
||||
gp2x_memregs[0x2958>>1] = 0;
|
||||
|
||||
len *= 2;
|
||||
while(len--) *memreg=*g++;
|
||||
}
|
||||
|
||||
|
||||
// TV Compatible function //
|
||||
void gp2x_video_RGB_setscaling(int W, int H)
|
||||
{
|
||||
float escalaw, escalah;
|
||||
int bpp = (gp2x_memregs[0x28DA>>1]>>9)&0x3;
|
||||
|
||||
escalaw = 1024.0; // RGB Horiz LCD
|
||||
escalah = 320.0; // RGB Vert LCD
|
||||
|
||||
if(gp2x_memregs[0x2800>>1]&0x100) //TV-Out
|
||||
{
|
||||
escalaw=489.0; // RGB Horiz TV (PAL, NTSC)
|
||||
if (gp2x_memregs[0x2818>>1] == 287) //PAL
|
||||
escalah=274.0; // RGB Vert TV PAL
|
||||
else if (gp2x_memregs[0x2818>>1] == 239) //NTSC
|
||||
escalah=331.0; // RGB Vert TV NTSC
|
||||
}
|
||||
|
||||
// scale horizontal
|
||||
gp2x_memregs[0x2906>>1]=(unsigned short)((float)escalaw *(W/320.0));
|
||||
// scale vertical
|
||||
gp2x_memregl[0x2908>>2]=(unsigned long)((float)escalah *bpp *(H/240.0));
|
||||
}
|
||||
|
||||
|
||||
/* LCD updates @ 80Hz? */
|
||||
void gp2x_video_wait_vsync(void)
|
||||
{
|
||||
gp2x_memregs[0x2846>>1] = 0x20|2; //(gp2x_memregs[0x2846>>1] | 0x20) & ~2;
|
||||
while(!(gp2x_memregs[0x2846>>1] & 2));// usleep(1);
|
||||
}
|
||||
|
||||
|
||||
void gp2x_memcpy_all_buffers(void *data, int offset, int len)
|
||||
{
|
||||
memcpy((char *)gp2x_screens[0] + offset, data, len);
|
||||
memcpy((char *)gp2x_screens[1] + offset, data, len);
|
||||
memcpy((char *)gp2x_screens[2] + offset, data, len);
|
||||
memcpy((char *)gp2x_screens[3] + offset, data, len);
|
||||
}
|
||||
|
||||
|
||||
void gp2x_memset_all_buffers(int offset, int byte, int len)
|
||||
{
|
||||
memset((char *)gp2x_screens[0] + offset, byte, len);
|
||||
memset((char *)gp2x_screens[1] + offset, byte, len);
|
||||
memset((char *)gp2x_screens[2] + offset, byte, len);
|
||||
memset((char *)gp2x_screens[3] + offset, byte, len);
|
||||
}
|
||||
|
||||
|
||||
unsigned long gp2x_joystick_read(int allow_usb_joy)
|
||||
{
|
||||
int i;
|
||||
unsigned long value=(gp2x_memregs[0x1198>>1] & 0x00FF);
|
||||
if(value==0xFD) value=0xFA;
|
||||
if(value==0xF7) value=0xEB;
|
||||
if(value==0xDF) value=0xAF;
|
||||
if(value==0x7F) value=0xBE;
|
||||
value = ~((gp2x_memregs[0x1184>>1] & 0xFF00) | value | (gp2x_memregs[0x1186>>1] << 16));
|
||||
|
||||
if (allow_usb_joy && num_of_joys > 0) {
|
||||
// check the usb joy as well..
|
||||
gp2x_usbjoy_update();
|
||||
for (i = 0; i < num_of_joys; i++)
|
||||
value |= gp2x_usbjoy_check(i);
|
||||
}
|
||||
|
||||
return value;
|
||||
}
|
||||
|
||||
static int s_oldrate = 0, s_oldbits = 0, s_oldstereo = 0;
|
||||
|
||||
void gp2x_start_sound(int rate, int bits, int stereo)
|
||||
{
|
||||
int frag = 0, bsize, buffers;
|
||||
|
||||
// if no settings change, we don't need to do anything
|
||||
if (rate == s_oldrate && s_oldbits == bits && s_oldstereo == stereo) return;
|
||||
|
||||
if (sounddev > 0) close(sounddev);
|
||||
sounddev = open("/dev/dsp", O_WRONLY|O_ASYNC);
|
||||
if (sounddev == -1)
|
||||
printf("open(\"/dev/dsp\") failed with %i\n", errno);
|
||||
|
||||
ioctl(sounddev, SNDCTL_DSP_SPEED, &rate);
|
||||
ioctl(sounddev, SNDCTL_DSP_SETFMT, &bits);
|
||||
ioctl(sounddev, SNDCTL_DSP_STEREO, &stereo);
|
||||
// calculate buffer size
|
||||
buffers = 16;
|
||||
bsize = rate / 32;
|
||||
if (rate > 22050) { bsize*=4; buffers*=2; } // 44k mode seems to be very demanding
|
||||
while ((bsize>>=1)) frag++;
|
||||
frag |= buffers<<16; // 16 buffers
|
||||
ioctl(sounddev, SNDCTL_DSP_SETFRAGMENT, &frag);
|
||||
printf("gp2x_set_sound: %i/%ibit/%s, %i buffers of %i bytes\n",
|
||||
rate, bits, stereo?"stereo":"mono", frag>>16, 1<<(frag&0xffff));
|
||||
|
||||
s_oldrate = rate; s_oldbits = bits; s_oldstereo = stereo;
|
||||
usleep(100000);
|
||||
}
|
||||
|
||||
|
||||
void gp2x_sound_write(void *buff, int len)
|
||||
{
|
||||
write(sounddev, buff, len);
|
||||
}
|
||||
|
||||
|
||||
void gp2x_sound_volume(int l, int r)
|
||||
{
|
||||
l=l<0?0:l; l=l>255?255:l; r=r<0?0:r; r=r>255?255:r;
|
||||
l<<=8; l|=r;
|
||||
ioctl(mixerdev, SOUND_MIXER_WRITE_PCM, &l); /*SOUND_MIXER_WRITE_VOLUME*/
|
||||
}
|
||||
|
||||
|
||||
/* 940 */
|
||||
void Pause940(int yes)
|
||||
{
|
||||
if(yes)
|
||||
gp2x_memregs[0x0904>>1] &= 0xFFFE;
|
||||
else
|
||||
gp2x_memregs[0x0904>>1] |= 1;
|
||||
}
|
||||
|
||||
|
||||
void Reset940(int yes)
|
||||
{
|
||||
gp2x_memregs[0x3B48>>1] = ((yes&1) << 7) | (0x03); /* bank=3 */
|
||||
}
|
||||
|
||||
|
||||
|
||||
/* common */
|
||||
void gp2x_init(void)
|
||||
{
|
||||
printf("entering init()\n"); fflush(stdout);
|
||||
|
||||
memdev = open("/dev/mem", O_RDWR);
|
||||
if (memdev == -1)
|
||||
{
|
||||
printf("open(\"/dev/mem\") failed with %i\n", errno);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
gp2x_memregs = mmap(0, 0x10000, PROT_READ|PROT_WRITE, MAP_SHARED, memdev, 0xc0000000);
|
||||
printf("memregs are @ %p\n", gp2x_memregs);
|
||||
if(gp2x_memregs == MAP_FAILED)
|
||||
{
|
||||
printf("mmap(memregs) failed with %i\n", errno);
|
||||
exit(1);
|
||||
}
|
||||
gp2x_memregl = (unsigned long *) gp2x_memregs;
|
||||
|
||||
gp2x_screens[3] = mmap(0, 640*480*4, PROT_WRITE, MAP_SHARED, memdev, FRAMEBUFF_ADDR3);
|
||||
if(gp2x_screens[3] == MAP_FAILED)
|
||||
{
|
||||
printf("mmap(gp2x_screen) failed with %i\n", errno);
|
||||
exit(1);
|
||||
}
|
||||
printf("framebuffers point to %p\n", gp2x_screens[3]);
|
||||
gp2x_screens[2] = (char *) gp2x_screens[3]+640*480;
|
||||
gp2x_screens[1] = (char *) gp2x_screens[2]+640*480;
|
||||
gp2x_screens[0] = (char *) gp2x_screens[1]+640*480;
|
||||
|
||||
gp2x_screen = gp2x_screens[0];
|
||||
screensel = 0;
|
||||
|
||||
// snd
|
||||
mixerdev = open("/dev/mixer", O_RDWR);
|
||||
if (mixerdev == -1)
|
||||
printf("open(\"/dev/mixer\") failed with %i\n", errno);
|
||||
|
||||
/* init usb joys -GnoStiC */
|
||||
gp2x_usbjoy_init();
|
||||
|
||||
printf("exitting init()\n"); fflush(stdout);
|
||||
}
|
||||
|
||||
char *ext_menu = 0, *ext_state = 0;
|
||||
|
||||
void gp2x_deinit(void)
|
||||
{
|
||||
Reset940(1);
|
||||
Pause940(1);
|
||||
|
||||
gp2x_video_changemode(15);
|
||||
munmap(gp2x_screens[0], 640*480*4);
|
||||
munmap((void *)gp2x_memregs, 0x10000);
|
||||
close(memdev);
|
||||
close(mixerdev);
|
||||
if (sounddev > 0) close(sounddev);
|
||||
|
||||
gp2x_usbjoy_deinit();
|
||||
|
||||
printf("all done, running ");
|
||||
|
||||
// Zaq121's alternative frontend support from MAME
|
||||
if(ext_menu && ext_state) {
|
||||
printf("%s -state %s\n", ext_menu, ext_state);
|
||||
execl(ext_menu, ext_menu, "-state", ext_state, NULL);
|
||||
} else if(ext_menu) {
|
||||
printf("%s\n", ext_menu);
|
||||
execl(ext_menu, ext_menu, NULL);
|
||||
} else {
|
||||
printf("gp2xmenu\n");
|
||||
chdir("/usr/gp2x");
|
||||
execl("gp2xmenu", "gp2xmenu", NULL);
|
||||
}
|
||||
}
|
||||
|
||||
|
40
platform/gp2x/gp2x.h
Normal file
40
platform/gp2x/gp2x.h
Normal file
|
@ -0,0 +1,40 @@
|
|||
|
||||
#ifndef __GP2X_H__
|
||||
#define __GP2X_H__
|
||||
|
||||
|
||||
void gp2x_init(void);
|
||||
void gp2x_deinit(void);
|
||||
|
||||
/* video */
|
||||
void gp2x_video_flip(void);
|
||||
void gp2x_video_changemode(int bpp);
|
||||
void gp2x_video_setpalette(int *pal, int len);
|
||||
void gp2x_video_RGB_setscaling(int W, int H);
|
||||
void gp2x_video_wait_vsync(void);
|
||||
void gp2x_memcpy_all_buffers(void *data, int offset, int len);
|
||||
void gp2x_memset_all_buffers(int offset, int byte, int len);
|
||||
|
||||
/* sound */
|
||||
void gp2x_start_sound(int rate, int bits, int stereo);
|
||||
void gp2x_sound_write(void *buff, int len);
|
||||
void gp2x_sound_volume(int l, int r);
|
||||
|
||||
/* joy */
|
||||
unsigned long gp2x_joystick_read(int allow_usb_joy);
|
||||
|
||||
/* 940 core */
|
||||
void Pause940(int yes);
|
||||
void Reset940(int yes);
|
||||
|
||||
|
||||
extern void *gp2x_screen;
|
||||
extern int memdev;
|
||||
|
||||
|
||||
enum { GP2X_UP=0x1, GP2X_LEFT=0x4, GP2X_DOWN=0x10, GP2X_RIGHT=0x40,
|
||||
GP2X_START=1<<8, GP2X_SELECT=1<<9, GP2X_L=1<<10, GP2X_R=1<<11,
|
||||
GP2X_A=1<<12, GP2X_B=1<<13, GP2X_X=1<<14, GP2X_Y=1<<15,
|
||||
GP2X_VOL_UP=1<<23, GP2X_VOL_DOWN=1<<22, GP2X_PUSH=1<<27 };
|
||||
|
||||
#endif
|
143
platform/gp2x/main.c
Normal file
143
platform/gp2x/main.c
Normal file
|
@ -0,0 +1,143 @@
|
|||
// (c) Copyright 2006 notaz, All rights reserved.
|
||||
// Free for non-commercial use.
|
||||
|
||||
// For commercial use, separate licencing terms must be obtained.
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
#include <strings.h>
|
||||
#include <linux/limits.h>
|
||||
|
||||
#include "gp2x.h"
|
||||
#include "menu.h"
|
||||
#include "emu.h"
|
||||
#include "version.h"
|
||||
|
||||
#include "squidgehack.h"
|
||||
#include "cpuctrl.h"
|
||||
|
||||
|
||||
extern char *ext_menu, *ext_state;
|
||||
extern int select_exits;
|
||||
extern char *PicoConfigFile;
|
||||
int mmuhack_status = 0;
|
||||
char **g_argv;
|
||||
|
||||
void parse_cmd_line(int argc, char *argv[])
|
||||
{
|
||||
int x, unrecognized = 0;
|
||||
|
||||
for(x = 1; x < argc; x++)
|
||||
{
|
||||
if(argv[x][0] == '-')
|
||||
{
|
||||
if(strcasecmp(argv[x], "-menu") == 0) {
|
||||
if(x+1 < argc) { ++x; ext_menu = argv[x]; } /* External Frontend: Program Name */
|
||||
}
|
||||
else if(strcasecmp(argv[x], "-state") == 0) {
|
||||
if(x+1 < argc) { ++x; ext_state = argv[x]; } /* External Frontend: Arguments */
|
||||
}
|
||||
else if(strcasecmp(argv[x], "-config") == 0) {
|
||||
if(x+1 < argc) { ++x; PicoConfigFile = argv[x]; }
|
||||
}
|
||||
else if(strcasecmp(argv[x], "-selectexit") == 0) {
|
||||
select_exits = 1;
|
||||
}
|
||||
else {
|
||||
unrecognized = 1;
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
/* External Frontend: ROM Name */
|
||||
FILE *f;
|
||||
strncpy(romFileName, argv[x], PATH_MAX);
|
||||
romFileName[PATH_MAX-1] = 0;
|
||||
f = fopen(romFileName, "rb");
|
||||
if (f) fclose(f);
|
||||
else unrecognized = 1;
|
||||
engineState = PGS_ReloadRom;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (unrecognized) {
|
||||
printf("\n\n\nPicoDrive v" VERSION " (c) notaz, 2006\n");
|
||||
printf("usage: %s [options] [romfile]\n", argv[0]);
|
||||
printf( "options:\n"
|
||||
"-menu <menu_path> launch a custom program on exit instead of default gp2xmenu\n"
|
||||
"-state <param> pass '-state param' to the menu program\n"
|
||||
"-config <file> use specified config file instead of default 'picoconfig.bin'\n"
|
||||
" see currentConfig_t structure in emu.h for the file format\n"
|
||||
"-selectexit pressing SELECT will exit the emu and start 'menu_path'\n");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
g_argv = argv;
|
||||
|
||||
emu_ReadConfig(0);
|
||||
gp2x_init();
|
||||
if (currentConfig.EmuOpt&0x10) {
|
||||
int ret = mmuhack();
|
||||
printf("squidge hack code finished and returned %i\n", ret); fflush(stdout);
|
||||
mmuhack_status = ret;
|
||||
}
|
||||
cpuctrl_init();
|
||||
Reset940(1);
|
||||
Pause940(1);
|
||||
if (currentConfig.EmuOpt&0x100) {
|
||||
printf("setting RAM timings.. "); fflush(stdout);
|
||||
// craigix: --trc 6 --tras 4 --twr 1 --tmrd 1 --trfc 1 --trp 2 --trcd 2
|
||||
set_RAM_Timings(6, 4, 1, 1, 1, 2, 2);
|
||||
printf("done.\n"); fflush(stdout);
|
||||
}
|
||||
emu_Init();
|
||||
|
||||
engineState = PGS_Menu;
|
||||
|
||||
if (argc > 1)
|
||||
parse_cmd_line(argc, argv);
|
||||
|
||||
for (;;)
|
||||
{
|
||||
switch (engineState)
|
||||
{
|
||||
case PGS_Menu:
|
||||
menu_loop();
|
||||
break;
|
||||
|
||||
case PGS_ReloadRom:
|
||||
if (emu_ReloadRom())
|
||||
engineState = PGS_Running;
|
||||
else {
|
||||
printf("PGS_ReloadRom == 0\n");
|
||||
engineState = PGS_Menu;
|
||||
}
|
||||
break;
|
||||
|
||||
case PGS_Running:
|
||||
emu_Loop();
|
||||
break;
|
||||
|
||||
case PGS_Quit:
|
||||
goto endloop;
|
||||
|
||||
default:
|
||||
printf("engine got into unknown state (%i), exitting\n", engineState);
|
||||
goto endloop;
|
||||
}
|
||||
}
|
||||
|
||||
endloop:
|
||||
|
||||
emu_Deinit();
|
||||
cpuctrl_deinit();
|
||||
gp2x_deinit();
|
||||
if(mmuhack_status)
|
||||
mmuunhack();
|
||||
|
||||
return 0;
|
||||
}
|
992
platform/gp2x/menu.c
Normal file
992
platform/gp2x/menu.c
Normal file
|
@ -0,0 +1,992 @@
|
|||
// (c) Copyright 2006 notaz, All rights reserved.
|
||||
// Free for non-commercial use.
|
||||
|
||||
// For commercial use, separate licencing terms must be obtained.
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdarg.h>
|
||||
#include <unistd.h>
|
||||
#include <dirent.h>
|
||||
|
||||
#include "gp2x.h"
|
||||
#include "emu.h"
|
||||
#include "menu.h"
|
||||
#include "usbjoy.h"
|
||||
#include "version.h"
|
||||
|
||||
#include "Pico/PicoInt.h"
|
||||
|
||||
#ifndef _DIRENT_HAVE_D_TYPE
|
||||
#error "need d_type for file browser
|
||||
#endif
|
||||
|
||||
extern char *actionNames[];
|
||||
extern char romFileName[PATH_MAX];
|
||||
extern char *rom_data;
|
||||
extern int mmuhack_status;
|
||||
extern int state_slot;
|
||||
|
||||
static char *gp2xKeyNames[] = {
|
||||
"UP", "???", "LEFT", "???", "DOWN", "???", "RIGHT", "???",
|
||||
"START", "SELECT", "L", "R", "A", "B", "X", "Y",
|
||||
"???", "???", "???", "???", "???", "???", "VOL DOWN", "VOL UP",
|
||||
"???", "???", "???", "PUSH", "???", "???", "???", "???"
|
||||
};
|
||||
|
||||
char menuErrorMsg[40] = {0, };
|
||||
|
||||
|
||||
static unsigned char fontdata8x8[] =
|
||||
{
|
||||
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
|
||||
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
|
||||
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
|
||||
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
|
||||
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
|
||||
0x3C,0x42,0x99,0xBD,0xBD,0x99,0x42,0x3C,0x3C,0x42,0x81,0x81,0x81,0x81,0x42,0x3C,
|
||||
0xFE,0x82,0x8A,0xD2,0xA2,0x82,0xFE,0x00,0xFE,0x82,0x82,0x82,0x82,0x82,0xFE,0x00,
|
||||
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x38,0x64,0x74,0x7C,0x38,0x00,0x00,
|
||||
0x80,0xC0,0xF0,0xFC,0xF0,0xC0,0x80,0x00,0x01,0x03,0x0F,0x3F,0x0F,0x03,0x01,0x00,
|
||||
0x18,0x3C,0x7E,0x18,0x7E,0x3C,0x18,0x00,0xEE,0xEE,0xEE,0xCC,0x00,0xCC,0xCC,0x00,
|
||||
0x00,0x00,0x30,0x68,0x78,0x30,0x00,0x00,0x00,0x38,0x64,0x74,0x7C,0x38,0x00,0x00,
|
||||
0x3C,0x66,0x7A,0x7A,0x7E,0x7E,0x3C,0x00,0x0E,0x3E,0x3A,0x22,0x26,0x6E,0xE4,0x40,
|
||||
0x18,0x3C,0x7E,0x3C,0x3C,0x3C,0x3C,0x00,0x3C,0x3C,0x3C,0x3C,0x7E,0x3C,0x18,0x00,
|
||||
0x08,0x7C,0x7E,0x7E,0x7C,0x08,0x00,0x00,0x10,0x3E,0x7E,0x7E,0x3E,0x10,0x00,0x00,
|
||||
0x58,0x2A,0xDC,0xC8,0xDC,0x2A,0x58,0x00,0x24,0x66,0xFF,0xFF,0x66,0x24,0x00,0x00,
|
||||
0x00,0x10,0x10,0x38,0x38,0x7C,0xFE,0x00,0xFE,0x7C,0x38,0x38,0x10,0x10,0x00,0x00,
|
||||
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x1C,0x1C,0x1C,0x18,0x00,0x18,0x18,0x00,
|
||||
0x6C,0x6C,0x24,0x00,0x00,0x00,0x00,0x00,0x00,0x28,0x7C,0x28,0x7C,0x28,0x00,0x00,
|
||||
0x10,0x38,0x60,0x38,0x0C,0x78,0x10,0x00,0x40,0xA4,0x48,0x10,0x24,0x4A,0x04,0x00,
|
||||
0x18,0x34,0x18,0x3A,0x6C,0x66,0x3A,0x00,0x18,0x18,0x20,0x00,0x00,0x00,0x00,0x00,
|
||||
0x30,0x60,0x60,0x60,0x60,0x60,0x30,0x00,0x0C,0x06,0x06,0x06,0x06,0x06,0x0C,0x00,
|
||||
0x10,0x54,0x38,0x7C,0x38,0x54,0x10,0x00,0x00,0x18,0x18,0x7E,0x18,0x18,0x00,0x00,
|
||||
0x00,0x00,0x00,0x00,0x18,0x18,0x30,0x00,0x00,0x00,0x00,0x00,0x3E,0x00,0x00,0x00,
|
||||
0x00,0x00,0x00,0x00,0x18,0x18,0x00,0x00,0x00,0x04,0x08,0x10,0x20,0x40,0x00,0x00,
|
||||
0x38,0x4C,0xC6,0xC6,0xC6,0x64,0x38,0x00,0x18,0x38,0x18,0x18,0x18,0x18,0x7E,0x00,
|
||||
0x7C,0xC6,0x0E,0x3C,0x78,0xE0,0xFE,0x00,0x7E,0x0C,0x18,0x3C,0x06,0xC6,0x7C,0x00,
|
||||
0x1C,0x3C,0x6C,0xCC,0xFE,0x0C,0x0C,0x00,0xFC,0xC0,0xFC,0x06,0x06,0xC6,0x7C,0x00,
|
||||
0x3C,0x60,0xC0,0xFC,0xC6,0xC6,0x7C,0x00,0xFE,0xC6,0x0C,0x18,0x30,0x30,0x30,0x00,
|
||||
0x78,0xC4,0xE4,0x78,0x86,0x86,0x7C,0x00,0x7C,0xC6,0xC6,0x7E,0x06,0x0C,0x78,0x00,
|
||||
0x00,0x00,0x18,0x00,0x00,0x18,0x00,0x00,0x00,0x00,0x18,0x00,0x00,0x18,0x18,0x30,
|
||||
0x1C,0x38,0x70,0xE0,0x70,0x38,0x1C,0x00,0x00,0x7C,0x00,0x00,0x7C,0x00,0x00,0x00,
|
||||
0x70,0x38,0x1C,0x0E,0x1C,0x38,0x70,0x00,0x7C,0xC6,0xC6,0x1C,0x18,0x00,0x18,0x00,
|
||||
0x3C,0x42,0x99,0xA1,0xA5,0x99,0x42,0x3C,0x38,0x6C,0xC6,0xC6,0xFE,0xC6,0xC6,0x00,
|
||||
0xFC,0xC6,0xC6,0xFC,0xC6,0xC6,0xFC,0x00,0x3C,0x66,0xC0,0xC0,0xC0,0x66,0x3C,0x00,
|
||||
0xF8,0xCC,0xC6,0xC6,0xC6,0xCC,0xF8,0x00,0xFE,0xC0,0xC0,0xFC,0xC0,0xC0,0xFE,0x00,
|
||||
0xFE,0xC0,0xC0,0xFC,0xC0,0xC0,0xC0,0x00,0x3E,0x60,0xC0,0xCE,0xC6,0x66,0x3E,0x00,
|
||||
0xC6,0xC6,0xC6,0xFE,0xC6,0xC6,0xC6,0x00,0x7E,0x18,0x18,0x18,0x18,0x18,0x7E,0x00,
|
||||
0x06,0x06,0x06,0x06,0xC6,0xC6,0x7C,0x00,0xC6,0xCC,0xD8,0xF0,0xF8,0xDC,0xCE,0x00,
|
||||
0x60,0x60,0x60,0x60,0x60,0x60,0x7E,0x00,0xC6,0xEE,0xFE,0xFE,0xD6,0xC6,0xC6,0x00,
|
||||
0xC6,0xE6,0xF6,0xFE,0xDE,0xCE,0xC6,0x00,0x7C,0xC6,0xC6,0xC6,0xC6,0xC6,0x7C,0x00,
|
||||
0xFC,0xC6,0xC6,0xC6,0xFC,0xC0,0xC0,0x00,0x7C,0xC6,0xC6,0xC6,0xDE,0xCC,0x7A,0x00,
|
||||
0xFC,0xC6,0xC6,0xCE,0xF8,0xDC,0xCE,0x00,0x78,0xCC,0xC0,0x7C,0x06,0xC6,0x7C,0x00,
|
||||
0x7E,0x18,0x18,0x18,0x18,0x18,0x18,0x00,0xC6,0xC6,0xC6,0xC6,0xC6,0xC6,0x7C,0x00,
|
||||
0xC6,0xC6,0xC6,0xEE,0x7C,0x38,0x10,0x00,0xC6,0xC6,0xD6,0xFE,0xFE,0xEE,0xC6,0x00,
|
||||
0xC6,0xEE,0x3C,0x38,0x7C,0xEE,0xC6,0x00,0x66,0x66,0x66,0x3C,0x18,0x18,0x18,0x00,
|
||||
0xFE,0x0E,0x1C,0x38,0x70,0xE0,0xFE,0x00,0x3C,0x30,0x30,0x30,0x30,0x30,0x3C,0x00,
|
||||
0x60,0x60,0x30,0x18,0x0C,0x06,0x06,0x00,0x3C,0x0C,0x0C,0x0C,0x0C,0x0C,0x3C,0x00,
|
||||
0x18,0x3C,0x66,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xFF,
|
||||
0x30,0x30,0x18,0x00,0x00,0x00,0x00,0x00,0x00,0x3C,0x06,0x3E,0x66,0x66,0x3C,0x00,
|
||||
0x60,0x7C,0x66,0x66,0x66,0x66,0x7C,0x00,0x00,0x3C,0x66,0x60,0x60,0x66,0x3C,0x00,
|
||||
0x06,0x3E,0x66,0x66,0x66,0x66,0x3E,0x00,0x00,0x3C,0x66,0x66,0x7E,0x60,0x3C,0x00,
|
||||
0x1C,0x30,0x78,0x30,0x30,0x30,0x30,0x00,0x00,0x3E,0x66,0x66,0x66,0x3E,0x06,0x3C,
|
||||
0x60,0x7C,0x76,0x66,0x66,0x66,0x66,0x00,0x18,0x00,0x38,0x18,0x18,0x18,0x18,0x00,
|
||||
0x0C,0x00,0x1C,0x0C,0x0C,0x0C,0x0C,0x38,0x60,0x60,0x66,0x6C,0x78,0x6C,0x66,0x00,
|
||||
0x38,0x18,0x18,0x18,0x18,0x18,0x18,0x00,0x00,0xEC,0xFE,0xFE,0xFE,0xD6,0xC6,0x00,
|
||||
0x00,0x7C,0x76,0x66,0x66,0x66,0x66,0x00,0x00,0x3C,0x66,0x66,0x66,0x66,0x3C,0x00,
|
||||
0x00,0x7C,0x66,0x66,0x66,0x7C,0x60,0x60,0x00,0x3E,0x66,0x66,0x66,0x3E,0x06,0x06,
|
||||
0x00,0x7E,0x70,0x60,0x60,0x60,0x60,0x00,0x00,0x3C,0x60,0x3C,0x06,0x66,0x3C,0x00,
|
||||
0x30,0x78,0x30,0x30,0x30,0x30,0x1C,0x00,0x00,0x66,0x66,0x66,0x66,0x6E,0x3E,0x00,
|
||||
0x00,0x66,0x66,0x66,0x66,0x3C,0x18,0x00,0x00,0xC6,0xD6,0xFE,0xFE,0x7C,0x6C,0x00,
|
||||
0x00,0x66,0x3C,0x18,0x3C,0x66,0x66,0x00,0x00,0x66,0x66,0x66,0x66,0x3E,0x06,0x3C,
|
||||
0x00,0x7E,0x0C,0x18,0x30,0x60,0x7E,0x00,0x0E,0x18,0x0C,0x38,0x0C,0x18,0x0E,0x00,
|
||||
0x18,0x18,0x18,0x00,0x18,0x18,0x18,0x00,0x70,0x18,0x30,0x1C,0x30,0x18,0x70,0x00,
|
||||
0x00,0x00,0x76,0xDC,0x00,0x00,0x00,0x00,0x10,0x28,0x10,0x54,0xAA,0x44,0x00,0x00,
|
||||
};
|
||||
|
||||
static void gp2x_text(unsigned char *screen, int x, int y, char *text, int color)
|
||||
{
|
||||
int i,l;
|
||||
|
||||
screen = screen + x + y*320;
|
||||
|
||||
for (i = 0; i < strlen(text); i++)
|
||||
{
|
||||
for (l=0;l<8;l++)
|
||||
{
|
||||
if(fontdata8x8[((text[i])*8)+l]&0x80) screen[l*320+0]=color;
|
||||
if(fontdata8x8[((text[i])*8)+l]&0x40) screen[l*320+1]=color;
|
||||
if(fontdata8x8[((text[i])*8)+l]&0x20) screen[l*320+2]=color;
|
||||
if(fontdata8x8[((text[i])*8)+l]&0x10) screen[l*320+3]=color;
|
||||
if(fontdata8x8[((text[i])*8)+l]&0x08) screen[l*320+4]=color;
|
||||
if(fontdata8x8[((text[i])*8)+l]&0x04) screen[l*320+5]=color;
|
||||
if(fontdata8x8[((text[i])*8)+l]&0x02) screen[l*320+6]=color;
|
||||
if(fontdata8x8[((text[i])*8)+l]&0x01) screen[l*320+7]=color;
|
||||
}
|
||||
screen += 8;
|
||||
}
|
||||
}
|
||||
|
||||
// draws white text to current bbp15 screen
|
||||
void gp2x_text_out15(int x, int y, char *text)
|
||||
{
|
||||
int i,l;
|
||||
unsigned short *screen = gp2x_screen;
|
||||
|
||||
screen = screen + x + y*320;
|
||||
|
||||
for (i = 0; i < strlen(text); i++)
|
||||
{
|
||||
for (l=0;l<8;l++)
|
||||
{
|
||||
if(fontdata8x8[((text[i])*8)+l]&0x80) screen[l*320+0]=0xffff;
|
||||
if(fontdata8x8[((text[i])*8)+l]&0x40) screen[l*320+1]=0xffff;
|
||||
if(fontdata8x8[((text[i])*8)+l]&0x20) screen[l*320+2]=0xffff;
|
||||
if(fontdata8x8[((text[i])*8)+l]&0x10) screen[l*320+3]=0xffff;
|
||||
if(fontdata8x8[((text[i])*8)+l]&0x08) screen[l*320+4]=0xffff;
|
||||
if(fontdata8x8[((text[i])*8)+l]&0x04) screen[l*320+5]=0xffff;
|
||||
if(fontdata8x8[((text[i])*8)+l]&0x02) screen[l*320+6]=0xffff;
|
||||
if(fontdata8x8[((text[i])*8)+l]&0x01) screen[l*320+7]=0xffff;
|
||||
}
|
||||
screen += 8;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void gp2x_text_out8(int x, int y, char *texto, ...)
|
||||
{
|
||||
va_list args;
|
||||
char buffer[512];
|
||||
|
||||
va_start(args,texto);
|
||||
vsprintf(buffer,texto,args);
|
||||
va_end(args);
|
||||
|
||||
gp2x_text(gp2x_screen,x,y,buffer,1);
|
||||
}
|
||||
|
||||
|
||||
void gp2x_text_out8_2(int x, int y, char *texto, int color)
|
||||
{
|
||||
gp2x_text(gp2x_screen, x, y, texto, color);
|
||||
}
|
||||
|
||||
void gp2x_text_out8_lim(int x, int y, char *texto, int max)
|
||||
{
|
||||
char buffer[320/8+1];
|
||||
|
||||
strncpy(buffer, texto, 320/8);
|
||||
if (max > 320/8) max = 320/8;
|
||||
if (max < 0) max = 0;
|
||||
buffer[max] = 0;
|
||||
|
||||
gp2x_text(gp2x_screen,x,y,buffer,1);
|
||||
}
|
||||
|
||||
|
||||
static unsigned long inp_prev = 0;
|
||||
static int inp_prevjoy = 0;
|
||||
|
||||
static unsigned long wait_for_input(unsigned long interesting)
|
||||
{
|
||||
unsigned long ret;
|
||||
static int repeats = 0, wait = 300*1000;
|
||||
int release = 0, i;
|
||||
|
||||
if (repeats == 5 || repeats == 15 || repeats == 30) wait /= 2;
|
||||
|
||||
for (i = 0; i < 6 && inp_prev == gp2x_joystick_read(1); i++) {
|
||||
if(i == 0) repeats++;
|
||||
usleep(wait/6);
|
||||
}
|
||||
|
||||
while ( !((ret = gp2x_joystick_read(1)) & interesting) ) {
|
||||
usleep(50000);
|
||||
release = 1;
|
||||
}
|
||||
|
||||
if (release || ret != inp_prev) {
|
||||
repeats = 0;
|
||||
wait = 300*1000;
|
||||
}
|
||||
inp_prev = ret;
|
||||
inp_prevjoy = 0;
|
||||
|
||||
// we don't need diagonals in menus
|
||||
if ((ret&GP2X_UP) && (ret&GP2X_LEFT)) ret &= ~GP2X_LEFT;
|
||||
if ((ret&GP2X_UP) && (ret&GP2X_RIGHT)) ret &= ~GP2X_RIGHT;
|
||||
if ((ret&GP2X_DOWN) && (ret&GP2X_LEFT)) ret &= ~GP2X_LEFT;
|
||||
if ((ret&GP2X_DOWN) && (ret&GP2X_RIGHT)) ret &= ~GP2X_RIGHT;
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static unsigned long input2_read(unsigned long interesting, int *joy)
|
||||
{
|
||||
unsigned long ret;
|
||||
int i;
|
||||
|
||||
do
|
||||
{
|
||||
*joy = 0;
|
||||
if ((ret = gp2x_joystick_read(0) & interesting)) break;
|
||||
gp2x_usbjoy_update();
|
||||
for (i = 0; i < num_of_joys; i++) {
|
||||
ret = gp2x_usbjoy_check2(i);
|
||||
if (ret) { *joy = i + 1; break; }
|
||||
}
|
||||
if (ret) break;
|
||||
}
|
||||
while(0);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
// similar to wait_for_input(), but returns joy num
|
||||
static unsigned long wait_for_input_usbjoy(unsigned long interesting, int *joy)
|
||||
{
|
||||
unsigned long ret;
|
||||
const int wait = 300*1000;
|
||||
int i;
|
||||
|
||||
if (inp_prevjoy == 0) inp_prev &= interesting;
|
||||
for (i = 0; i < 6; i++) {
|
||||
ret = input2_read(interesting, joy);
|
||||
if (*joy != inp_prevjoy || ret != inp_prev) break;
|
||||
usleep(wait/6);
|
||||
}
|
||||
|
||||
while ( !(ret = input2_read(interesting, joy)) ) {
|
||||
usleep(50000);
|
||||
}
|
||||
|
||||
inp_prev = ret;
|
||||
inp_prevjoy = *joy;
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
|
||||
// -------------- ROM selector --------------
|
||||
|
||||
static void draw_dirlist(char *curdir, struct dirent **namelist, int n, int sel)
|
||||
{
|
||||
int start, i, pos;
|
||||
|
||||
start = 12 - sel;
|
||||
n--; // exclude current dir (".")
|
||||
|
||||
memset(gp2x_screen, 0, 320*240);
|
||||
|
||||
if(start - 2 >= 0)
|
||||
gp2x_text_out8_lim(14, (start - 2)*10, curdir, 38);
|
||||
for (i = 0; i < n; i++) {
|
||||
pos = start + i;
|
||||
if (pos < 0) continue;
|
||||
if (pos > 23) break;
|
||||
if (namelist[i+1]->d_type == DT_DIR) {
|
||||
gp2x_text_out8_lim(14, pos*10, "/", 1);
|
||||
gp2x_text_out8_lim(14+8, pos*10, namelist[i+1]->d_name, 37);
|
||||
} else {
|
||||
gp2x_text_out8_lim(14, pos*10, namelist[i+1]->d_name, 38);
|
||||
}
|
||||
}
|
||||
gp2x_text_out8(5, 120, ">");
|
||||
gp2x_video_flip();
|
||||
}
|
||||
|
||||
static int scandir_cmp(const void *p1, const void *p2)
|
||||
{
|
||||
struct dirent **d1 = (struct dirent **)p1, **d2 = (struct dirent **)p2;
|
||||
if ((*d1)->d_type == (*d2)->d_type) return alphasort(d1, d2);
|
||||
if ((*d1)->d_type == DT_DIR) return -1; // put before
|
||||
if ((*d2)->d_type == DT_DIR) return 1;
|
||||
return alphasort(d1, d2);
|
||||
}
|
||||
|
||||
|
||||
static char *romsel_loop(char *curr_path)
|
||||
{
|
||||
struct dirent **namelist;
|
||||
DIR *dir;
|
||||
int n, sel = 0;
|
||||
unsigned long inp = 0;
|
||||
char *ret = NULL, *fname = NULL;
|
||||
|
||||
// is this a dir or a full path?
|
||||
if ((dir = opendir(curr_path))) {
|
||||
closedir(dir);
|
||||
} else {
|
||||
char *p;
|
||||
for (p = curr_path + strlen(curr_path) - 1; p > curr_path && *p != '/'; p--);
|
||||
*p = 0;
|
||||
fname = p+1;
|
||||
}
|
||||
|
||||
n = scandir(curr_path, &namelist, 0, scandir_cmp);
|
||||
if (n < 0) {
|
||||
// try root
|
||||
n = scandir(curr_path, &namelist, 0, scandir_cmp);
|
||||
if (n < 0) {
|
||||
// oops, we failed
|
||||
printf("dir: "); printf(curr_path); printf("\n");
|
||||
perror("scandir");
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
// try to find sel
|
||||
if (fname != NULL) {
|
||||
int i;
|
||||
for (i = 1; i < n; i++) {
|
||||
if (strcmp(namelist[i]->d_name, fname) == 0) {
|
||||
sel = i - 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (;;)
|
||||
{
|
||||
draw_dirlist(curr_path, namelist, n, sel);
|
||||
inp = wait_for_input(GP2X_UP|GP2X_DOWN|GP2X_LEFT|GP2X_RIGHT|GP2X_B|GP2X_X);
|
||||
if(inp & GP2X_UP ) { sel--; if (sel < 0) sel = n-2; }
|
||||
if(inp & GP2X_DOWN) { sel++; if (sel > n-2) sel = 0; }
|
||||
if(inp & GP2X_LEFT) { sel-=10; if (sel < 0) sel = 0; }
|
||||
if(inp & GP2X_RIGHT) { sel+=10; if (sel > n-2) sel = n-2; }
|
||||
if(inp & GP2X_B) { // enter dir/select
|
||||
again:
|
||||
if (namelist[sel+1]->d_type == DT_REG) {
|
||||
strcpy(romFileName, curr_path);
|
||||
strcat(romFileName, "/");
|
||||
strcat(romFileName, namelist[sel+1]->d_name);
|
||||
ret = romFileName;
|
||||
break;
|
||||
} else if (namelist[sel+1]->d_type == DT_DIR) {
|
||||
int newlen = strlen(curr_path) + strlen(namelist[sel+1]->d_name) + 2;
|
||||
char *p, *newdir = malloc(newlen);
|
||||
if (strcmp(namelist[sel+1]->d_name, "..") == 0) {
|
||||
char *start = curr_path;
|
||||
p = start + strlen(start) - 1;
|
||||
while (*p == '/' && p > start) p--;
|
||||
while (*p != '/' && p > start) p--;
|
||||
if (p <= start) strcpy(newdir, "/");
|
||||
else { strncpy(newdir, start, p-start); newdir[p-start] = 0; }
|
||||
} else {
|
||||
strcpy(newdir, curr_path);
|
||||
p = newdir + strlen(newdir) - 1;
|
||||
while (*p == '/' && p >= newdir) *p-- = 0;
|
||||
strcat(newdir, "/");
|
||||
strcat(newdir, namelist[sel+1]->d_name);
|
||||
}
|
||||
ret = romsel_loop(newdir);
|
||||
free(newdir);
|
||||
break;
|
||||
} else {
|
||||
// unknown file type, happens on NTFS mounts. Try to guess.
|
||||
FILE *tstf; int tmp;
|
||||
strcpy(romFileName, curr_path);
|
||||
strcat(romFileName, "/");
|
||||
strcat(romFileName, namelist[sel+1]->d_name);
|
||||
tstf = fopen(romFileName, "rb");
|
||||
if (tstf != NULL)
|
||||
{
|
||||
if (fread(&tmp, 1, 1, tstf) > 0 || ferror(tstf) == 0)
|
||||
namelist[sel+1]->d_type = DT_REG;
|
||||
else namelist[sel+1]->d_type = DT_DIR;
|
||||
fclose(tstf);
|
||||
goto again;
|
||||
}
|
||||
}
|
||||
}
|
||||
if(inp & GP2X_X) break; // cancel
|
||||
}
|
||||
|
||||
if (n > 0) {
|
||||
while(n--) free(namelist[n]);
|
||||
free(namelist);
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
// -------------- key config --------------
|
||||
|
||||
static char *usb_joy_key_name(int joy, int num)
|
||||
{
|
||||
static char name[16];
|
||||
switch (num)
|
||||
{
|
||||
case 0: sprintf(name, "Joy%i UP", joy); break;
|
||||
case 1: sprintf(name, "Joy%i DOWN", joy); break;
|
||||
case 2: sprintf(name, "Joy%i LEFT", joy); break;
|
||||
case 3: sprintf(name, "Joy%i RIGHT", joy); break;
|
||||
default:sprintf(name, "Joy%i b%i", joy, num-3); break;
|
||||
}
|
||||
return name;
|
||||
}
|
||||
|
||||
static void draw_key_config(int curr_act, int is_p2)
|
||||
{
|
||||
char strkeys[32*5];
|
||||
int joy, i;
|
||||
|
||||
strkeys[0] = 0;
|
||||
for (i = 0; i < 32; i++)
|
||||
{
|
||||
if (currentConfig.KeyBinds[i] & (1 << curr_act))
|
||||
{
|
||||
if (curr_act < 16 && (currentConfig.KeyBinds[i] & (1 << 16)) != (is_p2 << 16)) continue;
|
||||
if (strkeys[0]) { strcat(strkeys, " + "); strcat(strkeys, gp2xKeyNames[i]); break; }
|
||||
else strcpy(strkeys, gp2xKeyNames[i]);
|
||||
}
|
||||
}
|
||||
for (joy = 0; joy < num_of_joys; joy++)
|
||||
{
|
||||
for (i = 0; i < 32; i++)
|
||||
{
|
||||
if (currentConfig.JoyBinds[joy][i] & (1 << curr_act))
|
||||
{
|
||||
if (curr_act < 16 && (currentConfig.JoyBinds[joy][i] & (1 << 16)) != (is_p2 << 16)) continue;
|
||||
if (strkeys[0]) {
|
||||
strcat(strkeys, ", "); strcat(strkeys, usb_joy_key_name(joy + 1, i));
|
||||
break;
|
||||
}
|
||||
else strcpy(strkeys, usb_joy_key_name(joy + 1, i));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
memset(gp2x_screen, 0, 320*240);
|
||||
gp2x_text_out8(60, 40, "Action: %s", actionNames[curr_act]);
|
||||
gp2x_text_out8(60, 60, "Keys: %s", strkeys);
|
||||
|
||||
gp2x_text_out8(30, 180, "Use SELECT to change action");
|
||||
gp2x_text_out8(30, 190, "Press a key to bind/unbind");
|
||||
gp2x_text_out8(30, 200, "Select \"Done\" action and");
|
||||
gp2x_text_out8(30, 210, " press any key to finish");
|
||||
gp2x_video_flip();
|
||||
}
|
||||
|
||||
static void key_config_loop(int is_p2)
|
||||
{
|
||||
int curr_act = 0, joy = 0, i;
|
||||
unsigned long inp = 0;
|
||||
|
||||
for (;;)
|
||||
{
|
||||
draw_key_config(curr_act, is_p2);
|
||||
inp = wait_for_input_usbjoy(CONFIGURABLE_KEYS, &joy);
|
||||
// printf("got %08lX from joy %i\n", inp, joy);
|
||||
if (joy == 0) {
|
||||
if (inp & GP2X_SELECT) {
|
||||
curr_act++;
|
||||
while (!actionNames[curr_act] && curr_act < 32) curr_act++;
|
||||
if (curr_act > 31) curr_act = 0;
|
||||
}
|
||||
inp &= CONFIGURABLE_KEYS;
|
||||
inp &= ~GP2X_SELECT;
|
||||
}
|
||||
if (curr_act == 31 && inp) break;
|
||||
if (joy == 0) {
|
||||
for (i = 0; i < 32; i++)
|
||||
if (inp & (1 << i)) {
|
||||
currentConfig.KeyBinds[i] ^= (1 << curr_act);
|
||||
if (is_p2) currentConfig.KeyBinds[i] |= (1 << 16); // player 2 flag
|
||||
else currentConfig.KeyBinds[i] &= ~(1 << 16);
|
||||
}
|
||||
} else {
|
||||
for (i = 0; i < 32; i++)
|
||||
if (inp & (1 << i)) {
|
||||
currentConfig.JoyBinds[joy-1][i] ^= (1 << curr_act);
|
||||
if (is_p2) currentConfig.JoyBinds[joy-1][i] |= (1 << 16);
|
||||
else currentConfig.JoyBinds[joy-1][i] &= ~(1 << 16);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void draw_kc_sel(int menu_sel)
|
||||
{
|
||||
int tl_x = 25+40, tl_y = 60, y, i;
|
||||
char joyname[36];
|
||||
|
||||
y = tl_y;
|
||||
memset(gp2x_screen, 0, 320*240);
|
||||
gp2x_text_out8(tl_x, y, "Player 1");
|
||||
gp2x_text_out8(tl_x, (y+=10), "Player 2");
|
||||
gp2x_text_out8(tl_x, (y+=10), "Done");
|
||||
|
||||
// draw cursor
|
||||
gp2x_text_out8(tl_x - 16, tl_y + menu_sel*10, ">");
|
||||
|
||||
tl_x = 25;
|
||||
gp2x_text_out8(tl_x, (y=110), "USB joys detected:");
|
||||
if (num_of_joys > 0) {
|
||||
for (i = 0; i < num_of_joys; i++) {
|
||||
strncpy(joyname, joy_name(joys[i]), 33); joyname[33] = 0;
|
||||
gp2x_text_out8(tl_x, (y+=10), "%i: %s", i+1, joyname);
|
||||
}
|
||||
} else {
|
||||
gp2x_text_out8(tl_x, (y+=10), "none");
|
||||
}
|
||||
|
||||
|
||||
gp2x_video_flip();
|
||||
}
|
||||
|
||||
static void kc_sel_loop(void)
|
||||
{
|
||||
int menu_sel = 2, menu_sel_max = 2;
|
||||
unsigned long inp = 0;
|
||||
|
||||
for(;;)
|
||||
{
|
||||
draw_kc_sel(menu_sel);
|
||||
inp = wait_for_input(GP2X_UP|GP2X_DOWN|GP2X_B|GP2X_X);
|
||||
if(inp & GP2X_UP ) { menu_sel--; if (menu_sel < 0) menu_sel = menu_sel_max; }
|
||||
if(inp & GP2X_DOWN) { menu_sel++; if (menu_sel > menu_sel_max) menu_sel = 0; }
|
||||
if(inp & GP2X_B) {
|
||||
switch (menu_sel) {
|
||||
case 0: key_config_loop(0); return;
|
||||
case 1: key_config_loop(1); return;
|
||||
default: return;
|
||||
}
|
||||
}
|
||||
if(inp & GP2X_X) return;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
// --------- advanced options ----------
|
||||
|
||||
// order must match that of currentConfig_t
|
||||
struct {
|
||||
int EmuOpt;
|
||||
int PicoOpt;
|
||||
int PsndRate;
|
||||
int PicoRegion;
|
||||
int Frameskip;
|
||||
int CPUclock;
|
||||
} tmp_opts;
|
||||
int tmp_gamma;
|
||||
|
||||
static void draw_amenu_options(int menu_sel)
|
||||
{
|
||||
int tl_x = 25, tl_y = 60, y;
|
||||
char *mms = mmuhack_status ? "active) " : "inactive)";
|
||||
|
||||
y = tl_y;
|
||||
memset(gp2x_screen, 0, 320*240);
|
||||
gp2x_text_out8(tl_x, y, "Scale 32 column mode %s", (tmp_opts.PicoOpt&0x100)?"ON":"OFF"); // 0
|
||||
gp2x_text_out8(tl_x, (y+=10), "Gamma correction %i.%02i", tmp_gamma / 100, tmp_gamma%100); // 1
|
||||
gp2x_text_out8(tl_x, (y+=10), "Emulate Z80 %s", (tmp_opts.PicoOpt&0x004)?"ON":"OFF"); // 2
|
||||
gp2x_text_out8(tl_x, (y+=10), "Emulate YM2612 (FM) %s", (tmp_opts.PicoOpt&0x001)?"ON":"OFF"); // 3
|
||||
gp2x_text_out8(tl_x, (y+=10), "Emulate SN76496 (PSG) %s", (tmp_opts.PicoOpt&0x002)?"ON":"OFF"); // 4
|
||||
gp2x_text_out8(tl_x, (y+=10), "gzip savestates %s", (tmp_opts.EmuOpt &0x008)?"ON":"OFF"); // 5
|
||||
gp2x_text_out8(tl_x, (y+=10), "Don't save config on exit %s", (tmp_opts.EmuOpt &0x020)?"ON":"OFF"); // 6
|
||||
gp2x_text_out8(tl_x, (y+=10), "needs restart:");
|
||||
gp2x_text_out8(tl_x, (y+=10), "craigix's RAM timings %s", (tmp_opts.EmuOpt &0x100)?"ON":"OFF"); // 8
|
||||
gp2x_text_out8(tl_x, (y+=10), "squidgehack (now %s %s", mms, (tmp_opts.EmuOpt &0x010)?"ON":"OFF"); // 9
|
||||
gp2x_text_out8(tl_x, (y+=10), "Done");
|
||||
|
||||
// draw cursor
|
||||
gp2x_text_out8(tl_x - 16, tl_y + menu_sel*10, ">");
|
||||
|
||||
gp2x_video_flip();
|
||||
}
|
||||
|
||||
static void amenu_loop_options(void)
|
||||
{
|
||||
int menu_sel = 0, menu_sel_max = 11;
|
||||
unsigned long inp = 0;
|
||||
|
||||
for(;;)
|
||||
{
|
||||
draw_amenu_options(menu_sel);
|
||||
inp = wait_for_input(GP2X_UP|GP2X_DOWN|GP2X_LEFT|GP2X_RIGHT|GP2X_B|GP2X_X|GP2X_A);
|
||||
if(inp & GP2X_UP ) { menu_sel--; if (menu_sel < 0) menu_sel = menu_sel_max; }
|
||||
if(inp & GP2X_DOWN) { menu_sel++; if (menu_sel > menu_sel_max) menu_sel = 0; }
|
||||
if((inp& GP2X_B)||(inp&GP2X_LEFT)||(inp&GP2X_RIGHT)) { // toggleable options
|
||||
switch (menu_sel) {
|
||||
case 0: tmp_opts.PicoOpt^=0x100; break;
|
||||
case 2: tmp_opts.PicoOpt^=0x004; break;
|
||||
case 3: tmp_opts.PicoOpt^=0x001; break;
|
||||
case 4: tmp_opts.PicoOpt^=0x002; break;
|
||||
case 5: tmp_opts.EmuOpt ^=0x008; break;
|
||||
case 6: tmp_opts.EmuOpt ^=0x020; break;
|
||||
case 8: tmp_opts.EmuOpt ^=0x100; break;
|
||||
case 9: tmp_opts.EmuOpt ^=0x010; break;
|
||||
case 10: return;
|
||||
}
|
||||
}
|
||||
if(inp & (GP2X_X|GP2X_A)) return;
|
||||
if(inp & (GP2X_LEFT|GP2X_RIGHT)) { // multi choise
|
||||
switch (menu_sel) {
|
||||
case 1:
|
||||
while ((inp = gp2x_joystick_read(1)) & (GP2X_LEFT|GP2X_RIGHT)) {
|
||||
tmp_gamma += (inp & GP2X_LEFT) ? -1 : 1;
|
||||
if (tmp_gamma < 1) tmp_gamma = 1;
|
||||
if (tmp_gamma > 300) tmp_gamma = 300;
|
||||
draw_amenu_options(menu_sel);
|
||||
usleep(18*1000);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// -------------- options --------------
|
||||
|
||||
static char *region_name(unsigned int code)
|
||||
{
|
||||
char *names[] = { "Auto", "Japan NTSC", "Japan PAL", "USA", "Europe" };
|
||||
int i = 0;
|
||||
code <<= 1;
|
||||
while((code >>=1)) i++;
|
||||
if (i > 4) return "unknown";
|
||||
return names[i];
|
||||
}
|
||||
|
||||
static void draw_menu_options(int menu_sel)
|
||||
{
|
||||
int tl_x = 25, tl_y = 40, y;
|
||||
char monostereo[8], strframeskip[8], *strrend;
|
||||
|
||||
strcpy(monostereo, (tmp_opts.PicoOpt&0x08)?"stereo":"mono");
|
||||
if (tmp_opts.Frameskip < 0)
|
||||
strcpy(strframeskip, "Auto");
|
||||
else sprintf(strframeskip, "%i", tmp_opts.Frameskip);
|
||||
if (tmp_opts.PicoOpt&0x10) {
|
||||
strrend = " 8bit fast";
|
||||
} else if (tmp_opts.EmuOpt&0x80) {
|
||||
strrend = "16bit accurate";
|
||||
} else {
|
||||
strrend = " 8bit accurate";
|
||||
}
|
||||
|
||||
y = tl_y;
|
||||
memset(gp2x_screen, 0, 320*240);
|
||||
gp2x_text_out8(tl_x, y, "Renderer: %s", strrend); // 0
|
||||
gp2x_text_out8(tl_x, (y+=10), "Accurate timing (slower) %s", (tmp_opts.PicoOpt&0x040)?"ON":"OFF"); // 1
|
||||
gp2x_text_out8(tl_x, (y+=10), "Accurate sprites (slower) %s", (tmp_opts.PicoOpt&0x080)?"ON":"OFF"); // 2
|
||||
gp2x_text_out8(tl_x, (y+=10), "Show FPS %s", (tmp_opts.EmuOpt &0x002)?"ON":"OFF"); // 3
|
||||
gp2x_text_out8(tl_x, (y+=10), "Frameskip %s", strframeskip);
|
||||
gp2x_text_out8(tl_x, (y+=10), "Enable sound %s", (tmp_opts.EmuOpt &0x004)?"ON":"OFF"); // 5
|
||||
gp2x_text_out8(tl_x, (y+=10), "Sound Quality: %5iHz %s", tmp_opts.PsndRate, monostereo);
|
||||
gp2x_text_out8(tl_x, (y+=10), "Use ARM940 core for sound %s", (tmp_opts.PicoOpt&0x200)?"ON":"OFF"); // 7
|
||||
gp2x_text_out8(tl_x, (y+=10), "6 button pad %s", (tmp_opts.PicoOpt&0x020)?"ON":"OFF"); // 8
|
||||
gp2x_text_out8(tl_x, (y+=10), "Genesis Region: %s", region_name(tmp_opts.PicoRegion));
|
||||
gp2x_text_out8(tl_x, (y+=10), "Use SRAM savestates %s", (tmp_opts.EmuOpt &0x001)?"ON":"OFF"); // 10
|
||||
gp2x_text_out8(tl_x, (y+=10), "Confirm save overwrites %s", (tmp_opts.EmuOpt &0x200)?"ON":"OFF"); // 11
|
||||
gp2x_text_out8(tl_x, (y+=10), "Save slot %i", state_slot); // 12
|
||||
gp2x_text_out8(tl_x, (y+=10), "GP2X CPU clocks %iMhz", tmp_opts.CPUclock);
|
||||
gp2x_text_out8(tl_x, (y+=10), "[advanced options]");
|
||||
gp2x_text_out8(tl_x, (y+=10), "Save cfg as default");
|
||||
if (rom_data)
|
||||
gp2x_text_out8(tl_x, (y+=10), "Save cfg for current game only");
|
||||
|
||||
// draw cursor
|
||||
gp2x_text_out8(tl_x - 16, tl_y + menu_sel*10, ">");
|
||||
|
||||
gp2x_video_flip();
|
||||
}
|
||||
|
||||
static int sndrate_prevnext(int rate, int dir)
|
||||
{
|
||||
int i, rates[] = { 8000, 11025, 16000, 22050, 44100 };
|
||||
|
||||
for (i = 0; i < 5; i++)
|
||||
if (rates[i] == rate) break;
|
||||
|
||||
i += dir ? 1 : -1;
|
||||
if (i > 4) return dir ? 44100 : 22050;
|
||||
if (i < 0) return dir ? 11025 : 8000;
|
||||
return rates[i];
|
||||
}
|
||||
|
||||
static void menu_options_save(void)
|
||||
{
|
||||
memcpy(¤tConfig.EmuOpt, &tmp_opts.EmuOpt, sizeof(tmp_opts));
|
||||
currentConfig.gamma = tmp_gamma;
|
||||
PicoOpt = currentConfig.PicoOpt;
|
||||
PsndRate = currentConfig.PsndRate;
|
||||
PicoRegionOverride = currentConfig.PicoRegion;
|
||||
if (PicoOpt & 0x20) {
|
||||
actionNames[ 8] = "Z"; actionNames[ 9] = "Y";
|
||||
actionNames[10] = "X"; actionNames[11] = "MODE";
|
||||
} else {
|
||||
actionNames[8] = actionNames[9] = actionNames[10] = actionNames[11] = 0;
|
||||
}
|
||||
}
|
||||
|
||||
static void menu_loop_options(void)
|
||||
{
|
||||
int menu_sel = 0, menu_sel_max = 15;
|
||||
unsigned long inp = 0;
|
||||
|
||||
if (rom_data) menu_sel_max++;
|
||||
memcpy(&tmp_opts.EmuOpt, ¤tConfig.EmuOpt, sizeof(tmp_opts));
|
||||
tmp_gamma = currentConfig.gamma;
|
||||
tmp_opts.PicoOpt = PicoOpt;
|
||||
tmp_opts.PsndRate = PsndRate;
|
||||
tmp_opts.PicoRegion = PicoRegionOverride;
|
||||
|
||||
for(;;)
|
||||
{
|
||||
draw_menu_options(menu_sel);
|
||||
inp = wait_for_input(GP2X_UP|GP2X_DOWN|GP2X_LEFT|GP2X_RIGHT|GP2X_B|GP2X_X|GP2X_A);
|
||||
if(inp & GP2X_UP ) { menu_sel--; if (menu_sel < 0) menu_sel = menu_sel_max; }
|
||||
if(inp & GP2X_DOWN) { menu_sel++; if (menu_sel > menu_sel_max) menu_sel = 0; }
|
||||
if((inp& GP2X_B)||(inp&GP2X_LEFT)||(inp&GP2X_RIGHT)) { // toggleable options
|
||||
switch (menu_sel) {
|
||||
case 1: tmp_opts.PicoOpt^=0x040; break;
|
||||
case 2: tmp_opts.PicoOpt^=0x080; break;
|
||||
case 3: tmp_opts.EmuOpt ^=0x002; break;
|
||||
case 5: tmp_opts.EmuOpt ^=0x004; break;
|
||||
case 7: tmp_opts.PicoOpt^=0x200; break;
|
||||
case 8: tmp_opts.PicoOpt^=0x020; break;
|
||||
case 10: tmp_opts.EmuOpt ^=0x001; break;
|
||||
case 11: tmp_opts.EmuOpt ^=0x200; break;
|
||||
case 14: amenu_loop_options(); break;
|
||||
case 15: // done (save)
|
||||
menu_options_save();
|
||||
emu_WriteConfig(0);
|
||||
return;
|
||||
case 16: // done (save for current game)
|
||||
menu_options_save();
|
||||
emu_WriteConfig(1);
|
||||
return;
|
||||
}
|
||||
}
|
||||
if(inp & GP2X_X) return; // done (no save)
|
||||
if(inp & GP2X_A) {
|
||||
menu_options_save();
|
||||
return; // done (save)
|
||||
}
|
||||
if(inp & (GP2X_LEFT|GP2X_RIGHT)) { // multi choise
|
||||
switch (menu_sel) {
|
||||
case 0:
|
||||
if (inp & GP2X_LEFT) {
|
||||
if ( tmp_opts.PicoOpt&0x10) tmp_opts.PicoOpt&= ~0x10;
|
||||
else if (!(tmp_opts.EmuOpt &0x80))tmp_opts.EmuOpt |= 0x80;
|
||||
else if ( tmp_opts.EmuOpt &0x80) break;
|
||||
} else {
|
||||
if ( tmp_opts.PicoOpt&0x10) break;
|
||||
else if (!(tmp_opts.EmuOpt &0x80))tmp_opts.PicoOpt|= 0x10;
|
||||
else if ( tmp_opts.EmuOpt &0x80) tmp_opts.EmuOpt &= ~0x80;
|
||||
}
|
||||
break;
|
||||
case 4:
|
||||
tmp_opts.Frameskip += (inp & GP2X_LEFT) ? -1 : 1;
|
||||
if (tmp_opts.Frameskip < 0) tmp_opts.Frameskip = -1;
|
||||
if (tmp_opts.Frameskip > 32) tmp_opts.Frameskip = 32;
|
||||
break;
|
||||
case 6:
|
||||
if ((inp & GP2X_RIGHT) && tmp_opts.PsndRate == 44100 && !(tmp_opts.PicoOpt&0x08)) {
|
||||
tmp_opts.PsndRate = 8000; tmp_opts.PicoOpt|= 0x08;
|
||||
} else if ((inp & GP2X_LEFT) && tmp_opts.PsndRate == 8000 && (tmp_opts.PicoOpt&0x08)) {
|
||||
tmp_opts.PsndRate = 44100; tmp_opts.PicoOpt&=~0x08;
|
||||
} else tmp_opts.PsndRate = sndrate_prevnext(tmp_opts.PsndRate, inp & GP2X_RIGHT);
|
||||
break;
|
||||
case 9:
|
||||
if (inp & GP2X_RIGHT) {
|
||||
if (tmp_opts.PicoRegion) tmp_opts.PicoRegion<<=1; else tmp_opts.PicoRegion=1;
|
||||
if (tmp_opts.PicoRegion > 8) tmp_opts.PicoRegion = 8;
|
||||
} else tmp_opts.PicoRegion>>=1;
|
||||
break;
|
||||
case 12:
|
||||
if (inp & GP2X_RIGHT) {
|
||||
state_slot++; if (state_slot > 9) state_slot = 0;
|
||||
} else {state_slot--; if (state_slot < 0) state_slot = 9;
|
||||
}
|
||||
break;
|
||||
case 13:
|
||||
while ((inp = gp2x_joystick_read(1)) & (GP2X_LEFT|GP2X_RIGHT)) {
|
||||
tmp_opts.CPUclock += (inp & GP2X_LEFT) ? -1 : 1;
|
||||
if (tmp_opts.CPUclock < 1) tmp_opts.CPUclock = 1;
|
||||
draw_menu_options(menu_sel);
|
||||
usleep(50*1000);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// -------------- credits --------------
|
||||
|
||||
static void draw_menu_credits(void)
|
||||
{
|
||||
int tl_x = 15, tl_y = 70, y;
|
||||
memset(gp2x_screen, 0, 320*240);
|
||||
|
||||
gp2x_text_out8(tl_x, 20, "PicoDrive v" VERSION " (c) notaz, 2006");
|
||||
y = tl_y;
|
||||
gp2x_text_out8(tl_x, y, "Credits:");
|
||||
gp2x_text_out8(tl_x, (y+=10), "Dave: Cyclone 68000 core,");
|
||||
gp2x_text_out8(tl_x, (y+=10), " base code of PicoDrive");
|
||||
gp2x_text_out8(tl_x, (y+=10), "Reesy & FluBBa: DrZ80 core");
|
||||
gp2x_text_out8(tl_x, (y+=10), "MAME devs: YM2612 and SN76496 cores");
|
||||
gp2x_text_out8(tl_x, (y+=10), "Charles MacDonald: Genesis hw docs");
|
||||
gp2x_text_out8(tl_x, (y+=10), "Stephane Dallongeville:");
|
||||
gp2x_text_out8(tl_x, (y+=10), " opensource Gens");
|
||||
gp2x_text_out8(tl_x, (y+=10), "Haze: Genesis hw info");
|
||||
gp2x_text_out8(tl_x, (y+=10), "rlyeh and others: minimal SDK");
|
||||
gp2x_text_out8(tl_x, (y+=10), "Squidge: squidgehack");
|
||||
gp2x_text_out8(tl_x, (y+=10), "Dzz: ARM940 sample");
|
||||
gp2x_text_out8(tl_x, (y+=10), "GnoStiC / Puck2099: USB joystick");
|
||||
gp2x_text_out8(tl_x, (y+=10), "craigix: GP2X hardware");
|
||||
|
||||
gp2x_video_flip();
|
||||
}
|
||||
|
||||
|
||||
// -------------- root menu --------------
|
||||
|
||||
static void draw_menu_root(int menu_sel)
|
||||
{
|
||||
int tl_x = 70, tl_y = 70, y;
|
||||
memset(gp2x_screen, 0, 320*240);
|
||||
|
||||
gp2x_text_out8(tl_x, 20, "PicoDrive v" VERSION);
|
||||
|
||||
y = tl_y;
|
||||
if (rom_data) {
|
||||
gp2x_text_out8(tl_x, y, "Resume game");
|
||||
gp2x_text_out8(tl_x, (y+=10), "Save State");
|
||||
gp2x_text_out8(tl_x, (y+=10), "Load State");
|
||||
gp2x_text_out8(tl_x, (y+=10), "Reset game");
|
||||
} else {
|
||||
y += 30;
|
||||
}
|
||||
gp2x_text_out8(tl_x, (y+=10), "Load new ROM");
|
||||
gp2x_text_out8(tl_x, (y+=10), "Change options");
|
||||
gp2x_text_out8(tl_x, (y+=10), "Configure controls");
|
||||
gp2x_text_out8(tl_x, (y+=10), "Credits");
|
||||
gp2x_text_out8(tl_x, (y+=10), "Exit");
|
||||
|
||||
// draw cursor
|
||||
gp2x_text_out8(tl_x - 16, tl_y + menu_sel*10, ">");
|
||||
// error
|
||||
if (menuErrorMsg[0]) gp2x_text_out8(5, 226, menuErrorMsg);
|
||||
gp2x_video_flip();
|
||||
}
|
||||
|
||||
|
||||
static void menu_loop_root(void)
|
||||
{
|
||||
int menu_sel = 4, menu_sel_max = 8, menu_sel_min = 4;
|
||||
unsigned long inp = 0;
|
||||
char curr_path[PATH_MAX], *selfname;
|
||||
FILE *tstf;
|
||||
|
||||
if ( (tstf = fopen(currentConfig.lastRomFile, "rb")) )
|
||||
{
|
||||
fclose(tstf);
|
||||
strcpy(curr_path, currentConfig.lastRomFile);
|
||||
}
|
||||
else
|
||||
{
|
||||
getcwd(curr_path, PATH_MAX);
|
||||
}
|
||||
|
||||
if (rom_data) menu_sel = menu_sel_min = 0;
|
||||
|
||||
for(;;)
|
||||
{
|
||||
draw_menu_root(menu_sel);
|
||||
inp = wait_for_input(GP2X_UP|GP2X_DOWN|GP2X_B|GP2X_X|GP2X_SELECT);
|
||||
if(inp & GP2X_UP ) { menu_sel--; if (menu_sel < menu_sel_min) menu_sel = menu_sel_max; }
|
||||
if(inp & GP2X_DOWN) { menu_sel++; if (menu_sel > menu_sel_max) menu_sel = menu_sel_min; }
|
||||
if(inp &(GP2X_SELECT|GP2X_X)){
|
||||
if (rom_data) {
|
||||
while (gp2x_joystick_read(1) & (GP2X_SELECT|GP2X_X)) usleep(50*1000); // wait until select is released
|
||||
engineState = PGS_Running;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if(inp & GP2X_B ) {
|
||||
switch (menu_sel) {
|
||||
case 0: // resume game
|
||||
if (rom_data) { engineState = PGS_Running; return; }
|
||||
break;
|
||||
case 1: // save state
|
||||
if (rom_data) {
|
||||
if(emu_SaveLoadGame(0, 0)) {
|
||||
strcpy(menuErrorMsg, "save failed");
|
||||
continue;
|
||||
}
|
||||
engineState = PGS_Running;
|
||||
return;
|
||||
}
|
||||
break;
|
||||
case 2: // load state
|
||||
if (rom_data) {
|
||||
if(emu_SaveLoadGame(1, 0)) {
|
||||
strcpy(menuErrorMsg, "load failed");
|
||||
continue;
|
||||
}
|
||||
engineState = PGS_Running;
|
||||
return;
|
||||
}
|
||||
break;
|
||||
case 3: // reset game
|
||||
if (rom_data) {
|
||||
emu_ResetGame();
|
||||
engineState = PGS_Running;
|
||||
return;
|
||||
}
|
||||
break;
|
||||
case 4: // select rom
|
||||
selfname = romsel_loop(curr_path);
|
||||
if (selfname) {
|
||||
printf("selected file: %s\n", selfname);
|
||||
strncpy(currentConfig.lastRomFile, selfname, sizeof(currentConfig.lastRomFile)-1);
|
||||
currentConfig.lastRomFile[sizeof(currentConfig.lastRomFile)-1] = 0;
|
||||
engineState = PGS_ReloadRom;
|
||||
}
|
||||
return;
|
||||
case 5: // options
|
||||
menu_loop_options();
|
||||
break;
|
||||
case 6: // controls
|
||||
kc_sel_loop();
|
||||
break;
|
||||
case 7: // credits
|
||||
draw_menu_credits();
|
||||
usleep(500*1000);
|
||||
inp = wait_for_input(GP2X_B|GP2X_X);
|
||||
break;
|
||||
case 8: // exit
|
||||
engineState = PGS_Quit;
|
||||
return;
|
||||
}
|
||||
}
|
||||
menuErrorMsg[0] = 0; // clear error msg
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void menu_loop(void)
|
||||
{
|
||||
int pal[2];
|
||||
|
||||
// switch to 8bpp
|
||||
gp2x_video_changemode(8);
|
||||
gp2x_video_RGB_setscaling(320, 240);
|
||||
// set pal
|
||||
pal[0] = 0;
|
||||
pal[1] = 0x00ffffff;
|
||||
gp2x_video_setpalette(pal, 2);
|
||||
|
||||
menu_loop_root();
|
||||
|
||||
menuErrorMsg[0] = 0;
|
||||
}
|
16
platform/gp2x/menu.h
Normal file
16
platform/gp2x/menu.h
Normal file
|
@ -0,0 +1,16 @@
|
|||
// (c) Copyright 2006 notaz, All rights reserved.
|
||||
// Free for non-commercial use.
|
||||
|
||||
// For commercial use, separate licencing terms must be obtained.
|
||||
|
||||
extern char menuErrorMsg[40];
|
||||
|
||||
void gp2x_text_out8 (int x, int y, char *texto, ...);
|
||||
void gp2x_text_out15 (int x, int y, char *text);
|
||||
void gp2x_text_out8_2(int x, int y, char *texto, int color);
|
||||
void menu_loop(void);
|
||||
|
||||
#define CONFIGURABLE_KEYS \
|
||||
(GP2X_UP|GP2X_DOWN|GP2X_LEFT|GP2X_RIGHT|GP2X_A|GP2X_B|GP2X_X|GP2X_Y| \
|
||||
GP2X_START|GP2X_SELECT|GP2X_L|GP2X_R|GP2X_PUSH|GP2X_VOL_UP|GP2X_VOL_DOWN)
|
||||
|
104
platform/gp2x/mmuhack.c
Normal file
104
platform/gp2x/mmuhack.c
Normal file
|
@ -0,0 +1,104 @@
|
|||
#include <linux/config.h>
|
||||
#include <linux/module.h>
|
||||
#include <linux/kernel.h>
|
||||
#include <linux/init.h>
|
||||
#include <linux/miscdevice.h>
|
||||
#include <asm/memory.h>
|
||||
|
||||
#define MMUHACK_MINOR 225
|
||||
#define DEVICE_NAME "mmuhack"
|
||||
|
||||
#if __GNUC__ == 3
|
||||
#include <linux/version.h>
|
||||
static const char __module_kernel_version_gcc3[] __attribute__((__used__)) __attribute__((section(".modinfo"))) =
|
||||
"kernel_version=" UTS_RELEASE;
|
||||
#endif
|
||||
|
||||
static ssize_t mmuhack_open(struct inode *inode, struct file *filp)
|
||||
{
|
||||
unsigned int *pgtable;
|
||||
unsigned int *cpt;
|
||||
int i, j;
|
||||
int ttb;
|
||||
int ret = -EFAULT;
|
||||
|
||||
// get the pointer to the translation table base...
|
||||
asm volatile(
|
||||
"stmdb sp!, {r0}\n\t"
|
||||
"mrc p15, 0, r0, c2, c0, 0\n\t"
|
||||
"mov %0, r0\n\t"
|
||||
"ldmia sp!, {r0}\n\t": "=r"(ttb)
|
||||
);
|
||||
|
||||
pgtable = __va(ttb);
|
||||
|
||||
for (i = 0; i < 4096; i ++) if ( (pgtable[i] & 3) == 1 ) {
|
||||
cpt = __va(pgtable[i] & 0xfffffc00);
|
||||
|
||||
for (j = 0; j < 256; j ++) {/*
|
||||
if ( (cpt[j] & 0xfe00000f) == 0x02000002 ) {
|
||||
// set C and B bits in upper 32MB memory area...
|
||||
printk("Set C&B bits %08x\n",cpt[j]);
|
||||
cpt[j] |= 0xFFC;
|
||||
ret = 0;
|
||||
}
|
||||
*/
|
||||
if (((cpt[j] & 0xff000000) == 0x02000000) && ((cpt[j] & 12)==0) )
|
||||
{
|
||||
//printk("Set C&B bits %08x\n",cpt[j]);
|
||||
cpt[j] |= 0xFFC;
|
||||
}
|
||||
//if ((a>=0x31 && a<=0x36) && ((cpt[i] & 12)==0))
|
||||
if (((cpt[j] & 0xff000000) == 0x03000000) && ((cpt[j] & 12)==0))
|
||||
{
|
||||
//printk("Set C&B bits %08x\n",cpt[j]);
|
||||
//printf("SDL c and b bits not set, overwriting\n");
|
||||
cpt[j] |= 0xFFC;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// drain the write buffer and flush the tlb caches...
|
||||
asm volatile(
|
||||
"stmdb sp!, {r0}\n\t"
|
||||
"mov r0, #0\n\t"
|
||||
"mcr 15, 0, r0, cr7, cr10, 4\n\t"
|
||||
"mcr 15, 0, r0, cr8, cr7, 0\n\t"
|
||||
"ldmia sp!, {r0}\n\t"
|
||||
);
|
||||
|
||||
if (ret == 0)
|
||||
printk("MMU hack applied.\n");
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static struct file_operations mmuhack_fops = {
|
||||
owner: THIS_MODULE,
|
||||
open: mmuhack_open,
|
||||
};
|
||||
|
||||
|
||||
static struct miscdevice mmuhack = {
|
||||
MMUHACK_MINOR, DEVICE_NAME, &mmuhack_fops
|
||||
};
|
||||
|
||||
static int __init mmuhack_init(void)
|
||||
{
|
||||
misc_register(&mmuhack);
|
||||
/*
|
||||
printk("MMSP2 MMU Hack module.\n");
|
||||
*/
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void __exit mmuhack_exit(void)
|
||||
{
|
||||
misc_deregister(&mmuhack);
|
||||
/*
|
||||
printk(KERN_ALERT "MMU Hack module removed.\n");
|
||||
*/
|
||||
}
|
||||
|
||||
module_init(mmuhack_init);
|
||||
module_exit(mmuhack_exit);
|
4
platform/gp2x/mmuhack.txt
Normal file
4
platform/gp2x/mmuhack.txt
Normal file
|
@ -0,0 +1,4 @@
|
|||
Squidge's MMU Hack modularized.
|
||||
Original code by Squidge.
|
||||
Module by Annonymous?
|
||||
Slightly modified by me to suit my need.
|
18
platform/gp2x/port_config.h
Normal file
18
platform/gp2x/port_config.h
Normal file
|
@ -0,0 +1,18 @@
|
|||
// port specific settings
|
||||
|
||||
#ifndef PORT_CONFIG_H
|
||||
#define PORT_CONFIG_H
|
||||
|
||||
#define CPU_CALL
|
||||
|
||||
// draw2.c
|
||||
#define START_ROW 0 // which row of tiles to start rendering at?
|
||||
#define END_ROW 28 // ..end
|
||||
|
||||
// pico.c
|
||||
#define CAN_HANDLE_240_LINES 1
|
||||
|
||||
//#define dprintf(f,...) printf(f"\n",##__VA_ARGS__)
|
||||
#define dprintf(x...)
|
||||
|
||||
#endif //PORT_CONFIG_H
|
8
platform/gp2x/port_config.s
Normal file
8
platform/gp2x/port_config.s
Normal file
|
@ -0,0 +1,8 @@
|
|||
@ .equiv START_ROW, 1
|
||||
@ .equiv END_ROW, 27
|
||||
@ one row means 8 pixels. If above example was used, (27-1)*8=208 lines would be rendered.
|
||||
.equiv START_ROW, 0
|
||||
.equiv END_ROW, 28
|
||||
|
||||
@ this should be set to one only for GP2X port
|
||||
.equiv EXTERNAL_YM2612, 1
|
45
platform/gp2x/squidgehack.c
Normal file
45
platform/gp2x/squidgehack.c
Normal file
|
@ -0,0 +1,45 @@
|
|||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <fcntl.h>
|
||||
#include <unistd.h>
|
||||
|
||||
extern char **g_argv;
|
||||
|
||||
/* Call this MMU Hack kernel module after doing mmap, and before doing memset*/
|
||||
int mmuhack(void)
|
||||
{
|
||||
char kocmd[1024];
|
||||
int i, mmufd = open("/dev/mmuhack", O_RDWR);
|
||||
|
||||
if(mmufd < 0) {
|
||||
strcpy(kocmd, "/sbin/insmod ");
|
||||
strncpy(kocmd+13, g_argv[0], 1023-13);
|
||||
kocmd[1023] = 0;
|
||||
for (i = strlen(kocmd); i > 0; i--)
|
||||
if (kocmd[i] == '/') { kocmd[i] = 0; break; }
|
||||
strcat(kocmd, "/mmuhack.o");
|
||||
|
||||
printf("Installing NK's kernel module for Squidge MMU Hack (%s)...\n", kocmd);
|
||||
system(kocmd);
|
||||
mmufd = open("/dev/mmuhack", O_RDWR);
|
||||
}
|
||||
if(mmufd < 0) return 0;
|
||||
|
||||
close(mmufd);
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
/* Unload MMU Hack kernel module after closing all memory devices*/
|
||||
int mmuunhack(void)
|
||||
{
|
||||
int ret;
|
||||
printf("Removing NK's kernel module for Squidge MMU Hack... "); fflush(stdout);
|
||||
ret = system("/sbin/rmmod mmuhack");
|
||||
printf("done (%i)\n", ret);
|
||||
|
||||
return ret;
|
||||
}
|
7
platform/gp2x/squidgehack.h
Normal file
7
platform/gp2x/squidgehack.h
Normal file
|
@ -0,0 +1,7 @@
|
|||
#ifndef __MMUHACK__
|
||||
#define __MMUHACK__
|
||||
|
||||
extern int mmuhack(void);
|
||||
extern int mmuunhack(void);
|
||||
|
||||
#endif /* __MMUHACK__ */
|
37
platform/gp2x/test.c
Normal file
37
platform/gp2x/test.c
Normal file
|
@ -0,0 +1,37 @@
|
|||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
#include <sys/time.h>
|
||||
#include "gp2x.h"
|
||||
|
||||
void spend_cycles(int c);
|
||||
|
||||
int main(void)
|
||||
{
|
||||
struct timeval tval; // timing
|
||||
int thissec = 0, frames_done = 0;
|
||||
|
||||
gp2x_init();
|
||||
|
||||
for (;;)
|
||||
{
|
||||
gettimeofday(&tval, 0);
|
||||
|
||||
if(thissec != tval.tv_sec)
|
||||
{
|
||||
thissec = tval.tv_sec;
|
||||
|
||||
printf("frames_done: %i\n", frames_done);
|
||||
frames_done = 0;
|
||||
}
|
||||
|
||||
|
||||
//gp2x_video_wait_vsync();
|
||||
//usleep(1); // sleeps a minimum of ~20ms
|
||||
//gp2x_video_flip(); // can be called ~430000 times/sec
|
||||
spend_cycles(1000);
|
||||
frames_done++;
|
||||
}
|
||||
|
||||
}
|
||||
|
16
platform/gp2x/uClibc/README
Normal file
16
platform/gp2x/uClibc/README
Normal file
|
@ -0,0 +1,16 @@
|
|||
The routines included in this math library are derived from the
|
||||
math library for Apple's MacOS X/Darwin math library, which was
|
||||
itself swiped from FreeBSD. The original copyright information
|
||||
is as follows:
|
||||
|
||||
Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
|
||||
|
||||
Developed at SunPro, a Sun Microsystems, Inc. business.
|
||||
Permission to use, copy, modify, and distribute this
|
||||
software is freely granted, provided that this notice
|
||||
is preserved.
|
||||
|
||||
It has been ported to work with uClibc and generally behave
|
||||
by Erik Andersen <andersen@codepoet.org>
|
||||
22 May, 2001
|
||||
|
147
platform/gp2x/uClibc/e_log.c
Normal file
147
platform/gp2x/uClibc/e_log.c
Normal file
|
@ -0,0 +1,147 @@
|
|||
/* @(#)e_log.c 5.1 93/09/24 */
|
||||
/*
|
||||
* ====================================================
|
||||
* Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
|
||||
*
|
||||
* Developed at SunPro, a Sun Microsystems, Inc. business.
|
||||
* Permission to use, copy, modify, and distribute this
|
||||
* software is freely granted, provided that this notice
|
||||
* is preserved.
|
||||
* ====================================================
|
||||
*/
|
||||
|
||||
#if defined(LIBM_SCCS) && !defined(lint)
|
||||
static char rcsid[] = "$NetBSD: e_log.c,v 1.8 1995/05/10 20:45:49 jtc Exp $";
|
||||
#endif
|
||||
|
||||
/* __ieee754_log(x)
|
||||
* Return the logrithm of x
|
||||
*
|
||||
* Method :
|
||||
* 1. Argument Reduction: find k and f such that
|
||||
* x = 2^k * (1+f),
|
||||
* where sqrt(2)/2 < 1+f < sqrt(2) .
|
||||
*
|
||||
* 2. Approximation of log(1+f).
|
||||
* Let s = f/(2+f) ; based on log(1+f) = log(1+s) - log(1-s)
|
||||
* = 2s + 2/3 s**3 + 2/5 s**5 + .....,
|
||||
* = 2s + s*R
|
||||
* We use a special Reme algorithm on [0,0.1716] to generate
|
||||
* a polynomial of degree 14 to approximate R The maximum error
|
||||
* of this polynomial approximation is bounded by 2**-58.45. In
|
||||
* other words,
|
||||
* 2 4 6 8 10 12 14
|
||||
* R(z) ~ Lg1*s +Lg2*s +Lg3*s +Lg4*s +Lg5*s +Lg6*s +Lg7*s
|
||||
* (the values of Lg1 to Lg7 are listed in the program)
|
||||
* and
|
||||
* | 2 14 | -58.45
|
||||
* | Lg1*s +...+Lg7*s - R(z) | <= 2
|
||||
* | |
|
||||
* Note that 2s = f - s*f = f - hfsq + s*hfsq, where hfsq = f*f/2.
|
||||
* In order to guarantee error in log below 1ulp, we compute log
|
||||
* by
|
||||
* log(1+f) = f - s*(f - R) (if f is not too large)
|
||||
* log(1+f) = f - (hfsq - s*(hfsq+R)). (better accuracy)
|
||||
*
|
||||
* 3. Finally, log(x) = k*ln2 + log(1+f).
|
||||
* = k*ln2_hi+(f-(hfsq-(s*(hfsq+R)+k*ln2_lo)))
|
||||
* Here ln2 is split into two floating point number:
|
||||
* ln2_hi + ln2_lo,
|
||||
* where n*ln2_hi is always exact for |n| < 2000.
|
||||
*
|
||||
* Special cases:
|
||||
* log(x) is NaN with signal if x < 0 (including -INF) ;
|
||||
* log(+INF) is +INF; log(0) is -INF with signal;
|
||||
* log(NaN) is that NaN with no signal.
|
||||
*
|
||||
* Accuracy:
|
||||
* according to an error analysis, the error is always less than
|
||||
* 1 ulp (unit in the last place).
|
||||
*
|
||||
* Constants:
|
||||
* The hexadecimal values are the intended ones for the following
|
||||
* constants. The decimal values may be used, provided that the
|
||||
* compiler will convert from decimal to binary accurately enough
|
||||
* to produce the hexadecimal values shown.
|
||||
*/
|
||||
|
||||
#include "math.h"
|
||||
#include "math_private.h"
|
||||
|
||||
#ifdef __STDC__
|
||||
static const double
|
||||
#else
|
||||
static double
|
||||
#endif
|
||||
ln2_hi = 6.93147180369123816490e-01, /* 3fe62e42 fee00000 */
|
||||
ln2_lo = 1.90821492927058770002e-10, /* 3dea39ef 35793c76 */
|
||||
two54 = 1.80143985094819840000e+16, /* 43500000 00000000 */
|
||||
Lg1 = 6.666666666666735130e-01, /* 3FE55555 55555593 */
|
||||
Lg2 = 3.999999999940941908e-01, /* 3FD99999 9997FA04 */
|
||||
Lg3 = 2.857142874366239149e-01, /* 3FD24924 94229359 */
|
||||
Lg4 = 2.222219843214978396e-01, /* 3FCC71C5 1D8E78AF */
|
||||
Lg5 = 1.818357216161805012e-01, /* 3FC74664 96CB03DE */
|
||||
Lg6 = 1.531383769920937332e-01, /* 3FC39A09 D078C69F */
|
||||
Lg7 = 1.479819860511658591e-01; /* 3FC2F112 DF3E5244 */
|
||||
|
||||
#ifdef __STDC__
|
||||
static const double zero = 0.0;
|
||||
#else
|
||||
static double zero = 0.0;
|
||||
#endif
|
||||
|
||||
#ifdef __STDC__
|
||||
double __ieee754_log(double x)
|
||||
#else
|
||||
double __ieee754_log(x)
|
||||
double x;
|
||||
#endif
|
||||
{
|
||||
double hfsq,f,s,z,R,w,t1,t2,dk;
|
||||
int32_t k,hx,i,j;
|
||||
u_int32_t lx;
|
||||
|
||||
EXTRACT_WORDS(hx,lx,x);
|
||||
|
||||
k=0;
|
||||
if (hx < 0x00100000) { /* x < 2**-1022 */
|
||||
if (((hx&0x7fffffff)|lx)==0)
|
||||
return -two54/zero; /* log(+-0)=-inf */
|
||||
if (hx<0) return (x-x)/zero; /* log(-#) = NaN */
|
||||
k -= 54; x *= two54; /* subnormal number, scale up x */
|
||||
GET_HIGH_WORD(hx,x);
|
||||
}
|
||||
if (hx >= 0x7ff00000) return x+x;
|
||||
k += (hx>>20)-1023;
|
||||
hx &= 0x000fffff;
|
||||
i = (hx+0x95f64)&0x100000;
|
||||
SET_HIGH_WORD(x,hx|(i^0x3ff00000)); /* normalize x or x/2 */
|
||||
k += (i>>20);
|
||||
f = x-1.0;
|
||||
if((0x000fffff&(2+hx))<3) { /* |f| < 2**-20 */
|
||||
if(f==zero) {if(k==0) return zero; else {dk=(double)k;
|
||||
return dk*ln2_hi+dk*ln2_lo;}
|
||||
}
|
||||
R = f*f*(0.5-0.33333333333333333*f);
|
||||
if(k==0) return f-R; else {dk=(double)k;
|
||||
return dk*ln2_hi-((R-dk*ln2_lo)-f);}
|
||||
}
|
||||
s = f/(2.0+f);
|
||||
dk = (double)k;
|
||||
z = s*s;
|
||||
i = hx-0x6147a;
|
||||
w = z*z;
|
||||
j = 0x6b851-hx;
|
||||
t1= w*(Lg2+w*(Lg4+w*Lg6));
|
||||
t2= z*(Lg1+w*(Lg3+w*(Lg5+w*Lg7)));
|
||||
i |= j;
|
||||
R = t2+t1;
|
||||
if(i>0) {
|
||||
hfsq=0.5*f*f;
|
||||
if(k==0) return f-(hfsq-s*(hfsq+R)); else
|
||||
return dk*ln2_hi-((hfsq-(s*(hfsq+R)+dk*ln2_lo))-f);
|
||||
} else {
|
||||
if(k==0) return f-s*(f-R); else
|
||||
return dk*ln2_hi-((s*(f-R)-dk*ln2_lo)-f);
|
||||
}
|
||||
}
|
308
platform/gp2x/uClibc/e_pow.c
Normal file
308
platform/gp2x/uClibc/e_pow.c
Normal file
|
@ -0,0 +1,308 @@
|
|||
/* @(#)e_pow.c 5.1 93/09/24 */
|
||||
/*
|
||||
* ====================================================
|
||||
* Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
|
||||
*
|
||||
* Developed at SunPro, a Sun Microsystems, Inc. business.
|
||||
* Permission to use, copy, modify, and distribute this
|
||||
* software is freely granted, provided that this notice
|
||||
* is preserved.
|
||||
* ====================================================
|
||||
*/
|
||||
|
||||
#if defined(LIBM_SCCS) && !defined(lint)
|
||||
static char rcsid[] = "$NetBSD: e_pow.c,v 1.9 1995/05/12 04:57:32 jtc Exp $";
|
||||
#endif
|
||||
|
||||
/* __ieee754_pow(x,y) return x**y
|
||||
*
|
||||
* n
|
||||
* Method: Let x = 2 * (1+f)
|
||||
* 1. Compute and return log2(x) in two pieces:
|
||||
* log2(x) = w1 + w2,
|
||||
* where w1 has 53-24 = 29 bit trailing zeros.
|
||||
* 2. Perform y*log2(x) = n+y' by simulating muti-precision
|
||||
* arithmetic, where |y'|<=0.5.
|
||||
* 3. Return x**y = 2**n*exp(y'*log2)
|
||||
*
|
||||
* Special cases:
|
||||
* 1. (anything) ** 0 is 1
|
||||
* 2. (anything) ** 1 is itself
|
||||
* 3. (anything) ** NAN is NAN
|
||||
* 4. NAN ** (anything except 0) is NAN
|
||||
* 5. +-(|x| > 1) ** +INF is +INF
|
||||
* 6. +-(|x| > 1) ** -INF is +0
|
||||
* 7. +-(|x| < 1) ** +INF is +0
|
||||
* 8. +-(|x| < 1) ** -INF is +INF
|
||||
* 9. +-1 ** +-INF is NAN
|
||||
* 10. +0 ** (+anything except 0, NAN) is +0
|
||||
* 11. -0 ** (+anything except 0, NAN, odd integer) is +0
|
||||
* 12. +0 ** (-anything except 0, NAN) is +INF
|
||||
* 13. -0 ** (-anything except 0, NAN, odd integer) is +INF
|
||||
* 14. -0 ** (odd integer) = -( +0 ** (odd integer) )
|
||||
* 15. +INF ** (+anything except 0,NAN) is +INF
|
||||
* 16. +INF ** (-anything except 0,NAN) is +0
|
||||
* 17. -INF ** (anything) = -0 ** (-anything)
|
||||
* 18. (-anything) ** (integer) is (-1)**(integer)*(+anything**integer)
|
||||
* 19. (-anything except 0 and inf) ** (non-integer) is NAN
|
||||
*
|
||||
* Accuracy:
|
||||
* pow(x,y) returns x**y nearly rounded. In particular
|
||||
* pow(integer,integer)
|
||||
* always returns the correct integer provided it is
|
||||
* representable.
|
||||
*
|
||||
* Constants :
|
||||
* The hexadecimal values are the intended ones for the following
|
||||
* constants. The decimal values may be used, provided that the
|
||||
* compiler will convert from decimal to binary accurately enough
|
||||
* to produce the hexadecimal values shown.
|
||||
*/
|
||||
|
||||
#include "math.h"
|
||||
#include "math_private.h"
|
||||
|
||||
#ifdef __STDC__
|
||||
static const double
|
||||
#else
|
||||
static double
|
||||
#endif
|
||||
bp[] = {1.0, 1.5,},
|
||||
dp_h[] = { 0.0, 5.84962487220764160156e-01,}, /* 0x3FE2B803, 0x40000000 */
|
||||
dp_l[] = { 0.0, 1.35003920212974897128e-08,}, /* 0x3E4CFDEB, 0x43CFD006 */
|
||||
zero = 0.0,
|
||||
one = 1.0,
|
||||
two = 2.0,
|
||||
two53 = 9007199254740992.0, /* 0x43400000, 0x00000000 */
|
||||
huge = 1.0e300,
|
||||
tiny = 1.0e-300,
|
||||
/* poly coefs for (3/2)*(log(x)-2s-2/3*s**3 */
|
||||
L1 = 5.99999999999994648725e-01, /* 0x3FE33333, 0x33333303 */
|
||||
L2 = 4.28571428578550184252e-01, /* 0x3FDB6DB6, 0xDB6FABFF */
|
||||
L3 = 3.33333329818377432918e-01, /* 0x3FD55555, 0x518F264D */
|
||||
L4 = 2.72728123808534006489e-01, /* 0x3FD17460, 0xA91D4101 */
|
||||
L5 = 2.30660745775561754067e-01, /* 0x3FCD864A, 0x93C9DB65 */
|
||||
L6 = 2.06975017800338417784e-01, /* 0x3FCA7E28, 0x4A454EEF */
|
||||
P1 = 1.66666666666666019037e-01, /* 0x3FC55555, 0x5555553E */
|
||||
P2 = -2.77777777770155933842e-03, /* 0xBF66C16C, 0x16BEBD93 */
|
||||
P3 = 6.61375632143793436117e-05, /* 0x3F11566A, 0xAF25DE2C */
|
||||
P4 = -1.65339022054652515390e-06, /* 0xBEBBBD41, 0xC5D26BF1 */
|
||||
P5 = 4.13813679705723846039e-08, /* 0x3E663769, 0x72BEA4D0 */
|
||||
lg2 = 6.93147180559945286227e-01, /* 0x3FE62E42, 0xFEFA39EF */
|
||||
lg2_h = 6.93147182464599609375e-01, /* 0x3FE62E43, 0x00000000 */
|
||||
lg2_l = -1.90465429995776804525e-09, /* 0xBE205C61, 0x0CA86C39 */
|
||||
ovt = 8.0085662595372944372e-0017, /* -(1024-log2(ovfl+.5ulp)) */
|
||||
cp = 9.61796693925975554329e-01, /* 0x3FEEC709, 0xDC3A03FD =2/(3ln2) */
|
||||
cp_h = 9.61796700954437255859e-01, /* 0x3FEEC709, 0xE0000000 =(float)cp */
|
||||
cp_l = -7.02846165095275826516e-09, /* 0xBE3E2FE0, 0x145B01F5 =tail of cp_h*/
|
||||
ivln2 = 1.44269504088896338700e+00, /* 0x3FF71547, 0x652B82FE =1/ln2 */
|
||||
ivln2_h = 1.44269502162933349609e+00, /* 0x3FF71547, 0x60000000 =24b 1/ln2*/
|
||||
ivln2_l = 1.92596299112661746887e-08; /* 0x3E54AE0B, 0xF85DDF44 =1/ln2 tail*/
|
||||
|
||||
#ifdef __STDC__
|
||||
double __ieee754_pow(double x, double y)
|
||||
#else
|
||||
double __ieee754_pow(x,y)
|
||||
double x, y;
|
||||
#endif
|
||||
{
|
||||
double z,ax,z_h,z_l,p_h,p_l;
|
||||
double y1,t1,t2,r,s,t,u,v,w;
|
||||
int32_t i,j,k,yisint,n;
|
||||
int32_t hx,hy,ix,iy;
|
||||
u_int32_t lx,ly;
|
||||
|
||||
EXTRACT_WORDS(hx,lx,x);
|
||||
EXTRACT_WORDS(hy,ly,y);
|
||||
ix = hx&0x7fffffff; iy = hy&0x7fffffff;
|
||||
|
||||
/* y==zero: x**0 = 1 */
|
||||
if((iy|ly)==0) return one;
|
||||
|
||||
/* +-NaN return x+y */
|
||||
if(ix > 0x7ff00000 || ((ix==0x7ff00000)&&(lx!=0)) ||
|
||||
iy > 0x7ff00000 || ((iy==0x7ff00000)&&(ly!=0)))
|
||||
return x+y;
|
||||
|
||||
/* determine if y is an odd int when x < 0
|
||||
* yisint = 0 ... y is not an integer
|
||||
* yisint = 1 ... y is an odd int
|
||||
* yisint = 2 ... y is an even int
|
||||
*/
|
||||
yisint = 0;
|
||||
if(hx<0) {
|
||||
if(iy>=0x43400000) yisint = 2; /* even integer y */
|
||||
else if(iy>=0x3ff00000) {
|
||||
k = (iy>>20)-0x3ff; /* exponent */
|
||||
if(k>20) {
|
||||
j = ly>>(52-k);
|
||||
if((j<<(52-k))==ly) yisint = 2-(j&1);
|
||||
} else if(ly==0) {
|
||||
j = iy>>(20-k);
|
||||
if((j<<(20-k))==iy) yisint = 2-(j&1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* special value of y */
|
||||
if(ly==0) {
|
||||
if (iy==0x7ff00000) { /* y is +-inf */
|
||||
if(((ix-0x3ff00000)|lx)==0)
|
||||
return y - y; /* inf**+-1 is NaN */
|
||||
else if (ix >= 0x3ff00000)/* (|x|>1)**+-inf = inf,0 */
|
||||
return (hy>=0)? y: zero;
|
||||
else /* (|x|<1)**-,+inf = inf,0 */
|
||||
return (hy<0)?-y: zero;
|
||||
}
|
||||
if(iy==0x3ff00000) { /* y is +-1 */
|
||||
if(hy<0) return one/x; else return x;
|
||||
}
|
||||
if(hy==0x40000000) return x*x; /* y is 2 */
|
||||
if(hy==0x3fe00000) { /* y is 0.5 */
|
||||
if(hx>=0) /* x >= +0 */
|
||||
return __ieee754_sqrt(x);
|
||||
}
|
||||
}
|
||||
|
||||
ax = fabs(x);
|
||||
/* special value of x */
|
||||
if(lx==0) {
|
||||
if(ix==0x7ff00000||ix==0||ix==0x3ff00000){
|
||||
z = ax; /*x is +-0,+-inf,+-1*/
|
||||
if(hy<0) z = one/z; /* z = (1/|x|) */
|
||||
if(hx<0) {
|
||||
if(((ix-0x3ff00000)|yisint)==0) {
|
||||
z = (z-z)/(z-z); /* (-1)**non-int is NaN */
|
||||
} else if(yisint==1)
|
||||
z = -z; /* (x<0)**odd = -(|x|**odd) */
|
||||
}
|
||||
return z;
|
||||
}
|
||||
}
|
||||
|
||||
/* (x<0)**(non-int) is NaN */
|
||||
if(((((u_int32_t)hx>>31)-1)|yisint)==0) return (x-x)/(x-x);
|
||||
|
||||
/* |y| is huge */
|
||||
if(iy>0x41e00000) { /* if |y| > 2**31 */
|
||||
if(iy>0x43f00000){ /* if |y| > 2**64, must o/uflow */
|
||||
if(ix<=0x3fefffff) return (hy<0)? huge*huge:tiny*tiny;
|
||||
if(ix>=0x3ff00000) return (hy>0)? huge*huge:tiny*tiny;
|
||||
}
|
||||
/* over/underflow if x is not close to one */
|
||||
if(ix<0x3fefffff) return (hy<0)? huge*huge:tiny*tiny;
|
||||
if(ix>0x3ff00000) return (hy>0)? huge*huge:tiny*tiny;
|
||||
/* now |1-x| is tiny <= 2**-20, suffice to compute
|
||||
log(x) by x-x^2/2+x^3/3-x^4/4 */
|
||||
t = x-1; /* t has 20 trailing zeros */
|
||||
w = (t*t)*(0.5-t*(0.3333333333333333333333-t*0.25));
|
||||
u = ivln2_h*t; /* ivln2_h has 21 sig. bits */
|
||||
v = t*ivln2_l-w*ivln2;
|
||||
t1 = u+v;
|
||||
SET_LOW_WORD(t1,0);
|
||||
t2 = v-(t1-u);
|
||||
} else {
|
||||
double s2,s_h,s_l,t_h,t_l;
|
||||
n = 0;
|
||||
/* take care subnormal number */
|
||||
if(ix<0x00100000)
|
||||
{ax *= two53; n -= 53; GET_HIGH_WORD(ix,ax); }
|
||||
n += ((ix)>>20)-0x3ff;
|
||||
j = ix&0x000fffff;
|
||||
/* determine interval */
|
||||
ix = j|0x3ff00000; /* normalize ix */
|
||||
if(j<=0x3988E) k=0; /* |x|<sqrt(3/2) */
|
||||
else if(j<0xBB67A) k=1; /* |x|<sqrt(3) */
|
||||
else {k=0;n+=1;ix -= 0x00100000;}
|
||||
SET_HIGH_WORD(ax,ix);
|
||||
|
||||
/* compute s = s_h+s_l = (x-1)/(x+1) or (x-1.5)/(x+1.5) */
|
||||
u = ax-bp[k]; /* bp[0]=1.0, bp[1]=1.5 */
|
||||
v = one/(ax+bp[k]);
|
||||
s = u*v;
|
||||
s_h = s;
|
||||
SET_LOW_WORD(s_h,0);
|
||||
/* t_h=ax+bp[k] High */
|
||||
t_h = zero;
|
||||
SET_HIGH_WORD(t_h,((ix>>1)|0x20000000)+0x00080000+(k<<18));
|
||||
t_l = ax - (t_h-bp[k]);
|
||||
s_l = v*((u-s_h*t_h)-s_h*t_l);
|
||||
/* compute log(ax) */
|
||||
s2 = s*s;
|
||||
r = s2*s2*(L1+s2*(L2+s2*(L3+s2*(L4+s2*(L5+s2*L6)))));
|
||||
r += s_l*(s_h+s);
|
||||
s2 = s_h*s_h;
|
||||
t_h = 3.0+s2+r;
|
||||
SET_LOW_WORD(t_h,0);
|
||||
t_l = r-((t_h-3.0)-s2);
|
||||
/* u+v = s*(1+...) */
|
||||
u = s_h*t_h;
|
||||
v = s_l*t_h+t_l*s;
|
||||
/* 2/(3log2)*(s+...) */
|
||||
p_h = u+v;
|
||||
SET_LOW_WORD(p_h,0);
|
||||
p_l = v-(p_h-u);
|
||||
z_h = cp_h*p_h; /* cp_h+cp_l = 2/(3*log2) */
|
||||
z_l = cp_l*p_h+p_l*cp+dp_l[k];
|
||||
/* log2(ax) = (s+..)*2/(3*log2) = n + dp_h + z_h + z_l */
|
||||
t = (double)n;
|
||||
t1 = (((z_h+z_l)+dp_h[k])+t);
|
||||
SET_LOW_WORD(t1,0);
|
||||
t2 = z_l-(((t1-t)-dp_h[k])-z_h);
|
||||
}
|
||||
|
||||
s = one; /* s (sign of result -ve**odd) = -1 else = 1 */
|
||||
if(((((u_int32_t)hx>>31)-1)|(yisint-1))==0)
|
||||
s = -one;/* (-ve)**(odd int) */
|
||||
|
||||
/* split up y into y1+y2 and compute (y1+y2)*(t1+t2) */
|
||||
y1 = y;
|
||||
SET_LOW_WORD(y1,0);
|
||||
p_l = (y-y1)*t1+y*t2;
|
||||
p_h = y1*t1;
|
||||
z = p_l+p_h;
|
||||
EXTRACT_WORDS(j,i,z);
|
||||
if (j>=0x40900000) { /* z >= 1024 */
|
||||
if(((j-0x40900000)|i)!=0) /* if z > 1024 */
|
||||
return s*huge*huge; /* overflow */
|
||||
else {
|
||||
if(p_l+ovt>z-p_h) return s*huge*huge; /* overflow */
|
||||
}
|
||||
} else if((j&0x7fffffff)>=0x4090cc00 ) { /* z <= -1075 */
|
||||
if(((j-0xc090cc00)|i)!=0) /* z < -1075 */
|
||||
return s*tiny*tiny; /* underflow */
|
||||
else {
|
||||
if(p_l<=z-p_h) return s*tiny*tiny; /* underflow */
|
||||
}
|
||||
}
|
||||
/*
|
||||
* compute 2**(p_h+p_l)
|
||||
*/
|
||||
i = j&0x7fffffff;
|
||||
k = (i>>20)-0x3ff;
|
||||
n = 0;
|
||||
if(i>0x3fe00000) { /* if |z| > 0.5, set n = [z+0.5] */
|
||||
n = j+(0x00100000>>(k+1));
|
||||
k = ((n&0x7fffffff)>>20)-0x3ff; /* new k for n */
|
||||
t = zero;
|
||||
SET_HIGH_WORD(t,n&~(0x000fffff>>k));
|
||||
n = ((n&0x000fffff)|0x00100000)>>(20-k);
|
||||
if(j<0) n = -n;
|
||||
p_h -= t;
|
||||
}
|
||||
t = p_l+p_h;
|
||||
SET_LOW_WORD(t,0);
|
||||
u = t*lg2_h;
|
||||
v = (p_l-(t-p_h))*lg2+t*lg2_l;
|
||||
z = u+v;
|
||||
w = v-(z-u);
|
||||
t = z*z;
|
||||
t1 = z - t*(P1+t*(P2+t*(P3+t*(P4+t*P5))));
|
||||
r = (z*t1)/(t1-two)-(w+z*w);
|
||||
z = one-(r-z);
|
||||
GET_HIGH_WORD(j,z);
|
||||
j += (n<<20);
|
||||
if((j>>20)<=0) z = scalbn(z,n); /* subnormal output */
|
||||
else SET_HIGH_WORD(z,j);
|
||||
return s*z;
|
||||
}
|
183
platform/gp2x/uClibc/e_rem_pio2.c
Normal file
183
platform/gp2x/uClibc/e_rem_pio2.c
Normal file
|
@ -0,0 +1,183 @@
|
|||
/* @(#)e_rem_pio2.c 5.1 93/09/24 */
|
||||
/*
|
||||
* ====================================================
|
||||
* Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
|
||||
*
|
||||
* Developed at SunPro, a Sun Microsystems, Inc. business.
|
||||
* Permission to use, copy, modify, and distribute this
|
||||
* software is freely granted, provided that this notice
|
||||
* is preserved.
|
||||
* ====================================================
|
||||
*/
|
||||
|
||||
#if defined(LIBM_SCCS) && !defined(lint)
|
||||
static char rcsid[] = "$NetBSD: e_rem_pio2.c,v 1.8 1995/05/10 20:46:02 jtc Exp $";
|
||||
#endif
|
||||
|
||||
/* __ieee754_rem_pio2(x,y)
|
||||
*
|
||||
* return the remainder of x rem pi/2 in y[0]+y[1]
|
||||
* use __kernel_rem_pio2()
|
||||
*/
|
||||
|
||||
#include "math.h"
|
||||
#include "math_private.h"
|
||||
|
||||
/*
|
||||
* Table of constants for 2/pi, 396 Hex digits (476 decimal) of 2/pi
|
||||
*/
|
||||
#ifdef __STDC__
|
||||
static const int32_t two_over_pi[] = {
|
||||
#else
|
||||
static int32_t two_over_pi[] = {
|
||||
#endif
|
||||
0xA2F983, 0x6E4E44, 0x1529FC, 0x2757D1, 0xF534DD, 0xC0DB62,
|
||||
0x95993C, 0x439041, 0xFE5163, 0xABDEBB, 0xC561B7, 0x246E3A,
|
||||
0x424DD2, 0xE00649, 0x2EEA09, 0xD1921C, 0xFE1DEB, 0x1CB129,
|
||||
0xA73EE8, 0x8235F5, 0x2EBB44, 0x84E99C, 0x7026B4, 0x5F7E41,
|
||||
0x3991D6, 0x398353, 0x39F49C, 0x845F8B, 0xBDF928, 0x3B1FF8,
|
||||
0x97FFDE, 0x05980F, 0xEF2F11, 0x8B5A0A, 0x6D1F6D, 0x367ECF,
|
||||
0x27CB09, 0xB74F46, 0x3F669E, 0x5FEA2D, 0x7527BA, 0xC7EBE5,
|
||||
0xF17B3D, 0x0739F7, 0x8A5292, 0xEA6BFB, 0x5FB11F, 0x8D5D08,
|
||||
0x560330, 0x46FC7B, 0x6BABF0, 0xCFBC20, 0x9AF436, 0x1DA9E3,
|
||||
0x91615E, 0xE61B08, 0x659985, 0x5F14A0, 0x68408D, 0xFFD880,
|
||||
0x4D7327, 0x310606, 0x1556CA, 0x73A8C9, 0x60E27B, 0xC08C6B,
|
||||
};
|
||||
|
||||
#ifdef __STDC__
|
||||
static const int32_t npio2_hw[] = {
|
||||
#else
|
||||
static int32_t npio2_hw[] = {
|
||||
#endif
|
||||
0x3FF921FB, 0x400921FB, 0x4012D97C, 0x401921FB, 0x401F6A7A, 0x4022D97C,
|
||||
0x4025FDBB, 0x402921FB, 0x402C463A, 0x402F6A7A, 0x4031475C, 0x4032D97C,
|
||||
0x40346B9C, 0x4035FDBB, 0x40378FDB, 0x403921FB, 0x403AB41B, 0x403C463A,
|
||||
0x403DD85A, 0x403F6A7A, 0x40407E4C, 0x4041475C, 0x4042106C, 0x4042D97C,
|
||||
0x4043A28C, 0x40446B9C, 0x404534AC, 0x4045FDBB, 0x4046C6CB, 0x40478FDB,
|
||||
0x404858EB, 0x404921FB,
|
||||
};
|
||||
|
||||
/*
|
||||
* invpio2: 53 bits of 2/pi
|
||||
* pio2_1: first 33 bit of pi/2
|
||||
* pio2_1t: pi/2 - pio2_1
|
||||
* pio2_2: second 33 bit of pi/2
|
||||
* pio2_2t: pi/2 - (pio2_1+pio2_2)
|
||||
* pio2_3: third 33 bit of pi/2
|
||||
* pio2_3t: pi/2 - (pio2_1+pio2_2+pio2_3)
|
||||
*/
|
||||
|
||||
#ifdef __STDC__
|
||||
static const double
|
||||
#else
|
||||
static double
|
||||
#endif
|
||||
zero = 0.00000000000000000000e+00, /* 0x00000000, 0x00000000 */
|
||||
half = 5.00000000000000000000e-01, /* 0x3FE00000, 0x00000000 */
|
||||
two24 = 1.67772160000000000000e+07, /* 0x41700000, 0x00000000 */
|
||||
invpio2 = 6.36619772367581382433e-01, /* 0x3FE45F30, 0x6DC9C883 */
|
||||
pio2_1 = 1.57079632673412561417e+00, /* 0x3FF921FB, 0x54400000 */
|
||||
pio2_1t = 6.07710050650619224932e-11, /* 0x3DD0B461, 0x1A626331 */
|
||||
pio2_2 = 6.07710050630396597660e-11, /* 0x3DD0B461, 0x1A600000 */
|
||||
pio2_2t = 2.02226624879595063154e-21, /* 0x3BA3198A, 0x2E037073 */
|
||||
pio2_3 = 2.02226624871116645580e-21, /* 0x3BA3198A, 0x2E000000 */
|
||||
pio2_3t = 8.47842766036889956997e-32; /* 0x397B839A, 0x252049C1 */
|
||||
|
||||
#ifdef __STDC__
|
||||
int32_t __ieee754_rem_pio2(double x, double *y)
|
||||
#else
|
||||
int32_t __ieee754_rem_pio2(x,y)
|
||||
double x,y[];
|
||||
#endif
|
||||
{
|
||||
double z=0.0,w,t,r,fn;
|
||||
double tx[3];
|
||||
int32_t e0,i,j,nx,n,ix,hx;
|
||||
u_int32_t low;
|
||||
|
||||
GET_HIGH_WORD(hx,x); /* high word of x */
|
||||
ix = hx&0x7fffffff;
|
||||
if(ix<=0x3fe921fb) /* |x| ~<= pi/4 , no need for reduction */
|
||||
{y[0] = x; y[1] = 0; return 0;}
|
||||
if(ix<0x4002d97c) { /* |x| < 3pi/4, special case with n=+-1 */
|
||||
if(hx>0) {
|
||||
z = x - pio2_1;
|
||||
if(ix!=0x3ff921fb) { /* 33+53 bit pi is good enough */
|
||||
y[0] = z - pio2_1t;
|
||||
y[1] = (z-y[0])-pio2_1t;
|
||||
} else { /* near pi/2, use 33+33+53 bit pi */
|
||||
z -= pio2_2;
|
||||
y[0] = z - pio2_2t;
|
||||
y[1] = (z-y[0])-pio2_2t;
|
||||
}
|
||||
return 1;
|
||||
} else { /* negative x */
|
||||
z = x + pio2_1;
|
||||
if(ix!=0x3ff921fb) { /* 33+53 bit pi is good enough */
|
||||
y[0] = z + pio2_1t;
|
||||
y[1] = (z-y[0])+pio2_1t;
|
||||
} else { /* near pi/2, use 33+33+53 bit pi */
|
||||
z += pio2_2;
|
||||
y[0] = z + pio2_2t;
|
||||
y[1] = (z-y[0])+pio2_2t;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
if(ix<=0x413921fb) { /* |x| ~<= 2^19*(pi/2), medium size */
|
||||
t = fabs(x);
|
||||
n = (int32_t) (t*invpio2+half);
|
||||
fn = (double)n;
|
||||
r = t-fn*pio2_1;
|
||||
w = fn*pio2_1t; /* 1st round good to 85 bit */
|
||||
if(n<32&&ix!=npio2_hw[n-1]) {
|
||||
y[0] = r-w; /* quick check no cancellation */
|
||||
} else {
|
||||
u_int32_t high;
|
||||
j = ix>>20;
|
||||
y[0] = r-w;
|
||||
GET_HIGH_WORD(high,y[0]);
|
||||
i = j-((high>>20)&0x7ff);
|
||||
if(i>16) { /* 2nd iteration needed, good to 118 */
|
||||
t = r;
|
||||
w = fn*pio2_2;
|
||||
r = t-w;
|
||||
w = fn*pio2_2t-((t-r)-w);
|
||||
y[0] = r-w;
|
||||
GET_HIGH_WORD(high,y[0]);
|
||||
i = j-((high>>20)&0x7ff);
|
||||
if(i>49) { /* 3rd iteration need, 151 bits acc */
|
||||
t = r; /* will cover all possible cases */
|
||||
w = fn*pio2_3;
|
||||
r = t-w;
|
||||
w = fn*pio2_3t-((t-r)-w);
|
||||
y[0] = r-w;
|
||||
}
|
||||
}
|
||||
}
|
||||
y[1] = (r-y[0])-w;
|
||||
if(hx<0) {y[0] = -y[0]; y[1] = -y[1]; return -n;}
|
||||
else return n;
|
||||
}
|
||||
/*
|
||||
* all other (large) arguments
|
||||
*/
|
||||
if(ix>=0x7ff00000) { /* x is inf or NaN */
|
||||
y[0]=y[1]=x-x; return 0;
|
||||
}
|
||||
/* set z = scalbn(|x|,ilogb(x)-23) */
|
||||
GET_LOW_WORD(low,x);
|
||||
SET_LOW_WORD(z,low);
|
||||
e0 = (ix>>20)-1046; /* e0 = ilogb(z)-23; */
|
||||
SET_HIGH_WORD(z, ix - ((int32_t)(e0<<20)));
|
||||
for(i=0;i<2;i++) {
|
||||
tx[i] = (double)((int32_t)(z));
|
||||
z = (z-tx[i])*two24;
|
||||
}
|
||||
tx[2] = z;
|
||||
nx = 3;
|
||||
while(tx[nx-1]==zero) nx--; /* skip zero term */
|
||||
n = __kernel_rem_pio2(tx,y,e0,nx,2,two_over_pi);
|
||||
if(hx<0) {y[0] = -y[0]; y[1] = -y[1]; return -n;}
|
||||
return n;
|
||||
}
|
453
platform/gp2x/uClibc/e_sqrt.c
Normal file
453
platform/gp2x/uClibc/e_sqrt.c
Normal file
|
@ -0,0 +1,453 @@
|
|||
/* @(#)e_sqrt.c 5.1 93/09/24 */
|
||||
/*
|
||||
* ====================================================
|
||||
* Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
|
||||
*
|
||||
* Developed at SunPro, a Sun Microsystems, Inc. business.
|
||||
* Permission to use, copy, modify, and distribute this
|
||||
* software is freely granted, provided that this notice
|
||||
* is preserved.
|
||||
* ====================================================
|
||||
*/
|
||||
|
||||
#if defined(LIBM_SCCS) && !defined(lint)
|
||||
static char rcsid[] = "$NetBSD: e_sqrt.c,v 1.8 1995/05/10 20:46:17 jtc Exp $";
|
||||
#endif
|
||||
|
||||
/* __ieee754_sqrt(x)
|
||||
* Return correctly rounded sqrt.
|
||||
* ------------------------------------------
|
||||
* | Use the hardware sqrt if you have one |
|
||||
* ------------------------------------------
|
||||
* Method:
|
||||
* Bit by bit method using integer arithmetic. (Slow, but portable)
|
||||
* 1. Normalization
|
||||
* Scale x to y in [1,4) with even powers of 2:
|
||||
* find an integer k such that 1 <= (y=x*2^(2k)) < 4, then
|
||||
* sqrt(x) = 2^k * sqrt(y)
|
||||
* 2. Bit by bit computation
|
||||
* Let q = sqrt(y) truncated to i bit after binary point (q = 1),
|
||||
* i 0
|
||||
* i+1 2
|
||||
* s = 2*q , and y = 2 * ( y - q ). (1)
|
||||
* i i i i
|
||||
*
|
||||
* To compute q from q , one checks whether
|
||||
* i+1 i
|
||||
*
|
||||
* -(i+1) 2
|
||||
* (q + 2 ) <= y. (2)
|
||||
* i
|
||||
* -(i+1)
|
||||
* If (2) is false, then q = q ; otherwise q = q + 2 .
|
||||
* i+1 i i+1 i
|
||||
*
|
||||
* With some algebric manipulation, it is not difficult to see
|
||||
* that (2) is equivalent to
|
||||
* -(i+1)
|
||||
* s + 2 <= y (3)
|
||||
* i i
|
||||
*
|
||||
* The advantage of (3) is that s and y can be computed by
|
||||
* i i
|
||||
* the following recurrence formula:
|
||||
* if (3) is false
|
||||
*
|
||||
* s = s , y = y ; (4)
|
||||
* i+1 i i+1 i
|
||||
*
|
||||
* otherwise,
|
||||
* -i -(i+1)
|
||||
* s = s + 2 , y = y - s - 2 (5)
|
||||
* i+1 i i+1 i i
|
||||
*
|
||||
* One may easily use induction to prove (4) and (5).
|
||||
* Note. Since the left hand side of (3) contain only i+2 bits,
|
||||
* it does not necessary to do a full (53-bit) comparison
|
||||
* in (3).
|
||||
* 3. Final rounding
|
||||
* After generating the 53 bits result, we compute one more bit.
|
||||
* Together with the remainder, we can decide whether the
|
||||
* result is exact, bigger than 1/2ulp, or less than 1/2ulp
|
||||
* (it will never equal to 1/2ulp).
|
||||
* The rounding mode can be detected by checking whether
|
||||
* huge + tiny is equal to huge, and whether huge - tiny is
|
||||
* equal to huge for some floating point number "huge" and "tiny".
|
||||
*
|
||||
* Special cases:
|
||||
* sqrt(+-0) = +-0 ... exact
|
||||
* sqrt(inf) = inf
|
||||
* sqrt(-ve) = NaN ... with invalid signal
|
||||
* sqrt(NaN) = NaN ... with invalid signal for signaling NaN
|
||||
*
|
||||
* Other methods : see the appended file at the end of the program below.
|
||||
*---------------
|
||||
*/
|
||||
|
||||
#include "math.h"
|
||||
#include "math_private.h"
|
||||
|
||||
#ifdef __STDC__
|
||||
static const double one = 1.0, tiny=1.0e-300;
|
||||
#else
|
||||
static double one = 1.0, tiny=1.0e-300;
|
||||
#endif
|
||||
|
||||
#ifdef __STDC__
|
||||
double __ieee754_sqrt(double x)
|
||||
#else
|
||||
double __ieee754_sqrt(x)
|
||||
double x;
|
||||
#endif
|
||||
{
|
||||
double z;
|
||||
int32_t sign = (int)0x80000000;
|
||||
int32_t ix0,s0,q,m,t,i;
|
||||
u_int32_t r,t1,s1,ix1,q1;
|
||||
|
||||
EXTRACT_WORDS(ix0,ix1,x);
|
||||
|
||||
/* take care of Inf and NaN */
|
||||
if((ix0&0x7ff00000)==0x7ff00000) {
|
||||
return x*x+x; /* sqrt(NaN)=NaN, sqrt(+inf)=+inf
|
||||
sqrt(-inf)=sNaN */
|
||||
}
|
||||
/* take care of zero */
|
||||
if(ix0<=0) {
|
||||
if(((ix0&(~sign))|ix1)==0) return x;/* sqrt(+-0) = +-0 */
|
||||
else if(ix0<0)
|
||||
return (x-x)/(x-x); /* sqrt(-ve) = sNaN */
|
||||
}
|
||||
/* normalize x */
|
||||
m = (ix0>>20);
|
||||
if(m==0) { /* subnormal x */
|
||||
while(ix0==0) {
|
||||
m -= 21;
|
||||
ix0 |= (ix1>>11); ix1 <<= 21;
|
||||
}
|
||||
for(i=0;(ix0&0x00100000)==0;i++) ix0<<=1;
|
||||
m -= i-1;
|
||||
ix0 |= (ix1>>(32-i));
|
||||
ix1 <<= i;
|
||||
}
|
||||
m -= 1023; /* unbias exponent */
|
||||
ix0 = (ix0&0x000fffff)|0x00100000;
|
||||
if(m&1){ /* odd m, double x to make it even */
|
||||
ix0 += ix0 + ((ix1&sign)>>31);
|
||||
ix1 += ix1;
|
||||
}
|
||||
m >>= 1; /* m = [m/2] */
|
||||
|
||||
/* generate sqrt(x) bit by bit */
|
||||
ix0 += ix0 + ((ix1&sign)>>31);
|
||||
ix1 += ix1;
|
||||
q = q1 = s0 = s1 = 0; /* [q,q1] = sqrt(x) */
|
||||
r = 0x00200000; /* r = moving bit from right to left */
|
||||
|
||||
while(r!=0) {
|
||||
t = s0+r;
|
||||
if(t<=ix0) {
|
||||
s0 = t+r;
|
||||
ix0 -= t;
|
||||
q += r;
|
||||
}
|
||||
ix0 += ix0 + ((ix1&sign)>>31);
|
||||
ix1 += ix1;
|
||||
r>>=1;
|
||||
}
|
||||
|
||||
r = sign;
|
||||
while(r!=0) {
|
||||
t1 = s1+r;
|
||||
t = s0;
|
||||
if((t<ix0)||((t==ix0)&&(t1<=ix1))) {
|
||||
s1 = t1+r;
|
||||
if(((t1&sign)==sign)&&(s1&sign)==0) s0 += 1;
|
||||
ix0 -= t;
|
||||
if (ix1 < t1) ix0 -= 1;
|
||||
ix1 -= t1;
|
||||
q1 += r;
|
||||
}
|
||||
ix0 += ix0 + ((ix1&sign)>>31);
|
||||
ix1 += ix1;
|
||||
r>>=1;
|
||||
}
|
||||
|
||||
/* use floating add to find out rounding direction */
|
||||
if((ix0|ix1)!=0) {
|
||||
z = one-tiny; /* trigger inexact flag */
|
||||
if (z>=one) {
|
||||
z = one+tiny;
|
||||
if (q1==(u_int32_t)0xffffffff) { q1=0; q += 1;}
|
||||
else if (z>one) {
|
||||
if (q1==(u_int32_t)0xfffffffe) q+=1;
|
||||
q1+=2;
|
||||
} else
|
||||
q1 += (q1&1);
|
||||
}
|
||||
}
|
||||
ix0 = (q>>1)+0x3fe00000;
|
||||
ix1 = q1>>1;
|
||||
if ((q&1)==1) ix1 |= sign;
|
||||
ix0 += (m <<20);
|
||||
INSERT_WORDS(z,ix0,ix1);
|
||||
return z;
|
||||
}
|
||||
|
||||
/*
|
||||
Other methods (use floating-point arithmetic)
|
||||
-------------
|
||||
(This is a copy of a drafted paper by Prof W. Kahan
|
||||
and K.C. Ng, written in May, 1986)
|
||||
|
||||
Two algorithms are given here to implement sqrt(x)
|
||||
(IEEE double precision arithmetic) in software.
|
||||
Both supply sqrt(x) correctly rounded. The first algorithm (in
|
||||
Section A) uses newton iterations and involves four divisions.
|
||||
The second one uses reciproot iterations to avoid division, but
|
||||
requires more multiplications. Both algorithms need the ability
|
||||
to chop results of arithmetic operations instead of round them,
|
||||
and the INEXACT flag to indicate when an arithmetic operation
|
||||
is executed exactly with no roundoff error, all part of the
|
||||
standard (IEEE 754-1985). The ability to perform shift, add,
|
||||
subtract and logical AND operations upon 32-bit words is needed
|
||||
too, though not part of the standard.
|
||||
|
||||
A. sqrt(x) by Newton Iteration
|
||||
|
||||
(1) Initial approximation
|
||||
|
||||
Let x0 and x1 be the leading and the trailing 32-bit words of
|
||||
a floating point number x (in IEEE double format) respectively
|
||||
|
||||
1 11 52 ...widths
|
||||
------------------------------------------------------
|
||||
x: |s| e | f |
|
||||
------------------------------------------------------
|
||||
msb lsb msb lsb ...order
|
||||
|
||||
|
||||
------------------------ ------------------------
|
||||
x0: |s| e | f1 | x1: | f2 |
|
||||
------------------------ ------------------------
|
||||
|
||||
By performing shifts and subtracts on x0 and x1 (both regarded
|
||||
as integers), we obtain an 8-bit approximation of sqrt(x) as
|
||||
follows.
|
||||
|
||||
k := (x0>>1) + 0x1ff80000;
|
||||
y0 := k - T1[31&(k>>15)]. ... y ~ sqrt(x) to 8 bits
|
||||
Here k is a 32-bit integer and T1[] is an integer array containing
|
||||
correction terms. Now magically the floating value of y (y's
|
||||
leading 32-bit word is y0, the value of its trailing word is 0)
|
||||
approximates sqrt(x) to almost 8-bit.
|
||||
|
||||
Value of T1:
|
||||
static int T1[32]= {
|
||||
0, 1024, 3062, 5746, 9193, 13348, 18162, 23592,
|
||||
29598, 36145, 43202, 50740, 58733, 67158, 75992, 85215,
|
||||
83599, 71378, 60428, 50647, 41945, 34246, 27478, 21581,
|
||||
16499, 12183, 8588, 5674, 3403, 1742, 661, 130,};
|
||||
|
||||
(2) Iterative refinement
|
||||
|
||||
Apply Heron's rule three times to y, we have y approximates
|
||||
sqrt(x) to within 1 ulp (Unit in the Last Place):
|
||||
|
||||
y := (y+x/y)/2 ... almost 17 sig. bits
|
||||
y := (y+x/y)/2 ... almost 35 sig. bits
|
||||
y := y-(y-x/y)/2 ... within 1 ulp
|
||||
|
||||
|
||||
Remark 1.
|
||||
Another way to improve y to within 1 ulp is:
|
||||
|
||||
y := (y+x/y) ... almost 17 sig. bits to 2*sqrt(x)
|
||||
y := y - 0x00100006 ... almost 18 sig. bits to sqrt(x)
|
||||
|
||||
2
|
||||
(x-y )*y
|
||||
y := y + 2* ---------- ...within 1 ulp
|
||||
2
|
||||
3y + x
|
||||
|
||||
|
||||
This formula has one division fewer than the one above; however,
|
||||
it requires more multiplications and additions. Also x must be
|
||||
scaled in advance to avoid spurious overflow in evaluating the
|
||||
expression 3y*y+x. Hence it is not recommended uless division
|
||||
is slow. If division is very slow, then one should use the
|
||||
reciproot algorithm given in section B.
|
||||
|
||||
(3) Final adjustment
|
||||
|
||||
By twiddling y's last bit it is possible to force y to be
|
||||
correctly rounded according to the prevailing rounding mode
|
||||
as follows. Let r and i be copies of the rounding mode and
|
||||
inexact flag before entering the square root program. Also we
|
||||
use the expression y+-ulp for the next representable floating
|
||||
numbers (up and down) of y. Note that y+-ulp = either fixed
|
||||
point y+-1, or multiply y by nextafter(1,+-inf) in chopped
|
||||
mode.
|
||||
|
||||
I := FALSE; ... reset INEXACT flag I
|
||||
R := RZ; ... set rounding mode to round-toward-zero
|
||||
z := x/y; ... chopped quotient, possibly inexact
|
||||
If(not I) then { ... if the quotient is exact
|
||||
if(z=y) {
|
||||
I := i; ... restore inexact flag
|
||||
R := r; ... restore rounded mode
|
||||
return sqrt(x):=y.
|
||||
} else {
|
||||
z := z - ulp; ... special rounding
|
||||
}
|
||||
}
|
||||
i := TRUE; ... sqrt(x) is inexact
|
||||
If (r=RN) then z=z+ulp ... rounded-to-nearest
|
||||
If (r=RP) then { ... round-toward-+inf
|
||||
y = y+ulp; z=z+ulp;
|
||||
}
|
||||
y := y+z; ... chopped sum
|
||||
y0:=y0-0x00100000; ... y := y/2 is correctly rounded.
|
||||
I := i; ... restore inexact flag
|
||||
R := r; ... restore rounded mode
|
||||
return sqrt(x):=y.
|
||||
|
||||
(4) Special cases
|
||||
|
||||
Square root of +inf, +-0, or NaN is itself;
|
||||
Square root of a negative number is NaN with invalid signal.
|
||||
|
||||
|
||||
B. sqrt(x) by Reciproot Iteration
|
||||
|
||||
(1) Initial approximation
|
||||
|
||||
Let x0 and x1 be the leading and the trailing 32-bit words of
|
||||
a floating point number x (in IEEE double format) respectively
|
||||
(see section A). By performing shifs and subtracts on x0 and y0,
|
||||
we obtain a 7.8-bit approximation of 1/sqrt(x) as follows.
|
||||
|
||||
k := 0x5fe80000 - (x0>>1);
|
||||
y0:= k - T2[63&(k>>14)]. ... y ~ 1/sqrt(x) to 7.8 bits
|
||||
|
||||
Here k is a 32-bit integer and T2[] is an integer array
|
||||
containing correction terms. Now magically the floating
|
||||
value of y (y's leading 32-bit word is y0, the value of
|
||||
its trailing word y1 is set to zero) approximates 1/sqrt(x)
|
||||
to almost 7.8-bit.
|
||||
|
||||
Value of T2:
|
||||
static int T2[64]= {
|
||||
0x1500, 0x2ef8, 0x4d67, 0x6b02, 0x87be, 0xa395, 0xbe7a, 0xd866,
|
||||
0xf14a, 0x1091b,0x11fcd,0x13552,0x14999,0x15c98,0x16e34,0x17e5f,
|
||||
0x18d03,0x19a01,0x1a545,0x1ae8a,0x1b5c4,0x1bb01,0x1bfde,0x1c28d,
|
||||
0x1c2de,0x1c0db,0x1ba73,0x1b11c,0x1a4b5,0x1953d,0x18266,0x16be0,
|
||||
0x1683e,0x179d8,0x18a4d,0x19992,0x1a789,0x1b445,0x1bf61,0x1c989,
|
||||
0x1d16d,0x1d77b,0x1dddf,0x1e2ad,0x1e5bf,0x1e6e8,0x1e654,0x1e3cd,
|
||||
0x1df2a,0x1d635,0x1cb16,0x1be2c,0x1ae4e,0x19bde,0x1868e,0x16e2e,
|
||||
0x1527f,0x1334a,0x11051,0xe951, 0xbe01, 0x8e0d, 0x5924, 0x1edd,};
|
||||
|
||||
(2) Iterative refinement
|
||||
|
||||
Apply Reciproot iteration three times to y and multiply the
|
||||
result by x to get an approximation z that matches sqrt(x)
|
||||
to about 1 ulp. To be exact, we will have
|
||||
-1ulp < sqrt(x)-z<1.0625ulp.
|
||||
|
||||
... set rounding mode to Round-to-nearest
|
||||
y := y*(1.5-0.5*x*y*y) ... almost 15 sig. bits to 1/sqrt(x)
|
||||
y := y*((1.5-2^-30)+0.5*x*y*y)... about 29 sig. bits to 1/sqrt(x)
|
||||
... special arrangement for better accuracy
|
||||
z := x*y ... 29 bits to sqrt(x), with z*y<1
|
||||
z := z + 0.5*z*(1-z*y) ... about 1 ulp to sqrt(x)
|
||||
|
||||
Remark 2. The constant 1.5-2^-30 is chosen to bias the error so that
|
||||
(a) the term z*y in the final iteration is always less than 1;
|
||||
(b) the error in the final result is biased upward so that
|
||||
-1 ulp < sqrt(x) - z < 1.0625 ulp
|
||||
instead of |sqrt(x)-z|<1.03125ulp.
|
||||
|
||||
(3) Final adjustment
|
||||
|
||||
By twiddling y's last bit it is possible to force y to be
|
||||
correctly rounded according to the prevailing rounding mode
|
||||
as follows. Let r and i be copies of the rounding mode and
|
||||
inexact flag before entering the square root program. Also we
|
||||
use the expression y+-ulp for the next representable floating
|
||||
numbers (up and down) of y. Note that y+-ulp = either fixed
|
||||
point y+-1, or multiply y by nextafter(1,+-inf) in chopped
|
||||
mode.
|
||||
|
||||
R := RZ; ... set rounding mode to round-toward-zero
|
||||
switch(r) {
|
||||
case RN: ... round-to-nearest
|
||||
if(x<= z*(z-ulp)...chopped) z = z - ulp; else
|
||||
if(x<= z*(z+ulp)...chopped) z = z; else z = z+ulp;
|
||||
break;
|
||||
case RZ:case RM: ... round-to-zero or round-to--inf
|
||||
R:=RP; ... reset rounding mod to round-to-+inf
|
||||
if(x<z*z ... rounded up) z = z - ulp; else
|
||||
if(x>=(z+ulp)*(z+ulp) ...rounded up) z = z+ulp;
|
||||
break;
|
||||
case RP: ... round-to-+inf
|
||||
if(x>(z+ulp)*(z+ulp)...chopped) z = z+2*ulp; else
|
||||
if(x>z*z ...chopped) z = z+ulp;
|
||||
break;
|
||||
}
|
||||
|
||||
Remark 3. The above comparisons can be done in fixed point. For
|
||||
example, to compare x and w=z*z chopped, it suffices to compare
|
||||
x1 and w1 (the trailing parts of x and w), regarding them as
|
||||
two's complement integers.
|
||||
|
||||
...Is z an exact square root?
|
||||
To determine whether z is an exact square root of x, let z1 be the
|
||||
trailing part of z, and also let x0 and x1 be the leading and
|
||||
trailing parts of x.
|
||||
|
||||
If ((z1&0x03ffffff)!=0) ... not exact if trailing 26 bits of z!=0
|
||||
I := 1; ... Raise Inexact flag: z is not exact
|
||||
else {
|
||||
j := 1 - [(x0>>20)&1] ... j = logb(x) mod 2
|
||||
k := z1 >> 26; ... get z's 25-th and 26-th
|
||||
fraction bits
|
||||
I := i or (k&j) or ((k&(j+j+1))!=(x1&3));
|
||||
}
|
||||
R:= r ... restore rounded mode
|
||||
return sqrt(x):=z.
|
||||
|
||||
If multiplication is cheaper then the foregoing red tape, the
|
||||
Inexact flag can be evaluated by
|
||||
|
||||
I := i;
|
||||
I := (z*z!=x) or I.
|
||||
|
||||
Note that z*z can overwrite I; this value must be sensed if it is
|
||||
True.
|
||||
|
||||
Remark 4. If z*z = x exactly, then bit 25 to bit 0 of z1 must be
|
||||
zero.
|
||||
|
||||
--------------------
|
||||
z1: | f2 |
|
||||
--------------------
|
||||
bit 31 bit 0
|
||||
|
||||
Further more, bit 27 and 26 of z1, bit 0 and 1 of x1, and the odd
|
||||
or even of logb(x) have the following relations:
|
||||
|
||||
-------------------------------------------------
|
||||
bit 27,26 of z1 bit 1,0 of x1 logb(x)
|
||||
-------------------------------------------------
|
||||
00 00 odd and even
|
||||
01 01 even
|
||||
10 10 odd
|
||||
10 00 even
|
||||
11 01 even
|
||||
-------------------------------------------------
|
||||
|
||||
(4) Special cases (see (4) of Section A).
|
||||
|
||||
*/
|
||||
|
96
platform/gp2x/uClibc/k_cos.c
Normal file
96
platform/gp2x/uClibc/k_cos.c
Normal file
|
@ -0,0 +1,96 @@
|
|||
/* @(#)k_cos.c 5.1 93/09/24 */
|
||||
/*
|
||||
* ====================================================
|
||||
* Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
|
||||
*
|
||||
* Developed at SunPro, a Sun Microsystems, Inc. business.
|
||||
* Permission to use, copy, modify, and distribute this
|
||||
* software is freely granted, provided that this notice
|
||||
* is preserved.
|
||||
* ====================================================
|
||||
*/
|
||||
|
||||
#if defined(LIBM_SCCS) && !defined(lint)
|
||||
static char rcsid[] = "$NetBSD: k_cos.c,v 1.8 1995/05/10 20:46:22 jtc Exp $";
|
||||
#endif
|
||||
|
||||
/*
|
||||
* __kernel_cos( x, y )
|
||||
* kernel cos function on [-pi/4, pi/4], pi/4 ~ 0.785398164
|
||||
* Input x is assumed to be bounded by ~pi/4 in magnitude.
|
||||
* Input y is the tail of x.
|
||||
*
|
||||
* Algorithm
|
||||
* 1. Since cos(-x) = cos(x), we need only to consider positive x.
|
||||
* 2. if x < 2^-27 (hx<0x3e400000 0), return 1 with inexact if x!=0.
|
||||
* 3. cos(x) is approximated by a polynomial of degree 14 on
|
||||
* [0,pi/4]
|
||||
* 4 14
|
||||
* cos(x) ~ 1 - x*x/2 + C1*x + ... + C6*x
|
||||
* where the remez error is
|
||||
*
|
||||
* | 2 4 6 8 10 12 14 | -58
|
||||
* |cos(x)-(1-.5*x +C1*x +C2*x +C3*x +C4*x +C5*x +C6*x )| <= 2
|
||||
* | |
|
||||
*
|
||||
* 4 6 8 10 12 14
|
||||
* 4. let r = C1*x +C2*x +C3*x +C4*x +C5*x +C6*x , then
|
||||
* cos(x) = 1 - x*x/2 + r
|
||||
* since cos(x+y) ~ cos(x) - sin(x)*y
|
||||
* ~ cos(x) - x*y,
|
||||
* a correction term is necessary in cos(x) and hence
|
||||
* cos(x+y) = 1 - (x*x/2 - (r - x*y))
|
||||
* For better accuracy when x > 0.3, let qx = |x|/4 with
|
||||
* the last 32 bits mask off, and if x > 0.78125, let qx = 0.28125.
|
||||
* Then
|
||||
* cos(x+y) = (1-qx) - ((x*x/2-qx) - (r-x*y)).
|
||||
* Note that 1-qx and (x*x/2-qx) is EXACT here, and the
|
||||
* magnitude of the latter is at least a quarter of x*x/2,
|
||||
* thus, reducing the rounding error in the subtraction.
|
||||
*/
|
||||
|
||||
#include "math.h"
|
||||
#include "math_private.h"
|
||||
|
||||
#ifdef __STDC__
|
||||
static const double
|
||||
#else
|
||||
static double
|
||||
#endif
|
||||
one = 1.00000000000000000000e+00, /* 0x3FF00000, 0x00000000 */
|
||||
C1 = 4.16666666666666019037e-02, /* 0x3FA55555, 0x5555554C */
|
||||
C2 = -1.38888888888741095749e-03, /* 0xBF56C16C, 0x16C15177 */
|
||||
C3 = 2.48015872894767294178e-05, /* 0x3EFA01A0, 0x19CB1590 */
|
||||
C4 = -2.75573143513906633035e-07, /* 0xBE927E4F, 0x809C52AD */
|
||||
C5 = 2.08757232129817482790e-09, /* 0x3E21EE9E, 0xBDB4B1C4 */
|
||||
C6 = -1.13596475577881948265e-11; /* 0xBDA8FAE9, 0xBE8838D4 */
|
||||
|
||||
#ifdef __STDC__
|
||||
double __kernel_cos(double x, double y)
|
||||
#else
|
||||
double __kernel_cos(x, y)
|
||||
double x,y;
|
||||
#endif
|
||||
{
|
||||
double a,hz,z,r,qx;
|
||||
int32_t ix;
|
||||
GET_HIGH_WORD(ix,x);
|
||||
ix &= 0x7fffffff; /* ix = |x|'s high word*/
|
||||
if(ix<0x3e400000) { /* if x < 2**27 */
|
||||
if(((int)x)==0) return one; /* generate inexact */
|
||||
}
|
||||
z = x*x;
|
||||
r = z*(C1+z*(C2+z*(C3+z*(C4+z*(C5+z*C6)))));
|
||||
if(ix < 0x3FD33333) /* if |x| < 0.3 */
|
||||
return one - (0.5*z - (z*r - x*y));
|
||||
else {
|
||||
if(ix > 0x3fe90000) { /* x > 0.78125 */
|
||||
qx = 0.28125;
|
||||
} else {
|
||||
INSERT_WORDS(qx,ix-0x00200000,0); /* x/4 */
|
||||
}
|
||||
hz = 0.5*z-qx;
|
||||
a = one-qx;
|
||||
return a - (hz - (z*r-x*y));
|
||||
}
|
||||
}
|
320
platform/gp2x/uClibc/k_rem_pio2.c
Normal file
320
platform/gp2x/uClibc/k_rem_pio2.c
Normal file
|
@ -0,0 +1,320 @@
|
|||
/* @(#)k_rem_pio2.c 5.1 93/09/24 */
|
||||
/*
|
||||
* ====================================================
|
||||
* Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
|
||||
*
|
||||
* Developed at SunPro, a Sun Microsystems, Inc. business.
|
||||
* Permission to use, copy, modify, and distribute this
|
||||
* software is freely granted, provided that this notice
|
||||
* is preserved.
|
||||
* ====================================================
|
||||
*/
|
||||
|
||||
#if defined(LIBM_SCCS) && !defined(lint)
|
||||
static char rcsid[] = "$NetBSD: k_rem_pio2.c,v 1.7 1995/05/10 20:46:25 jtc Exp $";
|
||||
#endif
|
||||
|
||||
/*
|
||||
* __kernel_rem_pio2(x,y,e0,nx,prec,ipio2)
|
||||
* double x[],y[]; int e0,nx,prec; int ipio2[];
|
||||
*
|
||||
* __kernel_rem_pio2 return the last three digits of N with
|
||||
* y = x - N*pi/2
|
||||
* so that |y| < pi/2.
|
||||
*
|
||||
* The method is to compute the integer (mod 8) and fraction parts of
|
||||
* (2/pi)*x without doing the full multiplication. In general we
|
||||
* skip the part of the product that are known to be a huge integer (
|
||||
* more accurately, = 0 mod 8 ). Thus the number of operations are
|
||||
* independent of the exponent of the input.
|
||||
*
|
||||
* (2/pi) is represented by an array of 24-bit integers in ipio2[].
|
||||
*
|
||||
* Input parameters:
|
||||
* x[] The input value (must be positive) is broken into nx
|
||||
* pieces of 24-bit integers in double precision format.
|
||||
* x[i] will be the i-th 24 bit of x. The scaled exponent
|
||||
* of x[0] is given in input parameter e0 (i.e., x[0]*2^e0
|
||||
* match x's up to 24 bits.
|
||||
*
|
||||
* Example of breaking a double positive z into x[0]+x[1]+x[2]:
|
||||
* e0 = ilogb(z)-23
|
||||
* z = scalbn(z,-e0)
|
||||
* for i = 0,1,2
|
||||
* x[i] = floor(z)
|
||||
* z = (z-x[i])*2**24
|
||||
*
|
||||
*
|
||||
* y[] ouput result in an array of double precision numbers.
|
||||
* The dimension of y[] is:
|
||||
* 24-bit precision 1
|
||||
* 53-bit precision 2
|
||||
* 64-bit precision 2
|
||||
* 113-bit precision 3
|
||||
* The actual value is the sum of them. Thus for 113-bit
|
||||
* precison, one may have to do something like:
|
||||
*
|
||||
* long double t,w,r_head, r_tail;
|
||||
* t = (long double)y[2] + (long double)y[1];
|
||||
* w = (long double)y[0];
|
||||
* r_head = t+w;
|
||||
* r_tail = w - (r_head - t);
|
||||
*
|
||||
* e0 The exponent of x[0]
|
||||
*
|
||||
* nx dimension of x[]
|
||||
*
|
||||
* prec an integer indicating the precision:
|
||||
* 0 24 bits (single)
|
||||
* 1 53 bits (double)
|
||||
* 2 64 bits (extended)
|
||||
* 3 113 bits (quad)
|
||||
*
|
||||
* ipio2[]
|
||||
* integer array, contains the (24*i)-th to (24*i+23)-th
|
||||
* bit of 2/pi after binary point. The corresponding
|
||||
* floating value is
|
||||
*
|
||||
* ipio2[i] * 2^(-24(i+1)).
|
||||
*
|
||||
* External function:
|
||||
* double scalbn(), floor();
|
||||
*
|
||||
*
|
||||
* Here is the description of some local variables:
|
||||
*
|
||||
* jk jk+1 is the initial number of terms of ipio2[] needed
|
||||
* in the computation. The recommended value is 2,3,4,
|
||||
* 6 for single, double, extended,and quad.
|
||||
*
|
||||
* jz local integer variable indicating the number of
|
||||
* terms of ipio2[] used.
|
||||
*
|
||||
* jx nx - 1
|
||||
*
|
||||
* jv index for pointing to the suitable ipio2[] for the
|
||||
* computation. In general, we want
|
||||
* ( 2^e0*x[0] * ipio2[jv-1]*2^(-24jv) )/8
|
||||
* is an integer. Thus
|
||||
* e0-3-24*jv >= 0 or (e0-3)/24 >= jv
|
||||
* Hence jv = max(0,(e0-3)/24).
|
||||
*
|
||||
* jp jp+1 is the number of terms in PIo2[] needed, jp = jk.
|
||||
*
|
||||
* q[] double array with integral value, representing the
|
||||
* 24-bits chunk of the product of x and 2/pi.
|
||||
*
|
||||
* q0 the corresponding exponent of q[0]. Note that the
|
||||
* exponent for q[i] would be q0-24*i.
|
||||
*
|
||||
* PIo2[] double precision array, obtained by cutting pi/2
|
||||
* into 24 bits chunks.
|
||||
*
|
||||
* f[] ipio2[] in floating point
|
||||
*
|
||||
* iq[] integer array by breaking up q[] in 24-bits chunk.
|
||||
*
|
||||
* fq[] final product of x*(2/pi) in fq[0],..,fq[jk]
|
||||
*
|
||||
* ih integer. If >0 it indicates q[] is >= 0.5, hence
|
||||
* it also indicates the *sign* of the result.
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
/*
|
||||
* Constants:
|
||||
* The hexadecimal values are the intended ones for the following
|
||||
* constants. The decimal values may be used, provided that the
|
||||
* compiler will convert from decimal to binary accurately enough
|
||||
* to produce the hexadecimal values shown.
|
||||
*/
|
||||
|
||||
#include "math.h"
|
||||
#include "math_private.h"
|
||||
|
||||
#ifdef __STDC__
|
||||
static const int init_jk[] = {2,3,4,6}; /* initial value for jk */
|
||||
#else
|
||||
static int init_jk[] = {2,3,4,6};
|
||||
#endif
|
||||
|
||||
#ifdef __STDC__
|
||||
static const double PIo2[] = {
|
||||
#else
|
||||
static double PIo2[] = {
|
||||
#endif
|
||||
1.57079625129699707031e+00, /* 0x3FF921FB, 0x40000000 */
|
||||
7.54978941586159635335e-08, /* 0x3E74442D, 0x00000000 */
|
||||
5.39030252995776476554e-15, /* 0x3CF84698, 0x80000000 */
|
||||
3.28200341580791294123e-22, /* 0x3B78CC51, 0x60000000 */
|
||||
1.27065575308067607349e-29, /* 0x39F01B83, 0x80000000 */
|
||||
1.22933308981111328932e-36, /* 0x387A2520, 0x40000000 */
|
||||
2.73370053816464559624e-44, /* 0x36E38222, 0x80000000 */
|
||||
2.16741683877804819444e-51, /* 0x3569F31D, 0x00000000 */
|
||||
};
|
||||
|
||||
#ifdef __STDC__
|
||||
static const double
|
||||
#else
|
||||
static double
|
||||
#endif
|
||||
zero = 0.0,
|
||||
one = 1.0,
|
||||
two24 = 1.67772160000000000000e+07, /* 0x41700000, 0x00000000 */
|
||||
twon24 = 5.96046447753906250000e-08; /* 0x3E700000, 0x00000000 */
|
||||
|
||||
#ifdef __STDC__
|
||||
int __kernel_rem_pio2(double *x, double *y, int e0, int nx, int prec, const int32_t *ipio2)
|
||||
#else
|
||||
int __kernel_rem_pio2(x,y,e0,nx,prec,ipio2)
|
||||
double x[], y[]; int e0,nx,prec; int32_t ipio2[];
|
||||
#endif
|
||||
{
|
||||
int32_t jz,jx,jv,jp,jk,carry,n,iq[20],i,j,k,m,q0,ih;
|
||||
double z,fw,f[20],fq[20],q[20];
|
||||
|
||||
/* initialize jk*/
|
||||
jk = init_jk[prec];
|
||||
jp = jk;
|
||||
|
||||
/* determine jx,jv,q0, note that 3>q0 */
|
||||
jx = nx-1;
|
||||
jv = (e0-3)/24; if(jv<0) jv=0;
|
||||
q0 = e0-24*(jv+1);
|
||||
|
||||
/* set up f[0] to f[jx+jk] where f[jx+jk] = ipio2[jv+jk] */
|
||||
j = jv-jx; m = jx+jk;
|
||||
for(i=0;i<=m;i++,j++) f[i] = (j<0)? zero : (double) ipio2[j];
|
||||
|
||||
/* compute q[0],q[1],...q[jk] */
|
||||
for (i=0;i<=jk;i++) {
|
||||
for(j=0,fw=0.0;j<=jx;j++) fw += x[j]*f[jx+i-j]; q[i] = fw;
|
||||
}
|
||||
|
||||
jz = jk;
|
||||
recompute:
|
||||
/* distill q[] into iq[] reversingly */
|
||||
for(i=0,j=jz,z=q[jz];j>0;i++,j--) {
|
||||
fw = (double)((int32_t)(twon24* z));
|
||||
iq[i] = (int32_t)(z-two24*fw);
|
||||
z = q[j-1]+fw;
|
||||
}
|
||||
|
||||
/* compute n */
|
||||
z = scalbn(z,q0); /* actual value of z */
|
||||
z -= 8.0*floor(z*0.125); /* trim off integer >= 8 */
|
||||
n = (int32_t) z;
|
||||
z -= (double)n;
|
||||
ih = 0;
|
||||
if(q0>0) { /* need iq[jz-1] to determine n */
|
||||
i = (iq[jz-1]>>(24-q0)); n += i;
|
||||
iq[jz-1] -= i<<(24-q0);
|
||||
ih = iq[jz-1]>>(23-q0);
|
||||
}
|
||||
else if(q0==0) ih = iq[jz-1]>>23;
|
||||
else if(z>=0.5) ih=2;
|
||||
|
||||
if(ih>0) { /* q > 0.5 */
|
||||
n += 1; carry = 0;
|
||||
for(i=0;i<jz ;i++) { /* compute 1-q */
|
||||
j = iq[i];
|
||||
if(carry==0) {
|
||||
if(j!=0) {
|
||||
carry = 1; iq[i] = 0x1000000- j;
|
||||
}
|
||||
} else iq[i] = 0xffffff - j;
|
||||
}
|
||||
if(q0>0) { /* rare case: chance is 1 in 12 */
|
||||
switch(q0) {
|
||||
case 1:
|
||||
iq[jz-1] &= 0x7fffff; break;
|
||||
case 2:
|
||||
iq[jz-1] &= 0x3fffff; break;
|
||||
}
|
||||
}
|
||||
if(ih==2) {
|
||||
z = one - z;
|
||||
if(carry!=0) z -= scalbn(one,q0);
|
||||
}
|
||||
}
|
||||
|
||||
/* check if recomputation is needed */
|
||||
if(z==zero) {
|
||||
j = 0;
|
||||
for (i=jz-1;i>=jk;i--) j |= iq[i];
|
||||
if(j==0) { /* need recomputation */
|
||||
for(k=1;iq[jk-k]==0;k++); /* k = no. of terms needed */
|
||||
|
||||
for(i=jz+1;i<=jz+k;i++) { /* add q[jz+1] to q[jz+k] */
|
||||
f[jx+i] = (double) ipio2[jv+i];
|
||||
for(j=0,fw=0.0;j<=jx;j++) fw += x[j]*f[jx+i-j];
|
||||
q[i] = fw;
|
||||
}
|
||||
jz += k;
|
||||
goto recompute;
|
||||
}
|
||||
}
|
||||
|
||||
/* chop off zero terms */
|
||||
if(z==0.0) {
|
||||
jz -= 1; q0 -= 24;
|
||||
while(iq[jz]==0) { jz--; q0-=24;}
|
||||
} else { /* break z into 24-bit if necessary */
|
||||
z = scalbn(z,-q0);
|
||||
if(z>=two24) {
|
||||
fw = (double)((int32_t)(twon24*z));
|
||||
iq[jz] = (int32_t)(z-two24*fw);
|
||||
jz += 1; q0 += 24;
|
||||
iq[jz] = (int32_t) fw;
|
||||
} else iq[jz] = (int32_t) z ;
|
||||
}
|
||||
|
||||
/* convert integer "bit" chunk to floating-point value */
|
||||
fw = scalbn(one,q0);
|
||||
for(i=jz;i>=0;i--) {
|
||||
q[i] = fw*(double)iq[i]; fw*=twon24;
|
||||
}
|
||||
|
||||
/* compute PIo2[0,...,jp]*q[jz,...,0] */
|
||||
for(i=jz;i>=0;i--) {
|
||||
for(fw=0.0,k=0;k<=jp&&k<=jz-i;k++) fw += PIo2[k]*q[i+k];
|
||||
fq[jz-i] = fw;
|
||||
}
|
||||
|
||||
/* compress fq[] into y[] */
|
||||
switch(prec) {
|
||||
case 0:
|
||||
fw = 0.0;
|
||||
for (i=jz;i>=0;i--) fw += fq[i];
|
||||
y[0] = (ih==0)? fw: -fw;
|
||||
break;
|
||||
case 1:
|
||||
case 2:
|
||||
fw = 0.0;
|
||||
for (i=jz;i>=0;i--) fw += fq[i];
|
||||
y[0] = (ih==0)? fw: -fw;
|
||||
fw = fq[0]-fw;
|
||||
for (i=1;i<=jz;i++) fw += fq[i];
|
||||
y[1] = (ih==0)? fw: -fw;
|
||||
break;
|
||||
case 3: /* painful */
|
||||
for (i=jz;i>0;i--) {
|
||||
fw = fq[i-1]+fq[i];
|
||||
fq[i] += fq[i-1]-fw;
|
||||
fq[i-1] = fw;
|
||||
}
|
||||
for (i=jz;i>1;i--) {
|
||||
fw = fq[i-1]+fq[i];
|
||||
fq[i] += fq[i-1]-fw;
|
||||
fq[i-1] = fw;
|
||||
}
|
||||
for (fw=0.0,i=jz;i>=2;i--) fw += fq[i];
|
||||
if(ih==0) {
|
||||
y[0] = fq[0]; y[1] = fq[1]; y[2] = fw;
|
||||
} else {
|
||||
y[0] = -fq[0]; y[1] = -fq[1]; y[2] = -fw;
|
||||
}
|
||||
}
|
||||
return n&7;
|
||||
}
|
79
platform/gp2x/uClibc/k_sin.c
Normal file
79
platform/gp2x/uClibc/k_sin.c
Normal file
|
@ -0,0 +1,79 @@
|
|||
/* @(#)k_sin.c 5.1 93/09/24 */
|
||||
/*
|
||||
* ====================================================
|
||||
* Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
|
||||
*
|
||||
* Developed at SunPro, a Sun Microsystems, Inc. business.
|
||||
* Permission to use, copy, modify, and distribute this
|
||||
* software is freely granted, provided that this notice
|
||||
* is preserved.
|
||||
* ====================================================
|
||||
*/
|
||||
|
||||
#if defined(LIBM_SCCS) && !defined(lint)
|
||||
static char rcsid[] = "$NetBSD: k_sin.c,v 1.8 1995/05/10 20:46:31 jtc Exp $";
|
||||
#endif
|
||||
|
||||
/* __kernel_sin( x, y, iy)
|
||||
* kernel sin function on [-pi/4, pi/4], pi/4 ~ 0.7854
|
||||
* Input x is assumed to be bounded by ~pi/4 in magnitude.
|
||||
* Input y is the tail of x.
|
||||
* Input iy indicates whether y is 0. (if iy=0, y assume to be 0).
|
||||
*
|
||||
* Algorithm
|
||||
* 1. Since sin(-x) = -sin(x), we need only to consider positive x.
|
||||
* 2. if x < 2^-27 (hx<0x3e400000 0), return x with inexact if x!=0.
|
||||
* 3. sin(x) is approximated by a polynomial of degree 13 on
|
||||
* [0,pi/4]
|
||||
* 3 13
|
||||
* sin(x) ~ x + S1*x + ... + S6*x
|
||||
* where
|
||||
*
|
||||
* |sin(x) 2 4 6 8 10 12 | -58
|
||||
* |----- - (1+S1*x +S2*x +S3*x +S4*x +S5*x +S6*x )| <= 2
|
||||
* | x |
|
||||
*
|
||||
* 4. sin(x+y) = sin(x) + sin'(x')*y
|
||||
* ~ sin(x) + (1-x*x/2)*y
|
||||
* For better accuracy, let
|
||||
* 3 2 2 2 2
|
||||
* r = x *(S2+x *(S3+x *(S4+x *(S5+x *S6))))
|
||||
* then 3 2
|
||||
* sin(x) = x + (S1*x + (x *(r-y/2)+y))
|
||||
*/
|
||||
|
||||
#include "math.h"
|
||||
#include "math_private.h"
|
||||
|
||||
#ifdef __STDC__
|
||||
static const double
|
||||
#else
|
||||
static double
|
||||
#endif
|
||||
half = 5.00000000000000000000e-01, /* 0x3FE00000, 0x00000000 */
|
||||
S1 = -1.66666666666666324348e-01, /* 0xBFC55555, 0x55555549 */
|
||||
S2 = 8.33333333332248946124e-03, /* 0x3F811111, 0x1110F8A6 */
|
||||
S3 = -1.98412698298579493134e-04, /* 0xBF2A01A0, 0x19C161D5 */
|
||||
S4 = 2.75573137070700676789e-06, /* 0x3EC71DE3, 0x57B1FE7D */
|
||||
S5 = -2.50507602534068634195e-08, /* 0xBE5AE5E6, 0x8A2B9CEB */
|
||||
S6 = 1.58969099521155010221e-10; /* 0x3DE5D93A, 0x5ACFD57C */
|
||||
|
||||
#ifdef __STDC__
|
||||
double __kernel_sin(double x, double y, int iy)
|
||||
#else
|
||||
double __kernel_sin(x, y, iy)
|
||||
double x,y; int iy; /* iy=0 if y is zero */
|
||||
#endif
|
||||
{
|
||||
double z,r,v;
|
||||
int32_t ix;
|
||||
GET_HIGH_WORD(ix,x);
|
||||
ix &= 0x7fffffff; /* high word of x */
|
||||
if(ix<0x3e400000) /* |x| < 2**-27 */
|
||||
{if((int)x==0) return x;} /* generate inexact */
|
||||
z = x*x;
|
||||
v = z*x;
|
||||
r = S2+z*(S3+z*(S4+z*(S5+z*S6)));
|
||||
if(iy==0) return x+v*(S1+z*r);
|
||||
else return x-((z*(half*y-v*r)-y)-v*S1);
|
||||
}
|
15
platform/gp2x/uClibc/math.h
Normal file
15
platform/gp2x/uClibc/math.h
Normal file
|
@ -0,0 +1,15 @@
|
|||
#include <sys/types.h>
|
||||
|
||||
int __kernel_rem_pio2(double *x, double *y, int e0, int nx, int prec, const int32_t *ipio2);
|
||||
double __kernel_sin(double x, double y, int iy);
|
||||
double __kernel_cos(double x, double y);
|
||||
|
||||
double __ieee754_pow(double x, double y);
|
||||
double __ieee754_sqrt(double x);
|
||||
double __ieee754_log(double x);
|
||||
int32_t __ieee754_rem_pio2(double x, double *y);
|
||||
|
||||
double fabs(double x);
|
||||
double scalbn(double x, int n);
|
||||
double copysign(double x, double y);
|
||||
double floor(double x);
|
129
platform/gp2x/uClibc/math_private.h
Normal file
129
platform/gp2x/uClibc/math_private.h
Normal file
|
@ -0,0 +1,129 @@
|
|||
/*
|
||||
* ====================================================
|
||||
* Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
|
||||
*
|
||||
* Developed at SunPro, a Sun Microsystems, Inc. business.
|
||||
* Permission to use, copy, modify, and distribute this
|
||||
* software is freely granted, provided that this notice
|
||||
* is preserved.
|
||||
* ====================================================
|
||||
*/
|
||||
|
||||
/*
|
||||
* from: @(#)fdlibm.h 5.1 93/09/24
|
||||
* $Id: math_private.h,v 1.3 2004/02/09 07:10:38 andersen Exp $
|
||||
*/
|
||||
|
||||
#ifndef _MATH_PRIVATE_H_
|
||||
#define _MATH_PRIVATE_H_
|
||||
|
||||
#include <endian.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
/* The original fdlibm code used statements like:
|
||||
n0 = ((*(int*)&one)>>29)^1; * index of high word *
|
||||
ix0 = *(n0+(int*)&x); * high word of x *
|
||||
ix1 = *((1-n0)+(int*)&x); * low word of x *
|
||||
to dig two 32 bit words out of the 64 bit IEEE floating point
|
||||
value. That is non-ANSI, and, moreover, the gcc instruction
|
||||
scheduler gets it wrong. We instead use the following macros.
|
||||
Unlike the original code, we determine the endianness at compile
|
||||
time, not at run time; I don't see much benefit to selecting
|
||||
endianness at run time. */
|
||||
|
||||
/* A union which permits us to convert between a double and two 32 bit
|
||||
ints. */
|
||||
|
||||
/*
|
||||
* Math on arm is special:
|
||||
* For FPA, float words are always big-endian.
|
||||
* For VFP, floats words follow the memory system mode.
|
||||
*/
|
||||
|
||||
#if (__BYTE_ORDER == __BIG_ENDIAN) || \
|
||||
(!defined(__VFP_FP__) && (defined(__arm__) || defined(__thumb__)))
|
||||
|
||||
typedef union
|
||||
{
|
||||
double value;
|
||||
struct
|
||||
{
|
||||
u_int32_t msw;
|
||||
u_int32_t lsw;
|
||||
} parts;
|
||||
} ieee_double_shape_type;
|
||||
|
||||
#else
|
||||
|
||||
typedef union
|
||||
{
|
||||
double value;
|
||||
struct
|
||||
{
|
||||
u_int32_t lsw;
|
||||
u_int32_t msw;
|
||||
} parts;
|
||||
} ieee_double_shape_type;
|
||||
|
||||
#endif
|
||||
|
||||
/* Get two 32 bit ints from a double. */
|
||||
|
||||
#define EXTRACT_WORDS(ix0,ix1,d) \
|
||||
do { \
|
||||
ieee_double_shape_type ew_u; \
|
||||
ew_u.value = (d); \
|
||||
(ix0) = ew_u.parts.msw; \
|
||||
(ix1) = ew_u.parts.lsw; \
|
||||
} while (0)
|
||||
|
||||
/* Get the more significant 32 bit int from a double. */
|
||||
|
||||
#define GET_HIGH_WORD(i,d) \
|
||||
do { \
|
||||
ieee_double_shape_type gh_u; \
|
||||
gh_u.value = (d); \
|
||||
(i) = gh_u.parts.msw; \
|
||||
} while (0)
|
||||
|
||||
/* Get the less significant 32 bit int from a double. */
|
||||
|
||||
#define GET_LOW_WORD(i,d) \
|
||||
do { \
|
||||
ieee_double_shape_type gl_u; \
|
||||
gl_u.value = (d); \
|
||||
(i) = gl_u.parts.lsw; \
|
||||
} while (0)
|
||||
|
||||
/* Set a double from two 32 bit ints. */
|
||||
|
||||
#define INSERT_WORDS(d,ix0,ix1) \
|
||||
do { \
|
||||
ieee_double_shape_type iw_u; \
|
||||
iw_u.parts.msw = (ix0); \
|
||||
iw_u.parts.lsw = (ix1); \
|
||||
(d) = iw_u.value; \
|
||||
} while (0)
|
||||
|
||||
/* Set the more significant 32 bits of a double from an int. */
|
||||
|
||||
#define SET_HIGH_WORD(d,v) \
|
||||
do { \
|
||||
ieee_double_shape_type sh_u; \
|
||||
sh_u.value = (d); \
|
||||
sh_u.parts.msw = (v); \
|
||||
(d) = sh_u.value; \
|
||||
} while (0)
|
||||
|
||||
/* Set the less significant 32 bits of a double from an int. */
|
||||
|
||||
#define SET_LOW_WORD(d,v) \
|
||||
do { \
|
||||
ieee_double_shape_type sl_u; \
|
||||
sl_u.value = (d); \
|
||||
sl_u.parts.lsw = (v); \
|
||||
(d) = sl_u.value; \
|
||||
} while (0)
|
||||
|
||||
|
||||
#endif /* _MATH_PRIVATE_H_ */
|
72
platform/gp2x/uClibc/memset.s
Normal file
72
platform/gp2x/uClibc/memset.s
Normal file
|
@ -0,0 +1,72 @@
|
|||
/* Copyright (C) 1998 Free Software Foundation, Inc.
|
||||
This file is part of the GNU C Library.
|
||||
Contributed by Philip Blundell <philb@gnu.org>
|
||||
|
||||
The GNU C Library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2.1 of the License, or (at your option) any later version.
|
||||
|
||||
The GNU C Library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with the GNU C Library; if not, write to the Free
|
||||
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
|
||||
02111-1307 USA. */
|
||||
|
||||
@ #include <sys/syscall.h>
|
||||
|
||||
.text
|
||||
.global memset
|
||||
.type memset,%function
|
||||
.align 4
|
||||
|
||||
memset:
|
||||
mov a4, a1
|
||||
cmp a3, $8 @ at least 8 bytes to do?
|
||||
blt 2f
|
||||
orr a2, a2, a2, lsl $8
|
||||
orr a2, a2, a2, lsl $16
|
||||
1:
|
||||
tst a4, $3 @ aligned yet?
|
||||
strneb a2, [a4], $1
|
||||
subne a3, a3, $1
|
||||
bne 1b
|
||||
mov ip, a2
|
||||
1:
|
||||
cmp a3, $8 @ 8 bytes still to do?
|
||||
blt 2f
|
||||
stmia a4!, {a2, ip}
|
||||
sub a3, a3, $8
|
||||
cmp a3, $8 @ 8 bytes still to do?
|
||||
blt 2f
|
||||
stmia a4!, {a2, ip}
|
||||
sub a3, a3, $8
|
||||
cmp a3, $8 @ 8 bytes still to do?
|
||||
blt 2f
|
||||
stmia a4!, {a2, ip}
|
||||
sub a3, a3, $8
|
||||
cmp a3, $8 @ 8 bytes still to do?
|
||||
stmgeia a4!, {a2, ip}
|
||||
subge a3, a3, $8
|
||||
bge 1b
|
||||
2:
|
||||
movs a3, a3 @ anything left?
|
||||
moveq pc, lr @ nope
|
||||
rsb a3, a3, $7
|
||||
add pc, pc, a3, lsl $2
|
||||
mov r0, r0
|
||||
strb a2, [a4], $1
|
||||
strb a2, [a4], $1
|
||||
strb a2, [a4], $1
|
||||
strb a2, [a4], $1
|
||||
strb a2, [a4], $1
|
||||
strb a2, [a4], $1
|
||||
strb a2, [a4], $1
|
||||
mov pc, lr
|
||||
|
||||
.size memset,.-memset;
|
||||
|
39
platform/gp2x/uClibc/s_copysign.c
Normal file
39
platform/gp2x/uClibc/s_copysign.c
Normal file
|
@ -0,0 +1,39 @@
|
|||
/* @(#)s_copysign.c 5.1 93/09/24 */
|
||||
/*
|
||||
* ====================================================
|
||||
* Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
|
||||
*
|
||||
* Developed at SunPro, a Sun Microsystems, Inc. business.
|
||||
* Permission to use, copy, modify, and distribute this
|
||||
* software is freely granted, provided that this notice
|
||||
* is preserved.
|
||||
* ====================================================
|
||||
*/
|
||||
|
||||
#if defined(LIBM_SCCS) && !defined(lint)
|
||||
static char rcsid[] = "$NetBSD: s_copysign.c,v 1.8 1995/05/10 20:46:57 jtc Exp $";
|
||||
#endif
|
||||
|
||||
/*
|
||||
* copysign(double x, double y)
|
||||
* copysign(x,y) returns a value with the magnitude of x and
|
||||
* with the sign bit of y.
|
||||
*/
|
||||
|
||||
#include "math.h"
|
||||
#include "math_private.h"
|
||||
|
||||
#ifdef __STDC__
|
||||
double copysign(double x, double y)
|
||||
#else
|
||||
double copysign(x,y)
|
||||
double x,y;
|
||||
#endif
|
||||
{
|
||||
u_int32_t hx,hy;
|
||||
GET_HIGH_WORD(hx,x);
|
||||
GET_HIGH_WORD(hy,y);
|
||||
SET_HIGH_WORD(x,(hx&0x7fffffff)|(hy&0x80000000));
|
||||
return x;
|
||||
}
|
||||
|
35
platform/gp2x/uClibc/s_fabs.c
Normal file
35
platform/gp2x/uClibc/s_fabs.c
Normal file
|
@ -0,0 +1,35 @@
|
|||
/* @(#)s_fabs.c 5.1 93/09/24 */
|
||||
/*
|
||||
* ====================================================
|
||||
* Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
|
||||
*
|
||||
* Developed at SunPro, a Sun Microsystems, Inc. business.
|
||||
* Permission to use, copy, modify, and distribute this
|
||||
* software is freely granted, provided that this notice
|
||||
* is preserved.
|
||||
* ====================================================
|
||||
*/
|
||||
|
||||
#if defined(LIBM_SCCS) && !defined(lint)
|
||||
static char rcsid[] = "$NetBSD: s_fabs.c,v 1.7 1995/05/10 20:47:13 jtc Exp $";
|
||||
#endif
|
||||
|
||||
/*
|
||||
* fabs(x) returns the absolute value of x.
|
||||
*/
|
||||
|
||||
#include "math.h"
|
||||
#include "math_private.h"
|
||||
|
||||
#ifdef __STDC__
|
||||
double fabs(double x)
|
||||
#else
|
||||
double fabs(x)
|
||||
double x;
|
||||
#endif
|
||||
{
|
||||
u_int32_t high;
|
||||
GET_HIGH_WORD(high,x);
|
||||
SET_HIGH_WORD(x,high&0x7fffffff);
|
||||
return x;
|
||||
}
|
81
platform/gp2x/uClibc/s_floor.c
Normal file
81
platform/gp2x/uClibc/s_floor.c
Normal file
|
@ -0,0 +1,81 @@
|
|||
/* @(#)s_floor.c 5.1 93/09/24 */
|
||||
/*
|
||||
* ====================================================
|
||||
* Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
|
||||
*
|
||||
* Developed at SunPro, a Sun Microsystems, Inc. business.
|
||||
* Permission to use, copy, modify, and distribute this
|
||||
* software is freely granted, provided that this notice
|
||||
* is preserved.
|
||||
* ====================================================
|
||||
*/
|
||||
|
||||
#if defined(LIBM_SCCS) && !defined(lint)
|
||||
static char rcsid[] = "$NetBSD: s_floor.c,v 1.8 1995/05/10 20:47:20 jtc Exp $";
|
||||
#endif
|
||||
|
||||
/*
|
||||
* floor(x)
|
||||
* Return x rounded toward -inf to integral value
|
||||
* Method:
|
||||
* Bit twiddling.
|
||||
* Exception:
|
||||
* Inexact flag raised if x not equal to floor(x).
|
||||
*/
|
||||
|
||||
#include "math.h"
|
||||
#include "math_private.h"
|
||||
|
||||
#ifdef __STDC__
|
||||
static const double huge = 1.0e300;
|
||||
#else
|
||||
static double huge = 1.0e300;
|
||||
#endif
|
||||
|
||||
#ifdef __STDC__
|
||||
double floor(double x)
|
||||
#else
|
||||
double floor(x)
|
||||
double x;
|
||||
#endif
|
||||
{
|
||||
int32_t i0,i1,j0;
|
||||
u_int32_t i,j;
|
||||
EXTRACT_WORDS(i0,i1,x);
|
||||
j0 = ((i0>>20)&0x7ff)-0x3ff;
|
||||
if(j0<20) {
|
||||
if(j0<0) { /* raise inexact if x != 0 */
|
||||
if(huge+x>0.0) {/* return 0*sign(x) if |x|<1 */
|
||||
if(i0>=0) {i0=i1=0;}
|
||||
else if(((i0&0x7fffffff)|i1)!=0)
|
||||
{ i0=0xbff00000;i1=0;}
|
||||
}
|
||||
} else {
|
||||
i = (0x000fffff)>>j0;
|
||||
if(((i0&i)|i1)==0) return x; /* x is integral */
|
||||
if(huge+x>0.0) { /* raise inexact flag */
|
||||
if(i0<0) i0 += (0x00100000)>>j0;
|
||||
i0 &= (~i); i1=0;
|
||||
}
|
||||
}
|
||||
} else if (j0>51) {
|
||||
if(j0==0x400) return x+x; /* inf or NaN */
|
||||
else return x; /* x is integral */
|
||||
} else {
|
||||
i = ((u_int32_t)(0xffffffff))>>(j0-20);
|
||||
if((i1&i)==0) return x; /* x is integral */
|
||||
if(huge+x>0.0) { /* raise inexact flag */
|
||||
if(i0<0) {
|
||||
if(j0==20) i0+=1;
|
||||
else {
|
||||
j = i1+(1<<(52-j0));
|
||||
if(j<i1) i0 +=1 ; /* got a carry */
|
||||
i1=j;
|
||||
}
|
||||
}
|
||||
i1 &= (~i);
|
||||
}
|
||||
}
|
||||
INSERT_WORDS(x,i0,i1);
|
||||
return x;
|
||||
}
|
67
platform/gp2x/uClibc/s_scalbn.c
Normal file
67
platform/gp2x/uClibc/s_scalbn.c
Normal file
|
@ -0,0 +1,67 @@
|
|||
/* @(#)s_scalbn.c 5.1 93/09/24 */
|
||||
/*
|
||||
* ====================================================
|
||||
* Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
|
||||
*
|
||||
* Developed at SunPro, a Sun Microsystems, Inc. business.
|
||||
* Permission to use, copy, modify, and distribute this
|
||||
* software is freely granted, provided that this notice
|
||||
* is preserved.
|
||||
* ====================================================
|
||||
*/
|
||||
|
||||
#if defined(LIBM_SCCS) && !defined(lint)
|
||||
static char rcsid[] = "$NetBSD: s_scalbn.c,v 1.8 1995/05/10 20:48:08 jtc Exp $";
|
||||
#endif
|
||||
|
||||
/*
|
||||
* scalbn (double x, int n)
|
||||
* scalbn(x,n) returns x* 2**n computed by exponent
|
||||
* manipulation rather than by actually performing an
|
||||
* exponentiation or a multiplication.
|
||||
*/
|
||||
|
||||
#include "math.h"
|
||||
#include "math_private.h"
|
||||
|
||||
#ifdef __STDC__
|
||||
static const double
|
||||
#else
|
||||
static double
|
||||
#endif
|
||||
two54 = 1.80143985094819840000e+16, /* 0x43500000, 0x00000000 */
|
||||
twom54 = 5.55111512312578270212e-17, /* 0x3C900000, 0x00000000 */
|
||||
huge = 1.0e+300,
|
||||
tiny = 1.0e-300;
|
||||
|
||||
#ifdef __STDC__
|
||||
double scalbn (double x, int n)
|
||||
#else
|
||||
double scalbn (x,n)
|
||||
double x; int n;
|
||||
#endif
|
||||
{
|
||||
int32_t k,hx,lx;
|
||||
EXTRACT_WORDS(hx,lx,x);
|
||||
k = (hx&0x7ff00000)>>20; /* extract exponent */
|
||||
if (k==0) { /* 0 or subnormal x */
|
||||
if ((lx|(hx&0x7fffffff))==0) return x; /* +-0 */
|
||||
x *= two54;
|
||||
GET_HIGH_WORD(hx,x);
|
||||
k = ((hx&0x7ff00000)>>20) - 54;
|
||||
if (n< -50000) return tiny*x; /*underflow*/
|
||||
}
|
||||
if (k==0x7ff) return x+x; /* NaN or Inf */
|
||||
k = k+n;
|
||||
if (k > 0x7fe) return huge*copysign(huge,x); /* overflow */
|
||||
if (k > 0) /* normal result */
|
||||
{SET_HIGH_WORD(x,(hx&0x800fffff)|(k<<20)); return x;}
|
||||
if (k <= -54) {
|
||||
if (n > 50000) /* in case integer overflow in n+k */
|
||||
return huge*copysign(huge,x); /*overflow*/
|
||||
else return tiny*copysign(tiny,x); /*underflow*/
|
||||
}
|
||||
k += 54; /* subnormal result */
|
||||
SET_HIGH_WORD(x,(hx&0x800fffff)|(k<<20));
|
||||
return x*twom54;
|
||||
}
|
82
platform/gp2x/uClibc/s_sin.c
Normal file
82
platform/gp2x/uClibc/s_sin.c
Normal file
|
@ -0,0 +1,82 @@
|
|||
/* @(#)s_sin.c 5.1 93/09/24 */
|
||||
/*
|
||||
* ====================================================
|
||||
* Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
|
||||
*
|
||||
* Developed at SunPro, a Sun Microsystems, Inc. business.
|
||||
* Permission to use, copy, modify, and distribute this
|
||||
* software is freely granted, provided that this notice
|
||||
* is preserved.
|
||||
* ====================================================
|
||||
*/
|
||||
|
||||
#if defined(LIBM_SCCS) && !defined(lint)
|
||||
static char rcsid[] = "$NetBSD: s_sin.c,v 1.7 1995/05/10 20:48:15 jtc Exp $";
|
||||
#endif
|
||||
|
||||
/* sin(x)
|
||||
* Return sine function of x.
|
||||
*
|
||||
* kernel function:
|
||||
* __kernel_sin ... sine function on [-pi/4,pi/4]
|
||||
* __kernel_cos ... cose function on [-pi/4,pi/4]
|
||||
* __ieee754_rem_pio2 ... argument reduction routine
|
||||
*
|
||||
* Method.
|
||||
* Let S,C and T denote the sin, cos and tan respectively on
|
||||
* [-PI/4, +PI/4]. Reduce the argument x to y1+y2 = x-k*pi/2
|
||||
* in [-pi/4 , +pi/4], and let n = k mod 4.
|
||||
* We have
|
||||
*
|
||||
* n sin(x) cos(x) tan(x)
|
||||
* ----------------------------------------------------------
|
||||
* 0 S C T
|
||||
* 1 C -S -1/T
|
||||
* 2 -S -C T
|
||||
* 3 -C S -1/T
|
||||
* ----------------------------------------------------------
|
||||
*
|
||||
* Special cases:
|
||||
* Let trig be any of sin, cos, or tan.
|
||||
* trig(+-INF) is NaN, with signals;
|
||||
* trig(NaN) is that NaN;
|
||||
*
|
||||
* Accuracy:
|
||||
* TRIG(x) returns trig(x) nearly rounded
|
||||
*/
|
||||
|
||||
#include "math.h"
|
||||
#include "math_private.h"
|
||||
|
||||
#ifdef __STDC__
|
||||
double sin(double x)
|
||||
#else
|
||||
double sin(x)
|
||||
double x;
|
||||
#endif
|
||||
{
|
||||
double y[2],z=0.0;
|
||||
int32_t n, ix;
|
||||
|
||||
/* High word of x. */
|
||||
GET_HIGH_WORD(ix,x);
|
||||
|
||||
/* |x| ~< pi/4 */
|
||||
ix &= 0x7fffffff;
|
||||
if(ix <= 0x3fe921fb) return __kernel_sin(x,z,0);
|
||||
|
||||
/* sin(Inf or NaN) is NaN */
|
||||
else if (ix>=0x7ff00000) return x-x;
|
||||
|
||||
/* argument reduction needed */
|
||||
else {
|
||||
n = __ieee754_rem_pio2(x,y);
|
||||
switch(n&3) {
|
||||
case 0: return __kernel_sin(y[0],y[1],1);
|
||||
case 1: return __kernel_cos(y[0],y[1]);
|
||||
case 2: return -__kernel_sin(y[0],y[1],1);
|
||||
default:
|
||||
return -__kernel_cos(y[0],y[1]);
|
||||
}
|
||||
}
|
||||
}
|
12
platform/gp2x/uClibc/wrappers.c
Normal file
12
platform/gp2x/uClibc/wrappers.c
Normal file
|
@ -0,0 +1,12 @@
|
|||
#include "math.h"
|
||||
|
||||
double pow(double x, double y)
|
||||
{
|
||||
return __ieee754_pow(x, y);
|
||||
}
|
||||
|
||||
|
||||
double log(double x)
|
||||
{
|
||||
return __ieee754_log(x);
|
||||
}
|
424
platform/gp2x/usbjoy.c
Normal file
424
platform/gp2x/usbjoy.c
Normal file
|
@ -0,0 +1,424 @@
|
|||
/* Title: USB Joystick library
|
||||
Version 0.2
|
||||
Written by Puck2099 (puck2099@gmail.com), (c) 2006.
|
||||
<http://www.gp32wip.com>
|
||||
|
||||
If you use this library or a part of it, please, let it know.
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2.1 of the License, or (at your option) any later version.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with this library; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h> /* For the definition of NULL */
|
||||
#include <sys/types.h> // For Device open
|
||||
#include <sys/stat.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <fcntl.h>
|
||||
#include <unistd.h> // For Device read
|
||||
|
||||
#include <string.h>
|
||||
#include <limits.h> /* For the definition of PATH_MAX */
|
||||
#include <linux/joystick.h>
|
||||
|
||||
#include "usbjoy.h"
|
||||
|
||||
|
||||
/*
|
||||
Function: joy_open
|
||||
|
||||
Opens a USB joystick and fills its information.
|
||||
|
||||
Parameters:
|
||||
|
||||
joynumber - Joystick's identifier (0 reserved for GP2X's builtin Joystick).
|
||||
|
||||
Returns:
|
||||
|
||||
Filled usbjoy structure.
|
||||
|
||||
*/
|
||||
struct usbjoy *joy_open(int joynumber)
|
||||
{
|
||||
int fd;
|
||||
char path [128];
|
||||
struct usbjoy * joy = NULL;
|
||||
struct js_event event;
|
||||
static char insmod_done = 0;
|
||||
|
||||
// notaz: on my system I get unresolved input_* symbols, so have to 'insmod input' too
|
||||
// also we should insmod only once, not on every joy_open() call.
|
||||
if (!insmod_done) {
|
||||
system ("insmod input");
|
||||
system ("insmod joydev"); // Loads joydev module
|
||||
insmod_done = 1;
|
||||
}
|
||||
|
||||
if (joynumber == 0) {
|
||||
}
|
||||
else if (joynumber > 0) {
|
||||
sprintf (path, "/dev/input/js%d", joynumber-1);
|
||||
fd = open(path, O_RDONLY, 0);
|
||||
if (fd > 0) {
|
||||
joy = (struct usbjoy *) malloc(sizeof(*joy));
|
||||
if (joy == NULL) { close(fd); return NULL; }
|
||||
memset(joy, 0, sizeof(*joy));
|
||||
|
||||
// Set the joystick to non-blocking read mode
|
||||
fcntl(fd, F_SETFL, O_NONBLOCK);
|
||||
|
||||
// notaz: maybe we should flush init events now.
|
||||
// My pad returns axis as active when I plug it in, which is kind of annoying.
|
||||
while (read(fd, &event, sizeof(event)) > 0);
|
||||
|
||||
// Joystick's file descriptor
|
||||
joy->fd = fd;
|
||||
|
||||
// Joystick's name
|
||||
ioctl(joy->fd, JSIOCGNAME(128*sizeof(char)), joy->name);
|
||||
|
||||
// Joystick's device
|
||||
strcpy(joy->device, path);
|
||||
|
||||
// Joystick's buttons
|
||||
ioctl(joy->fd, JSIOCGBUTTONS, &joy->numbuttons);
|
||||
|
||||
// Joystick's axes
|
||||
ioctl(joy->fd, JSIOCGAXES, &joy->numaxes);
|
||||
|
||||
// Joystick's type (derived from name)
|
||||
if (strncasecmp(joy->name, "logitech", strlen("logitech")) == 0)
|
||||
joy->type = JOY_TYPE_LOGITECH;
|
||||
else joy->type = JOY_TYPE_GENERIC;
|
||||
} else {
|
||||
// printf ("ERROR: No Joystick found\n");
|
||||
}
|
||||
}
|
||||
return joy;
|
||||
}
|
||||
|
||||
/*
|
||||
Function: joy_name
|
||||
|
||||
Returns Joystick's name.
|
||||
|
||||
Parameters:
|
||||
|
||||
joy - Selected joystick.
|
||||
|
||||
Returns:
|
||||
|
||||
Joystick's name or NULL if <usbjoy> struct is empty.
|
||||
*/
|
||||
char * joy_name (struct usbjoy * joy) {
|
||||
if (joy != NULL) return joy->name;
|
||||
else return NULL;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
Function: joy_device
|
||||
|
||||
Returns Joystick's device.
|
||||
|
||||
Parameters:
|
||||
|
||||
joy - Selected joystick.
|
||||
|
||||
Returns:
|
||||
|
||||
Joystick's device or NULL if <usbjoy> struct is empty.
|
||||
*/
|
||||
char * joy_device (struct usbjoy * joy) {
|
||||
if (joy != NULL) return joy->device;
|
||||
else return NULL;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
Function: joy_buttons
|
||||
|
||||
Returns Joystick's buttons number.
|
||||
|
||||
Parameters:
|
||||
|
||||
joy - Selected joystick.
|
||||
|
||||
Returns:
|
||||
|
||||
Joystick's buttons or 0 if <usbjoy> struct is empty.
|
||||
*/
|
||||
int joy_buttons (struct usbjoy * joy) {
|
||||
if (joy != NULL) return joy->numbuttons;
|
||||
else return 0;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
Function: joy_axes
|
||||
|
||||
Returns Joystick's axes number.
|
||||
|
||||
Parameters:
|
||||
|
||||
joy - Selected joystick.
|
||||
|
||||
Returns:
|
||||
|
||||
Joystick's axes or 0 if <usbjoy> struct is empty.
|
||||
*/
|
||||
int joy_axes (struct usbjoy * joy) {
|
||||
if (joy != NULL) return joy->numaxes;
|
||||
else return 0;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
Function: joy_update
|
||||
|
||||
Updates Joystick's internal information (<statebuttons> and <stateaxes> fields).
|
||||
|
||||
Parameters:
|
||||
|
||||
joy - Selected joystick.
|
||||
|
||||
Returns:
|
||||
|
||||
0 - No events registered (no need to update).
|
||||
1 - Events registered (a button or axe has been pushed).
|
||||
-1 - Error: <usbjoy> struct is empty.
|
||||
*/
|
||||
int joy_update (struct usbjoy * joy) {
|
||||
struct js_event events[0xff];
|
||||
int i, len;
|
||||
int event = 0;
|
||||
if (joy != NULL) {
|
||||
if ((len=read(joy->fd, events, (sizeof events))) >0) {
|
||||
len /= sizeof(events[0]);
|
||||
for ( i=0; i<len; ++i ) {
|
||||
switch (events[i].type & ~JS_EVENT_INIT) {
|
||||
case JS_EVENT_AXIS:
|
||||
if (events[i].number == 0) {
|
||||
if (events[i].value == 0) joy->stateaxes[JOYLEFT] = joy->stateaxes[JOYRIGHT] = 0;
|
||||
else if (events[i].value < 0) joy->stateaxes[JOYLEFT] = 1;
|
||||
else joy->stateaxes[JOYRIGHT] = 1;
|
||||
}
|
||||
else if (events[i].number == 1) {
|
||||
if (events[i].value == 0) joy->stateaxes[JOYUP] = joy->stateaxes[JOYDOWN] = 0;
|
||||
else if (events[i].value < 0) joy->stateaxes[JOYUP] = 1;
|
||||
else joy->stateaxes[JOYDOWN] = 1;
|
||||
}
|
||||
event = 1;
|
||||
break;
|
||||
case JS_EVENT_BUTTON:
|
||||
joy->statebuttons[events[i].number] = events[i].value;
|
||||
event = 1;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
event = -1;
|
||||
}
|
||||
return event;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
Function: joy_getbutton
|
||||
|
||||
Returns Joystick's button information.
|
||||
|
||||
Parameters:
|
||||
|
||||
button - Button which value you want to know (from 0 to 31).
|
||||
joy - Selected joystick.
|
||||
|
||||
Returns:
|
||||
|
||||
0 - Button NOT pushed.
|
||||
1 - Button pushed.
|
||||
-1 - Error: <usbjoy> struct is empty.
|
||||
*/
|
||||
int joy_getbutton (int button, struct usbjoy * joy) {
|
||||
if (joy != NULL) {
|
||||
if (button < joy_buttons(joy)) return joy->statebuttons[button];
|
||||
else return 0;
|
||||
}
|
||||
else return -1;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
Function: joy_getaxe
|
||||
|
||||
Returns Joystick's axes information.
|
||||
|
||||
Parameters:
|
||||
|
||||
axe - Axe which value you want to know (see <Axes values>).
|
||||
joy - Selected joystick.
|
||||
|
||||
Returns:
|
||||
|
||||
0 - Direction NOT pushed.
|
||||
1 - Direction pushed.
|
||||
-1 - Error: <usbjoy> struct is empty.
|
||||
*/
|
||||
int joy_getaxe (int axe, struct usbjoy * joy) {
|
||||
if (joy != NULL) {
|
||||
if (axe < 4) return joy->stateaxes[axe];
|
||||
else return 0;
|
||||
}
|
||||
else return -1;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
Function: joy_close
|
||||
|
||||
Closes selected joystick's file descriptor and detroys it's fields.
|
||||
|
||||
Parameters:
|
||||
|
||||
joy - Selected joystick.
|
||||
|
||||
Returns:
|
||||
|
||||
0 - Joystick successfully closed.
|
||||
-1 - Error: <usbjoy> struct is empty.
|
||||
*/
|
||||
int joy_close (struct usbjoy * joy) {
|
||||
if (joy != NULL) {
|
||||
close (joy->fd);
|
||||
free (joy);
|
||||
return 0;
|
||||
}
|
||||
else return -1;
|
||||
}
|
||||
|
||||
|
||||
/*********************************************************************/
|
||||
/* GP2X USB Joystick Handling -GnoStiC */
|
||||
/*********************************************************************/
|
||||
|
||||
#include "gp2x.h"
|
||||
|
||||
int num_of_joys = 0;
|
||||
struct usbjoy *joys[4];
|
||||
|
||||
void gp2x_usbjoy_init (void) {
|
||||
/* Open available joysticks -GnoStiC */
|
||||
int i, n = 0;
|
||||
|
||||
printf("\n");
|
||||
for (i = 0; i < 4; i++) {
|
||||
joys[n] = joy_open(i+1);
|
||||
if (joys[n] && joy_buttons(joys[n]) > 0) {
|
||||
printf ("+-Joystick %d: \"%s\", buttons = %i\n", i+1, joy_name(joys[n]), joy_buttons(joys[n]));
|
||||
n++;
|
||||
}
|
||||
}
|
||||
num_of_joys = n;
|
||||
|
||||
printf("Found %d Joystick(s)\n",num_of_joys);
|
||||
}
|
||||
|
||||
void gp2x_usbjoy_update (void) {
|
||||
/* Update Joystick Event Cache */
|
||||
int q, foo;
|
||||
for (q=0; q < num_of_joys; q++) {
|
||||
foo = joy_update (joys[q]);
|
||||
}
|
||||
}
|
||||
|
||||
int gp2x_usbjoy_check (int joyno) {
|
||||
/* Check Joystick */
|
||||
int q, joyExKey = 0;
|
||||
struct usbjoy *joy = joys[joyno];
|
||||
|
||||
if (joy != NULL) {
|
||||
if (joy_getaxe(JOYUP, joy)) { joyExKey |= GP2X_UP; }
|
||||
if (joy_getaxe(JOYDOWN, joy)) { joyExKey |= GP2X_DOWN; }
|
||||
if (joy_getaxe(JOYLEFT, joy)) { joyExKey |= GP2X_LEFT; }
|
||||
if (joy_getaxe(JOYRIGHT, joy)) { joyExKey |= GP2X_RIGHT; }
|
||||
|
||||
/* loop through joy buttons to check if they are pushed */
|
||||
for (q=0; q<joy_buttons (joy); q++) {
|
||||
if (joy_getbutton (q, joy)) {
|
||||
if (joy->type == JOY_TYPE_LOGITECH) {
|
||||
switch (q) {
|
||||
case 0: joyExKey |= GP2X_A; break;
|
||||
case 1: joyExKey |= GP2X_X; break;
|
||||
case 2: joyExKey |= GP2X_B; break;
|
||||
case 3: joyExKey |= GP2X_Y; break;
|
||||
}
|
||||
} else {
|
||||
switch (q) {
|
||||
case 0: joyExKey |= GP2X_Y; break;
|
||||
case 1: joyExKey |= GP2X_B; break;
|
||||
case 2: joyExKey |= GP2X_X; break;
|
||||
case 3: joyExKey |= GP2X_A; break;
|
||||
}
|
||||
}
|
||||
|
||||
switch (q) {
|
||||
case 4: joyExKey |= GP2X_L; break;
|
||||
case 5: joyExKey |= GP2X_R; break;
|
||||
case 6: joyExKey |= GP2X_L; break; /* left shoulder button 2 */
|
||||
case 7: joyExKey |= GP2X_R; break; /* right shoulder button 2 */
|
||||
case 8: joyExKey |= GP2X_SELECT;break;
|
||||
case 9: joyExKey |= GP2X_START; break;
|
||||
case 10: joyExKey |= GP2X_PUSH; break;
|
||||
case 11: joyExKey |= GP2X_PUSH; break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return joyExKey;
|
||||
}
|
||||
|
||||
int gp2x_usbjoy_check2 (int joyno) {
|
||||
/* Check Joystick, don't map to gp2x joy */
|
||||
int q, to, joyExKey = 0;
|
||||
struct usbjoy *joy = joys[joyno];
|
||||
|
||||
if (joy != NULL) {
|
||||
if (joy_getaxe(JOYUP, joy)) { joyExKey |= 1 << 0; }
|
||||
if (joy_getaxe(JOYDOWN, joy)) { joyExKey |= 1 << 1; }
|
||||
if (joy_getaxe(JOYLEFT, joy)) { joyExKey |= 1 << 2; }
|
||||
if (joy_getaxe(JOYRIGHT, joy)) { joyExKey |= 1 << 3; }
|
||||
|
||||
/* loop through joy buttons to check if they are pushed */
|
||||
to = joy->numbuttons;
|
||||
if (to > 32-4) to = 32-4;
|
||||
for (q=0; q < to; q++)
|
||||
if (joy->statebuttons[q]) joyExKey |= 1 << (q+4);
|
||||
}
|
||||
return joyExKey;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void gp2x_usbjoy_deinit (void) {
|
||||
int i;
|
||||
for (i=0; i<num_of_joys; i++) {
|
||||
joy_close (joys[i]);
|
||||
}
|
||||
num_of_joys = 0;
|
||||
}
|
||||
|
241
platform/gp2x/usbjoy.h
Normal file
241
platform/gp2x/usbjoy.h
Normal file
|
@ -0,0 +1,241 @@
|
|||
/* Title: USB Joystick library
|
||||
Version 0.2
|
||||
Written by Puck2099 (puck2099@gmail.com), (c) 2006.
|
||||
<http://www.gp32wip.com>
|
||||
|
||||
If you use this library or a part of it, please, let it know.
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2.1 of the License, or (at your option) any later version.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with this library; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
#ifndef USBJOY_H
|
||||
#define USBJOY_H
|
||||
|
||||
/* notaz: my Logitech has different button layout, and I want it to match gptx's */
|
||||
typedef enum {
|
||||
JOY_TYPE_GENERIC,
|
||||
JOY_TYPE_LOGITECH
|
||||
} joy_type;
|
||||
|
||||
/*
|
||||
Enumeration: Axes values
|
||||
This enumeration contains shortcuts to the values used on axes.
|
||||
|
||||
Constants:
|
||||
JOYUP - Joystick Up
|
||||
JOYDOWN - Joystick Down
|
||||
JOYLEFT - Joystick Left
|
||||
JOYRIGHT - Joystick Right
|
||||
|
||||
See also:
|
||||
<joy_getaxe>
|
||||
*/
|
||||
#define JOYUP (0)
|
||||
#define JOYDOWN (1)
|
||||
#define JOYLEFT (2)
|
||||
#define JOYRIGHT (3)
|
||||
|
||||
|
||||
/*
|
||||
Struct: usbjoy
|
||||
|
||||
Contains all Joystick needed information.
|
||||
|
||||
Fields:
|
||||
fd - File descriptor used.
|
||||
name - Joystick's name.
|
||||
device - /dev/input/jsX device.
|
||||
numbuttons - Joystick's buttons.
|
||||
numaxes - Joystick's axes.
|
||||
numhats - Joystick's hats.
|
||||
statebuttons - Current state of each button.
|
||||
stateaxes - Current state of each direction.
|
||||
*/
|
||||
struct usbjoy {
|
||||
int fd;
|
||||
char name [128];
|
||||
char device [128];
|
||||
int numbuttons;
|
||||
int numaxes;
|
||||
int numhats;
|
||||
int statebuttons[32];
|
||||
int stateaxes[4];
|
||||
joy_type type;
|
||||
};
|
||||
|
||||
|
||||
/*
|
||||
Function: joy_open
|
||||
|
||||
Opens a USB joystick and fills its information.
|
||||
|
||||
Parameters:
|
||||
|
||||
joynumber - Joystick's identifier (0 reserved for GP2X's builtin Joystick).
|
||||
|
||||
Returns:
|
||||
|
||||
Filled usbjoy structure.
|
||||
*/
|
||||
struct usbjoy * joy_open (int joynumber);
|
||||
|
||||
|
||||
/*
|
||||
Function: joy_name
|
||||
|
||||
Returns Joystick's name.
|
||||
|
||||
Parameters:
|
||||
|
||||
joy - Selected joystick.
|
||||
|
||||
Returns:
|
||||
|
||||
Joystick's name or NULL if <usbjoy> struct is empty.
|
||||
*/
|
||||
char * joy_name (struct usbjoy * joy);
|
||||
|
||||
|
||||
/*
|
||||
Function: joy_device
|
||||
|
||||
Returns Joystick's device.
|
||||
|
||||
Parameters:
|
||||
|
||||
joy - Selected joystick.
|
||||
|
||||
Returns:
|
||||
|
||||
Joystick's device or NULL if <usbjoy> struct is empty.
|
||||
*/
|
||||
char * joy_device (struct usbjoy * joy);
|
||||
|
||||
/*
|
||||
Function: joy_buttons
|
||||
|
||||
Returns Joystick's buttons number.
|
||||
|
||||
Parameters:
|
||||
|
||||
joy - Selected joystick.
|
||||
|
||||
Returns:
|
||||
|
||||
Joystick's buttons or 0 if <usbjoy> struct is empty.
|
||||
*/
|
||||
int joy_buttons (struct usbjoy * joy);
|
||||
|
||||
/*
|
||||
Function: joy_axes
|
||||
|
||||
Returns Joystick's axes number.
|
||||
|
||||
Parameters:
|
||||
|
||||
joy - Selected joystick.
|
||||
|
||||
Returns:
|
||||
|
||||
Joystick's axes or 0 if <usbjoy> struct is empty.
|
||||
*/
|
||||
int joy_axes (struct usbjoy * joy);
|
||||
|
||||
|
||||
/*
|
||||
Function: joy_update
|
||||
|
||||
Updates Joystick's internal information (<statebuttons> and <stateaxes> fields).
|
||||
|
||||
Parameters:
|
||||
|
||||
joy - Selected joystick.
|
||||
|
||||
Returns:
|
||||
|
||||
0 - No events registered (no need to update).
|
||||
1 - Events registered (a button or axe has been pushed).
|
||||
-1 - Error: <usbjoy> struct is empty.
|
||||
*/
|
||||
int joy_update (struct usbjoy * joy);
|
||||
|
||||
|
||||
/*
|
||||
Function: joy_getbutton
|
||||
|
||||
Returns Joystick's button information.
|
||||
|
||||
Parameters:
|
||||
|
||||
button - Button which value you want to know (from 0 to 31).
|
||||
joy - Selected joystick.
|
||||
|
||||
Returns:
|
||||
|
||||
0 - Button NOT pushed.
|
||||
1 - Button pushed.
|
||||
-1 - Error: <usbjoy> struct is empty.
|
||||
*/
|
||||
int joy_getbutton (int button, struct usbjoy * joy);
|
||||
|
||||
|
||||
/*
|
||||
Function: joy_getaxe
|
||||
|
||||
Returns Joystick's axes information.
|
||||
|
||||
Parameters:
|
||||
|
||||
axe - Axe which value you want to know (see <Axes values>).
|
||||
joy - Selected joystick.
|
||||
|
||||
Returns:
|
||||
|
||||
0 - Direction NOT pushed.
|
||||
1 - Direction pushed.
|
||||
-1 - Error: <usbjoy> struct is empty.
|
||||
*/
|
||||
int joy_getaxe (int axe, struct usbjoy * joy);
|
||||
|
||||
/*
|
||||
Function: joy_close
|
||||
|
||||
Closes selected joystick's file descriptor and detroys it's fields.
|
||||
|
||||
Parameters:
|
||||
|
||||
joy - Selected joystick.
|
||||
|
||||
Returns:
|
||||
|
||||
0 - Joystick successfully closed.
|
||||
-1 - Error: <usbjoy> struct is empty.
|
||||
*/
|
||||
int joy_close (struct usbjoy * joy);
|
||||
|
||||
|
||||
|
||||
/* gp2x stuff */
|
||||
extern int num_of_joys;
|
||||
extern struct usbjoy *joys[4];
|
||||
|
||||
void gp2x_usbjoy_update(void);
|
||||
void gp2x_usbjoy_init(void);
|
||||
int gp2x_usbjoy_check(int joyno);
|
||||
int gp2x_usbjoy_check2(int joyno);
|
||||
void gp2x_usbjoy_deinit(void);
|
||||
|
||||
|
||||
#endif // USBJOY_H
|
2
platform/gp2x/version.h
Normal file
2
platform/gp2x/version.h
Normal file
|
@ -0,0 +1,2 @@
|
|||
#define VERSION "0.964"
|
||||
|
Loading…
Add table
Add a link
Reference in a new issue