revive GP2X build, update

This commit is contained in:
notaz 2013-08-23 03:09:53 +03:00
parent 8b78786e0f
commit 75a30842c4
35 changed files with 757 additions and 2592 deletions

View file

@ -74,6 +74,23 @@ OBJS += platform/libpicofe/linux/xenv.o
OBJS += platform/libpicofe/pandora/plat.o OBJS += platform/libpicofe/pandora/plat.o
USE_FRONTEND = 1 USE_FRONTEND = 1
endif endif
ifeq "$(PLATFORM)" "gp2x"
OBJS += platform/common/arm_utils.o
OBJS += platform/libpicofe/gp2x/in_gp2x.o
OBJS += platform/libpicofe/gp2x/soc.o
OBJS += platform/libpicofe/gp2x/soc_mmsp2.o
OBJS += platform/libpicofe/gp2x/soc_pollux.o
OBJS += platform/libpicofe/gp2x/plat.o
OBJS += platform/libpicofe/gp2x/pollux_set.o
OBJS += platform/gp2x/940ctl.o
OBJS += platform/gp2x/plat.o
OBJS += platform/gp2x/emu.o
OBJS += platform/gp2x/vid_mmsp2.o
OBJS += platform/gp2x/vid_pollux.o
OBJS += platform/gp2x/warm.o
USE_FRONTEND = 1
PLATFORM_MP3 = 1
endif
ifeq "$(PLATFORM)" "libretro" ifeq "$(PLATFORM)" "libretro"
OBJS += platform/libretro.o OBJS += platform/libretro.o
endif endif
@ -111,7 +128,8 @@ endif
endif # USE_FRONTEND endif # USE_FRONTEND
OBJS += platform/common/mp3.o OBJS += platform/common/mp3.o
ifeq "$(HAVE_LIBAVCODEC)" "1" ifeq "$(PLATFORM_MP3)" "1"
else ifeq "$(HAVE_LIBAVCODEC)" "1"
OBJS += platform/common/mp3_libavcodec.o OBJS += platform/common/mp3_libavcodec.o
else else
OBJS += platform/common/mp3_dummy.o OBJS += platform/common/mp3_dummy.o

View file

@ -47,8 +47,6 @@ else ifeq ($(platform), ios)
CFLAGS += -DIOS CFLAGS += -DIOS
ARCH := arm ARCH := arm
HAVE_NEON = 0
USE_DYNAREC = 0
use_cyclone = 0 use_cyclone = 0
use_fame = 1 use_fame = 1
@ -101,9 +99,7 @@ else ifeq ($(platform), qnx)
ASFLAGS += -mcpu=cortex-a9 -mfpu=neon -mfloat-abi=softfp ASFLAGS += -mcpu=cortex-a9 -mfpu=neon -mfloat-abi=softfp
ARCH = arm ARCH = arm
HAVE_NEON = 1
ARM_ASM = 1 ARM_ASM = 1
USE_DYNAREC = 1
else ifneq (,$(findstring armv,$(platform))) else ifneq (,$(findstring armv,$(platform)))
TARGET := $(TARGET_NAME)_libretro.so TARGET := $(TARGET_NAME)_libretro.so
SHARED := -shared -Wl,--no-undefined SHARED := -shared -Wl,--no-undefined
@ -118,7 +114,6 @@ endif
ifneq (,$(findstring neon,$(platform))) ifneq (,$(findstring neon,$(platform)))
CFLAGS += -mfpu=neon CFLAGS += -mfpu=neon
ASFLAGS += -mfpu=neon ASFLAGS += -mfpu=neon
HAVE_NEON = 1
endif endif
ifneq (,$(findstring softfloat,$(platform))) ifneq (,$(findstring softfloat,$(platform)))
CFLAGS += -mfloat-abi=softfp CFLAGS += -mfloat-abi=softfp
@ -131,7 +126,6 @@ ifneq (,$(findstring armasm,$(platform)))
ARM_ASM = 1 ARM_ASM = 1
endif endif
ARCH = arm ARCH = arm
USE_DYNAREC = 1
else else
TARGET := $(TARGET_NAME)_retro.dll TARGET := $(TARGET_NAME)_retro.dll
CC = gcc CC = gcc

63
configure vendored
View file

@ -2,9 +2,9 @@
# some elements originated from qemu configure # some elements originated from qemu configure
set -e set -e
TMPC="/tmp/pcsx-conf-${RANDOM}-$$-${RANDOM}.c" TMPC="/tmp/picodrive-conf-${RANDOM}-$$-${RANDOM}.c"
TMPO="/tmp/pcsx-conf-${RANDOM}-$$-${RANDOM}.o" TMPO="/tmp/picodrive-conf-${RANDOM}-$$-${RANDOM}.o"
TMPB="/tmp/pcsx-conf-${RANDOM}-$$-${RANDOM}" TMPB="/tmp/picodrive-conf-${RANDOM}-$$-${RANDOM}"
trap "rm -f $TMPC $TMPO $TMPB" EXIT INT QUIT TERM trap "rm -f $TMPC $TMPO $TMPB" EXIT INT QUIT TERM
rm -f config.log rm -f config.log
@ -17,7 +17,7 @@ compile_object()
compile_binary() compile_binary()
{ {
c="$CC $CFLAGS $TMPC -o $TMPB $LDFLAGS $MAIN_LDLIBS $@" c="$CC $CFLAGS $TMPC -o $TMPB $LDFLAGS $@"
echo $c >> config.log echo $c >> config.log
$c >> config.log 2>&1 $c >> config.log 2>&1
} }
@ -31,7 +31,7 @@ check_define()
# setting options to "yes" or "no" will make that choice default, # setting options to "yes" or "no" will make that choice default,
# "" means "autodetect". # "" means "autodetect".
platform_list="generic pandora" platform_list="generic pandora gp2x"
platform="generic" platform="generic"
sound_driver_list="oss alsa sdl" sound_driver_list="oss alsa sdl"
sound_drivers="" sound_drivers=""
@ -40,12 +40,12 @@ have_armv6=""
have_armv7="" have_armv7=""
have_arm_neon="" have_arm_neon=""
have_libavcodec="" have_libavcodec=""
enable_dynarec="yes"
need_sdl="no" need_sdl="no"
need_xlib="no" need_xlib="no"
# these are for known platforms # these are for known platforms
optimize_cortexa8="no" optimize_cortexa8="no"
optimize_arm926ej="no" optimize_arm926ej="no"
optimize_arm920="no"
# hardcoded stuff # hardcoded stuff
CC="${CC-${CROSS_COMPILE}gcc}" CC="${CC-${CROSS_COMPILE}gcc}"
@ -72,6 +72,16 @@ set_platform()
optimize_cortexa8="yes" optimize_cortexa8="yes"
have_arm_neon="yes" have_arm_neon="yes"
;; ;;
gp2x)
sound_drivers="oss"
optimize_arm920="yes"
CFLAGS="$CFLAGS -D__GP2X__"
if [ "$CROSS_COMPILE" = "arm-linux-" ]; then
# still using static, dynamic linking slows Wiz 1-10%
# also libm on F100 is not compatible
MAIN_LDLIBS="$MAIN_LDLIBS -static"
fi
;;
*) *)
fail "unsupported platform: $platform" fail "unsupported platform: $platform"
;; ;;
@ -87,12 +97,6 @@ for opt do
;; ;;
--sound-drivers=*) sound_drivers="$optarg" --sound-drivers=*) sound_drivers="$optarg"
;; ;;
--enable-neon) have_arm_neon="yes"
;;
--disable-neon) have_arm_neon="no"
;;
--disable-dynarec) enable_dynarec="no"
;;
*) echo "ERROR: unknown option $opt"; show_help="yes" *) echo "ERROR: unknown option $opt"; show_help="yes"
;; ;;
esac esac
@ -105,10 +109,6 @@ if [ "$show_help" = "yes" ]; then
echo " available: $platform_list" echo " available: $platform_list"
echo " --sound-drivers=LIST sound output drivers [guessed]" echo " --sound-drivers=LIST sound output drivers [guessed]"
echo " available: $sound_driver_list" echo " available: $sound_driver_list"
echo " --enable-neon"
echo " --disable-neon enable/disable ARM NEON optimizations [guessed]"
echo " --disable-dynarec disable dynamic recompiler"
echo " (dynarec is only available and enabled on ARM)"
echo "influential environment variables:" echo "influential environment variables:"
echo " CROSS_COMPILE CC CXX AS CFLAGS ASFLAGS LDFLAGS LDLIBS" echo " CROSS_COMPILE CC CXX AS CFLAGS ASFLAGS LDFLAGS LDLIBS"
exit 1 exit 1
@ -158,6 +158,10 @@ arm*)
CFLAGS="$CFLAGS -mcpu=arm926ej-s -mtune=arm926ej-s" CFLAGS="$CFLAGS -mcpu=arm926ej-s -mtune=arm926ej-s"
ASFLAGS="$ASFLAGS -mcpu=arm926ej-s -mfloat-abi=softfp" ASFLAGS="$ASFLAGS -mcpu=arm926ej-s -mfloat-abi=softfp"
fi fi
if [ "$optimize_arm920" = "yes" ]; then
CFLAGS="$CFLAGS -mcpu=arm920t -mtune=arm920t"
ASFLAGS="$ASFLAGS -mcpu=arm920t -mfloat-abi=soft"
fi
if [ "x$have_arm_neon" = "x" ]; then if [ "x$have_arm_neon" = "x" ]; then
# detect NEON from user-supplied cflags to enable asm code # detect NEON from user-supplied cflags to enable asm code
@ -202,7 +206,7 @@ arm*)
fi fi
# warn about common mistakes # warn about common mistakes
if [ "$have_armv5" != "yes" ]; then if [ "$platform" != "gp2x" -a "$have_armv5" != "yes" ]; then
if ! echo "$CFLAGS" | grep -q -- '-mcpu=\|-march='; then if ! echo "$CFLAGS" | grep -q -- '-mcpu=\|-march='; then
echo "Warning: compiling for ARMv4, is that really what you want?" echo "Warning: compiling for ARMv4, is that really what you want?"
echo "You probably should specify -mcpu= or -march= like this:" echo "You probably should specify -mcpu= or -march= like this:"
@ -216,8 +220,6 @@ arm*)
fi fi
;; ;;
*) *)
# dynarec only available on ARM
enable_dynarec="no"
;; ;;
esac esac
@ -243,7 +245,8 @@ check_libpng()
#include <png.h> #include <png.h>
void main() { png_init_io(0, 0); } void main() { png_init_io(0, 0); }
EOF EOF
compile_binary # compile_binary
compile_object
} }
check_oss() check_oss()
@ -315,7 +318,7 @@ else
fi fi
if echo $sound_drivers | grep -q "\<alsa\>"; then if echo $sound_drivers | grep -q "\<alsa\>"; then
MAIN_LDLIBS="-lasound $MAIN_LDLIBS" MAIN_LDLIBS="-lasound $MAIN_LDLIBS"
check_alsa || fail "please install libasound2-dev" check_alsa -lasound || fail "please install libasound2-dev"
fi fi
fi fi
@ -324,7 +327,7 @@ if [ "$need_sdl" = "yes" ]; then
fail "sdl-config is missing; please install libsdl (libsdl1.2-dev)" fail "sdl-config is missing; please install libsdl (libsdl1.2-dev)"
CFLAGS="$CFLAGS `sdl-config --cflags`" CFLAGS="$CFLAGS `sdl-config --cflags`"
MAIN_LDLIBS="`sdl-config --libs` $MAIN_LDLIBS" MAIN_LDLIBS="`sdl-config --libs` $MAIN_LDLIBS"
check_sdl || fail "please install libsdl (libsdl1.2-dev)" check_sdl `sdl-config --libs` || fail "please install libsdl (libsdl1.2-dev)"
fi fi
cat > $TMPC <<EOF cat > $TMPC <<EOF
@ -337,7 +340,6 @@ fi
# set things that failed to autodetect to "no" # set things that failed to autodetect to "no"
test "x$have_armv6" != "x" || have_armv6="no" test "x$have_armv6" != "x" || have_armv6="no"
test "x$have_armv7" != "x" || have_armv7="no" test "x$have_armv7" != "x" || have_armv7="no"
test "x$have_arm_neon" != "x" || have_arm_neon="no"
test "x$have_libavcodec" != "x" || have_libavcodec="no" test "x$have_libavcodec" != "x" || have_libavcodec="no"
echo "architecture $ARCH" echo "architecture $ARCH"
@ -348,9 +350,7 @@ echo "C compiler flags $CFLAGS"
echo "libraries $MAIN_LDLIBS" echo "libraries $MAIN_LDLIBS"
echo "linker flags $LDFLAGS" echo "linker flags $LDFLAGS"
echo "libavcodec (mp3) $have_libavcodec" echo "libavcodec (mp3) $have_libavcodec"
echo "enable dynarec $enable_dynarec"
# echo "ARMv7 optimizations $have_armv7" # echo "ARMv7 optimizations $have_armv7"
# echo "enable ARM NEON $have_arm_neon"
echo "# Automatically generated by configure" > $config_mak echo "# Automatically generated by configure" > $config_mak
printf "# Configured with:" >> $config_mak printf "# Configured with:" >> $config_mak
@ -372,11 +372,14 @@ echo "SOUND_DRIVERS = $sound_drivers" >> $config_mak
if [ "$have_libavcodec" = "yes" ]; then if [ "$have_libavcodec" = "yes" ]; then
echo "HAVE_LIBAVCODEC = 1" >> $config_mak echo "HAVE_LIBAVCODEC = 1" >> $config_mak
fi fi
if [ "$have_arm_neon" = "yes" ]; then
echo "HAVE_NEON = 1" >> $config_mak # GP2X toolchains are too old for UAL asm,
fi # so add this here to not litter main Makefile
if [ "$enable_dynarec" = "yes" ]; then if [ "$platform" = "g1p2x" ]; then
echo "USE_DYNAREC = 1" >> $config_mak echo >> $config_mak
echo "%.o: %.S" >> $config_mak
echo " $(CC) $(CFLAGS) -E -c $^ -o /tmp/$(notdir $@).s" >> $config_mak
echo " $(AS) $(ASFLAGS) /tmp/$(notdir $@).s -o $@" >> $config_mak
fi fi
# use pandora's skin (for now) # use pandora's skin (for now)

View file

