|
|
1.1 root 1: /*
2: Hatari
3: */
4:
5: #include <time.h>
1.1.1.2 ! root 6: #include <signal.h>
! 7: #include <sys/time.h>
1.1 root 8:
9: #include <SDL.h>
10:
11: #include "main.h"
12: #include "configuration.h"
13: #include "decode.h"
14: #include "dialog.h"
15: #include "createDiscImage.h"
16: #include "audio.h"
17: #include "debug.h"
18: #include "joy.h"
19: #include "errlog.h"
20: #include "file.h"
21: #include "floppy.h"
22: #include "gemdos.h"
23: #include "ikbd.h"
24: #include "intercept.h"
25: #include "reset.h"
26: #include "m68000.h"
27: #include "memorySnapShot.h"
28: #include "misc.h"
29: #include "printer.h"
30: #include "rs232.h"
31: #include "screen.h"
32: #include "shortcut.h"
33: #include "sound.h"
34: #include "timer.h"
35: #include "tos.h"
36: #include "video.h"
37: #include "view.h"
38: #include "ymFormat.h"
1.1.1.2 ! root 39: #include "debugui.h"
1.1 root 40:
41: #include "uae-cpu/hatari-glue.h"
42:
43:
44: extern int quit_program; /* Declared in newcpu.c */
45:
1.1.1.2 ! root 46: SDL_TimerID hSoundTimer; /* Handle to sound playback */
1.1 root 47:
48: BOOL bQuitProgram=FALSE; /* Flag to quit program cleanly */
49: BOOL bUseFullscreen=FALSE;
50: BOOL bEmulationActive=EMULATION_ACTIVE; /* Run emulation when started (we'll be in window mouse mode!) */
51: BOOL bAppActive = FALSE;
1.1.1.2 ! root 52: BOOL bEnableDebug=FALSE; /* Enable debug UI? */
1.1 root 53: unsigned int TimerID; /* Timer ID for main window */
54: char szName[] = { "Hatari" };
55: char szBootDiscImage[MAX_FILENAME_LENGTH] = { "" };
56:
57: char szWorkingDir[MAX_FILENAME_LENGTH] = { "" };
58: char szCurrentDir[MAX_FILENAME_LENGTH] = { "" };
59:
60: unsigned char STRam[16*1024*1024]; /* This is our ST Ram, includes all TOS/hardware areas for ease */
61:
62: int STSpeedMilliSeconds[] = { /* Convert option 'nMinMaxSpeed' into milliseconds */
63: 1000/50, /* MINMAXSPEED_MIN(20ms) */
64: 1000/66, /* MINMAXSPEED_1(15ms) */
65: 1000/100, /* MINMAXSPEED_2(10ms) */
66: 1000/200, /* MINMAXSPEED_3(5ms) */
67: 1, /* MINMAXSPEED_MAX(1ms) */
68: };
69:
70:
71:
72:
73: /*-----------------------------------------------------------------------*/
74: /*
75: Save/Restore snapshot of local variables('MemorySnapShot_Store' handles type)
76: */
77: void Main_MemorySnapShot_Capture(BOOL bSave)
78: {
79: int nBytes;
80:
81: /* Save/Restore details */
82: /* Only save/restore area of memory machine ie set to, eg 1Mb */
83: if (bSave) {
84: nBytes = STRamEnd_BusErr;
85: MemorySnapShot_Store(&nBytes,sizeof(nBytes));
86: MemorySnapShot_Store(STRam,nBytes);
87: }
88: else {
89: MemorySnapShot_Store(&nBytes,sizeof(nBytes));
90: MemorySnapShot_Store(STRam,nBytes);
91: }
92: /* And Cart/TOS/Hardware area */
93: MemorySnapShot_Store(&STRam[0xE00000],0x200000);
94: MemorySnapShot_Store(szBootDiscImage,sizeof(szBootDiscImage));
95: MemorySnapShot_Store(szWorkingDir,sizeof(szWorkingDir));
96: MemorySnapShot_Store(szCurrentDir,sizeof(szCurrentDir));
97: }
98:
99:
100: /*-----------------------------------------------------------------------*/
101: /*
102: Error handler
103: */
104: void Main_SysError(char *Error,char *Title)
105: {
1.1.1.2 ! root 106: fprintf(stderr,"%s : %s\n",Title,Error);
1.1 root 107: }
108:
1.1.1.2 ! root 109:
1.1 root 110: /*-----------------------------------------------------------------------*/
111: /*
112: Bring up message(handles full-screen as well as Window)
113: */
114: int Main_Message(char *lpText, char *lpCaption/*,unsigned int uType*/)
115: {
116: int Ret=0;
117:
118: /* Are we in full-screen? */
1.1.1.2 ! root 119: if (bInFullScreen)
! 120: Screen_ReturnFromFullScreen();
1.1 root 121:
122: /* Show message */
123: fprintf(stderr,"Message (%s):\n %s\n", lpCaption, lpText);
124:
125: return(Ret);
126: }
127:
128: /*-----------------------------------------------------------------------*/
129: /*
130: Pause emulation, stop sound
131: */
132: void Main_PauseEmulation(void)
133: {
1.1.1.2 ! root 134: SDL_PauseAudio(1);
1.1 root 135: bEmulationActive = EMULATION_INACTIVE;
136: }
137:
1.1.1.2 ! root 138: /*-----------------------------------------------------------------------*/
1.1 root 139: /*
140: Start emulation
141: */
142: void Main_UnPauseEmulation(void)
143: {
1.1.1.2 ! root 144: SDL_PauseAudio(0);
! 145: bFullScreenHold = FALSE; /* Release hold */
! 146: Screen_SetFullUpdate(); /* Cause full screen update(to clear all) */
1.1 root 147:
148: bEmulationActive = EMULATION_ACTIVE;
1.1.1.2 ! root 149: Audio_ResetBuffer();
1.1 root 150: }
151:
152: /* ----------------------------------------------------------------------- */
153: /*
154: Message handler ( actually called from Video_InterruptHandler_VBL() )
155: Here we process the SDL events (keyboard, mouse, ...) and map it to
156: Atari IKBD events.
157: */
158: #ifndef SDL_BUTTON_LEFT /* Seems not to be defined in old SDL versions */
159: #define SDL_BUTTON_LEFT 1
160: #define SDL_BUTTON_MIDDLE 2
161: #define SDL_BUTTON_RIGHT 3
162: #endif
163: void Main_EventHandler()
164: {
165: SDL_Event event;
166:
167: if( SDL_PollEvent(&event) )
168: switch( event.type )
169: {
170: case SDL_QUIT:
171: quit_program=1;
172: bQuitProgram=1;
173: break;
174: case SDL_MOUSEMOTION:
175: View_UpdateSTMousePosition(); /* Read/Update internal mouse position */
176: break;
177: case SDL_MOUSEBUTTONDOWN:
178: if( event.button.button==SDL_BUTTON_LEFT )
179: View_LeftMouseButtonDown();
180: else if( event.button.button==SDL_BUTTON_RIGHT )
181: View_RightMouseButtonDown();
182: else if( event.button.button==SDL_BUTTON_MIDDLE )
183: Keyboard.LButtonDblClk = 1; /* Start double-click sequence in emulation time */
184: break;
185: case SDL_MOUSEBUTTONUP:
186: if( event.button.button==SDL_BUTTON_LEFT )
187: View_LeftMouseButtonUp();
188: else if( event.button.button==SDL_BUTTON_RIGHT )
189: View_RightMouseButtonUp();
190: break;
191: case SDL_KEYDOWN:
192: View_KeyDown( event.key.keysym.sym, event.key.keysym.mod );
193: break;
194: case SDL_KEYUP:
1.1.1.2 ! root 195: View_KeyUp( event.key.keysym.sym, event.key.keysym.mod );
1.1 root 196: break;
197: }
198: }
199:
200:
201:
1.1.1.2 ! root 202: /*-----------------------------------------------------------------------*/
1.1 root 203: /*
204: This thread runs at 50fps and passes sound samples to direct sound and also also
205: set the counter/events to govern emulation speed to match the two together.
206: When running at a speed other than standard ST speed the VBL event is set by 'Main_SpeedThreadFunc'
207: which occurs at differing speeds.
208: */
1.1.1.2 ! root 209: void /*Uint32*/ Main_SoundTimerFunc(int v/*Uint32 interval, void *param*/)
1.1 root 210: {
1.1.1.2 ! root 211: struct itimerval mytimerval;
! 212: /* Advance frame counter, used to draw screen to window at 50fps */
1.1 root 213: VBLCounter++;
214: }
215:
1.1.1.2 ! root 216:
! 217: /*-----------------------------------------------------------------------*/
1.1 root 218: /*
1.1.1.2 ! root 219: Create sound timer to handle sound
1.1 root 220: */
1.1.1.2 ! root 221: void Main_CreateSoundTimer(void)
1.1 root 222: {
1.1.1.2 ! root 223: struct itimerval mytimerval;
! 224: /* Create thread to run every 20ms(50fps) to handle emulation samples */
! 225: //hSoundTimer = SDL_AddTimer(10,Main_SoundTimerFunc,NULL);
! 226:
! 227: signal(SIGALRM, Main_SoundTimerFunc);
! 228: mytimerval.it_interval.tv_sec=0; mytimerval.it_interval.tv_usec=20000;
! 229: mytimerval.it_value.tv_sec=0; mytimerval.it_value.tv_usec=20000;
! 230: setitimer(ITIMER_REAL, &mytimerval, NULL);
1.1 root 231: }
232:
1.1.1.2 ! root 233: /*-----------------------------------------------------------------------*/
1.1 root 234: /*
1.1.1.2 ! root 235: Delete sound timer
1.1 root 236: */
1.1.1.2 ! root 237: void Main_RemoveSoundTimer(void)
1.1 root 238: {
1.1.1.2 ! root 239: /*SDL_RemoveTimer(hSoundTimer);*/
! 240: signal(SIGALRM,SIG_IGN);
1.1 root 241: }
1.1.1.2 ! root 242:
! 243:
1.1 root 244:
245: /*-----------------------------------------------------------------------*/
246: /*
247: Check for any passed parameters
248: */
249: void Main_ReadParameters(int argc, char *argv[])
250: {
251: int i;
252:
253: /* Scan for any which we can use */
254: for(i=1; i<argc; i++)
255: {
256: if (strlen(argv[i])>0)
257: {
258: if (!strcmp(argv[i],"--help") || !strcmp(argv[i],"-h"))
259: {
260: printf("Usage:\n hatari [options] [disk image name]\n"
261: "Where options are:\n"
262: " --help or -h Print this help text and exit.\n"
263: " --version or -v Print version number and exit.\n"
1.1.1.2 ! root 264: " --mono or -m Start in monochrome mode instead of color.\n"
1.1 root 265: " --fullscreen or -f Try to use fullscreen mode.\n"
266: " --joystick or -j Emulate a ST joystick with the cursor keys\n"
1.1.1.2 ! root 267: " --sound or -s Enable sound (does not yet work right!)\n"
! 268: " --frameskip Skip every second frame (speeds up emulation!)\n"
! 269: " --debug or -d Allow debug interface.\n"
1.1 root 270: );
271: exit(0);
272: }
273: else if (!strcmp(argv[i],"--version") || !strcmp(argv[i],"-v"))
274: {
275: printf("This is %s.\n", PROG_NAME);
276: printf("This program is free software licensed under the GNU GPL.\n");
277: exit(0);
278: }
1.1.1.2 ! root 279: else if (!strcmp(argv[i],"--mono") || !strcmp(argv[i],"-m"))
1.1 root 280: {
1.1.1.2 ! root 281: bUseHighRes=TRUE;
! 282: STRes=PrevSTRes=ST_HIGH_RES;
1.1 root 283: }
284: else if (!strcmp(argv[i],"--fullscreen") || !strcmp(argv[i],"-f"))
285: {
286: bUseFullscreen=TRUE;
287: }
288: else if (!strcmp(argv[i],"--joystick") || !strcmp(argv[i],"-j"))
289: {
290: ConfigureParams.Joysticks.Joy[1].bCursorEmulation=TRUE;
291: }
1.1.1.2 ! root 292: else if (!strcmp(argv[i],"--sound") || !strcmp(argv[i],"-s"))
! 293: {
! 294: bDisableSound=FALSE;
! 295: ConfigureParams.Sound.bEnableSound = TRUE;
! 296: }
! 297: else if ( !strcmp(argv[i],"--frameskip") )
! 298: {
! 299: ConfigureParams.Screen.Advanced.bFrameSkip = TRUE;
! 300: }
! 301: else if (!strcmp(argv[i],"--debug") || !strcmp(argv[i],"-d"))
! 302: {
! 303: bEnableDebug=TRUE;
! 304: }
1.1 root 305: else
306: {
307: /* Possible passed disc image filename, ie starts with character other than '-' */
308: if (argv[i][0]!='-')
309: strcpy(szBootDiscImage,argv[i]);
310: }
311: }
312: }
313: }
314:
1.1.1.2 ! root 315:
! 316: /*-----------------------------------------------------------------------*/
1.1 root 317: /*
318: Initialise emulation
319: */
320: void Main_Init(void)
321: {
1.1.1.2 ! root 322: /* SDL init: */
! 323: if( SDL_Init(SDL_INIT_VIDEO|SDL_INIT_AUDIO/*|SDL_INIT_TIMER*/) < 0 )
! 324: {
! 325: fprintf(stderr, "Could not initialize the SDL library:\n %s\n", SDL_GetError() );
! 326: exit(-1);
! 327: }
! 328:
1.1 root 329: Misc_SeedRandom(1043618);
330: Printer_Init();
331: RS232_Init();
332: Configuration_Init();
333: Timer_Init();
334: File_Init();
335: Screen_Init();
336: Floppy_Init();
337: Reset_Cold();
338: GemDOS_Init();
339: Intercept_Init();
340: Joy_Init();
1.1.1.2 ! root 341: Audio_Init();
1.1 root 342: Sound_Init();
1.1.1.2 ! root 343: Main_CreateSoundTimer();
1.1 root 344:
1.1.1.2 ! root 345: /* Check passed disc image parameter, boot directly into emulator */
1.1 root 346: if (strlen(szBootDiscImage)>0) {
347: Floppy_InsertDiscIntoDrive(0,szBootDiscImage);
348: //FM View_ToggleWindowsMouse(MOUSE_ST);
349: }
350: }
351:
1.1.1.2 ! root 352: /*-----------------------------------------------------------------------*/
1.1 root 353: /*
354: Un-Initialise emulation
355: */
356: void Main_UnInit(void)
357: {
358: Screen_ReturnFromFullScreen();
1.1.1.2 ! root 359: Main_RemoveSoundTimer();
1.1 root 360: Floppy_EjectBothDrives();
361: Floppy_UnInit();
362: RS232_UnInit();
363: Printer_UnInit();
364: Intercept_UnInit();
1.1.1.2 ! root 365: Audio_UnInit();
1.1 root 366: YMFormat_FreeRecording();
367: //FM View_LimitCursorToScreen();
368: Screen_UnInit();
369:
370: #ifdef USE_DEBUGGER
371: FreeDebugDialog();
372: #endif
373: Configuration_UnInit();
1.1.1.2 ! root 374:
! 375: /* SDL uninit: */
! 376: SDL_Quit();
1.1 root 377: }
378:
1.1.1.2 ! root 379: /*-----------------------------------------------------------------------*/
1.1 root 380: /*
381: Main
382: */
383: int main(int argc, char *argv[])
384: {
385:
386: /* Generate random seed */
387: srand( time(NULL) );
388:
389: /* Get working directory, if in MSDev force */
390: Misc_FindWorkingDirectory();
391: #ifdef FORCE_WORKING_DIR
392: getcwd(szWorkingDir, MAX_FILENAME_LENGTH);
393: #endif
394:
395: /* Create debug files */
396: Debug_OpenFiles();
397: ErrLog_OpenFile();
398:
1.1.1.2 ! root 399: /* Set default configuration values: */
! 400: Configuration_SetDefault();
! 401:
1.1 root 402: /* Check for any passed parameters */
1.1.1.2 ! root 403: Main_ReadParameters(argc, argv);
1.1 root 404:
405: /* Init emulator system */
406: Main_Init();
407:
1.1.1.2 ! root 408: /* Switch immediately to fullscreen if user wants to */
! 409: if( bUseFullscreen )
! 410: Screen_EnterFullScreen();
! 411:
1.1 root 412: /* Set timing threads to govern timing and debug display */
413: //FM Main_SetSpeedThreadTimer(ConfigureParams.Configure.nMinMaxSpeed);
414: //FM TimerID = SetTimer(hWnd,1,1000,NULL);
415:
416: #ifdef USE_DEBUGGER
417: /* Run our debugger */
418: Debugger_Init();
419: Main_UnPauseEmulation();
420: /* Run messages until quit */
421: for(;;) {
422: if (Main_ExecuteWindowsMessage())
423: break;
424: }
425: #else
426: /* Run release emulation */
427: Main_UnPauseEmulation();
428: //RunIntructions();
429: Init680x0(); /* Init CPU emulation */
430: Start680x0(); /* Start emulation */
431: #endif
432:
433: /* Un-init emulation system */
434: //FM KillTimer(hWnd,TimerID);
435: Main_UnInit();
436:
437: /* Close debug files */
438: ErrLog_CloseFile();
439: Debug_CloseFiles();
440:
441: return(0);
442: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.