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

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.11  root       48: #define Dprintf(...) printf(__VA_ARGS__)
1.1.1.5   root       49: #else
1.1.1.11  root       50: #define Dprintf(...)
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? */
1.1.1.12! root      151:        if (current->Memory.TTRamSize_KB != changed->Memory.TTRamSize_KB)
1.1.1.10  root      152:                return true;
1.1.1.5   root      153: #endif
                    154: 
1.1       root      155:        /* Did change size of memory? */
1.1.1.12! root      156:        if (current->Memory.STRamSize_KB != changed->Memory.STRamSize_KB)
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
1.1.1.12! root      203:             || changed->Screen.bResizable != current->Screen.bResizable
1.1.1.10  root      204:             || changed->Screen.bUseVsync != current->Screen.bUseVsync
                    205: #endif
                    206:            ))
1.1       root      207:        {
1.1.1.5   root      208:                Dprintf("- screenmode>\n");
1.1.1.3   root      209:                bScreenModeChange = true;
1.1       root      210:        }
                    211: 
                    212:        /* Did set new printer parameters? */
                    213:        if (changed->Printer.bEnablePrinting != current->Printer.bEnablePrinting
                    214:            || strcmp(changed->Printer.szPrintToFileName,current->Printer.szPrintToFileName))
                    215:        {
1.1.1.5   root      216:                Dprintf("- printer>\n");
1.1.1.7   root      217:                Printer_UnInit();
                    218:                bReInitPrinter = true;
1.1       root      219:        }
                    220: 
                    221:        /* Did set new RS232 parameters? */
                    222:        if (changed->RS232.bEnableRS232 != current->RS232.bEnableRS232
                    223:            || strcmp(changed->RS232.szOutFileName, current->RS232.szOutFileName)
                    224:            || strcmp(changed->RS232.szInFileName, current->RS232.szInFileName))
                    225:        {
1.1.1.5   root      226:                Dprintf("- RS-232>\n");
1.1       root      227:                RS232_UnInit();
                    228:        }
                    229: 
                    230:        /* Did stop sound? Or change playback Hz. If so, also stop sound recording */
1.1.1.3   root      231:        if (!changed->Sound.bEnableSound || changed->Sound.nPlaybackFreq != current->Sound.nPlaybackFreq)
1.1       root      232:        {
1.1.1.5   root      233:                Dprintf("- sound>\n");
1.1       root      234:                if (Sound_AreWeRecording())
                    235:                        Sound_EndRecording();
                    236:                Audio_UnInit();
                    237:        }
                    238: 
                    239:        /* Did change floppy (images)? */
                    240:        for (i = 0; i < MAX_FLOPPYDRIVES; i++)
                    241:        {
                    242:                /*
                    243:                Log_Printf(LOG_DEBUG, "Old and new disk %c:\n\t%s\n\t%s", 'A'+i,
                    244:                           current->DiskImage.szDiskFileName[i],
                    245:                           changed->DiskImage.szDiskFileName[i]);
                    246:                 */
                    247:                if (strcmp(changed->DiskImage.szDiskFileName[i],
                    248:                           current->DiskImage.szDiskFileName[i])
                    249:                    || strcmp(changed->DiskImage.szDiskZipPath[i],
                    250:                              current->DiskImage.szDiskZipPath[i]))
1.1.1.3   root      251:                        bFloppyInsert[i] = true;
1.1       root      252:                else
1.1.1.3   root      253:                        bFloppyInsert[i] = false;
1.1       root      254:        }
                    255: 
1.1.1.9   root      256:        if ( changed->DiskImage.EnableDriveA != current->DiskImage.EnableDriveA )
                    257:                FDC_Drive_Set_Enable ( 0 , changed->DiskImage.EnableDriveA );
                    258:        if ( changed->DiskImage.EnableDriveB != current->DiskImage.EnableDriveB )
                    259:                FDC_Drive_Set_Enable ( 1 , changed->DiskImage.EnableDriveB );
                    260: 
                    261:        if ( changed->DiskImage.DriveA_NumberOfHeads != current->DiskImage.DriveA_NumberOfHeads )
                    262:                FDC_Drive_Set_NumberOfHeads ( 0 , changed->DiskImage.DriveA_NumberOfHeads );
                    263:        if ( changed->DiskImage.DriveB_NumberOfHeads != current->DiskImage.DriveB_NumberOfHeads )
                    264:                FDC_Drive_Set_NumberOfHeads ( 1 , changed->DiskImage.DriveB_NumberOfHeads );
                    265: 