@ -545,7 +545,7 @@ static void make_config_cfg(char *cfg_buff_512)
void emu_prep_defconfig(void) void emu_prep_defconfig(void)
{ {
memset(&defaultConfig, 0, sizeof(defaultConfig)); memset(&defaultConfig, 0, sizeof(defaultConfig));
defaultConfig.EmuOpt = 0x9d | EOPT_RAM_TIMINGS|EOPT_EN_CD_LEDS; defaultConfig.EmuOpt = 0x9d | EOPT_EN_CD_LEDS;
defaultConfig.s_PicoOpt = POPT_EN_STEREO|POPT_EN_FM|POPT_EN_PSG|POPT_EN_Z80 | defaultConfig.s_PicoOpt = POPT_EN_STEREO|POPT_EN_FM|POPT_EN_PSG|POPT_EN_Z80 |
POPT_EN_MCD_PCM|POPT_EN_MCD_CDDA|POPT_EN_MCD_GFX | POPT_EN_MCD_PCM|POPT_EN_MCD_CDDA|POPT_EN_MCD_GFX |
POPT_EN_SVP_DRC|POPT_ACC_SPRITES | POPT_EN_SVP_DRC|POPT_ACC_SPRITES |

View file

@ -21,10 +21,8 @@ extern int g_screen_height;
#define EOPT_SHOW_FPS (1<<1) #define EOPT_SHOW_FPS (1<<1)
#define EOPT_EN_SOUND (1<<2) #define EOPT_EN_SOUND (1<<2)
#define EOPT_GZIP_SAVES (1<<3) #define EOPT_GZIP_SAVES (1<<3)
#define EOPT_MMUHACK (1<<4)
#define EOPT_NO_AUTOSVCFG (1<<5) #define EOPT_NO_AUTOSVCFG (1<<5)
#define EOPT_16BPP (1<<7) // depreceted for .renderer #define EOPT_16BPP (1<<7) // depreceted for .renderer
#define EOPT_RAM_TIMINGS (1<<8)
#define EOPT_EN_CD_LEDS (1<<10) #define EOPT_EN_CD_LEDS (1<<10)
#define EOPT_A_SN_GAMMA (1<<12) #define EOPT_A_SN_GAMMA (1<<12)
#define EOPT_VSYNC (1<<13) #define EOPT_VSYNC (1<<13)

View file

@ -7,6 +7,7 @@
*/ */
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>
#include <time.h>
#include "emu.h" #include "emu.h"
#include "menu_pico.h" #include "menu_pico.h"
@ -66,7 +67,6 @@ static const char *men_dummy[] = { NULL };
#else #else
#define MENU_OPTIONS_GFX #define MENU_OPTIONS_GFX
#define MENU_OPTIONS_ADV #define MENU_OPTIONS_ADV
#define menu_main_plat_draw NULL
#endif #endif
static void make_bg(int no_scale) static void make_bg(int no_scale)
@ -524,6 +524,8 @@ static menu_entry e_menu_adv_options[] =
mee_onoff ("Don't save last used ROM", MA_OPT2_NO_LAST_ROM, currentConfig.EmuOpt, EOPT_NO_AUTOSVCFG), mee_onoff ("Don't save last used ROM", MA_OPT2_NO_LAST_ROM, currentConfig.EmuOpt, EOPT_NO_AUTOSVCFG),
mee_onoff ("Disable idle loop patching",MA_OPT2_NO_IDLE_LOOPS,PicoOpt, POPT_DIS_IDLE_DET), mee_onoff ("Disable idle loop patching",MA_OPT2_NO_IDLE_LOOPS,PicoOpt, POPT_DIS_IDLE_DET),
mee_onoff ("Disable frame limiter", MA_OPT2_NO_FRAME_LIMIT,currentConfig.EmuOpt, EOPT_NO_FRMLIMIT), mee_onoff ("Disable frame limiter", MA_OPT2_NO_FRAME_LIMIT,currentConfig.EmuOpt, EOPT_NO_FRMLIMIT),
mee_onoff ("Enable dynarecs", MA_OPT2_SVP_DYNAREC, PicoOpt, POPT_EN_SVP_DRC),
mee_onoff ("Status line in main menu", MA_OPT2_STATUS_LINE, currentConfig.EmuOpt, EOPT_SHOW_RTC),
MENU_OPTIONS_ADV MENU_OPTIONS_ADV
mee_end, mee_end,
}; };
@ -537,14 +539,20 @@ static int menu_loop_adv_options(int id, int keys)
// ------------ gfx options menu ------------ // ------------ gfx options menu ------------
static const char h_gamma[] = "Gamma/brightness adjustment (default 100)"; static const char h_gamma[] = "Gamma/brightness adjustment (default 1.00)";
static const char *mgn_aopt_gamma(int id, int *offs)
{
sprintf(static_buff, "%i.%02i", currentConfig.gamma / 100, currentConfig.gamma % 100);
return static_buff;
}
static menu_entry e_menu_gfx_options[] = static menu_entry e_menu_gfx_options[] =
{ {
mee_enum ("Video output mode", MA_OPT_VOUT_MODE, plat_target.vout_method, men_dummy), mee_enum ("Video output mode", MA_OPT_VOUT_MODE, plat_target.vout_method, men_dummy),
mee_enum ("Renderer", MA_OPT_RENDERER, currentConfig.renderer, renderer_names), mee_enum ("Renderer", MA_OPT_RENDERER, currentConfig.renderer, renderer_names),
mee_enum ("Filter", MA_OPT3_FILTERING, currentConfig.filter, men_dummy), mee_enum ("Filter", MA_OPT3_FILTERING, currentConfig.filter, men_dummy),
mee_range_h("Gamma adjustment", MA_OPT3_GAMMA, currentConfig.gamma, 1, 200, h_gamma), mee_range_cust_h("Gamma correction", MA_OPT2_GAMMA, currentConfig.gamma, 1, 300, mgn_aopt_gamma, h_gamma),
MENU_OPTIONS_GFX MENU_OPTIONS_GFX
mee_end, mee_end,
}; };
@ -753,10 +761,7 @@ static menu_entry e_menu_options[] =
static int menu_loop_options(int id, int keys) static int menu_loop_options(int id, int keys)
{ {
static int sel = 0; static int sel = 0;
int i;
i = me_id2offset(e_menu_options, MA_OPT_CPU_CLOCKS);
e_menu_options[i].enabled = e_menu_options[i].name[0] ? 1 : 0;
me_enable(e_menu_options, MA_OPT_SAVECFG_GAME, PicoGameLoaded); me_enable(e_menu_options, MA_OPT_SAVECFG_GAME, PicoGameLoaded);
me_enable(e_menu_options, MA_OPT_LOADCFG, config_slot != config_slot_current); me_enable(e_menu_options, MA_OPT_LOADCFG, config_slot != config_slot_current);
@ -941,6 +946,56 @@ static const char credits[] =
" Lordus, Exophase, Rokas,\n" " Lordus, Exophase, Rokas,\n"
" Nemesis, Tasco Deluxe"; " Nemesis, Tasco Deluxe";
static void menu_main_draw_status(void)
{
static time_t last_bat_read = 0;
static int last_bat_val = -1;
unsigned short *bp = g_screen_ptr;
int bat_h = me_mfont_h * 2 / 3;
int i, u, w, wfill, batt_val;
struct tm *tmp;
time_t ltime;
char time_s[16];
if (!(currentConfig.EmuOpt & EOPT_SHOW_RTC))
return;
ltime = time(NULL);
tmp = gmtime(&ltime);
strftime(time_s, sizeof(time_s), "%H:%M", tmp);
text_out16(g_screen_width - me_mfont_w * 6, me_mfont_h + 2, time_s);
if (ltime - last_bat_read > 10) {
last_bat_read = ltime;
last_bat_val = batt_val = plat_target_bat_capacity_get();
}
else
batt_val = last_bat_val;
if (batt_val < 0 || batt_val > 100)
return;
/* battery info */
bp += (me_mfont_h * 2 + 2) * g_screen_width + g_screen_width - me_mfont_w * 3 - 3;
for (i = 0; i < me_mfont_w * 2; i++)
bp[i] = menu_text_color;
for (i = 0; i < me_mfont_w * 2; i++)
bp[i + g_screen_width * bat_h] = menu_text_color;
for (i = 0; i <= bat_h; i++)
bp[i * g_screen_width] =
bp[i * g_screen_width + me_mfont_w * 2] = menu_text_color;
for (i = 2; i < bat_h - 1; i++)
bp[i * g_screen_width - 1] =
bp[i * g_screen_width - 2] = menu_text_color;
w = me_mfont_w * 2 - 1;
wfill = batt_val * w / 100;
for (u = 1; u < bat_h; u++)
for (i = 0; i < wfill; i++)
bp[(w - i) + g_screen_width * u] = menu_text_color;
}
static int main_menu_handler(int id, int keys) static int main_menu_handler(int id, int keys)
{ {
const char *ret_name; const char *ret_name;
@ -1029,7 +1084,7 @@ void menu_loop(void)
menu_enter(PicoGameLoaded); menu_enter(PicoGameLoaded);
in_set_config_int(0, IN_CFG_BLOCKING, 1); in_set_config_int(0, IN_CFG_BLOCKING, 1);
me_loop_d(e_menu_main, &sel, NULL, menu_main_plat_draw); me_loop_d(e_menu_main, &sel, NULL, menu_main_draw_status);
if (PicoGameLoaded) { if (PicoGameLoaded) {
if (engineState == PGS_Menu) if (engineState == PGS_Menu)
@ -1163,6 +1218,12 @@ void menu_init(void)
menu_init_base(); menu_init_base();
i = 0;
#if defined(_SVP_DRC) || defined(DRC_SH2)
i = 1;
#endif
me_enable(e_menu_adv_options, MA_OPT2_SVP_DYNAREC, i);
i = me_id2offset(e_menu_gfx_options, MA_OPT_VOUT_MODE); i = me_id2offset(e_menu_gfx_options, MA_OPT_VOUT_MODE);
e_menu_gfx_options[i].data = plat_target.vout_methods; e_menu_gfx_options[i].data = plat_target.vout_methods;
me_enable(e_menu_gfx_options, MA_OPT_VOUT_MODE, me_enable(e_menu_gfx_options, MA_OPT_VOUT_MODE,
@ -1173,6 +1234,13 @@ void menu_init(void)
me_enable(e_menu_gfx_options, MA_OPT3_FILTERING, me_enable(e_menu_gfx_options, MA_OPT3_FILTERING,
plat_target.hwfilters != NULL); plat_target.hwfilters != NULL);
me_enable(e_menu_gfx_options, MA_OPT3_GAMMA, me_enable(e_menu_gfx_options, MA_OPT2_GAMMA,
plat_target.gamma_set != NULL); plat_target.gamma_set != NULL);
i = me_id2offset(e_menu_options, MA_OPT_CPU_CLOCKS);
e_menu_options[i].enabled = 0;
if (plat_target.cpu_clock_set != NULL) {
e_menu_options[i].name = "CPU clock";
e_menu_options[i].enabled = 1;
}
} }

View file

@ -51,7 +51,6 @@ typedef enum
MA_OPT2_GZIP_STATES, MA_OPT2_GZIP_STATES,
MA_OPT2_NO_LAST_ROM, MA_OPT2_NO_LAST_ROM,
MA_OPT2_RAMTIMINGS, /* gp2x */ MA_OPT2_RAMTIMINGS, /* gp2x */
MA_OPT2_SQUIDGEHACK, /* gp2x */
MA_OPT2_STATUS_LINE, /* psp */ MA_OPT2_STATUS_LINE, /* psp */
MA_OPT2_NO_FRAME_LIMIT, /* psp */ MA_OPT2_NO_FRAME_LIMIT, /* psp */
MA_OPT2_SVP_DYNAREC, MA_OPT2_SVP_DYNAREC,
@ -66,7 +65,6 @@ typedef enum
MA_OPT3_PRES_FULLSCR, MA_OPT3_PRES_FULLSCR,
MA_OPT3_FILTERING, MA_OPT3_FILTERING,
MA_OPT3_VSYNC, MA_OPT3_VSYNC,
MA_OPT3_GAMMA,
MA_OPT3_BLACKLVL, MA_OPT3_BLACKLVL,
MA_OPT3_LAYER_X, MA_OPT3_LAYER_X,
MA_OPT3_LAYER_Y, MA_OPT3_LAYER_Y,

View file

@ -103,7 +103,7 @@ out:
return retval; return retval;
} }
void mp3_start_play(void *f_, int pos) void mp3_start_play(void *f_, int pos1024)
{ {
unsigned char buf[2048]; unsigned char buf[2048];
FILE *f = f_; FILE *f = f_;
@ -117,13 +117,6 @@ void mp3_start_play(void *f_, int pos)
if (!(PicoOpt & POPT_EN_MCD_CDDA) || f == NULL) // cdda disabled or no file? if (!(PicoOpt & POPT_EN_MCD_CDDA) || f == NULL) // cdda disabled or no file?
return; return;
ret = mp3dec_start();
if (ret != 0)
return;
decoder_active = 1;
mp3_current_file = f;
fseek(f, 0, SEEK_END); fseek(f, 0, SEEK_END);
mp3_file_len = ftell(f); mp3_file_len = ftell(f);
@ -144,12 +137,20 @@ void mp3_start_play(void *f_, int pos)
} }
// seek.. // seek..
if (pos) { if (pos1024 != 0) {
unsigned long long pos64 = mp3_file_len - mp3_file_pos; unsigned long long pos64 = mp3_file_len - mp3_file_pos;
pos64 *= pos; pos64 *= pos1024;
mp3_file_pos += pos64 >> 10; mp3_file_pos += pos64 >> 10;
} }
ret = mp3dec_start(f, mp3_file_pos);
if (ret != 0) {
return;
}
mp3_current_file = f;
decoder_active = 1;
mp3dec_decode(mp3_current_file, &mp3_file_pos, mp3_file_len); mp3dec_decode(mp3_current_file, &mp3_file_pos, mp3_file_len);
} }
@ -182,8 +183,9 @@ void mp3_update(int *buffer, int length, int stereo)
} else { } else {
int ret, left = 1152 - cdda_out_pos; int ret, left = 1152 - cdda_out_pos;
mix_samples(buffer, cdda_out_buffer + cdda_out_pos * 2, if (left > 0)
(left >> shr) * 2); mix_samples(buffer, cdda_out_buffer + cdda_out_pos * 2,
(left >> shr) * 2);
ret = mp3dec_decode(mp3_current_file, &mp3_file_pos, ret = mp3dec_decode(mp3_current_file, &mp3_file_pos,
mp3_file_len); mp3_file_len);

View file

@ -6,7 +6,7 @@
int mp3_find_sync_word(const unsigned char *buf, int size); int mp3_find_sync_word(const unsigned char *buf, int size);
/* decoder */ /* decoder */
int mp3dec_start(void); int mp3dec_start(FILE *f, int fpos_start);
int mp3dec_decode(FILE *f, int *file_pos, int file_len); int mp3dec_decode(FILE *f, int *file_pos, int file_len);
extern unsigned short mpeg1_l3_bitrates[16]; extern unsigned short mpeg1_l3_bitrates[16];

View file

@ -9,7 +9,7 @@
#include <stdio.h> #include <stdio.h>
#include "mp3.h" #include "mp3.h"
int mp3dec_start(void) int mp3dec_start(FILE *f, int fpos_start)
{ {
return -1; return -1;
} }

View file

@ -84,7 +84,7 @@ int mp3dec_decode(FILE *f, int *file_pos, int file_len)
return 0; return 0;
} }
int mp3dec_start(void) int mp3dec_start(FILE *f, int fpos_start)
{ {
// must re-init decoder for new track // must re-init decoder for new track
if (mp3dec) if (mp3dec)

View file

@ -91,7 +91,7 @@ int mp3dec_decode(FILE *f, int *file_pos, int file_len)
return 0; return 0;
} }
int mp3dec_start(void) int mp3dec_start(FILE *f, int fpos_start)
{ {
void (*avcodec_register_all)(void); void (*avcodec_register_all)(void);
AVCodec *(*avcodec_find_decoder)(enum CodecID id); AVCodec *(*avcodec_find_decoder)(enum CodecID id);

View file

@ -15,17 +15,19 @@
#include <fcntl.h> #include <fcntl.h>
#include <errno.h> #include <errno.h>
#include "code940/940shared.h" #include "../libpicofe/input.h"
#include "soc_mmsp2.h" #include "../libpicofe/gp2x/soc_mmsp2.h"
#include "soc.h" #include "../libpicofe/gp2x/soc.h"
#include "../common/mp3.h" #include "../common/mp3.h"
#include "../common/arm_utils.h" #include "../common/arm_utils.h"
#include "../common/menu.h" #include "../common/menu_pico.h"
#include "../common/emu.h" #include "../common/emu.h"
#include "../common/input.h"
#include "../../pico/pico_int.h" #include "../../pico/pico_int.h"
#include "../../pico/sound/ym2612.h" #include "../../pico/sound/ym2612.h"
#include "../../pico/sound/mix.h" #include "../../pico/sound/mix.h"
#include "code940/940shared.h"
#include "plat.h"
#include "940ctl.h"
static unsigned char *shared_mem = 0; static unsigned char *shared_mem = 0;
static _940_data_t *shared_data = 0; static _940_data_t *shared_data = 0;
@ -122,14 +124,14 @@ int YM2612Write_940(unsigned int a, unsigned int v, int scanline)
#define CHECK_BUSY(job) \ #define CHECK_BUSY(job) \
(gp2x_memregs[0x3b46>>1] & (1<<(job-1))) (memregs[0x3b46>>1] & (1<<(job-1)))
static void wait_busy_940(int job) static void wait_busy_940(int job)
{ {
int i; int i;
job--; job--;
for (i = 0; (gp2x_memregs[0x3b46>>1] & (1<<job)) && i < 0x10000; i++) for (i = 0; (memregs[0x3b46>>1] & (1<<job)) && i < 0x10000; i++)
spend_cycles(8*1024); // tested to be best for mp3 dec spend_cycles(8*1024); // tested to be best for mp3 dec
if (i < 0x10000) return; if (i < 0x10000) return;
@ -138,19 +140,19 @@ static void wait_busy_940(int job)
for (i = 0; i < 8; i++) for (i = 0; i < 8; i++)
printf("%i ", shared_ctl->vstarts[i]); printf("%i ", shared_ctl->vstarts[i]);
printf(")\n"); printf(")\n");
printf("irq pending flags: DUALCPU %04x, SRCPND %08lx (see 26), INTPND %08lx\n", printf("irq pending flags: DUALCPU %04x, SRCPND %08x (see 26), INTPND %08x\n",
gp2x_memregs[0x3b46>>1], gp2x_memregl[0x4500>>2], gp2x_memregl[0x4510>>2]); memregs[0x3b46>>1], memregl[0x4500>>2], memregl[0x4510>>2]);
printf("last lr: %08x, lastjob: %i\n", shared_ctl->last_lr, shared_ctl->lastjob); printf("last lr: %08x, lastjob: %i\n", shared_ctl->last_lr, shared_ctl->lastjob);
printf("trying to interrupt..\n"); printf("trying to interrupt..\n");
gp2x_memregs[0x3B3E>>1] = 0xffff; memregs[0x3B3E>>1] = 0xffff;
for (i = 0; gp2x_memregs[0x3b46>>1] && i < 0x10000; i++) for (i = 0; memregs[0x3b46>>1] && i < 0x10000; i++)
spend_cycles(8*1024); spend_cycles(8*1024);
printf("i = 0x%x\n", i); printf("i = 0x%x\n", i);
printf("irq pending flags: DUALCPU %04x, SRCPND %08lx (see 26), INTPND %08lx\n", printf("irq pending flags: DUALCPU %04x, SRCPND %08x (see 26), INTPND %08x\n",
gp2x_memregs[0x3b46>>1], gp2x_memregl[0x4500>>2], gp2x_memregl[0x4510>>2]); memregs[0x3b46>>1], memregl[0x4500>>2], memregl[0x4510>>2]);
printf("last lr: %08x, lastjob: %i\n", shared_ctl->last_lr, shared_ctl->lastjob); printf("last lr: %08x, lastjob: %i\n", shared_ctl->last_lr, shared_ctl->lastjob);
me_update_msg("940 crashed, too much overclock?"); menu_update_msg("940 crashed, too much overclock?");
engineState = PGS_Menu; engineState = PGS_Menu;
crashed_940 = 1; crashed_940 = 1;
} }
@ -165,9 +167,9 @@ static void add_job_940(int job)
// generate interrupt for this job // generate interrupt for this job
job--; job--;
gp2x_memregs[(0x3B20+job*2)>>1] = 1; memregs[(0x3B20+job*2)>>1] = 1;
// printf("added %i, pending %04x\n", job+1, gp2x_memregs[0x3b46>>1]); // printf("added %i, pending %04x\n", job+1, memregs[0x3b46>>1]);
} }
@ -288,11 +290,11 @@ void YM2612Init_940(int baseclock, int rate)
reset940(1, 2); reset940(1, 2);
pause940(1); pause940(1);
gp2x_memregs[0x3B40>>1] = 0; // disable DUALCPU interrupts for 920 memregs[0x3B40>>1] = 0; // disable DUALCPU interrupts for 920
gp2x_memregs[0x3B42>>1] = 1; // enable DUALCPU interrupts for 940 memregs[0x3B42>>1] = 1; // enable DUALCPU interrupts for 940
gp2x_memregl[0x4504>>2] = 0; // make sure no FIQs will be generated memregl[0x4504>>2] = 0; // make sure no FIQs will be generated
gp2x_memregl[0x4508>>2] = ~(1<<26); // unmask DUALCPU ints in the undocumented 940's interrupt controller memregl[0x4508>>2] = ~(1<<26); // unmask DUALCPU ints in the undocumented 940's interrupt controller
if (crashed_940) if (crashed_940)
@ -310,7 +312,7 @@ void YM2612Init_940(int baseclock, int rate)
text_out16(10, 100, "failed to open required file:"); text_out16(10, 100, "failed to open required file:");
text_out16(10, 110, CODE940_FILE); text_out16(10, 110, CODE940_FILE);
gp2x_video_flip2(); gp2x_video_flip2();
in_menu_wait(PBTN_MOK|PBTN_MBACK, 100); in_menu_wait(PBTN_MOK|PBTN_MBACK, NULL, 100);
printf("failed to open %s\n", binpath); printf("failed to open %s\n", binpath);
exit(1); exit(1);
} }
@ -335,11 +337,11 @@ void YM2612Init_940(int baseclock, int rate)
internal_reset(); internal_reset();
loaded_mp3 = 0; loaded_mp3 = NULL;
gp2x_memregs[0x3B46>>1] = 0xffff; // clear pending DUALCPU interrupts for 940 memregs[0x3B46>>1] = 0xffff; // clear pending DUALCPU interrupts for 940
gp2x_memregl[0x4500>>2] = 0xffffffff; // clear pending IRQs in SRCPND memregl[0x4500>>2] = 0xffffffff; // clear pending IRQs in SRCPND
gp2x_memregl[0x4510>>2] = 0xffffffff; // clear pending IRQs in INTPND memregl[0x4510>>2] = 0xffffffff; // clear pending IRQs in INTPND
/* start the 940 */ /* start the 940 */
reset940(0, 2); reset940(0, 2);
@ -410,85 +412,45 @@ int YM2612UpdateOne_940(int *buffer, int length, int stereo, int is_buf_empty)
/***********************************************************/ /***********************************************************/
static int mp3_samples_ready = 0, mp3_buffer_offs = 0; // FIXME: double buffering no longer used..
static int mp3_play_bufsel = 0, mp3_job_started = 0;
void mp3_update(int *buffer, int length, int stereo) int mp3dec_decode(FILE *f, int *file_pos, int file_len)
{ {
int length_mp3;
if (!(PicoOpt & POPT_EXT_FM)) { if (!(PicoOpt & POPT_EXT_FM)) {
mp3_update_local(buffer, length, stereo); //mp3_update_local(buffer, length, stereo);
return; return 0;
} }
// check if playback was started, track not ended // check if playback was started, track not ended
if (loaded_mp3 == NULL || shared_ctl->mp3_offs >= shared_ctl->mp3_len) if (loaded_mp3 == NULL || shared_ctl->mp3_offs >= shared_ctl->mp3_len) {
return; *file_pos = file_len;
return 1;
length_mp3 = length; }
if (PsndRate == 22050) length_mp3 <<= 1; // mp3s are locked to 44100Hz stereo
else if (PsndRate == 11025) length_mp3 <<= 2; // so make length 44100ish
/* do we have to wait? */ /* do we have to wait? */
if (mp3_job_started && mp3_samples_ready < length_mp3) { if (CHECK_BUSY(JOB940_MP3DECODE))
if (CHECK_BUSY(JOB940_MP3DECODE)) wait_busy_940(JOB940_MP3DECODE); wait_busy_940(JOB940_MP3DECODE);
mp3_job_started = 0;
mp3_samples_ready += 1152;
}
/* mix mp3 data, only stereo */ memcpy(cdda_out_buffer,
if (mp3_samples_ready >= length_mp3) shared_data->mp3_buffer[shared_ctl->mp3_buffsel],
{ sizeof(cdda_out_buffer));
int shr = 0;
void (*mix_samples)(int *dest_buf, short *mp3_buf, int count) = mix_16h_to_32;
if (PsndRate == 22050) { mix_samples = mix_16h_to_32_s1; shr = 1; }
else if (PsndRate == 11025) { mix_samples = mix_16h_to_32_s2; shr = 2; }
if (1152 - mp3_buffer_offs >= length_mp3) { *file_pos = shared_ctl->mp3_offs;
mix_samples(buffer, shared_data->mp3_buffer[mp3_play_bufsel] + mp3_buffer_offs*2, length<<1);
mp3_buffer_offs += length_mp3; if (shared_ctl->mp3_offs < shared_ctl->mp3_len) {
} else { // ask to decode more
// collect samples from both buffers.. //shared_ctl->mp3_buffsel ^= 1;
int left = 1152 - mp3_buffer_offs;
if (mp3_play_bufsel == 0)
{
mix_samples(buffer, shared_data->mp3_buffer[0] + mp3_buffer_offs*2, length<<1);
mp3_buffer_offs = length_mp3 - left;
mp3_play_bufsel = 1;
} else {
mix_samples(buffer, shared_data->mp3_buffer[1] + mp3_buffer_offs*2, (left>>shr)<<1);
mp3_buffer_offs = length_mp3 - left;
mix_samples(buffer + ((left>>shr)<<1),
shared_data->mp3_buffer[0], (mp3_buffer_offs>>shr)<<1);
mp3_play_bufsel = 0;
}
}
mp3_samples_ready -= length_mp3;
}
// ask to decode more if we already can
if (!mp3_job_started)
{
mp3_job_started = 1;
shared_ctl->mp3_buffsel ^= 1;
add_job_940(JOB940_MP3DECODE); add_job_940(JOB940_MP3DECODE);
} }
return 0;
} }
int mp3dec_start(FILE *f, int fpos_start)
void mp3_start_play(void *f_, int pos) // pos is 0-1023
{ {
int byte_offs = 0;
FILE *f = f_;
if (!(PicoOpt & POPT_EN_MCD_CDDA) || f == NULL)
return;
if (!(PicoOpt & POPT_EXT_FM)) { if (!(PicoOpt & POPT_EXT_FM)) {
mp3_start_play_local(f, pos); //mp3_start_play_local(f, pos);
return; return -1;
} }
if (loaded_mp3 != f) if (loaded_mp3 != f)
@ -501,34 +463,31 @@ void mp3_start_play(void *f_, int pos) // pos is 0-1023
} }
fseek(f, 0, SEEK_SET); fseek(f, 0, SEEK_SET);
fread(mp3_mem, 1, MP3_SIZE_MAX, f); fread(mp3_mem, 1, MP3_SIZE_MAX, f);
if (!feof(f)) printf("Warning: mp3 was too large, not all data loaded.\n"); if (!feof(f))
printf("Warning: mp3 was too large, not all data loaded.\n");
shared_ctl->mp3_len = ftell(f); shared_ctl->mp3_len = ftell(f);
loaded_mp3 = f; loaded_mp3 = f;
if (PicoOpt & POPT_EXT_FM) { // as we are going to change 940's cacheable area,
// as we are going to change 940's cacheable area, we must invalidate it's cache.. // we must invalidate it's cache..
if (CHECK_BUSY(JOB940_MP3DECODE)) wait_busy_940(JOB940_MP3DECODE); if (CHECK_BUSY(JOB940_MP3DECODE))
add_job_940(JOB940_INVALIDATE_DCACHE); wait_busy_940(JOB940_MP3DECODE);
} add_job_940(JOB940_INVALIDATE_DCACHE);
reset_timing = 1; reset_timing = 1;
} }
// seek.. shared_ctl->mp3_offs = fpos_start;
if (pos) { shared_ctl->mp3_buffsel = 0;
byte_offs = (shared_ctl->mp3_len << 6) >> 10;
byte_offs *= pos;
byte_offs >>= 6;
}
printf(" mp3 pos1024: %i, byte_offs %i/%i\n", pos, byte_offs, shared_ctl->mp3_len);
shared_ctl->mp3_offs = byte_offs;
// reset buffer pointers and stuff..
mp3_samples_ready = mp3_buffer_offs = mp3_play_bufsel = 0;
mp3_job_started = 0;
shared_ctl->mp3_buffsel = 1; // will change to 0 on first decode
add_job_940(JOB940_MP3RESET); add_job_940(JOB940_MP3RESET);
if (CHECK_BUSY(JOB940_MP3RESET)) wait_busy_940(JOB940_MP3RESET); if (CHECK_BUSY(JOB940_MP3RESET))
wait_busy_940(JOB940_MP3RESET);
// because we decode ahea, need to start now
if (shared_ctl->mp3_offs < shared_ctl->mp3_len) {
add_job_940(JOB940_MP3DECODE);
}
return 0;
} }

