refactoring for Wiz port; random cleanups

git-svn-id: file:///home/notaz/opt/svn/PicoDrive/platform@703 be3aeb3a-fb24-0410-a615-afba39da0efa
This commit is contained in:
notaz 2009-07-15 16:13:43 +00:00
parent 9c0d458840
commit d572cbad98
18 changed files with 531 additions and 492 deletions

View file

@ -538,6 +538,7 @@ static int custom_read(menu_entry *me, const char *var, const char *val)
return 0;
return 1;
#if 0 // TODO rm?
case MA_OPT_CPU_CLOCKS:
#ifdef __GP2X__
if (strcasecmp(var, "GP2X CPU clocks") != 0) return 0;
@ -546,6 +547,7 @@ static int custom_read(menu_entry *me, const char *var, const char *val)
#endif
currentConfig.CPUclock = atoi(val);
return 1;
#endif
case MA_OPT2_GAMMA:
if (strcasecmp(var, "Gamma correction") != 0) return 0;

View file

@ -1702,11 +1702,7 @@ static menu_entry e_menu_options[] =
mee_onoff ("Enable sound", MA_OPT_ENABLE_SOUND, currentConfig.EmuOpt, 0x004),
mee_cust ("Sound Quality", MA_OPT_SOUND_QUALITY, mh_opt_misc, mgn_opt_sound),
mee_cust ("Confirm savestate", MA_OPT_CONFIRM_STATES,mh_opt_misc, mgn_opt_c_saves),
#if defined(__GP2X__)
mee_range ("GP2X CPU clocks", MA_OPT_CPU_CLOCKS, currentConfig.CPUclock, 20, 400),
#elif defined(PSP)
mee_range ("PSP CPU clock", MA_OPT_CPU_CLOCKS, currentConfig.CPUclock, )
#endif
mee_range (cpu_clk_name, MA_OPT_CPU_CLOCKS, currentConfig.CPUclock, 20, 900),
mee_handler ("[Display options]", menu_loop_gfx_options),
mee_handler ("[Advanced options]", menu_loop_adv_options),
mee_handler ("[Sega/Mega CD options]", menu_loop_cd_options),

View file

