revive pandora and win32 builds, rm gp2x dep for linux, lots of refactoring

git-svn-id: file:///home/notaz/opt/svn/PicoDrive/platform@842 be3aeb3a-fb24-0410-a615-afba39da0efa
This commit is contained in:
notaz 2009-12-16 23:38:37 +00:00
parent a96477bb5e
commit d2f29611d1
24 changed files with 722 additions and 1039 deletions

View file

@ -16,14 +16,8 @@ ifndef ARCH
ARCH = x86
endif
ifeq "$(profile)" "1"
CFLAGS += -O3 -Wall
CFLAGS += -ftracer -fstrength-reduce -funroll-loops -fomit-frame-pointer -fstrict-aliasing -ffast-math
CFLAGS += -fprofile-generate
else
CFLAGS += -ggdb -Wall -falign-functions=2
endif
DEFINES = _UNZIP_SUPPORT IO_STATS IN_EVDEV
CFLAGS += -ggdb -Wall -falign-functions=2
CFLAGS += -I../.. -I.
LDFLAGS += -lm -lpng
ifeq "$(ARCH)" "arm"
@ -36,7 +30,7 @@ LDFLAGS += -lX11
CC = $(CROSS)gcc
# frontend
OBJS += platform/gp2x/emu.o blit.o in_evdev.o plat.o sndout_oss.o gp2x.o log_io.o
OBJS += io.o emu.o blit.o in_evdev.o plat.o sndout_oss.o log_io.o
# common
OBJS += platform/common/main.o platform/common/emu.o platform/common/menu.o \
@ -46,47 +40,34 @@ OBJS += platform/common/main.o platform/common/emu.o platform/common/menu.o \
ifeq "$(fake_in_gp2x)" "1"
DEFINES += IN_GP2X FAKE_IN_GP2X
OBJS += platform/gp2x/in_gp2x.o
DIRS += platform/gp2x
endif
# Pico
OBJS += pico/area.o pico/cart.o pico/memory.o pico/pico.o pico/sek.o \
pico/videoport.o pico/draw2.o pico/draw.o pico/z80if.o pico/patch.o \
pico/mode4.o pico/sms.o pico/misc.o pico/eeprom.o pico/debug.o
# Pico - CD
OBJS += pico/cd/pico.o pico/cd/memory.o pico/cd/sek.o pico/cd/LC89510.o \
pico/cd/cd_sys.o pico/cd/cd_file.o pico/cd/cue.o pico/cd/gfx_cd.o \
pico/cd/area.o pico/cd/misc.o pico/cd/pcm.o pico/cd/buffering.o
# Pico - 32X
OBJS += pico/32x/32x.o pico/32x/memory.o pico/32x/draw.o pico/32x/pwm.o
# Pico - Pico
OBJS += pico/pico/pico.o pico/pico/memory.o pico/pico/xpcm.o
# Pico - sound
OBJS += pico/sound/sound.o pico/sound/sn76496.o pico/sound/ym2612.o pico/sound/mix.o
# Pico - carthw
OBJS += pico/carthw/carthw.o pico/carthw/svp/svp.o pico/carthw/svp/memory.o \
pico/carthw/svp/ssp16.o pico/carthw/svp/compiler.o
ifeq "$(ARCH)" "arm"
OBJS += pico/carthw/svp/stub_arm.o
endif
OBJS += pico/sound/mix.o
OBJS += pico/carthw/svp/compiler.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 zlib/uncompr.o
# unzip
OBJS += unzip/unzip.o unzip/unzip_stream.o
CFLAGS += $(addprefix -D,$(DEFINES))
vpath %.c = ../..
vpath %.s = ../..
vpath %.S = ../..
vpath %.asm = ../..
DIRS = platform/linux platform/gp2x platform/common pico pico/cd pico/pico pico/sound pico/carthw/svp \
pico/32x zlib unzip cpu cpu/musashi cpu/fame cpu/mz80 cpu/cz80 cpu/sh2/mame cpu/drc
DIRS += platform/linux
all: mkdirs PicoDrive
include ../common/common.mak
include ../common/revision.mak
CFLAGS += $(addprefix -D,$(DEFINES))
clean: tidy
@$(RM) PicoDrive
@ -99,17 +80,6 @@ PicoDrive : $(OBJS)
@echo ">>>" $@
$(CC) $(CFLAGS) $^ $(LDFLAGS) -Wl,-Map=PicoDrive.map -o $@
mkdirs:
@mkdir -p $(DIRS)
include ../common/revision.mak
.c.o:
@echo ">>>" $<
$(CC) $(CFLAGS) -c $< -o $@
.s.o:
@echo ">>>" $<
$(CC) $(CFLAGS) -c $< -o $@
%.o : %.asm
@echo ">>>" $<
nasm -f elf $< -o $@