View file

@ -1,111 +1,6 @@
CROSS ?= arm-linux-
# settings
use_cyclone = 1
#use_musashi = 1
use_drz80 = 1
use_sh2drc = 1
#use_sh2mame = 1
asm_memory = 1
asm_render = 1
asm_ym2612 = 1
asm_misc = 1
asm_cdpico = 1
asm_cdmemory = 1
asm_32xdraw = 1
#profile = 1
#drc_debug = 3
-include Makefile.local
ifeq "$(debug_cyclone)" "1"
use_cyclone = 1
use_musashi = 1
endif
ifeq "$(use_musashi)" "1"
# due to CPU stop flag acces
asm_cdpico = 0
asm_cdmemory = 0
endif
ARCH = arm
DEFINES += ARM __GP2X__ IN_GP2X IN_EVDEV # BENCHMARK
CFLAGS += -Wall -Winline -I../.. -I.
ifeq ($(DEBUG),)
CFLAGS += -O3 -fomit-frame-pointer -fstrict-aliasing -ffast-math
endif
CFLAGS += -mcpu=arm920t -mtune=arm920t
ASFLAGS = -mcpu=arm920t -mfloat-abi=soft
LDFLAGS += -lm -lpng
CC = $(CROSS)gcc
STRIP = $(CROSS)strip
AS = $(CROSS)as
LD = $(CROSS)ld
OBJCOPY = $(CROSS)objcopy
# frontend
OBJS += plat.o warm.o pollux_set.o soc.o soc_mmsp2.o soc_pollux.o soc_dummy.o emu.o in_gp2x.o
# 940 core control
OBJS += 940ctl.o
# ARM stuff
OBJS += pico/carthw/svp/compiler.o pico/carthw/svp/stub_arm.o
OBJS += pico/sound/mix_arm.o
# common
OBJS += platform/common/emu.o platform/common/menu_pico.o platform/common/fonts.o platform/common/config.o \
platform/common/arm_utils.o platform/common/arm_linux.o platform/common/readpng.o \
platform/common/mp3_helix.o platform/common/input.o platform/common/main.o platform/common/mp3.o \
platform/linux/sndout_oss.o platform/linux/plat.o platform/linux/in_evdev.o
# unzip
OBJS += unzip/unzip.o unzip/unzip_stream.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
vpath %.c = ../..
vpath %.s = ../..
vpath %.S = ../..
DIRS += platform/gp2x platform/linux zlib unzip
all: mkdirs PicoDrive
include ../common/common.mak
include ../common/common_arm.mak
include ../common/revision.mak
CFLAGS += $(addprefix -D,$(DEFINES))
# partial linking helps profiled builds due to section merging
PicoDrive.o : $(OBJS) ../common/helix/$(CROSS)helix-mp3.a
$(LD) -r -o $@ $^
# still using static, dynamic linking slows Wiz 1-10%
# also libm on F100 is not compatible
PicoDrive : PicoDrive.o
@echo ">>>" $@
$(CC) -static -o $@ $(CFLAGS) $^ $(LDFLAGS) -Wl,-Map=$@.map
ifeq ($(DEBUG),)
$(STRIP) $@
endif
up: PicoDrive
@cp -v PicoDrive /mnt/gp2x/mnt/sd/emus/PicoDrive/
clean: tidy
$(RM) PicoDrive
tidy:
$(RM) $(OBJS)
readme.txt: ../../tools/textfilter ../base_readme.txt readme.txt: ../../tools/textfilter ../base_readme.txt
../../tools/textfilter ../base_readme.txt $@ GP2X ../../tools/textfilter ../base_readme.txt $@ GP2X
# ----------- release -----------
VER ?= $(shell head -n 1 version.h | sed 's/.*"\(.*\)\.\(.*\)".*/\1\2/g') VER ?= $(shell head -n 1 version.h | sed 's/.*"\(.*\)\.\(.*\)".*/\1\2/g')
CODE940 = code940/pico940_v3.bin CODE940 = code940/pico940_v3.bin
@ -125,4 +20,3 @@ rel: PicoDrive PicoDrive.gpe $(CODE940) readme.txt ../game_def.cfg \
$(CODE940): $(CODE940):
make -C code940/ make -C code940/

View file

