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

1.1       root        1: /*
                      2:   Hatari - change.c
                      3: 
1.1.1.8   root        4:   This file is distributed under the GNU General Public License, version 2
                      5:   or at your option any later version. Read the file gpl.txt for details.
1.1       root        6: 
                      7:   This code handles run-time configuration changes. We keep all our
                      8:   configuration details in a structure called 'ConfigureParams'.  Before
                      9:   doing he changes, a backup copy is done of this structure. When
                     10:   the changes are done, these are compared to see whether emulator
1.1.1.2   root       11:   needs to be rebooted
1.1       root       12: */
1.1.1.2   root       13: const char Change_fileid[] = "Hatari change.c : " __DATE__ " " __TIME__;
1.1       root       14: 
                     15: #include <ctype.h>
                     16: #include "main.h"
                     17: #include "configuration.h"
                     18: #include "audio.h"
                     19: #include "change.h"
                     20: #include "dialog.h"
                     21: #include "floppy.h"
1.1.1.9   root       22: #include "fdc.h"
1.1       root       23: #include "gemdos.h"
                     24: #include "hdc.h"
1.1.1.3   root       25: #include "ide.h"
1.1       root       26: #include "ioMem.h"
                     27: #include "joy.h"
                     28: #include "keymap.h"
                     29: #include "m68000.h"
1.1.1.2   root       30: #include "midi.h"
1.1       root       31: #include "options.h"
                     32: #include "printer.h"
                     33: #include "reset.h"
                     34: #include "rs232.h"
                     35: #include "screen.h"
                     36: #include "sound.h"
                     37: #include "statusbar.h"
                     38: #include "tos.h"
                     39: #include "vdi.h"
                     40: #include "video.h"
                     41: #include "hatari-glue.h"
                     42: #if ENABLE_DSP_EMU
                     43: # include "falcon/dsp.h"
                     44: #endif
                     45: 
1.1.1.5   root       46: #define DEBUG 0
                     47: #if DEBUG
