--- np2/macos9/dialog/d_disk.cpp 2003/10/23 10:57:49 1.1 +++ np2/macos9/dialog/d_disk.cpp 2004/02/14 07:56:51 1.5 @@ -1,7 +1,7 @@ #include "compiler.h" -// #include "strres.h" +#include "strres.h" #include "resource.h" -// #include "sysmng.h" +#include "dosio.h" #include "dialog.h" #include "dialogs.h" #include "pccore.h" @@ -23,166 +23,282 @@ void dialog_changefdd(BYTE drv) { void dialog_changehdd(BYTE drv) { + UINT num; + BOOL equip; char fname[MAX_PATH]; - if (drv < 2) { - if (dlgs_selectfile(fname, sizeof(fname))) { - diskdrv_sethdd(drv, fname); + num = drv & 0x0f; + equip = FALSE; + if (!(drv & 0x20)) { // SASI/IDE + if (num < 2) { + equip = TRUE; + } + } +#if defined(SUPPORT_SCSI) + else { // SCSI + if (num < 4) { + equip = TRUE; } } +#endif + if ((equip) && (dlgs_selectfile(fname, sizeof(fname)))) { + diskdrv_sethdd(drv, fname); + } } // ---- newdisk -#if 0 +static const char str_newdisk[] = "newdisk.d88"; -static const char str_newdisk[] = "newdisk"; -static const UINT32 hddsizetbl[5] = {20, 41, 65, 80, 128}; +typedef struct { + BYTE fdtype; + char label[16+1]; +} NEWDISK; + +static int NewHddDlgProc(UINT *hddsize, UINT hddminsize, UINT hddmaxsize) { + + DialogPtr hDlg; + Str255 sizestr; + int done; + short item; + char work[32]; + + hDlg = GetNewDialog(IDD_NEWHDDDISK, NULL, (WindowPtr)-1); + if (!hDlg) { + return(IDCANCEL); + } -static BYTE makefdtype = DISKTYPE_2HD << 4; -static char disklabel[16+1]; -static UINT hddsize; - -static LRESULT CALLBACK NewHddDlgProc(HWND hWnd, UINT msg, - WPARAM wp, LPARAM lp) { - - UINT val; - char work[32]; - - switch (msg) { - case WM_INITDIALOG: - SETLISTUINT32(hWnd, IDC_HDDSIZE, hddsizetbl); - SetFocus(GetDlgItem(hWnd, IDC_HDDSIZE)); - return(FALSE); - - case WM_COMMAND: - switch (LOWORD(wp)) { - case IDOK: - GetWindowText(GetDlgItem(hWnd, IDC_HDDSIZE), - work, sizeof(work)); - val = (UINT)milstr_solveINT(work); - if (val < 0) { - val = 0; - } - else if (val > 512) { - val = 512; - } - hddsize = val; - EndDialog(hWnd, IDOK); - break; - - case IDCANCEL: - EndDialog(hWnd, IDCANCEL); - break; - - default: - return(FALSE); - } - break; - - case WM_CLOSE: - PostMessage(hWnd, WM_COMMAND, IDCANCEL, 0); - break; - - default: - return(FALSE); - } - return(TRUE); -} - -static LRESULT CALLBACK NewdiskDlgProc(HWND hWnd, UINT msg, - WPARAM wp, LPARAM lp) { - - WORD res; - - switch (msg) { - case WM_INITDIALOG: - switch(makefdtype) { - case (DISKTYPE_2DD << 4): - res = IDC_MAKE2DD; - break; - - case (DISKTYPE_2HD << 4): - res = IDC_MAKE2HD; - break; - - default: - res = IDC_MAKE144; - break; - } - SetDlgItemCheck(hWnd, res, 1); - SetFocus(GetDlgItem(hWnd, IDC_DISKLABEL)); - return(FALSE); - - case WM_COMMAND: - switch (LOWORD(wp)) { - case IDOK: - GetWindowText(GetDlgItem(hWnd, IDC_DISKLABEL), - disklabel, sizeof(disklabel)); - if (milstr_kanji1st(disklabel, sizeof(disklabel) - 1)) { - disklabel[sizeof(disklabel) - 1] = '\0'; - } - if (GetDlgItemCheck(hWnd, IDC_MAKE2DD)) { - makefdtype = (DISKTYPE_2DD << 4); + mkstr255(sizestr, "41"); + SetDialogItemText(GetDlgItem(hDlg, IDC_HDDSIZE), sizestr); + SelectDialogItemText(hDlg, IDC_HDDSIZE, 0x0000, 0x7fff); + SPRINTF(work, "(%d-%dMB)", hddminsize, hddmaxsize); + mkstr255(sizestr, work); + SetDialogItemText(GetDlgItem(hDlg, IDC_HDDLIMIT), sizestr); + SetDialogDefaultItem(hDlg, IDOK); + SetDialogCancelItem(hDlg, IDCANCEL); + + done = 0; + while(!done) { + ModalDialog(NULL, &item); + switch(item) { + case IDOK: + GetDialogItemText(GetDlgItem(hDlg, IDC_HDDSIZE), sizestr); + mkcstr(work, sizeof(work), sizestr); + *hddsize = milstr_solveINT(work); + done = IDOK; + break; + + case IDCANCEL: + done = IDCANCEL; + break; + } + } + DisposeDialog(hDlg); + return(done); +} + +static const short sasires[6] = + {IDC_NEWSASI5MB, IDC_NEWSASI10MB, IDC_NEWSASI15MB, + IDC_NEWSASI20MB, IDC_NEWSASI30MB, IDC_NEWSASI40MB}; + +static int NewSASIDlgProc(UINT *hddtype) { + + DialogPtr hDlg; + int i; + ControlHandle btn[6]; + int done; + short item; + int type; + + hDlg = GetNewDialog(IDD_NEWSASIHDD, NULL, (WindowPtr)-1); + if (!hDlg) { + return(IDCANCEL); + } + for (i=0; i<6; i++) { + btn[i] = (ControlHandle)GetDlgItem(hDlg, sasires[i]); + SetControlValue(btn[i], 0); + } + SetDialogDefaultItem(hDlg, IDOK); + SetDialogCancelItem(hDlg, IDCANCEL); + + done = 0; + type = -1; + while(!done) { + ModalDialog(NULL, &item); + switch(item) { + case IDOK: + if (type >= 0) { + if (type > 3) { + type++; } - else if (GetDlgItemCheck(hWnd, IDC_MAKE2HD)) { - makefdtype = (DISKTYPE_2HD << 4); + *hddtype = type; + done = IDOK; + } + break; + + case IDCANCEL: + done = IDCANCEL; + break; + + case IDC_NEWSASI5MB: + case IDC_NEWSASI10MB: + case IDC_NEWSASI15MB: + case IDC_NEWSASI20MB: + case IDC_NEWSASI30MB: + case IDC_NEWSASI40MB: + for (i=0; i<6; i++) { + if (item == sasires[i]) { + SetControlValue(btn[i], 1); + type = i; } else { - makefdtype = (DISKTYPE_2HD << 4) + 1; + SetControlValue(btn[i], 0); } - EndDialog(hWnd, IDOK); - break; - - case IDCANCEL: - EndDialog(hWnd, IDCANCEL); - break; + } + break; + } + } + DisposeDialog(hDlg); + return(done); +} - default: - return(FALSE); - } - break; +static int NewdiskDlgProc(NEWDISK *newdisk) { - case WM_CLOSE: - PostMessage(hWnd, WM_COMMAND, IDCANCEL, 0); - break; + BOOL usefd144; + DialogPtr hDlg; + int media; + int done; + short item; + Str255 disklabel; + ControlHandle btn[3]; + + usefd144 = (np2cfg.usefd144)?TRUE:FALSE; + if (!usefd144) { + hDlg = GetNewDialog(IDD_NEWFDDDISK, NULL, (WindowPtr)-1); + } + else { + hDlg = GetNewDialog(IDD_NEWFDDDISK2, NULL, (WindowPtr)-1); + } + if (!hDlg) { + return(IDCANCEL); + } - default: - return(FALSE); + SelectDialogItemText(hDlg, IDC_DISKLABEL, 0x0000, 0x7fff); + btn[0] = (ControlHandle)GetDlgItem(hDlg, IDC_MAKE2DD); + btn[1] = (ControlHandle)GetDlgItem(hDlg, IDC_MAKE2HD); + btn[2] = (ControlHandle)NULL; + if (usefd144) { + btn[2] = (ControlHandle)GetDlgItem(hDlg, IDC_MAKE144); } - return(TRUE); + SetControlValue(btn[0], 0); + SetControlValue(btn[1], 1); + media = 1; + SetDialogDefaultItem(hDlg, IDOK); + SetDialogCancelItem(hDlg, IDCANCEL); + + done = 0; + while(!done) { + ModalDialog(NULL, &item); + switch(item) { + case IDOK: + if (media == 0) { + newdisk->fdtype = (DISKTYPE_2DD << 4); + } + else if (media == 1) { + newdisk->fdtype = (DISKTYPE_2HD << 4); + } + else { + newdisk->fdtype = (DISKTYPE_2HD << 4) + 1; + } + GetDialogItemText(GetDlgItem(hDlg, IDC_DISKLABEL), disklabel); + mkcstr(newdisk->label, sizeof(newdisk->label), disklabel); + done = IDOK; + break; + + case IDCANCEL: + done = IDCANCEL; + break; + + case IDC_DISKLABEL: + break; + + case IDC_MAKE2DD: + SetControlValue(btn[0], 1); + SetControlValue(btn[1], 0); + if (usefd144) { + SetControlValue(btn[2], 0); + } + media = 0; + break; + + case IDC_MAKE2HD: + SetControlValue(btn[0], 0); + SetControlValue(btn[1], 1); + if (usefd144) { + SetControlValue(btn[2], 0); + } + media = 1; + break; + + case IDC_MAKE144: + if (usefd144) { + SetControlValue(btn[0], 0); + SetControlValue(btn[1], 0); + SetControlValue(btn[2], 1); + media = 2; + } + break; + } + } + DisposeDialog(hDlg); + return(done); } -void dialog_newdisk(HWND hWnd) { - - char path[MAX_PATH]; -const char *p; - HINSTANCE hinst; +void dialog_newdisk(void) { - file_cpyname(path, fddfolder, sizeof(path)); - file_cutname(path); - file_catname(path, str_newdisk, sizeof(path)); + char path[MAX_PATH]; + char *ext; + UINT hddsize; + NEWDISK disk; - p = dlgs_selectwritefile(hWnd, &newdiskui, path, NULL, 0); - if (p == NULL) { + if (!dlgs_selectwritefile(path, sizeof(path), str_newdisk)) { return; } - hinst = (HINSTANCE)GetWindowLong(hWnd, GWL_HINSTANCE); - if (!file_cmpname(file_getext((char *)p), str_thd)) { + ext = file_getext(path); + if (!file_cmpname(ext, str_thd)) { hddsize = 0; - if (DialogBox(hinst, MAKEINTRESOURCE(IDD_NEWHDDDISK), - hWnd, (DLGPROC)NewHddDlgProc) == IDOK) { - newdisk_hdd(p, hddsize); // (hddsize < 5) || (hddsize > 256) + if (NewHddDlgProc(&hddsize, 5, 256) == IDOK) { + newdisk_thd(path, hddsize); } } - else { - if (DialogBox(hinst, - MAKEINTRESOURCE(np2cfg.usefd144?IDD_NEWDISK2:IDD_NEWDISK), - hWnd, (DLGPROC)NewdiskDlgProc) == IDOK) { - newdisk_fdd(p, makefdtype, disklabel); + else if (!file_cmpname(ext, str_nhd)) { + hddsize = 0; + if (NewHddDlgProc(&hddsize, 5, 512) == IDOK) { + newdisk_vhd(path, hddsize); + } + } + else if (!file_cmpname(ext, str_hdi)) { + hddsize = 7; + if (NewSASIDlgProc(&hddsize) == IDOK) { + newdisk_hdi(path, hddsize); + } + } +#if defined(SUPPORT_SCSI) + else if (!file_cmpname(ext, str_hdd)) { + hddsize = 0; + if (NewHddDlgProc(&hddsize, 2, 512) == IDOK) { + newdisk_vhd(path, hddsize); } } -} #endif + else if ((!file_cmpname(ext, str_d88)) || + (!file_cmpname(ext, str_d98)) || + (!file_cmpname(ext, str_88d)) || + (!file_cmpname(ext, str_98d))) { + if (NewdiskDlgProc(&disk) == IDOK) { + newdisk_fdd(path, disk.fdtype, disk.label); + } + } +}