@ -1,5 +1,4 @@
#include "../../../pico/sound/ym2612.h" #include "../../../pico/sound/ym2612.h"
#include "../../common/helix/pub/mp3dec.h"
// max 16 jobs, lower num means higher prio // max 16 jobs, lower num means higher prio
enum _940_job_t { enum _940_job_t {
@ -20,7 +19,7 @@ enum _940_job_t {
typedef struct typedef struct
{ {
YM2612 ym2612; /* current state of the emulated YM2612 */ YM2612 ym2612; /* current state of the emulated YM2612 */
HMP3Decoder mp3dec; /* mp3 decoder's handle */ void *mp3dec; /* mp3 decoder's handle */
int ym_buffer[44100/50*2]; /* this is where the YM2612 samples will be mixed to */ int ym_buffer[44100/50*2]; /* this is where the YM2612 samples will be mixed to */
short mp3_buffer[2][1152*2]; /* buffers for mp3 decoder's output */ short mp3_buffer[2][1152*2]; /* buffers for mp3 decoder's output */
} _940_data_t; } _940_data_t;

View file

@ -15,18 +15,17 @@
#include <stdlib.h> #include <stdlib.h>
#include <unistd.h> #include <unistd.h>
#include "plat_gp2x.h" #include "../libpicofe/gp2x/plat_gp2x.h"
#include "soc.h" #include "../libpicofe/gp2x/soc.h"
#include "soc_pollux.h" #include "../libpicofe/input.h"
#include "../common/plat.h" #include "../libpicofe/plat.h"
#include "../common/menu.h" #include "../libpicofe/gp2x/soc_pollux.h"
#include "../common/menu_pico.h"
#include "../common/arm_utils.h" #include "../common/arm_utils.h"
#include "../common/fonts.h"
#include "../common/emu.h" #include "../common/emu.h"
#include "../common/config.h" #include "../common/config_file.h"
#include "../common/input.h" #include "../common/version.h"
#include "../linux/sndout_oss.h" #include "plat.h"
#include "version.h"
#include <pico/pico_int.h> #include <pico/pico_int.h>
#include <pico/patch.h> #include <pico/patch.h>
@ -40,9 +39,8 @@
#endif #endif
extern int crashed_940; //extern int crashed_940;
static short __attribute__((aligned(4))) sndBuffer[2*(44100+100)/50];
static int osd_fps_x, osd_y, doing_bg_frame; static int osd_fps_x, osd_y, doing_bg_frame;
const char *renderer_names[] = { "16bit accurate", " 8bit accurate", " 8bit fast", NULL }; const char *renderer_names[] = { "16bit accurate", " 8bit accurate", " 8bit fast", NULL };
const char *renderer_names32x[] = { "accurate", "faster", "fastest", NULL }; const char *renderer_names32x[] = { "accurate", "faster", "fastest", NULL };
@ -51,8 +49,6 @@ enum renderer_types { RT_16BIT, RT_8BIT_ACC, RT_8BIT_FAST, RT_COUNT };
static int (*emu_scan_begin)(unsigned int num) = NULL; static int (*emu_scan_begin)(unsigned int num) = NULL;
static int (*emu_scan_end)(unsigned int num) = NULL; static int (*emu_scan_end)(unsigned int num) = NULL;
extern void *gp2x_screens[4];
void pemu_prep_defconfig(void) void pemu_prep_defconfig(void)
{ {
@ -670,8 +666,8 @@ static void RunEventsPico(unsigned int events)
void plat_update_volume(int has_changed, int is_up) void plat_update_volume(int has_changed, int is_up)
{ {
static int prev_frame = 0, wait_frames = 0; static int prev_frame = 0, wait_frames = 0;
int vol = currentConfig.volume;
int need_low_volume = 0; int need_low_volume = 0;
int vol = currentConfig.volume;
gp2x_soc_t soc; gp2x_soc_t soc;
soc = soc_detect(); soc = soc_detect();
@ -683,14 +679,9 @@ void plat_update_volume(int has_changed, int is_up)
if (need_low_volume && vol < 5 && prev_frame == Pico.m.frame_count - 1 && wait_frames < 12) if (need_low_volume && vol < 5 && prev_frame == Pico.m.frame_count - 1 && wait_frames < 12)
wait_frames++; wait_frames++;
else { else {
if (is_up) {
if (vol < 99) vol++;
} else {
if (vol > 0) vol--;
}
wait_frames = 0; wait_frames = 0;
sndout_oss_setvol(vol, vol); plat_target_step_volume(&currentConfig.volume, is_up ? 1 : -1);
currentConfig.volume = vol; vol = currentConfig.volume;
} }
emu_status_msg("VOL: %02i", vol); emu_status_msg("VOL: %02i", vol);
prev_frame = Pico.m.frame_count; prev_frame = Pico.m.frame_count;
@ -708,17 +699,13 @@ void plat_update_volume(int has_changed, int is_up)
} }
} }
static void oss_write_nonblocking(int len)
{
// sndout_oss_can_write() is not reliable, only use with no_frmlimit
if ((currentConfig.EmuOpt & EOPT_NO_FRMLIMIT) && !sndout_oss_can_write(len))
return;
sndout_oss_write_nb(PsndOut, len);
}
void pemu_sound_start(void) void pemu_sound_start(void)
{ {
emu_sound_start();
plat_target_step_volume(&currentConfig.volume, 0);
#if 0
static int PsndRate_old = 0, PicoOpt_old = 0, pal_old = 0; static int PsndRate_old = 0, PicoOpt_old = 0, pal_old = 0;
PsndOut = NULL; PsndOut = NULL;
@ -754,6 +741,7 @@ void pemu_sound_start(void)
PicoOpt_old = PicoOpt; PicoOpt_old = PicoOpt;
pal_old = Pico.m.pal; pal_old = Pico.m.pal;
} }
#endif
} }
static const int sound_rates[] = { 44100, 32000, 22050, 16000, 11025, 8000 }; static const int sound_rates[] = { 44100, 32000, 22050, 16000, 11025, 8000 };
@ -772,11 +760,6 @@ void pemu_sound_stop(void)
} }
} }
void pemu_sound_wait(void)
{
// don't need to do anything, writes will block by themselves
}
void pemu_forced_frame(int no_scale, int do_emu) void pemu_forced_frame(int no_scale, int do_emu)
{ {
doing_bg_frame = 1; doing_bg_frame = 1;
@ -794,110 +777,23 @@ void plat_debug_cat(char *str)
{ {
} }
#if 0 void plat_video_loop_prepare(void)
static void tga_dump(void)
{ {
#define BYTE unsigned char
#define WORD unsigned short
struct
{
BYTE IDLength; /* 00h Size of Image ID field */
BYTE ColorMapType; /* 01h Color map type */
BYTE ImageType; /* 02h Image type code */
WORD CMapStart; /* 03h Color map origin */
WORD CMapLength; /* 05h Color map length */
BYTE CMapDepth; /* 07h Depth of color map entries */
WORD XOffset; /* 08h X origin of image */
WORD YOffset; /* 0Ah Y origin of image */
WORD Width; /* 0Ch Width of image */
WORD Height; /* 0Eh Height of image */
BYTE PixelDepth; /* 10h Image pixel size */
BYTE ImageDescriptor; /* 11h Image descriptor byte */
} __attribute__((packed)) TGAHEAD;
static unsigned short oldscr[320*240];
FILE *f; char name[128]; int i;
memset(&TGAHEAD, 0, sizeof(TGAHEAD));
TGAHEAD.ImageType = 2;
TGAHEAD.Width = 320;
TGAHEAD.Height = 240;
TGAHEAD.PixelDepth = 16;
TGAHEAD.ImageDescriptor = 2<<4; // image starts at top-left
#define CONV(X) (((X>>1)&0x7fe0)|(X&0x1f)) // 555?
for (i = 0; i < 320*240; i++)
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 *)g_screen_ptr)[i]);
sprintf(name, "%05i.tga", Pico.m.frame_count);
f = fopen(name, "wb");
if (!f) { printf("!f\n"); exit(1); }
fwrite(&TGAHEAD, 1, sizeof(TGAHEAD), f);
fwrite(oldscr, 1, 320*240*2, f);
fclose(f);
}
}
#endif
void pemu_loop_prep(void)
{
static int gp2x_old_clock = -1, EmuOpt_old = 0, pal_old = 0;
static int gp2x_old_gamma = 100;
gp2x_soc_t soc;
soc = soc_detect();
if ((EmuOpt_old ^ currentConfig.EmuOpt) & EOPT_RAM_TIMINGS) {
if (currentConfig.EmuOpt & EOPT_RAM_TIMINGS)
set_ram_timings();
else
unset_ram_timings();
}
if (gp2x_old_clock < 0)
gp2x_old_clock = default_cpu_clock;
if (gp2x_old_clock != currentConfig.CPUclock && gp2x_set_cpuclk != NULL) {
printf("changing clock to %i...", currentConfig.CPUclock); fflush(stdout);
gp2x_set_cpuclk(currentConfig.CPUclock);
gp2x_old_clock = currentConfig.CPUclock;
printf(" done\n");
}
if (gp2x_old_gamma != currentConfig.gamma || ((EmuOpt_old ^ currentConfig.EmuOpt) & EOPT_A_SN_GAMMA)) {
set_lcd_gamma(currentConfig.gamma, !!(currentConfig.EmuOpt & EOPT_A_SN_GAMMA));
gp2x_old_gamma = currentConfig.gamma;
printf("updated gamma to %i, A_SN's curve: %i\n", currentConfig.gamma, !!(currentConfig.EmuOpt&0x1000));
}
if (((EmuOpt_old ^ currentConfig.EmuOpt) & EOPT_VSYNC) || Pico.m.pal != pal_old) {
if ((currentConfig.EmuOpt & EOPT_VSYNC) || soc == SOCID_POLLUX)
set_lcd_custom_rate(Pico.m.pal);
else if (EmuOpt_old & EOPT_VSYNC)
unset_lcd_custom_rate();
}
if (gp2x_dev_id == GP2X_DEV_CAANOO)
in_set_config_int(in_name_to_id("evdev:pollux-analog"), IN_CFG_ABS_DEAD_ZONE,
currentConfig.analog_deadzone);
if ((EmuOpt_old ^ currentConfig.EmuOpt) & EOPT_MMUHACK)
gp2x_make_fb_bufferable(currentConfig.EmuOpt & EOPT_MMUHACK);
EmuOpt_old = currentConfig.EmuOpt;
pal_old = Pico.m.pal;
// make sure we are in correct mode // make sure we are in correct mode
change_renderer(0); change_renderer(0);
vid_reset_mode(); vid_reset_mode();
}
void pemu_loop_prep(void)
{
if (gp2x_dev_id == GP2X_DEV_CAANOO)
in_set_config_int(in_name_to_id("evdev:pollux-analog"),
IN_CFG_ABS_DEAD_ZONE,
currentConfig.analog_deadzone);
// dirty buffers better go now than during gameplay // dirty buffers better go now than during gameplay
sync(); sync();
sleep(0); sleep(0);
pemu_sound_start();
} }
void pemu_loop_end(void) void pemu_loop_end(void)

View file

@ -1,311 +0,0 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#include "../common/input.h"
#include "in_gp2x.h"
#define IN_GP2X_PREFIX "gp2x:"
#define IN_GP2X_NBUTTONS 32
/* note: in_gp2x hadles combos (if 2 btns have the same bind,
* both must be pressed for action to happen) */
static int in_gp2x_combo_keys = 0;
static int in_gp2x_combo_acts = 0;
static int gpiodev = -1; /* Wiz only */
static int (*in_gp2x_get_bits)(void);
static const char *in_gp2x_keys[IN_GP2X_NBUTTONS] = {
[0 ... IN_GP2X_NBUTTONS-1] = NULL,
[GP2X_BTN_UP] = "Up", [GP2X_BTN_LEFT] = "Left",
[GP2X_BTN_DOWN] = "Down", [GP2X_BTN_RIGHT] = "Right",
[GP2X_BTN_START] = "Start", [GP2X_BTN_SELECT] = "Select",
[GP2X_BTN_L] = "L", [GP2X_BTN_R] = "R",
[GP2X_BTN_A] = "A", [GP2X_BTN_B] = "B",
[GP2X_BTN_X] = "X", [GP2X_BTN_Y] = "Y",
[GP2X_BTN_VOL_DOWN] = "VOL DOWN",
[GP2X_BTN_VOL_UP] = "VOL UP",
[GP2X_BTN_PUSH] = "PUSH"
};
static int in_gp2x_get_mmsp2_bits(void)
{
extern volatile unsigned short *gp2x_memregs;
int value;
value = gp2x_memregs[0x1198>>1] & 0xff; // 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; // GPIO C
value |= gp2x_memregs[0x1186>>1] << 16; // GPIO D
value = ~value & 0x08c0ff55;
return value;
}
static int in_gp2x_get_wiz_bits(void)
{
int r, value = 0;
r = read(gpiodev, &value, 4);
if (value & 0x02)
value |= 0x05;
if (value & 0x08)
value |= 0x14;
if (value & 0x20)
value |= 0x50;
if (value & 0x80)
value |= 0x41;
/* convert to GP2X style */
value &= 0x7ff55;
if (value & (1 << 16))
value |= 1 << GP2X_BTN_VOL_UP;
if (value & (1 << 17))
value |= 1 << GP2X_BTN_VOL_DOWN;
if (value & (1 << 18))
value |= 1 << GP2X_BTN_PUSH;
value &= ~0x70000;
return value;
}
#ifdef FAKE_IN_GP2X
volatile unsigned short *gp2x_memregs;
int gp2x_dev_id = -1;
static int in_gp2x_get_fake_bits(void)
{
extern int current_keys;
return current_keys;
}
#endif
static void in_gp2x_probe(void)
{
switch (gp2x_dev_id)
{
case GP2X_DEV_GP2X:
in_gp2x_get_bits = in_gp2x_get_mmsp2_bits;
break;
case GP2X_DEV_WIZ:
gpiodev = open("/dev/GPIO", O_RDONLY);
if (gpiodev < 0) {
perror("in_gp2x: couldn't open /dev/GPIO");
return;
}
in_gp2x_get_bits = in_gp2x_get_wiz_bits;
break;
// we'll use evdev for Caanoo
default:
#ifdef FAKE_IN_GP2X
in_gp2x_get_bits = in_gp2x_get_fake_bits;
break;
#endif
return;
}
in_register(IN_GP2X_PREFIX "GP2X pad", -1, NULL,
IN_GP2X_NBUTTONS, in_gp2x_keys, 1);
}
static void in_gp2x_free(void *drv_data)
{
if (gpiodev >= 0) {
close(gpiodev);
gpiodev = -1;
}
}
static const char * const *
in_gp2x_get_key_names(int *count)
{
*count = IN_GP2X_NBUTTONS;
return in_gp2x_keys;
}
/* ORs result with pressed buttons */
static int in_gp2x_update(void *drv_data, const int *binds, int *result)
{
int type_start = 0;
int i, t, keys;
keys = in_gp2x_get_bits();
if (keys & in_gp2x_combo_keys) {
result[IN_BINDTYPE_EMU] = in_combos_do(keys, binds, GP2X_BTN_PUSH,
in_gp2x_combo_keys, in_gp2x_combo_acts);
type_start = IN_BINDTYPE_PLAYER12;
}
for (i = 0; keys; i++, keys >>= 1) {
if (!(keys & 1))
continue;
for (t = type_start; t < IN_BINDTYPE_COUNT; t++)
result[t] |= binds[IN_BIND_OFFS(i, t)];
}
return 0;
}
int in_gp2x_update_keycode(void *data, int *is_down)
{
static int old_val = 0;
int val, diff, i;
val = in_gp2x_get_bits();
diff = val ^ old_val;
if (diff == 0)
return -1;
/* take one bit only */
for (i = 0; i < sizeof(diff)*8; i++)
if (diff & (1<<i))
break;
old_val ^= 1 << i;
if (is_down)
*is_down = !!(val & (1<<i));
return i;
}
static const struct {
short key;
short pbtn;
} key_pbtn_map[] =
{
{ GP2X_BTN_UP, PBTN_UP },
{ GP2X_BTN_DOWN, PBTN_DOWN },
{ GP2X_BTN_LEFT, PBTN_LEFT },
{ GP2X_BTN_RIGHT, PBTN_RIGHT },
{ GP2X_BTN_B, PBTN_MOK },
{ GP2X_BTN_X, PBTN_MBACK },
{ GP2X_BTN_A, PBTN_MA2 },
{ GP2X_BTN_Y, PBTN_MA3 },
{ GP2X_BTN_L, PBTN_L },
{ GP2X_BTN_R, PBTN_R },
{ GP2X_BTN_SELECT, PBTN_MENU },
};
#define KEY_PBTN_MAP_SIZE (sizeof(key_pbtn_map) / sizeof(key_pbtn_map[0]))
static int in_gp2x_menu_translate(void *drv_data, int keycode)
{
int i;
if (keycode < 0)
{
/* menu -> kc */
keycode = -keycode;
for (i = 0; i < KEY_PBTN_MAP_SIZE; i++)
if (key_pbtn_map[i].pbtn == keycode)
return key_pbtn_map[i].key;
}
else
{
for (i = 0; i < KEY_PBTN_MAP_SIZE; i++)
if (key_pbtn_map[i].key == keycode)
return key_pbtn_map[i].pbtn;
}
return 0;
}
#if 0 // TODO: move to pico
static const struct {
short code;
char btype;
char bit;
} in_gp2x_defbinds[] =
{
/* MXYZ SACB RLDU */
{ BTN_UP, IN_BINDTYPE_PLAYER12, 0 },
{ BTN_DOWN, IN_BINDTYPE_PLAYER12, 1 },
{ BTN_LEFT, IN_BINDTYPE_PLAYER12, 2 },
{ BTN_RIGHT, IN_BINDTYPE_PLAYER12, 3 },
{ BTN_X, IN_BINDTYPE_PLAYER12, 4 }, /* B */
{ BTN_B, IN_BINDTYPE_PLAYER12, 5 }, /* C */
{ BTN_A, IN_BINDTYPE_PLAYER12, 6 }, /* A */
{ BTN_START, IN_BINDTYPE_PLAYER12, 7 },
{ BTN_SELECT, IN_BINDTYPE_EMU, PEVB_MENU },
// { BTN_Y, IN_BINDTYPE_EMU, PEVB_SWITCH_RND },
{ BTN_L, IN_BINDTYPE_EMU, PEVB_STATE_SAVE },
{ BTN_R, IN_BINDTYPE_EMU, PEVB_STATE_LOAD },
{ BTN_VOL_UP, IN_BINDTYPE_EMU, PEVB_VOL_UP },
{ BTN_VOL_DOWN, IN_BINDTYPE_EMU, PEVB_VOL_DOWN },
{ 0, 0, 0 },
};
#endif
/* remove binds of missing keys, count remaining ones */
static int in_gp2x_clean_binds(void *drv_data, int *binds, int *def_binds)
{
int i, count = 0;
// int eb, have_vol = 0, have_menu = 0;
for (i = 0; i < IN_GP2X_NBUTTONS; i++) {
int t, offs;
for (t = 0; t < IN_BINDTYPE_COUNT; t++) {
offs = IN_BIND_OFFS(i, t);
if (in_gp2x_keys[i] == NULL)
binds[offs] = def_binds[offs] = 0;
if (binds[offs])
count++;
}
#if 0
eb = binds[IN_BIND_OFFS(i, IN_BINDTYPE_EMU)];
if (eb & (PEV_VOL_DOWN|PEV_VOL_UP))
have_vol = 1;
if (eb & PEV_MENU)
have_menu = 1;
#endif
}
// TODO: move to pico
#if 0
/* autobind some important keys, if they are unbound */
if (!have_vol && binds[GP2X_BTN_VOL_UP] == 0 && binds[GP2X_BTN_VOL_DOWN] == 0) {
binds[IN_BIND_OFFS(GP2X_BTN_VOL_UP, IN_BINDTYPE_EMU)] = PEV_VOL_UP;
binds[IN_BIND_OFFS(GP2X_BTN_VOL_DOWN, IN_BINDTYPE_EMU)] = PEV_VOL_DOWN;
count += 2;
}
if (!have_menu) {
binds[IN_BIND_OFFS(GP2X_BTN_SELECT, IN_BINDTYPE_EMU)] = PEV_MENU;
count++;
}
#endif
in_combos_find(binds, GP2X_BTN_PUSH, &in_gp2x_combo_keys, &in_gp2x_combo_acts);
return count;
}
static const in_drv_t in_gp2x_drv = {
.prefix = IN_GP2X_PREFIX,
.probe = in_gp2x_probe,
.free = in_gp2x_free,
.get_key_names = in_gp2x_get_key_names,
.clean_binds = in_gp2x_clean_binds,
.update = in_gp2x_update,
.update_keycode = in_gp2x_update_keycode,
.menu_translate = in_gp2x_menu_translate,
};
void in_gp2x_init(const struct in_default_bind *defbinds)
{
if (gp2x_dev_id == GP2X_DEV_WIZ)
in_gp2x_keys[GP2X_BTN_START] = "MENU";
in_gp2x_combo_keys = in_gp2x_combo_acts = 0;
in_register_driver(&in_gp2x_drv, defbinds);
}

View file

@ -1,17 +0,0 @@
struct in_default_bind;
void in_gp2x_init(const struct in_default_bind *defbinds);
enum { GP2X_BTN_UP = 0, GP2X_BTN_LEFT = 2, GP2X_BTN_DOWN = 4, GP2X_BTN_RIGHT = 6,
GP2X_BTN_START = 8, GP2X_BTN_SELECT = 9, GP2X_BTN_L = 10, GP2X_BTN_R = 11,
GP2X_BTN_A = 12, GP2X_BTN_B = 13, GP2X_BTN_X = 14, GP2X_BTN_Y = 15,
GP2X_BTN_VOL_UP = 23, GP2X_BTN_VOL_DOWN = 22, GP2X_BTN_PUSH = 27 };
/* FIXME */
#ifndef GP2X_DEV_GP2X
extern int gp2x_dev_id;
#define GP2X_DEV_GP2X 1
#define GP2X_DEV_WIZ 2
#define GP2X_DEV_CAANOO 3
#endif

View file