319
linux/emu.c Normal file
View file

@ -0,0 +1,319 @@
// (c) Copyright 2006-2009 notaz, All rights reserved.
// Free for non-commercial use.
// For commercial use, separate licencing terms must be obtained.
#include <stdio.h>
#include <unistd.h>
#include "../common/emu.h"
#include "../common/menu.h"
#include "../common/plat.h"
#include "../common/arm_utils.h"
#include "../linux/sndout_oss.h"
#include "version.h"
#include <pico/pico_int.h>
static short __attribute__((aligned(4))) sndBuffer[2*44100/50];
unsigned char temp_frame[320 * 240 * 2];
unsigned char *PicoDraw2FB = temp_frame;
static int osd_fps_x;
char cpu_clk_name[] = "unused";
extern void update_screen(void);
void pemu_prep_defconfig(void)
{
// XXX: move elsewhere
g_menubg_ptr = temp_frame;
}
void pemu_validate_config(void)
{
extern int PicoOpt;
// PicoOpt &= ~POPT_EXT_FM;
PicoOpt &= ~POPT_EN_SVP_DRC;
}
// FIXME: dupes from GP2X, need cleanup
static void (*osd_text)(int x, int y, const char *text);
static void osd_text8(int x, int y, const char *text)
{
int len = strlen(text)*8;
int *p, i, h, offs;
len = (len+3) >> 2;
for (h = 0; h < 8; h++) {
offs = (x + g_screen_width * (y+h)) & ~3;
p = (int *) ((char *)g_screen_ptr + offs);
for (i = len; i; i--, p++)
*p = 0xe0e0e0e0;
}
emu_text_out8(x, y, text);
}
static void osd_text16(int x, int y, const char *text)
{
int len = strlen(text)*8;
int *p, i, h, offs;
len = (len+1) >> 1;
for (h = 0; h < 8; h++) {
offs = (x + g_screen_width * (y+h)) & ~1;
p = (int *) ((short *)g_screen_ptr + offs);
for (i = len; i; i--, p++)
*p = (*p >> 2) & 0x39e7;
}
emu_text_out16(x, y, text);
}
static void draw_cd_leds(void)
{
int led_reg, pitch, scr_offs, led_offs;
led_reg = Pico_mcd->s68k_regs[0];
pitch = 320;
led_offs = 4;
scr_offs = pitch * 2 + 4;
if ((PicoOpt & POPT_ALT_RENDERER) || !(currentConfig.EmuOpt & EOPT_16BPP)) {
#define p(x) px[(x) >> 2]
// 8-bit modes
unsigned int *px = (unsigned int *)((char *)g_screen_ptr + scr_offs);
unsigned int col_g = (led_reg & 2) ? 0xc0c0c0c0 : 0xe0e0e0e0;
unsigned int col_r = (led_reg & 1) ? 0xd0d0d0d0 : 0xe0e0e0e0;
p(pitch*0) = p(pitch*1) = p(pitch*2) = col_g;
p(pitch*0 + led_offs) = p(pitch*1 + led_offs) = p(pitch*2 + led_offs) = col_r;
#undef p
} else {
#define p(x) px[(x)*2 >> 2] = px[((x)*2 >> 2) + 1]
// 16-bit modes
unsigned int *px = (unsigned int *)((short *)g_screen_ptr + scr_offs);
unsigned int col_g = (led_reg & 2) ? 0x06000600 : 0;
unsigned int col_r = (led_reg & 1) ? 0xc000c000 : 0;
p(pitch*0) = p(pitch*1) = p(pitch*2) = col_g;
p(pitch*0 + led_offs) = p(pitch*1 + led_offs) = p(pitch*2 + led_offs) = col_r;
#undef p
}
}
static int EmuScanBegin16(unsigned int num)
{
DrawLineDest = (unsigned short *)g_screen_ptr + num * g_screen_width;
return 0;
}
void pemu_update_display(const char *fps, const char *notice)
{
if (notice || (currentConfig.EmuOpt & EOPT_SHOW_FPS)) {
if (notice)
osd_text(4, g_screen_height - 8, notice);
if (currentConfig.EmuOpt & EOPT_SHOW_FPS)
osd_text(osd_fps_x, g_screen_height - 8, fps);
}
if ((PicoAHW & PAHW_MCD) && (currentConfig.EmuOpt & EOPT_EN_CD_LEDS))
draw_cd_leds();
update_screen();
}
void plat_video_toggle_renderer(int is_next, int force_16bpp, int is_menu)
{
// this will auto-select SMS/32X renderers
PicoDrawSetColorFormat(1);
}
void plat_video_menu_enter(int is_rom_loaded)
{
}
void plat_video_menu_begin(void)
{
memcpy32(g_screen_ptr, g_menubg_ptr, g_screen_width * g_screen_height * 2 / 4);
}
void plat_video_menu_end(void)
{
update_screen();
}
void plat_status_msg_clear(void)
{
unsigned short *d = (unsigned short *)g_screen_ptr + g_screen_width * g_screen_height;
int l = g_screen_width * 8;
memset32((int *)(d - l), 0, l * 2 / 4);
}
void plat_status_msg_busy_next(const char *msg)
{
plat_status_msg_clear();
pemu_update_display("", msg);
emu_status_msg("");
reset_timing = 1;
}
void plat_status_msg_busy_first(const char *msg)
{
// memset32(g_screen_ptr, 0, g_screen_width * g_screen_height * 2 / 4);
plat_status_msg_busy_next(msg);
}
void plat_update_volume(int has_changed, int is_up)
{
}
void pemu_forced_frame(int opts)
{
int po_old = PicoOpt;
int eo_old = currentConfig.EmuOpt;
PicoOpt &= ~POPT_ALT_RENDERER;
PicoOpt |= opts|POPT_ACC_SPRITES; // acc_sprites
currentConfig.EmuOpt |= EOPT_16BPP;
PicoDrawSetColorFormat(1);
PicoScanBegin = EmuScanBegin16;
Pico.m.dirtyPal = 1;
PicoFrameDrawOnly();
PicoOpt = po_old;
currentConfig.EmuOpt = eo_old;
}
static void updateSound(int len)
{
len <<= 1;
if (PicoOpt & POPT_EN_STEREO)
len <<= 1;
if ((currentConfig.EmuOpt & EOPT_NO_FRMLIMIT) && !sndout_oss_can_write(len))
return;
/* avoid writing audio when lagging behind to prevent audio lag */
if (PicoSkipFrame != 2)
sndout_oss_write(PsndOut, len);
}
void pemu_sound_start(void)
{
static int PsndRate_old = 0, PicoOpt_old = 0, pal_old = 0;
int target_fps = Pico.m.pal ? 50 : 60;
PsndOut = NULL;
if (currentConfig.EmuOpt & EOPT_EN_SOUND)
{
int snd_excess_add;
if (PsndRate != PsndRate_old || (PicoOpt&0x20b) != (PicoOpt_old&0x20b) || Pico.m.pal != pal_old)
PsndRerate(Pico.m.frame_count ? 1 : 0);
snd_excess_add = ((PsndRate - PsndLen*target_fps)<<16) / target_fps;
printf("starting audio: %i len: %i (ex: %04x) stereo: %i, pal: %i\n",
PsndRate, PsndLen, snd_excess_add, (PicoOpt&8)>>3, Pico.m.pal);
sndout_oss_start(PsndRate, 16, (PicoOpt&8)>>3);
sndout_oss_setvol(currentConfig.volume, currentConfig.volume);
PicoWriteSound = updateSound;
plat_update_volume(0, 0);
memset(sndBuffer, 0, sizeof(sndBuffer));
PsndOut = sndBuffer;
PsndRate_old = PsndRate;
PicoOpt_old = PicoOpt;
pal_old = Pico.m.pal;
}
}
void pemu_sound_stop(void)
{
}
void pemu_sound_wait(void)
{
// don't need to do anything, writes will block by themselves
}
void plat_debug_cat(char *str)
{
}
void emu_video_mode_change(int start_line, int line_count, int is_32cols)
{
osd_fps_x = 260;
// clear whole screen in all buffers
memset32(g_screen_ptr, 0, g_screen_width * g_screen_height * 2 / 4);
}
void pemu_loop_prep(void)
{
PicoDrawSetColorFormat(1);
PicoScanBegin = EmuScanBegin16;
osd_text = osd_text16;
pemu_sound_start();
}
void pemu_loop_end(void)
{
int po_old = PicoOpt;
int eo_old = currentConfig.EmuOpt;
pemu_sound_stop();
memset32(g_screen_ptr, 0, g_screen_width * g_screen_height * 2 / 4);
/* do one more frame for menu bg */
PicoOpt &= ~POPT_ALT_RENDERER;
PicoOpt |= POPT_EN_SOFTSCALE|POPT_ACC_SPRITES;
currentConfig.EmuOpt |= EOPT_16BPP;
PicoDrawSetColorFormat(1);
Pico.m.dirtyPal = 1;
PicoFrame();
PicoOpt = po_old;
currentConfig.EmuOpt = eo_old;
}
void plat_wait_till_us(unsigned int us_to)
{
unsigned int now;
now = plat_get_ticks_us();
while ((signed int)(us_to - now) > 512)
{
usleep(1024);
now = plat_get_ticks_us();
}
}
void plat_video_wait_vsync(void)
{
}
const char *plat_get_credits(void)
{
return "PicoDrive v" VERSION " (c) notaz, 2006-2009\n\n\n"
"Credits:\n"
"fDave: Cyclone 68000 core,\n"
" base code of PicoDrive\n"
"Reesy & FluBBa: DrZ80 core\n"
"MAME devs: YM2612 and SN76496 cores\n"
"rlyeh and others: minimal SDK\n"
"Squidge: mmuhack\n"
"Dzz: ARM940 sample\n"
"GnoStiC / Puck2099: USB joy code\n"
"craigix: GP2X hardware\n"
"ketchupgun: skin design\n"
"\n"
"special thanks (for docs, ideas):\n"
" Charles MacDonald, Haze,\n"
" Stephane Dallongeville,\n"
" Lordus, Exophase, Rokas,\n"
" Nemesis, Tasco Deluxe";
}

