|
|
1.1 root 1: /*
2: Hatari - main.c
3:
4: This file is distributed under the GNU Public License, version 2 or at
5: your option any later version. Read the file gpl.txt for details.
6:
7: Main initialization and event handling routines.
8: */
9:
10: #include <time.h>
11: #include <signal.h>
12: #include <sys/time.h>
13: #include <unistd.h>
14:
15: #include <SDL.h>
16:
17: #include "main.h"
18: #include "configuration.h"
19: #include "decode.h"
20: #include "dialog.h"
21: #include "audio.h"
22: #include "file.h"
23: #include "hostcall.h"
24: #include "input.h"
25: #include "reset.h"
26: #include "keymap.h"
27: #include "m68000.h"
28: #include "misc.h"
29: #include "screen.h"
30: #include "sdlgui.h"
31: #include "shortcut.h"
32: #include "video.h"
33:
34: #include "../cpu/hatari-glue.h"
35:
36:
37: #define FORCE_WORKING_DIR /* Set default directory to cwd */
38:
39:
40: BOOL bQuitProgram=FALSE; /* Flag to quit program cleanly */
41: BOOL bUseFullscreen=FALSE;
42: BOOL bEmulationActive=TRUE; /* Run emulation when started */
43: BOOL bAppActive = FALSE;
44: char szBootDiscImage[MAX_FILENAME_LENGTH] = { "" };
45:
46: char szWorkingDir[MAX_FILENAME_LENGTH] = { "" };
47: char szCurrentDir[MAX_FILENAME_LENGTH] = { "" };
48:
49: unsigned char STRam[MEMORY_SIZE]; /* This is our ST Ram, includes all TOS/hardware areas for ease */
50:
51:
52: /*-----------------------------------------------------------------------*/
53: /*
54: Error handler
55: */
56: void Main_SysError(char *Error,char *Title)
57: {
58: fprintf(stderr,"%s : %s\n",Title,Error);
59: }
60:
61:
62: /*-----------------------------------------------------------------------*/
63: /*
64: Bring up message(handles full-screen as well as Window)
65: */
66: int Main_Message(char *lpText, char *lpCaption/*,unsigned int uType*/)
67: {
68: int Ret=0;
69:
70: /* Show message */
71: fprintf(stderr,"%s: %s\n", lpCaption, lpText);
72:
73: return(Ret);
74: }
75:
76:
77: /*-----------------------------------------------------------------------*/
78: /*
79: Pause emulation, stop sound
80: */
81: void Main_PauseEmulation(void)
82: {
83: if( bEmulationActive )
84: {
85: Audio_EnableAudio(FALSE);
86: bEmulationActive = FALSE;
87: }
88: }
89:
90: /*-----------------------------------------------------------------------*/
91: /*
92: Start emulation
93: */
94: void Main_UnPauseEmulation(void)
95: {
96: if( !bEmulationActive )
97: {
98: Audio_EnableAudio(ConfigureParams.Sound.bEnableSound);
99: bFullScreenHold = FALSE; /* Release hold */
100:
101: bEmulationActive = TRUE;
102: }
103: }
104:
105: /* ----------------------------------------------------------------------- */
106: /*
107: Message handler
108: Here we process the SDL events (keyboard, mouse, ...) and map it to
109: Atari IKBD events.
110: */
111: void Main_EventHandler()
112: {
113: SDL_Event event;
114:
115: if( SDL_PollEvent(&event) )
116: switch( event.type )
117: {
118: case SDL_QUIT:
119: bQuitProgram = TRUE;
120: break;
121: case SDL_MOUSEMOTION: /* Read/Update internal mouse position */
122: input.motion_x += event.motion.xrel;
123: input.motion_y += event.motion.yrel;
124: break;
125: case SDL_MOUSEBUTTONDOWN:
126: Input_MousePress (event.button.button);
127: break;
128: case SDL_MOUSEBUTTONUP:
129: Input_MouseRelease (event.button.button);
130: break;
131: case SDL_KEYDOWN:
132: Keymap_KeyDown(&event.key.keysym);
133: break;
134: case SDL_KEYUP:
135: Keymap_KeyUp(&event.key.keysym);
136: break;
137: }
138: Input_Update ();
139: }
140:
141:
142: /*-----------------------------------------------------------------------*/
143: /*
144: Check for any passed parameters
145: */
146: void Main_ReadParameters(int argc, char *argv[])
147: {
148: int i;
149:
150: /* Scan for any which we can use */
151: for(i=1; i<argc; i++)
152: {
153: if (strlen(argv[i])>0)
154: {
155: if (!strcmp(argv[i],"--help") || !strcmp(argv[i],"-h"))
156: {
157: printf("Usage:\n frontier [options]\n"
158: "Where options are:\n"
159: " --help or -h Print this help text and exit.\n"
160: " --fullscreen or -f Try to use fullscreen mode.\n"
161: " --nosound Disable sound (faster!).\n"
162: );
163: exit(0);
164: }
165: else if (!strcmp(argv[i],"--fullscreen") || !strcmp(argv[i],"-f"))
166: {
167: bUseFullscreen=TRUE;
168: }
169: else if ( !strcmp(argv[i],"--nosound") )
170: {
171: bDisableSound=TRUE;
172: ConfigureParams.Sound.bEnableSound = FALSE;
173: }
174: else
175: {
176: /* some time make it possible to read alternative
177: * names for fe2.bin from command line */
178: fprintf(stderr,"Illegal parameter: %s\n",argv[i]);
179: }
180: }
181: }
182: }
183:
184:
185: /*-----------------------------------------------------------------------*/
186: /*
187: Initialise emulation
188: */
189: void Main_Init(void)
190: {
191: /* Init SDL's video subsystem. Note: Audio and joystick subsystems
192: will be initialized later (failures there are not fatal). */
193: if(SDL_Init(SDL_INIT_VIDEO) < 0)
194: {
195: fprintf(stderr, "Could not initialize the SDL library:\n %s\n", SDL_GetError() );
196: exit(-1);
197: }
198:
199: Misc_SeedRandom(1043618);
200: SDLGui_Init();
201: Screen_Init();
202: Init680x0(); /* Init CPU emulation */
203: Audio_Init();
204: Keymap_Init();
205:
206: GemDOS_Init();
207: GemDOS_InitDrives();
208:
209: if(Reset_VM()) /* Reset all systems */
210: {
211: /* If loading of the TOS failed, we bring up the GUI to let the
212: * user choose another TOS ROM file. */
213: Dialog_DoProperty();
214: }
215: if(bQuitProgram)
216: {
217: SDL_Quit();
218: exit(-2);
219: }
220: }
221:
222:
223: /*-----------------------------------------------------------------------*/
224: /*
225: Un-Initialise emulation
226: */
227: void Main_UnInit(void)
228: {
229: Screen_ReturnFromFullScreen();
230: GemDOS_UnInitDrives();
231: Audio_UnInit();
232: SDLGui_UnInit();
233: Screen_UnInit();
234:
235: /* SDL uninit: */
236: SDL_Quit();
237: }
238:
239:
240: /*-----------------------------------------------------------------------*/
241: /*
242: Main
243: */
244: int main(int argc, char *argv[])
245: {
246:
247: /* Generate random seed */
248: srand( time(NULL) );
249:
250: /* Get working directory, if in MSDev force */
251: Misc_FindWorkingDirectory(argv[0]);
252: #ifdef FORCE_WORKING_DIR
253: getcwd(szWorkingDir, MAX_FILENAME_LENGTH);
254: #endif
255:
256: /* Set default configuration values: */
257: Configuration_SetDefault();
258:
259: /* Check for any passed parameters */
260: Main_ReadParameters(argc, argv);
261:
262: /* Init emulator system */
263: Main_Init();
264:
265: /* Switch immediately to fullscreen if user wants to */
266: if( bUseFullscreen )
267: Screen_EnterFullScreen();
268:
269: /* Run emulation */
270: Main_UnPauseEmulation();
271: Start680x0(); /* Start emulation */
272:
273: /* Un-init emulation system */
274: Main_UnInit();
275:
276: return(0);
277: }
278:
279:
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.