Annotation of hatari/src/gui-sdl/dlgFloppy.c, revision 1.1.1.5

1.1       root        1: /*
                      2:   Hatari - dlgFloppy.c
                      3: 
1.1.1.4   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: const char DlgFloppy_fileid[] = "Hatari dlgFloppy.c : " __DATE__ " " __TIME__;
                      8: 
                      9: #include <assert.h>
                     10: #include "main.h"
                     11: #include "configuration.h"
                     12: #include "dialog.h"
                     13: #include "sdlgui.h"
                     14: #include "file.h"
                     15: #include "floppy.h"
                     16: 
                     17: 
1.1.1.5 ! root       18: #define FLOPPYDLG_ENABLE_A    3
        !            19: #define FLOPPYDLG_HEADS_DS_A  4
        !            20: #define FLOPPYDLG_EJECTA      5
        !            21: #define FLOPPYDLG_BROWSEA     6
        !            22: #define FLOPPYDLG_DISKA       7
        !            23: 
        !            24: #define FLOPPYDLG_ENABLE_B    9
        !            25: #define FLOPPYDLG_HEADS_DS_B  10
        !            26: #define FLOPPYDLG_EJECTB      11
        !            27: #define FLOPPYDLG_BROWSEB     12
        !            28: #define FLOPPYDLG_DISKB       13
        !            29: 
        !            30: #define FLOPPYDLG_IMGDIR      15
        !            31: #define FLOPPYDLG_BROWSEIMG   16
        !            32: #define FLOPPYDLG_AUTOB       17
        !            33: #define FLOPPYDLG_FASTFLOPPY  18
        !            34: #define FLOPPYDLG_CREATEIMG   19
        !            35: #define FLOPPYDLG_PROTOFF     21
        !            36: #define FLOPPYDLG_PROTON      22
        !            37: #define FLOPPYDLG_PROTAUTO    23
        !            38: #define FLOPPYDLG_EXIT        24
1.1       root       39: 
                     40: 
                     41: /* The floppy disks dialog: */
                     42: static SGOBJ floppydlg[] =
                     43: {
                     44:        { SGBOX, 0, 0, 0,0, 64,20, NULL },
                     45:        { SGTEXT, 0, 0, 25,1, 12,1, "Floppy disks" },
1.1.1.5 ! root       46: 
1.1       root       47:        { SGTEXT, 0, 0, 2,3, 8,1, "Drive A:" },
1.1.1.5 ! root       48:        { SGCHECKBOX, 0, 0, 12,3, 7,1, "Enabled" },
        !            49:        { SGCHECKBOX, 0, 0, 23,3, 12,1, "Double Sided" },
1.1       root       50:        { SGBUTTON, 0, 0, 46,3, 7,1, "Eject" },
                     51:        { SGBUTTON, 0, 0, 54,3, 8,1, "Browse" },
                     52:        { SGTEXT, 0, 0, 3,4, 58,1, NULL },
1.1.1.5 ! root       53: 
1.1       root       54:        { SGTEXT, 0, 0, 2,6, 8,1, "Drive B:" },
1.1.1.5 ! root       55:        { SGCHECKBOX, 0, 0, 12,6, 7,1, "Enabled" },
        !            56:        { SGCHECKBOX, 0, 0, 23,6, 12,1, "Double Sided" },
1.1       root       57:        { SGBUTTON, 0, 0, 46,6, 7,1, "Eject" },
                     58:        { SGBUTTON, 0, 0, 54,6, 8,1, "Browse" },
                     59:        { SGTEXT, 0, 0, 3,7, 58,1, NULL },
1.1.1.5 ! root       60: 
1.1       root       61:        { SGTEXT, 0, 0, 2,9, 32,1, "Default floppy images directory:" },
                     62:        { SGTEXT, 0, 0, 3,10, 58,1, NULL },
                     63:        { SGBUTTON, 0, 0, 54,9, 8,1, "Browse" },
                     64:        { SGCHECKBOX, 0, 0, 2,12, 16,1, "Auto insert B" },
1.1.1.3   root       65:        { SGCHECKBOX, 0, 0, 2,14, 21,1, "Fast floppy access" },
1.1       root       66:        { SGBUTTON, 0, 0, 42,14, 20,1, "Create blank image" },
                     67:        { SGTEXT, 0, 0, 2,16, 17,1, "Write protection:" },
                     68:        { SGRADIOBUT, 0, 0, 21,16, 5,1, "Off" },
                     69:        { SGRADIOBUT, 0, 0, 28,16, 5,1, "On" },
                     70:        { SGRADIOBUT, 0, 0, 34,16, 6,1, "Auto" },
                     71:        { SGBUTTON, SG_DEFAULT, 0, 22,18, 20,1, "Back to main menu" },
                     72:        { -1, 0, 0, 0,0, 0,0, NULL }
                     73: };
                     74: 
                     75: 
