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

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

unix.superglobalmegacorp.com

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