|
|
1.1 root 1: /*
2: Hatari - dlgFloppy.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: 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:
18: #define FLOPPYDLG_EJECTA 3
19: #define FLOPPYDLG_BROWSEA 4
20: #define FLOPPYDLG_DISKA 5
21: #define FLOPPYDLG_EJECTB 7
22: #define FLOPPYDLG_BROWSEB 8
23: #define FLOPPYDLG_DISKB 9
24: #define FLOPPYDLG_IMGDIR 11
25: #define FLOPPYDLG_BROWSEIMG 12
26: #define FLOPPYDLG_AUTOB 13
27: #define FLOPPYDLG_SLOWFLOPPY 14
28: #define FLOPPYDLG_CREATEIMG 15
29: #define FLOPPYDLG_PROTOFF 17
30: #define FLOPPYDLG_PROTON 18
31: #define FLOPPYDLG_PROTAUTO 19
32: #define FLOPPYDLG_EXIT 20
33:
34:
35: /* The floppy disks dialog: */
36: static SGOBJ floppydlg[] =
37: {
38: { SGBOX, 0, 0, 0,0, 64,20, NULL },
39: { SGTEXT, 0, 0, 25,1, 12,1, "Floppy disks" },
40: { SGTEXT, 0, 0, 2,3, 8,1, "Drive A:" },
41: { SGBUTTON, 0, 0, 46,3, 7,1, "Eject" },
42: { SGBUTTON, 0, 0, 54,3, 8,1, "Browse" },
43: { SGTEXT, 0, 0, 3,4, 58,1, NULL },
44: { SGTEXT, 0, 0, 2,6, 8,1, "Drive B:" },
45: { SGBUTTON, 0, 0, 46,6, 7,1, "Eject" },
46: { SGBUTTON, 0, 0, 54,6, 8,1, "Browse" },
47: { SGTEXT, 0, 0, 3,7, 58,1, NULL },
48: { SGTEXT, 0, 0, 2,9, 32,1, "Default floppy images directory:" },
49: { SGTEXT, 0, 0, 3,10, 58,1, NULL },
50: { SGBUTTON, 0, 0, 54,9, 8,1, "Browse" },
51: { SGCHECKBOX, 0, 0, 2,12, 16,1, "Auto insert B" },
52: { SGCHECKBOX, 0, 0, 2,14, 21,1, "Slow floppy access" },
53: { SGBUTTON, 0, 0, 42,14, 20,1, "Create blank image" },
54: { SGTEXT, 0, 0, 2,16, 17,1, "Write protection:" },
55: { SGRADIOBUT, 0, 0, 21,16, 5,1, "Off" },
56: { SGRADIOBUT, 0, 0, 28,16, 5,1, "On" },
57: { SGRADIOBUT, 0, 0, 34,16, 6,1, "Auto" },
58: { SGBUTTON, SG_DEFAULT, 0, 22,18, 20,1, "Back to main menu" },
59: { -1, 0, 0, 0,0, 0,0, NULL }
60: };
61:
62:
63: /**
64: * Let user browse given disk, insert disk if one selected.
65: * return false if no disk selected, otherwise return true.
66: */
67: static bool DlgDisk_BrowseDisk(char *dlgname, int drive, int diskid)
68: {
69: char *selname, *zip_path;
70: const char *tmpname;
71:
72: assert(drive >= 0 && drive < MAX_FLOPPYDRIVES);
73: if (ConfigureParams.DiskImage.szDiskFileName[drive][0])
74: tmpname = ConfigureParams.DiskImage.szDiskFileName[drive];
75: else
76: tmpname = ConfigureParams.DiskImage.szDiskImageDirectory;
77:
78: selname = SDLGui_FileSelect(tmpname, &zip_path, false);
79: if (selname)
80: {
81: if (File_Exists(selname))
82: {
83: const char *realname;
84: realname = Floppy_SetDiskFileName(drive, selname, zip_path);
85: /* TODO: error dialog when this fails */
86: if (realname)
87: {
88: File_ShrinkName(dlgname, realname, floppydlg[diskid].w);
89: }
90: }
91: else
92: {
93: Floppy_SetDiskFileNameNone(drive);
94: dlgname[0] = '\0';
95: }
96: if (zip_path)
97: free(zip_path);
98: free(selname);
99: return true;
100: }
101: return false;
102: }
103:
104:
105: /**
106: * Let user browse given directory, set directory if one selected.
107: * return false if none selected, otherwise return true.
108: */
109: static bool DlgDisk_BrowseDir(char *dlgname, char *confname, int maxlen)
110: {
111: char *str, *selname;
112:
113: selname = SDLGui_FileSelect(confname, NULL, false);
114: if (selname)
115: {
116: strcpy(confname, selname);
117: free(selname);
118:
119: str = strrchr(confname, PATHSEP);
120: if (str != NULL)
121: str[1] = 0;
122: File_CleanFileName(confname);
123: File_ShrinkName(dlgname, confname, maxlen);
124: return true;
125: }
126: return false;
127: }
128:
129:
130: /**
131: * Show and process the floppy disk image dialog.
132: */
133: void DlgFloppy_Main(void)
134: {
135: int but, i;
136: char dlgname[MAX_FLOPPYDRIVES][64], dlgdiskdir[64];
137:
138: SDLGui_CenterDlg(floppydlg);
139:
140: /* Set up dialog to actual values: */
141:
142: /* Disk name A: */
143: if (EmulationDrives[0].bDiskInserted)
144: File_ShrinkName(dlgname[0], ConfigureParams.DiskImage.szDiskFileName[0],
145: floppydlg[FLOPPYDLG_DISKA].w);
146: else
147: dlgname[0][0] = '\0';
148: floppydlg[FLOPPYDLG_DISKA].txt = dlgname[0];
149:
150: /* Disk name B: */
151: if (EmulationDrives[1].bDiskInserted)
152: File_ShrinkName(dlgname[1], ConfigureParams.DiskImage.szDiskFileName[1],
153: floppydlg[FLOPPYDLG_DISKB].w);
154: else
155: dlgname[1][0] = '\0';
156: floppydlg[FLOPPYDLG_DISKB].txt = dlgname[1];
157:
158: /* Default image directory: */
159: File_ShrinkName(dlgdiskdir, ConfigureParams.DiskImage.szDiskImageDirectory,
160: floppydlg[FLOPPYDLG_IMGDIR].w);
161: floppydlg[FLOPPYDLG_IMGDIR].txt = dlgdiskdir;
162:
163: /* Auto insert disk B: */
164: if (ConfigureParams.DiskImage.bAutoInsertDiskB)
165: floppydlg[FLOPPYDLG_AUTOB].state |= SG_SELECTED;
166: else
167: floppydlg[FLOPPYDLG_AUTOB].state &= ~SG_SELECTED;
168:
169: /* Write protection */
170: for (i = FLOPPYDLG_PROTOFF; i <= FLOPPYDLG_PROTAUTO; i++)
171: {
172: floppydlg[i].state &= ~SG_SELECTED;
173: }
174: floppydlg[FLOPPYDLG_PROTOFF+ConfigureParams.DiskImage.nWriteProtection].state |= SG_SELECTED;
175:
176: /* Slow floppy access */
177: if (ConfigureParams.DiskImage.bSlowFloppy)
178: floppydlg[FLOPPYDLG_SLOWFLOPPY].state |= SG_SELECTED;
179: else
180: floppydlg[FLOPPYDLG_SLOWFLOPPY].state &= ~SG_SELECTED;
181:
182: /* Draw and process the dialog */
183: do
184: {
185: but = SDLGui_DoDialog(floppydlg, NULL);
186: switch (but)
187: {
188: case FLOPPYDLG_EJECTA: /* Eject disk in drive A: */
189: Floppy_SetDiskFileNameNone(0);
190: dlgname[0][0] = '\0';
191: break;
192: case FLOPPYDLG_BROWSEA: /* Choose a new disk A: */
193: DlgDisk_BrowseDisk(dlgname[0], 0, FLOPPYDLG_DISKA);
194: break;
195: case FLOPPYDLG_EJECTB: /* Eject disk in drive B: */
196: Floppy_SetDiskFileNameNone(1);
197: dlgname[1][0] = '\0';
198: break;
199: case FLOPPYDLG_BROWSEB: /* Choose a new disk B: */
200: DlgDisk_BrowseDisk(dlgname[1], 1, FLOPPYDLG_DISKB);
201: break;
202: case FLOPPYDLG_BROWSEIMG:
203: DlgDisk_BrowseDir(dlgdiskdir,
204: ConfigureParams.DiskImage.szDiskImageDirectory,
205: floppydlg[FLOPPYDLG_IMGDIR].w);
206: break;
207: case FLOPPYDLG_CREATEIMG:
208: DlgNewDisk_Main();
209: break;
210: }
211: }
212: while (but != FLOPPYDLG_EXIT && but != SDLGUI_QUIT
213: && but != SDLGUI_ERROR && !bQuitProgram);
214:
215: /* Read values from dialog: */
216:
217: for (i = FLOPPYDLG_PROTOFF; i <= FLOPPYDLG_PROTAUTO; i++)
218: {
219: if (floppydlg[i].state & SG_SELECTED)
220: {
221: ConfigureParams.DiskImage.nWriteProtection = i-FLOPPYDLG_PROTOFF;
222: break;
223: }
224: }
225:
226: ConfigureParams.DiskImage.bAutoInsertDiskB = (floppydlg[FLOPPYDLG_AUTOB].state & SG_SELECTED);
227: ConfigureParams.DiskImage.bSlowFloppy = (floppydlg[FLOPPYDLG_SLOWFLOPPY].state & SG_SELECTED);
228: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.