Skip to content

Commit

Permalink
post-merge fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
warmenhoven committed Jan 5, 2025
1 parent 31412f0 commit 43243c1
Show file tree
Hide file tree
Showing 6 changed files with 79 additions and 64 deletions.
2 changes: 1 addition & 1 deletion Makefile.libretro
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,7 @@ else ifeq ($(platform), ctr)
CFLAGS += -I$(CTRULIB)/include
DEFINES += -std=c99

PLATFORM_DEFINES += -DUSE_VFS_3DS
PLATFORM_DEFINES += -DENABLE_VFS_3DS
STATIC_LINKING = 1

# Xbox 360
Expand Down
9 changes: 7 additions & 2 deletions libretro-build/Makefile.common
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ ifneq ($(DEBUG), 1)
endif

ifneq ($(HAVE_VFS_FD),1)
RETRODEFS += -DUSE_VFS_FILE
RETRODEFS += -DENABLE_VFS_FILE
endif

ifeq (,$(findstring win,$(platform)))
Expand Down Expand Up @@ -91,6 +91,7 @@ SOURCES_C := $(CORE_DIR)/src/arm/arm.c \
$(CORE_DIR)/src/gba/gba.c \
$(CORE_DIR)/src/gba/cart/gpio.c \
$(CORE_DIR)/src/gba/cart/ereader.c \
$(CORE_DIR)/src/gba/cart/unlicensed.c \
$(CORE_DIR)/src/gba/hle-bios.c \
$(CORE_DIR)/src/gba/input.c \
$(CORE_DIR)/src/gba/io.c \
Expand All @@ -114,13 +115,16 @@ SOURCES_C := $(CORE_DIR)/src/arm/arm.c \
$(CORE_DIR)/src/platform/libretro/libretro.c \
$(CORE_DIR)/src/sm83/isa-sm83.c \
$(CORE_DIR)/src/sm83/sm83.c \
$(CORE_DIR)/src/third-party/blip_buf/blip_buf.c \
$(CORE_DIR)/src/third-party/inih/ini.c \
$(CORE_DIR)/src/util/audio-buffer.c \
$(CORE_DIR)/src/util/circle-buffer.c \
$(CORE_DIR)/src/util/configuration.c \
$(CORE_DIR)/src/util/formatting.c \
$(CORE_DIR)/src/util/gbk-table.c \
$(CORE_DIR)/src/util/geometry.c \
$(CORE_DIR)/src/util/hash.c \
$(CORE_DIR)/src/util/image.c \
$(CORE_DIR)/src/util/md5.c \
$(CORE_DIR)/src/util/patch.c \
$(CORE_DIR)/src/util/patch-ips.c \
$(CORE_DIR)/src/util/patch-ups.c \
Expand All @@ -136,6 +140,7 @@ RETRODEFS += -DHAVE_CRC32
endif

ifeq ($(HAVE_VFS_FD),1)
RETRODEFS += -DENABLE_VFS_FD
ifeq ($(platform), vita)
SOURCES_C += $(CORE_DIR)/src/platform/psp2/sce-vfs.c
else ifeq ($(platform), ctr)
Expand Down
6 changes: 6 additions & 0 deletions src/platform/3ds/3ds-vfs.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ struct VFile3DS {
u64 offset;
};

