1 // Driver Init module
2 #include "burner.h"
3 
4 int bDrvOkay = 0;						// 1 if the Driver has been initted okay, and it's okay to use the BurnDrv functions
5 
6 char szAppRomPaths[DIRS_MAX][MAX_PATH] = {{"ms0:/"},{"roms/"}, };
7 
8 static bool bSaveRAM = false;
9 
DoLibInit()10 static int DoLibInit()					// Do Init of Burn library driver
11 {
12 	int nRet;
13 
14 	BzipOpen(false);
15 
16 	// If there is an error with the romset, report it
17 	if (nBzipError) {
18 	/*	char *szTitle;
19 		int nIcon, nButton;
20 
21 		// Make the correct title and icon
22 		if (nBzipError & 1) {
23 			nIcon = MB_ICONERROR;
24 			szTitle = APP_TITLE " Error";
25 		} else {
26 			nIcon = MB_ICONWARNING;
27 			szTitle = APP_TITLE " Warning";
28 		}
29 
30 		if (nBzipError & 0x08) {
31 			nButton = MB_OK;		// no data at all - pretty basic!
32 		} else {
33 			BzipText.Add("\nWould you like more detailed information?\n(For experts only!)\n");
34 			nButton = MB_DEFBUTTON2 | MB_YESNO;
35 		}
36 
37 		// We can't use AppError, so use MessageBox directly
38 		if (MessageBox(hScrnWnd, BzipText.szText, szTitle, nButton | nIcon | MB_SETFOREGROUND) == IDYES) {
39 			// Give the more detailed information string
40 			MessageBox(hScrnWnd, BzipDetail.szText, szTitle, MB_OK | nIcon | MB_SETFOREGROUND);
41 		}
42 */	}
43 
44 	//ProgressCreate();
45 
46 	nRet = BurnDrvInit();
47 
48 	BzipClose();
49 
50 //	ProgressDestroy();
51 
52 	if (nRet) {
53 		return 1;
54 	} else {
55 		return 0;
56 	}
57 }
58 
59 // Catch calls to BurnLoadRom() once the emulation has started;
60 // Intialise the zip module before forwarding the call, and exit cleanly.
DrvLoadRom(unsigned char * Dest,int * pnWrote,int i)61 static int DrvLoadRom(unsigned char* Dest, int* pnWrote, int i)
62 {
63 	int nRet;
64 
65 	BzipOpen(false);
66 
67 	if ((nRet = BurnExtLoadRom(Dest, pnWrote, i)) != 0) {
68 		char szText[256] = "";
69 		char* pszFilename;
70 
71 		BurnDrvGetRomName(&pszFilename, i, 0);
72 		sprintf(szText, "Error loading %s, requested by %s.\nThe emulation will likely suffer problems.", pszFilename, BurnDrvGetTextA(0));
73 	}
74 
75 	BzipClose();
76 
77 	BurnExtLoadRom = DrvLoadRom;
78 
79 	//ScrnTitle();
80 
81 	return nRet;
82 }
83 
DrvInit(int nDrvNum,bool bRestore)84 int DrvInit(int nDrvNum, bool bRestore)
85 {
86 	DrvExit();						// Make sure exitted
87 	AudSoundInit();						// Init Sound (not critical if it fails)
88 
89 	nBurnSoundRate = 0;					// Assume no sound
90 	pBurnSoundOut = NULL;
91 	if (bAudOkay) {
92 		nBurnSoundRate = nAudSampleRate;
93 		nBurnSoundLen = nAudSegLen;
94 	}
95 	nBurnDrvSelect = nDrvNum;		// Set the driver number
96 
97 	// Define nMaxPlayers early; GameInpInit() needs it (normally defined in DoLibInit()).
98 	nMaxPlayers = BurnDrvGetMaxPlayers();
99 	GameInpInit();					// Init game input
100 
101 	ConfigGameLoad(true);
102 	InputMake(true);
103 
104 	GameInpDefault();
105 
106 	if (DoLibInit()) {				// Init the Burn library's driver
107 		char szTemp[512];
108 
109 		BurnDrvExit();				// Exit the driver
110 
111 		_stprintf (szTemp, _T("There was an error starting '%s'.\n"), BurnDrvGetText(DRV_FULLNAME));
112 		return 1;
113 	}
114 
115 	BurnExtLoadRom = DrvLoadRom;
116 
117 	bDrvOkay = 1;					// Okay to use all BurnDrv functions
118 
119 	bSaveRAM = false;
120 	nBurnLayer = 0xFF;				// show all layers
121 
122 	// Reset the speed throttling code, so we don't 'jump' after the load
123 	RunReset();
124 	return 0;
125 }
126 
DrvInitCallback()127 int DrvInitCallback()
128 {
129 	return DrvInit(nBurnDrvSelect, false);
130 }
131 
DrvExit()132 int DrvExit()
133 {
134 	if (bDrvOkay) {
135 
136 //		StopReplay();
137 
138 		VidExit();
139 
140 		if (nBurnDrvSelect < nBurnDrvCount) {
141 
142 			//MemCardEject();				// Eject memory card if present
143 
144 			if (bSaveRAM) {
145 				//StatedAuto(1);			// Save NV (or full) RAM
146 				bSaveRAM = false;
147 			}
148 
149 			ConfigGameSave(bSaveInputs);
150 
151 			GameInpExit();				// Exit game input
152 			BurnDrvExit();				// Exit the driver
153 		}
154 	}
155 
156 	BurnExtLoadRom = NULL;
157 
158 	bDrvOkay = 0;					// Stop using the BurnDrv functions
159 
160 	//bRunPause = 0;					// Don't pause when exitted
161 
162 	if (bAudOkay) {
163 //		// Write silence into the sound buffer on exit, and for drivers which don't use pBurnSoundOut
164 		memset(nAudNextSound, 0, nAudSegLen << 2);
165 	}
166 
167 	nBurnDrvSelect = ~0U;			// no driver selected
168 
169 	return 0;
170 }
171 
ProgressUpdateBurner(double dProgress,const TCHAR * pszText,bool bAbs)172 int ProgressUpdateBurner(double dProgress, const TCHAR* pszText, bool bAbs)
173 {
174 	printf(".");
175 	return 0;
176 }
177 
AppError(TCHAR * szText,int bWarning)178 int AppError(TCHAR* szText, int bWarning)
179 {
180 	return 0;
181 }
182 
183