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