#ifdef ENABLE_VFS
struct VDirEntry3DS {
struct VDirEntry d;
FS_DirectoryEntry ent[MAX_ENT];
Expand All @@ -33,6 +34,7 @@ struct VDir3DS {
Handle handle;
struct VDirEntry3DS vde;
};
#endif

static bool _vf3dClose(struct VFile* vf);
static off_t _vf3dSeek(struct VFile* vf, off_t offset, int whence);
Expand All @@ -44,6 +46,7 @@ static void _vf3dTruncate(struct VFile* vf, size_t size);
static ssize_t _vf3dSize(struct VFile* vf);
static bool _vf3dSync(struct VFile* vf, void* buffer, size_t size);

#ifdef ENABLE_VFS
static bool _vd3dClose(struct VDir* vd);
static void _vd3dRewind(struct VDir* vd);
static struct VDirEntry* _vd3dListNext(struct VDir* vd);
Expand All @@ -53,6 +56,7 @@ static bool _vd3dDeleteFile(struct VDir* vd, const char* path);

static const char* _vd3deName(struct VDirEntry* vde);
static enum VFSType _vd3deType(struct VDirEntry* vde);
#endif

struct VFile* VFileOpen3DS(FS_Archive* archive, const char* path, int flags) {
struct VFile3DS* vf3d = malloc(sizeof(struct VFile3DS));
Expand Down Expand Up @@ -178,6 +182,7 @@ static bool _vf3dSync(struct VFile* vf, void* buffer, size_t size) {
return true;
}

#ifdef ENABLE_VFS
struct VDir* VDirOpen(const char* path) {
struct VDir3DS* vd3d = malloc(sizeof(struct VDir3DS));
if (!vd3d) {
Expand Down Expand Up @@ -326,3 +331,4 @@ bool VDirCreate(const char* path) {
return R_SUCCEEDED(rc) || rc == 0xC82044BE;
}
#endif
#endif
116 changes: 58 additions & 58 deletions src/platform/libretro/libretro.c
Original file line number Diff line number Diff line change
Expand Up @@ -353,7 +353,7 @@ static void _loadAudioLowPassFilterSettings(void) {
#define GBA_CC_BG 0.21f
#define GBA_CC_GAMMA_ADJ 1.0f

static color_t* ccLUT = NULL;
static mColor* ccLUT = NULL;
static unsigned ccType = 0;
static bool colorCorrectionEnabled = false;

Expand Down Expand Up @@ -456,7 +456,7 @@ static void _initColorCorrection(void) {

/* Allocate look-up table buffer, if required */
if (!ccLUT) {
size_t lutSize = 65536 * sizeof(color_t);
size_t lutSize = 65536 * sizeof(mColor);
ccLUT = malloc(lutSize);
if (!ccLUT) {
return;
Expand Down Expand Up @@ -553,17 +553,17 @@ enum frame_blend_method

static enum frame_blend_method frameBlendType = FRAME_BLEND_NONE;
static bool frameBlendEnabled = false;
static color_t* outputBufferPrev1 = NULL;
static color_t* outputBufferPrev2 = NULL;
static color_t* outputBufferPrev3 = NULL;
static color_t* outputBufferPrev4 = NULL;
static mColor* outputBufferPrev1 = NULL;
static mColor* outputBufferPrev2 = NULL;
static mColor* outputBufferPrev3 = NULL;
static mColor* outputBufferPrev4 = NULL;
static float* outputBufferAccR = NULL;
static float* outputBufferAccG = NULL;
static float* outputBufferAccB = NULL;
static float frameBlendResponse[4] = {0.0f};
static bool frameBlendResponseSet = false;

static bool _allocateOutputBufferPrev(color_t** buf) {
static bool _allocateOutputBufferPrev(mColor** buf) {
if (!*buf) {
*buf = malloc(VIDEO_BUFF_SIZE);
if (!*buf) {
Expand Down Expand Up @@ -721,7 +721,7 @@ static void _loadFrameBlendSettings(void) {
}

/* General post processing buffers/functions */
static color_t* ppOutputBuffer = NULL;
static mColor* ppOutputBuffer = NULL;

static void (*videoPostProcess)(unsigned width, unsigned height) = NULL;

Expand All @@ -732,8 +732,8 @@ static void (*videoPostProcess)(unsigned width, unsigned height) = NULL;
* minimise logic in the inner loops where possible */
static void videoPostProcessCc(unsigned width, unsigned height) {

color_t *src = outputBuffer;
color_t *dst = ppOutputBuffer;
mColor *src = outputBuffer;
mColor *dst = ppOutputBuffer;
size_t x, y;

for (y = 0; y < height; y++) {
Expand All @@ -747,25 +747,25 @@ static void videoPostProcessCc(unsigned width, unsigned height) {

static void videoPostProcessMix(unsigned width, unsigned height) {

color_t *srcCurr = outputBuffer;
color_t *srcPrev = outputBufferPrev1;
color_t *dst = ppOutputBuffer;
mColor *srcCurr = outputBuffer;
mColor *srcPrev = outputBufferPrev1;
mColor *dst = ppOutputBuffer;
size_t x, y;

for (y = 0; y < height; y++) {
for (x = 0; x < width; x++) {

/* Get colours from current + previous frames */
color_t rgbCurr = *(srcCurr + x);
color_t rgbPrev = *(srcPrev + x);
mColor rgbCurr = *(srcCurr + x);
mColor rgbPrev = *(srcPrev + x);

/* Store colours for next frame */
*(srcPrev + x) = rgbCurr;
*(srcPrev + x) = rgbCurr;

/* Mix colours
* > "Mixing Packed RGB Pixels Efficiently"
* http://blargg.8bitalley.com/info/rgb_mixing.html */
color_t rgbMix = (rgbCurr + rgbPrev + ((rgbCurr ^ rgbPrev) & 0x821)) >> 1;
mColor rgbMix = (rgbCurr + rgbPrev + ((rgbCurr ^ rgbPrev) & 0x821)) >> 1;

/* Assign colours for current frame */
*(dst + x) = colorCorrectionEnabled ?
Expand All @@ -779,21 +779,21 @@ static void videoPostProcessMix(unsigned width, unsigned height) {

static void videoPostProcessMixSmart(unsigned width, unsigned height) {

color_t *srcCurr = outputBuffer;
color_t *srcPrev1 = outputBufferPrev1;
color_t *srcPrev2 = outputBufferPrev2;
color_t *srcPrev3 = outputBufferPrev3;
color_t *dst = ppOutputBuffer;
mColor *srcCurr = outputBuffer;
mColor *srcPrev1 = outputBufferPrev1;
mColor *srcPrev2 = outputBufferPrev2;
mColor *srcPrev3 = outputBufferPrev3;
mColor *dst = ppOutputBuffer;
size_t x, y;

for (y = 0; y < height; y++) {
for (x = 0; x < width; x++) {

/* Get colours from current + previous frames */
color_t rgbCurr = *(srcCurr + x);
color_t rgbPrev1 = *(srcPrev1 + x);
color_t rgbPrev2 = *(srcPrev2 + x);
color_t rgbPrev3 = *(srcPrev3 + x);
mColor rgbCurr = *(srcCurr + x);
mColor rgbPrev1 = *(srcPrev1 + x);
mColor rgbPrev2 = *(srcPrev2 + x);
mColor rgbPrev3 = *(srcPrev3 + x);

/* Store colours for next frame */
*(srcPrev1 + x) = rgbCurr;
Expand All @@ -811,7 +811,7 @@ static void videoPostProcessMixSmart(unsigned width, unsigned height) {
/* Mix colours
* > "Mixing Packed RGB Pixels Efficiently"
* http://blargg.8bitalley.com/info/rgb_mixing.html */
color_t rgbMix = (rgbCurr + rgbPrev1 + ((rgbCurr ^ rgbPrev1) & 0x821)) >> 1;
mColor rgbMix = (rgbCurr + rgbPrev1 + ((rgbCurr ^ rgbPrev1) & 0x821)) >> 1;

/* Assign colours for current frame */
*(dst + x) = colorCorrectionEnabled ?
Expand All @@ -833,24 +833,24 @@ static void videoPostProcessMixSmart(unsigned width, unsigned height) {

static void videoPostProcessLcdGhost(unsigned width, unsigned height) {

color_t *srcCurr = outputBuffer;
color_t *srcPrev1 = outputBufferPrev1;
color_t *srcPrev2 = outputBufferPrev2;
color_t *srcPrev3 = outputBufferPrev3;
color_t *srcPrev4 = outputBufferPrev4;
color_t *dst = ppOutputBuffer;
float *response = frameBlendResponse;
mColor *srcCurr = outputBuffer;
mColor *srcPrev1 = outputBufferPrev1;
mColor *srcPrev2 = outputBufferPrev2;
mColor *srcPrev3 = outputBufferPrev3;
mColor *srcPrev4 = outputBufferPrev4;
mColor *dst = ppOutputBuffer;
float *response = frameBlendResponse;
size_t x, y;

for (y = 0; y < height; y++) {
for (x = 0; x < width; x++) {

/* Get colours from current + previous frames */
color_t rgbCurr = *(srcCurr + x);
color_t rgbPrev1 = *(srcPrev1 + x);
color_t rgbPrev2 = *(srcPrev2 + x);
color_t rgbPrev3 = *(srcPrev3 + x);
color_t rgbPrev4 = *(srcPrev4 + x);
mColor rgbCurr = *(srcCurr + x);
mColor rgbPrev1 = *(srcPrev1 + x);
mColor rgbPrev2 = *(srcPrev2 + x);
mColor rgbPrev3 = *(srcPrev3 + x);
mColor rgbPrev4 = *(srcPrev4 + x);

/* Store colours for next frame */
*(srcPrev1 + x) = rgbCurr;
Expand Down Expand Up @@ -879,7 +879,7 @@ static void videoPostProcessLcdGhost(unsigned width, unsigned height) {
float gPrev4 = (float)(rgbPrev4 >> 6 & 0x1F);
float bPrev4 = (float)(rgbPrev4 & 0x1F);

/* Mix colours for current frame and convert back to color_t
/* Mix colours for current frame and convert back to mColor
* > Response time effect implemented via an exponential
* drop-off algorithm, taken from the 'Gameboy Classic Shader'
* by Harlequin:
Expand All @@ -888,19 +888,19 @@ static void videoPostProcessLcdGhost(unsigned width, unsigned height) {
rCurr += (rPrev2 - rCurr) * *(response + 1);
rCurr += (rPrev3 - rCurr) * *(response + 2);
rCurr += (rPrev4 - rCurr) * *(response + 3);
color_t rMix = (color_t)(rCurr + 0.5f) & 0x1F;
mColor rMix = (mColor)(rCurr + 0.5f) & 0x1F;

gCurr += (gPrev1 - gCurr) * *response;
gCurr += (gPrev2 - gCurr) * *(response + 1);
gCurr += (gPrev3 - gCurr) * *(response + 2);
gCurr += (gPrev4 - gCurr) * *(response + 3);
color_t gMix = (color_t)(gCurr + 0.5f) & 0x1F;
mColor gMix = (mColor)(gCurr + 0.5f) & 0x1F;

bCurr += (bPrev1 - bCurr) * *response;
bCurr += (bPrev2 - bCurr) * *(response + 1);
bCurr += (bPrev3 - bCurr) * *(response + 2);
bCurr += (bPrev4 - bCurr) * *(response + 3);
color_t bMix = (color_t)(bCurr + 0.5f) & 0x1F;
mColor bMix = (mColor)(bCurr + 0.5f) & 0x1F;

/* Repack colours for current frame */
*(dst + x) = colorCorrectionEnabled ?
Expand All @@ -918,21 +918,21 @@ static void videoPostProcessLcdGhost(unsigned width, unsigned height) {

static void videoPostProcessLcdGhostFast(unsigned width, unsigned height) {

color_t *srcCurr = outputBuffer;
float *srcPrevR = outputBufferAccR;
float *srcPrevG = outputBufferAccG;
float *srcPrevB = outputBufferAccB;
color_t *dst = ppOutputBuffer;
mColor *srcCurr = outputBuffer;
float *srcPrevR = outputBufferAccR;
float *srcPrevG = outputBufferAccG;
float *srcPrevB = outputBufferAccB;
mColor *dst = ppOutputBuffer;
size_t x, y;

for (y = 0; y < height; y++) {
for (x = 0; x < width; x++) {

/* Get colours from current + previous frames */
color_t rgbCurr = *(srcCurr + x);
float rPrev = *(srcPrevR + x);
float gPrev = *(srcPrevG + x);
float bPrev = *(srcPrevB + x);
mColor rgbCurr = *(srcCurr + x);
float rPrev = *(srcPrevR + x);
float gPrev = *(srcPrevG + x);
float bPrev = *(srcPrevB + x);

/* Unpack current colours and convert to float */
float rCurr = (float)(rgbCurr >> 11 & 0x1F);
Expand All @@ -950,9 +950,9 @@ static void videoPostProcessLcdGhostFast(unsigned width, unsigned height) {
*(srcPrevB + x) = bMix;

/* Convert and repack current frame colours */
color_t rgbMix = ((color_t)(rMix + 0.5f) & 0x1F) << 11
| ((color_t)(gMix + 0.5f) & 0x1F) << 6
| ((color_t)(bMix + 0.5f) & 0x1F);
mColor rgbMix = ((mColor)(rMix + 0.5f) & 0x1F) << 11
| ((mColor)(gMix + 0.5f) & 0x1F) << 6
| ((mColor)(bMix + 0.5f) & 0x1F);

/* Assign colours for current frame */
*(dst + x) = colorCorrectionEnabled ?
Expand Down Expand Up @@ -1682,12 +1682,12 @@ void retro_run(void) {
#if defined(COLOR_16_BIT) && defined(COLOR_5_6_5)
if (videoPostProcess) {
videoPostProcess(width, height);
videoCallback(ppOutputBuffer, width, height, VIDEO_WIDTH_MAX * sizeof(color_t));
videoCallback(ppOutputBuffer, width, height, VIDEO_WIDTH_MAX * sizeof(mColor));
} else
#endif
videoCallback(outputBuffer, width, height, VIDEO_WIDTH_MAX * sizeof(color_t));
videoCallback(outputBuffer, width, height, VIDEO_WIDTH_MAX * sizeof(mColor));
} else {
videoCallback(NULL, width, height, VIDEO_WIDTH_MAX * sizeof(color_t));
videoCallback(NULL, width, height, VIDEO_WIDTH_MAX * sizeof(mColor));
}

#ifdef M_CORE_GBA
Expand Down
Loading

0 comments on commit 43243c1

Please sign in to comment.