1.1.1.10  root      266:        /* Did change GEMDOS drive Atari/host location or enabling? */
                    267:        if (changed->HardDisk.nGemdosDrive != current->HardDisk.nGemdosDrive
                    268:            || changed->HardDisk.bUseHardDiskDirectories != current->HardDisk.bUseHardDiskDirectories
1.1       root      269:            || (strcmp(changed->HardDisk.szHardDiskDirectories[0], current->HardDisk.szHardDiskDirectories[0])
                    270:                && changed->HardDisk.bUseHardDiskDirectories))
                    271:        {
1.1.1.5   root      272:                Dprintf("- gemdos HD>\n");
1.1       root      273:                GemDOS_UnInitDrives();
1.1.1.3   root      274:                bReInitGemdosDrive = true;
1.1       root      275:        }
                    276: 
1.1.1.9   root      277:        /* Did change ACSI image? */
                    278:        for (i = 0; i < MAX_ACSI_DEVS; i++)
1.1       root      279:        {
1.1.1.9   root      280:                if (changed->Acsi[i].bUseDevice != current->Acsi[i].bUseDevice
                    281:                    || (strcmp(changed->Acsi[i].sDeviceFile, current->Acsi[i].sDeviceFile)
                    282:                        && changed->Acsi[i].bUseDevice))
                    283:                {
                    284:                        Dprintf("- ACSI image %i>\n", i);
                    285:                        bReInitAcsiEmu = true;
                    286:                }
1.1.1.3   root      287:        }
1.1.1.9   root      288:        if (bReInitAcsiEmu)
                    289:                HDC_UnInit();
                    290: 
1.1.1.4   root      291:        /* Did change IDE HD master image? */
                    292:        if (changed->HardDisk.bUseIdeMasterHardDiskImage != current->HardDisk.bUseIdeMasterHardDiskImage
                    293:            || (strcmp(changed->HardDisk.szIdeMasterHardDiskImage, current->HardDisk.szIdeMasterHardDiskImage)
                    294:                && changed->HardDisk.bUseIdeMasterHardDiskImage))
                    295:        {
1.1.1.5   root      296:                Dprintf("- IDE master>\n");
1.1.1.4   root      297:                Ide_UnInit();
                    298:                bReInitIDEEmu = true;
                    299:        }
                    300: 
                    301:        /* Did change IDE HD slave image? */
                    302:        if (changed->HardDisk.bUseIdeSlaveHardDiskImage != current->HardDisk.bUseIdeSlaveHardDiskImage
                    303:            || (strcmp(changed->HardDisk.szIdeSlaveHardDiskImage, current->HardDisk.szIdeSlaveHardDiskImage)
                    304:                && changed->HardDisk.bUseIdeSlaveHardDiskImage))
1.1.1.3   root      305:        {
1.1.1.5   root      306:                Dprintf("- IDE slave>\n");
1.1.1.3   root      307:                Ide_UnInit();
                    308:                bReInitIDEEmu = true;
1.1       root      309:        }
                    310: 
