PageRenderTime 73ms CodeModel.GetById 26ms RepoModel.GetById 1ms app.codeStats 1ms

/od-win32/win32gui.cpp

https://github.com/tonioni/WinUAE
C++ | 15555 lines | 15110 code | 381 blank | 64 comment | 1330 complexity | eeb3e163cdcafdf0708842f96576f6dc MD5 | raw file
  1. /*==========================================================================
  2. *
  3. * Copyright (C) 1996 Brian King
  4. *
  5. * File: win32gui.c
  6. * Content: Win32-specific gui features for UAE port.
  7. *
  8. ***************************************************************************/
  9. #define CONFIGCACHE 1
  10. #define FRONTEND 0
  11. #define _WIN32_WINNT 0x600
  12. #include <stdio.h>
  13. #include <stdlib.h>
  14. #include <windows.h>
  15. #include <windowsx.h>
  16. #include <winspool.h>
  17. #include <winuser.h>
  18. #include <mmsystem.h>
  19. #include <commctrl.h>
  20. #include <commdlg.h>
  21. #include <dlgs.h>
  22. #include <prsht.h>
  23. #include <richedit.h>
  24. #include <shellapi.h>
  25. #include <Shlobj.h>
  26. #include <shlwapi.h>
  27. #include <ddraw.h>
  28. #include <shobjidl.h>
  29. #include <dbt.h>
  30. #include <Cfgmgr32.h>
  31. #include "resource.h"
  32. #include "sysconfig.h"
  33. #include "sysdeps.h"
  34. #include "gui.h"
  35. #include "options.h"
  36. #include "memory.h"
  37. #include "rommgr.h"
  38. #include "custom.h"
  39. #include "events.h"
  40. #include "newcpu.h"
  41. #include "traps.h"
  42. #include "disk.h"
  43. #include "uae.h"
  44. #include "threaddep/thread.h"
  45. #include "filesys.h"
  46. #include "autoconf.h"
  47. #include "inputdevice.h"
  48. #include "inputrecord.h"
  49. #include "xwin.h"
  50. #include "keyboard.h"
  51. #include "zfile.h"
  52. #include "parallel.h"
  53. #include "audio.h"
  54. #include "arcadia.h"
  55. #include "drawing.h"
  56. #include "fsdb.h"
  57. #include "blkdev.h"
  58. #include "dxwrap.h"
  59. #include "win32.h"
  60. #include "registry.h"
  61. #include "picasso96_win.h"
  62. #include "win32gui.h"
  63. #include "win32gfx.h"
  64. #include "sounddep/sound.h"
  65. #include "od-win32/parser.h"
  66. #include "od-win32/ahidsound.h"
  67. #include "target.h"
  68. #include "savestate.h"
  69. #include "avioutput.h"
  70. #include "opengl.h"
  71. #include "direct3d.h"
  72. #include "akiko.h"
  73. #include "cdtv.h"
  74. #include "gfxfilter.h"
  75. #include "driveclick.h"
  76. #include "scsi.h"
  77. #include "cpuboard.h"
  78. #include "x86.h"
  79. #include "sana2.h"
  80. #ifdef PROWIZARD
  81. #include "moduleripper.h"
  82. #endif
  83. #include "catweasel.h"
  84. #include "lcd.h"
  85. #include "uaeipc.h"
  86. #include "crc32.h"
  87. #include "rp.h"
  88. #include "statusline.h"
  89. #include "zarchive.h"
  90. #include "gfxboard.h"
  91. #include "win32_uaenet.h"
  92. #include "uae/ppc.h"
  93. #ifdef RETROPLATFORM
  94. #include "rp.h"
  95. #endif
  96. #include "ini.h"
  97. #include "specialmonitors.h"
  98. #include "gayle.h"
  99. #ifdef FLOPPYBRIDGE
  100. #include "floppybridge/floppybridge_abstract.h"
  101. #include "floppybridge/floppybridge_lib.h"
  102. #endif
  103. #define GUI_SCALE_DEFAULT 100
  104. #define ARCHIVE_STRING _T("*.zip;*.7z;*.rar;*.lha;*.lzh;*.lzx")
  105. #define DISK_FORMAT_STRING _T("(*.adf;*.adz;*.gz;*.dms;*.ipf;*.scp;*.fdi;*.exe)\0*.adf;*.adz;*.gz;*.dms;*.ipf;*.scp;*.fdi;*.exe;*.ima;*.wrp;*.dsq;*.st;*.raw;") ARCHIVE_STRING _T("\0")
  106. #define ROM_FORMAT_STRING _T("(*.rom;*.roz;*.bin;*.a500;*.a600;*.a1200;*.a4000)\0*.rom;*.roz;*.bin;*.a500;*.a600;*.a1200;*.a4000;") ARCHIVE_STRING _T("\0")
  107. #define USS_FORMAT_STRING_RESTORE _T("(*.uss)\0*.uss;*.gz;") ARCHIVE_STRING _T("\0")
  108. #define USS_FORMAT_STRING_SAVE _T("(*.uss)\0*.uss\0")
  109. #define HDF_FORMAT_STRING _T("(*.hdf;*.vhd;*.rdf;*.hdz;*.rdz;*.chd)\0*.hdf;*.vhd;*.rdf;*.hdz;*.rdz;*.chd\0")
  110. #define INP_FORMAT_STRING _T("(*.inp)\0*.inp\0")
  111. #define CD_FORMAT_STRING _T("(*.cue;*.ccd;*.mds;*.iso;*.chd;*.nrg)\0*.cue;*.ccd;*.mds;*.iso;*.chd;*.nrg;") ARCHIVE_STRING _T("\0")
  112. #define GEO_FORMAT_STRING _T("(*.geo)\0*.geo\0")
  113. #define CONFIG_HOST _T("Host")
  114. #define CONFIG_HARDWARE _T("Hardware")
  115. #define SOUND_BUFFER_MULTIPLIER 1024
  116. static wstring szNone;
  117. static int allow_quit;
  118. static int restart_requested;
  119. int full_property_sheet = 1;
  120. static struct uae_prefs *pguiprefs;
  121. struct uae_prefs workprefs;
  122. static int currentpage = -1;
  123. static int qs_request_reset;
  124. static int qs_override;
  125. int gui_active, gui_left;
  126. static struct newresource *panelresource;
  127. int dialog_inhibit;
  128. #undef HtmlHelp
  129. #ifndef HH_DISPLAY_TOPIC
  130. #define HH_DISPLAY_TOPIC 0
  131. #endif
  132. extern HWND(WINAPI *pHtmlHelp)(HWND, LPCWSTR, UINT, LPDWORD);
  133. void HtmlHelp(HWND a, LPCWSTR b, UINT c, const TCHAR *d)
  134. {
  135. if (pHtmlHelp) {
  136. (*pHtmlHelp)(a, b, c, (LPDWORD)d);
  137. } else {
  138. if (gui_message_multibutton(1, _T("Help file is not installed locally, do you want to open online version? (http://www.winuae.net/help/)")) == 1) {
  139. if ((int)ShellExecute(NULL, _T("open"), _T("http://www.winuae.net/help/"), NULL, NULL, SW_SHOWNORMAL) <= 32) {
  140. TCHAR szMessage[MAX_DPATH];
  141. WIN32GUI_LoadUIString(IDS_NOHELP, szMessage, MAX_DPATH);
  142. gui_message(szMessage);
  143. }
  144. }
  145. }
  146. }
  147. extern TCHAR help_file[MAX_DPATH];
  148. extern int mouseactive;
  149. TCHAR config_filename[256] = _T("");
  150. static TCHAR config_pathfilename[MAX_DPATH];
  151. static TCHAR config_folder[MAX_DPATH];
  152. static TCHAR config_search[MAX_DPATH];
  153. static TCHAR stored_path[MAX_DPATH];
  154. static int gui_size_changed;
  155. static int filterstackpos = 2 * MAX_FILTERSHADERS;
  156. extern std::vector<FloppyBridgeAPI::FloppyBridgeProfileInformation> bridgeprofiles;
  157. bool isguiactive(void)
  158. {
  159. return gui_active > 0;
  160. }
  161. static const int defaultaspectratios[] = {
  162. 5, 4, 4, 3, 16, 10, 15, 9, 27, 16, 128, 75, 16, 9, 256, 135, 21, 9, 16, 3,
  163. -1
  164. };
  165. static int getaspectratioindex (int ar)
  166. {
  167. for (int i = 0; defaultaspectratios[i] >= 0; i += 2) {
  168. if (ar == defaultaspectratios[i + 0] * ASPECTMULT + defaultaspectratios[i + 1])
  169. return i / 2;
  170. }
  171. return 0;
  172. }
  173. static int getaspectratio (int index)
  174. {
  175. for (int i = 0; defaultaspectratios[i] >= 0; i += 2) {
  176. if (i == index * 2) {
  177. return defaultaspectratios[i + 0] * ASPECTMULT + defaultaspectratios[i + 1];
  178. }
  179. }
  180. return 0;
  181. }
  182. static void addaspectratios (HWND hDlg, int id)
  183. {
  184. for (int i = 0; defaultaspectratios[i] >= 0; i += 2) {
  185. TCHAR tmp[100];
  186. _stprintf (tmp, _T("%d:%d (%.2f)"), defaultaspectratios[i + 0], defaultaspectratios[i + 1], (double)defaultaspectratios[i + 0] / defaultaspectratios[i + 1]);
  187. SendDlgItemMessage (hDlg, id, CB_ADDSTRING, 0, (LPARAM)tmp);
  188. }
  189. }
  190. int scsiromselected = 0;
  191. static int scsiromselectednum = 0;
  192. static int scsiromselectedcatnum = 0;
  193. #define Error(x) MessageBox (NULL, (x), _T("WinUAE Error"), MB_OK)
  194. wstring WIN32GUI_LoadUIString (DWORD id)
  195. {
  196. wchar_t tmp[MAX_DPATH];
  197. tmp[0] = 0;
  198. if (LoadString (hUIDLL ? hUIDLL : hInst, id, tmp, MAX_DPATH) == 0)
  199. LoadString (hInst, id, tmp, MAX_DPATH);
  200. return wstring(tmp);
  201. }
  202. void WIN32GUI_LoadUIString (DWORD id, TCHAR *string, DWORD dwStringLen)
  203. {
  204. if (LoadString (hUIDLL ? hUIDLL : hInst, id, string, dwStringLen) == 0)
  205. LoadString (hInst, id, string, dwStringLen);
  206. }
  207. static int quickstart_model = 0, quickstart_conf = 0, quickstart_compa = 1;
  208. static int quickstart_model_confstore[16];
  209. static int quickstart_floppy = 1, quickstart_cd = 0, quickstart_ntsc = 0;
  210. static int quickstart_floppytype[2], quickstart_floppysubtype[2];
  211. static TCHAR quickstart_floppysubtypeid[2][32];
  212. static int quickstart_cdtype = 0;
  213. static TCHAR quickstart_cddrive[16];
  214. static int quickstart_ok, quickstart_ok_floppy;
  215. // don't enable yet. issues with quickstart panel
  216. static bool firstautoloadconfig = false;
  217. static void addfloppytype (HWND hDlg, int n);
  218. static void addfloppyhistory (HWND hDlg);
  219. static void addhistorymenu (HWND hDlg, const TCHAR*, int f_text, int type, bool manglepath, int num);
  220. static void addcdtype (HWND hDlg, int id);
  221. static void getfloppyname (HWND hDlg, int n, int cd, int f_text);
  222. static int C_PAGES;
  223. #define MAX_C_PAGES 30
  224. static int LOADSAVE_ID = -1, MEMORY_ID = -1, KICKSTART_ID = -1, CPU_ID = -1,
  225. DISPLAY_ID = -1, HW3D_ID = -1, CHIPSET_ID = -1, CHIPSET2_ID = -1, SOUND_ID = -1, FLOPPY_ID = -1, DISK_ID = -1,
  226. HARDDISK_ID = -1, IOPORTS_ID = -1, GAMEPORTS_ID = -1, INPUT_ID = -1, MISC1_ID = -1, MISC2_ID = -1,
  227. AVIOUTPUT_ID = -1, PATHS_ID = -1, QUICKSTART_ID = -1, ABOUT_ID = -1, EXPANSION_ID = -1, EXPANSION2_ID = -1,
  228. BOARD_ID = -1, FRONTEND_ID = -1;
  229. static const int INPUTMAP_ID = MAX_C_PAGES - 1;
  230. static HWND pages[MAX_C_PAGES];
  231. #define MAX_IMAGETOOLTIPS 10
  232. static HWND guiDlg, panelDlg, ToolTipHWND;
  233. static struct dlgcontext maindctx;
  234. static HACCEL hAccelTable;
  235. static HWND customDlg;
  236. static int customDlgType;
  237. struct ToolTipHWNDS {
  238. WNDPROC proc;
  239. HWND hwnd;
  240. int imageid;
  241. };
  242. static struct ToolTipHWNDS ToolTipHWNDS2[MAX_IMAGETOOLTIPS + 1];
  243. struct GUIPAGE {
  244. DLGPROC dlgproc;
  245. LPCTSTR title;
  246. LPCTSTR icon;
  247. HTREEITEM tv;
  248. int himg;
  249. int idx;
  250. const TCHAR *help;
  251. HACCEL accel;
  252. int fullpanel;
  253. struct newresource *nres;
  254. int focusid;
  255. };
  256. static struct GUIPAGE ppage[MAX_C_PAGES];
  257. static bool ischecked (HWND hDlg, DWORD id)
  258. {
  259. return IsDlgButtonChecked (hDlg, id) == BST_CHECKED;
  260. }
  261. static void setchecked (HWND hDlg, DWORD id, bool checked)
  262. {
  263. CheckDlgButton (hDlg, id, checked ? BST_CHECKED : BST_UNCHECKED);
  264. }
  265. static void setfocus (HWND hDlg, int id)
  266. {
  267. SendMessage (hDlg, WM_NEXTDLGCTL, (WPARAM)GetDlgItem (hDlg, id), TRUE);
  268. }
  269. static void ew (HWND hDlg, DWORD id, int enable)
  270. {
  271. if (id == -1)
  272. return;
  273. HWND w = GetDlgItem (hDlg, id);
  274. if (!w)
  275. return;
  276. if (!enable && w == GetFocus ())
  277. SendMessage (hDlg, WM_NEXTDLGCTL, 0, FALSE);
  278. EnableWindow (w, !!enable);
  279. }
  280. static void hide (HWND hDlg, DWORD id, int hide)
  281. {
  282. HWND w;
  283. if (id == -1)
  284. return;
  285. w = GetDlgItem (hDlg, id);
  286. if (!w)
  287. return;
  288. if (hide && w == GetFocus ())
  289. SendMessage (hDlg, WM_NEXTDLGCTL, 0, FALSE);
  290. ShowWindow (w, hide ? SW_HIDE : SW_SHOW);
  291. }
  292. static void parsefilepath(TCHAR *path, int maxlen)
  293. {
  294. TCHAR *tmp = xmalloc(TCHAR, maxlen + 1);
  295. _tcscpy(tmp, path);
  296. TCHAR *p1 = _tcsstr(tmp, _T(" { "));
  297. TCHAR *p2 = _tcsstr(tmp, _T(" }"));
  298. if (p1 && p2 && p2 > p1) {
  299. *p1 = 0;
  300. memset(path, 0, maxlen * sizeof(TCHAR));
  301. memcpy(path, p1 + 3, (p2 - p1 - 3) * sizeof(TCHAR));
  302. _tcscat(path, tmp);
  303. }
  304. xfree(tmp);
  305. }
  306. static int scsiromselect_table[300];
  307. static bool getcomboboxtext(HWND hDlg, int id, TCHAR *out, int maxlen)
  308. {
  309. out[0] = 0;
  310. int posn = SendDlgItemMessage(hDlg, id, CB_GETCURSEL, 0, 0L);
  311. if (posn == CB_ERR) {
  312. GetDlgItemText(hDlg, id, out, maxlen);
  313. return true;
  314. }
  315. int len = SendDlgItemMessage(hDlg, id, CB_GETLBTEXTLEN, posn, 0);
  316. if (len < maxlen) {
  317. len = SendDlgItemMessage(hDlg, id, CB_GETLBTEXT, posn, (LPARAM)out);
  318. }
  319. return true;
  320. }
  321. static void gui_add_string(int *table, HWND hDlg, int item, int id, const TCHAR *str)
  322. {
  323. while (*table >= 0)
  324. table++;
  325. *table++ = id;
  326. *table = -1;
  327. SendDlgItemMessage(hDlg, item, CB_ADDSTRING, 0, (LPARAM)str);
  328. }
  329. static void gui_set_string_cursor(int *table, HWND hDlg, int item, int id)
  330. {
  331. int idx = 0;
  332. while (*table >= 0) {
  333. if (*table == id) {
  334. SendDlgItemMessage(hDlg, item, CB_SETCURSEL, idx, 0);
  335. return;
  336. }
  337. idx++;
  338. table++;
  339. }
  340. }
  341. static int gui_get_string_cursor(int *table, HWND hDlg, int item)
  342. {
  343. int posn = SendDlgItemMessage (hDlg, item, CB_GETCURSEL, 0, 0);
  344. if (posn < 0)
  345. return CB_ERR;
  346. return table[posn];
  347. }
  348. static void commonproc(HWND hDlg, UINT msg, WPARAM wParam, LPARAM lParam)
  349. {
  350. if (msg == WM_DPICHANGED) {
  351. RECT *const r = (RECT *)lParam;
  352. SetWindowPos(hDlg, NULL, r->left, r->top, r->right - r->left, r->bottom - r->top, SWP_NOZORDER | SWP_NOACTIVATE);
  353. }
  354. }
  355. static int stringboxdialogactive;
  356. static INT_PTR CALLBACK StringBoxDialogProc (HWND hDlg, UINT msg, WPARAM wParam, LPARAM lParam)
  357. {
  358. if (dialog_inhibit)
  359. return 0;
  360. switch(msg)
  361. {
  362. case WM_DESTROY:
  363. PostQuitMessage (0);
  364. return TRUE;
  365. case WM_CLOSE:
  366. stringboxdialogactive = 0;
  367. DestroyWindow (hDlg);
  368. return TRUE;
  369. case WM_INITDIALOG:
  370. return TRUE;
  371. case WM_COMMAND:
  372. switch (LOWORD (wParam))
  373. {
  374. case IDOK:
  375. stringboxdialogactive = -1;
  376. DestroyWindow (hDlg);
  377. return TRUE;
  378. case IDCANCEL:
  379. stringboxdialogactive = 0;
  380. DestroyWindow (hDlg);
  381. return TRUE;
  382. }
  383. break;
  384. }
  385. commonproc(hDlg, msg, wParam, lParam);
  386. return FALSE;
  387. }
  388. static int CALLBACK BrowseForFolderCallback (HWND hwnd, UINT uMsg, LPARAM lp, LPARAM pData)
  389. {
  390. TCHAR szPath[MAX_DPATH];
  391. switch(uMsg)
  392. {
  393. case BFFM_INITIALIZED:
  394. SendMessage (hwnd, BFFM_SETSELECTION, TRUE, pData);
  395. break;
  396. case BFFM_SELCHANGED:
  397. if (SHGetPathFromIDList ((LPITEMIDLIST)lp ,szPath))
  398. SendMessage(hwnd, BFFM_SETSTATUSTEXT, 0, (LPARAM)szPath);
  399. break;
  400. }
  401. return 0;
  402. }
  403. static int DirectorySelection2 (OPENFILENAME *ofn)
  404. {
  405. BROWSEINFO bi;
  406. LPITEMIDLIST pidlBrowse;
  407. TCHAR buf[MAX_DPATH], fullpath[MAX_DPATH];
  408. TCHAR *path = ofn->lpstrFile;
  409. int ret = 0;
  410. buf[0] = 0;
  411. memset (&bi, 0, sizeof bi);
  412. bi.hwndOwner = ofn->hwndOwner;
  413. bi.pidlRoot = NULL;
  414. bi.pszDisplayName = buf;
  415. bi.lpszTitle = NULL;
  416. bi.ulFlags = BIF_DONTGOBELOWDOMAIN | BIF_RETURNONLYFSDIRS | BIF_NEWDIALOGSTYLE;
  417. if (path[0] && GetFullPathName (path, sizeof fullpath / sizeof (TCHAR), fullpath, NULL)) {
  418. bi.lpfn = BrowseForFolderCallback;
  419. bi.lParam = (LPARAM)fullpath;
  420. }
  421. // Browse for a folder and return its PIDL.
  422. pidlBrowse = SHBrowseForFolder (&bi);
  423. if (pidlBrowse != NULL) {
  424. if (SHGetPathFromIDList (pidlBrowse, buf)) {
  425. _tcscpy (path, buf);
  426. ret = 1;
  427. }
  428. CoTaskMemFree (pidlBrowse);
  429. }
  430. return ret;
  431. }
  432. static TCHAR *getfilepath (TCHAR *s)
  433. {
  434. TCHAR *p = _tcsrchr (s, '\\');
  435. if (p)
  436. return p + 1;
  437. return NULL;
  438. }
  439. typedef HRESULT (CALLBACK* SHCREATEITEMFROMPARSINGNAME)
  440. (PCWSTR,IBindCtx*,REFIID,void**); // Vista+ only
  441. // OPENFILENAME->IFileOpenDialog wrapper
  442. static BOOL GetFileDialog (OPENFILENAME *opn, const GUID *guid, int mode)
  443. {
  444. SHCREATEITEMFROMPARSINGNAME pSHCreateItemFromParsingName;
  445. HRESULT hr;
  446. IFileOpenDialog *pfd;
  447. FILEOPENDIALOGOPTIONS pfos;
  448. IShellItem *shellitem = NULL;
  449. int ret;
  450. COMDLG_FILTERSPEC *fs = NULL;
  451. int filtercnt = 0;
  452. static const GUID fsdialogguid = { 0xe768b477, 0x3684, 0x4128, { 0x91, 0x55, 0x8c, 0x8f, 0xd9, 0x2d, 0x16, 0x7b } };
  453. if (isfullscreen () > 0)
  454. guid = &fsdialogguid;
  455. hr = E_FAIL;
  456. ret = 0;
  457. pSHCreateItemFromParsingName = (SHCREATEITEMFROMPARSINGNAME)GetProcAddress (
  458. GetModuleHandle (_T("shell32.dll")), "SHCreateItemFromParsingName");
  459. if (pSHCreateItemFromParsingName)
  460. hr = CoCreateInstance (mode > 0 ? __uuidof(FileSaveDialog) : __uuidof(FileOpenDialog),
  461. NULL,
  462. CLSCTX_INPROC_SERVER,
  463. mode > 0 ? IID_IFileSaveDialog : IID_IFileOpenDialog, (LPVOID*)&pfd);
  464. if (FAILED (hr)) {
  465. if (mode > 0)
  466. return GetSaveFileName (opn);
  467. else if (mode == 0)
  468. return GetOpenFileName (opn);
  469. else
  470. return DirectorySelection2 (opn);
  471. }
  472. pfd->GetOptions (&pfos);
  473. pfos |= FOS_FORCEFILESYSTEM;
  474. if (!(opn->Flags & OFN_FILEMUSTEXIST))
  475. pfos &= ~FOS_FILEMUSTEXIST;
  476. if (opn->Flags & OFN_ALLOWMULTISELECT)
  477. pfos |= FOS_ALLOWMULTISELECT;
  478. if (mode < 0)
  479. pfos |= FOS_PICKFOLDERS;
  480. pfd->SetOptions (pfos);
  481. opn->nFileOffset = 0;
  482. if (guid)
  483. pfd->SetClientGuid (*guid);
  484. if (opn->lpstrFilter) {
  485. const TCHAR *p = opn->lpstrFilter;
  486. int i;
  487. while (*p) {
  488. p += _tcslen (p) + 1;
  489. p += _tcslen (p) + 1;
  490. filtercnt++;
  491. }
  492. if (filtercnt) {
  493. fs = xmalloc (COMDLG_FILTERSPEC, filtercnt);
  494. p = opn->lpstrFilter;
  495. for (i = 0; i < filtercnt; i++) {
  496. fs[i].pszName = p;
  497. p += _tcslen (p) + 1;
  498. fs[i].pszSpec = p;
  499. p += _tcslen (p) + 1;
  500. }
  501. pfd->SetFileTypes (filtercnt, fs);
  502. }
  503. pfd->SetFileTypeIndex (opn->nFilterIndex);
  504. }
  505. if (mode >= 0 && opn->lpstrFile) {
  506. pfd->SetFileName(opn->lpstrFile);
  507. }
  508. if (opn->lpstrTitle) {
  509. pfd->SetTitle (opn->lpstrTitle);
  510. }
  511. if (opn->lpstrDefExt) {
  512. pfd->SetDefaultExtension (opn->lpstrDefExt);
  513. }
  514. if (opn->lpstrInitialDir) {
  515. TCHAR tmp[MAX_DPATH];
  516. const TCHAR *p = opn->lpstrInitialDir;
  517. if (GetFullPathName (p, sizeof tmp / sizeof (TCHAR), tmp, NULL))
  518. p = tmp;
  519. hr = pSHCreateItemFromParsingName (p, NULL, IID_IShellItem, (void**)&shellitem);
  520. if (SUCCEEDED (hr))
  521. pfd->SetFolder (shellitem);
  522. }
  523. hr = pfd->Show (opn->hwndOwner);
  524. if (SUCCEEDED (hr)) {
  525. UINT idx;
  526. IShellItemArray *pitema;
  527. opn->lpstrFile[0] = 0;
  528. opn->lpstrFile[1] = 0;
  529. if (opn->lpstrFileTitle)
  530. opn->lpstrFileTitle[0] = 0;
  531. if (mode > 0) {
  532. IShellItem *pitem;
  533. hr = pfd->GetResult (&pitem);
  534. if (SUCCEEDED (hr)) {
  535. WCHAR *path = NULL;
  536. hr = pitem->GetDisplayName (SIGDN_FILESYSPATH, &path);
  537. if (SUCCEEDED (hr)) {
  538. TCHAR *p = opn->lpstrFile;
  539. _tcscpy (p, path);
  540. p[_tcslen (p) + 1] = 0;
  541. p = getfilepath (opn->lpstrFile);
  542. if (p && opn->lpstrFileTitle)
  543. _tcscpy (opn->lpstrFileTitle, p);
  544. }
  545. pitem->Release ();
  546. }
  547. } else {
  548. hr = pfd->GetResults (&pitema);
  549. if (SUCCEEDED (hr)) {
  550. DWORD cnt;
  551. hr = pitema->GetCount (&cnt);
  552. if (SUCCEEDED (hr)) {
  553. int i, first = true;
  554. for (i = 0; i < cnt; i++) {
  555. IShellItem *pitem;
  556. hr = pitema->GetItemAt (i, &pitem);
  557. if (SUCCEEDED (hr)) {
  558. WCHAR *path = NULL;
  559. hr = pitem->GetDisplayName (SIGDN_FILESYSPATH, &path);
  560. if (SUCCEEDED (hr)) {
  561. TCHAR *ppath = path;
  562. TCHAR *p = opn->lpstrFile;
  563. while (*p)
  564. p += _tcslen (p) + 1;
  565. TCHAR *pathfilename = _tcsrchr (ppath, '\\');
  566. if (pathfilename)
  567. pathfilename++;
  568. if (first && cnt > 1) {
  569. opn->nFileOffset = pathfilename - ppath;
  570. _tcscpy (p, ppath);
  571. p[opn->nFileOffset - 1] = 0;
  572. p += _tcslen (p) + 1;
  573. *p = 0;
  574. ppath = pathfilename;
  575. } else if (cnt > 1) {
  576. ppath = pathfilename;
  577. } else {
  578. ppath = path;
  579. }
  580. if (!ppath)
  581. ppath = path;
  582. if (p - opn->lpstrFile + _tcslen (ppath) + 2 < opn->nMaxFile) {
  583. _tcscpy (p, ppath);
  584. p[_tcslen (p) + 1] = 0;
  585. }
  586. if (opn->lpstrFileTitle && !opn->lpstrFileTitle[0]) {
  587. p = getfilepath (opn->lpstrFile);
  588. if (p && opn->lpstrFileTitle)
  589. _tcscpy (opn->lpstrFileTitle, p);
  590. }
  591. first = false;
  592. }
  593. CoTaskMemFree (path);
  594. }
  595. }
  596. }
  597. pitema->Release ();
  598. }
  599. }
  600. hr = pfd->GetFileTypeIndex (&idx);
  601. if (SUCCEEDED (hr))
  602. opn->nFilterIndex = idx;
  603. ret = 1;
  604. }
  605. pfd->Release ();
  606. if (shellitem)
  607. shellitem->Release ();
  608. if (filtercnt) {
  609. xfree (fs);
  610. }
  611. return ret;
  612. }
  613. static BOOL GetOpenFileName_2 (HWND parent, OPENFILENAME *opn, const GUID *guid)
  614. {
  615. BOOL val;
  616. val = GetFileDialog (opn, guid, 0);
  617. return val;
  618. }
  619. static BOOL GetSaveFileName_2 (HWND parent, OPENFILENAME *opn, const GUID *guid)
  620. {
  621. BOOL val;
  622. val = GetFileDialog (opn, guid, 1);
  623. return val;
  624. }
  625. int DirectorySelection (HWND hDlg, const GUID *guid, TCHAR *path)
  626. {
  627. int val;
  628. OPENFILENAME ofn = { 0 };
  629. ofn.hwndOwner = hDlg;
  630. ofn.lpstrFile = path;
  631. ofn.lpstrInitialDir = path;
  632. ofn.nMaxFile = MAX_DPATH;
  633. val = GetFileDialog (&ofn, NULL, -1);
  634. fullpath (path, MAX_DPATH);
  635. return val;
  636. }
  637. static const TCHAR *historytypes[] =
  638. {
  639. _T("DiskImageMRUList"),
  640. _T("CDImageMRUList"),
  641. _T("DirFileSysMRUList"),
  642. _T("HardfileMRUList"),
  643. _T("FileSysMRUList"),
  644. _T("TapeImageMRUList"),
  645. _T("GenlockImageMRUList"),
  646. _T("GenlockVideoMRUList"),
  647. _T("GeometryMRUList"),
  648. _T("StatefileMRUList"),
  649. _T("ConfigfileMRUList")
  650. };
  651. static int regread;
  652. static void write_disk_history2 (int type)
  653. {
  654. int i, j;
  655. TCHAR tmp[16];
  656. UAEREG *fkey;
  657. if (!(regread & (1 << type)))
  658. return;
  659. fkey = regcreatetree (NULL, historytypes[type]);
  660. if (fkey == NULL)
  661. return;
  662. j = 1;
  663. for (i = 0; i <= MAX_PREVIOUS_IMAGES; i++) {
  664. TCHAR *s = DISK_history_get (i, type);
  665. if (s == 0 || _tcslen (s) == 0)
  666. continue;
  667. _stprintf (tmp, _T("Image%02d"), j);
  668. regsetstr (fkey, tmp, s);
  669. j++;
  670. }
  671. while (j <= MAX_PREVIOUS_IMAGES) {
  672. const TCHAR *s = _T("");
  673. _stprintf (tmp, _T("Image%02d"), j);
  674. regsetstr (fkey, tmp, s);
  675. j++;
  676. }
  677. regclosetree (fkey);
  678. }
  679. void write_disk_history (void)
  680. {
  681. write_disk_history2(HISTORY_FLOPPY);
  682. write_disk_history2(HISTORY_CD);
  683. write_disk_history2(HISTORY_DIR);
  684. write_disk_history2(HISTORY_HDF);
  685. write_disk_history2(HISTORY_FS);
  686. write_disk_history2(HISTORY_TAPE);
  687. write_disk_history2(HISTORY_GENLOCK_IMAGE);
  688. write_disk_history2(HISTORY_GENLOCK_VIDEO);
  689. write_disk_history2(HISTORY_GEO);
  690. write_disk_history2(HISTORY_STATEFILE);
  691. write_disk_history2(HISTORY_CONFIGFILE);
  692. }
  693. void reset_disk_history (void)
  694. {
  695. int i, rrold;
  696. for (i = 0; i < MAX_PREVIOUS_IMAGES; i++) {
  697. DISK_history_add(NULL, i, HISTORY_FLOPPY, 0);
  698. DISK_history_add(NULL, i, HISTORY_CD, 0);
  699. DISK_history_add(NULL, i, HISTORY_DIR, 0);
  700. DISK_history_add(NULL, i, HISTORY_HDF, 0);
  701. DISK_history_add(NULL, i, HISTORY_FS, 0);
  702. DISK_history_add(NULL, i, HISTORY_TAPE, 0);
  703. DISK_history_add(NULL, i, HISTORY_GENLOCK_IMAGE, 0);
  704. DISK_history_add(NULL, i, HISTORY_GENLOCK_VIDEO, 0);
  705. DISK_history_add(NULL, i, HISTORY_GEO, 0);
  706. DISK_history_add(NULL, i, HISTORY_STATEFILE, 0);
  707. DISK_history_add(NULL, i, HISTORY_CONFIGFILE, 0);
  708. }
  709. rrold = regread;
  710. regread = (1 << HISTORY_MAX) - 1;
  711. write_disk_history ();
  712. regread = rrold;
  713. }
  714. UAEREG *read_disk_history (int type)
  715. {
  716. TCHAR tmp2[MAX_DPATH];
  717. int size, size2;
  718. int idx, idx2;
  719. UAEREG *fkey;
  720. TCHAR tmp[MAX_DPATH];
  721. fkey = regcreatetree (NULL, historytypes[type]);
  722. if (fkey == NULL || (regread & (1 << type)))
  723. return fkey;
  724. idx = 0;
  725. for (;;) {
  726. size = sizeof (tmp) / sizeof (TCHAR);
  727. size2 = sizeof (tmp2) / sizeof (TCHAR);
  728. if (!regenumstr (fkey, idx, tmp, &size, tmp2, &size2))
  729. break;
  730. if (_tcslen (tmp) == 7) {
  731. idx2 = _tstol (tmp + 5) - 1;
  732. if (idx2 >= 0)
  733. DISK_history_add (tmp2, idx2, type, type != HISTORY_FLOPPY && type != HISTORY_CD);
  734. }
  735. idx++;
  736. }
  737. regread |= 1 << type;
  738. return fkey;
  739. }
  740. void exit_gui (int ok)
  741. {
  742. if (!gui_active)
  743. return;
  744. if (guiDlg == NULL)
  745. return;
  746. SendMessage (guiDlg, WM_COMMAND, ok ? IDOK : IDCANCEL, 0);
  747. }
  748. static int getcbn (HWND hDlg, int v, TCHAR *out, int maxlen)
  749. {
  750. LRESULT val = SendDlgItemMessage (hDlg, v, CB_GETCURSEL, 0, 0L);
  751. out[0] = 0;
  752. if (val == CB_ERR) {
  753. SendDlgItemMessage (hDlg, v, WM_GETTEXT, (WPARAM)maxlen, (LPARAM)out);
  754. return 1;
  755. } else {
  756. int len = SendDlgItemMessage(hDlg, v, CB_GETLBTEXTLEN, (WPARAM)val, 0);
  757. if (len < maxlen) {
  758. val = SendDlgItemMessage (hDlg, v, CB_GETLBTEXT, (WPARAM)val, (LPARAM)out);
  759. }
  760. return 0;
  761. }
  762. }
  763. struct favitems
  764. {
  765. TCHAR *value;
  766. TCHAR *path;
  767. int type;
  768. };
  769. #define MAXFAVORITES 30
  770. #define MAXFAVORITESPACE 99
  771. static void writefavoritepaths (int num, struct favitems *fitem)
  772. {
  773. int i, idx;
  774. UAEREG *fkey;
  775. fkey = regcreatetree (NULL, _T("FavoritePaths"));
  776. if (fkey == NULL)
  777. return;
  778. idx = 0;
  779. for (i = 0; i < num; i++) {
  780. TCHAR str[MAX_DPATH];
  781. TCHAR key[100];
  782. if (fitem[i].type != 1)
  783. continue;
  784. if (!_tcscmp (fitem[i].value, fitem[i].path))
  785. _tcscpy (str, fitem[i].value);
  786. else
  787. _stprintf (str, _T("%s \"%s\""), fitem[i].value, fitem[i].path);
  788. _stprintf (key, _T("PATH_ALL_%02d"), idx + 1);
  789. idx++;
  790. regsetstr (fkey, key, str);
  791. xfree (fitem[i].value);
  792. xfree (fitem[i].path);
  793. }
  794. while (idx < MAXFAVORITES) {
  795. TCHAR key[100];
  796. _stprintf (key, _T("PATH_ALL_%02d"), idx + 1);
  797. regdelete (fkey, key);
  798. idx++;
  799. }
  800. regclosetree (fkey);
  801. }
  802. static int askinputcustom (HWND hDlg, TCHAR *custom, int maxlen, DWORD titleid);
  803. static int addfavoritepath (HWND hDlg, int num, struct favitems *fitem)
  804. {
  805. TCHAR name[MAX_DPATH];
  806. const GUID favoriteguid =
  807. { 0xed6e5ad9, 0xc0aa, 0x42fb, { 0x83, 0x3, 0x37, 0x41, 0x77, 0xb4, 0x6f, 0x18 } };
  808. if (num >= MAXFAVORITES)
  809. return 0;
  810. if (!stored_path[0])
  811. GetModuleFileName (NULL, stored_path, MAX_DPATH);
  812. while (stored_path[0]) {
  813. DWORD v = GetFileAttributes (stored_path);
  814. TCHAR *s;
  815. if (v == INVALID_FILE_ATTRIBUTES)
  816. break;
  817. if (v & FILE_ATTRIBUTE_DIRECTORY)
  818. break;
  819. s = _tcsrchr (stored_path, '\\');
  820. if (!s)
  821. s = _tcsrchr (stored_path, '/');
  822. if (!s) {
  823. stored_path[0] = 0;
  824. break;
  825. }
  826. s[0] = 0;
  827. }
  828. if (!DirectorySelection (hDlg, &favoriteguid, stored_path))
  829. return 0;
  830. _tcscpy (name, stored_path);
  831. if (askinputcustom (hDlg, name, sizeof name / sizeof (TCHAR), IDS_SB_FAVORITENAME)) {
  832. fitem[num].value = my_strdup (name);
  833. fitem[num].path = my_strdup (stored_path);
  834. fitem[num].type = 1;
  835. num++;
  836. writefavoritepaths (num, fitem);
  837. }
  838. return 1;
  839. }
  840. static void removefavoritepath (int idx, int num, struct favitems *fitem)
  841. {
  842. int i;
  843. xfree (fitem[idx].value);
  844. xfree (fitem[idx].path);
  845. fitem[idx].value = fitem[idx].path = NULL;
  846. for (i = idx; i < num - 1; i++) {
  847. fitem[i].value = fitem[i + 1].value;
  848. fitem[i].path = fitem[i + 1].path;
  849. }
  850. num--;
  851. writefavoritepaths (num, fitem);
  852. }
  853. static void addeditmenu (HMENU menu, struct favitems *fitem)
  854. {
  855. int i;
  856. HMENU emenu = CreatePopupMenu ();
  857. TCHAR newpath[MAX_DPATH];
  858. MENUITEMINFO mii = { 0 };
  859. mii.cbSize = sizeof mii;
  860. mii.fMask = MIIM_FTYPE;
  861. mii.fType = MFT_SEPARATOR;
  862. mii.fState = MFS_ENABLED;
  863. InsertMenuItem (menu, -1, TRUE, &mii);
  864. mii.fMask = MIIM_STRING | MIIM_ID;
  865. mii.fType = MFT_STRING;
  866. mii.fState = MFS_ENABLED;
  867. mii.dwTypeData = _T("Add New");
  868. mii.cch = _tcslen (mii.dwTypeData);
  869. mii.wID = 1000;
  870. InsertMenuItem (emenu, -1, TRUE, &mii);
  871. i = 0;
  872. while (fitem[i].type) {
  873. if (fitem[i].type == 1) {
  874. mii.fMask = MIIM_STRING | MIIM_ID;
  875. mii.fType = MFT_STRING;
  876. mii.fState = MFS_ENABLED;
  877. mii.wID = 1001 + i;
  878. _stprintf (newpath, _T("Remove '%s'"), fitem[i].value);
  879. mii.dwTypeData = newpath;
  880. mii.cch = _tcslen (mii.dwTypeData);
  881. InsertMenuItem (emenu, -1, TRUE, &mii);
  882. }
  883. i++;
  884. }
  885. mii.fMask = MIIM_STRING | MIIM_SUBMENU;
  886. mii.fType = MFT_STRING;
  887. mii.fState = MFS_ENABLED;
  888. mii.dwTypeData = _T("Edit");
  889. mii.cch = _tcslen (mii.dwTypeData);
  890. mii.hSubMenu = emenu;
  891. InsertMenuItem (menu, -1, TRUE, &mii);
  892. }
  893. static int popupmenu (HWND hwnd, struct favitems *items, int morefiles)
  894. {
  895. int i, item, got;
  896. HMENU menu;
  897. POINT pt;
  898. menu = CreatePopupMenu ();
  899. got = 0;
  900. i = 0;
  901. while (items[i].type) {
  902. if (items[i].type >= 2) {
  903. MENUITEMINFO mii = { 0 };
  904. mii.cbSize = sizeof mii;
  905. mii.fMask = MIIM_STRING | MIIM_ID;
  906. mii.fType = MFT_STRING;
  907. mii.fState = MFS_ENABLED;
  908. mii.wID = items[i].type == 2 ? 1 + i : 990 - 3 + items[i].type;
  909. mii.dwTypeData = items[i].value;
  910. mii.cch = _tcslen (mii.dwTypeData);
  911. InsertMenuItem (menu, -1, TRUE, &mii);
  912. got = 1;
  913. }
  914. i++;
  915. }
  916. if (morefiles < 0) {
  917. MENUITEMINFO mii = { 0 };
  918. mii.cbSize = sizeof mii;
  919. mii.fMask = MIIM_STRING | MIIM_ID;
  920. mii.fType = MFT_STRING;
  921. mii.fState = MFS_ENABLED;
  922. mii.wID = 999;
  923. mii.dwTypeData = _T("[Directory scan]");
  924. mii.cch = _tcslen (mii.dwTypeData);
  925. InsertMenuItem (menu, -1, TRUE, &mii);
  926. got = 1;
  927. }
  928. if (got) {
  929. MENUITEMINFO mii = { 0 };
  930. mii.cbSize = sizeof mii;
  931. mii.fMask = MIIM_FTYPE;
  932. mii.fType = MFT_SEPARATOR;
  933. mii.fState = MFS_ENABLED;
  934. InsertMenuItem (menu, -1, TRUE, &mii);
  935. }
  936. i = 0;
  937. while (items[i].type) {
  938. if (items[i].type == 1) {
  939. MENUITEMINFO mii = { 0 };
  940. mii.cbSize = sizeof mii;
  941. mii.fMask = MIIM_STRING | MIIM_ID;
  942. mii.fType = MFT_STRING;
  943. mii.fState = MFS_ENABLED;
  944. mii.wID = 1 + i;
  945. mii.dwTypeData = items[i].value;
  946. mii.cch = _tcslen (mii.dwTypeData);
  947. InsertMenuItem (menu, -1, TRUE, &mii);
  948. }
  949. i++;
  950. }
  951. addeditmenu (menu, items);
  952. GetCursorPos (&pt);
  953. item = TrackPopupMenu (menu, TPM_LEFTALIGN | TPM_LEFTBUTTON | TPM_RIGHTBUTTON | TPM_RETURNCMD,
  954. pt.x, pt.y, 0, hwnd, NULL);
  955. PostMessage (hwnd, WM_NULL, 0, 0);
  956. DestroyMenu (menu);
  957. return item;
  958. }
  959. static void favitemsort (struct favitems *fitem, int start, int end)
  960. {
  961. for (int i = start; i < end; i++) {
  962. for (int j = i + 1; j < end; j++) {
  963. if (_tcscmp (fitem[i].value, fitem[j].value) > 0) {
  964. struct favitems tmp;
  965. memcpy (&tmp, &fitem[i], sizeof tmp);
  966. memcpy (&fitem[i], &fitem[j], sizeof tmp);
  967. memcpy (&fitem[j], &tmp, sizeof tmp);
  968. }
  969. }
  970. }
  971. }
  972. static int getdeepfavdiskimage (TCHAR *imgpath, struct favitems *fitem, int idx)
  973. {
  974. TCHAR path[MAX_DPATH], mask[MAX_DPATH];
  975. TCHAR *p;
  976. struct my_opendir_s *myd = NULL;
  977. int previdx = idx;
  978. if (!imgpath[0])
  979. return idx;
  980. _tcscpy (path, imgpath);
  981. mask[0] = 0;
  982. for (;;) {
  983. p = _tcsrchr (path, '\\');
  984. if (!p)
  985. p = _tcsrchr (path, '/');
  986. if (!p)
  987. break;
  988. if (!mask[0])
  989. _tcscpy (mask, p + 1);
  990. p[0] = 0;
  991. if (my_existsdir (path))
  992. break;
  993. }
  994. static TCHAR notallowed[] = _T("[]()_-#!{}=.,");
  995. for (int i = 0; i < _tcslen (notallowed); i++) {
  996. for (;;) {
  997. p = _tcsrchr (mask, notallowed[i]);
  998. if (!p)
  999. break;
  1000. if (p - mask < 6)
  1001. break;
  1002. p[0] = 0;
  1003. }
  1004. }
  1005. while (mask[_tcslen (mask) - 1] == ' ')
  1006. mask[_tcslen (mask) - 1] = 0;
  1007. _tcscat (mask, _T("*.*"));
  1008. myd = my_opendir (path, mask);
  1009. int cnt = 0;
  1010. while (myd && cnt < 30) {
  1011. TCHAR tmp[MAX_DPATH], tmp2[MAX_DPATH];
  1012. if (!my_readdir (myd, tmp))
  1013. break;
  1014. _tcscpy (tmp2, path);
  1015. _tcscat (tmp2, _T("\\"));
  1016. _tcscat (tmp2, tmp);
  1017. fitem[idx].value = my_strdup (tmp2);
  1018. fitem[idx].path = NULL;
  1019. fitem[idx].type = 2;
  1020. idx++;
  1021. cnt++;
  1022. }
  1023. my_closedir (myd);
  1024. favitemsort (fitem, previdx, idx);
  1025. fitem[idx].type = 0;
  1026. return idx;
  1027. }
  1028. static int getfavdiskimage (TCHAR *imgpath, struct favitems *fitem, int idx)
  1029. {
  1030. int i;
  1031. TCHAR name[MAX_DPATH];
  1032. _tcscpy (name, imgpath);
  1033. int previdx = idx;
  1034. for (;;) {
  1035. if (!disk_prevnext_name (name, 1))
  1036. break;
  1037. for (i = previdx; i < idx; i++) {
  1038. if (!_tcsicmp (fitem[i].value, name))
  1039. break;
  1040. }
  1041. if (i < idx)
  1042. break;
  1043. fitem[idx].value = my_strdup (name);
  1044. fitem[idx].path = NULL;
  1045. fitem[idx].type = 2;
  1046. idx++;
  1047. if (!_tcscmp (name, imgpath))
  1048. break;
  1049. }
  1050. favitemsort (fitem, previdx, idx);
  1051. fitem[idx].type = 0;
  1052. return idx;
  1053. }
  1054. static TCHAR *favoritepopup (HWND hwnd, int drive)
  1055. {
  1056. UAEREG *fkey;
  1057. int idx, idx2;
  1058. struct favitems fitem[MAXFAVORITESPACE + 1];
  1059. int ret, i, num;
  1060. int srcdrive, dstdrive;
  1061. int morefiles = 0;
  1062. srcdrive = dstdrive = drive;
  1063. for (;;) {
  1064. fkey = regcreatetree (NULL, _T("FavoritePaths"));
  1065. if (fkey == NULL)
  1066. return NULL;
  1067. idx = 0;
  1068. num = 0;
  1069. for (;;) {
  1070. TCHAR *p;
  1071. int size, size2;
  1072. TCHAR tmp[1000], tmp2[1000];
  1073. size = sizeof (tmp) / sizeof (TCHAR);
  1074. size2 = sizeof (tmp2) / sizeof (TCHAR);
  1075. if (!regenumstr (fkey, idx, tmp, &size, tmp2, &size2))
  1076. break;
  1077. p = _tcsrchr (tmp, '_');
  1078. if (p) {
  1079. idx2 = _tstol (p + 1);
  1080. if (idx2 > 0 && idx2 < MAXFAVORITES) {
  1081. TCHAR *p2 = _tcschr (tmp2, '"');
  1082. TCHAR *str, *fname;
  1083. idx2--;
  1084. if (p2) {
  1085. fname = my_strdup (p2 + 1);
  1086. do {
  1087. *p2-- = 0;
  1088. } while (p2 > tmp2 && *p2 == ' ');
  1089. p2 = _tcschr (fname, '"');
  1090. if (p2)
  1091. *p2 = 0;
  1092. str = my_strdup (tmp2);
  1093. } else {
  1094. str = my_strdup (tmp2);
  1095. fname = my_strdup (tmp2);
  1096. }
  1097. fitem[idx2].path = fname;
  1098. fitem[idx2].value = str;
  1099. fitem[idx2].type = 1;
  1100. }
  1101. }
  1102. idx++;
  1103. }
  1104. regclosetree (fkey);
  1105. favitemsort (fitem, 0, idx);
  1106. fitem[idx].type = 0;
  1107. if (srcdrive >= 0 && srcdrive <= 4) {
  1108. if (!morefiles) {
  1109. for (i = 0; i < 4; i++) {
  1110. if (workprefs.floppyslots[i].df[0] && srcdrive != i) {
  1111. TCHAR tmp[100];
  1112. _stprintf (tmp, _T("[DF%c:]"), i + '0');
  1113. fitem[idx].value = my_strdup (tmp);
  1114. fitem[idx].path = my_strdup (workprefs.floppyslots[i].df);
  1115. fitem[idx].type = 3 + i;
  1116. idx++;
  1117. fitem[idx].type = 0;
  1118. }
  1119. }
  1120. }
  1121. if (workprefs.floppyslots[srcdrive].df[0]) {
  1122. if (morefiles > 0) {
  1123. idx = getdeepfavdiskimage (workprefs.floppyslots[srcdrive].df, fitem, idx);
  1124. } else {
  1125. idx = getfavdiskimage (workprefs.floppyslots[srcdrive].df, fitem, idx);
  1126. morefiles = -1;
  1127. }
  1128. }
  1129. }
  1130. ret = popupmenu (hwnd, fitem, morefiles);
  1131. if (ret == 0)
  1132. break;
  1133. if (ret <= idx) {
  1134. if (fitem[ret - 1].type == 2) {
  1135. _tcscpy (workprefs.floppyslots[dstdrive].df, fitem[ret - 1].value);
  1136. disk_insert (dstdrive, workprefs.floppyslots[dstdrive].df);
  1137. ret = 0;
  1138. }
  1139. break;
  1140. }
  1141. if (ret >= 990 && ret <= 993) {
  1142. srcdrive = ret - 990;
  1143. } else if (ret == 999) {
  1144. morefiles = 1;
  1145. } else if (ret == 1000) {
  1146. if (!addfavoritepath (hwnd, idx, fitem)) {
  1147. ret = 0;
  1148. break;
  1149. }
  1150. } else if (ret > 1000) {
  1151. removefavoritepath (ret - 1001, idx, fitem);
  1152. }
  1153. }
  1154. for (i = 0; i < idx; i++) {
  1155. xfree (fitem[i].value);
  1156. if (i != ret - 1)
  1157. xfree (fitem[i].path);
  1158. }
  1159. if (ret == 0)
  1160. return NULL;
  1161. return fitem[ret - 1].path;
  1162. }
  1163. static TCHAR *favoritepopup (HWND hwnd)
  1164. {
  1165. return favoritepopup (hwnd, -1);
  1166. }
  1167. /* base Drag'n'Drop code borrowed from http://www.codeproject.com/listctrl/jianghong.asp */
  1168. // NOTE (TW):
  1169. // ListView_CreateDragImage has been broken at least since Windows Vista?
  1170. static int bDragging = 0;
  1171. static HIMAGELIST hDragImageList;
  1172. static int DragHeight;
  1173. static int drag_start (HWND hWnd, HWND hListView, LPARAM lParam)
  1174. {
  1175. POINT pt;
  1176. int bFirst, iPos;
  1177. POINT offset;
  1178. offset.x = 0;
  1179. offset.y = 0;
  1180. pt = ((NM_LISTVIEW*)((LPNMHDR)lParam))->ptAction;
  1181. ClientToScreen(hListView, &pt);
  1182. // Ok, now we create a drag-image for all selected items
  1183. bFirst = TRUE;
  1184. iPos = ListView_GetNextItem(hListView, -1, LVNI_SELECTED);
  1185. while (iPos != -1) {
  1186. if (bFirst) {
  1187. int width, height;
  1188. RECT rc2;
  1189. GetClientRect(hListView, &rc2);
  1190. if (!os_vista) {
  1191. IMAGEINFO imf;
  1192. POINT p;
  1193. // For the first selected item,
  1194. // we simply create a single-line drag image
  1195. hDragImageList = ListView_CreateDragImage(hListView, iPos, &p);
  1196. ImageList_GetImageInfo(hDragImageList, 0, &imf);
  1197. width = imf.rcImage.right;
  1198. height = imf.rcImage.bottom;
  1199. } else {
  1200. // ListView_CreateDragImage replacement hack follows..
  1201. RECT rc;
  1202. // Get Rectangle of selected ListView Item
  1203. ListView_GetItemRect(hListView, iPos, &rc, LVIR_BOUNDS);
  1204. if (rc.left < 0)
  1205. rc.left = 0;
  1206. if (rc.bottom < 0)
  1207. rc.bottom = 0;
  1208. width = rc.right - rc.left;
  1209. height = rc.bottom - rc.top;
  1210. if (width <= 0 || height <= 0)
  1211. return 0;
  1212. // Image becomes blank bar if visible part
  1213. // is smaller than complete width of item.
  1214. if (width > rc2.right - rc2.left)
  1215. width = rc2.right - rc2.left;
  1216. if (height > rc2.bottom - rc2.top)
  1217. height = rc2.bottom - rc2.top;
  1218. // Create HBITMAP of selected ListView Item
  1219. HDC hDC = GetDC(hListView);
  1220. if (hDC) {
  1221. HDC hMemDC = CreateCompatibleDC(hDC);
  1222. if (hMemDC) {
  1223. HBITMAP hBMP = CreateCompatibleBitmap(hDC, width, height);
  1224. if (hBMP) {
  1225. HGDIOBJ o = SelectObject(hMemDC, hBMP);
  1226. BitBlt(hMemDC, 0, 0, width, height, hDC, rc.left, rc.top, SRCCOPY);
  1227. SelectObject(hMemDC, o);
  1228. }
  1229. // Create ImageList, add HBITMAP to ImageList.
  1230. hDragImageList = ImageList_Create(width, height, ILC_COLOR24, 1, 1);
  1231. if (hBMP && hDragImageList) {
  1232. ImageList_Add(hDragImageList, hBMP, NULL);
  1233. DeleteObject(hBMP);
  1234. }
  1235. DeleteDC(hMemDC);
  1236. }
  1237. ReleaseDC(hListView, hDC);
  1238. }
  1239. }
  1240. offset.x = rc2.left;
  1241. offset.y = rc2.top;
  1242. ClientToScreen(hListView, &offset);
  1243. offset.x = pt.x - offset.x;
  1244. offset.y = height;
  1245. DragHeight = height;
  1246. bFirst = FALSE;
  1247. } else {
  1248. #if 0
  1249. IMAGEINFO imf;
  1250. HIMAGELIST hOneImageList, hTempImageList;
  1251. // For the rest selected items,
  1252. // we create a single-line drag image, then
  1253. // append it to the bottom of the complete drag image
  1254. hOneImageList = ListView_CreateDragImage(hListView, iPos, &p);
  1255. hTempImageList = ImageList_Merge(hDragImageList, 0, hOneImageList, 0, 0, iHeight);
  1256. ImageList_Destroy(hDragImageList);
  1257. ImageList_Destroy(hOneImageList);
  1258. hDragImageList = hTempImageList;
  1259. ImageList_GetImageInfo(hDragImageList, 0, &imf);
  1260. iHeight = imf.rcImage.bottom;
  1261. #endif
  1262. }
  1263. iPos = ListView_GetNextItem(hListView, iPos, LVNI_SELECTED);
  1264. }
  1265. if (!hDragImageList)
  1266. return 0;
  1267. // Now we can initialize then start the drag action
  1268. ImageList_BeginDrag(hDragImageList, 0, offset.x, offset.y);
  1269. ImageList_DragEnter(NULL, pt.x, pt.y);
  1270. bDragging = TRUE;
  1271. // Don't forget to capture the mouse
  1272. SetCapture (hWnd);
  1273. return 1;
  1274. }
  1275. static int drag_end (HWND hWnd, HWND hListView, LPARAM lParam, int **draggeditems)
  1276. {
  1277. int iPos, cnt;
  1278. LVHITTESTINFO lvhti;
  1279. LVITEM lvi;
  1280. *draggeditems = NULL;
  1281. if (!bDragging)
  1282. return -1;
  1283. // End the drag-and-drop process
  1284. bDragging = FALSE;
  1285. ImageList_DragLeave(hListView);
  1286. ImageList_EndDrag();
  1287. ImageList_Destroy(hDragImageList);
  1288. ReleaseCapture();
  1289. // Determine the dropped item
  1290. lvhti.pt.x = LOWORD(lParam);
  1291. lvhti.pt.y = HIWORD(lParam);
  1292. lvhti.pt.y -= DragHeight / 2;
  1293. ClientToScreen(hWnd, &lvhti.pt);
  1294. ScreenToClient(hListView, &lvhti.pt);
  1295. ListView_HitTest(hListView, &lvhti);
  1296. // Out of the ListView?
  1297. if (lvhti.iItem == -1)
  1298. return -1;
  1299. // Not in an item?
  1300. if ((lvhti.flags & LVHT_ONITEMLABEL) == 0 && (lvhti.flags & LVHT_ONITEMSTATEICON) == 0)
  1301. return -1;
  1302. // Dropped item is selected?
  1303. lvi.iItem = lvhti.iItem;
  1304. lvi.iSubItem = 0;
  1305. lvi.mask = LVIF_STATE;
  1306. lvi.stateMask = LVIS_SELECTED;
  1307. ListView_GetItem(hListView, &lvi);
  1308. if (lvi.state & LVIS_SELECTED)
  1309. return -1;
  1310. // Rearrange the items
  1311. iPos = ListView_GetNextItem(hListView, -1, LVNI_SELECTED);
  1312. cnt = 0;
  1313. while (iPos != -1) {
  1314. iPos = ListView_GetNextItem(hListView, iPos, LVNI_SELECTED);
  1315. cnt++;
  1316. }
  1317. if (cnt == 0)
  1318. return -1;
  1319. *draggeditems = xmalloc (int, cnt + 1);
  1320. iPos = ListView_GetNextItem(hListView, -1, LVNI_SELECTED);
  1321. cnt = 0;
  1322. while (iPos != -1) {
  1323. (*draggeditems)[cnt++] = iPos;
  1324. iPos = ListView_GetNextItem(hListView, iPos, LVNI_SELECTED);
  1325. }
  1326. (*draggeditems)[cnt] = -1;
  1327. return lvhti.iItem;
  1328. }
  1329. static int drag_move (HWND hWnd, LPARAM lParam)
  1330. {
  1331. POINT p;
  1332. if (!bDragging)
  1333. return 0;
  1334. p.x = LOWORD(lParam);
  1335. p.y = HIWORD(lParam);
  1336. ClientToScreen(hWnd, &p);
  1337. ImageList_DragMove(p.x, p.y);
  1338. return 1;
  1339. }
  1340. static HWND cachedlist = NULL;
  1341. static const TCHAR *memsize_names[] = {
  1342. /* 0 */ _T("none"),
  1343. /* 1 */ _T("64 KB"),
  1344. /* 2 */ _T("128 KB"),
  1345. /* 3 */ _T("256 KB"),
  1346. /* 4 */ _T("512 KB"),
  1347. /* 5 */ _T("1 MB"),
  1348. /* 6 */ _T("2 MB"),
  1349. /* 7 */ _T("4 MB"),
  1350. /* 8 */ _T("8 MB"),
  1351. /* 9 */ _T("16 MB"),
  1352. /* 10*/ _T("32 MB"),
  1353. /* 11*/ _T("64 MB"),
  1354. /* 12*/ _T("128 MB"),
  1355. /* 13*/ _T("256 MB"),
  1356. /* 14*/ _T("512 MB"),
  1357. /* 15*/ _T("1 GB"),
  1358. /* 16*/ _T("1.5MB"),
  1359. /* 17*/ _T("1.8MB"),
  1360. /* 18*/ _T("2 GB"),
  1361. /* 19*/ _T("384 MB"),
  1362. /* 20*/ _T("768 MB"),
  1363. /* 21*/ _T("1.5 GB"),
  1364. /* 22*/ _T("2.5 GB"),
  1365. /* 23*/ _T("3 GB")
  1366. };
  1367. static const unsigned long memsizes[] = {
  1368. /* 0 */ 0,
  1369. /* 1 */ 0x00010000, /* 64K */
  1370. /* 2 */ 0x00020000, /* 128K */
  1371. /* 3 */ 0x00040000, /* 256K */
  1372. /* 4 */ 0x00080000, /* 512K */
  1373. /* 5 */ 0x00100000, /* 1M */
  1374. /* 6 */ 0x00200000, /* 2M */
  1375. /* 7 */ 0x00400000, /* 4M */
  1376. /* 8 */ 0x00800000, /* 8M */
  1377. /* 9 */ 0x01000000, /* 16M */
  1378. /* 10*/ 0x02000000, /* 32M */
  1379. /* 11*/ 0x04000000, /* 64M */
  1380. /* 12*/ 0x08000000, //128M
  1381. /* 13*/ 0x10000000, //256M
  1382. /* 14*/ 0x20000000, //512M
  1383. /* 15*/ 0x40000000, //1GB
  1384. /* 16*/ 0x00180000, //1.5MB
  1385. /* 17*/ 0x001C0000, //1.8MB
  1386. /* 18*/ 0x80000000, //2GB
  1387. /* 19*/ 0x18000000, //384M
  1388. /* 20*/ 0x30000000, //768M
  1389. /* 21*/ 0x60000000, //1.5GB
  1390. /* 22*/ 0xA8000000, //2.5GB
  1391. /* 23*/ 0xC0000000, //3GB
  1392. };
  1393. static const int msi_chip[] = { 3, 4, 5, 16, 6, 7, 8 };
  1394. static const int msi_bogo[] = { 0, 4, 5, 16, 17 };
  1395. static const int msi_fast[] = { 0, 1, 2, 3, 4, 5, 6, 7, 8 };
  1396. static const int msi_z3fast[] = { 0, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 };
  1397. static const int msi_z3chip[] = { 0, 9, 10, 11, 12, 13, 19, 14, 20, 15 };
  1398. static const int msi_gfx[] = { 0, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 };
  1399. static const int msi_cpuboard[] = { 0, 5, 6, 7, 8, 9, 10, 11, 12, 13 };
  1400. static const int msi_mb[] = { 0, 5, 6, 7, 8, 9, 10, 11, 12 };
  1401. #define MIN_CHIP_MEM 0
  1402. #define MAX_CHIP_MEM 6
  1403. #define MIN_FAST_MEM 0
  1404. #define MAX_FAST_MEM 8
  1405. #define MIN_SLOW_MEM 0
  1406. #define MAX_SLOW_MEM 4
  1407. #define MIN_Z3_MEM 0
  1408. #define MAX_Z3_MEM 11
  1409. #define MAX_Z3_CHIPMEM 9
  1410. #define MIN_P96_MEM 0
  1411. #define MAX_P96_MEM_Z3 ((max_z3fastmem >> 20) < 512 ? 8 : ((max_z3fastmem >> 20) < 1024 ? 9 : ((max_z3fastmem >> 20) < 2048) ? 10 : 11))
  1412. #define MAX_P96_MEM_Z2 4
  1413. #define MIN_MB_MEM 0
  1414. #define MAX_MBL_MEM 7
  1415. #define MAX_MBH_MEM 8
  1416. #define MIN_CB_MEM 0
  1417. #define MAX_CB_MEM_Z2 4
  1418. #define MAX_CB_MEM_16M 5
  1419. #define MAX_CB_MEM_32M 6
  1420. #define MAX_CB_MEM_64M 7
  1421. #define MAX_CB_MEM_128M 8
  1422. #define MAX_CB_MEM_256M 9
  1423. #define MIN_M68K_PRIORITY 1
  1424. #define MAX_M68K_PRIORITY 16
  1425. #define MIN_CACHE_SIZE 0
  1426. #define MAX_CACHE_SIZE 5
  1427. #define MIN_REFRESH_RATE 1
  1428. #define MAX_REFRESH_RATE 10
  1429. #define MIN_SOUND_MEM 0
  1430. #define MAX_SOUND_MEM 10
  1431. struct romscandata {
  1432. UAEREG *fkey;
  1433. int got;
  1434. };
  1435. static struct romdata *scan_single_rom_2 (struct zfile *f)
  1436. {
  1437. uae_u8 buffer[20] = { 0 };
  1438. uae_u8 *rombuf;
  1439. int cl = 0, size;
  1440. struct romdata *rd = 0;
  1441. zfile_fseek (f, 0, SEEK_END);
  1442. size = zfile_ftell (f);
  1443. zfile_fseek (f, 0, SEEK_SET);
  1444. if (size > 524288 * 2) {/* don't skip KICK disks or 1M ROMs */
  1445. write_log (_T("'%s': too big %d, ignored\n"), zfile_getname(f), size);
  1446. return 0;
  1447. }
  1448. zfile_fread (buffer, 1, 11, f);
  1449. if (!memcmp (buffer, "KICK", 4)) {
  1450. zfile_fseek (f, 512, SEEK_SET);
  1451. if (size > 262144)
  1452. size = 262144;
  1453. } else if (!memcmp (buffer, "AMIROMTYPE1", 11)) {
  1454. cl = 1;
  1455. size -= 11;
  1456. } else {
  1457. zfile_fseek (f, 0, SEEK_SET);
  1458. }
  1459. rombuf = xcalloc (uae_u8, size);
  1460. if (!rombuf)
  1461. return 0;
  1462. zfile_fread (rombuf, 1, size, f);
  1463. if (cl > 0) {
  1464. decode_cloanto_rom_do (rombuf, size, size);
  1465. cl = 0;
  1466. }
  1467. if (!cl) {
  1468. rd = getromdatabydata (rombuf, size);
  1469. if (!rd && (size & 65535) == 0) {
  1470. /* check byteswap */
  1471. int i;
  1472. for (i = 0; i < size; i+=2) {
  1473. uae_u8 b = rombuf[i];
  1474. rombuf[i] = rombuf[i + 1];
  1475. rombuf[i + 1] = b;
  1476. }
  1477. rd = getromdatabydata (rombuf, size);
  1478. }
  1479. }
  1480. if (!rd) {
  1481. const TCHAR *name = my_getfilepart(zfile_getname(f));
  1482. rd = getfrombydefaultname(name, size);
  1483. }
  1484. if (!rd) {
  1485. write_log (_T("!: Name='%s':%d\nCRC32=%08X SHA1=%s\n"),
  1486. zfile_getname (f), size, get_crc32 (rombuf, size), get_sha1_txt (rombuf, size));
  1487. } else {
  1488. TCHAR tmp[MAX_DPATH];
  1489. getromname (rd, tmp);
  1490. write_log (_T("*: %s:%d = %s\nCRC32=%08X SHA1=%s\n"),
  1491. zfile_getname (f), size, tmp, get_crc32 (rombuf, size), get_sha1_txt (rombuf, size));
  1492. }
  1493. xfree (rombuf);
  1494. return rd;
  1495. }
  1496. static struct romdata *scan_single_rom (const TCHAR *path)
  1497. {
  1498. struct zfile *z;
  1499. TCHAR tmp[MAX_DPATH];
  1500. struct romdata *rd;
  1501. _tcscpy (tmp, path);
  1502. rd = scan_arcadia_rom (tmp, 0);
  1503. if (rd)
  1504. return rd;
  1505. rd = getromdatabypath (path);
  1506. if (rd && rd->crc32 == 0xffffffff)
  1507. return rd;
  1508. z = zfile_fopen (path, _T("rb"), ZFD_NORMAL);
  1509. if (!z)
  1510. return 0;
  1511. return scan_single_rom_2 (z);
  1512. }
  1513. static void abspathtorelative (TCHAR *name)
  1514. {
  1515. if (!_tcsncmp (start_path_exe, name, _tcslen (start_path_exe)))
  1516. memmove (name, name + _tcslen (start_path_exe), (_tcslen (name) - _tcslen (start_path_exe) + 1) * sizeof (TCHAR));
  1517. }
  1518. static int extpri(const TCHAR *p, int size)
  1519. {
  1520. const TCHAR *s = _tcsrchr(p, '.');
  1521. if (s == NULL)
  1522. return 80;
  1523. // if archive: lowest priority
  1524. if (!my_existsfile(p))
  1525. return 100;
  1526. int pri = 10;
  1527. // prefer matching size
  1528. struct mystat ms;
  1529. if (my_stat(p, &ms)) {
  1530. if (ms.size == size) {
  1531. pri--;
  1532. }
  1533. }
  1534. return pri;
  1535. }
  1536. static int addrom (UAEREG *fkey, struct romdata *rd, const TCHAR *name)
  1537. {
  1538. TCHAR tmp1[MAX_DPATH], tmp2[MAX_DPATH], tmp3[MAX_DPATH];
  1539. TCHAR pathname[MAX_DPATH];
  1540. _stprintf (tmp1, _T("ROM_%03d"), rd->id);
  1541. if (rd->group) {
  1542. TCHAR *p = tmp1 + _tcslen (tmp1);
  1543. _stprintf (p, _T("_%02d_%02d"), rd->group >> 16, rd->group & 65535);
  1544. }
  1545. getromname (rd, tmp2);
  1546. pathname[0] = 0;
  1547. if (name) {
  1548. _tcscpy (pathname, name);
  1549. if (getregmode ())
  1550. abspathtorelative (pathname);
  1551. }
  1552. if (rd->crc32 == 0xffffffff) {
  1553. if (rd->configname)
  1554. _stprintf (tmp2, _T(":%s"), rd->configname);
  1555. else
  1556. _stprintf (tmp2, _T(":ROM_%03d"), rd->id);
  1557. }
  1558. int size = sizeof tmp3 / sizeof(TCHAR);
  1559. if (regquerystr(fkey, tmp1, tmp3, &size)) {
  1560. TCHAR *s = _tcschr(tmp3, '\"');
  1561. if (s && _tcslen(s) > 1) {
  1562. TCHAR *s2 = s + 1;
  1563. s = _tcschr(s2, '\"');
  1564. if (s)
  1565. *s = 0;
  1566. int pri1 = extpri(s2, rd->size);
  1567. int pri2 = extpri(pathname, rd->size);
  1568. if (pri2 >= pri1)
  1569. return 1;
  1570. }
  1571. }
  1572. if (pathname[0]) {
  1573. _tcscat(tmp2, _T(" / \""));
  1574. _tcscat(tmp2, pathname);
  1575. _tcscat(tmp2, _T("\""));
  1576. }
  1577. if (!regsetstr (fkey, tmp1, tmp2))
  1578. return 0;
  1579. return 1;
  1580. }
  1581. static int isromext (const TCHAR *path, bool deepscan)
  1582. {
  1583. const TCHAR *ext;
  1584. int i;
  1585. if (!path)
  1586. return 0;
  1587. ext = _tcsrchr (path, '.');
  1588. if (!ext)
  1589. return 0;
  1590. ext++;
  1591. if (!_tcsicmp (ext, _T("rom")) || !_tcsicmp (ext, _T("bin")) || !_tcsicmp (ext, _T("adf")) || !_tcsicmp (ext, _T("key"))
  1592. || !_tcsicmp (ext, _T("a500")) || !_tcsicmp (ext, _T("a1200")) || !_tcsicmp (ext, _T("a4000")) || !_tcsicmp (ext, _T("cd32")))
  1593. return 1;
  1594. if (_tcslen (ext) >= 2 && toupper(ext[0]) == 'U' && isdigit (ext[1]))
  1595. return 1;
  1596. if (!deepscan)
  1597. return 0;
  1598. for (i = 0; uae_archive_extensions[i]; i++) {
  1599. if (!_tcsicmp (ext, uae_archive_extensions[i]))
  1600. return 1;
  1601. }
  1602. return 0;
  1603. }
  1604. static bool infoboxdialogstate;
  1605. static HWND infoboxhwnd;
  1606. static INT_PTR CALLBACK InfoBoxDialogProc (HWND hDlg, UINT msg, WPARAM wParam, LPARAM lParam)
  1607. {
  1608. if (dialog_inhibit)
  1609. return 0;
  1610. switch(msg)
  1611. {
  1612. case WM_DESTROY:
  1613. PostQuitMessage (0);
  1614. infoboxdialogstate = false;
  1615. return TRUE;
  1616. case WM_CLOSE:
  1617. DestroyWindow (hDlg);
  1618. infoboxdialogstate = false;
  1619. return TRUE;
  1620. case WM_INITDIALOG:
  1621. {
  1622. HWND owner = GetParent (hDlg);
  1623. if (!owner) {
  1624. owner = GetDesktopWindow ();
  1625. RECT ownerrc, merc;
  1626. GetWindowRect (owner, &ownerrc);
  1627. GetWindowRect (hDlg, &merc);
  1628. SetWindowPos (hDlg, NULL,
  1629. ownerrc.left + ((ownerrc.right - ownerrc.left) - (merc.right - merc.left)) /2,
  1630. ownerrc.top + ((ownerrc.bottom - ownerrc.top) - (merc.bottom - merc.top)) / 2,
  1631. 0, 0,
  1632. SWP_NOSIZE);
  1633. }
  1634. return TRUE;
  1635. }
  1636. case WM_COMMAND:
  1637. switch (LOWORD (wParam))
  1638. {
  1639. case IDCANCEL:
  1640. infoboxdialogstate = false;
  1641. DestroyWindow (hDlg);
  1642. return TRUE;
  1643. }
  1644. break;
  1645. }
  1646. commonproc(hDlg, msg, wParam, lParam);
  1647. return FALSE;
  1648. }
  1649. static bool scan_rom_hook (const TCHAR *name, int line)
  1650. {
  1651. MSG msg;
  1652. if (!infoboxhwnd)
  1653. return true;
  1654. if (name != NULL) {
  1655. const TCHAR *s = NULL;
  1656. if (line == 2) {
  1657. s = _tcsrchr (name, '/');
  1658. if (!s)
  1659. s = _tcsrchr (name, '\\');
  1660. if (s)
  1661. s++;
  1662. }
  1663. SetWindowText (GetDlgItem (infoboxhwnd, line == 1 ? IDC_INFOBOX_TEXT1 : (line == 2 ? IDC_INFOBOX_TEXT2 : IDC_INFOBOX_TEXT3)), s ? s : name);
  1664. }
  1665. while (PeekMessage (&msg, infoboxhwnd, 0, 0, PM_REMOVE)) {
  1666. if (!IsDialogMessage (infoboxhwnd, &msg)) {
  1667. TranslateMessage (&msg);
  1668. DispatchMessage (&msg);
  1669. }
  1670. }
  1671. return infoboxdialogstate;
  1672. }
  1673. static int scan_rom_2 (struct zfile *f, void *vrsd)
  1674. {
  1675. struct romscandata *rsd = (struct romscandata*)vrsd;
  1676. const TCHAR *path = zfile_getname(f);
  1677. const TCHAR *romkey = _T("rom.key");
  1678. struct romdata *rd;
  1679. scan_rom_hook (NULL, 0);
  1680. if (!isromext (path, true))
  1681. return 0;
  1682. rd = scan_single_rom_2 (f);
  1683. if (rd) {
  1684. TCHAR name[MAX_DPATH];
  1685. getromname (rd, name);
  1686. scan_rom_hook (name, 3);
  1687. addrom (rsd->fkey, rd, path);
  1688. if (rd->type & ROMTYPE_KEY)
  1689. addkeyfile (path);
  1690. rsd->got = 1;
  1691. } else if (_tcslen (path) > _tcslen (romkey) && !_tcsicmp (path + _tcslen (path) - _tcslen (romkey), romkey)) {
  1692. addkeyfile (path);
  1693. }
  1694. return 0;
  1695. }
  1696. static int scan_rom (const TCHAR *path, UAEREG *fkey, bool deepscan)
  1697. {
  1698. struct romscandata rsd = { fkey, 0 };
  1699. struct romdata *rd;
  1700. int cnt = 0;
  1701. if (!isromext (path, deepscan)) {
  1702. //write_log("ROMSCAN: skipping file '%s', unknown extension\n", path);
  1703. return 0;
  1704. }
  1705. scan_rom_hook (path, 2);
  1706. for (;;) {
  1707. TCHAR tmp[MAX_DPATH];
  1708. _tcscpy (tmp, path);
  1709. rd = scan_arcadia_rom (tmp, cnt++);
  1710. if (rd) {
  1711. if (!addrom (fkey, rd, tmp))
  1712. return 1;
  1713. continue;
  1714. }
  1715. break;
  1716. }
  1717. zfile_zopen (path, scan_rom_2, (void*)&rsd);
  1718. return rsd.got;
  1719. }
  1720. static int listrom (const int *roms)
  1721. {
  1722. int i;
  1723. i = 0;
  1724. while (roms[i] >= 0) {
  1725. struct romdata *rd = getromdatabyid (roms[i]);
  1726. if (rd && romlist_get (rd))
  1727. return 1;
  1728. i++;
  1729. }
  1730. return 0;
  1731. }
  1732. static void show_rom_list (void)
  1733. {
  1734. TCHAR *p;
  1735. TCHAR *p1, *p2;
  1736. const int *rp;
  1737. bool first = true;
  1738. const int romtable[] = {
  1739. 5, 4, -1, -1, // A500 1.2
  1740. 6, 32, -1, -1, // A500 1.3
  1741. 7, -1, -1, // A500+
  1742. 8, 9, 10, -1, -1, // A600
  1743. 23, 24, -1, -1, // A1000
  1744. 11, 31, 15, -1, -1, // A1200
  1745. 59, 71, 61, -1, -1, // A3000
  1746. 16, 46, 31, 13, 12, -1, -1, // A4000
  1747. 17, -1, -1, // A4000T
  1748. 18, -1, 19, -1, -1, // CD32
  1749. 20, 21, 22, -1, 6, 32, -1, -1, // CDTV
  1750. 9, 10, -1, 107, 108, -1, -1, // CDTV-CR
  1751. 49, 50, 75, 51, 76, 77, -1, 5, 4, -1, -2, // ARCADIA
  1752. 18, -1, 19, -1, 74, 23, -1, -1, // CD32 FMV
  1753. 69, 67, 70, 115, -1, -1, // nordic power
  1754. 65, 68, -1, -1, // x-power
  1755. 62, 60, -1, -1, // action cartridge
  1756. 116, -1, -1, // pro access
  1757. 52, 25, -1, -1, // ar 1
  1758. 26, 27, 28, -1, -1, // ar 2
  1759. 29, 30, -1, -1, // ar 3
  1760. 47, -1, -1, // action replay 1200
  1761. 0, 0, 0
  1762. };
  1763. p1 = _T("A500 Boot ROM 1.2\0A500 Boot ROM 1.3\0A500+\0A600\0A1000\0A1200\0A3000\0A4000\0A4000T\0")
  1764. _T("CD32\0CDTV\0CDTV-CR\0Arcadia Multi Select\0")
  1765. _T("CD32 Full Motion Video\0")
  1766. _T("Nordic Power\0X-Power Professional 500\0Action Cartridge Super IV Professional\0")
  1767. _T("Pro Access\0")
  1768. _T("Action Replay MK I\0Action Replay MK II\0Action Replay MK III\0")
  1769. _T("Action Replay 1200\0")
  1770. _T("\0");
  1771. p = xmalloc (TCHAR, 100000);
  1772. if (!p)
  1773. return;
  1774. WIN32GUI_LoadUIString (IDS_ROMSCANEND, p, 100);
  1775. _tcscat (p, _T("\n\n"));
  1776. rp = romtable;
  1777. while(rp[0]) {
  1778. int ok = 1;
  1779. p2 = p1 + _tcslen (p1) + 1;
  1780. while (*rp >= 0) {
  1781. if (ok) {
  1782. ok = 0;
  1783. if (listrom (rp))
  1784. ok = 1;
  1785. }
  1786. while(*rp++ >= 0);
  1787. }
  1788. if (ok) {
  1789. if (!first)
  1790. _tcscat (p, _T(", "));
  1791. first = false;
  1792. _tcscat (p, p1);
  1793. }
  1794. if (*rp == -2) {
  1795. _tcscat(p, _T("\n\n"));
  1796. first = true;
  1797. }
  1798. rp++;
  1799. p1 = p2;
  1800. }
  1801. pre_gui_message (p);
  1802. free (p);
  1803. }
  1804. static int scan_roms_2 (UAEREG *fkey, const TCHAR *path, bool deepscan, int level)
  1805. {
  1806. TCHAR buf[MAX_DPATH];
  1807. WIN32_FIND_DATA find_data;
  1808. HANDLE handle;
  1809. int ret;
  1810. if (!path)
  1811. return 0;
  1812. write_log (_T("ROM scan directory '%s'\n"), path);
  1813. _tcscpy (buf, path);
  1814. _tcscat (buf, _T("*.*"));
  1815. ret = 0;
  1816. handle = FindFirstFile (buf, &find_data);
  1817. if (handle == INVALID_HANDLE_VALUE)
  1818. return 0;
  1819. scan_rom_hook (path, 1);
  1820. for (;;) {
  1821. TCHAR tmppath[MAX_DPATH];
  1822. _tcscpy (tmppath, path);
  1823. _tcscat (tmppath, find_data.cFileName);
  1824. if (!(find_data.dwFileAttributes & (FILE_ATTRIBUTE_DIRECTORY |FILE_ATTRIBUTE_SYSTEM)) && find_data.nFileSizeLow < 10000000) {
  1825. if (scan_rom (tmppath, fkey, deepscan))
  1826. ret = 1;
  1827. } else if (deepscan && (find_data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)) {
  1828. if (recursiveromscan < 0 || recursiveromscan > level) {
  1829. if (find_data.cFileName[0] != '.') {
  1830. _tcscat(tmppath, _T("\\"));
  1831. scan_roms_2(fkey, tmppath, deepscan, level + 1);
  1832. }
  1833. }
  1834. }
  1835. if (!scan_rom_hook (NULL, 0) || FindNextFile (handle, &find_data) == 0) {
  1836. FindClose (handle);
  1837. break;
  1838. }
  1839. }
  1840. return ret;
  1841. }
  1842. #define MAX_ROM_PATHS 10
  1843. static int scan_roms_3 (UAEREG *fkey, TCHAR **paths, const TCHAR *path)
  1844. {
  1845. int i, ret;
  1846. TCHAR pathp[MAX_DPATH];
  1847. bool deepscan = true;
  1848. ret = 0;
  1849. scan_rom_hook (NULL, 0);
  1850. pathp[0] = 0;
  1851. GetFullPathName (path, MAX_DPATH, pathp, NULL);
  1852. if (!pathp[0])
  1853. return ret;
  1854. if (_tcsicmp (pathp, start_path_exe) == 0)
  1855. deepscan = false; // do not scan root dir archives
  1856. for (i = 0; i < MAX_ROM_PATHS; i++) {
  1857. if (paths[i] && !_tcsicmp (paths[i], pathp))
  1858. return ret;
  1859. }
  1860. ret = scan_roms_2 (fkey, pathp, deepscan, 0);
  1861. for (i = 0; i < MAX_ROM_PATHS; i++) {
  1862. if (!paths[i]) {
  1863. paths[i] = my_strdup(pathp);
  1864. break;
  1865. }
  1866. }
  1867. return ret;
  1868. }
  1869. extern int get_rom_path (TCHAR *out, pathtype mode);
  1870. int scan_roms (HWND hDlg, int show)
  1871. {
  1872. TCHAR path[MAX_DPATH];
  1873. static int recursive;
  1874. int id, i, ret, keys, cnt;
  1875. UAEREG *fkey, *fkey2;
  1876. TCHAR *paths[MAX_ROM_PATHS];
  1877. MSG msg;
  1878. if (recursive)
  1879. return 0;
  1880. recursive++;
  1881. ret = 0;
  1882. regdeletetree (NULL, _T("DetectedROMs"));
  1883. fkey = regcreatetree (NULL, _T("DetectedROMs"));
  1884. if (fkey == NULL)
  1885. goto end;
  1886. infoboxdialogstate = true;
  1887. infoboxhwnd = NULL;
  1888. if (!rp_isactive ()) {
  1889. HWND hwnd = CreateDialog (hUIDLL ? hUIDLL : hInst, MAKEINTRESOURCE (IDD_INFOBOX), hDlg, InfoBoxDialogProc);
  1890. if (!hwnd)
  1891. goto end;
  1892. infoboxhwnd = hwnd;
  1893. }
  1894. cnt = 0;
  1895. for (i = 0; i < MAX_ROM_PATHS; i++)
  1896. paths[i] = NULL;
  1897. scan_rom_hook (NULL, 0);
  1898. while (scan_rom_hook (NULL, 0)) {
  1899. keys = get_keyring ();
  1900. fetch_path (_T("KickstartPath"), path, sizeof path / sizeof (TCHAR));
  1901. cnt += scan_roms_3 (fkey, paths, path);
  1902. if (1) {
  1903. static pathtype pt[] = { PATH_TYPE_DEFAULT, PATH_TYPE_WINUAE, PATH_TYPE_NEWWINUAE, PATH_TYPE_NEWAF, PATH_TYPE_AMIGAFOREVERDATA, PATH_TYPE_END };
  1904. for (i = 0; pt[i] != PATH_TYPE_END; i++) {
  1905. ret = get_rom_path (path, pt[i]);
  1906. if (ret < 0)
  1907. break;
  1908. cnt += scan_roms_3 (fkey, paths, path);
  1909. }
  1910. if (get_keyring() > keys) { /* more keys detected in previous scan? */
  1911. write_log (_T("ROM scan: more keys found, restarting..\n"));
  1912. for (i = 0; i < MAX_ROM_PATHS; i++) {
  1913. xfree (paths[i]);
  1914. paths[i] = NULL;
  1915. }
  1916. continue;
  1917. }
  1918. }
  1919. break;
  1920. }
  1921. if (cnt == 0)
  1922. scan_roms_3 (fkey, paths, workprefs.path_rom.path[0]);
  1923. for (i = 0; i < MAX_ROM_PATHS; i++)
  1924. xfree (paths[i]);
  1925. fkey2 = regcreatetree (NULL, _T("DetectedROMS"));
  1926. if (fkey2) {
  1927. id = 1;
  1928. for (;;) {
  1929. struct romdata *rd = getromdatabyid (id);
  1930. if (!rd)
  1931. break;
  1932. if (rd->crc32 == 0xffffffff)
  1933. addrom (fkey, rd, NULL);
  1934. id++;
  1935. }
  1936. regclosetree (fkey2);
  1937. }
  1938. end:
  1939. if (infoboxhwnd) {
  1940. HWND hwnd = infoboxhwnd;
  1941. infoboxhwnd = NULL;
  1942. DestroyWindow (hwnd);
  1943. while (PeekMessage (&msg, 0, 0, 0, PM_REMOVE)) {
  1944. TranslateMessage (&msg);
  1945. DispatchMessage (&msg);
  1946. }
  1947. }
  1948. read_rom_list ();
  1949. if (show)
  1950. show_rom_list ();
  1951. regclosetree (fkey);
  1952. recursive--;
  1953. return ret;
  1954. }
  1955. static void box_art_check(struct uae_prefs *p, const TCHAR *config)
  1956. {
  1957. TCHAR tmp1[MAX_DPATH];
  1958. if (cfgfile_detect_art(p, tmp1)) {
  1959. show_box_art(tmp1, config);
  1960. } else {
  1961. show_box_art(NULL, NULL);
  1962. }
  1963. }
  1964. struct ConfigStruct {
  1965. TCHAR Name[MAX_DPATH];
  1966. TCHAR Path[MAX_DPATH];
  1967. TCHAR Fullpath[MAX_DPATH];
  1968. TCHAR HostLink[MAX_DPATH];
  1969. TCHAR HardwareLink[MAX_DPATH];
  1970. TCHAR Description[CFG_DESCRIPTION_LENGTH];
  1971. TCHAR Artpath[MAX_DPATH];
  1972. TCHAR Category[CFG_DESCRIPTION_LENGTH];
  1973. TCHAR Tags[CFG_DESCRIPTION_LENGTH];
  1974. int Type, Directory;
  1975. struct ConfigStruct *Parent, *Child;
  1976. int host, hardware;
  1977. HTREEITEM item;
  1978. FILETIME t;
  1979. };
  1980. struct CategoryStruct
  1981. {
  1982. TCHAR category[CFG_DESCRIPTION_LENGTH];
  1983. };
  1984. static const TCHAR *configreg[] = { _T("ConfigFile"), _T("ConfigFileHardware"), _T("ConfigFileHost") };
  1985. static const TCHAR *configregfolder[] = { _T("ConfigFileFolder"), _T("ConfigFileHardwareFolder"), _T("ConfigFileHostFolder") };
  1986. static const TCHAR *configregsearch[] = { _T("ConfigFileSearch"), _T("ConfigFileHardwareSearch"), _T("ConfigFileHostSearch") };
  1987. static const TCHAR *configreg2[] = { _T(""), _T("ConfigFileHardware_Auto"), _T("ConfigFileHost_Auto") };
  1988. static struct ConfigStruct **configstore;
  1989. static int configstoresize, configstoreallocated, configtype, configtypepanel;
  1990. static struct CategoryStruct **categorystore;
  1991. static int categorystoresize, categorystoreallocated;
  1992. static struct ConfigStruct *getconfigstorefrompath (TCHAR *path, TCHAR *out, int type)
  1993. {
  1994. int i;
  1995. for (i = 0; i < configstoresize; i++) {
  1996. if (((configstore[i]->Type == 0 || configstore[i]->Type == 3) && type == 0) || (configstore[i]->Type == type)) {
  1997. TCHAR path2[MAX_DPATH];
  1998. _tcscpy (path2, configstore[i]->Path);
  1999. _tcsncat (path2, configstore[i]->Name, MAX_DPATH - _tcslen(path2));
  2000. if (!_tcscmp (path, path2)) {
  2001. _tcscpy (out, configstore[i]->Fullpath);
  2002. _tcsncat (out, configstore[i]->Name, MAX_DPATH - _tcslen(out));
  2003. return configstore[i];
  2004. }
  2005. }
  2006. }
  2007. return 0;
  2008. }
  2009. void target_multipath_modified(struct uae_prefs *p)
  2010. {
  2011. if (p != &workprefs)
  2012. return;
  2013. memcpy(&currprefs.path_hardfile, &p->path_hardfile, sizeof(struct multipath));
  2014. memcpy(&currprefs.path_floppy, &p->path_floppy, sizeof(struct multipath));
  2015. memcpy(&currprefs.path_cd, &p->path_cd, sizeof(struct multipath));
  2016. memcpy(&currprefs.path_rom, &p->path_rom, sizeof(struct multipath));
  2017. }
  2018. static bool cfgfile_can_write(HWND hDlg, const TCHAR *path)
  2019. {
  2020. for (;;) {
  2021. int v = my_readonlyfile(path);
  2022. if (v <= 0)
  2023. return true;
  2024. TCHAR szMessage[MAX_DPATH], msg[MAX_DPATH], szTitle[MAX_DPATH];
  2025. WIN32GUI_LoadUIString(IDS_READONLYCONFIRMATION, szMessage, MAX_DPATH);
  2026. _stprintf(msg, szMessage, path);
  2027. WIN32GUI_LoadUIString(IDS_ERRORTITLE, szTitle, MAX_DPATH);
  2028. if (MessageBox(hDlg, msg, szTitle, MB_YESNO | MB_ICONWARNING | MB_APPLMODAL | MB_SETFOREGROUND) == IDYES) {
  2029. DWORD flags = GetFileAttributesSafe(path);
  2030. if (!(flags & FILE_ATTRIBUTE_READONLY)) {
  2031. return true;
  2032. }
  2033. flags &= ~FILE_ATTRIBUTE_READONLY;
  2034. SetFileAttributesSafe(path, flags);
  2035. continue;
  2036. }
  2037. break;
  2038. }
  2039. return false;
  2040. }
  2041. int target_cfgfile_load (struct uae_prefs *p, const TCHAR *filename, int type, int isdefault)
  2042. {
  2043. int v, i, type2;
  2044. int ct, ct2, size;
  2045. TCHAR tmp1[MAX_DPATH], tmp2[MAX_DPATH];
  2046. TCHAR fname[MAX_DPATH], cname[MAX_DPATH];
  2047. error_log(NULL);
  2048. _tcscpy (fname, filename);
  2049. cname[0] = 0;
  2050. if (!zfile_exists (fname)) {
  2051. fetch_configurationpath (fname, sizeof (fname) / sizeof (TCHAR));
  2052. if (_tcsncmp (fname, filename, _tcslen (fname)))
  2053. _tcscat (fname, filename);
  2054. else
  2055. _tcscpy (fname, filename);
  2056. }
  2057. if (!isdefault)
  2058. qs_override = 1;
  2059. if (type < 0) {
  2060. type = 0;
  2061. cfgfile_get_description(NULL, fname, NULL, NULL, NULL, NULL, NULL, &type);
  2062. if (!isdefault) {
  2063. const TCHAR *p = _tcsrchr(fname, '\\');
  2064. if (!p)
  2065. p = _tcsrchr(fname, '/');
  2066. if (p)
  2067. _tcscpy(cname, p + 1);
  2068. }
  2069. }
  2070. if (type == 0 || type == 1) {
  2071. discard_prefs (p, 0);
  2072. }
  2073. type2 = type;
  2074. if (type == 0 || type == 3) {
  2075. default_prefs (p, true, type);
  2076. write_log(_T("config reset\n"));
  2077. #if 0
  2078. if (isdefault == 0) {
  2079. fetch_configurationpath (tmp1, sizeof (tmp1) / sizeof (TCHAR));
  2080. _tcscat (tmp1, OPTIONSFILENAME);
  2081. cfgfile_load (p, tmp1, NULL, 0, 0);
  2082. }
  2083. #endif
  2084. }
  2085. ct2 = 0;
  2086. regqueryint (NULL, _T("ConfigFile_NoAuto"), &ct2);
  2087. v = cfgfile_load (p, fname, &type2, ct2, isdefault ? 0 : 1);
  2088. if (!v)
  2089. return v;
  2090. if (type > 0)
  2091. return v;
  2092. if (cname[0])
  2093. _tcscpy(config_filename, cname);
  2094. box_art_check(p, fname);
  2095. for (i = 1; i <= 2; i++) {
  2096. if (type != i) {
  2097. size = sizeof (ct);
  2098. ct = 0;
  2099. regqueryint (NULL, configreg2[i], &ct);
  2100. if (ct && ((i == 1 && p->config_hardware_path[0] == 0) || (i == 2 && p->config_host_path[0] == 0) || ct2)) {
  2101. size = sizeof (tmp1) / sizeof (TCHAR);
  2102. regquerystr (NULL, configreg[i], tmp1, &size);
  2103. fetch_path (_T("ConfigurationPath"), tmp2, sizeof (tmp2) / sizeof (TCHAR));
  2104. _tcscat (tmp2, tmp1);
  2105. v = i;
  2106. cfgfile_load (p, tmp2, &v, 1, 0);
  2107. }
  2108. }
  2109. }
  2110. cfgfile_get_shader_config(p, 0);
  2111. v = 1;
  2112. return v;
  2113. }
  2114. static int gui_width, gui_height;
  2115. int gui_fullscreen;
  2116. static RECT gui_fullscreen_rect;
  2117. static bool gui_resize_enabled;
  2118. static bool gui_resize_allowed;
  2119. // Internal panel max size: 396, 318
  2120. static int mm = 0;
  2121. static void m(int monid)
  2122. {
  2123. struct monconfig *gmw = &workprefs.gfx_monitor[monid];
  2124. struct monconfig *gmc = &currprefs.gfx_monitor[monid];
  2125. struct monconfig *gmh = &changed_prefs.gfx_monitor[monid];
  2126. write_log (_T("%d:0: %dx%d %dx%d %dx%d\n"), mm, gmc->gfx_size.width, gmc->gfx_size.height,
  2127. gmw->gfx_size.width, gmw->gfx_size.height, gmh->gfx_size.width, gmh->gfx_size.height);
  2128. write_log (_T("%d:1: %dx%d %dx%d %dx%d\n"), mm, gmc->gfx_size_fs.width, gmc->gfx_size_fs.height,
  2129. gmw->gfx_size_fs.width, gmw->gfx_size_fs.height, gmh->gfx_size_fs.width, gmh->gfx_size_fs.height);
  2130. mm++;
  2131. }
  2132. static void flipgui(int opengui)
  2133. {
  2134. D3D_guimode(0, opengui);
  2135. if (full_property_sheet)
  2136. return;
  2137. if (opengui) {
  2138. DirectDraw_FlipToGDISurface();
  2139. } else {
  2140. if (quit_program)
  2141. return;
  2142. full_redraw_all();
  2143. }
  2144. }
  2145. static int GetSettings (int all_options, HWND hwnd);
  2146. /* if drive is -1, show the full GUI, otherwise file-requester for DF[drive] */
  2147. void gui_display (int shortcut)
  2148. {
  2149. struct AmigaMonitor *mon = &AMonitors[0];
  2150. struct picasso96_state_struct *state = &picasso96_state[0];
  2151. struct monconfig *gm = &currprefs.gfx_monitor[0];
  2152. static int here;
  2153. int w, h;
  2154. if (here)
  2155. return;
  2156. here++;
  2157. gui_active++;
  2158. if (isfullscreen() > 0 && currprefs.gfx_api != 1)
  2159. screenshot_prepare(getfocusedmonitor());
  2160. flipgui(1);
  2161. if (setpaused (7)) {
  2162. inputdevice_unacquire ();
  2163. wait_keyrelease();
  2164. clearallkeys ();
  2165. setmouseactive(0, 0);
  2166. }
  2167. w = h = -1;
  2168. if (!WIN32GFX_IsPicassoScreen(mon) && currprefs.gfx_apmode[0].gfx_fullscreen && (gm->gfx_size.width < gui_width || gm->gfx_size.height < gui_height)) {
  2169. w = gm->gfx_size.width;
  2170. h = gm->gfx_size.height;
  2171. }
  2172. if (WIN32GFX_IsPicassoScreen(mon) && currprefs.gfx_apmode[1].gfx_fullscreen && (state->Width < gui_width || state->Height < gui_height)) {
  2173. w = gm->gfx_size.width;
  2174. h = gm->gfx_size.height;
  2175. }
  2176. mon->manual_painting_needed++; /* So that WM_PAINT will refresh the display */
  2177. flush_log ();
  2178. if (shortcut == -1) {
  2179. int ret;
  2180. ret = GetSettings(0, mon->hAmigaWnd);
  2181. if (!ret) {
  2182. savestate_state = 0;
  2183. }
  2184. } else if (shortcut >= 0 && shortcut < 4) {
  2185. DiskSelection(mon->hAmigaWnd, IDC_DF0 + shortcut, 0, &changed_prefs, NULL, NULL);
  2186. } else if (shortcut == 5) {
  2187. if (DiskSelection(mon->hAmigaWnd, IDC_DOSAVESTATE, 9, &changed_prefs, NULL, NULL))
  2188. save_state (savestate_fname, _T("Description!"));
  2189. } else if (shortcut == 4) {
  2190. if (DiskSelection(mon->hAmigaWnd, IDC_DOLOADSTATE, 10, &changed_prefs, NULL, NULL))
  2191. savestate_state = STATE_DORESTORE;
  2192. } else if (shortcut == 6) {
  2193. DiskSelection(mon->hAmigaWnd, IDC_CD_SELECT, 17, &changed_prefs, NULL, NULL);
  2194. }
  2195. mon->manual_painting_needed--; /* So that WM_PAINT doesn't need to use custom refreshing */
  2196. reset_sound ();
  2197. inputdevice_copyconfig (&changed_prefs, &currprefs);
  2198. inputdevice_config_change_test ();
  2199. clearallkeys ();
  2200. flipgui(0);
  2201. if (resumepaused (7)) {
  2202. inputdevice_acquire (TRUE);
  2203. setmouseactive(0, 1);
  2204. }
  2205. fpscounter_reset ();
  2206. screenshot_free ();
  2207. write_disk_history ();
  2208. gui_active--;
  2209. here--;
  2210. }
  2211. static void prefs_to_gui(struct uae_prefs *p)
  2212. {
  2213. int st = savestate_state;
  2214. default_prefs(&workprefs, false, 0);
  2215. copy_prefs(p, &workprefs);
  2216. /* filesys hack */
  2217. workprefs.mountitems = currprefs.mountitems;
  2218. memcpy (&workprefs.mountconfig, &currprefs.mountconfig, MOUNT_CONFIG_SIZE * sizeof (struct uaedev_config_info));
  2219. updatewinfsmode(0, &workprefs);
  2220. if (workprefs.statefile[0])
  2221. savestate_state = st;
  2222. }
  2223. static void gui_to_prefs(void)
  2224. {
  2225. // Always copy our prefs to changed_prefs
  2226. copy_prefs(&workprefs, &changed_prefs);
  2227. if (quit_program == -UAE_RESET_HARD) {
  2228. // copy all if hard reset
  2229. copy_prefs(&workprefs, &currprefs);
  2230. memory_hardreset(2);
  2231. }
  2232. // filesys hack
  2233. currprefs.mountitems = changed_prefs.mountitems;
  2234. memcpy (&currprefs.mountconfig, &changed_prefs.mountconfig, MOUNT_CONFIG_SIZE * sizeof (struct uaedev_config_info));
  2235. fixup_prefs (&changed_prefs, true);
  2236. updatewinfsmode(0, &changed_prefs);
  2237. }
  2238. static int iscd (int n)
  2239. {
  2240. if (quickstart_cd && n == 1 && currentpage == QUICKSTART_ID)
  2241. return 1;
  2242. return 0;
  2243. }
  2244. static const GUID diskselectionguids[] = {
  2245. { 0x4fa8fa15, 0xc209, 0x4112, { 0x94, 0x7b, 0xc6, 0x00, 0x8e, 0x1f, 0xa3, 0x29 } },
  2246. { 0x32073f09, 0x752d, 0x4783, { 0x84, 0x6c, 0xaa, 0x66, 0x48, 0x84, 0x14, 0x45 } },
  2247. { 0x8047f7ea, 0x8a42, 0x4695, { 0x94, 0x52, 0xf5, 0x0d, 0xb8, 0x43, 0x00, 0x58 } },
  2248. { 0x2412c4e7, 0xf608, 0x4333, { 0x83, 0xd2, 0xa1, 0x2f, 0xdf, 0x66, 0xac, 0xe5 } },
  2249. { 0xe3741dff, 0x11f2, 0x445f, { 0x94, 0xb0, 0xa3, 0xe7, 0x58, 0xe2, 0xcb, 0xb5 } },
  2250. { 0x2056d641, 0xba13, 0x4312, { 0xaa, 0x75, 0xc5, 0xeb, 0x52, 0xa8, 0x1c, 0xe3 } },
  2251. { 0x05aa5db2, 0x470b, 0x4725, { 0x96, 0x03, 0xee, 0x61, 0x30, 0xfc, 0x54, 0x99 } },
  2252. { 0x68366188, 0xa6d4, 0x4278, { 0xb7, 0x55, 0x6a, 0xb8, 0x17, 0xa6, 0x71, 0xd9 } },
  2253. { 0xe990bee1, 0xd7cc, 0x4768, { 0xaf, 0x34, 0xef, 0x39, 0x87, 0x48, 0x09, 0x50 } },
  2254. { 0x12c53317, 0xd99c, 0x4494, { 0x8d, 0x81, 0x00, 0x6d, 0x8c, 0x62, 0x7d, 0x83 } }
  2255. };
  2256. static void getfilter (int num, const TCHAR *name, int *filter, TCHAR *fname)
  2257. {
  2258. _tcscpy (fname, name);
  2259. _tcscat (fname, _T("_Filter"));
  2260. regqueryint (NULL, fname, &filter[num]);
  2261. }
  2262. static void setfilter (int num, int *filter, const TCHAR *fname)
  2263. {
  2264. if (fname == NULL || fname[0] == 0)
  2265. return;
  2266. regsetint (NULL, fname, filter[num]);
  2267. }
  2268. static UINT_PTR CALLBACK ofnhook (HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
  2269. {
  2270. struct AmigaMonitor *mon = &AMonitors[0];
  2271. HWND hWnd;
  2272. RECT windowRect;
  2273. int width, height, w2, h2, x, y;
  2274. struct MultiDisplay *md;
  2275. NMHDR *nmhdr;
  2276. if (message == WM_NOTIFY) {
  2277. nmhdr = (LPNMHDR)lParam;
  2278. if (nmhdr->code == CDN_INITDONE) {
  2279. write_log (_T("OFNHOOK CDN_INITDONE\n"));
  2280. PostMessage (hDlg, WM_USER + 1, 0, 0);
  2281. // OFN_ENABLESIZING enabled: SetWindowPos() only works once here...
  2282. }
  2283. return FALSE;
  2284. } else if (message != WM_USER + 1) {
  2285. return FALSE;
  2286. }
  2287. write_log (_T("OFNHOOK POST\n"));
  2288. hWnd = GetParent (hDlg);
  2289. md = getdisplay(&currprefs, mon->monitor_id);
  2290. if (!md)
  2291. return FALSE;
  2292. w2 = WIN32GFX_GetWidth(mon);
  2293. h2 = WIN32GFX_GetHeight(mon);
  2294. write_log (_T("MOVEWINDOW %dx%d %dx%d (%dx%d)\n"), md->rect.left, md->rect.top, md->rect.right, md->rect.bottom, w2, h2);
  2295. windowRect.left = windowRect.right = windowRect.top = windowRect.bottom = -1;
  2296. GetWindowRect (hWnd, &windowRect);
  2297. width = windowRect.right - windowRect.left;
  2298. height = windowRect.bottom - windowRect.top;
  2299. write_log (_T("%dx%d %dx%d\n"), windowRect.left, windowRect.top, windowRect.right, windowRect.bottom);
  2300. if (width < 800)
  2301. width = 800;
  2302. if (height < 600)
  2303. height = 600;
  2304. if (width > w2)
  2305. width = w2;
  2306. if (height > h2)
  2307. height = h2;
  2308. x = md->rect.left + (w2 - width) / 2;
  2309. y = md->rect.top + (h2 - height) / 2;
  2310. write_log (_T("X=%d Y=%d W=%d H=%d\n"), x, y, width, height);
  2311. SetWindowPos (hWnd, NULL, x, y, width, height, SWP_NOZORDER | SWP_NOACTIVATE);
  2312. return FALSE;
  2313. }
  2314. static void eject_cd (void)
  2315. {
  2316. workprefs.cdslots[0].name[0] = 0;
  2317. if (full_property_sheet)
  2318. workprefs.cdslots[0].type = SCSI_UNIT_DEFAULT;
  2319. quickstart_cddrive[0] = 0;
  2320. workprefs.cdslots[0].inuse = false;
  2321. if (full_property_sheet) {
  2322. quickstart_cdtype = 0;
  2323. } else {
  2324. if (quickstart_cdtype > 0) {
  2325. quickstart_cdtype = 1;
  2326. workprefs.cdslots[0].inuse = true;
  2327. }
  2328. }
  2329. }
  2330. void gui_infotextbox(HWND hDlg, const TCHAR *text)
  2331. {
  2332. stringboxdialogactive = 1;
  2333. HWND hwnd = CustomCreateDialog (IDD_DISKINFO, hDlg ? hDlg : hGUIWnd, StringBoxDialogProc);
  2334. if (hwnd == NULL)
  2335. return;
  2336. HFONT font = CreateFont (getscaledfontsize(-1), 0, 0, 0, 0, 0, 0, 0, DEFAULT_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY, DEFAULT_PITCH | FF_DONTCARE, _T("Lucida Console"));
  2337. if (font)
  2338. SendMessage (GetDlgItem (hwnd, IDC_DISKINFOBOX), WM_SETFONT, WPARAM(font), FALSE);
  2339. SendMessage (GetDlgItem (hwnd, IDC_DISKINFOBOX), WM_SETTEXT, 0, (LPARAM)text);
  2340. while (stringboxdialogactive == 1) {
  2341. MSG msg;
  2342. int ret;
  2343. WaitMessage ();
  2344. while ((ret = GetMessage (&msg, NULL, 0, 0))) {
  2345. if (ret == -1)
  2346. break;
  2347. if (!IsWindow (hwnd) || !IsDialogMessage (hwnd, &msg)) {
  2348. TranslateMessage (&msg);
  2349. DispatchMessage (&msg);
  2350. }
  2351. }
  2352. if (stringboxdialogactive == -1)
  2353. break;
  2354. }
  2355. if (font) {
  2356. DeleteObject(font);
  2357. }
  2358. }
  2359. static void infofloppy (HWND hDlg, int n)
  2360. {
  2361. struct diskinfo di;
  2362. TCHAR tmp2[MAX_DPATH], tmp1[MAX_DPATH], tmp3[MAX_DPATH];
  2363. TCHAR text[20000];
  2364. DISK_examine_image (&workprefs, n, &di, true, tmp3);
  2365. DISK_validate_filename(&workprefs, workprefs.floppyslots[n].df, n, tmp1, 0, NULL, NULL, NULL);
  2366. text[0] = 0;
  2367. if (tmp3[0]) {
  2368. _tcscpy(text, tmp3);
  2369. _tcscat(text, _T("\r\n\r\n"));
  2370. }
  2371. tmp2[0] = 0;
  2372. if (tmp1[0]) {
  2373. _stprintf(tmp2, _T("'%s'\r\n"), tmp1);
  2374. }
  2375. _stprintf (tmp2 + _tcslen(tmp2), _T("Disk readable: %s\r\n"), di.unreadable ? _T("No") : _T("Yes"));
  2376. if (di.image_crc_value) {
  2377. _stprintf(tmp2 + _tcslen(tmp2), _T("Disk CRC32: %08X\r\n"), di.imagecrc32);
  2378. }
  2379. _stprintf(tmp2 + _tcslen(tmp2),
  2380. _T("Boot block CRC32: %08X\r\nBoot block checksum valid: %s\r\nBoot block type: %s\r\n"),
  2381. di.bootblockcrc32,
  2382. di.bb_crc_valid ? _T("Yes") : _T("No"),
  2383. di.bootblocktype == 0 ? _T("Custom") : (di.bootblocktype == 1 ? _T("Standard 1.x") : _T("Standard 2.x+"))
  2384. );
  2385. _tcscat(text, tmp2);
  2386. if (di.diskname[0]) {
  2387. _stprintf (tmp2,
  2388. _T("Label: '%s'\r\n"), di.diskname);
  2389. _tcscat (text, tmp2);
  2390. }
  2391. _tcscat (text, _T("\r\n"));
  2392. if (di.bootblockinfo[0]) {
  2393. _tcscat(text, _T("Amiga Bootblock Reader database detected:\r\n"));
  2394. _tcscat(text, _T("Name: '"));
  2395. _tcscat(text, di.bootblockinfo);
  2396. _tcscat(text, _T("'"));
  2397. _tcscat(text, _T("\r\n"));
  2398. if (di.bootblockclass[0]) {
  2399. _tcscat(text, _T("Class: '"));
  2400. _tcscat(text, di.bootblockclass);
  2401. _tcscat(text, _T("'"));
  2402. _tcscat(text, _T("\r\n"));
  2403. }
  2404. _tcscat(text, _T("\r\n"));
  2405. }
  2406. int w = 32;
  2407. for (int i = 0; i < 1024; i += w) {
  2408. for (int j = 0; j < w; j++) {
  2409. uae_u8 b = di.bootblock[i + j];
  2410. _stprintf (tmp2 + j * 2, _T("%02X"), b);
  2411. if (b >= 32 && b < 127)
  2412. tmp2[w * 2 + 1 + j] = (TCHAR)b;
  2413. else
  2414. tmp2[w * 2 + 1 + j] = '.';
  2415. }
  2416. tmp2[w * 2] = ' ';
  2417. tmp2[w * 2 + 1 + w] = 0;
  2418. _tcscat (text, tmp2);
  2419. _tcscat (text, _T("\r\n"));
  2420. }
  2421. stringboxdialogactive = 1;
  2422. HWND hwnd = CustomCreateDialog (IDD_DISKINFO, hDlg, StringBoxDialogProc);
  2423. if (hwnd == NULL)
  2424. return;
  2425. HFONT font = CreateFont (getscaledfontsize(-1), 0, 0, 0, 0, 0, 0, 0, DEFAULT_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY, DEFAULT_PITCH | FF_DONTCARE, _T("Lucida Console"));
  2426. if (font)
  2427. SendMessage (GetDlgItem (hwnd, IDC_DISKINFOBOX), WM_SETFONT, WPARAM(font), FALSE);
  2428. SendMessage (GetDlgItem (hwnd, IDC_DISKINFOBOX), WM_SETTEXT, 0, (LPARAM)text);
  2429. while (stringboxdialogactive == 1) {
  2430. MSG msg;
  2431. int ret;
  2432. WaitMessage ();
  2433. while ((ret = GetMessage (&msg, NULL, 0, 0))) {
  2434. if (ret == -1)
  2435. break;
  2436. if (!IsWindow (hwnd) || !IsDialogMessage (hwnd, &msg)) {
  2437. TranslateMessage (&msg);
  2438. DispatchMessage (&msg);
  2439. }
  2440. }
  2441. if (stringboxdialogactive == -1)
  2442. break;
  2443. }
  2444. DeleteObject (font);
  2445. }
  2446. static void ejectfloppy (int n)
  2447. {
  2448. if (iscd (n)) {
  2449. eject_cd ();
  2450. } else {
  2451. workprefs.floppyslots[n].df[0] = 0;
  2452. // no disk in drive when GUI was entered
  2453. // make sure possibly disks inserted after GUI was entered
  2454. // are removed.
  2455. if (changed_prefs.floppyslots[n].df[0] == 0)
  2456. disk_insert(n, _T(""));
  2457. }
  2458. }
  2459. static void selectcd (struct uae_prefs *prefs, HWND hDlg, int num, int id, const TCHAR *full_path)
  2460. {
  2461. SetDlgItemText (hDlg, id, full_path);
  2462. if (quickstart_cddrive[0])
  2463. eject_cd ();
  2464. _tcscpy (prefs->cdslots[0].name, full_path);
  2465. fullpath (prefs->cdslots[0].name, sizeof prefs->cdslots[0].name / sizeof (TCHAR));
  2466. DISK_history_add (prefs->cdslots[0].name, -1, HISTORY_CD, 0);
  2467. }
  2468. static void selectdisk (struct uae_prefs *prefs, HWND hDlg, int num, int id, const TCHAR *full_path)
  2469. {
  2470. if (iscd (num)) {
  2471. selectcd (prefs, hDlg, num, id, full_path);
  2472. return;
  2473. }
  2474. SetDlgItemText (hDlg, id, full_path);
  2475. _tcscpy(prefs->floppyslots[num].df, full_path);
  2476. fullpath (prefs->floppyslots[num].df, sizeof prefs->floppyslots[num].df / sizeof (TCHAR));
  2477. DISK_history_add (prefs->floppyslots[num].df, -1, HISTORY_FLOPPY, 0);
  2478. }
  2479. static void selectgenlock(struct uae_prefs *prefs, HWND hDlg, int id, const TCHAR *full_path)
  2480. {
  2481. SetDlgItemText(hDlg, id, full_path);
  2482. if (workprefs.genlock_image == 3) {
  2483. _tcscpy(prefs->genlock_image_file, full_path);
  2484. fullpath(prefs->genlock_image_file, sizeof prefs->genlock_image_file / sizeof(TCHAR));
  2485. DISK_history_add(prefs->genlock_image_file, -1, HISTORY_GENLOCK_IMAGE, 0);
  2486. } else if (workprefs.genlock_image == 4 || workprefs.genlock_image >= 6) {
  2487. _tcscpy(prefs->genlock_video_file, full_path);
  2488. fullpath(prefs->genlock_video_file, sizeof prefs->genlock_video_file / sizeof(TCHAR));
  2489. DISK_history_add(prefs->genlock_video_file, -1, HISTORY_GENLOCK_VIDEO, 0);
  2490. }
  2491. }
  2492. static void getcreatefloppytype(HWND hDlg, drive_type *atype, int *hd)
  2493. {
  2494. *atype = DRV_NONE;
  2495. *hd = -1;
  2496. int type = SendDlgItemMessage(hDlg, IDC_FLOPPYTYPE, CB_GETCURSEL, 0, 0L);
  2497. switch (type)
  2498. {
  2499. case 0:
  2500. *atype = DRV_35_DD;
  2501. break;
  2502. case 1:
  2503. *atype = DRV_35_HD;
  2504. break;
  2505. case 2:
  2506. *atype = DRV_PC_35_ONLY_80;
  2507. break;
  2508. case 3:
  2509. *atype = DRV_PC_35_ONLY_80;
  2510. *hd = 1;
  2511. break;
  2512. case 4:
  2513. *atype = DRV_PC_525_ONLY_40;
  2514. break;
  2515. }
  2516. }
  2517. static void setdpath (const TCHAR *name, const TCHAR *path)
  2518. {
  2519. TCHAR tmp[MAX_DPATH];
  2520. _tcscpy (tmp, path);
  2521. fullpath (tmp, sizeof tmp / sizeof (TCHAR));
  2522. regsetstr (NULL, name, tmp);
  2523. }
  2524. // Common routine for popping up a file-requester
  2525. // flag - 0 for floppy loading, 1 for floppy creation, 2 for loading hdf, 3 for saving hdf
  2526. // flag - 4 for loading .uae config-files, 5 for saving .uae config-files
  2527. // flag = 6 for loading .rom files, 7 for loading .key files
  2528. // flag = 8 for loading configurations
  2529. // flag = 9 for saving snapshots
  2530. // flag = 10 for loading snapshots
  2531. // flag = 11 for selecting flash files
  2532. // flag = 12 for loading anything
  2533. // flag = 13 for selecting path
  2534. // flag = 14 for loading filesystem
  2535. // flag = 15 for loading input
  2536. // flag = 16 for recording input
  2537. // flag = 17 for CD image
  2538. // flag = 18 for Tape image
  2539. // flag = 20 for genlock image
  2540. // flag = 21 for genlock video
  2541. // flag = 22 for floppy replacement (missing statefile)
  2542. // fags = 23 for hdf geometry (load)
  2543. // fags = 24 for hdf geometry (save)
  2544. int DiskSelection_2 (HWND hDlg, WPARAM wParam, int flag, struct uae_prefs *prefs, TCHAR *infilename, TCHAR *path_out, int *multi)
  2545. {
  2546. static int previousfilter[32];
  2547. TCHAR filtername[MAX_DPATH] = _T("");
  2548. OPENFILENAME openFileName;
  2549. TCHAR full_path[MAX_DPATH] = _T("");
  2550. TCHAR full_path2[MAX_DPATH];
  2551. TCHAR file_name[MAX_DPATH] = _T("");
  2552. TCHAR init_path[MAX_DPATH] = _T("");
  2553. BOOL result = FALSE;
  2554. TCHAR* amiga_path = NULL, * initialdir = NULL;
  2555. const TCHAR *defext = NULL;
  2556. TCHAR *p, *nextp;
  2557. int all = 1;
  2558. int next;
  2559. int nosavepath = 0;
  2560. const GUID *guid = NULL;
  2561. TCHAR szTitle[MAX_DPATH] = { 0 };
  2562. TCHAR szFormat[MAX_DPATH];
  2563. TCHAR szFilter[MAX_DPATH] = { 0 };
  2564. memset (&openFileName, 0, sizeof (OPENFILENAME));
  2565. if (path_out && path_out[0]) {
  2566. _tcscpy (init_path, path_out);
  2567. nosavepath = 1;
  2568. } else {
  2569. _tcsncpy (init_path, start_path_data, MAX_DPATH);
  2570. switch (flag)
  2571. {
  2572. case 0:
  2573. case 1:
  2574. case 22:
  2575. getfilter (flag, _T("FloppyPath"), previousfilter, filtername);
  2576. fetch_path (_T("FloppyPath"), init_path, sizeof (init_path) / sizeof (TCHAR));
  2577. guid = &diskselectionguids[0];
  2578. break;
  2579. case 2:
  2580. case 3:
  2581. case 23:
  2582. case 24:
  2583. getfilter (flag, _T("hdfPath"), previousfilter, filtername);
  2584. fetch_path (_T("hdfPath"), init_path, sizeof (init_path) / sizeof (TCHAR));
  2585. guid = &diskselectionguids[1];
  2586. break;
  2587. case 6:
  2588. case 7:
  2589. case 11:
  2590. getfilter (flag, _T("KickstartPath"), previousfilter, filtername);
  2591. fetch_path (_T("KickstartPath"), init_path, sizeof (init_path) / sizeof (TCHAR));
  2592. guid = &diskselectionguids[2];
  2593. break;
  2594. case 4:
  2595. case 5:
  2596. case 8:
  2597. getfilter (flag, _T("ConfigurationPath"), previousfilter, filtername);
  2598. fetch_path (_T("ConfigurationPath"), init_path, sizeof (init_path) / sizeof (TCHAR));
  2599. guid = &diskselectionguids[3];
  2600. break;
  2601. case 9:
  2602. case 10:
  2603. {
  2604. int ok = 0;
  2605. if (savestate_fname[0]) {
  2606. _tcscpy (init_path, savestate_fname);
  2607. for (;;) {
  2608. TCHAR *p;
  2609. if (my_existsdir (init_path)) {
  2610. ok = 1;
  2611. break;
  2612. }
  2613. p = _tcsrchr (init_path, '\\');
  2614. if (!p)
  2615. p = _tcsrchr (init_path, '/');
  2616. if (!p)
  2617. break;
  2618. *p = 0;
  2619. }
  2620. }
  2621. if (!ok) {
  2622. getfilter (flag, _T("StatefilePath"), previousfilter, filtername);
  2623. fetch_path (_T("StatefilePath"), init_path, sizeof (init_path) / sizeof (TCHAR));
  2624. }
  2625. guid = &diskselectionguids[4];
  2626. }
  2627. break;
  2628. case 15:
  2629. case 16:
  2630. getfilter (flag, _T("InputPath"), previousfilter, filtername);
  2631. fetch_path (_T("InputPath"), init_path, sizeof (init_path) / sizeof (TCHAR));
  2632. guid = &diskselectionguids[5];
  2633. break;
  2634. case 17:
  2635. getfilter (flag, _T("CDPath"), previousfilter, filtername);
  2636. fetch_path (_T("CDPath"), init_path, sizeof (init_path) / sizeof (TCHAR));
  2637. guid = &diskselectionguids[6];
  2638. break;
  2639. case 18:
  2640. getfilter (flag, _T("TapePath"), previousfilter, filtername);
  2641. fetch_path (_T("TapePath"), init_path, sizeof (init_path) / sizeof (TCHAR));
  2642. guid = &diskselectionguids[7];
  2643. break;
  2644. case 20:
  2645. fetch_path(_T("GenlockImagePath"), init_path, sizeof(init_path) / sizeof(TCHAR));
  2646. guid = &diskselectionguids[8];
  2647. break;
  2648. case 21:
  2649. fetch_path(_T("GenlockVideoPath"), init_path, sizeof(init_path) / sizeof(TCHAR));
  2650. guid = &diskselectionguids[9];
  2651. break;
  2652. }
  2653. }
  2654. if (infilename)
  2655. _tcscpy(full_path, infilename);
  2656. szFilter[0] = 0;
  2657. szFilter[1] = 0;
  2658. switch (flag) {
  2659. case 0:
  2660. WIN32GUI_LoadUIString (IDS_SELECTADF, szTitle, MAX_DPATH);
  2661. WIN32GUI_LoadUIString (IDS_ADF, szFormat, MAX_DPATH);
  2662. _stprintf (szFilter, _T("%s "), szFormat);
  2663. memcpy (szFilter + _tcslen (szFilter), DISK_FORMAT_STRING, sizeof (DISK_FORMAT_STRING));
  2664. defext = _T("adf");
  2665. break;
  2666. case 22:
  2667. _tcscpy(szTitle, prefs->floppyslots[wParam - IDC_DF0].df);
  2668. WIN32GUI_LoadUIString (IDS_ADF, szFormat, MAX_DPATH);
  2669. _stprintf (szFilter, _T("%s "), szFormat);
  2670. memcpy (szFilter + _tcslen (szFilter), DISK_FORMAT_STRING, sizeof (DISK_FORMAT_STRING));
  2671. defext = _T("adf");
  2672. break;
  2673. case 1:
  2674. WIN32GUI_LoadUIString (IDS_CHOOSEBLANK, szTitle, MAX_DPATH);
  2675. WIN32GUI_LoadUIString (IDS_ADF, szFormat, MAX_DPATH);
  2676. _stprintf (szFilter, _T("%s "), szFormat);
  2677. memcpy (szFilter + _tcslen (szFilter), _T("(*.adf)\0*.adf\0"), 15 * sizeof (TCHAR));
  2678. defext = _T("adf");
  2679. break;
  2680. case 2:
  2681. case 3:
  2682. WIN32GUI_LoadUIString (IDS_SELECTHDF, szTitle, MAX_DPATH);
  2683. WIN32GUI_LoadUIString (IDS_HDF, szFormat, MAX_DPATH);
  2684. _stprintf (szFilter, _T("%s "), szFormat);
  2685. memcpy (szFilter + _tcslen (szFilter), HDF_FORMAT_STRING, sizeof (HDF_FORMAT_STRING));
  2686. defext = _T("hdf");
  2687. break;
  2688. case 4:
  2689. case 5:
  2690. WIN32GUI_LoadUIString (IDS_SELECTUAE, szTitle, MAX_DPATH);
  2691. WIN32GUI_LoadUIString (IDS_UAE, szFormat, MAX_DPATH );
  2692. _stprintf (szFilter, _T("%s "), szFormat);
  2693. memcpy (szFilter + _tcslen (szFilter), _T("(*.uae)\0*.uae\0"), 15 * sizeof (TCHAR));
  2694. defext = _T("uae");
  2695. break;
  2696. case 6:
  2697. WIN32GUI_LoadUIString (IDS_SELECTROM, szTitle, MAX_DPATH);
  2698. WIN32GUI_LoadUIString (IDS_ROM, szFormat, MAX_DPATH);
  2699. _stprintf (szFilter, _T("%s "), szFormat);
  2700. memcpy (szFilter + _tcslen (szFilter), ROM_FORMAT_STRING, sizeof (ROM_FORMAT_STRING));
  2701. defext = _T("rom");
  2702. break;
  2703. case 7:
  2704. WIN32GUI_LoadUIString (IDS_SELECTKEY, szTitle, MAX_DPATH);
  2705. WIN32GUI_LoadUIString (IDS_KEY, szFormat, MAX_DPATH);
  2706. _stprintf (szFilter, _T("%s "), szFormat);
  2707. memcpy (szFilter + _tcslen (szFilter), _T("(*.key)\0*.key\0"), 15 * sizeof (TCHAR));
  2708. defext = _T("key");
  2709. break;
  2710. case 15:
  2711. case 16:
  2712. WIN32GUI_LoadUIString (flag == 15 ? IDS_RESTOREINP : IDS_SAVEINP, szTitle, MAX_DPATH);
  2713. WIN32GUI_LoadUIString (IDS_INP, szFormat, MAX_DPATH);
  2714. _stprintf (szFilter, _T("%s "), szFormat);
  2715. memcpy (szFilter + _tcslen (szFilter), INP_FORMAT_STRING, sizeof (INP_FORMAT_STRING));
  2716. defext = _T("inp");
  2717. break;
  2718. case 9:
  2719. case 10:
  2720. WIN32GUI_LoadUIString (flag == 10 ? IDS_RESTOREUSS : IDS_SAVEUSS, szTitle, MAX_DPATH);
  2721. WIN32GUI_LoadUIString (IDS_USS, szFormat, MAX_DPATH);
  2722. _stprintf (szFilter, _T("%s "), szFormat);
  2723. if (flag == 10) {
  2724. memcpy (szFilter + _tcslen (szFilter), USS_FORMAT_STRING_RESTORE, sizeof (USS_FORMAT_STRING_RESTORE));
  2725. all = 1;
  2726. } else {
  2727. TCHAR tmp[MAX_DPATH];
  2728. memcpy (szFilter + _tcslen (szFilter), USS_FORMAT_STRING_SAVE, sizeof (USS_FORMAT_STRING_SAVE));
  2729. p = szFilter;
  2730. while (p[0] != 0 || p[1] !=0 ) p++;
  2731. p++;
  2732. WIN32GUI_LoadUIString (IDS_STATEFILE_UNCOMPRESSED, tmp, sizeof (tmp) / sizeof (TCHAR));
  2733. _tcscat (p, tmp);
  2734. _tcscat (p, _T(" (*.uss)"));
  2735. p += _tcslen (p) + 1;
  2736. _tcscpy (p, _T("*.uss"));
  2737. p += _tcslen (p) + 1;
  2738. WIN32GUI_LoadUIString (IDS_STATEFILE_RAMDUMP, tmp, sizeof (tmp) / sizeof (TCHAR));
  2739. _tcscat (p, tmp);
  2740. _tcscat (p, _T(" (*.dat)"));
  2741. p += _tcslen (p) + 1;
  2742. _tcscpy (p, _T("*.dat"));
  2743. p += _tcslen (p) + 1;
  2744. WIN32GUI_LoadUIString (IDS_STATEFILE_WAVE, tmp, sizeof (tmp) / sizeof (TCHAR));
  2745. _tcscat (p, tmp);
  2746. _tcscat (p, _T(" (*.wav)"));
  2747. p += _tcslen (p) + 1;
  2748. _tcscpy (p, _T("*.wav"));
  2749. p += _tcslen (p) + 1;
  2750. *p = 0;
  2751. all = 0;
  2752. }
  2753. defext = _T("uss");
  2754. break;
  2755. case 11:
  2756. case 19:
  2757. WIN32GUI_LoadUIString (IDS_SELECTFLASH, szTitle, MAX_DPATH);
  2758. WIN32GUI_LoadUIString (IDS_FLASH, szFormat, MAX_DPATH);
  2759. _stprintf (szFilter, _T("%s "), szFormat);
  2760. memcpy (szFilter + _tcslen (szFilter), _T("(*.nvr)\0*.nvr\0"), 15 * sizeof (TCHAR));
  2761. defext = _T("nvr");
  2762. break;
  2763. case 8:
  2764. default:
  2765. WIN32GUI_LoadUIString (IDS_SELECTINFO, szTitle, MAX_DPATH);
  2766. break;
  2767. case 12:
  2768. WIN32GUI_LoadUIString (IDS_SELECTFS, szTitle, MAX_DPATH);
  2769. initialdir = path_out;
  2770. break;
  2771. case 13:
  2772. WIN32GUI_LoadUIString (IDS_SELECTINFO, szTitle, MAX_DPATH);
  2773. initialdir = path_out;
  2774. break;
  2775. case 14:
  2776. _tcscpy (szTitle, _T("Select supported archive file"));
  2777. _stprintf (szFilter, _T("%s (%s)"), _T("Archive"), ARCHIVE_STRING);
  2778. _tcscpy (szFilter + _tcslen (szFilter) + 1, ARCHIVE_STRING);
  2779. initialdir = path_out;
  2780. break;
  2781. case 17:
  2782. WIN32GUI_LoadUIString (IDS_SELECTCD, szTitle, MAX_DPATH);
  2783. WIN32GUI_LoadUIString (IDS_CD, szFormat, MAX_DPATH);
  2784. _stprintf (szFilter, _T("%s "), szFormat);
  2785. memcpy (szFilter + _tcslen (szFilter), CD_FORMAT_STRING, sizeof (CD_FORMAT_STRING) + sizeof (TCHAR));
  2786. defext = _T("cue");
  2787. break;
  2788. case 18:
  2789. WIN32GUI_LoadUIString (IDS_SELECTTAPE, szTitle, MAX_DPATH);
  2790. break;
  2791. case 20:
  2792. _tcscpy(szTitle, _T("Select genlock image"));
  2793. break;
  2794. case 21:
  2795. _tcscpy(szTitle, _T("Select genlock video"));
  2796. break;
  2797. case 23:
  2798. case 24:
  2799. _tcscpy(szTitle, _T("Select geometry file"));
  2800. _stprintf (szFilter, _T("%s "), _T("Geometry files"));
  2801. memcpy (szFilter + _tcslen (szFilter), GEO_FORMAT_STRING, sizeof (GEO_FORMAT_STRING) + sizeof (TCHAR));
  2802. defext = _T("geo");
  2803. break;
  2804. break;
  2805. }
  2806. if (all) {
  2807. p = szFilter;
  2808. while (p[0] != 0 || p[1] !=0) p++;
  2809. p++;
  2810. _tcscpy (p, _T("All files (*.*)"));
  2811. p += _tcslen (p) + 1;
  2812. _tcscpy (p, _T("*.*"));
  2813. p += _tcslen (p) + 1;
  2814. *p = 0;
  2815. }
  2816. openFileName.lStructSize = sizeof (OPENFILENAME);
  2817. openFileName.hwndOwner = hDlg;
  2818. openFileName.Flags = OFN_EXPLORER | OFN_FILEMUSTEXIST | OFN_PATHMUSTEXIST |
  2819. OFN_LONGNAMES | OFN_HIDEREADONLY | OFN_NOCHANGEDIR | OFN_ENABLESIZING | (isfullscreen () > 0 ? OFN_ENABLEHOOK : 0);
  2820. openFileName.lpstrFilter = szFilter;
  2821. openFileName.lpstrDefExt = defext;
  2822. openFileName.nFilterIndex = previousfilter[flag];
  2823. openFileName.lpstrFile = full_path;
  2824. openFileName.nMaxFile = MAX_DPATH;
  2825. openFileName.lpstrFileTitle = file_name;
  2826. openFileName.nMaxFileTitle = MAX_DPATH;
  2827. openFileName.lpfnHook = ofnhook;
  2828. if (initialdir)
  2829. openFileName.lpstrInitialDir = initialdir;
  2830. else
  2831. openFileName.lpstrInitialDir = init_path;
  2832. openFileName.lpstrTitle = szTitle;
  2833. if (multi)
  2834. openFileName.Flags |= OFN_ALLOWMULTISELECT;
  2835. if (flag == 1 || flag == 3 || flag == 5 || flag == 9 || flag == 16 || flag == 24) {
  2836. openFileName.Flags &= ~OFN_FILEMUSTEXIST;
  2837. if (!(result = GetSaveFileName_2 (hDlg, &openFileName, guid)))
  2838. write_log (_T("GetSaveFileNameX() failed, err=%d.\n"), GetLastError ());
  2839. } else {
  2840. if (flag == 11 || flag == 19) {
  2841. openFileName.Flags &= ~OFN_FILEMUSTEXIST;
  2842. }
  2843. if (!(result = GetOpenFileName_2 (hDlg, &openFileName, guid)))
  2844. write_log (_T("GetOpenFileNameX() failed, err=%d.\n"), GetLastError ());
  2845. }
  2846. if (result) {
  2847. previousfilter[flag] = openFileName.nFilterIndex;
  2848. setfilter (flag, previousfilter, filtername);
  2849. }
  2850. memcpy (full_path2, full_path, sizeof full_path);
  2851. memcpy (stored_path, full_path, sizeof stored_path);
  2852. next = 0;
  2853. nextp = full_path2 + openFileName.nFileOffset;
  2854. if (path_out) {
  2855. if (multi) {
  2856. while (nextp[0])
  2857. nextp += _tcslen (nextp) + 1;
  2858. memcpy (path_out, full_path2, (nextp - full_path2 + 1) * sizeof (TCHAR));
  2859. } else {
  2860. _tcscpy (path_out, full_path2);
  2861. }
  2862. }
  2863. nextp = full_path2 + openFileName.nFileOffset;
  2864. if (nextp[_tcslen (nextp) + 1] == 0)
  2865. multi = 0;
  2866. while (result && next >= 0)
  2867. {
  2868. next = -1;
  2869. if (multi) {
  2870. if (nextp[0] == 0)
  2871. break;
  2872. _stprintf (full_path, _T("%s\\%s"), full_path2, nextp);
  2873. nextp += _tcslen (nextp) + 1;
  2874. }
  2875. switch (wParam)
  2876. {
  2877. case IDC_PATH_NAME:
  2878. case IDC_PATH_FILESYS:
  2879. if (flag == 8) {
  2880. if(_tcsstr (full_path, _T("Configurations\\"))) {
  2881. _tcscpy (full_path, init_path);
  2882. _tcscat (full_path, file_name);
  2883. }
  2884. }
  2885. SetDlgItemText (hDlg, wParam, full_path);
  2886. break;
  2887. case IDC_GENLOCKFILESELECT:
  2888. selectgenlock(prefs, hDlg, IDC_GENLOCKFILE, full_path);
  2889. break;
  2890. case IDC_PATH_GEOMETRY:
  2891. SetDlgItemText (hDlg, wParam, full_path);
  2892. break;
  2893. case IDC_CD_SELECT:
  2894. selectcd (prefs, hDlg, 0, IDC_CD_TEXT, full_path);
  2895. break;
  2896. case IDC_DF0:
  2897. case IDC_DF0QQ:
  2898. selectdisk (prefs, hDlg, 0, IDC_DF0TEXT, full_path);
  2899. next = IDC_DF1;
  2900. break;
  2901. case IDC_DF1:
  2902. case IDC_DF1QQ:
  2903. selectdisk (prefs, hDlg, 1, IDC_DF1TEXT, full_path);
  2904. next = IDC_DF2;
  2905. break;
  2906. case IDC_DF2:
  2907. selectdisk (prefs, hDlg, 2, IDC_DF2TEXT, full_path);
  2908. next = IDC_DF3;
  2909. break;
  2910. case IDC_DF3:
  2911. selectdisk (prefs, hDlg, 3, IDC_DF3TEXT, full_path);
  2912. break;
  2913. case IDC_DOSAVESTATE:
  2914. savestate_initsave (full_path, openFileName.nFilterIndex, FALSE, true);
  2915. break;
  2916. case IDC_DOLOADSTATE:
  2917. savestate_initsave (full_path, openFileName.nFilterIndex, FALSE, false);
  2918. break;
  2919. case IDC_CREATE:
  2920. {
  2921. drive_type atype = DRV_NONE;
  2922. int hd = -1;
  2923. TCHAR disk_name[32];
  2924. disk_name[0] = 0; disk_name[31] = 0;
  2925. GetDlgItemText (hDlg, IDC_CREATE_NAME, disk_name, 30);
  2926. getcreatefloppytype(hDlg, &atype, &hd);
  2927. if (disk_creatediskfile (&workprefs, full_path, 0, atype, hd, disk_name, ischecked (hDlg, IDC_FLOPPY_FFS), ischecked (hDlg, IDC_FLOPPY_BOOTABLE), NULL)) {
  2928. fullpath (full_path, sizeof full_path / sizeof (TCHAR));
  2929. DISK_history_add (full_path, -1, HISTORY_FLOPPY, 0);
  2930. }
  2931. }
  2932. break;
  2933. case IDC_CREATE_RAW:
  2934. {
  2935. drive_type atype = DRV_NONE;
  2936. int hd = -1;
  2937. TCHAR disk_name[32];
  2938. disk_name[0] = 0; disk_name[31] = 0;
  2939. GetDlgItemText(hDlg, IDC_CREATE_NAME, disk_name, 30);
  2940. getcreatefloppytype(hDlg, &atype, &hd);
  2941. if (disk_creatediskfile(&workprefs, full_path, 1, atype, hd, disk_name, ischecked(hDlg, IDC_FLOPPY_FFS), ischecked(hDlg, IDC_FLOPPY_BOOTABLE), NULL)) {
  2942. fullpath(full_path, sizeof full_path / sizeof(TCHAR));
  2943. DISK_history_add(full_path, -1, HISTORY_FLOPPY, 0);
  2944. }
  2945. }
  2946. break;
  2947. case IDC_LOAD:
  2948. if (target_cfgfile_load (&workprefs, full_path, CONFIG_TYPE_DEFAULT, 0) == 0) {
  2949. TCHAR szMessage[MAX_DPATH];
  2950. WIN32GUI_LoadUIString (IDS_COULDNOTLOADCONFIG, szMessage, MAX_DPATH);
  2951. pre_gui_message (szMessage);
  2952. } else {
  2953. SetDlgItemText (hDlg, IDC_EDITDESCRIPTION, workprefs.description);
  2954. SetDlgItemText (hDlg, IDC_EDITNAME, full_path);
  2955. }
  2956. break;
  2957. case IDC_SAVE:
  2958. if (cfgfile_can_write(hDlg, full_path)) {
  2959. SetDlgItemText(hDlg, IDC_EDITNAME, full_path);
  2960. cfgfile_save(&workprefs, full_path, 0);
  2961. }
  2962. break;
  2963. case IDC_ROMFILE:
  2964. _tcscpy (workprefs.romfile, full_path);
  2965. fullpath (workprefs.romfile, MAX_DPATH);
  2966. read_kickstart_version(&workprefs);
  2967. break;
  2968. case IDC_ROMFILE2:
  2969. _tcscpy (workprefs.romextfile, full_path);
  2970. fullpath (workprefs.romextfile, MAX_DPATH);
  2971. break;
  2972. case IDC_CUSTOMROMFILE:
  2973. {
  2974. int v = SendDlgItemMessage(hDlg, IDC_CUSTOMROMSELECT, CB_GETCURSEL, 0, 0);
  2975. if (v >= 0 && v < MAX_ROM_BOARDS) {
  2976. struct romboard *rb = &workprefs.romboards[v];
  2977. _tcscpy(rb->lf.loadfile, full_path);
  2978. fullpath(rb->lf.loadfile, MAX_DPATH);
  2979. if (rb->start_address) {
  2980. struct zfile *zf = zfile_fopen(rb->lf.loadfile, _T("rb"));
  2981. if (zf) {
  2982. rb->end_address = rb->start_address + zfile_size(zf);
  2983. rb->end_address = ((rb->end_address + 65535) & ~65535) - 1;
  2984. rb->size = rb->end_address - rb->start_address + 1;
  2985. zfile_fclose(zf);
  2986. }
  2987. }
  2988. }
  2989. break;
  2990. }
  2991. case IDC_FLASHFILE:
  2992. _tcscpy (workprefs.flashfile, full_path);
  2993. fullpath(workprefs.flashfile, MAX_DPATH);
  2994. break;
  2995. case IDC_RTCFILE:
  2996. _tcscpy (workprefs.rtcfile, full_path);
  2997. fullpath(workprefs.rtcfile, MAX_DPATH);
  2998. break;
  2999. case IDC_CARTFILE:
  3000. _tcscpy (workprefs.cartfile, full_path);
  3001. fullpath (workprefs.cartfile, MAX_DPATH);
  3002. break;
  3003. case IDC_SCSIROMFILE:
  3004. {
  3005. int val = gui_get_string_cursor(scsiromselect_table, hDlg, IDC_SCSIROMSELECT);
  3006. if (val != CB_ERR) {
  3007. int index;
  3008. struct boardromconfig *brc;
  3009. brc = get_device_rom_new(&workprefs, expansionroms[scsiromselected].romtype, scsiromselectednum, &index);
  3010. _tcscpy (brc->roms[index].romfile, full_path);
  3011. fullpath (brc->roms[index].romfile, MAX_DPATH);
  3012. }
  3013. break;
  3014. }
  3015. case IDC_CPUBOARDROMFILE:
  3016. {
  3017. int index;
  3018. struct boardromconfig *brc = get_device_rom_new(&workprefs, ROMTYPE_CPUBOARD, 0, &index);
  3019. _tcscpy(brc->roms[index].romfile, full_path);
  3020. fullpath(brc->roms[index].romfile, MAX_DPATH);
  3021. break;
  3022. }
  3023. case IDC_STATEREC_PLAY:
  3024. case IDC_STATEREC_RECORD:
  3025. case IDC_STATEREC_SAVE:
  3026. _tcscpy (workprefs.inprecfile, full_path);
  3027. _tcscpy (workprefs.inprecfile, full_path);
  3028. break;
  3029. }
  3030. if (!nosavepath || 1) {
  3031. if (flag == 0 || flag == 1 || flag == 22) {
  3032. amiga_path = _tcsstr (openFileName.lpstrFile, openFileName.lpstrFileTitle);
  3033. if (amiga_path && amiga_path != openFileName.lpstrFile) {
  3034. *amiga_path = 0;
  3035. setdpath (_T("FloppyPath"), openFileName.lpstrFile);
  3036. }
  3037. } else if (flag == 2 || flag == 3 || flag == 23) {
  3038. amiga_path = _tcsstr (openFileName.lpstrFile, openFileName.lpstrFileTitle);
  3039. if (amiga_path && amiga_path != openFileName.lpstrFile) {
  3040. *amiga_path = 0;
  3041. setdpath (_T("hdfPath"), openFileName.lpstrFile);
  3042. }
  3043. } else if (flag == 17) {
  3044. amiga_path = _tcsstr (openFileName.lpstrFile, openFileName.lpstrFileTitle);
  3045. if (amiga_path && amiga_path != openFileName.lpstrFile) {
  3046. *amiga_path = 0;
  3047. setdpath (_T("CDPath"), openFileName.lpstrFile);
  3048. }
  3049. } else if (flag == 18) {
  3050. amiga_path = _tcsstr (openFileName.lpstrFile, openFileName.lpstrFileTitle);
  3051. if (amiga_path && amiga_path != openFileName.lpstrFile) {
  3052. *amiga_path = 0;
  3053. setdpath (_T("TapePath"), openFileName.lpstrFile);
  3054. }
  3055. } else if (flag == 20) {
  3056. amiga_path = _tcsstr(openFileName.lpstrFile, openFileName.lpstrFileTitle);
  3057. if (amiga_path && amiga_path != openFileName.lpstrFile) {
  3058. *amiga_path = 0;
  3059. setdpath(_T("GenlockImagePath"), openFileName.lpstrFile);
  3060. }
  3061. } else if (flag == 21) {
  3062. amiga_path = _tcsstr(openFileName.lpstrFile, openFileName.lpstrFileTitle);
  3063. if (amiga_path && amiga_path != openFileName.lpstrFile) {
  3064. *amiga_path = 0;
  3065. setdpath(_T("GenlockVideoPath"), openFileName.lpstrFile);
  3066. }
  3067. }
  3068. }
  3069. if (!multi)
  3070. next = -1;
  3071. if (next >= 0)
  3072. wParam = next;
  3073. }
  3074. return result;
  3075. }
  3076. int DiskSelection (HWND hDlg, WPARAM wParam, int flag, struct uae_prefs *prefs, TCHAR *file_in, TCHAR *path_out)
  3077. {
  3078. return DiskSelection_2 (hDlg, wParam, flag, prefs, file_in, path_out, NULL);
  3079. }
  3080. int MultiDiskSelection (HWND hDlg, WPARAM wParam, int flag, struct uae_prefs *prefs, TCHAR *path_out)
  3081. {
  3082. int multi = 0;
  3083. return DiskSelection_2 (hDlg, wParam, flag, prefs, NULL, path_out, &multi);
  3084. }
  3085. static int loopmulti (const TCHAR *s, TCHAR *out)
  3086. {
  3087. static int index;
  3088. if (!out) {
  3089. index = _tcslen (s) + 1;
  3090. return 1;
  3091. }
  3092. if (index < 0)
  3093. return 0;
  3094. if (!s[index]) {
  3095. if (s[_tcslen (s) + 1] == 0) {
  3096. _tcscpy (out, s);
  3097. index = -1;
  3098. return 1;
  3099. }
  3100. return 0;
  3101. }
  3102. _stprintf (out, _T("%s\\%s"), s, s + index);
  3103. index += _tcslen (s + index) + 1;
  3104. return 1;
  3105. }
  3106. static BOOL CreateHardFile (HWND hDlg, uae_s64 hfsize, const TCHAR *dostype, TCHAR *newpath, TCHAR *outpath)
  3107. {
  3108. HANDLE hf;
  3109. int i = 0;
  3110. BOOL result = FALSE;
  3111. LONG highword = 0;
  3112. DWORD ret, written;
  3113. TCHAR init_path[MAX_DPATH] = _T("");
  3114. uae_u32 dt;
  3115. uae_u8 b;
  3116. int sparse, dynamic;
  3117. outpath[0] = 0;
  3118. sparse = 0;
  3119. dynamic = 0;
  3120. dt = 0;
  3121. if (ischecked (hDlg, IDC_HF_SPARSE))
  3122. sparse = 1;
  3123. if (ischecked (hDlg, IDC_HF_DYNAMIC)) {
  3124. dynamic = 1;
  3125. sparse = 0;
  3126. }
  3127. if (!DiskSelection (hDlg, IDC_PATH_NAME, 3, &workprefs, NULL, newpath))
  3128. return FALSE;
  3129. GetDlgItemText (hDlg, IDC_PATH_NAME, init_path, MAX_DPATH);
  3130. if (*init_path && hfsize) {
  3131. if (dynamic) {
  3132. if (!_stscanf (dostype, _T("%x"), &dt))
  3133. dt = 0;
  3134. if (_tcslen (init_path) > 4 && !_tcsicmp (init_path + _tcslen (init_path) - 4, _T(".hdf")))
  3135. _tcscpy (init_path + _tcslen (init_path) - 4, _T(".vhd"));
  3136. result = vhd_create (init_path, hfsize, dt);
  3137. } else {
  3138. SetCursor (LoadCursor (NULL, IDC_WAIT));
  3139. if ((hf = CreateFile (init_path, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL)) != INVALID_HANDLE_VALUE) {
  3140. if (sparse) {
  3141. DWORD ret;
  3142. DeviceIoControl (hf, FSCTL_SET_SPARSE, NULL, 0, NULL, 0, &ret, NULL);
  3143. }
  3144. if (hfsize >= 0x80000000) {
  3145. highword = (DWORD)(hfsize >> 32);
  3146. ret = SetFilePointer (hf, (DWORD)hfsize, &highword, FILE_BEGIN);
  3147. } else {
  3148. ret = SetFilePointer (hf, (DWORD)hfsize, NULL, FILE_BEGIN);
  3149. }
  3150. if (ret == INVALID_SET_FILE_POINTER && GetLastError() != NO_ERROR)
  3151. write_log (_T("SetFilePointer() failure for %s to posn %ud\n"), init_path, hfsize);
  3152. else
  3153. result = SetEndOfFile (hf);
  3154. SetFilePointer (hf, 0, NULL, FILE_BEGIN);
  3155. b = 0;
  3156. WriteFile (hf, &b, 1, &written, NULL);
  3157. WriteFile (hf, &b, 1, &written, NULL);
  3158. WriteFile (hf, &b, 1, &written, NULL);
  3159. WriteFile (hf, &b, 1, &written, NULL);
  3160. if (_stscanf (dostype, _T("%x"), &dt) > 0) {
  3161. SetFilePointer (hf, 0, NULL, FILE_BEGIN);
  3162. b = dt >> 24;
  3163. WriteFile (hf, &b, 1, &written, NULL);
  3164. b = dt >> 16;
  3165. WriteFile (hf, &b, 1, &written, NULL);
  3166. b = dt >> 8;
  3167. WriteFile (hf, &b, 1, &written, NULL);
  3168. b = dt >> 0;
  3169. WriteFile (hf, &b, 1, &written, NULL);
  3170. }
  3171. CloseHandle (hf);
  3172. } else {
  3173. write_log (_T("CreateFile() failed to create %s\n"), init_path);
  3174. }
  3175. SetCursor (LoadCursor (NULL, IDC_ARROW));
  3176. }
  3177. }
  3178. if (!result) {
  3179. TCHAR szMessage[MAX_DPATH];
  3180. TCHAR szTitle[MAX_DPATH];
  3181. WIN32GUI_LoadUIString (IDS_FAILEDHARDFILECREATION, szMessage, MAX_DPATH);
  3182. WIN32GUI_LoadUIString (IDS_CREATIONERROR, szTitle, MAX_DPATH);
  3183. MessageBox (hDlg, szMessage, szTitle, MB_OK | MB_ICONERROR | MB_APPLMODAL | MB_SETFOREGROUND);
  3184. } else {
  3185. _tcscpy (outpath, init_path);
  3186. }
  3187. return result;
  3188. }
  3189. static uae_s64 CalculateHardfileSize(HWND hDlg)
  3190. {
  3191. uae_s64 mbytes = 0;
  3192. TCHAR tmp[100];
  3193. tmp[0] = 0;
  3194. GetDlgItemText(hDlg, IDC_HF_SIZE, tmp, sizeof tmp / sizeof(TCHAR));
  3195. for (int i = 0; i < _tcslen(tmp); i++) {
  3196. if (tmp[i] == ',')
  3197. tmp[i] = '.';
  3198. }
  3199. double v = _tstof(tmp);
  3200. mbytes = (uae_s64)(v * 1024 * 1024);
  3201. mbytes &= ~511;
  3202. if (mbytes <= 0)
  3203. mbytes = 0;
  3204. return mbytes;
  3205. }
  3206. static const TCHAR *nth[] = {
  3207. _T(""), _T("second "), _T("third "), _T("fourth "), _T("fifth "), _T("sixth "), _T("seventh "), _T("eighth "), _T("ninth "), _T("tenth ")
  3208. };
  3209. static void setguititle (HWND phwnd)
  3210. {
  3211. static TCHAR title[200];
  3212. TCHAR title2[1000];
  3213. TCHAR *name;
  3214. static HWND hwnd;
  3215. if (phwnd)
  3216. hwnd = phwnd;
  3217. if (hwnd && !title[0]) {
  3218. GetWindowText (hwnd, title, sizeof title / sizeof (TCHAR));
  3219. if (_tcslen (WINUAEBETA) > 0) {
  3220. _tcscat (title, BetaStr);
  3221. if (_tcslen (WINUAEEXTRA) > 0) {
  3222. _tcscat (title, _T(" "));
  3223. _tcscat (title, WINUAEEXTRA);
  3224. }
  3225. }
  3226. }
  3227. title2[0] = 0;
  3228. name = workprefs.config_window_title;
  3229. if (name && _tcslen (name) > 0) {
  3230. _tcscat (title2, name);
  3231. _tcscat (title2, _T(" - "));
  3232. }
  3233. if (!title2[0]) {
  3234. name = config_filename;
  3235. if (name && _tcslen (name) > 0) {
  3236. _tcscat (title2, _T("["));
  3237. _tcscat (title2, name);
  3238. if (_tcslen(title2) > 4 && !_tcsicmp(title2 + _tcslen(title2) - 4, _T(".uae")))
  3239. title2[_tcslen(title2) - 4] = 0;
  3240. _tcscat (title2, _T("] - "));
  3241. }
  3242. }
  3243. _tcscat (title2, title);
  3244. SetWindowText (hwnd, title2);
  3245. }
  3246. static void GetConfigPath (TCHAR *path, struct ConfigStruct *parent, int noroot)
  3247. {
  3248. if (parent == NULL) {
  3249. path[0] = 0;
  3250. if (!noroot) {
  3251. fetch_path (_T("ConfigurationPath"), path, MAX_DPATH);
  3252. }
  3253. return;
  3254. }
  3255. if (parent) {
  3256. GetConfigPath (path, parent->Parent, noroot);
  3257. _tcsncat (path, parent->Name, MAX_DPATH - _tcslen(path));
  3258. _tcsncat (path, _T("\\"), MAX_DPATH - _tcslen(path));
  3259. }
  3260. }
  3261. void FreeConfigStruct (struct ConfigStruct *config)
  3262. {
  3263. xfree (config);
  3264. }
  3265. struct ConfigStruct *AllocConfigStruct (void)
  3266. {
  3267. struct ConfigStruct *config;
  3268. config = xcalloc (struct ConfigStruct, 1);
  3269. return config;
  3270. }
  3271. static void FreeConfigStore (void)
  3272. {
  3273. for (int i = 0; i < configstoresize; i++) {
  3274. FreeConfigStruct(configstore[i]);
  3275. }
  3276. xfree(configstore);
  3277. configstoresize = configstoreallocated = 0;
  3278. configstore = NULL;
  3279. for (int i = 0; i < categorystoresize; i++) {
  3280. xfree(categorystore[i]);
  3281. }
  3282. xfree(categorystore);
  3283. categorystoresize = 0;
  3284. categorystore = NULL;
  3285. }
  3286. static void sortcategories(void)
  3287. {
  3288. for (int i = 0; i < categorystoresize; i++) {
  3289. for (int j = i + 1; j < categorystoresize; j++) {
  3290. struct CategoryStruct *s1 = categorystore[i];
  3291. struct CategoryStruct *s2 = categorystore[j];
  3292. if (_tcsicmp(s1->category, s2->category) > 0) {
  3293. struct CategoryStruct *s = categorystore[i];
  3294. categorystore[i] = categorystore[j];
  3295. categorystore[j] = s;
  3296. }
  3297. }
  3298. }
  3299. }
  3300. static void addtocategories(const TCHAR *category)
  3301. {
  3302. if (!category[0])
  3303. return;
  3304. bool found = false;
  3305. for (int j = 0; j < categorystoresize; j++) {
  3306. struct CategoryStruct *s = categorystore[j];
  3307. if (!_tcsicmp(category, s->category)) {
  3308. found = true;
  3309. break;
  3310. }
  3311. }
  3312. if (!found) {
  3313. if (categorystore == NULL || categorystoresize == categorystoreallocated) {
  3314. categorystoreallocated += 100;
  3315. categorystore = xrealloc(struct CategoryStruct*, categorystore, categorystoreallocated);
  3316. }
  3317. struct CategoryStruct *s = categorystore[categorystoresize++] = xcalloc(struct CategoryStruct, 1);
  3318. _tcscpy(s->category, category);
  3319. }
  3320. }
  3321. static void getconfigcache (TCHAR *dst, const TCHAR *path)
  3322. {
  3323. _tcscpy (dst, path);
  3324. _tcsncat (dst, _T("configuration.cache"), MAX_DPATH - _tcslen(dst));
  3325. }
  3326. static void deleteconfigcache(void)
  3327. {
  3328. TCHAR path[MAX_DPATH], path2[MAX_DPATH];
  3329. GetConfigPath(path, NULL, FALSE);
  3330. if (!path[0])
  3331. return;
  3332. getconfigcache(path2, path);
  3333. _wunlink(path2);
  3334. }
  3335. static TCHAR *fgetsx (TCHAR *dst, FILE *f)
  3336. {
  3337. TCHAR *s2;
  3338. dst[0] = 0;
  3339. s2 = fgetws (dst, MAX_DPATH, f);
  3340. if (!s2)
  3341. return NULL;
  3342. if (_tcslen (dst) == 0)
  3343. return dst;
  3344. if (dst[_tcslen (dst) - 1] == '\n')
  3345. dst[_tcslen (dst) - 1] = 0;
  3346. if (dst[_tcslen (dst) - 1] == '\r')
  3347. dst[_tcslen (dst) - 1] = 0;
  3348. return dst;
  3349. }
  3350. static const TCHAR configcachever[] = _T("WinUAE Configuration.Cache");
  3351. static void setconfighosthard (struct ConfigStruct *config)
  3352. {
  3353. if (!config->Directory)
  3354. return;
  3355. if (!_tcsicmp (config->Name, CONFIG_HOST))
  3356. config->host = 1;
  3357. if (!_tcsicmp (config->Name, CONFIG_HARDWARE))
  3358. config->hardware = 1;
  3359. }
  3360. static void flushconfigcache (const TCHAR *cachepath)
  3361. {
  3362. FILE *zcache;
  3363. zcache = _tfopen (cachepath, _T("r"));
  3364. if (zcache == NULL)
  3365. return;
  3366. fclose (zcache);
  3367. bool hidden = my_isfilehidden (cachepath);
  3368. my_setfilehidden (cachepath, false);
  3369. zcache = _tfopen (cachepath, _T("w+, ccs=UTF-8"));
  3370. if (zcache)
  3371. fclose (zcache);
  3372. my_setfilehidden (cachepath, hidden);
  3373. write_log (_T("'%s' flushed\n"), cachepath);
  3374. }
  3375. static struct ConfigStruct *readconfigcache (const TCHAR *path)
  3376. {
  3377. FILE *zcache;
  3378. TCHAR cachepath[MAX_DPATH];
  3379. TCHAR buf[MAX_DPATH];
  3380. TCHAR rootpath[MAX_DPATH];
  3381. TCHAR path2[MAX_DPATH], tmp[MAX_DPATH];
  3382. struct ConfigStruct *cs, *first;
  3383. int err;
  3384. int filelines, dirlines, headlines, dirmode, lines;
  3385. TCHAR dirsep = '\\';
  3386. FILETIME t;
  3387. SYSTEMTIME st;
  3388. ULARGE_INTEGER t1, stt, dirtt;
  3389. HANDLE h;
  3390. WIN32_FIND_DATA ffd;
  3391. #if CONFIGCACHE == 0
  3392. return NULL;
  3393. #endif
  3394. err = 0;
  3395. first = NULL;
  3396. getconfigcache (cachepath, path);
  3397. zcache = my_opentext (cachepath);
  3398. if (!zcache)
  3399. return NULL;
  3400. if (!configurationcache) {
  3401. fclose (zcache);
  3402. _wunlink (cachepath);
  3403. return NULL;
  3404. }
  3405. fgetsx (buf, zcache);
  3406. if (feof (zcache))
  3407. goto end;
  3408. if (_tcscmp (buf, configcachever))
  3409. goto end;
  3410. GetFullPathName (path, sizeof path2 / sizeof (TCHAR), path2, NULL);
  3411. _tcscpy (rootpath, path2);
  3412. if (path2[_tcslen (path2) - 1] == '\\' || path2[_tcslen (path2) -1] == '/')
  3413. path2[_tcslen (path2) - 1] = 0;
  3414. h = FindFirstFile (path2, &ffd);
  3415. if (h == INVALID_HANDLE_VALUE)
  3416. goto end;
  3417. FindClose (h);
  3418. memcpy (&dirtt, &ffd.ftLastWriteTime, sizeof (ULARGE_INTEGER));
  3419. fgetsx (buf, zcache);
  3420. headlines = _tstol (buf);
  3421. fgetsx (buf, zcache);
  3422. headlines--;
  3423. dirlines = _tstol (buf);
  3424. fgetsx (buf, zcache);
  3425. headlines--;
  3426. filelines = _tstol (buf);
  3427. fgetsx (buf, zcache);
  3428. t1.QuadPart = _tstoi64 (buf);
  3429. headlines--;
  3430. GetSystemTime (&st);
  3431. SystemTimeToFileTime (&st, &t);
  3432. memcpy (&stt, &t, sizeof (ULARGE_INTEGER));
  3433. if (headlines < 0 || dirlines < 3 || filelines < 3 ||
  3434. t1.QuadPart == 0 || t1.QuadPart > stt.QuadPart || dirtt.QuadPart > t1.QuadPart)
  3435. goto end;
  3436. while (headlines-- > 0)
  3437. fgetsx (buf, zcache);
  3438. fgetsx (buf, zcache);
  3439. if (buf[0] != ';')
  3440. goto end;
  3441. while (fgetsx (buf, zcache)) {
  3442. TCHAR c;
  3443. TCHAR dirpath[MAX_DPATH];
  3444. dirmode = 0;
  3445. if (_tcslen (buf) > 0) {
  3446. c = buf[_tcslen (buf) - 1];
  3447. if (c == '/' || c == '\\') {
  3448. dirmode = 1;
  3449. dirsep = c;
  3450. }
  3451. }
  3452. _tcscpy (dirpath, buf);
  3453. if (dirmode) {
  3454. lines = dirlines;
  3455. } else {
  3456. TCHAR *p;
  3457. lines = filelines;
  3458. p = _tcsrchr (dirpath, dirsep);
  3459. if (p)
  3460. p[0] = 0;
  3461. else
  3462. dirpath[0] = 0;
  3463. }
  3464. lines--;
  3465. cs = AllocConfigStruct ();
  3466. if (configstore == NULL || configstoreallocated == configstoresize) {
  3467. configstoreallocated += 100;
  3468. configstore = xrealloc(struct ConfigStruct*, configstore, configstoreallocated);
  3469. }
  3470. configstore[configstoresize++] = cs;
  3471. if (!first)
  3472. first = cs;
  3473. cs->Directory = dirmode;
  3474. _tcscpy (tmp, path);
  3475. _tcscat (tmp, dirpath);
  3476. _tcscpy (cs->Fullpath, tmp);
  3477. _tcscpy (cs->Path, dirpath);
  3478. fgetsx (tmp, zcache);
  3479. lines--;
  3480. t1.QuadPart = _tstoi64 (tmp);
  3481. if (t1.QuadPart > stt.QuadPart)
  3482. goto end;
  3483. fgetsx (cs->Name, zcache);
  3484. lines--;
  3485. fgetsx (cs->Description, zcache);
  3486. lines--;
  3487. _tcscpy (tmp, cs->Path);
  3488. if (_tcslen (tmp) > 0) {
  3489. TCHAR *p = tmp;
  3490. if (tmp[_tcslen (tmp) - 1] == dirsep) {
  3491. tmp[_tcslen (tmp) - 1] = 0;
  3492. p = _tcsrchr (tmp, dirsep);
  3493. if (p)
  3494. p[1] = 0;
  3495. } else {
  3496. tmp[_tcslen (tmp) + 1] = 0;
  3497. tmp[_tcslen (tmp)] = dirsep;
  3498. }
  3499. if (p) {
  3500. int i;
  3501. for (i = 0; i < configstoresize; i++) {
  3502. struct ConfigStruct *cs2 = configstore[i];
  3503. if (cs2 != cs && !_tcscmp (cs2->Path, tmp) && cs2->Directory) {
  3504. cs->Parent = cs2;
  3505. if (!cs2->Child)
  3506. cs2->Child = cs;
  3507. cs->host = cs2->host;
  3508. cs->hardware = cs2->hardware;
  3509. }
  3510. }
  3511. }
  3512. }
  3513. if (_tcslen (cs->Path) > 0 && !dirmode) {
  3514. _tcscat (cs->Path, _T("\\"));
  3515. _tcscat (cs->Fullpath, _T("\\"));
  3516. }
  3517. if (!dirmode) {
  3518. fgetsx (cs->HardwareLink, zcache);
  3519. lines--;
  3520. fgetsx (cs->HostLink, zcache);
  3521. lines--;
  3522. fgetsx (buf, zcache);
  3523. lines--;
  3524. cs->Type = _tstol (buf);
  3525. if (lines > 0) {
  3526. fgetsx(cs->Artpath, zcache);
  3527. lines--;
  3528. }
  3529. if (lines > 0) {
  3530. fgetsx(cs->Category, zcache);
  3531. addtocategories(cs->Category);
  3532. lines--;
  3533. }
  3534. if (lines > 0) {
  3535. fgetsx(cs->Tags, zcache);
  3536. lines--;
  3537. }
  3538. }
  3539. setconfighosthard (cs);
  3540. if (lines < 0)
  3541. goto end;
  3542. while (lines-- > 0)
  3543. fgetsx (tmp, zcache);
  3544. fgetsx (tmp, zcache);
  3545. if (tmp[0] != ';')
  3546. goto end;
  3547. }
  3548. end:
  3549. if (!feof (zcache))
  3550. err = 1;
  3551. fclose (zcache);
  3552. if (err || first == NULL) {
  3553. write_log (_T("'%s' load failed\n"), cachepath);
  3554. flushconfigcache (cachepath);
  3555. FreeConfigStore ();
  3556. return NULL;
  3557. } else {
  3558. write_log (_T("'%s' loaded successfully\n"), cachepath);
  3559. }
  3560. return first;
  3561. }
  3562. static void writeconfigcacheentry (FILE *zcache, const TCHAR *relpath, struct ConfigStruct *cs)
  3563. {
  3564. TCHAR path2[MAX_DPATH];
  3565. TCHAR lf = 10;
  3566. TCHAR el[] = _T(";\n");
  3567. TCHAR *p;
  3568. ULARGE_INTEGER li;
  3569. GetFullPathName (cs->Fullpath, sizeof path2 / sizeof (TCHAR), path2, NULL);
  3570. if (_tcslen (path2) < _tcslen (relpath))
  3571. return;
  3572. if (_tcsncmp (path2, relpath, _tcslen (relpath)))
  3573. return;
  3574. p = path2 + _tcslen (relpath);
  3575. if (!cs->Directory)
  3576. _tcscat (p, cs->Name);
  3577. fwrite (p, _tcslen (p), sizeof (TCHAR), zcache);
  3578. fwrite (&lf, 1, sizeof (TCHAR), zcache);
  3579. memcpy (&li, &cs->t, sizeof (ULARGE_INTEGER));
  3580. _stprintf (path2, _T("%I64u"), li.QuadPart);
  3581. fwrite (path2, _tcslen (path2), sizeof (TCHAR), zcache);
  3582. fwrite (&lf, 1, sizeof (TCHAR), zcache);
  3583. fwrite (cs->Name, _tcslen (cs->Name), sizeof (TCHAR), zcache);
  3584. fwrite (&lf, 1, sizeof (TCHAR), zcache);
  3585. fwrite (cs->Description, _tcslen (cs->Description), sizeof (TCHAR), zcache);
  3586. fwrite (&lf, 1, sizeof (TCHAR), zcache);
  3587. if (!cs->Directory) {
  3588. fwrite (cs->HardwareLink, _tcslen (cs->HardwareLink), sizeof (TCHAR), zcache);
  3589. fwrite (&lf, 1, sizeof (TCHAR), zcache);
  3590. fwrite (cs->HostLink, _tcslen (cs->HostLink), sizeof (TCHAR), zcache);
  3591. fwrite (&lf, 1, sizeof (TCHAR), zcache);
  3592. _stprintf (path2, _T("%d"), cs->Type);
  3593. fwrite (path2, _tcslen (path2), sizeof (TCHAR), zcache);
  3594. fwrite (&lf, 1, sizeof (TCHAR), zcache);
  3595. fwrite(cs->Artpath, _tcslen(cs->Artpath), sizeof(TCHAR), zcache);
  3596. fwrite(&lf, 1, sizeof(TCHAR), zcache);
  3597. fwrite(cs->Category, _tcslen(cs->Category), sizeof(TCHAR), zcache);
  3598. fwrite(&lf, 1, sizeof(TCHAR), zcache);
  3599. fwrite(cs->Tags, _tcslen(cs->Tags), sizeof(TCHAR), zcache);
  3600. fwrite(&lf, 1, sizeof(TCHAR), zcache);
  3601. }
  3602. fwrite (el, _tcslen (el), sizeof (TCHAR), zcache);
  3603. }
  3604. static void writeconfigcacherec (FILE *zcache, const TCHAR *relpath, struct ConfigStruct *cs)
  3605. {
  3606. if (!cs->Directory)
  3607. return;
  3608. writeconfigcacheentry (zcache, relpath, cs);
  3609. for (int i = 0; i < configstoresize; i++) {
  3610. struct ConfigStruct *cs2 = configstore[i];
  3611. if (cs2->Parent == cs)
  3612. writeconfigcacherec (zcache, relpath, cs2);
  3613. }
  3614. }
  3615. static void writeconfigcache (const TCHAR *path)
  3616. {
  3617. TCHAR lf = 10;
  3618. FILE *zcache;
  3619. TCHAR cachepath[MAX_DPATH];
  3620. TCHAR path2[MAX_DPATH];
  3621. FILETIME t;
  3622. ULARGE_INTEGER ul;
  3623. SYSTEMTIME st;
  3624. if (!configurationcache)
  3625. return;
  3626. getconfigcache (cachepath, path);
  3627. bool hidden = my_isfilehidden (cachepath);
  3628. my_setfilehidden (cachepath, false);
  3629. zcache = _tfopen (cachepath, _T("w, ccs=UTF-8"));
  3630. if (!zcache)
  3631. return;
  3632. t.dwHighDateTime = t.dwLowDateTime = 0;
  3633. GetSystemTime (&st);
  3634. SystemTimeToFileTime (&st, &t);
  3635. fwrite (configcachever, _tcslen (configcachever), sizeof (TCHAR), zcache);
  3636. fwrite (&lf, 1, sizeof (TCHAR), zcache);
  3637. ul.HighPart = t.dwHighDateTime;
  3638. ul.LowPart = t.dwLowDateTime;
  3639. _stprintf (path2, _T("3\n4\n10\n%I64u\n;\n"), ul.QuadPart);
  3640. fwrite (path2, _tcslen (path2), sizeof (TCHAR), zcache);
  3641. GetFullPathName (path, sizeof path2 / sizeof (TCHAR), path2, NULL);
  3642. for (int i = 0; i < configstoresize; i++) {
  3643. struct ConfigStruct *cs = configstore[i];
  3644. if (cs->Directory && cs->Parent == NULL)
  3645. writeconfigcacherec (zcache, path2, cs);
  3646. }
  3647. for (int i = 0; i < configstoresize; i++) {
  3648. struct ConfigStruct *cs = configstore[i];
  3649. if (!cs->Directory)
  3650. writeconfigcacheentry (zcache, path2, cs);
  3651. }
  3652. fclose (zcache);
  3653. my_setfilehidden (cachepath, hidden);
  3654. write_log (_T("'%s' created\n"), cachepath);
  3655. }
  3656. static struct ConfigStruct *GetConfigs (struct ConfigStruct *configparent, int usedirs, int *level, int flushcache)
  3657. {
  3658. DWORD num_bytes = 0;
  3659. TCHAR path[MAX_DPATH];
  3660. TCHAR path2[MAX_DPATH];
  3661. TCHAR shortpath[MAX_DPATH];
  3662. WIN32_FIND_DATA find_data;
  3663. struct ConfigStruct *config, *first;
  3664. HANDLE handle;
  3665. if (*level == 0)
  3666. FreeConfigStore ();
  3667. first = NULL;
  3668. GetConfigPath (path, configparent, FALSE);
  3669. GetConfigPath (shortpath, configparent, TRUE);
  3670. _tcscpy (path2, path);
  3671. _tcsncat (path2, _T("*.*"), MAX_DPATH - _tcslen(path2));
  3672. if (*level == 0) {
  3673. if (flushcache) {
  3674. TCHAR cachepath[MAX_DPATH];
  3675. getconfigcache (cachepath, path);
  3676. flushconfigcache (cachepath);
  3677. }
  3678. first = readconfigcache (path);
  3679. sortcategories();
  3680. if (first)
  3681. return first;
  3682. }
  3683. handle = FindFirstFile (path2, &find_data);
  3684. if (handle == INVALID_HANDLE_VALUE) {
  3685. #ifndef SINGLEFILE
  3686. // Either the directory has no .CFG files, or doesn't exist.
  3687. // Create the directory, even if it already exists. No harm, and don't check return codes, because
  3688. // we may be doing this on a read-only media like CD-ROM.
  3689. if (configparent == NULL) {
  3690. GetConfigPath (path, NULL, FALSE);
  3691. CreateDirectory (path, NULL);
  3692. }
  3693. #endif
  3694. return NULL;
  3695. }
  3696. for (;;) {
  3697. config = NULL;
  3698. if (_tcscmp (find_data.cFileName, _T(".")) && _tcscmp (find_data.cFileName, _T(".."))) {
  3699. int ok = 0;
  3700. config = AllocConfigStruct ();
  3701. _tcscpy (config->Path, shortpath);
  3702. _tcscpy (config->Fullpath, path);
  3703. memcpy (&config->t, &find_data.ftLastWriteTime, sizeof (FILETIME));
  3704. if ((find_data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) && usedirs) {
  3705. if ((*level) < 2) {
  3706. struct ConfigStruct *child;
  3707. _tcscpy (config->Name, find_data.cFileName);
  3708. _tcscpy (config->Path, shortpath);
  3709. _tcscat (config->Path, config->Name);
  3710. _tcscat (config->Path, _T("\\"));
  3711. _tcscpy (config->Fullpath, path);
  3712. _tcscat (config->Fullpath, config->Name);
  3713. _tcscat (config->Fullpath, _T("\\"));
  3714. config->Directory = 1;
  3715. (*level)++;
  3716. config->Parent = configparent;
  3717. setconfighosthard (config);
  3718. child = GetConfigs (config, usedirs, level, FALSE);
  3719. (*level)--;
  3720. if (child)
  3721. config->Child = child;
  3722. ok = 1;
  3723. }
  3724. } else if (!(find_data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)) {
  3725. TCHAR path3[MAX_DPATH];
  3726. if (_tcslen (find_data.cFileName) > 4 && !strcasecmp (find_data.cFileName + _tcslen (find_data.cFileName) - 4, _T(".uae"))) {
  3727. _tcscpy (path3, path);
  3728. _tcsncat (path3, find_data.cFileName, MAX_DPATH - _tcslen(path3));
  3729. config->Artpath[0] = 0;
  3730. struct uae_prefs *p = cfgfile_open(path3, &config->Type);
  3731. if (p) {
  3732. cfgfile_get_description(p, NULL, config->Description, config->Category, config->Tags, config->HostLink, config->HardwareLink, NULL);
  3733. _tcscpy(config->Name, find_data.cFileName);
  3734. if (artcache) {
  3735. cfgfile_detect_art(p, config->Artpath);
  3736. }
  3737. addtocategories(config->Category);
  3738. cfgfile_close(p);
  3739. ok = 1;
  3740. }
  3741. }
  3742. }
  3743. if (!ok) {
  3744. FreeConfigStruct (config);
  3745. config = NULL;
  3746. }
  3747. }
  3748. if (config) {
  3749. if (configparent) {
  3750. config->host = configparent->host;
  3751. config->hardware = configparent->hardware;
  3752. }
  3753. config->Parent = configparent;
  3754. if (configstore == NULL || configstoreallocated == configstoresize) {
  3755. configstoreallocated += 100;
  3756. configstore = xrealloc(struct ConfigStruct*, configstore, configstoreallocated);
  3757. }
  3758. configstore[configstoresize++] = config;
  3759. if (first == NULL)
  3760. first = config;
  3761. }
  3762. if (FindNextFile (handle, &find_data) == 0) {
  3763. FindClose(handle);
  3764. break;
  3765. }
  3766. }
  3767. if (*level == 0 && CONFIGCACHE)
  3768. writeconfigcache (path);
  3769. sortcategories();
  3770. return first;
  3771. }
  3772. static struct ConfigStruct *CreateConfigStore (struct ConfigStruct *oldconfig, int flushcache)
  3773. {
  3774. int level;
  3775. TCHAR path[MAX_DPATH], name[MAX_DPATH];
  3776. struct ConfigStruct *cs;
  3777. if (oldconfig) {
  3778. _tcscpy (path, oldconfig->Path);
  3779. _tcscpy (name, oldconfig->Name);
  3780. }
  3781. level = 0;
  3782. GetConfigs (NULL, 1, &level, flushcache);
  3783. if (oldconfig) {
  3784. for (int i = 0; i < configstoresize; i++) {
  3785. cs = configstore[i];
  3786. if (!cs->Directory && !_tcscmp (path, cs->Path) && !_tcscmp (name, cs->Name))
  3787. return cs;
  3788. }
  3789. }
  3790. return 0;
  3791. }
  3792. static TCHAR *HandleConfiguration (HWND hDlg, int flag, struct ConfigStruct *config, TCHAR *newpath)
  3793. {
  3794. TCHAR name[MAX_DPATH], desc[MAX_DPATH];
  3795. TCHAR path[MAX_DPATH];
  3796. static TCHAR full_path[MAX_DPATH];
  3797. int ok = 1;
  3798. bool absolutepath = false;
  3799. full_path[0] = 0;
  3800. name[0] = 0;
  3801. desc[0] = 0;
  3802. config_pathfilename[0] = 0;
  3803. GetDlgItemText (hDlg, IDC_EDITNAME, name, MAX_DPATH);
  3804. if ((name[0] == '\\' && name[1] == '\\') || (_istalpha(name[0]) && name[1] == ':'))
  3805. absolutepath = true;
  3806. _tcscpy (config_filename, name);
  3807. if (flag == CONFIG_SAVE_FULL || flag == CONFIG_SAVE) {
  3808. if (_tcslen (name) < 4 || strcasecmp (name + _tcslen (name) - 4, _T(".uae"))) {
  3809. _tcscat (name, _T(".uae"));
  3810. SetDlgItemText (hDlg, IDC_EDITNAME, name);
  3811. }
  3812. if (config && !absolutepath)
  3813. _tcscpy (config->Name, name);
  3814. }
  3815. GetDlgItemText (hDlg, IDC_EDITDESCRIPTION, desc, MAX_DPATH);
  3816. if (config) {
  3817. _tcscpy (path, config->Fullpath);
  3818. _tcscat(config_pathfilename, config->Path);
  3819. _tcscat(config_pathfilename, config->Name);
  3820. _tcsncat(path, name, MAX_DPATH - _tcslen(path));
  3821. } else {
  3822. if (absolutepath) {
  3823. _tcscpy(path, name);
  3824. } else {
  3825. fetch_configurationpath(path, sizeof(path) / sizeof(TCHAR));
  3826. _tcsncat(path, name, MAX_DPATH - _tcslen(path));
  3827. }
  3828. TCHAR fname[MAX_DPATH];
  3829. getfilepart(fname, sizeof fname / sizeof(TCHAR), name);
  3830. SetDlgItemText(hDlg, IDC_EDITNAME, fname);
  3831. }
  3832. _tcscpy (full_path, path);
  3833. if (!config_pathfilename[0]) {
  3834. _tcscat(config_pathfilename, full_path);
  3835. }
  3836. switch (flag)
  3837. {
  3838. case CONFIG_SAVE_FULL:
  3839. ok = DiskSelection(hDlg, IDC_SAVE, 5, &workprefs, NULL, newpath);
  3840. GetDlgItemText (hDlg, IDC_EDITNAME, name, MAX_DPATH);
  3841. _tcscpy(config_filename, name);
  3842. _tcscpy(config_pathfilename, name);
  3843. break;
  3844. case CONFIG_LOAD_FULL:
  3845. if ((ok = DiskSelection(hDlg, IDC_LOAD, 4, &workprefs, NULL, newpath))) {
  3846. EnableWindow(GetDlgItem (hDlg, IDC_VIEWINFO), workprefs.info[0]);
  3847. GetDlgItemText (hDlg, IDC_EDITNAME, name, MAX_DPATH);
  3848. _tcscpy(config_filename, name);
  3849. _tcscpy(config_pathfilename, name);
  3850. }
  3851. break;
  3852. case CONFIG_SAVE:
  3853. if (_tcslen (name) == 0 || _tcscmp (name, _T(".uae")) == 0) {
  3854. TCHAR szMessage[MAX_DPATH];
  3855. WIN32GUI_LoadUIString(IDS_MUSTENTERNAME, szMessage, MAX_DPATH);
  3856. pre_gui_message (szMessage);
  3857. } else if (cfgfile_can_write(hDlg, path)) {
  3858. _tcscpy (workprefs.description, desc);
  3859. cfgfile_save (&workprefs, path, configtypepanel);
  3860. }
  3861. break;
  3862. case CONFIG_LOAD:
  3863. if (_tcslen (name) == 0) {
  3864. TCHAR szMessage[MAX_DPATH];
  3865. WIN32GUI_LoadUIString (IDS_MUSTSELECTCONFIG, szMessage, MAX_DPATH);
  3866. pre_gui_message (szMessage);
  3867. } else {
  3868. if (target_cfgfile_load (&workprefs, path, configtypepanel, 0) == 0) {
  3869. TCHAR szMessage[MAX_DPATH];
  3870. WIN32GUI_LoadUIString (IDS_COULDNOTLOADCONFIG, szMessage, MAX_DPATH);
  3871. pre_gui_message (szMessage);
  3872. config_filename[0] = 0;
  3873. ok = 0;
  3874. } else {
  3875. ew (hDlg, IDC_VIEWINFO, workprefs.info[0]);
  3876. }
  3877. }
  3878. break;
  3879. case CONFIG_DELETE:
  3880. {
  3881. TCHAR szMessage[MAX_DPATH];
  3882. TCHAR szTitle[MAX_DPATH];
  3883. TCHAR msg[MAX_DPATH];
  3884. WIN32GUI_LoadUIString(IDS_DELETECONFIGTITLE, szTitle, MAX_DPATH);
  3885. ok = 0;
  3886. if (name[0] == 0) {
  3887. if (config && config->Fullpath[0]) {
  3888. // directory selected
  3889. bool allowdelete = false;
  3890. TCHAR fp[MAX_DPATH];
  3891. _tcscpy(fp, config->Fullpath);
  3892. _tcscat(fp, _T("*"));
  3893. WIN32_FIND_DATA fd;
  3894. HANDLE h = FindFirstFile(fp, &fd);
  3895. if (h != INVALID_HANDLE_VALUE) {
  3896. allowdelete = true;
  3897. for (;;) {
  3898. if (fd.cFileName[0] != '.' || !(fd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)) {
  3899. allowdelete = false;
  3900. }
  3901. if (!FindNextFile(h, &fd))
  3902. break;
  3903. }
  3904. FindClose(h);
  3905. }
  3906. if (allowdelete) {
  3907. WIN32GUI_LoadUIString(IDS_DELETECONFIGDIRCONFIRMATION, szMessage, MAX_DPATH);
  3908. TCHAR fp[MAX_DPATH];
  3909. _tcscpy(fp, config->Fullpath);
  3910. fp[_tcslen(fp) - 1] = 0;
  3911. _stprintf(msg, szMessage, fp);
  3912. if (MessageBox(hDlg, msg, szTitle,
  3913. MB_YESNO | MB_ICONWARNING | MB_APPLMODAL | MB_SETFOREGROUND) == IDYES) {
  3914. if (RemoveDirectory(fp)) {
  3915. write_log(_T("deleted config directory '%s'\n"), fp);
  3916. config_filename[0] = 0;
  3917. ok = 1;
  3918. }
  3919. }
  3920. } else {
  3921. WIN32GUI_LoadUIString(IDS_DELETECONFIGDIRNOTEMPTY, szMessage, MAX_DPATH);
  3922. MessageBox(hDlg, szMessage, szTitle, MB_OK | MB_ICONWARNING | MB_APPLMODAL | MB_SETFOREGROUND);
  3923. }
  3924. } else {
  3925. TCHAR szMessage[MAX_DPATH];
  3926. WIN32GUI_LoadUIString(IDS_MUSTSELECTCONFIGFORDELETE, szMessage, MAX_DPATH);
  3927. pre_gui_message(szMessage);
  3928. }
  3929. } else {
  3930. // config file selected
  3931. WIN32GUI_LoadUIString(IDS_DELETECONFIGCONFIRMATION, szMessage, MAX_DPATH);
  3932. _stprintf(msg, szMessage, name);
  3933. if (MessageBox(hDlg, msg, szTitle,
  3934. MB_YESNO | MB_ICONWARNING | MB_APPLMODAL | MB_SETFOREGROUND) == IDYES) {
  3935. cfgfile_backup(path);
  3936. if (DeleteFile(path)) {
  3937. write_log(_T("deleted config '%s'\n"), path);
  3938. config_filename[0] = 0;
  3939. ok = 1;
  3940. } else {
  3941. write_log(_T("deleted config '%s' returned %x\n"), path, GetLastError());
  3942. if (!my_existsfile(path)) {
  3943. write_log(_T("deleted config '%s'\n"), path);
  3944. config_filename[0] = 0;
  3945. ok = 1;
  3946. }
  3947. }
  3948. }
  3949. }
  3950. config_pathfilename[0] = 0;
  3951. }
  3952. break;
  3953. }
  3954. setguititle (NULL);
  3955. return ok ? full_path : NULL;
  3956. }
  3957. static int disk_in_drive (int entry)
  3958. {
  3959. int i;
  3960. for (i = 0; i < 4; i++) {
  3961. if (_tcslen (workprefs.dfxlist[entry]) > 0 && !_tcscmp (workprefs.dfxlist[entry], workprefs.floppyslots[i].df))
  3962. return i;
  3963. }
  3964. return -1;
  3965. }
  3966. static int disk_swap (int entry, int mode)
  3967. {
  3968. int drv, i, drvs[4] = { -1, -1, -1, -1 };
  3969. for (i = 0; i < MAX_SPARE_DRIVES; i++) {
  3970. drv = disk_in_drive (i);
  3971. if (drv >= 0)
  3972. drvs[drv] = i;
  3973. }
  3974. if ((drv = disk_in_drive (entry)) >= 0) {
  3975. if (mode < 0) {
  3976. workprefs.floppyslots[drv].df[0] = 0;
  3977. return 1;
  3978. }
  3979. if (_tcscmp (workprefs.floppyslots[drv].df, currprefs.floppyslots[drv].df)) {
  3980. _tcscpy (workprefs.floppyslots[drv].df, currprefs.floppyslots[drv].df);
  3981. disk_insert (drv, workprefs.floppyslots[drv].df);
  3982. } else {
  3983. workprefs.floppyslots[drv].df[0] = 0;
  3984. }
  3985. if (drvs[0] < 0 || drvs[1] < 0 || drvs[2] < 0 || drvs[3] < 0) {
  3986. drv++;
  3987. while (drv < 4 && drvs[drv] >= 0)
  3988. drv++;
  3989. if (drv < 4 && workprefs.floppyslots[drv].dfxtype >= 0) {
  3990. _tcscpy (workprefs.floppyslots[drv].df, workprefs.dfxlist[entry]);
  3991. disk_insert (drv, workprefs.floppyslots[drv].df);
  3992. }
  3993. }
  3994. return 1;
  3995. }
  3996. for (i = 0; i < 4; i++) {
  3997. if (drvs[i] < 0 && workprefs.floppyslots[i].dfxtype >= 0) {
  3998. _tcscpy (workprefs.floppyslots[i].df, workprefs.dfxlist[entry]);
  3999. disk_insert (i, workprefs.floppyslots[i].df);
  4000. return 1;
  4001. }
  4002. }
  4003. _tcscpy (workprefs.floppyslots[0].df, workprefs.dfxlist[entry]);
  4004. disk_insert (0, workprefs.floppyslots[0].df);
  4005. return 1;
  4006. }
  4007. static int input_selected_device = -1;
  4008. static int input_selected_widget, input_total_devices;
  4009. static int input_selected_event, input_selected_sub_num;
  4010. static int input_copy_from;
  4011. struct remapcustoms_s
  4012. {
  4013. uae_u64 flags;
  4014. uae_u64 mask;
  4015. const TCHAR *name;
  4016. };
  4017. static struct remapcustoms_s remapcustoms[] =
  4018. {
  4019. { 0, IDEV_MAPPED_AUTOFIRE_SET | IDEV_MAPPED_TOGGLE | IDEV_MAPPED_INVERTTOGGLE,
  4020. NULL },
  4021. { IDEV_MAPPED_AUTOFIRE_SET, IDEV_MAPPED_AUTOFIRE_SET | IDEV_MAPPED_TOGGLE | IDEV_MAPPED_INVERTTOGGLE,
  4022. NULL },
  4023. { IDEV_MAPPED_AUTOFIRE_SET | IDEV_MAPPED_TOGGLE, IDEV_MAPPED_AUTOFIRE_SET | IDEV_MAPPED_TOGGLE | IDEV_MAPPED_INVERTTOGGLE,
  4024. NULL },
  4025. { IDEV_MAPPED_AUTOFIRE_SET | IDEV_MAPPED_INVERTTOGGLE, IDEV_MAPPED_AUTOFIRE_SET | IDEV_MAPPED_TOGGLE | IDEV_MAPPED_INVERTTOGGLE,
  4026. NULL },
  4027. { NULL }
  4028. };
  4029. static void getqualifiername (TCHAR *p, uae_u64 mask)
  4030. {
  4031. *p = 0;
  4032. if (mask == IDEV_MAPPED_QUALIFIER_SPECIAL) {
  4033. _tcscpy (p, _T("*"));
  4034. } else if (mask == (IDEV_MAPPED_QUALIFIER_SPECIAL << 1)) {
  4035. _tcscpy (p, _T("* [R]"));
  4036. } else if (mask == IDEV_MAPPED_QUALIFIER_SHIFT) {
  4037. _tcscpy (p, _T("Shift"));
  4038. } else if (mask == (IDEV_MAPPED_QUALIFIER_SHIFT << 1)) {
  4039. _tcscpy (p, _T("Shift [R]"));
  4040. } else if (mask == IDEV_MAPPED_QUALIFIER_CONTROL) {
  4041. _tcscpy (p, _T("Ctrl"));
  4042. } else if (mask == (IDEV_MAPPED_QUALIFIER_CONTROL << 1)) {
  4043. _tcscpy (p, _T("Ctrl [R]"));
  4044. } else if (mask == IDEV_MAPPED_QUALIFIER_ALT) {
  4045. _tcscpy (p, _T("Alt"));
  4046. } else if (mask == (IDEV_MAPPED_QUALIFIER_ALT << 1)) {
  4047. _tcscpy (p, _T("Alt [R]"));
  4048. } else if (mask == IDEV_MAPPED_QUALIFIER_WIN) {
  4049. _tcscpy (p, _T("Win"));
  4050. } else if (mask == (IDEV_MAPPED_QUALIFIER_WIN << 1)) {
  4051. _tcscpy (p, _T("Win [R]"));
  4052. } else {
  4053. int j;
  4054. uae_u64 i;
  4055. for (i = IDEV_MAPPED_QUALIFIER1, j = 0; i <= (IDEV_MAPPED_QUALIFIER8 << 1); i <<= 1, j++) {
  4056. if (i == mask) {
  4057. _stprintf (p, _T("%d%s"), j / 2 + 1, (j & 1) ? _T(" [R]") : _T(""));
  4058. }
  4059. }
  4060. }
  4061. }
  4062. static int input_get_lv_index(HWND list, int index)
  4063. {
  4064. LVFINDINFO plvfi = { 0 };
  4065. plvfi.flags = LVFI_PARAM;
  4066. plvfi.lParam = index;
  4067. return ListView_FindItem(list, -1, &plvfi);
  4068. }
  4069. static void set_lventry_input (HWND list, int index)
  4070. {
  4071. int i, sub, port;
  4072. TCHAR name[256];
  4073. TCHAR custom[MAX_DPATH];
  4074. TCHAR af[32], toggle[32], invert[32];
  4075. uae_u64 flags;
  4076. int itemindex = input_get_lv_index(list, index);
  4077. inputdevice_get_mapping (input_selected_device, index, &flags, &port, name, custom, input_selected_sub_num);
  4078. if (flags & IDEV_MAPPED_AUTOFIRE_SET) {
  4079. if (flags & IDEV_MAPPED_INVERTTOGGLE)
  4080. WIN32GUI_LoadUIString (IDS_ON, af, sizeof af / sizeof (TCHAR));
  4081. else
  4082. WIN32GUI_LoadUIString (IDS_YES, af, sizeof af / sizeof (TCHAR));
  4083. } else if (flags & IDEV_MAPPED_AUTOFIRE_POSSIBLE) {
  4084. WIN32GUI_LoadUIString (IDS_NO, af, sizeof af / sizeof (TCHAR));
  4085. } else {
  4086. _tcscpy (af, _T("-"));
  4087. }
  4088. if (flags & IDEV_MAPPED_TOGGLE) {
  4089. WIN32GUI_LoadUIString (IDS_YES, toggle, sizeof toggle / sizeof (TCHAR));
  4090. inputdevice_get_mapping(input_selected_device, index, &flags, &port, name, custom, input_selected_sub_num);
  4091. } else if (flags & IDEV_MAPPED_AUTOFIRE_POSSIBLE)
  4092. WIN32GUI_LoadUIString (IDS_NO, toggle, sizeof toggle / sizeof (TCHAR));
  4093. else
  4094. _tcscpy (toggle, _T("-"));
  4095. if (port > 0) {
  4096. TCHAR tmp[256];
  4097. _tcscpy (tmp, name);
  4098. _stprintf (name, _T("[PORT%d] %s"), port, tmp);
  4099. }
  4100. _tcscpy (invert, _T("-"));
  4101. if (flags & IDEV_MAPPED_INVERT)
  4102. WIN32GUI_LoadUIString (IDS_YES, invert, sizeof invert / sizeof (TCHAR));
  4103. if (flags & IDEV_MAPPED_SET_ONOFF) {
  4104. _tcscat (name, _T(" ("));
  4105. TCHAR val[32];
  4106. if ((flags & (IDEV_MAPPED_SET_ONOFF_VAL1 | IDEV_MAPPED_SET_ONOFF_VAL2)) == (IDEV_MAPPED_SET_ONOFF_VAL1 | IDEV_MAPPED_SET_ONOFF_VAL2)) {
  4107. _tcscpy(val, _T("onoff"));
  4108. } else if (flags & IDEV_MAPPED_SET_ONOFF_VAL2) {
  4109. _tcscpy(val, _T("press"));
  4110. } else if (flags & IDEV_MAPPED_SET_ONOFF_VAL1) {
  4111. WIN32GUI_LoadUIString (IDS_ON, val, sizeof val / sizeof (TCHAR));
  4112. } else {
  4113. WIN32GUI_LoadUIString (IDS_OFF, val, sizeof val / sizeof (TCHAR));
  4114. }
  4115. _tcscat (name, val);
  4116. _tcscat (name, _T(")"));
  4117. }
  4118. ListView_SetItemText (list, itemindex, 1, custom[0] ? custom : name);
  4119. ListView_SetItemText (list, itemindex, 2, af);
  4120. ListView_SetItemText (list, itemindex, 3, toggle);
  4121. ListView_SetItemText (list, itemindex, 4, invert);
  4122. _tcscpy (name, _T("-"));
  4123. if (flags & IDEV_MAPPED_QUALIFIER_MASK) {
  4124. TCHAR *p;
  4125. p = name;
  4126. for (i = 0; i < MAX_INPUT_QUALIFIERS * 2; i++) {
  4127. uae_u64 mask = IDEV_MAPPED_QUALIFIER1 << i;
  4128. if (flags & mask) {
  4129. if (p != name)
  4130. *p++ = ',';
  4131. getqualifiername (p, mask);
  4132. p += _tcslen (p);
  4133. }
  4134. }
  4135. }
  4136. ListView_SetItemText (list, itemindex, 5, name);
  4137. sub = 0;
  4138. for (i = 0; i < MAX_INPUT_SUB_EVENT; i++) {
  4139. if (inputdevice_get_mapping (input_selected_device, index, &flags, NULL, name, custom, i) || custom[0])
  4140. sub++;
  4141. }
  4142. _stprintf (name, _T("%d"), sub);
  4143. ListView_SetItemText (list, itemindex, 6, name);
  4144. }
  4145. static void update_listview_input (HWND hDlg)
  4146. {
  4147. int i;
  4148. if (!input_total_devices)
  4149. return;
  4150. for (i = 0; i < inputdevice_get_widget_num(input_selected_device); i++) {
  4151. set_lventry_input(GetDlgItem(hDlg, IDC_INPUTLIST), i);
  4152. }
  4153. }
  4154. static int inputmap_port = -1, inputmap_port_remap = -1;
  4155. static int inputmap_groupindex[MAX_COMPA_INPUTLIST + 1];
  4156. static int inputmap_handle (HWND list, int currentdevnum, int currentwidgetnum,
  4157. int *inputmap_portp, int *inputmap_indexp,
  4158. int state, int *inputmap_itemindexp, int deleteindex, uae_u64 flags_or, uae_u64 flags_and, uae_u64 *inputmap_flagsp)
  4159. {
  4160. int cntitem, cntgroup, portnum;
  4161. int mode;
  4162. const int *axistable;
  4163. bool found2 = false;
  4164. for (portnum = 0; portnum < 4; portnum++) {
  4165. if (list)
  4166. portnum = inputmap_port;
  4167. cntitem = 1;
  4168. cntgroup = 1;
  4169. int events[MAX_COMPA_INPUTLIST];
  4170. if (inputdevice_get_compatibility_input (&workprefs, portnum, &mode, events, &axistable) > 0) {
  4171. int evtnum;
  4172. for (int i = 0; (evtnum = events[i]) >= 0; i++) {
  4173. const struct inputevent *evt = inputdevice_get_eventinfo (evtnum);
  4174. LV_ITEM lvstruct = { 0 };
  4175. int devnum;
  4176. int status;
  4177. TCHAR name[256];
  4178. const int *atp = axistable;
  4179. int atpidx;
  4180. int item;
  4181. bool found = false;
  4182. uae_u64 flags;
  4183. if (list) {
  4184. LVGROUP group = { 0 };
  4185. group.cbSize = sizeof (LVGROUP);
  4186. group.mask = LVGF_HEADER | LVGF_GROUPID;
  4187. group.pszHeader = (TCHAR*)evt->name;
  4188. group.iGroupId = cntgroup;
  4189. ListView_InsertGroup (list, -1, &group);
  4190. lvstruct.mask = LVIF_TEXT | LVIF_PARAM | LVIF_GROUPID;
  4191. lvstruct.lParam = 0;
  4192. lvstruct.iSubItem = 0;
  4193. lvstruct.iGroupId = cntgroup;
  4194. if (inputmap_itemindexp) {
  4195. inputmap_itemindexp[cntgroup - 1] = -1;
  4196. inputmap_itemindexp[cntgroup - 1 + 1] = -1;
  4197. }
  4198. }
  4199. atpidx = 0;
  4200. while (*atp >= 0) {
  4201. if (*atp == evtnum) {
  4202. atp++;
  4203. atpidx = 2;
  4204. break;
  4205. }
  4206. if (atp[1] == evtnum || atp[2] == evtnum) {
  4207. atpidx = 1;
  4208. break;
  4209. }
  4210. atp += 3;
  4211. }
  4212. while (atpidx >= 0) {
  4213. devnum = 0;
  4214. while ((status = inputdevice_get_device_status (devnum)) >= 0) {
  4215. if ((1 || status)) {
  4216. for (int j = 0; j < inputdevice_get_widget_num (devnum); j++) {
  4217. for (int sub = 0; sub < MAX_INPUT_SUB_EVENT; sub++) {
  4218. int port;
  4219. int evtnum2 = inputdevice_get_mapping (devnum, j, &flags, &port, name, NULL, sub);
  4220. if (evtnum2 == evtnum) {
  4221. if (port - 1 != portnum)
  4222. continue;
  4223. if (cntitem - 1 == deleteindex) {
  4224. if (!flags_or && !flags_and && !inputmap_flagsp) {
  4225. inputdevice_set_mapping (devnum, j, NULL, NULL, 0, 0, sub);
  4226. deleteindex = -1;
  4227. found = true;
  4228. continue;
  4229. } else {
  4230. if (flags_or || flags_and) {
  4231. flags &= ~flags_and;
  4232. flags |= flags_or;
  4233. inputdevice_set_mapping(devnum, j, name, NULL, flags, port, sub);
  4234. } else {
  4235. *inputmap_flagsp = flags;
  4236. }
  4237. found = true;
  4238. found2 = true;
  4239. }
  4240. }
  4241. if (list) {
  4242. inputdevice_get_widget_type (devnum, j, name, false);
  4243. TCHAR target[MAX_DPATH];
  4244. _tcscpy (target, name);
  4245. _tcscat (target, _T(", "));
  4246. _tcscat (target, inputdevice_get_device_name2 (devnum));
  4247. if (flags & IDEV_MAPPED_AUTOFIRE_SET) {
  4248. _tcscat(target, _T(" ["));
  4249. if (flags & IDEV_MAPPED_TOGGLE)
  4250. _tcscat(target, remapcustoms[2].name);
  4251. else if (flags & IDEV_MAPPED_INVERTTOGGLE)
  4252. _tcscat(target, remapcustoms[3].name);
  4253. else
  4254. _tcscat(target, remapcustoms[1].name);
  4255. _tcscat(target, _T("]"));
  4256. }
  4257. lvstruct.pszText = target;
  4258. lvstruct.iItem = cntgroup * 256 + cntitem;
  4259. item = ListView_InsertItem(list, &lvstruct);
  4260. if (inputmap_itemindexp && inputmap_itemindexp[cntgroup - 1] < 0)
  4261. inputmap_itemindexp[cntgroup - 1] = item;
  4262. } else if (currentdevnum == devnum && currentwidgetnum == j) {
  4263. if (inputmap_portp)
  4264. *inputmap_portp = portnum;
  4265. if (inputmap_indexp)
  4266. *inputmap_indexp = cntitem - 1;
  4267. found2 = true;
  4268. if (state < 0)
  4269. return 1;
  4270. state = -1;
  4271. }
  4272. cntitem++;
  4273. found = true;
  4274. }
  4275. }
  4276. }
  4277. }
  4278. devnum++;
  4279. }
  4280. evtnum = *atp++;
  4281. atpidx--;
  4282. }
  4283. if (!found) {
  4284. if (list) {
  4285. lvstruct.pszText = _T("");
  4286. lvstruct.iItem = cntgroup * 256 + cntitem;
  4287. lvstruct.lParam = cntgroup;
  4288. item = ListView_InsertItem (list, &lvstruct);
  4289. if (inputmap_itemindexp && inputmap_itemindexp[cntgroup - 1] < 0)
  4290. inputmap_itemindexp[cntgroup - 1] = item;
  4291. }
  4292. cntitem++;
  4293. }
  4294. cntgroup++;
  4295. }
  4296. }
  4297. if (list)
  4298. break;
  4299. }
  4300. if (found2)
  4301. return 1;
  4302. return 0;
  4303. }
  4304. static void update_listview_inputmap (HWND hDlg, int deleteindex)
  4305. {
  4306. HWND list = GetDlgItem (hDlg, IDC_INPUTMAPLIST);
  4307. ListView_EnableGroupView (list, TRUE);
  4308. inputmap_handle (list, -1, -1, NULL, NULL, 0, inputmap_groupindex, deleteindex, 0, 0, NULL);
  4309. }
  4310. static int clicked_entry = -1;
  4311. #define LOADSAVE_COLUMNS 2
  4312. #define INPUT_COLUMNS 7
  4313. #define HARDDISK_COLUMNS 8
  4314. #define DISK_COLUMNS 3
  4315. #define MISC2_COLUMNS 2
  4316. #define INPUTMAP_COLUMNS 1
  4317. #define MISC1_COLUMNS 1
  4318. #define MAX_COLUMN_HEADING_WIDTH 20
  4319. #define CD_COLUMNS 3
  4320. #define BOARD_COLUMNS 5
  4321. #define LV_LOADSAVE 1
  4322. #define LV_HARDDISK 2
  4323. #define LV_INPUT 3
  4324. #define LV_DISK 4
  4325. #define LV_MISC2 5
  4326. #define LV_INPUTMAP 6
  4327. #define LV_MISC1 7
  4328. #define LV_CD 8
  4329. #define LV_BOARD 9
  4330. #define LV_MAX 10
  4331. static int lv_oldidx[LV_MAX];
  4332. static int lv_old_type = -1;
  4333. static int listview_num_columns;
  4334. struct miscentry
  4335. {
  4336. int type;
  4337. int canactive;
  4338. const TCHAR *name;
  4339. bool *b;
  4340. int *i;
  4341. int ival, imask;
  4342. };
  4343. static bool win32_middle_mouse_obsolete;
  4344. static const struct miscentry misclist[] = {
  4345. { 0, 1, _T("Untrap = middle button"), &win32_middle_mouse_obsolete },
  4346. { 0, 0, _T("Show GUI on startup"), &workprefs.start_gui },
  4347. { 0, 1, _T("Use CTRL-F11 to quit"), &workprefs.win32_ctrl_F11_is_quit },
  4348. { 0, 1, _T("Don't show taskbar button"), &workprefs.win32_notaskbarbutton },
  4349. { 0, 1, _T("Don't show notification icon"), &workprefs.win32_nonotificationicon },
  4350. { 0, 1, _T("Emulator window always on top"), &workprefs.win32_main_alwaysontop },
  4351. { 0, 1, _T("GUI window always on top"), &workprefs.win32_gui_alwaysontop },
  4352. { 0, 1, _T("Disable screensaver"), &workprefs.win32_powersavedisabled },
  4353. { 0, 0, _T("Synchronize clock"), &workprefs.tod_hack },
  4354. { 0, 1, _T("One second reboot pause"), &workprefs.reset_delay },
  4355. { 0, 1, _T("Faster RTG"), &workprefs.picasso96_nocustom },
  4356. { 0, 0, _T("Clipboard sharing"), &workprefs.clipboard_sharing },
  4357. { 0, 1, _T("Allow native code"), &workprefs.native_code },
  4358. { 0, 1, _T("Native on-screen display"), NULL, &workprefs.leds_on_screen, STATUSLINE_CHIPSET, STATUSLINE_CHIPSET },
  4359. { 0, 1, _T("RTG on-screen display"), NULL, &workprefs.leds_on_screen, STATUSLINE_RTG, STATUSLINE_RTG },
  4360. { 0, 0, _T("Create winuaelog.txt log"), &workprefs.win32_logfile },
  4361. { 0, 1, _T("Log illegal memory accesses"), &workprefs.illegal_mem },
  4362. { 0, 0, _T("Blank unused displays"), &workprefs.win32_blankmonitors },
  4363. { 0, 0, _T("Start mouse uncaptured"), &workprefs.win32_start_uncaptured },
  4364. { 0, 0, _T("Start minimized"), &workprefs.win32_start_minimized },
  4365. { 0, 1, _T("Minimize when focus is lost"), &workprefs.win32_minimize_inactive },
  4366. { 0, 1, _T("100/120Hz VSync black frame insertion"), &workprefs.lightboost_strobo },
  4367. { 0, 0, _T("Master floppy write protection"), &workprefs.floppy_read_only },
  4368. { 0, 0, _T("Master harddrive write protection"), &workprefs.harddrive_read_only },
  4369. { 0, 0, _T("Hide all UAE autoconfig boards"), &workprefs.uae_hide_autoconfig },
  4370. { 0, 1, _T("Right Control = Right Windows key"), &workprefs.right_control_is_right_win_key },
  4371. { 0, 0, _T("Windows shutdown/logoff notification"), &workprefs.win32_shutdown_notification },
  4372. { 0, 1, _T("Warn when attempting to close window"), &workprefs.win32_warn_exit },
  4373. { 0, 1, _T("Power led dims when audio filter is disabled"), NULL, &workprefs.power_led_dim, 128, 255 },
  4374. { 0, 1, _T("Automatically capture mouse when window is activated"), &workprefs.win32_capture_always },
  4375. { 0, 0, _T("Debug memory space"), &workprefs.debug_mem },
  4376. { 0, 1, _T("Force hard reset if CPU halted"), &workprefs.crash_auto_reset },
  4377. { 0, 0, NULL }
  4378. };
  4379. static void harddisktype (TCHAR *s, struct uaedev_config_info *ci)
  4380. {
  4381. switch (ci->type)
  4382. {
  4383. case UAEDEV_CD:
  4384. _tcscpy (s, _T("CD"));
  4385. break;
  4386. case UAEDEV_TAPE:
  4387. _tcscpy (s, _T("TAPE"));
  4388. break;
  4389. case UAEDEV_HDF:
  4390. _tcscpy (s, _T("HDF"));
  4391. break;
  4392. default:
  4393. _tcscpy (s, _T("n/a"));
  4394. break;
  4395. }
  4396. }
  4397. #define MAX_LISTVIEW_COLUMNS 16
  4398. static int listview_id;
  4399. static int listview_type;
  4400. static int listview_columns;
  4401. static int listview_sortdir, listview_sortcolumn;
  4402. static int listview_column_widths[MAX_LISTVIEW_COLUMNS];
  4403. struct lvsort
  4404. {
  4405. TCHAR **names;
  4406. int max;
  4407. int sortcolumn;
  4408. int sortdir;
  4409. };
  4410. static int CALLBACK lvsortcompare(LPARAM lParam1, LPARAM lParam2, LPARAM lParamSort)
  4411. {
  4412. struct lvsort *lvs = (struct lvsort*)lParamSort;
  4413. if (lParam1 >= lvs->max || lParam2 >= lvs->max)
  4414. return -1;
  4415. TCHAR *s1, *s2;
  4416. if (lvs->sortdir) {
  4417. s2 = lvs->names[lParam1];
  4418. s1 = lvs->names[lParam2];
  4419. } else {
  4420. s1 = lvs->names[lParam1];
  4421. s2 = lvs->names[lParam2];
  4422. }
  4423. return _tcsicmp(s1, s2);
  4424. }
  4425. static void SortListView(HWND list, int sortcolumn, int dir)
  4426. {
  4427. int cnt;
  4428. struct lvsort lvs;
  4429. TCHAR **names;
  4430. TCHAR buf[256];
  4431. cnt = ListView_GetItemCount(list);
  4432. names = xmalloc(TCHAR*, cnt);
  4433. for (int i = 0; i < cnt; i++) {
  4434. LVITEM item = { 0 };
  4435. item.iItem = i;
  4436. item.iSubItem = sortcolumn;
  4437. item.mask = LVIF_TEXT;
  4438. item.pszText = buf;
  4439. item.cchTextMax = sizeof(buf) / sizeof(TCHAR);
  4440. ListView_GetItem(list, &item);
  4441. names[i] = my_strdup(item.pszText);
  4442. }
  4443. lvs.sortcolumn = sortcolumn;
  4444. lvs.max = cnt;
  4445. lvs.sortdir = dir;
  4446. lvs.names = names;
  4447. ListView_SortItemsEx(list, lvsortcompare, &lvs);
  4448. for (int i = 0; i < cnt; i++) {
  4449. xfree(names[i]);
  4450. }
  4451. xfree(names);
  4452. ListView_SetSelectedColumn(list, sortcolumn);
  4453. }
  4454. static void SaveListView(HWND hDlg, bool force)
  4455. {
  4456. HWND list;
  4457. TCHAR name[200];
  4458. TCHAR data[256];
  4459. int columns[100];
  4460. int sortcolumn;
  4461. UAEREG *fkey;
  4462. if (listview_id <= 0)
  4463. return;
  4464. list = GetDlgItem(hDlg, listview_id);
  4465. if (!list)
  4466. return;
  4467. fkey = regcreatetree(NULL, _T("ListViews"));
  4468. if (!fkey)
  4469. return;
  4470. _stprintf(name, _T("LV_%d"), listview_type);
  4471. if (!force) {
  4472. bool modified = false;
  4473. for (int i = 0; i < listview_num_columns; i++) {
  4474. int w = ListView_GetColumnWidth(list, i);
  4475. if (listview_column_widths[i] != w) {
  4476. modified = true;
  4477. }
  4478. }
  4479. if (!regexists(fkey, name) && !modified)
  4480. return;
  4481. }
  4482. _tcscpy(data, _T("1,"));
  4483. ListView_GetColumnOrderArray(list, listview_columns, columns);
  4484. sortcolumn = ListView_GetSelectedColumn(list);
  4485. for (int i = 0; i < listview_columns; i++) {
  4486. int w = ListView_GetColumnWidth(list, i);
  4487. if (i > 0)
  4488. _tcscat(data, _T(","));
  4489. _stprintf(data + _tcslen(data), _T("%d:%d"), columns[i], w);
  4490. if (sortcolumn == columns[i]) {
  4491. _tcscat(data, listview_sortdir ? _T(":D") : _T(":A"));
  4492. }
  4493. }
  4494. regsetstr(fkey, name, data);
  4495. regclosetree(fkey);
  4496. }
  4497. static bool LoadListView(HWND list)
  4498. {
  4499. TCHAR name[200];
  4500. TCHAR data[256];
  4501. int columns[100], columnorders[100];
  4502. int size;
  4503. UAEREG *fkey;
  4504. bool err = true;
  4505. int sortindex = 0;
  4506. listview_sortcolumn = -1;
  4507. fkey = regcreatetree(NULL, _T("ListViews"));
  4508. if (!fkey)
  4509. return false;
  4510. _stprintf(name, _T("LV_%d"), listview_type);
  4511. size = sizeof(data) / sizeof(TCHAR) - 1;
  4512. if (regquerystr(fkey, name, data, &size)) {
  4513. _tcscat(data, _T(","));
  4514. TCHAR *p1 = data;
  4515. int idx = -1;
  4516. for (;;) {
  4517. TCHAR *p2 = _tcschr(p1, ',');
  4518. if (!p2) {
  4519. if (idx == listview_columns)
  4520. err = false;
  4521. break;
  4522. }
  4523. *p2++ = 0;
  4524. int v = _tstol(p1);
  4525. if (idx < 0) {
  4526. if (v != 1) {
  4527. break;
  4528. }
  4529. } else {
  4530. TCHAR *p3 = _tcschr(p1, ':');
  4531. if (!p3)
  4532. break;
  4533. *p3++ = 0;
  4534. if (v < 0 || v >= listview_columns)
  4535. break;
  4536. int w = _tstol(p3);
  4537. if (w < 1 || w >= 4096)
  4538. break;
  4539. columnorders[idx] = v;
  4540. columns[idx] = w;
  4541. p3 = _tcschr(p3, ':');
  4542. if (p3) {
  4543. p3++;
  4544. if (*p3 == 'A') {
  4545. sortindex = 1 + v;
  4546. } else if (*p3 == 'D') {
  4547. sortindex = -1 - v;
  4548. }
  4549. }
  4550. }
  4551. idx++;
  4552. if (idx > listview_columns) {
  4553. break;
  4554. }
  4555. p1 = p2;
  4556. }
  4557. if (!err) {
  4558. for (int i = 0; i < listview_columns; i++) {
  4559. ListView_SetColumnWidth(list, i, columns[i]);
  4560. }
  4561. if (columnorders) {
  4562. ListView_SetColumnOrderArray(list, listview_columns, columnorders);
  4563. }
  4564. if (sortindex && listview_sortdir >= 0) {
  4565. SortListView(list, abs(sortindex) - 1, sortindex < 0);
  4566. listview_sortdir = sortindex < 0;
  4567. }
  4568. }
  4569. }
  4570. regclosetree(fkey);
  4571. return !err;
  4572. }
  4573. static void ColumnClickListView(HWND hDlg, NM_LISTVIEW *lv)
  4574. {
  4575. LPNMLISTVIEW pnmv = (LPNMLISTVIEW)lv;
  4576. HWND list = pnmv->hdr.hwndFrom;
  4577. int column = pnmv->iSubItem;
  4578. int sortcolumn = ListView_GetSelectedColumn(list);
  4579. if (sortcolumn < 0 || sortcolumn != listview_sortcolumn || listview_sortdir < 0) {
  4580. listview_sortdir = 0;
  4581. } else {
  4582. listview_sortdir++;
  4583. }
  4584. listview_sortcolumn = column;
  4585. if (listview_sortdir > 1) {
  4586. listview_sortdir = -1;
  4587. ListView_SetSelectedColumn(list, -1);
  4588. InitializeListView(hDlg);
  4589. } else {
  4590. SortListView(list, column, listview_sortdir);
  4591. SaveListView(hDlg, true);
  4592. }
  4593. }
  4594. static void ResetListViews(void)
  4595. {
  4596. UAEREG *fkey = regcreatetree(NULL, _T("ListViews"));
  4597. if (!fkey)
  4598. return;
  4599. for (int i = 0; i < LV_MAX; i++) {
  4600. TCHAR name[256];
  4601. _stprintf(name, _T("LV_%d"), i);
  4602. regdelete(fkey, name);
  4603. }
  4604. regclosetree(fkey);
  4605. }
  4606. static void InitializeListView (HWND hDlg)
  4607. {
  4608. int lv_type;
  4609. HWND list;
  4610. LV_ITEM lvstruct;
  4611. LV_COLUMN lvcolumn;
  4612. RECT rect;
  4613. TCHAR column_heading[HARDDISK_COLUMNS][MAX_COLUMN_HEADING_WIDTH];
  4614. TCHAR blocksize_str[6] = _T("");
  4615. TCHAR readwrite_str[10] = _T("");
  4616. TCHAR size_str[32] = _T("");
  4617. TCHAR volname_str[MAX_DPATH] = _T("");
  4618. TCHAR devname_str[MAX_DPATH] = _T("");
  4619. TCHAR bootpri_str[6] = _T("");
  4620. int width = 0;
  4621. int items = 0, result = 0, i, j, entry = 0, temp = 0;
  4622. TCHAR tmp[10], tmp2[MAX_DPATH];
  4623. int listview_column_width[HARDDISK_COLUMNS];
  4624. DWORD extraflags = 0;
  4625. int listpadding;
  4626. int dpi = getdpiforwindow(hDlg);
  4627. if (cachedlist) {
  4628. if (lv_old_type >= 0) {
  4629. lv_oldidx[lv_old_type] = ListView_GetTopIndex (cachedlist);
  4630. lv_oldidx[lv_old_type] += ListView_GetCountPerPage (cachedlist) - 1;
  4631. }
  4632. cachedlist = NULL;
  4633. }
  4634. if (hDlg == pages[BOARD_ID]) {
  4635. listview_id = IDC_BOARDLIST;
  4636. listview_num_columns = BOARD_COLUMNS;;
  4637. lv_type = LV_BOARD;
  4638. _tcscpy(column_heading[0], _T("Type"));
  4639. _tcscpy(column_heading[1], _T("Name"));
  4640. _tcscpy(column_heading[2], _T("Start"));
  4641. _tcscpy(column_heading[3], _T("Size"));
  4642. _tcscpy(column_heading[4], _T("ID"));
  4643. } else if (hDlg == pages[HARDDISK_ID]) {
  4644. listview_id = IDC_VOLUMELIST;
  4645. listview_num_columns = HARDDISK_COLUMNS;
  4646. lv_type = LV_HARDDISK;
  4647. _tcscpy (column_heading[0], _T("*"));
  4648. WIN32GUI_LoadUIString (IDS_DEVICE, column_heading[1], MAX_COLUMN_HEADING_WIDTH);
  4649. WIN32GUI_LoadUIString (IDS_VOLUME, column_heading[2], MAX_COLUMN_HEADING_WIDTH);
  4650. WIN32GUI_LoadUIString (IDS_PATH, column_heading[3], MAX_COLUMN_HEADING_WIDTH);
  4651. WIN32GUI_LoadUIString (IDS_RW, column_heading[4], MAX_COLUMN_HEADING_WIDTH);
  4652. WIN32GUI_LoadUIString (IDS_BLOCKSIZE, column_heading[5], MAX_COLUMN_HEADING_WIDTH);
  4653. WIN32GUI_LoadUIString (IDS_HFDSIZE, column_heading[6], MAX_COLUMN_HEADING_WIDTH);
  4654. WIN32GUI_LoadUIString (IDS_BOOTPRI, column_heading[7], MAX_COLUMN_HEADING_WIDTH);
  4655. } else if (hDlg == pages[INPUT_ID]) {
  4656. listview_id = IDC_INPUTLIST;
  4657. listview_num_columns = INPUT_COLUMNS;
  4658. lv_type = LV_INPUT;
  4659. WIN32GUI_LoadUIString (IDS_INPUTHOSTWIDGET, column_heading[0], MAX_COLUMN_HEADING_WIDTH);
  4660. WIN32GUI_LoadUIString (IDS_INPUTAMIGAEVENT, column_heading[1], MAX_COLUMN_HEADING_WIDTH);
  4661. WIN32GUI_LoadUIString (IDS_INPUTAUTOFIRE, column_heading[2], MAX_COLUMN_HEADING_WIDTH);
  4662. WIN32GUI_LoadUIString (IDS_INPUTTOGGLE, column_heading[3], MAX_COLUMN_HEADING_WIDTH);
  4663. _tcscpy (column_heading[4], _T("Invert"));
  4664. WIN32GUI_LoadUIString (IDS_INPUTQUALIFIER, column_heading[5], MAX_COLUMN_HEADING_WIDTH);
  4665. _tcscpy (column_heading[6], _T("#"));
  4666. } else if (hDlg == pages[INPUTMAP_ID]) {
  4667. listview_id = IDC_INPUTMAPLIST;
  4668. listview_num_columns = INPUTMAP_COLUMNS;
  4669. lv_type = LV_INPUTMAP;
  4670. column_heading[0][0] = 0;
  4671. } else if (hDlg == pages[MISC2_ID]) {
  4672. listview_id = IDC_ASSOCIATELIST;
  4673. listview_num_columns = MISC2_COLUMNS;
  4674. lv_type = LV_MISC2;
  4675. _tcscpy (column_heading[0], _T("Extension"));
  4676. _tcscpy (column_heading[1], _T(""));
  4677. } else if (hDlg == pages[MISC1_ID]) {
  4678. listview_id = IDC_MISCLIST;
  4679. listview_num_columns = MISC1_COLUMNS;
  4680. lv_type = LV_MISC1;
  4681. column_heading[0][0] = 0;
  4682. extraflags = LVS_EX_CHECKBOXES;
  4683. } else if (hDlg == pages[DISK_ID]) {
  4684. listview_id = IDC_DISK;
  4685. listview_num_columns = DISK_COLUMNS;
  4686. lv_type = LV_DISK;
  4687. _tcscpy (column_heading[0], _T("#"));
  4688. WIN32GUI_LoadUIString (IDS_DISK_IMAGENAME, column_heading[1], MAX_COLUMN_HEADING_WIDTH);
  4689. WIN32GUI_LoadUIString (IDS_DISK_DRIVENAME, column_heading[2], MAX_COLUMN_HEADING_WIDTH);
  4690. } else {
  4691. // CD dialog
  4692. listview_id = IDC_CDLIST;
  4693. listview_num_columns = CD_COLUMNS;
  4694. lv_type = LV_CD;
  4695. _tcscpy (column_heading[0], _T("*"));
  4696. WIN32GUI_LoadUIString (IDS_DEVICE, column_heading[1], MAX_COLUMN_HEADING_WIDTH);
  4697. WIN32GUI_LoadUIString (IDS_PATH, column_heading[2], MAX_COLUMN_HEADING_WIDTH);
  4698. }
  4699. list = GetDlgItem(hDlg, listview_id);
  4700. listview_type = lv_type;
  4701. listview_columns = listview_num_columns;
  4702. SetWindowRedraw(list, FALSE);
  4703. scalaresource_listview_font_info(&listpadding);
  4704. listpadding *= 2;
  4705. int flags = LVS_EX_DOUBLEBUFFER | extraflags | LVS_EX_HEADERDRAGDROP;
  4706. if (lv_type != LV_MISC1)
  4707. flags |= LVS_EX_ONECLICKACTIVATE | LVS_EX_UNDERLINEHOT | LVS_EX_FULLROWSELECT;
  4708. ListView_SetExtendedListViewStyleEx (list, flags , flags);
  4709. ListView_RemoveAllGroups (list);
  4710. ListView_DeleteAllItems (list);
  4711. cachedlist = list;
  4712. for(i = 0; i < listview_num_columns; i++)
  4713. listview_column_width[i] = MulDiv(ListView_GetStringWidth(list, column_heading[i]), dpi, 72) + listpadding;
  4714. // If there are no columns, then insert some
  4715. lvcolumn.mask = LVCF_WIDTH;
  4716. if (ListView_GetColumn (list, 1, &lvcolumn) == FALSE) {
  4717. for(i = 0; i < listview_num_columns; i++) {
  4718. lvcolumn.mask = LVCF_FMT | LVCF_TEXT | LVCF_WIDTH | LVCF_SUBITEM;
  4719. lvcolumn.iSubItem = i;
  4720. lvcolumn.fmt = LVCFMT_LEFT;
  4721. lvcolumn.pszText = column_heading[i];
  4722. lvcolumn.cx = listview_column_width[i];
  4723. ListView_InsertColumn (list, i, &lvcolumn);
  4724. }
  4725. }
  4726. if (lv_type == LV_BOARD) {
  4727. listview_column_width[1] = MulDiv(200, dpi, 72);
  4728. listview_column_width[2] = MulDiv(90, dpi, 72);
  4729. listview_column_width[3] = MulDiv(90, dpi, 72);
  4730. listview_column_width[4] = MulDiv(90, dpi, 72);
  4731. i = 0;
  4732. if (full_property_sheet)
  4733. expansion_generate_autoconfig_info(&workprefs);
  4734. uaecptr highest_expamem = 0;
  4735. for (;;) {
  4736. TCHAR tmp[200];
  4737. struct autoconfig_info *aci = expansion_get_autoconfig_data(full_property_sheet ? &workprefs : &currprefs, i);
  4738. if (aci) {
  4739. if (aci->zorro == 3 && aci->size != 0 && aci->start + aci->size > highest_expamem)
  4740. highest_expamem = aci->start + aci->size;
  4741. }
  4742. if (!aci && highest_expamem <= Z3BASE_UAE)
  4743. break;
  4744. if (aci && aci->zorro >= 1 && aci->zorro <= 3)
  4745. _stprintf(tmp, _T("Z%d"), aci->zorro);
  4746. else
  4747. _tcscpy(tmp, _T("-"));
  4748. lvstruct.mask = LVIF_TEXT | LVIF_PARAM;
  4749. lvstruct.pszText = tmp;
  4750. lvstruct.lParam = 0;
  4751. if (aci) {
  4752. // movable
  4753. if (expansion_can_move(&workprefs, i))
  4754. lvstruct.lParam |= 1;
  4755. // outside or crosses 2G "border"
  4756. if (aci->zorro == 3 && aci->start + aci->size > 0x80000000 || aci->start + aci->size < aci->start)
  4757. lvstruct.lParam |= 2;
  4758. // outside or crosses 4G "border"
  4759. if (aci->zorro == 3 && aci->start == 0xffffffff)
  4760. lvstruct.lParam |= 4;
  4761. if (!full_property_sheet && (aci->zorro == 2 || aci->zorro == 3) && aci->addrbank && (aci->addrbank->flags & ABFLAG_RAM) && aci->addrbank->reserved_size) {
  4762. // failed to allocate
  4763. if (aci->addrbank->allocated_size == 0)
  4764. lvstruct.lParam |= 8;
  4765. // outside of JIT direct range
  4766. else if (canbang && (aci->addrbank->flags & ABFLAG_ALLOCINDIRECT))
  4767. lvstruct.lParam |= 16;
  4768. }
  4769. if (aci->rc && aci->ert && (aci->ert->deviceflags & EXPANSIONTYPE_PCMCIA) && !aci->rc->inserted) {
  4770. lvstruct.lParam |= 2;
  4771. }
  4772. }
  4773. lvstruct.iItem = i;
  4774. lvstruct.iSubItem = 0;
  4775. result = ListView_InsertItem(list, &lvstruct);
  4776. tmp[0] = 0;
  4777. TCHAR *s = tmp;
  4778. if (aci && aci->parent_of_previous) {
  4779. _tcscat(s, _T(" - "));
  4780. }
  4781. if (aci && (aci->parent_address_space || aci->parent_romtype) && !aci->parent_of_previous)
  4782. _tcscat(s, _T("? "));
  4783. if (aci)
  4784. _tcscat(s, aci->name);
  4785. ListView_SetItemText(list, result, 1, tmp);
  4786. if (aci) {
  4787. if (aci->start != 0xffffffff)
  4788. _stprintf(tmp, _T("0x%08x"), aci->start);
  4789. else
  4790. _tcscpy(tmp, _T("-"));
  4791. ListView_SetItemText(list, result, 2, tmp);
  4792. if (aci->size != 0)
  4793. _stprintf(tmp, _T("0x%08x"), aci->size);
  4794. else
  4795. _tcscpy(tmp, _T("-"));
  4796. ListView_SetItemText(list, result, 3, tmp);
  4797. if (aci->autoconfig_bytes[0] != 0xff)
  4798. _stprintf(tmp, _T("0x%04x/0x%02x"),
  4799. (aci->autoconfig_bytes[4] << 8) | aci->autoconfig_bytes[5], aci->autoconfig_bytes[1]);
  4800. else
  4801. _tcscpy(tmp, _T("-"));
  4802. ListView_SetItemText(list, result, 4, tmp);
  4803. } else {
  4804. _stprintf(tmp, _T("0x%08x"), highest_expamem);
  4805. ListView_SetItemText(list, result, 2, tmp);
  4806. }
  4807. i++;
  4808. if (!aci)
  4809. break;
  4810. }
  4811. } else if (lv_type == LV_MISC2) {
  4812. listview_column_width[0] = MulDiv(180, dpi, 72);
  4813. listview_column_width[1] = MulDiv(10, dpi, 72);
  4814. for (i = 0; exts[i].ext; i++) {
  4815. lvstruct.mask = LVIF_TEXT | LVIF_PARAM;
  4816. lvstruct.pszText = exts[i].ext;
  4817. lvstruct.lParam = 0;
  4818. lvstruct.iItem = i;
  4819. lvstruct.iSubItem = 0;
  4820. result = ListView_InsertItem (list, &lvstruct);
  4821. ListView_SetItemText (list, result, 1, exts[i].enabled ? _T("*") : _T(""));
  4822. }
  4823. } else if (lv_type == LV_INPUT) {
  4824. for (i = 0; input_total_devices && i < inputdevice_get_widget_num (input_selected_device); i++) {
  4825. TCHAR name[100];
  4826. inputdevice_get_widget_type (input_selected_device, i, name, true);
  4827. lvstruct.mask = LVIF_TEXT | LVIF_PARAM;
  4828. lvstruct.pszText = name;
  4829. lvstruct.lParam = i;
  4830. lvstruct.iItem = i;
  4831. lvstruct.iSubItem = 0;
  4832. result = ListView_InsertItem (list, &lvstruct);
  4833. width = MulDiv(ListView_GetStringWidth (list, lvstruct.pszText), dpi, 72) + listpadding;
  4834. if (width > listview_column_width[0])
  4835. listview_column_width[0] = width;
  4836. entry++;
  4837. }
  4838. listview_column_width[1] = MulDiv(260, dpi, 72);
  4839. listview_column_width[2] = MulDiv(65, dpi, 72);
  4840. listview_column_width[3] = MulDiv(65, dpi, 72);
  4841. listview_column_width[4] = MulDiv(65, dpi, 72);
  4842. listview_column_width[5] = MulDiv(65, dpi, 72);
  4843. listview_column_width[6] = MulDiv(30, dpi, 72);
  4844. update_listview_input (hDlg);
  4845. } else if (lv_type == LV_INPUTMAP) {
  4846. listview_column_width[0] = MulDiv(400, dpi, 72);
  4847. update_listview_inputmap (hDlg, -1);
  4848. } else if (lv_type == LV_MISC1) {
  4849. int itemids[] = { IDS_MISCLISTITEMS1, IDS_MISCLISTITEMS2, IDS_MISCLISTITEMS3, IDS_MISCLISTITEMS4 , -1 };
  4850. int itemoffset = 0;
  4851. int itemcnt = 0;
  4852. listview_column_width[0] = MulDiv(150, dpi, 72);
  4853. for (i = 0; misclist[i].name; i++) {
  4854. TCHAR tmpentry[MAX_DPATH], itemname[MAX_DPATH];
  4855. const struct miscentry *me = &misclist[i];
  4856. int type = me->type;
  4857. bool checked = false;
  4858. win32_middle_mouse_obsolete = (workprefs.input_mouse_untrap & MOUSEUNTRAP_MIDDLEBUTTON) != 0;
  4859. if (me->b) {
  4860. checked = *me->b;
  4861. } else if (me->i) {
  4862. checked = ((*me->i) & me->imask) != 0;
  4863. }
  4864. _tcscpy (itemname, me->name);
  4865. for (;;) {
  4866. if (itemids[itemcnt] < 0)
  4867. break;
  4868. WIN32GUI_LoadUIString (itemids[itemcnt], tmpentry, sizeof tmpentry / sizeof (TCHAR));
  4869. TCHAR *p = tmpentry;
  4870. for (int j = 0; j < itemoffset; j++) {
  4871. p = _tcschr (p, '\n');
  4872. if (!p || p[1] == 0) {
  4873. p = NULL;
  4874. itemoffset = 0;
  4875. itemcnt++;
  4876. break;
  4877. }
  4878. p++;
  4879. }
  4880. if (!p)
  4881. continue;
  4882. TCHAR *p2 = _tcschr (p, '\n');
  4883. if (p2) {
  4884. *p2 = 0;
  4885. _tcscpy (itemname, p);
  4886. }
  4887. itemoffset++;
  4888. break;
  4889. }
  4890. lvstruct.mask = LVIF_TEXT | LVIF_PARAM;
  4891. lvstruct.pszText = itemname;
  4892. lvstruct.lParam = 0;
  4893. lvstruct.iItem = i;
  4894. lvstruct.iSubItem = 0;
  4895. result = ListView_InsertItem (list, &lvstruct);
  4896. ListView_SetItemState (list, i, INDEXTOSTATEIMAGEMASK(type ? 0 : (checked ? 2 : 1)), LVIS_STATEIMAGEMASK);
  4897. width = MulDiv(ListView_GetStringWidth(list, lvstruct.pszText), dpi, 72) + listpadding;
  4898. if (width > listview_column_width[0])
  4899. listview_column_width[0] = width;
  4900. entry++;
  4901. }
  4902. } else if (lv_type == LV_DISK) {
  4903. for (i = 0; i < MAX_SPARE_DRIVES; i++) {
  4904. int drv;
  4905. _stprintf (tmp, _T("%d"), i + 1);
  4906. lvstruct.mask = LVIF_TEXT | LVIF_PARAM;
  4907. lvstruct.pszText = tmp;
  4908. lvstruct.lParam = 0;
  4909. lvstruct.iItem = i;
  4910. lvstruct.iSubItem = 0;
  4911. result = ListView_InsertItem (list, &lvstruct);
  4912. _tcscpy (tmp2, workprefs.dfxlist[i]);
  4913. j = _tcslen (tmp2) - 1;
  4914. if (j < 0)
  4915. j = 0;
  4916. while (j > 0) {
  4917. if ((tmp2[j - 1] == '\\' || tmp2[j - 1] == '/')) {
  4918. if (!(j >= 5 && (tmp2[j - 5] == '.' || tmp2[j - 4] == '.')))
  4919. break;
  4920. }
  4921. j--;
  4922. }
  4923. ListView_SetItemText (list, result, 1, tmp2 + j);
  4924. drv = disk_in_drive (i);
  4925. tmp[0] = 0;
  4926. if (drv >= 0)
  4927. _stprintf (tmp, _T("DF%d:"), drv);
  4928. ListView_SetItemText (list, result, 2, tmp);
  4929. width = MulDiv(ListView_GetStringWidth(list, lvstruct.pszText), dpi, 72) + listpadding;
  4930. if (width > listview_column_width[0])
  4931. listview_column_width[0] = width;
  4932. entry++;
  4933. }
  4934. listview_column_width[0] = MulDiv(30, dpi, 72);
  4935. listview_column_width[1] = MulDiv(336, dpi, 72);
  4936. listview_column_width[2] = MulDiv(50, dpi, 72);
  4937. } else if (lv_type == LV_CD) {
  4938. listview_column_width[2] = MulDiv(450, dpi, 72);
  4939. for (i = 0; i < MAX_TOTAL_SCSI_DEVICES; i++) {
  4940. TCHAR tmp[10];
  4941. struct device_info di = { 0 };
  4942. struct cdslot *cds = &workprefs.cdslots[i];
  4943. if (cds->inuse)
  4944. blkdev_get_info (&workprefs, i, &di);
  4945. _stprintf (tmp, _T("%d"), i);
  4946. lvstruct.mask = LVIF_TEXT | LVIF_PARAM;
  4947. lvstruct.pszText = cds->inuse ? (di.media_inserted ? _T("*") : _T("E")) : _T("-");
  4948. lvstruct.lParam = 0;
  4949. lvstruct.iItem = i;
  4950. lvstruct.iSubItem = 0;
  4951. result = ListView_InsertItem (list, &lvstruct);
  4952. ListView_SetItemText(list, result, 1, tmp);
  4953. ListView_SetItemText(list, result, 2, cds->name);
  4954. width = MulDiv(ListView_GetStringWidth(list, cds->name), dpi, 72) + listpadding;
  4955. if (width > listview_column_width[2])
  4956. listview_column_width[2] = width;
  4957. break;
  4958. }
  4959. } else if (lv_type == LV_HARDDISK) {
  4960. #ifdef FILESYS
  4961. listview_column_width[1] = MulDiv(80, dpi, 72);
  4962. for (i = 0; i < workprefs.mountitems; i++)
  4963. {
  4964. struct uaedev_config_data *uci = &workprefs.mountconfig[i];
  4965. struct uaedev_config_info *ci = &uci->ci;
  4966. int nosize = 0, type, ctype;
  4967. struct mountedinfo mi;
  4968. TCHAR *rootdir, *rootdirp;
  4969. type = get_filesys_unitconfig (&workprefs, i, &mi);
  4970. if (type < 0) {
  4971. type = ci->type == UAEDEV_HDF || ci->type == UAEDEV_CD || ci->type == UAEDEV_TAPE ? FILESYS_HARDFILE : FILESYS_VIRTUAL;
  4972. nosize = 1;
  4973. }
  4974. if (mi.size < 0)
  4975. nosize = 1;
  4976. rootdir = my_strdup (mi.rootdir);
  4977. rootdirp = rootdir;
  4978. if (!_tcsncmp (rootdirp, _T("HD_"), 3))
  4979. rootdirp += 3;
  4980. if (rootdirp[0] == ':') {
  4981. rootdirp++;
  4982. TCHAR *p = _tcschr (rootdirp, ':');
  4983. if (p)
  4984. *p = 0;
  4985. }
  4986. if (nosize)
  4987. _tcscpy (size_str, _T("n/a"));
  4988. else if (mi.size >= 1024 * 1024 * 1024)
  4989. _stprintf (size_str, _T("%.1fG"), ((double)(uae_u32)(mi.size / (1024 * 1024))) / 1024.0);
  4990. else if (mi.size < 10 * 1024 * 1024)
  4991. _stprintf (size_str, _T("%lldK"), mi.size / 1024);
  4992. else
  4993. _stprintf (size_str, _T("%.1fM"), ((double)(uae_u32)(mi.size / (1024))) / 1024.0);
  4994. ctype = ci->controller_type;
  4995. if (ctype >= HD_CONTROLLER_TYPE_IDE_FIRST && ctype <= HD_CONTROLLER_TYPE_IDE_LAST) {
  4996. const struct expansionromtype *ert = get_unit_expansion_rom(ctype);
  4997. const TCHAR *idedevs[] = {
  4998. _T("IDE:%d"),
  4999. _T("A600/A1200/A4000:%d"),
  5000. };
  5001. _stprintf (blocksize_str, _T("%d"), ci->blocksize);
  5002. if (ert) {
  5003. if (ci->controller_type_unit == 0)
  5004. _stprintf (devname_str, _T("%s:%d"), ert->friendlyname, ci->controller_unit);
  5005. else
  5006. _stprintf (devname_str, _T("%s:%d/%d"), ert->friendlyname, ci->controller_unit, ci->controller_type_unit + 1);
  5007. } else {
  5008. _stprintf (devname_str, idedevs[ctype - HD_CONTROLLER_TYPE_IDE_FIRST], ci->controller_unit);
  5009. }
  5010. harddisktype (volname_str, ci);
  5011. _tcscpy (bootpri_str, _T("n/a"));
  5012. } else if (ctype >= HD_CONTROLLER_TYPE_SCSI_FIRST && ctype <= HD_CONTROLLER_TYPE_SCSI_LAST) {
  5013. TCHAR sid[8];
  5014. const struct expansionromtype *ert = get_unit_expansion_rom(ctype);
  5015. const TCHAR *scsidevs[] = {
  5016. _T("SCSI:%s"),
  5017. _T("A3000:%s"),
  5018. _T("A4000T:%s"),
  5019. _T("CDTV:%s"),
  5020. };
  5021. if (ci->controller_unit == 8 && ert && !_tcscmp(ert->name, _T("a2091")))
  5022. _tcscpy(sid, _T("XT"));
  5023. else if (ci->controller_unit == 8 && ert && !_tcscmp(ert->name, _T("a2090a")))
  5024. _tcscpy(sid, _T("ST-506"));
  5025. else
  5026. _stprintf(sid, _T("%d"), ci->controller_unit);
  5027. _stprintf (blocksize_str, _T("%d"), ci->blocksize);
  5028. if (ert) {
  5029. if (ci->controller_type_unit == 0)
  5030. _stprintf (devname_str, _T("%s:%s"), ert->friendlyname, sid);
  5031. else
  5032. _stprintf (devname_str, _T("%s:%s/%d"), ert->friendlyname, sid, ci->controller_type_unit + 1);
  5033. } else {
  5034. _stprintf (devname_str, scsidevs[ctype - HD_CONTROLLER_TYPE_SCSI_FIRST], sid);
  5035. }
  5036. harddisktype (volname_str, ci);
  5037. _tcscpy (bootpri_str, _T("n/a"));
  5038. } else if (ctype >= HD_CONTROLLER_TYPE_CUSTOM_FIRST && ctype <= HD_CONTROLLER_TYPE_CUSTOM_LAST) {
  5039. TCHAR sid[8];
  5040. const struct expansionromtype *ert = get_unit_expansion_rom(ctype);
  5041. _stprintf(sid, _T("%d"), ci->controller_unit);
  5042. if (ert) {
  5043. if (ci->controller_type_unit == 0)
  5044. _stprintf(devname_str, _T("%s:%s"), ert->friendlyname, sid);
  5045. else
  5046. _stprintf(devname_str, _T("%s:%s/%d"), ert->friendlyname, sid, ci->controller_type_unit + 1);
  5047. } else {
  5048. _stprintf(devname_str, _T("PCMCIA"));
  5049. }
  5050. harddisktype(volname_str, ci);
  5051. _tcscpy(bootpri_str, _T("n/a"));
  5052. } else if (type == FILESYS_HARDFILE) {
  5053. _stprintf (blocksize_str, _T("%d"), ci->blocksize);
  5054. _tcscpy (devname_str, ci->devname);
  5055. _tcscpy (volname_str, _T("n/a"));
  5056. _stprintf (bootpri_str, _T("%d"), ci->bootpri);
  5057. } else if (type == FILESYS_HARDFILE_RDB || type == FILESYS_HARDDRIVE || ci->controller_type != HD_CONTROLLER_TYPE_UAE) {
  5058. _stprintf (blocksize_str, _T("%d"), ci->blocksize);
  5059. _stprintf (devname_str, _T("UAE:%d"), ci->controller_unit);
  5060. _tcscpy (volname_str, _T("n/a"));
  5061. _tcscpy (bootpri_str, _T("n/a"));
  5062. } else if (type == FILESYS_TAPE) {
  5063. _stprintf (blocksize_str, _T("%d"), ci->blocksize);
  5064. _tcscpy (devname_str, _T("UAE"));
  5065. harddisktype (volname_str, ci);
  5066. _tcscpy (bootpri_str, _T("n/a"));
  5067. } else {
  5068. _tcscpy (blocksize_str, _T("n/a"));
  5069. _tcscpy (devname_str, ci->devname);
  5070. _tcscpy (volname_str, ci->volname);
  5071. _tcscpy (size_str, _T("n/a"));
  5072. _stprintf (bootpri_str, _T("%d"), ci->bootpri);
  5073. }
  5074. if (!mi.ismedia) {
  5075. _tcscpy (blocksize_str, _T("n/a"));
  5076. _tcscpy (size_str, _T("n/a"));
  5077. }
  5078. if (rootdirp[0] == 0) {
  5079. xfree (rootdir);
  5080. rootdir = my_strdup (_T("-"));
  5081. rootdirp = rootdir;
  5082. }
  5083. WIN32GUI_LoadUIString (ci->readonly ? IDS_NO : IDS_YES, readwrite_str, sizeof (readwrite_str) / sizeof (TCHAR));
  5084. lvstruct.mask = LVIF_TEXT | LVIF_PARAM;
  5085. lvstruct.pszText = mi.ismedia == false ? _T("E") : (nosize && mi.size >= 0 ? _T("X") : (mi.ismounted ? _T("*") : _T(" ")));
  5086. if (mi.error == -1)
  5087. lvstruct.pszText = _T("?");
  5088. else if (mi.error == -2)
  5089. lvstruct.pszText = _T("!");
  5090. if (ci->controller_type != HD_CONTROLLER_TYPE_UAE && mi.ismedia)
  5091. lvstruct.pszText = _T(" ");
  5092. lvstruct.lParam = 0;
  5093. lvstruct.iItem = i;
  5094. lvstruct.iSubItem = 0;
  5095. result = ListView_InsertItem (list, &lvstruct);
  5096. if (result != -1) {
  5097. listview_column_width[0] = MulDiv(20, dpi, 72);
  5098. ListView_SetItemText(list, result, 1, devname_str);
  5099. width = MulDiv(ListView_GetStringWidth(list, devname_str), dpi, 72) + listpadding;
  5100. if(width > listview_column_width[1])
  5101. listview_column_width[1] = width;
  5102. ListView_SetItemText(list, result, 2, volname_str);
  5103. width = MulDiv(ListView_GetStringWidth(list, volname_str), dpi, 72) + listpadding;
  5104. if(width > listview_column_width[2])
  5105. listview_column_width[2] = width;
  5106. listview_column_width[3] = 150;
  5107. ListView_SetItemText(list, result, 3, rootdirp);
  5108. width = MulDiv(ListView_GetStringWidth(list, rootdirp), dpi, 72) + listpadding;
  5109. if(width > listview_column_width[3])
  5110. listview_column_width[3] = width;
  5111. ListView_SetItemText(list, result, 4, readwrite_str);
  5112. width = MulDiv(ListView_GetStringWidth(list, readwrite_str), dpi, 72) + listpadding;
  5113. if(width > listview_column_width[4])
  5114. listview_column_width[4] = width;
  5115. ListView_SetItemText(list, result, 5, blocksize_str);
  5116. width = MulDiv(ListView_GetStringWidth(list, blocksize_str), dpi, 72) + listpadding;
  5117. if(width > listview_column_width[5])
  5118. listview_column_width[5] = width;
  5119. ListView_SetItemText(list, result, 6, size_str);
  5120. width = MulDiv(ListView_GetStringWidth(list, size_str), dpi, 72) + listpadding;
  5121. if(width > listview_column_width[6])
  5122. listview_column_width[6] = width;
  5123. ListView_SetItemText(list, result, 7, bootpri_str);
  5124. width = MulDiv(ListView_GetStringWidth(list, bootpri_str), dpi, 72) + listpadding;
  5125. if(width > listview_column_width[7] )
  5126. listview_column_width[7] = width;
  5127. }
  5128. xfree (rootdir);
  5129. }
  5130. #endif
  5131. }
  5132. if (result != -1) {
  5133. if (GetWindowRect(list, &rect)) {
  5134. ScreenToClient(hDlg, (LPPOINT)&rect);
  5135. ScreenToClient(hDlg, (LPPOINT)&rect.right);
  5136. if (listview_num_columns == 2) {
  5137. if ((temp = rect.right - rect.left - listview_column_width[0] - MulDiv(30, dpi, 72)) > listview_column_width[1])
  5138. listview_column_width[1] = temp;
  5139. } else if (listview_num_columns == 1) {
  5140. listview_column_width[0] = rect.right - rect.left - MulDiv(30, dpi, 72);
  5141. }
  5142. }
  5143. for (i = 0; i < listview_num_columns; i++) {
  5144. listview_column_widths[i] = listview_column_width[i];
  5145. }
  5146. if (!LoadListView(list)) {
  5147. // Adjust our column widths so that we can see the contents...
  5148. for (i = 0; i < listview_num_columns; i++) {
  5149. int w = ListView_GetColumnWidth(list, i);
  5150. if (w < listview_column_width[i])
  5151. ListView_SetColumnWidth(list, i, listview_column_width[i]);
  5152. }
  5153. }
  5154. // Redraw the items in the list...
  5155. items = ListView_GetItemCount (list);
  5156. ListView_RedrawItems (list, 0, items);
  5157. }
  5158. if (lv_oldidx[lv_type] >= 0) {
  5159. int idx = lv_oldidx[lv_type];
  5160. if (idx >= ListView_GetItemCount (list))
  5161. idx = ListView_GetItemCount (list) - 1;
  5162. if (idx >= 0)
  5163. ListView_EnsureVisible (list, idx, FALSE);
  5164. }
  5165. lv_old_type = lv_type;
  5166. SetWindowRedraw(list, TRUE);
  5167. RedrawWindow(list, NULL, NULL, RDW_ERASE | RDW_FRAME | RDW_INVALIDATE | RDW_ALLCHILDREN);
  5168. }
  5169. static int listview_find_selected(HWND list, bool paramIndex)
  5170. {
  5171. int i, items;
  5172. items = ListView_GetItemCount (list);
  5173. for (i = 0; i < items; i++) {
  5174. if (ListView_GetItemState(list, i, LVIS_SELECTED) == LVIS_SELECTED) {
  5175. if (paramIndex) {
  5176. LVITEM pitem = { 0 };
  5177. pitem.mask = LVIF_PARAM;
  5178. pitem.iItem = i;
  5179. ListView_GetItem(list, &pitem);
  5180. return pitem.lParam;
  5181. }
  5182. return i;
  5183. }
  5184. }
  5185. return -1;
  5186. }
  5187. static int listview_entry_from_click (HWND list, int *column, bool paramIndex)
  5188. {
  5189. POINT point;
  5190. POINTS p;
  5191. DWORD pos = GetMessagePos ();
  5192. int items, entry;
  5193. p = MAKEPOINTS (pos);
  5194. point.x = p.x;
  5195. point.y = p.y;
  5196. ScreenToClient (list, &point);
  5197. entry = ListView_GetTopIndex (list);
  5198. items = entry + ListView_GetCountPerPage (list);
  5199. if (items > ListView_GetItemCount (list))
  5200. items = ListView_GetItemCount (list);
  5201. while (entry <= items) {
  5202. RECT rect;
  5203. /* Get the bounding rectangle of an item. If the mouse
  5204. * location is within the bounding rectangle of the item,
  5205. * you know you have found the item that was being clicked. */
  5206. if (ListView_GetItemRect (list, entry, &rect, LVIR_BOUNDS)) {
  5207. if (PtInRect (&rect, point)) {
  5208. POINT ppt;
  5209. int x;
  5210. UINT flag = LVIS_SELECTED | LVIS_FOCUSED;
  5211. ListView_GetItemPosition (list, entry, &ppt);
  5212. x = ppt.x;
  5213. ListView_SetItemState (list, entry, flag, flag);
  5214. for (int i = 0; i < listview_num_columns && column; i++) {
  5215. int cw = ListView_GetColumnWidth (list, i);
  5216. if (x < point.x && x + cw > point.x) {
  5217. *column = i;
  5218. break;
  5219. }
  5220. x += cw;
  5221. }
  5222. if (paramIndex) {
  5223. LVITEM pitem = { 0 };
  5224. pitem.mask = LVIF_PARAM;
  5225. pitem.iItem = entry;
  5226. ListView_GetItem(list, &pitem);
  5227. return pitem.lParam;
  5228. }
  5229. return entry;
  5230. }
  5231. }
  5232. entry++;
  5233. }
  5234. return -1;
  5235. }
  5236. static void getconfigfolderregistry(void)
  5237. {
  5238. int cfsize;
  5239. config_folder[0] = 0;
  5240. cfsize = sizeof(config_folder) / sizeof(TCHAR);
  5241. regquerystr(NULL, configregfolder[configtypepanel], config_folder, &cfsize);
  5242. config_search[0] = 0;
  5243. cfsize = sizeof(config_search) / sizeof(TCHAR);
  5244. regquerystr(NULL, configregsearch[configtypepanel], config_search, &cfsize);
  5245. }
  5246. static void ConfigToRegistry(struct ConfigStruct *config, int type)
  5247. {
  5248. if (config) {
  5249. TCHAR path[MAX_DPATH];
  5250. _tcscpy(path, config->Path);
  5251. _tcsncat(path, config->Name, MAX_DPATH - _tcslen(path));
  5252. regsetstr(NULL, configreg[type], path);
  5253. }
  5254. regsetstr(NULL, configregfolder[type], config_folder);
  5255. regsetstr(NULL, configregsearch[type], config_search);
  5256. }
  5257. static void ConfigToRegistry2(DWORD ct, int type, DWORD noauto)
  5258. {
  5259. if (type > 0)
  5260. regsetint(NULL, configreg2[type], ct);
  5261. if (noauto == 0 || noauto == 1)
  5262. regsetint(NULL, _T("ConfigFile_NoAuto"), noauto);
  5263. }
  5264. static void checkautoload(HWND hDlg, struct ConfigStruct *config)
  5265. {
  5266. int ct = 0;
  5267. if (configtypepanel > 0)
  5268. regqueryint(NULL, configreg2[configtypepanel], &ct);
  5269. if (!config || config->Directory) {
  5270. ct = 0;
  5271. ConfigToRegistry2(ct, configtypepanel, -1);
  5272. }
  5273. CheckDlgButton(hDlg, IDC_CONFIGAUTO, ct ? BST_CHECKED : BST_UNCHECKED);
  5274. ew(hDlg, IDC_CONFIGAUTO, configtypepanel > 0 && config && !config->Directory ? TRUE : FALSE);
  5275. regqueryint(NULL, _T("ConfigFile_NoAuto"), &ct);
  5276. CheckDlgButton(hDlg, IDC_CONFIGNOLINK, ct ? BST_CHECKED : BST_UNCHECKED);
  5277. }
  5278. static struct ConfigStruct *InfoSettingsProcConfig;
  5279. static INT_PTR CALLBACK InfoSettingsProc (HWND hDlg, UINT msg, WPARAM wParam, LPARAM lParam)
  5280. {
  5281. static int recursive = 0;
  5282. if (dialog_inhibit)
  5283. return 0;
  5284. switch (msg)
  5285. {
  5286. case WM_INITDIALOG:
  5287. {
  5288. recursive++;
  5289. SendDlgItemMessage(hDlg, IDC_CONFIGLINK, CB_RESETCONTENT, 0, 0L);
  5290. SendDlgItemMessage(hDlg, IDC_CONFIGLINK, CB_ADDSTRING, 0, (LPARAM)_T(""));
  5291. int idx1 = 1;
  5292. int idx2 = 0;
  5293. for (int j = 0; j < 2; j++) {
  5294. for (int i = 0; i < configstoresize; i++) {
  5295. struct ConfigStruct *cs = configstore[i];
  5296. if ((j == 0 && cs->Type == CONFIG_TYPE_HOST) || (j == 1 && cs->Type == CONFIG_TYPE_HARDWARE)) {
  5297. TCHAR tmp2[MAX_DPATH];
  5298. _tcscpy(tmp2, cs->Path);
  5299. _tcsncat(tmp2, cs->Name, MAX_DPATH - _tcslen(tmp2));
  5300. SendDlgItemMessage(hDlg, IDC_CONFIGLINK, CB_ADDSTRING, 0, (LPARAM)tmp2);
  5301. TCHAR *p1 = workprefs.config_host_path;
  5302. if (_tcslen(p1) > _tcslen(tmp2)) {
  5303. p1 += _tcslen(p1) - _tcslen(tmp2);
  5304. }
  5305. TCHAR *p2 = workprefs.config_host_path;
  5306. if (_tcslen(p2) > _tcslen(tmp2)) {
  5307. p2 += _tcslen(p2) - _tcslen(tmp2);
  5308. }
  5309. if (!_tcsicmp(tmp2, p1) || !_tcsicmp(tmp2, p2))
  5310. idx2 = idx1;
  5311. idx1++;
  5312. }
  5313. }
  5314. }
  5315. SendDlgItemMessage(hDlg, IDC_CONFIGLINK, CB_SETCURSEL, idx2, 0);
  5316. checkautoload(hDlg, InfoSettingsProcConfig);
  5317. EnableWindow(GetDlgItem(hDlg, IDC_CONFIGAUTO), configtypepanel > 0);
  5318. EnableWindow(GetDlgItem(hDlg, IDC_CONFIGLINK), configtypepanel == 0);
  5319. EnableWindow(GetDlgItem(hDlg, IDC_CONFIGNOLINK), configtypepanel == 0);
  5320. SetDlgItemText(hDlg, IDC_PATH_NAME, workprefs.info);
  5321. SetDlgItemText(hDlg, IDC_CONFIGCATEGORY, workprefs.category);
  5322. SetDlgItemText(hDlg, IDC_CONFIGTAGS, workprefs.tags);
  5323. recursive--;
  5324. return TRUE;
  5325. }
  5326. case WM_COMMAND:
  5327. if (recursive)
  5328. break;
  5329. recursive++;
  5330. switch (LOWORD(wParam))
  5331. {
  5332. case IDC_SELECTOR:
  5333. DiskSelection(hDlg, IDC_PATH_NAME, 8, &workprefs, NULL, NULL);
  5334. break;
  5335. case IDOK:
  5336. EndDialog(hDlg, 1);
  5337. break;
  5338. case IDCANCEL:
  5339. EndDialog(hDlg, 0);
  5340. break;
  5341. case IDC_CONFIGAUTO:
  5342. if (configtypepanel > 0) {
  5343. int ct = ischecked(hDlg, IDC_CONFIGAUTO) ? 1 : 0;
  5344. ConfigToRegistry2(ct, configtypepanel, -1);
  5345. }
  5346. break;
  5347. case IDC_CONFIGNOLINK:
  5348. if (configtypepanel == 0) {
  5349. int ct = ischecked(hDlg, IDC_CONFIGNOLINK) ? 1 : 0;
  5350. ConfigToRegistry2(-1, -1, ct);
  5351. }
  5352. break;
  5353. case IDC_CONFIGLINK:
  5354. if (HIWORD(wParam) == CBN_SELCHANGE || HIWORD(wParam) == CBN_KILLFOCUS) {
  5355. TCHAR tmp[MAX_DPATH];
  5356. tmp[0] = 0;
  5357. getcbn(hDlg, IDC_CONFIGLINK, tmp, sizeof(tmp) / sizeof(TCHAR));
  5358. _tcscpy(workprefs.config_host_path, tmp);
  5359. }
  5360. break;
  5361. }
  5362. GetDlgItemText(hDlg, IDC_PATH_NAME, workprefs.info, sizeof workprefs.info / sizeof(TCHAR));
  5363. GetDlgItemText(hDlg, IDC_CONFIGCATEGORY, workprefs.category, sizeof workprefs.category / sizeof(TCHAR));
  5364. GetDlgItemText(hDlg, IDC_CONFIGTAGS, workprefs.tags, sizeof workprefs.tags / sizeof(TCHAR));
  5365. recursive--;
  5366. break;
  5367. }
  5368. commonproc(hDlg, msg, wParam, lParam);
  5369. return FALSE;
  5370. }
  5371. static int addConfigFolder(HWND hDlg, const TCHAR *s, bool directory)
  5372. {
  5373. TCHAR tmp[MAX_DPATH];
  5374. if (directory) {
  5375. _tcscpy(tmp, s);
  5376. } else {
  5377. _stprintf(tmp, _T("[%s]"), s);
  5378. }
  5379. int idx = SendDlgItemMessage(hDlg, IDC_CONFIGFOLDER, CB_ADDSTRING, 0, (LPARAM)tmp);
  5380. if (!_tcscmp(tmp, config_folder))
  5381. SendDlgItemMessage(hDlg, IDC_CONFIGFOLDER, CB_SETCURSEL, idx, 0);
  5382. return idx;
  5383. }
  5384. static HTREEITEM AddConfigNode (HWND hDlg, struct ConfigStruct *config, const TCHAR *name, const TCHAR *desc, const TCHAR *path, int isdir, int expand, HTREEITEM parent)
  5385. {
  5386. TVINSERTSTRUCT is;
  5387. HWND TVhDlg;
  5388. TCHAR s[MAX_DPATH] = _T("");
  5389. TCHAR file_name[MAX_DPATH] = _T(""), file_path[MAX_DPATH] = _T("");
  5390. GetDlgItemText (hDlg, IDC_EDITNAME, file_name, MAX_DPATH);
  5391. GetDlgItemText (hDlg, IDC_EDITPATH, file_path, MAX_DPATH);
  5392. TVhDlg = GetDlgItem (hDlg, IDC_CONFIGTREE);
  5393. memset (&is, 0, sizeof (is));
  5394. is.hInsertAfter = isdir < 0 ? TVI_ROOT : TVI_SORT;
  5395. is.hParent = parent;
  5396. is.itemex.mask = TVIF_TEXT | TVIF_STATE | TVIF_IMAGE | TVIF_SELECTEDIMAGE | TVIF_PARAM;
  5397. if (name && path && !_tcscmp (file_name, name) && !_tcscmp (file_path, path)) {
  5398. is.itemex.state |= TVIS_SELECTED;
  5399. is.itemex.stateMask |= TVIS_SELECTED;
  5400. }
  5401. if (isdir) {
  5402. _tcscat (s, _T(" "));
  5403. is.itemex.state |= TVIS_BOLD;
  5404. is.itemex.stateMask |= TVIS_BOLD;
  5405. }
  5406. if (expand) {
  5407. is.itemex.state |= TVIS_EXPANDED;
  5408. is.itemex.stateMask |= TVIS_EXPANDED;
  5409. }
  5410. _tcscat (s, name);
  5411. if (_tcslen (s) > 4 && !_tcsicmp (s + _tcslen (s) - 4, _T(".uae")))
  5412. s[_tcslen (s) - 4] = 0;
  5413. if (desc && _tcslen (desc) > 0) {
  5414. _tcscat (s, _T(" ("));
  5415. _tcscat (s, desc);
  5416. _tcscat (s, _T(")"));
  5417. }
  5418. is.itemex.pszText = s;
  5419. is.itemex.iImage = is.itemex.iSelectedImage = isdir > 0 ? 0 : (isdir < 0) ? 2 : 1;
  5420. is.itemex.lParam = (LPARAM)config;
  5421. return TreeView_InsertItem (TVhDlg, &is);
  5422. }
  5423. static bool configsearchmatch(const TCHAR *str, int searchlen)
  5424. {
  5425. if (!str[0])
  5426. return false;
  5427. int strlen = _tcslen(str);
  5428. if (strlen >= searchlen) {
  5429. for (int i = 0; i <= strlen - searchlen; i++) {
  5430. if (!_tcsnicmp(config_search, str + i, searchlen)) {
  5431. return true;
  5432. }
  5433. }
  5434. }
  5435. return false;
  5436. }
  5437. static bool configsearch(struct ConfigStruct *config)
  5438. {
  5439. int searchlen = _tcslen(config_search);
  5440. for (int j = 0; j < 3; j++) {
  5441. TCHAR *str = NULL;
  5442. switch (j)
  5443. {
  5444. case 0:
  5445. str = config->Name;
  5446. if (configsearchmatch(str, searchlen))
  5447. return true;
  5448. break;
  5449. case 1:
  5450. str = config->Description;
  5451. if (configsearchmatch(str, searchlen))
  5452. return true;
  5453. break;
  5454. case 2:
  5455. {
  5456. TCHAR tag[CFG_DESCRIPTION_LENGTH + 1] = { 0 };
  5457. if (config->Tags[0]) {
  5458. _tcscpy(tag, config->Tags);
  5459. TCHAR *p = tag;
  5460. for (;;) {
  5461. TCHAR *p2 = p;
  5462. while (*p2 != ',' && *p2 != ' ' && *p2 != 0)
  5463. p2++;
  5464. *p2++ = 0;
  5465. if (configsearchmatch(p, searchlen))
  5466. return true;
  5467. if (*p2 == 0)
  5468. break;
  5469. p = p2;
  5470. }
  5471. }
  5472. }
  5473. break;
  5474. }
  5475. }
  5476. return false;
  5477. }
  5478. static int LoadConfigTreeView (HWND hDlg, int idx, HTREEITEM parent)
  5479. {
  5480. struct ConfigStruct *cparent, *config;
  5481. int cnt = 0;
  5482. if (configstoresize == 0)
  5483. return cnt;
  5484. if (idx < 0) {
  5485. idx = 0;
  5486. for (;;) {
  5487. config = configstore[idx];
  5488. if (config->Parent == NULL)
  5489. break;
  5490. idx++;
  5491. if (idx >= configstoresize)
  5492. return cnt;
  5493. }
  5494. }
  5495. cparent = configstore[idx]->Parent;
  5496. idx = 0;
  5497. while (idx < configstoresize) {
  5498. config = configstore[idx];
  5499. if ((configtypepanel == 1 && !config->hardware) || (configtypepanel == 2 && !config->host) || (configtypepanel == 0 && (config->host || config->hardware))) {
  5500. idx++;
  5501. continue;
  5502. }
  5503. if (config->Parent == cparent) {
  5504. bool visible = false;
  5505. int cfgflen = _tcslen(config_folder);
  5506. if (config_folder[0] == 0) {
  5507. visible = true;
  5508. } else if (config_folder[0] == '[' && config_folder[cfgflen - 1] == ']') {
  5509. visible = false;
  5510. if (cfgflen - 2 == _tcslen(config->Category) && !_tcsnicmp(config->Category, config_folder + 1, cfgflen - 2)) {
  5511. visible = true;
  5512. }
  5513. } else if (!_tcsncmp(config_folder, config->Path, _tcslen(config_folder))) {
  5514. visible = true;
  5515. }
  5516. if (config_search[0] && visible && !config->Directory) {
  5517. visible = configsearch(config);
  5518. }
  5519. if (visible) {
  5520. if (config->Directory) {
  5521. int stridx = -1;
  5522. bool expand = config->hardware || config->host;
  5523. if (config_folder[0]) {
  5524. expand = true;
  5525. }
  5526. stridx = addConfigFolder(hDlg, config->Path, true);
  5527. HTREEITEM par = AddConfigNode(hDlg, config, config->Name, NULL, config->Path, 1, expand, parent);
  5528. int idx2 = 0;
  5529. for (;;) {
  5530. if (configstore[idx2] == config->Child) {
  5531. config->item = par;
  5532. if (LoadConfigTreeView(hDlg, idx2, par) == 0) {
  5533. if (!config->hardware && !config->host && !config->Directory) {
  5534. TreeView_DeleteItem(GetDlgItem(hDlg, IDC_CONFIGTREE), par);
  5535. if (stridx >= 0)
  5536. SendDlgItemMessage(hDlg, IDC_CONFIGFOLDER, CB_DELETESTRING, stridx, 0);
  5537. }
  5538. }
  5539. break;
  5540. }
  5541. idx2++;
  5542. if (idx2 >= configstoresize)
  5543. break;
  5544. }
  5545. } else if (!config->Directory) {
  5546. if (((config->Type == 0 || config->Type == 3) && configtype == 0) || (config->Type == configtype)) {
  5547. config->item = AddConfigNode(hDlg, config, config->Name, config->Description, config->Path, 0, 0, parent);
  5548. cnt++;
  5549. }
  5550. }
  5551. } else {
  5552. if (config->Directory) {
  5553. addConfigFolder(hDlg, config->Path, true);
  5554. int idx2 = 0;
  5555. for (;;) {
  5556. if (configstore[idx2] == config->Child) {
  5557. LoadConfigTreeView(hDlg, idx2, parent);
  5558. break;
  5559. }
  5560. idx2++;
  5561. if (idx2 >= configstoresize)
  5562. break;
  5563. }
  5564. }
  5565. }
  5566. }
  5567. idx++;
  5568. }
  5569. return cnt;
  5570. }
  5571. static void InitializeConfig (HWND hDlg, struct ConfigStruct *config)
  5572. {
  5573. addhistorymenu(hDlg, config == NULL ? _T("") : config->Name, IDC_EDITNAME, HISTORY_CONFIGFILE, false, -1);
  5574. if (config == NULL) {
  5575. SetDlgItemText (hDlg, IDC_EDITDESCRIPTION, _T(""));
  5576. } else {
  5577. SetDlgItemText (hDlg, IDC_EDITDESCRIPTION, config->Description);
  5578. }
  5579. if (config && config->Artpath[0]) {
  5580. show_box_art(config->Artpath, config->Name);
  5581. } else {
  5582. show_box_art(NULL, NULL);
  5583. }
  5584. }
  5585. static void DeleteConfigTree (HWND hDlg)
  5586. {
  5587. HWND TVhDlg = GetDlgItem(hDlg, IDC_CONFIGTREE);
  5588. for (int i = 0; i < configstoresize; i++) {
  5589. configstore[i]->item = NULL;
  5590. }
  5591. TreeView_DeleteAllItems (TVhDlg);
  5592. }
  5593. static HTREEITEM InitializeConfigTreeView (HWND hDlg)
  5594. {
  5595. HIMAGELIST himl = ImageList_Create (16, 16, ILC_COLOR8 | ILC_MASK, 3, 0);
  5596. HWND TVhDlg = GetDlgItem(hDlg, IDC_CONFIGTREE);
  5597. HTREEITEM parent;
  5598. TCHAR path[MAX_DPATH];
  5599. if (himl) {
  5600. HICON icon;
  5601. icon = LoadIcon (hInst, (LPCWSTR)MAKEINTRESOURCE(IDI_FOLDER));
  5602. ImageList_AddIcon (himl, icon);
  5603. icon = LoadIcon (hInst, (LPCWSTR)MAKEINTRESOURCE(IDI_FILE));
  5604. ImageList_AddIcon (himl, icon);
  5605. icon = LoadIcon (hInst, (LPCWSTR)MAKEINTRESOURCE(IDI_ROOT));
  5606. ImageList_AddIcon (himl, icon);
  5607. TreeView_SetImageList (TVhDlg, himl, TVSIL_NORMAL);
  5608. }
  5609. SendDlgItemMessage(hDlg, IDC_CONFIGFOLDER, CB_RESETCONTENT, 0, 0L);
  5610. SendDlgItemMessage(hDlg, IDC_CONFIGFOLDER, CB_ADDSTRING, 0, (LPARAM)_T(""));
  5611. for (int i = 0; i < categorystoresize; i++) {
  5612. struct CategoryStruct *c = categorystore[i];
  5613. addConfigFolder(hDlg, c->category, false);
  5614. }
  5615. DeleteConfigTree (hDlg);
  5616. GetConfigPath (path, NULL, FALSE);
  5617. parent = AddConfigNode (hDlg, NULL, path, NULL, NULL, 0, 1, NULL);
  5618. LoadConfigTreeView (hDlg, -1, parent);
  5619. ew(hDlg, IDC_CONFIGFOLDER, SendDlgItemMessage(hDlg, IDC_CONFIGFOLDER, CB_GETCOUNT, 0, 0L) > 1);
  5620. return parent;
  5621. }
  5622. static struct ConfigStruct *fixloadconfig (HWND hDlg, struct ConfigStruct *config)
  5623. {
  5624. int i;
  5625. if (config && configtypepanel == 0 && (config->host || config->hardware))
  5626. return NULL;
  5627. if ((!config && configtypepanel) || (config && (configtypepanel == 2 && !config->host) || (configtypepanel == 1 && !config->hardware))) {
  5628. for (i = 0; i < configstoresize; i++) {
  5629. struct ConfigStruct *cs = configstore[i];
  5630. if (cs->Directory && ((configtypepanel == 1 && cs->hardware) || (configtypepanel == 2 && cs->host))) {
  5631. config = cs;
  5632. SetDlgItemText (hDlg, IDC_EDITPATH, config->Path);
  5633. break;
  5634. }
  5635. }
  5636. }
  5637. return config;
  5638. }
  5639. static struct ConfigStruct *initloadsave (HWND hDlg, struct ConfigStruct *config, bool init)
  5640. {
  5641. HTREEITEM root;
  5642. TCHAR name_buf[MAX_DPATH];
  5643. int dwRFPsize = sizeof(name_buf) / sizeof(TCHAR);
  5644. TCHAR path[MAX_DPATH];
  5645. HWND lv = GetDlgItem(hDlg, IDC_CONFIGTREE);
  5646. SetWindowRedraw(lv, FALSE);
  5647. EnableWindow (GetDlgItem (hDlg, IDC_VIEWINFO), workprefs.info[0]);
  5648. root = InitializeConfigTreeView (hDlg);
  5649. if (regquerystr (NULL, configreg[configtypepanel], name_buf, &dwRFPsize)) {
  5650. if (init) {
  5651. if (_tcsicmp(name_buf, _T("default.uae")))
  5652. target_cfgfile_load (&workprefs, name_buf, CONFIG_TYPE_DEFAULT, 0);
  5653. }
  5654. struct ConfigStruct *config2 = getconfigstorefrompath (name_buf, path, configtypepanel);
  5655. if (config2)
  5656. config = config2;
  5657. }
  5658. config = fixloadconfig (hDlg, config);
  5659. SetWindowRedraw(lv, TRUE);
  5660. RedrawWindow(lv, NULL, NULL, RDW_ERASE | RDW_FRAME | RDW_INVALIDATE | RDW_ALLCHILDREN);
  5661. if (config && config->item)
  5662. TreeView_SelectItem (GetDlgItem(hDlg, IDC_CONFIGTREE), config->item);
  5663. else
  5664. TreeView_SelectItem (GetDlgItem(hDlg, IDC_CONFIGTREE), root);
  5665. return config;
  5666. }
  5667. static struct ConfigStruct *refreshconfiglist(HWND hDlg, struct ConfigStruct *config)
  5668. {
  5669. struct ConfigStruct *cs = initloadsave(hDlg, config, false);
  5670. return cs;
  5671. }
  5672. static void loadsavecommands (HWND hDlg, WPARAM wParam, struct ConfigStruct **configp, TCHAR **pcfgfile, TCHAR *newpath)
  5673. {
  5674. struct ConfigStruct *config = *configp;
  5675. if (HIWORD(wParam) == CBN_SELCHANGE) {
  5676. switch (LOWORD(wParam))
  5677. {
  5678. case IDC_CONFIGFOLDER:
  5679. {
  5680. int idx = SendDlgItemMessage(hDlg, IDC_CONFIGFOLDER, CB_GETCURSEL, 0, 0L);
  5681. if (idx >= 0) {
  5682. SendDlgItemMessage(hDlg, IDC_CONFIGFOLDER, CB_GETLBTEXT, (WPARAM)idx, (LPARAM)config_folder);
  5683. if (_tcslen(config_folder) > 0 && config_folder[_tcslen(config_folder) - 1] != ']' && config_folder[_tcslen(config_folder) - 1] != '\\')
  5684. _tcscat(config_folder, _T("\\"));
  5685. ConfigToRegistry(config, configtypepanel);
  5686. config = refreshconfiglist(hDlg, config);
  5687. }
  5688. break;
  5689. }
  5690. case IDC_EDITNAME:
  5691. {
  5692. TCHAR cfg[MAX_DPATH];
  5693. if (getcomboboxtext(hDlg, IDC_EDITNAME, cfg, sizeof cfg / sizeof(TCHAR))) {
  5694. config = NULL;
  5695. for (int i = 0; i < configstoresize; i++) {
  5696. struct ConfigStruct *cs = configstore[i];
  5697. TCHAR path[MAX_DPATH];
  5698. _tcscpy(path, cs->Path);
  5699. _tcscat(path, cs->Name);
  5700. if (!_tcsicmp(path, cfg)) {
  5701. config = cs;
  5702. TreeView_SelectItem(GetDlgItem(hDlg, IDC_CONFIGTREE), cs->item);
  5703. break;
  5704. }
  5705. }
  5706. }
  5707. }
  5708. break;
  5709. }
  5710. }
  5711. if (HIWORD(wParam) == EN_CHANGE) {
  5712. switch (LOWORD(wParam))
  5713. {
  5714. case IDC_CONFIGSEARCH:
  5715. {
  5716. GetDlgItemText(hDlg, IDC_CONFIGSEARCH, config_search, MAX_DPATH);
  5717. config = refreshconfiglist(hDlg, config);
  5718. break;
  5719. }
  5720. }
  5721. }
  5722. switch (LOWORD (wParam))
  5723. {
  5724. case IDC_CONFIGSEARCHCLEAR:
  5725. if (config_search[0]) {
  5726. config_search[0] = 0;
  5727. SetDlgItemText(hDlg, IDC_CONFIGSEARCH, _T(""));
  5728. ConfigToRegistry(config, configtypepanel);
  5729. config = refreshconfiglist(hDlg, config);
  5730. }
  5731. break;
  5732. case IDC_SAVE:
  5733. if (HandleConfiguration (hDlg, CONFIG_SAVE_FULL, config, newpath)) {
  5734. DeleteConfigTree (hDlg);
  5735. config = CreateConfigStore (config, TRUE);
  5736. ConfigToRegistry (config, configtypepanel);
  5737. config = initloadsave (hDlg, config, false);
  5738. InitializeConfig (hDlg, config);
  5739. }
  5740. break;
  5741. case IDC_QUICKSAVE:
  5742. if (HandleConfiguration (hDlg, CONFIG_SAVE, config, NULL)) {
  5743. DeleteConfigTree (hDlg);
  5744. config = CreateConfigStore (config, TRUE);
  5745. ConfigToRegistry (config, configtypepanel);
  5746. config = initloadsave (hDlg, config, false);
  5747. InitializeConfig (hDlg, config);
  5748. }
  5749. break;
  5750. case IDC_QUICKLOAD:
  5751. *pcfgfile = HandleConfiguration (hDlg, CONFIG_LOAD, config, NULL);
  5752. if (*pcfgfile) {
  5753. ConfigToRegistry (config, configtypepanel);
  5754. InitializeConfig (hDlg, config);
  5755. if (full_property_sheet) {
  5756. inputdevice_updateconfig (NULL, &workprefs);
  5757. } else {
  5758. uae_restart (-1, *pcfgfile);
  5759. exit_gui(1);
  5760. }
  5761. }
  5762. break;
  5763. case IDC_LOAD:
  5764. *pcfgfile = HandleConfiguration (hDlg, CONFIG_LOAD_FULL, config, newpath);
  5765. if (*pcfgfile) {
  5766. ConfigToRegistry (config, configtypepanel);
  5767. InitializeConfig (hDlg, config);
  5768. if (full_property_sheet) {
  5769. inputdevice_updateconfig (NULL, &workprefs);
  5770. } else {
  5771. uae_restart (-1, *pcfgfile);
  5772. exit_gui(1);
  5773. }
  5774. }
  5775. break;
  5776. case IDC_DELETE:
  5777. if (HandleConfiguration (hDlg, CONFIG_DELETE, config, NULL)) {
  5778. DeleteConfigTree (hDlg);
  5779. config = CreateConfigStore (config, TRUE);
  5780. config = initloadsave (hDlg, config, false);
  5781. InitializeConfig (hDlg, config);
  5782. }
  5783. break;
  5784. case IDC_VIEWINFO:
  5785. if (workprefs.info[0]) {
  5786. TCHAR name_buf[MAX_DPATH];
  5787. if (_tcsstr (workprefs.info, _T("Configurations\\")))
  5788. _stprintf (name_buf, _T("%s\\%s"), start_path_data, workprefs.info);
  5789. else
  5790. _tcscpy (name_buf, workprefs.info);
  5791. ShellExecute (NULL, NULL, name_buf, NULL, NULL, SW_SHOWNORMAL);
  5792. }
  5793. break;
  5794. case IDC_SETINFO:
  5795. InfoSettingsProcConfig = config;
  5796. if (CustomDialogBox(IDD_SETINFO, hDlg, InfoSettingsProc))
  5797. EnableWindow( GetDlgItem( hDlg, IDC_VIEWINFO ), workprefs.info[0] );
  5798. break;
  5799. }
  5800. *configp = config;
  5801. }
  5802. static INT_PTR CALLBACK LoadSaveDlgProc (HWND hDlg, UINT msg, WPARAM wParam, LPARAM lParam)
  5803. {
  5804. TCHAR *cfgfile = NULL;
  5805. static int recursive;
  5806. static struct ConfigStruct *config;
  5807. if (dialog_inhibit)
  5808. return 0;
  5809. switch (msg)
  5810. {
  5811. case WM_INITDIALOG:
  5812. {
  5813. recursive++;
  5814. if (!configstore) {
  5815. DeleteConfigTree(hDlg);
  5816. CreateConfigStore(NULL, FALSE);
  5817. config = NULL;
  5818. }
  5819. getconfigfolderregistry();
  5820. pages[LOADSAVE_ID] = hDlg;
  5821. currentpage = LOADSAVE_ID;
  5822. SetDlgItemText(hDlg, IDC_EDITPATH, _T(""));
  5823. SetDlgItemText(hDlg, IDC_EDITDESCRIPTION, workprefs.description);
  5824. SetDlgItemText(hDlg, IDC_CONFIGSEARCH, config_search);
  5825. config = initloadsave(hDlg, config, firstautoloadconfig);
  5826. firstautoloadconfig = false;
  5827. recursive--;
  5828. return TRUE;
  5829. }
  5830. case WM_DESTROY:
  5831. ConfigToRegistry(NULL, configtypepanel);
  5832. break;
  5833. case WM_USER + 1:
  5834. if (config) {
  5835. if (config->Artpath[0]) {
  5836. show_box_art(config->Artpath, config->Name);
  5837. } else {
  5838. show_box_art(NULL, NULL);
  5839. }
  5840. }
  5841. break;
  5842. case WM_CONTEXTMENU:
  5843. {
  5844. int id = GetDlgCtrlID ((HWND)wParam);
  5845. if (id == IDC_SAVE || id == IDC_LOAD) {
  5846. TCHAR *s = favoritepopup (hDlg);
  5847. if (s) {
  5848. loadsavecommands (hDlg, id, &config, &cfgfile, s);
  5849. xfree (s);
  5850. }
  5851. }
  5852. break;
  5853. }
  5854. case WM_COMMAND:
  5855. {
  5856. recursive++;
  5857. loadsavecommands (hDlg, wParam, &config, &cfgfile, NULL);
  5858. recursive++;
  5859. break;
  5860. }
  5861. case WM_NOTIFY:
  5862. {
  5863. LPNMHDR nm = (LPNMHDR)lParam;
  5864. if (nm->hwndFrom == GetDlgItem (hDlg, IDC_CONFIGTREE)) {
  5865. switch (nm->code)
  5866. {
  5867. case NM_DBLCLK:
  5868. {
  5869. HTREEITEM ht = TreeView_GetSelection (GetDlgItem (hDlg, IDC_CONFIGTREE));
  5870. if (ht != NULL) {
  5871. TVITEMEX pitem;
  5872. memset (&pitem, 0, sizeof (pitem));
  5873. pitem.mask = TVIF_HANDLE | TVIF_PARAM;
  5874. pitem.hItem = ht;
  5875. if (TreeView_GetItem (GetDlgItem(hDlg, IDC_CONFIGTREE), &pitem)) {
  5876. struct ConfigStruct *config = (struct ConfigStruct*)pitem.lParam;
  5877. if (config && !config->Directory) {
  5878. cfgfile = HandleConfiguration (hDlg, CONFIG_LOAD, config, NULL);
  5879. if (cfgfile) {
  5880. ConfigToRegistry (config, configtypepanel);
  5881. if (!full_property_sheet)
  5882. uae_restart (0, cfgfile);
  5883. exit_gui (1);
  5884. }
  5885. }
  5886. }
  5887. }
  5888. return TRUE;
  5889. }
  5890. break;
  5891. case TVN_SELCHANGING:
  5892. return FALSE;
  5893. case TVN_SELCHANGED:
  5894. {
  5895. LPNMTREEVIEW tv = (LPNMTREEVIEW)lParam;
  5896. struct ConfigStruct *c = (struct ConfigStruct*)tv->itemNew.lParam;
  5897. if (c) {
  5898. config = c;
  5899. if (!config->Directory) {
  5900. InitializeConfig (hDlg, config);
  5901. } else {
  5902. InitializeConfig (hDlg, NULL);
  5903. }
  5904. SetDlgItemText (hDlg, IDC_EDITPATH, config->Path);
  5905. }
  5906. if (configtypepanel > 0) {
  5907. if (c && !c->Directory) {
  5908. ConfigToRegistry (config, configtypepanel);
  5909. InitializeConfig (hDlg, config);
  5910. }
  5911. checkautoload (hDlg, c);
  5912. }
  5913. return TRUE;
  5914. }
  5915. break;
  5916. }
  5917. }
  5918. break;
  5919. }
  5920. }
  5921. return FALSE;
  5922. }
  5923. #define MAX_CONTRIBUTORS_LENGTH 2048
  5924. static INT_PTR CALLBACK ErrorLogProc (HWND hDlg, UINT msg, WPARAM wParam, LPARAM lParam)
  5925. {
  5926. CHARFORMAT CharFormat;
  5927. TCHAR *err;
  5928. if (dialog_inhibit)
  5929. return 0;
  5930. switch (msg) {
  5931. case WM_COMMAND:
  5932. if (wParam == IDOK) {
  5933. EndDialog (hDlg, 1);
  5934. return TRUE;
  5935. } else if (wParam == IDC_ERRORLOGCLEAR) {
  5936. error_log (NULL);
  5937. EndDialog (hDlg, 1);
  5938. return TRUE;
  5939. }
  5940. break;
  5941. case WM_INITDIALOG:
  5942. err = get_error_log ();
  5943. if (err == NULL)
  5944. return FALSE;
  5945. CharFormat.cbSize = sizeof (CharFormat);
  5946. SetDlgItemText (hDlg, IDC_ERRORLOGMESSAGE, err);
  5947. SendDlgItemMessage (hDlg, IDC_ERRORLOGMESSAGE, EM_GETCHARFORMAT, 0, (LPARAM) & CharFormat);
  5948. CharFormat.dwMask |= CFM_SIZE | CFM_FACE;
  5949. CharFormat.yHeight = 8 * 20; /* height in twips, where a twip is 1/20th of a point - for a pt.size of 18 */
  5950. _tcscpy (CharFormat.szFaceName, os_vista ? _T("Segoe UI") : _T("Tahoma"));
  5951. SendDlgItemMessage (hDlg, IDC_ERRORLOGMESSAGE, EM_SETCHARFORMAT, SCF_ALL, (LPARAM) & CharFormat);
  5952. return TRUE;
  5953. }
  5954. commonproc(hDlg, msg, wParam, lParam);
  5955. return FALSE;
  5956. }
  5957. static INT_PTR CALLBACK ContributorsProc (HWND hDlg, UINT msg, WPARAM wParam, LPARAM lParam)
  5958. {
  5959. CHARFORMAT CharFormat;
  5960. TCHAR szContributors1[MAX_CONTRIBUTORS_LENGTH];
  5961. TCHAR szContributors2[MAX_CONTRIBUTORS_LENGTH];
  5962. TCHAR szContributors[MAX_CONTRIBUTORS_LENGTH * 2];
  5963. if (dialog_inhibit)
  5964. return 0;
  5965. switch (msg) {
  5966. case WM_COMMAND:
  5967. if (wParam == ID_OK) {
  5968. EndDialog (hDlg, 1);
  5969. return TRUE;
  5970. }
  5971. break;
  5972. case WM_INITDIALOG:
  5973. CharFormat.cbSize = sizeof (CharFormat);
  5974. WIN32GUI_LoadUIString(IDS_CONTRIBUTORS1, szContributors1, MAX_CONTRIBUTORS_LENGTH);
  5975. WIN32GUI_LoadUIString(IDS_CONTRIBUTORS2, szContributors2, MAX_CONTRIBUTORS_LENGTH);
  5976. _stprintf (szContributors, _T("%s%s"), szContributors1, szContributors2);
  5977. SetDlgItemText (hDlg, IDC_CONTRIBUTORS, szContributors );
  5978. SendDlgItemMessage (hDlg, IDC_CONTRIBUTORS, EM_GETCHARFORMAT, 0, (LPARAM) & CharFormat);
  5979. CharFormat.dwMask |= CFM_SIZE | CFM_FACE;
  5980. CharFormat.yHeight = 8 * 20; /* height in twips, where a twip is 1/20th of a point - for a pt.size of 18 */
  5981. _tcscpy (CharFormat.szFaceName, os_vista ? _T("Segoe UI") : _T("Tahoma"));
  5982. SendDlgItemMessage (hDlg, IDC_CONTRIBUTORS, EM_SETCHARFORMAT, SCF_ALL, (LPARAM) & CharFormat);
  5983. return TRUE;
  5984. }
  5985. commonproc(hDlg, msg, wParam, lParam);
  5986. return FALSE;
  5987. }
  5988. static void DisplayContributors (HWND hDlg)
  5989. {
  5990. CustomDialogBox (IDD_CONTRIBUTORS, hDlg, ContributorsProc);
  5991. }
  5992. typedef struct url_info
  5993. {
  5994. int id;
  5995. BOOL state;
  5996. const TCHAR *display;
  5997. const TCHAR *url;
  5998. } urlinfo;
  5999. static urlinfo urls[] =
  6000. {
  6001. {IDC_CLOANTOHOME, FALSE, _T("Cloanto's Amiga Forever"), _T("https://www.amigaforever.com/")},
  6002. {IDC_AMIGAHOME, FALSE, _T("Amiga Corporation"), _T("https://amiga.com/")},
  6003. // {IDC_PICASSOHOME, FALSE, _T("Picasso96 Home Page"), _T("http://www.picasso96.cogito.de/")},
  6004. // {IDC_UAEHOME, FALSE, _T("UAE Home Page"), _T("http://www.amigaemulator.org/")},
  6005. {IDC_WINUAEHOME, FALSE, _T("WinUAE Home Page"), _T("http://www.winuae.net/")},
  6006. // {IDC_AIABHOME, FALSE, _T("AIAB"), _T("http://www.amigainabox.co.uk/")},
  6007. // {IDC_THEROOTS, FALSE, _T("Back To The Roots"), _T("http://back2roots.abime.net/")},
  6008. {IDC_ABIME, FALSE, _T("abime.net"), _T("http://www.abime.net/")},
  6009. {IDC_CAPS, FALSE, _T("SPS"), _T("http://www.softpres.org/")},
  6010. {IDC_AMIGASYS, FALSE, _T("AmigaSYS"), _T("http://www.amigasys.com/")},
  6011. {IDC_AMIKIT, FALSE, _T("AmiKit"), _T("http://amikit.amiga.sk/")},
  6012. { -1, FALSE, NULL, NULL }
  6013. };
  6014. static void SetupRichText(HWND hDlg, urlinfo *url)
  6015. {
  6016. CHARFORMAT CharFormat;
  6017. CharFormat.cbSize = sizeof (CharFormat);
  6018. SetDlgItemText (hDlg, url->id, url->display);
  6019. SendDlgItemMessage (hDlg, url->id, EM_GETCHARFORMAT, 0, (LPARAM)&CharFormat);
  6020. CharFormat.dwMask |= CFM_UNDERLINE | CFM_SIZE | CFM_FACE | CFM_COLOR;
  6021. CharFormat.dwEffects = url->state ? CFE_UNDERLINE : 0;
  6022. CharFormat.yHeight = 10 * 20; /* height in twips, where a twip is 1/20th of a point - for a pt.size of 18 */
  6023. CharFormat.crTextColor = GetSysColor (COLOR_ACTIVECAPTION);
  6024. _tcscpy (CharFormat.szFaceName, os_vista ? _T("Segoe UI") : _T("Tahoma"));
  6025. SendDlgItemMessage (hDlg, url->id, EM_SETCHARFORMAT, SCF_ALL, (LPARAM)&CharFormat);
  6026. SendDlgItemMessage (hDlg, url->id, EM_SETBKGNDCOLOR, 0, GetSysColor (COLOR_3DFACE));
  6027. }
  6028. static void url_handler (HWND hDlg, UINT msg, WPARAM wParam, LPARAM lParam)
  6029. {
  6030. static int last_rectangle = -1;
  6031. int i;
  6032. BOOL found = FALSE;
  6033. HCURSOR m_hCursor = NULL;
  6034. POINT point;
  6035. point.x = LOWORD (lParam);
  6036. point.y = HIWORD (lParam);
  6037. for (i = 0; urls[i].id >= 0; i++)
  6038. {
  6039. RECT rect;
  6040. GetWindowRect (GetDlgItem(hDlg, urls[i].id), &rect);
  6041. ScreenToClient (hDlg, (POINT*)&rect);
  6042. ScreenToClient (hDlg, (POINT*)&rect.right);
  6043. if (PtInRect (&rect, point))
  6044. {
  6045. if(msg == WM_LBUTTONDOWN)
  6046. {
  6047. ShellExecute (NULL, NULL, urls[i].url , NULL, NULL, SW_SHOWNORMAL);
  6048. SetCursor (LoadCursor(NULL, MAKEINTRESOURCE (IDC_ARROW)));
  6049. }
  6050. else
  6051. {
  6052. if(i != last_rectangle)
  6053. {
  6054. // try and load the system hand (Win2000+)
  6055. m_hCursor = LoadCursor (NULL, MAKEINTRESOURCE (IDC_HAND) );
  6056. if (!m_hCursor)
  6057. {
  6058. // retry with our fallback hand
  6059. m_hCursor = LoadCursor (hInst, MAKEINTRESOURCE (IDC_MYHAND) );
  6060. }
  6061. SetCursor (m_hCursor);
  6062. urls[i].state = TRUE;
  6063. SetupRichText (hDlg, &urls[i]);
  6064. if(last_rectangle != -1)
  6065. {
  6066. urls[last_rectangle].state = FALSE;
  6067. SetupRichText (hDlg, &urls[last_rectangle]);
  6068. }
  6069. }
  6070. }
  6071. last_rectangle = i;
  6072. found = TRUE;
  6073. break;
  6074. }
  6075. }
  6076. if(!found && last_rectangle >= 0)
  6077. {
  6078. SetCursor (LoadCursor (NULL, MAKEINTRESOURCE (IDC_ARROW)));
  6079. urls[last_rectangle].state = FALSE;
  6080. SetupRichText (hDlg, &urls[last_rectangle]);
  6081. last_rectangle = -1;
  6082. }
  6083. }
  6084. static void setac (HWND hDlg, int id)
  6085. {
  6086. SHAutoComplete (GetDlgItem (hDlg, id), SHACF_FILESYSTEM | SHACF_AUTOAPPEND_FORCE_ON | SHACF_AUTOSUGGEST_FORCE_ON | SHACF_USETAB);
  6087. }
  6088. static void setautocomplete (HWND hDlg, int id)
  6089. {
  6090. HWND item = FindWindowEx (GetDlgItem (hDlg, id), NULL, _T("Edit"), NULL);
  6091. if (item)
  6092. SHAutoComplete (item, SHACF_FILESYSTEM | SHACF_AUTOAPPEND_FORCE_ON | SHACF_AUTOSUGGEST_FORCE_ON | SHACF_USETAB);
  6093. }
  6094. static void setmultiautocomplete (HWND hDlg, int *ids)
  6095. {
  6096. int i;
  6097. for (i = 0; ids[i] >= 0; i++)
  6098. setautocomplete (hDlg, ids[i]);
  6099. }
  6100. static void wsetpath (HWND hDlg, const TCHAR *name, DWORD d, const TCHAR *def)
  6101. {
  6102. TCHAR tmp[MAX_DPATH];
  6103. _tcscpy (tmp, def);
  6104. fetch_path (name, tmp, sizeof (tmp) / sizeof (TCHAR));
  6105. SetDlgItemText (hDlg, d, tmp);
  6106. }
  6107. static void values_to_pathsdialog (HWND hDlg)
  6108. {
  6109. wsetpath (hDlg, _T("KickstartPath"), IDC_PATHS_ROM, _T("Roms"));
  6110. wsetpath (hDlg, _T("ConfigurationPath"), IDC_PATHS_CONFIG, _T("Configurations"));
  6111. wsetpath (hDlg, _T("ScreenshotPath"), IDC_PATHS_SCREENSHOT, _T("ScreenShots"));
  6112. wsetpath (hDlg, _T("StatefilePath"), IDC_PATHS_SAVESTATE, _T("Savestates"));
  6113. wsetpath (hDlg, _T("SaveimagePath"), IDC_PATHS_SAVEIMAGE, _T("SaveImages"));
  6114. wsetpath (hDlg, _T("VideoPath"), IDC_PATHS_AVIOUTPUT, _T("Videos"));
  6115. wsetpath (hDlg, _T("RipperPath"), IDC_PATHS_RIP, _T(".\\"));
  6116. }
  6117. static const TCHAR *pathnames[] = {
  6118. _T("KickstartPath"),
  6119. _T("ConfigurationPath"),
  6120. _T("ScreenshotPath"),
  6121. _T("StatefilePath"),
  6122. _T("SaveimagePath"),
  6123. _T("VideoPath"),
  6124. _T("RipperPath"),
  6125. _T("LuaPath"),
  6126. _T("InputPath"),
  6127. NULL
  6128. };
  6129. static void rewritepaths(void)
  6130. {
  6131. for(int i = 0; pathnames[i]; i++) {
  6132. TCHAR tmp[MAX_DPATH];
  6133. fetch_path(pathnames[i], tmp, sizeof(tmp) / sizeof TCHAR);
  6134. set_path(pathnames[i], tmp);
  6135. }
  6136. }
  6137. static void resetregistry (void)
  6138. {
  6139. regdeletetree(NULL, _T("DetectedROMs"));
  6140. regdelete(NULL, _T("QuickStartMode"));
  6141. regdelete(NULL, _T("ConfigFile"));
  6142. regdelete(NULL, _T("ConfigFileHardware"));
  6143. regdelete(NULL, _T("ConfigFileHost"));
  6144. regdelete(NULL, _T("ConfigFileHardware_Auto"));
  6145. regdelete(NULL, _T("ConfigFileHost_Auto"));
  6146. regdelete(NULL, _T("ConfigurationPath"));
  6147. regdelete(NULL, _T("SaveimagePath"));
  6148. regdelete(NULL, _T("ScreenshotPath"));
  6149. regdelete(NULL, _T("StatefilePath"));
  6150. regdelete(NULL, _T("VideoPath"));
  6151. regdelete(NULL, _T("RipperPath"));
  6152. regdelete(NULL, _T("QuickStartModel"));
  6153. regdelete(NULL, _T("QuickStartConfiguration"));
  6154. regdelete(NULL, _T("QuickStartCompatibility"));
  6155. regdelete(NULL, _T("QuickStartHostConfig"));
  6156. regdelete(NULL, _T("RecursiveROMScan"));
  6157. regdelete(NULL, _T("ConfigurationCache"));
  6158. regdelete(NULL, _T("ArtCache"));
  6159. regdelete(NULL, _T("SaveImageOriginalPath"));
  6160. regdelete(NULL, _T("RelativePaths"));
  6161. regdelete(NULL, _T("DirectDraw_Secondary"));
  6162. regdelete(NULL, _T("ShownsupportedModes"));
  6163. regdelete(NULL, _T("ArtImageCount"));
  6164. regdelete(NULL, _T("ArtImageWidth"));
  6165. }
  6166. #include "zip.h"
  6167. static void copylog (const TCHAR *name, const TCHAR *path, FILE *f)
  6168. {
  6169. FILE *s;
  6170. s = my_opentext (path);
  6171. if (s) {
  6172. fputws (_T("\n"), f);
  6173. fputws (name, f);
  6174. fputws (_T(":\n"), f);
  6175. fputws (_T("\n"), f);
  6176. for (;;) {
  6177. TCHAR buf[MAX_DPATH];
  6178. if (!fgetws (buf, sizeof buf / sizeof (TCHAR), s))
  6179. break;
  6180. fputws (buf, f);
  6181. }
  6182. fclose (s);
  6183. }
  6184. }
  6185. static void saveconfig (FILE *f)
  6186. {
  6187. int len;
  6188. uae_u8 *s;
  6189. s = save_configuration (&len, true);
  6190. if (!s)
  6191. return;
  6192. TCHAR *c = utf8u ((char*)s);
  6193. fputws (c, f);
  6194. xfree (c);
  6195. xfree (s);
  6196. }
  6197. static void zipdate(zip_fileinfo *zi)
  6198. {
  6199. SYSTEMTIME st;
  6200. FILETIME ft;
  6201. WORD dosdate, dostime;
  6202. memset(zi, 0, sizeof zip_fileinfo);
  6203. GetLocalTime (&st);
  6204. SystemTimeToFileTime (&st, &ft);
  6205. FileTimeToDosDateTime(&ft, &dosdate, &dostime);
  6206. zi->dosDate = (dosdate << 16) | dostime;
  6207. }
  6208. static void ziplog(const char *name, const TCHAR *path, zipFile zf)
  6209. {
  6210. zip_fileinfo zi;
  6211. FILE *s;
  6212. s = my_opentext (path);
  6213. if (s) {
  6214. zipdate(&zi);
  6215. if (zipOpenNewFileInZip(zf, name, &zi, NULL, 0, NULL, 0, NULL, Z_DEFLATED, Z_DEFAULT_COMPRESSION) == ZIP_OK) {
  6216. for (;;) {
  6217. TCHAR buf[MAX_DPATH];
  6218. if (!fgetws (buf, sizeof buf / sizeof (TCHAR), s))
  6219. break;
  6220. zipWriteInFileInZip(zf, buf, _tcslen(buf) * sizeof TCHAR);
  6221. }
  6222. zipCloseFileInZip(zf);
  6223. }
  6224. fclose(s);
  6225. }
  6226. }
  6227. static void zipconfig(const char *name, zipFile zf)
  6228. {
  6229. int len;
  6230. uae_u8 *s;
  6231. zip_fileinfo zi;
  6232. s = save_configuration (&len, true);
  6233. if (!s)
  6234. return;
  6235. zipdate(&zi);
  6236. if (zipOpenNewFileInZip(zf, name, &zi, NULL, 0, NULL, 0, NULL, Z_DEFLATED, Z_DEFAULT_COMPRESSION) == ZIP_OK) {
  6237. zipWriteInFileInZip(zf, s, len);
  6238. zipCloseFileInZip(zf);
  6239. }
  6240. xfree(s);
  6241. }
  6242. static void savelog (HWND hDlg, int all)
  6243. {
  6244. TCHAR tmp[MAX_DPATH], tmp2[MAX_DPATH];
  6245. TCHAR name[MAX_DPATH];
  6246. tmp[0] = 0;
  6247. _stprintf(name, _T("winuae%s_%s_%d.%d.%d.%s"),
  6248. #ifdef _WIN64
  6249. _T("64"),
  6250. #else
  6251. _T(""),
  6252. #endif
  6253. all ? _T("debug") : _T("config"),
  6254. UAEMAJOR, UAEMINOR, UAESUBREV,
  6255. all ? _T("zip") : _T("txt"));
  6256. if (all) {
  6257. OPENFILENAME openFileName = { 0 };
  6258. flush_log ();
  6259. _tcscpy(tmp, name);
  6260. _tcscpy(tmp2, tmp);
  6261. openFileName.lStructSize = sizeof (OPENFILENAME);
  6262. openFileName.hwndOwner = hDlg;
  6263. openFileName.Flags = OFN_EXPLORER | OFN_PATHMUSTEXIST | OFN_OVERWRITEPROMPT |
  6264. OFN_LONGNAMES | OFN_HIDEREADONLY | OFN_NOCHANGEDIR | OFN_ENABLESIZING;
  6265. openFileName.lpstrFile = tmp;
  6266. openFileName.lpstrFileTitle = tmp2;
  6267. openFileName.nMaxFile = MAX_DPATH;
  6268. openFileName.nMaxFileTitle = MAX_DPATH;
  6269. openFileName.lpstrDefExt = _T("zip");
  6270. // {8F1A2703-9FE0-468A-BBD7-D2336FD693E8}
  6271. static const GUID logdialogguid = { 0x8f1a2703, 0x9fe0, 0x468a, { 0xbb, 0xd7, 0xd2, 0x33, 0x6f, 0xd6, 0x93, 0xe8 } };
  6272. if (GetSaveFileName_2 (hDlg, &openFileName, &logdialogguid)) {
  6273. zipFile zf = zipOpen(openFileName.lpstrFile, 0);
  6274. if (zf) {
  6275. ziplog("winuaebootlog.txt", bootlogpath, zf);
  6276. ziplog("winuaelog.txt", logpath, zf);
  6277. zipconfig("config.uae", zf);
  6278. }
  6279. zipClose(zf, NULL);
  6280. }
  6281. } else {
  6282. if (GetTempPath (MAX_DPATH, tmp) <= 0)
  6283. return;
  6284. _tcscat(tmp, name);
  6285. FILE *f = _tfopen (tmp, _T("wt, ccs=UTF-8"));
  6286. saveconfig (f);
  6287. fclose (f);
  6288. ShellExecute (NULL, _T("open"), tmp, NULL, NULL, SW_SHOWNORMAL);
  6289. }
  6290. #if 0
  6291. if (all) {
  6292. f = _tfopen (tmp, _T("wt, ccs=UTF-8"));
  6293. copylog (_T("winuaebootlog"), bootlogpath, f);
  6294. copylog (_T("winuaelog"), logpath, f);
  6295. fputws (_T("\n"), f);
  6296. fputws (_T("configuration:\n"), f);
  6297. fputws (_T("\n"), f);
  6298. saveconfig (f);
  6299. fclose (f);
  6300. } else {
  6301. _tcscat (tmp, _T("winuae_config.txt"));
  6302. f = _tfopen (tmp, _T("wt, ccs=UTF-8"));
  6303. saveconfig (f);
  6304. fclose (f);
  6305. }
  6306. #endif
  6307. }
  6308. pathtype path_type;
  6309. static INT_PTR CALLBACK PathsDlgProc (HWND hDlg, UINT msg, WPARAM wParam, LPARAM lParam)
  6310. {
  6311. const GUID pathsguid = { 0x5674338c, 0x7a0b, 0x4565, { 0xbf, 0x75, 0x62, 0x8c, 0x80, 0x4a, 0xef, 0xf7 } };
  6312. void create_afnewdir(int);
  6313. static int recursive;
  6314. static pathtype ptypes[10];
  6315. static int numtypes;
  6316. int val, selpath = 0;
  6317. TCHAR tmp[MAX_DPATH];
  6318. if (dialog_inhibit)
  6319. return 0;
  6320. switch (msg)
  6321. {
  6322. case WM_INITDIALOG:
  6323. recursive++;
  6324. pages[PATHS_ID] = hDlg;
  6325. setac (hDlg, IDC_PATHS_ROM);
  6326. setac (hDlg, IDC_PATHS_CONFIG);
  6327. setac (hDlg, IDC_PATHS_SCREENSHOT);
  6328. setac (hDlg, IDC_PATHS_SAVESTATE);
  6329. setac (hDlg, IDC_PATHS_SAVEIMAGE);
  6330. setac (hDlg, IDC_PATHS_AVIOUTPUT);
  6331. setac (hDlg, IDC_PATHS_RIP);
  6332. CheckDlgButton(hDlg, IDC_PATHS_RECURSIVEROMS, recursiveromscan);
  6333. CheckDlgButton(hDlg, IDC_PATHS_CONFIGCACHE, configurationcache);
  6334. CheckDlgButton(hDlg, IDC_PATHS_ARTCACHE, artcache);
  6335. CheckDlgButton(hDlg, IDC_PATHS_SAVEIMAGEORIGINALPATH, saveimageoriginalpath);
  6336. CheckDlgButton(hDlg, IDC_PATHS_RELATIVE, relativepaths);
  6337. CheckDlgButton(hDlg, IDC_REGISTRYMODE, getregmode() != NULL);
  6338. currentpage = PATHS_ID;
  6339. ShowWindow (GetDlgItem (hDlg, IDC_RESETREGISTRY), FALSE);
  6340. numtypes = 0;
  6341. SendDlgItemMessage (hDlg, IDC_PATHS_DEFAULTTYPE, CB_RESETCONTENT, 0, 0L);
  6342. if (af_path_2005 & 1) {
  6343. WIN32GUI_LoadUIString (IDS_DEFAULT_AF, tmp, sizeof tmp / sizeof (TCHAR));
  6344. SendDlgItemMessage (hDlg, IDC_PATHS_DEFAULTTYPE, CB_ADDSTRING, 0, (LPARAM)tmp);
  6345. if (path_type == PATH_TYPE_NEWAF)
  6346. selpath = numtypes;
  6347. ptypes[numtypes++] = PATH_TYPE_NEWAF;
  6348. }
  6349. if (start_path_new1[0]) {
  6350. WIN32GUI_LoadUIString (IDS_DEFAULT_NEWWINUAE, tmp, sizeof tmp / sizeof (TCHAR));
  6351. SendDlgItemMessage (hDlg, IDC_PATHS_DEFAULTTYPE, CB_ADDSTRING, 0, (LPARAM)tmp);
  6352. if (path_type == PATH_TYPE_NEWWINUAE)
  6353. selpath = numtypes;
  6354. ptypes[numtypes++] = PATH_TYPE_NEWWINUAE;
  6355. }
  6356. if ((af_path_2005 & 3) == 2) {
  6357. SendDlgItemMessage (hDlg, IDC_PATHS_DEFAULTTYPE, CB_ADDSTRING, 0, (LPARAM)_T("AmigaForeverData"));
  6358. if (path_type == PATH_TYPE_AMIGAFOREVERDATA)
  6359. selpath = numtypes;
  6360. ptypes[numtypes++] = PATH_TYPE_AMIGAFOREVERDATA;
  6361. }
  6362. WIN32GUI_LoadUIString (IDS_DEFAULT_WINUAE, tmp, sizeof tmp / sizeof (TCHAR));
  6363. SendDlgItemMessage (hDlg, IDC_PATHS_DEFAULTTYPE, CB_ADDSTRING, 0, (LPARAM)tmp);
  6364. if (path_type == PATH_TYPE_WINUAE || path_type == PATH_TYPE_DEFAULT)
  6365. selpath = numtypes;
  6366. ptypes[numtypes++] = PATH_TYPE_WINUAE;
  6367. SendDlgItemMessage (hDlg, IDC_PATHS_DEFAULTTYPE, CB_SETCURSEL, selpath, 0);
  6368. EnableWindow (GetDlgItem (hDlg, IDC_PATHS_DEFAULTTYPE), numtypes > 0 ? TRUE : FALSE);
  6369. SetWindowText (GetDlgItem (hDlg, IDC_LOGPATH), bootlogpath);
  6370. SendDlgItemMessage (hDlg, IDC_LOGSELECT, CB_RESETCONTENT, 0, 0);
  6371. SendDlgItemMessage (hDlg, IDC_LOGSELECT, CB_ADDSTRING, 0, (LPARAM)_T("winuaebootlog.txt"));
  6372. SendDlgItemMessage (hDlg, IDC_LOGSELECT, CB_ADDSTRING, 0, (LPARAM)_T("winuaelog.txt"));
  6373. WIN32GUI_LoadUIString (IDS_CURRENT_CONFIGURATION, tmp, sizeof tmp / sizeof (TCHAR));
  6374. SendDlgItemMessage (hDlg, IDC_LOGSELECT, CB_ADDSTRING, 0, (LPARAM)tmp);
  6375. SendDlgItemMessage (hDlg, IDC_LOGSELECT, CB_SETCURSEL, 0, 0);
  6376. CheckDlgButton (hDlg, IDC_LOGENABLE, winuaelog_temporary_enable || (full_property_sheet == 0 && currprefs.win32_logfile));
  6377. ew (hDlg, IDC_LOGENABLE, winuaelog_temporary_enable == false && full_property_sheet);
  6378. extern int consoleopen;
  6379. if (consoleopen || !full_property_sheet) {
  6380. CheckDlgButton (hDlg, IDC_LOGENABLE2, consoleopen ? TRUE : FALSE);
  6381. ew (hDlg, IDC_LOGENABLE2, FALSE);
  6382. }
  6383. values_to_pathsdialog (hDlg);
  6384. recursive--;
  6385. return TRUE;
  6386. case WM_COMMAND:
  6387. if (recursive > 0)
  6388. break;
  6389. recursive++;
  6390. if (HIWORD (wParam) == CBN_SELCHANGE || HIWORD (wParam) == CBN_KILLFOCUS) {
  6391. switch (LOWORD (wParam))
  6392. {
  6393. case IDC_LOGSELECT:
  6394. val = SendDlgItemMessage (hDlg, IDC_LOGSELECT, CB_GETCURSEL, 0, 0L);
  6395. if (val == 0) {
  6396. SetWindowText (GetDlgItem (hDlg, IDC_LOGPATH), bootlogpath);
  6397. ew (hDlg, IDC_LOGOPEN, bootlogpath[0]);
  6398. } else if (val == 1) {
  6399. SetWindowText (GetDlgItem (hDlg, IDC_LOGPATH), logpath);
  6400. ew (hDlg, IDC_LOGOPEN, logpath[0]);
  6401. } else if (val == 2) {
  6402. SetWindowText (GetDlgItem (hDlg, IDC_LOGPATH), _T("Configuration"));
  6403. ew (hDlg, IDC_LOGOPEN, TRUE);
  6404. }
  6405. break;
  6406. }
  6407. } else {
  6408. switch (LOWORD (wParam))
  6409. {
  6410. case IDC_REGISTRYMODE:
  6411. bool switchreginimode(void);
  6412. switchreginimode();
  6413. CheckDlgButton(hDlg, IDC_REGISTRYMODE, getregmode() != NULL);
  6414. break;
  6415. case IDC_LOGSAVE:
  6416. savelog (hDlg, 1);
  6417. break;
  6418. case IDC_LOGENABLE:
  6419. winuaelog_temporary_enable = ischecked (hDlg, IDC_LOGENABLE);
  6420. break;
  6421. case IDC_LOGENABLE2:
  6422. extern int console_logging;
  6423. console_logging = 1;
  6424. break;
  6425. case IDC_LOGOPEN:
  6426. flush_log ();
  6427. val = SendDlgItemMessage (hDlg, IDC_LOGSELECT, CB_GETCURSEL, 0, 0L);
  6428. if (val == 0) {
  6429. if (bootlogpath[0])
  6430. ShellExecute (NULL, _T("open"), bootlogpath, NULL, NULL, SW_SHOWNORMAL);
  6431. } else if (val == 1) {
  6432. if (logpath[0])
  6433. ShellExecute (NULL, _T("open"), logpath, NULL, NULL, SW_SHOWNORMAL);
  6434. } else if (val == 2) {
  6435. savelog (hDlg, 0);
  6436. }
  6437. break;
  6438. case IDC_PATHS_ROMS:
  6439. fetch_path (_T("KickstartPath"), tmp, sizeof (tmp) / sizeof (TCHAR));
  6440. if (DirectorySelection (hDlg, &pathsguid, tmp)) {
  6441. load_keyring (&workprefs, NULL);
  6442. set_path (_T("KickstartPath"), tmp);
  6443. if (!scan_roms (hDlg, 1))
  6444. gui_message_id (IDS_ROMSCANNOROMS);
  6445. values_to_pathsdialog (hDlg);
  6446. }
  6447. break;
  6448. case IDC_PATHS_ROM:
  6449. GetWindowText (GetDlgItem (hDlg, IDC_PATHS_ROM), tmp, sizeof (tmp) / sizeof (TCHAR));
  6450. set_path (_T("KickstartPath"), tmp);
  6451. break;
  6452. case IDC_PATHS_CONFIGS:
  6453. fetch_path (_T("ConfigurationPath"), tmp, sizeof (tmp) / sizeof (TCHAR));
  6454. if (DirectorySelection (hDlg, &pathsguid, tmp)) {
  6455. set_path (_T("ConfigurationPath"), tmp);
  6456. values_to_pathsdialog (hDlg);
  6457. FreeConfigStore ();
  6458. }
  6459. break;
  6460. case IDC_PATHS_CONFIG:
  6461. GetWindowText (GetDlgItem (hDlg, IDC_PATHS_CONFIG), tmp, sizeof (tmp) / sizeof (TCHAR));
  6462. set_path (_T("ConfigurationPath"), tmp);
  6463. FreeConfigStore ();
  6464. break;
  6465. case IDC_PATHS_SCREENSHOTS:
  6466. fetch_path (_T("ScreenshotPath"), tmp, sizeof (tmp) / sizeof (TCHAR));
  6467. if (DirectorySelection (hDlg, &pathsguid, tmp)) {
  6468. set_path (_T("ScreenshotPath"), tmp);
  6469. values_to_pathsdialog (hDlg);
  6470. }
  6471. break;
  6472. case IDC_PATHS_SCREENSHOT:
  6473. GetWindowText (GetDlgItem (hDlg, IDC_PATHS_SCREENSHOT), tmp, sizeof (tmp) / sizeof (TCHAR));
  6474. set_path (_T("ScreenshotPath"), tmp);
  6475. break;
  6476. case IDC_PATHS_SAVESTATES:
  6477. fetch_path (_T("StatefilePath"), tmp, sizeof (tmp) / sizeof (TCHAR));
  6478. if (DirectorySelection (hDlg, &pathsguid, tmp)) {
  6479. set_path (_T("StatefilePath"), tmp);
  6480. values_to_pathsdialog (hDlg);
  6481. }
  6482. break;
  6483. case IDC_PATHS_SAVESTATE:
  6484. GetWindowText (GetDlgItem (hDlg, IDC_PATHS_SAVESTATE), tmp, sizeof (tmp) / sizeof (TCHAR));
  6485. set_path (_T("StatefilePath"), tmp);
  6486. break;
  6487. case IDC_PATHS_SAVEIMAGES:
  6488. fetch_path (_T("SaveimagePath"), tmp, sizeof (tmp) / sizeof (TCHAR));
  6489. if (DirectorySelection (hDlg, &pathsguid, tmp)) {
  6490. set_path (_T("SaveimagePath"), tmp);
  6491. values_to_pathsdialog (hDlg);
  6492. }
  6493. break;
  6494. case IDC_PATHS_SAVEIMAGE:
  6495. GetWindowText (GetDlgItem (hDlg, IDC_PATHS_SAVEIMAGE), tmp, sizeof (tmp) / sizeof (TCHAR));
  6496. set_path (_T("SaveimagePath"), tmp);
  6497. break;
  6498. case IDC_PATHS_AVIOUTPUTS:
  6499. fetch_path (_T("VideoPath"), tmp, sizeof (tmp) / sizeof (TCHAR));
  6500. if (DirectorySelection (hDlg, &pathsguid, tmp)) {
  6501. set_path (_T("VideoPath"), tmp);
  6502. values_to_pathsdialog (hDlg);
  6503. }
  6504. break;
  6505. case IDC_PATHS_RIPS:
  6506. fetch_path (_T("RipperPath"), tmp, sizeof (tmp) / sizeof (TCHAR));
  6507. if (DirectorySelection (hDlg, &pathsguid, tmp)) {
  6508. set_path (_T("RipperPath"), tmp);
  6509. values_to_pathsdialog (hDlg);
  6510. }
  6511. break;
  6512. case IDC_PATHS_AVIOUTPUT:
  6513. GetWindowText (GetDlgItem (hDlg, IDC_PATHS_AVIOUTPUT), tmp, sizeof (tmp) / sizeof (TCHAR));
  6514. set_path (_T("VideoPath"), tmp);
  6515. break;
  6516. case IDC_PATHS_RIP:
  6517. GetWindowText (GetDlgItem (hDlg, IDC_PATHS_RIP), tmp, sizeof (tmp) / sizeof (TCHAR));
  6518. set_path (_T("RipperPath"), tmp);
  6519. break;
  6520. case IDC_PATHS_DEFAULT:
  6521. val = SendDlgItemMessage (hDlg, IDC_PATHS_DEFAULTTYPE, CB_GETCURSEL, 0, 0L);
  6522. if (val != CB_ERR && val >= 0 && val < numtypes) {
  6523. val = ptypes[val];
  6524. if (val == PATH_TYPE_WINUAE) {
  6525. _tcscpy (start_path_data, start_path_exe);
  6526. path_type = PATH_TYPE_WINUAE;
  6527. } else if (val == PATH_TYPE_NEWWINUAE && start_path_new1[0]) {
  6528. _tcscpy (start_path_data, start_path_new1);
  6529. path_type = PATH_TYPE_NEWWINUAE;
  6530. create_afnewdir(0);
  6531. } else if (val == PATH_TYPE_NEWAF && start_path_new1[0]) {
  6532. path_type = PATH_TYPE_NEWAF;
  6533. create_afnewdir(0);
  6534. _tcscpy (start_path_data, start_path_new1);
  6535. } else if (val == PATH_TYPE_AMIGAFOREVERDATA && start_path_new2[0]) {
  6536. path_type = PATH_TYPE_AMIGAFOREVERDATA;
  6537. _tcscpy (start_path_data, start_path_new1);
  6538. }
  6539. SetCurrentDirectory (start_path_data);
  6540. setpathmode (path_type);
  6541. set_path (_T("KickstartPath"), NULL, path_type);
  6542. set_path (_T("ConfigurationPath"), NULL, path_type);
  6543. set_path (_T("ScreenshotPath"), NULL, path_type);
  6544. set_path (_T("StatefilePath"), NULL, path_type);
  6545. set_path (_T("SaveimagePath"), NULL, path_type);
  6546. set_path (_T("VideoPath"), NULL, path_type);
  6547. set_path (_T("RipperPath"), NULL, path_type);
  6548. set_path (_T("InputPath"), NULL, path_type);
  6549. values_to_pathsdialog (hDlg);
  6550. FreeConfigStore ();
  6551. }
  6552. break;
  6553. case IDC_ROM_RESCAN:
  6554. scan_roms (hDlg, 1);
  6555. break;
  6556. case IDC_RESETREGISTRY:
  6557. resetregistry ();
  6558. break;
  6559. case IDC_RESETDISKHISTORY:
  6560. reset_disk_history ();
  6561. break;
  6562. case IDC_PATHS_RECURSIVEROMS:
  6563. recursiveromscan = ischecked (hDlg, IDC_PATHS_RECURSIVEROMS) ? 2 : 0;
  6564. regsetint (NULL, _T("RecursiveROMScan"), recursiveromscan);
  6565. break;
  6566. case IDC_PATHS_CONFIGCACHE:
  6567. configurationcache = ischecked(hDlg, IDC_PATHS_CONFIGCACHE) ? 1 : 0;
  6568. regsetint(NULL, _T("ConfigurationCache"), configurationcache);
  6569. deleteconfigcache();
  6570. break;
  6571. case IDC_PATHS_ARTCACHE:
  6572. artcache = ischecked(hDlg, IDC_PATHS_ARTCACHE) ? 1 : 0;
  6573. regsetint(NULL, _T("ArtCache"), artcache);
  6574. deleteconfigcache();
  6575. break;
  6576. case IDC_PATHS_SAVEIMAGEORIGINALPATH:
  6577. saveimageoriginalpath = ischecked (hDlg, IDC_PATHS_SAVEIMAGEORIGINALPATH) ? 1 : 0;
  6578. regsetint (NULL, _T("SaveImageOriginalPath"), saveimageoriginalpath);
  6579. break;
  6580. case IDC_PATHS_RELATIVE:
  6581. relativepaths = ischecked (hDlg, IDC_PATHS_RELATIVE) ? 1 : 0;
  6582. regsetint (NULL, _T("RelativePaths"), relativepaths);
  6583. rewritepaths();
  6584. break;
  6585. }
  6586. }
  6587. recursive--;
  6588. }
  6589. return FALSE;
  6590. }
  6591. struct amigamodels {
  6592. int compalevels;
  6593. int id;
  6594. int resetlevels[6];
  6595. };
  6596. static struct amigamodels amodels[] = {
  6597. { 4, IDS_QS_MODEL_A500, { 0, 0, 0, 0, 0, 0 } }, // "Amiga 500"
  6598. { 4, IDS_QS_MODEL_A500P, { 0, 0, 0, 0, 0, 0 } }, // "Amiga 500+"
  6599. { 4, IDS_QS_MODEL_A600, { 0, 0, 1, 0, 0, 0 } }, // "Amiga 600"
  6600. { 4, IDS_QS_MODEL_A1000, { 0, 0, 0, 0, 0, 0 } }, // "Amiga 1000"
  6601. { 5, IDS_QS_MODEL_A1200, { 0, 1, 2, 3, 4, 5 } }, // "Amiga 1200"
  6602. { 2, IDS_QS_MODEL_A3000, { 0, 0, 0, 0, 0, 0 } }, // "Amiga 3000"
  6603. { 1, IDS_QS_MODEL_A4000, { 0, 0, 1, 0, 0, 0 } }, // "Amiga 4000"
  6604. { 0, }, //{ 1, IDS_QS_MODEL_A4000T }, // "Amiga 4000T"
  6605. { 4, IDS_QS_MODEL_CD32, { 0, 0, 1, 0, 0, 0 } }, // "CD32"
  6606. { 4, IDS_QS_MODEL_CDTV, { 0, 0, 1, 0, 0, 0 } }, // "CDTV"
  6607. { 4, IDS_QS_MODEL_ARCADIA, { 0, 0, 0, 0, 0, 0 } }, // "Arcadia"
  6608. { 1, IDS_QS_MODEL_MACROSYSTEM, { 0, 0, 0, 0, 0, 0 } },
  6609. { 1, IDS_QS_MODEL_UAE, { 0, 0, 0, 0, 0, 0 } }, // "Expanded UAE example configuration"
  6610. { -1 }
  6611. };
  6612. static void enable_for_quickstart (HWND hDlg)
  6613. {
  6614. int v = quickstart_ok && quickstart_ok_floppy ? TRUE : FALSE;
  6615. ew (guiDlg, IDC_RESETAMIGA, !full_property_sheet ? TRUE : FALSE);
  6616. ShowWindow (GetDlgItem (hDlg, IDC_QUICKSTART_SETCONFIG), quickstart ? SW_HIDE : SW_SHOW);
  6617. }
  6618. static void load_quickstart (HWND hDlg, int romcheck)
  6619. {
  6620. ew (guiDlg, IDC_RESETAMIGA, FALSE);
  6621. workprefs.nr_floppies = quickstart_floppy;
  6622. quickstart_ok = built_in_prefs (&workprefs, quickstart_model, quickstart_conf, quickstart_compa, romcheck);
  6623. workprefs.ntscmode = quickstart_ntsc != 0;
  6624. quickstart_cd = workprefs.floppyslots[1].dfxtype == DRV_NONE && (quickstart_model == 8 || quickstart_model == 9);
  6625. // DF0: HD->DD
  6626. if (quickstart_model <= 4) {
  6627. if (quickstart_floppytype[0] == 1) {
  6628. quickstart_floppytype[0] = 0;
  6629. }
  6630. }
  6631. for (int i = 0; i < 2; i++) {
  6632. if (i < quickstart_floppy) {
  6633. workprefs.floppyslots[i].dfxtype = quickstart_floppytype[i];
  6634. workprefs.floppyslots[i].dfxsubtype = quickstart_floppysubtype[i];
  6635. _tcscpy(workprefs.floppyslots[i].dfxsubtypeid, quickstart_floppysubtypeid[i]);
  6636. } else {
  6637. workprefs.floppyslots[i].dfxtype = DRV_NONE;
  6638. workprefs.floppyslots[i].dfxsubtype = 0;
  6639. workprefs.floppyslots[i].dfxsubtypeid[0] = 0;
  6640. }
  6641. }
  6642. floppybridge_init(&workprefs);
  6643. enable_for_quickstart (hDlg);
  6644. addfloppytype (hDlg, 0);
  6645. addfloppytype (hDlg, 1);
  6646. addfloppyhistory (hDlg);
  6647. config_filename[0] = 0;
  6648. setguititle (NULL);
  6649. }
  6650. static void quickstarthost (HWND hDlg, TCHAR *name)
  6651. {
  6652. int type = CONFIG_TYPE_HOST;
  6653. TCHAR tmp[MAX_DPATH];
  6654. if (getconfigstorefrompath (name, tmp, CONFIG_TYPE_HOST)) {
  6655. if (cfgfile_load (&workprefs, tmp, &type, 1, 0))
  6656. workprefs.start_gui = 1;
  6657. }
  6658. }
  6659. static void init_quickstartdlg_tooltip (HWND hDlg, TCHAR *tt)
  6660. {
  6661. TOOLINFO ti;
  6662. ti.cbSize = sizeof (TOOLINFO);
  6663. ti.uFlags = TTF_SUBCLASS | TTF_IDISHWND;
  6664. ti.hwnd = hDlg;
  6665. ti.hinst = hInst;
  6666. ti.uId = (UINT_PTR)GetDlgItem (hDlg, IDC_QUICKSTART_CONFIGURATION);
  6667. ti.lpszText = tt;
  6668. SendMessage (ToolTipHWND, TTM_DELTOOL, 0, (LPARAM) (LPTOOLINFO) &ti);
  6669. if (!tt)
  6670. return;
  6671. SendMessage (ToolTipHWND, TTM_ADDTOOL, 0, (LPARAM) (LPTOOLINFO) &ti);
  6672. }
  6673. static void init_quickstartdlg (HWND hDlg)
  6674. {
  6675. static int firsttime;
  6676. int i, j, idx, idx2, qssize, total;
  6677. TCHAR tmp1[2 * MAX_DPATH], tmp2[MAX_DPATH], hostconf[MAX_DPATH];
  6678. TCHAR *p1, *p2;
  6679. firstautoloadconfig = false;
  6680. qssize = sizeof (tmp1) / sizeof (TCHAR);
  6681. regquerystr (NULL, _T("QuickStartHostConfig"), hostconf, &qssize);
  6682. if (firsttime == 0 && workprefs.start_gui) {
  6683. int size;
  6684. regqueryint(NULL, _T("QuickStartModel"), &quickstart_model);
  6685. regqueryint(NULL, _T("QuickStartConfiguration"), &quickstart_conf);
  6686. quickstart_model_confstore[quickstart_model] = quickstart_conf;
  6687. regqueryint(NULL, _T("QuickStartCompatibility"), &quickstart_compa);
  6688. regqueryint(NULL, _T("QuickStartFloppies"), &quickstart_floppy);
  6689. regqueryint(NULL, _T("QuickStartDF0Type"), &quickstart_floppytype[0]);
  6690. regqueryint(NULL, _T("QuickStartDF1Type"), &quickstart_floppytype[1]);
  6691. regqueryint(NULL, _T("QuickStartDF0SubType"), &quickstart_floppysubtype[0]);
  6692. regqueryint(NULL, _T("QuickStartDF1SubType"), &quickstart_floppysubtype[1]);
  6693. size = 30;
  6694. regquerystr(NULL, _T("QuickStartDF0SubTypeID"), quickstart_floppysubtypeid[0], &size);
  6695. size = 30;
  6696. regquerystr(NULL, _T("QuickStartDF1SubTypeID"), quickstart_floppysubtypeid[1], &size);
  6697. regqueryint(NULL, _T("QuickStartCDType"), &quickstart_cdtype);
  6698. size = sizeof quickstart_cddrive / sizeof (TCHAR);
  6699. regquerystr(NULL, _T("QuickStartCDDrive"), quickstart_cddrive, &size);
  6700. regqueryint(NULL, _T("QuickStartNTSC"), &quickstart_ntsc);
  6701. if (quickstart) {
  6702. workprefs.floppyslots[0].df[0] = 0;
  6703. workprefs.floppyslots[1].df[0] = 0;
  6704. workprefs.floppyslots[2].df[0] = 0;
  6705. workprefs.floppyslots[3].df[0] = 0;
  6706. workprefs.cdslots[0].name[0] = 0;
  6707. workprefs.cdslots[0].inuse = quickstart_cdtype > 0;
  6708. load_quickstart (hDlg, 1);
  6709. quickstarthost (hDlg, hostconf);
  6710. }
  6711. }
  6712. firsttime = 1;
  6713. CheckDlgButton (hDlg, IDC_QUICKSTARTMODE, quickstart);
  6714. CheckDlgButton (hDlg, IDC_NTSC, quickstart_ntsc != 0);
  6715. WIN32GUI_LoadUIString (IDS_QS_MODELS, tmp1, sizeof (tmp1) / sizeof (TCHAR));
  6716. _tcscat (tmp1, _T("\n"));
  6717. p1 = tmp1;
  6718. SendDlgItemMessage (hDlg, IDC_QUICKSTART_MODEL, CB_RESETCONTENT, 0, 0L);
  6719. idx = idx2 = 0;
  6720. i = 0;
  6721. while (amodels[i].compalevels >= 0) {
  6722. if (amodels[i].compalevels > 0) {
  6723. p2 = _tcschr (p1, '\n');
  6724. if (p2 && _tcslen (p2) > 0) {
  6725. *p2++ = 0;
  6726. SendDlgItemMessage (hDlg, IDC_QUICKSTART_MODEL, CB_ADDSTRING, 0, (LPARAM)p1);
  6727. p1 = p2;
  6728. }
  6729. if (i == quickstart_model)
  6730. idx2 = idx;
  6731. idx++;
  6732. }
  6733. i++;
  6734. }
  6735. SendDlgItemMessage (hDlg, IDC_QUICKSTART_MODEL, CB_SETCURSEL, idx2, 0);
  6736. total = 0;
  6737. SendDlgItemMessage (hDlg, IDC_QUICKSTART_CONFIGURATION, CB_RESETCONTENT, 0, 0L);
  6738. if (amodels[quickstart_model].id == IDS_QS_MODEL_ARCADIA) {
  6739. struct romlist **rl = getarcadiaroms ();
  6740. for (i = 0; rl[i]; i++) {
  6741. SendDlgItemMessage (hDlg, IDC_QUICKSTART_CONFIGURATION, CB_ADDSTRING, 0, (LPARAM)rl[i]->rd->name);
  6742. total++;
  6743. }
  6744. xfree (rl);
  6745. } else {
  6746. WIN32GUI_LoadUIString (amodels[quickstart_model].id, tmp1, sizeof (tmp1) / sizeof (TCHAR));
  6747. _tcscat (tmp1, _T("\n"));
  6748. p1 = tmp1;
  6749. init_quickstartdlg_tooltip (hDlg, 0);
  6750. total = 0;
  6751. for (;;) {
  6752. p2 = _tcschr (p1, '\n');
  6753. if (!p2)
  6754. break;
  6755. *p2++= 0;
  6756. SendDlgItemMessage (hDlg, IDC_QUICKSTART_CONFIGURATION, CB_ADDSTRING, 0, (LPARAM)p1);
  6757. p1 = p2;
  6758. p2 = _tcschr (p1, '\n');
  6759. if (!p2)
  6760. break;
  6761. *p2++= 0;
  6762. if (quickstart_conf == total && _tcslen (p1) > 0)
  6763. init_quickstartdlg_tooltip (hDlg, p1);
  6764. p1 = p2;
  6765. total++;
  6766. }
  6767. }
  6768. if (quickstart_conf >= total)
  6769. quickstart_conf = 0;
  6770. SendDlgItemMessage (hDlg, IDC_QUICKSTART_CONFIGURATION, CB_SETCURSEL, quickstart_conf, 0);
  6771. if (quickstart_compa >= amodels[quickstart_model].compalevels)
  6772. quickstart_compa = 1;
  6773. if (quickstart_compa >= amodels[quickstart_model].compalevels)
  6774. quickstart_compa = 0;
  6775. i = amodels[quickstart_model].compalevels;
  6776. ew (hDlg, IDC_QUICKSTART_COMPATIBILITY, i > 1);
  6777. SendDlgItemMessage (hDlg, IDC_QUICKSTART_COMPATIBILITY, TBM_SETRANGE, TRUE, MAKELONG (0, i > 1 ? i - 1 : 1));
  6778. SendDlgItemMessage (hDlg, IDC_QUICKSTART_COMPATIBILITY, TBM_SETPAGESIZE, 0, 1);
  6779. SendDlgItemMessage (hDlg, IDC_QUICKSTART_COMPATIBILITY, TBM_SETPOS, TRUE, quickstart_compa);
  6780. SendDlgItemMessage (hDlg, IDC_QUICKSTART_HOSTCONFIG, CB_RESETCONTENT, 0, 0L);
  6781. WIN32GUI_LoadUIString (IDS_DEFAULT_HOST, tmp1, sizeof (tmp1) / sizeof (TCHAR));
  6782. SendDlgItemMessage (hDlg, IDC_QUICKSTART_HOSTCONFIG, CB_ADDSTRING, 0, (LPARAM)tmp1);
  6783. idx = 0;
  6784. j = 1;
  6785. for (i = 0; i < configstoresize; i++) {
  6786. if (configstore[i]->Type == CONFIG_TYPE_HOST) {
  6787. _tcscpy (tmp2, configstore[i]->Path);
  6788. _tcsncat (tmp2, configstore[i]->Name, MAX_DPATH - _tcslen(tmp2));
  6789. if (!_tcscmp (tmp2, hostconf))
  6790. idx = j;
  6791. SendDlgItemMessage (hDlg, IDC_QUICKSTART_HOSTCONFIG, CB_ADDSTRING, 0, (LPARAM)tmp2);
  6792. j++;
  6793. }
  6794. }
  6795. SendDlgItemMessage (hDlg, IDC_QUICKSTART_HOSTCONFIG, CB_SETCURSEL, idx, 0);
  6796. regsetint (NULL, _T("QuickStartModel"), quickstart_model);
  6797. regsetint (NULL, _T("QuickStartConfiguration"), quickstart_conf);
  6798. regsetint (NULL, _T("QuickStartCompatibility"), quickstart_compa);
  6799. }
  6800. static void floppytooltip (HWND hDlg, int num, uae_u32 crc32);
  6801. static void testimage (HWND hDlg, int num)
  6802. {
  6803. int ret;
  6804. int reload = 0;
  6805. struct diskinfo di;
  6806. int messageid = -1;
  6807. TCHAR tmp[MAX_DPATH];
  6808. floppytooltip (hDlg, num, 0);
  6809. quickstart_ok_floppy = 0;
  6810. if (workprefs.floppyslots[0].dfxtype < 0) {
  6811. quickstart_ok_floppy = 1;
  6812. return;
  6813. }
  6814. if (!workprefs.floppyslots[num].df[0])
  6815. return;
  6816. floppybridge_init(&workprefs);
  6817. ret = DISK_examine_image (&workprefs, num, &di, false, NULL);
  6818. if (!ret)
  6819. return;
  6820. floppytooltip (hDlg, num, di.imagecrc32);
  6821. if (num > 0)
  6822. return;
  6823. if (!full_property_sheet)
  6824. return;
  6825. switch (ret)
  6826. {
  6827. case 10:
  6828. quickstart_ok_floppy = 1;
  6829. break;
  6830. case 11:
  6831. quickstart_ok_floppy = 1;
  6832. if (quickstart_model != 1 && quickstart_model != 2 && quickstart_model != 4 &&
  6833. quickstart_model != 5 && quickstart_model != 6 && quickstart_model != 8 && quickstart_model != 11) {
  6834. quickstart_model = 4;
  6835. messageid = IDS_IMGCHK_KS2;
  6836. reload = 1;
  6837. }
  6838. break;
  6839. case 12:
  6840. quickstart_ok_floppy = 1;
  6841. if (quickstart_model != 4 && quickstart_model != 8 && quickstart_model != 11) {
  6842. quickstart_model = 4;
  6843. messageid = IDS_IMGCHK_KS3;
  6844. reload = 1;
  6845. }
  6846. break;
  6847. case 4:
  6848. messageid = IDS_IMGCHK_BOOTBLOCKNO;
  6849. break;
  6850. case 3:
  6851. messageid = IDS_IMGCHK_BOOTBLOCKCRCERROR;
  6852. break;
  6853. case 2:
  6854. messageid = IDS_IMGCHK_DAMAGED;
  6855. break;
  6856. }
  6857. if (messageid > 0) {
  6858. WIN32GUI_LoadUIString (messageid, tmp, sizeof (tmp) / sizeof (TCHAR));
  6859. gui_message (tmp);
  6860. }
  6861. if (reload && quickstart) {
  6862. load_quickstart (hDlg, 1);
  6863. init_quickstartdlg (hDlg);
  6864. }
  6865. }
  6866. static INT_PTR CALLBACK FloppyDlgProc (HWND hDlg, UINT msg, WPARAM wParam, LPARAM lParam);
  6867. static int diskselectmenu (HWND hDlg, WPARAM wParam);
  6868. static void addallfloppies (HWND hDlg);
  6869. #define BUTTONSPERFLOPPY 9
  6870. static const int floppybuttons[][BUTTONSPERFLOPPY] = {
  6871. { IDC_DF0TEXT,IDC_DF0,IDC_EJECT0,IDC_DF0TYPE,IDC_DF0WP,-1,IDC_SAVEIMAGE0,IDC_DF0ENABLE, IDC_INFO0 },
  6872. { IDC_DF1TEXT,IDC_DF1,IDC_EJECT1,IDC_DF1TYPE,IDC_DF1WP,-1,IDC_SAVEIMAGE1,IDC_DF1ENABLE, IDC_INFO1 },
  6873. { IDC_DF2TEXT,IDC_DF2,IDC_EJECT2,IDC_DF2TYPE,IDC_DF2WP,-1,IDC_SAVEIMAGE2,IDC_DF2ENABLE, IDC_INFO2 },
  6874. { IDC_DF3TEXT,IDC_DF3,IDC_EJECT3,IDC_DF3TYPE,IDC_DF3WP,-1,IDC_SAVEIMAGE3,IDC_DF3ENABLE, IDC_INFO3 }
  6875. };
  6876. static const int floppybuttonsq[][BUTTONSPERFLOPPY] = {
  6877. { IDC_DF0TEXTQ,IDC_DF0QQ,IDC_EJECT0Q,IDC_DF0TYPE,IDC_DF0WPQ,IDC_DF0WPTEXTQ,-1,IDC_DF0QENABLE, IDC_INFO0Q },
  6878. { IDC_DF1TEXTQ,IDC_DF1QQ,IDC_EJECT1Q,IDC_DF1TYPE,IDC_DF1WPQ,IDC_DF1WPTEXTQ,-1,IDC_DF1QENABLE, IDC_INFO1Q },
  6879. { -1,-1,-1,-1,-1,-1,-1,-1 },
  6880. { -1,-1,-1,-1,-1,-1,-1,-1 }
  6881. };
  6882. static int fromdfxtype(int num, int dfx, int subtype)
  6883. {
  6884. if (currentpage == QUICKSTART_ID) {
  6885. switch (dfx)
  6886. {
  6887. case DRV_35_DD:
  6888. return 0;
  6889. case DRV_35_HD:
  6890. return 1;
  6891. }
  6892. if (dfx == DRV_FB) {
  6893. return 2 + subtype;
  6894. }
  6895. return -1;
  6896. }
  6897. switch (dfx)
  6898. {
  6899. case DRV_35_DD:
  6900. return 0;
  6901. case DRV_35_HD:
  6902. return 1;
  6903. case DRV_525_SD:
  6904. return 2;
  6905. case DRV_525_DD:
  6906. return 3;
  6907. case DRV_35_DD_ESCOM:
  6908. return 4;
  6909. }
  6910. if (num < 2) {
  6911. if (dfx == DRV_FB) {
  6912. return 5 + subtype;
  6913. }
  6914. } else {
  6915. switch (dfx)
  6916. {
  6917. case DRV_PC_525_ONLY_40:
  6918. return 5;
  6919. case DRV_PC_525_40_80:
  6920. return 6;
  6921. case DRV_PC_35_ONLY_80:
  6922. return 7;
  6923. }
  6924. if (dfx == DRV_FB) {
  6925. return 8 + subtype;
  6926. }
  6927. }
  6928. return -1;
  6929. }
  6930. static int todfxtype(int num, int dfx, int *subtype)
  6931. {
  6932. *subtype = 0;
  6933. if (currentpage == QUICKSTART_ID) {
  6934. switch (dfx)
  6935. {
  6936. case 0:
  6937. return DRV_35_DD;
  6938. case 1:
  6939. return DRV_35_HD;
  6940. }
  6941. if (dfx >= 2) {
  6942. *subtype = dfx - 2;
  6943. return DRV_FB;
  6944. }
  6945. return -1;
  6946. }
  6947. switch (dfx)
  6948. {
  6949. case 0:
  6950. return DRV_35_DD;
  6951. case 1:
  6952. return DRV_35_HD;
  6953. case 2:
  6954. return DRV_525_SD;
  6955. case 3:
  6956. return DRV_525_DD;
  6957. case 4:
  6958. return DRV_35_DD_ESCOM;
  6959. }
  6960. if (num < 2) {
  6961. if (dfx >= 5) {
  6962. *subtype = dfx - 5;
  6963. return DRV_FB;
  6964. }
  6965. } else {
  6966. switch (dfx)
  6967. {
  6968. case 5:
  6969. return DRV_PC_525_ONLY_40;
  6970. case 6:
  6971. return DRV_PC_525_40_80;
  6972. case 7:
  6973. return DRV_PC_35_ONLY_80;
  6974. }
  6975. if (dfx >= 8) {
  6976. *subtype = dfx - 8;
  6977. return DRV_FB;
  6978. }
  6979. }
  6980. return -1;
  6981. }
  6982. static void setfloppytexts (HWND hDlg, int qs)
  6983. {
  6984. SetDlgItemText (hDlg, IDC_DF0TEXT, workprefs.floppyslots[0].df);
  6985. SetDlgItemText (hDlg, IDC_DF1TEXT, workprefs.floppyslots[1].df);
  6986. SetDlgItemText (hDlg, IDC_DF2TEXT, workprefs.floppyslots[2].df);
  6987. SetDlgItemText (hDlg, IDC_DF3TEXT, workprefs.floppyslots[3].df);
  6988. SetDlgItemText (hDlg, IDC_DF0TEXTQ, workprefs.floppyslots[0].df);
  6989. SetDlgItemText (hDlg, IDC_DF1TEXTQ, workprefs.floppyslots[1].df);
  6990. if (!qs)
  6991. addallfloppies (hDlg);
  6992. }
  6993. static void updatefloppytypes(HWND hDlg)
  6994. {
  6995. TCHAR ft35dd[20], ft35hd[20], ft525sd[20], ft35ddescom[20];
  6996. bool qs = currentpage == QUICKSTART_ID;
  6997. WIN32GUI_LoadUIString(IDS_FLOPPYTYPE35DD, ft35dd, sizeof ft35dd / sizeof(TCHAR));
  6998. WIN32GUI_LoadUIString(IDS_FLOPPYTYPE35HD, ft35hd, sizeof ft35hd / sizeof(TCHAR));
  6999. WIN32GUI_LoadUIString(IDS_FLOPPYTYPE525SD, ft525sd, sizeof ft525sd / sizeof(TCHAR));
  7000. WIN32GUI_LoadUIString(IDS_FLOPPYTYPE35DDESCOM, ft35ddescom, sizeof ft35ddescom / sizeof(TCHAR));
  7001. for (int i = 0; i < (qs ? 2 : 4); i++) {
  7002. int f_type;
  7003. if (qs) {
  7004. f_type = floppybuttonsq[i][3];
  7005. } else {
  7006. f_type = floppybuttons[i][3];
  7007. }
  7008. SendDlgItemMessage(hDlg, f_type, CB_RESETCONTENT, 0, 0L);
  7009. SendDlgItemMessage(hDlg, f_type, CB_ADDSTRING, 0, (LPARAM)ft35dd);
  7010. SendDlgItemMessage(hDlg, f_type, CB_ADDSTRING, 0, (LPARAM)ft35hd);
  7011. if (!qs) {
  7012. SendDlgItemMessage(hDlg, f_type, CB_ADDSTRING, 0, (LPARAM)ft525sd);
  7013. SendDlgItemMessage(hDlg, f_type, CB_ADDSTRING, 0, (LPARAM)_T("5.25\" (80)"));
  7014. SendDlgItemMessage(hDlg, f_type, CB_ADDSTRING, 0, (LPARAM)ft35ddescom);
  7015. if (i >= 2) {
  7016. SendDlgItemMessage(hDlg, f_type, CB_ADDSTRING, 0, (LPARAM)_T("Bridgeboard 5.25\" 40"));
  7017. SendDlgItemMessage(hDlg, f_type, CB_ADDSTRING, 0, (LPARAM)_T("Bridgeboard 5.25\" 80"));
  7018. SendDlgItemMessage(hDlg, f_type, CB_ADDSTRING, 0, (LPARAM)_T("Bridgeboard 3.5\" 80"));
  7019. }
  7020. }
  7021. if (floppybridge_available) {
  7022. SendDlgItemMessage(hDlg, f_type, CB_ADDSTRING, 0, (LPARAM)_T("Configure FloppyBridge"));
  7023. for (int j = 0; j < bridgeprofiles.size(); j++) {
  7024. FloppyBridgeAPI::FloppyBridgeProfileInformation fbpi = bridgeprofiles.at(j);
  7025. TCHAR tmp[256];
  7026. if (_tcslen(fbpi.name) < sizeof(tmp) - 10) {
  7027. _stprintf(tmp, _T("FB: %s"), fbpi.name);
  7028. SendDlgItemMessage(hDlg, f_type, CB_ADDSTRING, 0, (LPARAM)tmp);
  7029. }
  7030. }
  7031. }
  7032. int nn;
  7033. if (qs) {
  7034. nn = fromdfxtype(i, quickstart_floppytype[i], quickstart_floppysubtype[i]);
  7035. } else {
  7036. nn = fromdfxtype(i, workprefs.floppyslots[i].dfxtype, workprefs.floppyslots[i].dfxsubtype);
  7037. }
  7038. SendDlgItemMessage(hDlg, f_type, CB_SETCURSEL, nn, 0L);
  7039. }
  7040. }
  7041. static INT_PTR CALLBACK QuickstartDlgProc (HWND hDlg, UINT msg, WPARAM wParam, LPARAM lParam)
  7042. {
  7043. static int recursive;
  7044. int ret = FALSE, i;
  7045. TCHAR tmp[MAX_DPATH];
  7046. static TCHAR df0[MAX_DPATH];
  7047. static TCHAR df1[MAX_DPATH];
  7048. static int dfxtype[2] = { -1, -1 };
  7049. static int doinit;
  7050. LRESULT val;
  7051. if (dialog_inhibit)
  7052. return 0;
  7053. switch(msg)
  7054. {
  7055. case WM_INITDIALOG:
  7056. {
  7057. int ids[] = { IDC_DF0TEXTQ, IDC_DF1TEXTQ, -1 };
  7058. pages[QUICKSTART_ID] = hDlg;
  7059. currentpage = QUICKSTART_ID;
  7060. enable_for_quickstart (hDlg);
  7061. setfloppytexts (hDlg, true);
  7062. floppybridge_init(&workprefs);
  7063. setmultiautocomplete (hDlg, ids);
  7064. doinit = 1;
  7065. break;
  7066. }
  7067. case WM_NULL:
  7068. if (recursive > 0)
  7069. break;
  7070. recursive++;
  7071. if (doinit) {
  7072. addfloppytype (hDlg, 0);
  7073. addfloppytype (hDlg, 1);
  7074. addfloppyhistory (hDlg);
  7075. init_quickstartdlg (hDlg);
  7076. updatefloppytypes(hDlg);
  7077. }
  7078. doinit = 0;
  7079. recursive--;
  7080. break;
  7081. case WM_CONTEXTMENU:
  7082. if (recursive > 0)
  7083. break;
  7084. recursive++;
  7085. diskselectmenu (hDlg, wParam);
  7086. setfloppytexts (hDlg, true);
  7087. recursive--;
  7088. break;
  7089. case WM_COMMAND:
  7090. if (recursive > 0)
  7091. break;
  7092. recursive++;
  7093. if (HIWORD (wParam) == CBN_SELCHANGE || HIWORD (wParam) == CBN_KILLFOCUS) {
  7094. switch (LOWORD (wParam))
  7095. {
  7096. case IDC_CD0Q_TYPE:
  7097. val = SendDlgItemMessage (hDlg, IDC_CD0Q_TYPE, CB_GETCURSEL, 0, 0);
  7098. if (val != CB_ERR) {
  7099. quickstart_cdtype = val;
  7100. if (full_property_sheet)
  7101. workprefs.cdslots[0].type = SCSI_UNIT_DEFAULT;
  7102. if (quickstart_cdtype >= 2) {
  7103. int len = sizeof quickstart_cddrive / sizeof (TCHAR);
  7104. quickstart_cdtype = 2;
  7105. SendDlgItemMessage (hDlg, IDC_CD0Q_TYPE, WM_GETTEXT, (WPARAM)len, (LPARAM)quickstart_cddrive);
  7106. _tcscpy (workprefs.cdslots[0].name, quickstart_cddrive);
  7107. } else {
  7108. eject_cd ();
  7109. quickstart_cdtype = val;
  7110. }
  7111. workprefs.cdslots[0].inuse = quickstart_cdtype > 0;
  7112. addfloppytype (hDlg, 1);
  7113. addfloppyhistory (hDlg);
  7114. }
  7115. break;
  7116. case IDC_QUICKSTART_MODEL:
  7117. val = SendDlgItemMessage (hDlg, IDC_QUICKSTART_MODEL, CB_GETCURSEL, 0, 0L);
  7118. if (val != CB_ERR) {
  7119. i = 0;
  7120. while (amodels[i].compalevels >= 0) {
  7121. if (amodels[i].compalevels > 0)
  7122. val--;
  7123. if (val < 0)
  7124. break;
  7125. i++;
  7126. }
  7127. if (i != quickstart_model) {
  7128. quickstart_model = i;
  7129. quickstart_conf = quickstart_model_confstore[quickstart_model];
  7130. init_quickstartdlg (hDlg);
  7131. if (quickstart)
  7132. load_quickstart (hDlg, 1);
  7133. if (quickstart && !full_property_sheet)
  7134. qs_request_reset |= 4;
  7135. }
  7136. }
  7137. break;
  7138. case IDC_QUICKSTART_CONFIGURATION:
  7139. val = SendDlgItemMessage (hDlg, IDC_QUICKSTART_CONFIGURATION, CB_GETCURSEL, 0, 0L);
  7140. if (val != CB_ERR && val != quickstart_conf) {
  7141. int rslevel = amodels[quickstart_model].resetlevels[quickstart_conf];
  7142. quickstart_conf = val;
  7143. if (!full_property_sheet && amodels[quickstart_model].resetlevels[quickstart_conf] != rslevel) {
  7144. qs_request_reset |= 4;
  7145. }
  7146. quickstart_model_confstore[quickstart_model] = quickstart_conf;
  7147. init_quickstartdlg (hDlg);
  7148. if (quickstart)
  7149. load_quickstart (hDlg, 1);
  7150. if (quickstart && !full_property_sheet)
  7151. qs_request_reset |= 2;
  7152. }
  7153. break;
  7154. case IDC_QUICKSTART_HOSTCONFIG:
  7155. val = SendDlgItemMessage (hDlg, IDC_QUICKSTART_HOSTCONFIG, CB_GETCURSEL, 0, 0);
  7156. if (val != CB_ERR) {
  7157. SendDlgItemMessage (hDlg, IDC_QUICKSTART_HOSTCONFIG, CB_GETLBTEXT, (WPARAM)val, (LPARAM)tmp);
  7158. regsetstr (NULL, _T("QuickStartHostConfig"), tmp);
  7159. quickstarthost (hDlg, tmp);
  7160. if (val == 0 && quickstart)
  7161. load_quickstart (hDlg, 0);
  7162. }
  7163. break;
  7164. }
  7165. } else {
  7166. switch (LOWORD (wParam))
  7167. {
  7168. case IDC_NTSC:
  7169. quickstart_ntsc = ischecked (hDlg, IDC_NTSC);
  7170. regsetint (NULL, _T("QuickStartNTSC"), quickstart_ntsc);
  7171. if (quickstart) {
  7172. init_quickstartdlg (hDlg);
  7173. load_quickstart (hDlg, 0);
  7174. }
  7175. break;
  7176. case IDC_QUICKSTARTMODE:
  7177. quickstart = ischecked (hDlg, IDC_QUICKSTARTMODE);
  7178. regsetint (NULL, _T("QuickStartMode"), quickstart);
  7179. quickstart_cd = 0;
  7180. if (quickstart) {
  7181. init_quickstartdlg (hDlg);
  7182. load_quickstart (hDlg, 0);
  7183. }
  7184. enable_for_quickstart (hDlg);
  7185. break;
  7186. }
  7187. }
  7188. switch (LOWORD (wParam))
  7189. {
  7190. case IDC_DF0TEXTQ:
  7191. case IDC_DF0WPQ:
  7192. case IDC_EJECT0Q:
  7193. case IDC_DF0QQ:
  7194. case IDC_DF1TEXTQ:
  7195. case IDC_DF1WPQ:
  7196. case IDC_EJECT1Q:
  7197. case IDC_DF1QQ:
  7198. case IDC_DF0QENABLE:
  7199. case IDC_DF1QENABLE:
  7200. case IDC_INFO0Q:
  7201. case IDC_INFO1Q:
  7202. case IDC_DF0TYPE:
  7203. case IDC_DF1TYPE:
  7204. if (currentpage == QUICKSTART_ID)
  7205. ret = FloppyDlgProc (hDlg, msg, wParam, lParam);
  7206. break;
  7207. case IDC_QUICKSTART_SETCONFIG:
  7208. load_quickstart (hDlg, 1);
  7209. break;
  7210. }
  7211. recursive--;
  7212. case WM_HSCROLL:
  7213. if (recursive > 0)
  7214. break;
  7215. recursive++;
  7216. if ((HWND)lParam == GetDlgItem (hDlg, IDC_QUICKSTART_COMPATIBILITY)) {
  7217. val = SendMessage ((HWND)lParam, TBM_GETPOS, 0, 0);
  7218. if (val >= 0 && val != quickstart_compa) {
  7219. quickstart_compa = val;
  7220. init_quickstartdlg (hDlg);
  7221. if (quickstart)
  7222. load_quickstart (hDlg, 0);
  7223. }
  7224. }
  7225. recursive--;
  7226. break;
  7227. }
  7228. if (recursive == 0 && quickstart) {
  7229. recursive++;
  7230. if (_tcscmp (workprefs.floppyslots[0].df, df0) || workprefs.floppyslots[0].dfxtype != dfxtype[0]) {
  7231. _tcscpy (df0, workprefs.floppyslots[0].df);
  7232. dfxtype[0] = workprefs.floppyslots[0].dfxtype;
  7233. testimage (hDlg, 0);
  7234. enable_for_quickstart (hDlg);
  7235. }
  7236. if (_tcscmp (workprefs.floppyslots[1].df, df1) || workprefs.floppyslots[1].dfxtype != dfxtype[1]) {
  7237. _tcscpy (df1, workprefs.floppyslots[1].df);
  7238. dfxtype[1] = workprefs.floppyslots[1].dfxtype;
  7239. testimage (hDlg, 1);
  7240. }
  7241. recursive--;
  7242. }
  7243. return ret;
  7244. }
  7245. static void init_aboutdlg (HWND hDlg)
  7246. {
  7247. CHARFORMAT CharFormat;
  7248. int i;
  7249. CharFormat.cbSize = sizeof (CharFormat);
  7250. SetDlgItemText (hDlg, IDC_RICHEDIT1, _T("WinUAE"));
  7251. SendDlgItemMessage (hDlg, IDC_RICHEDIT1, EM_GETCHARFORMAT, 0, (LPARAM) & CharFormat);
  7252. CharFormat.dwMask |= CFM_BOLD | CFM_SIZE | CFM_FACE;
  7253. CharFormat.dwEffects = CFE_BOLD;
  7254. CharFormat.yHeight = 24 * 20; /* height in twips, where a twip is 1/20th of a point */
  7255. _tcscpy (CharFormat.szFaceName, os_vista ? _T("Segoe UI") : _T("Tahoma"));
  7256. SendDlgItemMessage (hDlg, IDC_RICHEDIT1, EM_SETCHARFORMAT, SCF_ALL, (LPARAM) & CharFormat);
  7257. SendDlgItemMessage (hDlg, IDC_RICHEDIT1, EM_SETBKGNDCOLOR, 0, GetSysColor (COLOR_3DFACE));
  7258. SetDlgItemText (hDlg, IDC_RICHEDIT2, VersionStr );
  7259. SendDlgItemMessage (hDlg, IDC_RICHEDIT2, EM_GETCHARFORMAT, 0, (LPARAM) & CharFormat);
  7260. CharFormat.dwMask |= CFM_SIZE | CFM_FACE;
  7261. CharFormat.yHeight = 12 * 20;
  7262. _tcscpy (CharFormat.szFaceName, os_vista ? _T("Segoe UI") : _T("Tahoma"));
  7263. SendDlgItemMessage (hDlg, IDC_RICHEDIT2, EM_SETCHARFORMAT, SCF_ALL, (LPARAM) & CharFormat);
  7264. SendDlgItemMessage (hDlg, IDC_RICHEDIT2, EM_SETBKGNDCOLOR, 0, GetSysColor (COLOR_3DFACE));
  7265. for(i = 0; urls[i].id >= 0; i++)
  7266. SetupRichText (hDlg, &urls[i]);
  7267. }
  7268. static INT_PTR CALLBACK AboutDlgProc (HWND hDlg, UINT msg, WPARAM wParam, LPARAM lParam)
  7269. {
  7270. if (dialog_inhibit)
  7271. return 0;
  7272. switch( msg )
  7273. {
  7274. case WM_INITDIALOG:
  7275. pages[ABOUT_ID] = hDlg;
  7276. currentpage = ABOUT_ID;
  7277. init_aboutdlg (hDlg);
  7278. break;
  7279. case WM_COMMAND:
  7280. if (wParam == IDC_CONTRIBUTORS)
  7281. DisplayContributors (hDlg);
  7282. break;
  7283. case WM_SETCURSOR:
  7284. return TRUE;
  7285. break;
  7286. case WM_LBUTTONDOWN:
  7287. case WM_MOUSEMOVE:
  7288. url_handler (hDlg, msg, wParam, lParam);
  7289. break;
  7290. }
  7291. return FALSE;
  7292. }
  7293. static void enable_for_displaydlg (HWND hDlg)
  7294. {
  7295. int rtg = ((!workprefs.address_space_24 || gfxboard_get_configtype(&workprefs.rtgboards[0]) == 2) && workprefs.rtgboards[0].rtgmem_size) || workprefs.rtgboards[0].rtgmem_type >= GFXBOARD_HARDWARE;
  7296. #ifndef PICASSO96
  7297. rtg = FALSE;
  7298. #endif
  7299. ew(hDlg, IDC_SCREENMODE_RTG, rtg);
  7300. ew(hDlg, IDC_SCREENMODE_RTG2, rtg);
  7301. ew(hDlg, IDC_XCENTER, TRUE);
  7302. ew(hDlg, IDC_YCENTER, TRUE);
  7303. ew(hDlg, IDC_FRAMERATE, !workprefs.cpu_memory_cycle_exact);
  7304. ew(hDlg, IDC_LORES, !workprefs.gfx_autoresolution);
  7305. ew(hDlg, IDC_OVERSCANMODE, TRUE);
  7306. ew(hDlg, IDC_AUTORESOLUTIONVGA, workprefs.gfx_resolution >= RES_HIRES && workprefs.gfx_vresolution >= VRES_DOUBLE);
  7307. if (workprefs.gfx_resolution < RES_HIRES || workprefs.gfx_vresolution < VRES_DOUBLE) {
  7308. workprefs.gfx_autoresolution_vga = false;
  7309. CheckDlgButton (hDlg, IDC_AUTORESOLUTIONVGA, workprefs.gfx_autoresolution_vga);
  7310. }
  7311. bool isdouble = workprefs.gfx_vresolution > 0;
  7312. ew (hDlg, IDC_LM_NORMAL, !workprefs.gfx_autoresolution);
  7313. ew (hDlg, IDC_LM_DOUBLED, !workprefs.gfx_autoresolution);
  7314. ew (hDlg, IDC_LM_SCANLINES, !workprefs.gfx_autoresolution);
  7315. ew (hDlg, IDC_LM_PDOUBLED2, !workprefs.gfx_autoresolution);
  7316. ew (hDlg, IDC_LM_PDOUBLED3, !workprefs.gfx_autoresolution);
  7317. ew (hDlg, IDC_LM_INORMAL, !workprefs.gfx_autoresolution && !isdouble);
  7318. ew (hDlg, IDC_LM_IDOUBLED, !workprefs.gfx_autoresolution && isdouble);
  7319. ew (hDlg, IDC_LM_IDOUBLED2, !workprefs.gfx_autoresolution && isdouble);
  7320. ew (hDlg, IDC_LM_IDOUBLED3, !workprefs.gfx_autoresolution && isdouble);
  7321. if (workprefs.gfx_apmode[0].gfx_vsyncmode == 1 || workprefs.gfx_apmode[0].gfx_vsyncmode == 2) {
  7322. hide(hDlg, IDC_SCREENMODE_NATIVE3, FALSE);
  7323. ew(hDlg, IDC_SCREENMODE_NATIVE3, TRUE);
  7324. } else {
  7325. ew(hDlg, IDC_SCREENMODE_NATIVE3, FALSE);
  7326. hide(hDlg, IDC_SCREENMODE_NATIVE3, TRUE);
  7327. }
  7328. #if WINUAEPUBLICBETA
  7329. hide(hDlg, IDC_DISPLAY_VARSYNC, FALSE);
  7330. #endif
  7331. }
  7332. static void enable_for_chipsetdlg (HWND hDlg)
  7333. {
  7334. int enable = workprefs.cpu_memory_cycle_exact ? FALSE : TRUE;
  7335. #if !defined (CPUEMU_13)
  7336. ew (hDlg, IDC_CYCLEEXACT, FALSE);
  7337. #else
  7338. ew (hDlg, IDC_CYCLEEXACTMEMORY, workprefs.cpu_model >= 68020);
  7339. #endif
  7340. if (workprefs.immediate_blits && workprefs.waiting_blits) {
  7341. workprefs.waiting_blits = 0;
  7342. CheckDlgButton (hDlg, IDC_BLITWAIT, FALSE);
  7343. }
  7344. ew(hDlg, IDC_BLITIMM, !workprefs.cpu_cycle_exact);
  7345. ew(hDlg, IDC_GENLOCKMODE, workprefs.genlock ? TRUE : FALSE);
  7346. ew(hDlg, IDC_GENLOCKMIX, workprefs.genlock ? TRUE : FALSE);
  7347. ew(hDlg, IDC_GENLOCK_ALPHA, workprefs.genlock ? TRUE : FALSE);
  7348. ew(hDlg, IDC_GENLOCK_KEEP_ASPECT, workprefs.genlock ? TRUE : FALSE);
  7349. ew(hDlg, IDC_GENLOCKFILE, workprefs.genlock && (workprefs.genlock_image >= 6 || (workprefs.genlock_image >= 3 && workprefs.genlock_image < 5)) ? TRUE : FALSE);
  7350. ew(hDlg, IDC_GENLOCKFILESELECT, workprefs.genlock && (workprefs.genlock_image >= 6 || (workprefs.genlock_image >= 3 && workprefs.genlock_image < 5)) ? TRUE : FALSE);
  7351. ew(hDlg, IDC_MONITOREMU_MON, workprefs.monitoremu != 0);
  7352. }
  7353. static const int fakerefreshrates[] = { 50, 60, 100, 120, 0 };
  7354. struct storedrefreshrate
  7355. {
  7356. int rate, type;
  7357. };
  7358. static struct storedrefreshrate storedrefreshrates[MAX_REFRESH_RATES + 4 + 1];
  7359. static void init_frequency_combo (HWND hDlg, int dmode)
  7360. {
  7361. int i, j, freq;
  7362. TCHAR hz[20], hz2[20], txt[100];
  7363. LRESULT index;
  7364. struct MultiDisplay *md = getdisplay(&workprefs, 0);
  7365. i = 0; index = 0;
  7366. while (dmode >= 0 && (freq = md->DisplayModes[dmode].refresh[i]) > 0 && index < MAX_REFRESH_RATES) {
  7367. storedrefreshrates[index].rate = freq;
  7368. storedrefreshrates[index++].type = md->DisplayModes[dmode].refreshtype[i];
  7369. i++;
  7370. }
  7371. if (workprefs.gfx_apmode[0].gfx_vsyncmode == 0 && workprefs.gfx_apmode[0].gfx_vsync) {
  7372. i = 0;
  7373. while ((freq = fakerefreshrates[i]) > 0 && index < MAX_REFRESH_RATES) {
  7374. for (j = 0; j < index; j++) {
  7375. if (storedrefreshrates[j].rate == freq)
  7376. break;
  7377. }
  7378. if (j == index) {
  7379. storedrefreshrates[index].rate = -freq;
  7380. storedrefreshrates[index++].type = 0;
  7381. }
  7382. i++;
  7383. }
  7384. }
  7385. storedrefreshrates[index].rate = 0;
  7386. for (i = 0; i < index; i++) {
  7387. for (j = i + 1; j < index; j++) {
  7388. if (abs (storedrefreshrates[i].rate) >= abs (storedrefreshrates[j].rate)) {
  7389. struct storedrefreshrate srr;
  7390. memcpy (&srr, &storedrefreshrates[i], sizeof (struct storedrefreshrate));
  7391. memcpy (&storedrefreshrates[i], &storedrefreshrates[j], sizeof (struct storedrefreshrate));
  7392. memcpy (&storedrefreshrates[j], &srr, sizeof (struct storedrefreshrate));
  7393. }
  7394. }
  7395. }
  7396. hz[0] = hz2[0] = 0;
  7397. SendDlgItemMessage(hDlg, IDC_REFRESHRATE, CB_RESETCONTENT, 0, 0);
  7398. WIN32GUI_LoadUIString (IDS_VSYNC_DEFAULT, txt, sizeof (txt) / sizeof (TCHAR));
  7399. SendDlgItemMessage(hDlg, IDC_REFRESHRATE, CB_ADDSTRING, 0, (LPARAM)txt);
  7400. for (i = 0; i < index; i++) {
  7401. bool lace = (storedrefreshrates[i].type & REFRESH_RATE_LACE) != 0;
  7402. freq = storedrefreshrates[i].rate;
  7403. if (freq < 0) {
  7404. freq = -freq;
  7405. _stprintf (hz, _T("(%dHz)"), freq);
  7406. } else {
  7407. _stprintf (hz, _T("%dHz"), freq);
  7408. }
  7409. if (freq == 50 || freq == 100 || (freq * 2 == 50 && lace))
  7410. _tcscat (hz, _T(" PAL"));
  7411. if (freq == 60 || freq == 120 || (freq * 2 == 60 && lace))
  7412. _tcscat (hz, _T(" NTSC"));
  7413. if (lace) {
  7414. TCHAR tmp[10];
  7415. _stprintf (tmp, _T(" (%di)"), freq * 2);
  7416. _tcscat (hz, tmp);
  7417. }
  7418. if (storedrefreshrates[i].type & REFRESH_RATE_RAW)
  7419. _tcscat (hz, _T(" (*)"));
  7420. if (abs (workprefs.gfx_apmode[0].gfx_refreshrate) == freq)
  7421. _tcscpy (hz2, hz);
  7422. SendDlgItemMessage (hDlg, IDC_REFRESHRATE, CB_ADDSTRING, 0, (LPARAM)hz);
  7423. }
  7424. index = CB_ERR;
  7425. if (hz2[0] >= 0)
  7426. index = SendDlgItemMessage (hDlg, IDC_REFRESHRATE, CB_SELECTSTRING, 0, (LPARAM)hz2);
  7427. if (index == CB_ERR) {
  7428. WIN32GUI_LoadUIString (IDS_VSYNC_DEFAULT, txt, sizeof (txt) / sizeof (TCHAR));
  7429. SendDlgItemMessage(hDlg, IDC_REFRESHRATE, CB_SELECTSTRING, i, (LPARAM)txt);
  7430. workprefs.gfx_apmode[0].gfx_refreshrate = 0;
  7431. }
  7432. }
  7433. #define MAX_FRAMERATE_LENGTH 40
  7434. #define MAX_NTH_LENGTH 20
  7435. static int display_mode_index (uae_u32 x, uae_u32 y, uae_u32 d)
  7436. {
  7437. int i, j;
  7438. struct MultiDisplay *md = getdisplay(&workprefs, 0);
  7439. j = 0;
  7440. for (i = 0; md->DisplayModes[i].depth >= 0; i++) {
  7441. if (md->DisplayModes[i].res.width == x &&
  7442. md->DisplayModes[i].res.height == y &&
  7443. md->DisplayModes[i].depth == d)
  7444. break;
  7445. j++;
  7446. }
  7447. if (x == 0 && y == 0) {
  7448. j = 0;
  7449. for (i = 0; md->DisplayModes[i].depth >= 0; i++) {
  7450. if (md->DisplayModes[i].res.width == md->rect.right - md->rect.left &&
  7451. md->DisplayModes[i].res.height == md->rect.bottom - md->rect.top &&
  7452. md->DisplayModes[i].depth == d)
  7453. break;
  7454. j++;
  7455. }
  7456. }
  7457. if(md->DisplayModes[i].depth < 0)
  7458. j = -1;
  7459. return j;
  7460. }
  7461. static int da_mode_selected, da_mode_multiplier;
  7462. static int *getp_da (HWND hDlg)
  7463. {
  7464. int vmin = -200;
  7465. int vmax = 200;
  7466. da_mode_multiplier = 10;
  7467. int *p = 0;
  7468. switch (da_mode_selected)
  7469. {
  7470. case 0:
  7471. p = &workprefs.gfx_luminance;
  7472. break;
  7473. case 1:
  7474. p = &workprefs.gfx_contrast;
  7475. break;
  7476. case 2:
  7477. p = &workprefs.gfx_gamma;
  7478. break;
  7479. case 3:
  7480. p = &workprefs.gfx_gamma_ch[0];
  7481. break;
  7482. case 4:
  7483. p = &workprefs.gfx_gamma_ch[1];
  7484. break;
  7485. case 5:
  7486. p = &workprefs.gfx_gamma_ch[2];
  7487. break;
  7488. case 6:
  7489. p = &workprefs.gfx_threebitcolors;
  7490. vmin = 0;
  7491. vmax = 3;
  7492. da_mode_multiplier = 1;
  7493. break;
  7494. }
  7495. if (*p < vmin * da_mode_multiplier)
  7496. *p = vmin * da_mode_multiplier;
  7497. if (*p > vmax * da_mode_multiplier)
  7498. *p = vmax * da_mode_multiplier;
  7499. SendDlgItemMessage(hDlg, IDC_DA_SLIDER, TBM_SETPAGESIZE, 0, 1);
  7500. SendDlgItemMessage(hDlg, IDC_DA_SLIDER, TBM_SETRANGE, TRUE, MAKELONG(vmin, vmax));
  7501. return p;
  7502. }
  7503. static void set_da (HWND hDlg)
  7504. {
  7505. int *p = getp_da (hDlg);
  7506. if (!p)
  7507. return;
  7508. TCHAR buf[10];
  7509. SendDlgItemMessage (hDlg, IDC_DA_SLIDER, TBM_SETPOS, TRUE, (*p) / da_mode_multiplier);
  7510. _stprintf(buf, _T("%.1f"), (double)((*p) / (double)da_mode_multiplier));
  7511. SetDlgItemText (hDlg, IDC_DA_TEXT, buf);
  7512. }
  7513. static void update_da (HWND hDlg)
  7514. {
  7515. currprefs.gfx_gamma = workprefs.gfx_gamma;
  7516. currprefs.gfx_gamma_ch[0] = workprefs.gfx_gamma_ch[0];
  7517. currprefs.gfx_gamma_ch[1] = workprefs.gfx_gamma_ch[1];
  7518. currprefs.gfx_gamma_ch[2] = workprefs.gfx_gamma_ch[2];
  7519. currprefs.gfx_luminance = workprefs.gfx_luminance;
  7520. currprefs.gfx_contrast = workprefs.gfx_contrast;
  7521. currprefs.gfx_threebitcolors = workprefs.gfx_threebitcolors;
  7522. set_da (hDlg);
  7523. init_colors(0);
  7524. init_custom();
  7525. updatedisplayarea(-1);
  7526. }
  7527. static void handle_da (HWND hDlg)
  7528. {
  7529. int *p;
  7530. int v;
  7531. p = getp_da (hDlg);
  7532. if (!p)
  7533. return;
  7534. v = SendDlgItemMessage (hDlg, IDC_DA_SLIDER, TBM_GETPOS, 0, 0) * da_mode_multiplier;
  7535. if (v == *p)
  7536. return;
  7537. *p = v;
  7538. update_da (hDlg);
  7539. }
  7540. void init_da (HWND hDlg)
  7541. {
  7542. int *p;
  7543. TCHAR tmp[MAX_DPATH], *p1, *p2;
  7544. WIN32GUI_LoadUIString(IDS_DISPLAY_ATTRIBUTES, tmp, sizeof tmp / sizeof (TCHAR));
  7545. SendDlgItemMessage(hDlg, IDC_DA_MODE, CB_RESETCONTENT, 0, 0);
  7546. _tcscat (tmp, _T("\n"));
  7547. p1 = tmp;
  7548. for (;;) {
  7549. p2 = _tcschr (p1, '\n');
  7550. if (p2 && _tcslen (p2) > 0) {
  7551. *p2++ = 0;
  7552. SendDlgItemMessage (hDlg, IDC_DA_MODE, CB_ADDSTRING, 0, (LPARAM)p1);
  7553. p1 = p2;
  7554. } else
  7555. break;
  7556. }
  7557. if (da_mode_selected == CB_ERR)
  7558. da_mode_selected = 0;
  7559. SendDlgItemMessage (hDlg, IDC_DA_MODE, CB_SETCURSEL, da_mode_selected, 0);
  7560. p = getp_da (hDlg);
  7561. if (p)
  7562. set_da (hDlg);
  7563. }
  7564. static int gui_display_depths[3];
  7565. static void init_display_mode (HWND hDlg)
  7566. {
  7567. int d, d2, index;
  7568. int i, cnt;
  7569. struct MultiDisplay *md = getdisplay(&workprefs, 0);
  7570. struct monconfig *gm = &workprefs.gfx_monitor[0];
  7571. switch (workprefs.color_mode)
  7572. {
  7573. case 2:
  7574. d = 16;
  7575. break;
  7576. case 5:
  7577. default:
  7578. d = 32;
  7579. break;
  7580. }
  7581. if (workprefs.gfx_apmode[0].gfx_fullscreen) {
  7582. d2 = d;
  7583. if ((index = WIN32GFX_AdjustScreenmode (md, &gm->gfx_size_fs.width, &gm->gfx_size_fs.height, &d2)) >= 0) {
  7584. switch (d2)
  7585. {
  7586. case 15:
  7587. case 16:
  7588. workprefs.color_mode = 2;
  7589. d = 2;
  7590. break;
  7591. case 32:
  7592. default:
  7593. workprefs.color_mode = 5;
  7594. d = 4;
  7595. break;
  7596. }
  7597. }
  7598. } else {
  7599. d = d / 8;
  7600. }
  7601. if (gm->gfx_size_fs.special == WH_NATIVE) {
  7602. int cnt = (int)SendDlgItemMessage (hDlg, IDC_RESOLUTION, CB_GETCOUNT, 0, 0);
  7603. SendDlgItemMessage (hDlg, IDC_RESOLUTION, CB_SETCURSEL, cnt - 1, 0);
  7604. index = display_mode_index (gm->gfx_size_fs.width, gm->gfx_size_fs.height, d);
  7605. } else {
  7606. index = display_mode_index (gm->gfx_size_fs.width, gm->gfx_size_fs.height, d);
  7607. if (index >= 0)
  7608. SendDlgItemMessage (hDlg, IDC_RESOLUTION, CB_SETCURSEL, md->DisplayModes[index].residx, 0);
  7609. gm->gfx_size_fs.special = 0;
  7610. }
  7611. SendDlgItemMessage(hDlg, IDC_RESOLUTIONDEPTH, CB_RESETCONTENT, 0, 0);
  7612. cnt = 0;
  7613. gui_display_depths[0] = gui_display_depths[1] = gui_display_depths[2] = -1;
  7614. if (index >= 0) {
  7615. for (i = 0; md->DisplayModes[i].depth >= 0; i++) {
  7616. if (md->DisplayModes[i].depth > 1 && md->DisplayModes[i].residx == md->DisplayModes[index].residx) {
  7617. TCHAR tmp[64];
  7618. _stprintf (tmp, _T("%d"), md->DisplayModes[i].depth * 8);
  7619. SendDlgItemMessage(hDlg, IDC_RESOLUTIONDEPTH, CB_ADDSTRING, 0, (LPARAM)tmp);
  7620. if (md->DisplayModes[i].depth == d)
  7621. SendDlgItemMessage (hDlg, IDC_RESOLUTIONDEPTH, CB_SETCURSEL, cnt, 0);
  7622. gui_display_depths[cnt] = md->DisplayModes[i].depth;
  7623. cnt++;
  7624. }
  7625. }
  7626. }
  7627. init_frequency_combo (hDlg, index);
  7628. }
  7629. #if 0
  7630. static int display_toselect (int fs, int vsync, int p96)
  7631. {
  7632. if (p96)
  7633. return fs * 2 + (vsync ? 1 : 0);
  7634. if (fs == 2)
  7635. return 4;
  7636. if (!vsync)
  7637. return fs;
  7638. if (fs == 1 && vsync == 1)
  7639. return 2;
  7640. if (fs == 1 && vsync == 2)
  7641. return 3;
  7642. return fs;
  7643. }
  7644. static void display_fromselect (int val, int *fs, int *vsync, int p96)
  7645. {
  7646. int ofs = *fs;
  7647. if (val == CB_ERR)
  7648. return;
  7649. *fs = 0;
  7650. *vsync = 0;
  7651. if (p96) {
  7652. *fs = val / 2;
  7653. *vsync = val & 1;
  7654. if (*fs == 2 && *fs != ofs) {
  7655. workprefs.win32_rtgscaleifsmall = 1;
  7656. workprefs.win32_rtgmatchdepth = 0;
  7657. }
  7658. return;
  7659. }
  7660. switch (val)
  7661. {
  7662. case 0:
  7663. *fs = 0;
  7664. break;
  7665. case 1:
  7666. *fs = 1;
  7667. break;
  7668. case 2:
  7669. *fs = 1;
  7670. *vsync = 1;
  7671. break;
  7672. case 3:
  7673. *fs = 1;
  7674. *vsync = 2;
  7675. break;
  7676. case 4:
  7677. *fs = 2;
  7678. if (workprefs.gfx_filter == 0 && *fs != ofs && !workprefs.gfx_api) {
  7679. workprefs.gfx_filter = 1;
  7680. workprefs.gfx_filter_horiz_zoom = 0;
  7681. workprefs.gfx_filter_vert_zoom = 0;
  7682. workprefs.gfx_filter_horiz_zoom_mult = 0;
  7683. workprefs.gfx_filter_vert_zoom_mult = 0;
  7684. workprefs.gfx_filter_aspect = -1;
  7685. workprefs.gfx_filter_horiz_offset = 0;
  7686. workprefs.gfx_filter_vert_offset = 0;
  7687. workprefs.gfx_filter_keep_aspect = 0;
  7688. }
  7689. break;
  7690. }
  7691. }
  7692. #endif
  7693. #define MAX_GUI_DISPLAY_SECTIONS 30
  7694. static void values_to_displaydlg (HWND hDlg)
  7695. {
  7696. TCHAR buffer[MAX_DPATH];
  7697. int rates[MAX_CHIPSET_REFRESH_TOTAL];
  7698. int v;
  7699. double d;
  7700. init_display_mode (hDlg);
  7701. SetDlgItemInt (hDlg, IDC_XSIZE, workprefs.gfx_monitor[0].gfx_size_win.width, FALSE);
  7702. SetDlgItemInt (hDlg, IDC_YSIZE, workprefs.gfx_monitor[0].gfx_size_win.height, FALSE);
  7703. SendDlgItemMessage(hDlg, IDC_RATE2BOX, CB_RESETCONTENT, 0, 0);
  7704. v = 0;
  7705. struct chipset_refresh *selectcr = full_property_sheet ? (workprefs.ntscmode ? &workprefs.cr[CHIPSET_REFRESH_NTSC] : &workprefs.cr[CHIPSET_REFRESH_PAL]) : get_chipset_refresh (&workprefs) ;
  7706. for (int i = 0; i < MAX_CHIPSET_REFRESH_TOTAL; i++) {
  7707. struct chipset_refresh *cr = &workprefs.cr[i];
  7708. if (cr->rate > 0) {
  7709. _tcscpy (buffer, cr->label);
  7710. if (!buffer[0])
  7711. _stprintf (buffer, _T(":%d"), i);
  7712. SendDlgItemMessage(hDlg, IDC_RATE2BOX, CB_ADDSTRING, 0, (LPARAM)buffer);
  7713. d = workprefs.chipset_refreshrate;
  7714. if (abs (d) < 1)
  7715. d = currprefs.ntscmode ? 60.0 : 50.0;
  7716. if (selectcr && selectcr->index == cr->index)
  7717. workprefs.cr_selected = i;
  7718. rates[i] = v;
  7719. v++;
  7720. }
  7721. }
  7722. if (workprefs.cr_selected < 0 || workprefs.cr[workprefs.cr_selected].rate <= 0)
  7723. workprefs.cr_selected = CHIPSET_REFRESH_PAL;
  7724. selectcr = &workprefs.cr[workprefs.cr_selected];
  7725. SendDlgItemMessage(hDlg, IDC_RATE2BOX, CB_SETCURSEL, rates[workprefs.cr_selected], 0);
  7726. SendDlgItemMessage (hDlg, IDC_FRAMERATE2, TBM_SETPOS, TRUE, (LPARAM)(selectcr->rate + 0.5));
  7727. _stprintf (buffer, _T("%.6f"), selectcr->locked || full_property_sheet ? selectcr->rate : workprefs.chipset_refreshrate);
  7728. SetDlgItemText (hDlg, IDC_RATE2TEXT, buffer);
  7729. CheckDlgButton (hDlg, IDC_RATE2ENABLE, selectcr->locked);
  7730. ew (hDlg, IDC_RATE2TEXT, selectcr->locked != 0);
  7731. ew (hDlg, IDC_FRAMERATE2, selectcr->locked != 0);
  7732. v = workprefs.cpu_memory_cycle_exact ? 1 : workprefs.gfx_framerate;
  7733. SendDlgItemMessage (hDlg, IDC_FRAMERATE, TBM_SETPOS, TRUE, (int)v);
  7734. CheckRadioButton (hDlg, IDC_LM_NORMAL, IDC_LM_PDOUBLED3, IDC_LM_NORMAL + (workprefs.gfx_vresolution ? 1 : 0) + workprefs.gfx_pscanlines);
  7735. CheckRadioButton (hDlg, IDC_LM_INORMAL, IDC_LM_IDOUBLED3, IDC_LM_INORMAL + (workprefs.gfx_iscanlines ? workprefs.gfx_iscanlines + 1 : (workprefs.gfx_vresolution ? 1 : 0)));
  7736. SendDlgItemMessage(hDlg, IDC_SCREENMODE_NATIVE, CB_RESETCONTENT, 0, 0);
  7737. SendDlgItemMessage(hDlg, IDC_SCREENMODE_NATIVE2, CB_RESETCONTENT, 0, 0);
  7738. SendDlgItemMessage(hDlg, IDC_SCREENMODE_NATIVE3, CB_RESETCONTENT, 0, 0);
  7739. WIN32GUI_LoadUIString(IDS_SCREEN_WINDOWED, buffer, sizeof buffer / sizeof (TCHAR));
  7740. SendDlgItemMessage(hDlg, IDC_SCREENMODE_NATIVE, CB_ADDSTRING, 0, (LPARAM)buffer);
  7741. WIN32GUI_LoadUIString(IDS_SCREEN_FULLSCREEN, buffer, sizeof buffer / sizeof (TCHAR));
  7742. SendDlgItemMessage(hDlg, IDC_SCREENMODE_NATIVE, CB_ADDSTRING, 0, (LPARAM)buffer);
  7743. WIN32GUI_LoadUIString(IDS_SCREEN_FULLWINDOW, buffer, sizeof buffer / sizeof (TCHAR));
  7744. SendDlgItemMessage(hDlg, IDC_SCREENMODE_NATIVE, CB_ADDSTRING, 0, (LPARAM)buffer);
  7745. WIN32GUI_LoadUIString(IDS_SCREEN_VSYNC_NONE, buffer, sizeof buffer / sizeof (TCHAR));
  7746. SendDlgItemMessage(hDlg, IDC_SCREENMODE_NATIVE2, CB_ADDSTRING, 0, (LPARAM)buffer);
  7747. WIN32GUI_LoadUIString(IDS_SCREEN_VSYNC2, buffer, sizeof buffer / sizeof (TCHAR));
  7748. SendDlgItemMessage(hDlg, IDC_SCREENMODE_NATIVE2, CB_ADDSTRING, 0, (LPARAM)buffer);
  7749. WIN32GUI_LoadUIString(IDS_SCREEN_VSYNC2_AUTOSWITCH, buffer, sizeof buffer / sizeof (TCHAR));
  7750. SendDlgItemMessage(hDlg, IDC_SCREENMODE_NATIVE2, CB_ADDSTRING, 0, (LPARAM)buffer);
  7751. WIN32GUI_LoadUIString(IDS_SCREEN_VSYNC, buffer, sizeof buffer / sizeof (TCHAR));
  7752. SendDlgItemMessage(hDlg, IDC_SCREENMODE_NATIVE2, CB_ADDSTRING, 0, (LPARAM)buffer);
  7753. WIN32GUI_LoadUIString(IDS_SCREEN_VSYNC_AUTOSWITCH, buffer, sizeof buffer / sizeof(TCHAR));
  7754. SendDlgItemMessage(hDlg, IDC_SCREENMODE_NATIVE2, CB_ADDSTRING, 0, (LPARAM)buffer);
  7755. for (int i = 1; i < MAX_GUI_DISPLAY_SECTIONS; i++) {
  7756. _stprintf(buffer, _T("%d"), i);
  7757. SendDlgItemMessage(hDlg, IDC_SCREENMODE_NATIVE3, CB_ADDSTRING, 0, (LPARAM)buffer);
  7758. }
  7759. SendDlgItemMessage(hDlg, IDC_SCREENMODE_NATIVE, CB_SETCURSEL, workprefs.gfx_apmode[0].gfx_fullscreen, 0);
  7760. v = workprefs.gfx_apmode[0].gfx_vsync;
  7761. if (v < 0)
  7762. v = 5;
  7763. else if (v > 0) {
  7764. v = v + (workprefs.gfx_apmode[0].gfx_vsyncmode || !v ? 0 : 2);
  7765. }
  7766. SendDlgItemMessage(hDlg, IDC_SCREENMODE_NATIVE2, CB_SETCURSEL, v, 0);
  7767. if (workprefs.gfx_display_sections - 1 < MAX_GUI_DISPLAY_SECTIONS)
  7768. SendDlgItemMessage(hDlg, IDC_SCREENMODE_NATIVE3, CB_SETCURSEL, workprefs.gfx_display_sections - 1, 0);
  7769. SendDlgItemMessage(hDlg, IDC_SCREENMODE_RTG, CB_RESETCONTENT, 0, 0);
  7770. SendDlgItemMessage(hDlg, IDC_SCREENMODE_RTG2, CB_RESETCONTENT, 0, 0);
  7771. WIN32GUI_LoadUIString(IDS_SCREEN_WINDOWED, buffer, sizeof buffer / sizeof (TCHAR));
  7772. SendDlgItemMessage(hDlg, IDC_SCREENMODE_RTG, CB_ADDSTRING, 0, (LPARAM)buffer);
  7773. WIN32GUI_LoadUIString(IDS_SCREEN_FULLSCREEN, buffer, sizeof buffer / sizeof (TCHAR));
  7774. SendDlgItemMessage(hDlg, IDC_SCREENMODE_RTG, CB_ADDSTRING, 0, (LPARAM)buffer);
  7775. WIN32GUI_LoadUIString(IDS_SCREEN_FULLWINDOW, buffer, sizeof buffer / sizeof (TCHAR));
  7776. SendDlgItemMessage(hDlg, IDC_SCREENMODE_RTG, CB_ADDSTRING, 0, (LPARAM)buffer);
  7777. SendDlgItemMessage(hDlg, IDC_SCREENMODE_RTG2, CB_ADDSTRING, 0, (LPARAM)_T("-"));
  7778. #if 0
  7779. WIN32GUI_LoadUIString(IDS_SCREEN_VSYNC, buffer, sizeof buffer / sizeof (TCHAR));
  7780. SendDlgItemMessage(hDlg, IDC_SCREENMODE_RTG2, CB_ADDSTRING, 0, (LPARAM)buffer);
  7781. WIN32GUI_LoadUIString(IDS_SCREEN_VSYNC_AUTOSWITCH, buffer, sizeof buffer / sizeof (TCHAR));
  7782. SendDlgItemMessage(hDlg, IDC_SCREENMODE_RTG2, CB_ADDSTRING, 0, (LPARAM)buffer);
  7783. #endif
  7784. WIN32GUI_LoadUIString(IDS_SCREEN_VSYNC2, buffer, sizeof buffer / sizeof (TCHAR));
  7785. SendDlgItemMessage(hDlg, IDC_SCREENMODE_RTG2, CB_ADDSTRING, 0, (LPARAM)buffer);
  7786. #if 0
  7787. WIN32GUI_LoadUIString(IDS_SCREEN_VSYNC2_AUTOSWITCH, buffer, sizeof buffer / sizeof (TCHAR));
  7788. SendDlgItemMessage(hDlg, IDC_SCREENMODE_RTG2, CB_ADDSTRING, 0, (LPARAM)buffer);
  7789. #endif
  7790. SendDlgItemMessage(hDlg, IDC_SCREENMODE_RTG, CB_SETCURSEL,
  7791. workprefs.gfx_apmode[1].gfx_fullscreen, 0);
  7792. v = workprefs.gfx_apmode[1].gfx_vsync;
  7793. if (v < 0)
  7794. v = 2;
  7795. else if (v > 0)
  7796. v = 1;
  7797. SendDlgItemMessage(hDlg, IDC_SCREENMODE_RTG2, CB_SETCURSEL, v, 0);
  7798. SendDlgItemMessage(hDlg, IDC_LORES, CB_RESETCONTENT, 0, 0);
  7799. WIN32GUI_LoadUIString(IDS_RES_LORES, buffer, sizeof buffer / sizeof (TCHAR));
  7800. SendDlgItemMessage(hDlg, IDC_LORES, CB_ADDSTRING, 0, (LPARAM)buffer);
  7801. WIN32GUI_LoadUIString(IDS_RES_HIRES, buffer, sizeof buffer / sizeof (TCHAR));
  7802. SendDlgItemMessage(hDlg, IDC_LORES, CB_ADDSTRING, 0, (LPARAM)buffer);
  7803. WIN32GUI_LoadUIString(IDS_RES_SUPERHIRES, buffer, sizeof buffer / sizeof (TCHAR));
  7804. SendDlgItemMessage(hDlg, IDC_LORES, CB_ADDSTRING, 0, (LPARAM)buffer);
  7805. SendDlgItemMessage (hDlg, IDC_LORES, CB_SETCURSEL, workprefs.gfx_resolution, 0);
  7806. SendDlgItemMessage(hDlg, IDC_OVERSCANMODE, CB_RESETCONTENT, 0, 0);
  7807. SendDlgItemMessage(hDlg, IDC_OVERSCANMODE, CB_ADDSTRING, 0, (LPARAM)_T("TV (narrow)"));
  7808. SendDlgItemMessage(hDlg, IDC_OVERSCANMODE, CB_ADDSTRING, 0, (LPARAM)_T("TV (standard"));
  7809. SendDlgItemMessage(hDlg, IDC_OVERSCANMODE, CB_ADDSTRING, 0, (LPARAM)_T("TV (wide)"));
  7810. SendDlgItemMessage(hDlg, IDC_OVERSCANMODE, CB_ADDSTRING, 0, (LPARAM)_T("Overscan"));
  7811. SendDlgItemMessage(hDlg, IDC_OVERSCANMODE, CB_ADDSTRING, 0, (LPARAM)_T("Overscan+"));
  7812. SendDlgItemMessage(hDlg, IDC_OVERSCANMODE, CB_ADDSTRING, 0, (LPARAM)_T("Extreme"));
  7813. SendDlgItemMessage(hDlg, IDC_OVERSCANMODE, CB_SETCURSEL, workprefs.gfx_overscanmode, 0);
  7814. SendDlgItemMessage(hDlg, IDC_AUTORESOLUTIONSELECT, CB_RESETCONTENT, 0, 0);
  7815. WIN32GUI_LoadUIString(IDS_DISABLED, buffer, sizeof buffer / sizeof (TCHAR));
  7816. SendDlgItemMessage(hDlg, IDC_AUTORESOLUTIONSELECT, CB_ADDSTRING, 0, (LPARAM)buffer);
  7817. WIN32GUI_LoadUIString(IDS_ALWAYS_ON, buffer, sizeof buffer / sizeof (TCHAR));
  7818. SendDlgItemMessage(hDlg, IDC_AUTORESOLUTIONSELECT, CB_ADDSTRING, 0, (LPARAM)buffer);
  7819. SendDlgItemMessage(hDlg, IDC_AUTORESOLUTIONSELECT, CB_ADDSTRING, 0, (LPARAM)_T("10%"));
  7820. SendDlgItemMessage(hDlg, IDC_AUTORESOLUTIONSELECT, CB_ADDSTRING, 0, (LPARAM)_T("33%"));
  7821. SendDlgItemMessage(hDlg, IDC_AUTORESOLUTIONSELECT, CB_ADDSTRING, 0, (LPARAM)_T("66%"));
  7822. if (workprefs.gfx_autoresolution == 0)
  7823. SendDlgItemMessage (hDlg, IDC_AUTORESOLUTIONSELECT, CB_SETCURSEL, 0, 0);
  7824. else if (workprefs.gfx_autoresolution == 1)
  7825. SendDlgItemMessage (hDlg, IDC_AUTORESOLUTIONSELECT, CB_SETCURSEL, 1, 0);
  7826. else if (workprefs.gfx_autoresolution <= 10)
  7827. SendDlgItemMessage (hDlg, IDC_AUTORESOLUTIONSELECT, CB_SETCURSEL, 2, 0);
  7828. else if (workprefs.gfx_autoresolution <= 33)
  7829. SendDlgItemMessage (hDlg, IDC_AUTORESOLUTIONSELECT, CB_SETCURSEL, 3, 0);
  7830. else if (workprefs.gfx_autoresolution <= 99)
  7831. SendDlgItemMessage(hDlg, IDC_AUTORESOLUTIONSELECT, CB_SETCURSEL, 4, 0);
  7832. else
  7833. SendDlgItemMessage(hDlg, IDC_AUTORESOLUTIONSELECT, CB_SETCURSEL, 5, 0);
  7834. CheckDlgButton(hDlg, IDC_AUTORESOLUTIONVGA, workprefs.gfx_autoresolution_vga);
  7835. CheckDlgButton(hDlg, IDC_BLACKER_THAN_BLACK, workprefs.gfx_blackerthanblack);
  7836. CheckDlgButton(hDlg, IDC_LORES_SMOOTHED, workprefs.gfx_lores_mode);
  7837. CheckDlgButton(hDlg, IDC_FLICKERFIXER, workprefs.gfx_scandoubler);
  7838. CheckDlgButton(hDlg, IDC_GRAYSCALE, workprefs.gfx_grayscale);
  7839. CheckDlgButton (hDlg, IDC_XCENTER, workprefs.gfx_xcenter);
  7840. CheckDlgButton (hDlg, IDC_YCENTER, workprefs.gfx_ycenter);
  7841. SendDlgItemMessage(hDlg, IDC_DISPLAY_BUFFERCNT, CB_RESETCONTENT, 0, 0);
  7842. #if 0
  7843. WIN32GUI_LoadUIString(IDS_BUFFER_SINGLE, buffer, sizeof buffer / sizeof (TCHAR));
  7844. SendDlgItemMessage(hDlg, IDC_DISPLAY_BUFFERCNT, CB_ADDSTRING, 0, (LPARAM)buffer);
  7845. #endif
  7846. WIN32GUI_LoadUIString(IDS_BUFFER_DOUBLE, buffer, sizeof buffer / sizeof (TCHAR));
  7847. SendDlgItemMessage(hDlg, IDC_DISPLAY_BUFFERCNT, CB_ADDSTRING, 0, (LPARAM)buffer);
  7848. WIN32GUI_LoadUIString(IDS_BUFFER_TRIPLE, buffer, sizeof buffer / sizeof (TCHAR));
  7849. SendDlgItemMessage(hDlg, IDC_DISPLAY_BUFFERCNT, CB_ADDSTRING, 0, (LPARAM)buffer);
  7850. SendDlgItemMessage (hDlg, IDC_DISPLAY_BUFFERCNT, CB_SETCURSEL, workprefs.gfx_apmode[0].gfx_backbuffers - 1, 0);
  7851. CheckDlgButton(hDlg, IDC_DISPLAY_VARSYNC, workprefs.gfx_variable_sync != 0);
  7852. CheckDlgButton(hDlg, IDC_DISPLAY_RESIZE, workprefs.gfx_windowed_resize != 0);
  7853. init_da (hDlg);
  7854. }
  7855. static void init_resolution_combo (HWND hDlg)
  7856. {
  7857. int i, idx;
  7858. TCHAR tmp[MAX_DPATH];
  7859. struct MultiDisplay *md = getdisplay(&workprefs, 0);
  7860. idx = -1;
  7861. SendDlgItemMessage(hDlg, IDC_RESOLUTION, CB_RESETCONTENT, 0, 0);
  7862. for (i = 0; md->DisplayModes[i].depth >= 0; i++) {
  7863. if (md->DisplayModes[i].depth > 1 && md->DisplayModes[i].residx != idx) {
  7864. _stprintf (tmp, _T("%dx%d%s"), md->DisplayModes[i].res.width, md->DisplayModes[i].res.height, md->DisplayModes[i].lace ? _T("i") : _T(""));
  7865. if (md->DisplayModes[i].rawmode)
  7866. _tcscat (tmp, _T(" (*)"));
  7867. SendDlgItemMessage(hDlg, IDC_RESOLUTION, CB_ADDSTRING, 0, (LPARAM)tmp);
  7868. idx = md->DisplayModes[i].residx;
  7869. }
  7870. }
  7871. WIN32GUI_LoadUIString (IDS_DISPLAYMODE_NATIVE, tmp, sizeof tmp / sizeof (TCHAR));
  7872. SendDlgItemMessage(hDlg, IDC_RESOLUTION, CB_ADDSTRING, 0, (LPARAM)tmp);
  7873. }
  7874. static void init_displays_combo (HWND hDlg, bool rtg)
  7875. {
  7876. const TCHAR *adapter = _T("");
  7877. struct MultiDisplay *md = Displays;
  7878. int cnt = 0, cnt2 = 0;
  7879. int displaynum;
  7880. int idx = 0;
  7881. int id = rtg ? IDC_RTG_DISPLAYSELECT : IDC_DISPLAYSELECT;
  7882. displaynum = workprefs.gfx_apmode[rtg ? APMODE_RTG : APMODE_NATIVE].gfx_display - 1;
  7883. SendDlgItemMessage (hDlg, id, CB_RESETCONTENT, 0, 0);
  7884. if (displaynum < 0)
  7885. displaynum = 0;
  7886. while (md->monitorname) {
  7887. if (_tcscmp (md->adapterkey, adapter) != 0) {
  7888. SendDlgItemMessage (hDlg, id, CB_ADDSTRING, 0, (LPARAM)md->adaptername);
  7889. adapter = md->adapterkey;
  7890. cnt++;
  7891. }
  7892. TCHAR buf[MAX_DPATH];
  7893. _stprintf (buf, _T(" %s"), md->fullname);
  7894. SendDlgItemMessage (hDlg, id, CB_ADDSTRING, 0, (LPARAM)buf);
  7895. if (displaynum == cnt2)
  7896. idx = cnt;
  7897. md++;
  7898. cnt2++;
  7899. cnt++;
  7900. }
  7901. SendDlgItemMessage (hDlg, id, CB_SETCURSEL, idx, 0);
  7902. }
  7903. static bool get_displays_combo (HWND hDlg, bool rtg)
  7904. {
  7905. struct MultiDisplay *md = Displays;
  7906. LRESULT posn;
  7907. const TCHAR *adapter = _T("");
  7908. int cnt = 0, cnt2 = 0;
  7909. int displaynum;
  7910. int id = rtg ? IDC_RTG_DISPLAYSELECT : IDC_DISPLAYSELECT;
  7911. posn = SendDlgItemMessage (hDlg, id, CB_GETCURSEL, 0, 0);
  7912. if (posn == CB_ERR)
  7913. return false;
  7914. displaynum = workprefs.gfx_apmode[rtg ? APMODE_RTG : APMODE_NATIVE].gfx_display - 1;
  7915. if (displaynum < 0)
  7916. displaynum = 0;
  7917. while (md->monitorname) {
  7918. int foundnum = -1;
  7919. if (_tcscmp (md->adapterkey, adapter) != 0) {
  7920. adapter = md->adapterkey;
  7921. if (posn == cnt)
  7922. foundnum = cnt2;
  7923. cnt++;
  7924. }
  7925. if (posn == cnt)
  7926. foundnum = cnt2;
  7927. if (foundnum >= 0) {
  7928. if (foundnum == displaynum)
  7929. return false;
  7930. workprefs.gfx_apmode[rtg ? APMODE_RTG : APMODE_NATIVE].gfx_display = foundnum + 1;
  7931. init_displays_combo (hDlg, rtg);
  7932. return true;
  7933. }
  7934. cnt++;
  7935. cnt2++;
  7936. md++;
  7937. }
  7938. return false;
  7939. }
  7940. static void values_from_displaydlg (HWND hDlg, UINT msg, WPARAM wParam, LPARAM lParam)
  7941. {
  7942. BOOL success = FALSE;
  7943. int i;
  7944. struct monconfig *gm = &workprefs.gfx_monitor[0];
  7945. int gfx_width = gm->gfx_size_win.width;
  7946. int gfx_height = gm->gfx_size_win.height;
  7947. LRESULT posn;
  7948. TCHAR tmp[200];
  7949. workprefs.gfx_apmode[0].gfx_fullscreen = SendDlgItemMessage (hDlg, IDC_SCREENMODE_NATIVE, CB_GETCURSEL, 0, 0);
  7950. workprefs.gfx_lores_mode = ischecked (hDlg, IDC_LORES_SMOOTHED);
  7951. workprefs.gfx_scandoubler = ischecked (hDlg, IDC_FLICKERFIXER);
  7952. workprefs.gfx_blackerthanblack = ischecked (hDlg, IDC_BLACKER_THAN_BLACK);
  7953. workprefs.gfx_autoresolution_vga = ischecked(hDlg, IDC_AUTORESOLUTIONVGA);
  7954. workprefs.gfx_grayscale = ischecked(hDlg, IDC_GRAYSCALE);
  7955. int vres = workprefs.gfx_vresolution;
  7956. int viscan = workprefs.gfx_iscanlines;
  7957. int vpscan = workprefs.gfx_pscanlines;
  7958. workprefs.gfx_vresolution = (ischecked (hDlg, IDC_LM_DOUBLED) || ischecked (hDlg, IDC_LM_SCANLINES) || ischecked (hDlg, IDC_LM_PDOUBLED2) || ischecked (hDlg, IDC_LM_PDOUBLED3)) ? VRES_DOUBLE : VRES_NONDOUBLE;
  7959. workprefs.gfx_iscanlines = 0;
  7960. workprefs.gfx_pscanlines = 0;
  7961. if (workprefs.gfx_vresolution >= VRES_DOUBLE) {
  7962. if (ischecked (hDlg, IDC_LM_IDOUBLED2))
  7963. workprefs.gfx_iscanlines = 1;
  7964. if (ischecked (hDlg, IDC_LM_IDOUBLED3))
  7965. workprefs.gfx_iscanlines = 2;
  7966. if (ischecked (hDlg, IDC_LM_SCANLINES))
  7967. workprefs.gfx_pscanlines = 1;
  7968. if (ischecked (hDlg, IDC_LM_PDOUBLED2))
  7969. workprefs.gfx_pscanlines = 2;
  7970. if (ischecked (hDlg, IDC_LM_PDOUBLED3))
  7971. workprefs.gfx_pscanlines = 3;
  7972. }
  7973. if (vres != workprefs.gfx_vresolution || viscan != workprefs.gfx_iscanlines || vpscan != workprefs.gfx_pscanlines) {
  7974. CheckRadioButton (hDlg, IDC_LM_NORMAL, IDC_LM_PDOUBLED3, IDC_LM_NORMAL + (workprefs.gfx_vresolution ? 1 : 0) + workprefs.gfx_pscanlines);
  7975. CheckRadioButton (hDlg, IDC_LM_INORMAL, IDC_LM_IDOUBLED3, IDC_LM_INORMAL + (workprefs.gfx_iscanlines ? workprefs.gfx_iscanlines + 1: (workprefs.gfx_vresolution ? 1 : 0)));
  7976. }
  7977. workprefs.gfx_apmode[0].gfx_backbuffers = SendDlgItemMessage (hDlg, IDC_DISPLAY_BUFFERCNT, CB_GETCURSEL, 0, 0) + 1;
  7978. workprefs.gfx_framerate = SendDlgItemMessage (hDlg, IDC_FRAMERATE, TBM_GETPOS, 0, 0);
  7979. i = SendDlgItemMessage (hDlg, IDC_SCREENMODE_NATIVE2, CB_GETCURSEL, 0, 0);
  7980. int oldvsmode = workprefs.gfx_apmode[0].gfx_vsyncmode;
  7981. int oldvs = workprefs.gfx_apmode[0].gfx_vsync;
  7982. workprefs.gfx_apmode[0].gfx_vsync = 0;
  7983. workprefs.gfx_apmode[0].gfx_vsyncmode = 0;
  7984. if (i == 1) {
  7985. workprefs.gfx_apmode[0].gfx_vsync = 1;
  7986. workprefs.gfx_apmode[0].gfx_vsyncmode = 1;
  7987. } else if (i == 2) {
  7988. workprefs.gfx_apmode[0].gfx_vsync = 2;
  7989. workprefs.gfx_apmode[0].gfx_vsyncmode = 1;
  7990. } else if (i == 3) {
  7991. workprefs.gfx_apmode[0].gfx_vsync = 1;
  7992. workprefs.gfx_apmode[0].gfx_vsyncmode = 0;
  7993. } else if (i == 4) {
  7994. workprefs.gfx_apmode[0].gfx_vsync = 2;
  7995. workprefs.gfx_apmode[0].gfx_vsyncmode = 0;
  7996. } else if (i == 5) {
  7997. workprefs.gfx_apmode[0].gfx_vsync = -1;
  7998. workprefs.gfx_apmode[0].gfx_vsyncmode = 0;
  7999. }
  8000. i = SendDlgItemMessage(hDlg, IDC_SCREENMODE_NATIVE3, CB_GETCURSEL, 0, 0);
  8001. if (i >= 0 && i < 100)
  8002. workprefs.gfx_display_sections = i + 1;
  8003. workprefs.gfx_apmode[1].gfx_fullscreen = SendDlgItemMessage (hDlg, IDC_SCREENMODE_RTG, CB_GETCURSEL, 0, 0);
  8004. i = SendDlgItemMessage (hDlg, IDC_SCREENMODE_RTG2, CB_GETCURSEL, 0, 0);
  8005. workprefs.gfx_apmode[1].gfx_vsync = 0;
  8006. workprefs.gfx_apmode[1].gfx_vsyncmode = 0;
  8007. if (i == 1) {
  8008. workprefs.gfx_apmode[1].gfx_vsync = 1;
  8009. workprefs.gfx_apmode[1].gfx_vsyncmode = 1;
  8010. } else if (i == 2) {
  8011. workprefs.gfx_apmode[1].gfx_vsync = -1;
  8012. workprefs.gfx_apmode[1].gfx_vsyncmode = 0;
  8013. }
  8014. bool updaterate = false, updateslider = false;
  8015. TCHAR label[16];
  8016. label[0] = 0;
  8017. SendDlgItemMessage (hDlg, IDC_RATE2BOX, WM_GETTEXT, sizeof label / sizeof (TCHAR), (LPARAM)label);
  8018. struct chipset_refresh *cr;
  8019. for (i = 0; i < MAX_CHIPSET_REFRESH_TOTAL; i++) {
  8020. cr = &workprefs.cr[i];
  8021. if (!_tcscmp (label, cr->label) || (cr->label[0] == 0 && label[0] == ':' &&_tstol (label + 1) == i)) {
  8022. if (workprefs.cr_selected != i) {
  8023. workprefs.cr_selected = i;
  8024. updaterate = true;
  8025. updateslider = true;
  8026. CheckDlgButton (hDlg, IDC_RATE2ENABLE, cr->locked);
  8027. ew (hDlg, IDC_FRAMERATE2, cr->locked != 0);
  8028. ew (hDlg, IDC_RATE2TEXT, cr->locked != 0);
  8029. } else {
  8030. cr->locked = ischecked (hDlg, IDC_RATE2ENABLE) != 0;
  8031. if (cr->locked) {
  8032. cr->inuse = true;
  8033. } else {
  8034. // deactivate if plain uncustomized PAL or NTSC
  8035. if (!cr->commands[0] && !cr->filterprofile[0] && cr->resolution == 7 &&
  8036. cr->horiz < 0 && cr->vert < 0 && cr->lace < 0 && cr->vsync < 0 && cr->framelength < 0 &&
  8037. (cr == &workprefs.cr[CHIPSET_REFRESH_PAL] || cr == &workprefs.cr[CHIPSET_REFRESH_NTSC])) {
  8038. cr->inuse = false;
  8039. }
  8040. }
  8041. }
  8042. break;
  8043. }
  8044. }
  8045. if (cr->locked) {
  8046. if (msg == WM_HSCROLL) {
  8047. i = SendDlgItemMessage (hDlg, IDC_FRAMERATE2, TBM_GETPOS, 0, 0);
  8048. if (i != (int)cr->rate)
  8049. cr->rate = (double)i;
  8050. updaterate = true;
  8051. } else if (LOWORD (wParam) == IDC_RATE2TEXT && HIWORD (wParam) == EN_KILLFOCUS) {
  8052. if (GetDlgItemText(hDlg, IDC_RATE2TEXT, tmp, sizeof tmp / sizeof (TCHAR))) {
  8053. cr->rate = _tstof (tmp);
  8054. updaterate = true;
  8055. updateslider = true;
  8056. }
  8057. }
  8058. } else if (i == CHIPSET_REFRESH_PAL) {
  8059. cr->rate = 50.0;
  8060. } else if (i == CHIPSET_REFRESH_NTSC) {
  8061. cr->rate = 60.0;
  8062. }
  8063. if (cr->rate > 0 && cr->rate < 1) {
  8064. cr->rate = currprefs.ntscmode ? 60.0 : 50.0;
  8065. updaterate = true;
  8066. }
  8067. if (cr->rate > 300) {
  8068. cr->rate = currprefs.ntscmode ? 60.0 : 50.0;
  8069. updaterate = true;
  8070. }
  8071. if (updaterate) {
  8072. TCHAR buffer[20];
  8073. _stprintf (buffer, _T("%.6f"), cr->rate);
  8074. SetDlgItemText (hDlg, IDC_RATE2TEXT, buffer);
  8075. }
  8076. if (updateslider) {
  8077. SendDlgItemMessage (hDlg, IDC_FRAMERATE2, TBM_SETPOS, TRUE, (LPARAM)cr->rate);
  8078. }
  8079. workprefs.gfx_xcenter = ischecked (hDlg, IDC_XCENTER) ? 2 : 0; /* Smart centering */
  8080. workprefs.gfx_ycenter = ischecked (hDlg, IDC_YCENTER) ? 2 : 0; /* Smart centering */
  8081. workprefs.gfx_variable_sync = ischecked(hDlg, IDC_DISPLAY_VARSYNC) ? 1 : 0;
  8082. workprefs.gfx_windowed_resize = ischecked(hDlg, IDC_DISPLAY_RESIZE);
  8083. LRESULT posn1 = SendDlgItemMessage (hDlg, IDC_AUTORESOLUTIONSELECT, CB_GETCURSEL, 0, 0);
  8084. if (posn1 != CB_ERR) {
  8085. if (posn1 == 0)
  8086. workprefs.gfx_autoresolution = 0;
  8087. else if (posn1 == 1)
  8088. workprefs.gfx_autoresolution = 1;
  8089. else if (posn1 == 2)
  8090. workprefs.gfx_autoresolution = 10;
  8091. else if (posn1 == 3)
  8092. workprefs.gfx_autoresolution = 33;
  8093. else if (posn1 == 4)
  8094. workprefs.gfx_autoresolution = 66;
  8095. else
  8096. workprefs.gfx_autoresolution = 100;
  8097. }
  8098. int dmode = -1;
  8099. bool native = false;
  8100. struct MultiDisplay *md = getdisplay(&workprefs, 0);
  8101. posn1 = SendDlgItemMessage (hDlg, IDC_RESOLUTION, CB_GETCURSEL, 0, 0);
  8102. LRESULT posn2 = SendDlgItemMessage (hDlg, IDC_RESOLUTIONDEPTH, CB_GETCURSEL, 0, 0);
  8103. if (posn1 != CB_ERR) {
  8104. if (posn2 == CB_ERR)
  8105. posn2 = 0;
  8106. workprefs.gfx_monitor[0].gfx_size_fs.special = 0;
  8107. for (dmode = 0; md->DisplayModes[dmode].depth >= 0; dmode++) {
  8108. if (md->DisplayModes[dmode].residx == posn1)
  8109. break;
  8110. }
  8111. if (md->DisplayModes[dmode].depth <= 0) {
  8112. for (dmode = 0; md->DisplayModes[dmode].depth >= 0; dmode++) {
  8113. if (md->DisplayModes[dmode].res.width == md->rect.right - md->rect.left &&
  8114. md->DisplayModes[dmode].res.height == md->rect.bottom - md->rect.top &&
  8115. md->DisplayModes[dmode].depth == gui_display_depths[posn2])
  8116. {
  8117. workprefs.gfx_monitor[0].gfx_size_fs.special = WH_NATIVE;
  8118. break;
  8119. }
  8120. }
  8121. if (md->DisplayModes[dmode].depth <= 0)
  8122. dmode = -1;
  8123. } else {
  8124. i = dmode;
  8125. while (md->DisplayModes[dmode].residx == posn1) {
  8126. if (md->DisplayModes[dmode].depth == gui_display_depths[posn2])
  8127. break;
  8128. dmode++;
  8129. }
  8130. if (md->DisplayModes[dmode].residx != posn1)
  8131. dmode = i;
  8132. }
  8133. }
  8134. if (oldvsmode != workprefs.gfx_apmode[0].gfx_vsyncmode || oldvs != workprefs.gfx_apmode[0].gfx_vsync)
  8135. init_frequency_combo (hDlg, dmode);
  8136. if (msg == WM_COMMAND && HIWORD (wParam) == CBN_SELCHANGE)
  8137. {
  8138. if (LOWORD (wParam) == IDC_DISPLAYSELECT) {
  8139. get_displays_combo (hDlg, false);
  8140. init_resolution_combo (hDlg);
  8141. init_display_mode (hDlg);
  8142. return;
  8143. } else if (LOWORD(wParam) == IDC_LORES) {
  8144. posn = SendDlgItemMessage(hDlg, IDC_LORES, CB_GETCURSEL, 0, 0);
  8145. if (posn != CB_ERR)
  8146. workprefs.gfx_resolution = posn;
  8147. } else if (LOWORD(wParam) == IDC_OVERSCANMODE) {
  8148. posn = SendDlgItemMessage(hDlg, IDC_OVERSCANMODE, CB_GETCURSEL, 0, 0);
  8149. if (posn != CB_ERR)
  8150. workprefs.gfx_overscanmode = posn;
  8151. } else if ((LOWORD (wParam) == IDC_RESOLUTION || LOWORD(wParam) == IDC_RESOLUTIONDEPTH) && dmode >= 0) {
  8152. workprefs.gfx_monitor[0].gfx_size_fs.width = md->DisplayModes[dmode].res.width;
  8153. workprefs.gfx_monitor[0].gfx_size_fs.height = md->DisplayModes[dmode].res.height;
  8154. switch(md->DisplayModes[dmode].depth)
  8155. {
  8156. case 2:
  8157. workprefs.color_mode = 2;
  8158. break;
  8159. case 3:
  8160. case 4:
  8161. workprefs.color_mode = 5;
  8162. break;
  8163. default:
  8164. workprefs.color_mode = 0;
  8165. break;
  8166. }
  8167. /* Set the Int boxes */
  8168. SetDlgItemInt (hDlg, IDC_XSIZE, workprefs.gfx_monitor[0].gfx_size_win.width, FALSE);
  8169. SetDlgItemInt (hDlg, IDC_YSIZE, workprefs.gfx_monitor[0].gfx_size_win.height, FALSE);
  8170. init_display_mode (hDlg);
  8171. } else if (LOWORD (wParam) == IDC_REFRESHRATE && dmode >= 0) {
  8172. LRESULT posn1;
  8173. posn1 = SendDlgItemMessage (hDlg, IDC_REFRESHRATE, CB_GETCURSEL, 0, 0);
  8174. if (posn1 == CB_ERR)
  8175. return;
  8176. if (posn1 == 0) {
  8177. workprefs.gfx_apmode[APMODE_NATIVE].gfx_refreshrate = 0;
  8178. workprefs.gfx_apmode[APMODE_NATIVE].gfx_interlaced = dmode >= 0 && md->DisplayModes[dmode].lace;
  8179. } else {
  8180. posn1--;
  8181. workprefs.gfx_apmode[APMODE_NATIVE].gfx_refreshrate = storedrefreshrates[posn1].rate;
  8182. workprefs.gfx_apmode[APMODE_NATIVE].gfx_interlaced = (storedrefreshrates[posn1].type & REFRESH_RATE_LACE) != 0;
  8183. }
  8184. values_to_displaydlg (hDlg);
  8185. } else if (LOWORD (wParam) == IDC_DA_MODE) {
  8186. da_mode_selected = SendDlgItemMessage (hDlg, IDC_DA_MODE, CB_GETCURSEL, 0, 0);
  8187. init_da (hDlg);
  8188. handle_da (hDlg);
  8189. }
  8190. }
  8191. updatewinfsmode(0, &workprefs);
  8192. }
  8193. static int hw3d_changed;
  8194. static INT_PTR CALLBACK DisplayDlgProc (HWND hDlg, UINT msg, WPARAM wParam, LPARAM lParam)
  8195. {
  8196. static int recursive = 0;
  8197. if (dialog_inhibit)
  8198. return 0;
  8199. switch (msg)
  8200. {
  8201. case WM_INITDIALOG:
  8202. pages[DISPLAY_ID] = hDlg;
  8203. currentpage = DISPLAY_ID;
  8204. SendDlgItemMessage (hDlg, IDC_FRAMERATE, TBM_SETPAGESIZE, 0, 1);
  8205. SendDlgItemMessage (hDlg, IDC_FRAMERATE, TBM_SETRANGE, TRUE, MAKELONG (MIN_REFRESH_RATE, MAX_REFRESH_RATE));
  8206. SendDlgItemMessage (hDlg, IDC_FRAMERATE2, TBM_SETPAGESIZE, 0, 1);
  8207. SendDlgItemMessage (hDlg, IDC_FRAMERATE2, TBM_SETRANGE, TRUE, MAKELONG (1, 99));
  8208. recursive++;
  8209. init_displays_combo (hDlg, false);
  8210. init_resolution_combo (hDlg);
  8211. init_da (hDlg);
  8212. recursive--;
  8213. case WM_USER:
  8214. recursive++;
  8215. values_to_displaydlg (hDlg);
  8216. enable_for_displaydlg (hDlg);
  8217. recursive--;
  8218. break;
  8219. case WM_HSCROLL:
  8220. case WM_COMMAND:
  8221. if (recursive > 0)
  8222. break;
  8223. recursive++;
  8224. switch(LOWORD(wParam))
  8225. {
  8226. case IDC_DA_RESET:
  8227. {
  8228. int *p;
  8229. da_mode_selected = SendDlgItemMessage(hDlg, IDC_DA_MODE, CB_GETCURSEL, 0, 0);
  8230. p = getp_da(hDlg);
  8231. if (p)
  8232. *p = 0;
  8233. init_da(hDlg);
  8234. update_da(hDlg);
  8235. }
  8236. break;
  8237. case IDC_XSIZE:
  8238. {
  8239. BOOL success;
  8240. struct monconfig *gm = &workprefs.gfx_monitor[0];
  8241. gm->gfx_size_win.width = GetDlgItemInt(hDlg, IDC_XSIZE, &success, FALSE);
  8242. if (!success)
  8243. gm->gfx_size_win.width = 800;
  8244. }
  8245. break;
  8246. case IDC_YSIZE:
  8247. {
  8248. BOOL success;
  8249. struct monconfig *gm = &workprefs.gfx_monitor[0];
  8250. gm->gfx_size_win.height = GetDlgItemInt(hDlg, IDC_YSIZE, &success, FALSE);
  8251. if (!success)
  8252. gm->gfx_size_win.height = 600;
  8253. }
  8254. break;
  8255. default:
  8256. handle_da (hDlg);
  8257. values_from_displaydlg (hDlg, msg, wParam, lParam);
  8258. enable_for_displaydlg (hDlg);
  8259. if (LOWORD (wParam) == IDC_RATE2ENABLE || LOWORD(wParam) == IDC_SCREENMODE_NATIVE3 || LOWORD(wParam) == IDC_SCREENMODE_NATIVE2 || LOWORD(wParam) == IDC_SCREENMODE_NATIVE) {
  8260. values_to_displaydlg (hDlg);
  8261. }
  8262. }
  8263. recursive--;
  8264. break;
  8265. }
  8266. if (hw3d_changed && recursive == 0) {
  8267. recursive++;
  8268. enable_for_displaydlg (hDlg);
  8269. values_to_displaydlg (hDlg);
  8270. hw3d_changed = 0;
  8271. recursive--;
  8272. }
  8273. return FALSE;
  8274. }
  8275. static void values_to_chipsetdlg (HWND hDlg)
  8276. {
  8277. TCHAR Nth[MAX_NTH_LENGTH];
  8278. TCHAR *blah[1] = { Nth };
  8279. TCHAR *string = NULL;
  8280. switch(workprefs.chipset_mask)
  8281. {
  8282. case 0:
  8283. CheckRadioButton(hDlg, IDC_OCS, IDC_AGA, IDC_OCS + 0);
  8284. break;
  8285. case CSMASK_ECS_AGNUS:
  8286. CheckRadioButton(hDlg, IDC_OCS, IDC_AGA, IDC_OCS + 1);
  8287. break;
  8288. case CSMASK_ECS_DENISE:
  8289. CheckRadioButton(hDlg, IDC_OCS, IDC_AGA, IDC_OCS + 2);
  8290. break;
  8291. case CSMASK_ECS_AGNUS | CSMASK_ECS_DENISE:
  8292. CheckRadioButton(hDlg, IDC_OCS, IDC_AGA, IDC_OCS + 3);
  8293. break;
  8294. case CSMASK_AGA:
  8295. case CSMASK_ECS_AGNUS | CSMASK_ECS_DENISE | CSMASK_AGA:
  8296. CheckRadioButton(hDlg, IDC_OCS, IDC_AGA, IDC_OCS + 4);
  8297. break;
  8298. }
  8299. CheckDlgButton(hDlg, IDC_NTSC, workprefs.ntscmode);
  8300. CheckDlgButton(hDlg, IDC_GENLOCK, workprefs.genlock);
  8301. CheckDlgButton(hDlg, IDC_BLITIMM, workprefs.immediate_blits);
  8302. CheckDlgButton(hDlg, IDC_BLITWAIT, workprefs.waiting_blits);
  8303. CheckDlgButton(hDlg, IDC_KEYBOARD_CONNECTED, workprefs.keyboard_connected);
  8304. CheckDlgButton(hDlg, IDC_SUBPIXEL, workprefs.chipset_hr);
  8305. CheckRadioButton(hDlg, IDC_COLLISION0, IDC_COLLISION3, IDC_COLLISION0 + workprefs.collision_level);
  8306. CheckDlgButton(hDlg, IDC_CYCLEEXACT, workprefs.cpu_cycle_exact);
  8307. CheckDlgButton(hDlg, IDC_CYCLEEXACTMEMORY, workprefs.cpu_memory_cycle_exact);
  8308. SendDlgItemMessage(hDlg, IDC_CS_EXT, CB_SETCURSEL, workprefs.cs_compatible, 0);
  8309. SendDlgItemMessage(hDlg, IDC_MONITOREMU, CB_SETCURSEL, workprefs.monitoremu, 0);
  8310. SendDlgItemMessage(hDlg, IDC_MONITOREMU_MON, CB_SETCURSEL, workprefs.monitoremu_mon, 0);
  8311. SendDlgItemMessage(hDlg, IDC_GENLOCKMODE, CB_SETCURSEL, workprefs.genlock_image, 0);
  8312. SendDlgItemMessage(hDlg, IDC_GENLOCKMIX, CB_SETCURSEL, workprefs.genlock_mix / 25, 0);
  8313. CheckDlgButton(hDlg, IDC_GENLOCK_ALPHA, workprefs.genlock_alpha);
  8314. CheckDlgButton(hDlg, IDC_GENLOCK_KEEP_ASPECT, workprefs.genlock_aspect);
  8315. }
  8316. static int cs_compatible = CP_GENERIC;
  8317. static void values_from_chipsetdlg (HWND hDlg, UINT msg, WPARAM wParam, LPARAM lParam)
  8318. {
  8319. BOOL success = FALSE;
  8320. int nn;
  8321. bool n1, n2;
  8322. int id = LOWORD(wParam);
  8323. workprefs.genlock = ischecked (hDlg, IDC_GENLOCK);
  8324. workprefs.genlock_alpha = ischecked(hDlg, IDC_GENLOCK_ALPHA);
  8325. workprefs.genlock_aspect = ischecked(hDlg, IDC_GENLOCK_KEEP_ASPECT);
  8326. workprefs.immediate_blits = ischecked (hDlg, IDC_BLITIMM);
  8327. workprefs.waiting_blits = ischecked (hDlg, IDC_BLITWAIT) ? 1 : 0;
  8328. workprefs.chipset_hr = ischecked(hDlg, IDC_SUBPIXEL);
  8329. workprefs.keyboard_connected = ischecked(hDlg, IDC_KEYBOARD_CONNECTED) ? 1 : 0;
  8330. n2 = ischecked (hDlg, IDC_CYCLEEXACTMEMORY);
  8331. n1 = ischecked (hDlg, IDC_CYCLEEXACT);
  8332. if (workprefs.cpu_cycle_exact != n1 || workprefs.cpu_memory_cycle_exact != n2) {
  8333. if (id == IDC_CYCLEEXACTMEMORY) {
  8334. if (n2) {
  8335. // n2: f -> t
  8336. if (workprefs.cpu_model < 68020) {
  8337. n1 = true;
  8338. CheckDlgButton (hDlg, IDC_CYCLEEXACT, n1);
  8339. }
  8340. } else {
  8341. // n2: t -> f
  8342. n1 = false;
  8343. CheckDlgButton (hDlg, IDC_CYCLEEXACT, n1);
  8344. }
  8345. } else if (id == IDC_CYCLEEXACT) {
  8346. if (n1) {
  8347. // n1: f -> t
  8348. n2 = true;
  8349. CheckDlgButton (hDlg, IDC_CYCLEEXACTMEMORY, n2);
  8350. } else {
  8351. // n1: t -> f
  8352. if (workprefs.cpu_model < 68020) {
  8353. n2 = false;
  8354. CheckDlgButton (hDlg, IDC_CYCLEEXACTMEMORY, n2);
  8355. }
  8356. }
  8357. }
  8358. workprefs.cpu_cycle_exact = n1;
  8359. workprefs.cpu_memory_cycle_exact = workprefs.blitter_cycle_exact = n2;
  8360. if (n2) {
  8361. if (workprefs.cpu_model == 68000)
  8362. workprefs.cpu_compatible = 1;
  8363. if (workprefs.cpu_model <= 68030)
  8364. workprefs.m68k_speed = 0;
  8365. if (workprefs.immediate_blits) {
  8366. workprefs.immediate_blits = false;
  8367. CheckDlgButton (hDlg, IDC_BLITIMM, FALSE);
  8368. }
  8369. workprefs.gfx_framerate = 1;
  8370. workprefs.cachesize = 0;
  8371. }
  8372. }
  8373. workprefs.collision_level = ischecked (hDlg, IDC_COLLISION0) ? 0
  8374. : ischecked (hDlg, IDC_COLLISION1) ? 1
  8375. : ischecked (hDlg, IDC_COLLISION2) ? 2 : 3;
  8376. workprefs.chipset_mask = ischecked (hDlg, IDC_OCS) ? 0
  8377. : ischecked (hDlg, IDC_ECS_AGNUS) ? CSMASK_ECS_AGNUS
  8378. : ischecked (hDlg, IDC_ECS_DENISE) ? CSMASK_ECS_DENISE
  8379. : ischecked (hDlg, IDC_ECS) ? CSMASK_ECS_AGNUS | CSMASK_ECS_DENISE
  8380. : CSMASK_AGA | CSMASK_ECS_AGNUS | CSMASK_ECS_DENISE;
  8381. n1 = ischecked (hDlg, IDC_NTSC);
  8382. if (workprefs.ntscmode != n1) {
  8383. workprefs.ntscmode = n1;
  8384. }
  8385. nn = SendDlgItemMessage (hDlg, IDC_CS_EXT, CB_GETCURSEL, 0, 0);
  8386. if (nn != CB_ERR) {
  8387. workprefs.cs_compatible = nn;
  8388. cs_compatible = nn;
  8389. built_in_chipset_prefs (&workprefs);
  8390. }
  8391. nn = SendDlgItemMessage(hDlg, IDC_MONITOREMU, CB_GETCURSEL, 0, 0);
  8392. if (nn != CB_ERR)
  8393. workprefs.monitoremu = nn;
  8394. nn = SendDlgItemMessage(hDlg, IDC_MONITOREMU_MON, CB_GETCURSEL, 0, 0);
  8395. if (nn != CB_ERR)
  8396. workprefs.monitoremu_mon = nn;
  8397. nn = SendDlgItemMessage(hDlg, IDC_GENLOCKMODE, CB_GETCURSEL, 0, 0);
  8398. if (nn != CB_ERR && nn != workprefs.genlock_image) {
  8399. workprefs.genlock_image = nn;
  8400. if (workprefs.genlock_image == 3) {
  8401. SendDlgItemMessage(hDlg, IDC_GENLOCKFILE, WM_SETTEXT, 0, (LPARAM)workprefs.genlock_image_file);
  8402. } else if (workprefs.genlock_image == 4) {
  8403. SendDlgItemMessage(hDlg, IDC_GENLOCKFILE, WM_SETTEXT, 0, (LPARAM)workprefs.genlock_video_file);
  8404. }
  8405. }
  8406. nn = SendDlgItemMessage(hDlg, IDC_GENLOCKMIX, CB_GETCURSEL, 0, 0);
  8407. if (nn != CB_ERR) {
  8408. workprefs.genlock_mix = nn * 25;
  8409. if (workprefs.genlock_mix >= 250)
  8410. workprefs.genlock_mix = 255;
  8411. }
  8412. }
  8413. static void setgenlock(HWND hDlg)
  8414. {
  8415. setautocomplete(hDlg, IDC_GENLOCKFILE);
  8416. if (workprefs.genlock_image == 3) {
  8417. addhistorymenu(hDlg, workprefs.genlock_image_file, IDC_GENLOCKFILE, HISTORY_GENLOCK_IMAGE, true, -1);
  8418. } else if (workprefs.genlock_image == 4 || workprefs.genlock_image >= 6) {
  8419. addhistorymenu(hDlg, workprefs.genlock_video_file, IDC_GENLOCKFILE, HISTORY_GENLOCK_VIDEO, true, -1);
  8420. }
  8421. }
  8422. static INT_PTR CALLBACK ChipsetDlgProc (HWND hDlg, UINT msg, WPARAM wParam, LPARAM lParam)
  8423. {
  8424. static int recursive = 0;
  8425. TCHAR buffer[MAX_DPATH], tmp[MAX_DPATH];
  8426. if (dialog_inhibit)
  8427. return 0;
  8428. switch (msg) {
  8429. case WM_INITDIALOG:
  8430. {
  8431. pages[CHIPSET_ID] = hDlg;
  8432. currentpage = CHIPSET_ID;
  8433. SendDlgItemMessage(hDlg, IDC_CS_EXT, CB_RESETCONTENT, 0, 0);
  8434. SendDlgItemMessage(hDlg, IDC_CS_EXT, CB_ADDSTRING, 0, (LPARAM)_T("Custom"));
  8435. WIN32GUI_LoadUIString(IDS_GENERIC, buffer, sizeof buffer / sizeof(TCHAR));
  8436. SendDlgItemMessage(hDlg, IDC_CS_EXT, CB_ADDSTRING, 0, (LPARAM)buffer);
  8437. SendDlgItemMessage(hDlg, IDC_CS_EXT, CB_ADDSTRING, 0, (LPARAM)_T("CDTV"));
  8438. SendDlgItemMessage(hDlg, IDC_CS_EXT, CB_ADDSTRING, 0, (LPARAM)_T("CDTV-CR"));
  8439. SendDlgItemMessage(hDlg, IDC_CS_EXT, CB_ADDSTRING, 0, (LPARAM)_T("CD32"));
  8440. SendDlgItemMessage(hDlg, IDC_CS_EXT, CB_ADDSTRING, 0, (LPARAM)_T("A500"));
  8441. SendDlgItemMessage(hDlg, IDC_CS_EXT, CB_ADDSTRING, 0, (LPARAM)_T("A500+"));
  8442. SendDlgItemMessage(hDlg, IDC_CS_EXT, CB_ADDSTRING, 0, (LPARAM)_T("A600"));
  8443. SendDlgItemMessage(hDlg, IDC_CS_EXT, CB_ADDSTRING, 0, (LPARAM)_T("A1000"));
  8444. SendDlgItemMessage(hDlg, IDC_CS_EXT, CB_ADDSTRING, 0, (LPARAM)_T("A1200"));
  8445. SendDlgItemMessage(hDlg, IDC_CS_EXT, CB_ADDSTRING, 0, (LPARAM)_T("A2000"));
  8446. SendDlgItemMessage(hDlg, IDC_CS_EXT, CB_ADDSTRING, 0, (LPARAM)_T("A3000"));
  8447. SendDlgItemMessage(hDlg, IDC_CS_EXT, CB_ADDSTRING, 0, (LPARAM)_T("A3000T"));
  8448. SendDlgItemMessage(hDlg, IDC_CS_EXT, CB_ADDSTRING, 0, (LPARAM)_T("A4000"));
  8449. SendDlgItemMessage(hDlg, IDC_CS_EXT, CB_ADDSTRING, 0, (LPARAM)_T("A4000T"));
  8450. SendDlgItemMessage(hDlg, IDC_CS_EXT, CB_ADDSTRING, 0, (LPARAM)_T("Velvet"));
  8451. SendDlgItemMessage(hDlg, IDC_CS_EXT, CB_ADDSTRING, 0, (LPARAM)_T("Casablanca"));
  8452. SendDlgItemMessage(hDlg, IDC_CS_EXT, CB_ADDSTRING, 0, (LPARAM)_T("DraCo"));
  8453. SendDlgItemMessage(hDlg, IDC_GENLOCKMODE, CB_RESETCONTENT, 0, 0);
  8454. SendDlgItemMessage(hDlg, IDC_GENLOCKMODE, CB_ADDSTRING, 0, (LPARAM)_T("-"));
  8455. WIN32GUI_LoadUIString(IDS_GENLOCK_OPTIONS, tmp, sizeof tmp / sizeof(TCHAR));
  8456. TCHAR *p1 = tmp;
  8457. for (;;) {
  8458. TCHAR *p2 = _tcschr(p1, '\n');
  8459. if (p2 && _tcslen(p2) > 0) {
  8460. *p2++ = 0;
  8461. SendDlgItemMessage(hDlg, IDC_GENLOCKMODE, CB_ADDSTRING, 0, (LPARAM)p1);
  8462. p1 = p2;
  8463. } else
  8464. break;
  8465. }
  8466. SendDlgItemMessage(hDlg, IDC_GENLOCKMIX, CB_RESETCONTENT, 0, 0);
  8467. for (int i = 0; i <= 10; i++) {
  8468. _stprintf(buffer, _T("%d%%"), (10 - i) * 10);
  8469. SendDlgItemMessage(hDlg, IDC_GENLOCKMIX, CB_ADDSTRING, 0, (LPARAM)buffer);
  8470. }
  8471. SendDlgItemMessage(hDlg, IDC_MONITOREMU, CB_RESETCONTENT, 0, 0);
  8472. SendDlgItemMessage(hDlg, IDC_MONITOREMU, CB_ADDSTRING, 0, (LPARAM)_T("-"));
  8473. WIN32GUI_LoadUIString(IDS_AUTODETECT, buffer, sizeof buffer / sizeof(TCHAR));
  8474. SendDlgItemMessage(hDlg, IDC_MONITOREMU, CB_ADDSTRING, 0, (LPARAM)buffer);
  8475. for (int i = 0; specialmonitorfriendlynames[i]; i++) {
  8476. _stprintf(buffer, _T("%s (%s)"), specialmonitorfriendlynames[i], specialmonitormanufacturernames[i]);
  8477. SendDlgItemMessage(hDlg, IDC_MONITOREMU, CB_ADDSTRING, 0, (LPARAM)buffer);
  8478. }
  8479. SendDlgItemMessage(hDlg, IDC_MONITOREMU_MON, CB_RESETCONTENT, 0, 0);
  8480. for (int i = 0; i < MAX_AMIGAMONITORS; i++) {
  8481. _stprintf(buffer, _T("%d"), i + 1);
  8482. SendDlgItemMessage(hDlg, IDC_MONITOREMU_MON, CB_ADDSTRING, 0, (LPARAM)buffer);
  8483. }
  8484. #ifndef AGA
  8485. ew(hDlg, IDC_AGA, FALSE);
  8486. #endif
  8487. setgenlock(hDlg);
  8488. }
  8489. case WM_USER:
  8490. recursive++;
  8491. values_to_chipsetdlg (hDlg);
  8492. enable_for_chipsetdlg (hDlg);
  8493. recursive--;
  8494. break;
  8495. case WM_COMMAND:
  8496. if (recursive > 0)
  8497. break;
  8498. recursive++;
  8499. if (HIWORD(wParam) == CBN_SELCHANGE || HIWORD(wParam) == CBN_KILLFOCUS) {
  8500. switch (LOWORD(wParam))
  8501. {
  8502. case IDC_GENLOCKFILE:
  8503. {
  8504. TCHAR *p = workprefs.genlock_image == 3 ? workprefs.genlock_image_file : workprefs.genlock_video_file;
  8505. getcomboboxtext(hDlg, IDC_GENLOCKFILE, p, MAX_DPATH);
  8506. parsefilepath(p, MAX_DPATH);
  8507. addhistorymenu(hDlg, p, IDC_GENLOCKFILE, workprefs.genlock_image == 3 ? HISTORY_GENLOCK_IMAGE : HISTORY_GENLOCK_VIDEO, true, -1);
  8508. break;
  8509. }
  8510. }
  8511. }
  8512. switch (LOWORD(wParam))
  8513. {
  8514. case IDC_GENLOCKFILESELECT:
  8515. {
  8516. TCHAR path[MAX_DPATH];
  8517. path[0] = 0;
  8518. DiskSelection(hDlg, IDC_GENLOCKFILESELECT, workprefs.genlock_image == 3 ? 20 : 21, &workprefs, NULL, path);
  8519. break;
  8520. }
  8521. case IDC_BLITWAIT:
  8522. if (workprefs.immediate_blits) {
  8523. workprefs.immediate_blits = false;
  8524. CheckDlgButton (hDlg, IDC_BLITIMM, FALSE);
  8525. }
  8526. break;
  8527. case IDC_BLITIMM:
  8528. if (workprefs.waiting_blits) {
  8529. workprefs.waiting_blits = false;
  8530. CheckDlgButton (hDlg, IDC_BLITWAIT, FALSE);
  8531. }
  8532. break;
  8533. }
  8534. values_from_chipsetdlg(hDlg, msg, wParam, lParam);
  8535. enable_for_chipsetdlg(hDlg);
  8536. recursive--;
  8537. break;
  8538. case WM_HSCROLL:
  8539. if (recursive > 0)
  8540. break;
  8541. recursive++;
  8542. values_from_chipsetdlg (hDlg, msg, wParam, lParam);
  8543. enable_for_chipsetdlg( hDlg );
  8544. recursive--;
  8545. break;
  8546. }
  8547. return FALSE;
  8548. }
  8549. static void values_to_chipsetdlg2 (HWND hDlg)
  8550. {
  8551. TCHAR txt[32];
  8552. uae_u32 rev;
  8553. switch(workprefs.cs_ciaatod)
  8554. {
  8555. case 0:
  8556. CheckRadioButton(hDlg, IDC_CS_CIAA_TOD1, IDC_CS_CIAA_TOD3, IDC_CS_CIAA_TOD1);
  8557. break;
  8558. case 1:
  8559. CheckRadioButton(hDlg, IDC_CS_CIAA_TOD1, IDC_CS_CIAA_TOD3, IDC_CS_CIAA_TOD2);
  8560. break;
  8561. case 2:
  8562. CheckRadioButton(hDlg, IDC_CS_CIAA_TOD1, IDC_CS_CIAA_TOD3, IDC_CS_CIAA_TOD3);
  8563. break;
  8564. }
  8565. switch(workprefs.cs_rtc)
  8566. {
  8567. case 0:
  8568. CheckRadioButton(hDlg, IDC_CS_RTC1, IDC_CS_RTC4, IDC_CS_RTC1);
  8569. break;
  8570. case 1:
  8571. CheckRadioButton(hDlg, IDC_CS_RTC1, IDC_CS_RTC4, IDC_CS_RTC2);
  8572. break;
  8573. case 2:
  8574. CheckRadioButton(hDlg, IDC_CS_RTC1, IDC_CS_RTC4, IDC_CS_RTC3);
  8575. break;
  8576. case 3:
  8577. CheckRadioButton(hDlg, IDC_CS_RTC1, IDC_CS_RTC4, IDC_CS_RTC4);
  8578. break;
  8579. }
  8580. CheckDlgButton(hDlg, IDC_CS_COMPATIBLE, workprefs.cs_compatible != 0);
  8581. CheckDlgButton(hDlg, IDC_CS_RESETWARNING, workprefs.cs_resetwarning);
  8582. CheckDlgButton(hDlg, IDC_CS_NOEHB, workprefs.cs_denisenoehb);
  8583. CheckDlgButton(hDlg, IDC_CS_DIPAGNUS, workprefs.cs_dipagnus);
  8584. CheckDlgButton(hDlg, IDC_CS_KSMIRROR_E0, workprefs.cs_ksmirror_e0);
  8585. CheckDlgButton(hDlg, IDC_CS_KSMIRROR_A8, workprefs.cs_ksmirror_a8);
  8586. CheckDlgButton(hDlg, IDC_CS_CIAOVERLAY, workprefs.cs_ciaoverlay);
  8587. CheckDlgButton(hDlg, IDC_CS_DF0IDHW, workprefs.cs_df0idhw);
  8588. CheckDlgButton(hDlg, IDC_CS_CD32CD, workprefs.cs_cd32cd);
  8589. CheckDlgButton(hDlg, IDC_CS_CD32C2P, workprefs.cs_cd32c2p);
  8590. CheckDlgButton(hDlg, IDC_CS_CD32NVRAM, workprefs.cs_cd32nvram);
  8591. CheckDlgButton(hDlg, IDC_CS_CDTVCD, workprefs.cs_cdtvcd);
  8592. CheckDlgButton(hDlg, IDC_CS_CDTVCR, workprefs.cs_cdtvcr);
  8593. CheckDlgButton(hDlg, IDC_CS_CDTVRAM, workprefs.cs_cdtvram);
  8594. CheckDlgButton(hDlg, IDC_CS_A1000RAM, workprefs.cs_a1000ram);
  8595. CheckDlgButton(hDlg, IDC_CS_RAMSEY, workprefs.cs_ramseyrev >= 0);
  8596. CheckDlgButton(hDlg, IDC_CS_FATGARY, workprefs.cs_fatgaryrev >= 0);
  8597. CheckDlgButton(hDlg, IDC_CS_AGNUS, workprefs.cs_agnusrev >= 0);
  8598. CheckDlgButton(hDlg, IDC_CS_DENISE, workprefs.cs_deniserev >= 0);
  8599. CheckDlgButton(hDlg, IDC_CS_DMAC, workprefs.cs_mbdmac & 1);
  8600. CheckDlgButton(hDlg, IDC_CS_DMAC2, workprefs.cs_mbdmac & 2);
  8601. CheckDlgButton(hDlg, IDC_CS_PCMCIA, workprefs.cs_pcmcia);
  8602. CheckDlgButton(hDlg, IDC_CS_SLOWISFAST, workprefs.cs_slowmemisfast);
  8603. CheckDlgButton(hDlg, IDC_CS_CIATODBUG, workprefs.cs_ciatodbug);
  8604. CheckDlgButton(hDlg, IDC_CS_Z3AUTOCONFIG, workprefs.cs_z3autoconfig);
  8605. CheckDlgButton(hDlg, IDC_CS_IDE1, workprefs.cs_ide > 0 && (workprefs.cs_ide & 1));
  8606. CheckDlgButton(hDlg, IDC_CS_IDE2, workprefs.cs_ide > 0 && (workprefs.cs_ide & 2));
  8607. CheckDlgButton(hDlg, IDC_CS_1MCHIPJUMPER, workprefs.cs_1mchipjumper || workprefs.chipmem.size >= 0x100000);
  8608. CheckDlgButton(hDlg, IDC_CS_BYTECUSTOMWRITEBUG, workprefs.cs_bytecustomwritebug);
  8609. CheckDlgButton(hDlg, IDC_CS_COMPOSITECOLOR, workprefs.cs_color_burst);
  8610. CheckDlgButton(hDlg, IDC_CS_TOSHIBAGARY, workprefs.cs_toshibagary);
  8611. CheckDlgButton(hDlg, IDC_CS_ROMISSLOW, workprefs.cs_romisslow);
  8612. CheckDlgButton(hDlg, IDC_CS_CIA, workprefs.cs_ciatype[0]);
  8613. SendDlgItemMessage(hDlg, IDC_CS_UNMAPPED, CB_SETCURSEL, workprefs.cs_unmapped_space, 0);
  8614. txt[0] = 0;
  8615. _stprintf (txt, _T("%d"), workprefs.cs_rtc_adjust);
  8616. SetDlgItemText(hDlg, IDC_CS_RTCADJUST, txt);
  8617. txt[0] = 0;
  8618. if (workprefs.cs_fatgaryrev >= 0)
  8619. _stprintf (txt, _T("%02X"), workprefs.cs_fatgaryrev);
  8620. SetDlgItemText(hDlg, IDC_CS_FATGARYREV, txt);
  8621. txt[0] = 0;
  8622. if (workprefs.cs_ramseyrev >= 0)
  8623. _stprintf (txt, _T("%02X"), workprefs.cs_ramseyrev);
  8624. SetDlgItemText(hDlg, IDC_CS_RAMSEYREV, txt);
  8625. txt[0] = 0;
  8626. if (workprefs.cs_agnusrev >= 0) {
  8627. rev = workprefs.cs_agnusrev;
  8628. _stprintf (txt, _T("%02X"), rev);
  8629. } else if (workprefs.cs_compatible) {
  8630. rev = 0;
  8631. if (workprefs.ntscmode)
  8632. rev |= 0x10;
  8633. rev |= (workprefs.chipset_mask & CSMASK_AGA) ? 0x23 : 0;
  8634. rev |= (currprefs.chipset_mask & CSMASK_ECS_AGNUS) ? 0x20 : 0;
  8635. if (workprefs.chipmem.size > 1024 * 1024 && (workprefs.chipset_mask & CSMASK_ECS_AGNUS))
  8636. rev |= 0x21;
  8637. _stprintf (txt, _T("%02X"), rev);
  8638. }
  8639. SetDlgItemText(hDlg, IDC_CS_AGNUSREV, txt);
  8640. txt[0] = 0;
  8641. if (workprefs.cs_deniserev >= 0) {
  8642. rev = workprefs.cs_deniserev;
  8643. _stprintf (txt, _T("%01.1X"), rev);
  8644. } else if (workprefs.cs_compatible) {
  8645. rev = 0xf;
  8646. if (workprefs.chipset_mask & CSMASK_ECS_DENISE)
  8647. rev = 0xc;
  8648. if (workprefs.chipset_mask & CSMASK_AGA)
  8649. rev = 0x8;
  8650. _stprintf (txt, _T("%01.1X"), rev);
  8651. }
  8652. SetDlgItemText(hDlg, IDC_CS_DENISEREV, txt);
  8653. }
  8654. static void values_from_chipsetdlg2 (HWND hDlg, UINT msg, WPARAM wParam, LPARAM lParam)
  8655. {
  8656. TCHAR txt[32], *p;
  8657. int v;
  8658. if (!!workprefs.cs_compatible != ischecked(hDlg, IDC_CS_COMPATIBLE)) {
  8659. if (ischecked(hDlg, IDC_CS_COMPATIBLE)) {
  8660. if (!cs_compatible)
  8661. cs_compatible = CP_GENERIC;
  8662. workprefs.cs_compatible = cs_compatible;
  8663. } else {
  8664. workprefs.cs_compatible = 0;
  8665. }
  8666. built_in_chipset_prefs(&workprefs);
  8667. values_to_chipsetdlg2(hDlg);
  8668. }
  8669. workprefs.cs_resetwarning = ischecked (hDlg, IDC_CS_RESETWARNING);
  8670. workprefs.cs_ciatodbug = ischecked (hDlg, IDC_CS_CIATODBUG);
  8671. workprefs.cs_denisenoehb = ischecked (hDlg, IDC_CS_NOEHB);
  8672. workprefs.cs_dipagnus = ischecked (hDlg, IDC_CS_DIPAGNUS);
  8673. workprefs.cs_agnusbltbusybug = workprefs.cs_dipagnus;
  8674. workprefs.cs_ksmirror_e0 = ischecked (hDlg, IDC_CS_KSMIRROR_E0);
  8675. workprefs.cs_ksmirror_a8 = ischecked (hDlg, IDC_CS_KSMIRROR_A8);
  8676. workprefs.cs_ciaoverlay = ischecked (hDlg, IDC_CS_CIAOVERLAY);
  8677. workprefs.cs_df0idhw = ischecked (hDlg, IDC_CS_DF0IDHW);
  8678. workprefs.cs_cd32cd = ischecked (hDlg, IDC_CS_CD32CD);
  8679. workprefs.cs_cd32c2p = ischecked (hDlg, IDC_CS_CD32C2P);
  8680. workprefs.cs_cd32nvram = ischecked (hDlg, IDC_CS_CD32NVRAM);
  8681. workprefs.cs_cdtvcd = ischecked (hDlg, IDC_CS_CDTVCD);
  8682. workprefs.cs_cdtvcr = ischecked (hDlg, IDC_CS_CDTVCR);
  8683. workprefs.cs_cdtvram = ischecked (hDlg, IDC_CS_CDTVRAM);
  8684. workprefs.cs_a1000ram = ischecked (hDlg, IDC_CS_A1000RAM);
  8685. workprefs.cs_ramseyrev = ischecked (hDlg, IDC_CS_RAMSEY) ? 0x0f : -1;
  8686. workprefs.cs_fatgaryrev = ischecked (hDlg, IDC_CS_FATGARY) ? 0x00 : -1;
  8687. workprefs.cs_mbdmac = ischecked (hDlg, IDC_CS_DMAC) ? 1 : 0;
  8688. workprefs.cs_mbdmac |= ischecked (hDlg, IDC_CS_DMAC2) ? 2 : 0;
  8689. workprefs.cs_pcmcia = ischecked (hDlg, IDC_CS_PCMCIA) ? 1 : 0;
  8690. workprefs.cs_slowmemisfast = ischecked (hDlg, IDC_CS_SLOWISFAST) ? 1 : 0;
  8691. workprefs.cs_z3autoconfig = ischecked (hDlg, IDC_CS_Z3AUTOCONFIG) ? 1 : 0;
  8692. workprefs.cs_ide = ischecked (hDlg, IDC_CS_IDE1) ? 1 : (ischecked (hDlg, IDC_CS_IDE2) ? 2 : 0);
  8693. workprefs.cs_ciaatod = ischecked (hDlg, IDC_CS_CIAA_TOD1) ? 0
  8694. : (ischecked (hDlg, IDC_CS_CIAA_TOD2) ? 1 : 2);
  8695. workprefs.cs_rtc = ischecked (hDlg, IDC_CS_RTC1) ? 0
  8696. : ischecked (hDlg, IDC_CS_RTC2) ? 1 : ischecked (hDlg, IDC_CS_RTC3) ? 2 : 3;
  8697. workprefs.cs_1mchipjumper = ischecked(hDlg, IDC_CS_1MCHIPJUMPER);
  8698. workprefs.cs_bytecustomwritebug = ischecked(hDlg, IDC_CS_BYTECUSTOMWRITEBUG);
  8699. workprefs.cs_color_burst = ischecked(hDlg, IDC_CS_COMPOSITECOLOR);
  8700. workprefs.cs_toshibagary = ischecked(hDlg, IDC_CS_TOSHIBAGARY);
  8701. workprefs.cs_romisslow = ischecked(hDlg, IDC_CS_ROMISSLOW);
  8702. workprefs.cs_ciatype[0] = workprefs.cs_ciatype[1] = ischecked(hDlg, IDC_CS_CIA);
  8703. LRESULT val = SendDlgItemMessage(hDlg, IDC_CS_UNMAPPED, CB_GETCURSEL, 0, 0L);
  8704. if (val != CB_ERR)
  8705. workprefs.cs_unmapped_space = val;
  8706. cfgfile_compatibility_romtype(&workprefs);
  8707. if (workprefs.cs_rtc) {
  8708. txt[0] = 0;
  8709. SendDlgItemMessage (hDlg, IDC_CS_RTCADJUST, WM_GETTEXT, (WPARAM)sizeof (txt) / sizeof (TCHAR), (LPARAM)txt);
  8710. workprefs.cs_rtc_adjust = _tstol(txt);
  8711. }
  8712. if (workprefs.cs_fatgaryrev >= 0) {
  8713. txt[0] = 0;
  8714. SendDlgItemMessage (hDlg, IDC_CS_FATGARYREV, WM_GETTEXT, (WPARAM)sizeof (txt) / sizeof (TCHAR), (LPARAM)txt);
  8715. v = _tcstol (txt, &p, 16);
  8716. if (v >= 0 && v <= 255)
  8717. workprefs.cs_fatgaryrev = v;
  8718. }
  8719. if (workprefs.cs_ramseyrev >= 0) {
  8720. txt[0] = 0;
  8721. SendDlgItemMessage (hDlg, IDC_CS_RAMSEYREV, WM_GETTEXT, (WPARAM)sizeof (txt) / sizeof (TCHAR), (LPARAM)txt);
  8722. v = _tcstol (txt, &p, 16);
  8723. if (v >= 0 && v <= 255)
  8724. workprefs.cs_ramseyrev = v;
  8725. }
  8726. if (workprefs.cs_agnusrev >= 0) {
  8727. txt[0] = 0;
  8728. SendDlgItemMessage (hDlg, IDC_CS_AGNUSREV, WM_GETTEXT, (WPARAM)sizeof (txt) / sizeof (TCHAR), (LPARAM)txt);
  8729. v = _tcstol (txt, &p, 16);
  8730. if (v >= 0 && v <= 255)
  8731. workprefs.cs_agnusrev = v;
  8732. }
  8733. if (workprefs.cs_deniserev >= 0) {
  8734. txt[0] = 0;
  8735. SendDlgItemMessage (hDlg, IDC_CS_DENISEREV, WM_GETTEXT, (WPARAM)sizeof (txt) / sizeof (TCHAR), (LPARAM)txt);
  8736. v = _tcstol (txt, &p, 16);
  8737. if (v >= 0 && v <= 15)
  8738. workprefs.cs_deniserev = v;
  8739. }
  8740. }
  8741. static void enable_for_chipsetdlg2 (HWND hDlg)
  8742. {
  8743. int e = workprefs.cs_compatible ? FALSE : TRUE;
  8744. ew(hDlg, IDC_CS_FATGARY, e);
  8745. ew(hDlg, IDC_CS_RAMSEY, e);
  8746. ew(hDlg, IDC_CS_AGNUS, e);
  8747. ew(hDlg, IDC_CS_DENISE, e);
  8748. ew(hDlg, IDC_CS_FATGARYREV, e);
  8749. ew(hDlg, IDC_CS_RAMSEYREV, e);
  8750. ew(hDlg, IDC_CS_AGNUSREV, e);
  8751. ew(hDlg, IDC_CS_DENISEREV, e);
  8752. ew(hDlg, IDC_CS_IDE1, e);
  8753. ew(hDlg, IDC_CS_IDE2, e);
  8754. ew(hDlg, IDC_CS_DMAC, e);
  8755. ew(hDlg, IDC_CS_DMAC2, e);
  8756. ew(hDlg, IDC_CS_PCMCIA, e);
  8757. ew(hDlg, IDC_CS_SLOWISFAST, e);
  8758. ew(hDlg, IDC_CS_CD32CD, e);
  8759. ew(hDlg, IDC_CS_CD32NVRAM, e);
  8760. ew(hDlg, IDC_CS_CD32C2P, e);
  8761. ew(hDlg, IDC_CS_CDTVCD, e);
  8762. ew(hDlg, IDC_CS_CDTVCR, e);
  8763. ew(hDlg, IDC_CS_CDTVRAM, e);
  8764. ew(hDlg, IDC_CS_RESETWARNING, e);
  8765. ew(hDlg, IDC_CS_CIATODBUG, e);
  8766. ew(hDlg, IDC_CS_NOEHB, e);
  8767. ew(hDlg, IDC_CS_DIPAGNUS, e);
  8768. ew(hDlg, IDC_CS_Z3AUTOCONFIG, e);
  8769. ew(hDlg, IDC_CS_KSMIRROR_E0, e);
  8770. ew(hDlg, IDC_CS_KSMIRROR_A8, e);
  8771. ew(hDlg, IDC_CS_CIAOVERLAY, e);
  8772. ew(hDlg, IDC_CS_A1000RAM, e);
  8773. ew(hDlg, IDC_CS_DF0IDHW, e);
  8774. ew(hDlg, IDC_CS_CIAA_TOD1, e);
  8775. ew(hDlg, IDC_CS_CIAA_TOD2, e);
  8776. ew(hDlg, IDC_CS_CIAA_TOD3, e);
  8777. ew(hDlg, IDC_CS_RTC1, e);
  8778. ew(hDlg, IDC_CS_RTC2, e);
  8779. ew(hDlg, IDC_CS_RTC3, e);
  8780. ew(hDlg, IDC_CS_RTC4, e);
  8781. ew(hDlg, IDC_CS_RTCADJUST, e);
  8782. ew(hDlg, IDC_CS_1MCHIPJUMPER, e && workprefs.chipmem.size < 0x100000);
  8783. ew(hDlg, IDC_CS_BYTECUSTOMWRITEBUG, e);
  8784. ew(hDlg, IDC_CS_COMPOSITECOLOR, e);
  8785. ew(hDlg, IDC_CS_TOSHIBAGARY, e);
  8786. ew(hDlg, IDC_CS_ROMISSLOW, e);
  8787. ew(hDlg, IDC_CS_UNMAPPED, e);
  8788. ew(hDlg, IDC_CS_CIA, e);
  8789. }
  8790. static INT_PTR CALLBACK ChipsetDlgProc2 (HWND hDlg, UINT msg, WPARAM wParam, LPARAM lParam)
  8791. {
  8792. static int recursive = 0;
  8793. TCHAR tmp[MAX_DPATH];
  8794. if (dialog_inhibit)
  8795. return 0;
  8796. switch (msg) {
  8797. case WM_INITDIALOG:
  8798. {
  8799. pages[CHIPSET2_ID] = hDlg;
  8800. currentpage = CHIPSET2_ID;
  8801. cs_compatible = workprefs.cs_compatible;
  8802. SendDlgItemMessage(hDlg, IDC_CS_UNMAPPED, CB_RESETCONTENT, 0, 0L);
  8803. WIN32GUI_LoadUIString(IDS_UNMAPPED_ADDRESS, tmp, sizeof tmp / sizeof(TCHAR));
  8804. TCHAR *p1 = tmp;
  8805. for (;;) {
  8806. TCHAR *p2 = _tcschr(p1, '\n');
  8807. if (p2 && _tcslen(p2) > 0) {
  8808. *p2++ = 0;
  8809. SendDlgItemMessage(hDlg, IDC_CS_UNMAPPED, CB_ADDSTRING, 0, (LPARAM)p1);
  8810. p1 = p2;
  8811. } else
  8812. break;
  8813. }
  8814. }
  8815. case WM_USER:
  8816. recursive++;
  8817. values_to_chipsetdlg2 (hDlg);
  8818. enable_for_chipsetdlg2 (hDlg);
  8819. recursive--;
  8820. break;
  8821. case WM_HSCROLL:
  8822. case WM_COMMAND:
  8823. if (recursive > 0)
  8824. break;
  8825. recursive++;
  8826. values_from_chipsetdlg2 (hDlg, msg, wParam, lParam);
  8827. enable_for_chipsetdlg2 (hDlg);
  8828. recursive--;
  8829. break;
  8830. }
  8831. return FALSE;
  8832. }
  8833. static int fastram_select;
  8834. static uae_u32 *fastram_select_pointer;
  8835. static const int *fastram_select_msi;
  8836. static struct ramboard *fastram_select_ramboard;
  8837. #define MAX_STANDARD_RAM_BOARDS 2
  8838. static void enable_for_memorydlg (HWND hDlg)
  8839. {
  8840. int z3 = workprefs.address_space_24 == false;
  8841. bool ac = fastram_select_ramboard && fastram_select_ramboard->autoconfig_inuse;
  8842. bool manual = fastram_select_ramboard && fastram_select_ramboard->manual_config;
  8843. bool size = fastram_select_ramboard && fastram_select_ramboard->size != 0;
  8844. #ifndef AUTOCONFIG
  8845. z3 = FALSE;
  8846. fast = FALSE;
  8847. #endif
  8848. ew (hDlg, IDC_Z3TEXT, z3);
  8849. ew (hDlg, IDC_Z3FASTRAM, z3);
  8850. ew (hDlg, IDC_Z3FASTMEM, z3);
  8851. ew (hDlg, IDC_Z3CHIPRAM, z3);
  8852. ew (hDlg, IDC_Z3CHIPMEM, z3);
  8853. ew (hDlg, IDC_FASTMEM, true);
  8854. ew (hDlg, IDC_FASTRAM, true);
  8855. ew (hDlg, IDC_Z3MAPPING, z3);
  8856. ew (hDlg, IDC_FASTTEXT, true);
  8857. bool isfast = fastram_select >= MAX_STANDARD_RAM_BOARDS && fastram_select < MAX_STANDARD_RAM_BOARDS + 2 * MAX_RAM_BOARDS && fastram_select_ramboard && fastram_select_ramboard->size;
  8858. ew(hDlg, IDC_AUTOCONFIG_MANUFACTURER, isfast && !manual);
  8859. ew(hDlg, IDC_AUTOCONFIG_PRODUCT, isfast && !manual);
  8860. ew(hDlg, IDC_MEMORYBOARDSELECT, isfast);
  8861. ew(hDlg, IDC_AUTOCONFIG_DATA, ac && size);
  8862. ew(hDlg, IDC_FASTMEMAUTOCONFIGUSE, isfast);
  8863. ew(hDlg, IDC_FASTMEMNOAUTOCONFIG, isfast);
  8864. ew(hDlg, IDC_FASTMEMDMA, true);
  8865. ew(hDlg, IDC_FASTMEMFORCE16, true);
  8866. ew(hDlg, IDC_MEMORYRAM, true);
  8867. ew(hDlg, IDC_MEMORYMEM, true);
  8868. ew(hDlg, IDC_RAM_ADDRESS, manual && size);
  8869. ew(hDlg, IDC_RAM_ADDRESS2, manual && size);
  8870. }
  8871. static void setfastram_ramboard(HWND hDlg, int zram)
  8872. {
  8873. if (!fastram_select_ramboard)
  8874. return;
  8875. int idx = 1;
  8876. for (int i = 0; memoryboards[i].name; i++) {
  8877. const struct memoryboardtype *mbt = &memoryboards[i];
  8878. if (mbt->z == zram) {
  8879. if ((mbt->manufacturer == fastram_select_ramboard->manufacturer && mbt->product == fastram_select_ramboard->product) || (mbt->address && mbt->address == fastram_select_ramboard->start_address)) {
  8880. SendDlgItemMessage(hDlg, IDC_MEMORYBOARDSELECT, CB_SETCURSEL, idx, 0);
  8881. break;
  8882. }
  8883. idx++;
  8884. }
  8885. }
  8886. }
  8887. static int getmemsize(uae_u32 size, const int *msi)
  8888. {
  8889. int mem_size = 0;
  8890. if (msi == msi_fast) {
  8891. switch (size)
  8892. {
  8893. case 0x00000000: mem_size = 0; break;
  8894. case 0x00010000: mem_size = 1; break;
  8895. case 0x00020000: mem_size = 2; break;
  8896. case 0x00040000: mem_size = 3; break;
  8897. case 0x00080000: mem_size = 4; break;
  8898. case 0x00100000: mem_size = 5; break;
  8899. case 0x00200000: mem_size = 6; break;
  8900. case 0x00400000: mem_size = 7; break;
  8901. case 0x00800000: mem_size = 8; break;
  8902. case 0x01000000: mem_size = 9; break;
  8903. }
  8904. } else if (msi == msi_chip) {
  8905. switch (size)
  8906. {
  8907. case 0x00040000: mem_size = 0; break;
  8908. case 0x00080000: mem_size = 1; break;
  8909. case 0x00100000: mem_size = 2; break;
  8910. case 0x00180000: mem_size = 3; break;
  8911. case 0x00200000: mem_size = 4; break;
  8912. case 0x00400000: mem_size = 5; break;
  8913. case 0x00800000: mem_size = 6; break;
  8914. }
  8915. } else if (msi == msi_bogo) {
  8916. switch (size)
  8917. {
  8918. case 0x00000000: mem_size = 0; break;
  8919. case 0x00080000: mem_size = 1; break;
  8920. case 0x00100000: mem_size = 2; break;
  8921. case 0x00180000: mem_size = 3; break;
  8922. case 0x001C0000: mem_size = 4; break;
  8923. }
  8924. } else if (msi == msi_z3chip) {
  8925. switch (size)
  8926. {
  8927. case 0x00000000: mem_size = 0; break;
  8928. case 0x01000000: mem_size = 1; break;
  8929. case 0x02000000: mem_size = 2; break;
  8930. case 0x04000000: mem_size = 3; break;
  8931. case 0x08000000: mem_size = 4; break;
  8932. case 0x10000000: mem_size = 5; break;
  8933. case 0x18000000: mem_size = 6; break;
  8934. case 0x20000000: mem_size = 7; break;
  8935. case 0x30000000: mem_size = 8; break;
  8936. case 0x40000000: mem_size = 9; break;
  8937. }
  8938. } else {
  8939. if (size < 0x00100000)
  8940. mem_size = 0;
  8941. else if (size < 0x00200000)
  8942. mem_size = 1;
  8943. else if (size < 0x00400000)
  8944. mem_size = 2;
  8945. else if (size < 0x00800000)
  8946. mem_size = 3;
  8947. else if (size < 0x01000000)
  8948. mem_size = 4;
  8949. else if (size < 0x02000000)
  8950. mem_size = 5;
  8951. else if (size < 0x04000000)
  8952. mem_size = 6;
  8953. else if (size < 0x08000000)
  8954. mem_size = 7;
  8955. else if (size < 0x10000000)
  8956. mem_size = 8;
  8957. else if (size < 0x20000000)
  8958. mem_size = 9;
  8959. else if (size < 0x40000000)
  8960. mem_size = 10;
  8961. else // 1GB
  8962. mem_size = 11;
  8963. }
  8964. return mem_size;
  8965. }
  8966. static void addadvancedram(HWND hDlg, struct ramboard *rb, const TCHAR *name, const int *msi)
  8967. {
  8968. TCHAR tmp[200];
  8969. _tcscpy(tmp, name);
  8970. if (rb->size) {
  8971. int mem_size = getmemsize(rb->size, msi);
  8972. _tcscat(tmp, _T(" ("));
  8973. _tcscat(tmp, memsize_names[msi[mem_size]]);
  8974. _tcscat(tmp, _T(")"));
  8975. }
  8976. SendDlgItemMessage(hDlg, IDC_MEMORYSELECT, CB_ADDSTRING, 0, (LPARAM)tmp);
  8977. }
  8978. static void setfastram_selectmenu(HWND hDlg, int mode)
  8979. {
  8980. int min;
  8981. int max;
  8982. const int *msi;
  8983. TCHAR tmp[200];
  8984. int zram = 0;
  8985. struct ramboard *fastram_select_ramboard_old = fastram_select_ramboard;
  8986. fastram_select_ramboard = NULL;
  8987. if (fastram_select == 0) {
  8988. min = 0;
  8989. max = MAX_CHIP_MEM;
  8990. msi = msi_chip;
  8991. fastram_select_pointer = &workprefs.chipmem.size;
  8992. fastram_select_ramboard = &workprefs.chipmem;
  8993. } else if (fastram_select == 1) {
  8994. min = 0;
  8995. max = MAX_SLOW_MEM;
  8996. msi = msi_bogo;
  8997. fastram_select_pointer = &workprefs.bogomem.size;
  8998. fastram_select_ramboard = &workprefs.bogomem;
  8999. } else if (fastram_select < MAX_STANDARD_RAM_BOARDS + MAX_RAM_BOARDS) {
  9000. msi = msi_fast;
  9001. min = MIN_FAST_MEM;
  9002. max = MAX_FAST_MEM;
  9003. fastram_select_ramboard = &workprefs.fastmem[fastram_select - MAX_STANDARD_RAM_BOARDS];
  9004. fastram_select_pointer = &fastram_select_ramboard->size;
  9005. zram = 2;
  9006. } else if (fastram_select >= MAX_STANDARD_RAM_BOARDS + MAX_RAM_BOARDS && fastram_select < MAX_STANDARD_RAM_BOARDS + MAX_RAM_BOARDS * 2) {
  9007. msi = msi_z3fast;
  9008. min = MIN_Z3_MEM;
  9009. max = MAX_Z3_MEM;
  9010. fastram_select_ramboard = &workprefs.z3fastmem[fastram_select - (MAX_RAM_BOARDS + MAX_STANDARD_RAM_BOARDS)];
  9011. fastram_select_pointer = &fastram_select_ramboard->size;
  9012. zram = 3;
  9013. } else if (fastram_select == MAX_STANDARD_RAM_BOARDS + 2 * MAX_RAM_BOARDS) {
  9014. min = 0;
  9015. max = MAX_CB_MEM_128M;
  9016. msi = msi_cpuboard;
  9017. fastram_select_pointer = &workprefs.mbresmem_high.size;
  9018. fastram_select_ramboard = &workprefs.mbresmem_high;
  9019. } else if (fastram_select == MAX_STANDARD_RAM_BOARDS + 2 * MAX_RAM_BOARDS + 1) {
  9020. min = 0;
  9021. max = MAX_CB_MEM_64M;
  9022. msi = msi_cpuboard;
  9023. fastram_select_pointer = &workprefs.mbresmem_low.size;
  9024. fastram_select_ramboard = &workprefs.mbresmem_low;
  9025. } else if (fastram_select == MAX_STANDARD_RAM_BOARDS + 2 * MAX_RAM_BOARDS + 2) {
  9026. min = 0;
  9027. max = MAX_Z3_CHIPMEM;
  9028. msi = msi_z3chip;
  9029. fastram_select_pointer = &workprefs.z3chipmem.size;
  9030. fastram_select_ramboard = &workprefs.z3chipmem;
  9031. } else {
  9032. return;
  9033. }
  9034. fastram_select_msi = msi;
  9035. uae_u32 v = *fastram_select_pointer;
  9036. int mem_size = getmemsize(v, msi);
  9037. SendDlgItemMessage(hDlg, IDC_MEMORYMEM, TBM_SETRANGE, TRUE, MAKELONG(min, max));
  9038. SendDlgItemMessage(hDlg, IDC_MEMORYMEM, TBM_SETPOS, TRUE, mem_size);
  9039. SetDlgItemText(hDlg, IDC_MEMORYRAM, memsize_names[msi[mem_size]]);
  9040. expansion_generate_autoconfig_info(&workprefs);
  9041. struct ramboard *rb = fastram_select_ramboard;
  9042. setchecked(hDlg, IDC_FASTMEMAUTOCONFIGUSE, rb && rb->autoconfig_inuse);
  9043. setchecked(hDlg, IDC_FASTMEMNOAUTOCONFIG, rb && rb->manual_config);
  9044. setchecked(hDlg, IDC_FASTMEMDMA, rb && rb->nodma == 0);
  9045. setchecked(hDlg, IDC_FASTMEMFORCE16, rb && rb->force16bit != 0);
  9046. if (rb) {
  9047. if (rb->manual_config) {
  9048. if (rb->end_address <= rb->start_address || rb->start_address + rb->size < rb->end_address)
  9049. rb->end_address = rb->start_address + rb->size - 1;
  9050. } else {
  9051. rb->start_address = 0;
  9052. rb->end_address = 0;
  9053. }
  9054. if (fastram_select_ramboard_old != fastram_select_ramboard || mode < 0) {
  9055. if (zram) {
  9056. ew(hDlg, IDC_MEMORYBOARDSELECT, TRUE);
  9057. SendDlgItemMessage(hDlg, IDC_MEMORYBOARDSELECT, CB_RESETCONTENT, 0, 0);
  9058. SendDlgItemMessage(hDlg, IDC_MEMORYBOARDSELECT, CB_ADDSTRING, 0, (LPARAM)_T("-"));
  9059. for (int i = 0; memoryboards[i].name; i++) {
  9060. const struct memoryboardtype *mbt = &memoryboards[i];
  9061. if (mbt->z == zram) {
  9062. _stprintf(tmp, _T("%s %s"), memoryboards[i].man, memoryboards[i].name);
  9063. SendDlgItemMessage(hDlg, IDC_MEMORYBOARDSELECT, CB_ADDSTRING, 0, (LPARAM)tmp);
  9064. }
  9065. }
  9066. } else {
  9067. SendDlgItemMessage(hDlg, IDC_MEMORYBOARDSELECT, CB_RESETCONTENT, 0, 0);
  9068. ew(hDlg, IDC_MEMORYBOARDSELECT, FALSE);
  9069. }
  9070. }
  9071. struct autoconfig_info* aci = NULL;
  9072. if (fastram_select >= MAX_STANDARD_RAM_BOARDS && fastram_select < MAX_STANDARD_RAM_BOARDS + 2 * MAX_RAM_BOARDS) {
  9073. aci = expansion_get_autoconfig_info(&workprefs, fastram_select < MAX_STANDARD_RAM_BOARDS + MAX_RAM_BOARDS ? ROMTYPE_RAMZ2 : ROMTYPE_RAMZ3, fastram_select % MAX_RAM_BOARDS);
  9074. if (!rb->autoconfig_inuse) {
  9075. if (aci) {
  9076. memcpy(rb->autoconfig, aci->autoconfig_bytes, sizeof rb->autoconfig);
  9077. }
  9078. if (rb->manufacturer) {
  9079. rb->autoconfig[1] = rb->product;
  9080. rb->autoconfig[4] = (rb->manufacturer >> 8) & 0xff;
  9081. rb->autoconfig[5] = rb->manufacturer & 0xff;
  9082. } else {
  9083. memset(rb->autoconfig, 0, sizeof rb->autoconfig);
  9084. aci = expansion_get_autoconfig_info(&workprefs, fastram_select < MAX_RAM_BOARDS ? ROMTYPE_RAMZ2 : ROMTYPE_RAMZ3, fastram_select% MAX_RAM_BOARDS);
  9085. if (aci) {
  9086. memcpy(rb->autoconfig, aci->autoconfig_bytes, sizeof rb->autoconfig);
  9087. }
  9088. }
  9089. }
  9090. }
  9091. if (mode != 3) {
  9092. if (aci && !rb->manual_config) {
  9093. _stprintf(tmp, _T("%08x"), aci->start);
  9094. SetDlgItemText(hDlg, IDC_RAM_ADDRESS, tmp);
  9095. _stprintf(tmp, _T("%08x"), aci->start + aci->size - 1);
  9096. SetDlgItemText(hDlg, IDC_RAM_ADDRESS2, tmp);
  9097. } else if (rb->manual_config) {
  9098. _stprintf(tmp, _T("%08x"), rb->start_address);
  9099. SetDlgItemText(hDlg, IDC_RAM_ADDRESS, tmp);
  9100. _stprintf(tmp, _T("%08x"), rb->end_address);
  9101. SetDlgItemText(hDlg, IDC_RAM_ADDRESS2, tmp);
  9102. } else {
  9103. SetDlgItemText(hDlg, IDC_RAM_ADDRESS, _T(""));
  9104. SetDlgItemText(hDlg, IDC_RAM_ADDRESS2, _T(""));
  9105. }
  9106. }
  9107. if (mode == 1 && rb->autoconfig_inuse) {
  9108. rb->autoconfig[1] = rb->product;
  9109. rb->autoconfig[4] = (rb->manufacturer >> 8) & 0xff;
  9110. rb->autoconfig[5] = rb->manufacturer & 0xff;
  9111. }
  9112. if (mode != 2) {
  9113. tmp[0] = 0;
  9114. TCHAR *p = tmp;
  9115. for (int i = 0; i < 12; i++) {
  9116. if (i > 0)
  9117. _tcscat(p, _T("."));
  9118. _stprintf(p + _tcslen(p), _T("%02x"), rb->autoconfig[i]);
  9119. }
  9120. SetDlgItemText(hDlg, IDC_AUTOCONFIG_DATA, tmp);
  9121. }
  9122. if (rb->autoconfig_inuse) {
  9123. rb->product = rb->autoconfig[1];
  9124. rb->manufacturer = (rb->autoconfig[4] << 8) | rb->autoconfig[5];
  9125. }
  9126. if (mode != 1) {
  9127. if (rb->manufacturer) {
  9128. _stprintf(tmp, _T("%d"), rb->manufacturer);
  9129. SetDlgItemText(hDlg, IDC_AUTOCONFIG_MANUFACTURER, tmp);
  9130. _stprintf(tmp, _T("%d"), rb->product);
  9131. SetDlgItemText(hDlg, IDC_AUTOCONFIG_PRODUCT, tmp);
  9132. } else {
  9133. rb->product = 0;
  9134. SetDlgItemText(hDlg, IDC_AUTOCONFIG_MANUFACTURER, _T(""));
  9135. SetDlgItemText(hDlg, IDC_AUTOCONFIG_PRODUCT, _T(""));
  9136. }
  9137. }
  9138. setfastram_ramboard(hDlg, zram);
  9139. } else {
  9140. SetDlgItemText(hDlg, IDC_AUTOCONFIG_MANUFACTURER, _T(""));
  9141. SetDlgItemText(hDlg, IDC_AUTOCONFIG_PRODUCT, _T(""));
  9142. }
  9143. SendDlgItemMessage(hDlg, IDC_MEMORYSELECT, CB_RESETCONTENT, 0, 0);
  9144. addadvancedram(hDlg, &workprefs.chipmem, _T("Chip RAM"), msi_chip);
  9145. addadvancedram(hDlg, &workprefs.bogomem, _T("Slow RAM"), msi_bogo);
  9146. for (int i = 0; i < MAX_RAM_BOARDS; i++) {
  9147. struct autoconfig_info *aci = expansion_get_autoconfig_info(&workprefs, ROMTYPE_RAMZ2, i);
  9148. _stprintf(tmp, _T("Z2 Fast Ram #%d"), i + 1);
  9149. if (workprefs.fastmem[i].size)
  9150. _stprintf(tmp + _tcslen(tmp), _T(" [%dk]"), workprefs.fastmem[i].size / 1024);
  9151. if (aci && aci->cst) {
  9152. _stprintf(tmp + _tcslen(tmp), _T(" (%s)"), aci->cst->name);
  9153. } else if (aci && aci->ert) {
  9154. _stprintf(tmp + _tcslen(tmp), _T(" (%s)"), aci->ert->friendlyname);
  9155. }
  9156. SendDlgItemMessage(hDlg, IDC_MEMORYSELECT, CB_ADDSTRING, 0, (LPARAM)tmp);
  9157. }
  9158. if (!workprefs.address_space_24) {
  9159. for (int i = 0; i < MAX_RAM_BOARDS; i++) {
  9160. struct autoconfig_info *aci = expansion_get_autoconfig_info(&workprefs, ROMTYPE_RAMZ3, i);
  9161. _stprintf(tmp, _T("Z3 Fast Ram #%d"), i + 1);
  9162. if (workprefs.z3fastmem[i].size)
  9163. _stprintf(tmp + _tcslen(tmp), _T(" [%dM]"), workprefs.z3fastmem[i].size / (1024 * 1024));
  9164. if (aci && aci->cst) {
  9165. _stprintf(tmp + _tcslen(tmp), _T(" (%s)"), aci->cst->name);
  9166. } else if (aci && aci->ert) {
  9167. _stprintf(tmp + _tcslen(tmp), _T(" (%s)"), aci->ert->friendlyname);
  9168. }
  9169. SendDlgItemMessage(hDlg, IDC_MEMORYSELECT, CB_ADDSTRING, 0, (LPARAM)tmp);
  9170. }
  9171. addadvancedram(hDlg, &workprefs.mbresmem_high, _T("Processor Slot Fast RAM"), msi_mb);
  9172. addadvancedram(hDlg, &workprefs.mbresmem_low, _T("Motherboard Fast RAM"), msi_mb);
  9173. addadvancedram(hDlg, &workprefs.z3chipmem, _T("32-bit Chip RAM"), msi_z3chip);
  9174. } else {
  9175. if (fastram_select >= MAX_STANDARD_RAM_BOARDS + MAX_RAM_BOARDS)
  9176. fastram_select = 0;
  9177. }
  9178. SendDlgItemMessage(hDlg, IDC_MEMORYSELECT, CB_SETCURSEL, fastram_select, 0);
  9179. enable_for_memorydlg(hDlg);
  9180. }
  9181. extern uae_u32 natmem_reserved_size;
  9182. static void setmax32bitram (HWND hDlg)
  9183. {
  9184. TCHAR tmp[256];
  9185. uae_u32 size32 = 0, z3size_uae = 0, z3size_real = 0;
  9186. z3size_uae = natmem_reserved_size >= expamem_z3_pointer_uae ? natmem_reserved_size - expamem_z3_pointer_uae : 0;
  9187. z3size_real = natmem_reserved_size >= expamem_z3_pointer_real ? natmem_reserved_size - expamem_z3_pointer_real : 0;
  9188. uae_u32 first = 0;
  9189. int idx = 0;
  9190. for (;;) {
  9191. struct autoconfig_info *aci = expansion_get_autoconfig_data(&workprefs, idx);
  9192. if (!aci)
  9193. break;
  9194. if (aci->start >= 0x10000000 && !first)
  9195. first = aci->start;
  9196. if (aci->start >= 0x10000000 && aci->start + aci->size > size32)
  9197. size32 = aci->start + aci->size;
  9198. idx++;
  9199. }
  9200. if (size32 >= first)
  9201. size32 -= first;
  9202. _stprintf (tmp, L"Configured 32-bit address space: %dM, reserved: %dM, Z3 available: %dM (UAE), %dM (Real)",
  9203. size32 / (1024 * 1024), (natmem_reserved_size - 256 * 1024 * 1024) / (1024 * 1024), z3size_uae / (1024 * 1024), z3size_real / (1024 * 1024));
  9204. SetDlgItemText (hDlg, IDC_MAX32RAM, tmp);
  9205. }
  9206. static void setcpuboardmemsize(HWND hDlg)
  9207. {
  9208. if (workprefs.cpuboardmem1.size > cpuboard_maxmemory(&workprefs))
  9209. workprefs.cpuboardmem1.size = cpuboard_maxmemory(&workprefs);
  9210. if (cpuboard_memorytype(&workprefs) == BOARD_MEMORY_Z2) {
  9211. workprefs.fastmem[0].size = workprefs.cpuboardmem1.size;
  9212. }
  9213. if (cpuboard_memorytype(&workprefs) == BOARD_MEMORY_25BITMEM) {
  9214. workprefs.mem25bit.size = workprefs.cpuboardmem1.size;
  9215. }
  9216. if (workprefs.cpuboard_type == 0) {
  9217. workprefs.mem25bit.size = 0;
  9218. }
  9219. if (cpuboard_memorytype(&workprefs) == BOARD_MEMORY_HIGHMEM)
  9220. workprefs.mbresmem_high.size = workprefs.cpuboardmem1.size;
  9221. int maxmem = cpuboard_maxmemory(&workprefs);
  9222. if (workprefs.cpuboardmem1.size > maxmem) {
  9223. workprefs.cpuboardmem1.size = maxmem;
  9224. }
  9225. if (maxmem <= 8 * 1024 * 1024)
  9226. SendDlgItemMessage (hDlg, IDC_CPUBOARDMEM, TBM_SETRANGE, TRUE, MAKELONG (MIN_CB_MEM, MAX_CB_MEM_Z2));
  9227. else if (maxmem <= 16 * 1024 * 1024)
  9228. SendDlgItemMessage(hDlg, IDC_CPUBOARDMEM, TBM_SETRANGE, TRUE, MAKELONG(MIN_CB_MEM, MAX_CB_MEM_16M));
  9229. else if (maxmem <= 32 * 1024 * 1024)
  9230. SendDlgItemMessage(hDlg, IDC_CPUBOARDMEM, TBM_SETRANGE, TRUE, MAKELONG(MIN_CB_MEM, MAX_CB_MEM_32M));
  9231. else if (maxmem <= 64 * 1024 * 1024)
  9232. SendDlgItemMessage(hDlg, IDC_CPUBOARDMEM, TBM_SETRANGE, TRUE, MAKELONG(MIN_CB_MEM, MAX_CB_MEM_64M));
  9233. else if (maxmem <= 128 * 1024 * 1024)
  9234. SendDlgItemMessage (hDlg, IDC_CPUBOARDMEM, TBM_SETRANGE, TRUE, MAKELONG (MIN_CB_MEM, MAX_CB_MEM_128M));
  9235. else
  9236. SendDlgItemMessage (hDlg, IDC_CPUBOARDMEM, TBM_SETRANGE, TRUE, MAKELONG (MIN_CB_MEM, MAX_CB_MEM_256M));
  9237. int mem_size = 0;
  9238. switch (workprefs.cpuboardmem1.size) {
  9239. case 0x00000000: mem_size = 0; break;
  9240. case 0x00100000: mem_size = 1; break;
  9241. case 0x00200000: mem_size = 2; break;
  9242. case 0x00400000: mem_size = 3; break;
  9243. case 0x00800000: mem_size = 4; break;
  9244. case 0x01000000: mem_size = 5; break;
  9245. case 0x02000000: mem_size = 6; break;
  9246. case 0x04000000: mem_size = 7; break;
  9247. case 0x08000000: mem_size = 8; break;
  9248. case 0x10000000: mem_size = 9; break;
  9249. }
  9250. SendDlgItemMessage (hDlg, IDC_CPUBOARDMEM, TBM_SETPOS, TRUE, mem_size);
  9251. SetDlgItemText (hDlg, IDC_CPUBOARDRAM, memsize_names[msi_cpuboard[mem_size]]);
  9252. SendDlgItemMessage (hDlg, IDC_CPUBOARD_TYPE, CB_SETCURSEL, workprefs.cpuboard_type, 0);
  9253. SendDlgItemMessage (hDlg, IDC_CPUBOARD_SUBTYPE, CB_SETCURSEL, workprefs.cpuboard_subtype, 0);
  9254. // for (int i = 0; cpuboard_settings_id[i] >= 0; i++) {
  9255. // setchecked(hDlg, cpuboard_settings_id[i], (workprefs.cpuboard_settings & (1 << i)) != 0);
  9256. // }
  9257. }
  9258. static int manybits (int v, int mask)
  9259. {
  9260. int i, cnt;
  9261. cnt = 0;
  9262. for (i = 0; i < 32; i++) {
  9263. if (((1 << i) & mask) & v)
  9264. cnt++;
  9265. }
  9266. if (cnt > 1)
  9267. return 1;
  9268. return 0;
  9269. }
  9270. static void values_to_memorydlg (HWND hDlg)
  9271. {
  9272. uae_u32 mem_size = 0;
  9273. uae_u32 v;
  9274. switch (workprefs.chipmem.size) {
  9275. case 0x00040000: mem_size = 0; break;
  9276. case 0x00080000: mem_size = 1; break;
  9277. case 0x00100000: mem_size = 2; break;
  9278. case 0x00180000: mem_size = 3; break;
  9279. case 0x00200000: mem_size = 4; break;
  9280. case 0x00400000: mem_size = 5; break;
  9281. case 0x00800000: mem_size = 6; break;
  9282. }
  9283. SendDlgItemMessage (hDlg, IDC_CHIPMEM, TBM_SETPOS, TRUE, mem_size);
  9284. SetDlgItemText (hDlg, IDC_CHIPRAM, memsize_names[msi_chip[mem_size]]);
  9285. mem_size = 0;
  9286. switch (workprefs.fastmem[0].size) {
  9287. case 0x00000000: mem_size = 0; break;
  9288. case 0x00010000: mem_size = 1; break;
  9289. case 0x00020000: mem_size = 2; break;
  9290. case 0x00040000: mem_size = 3; break;
  9291. case 0x00080000: mem_size = 4; break;
  9292. case 0x00100000: mem_size = 5; break;
  9293. case 0x00200000: mem_size = 6; break;
  9294. case 0x00400000: mem_size = 7; break;
  9295. case 0x00800000: mem_size = 8; break;
  9296. case 0x01000000: mem_size = 9; break;
  9297. }
  9298. SendDlgItemMessage (hDlg, IDC_FASTMEM, TBM_SETPOS, TRUE, mem_size);
  9299. SetDlgItemText (hDlg, IDC_FASTRAM, memsize_names[msi_fast[mem_size]]);
  9300. mem_size = 0;
  9301. switch (workprefs.bogomem.size) {
  9302. case 0x00000000: mem_size = 0; break;
  9303. case 0x00080000: mem_size = 1; break;
  9304. case 0x00100000: mem_size = 2; break;
  9305. case 0x00180000: mem_size = 3; break;
  9306. case 0x001C0000: mem_size = 4; break;
  9307. }
  9308. SendDlgItemMessage (hDlg, IDC_SLOWMEM, TBM_SETPOS, TRUE, mem_size);
  9309. SetDlgItemText (hDlg, IDC_SLOWRAM, memsize_names[msi_bogo[mem_size]]);
  9310. mem_size = 0;
  9311. v = workprefs.z3fastmem[0].size;
  9312. if (v < 0x00100000)
  9313. mem_size = 0;
  9314. else if (v < 0x00200000)
  9315. mem_size = 1;
  9316. else if (v < 0x00400000)
  9317. mem_size = 2;
  9318. else if (v < 0x00800000)
  9319. mem_size = 3;
  9320. else if (v < 0x01000000)
  9321. mem_size = 4;
  9322. else if (v < 0x02000000)
  9323. mem_size = 5;
  9324. else if (v < 0x04000000)
  9325. mem_size = 6;
  9326. else if (v < 0x08000000)
  9327. mem_size = 7;
  9328. else if (v < 0x10000000)
  9329. mem_size = 8;
  9330. else if (v < 0x20000000)
  9331. mem_size = 9;
  9332. else if (v < 0x40000000)
  9333. mem_size = 10;
  9334. else // 1GB
  9335. mem_size = 11;
  9336. SendDlgItemMessage (hDlg, IDC_Z3FASTMEM, TBM_SETPOS, TRUE, mem_size);
  9337. SetDlgItemText (hDlg, IDC_Z3FASTRAM, memsize_names[msi_z3fast[mem_size]]);
  9338. mem_size = 0;
  9339. v = workprefs.z3chipmem.size;
  9340. if (v < 0x01000000)
  9341. mem_size = 0;
  9342. else if (v < 0x02000000)
  9343. mem_size = 1;
  9344. else if (v < 0x04000000)
  9345. mem_size = 2;
  9346. else if (v < 0x08000000)
  9347. mem_size = 3;
  9348. else if (v < 0x10000000)
  9349. mem_size = 4;
  9350. else if (v < 0x18000000)
  9351. mem_size = 5;
  9352. else if (v < 0x20000000)
  9353. mem_size = 6;
  9354. else if (v < 0x30000000)
  9355. mem_size = 7;
  9356. else if (v < 0x40000000)
  9357. mem_size = 8;
  9358. else
  9359. mem_size = 9;
  9360. SendDlgItemMessage (hDlg, IDC_Z3CHIPMEM, TBM_SETPOS, TRUE, mem_size);
  9361. SetDlgItemText (hDlg, IDC_Z3CHIPRAM, memsize_names[msi_z3chip[mem_size]]);
  9362. #if 0
  9363. mem_size = 0;
  9364. switch (workprefs.mbresmem_low_size) {
  9365. case 0x00000000: mem_size = 0; break;
  9366. case 0x00100000: mem_size = 1; break;
  9367. case 0x00200000: mem_size = 2; break;
  9368. case 0x00400000: mem_size = 3; break;
  9369. case 0x00800000: mem_size = 4; break;
  9370. case 0x01000000: mem_size = 5; break;
  9371. case 0x02000000: mem_size = 6; break;
  9372. case 0x04000000: mem_size = 7; break;
  9373. }
  9374. SendDlgItemMessage (hDlg, IDC_MBMEM1, TBM_SETPOS, TRUE, mem_size);
  9375. SetDlgItemText (hDlg, IDC_MBRAM1, memsize_names[msi_gfx[mem_size]]);
  9376. mem_size = 0;
  9377. switch (workprefs.mbresmem_high_size) {
  9378. case 0x00000000: mem_size = 0; break;
  9379. case 0x00100000: mem_size = 1; break;
  9380. case 0x00200000: mem_size = 2; break;
  9381. case 0x00400000: mem_size = 3; break;
  9382. case 0x00800000: mem_size = 4; break;
  9383. case 0x01000000: mem_size = 5; break;
  9384. case 0x02000000: mem_size = 6; break;
  9385. case 0x04000000: mem_size = 7; break;
  9386. case 0x08000000: mem_size = 8; break;
  9387. }
  9388. SendDlgItemMessage (hDlg, IDC_MBMEM2, TBM_SETPOS, TRUE, mem_size);
  9389. SetDlgItemText (hDlg, IDC_MBRAM2, memsize_names[msi_gfx[mem_size]]);
  9390. #endif
  9391. setmax32bitram (hDlg);
  9392. }
  9393. static void fix_values_memorydlg (void)
  9394. {
  9395. if (workprefs.chipmem.size <= 0x200000)
  9396. return;
  9397. int total = 0;
  9398. for (int i = 0; i < MAX_RAM_BOARDS; i++) {
  9399. if (workprefs.fastmem[i].size > 262144)
  9400. workprefs.fastmem[i].size = 262144;
  9401. total += workprefs.fastmem[i].size;
  9402. if (total > 262144) {
  9403. workprefs.fastmem[i].size = 0;
  9404. }
  9405. }
  9406. }
  9407. static void addromfiles(UAEREG *fkey, HWND hDlg, DWORD d, const TCHAR *path, int type1, int type2)
  9408. {
  9409. int idx;
  9410. TCHAR tmp[MAX_DPATH];
  9411. TCHAR tmp2[MAX_DPATH];
  9412. TCHAR seltmp[MAX_DPATH];
  9413. struct romdata *rdx = NULL;
  9414. SendDlgItemMessage(hDlg, d, CB_RESETCONTENT, 0, 0);
  9415. SendDlgItemMessage(hDlg, d, CB_ADDSTRING, 0, (LPARAM) _T(""));
  9416. if (path)
  9417. rdx = scan_single_rom(path);
  9418. idx = 0;
  9419. seltmp[0] = 0;
  9420. for (; fkey;) {
  9421. int size = sizeof(tmp) / sizeof(TCHAR);
  9422. int size2 = sizeof(tmp2) / sizeof(TCHAR);
  9423. if (!regenumstr(fkey, idx, tmp, &size, tmp2, &size2))
  9424. break;
  9425. if (_tcslen(tmp) == 7 || _tcslen(tmp) == 13) {
  9426. int group = 0;
  9427. int subitem = 0;
  9428. int idx2 = _tstol(tmp + 4);
  9429. if (_tcslen(tmp) == 13) {
  9430. group = _tstol(tmp + 8);
  9431. subitem = _tstol(tmp + 11);
  9432. }
  9433. if (idx2 >= 0) {
  9434. struct romdata *rd = getromdatabyidgroup(idx2, group, subitem);
  9435. for (int i = 0; i < 2; i++) {
  9436. int type = i ? type2 : type1;
  9437. if (type) {
  9438. if (rd && ((((rd->type & ROMTYPE_GROUP_MASK) & (type & ROMTYPE_GROUP_MASK)) && ((rd->type & ROMTYPE_SUB_MASK) == (type & ROMTYPE_SUB_MASK) || !(type & ROMTYPE_SUB_MASK))) ||
  9439. (rd->type & type) == ROMTYPE_NONE || (rd->type & type) == ROMTYPE_NOT)) {
  9440. getromname(rd, tmp);
  9441. if (SendDlgItemMessage(hDlg, d, CB_FINDSTRING, (WPARAM) -1, (LPARAM) tmp) < 0)
  9442. SendDlgItemMessage(hDlg, d, CB_ADDSTRING, 0, (LPARAM) tmp);
  9443. if (rd == rdx)
  9444. _tcscpy(seltmp, tmp);
  9445. break;
  9446. }
  9447. }
  9448. }
  9449. }
  9450. }
  9451. idx++;
  9452. }
  9453. if (seltmp[0])
  9454. SendDlgItemMessage(hDlg, d, CB_SELECTSTRING, (WPARAM) -1, (LPARAM) seltmp);
  9455. else
  9456. SetDlgItemText(hDlg, d, path);
  9457. }
  9458. static void getromfile(HWND hDlg, DWORD d, TCHAR *path, int size)
  9459. {
  9460. LRESULT val = SendDlgItemMessage(hDlg, d, CB_GETCURSEL, 0, 0L);
  9461. if (val == CB_ERR) {
  9462. SendDlgItemMessage(hDlg, d, WM_GETTEXT, (WPARAM) size, (LPARAM) path);
  9463. }
  9464. else {
  9465. TCHAR tmp1[MAX_DPATH];
  9466. struct romdata *rd;
  9467. SendDlgItemMessage(hDlg, d, CB_GETLBTEXT, (WPARAM) val, (LPARAM) tmp1);
  9468. path[0] = 0;
  9469. rd = getromdatabyname(tmp1);
  9470. if (rd) {
  9471. struct romlist *rl = getromlistbyromdata(rd);
  9472. if (rd->configname)
  9473. _stprintf(path, _T(":%s"), rd->configname);
  9474. else if (rl)
  9475. _tcsncpy(path, rl->path, size);
  9476. }
  9477. }
  9478. }
  9479. struct expansionrom_gui
  9480. {
  9481. const struct expansionboardsettings *expansionrom_gui_ebs;
  9482. int expansionrom_gui_item;
  9483. DWORD expansionrom_gui_itemselector;
  9484. DWORD expansionrom_gui_selector;
  9485. DWORD expansionrom_gui_checkbox;
  9486. DWORD expansionrom_gui_stringbox;
  9487. int expansionrom_gui_settingsbits;
  9488. int expansionrom_gui_settingsshift;
  9489. int expansionrom_gui_settings;
  9490. TCHAR expansionrom_gui_string[ROMCONFIG_CONFIGTEXT_LEN];
  9491. };
  9492. static struct expansionrom_gui expansion_gui_item;
  9493. static struct expansionrom_gui accelerator_gui_item;
  9494. static void reset_expansionrom_gui(HWND hDlg, struct expansionrom_gui *eg, DWORD itemselector, DWORD selector, DWORD checkbox, DWORD stringbox)
  9495. {
  9496. eg->expansionrom_gui_settings = NULL;
  9497. eg->expansionrom_gui_ebs = NULL;
  9498. eg->expansionrom_gui_string[0] = 0;
  9499. hide(hDlg, itemselector, 1);
  9500. hide(hDlg, selector, 1);
  9501. hide(hDlg, checkbox, 1);
  9502. hide(hDlg, stringbox, 1);
  9503. }
  9504. static void create_expansionrom_gui(HWND hDlg, struct expansionrom_gui *eg, const struct expansionboardsettings *ebs,
  9505. int settings, const TCHAR *settingsstring,
  9506. DWORD itemselector, DWORD selector, DWORD checkbox, DWORD stringbox)
  9507. {
  9508. bool reset = false;
  9509. static int recursive;
  9510. const struct expansionboardsettings *eb;
  9511. if (eg->expansionrom_gui_ebs != ebs) {
  9512. if (eg->expansionrom_gui_ebs)
  9513. eg->expansionrom_gui_item = 0;
  9514. reset = true;
  9515. }
  9516. eg->expansionrom_gui_ebs = ebs;
  9517. eg->expansionrom_gui_itemselector = itemselector;
  9518. eg->expansionrom_gui_selector = selector;
  9519. eg->expansionrom_gui_checkbox = checkbox;
  9520. eg->expansionrom_gui_stringbox = stringbox;
  9521. eg->expansionrom_gui_settings = settings;
  9522. if (settingsstring != eg->expansionrom_gui_string) {
  9523. eg->expansionrom_gui_string[0] = 0;
  9524. if (settingsstring)
  9525. _tcscpy(eg->expansionrom_gui_string, settingsstring);
  9526. }
  9527. if (!ebs) {
  9528. reset_expansionrom_gui(hDlg, eg, itemselector, selector, checkbox, stringbox);
  9529. return;
  9530. }
  9531. if (recursive > 0)
  9532. return;
  9533. recursive++;
  9534. retry:
  9535. int item = eg->expansionrom_gui_item;
  9536. hide(hDlg, itemselector, 0);
  9537. int bitcnt = 0;
  9538. for (int i = 0; i < item; i++) {
  9539. const struct expansionboardsettings *eb = &ebs[i];
  9540. if (eb->name == NULL) {
  9541. eg->expansionrom_gui_item = 0;
  9542. goto retry;
  9543. }
  9544. if (eb->type == EXPANSIONBOARD_STRING) {
  9545. ;
  9546. } else if (eb->type == EXPANSIONBOARD_MULTI) {
  9547. const TCHAR *p = eb->configname;
  9548. int itemcnt = -1;
  9549. while (p[0]) {
  9550. itemcnt++;
  9551. p += _tcslen(p) + 1;
  9552. }
  9553. int bits = 1;
  9554. for (int i = 0; i < 8; i++) {
  9555. if ((1 << i) >= itemcnt) {
  9556. bits = i;
  9557. break;
  9558. }
  9559. }
  9560. bitcnt += bits;
  9561. } else {
  9562. bitcnt++;
  9563. }
  9564. bitcnt += eb->bitshift;
  9565. }
  9566. if (reset) {
  9567. SendDlgItemMessage(hDlg, itemselector, CB_RESETCONTENT, 0, 0);
  9568. for (int i = 0; ebs[i].name; i++) {
  9569. const struct expansionboardsettings *eb = &ebs[i];
  9570. SendDlgItemMessage(hDlg, itemselector, CB_ADDSTRING, 0, (LPARAM)eb->name);
  9571. }
  9572. SendDlgItemMessage(hDlg, itemselector, CB_SETCURSEL, item, 0);
  9573. }
  9574. eb = &ebs[item];
  9575. bitcnt += eb->bitshift;
  9576. if (eb->type == EXPANSIONBOARD_STRING) {
  9577. hide(hDlg, stringbox, 0);
  9578. hide(hDlg, selector, 1);
  9579. hide(hDlg, checkbox, 1);
  9580. eg->expansionrom_gui_settingsbits = 0;
  9581. SetDlgItemText(hDlg, stringbox, eg->expansionrom_gui_string);
  9582. } else if (eb->type == EXPANSIONBOARD_MULTI) {
  9583. SendDlgItemMessage(hDlg, selector, CB_RESETCONTENT, 0, 0);
  9584. int itemcnt = -1;
  9585. const TCHAR *p = eb->name;
  9586. while (p[0]) {
  9587. if (itemcnt >= 0) {
  9588. SendDlgItemMessage(hDlg, selector, CB_ADDSTRING, 0, (LPARAM)p);
  9589. }
  9590. itemcnt++;
  9591. p += _tcslen(p) + 1;
  9592. }
  9593. int bits = 1;
  9594. for (int i = 0; i < 8; i++) {
  9595. if ((1 << i) >= itemcnt) {
  9596. bits = i;
  9597. break;
  9598. }
  9599. }
  9600. int value = settings;
  9601. if (eb->invert)
  9602. value ^= 0x7fffffff;
  9603. value >>= bitcnt;
  9604. value &= (1 << bits) - 1;
  9605. SendDlgItemMessage(hDlg, selector, CB_SETCURSEL, value, 0);
  9606. hide(hDlg, stringbox, 1);
  9607. hide(hDlg, selector, 0);
  9608. hide(hDlg, checkbox, 1);
  9609. eg->expansionrom_gui_settingsbits = bits;
  9610. } else {
  9611. hide(hDlg, stringbox, 1);
  9612. hide(hDlg, selector, 1);
  9613. hide(hDlg, checkbox, 0);
  9614. setchecked(hDlg, checkbox, ((settings >> bitcnt) ^ (eb->invert ? 1 : 0)) & 1);
  9615. eg->expansionrom_gui_settingsbits = 1;
  9616. }
  9617. eg->expansionrom_gui_settingsshift = bitcnt;
  9618. recursive--;
  9619. }
  9620. static void get_expansionrom_gui(HWND hDlg, struct expansionrom_gui *eg)
  9621. {
  9622. if (!eg->expansionrom_gui_ebs)
  9623. return;
  9624. int val;
  9625. int settings = eg->expansionrom_gui_settings;
  9626. val = SendDlgItemMessage(hDlg, eg->expansionrom_gui_itemselector, CB_GETCURSEL, 0, 0);
  9627. if (val != CB_ERR && val != eg->expansionrom_gui_item) {
  9628. eg->expansionrom_gui_item = val;
  9629. create_expansionrom_gui(hDlg, eg, eg->expansionrom_gui_ebs, eg->expansionrom_gui_settings, eg->expansionrom_gui_string,
  9630. eg->expansionrom_gui_itemselector, eg->expansionrom_gui_selector, eg->expansionrom_gui_checkbox, eg->expansionrom_gui_stringbox);
  9631. return;
  9632. }
  9633. const struct expansionboardsettings *eb = &eg->expansionrom_gui_ebs[eg->expansionrom_gui_item];
  9634. if (eb->type == EXPANSIONBOARD_STRING) {
  9635. GetDlgItemText(hDlg, eg->expansionrom_gui_stringbox, eg->expansionrom_gui_string, sizeof(eg->expansionrom_gui_string) / sizeof(TCHAR));
  9636. } else if (eb->type == EXPANSIONBOARD_MULTI) {
  9637. val = SendDlgItemMessage(hDlg, eg->expansionrom_gui_selector, CB_GETCURSEL, 0, 0);
  9638. if (val != CB_ERR) {
  9639. int mask = (1 << eg->expansionrom_gui_settingsbits) - 1;
  9640. settings &= ~(mask << eg->expansionrom_gui_settingsshift);
  9641. settings |= val << eg->expansionrom_gui_settingsshift;
  9642. if (eb->invert)
  9643. settings ^= mask << eg->expansionrom_gui_settingsshift;
  9644. }
  9645. } else {
  9646. settings &= ~(1 << eg->expansionrom_gui_settingsshift);
  9647. if (ischecked(hDlg, eg->expansionrom_gui_checkbox)) {
  9648. settings |= 1 << eg->expansionrom_gui_settingsshift;
  9649. }
  9650. if (eb->invert)
  9651. settings ^= 1 << eg->expansionrom_gui_settingsshift;
  9652. }
  9653. eg->expansionrom_gui_settings = settings;
  9654. }
  9655. static struct netdriverdata *ndd[MAX_TOTAL_NET_DEVICES + 1];
  9656. static int net_enumerated;
  9657. struct netdriverdata **target_ethernet_enumerate(void)
  9658. {
  9659. if (net_enumerated)
  9660. return ndd;
  9661. ethernet_enumerate(ndd, 0);
  9662. net_enumerated = 1;
  9663. return ndd;
  9664. }
  9665. static const int scsiromselectedmask[] = {
  9666. EXPANSIONTYPE_INTERNAL, EXPANSIONTYPE_SCSI, EXPANSIONTYPE_IDE, EXPANSIONTYPE_SASI, EXPANSIONTYPE_CUSTOM,
  9667. EXPANSIONTYPE_PCI_BRIDGE, EXPANSIONTYPE_X86_BRIDGE, EXPANSIONTYPE_RTG,
  9668. EXPANSIONTYPE_SOUND, EXPANSIONTYPE_NET, EXPANSIONTYPE_FLOPPY, EXPANSIONTYPE_X86_EXPANSION
  9669. };
  9670. static void init_expansion2(HWND hDlg, bool init)
  9671. {
  9672. static int first = -1;
  9673. bool last = false;
  9674. for (;;) {
  9675. bool matched = false;
  9676. int *idtab;
  9677. int total = 0;
  9678. SendDlgItemMessage(hDlg, IDC_SCSIROMSELECT, CB_RESETCONTENT, 0, 0);
  9679. scsiromselect_table[0] = -1;
  9680. for (int i = 0; expansionroms[i].name; i++) {
  9681. total++;
  9682. }
  9683. idtab = xcalloc(int, total * 2);
  9684. int idcnt = 0;
  9685. for (int i = 0; expansionroms[i].name; i++) {
  9686. if (expansionroms[i].romtype & ROMTYPE_CPUBOARD)
  9687. continue;
  9688. if (!(expansionroms[i].deviceflags & scsiromselectedmask[scsiromselectedcatnum]))
  9689. continue;
  9690. if (scsiromselectedcatnum == 0 && (expansionroms[i].deviceflags & (EXPANSIONTYPE_SASI | EXPANSIONTYPE_CUSTOM)))
  9691. continue;
  9692. if ((expansionroms[i].deviceflags & EXPANSIONTYPE_X86_EXPANSION) && scsiromselectedmask[scsiromselectedcatnum] != EXPANSIONTYPE_X86_EXPANSION)
  9693. continue;
  9694. int cnt = 0;
  9695. for (int j = 0; j < MAX_DUPLICATE_EXPANSION_BOARDS; j++) {
  9696. if (is_board_enabled(&workprefs, expansionroms[i].romtype, j)) {
  9697. cnt++;
  9698. }
  9699. }
  9700. if (i == scsiromselected)
  9701. matched = true;
  9702. if (cnt > 0) {
  9703. if (first < 0)
  9704. first = i;
  9705. }
  9706. idtab[idcnt++] = i;
  9707. idtab[idcnt++] = cnt;
  9708. }
  9709. for (int j = 0; j < idcnt; j += 2) {
  9710. TCHAR *nameval = NULL;
  9711. TCHAR *cnameval = NULL;
  9712. int ididx = -1;
  9713. for (int i = 0; i < idcnt; i += 2) {
  9714. TCHAR name[256], cname[256];
  9715. int id = idtab[i];
  9716. int cnt = idtab[i + 1];
  9717. if (id < 0)
  9718. continue;
  9719. name[0] = 0;
  9720. cname[0] = 0;
  9721. if (cnt == 1)
  9722. _tcscat(name, _T("* "));
  9723. else if (cnt > 1)
  9724. _stprintf(name + _tcslen(name), _T("[%d] "), cnt);
  9725. _tcscat(name, expansionroms[id].friendlyname);
  9726. _tcscat(cname, expansionroms[id].friendlyname);
  9727. if (expansionroms[id].friendlymanufacturer) {
  9728. _tcscat(name, _T(" ("));
  9729. _tcscat(name, expansionroms[id].friendlymanufacturer);
  9730. _tcscat(name, _T(")"));
  9731. }
  9732. if (!cnameval || _tcsicmp(cnameval, cname) > 0) {
  9733. xfree(nameval);
  9734. xfree(cnameval);
  9735. nameval = my_strdup(name);
  9736. cnameval = my_strdup(cname);
  9737. ididx = i;
  9738. }
  9739. }
  9740. gui_add_string(scsiromselect_table, hDlg, IDC_SCSIROMSELECT, idtab[ididx], nameval);
  9741. idtab[ididx] = -1;
  9742. xfree(nameval);
  9743. xfree(cnameval);
  9744. }
  9745. xfree(idtab);
  9746. if (scsiromselected > 0 && matched)
  9747. break;
  9748. int found = -1;
  9749. for (int i = 0; expansionroms[i].name; i++) {
  9750. int romtype = expansionroms[i].romtype;
  9751. if (romtype & ROMTYPE_CPUBOARD)
  9752. continue;
  9753. if (!(expansionroms[i].deviceflags & scsiromselectedmask[scsiromselectedcatnum]))
  9754. continue;
  9755. if (scsiromselectedcatnum == 0 && (expansionroms[i].deviceflags & (EXPANSIONTYPE_SASI | EXPANSIONTYPE_CUSTOM)))
  9756. continue;
  9757. if (is_board_enabled(&workprefs, romtype, 0)) {
  9758. if (found == -1)
  9759. found = i;
  9760. else
  9761. found = -2;
  9762. }
  9763. }
  9764. if (scsiromselected < 0 && found < 0)
  9765. found = first;
  9766. if (found > 0) {
  9767. scsiromselected = found;
  9768. break;
  9769. }
  9770. if (last || !init)
  9771. break;
  9772. scsiromselectedcatnum++;
  9773. if (scsiromselectedcatnum > 5) {
  9774. last = true;
  9775. scsiromselectedcatnum = 0;
  9776. scsiromselected = 0;
  9777. }
  9778. }
  9779. if (scsiromselected > 0)
  9780. gui_set_string_cursor(scsiromselect_table, hDlg, IDC_SCSIROMSELECT, scsiromselected);
  9781. SendDlgItemMessage(hDlg, IDC_SCSIROMSELECTCAT, CB_SETCURSEL, scsiromselectedcatnum, 0);
  9782. SendDlgItemMessage(hDlg, IDC_SCSIROMID, CB_RESETCONTENT, 0, 0);
  9783. int index;
  9784. struct boardromconfig *brc = get_device_rom(&workprefs, expansionroms[scsiromselected].romtype, scsiromselectednum, &index);
  9785. const struct expansionromtype *ert = &expansionroms[scsiromselected];
  9786. if (brc && ert && ert->id_jumper) {
  9787. for (int i = 0; i < 8; i++) {
  9788. TCHAR tmp[10];
  9789. _stprintf(tmp, _T("%d"), i);
  9790. SendDlgItemMessage(hDlg, IDC_SCSIROMID, CB_ADDSTRING, 0, (LPARAM)tmp);
  9791. }
  9792. } else {
  9793. SendDlgItemMessage(hDlg, IDC_SCSIROMID, CB_ADDSTRING, 0, (LPARAM)_T("-"));
  9794. SendDlgItemMessage(hDlg, IDC_SCSIROMID, CB_SETCURSEL, 0, 0);
  9795. ew(hDlg, IDC_SCSIROMID, 0);
  9796. }
  9797. }
  9798. static void values_to_expansion2dlg_sub(HWND hDlg)
  9799. {
  9800. SendDlgItemMessage(hDlg, IDC_CPUBOARDROMSUBSELECT, CB_RESETCONTENT, 0, 0);
  9801. ew(hDlg, IDC_CPUBOARDROMSUBSELECT, false);
  9802. SendDlgItemMessage(hDlg, IDC_SCSIROMSUBSELECT, CB_RESETCONTENT, 0, 0);
  9803. const struct expansionromtype *er = &expansionroms[scsiromselected];
  9804. const struct expansionsubromtype *srt = er->subtypes;
  9805. int deviceflags = er->deviceflags;
  9806. ew(hDlg, IDC_SCSIROMSUBSELECT, srt != NULL);
  9807. while (srt && srt->name) {
  9808. SendDlgItemMessage(hDlg, IDC_SCSIROMSUBSELECT, CB_ADDSTRING, 0, (LPARAM) srt->name);
  9809. srt++;
  9810. }
  9811. int index;
  9812. struct boardromconfig *brc = get_device_rom(&workprefs, expansionroms[scsiromselected].romtype, scsiromselectednum, &index);
  9813. if (brc && er->subtypes) {
  9814. SendDlgItemMessage(hDlg, IDC_SCSIROMSUBSELECT, CB_SETCURSEL, brc->roms[index].subtype, 0);
  9815. SendDlgItemMessage(hDlg, IDC_SCSIROMID, CB_SETCURSEL, brc->roms[index].device_id, 0);
  9816. deviceflags |= er->subtypes[brc->roms[index].subtype].deviceflags;
  9817. } else if (srt) {
  9818. SendDlgItemMessage(hDlg, IDC_SCSIROMSUBSELECT, CB_SETCURSEL, 0, 0);
  9819. SendDlgItemMessage(hDlg, IDC_SCSIROMID, CB_SETCURSEL, 0, 0);
  9820. }
  9821. SendDlgItemMessage(hDlg, IDC_SCSIROMSELECTNUM, CB_RESETCONTENT, 0, 0);
  9822. if (deviceflags & EXPANSIONTYPE_CLOCKPORT) {
  9823. SendDlgItemMessage(hDlg, IDC_SCSIROMSELECTNUM, CB_ADDSTRING, 0, (LPARAM)_T("-"));
  9824. }
  9825. for (int i = 0; i < MAX_AVAILABLE_DUPLICATE_EXPANSION_BOARDS; i++) {
  9826. TCHAR tmp[10];
  9827. _stprintf(tmp, _T("%d"), i + 1);
  9828. SendDlgItemMessage(hDlg, IDC_SCSIROMSELECTNUM, CB_ADDSTRING, 0, (LPARAM)tmp);
  9829. }
  9830. SendDlgItemMessage(hDlg, IDC_SCSIROMSELECTNUM, CB_SETCURSEL, scsiromselectednum, 0);
  9831. if ((er->zorro < 2 || er->singleonly) && !(deviceflags & EXPANSIONTYPE_CLOCKPORT)) {
  9832. scsiromselectednum = 0;
  9833. SendDlgItemMessage(hDlg, IDC_SCSIROMSELECTNUM, CB_SETCURSEL, 0, 0);
  9834. }
  9835. ew(hDlg, IDC_SCSIROMSELECTNUM, (er->zorro >= 2 && !er->singleonly) || (deviceflags & EXPANSIONTYPE_CLOCKPORT));
  9836. hide(hDlg, IDC_SCSIROM24BITDMA, (deviceflags & EXPANSIONTYPE_DMA24) == 0);
  9837. ew(hDlg, IDC_SCSIROM24BITDMA, (deviceflags & EXPANSIONTYPE_DMA24) != 0);
  9838. }
  9839. static void values_from_expansion2dlg(HWND hDlg)
  9840. {
  9841. int index;
  9842. struct boardromconfig *brc;
  9843. TCHAR tmp[MAX_DPATH];
  9844. bool changed = false;
  9845. bool isnew = false;
  9846. int checked = ischecked(hDlg, IDC_SCSIROMSELECTED);
  9847. getromfile(hDlg, IDC_SCSIROMFILE, tmp, MAX_DPATH / sizeof(TCHAR));
  9848. if (tmp[0] || checked) {
  9849. const struct expansionromtype *ert = &expansionroms[scsiromselected];
  9850. if (!get_device_rom(&workprefs, expansionroms[scsiromselected].romtype, scsiromselectednum, &index))
  9851. isnew = true;
  9852. brc = get_device_rom_new(&workprefs, expansionroms[scsiromselected].romtype, scsiromselectednum, &index);
  9853. if (checked) {
  9854. if (!brc->roms[index].romfile[0])
  9855. changed = true;
  9856. _tcscpy(brc->roms[index].romfile, _T(":ENABLED"));
  9857. } else {
  9858. changed = _tcscmp(tmp, brc->roms[index].romfile) != 0;
  9859. getromfile(hDlg, IDC_SCSIROMFILE, brc->roms[index].romfile, MAX_DPATH / sizeof(TCHAR));
  9860. }
  9861. brc->roms[index].autoboot_disabled = ischecked(hDlg, IDC_SCSIROMFILEAUTOBOOT);
  9862. brc->roms[index].inserted = ischecked(hDlg, IDC_SCSIROMFILEPCMCIA);
  9863. brc->roms[index].dma24bit = ischecked(hDlg, IDC_SCSIROM24BITDMA);
  9864. int v = SendDlgItemMessage(hDlg, IDC_SCSIROMID, CB_GETCURSEL, 0, 0L);
  9865. if (v != CB_ERR && !isnew)
  9866. brc->roms[index].device_id = v;
  9867. const struct expansionboardsettings *cbs = ert->settings;
  9868. if (cbs) {
  9869. brc->roms[index].device_settings = expansion_gui_item.expansionrom_gui_settings;
  9870. _tcscpy(brc->roms[index].configtext, expansion_gui_item.expansionrom_gui_string);
  9871. }
  9872. #if 0
  9873. for (int i = 0; cbs[i].name; i++) {
  9874. int id = expansion_settings_id[i];
  9875. if (id < 0)
  9876. break;
  9877. brc->roms[index].device_settings &= ~(1 << i);
  9878. if (ischecked(hDlg, id))
  9879. brc->roms[index].device_settings |= 1 << i;
  9880. }
  9881. }
  9882. #endif
  9883. v = SendDlgItemMessage(hDlg, IDC_SCSIROMSUBSELECT, CB_GETCURSEL, 0, 0L);
  9884. if (v != CB_ERR)
  9885. brc->roms[index].subtype = v;
  9886. } else {
  9887. brc = get_device_rom(&workprefs, expansionroms[scsiromselected].romtype, scsiromselectednum, &index);
  9888. if (brc && brc->roms[index].romfile[0])
  9889. changed = true;
  9890. clear_device_rom(&workprefs, expansionroms[scsiromselected].romtype, scsiromselectednum, true);
  9891. }
  9892. if (changed) {
  9893. // singleonly check and removal
  9894. if (expansionroms[scsiromselected].singleonly) {
  9895. if (get_device_rom(&workprefs, expansionroms[scsiromselected].romtype, scsiromselectednum, &index)) {
  9896. for (int i = 0; i < MAX_EXPANSION_BOARDS; i++) {
  9897. if (i != scsiromselectednum) {
  9898. clear_device_rom(&workprefs, expansionroms[scsiromselected].romtype, i, true);
  9899. }
  9900. }
  9901. }
  9902. }
  9903. init_expansion2(hDlg, false);
  9904. values_to_expansion2dlg_sub(hDlg);
  9905. }
  9906. workprefs.cpuboard_settings = accelerator_gui_item.expansionrom_gui_settings;
  9907. getromfile(hDlg, IDC_CPUBOARDROMFILE, tmp, sizeof(brc->roms[index].romfile) / sizeof(TCHAR));
  9908. if (tmp[0]) {
  9909. brc = get_device_rom_new(&workprefs, ROMTYPE_CPUBOARD, 0, &index);
  9910. getromfile(hDlg, IDC_CPUBOARDROMFILE, brc->roms[index].romfile, sizeof(brc->roms[index].romfile) / sizeof(TCHAR));
  9911. } else {
  9912. clear_device_rom(&workprefs, ROMTYPE_CPUBOARD, 0, true);
  9913. }
  9914. }
  9915. static void values_to_expansion2_expansion_roms(HWND hDlg, UAEREG *fkey)
  9916. {
  9917. int index;
  9918. bool keyallocated = false;
  9919. struct boardromconfig *brc;
  9920. if (!fkey) {
  9921. fkey = regcreatetree(NULL, _T("DetectedROMs"));
  9922. keyallocated = true;
  9923. }
  9924. if (scsiromselected) {
  9925. const struct expansionromtype *ert = &expansionroms[scsiromselected];
  9926. int romtype = ert->romtype;
  9927. int romtype_extra = ert->romtype_extra;
  9928. int deviceflags = ert->deviceflags;
  9929. brc = get_device_rom(&workprefs, romtype, scsiromselectednum, &index);
  9930. if (brc && ert->subtypes) {
  9931. const struct expansionsubromtype *esrt = &ert->subtypes[brc->roms[index].subtype];
  9932. if (esrt->romtype) {
  9933. romtype = esrt->romtype;
  9934. romtype_extra = 0;
  9935. }
  9936. deviceflags |= esrt->deviceflags;
  9937. }
  9938. ew(hDlg, IDC_SCSIROMFILE, true);
  9939. ew(hDlg, IDC_SCSIROMCHOOSER, true);
  9940. hide(hDlg, IDC_SCSIROMFILEAUTOBOOT, 0);
  9941. if (romtype & ROMTYPE_NOT) {
  9942. hide(hDlg, IDC_SCSIROMCHOOSER, 1);
  9943. hide(hDlg, IDC_SCSIROMFILE, 1);
  9944. hide(hDlg, IDC_SCSIROMSELECTED, 0);
  9945. setchecked(hDlg, IDC_SCSIROMSELECTED, brc && brc->roms[index].romfile[0] != 0);
  9946. } else {
  9947. hide(hDlg, IDC_SCSIROMCHOOSER, 0);
  9948. hide(hDlg, IDC_SCSIROMFILE, 0);
  9949. hide(hDlg, IDC_SCSIROMSELECTED, 1);
  9950. setchecked(hDlg, IDC_SCSIROMSELECTED, false);
  9951. addromfiles(fkey, hDlg, IDC_SCSIROMFILE, brc ? brc->roms[index].romfile : NULL, romtype, romtype_extra);
  9952. setchecked(hDlg, IDC_SCSIROMFILEAUTOBOOT, brc && brc->roms[index].autoboot_disabled);
  9953. }
  9954. if (deviceflags & EXPANSIONTYPE_PCMCIA) {
  9955. setchecked(hDlg, IDC_SCSIROMFILEPCMCIA, brc && brc->roms[index].inserted);
  9956. hide(hDlg, IDC_SCSIROMFILEPCMCIA, 0);
  9957. } else {
  9958. hide(hDlg, IDC_SCSIROMFILEPCMCIA, 1);
  9959. if (brc)
  9960. brc->roms[index].inserted = false;
  9961. }
  9962. hide(hDlg, IDC_SCSIROM24BITDMA, (deviceflags & EXPANSIONTYPE_DMA24) == 0);
  9963. ew(hDlg, IDC_SCSIROM24BITDMA, (deviceflags & EXPANSIONTYPE_DMA24) != 0);
  9964. setchecked(hDlg, IDC_SCSIROM24BITDMA, brc && brc->roms[index].dma24bit);
  9965. } else {
  9966. hide(hDlg, IDC_SCSIROMCHOOSER, 0);
  9967. hide(hDlg, IDC_SCSIROMFILE, 0);
  9968. hide(hDlg, IDC_SCSIROMSELECTED, 1);
  9969. hide(hDlg, IDC_SCSIROMFILEPCMCIA, 1);
  9970. hide(hDlg, IDC_SCSIROMFILEAUTOBOOT, 1);
  9971. setchecked(hDlg, IDC_SCSIROMSELECTED, false);
  9972. setchecked(hDlg, IDC_SCSIROMFILEAUTOBOOT, false);
  9973. setchecked(hDlg, IDC_SCSIROMFILEPCMCIA, false);
  9974. SendDlgItemMessage(hDlg, IDC_SCSIROMFILE, CB_RESETCONTENT, 0, 0);
  9975. ew(hDlg, IDC_SCSIROMFILE, false);
  9976. ew(hDlg, IDC_SCSIROMCHOOSER, false);
  9977. ew(hDlg, IDC_SCSIROM24BITDMA, 0);
  9978. hide(hDlg, IDC_SCSIROM24BITDMA, 1);
  9979. }
  9980. if (keyallocated)
  9981. regclosetree(fkey);
  9982. }
  9983. #if 0
  9984. static void createautoconfiginfo(struct autoconfig_info *aci, TCHAR *buf)
  9985. {
  9986. TCHAR tmp2[200];
  9987. if (aci->autoconfig[0] == 0xff) {
  9988. buf[0] = 0;
  9989. return;
  9990. }
  9991. if (aci->start != 0xffffffff)
  9992. _stprintf(tmp2, _T("0x%08x-0x%08x"), aci->start, aci->start + aci->size - 1);
  9993. else
  9994. _tcscpy(tmp2, _T("--------"));
  9995. _stprintf(buf, _T("%u/%u [0x%04x/0x%02x] %s "),
  9996. (aci->autoconfig[4] << 8) | aci->autoconfig[5], aci->autoconfig[1],
  9997. (aci->autoconfig[4] << 8) | aci->autoconfig[5], aci->autoconfig[1],
  9998. tmp2
  9999. );
  10000. TCHAR *p = buf + _tcslen(buf);
  10001. for (int i = 0; i < 12; i++) {
  10002. if (i > 0)
  10003. _tcscat(p, _T("."));
  10004. _stprintf(p + _tcslen(p), _T("%02x"), aci->autoconfig[i]);
  10005. }
  10006. }
  10007. #endif
  10008. static void values_to_expansion2_expansion_settings(HWND hDlg, int mode)
  10009. {
  10010. int index;
  10011. struct boardromconfig *brc;
  10012. if (scsiromselected) {
  10013. const struct expansionromtype *ert = &expansionroms[scsiromselected];
  10014. brc = get_device_rom(&workprefs, expansionroms[scsiromselected].romtype, scsiromselectednum, &index);
  10015. if (brc) {
  10016. if (brc->roms[index].romfile[0])
  10017. ew(hDlg, IDC_SCSIROMFILEAUTOBOOT, ert->autoboot_jumper);
  10018. } else {
  10019. ew(hDlg, IDC_SCSIROMFILEAUTOBOOT, FALSE);
  10020. setchecked(hDlg, IDC_SCSIROMFILEAUTOBOOT, false);
  10021. }
  10022. ew(hDlg, IDC_SCSIROMID, ert->id_jumper);
  10023. const struct expansionboardsettings *cbs = ert->settings;
  10024. create_expansionrom_gui(hDlg, &expansion_gui_item, cbs,
  10025. brc ? brc->roms[index].device_settings : 0,
  10026. brc ? brc->roms[index].configtext : NULL,
  10027. IDC_EXPANSIONBOARDITEMSELECTOR, IDC_EXPANSIONBOARDSELECTOR, IDC_EXPANSIONBOARDCHECKBOX, IDC_EXPANSIONBOARDSTRINGBOX);
  10028. } else {
  10029. reset_expansionrom_gui(hDlg, &expansion_gui_item,
  10030. IDC_EXPANSIONBOARDITEMSELECTOR, IDC_EXPANSIONBOARDSELECTOR, IDC_EXPANSIONBOARDCHECKBOX, IDC_EXPANSIONBOARDSTRINGBOX);
  10031. }
  10032. #if 0
  10033. for (int i = 0; expansion_settings_id[i] >= 0; i++) {
  10034. hide(hDlg, expansion_settings_id[i], !(cbs && cbs[i].name));
  10035. }
  10036. int i = 0;
  10037. if (cbs) {
  10038. for (i = 0; cbs[i].name; i++) {
  10039. int id = expansion_settings_id[i];
  10040. if (id < 0)
  10041. break;
  10042. SetWindowText(GetDlgItem(hDlg, id), cbs[i].name);
  10043. setchecked(hDlg, id, (brc && (brc->roms[index].device_settings & (1 << i))));
  10044. }
  10045. }
  10046. while (expansion_settings_id[i] >= 0) {
  10047. int id = expansion_settings_id[i];
  10048. SetWindowText(GetDlgItem(hDlg, id), _T("-"));
  10049. hide(hDlg, id, true);
  10050. i++;
  10051. }
  10052. #endif
  10053. }
  10054. static void enable_for_expansion2dlg (HWND hDlg)
  10055. {
  10056. int z3 = true;
  10057. int cw, en;
  10058. en = !!full_property_sheet;
  10059. cw = catweasel_detect ();
  10060. ew(hDlg, IDC_CATWEASEL, cw && en);
  10061. ew(hDlg, IDC_SOCKETS, en);
  10062. ew(hDlg, IDC_SCSIDEVICE, en);
  10063. ew(hDlg, IDC_CATWEASEL, en);
  10064. ew(hDlg, IDC_SANA2, en);
  10065. ew(hDlg, IDC_CS_CD32FMV, en);
  10066. ew(hDlg, IDC_CPUBOARDROMFILE, workprefs.cpuboard_type != 0);
  10067. ew(hDlg, IDC_CPUBOARDROMCHOOSER, workprefs.cpuboard_type != 0);
  10068. ew(hDlg, IDC_CPUBOARDMEM, workprefs.cpuboard_type > 0);
  10069. ew(hDlg, IDC_CPUBOARDRAM, workprefs.cpuboard_type > 0);
  10070. ew(hDlg, IDC_CPUBOARD_SUBTYPE, workprefs.cpuboard_type);
  10071. #if 0
  10072. const struct expansionboardsettings *cbs = cpuboards[workprefs.cpuboard_type].subtypes[workprefs.cpuboard_subtype].settings;
  10073. int i = 0;
  10074. if (cbs) {
  10075. while (cpuboard_settings_id[i] >= 0) {
  10076. if (!cbs[i].name)
  10077. break;
  10078. hide(hDlg, cpuboard_settings_id[i], 0);
  10079. i++;
  10080. }
  10081. }
  10082. while (cpuboard_settings_id[i] >= 0) {
  10083. hide(hDlg, cpuboard_settings_id[i], 1);
  10084. i++;
  10085. }
  10086. #endif
  10087. }
  10088. static void values_to_expansion2dlg (HWND hDlg, int mode)
  10089. {
  10090. int cw;
  10091. int index;
  10092. struct boardromconfig *brc;
  10093. CheckDlgButton(hDlg, IDC_SOCKETS, workprefs.socket_emu);
  10094. CheckDlgButton(hDlg, IDC_CATWEASEL, workprefs.catweasel);
  10095. CheckDlgButton(hDlg, IDC_SCSIDEVICE, workprefs.scsi == 1);
  10096. CheckDlgButton(hDlg, IDC_SANA2, workprefs.sana2);
  10097. CheckDlgButton(hDlg, IDC_CS_CD32FMV, workprefs.cs_cd32fmv);
  10098. cw = catweasel_detect ();
  10099. ew (hDlg, IDC_CATWEASEL, cw);
  10100. if (!cw && workprefs.catweasel < 100)
  10101. workprefs.catweasel = 0;
  10102. UAEREG *fkey = regcreatetree(NULL, _T("DetectedROMs"));
  10103. load_keyring(&workprefs, NULL);
  10104. values_to_expansion2_expansion_roms(hDlg, fkey);
  10105. values_to_expansion2_expansion_settings(hDlg, mode);
  10106. if (workprefs.cpuboard_type) {
  10107. const struct cpuboardsubtype *cst = &cpuboards[workprefs.cpuboard_type].subtypes[workprefs.cpuboard_subtype];
  10108. brc = get_device_rom(&workprefs, ROMTYPE_CPUBOARD, 0, &index);
  10109. addromfiles(fkey, hDlg, IDC_CPUBOARDROMFILE, brc ? brc->roms[index].romfile : NULL,
  10110. cst->romtype, cst->romtype_extra);
  10111. } else {
  10112. SendDlgItemMessage(hDlg, IDC_CPUBOARDROMFILE, CB_RESETCONTENT, 0, 0);
  10113. }
  10114. regclosetree(fkey);
  10115. gui_set_string_cursor(scsiromselect_table, hDlg, IDC_SCSIROMSELECT, scsiromselected);
  10116. values_to_expansion2dlg_sub(hDlg);
  10117. }
  10118. static void updatecpuboardsubtypes(HWND hDlg)
  10119. {
  10120. SendDlgItemMessage(hDlg, IDC_CPUBOARD_SUBTYPE, CB_RESETCONTENT, 0, 0);
  10121. for (int i = 0; cpuboards[workprefs.cpuboard_type].subtypes[i].name; i++) {
  10122. SendDlgItemMessage(hDlg, IDC_CPUBOARD_SUBTYPE, CB_ADDSTRING, 0, (LPARAM) cpuboards[workprefs.cpuboard_type].subtypes[i].name);
  10123. }
  10124. const struct expansionboardsettings *cbs = cpuboards[workprefs.cpuboard_type].subtypes[workprefs.cpuboard_subtype].settings;
  10125. create_expansionrom_gui(hDlg, &accelerator_gui_item, cbs, workprefs.cpuboard_settings, NULL,
  10126. IDC_ACCELERATORBOARDITEMSELECTOR, IDC_ACCELERATORBOARDSELECTOR, IDC_ACCELERATORBOARDCHECKBOX, -1);
  10127. #if 0
  10128. int i = 0;
  10129. if (cbs) {
  10130. for (i = 0; cbs[i].name; i++) {
  10131. int id = cpuboard_settings_id[i];
  10132. if (id < 0)
  10133. break;
  10134. SetWindowText(GetDlgItem(hDlg, id), cbs[i].name);
  10135. }
  10136. }
  10137. while (cpuboard_settings_id[i] >= 0) {
  10138. int id = cpuboard_settings_id[i];
  10139. SetWindowText(GetDlgItem(hDlg, id), _T("-"));
  10140. i++;
  10141. }
  10142. #endif
  10143. }
  10144. static int gui_rtg_index;
  10145. static void expansion2filebuttons(HWND hDlg, WPARAM wParam, TCHAR *path)
  10146. {
  10147. switch (LOWORD(wParam))
  10148. {
  10149. case IDC_SCSIROMCHOOSER:
  10150. DiskSelection(hDlg, IDC_SCSIROMFILE, 6, &workprefs, NULL, path);
  10151. values_to_expansion2dlg(hDlg, 1);
  10152. break;
  10153. case IDC_CPUBOARDROMCHOOSER:
  10154. DiskSelection(hDlg, IDC_CPUBOARDROMFILE, 6, &workprefs, NULL, path);
  10155. values_to_expansion2dlg(hDlg, 2);
  10156. break;
  10157. }
  10158. }
  10159. static INT_PTR CALLBACK Expansion2DlgProc(HWND hDlg, UINT msg, WPARAM wParam, LPARAM lParam)
  10160. {
  10161. int v, val;
  10162. TCHAR tmp[MAX_DPATH];
  10163. static int recursive = 0;
  10164. if (dialog_inhibit)
  10165. return 0;
  10166. switch (msg)
  10167. {
  10168. case WM_INITDIALOG:
  10169. {
  10170. recursive++;
  10171. pages[EXPANSION2_ID] = hDlg;
  10172. currentpage = EXPANSION2_ID;
  10173. int ids[] = { IDC_SCSIROMFILE, IDC_CPUBOARDROMFILE, -1 };
  10174. setmultiautocomplete(hDlg, ids);
  10175. if (!net_enumerated) {
  10176. target_ethernet_enumerate();
  10177. for (int i = 0; ndd[i]; i++) {
  10178. struct netdriverdata *n = ndd[i];
  10179. if (!n->active)
  10180. continue;
  10181. if (n->type == UAENET_SLIRP) {
  10182. WIN32GUI_LoadUIString(IDS_SLIRP, tmp, sizeof tmp / sizeof(TCHAR));
  10183. n->desc = my_strdup(tmp);
  10184. }
  10185. else if (n->type == UAENET_SLIRP_INBOUND) {
  10186. WIN32GUI_LoadUIString(IDS_SLIRP_INBOUND, tmp, sizeof tmp / sizeof(TCHAR));
  10187. n->desc = my_strdup(tmp);
  10188. }
  10189. }
  10190. ethernet_updateselection();
  10191. net_enumerated = 1;
  10192. }
  10193. SendDlgItemMessage(hDlg, IDC_CPUBOARD_TYPE, CB_RESETCONTENT, 0, 0);
  10194. for (int i = 0; cpuboards[i].name; i++) {
  10195. SendDlgItemMessage(hDlg, IDC_CPUBOARD_TYPE, CB_ADDSTRING, 0, (LPARAM) cpuboards[i].name);
  10196. }
  10197. WIN32GUI_LoadUIString(IDS_EXPANSION_CATEGORY, tmp, sizeof tmp / sizeof(TCHAR));
  10198. SendDlgItemMessage(hDlg, IDC_SCSIROMSELECTCAT, CB_RESETCONTENT, 0, 0);
  10199. _tcscat(tmp, _T("\n"));
  10200. TCHAR *p1 = tmp;
  10201. for (;;) {
  10202. TCHAR *p2 = _tcschr(p1, '\n');
  10203. if (p2 && _tcslen(p2) > 0) {
  10204. *p2++ = 0;
  10205. SendDlgItemMessage(hDlg, IDC_SCSIROMSELECTCAT, CB_ADDSTRING, 0, (LPARAM)p1);
  10206. p1 = p2;
  10207. } else
  10208. break;
  10209. }
  10210. reset_expansionrom_gui(hDlg, &expansion_gui_item, IDC_EXPANSIONBOARDITEMSELECTOR, IDC_EXPANSIONBOARDSELECTOR, IDC_EXPANSIONBOARDCHECKBOX, IDC_EXPANSIONBOARDSTRINGBOX);
  10211. reset_expansionrom_gui(hDlg, &accelerator_gui_item, IDC_ACCELERATORBOARDITEMSELECTOR, IDC_ACCELERATORBOARDSELECTOR, IDC_ACCELERATORBOARDCHECKBOX, -1);
  10212. hide(hDlg, IDC_SCSIROMSELECTED, 1);
  10213. init_expansion2(hDlg, true);
  10214. updatecpuboardsubtypes(hDlg);
  10215. setcpuboardmemsize(hDlg);
  10216. recursive--;
  10217. }
  10218. case WM_USER:
  10219. recursive++;
  10220. values_to_expansion2dlg(hDlg, 0);
  10221. enable_for_expansion2dlg(hDlg);
  10222. recursive--;
  10223. break;
  10224. case WM_COMMAND:
  10225. {
  10226. if (recursive > 0)
  10227. break;
  10228. recursive++;
  10229. switch (LOWORD(wParam))
  10230. {
  10231. case IDC_EXPANSIONBOARDSTRINGBOX:
  10232. get_expansionrom_gui(hDlg, &expansion_gui_item);
  10233. values_from_expansion2dlg(hDlg);
  10234. break;
  10235. case IDC_EXPANSIONBOARDCHECKBOX:
  10236. get_expansionrom_gui(hDlg, &expansion_gui_item);
  10237. values_from_expansion2dlg(hDlg);
  10238. break;
  10239. case IDC_ACCELERATORBOARDCHECKBOX:
  10240. get_expansionrom_gui(hDlg, &accelerator_gui_item);
  10241. values_from_expansion2dlg(hDlg);
  10242. break;
  10243. case IDC_SCSIROMFILEAUTOBOOT:
  10244. case IDC_SCSIROMFILEPCMCIA:
  10245. case IDC_SCSIROM24BITDMA:
  10246. values_from_expansion2dlg(hDlg);
  10247. break;
  10248. case IDC_SOCKETS:
  10249. workprefs.socket_emu = ischecked(hDlg, IDC_SOCKETS);
  10250. break;
  10251. case IDC_SCSIDEVICE:
  10252. workprefs.scsi = ischecked(hDlg, IDC_SCSIDEVICE);
  10253. enable_for_expansion2dlg(hDlg);
  10254. break;
  10255. case IDC_SANA2:
  10256. workprefs.sana2 = ischecked(hDlg, IDC_SANA2);
  10257. break;
  10258. case IDC_CATWEASEL:
  10259. workprefs.catweasel = ischecked(hDlg, IDC_CATWEASEL) ? -1 : 0;
  10260. cfgfile_compatibility_romtype(&workprefs);
  10261. break;
  10262. case IDC_CS_CD32FMV:
  10263. workprefs.cs_cd32fmv = ischecked(hDlg, IDC_CS_CD32FMV) ? 1 : 0;
  10264. cfgfile_compatibility_romtype(&workprefs);
  10265. break;
  10266. case IDC_SCSIROMSELECTED:
  10267. values_from_expansion2dlg(hDlg);
  10268. values_to_expansion2_expansion_settings(hDlg, 1);
  10269. break;
  10270. }
  10271. expansion2filebuttons(hDlg, wParam, NULL);
  10272. if (HIWORD(wParam) == CBN_SELENDOK || HIWORD(wParam) == CBN_KILLFOCUS || HIWORD(wParam) == CBN_EDITCHANGE) {
  10273. switch (LOWORD(wParam))
  10274. {
  10275. case IDC_EXPANSIONBOARDITEMSELECTOR:
  10276. case IDC_EXPANSIONBOARDSELECTOR:
  10277. get_expansionrom_gui(hDlg, &expansion_gui_item);
  10278. values_from_expansion2dlg(hDlg);
  10279. break;
  10280. case IDC_ACCELERATORBOARDITEMSELECTOR:
  10281. case IDC_ACCELERATORBOARDSELECTOR:
  10282. get_expansionrom_gui(hDlg, &accelerator_gui_item);
  10283. values_from_expansion2dlg(hDlg);
  10284. break;
  10285. case IDC_SCSIROMFILE:
  10286. case IDC_SCSIROMID:
  10287. values_from_expansion2dlg(hDlg);
  10288. values_to_expansion2_expansion_settings(hDlg, 1);
  10289. break;
  10290. case IDC_CPUBOARDROMFILE:
  10291. case IDC_CPUBOARDROMSUBSELECT:
  10292. values_from_expansion2dlg(hDlg);
  10293. values_to_expansion2_expansion_settings(hDlg, 2);
  10294. break;
  10295. case IDC_SCSIROMSUBSELECT:
  10296. values_from_expansion2dlg(hDlg);
  10297. values_to_expansion2_expansion_roms(hDlg, NULL);
  10298. values_to_expansion2_expansion_settings(hDlg, 1);
  10299. break;
  10300. case IDC_SCSIROMSELECTCAT:
  10301. val = SendDlgItemMessage(hDlg, IDC_SCSIROMSELECTCAT, CB_GETCURSEL, 0, 0);
  10302. if (val != CB_ERR && val != scsiromselectedcatnum) {
  10303. scsiromselectedcatnum = val;
  10304. scsiromselected = 0;
  10305. init_expansion2(hDlg, false);
  10306. values_to_expansion2_expansion_roms(hDlg, NULL);
  10307. values_to_expansion2_expansion_settings(hDlg, 1);
  10308. values_to_expansion2dlg_sub(hDlg);
  10309. }
  10310. break;
  10311. case IDC_SCSIROMSELECTNUM:
  10312. case IDC_SCSIROMSELECT:
  10313. val = SendDlgItemMessage(hDlg, IDC_SCSIROMSELECTNUM, CB_GETCURSEL, 0, 0);
  10314. if (val != CB_ERR)
  10315. scsiromselectednum = val;
  10316. val = gui_get_string_cursor(scsiromselect_table, hDlg, IDC_SCSIROMSELECT);
  10317. if (val != CB_ERR) {
  10318. scsiromselected = val;
  10319. values_to_expansion2_expansion_roms(hDlg, NULL);
  10320. values_to_expansion2_expansion_settings(hDlg, 1);
  10321. values_to_expansion2dlg_sub(hDlg);
  10322. }
  10323. break;
  10324. case IDC_CPUBOARD_TYPE:
  10325. v = SendDlgItemMessage(hDlg, IDC_CPUBOARD_TYPE, CB_GETCURSEL, 0, 0L);
  10326. if (v != CB_ERR && v != workprefs.cpuboard_type) {
  10327. workprefs.cpuboard_type = v;
  10328. workprefs.cpuboard_subtype = 0;
  10329. workprefs.cpuboard_settings = 0;
  10330. updatecpuboardsubtypes(hDlg);
  10331. if (is_ppc_cpu(&workprefs)) {
  10332. workprefs.ppc_mode = 2;
  10333. } else if (workprefs.ppc_mode == 2) {
  10334. workprefs.ppc_mode = 0;
  10335. }
  10336. cpuboard_set_cpu(&workprefs);
  10337. setcpuboardmemsize(hDlg);
  10338. enable_for_expansion2dlg(hDlg);
  10339. values_to_expansion2dlg(hDlg, 2);
  10340. }
  10341. break;
  10342. case IDC_CPUBOARD_SUBTYPE:
  10343. v = SendDlgItemMessage(hDlg, IDC_CPUBOARD_SUBTYPE, CB_GETCURSEL, 0, 0L);
  10344. if (v != CB_ERR && v != workprefs.cpuboard_subtype) {
  10345. workprefs.cpuboard_subtype = v;
  10346. workprefs.cpuboard_settings = 0;
  10347. updatecpuboardsubtypes(hDlg);
  10348. if (is_ppc_cpu(&workprefs)) {
  10349. workprefs.ppc_mode = 2;
  10350. } else if (workprefs.ppc_mode == 2) {
  10351. workprefs.ppc_mode = 0;
  10352. }
  10353. cpuboard_set_cpu(&workprefs);
  10354. setcpuboardmemsize(hDlg);
  10355. enable_for_expansion2dlg(hDlg);
  10356. values_to_expansion2dlg(hDlg, 2);
  10357. }
  10358. break;
  10359. }
  10360. }
  10361. #if 0
  10362. for (int i = 0; cpuboard_settings_id[i] >= 0; i++) {
  10363. workprefs.cpuboard_settings &= ~(1 << i);
  10364. if (ischecked(hDlg, cpuboard_settings_id[i]))
  10365. workprefs.cpuboard_settings |= 1 << i;
  10366. }
  10367. #endif
  10368. recursive--;
  10369. }
  10370. break;
  10371. case WM_HSCROLL:
  10372. if (recursive > 0)
  10373. break;
  10374. recursive++;
  10375. workprefs.cpuboardmem1.size = memsizes[msi_cpuboard[SendMessage(GetDlgItem(hDlg, IDC_CPUBOARDMEM), TBM_GETPOS, 0, 0)]];
  10376. setcpuboardmemsize(hDlg);
  10377. recursive--;
  10378. break;
  10379. }
  10380. return FALSE;
  10381. }
  10382. static void enable_for_expansiondlg(HWND hDlg)
  10383. {
  10384. int z3 = true;
  10385. int en;
  10386. en = !!full_property_sheet;
  10387. int rtg = workprefs.rtgboards[gui_rtg_index].rtgmem_size && full_property_sheet && workprefs.rtgboards[gui_rtg_index].rtgmem_type < GFXBOARD_HARDWARE;
  10388. int rtg2 = workprefs.rtgboards[gui_rtg_index].rtgmem_size || workprefs.rtgboards[gui_rtg_index].rtgmem_type >= GFXBOARD_HARDWARE;
  10389. int rtg3 = workprefs.rtgboards[gui_rtg_index].rtgmem_size && workprefs.rtgboards[gui_rtg_index].rtgmem_type < GFXBOARD_HARDWARE;
  10390. int rtg4 = workprefs.rtgboards[gui_rtg_index].rtgmem_type < GFXBOARD_HARDWARE;
  10391. int rtg5 = workprefs.rtgboards[gui_rtg_index].rtgmem_size && full_property_sheet;
  10392. int rtg0 = rtg2;
  10393. if (gui_rtg_index > 0) {
  10394. rtg = false;
  10395. rtg2 = false;
  10396. rtg3 = false;
  10397. }
  10398. ew(hDlg, IDC_P96RAM, rtg0);
  10399. ew(hDlg, IDC_P96MEM, rtg0);
  10400. ew(hDlg, IDC_RTG_Z2Z3, z3);
  10401. ew(hDlg, IDC_MONITOREMU_MON, rtg5);
  10402. ew(hDlg, IDC_RTG_8BIT, rtg);
  10403. ew(hDlg, IDC_RTG_16BIT, rtg);
  10404. ew(hDlg, IDC_RTG_24BIT, rtg);
  10405. ew(hDlg, IDC_RTG_32BIT, rtg);
  10406. ew(hDlg, IDC_RTG_MATCH_DEPTH, rtg3);
  10407. ew(hDlg, IDC_RTG_SCALE, rtg2);
  10408. ew(hDlg, IDC_RTG_CENTER, rtg2);
  10409. ew(hDlg, IDC_RTG_SCALE_ALLOW, rtg2);
  10410. ew(hDlg, IDC_RTG_SCALE_ASPECTRATIO, rtg2);
  10411. ew(hDlg, IDC_RTG_VBLANKRATE, rtg2);
  10412. ew(hDlg, IDC_RTG_BUFFERCNT, rtg2);
  10413. ew(hDlg, IDC_RTG_DISPLAYSELECT, rtg2);
  10414. ew(hDlg, IDC_RTG_VBINTERRUPT, rtg3);
  10415. ew(hDlg, IDC_RTG_THREAD, rtg3 && en);
  10416. if (!workprefs.gfx_api) {
  10417. workprefs.rtg_hardwaresprite = false;
  10418. CheckDlgButton(hDlg, IDC_RTG_HWSPRITE, FALSE);
  10419. }
  10420. ew(hDlg, IDC_RTG_HWSPRITE, rtg3 && workprefs.gfx_api);
  10421. }
  10422. static void values_to_expansiondlg(HWND hDlg)
  10423. {
  10424. SendDlgItemMessage(hDlg, IDC_RTG_BUFFERCNT, CB_SETCURSEL, workprefs.gfx_apmode[1].gfx_backbuffers == 0 ? 0 : workprefs.gfx_apmode[1].gfx_backbuffers - 1, 0);
  10425. int min_mem = MIN_P96_MEM;
  10426. int max_mem = MAX_P96_MEM_Z3;
  10427. struct rtgboardconfig *rbc = &workprefs.rtgboards[gui_rtg_index];
  10428. if (gfxboard_get_configtype(rbc) == 2) {
  10429. int v = rbc->rtgmem_size;
  10430. max_mem = MAX_P96_MEM_Z2;
  10431. rbc->rtgmem_size = 1024 * 1024;
  10432. if (rbc->rtgmem_type >= GFXBOARD_HARDWARE && v > gfxboard_get_vram_max(rbc))
  10433. v = gfxboard_get_vram_max(rbc);
  10434. if (rbc->rtgmem_type >= GFXBOARD_HARDWARE && v < gfxboard_get_vram_min(rbc))
  10435. v = gfxboard_get_vram_min(rbc);
  10436. rbc->rtgmem_size = v;
  10437. } else if (gfxboard_get_configtype(rbc) == 3) {
  10438. int v = rbc->rtgmem_size;
  10439. if (rbc->rtgmem_type >= GFXBOARD_HARDWARE && v > gfxboard_get_vram_max(rbc))
  10440. v = gfxboard_get_vram_max(rbc);
  10441. if (rbc->rtgmem_type >= GFXBOARD_HARDWARE && v < gfxboard_get_vram_min(rbc))
  10442. v = gfxboard_get_vram_min(rbc);
  10443. rbc->rtgmem_size = v;
  10444. } else {
  10445. int v = rbc->rtgmem_size;
  10446. if (rbc->rtgmem_type >= GFXBOARD_HARDWARE && v > gfxboard_get_vram_max(rbc))
  10447. v = gfxboard_get_vram_max(rbc);
  10448. if (rbc->rtgmem_type >= GFXBOARD_HARDWARE && v < gfxboard_get_vram_min(rbc))
  10449. v = gfxboard_get_vram_min(rbc);
  10450. rbc->rtgmem_size = v;
  10451. }
  10452. if (rbc->rtgmem_type >= GFXBOARD_HARDWARE) {
  10453. switch (gfxboard_get_vram_min(rbc)) {
  10454. case 0x00100000: min_mem = 1; break;
  10455. case 0x00200000: min_mem = 2; break;
  10456. case 0x00400000: min_mem = 3; break;
  10457. }
  10458. switch (gfxboard_get_vram_max(rbc)) {
  10459. case 0x00100000: max_mem = 1; break;
  10460. case 0x00200000: max_mem = 2; break;
  10461. case 0x00400000: max_mem = 3; break;
  10462. }
  10463. }
  10464. SendDlgItemMessage(hDlg, IDC_P96MEM, TBM_SETRANGE, TRUE, MAKELONG(min_mem, max_mem));
  10465. int mem_size = 0;
  10466. switch (rbc->rtgmem_size) {
  10467. case 0x00000000: mem_size = 0; break;
  10468. case 0x00100000: mem_size = 1; break;
  10469. case 0x00200000: mem_size = 2; break;
  10470. case 0x00400000: mem_size = 3; break;
  10471. case 0x00800000: mem_size = 4; break;
  10472. case 0x01000000: mem_size = 5; break;
  10473. case 0x02000000: mem_size = 6; break;
  10474. case 0x04000000: mem_size = 7; break;
  10475. case 0x08000000: mem_size = 8; break;
  10476. case 0x10000000: mem_size = 9; break;
  10477. case 0x20000000: mem_size = 10; break;
  10478. case 0x40000000: mem_size = 11; break;
  10479. }
  10480. SendDlgItemMessage(hDlg, IDC_P96MEM, TBM_SETPOS, TRUE, mem_size);
  10481. SetDlgItemText(hDlg, IDC_P96RAM, memsize_names[msi_gfx[mem_size]]);
  10482. SendDlgItemMessage(hDlg, IDC_RTG_Z2Z3, CB_SETCURSEL, rbc->rtgmem_size == 0 ? 0 : gfxboard_get_index_from_id(rbc->rtgmem_type) + 1, 0);
  10483. SendDlgItemMessage(hDlg, IDC_MONITOREMU_MON, CB_SETCURSEL, rbc->monitor_id, 0);
  10484. SendDlgItemMessage(hDlg, IDC_RTG_NUM, CB_SETCURSEL, gui_rtg_index, 0);
  10485. SendDlgItemMessage(hDlg, IDC_RTG_8BIT, CB_SETCURSEL, (workprefs.picasso96_modeflags & RGBFF_CLUT) ? 1 : 0, 0);
  10486. SendDlgItemMessage(hDlg, IDC_RTG_16BIT, CB_SETCURSEL,
  10487. (manybits(workprefs.picasso96_modeflags, RGBFF_R5G6B5PC | RGBFF_R5G6B5PC | RGBFF_R5G6B5 | RGBFF_R5G5B5 | RGBFF_B5G6R5PC | RGBFF_B5G5R5PC)) ? 1 :
  10488. (workprefs.picasso96_modeflags & RGBFF_R5G6B5PC) ? 2 :
  10489. (workprefs.picasso96_modeflags & RGBFF_R5G5B5PC) ? 3 :
  10490. (workprefs.picasso96_modeflags & RGBFF_R5G6B5) ? 4 :
  10491. (workprefs.picasso96_modeflags & RGBFF_R5G5B5) ? 5 :
  10492. (workprefs.picasso96_modeflags & RGBFF_B5G6R5PC) ? 6 :
  10493. (workprefs.picasso96_modeflags & RGBFF_B5G5R5PC) ? 7 : 0, 0);
  10494. SendDlgItemMessage(hDlg, IDC_RTG_24BIT, CB_SETCURSEL,
  10495. (manybits(workprefs.picasso96_modeflags, RGBFF_R8G8B8 | RGBFF_B8G8R8)) ? 1 :
  10496. (workprefs.picasso96_modeflags & RGBFF_R8G8B8) ? 2 :
  10497. (workprefs.picasso96_modeflags & RGBFF_B8G8R8) ? 3 : 0, 0);
  10498. SendDlgItemMessage(hDlg, IDC_RTG_32BIT, CB_SETCURSEL,
  10499. (manybits(workprefs.picasso96_modeflags, RGBFF_A8R8G8B8 | RGBFF_A8B8G8R8 | RGBFF_R8G8B8A8 | RGBFF_B8G8R8A8)) ? 1 :
  10500. (workprefs.picasso96_modeflags & RGBFF_A8R8G8B8) ? 2 :
  10501. (workprefs.picasso96_modeflags & RGBFF_A8B8G8R8) ? 3 :
  10502. (workprefs.picasso96_modeflags & RGBFF_R8G8B8A8) ? 4 :
  10503. (workprefs.picasso96_modeflags & RGBFF_B8G8R8A8) ? 5 : 0, 0);
  10504. if (workprefs.win32_rtgvblankrate <= 0 ||
  10505. workprefs.win32_rtgvblankrate == 50 ||
  10506. workprefs.win32_rtgvblankrate == 60 ||
  10507. workprefs.win32_rtgvblankrate == 70 ||
  10508. workprefs.win32_rtgvblankrate == 75) {
  10509. SendDlgItemMessage(hDlg, IDC_RTG_VBLANKRATE, CB_SETCURSEL,
  10510. (workprefs.win32_rtgvblankrate == 0) ? 0 :
  10511. (workprefs.win32_rtgvblankrate == -1) ? 1 :
  10512. (workprefs.win32_rtgvblankrate == -2) ? 0 :
  10513. (workprefs.win32_rtgvblankrate == 50) ? 2 :
  10514. (workprefs.win32_rtgvblankrate == 60) ? 3 :
  10515. (workprefs.win32_rtgvblankrate == 70) ? 4 :
  10516. (workprefs.win32_rtgvblankrate == 75) ? 5 : 0, 0);
  10517. } else {
  10518. TCHAR tmp[10];
  10519. _stprintf(tmp, _T("%d"), workprefs.win32_rtgvblankrate);
  10520. SendDlgItemMessage(hDlg, IDC_RTG_VBLANKRATE, WM_SETTEXT, 0, (LPARAM) tmp);
  10521. }
  10522. CheckDlgButton(hDlg, IDC_RTG_SCALE, workprefs.gf[1].gfx_filter_autoscale == RTG_MODE_SCALE);
  10523. CheckDlgButton(hDlg, IDC_RTG_CENTER, workprefs.gf[1].gfx_filter_autoscale == RTG_MODE_CENTER);
  10524. CheckDlgButton(hDlg, IDC_RTG_SCALE_ALLOW, workprefs.win32_rtgallowscaling);
  10525. CheckDlgButton(hDlg, IDC_RTG_MATCH_DEPTH, workprefs.win32_rtgmatchdepth);
  10526. CheckDlgButton(hDlg, IDC_RTG_VBINTERRUPT, workprefs.rtg_hardwareinterrupt);
  10527. CheckDlgButton(hDlg, IDC_RTG_HWSPRITE, workprefs.rtg_hardwaresprite);
  10528. CheckDlgButton(hDlg, IDC_RTG_THREAD, workprefs.rtg_multithread);
  10529. SendDlgItemMessage(hDlg, IDC_RTG_SCALE_ASPECTRATIO, CB_SETCURSEL,
  10530. (workprefs.win32_rtgscaleaspectratio == 0) ? 0 :
  10531. (workprefs.win32_rtgscaleaspectratio < 0) ? 1 :
  10532. getaspectratioindex(workprefs.win32_rtgscaleaspectratio) + 2, 0);
  10533. }
  10534. static INT_PTR CALLBACK ExpansionDlgProc (HWND hDlg, UINT msg, WPARAM wParam, LPARAM lParam)
  10535. {
  10536. int v;
  10537. TCHAR tmp[256];
  10538. static int recursive = 0;
  10539. static int enumerated;
  10540. if (dialog_inhibit)
  10541. return 0;
  10542. switch (msg)
  10543. {
  10544. case WM_INITDIALOG:
  10545. pages[EXPANSION_ID] = hDlg;
  10546. currentpage = EXPANSION_ID;
  10547. init_displays_combo (hDlg, true);
  10548. SendDlgItemMessage(hDlg, IDC_RTG_NUM, CB_RESETCONTENT, 0, 0);
  10549. for (int i = 0; i < MAX_RTG_BOARDS; i++) {
  10550. _stprintf(tmp, _T("%d"), i + 1);
  10551. SendDlgItemMessage(hDlg, IDC_RTG_NUM, CB_ADDSTRING, 0, (LPARAM)tmp);
  10552. }
  10553. SendDlgItemMessage(hDlg, IDC_MONITOREMU_MON, CB_RESETCONTENT, 0, 0);
  10554. for (int i = 0; i < MAX_AMIGAMONITORS; i++) {
  10555. _stprintf(tmp, _T("%d"), i + 1);
  10556. SendDlgItemMessage(hDlg, IDC_MONITOREMU_MON, CB_ADDSTRING, 0, (LPARAM)tmp);
  10557. }
  10558. SendDlgItemMessage (hDlg, IDC_RTG_Z2Z3, CB_RESETCONTENT, 0, 0);
  10559. SendDlgItemMessage (hDlg, IDC_RTG_Z2Z3, CB_ADDSTRING, 0, (LPARAM)_T("-"));
  10560. v = 0;
  10561. for (;;) {
  10562. int index = gfxboard_get_id_from_index(v);
  10563. if (index < 0)
  10564. break;
  10565. const TCHAR *n1 = gfxboard_get_name(index);
  10566. const TCHAR *n2 = gfxboard_get_manufacturername(index);
  10567. v++;
  10568. _tcscpy(tmp, n1);
  10569. if (n2) {
  10570. _tcscat(tmp, _T(" ("));
  10571. _tcscat(tmp, n2);
  10572. _tcscat(tmp, _T(")"));
  10573. }
  10574. SendDlgItemMessage (hDlg, IDC_RTG_Z2Z3, CB_ADDSTRING, 0, (LPARAM)tmp);
  10575. }
  10576. WIN32GUI_LoadUIString(IDS_ALL, tmp, sizeof tmp / sizeof (TCHAR));
  10577. SendDlgItemMessage (hDlg, IDC_RTG_8BIT, CB_RESETCONTENT, 0, 0);
  10578. SendDlgItemMessage (hDlg, IDC_RTG_8BIT, CB_ADDSTRING, 0, (LPARAM)_T("(8bit)"));
  10579. SendDlgItemMessage (hDlg, IDC_RTG_8BIT, CB_ADDSTRING, 0, (LPARAM)_T("8-bit (*)"));
  10580. SendDlgItemMessage (hDlg, IDC_RTG_16BIT, CB_RESETCONTENT, 0, 0);
  10581. SendDlgItemMessage (hDlg, IDC_RTG_16BIT, CB_ADDSTRING, 0, (LPARAM)_T("(15/16bit)"));
  10582. SendDlgItemMessage (hDlg, IDC_RTG_16BIT, CB_ADDSTRING, 0, (LPARAM)tmp);
  10583. SendDlgItemMessage (hDlg, IDC_RTG_16BIT, CB_ADDSTRING, 0, (LPARAM)_T("R5G6B5PC (*)"));
  10584. SendDlgItemMessage (hDlg, IDC_RTG_16BIT, CB_ADDSTRING, 0, (LPARAM)_T("R5G5B5PC"));
  10585. SendDlgItemMessage (hDlg, IDC_RTG_16BIT, CB_ADDSTRING, 0, (LPARAM)_T("R5G6B5"));
  10586. SendDlgItemMessage (hDlg, IDC_RTG_16BIT, CB_ADDSTRING, 0, (LPARAM)_T("R5G5B5"));
  10587. SendDlgItemMessage (hDlg, IDC_RTG_16BIT, CB_ADDSTRING, 0, (LPARAM)_T("B5G6R5PC"));
  10588. SendDlgItemMessage (hDlg, IDC_RTG_16BIT, CB_ADDSTRING, 0, (LPARAM)_T("B5G5R5PC"));
  10589. SendDlgItemMessage (hDlg, IDC_RTG_24BIT, CB_RESETCONTENT, 0, 0);
  10590. SendDlgItemMessage (hDlg, IDC_RTG_24BIT, CB_ADDSTRING, 0, (LPARAM)_T("(24bit)"));
  10591. SendDlgItemMessage (hDlg, IDC_RTG_24BIT, CB_ADDSTRING, 0, (LPARAM)tmp);
  10592. SendDlgItemMessage (hDlg, IDC_RTG_24BIT, CB_ADDSTRING, 0, (LPARAM)_T("R8G8B8"));
  10593. SendDlgItemMessage (hDlg, IDC_RTG_24BIT, CB_ADDSTRING, 0, (LPARAM)_T("B8G8R8"));
  10594. SendDlgItemMessage (hDlg, IDC_RTG_32BIT, CB_RESETCONTENT, 0, 0);
  10595. SendDlgItemMessage (hDlg, IDC_RTG_32BIT, CB_ADDSTRING, 0, (LPARAM)_T("(32bit)"));
  10596. SendDlgItemMessage (hDlg, IDC_RTG_32BIT, CB_ADDSTRING, 0, (LPARAM)tmp);
  10597. SendDlgItemMessage (hDlg, IDC_RTG_32BIT, CB_ADDSTRING, 0, (LPARAM)_T("A8R8G8B8"));
  10598. SendDlgItemMessage (hDlg, IDC_RTG_32BIT, CB_ADDSTRING, 0, (LPARAM)_T("A8B8G8R8"));
  10599. SendDlgItemMessage (hDlg, IDC_RTG_32BIT, CB_ADDSTRING, 0, (LPARAM)_T("R8G8B8A8"));
  10600. SendDlgItemMessage (hDlg, IDC_RTG_32BIT, CB_ADDSTRING, 0, (LPARAM)_T("B8G8R8A8 (*)"));
  10601. SendDlgItemMessage (hDlg, IDC_P96MEM, TBM_SETRANGE, TRUE, MAKELONG (MIN_P96_MEM, gfxboard_get_configtype(&workprefs.rtgboards[gui_rtg_index]) == 3 ? MAX_P96_MEM_Z3 : MAX_P96_MEM_Z2));
  10602. SendDlgItemMessage (hDlg, IDC_RTG_SCALE_ASPECTRATIO, CB_RESETCONTENT, 0, 0);
  10603. WIN32GUI_LoadUIString (IDS_DISABLED, tmp, sizeof tmp / sizeof (TCHAR));
  10604. SendDlgItemMessage (hDlg, IDC_RTG_SCALE_ASPECTRATIO, CB_ADDSTRING, 0, (LPARAM)tmp);
  10605. WIN32GUI_LoadUIString (IDS_AUTOMATIC, tmp, sizeof tmp / sizeof (TCHAR));
  10606. SendDlgItemMessage (hDlg, IDC_RTG_SCALE_ASPECTRATIO, CB_ADDSTRING, 0, (LPARAM)tmp);
  10607. addaspectratios (hDlg, IDC_RTG_SCALE_ASPECTRATIO);
  10608. SendDlgItemMessage (hDlg, IDC_RTG_VBLANKRATE, CB_RESETCONTENT, 0, 0);
  10609. SendDlgItemMessage (hDlg, IDC_RTG_VBLANKRATE, CB_ADDSTRING, 0, (LPARAM)_T("Chipset"));
  10610. SendDlgItemMessage (hDlg, IDC_RTG_VBLANKRATE, CB_ADDSTRING, 0, (LPARAM)_T("Default"));
  10611. SendDlgItemMessage (hDlg, IDC_RTG_VBLANKRATE, CB_ADDSTRING, 0, (LPARAM)_T("50"));
  10612. SendDlgItemMessage (hDlg, IDC_RTG_VBLANKRATE, CB_ADDSTRING, 0, (LPARAM)_T("60"));
  10613. SendDlgItemMessage (hDlg, IDC_RTG_VBLANKRATE, CB_ADDSTRING, 0, (LPARAM)_T("70"));
  10614. SendDlgItemMessage (hDlg, IDC_RTG_VBLANKRATE, CB_ADDSTRING, 0, (LPARAM)_T("75"));
  10615. SendDlgItemMessage(hDlg, IDC_RTG_BUFFERCNT, CB_RESETCONTENT, 0, 0);
  10616. WIN32GUI_LoadUIString(IDS_BUFFER_DOUBLE, tmp, sizeof tmp / sizeof (TCHAR));
  10617. SendDlgItemMessage(hDlg, IDC_RTG_BUFFERCNT, CB_ADDSTRING, 0, (LPARAM)tmp);
  10618. WIN32GUI_LoadUIString(IDS_BUFFER_TRIPLE, tmp, sizeof tmp / sizeof (TCHAR));
  10619. SendDlgItemMessage(hDlg, IDC_RTG_BUFFERCNT, CB_ADDSTRING, 0, (LPARAM)tmp);
  10620. case WM_USER:
  10621. recursive++;
  10622. values_to_expansiondlg (hDlg);
  10623. enable_for_expansiondlg (hDlg);
  10624. recursive--;
  10625. break;
  10626. case WM_HSCROLL:
  10627. workprefs.rtgboards[gui_rtg_index].rtgmem_size = memsizes[msi_gfx[SendMessage (GetDlgItem (hDlg, IDC_P96MEM), TBM_GETPOS, 0, 0)]];
  10628. values_to_expansiondlg(hDlg);
  10629. enable_for_expansiondlg(hDlg);
  10630. break;
  10631. case WM_COMMAND:
  10632. {
  10633. if (recursive > 0)
  10634. break;
  10635. recursive++;
  10636. switch (LOWORD (wParam))
  10637. {
  10638. case IDC_RTG_MATCH_DEPTH:
  10639. workprefs.win32_rtgmatchdepth = ischecked (hDlg, IDC_RTG_MATCH_DEPTH);
  10640. break;
  10641. case IDC_RTG_SCALE:
  10642. workprefs.gf[1].gfx_filter_autoscale = ischecked(hDlg, IDC_RTG_SCALE) ? RTG_MODE_SCALE : 0;
  10643. setchecked (hDlg, IDC_RTG_CENTER, false);
  10644. break;
  10645. case IDC_RTG_CENTER:
  10646. workprefs.gf[1].gfx_filter_autoscale = ischecked(hDlg, IDC_RTG_CENTER) ? RTG_MODE_CENTER : 0;
  10647. setchecked (hDlg, IDC_RTG_SCALE, false);
  10648. break;
  10649. case IDC_RTG_SCALE_ALLOW:
  10650. workprefs.win32_rtgallowscaling = ischecked (hDlg, IDC_RTG_SCALE_ALLOW);
  10651. break;
  10652. case IDC_RTG_VBINTERRUPT:
  10653. workprefs.rtg_hardwareinterrupt = ischecked (hDlg, IDC_RTG_VBINTERRUPT);
  10654. break;
  10655. case IDC_RTG_HWSPRITE:
  10656. workprefs.rtg_hardwaresprite = ischecked(hDlg, IDC_RTG_HWSPRITE);
  10657. break;
  10658. case IDC_RTG_THREAD:
  10659. workprefs.rtg_multithread = ischecked(hDlg, IDC_RTG_THREAD);
  10660. break;
  10661. }
  10662. if (HIWORD (wParam) == CBN_SELENDOK || HIWORD (wParam) == CBN_KILLFOCUS || HIWORD (wParam) == CBN_EDITCHANGE) {
  10663. uae_u32 mask = workprefs.picasso96_modeflags;
  10664. switch (LOWORD (wParam))
  10665. {
  10666. case IDC_RTG_DISPLAYSELECT:
  10667. get_displays_combo (hDlg, true);
  10668. break;
  10669. case IDC_RTG_BUFFERCNT:
  10670. v = SendDlgItemMessage (hDlg, IDC_RTG_BUFFERCNT, CB_GETCURSEL, 0, 0L);
  10671. if (v != CB_ERR) {
  10672. v++;
  10673. workprefs.gfx_apmode[1].gfx_backbuffers = v;
  10674. }
  10675. break;
  10676. case IDC_RTG_SCALE_ASPECTRATIO:
  10677. v = SendDlgItemMessage (hDlg, IDC_RTG_SCALE_ASPECTRATIO, CB_GETCURSEL, 0, 0L);
  10678. if (v != CB_ERR) {
  10679. if (v == 0)
  10680. workprefs.win32_rtgscaleaspectratio = 0;
  10681. else if (v == 1)
  10682. workprefs.win32_rtgscaleaspectratio = -1;
  10683. else if (v >= 2)
  10684. workprefs.win32_rtgscaleaspectratio = getaspectratio (v - 2);
  10685. }
  10686. break;
  10687. case IDC_RTG_NUM:
  10688. v = SendDlgItemMessage(hDlg, IDC_RTG_NUM, CB_GETCURSEL, 0, 0L);
  10689. if (v != CB_ERR) {
  10690. gui_rtg_index = v;
  10691. values_to_expansiondlg(hDlg);
  10692. enable_for_expansiondlg(hDlg);
  10693. }
  10694. break;
  10695. case IDC_MONITOREMU_MON:
  10696. v = SendDlgItemMessage(hDlg, IDC_MONITOREMU_MON, CB_GETCURSEL, 0, 0L);
  10697. if (v != CB_ERR) {
  10698. workprefs.rtgboards[gui_rtg_index].monitor_id = v;
  10699. values_to_expansiondlg(hDlg);
  10700. }
  10701. break;
  10702. case IDC_RTG_Z2Z3:
  10703. v = SendDlgItemMessage (hDlg, IDC_RTG_Z2Z3, CB_GETCURSEL, 0, 0L);
  10704. if (v != CB_ERR) {
  10705. if (v == 0) {
  10706. workprefs.rtgboards[gui_rtg_index].rtgmem_type = 1;
  10707. workprefs.rtgboards[gui_rtg_index].rtgmem_size = 0;
  10708. } else {
  10709. workprefs.rtgboards[gui_rtg_index].rtgmem_type = gfxboard_get_id_from_index(v - 1);
  10710. if (workprefs.rtgboards[gui_rtg_index].rtgmem_size == 0)
  10711. workprefs.rtgboards[gui_rtg_index].rtgmem_size = 4096 * 1024;
  10712. }
  10713. cfgfile_compatibility_rtg(&workprefs);
  10714. enable_for_expansiondlg (hDlg);
  10715. }
  10716. break;
  10717. case IDC_RTG_8BIT:
  10718. v = SendDlgItemMessage (hDlg, IDC_RTG_8BIT, CB_GETCURSEL, 0, 0L);
  10719. if (v != CB_ERR) {
  10720. mask &= ~RGBFF_CLUT;
  10721. if (v == 1)
  10722. mask |= RGBFF_CLUT;
  10723. }
  10724. break;
  10725. case IDC_RTG_16BIT:
  10726. v = SendDlgItemMessage (hDlg, IDC_RTG_16BIT, CB_GETCURSEL, 0, 0L);
  10727. if (v != CB_ERR) {
  10728. mask &= ~(RGBFF_R5G6B5PC | RGBFF_R5G5B5PC | RGBFF_R5G6B5 | RGBFF_R5G5B5 | RGBFF_B5G6R5PC | RGBFF_B5G5R5PC);
  10729. if (v == 1)
  10730. mask |= RGBFF_R5G6B5PC | RGBFF_R5G6B5PC | RGBFF_R5G5B5PC | RGBFF_R5G6B5 | RGBFF_R5G5B5 | RGBFF_B5G6R5PC | RGBFF_B5G5R5PC;
  10731. if (v == 2)
  10732. mask |= RGBFF_R5G6B5PC;
  10733. if (v == 3)
  10734. mask |= RGBFF_R5G5B5PC;
  10735. if (v == 4)
  10736. mask |= RGBFF_R5G6B5;
  10737. if (v == 5)
  10738. mask |= RGBFF_R5G5B5;
  10739. if (v == 6)
  10740. mask |= RGBFF_B5G6R5PC;
  10741. if (v == 7)
  10742. mask |= RGBFF_B5G5R5PC;
  10743. }
  10744. break;
  10745. case IDC_RTG_24BIT:
  10746. v = SendDlgItemMessage (hDlg, IDC_RTG_24BIT, CB_GETCURSEL, 0, 0L);
  10747. if (v != CB_ERR) {
  10748. mask &= ~(RGBFF_R8G8B8 | RGBFF_B8G8R8);
  10749. if (v == 1)
  10750. mask |= RGBFF_R8G8B8 | RGBFF_B8G8R8;
  10751. if (v == 2)
  10752. mask |= RGBFF_R8G8B8;
  10753. if (v == 3)
  10754. mask |= RGBFF_B8G8R8;
  10755. }
  10756. break;
  10757. case IDC_RTG_32BIT:
  10758. v = SendDlgItemMessage (hDlg, IDC_RTG_32BIT, CB_GETCURSEL, 0, 0L);
  10759. if (v != CB_ERR) {
  10760. mask &= ~(RGBFF_A8R8G8B8 | RGBFF_A8B8G8R8 | RGBFF_R8G8B8A8 | RGBFF_B8G8R8A8);
  10761. if (v == 1)
  10762. mask |= RGBFF_A8R8G8B8 | RGBFF_A8B8G8R8 | RGBFF_R8G8B8A8 | RGBFF_B8G8R8A8;
  10763. if (v == 2)
  10764. mask |= RGBFF_A8R8G8B8;
  10765. if (v == 3)
  10766. mask |= RGBFF_A8B8G8R8;
  10767. if (v == 4)
  10768. mask |= RGBFF_R8G8B8A8;
  10769. if (v == 5)
  10770. mask |= RGBFF_B8G8R8A8;
  10771. }
  10772. break;
  10773. case IDC_RTG_VBLANKRATE:
  10774. tmp[0] = 0;
  10775. v = SendDlgItemMessage (hDlg, IDC_RTG_VBLANKRATE, CB_GETCURSEL, 0, 0L);
  10776. if (v != CB_ERR) {
  10777. if (v == 0) {
  10778. workprefs.win32_rtgvblankrate = 0;
  10779. } else if (v == 1) {
  10780. workprefs.win32_rtgvblankrate = -1;
  10781. } else {
  10782. v = SendDlgItemMessage (hDlg, IDC_RTG_VBLANKRATE, CB_GETLBTEXT, (WPARAM)v, (LPARAM)tmp);
  10783. }
  10784. } else {
  10785. v = SendDlgItemMessage (hDlg, IDC_RTG_VBLANKRATE, WM_GETTEXT, (WPARAM)sizeof tmp / sizeof (TCHAR), (LPARAM)tmp);
  10786. }
  10787. if (tmp[0])
  10788. workprefs.win32_rtgvblankrate = _tstol (tmp);
  10789. break;
  10790. }
  10791. workprefs.picasso96_modeflags = mask;
  10792. values_to_expansiondlg (hDlg);
  10793. }
  10794. recursive--;
  10795. }
  10796. break;
  10797. }
  10798. return FALSE;
  10799. }
  10800. static LRESULT ProcesssBoardsDlgProcCustomDraw(LPARAM lParam)
  10801. {
  10802. }
  10803. static void BoardsEnable(HWND hDlg, int selected)
  10804. {
  10805. bool move_up = expansion_can_move(&workprefs, selected);
  10806. bool move_down = move_up;
  10807. if (move_up) {
  10808. if (expansion_autoconfig_move(&workprefs, selected, -1, true) < 0)
  10809. move_up = false;
  10810. }
  10811. if (move_down) {
  10812. if (expansion_autoconfig_move(&workprefs, selected, 1, true) < 0)
  10813. move_down = false;
  10814. }
  10815. ew(hDlg, IDC_BOARDS_UP, move_up);
  10816. ew(hDlg, IDC_BOARDS_DOWN, move_down);
  10817. }
  10818. static INT_PTR CALLBACK BoardsDlgProc(HWND hDlg, UINT msg, WPARAM wParam, LPARAM lParam)
  10819. {
  10820. static int recursive = 0;
  10821. static int selected = -1;
  10822. if (dialog_inhibit)
  10823. return 0;
  10824. switch (msg)
  10825. {
  10826. case WM_INITDIALOG:
  10827. recursive++;
  10828. pages[BOARD_ID] = hDlg;
  10829. currentpage = BOARD_ID;
  10830. setchecked(hDlg, IDC_AUTOCONFIGCUSTOMSORT, workprefs.autoconfig_custom_sort);
  10831. ew(hDlg, IDC_BOARDLIST, workprefs.autoconfig_custom_sort != 0 && full_property_sheet);
  10832. ew(hDlg, IDC_BOARDS_UP, FALSE);
  10833. ew(hDlg, IDC_BOARDS_DOWN, FALSE);
  10834. ew(hDlg, IDC_AUTOCONFIGCUSTOMSORT, full_property_sheet);
  10835. InitializeListView(hDlg);
  10836. recursive--;
  10837. break;
  10838. case WM_COMMAND:
  10839. if (!recursive) {
  10840. recursive++;
  10841. switch (LOWORD(wParam))
  10842. {
  10843. case IDC_AUTOCONFIGCUSTOMSORT:
  10844. workprefs.autoconfig_custom_sort = ischecked(hDlg, IDC_AUTOCONFIGCUSTOMSORT);
  10845. expansion_set_autoconfig_sort(&workprefs);
  10846. ew(hDlg, IDC_BOARDLIST, workprefs.autoconfig_custom_sort != 0);
  10847. InitializeListView(hDlg);
  10848. break;
  10849. case IDC_BOARDS_UP:
  10850. case IDC_BOARDS_DOWN:
  10851. if (selected >= 0) {
  10852. int newpos = expansion_autoconfig_move(&workprefs, selected, LOWORD(wParam) == IDC_BOARDS_UP ? -1 : 1, false);
  10853. if (newpos >= 0) {
  10854. selected = newpos;
  10855. BoardsEnable(hDlg, selected);
  10856. InitializeListView(hDlg);
  10857. ListView_SetItemState(cachedlist, selected, LVIS_SELECTED, LVIS_SELECTED);
  10858. }
  10859. }
  10860. break;
  10861. }
  10862. recursive--;
  10863. }
  10864. break;
  10865. case WM_NOTIFY:
  10866. if (((LPNMHDR)lParam)->idFrom == IDC_BOARDLIST) {
  10867. switch (((LPNMHDR)lParam)->code)
  10868. {
  10869. case NM_CUSTOMDRAW:
  10870. {
  10871. LPNMLVCUSTOMDRAW lpNMLVCD = (LPNMLVCUSTOMDRAW)lParam;
  10872. switch (lpNMLVCD->nmcd.dwDrawStage)
  10873. {
  10874. case CDDS_PREPAINT:
  10875. case CDDS_ITEMPREPAINT:
  10876. SetWindowLongPtr(hDlg, DWLP_MSGRESULT, CDRF_NOTIFYITEMDRAW | CDRF_NOTIFYSUBITEMDRAW);
  10877. return TRUE;
  10878. case CDDS_ITEMPREPAINT| CDDS_SUBITEM:
  10879. {
  10880. BOOL ret = FALSE;
  10881. if (lpNMLVCD->nmcd.lItemlParam & 16) {
  10882. lpNMLVCD->clrText = GetSysColor(COLOR_GRAYTEXT);
  10883. SetWindowLongPtr(hDlg, DWLP_MSGRESULT, CDRF_NEWFONT);
  10884. ret = TRUE;
  10885. }
  10886. if (lpNMLVCD->nmcd.lItemlParam & 8) {
  10887. lpNMLVCD->clrTextBk = RGB(0xaa, 0x00, 0x00);
  10888. SetWindowLongPtr(hDlg, DWLP_MSGRESULT, CDRF_NEWFONT);
  10889. return TRUE;
  10890. }
  10891. if (lpNMLVCD->nmcd.lItemlParam & 4) {
  10892. lpNMLVCD->clrTextBk = RGB(0xaa, 0xaa, 0x00);
  10893. SetWindowLongPtr(hDlg, DWLP_MSGRESULT, CDRF_NEWFONT);
  10894. return TRUE;
  10895. }
  10896. if (lpNMLVCD->nmcd.lItemlParam & 2) {
  10897. lpNMLVCD->clrTextBk = GetSysColor(COLOR_INACTIVECAPTION);
  10898. SetWindowLongPtr(hDlg, DWLP_MSGRESULT, CDRF_NEWFONT);
  10899. return TRUE;
  10900. }
  10901. return ret;
  10902. }
  10903. }
  10904. }
  10905. return CDRF_DODEFAULT;
  10906. case NM_CLICK:
  10907. {
  10908. int column;
  10909. NM_LISTVIEW *nmlistview = (NM_LISTVIEW *)lParam;
  10910. HWND list = nmlistview->hdr.hwndFrom;
  10911. int entry = listview_entry_from_click(list, &column, false);
  10912. if (entry >= 0) {
  10913. selected = entry;
  10914. BoardsEnable(hDlg, selected);
  10915. }
  10916. }
  10917. break;
  10918. }
  10919. }
  10920. }
  10921. return FALSE;
  10922. }
  10923. static const struct memoryboardtype* getmemoryboardselect(HWND hDlg)
  10924. {
  10925. int v = SendDlgItemMessage(hDlg, IDC_MEMORYBOARDSELECT, CB_GETCURSEL, 0, 0L);
  10926. if (v == CB_ERR)
  10927. return NULL;
  10928. int idx = 1;
  10929. for (int i = 0; memoryboards[i].name; i++) {
  10930. const struct memoryboardtype *mbt = &memoryboards[i];
  10931. if ((fastram_select < MAX_RAM_BOARDS && mbt->z == 2) || (fastram_select >= MAX_RAM_BOARDS && mbt->z == 3)) {
  10932. if (idx == v) {
  10933. return mbt;
  10934. }
  10935. }
  10936. idx++;
  10937. }
  10938. return NULL;
  10939. }
  10940. static INT_PTR CALLBACK MemoryDlgProc (HWND hDlg, UINT msg, WPARAM wParam, LPARAM lParam)
  10941. {
  10942. TCHAR tmp[MAX_DPATH];
  10943. static int recursive = 0;
  10944. int v;
  10945. if (dialog_inhibit)
  10946. return 0;
  10947. switch (msg)
  10948. {
  10949. case WM_INITDIALOG:
  10950. recursive++;
  10951. pages[MEMORY_ID] = hDlg;
  10952. currentpage = MEMORY_ID;
  10953. SendDlgItemMessage (hDlg, IDC_CHIPMEM, TBM_SETRANGE, TRUE, MAKELONG (MIN_CHIP_MEM, MAX_CHIP_MEM));
  10954. SendDlgItemMessage (hDlg, IDC_FASTMEM, TBM_SETRANGE, TRUE, MAKELONG (MIN_FAST_MEM, MAX_FAST_MEM));
  10955. SendDlgItemMessage (hDlg, IDC_SLOWMEM, TBM_SETRANGE, TRUE, MAKELONG (MIN_SLOW_MEM, MAX_SLOW_MEM));
  10956. SendDlgItemMessage (hDlg, IDC_Z3FASTMEM, TBM_SETRANGE, TRUE, MAKELONG (MIN_Z3_MEM, MAX_Z3_MEM));
  10957. SendDlgItemMessage (hDlg, IDC_Z3CHIPMEM, TBM_SETRANGE, TRUE, MAKELONG (MIN_Z3_MEM, MAX_Z3_CHIPMEM));
  10958. SendDlgItemMessage (hDlg, IDC_Z3MAPPING, CB_RESETCONTENT, 0, 0);
  10959. WIN32GUI_LoadUIString (IDS_AUTOMATIC, tmp, sizeof tmp / sizeof (TCHAR));
  10960. _tcscat(tmp, _T(" (*)"));
  10961. SendDlgItemMessage (hDlg, IDC_Z3MAPPING, CB_ADDSTRING, 0, (LPARAM)tmp);
  10962. SendDlgItemMessage(hDlg, IDC_Z3MAPPING, CB_ADDSTRING, 0, (LPARAM)_T("UAE (0x10000000)"));
  10963. SendDlgItemMessage(hDlg, IDC_Z3MAPPING, CB_ADDSTRING, 0, (LPARAM)_T("Real (0x40000000)"));
  10964. SendDlgItemMessage (hDlg, IDC_Z3MAPPING, CB_SETCURSEL, workprefs.z3_mapping_mode, 0);
  10965. setfastram_selectmenu(hDlg, -1);
  10966. recursive--;
  10967. case WM_USER:
  10968. recursive++;
  10969. fix_values_memorydlg ();
  10970. values_to_memorydlg (hDlg);
  10971. enable_for_memorydlg (hDlg);
  10972. recursive--;
  10973. break;
  10974. case WM_COMMAND:
  10975. if (!recursive) {
  10976. recursive++;
  10977. switch (LOWORD(wParam))
  10978. {
  10979. case IDC_FASTMEMDMA:
  10980. if (fastram_select_ramboard) {
  10981. struct ramboard* rb = fastram_select_ramboard;
  10982. rb->nodma = ischecked(hDlg, IDC_FASTMEMDMA) == 0;
  10983. setfastram_selectmenu(hDlg, 0);
  10984. }
  10985. break;
  10986. case IDC_FASTMEMFORCE16:
  10987. if (fastram_select_ramboard) {
  10988. struct ramboard* rb = fastram_select_ramboard;
  10989. rb->force16bit = ischecked(hDlg, IDC_FASTMEMFORCE16) != 0;
  10990. setfastram_selectmenu(hDlg, 0);
  10991. }
  10992. break;
  10993. case IDC_FASTMEMAUTOCONFIGUSE:
  10994. if (fastram_select_ramboard) {
  10995. struct ramboard* rb = fastram_select_ramboard;
  10996. rb->autoconfig_inuse = ischecked(hDlg, IDC_FASTMEMAUTOCONFIGUSE);
  10997. rb->manual_config = false;
  10998. setfastram_selectmenu(hDlg, 0);
  10999. }
  11000. break;
  11001. case IDC_FASTMEMNOAUTOCONFIG:
  11002. if (fastram_select_ramboard) {
  11003. struct ramboard *rb = fastram_select_ramboard;
  11004. rb->manual_config = ischecked(hDlg, IDC_FASTMEMNOAUTOCONFIG);
  11005. rb->autoconfig_inuse = false;
  11006. const struct memoryboardtype *mbt = getmemoryboardselect(hDlg);
  11007. if (mbt && fastram_select_ramboard->manual_config && mbt->address) {
  11008. fastram_select_ramboard->start_address = mbt->address;
  11009. if (fastram_select_ramboard->end_address <= fastram_select_ramboard->start_address ||
  11010. fastram_select_ramboard->end_address >= fastram_select_ramboard->start_address + fastram_select_ramboard->size)
  11011. fastram_select_ramboard->end_address = mbt->address + fastram_select_ramboard->size - 1;
  11012. }
  11013. setfastram_selectmenu(hDlg, 0);
  11014. }
  11015. break;
  11016. }
  11017. if (HIWORD (wParam) == CBN_SELCHANGE || HIWORD (wParam) == CBN_KILLFOCUS) {
  11018. switch (LOWORD (wParam))
  11019. {
  11020. case IDC_Z3MAPPING:
  11021. v = SendDlgItemMessage (hDlg, IDC_Z3MAPPING, CB_GETCURSEL, 0, 0L);
  11022. if (v != CB_ERR) {
  11023. workprefs.z3_mapping_mode = v;
  11024. }
  11025. break;
  11026. case IDC_MEMORYSELECT:
  11027. v = SendDlgItemMessage(hDlg, IDC_MEMORYSELECT, CB_GETCURSEL, 0, 0L);
  11028. if (v != CB_ERR) {
  11029. fastram_select = v;
  11030. setfastram_selectmenu(hDlg, 0);
  11031. }
  11032. break;
  11033. case IDC_MEMORYBOARDSELECT:
  11034. if (fastram_select_ramboard) {
  11035. const struct memoryboardtype *mbt = getmemoryboardselect(hDlg);
  11036. if (mbt) {
  11037. if (mbt->manufacturer != 0xffff) {
  11038. fastram_select_ramboard->manufacturer = mbt->manufacturer;
  11039. fastram_select_ramboard->product = mbt->product;
  11040. } else {
  11041. fastram_select_ramboard->autoconfig_inuse = false;
  11042. fastram_select_ramboard->manual_config = true;
  11043. }
  11044. if (fastram_select_ramboard->manual_config && mbt->address) {
  11045. fastram_select_ramboard->start_address = mbt->address;
  11046. fastram_select_ramboard->end_address = mbt->address + fastram_select_ramboard->size - 1;
  11047. }
  11048. setfastram_selectmenu(hDlg, 0);
  11049. break;
  11050. }
  11051. }
  11052. break;
  11053. }
  11054. } else if (HIWORD(wParam) == EN_CHANGE || HIWORD(wParam) == EN_KILLFOCUS) {
  11055. switch (LOWORD(wParam))
  11056. {
  11057. case IDC_AUTOCONFIG_MANUFACTURER:
  11058. case IDC_AUTOCONFIG_PRODUCT:
  11059. if (fastram_select_ramboard) {
  11060. GetDlgItemText(hDlg, IDC_AUTOCONFIG_MANUFACTURER, tmp, sizeof tmp / sizeof(TCHAR));
  11061. fastram_select_ramboard->manufacturer = _tstol(tmp);
  11062. GetDlgItemText(hDlg, IDC_AUTOCONFIG_PRODUCT, tmp, sizeof tmp / sizeof(TCHAR));
  11063. fastram_select_ramboard->product = _tstol(tmp);
  11064. setfastram_selectmenu(hDlg, 1);
  11065. }
  11066. break;
  11067. case IDC_RAM_ADDRESS:
  11068. case IDC_RAM_ADDRESS2:
  11069. if (fastram_select_ramboard) {
  11070. TCHAR *endptr;
  11071. GetDlgItemText(hDlg, IDC_RAM_ADDRESS, tmp, sizeof tmp / sizeof(TCHAR));
  11072. fastram_select_ramboard->start_address = _tcstoul(tmp, &endptr, 16);
  11073. GetDlgItemText(hDlg, IDC_RAM_ADDRESS2, tmp, sizeof tmp / sizeof(TCHAR));
  11074. fastram_select_ramboard->end_address = _tcstoul(tmp, &endptr, 16);
  11075. setfastram_selectmenu(hDlg, HIWORD(wParam) == EN_KILLFOCUS ? 0 : 3);
  11076. }
  11077. break;
  11078. case IDC_AUTOCONFIG_DATA:
  11079. if (fastram_select_ramboard && fastram_select_ramboard->autoconfig_inuse) {
  11080. struct ramboard *rb = fastram_select_ramboard;
  11081. GetDlgItemText(hDlg, IDC_AUTOCONFIG_DATA, tmp, sizeof tmp / sizeof(TCHAR));
  11082. memset(rb->autoconfig, 0, sizeof rb->autoconfig);
  11083. for (int i = 0; i < sizeof rb->autoconfig; i++) {
  11084. TCHAR *s2 = &tmp[i * 3];
  11085. if (i + 1 < 12 && s2[2] != '.')
  11086. break;
  11087. TCHAR *endptr;
  11088. tmp[2] = 0;
  11089. rb->autoconfig[i] = (uae_u8)_tcstol(s2, &endptr, 16);
  11090. }
  11091. setfastram_selectmenu(hDlg, 2);
  11092. }
  11093. break;
  11094. }
  11095. }
  11096. recursive--;
  11097. }
  11098. break;
  11099. case WM_HSCROLL:
  11100. {
  11101. recursive++;
  11102. bool change1 = false;
  11103. uae_u32 v;
  11104. v = memsizes[msi_chip[SendMessage (GetDlgItem (hDlg, IDC_CHIPMEM), TBM_GETPOS, 0, 0)]];
  11105. if (v != workprefs.chipmem.size) {
  11106. change1 = true;
  11107. workprefs.chipmem.size = v;
  11108. }
  11109. v = memsizes[msi_bogo[SendMessage (GetDlgItem (hDlg, IDC_SLOWMEM), TBM_GETPOS, 0, 0)]];
  11110. if (v != workprefs.bogomem.size) {
  11111. change1 = true;
  11112. workprefs.bogomem.size = v;
  11113. }
  11114. v = memsizes[msi_fast[SendMessage (GetDlgItem (hDlg, IDC_FASTMEM), TBM_GETPOS, 0, 0)]];
  11115. if (v != workprefs.fastmem[0].size) {
  11116. change1 = true;
  11117. workprefs.fastmem[0].size = v;
  11118. fastram_select = 0;
  11119. setfastram_selectmenu(hDlg, 0);
  11120. }
  11121. v = memsizes[msi_z3fast[SendMessage (GetDlgItem (hDlg, IDC_Z3FASTMEM), TBM_GETPOS, 0, 0)]];
  11122. if (v != workprefs.z3fastmem[0].size) {
  11123. change1 = true;
  11124. workprefs.z3fastmem[0].size = v;
  11125. fastram_select = MAX_RAM_BOARDS;
  11126. setfastram_selectmenu(hDlg, 0);
  11127. }
  11128. v = memsizes[msi_z3chip[SendMessage (GetDlgItem (hDlg, IDC_Z3CHIPMEM), TBM_GETPOS, 0, 0)]];
  11129. if (v != workprefs.z3chipmem.size) {
  11130. change1 = true;
  11131. workprefs.z3chipmem.size = v;
  11132. }
  11133. if (!change1 && fastram_select_pointer) {
  11134. v = memsizes[fastram_select_msi[SendMessage(GetDlgItem(hDlg, IDC_MEMORYMEM), TBM_GETPOS, 0, 0)]];
  11135. if (*fastram_select_pointer != v) {
  11136. *fastram_select_pointer = v;
  11137. setfastram_selectmenu(hDlg, 0);
  11138. values_to_memorydlg(hDlg);
  11139. }
  11140. }
  11141. if (change1) {
  11142. fix_values_memorydlg ();
  11143. values_to_memorydlg (hDlg);
  11144. setfastram_selectmenu(hDlg, 0);
  11145. enable_for_memorydlg (hDlg);
  11146. }
  11147. recursive--;
  11148. break;
  11149. }
  11150. }
  11151. return FALSE;
  11152. }
  11153. static int customromselectnum;
  11154. static void values_to_kickstartdlg(HWND hDlg)
  11155. {
  11156. UAEREG *fkey;
  11157. fkey = regcreatetree(NULL, _T("DetectedROMs"));
  11158. load_keyring(&workprefs, NULL);
  11159. addromfiles(fkey, hDlg, IDC_ROMFILE, workprefs.romfile,
  11160. ROMTYPE_KICK | ROMTYPE_KICKCD32, 0);
  11161. addromfiles(fkey, hDlg, IDC_ROMFILE2, workprefs.romextfile,
  11162. ROMTYPE_EXTCD32 | ROMTYPE_EXTCDTV | ROMTYPE_ARCADIABIOS | ROMTYPE_ALG, 0);
  11163. addromfiles(fkey, hDlg, IDC_CARTFILE, workprefs.cartfile,
  11164. ROMTYPE_FREEZER | ROMTYPE_ARCADIAGAME | ROMTYPE_CD32CART, 0);
  11165. regclosetree(fkey);
  11166. SetDlgItemText(hDlg, IDC_FLASHFILE, workprefs.flashfile);
  11167. SetDlgItemText(hDlg, IDC_RTCFILE, workprefs.rtcfile);
  11168. CheckDlgButton(hDlg, IDC_KICKSHIFTER, workprefs.kickshifter);
  11169. CheckDlgButton(hDlg, IDC_MAPROM, workprefs.maprom);
  11170. if (workprefs.boot_rom == 1) {
  11171. SendDlgItemMessage(hDlg, IDC_UAEBOARD_TYPE, CB_SETCURSEL, 0, 0);
  11172. }
  11173. else {
  11174. SendDlgItemMessage(hDlg, IDC_UAEBOARD_TYPE, CB_SETCURSEL, workprefs.uaeboard + 1, 0);
  11175. }
  11176. }
  11177. static void values_to_kickstartdlg2(HWND hDlg)
  11178. {
  11179. int v = SendDlgItemMessage(hDlg, IDC_CUSTOMROMSELECT, CB_GETCURSEL, 0, 0);
  11180. if (v >= 0 && v < MAX_ROM_BOARDS) {
  11181. customromselectnum = v;
  11182. }
  11183. SendDlgItemMessage(hDlg, IDC_CUSTOMROMSELECT, CB_RESETCONTENT, 0, 0);
  11184. for (int i = 0; i < MAX_ROM_BOARDS; i++) {
  11185. TCHAR tmp[MAX_DPATH];
  11186. struct romboard *rb = &workprefs.romboards[i];
  11187. _stprintf(tmp, _T("ROM #%d"), i + 1);
  11188. if (rb->size)
  11189. _stprintf(tmp + _tcslen(tmp), _T(" %08x - %08x"), rb->start_address, rb->end_address - 1);
  11190. SendDlgItemMessage(hDlg, IDC_CUSTOMROMSELECT, CB_ADDSTRING, 0, (LPARAM)tmp);
  11191. }
  11192. if (customromselectnum >= 0 && customromselectnum < MAX_ROM_BOARDS) {
  11193. struct romboard *rb = &workprefs.romboards[customromselectnum];
  11194. TCHAR tmp[100];
  11195. _stprintf(tmp, _T("%08x"), rb->start_address);
  11196. if (!rb->end_address && !rb->start_address) {
  11197. tmp[0] = 0;
  11198. }
  11199. SetDlgItemText(hDlg, IDC_ROM_ADDRESS, tmp);
  11200. _stprintf(tmp, _T("%08x"), rb->end_address);
  11201. if (!rb->end_address && !rb->start_address) {
  11202. tmp[0] = 0;
  11203. }
  11204. SetDlgItemText(hDlg, IDC_ROM_ADDRESS2, tmp);
  11205. SetDlgItemText(hDlg, IDC_CUSTOMROMFILE, rb->lf.loadfile);
  11206. SendDlgItemMessage(hDlg, IDC_CUSTOMROMSELECT, CB_SETCURSEL, customromselectnum, 0);
  11207. }
  11208. }
  11209. static void values_from_kickstartdlg(HWND hDlg)
  11210. {
  11211. getromfile(hDlg, IDC_ROMFILE, workprefs.romfile, sizeof(workprefs.romfile) / sizeof(TCHAR));
  11212. getromfile(hDlg, IDC_ROMFILE2, workprefs.romextfile, sizeof(workprefs.romextfile) / sizeof(TCHAR));
  11213. getromfile(hDlg, IDC_CARTFILE, workprefs.cartfile, sizeof(workprefs.cartfile) / sizeof(TCHAR));
  11214. read_kickstart_version(&workprefs);
  11215. int v = SendDlgItemMessage(hDlg, IDC_UAEBOARD_TYPE, CB_GETCURSEL, 0, 0);
  11216. if (v > 0) {
  11217. workprefs.uaeboard = v - 1;
  11218. workprefs.boot_rom = 0;
  11219. } else {
  11220. workprefs.uaeboard = 0;
  11221. workprefs.boot_rom = 1; // disabled
  11222. }
  11223. }
  11224. static void values_from_kickstartdlg2(HWND hDlg)
  11225. {
  11226. int v = SendDlgItemMessage(hDlg, IDC_CUSTOMROMSELECT, CB_GETCURSEL, 0, 0);
  11227. if (v >= 0 && v < MAX_ROM_BOARDS) {
  11228. struct romboard *rb = &workprefs.romboards[v];
  11229. TCHAR tmp[100];
  11230. TCHAR *endptr;
  11231. GetDlgItemText(hDlg, IDC_ROM_ADDRESS, tmp, sizeof tmp / sizeof(TCHAR));
  11232. rb->start_address =_tcstoul(tmp, &endptr, 16);
  11233. rb->start_address &= ~65535;
  11234. GetDlgItemText(hDlg, IDC_ROM_ADDRESS2, tmp, sizeof tmp / sizeof(TCHAR));
  11235. rb->end_address = _tcstoul(tmp, &endptr, 16);
  11236. rb->end_address = ((rb->end_address - 1) & ~65535) | 0xffff;
  11237. rb->size = 0;
  11238. if (rb->end_address > rb->start_address) {
  11239. rb->size = (rb->end_address - rb->start_address + 65535) & ~65535;
  11240. }
  11241. }
  11242. }
  11243. static void init_kickstart (HWND hDlg)
  11244. {
  11245. ew (hDlg, IDC_MAPROM, workprefs.cpuboard_type == 0);
  11246. #if !defined (CDTV) && !defined (CD32)
  11247. ew (hDlg, IDC_FLASHFILE), FALSE);
  11248. ew (hDlg, IDC_ROMFILE2), FALSE);
  11249. #endif
  11250. #if !defined (ACTION_REPLAY)
  11251. ew (hDlg, IDC_CARTFILE), FALSE);
  11252. #endif
  11253. #if defined (UAE_MINI)
  11254. ew (hDlg, IDC_KICKSHIFTER), FALSE);
  11255. ew (hDlg, IDC_ROMCHOOSER2), FALSE);
  11256. ew (hDlg, IDC_CARTCHOOSER), FALSE);
  11257. ew (hDlg, IDC_FLASHCHOOSER), FALSE);
  11258. #endif
  11259. ew(hDlg, IDC_UAEBOARD_TYPE, full_property_sheet);
  11260. SendDlgItemMessage(hDlg, IDC_UAEBOARD_TYPE, CB_RESETCONTENT, 0, 0);
  11261. SendDlgItemMessage(hDlg, IDC_UAEBOARD_TYPE, CB_ADDSTRING, 0, (LPARAM)_T("ROM disabled"));
  11262. SendDlgItemMessage(hDlg, IDC_UAEBOARD_TYPE, CB_ADDSTRING, 0, (LPARAM)_T("Original UAE (FS + F0 ROM)"));
  11263. SendDlgItemMessage(hDlg, IDC_UAEBOARD_TYPE, CB_ADDSTRING, 0, (LPARAM)_T("New UAE (64k + F0 ROM)"));
  11264. SendDlgItemMessage(hDlg, IDC_UAEBOARD_TYPE, CB_ADDSTRING, 0, (LPARAM)_T("New UAE (128k, ROM, Direct)"));
  11265. SendDlgItemMessage(hDlg, IDC_UAEBOARD_TYPE, CB_ADDSTRING, 0, (LPARAM)_T("New UAE (128k, ROM, Indirect)"));
  11266. if (!regexiststree(NULL, _T("DetectedROMs")))
  11267. scan_roms (NULL, rp_isactive () ? 0 : 1);
  11268. }
  11269. static void kickstartfilebuttons (HWND hDlg, WPARAM wParam, TCHAR *path)
  11270. {
  11271. switch (LOWORD(wParam))
  11272. {
  11273. case IDC_KICKCHOOSER:
  11274. DiskSelection(hDlg, IDC_ROMFILE, 6, &workprefs, NULL, path);
  11275. values_to_kickstartdlg(hDlg);
  11276. break;
  11277. case IDC_ROMCHOOSER2:
  11278. DiskSelection(hDlg, IDC_ROMFILE2, 6, &workprefs, NULL, path);
  11279. values_to_kickstartdlg(hDlg);
  11280. break;
  11281. case IDC_CUSTOMROMCHOOSER:
  11282. DiskSelection(hDlg, IDC_CUSTOMROMFILE, 6, &workprefs, NULL, path);
  11283. values_to_kickstartdlg2(hDlg);
  11284. break;
  11285. case IDC_FLASHCHOOSER:
  11286. DiskSelection(hDlg, IDC_FLASHFILE, 11, &workprefs, NULL, path);
  11287. values_to_kickstartdlg(hDlg);
  11288. break;
  11289. case IDC_RTCCHOOSER:
  11290. DiskSelection(hDlg, IDC_RTCFILE, 19, &workprefs, NULL, path);
  11291. values_to_kickstartdlg(hDlg);
  11292. break;
  11293. case IDC_CARTCHOOSER:
  11294. DiskSelection(hDlg, IDC_CARTFILE, 6, &workprefs, NULL, path);
  11295. values_to_kickstartdlg(hDlg);
  11296. break;
  11297. }
  11298. }
  11299. static INT_PTR CALLBACK KickstartDlgProc (HWND hDlg, UINT msg, WPARAM wParam, LPARAM lParam)
  11300. {
  11301. static int recursive;
  11302. TCHAR tmp[MAX_DPATH];
  11303. if (dialog_inhibit)
  11304. return 0;
  11305. switch (msg)
  11306. {
  11307. case WM_INITDIALOG:
  11308. {
  11309. int ids[] = { IDC_ROMFILE, IDC_ROMFILE2, IDC_CARTFILE, -1 };
  11310. pages[KICKSTART_ID] = hDlg;
  11311. currentpage = KICKSTART_ID;
  11312. init_kickstart (hDlg);
  11313. values_to_kickstartdlg(hDlg);
  11314. values_to_kickstartdlg2(hDlg);
  11315. setmultiautocomplete (hDlg, ids);
  11316. setac (hDlg, IDC_FLASHFILE);
  11317. setac (hDlg, IDC_RTCFILE);
  11318. return TRUE;
  11319. }
  11320. case WM_CONTEXTMENU:
  11321. {
  11322. int id = GetDlgCtrlID((HWND)wParam);
  11323. if (id == IDC_KICKCHOOSER || id == IDC_ROMCHOOSER2
  11324. || id == IDC_FLASHCHOOSER || id == IDC_CARTCHOOSER || id == IDC_RTCCHOOSER) {
  11325. TCHAR *s = favoritepopup (hDlg);
  11326. if (s) {
  11327. TCHAR newfile[MAX_DPATH];
  11328. _tcscpy (newfile, s);
  11329. kickstartfilebuttons (hDlg, id, newfile);
  11330. xfree (s);
  11331. }
  11332. }
  11333. break;
  11334. }
  11335. case WM_COMMAND:
  11336. if (recursive > 0)
  11337. break;
  11338. recursive++;
  11339. if (HIWORD(wParam) == CBN_SELCHANGE || HIWORD(wParam) == CBN_KILLFOCUS) {
  11340. switch (LOWORD(wParam))
  11341. {
  11342. case IDC_ROMFILE:
  11343. case IDC_ROMFILE2:
  11344. case IDC_CARTFILE:
  11345. case IDC_UAEBOARD_TYPE:
  11346. values_from_kickstartdlg(hDlg);
  11347. break;
  11348. case IDC_CUSTOMROMSELECT:
  11349. values_to_kickstartdlg2(hDlg);
  11350. break;
  11351. }
  11352. } else if (HIWORD(wParam) == EN_CHANGE || HIWORD(wParam) == EN_KILLFOCUS) {
  11353. switch (LOWORD(wParam))
  11354. {
  11355. case IDC_ROM_ADDRESS:
  11356. case IDC_ROM_ADDRESS2:
  11357. values_from_kickstartdlg2(hDlg);
  11358. break;
  11359. }
  11360. }
  11361. kickstartfilebuttons (hDlg, wParam, NULL);
  11362. switch (LOWORD (wParam))
  11363. {
  11364. case IDC_FLASHFILE:
  11365. GetWindowText (GetDlgItem (hDlg, IDC_FLASHFILE), tmp, sizeof (tmp) / sizeof (TCHAR));
  11366. _tcscpy (workprefs.flashfile, tmp);
  11367. break;
  11368. case IDC_RTCFILE:
  11369. GetWindowText (GetDlgItem (hDlg, IDC_RTCFILE), tmp, sizeof (tmp) / sizeof (TCHAR));
  11370. _tcscpy (workprefs.rtcfile, tmp);
  11371. break;
  11372. case IDC_KICKSHIFTER:
  11373. workprefs.kickshifter = ischecked (hDlg, IDC_KICKSHIFTER);
  11374. break;
  11375. case IDC_MAPROM:
  11376. workprefs.maprom = ischecked (hDlg, IDC_MAPROM) ? 0x0f000000 : 0;
  11377. break;
  11378. }
  11379. recursive--;
  11380. break;
  11381. }
  11382. return FALSE;
  11383. }
  11384. static void enable_for_miscdlg (HWND hDlg)
  11385. {
  11386. if (!full_property_sheet) {
  11387. ew (hDlg, IDC_NOSPEED, TRUE);
  11388. ew (hDlg, IDC_NOSPEEDPAUSE, TRUE);
  11389. ew (hDlg, IDC_NOSOUND, TRUE);
  11390. ew (hDlg, IDC_DOSAVESTATE, TRUE);
  11391. ew (hDlg, IDC_SCSIMODE, FALSE);
  11392. } else {
  11393. #if !defined (SCSIEMU)
  11394. EnableWindow (GetDlgItem(hDlg, IDC_SCSIMODE), TRUE);
  11395. #endif
  11396. ew (hDlg, IDC_DOSAVESTATE, FALSE);
  11397. }
  11398. ew (hDlg, IDC_ASSOCIATELIST, !rp_isactive ());
  11399. ew (hDlg, IDC_ASSOCIATE_ON, !rp_isactive ());
  11400. ew (hDlg, IDC_ASSOCIATE_OFF, !rp_isactive ());
  11401. ew (hDlg, IDC_DXMODE_OPTIONS, workprefs.gfx_api == 2 || (full_property_sheet && workprefs.gfx_api == 0));
  11402. bool paused = false;
  11403. bool nosound = false;
  11404. bool nojoy = (workprefs.win32_inactive_input & 4) == 0;
  11405. ew (hDlg, IDC_ACTIVE_PAUSE, paused == false);
  11406. ew (hDlg, IDC_ACTIVE_NOSOUND, nosound == false && paused == false);
  11407. if (!paused) {
  11408. paused = workprefs.win32_active_nocapture_pause;
  11409. if (!nosound)
  11410. nosound = workprefs.win32_active_nocapture_nosound;
  11411. else
  11412. workprefs.win32_active_nocapture_nosound = true;
  11413. } else {
  11414. workprefs.win32_active_nocapture_pause = workprefs.win32_active_nocapture_nosound = true;
  11415. nosound = true;
  11416. nojoy = true;
  11417. }
  11418. if (paused)
  11419. CheckDlgButton (hDlg, IDC_INACTIVE_PAUSE, TRUE);
  11420. if (nosound || paused)
  11421. CheckDlgButton(hDlg, IDC_INACTIVE_NOSOUND, TRUE);
  11422. if (paused || nojoy)
  11423. CheckDlgButton(hDlg, IDC_INACTIVE_NOJOY, TRUE);
  11424. ew(hDlg, IDC_INACTIVE_PAUSE, paused == false);
  11425. ew(hDlg, IDC_INACTIVE_NOSOUND, nosound == false && paused == false);
  11426. ew(hDlg, IDC_INACTIVE_NOJOY, paused == false);
  11427. if (!paused) {
  11428. paused = workprefs.win32_inactive_pause;
  11429. if (!nosound)
  11430. nosound = workprefs.win32_inactive_nosound;
  11431. else
  11432. workprefs.win32_inactive_nosound = true;
  11433. if (!nojoy)
  11434. nojoy = (workprefs.win32_inactive_input & 4) == 0;
  11435. else
  11436. workprefs.win32_inactive_input = 0;
  11437. } else {
  11438. workprefs.win32_inactive_pause = workprefs.win32_inactive_nosound = true;
  11439. workprefs.win32_inactive_input = workprefs.win32_inactive_input = 0;
  11440. nosound = true;
  11441. nojoy = true;
  11442. }
  11443. if (paused)
  11444. CheckDlgButton (hDlg, IDC_MINIMIZED_PAUSE, TRUE);
  11445. if (nosound || paused)
  11446. CheckDlgButton (hDlg, IDC_MINIMIZED_NOSOUND, TRUE);
  11447. if (paused || nojoy)
  11448. CheckDlgButton(hDlg, IDC_MINIMIZED_NOJOY, TRUE);
  11449. ew(hDlg, IDC_MINIMIZED_PAUSE, paused == false);
  11450. ew(hDlg, IDC_MINIMIZED_NOSOUND, nosound == false && paused == false);
  11451. ew(hDlg, IDC_MINIMIZED_NOJOY, nojoy == false && paused == false);
  11452. if (!paused) {
  11453. paused = workprefs.win32_iconified_pause;
  11454. if (!nosound)
  11455. nosound = workprefs.win32_iconified_nosound;
  11456. else
  11457. workprefs.win32_iconified_nosound = true;
  11458. } else {
  11459. workprefs.win32_iconified_pause = workprefs.win32_iconified_nosound = true;
  11460. workprefs.win32_iconified_input = workprefs.win32_iconified_input = 0;
  11461. nosound = true;
  11462. nojoy = true;
  11463. }
  11464. }
  11465. static void misc_kbled (HWND hDlg, int v, int nv)
  11466. {
  11467. const TCHAR *defname = v == IDC_KBLED1 ? _T("(NumLock)") : v == IDC_KBLED2 ? _T("(CapsLock)") : _T("(ScrollLock)");
  11468. SendDlgItemMessage (hDlg, v, CB_RESETCONTENT, 0, 0L);
  11469. SendDlgItemMessage (hDlg, v, CB_ADDSTRING, 0, (LPARAM)defname);
  11470. SendDlgItemMessage (hDlg, v, CB_ADDSTRING, 0, (LPARAM)_T("POWER"));
  11471. SendDlgItemMessage (hDlg, v, CB_ADDSTRING, 0, (LPARAM)_T("DF0"));
  11472. SendDlgItemMessage (hDlg, v, CB_ADDSTRING, 0, (LPARAM)_T("DF1"));
  11473. SendDlgItemMessage (hDlg, v, CB_ADDSTRING, 0, (LPARAM)_T("DF2"));
  11474. SendDlgItemMessage (hDlg, v, CB_ADDSTRING, 0, (LPARAM)_T("DF3"));
  11475. SendDlgItemMessage (hDlg, v, CB_ADDSTRING, 0, (LPARAM)_T("HD"));
  11476. SendDlgItemMessage (hDlg, v, CB_ADDSTRING, 0, (LPARAM)_T("CD"));
  11477. SendDlgItemMessage (hDlg, v, CB_ADDSTRING, 0, (LPARAM)_T("DF*"));
  11478. SendDlgItemMessage (hDlg, v, CB_SETCURSEL, nv, 0);
  11479. }
  11480. static void misc_getkbled (HWND hDlg, int v, int n)
  11481. {
  11482. LRESULT nv = SendDlgItemMessage (hDlg, v, CB_GETCURSEL, 0, 0L);
  11483. if (nv != CB_ERR) {
  11484. workprefs.keyboard_leds[n] = nv;
  11485. misc_kbled (hDlg, v, nv);
  11486. }
  11487. workprefs.keyboard_leds_in_use = (workprefs.keyboard_leds[0] | workprefs.keyboard_leds[1] | workprefs.keyboard_leds[2]) != 0;
  11488. }
  11489. static void misc_getpri (HWND hDlg, int v, int *n)
  11490. {
  11491. LRESULT nv = SendDlgItemMessage (hDlg, v, CB_GETCURSEL, 0, 0L);
  11492. if (nv != CB_ERR)
  11493. *n = nv;
  11494. }
  11495. static void misc_addpri (HWND hDlg, int v, int pri)
  11496. {
  11497. int i;
  11498. DWORD opri = GetPriorityClass (GetCurrentProcess ());
  11499. ew (hDlg, v, !(opri != IDLE_PRIORITY_CLASS && opri != NORMAL_PRIORITY_CLASS && opri != BELOW_NORMAL_PRIORITY_CLASS && opri != ABOVE_NORMAL_PRIORITY_CLASS));
  11500. SendDlgItemMessage (hDlg, v, CB_RESETCONTENT, 0, 0L);
  11501. i = 0;
  11502. while (priorities[i].name) {
  11503. SendDlgItemMessage (hDlg, v, CB_ADDSTRING, 0, (LPARAM)priorities[i].name);
  11504. i++;
  11505. }
  11506. SendDlgItemMessage (hDlg, v, CB_SETCURSEL, pri, 0);
  11507. }
  11508. static void misc_scsi (HWND hDlg)
  11509. {
  11510. TCHAR tmp[MAX_DPATH];
  11511. SendDlgItemMessage (hDlg, IDC_SCSIMODE, CB_RESETCONTENT, 0, 0);
  11512. WIN32GUI_LoadUIString (IDS_SCSI_EMULATION, tmp, sizeof tmp / sizeof (TCHAR));
  11513. SendDlgItemMessage (hDlg, IDC_SCSIMODE, CB_ADDSTRING, 0, (LPARAM)tmp);
  11514. SendDlgItemMessage (hDlg, IDC_SCSIMODE, CB_ADDSTRING, 0, (LPARAM)_T("SPTI"));
  11515. SendDlgItemMessage (hDlg, IDC_SCSIMODE, CB_ADDSTRING, 0, (LPARAM)_T("SPTI + SCSI SCAN"));
  11516. SendDlgItemMessage (hDlg, IDC_SCSIMODE, CB_SETCURSEL, workprefs.win32_uaescsimode, 0);
  11517. }
  11518. static void misc_lang (HWND hDlg)
  11519. {
  11520. int i, idx = 0, cnt = 0, lid;
  11521. WORD langid = -1;
  11522. TCHAR tmp[MAX_DPATH];
  11523. if (regqueryint (NULL, _T("Language"), &lid))
  11524. langid = (WORD)lid;
  11525. WIN32GUI_LoadUIString (IDS_AUTODETECT, tmp, sizeof tmp / sizeof (TCHAR));
  11526. SendDlgItemMessage (hDlg, IDC_LANGUAGE, CB_RESETCONTENT, 0, 0);
  11527. SendDlgItemMessage (hDlg, IDC_LANGUAGE, CB_ADDSTRING, 0, (LPARAM)tmp);
  11528. SendDlgItemMessage (hDlg, IDC_LANGUAGE, CB_ADDSTRING, 0, (LPARAM)_T("English (built-in)"));
  11529. if (langid == 0)
  11530. idx = 1;
  11531. cnt = 2;
  11532. for (i = 0; langs[i].name; i++) {
  11533. HMODULE hm = language_load (langs[i].id);
  11534. if (hm) {
  11535. FreeLibrary (hm);
  11536. SendDlgItemMessage (hDlg, IDC_LANGUAGE, CB_ADDSTRING, 0, (LPARAM)langs[i].name);
  11537. if (langs[i].id == langid)
  11538. idx = cnt;
  11539. cnt++;
  11540. }
  11541. }
  11542. SendDlgItemMessage (hDlg, IDC_LANGUAGE, CB_SETCURSEL, idx, 0);
  11543. SendDlgItemMessage (hDlg, IDC_GUI_SIZE, CB_RESETCONTENT, 0, 0);
  11544. WIN32GUI_LoadUIString (IDS_SELECT_MENU, tmp, sizeof tmp / sizeof (TCHAR));
  11545. SendDlgItemMessage (hDlg, IDC_GUI_SIZE, CB_ADDSTRING, 0, (LPARAM)tmp);
  11546. SendDlgItemMessage (hDlg, IDC_GUI_SIZE, CB_ADDSTRING, 0, (LPARAM)_T("200%"));
  11547. SendDlgItemMessage (hDlg, IDC_GUI_SIZE, CB_ADDSTRING, 0, (LPARAM)_T("190%"));
  11548. SendDlgItemMessage (hDlg, IDC_GUI_SIZE, CB_ADDSTRING, 0, (LPARAM)_T("180%"));
  11549. SendDlgItemMessage (hDlg, IDC_GUI_SIZE, CB_ADDSTRING, 0, (LPARAM)_T("170%"));
  11550. SendDlgItemMessage (hDlg, IDC_GUI_SIZE, CB_ADDSTRING, 0, (LPARAM)_T("160%"));
  11551. SendDlgItemMessage (hDlg, IDC_GUI_SIZE, CB_ADDSTRING, 0, (LPARAM)_T("150%"));
  11552. SendDlgItemMessage (hDlg, IDC_GUI_SIZE, CB_ADDSTRING, 0, (LPARAM)_T("140%"));
  11553. SendDlgItemMessage (hDlg, IDC_GUI_SIZE, CB_ADDSTRING, 0, (LPARAM)_T("130%"));
  11554. SendDlgItemMessage (hDlg, IDC_GUI_SIZE, CB_ADDSTRING, 0, (LPARAM)_T("120%"));
  11555. SendDlgItemMessage (hDlg, IDC_GUI_SIZE, CB_ADDSTRING, 0, (LPARAM)_T("110%"));
  11556. SendDlgItemMessage (hDlg, IDC_GUI_SIZE, CB_ADDSTRING, 0, (LPARAM)_T("100%"));
  11557. SendDlgItemMessage (hDlg, IDC_GUI_SIZE, CB_ADDSTRING, 0, (LPARAM)_T(" 90%"));
  11558. SendDlgItemMessage (hDlg, IDC_GUI_SIZE, CB_ADDSTRING, 0, (LPARAM)_T(" 80%"));
  11559. SendDlgItemMessage (hDlg, IDC_GUI_SIZE, CB_ADDSTRING, 0, (LPARAM)_T(" 70%"));
  11560. SendDlgItemMessage (hDlg, IDC_GUI_SIZE, CB_ADDSTRING, 0, (LPARAM)_T(" 60%"));
  11561. SendDlgItemMessage (hDlg, IDC_GUI_SIZE, CB_SETCURSEL, 0, 0);
  11562. }
  11563. static void misc_setlang (int v)
  11564. {
  11565. int i;
  11566. WORD langid = 0;
  11567. v-=2;
  11568. if (v >= 0) {
  11569. for (i = 0; langs[i].name; i++) {
  11570. HMODULE hm = language_load (langs[i].id);
  11571. if (hm) {
  11572. FreeLibrary(hm);
  11573. if (v == 0) {
  11574. langid = langs[i].id;
  11575. break;
  11576. }
  11577. v--;
  11578. }
  11579. }
  11580. }
  11581. if (v == -2)
  11582. langid = -1;
  11583. regsetint (NULL, _T("Language"), langid);
  11584. FreeLibrary(hUIDLL);
  11585. hUIDLL = NULL;
  11586. if (langid >= 0)
  11587. hUIDLL = language_load(langid);
  11588. restart_requested = 1;
  11589. exit_gui(0);
  11590. }
  11591. static void misc_gui_font (HWND hDlg, int fonttype)
  11592. {
  11593. if (scaleresource_choosefont (hDlg, fonttype))
  11594. gui_size_changed = 10;
  11595. }
  11596. static void values_to_miscdlg_dx(HWND hDlg)
  11597. {
  11598. SendDlgItemMessage(hDlg, IDC_DXMODE_OPTIONS, CB_RESETCONTENT, 0, 0);
  11599. if (workprefs.gfx_api == 0) {
  11600. SendDlgItemMessage(hDlg, IDC_DXMODE_OPTIONS, CB_ADDSTRING, 0, (LPARAM)_T("NonLocalVRAM"));
  11601. SendDlgItemMessage(hDlg, IDC_DXMODE_OPTIONS, CB_ADDSTRING, 0, (LPARAM)_T("DefaultRAM *"));
  11602. SendDlgItemMessage(hDlg, IDC_DXMODE_OPTIONS, CB_ADDSTRING, 0, (LPARAM)_T("LocalVRAM"));
  11603. SendDlgItemMessage(hDlg, IDC_DXMODE_OPTIONS, CB_ADDSTRING, 0, (LPARAM)_T("SystemRAM"));
  11604. SendDlgItemMessage(hDlg, IDC_DXMODE_OPTIONS, CB_SETCURSEL, ddforceram, 0);
  11605. } else if (workprefs.gfx_api >= 2) {
  11606. SendDlgItemMessage(hDlg, IDC_DXMODE_OPTIONS, CB_ADDSTRING, 0, (LPARAM)_T("Hardware D3D11"));
  11607. SendDlgItemMessage(hDlg, IDC_DXMODE_OPTIONS, CB_ADDSTRING, 0, (LPARAM)_T("Software D3D11"));
  11608. SendDlgItemMessage(hDlg, IDC_DXMODE_OPTIONS, CB_SETCURSEL, workprefs.gfx_api_options, 0);
  11609. }
  11610. }
  11611. static void values_to_miscdlg (HWND hDlg)
  11612. {
  11613. TCHAR tmp[MAX_DPATH];
  11614. if (currentpage == MISC1_ID) {
  11615. misc_kbled (hDlg, IDC_KBLED1, workprefs.keyboard_leds[0]);
  11616. misc_kbled (hDlg, IDC_KBLED2, workprefs.keyboard_leds[1]);
  11617. misc_kbled (hDlg, IDC_KBLED3, workprefs.keyboard_leds[2]);
  11618. CheckDlgButton (hDlg, IDC_KBLED_USB, workprefs.win32_kbledmode);
  11619. CheckDlgButton (hDlg, IDC_GUI_RESIZE, gui_resize_enabled);
  11620. CheckDlgButton (hDlg, IDC_GUI_FULLSCREEN, gui_fullscreen > 0);
  11621. ew (hDlg, IDC_GUI_RESIZE, gui_resize_allowed);
  11622. misc_scsi (hDlg);
  11623. misc_lang (hDlg);
  11624. SendDlgItemMessage(hDlg, IDC_DXMODE, CB_RESETCONTENT, 0, 0);
  11625. SendDlgItemMessage(hDlg, IDC_DXMODE, CB_ADDSTRING, 0, (LPARAM)_T("DirectDraw"));
  11626. SendDlgItemMessage(hDlg, IDC_DXMODE, CB_ADDSTRING, 0, (LPARAM)_T("Direct3D 9"));
  11627. SendDlgItemMessage(hDlg, IDC_DXMODE, CB_ADDSTRING, 0, (LPARAM)_T("Direct3D 11"));
  11628. SendDlgItemMessage(hDlg, IDC_DXMODE, CB_ADDSTRING, 0, (LPARAM)_T("Direct3D 11 HDR (experimental)"));
  11629. SendDlgItemMessage(hDlg, IDC_DXMODE, CB_SETCURSEL, workprefs.gfx_api, 0);
  11630. values_to_miscdlg_dx(hDlg);
  11631. SendDlgItemMessage (hDlg, IDC_WINDOWEDMODE, CB_RESETCONTENT, 0, 0);
  11632. WIN32GUI_LoadUIString (IDS_WSTYLE_BORDERLESS, tmp, sizeof tmp / sizeof (TCHAR));
  11633. SendDlgItemMessage (hDlg, IDC_WINDOWEDMODE, CB_ADDSTRING, 0, (LPARAM)tmp);
  11634. WIN32GUI_LoadUIString (IDS_WSTYLE_MINIMAL, tmp, sizeof tmp / sizeof (TCHAR));
  11635. SendDlgItemMessage (hDlg, IDC_WINDOWEDMODE, CB_ADDSTRING, 0, (LPARAM)tmp);
  11636. WIN32GUI_LoadUIString (IDS_WSTYLE_STANDARD, tmp, sizeof tmp / sizeof (TCHAR));
  11637. SendDlgItemMessage (hDlg, IDC_WINDOWEDMODE, CB_ADDSTRING, 0, (LPARAM)tmp);
  11638. WIN32GUI_LoadUIString (IDS_WSTYLE_EXTENDED, tmp, sizeof tmp / sizeof (TCHAR));
  11639. SendDlgItemMessage (hDlg, IDC_WINDOWEDMODE, CB_ADDSTRING, 0, (LPARAM)tmp);
  11640. SendDlgItemMessage (hDlg, IDC_WINDOWEDMODE, CB_SETCURSEL,
  11641. workprefs.win32_borderless ? 0 : (workprefs.win32_statusbar + 1),
  11642. 0);
  11643. } else if (currentpage == MISC2_ID) {
  11644. CheckDlgButton(hDlg, IDC_ACTIVE_PAUSE, workprefs.win32_active_nocapture_pause);
  11645. CheckDlgButton(hDlg, IDC_ACTIVE_NOSOUND, workprefs.win32_active_nocapture_nosound || workprefs.win32_active_nocapture_pause);
  11646. CheckDlgButton(hDlg, IDC_INACTIVE_PAUSE, workprefs.win32_inactive_pause);
  11647. CheckDlgButton(hDlg, IDC_INACTIVE_NOSOUND, workprefs.win32_inactive_nosound || workprefs.win32_inactive_pause);
  11648. CheckDlgButton(hDlg, IDC_INACTIVE_NOJOY, (workprefs.win32_inactive_input & 4) == 0 || workprefs.win32_inactive_pause);
  11649. CheckDlgButton(hDlg, IDC_MINIMIZED_PAUSE, workprefs.win32_iconified_pause);
  11650. CheckDlgButton(hDlg, IDC_MINIMIZED_NOSOUND, workprefs.win32_iconified_nosound || workprefs.win32_iconified_pause);
  11651. CheckDlgButton(hDlg, IDC_MINIMIZED_NOJOY, (workprefs.win32_iconified_input & 4) == 0 || workprefs.win32_iconified_pause);
  11652. misc_addpri(hDlg, IDC_ACTIVE_PRIORITY, workprefs.win32_active_capture_priority);
  11653. misc_addpri(hDlg, IDC_INACTIVE_PRIORITY, workprefs.win32_inactive_priority);
  11654. misc_addpri(hDlg, IDC_MINIMIZED_PRIORITY, workprefs.win32_iconified_priority);
  11655. }
  11656. }
  11657. static void setstatefilename (HWND hDlg)
  11658. {
  11659. TCHAR *s = _tcsrchr (workprefs.statefile, '\\');
  11660. if (s) {
  11661. s++;
  11662. } else {
  11663. s = _tcsrchr (workprefs.statefile, '/');
  11664. if (s)
  11665. s++;
  11666. }
  11667. if (!s)
  11668. s = workprefs.statefile;
  11669. SetDlgItemText (hDlg, IDC_STATENAME, s);
  11670. ew (hDlg, IDC_STATECLEAR, workprefs.statefile[0] != 0);
  11671. setchecked (hDlg, IDC_STATECLEAR, workprefs.statefile[0] != 0);
  11672. }
  11673. static void setdefaultguisize(int skipdpi)
  11674. {
  11675. int dpi = skipdpi ? 96 : getdpiformonitor(NULL);
  11676. gui_width = MulDiv(GUI_INTERNAL_WIDTH, dpi, 96);
  11677. gui_height = MulDiv(GUI_INTERNAL_HEIGHT, dpi, 96);
  11678. int w = GetSystemMetrics(SM_CXVIRTUALSCREEN);
  11679. int h = GetSystemMetrics(SM_CYVIRTUALSCREEN);
  11680. if ((dpi > 96) && (gui_width > w || gui_height > h)) {
  11681. gui_width = w;
  11682. gui_height = h;
  11683. }
  11684. }
  11685. static void saveguisize(void)
  11686. {
  11687. if (gui_fullscreen)
  11688. return;
  11689. if (full_property_sheet || isfullscreen() == 0) {
  11690. regsetint(NULL, _T("GUISizeX"), gui_width);
  11691. regsetint(NULL, _T("GUISizeY"), gui_height);
  11692. } else if (isfullscreen() < 0) {
  11693. regsetint(NULL, _T("GUISizeFWX"), gui_width);
  11694. regsetint(NULL, _T("GUISizeFWY"), gui_height);
  11695. } else if (isfullscreen() > 0) {
  11696. regsetint(NULL, _T("GUISizeFSX"), gui_width);
  11697. regsetint(NULL, _T("GUISizeFSY"), gui_height);
  11698. }
  11699. }
  11700. static void getstoredguisize(void)
  11701. {
  11702. if (full_property_sheet || isfullscreen () == 0) {
  11703. regqueryint(NULL, _T("GUISizeX"), &gui_width);
  11704. regqueryint(NULL, _T("GUISizeY"), &gui_height);
  11705. scaleresource_init(gui_fullscreen ? _T("GFS") : _T(""), gui_fullscreen);
  11706. } else if (isfullscreen () < 0) {
  11707. regqueryint(NULL, _T("GUISizeFWX"), &gui_width);
  11708. regqueryint(NULL, _T("GUISizeFWY"), &gui_height);
  11709. scaleresource_init(gui_fullscreen ? _T("FW_GFS") : _T("FW"), gui_fullscreen);
  11710. } else if (isfullscreen () > 0) {
  11711. regqueryint(NULL, _T("GUISizeFSX"), &gui_width);
  11712. regqueryint(NULL, _T("GUISizeFSY"), &gui_height);
  11713. scaleresource_init(gui_fullscreen ? _T("FS_GFS") : _T("FS"), gui_fullscreen);
  11714. }
  11715. }
  11716. static INT_PTR MiscDlgProc (HWND hDlg, UINT msg, WPARAM wParam, LPARAM lParam)
  11717. {
  11718. int v, i;
  11719. static int recursive;
  11720. TCHAR tmp[MAX_DPATH];
  11721. if (recursive)
  11722. return FALSE;
  11723. recursive++;
  11724. switch (msg)
  11725. {
  11726. case WM_INITDIALOG:
  11727. pages[currentpage] = hDlg;
  11728. InitializeListView (hDlg);
  11729. values_to_miscdlg (hDlg);
  11730. enable_for_miscdlg (hDlg);
  11731. addhistorymenu(hDlg, NULL, IDC_STATENAME, HISTORY_STATEFILE, true, -1);
  11732. setstatefilename(hDlg);
  11733. recursive--;
  11734. return TRUE;
  11735. case WM_USER:
  11736. values_to_miscdlg (hDlg);
  11737. enable_for_miscdlg (hDlg);
  11738. recursive--;
  11739. return TRUE;
  11740. case WM_CONTEXTMENU:
  11741. if (GetDlgCtrlID((HWND)wParam) == IDC_DOSAVESTATE) {
  11742. TCHAR *s = favoritepopup (hDlg);
  11743. if (s) {
  11744. TCHAR path[MAX_DPATH];
  11745. _tcscpy (path, s);
  11746. xfree (s);
  11747. if (DiskSelection(hDlg, wParam, 9, &workprefs, NULL, path))
  11748. save_state (savestate_fname, _T("Description!"));
  11749. }
  11750. } else if (GetDlgCtrlID((HWND)wParam) == IDC_DOLOADSTATE) {
  11751. TCHAR *s = favoritepopup (hDlg);
  11752. if (s) {
  11753. TCHAR path[MAX_DPATH];
  11754. _tcscpy (path, s);
  11755. xfree (s);
  11756. if (DiskSelection(hDlg, wParam, 10, &workprefs, NULL, path))
  11757. savestate_state = STATE_DORESTORE;
  11758. }
  11759. }
  11760. break;
  11761. case WM_NOTIFY:
  11762. if (((LPNMHDR) lParam)->idFrom == IDC_ASSOCIATELIST) {
  11763. int entry, col;
  11764. HWND list;
  11765. NM_LISTVIEW *nmlistview = (NM_LISTVIEW *)lParam;
  11766. list = nmlistview->hdr.hwndFrom;
  11767. if (nmlistview->hdr.code == NM_DBLCLK) {
  11768. entry = listview_entry_from_click (list, &col, false);
  11769. exts[entry].enabled = exts[entry].enabled ? 0 : 1;
  11770. associate_file_extensions ();
  11771. InitializeListView (hDlg);
  11772. }
  11773. } else if (((LPNMHDR) lParam)->idFrom == IDC_MISCLIST) {
  11774. NM_LISTVIEW *nmlistview = (NM_LISTVIEW *)lParam;
  11775. if (nmlistview->hdr.code == LVN_ITEMCHANGED) {
  11776. int item = nmlistview->iItem;
  11777. if (item >= 0) {
  11778. const struct miscentry *me = &misclist[item];
  11779. bool checked = (nmlistview->uNewState & LVIS_STATEIMAGEMASK) == 0x2000;
  11780. if (me->b) {
  11781. *me->b = checked;
  11782. } else if (me->i) {
  11783. *me->i &= ~me->imask;
  11784. if (checked)
  11785. *me->i |= me->ival & me->imask;
  11786. }
  11787. workprefs.input_mouse_untrap &= ~MOUSEUNTRAP_MIDDLEBUTTON;
  11788. if (win32_middle_mouse_obsolete)
  11789. workprefs.input_mouse_untrap |= MOUSEUNTRAP_MIDDLEBUTTON;
  11790. }
  11791. }
  11792. }
  11793. break;
  11794. case WM_COMMAND:
  11795. if (currentpage == MISC1_ID) {
  11796. if (HIWORD (wParam) == CBN_SELENDOK || HIWORD (wParam) == CBN_KILLFOCUS || HIWORD (wParam) == CBN_EDITCHANGE) {
  11797. switch (LOWORD (wParam))
  11798. {
  11799. case IDC_STATENAME:
  11800. if (HIWORD(wParam) != CBN_EDITCHANGE && getcomboboxtext(hDlg, IDC_STATENAME, tmp, sizeof tmp / sizeof(TCHAR))) {
  11801. if (tmp[0]) {
  11802. parsefilepath(tmp, sizeof tmp / sizeof(TCHAR));
  11803. if (_tcscmp(tmp, savestate_fname)) {
  11804. _tcscpy(savestate_fname, tmp);
  11805. savestate_state = STATE_DORESTORE;
  11806. if (!my_existsfile(savestate_fname)) {
  11807. TCHAR t[MAX_DPATH];
  11808. _tcscpy(t, savestate_fname);
  11809. _tcscat(savestate_fname, _T(".uss"));
  11810. if (!my_existsfile(savestate_fname)) {
  11811. fetch_statefilepath(savestate_fname, sizeof(t) / sizeof(MAX_DPATH));
  11812. _tcscat(savestate_fname, t);
  11813. if (!my_existsfile(savestate_fname)) {
  11814. _tcscat(savestate_fname, _T(".uss"));
  11815. if (!my_existsfile(savestate_fname)) {
  11816. _tcscpy(savestate_fname, t);
  11817. }
  11818. }
  11819. }
  11820. }
  11821. _tcscpy(workprefs.statefile, savestate_fname);
  11822. setstatefilename(hDlg);
  11823. }
  11824. }
  11825. }
  11826. break;
  11827. case IDC_KBLED1:
  11828. misc_getkbled (hDlg, IDC_KBLED1, 0);
  11829. break;
  11830. case IDC_KBLED2:
  11831. misc_getkbled (hDlg, IDC_KBLED2, 1);
  11832. break;
  11833. case IDC_KBLED3:
  11834. misc_getkbled (hDlg, IDC_KBLED3, 2);
  11835. break;
  11836. case IDC_LANGUAGE:
  11837. if (HIWORD (wParam) == CBN_SELENDOK) {
  11838. v = SendDlgItemMessage (hDlg, IDC_LANGUAGE, CB_GETCURSEL, 0, 0L);
  11839. if (v != CB_ERR)
  11840. misc_setlang (v);
  11841. }
  11842. break;
  11843. case IDC_DXMODE:
  11844. v = SendDlgItemMessage (hDlg, IDC_DXMODE, CB_GETCURSEL, 0, 0L);
  11845. if (v != CB_ERR) {
  11846. workprefs.gfx_api = v;
  11847. if (full_property_sheet)
  11848. d3d_select(&workprefs);
  11849. enable_for_miscdlg (hDlg);
  11850. values_to_miscdlg_dx(hDlg);
  11851. }
  11852. break;
  11853. case IDC_WINDOWEDMODE:
  11854. v = SendDlgItemMessage (hDlg, IDC_WINDOWEDMODE, CB_GETCURSEL, 0, 0L);
  11855. if (v != CB_ERR) {
  11856. workprefs.win32_borderless = 0;
  11857. workprefs.win32_statusbar = 0;
  11858. if (v == 0)
  11859. workprefs.win32_borderless = 1;
  11860. if (v > 0)
  11861. workprefs.win32_statusbar = v - 1;
  11862. }
  11863. break;
  11864. case IDC_DXMODE_OPTIONS:
  11865. v = SendDlgItemMessage (hDlg, IDC_DXMODE_OPTIONS, CB_GETCURSEL, 0, 0L);
  11866. if (v != CB_ERR) {
  11867. if (workprefs.gfx_api >= 2) {
  11868. workprefs.gfx_api_options = v;
  11869. } else if (!workprefs.gfx_api) {
  11870. ddforceram = v;
  11871. regsetint(NULL, _T("DirectDraw_Secondary"), ddforceram);
  11872. }
  11873. }
  11874. break;
  11875. case IDC_SCSIMODE:
  11876. v = SendDlgItemMessage (hDlg, IDC_SCSIMODE, CB_GETCURSEL, 0, 0L);
  11877. if (v != CB_ERR)
  11878. workprefs.win32_uaescsimode = v;
  11879. break;
  11880. }
  11881. }
  11882. } else if (currentpage == MISC2_ID) {
  11883. misc_getpri (hDlg, IDC_ACTIVE_PRIORITY, &workprefs.win32_active_capture_priority);
  11884. misc_getpri (hDlg, IDC_INACTIVE_PRIORITY, &workprefs.win32_inactive_priority);
  11885. misc_getpri (hDlg, IDC_MINIMIZED_PRIORITY, &workprefs.win32_iconified_priority);
  11886. }
  11887. switch(wParam)
  11888. {
  11889. case IDC_GUI_LVDEFAULT:
  11890. ResetListViews();
  11891. break;
  11892. case IDC_GUI_DEFAULT:
  11893. scaleresource_setdefaults(hDlg);
  11894. v = SendDlgItemMessage (hDlg, IDC_GUI_SIZE, CB_GETCURSEL, 0, 0L);
  11895. if (v != CB_ERR) {
  11896. if (v == 0) {
  11897. v = GUI_SCALE_DEFAULT;
  11898. } else {
  11899. v--;
  11900. v = 200 - v * 10;
  11901. }
  11902. gui_width = (int)(GUI_INTERNAL_WIDTH * v / 100);
  11903. gui_height = (int)(GUI_INTERNAL_HEIGHT * v / 100);
  11904. int dpi = getdpiforwindow(hDlg);
  11905. gui_width = MulDiv(gui_width, dpi, 96);
  11906. gui_height = MulDiv(gui_height, dpi, 96);
  11907. if (gui_width < MIN_GUI_INTERNAL_WIDTH || gui_height < MIN_GUI_INTERNAL_HEIGHT) {
  11908. gui_width = MIN_GUI_INTERNAL_WIDTH;
  11909. gui_height = MIN_GUI_INTERNAL_HEIGHT;
  11910. }
  11911. scaleresource_setsize(gui_width, gui_height, gui_fullscreen);
  11912. gui_size_changed = 10;
  11913. }
  11914. break;
  11915. case IDC_GUI_FONT:
  11916. misc_gui_font (hDlg, 0);
  11917. break;
  11918. case IDC_GUI_RESIZE:
  11919. gui_resize_enabled = ischecked (hDlg, IDC_GUI_RESIZE);
  11920. gui_fullscreen = -1;
  11921. gui_size_changed = 10;
  11922. break;
  11923. case IDC_GUI_FULLSCREEN:
  11924. gui_fullscreen = ischecked (hDlg, IDC_GUI_FULLSCREEN);
  11925. if (!gui_fullscreen) {
  11926. gui_fullscreen = -1;
  11927. getstoredguisize();
  11928. }
  11929. gui_size_changed = 10;
  11930. break;
  11931. case IDC_ASSOCIATE_ON:
  11932. for (i = 0; exts[i].ext; i++)
  11933. exts[i].enabled = 1;
  11934. associate_file_extensions ();
  11935. InitializeListView (hDlg);
  11936. break;
  11937. case IDC_ASSOCIATE_OFF:
  11938. for (i = 0; exts[i].ext; i++)
  11939. exts[i].enabled = 0;
  11940. associate_file_extensions ();
  11941. InitializeListView (hDlg);
  11942. break;
  11943. case IDC_STATECLEAR:
  11944. savestate_initsave (NULL, 0, 0, false);
  11945. _tcscpy (workprefs.statefile, savestate_fname);
  11946. setstatefilename (hDlg);
  11947. break;
  11948. case IDC_DOSAVESTATE:
  11949. workprefs.statefile[0] = 0;
  11950. if (DiskSelection(hDlg, wParam, 9, &workprefs, NULL, NULL)) {
  11951. save_state (savestate_fname, _T("Description!"));
  11952. _tcscpy (workprefs.statefile, savestate_fname);
  11953. }
  11954. setstatefilename (hDlg);
  11955. break;
  11956. case IDC_DOLOADSTATE:
  11957. if (DiskSelection(hDlg, wParam, 10, &workprefs, NULL, NULL))
  11958. savestate_state = STATE_DORESTORE;
  11959. _tcscpy (workprefs.statefile, savestate_fname);
  11960. setstatefilename (hDlg);
  11961. break;
  11962. case IDC_INACTIVE_NOJOY:
  11963. if (!ischecked(hDlg, IDC_INACTIVE_NOJOY))
  11964. CheckDlgButton(hDlg, IDC_INACTIVE_PAUSE, BST_UNCHECKED);
  11965. case IDC_INACTIVE_NOSOUND:
  11966. if (!ischecked(hDlg, IDC_INACTIVE_NOSOUND))
  11967. CheckDlgButton(hDlg, IDC_INACTIVE_PAUSE, BST_UNCHECKED);
  11968. case IDC_INACTIVE_PAUSE:
  11969. workprefs.win32_inactive_pause = ischecked (hDlg, IDC_INACTIVE_PAUSE);
  11970. if (workprefs.win32_inactive_pause) {
  11971. CheckDlgButton(hDlg, IDC_INACTIVE_NOSOUND, BST_CHECKED);
  11972. CheckDlgButton(hDlg, IDC_INACTIVE_NOJOY, BST_CHECKED);
  11973. }
  11974. workprefs.win32_inactive_nosound = ischecked(hDlg, IDC_INACTIVE_NOSOUND);
  11975. workprefs.win32_inactive_input = ischecked(hDlg, IDC_INACTIVE_NOJOY) ? 0 : 4;
  11976. enable_for_miscdlg(hDlg);
  11977. break;
  11978. case IDC_ACTIVE_NOSOUND:
  11979. if (!ischecked (hDlg, IDC_ACTIVE_NOSOUND))
  11980. CheckDlgButton (hDlg, IDC_ACTIVE_PAUSE, BST_UNCHECKED);
  11981. case IDC_ACTIVE_PAUSE:
  11982. workprefs.win32_active_nocapture_pause = ischecked (hDlg, IDC_ACTIVE_PAUSE);
  11983. if (workprefs.win32_active_nocapture_pause)
  11984. CheckDlgButton (hDlg, IDC_ACTIVE_NOSOUND, BST_CHECKED);
  11985. workprefs.win32_active_nocapture_nosound = ischecked (hDlg, IDC_ACTIVE_NOSOUND);
  11986. enable_for_miscdlg (hDlg);
  11987. break;
  11988. case IDC_MINIMIZED_NOJOY:
  11989. if (!ischecked(hDlg, IDC_MINIMIZED_NOJOY))
  11990. CheckDlgButton(hDlg, IDC_MINIMIZED_PAUSE, BST_UNCHECKED);
  11991. case IDC_MINIMIZED_NOSOUND:
  11992. if (!ischecked(hDlg, IDC_MINIMIZED_NOSOUND))
  11993. CheckDlgButton(hDlg, IDC_MINIMIZED_PAUSE, BST_UNCHECKED);
  11994. case IDC_MINIMIZED_PAUSE:
  11995. workprefs.win32_iconified_pause = ischecked (hDlg, IDC_MINIMIZED_PAUSE);
  11996. if (workprefs.win32_iconified_pause) {
  11997. CheckDlgButton(hDlg, IDC_MINIMIZED_NOSOUND, BST_CHECKED);
  11998. CheckDlgButton(hDlg, IDC_MINIMIZED_NOJOY, BST_CHECKED);
  11999. }
  12000. workprefs.win32_iconified_nosound = ischecked(hDlg, IDC_MINIMIZED_NOSOUND);
  12001. workprefs.win32_iconified_input = ischecked(hDlg, IDC_MINIMIZED_NOJOY) ? 0 : 4;
  12002. enable_for_miscdlg(hDlg);
  12003. break;
  12004. case IDC_KBLED_USB:
  12005. workprefs.win32_kbledmode = ischecked (hDlg, IDC_KBLED_USB) ? 1 : 0;
  12006. break;
  12007. }
  12008. recursive--;
  12009. return TRUE;
  12010. }
  12011. recursive--;
  12012. return FALSE;
  12013. }
  12014. static INT_PTR CALLBACK MiscDlgProc1 (HWND hDlg, UINT msg, WPARAM wParam, LPARAM lParam)
  12015. {
  12016. currentpage = MISC1_ID;
  12017. return MiscDlgProc (hDlg, msg, wParam, lParam);
  12018. }
  12019. static INT_PTR CALLBACK MiscDlgProc2 (HWND hDlg, UINT msg, WPARAM wParam, LPARAM lParam)
  12020. {
  12021. currentpage = MISC2_ID;
  12022. return MiscDlgProc (hDlg, msg, wParam, lParam);
  12023. }
  12024. static const int cpu_ids[] = { IDC_CPU0, IDC_CPU1, IDC_CPU2, IDC_CPU3, IDC_CPU4, IDC_CPU5 };
  12025. static const int fpu_ids[] = { IDC_FPU0, IDC_FPU1, IDC_FPU2, IDC_FPU3 };
  12026. static const int trust_ids[] = { IDC_TRUST0, IDC_TRUST1, IDC_TRUST1, IDC_TRUST1 };
  12027. static void enable_for_cpudlg (HWND hDlg)
  12028. {
  12029. BOOL enable = FALSE, jitenable = FALSE;
  12030. BOOL cpu_based_enable = FALSE;
  12031. ew(hDlg, IDC_SPEED, !workprefs.cpu_cycle_exact);
  12032. ew(hDlg, IDC_COMPATIBLE24, workprefs.cpu_model <= 68030);
  12033. //ew(hDlg, IDC_CS_HOST, !workprefs.cpu_cycle_exact);
  12034. //ew(hDlg, IDC_CS_68000, !workprefs.cpu_cycle_exact);
  12035. //ew(hDlg, IDC_CS_ADJUSTABLE, !workprefs.cpu_cycle_exact);
  12036. ew(hDlg, IDC_CPUIDLE, workprefs.m68k_speed != 0 ? TRUE : FALSE);
  12037. ew(hDlg, IDC_PPC_CPUIDLE, workprefs.ppc_mode != 0);
  12038. ew(hDlg, IDC_SPEED_x86, is_x86_cpu(&workprefs));
  12039. ew(hDlg, IDC_CPUTEXT_x86, is_x86_cpu(&workprefs));
  12040. #if !defined(CPUEMU_0) || defined(CPUEMU_68000_ONLY)
  12041. ew(hDlg, IDC_CPU1, FALSE);
  12042. ew(hDlg, IDC_CPU2, FALSE);
  12043. ew(hDlg, IDC_CPU3, FALSE);
  12044. ew(hDlg, IDC_CPU4, FALSE);
  12045. ew(hDlg, IDC_CPU5, FALSE);
  12046. #endif
  12047. cpu_based_enable = workprefs.cpu_model >= 68020 && workprefs.address_space_24 == 0;
  12048. jitenable = cpu_based_enable && !workprefs.mmu_model;
  12049. #ifndef JIT
  12050. jitenable = FALSE;
  12051. #endif
  12052. enable = jitenable && workprefs.cachesize;
  12053. ew(hDlg, IDC_FPU_MODE, workprefs.fpu_model != 0);
  12054. ew(hDlg, IDC_TRUST0, enable);
  12055. ew(hDlg, IDC_TRUST1, enable);
  12056. ew(hDlg, IDC_HARDFLUSH, enable);
  12057. ew(hDlg, IDC_CONSTJUMP, enable);
  12058. ew(hDlg, IDC_JITFPU, enable);
  12059. ew(hDlg, IDC_JITCRASH, enable);
  12060. ew(hDlg, IDC_NOFLAGS, enable);
  12061. ew(hDlg, IDC_CS_CACHE_TEXT, enable);
  12062. ew(hDlg, IDC_CACHE, enable);
  12063. ew(hDlg, IDC_JITENABLE, jitenable);
  12064. ew(hDlg, IDC_COMPATIBLE, !workprefs.cpu_memory_cycle_exact && !(workprefs.cachesize && workprefs.cpu_model >= 68040));
  12065. ew(hDlg, IDC_COMPATIBLE_FPU, workprefs.fpu_model > 0);
  12066. ew(hDlg, IDC_FPU_UNIMPLEMENTED, workprefs.fpu_model && !workprefs.cachesize);
  12067. ew(hDlg, IDC_CPU_UNIMPLEMENTED, workprefs.cpu_model == 68060 && !workprefs.cachesize);
  12068. #if 0
  12069. ew(hDlg, IDC_CPU_MULTIPLIER, workprefs.cpu_cycle_exact);
  12070. #endif
  12071. ew(hDlg, IDC_CPU_FREQUENCY, (workprefs.cpu_cycle_exact || workprefs.cpu_compatible) && workprefs.m68k_speed >= 0);
  12072. ew(hDlg, IDC_CPU_FREQUENCY2, workprefs.cpu_cycle_exact && !workprefs.cpu_clock_multiplier && workprefs.m68k_speed >= 0);
  12073. ew(hDlg, IDC_FPU1, workprefs.cpu_model < 68040 && (workprefs.cpu_model >= 68020 || !workprefs.cpu_compatible));
  12074. ew(hDlg, IDC_FPU2, workprefs.cpu_model < 68040 && (workprefs.cpu_model >= 68020 || !workprefs.cpu_compatible));
  12075. ew(hDlg, IDC_FPU3, workprefs.cpu_model >= 68040);
  12076. ew(hDlg, IDC_MMUENABLEEC, workprefs.cpu_model >= 68030 && workprefs.cachesize == 0);
  12077. ew(hDlg, IDC_MMUENABLE, workprefs.cpu_model >= 68030 && workprefs.cachesize == 0);
  12078. ew(hDlg, IDC_CPUDATACACHE, workprefs.cpu_model >= 68030 && workprefs.cachesize == 0 && workprefs.cpu_compatible);
  12079. ew(hDlg, IDC_CPU_PPC, workprefs.cpu_model >= 68040 && (workprefs.ppc_mode == 1 || (workprefs.ppc_mode == 0 && !is_ppc_cpu(&workprefs))));
  12080. SendDlgItemMessage(hDlg, IDC_SPEED, TBM_SETRANGE, TRUE, workprefs.m68k_speed < 0 || (workprefs.cpu_memory_cycle_exact && !workprefs.cpu_cycle_exact) ? MAKELONG(-9, 0) : MAKELONG(-9, 50));
  12081. SendDlgItemMessage(hDlg, IDC_SPEED, TBM_SETPAGESIZE, 0, 1);
  12082. SendDlgItemMessage(hDlg, IDC_SPEED_x86, TBM_SETRANGE, TRUE, MAKELONG(0, 1000));
  12083. SendDlgItemMessage(hDlg, IDC_SPEED_x86, TBM_SETPAGESIZE, 0, 10);
  12084. }
  12085. static double getcpufreq (int m)
  12086. {
  12087. double f;
  12088. f = workprefs.ntscmode ? 28636360.0 : 28375160.0;
  12089. return f * (m >> 8) / 8.0;
  12090. }
  12091. static void values_to_cpudlg(HWND hDlg, WPARAM wParam)
  12092. {
  12093. TCHAR buffer[8] = _T("");
  12094. int cpu;
  12095. SendDlgItemMessage(hDlg, IDC_SPEED_x86, TBM_SETPOS, TRUE, (int)(workprefs.x86_speed_throttle / 100));
  12096. _stprintf(buffer, _T("%+d%%"), (int)(workprefs.x86_speed_throttle / 10));
  12097. SetDlgItemText(hDlg, IDC_CPUTEXT_x86, buffer);
  12098. SendDlgItemMessage (hDlg, IDC_SPEED, TBM_SETPOS, TRUE, (int)(workprefs.m68k_speed_throttle / 100));
  12099. _stprintf (buffer, _T("%+d%%"), (int)(workprefs.m68k_speed_throttle / 10));
  12100. SetDlgItemText (hDlg, IDC_CPUTEXT, buffer);
  12101. CheckDlgButton (hDlg, IDC_COMPATIBLE, workprefs.cpu_compatible);
  12102. CheckDlgButton (hDlg, IDC_COMPATIBLE24, workprefs.address_space_24);
  12103. CheckDlgButton (hDlg, IDC_CPUDATACACHE, workprefs.cpu_data_cache);
  12104. CheckDlgButton (hDlg, IDC_COMPATIBLE_FPU, workprefs.fpu_strict);
  12105. CheckDlgButton (hDlg, IDC_FPU_UNIMPLEMENTED, !workprefs.fpu_no_unimplemented || workprefs.cachesize);
  12106. SendDlgItemMessage(hDlg, IDC_FPU_MODE, CB_SETCURSEL, workprefs.fpu_mode < 0 ? 1 : (workprefs.fpu_mode > 0 ? 2 : 0), 0);
  12107. CheckDlgButton (hDlg, IDC_CPU_UNIMPLEMENTED, !workprefs.int_no_unimplemented || workprefs.cachesize);
  12108. SendDlgItemMessage (hDlg, IDC_CPUIDLE, TBM_SETPOS, TRUE, workprefs.cpu_idle == 0 ? 0 : 12 - workprefs.cpu_idle / 15);
  12109. _stprintf(buffer, _T("%d%%"), (workprefs.cpu_idle == 0 ? 0 : 12 - workprefs.cpu_idle / 15) * 10);
  12110. SetDlgItemText(hDlg, IDC_CPUIDLETEXT, buffer);
  12111. SendDlgItemMessage (hDlg, IDC_PPC_CPUIDLE, TBM_SETPOS, TRUE, workprefs.ppc_cpu_idle);
  12112. cpu = (workprefs.cpu_model - 68000) / 10;
  12113. if (cpu >= 5)
  12114. cpu--;
  12115. CheckRadioButton (hDlg, IDC_CPU0, IDC_CPU5, cpu_ids[cpu]);
  12116. CheckRadioButton (hDlg, IDC_FPU0, IDC_FPU3, fpu_ids[workprefs.fpu_model == 0 ? 0 : (workprefs.fpu_model == 68881 ? 1 : (workprefs.fpu_model == 68882 ? 2 : 3))]);
  12117. if (workprefs.m68k_speed < 0)
  12118. CheckRadioButton(hDlg, IDC_CS_HOST, IDC_CS_ADJUSTABLE, IDC_CS_HOST);
  12119. else if (workprefs.m68k_speed >= 0)
  12120. CheckRadioButton(hDlg, IDC_CS_HOST, IDC_CS_ADJUSTABLE, IDC_CS_68000);
  12121. CheckRadioButton (hDlg, IDC_TRUST0, IDC_TRUST1, trust_ids[workprefs.comptrustbyte]);
  12122. int idx = 0;
  12123. for (int i = 0; i < MAX_CACHE_SIZE; i++) {
  12124. if (workprefs.cachesize >= (1024 << i) && workprefs.cachesize < (1024 << i) * 2) {
  12125. idx = i + 1;
  12126. break;
  12127. }
  12128. }
  12129. SendDlgItemMessage (hDlg, IDC_CACHE, TBM_SETPOS, TRUE, idx);
  12130. _stprintf (buffer, _T("%d MB"), workprefs.cachesize / 1024 );
  12131. SetDlgItemText (hDlg, IDC_CACHETEXT, buffer);
  12132. CheckDlgButton(hDlg, IDC_JITCRASH, workprefs.comp_catchfault);
  12133. CheckDlgButton(hDlg, IDC_NOFLAGS, workprefs.compnf);
  12134. CheckDlgButton(hDlg, IDC_JITFPU, workprefs.compfpu);
  12135. CheckDlgButton(hDlg, IDC_HARDFLUSH, workprefs.comp_hardflush);
  12136. CheckDlgButton(hDlg, IDC_CONSTJUMP, workprefs.comp_constjump);
  12137. CheckDlgButton(hDlg, IDC_JITENABLE, workprefs.cachesize > 0);
  12138. bool mmu = ((workprefs.cpu_model == 68060 && workprefs.mmu_model == 68060) ||
  12139. (workprefs.cpu_model == 68040 && workprefs.mmu_model == 68040) ||
  12140. (workprefs.cpu_model == 68030 && workprefs.mmu_model == 68030)) &&
  12141. workprefs.cachesize == 0;
  12142. CheckRadioButton (hDlg, IDC_MMUENABLEOFF, IDC_MMUENABLE, mmu == 0 ? IDC_MMUENABLEOFF : (mmu && workprefs.mmu_ec) ? IDC_MMUENABLEEC : IDC_MMUENABLE);
  12143. CheckDlgButton(hDlg, IDC_CPU_PPC, workprefs.ppc_mode || is_ppc_cpu(&workprefs));
  12144. }
  12145. static void values_from_cpudlg(HWND hDlg, WPARAM wParam)
  12146. {
  12147. int newcpu, oldcpu, newfpu, newtrust, oldcache, jitena, idx;
  12148. static int cachesize_prev, trust_prev;
  12149. workprefs.cpu_compatible = workprefs.cpu_memory_cycle_exact | (ischecked (hDlg, IDC_COMPATIBLE) ? 1 : 0);
  12150. workprefs.fpu_strict = ischecked (hDlg, IDC_COMPATIBLE_FPU) ? 1 : 0;
  12151. workprefs.fpu_no_unimplemented = ischecked (hDlg, IDC_FPU_UNIMPLEMENTED) ? 0 : 1;
  12152. workprefs.int_no_unimplemented = ischecked (hDlg, IDC_CPU_UNIMPLEMENTED) ? 0 : 1;
  12153. workprefs.address_space_24 = ischecked (hDlg, IDC_COMPATIBLE24) ? 1 : 0;
  12154. workprefs.m68k_speed = ischecked (hDlg, IDC_CS_HOST) ? -1 : 0;
  12155. workprefs.m68k_speed_throttle = SendMessage (GetDlgItem (hDlg, IDC_SPEED), TBM_GETPOS, 0, 0) * 100;
  12156. if (workprefs.m68k_speed_throttle > 0 && workprefs.m68k_speed < 0)
  12157. workprefs.m68k_speed_throttle = 0;
  12158. workprefs.x86_speed_throttle = SendMessage(GetDlgItem(hDlg, IDC_SPEED_x86), TBM_GETPOS, 0, 0) * 100;
  12159. idx = SendDlgItemMessage(hDlg, IDC_FPU_MODE, CB_GETCURSEL, 0, 0);
  12160. if (idx == 0)
  12161. workprefs.fpu_mode = 0;
  12162. if (idx == 1)
  12163. workprefs.fpu_mode = -1;
  12164. if (idx == 2)
  12165. workprefs.fpu_mode = 1;
  12166. newcpu = ischecked (hDlg, IDC_CPU0) ? 68000
  12167. : ischecked (hDlg, IDC_CPU1) ? 68010
  12168. : ischecked (hDlg, IDC_CPU2) ? 68020
  12169. : ischecked (hDlg, IDC_CPU3) ? 68030
  12170. : ischecked (hDlg, IDC_CPU4) ? 68040
  12171. : ischecked (hDlg, IDC_CPU5) ? 68060 : 0;
  12172. newfpu = ischecked (hDlg, IDC_FPU0) ? 0
  12173. : ischecked (hDlg, IDC_FPU1) ? 1
  12174. : ischecked (hDlg, IDC_FPU2) ? 2
  12175. : ischecked (hDlg, IDC_FPU3) ? 3 : 0;
  12176. /* When switching away from 68000, disable 24 bit addressing. */
  12177. oldcpu = workprefs.cpu_model;
  12178. if (workprefs.cpu_model != newcpu && newcpu <= 68010)
  12179. newfpu = 0;
  12180. workprefs.cpu_model = newcpu;
  12181. workprefs.mmu_model = 0;
  12182. workprefs.mmu_ec = false;
  12183. workprefs.cpu_data_cache = false;
  12184. switch(newcpu)
  12185. {
  12186. case 68000:
  12187. case 68010:
  12188. workprefs.fpu_model = newfpu == 0 ? 0 : (newfpu == 2 ? 68882 : 68881);
  12189. if (workprefs.cpu_compatible || workprefs.cpu_memory_cycle_exact)
  12190. workprefs.fpu_model = 0;
  12191. if (newcpu != oldcpu)
  12192. workprefs.address_space_24 = 1;
  12193. break;
  12194. case 68020:
  12195. workprefs.fpu_model = newfpu == 0 ? 0 : (newfpu == 2 ? 68882 : 68881);
  12196. break;
  12197. case 68030:
  12198. if (newcpu != oldcpu)
  12199. workprefs.address_space_24 = 0;
  12200. workprefs.fpu_model = newfpu == 0 ? 0 : (newfpu == 2 ? 68882 : 68881);
  12201. workprefs.mmu_ec = ischecked(hDlg, IDC_MMUENABLEEC);
  12202. workprefs.mmu_model = workprefs.mmu_ec || ischecked (hDlg, IDC_MMUENABLE) ? 68030 : 0;
  12203. if (workprefs.cpu_compatible)
  12204. workprefs.cpu_data_cache = ischecked (hDlg, IDC_CPUDATACACHE);
  12205. break;
  12206. case 68040:
  12207. workprefs.fpu_model = newfpu ? 68040 : 0;
  12208. workprefs.address_space_24 = 0;
  12209. if (workprefs.fpu_model)
  12210. workprefs.fpu_model = 68040;
  12211. workprefs.mmu_ec = ischecked(hDlg, IDC_MMUENABLEEC);
  12212. workprefs.mmu_model = workprefs.mmu_ec || ischecked (hDlg, IDC_MMUENABLE) ? 68040 : 0;
  12213. if (workprefs.cpu_compatible)
  12214. workprefs.cpu_data_cache = ischecked (hDlg, IDC_CPUDATACACHE);
  12215. break;
  12216. case 68060:
  12217. workprefs.fpu_model = newfpu ? 68060 : 0;
  12218. workprefs.address_space_24 = 0;
  12219. workprefs.mmu_ec = ischecked(hDlg, IDC_MMUENABLEEC);
  12220. workprefs.mmu_model = workprefs.mmu_ec || ischecked (hDlg, IDC_MMUENABLE) ? 68060 : 0;
  12221. if (workprefs.cpu_compatible)
  12222. workprefs.cpu_data_cache = ischecked (hDlg, IDC_CPUDATACACHE);
  12223. break;
  12224. }
  12225. if (newcpu != oldcpu && workprefs.cpu_compatible) {
  12226. int idx = 0;
  12227. if (newcpu <= 68010) {
  12228. workprefs.cpu_clock_multiplier = 2 * 256;
  12229. idx = 1;
  12230. } else if (newcpu == 68020) {
  12231. workprefs.cpu_clock_multiplier = 4 * 256;
  12232. idx = 2;
  12233. } else {
  12234. workprefs.cpu_clock_multiplier = 8 * 256;
  12235. idx = 3;
  12236. }
  12237. SendDlgItemMessage(hDlg, IDC_CPU_FREQUENCY, CB_SETCURSEL, idx, 0);
  12238. }
  12239. newtrust = ischecked (hDlg, IDC_TRUST0) ? 0 : 1;
  12240. workprefs.comptrustbyte = newtrust;
  12241. workprefs.comptrustword = newtrust;
  12242. workprefs.comptrustlong = newtrust;
  12243. workprefs.comptrustnaddr= newtrust;
  12244. workprefs.comp_catchfault = ischecked(hDlg, IDC_JITCRASH);
  12245. workprefs.compnf = ischecked(hDlg, IDC_NOFLAGS);
  12246. workprefs.compfpu = ischecked(hDlg, IDC_JITFPU);
  12247. workprefs.comp_hardflush = ischecked(hDlg, IDC_HARDFLUSH);
  12248. workprefs.comp_constjump = ischecked(hDlg, IDC_CONSTJUMP);
  12249. #ifdef JIT
  12250. oldcache = workprefs.cachesize;
  12251. jitena = (ischecked (hDlg, IDC_JITENABLE) ? 1 : 0) && !workprefs.address_space_24 && workprefs.cpu_model >= 68020;
  12252. idx = SendMessage (GetDlgItem (hDlg, IDC_CACHE), TBM_GETPOS, 0, 0);
  12253. workprefs.cachesize = 1024 << idx;
  12254. if (workprefs.cachesize <= 1024)
  12255. workprefs.cachesize = 0;
  12256. else
  12257. workprefs.cachesize /= 2;
  12258. if (!jitena) {
  12259. cachesize_prev = workprefs.cachesize;
  12260. trust_prev = workprefs.comptrustbyte;
  12261. workprefs.cachesize = 0;
  12262. } else if (jitena && !oldcache) {
  12263. workprefs.cachesize = MAX_JIT_CACHE;
  12264. workprefs.cpu_cycle_exact = false;
  12265. workprefs.cpu_memory_cycle_exact = false;
  12266. if (!cachesize_prev)
  12267. trust_prev = 0;
  12268. if (cachesize_prev) {
  12269. workprefs.cachesize = cachesize_prev;
  12270. }
  12271. workprefs.comptrustbyte = trust_prev;
  12272. workprefs.comptrustword = trust_prev;
  12273. workprefs.comptrustlong = trust_prev;
  12274. workprefs.comptrustnaddr = trust_prev;
  12275. if (workprefs.fpu_mode > 0) {
  12276. workprefs.compfpu = false;
  12277. setchecked(hDlg, IDC_JITFPU, false);
  12278. }
  12279. }
  12280. if (!workprefs.cachesize) {
  12281. setchecked (hDlg, IDC_JITENABLE, false);
  12282. }
  12283. if (workprefs.cachesize && workprefs.compfpu && workprefs.fpu_mode > 0) {
  12284. workprefs.fpu_mode = 0;
  12285. SendDlgItemMessage(hDlg, IDC_FPU_MODE, CB_SETCURSEL, 0, 0);
  12286. }
  12287. if (oldcache == 0 && workprefs.cachesize > 0) {
  12288. canbang = 1;
  12289. }
  12290. if (workprefs.cachesize && workprefs.cpu_model >= 68040) {
  12291. workprefs.cpu_compatible = false;
  12292. }
  12293. #endif
  12294. if (ischecked(hDlg, IDC_CPU_PPC)) {
  12295. if (workprefs.ppc_mode == 0)
  12296. workprefs.ppc_mode = 1;
  12297. if (workprefs.ppc_mode == 1 && workprefs.cpu_model < 68040)
  12298. workprefs.ppc_mode = 0;
  12299. } else if (!ischecked(hDlg, IDC_CPU_PPC) && workprefs.ppc_mode == 1) {
  12300. workprefs.ppc_mode = 0;
  12301. }
  12302. workprefs.cpu_idle = SendMessage (GetDlgItem (hDlg, IDC_CPUIDLE), TBM_GETPOS, 0, 0);
  12303. if (workprefs.cpu_idle > 0)
  12304. workprefs.cpu_idle = (12 - workprefs.cpu_idle) * 15;
  12305. workprefs.ppc_cpu_idle = SendMessage (GetDlgItem (hDlg, IDC_PPC_CPUIDLE), TBM_GETPOS, 0, 0);
  12306. if (pages[KICKSTART_ID])
  12307. SendMessage (pages[KICKSTART_ID], WM_USER, 0, 0);
  12308. if (pages[DISPLAY_ID])
  12309. SendMessage (pages[DISPLAY_ID], WM_USER, 0, 0);
  12310. if (pages[MEMORY_ID])
  12311. SendMessage (pages[MEMORY_ID], WM_USER, 0, 0);
  12312. idx = SendDlgItemMessage(hDlg, IDC_CPU_FREQUENCY, CB_GETCURSEL, 0, 0);
  12313. if (idx != CB_ERR) {
  12314. int m = workprefs.cpu_clock_multiplier;
  12315. workprefs.cpu_frequency = 0;
  12316. workprefs.cpu_clock_multiplier = 0;
  12317. if (idx < 4) {
  12318. workprefs.cpu_clock_multiplier = (1 << 8) << idx;
  12319. if (workprefs.cpu_cycle_exact || workprefs.cpu_compatible) {
  12320. TCHAR txt[20];
  12321. double f = getcpufreq(workprefs.cpu_clock_multiplier);
  12322. _stprintf(txt, _T("%.6f"), f / 1000000.0);
  12323. SendDlgItemMessage(hDlg, IDC_CPU_FREQUENCY2, WM_SETTEXT, 0, (LPARAM)txt);
  12324. } else {
  12325. SendDlgItemMessage(hDlg, IDC_CPU_FREQUENCY2, WM_SETTEXT, 0, (LPARAM)_T(""));
  12326. }
  12327. } else if (workprefs.cpu_cycle_exact) {
  12328. TCHAR txt[20];
  12329. txt[0] = 0;
  12330. SendDlgItemMessage(hDlg, IDC_CPU_FREQUENCY2, WM_GETTEXT, (WPARAM)sizeof(txt) / sizeof(TCHAR), (LPARAM)txt);
  12331. workprefs.cpu_clock_multiplier = 0;
  12332. workprefs.cpu_frequency = (int)(_tstof(txt) * 1000000.0);
  12333. if (workprefs.cpu_frequency < 1 * 1000000)
  12334. workprefs.cpu_frequency = 0;
  12335. if (workprefs.cpu_frequency >= 99 * 1000000)
  12336. workprefs.cpu_frequency = 0;
  12337. if (!workprefs.cpu_frequency) {
  12338. workprefs.cpu_frequency = (int)(getcpufreq(m) * 1000000.0);
  12339. }
  12340. }
  12341. }
  12342. }
  12343. static INT_PTR CALLBACK CPUDlgProc (HWND hDlg, UINT msg, WPARAM wParam, LPARAM lParam)
  12344. {
  12345. static int recursive = 0;
  12346. int idx;
  12347. if (dialog_inhibit)
  12348. return 0;
  12349. switch (msg) {
  12350. case WM_INITDIALOG:
  12351. recursive++;
  12352. pages[CPU_ID] = hDlg;
  12353. currentpage = CPU_ID;
  12354. SendDlgItemMessage (hDlg, IDC_CACHE, TBM_SETRANGE, TRUE, MAKELONG (MIN_CACHE_SIZE, MAX_CACHE_SIZE));
  12355. SendDlgItemMessage (hDlg, IDC_CACHE, TBM_SETPAGESIZE, 0, 1);
  12356. SendDlgItemMessage (hDlg, IDC_CPUIDLE, TBM_SETRANGE, TRUE, MAKELONG (0, 10));
  12357. SendDlgItemMessage (hDlg, IDC_CPUIDLE, TBM_SETPAGESIZE, 0, 1);
  12358. SendDlgItemMessage (hDlg, IDC_PPC_CPUIDLE, TBM_SETRANGE, TRUE, MAKELONG (0, 10));
  12359. SendDlgItemMessage (hDlg, IDC_PPC_CPUIDLE, TBM_SETPAGESIZE, 0, 1);
  12360. SendDlgItemMessage (hDlg, IDC_CPU_FREQUENCY, CB_RESETCONTENT, 0, 0);
  12361. SendDlgItemMessage (hDlg, IDC_CPU_FREQUENCY, CB_ADDSTRING, 0, (LPARAM)_T("1x"));
  12362. SendDlgItemMessage (hDlg, IDC_CPU_FREQUENCY, CB_ADDSTRING, 0, (LPARAM)_T("2x (A500)"));
  12363. SendDlgItemMessage (hDlg, IDC_CPU_FREQUENCY, CB_ADDSTRING, 0, (LPARAM)_T("4x (A1200)"));
  12364. SendDlgItemMessage (hDlg, IDC_CPU_FREQUENCY, CB_ADDSTRING, 0, (LPARAM)_T("8x"));
  12365. if (workprefs.cpu_cycle_exact) {
  12366. SendDlgItemMessage(hDlg, IDC_CPU_FREQUENCY, CB_ADDSTRING, 0, (LPARAM)_T("Custom"));
  12367. }
  12368. SendDlgItemMessage(hDlg, IDC_FPU_MODE, CB_RESETCONTENT, 0, 0);
  12369. SendDlgItemMessage(hDlg, IDC_FPU_MODE, CB_ADDSTRING, 0, (LPARAM)_T("Host (64-bit)"));
  12370. SendDlgItemMessage(hDlg, IDC_FPU_MODE, CB_ADDSTRING, 0, (LPARAM)_T("Host (80-bit)"));
  12371. SendDlgItemMessage(hDlg, IDC_FPU_MODE, CB_ADDSTRING, 0, (LPARAM)_T("Softfloat (80-bit)"));
  12372. idx = 4;
  12373. if (workprefs.cpu_clock_multiplier >= 1 << 8) {
  12374. idx = 0;
  12375. while (idx < 3) {
  12376. if (workprefs.cpu_clock_multiplier <= (1 << 8) << idx)
  12377. break;
  12378. idx++;
  12379. }
  12380. } else if (workprefs.cpu_clock_multiplier == 0 && workprefs.cpu_frequency == 0 && workprefs.cpu_model <= 68010) {
  12381. idx = 1; // A500
  12382. } else if (workprefs.cpu_clock_multiplier == 0 && workprefs.cpu_frequency == 0 && workprefs.cpu_model >= 68020) {
  12383. idx = 2; // A1200
  12384. }
  12385. if (!workprefs.cpu_cycle_exact) {
  12386. workprefs.cpu_frequency = 0;
  12387. if (!workprefs.cpu_clock_multiplier && (idx == 1 || idx == 2)) {
  12388. workprefs.cpu_clock_multiplier = (1 << idx) << 8;
  12389. }
  12390. } else {
  12391. if (!workprefs.cpu_frequency && (idx == 1 || idx == 2)) {
  12392. workprefs.cpu_clock_multiplier = (1 << idx) << 8;
  12393. }
  12394. }
  12395. SendDlgItemMessage (hDlg, IDC_CPU_FREQUENCY, CB_SETCURSEL, idx, 0);
  12396. if (!workprefs.cpu_clock_multiplier) {
  12397. TCHAR txt[20];
  12398. _stprintf (txt, _T("%.6f"), workprefs.cpu_frequency / 1000000.0);
  12399. SendDlgItemMessage (hDlg, IDC_CPU_FREQUENCY2, WM_SETTEXT, 0, (LPARAM)txt);
  12400. } else {
  12401. TCHAR txt[20];
  12402. double f = getcpufreq(workprefs.cpu_clock_multiplier);
  12403. _stprintf(txt, _T("%.6f"), f / 1000000.0);
  12404. SendDlgItemMessage(hDlg, IDC_CPU_FREQUENCY2, WM_SETTEXT, 0, (LPARAM)txt);
  12405. }
  12406. recursive--;
  12407. case WM_USER:
  12408. recursive++;
  12409. enable_for_cpudlg (hDlg);
  12410. values_to_cpudlg (hDlg, wParam);
  12411. recursive--;
  12412. return TRUE;
  12413. case WM_COMMAND:
  12414. if (recursive > 0)
  12415. break;
  12416. if (currentpage == CPU_ID) {
  12417. recursive++;
  12418. values_from_cpudlg(hDlg, wParam);
  12419. enable_for_cpudlg(hDlg);
  12420. values_to_cpudlg(hDlg, wParam);
  12421. recursive--;
  12422. }
  12423. break;
  12424. case WM_HSCROLL:
  12425. if (currentpage == CPU_ID) {
  12426. recursive++;
  12427. values_from_cpudlg(hDlg, wParam);
  12428. enable_for_cpudlg(hDlg);
  12429. values_to_cpudlg(hDlg, wParam);
  12430. recursive--;
  12431. }
  12432. break;
  12433. }
  12434. return FALSE;
  12435. }
  12436. static void enable_for_sounddlg (HWND hDlg)
  12437. {
  12438. int numdevs;
  12439. numdevs = enumerate_sound_devices ();
  12440. if (numdevs == 0)
  12441. ew (hDlg, IDC_SOUNDCARDLIST, FALSE);
  12442. else
  12443. ew (hDlg, IDC_SOUNDCARDLIST, workprefs.produce_sound);
  12444. ew (hDlg, IDC_FREQUENCY, workprefs.produce_sound);
  12445. ew (hDlg, IDC_SOUNDFREQ, workprefs.produce_sound ? TRUE : FALSE);
  12446. ew (hDlg, IDC_SOUNDSTEREO, workprefs.produce_sound);
  12447. ew (hDlg, IDC_SOUNDINTERPOLATION, workprefs.produce_sound);
  12448. ew (hDlg, IDC_SOUNDVOLUME, workprefs.produce_sound);
  12449. ew (hDlg, IDC_SOUNDVOLUME2, workprefs.produce_sound);
  12450. ew (hDlg, IDC_SOUNDVOLUMEEXT, workprefs.produce_sound);
  12451. ew (hDlg, IDC_SOUNDVOLUMEEXT2, workprefs.produce_sound);
  12452. ew (hDlg, IDC_SOUNDSTEREOSEP, workprefs.sound_stereo > 0 && workprefs.produce_sound);
  12453. ew (hDlg, IDC_SOUNDSTEREOMIX, workprefs.sound_stereo > 0 && workprefs.produce_sound);
  12454. ew (hDlg, IDC_SOUNDBUFFERMEM, workprefs.produce_sound);
  12455. ew (hDlg, IDC_SOUNDBUFFERRAM, workprefs.produce_sound);
  12456. ew (hDlg, IDC_SOUNDADJUST, workprefs.produce_sound);
  12457. ew (hDlg, IDC_SOUNDADJUSTNUM, workprefs.produce_sound);
  12458. ew (hDlg, IDC_SOUNDBUFFERTEXT, workprefs.produce_sound);
  12459. ew (hDlg, IDC_SOUNDDRIVE, workprefs.produce_sound);
  12460. ew (hDlg, IDC_SOUNDDRIVESELECT, workprefs.produce_sound);
  12461. ew (hDlg, IDC_SOUNDDRIVEVOLUME, workprefs.produce_sound);
  12462. ew (hDlg, IDC_SOUNDDRIVEVOLUME2, workprefs.produce_sound);
  12463. ew (hDlg, IDC_SOUNDDRIVEVOLUMEX, workprefs.produce_sound);
  12464. ew (hDlg, IDC_SOUNDDRIVEVOLUMEX2, workprefs.produce_sound);
  12465. ew (hDlg, IDC_AUDIOSYNC, workprefs.produce_sound);
  12466. ew (hDlg, IDC_SOUNDFILTER, workprefs.produce_sound);
  12467. ew (hDlg, IDC_SOUNDSWAP, workprefs.produce_sound);
  12468. ew (hDlg, IDC_SOUNDCALIBRATE, workprefs.produce_sound && full_property_sheet);
  12469. }
  12470. static int exact_log2 (int v)
  12471. {
  12472. int l = 0;
  12473. while ((v >>= 1) != 0)
  12474. l++;
  12475. return l;
  12476. }
  12477. static TCHAR *drivesounds;
  12478. static void sound_loaddrivesamples (void)
  12479. {
  12480. WIN32_FIND_DATA fd;
  12481. HANDLE h;
  12482. TCHAR *p;
  12483. int len = 0;
  12484. TCHAR dirname[1024];
  12485. free (drivesounds);
  12486. p = drivesounds = 0;
  12487. get_plugin_path (dirname, sizeof dirname / sizeof (TCHAR), _T("floppysounds"));
  12488. _tcscat (dirname, _T("*.wav"));
  12489. h = FindFirstFile (dirname, &fd);
  12490. if (h == INVALID_HANDLE_VALUE)
  12491. return;
  12492. for (;;) {
  12493. if (!(fd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)) {
  12494. TCHAR *name = fd.cFileName;
  12495. if (_tcslen (name) > _tcslen (DS_NAME_CLICK) + 4 && !_tcsncmp (name, DS_NAME_CLICK, _tcslen (DS_NAME_CLICK))) {
  12496. if (p - drivesounds < 1000) {
  12497. TCHAR *oldp = p;
  12498. len += 2000;
  12499. drivesounds = p = xrealloc (TCHAR, drivesounds, len);
  12500. if (oldp) {
  12501. do {
  12502. p = p + _tcslen (p) + 1;
  12503. } while (p[0]);
  12504. }
  12505. }
  12506. _tcscpy (p, name + _tcslen (DS_NAME_CLICK));
  12507. p[_tcslen (name + _tcslen (DS_NAME_CLICK)) - 4] = 0;
  12508. p += _tcslen (p);
  12509. *p++ = 0;
  12510. *p = 0;
  12511. }
  12512. }
  12513. if (!FindNextFile (h, &fd))
  12514. break;
  12515. }
  12516. FindClose (h);
  12517. }
  12518. extern int soundpercent;
  12519. static const int sndbufsizes[] = { 1024, 2048, 3072, 4096, 6144, 8192, 12288, 16384, 32768, 65536, -1 };
  12520. static int *volumeselection, volumeselectionindex;
  12521. static int sounddrivesel;
  12522. static int getsoundbufsizeindex (int size)
  12523. {
  12524. int idx;
  12525. if (size < sndbufsizes[0])
  12526. return 0;
  12527. for (idx = 0; sndbufsizes[idx] < size && sndbufsizes[idx + 1] >= 0 ; idx++);
  12528. return idx + 1;
  12529. }
  12530. static void update_soundgui (HWND hDlg)
  12531. {
  12532. int bufsize;
  12533. TCHAR txt[20];
  12534. bufsize = getsoundbufsizeindex (workprefs.sound_maxbsiz);
  12535. if (bufsize <= 0) {
  12536. _tcscpy(txt, _T("Min"));
  12537. } else {
  12538. _stprintf (txt, _T("%d"), bufsize);
  12539. }
  12540. SetDlgItemText (hDlg, IDC_SOUNDBUFFERMEM, txt);
  12541. SendDlgItemMessage (hDlg, IDC_SOUNDVOLUME, TBM_SETPOS, TRUE, 100 - workprefs.sound_volume_master);
  12542. _stprintf (txt, _T("%d%%"), 100 - workprefs.sound_volume_master);
  12543. SetDlgItemText (hDlg, IDC_SOUNDVOLUME2, txt);
  12544. SendDlgItemMessage (hDlg, IDC_SOUNDVOLUMEEXT, TBM_SETPOS, TRUE, 100 - (*volumeselection));
  12545. _stprintf (txt, _T("%d%%"), 100 - (*volumeselection));
  12546. SetDlgItemText (hDlg, IDC_SOUNDVOLUMEEXT2, txt);
  12547. SendDlgItemMessage (hDlg, IDC_SOUNDDRIVEVOLUME, TBM_SETPOS, TRUE, 100 - workprefs.dfxclickvolume_empty[sounddrivesel]);
  12548. _stprintf (txt, _T("%d%%"), 100 - workprefs.dfxclickvolume_empty[sounddrivesel]);
  12549. SetDlgItemText (hDlg, IDC_SOUNDDRIVEVOLUME2, txt);
  12550. SendDlgItemMessage (hDlg, IDC_SOUNDDRIVEVOLUMEX, TBM_SETPOS, TRUE, 100 - workprefs.dfxclickvolume_disk[sounddrivesel]);
  12551. _stprintf (txt, _T("%d%%"), 100 - workprefs.dfxclickvolume_disk[sounddrivesel]);
  12552. SetDlgItemText (hDlg, IDC_SOUNDDRIVEVOLUMEX2, txt);
  12553. }
  12554. static int soundfreqs[] = { 11025, 15000, 22050, 32000, 44100, 48000, 0 };
  12555. static int sounddrivers[] = { IDC_SOUND_DS, IDC_SOUND_WASAPI, IDC_SOUND_OPENAL, IDC_SOUND_PORTAUDIO, 0 };
  12556. static void values_to_sounddlg (HWND hDlg)
  12557. {
  12558. int which_button;
  12559. int sound_freq = workprefs.sound_freq;
  12560. int produce_sound = workprefs.produce_sound;
  12561. int stereo = workprefs.sound_stereo;
  12562. TCHAR txt[100], txt2[100], *p;
  12563. int i, selected;
  12564. SendDlgItemMessage (hDlg, IDC_SOUNDFILTER, CB_RESETCONTENT, 0, 0);
  12565. WIN32GUI_LoadUIString (IDS_SOUND_FILTER_OFF, txt, sizeof (txt) / sizeof (TCHAR));
  12566. SendDlgItemMessage (hDlg, IDC_SOUNDFILTER, CB_ADDSTRING, 0, (LPARAM)txt);
  12567. WIN32GUI_LoadUIString (IDS_SOUND_FILTER_EMULATED, txt, sizeof (txt) / sizeof (TCHAR));
  12568. SendDlgItemMessage (hDlg, IDC_SOUNDFILTER, CB_ADDSTRING, 0, (LPARAM)txt);
  12569. WIN32GUI_LoadUIString (IDS_SOUND_FILTER_EMULATED_E, txt, sizeof (txt) / sizeof (TCHAR));
  12570. SendDlgItemMessage (hDlg, IDC_SOUNDFILTER, CB_ADDSTRING, 0, (LPARAM)txt);
  12571. WIN32GUI_LoadUIString (IDS_SOUND_FILTER_ON_AGA, txt, sizeof (txt) / sizeof (TCHAR));
  12572. SendDlgItemMessage (hDlg, IDC_SOUNDFILTER, CB_ADDSTRING, 0, (LPARAM)txt);
  12573. WIN32GUI_LoadUIString (IDS_SOUND_FILTER_ON_A500, txt, sizeof (txt) / sizeof (TCHAR));
  12574. SendDlgItemMessage (hDlg, IDC_SOUNDFILTER, CB_ADDSTRING, 0, (LPARAM)txt);
  12575. i = 0;
  12576. switch (workprefs.sound_filter)
  12577. {
  12578. case 0:
  12579. i = 0;
  12580. break;
  12581. case 1:
  12582. i = workprefs.sound_filter_type ? 2 : 1;
  12583. break;
  12584. case 2:
  12585. i = workprefs.sound_filter_type ? 4 : 3;
  12586. break;
  12587. }
  12588. SendDlgItemMessage (hDlg, IDC_SOUNDFILTER, CB_SETCURSEL, i, 0);
  12589. SendDlgItemMessage (hDlg, IDC_SOUNDSTEREO, CB_RESETCONTENT, 0, 0);
  12590. WIN32GUI_LoadUIString (IDS_SOUND_MONO, txt, sizeof (txt) / sizeof (TCHAR));
  12591. SendDlgItemMessage (hDlg, IDC_SOUNDSTEREO, CB_ADDSTRING, 0, (LPARAM)txt);
  12592. WIN32GUI_LoadUIString (IDS_SOUND_STEREO, txt, sizeof (txt) / sizeof (TCHAR));
  12593. SendDlgItemMessage (hDlg, IDC_SOUNDSTEREO, CB_ADDSTRING, 0, (LPARAM)txt);
  12594. WIN32GUI_LoadUIString (IDS_SOUND_STEREO2, txt, sizeof (txt) / sizeof (TCHAR));
  12595. SendDlgItemMessage (hDlg, IDC_SOUNDSTEREO, CB_ADDSTRING, 0, (LPARAM)txt);
  12596. WIN32GUI_LoadUIString (IDS_SOUND_4CHANNEL, txt, sizeof (txt) / sizeof (TCHAR));
  12597. SendDlgItemMessage (hDlg, IDC_SOUNDSTEREO, CB_ADDSTRING, 0, (LPARAM)txt);
  12598. WIN32GUI_LoadUIString (IDS_SOUND_CLONED51, txt, sizeof (txt) / sizeof (TCHAR));
  12599. SendDlgItemMessage (hDlg, IDC_SOUNDSTEREO, CB_ADDSTRING, 0, (LPARAM)txt);
  12600. WIN32GUI_LoadUIString (IDS_SOUND_51, txt, sizeof (txt) / sizeof (TCHAR));
  12601. SendDlgItemMessage (hDlg, IDC_SOUNDSTEREO, CB_ADDSTRING, 0, (LPARAM)txt);
  12602. SendDlgItemMessage (hDlg, IDC_SOUNDSTEREO, CB_SETCURSEL, workprefs.sound_stereo, 0);
  12603. SendDlgItemMessage (hDlg, IDC_SOUNDSWAP, CB_RESETCONTENT, 0, 0);
  12604. SendDlgItemMessage (hDlg, IDC_SOUNDSWAP, CB_ADDSTRING, 0, (LPARAM)_T("-"));
  12605. WIN32GUI_LoadUIString (IDS_SOUND_SWAP_PAULA, txt, sizeof (txt) / sizeof (TCHAR));
  12606. SendDlgItemMessage (hDlg, IDC_SOUNDSWAP, CB_ADDSTRING, 0, (LPARAM)txt);
  12607. WIN32GUI_LoadUIString (IDS_SOUND_SWAP_AHI, txt, sizeof (txt) / sizeof (TCHAR));
  12608. SendDlgItemMessage (hDlg, IDC_SOUNDSWAP, CB_ADDSTRING, 0, (LPARAM)txt);
  12609. WIN32GUI_LoadUIString (IDS_SOUND_SWAP_BOTH, txt, sizeof (txt) / sizeof (TCHAR));
  12610. SendDlgItemMessage (hDlg, IDC_SOUNDSWAP, CB_ADDSTRING, 0, (LPARAM)txt);
  12611. SendDlgItemMessage (hDlg, IDC_SOUNDSWAP, CB_SETCURSEL,
  12612. workprefs.sound_stereo_swap_paula + workprefs.sound_stereo_swap_ahi * 2, 0);
  12613. SendDlgItemMessage (hDlg, IDC_SOUNDSTEREOSEP, CB_RESETCONTENT, 0, 0);
  12614. for (i = 10; i >= 0; i--) {
  12615. _stprintf (txt, _T("%d%%"), i * 10);
  12616. SendDlgItemMessage (hDlg, IDC_SOUNDSTEREOSEP, CB_ADDSTRING, 0, (LPARAM)txt);
  12617. }
  12618. SendDlgItemMessage (hDlg, IDC_SOUNDSTEREOSEP, CB_SETCURSEL, 10 - workprefs.sound_stereo_separation, 0);
  12619. SendDlgItemMessage (hDlg, IDC_SOUNDSTEREOMIX, CB_RESETCONTENT, 0, 0);
  12620. SendDlgItemMessage (hDlg, IDC_SOUNDSTEREOMIX, CB_ADDSTRING, 0, (LPARAM)_T("-"));
  12621. for (i = 0; i < 10; i++) {
  12622. _stprintf (txt, _T("%d"), i + 1);
  12623. SendDlgItemMessage (hDlg, IDC_SOUNDSTEREOMIX, CB_ADDSTRING, 0, (LPARAM)txt);
  12624. }
  12625. SendDlgItemMessage (hDlg, IDC_SOUNDSTEREOMIX, CB_SETCURSEL,
  12626. workprefs.sound_mixed_stereo_delay > 0 ? workprefs.sound_mixed_stereo_delay : 0, 0);
  12627. SendDlgItemMessage (hDlg, IDC_SOUNDINTERPOLATION, CB_RESETCONTENT, 0, 0);
  12628. WIN32GUI_LoadUIString (IDS_DISABLED, txt, sizeof (txt) / sizeof (TCHAR));
  12629. SendDlgItemMessage (hDlg, IDC_SOUNDINTERPOLATION, CB_ADDSTRING, 0, (LPARAM)txt);
  12630. SendDlgItemMessage (hDlg, IDC_SOUNDINTERPOLATION, CB_ADDSTRING, 0, (LPARAM)_T("Anti"));
  12631. SendDlgItemMessage (hDlg, IDC_SOUNDINTERPOLATION, CB_ADDSTRING, 0, (LPARAM)_T("Sinc"));
  12632. SendDlgItemMessage (hDlg, IDC_SOUNDINTERPOLATION, CB_ADDSTRING, 0, (LPARAM)_T("RH"));
  12633. SendDlgItemMessage (hDlg, IDC_SOUNDINTERPOLATION, CB_ADDSTRING, 0, (LPARAM)_T("Crux"));
  12634. SendDlgItemMessage (hDlg, IDC_SOUNDINTERPOLATION, CB_SETCURSEL, workprefs.sound_interpol, 0);
  12635. SendDlgItemMessage (hDlg, IDC_SOUNDFREQ, CB_RESETCONTENT, 0, 0);
  12636. i = 0;
  12637. selected = -1;
  12638. while (soundfreqs[i]) {
  12639. _stprintf (txt, _T("%d"), soundfreqs[i]);
  12640. SendDlgItemMessage (hDlg, IDC_SOUNDFREQ, CB_ADDSTRING, 0, (LPARAM)txt);
  12641. i++;
  12642. }
  12643. _stprintf (txt, _T("%d"), workprefs.sound_freq);
  12644. SendDlgItemMessage (hDlg, IDC_SOUNDFREQ, WM_SETTEXT, 0, (LPARAM)txt);
  12645. switch (workprefs.produce_sound)
  12646. {
  12647. case 0: which_button = IDC_SOUND0; break;
  12648. case 1: which_button = IDC_SOUND1; break;
  12649. case 2: case 3: which_button = IDC_SOUND2; break;
  12650. }
  12651. CheckRadioButton (hDlg, IDC_SOUND0, IDC_SOUND2, which_button);
  12652. CheckDlgButton (hDlg, IDC_SOUND_AUTO, workprefs.sound_auto);
  12653. CheckDlgButton(hDlg, IDC_SOUND_CDPAULAMIX, workprefs.sound_cdaudio);
  12654. CheckDlgButton(hDlg, IDC_SOUND_VOLCNT, workprefs.sound_volcnt);
  12655. if (workprefs.sound_maxbsiz < SOUND_BUFFER_MULTIPLIER)
  12656. workprefs.sound_maxbsiz = 0;
  12657. SendDlgItemMessage (hDlg, IDC_SOUNDBUFFERRAM, TBM_SETPOS, TRUE, getsoundbufsizeindex (workprefs.sound_maxbsiz));
  12658. SendDlgItemMessage (hDlg, IDC_SOUNDVOLUME, TBM_SETPOS, TRUE, 0);
  12659. SendDlgItemMessage (hDlg, IDC_SOUNDVOLUMEEXT, TBM_SETPOS, TRUE, 0);
  12660. SendDlgItemMessage (hDlg, IDC_SOUNDCARDLIST, CB_SETCURSEL, workprefs.win32_soundcard, 0);
  12661. sounddrivesel = SendDlgItemMessage (hDlg, IDC_SOUNDDRIVE, CB_GETCURSEL, 0, 0);
  12662. if (sounddrivesel < 0)
  12663. sounddrivesel = 0;
  12664. SendDlgItemMessage (hDlg, IDC_SOUNDDRIVE, CB_RESETCONTENT, 0, 0);
  12665. for (i = 0; i < 4; i++) {
  12666. _stprintf (txt, _T("DF%d:"), i);
  12667. SendDlgItemMessage (hDlg, IDC_SOUNDDRIVE, CB_ADDSTRING, 0, (LPARAM)txt);
  12668. }
  12669. SendDlgItemMessage (hDlg, IDC_SOUNDDRIVE, CB_SETCURSEL, sounddrivesel, 0);
  12670. SendDlgItemMessage (hDlg, IDC_SOUNDDRIVESELECT, CB_RESETCONTENT, 0, 0);
  12671. WIN32GUI_LoadUIString (IDS_DRIVESOUND_NONE, txt, sizeof (txt) / sizeof (TCHAR));
  12672. SendDlgItemMessage (hDlg, IDC_SOUNDDRIVESELECT, CB_ADDSTRING, 0, (LPARAM)txt);
  12673. WIN32GUI_LoadUIString (IDS_DRIVESOUND_DEFAULT_A500, txt, sizeof (txt) / sizeof (TCHAR));
  12674. SendDlgItemMessage (hDlg, IDC_SOUNDDRIVESELECT, CB_ADDSTRING, 0, (LPARAM)txt);
  12675. driveclick_fdrawcmd_detect ();
  12676. if (driveclick_pcdrivemask) {
  12677. for (i = 0; i < 2; i++) {
  12678. WIN32GUI_LoadUIString (IDS_DRIVESOUND_PC_FLOPPY, txt, sizeof (txt) / sizeof (TCHAR));
  12679. _stprintf (txt2, txt, 'A' + i);
  12680. SendDlgItemMessage (hDlg, IDC_SOUNDDRIVESELECT, CB_ADDSTRING, 0, (LPARAM)txt2);
  12681. }
  12682. }
  12683. SendDlgItemMessage (hDlg, IDC_SOUNDDRIVESELECT, CB_SETCURSEL, 0, 0);
  12684. p = drivesounds;
  12685. if (p) {
  12686. while (p[0]) {
  12687. SendDlgItemMessage (hDlg, IDC_SOUNDDRIVESELECT, CB_ADDSTRING, 0, (LPARAM)p);
  12688. p += _tcslen (p) + 1;
  12689. }
  12690. }
  12691. if (workprefs.floppyslots[sounddrivesel].dfxclick < 0) {
  12692. p = drivesounds;
  12693. i = DS_BUILD_IN_SOUNDS + (driveclick_pcdrivemask ? 2 : 0) + 1;
  12694. while (p && p[0]) {
  12695. if (!_tcsicmp (p, workprefs.floppyslots[sounddrivesel].dfxclickexternal)) {
  12696. SendDlgItemMessage (hDlg, IDC_SOUNDDRIVESELECT, CB_SETCURSEL, i, 0);
  12697. break;
  12698. }
  12699. i++;
  12700. p += _tcslen (p) + 1;
  12701. }
  12702. } else {
  12703. SendDlgItemMessage (hDlg, IDC_SOUNDDRIVESELECT, CB_SETCURSEL, workprefs.floppyslots[sounddrivesel].dfxclick, 0);
  12704. }
  12705. update_soundgui (hDlg);
  12706. }
  12707. static void values_from_sounddlg (HWND hDlg)
  12708. {
  12709. TCHAR txt[10];
  12710. LRESULT idx;
  12711. int soundcard, i;
  12712. idx = SendDlgItemMessage (hDlg, IDC_SOUNDFREQ, CB_GETCURSEL, 0, 0);
  12713. if (idx >= 0) {
  12714. workprefs.sound_freq = soundfreqs[idx];
  12715. } else {
  12716. txt[0] = 0;
  12717. SendDlgItemMessage (hDlg, IDC_SOUNDFREQ, WM_GETTEXT, (WPARAM)sizeof (txt) / sizeof (TCHAR), (LPARAM)txt);
  12718. workprefs.sound_freq = _tstol (txt);
  12719. }
  12720. if (workprefs.sound_freq < 8000)
  12721. workprefs.sound_freq = 8000;
  12722. if (workprefs.sound_freq > 768000)
  12723. workprefs.sound_freq = 768000;
  12724. workprefs.produce_sound = (ischecked (hDlg, IDC_SOUND0) ? 0
  12725. : ischecked (hDlg, IDC_SOUND1) ? 1 : 3);
  12726. workprefs.sound_auto = ischecked (hDlg, IDC_SOUND_AUTO);
  12727. workprefs.sound_cdaudio = ischecked(hDlg, IDC_SOUND_CDPAULAMIX);
  12728. workprefs.sound_volcnt = ischecked(hDlg, IDC_SOUND_VOLCNT);
  12729. idx = SendDlgItemMessage (hDlg, IDC_SOUNDSTEREO, CB_GETCURSEL, 0, 0);
  12730. if (idx != CB_ERR)
  12731. workprefs.sound_stereo = idx;
  12732. workprefs.sound_stereo_separation = 0;
  12733. workprefs.sound_mixed_stereo_delay = 0;
  12734. if (workprefs.sound_stereo > 0) {
  12735. idx = SendDlgItemMessage (hDlg, IDC_SOUNDSTEREOSEP, CB_GETCURSEL, 0, 0);
  12736. if (idx != CB_ERR) {
  12737. if (idx > 0)
  12738. workprefs.sound_mixed_stereo_delay = -1;
  12739. workprefs.sound_stereo_separation = 10 - idx;
  12740. }
  12741. idx = SendDlgItemMessage (hDlg, IDC_SOUNDSTEREOMIX, CB_GETCURSEL, 0, 0);
  12742. if (idx != CB_ERR && idx > 0)
  12743. workprefs.sound_mixed_stereo_delay = idx;
  12744. }
  12745. workprefs.sound_interpol = SendDlgItemMessage (hDlg, IDC_SOUNDINTERPOLATION, CB_GETCURSEL, 0, 0);
  12746. soundcard = SendDlgItemMessage (hDlg, IDC_SOUNDCARDLIST, CB_GETCURSEL, 0, 0L);
  12747. if (soundcard != workprefs.win32_soundcard && soundcard != CB_ERR) {
  12748. workprefs.win32_soundcard = soundcard;
  12749. update_soundgui (hDlg);
  12750. }
  12751. switch (SendDlgItemMessage (hDlg, IDC_SOUNDFILTER, CB_GETCURSEL, 0, 0))
  12752. {
  12753. case 0:
  12754. workprefs.sound_filter = FILTER_SOUND_OFF;
  12755. break;
  12756. case 1:
  12757. workprefs.sound_filter = FILTER_SOUND_EMUL;
  12758. workprefs.sound_filter_type = 0;
  12759. break;
  12760. case 2:
  12761. workprefs.sound_filter = FILTER_SOUND_EMUL;
  12762. workprefs.sound_filter_type = 1;
  12763. break;
  12764. case 3:
  12765. workprefs.sound_filter = FILTER_SOUND_ON;
  12766. workprefs.sound_filter_type = 0;
  12767. break;
  12768. case 4:
  12769. workprefs.sound_filter = FILTER_SOUND_ON;
  12770. workprefs.sound_filter_type = 1;
  12771. break;
  12772. }
  12773. workprefs.sound_stereo_swap_paula = (SendDlgItemMessage (hDlg, IDC_SOUNDSWAP, CB_GETCURSEL, 0, 0) & 1) ? 1 : 0;
  12774. workprefs.sound_stereo_swap_ahi = (SendDlgItemMessage (hDlg, IDC_SOUNDSWAP, CB_GETCURSEL, 0, 0) & 2) ? 1 : 0;
  12775. idx = SendDlgItemMessage (hDlg, IDC_SOUNDVOLUMESELECT, CB_GETCURSEL, 0, 0);
  12776. if (idx != volumeselectionindex) {
  12777. volumeselectionindex = idx;
  12778. if (volumeselectionindex < 0 || volumeselectionindex > 4)
  12779. volumeselectionindex = 0;
  12780. if (volumeselectionindex == 1)
  12781. volumeselection = &workprefs.sound_volume_cd;
  12782. else if (volumeselectionindex == 2)
  12783. volumeselection = &workprefs.sound_volume_board;
  12784. else if (volumeselectionindex == 3)
  12785. volumeselection = &workprefs.sound_volume_midi;
  12786. else if (volumeselectionindex == 4)
  12787. volumeselection = &workprefs.sound_volume_genlock;
  12788. else
  12789. volumeselection = &workprefs.sound_volume_paula;
  12790. update_soundgui (hDlg);
  12791. }
  12792. for (i = 0; sounddrivers[i]; i++) {
  12793. int old = sounddrivermask;
  12794. sounddrivermask &= ~(1 << i);
  12795. if (ischecked (hDlg, sounddrivers[i]))
  12796. sounddrivermask |= 1 << i;
  12797. if (old != sounddrivermask)
  12798. regsetint (NULL, _T("SoundDriverMask"), sounddrivermask);
  12799. }
  12800. idx = SendDlgItemMessage (hDlg, IDC_SOUNDDRIVE, CB_GETCURSEL, 0, 0);
  12801. if (idx != CB_ERR && idx >= 0) {
  12802. LRESULT res = SendDlgItemMessage (hDlg, IDC_SOUNDDRIVESELECT, CB_GETCURSEL, 0, 0);
  12803. if (res != CB_ERR && res >= 0) {
  12804. int xtra = driveclick_pcdrivemask ? 2 : 0;
  12805. if (res > DS_BUILD_IN_SOUNDS + xtra) {
  12806. int j = res - (DS_BUILD_IN_SOUNDS + xtra + 1);
  12807. TCHAR *p = drivesounds;
  12808. while (j-- > 0)
  12809. p += _tcslen (p) + 1;
  12810. workprefs.floppyslots[idx].dfxclick = -1;
  12811. _tcscpy (workprefs.floppyslots[idx].dfxclickexternal, p);
  12812. } else {
  12813. workprefs.floppyslots[idx].dfxclick = res;
  12814. workprefs.floppyslots[idx].dfxclickexternal[0] = 0;
  12815. }
  12816. }
  12817. }
  12818. }
  12819. static INT_PTR CALLBACK SoundDlgProc (HWND hDlg, UINT msg, WPARAM wParam, LPARAM lParam)
  12820. {
  12821. static int recursive = 0;
  12822. int numdevs;
  12823. int card, i;
  12824. if (dialog_inhibit)
  12825. return 0;
  12826. switch (msg) {
  12827. case WM_INITDIALOG:
  12828. {
  12829. recursive++;
  12830. sound_loaddrivesamples ();
  12831. SendDlgItemMessage (hDlg, IDC_SOUNDBUFFERRAM, TBM_SETRANGE, TRUE, MAKELONG (MIN_SOUND_MEM, MAX_SOUND_MEM));
  12832. SendDlgItemMessage (hDlg, IDC_SOUNDBUFFERRAM, TBM_SETPAGESIZE, 0, 1);
  12833. SendDlgItemMessage (hDlg, IDC_SOUNDVOLUME, TBM_SETRANGE, TRUE, MAKELONG (0, 100));
  12834. SendDlgItemMessage (hDlg, IDC_SOUNDVOLUME, TBM_SETPAGESIZE, 0, 1);
  12835. SendDlgItemMessage (hDlg, IDC_SOUNDVOLUMEEXT, TBM_SETRANGE, TRUE, MAKELONG (0, 100));
  12836. SendDlgItemMessage (hDlg, IDC_SOUNDVOLUMEEXT, TBM_SETPAGESIZE, 0, 1);
  12837. SendDlgItemMessage (hDlg, IDC_SOUNDDRIVEVOLUME, TBM_SETRANGE, TRUE, MAKELONG (0, 100));
  12838. SendDlgItemMessage (hDlg, IDC_SOUNDDRIVEVOLUME, TBM_SETPAGESIZE, 0, 1);
  12839. SendDlgItemMessage (hDlg, IDC_SOUNDDRIVEVOLUMEX, TBM_SETRANGE, TRUE, MAKELONG (0, 100));
  12840. SendDlgItemMessage (hDlg, IDC_SOUNDDRIVEVOLUMEX, TBM_SETPAGESIZE, 0, 1);
  12841. SendDlgItemMessage (hDlg, IDC_SOUNDADJUST, TBM_SETRANGE, TRUE, MAKELONG (-100, +30));
  12842. SendDlgItemMessage (hDlg, IDC_SOUNDADJUST, TBM_SETPAGESIZE, 0, 1);
  12843. for (i = 0; i < sounddrivers[i]; i++) {
  12844. CheckDlgButton (hDlg, sounddrivers[i], (sounddrivermask & (1 << i)) ? TRUE : FALSE);
  12845. }
  12846. if (!volumeselection) {
  12847. volumeselection = &workprefs.sound_volume_paula;
  12848. volumeselectionindex = 0;
  12849. }
  12850. SendDlgItemMessage (hDlg, IDC_SOUNDVOLUMESELECT, CB_RESETCONTENT, 0, 0L);
  12851. SendDlgItemMessage (hDlg, IDC_SOUNDVOLUMESELECT, CB_ADDSTRING, 0, (LPARAM)_T("Paula"));
  12852. SendDlgItemMessage (hDlg, IDC_SOUNDVOLUMESELECT, CB_ADDSTRING, 0, (LPARAM)_T("CD"));
  12853. SendDlgItemMessage (hDlg, IDC_SOUNDVOLUMESELECT, CB_ADDSTRING, 0, (LPARAM)_T("AHI"));
  12854. SendDlgItemMessage (hDlg, IDC_SOUNDVOLUMESELECT, CB_ADDSTRING, 0, (LPARAM)_T("MIDI"));
  12855. SendDlgItemMessage (hDlg, IDC_SOUNDVOLUMESELECT, CB_ADDSTRING, 0, (LPARAM)_T("Genlock"));
  12856. SendDlgItemMessage (hDlg, IDC_SOUNDVOLUMESELECT, CB_SETCURSEL, volumeselectionindex, 0);
  12857. SendDlgItemMessage (hDlg, IDC_SOUNDCARDLIST, CB_RESETCONTENT, 0, 0L);
  12858. numdevs = enumerate_sound_devices ();
  12859. for (card = 0; card < numdevs; card++) {
  12860. TCHAR tmp[MAX_DPATH];
  12861. int type = sound_devices[card]->type;
  12862. _stprintf (tmp, _T("%s: %s"),
  12863. type == SOUND_DEVICE_XAUDIO2 ? _T("XAudio2") : (type == SOUND_DEVICE_DS ? _T("DSOUND") : (type == SOUND_DEVICE_AL ? _T("OpenAL") : (type == SOUND_DEVICE_PA ? _T("PortAudio") : (type == SOUND_DEVICE_WASAPI ? _T("WASAPI") : _T("WASAPI EX"))))),
  12864. sound_devices[card]->name);
  12865. SendDlgItemMessage (hDlg, IDC_SOUNDCARDLIST, CB_ADDSTRING, 0, (LPARAM)tmp);
  12866. }
  12867. if (numdevs == 0)
  12868. workprefs.produce_sound = 0; /* No sound card in system, enable_for_sounddlg will accommodate this */
  12869. pages[SOUND_ID] = hDlg;
  12870. currentpage = SOUND_ID;
  12871. update_soundgui (hDlg);
  12872. recursive--;
  12873. }
  12874. case WM_USER:
  12875. recursive++;
  12876. values_to_sounddlg (hDlg);
  12877. enable_for_sounddlg (hDlg);
  12878. recursive--;
  12879. return TRUE;
  12880. case WM_COMMAND:
  12881. if (recursive > 0)
  12882. break;
  12883. recursive++;
  12884. if(LOWORD (wParam) == IDC_SOUNDDRIVE) {
  12885. values_to_sounddlg (hDlg);
  12886. }
  12887. values_from_sounddlg (hDlg);
  12888. enable_for_sounddlg (hDlg);
  12889. recursive--;
  12890. break;
  12891. case WM_HSCROLL:
  12892. if ((HWND)lParam == GetDlgItem (hDlg, IDC_SOUNDBUFFERRAM)) {
  12893. int v = SendMessage (GetDlgItem (hDlg, IDC_SOUNDBUFFERRAM), TBM_GETPOS, 0, 0);
  12894. if (v >= 0) {
  12895. if (v == 0)
  12896. workprefs.sound_maxbsiz = 0;
  12897. else
  12898. workprefs.sound_maxbsiz = sndbufsizes[v - 1];
  12899. }
  12900. }
  12901. workprefs.sound_volume_master = 100 - SendMessage (GetDlgItem (hDlg, IDC_SOUNDVOLUME), TBM_GETPOS, 0, 0);
  12902. (*volumeselection) = 100 - SendMessage (GetDlgItem (hDlg, IDC_SOUNDVOLUMEEXT), TBM_GETPOS, 0, 0);
  12903. workprefs.dfxclickvolume_empty[sounddrivesel] = 100 - SendMessage (GetDlgItem (hDlg, IDC_SOUNDDRIVEVOLUME), TBM_GETPOS, 0, 0);
  12904. workprefs.dfxclickvolume_disk[sounddrivesel] = 100 - SendMessage (GetDlgItem (hDlg, IDC_SOUNDDRIVEVOLUMEX), TBM_GETPOS, 0, 0);
  12905. update_soundgui (hDlg);
  12906. break;
  12907. }
  12908. return FALSE;
  12909. }
  12910. #ifdef FILESYS
  12911. struct cddlg_vals
  12912. {
  12913. struct uaedev_config_info ci;
  12914. };
  12915. struct tapedlg_vals
  12916. {
  12917. struct uaedev_config_info ci;
  12918. };
  12919. struct fsvdlg_vals
  12920. {
  12921. struct uaedev_config_info ci;
  12922. int rdb;
  12923. };
  12924. struct hfdlg_vals
  12925. {
  12926. struct uaedev_config_info ci;
  12927. bool original;
  12928. uae_u64 size;
  12929. uae_u32 dostype;
  12930. int forcedcylinders;
  12931. bool rdb;
  12932. };
  12933. static struct cddlg_vals current_cddlg;
  12934. static struct tapedlg_vals current_tapedlg;
  12935. static struct fsvdlg_vals current_fsvdlg;
  12936. static struct hfdlg_vals current_hfdlg;
  12937. static int archivehd;
  12938. static void hardfile_testrdb (struct hfdlg_vals *hdf)
  12939. {
  12940. uae_u8 id[512];
  12941. int i;
  12942. struct hardfiledata hfd;
  12943. memset (id, 0, sizeof id);
  12944. memset (&hfd, 0, sizeof hfd);
  12945. hfd.ci.readonly = true;
  12946. hfd.ci.blocksize = 512;
  12947. if (hdf_open (&hfd, current_hfdlg.ci.rootdir) > 0) {
  12948. for (i = 0; i < 16; i++) {
  12949. hdf_read_rdb (&hfd, id, i * 512, 512);
  12950. if (i == 0 && !memcmp (id + 2, "CIS", 3)) {
  12951. hdf->ci.controller_type = HD_CONTROLLER_TYPE_CUSTOM_FIRST;
  12952. hdf->ci.controller_type_unit = 0;
  12953. break;
  12954. }
  12955. bool babe = id[0] == 0xBA && id[1] == 0xBE; // A2090
  12956. if (!memcmp (id, "RDSK\0\0\0", 7) || !memcmp (id, "CDSK\0\0\0", 7) || !memcmp (id, "DRKS\0\0", 6) ||
  12957. (id[0] == 0x53 && id[1] == 0x10 && id[2] == 0x9b && id[3] == 0x13 && id[4] == 0 && id[5] == 0) || babe) {
  12958. // RDSK or ADIDE "encoded" RDSK
  12959. int blocksize = 512;
  12960. if (!babe)
  12961. blocksize = (id[16] << 24) | (id[17] << 16) | (id[18] << 8) | (id[19] << 0);
  12962. hdf->ci.cyls = hdf->ci.highcyl = hdf->forcedcylinders = 0;
  12963. hdf->ci.sectors = 0;
  12964. hdf->ci.surfaces = 0;
  12965. hdf->ci.reserved = 0;
  12966. hdf->ci.filesys[0] = 0;
  12967. hdf->ci.bootpri = 0;
  12968. hdf->ci.devname[0] = 0;
  12969. if (blocksize >= 512)
  12970. hdf->ci.blocksize = blocksize;
  12971. break;
  12972. }
  12973. }
  12974. hdf_close (&hfd);
  12975. }
  12976. }
  12977. static void default_fsvdlg (struct fsvdlg_vals *f)
  12978. {
  12979. memset (f, 0, sizeof (struct fsvdlg_vals));
  12980. f->ci.type = UAEDEV_DIR;
  12981. }
  12982. static void default_tapedlg (struct tapedlg_vals *f)
  12983. {
  12984. memset (f, 0, sizeof (struct tapedlg_vals));
  12985. f->ci.type = UAEDEV_TAPE;
  12986. }
  12987. static void default_hfdlg (struct hfdlg_vals *f, bool rdb)
  12988. {
  12989. int ctrl = f->ci.controller_type;
  12990. int unit = f->ci.controller_unit;
  12991. memset (f, 0, sizeof (struct hfdlg_vals));
  12992. uci_set_defaults (&f->ci, rdb);
  12993. f->original = true;
  12994. f->ci.type = UAEDEV_HDF;
  12995. f->ci.controller_type = ctrl;
  12996. f->ci.controller_unit = unit;
  12997. f->ci.unit_feature_level = 1;
  12998. }
  12999. static void default_rdb_hfdlg (struct hfdlg_vals *f, const TCHAR *filename)
  13000. {
  13001. default_hfdlg (f, true);
  13002. _tcscpy (current_hfdlg.ci.rootdir, filename);
  13003. hardfile_testrdb (f);
  13004. }
  13005. static void volumeselectfile (HWND hDlg, int setout)
  13006. {
  13007. TCHAR directory_path[MAX_DPATH];
  13008. _tcscpy (directory_path, current_fsvdlg.ci.rootdir);
  13009. if (directory_path[0] == 0) {
  13010. int out = sizeof directory_path / sizeof (TCHAR);
  13011. regquerystr (NULL, _T("FilesystemFilePath"), directory_path, &out);
  13012. }
  13013. if (DiskSelection (hDlg, 0, 14, &workprefs, NULL, directory_path)) {
  13014. TCHAR *s = filesys_createvolname (NULL, directory_path, NULL, _T("Harddrive"));
  13015. SetDlgItemText (hDlg, IDC_PATH_NAME, directory_path);
  13016. SetDlgItemText (hDlg, IDC_VOLUME_NAME, s);
  13017. xfree (s);
  13018. CheckDlgButton (hDlg, IDC_FS_RW, FALSE);
  13019. ew (hDlg, IDC_FS_RW, FALSE);
  13020. archivehd = 1;
  13021. TCHAR *p = _tcsrchr (directory_path, '\\');
  13022. if (p) {
  13023. TCHAR t = p[1];
  13024. p[1] = 0;
  13025. regsetstr (NULL, _T("FilesystemFilePath"), directory_path);
  13026. p[1] = t;
  13027. }
  13028. if (setout)
  13029. _tcscpy (current_fsvdlg.ci.rootdir, directory_path);
  13030. }
  13031. }
  13032. static void volumeselectdir (HWND hDlg, int newdir, int setout)
  13033. {
  13034. const GUID volumeguid = { 0x1df05121, 0xcc08, 0x46ea, { 0x80, 0x3f, 0x98, 0x3c, 0x54, 0x88, 0x53, 0x76 } };
  13035. TCHAR szTitle[MAX_DPATH];
  13036. TCHAR directory_path[MAX_DPATH];
  13037. _tcscpy (directory_path, current_fsvdlg.ci.rootdir);
  13038. if (!newdir) {
  13039. if (directory_path[0] == 0) {
  13040. int out = sizeof directory_path / sizeof (TCHAR);
  13041. regquerystr (NULL, _T("FilesystemDirectoryPath"), directory_path, &out);
  13042. }
  13043. WIN32GUI_LoadUIString (IDS_SELECTFILESYSROOT, szTitle, MAX_DPATH);
  13044. if (DirectorySelection (hDlg, &volumeguid, directory_path)) {
  13045. newdir = 1;
  13046. DISK_history_add (directory_path, -1, HISTORY_DIR, 1);
  13047. regsetstr (NULL, _T("FilesystemDirectoryPath"), directory_path);
  13048. }
  13049. }
  13050. if (newdir) {
  13051. SetDlgItemText (hDlg, IDC_PATH_NAME, directory_path);
  13052. ew (hDlg, IDC_FS_RW, TRUE);
  13053. archivehd = 0;
  13054. if (setout)
  13055. _tcscpy(current_fsvdlg.ci.rootdir, directory_path);
  13056. }
  13057. }
  13058. static INT_PTR CALLBACK VolumeSettingsProc (HWND hDlg, UINT msg, WPARAM wParam, LPARAM lParam)
  13059. {
  13060. static int recursive = 0;
  13061. if (dialog_inhibit)
  13062. return 0;
  13063. switch (msg) {
  13064. case WM_INITDIALOG:
  13065. {
  13066. archivehd = -1;
  13067. if (my_existsfile (current_fsvdlg.ci.rootdir))
  13068. archivehd = 1;
  13069. else if (my_existsdir (current_fsvdlg.ci.rootdir))
  13070. archivehd = 0;
  13071. recursive++;
  13072. setautocomplete (hDlg, IDC_PATH_NAME);
  13073. addhistorymenu(hDlg, current_fsvdlg.ci.rootdir, IDC_PATH_NAME, HISTORY_DIR, false, -1);
  13074. SetDlgItemText (hDlg, IDC_VOLUME_NAME, current_fsvdlg.ci.volname);
  13075. SetDlgItemText (hDlg, IDC_VOLUME_DEVICE, current_fsvdlg.ci.devname);
  13076. SetDlgItemInt (hDlg, IDC_VOLUME_BOOTPRI, current_fsvdlg.ci.bootpri, TRUE);
  13077. if (archivehd > 0)
  13078. current_fsvdlg.ci.readonly = true;
  13079. CheckDlgButton (hDlg, IDC_FS_RW, !current_fsvdlg.ci.readonly);
  13080. CheckDlgButton (hDlg, IDC_FS_AUTOBOOT, ISAUTOBOOT(&current_fsvdlg.ci));
  13081. ew (hDlg, IDC_FS_RW, archivehd <= 0);
  13082. recursive--;
  13083. }
  13084. return TRUE;
  13085. case WM_CONTEXTMENU:
  13086. if (GetDlgCtrlID ((HWND)wParam) == IDC_FS_SELECT_FILE) {
  13087. TCHAR *s = favoritepopup (hDlg);
  13088. if (s) {
  13089. _tcscpy (current_fsvdlg.ci.rootdir, s);
  13090. xfree (s);
  13091. volumeselectfile (hDlg, 0);
  13092. }
  13093. } else if (GetDlgCtrlID ((HWND)wParam) == IDC_FS_SELECT_DIR) {
  13094. TCHAR *s = favoritepopup (hDlg);
  13095. if (s) {
  13096. _tcscpy (current_fsvdlg.ci.rootdir, s);
  13097. xfree (s);
  13098. volumeselectdir (hDlg, 1, 0);
  13099. }
  13100. }
  13101. break;
  13102. case WM_COMMAND:
  13103. if (HIWORD(wParam) == CBN_SELCHANGE || HIWORD(wParam) == CBN_KILLFOCUS) {
  13104. switch (LOWORD(wParam))
  13105. {
  13106. case IDC_PATH_NAME:
  13107. getcomboboxtext(hDlg, IDC_PATH_NAME, current_fsvdlg.ci.rootdir, sizeof current_fsvdlg.ci.rootdir / sizeof(TCHAR));
  13108. break;
  13109. }
  13110. }
  13111. if (HIWORD(wParam) == EN_UPDATE || HIWORD(wParam) == EN_KILLFOCUS) {
  13112. switch (LOWORD(wParam))
  13113. {
  13114. case IDC_VOLUME_NAME:
  13115. GetDlgItemText(hDlg, IDC_VOLUME_NAME, current_fsvdlg.ci.volname, sizeof current_fsvdlg.ci.volname / sizeof(TCHAR));
  13116. break;
  13117. case IDC_VOLUME_DEVICE:
  13118. GetDlgItemText(hDlg, IDC_VOLUME_DEVICE, current_fsvdlg.ci.devname, sizeof current_fsvdlg.ci.devname / sizeof(TCHAR));
  13119. break;
  13120. }
  13121. }
  13122. if (recursive)
  13123. break;
  13124. recursive++;
  13125. if (HIWORD (wParam) == BN_CLICKED) {
  13126. switch (LOWORD (wParam))
  13127. {
  13128. case IDC_FS_SELECT_EJECT:
  13129. SetDlgItemText (hDlg, IDC_PATH_NAME, _T(""));
  13130. SetDlgItemText (hDlg, IDC_VOLUME_NAME, _T(""));
  13131. current_fsvdlg.ci.rootdir[0] = 0;
  13132. current_fsvdlg.ci.volname[0] = 0;
  13133. CheckDlgButton (hDlg, IDC_FS_RW, TRUE);
  13134. ew (hDlg, IDC_FS_RW, TRUE);
  13135. archivehd = -1;
  13136. break;
  13137. case IDC_FS_SELECT_FILE:
  13138. volumeselectfile (hDlg, 1);
  13139. break;
  13140. case IDC_FS_SELECT_DIR:
  13141. volumeselectdir (hDlg, 0, 1);
  13142. break;
  13143. case IDOK:
  13144. EndDialog (hDlg, 1);
  13145. break;
  13146. case IDCANCEL:
  13147. EndDialog (hDlg, 0);
  13148. break;
  13149. }
  13150. }
  13151. current_fsvdlg.ci.readonly = !ischecked (hDlg, IDC_FS_RW);
  13152. current_fsvdlg.ci.bootpri = GetDlgItemInt (hDlg, IDC_VOLUME_BOOTPRI, NULL, TRUE);
  13153. if(LOWORD (wParam) == IDC_FS_AUTOBOOT) {
  13154. if (!ischecked (hDlg, IDC_FS_AUTOBOOT)) {
  13155. current_fsvdlg.ci.bootpri = BOOTPRI_NOAUTOBOOT;
  13156. } else {
  13157. current_fsvdlg.ci.bootpri = 0;
  13158. }
  13159. SetDlgItemInt (hDlg, IDC_VOLUME_BOOTPRI, current_fsvdlg.ci.bootpri, TRUE);
  13160. }
  13161. recursive--;
  13162. break;
  13163. }
  13164. commonproc(hDlg, msg, wParam, lParam);
  13165. return FALSE;
  13166. }
  13167. STATIC_INLINE bool is_hdf_rdb (void)
  13168. {
  13169. return current_hfdlg.ci.sectors == 0 && current_hfdlg.ci.surfaces == 0 && current_hfdlg.ci.reserved == 0;
  13170. }
  13171. static int hdmenutable[256];
  13172. static void sethardfilegeo(HWND hDlg)
  13173. {
  13174. if (current_hfdlg.ci.geometry[0]) {
  13175. current_hfdlg.ci.physical_geometry = true;
  13176. setchecked(hDlg, IDC_HDF_PHYSGEOMETRY, TRUE);
  13177. ew(hDlg, IDC_HDF_PHYSGEOMETRY, FALSE);
  13178. get_hd_geometry(&current_hfdlg.ci);
  13179. } else if (current_hfdlg.ci.chs) {
  13180. current_hfdlg.ci.physical_geometry = true;
  13181. setchecked(hDlg, IDC_HDF_PHYSGEOMETRY, TRUE);
  13182. ew(hDlg, IDC_HDF_PHYSGEOMETRY, FALSE);
  13183. ew(hDlg, IDC_SECTORS, FALSE);
  13184. ew(hDlg, IDC_SECTORS, FALSE);
  13185. ew(hDlg, IDC_RESERVED, FALSE);
  13186. ew(hDlg, IDC_BLOCKSIZE, FALSE);
  13187. } else {
  13188. ew (hDlg, IDC_HDF_PHYSGEOMETRY, TRUE);
  13189. }
  13190. }
  13191. static void sethardfiletypes(HWND hDlg)
  13192. {
  13193. bool ide = current_hfdlg.ci.controller_type >= HD_CONTROLLER_TYPE_IDE_FIRST && current_hfdlg.ci.controller_type <= HD_CONTROLLER_TYPE_IDE_LAST;
  13194. bool scsi = current_hfdlg.ci.controller_type >= HD_CONTROLLER_TYPE_SCSI_FIRST && current_hfdlg.ci.controller_type <= HD_CONTROLLER_TYPE_SCSI_LAST;
  13195. ew(hDlg, IDC_HDF_CONTROLLER_TYPE, ide);
  13196. ew(hDlg, IDC_HDF_FEATURE_LEVEL, ide || scsi);
  13197. if (!ide) {
  13198. current_hfdlg.ci.controller_media_type = 0;
  13199. }
  13200. if (current_hfdlg.ci.controller_media_type && current_hfdlg.ci.unit_feature_level == 0)
  13201. current_hfdlg.ci.unit_feature_level = 1;
  13202. SendDlgItemMessage(hDlg, IDC_HDF_CONTROLLER_TYPE, CB_SETCURSEL, current_hfdlg.ci.controller_media_type, 0);
  13203. SendDlgItemMessage(hDlg, IDC_HDF_FEATURE_LEVEL, CB_SETCURSEL, current_hfdlg.ci.unit_feature_level, 0);
  13204. }
  13205. static void sethd(HWND hDlg)
  13206. {
  13207. bool rdb = is_hdf_rdb ();
  13208. bool physgeo = (rdb && ischecked(hDlg, IDC_HDF_PHYSGEOMETRY)) || current_hfdlg.ci.chs;
  13209. bool enablegeo = (!rdb || (physgeo && current_hfdlg.ci.geometry[0] == 0)) && !current_hfdlg.ci.chs;
  13210. const struct expansionromtype *ert = get_unit_expansion_rom(current_hfdlg.ci.controller_type);
  13211. if (ert && current_hfdlg.ci.controller_unit >= 8) {
  13212. if (!_tcscmp(ert->name, _T("a2091"))) {
  13213. current_hfdlg.ci.unit_feature_level = HD_LEVEL_SASI_CHS;
  13214. } else if (!_tcscmp(ert->name, _T("a2090a"))) {
  13215. current_hfdlg.ci.unit_feature_level = HD_LEVEL_SCSI_1;
  13216. }
  13217. }
  13218. if (!physgeo)
  13219. current_hfdlg.ci.physical_geometry = false;
  13220. ew(hDlg, IDC_SECTORS, enablegeo);
  13221. ew(hDlg, IDC_HEADS, enablegeo);
  13222. ew(hDlg, IDC_RESERVED, enablegeo);
  13223. ew(hDlg, IDC_BLOCKSIZE, enablegeo);
  13224. }
  13225. static void setharddrive(HWND hDlg)
  13226. {
  13227. sethardfilegeo(hDlg);
  13228. sethd(hDlg);
  13229. ew(hDlg,IDC_BLOCKSIZE, FALSE);
  13230. SetDlgItemInt (hDlg, IDC_SECTORS, current_hfdlg.ci.psecs, FALSE);
  13231. SetDlgItemInt (hDlg, IDC_HEADS, current_hfdlg.ci.pheads, FALSE);
  13232. SetDlgItemInt (hDlg, IDC_RESERVED, current_hfdlg.ci.pcyls, FALSE);
  13233. SetDlgItemInt (hDlg, IDC_BLOCKSIZE, current_hfdlg.ci.blocksize, FALSE);
  13234. sethardfiletypes(hDlg);
  13235. }
  13236. static void sethardfile (HWND hDlg)
  13237. {
  13238. sethardfilegeo(hDlg);
  13239. bool ide = current_hfdlg.ci.controller_type >= HD_CONTROLLER_TYPE_IDE_FIRST && current_hfdlg.ci.controller_type <= HD_CONTROLLER_TYPE_IDE_LAST;
  13240. bool scsi = current_hfdlg.ci.controller_type >= HD_CONTROLLER_TYPE_SCSI_FIRST && current_hfdlg.ci.controller_type <= HD_CONTROLLER_TYPE_SCSI_LAST;
  13241. bool rdb = is_hdf_rdb ();
  13242. bool physgeo = rdb && ischecked(hDlg, IDC_HDF_PHYSGEOMETRY);
  13243. bool disables = !rdb || (rdb && current_hfdlg.ci.controller_type == HD_CONTROLLER_TYPE_UAE);
  13244. sethd(hDlg);
  13245. if (!disables)
  13246. current_hfdlg.ci.bootpri = 0;
  13247. SetDlgItemText (hDlg, IDC_PATH_NAME, current_hfdlg.ci.rootdir);
  13248. SetDlgItemText (hDlg, IDC_PATH_FILESYS, current_hfdlg.ci.filesys);
  13249. SetDlgItemText (hDlg, IDC_HARDFILE_DEVICE, current_hfdlg.ci.devname);
  13250. SetDlgItemInt (hDlg, IDC_SECTORS, rdb ? current_hfdlg.ci.psecs : current_hfdlg.ci.sectors, FALSE);
  13251. SetDlgItemInt (hDlg, IDC_HEADS, rdb ? current_hfdlg.ci.pheads : current_hfdlg.ci.surfaces, FALSE);
  13252. SetDlgItemInt (hDlg, IDC_RESERVED, rdb ? current_hfdlg.ci.pcyls : current_hfdlg.ci.reserved, FALSE);
  13253. SetDlgItemInt (hDlg, IDC_BLOCKSIZE, current_hfdlg.ci.blocksize, FALSE);
  13254. SetDlgItemInt (hDlg, IDC_HARDFILE_BOOTPRI, current_hfdlg.ci.bootpri, TRUE);
  13255. CheckDlgButton (hDlg, IDC_HDF_RW, !current_hfdlg.ci.readonly);
  13256. CheckDlgButton (hDlg, IDC_HDF_AUTOBOOT, ISAUTOBOOT(&current_hfdlg.ci));
  13257. CheckDlgButton (hDlg, IDC_HDF_DONOTMOUNT, !ISAUTOMOUNT(&current_hfdlg.ci));
  13258. ew (hDlg, IDC_HDF_RDB, !rdb);
  13259. ew (hDlg, IDC_HDF_AUTOBOOT, disables);
  13260. ew (hDlg, IDC_HDF_DONOTMOUNT, disables);
  13261. hide (hDlg, IDC_HDF_AUTOBOOT, !disables);
  13262. hide (hDlg, IDC_HDF_DONOTMOUNT, !disables);
  13263. hide (hDlg, IDC_HARDFILE_BOOTPRI, !disables);
  13264. hide (hDlg, IDC_HARDFILE_BOOTPRI_TEXT, !disables);
  13265. hide (hDlg, IDC_HDF_PHYSGEOMETRY, !rdb);
  13266. if (!rdb)
  13267. setchecked(hDlg, IDC_HDF_PHYSGEOMETRY, false);
  13268. hide(hDlg, IDC_RESERVED_TEXT, rdb);
  13269. hide(hDlg, IDC_CYLINDERS_TEXT, !rdb);
  13270. gui_set_string_cursor(hdmenutable, hDlg, IDC_HDF_CONTROLLER, current_hfdlg.ci.controller_type + current_hfdlg.ci.controller_type_unit * HD_CONTROLLER_NEXT_UNIT);
  13271. SendDlgItemMessage (hDlg, IDC_HDF_CONTROLLER_UNIT, CB_SETCURSEL, current_hfdlg.ci.controller_unit, 0);
  13272. sethardfiletypes(hDlg);
  13273. }
  13274. static void addhdcontroller(HWND hDlg, const struct expansionromtype *erc, int *hdmenutable, int firstid, int flags)
  13275. {
  13276. TCHAR name[MAX_DPATH];
  13277. name[0] = 0;
  13278. if (erc->friendlymanufacturer && _tcsicmp(erc->friendlymanufacturer, erc->friendlyname)) {
  13279. _tcscat(name, erc->friendlymanufacturer);
  13280. _tcscat(name, _T(" "));
  13281. }
  13282. _tcscat(name, erc->friendlyname);
  13283. if (workprefs.cpuboard_type && erc->romtype == ROMTYPE_CPUBOARD) {
  13284. const struct cpuboardsubtype *cbt = &cpuboards[workprefs.cpuboard_type].subtypes[workprefs.cpuboard_subtype];
  13285. if (!(cbt->deviceflags & flags))
  13286. return;
  13287. _tcscat(name, _T(" ("));
  13288. _tcscat(name, cbt->name);
  13289. _tcscat(name, _T(")"));
  13290. }
  13291. if (get_boardromconfig(&workprefs, erc->romtype, NULL) || get_boardromconfig(&workprefs, erc->romtype_extra, NULL)) {
  13292. gui_add_string(hdmenutable, hDlg, IDC_HDF_CONTROLLER, firstid, name);
  13293. for (int j = 1; j < MAX_DUPLICATE_EXPANSION_BOARDS; j++) {
  13294. if (is_board_enabled(&workprefs, erc->romtype, j)) {
  13295. TCHAR tmp[MAX_DPATH];
  13296. _stprintf(tmp, _T("%s [%d]"), name, j + 1);
  13297. gui_add_string(hdmenutable, hDlg, IDC_HDF_CONTROLLER, firstid + j * HD_CONTROLLER_NEXT_UNIT, tmp);
  13298. }
  13299. }
  13300. }
  13301. }
  13302. static void inithdcontroller (HWND hDlg, int ctype, int ctype_unit, int devtype, bool media)
  13303. {
  13304. hdmenutable[0] = -1;
  13305. SendDlgItemMessage(hDlg, IDC_HDF_CONTROLLER, CB_RESETCONTENT, 0, 0);
  13306. gui_add_string(hdmenutable, hDlg, IDC_HDF_CONTROLLER, HD_CONTROLLER_TYPE_UAE, _T("UAE (uaehf.device)"));
  13307. gui_add_string(hdmenutable, hDlg, IDC_HDF_CONTROLLER, 0, _T(""));
  13308. gui_add_string(hdmenutable, hDlg, IDC_HDF_CONTROLLER, HD_CONTROLLER_TYPE_IDE_AUTO, _T("IDE (Auto)"));
  13309. for (int i = 0; expansionroms[i].name; i++) {
  13310. const struct expansionromtype *erc = &expansionroms[i];
  13311. if (erc->deviceflags & EXPANSIONTYPE_IDE) {
  13312. addhdcontroller(hDlg, erc, hdmenutable, HD_CONTROLLER_TYPE_IDE_EXPANSION_FIRST + i, EXPANSIONTYPE_IDE);
  13313. }
  13314. }
  13315. gui_add_string(hdmenutable, hDlg, IDC_HDF_CONTROLLER, 0, _T(""));
  13316. gui_add_string(hdmenutable, hDlg, IDC_HDF_CONTROLLER, HD_CONTROLLER_TYPE_SCSI_AUTO, _T("SCSI (Auto)"));
  13317. for (int i = 0; expansionroms[i].name; i++) {
  13318. const struct expansionromtype *erc = &expansionroms[i];
  13319. if (erc->deviceflags & EXPANSIONTYPE_SCSI) {
  13320. addhdcontroller(hDlg, erc, hdmenutable, HD_CONTROLLER_TYPE_SCSI_EXPANSION_FIRST + i, EXPANSIONTYPE_SCSI);
  13321. }
  13322. }
  13323. #if 0
  13324. gui_add_string(hdmenutable, hDlg, IDC_HDF_CONTROLLER, 0, _T(""));
  13325. for (int i = 0; expansionroms[i].name; i++) {
  13326. const struct expansionromtype *erc = &expansionroms[i];
  13327. if ((erc->romtype & ROMTYPE_MASK) == ROMTYPE_MB_PCMCIA) {
  13328. addhdcontroller(hDlg, erc, hdmenutable, HD_CONTROLLER_TYPE_CUSTOM_FIRST + i, 0);
  13329. ctype_unit = 0;
  13330. }
  13331. }
  13332. #endif
  13333. gui_add_string(hdmenutable, hDlg, IDC_HDF_CONTROLLER, 0, _T(""));
  13334. for (int i = 0; expansionroms[i].name; i++) {
  13335. const struct expansionromtype *erc = &expansionroms[i];
  13336. if (erc->deviceflags & EXPANSIONTYPE_CUSTOMDISK) {
  13337. addhdcontroller(hDlg, erc, hdmenutable, HD_CONTROLLER_TYPE_CUSTOM_FIRST + i, EXPANSIONTYPE_CUSTOMDISK);
  13338. break;
  13339. }
  13340. }
  13341. gui_set_string_cursor(hdmenutable, hDlg, IDC_HDF_CONTROLLER, ctype + ctype_unit * HD_CONTROLLER_NEXT_UNIT);
  13342. SendDlgItemMessage (hDlg, IDC_HDF_CONTROLLER_UNIT, CB_RESETCONTENT, 0, 0);
  13343. if (ctype >= HD_CONTROLLER_TYPE_IDE_FIRST && ctype <= HD_CONTROLLER_TYPE_IDE_LAST) {
  13344. const struct expansionromtype *ert = get_unit_expansion_rom(ctype);
  13345. int ports = 2 + (ert ? ert->extrahdports : 0);
  13346. for (int i = 0; i < ports; i += 2) {
  13347. TCHAR tmp[100];
  13348. _stprintf(tmp, _T("%d"), i + 0);
  13349. SendDlgItemMessage(hDlg, IDC_HDF_CONTROLLER_UNIT, CB_ADDSTRING, 0, (LPARAM)tmp);
  13350. _stprintf(tmp, _T("%d"), i + 1);
  13351. SendDlgItemMessage(hDlg, IDC_HDF_CONTROLLER_UNIT, CB_ADDSTRING, 0, (LPARAM)tmp);
  13352. }
  13353. if (media)
  13354. ew(hDlg, IDC_HDF_CONTROLLER_UNIT, TRUE);
  13355. } else if (ctype >= HD_CONTROLLER_TYPE_SCSI_FIRST && ctype <= HD_CONTROLLER_TYPE_SCSI_LAST) {
  13356. const struct expansionromtype *ert = get_unit_expansion_rom(ctype);
  13357. SendDlgItemMessage (hDlg, IDC_HDF_CONTROLLER_UNIT, CB_ADDSTRING, 0, (LPARAM)_T("0"));
  13358. SendDlgItemMessage (hDlg, IDC_HDF_CONTROLLER_UNIT, CB_ADDSTRING, 0, (LPARAM)_T("1"));
  13359. if (!ert || !(ert->deviceflags & (EXPANSIONTYPE_SASI | EXPANSIONTYPE_CUSTOM)) ) {
  13360. SendDlgItemMessage(hDlg, IDC_HDF_CONTROLLER_UNIT, CB_ADDSTRING, 0, (LPARAM)_T("2"));
  13361. SendDlgItemMessage(hDlg, IDC_HDF_CONTROLLER_UNIT, CB_ADDSTRING, 0, (LPARAM)_T("3"));
  13362. SendDlgItemMessage(hDlg, IDC_HDF_CONTROLLER_UNIT, CB_ADDSTRING, 0, (LPARAM)_T("4"));
  13363. SendDlgItemMessage(hDlg, IDC_HDF_CONTROLLER_UNIT, CB_ADDSTRING, 0, (LPARAM)_T("5"));
  13364. SendDlgItemMessage(hDlg, IDC_HDF_CONTROLLER_UNIT, CB_ADDSTRING, 0, (LPARAM)_T("6"));
  13365. SendDlgItemMessage(hDlg, IDC_HDF_CONTROLLER_UNIT, CB_ADDSTRING, 0, (LPARAM)_T("7"));
  13366. if (devtype == UAEDEV_HDF && ert && !_tcscmp(ert->name, _T("a2091")))
  13367. SendDlgItemMessage(hDlg, IDC_HDF_CONTROLLER_UNIT, CB_ADDSTRING, 0, (LPARAM)_T("XT"));
  13368. if (devtype == UAEDEV_HDF && ert && !_tcscmp(ert->name, _T("a2090a"))) {
  13369. SendDlgItemMessage(hDlg, IDC_HDF_CONTROLLER_UNIT, CB_ADDSTRING, 0, (LPARAM)_T("ST-506 #1"));
  13370. SendDlgItemMessage(hDlg, IDC_HDF_CONTROLLER_UNIT, CB_ADDSTRING, 0, (LPARAM)_T("ST-506 #2"));
  13371. }
  13372. }
  13373. if (media)
  13374. ew(hDlg, IDC_HDF_CONTROLLER_UNIT, TRUE);
  13375. } else if (ctype >= HD_CONTROLLER_TYPE_CUSTOM_FIRST && ctype <= HD_CONTROLLER_TYPE_CUSTOM_LAST) {
  13376. ew(hDlg, IDC_HDF_CONTROLLER_UNIT, FALSE);
  13377. } else if (ctype == HD_CONTROLLER_TYPE_UAE) {
  13378. for (int i = 0; i < MAX_FILESYSTEM_UNITS; i++) {
  13379. TCHAR tmp[100];
  13380. _stprintf(tmp, _T("%d"), i);
  13381. SendDlgItemMessage(hDlg, IDC_HDF_CONTROLLER_UNIT, CB_ADDSTRING, 0, (LPARAM)tmp);
  13382. }
  13383. if (media)
  13384. ew(hDlg, IDC_HDF_CONTROLLER_UNIT, TRUE);
  13385. } else {
  13386. ew(hDlg, IDC_HDF_CONTROLLER_UNIT, FALSE);
  13387. }
  13388. SendDlgItemMessage (hDlg, IDC_HDF_CONTROLLER_TYPE, CB_RESETCONTENT, 0, 0);
  13389. SendDlgItemMessage (hDlg, IDC_HDF_CONTROLLER_TYPE, CB_ADDSTRING, 0, (LPARAM)_T("HD"));
  13390. SendDlgItemMessage (hDlg, IDC_HDF_CONTROLLER_TYPE, CB_ADDSTRING, 0, (LPARAM)_T("CF"));
  13391. SendDlgItemMessage (hDlg, IDC_HDF_FEATURE_LEVEL, CB_RESETCONTENT, 0, 0);
  13392. if (ctype >= HD_CONTROLLER_TYPE_IDE_FIRST && ctype <= HD_CONTROLLER_TYPE_IDE_LAST) {
  13393. SendDlgItemMessage (hDlg, IDC_HDF_FEATURE_LEVEL, CB_ADDSTRING, 0, (LPARAM)_T("ATA-1"));
  13394. SendDlgItemMessage (hDlg, IDC_HDF_FEATURE_LEVEL, CB_ADDSTRING, 0, (LPARAM)_T("ATA-2+"));
  13395. SendDlgItemMessage (hDlg, IDC_HDF_FEATURE_LEVEL, CB_ADDSTRING, 0, (LPARAM)_T("ATA-2+ Strict"));
  13396. } else if (ctype >= HD_CONTROLLER_TYPE_SCSI_FIRST && ctype <= HD_CONTROLLER_TYPE_SCSI_LAST) {
  13397. const struct expansionromtype *ert = get_unit_expansion_rom(ctype);
  13398. SendDlgItemMessage (hDlg, IDC_HDF_FEATURE_LEVEL, CB_ADDSTRING, 0, (LPARAM)_T("SCSI-1"));
  13399. SendDlgItemMessage(hDlg, IDC_HDF_FEATURE_LEVEL, CB_ADDSTRING, 0, (LPARAM)_T("SCSI-2"));
  13400. if (ert && (ert->deviceflags & (EXPANSIONTYPE_CUSTOM | EXPANSIONTYPE_CUSTOM_SECONDARY | EXPANSIONTYPE_SASI))) {
  13401. SendDlgItemMessage(hDlg, IDC_HDF_FEATURE_LEVEL, CB_ADDSTRING, 0, (LPARAM)_T("SASI"));
  13402. SendDlgItemMessage(hDlg, IDC_HDF_FEATURE_LEVEL, CB_ADDSTRING, 0, (LPARAM)_T("SASI CHS"));
  13403. }
  13404. }
  13405. }
  13406. static void inithardfile (HWND hDlg, bool media)
  13407. {
  13408. TCHAR tmp[MAX_DPATH];
  13409. ew (hDlg, IDC_HF_DOSTYPE, FALSE);
  13410. ew (hDlg, IDC_HF_CREATE, FALSE);
  13411. inithdcontroller (hDlg, current_hfdlg.ci.controller_type, current_hfdlg.ci.controller_type_unit, UAEDEV_HDF, media);
  13412. SendDlgItemMessage (hDlg, IDC_HF_TYPE, CB_RESETCONTENT, 0, 0);
  13413. WIN32GUI_LoadUIString (IDS_HF_FS_CUSTOM, tmp, sizeof (tmp) / sizeof (TCHAR));
  13414. SendDlgItemMessage (hDlg, IDC_HF_TYPE, CB_ADDSTRING, 0, (LPARAM)_T("RDB/OFS/FFS"));
  13415. SendDlgItemMessage (hDlg, IDC_HF_TYPE, CB_ADDSTRING, 0, (LPARAM)_T("PFS3"));
  13416. SendDlgItemMessage (hDlg, IDC_HF_TYPE, CB_ADDSTRING, 0, (LPARAM)_T("PDS3"));
  13417. SendDlgItemMessage (hDlg, IDC_HF_TYPE, CB_ADDSTRING, 0, (LPARAM)_T("SFS"));
  13418. SendDlgItemMessage (hDlg, IDC_HF_TYPE, CB_ADDSTRING, 0, (LPARAM)tmp);
  13419. SendDlgItemMessage (hDlg, IDC_HF_TYPE, CB_SETCURSEL, 0, 0);
  13420. }
  13421. static void sethfdostype (HWND hDlg, int idx)
  13422. {
  13423. switch (idx)
  13424. {
  13425. case 1:
  13426. SetDlgItemText (hDlg, IDC_HF_DOSTYPE, _T("0x50465300"));
  13427. break;
  13428. case 2:
  13429. SetDlgItemText (hDlg, IDC_HF_DOSTYPE, _T("0x50445300"));
  13430. break;
  13431. case 3:
  13432. SetDlgItemText (hDlg, IDC_HF_DOSTYPE, _T("0x53465300"));
  13433. break;
  13434. default:
  13435. SetDlgItemText (hDlg, IDC_HF_DOSTYPE, _T(""));
  13436. break;
  13437. }
  13438. }
  13439. static void updatehdfinfo(HWND hDlg, bool force, bool defaults, bool realdrive)
  13440. {
  13441. uae_u8 id[512] = { 0 };
  13442. uae_u64 bsize;
  13443. uae_u32 blocks, cyls, i;
  13444. TCHAR tmp[200], tmp2[200];
  13445. TCHAR idtmp[17];
  13446. bool phys = is_hdf_rdb();
  13447. bsize = 0;
  13448. if (force) {
  13449. bool open = false;
  13450. bool gotrdb = false;
  13451. int blocksize = 512;
  13452. struct hardfiledata hfd;
  13453. memset (id, 0, sizeof id);
  13454. memset (&hfd, 0, sizeof hfd);
  13455. hfd.ci.readonly = true;
  13456. hfd.ci.blocksize = blocksize;
  13457. current_hfdlg.size = 0;
  13458. current_hfdlg.dostype = 0;
  13459. if (hdf_open (&hfd, current_hfdlg.ci.rootdir) > 0) {
  13460. open = true;
  13461. for (i = 0; i < 16; i++) {
  13462. hdf_read (&hfd, id, i * 512, 512);
  13463. bsize = hfd.virtsize;
  13464. current_hfdlg.size = hfd.virtsize;
  13465. if (!memcmp (id, "RDSK", 4) || !memcmp (id, "CDSK", 4)) {
  13466. blocksize = (id[16] << 24) | (id[17] << 16) | (id[18] << 8) | (id[19] << 0);
  13467. gotrdb = true;
  13468. break;
  13469. }
  13470. }
  13471. if (i == 16) {
  13472. hdf_read (&hfd, id, 0, 512);
  13473. current_hfdlg.dostype = (id[0] << 24) | (id[1] << 16) | (id[2] << 8) | (id[3] << 0);
  13474. }
  13475. }
  13476. if (defaults) {
  13477. if (blocksize > 512) {
  13478. hfd.ci.blocksize = blocksize;
  13479. }
  13480. }
  13481. if (hfd.ci.chs) {
  13482. current_hfdlg.ci.physical_geometry = true;
  13483. current_hfdlg.ci.chs = true;
  13484. current_hfdlg.ci.pcyls = hfd.ci.pcyls;
  13485. current_hfdlg.ci.pheads = hfd.ci.pheads;
  13486. current_hfdlg.ci.psecs = hfd.ci.psecs;
  13487. }
  13488. if (!current_hfdlg.ci.physical_geometry) {
  13489. if (current_hfdlg.ci.controller_type >= HD_CONTROLLER_TYPE_IDE_FIRST && current_hfdlg.ci.controller_type <= HD_CONTROLLER_TYPE_IDE_LAST) {
  13490. getchspgeometry (bsize, &current_hfdlg.ci.pcyls, &current_hfdlg.ci.pheads, &current_hfdlg.ci.psecs, true);
  13491. } else {
  13492. getchspgeometry (bsize, &current_hfdlg.ci.pcyls, &current_hfdlg.ci.pheads, &current_hfdlg.ci.psecs, false);
  13493. }
  13494. if (defaults && !gotrdb && !realdrive) {
  13495. gethdfgeometry(bsize, &current_hfdlg.ci);
  13496. phys = false;
  13497. }
  13498. } else {
  13499. current_hfdlg.forcedcylinders = current_hfdlg.ci.pcyls;
  13500. }
  13501. if (hDlg && (hfd.identity[0] || hfd.identity[1])) {
  13502. TCHAR ident[256];
  13503. int i;
  13504. for (i = 0; i < 11; i++) {
  13505. _stprintf(ident + i * 5, _T("%02X%02X."), hfd.identity[i * 2 + 1], hfd.identity[i * 2 + 0]);
  13506. }
  13507. ident[i * 5 - 1] = 0;
  13508. SetDlgItemText(hDlg, IDC_HDFINFO3, ident);
  13509. }
  13510. hdf_close (&hfd);
  13511. }
  13512. if (current_hfdlg.ci.controller_type >= HD_CONTROLLER_TYPE_IDE_FIRST && current_hfdlg.ci.controller_type <= HD_CONTROLLER_TYPE_IDE_LAST) {
  13513. if (current_hfdlg.ci.unit_feature_level == HD_LEVEL_ATA_1 && bsize >= 4 * (uae_u64)0x40000000)
  13514. current_hfdlg.ci.unit_feature_level = HD_LEVEL_ATA_2;
  13515. }
  13516. cyls = phys ? current_hfdlg.ci.pcyls : current_hfdlg.forcedcylinders;
  13517. int heads = phys ? current_hfdlg.ci.pheads : current_hfdlg.ci.surfaces;
  13518. int secs = phys ? current_hfdlg.ci.psecs : current_hfdlg.ci.sectors;
  13519. if (!cyls && current_hfdlg.ci.blocksize && secs && heads) {
  13520. cyls = bsize / ((uae_u64)current_hfdlg.ci.blocksize * secs * heads);
  13521. }
  13522. blocks = cyls * (secs * heads);
  13523. if (!blocks && current_hfdlg.ci.blocksize)
  13524. blocks = bsize / current_hfdlg.ci.blocksize;
  13525. if (current_hfdlg.ci.max_lba)
  13526. blocks = current_hfdlg.ci.max_lba;
  13527. for (i = 0; i < sizeof (idtmp) / sizeof (TCHAR) - 1; i++) {
  13528. TCHAR c = id[i];
  13529. if (c < 32 || c > 126)
  13530. c = '.';
  13531. idtmp[i] = c;
  13532. idtmp[i + 1] = 0;
  13533. }
  13534. tmp[0] = 0;
  13535. if (bsize) {
  13536. _stprintf (tmp2, _T(" %s [%02X%02X%02X%02X %02X%02X%02X%02X %02X%02X%02X%02X %02X%02X%02X%02X]"), idtmp,
  13537. id[0], id[1], id[2], id[3], id[4], id[5], id[6], id[7],
  13538. id[8], id[9], id[10], id[11], id[12], id[13], id[14], id[15]);
  13539. if (!blocks) {
  13540. _stprintf (tmp, _T("%uMB"), (unsigned int)(bsize / (1024 * 1024)));
  13541. } else if (blocks && !cyls) {
  13542. _stprintf (tmp, _T("%u blocks, %.1fMB"),
  13543. blocks,
  13544. (double)bsize / (1024.0 * 1024.0));
  13545. } else {
  13546. _stprintf (tmp, _T("%u/%u/%u, %u/%u blocks, %.1fMB/%.1fMB"),
  13547. cyls, heads, secs,
  13548. blocks, (int)(bsize / current_hfdlg.ci.blocksize),
  13549. (double)blocks * 1.0 * current_hfdlg.ci.blocksize / (1024.0 * 1024.0),
  13550. (double)bsize / (1024.0 * 1024.0));
  13551. if ((uae_u64)cyls * heads * secs > bsize / current_hfdlg.ci.blocksize) {
  13552. _tcscat (tmp2, _T(" [Geometry larger than drive!]"));
  13553. } else if (cyls > 65535) {
  13554. _tcscat (tmp2, _T(" [Too many cyls]"));
  13555. }
  13556. }
  13557. if (hDlg != NULL) {
  13558. SetDlgItemText(hDlg, IDC_HDFINFO, tmp);
  13559. SetDlgItemText(hDlg, IDC_HDFINFO2, tmp2);
  13560. }
  13561. }
  13562. }
  13563. static void hardfileselecthdf (HWND hDlg, TCHAR *newpath, bool ask, bool newhd)
  13564. {
  13565. if (ask) {
  13566. DiskSelection (hDlg, IDC_PATH_NAME, 2, &workprefs, NULL, newpath);
  13567. GetDlgItemText (hDlg, IDC_PATH_NAME, current_hfdlg.ci.rootdir, sizeof current_hfdlg.ci.rootdir / sizeof (TCHAR));
  13568. DISK_history_add(current_hfdlg.ci.rootdir, -1, HISTORY_HDF, 1);
  13569. }
  13570. fullpath (current_hfdlg.ci.rootdir, sizeof current_hfdlg.ci.rootdir / sizeof (TCHAR));
  13571. if (newhd) {
  13572. // Set RDB mode if IDE or SCSI
  13573. if (current_hfdlg.ci.controller_type > 0) {
  13574. current_hfdlg.ci.sectors = current_hfdlg.ci.reserved = current_hfdlg.ci.surfaces = 0;
  13575. }
  13576. }
  13577. inithardfile (hDlg, true);
  13578. hardfile_testrdb (&current_hfdlg);
  13579. updatehdfinfo (hDlg, true, true, false);
  13580. get_hd_geometry (&current_hfdlg.ci);
  13581. updatehdfinfo (hDlg, false, false, false);
  13582. sethardfile (hDlg);
  13583. }
  13584. static void hardfilecreatehdf (HWND hDlg, TCHAR *newpath)
  13585. {
  13586. TCHAR hdfpath[MAX_DPATH];
  13587. LRESULT res;
  13588. uae_s64 setting = CalculateHardfileSize (hDlg);
  13589. TCHAR dostype[16];
  13590. GetDlgItemText (hDlg, IDC_HF_DOSTYPE, dostype, sizeof (dostype) / sizeof (TCHAR));
  13591. res = SendDlgItemMessage (hDlg, IDC_HF_TYPE, CB_GETCURSEL, 0, 0);
  13592. if (res == 0)
  13593. dostype[0] = 0;
  13594. if (CreateHardFile (hDlg, setting, dostype, newpath, hdfpath)) {
  13595. if (!current_hfdlg.ci.rootdir[0]) {
  13596. fullpath (hdfpath, sizeof hdfpath / sizeof (TCHAR));
  13597. _tcscpy (current_hfdlg.ci.rootdir, hdfpath);
  13598. }
  13599. }
  13600. sethardfile (hDlg);
  13601. }
  13602. static INT_PTR CALLBACK TapeDriveSettingsProc (HWND hDlg, UINT msg, WPARAM wParam, LPARAM lParam)
  13603. {
  13604. static int recursive = 0;
  13605. int posn, readonly;
  13606. TCHAR tmp[MAX_DPATH];
  13607. if (dialog_inhibit)
  13608. return 0;
  13609. switch (msg) {
  13610. case WM_INITDIALOG:
  13611. recursive++;
  13612. inithdcontroller(hDlg, current_tapedlg.ci.controller_type, current_tapedlg.ci.controller_type_unit, UAEDEV_TAPE, current_tapedlg.ci.rootdir[0] != 0);
  13613. SendDlgItemMessage(hDlg, IDC_HDF_CONTROLLER_UNIT, CB_SETCURSEL, current_tapedlg.ci.controller_unit, 0);
  13614. setautocomplete (hDlg, IDC_PATH_NAME);
  13615. addhistorymenu(hDlg, current_tapedlg.ci.rootdir, IDC_PATH_NAME, HISTORY_TAPE, false, -1);
  13616. readonly = !tape_can_write(current_tapedlg.ci.rootdir);
  13617. CheckDlgButton (hDlg, IDC_TAPE_RW, current_tapedlg.ci.readonly == 0 && !readonly);
  13618. ew (hDlg, IDC_TAPE_RW, !readonly);
  13619. recursive--;
  13620. customDlgType = IDD_TAPEDRIVE;
  13621. customDlg = hDlg;
  13622. return TRUE;
  13623. case WM_COMMAND:
  13624. if (HIWORD (wParam) == CBN_SELCHANGE || HIWORD (wParam) == CBN_KILLFOCUS) {
  13625. switch (LOWORD (wParam))
  13626. {
  13627. case IDC_PATH_NAME:
  13628. if (getcomboboxtext(hDlg, IDC_PATH_NAME, tmp, sizeof tmp / sizeof(TCHAR))) {
  13629. if (_tcscmp (tmp, current_tapedlg.ci.rootdir)) {
  13630. _tcscpy (current_tapedlg.ci.rootdir, tmp);
  13631. readonly = !tape_can_write(current_tapedlg.ci.rootdir);
  13632. ew (hDlg, IDC_TAPE_RW, !readonly);
  13633. if (readonly)
  13634. CheckDlgButton (hDlg, IDC_TAPE_RW, FALSE);
  13635. }
  13636. }
  13637. break;
  13638. case IDC_HDF_CONTROLLER:
  13639. posn = gui_get_string_cursor(hdmenutable, hDlg, IDC_HDF_CONTROLLER);
  13640. if (posn != CB_ERR) {
  13641. current_tapedlg.ci.controller_type = posn % HD_CONTROLLER_NEXT_UNIT;
  13642. current_tapedlg.ci.controller_type_unit = posn / HD_CONTROLLER_NEXT_UNIT;
  13643. inithdcontroller(hDlg, current_tapedlg.ci.controller_type, current_tapedlg.ci.controller_type_unit, UAEDEV_TAPE, current_tapedlg.ci.rootdir);
  13644. SendDlgItemMessage(hDlg, IDC_HDF_CONTROLLER_UNIT, CB_SETCURSEL, current_tapedlg.ci.controller_unit, 0);
  13645. }
  13646. break;
  13647. case IDC_HDF_CONTROLLER_UNIT:
  13648. posn = SendDlgItemMessage (hDlg, IDC_HDF_CONTROLLER_UNIT, CB_GETCURSEL, 0, 0);
  13649. if (posn != CB_ERR) {
  13650. current_tapedlg.ci.controller_unit = posn;
  13651. }
  13652. break;
  13653. }
  13654. }
  13655. if (recursive)
  13656. break;
  13657. recursive++;
  13658. switch (LOWORD (wParam))
  13659. {
  13660. case IDC_TAPE_EJECT:
  13661. current_tapedlg.ci.rootdir[0] = 0;
  13662. SetDlgItemText(hDlg, IDC_PATH_NAME, current_tapedlg.ci.rootdir);
  13663. break;
  13664. case IDC_TAPE_SELECT_FILE:
  13665. DiskSelection (hDlg, IDC_PATH_NAME, 18, &workprefs, NULL, NULL);
  13666. GetDlgItemText (hDlg, IDC_PATH_NAME, current_tapedlg.ci.rootdir, sizeof current_tapedlg.ci.rootdir / sizeof (TCHAR));
  13667. DISK_history_add(current_tapedlg.ci.rootdir, -1, HISTORY_TAPE, 1);
  13668. fullpath (current_tapedlg.ci.rootdir, sizeof current_tapedlg.ci.rootdir / sizeof (TCHAR));
  13669. readonly = !tape_can_write(current_tapedlg.ci.rootdir);
  13670. ew (hDlg, IDC_TAPE_RW, !readonly);
  13671. if (readonly)
  13672. CheckDlgButton (hDlg, IDC_TAPE_RW, FALSE);
  13673. break;
  13674. case IDC_TAPE_SELECT_DIR:
  13675. {
  13676. const GUID volumeguid = { 0xb95772a5, 0x8444, 0x48d8, { 0xab, 0x9a, 0xef, 0x3c, 0x62, 0x11, 0x3a, 0x37 } };
  13677. TCHAR directory_path[MAX_DPATH];
  13678. _tcscpy (directory_path, current_tapedlg.ci.rootdir);
  13679. if (directory_path[0] == 0) {
  13680. int out = sizeof directory_path / sizeof (TCHAR);
  13681. regquerystr (NULL, _T("TapeDirectoryPath"), directory_path, &out);
  13682. }
  13683. if (DirectorySelection (hDlg, &volumeguid, directory_path)) {
  13684. regsetstr (NULL, _T("TapeDirectoryPath"), directory_path);
  13685. SetDlgItemText (hDlg, IDC_PATH_NAME, directory_path);
  13686. }
  13687. _tcscpy (current_tapedlg.ci.rootdir, directory_path);
  13688. DISK_history_add(current_tapedlg.ci.rootdir, -1, HISTORY_TAPE, 1);
  13689. readonly = !tape_can_write(current_tapedlg.ci.rootdir);
  13690. ew (hDlg, IDC_TAPE_RW, !readonly);
  13691. if (readonly)
  13692. CheckDlgButton (hDlg, IDC_TAPE_RW, FALSE);
  13693. break;
  13694. }
  13695. case IDOK:
  13696. EndDialog (hDlg, 1);
  13697. break;
  13698. case IDCANCEL:
  13699. EndDialog (hDlg, 0);
  13700. break;
  13701. }
  13702. current_tapedlg.ci.readonly = !ischecked (hDlg, IDC_TAPE_RW);
  13703. recursive--;
  13704. break;
  13705. }
  13706. commonproc(hDlg, msg, wParam, lParam);
  13707. return FALSE;
  13708. }
  13709. static INT_PTR CALLBACK CDDriveSettingsProc (HWND hDlg, UINT msg, WPARAM wParam, LPARAM lParam)
  13710. {
  13711. static int recursive = 0;
  13712. int posn;
  13713. if (dialog_inhibit)
  13714. return 0;
  13715. switch (msg) {
  13716. case WM_INITDIALOG:
  13717. recursive++;
  13718. if (current_cddlg.ci.controller_type == HD_CONTROLLER_TYPE_UAE)
  13719. current_cddlg.ci.controller_type = (is_board_enabled(&workprefs, ROMTYPE_A2091, 0) ||
  13720. is_board_enabled(&workprefs, ROMTYPE_GVPS2, 0) || is_board_enabled(&workprefs, ROMTYPE_A4091, 0) ||
  13721. (workprefs.cs_mbdmac & 3)) ? HD_CONTROLLER_TYPE_SCSI_AUTO : HD_CONTROLLER_TYPE_IDE_AUTO;
  13722. inithdcontroller(hDlg, current_cddlg.ci.controller_type, current_cddlg.ci.controller_type_unit, UAEDEV_CD, current_cddlg.ci.rootdir[0] != 0);
  13723. SendDlgItemMessage(hDlg, IDC_HDF_CONTROLLER_UNIT, CB_SETCURSEL, current_cddlg.ci.controller_unit, 0);
  13724. InitializeListView (hDlg);
  13725. recursive--;
  13726. customDlgType = IDD_CDDRIVE;
  13727. customDlg = hDlg;
  13728. return TRUE;
  13729. case WM_NOTIFY:
  13730. if (((LPNMHDR) lParam)->idFrom == IDC_CDLIST) {
  13731. NM_LISTVIEW *nmlistview = (NM_LISTVIEW *)lParam;
  13732. if (nmlistview->hdr.code == NM_DBLCLK)
  13733. EndDialog (hDlg, 1);
  13734. }
  13735. break;
  13736. case WM_COMMAND:
  13737. if (recursive)
  13738. break;
  13739. recursive++;
  13740. switch (LOWORD (wParam))
  13741. {
  13742. case IDOK:
  13743. EndDialog (hDlg, 1);
  13744. break;
  13745. case IDCANCEL:
  13746. EndDialog (hDlg, 0);
  13747. break;
  13748. case IDC_HDF_CONTROLLER:
  13749. posn = gui_get_string_cursor(hdmenutable, hDlg, IDC_HDF_CONTROLLER);
  13750. if (posn != CB_ERR) {
  13751. current_cddlg.ci.controller_type = posn % HD_CONTROLLER_NEXT_UNIT;
  13752. current_cddlg.ci.controller_type_unit = posn / HD_CONTROLLER_NEXT_UNIT;
  13753. inithdcontroller(hDlg, current_cddlg.ci.controller_type, current_cddlg.ci.controller_type_unit, UAEDEV_CD, current_cddlg.ci.rootdir[0] != 0);
  13754. SendDlgItemMessage(hDlg, IDC_HDF_CONTROLLER_UNIT, CB_SETCURSEL, current_cddlg.ci.controller_unit, 0);
  13755. }
  13756. break;
  13757. case IDC_HDF_CONTROLLER_UNIT:
  13758. posn = SendDlgItemMessage (hDlg, IDC_HDF_CONTROLLER_UNIT, CB_GETCURSEL, 0, 0);
  13759. if (posn != CB_ERR) {
  13760. current_cddlg.ci.controller_unit = posn;
  13761. }
  13762. break;
  13763. }
  13764. recursive--;
  13765. break;
  13766. }
  13767. commonproc(hDlg, msg, wParam, lParam);
  13768. return FALSE;
  13769. }
  13770. static void set_phys_cyls(HWND hDlg)
  13771. {
  13772. if (ischecked(hDlg, IDC_HDF_PHYSGEOMETRY)) {
  13773. int v = (current_hfdlg.ci.pheads * current_hfdlg.ci.psecs * current_hfdlg.ci.blocksize);
  13774. current_hfdlg.ci.pcyls = v ? current_hfdlg.size / v : 0;
  13775. current_hfdlg.ci.physical_geometry = true;
  13776. SetDlgItemInt (hDlg, IDC_RESERVED, current_hfdlg.ci.pcyls, FALSE);
  13777. }
  13778. }
  13779. static void restore_hd_geom(struct uaedev_config_info *dst, struct uaedev_config_info *src)
  13780. {
  13781. _tcscpy(dst->filesys, src->filesys);
  13782. _tcscpy(dst->devname, src->devname);
  13783. dst->controller_type = src->controller_type;
  13784. dst->controller_type_unit = src->controller_type_unit;
  13785. dst->controller_unit = src->controller_unit;
  13786. dst->controller_media_type = src->controller_media_type;
  13787. dst->unit_feature_level = src->unit_feature_level;
  13788. dst->bootpri = src->bootpri;
  13789. dst->readonly = src->readonly;
  13790. dst->physical_geometry = src->physical_geometry;
  13791. if (src->physical_geometry) {
  13792. dst->cyls = dst->sectors = dst->surfaces = dst->reserved = 0;
  13793. dst->pcyls = src->pcyls;
  13794. dst->pheads = src->pheads;
  13795. dst->psecs = src->psecs;
  13796. }
  13797. }
  13798. static INT_PTR CALLBACK HardfileSettingsProc (HWND hDlg, UINT msg, WPARAM wParam, LPARAM lParam)
  13799. {
  13800. static int recursive = 0;
  13801. LRESULT res, posn;
  13802. TCHAR tmp[MAX_DPATH];
  13803. int v;
  13804. int *p;
  13805. if (dialog_inhibit)
  13806. return 0;
  13807. switch (msg) {
  13808. case WM_DROPFILES:
  13809. dragdrop (hDlg, (HDROP)wParam, &changed_prefs, -2);
  13810. return FALSE;
  13811. case WM_INITDIALOG:
  13812. recursive++;
  13813. setchecked(hDlg, IDC_HDF_PHYSGEOMETRY, current_hfdlg.ci.physical_geometry);
  13814. setautocomplete (hDlg, IDC_PATH_NAME);
  13815. setautocomplete (hDlg, IDC_PATH_FILESYS);
  13816. setautocomplete (hDlg, IDC_PATH_GEOMETRY);
  13817. addhistorymenu(hDlg, current_hfdlg.ci.geometry, IDC_PATH_GEOMETRY, HISTORY_GEO, false, -1);
  13818. inithardfile (hDlg, current_hfdlg.ci.rootdir[0] != 0);
  13819. addhistorymenu(hDlg, current_hfdlg.ci.rootdir, IDC_PATH_NAME, HISTORY_HDF, false, -1);
  13820. addhistorymenu(hDlg, current_hfdlg.ci.filesys, IDC_PATH_FILESYS, HISTORY_FS, false, -1);
  13821. updatehdfinfo (hDlg, true, false, false);
  13822. sethardfile (hDlg);
  13823. sethfdostype (hDlg, 0);
  13824. setac (hDlg, IDC_PATH_NAME);
  13825. recursive--;
  13826. customDlgType = IDD_HARDFILE;
  13827. customDlg = hDlg;
  13828. return TRUE;
  13829. case WM_CONTEXTMENU:
  13830. if (GetDlgCtrlID ((HWND)wParam) == IDC_SELECTOR) {
  13831. TCHAR *s = favoritepopup (hDlg);
  13832. if (s) {
  13833. TCHAR path[MAX_DPATH];
  13834. _tcscpy (path, s);
  13835. xfree (s);
  13836. hardfileselecthdf (hDlg, path, true, false);
  13837. }
  13838. } else if (GetDlgCtrlID ((HWND)wParam) == IDC_FILESYS_SELECTOR) {
  13839. TCHAR *s = favoritepopup (hDlg);
  13840. if (s) {
  13841. TCHAR path[MAX_DPATH];
  13842. _tcscpy (path, s);
  13843. xfree (s);
  13844. DiskSelection (hDlg, IDC_PATH_FILESYS, 12, &workprefs, NULL, path);
  13845. }
  13846. } else if (GetDlgCtrlID ((HWND)wParam) == IDC_HF_CREATE) {
  13847. TCHAR *s = favoritepopup (hDlg);
  13848. if (s) {
  13849. TCHAR path[MAX_DPATH];
  13850. _tcscpy (path, s);
  13851. xfree (s);
  13852. hardfilecreatehdf (hDlg, path);
  13853. }
  13854. }
  13855. break;
  13856. case WM_COMMAND:
  13857. if (HIWORD (wParam) == CBN_SELCHANGE || HIWORD (wParam) == CBN_KILLFOCUS) {
  13858. switch (LOWORD (wParam)) {
  13859. case IDC_PATH_GEOMETRY:
  13860. getcomboboxtext(hDlg, IDC_PATH_GEOMETRY, current_hfdlg.ci.geometry, sizeof current_hfdlg.ci.geometry / sizeof(TCHAR));
  13861. if (HIWORD (wParam) == CBN_KILLFOCUS) {
  13862. addhistorymenu(hDlg, current_hfdlg.ci.geometry, IDC_PATH_GEOMETRY, HISTORY_GEO, false, -1);
  13863. sethardfile(hDlg);
  13864. updatehdfinfo (hDlg, true, false, false);
  13865. }
  13866. break;
  13867. case IDC_PATH_NAME:
  13868. if (getcomboboxtext(hDlg, IDC_PATH_NAME, tmp, sizeof tmp / sizeof(TCHAR))) {
  13869. if (_tcscmp (tmp, current_hfdlg.ci.rootdir)) {
  13870. _tcscpy (current_hfdlg.ci.rootdir, tmp);
  13871. recursive++;
  13872. hardfileselecthdf (hDlg, NULL, false, false);
  13873. recursive--;
  13874. }
  13875. }
  13876. if (HIWORD (wParam) == CBN_KILLFOCUS) {
  13877. addhistorymenu(hDlg, current_hfdlg.ci.rootdir, IDC_PATH_NAME, HISTORY_HDF, false, -1);
  13878. }
  13879. break;
  13880. case IDC_PATH_FILESYS:
  13881. getcomboboxtext(hDlg, IDC_PATH_FILESYS, current_hfdlg.ci.filesys, sizeof current_hfdlg.ci.filesys / sizeof(TCHAR));
  13882. if (HIWORD(wParam) == CBN_KILLFOCUS) {
  13883. addhistorymenu(hDlg, current_hfdlg.ci.filesys, IDC_PATH_FILESYS, HISTORY_FS, false, -1);
  13884. }
  13885. break;
  13886. }
  13887. }
  13888. if (recursive)
  13889. break;
  13890. recursive++;
  13891. if (HIWORD(wParam) == CBN_SELCHANGE || HIWORD(wParam) == CBN_KILLFOCUS) {
  13892. switch (LOWORD(wParam))
  13893. {
  13894. case IDC_HDF_CONTROLLER:
  13895. posn = gui_get_string_cursor(hdmenutable, hDlg, IDC_HDF_CONTROLLER);
  13896. if (posn != CB_ERR) {
  13897. current_hfdlg.ci.controller_type = posn % HD_CONTROLLER_NEXT_UNIT;
  13898. current_hfdlg.ci.controller_type_unit = posn / HD_CONTROLLER_NEXT_UNIT;
  13899. inithdcontroller(hDlg, current_hfdlg.ci.controller_type, current_hfdlg.ci.controller_type_unit, UAEDEV_HDF, current_hfdlg.ci.rootdir[0] != 0);
  13900. sethardfile(hDlg);
  13901. }
  13902. break;
  13903. case IDC_HDF_CONTROLLER_UNIT:
  13904. posn = SendDlgItemMessage(hDlg, IDC_HDF_CONTROLLER_UNIT, CB_GETCURSEL, 0, 0);
  13905. if (posn != CB_ERR) {
  13906. current_hfdlg.ci.controller_unit = posn;
  13907. sethardfile(hDlg);
  13908. }
  13909. break;
  13910. case IDC_HDF_CONTROLLER_TYPE:
  13911. posn = SendDlgItemMessage(hDlg, IDC_HDF_CONTROLLER_TYPE, CB_GETCURSEL, 0, 0);
  13912. if (posn != CB_ERR) {
  13913. current_hfdlg.ci.controller_media_type = posn;
  13914. sethardfile(hDlg);
  13915. }
  13916. break;
  13917. case IDC_HDF_FEATURE_LEVEL:
  13918. posn = SendDlgItemMessage(hDlg, IDC_HDF_FEATURE_LEVEL, CB_GETCURSEL, 0, 0);
  13919. if (posn != CB_ERR) {
  13920. current_hfdlg.ci.unit_feature_level = posn;
  13921. sethardfile(hDlg);
  13922. }
  13923. break;
  13924. }
  13925. }
  13926. switch (LOWORD (wParam)) {
  13927. case IDC_HF_SIZE:
  13928. ew (hDlg, IDC_HF_CREATE, CalculateHardfileSize (hDlg) > 0);
  13929. break;
  13930. case IDC_HF_TYPE:
  13931. res = SendDlgItemMessage (hDlg, IDC_HF_TYPE, CB_GETCURSEL, 0, 0);
  13932. sethfdostype (hDlg, (int)res);
  13933. ew (hDlg, IDC_HF_DOSTYPE, res >= 4);
  13934. break;
  13935. case IDC_HF_CREATE:
  13936. {
  13937. struct uaedev_config_info citmp;
  13938. memcpy(&citmp, &current_hfdlg.ci, sizeof citmp);
  13939. default_hfdlg (&current_hfdlg, false);
  13940. restore_hd_geom(&current_hfdlg.ci, &citmp);
  13941. hardfilecreatehdf (hDlg, NULL);
  13942. }
  13943. break;
  13944. case IDC_SELECTOR:
  13945. {
  13946. bool newhd = current_hfdlg.ci.rootdir[0] == 0;
  13947. struct uaedev_config_info citmp;
  13948. memcpy(&citmp, &current_hfdlg.ci, sizeof citmp);
  13949. default_hfdlg (&current_hfdlg, false);
  13950. restore_hd_geom(&current_hfdlg.ci, &citmp);
  13951. hardfileselecthdf (hDlg, NULL, true, newhd);
  13952. }
  13953. break;
  13954. case IDC_FILESYS_SELECTOR:
  13955. DiskSelection (hDlg, IDC_PATH_FILESYS, 12, &workprefs, NULL, NULL);
  13956. getcomboboxtext(hDlg, IDC_PATH_FILESYS, current_hfdlg.ci.filesys, sizeof current_hfdlg.ci.filesys / sizeof(TCHAR));
  13957. DISK_history_add(current_hfdlg.ci.filesys, -1, HISTORY_FS, 1);
  13958. break;
  13959. case IDOK:
  13960. EndDialog (hDlg, 1);
  13961. break;
  13962. case IDCANCEL:
  13963. EndDialog (hDlg, 0);
  13964. break;
  13965. case IDC_HDF_PHYSGEOMETRY:
  13966. current_hfdlg.ci.physical_geometry = ischecked(hDlg, IDC_HDF_PHYSGEOMETRY);
  13967. updatehdfinfo(hDlg, true, false, false);
  13968. sethardfile(hDlg);
  13969. break;
  13970. case IDC_HDF_RW:
  13971. current_hfdlg.ci.readonly = !ischecked (hDlg, IDC_HDF_RW);
  13972. break;
  13973. case IDC_HDF_AUTOBOOT:
  13974. if (ischecked (hDlg, IDC_HDF_AUTOBOOT)) {
  13975. current_hfdlg.ci.bootpri = 0;
  13976. setchecked (hDlg, IDC_HDF_DONOTMOUNT, false);
  13977. } else {
  13978. current_hfdlg.ci.bootpri = BOOTPRI_NOAUTOBOOT;
  13979. }
  13980. SetDlgItemInt (hDlg, IDC_HARDFILE_BOOTPRI, current_hfdlg.ci.bootpri, TRUE);
  13981. break;
  13982. case IDC_HDF_DONOTMOUNT:
  13983. if (ischecked (hDlg, IDC_HDF_DONOTMOUNT)) {
  13984. current_hfdlg.ci.bootpri = BOOTPRI_NOAUTOMOUNT;
  13985. setchecked (hDlg, IDC_HDF_AUTOBOOT, false);
  13986. } else {
  13987. current_hfdlg.ci.bootpri = BOOTPRI_NOAUTOBOOT;
  13988. setchecked (hDlg, IDC_HDF_AUTOBOOT, true);
  13989. }
  13990. SetDlgItemInt (hDlg, IDC_HARDFILE_BOOTPRI, current_hfdlg.ci.bootpri, TRUE);
  13991. break;
  13992. case IDC_HDF_RDB:
  13993. SetDlgItemText (hDlg, IDC_PATH_FILESYS, _T(""));
  13994. SetDlgItemText (hDlg, IDC_HARDFILE_DEVICE, _T(""));
  13995. current_hfdlg.ci.sectors = current_hfdlg.ci.reserved = current_hfdlg.ci.surfaces = 0;
  13996. current_hfdlg.ci.bootpri = 0;
  13997. sethardfile (hDlg);
  13998. break;
  13999. case IDC_PATH_GEOMETRY_SELECTOR:
  14000. if (DiskSelection (hDlg, IDC_PATH_GEOMETRY, 23, &workprefs, NULL, current_hfdlg.ci.geometry)) {
  14001. DISK_history_add(current_hfdlg.ci.geometry, -1, HISTORY_GEO, 1);
  14002. sethardfile(hDlg);
  14003. updatehdfinfo (hDlg, true, false, false);
  14004. }
  14005. break;
  14006. case IDC_SECTORS:
  14007. p = ischecked(hDlg, IDC_HDF_PHYSGEOMETRY) ? &current_hfdlg.ci.psecs : &current_hfdlg.ci.sectors;
  14008. v = *p;
  14009. *p = GetDlgItemInt (hDlg, IDC_SECTORS, NULL, FALSE);
  14010. if (v != *p) {
  14011. set_phys_cyls(hDlg);
  14012. updatehdfinfo (hDlg, true, false, false);
  14013. ew (hDlg, IDC_HDF_RDB, !is_hdf_rdb ());
  14014. }
  14015. break;
  14016. case IDC_RESERVED:
  14017. p = ischecked(hDlg, IDC_HDF_PHYSGEOMETRY) ? &current_hfdlg.ci.pcyls : &current_hfdlg.ci.reserved;
  14018. v = *p;
  14019. *p = GetDlgItemInt (hDlg, IDC_RESERVED, NULL, FALSE);
  14020. if (v != *p) {
  14021. if (ischecked(hDlg, IDC_HDF_PHYSGEOMETRY)) {
  14022. current_hfdlg.ci.physical_geometry = true;
  14023. }
  14024. updatehdfinfo (hDlg, true, false, false);
  14025. ew (hDlg, IDC_HDF_RDB, !is_hdf_rdb ());
  14026. }
  14027. break;
  14028. case IDC_HEADS:
  14029. p = ischecked(hDlg, IDC_HDF_PHYSGEOMETRY) ? &current_hfdlg.ci.pheads : &current_hfdlg.ci.surfaces;
  14030. v = *p;
  14031. *p = GetDlgItemInt (hDlg, IDC_HEADS, NULL, FALSE);
  14032. if (v != *p) {
  14033. set_phys_cyls(hDlg);
  14034. updatehdfinfo (hDlg, true, false, false);
  14035. ew (hDlg, IDC_HDF_RDB, !is_hdf_rdb ());
  14036. }
  14037. break;
  14038. case IDC_BLOCKSIZE:
  14039. v = current_hfdlg.ci.blocksize;
  14040. current_hfdlg.ci.blocksize = GetDlgItemInt (hDlg, IDC_BLOCKSIZE, NULL, FALSE);
  14041. if (v != current_hfdlg.ci.blocksize)
  14042. updatehdfinfo (hDlg, true, false, false);
  14043. break;
  14044. case IDC_HARDFILE_BOOTPRI:
  14045. current_hfdlg.ci.bootpri = GetDlgItemInt (hDlg, IDC_HARDFILE_BOOTPRI, NULL, TRUE);
  14046. if (current_hfdlg.ci.bootpri < -127)
  14047. current_hfdlg.ci.bootpri = -127;
  14048. if (current_hfdlg.ci.bootpri > 127)
  14049. current_hfdlg.ci.bootpri = 127;
  14050. break;
  14051. case IDC_HARDFILE_DEVICE:
  14052. GetDlgItemText (hDlg, IDC_HARDFILE_DEVICE, current_hfdlg.ci.devname, sizeof current_hfdlg.ci.devname / sizeof (TCHAR));
  14053. break;
  14054. }
  14055. recursive--;
  14056. break;
  14057. }
  14058. commonproc(hDlg, msg, wParam, lParam);
  14059. return FALSE;
  14060. }
  14061. extern int harddrive_to_hdf (HWND, struct uae_prefs*, int);
  14062. static INT_PTR CALLBACK HarddriveSettingsProc (HWND hDlg, UINT msg, WPARAM wParam, LPARAM lParam)
  14063. {
  14064. static int recursive = 0;
  14065. int v, i;
  14066. int *p;
  14067. LRESULT posn;
  14068. static int oposn;
  14069. if (dialog_inhibit)
  14070. return 0;
  14071. switch (msg) {
  14072. case WM_INITDIALOG:
  14073. {
  14074. int index;
  14075. oposn = -1;
  14076. hdf_init_target ();
  14077. recursive++;
  14078. setautocomplete (hDlg, IDC_PATH_GEOMETRY);
  14079. addhistorymenu(hDlg, current_hfdlg.ci.geometry, IDC_PATH_GEOMETRY, HISTORY_GEO, false, -1);
  14080. setchecked(hDlg, IDC_HDF_PHYSGEOMETRY, current_hfdlg.ci.physical_geometry);
  14081. setharddrive(hDlg);
  14082. inithdcontroller(hDlg, current_hfdlg.ci.controller_type, current_hfdlg.ci.controller_type_unit, UAEDEV_HDF, current_hfdlg.ci.rootdir[0] != 0);
  14083. CheckDlgButton (hDlg, IDC_HDF_RW, !current_hfdlg.ci.readonly);
  14084. CheckDlgButton(hDlg, IDC_HDF_LOCK, current_hfdlg.ci.lock);
  14085. CheckDlgButton(hDlg, IDC_HDF_IDENTITY, current_hfdlg.ci.loadidentity);
  14086. SendDlgItemMessage (hDlg, IDC_HARDDRIVE, CB_RESETCONTENT, 0, 0);
  14087. ew (hDlg, IDC_HARDDRIVE_IMAGE, FALSE);
  14088. index = -1;
  14089. for (i = 0; i < hdf_getnumharddrives (); i++) {
  14090. SendDlgItemMessage (hDlg, IDC_HARDDRIVE, CB_ADDSTRING, 0, (LPARAM)hdf_getnameharddrive (i, 1, NULL, NULL, NULL));
  14091. TCHAR *name1 = hdf_getnameharddrive (i, 4, NULL, NULL, NULL);
  14092. TCHAR *name2 = hdf_getnameharddrive (i, 2, NULL, NULL, NULL);
  14093. TCHAR *name3 = hdf_getnameharddrive (i, 0, NULL, NULL, NULL);
  14094. if (!_tcscmp (current_hfdlg.ci.rootdir, name1) || !_tcscmp (current_hfdlg.ci.rootdir, name2) || !_tcscmp (current_hfdlg.ci.rootdir, name3))
  14095. index = i;
  14096. }
  14097. if (index >= 0) {
  14098. SendDlgItemMessage (hDlg, IDC_HARDDRIVE, CB_SETCURSEL, index, 0);
  14099. gui_set_string_cursor(hdmenutable, hDlg, IDC_HDF_CONTROLLER, current_hfdlg.ci.controller_type + current_hfdlg.ci.controller_type_unit * HD_CONTROLLER_NEXT_UNIT);
  14100. SendDlgItemMessage(hDlg, IDC_HDF_CONTROLLER_UNIT, CB_SETCURSEL, current_hfdlg.ci.controller_unit, 0);
  14101. SendDlgItemMessage(hDlg, IDC_HDF_CONTROLLER_TYPE, CB_SETCURSEL, current_hfdlg.ci.controller_media_type, 0);
  14102. SendDlgItemMessage(hDlg, IDC_HDF_FEATURE_LEVEL, CB_SETCURSEL, current_hfdlg.ci.unit_feature_level, 0);
  14103. }
  14104. recursive--;
  14105. return TRUE;
  14106. }
  14107. case WM_COMMAND:
  14108. if (recursive)
  14109. break;
  14110. recursive++;
  14111. if (HIWORD(wParam) == CBN_SELCHANGE || HIWORD(wParam) == CBN_KILLFOCUS) {
  14112. switch (LOWORD(wParam)) {
  14113. case IDC_PATH_GEOMETRY:
  14114. getcomboboxtext(hDlg, IDC_PATH_GEOMETRY, current_hfdlg.ci.geometry, sizeof current_hfdlg.ci.geometry / sizeof(TCHAR));
  14115. if (HIWORD (wParam) == CBN_KILLFOCUS) {
  14116. addhistorymenu(hDlg, current_hfdlg.ci.geometry, IDC_PATH_GEOMETRY, HISTORY_GEO, false, -1);
  14117. setharddrive(hDlg);
  14118. updatehdfinfo (hDlg, true, false, true);
  14119. }
  14120. break;
  14121. }
  14122. }
  14123. if (HIWORD (wParam) == BN_CLICKED) {
  14124. switch (LOWORD (wParam)) {
  14125. case IDOK:
  14126. EndDialog (hDlg, 1);
  14127. break;
  14128. case IDCANCEL:
  14129. EndDialog (hDlg, 0);
  14130. break;
  14131. case IDC_HDF_PHYSGEOMETRY:
  14132. current_hfdlg.ci.physical_geometry = ischecked(hDlg, IDC_HDF_PHYSGEOMETRY);
  14133. updatehdfinfo(hDlg, true, false, true);
  14134. setharddrive(hDlg);
  14135. break;
  14136. case IDC_HARDDRIVE_ID:
  14137. if (oposn >= 0) {
  14138. void hd_get_meta(HWND hDlg, int idx, TCHAR*);
  14139. hd_get_meta(hDlg, oposn, current_hfdlg.ci.geometry);
  14140. setharddrive(hDlg);
  14141. }
  14142. break;
  14143. case IDC_HARDDRIVE_IMAGE:
  14144. posn = SendDlgItemMessage (hDlg, IDC_HARDDRIVE, CB_GETCURSEL, 0, 0);
  14145. if (posn != CB_ERR)
  14146. harddrive_to_hdf (hDlg, &workprefs, posn);
  14147. break;
  14148. case IDC_HDF_RW:
  14149. posn = SendDlgItemMessage (hDlg, IDC_HARDDRIVE, CB_GETCURSEL, 0, 0);
  14150. if (posn != CB_ERR) {
  14151. int dang = 1;
  14152. hdf_getnameharddrive (posn, 1, NULL, &dang, NULL);
  14153. current_hfdlg.ci.readonly = (ischecked (hDlg, IDC_HDF_RW) && !dang) ? false : true;
  14154. }
  14155. break;
  14156. case IDC_HDF_LOCK:
  14157. posn = SendDlgItemMessage(hDlg, IDC_HARDDRIVE, CB_GETCURSEL, 0, 0);
  14158. if (posn != CB_ERR) {
  14159. int dang = 1;
  14160. hdf_getnameharddrive(posn, 1, NULL, &dang, NULL);
  14161. current_hfdlg.ci.lock = ischecked(hDlg, IDC_HDF_LOCK);
  14162. }
  14163. break;
  14164. case IDC_HDF_IDENTITY:
  14165. posn = SendDlgItemMessage(hDlg, IDC_HDF_IDENTITY, CB_GETCURSEL, 0, 0);
  14166. if (posn != CB_ERR) {
  14167. current_hfdlg.ci.loadidentity = ischecked(hDlg, IDC_HDF_IDENTITY);
  14168. }
  14169. break;
  14170. }
  14171. }
  14172. switch(LOWORD(wParam))
  14173. {
  14174. case IDC_HARDDRIVE:
  14175. posn = SendDlgItemMessage (hDlg, IDC_HARDDRIVE, CB_GETCURSEL, 0, 0);
  14176. if (oposn != posn && posn != CB_ERR) {
  14177. oposn = posn;
  14178. if (posn >= 0) {
  14179. BOOL ena;
  14180. uae_u32 flags;
  14181. int dang = 1;
  14182. hdf_getnameharddrive (posn, 1, NULL, &dang, &flags);
  14183. _tcscpy (current_hfdlg.ci.rootdir, hdf_getnameharddrive (posn, 4, NULL, &dang, NULL));
  14184. ena = dang >= 0;
  14185. ew(hDlg, IDC_HARDDRIVE_IMAGE, ena);
  14186. ew(hDlg, IDC_HARDDRIVE_ID, ena);
  14187. ew(hDlg, IDC_HDF_LOCK, ena);
  14188. ew(hDlg, IDOK, ena);
  14189. ew(hDlg, IDC_HDF_RW, !dang);
  14190. ew(hDlg, IDC_HDF_FEATURE_LEVEL, ena);
  14191. ew(hDlg, IDC_HDF_CONTROLLER, ena);
  14192. ew(hDlg, IDC_HDF_CONTROLLER_UNIT, ena);
  14193. ew(hDlg, IDC_HDF_CONTROLLER_TYPE, ena);
  14194. ew(hDlg, IDC_PATH_GEOMETRY, ena);
  14195. ew(hDlg, IDC_PATH_GEOMETRY_SELECTOR, ena);
  14196. ew(hDlg, IDC_HDF_PHYSGEOMETRY, ena && current_hfdlg.ci.geometry[0] == 0);
  14197. if (dang)
  14198. current_hfdlg.ci.readonly = true;
  14199. current_hfdlg.ci.blocksize = 512;
  14200. current_hfdlg.forcedcylinders = 0;
  14201. current_hfdlg.ci.cyls = current_hfdlg.ci.highcyl = current_hfdlg.ci.sectors = current_hfdlg.ci.surfaces = 0;
  14202. SetDlgItemText(hDlg, IDC_HDFINFO, _T(""));
  14203. SetDlgItemText(hDlg, IDC_HDFINFO2, _T(""));
  14204. SetDlgItemText(hDlg, IDC_HDFINFO3, _T(""));
  14205. updatehdfinfo (hDlg, true, current_hfdlg.ci.geometry[0] ? false : true, true);
  14206. hdf_getnameharddrive(posn, 1, NULL, &dang, &flags);
  14207. ew(hDlg, IDC_HDF_IDENTITY, ena && (flags & 1));
  14208. if (!(flags & 1))
  14209. current_hfdlg.ci.loadidentity = false;
  14210. gui_set_string_cursor(hdmenutable, hDlg, IDC_HDF_CONTROLLER, current_hfdlg.ci.controller_type + current_hfdlg.ci.controller_type_unit * MAX_DUPLICATE_EXPANSION_BOARDS);
  14211. SendDlgItemMessage(hDlg, IDC_HDF_CONTROLLER_UNIT, CB_SETCURSEL, current_hfdlg.ci.controller_unit, 0);
  14212. CheckDlgButton(hDlg, IDC_HDF_RW, !current_hfdlg.ci.readonly);
  14213. _tcscpy (current_hfdlg.ci.rootdir, hdf_getnameharddrive ((int)posn, 4, &current_hfdlg.ci.blocksize, NULL, NULL));
  14214. setharddrive(hDlg);
  14215. }
  14216. }
  14217. break;
  14218. case IDC_HDF_CONTROLLER:
  14219. posn = gui_get_string_cursor(hdmenutable, hDlg, IDC_HDF_CONTROLLER);
  14220. if (posn != CB_ERR && current_hfdlg.ci.controller_type != posn) {
  14221. current_hfdlg.ci.controller_type = posn % HD_CONTROLLER_NEXT_UNIT;
  14222. current_hfdlg.ci.controller_type_unit = posn / HD_CONTROLLER_NEXT_UNIT;
  14223. current_hfdlg.forcedcylinders = 0;
  14224. current_hfdlg.ci.cyls = current_hfdlg.ci.highcyl = current_hfdlg.ci.sectors = current_hfdlg.ci.surfaces = 0;
  14225. SetDlgItemText(hDlg, IDC_HDFINFO, _T(""));
  14226. SetDlgItemText(hDlg, IDC_HDFINFO2, _T(""));
  14227. SetDlgItemText(hDlg, IDC_HDFINFO3, _T(""));
  14228. updatehdfinfo (hDlg, true, true, true);
  14229. inithdcontroller(hDlg, current_hfdlg.ci.controller_type, current_hfdlg.ci.controller_type_unit, UAEDEV_HDF, current_hfdlg.ci.rootdir[0] != 0);
  14230. SendDlgItemMessage(hDlg, IDC_HDF_CONTROLLER_UNIT, CB_SETCURSEL, current_hfdlg.ci.controller_unit, 0);
  14231. sethardfiletypes(hDlg);
  14232. }
  14233. break;
  14234. case IDC_HDF_CONTROLLER_UNIT:
  14235. posn = SendDlgItemMessage (hDlg, IDC_HDF_CONTROLLER_UNIT, CB_GETCURSEL, 0, 0);
  14236. if (posn != CB_ERR) {
  14237. current_hfdlg.ci.controller_unit = posn;
  14238. }
  14239. break;
  14240. case IDC_HDF_CONTROLLER_TYPE:
  14241. posn = SendDlgItemMessage (hDlg, IDC_HDF_CONTROLLER_TYPE, CB_GETCURSEL, 0, 0);
  14242. if (posn != CB_ERR) {
  14243. current_hfdlg.ci.controller_media_type = posn;
  14244. }
  14245. break;
  14246. case IDC_HDF_FEATURE_LEVEL:
  14247. posn = SendDlgItemMessage(hDlg, IDC_HDF_FEATURE_LEVEL, CB_GETCURSEL, 0, 0);
  14248. if (posn != CB_ERR) {
  14249. current_hfdlg.ci.unit_feature_level = posn;
  14250. }
  14251. break;
  14252. case IDC_PATH_GEOMETRY_SELECTOR:
  14253. if (DiskSelection (hDlg, IDC_PATH_GEOMETRY, 23, &workprefs, NULL, current_hfdlg.ci.geometry)) {
  14254. getcomboboxtext(hDlg, IDC_PATH_GEOMETRY, current_hfdlg.ci.geometry, sizeof current_hfdlg.ci.geometry / sizeof(TCHAR));
  14255. DISK_history_add(current_hfdlg.ci.geometry, -1, HISTORY_GEO, 1);
  14256. setharddrive(hDlg);
  14257. updatehdfinfo (hDlg, true, false, true);
  14258. }
  14259. break;
  14260. case IDC_SECTORS:
  14261. p = &current_hfdlg.ci.psecs;
  14262. v = *p;
  14263. *p = GetDlgItemInt (hDlg, IDC_SECTORS, NULL, FALSE);
  14264. if (v != *p) {
  14265. set_phys_cyls(hDlg);
  14266. updatehdfinfo (hDlg, true, false, true);
  14267. ew (hDlg, IDC_HDF_RDB, !is_hdf_rdb ());
  14268. }
  14269. break;
  14270. case IDC_RESERVED:
  14271. p = &current_hfdlg.ci.pcyls;
  14272. v = *p;
  14273. *p = GetDlgItemInt (hDlg, IDC_RESERVED, NULL, FALSE);
  14274. if (v != *p) {
  14275. if (ischecked(hDlg, IDC_HDF_PHYSGEOMETRY)) {
  14276. current_hfdlg.ci.physical_geometry = true;
  14277. }
  14278. updatehdfinfo (hDlg, true, false, true);
  14279. ew (hDlg, IDC_HDF_RDB, !is_hdf_rdb ());
  14280. }
  14281. break;
  14282. case IDC_HEADS:
  14283. p = &current_hfdlg.ci.pheads;
  14284. v = *p;
  14285. *p = GetDlgItemInt (hDlg, IDC_HEADS, NULL, FALSE);
  14286. if (v != *p) {
  14287. set_phys_cyls(hDlg);
  14288. updatehdfinfo (hDlg, true, false, true);
  14289. ew (hDlg, IDC_HDF_RDB, !is_hdf_rdb ());
  14290. }
  14291. break;
  14292. }
  14293. recursive--;
  14294. break;
  14295. }
  14296. commonproc(hDlg, msg, wParam, lParam);
  14297. return FALSE;
  14298. }
  14299. static void new_filesys (HWND hDlg, int entry)
  14300. {
  14301. struct uaedev_config_data *uci;
  14302. struct uaedev_config_info ci;
  14303. memcpy (&ci, &current_fsvdlg.ci, sizeof (struct uaedev_config_info));
  14304. uci = add_filesys_config (&workprefs, entry, &ci);
  14305. if (uci) {
  14306. if (uci->ci.rootdir[0])
  14307. filesys_media_change (uci->ci.rootdir, 1, uci);
  14308. else if (uci->configoffset >= 0)
  14309. filesys_eject (uci->configoffset);
  14310. }
  14311. }
  14312. static void new_cddrive (HWND hDlg, int entry)
  14313. {
  14314. struct uaedev_config_info ci = { 0 };
  14315. ci.device_emu_unit = 0;
  14316. ci.controller_type = current_cddlg.ci.controller_type;
  14317. ci.controller_unit = current_cddlg.ci.controller_unit;
  14318. ci.type = UAEDEV_CD;
  14319. ci.readonly = true;
  14320. ci.blocksize = 2048;
  14321. add_filesys_config (&workprefs, entry, &ci);
  14322. }
  14323. static void new_tapedrive (HWND hDlg, int entry)
  14324. {
  14325. struct uaedev_config_data *uci;
  14326. struct uaedev_config_info ci = { 0 };
  14327. ci.controller_type = current_tapedlg.ci.controller_type;
  14328. ci.controller_unit = current_tapedlg.ci.controller_unit;
  14329. ci.readonly = current_tapedlg.ci.readonly;
  14330. _tcscpy (ci.rootdir, current_tapedlg.ci.rootdir);
  14331. ci.type = UAEDEV_TAPE;
  14332. ci.blocksize = 512;
  14333. uci = add_filesys_config (&workprefs, entry, &ci);
  14334. if (uci && uci->unitnum >= 0) {
  14335. tape_media_change (uci->unitnum, &ci);
  14336. }
  14337. }
  14338. static void new_hardfile (HWND hDlg, int entry)
  14339. {
  14340. struct uaedev_config_data *uci;
  14341. struct uaedev_config_info ci;
  14342. memcpy (&ci, &current_hfdlg.ci, sizeof (struct uaedev_config_info));
  14343. uci = add_filesys_config (&workprefs, entry, &ci);
  14344. if (uci) {
  14345. struct hardfiledata *hfd = get_hardfile_data (uci->configoffset);
  14346. if (hfd)
  14347. hardfile_media_change (hfd, &ci, true, false);
  14348. pcmcia_disk_reinsert(&workprefs, &uci->ci, false);
  14349. }
  14350. }
  14351. static void new_harddrive (HWND hDlg, int entry)
  14352. {
  14353. struct uaedev_config_data *uci;
  14354. uci = add_filesys_config (&workprefs, entry, &current_hfdlg.ci);
  14355. if (uci) {
  14356. struct hardfiledata *hfd = get_hardfile_data (uci->configoffset);
  14357. if (hfd)
  14358. hardfile_media_change (hfd, &current_hfdlg.ci, true, false);
  14359. pcmcia_disk_reinsert(&workprefs, &uci->ci, false);
  14360. }
  14361. }
  14362. static void harddisk_remove (HWND hDlg)
  14363. {
  14364. int entry = listview_find_selected (GetDlgItem (hDlg, IDC_VOLUMELIST), false);
  14365. if (entry < 0)
  14366. return;
  14367. kill_filesys_unitconfig (&workprefs, entry);
  14368. }
  14369. static void harddisk_move (HWND hDlg, int up)
  14370. {
  14371. int entry = listview_find_selected (GetDlgItem (hDlg, IDC_VOLUMELIST), false);
  14372. if (entry < 0)
  14373. return;
  14374. move_filesys_unitconfig (&workprefs, entry, up ? entry - 1 : entry + 1);
  14375. }
  14376. static void harddisk_edit (HWND hDlg)
  14377. {
  14378. int entry = listview_find_selected (GetDlgItem (hDlg, IDC_VOLUMELIST), false);
  14379. int type;
  14380. struct uaedev_config_data *uci;
  14381. struct mountedinfo mi;
  14382. if (entry < 0 || entry >= workprefs.mountitems)
  14383. return;
  14384. uci = &workprefs.mountconfig[entry];
  14385. type = get_filesys_unitconfig (&workprefs, entry, &mi);
  14386. if (type < 0)
  14387. type = uci->ci.type == UAEDEV_HDF ? FILESYS_HARDFILE : FILESYS_VIRTUAL;
  14388. if (uci->ci.type == UAEDEV_CD) {
  14389. memcpy (&current_cddlg.ci, uci, sizeof (struct uaedev_config_info));
  14390. if (CustomDialogBox (IDD_CDDRIVE, hDlg, CDDriveSettingsProc)) {
  14391. new_cddrive (hDlg, entry);
  14392. }
  14393. } else if (uci->ci.type == UAEDEV_TAPE) {
  14394. memcpy (&current_tapedlg.ci, uci, sizeof (struct uaedev_config_info));
  14395. if (CustomDialogBox (IDD_TAPEDRIVE, hDlg, TapeDriveSettingsProc)) {
  14396. new_tapedrive (hDlg, entry);
  14397. }
  14398. }
  14399. else if(type == FILESYS_HARDFILE || type == FILESYS_HARDFILE_RDB)
  14400. {
  14401. current_hfdlg.forcedcylinders = uci->ci.highcyl;
  14402. memcpy (&current_hfdlg.ci, uci, sizeof (struct uaedev_config_info));
  14403. if (CustomDialogBox (IDD_HARDFILE, hDlg, HardfileSettingsProc)) {
  14404. new_hardfile (hDlg, entry);
  14405. }
  14406. }
  14407. else if (type == FILESYS_HARDDRIVE) /* harddisk */
  14408. {
  14409. memcpy (&current_hfdlg.ci, uci, sizeof (struct uaedev_config_info));
  14410. if (CustomDialogBox (IDD_HARDDRIVE, hDlg, HarddriveSettingsProc)) {
  14411. new_harddrive (hDlg, entry);
  14412. }
  14413. }
  14414. else /* Filesystem */
  14415. {
  14416. memcpy (&current_fsvdlg.ci, uci, sizeof (struct uaedev_config_info));
  14417. archivehd = -1;
  14418. if (CustomDialogBox (IDD_FILESYS, hDlg, VolumeSettingsProc)) {
  14419. new_filesys (hDlg, entry);
  14420. }
  14421. }
  14422. }
  14423. static ACCEL HarddiskAccel[] = {
  14424. { FVIRTKEY|FSHIFT, VK_UP, IDC_UP }, { FVIRTKEY|FSHIFT, VK_DOWN, IDC_DOWN },
  14425. { FVIRTKEY, VK_RETURN, IDC_EDIT }, { FVIRTKEY, VK_DELETE, IDC_REMOVE },
  14426. { 0, 0, 0 }
  14427. };
  14428. static void hilitehd (HWND hDlg)
  14429. {
  14430. int total = ListView_GetItemCount (cachedlist);
  14431. if (total <= 0) {
  14432. ew (hDlg, IDC_EDIT, FALSE);
  14433. ew (hDlg, IDC_REMOVE, FALSE);
  14434. return;
  14435. }
  14436. if (clicked_entry < 0)
  14437. clicked_entry = 0;
  14438. if (clicked_entry >= total)
  14439. clicked_entry = total;
  14440. ListView_SetItemState (cachedlist, clicked_entry, LVIS_SELECTED | LVIS_FOCUSED, LVIS_SELECTED | LVIS_FOCUSED);
  14441. ew (hDlg, IDC_EDIT, TRUE);
  14442. ew (hDlg, IDC_REMOVE, TRUE);
  14443. }
  14444. static int harddiskdlg_button (HWND hDlg, WPARAM wParam)
  14445. {
  14446. int button = LOWORD (wParam);
  14447. switch (button) {
  14448. case IDC_CD_SELECT:
  14449. DiskSelection (hDlg, wParam, 17, &workprefs, NULL, NULL);
  14450. quickstart_cdtype = 1;
  14451. workprefs.cdslots[0].inuse = true;
  14452. addcdtype (hDlg, IDC_CD_TYPE);
  14453. InitializeListView (hDlg);
  14454. hilitehd (hDlg);
  14455. break;
  14456. case IDC_CD_EJECT:
  14457. eject_cd ();
  14458. SetDlgItemText (hDlg, IDC_CD_TEXT, _T(""));
  14459. addcdtype (hDlg, IDC_CD_TYPE);
  14460. InitializeListView (hDlg);
  14461. hilitehd (hDlg);
  14462. break;
  14463. case IDC_NEW_FS:
  14464. default_fsvdlg (&current_fsvdlg);
  14465. archivehd = 0;
  14466. if (CustomDialogBox (IDD_FILESYS, hDlg, VolumeSettingsProc))
  14467. new_filesys (hDlg, -1);
  14468. return 1;
  14469. case IDC_NEW_FSARCH:
  14470. archivehd = 1;
  14471. default_fsvdlg (&current_fsvdlg);
  14472. if (CustomDialogBox (IDD_FILESYS, hDlg, VolumeSettingsProc))
  14473. new_filesys (hDlg, -1);
  14474. return 1;
  14475. case IDC_NEW_HF:
  14476. default_hfdlg (&current_hfdlg, false);
  14477. if (CustomDialogBox (IDD_HARDFILE, hDlg, HardfileSettingsProc))
  14478. new_hardfile (hDlg, -1);
  14479. return 1;
  14480. case IDC_NEW_CD:
  14481. if (CustomDialogBox (IDD_CDDRIVE, hDlg, CDDriveSettingsProc))
  14482. new_cddrive (hDlg, -1);
  14483. return 1;
  14484. case IDC_NEW_TAPE:
  14485. default_tapedlg (&current_tapedlg);
  14486. if (CustomDialogBox (IDD_TAPEDRIVE, hDlg, TapeDriveSettingsProc))
  14487. new_tapedrive (hDlg, -1);
  14488. return 1;
  14489. case IDC_NEW_HD:
  14490. default_hfdlg (&current_hfdlg, true);
  14491. current_hfdlg.ci.type = UAEDEV_HDF;
  14492. if (hdf_init_target () == 0) {
  14493. TCHAR tmp[MAX_DPATH];
  14494. WIN32GUI_LoadUIString (IDS_NOHARDDRIVES, tmp, sizeof (tmp) / sizeof (TCHAR));
  14495. gui