Skip to content
Permalink
Browse files

Merge pull request #65 from retro-wertz/libretro

retro_get_memory_data/size and memory descriptors update
  • Loading branch information
hizzlekizzle committed Jul 28, 2019
2 parents 90b051e + 2084a63 commit c3edd6d433a73e7bb805b6a1373aaaa1a6c0128c
@@ -110,6 +110,8 @@ endif()

option(ENABLE_FFMPEG "Enable ffmpeg A/V recording" ${FFMPEG_DEFAULT})

option(ENABLE_ONLINEUPDATES "Enable online update checks" ON)

set(LTO_DEFAULT ON)

# lto produces buggy binaries for 64 bit win32
@@ -293,6 +295,10 @@ if(ENABLE_FFMPEG)
endif()
endif()

if(NOT ENABLE_ONLINEUPDATES)
add_definitions(-DNO_ONLINEUPDATES)
endif()

if(NOT ENABLE_FFMPEG)
add_definitions(-DNO_FFMPEG)
endif()
@@ -444,7 +450,7 @@ if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID STREQUAL Clang)
if(X86_32 OR AMD64)
set(MY_C_OPT_FLAGS ${MY_C_OPT_FLAGS} -mtune=generic)
endif()

# common debug flags
if(CMAKE_COMPILER_IS_GNUCXX)
set(MY_C_DBG_FLAGS -ggdb3 -Og -fno-omit-frame-pointer)
@@ -177,6 +177,7 @@ Here is the complete list:
| ENABLE_LINK | Enable GBA linking functionality (requires SFML) | ON |
| ENABLE_LIRC | Enable LIRC support | OFF |
| ENABLE_FFMPEG | Enable ffmpeg A/V recording | OFF |
| ENABLE_ONLINEUPDATES | Enable online update checks | ON |
| ENABLE_LTO | Compile with Link Time Optimization (gcc and clang only) | ON for release build |
| ENABLE_GBA_LOGGING | Enable extended GBA logging | ON |
| ENABLE_DIRECT3D | Direct3D rendering for wxWidgets (Windows, **NOT IMPLEMENTED!!!**) | ON |
@@ -38,7 +38,6 @@ extern "C" {
#else // _WIN32
#include <direct.h>
#define GETCWD _getcwd
#define snprintf sprintf
#define stat _stat
#define mkdir(X,Y) (_mkdir(X))
// from: https://www.linuxquestions.org/questions/programming-9/porting-to-win32-429334/
@@ -4830,16 +4830,16 @@ void gbEmulate(int ticksToStop)
//(fixes a part of Carmaggedon problem)
if ((register_LCDC & 0x01 || gbCgbMode) && (register_LCDC & 0x20) && (gbWindowLine != -2)) {

int inUseRegister_WY = 0;
int tempinUseRegister_WY = inUseRegister_WY;
int tempgbWindowLine = gbWindowLine;

if ((tempgbWindowLine == -1) || (tempgbWindowLine > 144)) {
inUseRegister_WY = oldRegister_WY;
tempinUseRegister_WY = oldRegister_WY;
if (register_LY > oldRegister_WY)
tempgbWindowLine = 146;
}

if (register_LY >= inUseRegister_WY) {
if (register_LY >= tempinUseRegister_WY) {

if (tempgbWindowLine == -1)
tempgbWindowLine = 0;
@@ -2,6 +2,8 @@
#include <stdlib.h>
#include <string.h>

#include <libretro.h>

#include "NLS.h"
#include "System.h"
#include "Util.h"
@@ -111,63 +113,59 @@ bool utilIsGBImage(const char* file)
return false;
}

// strip .gz or .z off end
void utilStripDoubleExtension(const char* file, char* buffer)
IMAGE_TYPE utilFindType(const char* file)
{
if (buffer != file) // allows conversion in place
strcpy(buffer, file);
}
if (utilIsGBAImage(file))
return IMAGE_GBA;

static bool utilIsImage(const char* file)
{
return utilIsGBAImage(file) || utilIsGBImage(file);
}
if (utilIsGBImage(file))
return IMAGE_GB;

IMAGE_TYPE utilFindType(const char* file)
{
//char buffer[2048];
if (!utilIsImage(file)) // TODO: utilIsArchive() instead?
{
return IMAGE_UNKNOWN;
}
return utilIsGBAImage(file) ? IMAGE_GBA : IMAGE_GB;
return IMAGE_UNKNOWN;
}

static int utilGetSize(int size)
{
int res = 1;
while(res < size)
res <<= 1;
return res;
int res = 1;
while(res < size)
res <<= 1;
return res;
}

uint8_t *utilLoad(const char *file, bool (*accept)(const char *), uint8_t *data, int &size)
{
FILE *fp = NULL;
//char *buf = NULL;

fp = fopen(file,"rb");
if(!fp) return NULL;
fseek(fp, 0, SEEK_END); //go to end
size = ftell(fp); // get position at end (length)
rewind(fp);

uint8_t *image = data;
if(image == NULL)
{
//allocate buffer memory if none was passed to the function
image = (uint8_t *)malloc(utilGetSize(size));
if(image == NULL)
{
systemMessage(MSG_OUT_OF_MEMORY, N_("Failed to allocate memory for %s"),
"data");
return NULL;
}
}

FREAD_UNCHECKED(image, 1, size, fp); // read into buffer
fclose(fp);
return image;
FILE *fp = NULL;

fp = fopen(file,"rb");
if (!fp)
{
log("Failed to open file %s", file);
return NULL;
}
fseek(fp, 0, SEEK_END); //go to end

size = ftell(fp); // get position at end (length)
rewind(fp);

uint8_t *image = data;
if(image == NULL)
{
image = (uint8_t *)malloc(utilGetSize(size));
if(image == NULL)
{
log("Failed to allocate memory for %s", file);
return NULL;
}
}

if (fread(image, 1, size, fp) != size) {
log("Failed to read from %s", file);
fclose(fp);
return NULL;
}

fclose(fp);
return image;
}

void utilGBAFindSave(const int size)
@@ -220,12 +218,10 @@ void utilGBAFindSave(const int size)
p++;
}
// if no matches found, then set it to NONE
if (detectedSaveType == 0) {
if (detectedSaveType == 0)
detectedSaveType = 5;
}
if (detectedSaveType == 4) {
if (detectedSaveType == 4)
detectedSaveType = 3;
}

cpuSaveType = detectedSaveType;
rtcEnabled = rtcFound_;
@@ -234,30 +230,20 @@ void utilGBAFindSave(const int size)

void utilUpdateSystemColorMaps(bool lcd)
{
int i = 0;

(void)lcd;

switch (systemColorDepth) {
case 16: {
for (int i = 0; i < 0x10000; i++) {
case 16:
for (i = 0; i < 0x10000; i++)
systemColorMap16[i] = ((i & 0x1f) << systemRedShift) | (((i & 0x3e0) >> 5) << systemGreenShift) | (((i & 0x7c00) >> 10) << systemBlueShift);
}
} break;
break;
case 24:
case 32: {
for (int i = 0; i < 0x10000; i++) {
case 32:
for (i = 0; i < 0x10000; i++)
systemColorMap32[i] = ((i & 0x1f) << systemRedShift) | (((i & 0x3e0) >> 5) << systemGreenShift) | (((i & 0x7c00) >> 10) << systemBlueShift);
}
} break;
}
}

// Check for existence of file.
bool utilFileExists(const char* filename)
{
FILE* f = fopen(filename, "r");
if (f == NULL) {
return false;
} else {
fclose(f);
return true;
break;
}
}

0 comments on commit c3edd6d

Please sign in to comment.
You can’t perform that action at this time.