Commit 81e2edc2 authored by Libretro-Admin's avatar Libretro-Admin
Browse files

Cleanups

parent 1c190bf1
Pipeline #64788 passed with stages
in 1 minute and 34 seconds
#include "IPS.h"
#include <stdio.h>
#include <string.h>
#if defined(ANDROID)
#include "MemFS.h"
#define fopen mopen
#define fclose mclose
#define fread mread
#define fseek mseek
#elif defined(ZLIB)
#include <zlib.h>
#define fopen(F,M) (FILE *)gzopen(F,M)
#define fclose(F) gzclose((gzFile)(F))
#define fread(B,N,L,F) gzread((gzFile)(F),B,(L)*(N))
#define fseek(F,N,W) (gzseek((gzFile)(F),N,W)<0? -1:0)
#endif
/** MeasureIPS() *********************************************/
/** Find total data size assumed by a given .IPS file. **/
/*************************************************************/
unsigned int MeasureIPS(const char *FileName)
{
return(ApplyIPS(FileName,0,0));
}
/** ApplyIPS() ***********************************************/
/** Loads patches from an .IPS file and applies them to the **/
/** given data buffer. Returns number of patches applied. **/
/*************************************************************/
unsigned int ApplyIPS(const char *FileName,unsigned char *Data,unsigned int Size)
{
unsigned char Buf[16];
unsigned int Result,Count,J,N;
FILE *F;
F = fopen(FileName,"rb");
if(!F) return(0);
/* Verify file header */
if(fread(Buf,1,5,F)!=5) { fclose(F);return(0); }
if(memcmp(Buf,"PATCH",5)) { fclose(F);return(0); }
for(Result=0,Count=1;fread(Buf,1,5,F)==5;++Count)
{
J = Buf[2]+((unsigned int)Buf[1]<<8)+((unsigned int)Buf[0]<<16);
N = Buf[4]+((unsigned int)Buf[3]<<8);
/* Apparently, these may signal the end of .IPS file */
if((J==0xFFFFFF) || !memcmp(Buf,"EOF",3)) break;
/* If patching with a block of data... */
if(N)
{
/* Copying data */
if(!Data)
{
/* Just measuring patch size */
if(Result<J+N) Result=J+N;
if(fseek(F,N,SEEK_CUR)<0) break;
}
else if(J+N>Size)
{
printf("IPS: Failed applying COPY patch #%d to 0x%X..0x%X of 0x%X bytes.\n",Count,J,J+N-1,Size);
if(fseek(F,N,SEEK_CUR)<0) break;
}
else if(fread(Data+J,1,N,F)==N)
{
// printf("IPS: Applied COPY patch #%d to 0x%X..0x%X.\n",Count,J,J+N-1);
++Result;
}
else
{
printf("IPS: Failed reading COPY patch #%d from the file.\n",Count);
break;
}
}
else
{
/* Filling with a value */
if(fread(Buf,1,3,F)!=3)
{
if(Data) printf("IPS: Failed reading FILL patch #%d from the file.\n",Count);
break;
}
/* Compute fill length */
N = ((unsigned int)Buf[0]<<8)+Buf[1];
if(!Data)
{
if(Result<J+N) Result=J+N;
}
else if(!N || (J+N>Size))
{
printf("IPS: Failed applying FILL patch #%d (0x%02X) to 0x%X..0x%X of 0x%X bytes.\n",Count,Buf[1],J,J+N-1,Size);
}
else
{
// printf("IPS: Applied FILL patch #%d (0x%02X) to 0x%X..0x%X.\n",Count,Buf[1],J,J+N-1);
memset(Data+J,Buf[2],N);
++Result;
}
}
}
fclose(F);
return(Result);
}
#if defined(ZLIB) || defined(ANDROID)
#undef fopen
#undef fclose
#undef fread
#undef fseek
#endif
#ifndef IPS_H
#define IPS_H
/** ApplyIPS() ***********************************************/
/** Loads patches from an .IPS file and applies them to the **/
/** given data buffer. Returns number of patches applied. **/
/*************************************************************/
unsigned int ApplyIPS(const char *FileName,unsigned char *Data,unsigned int Size);
/** MeasureIPS() *********************************************/
/** Find total data size assumed by a given .IPS file. **/
/*************************************************************/
unsigned int MeasureIPS(const char *FileName);
#endif /* IPS_H */
This diff is collapsed.
/** EMULib Emulation Library *********************************/
/** **/
/** Touch.h **/
/** **/
/** This file declares functions that simulate joystick and **/
/** dialpad with the touch screen. **/
/** **/
/** Copyright (C) Marat Fayzullin 2008-2014 **/
/** You are not allowed to distribute this software **/
/** commercially. Please, notify me, if you make any **/
/** changes to this file. **/
/*************************************************************/
#ifndef TOUCH_H
#define TOUCH_H
#include "EMULib.h"
/* SetFinButton() special mask bits **************************/
#define BTN_INVISIBLE 0x80000000
/* GenericPenDialpad() result ********************************/
#define DIAL_NONE 0 /* No dialpad buttons pressed */
#define DIAL_1 1
#define DIAL_2 2
#define DIAL_3 3
#define DIAL_4 4
#define DIAL_5 5
#define DIAL_6 6
#define DIAL_7 7
#define DIAL_8 8
#define DIAL_9 9
#define DIAL_STAR 10
#define DIAL_0 11
#define DIAL_POUND 12
#ifdef __cplusplus
extern "C" {
#endif
/** RenderVideo() ********************************************/
/** Draw video buffer to a given image. Return 0 on failure **/
/** or destination rectangle size inside OutImg on success. **/
/*************************************************************/
unsigned int RenderVideo(Image *OutImg,Image *CueImg,int Effects,int PenKey,int FrameRate);
/** GenericFullJoystick() ************************************/
/** Treat whole screen as one big directional pad. Result **/
/** compatible with GetJoystick() (arrows only though). **/
/*************************************************************/
unsigned int GenericFullJoystick(int X,int Y,int W,int H);
/** GenericPenJoystick() *************************************/
/** Get simulated joystick buttons from touch screen UI. **/
/** Result compatible with GetJoystick(). **/
/*************************************************************/
unsigned int GenericPenJoystick(int X,int Y,int W,int H);
/** GenericPenDialpad() **************************************/
/** Get simulated dialpad buttons from touch screen UI. **/
/*************************************************************/
unsigned char GenericPenDialpad(int X,int Y,int W,int H);
/** GenericPenKeyboard() *************************************/
/** Get virtual on-screen keyboard buttons. **/
/*************************************************************/
unsigned char GenericPenKeyboard(int X,int Y,int W,int H);
/** GenericDialKeyboard() ************************************/
/** Process dialpad input to the virtual keyboard. Returns **/
/** virtual keyboard key if selected, or 0 if not. **/
/*************************************************************/
unsigned char GenericDialKeyboard(unsigned char Key);
/** GenericFinJoystick() *************************************/
/** Return the BTN_* bits corresponding to position X,Y of **/
/** the finger joystick shown in Dst. **/
/*************************************************************/
unsigned int GenericFinJoystick(int X,int Y,int W,int H,unsigned int CurState);
/** SetPenCues() *********************************************/
/** Set pen cues for given buttons to a given string. **/
/*************************************************************/
void SetPenCues(unsigned int Buttons,const char *CueText);
/** SetPenKeyboard() *****************************************/
/** Set pen keyboard dimensions. **/
/*************************************************************/
void SetPenKeyboard(unsigned int KeyStep,unsigned int KeySize,unsigned int ChrSize);
/** InitFinJoystick() ****************************************/
/** Initialize finger joystick images by cropping them from **/
/** the given source image. Returns number of buttons set **/
/** successfully (i.e. found inside the Src bounds). **/
/*************************************************************/
int InitFinJoystick(const Image *Src);
/** SetFinButton() *******************************************/
/** Set finger joystick button(s) to given location. When **/
/** Img=0, create wireframe buttons. When Mask=0, set the **/
/** directional buttons image and location. When Mask ORed **/
/** withBTN_INVISIBLE, create invisible buttons. Returns **/
/** the number of virtual buttons set or 0 for none. **/
/*************************************************************/
int SetFinButton(unsigned int Mask,const Image *Src,int X,int Y,int W,int H);
/** DrawPenCues() ********************************************/
/** Overlay dotted cue lines for using PenJoystick() onto a **/
/** given image. Show dialpad cues if requested. **/
/*************************************************************/
void DrawPenCues(Image *Img,int ShowDialpad,int Color);
/** DrawDialpad() ********************************************/
/** Draw virtual dialpad in a given image. **/
/*************************************************************/
void DrawDialpad(Image *Img,int Color);
/** DrawKeyboard() *******************************************/
/** Draw virtual keyboard in a given image. Key modifiers **/
/** and the key code passed in CurKey are highlighted. **/
/*************************************************************/
void DrawKeyboard(Image *Img,unsigned int CurKey);
/** DrawFinJoystick() ****************************************/
/** Draw finger joystick into given destination image. When **/
/** DW=0 or DWH=0, the whole image will be updated. When **/
/** DWxDH+DX+DY represent a dirty rectangle inside Dst, the **/
/** function will only update joystick buttons overlapping **/
/** this rectangle, representing them with dotted lines. **/
/** Returns the number of buttons overlapping the dirty **/
/** rectangle. **/
/*************************************************************/
int DrawFinJoystick(Image *Dst,int DX,int DY,int DW,int DH,int TextColor);
/** GetKbdWidth()/GetKbdHeight() *****************************/
/** Return virtual keyboard dimensions. **/
/*************************************************************/
unsigned int GetKbdWidth();
unsigned int GetKbdHeight();
#ifdef __cplusplus
}
#endif
#endif /* TOUCH_H */
/** EMULib Emulation Library *********************************/
/** **/
/** TouchMux.h **/
/** **/
/** This file wraps Touch.c routines for multiple display **/
/** depths (BPP8,BPP16,BPP32). It is used automatically **/
/** when none of BPP* values are defined. **/
/** **/
/** Copyright (C) Marat Fayzullin 2008-2014 **/
/** You are not allowed to distribute this software **/
/** commercially. Please, notify me, if you make any **/
/** changes to this file. **/
/*************************************************************/
#ifndef TOUCHMUX_H
#define TOUCHMUX_H
#include "EMULib.h"
#include "Touch.h"
#undef BPP8
#undef BPP16
#undef BPP24
#undef BPP32
#undef PIXEL
#define BPP8
#define pixel unsigned char
#define PIXEL(R,G,B) (pixel)(((7*(R)/255)<<5)|((7*(G)/255)<<2)|(3*(B)/255))
#define DrawHLine DrawHLine_8
#define DrawVLine DrawVLine_8
#define DrawPenCues DrawPenCues_8
#define DrawDialpad DrawDialpad_8
#define DrawKeyboard DrawKeyboard_8
#define DrawFinJoystick DrawFinJoystick_8
#define RenderVideo RenderVideo_8
#define PrintXY PrintXY_8
#define PrintXY2 PrintXY2_8
#include "Touch.c"
#undef pixel
#undef PIXEL
#undef DrawHLine
#undef DrawVLine
#undef DrawPenCues
#undef DrawDialpad
#undef DrawKeyboard
#undef DrawFinJoystick
#undef RenderVideo
#undef PrintXY
#undef PrintXY2
#undef BPP8
#define BPP16
#define pixel unsigned short
#if defined(UNIX) || defined(ANDROID) || defined(S60) || defined(UIQ) || defined(NXC2600) || defined(STMP3700)
/* Symbian and Unix use true 16BPP color */
#define PIXEL(R,G,B) (pixel)(((31*(R)/255)<<11)|((63*(G)/255)<<5)|(31*(B)/255))
#else
/* Other platforms use 15BPP color */
#define PIXEL(R,G,B) (pixel)(((31*(R)/255)<<10)|((31*(G)/255)<<5)|(31*(B)/255))
#endif
#define DrawHLine DrawHLine_16
#define DrawVLine DrawVLine_16
#define DrawPenCues DrawPenCues_16
#define DrawDialpad DrawDialpad_16
#define DrawKeyboard DrawKeyboard_16
#define DrawFinJoystick DrawFinJoystick_16
#define RenderVideo RenderVideo_16
#define PrintXY PrintXY_16
#define PrintXY2 PrintXY2_16
#include "Touch.c"
#undef pixel
#undef PIXEL
#undef DrawHLine
#undef DrawVLine
#undef DrawPenCues
#undef DrawDialpad
#undef DrawKeyboard
#undef DrawFinJoystick
#undef RenderVideo
#undef PrintXY
#undef PrintXY2
#undef BPP16
#define BPP32
#define pixel unsigned int
#if defined(ANDROID)
#define PIXEL(R,G,B) (pixel)(((int)R<<16)|((int)G<<8)|B|0xFF000000)
#else
#define PIXEL(R,G,B) (pixel)(((int)R<<16)|((int)G<<8)|B)
#endif
#define DrawHLine DrawHLine_32
#define DrawVLine DrawVLine_32
#define DrawPenCues DrawPenCues_32
#define DrawDialpad DrawDialpad_32
#define DrawKeyboard DrawKeyboard_32
#define DrawFinJoystick DrawFinJoystick_32
#define RenderVideo RenderVideo_32
#define PrintXY PrintXY_32
#define PrintXY2 PrintXY2_32
#include "Touch.c"
#undef pixel
#undef PIXEL
#undef DrawHLine
#undef DrawVLine
#undef DrawPenCues
#undef DrawDialpad
#undef DrawKeyboard
#undef DrawFinJoystick
#undef RenderVideo
#undef PrintXY
#undef PrintXY2
#undef BPP32
/** DrawPenCues() ********************************************/
/** Overlay dotted cue lines for using PenJoystick() onto a **/
/** given image. Show dialpad cues if requested. **/
/*************************************************************/
void DrawPenCues(Image *Img,int ShowDialpad,int Color)
{
switch(Img->D)
{
case 8: DrawPenCues_8(Img,ShowDialpad,Color);break;
case 16: DrawPenCues_16(Img,ShowDialpad,Color);break;
case 24:
case 32: DrawPenCues_32(Img,ShowDialpad,Color);break;
}
}
/** DrawDialpad() ********************************************/
/** Draw virtual dialpad in a given image. **/
/*************************************************************/
void DrawDialpad(Image *Img,int Color)
{
switch(Img->D)
{
case 8: DrawDialpad_8(Img,Color);break;
case 16: DrawDialpad_16(Img,Color);break;
case 24:
case 32: DrawDialpad_32(Img,Color);break;
}
}
/** DrawKeyboard() *******************************************/
/** Draw virtual keyboard in a given image. Key modifiers **/
/** and the key code passed in CurKey are highlighted. **/
/*************************************************************/
void DrawKeyboard(Image *Img,unsigned int CurKey)
{
switch(Img->D)
{
case 8: DrawKeyboard_8(Img,CurKey);break;
case 16: DrawKeyboard_16(Img,CurKey);break;
case 24:
case 32: DrawKeyboard_32(Img,CurKey);break;
}
}
/** DrawFinJoystick() ****************************************/
/** Draw finger joystick into given destination image. If **/
/** the destination if too small, this function returns 0, **/
/** it returns 1 otherwise. **/
/*************************************************************/
int DrawFinJoystick(Image *Dst,int DX,int DY,int DW,int DH,int TextColor)
{
switch(Dst->D)
{
case 8: return(DrawFinJoystick_8(Dst,DX,DY,DW,DH,TextColor));
case 16: return(DrawFinJoystick_16(Dst,DX,DY,DW,DH,TextColor));
case 24:
case 32: return(DrawFinJoystick_32(Dst,DX,DY,DW,DH,TextColor));
}
/* Wrong depth */
return(0);
}
/** RenderVideo() ********************************************/
/** Draw video buffer to a given image. Return 0 on failure **/
/** or destination rectangle size inside OutImg on success. **/
/*************************************************************/
unsigned int RenderVideo(Image *OutImg,Image *CueImg,int Effects,int PenKey,int FrameRate)
{
int D = OutImg? OutImg->D:VideoImg? VideoImg->D:0;
/* Check that the depths are the same */
if(CueImg && (D!=CueImg->D)) return(0);
switch(D)
{
case 8: return(RenderVideo_8(OutImg,CueImg,Effects,PenKey,FrameRate));
case 16: return(RenderVideo_16(OutImg,CueImg,Effects,PenKey,FrameRate));
case 24:
case 32: return(RenderVideo_32(OutImg,CueImg,Effects,PenKey,FrameRate));
}
/* Wrong depth */
return(0);
}
#endif /* TOUCHMUX_H */
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment