Annotation of hatari/src/main.c, revision 1.1.1.10

1.1       root        1: /*
1.1.1.6   root        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.
1.1       root        8: */
1.1.1.10! root        9: char Main_rcsid[] = "Hatari $Id: main.c,v 1.74 2005/06/05 14:19:39 thothy Exp $";
1.1       root       10: 
                     11: #include <time.h>
1.1.1.5   root       12: #include <unistd.h>
1.1       root       13: 
                     14: #include <SDL.h>
                     15: 
                     16: #include "main.h"
                     17: #include "configuration.h"
                     18: #include "dialog.h"
                     19: #include "audio.h"
                     20: #include "joy.h"
                     21: #include "file.h"
                     22: #include "floppy.h"
                     23: #include "gemdos.h"
1.1.1.4   root       24: #include "hdc.h"
1.1       root       25: #include "ikbd.h"
1.1.1.10! root       26: #include "ioMem.h"
1.1.1.5   root       27: #include "keymap.h"
1.1.1.10! root       28: #include "log.h"
1.1       root       29: #include "m68000.h"
                     30: #include "memorySnapShot.h"
                     31: #include "misc.h"
1.1.1.8   root       32: #include "midi.h"
1.1       root       33: #include "printer.h"
1.1.1.8   root       34: #include "reset.h"
1.1       root       35: #include "rs232.h"
                     36: #include "screen.h"
1.1.1.5   root       37: #include "sdlgui.h"
1.1       root       38: #include "shortcut.h"
                     39: #include "sound.h"
1.1.1.8   root       40: #include "stMemory.h"
1.1       root       41: #include "tos.h"
1.1.1.5   root       42: #include "vdi.h"
1.1       root       43: #include "video.h"
                     44: #include "ymFormat.h"
1.1.1.2   root       45: #include "debugui.h"
1.1       root       46: 
                     47: #include "uae-cpu/hatari-glue.h"
                     48: 
                     49: 
                     50: BOOL bQuitProgram=FALSE;                  /* Flag to quit program cleanly */
1.1.1.4   root       51: BOOL bEmulationActive=TRUE;               /* Run emulation when started */
1.1.1.2   root       52: BOOL bEnableDebug=FALSE;                  /* Enable debug UI? */
1.1.1.8   root       53: char szBootDiscImage[FILENAME_MAX];
                     54: char szWorkingDir[FILENAME_MAX];          /* Working directory */
1.1.1.9   root       55: BOOL bIgnoreNextMouseMotion = FALSE;      /* Next mouse motion will be ignored (needed after SDL_WarpMouse) */
1.1       root       56: 
                     57: 
                     58: /*-----------------------------------------------------------------------*/
                     59: /*
                     60:   Save/Restore snapshot of local variables('MemorySnapShot_Store' handles type)
                     61: */
                     62: void Main_MemorySnapShot_Capture(BOOL bSave)
                     63: {
                     64:   int nBytes;
                     65: 
                     66:   /* Save/Restore details */
                     67:   /* Only save/restore area of memory machine ie set to, eg 1Mb */
                     68:   if (bSave) {
1.1.1.7   root       69:     nBytes = STRamEnd;  /* was: STRamEnd_BusErr */
1.1       root       70:     MemorySnapShot_Store(&nBytes,sizeof(nBytes));
                     71:     MemorySnapShot_Store(STRam,nBytes);
                     72:   }
                     73:   else {
                     74:     MemorySnapShot_Store(&nBytes,sizeof(nBytes));
                     75:     MemorySnapShot_Store(STRam,nBytes);
                     76:   }
                     77:   /* And Cart/TOS/Hardware area */
                     78:   MemorySnapShot_Store(&STRam[0xE00000],0x200000);
                     79:   MemorySnapShot_Store(szBootDiscImage,sizeof(szBootDiscImage));
                     80:   MemorySnapShot_Store(szWorkingDir,sizeof(szWorkingDir));
                     81: }
                     82: 
                     83: 
                     84: /*-----------------------------------------------------------------------*/
                     85: /*
                     86:   Pause emulation, stop sound
                     87: */
                     88: void Main_PauseEmulation(void)
                     89: {
1.1.1.4   root       90:   if( bEmulationActive )
                     91:   {
1.1.1.6   root       92:     Audio_EnableAudio(FALSE);
1.1.1.4   root       93:     bEmulationActive = FALSE;
                     94:   }
1.1       root       95: }
                     96: 
1.1.1.2   root       97: /*-----------------------------------------------------------------------*/
1.1       root       98: /*
                     99:   Start emulation
                    100: */
                    101: void Main_UnPauseEmulation(void)
                    102: {
1.1.1.4   root      103:   if( !bEmulationActive )
                    104:   {
1.1.1.6   root      105:     Audio_EnableAudio(ConfigureParams.Sound.bEnableSound);
1.1.1.4   root      106:     Screen_SetFullUpdate();       /* Cause full screen update(to clear all) */
1.1       root      107: 
1.1.1.4   root      108:     bEmulationActive = TRUE;
                    109:   }
1.1       root      110: }
                    111: 
1.1.1.7   root      112: 
1.1       root      113: /* ----------------------------------------------------------------------- */
                    114: /*
1.1.1.9   root      115:   Set mouse pointer to new coordinates and set flag to ignore the mouse event
                    116:   that is generated by SDL_WarpMouse().
                    117: */
                    118: void Main_WarpMouse(int x, int y)
                    119: {
                    120:   SDL_WarpMouse(x, y);                  /* Set mouse pointer to new position */
                    121:   bIgnoreNextMouseMotion = TRUE;        /* Ignore mouse motion event from SDL_WarpMouse */
                    122: }
                    123: 
                    124: 
                    125: /* ----------------------------------------------------------------------- */
                    126: /*
1.1.1.7   root      127:   Message handler
1.1       root      128:   Here we process the SDL events (keyboard, mouse, ...) and map it to
                    129:   Atari IKBD events.
                    130: */
1.1.1.8   root      131: void Main_EventHandler(void)
1.1       root      132: {
1.1.1.4   root      133:   SDL_Event event;
1.1       root      134: 
1.1.1.4   root      135:   if( SDL_PollEvent(&event) )
                    136:    switch( event.type )
1.1       root      137:    {
1.1.1.9   root      138: 
1.1       root      139:     case SDL_QUIT:
1.1.1.4   root      140:        bQuitProgram = TRUE;
1.1.1.8   root      141:        set_special(SPCFLAG_BRK);        /* Assure that CPU core shuts down */
1.1       root      142:        break;
1.1.1.9   root      143: 
1.1.1.4   root      144:     case SDL_MOUSEMOTION:               /* Read/Update internal mouse position */
1.1.1.9   root      145:        if (bIgnoreNextMouseMotion)
                    146:        {
                    147:          bIgnoreNextMouseMotion = FALSE;
                    148:        }
                    149:        else
                    150:        {
                    151:          KeyboardProcessor.Mouse.dx += event.motion.xrel;
                    152:          KeyboardProcessor.Mouse.dy += event.motion.yrel;
                    153:        }
1.1       root      154:        break;
1.1.1.9   root      155: 
1.1       root      156:     case SDL_MOUSEBUTTONDOWN:
                    157:        if( event.button.button==SDL_BUTTON_LEFT )
1.1.1.4   root      158:        {
                    159:          if(Keyboard.LButtonDblClk==0)
                    160:            Keyboard.bLButtonDown |= BUTTON_MOUSE;  /* Set button down flag */
                    161:        }
1.1       root      162:        else if( event.button.button==SDL_BUTTON_RIGHT )
1.1.1.4   root      163:          Keyboard.bRButtonDown |= BUTTON_MOUSE;
1.1       root      164:        else if( event.button.button==SDL_BUTTON_MIDDLE )
                    165:          Keyboard.LButtonDblClk = 1;    /* Start double-click sequence in emulation time */
                    166:        break;
1.1.1.9   root      167: 
1.1       root      168:     case SDL_MOUSEBUTTONUP:
                    169:        if( event.button.button==SDL_BUTTON_LEFT )
1.1.1.4   root      170:          Keyboard.bLButtonDown &= ~BUTTON_MOUSE;
1.1       root      171:        else if( event.button.button==SDL_BUTTON_RIGHT )
1.1.1.4   root      172:          Keyboard.bRButtonDown &= ~BUTTON_MOUSE;;
1.1       root      173:        break;
1.1.1.9   root      174: 
1.1.1.7   root      175:     case SDL_KEYDOWN:
                    176:        Keymap_KeyDown(&event.key.keysym);
1.1       root      177:        break;
1.1.1.9   root      178: 
1.1.1.7   root      179:     case SDL_KEYUP:
                    180:        Keymap_KeyUp(&event.key.keysym);
1.1       root      181:        break;
                    182:    }
                    183: }
                    184: 
                    185: 