View file

@ -1,4 +1,3 @@
/* faking/emulating gp2x by using xlib */
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
@ -10,28 +9,19 @@
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <errno.h>
#include "../gp2x/version.h"
#include "../common/emu.h"
#include "../common/menu.h"
#include "../common/readpng.h"
#include "sndout_oss.h"
#include "version.h"
#include "log_io.h"
unsigned long current_keys = 0;
static int current_bpp = 8;
static int current_bpp = 16;
static int current_pal[256];
static const char *verstring = "PicoDrive " VERSION;
static int scr_changed = 0, scr_w = SCREEN_WIDTH, scr_h = SCREEN_HEIGHT;
void *gp2x_screens[4];
// dummies
int mix_32_to_16l_level;
int crashed_940 = 0;
int default_cpu_clock = 123;
void *gp2x_memregs = NULL;
/* ifndef is for qemu build without video out */
#ifndef ARM
@ -262,19 +252,14 @@ static void xlib_init(void)
static void realloc_screen(void)
{
void *old = g_screen_ptr;
int i;
g_screen_width = scr_w;
g_screen_height = scr_h;
g_screen_ptr = calloc(g_screen_width * g_screen_height * 2, 1);
free(old);
scr_changed = 0;
for (i = 0; i < 4; i++)
gp2x_screens[i] = g_screen_ptr;
}
/* gp2x/emu.c stuff, most to be rm'd */
static void gp2x_video_flip_(void)
void update_screen(void)
{
#ifndef ARM
unsigned int *image;
@ -319,86 +304,6 @@ static void gp2x_video_flip_(void)
#endif
}
static void gp2x_video_changemode_ll_(int bpp)
{
current_bpp = bpp;
}
static void gp2x_video_setpalette_(int *pal, int len)
{
memcpy(current_pal, pal, len*4);
}
void gp2x_memcpy_all_buffers(void *data, int offset, int len)
{
}
void gp2x_memset_all_buffers(int offset, int byte, int len)
{
memset((char *)g_screen_ptr + offset, byte, len);
}
void gp2x_video_changemode(int bpp)
{
gp2x_video_changemode_ll_(bpp);
}
void gp2x_make_fb_bufferable(int yes)
{
}
int soc_detect(void)
{
return 0;
}
/* plat */
static char menu_bg_buffer[320*240*2];
char cpu_clk_name[16] = "GP2X CPU clocks";
void plat_video_menu_enter(int is_rom_loaded)
{
if (is_rom_loaded)
{
// darken the active framebuffer
memset(g_screen_ptr, 0, 320*8*2);
menu_darken_bg((char *)g_screen_ptr + 320*8*2, 320*224, 1);
memset((char *)g_screen_ptr + 320*232*2, 0, 320*8*2);
}
else
{
char buff[256];
// should really only happen once, on startup..
emu_make_path(buff, "skin/background.png", sizeof(buff));
if (readpng(g_screen_ptr, buff, READPNG_BG) < 0)
memset(g_screen_ptr, 0, 320*240*2);
}
memcpy(menu_bg_buffer, g_screen_ptr, 320*240*2);
// switch to 16bpp
gp2x_video_changemode_ll_(16);
gp2x_video_flip_();
}
void plat_video_menu_begin(void)
{
memcpy(g_screen_ptr, menu_bg_buffer, 320*240*2);
}
void plat_video_menu_end(void)
{
gp2x_video_flip_();
}
void plat_validate_config(void)
{
extern int PicoOpt;
// PicoOpt &= ~POPT_EXT_FM;
PicoOpt &= ~(1<<17); // POPT_EN_SVP_DRC
}
void plat_early_init(void)
{
}
@ -422,38 +327,7 @@ void plat_finish(void)
sndout_oss_exit();
}
/* nasty */
static void do_nothing()
{
}
void *gp2x_video_flip = gp2x_video_flip_;
void *gp2x_video_flip2 = gp2x_video_flip_;
void *gp2x_video_changemode_ll = gp2x_video_changemode_ll_;
void *gp2x_video_setpalette = gp2x_video_setpalette_;
void *gp2x_video_RGB_setscaling = do_nothing;
void *gp2x_video_wait_vsync = do_nothing;
void *gp2x_set_cpuclk = do_nothing;
void *gp2x_read_battery = do_nothing;
void *set_lcd_custom_rate = do_nothing;
void *unset_lcd_custom_rate = do_nothing;
void *set_lcd_gamma = do_nothing;
void *set_ram_timings = do_nothing;
void *unset_ram_timings = do_nothing;
/* joy */
int gp2x_touchpad_read(int *x, int *y)
{
return -1;
}
/* misc */
void spend_cycles(int c)
{
usleep(c/200);
}
int mp3_get_bitrate(FILE *f, int size)
{
return 128;
@ -467,10 +341,6 @@ void mp3_update(int *buffer, int length, int stereo)
{
}
void cache_flush_d_inval_i()
{
}
/* lprintf */
void lprintf(const char *fmt, ...)
{

View file

@ -1,4 +1,5 @@
#include <stdio.h>
#include <string.h>
#include <dirent.h>
#include <sys/time.h>
#include <time.h>
@ -17,6 +18,21 @@ int plat_is_dir(const char *path)
return 0;
}
int plat_get_root_dir(char *dst, int len)
{
extern char **g_argv;
int j;
strncpy(dst, g_argv[0], len);
len -= 32; // reserve
if (len < 0) len = 0;
dst[len] = 0;
for (j = strlen(dst); j > 0; j--)
if (dst[j] == '/') { dst[j+1] = 0; break; }
return j + 1;
}
#ifdef __GP2X__
/* Wiz has a borked gettimeofday().. */
#define plat_get_ticks_ms plat_get_ticks_ms_good