@ -1,65 +1,7 @@
#include <time.h> #include "../libpicofe/gp2x/plat_gp2x.h"
#include "soc.h"
#include "plat_gp2x.h"
static void menu_main_plat_draw(void)
{
static time_t last_bat_read = 0;
static int last_bat_val = -1;
unsigned short *bp = g_screen_ptr;
int bat_h = me_mfont_h * 2 / 3;
int i, u, w, wfill, batt_val;
struct tm *tmp;
time_t ltime;
char time_s[16];
if (!(currentConfig.EmuOpt & EOPT_SHOW_RTC))
return;
ltime = time(NULL);
tmp = gmtime(&ltime);
strftime(time_s, sizeof(time_s), "%H:%M", tmp);
text_out16(g_screen_width - me_mfont_w * 6, me_mfont_h + 2, time_s);
if (ltime - last_bat_read > 10) {
last_bat_read = ltime;
last_bat_val = batt_val = gp2x_read_battery();
}
else
batt_val = last_bat_val;
if (batt_val < 0 || batt_val > 100)
return;
/* battery info */
bp += (me_mfont_h * 2 + 2) * g_screen_width + g_screen_width - me_mfont_w * 3 - 3;
for (i = 0; i < me_mfont_w * 2; i++)
bp[i] = menu_text_color;
for (i = 0; i < me_mfont_w * 2; i++)
bp[i + g_screen_width * bat_h] = menu_text_color;
for (i = 0; i <= bat_h; i++)
bp[i * g_screen_width] =
bp[i * g_screen_width + me_mfont_w * 2] = menu_text_color;
for (i = 2; i < bat_h - 1; i++)
bp[i * g_screen_width - 1] =
bp[i * g_screen_width - 2] = menu_text_color;
w = me_mfont_w * 2 - 1;
wfill = batt_val * w / 100;
for (u = 1; u < bat_h; u++)
for (i = 0; i < wfill; i++)
bp[(w - i) + g_screen_width * u] = menu_text_color;
}
// ------------ gfx options menu ------------ // ------------ gfx options menu ------------
static const char *mgn_aopt_gamma(int id, int *offs)
{
sprintf(static_buff, "%i.%02i", currentConfig.gamma / 100, currentConfig.gamma % 100);
return static_buff;
}
const char *men_scaling_opts[] = { "OFF", "software", "hardware", NULL }; const char *men_scaling_opts[] = { "OFF", "software", "hardware", NULL };
@ -67,16 +9,11 @@ const char *men_scaling_opts[] = { "OFF", "software", "hardware", NULL };
mee_enum ("Horizontal scaling", MA_OPT_SCALING, currentConfig.scaling, men_scaling_opts), \ mee_enum ("Horizontal scaling", MA_OPT_SCALING, currentConfig.scaling, men_scaling_opts), \
mee_enum ("Vertical scaling", MA_OPT_VSCALING, currentConfig.vscaling, men_scaling_opts), \ mee_enum ("Vertical scaling", MA_OPT_VSCALING, currentConfig.vscaling, men_scaling_opts), \
mee_onoff ("Tearing Fix", MA_OPT_TEARING_FIX, currentConfig.EmuOpt, EOPT_WIZ_TEAR_FIX), \ mee_onoff ("Tearing Fix", MA_OPT_TEARING_FIX, currentConfig.EmuOpt, EOPT_WIZ_TEAR_FIX), \
mee_range_cust("Gamma correction", MA_OPT2_GAMMA, currentConfig.gamma, 1, 300, mgn_aopt_gamma), \ /*mee_onoff ("A_SN's gamma curve", MA_OPT2_A_SN_GAMMA, currentConfig.EmuOpt, EOPT_A_SN_GAMMA),*/ \
mee_onoff ("A_SN's gamma curve", MA_OPT2_A_SN_GAMMA, currentConfig.EmuOpt, EOPT_A_SN_GAMMA), \
mee_onoff ("Vsync", MA_OPT2_VSYNC, currentConfig.EmuOpt, EOPT_VSYNC), mee_onoff ("Vsync", MA_OPT2_VSYNC, currentConfig.EmuOpt, EOPT_VSYNC),
#define MENU_OPTIONS_ADV \ #define MENU_OPTIONS_ADV \
mee_onoff ("Use second CPU for sound", MA_OPT_ARM940_SOUND, PicoOpt, POPT_EXT_FM), \ mee_onoff ("Use second CPU for sound", MA_OPT_ARM940_SOUND, PicoOpt, POPT_EXT_FM), \
mee_onoff ("RAM overclock", MA_OPT2_RAMTIMINGS, currentConfig.EmuOpt, EOPT_RAM_TIMINGS), \
mee_onoff ("MMU hack", MA_OPT2_SQUIDGEHACK, currentConfig.EmuOpt, EOPT_MMUHACK), \
mee_onoff ("SVP dynarec", MA_OPT2_SVP_DYNAREC, PicoOpt, POPT_EN_SVP_DRC), \
mee_onoff ("Status line in main menu", MA_OPT2_STATUS_LINE, currentConfig.EmuOpt, EOPT_SHOW_RTC),
static menu_entry e_menu_adv_options[]; static menu_entry e_menu_adv_options[];
@ -86,12 +23,6 @@ static menu_entry e_menu_keyconfig[];
void gp2x_menu_init(void) void gp2x_menu_init(void)
{ {
static menu_entry *cpu_clk_ent;
int i;
i = me_id2offset(e_menu_options, MA_OPT_CPU_CLOCKS);
cpu_clk_ent = &e_menu_options[i];
/* disable by default.. */ /* disable by default.. */
me_enable(e_menu_adv_options, MA_OPT_ARM940_SOUND, 0); me_enable(e_menu_adv_options, MA_OPT_ARM940_SOUND, 0);
me_enable(e_menu_gfx_options, MA_OPT_TEARING_FIX, 0); me_enable(e_menu_gfx_options, MA_OPT_TEARING_FIX, 0);
@ -103,22 +34,16 @@ void gp2x_menu_init(void)
me_enable(e_menu_adv_options, MA_OPT_ARM940_SOUND, 1); me_enable(e_menu_adv_options, MA_OPT_ARM940_SOUND, 1);
me_enable(e_menu_gfx_options, MA_OPT2_GAMMA, 1); me_enable(e_menu_gfx_options, MA_OPT2_GAMMA, 1);
me_enable(e_menu_gfx_options, MA_OPT2_A_SN_GAMMA, 1); me_enable(e_menu_gfx_options, MA_OPT2_A_SN_GAMMA, 1);
cpu_clk_ent->name = "GP2X CPU clocks";
break; break;
case GP2X_DEV_WIZ: case GP2X_DEV_WIZ:
me_enable(e_menu_gfx_options, MA_OPT_TEARING_FIX, 1); me_enable(e_menu_gfx_options, MA_OPT_TEARING_FIX, 1);
cpu_clk_ent->name = "Wiz/Caanoo CPU clock";
break; break;
case GP2X_DEV_CAANOO: case GP2X_DEV_CAANOO:
cpu_clk_ent->name = "Wiz/Caanoo CPU clock";
break; break;
default: default:
break; break;
} }
if (gp2x_set_cpuclk == NULL)
cpu_clk_ent->name = "";
if (gp2x_dev_id != GP2X_DEV_GP2X) if (gp2x_dev_id != GP2X_DEV_GP2X)
men_scaling_opts[2] = NULL; /* leave only off and sw */ men_scaling_opts[2] = NULL; /* leave only off and sw */

View file

