|
|
1.1 root 1: /*
2: Hatari - dlgNewDisk.c
3:
1.1.1.7 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: */
1.1.1.4 root 7: const char DlgNewDisk_fileid[] = "Hatari dlgNewDisk.c : " __DATE__ " " __TIME__;
1.1 root 8:
9: #include "main.h"
10: #include "configuration.h"
11: #include "createBlankImage.h"
12: #include "dialog.h"
13: #include "sdlgui.h"
14: #include "file.h"
1.1.1.5 root 15: #include "log.h"
1.1 root 16:
17: #define DLGNEWDISK_DECTRACK 3
18: #define DLGNEWDISK_TRACKSTR 4
19: #define DLGNEWDISK_INCTRACK 5
20: #define DLGNEWDISK_SECTORS9 7
21: #define DLGNEWDISK_SECTORS10 8
22: #define DLGNEWDISK_SECTORS11 9
1.1.1.5 root 23: #define DLGNEWDISK_SECTORS18 10
24: #define DLGNEWDISK_SECTORS36 11
25: #define DLGNEWDISK_SIDES1 13
26: #define DLGNEWDISK_SIDES2 14
27: #define DLGNEWDISK_SAVE 15
28: #define DLGNEWDISK_EXIT 16
1.1 root 29:
30: static char szTracks[3];
31: static int nTracks = 80;
32:
33: /* The new disk image dialog: */
34: static SGOBJ newdiskdlg[] =
35: {
1.1.1.5 root 36: { SGBOX, 0, 0, 0,0, 29,14, NULL },
1.1 root 37: { SGTEXT, 0, 0, 6,1, 16,1, "New floppy image" },
38: { SGTEXT, 0, 0, 2,3, 7,1, "Tracks:" },
1.1.1.8 ! root 39: { SGBUTTON, 0, 0, 12,3, 1,1, "\x04", SG_SHORTCUT_LEFT },
1.1 root 40: { SGTEXT, 0, 0, 14,3, 2,1, szTracks },
1.1.1.8 ! root 41: { SGBUTTON, 0, 0, 17,3, 1,1, "\x03", SG_SHORTCUT_RIGHT },
1.1 root 42: { SGTEXT, 0, 0, 2,5, 8,1, "Sectors:" },
1.1.1.8 ! root 43: { SGRADIOBUT, 0, SG_SELECTED, 12,5, 4,1, " _9" },
! 44: { SGRADIOBUT, 0, 0, 17,5, 4,1, "1_0" },
1.1 root 45: { SGRADIOBUT, 0, 0, 22,5, 4,1, "11" },
1.1.1.8 ! root 46: { SGRADIOBUT, 0, 0, 12,6, 9,1, "1_8 (HD)" },
! 47: { SGRADIOBUT, 0, 0, 12,7, 9,1, "3_6 (ED)" },
1.1.1.5 root 48: { SGTEXT, 0, 0, 2,9, 6,1, "Sides:" },
1.1.1.8 ! root 49: { SGRADIOBUT, 0, 0, 12,9, 3,1, "_1" },
! 50: { SGRADIOBUT, 0, SG_SELECTED, 17,9, 3,1, "_2" },
! 51: { SGBUTTON, SG_DEFAULT, 0, 4,12, 8,1, "_Create" },
! 52: { SGBUTTON, SG_CANCEL, 0, 18,12, 6,1, "_Back" },
1.1 root 53: { -1, 0, 0, 0,0, 0,0, NULL }
54: };
55:
56: #define DEFAULT_DISK_NAME "new_disk.st"
57:
1.1.1.5 root 58:
59: /*-----------------------------------------------------------------------*/
60: /**
61: * Handle creation of a the "new blank disk image".
62: * return true if disk created, false otherwise.
63: */
64: static bool DlgNewDisk_CreateDisk(const char *path)
65: {
66: int nSectors, nSides;
67:
68: /* (potentially non-existing) filename? */
69: if (File_DirExists(path))
70: {
71: Log_AlertDlg(LOG_ERROR, "ERROR: '%s' isn't a file!", path);
72: return false;
73: }
74:
75: /* Get number of sectors */
76: if (newdiskdlg[DLGNEWDISK_SECTORS36].state & SG_SELECTED)
77: nSectors = 36;
78: else if (newdiskdlg[DLGNEWDISK_SECTORS18].state & SG_SELECTED)
79: nSectors = 18;
80: else if (newdiskdlg[DLGNEWDISK_SECTORS11].state & SG_SELECTED)
81: nSectors = 11;
82: else if (newdiskdlg[DLGNEWDISK_SECTORS10].state & SG_SELECTED)
83: nSectors = 10;
84: else
85: nSectors = 9;
86:
87: /* Get number of sides */
88: if (newdiskdlg[DLGNEWDISK_SIDES1].state & SG_SELECTED)
89: nSides = 1;
90: else
91: nSides = 2;
92:
93: return CreateBlankImage_CreateFile(path, nTracks, nSectors, nSides);
94: }
95:
96:
1.1 root 97: /*-----------------------------------------------------------------------*/
1.1.1.5 root 98: /**
99: * Show and process the "new blank disk image" dialog.
100: * Return file name of last created diskimage or NULL if none created.
101: * Caller needs to free the name.
102: */
103: char *DlgNewDisk_Main(void)
1.1 root 104: {
105: int but;
1.1.1.5 root 106: char *szNewDiskName, *tmpname, *retname = NULL;
1.1 root 107: sprintf(szTracks, "%i", nTracks);
108:
109: SDLGui_CenterDlg(newdiskdlg);
110:
111: /* Initialize disk image name: */
1.1.1.2 root 112: szNewDiskName = File_MakePath(ConfigureParams.DiskImage.szDiskImageDirectory, "new_disk.st", NULL);
1.1 root 113: if (!szNewDiskName)
1.1.1.5 root 114: return NULL;
1.1 root 115:
116: /* Draw and process the dialog */
117: do
118: {
1.1.1.8 ! root 119: but = SDLGui_DoDialog(newdiskdlg, NULL, false);
1.1 root 120: switch(but)
121: {
122: case DLGNEWDISK_DECTRACK:
123: if (nTracks > 40)
124: nTracks -= 1;
125: sprintf(szTracks, "%i", nTracks);
126: break;
127: case DLGNEWDISK_INCTRACK:
128: if (nTracks < 85)
129: nTracks += 1;
130: sprintf(szTracks, "%i", nTracks);
131: break;
132: case DLGNEWDISK_SAVE:
1.1.1.8 ! root 133: tmpname = SDLGui_FileSelect("New floppy image:", szNewDiskName, NULL, true);
1.1 root 134: if (tmpname)
135: {
1.1.1.5 root 136: if (DlgNewDisk_CreateDisk(tmpname))
1.1.1.6 root 137: {
138: if (retname)
139: free(retname);
1.1.1.5 root 140: retname = tmpname;
1.1.1.6 root 141: }
1.1.1.5 root 142: else
143: free(tmpname);
1.1 root 144: }
145: break;
146: }
147: }
148: while (but != DLGNEWDISK_EXIT && but != SDLGUI_QUIT
149: && but != SDLGUI_ERROR && !bQuitProgram);
150:
151: free(szNewDiskName);
1.1.1.5 root 152: return retname;
1.1 root 153: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.