1 // FinalBurn Neo - Emulator for MC68000/Z80 based arcade games
2 //            Refer to the "license.txt" file for more info
3 #pragma once
4 #include <limits.h>
5 #include <stdarg.h>
6 #include <stdio.h>
7 #include <stdlib.h>
8 #include <string.h>
9 #include <math.h>
10 #include <assert.h>
11 #include <ctype.h>
12 
13 #include "tchar.h"
14 
15 // Macro to make quoted strings
16 #define MAKE_STRING_2(s) #s
17 #define MAKE_STRING(s) MAKE_STRING_2(s)
18 
19 #define BZIP_MAX (20)								// Maximum zip files to search through
20 #if defined (BUILD_QT)
21  #define DIRS_MAX (4)								// Maximum number of directories to search
22 #else
23  #define DIRS_MAX (20)								// Maximum number of directories to search
24 #endif
25 
26 #include "title.h"
27 #include "burn.h"
28 
29 // ---------------------------------------------------------------------------
30 // OS dependent functionality
31 typedef struct tagIMAGE {
32 	unsigned int	width;
33 	unsigned int	height;
34 	unsigned int	rowbytes;
35 	unsigned int	imgbytes;
36 	unsigned char**	rowptr;
37 	unsigned char*	bmpbits;
38 	unsigned int	flags;
39 } IMAGE;
40 
41 #if defined (BUILD_WIN32)
42  #include "burner_win32.h"
43 #elif defined (BUILD_MACOS)
44  #include "burner_macos.h"
45 #elif defined (BUILD_SDL) || defined (BUILD_SDL2)
46  #include "burner_sdl.h"
47 #elif defined (_XBOX) && !defined(__LIBRETRO__)
48  #include "burner_xbox.h"
49 #elif defined(__LIBRETRO__)
50 #include "burner_libretro.h"
51 #elif defined(BUILD_QT)
52  #include "burner_qt.h"
53 #endif
54 
55 #if defined (INCLUDE_LIB_PNGH)
56  #include "png.h"
57 #endif
58 
59 // ---------------------------------------------------------------------------
60 // OS independent functionality
61 
62 #ifndef __LIBRETRO__
63 #include "interface.h"
64 #endif
65 
66 #if defined (INCLUDE_LUA_SUPPORT) || defined (BUILD_WIN32)
67 #include "luaengine.h"
68 #endif
69 
70 #define IMG_FREE		(1 << 0)
71 
72 // Macros for parsing text
73 #define SKIP_WS(s) while (_istspace(*s)) { s++; }			// Skip whitespace
74 #define FIND_WS(s) while (*s && !_istspace(*s)) { s++; }	// Find whitespace
75 #define FIND_QT(s) while (*s && *s != _T('\"')) { s++; }	// Find quote
76 
77 // image.cpp
78 extern int bPngImageOrientation;
79 void img_free(IMAGE* img);
80 INT32 img_alloc(IMAGE* img);
81 
82 bool PNGIsImage(FILE* fp);
83 bool PNGIsImageBuffer(unsigned char* buffer, int bufferLength);
84 INT32 PNGLoad(IMAGE* img, FILE* fp, INT32 nPreset);
85 INT32 PNGLoadBuffer(IMAGE* img, unsigned char* buffer, int bufferLength, INT32 nPreset);
86 INT32 PNGGetInfo(IMAGE* img, FILE *fp);
87 INT32 PNGGetInfoBuffer(IMAGE* img, unsigned char* buffer, int bufferLength);
88 
89 // gami.cpp
90 extern struct GameInp* GameInp;
91 extern UINT32 nGameInpCount;
92 extern UINT32 nMacroCount;
93 extern UINT32 nMaxMacro;
94 
95 extern INT32 nAnalogSpeed;
96 
97 extern INT32 nFireButtons;
98 
99 extern bool bStreetFighterLayout;
100 extern bool bLeftAltkeyMapped;
101 
102 INT32 GameInpInit();
103 INT32 GameInpExit();
104 TCHAR* InputCodeDesc(INT32 c);
105 TCHAR* InpToDesc(struct GameInp* pgi);
106 TCHAR* InpMacroToDesc(struct GameInp* pgi);
107 TCHAR* InputNumToName(UINT32 i);
108 TCHAR* InpToString(struct GameInp* pgi);
109 TCHAR* InpMacroToString(struct GameInp* pgi);
110 #ifndef __LIBRETRO__
111 void GameInpCheckLeftAlt();
112 void GameInpCheckMouse();
113 #endif
114 INT32 GameInpBlank(INT32 bDipSwitch);
115 INT32 GameInputAutoIni(INT32 nPlayer, TCHAR* lpszFile, bool bOverWrite);
116 INT32 ConfigGameLoadHardwareDefaults();
117 INT32 GameInpDefault();
118 INT32 GameInpWrite(FILE* h);
119 INT32 GameInpRead(TCHAR* szVal, bool bOverWrite);
120 INT32 GameInpMacroRead(TCHAR* szVal, bool bOverWrite);
121 INT32 GameMacroAutofireRead(TCHAR* szVal, bool bOverWrite);
122 INT32 GameInpCustomRead(TCHAR* szVal, bool bOverWrite);
123 
124 struct tIniStruct {
125 	TCHAR system[80];
126 	TCHAR ini[MAX_PATH];
127 	INT32 hw[8];
128 	char gameinfotoken[80];
129 };
130 
131 extern tIniStruct gamehw_cfg[];
132 
133 void GetHistoryDatHardwareToken(char *to_string);
134 
135 // inp_interface.cpp
136 extern INT32 nAutoFireRate;
137 
138 // Player Default Controls
139 extern INT32 nPlayerDefaultControls[8];
140 extern TCHAR szPlayerDefaultIni[5][MAX_PATH];
141 
142 // mappable System Macros for the Input Dialogue
143 extern UINT8 macroSystemPause;
144 extern UINT8 macroSystemFFWD;
145 extern UINT8 macroSystemFrame;
146 extern UINT8 macroSystemSaveState;
147 extern UINT8 macroSystemLoadState;
148 extern UINT8 macroSystemUNDOState;
149 extern UINT8 macroSystemLuaHotkey1;
150 extern UINT8 macroSystemLuaHotkey2;
151 extern UINT8 macroSystemLuaHotkey3;
152 extern UINT8 macroSystemLuaHotkey4;
153 extern UINT8 macroSystemLuaHotkey5;
154 extern UINT8 macroSystemLuaHotkey6;
155 extern UINT8 macroSystemLuaHotkey7;
156 extern UINT8 macroSystemLuaHotkey8;
157 extern UINT8 macroSystemLuaHotkey9;
158 
159 // scrn.cpp
160 extern void scrnSSUndo();
161 extern bool bHasFocus;
162 
163 // cong.cpp
164 extern const INT32 nConfigMinVersion;					// Minimum version of application for which input files are valid
165 extern bool bSaveInputs;
166 INT32 ConfigGameLoad(bool bOverWrite);				// char* lpszName = NULL
167 INT32 ConfigGameSave(bool bSave);
168 
169 // conc.cpp
170 INT32 ConfigCheatLoad();
171 
172 // gamc.cpp
173 INT32 GamcMisc(struct GameInp* pgi, char* szi, INT32 nPlayer);
174 INT32 GamcAnalogKey(struct GameInp* pgi, char* szi, INT32 nPlayer, INT32 nSlide);
175 INT32 GamcAnalogJoy(struct GameInp* pgi, char* szi, INT32 nPlayer, INT32 nJoy, INT32 nSlide);
176 INT32 GamcPlayer(struct GameInp* pgi, char* szi, INT32 nPlayer, INT32 nDevice);
177 INT32 GamcPlayerHotRod(struct GameInp* pgi, char* szi, INT32 nPlayer, INT32 nFlags, INT32 nSlide);
178 
179 // misc.cpp
180 #define QUOTE_MAX (128)															// Maximum length of "quoted strings"
181 INT32 QuoteRead(TCHAR** ppszQuote, TCHAR** ppszEnd, TCHAR* pszSrc);					// Read a quoted string from szSrc and poINT32 to the end
182 TCHAR* LabelCheck(TCHAR* s, TCHAR* pszLabel);
183 
184 TCHAR* ExtractFilename(TCHAR* fullname);
185 TCHAR* DriverToName(UINT32 nDrv);
186 UINT32 NameToDriver(TCHAR* szName);
187 TCHAR *StrReplace(TCHAR *str, TCHAR find, TCHAR replace);
188 TCHAR *StrLower(TCHAR *str);
189 TCHAR *FileExt(TCHAR *str);
190 bool IsFileExt(TCHAR *str, TCHAR *ext);
191 
192 extern INT32 bDoGamma;
193 extern INT32 bHardwareGammaOnly;
194 extern double nGamma;
195 
196 INT32 SetBurnHighCol(INT32 nDepth);
197 char* DecorateGameName(UINT32 nBurnDrv);
198 TCHAR* DecorateGenreInfo();
199 void ComputeGammaLUT();
200 
201 // dat.cpp
202 #define DAT_ARCADE_ONLY			0
203 #define DAT_MEGADRIVE_ONLY		1
204 #define DAT_PCENGINE_ONLY		2
205 #define DAT_TG16_ONLY			3
206 #define DAT_SGX_ONLY			4
207 #define DAT_SG1000_ONLY			5
208 #define DAT_COLECO_ONLY			6
209 #define DAT_MASTERSYSTEM_ONLY	7
210 #define DAT_GAMEGEAR_ONLY		8
211 #define DAT_MSX_ONLY			9
212 #define DAT_SPECTRUM_ONLY		10
213 #define DAT_NEOGEO_ONLY			11
214 #define DAT_NES_ONLY			12
215 #define DAT_FDS_ONLY			13
216 #define DAT_NGP_ONLY			14
217 #define DAT_CHANNELF_ONLY		15
218 
219 INT32 write_datfile(INT32 bType, FILE* fDat);
220 INT32 create_datfile(TCHAR* szFilename, INT32 bType);
221 
222 // sshot.cpp
223 INT32 MakeScreenShot();
224 
225 // state.cpp
226 INT32 BurnStateLoadEmbed(FILE* fp, INT32 nOffset, INT32 bAll, INT32 (*pLoadGame)());
227 INT32 BurnStateLoad(TCHAR* szName, INT32 bAll, INT32 (*pLoadGame)());
228 INT32 BurnStateSaveEmbed(FILE* fp, INT32 nOffset, INT32 bAll);
229 INT32 BurnStateSave(TCHAR* szName, INT32 bAll);
230 INT32 BurnStateUNDO(TCHAR* szName);
231 
232 // statec.cpp
233 INT32 BurnStateCompress(UINT8** pDef, INT32* pnDefLen, INT32 bAll);
234 INT32 BurnStateDecompress(UINT8* Def, INT32 nDefLen, INT32 bAll);
235 
236 // nvram.cpp
237 INT32 BurnNvramLoad(TCHAR* szName);
238 INT32 BurnNvramSave(TCHAR* szName);
239 
240 // zipfn.cpp
241 struct ZipEntry { char* szName;	UINT32 nLen; UINT32 nCrc; };
242 
243 INT32 ZipOpen(char* szZip);
244 INT32 ZipClose();
245 INT32 ZipGetList(struct ZipEntry** pList, INT32* pnListCount);
246 INT32 ZipLoadFile(UINT8* Dest, INT32 nLen, INT32* pnWrote, INT32 nEntry);
247 INT32 __cdecl ZipLoadOneFile(char* arcName, const char* fileName, void** Dest, INT32* pnWrote);
248 
249 // bzip.cpp
250 
251 #define BZIP_STATUS_OK		(0)
252 #define BZIP_STATUS_BADDATA	(1)
253 #define BZIP_STATUS_ERROR	(2)
254 
255 INT32 BzipOpen(bool);
256 INT32 BzipClose();
257 INT32 BzipInit();
258 INT32 BzipExit();
259 INT32 BzipStatus();
260 
261 // support_paths.cpp
262 extern TCHAR szAppPreviewsPath[MAX_PATH];
263 extern TCHAR szAppTitlesPath[MAX_PATH];
264 extern TCHAR szAppCheatsPath[MAX_PATH];
265 extern TCHAR szAppIpsPath[MAX_PATH];
266 extern TCHAR szAppIconsPath[MAX_PATH];
267 extern TCHAR szAppSelectPath[MAX_PATH];
268 extern TCHAR szAppVersusPath[MAX_PATH];
269 extern TCHAR szAppHowtoPath[MAX_PATH];
270 extern TCHAR szAppScoresPath[MAX_PATH];
271 extern TCHAR szAppBossesPath[MAX_PATH];
272 extern TCHAR szAppGameoverPath[MAX_PATH];
273 extern TCHAR szAppFlyersPath[MAX_PATH];
274 extern TCHAR szAppMarqueesPath[MAX_PATH];
275 extern TCHAR szAppControlsPath[MAX_PATH];
276 extern TCHAR szAppCabinetsPath[MAX_PATH];
277 extern TCHAR szAppPCBsPath[MAX_PATH];
278 extern TCHAR szAppHistoryPath[MAX_PATH];
279