@ -1,69 +1,76 @@
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include <linux/input.h>
#include "plat_gp2x.h"
#include "soc.h"
#include "warm.h"
#include "../common/plat.h"
#include "../common/readpng.h"
#include "../common/menu.h"
#include "../common/emu.h" #include "../common/emu.h"
#include "../common/input.h" #include "../common/menu_pico.h"
#include "../linux/sndout_oss.h" #include "../common/input_pico.h"
#include "../libpicofe/input.h"
#include "../libpicofe/plat.h"
#include "../libpicofe/linux/in_evdev.h"
#include "../libpicofe/gp2x/soc.h"
#include "../libpicofe/gp2x/plat_gp2x.h"
#include "../libpicofe/gp2x/in_gp2x.h"
#include "940ctl.h"
#include "warm.h"
#include "plat.h"
#include <pico/pico.h> #include <pico/pico.h>
/* GP2X local */ /* GP2X local */
int default_cpu_clock;
int gp2x_dev_id;
int gp2x_current_bpp; int gp2x_current_bpp;
void *gp2x_screens[4]; void *gp2x_screens[4];
#include <linux/input.h> 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);
static const char * const caanoo_keys[KEY_MAX + 1] = { static struct in_default_bind in_evdev_defbinds[] =
[0 ... KEY_MAX] = NULL,
[KEY_UP] = "Up",
[KEY_LEFT] = "Left",
[KEY_RIGHT] = "Right",
[KEY_DOWN] = "Down",
[BTN_TRIGGER] = "A",
[BTN_THUMB] = "X",
[BTN_THUMB2] = "B",
[BTN_TOP] = "Y",
[BTN_TOP2] = "L",
[BTN_PINKIE] = "R",
[BTN_BASE] = "Home",
[BTN_BASE2] = "Lock",
[BTN_BASE3] = "I",
[BTN_BASE4] = "II",
[BTN_BASE5] = "Push",
};
struct in_default_bind in_evdev_defbinds[] =
{ {
/* MXYZ SACB RLDU */ /* MXYZ SACB RLDU */
{ KEY_UP, IN_BINDTYPE_PLAYER12, 0 }, { KEY_UP, IN_BINDTYPE_PLAYER12, GBTN_UP },
{ KEY_DOWN, IN_BINDTYPE_PLAYER12, 1 }, { KEY_DOWN, IN_BINDTYPE_PLAYER12, GBTN_DOWN },
{ KEY_LEFT, IN_BINDTYPE_PLAYER12, 2 }, { KEY_LEFT, IN_BINDTYPE_PLAYER12, GBTN_LEFT },
{ KEY_RIGHT, IN_BINDTYPE_PLAYER12, 3 }, { KEY_RIGHT, IN_BINDTYPE_PLAYER12, GBTN_RIGHT },
{ KEY_S, IN_BINDTYPE_PLAYER12, 4 }, /* B */ { KEY_A, IN_BINDTYPE_PLAYER12, GBTN_A },
{ KEY_D, IN_BINDTYPE_PLAYER12, 5 }, /* C */ { KEY_S, IN_BINDTYPE_PLAYER12, GBTN_B },
{ KEY_A, IN_BINDTYPE_PLAYER12, 6 }, /* A */ { KEY_D, IN_BINDTYPE_PLAYER12, GBTN_C },
{ KEY_ENTER, IN_BINDTYPE_PLAYER12, 7 }, { KEY_ENTER, IN_BINDTYPE_PLAYER12, GBTN_START },
{ KEY_BACKSLASH, IN_BINDTYPE_EMU, PEVB_MENU }, { KEY_BACKSLASH, IN_BINDTYPE_EMU, PEVB_MENU },
/* Caanoo */ /* Caanoo */
{ BTN_THUMB, IN_BINDTYPE_PLAYER12, 4 }, /* B */ { BTN_TRIGGER, IN_BINDTYPE_PLAYER12, GBTN_A },
{ BTN_THUMB2, IN_BINDTYPE_PLAYER12, 5 }, /* C */ { BTN_THUMB, IN_BINDTYPE_PLAYER12, GBTN_B },
{ BTN_TRIGGER, IN_BINDTYPE_PLAYER12, 6 }, /* A */ { BTN_THUMB2, IN_BINDTYPE_PLAYER12, GBTN_C },
{ BTN_BASE3, IN_BINDTYPE_PLAYER12, 7 }, { BTN_BASE3, IN_BINDTYPE_PLAYER12, GBTN_START },
{ BTN_TOP2, IN_BINDTYPE_EMU, PEVB_STATE_SAVE }, { BTN_TOP2, IN_BINDTYPE_EMU, PEVB_STATE_SAVE },
{ BTN_PINKIE, IN_BINDTYPE_EMU, PEVB_STATE_LOAD }, { BTN_PINKIE, IN_BINDTYPE_EMU, PEVB_STATE_LOAD },
{ BTN_BASE, IN_BINDTYPE_EMU, PEVB_MENU }, { BTN_BASE, IN_BINDTYPE_EMU, PEVB_MENU },
{ 0, 0, 0 } { 0, 0, 0 }
}; };
static struct in_default_bind in_gp2x_defbinds[] =
{
{ GP2X_BTN_UP, IN_BINDTYPE_PLAYER12, GBTN_UP },
{ GP2X_BTN_DOWN, IN_BINDTYPE_PLAYER12, GBTN_DOWN },
{ GP2X_BTN_LEFT, IN_BINDTYPE_PLAYER12, GBTN_LEFT },
{ GP2X_BTN_RIGHT, IN_BINDTYPE_PLAYER12, GBTN_RIGHT },
{ GP2X_BTN_A, IN_BINDTYPE_PLAYER12, GBTN_A },
{ GP2X_BTN_X, IN_BINDTYPE_PLAYER12, GBTN_B },
{ GP2X_BTN_B, IN_BINDTYPE_PLAYER12, GBTN_C },
{ GP2X_BTN_START, IN_BINDTYPE_PLAYER12, GBTN_START },
{ GP2X_BTN_Y, IN_BINDTYPE_EMU, PEVB_SWITCH_RND },
{ GP2X_BTN_L, IN_BINDTYPE_EMU, PEVB_STATE_SAVE },
{ GP2X_BTN_R, IN_BINDTYPE_EMU, PEVB_STATE_LOAD },
{ GP2X_BTN_VOL_DOWN, IN_BINDTYPE_EMU, PEVB_VOL_DOWN },
{ GP2X_BTN_VOL_UP, IN_BINDTYPE_EMU, PEVB_VOL_UP },
{ GP2X_BTN_SELECT, IN_BINDTYPE_EMU, PEVB_MENU },
{ 0, 0, 0 }
};
void gp2x_video_changemode(int bpp) void gp2x_video_changemode(int bpp)
{ {
gp2x_video_changemode_ll(bpp); gp2x_video_changemode_ll(bpp);
@ -126,6 +133,7 @@ void plat_video_menu_enter(int is_rom_loaded)
// switch to 16bpp // switch to 16bpp
gp2x_video_changemode_ll(16); gp2x_video_changemode_ll(16);
gp2x_video_RGB_setscaling(0, 320, 240); gp2x_video_RGB_setscaling(0, 320, 240);
printf("menu_enter\n");
} }
void plat_video_menu_begin(void) void plat_video_menu_begin(void)
@ -138,36 +146,12 @@ void plat_video_menu_end(void)
gp2x_video_flip2(); gp2x_video_flip2();
} }
void plat_video_menu_leave(void)
{
}
void plat_early_init(void) void plat_early_init(void)
{ {
gp2x_soc_t soc;
FILE *f;
soc = soc_detect();
switch (soc)
{
case SOCID_MMSP2:
default_cpu_clock = 200;
gp2x_dev_id = GP2X_DEV_GP2X;
break;
case SOCID_POLLUX:
default_cpu_clock = 533;
f = fopen("/dev/accel", "rb");
if (f) {
printf("detected Caanoo\n");
gp2x_dev_id = GP2X_DEV_CAANOO;
fclose(f);
}
else {
printf("detected Wiz\n");
gp2x_dev_id = GP2X_DEV_WIZ;
}
break;
default:
printf("could not recognize SoC, running in dummy mode.\n");
break;
}
// just use gettimeofday until plat_init() // just use gettimeofday until plat_init()
gp2x_get_ticks_ms = plat_get_ticks_ms_good; gp2x_get_ticks_ms = plat_get_ticks_ms_good;
gp2x_get_ticks_us = plat_get_ticks_us_good; gp2x_get_ticks_us = plat_get_ticks_us_good;
@ -175,55 +159,49 @@ void plat_early_init(void)
void plat_init(void) void plat_init(void)
{ {
gp2x_soc_t soc; warm_init();
soc = soc_detect(); switch (gp2x_dev_id) {
switch (soc) case GP2X_DEV_GP2X:
{ sharedmem940_init();
case SOCID_MMSP2: vid_mmsp2_init();
mmsp2_init();
break; break;
case SOCID_POLLUX: case GP2X_DEV_WIZ:
pollux_init(); case GP2X_DEV_CAANOO:
break; vid_pollux_init();
default:
dummy_init();
break; break;
} }
warm_init(); g_menuscreen_w = 320;
g_menuscreen_h = 240;
gp2x_memset_all_buffers(0, 0, 320*240*2); gp2x_memset_all_buffers(0, 0, 320*240*2);
gp2x_make_fb_bufferable(1);
// use buffer2 for menubg to save mem (using only buffers 0, 1 in menu) // use buffer2 for menubg to save mem (using only buffers 0, 1 in menu)
g_menubg_ptr = gp2x_screens[2]; g_menubg_ptr = gp2x_screens[2];
if (gp2x_dev_id == GP2X_DEV_CAANOO)
in_set_config(in_name_to_id("evdev:pollux-analog"), IN_CFG_KEY_NAMES,
caanoo_keys, sizeof(caanoo_keys));
flip_after_sync = 1; flip_after_sync = 1;
gp2x_menu_init(); gp2x_menu_init();
in_evdev_init(in_evdev_defbinds);
in_gp2x_init(in_gp2x_defbinds);
in_probe();
plat_target_setup_input();
} }
void plat_finish(void) void plat_finish(void)
{ {
gp2x_soc_t soc;
warm_finish(); warm_finish();
soc = soc_detect(); switch (gp2x_dev_id) {
switch (soc) case GP2X_DEV_GP2X:
{ sharedmem940_finish();
case SOCID_MMSP2: vid_mmsp2_finish();
mmsp2_finish();
break; break;
case SOCID_POLLUX: case GP2X_DEV_WIZ:
pollux_finish(); case GP2X_DEV_CAANOO:
break; vid_pollux_finish();
default:
dummy_finish();
break; break;
} }
} }

25
platform/gp2x/plat.h Normal file
View file

@ -0,0 +1,25 @@
extern void *gp2x_screens[4];
extern int gp2x_current_bpp;
/* SoC specific functions */
extern void (*gp2x_video_flip)(void);
extern void (*gp2x_video_flip2)(void);
/* negative bpp means rotated mode (for Wiz) */
extern void (*gp2x_video_changemode_ll)(int bpp);
extern void (*gp2x_video_setpalette)(int *pal, int len);
extern void (*gp2x_video_RGB_setscaling)(int ln_offs, int W, int H);
extern void (*gp2x_video_wait_vsync)(void);
/* ??? */
void gp2x_video_changemode(int bpp);
void gp2x_memcpy_all_buffers(void *data, int offset, int len);
void gp2x_memset_all_buffers(int offset, int byte, int len);
/* vid_*.c */
void vid_mmsp2_init(void);
void vid_mmsp2_finish(void);
void vid_pollux_init();
void vid_pollux_finish();
void gp2x_menu_init(void);

View file

@ -1,29 +0,0 @@
#ifndef __GP2X_H__
#define __GP2X_H__
extern int default_cpu_clock;
/* video */
void gp2x_video_changemode(int bpp);
void gp2x_memcpy_all_buffers(void *data, int offset, int len);
void gp2x_memset_all_buffers(int offset, int byte, int len);
void gp2x_make_fb_bufferable(int yes);
/* input */
int gp2x_touchpad_read(int *x, int *y);
/* misc */
enum {
GP2X_DEV_GP2X = 1,
GP2X_DEV_WIZ,
GP2X_DEV_CAANOO,
};
extern int gp2x_dev_id;
extern int gp2x_current_bpp;
unsigned int plat_get_ticks_ms_good(void);
unsigned int plat_get_ticks_us_good(void);
void gp2x_menu_init(void);
#endif

View file

@ -1,388 +0,0 @@
/*
* quick tool to set various timings for Wiz
*
* Copyright (c) Gražvydas "notaz" Ignotas, 2009
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* * Neither the name of the organization nor the
* names of its contributors may be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* HTOTAL: X VTOTAL: 341
* HSWIDTH: 1 VSWIDTH: 0
* HASTART: 37 VASTART: 17
* HAEND: 277 VAEND: 337
*
* 120Hz
* pcd 8, 447: + 594us
* pcd 9, 397: + 36us
* pcd 10, 357: - 523us
* pcd 11, 325: +1153us
*
* 'lcd_timings=397,1,37,277,341,0,17,337;dpc_clkdiv0=9'
* 'ram_timings=2,9,4,1,1,1,1'
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "pollux_set.h"
/* parse stuff */
static int parse_lcd_timings(const char *str, void *data)
{
int *lcd_timings = data;
const char *p = str;
int ret, c;
ret = sscanf(str, "%d,%d,%d,%d,%d,%d,%d,%d",
&lcd_timings[0], &lcd_timings[1], &lcd_timings[2], &lcd_timings[3],
&lcd_timings[4], &lcd_timings[5], &lcd_timings[6], &lcd_timings[7]);
if (ret != 8)
return -1;
/* skip seven commas */
for (c = 0; c < 7 && *p != 0; p++)
if (*p == ',')
c++;
if (c != 7)
return -1;
/* skip last number */
while ('0' <= *p && *p <= '9')
p++;
return p - str;
}
static int parse_ram_timings(const char *str, void *data)
{
int *ram_timings = data;
const char *p = str;
int ret, c;
float cas;
ret = sscanf(p, "%f,%d,%d,%d,%d,%d,%d",
&cas, &ram_timings[1], &ram_timings[2], &ram_timings[3],
&ram_timings[4], &ram_timings[5], &ram_timings[6]);
if (ret != 7)
return -1;
if (cas == 2)
ram_timings[0] = 1;
else if (cas == 2.5)
ram_timings[0] = 2;
else if (cas == 3)
ram_timings[0] = 3;
else
return -1;
for (c = 0; c < 6 && *p != 0; p++)
if (*p == ',')
c++;
if (c != 6)
return -1;
while ('0' <= *p && *p <= '9')
p++;
return p - str;
}
static int parse_decimal(const char *str, void *data)
{
char *ep;
*(int *)data = strtoul(str, &ep, 10);
if (ep == str)
return -1;
return ep - str;
}
/* validate and apply stuff */
static int apply_lcd_timings(volatile unsigned short *memregs, void *data)
{
int *lcd_timings = data;
int i;
for (i = 0; i < 8; i++) {
if (lcd_timings[i] & ~0xffff) {
fprintf(stderr, "pollux_set: invalid lcd timing %d: %d\n", i, lcd_timings[i]);
return -1;
}
}
for (i = 0; i < 8; i++)
memregs[(0x307c>>1) + i] = lcd_timings[i];
return 0;
}
static const struct {
signed char adj; /* how to adjust value passed by user */
signed short min; /* range of */
signed short max; /* allowed values (inclusive) */
}
ram_ranges[] = {
{ 0, 1, 3 }, /* cas (cl) */
{ -2, 0, 15 }, /* trc */
{ -2, 0, 15 }, /* tras */
{ 0, 0, 15 }, /* twr */
{ 0, 0, 15 }, /* tmrd */
{ 0, 0, 15 }, /* trp */
{ 0, 0, 15 }, /* trcd */
};
static int apply_ram_timings(volatile unsigned short *memregs, void *data)
{
int *ram_timings = data;
int i, val;
for (i = 0; i < 7; i++)
{
ram_timings[i] += ram_ranges[i].adj;
if (ram_timings[i] < ram_ranges[i].min || ram_timings[i] > ram_ranges[i].max) {
fprintf(stderr, "pollux_set: invalid RAM timing %d\n", i);
return -1;
}
}
val = memregs[0x14802>>1] & 0x0f00;
val |= (ram_timings[4] << 12) | (ram_timings[5] << 4) | ram_timings[6];
memregs[0x14802>>1] = val;
val = memregs[0x14804>>1] & 0x4000;
val |= (ram_timings[0] << 12) | (ram_timings[1] << 8) |
(ram_timings[2] << 4) | ram_timings[3];
val |= 0x8000;
memregs[0x14804>>1] = val;
for (i = 0; i < 0x100000 && (memregs[0x14804>>1] & 0x8000); i++)
;
return 0;
}
static int apply_dpc_clkdiv0(volatile unsigned short *memregs, void *data)
{
int pcd = *(int *)data;
int tmp;
if ((pcd - 1) & ~0x3f) {
fprintf(stderr, "pollux_set: invalid lcd clkdiv0: %d\n", pcd);
return -1;
}
pcd = (pcd - 1) & 0x3f;
tmp = memregs[0x31c4>>1];
memregs[0x31c4>>1] = (tmp & ~0x3f0) | (pcd << 4);
return 0;
}
static int apply_cpuclk(volatile unsigned short *memregs, void *data)
{
volatile unsigned int *memregl = (volatile void *)memregs;
int mhz = *(int *)data;
int adiv, mdiv, pdiv, sdiv = 0;
int i, vf000, vf004;
// m = MDIV, p = PDIV, s = SDIV
#define SYS_CLK_FREQ 27
pdiv = 9;
mdiv = (mhz * pdiv) / SYS_CLK_FREQ;
if (mdiv & ~0x3ff)
return -1;
vf004 = (pdiv<<18) | (mdiv<<8) | sdiv;
// attempt to keep AHB the divider close to 250, but not higher
for (adiv = 1; mhz / adiv > 250; adiv++)
;
vf000 = memregl[0xf000>>2];
vf000 = (vf000 & ~0x3c0) | ((adiv - 1) << 6);
memregl[0xf000>>2] = vf000;
memregl[0xf004>>2] = vf004;
memregl[0xf07c>>2] |= 0x8000;
for (i = 0; (memregl[0xf07c>>2] & 0x8000) && i < 0x100000; i++)
;
printf("clock set to %dMHz, AHB set to %dMHz\n", mhz, mhz / adiv);
return 0;
}
static int lcd_timings[8];
static int ram_timings[7];
static int dpc_clkdiv0;
static int cpuclk;
static const char lcd_t_help[] = "htotal,hswidth,hastart,haend,vtotal,vswidth,vastart,vaend";
static const char ram_t_help[] = "CAS,tRC,tRAS,tWR,tMRD,tRP,tRCD";
static const struct {
const char *name;
const char *help;
int (*parse)(const char *str, void *data);
int (*apply)(volatile unsigned short *memregs, void *data);
void *data;
}
all_params[] = {
{ "lcd_timings", lcd_t_help, parse_lcd_timings, apply_lcd_timings, lcd_timings },
{ "ram_timings", ram_t_help, parse_ram_timings, apply_ram_timings, ram_timings },
{ "dpc_clkdiv0", "divider", parse_decimal, apply_dpc_clkdiv0, &dpc_clkdiv0 },
{ "clkdiv0", "divider", parse_decimal, apply_dpc_clkdiv0, &dpc_clkdiv0 }, /* alias */
{ "cpuclk", "MHZ", parse_decimal, apply_cpuclk, &cpuclk },
};
#define ALL_PARAM_COUNT (sizeof(all_params) / sizeof(all_params[0]))
/*
* set timings based on preformated string
* returns 0 on success.
*/
int pollux_set(volatile unsigned short *memregs, const char *str)
{
int parsed_params[ALL_PARAM_COUNT];
int applied_params[ALL_PARAM_COUNT];
int applied_something = 0;
const char *p, *po;
int i, ret;
if (str == NULL)
return -1;
memset(parsed_params, 0, sizeof(parsed_params));
memset(applied_params, 0, sizeof(applied_params));
p = str;
while (1)
{
again:
while (*p == ';' || *p == ' ')
p++;
if (*p == 0)
break;
for (i = 0; i < ALL_PARAM_COUNT; i++)
{
int param_len = strlen(all_params[i].name);
if (strncmp(p, all_params[i].name, param_len) == 0 && p[param_len] == '=')
{
p += param_len + 1;
ret = all_params[i].parse(p, all_params[i].data);
if (ret < 0) {
fprintf(stderr, "pollux_set parser: error at %-10s\n", p);
fprintf(stderr, " valid format is: <%s>\n", all_params[i].help);
return -1;
}
parsed_params[i] = 1;
p += ret;
goto again;
}
}
/* Unknown param. Attempt to be forward compatible and ignore it. */
for (po = p; *p != 0 && *p != ';'; p++)
;
fprintf(stderr, "unhandled param: ");
fwrite(po, 1, p - po, stderr);
fprintf(stderr, "\n");
}
/* validate and apply */
for (i = 0; i < ALL_PARAM_COUNT; i++)
{
if (!parsed_params[i])
continue;
ret = all_params[i].apply(memregs, all_params[i].data);
if (ret < 0) {
fprintf(stderr, "pollux_set: failed to apply %s (bad value?)\n",
all_params[i].name);
continue;
}
applied_something = 1;
applied_params[i] = 1;
}
if (applied_something)
{
int c;
printf("applied: ");
for (i = c = 0; i < ALL_PARAM_COUNT; i++)
{
if (!applied_params[i])
continue;
if (c != 0)
printf(", ");
printf("%s", all_params[i].name);
c++;
}
printf("\n");
}
return 0;
}
#ifdef BINARY
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <sys/mman.h>
#include <unistd.h>
static void usage(const char *binary)
{
int i;
printf("usage:\n%s <set_str[;set_str[;...]]>\n"
"set_str:\n", binary);
for (i = 0; i < ALL_PARAM_COUNT; i++)
printf(" %s=<%s>\n", all_params[i].name, all_params[i].help);
}
int main(int argc, char *argv[])
{
volatile unsigned short *memregs;
int ret, memdev;
if (argc != 2) {
usage(argv[0]);
return 1;
}
memdev = open("/dev/mem", O_RDWR);
if (memdev == -1)
{
perror("open(/dev/mem) failed");
return 1;
}
memregs = mmap(0, 0x20000, PROT_READ|PROT_WRITE, MAP_SHARED, memdev, 0xc0000000);
if (memregs == MAP_FAILED)
{
perror("mmap(memregs) failed");
close(memdev);
return 1;
}
ret = pollux_set(memregs, argv[1]);
munmap((void *)memregs, 0x20000);
close(memdev);
return ret;
}
#endif

View file

@ -1,10 +0,0 @@
#ifdef __cplusplus
extern "C"
{
#endif
int pollux_set(volatile unsigned short *memregs, const char *str);
#ifdef __cplusplus
}
#endif

View file

@ -1,101 +0,0 @@
#include <stdio.h>
#include <string.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <sys/mman.h>
#include <unistd.h>
#include "soc.h"
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);
void (*gp2x_set_cpuclk)(unsigned int mhz);
void (*set_lcd_custom_rate)(int is_pal);
void (*unset_lcd_custom_rate)(void);
void (*set_lcd_gamma)(int g100, int A_SNs_curve);
void (*set_ram_timings)(void);
void (*unset_ram_timings)(void);
int (*gp2x_read_battery)(void);
unsigned int (*gp2x_get_ticks_ms)(void);
unsigned int (*gp2x_get_ticks_us)(void);
gp2x_soc_t soc_detect(void)
{
volatile unsigned short *memregs;
volatile unsigned int *memregl;
static gp2x_soc_t ret = -2;
int pollux_chipname[0x30/4 + 1];
char *pollux_chipname_c = (char *)pollux_chipname;
int memdev;
int i;
if ((int)ret != -2)
/* already detected */
return ret;
memdev = open("/dev/mem", O_RDONLY);
if (memdev == -1)
{
perror("open(/dev/mem)");
ret = -1;
return -1;
}
memregs = mmap(0, 0x20000, PROT_READ, MAP_SHARED, memdev, 0xc0000000);
if (memregs == MAP_FAILED)
{
perror("mmap(memregs)");
close(memdev);
ret = -1;
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);
return ret;
}

View file

@ -1,38 +0,0 @@
typedef enum {
SOCID_MMSP2 = 1,
SOCID_POLLUX,
} gp2x_soc_t;
gp2x_soc_t soc_detect(void);
void mmsp2_init(void);
void mmsp2_finish(void);
void pollux_init(void);
void pollux_finish(void);
void dummy_init(void);
void dummy_finish(void);
/* SoC specific functions */
extern void (*gp2x_video_flip)(void);
extern void (*gp2x_video_flip2)(void);
/* negative bpp means rotated mode (for Wiz) */
extern void (*gp2x_video_changemode_ll)(int bpp);
extern void (*gp2x_video_setpalette)(int *pal, int len);
extern void (*gp2x_video_RGB_setscaling)(int ln_offs, int W, int H);
extern void (*gp2x_video_wait_vsync)(void);
extern void (*gp2x_set_cpuclk)(unsigned int mhz);
extern void (*set_lcd_custom_rate)(int is_pal);
extern void (*unset_lcd_custom_rate)(void);
extern void (*set_lcd_gamma)(int g100, int A_SNs_curve);
extern void (*set_ram_timings)(void);
extern void (*unset_ram_timings)(void);
extern int (*gp2x_read_battery)(void);
/* gettimeofday is not suitable for Wiz, at least fw 1.1 or lower */
extern unsigned int (*gp2x_get_ticks_ms)(void);
extern unsigned int (*gp2x_get_ticks_us)(void);

View file

@ -1,95 +0,0 @@
/* dummy code for qemu testing, etc */
#include <stdlib.h>
#include "soc.h"
#include "../common/emu.h"
extern void *gp2x_screens[4];
extern unsigned int plat_get_ticks_ms_good(void);
extern unsigned int plat_get_ticks_us_good(void);
/* video stuff */
static void gp2x_video_flip_(void)
{
}
/* doulblebuffered flip */
static void gp2x_video_flip2_(void)
{
}
static void gp2x_video_changemode_ll_(int bpp)
{
}
static void gp2x_video_setpalette_(int *pal, int len)
{
}
static void gp2x_video_RGB_setscaling_(int ln_offs, int W, int H)
{
}
static void gp2x_video_wait_vsync_(void)
{
}
/* RAM timings */
static void set_ram_timings_(void)
{
}
static void unset_ram_timings_(void)
{
}
/* LCD refresh */
static void set_lcd_custom_rate_(int is_pal)
{
}
static void unset_lcd_custom_rate_(void)
{
}
static void set_lcd_gamma_(int g100, int A_SNs_curve)
{
}
static int gp2x_read_battery_(void)
{
return 0;
}
void dummy_init(void)
{
int i;
g_screen_ptr = malloc(320 * 240 * 2);
for (i = 0; i < array_size(gp2x_screens); i++)
gp2x_screens[i] = g_screen_ptr;
gp2x_video_flip = gp2x_video_flip_;
gp2x_video_flip2 = gp2x_video_flip2_;
gp2x_video_changemode_ll = gp2x_video_changemode_ll_;
gp2x_video_setpalette = gp2x_video_setpalette_;
gp2x_video_RGB_setscaling = gp2x_video_RGB_setscaling_;
gp2x_video_wait_vsync = gp2x_video_wait_vsync_;
set_lcd_custom_rate = set_lcd_custom_rate_;
unset_lcd_custom_rate = unset_lcd_custom_rate_;
set_lcd_gamma = set_lcd_gamma_;
set_ram_timings = set_ram_timings_;
unset_ram_timings = unset_ram_timings_;
gp2x_read_battery = gp2x_read_battery_;
gp2x_get_ticks_ms = plat_get_ticks_ms_good;
gp2x_get_ticks_us = plat_get_ticks_us_good;
}
void dummy_finish(void)
{
free(gp2x_screens[0]);
}

View file

@ -1,550 +0,0 @@
/*
* PicoDrive
* (C) notaz, 2006-2009
*
* This work is licensed under the terms of MAME license.
* See COPYING file in the top-level directory.
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <sys/mman.h>
#include <unistd.h>
#include "soc.h"
#include "soc_mmsp2.h"
#include "plat_gp2x.h"
#include "../common/emu.h"
#include "../common/plat.h"
#include "../common/arm_utils.h"
#include "940ctl.h"
volatile unsigned short *gp2x_memregs;
volatile unsigned long *gp2x_memregl;
extern void *gp2x_screens[4];
static int screensel = 0;
int memdev = -1; /* 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 char gamma_was_changed = 0;
static char cpuclk_was_changed = 0;
static unsigned short gp2x_screenaddr_old[4];
static unsigned short memtimex_old[2];
static unsigned short reg0910;
/* video stuff */
static 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 */
static 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];
}
static 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*/
}
static 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++;
}
static 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));
}
static 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);
}
/*
* CPU clock
* Fout = (m * Fin) / (p * 2^s)
* m = MDIV+8, p = PDIV+2, s = SDIV
*
* m = (Fout * p * 2^s) / Fin
*/
#define SYS_CLK_FREQ 7372800
static void gp2x_set_cpuclk_(unsigned int mhz)
{
unsigned int mdiv, pdiv, sdiv = 0;
unsigned int v;
int i;
pdiv = 3;
mdiv = (mhz * pdiv * 1000000) / SYS_CLK_FREQ;
if (mdiv & ~0xff) {
fprintf(stderr, "invalid cpuclk MHz: %u\n", mhz);
return;
}
v = ((mdiv-8)<<8) | ((pdiv-2)<<2) | sdiv;
gp2x_memregs[0x910>>1] = v;
for (i = 0; i < 10000; i++)
if (!(gp2x_memregs[0x902>>1] & 1))
break;
cpuclk_was_changed = 1;
}
/* RAM timings */
#define TIMING_CHECK(t, adj, mask) \
t += adj; \
if (t & ~mask) \
goto bad
static void set_ram_timing_vals(int tCAS, int tRC, int tRAS, int tWR, int tMRD, int tRFC, int tRP, int tRCD)
{
int i;
TIMING_CHECK(tCAS, -2, 0x1);
TIMING_CHECK(tRC, -1, 0xf);
TIMING_CHECK(tRAS, -1, 0xf);
TIMING_CHECK(tWR, -1, 0xf);
TIMING_CHECK(tMRD, -1, 0xf);
TIMING_CHECK(tRFC, -1, 0xf);
TIMING_CHECK(tRP, -1, 0xf);
TIMING_CHECK(tRCD, -1, 0xf);
/* get spend_cycles() into cache */
spend_cycles(1);
gp2x_memregs[0x3802>>1] = ((tMRD & 0xF) << 12) | ((tRFC & 0xF) << 8) | ((tRP & 0xF) << 4) | (tRCD & 0xF);
gp2x_memregs[0x3804>>1] = 0x8000 | ((tCAS & 1) << 12) | ((tRC & 0xF) << 8) | ((tRAS & 0xF) << 4) | (tWR & 0xF);
/* be sure we don't access the mem while it's being reprogrammed */
spend_cycles(128*1024);
for (i = 0; i < 8*1024; i++)
if (!(gp2x_memregs[0x3804>>1] & 0x8000))
break;
printf("RAM timings set.\n");
return;
bad:
fprintf(stderr, "RAM timings invalid.\n");
}
static void set_ram_timings_(void)
{
/* craigix: --cas 2 --trc 6 --tras 4 --twr 1 --tmrd 1 --trfc 1 --trp 2 --trcd 2 */
set_ram_timing_vals(2, 6, 4, 1, 1, 1, 2, 2);
}
static void unset_ram_timings_(void)
{
gp2x_memregs[0x3802>>1] = memtimex_old[0];
gp2x_memregs[0x3804>>1] = memtimex_old[1] | 0x8000;
printf("RAM timings reset to startup values.\n");
}
/* LCD refresh */
typedef struct
{
unsigned short reg, valmask, val;
}
reg_setting;
/* 120.00 97/0/2/7|25/ 7/ 7/11/37 */
static const reg_setting lcd_rate_120[] =
{
{ 0x0914, 0xffff, (97<<8)|(0<<2)|2 }, /* UPLLSETVREG */
{ 0x0924, 0xff00, (2<<14)|(7<<8) }, /* DISPCSETREG */
{ 0x281A, 0x00ff, 25 }, /* .HSWID(T2) */
{ 0x281C, 0x00ff, 7 }, /* .HSSTR(T8) */
{ 0x281E, 0x00ff, 7 }, /* .HSEND(T7) */
{ 0x2822, 0x01ff, 11 }, /* .VSEND (T9) */
{ 0x2826, 0x0ff0, 37<<4 }, /* .DESTR(T3) */
{ 0, 0, 0 }
};
/* 100.00 96/0/2/7|29/25/53/15/37 */
static const reg_setting lcd_rate_100[] =
{
{ 0x0914, 0xffff, (96<<8)|(0<<2)|2 }, /* UPLLSETVREG */
{ 0x0924, 0xff00, (2<<14)|(7<<8) }, /* DISPCSETREG */
{ 0x281A, 0x00ff, 29 }, /* .HSWID(T2) */
{ 0x281C, 0x00ff, 25 }, /* .HSSTR(T8) */
{ 0x281E, 0x00ff, 53 }, /* .HSEND(T7) */
{ 0x2822, 0x01ff, 15 }, /* .VSEND (T9) */
{ 0x2826, 0x0ff0, 37<<4 }, /* .DESTR(T3) */
{ 0, 0, 0 }
};
static reg_setting lcd_rate_defaults[] =
{
{ 0x0914, 0xffff, 0 },
{ 0x0924, 0xff00, 0 },
{ 0x281A, 0x00ff, 0 },
{ 0x281C, 0x00ff, 0 },
{ 0x281E, 0x00ff, 0 },
{ 0x2822, 0x01ff, 0 },
{ 0x2826, 0x0ff0, 0 },
{ 0, 0, 0 }
};
static void get_reg_setting(reg_setting *set)
{
for (; set->reg; set++)
{
unsigned short val = gp2x_memregs[set->reg >> 1];
val &= set->valmask;
set->val = val;
}
}
static void set_reg_setting(const reg_setting *set)
{
for (; set->reg; set++)
{
unsigned short val = gp2x_memregs[set->reg >> 1];
val &= ~set->valmask;
val |= set->val;
gp2x_memregs[set->reg >> 1] = val;
}
}
static void set_lcd_custom_rate_(int is_pal)
{
if (gp2x_memregs[0x2800>>1] & 0x100) // tv-out
return;
printf("setting custom LCD refresh (%d Hz)... ", is_pal ? 100 : 120);
fflush(stdout);
set_reg_setting(is_pal ? lcd_rate_100 : lcd_rate_120);
printf("done.\n");
}
static void unset_lcd_custom_rate_(void)
{
printf("reset to prev LCD refresh.\n");
set_reg_setting(lcd_rate_defaults);
}
static void set_lcd_gamma_(int g100, int A_SNs_curve)
{
float gamma = (float) g100 / 100;
int i;
gamma = 1 / gamma;
/* enable gamma */
gp2x_memregs[0x2880>>1] &= ~(1<<12);
gp2x_memregs[0x295C>>1] = 0;
for (i = 0; i < 256; i++)
{
unsigned char g;
unsigned short s;
const unsigned short grey50=143, grey75=177, grey25=97;
double blah;
if (A_SNs_curve)
{
// The next formula is all about gaussian interpolation
blah = (( -128 * exp(-powf((float) i/64.0f + 2.0f , 2.0f))) +
( -64 * exp(-powf((float) i/64.0f + 1.0f , 2.0f))) +
(grey25 * exp(-powf((float) i/64.0f - 1.0f , 2.0f))) +
(grey50 * exp(-powf((float) i/64.0f - 2.0f , 2.0f))) +
(grey75 * exp(-powf((float) i/64.0f - 3.0f , 2.0f))) +
( 256 * exp(-powf((float) i/64.0f - 4.0f , 2.0f))) +
( 320 * exp(-powf((float) i/64.0f - 5.0f , 2.0f))) +
( 384 * exp(-powf((float) i/64.0f - 6.0f , 2.0f)))) / 1.772637;
blah += 0.5;
}
else
{
blah = i;
}
g = (unsigned char)(255.0 * pow(blah/255.0, gamma));
//printf("%d : %d\n", i, g);
s = (g<<8) | g;
gp2x_memregs[0x295E>>1]= s;
gp2x_memregs[0x295E>>1]= g;
}
gamma_was_changed = 1;
}
static int gp2x_read_battery_(void)
{
return -1; /* TODO? */
}
/* 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));
/* save startup values: LCD refresh */
get_reg_setting(lcd_rate_defaults);
/* CPU and RAM timings */
reg0910 = gp2x_memregs[0x0910>>1];
memtimex_old[0] = gp2x_memregs[0x3802>>1];
memtimex_old[1] = gp2x_memregs[0x3804>>1];
/* 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");
/* code940 portion */
sharedmem940_init();
gp2x_video_flip = gp2x_video_flip_;
gp2x_video_flip2 = gp2x_video_flip2_;
gp2x_video_changemode_ll = gp2x_video_changemode_ll_;
gp2x_video_setpalette = gp2x_video_setpalette_;
gp2x_video_RGB_setscaling = gp2x_video_RGB_setscaling_;
gp2x_video_wait_vsync = gp2x_video_wait_vsync_;
gp2x_set_cpuclk = gp2x_set_cpuclk_;
set_lcd_custom_rate = set_lcd_custom_rate_;
unset_lcd_custom_rate = unset_lcd_custom_rate_;
set_lcd_gamma = set_lcd_gamma_;
set_ram_timings = set_ram_timings_;
unset_ram_timings = unset_ram_timings_;
gp2x_read_battery = gp2x_read_battery_;
gp2x_get_ticks_ms = plat_get_ticks_ms_good;
gp2x_get_ticks_us = plat_get_ticks_us_good;
}
void mmsp2_finish(void)
{
reset940(1, 3);
pause940(1);
sharedmem940_finish();
gp2x_video_RGB_setscaling_(0, 320, 240);
gp2x_video_changemode_ll_(16);
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];
unset_lcd_custom_rate_();
if (gamma_was_changed)
set_lcd_gamma_(100, 0);
unset_ram_timings_();
if (cpuclk_was_changed)
gp2x_memregs[0x910>>1] = reg0910;
munmap(gp2x_screens[0], FRAMEBUFF_WHOLESIZE);
munmap((void *)gp2x_memregs, 0x10000);
close(memdev);
if (touchdev >= 0)
close(touchdev);
}

