|
|
1.1 root 1: /*
2: Hatari - dlgNewDisk.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.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:" },
39: { SGBUTTON, 0, 0, 12,3, 1,1, "\x04" }, /* Left-arrow button */
40: { SGTEXT, 0, 0, 14,3, 2,1, szTracks },
41: { SGBUTTON, 0, 0, 17,3, 1,1, "\x03" }, /* Right-arrow button */
42: { SGTEXT, 0, 0, 2,5, 8,1, "Sectors:" },
1.1.1.5 ! root 43: { SGRADIOBUT, 0, SG_SELECTED, 12,5, 4,1, " 9" },
1.1 root 44: { SGRADIOBUT, 0, 0, 17,5, 4,1, "10" },
45: { SGRADIOBUT, 0, 0, 22,5, 4,1, "11" },
1.1.1.5 ! root 46: { SGRADIOBUT, 0, 0, 12,6, 9,1, "18 (HD)" },
! 47: { SGRADIOBUT, 0, 0, 12,7, 9,1, "36 (ED)" },
! 48: { SGTEXT, 0, 0, 2,9, 6,1, "Sides:" },
! 49: { SGRADIOBUT, 0, 0, 12,9, 4,1, "1" },
! 50: { SGRADIOBUT, 0, SG_SELECTED, 17,9, 4,1, "2" },
! 51: { SGBUTTON, 0, 0, 4,12, 8,1, "Create" },
! 52: { SGBUTTON, 0, 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: {
119: but = SDLGui_DoDialog(newdiskdlg, NULL);
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.5 ! root 133: if (retname)
! 134: free(retname);
1.1.1.4 root 135: tmpname = SDLGui_FileSelect(szNewDiskName, NULL, true);
1.1 root 136: if (tmpname)
137: {
1.1.1.5 ! root 138: if (DlgNewDisk_CreateDisk(tmpname))
! 139: retname = tmpname;
! 140: else
! 141: free(tmpname);
1.1 root 142: }
143: break;
144: }
145: }
146: while (but != DLGNEWDISK_EXIT && but != SDLGUI_QUIT
147: && but != SDLGUI_ERROR && !bQuitProgram);
148:
149: free(szNewDiskName);
1.1.1.5 ! root 150: return retname;
1.1 root 151: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.