1.1.1.2   root      186: /*-----------------------------------------------------------------------*/
1.1       root      187: /*
1.1.1.8   root      188:   Show supported options.
                    189: */
                    190: static void Main_ShowOptions(void)
                    191: {
                    192:   printf("Usage:\n hatari [options] [disk image name]\n"
                    193:          "Where options are:\n"
                    194:          "  --help or -h          Print this help text and exit.\n"
                    195:          "  --version or -v       Print version number and exit.\n"
                    196:          "  --mono or -m          Start in monochrome mode instead of color.\n"
1.1.1.9   root      197:          "  --fullscreen or -f    Start emulator in fullscreen mode.\n"
                    198:          "  --window or -w        Start emulator in window mode.\n"
1.1.1.8   root      199:          "  --joystick or -j      Emulate a ST joystick with the cursor keys.\n"
                    200:          "  --nosound             Disable sound (faster!).\n"
                    201:          "  --printer             Enable printer support (experimental).\n"
                    202:          "  --midi <filename>     Enable midi support and write midi data to <filename>.\n"
                    203:          "  --rs232 <filename>    Use <filename> as the serial port device.\n"
                    204:          "  --frameskip           Skip every second frame (speeds up emulation!).\n"
                    205:          "  --debug or -D         Allow debug interface.\n"
                    206:          "  --harddrive <dir>     Emulate an ST harddrive\n"
                    207:          "     or -d <dir>         (<dir> = root directory).\n"
                    208:          "  --hdimage <imagename> Emulate an ST harddrive with an image.\n"
                    209:          "  --tos <file>          Use TOS image <file>.\n"
1.1.1.9   root      210:          "  --cartridge <file>    Use ROM cartridge image <file>.\n"
1.1.1.8   root      211:          "  --cpulevel <x>        Set the CPU type (x => 680x0) (TOS 2.06 only!).\n"
                    212:          "  --compatible          Use a more compatible (but slower) 68000 CPU mode.\n"
                    213:          "  --blitter             Enable blitter emulation (unstable!)\n"
                    214:          "  --vdi                 Use extended VDI resolution\n"
                    215:          "  --memsize <x>         Memory size in MB (x = 0, 1, 2 or 4; 0 for 512kB)\n"
                    216:          "  --configfile <file>   Use <file> instead of ~/.hatari.cfg as configuration\n"
                    217:          "     or -c <file>        file.\n"
                    218:          "  --slowfdc             Slow down FDC emulation (very experimental!).\n"
                    219:         );
                    220: }
                    221: 
                    222: 
                    223: /*-----------------------------------------------------------------------*/
                    224: /*
1.1       root      225:   Check for any passed parameters
                    226: */