View file

@ -1,9 +0,0 @@
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);

View file

@ -1,439 +0,0 @@
/*
* PicoDrive
* (C) notaz, 2009,2010
*
* This work is licensed under the terms of MAME license.
* See COPYING file in the top-level directory.
*/
/*
* <random_info=mem_map>
* 00000000-029fffff linux (42MB)
* 02a00000-02dfffff fb (4MB, 153600B really used)
* 02e00000-02ffffff sound dma (2MB)
* 03000000-03ffffff MPEGDEC (?, 16MB)
* </random_info>
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <sys/mman.h>
#include <unistd.h>
#include <sys/ioctl.h>
#include <linux/fb.h>
#include "soc.h"
#include "plat_gp2x.h"
#include "../common/emu.h"
#include "../common/plat.h"
#include "../common/arm_utils.h"
#include "pollux_set.h"
static volatile unsigned short *memregs;
static volatile unsigned int *memregl;
static int memdev = -1;
static int battdev = -1;
extern void *gp2x_screens[4];
#define fb_buf_count 4
static unsigned int fb_paddr[fb_buf_count];
static int fb_work_buf;
static int fbdev = -1;
static char cpuclk_was_changed = 0;
static unsigned short memtimex_old[2];
static unsigned int pllsetreg0_old;
static unsigned int timer_drift; // count per real second
static int last_pal_setting = 0;
/* misc */
static void pollux_set_fromenv(const char *env_var)
{
const char *set_string;
set_string = getenv(env_var);
if (set_string)
pollux_set(memregs, set_string);
else
printf("env var %s not defined.\n", env_var);
}
/* video stuff */
static void pollux_video_flip(int buf_count)
{
memregl[0x406C>>2] = fb_paddr[fb_work_buf];
memregl[0x4058>>2] |= 0x10;
fb_work_buf++;
if (fb_work_buf >= buf_count)
fb_work_buf = 0;
g_screen_ptr = gp2x_screens[fb_work_buf];
}
static void gp2x_video_flip_(void)
{
pollux_video_flip(fb_buf_count);
}
/* doulblebuffered flip */
static void gp2x_video_flip2_(void)
{
pollux_video_flip(2);
}
static void gp2x_video_changemode_ll_(int bpp)
{
static int prev_bpp = 0;
int code = 0, bytes = 2;
int rot_cmd[2] = { 0, 0 };
unsigned int r;
char buff[32];
int ret;
if (bpp == prev_bpp)
return;
prev_bpp = bpp;
printf("changemode: %dbpp rot=%d\n", abs(bpp), bpp < 0);
/* negative bpp means rotated mode */
rot_cmd[0] = (bpp < 0) ? 6 : 5;
ret = ioctl(fbdev, _IOW('D', 90, int[2]), rot_cmd);
if (ret < 0)
perror("rot ioctl failed");
memregl[0x4004>>2] = (bpp < 0) ? 0x013f00ef : 0x00ef013f;
memregl[0x4000>>2] |= 1 << 3;
/* the above ioctl resets LCD timings, so set them here */
snprintf(buff, sizeof(buff), "POLLUX_LCD_TIMINGS_%s", last_pal_setting ? "PAL" : "NTSC");
pollux_set_fromenv(buff);
switch (abs(bpp))
{
case 8:
code = 0x443a;
bytes = 1;
break;
case 15:
case 16:
code = 0x4432;
bytes = 2;
break;
default:
printf("unhandled bpp request: %d\n", abs(bpp));
return;
}
memregl[0x405c>>2] = bytes;
memregl[0x4060>>2] = bytes * (bpp < 0 ? 240 : 320);
r = memregl[0x4058>>2];
r = (r & 0xffff) | (code << 16) | 0x10;
memregl[0x4058>>2] = r;
}
static void gp2x_video_setpalette_(int *pal, int len)
{
/* pollux palette is 16bpp only.. */
int i;
for (i = 0; i < len; i++)
{
int c = pal[i];
c = ((c >> 8) & 0xf800) | ((c >> 5) & 0x07c0) | ((c >> 3) & 0x001f);
memregl[0x4070>>2] = (i << 24) | c;
}
}
static void gp2x_video_RGB_setscaling_(int ln_offs, int W, int H)
{
/* maybe a job for 3d hardware? */
}
static void gp2x_video_wait_vsync_(void)
{
while (!(memregl[0x308c>>2] & (1 << 10)))
spend_cycles(128);
memregl[0x308c>>2] |= 1 << 10;
}
/* CPU clock */
static void gp2x_set_cpuclk_(unsigned int mhz)
{
char buff[24];
snprintf(buff, sizeof(buff), "cpuclk=%u", mhz);
pollux_set(memregs, buff);
cpuclk_was_changed = 1;
}
/* RAM timings */
static void set_ram_timings_(void)
{
pollux_set_fromenv("POLLUX_RAM_TIMINGS");
}
static void unset_ram_timings_(void)
{
int i;
memregs[0x14802>>1] = memtimex_old[0];
memregs[0x14804>>1] = memtimex_old[1] | 0x8000;
for (i = 0; i < 0x100000; i++)
if (!(memregs[0x14804>>1] & 0x8000))
break;
printf("RAM timings reset to startup values.\n");
}
/* LCD refresh */
static void set_lcd_custom_rate_(int is_pal)
{
/* just remember PAL/NTSC. We always set timings in _changemode_ll() */
last_pal_setting = is_pal;
}
static void unset_lcd_custom_rate_(void)
{
}
static void set_lcd_gamma_(int g100, int A_SNs_curve)
{
/* hm, the LCD possibly can do it (but not POLLUX) */
}
static int gp2x_read_battery_(void)
{
unsigned short magic_val = 0;
if (battdev < 0)
return -1;
if (read(battdev, &magic_val, sizeof(magic_val)) != sizeof(magic_val))
return -1;
switch (magic_val) {
default:
case 1: return 100;
case 2: return 66;
case 3: return 40;
case 4: return 0;
}
}
#define TIMER_BASE3 0x1980
#define TIMER_REG(x) memregl[(TIMER_BASE3 + x) >> 2]
static unsigned int gp2x_get_ticks_us_(void)
{
TIMER_REG(0x08) = 0x4b; /* run timer, latch value */
return TIMER_REG(0);
}
static unsigned int gp2x_get_ticks_ms_(void)
{
/* approximate /= 1000 */
unsigned long long v64;
v64 = (unsigned long long)gp2x_get_ticks_us_() * 4294968;
return v64 >> 32;
}
static void timer_cleanup(void)
{
TIMER_REG(0x40) = 0x0c; /* be sure clocks are on */
TIMER_REG(0x08) = 0x23; /* stop the timer, clear irq in case it's pending */
TIMER_REG(0x00) = 0; /* clear counter */
TIMER_REG(0x40) = 0; /* clocks off */
TIMER_REG(0x44) = 0; /* dividers back to default */
}
/* note: both PLLs are programmed the same way,
* the databook incorrectly states that PLL1 differs */
static int decode_pll(unsigned int reg)
{
long long v;
int p, m, s;
p = (reg >> 18) & 0x3f;
m = (reg >> 8) & 0x3ff;
s = reg & 0xff;
if (p == 0)
p = 1;
v = 27000000; // master clock
v = v * m / (p << s);
return v;
}
int pollux_get_real_snd_rate(int req_rate)
{
int clk0_src, clk1_src, rate, div;
clk0_src = (memregl[0xdbc4>>2] >> 1) & 7;
clk1_src = (memregl[0xdbc8>>2] >> 1) & 7;
if (clk0_src > 1 || clk1_src != 7) {
fprintf(stderr, "get_real_snd_rate: bad clk sources: %d %d\n", clk0_src, clk1_src);
return req_rate;
}
rate = decode_pll(clk0_src ? memregl[0xf008>>2] : memregl[0xf004>>2]);
// apply divisors
div = ((memregl[0xdbc4>>2] >> 4) & 0x3f) + 1;
rate /= div;
div = ((memregl[0xdbc8>>2] >> 4) & 0x3f) + 1;
rate /= div;
rate /= 64;
//printf("rate %d\n", rate);
rate -= rate * timer_drift / 1000000;
printf("adjusted rate: %d\n", rate);
if (rate < 8000-1000 || rate > 44100+1000) {
fprintf(stderr, "get_real_snd_rate: got bad rate: %d\n", rate);
return req_rate;
}
return rate;
}
void pollux_init(void)
{
struct fb_fix_screeninfo fbfix;
int i, ret, rate, timer_div;
memdev = open("/dev/mem", O_RDWR);
if (memdev == -1) {
perror("open(/dev/mem) failed");
exit(1);
}
memregs = mmap(0, 0x20000, PROT_READ|PROT_WRITE, MAP_SHARED, memdev, 0xc0000000);
if (memregs == MAP_FAILED) {
perror("mmap(memregs) failed");
exit(1);
}
memregl = (volatile void *)memregs;
fbdev = open("/dev/fb0", O_RDWR);
if (fbdev < 0) {
perror("can't open fbdev");
exit(1);
}
ret = ioctl(fbdev, FBIOGET_FSCREENINFO, &fbfix);
if (ret == -1) {
perror("ioctl(fbdev) failed");
exit(1);
}
printf("framebuffer: \"%s\" @ %08lx\n", fbfix.id, fbfix.smem_start);
fb_paddr[0] = fbfix.smem_start;
gp2x_screens[0] = mmap(0, 320*240*2*fb_buf_count, PROT_READ|PROT_WRITE,
MAP_SHARED, memdev, fb_paddr[0]);
if (gp2x_screens[0] == MAP_FAILED)
{
perror("mmap(gp2x_screens) failed");
exit(1);
}
memset(gp2x_screens[0], 0, 320*240*2*fb_buf_count);
printf(" %p -> %08x\n", gp2x_screens[0], fb_paddr[0]);
for (i = 1; i < fb_buf_count; i++)
{
fb_paddr[i] = fb_paddr[i-1] + 320*240*2;
gp2x_screens[i] = (char *)gp2x_screens[i-1] + 320*240*2;
printf(" %p -> %08x\n", gp2x_screens[i], fb_paddr[i]);
}
fb_work_buf = 0;
g_screen_ptr = gp2x_screens[0];
battdev = open("/dev/pollux_batt", O_RDONLY);
if (battdev < 0)
perror("Warning: could't open pollux_batt");
/* find what PLL1 runs at, for the timer */
rate = decode_pll(memregl[0xf008>>2]);
printf("PLL1 @ %dHz\n", rate);
/* setup timer */
timer_div = (rate + 500000) / 1000000;
if (1 <= timer_div && timer_div <= 256) {
timer_drift = (rate - (timer_div * 1000000)) / timer_div;
if (TIMER_REG(0x08) & 8) {
fprintf(stderr, "warning: timer in use, overriding!\n");
timer_cleanup();
}
TIMER_REG(0x44) = ((timer_div - 1) << 4) | 2; /* using PLL1, divide by it's rate */
TIMER_REG(0x40) = 0x0c; /* clocks on */
TIMER_REG(0x08) = 0x6b; /* run timer, clear irq, latch value */
gp2x_get_ticks_ms = gp2x_get_ticks_ms_;
gp2x_get_ticks_us = gp2x_get_ticks_us_;
}
else {
fprintf(stderr, "warning: could not make use of timer\n");
// those functions are actually not good at all on Wiz kernel
gp2x_get_ticks_ms = plat_get_ticks_ms_good;
gp2x_get_ticks_us = plat_get_ticks_us_good;
}
pllsetreg0_old = memregl[0xf004>>2];
memtimex_old[0] = memregs[0x14802>>1];
memtimex_old[1] = memregs[0x14804>>1];
gp2x_video_flip = gp2x_video_flip_;
gp2x_video_flip2 = gp2x_video_flip2_;
gp2x_video_changemode_ll = gp2x_video_changemode_ll_;
gp2x_video_setpalette = gp2x_video_setpalette_;
gp2x_video_RGB_setscaling = gp2x_video_RGB_setscaling_;
gp2x_video_wait_vsync = gp2x_video_wait_vsync_;
/* some firmwares have sys clk on PLL0, we can't adjust CPU clock
* by reprogramming the PLL0 then, as it overclocks system bus */
if ((memregl[0xf000>>2] & 0x03000030) == 0x01000000)
gp2x_set_cpuclk = gp2x_set_cpuclk_;
else {
fprintf(stderr, "unexpected PLL config (%08x), overclocking disabled\n",
memregl[0xf000>>2]);
gp2x_set_cpuclk = NULL;
}
set_lcd_custom_rate = set_lcd_custom_rate_;
unset_lcd_custom_rate = unset_lcd_custom_rate_;
set_lcd_gamma = set_lcd_gamma_;
set_ram_timings = set_ram_timings_;
unset_ram_timings = unset_ram_timings_;
gp2x_read_battery = gp2x_read_battery_;
}
void pollux_finish(void)
{
/* switch to default fb mem, turn portrait off */
memregl[0x406C>>2] = fb_paddr[0];
memregl[0x4058>>2] |= 0x10;
close(fbdev);
gp2x_video_changemode_ll_(16);
unset_ram_timings_();
if (cpuclk_was_changed) {
memregl[0xf004>>2] = pllsetreg0_old;
memregl[0xf07c>>2] |= 0x8000;
}
timer_cleanup();
munmap((void *)memregs, 0x20000);
close(memdev);
if (battdev >= 0)
close(battdev);
}

