From: notaz Date: Wed, 15 Jul 2009 16:13:43 +0000 (+0000) Subject: refactoring for Wiz port; random cleanups X-Git-Tag: v1.85~345 X-Git-Url: https://notaz.gp2x.de/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=421713439805e3d389c420a04afc48fc267eb28f;p=picodrive.git refactoring for Wiz port; random cleanups git-svn-id: file:///home/notaz/opt/svn/PicoDrive@703 be3aeb3a-fb24-0410-a615-afba39da0efa --- diff --git a/platform/common/config.c b/platform/common/config.c index 3ad6a94e..c5ff5386 100644 --- a/platform/common/config.c +++ b/platform/common/config.c @@ -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; diff --git a/platform/common/menu.c b/platform/common/menu.c index eccdefce..0b49234b 100644 --- a/platform/common/menu.c +++ b/platform/common/menu.c @@ -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), diff --git a/platform/common/menu.h b/platform/common/menu.h index a3625f84..430f0022 100644 --- a/platform/common/menu.h +++ b/platform/common/menu.h @@ -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 */ diff --git a/platform/common/plat.h b/platform/common/plat.h index ca1b3f3e..ac7a438c 100644 --- a/platform/common/plat.h +++ b/platform/common/plat.h @@ -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); diff --git a/platform/gp2x/940ctl.c b/platform/gp2x/940ctl.c index 7d7a400d..083036e8 100644 --- a/platform/gp2x/940ctl.c +++ b/platform/gp2x/940ctl.c @@ -11,7 +11,8 @@ #include #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 diff --git a/platform/gp2x/Makefile b/platform/gp2x/Makefile index ea86f6ba..b5ca333c 100644 --- a/platform/gp2x/Makefile +++ b/platform/gp2x/Makefile @@ -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 diff --git a/platform/gp2x/emu.c b/platform/gp2x/emu.c index 69a464ea..585c1d55 100644 --- a/platform/gp2x/emu.c +++ b/platform/gp2x/emu.c @@ -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" diff --git a/platform/gp2x/gp2x.h b/platform/gp2x/gp2x.h index 5bebe74c..3f6dadd8 100644 --- a/platform/gp2x/gp2x.h +++ b/platform/gp2x/gp2x.h @@ -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 diff --git a/platform/gp2x/in_gp2x.c b/platform/gp2x/in_gp2x.c index 213b3d4a..8066ca7e 100644 --- a/platform/gp2x/in_gp2x.c +++ b/platform/gp2x/in_gp2x.c @@ -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; diff --git a/platform/gp2x/main.c b/platform/gp2x/main.c index 0ea8e824..2eed35bd 100644 --- a/platform/gp2x/main.c +++ b/platform/gp2x/main.c @@ -10,7 +10,6 @@ #include #include -#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 launch a custom program on exit instead of default gp2xmenu\n" - "-state pass '-state param' to the menu program\n" - "-config 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 if ROM is specified, try loading slot \n"); + printf("options:\n" + " -config use specified config file instead of default 'config.cfg'\n" + " -loadstate if ROM is specified, try loading slot \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; diff --git a/platform/gp2x/plat.c b/platform/gp2x/plat.c index a2b83944..01606349 100644 --- a/platform/gp2x/plat.c +++ b/platform/gp2x/plat.c @@ -1,11 +1,51 @@ +#include +#include #include +#include #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); +} + diff --git a/platform/gp2x/soc.c b/platform/gp2x/soc.c new file mode 100644 index 00000000..d34077db --- /dev/null +++ b/platform/gp2x/soc.c @@ -0,0 +1,78 @@ +#include +#include +#include +#include +#include +#include +#include + +#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; +} + diff --git a/platform/gp2x/soc.h b/platform/gp2x/soc.h new file mode 100644 index 00000000..c47db178 --- /dev/null +++ b/platform/gp2x/soc.h @@ -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); diff --git a/platform/gp2x/gp2x.c b/platform/gp2x/soc_mmsp2.c similarity index 56% rename from platform/gp2x/gp2x.c rename to platform/gp2x/soc_mmsp2.c index f350352f..86e3ac87 100644 --- a/platform/gp2x/gp2x.c +++ b/platform/gp2x/soc_mmsp2.c @@ -1,385 +1,280 @@ -/** - * 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 -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include "gp2x.h" -#include "../linux/sndout_oss.h" -#include "../common/arm_utils.h" -#include "../common/arm_linux.h" -#include "../common/emu.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 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) - -static const int gp2x_screenaddrs[4] = { FRAMEBUFF_ADDR0, FRAMEBUFF_ADDR1, FRAMEBUFF_ADDR2, FRAMEBUFF_ADDR3 }; -static int gp2x_screenaddrs_use[4]; -static unsigned short gp2x_screenaddr_old[4]; - - -/* video stuff */ -void gp2x_video_flip(void) -{ - unsigned short lsw = (unsigned short) gp2x_screenaddrs_use[screensel&3]; - unsigned short msw = (unsigned short)(gp2x_screenaddrs_use[screensel&3] >> 16); - - gp2x_memregs[0x2910>>1] = msw; - gp2x_memregs[0x2914>>1] = msw; - gp2x_memregs[0x290E>>1] = lsw; - gp2x_memregs[0x2912>>1] = lsw; - - // jump to other buffer: - g_screen_ptr = gp2x_screens[++screensel&3]; -} - -/* doulblebuffered flip */ -void gp2x_video_flip2(void) -{ - unsigned short msw = (unsigned short)(gp2x_screenaddrs_use[screensel&1] >> 16); - - gp2x_memregs[0x2910>>1] = msw; - gp2x_memregs[0x2914>>1] = msw; - gp2x_memregs[0x290E>>1] = 0; - gp2x_memregs[0x2912>>1] = 0; - - // jump to other buffer: - g_screen_ptr = gp2x_screens[++screensel&1]; -} - - -void gp2x_video_changemode2(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*/ -} - - -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; - 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 ln_offs, int W, int H) -{ - float escalaw, escalah; - int bpp = (gp2x_memregs[0x28DA>>1]>>9)&0x3; - unsigned short scalw; - - // set offset - gp2x_screenaddrs_use[0] = gp2x_screenaddrs[0] + ln_offs * 320 * bpp; - gp2x_screenaddrs_use[1] = gp2x_screenaddrs[1] + ln_offs * 320 * bpp; - gp2x_screenaddrs_use[2] = gp2x_screenaddrs[2] + ln_offs * 320 * bpp; - gp2x_screenaddrs_use[3] = gp2x_screenaddrs[3] + ln_offs * 320 * bpp; - - 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 - scalw = (unsigned short)((float)escalaw *(W/320.0)); - /* if there is no horizontal scaling, vertical doesn't work. Here is a nasty wrokaround... */ - if (H != 240 && W == 320) scalw--; - gp2x_memregs[0x2906>>1]=scalw; - // scale vertical - 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); -} - - -void gp2x_video_flush_cache(void) -{ - // 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); -} - - -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); -} - - -void gp2x_pd_clone_buffer2(void) -{ - memcpy(g_screen_ptr, gp2x_screens[2], 320*240*2); -} - - -typedef struct ucb1x00_ts_event -{ - unsigned short pressure; - unsigned short x; - unsigned short y; - unsigned short pad; - struct timeval stamp; -} UCB1X00_TS_EVENT; - -int gp2x_touchpad_read(int *x, int *y) -{ - UCB1X00_TS_EVENT event; - static int zero_seen = 0; - int retval; - - if (touchdev < 0) return -1; - - retval = read(touchdev, &event, sizeof(event)); - if (retval <= 0) { - printf("touch read failed %i %i\n", retval, errno); - return -1; - } - // this is to ignore the messed-up 4.1.x driver - if (event.pressure == 0) zero_seen = 1; - - if (x) *x = (event.x * touchcal[0] + touchcal[2]) >> 16; - if (y) *y = (event.y * touchcal[4] + touchcal[5]) >> 16; - // printf("read %i %i %i\n", event.pressure, *x, *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; - char tmp[16]; - - f = fopen(path, "w"); - if (f == NULL) { - printf("failed to open: %s\n", path); - return; - } - - fprintf(f, "0\n"); - fclose(f); - - printf("\"%s\" is set to: ", path); - f = fopen(path, "r"); - if (f == NULL) { - printf("(open failed)\n"); - return; - } - - fgets(tmp, sizeof(tmp), f); - printf("%s", tmp); - fclose(f); -} - - -/* common */ -void gp2x_init(void) -{ - printf("entering init()\n"); fflush(stdout); - - memdev = open("/dev/mem", O_RDWR); - if (memdev == -1) - { - perror("open(\"/dev/mem\")"); - 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) - { - perror("mmap(memregs)"); - exit(1); - } - gp2x_memregl = (unsigned long *) gp2x_memregs; - - 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) - { - 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; - - g_screen_ptr = gp2x_screens[0]; - screensel = 0; - - gp2x_screenaddr_old[0] = gp2x_memregs[0x290E>>1]; - gp2x_screenaddr_old[1] = gp2x_memregs[0x2910>>1]; - gp2x_screenaddr_old[2] = gp2x_memregs[0x2912>>1]; - 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); - if (touchdev >= 0) { - FILE *pcf = fopen("/etc/pointercal", "r"); - if (pcf) { - fscanf(pcf, "%d %d %d %d %d %d %d", &touchcal[0], &touchcal[1], - &touchcal[2], &touchcal[3], &touchcal[4], &touchcal[5], &touchcal[6]); - fclose(pcf); - } - printf("found touchscreen/wm97xx\n"); - } - - /* 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) -{ - 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]; - gp2x_memregs[0x2914>>1] = gp2x_screenaddr_old[3]; - - 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); -} - +#include +#include +#include +#include +#include +#include +#include +#include + +#include "soc.h" +#include "soc_mmsp2.h" +#include "gp2x.h" +#include "../common/emu.h" +#include "../common/arm_utils.h" + +volatile unsigned short *gp2x_memregs; +volatile unsigned long *gp2x_memregl; +extern void *gp2x_screens[4]; +static int screensel = 0; + +int memdev = 0; /* used by code940 */ +static int touchdev = -1; +static int touchcal[7] = { 6203, 0, -1501397, 0, -4200, 16132680, 65536 }; + +#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]; +static unsigned short gp2x_screenaddr_old[4]; + + +/* video stuff */ +void gp2x_video_flip(void) +{ + unsigned short lsw = (unsigned short) gp2x_screenaddrs_use[screensel&3]; + unsigned short msw = (unsigned short)(gp2x_screenaddrs_use[screensel&3] >> 16); + + gp2x_memregs[0x2910>>1] = msw; + gp2x_memregs[0x2914>>1] = msw; + gp2x_memregs[0x290E>>1] = lsw; + gp2x_memregs[0x2912>>1] = lsw; + + // jump to other buffer: + g_screen_ptr = gp2x_screens[++screensel&3]; +} + +/* doulblebuffered flip */ +void gp2x_video_flip2(void) +{ + unsigned short msw = (unsigned short)(gp2x_screenaddrs_use[screensel&1] >> 16); + + gp2x_memregs[0x2910>>1] = msw; + gp2x_memregs[0x2914>>1] = msw; + gp2x_memregs[0x290E>>1] = 0; + gp2x_memregs[0x2912>>1] = 0; + + // jump to other buffer: + g_screen_ptr = gp2x_screens[++screensel&1]; +} + +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*/ +} + +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 ln_offs, int W, int H) +{ + float escalaw, escalah; + int bpp = (gp2x_memregs[0x28DA>>1]>>9)&0x3; + unsigned short scalw; + + // set offset + gp2x_screenaddrs_use[0] = gp2x_screenaddrs[0] + ln_offs * 320 * bpp; + gp2x_screenaddrs_use[1] = gp2x_screenaddrs[1] + ln_offs * 320 * bpp; + gp2x_screenaddrs_use[2] = gp2x_screenaddrs[2] + ln_offs * 320 * bpp; + gp2x_screenaddrs_use[3] = gp2x_screenaddrs[3] + ln_offs * 320 * bpp; + + 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 + scalw = (unsigned short)((float)escalaw *(W/320.0)); + /* if there is no horizontal scaling, vertical doesn't work. Here is a nasty wrokaround... */ + if (H != 240 && W == 320) scalw--; + gp2x_memregs[0x2906>>1]=scalw; + // scale vertical + 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); +} + +/* 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); +} + + +/* these are not quite MMSP2 related, + * more to GP2X F100/F200 consoles themselves. */ +typedef struct ucb1x00_ts_event +{ + unsigned short pressure; + unsigned short x; + unsigned short y; + unsigned short pad; + struct timeval stamp; +} UCB1X00_TS_EVENT; + +int gp2x_touchpad_read(int *x, int *y) +{ + UCB1X00_TS_EVENT event; + static int zero_seen = 0; + int retval; + + if (touchdev < 0) return -1; + + retval = read(touchdev, &event, sizeof(event)); + if (retval <= 0) { + perror("touch read failed"); + return -1; + } + // this is to ignore the messed-up 4.1.x driver + if (event.pressure == 0) zero_seen = 1; + + if (x) *x = (event.x * touchcal[0] + touchcal[2]) >> 16; + if (y) *y = (event.y * touchcal[4] + touchcal[5]) >> 16; + // printf("read %i %i %i\n", event.pressure, *x, *y); + + return zero_seen ? event.pressure : 0; +} + +static void proc_set(const char *path, const char *val) +{ + FILE *f; + char tmp[16]; + + f = fopen(path, "w"); + if (f == NULL) { + printf("failed to open: %s\n", path); + return; + } + + fprintf(f, "0\n"); + fclose(f); + + printf("\"%s\" is set to: ", path); + f = fopen(path, "r"); + if (f == NULL) { + printf("(open failed)\n"); + return; + } + + fgets(tmp, sizeof(tmp), f); + printf("%s", tmp); + fclose(f); +} + + +void mmsp2_init(void) +{ + int i; + + memdev = open("/dev/mem", O_RDWR); + if (memdev == -1) + { + perror("open(\"/dev/mem\")"); + exit(1); + } + + gp2x_memregs = mmap(0, 0x10000, PROT_READ|PROT_WRITE, MAP_SHARED, memdev, 0xc0000000); + if (gp2x_memregs == MAP_FAILED) + { + perror("mmap(memregs)"); + exit(1); + } + gp2x_memregl = (unsigned long *) gp2x_memregs; + + gp2x_memregs[0x2880>>1] &= ~0x383; // disable cursor, subpict, osd, video layers + + 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:\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; + + gp2x_screenaddr_old[0] = gp2x_memregs[0x290E>>1]; + gp2x_screenaddr_old[1] = gp2x_memregs[0x2910>>1]; + gp2x_screenaddr_old[2] = gp2x_memregs[0x2912>>1]; + gp2x_screenaddr_old[3] = gp2x_memregs[0x2914>>1]; + + memcpy(gp2x_screenaddrs_use, gp2x_screenaddrs, sizeof(gp2x_screenaddrs)); + + // touchscreen + touchdev = open("/dev/touchscreen/wm97xx", O_RDONLY); + if (touchdev >= 0) { + FILE *pcf = fopen("/etc/pointercal", "r"); + if (pcf) { + fscanf(pcf, "%d %d %d %d %d %d %d", &touchcal[0], &touchcal[1], + &touchcal[2], &touchcal[3], &touchcal[4], &touchcal[5], &touchcal[6]); + fclose(pcf); + } + printf("found touchscreen/wm97xx\n"); + } + + /* disable Linux read-ahead */ + proc_set("/proc/sys/vm/max-readahead", "0\n"); + proc_set("/proc/sys/vm/min-readahead", "0\n"); +} + +void mmsp2_finish(void) +{ + reset940(1, 3); + pause940(1); + + gp2x_memregs[0x290E>>1] = gp2x_screenaddr_old[0]; + gp2x_memregs[0x2910>>1] = gp2x_screenaddr_old[1]; + gp2x_memregs[0x2912>>1] = gp2x_screenaddr_old[2]; + gp2x_memregs[0x2914>>1] = gp2x_screenaddr_old[3]; + + munmap(gp2x_screens[0], FRAMEBUFF_WHOLESIZE); + munmap((void *)gp2x_memregs, 0x10000); + close(memdev); + if (touchdev >= 0) + close(touchdev); +} + diff --git a/platform/gp2x/soc_mmsp2.h b/platform/gp2x/soc_mmsp2.h new file mode 100644 index 00000000..493bf9f6 --- /dev/null +++ b/platform/gp2x/soc_mmsp2.h @@ -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); + diff --git a/platform/gp2x/soc_pollux.c b/platform/gp2x/soc_pollux.c new file mode 100644 index 00000000..c8ca1b85 --- /dev/null +++ b/platform/gp2x/soc_pollux.c @@ -0,0 +1,9 @@ + +void pollux_init(void) +{ +} + +void pollux_finish(void) +{ +} + diff --git a/platform/linux/gp2x.c b/platform/linux/gp2x.c index a22e079f..a58b4516 100644 --- a/platform/linux/gp2x.c +++ b/platform/linux/gp2x.c @@ -1,4 +1,4 @@ -/* faking/emulating gp2x.c by using gtk */ +/* faking/emulating gp2x by using gtk */ #include #include #include @@ -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) { } diff --git a/platform/pandora/emu.c b/platform/pandora/emu.c index 16fc7cd1..a6f990ae 100644 --- a/platform/pandora/emu.c +++ b/platform/pandora/emu.c @@ -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;