/*
usage tvon -tvmode 3
tvmode defaults to 4 (PAL). 3 is NTSC.
This should be run from a script -
#!/bin/sh
./tvon
cd /usr/gp2x/
./gp2xmenu
.gp2xmenu is actually executed after a tvoff script is executed as tvon.gpe will automatically run gp2xmenu and keep this process open. The tvoff script just needs to contain #!/bin/sh as it's purpose is to exit (and close this process, which will close the tv handle) and allow the tvon script to continue.
Bit of a hack, but at least it works :)
Woogal.
*/
#include <math.h>
#include <stdlib.h>
#include <stdio.h>
#include <stdarg.h>
#include <string.h>
#include <sys/ioctl.h>
#include <fcntl.h>
#include "SDL.h"
#include <sys/mman.h>
#include "mmsp2_regs.h"
int com_argc;
#define MAX_NUM_ARGVS 20
static char *com_argv[MAX_NUM_ARGVS];
#define CMDLINE_LENGTH 256
char com_cmdline[CMDLINE_LENGTH];
int handle;
typedef struct { unsigned char id,addr,data;} i2cw;
typedef struct { unsigned char id,addr,*pdata;} i2cr;
void gp2x_i2c_write(unsigned char addr, unsigned char data)
{
i2cw a = {.id = 0x8A, .addr = addr, .data = data};
ioctl(handle, _IOW('v', 0x00, i2cw), &a);
}
unsigned char gp2x_i2c_read(unsigned char addr)
{
unsigned char temp;
i2cr a = {.id = 0x8A, .addr = addr, .pdata = &temp };
ioctl(handle, _IOW('v', 0x01, i2cr), &a);
return (*a.pdata);
}
void COM_InitArgv (int argc, char **argv)
{
int i, j, n;
// reconstitute the command line for the cmdline externally visible cvar
n = 0;
for (j=0 ; (j<MAX_NUM_ARGVS) && (j< argc) ; j++)
{
i = 0;
while ((n < (CMDLINE_LENGTH - 1)) && argv[j][i])
{
com_cmdline[n++] = argv[j][i++];
}
if (n < (CMDLINE_LENGTH - 1))
com_cmdline[n++] = ' ';
else
break;
}
com_cmdline[n] = 0;
for (com_argc=0 ; (com_argc<MAX_NUM_ARGVS) && (com_argc < argc) ;
com_argc++)
{
com_argv[com_argc] = argv[com_argc];
}
}
int COM_CheckParm (char *parm)
{
int i;
for (i=1 ; i<com_argc ; i++)
{
if (!com_argv[i])
continue;
if (!strcmp (parm,com_argv[i]))
return i;
}
return 0;
}
int main(int argc, char *argv[])
{
int i;
COM_InitArgv (argc, argv);
FILE *fh;
//this is your program. i'm working with LCD at the moment...
//...
int Uppermemfd;
unsigned char* UpperMem;
Uppermemfd = open("/dev/mem", O_RDWR); //Open the memory for reading/writing
UpperMem = (unsigned char*)mmap(0, 0x2000000, PROT_READ | PROT_WRITE, MAP_SHARED, Uppermemfd, 0x2000000); //mmap the upper 32MB.
int memory_fd;
unsigned short volatile *io;
memory_fd = open("/dev/mem", O_RDWR, 0);
io=mmap(NULL, 0x10000, PROT_READ|PROT_WRITE,MAP_SHARED, memory_fd, 0xc0000000);
printf("width: %d\n",io[DPC_X_MAX]+1);
if (io[DPC_X_MAX] + 1==320) { // we're using the lcd (unless someone has got a 320x240 tv mode working)
//now activate TV out by opening this device
UpperMem[0]=open("/dev/cx25874",O_RDWR); // use a fixed area of memory for the handle so we can switch between PAL and NTSC later if we want
//set TV video mode (mode 3 is 720x480Ix16_30Hz NTSC; mode 4 is 720x576Ix16_50Hz PAL)
//note: there are other video modes supported by the module driver (modes 0,1 and 5) but they do not work at all in our gp2xs/tvs. trust me.
int tvmode=4; // default to PAL
i = COM_CheckParm ("-tvmode");
if (i && i < com_argc-1)
{
tvmode=atoi(com_argv[i+1]);
}
ioctl(UpperMem[0], _IOW('v', 0x02, unsigned char), tvmode); // activate the mode
}
close(memory_fd); // don't need this anymore, but make sure the tv handle isn't closed!
chdir ("/usr/gp2x");
execl("/usr/gp2x/gp2xmenu","gp2xmenu","--disable-autorun",0); // run the menu skipping autorun
}