View file

@ -1,2 +0,0 @@
int pollux_get_real_snd_rate(int req_rate);

174
platform/gp2x/vid_mmsp2.c Normal file
View file

@ -0,0 +1,174 @@
/*
* (C) Gražvydas "notaz" Ignotas, 2006-2009,2013
*
* This work is licensed under the terms of any of these licenses
* (at your option):
* - GNU GPL, version 2 or later.
* - GNU LGPL, version 2.1 or later.
* - MAME license.
* See the COPYING file in the top-level directory.
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <linux/fb.h>
#include <sys/mman.h>
#include "../libpicofe/gp2x/plat_gp2x.h"
#include "../libpicofe/gp2x/soc.h"
#include "../common/arm_utils.h"
#include "../common/emu.h"
#include "plat.h"
#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];
static int screensel;
static 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);
memregs[0x2910>>1] = msw;
memregs[0x2914>>1] = msw;
memregs[0x290E>>1] = lsw;
memregs[0x2912>>1] = lsw;
// jump to other buffer:
g_screen_ptr = gp2x_screens[++screensel&3];
}
/* doulblebuffered flip */
static void gp2x_video_flip2_(void)
{
unsigned short msw = (unsigned short)(gp2x_screenaddrs_use[screensel&1] >> 16);
memregs[0x2910>>1] = msw;
memregs[0x2914>>1] = msw;
memregs[0x290E>>1] = 0;
memregs[0x2912>>1] = 0;
// jump to other buffer:
g_screen_ptr = gp2x_screens[++screensel&1];
}
static void gp2x_video_changemode_ll_(int bpp)
{
printf("changemode %d\n", bpp);
memregs[0x28DA>>1] = (((bpp+1)/8)<<9)|0xAB; /*8/15/16/24bpp...*/
memregs[0x290C>>1] = 320*((bpp+1)/8); /*line width in bytes*/
}
static void gp2x_video_setpalette_(int *pal, int len)
{
unsigned short *g = (unsigned short *)pal;
volatile unsigned short *memreg = &memregs[0x295A>>1];
memregs[0x2958>>1] = 0;
len *= 2;
while (len--)
*memreg = *g++;
}
static void gp2x_video_RGB_setscaling_(int ln_offs, int W, int H)
{
float escalaw, escalah;
int bpp = (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 (memregs[0x2800>>1]&0x100) //TV-Out
{
escalaw=489.0; // RGB Horiz TV (PAL, NTSC)
if (memregs[0x2818>>1] == 287) //PAL
escalah=274.0; // RGB Vert TV PAL
else if (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--;
memregs[0x2906>>1]=scalw;
// scale vertical
memregl[0x2908>>2]=(unsigned long)((float)escalah *bpp *(H/240.0));
}
static void gp2x_video_wait_vsync_(void)
{
unsigned short v = memregs[0x1182>>1];
while (!((v ^ memregs[0x1182>>1]) & 0x10))
spend_cycles(1024);
}
void vid_mmsp2_init(void)
{
int i;
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] = memregs[0x290E>>1];
gp2x_screenaddr_old[1] = memregs[0x2910>>1];
gp2x_screenaddr_old[2] = memregs[0x2912>>1];
gp2x_screenaddr_old[3] = memregs[0x2914>>1];
memcpy(gp2x_screenaddrs_use, gp2x_screenaddrs, sizeof(gp2x_screenaddrs));
gp2x_video_flip = gp2x_video_flip_;
gp2x_video_flip2 = gp2x_video_flip2_;
gp2x_video_changemode_ll = gp2x_video_changemode_ll_;
gp2x_video_setpalette = gp2x_video_setpalette_;
gp2x_video_RGB_setscaling = gp2x_video_RGB_setscaling_;
gp2x_video_wait_vsync = gp2x_video_wait_vsync_;
}
void vid_mmsp2_finish(void)
{
gp2x_video_RGB_setscaling_(0, 320, 240);
gp2x_video_changemode_ll_(16);
memregs[0x290E>>1] = gp2x_screenaddr_old[0];
memregs[0x2910>>1] = gp2x_screenaddr_old[1];
memregs[0x2912>>1] = gp2x_screenaddr_old[2];
memregs[0x2914>>1] = gp2x_screenaddr_old[3];
munmap(gp2x_screens[0], FRAMEBUFF_WHOLESIZE);
}

232
platform/gp2x/vid_pollux.c Normal file
View file

@ -0,0 +1,232 @@
/*
* (C) Gražvydas "notaz" Ignotas, 2009,2013
*
* This work is licensed under the terms of any of these licenses
* (at your option):
* - GNU GPL, version 2 or later.
* - GNU LGPL, version 2.1 or later.
* - MAME license.
* See the COPYING file in the top-level directory.
*
* <random_info=mem_map>
* 00000000-029fffff linux (42MB)
* 02a00000-02dfffff fb (4MB, 153600B really used)
* 02e00000-02ffffff sound dma (2MB)
* 03000000-03ffffff MPEGDEC (?, 16MB)
* </random_info>
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <sys/ioctl.h>
#include <sys/mman.h>
#include <linux/fb.h>
#include <unistd.h>
#include "../libpicofe/gp2x/soc.h"
#include "../libpicofe/gp2x/plat_gp2x.h"
#include "../libpicofe/gp2x/pollux_set.h"
#include "../common/emu.h"
#include "../common/arm_utils.h"
#include "plat.h"
#define fb_buf_count 4
static unsigned int fb_paddr[fb_buf_count];
static int fb_work_buf;
static int fbdev = -1;
static unsigned short memtimex_old[2];
static int last_pal_setting = 0;
/* misc */
static void pollux_set_fromenv(const char *env_var)
{
const char *set_string;
set_string = getenv(env_var);
if (set_string)
pollux_set(memregs, set_string);
else
printf("env var %s not defined.\n", env_var);
}
/* video stuff */
static void pollux_video_flip(int buf_count)
{
memregl[0x406C>>2] = fb_paddr[fb_work_buf];
memregl[0x4058>>2] |= 0x10;
fb_work_buf++;
if (fb_work_buf >= buf_count)
fb_work_buf = 0;
g_screen_ptr = gp2x_screens[fb_work_buf];
}
static void gp2x_video_flip_(void)
{
pollux_video_flip(fb_buf_count);
}
/* doulblebuffered flip */
static void gp2x_video_flip2_(void)
{
pollux_video_flip(2);
}
static void gp2x_video_changemode_ll_(int bpp)
{
static int prev_bpp = 0;
int code = 0, bytes = 2;
int rot_cmd[2] = { 0, 0 };
unsigned int r;
char buff[32];
int ret;
if (bpp == prev_bpp)
return;
prev_bpp = bpp;
printf("changemode: %dbpp rot=%d\n", abs(bpp), bpp < 0);
/* negative bpp means rotated mode */
rot_cmd[0] = (bpp < 0) ? 6 : 5;
ret = ioctl(fbdev, _IOW('D', 90, int[2]), rot_cmd);
if (ret < 0)
perror("rot ioctl failed");
memregl[0x4004>>2] = (bpp < 0) ? 0x013f00ef : 0x00ef013f;
memregl[0x4000>>2] |= 1 << 3;
/* the above ioctl resets LCD timings, so set them here */
snprintf(buff, sizeof(buff), "POLLUX_LCD_TIMINGS_%s", last_pal_setting ? "PAL" : "NTSC");
pollux_set_fromenv(buff);
switch (abs(bpp))
{
case 8:
code = 0x443a;
bytes = 1;
break;
case 15:
case 16:
code = 0x4432;
bytes = 2;
break;
default:
printf("unhandled bpp request: %d\n", abs(bpp));
return;
}
memregl[0x405c>>2] = bytes;
memregl[0x4060>>2] = bytes * (bpp < 0 ? 240 : 320);
r = memregl[0x4058>>2];
r = (r & 0xffff) | (code << 16) | 0x10;
memregl[0x4058>>2] = r;
}
static void gp2x_video_setpalette_(int *pal, int len)
{
/* pollux palette is 16bpp only.. */
int i;
for (i = 0; i < len; i++)
{
int c = pal[i];
c = ((c >> 8) & 0xf800) | ((c >> 5) & 0x07c0) | ((c >> 3) & 0x001f);
memregl[0x4070>>2] = (i << 24) | c;
}
}
static void gp2x_video_RGB_setscaling_(int ln_offs, int W, int H)
{
/* maybe a job for 3d hardware? */
}
static void gp2x_video_wait_vsync_(void)
{
while (!(memregl[0x308c>>2] & (1 << 10)))
spend_cycles(128);
memregl[0x308c>>2] |= 1 << 10;
}
/* RAM timings */
static void set_ram_timings_(void)
{
pollux_set_fromenv("POLLUX_RAM_TIMINGS");
}
static void unset_ram_timings_(void)
{
int i;
memregs[0x14802>>1] = memtimex_old[0];
memregs[0x14804>>1] = memtimex_old[1] | 0x8000;
for (i = 0; i < 0x100000; i++)
if (!(memregs[0x14804>>1] & 0x8000))
break;
printf("RAM timings reset to startup values.\n");
}
void vid_pollux_init(void)
{
struct fb_fix_screeninfo fbfix;
int i, ret;
fbdev = open("/dev/fb0", O_RDWR);
if (fbdev < 0) {
perror("can't open fbdev");
exit(1);
}
ret = ioctl(fbdev, FBIOGET_FSCREENINFO, &fbfix);
if (ret == -1) {
perror("ioctl(fbdev) failed");
exit(1);
}
printf("framebuffer: \"%s\" @ %08lx\n", fbfix.id, fbfix.smem_start);
fb_paddr[0] = fbfix.smem_start;
gp2x_screens[0] = mmap(0, 320*240*2*fb_buf_count, PROT_READ|PROT_WRITE,
MAP_SHARED, memdev, fb_paddr[0]);
if (gp2x_screens[0] == MAP_FAILED)
{
perror("mmap(gp2x_screens) failed");
exit(1);
}
memset(gp2x_screens[0], 0, 320*240*2*fb_buf_count);
printf(" %p -> %08x\n", gp2x_screens[0], fb_paddr[0]);
for (i = 1; i < fb_buf_count; i++)
{
fb_paddr[i] = fb_paddr[i-1] + 320*240*2;
gp2x_screens[i] = (char *)gp2x_screens[i-1] + 320*240*2;
printf(" %p -> %08x\n", gp2x_screens[i], fb_paddr[i]);
}
fb_work_buf = 0;
g_screen_ptr = gp2x_screens[0];
set_ram_timings_();
gp2x_video_flip = gp2x_video_flip_;
gp2x_video_flip2 = gp2x_video_flip2_;
gp2x_video_changemode_ll = gp2x_video_changemode_ll_;
gp2x_video_setpalette = gp2x_video_setpalette_;
gp2x_video_RGB_setscaling = gp2x_video_RGB_setscaling_;
gp2x_video_wait_vsync = gp2x_video_wait_vsync_;
}
void vid_pollux_finish(void)
{
munmap(gp2x_screens[0], 320*240*2 * fb_buf_count);
close(fbdev);
fbdev = -1;
unset_ram_timings_();
}

@ -1 +1 @@
Subproject commit c54d04fd84f59c60c6ecdbd2502fbda5de735b4b Subproject commit 7ceadd9993ea84078e9d74d79215419e06496f90

View file

@ -67,11 +67,7 @@ static int menu_loop_cscaler(int id, int keys)
mee_range_hide("layer_w", MA_OPT3_LAYER_W, g_layer_cw, 160, 800), \ mee_range_hide("layer_w", MA_OPT3_LAYER_W, g_layer_cw, 160, 800), \
mee_range_hide("layer_h", MA_OPT3_LAYER_H, g_layer_ch, 60, 480), \ mee_range_hide("layer_h", MA_OPT3_LAYER_H, g_layer_ch, 60, 480), \
#define MENU_OPTIONS_ADV \ #define MENU_OPTIONS_ADV
mee_onoff ("SVP dynarec", MA_OPT2_SVP_DYNAREC, PicoOpt, POPT_EN_SVP_DRC), \
mee_onoff ("Status line in main menu", MA_OPT2_STATUS_LINE, currentConfig.EmuOpt, EOPT_SHOW_RTC),
#define menu_main_plat_draw NULL
static menu_entry e_menu_gfx_options[]; static menu_entry e_menu_gfx_options[];
static menu_entry e_menu_options[]; static menu_entry e_menu_options[];
@ -79,11 +75,6 @@ static menu_entry e_menu_keyconfig[];
void pnd_menu_init(void) void pnd_menu_init(void)
{ {
int i;
i = me_id2offset(e_menu_options, MA_OPT_CPU_CLOCKS);
e_menu_options[i].name = "Max CPU clock";
me_enable(e_menu_keyconfig, MA_CTRL_DEADZONE, 0); me_enable(e_menu_keyconfig, MA_CTRL_DEADZONE, 0);
} }