Reimplement large parts of FCEUmm API - still no background layers -

only sprites
This commit is contained in:
twinaphex
2014-03-31 00:17:47 +02:00
parent d4a3125c44
commit cd8f609236
2 changed files with 85 additions and 47 deletions

View File

@@ -29,6 +29,8 @@
#include <string.h> #include <string.h>
#include "memstream.h" #include "memstream.h"
static retro_video_refresh_t video_cb = NULL; static retro_video_refresh_t video_cb = NULL;
static retro_input_poll_t poll_cb = NULL; static retro_input_poll_t poll_cb = NULL;
static retro_input_state_t input_cb = NULL; static retro_input_state_t input_cb = NULL;
@@ -45,6 +47,13 @@ static __attribute__((aligned(16))) uint16_t retro_palette[256];
static uint16_t retro_palette[256]; static uint16_t retro_palette[256];
#endif #endif
/* Some timing-related variables. */
static int maxconbskip = 9; /* Maximum consecutive blit skips. */
static int ffbskip = 9; /* Blit skips per blit when FF-ing */
static int soundo = 1;
static volatile int nofocus = 0;
static int32 *sound = 0; static int32 *sound = 0;
static uint32 JSReturn[2]; static uint32 JSReturn[2];
@@ -87,6 +96,9 @@ int FCEUD_SendData(void *data, uint32 len)
#define RED_EXPAND 3 #define RED_EXPAND 3
#define GREEN_EXPAND 2 #define GREEN_EXPAND 2
#define BLUE_EXPAND 3 #define BLUE_EXPAND 3
#define RED_MASK 0xF800
#define GREEN_MASK 0x7e0
#define BLUE_MASK 0x1f
#else #else
#define RED_SHIFT 10 #define RED_SHIFT 10
#define GREEN_SHIFT 5 #define GREEN_SHIFT 5
@@ -104,6 +116,11 @@ void FCEUD_SetPalette(unsigned char index, unsigned char r, unsigned char g, uns
retro_palette[index] = (r << RED_SHIFT) | (g << GREEN_SHIFT) | (b << BLUE_SHIFT); retro_palette[index] = (r << RED_SHIFT) | (g << GREEN_SHIFT) | (b << BLUE_SHIFT);
} }
void FCEUD_GetPalette(unsigned char i, unsigned char *r, unsigned char *g, unsigned char *b)
{
}
bool FCEUD_ShouldDrawInputAids (void) bool FCEUD_ShouldDrawInputAids (void)
{ {
return 1; return 1;
@@ -118,8 +135,6 @@ void FCEUD_Message(char *s)
void FCEUD_NetworkClose(void) void FCEUD_NetworkClose(void)
{ } { }
void FCEUD_GetPalette(uint8 i,uint8 *r, uint8 *g, uint8 *b) { }
void FCEUD_SoundToggle (void) void FCEUD_SoundToggle (void)
{ {
FCEUI_SetSoundVolume(100); FCEUI_SetSoundVolume(100);
@@ -542,25 +557,6 @@ static const keymap bindmap[] = {
{ RETRO_DEVICE_ID_JOYPAD_RIGHT, JOY_RIGHT }, { RETRO_DEVICE_ID_JOYPAD_RIGHT, JOY_RIGHT },
}; };
static void update_input(void)
{
unsigned i;
unsigned char pad[2];
pad[0] = 0;
pad[1] = 0;
poll_cb();
for ( i = 0; i < 8; i++)
pad[0] |= input_cb(0, RETRO_DEVICE_JOYPAD, 0, bindmap[i].retro) ? bindmap[i].nes : 0;
for ( i = 0; i < 8; i++)
pad[1] |= input_cb(1, RETRO_DEVICE_JOYPAD, 0, bindmap[i].retro) ? bindmap[i].nes : 0;
JSReturn[0] = pad[0] | (pad[1] << 8);
}
static void check_variables(void) static void check_variables(void)
{ {
struct retro_variable var = {0}; struct retro_variable var = {0};
@@ -605,23 +601,29 @@ static void check_variables(void)
} }
} }
void retro_run(void) static void FCEUD_UpdateInput(void)
{
unsigned i;
unsigned char pad[2];
pad[0] = 0;
pad[1] = 0;
poll_cb();
for ( i = 0; i < 8; i++)
pad[0] |= input_cb(0, RETRO_DEVICE_JOYPAD, 0, bindmap[i].retro) ? bindmap[i].nes : 0;
for ( i = 0; i < 8; i++)
pad[1] |= input_cb(1, RETRO_DEVICE_JOYPAD, 0, bindmap[i].retro) ? bindmap[i].nes : 0;
JSReturn[0] = pad[0] | (pad[1] << 8);
}
void FCEUD_BlitScreen(uint8 *XBuf)
{ {
unsigned y, x, width, height, pitch;
uint8_t *gfx; uint8_t *gfx;
int32 ssize; unsigned width, height, pitch, x, y;
bool updated;
#ifndef PSP
static uint16_t video_out[256 * 240];
#endif
ssize = 0;
updated = false;
update_input();
FCEUI_Emulate(&gfx, &sound, &ssize, 0);
#ifdef PSP #ifdef PSP
static unsigned int __attribute__((aligned(16))) d_list[32]; static unsigned int __attribute__((aligned(16))) d_list[32];
void* const texture_vram_p = (void*) (0x44200000 - (256 * 256)); // max VRAM address - frame size void* const texture_vram_p = (void*) (0x44200000 - (256 * 256)); // max VRAM address - frame size
@@ -648,45 +650,76 @@ void retro_run(void)
sceGuClutLoad(32, retro_palette); sceGuClutLoad(32, retro_palette);
sceGuFinish(); sceGuFinish();
#else
static uint16_t video_out[256 * 240];
#endif #endif
if (use_overscan) if (use_overscan)
{ {
width = 256; width = 256;
height = 240; height = 240;
#ifdef PSP
pitch = 256; pitch = 256;
video_cb(texture_vram_p, width, height, pitch); #ifndef PSP
#else
pitch = 512; pitch = 512;
gfx = XBuf; gfx = XBuf;
for (y = 0; y < height; y++) for (y = 0; y < height; y++)
for ( x = 0; x < width; x++, gfx++) for ( x = 0; x < width; x++, gfx++)
video_out[y * width + x] = retro_palette[*gfx]; video_out[y * width + x] = retro_palette[*gfx];
video_cb(video_out, width, height, pitch);
#endif #endif
} }
else else
{ {
width = 256 - 16; width = 256 - 16;
height = 240 - 16; height = 240 - 16;
#ifdef PSP
pitch = 256; pitch = 256;
video_cb(texture_vram_p, width, height, pitch); #ifndef PSP
#else
pitch = 512 - 32; pitch = 512 - 32;
gfx = XBuf + 8 + 256 * 8; gfx = XBuf + 8 + 256 * 8;
for (y = 0; y < height; y++, gfx += 16) for (y = 0; y < height; y++, gfx += 16)
for ( x = 0; x < width; x++, gfx++) for ( x = 0; x < width; x++, gfx++)
video_out[y * width + x] = retro_palette[*gfx]; video_out[y * width + x] = retro_palette[*gfx];
video_cb(video_out, width, height, pitch);
#endif #endif
} }
for (y = 0; y < ssize; y++) #ifdef PSP
sound[y] = (sound[y] << 16) | (sound[y] & 0xffff); video_cb(texture_vram_p, width, height, pitch);
#else
video_cb(video_out, width, height, pitch);
#endif
}
audio_batch_cb((const int16_t*)sound, ssize); void FCEUD_WriteSoundData(int32 *Buffer, int Count)
{
int y;
for (y = 0; y < Count; y++)
Buffer[y] = (Buffer[y] << 16) | (Buffer[y] & 0xffff);
audio_batch_cb((const int16_t*)Buffer, Count);
}
void FCEUD_Update(uint8 *XBuf, int32 *Buffer, int Count)
{
if (Count)
FCEUD_WriteSoundData(Buffer, Count);
FCEUD_BlitScreen(XBuf);
Buffer += Count;
FCEUD_UpdateInput();
}
void retro_run(void)
{
unsigned y, x;
uint8_t *gfx;
int32 ssize;
bool updated;
ssize = 0;
updated = false;
FCEUI_SetRenderDisable(0, 0);
FCEUI_Emulate(&gfx, &sound, &ssize, 0);
FCEUD_Update(gfx, sound, ssize);
if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE_UPDATE, &updated) && updated) if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE_UPDATE, &updated) && updated)
check_variables(); check_variables();

