From 7fd581f40bb5273e81dc08afdd55224c26c8fb9e Mon Sep 17 00:00:00 2001 From: notaz Date: Sun, 8 Mar 2009 22:49:51 +0000 Subject: [PATCH] bring pandora to buildable state. Some cleanups and fixes along the way. git-svn-id: file:///home/notaz/opt/svn/PicoDrive/platform@650 be3aeb3a-fb24-0410-a615-afba39da0efa --- common/input.c | 2 +- common/menu.h | 3 + gp2x/main.c | 4 +- pandora/Makefile | 4 +- pandora/emu.c | 93 ++++++++++++++---------------- pandora/main.c | 22 +++----- pandora/pandora.c | 140 +++------------------------------------------- 7 files changed, 66 insertions(+), 202 deletions(-) diff --git a/common/input.c b/common/input.c index 0f6b6e4..81f6e16 100644 --- a/common/input.c +++ b/common/input.c @@ -257,8 +257,8 @@ int in_update_keycode(int *dev_id_out, int *is_down_out, int timeout_ms) int result = -1, dev_id = 0, is_down, result_menu; int fds_hnds[IN_MAX_DEVS]; int i, ret, count = 0; + in_drv_t *drv = NULL; unsigned int ticks; - in_drv_t *drv; if (in_have_async_devs) { result = in_update_kc_async(&dev_id, &is_down, timeout_ms); diff --git a/common/menu.h b/common/menu.h index 3f77603..a3625f8 100644 --- a/common/menu.h +++ b/common/menu.h @@ -156,6 +156,9 @@ void menu_init(void); void text_out16(int x, int y, const char *texto, ...); void me_update_msg(const char *msg); +void menu_loop(void); +int menu_loop_tray(void); + menu_entry *me_list_get_first(void); menu_entry *me_list_get_next(void); diff --git a/gp2x/main.c b/gp2x/main.c index 95a181c..1aad15c 100644 --- a/gp2x/main.c +++ b/gp2x/main.c @@ -62,8 +62,8 @@ void parse_cmd_line(int argc, char *argv[]) } else { /* External Frontend: ROM Name */ FILE *f; - strncpy(rom_fname_reload, argv[x], PATH_MAX); - rom_fname_reload[PATH_MAX-1] = 0; + strncpy(rom_fname_reload, argv[x], sizeof(rom_fname_reload)); + rom_fname_reload[sizeof(rom_fname_reload) - 1] = 0; f = fopen(rom_fname_reload, "rb"); if (f) fclose(f); else unrecognized = 1; diff --git a/pandora/Makefile b/pandora/Makefile index a8f552c..02ef609 100644 --- a/pandora/Makefile +++ b/pandora/Makefile @@ -52,13 +52,13 @@ LD = $(CROSS)ld OBJCOPY = $(CROSS)objcopy # frontend -OBJS += pandora.o main.o emu.o asm_utils.o platform/gp2x/menu.o +OBJS += pandora.o main.o emu.o asm_utils.o plat.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/arm_linux.o \ platform/common/readpng.o platform/common/input.o platform/linux/in_evdev.o \ - platform/linux/sndout_oss.o + platform/linux/sndout_oss.o platform/linux/plat.o # Pico ifeq "$(amalgamate)" "1" diff --git a/pandora/emu.c b/pandora/emu.c index 673c963..3b9e62c 100644 --- a/pandora/emu.c +++ b/pandora/emu.c @@ -14,12 +14,10 @@ #include -#include "../gp2x/emu.h" -#include "../gp2x/menu.h" -#include "../gp2x/gp2x.h" #include "../common/arm_utils.h" #include "../common/fonts.h" #include "../common/emu.h" +#include "../common/menu.h" #include "../common/config.h" #include "../common/common.h" #include "../common/input.h" @@ -182,7 +180,7 @@ void osd_text(int x, int y, const char *text) x &= ~3; // align x len = (len+3) >> 2; for (h = 0; h < 8; h++) { - p = (int *) ((unsigned char *) gp2x_screen+x+g_screen_width*(y+h)); + p = (int *) ((unsigned char *) g_screen_ptr+x+g_screen_width*(y+h)); for (i = len; i; i--, p++) *p = 0xe0e0e0e0; } emu_textOut8(x, y, text); @@ -191,7 +189,7 @@ void osd_text(int x, int y, const char *text) x &= ~1; // align x len++; for (h = 0; h < 16; h++) { - p = (int *) ((unsigned short *) gp2x_screen+x+g_screen_width*(y+h)); + p = (int *) ((unsigned short *) g_screen_ptr+x+g_screen_width*(y+h)); for (i = len; i; i--, p++) *p = 0;//(*p>>2)&0x39e7; } textOut16(x, y, text); @@ -209,15 +207,15 @@ static void draw_cd_leds(void) // 8-bit modes unsigned int col_g = (old_reg & 2) ? 0xc0c0c0c0 : 0xe0e0e0e0; unsigned int col_r = (old_reg & 1) ? 0xd0d0d0d0 : 0xe0e0e0e0; - *(unsigned int *)((char *)gp2x_screen + g_screen_width*2+ 4) = - *(unsigned int *)((char *)gp2x_screen + g_screen_width*3+ 4) = - *(unsigned int *)((char *)gp2x_screen + g_screen_width*4+ 4) = col_g; - *(unsigned int *)((char *)gp2x_screen + g_screen_width*2+12) = - *(unsigned int *)((char *)gp2x_screen + g_screen_width*3+12) = - *(unsigned int *)((char *)gp2x_screen + g_screen_width*4+12) = col_r; + *(unsigned int *)((char *)g_screen_ptr + g_screen_width*2+ 4) = + *(unsigned int *)((char *)g_screen_ptr + g_screen_width*3+ 4) = + *(unsigned int *)((char *)g_screen_ptr + g_screen_width*4+ 4) = col_g; + *(unsigned int *)((char *)g_screen_ptr + g_screen_width*2+12) = + *(unsigned int *)((char *)g_screen_ptr + g_screen_width*3+12) = + *(unsigned int *)((char *)g_screen_ptr + g_screen_width*4+12) = col_r; } else { // 16-bit modes - unsigned int *p = (unsigned int *)((short *)gp2x_screen + g_screen_width*2+4); + unsigned int *p = (unsigned int *)((short *)g_screen_ptr + g_screen_width*2+4); unsigned int col_g = (old_reg & 2) ? 0x06000600 : 0; unsigned int col_r = (old_reg & 1) ? 0xc000c000 : 0; *p++ = col_g; *p++ = col_g; p+=2; *p++ = col_r; *p++ = col_r; p += g_screen_width/2 - 12/2; @@ -228,7 +226,7 @@ static void draw_cd_leds(void) static void draw_pico_ptr(void) { - unsigned short *p = (unsigned short *)gp2x_screen; + unsigned short *p = (unsigned short *)g_screen_ptr; // only if pen enabled and for 16bit modes if (pico_inp_mode == 0 || (PicoOpt&0x10) || !(currentConfig.EmuOpt&0x80)) return; @@ -250,9 +248,9 @@ static void draw_pico_ptr(void) static int EmuScanBegin16(unsigned int num) { if (!(Pico.video.reg[1]&8)) num += 8; - DrawLineDest = (unsigned short *)gp2x_screen + num*800 + 800/2 - 320/2; + DrawLineDest = (unsigned short *)g_screen_ptr + num*800 + 800/2 - 320/2; //int w = (Pico.video.reg[12]&1) ? 320 : 256; - //DrawLineDest = (unsigned short *)gp2x_screen + num*w; + //DrawLineDest = (unsigned short *)g_screen_ptr + num*w; return 0; } @@ -268,7 +266,7 @@ static int EmuScanEnd16(unsigned int num) int len, mask = 0xff; if (!(Pico.video.reg[1]&8)) num += 8; - pd=(unsigned short *)gp2x_screen + num*800*2 + 800/2 - 320*2/2; + pd=(unsigned short *)g_screen_ptr + num*800*2 + 800/2 - 320*2/2; if (Pico.m.dirtyPal) PicoDoHighPal555(sh); @@ -301,14 +299,6 @@ static int EmuScanEnd16(unsigned int num) #endif // USE_320_SCREEN -static int EmuScanBegin8(unsigned int num) -{ - if (!(Pico.video.reg[1]&8)) num += 8; - DrawLineDest = (unsigned char *) gp2x_screen + g_screen_width * num; - - return 0; -} - int localPal[0x100]; static void (*vidCpyM2)(void *dest, void *src) = NULL; @@ -323,13 +313,13 @@ static void blit(const char *fps, const char *notice) Pico.m.dirtyPal = 0; vidConvCpyRGB32(localPal, Pico.cram, 0x40); // feed new palette to our device - gp2x_video_setpalette(localPal, 0x40); + // gp2x_video_setpalette(localPal, 0x40); } // a hack for VR if (PicoRead16Hook == PicoSVPRead16) memset32((int *)(PicoDraw2FB+328*8+328*223), 0xe0e0e0e0, 328); // do actual copy - vidCpyM2((unsigned char *)gp2x_screen+g_screen_width*8, PicoDraw2FB+328*8); + vidCpyM2((unsigned char *)g_screen_ptr+g_screen_width*8, PicoDraw2FB+328*8); } else if (!(emu_opt&0x80)) { @@ -362,7 +352,7 @@ static void blit(const char *fps, const char *notice) localPal[0xe0] = 0x00000000; // reserved pixels for OSD localPal[0xf0] = 0x00ffffff; } - gp2x_video_setpalette(localPal, pallen); + // gp2x_video_setpalette(localPal, pallen); } } @@ -377,33 +367,24 @@ static void blit(const char *fps, const char *notice) draw_cd_leds(); if (PicoAHW & PAHW_PICO) draw_pico_ptr(); -{ -//static int u=0; -//memset((char *)gp2x_screen+800*471*2, (u++)>>1, 800*9*2); -} //gp2x_video_wait_vsync(); - gp2x_video_flip(); + // gp2x_video_flip(); } // clears whole screen or just the notice area (in all buffers) static void clearArea(int full) { - if ((PicoOpt&0x10)||!(currentConfig.EmuOpt&0x80)) { - // 8-bit renderers - if (full) gp2x_memset_all_buffers(0, 0xe0, g_screen_width*240); - else gp2x_memset_all_buffers(g_screen_width*232, 0xe0, g_screen_width*8); - } else { - // 16bit accurate renderer - if (full) gp2x_memset_all_buffers(0, 0, g_screen_width*g_screen_height*2); - else gp2x_memset_all_buffers(g_screen_width*(g_screen_height-16)*2, 0, g_screen_width*16*2); - } + if (full) memset(g_screen_ptr, 0, g_screen_width*g_screen_height*2); + else memset((short *)g_screen_ptr + g_screen_width * (g_screen_height - 16), 0, + g_screen_width * 16 * 2); } static void vidResetMode(void) { +#if 0 if (PicoOpt&0x10) { gp2x_video_changemode(8); } else if (currentConfig.EmuOpt&0x80) { @@ -435,27 +416,37 @@ static void vidResetMode(void) if (currentConfig.scaling == 2 && !(Pico.video.reg[1]&8)) gp2x_video_RGB_setscaling(8, (PicoOpt&0x100)&&!(Pico.video.reg[12]&1) ? 256 : 320, 224); else gp2x_video_RGB_setscaling(0, (PicoOpt&0x100)&&!(Pico.video.reg[12]&1) ? 256 : 320, 240); +#else +#ifdef USE_320_SCREEN + PicoDrawSetColorFormat(1); + PicoScanBegin = EmuScanBegin16; +#else + PicoDrawSetColorFormat(-1); + PicoScanEnd = EmuScanEnd16; +#endif +#endif } static void emu_msg_cb(const char *msg) { +/* if ((PicoOpt&0x10)||!(currentConfig.EmuOpt&0x80)) { // 8-bit renderers gp2x_memset_all_buffers(g_screen_width*(g_screen_height-16), 0xe0, g_screen_width*16); osd_text(4, g_screen_height-16, msg); - gp2x_memcpy_all_buffers((char *)gp2x_screen+g_screen_width*(g_screen_height-16), + gp2x_memcpy_all_buffers((char *)g_screen_ptr+g_screen_width*(g_screen_height-16), g_screen_width*(g_screen_height-16), g_screen_width*16); } else { // 16bit accurate renderer gp2x_memset_all_buffers(g_screen_width*(g_screen_height-16)*2, 0, g_screen_width*16*2); osd_text(4, g_screen_height-16, msg); - gp2x_memcpy_all_buffers((char *)gp2x_screen+g_screen_width*(g_screen_height-16)*2, + gp2x_memcpy_all_buffers((char *)g_screen_ptr+g_screen_width*(g_screen_height-16)*2, g_screen_width*(g_screen_height-16)*2, g_screen_width*16*2); } gettimeofday(¬iceMsgTime, 0); noticeMsgTime.tv_sec -= 2; - +*/ /* assumption: emu_msg_cb gets called only when something slow is about to happen */ reset_timing = 1; } @@ -582,7 +573,7 @@ static void RunEvents(unsigned int which) if (do_it) { osd_text(4, g_screen_height-16, (which & 0x1000) ? "LOADING GAME" : "SAVING GAME"); PicoStateProgressCB = emu_state_cb; - gp2x_memcpy_all_buffers(gp2x_screen, 0, g_screen_width*g_screen_height*2); + //gp2x_memcpy_all_buffers(g_screen_ptr, 0, g_screen_width*g_screen_height*2); emu_SaveLoadGame((which & 0x1000) >> 12, 0); PicoStateProgressCB = NULL; } @@ -707,7 +698,7 @@ void emu_forcedFrame(int opts) clearArea(1); } else vidCpyM2 = vidCpyM2_40col; - vidCpyM2((unsigned char *)gp2x_screen+g_screen_width*8, PicoDraw2FB+328*8); + vidCpyM2((unsigned char *)g_screen_ptr+g_screen_width*8, PicoDraw2FB+328*8); vidConvCpyRGB32(localPal, Pico.cram, 0x40); gp2x_video_setpalette(localPal, 0x40); */ @@ -806,7 +797,7 @@ void emu_Loop(void) // calc vsync offset to sync timing code with vsync if (currentConfig.EmuOpt&0x2000) { gettimeofday(&tval, 0); - gp2x_video_wait_vsync(); + //gp2x_video_wait_vsync(); gettimeofday(&tval, 0); vsync_offset = tval.tv_usec; while (vsync_offset >= target_frametime) @@ -863,9 +854,9 @@ void emu_Loop(void) vidCpyM2 = vidCpyM2_32col; } } - if (currentConfig.scaling == 2 && !(modes&8)) // want vertical scaling and game is not in 240 line mode - gp2x_video_RGB_setscaling(8, scalex, 224); - else gp2x_video_RGB_setscaling(0, scalex, 240); + //if (currentConfig.scaling == 2 && !(modes&8)) // want vertical scaling and game is not in 240 line mode + // gp2x_video_RGB_setscaling(8, scalex, 224); + // else gp2x_video_RGB_setscaling(0, scalex, 240); oldmodes = modes; clearArea(1); } @@ -966,7 +957,7 @@ void emu_Loop(void) if (vsync_offset) { if (lim_time - tval.tv_usec > target_frametime/2) simpleWait(pthissec, lim_time - target_frametime/4); - gp2x_video_wait_vsync(); + // gp2x_video_wait_vsync(); } else { simpleWait(pthissec, lim_time); } diff --git a/pandora/main.c b/pandora/main.c index 51f7f8e..37a69fe 100644 --- a/pandora/main.c +++ b/pandora/main.c @@ -10,20 +10,17 @@ #include #include -#include "../gp2x/gp2x.h" -#include "../gp2x/menu.h" +#include "../gp2x/emu.h" // TODO rm #include "../common/menu.h" #include "../common/emu.h" #include "../common/config.h" #include "../common/input.h" -#include "../gp2x/emu.h" #include "../gp2x/version.h" +#include "pandora.h" -extern int select_exits; extern char *PicoConfigFile; static int load_state_slot = -1; -int mmuhack_status = 0; // TODO rm char **g_argv; void parse_cmd_line(int argc, char *argv[]) @@ -37,9 +34,6 @@ void parse_cmd_line(int argc, char *argv[]) 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]); } } @@ -50,8 +44,8 @@ void parse_cmd_line(int argc, char *argv[]) } else { /* External Frontend: ROM Name */ FILE *f; - strncpy(rom_fname_reload, argv[x], PATH_MAX); - rom_fname_reload[PATH_MAX-1] = 0; + strncpy(rom_fname_reload, argv[x], sizeof(rom_fname_reload)); + rom_fname_reload[sizeof(rom_fname_reload) - 1] = 0; f = fopen(rom_fname_reload, "rb"); if (f) fclose(f); else unrecognized = 1; @@ -61,14 +55,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"); } } @@ -85,7 +76,7 @@ int main(int argc, char *argv[]) in_probe(); in_debug_dump(); - gp2x_init(); + pnd_init(); emu_Init(); menu_init(); @@ -141,6 +132,7 @@ int main(int argc, char *argv[]) endloop: emu_Deinit(); + pnd_exit(); return 0; } diff --git a/pandora/pandora.c b/pandora/pandora.c index 6c33e6c..ce9fac6 100644 --- a/pandora/pandora.c +++ b/pandora/pandora.c @@ -1,4 +1,3 @@ - #include #include #include @@ -11,139 +10,21 @@ #include #include -#include "../gp2x/gp2x.h" #include "../linux/sndout_oss.h" #include "../common/arm_linux.h" +#include "../common/emu.h" +#include "pandora.h" -static volatile unsigned int *memregs = MAP_FAILED; -//static -int memdev = 0; static int fbdev = -1; #define SCREEN_MAP_SIZE (800*480*2) static void *screen = MAP_FAILED; -void *gp2x_screen; - - -/* video stuff */ -void gp2x_video_flip(void) -{ -} - -/* doulblebuffered flip */ -void gp2x_video_flip2(void) -{ -} - - -void gp2x_video_changemode2(int bpp) -{ -} - - -void gp2x_video_changemode(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) -{ -// cache_flush_d_inval_i(gp2x_screen, (char *)gp2x_screen + 320*240*2, 0); -} - -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) -{ - memset((char *)gp2x_screen + offset, byte, len); -} - - -void gp2x_pd_clone_buffer2(void) -{ - memset(gp2x_screen, 0, 800*480*2); -} - -// FIXME -#if 0 -static int touchcal[7] = { 6203, 0, -1501397, 0, -4200, 16132680, 65536 }; - -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; -} -#else -int gp2x_touchpad_read(int *x, int *y) { return -1; } -#endif /* common */ -void gp2x_init(void) +void pnd_init(void) { printf("entering init()\n"); fflush(stdout); - memdev = open("/dev/mem", O_RDWR); - if (memdev == -1) - { - perror("open(\"/dev/mem\")"); - exit(1); - } -/* - memregs = mmap(0, 0x01000000, PROT_READ|PROT_WRITE, MAP_SHARED, memdev, 0x48000000); - if (memregs == MAP_FAILED) - { - printf("mmap(memregs) failed with %i\n", errno); - exit(1); - } -*/ fbdev = open("/dev/fb0", O_RDWR); if (fbdev == -1) { @@ -158,7 +39,7 @@ void gp2x_init(void) exit(1); } printf("fbptr %p\n", screen); - gp2x_screen = screen; + g_screen_ptr = screen; // snd sndout_oss_init(); @@ -166,14 +47,12 @@ void gp2x_init(void) printf("exitting init()\n"); fflush(stdout); } -void gp2x_deinit(void) +void pnd_exit(void) { if (screen != MAP_FAILED) munmap(screen, SCREEN_MAP_SIZE); - if (memregs != MAP_FAILED) - munmap((void *)memregs, 0x10000); - close(memdev); - if (fbdev >= 0) close(fbdev); + if (fbdev >= 0) + close(fbdev); sndout_oss_exit(); @@ -192,12 +71,11 @@ void lprintf(const char *fmt, ...) /* fake GP2X */ -int crashed_940 = 0; - +/* 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) {} void Pause940(int yes) {} void Reset940(int yes, int bank) {} - +*/ -- 2.39.2