1.1.1.11  root      311:        /* Did change blitter, DSP or system type? */
1.1       root      312:        if (changed->System.bBlitter != current->System.bBlitter
                    313: #if ENABLE_DSP_EMU
                    314:            || changed->System.nDSPType != current->System.nDSPType
                    315: #endif
                    316:            || changed->System.nMachineType != current->System.nMachineType)
                    317:        {
1.1.1.11  root      318:                Dprintf("- blitter/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
1.1.1.12! root      335: #ifdef HAVE_PORTMIDI
        !           336:            || strcmp(changed->Midi.sMidiOutPortName, current->Midi.sMidiOutPortName)
        !           337:            || strcmp(changed->Midi.sMidiInPortName, current->Midi.sMidiInPortName)
        !           338: #else
        !           339:            || strcmp(changed->Midi.sMidiOutFileName, current->Midi.sMidiOutFileName)
        !           340:            || strcmp(changed->Midi.sMidiInFileName, current->Midi.sMidiInFileName)
        !           341: #endif
        !           342:            )
1.1.1.2   root      343:        {
1.1.1.5   root      344:                Dprintf("- midi>\n");
1.1.1.2   root      345:                Midi_UnInit();
                    346:                bReInitMidi = true;
                    347:        }
                    348: 
1.1       root      349:        /* Copy details to configuration,
                    350:         * so it can be saved out or set on reset
                    351:         */
                    352:        if (changed != &ConfigureParams)
                    353:        {
                    354:                ConfigureParams = *changed;
                    355:        }
                    356: 
                    357:        /* Copy details to global, if we reset copy them all */
                    358:        Configuration_Apply(NeedReset);
                    359: 
                    360: #if ENABLE_DSP_EMU
1.1.1.3   root      361:        if (current->System.nDSPType != DSP_TYPE_EMU &&
                    362:            changed->System.nDSPType == DSP_TYPE_EMU)
1.1       root      363:        {
1.1.1.5   root      364:                Dprintf("- DSP<\n");
1.1.1.10  root      365:                DSP_Enable();
1.1       root      366:        }
                    367: #endif
                    368: 
                    369:        /* Set keyboard remap file */
                    370:        if (ConfigureParams.Keyboard.nKeymapType == KEYMAP_LOADED)
1.1.1.5   root      371:        {
                    372:                Dprintf("- keymap<\n");
1.1       root      373:                Keymap_LoadRemapFile(ConfigureParams.Keyboard.szMappingFileName);
1.1.1.5   root      374:        }
1.1       root      375: 
                    376:        /* Mount a new HD image: */
1.1.1.9   root      377:        if (bReInitAcsiEmu)
1.1       root      378:        {
1.1.1.5   root      379:                Dprintf("- HD<\n");
1.1.1.4   root      380:                HDC_Init();
1.1       root      381:        }
                    382: 
1.1.1.4   root      383:        /* Mount a new IDE HD master or slave image: */
                    384:        if (bReInitIDEEmu && (ConfigureParams.HardDisk.bUseIdeMasterHardDiskImage || ConfigureParams.HardDisk.bUseIdeSlaveHardDiskImage))
1.1.1.3   root      385:        {
1.1.1.5   root      386:                Dprintf("- IDE<\n");
1.1.1.3   root      387:                Ide_Init();
                    388:        }
                    389: 
1.1       root      390:        /* Insert floppies? */
                    391:        for (i = 0; i < MAX_FLOPPYDRIVES; i++)
                    392:        {
                    393:                if (bFloppyInsert[i])
1.1.1.5   root      394:                {
                    395:                        Dprintf("- floppy<\n");
1.1       root      396:                        Floppy_InsertDiskIntoDrive(i);
1.1.1.5   root      397:                }
1.1       root      398:        }
                    399: 
                    400:        /* Mount a new GEMDOS drive? */
                    401:        if (bReInitGemdosDrive && ConfigureParams.HardDisk.bUseHardDiskDirectories)
                    402:        {
1.1.1.5   root      403:                Dprintf("- gemdos HD<\n");
1.1       root      404:                GemDOS_InitDrives();
                    405:        }
                    406: 
                    407:        /* Restart audio sub system if necessary: */
                    408:        if (ConfigureParams.Sound.bEnableSound && !bSoundWorking)
                    409:        {
1.1.1.5   root      410:                Dprintf("- audio<\n");
1.1       root      411:                Audio_Init();
                    412:        }
                    413: 
                    414:        /* Re-initialize the RS232 emulation: */
1.1.1.7   root      415:        if (ConfigureParams.RS232.bEnableRS232)
1.1       root      416:        {
1.1.1.5   root      417:                Dprintf("- RS-232<\n");
1.1       root      418:                RS232_Init();
                    419:        }
                    420: 
                    421:        /* Re-init IO memory map? */
                    422:        if (bReInitIoMem)
                    423:        {
1.1.1.5   root      424:                Dprintf("- IO mem<\n");
1.1       root      425:                IoMem_Init();
                    426:        }
                    427: 
1.1.1.7   root      428:        /* Re-init Printer emulation? */
                    429:        if (bReInitPrinter)
                    430:        {
                    431:                Dprintf("- printer<\n");
                    432:                Printer_Init();
                    433:        }
                    434: 
1.1.1.2   root      435:        /* Re-init MIDI emulation? */
                    436:        if (bReInitMidi)
                    437:        {
1.1.1.5   root      438:                Dprintf("- midi<\n");
1.1.1.2   root      439:                Midi_Init();
                    440:        }
                    441: 
1.1       root      442:        /* Force things associated with screen change */
                    443:        if (bScreenModeChange)
                    444:        {
1.1.1.5   root      445:                Dprintf("- screenmode<\n");
1.1.1.10  root      446:                Screen_ModeChanged(true);
1.1       root      447:        }
                    448: 
                    449:        /* Do we need to perform reset? */
                    450:        if (NeedReset)
                    451:        {
1.1.1.5   root      452:                Dprintf("- reset\n");
1.1       root      453:                Reset_Cold();
                    454:        }
                    455: 
                    456:        /* Go into/return from full screen if flagged */
                    457:        if (!bInFullScreen && ConfigureParams.Screen.bFullScreen)
                    458:                Screen_EnterFullScreen();
                    459:        else if (bInFullScreen && !ConfigureParams.Screen.bFullScreen)
                    460:                Screen_ReturnFromFullScreen();
1.1.1.4   root      461: 
                    462:        /* update statusbar info (CPU, MHz, mem etc) */
                    463:        Statusbar_UpdateInfo();
1.1.1.5   root      464:        Dprintf("done.\n");
1.1       root      465: }
                    466: 
                    467: 
                    468: /*-----------------------------------------------------------------------*/
                    469: /**
                    470:  * Change given Hatari options
1.1.1.3   root      471:  * Return false if parsing failed, true otherwise
1.1       root      472:  */
                    473: static bool Change_Options(int argc, const char *argv[])
                    474: {
                    475:        bool bOK;
                    476:        CNF_PARAMS current;
                    477: 
1.1.1.3   root      478:        Main_PauseEmulation(false);
1.1       root      479: 
                    480:        /* get configuration changes */
                    481:        current = ConfigureParams;
                    482:        ConfigureParams.Screen.bFullScreen = bInFullScreen;
                    483:        bOK = Opt_ParseParameters(argc, argv);
                    484: 
                    485:        /* Check if reset is required and ask user if he really wants to continue */
                    486:        if (bOK && Change_DoNeedReset(&current, &ConfigureParams)
1.1.1.5   root      487:            && current.Log.nAlertDlgLogLevel > LOG_FATAL) {
1.1       root      488:                bOK = DlgAlert_Query("The emulated system must be "
                    489:                                     "reset to apply these changes. "
                    490:                                     "Apply changes now and reset "
                    491:                                     "the emulator?");
                    492:        }
                    493:        /* Copy details to configuration */
                    494:        if (bOK) {
1.1.1.3   root      495:                Change_CopyChangedParamsToConfiguration(&current, &ConfigureParams, false);
1.1       root      496:        } else {
                    497:                ConfigureParams = current;
                    498:        }
                    499: 
                    500:        Main_UnPauseEmulation();
                    501:        return bOK;
                    502: }
                    503: 
                    504: 
                    505: /*-----------------------------------------------------------------------*/
                    506: /**
1.1.1.7   root      507:  * Parse given command line and change Hatari options accordingly.
                    508:  * Given string must be stripped and not empty.
1.1.1.3   root      509:  * Return false if parsing failed or there were no args, true otherwise
1.1       root      510:  */
                    511: bool Change_ApplyCommandline(char *cmdline)
                    512: {
                    513:        int i, argc, inarg;
                    514:        const char **argv;
                    515:        bool ret;
                    516: 
                    517:        /* count args */
                    518:        inarg = argc = 0;
                    519:        for (i = 0; cmdline[i]; i++)
                    520:        {
1.1.1.9   root      521:                if (isspace((unsigned char)cmdline[i]) && cmdline[i-1] != '\\')
1.1       root      522:                {
                    523:                        inarg = 0;
                    524:                        continue;
                    525:                }
                    526:                if (!inarg)
                    527:                {
                    528:                        inarg++;
                    529:                        argc++;
                    530:                }
                    531:        }
                    532:        if (!argc)
                    533:        {
1.1.1.3   root      534:                return false;
1.1       root      535:        }
                    536:        /* 2 = "hatari" + NULL */
                    537:        argv = malloc((argc+2) * sizeof(char*));
                    538:        if (!argv)
                    539:        {
                    540:                perror("command line alloc");
1.1.1.3   root      541:                return false;
1.1       root      542:        }
                    543: 
                    544:        /* parse them to array */
                    545:        fprintf(stderr, "Command line with '%d' arguments:\n", argc);
                    546:        inarg = argc = 0;
                    547:        argv[argc++] = "hatari";
                    548:        for (i = 0; cmdline[i]; i++)
                    549:        {
1.1.1.9   root      550:                if (isspace((unsigned char)cmdline[i]))
1.1       root      551:                {
1.1.1.7   root      552:                        if (cmdline[i-1] != '\\')
1.1       root      553:                        {
1.1.1.7   root      554:                                cmdline[i] = '\0';
                    555:                                if (inarg)
                    556:                                {
                    557:                                        fprintf(stderr, "- '%s'\n", argv[argc-1]);
                    558:                                }
                    559:                                inarg = 0;
                    560:                                continue;
                    561:                        }
                    562:                        else
                    563:                        {
                    564:                                /* remove quote for space */
                    565:                                memcpy(cmdline+i-1, cmdline+i, strlen(cmdline+i)+1);
                    566:                                i--;
1.1       root      567:                        }
                    568:                }
                    569:                if (!inarg)
                    570:                {
                    571:                        argv[argc++] = &(cmdline[i]);
                    572:                        inarg++;
                    573:                }
                    574:        }
                    575:        if (inarg)
                    576:        {
                    577:                fprintf(stderr, "- '%s'\n", argv[argc-1]);
                    578:        }
                    579:        argv[argc] = NULL;
                    580:        
                    581:        /* do args */
                    582:        ret = Change_Options(argc, argv);
1.1.1.3   root      583:        free((void *)argv);
1.1       root      584:        return ret;
                    585: }

unix.superglobalmegacorp.com

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