From e31266dd116b6bea59ce3f2036feeb6725c45a72 Mon Sep 17 00:00:00 2001 From: notaz Date: Wed, 4 Mar 2009 22:07:13 +0000 Subject: [PATCH] screen ptr/size unification, major cleanups git-svn-id: file:///home/notaz/opt/svn/PicoDrive/platform@644 be3aeb3a-fb24-0410-a615-afba39da0efa --- common/common.h | 148 ++---------------------------------------- common/emu.c | 80 ++++++++++------------- common/emu.h | 11 ++++ common/menu.c | 144 ++++++++++++++++++++-------------------- gp2x/940ctl.c | 2 +- gp2x/emu.c | 80 +++++++++-------------- gp2x/gp2x.c | 28 ++------ gp2x/gp2x.h | 1 - gp2x/plat.c | 11 ++-- gp2x/port_config.h | 4 ++ linux/Makefile | 2 +- linux/gp2x.c | 80 +++++++++++------------ linux/port_config.h | 4 ++ pandora/emu.c | 71 ++++++++++---------- pandora/port_config.h | 4 ++ psp/port_config.h | 4 ++ 16 files changed, 259 insertions(+), 415 deletions(-) diff --git a/common/common.h b/common/common.h index 8904ecd..c84583a 100644 --- a/common/common.h +++ b/common/common.h @@ -1,155 +1,17 @@ -// platform specific things for common menu code +/* random common definitions */ -/* TODO: get rid of this file */ - -#ifdef __GP2X__ -#include "../gp2x/gp2x.h" - -// TODO merge #define PBTN_UP (1 << 0) #define PBTN_DOWN (1 << 1) #define PBTN_LEFT (1 << 2) #define PBTN_RIGHT (1 << 3) -#define PBTN_NORTH (1 << 4) -#define PBTN_SOUTH (1 << 5) -#define PBTN_WEST (1 << 6) -#define PBTN_EAST (1 << 7) -#define PBTN_L (1 << 8) -#define PBTN_R (1 << 9) - -/* menu nav */ -#define PBTN_MOK PBTN_EAST -#define PBTN_MBACK PBTN_SOUTH -#define PBTN_MENU (1 << 10) - -#if 0 -#define PBTN_UP GP2X_UP -#define PBTN_DOWN GP2X_DOWN -#define PBTN_LEFT GP2X_LEFT -#define PBTN_RIGHT GP2X_RIGHT - -#define PBTN_NORTH GP2X_Y -#define PBTN_SOUTH GP2X_X -#define PBTN_WEST GP2X_A -#define PBTN_EAST GP2X_B -#define PBTN_L GP2X_L -#define PBTN_R GP2X_R - -/* menu nav */ -#define PBTN_MOK GP2X_B -#define PBTN_MBACK GP2X_X -#define PBTN_MENU GP2X_SELECT -#endif -#define GP2X_Y 0 /* FIXME */ - -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 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() - -// ------------------------------------ - -#elif defined(__GIZ__) - -#include "../gizmondo/giz.h" - -#define PBTN_NORTH PBTN_STOP -#define PBTN_SOUTH PBTN_PLAY -#define PBTN_WEST PBTN_REW -#define PBTN_EAST PBTN_FWD - -void menu_draw_begin(int use_bgbuff); -void menu_darken_bg(void *dst, const void *src, int pixels, int darker); -void menu_draw_end(void); - -#define SCREEN_WIDTH 321 -#define SCREEN_HEIGHT 240 -#define SCREEN_BUFFER ((giz_screen != NULL) ? giz_screen : menu_screen) -extern void *menu_screen; -extern void *giz_screen; - -#define menu_draw_begin() \ - menu_draw_begin(1) -#define clear_screen() \ - memset(SCREEN_BUFFER, 0, SCREEN_WIDTH*SCREEN_HEIGHT*2) -#define darken_screen() \ - menu_darken_bg(menu_screen, menu_screen, SCREEN_WIDTH*SCREEN_HEIGHT, 0) +#define PBTN_MOK (1 << 4) +#define PBTN_MBACK (1 << 5) +#define PBTN_MA2 (1 << 6) /* menu action 2 */ +#define PBTN_MA3 (1 << 7) -// ------------------------------------ - -#elif defined(PSP) - -#include "../psp/psp.h" - -#define PBTN_NORTH PBTN_TRIANGLE -#define PBTN_SOUTH PBTN_X -#define PBTN_WEST PBTN_SQUARE -#define PBTN_EAST PBTN_CIRCLE - -void menu_draw_begin(void); -void menu_darken_bg(void *dst, const void *src, int pixels, int darker); -void menu_draw_end(void); - -#define SCREEN_WIDTH 512 -#define SCREEN_HEIGHT 272 -#define SCREEN_BUFFER psp_screen - -#define clear_screen() \ - memset(SCREEN_BUFFER, 0, SCREEN_WIDTH*SCREEN_HEIGHT*2) -#define darken_screen() \ - menu_darken_bg(psp_screen, psp_screen, SCREEN_WIDTH*SCREEN_HEIGHT, 0) - -// ------------------------------------ - -#elif defined(PANDORA) - -#define PBTN_UP (1 << 0) -#define PBTN_DOWN (1 << 1) -#define PBTN_LEFT (1 << 2) -#define PBTN_RIGHT (1 << 3) - -#define PBTN_NORTH (1 << 4) -#define PBTN_SOUTH (1 << 5) -#define PBTN_WEST (1 << 6) -#define PBTN_EAST (1 << 7) #define PBTN_L (1 << 8) #define PBTN_R (1 << 9) -/* menu nav */ -#define PBTN_MOK PBTN_EAST -#define PBTN_MBACK PBTN_SOUTH #define PBTN_MENU (1 << 10) -void gp2x_pd_clone_buffer2(void); -void menu_darken_bg(void *dst, int pixels, int darker); -void menu_flip(void); - -extern void *gp2x_screen; - -#define SCREEN_WIDTH 800 -#define SCREEN_HEIGHT 480 -#define SCREEN_BUFFER gp2x_screen - -#define menu_draw_begin() \ - gp2x_pd_clone_buffer2() -#define clear_screen() \ - memset(gp2x_screen, 0, 800*480*2) -#define darken_screen() \ - menu_darken_bg(gp2x_screen, 800*480, 0) -#define menu_draw_end() \ - menu_flip() - -#endif diff --git a/common/emu.c b/common/emu.c index 7aac10b..f8b4e65 100644 --- a/common/emu.c +++ b/common/emu.c @@ -24,6 +24,13 @@ #include +void *g_screen_ptr; + +#if !SCREEN_SIZE_FIXED +int g_screen_width = SCREEN_WIDTH; +int g_screen_height = SCREEN_HEIGHT; +#endif + char *PicoConfigFile = "config.cfg"; currentConfig_t currentConfig, defaultConfig; char noticeMsg[64] = { 0, }; @@ -679,54 +686,36 @@ void emu_writelrom(void) #endif } -#ifndef UIQ3 -void emu_textOut8(int x, int y, const char *text) -{ - int i,l,len=strlen(text); - unsigned char *screen = (unsigned char *)SCREEN_BUFFER + x + y*SCREEN_WIDTH; - - /* always using built-in font */ - for (i = 0; i < len; i++) - { - for (l=0;l<8;l++) - { - unsigned char fd = fontdata8x8[((text[i])*8)+l]; - if (fd&0x80) screen[l*SCREEN_WIDTH+0]=0xf0; - if (fd&0x40) screen[l*SCREEN_WIDTH+1]=0xf0; - if (fd&0x20) screen[l*SCREEN_WIDTH+2]=0xf0; - if (fd&0x10) screen[l*SCREEN_WIDTH+3]=0xf0; - if (fd&0x08) screen[l*SCREEN_WIDTH+4]=0xf0; - if (fd&0x04) screen[l*SCREEN_WIDTH+5]=0xf0; - if (fd&0x02) screen[l*SCREEN_WIDTH+6]=0xf0; - if (fd&0x01) screen[l*SCREEN_WIDTH+7]=0xf0; - } - screen += 8; - } +/* always using built-in font */ + +#define mk_text_out(name, type, val) \ +void name(int x, int y, const char *text) \ +{ \ + int i, l, len = strlen(text); \ + type *screen = (type *)g_screen_ptr + x + y * g_screen_width; \ + \ + for (i = 0; i < len; i++, screen += 8) \ + { \ + for (l = 0; l < 8; l++) \ + { \ + unsigned char fd = fontdata8x8[text[i] * 8 + l];\ + type *s = screen + l * g_screen_width; \ + if (fd&0x80) s[0] = val; \ + if (fd&0x40) s[1] = val; \ + if (fd&0x20) s[2] = val; \ + if (fd&0x10) s[3] = val; \ + if (fd&0x08) s[4] = val; \ + if (fd&0x04) s[5] = val; \ + if (fd&0x02) s[6] = val; \ + if (fd&0x01) s[7] = val; \ + } \ + } \ } -void emu_textOut16(int x, int y, const char *text) -{ - int i,l,len=strlen(text); - unsigned short *screen = (unsigned short *)SCREEN_BUFFER + x + y*SCREEN_WIDTH; +mk_text_out(emu_textOut8, unsigned char, 0xf0) +mk_text_out(emu_textOut16, unsigned short, 0xffff) - for (i = 0; i < len; i++) - { - for (l=0;l<8;l++) - { - unsigned char fd = fontdata8x8[((text[i])*8)+l]; - if(fd&0x80) screen[l*SCREEN_WIDTH+0]=0xffff; - if(fd&0x40) screen[l*SCREEN_WIDTH+1]=0xffff; - if(fd&0x20) screen[l*SCREEN_WIDTH+2]=0xffff; - if(fd&0x10) screen[l*SCREEN_WIDTH+3]=0xffff; - if(fd&0x08) screen[l*SCREEN_WIDTH+4]=0xffff; - if(fd&0x04) screen[l*SCREEN_WIDTH+5]=0xffff; - if(fd&0x02) screen[l*SCREEN_WIDTH+6]=0xffff; - if(fd&0x01) screen[l*SCREEN_WIDTH+7]=0xffff; - } - screen += 8; - } -} -#endif +#undef mk_text_out #ifdef PSP #define MAX_COMBO_KEY 23 @@ -734,6 +723,7 @@ void emu_textOut16(int x, int y, const char *text) #define MAX_COMBO_KEY 31 #endif +// FIXME void emu_findKeyBindCombos(void) { int act, u; diff --git a/common/emu.h b/common/emu.h index 516c77f..91921c9 100644 --- a/common/emu.h +++ b/common/emu.h @@ -9,6 +9,17 @@ extern "C" { #endif +extern void *g_screen_ptr; + +#if SCREEN_SIZE_FIXED +#define g_screen_width SCREEN_WIDTH +#define g_screen_height SCREEN_HEIGHT +#else +extern int g_screen_width; +extern int g_screen_height; +#endif + + #define EOPT_USE_SRAM (1<<0) #define EOPT_SHOW_FPS (1<<1) #define EOPT_EN_SOUND (1<<2) diff --git a/common/menu.c b/common/menu.c index 4d980fa..dc53393 100644 --- a/common/menu.c +++ b/common/menu.c @@ -1,4 +1,4 @@ -// (c) Copyright 2006,2007 notaz, All rights reserved. +// (c) Copyright 2006-2009 notaz, All rights reserved. // Free for non-commercial use. // For commercial use, separate licencing terms must be obtained. @@ -38,7 +38,7 @@ static int menu_sel_color = -1; // disabled static void text_out16_(int x, int y, const char *text, int color) { int i, l, u, tr, tg, tb, len; - unsigned short *dest = (unsigned short *)SCREEN_BUFFER + x + y*SCREEN_WIDTH; + unsigned short *dest = (unsigned short *)g_screen_ptr + x + y * g_screen_width; tr = (color & 0xf800) >> 8; tg = (color & 0x07e0) >> 3; tb = (color & 0x001f) << 3; @@ -61,7 +61,7 @@ static void text_out16_(int x, int y, const char *text, int color) { unsigned char *src = menu_font_data + (unsigned int)text[i]*4*10; unsigned short *dst = dest; - for (l = 0; l < 10; l++, dst += SCREEN_WIDTH-8) + for (l = 0; l < 10; l++, dst += g_screen_width - 8) { for (u = 8/2; u > 0; u--, src++) { @@ -92,7 +92,7 @@ void text_out16(int x, int y, const char *texto, ...) { va_list args; char buffer[256]; - int maxw = (SCREEN_WIDTH - x) / 8; + int maxw = (g_screen_width - x) / 8; if (maxw < 0) return; @@ -123,7 +123,7 @@ static void smalltext_out16_(int x, int y, const char *texto, int color) if (!c) break; src = fontdata6x8[c]; - dst = (unsigned short *)SCREEN_BUFFER + x + y*SCREEN_WIDTH; + dst = (unsigned short *)g_screen_ptr + x + y * g_screen_width; while (h--) { @@ -136,15 +136,15 @@ static void smalltext_out16_(int x, int y, const char *texto, int color) } src++; - dst += SCREEN_WIDTH-6; + dst += g_screen_width - 6; } } } void smalltext_out16(int x, int y, const char *texto, int color) { - char buffer[SCREEN_WIDTH/6+1]; - int maxw = (SCREEN_WIDTH - x) / 6; + char buffer[128]; + int maxw = (g_screen_width - x) / 6; if (maxw < 0) return; @@ -167,13 +167,13 @@ static void menu_draw_selection(int x, int y, int w) if (menu_sel_color < 0) return; // no selection hilight if (y > 0) y--; - dest = (unsigned short *)SCREEN_BUFFER + x + y*SCREEN_WIDTH + 14; + dest = (unsigned short *)g_screen_ptr + x + y * g_screen_width + 14; for (h = 11; h > 0; h--) { dst = dest; for (i = w; i > 0; i--) *dst++ = menu_sel_color; - dest += SCREEN_WIDTH; + dest += g_screen_width; } } @@ -334,17 +334,17 @@ static void me_draw(const menu_entry *entries, int sel) h = n * 10; w += 16; /* selector */ - if (w > SCREEN_WIDTH) { - lprintf("width %d > %d\n", w, SCREEN_WIDTH); - w = SCREEN_WIDTH; + if (w > g_screen_width) { + lprintf("width %d > %d\n", w, g_screen_width); + w = g_screen_width; } - if (h > SCREEN_HEIGHT) { - lprintf("height %d > %d\n", w, SCREEN_HEIGHT); - h = SCREEN_HEIGHT; + if (h > g_screen_height) { + lprintf("height %d > %d\n", w, g_screen_height); + h = g_screen_height; } - x = SCREEN_WIDTH / 2 - w / 2; - y = SCREEN_HEIGHT / 2 - h / 2; + x = g_screen_width / 2 - w / 2; + y = g_screen_height / 2 - h / 2; /* draw */ plat_video_menu_begin(); @@ -390,7 +390,7 @@ static void me_draw(const menu_entry *entries, int sel) /* display message if we have one */ if (menuErrorMsg[0] != 0) { static int msg_redraws = 0; - if (SCREEN_HEIGHT - h >= 2*10) + if (g_screen_height - h >= 2*10) text_out16(5, 226, menuErrorMsg); else lprintf("menu msg doesn't fit!\n"); @@ -510,14 +510,14 @@ static void draw_menu_credits(void) p++; } - x = SCREEN_WIDTH / 2 - w * 8 / 2; - y = SCREEN_HEIGHT / 2 - h * 10 / 2; + x = g_screen_width / 2 - w * 8 / 2; + y = g_screen_height / 2 - h * 10 / 2; if (x < 0) x = 0; if (y < 0) y = 0; plat_video_menu_begin(); - for (p = creds; *p != 0 && y <= SCREEN_HEIGHT - 10; y += 10) { + for (p = creds; *p != 0 && y <= g_screen_height - 10; y += 10) { text_out16(x, y, p); for (; *p != 0 && *p != '\n'; p++) @@ -535,30 +535,30 @@ static int cdload_called = 0; static void load_progress_cb(int percent) { - int ln, len = percent * SCREEN_WIDTH / 100; - unsigned short *dst = (unsigned short *)SCREEN_BUFFER + SCREEN_WIDTH * 10 * 2; + int ln, len = percent * g_screen_width / 100; + unsigned short *dst = (unsigned short *)g_screen_ptr + g_screen_width * 10 * 2; - if (len > SCREEN_WIDTH) - len = SCREEN_WIDTH; - for (ln = 10 - 2; ln > 0; ln--, dst += SCREEN_WIDTH) + if (len > g_screen_width) + len = g_screen_width; + for (ln = 10 - 2; ln > 0; ln--, dst += g_screen_width) memset(dst, 0xff, len * 2); plat_video_menu_end(); } static void cdload_progress_cb(int percent) { - int ln, len = percent * SCREEN_WIDTH / 100; - unsigned short *dst = (unsigned short *)SCREEN_BUFFER + SCREEN_WIDTH * 10 * 2; + int ln, len = percent * g_screen_width / 100; + unsigned short *dst = (unsigned short *)g_screen_ptr + g_screen_width * 10 * 2; - memset(dst, 0xff, SCREEN_WIDTH * (10 - 2) * 2); + memset(dst, 0xff, g_screen_width * (10 - 2) * 2); smalltext_out16(1, 3 * 10, "Processing CD image / MP3s", 0xffff); smalltext_out16(1, 4 * 10, rom_fname_loaded, 0xffff); - dst += SCREEN_WIDTH * 30; + dst += g_screen_width * 30; - if (len > SCREEN_WIDTH) - len = SCREEN_WIDTH; - for (ln = (10 - 2); ln > 0; ln--, dst += SCREEN_WIDTH) + if (len > g_screen_width) + len = g_screen_width; + for (ln = (10 - 2); ln > 0; ln--, dst += g_screen_width) memset(dst, 0xff, len * 2); plat_video_menu_end(); @@ -618,7 +618,7 @@ static void draw_dirlist(char *curdir, struct dirent **namelist, int n, int sel) { int max_cnt, start, i, pos; - max_cnt = SCREEN_HEIGHT / 10; + max_cnt = g_screen_height / 10; start = max_cnt / 2 - sel; n--; // exclude current dir (".") @@ -627,7 +627,7 @@ static void draw_dirlist(char *curdir, struct dirent **namelist, int n, int sel) // if (!rom_loaded) // menu_darken_bg(gp2x_screen, 320*240, 0); - menu_darken_bg((short *)SCREEN_BUFFER + SCREEN_WIDTH * max_cnt/2 * 10, SCREEN_WIDTH * 8, 0); + menu_darken_bg((short *)g_screen_ptr + g_screen_width * max_cnt/2 * 10, g_screen_width * 8, 0); if (start - 2 >= 0) smalltext_out16(14, (start - 2)*10, curdir, 0xffff); @@ -723,14 +723,14 @@ rescan: { draw_dirlist(curr_path, namelist, n, sel); inp = in_menu_wait(PBTN_UP|PBTN_DOWN|PBTN_LEFT|PBTN_RIGHT| - PBTN_L|PBTN_R|PBTN_WEST|PBTN_MOK|PBTN_MBACK|PBTN_MENU, 33); // TODO L R + PBTN_L|PBTN_R|PBTN_MA2|PBTN_MOK|PBTN_MBACK|PBTN_MENU, 33); if (inp & PBTN_UP ) { sel--; if (sel < 0) sel = n-2; } if (inp & PBTN_DOWN) { sel++; if (sel > n-2) sel = 0; } if (inp & PBTN_LEFT) { sel-=10; if (sel < 0) sel = 0; } if (inp & PBTN_L) { sel-=24; if (sel < 0) sel = 0; } if (inp & PBTN_RIGHT) { sel+=10; if (sel > n-2) sel = n-2; } if (inp & PBTN_R) { sel+=24; if (sel > n-2) sel = n-2; } - if ((inp & PBTN_MOK) || (inp & (PBTN_MENU|PBTN_WEST)) == (PBTN_MENU|PBTN_WEST)) // enter dir/select || delete + if ((inp & PBTN_MOK) || (inp & (PBTN_MENU|PBTN_MA2)) == (PBTN_MENU|PBTN_MA2)) { again: if (namelist[sel+1]->d_type == DT_REG) @@ -810,7 +810,7 @@ static void draw_patchlist(int sel) { int max_cnt, start, i, pos, active; - max_cnt = SCREEN_HEIGHT / 10; + max_cnt = g_screen_height / 10; start = max_cnt / 2 - sel; plat_video_menu_begin(); @@ -932,9 +932,9 @@ static void draw_savestate_menu(int menu_sel, int is_loading) w = 13 * 8 + 16; h = (1+2+10+1) * 10; - x = SCREEN_WIDTH / 2 - w / 2; + x = g_screen_width / 2 - w / 2; if (x < 0) x = 0; - y = SCREEN_HEIGHT / 2 - h / 2; + y = g_screen_height / 2 - h / 2; if (y < 0) y = 0; plat_video_menu_begin(); @@ -945,7 +945,6 @@ static void draw_savestate_menu(int menu_sel, int is_loading) menu_draw_selection(x - 16, y + menu_sel * 10, 13 * 8 + 4); /* draw all 10 slots */ - y += 10; for (i = 0; i < 10; i++, y += 10) { text_out16(x, y, "SLOT %i (%s)", i, (state_slot_flags & (1 << i)) ? "USED" : "free"); @@ -1060,7 +1059,7 @@ static void draw_key_config(const me_bind_action *opts, int opt_cnt, int player_ int x, y = 30, w, i; const char *dev_name; - x = SCREEN_WIDTH / 2 - 32*8 / 2; + x = g_screen_width / 2 - 32*8 / 2; if (x < 0) x = 0; plat_video_menu_begin(); @@ -1079,20 +1078,20 @@ static void draw_key_config(const me_bind_action *opts, int opt_cnt, int player_ w = strlen(dev_name) * 8; if (w < 30 * 8) w = 30 * 8; - if (w > SCREEN_WIDTH) - w = SCREEN_WIDTH; + if (w > g_screen_width) + w = g_screen_width; - x = SCREEN_WIDTH / 2 - w / 2; + x = g_screen_width / 2 - w / 2; if (dev_count > 1) { - text_out16(x, SCREEN_HEIGHT - 4*10, "Viewing binds for:"); - text_out16(x, SCREEN_HEIGHT - 3*10, dev_name); + text_out16(x, g_screen_height - 4*10, "Viewing binds for:"); + text_out16(x, g_screen_height - 3*10, dev_name); } if (is_bind) - text_out16(x, SCREEN_HEIGHT - 2*10, "Press a button to bind/unbind"); + text_out16(x, g_screen_height - 2*10, "Press a button to bind/unbind"); else if (dev_count > 1) - text_out16(x, SCREEN_HEIGHT - 2*10, "Press left/right for other devs"); + text_out16(x, g_screen_height - 2*10, "Press left/right for other devs"); plat_video_menu_end(); } @@ -1653,7 +1652,8 @@ static void mplayer_loop(void) while (1) { PDebugZ80Frame(); - if (in_menu_wait_any(0) & PBTN_NORTH) break; + if (in_menu_wait_any(0) & PBTN_MA3) + break; emu_waitSound(); } @@ -1674,7 +1674,7 @@ static void draw_text_debug(const char *str, int skip, int from) } str = p; - for (line = from; line < SCREEN_HEIGHT/10; line++) + for (line = from; line < g_screen_height / 10; line++) { while (*p && *p != '\n') p++; smalltext_out16(1, line*10, str, 0xffff); @@ -1691,9 +1691,9 @@ static void draw_frame_debug(void) if (PicoDrawMask & PDRAW_SPRITES_LOW_ON) memcpy(layer_str + 12, "spr_lo", 6); if (PicoDrawMask & PDRAW_SPRITES_HI_ON) memcpy(layer_str + 19, "spr_hi", 6); - clear_screen(); + memset(g_screen_ptr, 0, g_screen_width * g_screen_height * 2); emu_forcedFrame(0); - smalltext_out16(4, SCREEN_HEIGHT-8, layer_str, 0xffff); + smalltext_out16(4, g_screen_height - 8, layer_str, 0xffff); } static void debug_menu_loop(void) @@ -1711,26 +1711,26 @@ static void debug_menu_loop(void) emu_platformDebugCat(tmp); draw_text_debug(tmp, 0, 0); if (dumped) { - smalltext_out16(SCREEN_WIDTH-6*10, SCREEN_HEIGHT-8, "dumped", 0xffff); + smalltext_out16(g_screen_width - 6*10, g_screen_height - 8, "dumped", 0xffff); dumped = 0; } break; case 1: draw_frame_debug(); break; - case 2: clear_screen(); + case 2: memset(g_screen_ptr, 0, g_screen_width * g_screen_height * 2); emu_forcedFrame(0); - darken_screen(); - PDebugShowSpriteStats((unsigned short *)SCREEN_BUFFER + (SCREEN_HEIGHT/2 - 240/2)*SCREEN_WIDTH + - SCREEN_WIDTH/2 - 320/2, SCREEN_WIDTH); break; - case 3: clear_screen(); - PDebugShowPalette(SCREEN_BUFFER, SCREEN_WIDTH); - PDebugShowSprite((unsigned short *)SCREEN_BUFFER + SCREEN_WIDTH*120+SCREEN_WIDTH/2+16, - SCREEN_WIDTH, spr_offs); + menu_darken_bg(g_screen_ptr, g_screen_width * g_screen_height, 0); + PDebugShowSpriteStats((unsigned short *)g_screen_ptr + (g_screen_height/2 - 240/2)*g_screen_width + + g_screen_width/2 - 320/2, g_screen_width); break; + case 3: memset(g_screen_ptr, 0, g_screen_width * g_screen_height * 2); + PDebugShowPalette(g_screen_ptr, g_screen_width); + PDebugShowSprite((unsigned short *)g_screen_ptr + g_screen_width*120 + g_screen_width/2 + 16, + g_screen_width, spr_offs); draw_text_debug(PDebugSpriteList(), spr_offs, 6); break; } plat_video_menu_end(); - inp = in_menu_wait(PBTN_EAST|PBTN_MBACK|PBTN_WEST|PBTN_NORTH|PBTN_L|PBTN_R | + inp = in_menu_wait(PBTN_MOK|PBTN_MBACK|PBTN_MA2|PBTN_MA3|PBTN_L|PBTN_R | PBTN_UP|PBTN_DOWN|PBTN_LEFT|PBTN_RIGHT, 70); if (inp & PBTN_MBACK) return; if (inp & PBTN_L) { mode--; if (mode < 0) mode = 3; } @@ -1738,15 +1738,17 @@ static void debug_menu_loop(void) switch (mode) { case 0: - if (inp & PBTN_EAST) SekStepM68k(); - if (inp & PBTN_NORTH) { - while (inp & PBTN_NORTH) inp = in_menu_wait_any(-1); + if (inp & PBTN_MOK) + SekStepM68k(); + if (inp & PBTN_MA3) { + while (inp & PBTN_MA3) + inp = in_menu_wait_any(-1); mplayer_loop(); } - if ((inp & (PBTN_WEST|PBTN_LEFT)) == (PBTN_WEST|PBTN_LEFT)) { + if ((inp & (PBTN_MA2|PBTN_LEFT)) == (PBTN_MA2|PBTN_LEFT)) { mkdir("dumps", 0777); PDebugDumpMem(); - while (inp & PBTN_WEST) inp = in_menu_wait_any(-1); + while (inp & PBTN_MA2) inp = in_menu_wait_any(-1); dumped = 1; } break; @@ -1755,12 +1757,12 @@ static void debug_menu_loop(void) if (inp & PBTN_RIGHT) PicoDrawMask ^= PDRAW_LAYERA_ON; if (inp & PBTN_DOWN) PicoDrawMask ^= PDRAW_SPRITES_LOW_ON; if (inp & PBTN_UP) PicoDrawMask ^= PDRAW_SPRITES_HI_ON; - if (inp & PBTN_EAST) { + if (inp & PBTN_MOK) { PsndOut = NULL; // just in case PicoSkipFrame = 1; PicoFrame(); PicoSkipFrame = 0; - while (inp & PBTN_EAST) inp = in_menu_wait_any(-1); + while (inp & PBTN_MOK) inp = in_menu_wait_any(-1); } break; case 3: diff --git a/gp2x/940ctl.c b/gp2x/940ctl.c index 1c6e4ca..d219d8a 100644 --- a/gp2x/940ctl.c +++ b/gp2x/940ctl.c @@ -313,7 +313,7 @@ void YM2612Init_940(int baseclock, int rate) fp = fopen(binpath, "rb"); if(!fp) { - memset(gp2x_screen, 0, 320*240*2); + memset(g_screen_ptr, 0, 320*240*2); text_out16(10, 100, "failed to open required file:"); text_out16(10, 110, CODE940_FILE); gp2x_video_flip2(); diff --git a/gp2x/emu.c b/gp2x/emu.c index f5052db..237105a 100644 --- a/gp2x/emu.c +++ b/gp2x/emu.c @@ -17,7 +17,6 @@ #include "emu.h" #include "gp2x.h" #include "menu.h" -#include "../linux/usbjoy.h" #include "../common/arm_utils.h" #include "../common/fonts.h" #include "../common/emu.h" @@ -167,23 +166,24 @@ void emu_prepareDefaultConfig(void) void osd_text(int x, int y, const char *text) { int len = strlen(text)*8; + int *p, i, h, offs; if ((PicoOpt&0x10)||!(currentConfig.EmuOpt&0x80)) { - int *p, i, h; - x &= ~3; // align x len = (len+3) >> 2; for (h = 0; h < 8; h++) { - p = (int *) ((unsigned char *) gp2x_screen+x+320*(y+h)); - for (i = len; i; i--, p++) *p = 0xe0e0e0e0; + offs = (x + g_screen_width * (y+h)) & ~3; + p = (int *) ((char *)g_screen_ptr + offs); + for (i = len; i; i--, p++) + *p = 0xe0e0e0e0; } emu_textOut8(x, y, text); } else { - int *p, i, h; - x &= ~1; // align x len = (len+1) >> 1; for (h = 0; h < 8; h++) { - p = (int *) ((unsigned short *) gp2x_screen+x+320*(y+h)); - for (i = len; i; i--, p++) *p = (*p>>2)&0x39e7; + offs = (x + g_screen_width * (y+h)) & ~1; + p = (int *) ((short *)g_screen_ptr + offs); + for (i = len; i; i--, p++) + *p = (*p >> 2) & 0x39e7; } emu_textOut16(x, y, text); } @@ -200,15 +200,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 + 320*2+ 4) = - *(unsigned int *)((char *)gp2x_screen + 320*3+ 4) = - *(unsigned int *)((char *)gp2x_screen + 320*4+ 4) = col_g; - *(unsigned int *)((char *)gp2x_screen + 320*2+12) = - *(unsigned int *)((char *)gp2x_screen + 320*3+12) = - *(unsigned int *)((char *)gp2x_screen + 320*4+12) = col_r; + *(unsigned int *)((char *)g_screen_ptr + 320*2+ 4) = + *(unsigned int *)((char *)g_screen_ptr + 320*3+ 4) = + *(unsigned int *)((char *)g_screen_ptr + 320*4+ 4) = col_g; + *(unsigned int *)((char *)g_screen_ptr + 320*2+12) = + *(unsigned int *)((char *)g_screen_ptr + 320*3+12) = + *(unsigned int *)((char *)g_screen_ptr + 320*4+12) = col_r; } else { // 16-bit modes - unsigned int *p = (unsigned int *)((short *)gp2x_screen + 320*2+4); + unsigned int *p = (unsigned int *)((short *)g_screen_ptr + 320*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 += 320/2 - 12/2; @@ -219,7 +219,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; @@ -239,7 +239,7 @@ 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 + 320 * num; + DrawLineDest = (unsigned short *) g_screen_ptr + g_screen_width * num; return 0; } @@ -247,7 +247,7 @@ static int EmuScanBegin16(unsigned int num) static int EmuScanBegin8(unsigned int num) { if (!(Pico.video.reg[1]&8)) num += 8; - DrawLineDest = (unsigned char *) gp2x_screen + 320 * num; + DrawLineDest = (unsigned char *) g_screen_ptr + g_screen_width * num; return 0; } @@ -272,7 +272,7 @@ static void blit(const char *fps, const char *notice) if (PicoRead16Hook == PicoSVPRead16) memset32((int *)(PicoDraw2FB+328*8+328*223), 0xe0e0e0e0, 328); // do actual copy - vidCpyM2((unsigned char *)gp2x_screen+320*8, PicoDraw2FB+328*8); + vidCpyM2((unsigned char *)g_screen_ptr+320*8, PicoDraw2FB+328*8); } else if (!(emu_opt&0x80)) { @@ -326,12 +326,12 @@ static void blit(const char *fps, const char *notice) if (!(PicoOpt&0x10)) { if (!(Pico.video.reg[1]&8)) { if (currentConfig.EmuOpt&0x80) { - DrawLineDest = (unsigned short *) gp2x_screen + 320*8; + DrawLineDest = (unsigned short *) g_screen_ptr + 320*8; } else { - DrawLineDest = (unsigned char *) gp2x_screen + 320*8; + DrawLineDest = (unsigned char *) g_screen_ptr + 320*8; } } else { - DrawLineDest = gp2x_screen; + DrawLineDest = g_screen_ptr; } } } @@ -389,12 +389,12 @@ static void emu_msg_cb(const char *msg) // 8-bit renderers gp2x_memset_all_buffers(320*232, 0xe0, 320*8); osd_text(4, 232, msg); - gp2x_memcpy_all_buffers((char *)gp2x_screen+320*232, 320*232, 320*8); + gp2x_memcpy_all_buffers((char *)g_screen_ptr+320*232, 320*232, 320*8); } else { // 16bit accurate renderer gp2x_memset_all_buffers(320*232*2, 0, 320*8*2); osd_text(4, 232, msg); - gp2x_memcpy_all_buffers((char *)gp2x_screen+320*232*2, 320*232*2, 320*8*2); + gp2x_memcpy_all_buffers((char *)g_screen_ptr+320*232*2, 320*232*2, 320*8*2); } gettimeofday(¬iceMsgTime, 0); noticeMsgTime.tv_sec -= 2; @@ -521,7 +521,7 @@ static void RunEvents(unsigned int which) if (do_it) { osd_text(4, 232, (which & 0x1000) ? "LOADING GAME" : "SAVING GAME"); PicoStateProgressCB = emu_state_cb; - gp2x_memcpy_all_buffers(gp2x_screen, 0, 320*240*2); + gp2x_memcpy_all_buffers(g_screen_ptr, 0, 320*240*2); emu_SaveLoadGame((which & 0x1000) >> 12, 0); PicoStateProgressCB = NULL; } @@ -567,14 +567,10 @@ static void updateKeys(void) { unsigned int keys, keys2, allActions[2] = { 0, 0 }, events; static unsigned int prevEvents = 0; - int joy, i; keys = gp2x_joystick_read(0); - if (keys & GP2X_SELECT) { + if (keys & GP2X_SELECT) engineState = select_exits ? PGS_Quit : PGS_Menu; - // wait until select is released, so menu would not resume game - while (gp2x_joystick_read(1) & GP2X_SELECT) usleep(50*1000); - } keys &= CONFIGURABLE_KEYS; keys2 = keys; @@ -612,22 +608,6 @@ static void updateKeys(void) } #endif - // add joy inputs - if (num_of_joys > 0) - { - usbjoy_update(); - for (joy = 0; joy < num_of_joys; joy++) { - int btns = usbjoy_check2(joy); - for (i = 0; i < 32; i++) { - if (btns & (1 << i)) { - int acts = currentConfig.JoyBinds[joy][i]; - int pl = (acts >> 16) & 1; - allActions[pl] |= acts; - } - } - } - } - PicoPad[0] = allActions[0] & 0xfff; PicoPad[1] = allActions[1] & 0xfff; @@ -736,7 +716,7 @@ void emu_forcedFrame(int opts) clearArea(1); } else vidCpyM2 = vidCpyM2_40col; - vidCpyM2((unsigned char *)gp2x_screen+320*8, PicoDraw2FB+328*8); + vidCpyM2((unsigned char *)g_screen_ptr+320*8, PicoDraw2FB+328*8); vidConvCpyRGB32(localPal, Pico.cram, 0x40); gp2x_video_setpalette(localPal, 0x40); */ @@ -799,11 +779,11 @@ static void tga_dump(void) #define CONV(X) (((X>>1)&0x7fe0)|(X&0x1f)) // 555? for (i = 0; i < 320*240; i++) - if(oldscr[i] != CONV(((unsigned short *)gp2x_screen)[i])) break; + if(oldscr[i] != CONV(((unsigned short *)g_screen_ptr)[i])) break; if (i < 320*240) { for (i = 0; i < 320*240; i++) - oldscr[i] = CONV(((unsigned short *)gp2x_screen)[i]); + oldscr[i] = CONV(((unsigned short *)g_screen_ptr)[i]); sprintf(name, "%05i.tga", Pico.m.frame_count); f = fopen(name, "wb"); if (!f) { printf("!f\n"); exit(1); } diff --git a/gp2x/gp2x.c b/gp2x/gp2x.c index 89505a0..e0aa296 100644 --- a/gp2x/gp2x.c +++ b/gp2x/gp2x.c @@ -32,7 +32,6 @@ #include #include "gp2x.h" -#include "../linux/usbjoy.h" #include "../linux/sndout_oss.h" #include "../common/arm_utils.h" #include "../common/arm_linux.h" @@ -47,8 +46,6 @@ int memdev = 0; static int 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) @@ -72,7 +69,7 @@ void gp2x_video_flip(void) gp2x_memregs[0x2912>>1] = lsw; // jump to other buffer: - gp2x_screen = gp2x_screens[++screensel&3]; + g_screen_ptr = gp2x_screens[++screensel&3]; } /* doulblebuffered flip */ @@ -86,7 +83,7 @@ void gp2x_video_flip2(void) gp2x_memregs[0x2912>>1] = 0; // jump to other buffer: - gp2x_screen = gp2x_screens[++screensel&1]; + g_screen_ptr = gp2x_screens[++screensel&1]; } @@ -162,7 +159,7 @@ void gp2x_video_wait_vsync(void) void gp2x_video_flush_cache(void) { // since we are using the mmu hack, we must flush the cache first - cache_flush_d_inval_i(gp2x_screen, (char *)gp2x_screen + 320*240*2); + cache_flush_d_inval_i(g_screen_ptr, (char *)g_screen_ptr + 320*240*2); } @@ -193,11 +190,11 @@ void gp2x_memset_all_buffers(int offset, int byte, int len) void gp2x_pd_clone_buffer2(void) { - memcpy(gp2x_screen, gp2x_screens[2], 320*240*2); + memcpy(g_screen_ptr, gp2x_screens[2], 320*240*2); } -unsigned long gp2x_joystick_read(int allow_usb_joy) +unsigned long gp2x_joystick_read(int unused) { int i; unsigned long value=(gp2x_memregs[0x1198>>1] & 0x00FF); // GPIO M @@ -207,13 +204,6 @@ unsigned long gp2x_joystick_read(int allow_usb_joy) 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.. - usbjoy_update(); - for (i = 0; i < num_of_joys; i++) - value |= usbjoy_check(i); - } - return value; } @@ -318,7 +308,7 @@ void gp2x_init(void) gp2x_screens[0] = mmap(0, FRAMEBUFF_WHOLESIZE, PROT_WRITE, MAP_SHARED, memdev, FRAMEBUFF_ADDR0); if(gp2x_screens[0] == MAP_FAILED) { - perror("mmap(gp2x_screen)"); + perror("mmap(g_screen_ptr)"); exit(1); } printf("framebuffers point to %p\n", gp2x_screens[0]); @@ -326,7 +316,7 @@ void gp2x_init(void) gp2x_screens[2] = (char *) gp2x_screens[1]+0x30000; gp2x_screens[3] = (char *) gp2x_screens[2]+0x30000; - gp2x_screen = gp2x_screens[0]; + g_screen_ptr = gp2x_screens[0]; screensel = 0; gp2x_screenaddr_old[0] = gp2x_memregs[0x290E>>1]; @@ -340,9 +330,6 @@ void gp2x_init(void) // snd sndout_oss_init(); - /* init usb joys -GnoStiC */ - usbjoy_init(); - // touchscreen touchdev = open("/dev/touchscreen/wm97xx", O_RDONLY); if (touchdev >= 0) { @@ -381,7 +368,6 @@ void gp2x_deinit(void) if (touchdev >= 0) close(touchdev); sndout_oss_exit(); - usbjoy_deinit(); printf("all done, running "); diff --git a/gp2x/gp2x.h b/gp2x/gp2x.h index b61b853..4636e93 100644 --- a/gp2x/gp2x.h +++ b/gp2x/gp2x.h @@ -29,7 +29,6 @@ void Pause940(int yes); void Reset940(int yes, int bank); -extern void *gp2x_screen; extern int memdev; diff --git a/gp2x/plat.c b/gp2x/plat.c index 16fa183..a2b8394 100644 --- a/gp2x/plat.c +++ b/gp2x/plat.c @@ -4,6 +4,7 @@ #include "../common/plat.h" #include "../common/readpng.h" #include "../common/menu.h" +#include "../common/emu.h" void plat_video_menu_enter(int is_rom_loaded) @@ -11,18 +12,18 @@ void plat_video_menu_enter(int is_rom_loaded) if (is_rom_loaded) { // darken the active framebuffer - memset(gp2x_screen, 0, 320*8*2); - menu_darken_bg((char *)gp2x_screen + 320*8*2, 320*224, 1); - memset((char *)gp2x_screen + 320*232*2, 0, 320*8*2); + memset(g_screen_ptr, 0, 320*8*2); + menu_darken_bg((char *)g_screen_ptr + 320*8*2, 320*224, 1); + memset((char *)g_screen_ptr + 320*232*2, 0, 320*8*2); } else { // should really only happen once, on startup.. - readpng(gp2x_screen, "skin/background.png", READPNG_BG); + readpng(g_screen_ptr, "skin/background.png", READPNG_BG); } // copy to buffer2 - gp2x_memcpy_buffers((1<<2), gp2x_screen, 0, 320*240*2); + gp2x_memcpy_buffers((1<<2), g_screen_ptr, 0, 320*240*2); // switch to 16bpp gp2x_video_changemode2(16); diff --git a/gp2x/port_config.h b/gp2x/port_config.h index 9dc2c6a..ba7acee 100644 --- a/gp2x/port_config.h +++ b/gp2x/port_config.h @@ -8,6 +8,10 @@ #define REDUCE_IO_CALLS 0 #define SIMPLE_WRITE_SOUND 0 +#define SCREEN_SIZE_FIXED 1 +#define SCREEN_WIDTH 320 +#define SCREEN_HEIGHT 240 + // draw.c #define OVERRIDE_HIGHCOL 0 diff --git a/linux/Makefile b/linux/Makefile index acd9307..9edc7ff 100644 --- a/linux/Makefile +++ b/linux/Makefile @@ -24,7 +24,7 @@ CFLAGS += `pkg-config --cflags gthread-2.0` LDFLAGS += `pkg-config --libs gthread-2.0` # frontend -OBJS += platform/gp2x/main.o platform/gp2x/emu.o platform/gp2x/plat.o usbjoy.o blit.o \ +OBJS += platform/gp2x/main.o platform/gp2x/emu.o platform/gp2x/plat.o blit.o \ in_evdev.o plat.o sndout_oss.o gp2x.o 940ctl_ym2612.o log_io.o # common diff --git a/linux/gp2x.c b/linux/gp2x.c index cb1d8d2..4f24ca9 100644 --- a/linux/gp2x.c +++ b/linux/gp2x.c @@ -15,16 +15,16 @@ #include "../gp2x/emu.h" #include "../gp2x/gp2x.h" #include "../gp2x/version.h" +#include "../common/emu.h" #include "sndout_oss.h" -#include "usbjoy.h" #include "log_io.h" -void *gp2x_screen; unsigned long current_keys = 0; static int current_bpp = 8; static int current_pal[256]; 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; @@ -111,17 +111,12 @@ static gint key_release_event (GtkWidget *widget, GdkEventKey *event) return 0; } -/* -void gdk_drawable_get_size (GdkDrawable *drawable, - gint *width, - gint *height); -**/ - static void size_allocate_event(GtkWidget *widget, GtkAllocation *allocation, gpointer user_data) { - gint w, h; - gdk_drawable_get_size(gtk_items.window, &w, &h); - printf("%dx%d %dx%d\n", allocation->width, allocation->height, w, h); + // printf("%dx%d\n", allocation->width, allocation->height); + scr_w = allocation->width - 2; + scr_h = allocation->height - 2; + scr_changed = 1; } static void *gtk_threadf(void *targ) @@ -153,7 +148,7 @@ static void *gtk_threadf(void *targ) g_signal_connect (G_OBJECT (gtk_items.window), "size_allocate", G_CALLBACK (size_allocate_event), NULL); - gtk_container_set_border_width (GTK_CONTAINER (gtk_items.window), 2); + gtk_container_set_border_width (GTK_CONTAINER (gtk_items.window), 1); gtk_window_set_title ((GtkWindow *) gtk_items.window, verstring); box = gtk_hbox_new(FALSE, 0); @@ -198,28 +193,35 @@ void finalize_image(guchar *pixels, gpointer data) /* --- */ +static void realloc_screen(void) +{ + void *old = g_screen_ptr; + g_screen_width = scr_w; + g_screen_height = scr_h; + g_screen_ptr = malloc(g_screen_width * g_screen_height * 2); + free(old); + scr_changed = 0; +} + void gp2x_init(void) { printf("entering init()\n"); fflush(stdout); - gp2x_screen = malloc(320*240*2 + 320*2); - memset(gp2x_screen, 0, 320*240*2 + 320*2); + realloc_screen(); + memset(g_screen_ptr, 0, g_screen_width * g_screen_height * 2); // snd sndout_oss_init(); gtk_initf(); - usbjoy_init(); - printf("exitting init()\n"); fflush(stdout); } void gp2x_deinit(void) { - free(gp2x_screen); + free(g_screen_ptr); sndout_oss_exit(); - usbjoy_deinit(); } /* video */ @@ -227,11 +229,13 @@ void gp2x_video_flip(void) { GdkPixbuf *pixbuf; unsigned char *image; - int i; + int pixel_count, i; + + pixel_count = g_screen_width * g_screen_height; gdk_threads_enter(); - image = malloc (320*240*3); + image = malloc(pixel_count * 3); if (image == NULL) { gdk_threads_leave(); @@ -240,10 +244,10 @@ void gp2x_video_flip(void) if (current_bpp == 8) { - unsigned char *pixels = gp2x_screen; + unsigned char *pixels = g_screen_ptr; int pix; - for (i = 0; i < 320*240; i++) + for (i = 0; i < pixel_count; i++) { pix = current_pal[pixels[i]]; image[3 * i + 0] = pix >> 16; @@ -253,9 +257,9 @@ void gp2x_video_flip(void) } else { - unsigned short *pixels = gp2x_screen; + unsigned short *pixels = g_screen_ptr; - for (i = 0; i < 320*240; i++) + for (i = 0; i < pixel_count; i++) { /* in: rrrr rggg gggb bbbb */ /* out: rrrr r000 gggg gg00 bbbb b000 */ @@ -266,11 +270,15 @@ void gp2x_video_flip(void) } pixbuf = gdk_pixbuf_new_from_data (image, GDK_COLORSPACE_RGB, - FALSE, 8, 320, 240, 320*3, finalize_image, NULL); + FALSE, 8, g_screen_width, g_screen_height, + g_screen_width * 3, finalize_image, NULL); gtk_image_set_from_pixbuf (GTK_IMAGE (gtk_items.pixmap1), pixbuf); g_object_unref (pixbuf); gdk_threads_leave(); + + if (scr_changed) + realloc_screen(); } void gp2x_video_flip2(void) @@ -303,40 +311,30 @@ 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 *)gp2x_screen + offset != data) - memcpy((char *)gp2x_screen + offset, data, 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 *)gp2x_screen + offset, data, len); + memcpy((char *)g_screen_ptr + offset, data, len); } void gp2x_memset_all_buffers(int offset, int byte, int len) { - memset((char *)gp2x_screen + offset, byte, len); + memset((char *)g_screen_ptr + offset, byte, len); } void gp2x_pd_clone_buffer2(void) { - memset(gp2x_screen, 0, 320*240*2); + memset(g_screen_ptr, 0, g_screen_width * g_screen_height * 2); } /* joy */ unsigned long gp2x_joystick_read(int allow_usb_joy) { - unsigned long value = current_keys; - int i; - - if (allow_usb_joy && num_of_joys > 0) { - // check the usb joy as well.. - usbjoy_update(); - for (i = 0; i < num_of_joys; i++) - value |= usbjoy_check(i); - } - - return value; + return current_keys; } int gp2x_touchpad_read(int *x, int *y) diff --git a/linux/port_config.h b/linux/port_config.h index b781da7..a8048e4 100644 --- a/linux/port_config.h +++ b/linux/port_config.h @@ -10,6 +10,10 @@ #define REDUCE_IO_CALLS 0 #define SIMPLE_WRITE_SOUND 0 +#define SCREEN_SIZE_FIXED 0 +#define SCREEN_WIDTH 320 +#define SCREEN_HEIGHT 240 + // draw.c #define OVERRIDE_HIGHCOL 0 diff --git a/pandora/emu.c b/pandora/emu.c index 2d06d98..673c963 100644 --- a/pandora/emu.c +++ b/pandora/emu.c @@ -52,7 +52,7 @@ int reset_timing = 0; #define PICO_PEN_ADJUST_X 4 #define PICO_PEN_ADJUST_Y 2 -static int pico_pen_x = SCREEN_WIDTH/2, pico_pen_y = 240/2; +static int pico_pen_x = 0, pico_pen_y = 240/2; static void emu_msg_cb(const char *msg); static void emu_msg_tray_open(void); @@ -126,7 +126,6 @@ void emu_prepareDefaultConfig(void) defaultConfig.EmuOpt = 0x8f | 0x00600; // | <- confirm_save, cd_leds defaultConfig.s_PicoOpt = 0x0f | POPT_EXT_FM|POPT_EN_MCD_PCM|POPT_EN_MCD_CDDA|POPT_EN_SVP_DRC; defaultConfig.s_PicoOpt |= POPT_ACC_SPRITES|POPT_EN_MCD_GFX; -// defaultConfig.s_PicoOpt &= ~POPT_EN_SVP_DRC; // crashes :( defaultConfig.EmuOpt &= ~8; // no save gzip defaultConfig.s_PsndRate = 44100; defaultConfig.s_PicoRegion = 0; @@ -142,14 +141,14 @@ void emu_prepareDefaultConfig(void) static void textOut16(int x, int y, const char *text) { int i,l,len=strlen(text); - unsigned int *screen = (unsigned int *)((unsigned short *)SCREEN_BUFFER + (x&~1) + y*SCREEN_WIDTH); + unsigned int *screen = (unsigned int *)((unsigned short *)g_screen_ptr + (x&~1) + y*g_screen_width); for (i = 0; i < len; i++) { for (l=0;l<16;) { unsigned char fd = fontdata8x8[((text[i])*8)+l/2]; - unsigned int *d = &screen[l*SCREEN_WIDTH/2]; + unsigned int *d = &screen[l*g_screen_width/2]; if (fd&0x80) d[0]=0xffffffff; if (fd&0x40) d[1]=0xffffffff; if (fd&0x20) d[2]=0xffffffff; @@ -158,7 +157,7 @@ static void textOut16(int x, int y, const char *text) if (fd&0x04) d[5]=0xffffffff; if (fd&0x02) d[6]=0xffffffff; if (fd&0x01) d[7]=0xffffffff; - l++; d = &screen[l*SCREEN_WIDTH/2]; + l++; d = &screen[l*g_screen_width/2]; if (fd&0x80) d[0]=0xffffffff; if (fd&0x40) d[1]=0xffffffff; if (fd&0x20) d[2]=0xffffffff; @@ -183,7 +182,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+SCREEN_WIDTH*(y+h)); + p = (int *) ((unsigned char *) gp2x_screen+x+g_screen_width*(y+h)); for (i = len; i; i--, p++) *p = 0xe0e0e0e0; } emu_textOut8(x, y, text); @@ -192,7 +191,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+SCREEN_WIDTH*(y+h)); + p = (int *) ((unsigned short *) gp2x_screen+x+g_screen_width*(y+h)); for (i = len; i; i--, p++) *p = 0;//(*p>>2)&0x39e7; } textOut16(x, y, text); @@ -210,19 +209,19 @@ 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 + SCREEN_WIDTH*2+ 4) = - *(unsigned int *)((char *)gp2x_screen + SCREEN_WIDTH*3+ 4) = - *(unsigned int *)((char *)gp2x_screen + SCREEN_WIDTH*4+ 4) = col_g; - *(unsigned int *)((char *)gp2x_screen + SCREEN_WIDTH*2+12) = - *(unsigned int *)((char *)gp2x_screen + SCREEN_WIDTH*3+12) = - *(unsigned int *)((char *)gp2x_screen + SCREEN_WIDTH*4+12) = col_r; + *(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; } else { // 16-bit modes - unsigned int *p = (unsigned int *)((short *)gp2x_screen + SCREEN_WIDTH*2+4); + unsigned int *p = (unsigned int *)((short *)gp2x_screen + 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 += SCREEN_WIDTH/2 - 12/2; - *p++ = col_g; *p++ = col_g; p+=2; *p++ = col_r; *p++ = col_r; p += SCREEN_WIDTH/2 - 12/2; + *p++ = col_g; *p++ = col_g; p+=2; *p++ = col_r; *p++ = col_r; p += g_screen_width/2 - 12/2; + *p++ = col_g; *p++ = col_g; p+=2; *p++ = col_r; *p++ = col_r; p += g_screen_width/2 - 12/2; *p++ = col_g; *p++ = col_g; p+=2; *p++ = col_r; *p++ = col_r; } } @@ -237,7 +236,7 @@ static void draw_pico_ptr(void) if (!(Pico.video.reg[12]&1) && !(PicoOpt&POPT_DIS_32C_BORDER)) p += 32; - p += SCREEN_WIDTH * (pico_pen_y + PICO_PEN_ADJUST_Y); + p += g_screen_width * (pico_pen_y + PICO_PEN_ADJUST_Y); p += pico_pen_x + PICO_PEN_ADJUST_X; p[0] ^= 0xffff; p[319] ^= 0xffff; @@ -305,7 +304,7 @@ static int EmuScanEnd16(unsigned int num) static int EmuScanBegin8(unsigned int num) { if (!(Pico.video.reg[1]&8)) num += 8; - DrawLineDest = (unsigned char *) gp2x_screen + SCREEN_WIDTH * num; + DrawLineDest = (unsigned char *) gp2x_screen + g_screen_width * num; return 0; } @@ -330,7 +329,7 @@ static void blit(const char *fps, const char *notice) if (PicoRead16Hook == PicoSVPRead16) memset32((int *)(PicoDraw2FB+328*8+328*223), 0xe0e0e0e0, 328); // do actual copy - vidCpyM2((unsigned char *)gp2x_screen+SCREEN_WIDTH*8, PicoDraw2FB+328*8); + vidCpyM2((unsigned char *)gp2x_screen+g_screen_width*8, PicoDraw2FB+328*8); } else if (!(emu_opt&0x80)) { @@ -368,7 +367,7 @@ static void blit(const char *fps, const char *notice) } if (notice || (emu_opt & 2)) { - int h = SCREEN_HEIGHT-16; + int h = g_screen_height-16; if (currentConfig.scaling == 2 && !(Pico.video.reg[1]&8)) h -= 16; if (notice) osd_text(4, h, notice); if (emu_opt & 2) @@ -393,12 +392,12 @@ static void clearArea(int full) { if ((PicoOpt&0x10)||!(currentConfig.EmuOpt&0x80)) { // 8-bit renderers - if (full) gp2x_memset_all_buffers(0, 0xe0, SCREEN_WIDTH*240); - else gp2x_memset_all_buffers(SCREEN_WIDTH*232, 0xe0, SCREEN_WIDTH*8); + 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, SCREEN_WIDTH*SCREEN_HEIGHT*2); - else gp2x_memset_all_buffers(SCREEN_WIDTH*(SCREEN_HEIGHT-16)*2, 0, SCREEN_WIDTH*16*2); + 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); } } @@ -443,16 +442,16 @@ static void emu_msg_cb(const char *msg) { if ((PicoOpt&0x10)||!(currentConfig.EmuOpt&0x80)) { // 8-bit renderers - gp2x_memset_all_buffers(SCREEN_WIDTH*(SCREEN_HEIGHT-16), 0xe0, SCREEN_WIDTH*16); - osd_text(4, SCREEN_HEIGHT-16, msg); - gp2x_memcpy_all_buffers((char *)gp2x_screen+SCREEN_WIDTH*(SCREEN_HEIGHT-16), - SCREEN_WIDTH*(SCREEN_HEIGHT-16), SCREEN_WIDTH*16); + 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), + g_screen_width*(g_screen_height-16), g_screen_width*16); } else { // 16bit accurate renderer - gp2x_memset_all_buffers(SCREEN_WIDTH*(SCREEN_HEIGHT-16)*2, 0, SCREEN_WIDTH*16*2); - osd_text(4, SCREEN_HEIGHT-16, msg); - gp2x_memcpy_all_buffers((char *)gp2x_screen+SCREEN_WIDTH*(SCREEN_HEIGHT-16)*2, - SCREEN_WIDTH*(SCREEN_HEIGHT-16)*2, SCREEN_WIDTH*16*2); + 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, + g_screen_width*(g_screen_height-16)*2, g_screen_width*16*2); } gettimeofday(¬iceMsgTime, 0); noticeMsgTime.tv_sec -= 2; @@ -581,9 +580,9 @@ static void RunEvents(unsigned int which) #endif } if (do_it) { - osd_text(4, SCREEN_HEIGHT-16, (which & 0x1000) ? "LOADING GAME" : "SAVING GAME"); + osd_text(4, g_screen_height-16, (which & 0x1000) ? "LOADING GAME" : "SAVING GAME"); PicoStateProgressCB = emu_state_cb; - gp2x_memcpy_all_buffers(gp2x_screen, 0, SCREEN_WIDTH*SCREEN_HEIGHT*2); + gp2x_memcpy_all_buffers(gp2x_screen, 0, g_screen_width*g_screen_height*2); emu_SaveLoadGame((which & 0x1000) >> 12, 0); PicoStateProgressCB = NULL; } @@ -708,7 +707,7 @@ void emu_forcedFrame(int opts) clearArea(1); } else vidCpyM2 = vidCpyM2_40col; - vidCpyM2((unsigned char *)gp2x_screen+SCREEN_WIDTH*8, PicoDraw2FB+328*8); + vidCpyM2((unsigned char *)gp2x_screen+g_screen_width*8, PicoDraw2FB+328*8); vidConvCpyRGB32(localPal, Pico.cram, 0x40); gp2x_video_setpalette(localPal, 0x40); */ @@ -851,7 +850,7 @@ void emu_Loop(void) modes = ((Pico.video.reg[12]&1)<<2)|(Pico.video.reg[1]&8); if (modes != oldmodes) { - int scalex = SCREEN_WIDTH; + int scalex = g_screen_width; osd_fps_x = OSD_FPS_X; if (modes & 4) { vidCpyM2 = vidCpyM2_40col; diff --git a/pandora/port_config.h b/pandora/port_config.h index 9dc2c6a..b82b89c 100644 --- a/pandora/port_config.h +++ b/pandora/port_config.h @@ -8,6 +8,10 @@ #define REDUCE_IO_CALLS 0 #define SIMPLE_WRITE_SOUND 0 +#define SCREEN_SIZE_FIXED 1 +#define SCREEN_WIDTH 800 +#define SCREEN_HEIGHT 480 + // draw.c #define OVERRIDE_HIGHCOL 0 diff --git a/psp/port_config.h b/psp/port_config.h index 4659b62..a59692c 100644 --- a/psp/port_config.h +++ b/psp/port_config.h @@ -8,6 +8,10 @@ #define REDUCE_IO_CALLS 1 // another workaround #define SIMPLE_WRITE_SOUND 0 +#define SCREEN_SIZE_FIXED 1 +#define SCREEN_WIDTH 512 +#define SCREEN_HEIGHT 272 + // draw.c #define USE_BGR555 1 #define OVERRIDE_HIGHCOL 1 -- 2.39.2