|
|
1.1 root 1: /* 1.1.1.4 ! root 2: Hatari - createBlankImage.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. 1.1 root 6: 7: Create Blank .ST/.MSA Disc Images 8: */ 1.1.1.4 ! root 9: static char rcsid[] = "Hatari $Id: createBlankImage.c,v 1.4 2003/04/04 16:28:24 thothy Exp $"; 1.1 root 10: 11: #include "main.h" 1.1.1.4 ! root 12: #include "configuration.h" 1.1 root 13: #include "file.h" 14: #include "floppy.h" 15: #include "memAlloc.h" 16: #include "misc.h" 17: #include "msa.h" 18: #include "st.h" 19: 20: 1.1.1.3 root 21: /* FIXME: This file needs a nearly complete rewrite for Hatari... */ 22: 23: 1.1 root 24: /*-----------------------------------------------------------------------*/ 25: /* 26: 40 track SS 40 track DS 80 track SS 80 track DS 27: 0- 1 Branch instruction to boot program if executable 28: 2- 7 'Loader' 29: 8-10 24-bit serial number 30: 11-12 BPS 512 512 512 512 31: 13 SPC 1 2 2 2 32: 14-15 RES 1 1 1 1 33: 16 FAT 2 2 2 2 34: 17-18 DIR 64 112 112 112 35: 19-20 SEC 360 720 720 1440 36: 21 MEDIA 252 253 248 249 (isn't used by ST-BIOS) 37: 22-23 SPF 2 2 5 5 38: 24-25 SPT 9 9 9 9 39: 26-27 SIDE 1 2 1 2 40: 28-29 HID 0 0 0 0 41: 510-511 CHECKSUM 42: */ 43: 44: typedef struct { 45: int nTracks,nSectors,nSides; 46: } STANDARDDISCSIZES; 47: 48: #define DEFAULT_STANDARDDISC 1 49: #define MAX_STANDARDDISCSIZES 2 1.1.1.3 root 50: 1.1 root 51: static STANDARDDISCSIZES StandardDiscSizes[MAX_STANDARDDISCSIZES] = { 1.1.1.3 root 52: { 80,9,1 }, /* 80 tracks, single sided (360k) */ 53: { 80,9,2 } /* 80 tracks, double sided (720k) */ 1.1 root 54: }; 1.1.1.3 root 55: 56: #if 0 1.1 root 57: static char *pszStandardDiscNames[] = { 58: "80 tracks, single sided (360k)", 59: "80 tracks, double sided (720k)", 1.1.1.2 root 60: NULL /* term */ 1.1 root 61: }; 1.1.1.3 root 62: #endif 1.1 root 63: 64: #define NUM_TRACKSTEXTS 3 65: #define NUM_SECTORSTEXTS 3 66: #define NUM_SIDESTEXTS 2 1.1.1.3 root 67: 1.1 root 68: static char *pszTracksText[] = { 69: "80","81","82",NULL 70: }; 1.1.1.3 root 71: 1.1 root 72: static char *pszSectorsText[] = { 73: "9","10","11",NULL 74: }; 1.1.1.3 root 75: 1.1 root 76: static char *pszSidesText[] = { 77: "1","2",NULL 78: }; 79: 80: /* FIXME 81: static int Custom_DialogItems[] = { 82: IDC_STATICTRACKS, 83: IDC_STATICSECTORS, 84: IDC_STATICSIDES, 85: IDC_EDITTRACKS, 86: IDC_EDITSECTORS, 87: IDC_EDITSIDES, 88: IDC_SPINTRACKS, 89: IDC_SPINSECTORS, 90: IDC_SPINSIDES, 91: IDC_STATICSIZE, 92: 0, //term 93: }; 94: */ 95: 96: static int CustomTracks=0,CustomSectors=0,CustomSides=1; /* Default settings, 80 tracks, 9 sectors, 2 sides */ 1.1.1.3 root 97: #if 0 1.1 root 98: static BOOL bInsertIntoDrive=FALSE; /* Insert disc image into drive when complete? */ 99: static BOOL bCustomDiscImage=FALSE; /* Is custom or standard disc size? */ 1.1.1.3 root 100: #endif 1.1 root 101: static int ChosenDiscType; /* Index into StandardDiscSizes[] of chosen image type */ 102: static int ChosenDiscDrive; /* Drive we are making disc image in, eg 0=A:, 1=B: */ 103: static char CreateBlankImageFileName[MAX_FILENAME_LENGTH]; 104: 105: 106: /*-----------------------------------------------------------------------*/ 107: /* 108: Create .ST/.MSA disc image according to 'Tracks,Sector,Sides' and save as filename 109: */ 110: void CreateBlankImage_CreateFile(/*HWND hDlg,*/char *pszFileName,int nTracks, int nSectors, int nSides, BOOL bInsertIntoDrive) 111: { 112: unsigned char *pDiscFile; 113: unsigned long DiscSize; 114: unsigned short int SPC,DIR,MEDIA,SPF; 115: char szString[MAX_FILENAME_LENGTH]; 116: BOOL bRet=FALSE; 117: 118: /* Calculate size of disc image */ 119: DiscSize = nTracks * (nSectors*NUMBYTESPERSECTOR) * nSides; 120: /* Allocate space for our 'file', and blank */ 121: pDiscFile = (unsigned char *)Memory_Alloc(DiscSize); 122: Memory_Clear(pDiscFile,DiscSize); 123: 124: /* Fill in boot-sector, this would better as a structure but 'C' pads the variables out */ 125: Memory_Set(pDiscFile+2,0x4e,6); /* 2-7 'Loader' */ 126: *(unsigned char *)(pDiscFile+8) = rand(); /* 8-10 24-bit serial number */ 127: *(unsigned char *)(pDiscFile+9) = rand(); 128: *(unsigned char *)(pDiscFile+10) = rand(); 129: *(unsigned short int *)(pDiscFile+11) = NUMBYTESPERSECTOR; /* 11-12 BPS */ 130: if ( (nTracks==40) && (nSides==1) ) SPC = 1; 131: else SPC = 2; 132: *(unsigned char *)(pDiscFile+13) = SPC; /* 13 SPC */ 133: *(unsigned short int *)(pDiscFile+14) = 1; /* 14-15 RES */ 134: *(unsigned char *)(pDiscFile+16) = 2; /* 16 FAT */ 135: if (SPC==1) DIR = 64; 136: else DIR = 112; 137: *(unsigned short int *)(pDiscFile+17) = DIR; /* 17-18 DIR */ 138: *(unsigned short int *)(pDiscFile+19) = nTracks*nSectors*nSides; /* 19-20 SEC */ 139: if (nTracks==40) MEDIA = 252; 140: else MEDIA = 248; 141: if (nSides==2) MEDIA++; 142: *(unsigned char *)(pDiscFile+21) = MEDIA; /* 21 MEDIA */ 143: if (nTracks>=80) SPF = 5; 144: else SPF = 2; 145: *(unsigned short int *)(pDiscFile+22) = SPF; /* 22-23 SPF */ 146: *(unsigned short int *)(pDiscFile+24) = nSectors; /* 24-25 SPT */ 147: *(unsigned short int *)(pDiscFile+26) = nSides; /* 26-27 SIDE */ 148: *(unsigned short int *)(pDiscFile+28) = 0; /* 28-29 HID */ 149: 150: /* Ask if OK to overwrite, if exists? */ 151: if (File_QueryOverwrite(/*hDlg,*/pszFileName)) { 152: /* Save image to file, as .ST or compressed .MSA */ 153: if (File_FileNameIsMSA(pszFileName)) 154: bRet = MSA_WriteDisc(pszFileName,pDiscFile,DiscSize); 155: else if (File_FileNameIsST(pszFileName)) 156: bRet = ST_WriteDisc(pszFileName,pDiscFile,DiscSize); 157: 158: /* Did create successfully? */ 159: if (bRet) { 160: /* Say OK, */ 161: // MessageBox(hDlg,"Disc image created successfully.",PROG_NAME,MB_OK | MB_ICONINFORMATION); 162: /* Insert into drive A: or B: ? */ 163: if (bInsertIntoDrive) 164: Floppy_InsertDiscIntoDrive(ChosenDiscDrive,pszFileName); 165: } 166: else { 167: /* Warn user we were unable to create image */ 168: sprintf(szString,"Unable to create disc image '%s'.",pszFileName); 169: // MessageBox(hDlg,szString,PROG_NAME,MB_OK | MB_ICONSTOP); 170: } 171: } 172: 173: /* Free image */ 174: Memory_Free(pDiscFile); 175: } 176: 1.1.1.2 root 177: 178: /*-----------------------------------------------------------------------*/ 1.1 root 179: /* 180: Enable dialog items according to choice of standard or custom size 181: */ 182: void CreateBlankImage_EnableDialog(/*HWND hDlg,*/BOOL bState) 183: { 1.1.1.2 root 184: /* Standard disc size */ 1.1 root 185: // Dialog_EnableItem(hDlg,IDC_IMAGECOMBO,bState); 186: 1.1.1.2 root 187: /* Custom disc size */ 1.1 root 188: // Dialog_EnableItems(hDlg,Custom_DialogItems,!bState); 189: } 190: 1.1.1.2 root 191: 192: /*-----------------------------------------------------------------------*/ 1.1 root 193: /* 194: Find number of Tracks,Sectors and Sides from chosen dialog settings 195: */ 196: void CreateBlankImage_FindTracksSectorsSides(int *nTracks, int *nSectors, int *nSides, BOOL bCustom, int ChosenDiscType) 197: { 198: if (bCustom) { 199: *nTracks = atoi(pszTracksText[CustomTracks]); 200: *nSectors = atoi(pszSectorsText[CustomSectors]); 201: *nSides = atoi(pszSidesText[CustomSides]); 202: } 203: else { 204: *nTracks = StandardDiscSizes[ChosenDiscType].nTracks; 205: *nSectors = StandardDiscSizes[ChosenDiscType].nSectors; 206: *nSides = StandardDiscSizes[ChosenDiscType].nSides; 207: } 208: } 209: 1.1.1.2 root 210: 211: /*-----------------------------------------------------------------------*/ 1.1 root 212: /* 213: Show size of custom disc in dialog 214: */ 215: void CreateBlankImage_ShowDiscImageCapacity(/*HWND hDlg*/) 216: { 217: char szString[256]; 218: int DiscSize,nTracks,nSectors,nSides; 219: 1.1.1.2 root 220: /* Find size of disc image */ 1.1 root 221: CreateBlankImage_FindTracksSectorsSides(&nTracks,&nSectors,&nSides,TRUE,ChosenDiscType); 222: DiscSize = nTracks*nSectors*nSides*NUMBYTESPERSECTOR; 223: 224: sprintf(szString,"Capactity: %dk (%d bytes)", DiscSize/1024,DiscSize); 225: // Dialog_SetText(hDlg,IDC_STATICSIZE,szString); 226: } 227: 1.1.1.2 root 228: 229: /*-----------------------------------------------------------------------*/ 1.1 root 230: /* 231: Set dialog edit box details for Tracks,Sectors and Sides 232: */ 233: 234: void CreateBlankImage_SetDiscImageTracksDetail(/*HWND hDlg,*/int NewCustomTracks) 235: { 236: // Dialog_SetText(hDlg,IDC_EDITTRACKS,pszTracksText[CustomTracks=NewCustomTracks]); 237: // CreateBlankImage_ShowDiscImageCapacity(hDlg); 238: } 239: 240: void CreateBlankImage_SetDiscImageSectorsDetail(/*HWND hDlg,*/int NewCustomSectors) 241: { 242: // Dialog_SetText(hDlg,IDC_EDITSECTORS,pszSectorsText[CustomSectors=NewCustomSectors]); 243: // CreateBlankImage_ShowDiscImageCapacity(hDlg); 244: } 245: 246: void CreateBlankImage_SetDiscImageSidesDetail(/*HWND hDlg,*/int NewCustomSides) 247: { 248: // Dialog_SetText(hDlg,IDC_EDITSIDES,pszSidesText[CustomSides=NewCustomSides]); 249: // CreateBlankImage_ShowDiscImageCapacity(hDlg); 250: } 251: 1.1.1.2 root 252: 253: /*-----------------------------------------------------------------------*/ 1.1 root 254: /* 255: Handle create disc dialog messages 256: */ 257: BOOL CreateBlankImage_DiscImageDialog(/*HWND hDlg, UINT Message, WPARAM wParam, LPARAM lParam*/) 258: { 259: #if 0 260: NMUPDOWN *pUpDown; 261: char szString[MAX_FILENAME_LENGTH]; 262: int nTracks,nSectors,nSides; 263: int Offset; 264: 265: switch(Message) { 266: case WM_INITDIALOG: 267: // Set Insert into drive checkbox 268: Dialog_SetButton(hDlg,IDC_CHECK_INSERTINTODRIVE,bInsertIntoDrive); 269: // Fill in combobox 270: Dialog_SetComboBoxItems(hDlg,IDC_IMAGECOMBO,pszStandardDiscNames,DEFAULT_STANDARDDISC); 271: // And select, defaults to 720k disc image size 272: ChosenDiscType = DEFAULT_STANDARDDISC; // 80 tracks, 9 sectors, 2 sides 720k 273: // Set default choice 274: Dialog_SetButton(hDlg,IDC_STDDISCSIZERADIO,!bCustomDiscImage); 275: Dialog_SetButton(hDlg,IDC_CUSTOMDISCSIZERADIO,bCustomDiscImage); 276: // Set custom spin items 277: Dialog_SetSpinList(hDlg,IDC_EDITTRACKS,IDC_SPINTRACKS,pszTracksText,NUM_TRACKSTEXTS,CustomTracks); 278: Dialog_SetSpinList(hDlg,IDC_EDITSECTORS,IDC_SPINSECTORS,pszSectorsText,NUM_SECTORSTEXTS,CustomSectors); 279: Dialog_SetSpinList(hDlg,IDC_EDITSIDES,IDC_SPINSIDES,pszSidesText,NUM_SIDESTEXTS,CustomSides); 280: 281: CreateBlankImage_ShowDiscImageCapacity(hDlg); 282: CreateBlankImage_EnableDialog(hDlg,!bCustomDiscImage); 283: return(TRUE); 284: 285: case WM_NOTIFY: 286: switch(wParam) { 287: // Handle spin controls 288: case IDC_SPINTRACKS: 289: pUpDown = (NMUPDOWN *)lParam; 290: Offset = Misc_LimitInt(pUpDown->iPos + pUpDown->iDelta, 0,NUM_TRACKSTEXTS-1); 291: Dialog_UpdateSpinList(hDlg,IDC_EDITTRACKS,pszTracksText,NUM_TRACKSTEXTS,Offset); 292: CreateBlankImage_SetDiscImageTracksDetail(hDlg,Offset); 293: return(TRUE); 294: case IDC_SPINSECTORS: 295: pUpDown = (NMUPDOWN *)lParam; 296: Offset = Misc_LimitInt(pUpDown->iPos + pUpDown->iDelta, 0,NUM_SECTORSTEXTS-1); 297: Dialog_UpdateSpinList(hDlg,IDC_EDITSECTORS,pszSectorsText,NUM_SECTORSTEXTS,Offset); 298: CreateBlankImage_SetDiscImageSectorsDetail(hDlg,Offset); 299: return(TRUE); 300: case IDC_SPINSIDES: 301: pUpDown = (NMUPDOWN *)lParam; 302: Offset = Misc_LimitInt(pUpDown->iPos + pUpDown->iDelta, 0,NUM_SIDESTEXTS-1); 303: Dialog_UpdateSpinList(hDlg,IDC_EDITSIDES,pszSidesText,NUM_SIDESTEXTS,Offset); 304: CreateBlankImage_SetDiscImageSidesDetail(hDlg,Offset); 305: return(TRUE); 306: } 307: 308: break; 309: 310: case WM_COMMAND: 311: switch(wParam) { 312: case IDC_STDDISCSIZERADIO: 313: case IDC_CUSTOMDISCSIZERADIO: 314: bCustomDiscImage ^= TRUE; 315: CreateBlankImage_EnableDialog(/*hDlg,*/!bCustomDiscImage); 316: return(TRUE); 317: case IDC_IMAGECOMBO: 318: return(TRUE); 319: 320: case IDOK: 321: // Read back dialog choices 322: bInsertIntoDrive = Dialog_ReadButton(hDlg,IDC_CHECK_INSERTINTODRIVE); 323: bCustomDiscImage = Dialog_ReadButton(hDlg,IDC_CUSTOMDISCSIZERADIO); 324: // Get type of disc(for standard size) 325: ChosenDiscType = Dialog_GetSelectedComboBoxItem(hDlg,IDC_IMAGECOMBO); 326: // Find disc details,(if chosen or custom type) 327: CreateBlankImage_FindTracksSectorsSides(&nTracks,&nSectors,&nSides,bCustomDiscImage,ChosenDiscType); 328: // Confirm with user and create image 329: sprintf(szString,"Create disc image '%s'\n(%d Track, %d Sectors, %d Sides) ?",CreateBlankImageFileName,nTracks,nSectors,nSides); 330: if (MessageBox(hDlg,szString,PROG_NAME,MB_YESNO | MB_ICONQUESTION)==IDYES) 331: CreateBlankImage_CreateFile(hDlg,CreateBlankImageFileName,nTracks,nSectors,nSides,bInsertIntoDrive); 332: case IDCANCEL: 333: EndDialog(hDlg,0); 334: return(TRUE); 335: } 336: break; 337: } 338: 339: #endif 1.1.1.3 root 340: return(FALSE); 1.1 root 341: } 342: 1.1.1.2 root 343: 344: /*-----------------------------------------------------------------------*/ 1.1 root 345: /* 346: Create output disassembly dialog 347: */ 348: BOOL CreateBlankImage_DoDialog(/*HWND hDlg,*/int Drive,char *pszFileName) 349: { 350: // PROC lpfnDlgProc; 351: 352: /* Is filename valid, ie .ST or .MSA? */ 353: if (File_FileNameIsST(pszFileName) || File_FileNameIsMSA(pszFileName)) { 354: /* Store drive for later(when create image) */ 355: ChosenDiscDrive = Drive; 356: /* Store filename for later */ 357: strcpy(CreateBlankImageFileName,pszFileName); 358: /* Open dialog */ 359: // lpfnDlgProc = MakeProcInstance((PROC)CreateBlankImage_DiscImageDialog,hInst); 360: // DialogBoxParam(hInst,MAKEINTRESOURCE(IDD_DIALOG_BLANKIMAGE),hDlg,(DLGPROC)lpfnDlgProc,NULL); 361: return(TRUE); 362: } 363: else 364: // MessageBox(hWnd,"Invalid disc filename. Please re-enter.",PROG_NAME,MB_OK | MB_ICONSTOP); 365: 366: return(FALSE); 367: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.