@ -96,7 +96,7 @@ typedef enum
typedef struct
{
char *name;
const char *name;
menu_behavior beh;
menu_id id;
void *var; /* for on-off/range settings */

View file

@ -3,6 +3,7 @@ extern "C" {
#endif
/* stuff to be implemented by platform code */
extern char cpu_clk_name[];
/* TODO rename all these */
extern const char * const keyNames[]; // TODO rm
void emu_prepareDefaultConfig(void);
@ -18,6 +19,9 @@ int emu_getMainDir(char *dst, int len);
void menu_romload_prepare(const char *rom_name);
void menu_romload_end(void);
void plat_init(void);
void plat_finish(void);
/* menu: enter (switch bpp, etc), begin/end drawing */
void plat_video_menu_enter(int is_rom_loaded);
void plat_video_menu_begin(void);

View file

@ -11,7 +11,8 @@
#include <errno.h>
#include "code940/940shared.h"
#include "gp2x.h"
#include "soc_mmsp2.h"
#include "soc.h"
#include "emu.h"
#include "../common/mp3.h"
#include "../common/arm_utils.h"
@ -21,10 +22,6 @@
#include "../../pico/sound/ym2612.h"
#include "../../pico/sound/mix.h"
/* we will need some gp2x internals here */
extern volatile unsigned short *gp2x_memregs; /* from minimal library rlyeh */
extern volatile unsigned long *gp2x_memregl;
extern int reset_timing;
static unsigned char *shared_mem = 0;
static _940_data_t *shared_data = 0;
@ -286,8 +283,8 @@ void YM2612Init_940(int baseclock, int rate)
printf("YM2612Init_940()\n");
printf("Mem usage: shared_data: %i, shared_ctl: %i\n", sizeof(*shared_data), sizeof(*shared_ctl));
Reset940(1, 2);
Pause940(1);
reset940(1, 2);
pause940(1);
gp2x_memregs[0x3B40>>1] = 0; // disable DUALCPU interrupts for 920
gp2x_memregs[0x3B42>>1] = 1; // enable DUALCPU interrupts for 940
@ -347,8 +344,8 @@ void YM2612Init_940(int baseclock, int rate)
gp2x_memregl[0x4510>>2] = 0xffffffff; // clear pending IRQs in INTPND
/* start the 940 */
Reset940(0, 2);
Pause940(0);
reset940(0, 2);
pause940(0);
// YM2612ResetChip_940(); // will be done on JOB940_YM2612INIT

View file

@ -54,8 +54,8 @@ LD = $(CROSS)ld
OBJCOPY = $(CROSS)objcopy
# frontend
# TODO: clean cpuctrl
OBJS += main.o gp2x.o emu.o in_gp2x.o plat.o squidgehack.o cpuctrl.o
# TODO: rm cpuctrl
OBJS += main.o soc.o soc_mmsp2.o soc_pollux.o emu.o in_gp2x.o plat.o squidgehack.o cpuctrl.o
# 940 core control
OBJS += 940ctl.o

View file

@ -16,6 +16,7 @@
#include "emu.h"
#include "gp2x.h"
#include "soc.h"
#include "../common/menu.h"
#include "../common/arm_utils.h"
#include "../common/fonts.h"
@ -40,8 +41,6 @@
#endif
int select_exits = 0;
extern int crashed_940;
static short __attribute__((aligned(4))) sndBuffer[2*44100/50];
@ -1017,7 +1016,7 @@ const char *plat_get_credits(void)
"Reesy & FluBBa: DrZ80 core\n"
"MAME devs: YM2612 and SN76496 cores\n"
"rlyeh and others: minimal SDK\n"
"Squidge: squidgehack\n"
"Squidge: mmuhack\n"
"Dzz: ARM940 sample\n"
"GnoStiC / Puck2099: USB joy code\n"
"craigix: GP2X hardware\n"

View file

@ -1,34 +1,12 @@
#ifndef __GP2X_H__
#define __GP2X_H__
void gp2x_init(void);
void gp2x_deinit(void);
/* video */
void gp2x_video_flip(void);
void gp2x_video_flip2(void);
void gp2x_video_changemode(int bpp);
void gp2x_video_changemode2(int bpp);
void gp2x_video_setpalette(int *pal, int len);
void gp2x_video_RGB_setscaling(int ln_offs, int W, int H);
void gp2x_video_wait_vsync(void);
void gp2x_video_flush_cache(void);
void gp2x_memcpy_buffers(int buffers, void *data, int offset, int len);
void gp2x_memcpy_all_buffers(void *data, int offset, int len);
void gp2x_memset_all_buffers(int offset, int byte, int len);
void gp2x_pd_clone_buffer2(void);
/* input */
int gp2x_touchpad_read(int *x, int *y);
/* 940 core */
void Pause940(int yes);
void Reset940(int yes, int bank);
extern int memdev;
#endif

View file

@ -3,6 +3,7 @@
#include "../common/input.h"
#include "in_gp2x.h"
#include "soc.h"
#define IN_PREFIX "gp2x:"
#define IN_GP2X_NBUTTONS 32
@ -12,8 +13,6 @@
static int in_gp2x_combo_keys = 0;
static int in_gp2x_combo_acts = 0;
extern volatile unsigned short *gp2x_memregs; /* from minimal library rlyeh */
enum { BTN_UP = 0, BTN_LEFT = 2, BTN_DOWN = 4, BTN_RIGHT = 6,
BTN_START = 8, BTN_SELECT = 9, BTN_L = 10, BTN_R = 11,
BTN_A = 12, BTN_B = 13, BTN_X = 14, BTN_Y = 15,
@ -43,6 +42,7 @@ static int in_gp2x_get_bind_count(void)
static int in_gp2x_get_gpio_bits(void)
{
#ifndef FAKE_IN_GP2X
extern volatile unsigned short *gp2x_memregs;
int value;
value = gp2x_memregs[0x1198>>1] & 0xff; // GPIO M
if (value == 0xFD) value = 0xFA;

View file

@ -10,7 +10,6 @@
#include <strings.h>
#include <linux/limits.h>
#include "gp2x.h"
#include "../common/menu.h"
#include "../common/emu.h"
#include "../common/config.h"
@ -24,8 +23,6 @@
#include "cpuctrl.h"
extern char *ext_menu, *ext_state;
extern int select_exits;
extern char *PicoConfigFile;
static int load_state_slot = -1;
int mmuhack_status = 0;
@ -35,24 +32,15 @@ void parse_cmd_line(int argc, char *argv[])
{
int x, unrecognized = 0;
for(x = 1; x < argc; x++)
for (x = 1; x < argc; x++)
{
if(argv[x][0] == '-')
if (argv[x][0] == '-')
{
if(strcasecmp(argv[x], "-menu") == 0) {
if(x+1 < argc) { ++x; ext_menu = argv[x]; } /* External Frontend: Program Name */
if (strcasecmp(argv[x], "-config") == 0) {
if (x+1 < argc) { ++x; PicoConfigFile = argv[x]; }
}
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 if(strcasecmp(argv[x], "-loadstate") == 0) {
if(x+1 < argc) { ++x; load_state_slot = atoi(argv[x]); }
else if (strcasecmp(argv[x], "-loadstate") == 0) {
if (x+1 < argc) { ++x; load_state_slot = atoi(argv[x]); }
}
else {
unrecognized = 1;
@ -72,15 +60,11 @@ void parse_cmd_line(int argc, char *argv[])
}
if (unrecognized) {
printf("\n\n\nPicoDrive v" VERSION " (c) notaz, 2006-2008\n");
printf("\n\n\nPicoDrive v" VERSION " (c) notaz, 2006-2009\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"
"-loadstate <num> if ROM is specified, try loading slot <num>\n");
printf("options:\n"
" -config <file> use specified config file instead of default 'config.cfg'\n"
" -loadstate <num> if ROM is specified, try loading slot <num>\n");
}
}
@ -89,22 +73,22 @@ int main(int argc, char *argv[])
{
g_argv = argv;
/* in_init() must go before config, config accesses in_ fwk */
in_init();
emu_prepareDefaultConfig();
emu_ReadConfig(0, 0);
config_readlrom(PicoConfigFile);
plat_init();
in_probe();
in_debug_dump();
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
@ -169,8 +153,8 @@ int main(int argc, char *argv[])
emu_Deinit();
sharedmem_deinit();
cpuctrl_deinit();
gp2x_deinit();
if(mmuhack_status)
plat_finish();
if (mmuhack_status)
mmuunhack();
return 0;

View file

@ -1,11 +1,51 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdarg.h>
#include "gp2x.h"
#include "soc.h"
#include "../common/plat.h"
#include "../common/readpng.h"
#include "../common/menu.h"
#include "../common/emu.h"
#include "../linux/sndout_oss.h"
/* GP2X local */
void *gp2x_screens[4];
void gp2x_video_changemode(int bpp)
{
gp2x_video_changemode_ll(bpp);
gp2x_memset_all_buffers(0, 0, 320*240*2);
gp2x_video_flip();
}
static void gp2x_memcpy_buffers(int buffers, void *data, int offset, int len)
{
char *dst;
if (buffers & (1<<0)) { dst = (char *)gp2x_screens[0] + offset; if (dst != data) memcpy(dst, data, len); }
if (buffers & (1<<1)) { dst = (char *)gp2x_screens[1] + offset; if (dst != data) memcpy(dst, data, len); }
if (buffers & (1<<2)) { dst = (char *)gp2x_screens[2] + offset; if (dst != data) memcpy(dst, data, len); }
if (buffers & (1<<3)) { dst = (char *)gp2x_screens[3] + offset; if (dst != data) memcpy(dst, data, len); }
}
void gp2x_memcpy_all_buffers(void *data, int offset, int len)
{
gp2x_memcpy_buffers(0xf, data, offset, 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);
}
/* common */
char cpu_clk_name[16] = "GP2X CPU clocks";
void plat_video_menu_enter(int is_rom_loaded)
{
@ -26,19 +66,70 @@ void plat_video_menu_enter(int is_rom_loaded)
gp2x_memcpy_buffers((1<<2), g_screen_ptr, 0, 320*240*2);
// switch to 16bpp
gp2x_video_changemode2(16);
gp2x_video_changemode_ll(16);
gp2x_video_RGB_setscaling(0, 320, 240);
gp2x_video_flip2();
}
void plat_video_menu_begin(void)
{
gp2x_pd_clone_buffer2();
memcpy(g_screen_ptr, gp2x_screens[2], 320*240*2);
}
void plat_video_menu_end(void)
{
gp2x_video_flush_cache();
// FIXME
// gp2x_video_flush_cache();
gp2x_video_flip2();
}
void plat_init(void)
{
gp2x_soc_t soc;
soc = soc_detect();
switch (soc)
{
case SOCID_MMSP2:
mmsp2_init();
break;
case SOCID_POLLUX:
pollux_init();
strcpy(cpu_clk_name, "Wiz CPU clock");
break;
default:
fprintf(stderr, "could not recognize SoC, bailing out.\n");
exit(1);
}
gp2x_memset_all_buffers(0, 0, 320*240*2);
// snd
sndout_oss_init();
}
void plat_finish(void)
{
switch (gp2x_soc)
{
case SOCID_MMSP2:
mmsp2_finish();
break;
case SOCID_POLLUX:
pollux_finish();
break;
}
gp2x_video_changemode(16);
sndout_oss_exit();
}
void lprintf(const char *fmt, ...)
{
va_list vl;
va_start(vl, fmt);
vprintf(fmt, vl);
va_end(vl);
}

78
gp2x/soc.c Normal file
View file

@ -0,0 +1,78 @@
#include <stdio.h>
#include <string.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <sys/mman.h>
#include <unistd.h>
#include "soc.h"
#include "../common/emu.h"
gp2x_soc_t gp2x_soc = -1;
gp2x_soc_t soc_detect(void)
{
volatile unsigned short *memregs;
volatile unsigned int *memregl;
int pollux_chipname[0x30/4 + 1];
char *pollux_chipname_c = (char *)pollux_chipname;
gp2x_soc_t ret = -1;
int memdev;
int i;
memdev = open("/dev/mem", O_RDONLY);
if (memdev == -1)
{
perror("open(/dev/mem)");
return -1;
}
memregs = mmap(0, 0x20000, PROT_READ, MAP_SHARED, memdev, 0xc0000000);
if (memregs == MAP_FAILED)
{
perror("mmap(memregs)");
close(memdev);
return -1;
}
memregl = (volatile void *)memregs;
if (memregs[0x1836>>1] == 0x2330)
{
printf("looks like this is MMSP2\n");
ret = SOCID_MMSP2;
goto out;
}
/* perform word reads. Byte reads might also work,
* but we don't want to play with that. */
for (i = 0; i < 0x30; i += 4)
{
pollux_chipname[i >> 2] = memregl[(0x1f810 + i) >> 2];
}
pollux_chipname_c[0x30] = 0;
for (i = 0; i < 0x30; i++)
{
unsigned char c = pollux_chipname_c[i];
if (c < 0x20 || c > 0x7f)
goto not_pollux_like;
}
printf("found pollux-like id: \"%s\"\n", pollux_chipname_c);
if (strncmp(pollux_chipname_c, "MAGICEYES-LEAPFROG-LF1000", 25) ||
strncmp(pollux_chipname_c, "MAGICEYES-POLLUX", 16))
{
ret = SOCID_POLLUX;
goto out;
}
not_pollux_like:
out:
munmap((void *)memregs, 0x20000);
close(memdev);
gp2x_soc = ret;
return ret;
}

21
gp2x/soc.h Normal file
View file

@ -0,0 +1,21 @@
typedef enum {
SOCID_MMSP2 = 1,
SOCID_POLLUX,
} gp2x_soc_t;
extern gp2x_soc_t gp2x_soc;
gp2x_soc_t soc_detect(void);
void mmsp2_init(void);
void mmsp2_finish(void);
void pollux_init(void);
void pollux_finish(void);
void gp2x_video_flip(void);
void gp2x_video_flip2(void);
void gp2x_video_changemode_ll(int bpp);
void gp2x_video_setpalette(int *pal, int len);
void gp2x_video_RGB_setscaling(int ln_offs, int W, int H);
void gp2x_video_wait_vsync(void);

View file

@ -1,57 +1,33 @@
/**
* 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 <stdarg.h>
#include <string.h>
#include <unistd.h>
#include <sys/mman.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <errno.h>
#include <sys/mman.h>
#include <unistd.h>
#include "soc.h"
#include "soc_mmsp2.h"
#include "gp2x.h"
#include "../linux/sndout_oss.h"
#include "../common/arm_utils.h"
#include "../common/arm_linux.h"
#include "../common/emu.h"
#include "../common/arm_utils.h"
volatile unsigned short *gp2x_memregs;
//static
volatile unsigned long *gp2x_memregl;
static void *gp2x_screens[4];
extern void *gp2x_screens[4];
static int screensel = 0;
//static
int memdev = 0;
int memdev = 0; /* used by code940 */
static int touchdev = -1;
static int touchcal[7] = { 6203, 0, -1501397, 0, -4200, 16132680, 65536 };
#define FRAMEBUFF_WHOLESIZE (0x30000*4) // 320*240*2 + some more
#define FRAMEBUFF_ADDR0 (0x4000000-FRAMEBUFF_WHOLESIZE)
#define FRAMEBUFF_ADDR1 (FRAMEBUFF_ADDR0+0x30000)
#define FRAMEBUFF_ADDR2 (FRAMEBUFF_ADDR1+0x30000)
#define FRAMEBUFF_ADDR3 (FRAMEBUFF_ADDR2+0x30000)
#define FRAMEBUFF_SIZE 0x30000
#define FRAMEBUFF_WHOLESIZE (FRAMEBUFF_SIZE*4) // 320*240*2 + some more
#define FRAMEBUFF_ADDR0 (0x4000000 - FRAMEBUFF_WHOLESIZE)
#define FRAMEBUFF_ADDR1 (FRAMEBUFF_ADDR0 + FRAMEBUFF_SIZE)
#define FRAMEBUFF_ADDR2 (FRAMEBUFF_ADDR1 + FRAMEBUFF_SIZE)
#define FRAMEBUFF_ADDR3 (FRAMEBUFF_ADDR2 + FRAMEBUFF_SIZE)
static const int gp2x_screenaddrs[4] = { FRAMEBUFF_ADDR0, FRAMEBUFF_ADDR1, FRAMEBUFF_ADDR2, FRAMEBUFF_ADDR3 };
static int gp2x_screenaddrs_use[4];
@ -87,34 +63,24 @@ void gp2x_video_flip2(void)
g_screen_ptr = gp2x_screens[++screensel&1];
}
void gp2x_video_changemode2(int bpp)
void gp2x_video_changemode_ll(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_memregs[0x28DA>>1] = (((bpp+1)/8)<<9)|0xAB; /*8/15/16/24bpp...*/
gp2x_memregs[0x290C>>1] = 320*((bpp+1)/8); /*line width in bytes*/
}
void gp2x_video_changemode(int bpp)
{
gp2x_video_changemode2(bpp);
gp2x_memset_all_buffers(0, 0, 320*240*2);
gp2x_video_flip();
}
void gp2x_video_setpalette(int *pal, int len)
{
unsigned short *g=(unsigned short *)pal;
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++;
while (len--)
*memreg = *g++;
}
// TV Compatible function //
void gp2x_video_RGB_setscaling(int ln_offs, int W, int H)
{
@ -149,52 +115,30 @@ void gp2x_video_RGB_setscaling(int ln_offs, int W, int H)
gp2x_memregl[0x2908>>2]=(unsigned long)((float)escalah *bpp *(H/240.0));
}
void gp2x_video_wait_vsync(void)
{
unsigned short v = gp2x_memregs[0x1182>>1];
while (!((v ^ gp2x_memregs[0x1182>>1]) & 0x10)) spend_cycles(1024);
while (!((v ^ gp2x_memregs[0x1182>>1]) & 0x10))
spend_cycles(1024);
}
void gp2x_video_flush_cache(void)
/* 940 */
void pause940(int yes)
{
// since we are using the mmu hack, we must flush the cache first
cache_flush_d_inval_i(g_screen_ptr, (char *)g_screen_ptr + 320*240*2);
if (yes)
gp2x_memregs[0x0904>>1] &= 0xFFFE;
else
gp2x_memregs[0x0904>>1] |= 1;
}
void gp2x_memcpy_buffers(int buffers, void *data, int offset, int len)
void reset940(int yes, int bank)
{
char *dst;
if (buffers & (1<<0)) { dst = (char *)gp2x_screens[0] + offset; if (dst != data) memcpy(dst, data, len); }
if (buffers & (1<<1)) { dst = (char *)gp2x_screens[1] + offset; if (dst != data) memcpy(dst, data, len); }
if (buffers & (1<<2)) { dst = (char *)gp2x_screens[2] + offset; if (dst != data) memcpy(dst, data, len); }
if (buffers & (1<<3)) { dst = (char *)gp2x_screens[3] + offset; if (dst != data) memcpy(dst, data, len); }
}
void gp2x_memcpy_all_buffers(void *data, int offset, int len)
{
gp2x_memcpy_buffers(0xf, data, offset, 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);
}
void gp2x_pd_clone_buffer2(void)
{
memcpy(g_screen_ptr, gp2x_screens[2], 320*240*2);
gp2x_memregs[0x3B48>>1] = ((yes&1) << 7) | (bank & 0x03);
}
/* these are not quite MMSP2 related,
* more to GP2X F100/F200 consoles themselves. */
typedef struct ucb1x00_ts_event
{
unsigned short pressure;
@ -214,7 +158,7 @@ int gp2x_touchpad_read(int *x, int *y)
retval = read(touchdev, &event, sizeof(event));
if (retval <= 0) {
printf("touch read failed %i %i\n", retval, errno);
perror("touch read failed");
return -1;
}
// this is to ignore the messed-up 4.1.x driver
@ -227,22 +171,6 @@ int gp2x_touchpad_read(int *x, int *y)
return zero_seen ? event.pressure : 0;
}
/* 940 */
void Pause940(int yes)
{
if(yes)
gp2x_memregs[0x0904>>1] &= 0xFFFE;
else
gp2x_memregs[0x0904>>1] |= 1;
}
void Reset940(int yes, int bank)
{
gp2x_memregs[0x3B48>>1] = ((yes&1) << 7) | (bank & 0x03);
}
static void proc_set(const char *path, const char *val)
{
FILE *f;
@ -270,10 +198,9 @@ static void proc_set(const char *path, const char *val)
}
/* common */
void gp2x_init(void)
void mmsp2_init(void)
{
printf("entering init()\n"); fflush(stdout);
int i;
memdev = open("/dev/mem", O_RDWR);
if (memdev == -1)
@ -283,8 +210,7 @@ void gp2x_init(void)
}
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)
if (gp2x_memregs == MAP_FAILED)
{
perror("mmap(memregs)");
exit(1);
@ -293,16 +219,20 @@ void gp2x_init(void)
gp2x_memregs[0x2880>>1] &= ~0x383; // disable cursor, subpict, osd, video layers
gp2x_screens[0] = mmap(0, FRAMEBUFF_WHOLESIZE, PROT_WRITE, MAP_SHARED, memdev, FRAMEBUFF_ADDR0);
if(gp2x_screens[0] == MAP_FAILED)
gp2x_screens[0] = mmap(0, FRAMEBUFF_WHOLESIZE, PROT_WRITE, MAP_SHARED,
memdev, gp2x_screenaddrs[0]);
if (gp2x_screens[0] == MAP_FAILED)
{
perror("mmap(g_screen_ptr)");
exit(1);
}
printf("framebuffers point to %p\n", gp2x_screens[0]);
gp2x_screens[1] = (char *) gp2x_screens[0]+0x30000;
gp2x_screens[2] = (char *) gp2x_screens[1]+0x30000;
gp2x_screens[3] = (char *) gp2x_screens[2]+0x30000;
printf("framebuffers:\n");
printf(" %08x -> %p\n", gp2x_screenaddrs[0], gp2x_screens[0]);
for (i = 1; i < 4; i++)
{
gp2x_screens[i] = (char *) gp2x_screens[i - 1] + FRAMEBUFF_SIZE;
printf(" %08x -> %p\n", gp2x_screenaddrs[i], gp2x_screens[i]);
}
g_screen_ptr = gp2x_screens[0];
screensel = 0;
@ -313,10 +243,6 @@ void gp2x_init(void)
gp2x_screenaddr_old[3] = gp2x_memregs[0x2914>>1];
memcpy(gp2x_screenaddrs_use, gp2x_screenaddrs, sizeof(gp2x_screenaddrs));
gp2x_memset_all_buffers(0, 0, 320*240*2);
// snd
sndout_oss_init();
// touchscreen
touchdev = open("/dev/touchscreen/wm97xx", O_RDONLY);
@ -333,18 +259,13 @@ void gp2x_init(void)
/* disable Linux read-ahead */
proc_set("/proc/sys/vm/max-readahead", "0\n");
proc_set("/proc/sys/vm/min-readahead", "0\n");
printf("exitting init()\n"); fflush(stdout);
}
char *ext_menu = 0, *ext_state = 0;
void gp2x_deinit(void)
void mmsp2_finish(void)
{
Reset940(1, 3);
Pause940(1);
reset940(1, 3);
pause940(1);
gp2x_video_changemode(15);
gp2x_memregs[0x290E>>1] = gp2x_screenaddr_old[0];
gp2x_memregs[0x2910>>1] = gp2x_screenaddr_old[1];
gp2x_memregs[0x2912>>1] = gp2x_screenaddr_old[2];
@ -353,33 +274,7 @@ void gp2x_deinit(void)
munmap(gp2x_screens[0], FRAMEBUFF_WHOLESIZE);
munmap((void *)gp2x_memregs, 0x10000);
close(memdev);
if (touchdev >= 0) close(touchdev);
sndout_oss_exit();
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);
}
}
/* lprintf */
void lprintf(const char *fmt, ...)
{
va_list vl;
va_start(vl, fmt);
vprintf(fmt, vl);
va_end(vl);
if (touchdev >= 0)
close(touchdev);
}

9
gp2x/soc_mmsp2.h Normal file
View file

@ -0,0 +1,9 @@
extern int memdev;
extern volatile unsigned short *gp2x_memregs;
extern volatile unsigned long *gp2x_memregl;
/* 940 core */
void pause940(int yes);
void reset940(int yes, int bank);

9
gp2x/soc_pollux.c Normal file
View file

@ -0,0 +1,9 @@
void pollux_init(void)
{
}
void pollux_finish(void)
{
}

View file

@ -1,4 +1,4 @@
/* faking/emulating gp2x.c by using gtk */
/* faking/emulating gp2x by using gtk */
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
@ -27,7 +27,6 @@ static const char *verstring = "PicoDrive " VERSION;
static int scr_changed = 0, scr_w = SCREEN_WIDTH, scr_h = SCREEN_HEIGHT;
// dummies
char *ext_menu = 0, *ext_state = 0;
int mix_32_to_16l_level;
/* gtk */
@ -211,7 +210,7 @@ static void realloc_screen(void)
scr_changed = 0;
}
void gp2x_init(void)
void plat_init(void)
{
printf("entering init()\n"); fflush(stdout);
@ -226,7 +225,7 @@ void gp2x_init(void)
printf("exitting init()\n"); fflush(stdout);
}
void gp2x_deinit(void)
void plat_finish(void)
{
free(g_screen_ptr);
sndout_oss_exit();
@ -309,36 +308,15 @@ void gp2x_video_setpalette(int *pal, int len)
memcpy(current_pal, pal, len*4);
}
void gp2x_video_flush_cache(void)
{
}
void gp2x_video_RGB_setscaling(int v_offs, int W, int H)
{
}
void gp2x_memcpy_buffers(int buffers, void *data, int offset, int len)
{
if ((char *)g_screen_ptr + offset != data)
memcpy((char *)g_screen_ptr + offset, data, len);
}
void gp2x_memcpy_all_buffers(void *data, int offset, int len)
{
memcpy((char *)g_screen_ptr + offset, data, len);
}
void gp2x_memset_all_buffers(int offset, int byte, int len)
{
memset((char *)g_screen_ptr + offset, byte, len);
}
void gp2x_pd_clone_buffer2(void)
{
memset(g_screen_ptr, 0, g_screen_width * g_screen_height * 2);
}
/* joy */
int gp2x_touchpad_read(int *x, int *y)
{
@ -347,11 +325,11 @@ int gp2x_touchpad_read(int *x, int *y)
/* 940 */
int crashed_940 = 0;
void Pause940(int yes)
void pause940(int yes)
{
}
void Reset940(int yes, int bank)
void reset940(int yes, int bank)
{
}

View file

@ -39,8 +39,6 @@
#endif
int select_exits = 0;
static short __attribute__((aligned(4))) sndBuffer[2*44100/50];
static struct timeval noticeMsgTime = { 0, 0 }; // when started showing
static int osd_fps_x;