|
|
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: */ ! 7: const char DlgNewDisk_rcsid[] = "Hatari $Id: dlgNewDisk.c,v 1.1 2008/02/23 22:14:21 thothy Exp $"; ! 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" ! 15: ! 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 ! 23: #define DLGNEWDISK_SIDES1 11 ! 24: #define DLGNEWDISK_SIDES2 12 ! 25: #define DLGNEWDISK_SAVE 13 ! 26: #define DLGNEWDISK_EXIT 14 ! 27: ! 28: static char szTracks[3]; ! 29: static int nTracks = 80; ! 30: ! 31: /* The new disk image dialog: */ ! 32: static SGOBJ newdiskdlg[] = ! 33: { ! 34: { SGBOX, 0, 0, 0,0, 28,12, NULL }, ! 35: { SGTEXT, 0, 0, 6,1, 16,1, "New floppy image" }, ! 36: { SGTEXT, 0, 0, 2,3, 7,1, "Tracks:" }, ! 37: { SGBUTTON, 0, 0, 12,3, 1,1, "\x04" }, /* Left-arrow button */ ! 38: { SGTEXT, 0, 0, 14,3, 2,1, szTracks }, ! 39: { SGBUTTON, 0, 0, 17,3, 1,1, "\x03" }, /* Right-arrow button */ ! 40: { SGTEXT, 0, 0, 2,5, 8,1, "Sectors:" }, ! 41: { SGRADIOBUT, 0, SG_SELECTED, 12,5, 4,1, "9" }, ! 42: { SGRADIOBUT, 0, 0, 17,5, 4,1, "10" }, ! 43: { SGRADIOBUT, 0, 0, 22,5, 4,1, "11" }, ! 44: { SGTEXT, 0, 0, 2,7, 6,1, "Sides:" }, ! 45: { SGRADIOBUT, 0, 0, 12,7, 4,1, "1" }, ! 46: { SGRADIOBUT, 0, SG_SELECTED, 17,7, 4,1, "2" }, ! 47: { SGBUTTON, 0, 0, 4,10, 8,1, "Create" }, ! 48: { SGBUTTON, 0, 0, 18,10, 6,1, "Back" }, ! 49: { -1, 0, 0, 0,0, 0,0, NULL } ! 50: }; ! 51: ! 52: #define DEFAULT_DISK_NAME "new_disk.st" ! 53: ! 54: /*-----------------------------------------------------------------------*/ ! 55: /* ! 56: Show and process the "new blank disk image" dialog. ! 57: */ ! 58: void DlgNewDisk_Main(void) ! 59: { ! 60: int but; ! 61: char *szNewDiskName, *tmpname; ! 62: sprintf(szTracks, "%i", nTracks); ! 63: ! 64: SDLGui_CenterDlg(newdiskdlg); ! 65: ! 66: /* Initialize disk image name: */ ! 67: szNewDiskName = malloc(strlen(DialogParams.DiskImage.szDiskImageDirectory) + strlen(DEFAULT_DISK_NAME) + 1); ! 68: if (!szNewDiskName) ! 69: { ! 70: perror("DlgNewDisk_Main"); ! 71: return; ! 72: } ! 73: strcpy(szNewDiskName, DialogParams.DiskImage.szDiskImageDirectory); ! 74: strcat(szNewDiskName, "new_disk.st"); ! 75: ! 76: /* Draw and process the dialog */ ! 77: do ! 78: { ! 79: but = SDLGui_DoDialog(newdiskdlg, NULL); ! 80: switch(but) ! 81: { ! 82: case DLGNEWDISK_DECTRACK: ! 83: if (nTracks > 40) ! 84: nTracks -= 1; ! 85: sprintf(szTracks, "%i", nTracks); ! 86: break; ! 87: case DLGNEWDISK_INCTRACK: ! 88: if (nTracks < 85) ! 89: nTracks += 1; ! 90: sprintf(szTracks, "%i", nTracks); ! 91: break; ! 92: case DLGNEWDISK_SAVE: ! 93: tmpname = SDLGui_FileSelect(szNewDiskName, NULL, TRUE); ! 94: if (tmpname) ! 95: { ! 96: if (!File_DoesFileNameEndWithSlash(tmpname)) ! 97: { ! 98: int nSectors, nSides; ! 99: ! 100: /* Get number of sectors */ ! 101: if (newdiskdlg[DLGNEWDISK_SECTORS11].state & SG_SELECTED) ! 102: nSectors = 11; ! 103: else if (newdiskdlg[DLGNEWDISK_SECTORS10].state & SG_SELECTED) ! 104: nSectors = 10; ! 105: else ! 106: nSectors = 9; ! 107: ! 108: /* Get number of sides */ ! 109: if (newdiskdlg[DLGNEWDISK_SIDES1].state & SG_SELECTED) ! 110: nSides = 1; ! 111: else ! 112: nSides = 2; ! 113: ! 114: CreateBlankImage_CreateFile(tmpname, nTracks, nSectors, nSides); ! 115: } ! 116: free(tmpname); ! 117: } ! 118: break; ! 119: } ! 120: } ! 121: while (but != DLGNEWDISK_EXIT && but != SDLGUI_QUIT ! 122: && but != SDLGUI_ERROR && !bQuitProgram); ! 123: ! 124: free(szNewDiskName); ! 125: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.