View File

@@ -81,6 +81,7 @@ char *FCEU_MakeFName(int type, int id1, char *cd1) {
struct stat tmpstat; struct stat tmpstat;
switch (type) { switch (type) {
#ifndef __LIBRETRO__
case FCEUMKF_NPTEMP: asprintf(&ret, "%s"PSS "m590plqd94fo.tmp", BaseDirectory); break; case FCEUMKF_NPTEMP: asprintf(&ret, "%s"PSS "m590plqd94fo.tmp", BaseDirectory); break;
case FCEUMKF_MOVIE: case FCEUMKF_MOVIE:
if (odirs[FCEUIOD_STATE]) if (odirs[FCEUIOD_STATE])
@@ -149,6 +150,7 @@ char *FCEU_MakeFName(int type, int id1, char *cd1) {
break; break;
case FCEUMKF_IPS: asprintf(&ret, "%s"PSS "%s%s.ips", FileBaseDirectory, FileBase, FileExt); case FCEUMKF_IPS: asprintf(&ret, "%s"PSS "%s%s.ips", FileBaseDirectory, FileBase, FileExt);
break; break;
#endif
case FCEUMKF_GGROM: asprintf(&ret, "%s"PSS "gg.rom", BaseDirectory); break; case FCEUMKF_GGROM: asprintf(&ret, "%s"PSS "gg.rom", BaseDirectory); break;
case FCEUMKF_FDSROM: asprintf(&ret, "%s"PSS "disksys.rom", BaseDirectory); break; case FCEUMKF_FDSROM: asprintf(&ret, "%s"PSS "disksys.rom", BaseDirectory); break;
case FCEUMKF_PALETTE: case FCEUMKF_PALETTE:
@@ -157,6 +159,9 @@ char *FCEU_MakeFName(int type, int id1, char *cd1) {
else else
asprintf(&ret, "%s"PSS "gameinfo"PSS "%s.pal", BaseDirectory, FileBase); asprintf(&ret, "%s"PSS "gameinfo"PSS "%s.pal", BaseDirectory, FileBase);
break; break;
default:
ret = malloc(1);
*ret = '\0';
} }
return(ret); return(ret);
} }