1.1.1.8   root      227: static void Main_ReadParameters(int argc, char *argv[])
1.1       root      228: {
1.1.1.4   root      229:   int i;
1.1       root      230: 
1.1.1.4   root      231:   /* Scan for any which we can use */
                    232:   for(i=1; i<argc; i++)
1.1       root      233:   {
1.1.1.4   root      234:     if (strlen(argv[i])>0)
1.1       root      235:     {
1.1.1.4   root      236:       if (!strcmp(argv[i],"--help") || !strcmp(argv[i],"-h"))
1.1       root      237:       {
1.1.1.8   root      238:         Main_ShowOptions();
1.1.1.4   root      239:         exit(0);
1.1       root      240:       }
                    241:       else if (!strcmp(argv[i],"--version") || !strcmp(argv[i],"-v"))
                    242:       {
1.1.1.4   root      243:         printf("This is %s.\n", PROG_NAME);
                    244:         printf("This program is free software licensed under the GNU GPL.\n");
                    245:         exit(0);
1.1       root      246:       }
1.1.1.2   root      247:       else if (!strcmp(argv[i],"--mono") || !strcmp(argv[i],"-m"))
1.1       root      248:       {
1.1.1.4   root      249:         bUseHighRes=TRUE;
                    250:         ConfigureParams.Screen.bUseHighRes=TRUE;
                    251:         STRes=PrevSTRes=ST_HIGH_RES;
1.1       root      252:       }
                    253:       else if (!strcmp(argv[i],"--fullscreen") || !strcmp(argv[i],"-f"))
                    254:       {
1.1.1.9   root      255:         ConfigureParams.Screen.bFullScreen = TRUE;
                    256:       }
                    257:       else if (!strcmp(argv[i],"--window") || !strcmp(argv[i],"-w"))
                    258:       {
                    259:         ConfigureParams.Screen.bFullScreen = FALSE;
1.1       root      260:       }
                    261:       else if (!strcmp(argv[i],"--joystick") || !strcmp(argv[i],"-j"))
                    262:       {
1.1.1.4   root      263:         ConfigureParams.Joysticks.Joy[1].bCursorEmulation=TRUE;
1.1       root      264:       }
1.1.1.4   root      265:       else if ( !strcmp(argv[i],"--nosound") )
1.1.1.2   root      266:       {
1.1.1.4   root      267:         ConfigureParams.Sound.bEnableSound = FALSE;
1.1.1.2   root      268:       }
                    269:       else if ( !strcmp(argv[i],"--frameskip") )
                    270:       {
1.1.1.7   root      271:         ConfigureParams.Screen.bFrameSkip = TRUE;
1.1.1.2   root      272:       }
1.1.1.8   root      273:       else if ( !strcmp(argv[i],"--printer") )
                    274:       {
                    275:         /* FIXME: add more commandline configuration for printing */
                    276:         ConfigureParams.Printer.bEnablePrinting = TRUE;
                    277:       }
                    278:       else if (!strcmp(argv[i], "--midi"))
                    279:       {
                    280:         if(i+1 >= argc)
                    281:           fprintf(stderr, "Missing argument for --midi\n");
                    282:         else
                    283:         {
                    284:           if (strlen(argv[i+1]) <= sizeof(ConfigureParams.Midi.szMidiOutFileName))
                    285:           {
                    286:             ConfigureParams.Midi.bEnableMidi = TRUE;
                    287:             strcpy(ConfigureParams.Midi.szMidiOutFileName, argv[i+1]);
                    288:           }
                    289:           else fprintf(stderr, "Midi file name too long!\n");
                    290:           i += 1;
                    291:         }
                    292:       }
                    293:       else if (!strcmp(argv[i], "--rs232"))
                    294:       {
                    295:         if(i+1 >= argc)
                    296:           fprintf(stderr, "Missing argument for --rs232\n");
                    297:         else
                    298:         {
                    299:           if (strlen(argv[i+1]) <= sizeof(ConfigureParams.RS232.szOutFileName))
                    300:           {
                    301:             ConfigureParams.RS232.bEnableRS232 = TRUE;
                    302:             strcpy(ConfigureParams.RS232.szOutFileName, argv[i+1]);
                    303:             strcpy(ConfigureParams.RS232.szInFileName, argv[i+1]);
                    304:           }
                    305:           else fprintf(stderr, "RS232 file name too long!\n");
                    306:           i += 1;
                    307:         }
                    308:       }
1.1.1.4   root      309:       else if (!strcmp(argv[i],"--debug") || !strcmp(argv[i],"-D"))
1.1.1.2   root      310:       {
1.1.1.4   root      311:         bEnableDebug=TRUE;
1.1.1.2   root      312:       }
1.1.1.4   root      313:       else if (!strcmp(argv[i],"--hdimage"))
1.1.1.3   root      314:       {
1.1.1.8   root      315:         if(i+1 >= argc)
1.1.1.7   root      316:           fprintf(stderr, "Missing argument for --hdimage\n");
                    317:         else
1.1.1.4   root      318:         {
1.1.1.8   root      319:           if (strlen(argv[i+1]) <= sizeof(ConfigureParams.HardDisc.szHardDiscImage))
1.1.1.4   root      320:           {
1.1.1.7   root      321:             ConfigureParams.HardDisc.bUseHardDiscImage = TRUE;
1.1.1.4   root      322:             strcpy(ConfigureParams.HardDisc.szHardDiscImage, argv[i+1]);
                    323:           }
1.1.1.7   root      324:           else fprintf(stderr, "HD image file name too long!\n");
                    325:           i += 1;
1.1.1.4   root      326:         }
                    327:       }
                    328:       else if (!strcmp(argv[i],"--harddrive") || !strcmp(argv[i],"-d"))
                    329:       {
1.1.1.8   root      330:         if(i+1 >= argc)
1.1.1.7   root      331:           fprintf(stderr, "Missing argument for --harddrive\n");
                    332:         else
1.1.1.4   root      333:         {
1.1.1.7   root      334:           if(strlen(argv[i+1]) <= MAX_PATH )
                    335:           {
                    336:             ConfigureParams.HardDisc.bUseHardDiscDirectories = TRUE;
                    337:             ConfigureParams.HardDisc.bBootFromHardDisc = TRUE;
                    338:             strcpy(ConfigureParams.HardDisc.szHardDiscDirectories[0], argv[i+1]);
                    339:           }
                    340:           else fprintf(stderr, "HD directory name too long!\n");
1.1.1.4   root      341:           i += 1;
                    342:         }
1.1.1.3   root      343:       }
                    344:       else if (!strcmp(argv[i],"--tos"))
                    345:       {
1.1.1.4   root      346:         if(i+1>=argc)
                    347:           fprintf(stderr,"Missing argument for --tos.\n");
1.1.1.3   root      348:         else
1.1.1.9   root      349:           strncpy(ConfigureParams.Rom.szTosImageFileName, argv[++i], sizeof(ConfigureParams.Rom.szTosImageFileName));
                    350:       }
                    351:       else if (!strcmp(argv[i],"--cartridge"))
                    352:       {
                    353:         if(i+1>=argc)
                    354:           fprintf(stderr,"Missing argument for --cartridge.\n");
                    355:         else
                    356:           strncpy(ConfigureParams.Rom.szCartridgeImageFileName, argv[++i], sizeof(ConfigureParams.Rom.szCartridgeImageFileName));
1.1.1.3   root      357:       }
                    358:       else if (!strcmp(argv[i],"--cpulevel"))
                    359:       {
1.1.1.4   root      360:         if(i+1>=argc)
                    361:           fprintf(stderr,"Missing argument for --cpulevel.\n");
                    362:          else
                    363:           cpu_level = atoi(argv[++i]);
                    364:         if(cpu_level<0 || cpu_level>4)
                    365:           cpu_level = 0;
1.1.1.5   root      366:         ConfigureParams.System.nCpuLevel = cpu_level;
1.1.1.3   root      367:       }
                    368:       else if (!strcmp(argv[i],"--compatible") || !strcmp(argv[i],"-d"))
                    369:       {
1.1.1.4   root      370:         cpu_compatible = TRUE;
1.1.1.5   root      371:         ConfigureParams.System.bCompatibleCpu = TRUE;
                    372:       }
                    373:       else if (!strcmp(argv[i],"--blitter"))
                    374:       {
                    375:         ConfigureParams.System.bBlitter = TRUE;
                    376:       }
1.1.1.7   root      377:       else if (!strcmp(argv[i], "--vdi"))
1.1.1.5   root      378:       {
1.1.1.9   root      379:         bUseVDIRes = ConfigureParams.Screen.bUseExtVdiResolutions = TRUE;
1.1.1.3   root      380:       }
1.1.1.7   root      381:       else if (!strcmp(argv[i], "--memsize"))
                    382:       {
                    383:         int memorysize = MEMORY_SIZE_1Mb;
                    384:         if(i+1 >= argc)
                    385:           fprintf(stderr,"Missing argument for --memsize.\n");
                    386:         else
                    387:           memorysize = atoi(argv[++i]);
                    388:         if(memorysize == 0)
                    389:           ConfigureParams.Memory.nMemorySize = MEMORY_SIZE_512Kb;
                    390:         else if(memorysize == 2)
                    391:           ConfigureParams.Memory.nMemorySize = MEMORY_SIZE_2Mb;
                    392:         else if(memorysize == 4)
                    393:           ConfigureParams.Memory.nMemorySize = MEMORY_SIZE_4Mb;
                    394:         else  /* Use 1MB as default */
                    395:           ConfigureParams.Memory.nMemorySize = MEMORY_SIZE_1Mb;
                    396:       }
1.1.1.8   root      397:       else if (!strcmp(argv[i],"--configfile") || !strcmp(argv[i],"-c"))
                    398:       {
                    399:         if (i+1 >= argc)
                    400:           fprintf(stderr, "Missing argument for --configfile\n");
                    401:         else
                    402:         {
                    403:           if (strlen(argv[i+1]) <= sizeof(sConfigFileName))
                    404:           {
                    405:             strcpy(sConfigFileName, argv[i+1]);
1.1.1.10! root      406:             Configuration_Load(NULL);
1.1.1.8   root      407:           }
                    408:           else
                    409:             fprintf(stderr, "Config file name too long!\n");
                    410:           i += 1;
                    411:         }
                    412:       }
                    413:       else if (!strcmp(argv[i], "--slowfdc"))
                    414:       {
                    415:         ConfigureParams.System.bSlowFDC = TRUE;
                    416:       }
1.1       root      417:       else
                    418:       {
1.1.1.4   root      419:         /* Possible passed disc image filename, ie starts with character other than '-' */
1.1.1.8   root      420:         if (argv[i][0] != '-' && strlen(argv[i]) < sizeof(szBootDiscImage)
                    421:             && File_Exists(argv[i]))
                    422:         {
                    423:           strcpy(szBootDiscImage, argv[i]);
                    424:           File_MakeAbsoluteName(szBootDiscImage);
                    425:         }
1.1.1.3   root      426:         else
1.1.1.8   root      427:           fprintf(stderr,"Illegal parameter: %s\n", argv[i]);
1.1       root      428:       }
                    429:     }
                    430:   }
1.1.1.10! root      431: 
        !           432:   Configuration_WorkOnDetails(FALSE);
1.1       root      433: }
                    434: 