1.1.1.2   root       76: #define DLGMOUNT_A       2
                     77: #define DLGMOUNT_B       3
                     78: #define DLGMOUNT_CANCEL  4
                     79: 
                     80: /* The "Alert"-dialog: */
                     81: static SGOBJ alertdlg[] =
                     82: {
                     83:        { SGBOX, 0, 0, 0,0, 40,6, NULL },
                     84:        { SGTEXT, 0, 0, 3,1, 30,1, "Insert last created disk to?" },
                     85:        { SGBUTTON, 0, 0, 3,4, 10,1, "Drive A:" },
                     86:        { SGBUTTON, 0, 0, 15,4, 10,1, "Drive B:" },
                     87:        { SGBUTTON, SG_CANCEL, 0, 27,4, 10,1, "Cancel" },
                     88:        { -1, 0, 0, 0,0, 0,0, NULL }
                     89: };
                     90: 
                     91: 
1.1       root       92: /**
                     93:  * Let user browse given disk, insert disk if one selected.
                     94:  */
1.1.1.2   root       95: static void DlgDisk_BrowseDisk(char *dlgname, int drive, int diskid)
1.1       root       96: {
                     97:        char *selname, *zip_path;
1.1.1.2   root       98:        const char *tmpname, *realname;
1.1       root       99: 
                    100:        assert(drive >= 0 && drive < MAX_FLOPPYDRIVES);
                    101:        if (ConfigureParams.DiskImage.szDiskFileName[drive][0])
                    102:                tmpname = ConfigureParams.DiskImage.szDiskFileName[drive];
                    103:        else
                    104:                tmpname = ConfigureParams.DiskImage.szDiskImageDirectory;
                    105: 
                    106:        selname = SDLGui_FileSelect(tmpname, &zip_path, false);
1.1.1.2   root      107:        if (!selname)
                    108:                return;
                    109: 
                    110:        if (File_Exists(selname))
1.1       root      111:        {
1.1.1.2   root      112:                realname = Floppy_SetDiskFileName(drive, selname, zip_path);
                    113:                if (realname)
                    114:                        File_ShrinkName(dlgname, realname, floppydlg[diskid].w);
                    115:        }
                    116:        else
                    117:        {
                    118:                Floppy_SetDiskFileNameNone(drive);
                    119:                dlgname[0] = '\0';
1.1       root      120:        }
1.1.1.2   root      121:        if (zip_path)
                    122:                free(zip_path);
                    123:        free(selname);
1.1       root      124: }
                    125: 
                    126: 
                    127: /**
                    128:  * Let user browse given directory, set directory if one selected.
                    129:  */
