Skip to content

Commit

Permalink
Added frameskip.
Browse files Browse the repository at this point in the history
  • Loading branch information
Nunatica committed Nov 20, 2016
1 parent c5bedbd commit 9a6896b
Show file tree
Hide file tree
Showing 4 changed files with 91 additions and 71 deletions.
9 changes: 8 additions & 1 deletion Makefile.libretro
Expand Up @@ -6,6 +6,7 @@ USE_CHEATS=1
USE_TWEAKS=0
USE_THREADED_RENDERER=0
USE_MOTION_SENSOR=0
USE_FRAME_SKIP=0
HAVE_NEON=0

CORE_DIR := .
Expand Down Expand Up @@ -228,7 +229,7 @@ else ifeq ($(platform), vita)
CXX = arm-vita-eabi-g++$(EXE_EXT)
AR = arm-vita-eabi-ar$(EXE_EXT)
PLATFORM_DEFINES := -DBRANCHLESS_GBA_GFX -DVITA
__FLAGS := -marm -mtune=cortex-a9 -mcpu=cortex-a9 -mfloat-abi=hard -mword-relocations
__FLAGS := -marm -mfpu=neon -mtune=cortex-a9 -mcpu=cortex-a9 -mfloat-abi=hard -mword-relocations
__FLAGS += -fno-optimize-sibling-calls -fno-strict-aliasing -fno-partial-inlining -fno-tree-vrp
__FLAGS += -ffast-math -fsingle-precision-constant -funroll-loops -ftracer

Expand All @@ -241,6 +242,7 @@ else ifeq ($(platform), vita)
USE_TWEAKS=1
USE_THREADED_RENDERER=1
USE_MOTION_SENSOR=1
USE_FRAME_SKIP=1
HAVE_NEON=1
# Libxenon
else ifeq ($(platform), xenon)
Expand Down Expand Up @@ -367,6 +369,11 @@ CFLAGS += -DUSE_MOTION_SENSOR
CXXFLAGS += -DUSE_MOTION_SENSOR
endif

ifeq ($(USE_FRAME_SKIP), 1)
CFLAGS += -DUSE_FRAME_SKIP
CXXFLAGS += -DUSE_FRAME_SKIP
endif

LIBS :=

%.o: %.cpp
Expand Down
40 changes: 31 additions & 9 deletions libretro/libretro.cpp
Expand Up @@ -142,6 +142,9 @@ void retro_set_environment(retro_environment_t cb)

struct retro_variable variables[] = {
{ "vbanext_bios", "Use bios (if available); enabled|disabled" },
#if USE_FRAME_SKIP
{ "vbanext_frameskip", "Frameskip; 0|1/3|1/2|1|2|3|4" },
#endif
{ NULL, NULL },
};

Expand Down Expand Up @@ -386,6 +389,27 @@ static void load_image_preferences (void)
}
}

#if USE_FRAME_SKIP
static int get_frameskip_code()
{
struct retro_variable var;

var.key = "vbanext_frameskip";
var.value = NULL;

if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && var.value)
{
if (strcmp(var.value, "1/3") == 0) return 0x13;
if (strcmp(var.value, "1/2") == 0) return 0x12;
if (strcmp(var.value, "1") == 0) return 0x1;
if (strcmp(var.value, "2") == 0) return 0x2;
if (strcmp(var.value, "3") == 0) return 0x3;
if (strcmp(var.value, "4") == 0) return 0x4;
}
return 0;
}
#endif

static void gba_init(void)
{
cpuSaveType = 0;
Expand Down Expand Up @@ -435,6 +459,11 @@ static void gba_init(void)
uint8_t * state_buf = (uint8_t*)malloc(2000000);
serialize_size = CPUWriteState(state_buf, 2000000);
free(state_buf);

#if USE_FRAME_SKIP
SetFrameskip(get_frameskip_code());
#endif

}

void retro_deinit(void)
Expand Down Expand Up @@ -484,15 +513,8 @@ static unsigned has_frame;

static void update_variables(void)
{
#if 0
struct retro_variable var;

var.key = "vbam-next-undefined";
var.value = NULL;

if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && var.value)
{
}
#if USE_FRAME_SKIP
SetFrameskip(get_frameskip_code());
#endif
}

Expand Down
110 changes: 49 additions & 61 deletions src/gba.cpp
Expand Up @@ -4,6 +4,7 @@
#include <math.h>
#include <stddef.h>
#include <memalign.h>
#include <time.h>

#include "system.h"
#include "globals.h"
Expand Down Expand Up @@ -51,6 +52,22 @@
// Used in R_WIN_* to indicate whether color effects are enabled
#define LayerMask_SFX (1 << 5)

#if USE_FRAME_SKIP

int fs_count = 0;
int fs_type = 0;
int fs_type_a = 0;
int fs_type_b = 0;
bool fs_draw = false;

void SetFrameskip(int code)
{
fs_type = code;
fs_type_a = (0xF0 & fs_type) >> 4;
fs_type_b = 0xF & fs_type;
}
#endif