1.1.1.2   root      435: 
                    436: /*-----------------------------------------------------------------------*/
1.1       root      437: /*
                    438:   Initialise emulation
                    439: */
1.1.1.8   root      440: static void Main_Init(void)
1.1       root      441: {
1.1.1.10! root      442:   /* Open debug log file */
        !           443:   Log_Init();
        !           444:   Log_Printf(LOG_INFO, PROG_NAME ", compiled on:  " __DATE__ ", " __TIME__ "\n");
        !           445: 
1.1.1.7   root      446:   /* Init SDL's video subsystem. Note: Audio and joystick subsystems
1.1.1.5   root      447:      will be initialized later (failures there are not fatal). */
1.1.1.7   root      448:   if(SDL_Init(SDL_INIT_VIDEO) < 0)
1.1.1.4   root      449:   {
1.1.1.2   root      450:     fprintf(stderr, "Could not initialize the SDL library:\n %s\n", SDL_GetError() );
                    451:     exit(-1);
1.1.1.4   root      452:   }
1.1.1.2   root      453: 
1.1       root      454:   Misc_SeedRandom(1043618);
1.1.1.4   root      455:   SDLGui_Init();
1.1       root      456:   Printer_Init();
                    457:   RS232_Init();
1.1.1.8   root      458:   Midi_Init();
1.1       root      459:   Screen_Init();
                    460:   Floppy_Init();
1.1.1.6   root      461:   Init680x0();                  /* Init CPU emulation */
                    462:   Audio_Init();
1.1.1.7   root      463:   Keymap_Init();
                    464: 
                    465:   /* Init HD emulation */
                    466:   if(ConfigureParams.HardDisc.bUseHardDiscImage)
                    467:   {
                    468:     char *szHardDiscImage = ConfigureParams.HardDisc.szHardDiscImage;
                    469:     if( HDC_Init(szHardDiscImage) )
                    470:       printf("Hard drive image %s mounted.\n", szHardDiscImage);
                    471:     else
                    472:       printf("Couldn't open HD file: %s, or no partitions\n", szHardDiscImage);
                    473:   }
                    474:   GemDOS_Init();
                    475:   if(ConfigureParams.HardDisc.bUseHardDiscDirectories)
                    476:   {
                    477:     GemDOS_InitDrives();
                    478:   }
1.1.1.6   root      479: 
                    480:   if(Reset_Cold())              /* Reset all systems, load TOS image */
                    481:   {
                    482:     /* If loading of the TOS failed, we bring up the GUI to let the
                    483:      * user choose another TOS ROM file. */
                    484:     Dialog_DoProperty();
                    485:   }
                    486:   if(!bTosImageLoaded || bQuitProgram)
                    487:   {
                    488:     fprintf(stderr, "Failed to load TOS image!\n");
                    489:     SDL_Quit();
                    490:     exit(-2);
                    491:   }
                    492: 
1.1.1.10! root      493:   IoMem_Init();
1.1       root      494:   Joy_Init();
                    495:   Sound_Init();
                    496: 
1.1.1.2   root      497:   /* Check passed disc image parameter, boot directly into emulator */
1.1.1.6   root      498:   if(strlen(szBootDiscImage) > 0)
                    499:   {
1.1       root      500:     Floppy_InsertDiscIntoDrive(0,szBootDiscImage);
                    501:   }
                    502: }
                    503: 
