|
|
1.1 root 1: /*
2: Hatari - dlgDisc.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: */
1.1.1.2 ! root 7: char DlgDisc_rcsid[] = "Hatari $Id: dlgDisc.c,v 1.11 2005/02/25 13:28:47 thothy Exp $";
1.1 root 8:
9: #include "main.h"
10: #include "configuration.h"
11: #include "dialog.h"
12: #include "sdlgui.h"
13: #include "file.h"
14: #include "floppy.h"
15: #include "gemdos.h"
16: #include "hdc.h"
17:
18:
19: #define DISCDLG_EJECTA 4
20: #define DISCDLG_BROWSEA 5
21: #define DISCDLG_DISCA 6
22: #define DISCDLG_EJECTB 8
23: #define DISCDLG_BROWSEB 9
24: #define DISCDLG_DISCB 10
25: #define DISCDLG_IMGDIR 12
26: #define DISCDLG_BROWSEIMG 13
27: #define DISCDLG_AUTOB 14
28: #define DISCDLG_CREATEIMG 15
1.1.1.2 ! root 29: #define DISCDLG_PROTOFF 17
! 30: #define DISCDLG_PROTON 18
! 31: #define DISCDLG_PROTAUTO 19
! 32: #define DISCDLG_EJECTHDIMG 23
! 33: #define DISCDLG_BROWSEHDIMG 24
! 34: #define DISCDLG_DISCHDIMG 25
! 35: #define DISCDLG_UNMOUNTGDOS 27
! 36: #define DISCDLG_BROWSEGDOS 28
! 37: #define DISCDLG_DISCGDOS 29
! 38: #define DISCDLG_BOOTHD 30
! 39: #define DISCDLG_EXIT 31
1.1 root 40:
41:
42: /* The discs dialog: */
43: static SGOBJ discdlg[] =
44: {
45: { SGBOX, 0, 0, 0,0, 64,25, NULL },
1.1.1.2 ! root 46:
! 47: { SGBOX, 0, 0, 1,1, 62,12, NULL },
1.1 root 48: { SGTEXT, 0, 0, 25,1, 12,1, "Floppy discs" },
49: { SGTEXT, 0, 0, 2,2, 8,1, "Drive A:" },
50: { SGBUTTON, 0, 0, 46,2, 7,1, "Eject" },
51: { SGBUTTON, 0, 0, 54,2, 8,1, "Browse" },
52: { SGTEXT, 0, 0, 3,3, 58,1, NULL },
53: { SGTEXT, 0, 0, 2,4, 8,1, "Drive B:" },
54: { SGBUTTON, 0, 0, 46,4, 7,1, "Eject" },
55: { SGBUTTON, 0, 0, 54,4, 8,1, "Browse" },
56: { SGTEXT, 0, 0, 3,5, 58,1, NULL },
1.1.1.2 ! root 57: { SGTEXT, 0, 0, 2,7, 32,1, "Default floppy images directory:" },
1.1 root 58: { SGTEXT, 0, 0, 3,8, 58,1, NULL },
59: { SGBUTTON, 0, 0, 54,7, 8,1, "Browse" },
60: { SGCHECKBOX, 0, 0, 2,10, 16,1, "Auto insert B" },
61: { SGBUTTON, 0, 0, 42,10, 20,1, "Create blank image" },
1.1.1.2 ! root 62: { SGTEXT, 0, 0, 2,12, 17,1, "Write protection:" },
! 63: { SGRADIOBUT, 0, 0, 21,12, 5,1, "Off" },
! 64: { SGRADIOBUT, 0, 0, 28,12, 5,1, "On" },
! 65: { SGRADIOBUT, 0, 0, 34,12, 6,1, "Auto" },
! 66:
! 67: { SGBOX, 0, 0, 1,14, 62,8, NULL },
! 68: { SGTEXT, 0, 0, 27,14, 10,1, "Hard discs" },
! 69: { SGTEXT, 0, 0, 2,15, 9,1, "HD image:" },
! 70: { SGBUTTON, 0, 0, 46,15, 7,1, "Eject" },
! 71: { SGBUTTON, 0, 0, 54,15, 8,1, "Browse" },
! 72: { SGTEXT, 0, 0, 3,16, 58,1, NULL },
1.1 root 73: { SGTEXT, 0, 0, 2,17, 13,1, "GEMDOS drive:" },
74: { SGBUTTON, 0, 0, 46,17, 7,1, "Eject" },
75: { SGBUTTON, 0, 0, 54,17, 8,1, "Browse" },
76: { SGTEXT, 0, 0, 3,18, 58,1, NULL },
77: { SGCHECKBOX, 0, 0, 2,20, 14,1, "Boot from HD" },
1.1.1.2 ! root 78:
1.1 root 79: { SGBUTTON, 0, 0, 22,23, 20,1, "Back to main menu" },
80: { -1, 0, 0, 0,0, 0,0, NULL }
81: };
82:
83:
84: /*-----------------------------------------------------------------------*/
85: /*
86: Show and process the disc image dialog.
87: */
88: void Dialog_DiscDlg(void)
89: {
1.1.1.2 ! root 90: int but, i;
1.1 root 91: char dlgnamea[64], dlgnameb[64], dlgdiscdir[64];
92: char dlgnamegdos[64], dlgnamehdimg[64];
93: char *tmpname;
94: char *zip_path;
95:
96: /* Allocate memory for tmpname and zip_path: */
1.1.1.2 ! root 97: tmpname = malloc(2 * FILENAME_MAX);
! 98: if (!tmpname)
! 99: {
! 100: perror("Dialog_DiscDlg");
! 101: return;
! 102: }
1.1 root 103: zip_path = tmpname + FILENAME_MAX;
104: zip_path[0] = 0;
105:
106: SDLGui_CenterDlg(discdlg);
107:
108: /* Set up dialog to actual values: */
109:
110: /* Disc name A: */
111: if( EmulationDrives[0].bDiscInserted )
112: File_ShrinkName(dlgnamea, EmulationDrives[0].szFileName, discdlg[DISCDLG_DISCA].w);
113: else
114: dlgnamea[0] = 0;
115: discdlg[DISCDLG_DISCA].txt = dlgnamea;
116:
117: /* Disc name B: */
118: if( EmulationDrives[1].bDiscInserted )
119: File_ShrinkName(dlgnameb, EmulationDrives[1].szFileName, discdlg[DISCDLG_DISCB].w);
120: else
121: dlgnameb[0] = 0;
122: discdlg[DISCDLG_DISCB].txt = dlgnameb;
123:
124: /* Default image directory: */
125: File_ShrinkName(dlgdiscdir, DialogParams.DiscImage.szDiscImageDirectory, discdlg[DISCDLG_IMGDIR].w);
126: discdlg[DISCDLG_IMGDIR].txt = dlgdiscdir;
127:
128: /* Auto insert disc B: */
1.1.1.2 ! root 129: if (DialogParams.DiscImage.bAutoInsertDiscB)
1.1 root 130: discdlg[DISCDLG_AUTOB].state |= SG_SELECTED;
1.1.1.2 ! root 131: else
1.1 root 132: discdlg[DISCDLG_AUTOB].state &= ~SG_SELECTED;
133:
1.1.1.2 ! root 134: /* Write protection */
! 135: for (i = DISCDLG_PROTOFF; i <= DISCDLG_PROTAUTO; i++)
! 136: {
! 137: discdlg[i].state &= ~SG_SELECTED;
! 138: }
! 139: discdlg[DISCDLG_PROTOFF+DialogParams.DiscImage.nWriteProtection].state |= SG_SELECTED;
! 140:
1.1 root 141: /* Boot from harddisk? */
142: if( DialogParams.HardDisc.bBootFromHardDisc )
143: discdlg[DISCDLG_BOOTHD].state |= SG_SELECTED;
144: else
145: discdlg[DISCDLG_BOOTHD].state &= ~SG_SELECTED;
146:
147: /* GEMDOS Hard disc directory: */
148: if( strcmp(DialogParams.HardDisc.szHardDiscDirectories[0], ConfigureParams.HardDisc.szHardDiscDirectories[0])!=0
149: || GEMDOS_EMU_ON )
150: File_ShrinkName(dlgnamegdos, DialogParams.HardDisc.szHardDiscDirectories[0], discdlg[DISCDLG_DISCGDOS].w);
151: else
152: dlgnamegdos[0] = 0;
153: discdlg[DISCDLG_DISCGDOS].txt = dlgnamegdos;
154:
155: /* Hard disc image: */
156: if( ACSI_EMU_ON )
157: File_ShrinkName(dlgnamehdimg, DialogParams.HardDisc.szHardDiscImage, discdlg[DISCDLG_DISCHDIMG].w);
158: else
159: dlgnamehdimg[0] = 0;
160: discdlg[DISCDLG_DISCHDIMG].txt = dlgnamehdimg;
161:
162: /* Draw and process the dialog */
163: do
164: {
1.1.1.2 ! root 165: but = SDLGui_DoDialog(discdlg, NULL);
1.1 root 166: switch(but)
167: {
168: case DISCDLG_EJECTA: /* Eject disc in drive A: */
169: Floppy_EjectDiscFromDrive(0, FALSE);
170: dlgnamea[0] = 0;
171: break;
172: case DISCDLG_BROWSEA: /* Choose a new disc A: */
173: if( EmulationDrives[0].bDiscInserted )
174: strcpy(tmpname, EmulationDrives[0].szFileName);
175: else
176: strcpy(tmpname, DialogParams.DiscImage.szDiscImageDirectory);
177: if( SDLGui_FileSelect(tmpname, zip_path, FALSE) )
178: {
179: if( !File_DoesFileNameEndWithSlash(tmpname) && File_Exists(tmpname) )
180: {
181: Floppy_ZipInsertDiscIntoDrive(0, tmpname, zip_path); /* FIXME: This shouldn't be done here but in Dialog_CopyDialogParamsToConfiguration */
182: File_ShrinkName(dlgnamea, tmpname, discdlg[DISCDLG_DISCA].w);
183: }
184: else
185: {
186: Floppy_EjectDiscFromDrive(0, FALSE); /* FIXME: This shouldn't be done here but in Dialog_CopyDialogParamsToConfiguration */
187: dlgnamea[0] = 0;
188: }
189: }
190: break;
191: case DISCDLG_EJECTB: /* Eject disc in drive B: */
192: Floppy_EjectDiscFromDrive(1, FALSE);
193: dlgnameb[0] = 0;
194: break;
195: case DISCDLG_BROWSEB: /* Choose a new disc B: */
196: if( EmulationDrives[1].bDiscInserted )
197: strcpy(tmpname, EmulationDrives[1].szFileName);
198: else
199: strcpy(tmpname, DialogParams.DiscImage.szDiscImageDirectory);
200: if( SDLGui_FileSelect(tmpname, zip_path, FALSE) )
201: {
202: if( !File_DoesFileNameEndWithSlash(tmpname) && File_Exists(tmpname) )
203: {
204: Floppy_ZipInsertDiscIntoDrive(1, tmpname, zip_path); /* FIXME: This shouldn't be done here but in Dialog_CopyDialogParamsToConfiguration */
205: File_ShrinkName(dlgnameb, tmpname, discdlg[DISCDLG_DISCB].w);
206: }
207: else
208: {
209: Floppy_EjectDiscFromDrive(1, FALSE); /* FIXME: This shouldn't be done here but in Dialog_CopyDialogParamsToConfiguration */
210: dlgnameb[0] = 0;
211: }
212: }
213: break;
214: case DISCDLG_BROWSEIMG:
215: strcpy(tmpname, DialogParams.DiscImage.szDiscImageDirectory);
216: if( SDLGui_FileSelect(tmpname, NULL, FALSE) )
217: {
218: char *ptr;
219: ptr = strrchr(tmpname, '/');
220: if( ptr!=NULL ) ptr[1]=0;
221: strcpy(DialogParams.DiscImage.szDiscImageDirectory, tmpname);
222: File_ShrinkName(dlgdiscdir, DialogParams.DiscImage.szDiscImageDirectory, discdlg[DISCDLG_IMGDIR].w);
223: }
224: break;
225: case DISCDLG_CREATEIMG:
226: DlgNewDisc_Main();
227: break;
228: case DISCDLG_UNMOUNTGDOS:
229: GemDOS_UnInitDrives(); /* FIXME: This shouldn't be done here but it's the only quick solution I could think of */
230: strcpy(DialogParams.HardDisc.szHardDiscDirectories[0], ConfigureParams.HardDisc.szHardDiscDirectories[0]);
231: dlgnamegdos[0] = 0;
232: break;
233: case DISCDLG_BROWSEGDOS:
234: strcpy(tmpname, DialogParams.HardDisc.szHardDiscDirectories[0]);
235: if( SDLGui_FileSelect(tmpname, NULL, FALSE) )
236: {
237: char *ptr;
238: ptr = strrchr(tmpname, '/');
239: if( ptr!=NULL ) ptr[1]=0; /* Remove file name from path */
240: strcpy(DialogParams.HardDisc.szHardDiscDirectories[0], tmpname);
1.1.1.2 ! root 241: File_CleanFileName(DialogParams.HardDisc.szHardDiscDirectories[0]);
1.1 root 242: File_ShrinkName(dlgnamegdos, DialogParams.HardDisc.szHardDiscDirectories[0], discdlg[DISCDLG_DISCGDOS].w);
243: }
244: break;
245: case DISCDLG_EJECTHDIMG:
246: DialogParams.HardDisc.szHardDiscImage[0] = 0;
247: DialogParams.HardDisc.bUseHardDiscImage = FALSE;
248: dlgnamehdimg[0] = 0;
249: break;
250: case DISCDLG_BROWSEHDIMG:
251: strcpy(tmpname, DialogParams.HardDisc.szHardDiscImage);
252: if( SDLGui_FileSelect(tmpname, NULL, FALSE) )
253: {
254: strcpy(DialogParams.HardDisc.szHardDiscImage, tmpname);
255: if( !File_DoesFileNameEndWithSlash(tmpname) && File_Exists(tmpname) )
256: {
257: File_ShrinkName(dlgnamehdimg, tmpname, discdlg[DISCDLG_DISCHDIMG].w);
258: DialogParams.HardDisc.bUseHardDiscImage = TRUE;
259: }
260: else
261: {
262: dlgnamehdimg[0] = 0;
263: }
264: }
265: break;
266: }
267: }
1.1.1.2 ! root 268: while (but!=DISCDLG_EXIT && but != SDLGUI_QUIT && !bQuitProgram);
! 269:
! 270: /* Read values from dialog: */
! 271:
! 272: for (i = DISCDLG_PROTOFF; i <= DISCDLG_PROTAUTO; i++)
! 273: {
! 274: if (discdlg[i].state & SG_SELECTED)
! 275: {
! 276: DialogParams.DiscImage.nWriteProtection = i-DISCDLG_PROTOFF;
! 277: break;
! 278: }
! 279: }
1.1 root 280:
281: DialogParams.DiscImage.bAutoInsertDiscB = (discdlg[DISCDLG_AUTOB].state & SG_SELECTED);
282: DialogParams.HardDisc.bBootFromHardDisc = (discdlg[DISCDLG_BOOTHD].state & SG_SELECTED);
283:
1.1.1.2 ! root 284: free(tmpname);
1.1 root 285: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.