typedef void (*renderfunc_t)(void);

template<int renderer_idx>
Expand Down Expand Up @@ -11302,54 +11319,6 @@ static void threaded_renderer_loop(void* p) {
renderer_ctx.renderer_control = 0; //loop is terminated.
}

/*
static void threaded_renderer_loop(void* p) {
int renderer_idx = reinterpret_cast<intptr_t>(p);
INIT_RENDERER_CONTEXT(renderer_idx);

renderfunc_t drawSprites = NULL;
renderfunc_t drawOBJWin = NULL;
renderfunc_t (*getRenderFunc)(int, int) = NULL;

switch(renderer_idx) {
case 0:
drawSprites = gfxDrawSprites<0>;
drawOBJWin = gfxDrawOBJWin<0>;
getRenderFunc = GetRenderFunc<0>;
break;
case 1:
drawSprites = gfxDrawSprites<1>;
drawOBJWin = gfxDrawOBJWin<1>;
getRenderFunc = GetRenderFunc<1>;
break;
case 2:
drawSprites = gfxDrawSprites<2>;
drawOBJWin = gfxDrawOBJWin<2>;
getRenderFunc = GetRenderFunc<2>;
break;
case 3:
drawSprites = gfxDrawSprites<3>;
drawOBJWin = gfxDrawOBJWin<3>;
getRenderFunc = GetRenderFunc<3>;
break;
default:
return;
}

while(renderer_ctx.renderer_control == 1) {
if(renderer_idx == 0) {
if(threaded_renderer_ready) {
threaded_renderer_ready = 0;
systemDrawScreen();
}
}
threaded_renderer_loop_impl();
}

renderer_ctx.renderer_control = 0; //loop is terminated.
}
*/

static void fetchBackgroundOffset(int video_mode) {
//update gfxBG2X, gfxBG2Y, gfxBG3X, gfxBG3Y
switch(video_mode) {
Expand Down Expand Up @@ -12452,8 +12421,7 @@ void CPUUpdateRegister(uint32_t address, uint16_t value)
}

void CPUInit(const char *biosFileName, bool useBiosFile)
{

{
#ifdef MSB_FIRST
if(!cpuBiosSwapped)
{
Expand Down Expand Up @@ -13065,6 +13033,20 @@ void CPULoop (void)
#if !THREADED_RENDERER
systemDrawScreen();
#endif

#if USE_FRAME_SKIP
++fs_count;

if(fs_type_b == 0) {
fs_draw = true;
} else {
if(fs_type_a > 0) {
fs_draw = (fs_count % (fs_type_b + 1));
} else {
fs_draw = ((fs_count % (fs_type_b + 1)) == 0);
}
}
#endif
framedone = true;
}

Expand All @@ -13073,23 +13055,29 @@ void CPULoop (void)
}
else
{

#if USE_FRAME_SKIP
if(fs_draw) {
#endif
#if THREADED_RENDERER
postRender();
postRender();
#else
bool draw_objwin = (graphics.layerEnable & 0x9000) == 0x9000;
bool draw_sprites = R_DISPCNT_Screen_Display_OBJ;
bool draw_objwin = (graphics.layerEnable & 0x9000) == 0x9000;
bool draw_sprites = R_DISPCNT_Screen_Display_OBJ;

memset(RENDERER_LINE[Layer_OBJ], -1, 240 * sizeof(u32)); // erase all sprites
if(draw_sprites) gfxDrawSprites<0>();
memset(RENDERER_LINE[Layer_OBJ], -1, 240 * sizeof(u32)); // erase all sprites
if(draw_sprites) gfxDrawSprites<0>();

if(renderfunc_type == 2) {
memset(RENDERER_LINE[Layer_WIN_OBJ], -1, 240 * sizeof(u32)); // erase all OBJ Win
if(draw_objwin) gfxDrawOBJWin<0>();
}
if(renderfunc_type == 2) {
memset(RENDERER_LINE[Layer_WIN_OBJ], -1, 240 * sizeof(u32)); // erase all OBJ Win
if(draw_objwin) gfxDrawOBJWin<0>();
}

GetRenderFunc<0>(renderfunc_mode, renderfunc_type)();
GetRenderFunc<0>(renderfunc_mode, renderfunc_type)();
#endif
#if USE_FRAME_SKIP
}
#endif

// entering H-Blank
io_registers[REG_DISPSTAT] |= 2;
UPDATE_REG(0x04, io_registers[REG_DISPSTAT]);
Expand Down
3 changes: 3 additions & 0 deletions src/gba.h
Expand Up @@ -112,6 +112,9 @@ extern void CPUReset (void);
extern void CPULoop(void);
extern void UpdateJoypad(void);
extern void CPUCheckDMA(int,int);
#if USE_FRAME_SKIP
extern void SetFrameskip(int);
#endif

#if THREADED_RENDERER
extern void ThreadedRendererStart();
Expand Down

0 comments on commit 9a6896b

Please sign in to comment.