1.1.1.6   root      504: 
1.1.1.2   root      505: /*-----------------------------------------------------------------------*/
1.1       root      506: /*
                    507:   Un-Initialise emulation
                    508: */
1.1.1.8   root      509: static void Main_UnInit(void)
1.1       root      510: {
                    511:   Screen_ReturnFromFullScreen();
                    512:   Floppy_UnInit();
1.1.1.4   root      513:   HDC_UnInit();
1.1.1.8   root      514:   Midi_UnInit();
1.1       root      515:   RS232_UnInit();
                    516:   Printer_UnInit();
1.1.1.10! root      517:   IoMem_UnInit();
1.1.1.4   root      518:   GemDOS_UnInitDrives();
1.1.1.5   root      519:   if(Sound_AreWeRecording())
                    520:     Sound_EndRecording();
1.1.1.2   root      521:   Audio_UnInit();
1.1       root      522:   YMFormat_FreeRecording();
1.1.1.4   root      523:   SDLGui_UnInit();
1.1       root      524:   Screen_UnInit();
1.1.1.8   root      525:   Exit680x0();
1.1       root      526: 
1.1.1.2   root      527:   /* SDL uninit: */
                    528:   SDL_Quit();
1.1.1.10! root      529: 
        !           530:   /* Close debug log file */
        !           531:   Log_UnInit();
1.1       root      532: }
                    533: 
