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