1.1.1.9   root       48: #define Dprintf(a...) printf(a)
1.1.1.5   root       49: #else
1.1.1.9   root       50: #define Dprintf(a...)
1.1.1.5   root       51: #endif
1.1       root       52: 
                     53: /*-----------------------------------------------------------------------*/
                     54: /**
                     55:  * Check if user needs to be warned that changes will take place after reset.
1.1.1.3   root       56:  * Return true if wants to reset.
1.1       root       57:  */
                     58: bool Change_DoNeedReset(CNF_PARAMS *current, CNF_PARAMS *changed)
                     59: {
1.1.1.9   root       60:        int i;
                     61: 
1.1       root       62:        /* Did we change monitor type? If so, must reset */
                     63:        if (current->Screen.nMonitorType != changed->Screen.nMonitorType
                     64:            && (changed->System.nMachineType == MACHINE_FALCON
                     65:                || current->Screen.nMonitorType == MONITOR_TYPE_MONO
                     66:                || changed->Screen.nMonitorType == MONITOR_TYPE_MONO))
1.1.1.3   root       67:                return true;
1.1       root       68: 
                     69:        /* Did change to GEM VDI display? */
                     70:        if (current->Screen.bUseExtVdiResolutions != changed->Screen.bUseExtVdiResolutions)
1.1.1.3   root       71:                return true;
1.1       root       72: 
                     73:        /* Did change GEM resolution or color depth? */
                     74:        if (changed->Screen.bUseExtVdiResolutions &&
                     75:            (current->Screen.nVdiWidth != changed->Screen.nVdiWidth
                     76:             || current->Screen.nVdiHeight != changed->Screen.nVdiHeight
                     77:             || current->Screen.nVdiColors != changed->Screen.nVdiColors))
1.1.1.3   root       78:                return true;
1.1       root       79: 
                     80:        /* Did change TOS ROM image? */
                     81:        if (strcmp(changed->Rom.szTosImageFileName, current->Rom.szTosImageFileName))
1.1.1.3   root       82:                return true;
1.1       root       83: 
1.1.1.3   root       84:        /* Did change ACSI hard disk image? */
1.1.1.9   root       85:        for (i = 0; i < MAX_ACSI_DEVS; i++)
                     86:        {
                     87:                if (changed->Acsi[i].bUseDevice != current->Acsi[i].bUseDevice
                     88:                    || (strcmp(changed->Acsi[i].sDeviceFile, current->Acsi[i].sDeviceFile)
                     89:                        && changed->Acsi[i].bUseDevice))
                     90:                        return true;
                     91:        }
1.1.1.3   root       92: 
1.1.1.4   root       93:        /* Did change IDE master hard disk image? */
                     94:        if (changed->HardDisk.bUseIdeMasterHardDiskImage != current->HardDisk.bUseIdeMasterHardDiskImage
                     95:            || strcmp(changed->HardDisk.szIdeMasterHardDiskImage, current->HardDisk.szIdeMasterHardDiskImage))
                     96:                return true;
                     97: 
                     98:        /* Did change IDE slave hard disk image? */
                     99:        if (changed->HardDisk.bUseIdeSlaveHardDiskImage != current->HardDisk.bUseIdeSlaveHardDiskImage
                    100:            || strcmp(changed->HardDisk.szIdeSlaveHardDiskImage, current->HardDisk.szIdeSlaveHardDiskImage))
1.1.1.3   root      101:                return true;
1.1       root      102: 
1.1.1.10! root      103:        /* Did change GEMDOS drive Atari/host location or enabling? */
        !           104:        if (changed->HardDisk.nGemdosDrive != current->HardDisk.nGemdosDrive
        !           105:            || changed->HardDisk.bUseHardDiskDirectories != current->HardDisk.bUseHardDiskDirectories
1.1       root      106:            || (strcmp(changed->HardDisk.szHardDiskDirectories[0], current->HardDisk.szHardDiskDirectories[0])
                    107:                && changed->HardDisk.bUseHardDiskDirectories))
1.1.1.3   root      108:                return true;
1.1       root      109: 
                    110:        /* Did change machine type? */
                    111:        if (changed->System.nMachineType != current->System.nMachineType)
1.1.1.3   root      112:                return true;
1.1.1.8   root      113:        /* did change ST Blitter? */
                    114:        else if (current->System.nMachineType == MACHINE_ST &&
                    115:                 current->System.bBlitter != changed->System.bBlitter)
                    116:                return true;
1.1       root      117: 
1.1.1.5   root      118: #if ENABLE_DSP_EMU
                    119:        /* enabling DSP needs reset (disabling it not) */
                    120:        if (current->System.nDSPType != DSP_TYPE_EMU &&
                    121:            changed->System.nDSPType == DSP_TYPE_EMU)
                    122:                return true;
                    123: #endif
                    124: 
1.1.1.8   root      125:        /* did change CPU type? */
                    126:        if (changed->System.nCpuLevel != current->System.nCpuLevel)
                    127:                return true;
                    128: 
1.1.1.5   root      129: #if ENABLE_WINUAE_CPU
1.1.1.6   root      130:        /* Did change CPU address mode? */
                    131:        if (changed->System.bAddressSpace24 != current->System.bAddressSpace24)
                    132:                return true;
                    133: 
1.1.1.5   root      134:        /* Did change CPU prefetch mode? */
                    135:        if (changed->System.bCompatibleCpu != current->System.bCompatibleCpu)
                    136:                return true;
                    137: 
                    138:        /* Did change CPU cycle exact? */
                    139:        if (changed->System.bCycleExactCpu != current->System.bCycleExactCpu)
                    140:                return true;
                    141: 
                    142:        /* Did change MMU? */
                    143:        if (changed->System.bMMU != current->System.bMMU)
                    144:                return true;
1.1.1.7   root      145:  
                    146:        /* Did change FPU? */
                    147:        if (changed->System.n_FPUType != current->System.n_FPUType)
                    148:                return true;
1.1.1.10! root      149: 
        !           150:        /* Did change size of TT-RAM? */
        !           151:        if (current->Memory.nTTRamSize != changed->Memory.nTTRamSize)
        !           152:                return true;
1.1.1.5   root      153: #endif
                    154: 
1.1       root      155:        /* Did change size of memory? */
                    156:        if (current->Memory.nMemorySize != changed->Memory.nMemorySize)
1.1.1.3   root      157:                return true;
1.1       root      158: 
1.1.1.8   root      159:        /* MIDI related IRQs start/stop needs reset */
                    160:        if (current->Midi.bEnableMidi != changed->Midi.bEnableMidi)
                    161:                return true;
                    162: 
1.1.1.3   root      163:        return false;
1.1       root      164: }
                    165: 
                    166: 
                    167: /*-----------------------------------------------------------------------*/
                    168: /**
                    169:  * Copy details back to configuration and perform reset.
                    170:  */
                    171: void Change_CopyChangedParamsToConfiguration(CNF_PARAMS *current, CNF_PARAMS *changed, bool bForceReset)
                    172: {
                    173:        bool NeedReset;
1.1.1.3   root      174:        bool bReInitGemdosDrive = false;
                    175:        bool bReInitAcsiEmu = false;
                    176:        bool bReInitIDEEmu = false;
                    177:        bool bReInitIoMem = false;
                    178:        bool bScreenModeChange = false;
                    179:        bool bReInitMidi = false;
1.1.1.7   root      180:        bool bReInitPrinter = false;
1.1       root      181:        bool bFloppyInsert[MAX_FLOPPYDRIVES];
                    182:        int i;
                    183: 
1.1.1.5   root      184:        Dprintf("Changes for:\n");
1.1       root      185:        /* Do we need to warn user that changes will only take effect after reset? */
                    186:        if (bForceReset)
                    187:                NeedReset = bForceReset;
                    188:        else
                    189:                NeedReset = Change_DoNeedReset(current, changed);
                    190: 
                    191:        /* Do need to change resolution? Need if change display/overscan settings
                    192:         * (if switch between Colour/Mono cause reset later) or toggle statusbar
                    193:         */
                    194:        if (!NeedReset &&
                    195:            (changed->Screen.nForceBpp != current->Screen.nForceBpp
1.1.1.4   root      196:             || changed->Screen.bAspectCorrect != current->Screen.bAspectCorrect
                    197:             || changed->Screen.nMaxWidth != current->Screen.nMaxWidth
                    198:             || changed->Screen.nMaxHeight != current->Screen.nMaxHeight
1.1       root      199:             || changed->Screen.bAllowOverscan != current->Screen.bAllowOverscan
1.1.1.10! root      200:             || changed->Screen.bShowStatusbar != current->Screen.bShowStatusbar
        !           201: #if WITH_SDL2
        !           202:             || changed->Screen.nRenderScaleQuality != current->Screen.nRenderScaleQuality
        !           203:             || changed->Screen.bUseVsync != current->Screen.bUseVsync
        !           204: #endif
        !           205:            ))
1.1       root      206:        {
1.1.1.5   root      207:                Dprintf("- screenmode>\n");
1.1.1.3   root      208:                bScreenModeChange = true;
1.1       root      209:        }
                    210: 
                    211:        /* Did set new printer parameters? */
                    212:        if (changed->Printer.bEnablePrinting != current->Printer.bEnablePrinting
                    213:            || strcmp(changed->Printer.szPrintToFileName,current->Printer.szPrintToFileName))
                    214:        {
1.1.1.5   root      215:                Dprintf("- printer>\n");
1.1.1.7   root      216:                Printer_UnInit();
                    217:                bReInitPrinter = true;
1.1       root      218:        }
                    219: 
                    220:        /* Did set new RS232 parameters? */
                    221:        if (changed->RS232.bEnableRS232 != current->RS232.bEnableRS232
                    222:            || strcmp(changed->RS232.szOutFileName, current->RS232.szOutFileName)
                    223:            || strcmp(changed->RS232.szInFileName, current->RS232.szInFileName))
                    224:        {
1.1.1.5   root      225:                Dprintf("- RS-232>\n");
1.1       root      226:                RS232_UnInit();
                    227:        }
                    228: 
                    229:        /* Did stop sound? Or change playback Hz. If so, also stop sound recording */
1.1.1.3   root      230:        if (!changed->Sound.bEnableSound || changed->Sound.nPlaybackFreq != current->Sound.nPlaybackFreq)
1.1       root      231:        {
1.1.1.5   root      232:                Dprintf("- sound>\n");
1.1       root      233:                if (Sound_AreWeRecording())
                    234:                        Sound_EndRecording();
                    235:                Audio_UnInit();
                    236:        }
                    237: 
                    238:        /* Did change floppy (images)? */
                    239:        for (i = 0; i < MAX_FLOPPYDRIVES; i++)
                    240:        {
                    241:                /*
                    242:                Log_Printf(LOG_DEBUG, "Old and new disk %c:\n\t%s\n\t%s", 'A'+i,
                    243:                           current->DiskImage.szDiskFileName[i],
                    244:                           changed->DiskImage.szDiskFileName[i]);
                    245:                 */
                    246:                if (strcmp(changed->DiskImage.szDiskFileName[i],
                    247:                           current->DiskImage.szDiskFileName[i])
                    248:                    || strcmp(changed->DiskImage.szDiskZipPath[i],
                    249:                              current->DiskImage.szDiskZipPath[i]))
1.1.1.3   root      250:                        bFloppyInsert[i] = true;
1.1       root      251:                else
1.1.1.3   root      252:                        bFloppyInsert[i] = false;
1.1       root      253:        }
                    254: 
1.1.1.9   root      255:        if ( changed->DiskImage.EnableDriveA != current->DiskImage.EnableDriveA )
                    256:                FDC_Drive_Set_Enable ( 0 , changed->DiskImage.EnableDriveA );
                    257:        if ( changed->DiskImage.EnableDriveB != current->DiskImage.EnableDriveB )
                    258:                FDC_Drive_Set_Enable ( 1 , changed->DiskImage.EnableDriveB );
                    259: 
                    260:        if ( changed->DiskImage.DriveA_NumberOfHeads != current->DiskImage.DriveA_NumberOfHeads )
                    261:                FDC_Drive_Set_NumberOfHeads ( 0 , changed->DiskImage.DriveA_NumberOfHeads );
                    262:        if ( changed->DiskImage.DriveB_NumberOfHeads != current->DiskImage.DriveB_NumberOfHeads )
                    263:                FDC_Drive_Set_NumberOfHeads ( 1 , changed->DiskImage.DriveB_NumberOfHeads );
                    264: 
1.1.1.10! root      265:        /* Did change GEMDOS drive Atari/host location or enabling? */
        !           266:        if (changed->HardDisk.nGemdosDrive != current->HardDisk.nGemdosDrive
        !           267:            || changed->HardDisk.bUseHardDiskDirectories != current->HardDisk.bUseHardDiskDirectories
1.1       root      268:            || (strcmp(changed->HardDisk.szHardDiskDirectories[0], current->HardDisk.szHardDiskDirectories[0])
                    269:                && changed->HardDisk.bUseHardDiskDirectories))
                    270:        {
1.1.1.5   root      271:                Dprintf("- gemdos HD>\n");
1.1       root      272:                GemDOS_UnInitDrives();
1.1.1.3   root      273:                bReInitGemdosDrive = true;
1.1       root      274:        }
                    275: 
1.1.1.9   root      276:        /* Did change ACSI image? */
                    277:        for (i = 0; i < MAX_ACSI_DEVS; i++)
1.1       root      278:        {
1.1.1.9   root      279:                if (changed->Acsi[i].bUseDevice != current->Acsi[i].bUseDevice
                    280:                    || (strcmp(changed->Acsi[i].sDeviceFile, current->Acsi[i].sDeviceFile)
                    281:                        && changed->Acsi[i].bUseDevice))
                    282:                {
                    283:                        Dprintf("- ACSI image %i>\n", i);
                    284:                        bReInitAcsiEmu = true;
                    285:                }
1.1.1.3   root      286:        }
1.1.1.9   root      287:        if (bReInitAcsiEmu)
                    288:                HDC_UnInit();
                    289: 
1.1.1.4   root      290:        /* Did change IDE HD master image? */
                    291:        if (changed->HardDisk.bUseIdeMasterHardDiskImage != current->HardDisk.bUseIdeMasterHardDiskImage
                    292:            || (strcmp(changed->HardDisk.szIdeMasterHardDiskImage, current->HardDisk.szIdeMasterHardDiskImage)
                    293:                && changed->HardDisk.bUseIdeMasterHardDiskImage))
                    294:        {
1.1.1.5   root      295:                Dprintf("- IDE master>\n");
1.1.1.4   root      296:                Ide_UnInit();
                    297:                bReInitIDEEmu = true;
                    298:        }
                    299: 
                    300:        /* Did change IDE HD slave image? */
                    301:        if (changed->HardDisk.bUseIdeSlaveHardDiskImage != current->HardDisk.bUseIdeSlaveHardDiskImage
                    302:            || (strcmp(changed->HardDisk.szIdeSlaveHardDiskImage, current->HardDisk.szIdeSlaveHardDiskImage)
                    303:                && changed->HardDisk.bUseIdeSlaveHardDiskImage))
1.1.1.3   root      304:        {
1.1.1.5   root      305:                Dprintf("- IDE slave>\n");
1.1.1.3   root      306:                Ide_UnInit();
                    307:                bReInitIDEEmu = true;
1.1       root      308:        }
                    309: 
                    310:        /* Did change blitter, rtc or system type? */
                    311:        if (changed->System.bBlitter != current->System.bBlitter
                    312: #if ENABLE_DSP_EMU
                    313:            || changed->System.nDSPType != current->System.nDSPType
                    314: #endif
                    315:            || changed->System.bRealTimeClock != current->System.bRealTimeClock
                    316:            || changed->System.nMachineType != current->System.nMachineType)
                    317:        {
1.1.1.5   root      318:                Dprintf("- blitter/rtc/dsp/machine>\n");
1.1       root      319:                IoMem_UnInit();
1.1.1.3   root      320:                bReInitIoMem = true;
1.1       root      321:        }
                    322:        
                    323: #if ENABLE_DSP_EMU
                    324:        /* Disabled DSP? */
1.1.1.3   root      325:        if (current->System.nDSPType == DSP_TYPE_EMU &&
                    326:            changed->System.nDSPType != DSP_TYPE_EMU)
1.1       root      327:        {
1.1.1.5   root      328:                Dprintf("- DSP>\n");
1.1.1.10! root      329:                DSP_Disable();
1.1       root      330:        }
                    331: #endif
                    332: 
1.1.1.2   root      333:        /* Did change MIDI settings? */
                    334:        if (current->Midi.bEnableMidi != changed->Midi.bEnableMidi
                    335:            || ((strcmp(changed->Midi.sMidiOutFileName, current->Midi.sMidiOutFileName)
                    336:                 || strcmp(changed->Midi.sMidiInFileName, current->Midi.sMidiInFileName))
                    337:                && changed->Midi.bEnableMidi))
                    338:        {
1.1.1.5   root      339:                Dprintf("- midi>\n");
1.1.1.2   root      340:                Midi_UnInit();
                    341:                bReInitMidi = true;
                    342:        }
                    343: 
1.1       root      344:        /* Copy details to configuration,
                    345:         * so it can be saved out or set on reset
                    346:         */
                    347:        if (changed != &ConfigureParams)
                    348:        {
                    349:                ConfigureParams = *changed;
                    350:        }
                    351: 
                    352:        /* Copy details to global, if we reset copy them all */
                    353:        Configuration_Apply(NeedReset);
                    354: 
                    355: #if ENABLE_DSP_EMU
1.1.1.3   root      356:        if (current->System.nDSPType != DSP_TYPE_EMU &&
                    357:            changed->System.nDSPType == DSP_TYPE_EMU)
1.1       root      358:        {
1.1.1.5   root      359:                Dprintf("- DSP<\n");
1.1.1.10! root      360:                DSP_Enable();
1.1       root      361:        }
                    362: #endif
                    363: 
                    364:        /* Set keyboard remap file */
                    365:        if (ConfigureParams.Keyboard.nKeymapType == KEYMAP_LOADED)
1.1.1.5   root      366:        {
                    367:                Dprintf("- keymap<\n");
1.1       root      368:                Keymap_LoadRemapFile(ConfigureParams.Keyboard.szMappingFileName);
1.1.1.5   root      369:        }
1.1       root      370: 
                    371:        /* Mount a new HD image: */
1.1.1.9   root      372:        if (bReInitAcsiEmu)
1.1       root      373:        {
1.1.1.5   root      374:                Dprintf("- HD<\n");
1.1.1.4   root      375:                HDC_Init();
1.1       root      376:        }
                    377: 
1.1.1.4   root      378:        /* Mount a new IDE HD master or slave image: */
                    379:        if (bReInitIDEEmu && (ConfigureParams.HardDisk.bUseIdeMasterHardDiskImage || ConfigureParams.HardDisk.bUseIdeSlaveHardDiskImage))
1.1.1.3   root      380:        {
1.1.1.5   root      381:                Dprintf("- IDE<\n");
1.1.1.3   root      382:                Ide_Init();
                    383:        }
                    384: 
1.1       root      385:        /* Insert floppies? */
                    386:        for (i = 0; i < MAX_FLOPPYDRIVES; i++)
                    387:        {
                    388:                if (bFloppyInsert[i])
1.1.1.5   root      389:                {
                    390:                        Dprintf("- floppy<\n");
1.1       root      391:                        Floppy_InsertDiskIntoDrive(i);
1.1.1.5   root      392:                }
1.1       root      393:        }
                    394: 
                    395:        /* Mount a new GEMDOS drive? */
                    396:        if (bReInitGemdosDrive && ConfigureParams.HardDisk.bUseHardDiskDirectories)
                    397:        {
1.1.1.5   root      398:                Dprintf("- gemdos HD<\n");
1.1       root      399:                GemDOS_InitDrives();
                    400:        }
                    401: 
                    402:        /* Restart audio sub system if necessary: */
                    403:        if (ConfigureParams.Sound.bEnableSound && !bSoundWorking)
                    404:        {
1.1.1.5   root      405:                Dprintf("- audio<\n");
1.1       root      406:                Audio_Init();
                    407:        }
                    408: 
                    409:        /* Re-initialize the RS232 emulation: */
1.1.1.7   root      410:        if (ConfigureParams.RS232.bEnableRS232)
1.1       root      411:        {
1.1.1.5   root      412:                Dprintf("- RS-232<\n");
1.1       root      413:                RS232_Init();
                    414:        }
                    415: 
                    416:        /* Re-init IO memory map? */
                    417:        if (bReInitIoMem)
                    418:        {
1.1.1.5   root      419:                Dprintf("- IO mem<\n");
1.1       root      420:                IoMem_Init();
                    421:        }
                    422: 
1.1.1.7   root      423:        /* Re-init Printer emulation? */
                    424:        if (bReInitPrinter)
                    425:        {
                    426:                Dprintf("- printer<\n");
                    427:                Printer_Init();
                    428:        }
                    429: 
1.1.1.2   root      430:        /* Re-init MIDI emulation? */
                    431:        if (bReInitMidi)
                    432:        {
1.1.1.5   root      433:                Dprintf("- midi<\n");
1.1.1.2   root      434:                Midi_Init();
                    435:        }
                    436: 
1.1       root      437:        /* Force things associated with screen change */
                    438:        if (bScreenModeChange)
                    439:        {
1.1.1.5   root      440:                Dprintf("- screenmode<\n");
1.1.1.10! root      441:                Screen_ModeChanged(true);
1.1       root      442:        }
                    443: 
                    444:        /* Do we need to perform reset? */
                    445:        if (NeedReset)
                    446:        {
1.1.1.5   root      447:                Dprintf("- reset\n");
1.1       root      448:                Reset_Cold();
                    449:        }
                    450: 
                    451:        /* Go into/return from full screen if flagged */
                    452:        if (!bInFullScreen && ConfigureParams.Screen.bFullScreen)
                    453:                Screen_EnterFullScreen();
                    454:        else if (bInFullScreen && !ConfigureParams.Screen.bFullScreen)
                    455:                Screen_ReturnFromFullScreen();
1.1.1.4   root      456: 
                    457:        /* update statusbar info (CPU, MHz, mem etc) */
                    458:        Statusbar_UpdateInfo();
1.1.1.5   root      459:        Dprintf("done.\n");
1.1       root      460: }
                    461: 
                    462: 
                    463: /*-----------------------------------------------------------------------*/
                    464: /**
                    465:  * Change given Hatari options
1.1.1.3   root      466:  * Return false if parsing failed, true otherwise
1.1       root      467:  */
                    468: static bool Change_Options(int argc, const char *argv[])
                    469: {
                    470:        bool bOK;
                    471:        CNF_PARAMS current;
                    472: 
1.1.1.3   root      473:        Main_PauseEmulation(false);
1.1       root      474: 
                    475:        /* get configuration changes */
                    476:        current = ConfigureParams;
                    477:        ConfigureParams.Screen.bFullScreen = bInFullScreen;
                    478:        bOK = Opt_ParseParameters(argc, argv);
                    479: 
                    480:        /* Check if reset is required and ask user if he really wants to continue */
                    481:        if (bOK && Change_DoNeedReset(&current, &ConfigureParams)
1.1.1.5   root      482:            && current.Log.nAlertDlgLogLevel > LOG_FATAL) {
1.1       root      483:                bOK = DlgAlert_Query("The emulated system must be "
                    484:                                     "reset to apply these changes. "
                    485:                                     "Apply changes now and reset "
                    486:                                     "the emulator?");
                    487:        }
                    488:        /* Copy details to configuration */
                    489:        if (bOK) {
1.1.1.3   root      490:                Change_CopyChangedParamsToConfiguration(&current, &ConfigureParams, false);
1.1       root      491:        } else {
                    492:                ConfigureParams = current;
                    493:        }
                    494: 
                    495:        Main_UnPauseEmulation();
                    496:        return bOK;
                    497: }
                    498: 
                    499: 
                    500: /*-----------------------------------------------------------------------*/
                    501: /**
1.1.1.7   root      502:  * Parse given command line and change Hatari options accordingly.
                    503:  * Given string must be stripped and not empty.
1.1.1.3   root      504:  * Return false if parsing failed or there were no args, true otherwise
1.1       root      505:  */
                    506: bool Change_ApplyCommandline(char *cmdline)
                    507: {
                    508:        int i, argc, inarg;
                    509:        const char **argv;
                    510:        bool ret;
                    511: 
                    512:        /* count args */
                    513:        inarg = argc = 0;
                    514:        for (i = 0; cmdline[i]; i++)
                    515:        {
1.1.1.9   root      516:                if (isspace((unsigned char)cmdline[i]) && cmdline[i-1] != '\\')
1.1       root      517:                {
                    518:                        inarg = 0;
                    519:                        continue;
                    520:                }
                    521:                if (!inarg)
                    522:                {
                    523:                        inarg++;
                    524:                        argc++;
                    525:                }
                    526:        }
                    527:        if (!argc)
                    528:        {
1.1.1.3   root      529:                return false;
1.1       root      530:        }
                    531:        /* 2 = "hatari" + NULL */
                    532:        argv = malloc((argc+2) * sizeof(char*));
                    533:        if (!argv)
                    534:        {
                    535:                perror("command line alloc");
1.1.1.3   root      536:                return false;
1.1       root      537:        }
                    538: 
                    539:        /* parse them to array */
                    540:        fprintf(stderr, "Command line with '%d' arguments:\n", argc);
                    541:        inarg = argc = 0;
                    542:        argv[argc++] = "hatari";
                    543:        for (i = 0; cmdline[i]; i++)
                    544:        {
1.1.1.9   root      545:                if (isspace((unsigned char)cmdline[i]))
1.1       root      546:                {
1.1.1.7   root      547:                        if (cmdline[i-1] != '\\')
1.1       root      548:                        {
1.1.1.7   root      549:                                cmdline[i] = '\0';
                    550:                                if (inarg)
                    551:                                {
                    552:                                        fprintf(stderr, "- '%s'\n", argv[argc-1]);
                    553:                                }
                    554:                                inarg = 0;
                    555:                                continue;
                    556:                        }
                    557:                        else
                    558:                        {
                    559:                                /* remove quote for space */
                    560:                                memcpy(cmdline+i-1, cmdline+i, strlen(cmdline+i)+1);
                    561:                                i--;
1.1       root      562:                        }
                    563:                }
                    564:                if (!inarg)
                    565:                {
                    566:                        argv[argc++] = &(cmdline[i]);
                    567:                        inarg++;
                    568:                }
                    569:        }
                    570:        if (inarg)
                    571:        {
                    572:                fprintf(stderr, "- '%s'\n", argv[argc-1]);
                    573:        }
                    574:        argv[argc] = NULL;
                    575:        
                    576:        /* do args */
                    577:        ret = Change_Options(argc, argv);
1.1.1.3   root      578:        free((void *)argv);
1.1       root      579:        return ret;
                    580: }

unix.superglobalmegacorp.com

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