1.1.1.6   root      534: 
1.1.1.2   root      535: /*-----------------------------------------------------------------------*/
1.1       root      536: /*
                    537:   Main
                    538: */
                    539: int main(int argc, char *argv[])
                    540: {
                    541:   /* Generate random seed */
1.1.1.10! root      542:   srand(time(NULL));
1.1       root      543: 
1.1.1.8   root      544:   /* Get working directory */
                    545:   getcwd(szWorkingDir, FILENAME_MAX);
                    546: 
                    547:   szBootDiscImage[0] = 0;
1.1       root      548: 
1.1.1.2   root      549:   /* Set default configuration values: */
                    550:   Configuration_SetDefault();
                    551: 
1.1.1.7   root      552:   /* Now load the values from the configuration file */
1.1.1.10! root      553:   Configuration_Load(CONFDIR"/hatari.cfg");     /* Try the global configuration file first */
        !           554:   Configuration_Load(NULL);                     /* Now try the users configuration file */
1.1.1.7   root      555: 
1.1       root      556:   /* Check for any passed parameters */
1.1.1.2   root      557:   Main_ReadParameters(argc, argv);
1.1       root      558: 
                    559:   /* Init emulator system */
                    560:   Main_Init();
                    561: 
1.1.1.2   root      562:   /* Switch immediately to fullscreen if user wants to */
1.1.1.9   root      563:   if (ConfigureParams.Screen.bFullScreen)
1.1.1.2   root      564:     Screen_EnterFullScreen();
                    565: 
1.1.1.4   root      566:   /* Run emulation */
1.1       root      567:   Main_UnPauseEmulation();
1.1.1.4   root      568:   Start680x0();                 /* Start emulation */
1.1       root      569: 
                    570:   /* Un-init emulation system */
1.1.1.7   root      571:   Main_UnInit();
1.1       root      572: 
1.1.1.10! root      573:   return 0;
1.1       root      574: }

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.