From fe01739339fe177363948c6fd518352243d5cf37 Mon Sep 17 00:00:00 2001 From: notaz Date: Mon, 21 Jul 2008 21:31:21 +0000 Subject: [PATCH] beginnings for Pandora support git-svn-id: file:///home/notaz/opt/svn/PicoDrive/platform@558 be3aeb3a-fb24-0410-a615-afba39da0efa --- common/common.h | 42 ++++ common/emu.c | 14 +- pandora/Makefile | 238 +++++++++++++++++++++ pandora/main.c | 132 ++++++++++++ pandora/pandora.c | 477 ++++++++++++++++++++++++++++++++++++++++++ pandora/port_config.h | 27 +++ pandora/port_config.s | 14 ++ 7 files changed, 931 insertions(+), 13 deletions(-) create mode 100644 pandora/Makefile create mode 100644 pandora/main.c create mode 100644 pandora/pandora.c create mode 100644 pandora/port_config.h create mode 100644 pandora/port_config.s diff --git a/common/common.h b/common/common.h index 1bef02c..f2964bc 100644 --- a/common/common.h +++ b/common/common.h @@ -76,4 +76,46 @@ void menu_draw_end(void); #define darken_screen() \ menu_darken_bg(psp_screen, psp_screen, SCREEN_WIDTH*SCREEN_HEIGHT, 0) +// ------------------------------------ + +#elif defined(PANDORA) + +// TODO + +#include "../gp2x/gp2x.h" + +#define BTN_UP 0 +#define BTN_DOWN 0 +#define BTN_LEFT 0 +#define BTN_RIGHT 0 + +#define BTN_NORTH 0 +#define BTN_SOUTH 0 +#define BTN_WEST 0 +#define BTN_EAST 0 +#define BTN_L 0 +#define BTN_R 0 + +unsigned long wait_for_input(unsigned long interesting); +void gp2x_pd_clone_buffer2(void); +void menu_darken_bg(void *dst, int pixels, int darker); +void menu_flip(void); + +#define SCREEN_WIDTH 320 +#define SCREEN_HEIGHT 240 +#define SCREEN_BUFFER gp2x_screen + +#define read_buttons(which) \ + wait_for_input(which) +#define read_buttons_async(which) \ + (gp2x_joystick_read(0) & (which)) +#define menu_draw_begin() \ + gp2x_pd_clone_buffer2() +#define clear_screen() \ + memset(gp2x_screen, 0, 320*240*2) +#define darken_screen() \ + menu_darken_bg(gp2x_screen, 320*240, 0) +#define menu_draw_end() \ + menu_flip() + #endif diff --git a/common/emu.c b/common/emu.c index ae1a638..494484b 100644 --- a/common/emu.c +++ b/common/emu.c @@ -15,25 +15,13 @@ #include "fonts.h" #include "lprintf.h" #include "config.h" +#include "common.h" #include #include #include #include -#if defined(__GP2X__) - #include "../gp2x/gp2x.h" - #define SCREEN_WIDTH 320 - #define SCREEN_BUFFER gp2x_screen -#elif defined(__GIZ__) - #include "../gizmondo/giz.h" - #define SCREEN_WIDTH 321 - #define SCREEN_BUFFER giz_screen -#elif defined(PSP) - #include "../psp/psp.h" - #define SCREEN_WIDTH 512 - #define SCREEN_BUFFER psp_screen -#endif char *PicoConfigFile = "config.cfg"; currentConfig_t currentConfig, defaultConfig; diff --git a/pandora/Makefile b/pandora/Makefile new file mode 100644 index 0000000..ffa1d72 --- /dev/null +++ b/pandora/Makefile @@ -0,0 +1,238 @@ +export CROSS = arm-none-linux-gnueabi- + +# settings +#mz80 = 1 +#debug_cyclone = 1 +asm_memory = 1 +asm_render = 1 +asm_ym2612 = 1 +asm_misc = 1 +asm_cdpico = 1 +asm_cdmemory = 1 +amalgamate = 0 +#profile = 1 +#use_musashi = 1 +#up = 1 + + +ifeq "$(debug_cyclone)" "1" +use_cyclone = 1 +use_musashi = 1 +endif +ifeq "$(use_musashi)" "1" +asm_cdpico = 0 +asm_memory = 0 +asm_cdmemory = 0 +else +use_cyclone = 1 +endif + +DEFINC = -I../.. -I. -DARM -DPANDORA +COPT_COMMON = -static -Wall -Winline +ifeq ($(DEBUG),) +COPT_COMMON += -O3 -ftracer -fstrength-reduce -fomit-frame-pointer -fstrict-aliasing -ffast-math +else +COPT_COMMON += -ggdb +endif +ifeq "$(profile)" "1" +COPT_COMMON += -fprofile-generate +endif +ifeq "$(profile)" "2" +COPT_COMMON += -fprofile-use +endif +COPT = $(COPT_COMMON) +ASOPT = +GCC = $(CROSS)gcc +STRIP = $(CROSS)strip +AS = $(CROSS)as +LD = $(CROSS)ld +OBJCOPY = $(CROSS)objcopy + +# frontend +OBJS += pandora.o main.o platform/gp2x/menu.o platform/gp2x/usbjoy.o platform/gp2x/emu.o + +# common +OBJS += platform/common/emu.o platform/common/menu.o platform/common/fonts.o platform/common/config.o \ + platform/common/arm_utils.o platform/common/mp3_helix.o # platform/common/readpng.o + +# Pico +ifeq "$(amalgamate)" "1" +OBJS += ../../PicoAll.o +else +OBJS += Pico/Area.o Pico/Cart.o Pico/Memory.o Pico/Misc.o Pico/Pico.o Pico/Sek.o \ + Pico/VideoPort.o Pico/Draw2.o Pico/Draw.o Pico/Patch.o Pico/Debug.o +# Pico - CD +OBJS += Pico/cd/Pico.o Pico/cd/Memory.o Pico/cd/Sek.o Pico/cd/LC89510.o \ + Pico/cd/cd_sys.o Pico/cd/cd_file.o Pico/cd/cue.o Pico/cd/gfx_cd.o \ + Pico/cd/Area.o Pico/cd/Misc.o Pico/cd/pcm.o Pico/cd/buffering.o +endif +# Pico - Pico +OBJS += Pico/Pico/Pico.o Pico/Pico/Memory.o Pico/Pico/xpcm.o +# Pico - carthw +OBJS += Pico/carthw/carthw.o Pico/carthw/svp/svp.o Pico/carthw/svp/Memory.o \ + Pico/carthw/svp/ssp16.o Pico/carthw/svp/compiler.o Pico/carthw/svp/stub_arm.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 +ifeq "$(asm_misc)" "1" +DEFINC += -D_ASM_MISC_C +OBJS += Pico/misc_asm.o +OBJS += Pico/cd/misc_asm.o +endif +ifeq "$(asm_cdpico)" "1" +DEFINC += -D_ASM_CD_PICO_C +OBJS += Pico/cd/pico_asm.o +endif +ifeq "$(asm_cdmemory)" "1" +DEFINC += -D_ASM_CD_MEMORY_C +OBJS += Pico/cd/memory_asm.o +endif + +# Pico - sound +ifneq "$(amalgamate)" "1" +OBJS += Pico/sound/sound.o +endif +OBJS += Pico/sound/mix_asm.o +OBJS += 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 unzip/unzip_stream.o +# debug +ifeq "$(debug_cyclone)" "1" +OBJS += Pico/DebugCPU.o cpu/musashi/m68kdasm.o +endif +# CPU cores +ifeq "$(use_musashi)" "1" +DEFINC += -DEMU_M68K +OBJS += cpu/musashi/m68kops.o cpu/musashi/m68kcpu.o +endif +ifeq "$(use_cyclone)" "1" +DEFINC += -DEMU_C68K +OBJS += cpu/Cyclone/proj/Cyclone.o cpu/Cyclone/tools/idle.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 + +vpath %.c = ../.. +vpath %.s = ../.. +vpath %.S = ../.. +DIRS = platform platform/gp2x platform/common Pico Pico/cd Pico/Pico Pico/sound Pico/carthw/svp \ + zlib unzip cpu cpu/musashi cpu/Cyclone/proj cpu/Cyclone/tools cpu/mz80 cpu/DrZ80 + + +all: mkdirs PicoDrive + +PicoDrive : $(OBJS) ../common/helix/helix_mp3.a + @echo ">>>" $@ + $(GCC) -o $@ $(COPT) $^ -lm -Wl,-Map=PicoDrive.map # -lpng +ifeq ($(DEBUG),) + $(STRIP) $@ +endif + + +# cleanup +clean: tidy + $(RM) PicoDrive +tidy: + $(RM) $(OBJS) +# rm -rf $(DIRS) # don't clean, gcda may be there +# @make -C ../../cpu/Cyclone/proj -f Makefile.linux clean + + +clean_prof: + find ../.. -name '*.gcno' -delete + find ../.. -name '*.gcda' -delete + + +mkdirs: + mkdir -p $(DIRS) + +.c.o: + @echo ">>>" $< + $(GCC) $(COPT) $(DEFINC) -c $< -o $@ +.s.o: + @echo ">>>" $< + $(GCC) $(COPT) $(DEFINC) -c $< -o $@ +.S.o: + @echo ">>>" $< + $(GCC) $(COPT) $(DEFINC) -c $< -o $@ + +Pico/carthw/svp/compiler.o : ../../Pico/carthw/svp/ssp16.o ../../Pico/carthw/svp/gen_arm.c + +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 $@ +Pico/sound/mix_asm.o : ../../Pico/sound/mix.s + @echo ">>>" $< + $(AS) $(ASOPT) $< -o $@ +Pico/misc_asm.o : ../../Pico/Misc.s + @echo ">>>" $< + $(AS) $(ASOPT) $< -o $@ +Pico/cd/pico_asm.o : ../../Pico/cd/Pico.s + @echo ">>>" $< + $(AS) $(ASOPT) $< -o $@ +Pico/cd/memory_asm.o : ../../Pico/cd/Memory.s + @echo ">>>" $< + $(AS) $(ASOPT) $< -o $@ +Pico/cd/misc_asm.o : ../../Pico/cd/Misc.s + @echo ">>>" $< + $(AS) $(ASOPT) $< -o $@ + +# build Cyclone +../../cpu/Cyclone/proj/Cyclone.s : + @echo building Cyclone... + @make -C ../../cpu/Cyclone/proj CONFIG_FILE=config_pico.h + +../../cpu/musashi/m68kops.c : + @make -C ../../cpu/musashi + +Pico/Pico.o Pico/cd/Pico.o: ../../Pico/PicoFrameHints.c ../../Pico/PicoInt.h +Pico/Memory.o Pico/cd/Memory.o : ../../Pico/MemoryCmn.c ../../Pico/PicoInt.h + +# build helix libs +../common/helix/helix_mp3.a: + make -C ../common/helix + +readme.txt: ../../tools/textfilter ../base_readme.txt + ../../tools/textfilter ../base_readme.txt $@ GP2X + +../../tools/textfilter: ../../tools/textfilter.c + make -C ../../tools/ textfilter + + +# ----------- release ----------- +ifneq ($(findstring rel,$(MAKECMDGOALS)),) +$(error TODO) +ifeq ($(VER),) +$(error need VER) +endif +endif + diff --git a/pandora/main.c b/pandora/main.c new file mode 100644 index 0000000..8261446 --- /dev/null +++ b/pandora/main.c @@ -0,0 +1,132 @@ +// (c) Copyright 2006 notaz, All rights reserved. +// Free for non-commercial use. + +// For commercial use, separate licencing terms must be obtained. + +#include +#include +#include +#include +#include + +#include "../gp2x/gp2x.h" +#include "../gp2x/menu.h" +#include "../common/menu.h" +#include "../common/emu.h" +#include "../common/config.h" +#include "../gp2x/emu.h" +#include "../gp2x/version.h" + + +extern char *ext_menu, *ext_state; +extern int select_exits; +extern char *PicoConfigFile; +int mmuhack_status = 0; // TODO rm +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-2008\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"); + } +} + + +int main(int argc, char *argv[]) +{ + g_argv = argv; + + emu_prepareDefaultConfig(); + emu_ReadConfig(0, 0); + config_readlrom(PicoConfigFile); + + gp2x_init(); + emu_Init(); + menu_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_RestartRun: + engineState = PGS_Running; + + 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(); + + return 0; +} diff --git a/pandora/pandora.c b/pandora/pandora.c new file mode 100644 index 0000000..3fc4690 --- /dev/null +++ b/pandora/pandora.c @@ -0,0 +1,477 @@ +/** + * 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 +#include + +#include "../gp2x/gp2x.h" +#include "../gp2x/usbjoy.h" +#include "../common/arm_utils.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 = -1, mixerdev = -1, touchdev = -1; +static int touchcal[7] = { 6203, 0, -1501397, 0, -4200, 16132680, 65536 }; + +void *gp2x_screen; + +#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: + gp2x_screen = 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: + gp2x_screen = 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 + // (the params are most likely wrong, but they seem to work somehow) + //flushcache(addr, addr + 320*240*2, 0); + flushcache(gp2x_screen, (char *)gp2x_screen + 320*240*2, 0); +} + + +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(gp2x_screen, gp2x_screens[2], 320*240*2); +} + + +unsigned long gp2x_joystick_read(int allow_usb_joy) +{ + int i; + unsigned long value=(gp2x_memregs[0x1198>>1] & 0x00FF); // GPIO M + 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)); // C D + + 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; +} + +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; +} + + +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_SETFMT, &bits); + ioctl(sounddev, SNDCTL_DSP_SPEED, &rate); + 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); + usleep(192*1024); + + 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; +} + + +void gp2x_sound_write(void *buff, int len) +{ + write(sounddev, buff, len); +} + +void gp2x_sound_sync(void) +{ + ioctl(sounddev, SOUND_PCM_SYNC, 0); +} + +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, 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) + { + 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_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) + { + printf("mmap(gp2x_screen) failed with %i\n", errno); + 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; + + gp2x_screen = 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 + 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(); + + // 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); + close(mixerdev); + if (sounddev >= 0) close(sounddev); + if (touchdev >= 0) close(touchdev); + + 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); + } +} + +/* lprintf */ +void lprintf(const char *fmt, ...) +{ + va_list vl; + + va_start(vl, fmt); + vprintf(fmt, vl); + va_end(vl); +} + + +/* fake GP2X */ +int crashed_940 = 0; + +int readpng(void *dest, const char *fname, int what) { return -1; } +void set_gamma(int g100, int A_SNs_curve) {} +void set_FCLK(unsigned MHZ) {} +void set_LCD_custom_rate(int rate) {} +void unset_LCD_custom_rate(void) {} + diff --git a/pandora/port_config.h b/pandora/port_config.h new file mode 100644 index 0000000..22b43cd --- /dev/null +++ b/pandora/port_config.h @@ -0,0 +1,27 @@ +// port specific settings + +#ifndef PORT_CONFIG_H +#define PORT_CONFIG_H + +#define CASE_SENSITIVE_FS 1 // CS filesystem +#define DONT_OPEN_MANY_FILES 0 +#define REDUCE_IO_CALLS 0 +#define SIMPLE_WRITE_SOUND 0 + +// draw.c +#define OVERRIDE_HIGHCOL 0 + +// 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 + +// logging emu events +#define EL_LOGMASK (EL_STATUS|EL_IDLE) // (EL_STATUS|EL_ANOMALY|EL_UIO|EL_SRAMIO|EL_INTS|EL_CDPOLL) // xffff + +//#define dprintf(f,...) printf("%05i:%03i: " f "\n",Pico.m.frame_count,Pico.m.scanline,##__VA_ARGS__) +#define dprintf(x...) + +#endif //PORT_CONFIG_H diff --git a/pandora/port_config.s b/pandora/port_config.s new file mode 100644 index 0000000..5a41036 --- /dev/null +++ b/pandora/port_config.s @@ -0,0 +1,14 @@ +@ vim:filetype=armasm + +@ .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 + +.equiv OVERRIDE_HIGHCOL, 0 +.equiv UNALIGNED_DRAWLINEDEST, 0 + +@ this should be set to one only for GP2X port +.equiv EXTERNAL_YM2612, 1 + -- 2.39.5