Commit 30d522cc authored by Libretro-Admin's avatar Libretro-Admin
Browse files

Indenting changes

parent 5f0d1260
Pipeline #58003 passed with stages
in 9 minutes and 27 seconds
......@@ -24,192 +24,182 @@ static const char *gme_allowed_exts[] = {
static bool is_gme_allowed_ext(char *ext)
{
int i;
int arr_length;
arr_length = sizeof(gme_allowed_exts) / sizeof(char*);
for(i=0;i<arr_length;i++)
{
if(strcmp(ext,gme_allowed_exts[i])==0)
{
return true;
}
}
return false;
int i;
int arr_length;
arr_length = sizeof(gme_allowed_exts) / sizeof(char*);
for(i=0;i<arr_length;i++)
{
if(strcmp(ext,gme_allowed_exts[i])==0)
return true;
}
return false;
}
static bool uncompress_file_data(file_data** fd)
{
int srcLen,dstLen;
int err = -1;
z_stream strm = {0};
file_data* src_fd = *fd;
file_data* dest_fd = NULL;
int srcLen,dstLen;
int err = -1;
z_stream strm = {0};
file_data* src_fd = *fd;
file_data* dest_fd = NULL;
srcLen = src_fd->length;
memcpy(&dstLen,&(src_fd->data[src_fd->length-4]),4);
dest_fd = malloc(sizeof(file_data));
dest_fd->length = dstLen;
dest_fd->name = calloc(strlen(src_fd->name)+1,sizeof(char));
strcpy(dest_fd->name,src_fd->name);
dest_fd->data = malloc(dstLen * sizeof(char));
strm.total_in = strm.avail_in = srcLen;
strm.total_out = strm.avail_out = dstLen;
strm.next_in = (Bytef *) src_fd->data;
strm.next_out = (Bytef *) dest_fd->data;
srcLen = src_fd->length;
memcpy(&dstLen,&(src_fd->data[src_fd->length-4]),4);
dest_fd = malloc(sizeof(file_data));
dest_fd->length = dstLen;
dest_fd->name = calloc(strlen(src_fd->name)+1,sizeof(char));
strcpy(dest_fd->name,src_fd->name);
dest_fd->data = malloc(dstLen * sizeof(char));
strm.total_in = strm.avail_in = srcLen;
strm.total_out = strm.avail_out = dstLen;
strm.next_in = (Bytef *) src_fd->data;
strm.next_out = (Bytef *) dest_fd->data;
strm.zalloc = Z_NULL;
strm.zfree = Z_NULL;
strm.opaque = Z_NULL;
strm.zalloc = Z_NULL;
strm.zfree = Z_NULL;
strm.opaque = Z_NULL;
err = inflateInit2(&strm, (15 + 32)); //15 window bits, and the +32 tells zlib to to detect if using gzip or zlib
if (err == Z_OK)
{
err = inflate(&strm, Z_FINISH);
if (err != Z_STREAM_END)
{
inflateEnd(&strm);
return false;
}
}
else
{
inflateEnd(&strm);
return false;
}
inflateEnd(&strm);
free(src_fd->data);
free(src_fd->name);
free(src_fd);
*fd = dest_fd;
return true;
err = inflateInit2(&strm, (15 + 32)); //15 window bits, and the +32 tells zlib to to detect if using gzip or zlib
if (err == Z_OK)
{
err = inflate(&strm, Z_FINISH);
if (err != Z_STREAM_END)
{
inflateEnd(&strm);
return false;
}
}
else
{
inflateEnd(&strm);
return false;
}
inflateEnd(&strm);
free(src_fd->data);
free(src_fd->name);
free(src_fd);
*fd = dest_fd;
return true;
}
static bool get_files_from_zip(const char *path, file_data ***dest_files, int *dest_numfiles)
{
unzFile uf = NULL;
unz_global_info64 gi;
unz_file_info64 file_info;
int i;
char filename_inzip[256];
char *ext;
file_data **files;
int numfiles,position;
unzFile uf = NULL;
unz_global_info64 gi;
unz_file_info64 file_info;
int i;
char filename_inzip[256];
char *ext;
file_data **files;
int numfiles,position;
//load zip content
uf = unzOpen64(path);
unzGetGlobalInfo64(uf,&gi);
numfiles = (int)gi.number_entry;
files = malloc(sizeof(file_data*) * numfiles);
position = 0;
for(i=0;i<gi.number_entry;i++)
{
void* buf;
int err;
int bytes_read;
uInt size_buf = 8192;
//read compressed file info
err = unzGetCurrentFileInfo64(uf,&file_info,filename_inzip,sizeof(filename_inzip),NULL,0,NULL,0);
if(err!=UNZ_OK)
{
//load zip content
uf = unzOpen64(path);
unzGetGlobalInfo64(uf,&gi);
numfiles = (int)gi.number_entry;
files = malloc(sizeof(file_data*) * numfiles);
position = 0;
for(i=0;i<gi.number_entry;i++)
{
void* buf;
int err;
int bytes_read;
uInt size_buf = 8192;
//read compressed file info
err = unzGetCurrentFileInfo64(uf,&file_info,filename_inzip,sizeof(filename_inzip),NULL,0,NULL,0);
if(err!=UNZ_OK)
{
return false;
}
if(filename_inzip[file_info.size_filename -1]=='/')
ext = strrchr(filename_inzip,'/');
else
ext = strrchr(filename_inzip,'.') + 1;
if(is_gme_allowed_ext(ext))
{
//get file name in zip
files[position] = malloc(sizeof(file_data));
files[position]->name = calloc(strlen(filename_inzip)+1,sizeof(char));
strcpy(files[position]->name,filename_inzip);
//allocate uncompressed data buffer
files[position]->length= sizeof(char) * file_info.uncompressed_size;
files[position]->data = (char*)malloc(files[position]->length);
//setup buffer
bytes_read = 0;
buf = (void*)malloc(size_buf);
if (buf==NULL)
return false;
}
if(filename_inzip[file_info.size_filename -1]=='/')
ext = strrchr(filename_inzip,'/');
else
ext = strrchr(filename_inzip,'.') + 1;
if(is_gme_allowed_ext(ext))
{
//get file name in zip
files[position] = malloc(sizeof(file_data));
files[position]->name = calloc(strlen(filename_inzip)+1,sizeof(char));
strcpy(files[position]->name,filename_inzip);
//allocate uncompressed data buffer
files[position]->length= sizeof(char) * file_info.uncompressed_size;
files[position]->data = (char*)malloc(files[position]->length);
//setup buffer
bytes_read = 0;
buf = (void*)malloc(size_buf);
if (buf==NULL)
return false;
//read file from zip
err = unzOpenCurrentFilePassword(uf,NULL);
if (err!=UNZ_OK)
return false;
//get data from zip
do
//read file from zip
err = unzOpenCurrentFilePassword(uf,NULL);
if (err!=UNZ_OK)
return false;
//get data from zip
do
{
err = unzReadCurrentFile(uf,buf,size_buf);
if(err<0)
return false;
if(err>0)
{
err = unzReadCurrentFile(uf,buf,size_buf);
if(err<0)
return false;
if(err>0)
{
memcpy(files[position]->data + bytes_read,buf,err * sizeof(char));
bytes_read += err;
}
} while (err>0);
if(buf!=NULL)
free(buf);
memcpy(files[position]->data + bytes_read,buf,err * sizeof(char));
bytes_read += err;
}
} while (err>0);
if(buf!=NULL)
free(buf);
if(strcmp(ext,"vgz")==0)
if(!uncompress_file_data(&(files[position])))
return false;
position++;
}
else
{
numfiles--;
}
if ((i+1)<gi.number_entry)
unzGoToNextFile(uf);
}
files = realloc(files,sizeof(file_data*) * numfiles);
*dest_files = files;
*dest_numfiles = numfiles;
return true;
if(strcmp(ext,"vgz")==0)
if(!uncompress_file_data(&(files[position])))
return false;
position++;
}
else
{
numfiles--;
}
if ((i+1)<gi.number_entry)
unzGoToNextFile(uf);
}
files = realloc(files,sizeof(file_data*) * numfiles);
*dest_files = files;
*dest_numfiles = numfiles;
return true;
}
bool get_file_data(const char *path,file_data ***dest_files, int *dest_numfiles)
{
//local variables
FILE *fp;
const char *bname;
char *ext;
file_data **files;
//get file name and extension
bname = path_basename(path);
ext = strrchr(path,'.') +1;
//get file data
if(strcmp(ext,"zip")==0)
{
return get_files_from_zip(path,dest_files,dest_numfiles);
}
else
{
file_data *fd;
fp = fopen(path,"rb");
if (!fp)
return false;
files = malloc(sizeof(file_data*));
fd = malloc(sizeof(file_data));
//get file length
fseek (fp,0,SEEK_END);
fd->length = ftell(fp);
rewind(fp);
//get file data
fd->data = malloc(sizeof(char)*fd->length);
fread(fd->data,1,fd->length,fp);
fclose(fp);
fd->name = calloc(strlen(bname)+1,sizeof(char));
strcpy(fd->name,bname);
if(strcmp(ext,"vgz")==0)
{
if(!uncompress_file_data(&fd))
return false;
}
files[0] = fd;
*dest_files = files;
*dest_numfiles = 1;
return true;
}
//local variables
FILE *fp;
file_data *fd;
file_data **files;
//get file name and extension
const char *bname = path_basename(path);
char *ext = strrchr(path,'.') +1;
//get file data
if(strcmp(ext,"zip")==0)
return get_files_from_zip(path,dest_files,dest_numfiles);
if (!(fp = fopen(path,"rb")))
return false;
files = malloc(sizeof(file_data*));
fd = malloc(sizeof(file_data));
//get file length
fseek (fp,0,SEEK_END);
fd->length = ftell(fp);
rewind(fp);
//get file data
fd->data = malloc(sizeof(char)*fd->length);
fread(fd->data,1,fd->length,fp);
fclose(fp);
fd->name = calloc(strlen(bname)+1,sizeof(char));
strcpy(fd->name,bname);
if(strcmp(ext,"vgz")==0)
{
if(!uncompress_file_data(&fd))
return false;
}
files[0] = fd;
*dest_files = files;
*dest_numfiles = 1;
return true;
}
#ifndef GME_LIBRETRO_FILEFORMAT_H__
#define GME_LIBRETRO_FILEFORMAT_H__
typedef struct {
char* name;
char* data;
int length;
typedef struct
{
char* name;
char* data;
int length;
} file_data;
bool get_file_data(const char *path,file_data ***files, int *dest_numfiles);
#endif
\ No newline at end of file
#endif
......@@ -6,34 +6,37 @@
unsigned short get_color(char r, char g, char b)
{
unsigned short color= (r << 11) | (g << 5) | b;
return color;
unsigned short color= (r << 11) | (g << 5) | b;
return color;
}
surface *create_surface(unsigned int width, unsigned int height, unsigned int bpp)
{
surface *newsurf = malloc(sizeof(surface));
if(newsurf==NULL)
return NULL;
newsurf->pixel_data = malloc(width*height*bpp);
if(newsurf->pixel_data==NULL)
surface *newsurf = malloc(sizeof(surface));
if (!newsurf)
return NULL;
newsurf->pixel_data = malloc(width*height*bpp);
if (!newsurf->pixel_data)
{
free(newsurf);
return NULL;
}
memset(newsurf->pixel_data,0,width*height*bpp);
newsurf->width = width;
newsurf->height = height;
newsurf->bytes_per_pixel = bpp;
return newsurf;
memset(newsurf->pixel_data,0,width*height*bpp);
newsurf->width = width;
newsurf->height = height;
newsurf->bytes_per_pixel = bpp;
return newsurf;
}
void free_surface(surface *surf)
{
if(surf != NULL) {
free(surf->pixel_data);
free(surf);
}
if (surf)
{
free(surf->pixel_data);
free(surf);
}
}
surface *clip_surface(surface *src_surf, int x_src, int y_src, int x0, int y0, int x1, int y1)
......@@ -42,16 +45,19 @@ surface *clip_surface(surface *src_surf, int x_src, int y_src, int x0, int y0, i
int lx,ly,lw,lh; //local coord
surface *clipped_surf = NULL;
//check if completely out of bounds
if( (x_src+src_surf->width) <x0 || x_src > x1 || (y_src+src_surf->height) < y0 || y_src > y1)
if( (x_src+src_surf->width) <x0
|| (x_src > x1)
|| (y_src+src_surf->height) < y0
|| (y_src > y1))
return clipped_surf;
wx0 = MAX(x_src,x0);
wy0 = MAX(y_src,y0);
wx1 = MIN(x_src+src_surf->width,x1);
wy1 = MIN(y_src+src_surf->height,y1);
lx = wx0 - x_src;
ly = wy0 - y_src;
lw = wx1 - wx0;
lh = wy1 - wy0;
wx0 = MAX(x_src,x0);
wy0 = MAX(y_src,y0);
wx1 = MIN(x_src+src_surf->width,x1);
wy1 = MIN(y_src+src_surf->height,y1);
lx = wx0 - x_src;
ly = wy0 - y_src;
lw = wx1 - wx0;
lh = wy1 - wy0;
clipped_surf = create_surface(lw, lh,2);
copy_surface(src_surf,clipped_surf,lx,ly,0,0,lw,lh);
return clipped_surf;
......@@ -73,34 +79,35 @@ void copy_surface(surface *src_surf, surface *dst_surf, int x_src, int y_src, in
void draw_line(surface *surf, unsigned short color, int start_x, int start_y, int end_x, int end_y)
{
if(start_x==end_x) //vertical line
{
if(start_x==end_x) //vertical line
{
int y;
for(y=start_y;y<=end_y;y++)
set_pixel(surf,start_x,y,color);
}
else if(start_y==end_y) // horizontal line
for(y=start_y;y<=end_y;y++)
set_pixel(surf,start_x,y,color);
}
else if(start_y==end_y) // horizontal line
{
int x;
for(x=start_x;x<=end_x;x++)
set_pixel(surf,x,start_y,color) = color;
}
else
{
// Bresenham line algorithm, copied from https://rosettacode.org/wiki/Bitmap/Bresenham%27s_line_algorithm#C
int x = start_x, y = start_y;
int dx = abs(end_x-start_x), sx = start_x<end_x ? 1 : -1;
int dy = abs(end_y-start_y), sy = start_y<end_y ? 1 : -1;
int err = (dx>dy ? dx : -dy)/2, e2;
for(;;)
else
{
// Bresenham line algorithm, copied from https://rosettacode.org/wiki/Bitmap/Bresenham%27s_line_algorithm#C
int x = start_x, y = start_y;
int dx = abs(end_x-start_x), sx = start_x<end_x ? 1 : -1;
int dy = abs(end_y-start_y), sy = start_y<end_y ? 1 : -1;
int err = (dx>dy ? dx : -dy)/2, e2;
for(;;)
{
set_pixel(surf,x,y,color);
if (x==end_x && y==end_y) break;
if (x==end_x && y==end_y)
break;
e2 = err;
if (e2 >-dx) { err -= dy; x += sx; }
if (e2 < dy) { err += dx; y += sy; }
}
}
}
}
void draw_box(surface *surf, unsigned short color, int x0, int y0, int x1, int y1)
......@@ -124,13 +131,10 @@ void draw_shape(surface *surf, unsigned short color, int pos_x, int pos_y, int w
void draw_letter(surface *surf, unsigned short color, char letter, int pos_x, int pos_y)
{
int y, x;
int charx = 0;
int chary = 0;
//calculate letter offset
charx = (letter % 16);
chary = (letter >> 4);
charx *= 8;
chary *= 8;
int charx = (letter % 16) * 8;
int chary = (letter >> 4) * 8;
for(y=0;y<8;y++)
{
for(x=0;x<8;x++)
......@@ -158,15 +162,16 @@ void draw_string(surface *surf, unsigned short color, char* text, int pos_x, int
if((msglen*8)>280)
{
delta = (msglen*8) -280;
modulo = delta + (delay * 2);
delta = (msglen*8) -280;
modulo = delta + (delay * 2);
x_offset = (modulo - abs(framecounter/frame_delay % (2*modulo) - modulo)) - delay; // triangle function
x_offset = MAX(x_offset,0); //clamp left to add delay
x_offset = MIN(x_offset,delta); //clamp right to add delay
}
clipped_surface = clip_surface(temp_surface,pos_x-x_offset,pos_y,21,21,299,219);
if(clipped_surface !=NULL)
if (clipped_surface)
{
copy_surface(clipped_surface,surf,0,0,pos_x,pos_y,clipped_surface->width,clipped_surface->height);
free_surface(clipped_surface);
......
......@@ -8,11 +8,12 @@
#define get_pixel(surf,x,y) ((unsigned short *)surf->pixel_data)[(x)+((y)*surf->width)]
#define is_font_pixel(x,y) (((unsigned short *)font.pixel_data)[(x)+((y)*font.width)] == 0 ? 1 : 0)
typedef struct {
unsigned int width;
unsigned int height;
unsigned int bytes_per_pixel; /* 2:RGB16, 3:RGB, 4:RGBA */
char *pixel_data;
typedef struct
{
unsigned int width;
unsigned int height;
unsigned int bytes_per_pixel; /* 2:RGB16, 3:RGB, 4:RGBA */
char *pixel_data;
} surface;
unsigned short get_color(char r, char g, char b);
......@@ -26,8 +27,6 @@ void draw_letter(surface *surf, unsigned short color, char letter, int pos_x, in
void draw_string(surface *surf, unsigned short color, char* text, int pos_x, int pos_y, unsigned int framecounter);
int get_string_length(char* text);
/* GIMP RGBA C-Source image dump (font.c) */
static const surface font = {
128, 128, 2,
......
......@@ -178,8 +178,7 @@ bool retro_load_game(const struct retro_game_info *info)
if(open_file(info->path,sample_rate))
return true;
else
return false;
return false;
}
bool retro_load_game_special(unsigned game_type, const struct retro_game_info *info, size_t num_info)
......@@ -191,5 +190,3 @@ void retro_unload_game(void)
{
close_file();
}
......@@ -9,27 +9,29 @@ static retro_log_printf_t log_cb;
void init_log(retro_environment_t environ_cb)
{
struct retro_log_callback log;
if (environ_cb(RETRO_ENVIRONMENT_GET_LOG_INTERFACE, &log))
struct retro_log_callback log;
if (environ_cb(RETRO_ENVIRONMENT_GET_LOG_INTERFACE, &log))
log_cb = log.log;
else
else
log_cb = NULL;
}
void handle_error( const char* error )
{
char str [256];
if(error) {
sprintf( str, "Error: %s", error );
log_cb(RETRO_LOG_ERROR, str );
}
char str [256];
if(error)
{
sprintf( str, "Error: %s", error );
log_cb(RETRO_LOG_ERROR, str );
}