1.1.1.2   root      130: static void DlgDisk_BrowseDir(char *dlgname, char *confname, int maxlen)
1.1       root      131: {
                    132:        char *str, *selname;
                    133: 
                    134:        selname = SDLGui_FileSelect(confname, NULL, false);
1.1.1.2   root      135:        if (!selname)
                    136:                return;
                    137: 
                    138:        strcpy(confname, selname);
                    139:        free(selname);
                    140: 
                    141:        str = strrchr(confname, PATHSEP);
                    142:        if (str != NULL)
                    143:                str[1] = 0;
                    144:        File_CleanFileName(confname);
                    145:        File_ShrinkName(dlgname, confname, maxlen);
                    146: }
                    147: 
                    148: 
                    149: /**
                    150:  * Ask whether new disk should be inserted to A: or B: and if yes, insert.
                    151:  */
                    152: static void DlgFloppy_QueryInsert(char *namea, int ida, char *nameb, int idb, const char *path)
                    153: {
                    154:        const char *realname;
                    155:        int diskid, dlgid;
                    156:        char *dlgname;
1.1       root      157: 
1.1.1.2   root      158:        SDLGui_CenterDlg(alertdlg);
                    159:        switch (SDLGui_DoDialog(alertdlg, NULL))
                    160:        {
                    161:                case DLGMOUNT_A:
                    162:                        dlgname = namea;
                    163:                        dlgid = ida;
                    164:                        diskid = 0;
                    165:                        break;
                    166:                case DLGMOUNT_B:
                    167:                        dlgname = nameb;
                    168:                        dlgid = idb;
                    169:                        diskid = 1;
                    170:                        break;
                    171:                default:
                    172:                        return;
1.1       root      173:        }
1.1.1.2   root      174: 
                    175:        realname = Floppy_SetDiskFileName(diskid, path, NULL);
                    176:        if (realname)
                    177:                File_ShrinkName(dlgname, realname, floppydlg[dlgid].w);
1.1       root      178: }
                    179: 
                    180: 
                    181: /**
                    182:  * Show and process the floppy disk image dialog.
                    183:  */
                    184: void DlgFloppy_Main(void)
                    185: {
                    186:        int but, i;
1.1.1.2   root      187:        char *newdisk;
1.1       root      188:        char dlgname[MAX_FLOPPYDRIVES][64], dlgdiskdir[64];
                    189: 
                    190:        SDLGui_CenterDlg(floppydlg);
                    191: 
                    192:        /* Set up dialog to actual values: */
                    193: 
                    194:        /* Disk name A: */
                    195:        if (EmulationDrives[0].bDiskInserted)
                    196:                File_ShrinkName(dlgname[0], ConfigureParams.DiskImage.szDiskFileName[0],
                    197:                                floppydlg[FLOPPYDLG_DISKA].w);
                    198:        else
                    199:                dlgname[0][0] = '\0';
                    200:        floppydlg[FLOPPYDLG_DISKA].txt = dlgname[0];
                    201: 
                    202:        /* Disk name B: */
                    203:        if (EmulationDrives[1].bDiskInserted)
                    204:                File_ShrinkName(dlgname[1], ConfigureParams.DiskImage.szDiskFileName[1],
                    205:                                floppydlg[FLOPPYDLG_DISKB].w);
                    206:        else
                    207:                dlgname[1][0] = '\0';
                    208:        floppydlg[FLOPPYDLG_DISKB].txt = dlgname[1];
                    209: 
                    210:        /* Default image directory: */
                    211:        File_ShrinkName(dlgdiskdir, ConfigureParams.DiskImage.szDiskImageDirectory,
                    212:                        floppydlg[FLOPPYDLG_IMGDIR].w);
                    213:        floppydlg[FLOPPYDLG_IMGDIR].txt = dlgdiskdir;
                    214: 
                    215:        /* Auto insert disk B: */
                    216:        if (ConfigureParams.DiskImage.bAutoInsertDiskB)
                    217:                floppydlg[FLOPPYDLG_AUTOB].state |= SG_SELECTED;
                    218:        else
                    219:                floppydlg[FLOPPYDLG_AUTOB].state &= ~SG_SELECTED;
                    220: 
                    221:        /* Write protection */
                    222:        for (i = FLOPPYDLG_PROTOFF; i <= FLOPPYDLG_PROTAUTO; i++)
                    223:        {
                    224:                floppydlg[i].state &= ~SG_SELECTED;
                    225:        }
                    226:        floppydlg[FLOPPYDLG_PROTOFF+ConfigureParams.DiskImage.nWriteProtection].state |= SG_SELECTED;
                    227: 
1.1.1.3   root      228:        /* Fast floppy access */
                    229:        if (ConfigureParams.DiskImage.FastFloppy)
                    230:                floppydlg[FLOPPYDLG_FASTFLOPPY].state |= SG_SELECTED;
1.1       root      231:        else
1.1.1.3   root      232:                floppydlg[FLOPPYDLG_FASTFLOPPY].state &= ~SG_SELECTED;
1.1       root      233: 
1.1.1.5 ! root      234:        /* Enable/disable drives A: and B: */
        !           235:        if (ConfigureParams.DiskImage.EnableDriveA)
        !           236:                floppydlg[FLOPPYDLG_ENABLE_A].state |= SG_SELECTED;
        !           237:        else
        !           238:                floppydlg[FLOPPYDLG_ENABLE_A].state &= ~SG_SELECTED;
        !           239: 
        !           240:        if (ConfigureParams.DiskImage.EnableDriveB)
        !           241:                floppydlg[FLOPPYDLG_ENABLE_B].state |= SG_SELECTED;
        !           242:        else
        !           243:                floppydlg[FLOPPYDLG_ENABLE_B].state &= ~SG_SELECTED;
        !           244: 
        !           245:        /* Set drives to single sided or double sided */
        !           246:        if (ConfigureParams.DiskImage.DriveA_NumberOfHeads == 2)
        !           247:                floppydlg[FLOPPYDLG_HEADS_DS_A].state |= SG_SELECTED;
        !           248:        else
        !           249:                floppydlg[FLOPPYDLG_HEADS_DS_A].state &= ~SG_SELECTED;
        !           250: 
        !           251:        if (ConfigureParams.DiskImage.DriveB_NumberOfHeads == 2)
        !           252:                floppydlg[FLOPPYDLG_HEADS_DS_B].state |= SG_SELECTED;
        !           253:        else
        !           254:                floppydlg[FLOPPYDLG_HEADS_DS_B].state &= ~SG_SELECTED;
        !           255: 
        !           256: 
1.1       root      257:        /* Draw and process the dialog */
                    258:        do
                    259:        {
                    260:                but = SDLGui_DoDialog(floppydlg, NULL);
                    261:                switch (but)
                    262:                {
                    263:                 case FLOPPYDLG_EJECTA:                         /* Eject disk in drive A: */
                    264:                        Floppy_SetDiskFileNameNone(0);
                    265:                        dlgname[0][0] = '\0';
                    266:                        break;
                    267:                 case FLOPPYDLG_BROWSEA:                        /* Choose a new disk A: */
                    268:                        DlgDisk_BrowseDisk(dlgname[0], 0, FLOPPYDLG_DISKA);
                    269:                        break;
                    270:                 case FLOPPYDLG_EJECTB:                         /* Eject disk in drive B: */
                    271:                        Floppy_SetDiskFileNameNone(1);
                    272:                        dlgname[1][0] = '\0';
                    273:                        break;
                    274:                case FLOPPYDLG_BROWSEB:                         /* Choose a new disk B: */
                    275:                        DlgDisk_BrowseDisk(dlgname[1], 1, FLOPPYDLG_DISKB);
                    276:                        break;
                    277:                 case FLOPPYDLG_BROWSEIMG:
                    278:                        DlgDisk_BrowseDir(dlgdiskdir,
                    279:                                         ConfigureParams.DiskImage.szDiskImageDirectory,
                    280:                                         floppydlg[FLOPPYDLG_IMGDIR].w);
                    281:                        break;
                    282:                 case FLOPPYDLG_CREATEIMG:
1.1.1.2   root      283:                        newdisk = DlgNewDisk_Main();
                    284:                        if (newdisk)
                    285:                        {
                    286:                                DlgFloppy_QueryInsert(dlgname[0], FLOPPYDLG_DISKA,
                    287:                                                      dlgname[1], FLOPPYDLG_DISKB,
                    288:                                                      newdisk);
                    289:                                free(newdisk);
                    290:                        }
1.1       root      291:                        break;
                    292:                }
                    293:        }
                    294:        while (but != FLOPPYDLG_EXIT && but != SDLGUI_QUIT
                    295:                && but != SDLGUI_ERROR && !bQuitProgram);
                    296: 
                    297:        /* Read values from dialog: */
                    298: 
                    299:        for (i = FLOPPYDLG_PROTOFF; i <= FLOPPYDLG_PROTAUTO; i++)
                    300:        {
                    301:                if (floppydlg[i].state & SG_SELECTED)
                    302:                {
                    303:                        ConfigureParams.DiskImage.nWriteProtection = i-FLOPPYDLG_PROTOFF;
                    304:                        break;
                    305:                }
                    306:        }
                    307: 
                    308:        ConfigureParams.DiskImage.bAutoInsertDiskB = (floppydlg[FLOPPYDLG_AUTOB].state & SG_SELECTED);
1.1.1.3   root      309:        ConfigureParams.DiskImage.FastFloppy = (floppydlg[FLOPPYDLG_FASTFLOPPY].state & SG_SELECTED);
1.1.1.5 ! root      310:        ConfigureParams.DiskImage.EnableDriveA = (floppydlg[FLOPPYDLG_ENABLE_A].state & SG_SELECTED);
        !           311:        ConfigureParams.DiskImage.EnableDriveB = (floppydlg[FLOPPYDLG_ENABLE_B].state & SG_SELECTED);
        !           312:        ConfigureParams.DiskImage.DriveA_NumberOfHeads = ( (floppydlg[FLOPPYDLG_HEADS_DS_A].state & SG_SELECTED) ? 2 : 1 );
        !           313:        ConfigureParams.DiskImage.DriveB_NumberOfHeads = ( (floppydlg[FLOPPYDLG_HEADS_DS_B].state & SG_SELECTED) ? 2 : 1 );
1.1       root      314: }

unix.superglobalmegacorp.com

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