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 
10 #include <stdio.h>
11 #include <stdlib.h>
12 #include <io.h>
13 #include <windows.h>
14 #include <winspool.h>
15 #include <winuser.h>
16 #ifdef _MSC_VER
17 #include <mmsystem.h>
18 #include <shlobj.h>
19 #include <commdlg.h>
20 #include <dlgs.h>
21 #include <process.h>
22 #include <prsht.h>
23 #include <richedit.h>
24 #include <shellapi.h>
25 #else
26 #include <shlobj.h>
27 #include <commdlg.h>
28 #include <richedit.h>
29 #endif
30 
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 "custom.h"
38 #include "newcpu.h"
39 #include "disk.h"
40 #include "uae.h"
41 #include "threaddep/thread.h"
42 #include "filesys.h"
43 #include "autoconf.h"
44 
45 #include "picasso96.h"
46 #include "osdep/win32gui.h"
47 #include "osdep/win32.h"
48 #include "osdep/win32gfx.h"
49 #include "osdep/dxwrap.h"
50 #include "sounddep/sound.h"
51 #include "target.h"
52 #include "savestate.h"
53 
54 #define DISK_FORMAT_STRING "(*.ADF;*.ADZ;*.GZ;*.DMS;*.FDI)\0*.ADF;*.ADZ;*.GZ;*.DMS;*.FDI\0"
55 
56 static int allow_quit;
57 static int full_property_sheet;
58 static struct uae_prefs *pguiprefs;
59 static struct uae_prefs workprefs;
60 
61 extern HWND (WINAPI *pHtmlHelp)(HWND, LPCSTR, UINT, LPDWORD );
62 #undef HtmlHelp
63 #ifndef HH_DISPLAY_TOPIC
64 #define HH_DISPLAY_TOPIC 0
65 #endif
66 #define HtmlHelp(a,b,c,d) if( pHtmlHelp ) (*pHtmlHelp)(a,b,c,(LPDWORD)d); else \
67 { char szMessage[ MAX_PATH ]; WIN32GUI_LoadUIString( IDS_NOHELP, szMessage, MAX_PATH ); gui_message( szMessage ); }
68 
69 extern HWND hAmigaWnd;
70 extern char help_file[ MAX_PATH ];
71 
72 extern int mouseactive;
73 extern char *start_path;
74 
75 extern char configname[256];
76 char config_filename[ MAX_PATH ] = "";
77 
78 HANDLE win32uae_key = NULL;
79 
80 drive_specs blankdrive =
81 {"", "", 1, 32, 1, 2, 0, 0};
82 
83 #define Error(x) MessageBox( NULL, (x), "WinUAE Error", MB_OK )
84 
WIN32GUI_LoadUIString(DWORD id,char * string,DWORD dwStringLen)85 void WIN32GUI_LoadUIString( DWORD id, char *string, DWORD dwStringLen )
86 {
87     if( LoadString( hUIDLL ? hUIDLL : hInst, id, string, dwStringLen ) == 0 )
88 	LoadString( hInst, id, string, dwStringLen );
89 }
90 
91 HWND hPropertySheet = NULL;
92 
93 /* C_PAGES must be last */
94 enum {
95     LOADSAVE_ID, MEMORY_ID, KICKSTART_ID, CPU_ID,
96     DISPLAY_ID, CHIPSET_ID, SOUND_ID, FLOPPY_ID, HARDDISK_ID,
97     PORTS_ID, MISC_ID, ABOUT_ID, C_PAGES
98 };
99 
100 static HWND pages[C_PAGES];
101 
102 #define MIN_CHIP_MEM 0
103 #define MAX_CHIP_MEM 4
104 #define MIN_FAST_MEM 0
105 #define MAX_FAST_MEM 4
106 #define MIN_SLOW_MEM 0
107 #define MAX_SLOW_MEM 2
108 #define MIN_Z3_MEM 0
109 #define MAX_Z3_MEM 10
110 #define MIN_P96_MEM 0
111 #define MAX_P96_MEM 6
112 #define MIN_M68K_PRIORITY 1
113 #define MAX_M68K_PRIORITY 16
114 #define MIN_CACHE_SIZE 0
115 #define MAX_CACHE_SIZE 8
116 #define MIN_REFRESH_RATE 1
117 #define MAX_REFRESH_RATE 10
118 #define MIN_SOUND_MEM 0
119 #define MAX_SOUND_MEM 6
120 
121 static char szNone[ MAX_PATH ] = "None";
122 
123 /* if drive is -1, show the full GUI, otherwise file-requester for DF[drive] */
WIN32GUI_DisplayGUI(int drive)124 void WIN32GUI_DisplayGUI( int drive )
125 {
126     HRESULT ddrval;
127     int flipflop = 0;
128 
129     if( ( !WIN32GFX_IsPicassoScreen() && currprefs.gfx_afullscreen && ( currprefs.gfx_width < 640 ) ) ||
130 	( WIN32GFX_IsPicassoScreen() && currprefs.gfx_pfullscreen && ( picasso96_state.Width < 640 ) ) )
131 	flipflop = 1;
132 
133     WIN32GFX_ClearPalette();
134 
135     if( !WIN32GFX_IsFullScreen() )
136 	setmouseactive (FALSE);
137     else
138     {
139 	if( DirectDraw_GetLockableType() == primary_surface )
140 	{
141 	    /* Blit our primary to our secondary, so we can then use the secondary to refresh from */
142 	    ddrval = DirectDraw_Blt( secondary_surface, NULL, primary_surface, NULL, DDBLT_WAIT, NULL );
143 	}
144     }
145     manual_painting_needed = 1; /* So that WM_PAINT will refresh the display */
146     pause_sound(0);
147 
148     DirectDraw_FlipToGDISurface();
149 
150     if( drive == -1 )
151     {
152 	if( flipflop )
153 	    ShowWindow( hAmigaWnd, SW_MINIMIZE );
154 	GetSettings(0);
155 	if( flipflop )
156 	    ShowWindow( hAmigaWnd, SW_RESTORE );
157     }
158     else
159     {
160 	DiskSelection( hAmigaWnd, IDC_DF0+drive, 0, &changed_prefs );
161     }
162     resume_sound();
163     WIN32GFX_SetPalette();
164     manual_painting_needed = 0; /* So that WM_PAINT doesn't need to use custom refreshing */
165     if( !WIN32GFX_IsFullScreen() || !mouseactive)
166 	SetCursor (NULL);
167 
168     // This is a hack to fix the fact that time is passing while the GUI was present,
169     // and we don't want our frames-per-second calculation in drawing.c to get skewed.
170 #ifdef HAVE_GETTIMEOFDAY
171     {
172 	struct timeval tv;
173 	gettimeofday(&tv,NULL);
174 	msecs = (tv.tv_sec-seconds_base) * 1000 + tv.tv_usec / 1000;
175     }
176 #endif
177 }
178 
prefs_to_gui(struct uae_prefs * p)179 static void prefs_to_gui (struct uae_prefs *p)
180 {
181     workprefs = *p;
182     workprefs.mountinfo = dup_mountinfo (p->mountinfo);
183     /* Could also duplicate unknown lines, but no need - we never
184        modify those.  */
185 }
186 
gui_to_prefs(void)187 static void gui_to_prefs (void)
188 {
189     /* Always copy our prefs to changed_prefs, ... */
190     changed_prefs = workprefs;
191 
192     /* ... but use currprefs for the mountinfo.  The filesystem code
193        keeps a private copy, and only looks at currprefs once per reset.
194        It never looks at changed_prefs.  */
195     free_mountinfo (currprefs.mountinfo);
196     currprefs.mountinfo = dup_mountinfo (workprefs.mountinfo);
197 }
198 
199 #define TRACK_WRITE_LEN (6250*2)
200 
disk_checksum(uae_u8 * p,uae_u8 * c)201 static void disk_checksum(uae_u8 *p, uae_u8 *c)
202 {
203     uae_u32 cs = 0;
204     int i;
205 
206     for (i = 0; i < 512; i+= 4) cs += (p[i] << 24) | (p[i+1] << 16) | (p[i+2] << 8) | (p[i+3] << 0);
207     cs = -cs;
208     c[0] = cs >> 24; c[1] = cs >> 16; c[2] = cs >> 8; c[3] = cs >> 0;
209 }
210 
disk_date(uae_u8 * p)211 static void disk_date (uae_u8 *p)
212 {
213     time_t t;
214     struct tm *today;
215     int year, days, minutes, ticks;
216     char tmp[10];
217 
218     time (&t);
219     today = localtime( &t );
220     strftime (tmp, sizeof(tmp), "%Y", today);
221     year = atol (tmp);
222     strftime (tmp, sizeof(tmp), "%j", today);
223     days = atol (tmp) - 1;
224     strftime (tmp, sizeof(tmp), "%H", today);
225     minutes = atol (tmp) * 60;
226     strftime (tmp, sizeof(tmp), "%M", today);
227     minutes += atol (tmp);
228     strftime (tmp, sizeof(tmp), "%S", today);
229     ticks = atol (tmp) * 50;
230 
231     while (year > 1978) {
232 	if ( !(year % 100) ? !(year % 400) : !(year % 4) ) days++;
233 	days += 365;
234 	year--;
235     }
236 
237     p[0] = days >> 24; p[1] = days >> 16; p[2] = days >> 8; p[3] = days >> 0;
238     p[4] = minutes >> 24; p[5] = minutes >> 16; p[6] = minutes >> 8; p[7] = minutes >> 0;
239     p[8] = ticks >> 24; p[9] = ticks >> 16; p[10] = ticks >> 8; p[11] = ticks >> 0;
240 }
241 
CreateDiskFile(char * name,int type)242 static void CreateDiskFile (char *name, int type)
243 {
244     HANDLE adf;
245     int i, j, file_size = 880 * 1024, tracks;
246     char *chunk = NULL;
247     DWORD count;
248     uae_u8 tmp[3*4];
249     char *disk_name = "empty";
250 
251     SetCursor (LoadCursor (NULL, IDC_WAIT));
252     adf = CreateFile (name, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL | FILE_FLAG_SEQUENTIAL_SCAN, NULL);
253     if (adf != INVALID_HANDLE_VALUE) {
254 	if ((chunk = xmalloc (16384)) != NULL) {
255 	memset(chunk,0,16384);
256 	switch(type)
257 	    {
258 	    case 0:
259 	    for (i = 0; i < file_size; i += 11264) {
260 		memset(chunk, 0, 11264);
261 		if (i == 0) {
262 		    /* boot block */
263 		    strcpy (chunk, "DOS");
264 		} else if (i == 880 * 512) {
265 		    /* root block */
266 		    chunk[0+3] = 2;
267 		    chunk[12+3] = 0x48;
268 		    chunk[312] = chunk[313] = chunk[314] = chunk[315] = 0xff;
269 		    chunk[316+2] = 881 >> 8; chunk[316+3] = 881 & 255;
270 		    chunk[432] = strlen (disk_name);
271 		    strcpy (chunk + 433, disk_name);
272 		    chunk[508 + 3] = 1;
273 		    disk_date (chunk + 420);
274 		    memcpy (chunk + 472, chunk + 420, 3 * 4);
275 		    memcpy (chunk + 484, chunk + 420, 3 * 4);
276 		    disk_checksum(chunk, chunk + 20);
277 		    /* bitmap block */
278 		    memset (chunk + 512 + 4, 0xff, 220);
279 		    chunk[512 + 112 + 2] = 0x3f;
280 		    disk_checksum(chunk + 512, chunk + 512);
281 
282 		}
283 		WriteFile (adf, chunk, 11264, &count, NULL);
284 	    }
285 	    break;
286 	    case 1:
287 	    tracks=2*80;
288 	    WriteFile(adf,"UAE-1ADF",8,&count,0);
289 	    tmp[0]=0;tmp[1]=0; /* flags (reserved) */
290 	    tmp[2]=0;tmp[3]=tracks; /* number of tracks */
291 	    WriteFile(adf,tmp,4,&count,0);
292 	    tmp[0]=0;tmp[1]=0; /* flags (reserved) */
293 	    tmp[2]=0;tmp[3]=1; /* track type */
294 	    tmp[4]=0;tmp[5]=0;tmp[6]=TRACK_WRITE_LEN>>8;tmp[7]=TRACK_WRITE_LEN;
295 	    tmp[8]=0;tmp[9]=(TRACK_WRITE_LEN*8)>>16;tmp[10]=(TRACK_WRITE_LEN*8)>>8;tmp[11]=(TRACK_WRITE_LEN*8);
296 	    for (i=0;i<tracks;i++) WriteFile(adf,tmp,sizeof(tmp),&count,0);
297 	    for (i=0;i<tracks;i++) WriteFile(adf,chunk,TRACK_WRITE_LEN,&count,NULL);
298 	    break;
299 	    }
300 	}
301 	CloseHandle (adf);
302     }
303     SetCursor (LoadCursor (NULL, IDC_ARROW));
304 }
305 
306 // Common routine for popping up a file-requester
307 // flag - 0 for floppy loading, 1 for floppy creation, 2 for loading hdf, 3 for saving hdf
308 // flag - 4 for loading .uae config-files, 5 for saving .uae config-files
309 // flag = 6 for loading .rom files, 7 for loading .key files
310 // flag = 8 for loading anything you want
311 // flag = 9 for saving snapshots
312 // flag = 10 for loading snapshots
DiskSelection(HWND hDlg,WPARAM wParam,int flag,struct uae_prefs * prefs)313 void DiskSelection( HWND hDlg, WPARAM wParam, int flag, struct uae_prefs *prefs )
314 {
315     OPENFILENAME openFileName;
316     char regfloppypath[MAX_PATH] = "";
317     char regrompath[MAX_PATH] = "";
318     char reghdfpath[MAX_PATH] = "";
319     DWORD dwType = REG_SZ;
320     DWORD dwRFPsize = MAX_PATH;
321     DWORD dwRRPsize = MAX_PATH;
322     DWORD dwRHPsize = MAX_PATH;
323 
324     char full_path[MAX_PATH] = "";
325     char file_name[MAX_PATH] = "";
326     char init_path[MAX_PATH] = "";
327     BOOL result = FALSE;
328     char *amiga_path = NULL;
329     char description[ CFG_DESCRIPTION_LENGTH ] = "";
330     int i;
331 
332     char szTitle[ MAX_PATH ];
333     char szFormat[ MAX_PATH ];
334     char szFilter[ MAX_PATH ];
335 
336     if( hWinUAEKey )
337     {
338 	RegQueryValueEx( hWinUAEKey, "FloppyPath", 0, &dwType, (LPBYTE)regfloppypath, &dwRFPsize );
339 	RegQueryValueEx( hWinUAEKey, "KickstartPath", 0, &dwType, (LPBYTE)regrompath, &dwRRPsize );
340 	RegQueryValueEx( hWinUAEKey, "hdfPath", 0, &dwType, (LPBYTE)reghdfpath, &dwRHPsize );
341     }
342 
343     strncpy( init_path, start_path, MAX_PATH );
344     switch( flag )
345     {
346 	case 0:
347 	case 1:
348 	    if( regfloppypath[0] )
349 		strncpy( init_path, regfloppypath, MAX_PATH );
350 	    else
351 		strncat( init_path, "\\..\\shared\\adf\\", MAX_PATH );
352 	break;
353 	case 2:
354 	case 3:
355 	    if( reghdfpath[0] )
356 		strncpy( init_path, reghdfpath, MAX_PATH );
357 	    else
358 		strncat( init_path, "\\..\\shared\\hdf\\", MAX_PATH );
359 	break;
360 	case 6:
361 	case 7:
362 	    if( regrompath[0] )
363 		strncpy( init_path, regrompath, MAX_PATH );
364 	    else
365 		strncat( init_path, "\\..\\shared\\rom\\", MAX_PATH );
366 	break;
367 	case 4:
368 	case 5:
369 	default:
370 	    strncat( init_path, "\\Configurations\\", MAX_PATH );
371 	break;
372     }
373 
374     openFileName.lStructSize = sizeof (OPENFILENAME);
375     openFileName.hwndOwner = hDlg;
376     openFileName.hInstance = hInst;
377 
378     switch (flag) {
379     case 0:
380 	WIN32GUI_LoadUIString( IDS_SELECTADF, szTitle, MAX_PATH );
381 	WIN32GUI_LoadUIString( IDS_ADF, szFormat, MAX_PATH );
382 	sprintf( szFilter, "%s ", szFormat );
383 	memcpy( szFilter + strlen( szFilter ), DISK_FORMAT_STRING, sizeof( DISK_FORMAT_STRING ) + 1 );
384 
385 	openFileName.lpstrTitle = szTitle;
386 	openFileName.lpstrDefExt = "ADF";
387 	openFileName.lpstrFilter = szFilter;
388 	break;
389     case 1:
390 	WIN32GUI_LoadUIString( IDS_CHOOSEBLANK, szTitle, MAX_PATH );
391 	WIN32GUI_LoadUIString( IDS_ADF, szFormat, MAX_PATH );
392 	sprintf( szFilter, "%s ", szFormat );
393 	memcpy( szFilter + strlen( szFilter ), "(*.ADF)\0*.ADF\0", 15 );
394 
395 	openFileName.lpstrTitle = szTitle;
396 	openFileName.lpstrDefExt = "ADF";
397 	openFileName.lpstrFilter = szFilter;
398 	break;
399     case 2:
400     case 3:
401 	WIN32GUI_LoadUIString( IDS_SELECTHDF, szTitle, MAX_PATH );
402 	WIN32GUI_LoadUIString( IDS_HDF, szFormat, MAX_PATH );
403 	sprintf( szFilter, "%s ", szFormat );
404 	memcpy( szFilter + strlen( szFilter ), "(*.HDF)\0*.HDF\0", 15 );
405 
406 	openFileName.lpstrTitle = szTitle;
407 	openFileName.lpstrDefExt = "HDF";
408 	openFileName.lpstrFilter = szFilter;
409 	break;
410     case 4:
411     case 5:
412 	WIN32GUI_LoadUIString( IDS_SELECTUAE, szTitle, MAX_PATH );
413 	WIN32GUI_LoadUIString( IDS_UAE, szFormat, MAX_PATH );
414 	sprintf( szFilter, "%s ", szFormat );
415 	memcpy( szFilter + strlen( szFilter ), "(*.UAE)\0*.UAE\0", 15 );
416 
417 	openFileName.lpstrTitle  = szTitle;
418 	openFileName.lpstrDefExt = "UAE";
419 	openFileName.lpstrFilter = szFilter;
420 	break;
421     case 6:
422 	WIN32GUI_LoadUIString( IDS_SELECTROM, szTitle, MAX_PATH );
423 	WIN32GUI_LoadUIString( IDS_ROM, szFormat, MAX_PATH );
424 	sprintf( szFilter, "%s ", szFormat );
425 	memcpy( szFilter + strlen( szFilter ), "(*.ROM)\0*.ROM\0", 15 );
426 
427 	openFileName.lpstrTitle = szTitle;
428 	openFileName.lpstrDefExt = "ROM";
429 	openFileName.lpstrFilter = szFilter;
430 	break;
431     case 7:
432 	WIN32GUI_LoadUIString( IDS_SELECTKEY, szTitle, MAX_PATH );
433 	WIN32GUI_LoadUIString( IDS_KEY, szFormat, MAX_PATH );
434 	sprintf( szFilter, "%s ", szFormat );
435 	memcpy( szFilter + strlen( szFilter ), "(*.KEY)\0*.KEY\0", 15 );
436 
437 	openFileName.lpstrTitle = szTitle;
438 	openFileName.lpstrDefExt = "KEY";
439 	openFileName.lpstrFilter = szFilter;
440 	break;
441     case 9:
442     case 10:
443 	WIN32GUI_LoadUIString( IDS_SELECTUSS, szTitle, MAX_PATH );
444 	WIN32GUI_LoadUIString( IDS_USS, szFormat, MAX_PATH );
445 	sprintf( szFilter, "%s ", szFormat );
446 	memcpy( szFilter + strlen( szFilter ), "(*.USS)\0*.USS\0", 15 );
447 
448 	openFileName.lpstrTitle  = szTitle;
449 	openFileName.lpstrDefExt = "USS";
450 	openFileName.lpstrFilter = szFilter;
451 	break;
452     case 8:
453     default:
454 	WIN32GUI_LoadUIString( IDS_SELECTINFO, szTitle, MAX_PATH );
455 
456 	openFileName.lpstrTitle = szTitle;
457 	openFileName.lpstrFilter = NULL;
458 	openFileName.lpstrDefExt = NULL;
459 	break;
460     }
461     openFileName.Flags = OFN_EXPLORER | OFN_FILEMUSTEXIST | OFN_PATHMUSTEXIST | OFN_LONGNAMES | OFN_HIDEREADONLY | OFN_NOCHANGEDIR;
462     openFileName.lpstrCustomFilter = NULL;
463     openFileName.nMaxCustFilter = 0;
464     openFileName.nFilterIndex = 0;
465     openFileName.lpstrFile = full_path;
466     openFileName.nMaxFile = MAX_PATH;
467     openFileName.lpstrFileTitle = file_name;
468     openFileName.nMaxFileTitle = MAX_PATH;
469     openFileName.lpstrInitialDir = init_path;
470     openFileName.lpfnHook = NULL;
471     openFileName.lpTemplateName = NULL;
472     openFileName.lCustData = 0;
473     if (flag == 1 || flag == 3 || flag == 5 || flag == 9)
474     {
475 	if( !(result = GetSaveFileName (&openFileName)) )
476 	    write_log ("GetSaveFileName() failed.\n");
477     }
478     else
479     {
480 	if( !(result = GetOpenFileName (&openFileName)) )
481 	    write_log ("GetOpenFileName() failed.\n");
482     }
483 
484     if (result)
485     {
486 	switch (wParam)
487 	{
488 	case IDC_PATH_NAME:
489 	    if( flag == 8 )
490 	    {
491 		if( strstr( full_path, "Configurations\\" ) )
492 		{
493 		    strcpy( full_path, init_path );
494 		    strcat( full_path, file_name );
495 		}
496 	    }
497 	    SetDlgItemText (hDlg, wParam, full_path);
498 	    break;
499 	case IDC_DF0:
500 	    SetDlgItemText (hDlg, IDC_DF0TEXT, full_path);
501 	    strcpy( prefs->df[0], full_path );
502 	    disk_insert( 0, full_path );
503 	    break;
504 	case IDC_DF1:
505 	    SetDlgItemText (hDlg, IDC_DF1TEXT, full_path);
506 	    strcpy( prefs->df[1], full_path );
507 	    disk_insert( 1, full_path );
508 	    break;
509 	case IDC_DF2:
510 	    SetDlgItemText (hDlg, IDC_DF2TEXT, full_path);
511 	    strcpy( prefs->df[2], full_path );
512 	    disk_insert( 2, full_path );
513 	    break;
514 	case IDC_DF3:
515 	    SetDlgItemText (hDlg, IDC_DF3TEXT, full_path);
516 	    strcpy( prefs->df[3], full_path );
517 	    disk_insert( 3, full_path );
518 	    break;
519 	case IDC_DOSAVESTATE:
520 	case IDC_DOLOADSTATE:
521 	    strcpy( savestate_filename, full_path );
522 	    break;
523 	case IDC_CREATE:
524 	    CreateDiskFile( full_path, 0 );
525 	    break;
526 	case IDC_CREATE_RAW:
527 	    CreateDiskFile( full_path, 1 );
528 	    break;
529 	case IDC_LOAD:
530 	    if( cfgfile_load( &workprefs, full_path ) == 0 )
531 	    {
532 		char szMessage[ MAX_PATH ];
533 		WIN32GUI_LoadUIString( IDS_COULDNOTLOADCONFIG, szMessage, MAX_PATH );
534 		gui_message( szMessage );
535 	    }
536 	    else
537 	    {
538 		cfgfile_get_description( full_path, description );
539 		for( i = 0; i < C_PAGES; i++ )
540 		{
541 		    if( pages[i] )
542 			SendMessage( pages[i], WM_USER, 0, 0 );
543 		}
544 
545 		SetDlgItemText( hDlg, IDC_EDITDESCRIPTION, description );
546 		SetDlgItemText( hDlg, IDC_EDITNAME, full_path );
547 	    }
548 	    break;
549 	case IDC_SAVE:
550 	    SetDlgItemText( hDlg, IDC_EDITNAME, full_path );
551 	    break;
552 	case IDC_ROMFILE:
553 	    SetDlgItemText( hDlg, IDC_ROMFILE, full_path );
554 	    strcpy( workprefs.romfile, full_path );
555 	    break;
556 	case IDC_KEYFILE:
557 	    SetDlgItemText( hDlg, IDC_KEYFILE, full_path );
558 	    strcpy( workprefs.keyfile, full_path );
559 	    break;
560 	}
561 	if( flag == 0 || flag == 1 )
562 	{
563 	    amiga_path = strstr( openFileName.lpstrFile, openFileName.lpstrFileTitle );
564 	    if( amiga_path && amiga_path != openFileName.lpstrFile )
565 	    {
566 		*amiga_path = 0;
567 		if( hWinUAEKey )
568 		    RegSetValueEx( hWinUAEKey, "FloppyPath", 0, REG_SZ, (CONST BYTE *)openFileName.lpstrFile, strlen( openFileName.lpstrFile ) );
569 	    }
570 	}
571 	else if( flag == 2 || flag == 3 )
572 	{
573 	    amiga_path = strstr( openFileName.lpstrFile, openFileName.lpstrFileTitle );
574 	    if( amiga_path && amiga_path != openFileName.lpstrFile )
575 	    {
576 		*amiga_path = 0;
577 		if( hWinUAEKey )
578 		    RegSetValueEx( hWinUAEKey, "hdfPath", 0, REG_SZ, (CONST BYTE *)openFileName.lpstrFile, strlen( openFileName.lpstrFile ) );
579 	    }
580 	}
581 	else if( flag == 6 || flag == 7 )
582 	{
583 	    amiga_path = strstr( openFileName.lpstrFile, openFileName.lpstrFileTitle );
584 	    if( amiga_path && amiga_path != openFileName.lpstrFile )
585 	    {
586 		*amiga_path = 0;
587 		if( hWinUAEKey )
588 		    RegSetValueEx( hWinUAEKey, "KickstartPath", 0, REG_SZ, (CONST BYTE *)openFileName.lpstrFile, strlen( openFileName.lpstrFile ) );
589 	    }
590 	}
591     }
592 }
593 
CreateHardFile(HWND hDlg,UINT hfsize)594 static BOOL CreateHardFile (HWND hDlg, UINT hfsize)
595 {
596     HANDLE hf;
597     int i = 0;
598     BOOL result = FALSE;
599 
600     char init_path[MAX_PATH] = "";
601 
602     DiskSelection (hDlg, IDC_PATH_NAME, 3, &workprefs);
603     GetDlgItemText (hDlg, IDC_PATH_NAME, init_path, MAX_PATH);
604     if( *init_path && hfsize )
605     {
606 	    SetCursor( LoadCursor( NULL, IDC_WAIT ) );
607 	    if( ( hf = CreateFile (init_path, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL | FILE_FLAG_SEQUENTIAL_SCAN, NULL) ) != INVALID_HANDLE_VALUE )
608 	{
609 	    if( SetFilePointer( hf, hfsize, NULL, FILE_BEGIN ) == hfsize )
610 	    {
611 		result = SetEndOfFile( hf );
612 	    }
613 	    else
614 	    {
615 		write_log ( "SetFilePointer() failure for %s to posn %d\n", init_path, hfsize );
616 	    }
617 	    CloseHandle( hf );
618 	}
619 	else
620 	{
621 	    write_log ( "CreateFile() failed to create %s\n", init_path );
622 	}
623 	SetCursor( LoadCursor( NULL, IDC_ARROW ) );
624     }
625     return result;
626 }
627 
628 static const char *memsize_names[] = {
629 /* 0 */ szNone,
630 /* 1 */ "256 K",
631 /* 2 */ "512 K",
632 /* 3 */ "1 MB",
633 /* 4 */ "2 MB",
634 /* 5 */ "4 MB",
635 /* 6 */ "8 MB",
636 /* 7 */ "16 MB",
637 /* 8 */ "32 MB",
638 /* 9 */ "64 MB",
639 /* 10*/ "128 MB",
640 /* 11*/ "256 MB",
641 /* 12*/ "512 MB",
642 /* 13*/ "1 GB",
643 
644 };
645 
646 static unsigned long memsizes[] = {
647 /* 0 */ 0,
648 /* 1 */ 0x00040000, /*  256-K */
649 /* 2 */ 0x00080000, /*  512-K */
650 /* 3 */ 0x00100000, /*  1-meg */
651 /* 4 */ 0x00200000, /*  2-meg */
652 /* 5 */ 0x00400000, /*  4-meg */
653 /* 6 */ 0x00800000, /*  8-meg */
654 /* 7 */ 0x01000000, /* 16-meg */
655 /* 8 */ 0x02000000, /* 32-meg */
656 /* 9 */ 0x04000000, /* 64-meg */
657 /* 10*/ 0x08000000, //128 Meg
658 /* 11*/ 0x10000000, //256 Meg
659 /* 12*/ 0x20000000, //512 Meg The correct size is set in mman.c
660 /* 13*/ 0x40000000, //1GB Meg
661 };
662 
663 static int msi_chip[] = { 2, 3, 4, 5, 6 };
664 static int msi_bogo[] = { 0, 2, 3 };
665 static int msi_fast[] = { 0, 3, 4, 5, 6 };
666 static int msi_z3fast[] = { 0, 3, 4, 5, 6, 7, 8, 9, 10,11,12,13 };
667 static int msi_gfx[] = { 0, 3, 4, 5, 6,7,8};
668 
CalculateHardfileSize(HWND hDlg)669 static UINT CalculateHardfileSize (HWND hDlg)
670 {
671     BOOL Translated = FALSE;
672     UINT bytes = 0;
673     bytes = GetDlgItemInt( hDlg, IDC_HFSIZE, &Translated, FALSE );
674     if( !Translated )
675 	bytes = 0;
676     return bytes;
677 }
678 
679 
680 static const char *nth[] = {
681     "", "second ", "third ", "fourth ", "fifth ", "sixth ", "seventh ", "eighth ", "ninth ", "tenth "
682 };
683 
AllocateConfigStruct(void)684 ConfigStructPtr AllocateConfigStruct( void )
685 {
686     return xmalloc( sizeof( ConfigStruct ) );
687 }
688 
FreeConfigStruct(ConfigStructPtr cfgptr)689 void FreeConfigStruct( ConfigStructPtr cfgptr )
690 {
691     free( cfgptr );
692 }
693 
GetFirstConfigEntry(HANDLE * file_handle,LPWIN32_FIND_DATA find_data)694 ConfigStructPtr GetFirstConfigEntry( HANDLE *file_handle, LPWIN32_FIND_DATA find_data )
695 {
696     ConfigStructPtr config = NULL;
697     DWORD num_bytes = 0;
698     char init_path[ MAX_PATH ] = "", *posn;
699     char description[ CFG_DESCRIPTION_LENGTH ] = "";
700 
701     if( start_path )
702     {
703 	strncpy( init_path, start_path, MAX_PATH );
704 	strncat( init_path, "\\Configurations\\*.UAE", MAX_PATH );
705     }
706 
707     if( ( *file_handle = FindFirstFile( init_path, find_data ) ) != INVALID_HANDLE_VALUE )
708     {
709 	config = AllocateConfigStruct();
710 	sprintf( init_path, "%s\\Configurations\\%s", start_path, find_data->cFileName );
711 	if( cfgfile_get_description( init_path, description ) )
712 	{
713 	    if( ( posn = strrchr( find_data->cFileName, '.' ) ) != NULL )
714 		*posn = '\0';
715 	    strcpy( config->Name, find_data->cFileName );
716 
717 	    strcpy( config->Description, description );
718 	}
719 	else
720 	{
721 	    FreeConfigStruct( config );
722 	    config = NULL;
723 	}
724     }
725     else
726     {
727 	// Either the directory has no .CFG files, or doesn't exist.
728 
729 	// Create the directory, even if it already exists.  No harm, and don't check return codes, because
730 	// we may be doing this on a read-only media like CD-ROM.
731 	sprintf( init_path, "%s\\Configurations", start_path );
732 	CreateDirectory( init_path, NULL );
733     }
734     return config;
735 }
736 
GetNextConfigEntry(HANDLE * file_handle,LPWIN32_FIND_DATA find_data)737 ConfigStructPtr GetNextConfigEntry( HANDLE *file_handle, LPWIN32_FIND_DATA find_data )
738 {
739     ConfigStructPtr config = NULL;
740     char init_path[ MAX_PATH ] = "";
741     char desc[ CFG_DESCRIPTION_LENGTH ] = "";
742     char *posn;
743 
744     if( FindNextFile( *file_handle, find_data ) == 0 )
745     {
746 	FindClose( *file_handle );
747     }
748     else
749     {
750 	config = AllocateConfigStruct();
751 	sprintf( init_path, "%s\\Configurations\\%s", start_path, find_data->cFileName );
752 	if( cfgfile_get_description( init_path, desc ) )
753 	{
754 	    if( ( posn = strrchr( find_data->cFileName, '.' ) ) != NULL )
755 		*posn = '\0';
756 	    strcpy( config->Name, find_data->cFileName );
757 
758 	    strcpy( config->Description, desc );
759 	}
760 	else
761 	{
762 	    FreeConfigStruct( config );
763 	    config = NULL;
764 	}
765     }
766     return config;
767 }
768 
HandleConfiguration(HWND hDlg,int flag)769 void HandleConfiguration( HWND hDlg, int flag )
770 {
771     char full_path[MAX_PATH] = "";
772     char file_name[MAX_PATH] = "";
773     char init_path[MAX_PATH] = "";
774     ConfigStructPtr cfgptr = NULL;
775     int i;
776 
777     if( ( cfgptr = AllocateConfigStruct() ) != NULL )
778     {
779 	switch( flag )
780 	{
781 	    case CONFIG_SAVE_FULL:
782 		DiskSelection( hDlg, IDC_SAVE, 5, &workprefs );
783 		GetDlgItemText( hDlg, IDC_EDITNAME, full_path, MAX_PATH );
784 		GetDlgItemText( hDlg, IDC_EDITDESCRIPTION, workprefs.description, 256 );
785 		cfgfile_save( &workprefs, full_path );
786 	    break;
787 
788 	    case CONFIG_LOAD_FULL:
789 		DiskSelection( hDlg, IDC_LOAD, 4, &workprefs );
790 		for( i = 0; i < C_PAGES; i++ )
791 		{
792 		    if( pages[i] )
793 			SendMessage( pages[i], WM_USER, 0, 0 );
794 		}
795 		EnableWindow( GetDlgItem( hDlg, IDC_VIEWINFO ), workprefs.info[0] );
796 	    break;
797 
798 	    case CONFIG_SAVE:
799 		GetDlgItemText( hDlg, IDC_EDITNAME, cfgptr->Name, MAX_PATH );
800 		if( cfgptr->Name[0] == '\0' )
801 		{
802 		    char szMessage[ MAX_PATH ];
803 		    WIN32GUI_LoadUIString( IDS_MUSTENTERNAME, szMessage, MAX_PATH );
804 		    gui_message( szMessage );
805 		}
806 		else
807 		{
808 		    if( !strchr( cfgptr->Name, '\\' ) && !strchr( cfgptr->Name, '/' ) )
809 		    {
810 			if( start_path )
811 			{
812 			    strncpy( init_path, start_path, MAX_PATH );
813 			    strncat( init_path, "\\Configurations\\", MAX_PATH );
814 			}
815 
816 			sprintf( full_path, "%s%s.UAE", init_path, cfgptr->Name );
817 		    }
818 		    else
819 		    {
820 			strcpy( full_path, cfgptr->Name );
821 		    }
822 		    GetDlgItemText( hDlg, IDC_EDITDESCRIPTION, workprefs.description, 256 );
823 		    cfgfile_save( &workprefs, full_path );
824 		}
825 	    break;
826 
827 	    case CONFIG_LOAD:
828 		GetDlgItemText( hDlg, IDC_EDITNAME, cfgptr->Name, MAX_PATH );
829 		if( cfgptr->Name[0] == '\0' )
830 		{
831 		    char szMessage[ MAX_PATH ];
832 		    WIN32GUI_LoadUIString( IDS_MUSTSELECTCONFIG, szMessage, MAX_PATH );
833 		    gui_message( szMessage );
834 		}
835 		else
836 		{
837 		    if( start_path )
838 		    {
839 			strncpy( init_path, start_path, MAX_PATH );
840 			strncat( init_path, "\\Configurations\\", MAX_PATH );
841 		    }
842 
843 		    sprintf( full_path, "%s%s.UAE", init_path, cfgptr->Name );
844 		    strcpy( config_filename, cfgptr->Name );
845 
846 		    if( cfgfile_load( &workprefs, full_path ) == 0 )
847 		    {
848 			char szMessage[ MAX_PATH ];
849 			WIN32GUI_LoadUIString( IDS_COULDNOTLOADCONFIG, szMessage, MAX_PATH );
850 			gui_message( szMessage );
851 		    }
852 
853 		    for( i = 0; i < C_PAGES; i++ )
854 		    {
855 			if( pages[i] )
856 			    SendMessage( pages[i], WM_USER, 0, 0 );
857 		    }
858 		    EnableWindow( GetDlgItem( hDlg, IDC_VIEWINFO ), workprefs.info[0] );
859 		}
860 	    break;
861 
862 	    case CONFIG_DELETE:
863 		GetDlgItemText( hDlg, IDC_EDITNAME, cfgptr->Name, MAX_PATH );
864 		if( cfgptr->Name[0] == '\0' )
865 		{
866 		    char szMessage[ MAX_PATH ];
867 		    WIN32GUI_LoadUIString( IDS_MUSTSELECTCONFIGFORDELETE, szMessage, MAX_PATH );
868 		    gui_message( szMessage );
869 		}
870 		else
871 		{
872 		    char szMessage[ MAX_PATH ];
873 		    char szTitle[ MAX_PATH ];
874 		    WIN32GUI_LoadUIString( IDS_DELETECONFIGCONFIRMATION, szMessage, MAX_PATH );
875 		    WIN32GUI_LoadUIString( IDS_DELETECONFIGTITLE, szTitle, MAX_PATH );
876 		    if( MessageBox( hDlg, szMessage, szTitle,
877 				    MB_YESNO | MB_ICONWARNING | MB_APPLMODAL | MB_SETFOREGROUND ) == IDYES )
878 		    {
879 			if( start_path )
880 			{
881 			    strncpy( init_path, start_path, MAX_PATH );
882 			    strncat( init_path, "\\Configurations\\", MAX_PATH );
883 			}
884 
885 			sprintf( full_path, "%s%s.UAE", init_path, cfgptr->Name );
886 			DeleteFile( full_path );
887 		    }
888 		}
889 	    break;
890 	}
891 	FreeConfigStruct( cfgptr );
892     }
893 }
894 
895 static int clicked_entry = -1;
896 
897 #define LOADSAVE_COLUMNS 2
898 #define HARDDISK_COLUMNS 7
899 #define MAX_COLUMN_HEADING_WIDTH 20
900 
InitializeListView(HWND hDlg)901 void InitializeListView( HWND hDlg )
902 {
903     HANDLE file_handle = NULL;
904     WIN32_FIND_DATA find_data;
905     BOOL rc = TRUE;
906     HWND list;
907     LV_ITEM lvstruct;
908     LV_COLUMN lvcolumn;
909     RECT rect;
910     int num_columns = ( hDlg == pages[ LOADSAVE_ID ] ) ? LOADSAVE_COLUMNS : HARDDISK_COLUMNS;
911     char column_heading[ HARDDISK_COLUMNS ][ MAX_COLUMN_HEADING_WIDTH ];
912     char sectors_str[6]   = "";
913     char surfaces_str[6]  = "";
914     char reserved_str[6]  = "";
915     char blocksize_str[6] = "";
916     char readwrite_str[4] = "";
917     char volname_str[ MAX_PATH ] = "";
918     int width = 0, column_width[ HARDDISK_COLUMNS ];
919     int items = 0, result = 0, i, entry = 0, temp = 0;
920     ConfigStructPtr config = NULL;
921 
922     if( num_columns == LOADSAVE_COLUMNS )
923     {
924 	WIN32GUI_LoadUIString( IDS_NAME, column_heading[0], MAX_COLUMN_HEADING_WIDTH );
925 	WIN32GUI_LoadUIString( IDS_DESCRIPTION, column_heading[1], MAX_COLUMN_HEADING_WIDTH );
926 
927 	list = GetDlgItem( hDlg, IDC_CONFIGLIST );
928     }
929     else
930     {
931 	WIN32GUI_LoadUIString( IDS_VOLUME, column_heading[0], MAX_COLUMN_HEADING_WIDTH );
932 	WIN32GUI_LoadUIString( IDS_PATH, column_heading[1], MAX_COLUMN_HEADING_WIDTH );
933 	WIN32GUI_LoadUIString( IDS_RW, column_heading[2], MAX_COLUMN_HEADING_WIDTH );
934 	WIN32GUI_LoadUIString( IDS_SECTORS, column_heading[3], MAX_COLUMN_HEADING_WIDTH );
935 	WIN32GUI_LoadUIString( IDS_SURFACES, column_heading[4], MAX_COLUMN_HEADING_WIDTH );
936 	WIN32GUI_LoadUIString( IDS_RESERVED, column_heading[5], MAX_COLUMN_HEADING_WIDTH );
937 	WIN32GUI_LoadUIString( IDS_BLOCKSIZE, column_heading[6], MAX_COLUMN_HEADING_WIDTH );
938 
939 	list = GetDlgItem( hDlg, IDC_VOLUMELIST );
940     }
941 
942     ListView_DeleteAllItems( list );
943 
944     for( i = 0; i < num_columns; i++ )
945 	column_width[i] = ListView_GetStringWidth( list, column_heading[i] ) + 15;
946 
947     // If there are no columns, then insert some
948     lvcolumn.mask = LVCF_WIDTH;
949     if( ListView_GetColumn( list, 1, &lvcolumn ) == FALSE )
950     {
951 	for( i = 0; i < num_columns; i++ )
952 	{
953 	    lvcolumn.mask     = LVCF_FMT | LVCF_TEXT | LVCF_WIDTH | LVCF_SUBITEM;
954 	    lvcolumn.iSubItem = i;
955 	    lvcolumn.fmt      = LVCFMT_LEFT;
956 	    lvcolumn.pszText  = column_heading[i];
957 	    lvcolumn.cx       = column_width[i];
958 	    ListView_InsertColumn( list, i, &lvcolumn );
959 	}
960     }
961     if( num_columns == LOADSAVE_COLUMNS )
962     {
963 	if( ( config = GetFirstConfigEntry( &file_handle, &find_data ) ) != NULL )
964 	{
965 	    while( config )
966 	    {
967 		lvstruct.mask     = LVIF_TEXT | LVIF_PARAM;
968 		lvstruct.pszText  = config->Name;
969 		lvstruct.lParam   = 0;
970 		lvstruct.iItem    = entry;
971 		lvstruct.iSubItem = 0;
972 		result = ListView_InsertItem( list, &lvstruct );
973 		if( result != -1 )
974 		{
975 		    width = ListView_GetStringWidth( list, lvstruct.pszText ) + 15;
976 		    if( width > column_width[ lvstruct.iSubItem ] )
977 			column_width[ lvstruct.iSubItem ] = width;
978 
979 		    ListView_SetItemText( list, result, 1, config->Description );
980 		    width = ListView_GetStringWidth( list, config->Description ) + 15;
981 		    if( width > column_width[ 1 ] )
982 			column_width[ 1 ] = width;
983 
984 		    entry++;
985 		}
986 		FreeConfigStruct( config );
987 		config = GetNextConfigEntry( &file_handle, &find_data );
988 	    }
989 	}
990     }
991     else
992     {
993 	for( i = 0; i < nr_units( workprefs.mountinfo ); i++ )
994 	{
995 	    int secspertrack, surfaces, reserved, blocksize, size;
996 	    int cylinders, readonly;
997 	    char *volname, *rootdir;
998 	    char *failure;
999 
1000 	    failure = get_filesys_unit (workprefs.mountinfo, i,
1001 					&volname, &rootdir, &readonly,
1002 					&secspertrack, &surfaces, &reserved,
1003 					&cylinders, &size, &blocksize);
1004 
1005 	    if( is_hardfile( workprefs.mountinfo, i ) )
1006 	    {
1007 		sprintf( sectors_str, "%d", secspertrack );
1008 		sprintf( surfaces_str, "%d", surfaces );
1009 		sprintf( reserved_str, "%d", reserved );
1010 		sprintf( blocksize_str, "%d", blocksize );
1011 		sprintf( volname_str, "DH%d", i );
1012 	    }
1013 	    else
1014 	    {
1015 		strcpy( sectors_str, "n/a" );
1016 		strcpy( surfaces_str, "n/a" );
1017 		strcpy( reserved_str, "n/a" );
1018 		strcpy( blocksize_str, "n/a" );
1019 		strcpy( volname_str, volname );
1020 	    }
1021 
1022 	    sprintf( readwrite_str, "%s", readonly ? "no" : "yes" );
1023 	    lvstruct.mask     = LVIF_TEXT | LVIF_PARAM;
1024 	    lvstruct.pszText  = volname_str;
1025 	    lvstruct.lParam   = 0;
1026 	    lvstruct.iItem    = i;
1027 	    lvstruct.iSubItem = 0;
1028 	    result = ListView_InsertItem (list, &lvstruct);
1029 	    if (result != -1) {
1030 		width = ListView_GetStringWidth( list, lvstruct.pszText ) + 15;
1031 		if( width > column_width[ lvstruct.iSubItem ] )
1032 		    column_width[ lvstruct.iSubItem ] = width;
1033 
1034 		ListView_SetItemText( list, result, 1, rootdir );
1035 		width = ListView_GetStringWidth( list, rootdir ) + 15;
1036 		if( width > column_width[ 1 ] )
1037 		    column_width[ 1 ] = width;
1038 
1039 		ListView_SetItemText( list, result, 2, readwrite_str );
1040 		width = ListView_GetStringWidth( list, readwrite_str ) + 15;
1041 		if( width > column_width[ 2 ] )
1042 		    column_width[ 2 ] = width;
1043 
1044 		ListView_SetItemText( list, result, 3, sectors_str );
1045 		width = ListView_GetStringWidth( list, sectors_str ) + 15;
1046 		if( width > column_width[ 3 ] )
1047 		    column_width[ 3 ] = width;
1048 
1049 		ListView_SetItemText( list, result, 4, surfaces_str );
1050 		width = ListView_GetStringWidth( list, surfaces_str ) + 15;
1051 		if( width > column_width[ 4 ] )
1052 		    column_width[ 4 ] = width;
1053 
1054 		ListView_SetItemText( list, result, 5, reserved_str );
1055 		width = ListView_GetStringWidth( list, reserved_str ) + 15;
1056 		if( width > column_width[ 5 ] )
1057 		    column_width[ 5 ] = width;
1058 
1059 		ListView_SetItemText( list, result, 6, blocksize_str );
1060 		width = ListView_GetStringWidth( list, blocksize_str ) + 15;
1061 		if( width > column_width[ 6 ] )
1062 		    column_width[ 6 ] = width;
1063 	    }
1064 	}
1065     }
1066     if( rc == FALSE )
1067     {
1068 	FreeConfigStruct( config );
1069     }
1070 
1071     if( result != -1 )
1072     {
1073 	if( GetWindowRect( list, &rect ) )
1074 	{
1075 	    ScreenToClient( hDlg, (LPPOINT)&rect );
1076 	    ScreenToClient( hDlg, (LPPOINT)&rect.right );
1077 	    if( num_columns == 2 )
1078 	    {
1079 		if( ( temp = rect.right - rect.left - column_width[ 0 ] - 4 ) > column_width[1] )
1080 		    column_width[1] = temp;
1081 	    }
1082 	}
1083 
1084 	// Adjust our column widths so that we can see the contents...
1085 	for( i = 0; i < num_columns; i++ )
1086 	{
1087 	    ListView_SetColumnWidth( list, i, column_width[i] );
1088 	}
1089 
1090 #if 0
1091 	// Turn on full-row-select option
1092 	ListView_SetExtendedListViewStyle( list, LVS_EX_FULLROWSELECT );
1093 #endif
1094 
1095 	// Redraw the items in the list...
1096 	items = ListView_GetItemCount( list );
1097 	ListView_RedrawItems( list, 0, items );
1098     }
1099 }
1100 
listview_find_selected(HWND list)1101 static int listview_find_selected (HWND list)
1102 {
1103     int i, items;
1104     items = ListView_GetItemCount (list);
1105     for (i = 0; i < items; i++) {
1106 	if (ListView_GetItemState (list, i, LVIS_SELECTED) == LVIS_SELECTED)
1107 	    return i;
1108     }
1109     return -1;
1110 }
1111 
listview_entry_from_click(HWND list)1112 static int listview_entry_from_click (HWND list)
1113 {
1114     POINT point;
1115     DWORD pos = GetMessagePos ();
1116     int items, entry;
1117 
1118     point.x = LOWORD (pos);
1119     point.y = HIWORD (pos);
1120     ScreenToClient (list, &point);
1121     entry = ListView_GetTopIndex (list);
1122     items = entry + ListView_GetCountPerPage (list);
1123     if (items > ListView_GetItemCount (list))
1124 	items = ListView_GetItemCount (list);
1125 
1126     while (entry <= items) {
1127 	RECT rect;
1128 	/* Get the bounding rectangle of an item. If the mouse
1129 	 * location is within the bounding rectangle of the item,
1130 	 * you know you have found the item that was being clicked.  */
1131 	ListView_GetItemRect (list, entry, &rect, LVIR_BOUNDS);
1132 	if (PtInRect (&rect, point)) {
1133 	    UINT flag = LVIS_SELECTED | LVIS_FOCUSED;
1134 	    ListView_SetItemState (list, entry, flag, flag);
1135 	    return entry;
1136 	}
1137 	entry++;
1138     }
1139     return -1;
1140 }
1141 
InfoSettingsProc(HWND hDlg,UINT msg,WPARAM wParam,LPARAM lParam)1142 static int CALLBACK InfoSettingsProc (HWND hDlg, UINT msg, WPARAM wParam, LPARAM lParam)
1143 {
1144     static int recursive = 0;
1145 
1146     switch (msg)
1147     {
1148 	case WM_INITDIALOG:
1149 	    recursive++;
1150 	    SetDlgItemText (hDlg, IDC_PATH_NAME, workprefs.info);
1151 	    recursive--;
1152 	return TRUE;
1153 
1154 	case WM_COMMAND:
1155 	    if (recursive)
1156 		break;
1157 	    recursive++;
1158 
1159 	    switch( wParam )
1160 	    {
1161 		case IDC_SELECTOR:
1162 		    DiskSelection (hDlg, IDC_PATH_NAME, 8, &workprefs );
1163 		break;
1164 		case IDOK:
1165 		    EndDialog (hDlg, 1);
1166 		break;
1167 		case IDCANCEL:
1168 		    EndDialog (hDlg, 0);
1169 		break;
1170 	    }
1171 
1172 	    GetDlgItemText( hDlg, IDC_PATH_NAME, workprefs.info, sizeof workprefs.info );
1173 	    recursive--;
1174 	break;
1175     }
1176     return FALSE;
1177 }
1178 
LoadSaveDlgProc(HWND hDlg,UINT msg,WPARAM wParam,LPARAM lParam)1179 static BOOL CALLBACK LoadSaveDlgProc (HWND hDlg, UINT msg, WPARAM wParam, LPARAM lParam)
1180 {
1181     char name_buf[MAX_PATH] = "", desc_buf[128] = "";
1182     char *posn = NULL;
1183     HWND list;
1184     int dblclick = 0;
1185     NM_LISTVIEW *nmlistview;
1186     int items = 0, entry = 0;
1187     LPHELPINFO lpHelpInfo;
1188 
1189     switch (msg) {
1190     case WM_INITDIALOG:
1191 	pages[LOADSAVE_ID] = hDlg;
1192 	InitializeListView(hDlg);
1193 	if( !full_property_sheet )
1194 	{
1195 	    EnableWindow( GetDlgItem( hDlg, IDC_SAVE ), FALSE );
1196 	}
1197 	EnableWindow( GetDlgItem( hDlg, IDC_VIEWINFO ), workprefs.info[0] );
1198 #if 0
1199 	if( !config_filename[0] && configname[0] )
1200 	{
1201 	    if( posn = strrchr( configname, '\\' ) )
1202 		strcpy( configname, ++posn );
1203 	    if( posn = strrchr( configname, '.' ) )
1204 		*posn = '\0';
1205 	    strcpy( config_filename, configname );
1206 	}
1207 #endif
1208 	SetDlgItemText( hDlg, IDC_EDITNAME, config_filename );
1209 	SetDlgItemText( hDlg, IDC_EDITDESCRIPTION, workprefs.description );
1210 	return TRUE;
1211 
1212     case WM_USER:
1213 	break;
1214 
1215     case WM_HELP:
1216 	lpHelpInfo = (LPHELPINFO)lParam;
1217 	break;
1218 
1219     case WM_COMMAND:
1220 	switch (wParam)
1221 	{
1222 	    case IDC_SAVE:
1223 		HandleConfiguration( hDlg, CONFIG_SAVE_FULL );
1224 		InitializeListView( hDlg );
1225 	    break;
1226 	    case IDC_QUICKSAVE:
1227 		HandleConfiguration( hDlg, CONFIG_SAVE );
1228 		InitializeListView( hDlg );
1229 	    break;
1230 	    case IDC_QUICKLOAD:
1231 		HandleConfiguration( hDlg, CONFIG_LOAD );
1232 	    break;
1233 	    case IDC_LOAD:
1234 		HandleConfiguration( hDlg, CONFIG_LOAD_FULL );
1235 	    break;
1236 	    case IDC_DELETE:
1237 		HandleConfiguration( hDlg, CONFIG_DELETE );
1238 		InitializeListView( hDlg );
1239 	    break;
1240 	    case IDC_VIEWINFO:
1241 		if( workprefs.info[0] )
1242 		{
1243 		    if( strstr( workprefs.info, "Configurations\\" ) )
1244 			sprintf( name_buf, "%s\\%s", start_path, workprefs.info );
1245 		    else
1246 			strcpy( name_buf, workprefs.info );
1247 		    ShellExecute( NULL, NULL, name_buf, NULL, NULL, SW_SHOWNORMAL );
1248 		}
1249 	    break;
1250 	    case IDC_SETINFO:
1251 		if( DialogBox( hUIDLL ? hUIDLL : hInst, MAKEINTRESOURCE (IDD_SETINFO), hDlg, InfoSettingsProc ) )
1252 		{
1253 		    EnableWindow( GetDlgItem( hDlg, IDC_VIEWINFO ), workprefs.info[0] );
1254 		}
1255 	    break;
1256 	}
1257 	break;
1258 
1259 	case WM_NOTIFY:
1260 	    if (((LPNMHDR) lParam)->idFrom == IDC_CONFIGLIST)
1261 	    {
1262 		nmlistview = (NM_LISTVIEW *) lParam;
1263 		list = nmlistview->hdr.hwndFrom;
1264 
1265 		switch (nmlistview->hdr.code)
1266 		{
1267 		case NM_DBLCLK:
1268 		    dblclick = 1;
1269 		    /* fall-through */
1270 		case NM_CLICK:
1271 		    entry = listview_entry_from_click (list);
1272 		    /* Copy the item's name and description to the gadgets at the bottom... */
1273 		    if (entry >= 0)
1274 		    {
1275 			ListView_GetItemText (list, entry, 0, name_buf, MAX_PATH);
1276 			ListView_GetItemText (list, entry, 1, desc_buf, 128);
1277 			SetDlgItemText (hDlg, IDC_EDITNAME, name_buf);
1278 			SetDlgItemText (hDlg, IDC_EDITDESCRIPTION, desc_buf);
1279 			ListView_RedrawItems (list, 0, items);
1280 
1281 			if( dblclick )
1282 			{
1283 			    HandleConfiguration( hDlg, CONFIG_LOAD );
1284 			    /* Copy stuff from workprefs and config_xxx settings */
1285 			    gui_to_prefs ();
1286 			    PropSheet_PressButton( hPropertySheet, PSBTN_OK );
1287 			}
1288 		    }
1289 		    break;
1290 		}
1291 	    }
1292 	    else
1293 	    {
1294 		switch (((NMHDR *) lParam)->code)
1295 		{
1296 		case PSN_HELP:
1297 		    HtmlHelp( NULL, help_file, HH_DISPLAY_TOPIC, "configurations.htm" );
1298 		    break;
1299 		case PSN_APPLY:
1300 		    /* Copy stuff from workprefs and config_xxx settings */
1301 		    gui_to_prefs ();
1302 		    break;
1303 
1304 		case PSN_RESET:
1305 		    if (allow_quit)
1306 		    {
1307 			quit_program = 1;
1308 			regs.spcflags |= SPCFLAG_BRK;
1309 		    }
1310 		    break;
1311 		}
1312 	    }
1313 	    break;
1314     }
1315 
1316     return FALSE;
1317 }
1318 
1319 #define MAX_CONTRIBUTORS_LENGTH 2048
1320 
ContributorsProc(HWND hDlg,UINT msg,WPARAM wParam,LPARAM lParam)1321 static int CALLBACK ContributorsProc (HWND hDlg, UINT msg, WPARAM wParam, LPARAM lParam)
1322 {
1323     CHARFORMAT CharFormat;
1324     char szContributors1[ MAX_CONTRIBUTORS_LENGTH ];
1325     char szContributors2[ MAX_CONTRIBUTORS_LENGTH ];
1326     char szContributors[ MAX_CONTRIBUTORS_LENGTH*2 ];
1327 
1328     switch (msg) {
1329      case WM_COMMAND:
1330 	if (wParam == ID_OK) {
1331 	    EndDialog (hDlg, 1);
1332 	    return TRUE;
1333 	}
1334 	break;
1335      case WM_INITDIALOG:
1336 	CharFormat.cbSize = sizeof (CharFormat);
1337 
1338 	WIN32GUI_LoadUIString( IDS_CONTRIBUTORS1, szContributors1, MAX_CONTRIBUTORS_LENGTH );
1339 	WIN32GUI_LoadUIString( IDS_CONTRIBUTORS2, szContributors2, MAX_CONTRIBUTORS_LENGTH );
1340 	sprintf( szContributors, "%s%s", szContributors1, szContributors2 );
1341 
1342 	SetDlgItemText (hDlg, IDC_CONTRIBUTORS, szContributors );
1343 	SendDlgItemMessage (hDlg, IDC_CONTRIBUTORS, EM_GETCHARFORMAT, 0, (LPARAM) & CharFormat);
1344 	CharFormat.dwMask |= CFM_SIZE | CFM_FACE;
1345 	CharFormat.yHeight = 10 * 20;	/* height in twips, where a twip is 1/20th of a point - for a pt.size of 18 */
1346 
1347 	strcpy (CharFormat.szFaceName, "Times New Roman");
1348 	SendDlgItemMessage (hDlg, IDC_CONTRIBUTORS, EM_SETCHARFORMAT, SCF_ALL, (LPARAM) & CharFormat);
1349 	/* SendDlgItemMessage(hDlg, IDC_CONTRIBUTORS, EM_SETBKGNDCOLOR,0,GetSysColor( COLOR_3DFACE ) ); */
1350 
1351 	return TRUE;
1352     }
1353     return FALSE;
1354 }
1355 
DisplayContributors(HWND hDlg)1356 static void DisplayContributors (HWND hDlg)
1357 {
1358     DialogBox( hUIDLL ? hUIDLL : hInst, MAKEINTRESOURCE (IDD_CONTRIBUTORS), hDlg, ContributorsProc);
1359 }
1360 
1361 #define NUM_URLS 7
1362 typedef struct url_info
1363 {
1364     int   id;
1365     BOOL  state;
1366     char *display;
1367     char *url;
1368 } urlinfo;
1369 
1370 static urlinfo urls[NUM_URLS] =
1371 {
1372     {IDC_CLOANTOHOME, FALSE, "Cloanto's Amiga Forever", "http://www.cloanto.com/amiga/forever/"},
1373     {IDC_AMIGAHOME, FALSE, "Amiga Inc.", "http://www.amiga.com"},
1374     {IDC_PICASSOHOME, FALSE, "Picasso96 Home Page", "http://www.picasso96.cogito.de/"},
1375     {IDC_UAEHOME, FALSE, "UAE Home Page", "http://www.freiburg.linux.de/~uae/"},
1376     {IDC_WINUAEHOME, FALSE, "WinUAE Home Page", "http://www.CodePoet.com/UAE/"},
1377     {IDC_AIABHOME, FALSE, "AIAB", "http://aiab.emuunlim.com/"},
1378     {IDC_THEROOTS, FALSE, "Back To The Roots", "http://back2roots.emuunlim.com/"}
1379 };
1380 
SetupRichText(HWND hDlg,urlinfo * url)1381 static void SetupRichText( HWND hDlg, urlinfo *url )
1382 {
1383     CHARFORMAT CharFormat;
1384     CharFormat.cbSize = sizeof (CharFormat);
1385 
1386     SetDlgItemText( hDlg, url->id, url->display );
1387     SendDlgItemMessage( hDlg, url->id, EM_GETCHARFORMAT, 0, (LPARAM)&CharFormat );
1388     CharFormat.dwMask   |= CFM_UNDERLINE | CFM_SIZE | CFM_FACE | CFM_COLOR;
1389     CharFormat.dwEffects = url->state ? CFE_UNDERLINE : 0;
1390     CharFormat.yHeight = 10 * 20;	/* height in twips, where a twip is 1/20th of a point - for a pt.size of 18 */
1391 
1392     CharFormat.crTextColor = GetSysColor( COLOR_ACTIVECAPTION );
1393     strcpy( CharFormat.szFaceName, "Tahoma" );
1394     SendDlgItemMessage( hDlg, url->id, EM_SETCHARFORMAT, SCF_ALL, (LPARAM)&CharFormat );
1395     SendDlgItemMessage( hDlg, url->id, EM_SETBKGNDCOLOR, 0, GetSysColor( COLOR_3DFACE ) );
1396 }
1397 
url_handler(HWND hDlg,UINT msg,WPARAM wParam,LPARAM lParam)1398 static void url_handler(HWND hDlg, UINT msg, WPARAM wParam, LPARAM lParam )
1399 {
1400     static int last_rectangle = -1;
1401     int i;
1402     BOOL found = FALSE;
1403     HCURSOR m_hCursor = NULL;
1404     POINT point;
1405     point.x = LOWORD (lParam);
1406     point.y = HIWORD (lParam);
1407 
1408     for (i = 0; i < NUM_URLS; i++)
1409     {
1410 	RECT rect;
1411 	GetWindowRect( GetDlgItem( hDlg, urls[i].id), &rect );
1412 	ScreenToClient( hDlg, (POINT *) &rect );
1413 	ScreenToClient( hDlg, (POINT *) &(rect.right) );
1414 	if( PtInRect( &rect, point ) )
1415 	{
1416 	    if( msg == WM_LBUTTONDOWN )
1417 	    {
1418 		ShellExecute (NULL, NULL, urls[i].url , NULL, NULL, SW_SHOWNORMAL);
1419 		SetCursor( LoadCursor( NULL, MAKEINTRESOURCE(IDC_ARROW) ) );
1420 	    }
1421 	    else
1422 	    {
1423 		if( ( i != last_rectangle ) )
1424 		{
1425 		    // try and load the system hand (Win2000+)
1426 		    m_hCursor = LoadCursor(NULL, MAKEINTRESOURCE(IDC_HAND) );
1427 		    if (!m_hCursor)
1428 		    {
1429 			// retry with our fallback hand
1430 			m_hCursor = LoadCursor(hInst, MAKEINTRESOURCE(IDC_MYHAND) );
1431 		    }
1432 		    SetCursor( m_hCursor );
1433 		    urls[i].state = TRUE;
1434 		    SetupRichText( hDlg, &urls[i] );
1435 
1436 		    if( last_rectangle != -1 )
1437 		    {
1438 			urls[last_rectangle].state = FALSE;
1439 			SetupRichText( hDlg, &urls[last_rectangle] );
1440 		    }
1441 		}
1442 	    }
1443 	    last_rectangle = i;
1444 	    found = TRUE;
1445 	    break;
1446 	}
1447     }
1448 
1449     if( !found && last_rectangle >= 0 )
1450     {
1451 	SetCursor( LoadCursor( NULL, MAKEINTRESOURCE(IDC_ARROW) ) );
1452 	urls[last_rectangle].state = FALSE;
1453 	SetupRichText( hDlg, &urls[last_rectangle] );
1454 	last_rectangle = -1;
1455     }
1456 }
1457 
init_aboutdlg(HWND hDlg)1458 static void init_aboutdlg (HWND hDlg)
1459 {
1460     CHARFORMAT CharFormat;
1461     int i;
1462 
1463     CharFormat.cbSize = sizeof (CharFormat);
1464 
1465     SetDlgItemText (hDlg, IDC_RICHEDIT1, "UAE/Win32");
1466     SendDlgItemMessage (hDlg, IDC_RICHEDIT1, EM_GETCHARFORMAT, 0, (LPARAM) & CharFormat);
1467     CharFormat.dwMask |= CFM_BOLD | CFM_SIZE | CFM_FACE;
1468     CharFormat.dwEffects = CFE_BOLD;
1469     CharFormat.yHeight = 18 * 20;	/* height in twips, where a twip is 1/20th of a point - for a pt.size of 18 */
1470 
1471     strcpy (CharFormat.szFaceName, "Times New Roman");
1472     SendDlgItemMessage (hDlg, IDC_RICHEDIT1, EM_SETCHARFORMAT, SCF_ALL, (LPARAM) & CharFormat);
1473     SendDlgItemMessage (hDlg, IDC_RICHEDIT1, EM_SETBKGNDCOLOR, 0, GetSysColor (COLOR_3DFACE));
1474 
1475     SetDlgItemText (hDlg, IDC_RICHEDIT2, VersionStr );
1476     SendDlgItemMessage (hDlg, IDC_RICHEDIT2, EM_GETCHARFORMAT, 0, (LPARAM) & CharFormat);
1477     CharFormat.dwMask |= CFM_SIZE | CFM_FACE;
1478     CharFormat.yHeight = 10 * 20;
1479     strcpy (CharFormat.szFaceName, "Times New Roman");
1480     SendDlgItemMessage (hDlg, IDC_RICHEDIT2, EM_SETCHARFORMAT, SCF_ALL, (LPARAM) & CharFormat);
1481     SendDlgItemMessage (hDlg, IDC_RICHEDIT2, EM_SETBKGNDCOLOR, 0, GetSysColor (COLOR_3DFACE));
1482 
1483     for( i = 0; i < NUM_URLS; i++ )
1484     {
1485 	SetupRichText( hDlg, &urls[i] );
1486     }
1487 }
1488 
AboutDlgProc(HWND hDlg,UINT msg,WPARAM wParam,LPARAM lParam)1489 static BOOL CALLBACK AboutDlgProc (HWND hDlg, UINT msg, WPARAM wParam, LPARAM lParam)
1490 {
1491     switch( msg )
1492     {
1493 	case WM_INITDIALOG:
1494 	    pages[ABOUT_ID] = hDlg;
1495 	    init_aboutdlg (hDlg);
1496 	    break;
1497 
1498 	case WM_COMMAND:
1499 	    if (wParam == IDC_CONTRIBUTORS)
1500 	    {
1501 		DisplayContributors (hDlg);
1502 	    }
1503 	    break;
1504 	case WM_SETCURSOR:
1505 	    return TRUE;
1506 	    break;
1507 	case WM_LBUTTONDOWN:
1508 	case WM_MOUSEMOVE:
1509 	    url_handler( hDlg, msg, wParam, lParam );
1510 	    break;
1511 	case WM_NOTIFY:
1512 	    switch (((NMHDR *) lParam)->code)
1513 	    {
1514 		case PSN_APPLY:
1515 		    /* Copy stuff from workprefs and config_xxx settings */
1516 		    gui_to_prefs ();
1517 		    break;
1518 
1519 		case PSN_RESET:
1520 		    if (allow_quit)
1521 		    {
1522 			quit_program = 1;
1523 			regs.spcflags |= SPCFLAG_BRK;
1524 		    }
1525 		    break;
1526 	    }
1527 	    break;
1528     }
1529 
1530     return FALSE;
1531 }
1532 
GetDisplayMode(int logical_number)1533 static struct win32_displaymode *GetDisplayMode (int logical_number)
1534 {
1535     struct win32_displaymode *dm = win32_displaymode_list;
1536     while (logical_number > 0 && dm != 0)
1537 	dm = dm->next, logical_number--;
1538     return dm;
1539 }
1540 
enable_for_displaydlg(HWND hDlg)1541 static void enable_for_displaydlg (HWND hDlg)
1542 {
1543     if (! full_property_sheet)
1544     {
1545 	/* Disable certain controls which are only to be set once at start-up... */
1546 	EnableWindow (GetDlgItem (hDlg, IDC_TEST16BIT), FALSE);
1547 	EnableWindow (GetDlgItem (hDlg, IDC_LORES), FALSE);
1548 	EnableWindow (GetDlgItem (hDlg, IDC_XCENTER), FALSE);
1549 	EnableWindow (GetDlgItem (hDlg, IDC_YCENTER), FALSE);
1550 	EnableWindow (GetDlgItem (hDlg, IDC_ASPECT), FALSE);
1551 	EnableWindow (GetDlgItem (hDlg, IDC_LM_NORMAL), FALSE);
1552 	EnableWindow (GetDlgItem (hDlg, IDC_LM_DOUBLED), FALSE);
1553 	EnableWindow (GetDlgItem (hDlg, IDC_LM_SCANLINES), FALSE);
1554 	EnableWindow (GetDlgItem (hDlg, IDC_RESOLUTION), FALSE);
1555 	EnableWindow (GetDlgItem (hDlg, IDC_XSIZE), FALSE);
1556 	EnableWindow (GetDlgItem (hDlg, IDC_YSIZE), FALSE);
1557     }
1558     else
1559     {
1560 	EnableWindow( GetDlgItem( hDlg, IDC_PFULLSCREEN ), ! workprefs.address_space_24);
1561 	EnableWindow( GetDlgItem( hDlg, IDC_XSIZE ), workprefs.gfx_afullscreen ? FALSE:TRUE );
1562 	EnableWindow( GetDlgItem( hDlg, IDC_YSIZE ), workprefs.gfx_afullscreen ? FALSE:TRUE );
1563 	EnableWindow( GetDlgItem( hDlg, IDC_RESOLUTION ), workprefs.gfx_afullscreen ? TRUE:FALSE );
1564     }
1565 }
1566 
enable_for_chipsetdlg(HWND hDlg)1567 static void enable_for_chipsetdlg (HWND hDlg)
1568 {
1569 }
1570 
LoadNthString(DWORD value,char * nth,DWORD dwNthMax)1571 static void LoadNthString( DWORD value, char *nth, DWORD dwNthMax )
1572 {
1573     switch( value )
1574     {
1575 	case 1:
1576 	    WIN32GUI_LoadUIString( IDS_SECOND, nth, dwNthMax );
1577 	break;
1578 
1579 	case 2:
1580 	    WIN32GUI_LoadUIString( IDS_THIRD, nth, dwNthMax );
1581 	break;
1582 
1583 	case 3:
1584 	    WIN32GUI_LoadUIString( IDS_FOURTH, nth, dwNthMax );
1585 	break;
1586 
1587 	case 4:
1588 	    WIN32GUI_LoadUIString( IDS_FIFTH, nth, dwNthMax );
1589 	break;
1590 
1591 	case 5:
1592 	    WIN32GUI_LoadUIString( IDS_SIXTH, nth, dwNthMax );
1593 	break;
1594 
1595 	case 6:
1596 	    WIN32GUI_LoadUIString( IDS_SEVENTH, nth, dwNthMax );
1597 	break;
1598 
1599 	case 7:
1600 	    WIN32GUI_LoadUIString( IDS_EIGHTH, nth, dwNthMax );
1601 	break;
1602 
1603 	case 8:
1604 	    WIN32GUI_LoadUIString( IDS_NINTH, nth, dwNthMax );
1605 	break;
1606 
1607 	case 9:
1608 	    WIN32GUI_LoadUIString( IDS_TENTH, nth, dwNthMax );
1609 	break;
1610 
1611 	default:
1612 	    strcpy( nth, "" );
1613     }
1614 }
1615 
1616 #define MAX_FRAMERATE_LENGTH 40
1617 #define MAX_NTH_LENGTH 20
1618 
values_to_displaydlg(HWND hDlg)1619 static void values_to_displaydlg (HWND hDlg)
1620 {
1621     char buffer[ MAX_FRAMERATE_LENGTH + MAX_NTH_LENGTH ];
1622     char Nth[ MAX_NTH_LENGTH ];
1623     LPSTR blah[1] = { Nth };
1624     LPTSTR string = NULL;
1625     int d,d2,index;
1626 
1627     switch( workprefs.color_mode )
1628     {
1629     case 2:
1630 	d = 16;
1631 	break;
1632     case 5:
1633 	d = 32;
1634 	break;
1635     default:
1636 	d = 8;
1637 	break;
1638     }
1639 
1640     if( workprefs.gfx_afullscreen )
1641     {
1642 	d2 = d;
1643 	if( ( index = WIN32GFX_AdjustScreenmode( &workprefs.gfx_width, &workprefs.gfx_height, &d2 ) ) >= 0 )
1644 	{
1645 	    switch( d2 )
1646 	    {
1647 	    case 15:
1648 		workprefs.color_mode = 1;
1649 		d = 2;
1650 		break;
1651 	    case 16:
1652 		workprefs.color_mode = 2;
1653 		d = 2;
1654 		break;
1655 	    case 32:
1656 		workprefs.color_mode = 5;
1657 		d = 4;
1658 		break;
1659 	    default:
1660 		workprefs.color_mode = 0;
1661 		d = 1;
1662 		break;
1663 	    }
1664 	}
1665     }
1666     else
1667     {
1668 	d = d/8;
1669     }
1670 
1671     if ((index = picasso_display_mode_index (workprefs.gfx_width, workprefs.gfx_height, d)) >= 0)
1672 	SendDlgItemMessage( hDlg, IDC_RESOLUTION, CB_SETCURSEL, index, 0 );
1673 
1674     SetDlgItemInt( hDlg, IDC_XSIZE, workprefs.gfx_width, FALSE );
1675     SetDlgItemInt( hDlg, IDC_YSIZE, workprefs.gfx_height, FALSE );
1676 
1677     SendDlgItemMessage (hDlg, IDC_FRAMERATE, TBM_SETPOS, TRUE, workprefs.gfx_framerate);
1678 
1679     WIN32GUI_LoadUIString( IDS_FRAMERATE, buffer, MAX_FRAMERATE_LENGTH );
1680     LoadNthString( workprefs.gfx_framerate - 1, Nth, MAX_NTH_LENGTH );
1681     if( FormatMessage( FORMAT_MESSAGE_FROM_STRING | FORMAT_MESSAGE_ARGUMENT_ARRAY | FORMAT_MESSAGE_ALLOCATE_BUFFER,
1682 		       buffer, 0, 0, (LPTSTR)&string, MAX_FRAMERATE_LENGTH + MAX_NTH_LENGTH, (va_list *)blah ) == 0 )
1683     {
1684 	DWORD dwLastError = GetLastError();
1685 	sprintf (buffer, "Every %s Frame", nth[workprefs.gfx_framerate - 1]);
1686 	SetDlgItemText( hDlg, IDC_RATETEXT, buffer );
1687     }
1688     else
1689     {
1690 	SetDlgItemText( hDlg, IDC_RATETEXT, string );
1691 	LocalFree( string );
1692     }
1693 
1694     CheckRadioButton( hDlg, IDC_LM_NORMAL, IDC_LM_SCANLINES, IDC_LM_NORMAL+workprefs.gfx_linedbl );
1695     CheckDlgButton (hDlg, IDC_AFULLSCREEN, workprefs.gfx_afullscreen);
1696     CheckDlgButton (hDlg, IDC_PFULLSCREEN, workprefs.gfx_pfullscreen);
1697     CheckDlgButton (hDlg, IDC_ASPECT, workprefs.gfx_correct_aspect);
1698     CheckDlgButton (hDlg, IDC_LORES, workprefs.gfx_lores);
1699 
1700     CheckDlgButton (hDlg, IDC_XCENTER, workprefs.gfx_xcenter);
1701     CheckDlgButton (hDlg, IDC_YCENTER, workprefs.gfx_ycenter);
1702 }
1703 
init_resolution_combo(HWND hDlg)1704 static void init_resolution_combo (HWND hDlg)
1705 {
1706     int i;
1707 
1708     for( i = 0; i < picasso_nr_resolutions (); i++ )
1709     {
1710 	SendDlgItemMessage( hDlg, IDC_RESOLUTION, CB_ADDSTRING, 0, (LPARAM)(LPCTSTR)DisplayModes[i].name );
1711     }
1712 }
1713 
values_from_displaydlg(HWND hDlg,UINT msg,WPARAM wParam,LPARAM lParam)1714 static void values_from_displaydlg (HWND hDlg, UINT msg, WPARAM wParam, LPARAM lParam)
1715 {
1716     BOOL success = FALSE;
1717 
1718     workprefs.gfx_pfullscreen    = IsDlgButtonChecked (hDlg, IDC_PFULLSCREEN);
1719     workprefs.gfx_afullscreen    = IsDlgButtonChecked (hDlg, IDC_AFULLSCREEN);
1720     EnableWindow( GetDlgItem( hDlg, IDC_RESOLUTION ), workprefs.gfx_afullscreen ? TRUE:FALSE );
1721 
1722     workprefs.gfx_lores          = IsDlgButtonChecked (hDlg, IDC_LORES);
1723     workprefs.gfx_correct_aspect = IsDlgButtonChecked (hDlg, IDC_ASPECT);
1724     workprefs.gfx_linedbl = ( IsDlgButtonChecked( hDlg, IDC_LM_SCANLINES ) ? 2 :
1725 			      IsDlgButtonChecked( hDlg, IDC_LM_DOUBLED ) ? 1 : 0 );
1726 
1727     workprefs.gfx_framerate = SendDlgItemMessage (hDlg, IDC_FRAMERATE, TBM_GETPOS, 0, 0);
1728 
1729     {
1730 	char buffer[ MAX_FRAMERATE_LENGTH ];
1731 	char Nth[ MAX_NTH_LENGTH ];
1732 	LPSTR blah[1] = { Nth };
1733 	LPTSTR string = NULL;
1734 
1735 	WIN32GUI_LoadUIString( IDS_FRAMERATE, buffer, MAX_FRAMERATE_LENGTH );
1736 	LoadNthString( workprefs.gfx_framerate - 1, Nth, MAX_NTH_LENGTH );
1737 	if( FormatMessage( FORMAT_MESSAGE_FROM_STRING | FORMAT_MESSAGE_ARGUMENT_ARRAY | FORMAT_MESSAGE_ALLOCATE_BUFFER,
1738 			   buffer, 0, 0, (LPTSTR)&string, MAX_FRAMERATE_LENGTH + MAX_NTH_LENGTH, (va_list *)blah ) == 0 )
1739 	{
1740 	    DWORD dwLastError = GetLastError();
1741 	    sprintf (buffer, "Every %s Frame", nth[workprefs.gfx_framerate - 1]);
1742 	    SetDlgItemText( hDlg, IDC_RATETEXT, buffer );
1743 	}
1744 	else
1745 	{
1746 	    SetDlgItemText( hDlg, IDC_RATETEXT, string );
1747 	    LocalFree( string );
1748 	}
1749 	workprefs.gfx_width  = GetDlgItemInt( hDlg, IDC_XSIZE, &success, FALSE );
1750 	if( !success )
1751 	    workprefs.gfx_width = 800;
1752 	workprefs.gfx_height = GetDlgItemInt( hDlg, IDC_YSIZE, &success, FALSE );
1753 	if( !success )
1754 	    workprefs.gfx_height = 600;
1755     }
1756     workprefs.gfx_xcenter = (IsDlgButtonChecked (hDlg, IDC_XCENTER) ? 2 : 0 ); /* Smart centering */
1757     workprefs.gfx_ycenter = (IsDlgButtonChecked (hDlg, IDC_YCENTER) ? 2 : 0 ); /* Smart centering */
1758 
1759     if (msg == WM_COMMAND && LOWORD (wParam) == IDC_RESOLUTION && HIWORD (wParam) == CBN_SELCHANGE)
1760     {
1761 	    LONG posn;
1762 	    posn = SendDlgItemMessage (hDlg, IDC_RESOLUTION, CB_GETCURSEL, 0, 0);
1763 	    if (posn == CB_ERR)
1764 		return;
1765 	workprefs.gfx_width  = DisplayModes[posn].res.width;
1766 	workprefs.gfx_height = DisplayModes[posn].res.height;
1767 	switch( DisplayModes[posn].depth )
1768 	{
1769 	case 2:
1770 	    workprefs.color_mode = 2;
1771 	    break;
1772 	case 3:
1773 	case 4:
1774 	    workprefs.color_mode = 5;
1775 	    break;
1776 	default:
1777 	    workprefs.color_mode = 0;
1778 	    break;
1779 	}
1780 	/* Set the Int boxes */
1781 	SetDlgItemInt( hDlg, IDC_XSIZE, workprefs.gfx_width, FALSE );
1782 	SetDlgItemInt( hDlg, IDC_YSIZE, workprefs.gfx_height, FALSE );
1783     }
1784 }
1785 
DisplayDlgProc(HWND hDlg,UINT msg,WPARAM wParam,LPARAM lParam)1786 static BOOL CALLBACK DisplayDlgProc (HWND hDlg, UINT msg, WPARAM wParam, LPARAM lParam)
1787 {
1788     static int recursive = 0;
1789     HKEY hPixelFormatKey;
1790     RGBFTYPE colortype      = RGBFB_NONE;
1791     DWORD dwType            = REG_DWORD;
1792     DWORD dwDisplayInfoSize = sizeof( colortype );
1793 
1794     switch (msg)
1795     {
1796     case WM_INITDIALOG:
1797 	pages[DISPLAY_ID] = hDlg;
1798 	SendDlgItemMessage (hDlg, IDC_FRAMERATE, TBM_SETPAGESIZE, 0, 1);
1799 	SendDlgItemMessage (hDlg, IDC_FRAMERATE, TBM_SETRANGE, TRUE, MAKELONG (MIN_REFRESH_RATE, MAX_REFRESH_RATE));
1800 	init_resolution_combo( hDlg );
1801 
1802     case WM_USER:
1803 	recursive++;
1804 	values_to_displaydlg (hDlg);
1805 	enable_for_displaydlg (hDlg);
1806 	recursive--;
1807 	break;
1808 
1809     case WM_HSCROLL:
1810     case WM_COMMAND:
1811 	if (recursive > 0)
1812 	    break;
1813 	recursive++;
1814 	if( ( wParam == IDC_TEST16BIT ) && DirectDraw_Start() )
1815 	{
1816 	    if( RegOpenKeyEx( HKEY_CURRENT_USER, "Software\\CodePoet Computing\\WinUAE", 0, KEY_ALL_ACCESS, &hPixelFormatKey ) == ERROR_SUCCESS )
1817 	    {
1818 		char szMessage[ 4096 ];
1819 		char szTitle[ MAX_PATH ];
1820 		WIN32GUI_LoadUIString( IDS_GFXCARDCHECK, szMessage, 4096 );
1821 		WIN32GUI_LoadUIString( IDS_GFXCARDTITLE, szTitle, MAX_PATH );
1822 
1823 		if( MessageBox( NULL, szMessage, szTitle,
1824 				MB_YESNO | MB_ICONWARNING | MB_TASKMODAL | MB_SETFOREGROUND ) == IDYES )
1825 		{
1826 		    colortype = WIN32GFX_FigurePixelFormats(0);
1827 		    RegSetValueEx( hPixelFormatKey, "DisplayInfo", 0, REG_DWORD, (CONST BYTE *)&colortype, sizeof( colortype ) );
1828 		}
1829 		RegCloseKey( hPixelFormatKey );
1830 	    }
1831 	    else
1832 	    {
1833 		write_log ( "WinUAE is missing HKEY_LOCAL_MACHINE Registry keys!  These can only be created by a valid Setup program.\n" );
1834 	    }
1835 	    DirectDraw_Release();
1836 	}
1837 	else
1838 	{
1839 	    values_from_displaydlg (hDlg, msg, wParam, lParam);
1840 	    enable_for_displaydlg( hDlg );
1841 	}
1842 	recursive--;
1843 	break;
1844 
1845     case WM_NOTIFY:
1846 	switch (((NMHDR *) lParam)->code)
1847 	{
1848 	case PSN_HELP:
1849 	    HtmlHelp( NULL, help_file, HH_DISPLAY_TOPIC, "display.htm" );
1850 	    break;
1851 
1852 	case PSN_APPLY:
1853 	    /* Copy stuff from workprefs and config_xxx settings */
1854 	    gui_to_prefs ();
1855 	    break;
1856 
1857 	case PSN_RESET:
1858 	    if (allow_quit)
1859 	    {
1860 		quit_program = 1;
1861 		regs.spcflags |= SPCFLAG_BRK;
1862 	    }
1863 	    break;
1864 	}
1865 	break;
1866     }
1867     return FALSE;
1868 }
1869 
values_to_chipsetdlg(HWND hDlg)1870 static void values_to_chipsetdlg (HWND hDlg)
1871 {
1872     char buffer[ MAX_FRAMERATE_LENGTH + MAX_NTH_LENGTH ];
1873     char Nth[ MAX_NTH_LENGTH ];
1874     LPSTR blah[1] = { Nth };
1875     LPTSTR string = NULL;
1876     int d,d2,index;
1877 
1878     switch( workprefs.chipset_mask )
1879     {
1880     case 0:
1881 	CheckRadioButton( hDlg, IDC_OCS, IDC_AGA, IDC_OCS+0 );
1882 	break;
1883     case CSMASK_ECS_AGNUS:
1884 	CheckRadioButton( hDlg, IDC_OCS, IDC_AGA, IDC_OCS+1 );
1885 	break;
1886     case CSMASK_ECS_DENISE:
1887 	CheckRadioButton( hDlg, IDC_OCS, IDC_AGA, IDC_OCS+2 );
1888 	break;
1889     case CSMASK_ECS_AGNUS | CSMASK_ECS_DENISE:
1890 	CheckRadioButton( hDlg, IDC_OCS, IDC_AGA, IDC_OCS+3 );
1891 	break;
1892     case CSMASK_AGA:
1893     case CSMASK_ECS_AGNUS | CSMASK_ECS_DENISE | CSMASK_AGA:
1894 	CheckRadioButton( hDlg, IDC_OCS, IDC_AGA, IDC_OCS+4 );
1895 	break;
1896     }
1897 
1898     CheckDlgButton (hDlg, IDC_BLITIMM, workprefs.immediate_blits);
1899     CheckDlgButton (hDlg, IDC_NTSC, workprefs.ntscmode);
1900 
1901     CheckRadioButton (hDlg, IDC_COLLISION0, IDC_COLLISION3, IDC_COLLISION0 + workprefs.collision_level);
1902     CheckDlgButton (hDlg, IDC_FASTCOPPER, workprefs.fast_copper );
1903 }
1904 
values_from_chipsetdlg(HWND hDlg,UINT msg,WPARAM wParam,LPARAM lParam)1905 static void values_from_chipsetdlg (HWND hDlg, UINT msg, WPARAM wParam, LPARAM lParam)
1906 {
1907     BOOL success = FALSE;
1908 
1909     workprefs.fast_copper = IsDlgButtonChecked (hDlg, IDC_FASTCOPPER);
1910     workprefs.immediate_blits = IsDlgButtonChecked (hDlg, IDC_BLITIMM);
1911     workprefs.collision_level = (IsDlgButtonChecked (hDlg, IDC_COLLISION0) ? 0
1912 				 : IsDlgButtonChecked (hDlg, IDC_COLLISION1) ? 1
1913 				 : IsDlgButtonChecked (hDlg, IDC_COLLISION2) ? 2 : 3);
1914     workprefs.chipset_mask = (IsDlgButtonChecked( hDlg, IDC_OCS ) ? 0
1915 			      : IsDlgButtonChecked( hDlg, IDC_ECS_AGNUS ) ? CSMASK_ECS_AGNUS
1916 			      : IsDlgButtonChecked( hDlg, IDC_ECS_DENISE ) ? CSMASK_ECS_DENISE
1917 			      : IsDlgButtonChecked( hDlg, IDC_ECS ) ? CSMASK_ECS_AGNUS | CSMASK_ECS_DENISE
1918 			      : CSMASK_AGA | CSMASK_ECS_AGNUS | CSMASK_ECS_DENISE);
1919     workprefs.ntscmode = (IsDlgButtonChecked (hDlg, IDC_NTSC) ? 1 : 0);
1920 }
1921 
ChipsetDlgProc(HWND hDlg,UINT msg,WPARAM wParam,LPARAM lParam)1922 static BOOL CALLBACK ChipsetDlgProc (HWND hDlg, UINT msg, WPARAM wParam, LPARAM lParam)
1923 {
1924     static int recursive = 0;
1925     HKEY hPixelFormatKey;
1926     RGBFTYPE colortype      = RGBFB_NONE;
1927     DWORD dwType            = REG_DWORD;
1928     DWORD dwDisplayInfoSize = sizeof( colortype );
1929 
1930     switch (msg) {
1931     case WM_INITDIALOG:
1932 	pages[CHIPSET_ID] = hDlg;
1933 
1934     case WM_USER:
1935 	recursive++;
1936 	values_to_chipsetdlg (hDlg);
1937 	enable_for_chipsetdlg (hDlg);
1938 	recursive--;
1939 	break;
1940 
1941     case WM_HSCROLL:
1942     case WM_COMMAND:
1943 	if (recursive > 0)
1944 	    break;
1945 	recursive++;
1946 	values_from_chipsetdlg (hDlg, msg, wParam, lParam);
1947 	enable_for_chipsetdlg( hDlg );
1948 	recursive--;
1949 	break;
1950 
1951     case WM_NOTIFY:
1952 	switch (((NMHDR *) lParam)->code) {
1953 	case PSN_HELP:
1954 	    HtmlHelp( NULL, help_file, HH_DISPLAY_TOPIC, "chipset.htm" );
1955 	    break;
1956 
1957 	case PSN_APPLY:
1958 	    /* Copy stuff from workprefs and config_xxx settings */
1959 	    gui_to_prefs ();
1960 	    break;
1961 
1962 	case PSN_RESET:
1963 	    if (allow_quit) {
1964 		quit_program = 1;
1965 		regs.spcflags |= SPCFLAG_BRK;
1966 	    }
1967 	    break;
1968 	}
1969 	break;
1970     }
1971     return FALSE;
1972 }
1973 
enable_for_memorydlg(HWND hDlg)1974 static void enable_for_memorydlg (HWND hDlg)
1975 {
1976     EnableWindow (GetDlgItem (hDlg, IDC_Z3TEXT), ! workprefs.address_space_24);
1977     EnableWindow (GetDlgItem (hDlg, IDC_Z3FASTRAM), ! workprefs.address_space_24);
1978     EnableWindow (GetDlgItem (hDlg, IDC_Z3FASTMEM), ! workprefs.address_space_24);
1979     EnableWindow (GetDlgItem (hDlg, IDC_FASTMEM), workprefs.chipmem_size <= 0x200000);
1980     EnableWindow (GetDlgItem (hDlg, IDC_FASTRAM), workprefs.chipmem_size <= 0x200000);
1981     EnableWindow (GetDlgItem (hDlg, IDC_FASTTEXT), workprefs.chipmem_size <= 0x200000);
1982     EnableWindow (GetDlgItem (hDlg, IDC_GFXCARDTEXT), ! workprefs.address_space_24);
1983     EnableWindow (GetDlgItem (hDlg, IDC_P96RAM), ! workprefs.address_space_24);
1984     EnableWindow (GetDlgItem (hDlg, IDC_P96MEM), ! workprefs.address_space_24);
1985 }
1986 
values_to_memorydlg(HWND hDlg)1987 static void values_to_memorydlg (HWND hDlg)
1988 {
1989     uae_u32 mem_size = 0;
1990 
1991     switch (workprefs.chipmem_size) {
1992      case 0x00080000: mem_size = 0; break;
1993      case 0x00100000: mem_size = 1; break;
1994      case 0x00200000: mem_size = 2; break;
1995      case 0x00400000: mem_size = 3; break;
1996      case 0x00800000: mem_size = 4; break;
1997     }
1998     SendDlgItemMessage (hDlg, IDC_CHIPMEM, TBM_SETPOS, TRUE, mem_size);
1999     SetDlgItemText (hDlg, IDC_CHIPRAM, memsize_names[msi_chip[mem_size]]);
2000 
2001     mem_size = 0;
2002     switch (workprefs.fastmem_size) {
2003      case 0x00000000: mem_size = 0; break;
2004      case 0x00100000: mem_size = 1; break;
2005      case 0x00200000: mem_size = 2; break;
2006      case 0x00400000: mem_size = 3; break;
2007      case 0x00800000: mem_size = 4; break;
2008      case 0x01000000: mem_size = 5; break;
2009     }
2010     SendDlgItemMessage (hDlg, IDC_FASTMEM, TBM_SETPOS, TRUE, mem_size);
2011     SetDlgItemText (hDlg, IDC_FASTRAM, memsize_names[msi_fast[mem_size]]);
2012 
2013     mem_size = 0;
2014     switch (workprefs.bogomem_size) {
2015      case 0x00000000: mem_size = 0; break;
2016      case 0x00080000: mem_size = 1; break;
2017      case 0x00100000: mem_size = 2; break;
2018     }
2019     SendDlgItemMessage (hDlg, IDC_SLOWMEM, TBM_SETPOS, TRUE, mem_size);
2020     SetDlgItemText (hDlg, IDC_SLOWRAM, memsize_names[msi_bogo[mem_size]]);
2021 
2022     mem_size = 0;
2023     switch (workprefs.z3fastmem_size) {
2024      case 0x00000000: mem_size = 0; break; /*   0-megs */
2025      case 0x00100000: mem_size = 1; break; /*   1-megs */
2026      case 0x00200000: mem_size = 2; break; /*   2-megs */
2027      case 0x00400000: mem_size = 3; break; /*   4-megs */
2028      case 0x00800000: mem_size = 4; break; /*   8-megs */
2029      case 0x01000000: mem_size = 5; break; /*  16-megs */
2030      case 0x02000000: mem_size = 6; break; /*  32-megs */
2031      case 0x04000000: mem_size = 7; break; /*  64-megs */
2032      case 0x08000000: mem_size = 8; break; /* 128-megs */
2033 	 case 0x10000000: mem_size = 9; break; /* 256-megs */
2034 	 case 0x20000000: mem_size = 10; break; /* 512-megs */
2035      case 0x40000000: mem_size = 11; break; /* 1 GB-megs */
2036 
2037     }
2038     SendDlgItemMessage (hDlg, IDC_Z3FASTMEM, TBM_SETPOS, TRUE, mem_size);
2039     SetDlgItemText (hDlg, IDC_Z3FASTRAM, memsize_names[msi_z3fast[mem_size]]);
2040 
2041     mem_size = 0;
2042     switch (workprefs.gfxmem_size) {
2043      case 0x00000000: mem_size = 0; break;
2044      case 0x00100000: mem_size = 1; break;
2045      case 0x00200000: mem_size = 2; break;
2046      case 0x00400000: mem_size = 3; break;
2047      case 0x00800000: mem_size = 4; break;
2048 	 case 0x01000000: mem_size = 5; break;
2049 	 case 0x02000000: mem_size = 6; break;
2050     }
2051     SendDlgItemMessage (hDlg, IDC_P96MEM, TBM_SETPOS, TRUE, mem_size);
2052     SetDlgItemText (hDlg, IDC_P96RAM, memsize_names[msi_gfx[mem_size]]);
2053 }
2054 
fix_values_memorydlg(void)2055 static void fix_values_memorydlg (void)
2056 {
2057     if (workprefs.chipmem_size > 0x200000)
2058 	workprefs.fastmem_size = 0;
2059 }
2060 
MemoryDlgProc(HWND hDlg,UINT msg,WPARAM wParam,LPARAM lParam)2061 static BOOL CALLBACK MemoryDlgProc (HWND hDlg, UINT msg, WPARAM wParam, LPARAM lParam)
2062 {
2063     static int recursive = 0;
2064     unsigned int max_z3_mem = MAX_Z3_MEM;
2065     MEMORYSTATUS memstats;
2066 
2067     switch (msg)
2068     {
2069     case WM_INITDIALOG:
2070 	pages[MEMORY_ID] = hDlg;
2071 
2072 	memstats.dwLength = sizeof( memstats );
2073 	GlobalMemoryStatus( &memstats );
2074 	while( ( memstats.dwAvailPageFile + memstats.dwAvailPhys - 32000000) < (DWORD)( 1 << (max_z3_mem + 19) ) )
2075 	    max_z3_mem--;
2076 
2077 	SendDlgItemMessage (hDlg, IDC_CHIPMEM, TBM_SETRANGE, TRUE, MAKELONG (MIN_CHIP_MEM, MAX_CHIP_MEM));
2078 	SendDlgItemMessage (hDlg, IDC_FASTMEM, TBM_SETRANGE, TRUE, MAKELONG (MIN_FAST_MEM, MAX_FAST_MEM));
2079 	SendDlgItemMessage (hDlg, IDC_SLOWMEM, TBM_SETRANGE, TRUE, MAKELONG (MIN_SLOW_MEM, MAX_SLOW_MEM));
2080 	SendDlgItemMessage (hDlg, IDC_Z3FASTMEM, TBM_SETRANGE, TRUE, MAKELONG (MIN_Z3_MEM, max_z3_mem));
2081 	SendDlgItemMessage (hDlg, IDC_P96MEM, TBM_SETRANGE, TRUE, MAKELONG (MIN_P96_MEM, MAX_P96_MEM));
2082 
2083     case WM_USER:
2084 	recursive++;
2085 	fix_values_memorydlg ();
2086 	values_to_memorydlg (hDlg);
2087 	enable_for_memorydlg (hDlg);
2088 	recursive--;
2089 	break;
2090 
2091     case WM_HSCROLL:
2092 	workprefs.chipmem_size = memsizes[msi_chip[SendMessage (GetDlgItem (hDlg, IDC_CHIPMEM), TBM_GETPOS, 0, 0)]];
2093 	workprefs.bogomem_size = memsizes[msi_bogo[SendMessage (GetDlgItem (hDlg, IDC_SLOWMEM), TBM_GETPOS, 0, 0)]];
2094 	workprefs.fastmem_size = memsizes[msi_fast[SendMessage (GetDlgItem (hDlg, IDC_FASTMEM), TBM_GETPOS, 0, 0)]];
2095 	workprefs.z3fastmem_size = memsizes[msi_z3fast[SendMessage (GetDlgItem (hDlg, IDC_Z3FASTMEM), TBM_GETPOS, 0, 0)]];
2096 	workprefs.gfxmem_size = memsizes[msi_gfx[SendMessage (GetDlgItem (hDlg, IDC_P96MEM), TBM_GETPOS, 0, 0)]];
2097 	fix_values_memorydlg();
2098 	values_to_memorydlg(hDlg);
2099 	enable_for_memorydlg(hDlg);
2100 	break;
2101 
2102     case WM_COMMAND:
2103 	if (recursive > 0)
2104 	    break;
2105 	recursive++;
2106 	values_to_memorydlg (hDlg);
2107 	recursive--;
2108 	break;
2109 
2110     case WM_NOTIFY:
2111 	switch (((NMHDR *) lParam)->code)
2112 	{
2113 	case PSN_HELP:
2114 	    HtmlHelp( NULL, help_file, HH_DISPLAY_TOPIC, "ram.htm" );
2115 	    break;
2116 
2117 	case PSN_APPLY:
2118 	    /* Copy stuff from workprefs and config_xxx settings */
2119 	    gui_to_prefs ();
2120 	    break;
2121 
2122 	case PSN_RESET:
2123 	    if (allow_quit)
2124 	    {
2125 		quit_program = 1;
2126 		regs.spcflags |= SPCFLAG_BRK;
2127 	    }
2128 	    break;
2129 	}
2130     }
2131     return FALSE;
2132 }
2133 
values_to_kickstartdlg(HWND hDlg)2134 static void values_to_kickstartdlg (HWND hDlg)
2135 {
2136     SetDlgItemText( hDlg, IDC_ROMFILE, workprefs.romfile );
2137     SetDlgItemText( hDlg, IDC_KEYFILE, workprefs.keyfile );
2138     // Disable Expansion ROM settings for now (CD32 related)
2139     ShowWindow( GetDlgItem( hDlg, IDC_ROMFILE2TEXT ), SW_HIDE );
2140     ShowWindow( GetDlgItem( hDlg, IDC_ROMFILE2 ), SW_HIDE );
2141     ShowWindow( GetDlgItem( hDlg, IDC_ROMCHOOSER2 ), SW_HIDE );
2142 }
2143 
KickstartDlgProc(HWND hDlg,UINT msg,WPARAM wParam,LPARAM lParam)2144 static BOOL CALLBACK KickstartDlgProc (HWND hDlg, UINT msg, WPARAM wParam, LPARAM lParam)
2145 {
2146     switch( msg )
2147     {
2148     case WM_INITDIALOG:
2149 	pages[KICKSTART_ID] = hDlg;
2150 
2151     case WM_USER:
2152 	values_to_kickstartdlg (hDlg);
2153 	return TRUE;
2154 
2155     case WM_COMMAND:
2156 	switch( wParam )
2157 	{
2158 	case IDC_KICKCHOOSER:
2159 	    DiskSelection( hDlg, IDC_ROMFILE, 6, &workprefs );
2160 	    break;
2161 
2162 	case IDC_KEYCHOOSER:
2163 	    DiskSelection( hDlg, IDC_KEYFILE, 7, &workprefs );
2164 	    break;
2165 
2166 	default:
2167 	    if( SendMessage( GetDlgItem( hDlg, IDC_ROMFILE ), EM_GETMODIFY, 0, 0 ) )
2168 	    {
2169 		GetDlgItemText( hDlg, IDC_ROMFILE, workprefs.romfile, CFG_ROM_LENGTH);
2170 		SendMessage( GetDlgItem( hDlg, IDC_ROMFILE ), EM_SETMODIFY, 0, 0 );
2171 	    }
2172 	    if( SendMessage( GetDlgItem( hDlg, IDC_KEYFILE ), EM_GETMODIFY, 0, 0 ) )
2173 	    {
2174 		GetDlgItemText( hDlg, IDC_KEYFILE, workprefs.keyfile, CFG_KEY_LENGTH);
2175 		SendMessage( GetDlgItem( hDlg, IDC_ROMFILE ), EM_SETMODIFY, 0, 0 );
2176 	    }
2177 	    break;
2178 	}
2179 	break;
2180 
2181     case WM_NOTIFY:
2182 	switch( ((NMHDR *) lParam)->code )
2183 	{
2184 	case PSN_HELP:
2185 	    HtmlHelp( NULL, help_file, HH_DISPLAY_TOPIC, "rom.htm" );
2186 	    break;
2187 
2188 	case PSN_APPLY:
2189 	    /* Copy stuff from workprefs and config_xxx settings */
2190 	    gui_to_prefs ();
2191 	    break;
2192 
2193 	case PSN_RESET:
2194 	    if (allow_quit)
2195 	    {
2196 		quit_program = 1;
2197 		regs.spcflags |= SPCFLAG_BRK;
2198 	    }
2199 	    break;
2200 	}
2201 	break;
2202     }
2203     return FALSE;
2204 }
2205 
enable_for_miscdlg(HWND hDlg)2206 static void enable_for_miscdlg (HWND hDlg)
2207 {
2208     if( !full_property_sheet )
2209     {
2210 	EnableWindow( GetDlgItem( hDlg, IDC_JULIAN), FALSE);
2211 	EnableWindow( GetDlgItem( hDlg, IDC_SOCKETS), FALSE);
2212 	EnableWindow( GetDlgItem( hDlg, IDC_SHOWGUI ), FALSE );
2213 	EnableWindow( GetDlgItem( hDlg, IDC_AUTOCONFIG ), FALSE );
2214 	EnableWindow( GetDlgItem( hDlg, IDC_CREATELOGFILE ), FALSE );
2215 	EnableWindow( GetDlgItem( hDlg, IDC_ILLEGAL ), FALSE );
2216 	EnableWindow( GetDlgItem( hDlg, IDC_NOSPEED ), FALSE );
2217 	EnableWindow( GetDlgItem( hDlg, IDC_NOSOUND ), FALSE );
2218 	EnableWindow( GetDlgItem( hDlg, IDC_NOOVERLAY ), FALSE );
2219 	ShowWindow( GetDlgItem( hDlg, IDC_RESETAMIGA ), SW_SHOW );
2220 	ShowWindow( GetDlgItem( hDlg, IDC_QUITEMU ), SW_SHOW );
2221     }
2222     // Turn off cd.device and c2p h/w (Akiko) check-boxes for now
2223     ShowWindow( GetDlgItem( hDlg, IDC_AKIKOC2P ), SW_HIDE );
2224     ShowWindow( GetDlgItem( hDlg, IDC_CDDEVICE ), SW_HIDE );
2225 }
2226 
values_to_miscdlg(HWND hDlg)2227 static void values_to_miscdlg (HWND hDlg)
2228 {
2229     CheckDlgButton( hDlg, IDC_SOCKETS, workprefs.socket_emu );
2230     CheckDlgButton( hDlg, IDC_ILLEGAL, workprefs.illegal_mem);
2231 }
2232 
MiscDlgProc(HWND hDlg,UINT msg,WPARAM wParam,LPARAM lParam)2233 static BOOL CALLBACK MiscDlgProc (HWND hDlg, UINT msg, WPARAM wParam, LPARAM lParam)
2234 {
2235     switch (msg)
2236     {
2237     case WM_INITDIALOG:
2238 	pages[MISC_ID] = hDlg;
2239 
2240     case WM_USER:
2241 	values_to_miscdlg (hDlg);
2242 	enable_for_miscdlg (hDlg);
2243 	return TRUE;
2244 
2245     case WM_COMMAND:
2246 	switch( wParam )
2247 	{
2248 	case IDC_DOSAVESTATE:
2249 	    DiskSelection( hDlg, wParam, 9, &workprefs );
2250 	    if( strlen( savestate_filename ) )
2251 	    {
2252 		savestate_state = STATE_DOSAVE;
2253 	    }
2254 	    break;
2255 	case IDC_DOLOADSTATE:
2256 	    DiskSelection( hDlg, wParam, 10, &workprefs );
2257 	    if( strlen( savestate_filename ) )
2258 	    {
2259 		savestate_state = STATE_DORESTORE;
2260 	    }
2261 	    break;
2262 	case IDC_RESETAMIGA:
2263 	    uae_reset();
2264 	    break;
2265 	case IDC_QUITEMU:
2266 	    uae_quit();
2267 	    PropSheet_PressButton( hPropertySheet, PSBTN_CANCEL );
2268 	    break;
2269 	case IDC_SOCKETS:
2270 	    workprefs.socket_emu   = IsDlgButtonChecked( hDlg, IDC_SOCKETS );
2271 	    break;
2272 	case IDC_ILLEGAL:
2273 	    workprefs.illegal_mem = IsDlgButtonChecked (hDlg, IDC_ILLEGAL);
2274 	    break;
2275 	}
2276 	break;
2277 
2278     case WM_NOTIFY:
2279 	switch (((NMHDR *) lParam)->code)
2280 	{
2281 	case PSN_HELP:
2282 	    HtmlHelp( NULL, help_file, HH_DISPLAY_TOPIC, "misc.htm" );
2283 	    break;
2284 
2285 	case PSN_APPLY:
2286 	    /* Copy stuff from workprefs and config_xxx settings */
2287 	    gui_to_prefs ();
2288 	    break;
2289 
2290 	case PSN_RESET:
2291 	    if (allow_quit)
2292 	    {
2293 		quit_program = 1;
2294 		regs.spcflags |= SPCFLAG_BRK;
2295 	    }
2296 	    break;
2297 	}
2298 	break;
2299     }
2300     return FALSE;
2301 }
2302 
2303 static int cpu_ids[]   = { IDC_CPU0, IDC_CPU0, IDC_CPU1, IDC_CPU1, IDC_CPU2, IDC_CPU4, IDC_CPU3, IDC_CPU5, IDC_CPU6, IDC_CPU6 };
2304 static int trust_ids[] = { IDC_TRUST0, IDC_TRUST1, IDC_TRUST1, IDC_TRUST2 };
2305 
enable_for_cpudlg(HWND hDlg)2306 static void enable_for_cpudlg (HWND hDlg)
2307 {
2308     /* The "compatible" checkbox is only available when CPU type is 68000 */
2309     EnableWindow (GetDlgItem (hDlg, IDC_COMPATIBLE), workprefs.cpu_level == 0);
2310 
2311     /* These four items only get enabled when adjustable CPU style is enabled */
2312     EnableWindow (GetDlgItem (hDlg, IDC_SPEED), workprefs.m68k_speed > 0);
2313     EnableWindow (GetDlgItem (hDlg, IDC_CS_CPU_TEXT), workprefs.m68k_speed > 0);
2314     EnableWindow (GetDlgItem (hDlg, IDC_CS_CHIPSET_TEXT), workprefs.m68k_speed > 0);
2315     EnableWindow (GetDlgItem (hDlg, IDC_CPUTEXT), workprefs.m68k_speed > 0 );
2316 
2317 }
2318 
values_to_cpudlg(HWND hDlg)2319 static void values_to_cpudlg (HWND hDlg)
2320 {
2321     SendDlgItemMessage (hDlg, IDC_SPEED, TBM_SETPOS, TRUE, workprefs.m68k_speed <= 0 ? 1 : workprefs.m68k_speed / CYCLE_UNIT );
2322     SetDlgItemInt( hDlg, IDC_CPUTEXT, workprefs.m68k_speed <= 0 ? 1 : workprefs.m68k_speed / CYCLE_UNIT, FALSE );
2323     CheckDlgButton (hDlg, IDC_COMPATIBLE, workprefs.cpu_compatible);
2324     CheckRadioButton (hDlg, IDC_CPU0, IDC_CPU6, cpu_ids[workprefs.cpu_level * 2 + !workprefs.address_space_24]);
2325 
2326     if (workprefs.m68k_speed == -1)
2327 	CheckRadioButton( hDlg, IDC_CS_HOST, IDC_CS_ADJUSTABLE, IDC_CS_HOST );
2328     else if (workprefs.m68k_speed == 0)
2329 	CheckRadioButton( hDlg, IDC_CS_HOST, IDC_CS_ADJUSTABLE, IDC_CS_68000 );
2330     else
2331 	CheckRadioButton( hDlg, IDC_CS_HOST, IDC_CS_ADJUSTABLE, IDC_CS_ADJUSTABLE );
2332 }
2333 
values_from_cpudlg(HWND hDlg)2334 static void values_from_cpudlg (HWND hDlg)
2335 {
2336     int newcpu;
2337     int newtrust;
2338 
2339     workprefs.cpu_compatible = IsDlgButtonChecked (hDlg, IDC_COMPATIBLE);
2340     workprefs.m68k_speed = IsDlgButtonChecked (hDlg, IDC_CS_HOST) ? -1
2341 	: IsDlgButtonChecked (hDlg, IDC_CS_68000) ? 0
2342 	: SendMessage (GetDlgItem (hDlg, IDC_SPEED), TBM_GETPOS, 0, 0) * CYCLE_UNIT;
2343 
2344     newcpu = (IsDlgButtonChecked (hDlg, IDC_CPU0) ? 0
2345 	: IsDlgButtonChecked (hDlg, IDC_CPU1) ? 1
2346 	: IsDlgButtonChecked (hDlg, IDC_CPU2) ? 2
2347 	: IsDlgButtonChecked (hDlg, IDC_CPU3) ? 3
2348 	: IsDlgButtonChecked (hDlg, IDC_CPU4) ? 4
2349 	: IsDlgButtonChecked (hDlg, IDC_CPU5) ? 5 : 6);
2350     /* When switching away from 68000, disable 24 bit addressing.  */
2351     switch( newcpu )
2352     {
2353 	case 0: // 68000
2354 	case 1: // 68010
2355 	case 2: // 68EC020
2356 	case 3: // 68EC020+FPU
2357 	    workprefs.address_space_24 = 1;
2358 	    workprefs.cpu_level = newcpu;
2359 	break;
2360 
2361 	case 4: // 68020
2362 	case 5: // 68020+FPU
2363 	case 6: // 68040
2364 	    workprefs.address_space_24 = 0;
2365 	    workprefs.cpu_level = newcpu - 2;
2366 	break;
2367     }
2368     if (newcpu > 0)
2369 	workprefs.cpu_compatible = 0;
2370 
2371     if( pages[ KICKSTART_ID ] )
2372 	SendMessage( pages[ KICKSTART_ID ], WM_USER, 0, 0 );
2373     if( pages[ DISPLAY_ID ] )
2374 	SendMessage( pages[ DISPLAY_ID ], WM_USER, 0, 0 );
2375     if( pages[ MEMORY_ID ] )
2376 	SendMessage( pages[ MEMORY_ID ], WM_USER, 0, 0 );
2377 }
2378 
CPUDlgProc(HWND hDlg,UINT msg,WPARAM wParam,LPARAM lParam)2379 static BOOL CALLBACK CPUDlgProc (HWND hDlg, UINT msg, WPARAM wParam, LPARAM lParam)
2380 {
2381     static int recursive = 0;
2382 
2383     switch (msg) {
2384     case WM_INITDIALOG:
2385 	pages[CPU_ID] = hDlg;
2386 	SendDlgItemMessage (hDlg, IDC_SPEED, TBM_SETRANGE, TRUE, MAKELONG (MIN_M68K_PRIORITY, MAX_M68K_PRIORITY));
2387 	SendDlgItemMessage (hDlg, IDC_SPEED, TBM_SETPAGESIZE, 0, 1);
2388 
2389     case WM_USER:
2390 	recursive++;
2391 	values_to_cpudlg (hDlg);
2392 	enable_for_cpudlg (hDlg);
2393 	recursive--;
2394 	return TRUE;
2395 
2396     case WM_COMMAND:
2397 	if (recursive > 0)
2398 	    break;
2399 	recursive++;
2400 	values_from_cpudlg (hDlg);
2401 	values_to_cpudlg (hDlg);
2402 	enable_for_cpudlg (hDlg);
2403 	recursive--;
2404 	break;
2405 
2406     case WM_HSCROLL:
2407 	recursive++;
2408 	values_from_cpudlg( hDlg );
2409 	values_to_cpudlg( hDlg );
2410 	enable_for_cpudlg( hDlg );
2411 	recursive--;
2412 	break;
2413 
2414     case WM_NOTIFY:
2415 	switch (((NMHDR *) lParam)->code) {
2416 	case PSN_HELP:
2417 	    HtmlHelp( NULL, help_file, HH_DISPLAY_TOPIC, "cpu.htm" );
2418 	    break;
2419 	case PSN_APPLY:
2420 	    /* Copy stuff from workprefs and config_xxx settings */
2421 	    gui_to_prefs ();
2422 	    break;
2423 
2424 	case PSN_RESET:
2425 	    if (allow_quit) {
2426 		quit_program = 1;
2427 		regs.spcflags |= SPCFLAG_BRK;
2428 	    }
2429 	    break;
2430 	}
2431     }
2432     return FALSE;
2433 }
2434 
2435 static BOOL sound_frequency_supported[ 4 ] = { 0, 0, 0, 0 };
2436 
fill_sound_frequency_supported(void)2437 static void fill_sound_frequency_supported( void )
2438 {
2439     WAVEFORMATEX wavfmt;
2440     HWAVEOUT hWaveOut = NULL;
2441     int i = 0;
2442     MMRESULT result;
2443 
2444     wavfmt.cbSize = 0;
2445     wavfmt.wFormatTag = WAVE_FORMAT_PCM;
2446     wavfmt.nChannels = 2;
2447     wavfmt.nSamplesPerSec = 11025;
2448     wavfmt.wBitsPerSample = 16;
2449     wavfmt.nBlockAlign = 4;
2450     wavfmt.nAvgBytesPerSec = wavfmt.nBlockAlign * wavfmt.nSamplesPerSec;
2451 
2452     for( i = 0; i < 4; i++ )
2453     {
2454 	if( i == 3 )
2455 	    wavfmt.nSamplesPerSec = 48000;
2456 	else
2457 	    wavfmt.nSamplesPerSec = 11025 * (i+1);
2458 	wavfmt.nAvgBytesPerSec = wavfmt.nBlockAlign * wavfmt.nSamplesPerSec;
2459 	result = waveOutOpen( &hWaveOut, WAVE_MAPPER, &wavfmt, 0, 0, WAVE_FORMAT_QUERY );
2460 	if( result == MMSYSERR_NOERROR )
2461 	{
2462 	    sound_frequency_supported[i] = 1;
2463 	}
2464 	else
2465 	{
2466 	    write_log ( "WAVEOUT: Unsupported format of %d Hz\n", wavfmt.nSamplesPerSec );
2467 	}
2468     }
2469 }
2470 
enable_for_sounddlg(HWND hDlg)2471 static void enable_for_sounddlg (HWND hDlg)
2472 {
2473     EnableWindow( GetDlgItem( hDlg, IDC_FREQUENCY ), workprefs.produce_sound );
2474     EnableWindow( GetDlgItem( hDlg, IDC_11KHZ ), workprefs.produce_sound && sound_frequency_supported[0] );
2475     EnableWindow( GetDlgItem( hDlg, IDC_22KHZ ), workprefs.produce_sound && sound_frequency_supported[1] );
2476     EnableWindow( GetDlgItem( hDlg, IDC_44KHZ ), workprefs.produce_sound && sound_frequency_supported[2] );
2477     EnableWindow( GetDlgItem( hDlg, IDC_48KHZ ), workprefs.produce_sound && sound_frequency_supported[3] );
2478 
2479     EnableWindow( GetDlgItem( hDlg, IDC_SOUNDSIZE ), workprefs.produce_sound );
2480     EnableWindow( GetDlgItem( hDlg, IDC_8BIT ), workprefs.produce_sound );
2481     EnableWindow( GetDlgItem( hDlg, IDC_16BIT ), workprefs.produce_sound );
2482 
2483     EnableWindow( GetDlgItem( hDlg, IDC_STEREOMODE ), workprefs.produce_sound );
2484     EnableWindow( GetDlgItem( hDlg, IDC_STEREOMODE0 ), workprefs.produce_sound );
2485     EnableWindow( GetDlgItem( hDlg, IDC_STEREOMODE1 ), workprefs.produce_sound );
2486     EnableWindow( GetDlgItem( hDlg, IDC_STEREOMODE2 ), workprefs.produce_sound );
2487 
2488     EnableWindow( GetDlgItem( hDlg, IDC_SOUNDINTERPOLATION ), workprefs.produce_sound );
2489     EnableWindow( GetDlgItem( hDlg, IDC_INTERPOLATION0 ), workprefs.produce_sound );
2490     EnableWindow( GetDlgItem( hDlg, IDC_INTERPOLATION1 ), workprefs.produce_sound );
2491 
2492     EnableWindow( GetDlgItem( hDlg, IDC_SOUNDBUFFERMEM ), workprefs.produce_sound );
2493     EnableWindow( GetDlgItem( hDlg, IDC_SOUNDBUFFERRAM ), workprefs.produce_sound );
2494     EnableWindow( GetDlgItem( hDlg, IDC_SOUNDBUFFERTEXT ), workprefs.produce_sound );
2495 
2496     EnableWindow( GetDlgItem( hDlg, IDC_AUDIOSYNC ), workprefs.produce_sound );
2497 }
2498 
exact_log2(int v)2499 static int exact_log2 (int v)
2500 {
2501     int l = 0;
2502     while ((v >>= 1) != 0)
2503 	l++;
2504     return l;
2505 }
2506 
values_to_sounddlg(HWND hDlg)2507 static void values_to_sounddlg (HWND hDlg)
2508 {
2509     int which_button;
2510 
2511     if( (workprefs.sound_freq <= 11025) && sound_frequency_supported[0] )
2512 	which_button = IDC_11KHZ;
2513     else if( (workprefs.sound_freq <= 22050) && sound_frequency_supported[1] )
2514 	which_button = IDC_22KHZ;
2515     else if( (workprefs.sound_freq <= 44100) && sound_frequency_supported[2] )
2516 	which_button = IDC_44KHZ;
2517     else if( sound_frequency_supported[3] )
2518 	which_button = IDC_48KHZ;
2519     else
2520 	which_button = IDC_22KHZ; /* default */
2521     CheckRadioButton (hDlg, IDC_11KHZ, IDC_48KHZ, which_button);
2522 
2523     CheckRadioButton (hDlg, IDC_8BIT, IDC_16BIT, workprefs.sound_bits == 16 ? IDC_16BIT : IDC_8BIT);
2524 
2525     switch (workprefs.produce_sound) {
2526      case 0: which_button = IDC_SOUND0; break;
2527      case 1: which_button = IDC_SOUND1; break;
2528      case 2: which_button = IDC_SOUND2; break;
2529      case 3: which_button = IDC_SOUND3; break;
2530     }
2531 
2532     CheckRadioButton( hDlg, IDC_SOUND0, IDC_SOUND3, which_button );
2533 
2534     switch (workprefs.stereo)
2535     {
2536     case 0:
2537 	// mono
2538 	which_button = IDC_STEREOMODE0;
2539 	break;
2540     case 1:
2541     default:
2542 	// stereo, but which type?
2543 	if( workprefs.mixed_stereo )
2544 	    which_button = IDC_STEREOMODE2;
2545 	else
2546 	    which_button = IDC_STEREOMODE1;
2547 	break;
2548     }
2549     CheckRadioButton( hDlg, IDC_STEREOMODE0, IDC_STEREOMODE2, which_button );
2550 
2551     CheckRadioButton( hDlg, IDC_INTERPOLATION0, IDC_INTERPOLATION1, IDC_INTERPOLATION0 + workprefs.sound_interpol );
2552     SendDlgItemMessage( hDlg, IDC_SOUNDBUFFERRAM, TBM_SETPOS, TRUE, exact_log2 (currprefs.sound_maxbsiz / 256));
2553     SetDlgItemInt( hDlg, IDC_SOUNDBUFFERMEM, workprefs.sound_maxbsiz, FALSE );
2554 }
2555 
values_from_sounddlg(HWND hDlg)2556 static void values_from_sounddlg (HWND hDlg)
2557 {
2558     workprefs.sound_bits = IsDlgButtonChecked (hDlg, IDC_8BIT) ? 8 : 16;
2559     workprefs.sound_freq = (IsDlgButtonChecked (hDlg, IDC_11KHZ) ? 11025
2560 			    : IsDlgButtonChecked (hDlg, IDC_22KHZ) ? 22050
2561 			    : IsDlgButtonChecked (hDlg, IDC_44KHZ) ? 44100 : 48000);
2562     workprefs.produce_sound = (IsDlgButtonChecked (hDlg, IDC_SOUND0) ? 0
2563 			       : IsDlgButtonChecked (hDlg, IDC_SOUND1) ? 1
2564 			       : IsDlgButtonChecked (hDlg, IDC_SOUND2) ? 2 : 3);
2565     workprefs.mixed_stereo = 0;
2566     workprefs.stereo = IsDlgButtonChecked (hDlg, IDC_STEREOMODE0) ? 0 :
2567 		       IsDlgButtonChecked( hDlg, IDC_STEREOMODE1 ) ? 1 : (workprefs.mixed_stereo = 1);
2568 
2569     workprefs.sound_interpol = IsDlgButtonChecked( hDlg, IDC_INTERPOLATION0 ) ? 0 : 1;
2570     workprefs.sound_maxbsiz = GetDlgItemInt( hDlg, IDC_SOUNDBUFFERMEM, NULL, FALSE );
2571 }
2572 
SoundDlgProc(HWND hDlg,UINT msg,WPARAM wParam,LPARAM lParam)2573 static BOOL CALLBACK SoundDlgProc (HWND hDlg, UINT msg, WPARAM wParam, LPARAM lParam)
2574 {
2575     static int recursive = 0;
2576 
2577     switch (msg) {
2578     case WM_INITDIALOG:
2579 	fill_sound_frequency_supported();
2580 	SendDlgItemMessage (hDlg, IDC_SOUNDBUFFERRAM, TBM_SETRANGE, TRUE, MAKELONG (MIN_SOUND_MEM, MAX_SOUND_MEM));
2581 	SendDlgItemMessage (hDlg, IDC_SOUNDBUFFERRAM, TBM_SETPAGESIZE, 0, 1);
2582 
2583 	pages[SOUND_ID] = hDlg;
2584 
2585     case WM_USER:
2586 	recursive++;
2587 	values_to_sounddlg (hDlg);
2588 	enable_for_sounddlg (hDlg);
2589 	recursive--;
2590 	return TRUE;
2591 
2592     case WM_COMMAND:
2593 	if (recursive > 0)
2594 	    break;
2595 	recursive++;
2596 	values_from_sounddlg (hDlg);
2597 	enable_for_sounddlg (hDlg);
2598 	recursive--;
2599 	break;
2600 
2601      case WM_HSCROLL:
2602 	workprefs.sound_maxbsiz = 512 << SendMessage( GetDlgItem( hDlg, IDC_SOUNDBUFFERRAM ), TBM_GETPOS, 0, 0 );
2603 	SetDlgItemInt( hDlg, IDC_SOUNDBUFFERMEM, workprefs.sound_maxbsiz, FALSE );
2604 	break;
2605 
2606     case WM_NOTIFY:
2607 	switch (((NMHDR *) lParam)->code) {
2608 	case PSN_HELP:
2609 	    HtmlHelp( NULL, help_file, HH_DISPLAY_TOPIC, "sound.htm" );
2610 	    break;
2611 	case PSN_APPLY:
2612 	    /* Copy stuff from workprefs and config_xxx settings */
2613 	    gui_to_prefs ();
2614 	    break;
2615 	case PSN_RESET:
2616 	    if (allow_quit) {
2617 		quit_program = 1;
2618 		regs.spcflags |= SPCFLAG_BRK;
2619 	    }
2620 	    break;
2621 	}
2622 	break;
2623     }
2624     return FALSE;
2625 }
2626 
2627 struct fsvdlg_vals
2628 {
2629     char volume[4096];
2630     char rootdir[4096];
2631     int rw;
2632 };
2633 
2634 static struct fsvdlg_vals empty_fsvdlg = { "", "", 1 };
2635 static struct fsvdlg_vals current_fsvdlg;
2636 
2637 struct hfdlg_vals
2638 {
2639     char volumename[4096];
2640     char filename[4096];
2641     int sectors;
2642     int reserved;
2643     int surfaces;
2644     int cylinders;
2645     int blocksize;
2646     int rw;
2647 };
2648 
2649 static struct hfdlg_vals empty_hfdlg = { "", "", 32, 2, 1, 0, 512, 1 };
2650 static struct hfdlg_vals current_hfdlg;
2651 
VolumeSettingsProc(HWND hDlg,UINT msg,WPARAM wParam,LPARAM lParam)2652 static int CALLBACK VolumeSettingsProc (HWND hDlg, UINT msg, WPARAM wParam, LPARAM lParam)
2653 {
2654     static int recursive = 0;
2655     BROWSEINFO browse_info;
2656     char directory_path[MAX_PATH] = "";
2657     LPITEMIDLIST browse;
2658     char szTitle[ MAX_PATH ];
2659 
2660     WIN32GUI_LoadUIString( IDS_SELECTFILESYSROOT, szTitle, MAX_PATH );
2661 
2662     browse_info.hwndOwner = hDlg;
2663     browse_info.pidlRoot = NULL;
2664     browse_info.pszDisplayName = directory_path;
2665     browse_info.lpszTitle = "";
2666     browse_info.ulFlags = BIF_DONTGOBELOWDOMAIN | BIF_RETURNONLYFSDIRS;
2667     browse_info.lpfn = NULL;
2668     browse_info.iImage = 0;
2669 
2670     switch (msg) {
2671      case WM_INITDIALOG:
2672 	recursive++;
2673 	SetDlgItemText (hDlg, IDC_VOLUME_NAME, current_fsvdlg.volume);
2674 	SetDlgItemText (hDlg, IDC_PATH_NAME, current_fsvdlg.rootdir);
2675 	CheckDlgButton (hDlg, IDC_RW, current_fsvdlg.rw);
2676 	recursive--;
2677 	return TRUE;
2678 
2679      case WM_COMMAND:
2680 	if (recursive)
2681 	    break;
2682 	recursive++;
2683 	if (HIWORD (wParam) == BN_CLICKED) {
2684 	    switch (LOWORD (wParam)) {
2685 	     case IDC_SELECTOR:
2686 		if ((browse = SHBrowseForFolder (&browse_info)) != NULL) {
2687 		    SHGetPathFromIDList (browse, directory_path);
2688 		    SetDlgItemText (hDlg, IDC_PATH_NAME, directory_path);
2689 		}
2690 		break;
2691 	     case IDOK:
2692 		if( strlen( current_fsvdlg.rootdir ) == 0 )
2693 		{
2694 		    char szMessage[ MAX_PATH ];
2695 		    char szTitle[ MAX_PATH ];
2696 		    WIN32GUI_LoadUIString( IDS_MUSTSELECTPATH, szMessage, MAX_PATH );
2697 		    WIN32GUI_LoadUIString( IDS_SETTINGSERROR, szTitle, MAX_PATH );
2698 
2699 		    MessageBox( hDlg, szMessage, szTitle,
2700 				MB_OK | MB_ICONERROR | MB_APPLMODAL | MB_SETFOREGROUND);
2701 		    break;
2702 		}
2703 		if( strlen( current_fsvdlg.volume ) == 0 )
2704 		{
2705 		    char szMessage[ MAX_PATH ];
2706 		    char szTitle[ MAX_PATH ];
2707 		    WIN32GUI_LoadUIString( IDS_MUSTSELECTNAME, szMessage, MAX_PATH );
2708 		    WIN32GUI_LoadUIString( IDS_SETTINGSERROR, szTitle, MAX_PATH );
2709 
2710 		    MessageBox( hDlg, szMessage, szTitle,
2711 				MB_OK | MB_ICONERROR | MB_APPLMODAL | MB_SETFOREGROUND);
2712 		    break;
2713 		}
2714 		EndDialog (hDlg, 1);
2715 
2716 		break;
2717 	     case IDCANCEL:
2718 		EndDialog (hDlg, 0);
2719 		break;
2720 	    }
2721 	}
2722 	GetDlgItemText (hDlg, IDC_PATH_NAME, current_fsvdlg.rootdir, sizeof current_fsvdlg.rootdir);
2723 	GetDlgItemText (hDlg, IDC_VOLUME_NAME, current_fsvdlg.volume, sizeof current_fsvdlg.volume);
2724 	current_fsvdlg.rw = IsDlgButtonChecked (hDlg, IDC_RW);
2725 	recursive--;
2726 	break;
2727     }
2728     return FALSE;
2729 }
2730 
HardfileSettingsProc(HWND hDlg,UINT msg,WPARAM wParam,LPARAM lParam)2731 static int CALLBACK HardfileSettingsProc (HWND hDlg, UINT msg, WPARAM wParam, LPARAM lParam)
2732 {
2733     static int recursive = 0;
2734     UINT setting;
2735 
2736     switch (msg) {
2737     case WM_INITDIALOG:
2738 	recursive++;
2739 	SetDlgItemText (hDlg, IDC_PATH_NAME, current_hfdlg.filename);
2740 	SetDlgItemInt( hDlg, IDC_SECTORS, current_hfdlg.sectors, FALSE);
2741 	SetDlgItemInt( hDlg, IDC_HEADS, current_hfdlg.surfaces, FALSE);
2742 	SetDlgItemInt( hDlg, IDC_RESERVED, current_hfdlg.reserved, FALSE);
2743 	SetDlgItemInt( hDlg, IDC_BLOCKSIZE, current_hfdlg.blocksize, FALSE);
2744 	CheckDlgButton (hDlg, IDC_RW, current_hfdlg.rw);
2745 	recursive--;
2746 	return TRUE;
2747 
2748     case WM_COMMAND:
2749 	if (recursive)
2750 	    break;
2751 	recursive++;
2752 
2753 	if (HIWORD (wParam) == BN_CLICKED) {
2754 	    switch (LOWORD (wParam)) {
2755 	    case IDC_CREATEHF:
2756 		setting = CalculateHardfileSize (hDlg);
2757 		if( !CreateHardFile(hDlg, setting) )
2758 		{
2759 		    char szMessage[ MAX_PATH ];
2760 		    char szTitle[ MAX_PATH ];
2761 		    WIN32GUI_LoadUIString( IDS_FAILEDHARDFILECREATION, szMessage, MAX_PATH );
2762 		    WIN32GUI_LoadUIString( IDS_CREATIONERROR, szTitle, MAX_PATH );
2763 
2764 		    MessageBox( hDlg, szMessage, szTitle,
2765 				MB_OK | MB_ICONERROR | MB_APPLMODAL | MB_SETFOREGROUND);
2766 		}
2767 		break;
2768 	    case IDC_SELECTOR:
2769 		DiskSelection (hDlg, IDC_PATH_NAME, 2, &workprefs );
2770 		break;
2771 	    case IDOK:
2772 		if( strlen( current_hfdlg.filename ) == 0 )
2773 		{
2774 		    char szMessage[ MAX_PATH ];
2775 		    char szTitle[ MAX_PATH ];
2776 		    WIN32GUI_LoadUIString( IDS_MUSTSELECTFILE, szMessage, MAX_PATH );
2777 		    WIN32GUI_LoadUIString( IDS_SETTINGSERROR, szTitle, MAX_PATH );
2778 
2779 		    MessageBox( hDlg, szMessage, szTitle,
2780 				MB_OK | MB_ICONERROR | MB_APPLMODAL | MB_SETFOREGROUND);
2781 		    break;
2782 		}
2783 		EndDialog (hDlg, 1);
2784 		break;
2785 	    case IDCANCEL:
2786 		EndDialog (hDlg, 0);
2787 		break;
2788 	    }
2789 	}
2790 
2791 	GetDlgItemText (hDlg, IDC_PATH_NAME, current_hfdlg.filename, sizeof current_hfdlg.filename);
2792 	current_hfdlg.sectors   = GetDlgItemInt( hDlg, IDC_SECTORS, FALSE, FALSE );
2793 	current_hfdlg.reserved  = GetDlgItemInt( hDlg, IDC_RESERVED, FALSE, FALSE );
2794 	current_hfdlg.surfaces  = GetDlgItemInt( hDlg, IDC_HEADS, FALSE, FALSE );
2795 	current_hfdlg.blocksize = GetDlgItemInt( hDlg, IDC_BLOCKSIZE, FALSE, FALSE );
2796 	current_hfdlg.rw = IsDlgButtonChecked (hDlg, IDC_RW);
2797 	recursive--;
2798 
2799 	break;
2800     }
2801     return FALSE;
2802 }
2803 
new_filesys(HWND hDlg)2804 static void new_filesys (HWND hDlg)
2805 {
2806     const char *result;
2807 
2808     result = add_filesys_unit (workprefs.mountinfo, current_fsvdlg.volume,
2809 			       current_fsvdlg.rootdir, ! current_fsvdlg.rw, 0, 0, 0, 0);
2810     if (result)
2811 	MessageBox (hDlg, result, "Bad directory",
2812 		    MB_OK | MB_ICONERROR | MB_APPLMODAL | MB_SETFOREGROUND);
2813 }
2814 
new_hardfile(HWND hDlg)2815 static void new_hardfile (HWND hDlg)
2816 {
2817     const char *result;
2818 
2819     result = add_filesys_unit (workprefs.mountinfo, 0, current_hfdlg.filename,
2820 			       ! current_hfdlg.rw, current_hfdlg.sectors, current_hfdlg.surfaces,
2821 			       current_hfdlg.reserved, current_hfdlg.blocksize);
2822     if (result)
2823 	MessageBox (hDlg, result, "Bad hardfile",
2824 		    MB_OK | MB_ICONERROR | MB_APPLMODAL | MB_SETFOREGROUND);
2825 }
2826 
harddisk_remove(HWND hDlg)2827 static void harddisk_remove (HWND hDlg)
2828 {
2829     int entry = listview_find_selected (GetDlgItem (hDlg, IDC_VOLUMELIST));
2830     if (entry < 0)
2831 	return;
2832     kill_filesys_unit (workprefs.mountinfo, entry);
2833 }
2834 
harddisk_move(HWND hDlg,int up)2835 static void harddisk_move (HWND hDlg, int up)
2836 {
2837     int entry = listview_find_selected (GetDlgItem (hDlg, IDC_VOLUMELIST));
2838     if (entry < 0)
2839 	return;
2840     move_filesys_unit (workprefs.mountinfo, entry, up ? entry - 1 : entry + 1);
2841 }
2842 
harddisk_edit(HWND hDlg)2843 static void harddisk_edit (HWND hDlg)
2844 {
2845     int entry = listview_find_selected (GetDlgItem (hDlg, IDC_VOLUMELIST));
2846     char *volname, *rootdir;
2847     int secspertrack, surfaces, cylinders, reserved, size, blocksize, readonly;
2848     const char *failure;
2849 
2850     if (entry < 0)
2851 	return;
2852 
2853     failure = get_filesys_unit (workprefs.mountinfo, entry, &volname, &rootdir, &readonly,
2854 			    &secspertrack, &surfaces, &reserved, &cylinders, &size,
2855 			    &blocksize);
2856 
2857     if( is_hardfile( workprefs.mountinfo, entry ) )
2858     {
2859 	current_hfdlg.sectors = secspertrack;
2860 	current_hfdlg.surfaces = surfaces;
2861 	current_hfdlg.reserved = reserved;
2862 	current_hfdlg.cylinders = cylinders;
2863 	current_hfdlg.blocksize = blocksize;
2864 
2865 	strncpy (current_hfdlg.filename, rootdir, (sizeof current_hfdlg.filename) - 1);
2866 	current_hfdlg.filename[(sizeof current_hfdlg.filename) - 1] = '\0';
2867 	current_hfdlg.rw = !readonly;
2868 	if (DialogBox( hUIDLL ? hUIDLL : hInst, MAKEINTRESOURCE (IDD_HARDFILE), hDlg, HardfileSettingsProc))
2869 	{
2870 	    const char *result;
2871 	    result = set_filesys_unit (workprefs.mountinfo, entry, 0, current_hfdlg.filename,
2872 				       ! current_hfdlg.rw, current_hfdlg.sectors, current_hfdlg.surfaces,
2873 				       current_hfdlg.reserved, current_hfdlg.blocksize);
2874 	    if (result)
2875 		MessageBox (hDlg, result, "Bad hardfile",
2876 		MB_OK | MB_ICONERROR | MB_APPLMODAL | MB_SETFOREGROUND);
2877 	}
2878     }
2879     else /* Filesystem */
2880     {
2881 	strncpy (current_fsvdlg.rootdir, rootdir, (sizeof current_fsvdlg.rootdir) - 1);
2882 	current_fsvdlg.rootdir[(sizeof current_fsvdlg.rootdir) - 1] = '\0';
2883 	strncpy (current_fsvdlg.volume, volname, (sizeof current_fsvdlg.volume) - 1);
2884 	current_fsvdlg.volume[(sizeof current_fsvdlg.volume) - 1] = '\0';
2885 	current_fsvdlg.rw = !readonly;
2886 	if (DialogBox( hUIDLL ? hUIDLL : hInst, MAKEINTRESOURCE (IDD_FILESYS), hDlg, VolumeSettingsProc)) {
2887 	    const char *result;
2888 	    result = set_filesys_unit (workprefs.mountinfo, entry, current_fsvdlg.volume,
2889 				       current_fsvdlg.rootdir, ! current_fsvdlg.rw, 0, 0, 0, 0);
2890 	    if (result)
2891 		MessageBox (hDlg, result, "Bad hardfile",
2892 		MB_OK | MB_ICONERROR | MB_APPLMODAL | MB_SETFOREGROUND);
2893 	}
2894     }
2895 }
2896 
2897 static HWND cachedlist = NULL;
2898 
harddiskdlg_button(HWND hDlg,int button)2899 static void harddiskdlg_button (HWND hDlg, int button)
2900 {
2901     switch (button) {
2902      case IDC_NEW_FS:
2903 	current_fsvdlg = empty_fsvdlg;
2904 	if (DialogBox( hUIDLL ? hUIDLL : hInst, MAKEINTRESOURCE (IDD_FILESYS), hDlg, VolumeSettingsProc))
2905 	    new_filesys (hDlg);
2906 	break;
2907 
2908      case IDC_NEW_HF:
2909 	current_hfdlg = empty_hfdlg;
2910 	if (DialogBox( hUIDLL ? hUIDLL : hInst, MAKEINTRESOURCE (IDD_HARDFILE), hDlg, HardfileSettingsProc))
2911 	    new_hardfile (hDlg);
2912 	break;
2913 
2914      case IDC_EDIT:
2915 	harddisk_edit (hDlg);
2916 	break;
2917 
2918      case IDC_REMOVE:
2919 	harddisk_remove (hDlg);
2920 	break;
2921 
2922      case IDC_UP:
2923 	harddisk_move (hDlg, 1);
2924 	clicked_entry--;
2925 	break;
2926 
2927      case IDC_DOWN:
2928 	harddisk_move (hDlg, 0);
2929 	clicked_entry++;
2930 	break;
2931 
2932     case IDC_MAPDRIVES:
2933 	break;
2934     }
2935 }
2936 
harddiskdlg_volume_notify(HWND hDlg,NM_LISTVIEW * nmlistview)2937 static void harddiskdlg_volume_notify (HWND hDlg, NM_LISTVIEW *nmlistview)
2938 {
2939     HWND list = nmlistview->hdr.hwndFrom;
2940     int dblclick = 0;
2941     int entry = 0;
2942 
2943     switch (nmlistview->hdr.code) {
2944      case NM_DBLCLK:
2945 	dblclick = 1;
2946 	/* fall through */
2947      case NM_CLICK:
2948 	entry = listview_entry_from_click (list);
2949 	if (entry >= 0)
2950 	{
2951 	    if(dblclick)
2952 		harddisk_edit (hDlg);
2953 	    InitializeListView( hDlg );
2954 	    clicked_entry = entry;
2955 	    cachedlist = list;
2956 	    // Hilite the current selected item
2957 	    ListView_SetItemState( cachedlist, clicked_entry, LVIS_SELECTED, LVIS_SELECTED );
2958 	}
2959 	break;
2960     }
2961 }
2962 
HarddiskDlgProc(HWND hDlg,UINT msg,WPARAM wParam,LPARAM lParam)2963 static BOOL CALLBACK HarddiskDlgProc (HWND hDlg, UINT msg, WPARAM wParam, LPARAM lParam)
2964 {
2965     static HICON hMoveUp = NULL, hMoveDown = NULL;
2966 
2967     switch (msg) {
2968     case WM_INITDIALOG:
2969 	clicked_entry = 0;
2970 	pages[HARDDISK_ID] = hDlg;
2971 	if( !hMoveUp )
2972 	    hMoveUp = (HICON)LoadImage( hInst, MAKEINTRESOURCE( IDI_MOVE_UP ), IMAGE_ICON, 16, 16, LR_LOADMAP3DCOLORS );
2973 	if( !hMoveDown )
2974 	    hMoveDown = (HICON)LoadImage( hInst, MAKEINTRESOURCE( IDI_MOVE_DOWN ), IMAGE_ICON, 16, 16, LR_LOADMAP3DCOLORS );
2975 	SendMessage( GetDlgItem( hDlg, IDC_UP ), BM_SETIMAGE, (WPARAM)IMAGE_ICON, (LPARAM)hMoveUp );
2976 	SendMessage( GetDlgItem( hDlg, IDC_DOWN ), BM_SETIMAGE, (WPARAM)IMAGE_ICON, (LPARAM)hMoveDown );
2977 
2978     case WM_USER:
2979 	InitializeListView( hDlg );
2980 	break;
2981 
2982     case WM_COMMAND:
2983 	if (HIWORD (wParam) == BN_CLICKED)
2984 	{
2985 	    harddiskdlg_button (hDlg, LOWORD (wParam));
2986 	    InitializeListView( hDlg );
2987 
2988 	    if( clicked_entry < 0 )
2989 		clicked_entry = 0;
2990 	    if( clicked_entry >= ListView_GetItemCount( cachedlist ) )
2991 		clicked_entry = ListView_GetItemCount( cachedlist ) - 1;
2992 
2993 	    if( cachedlist && clicked_entry >= 0 )
2994 	    {
2995 		// Hilite the current selected item
2996 		ListView_SetItemState( cachedlist, clicked_entry, LVIS_SELECTED | LVIS_FOCUSED, LVIS_SELECTED | LVIS_FOCUSED );
2997 	    }
2998 	}
2999 	break;
3000 
3001     case WM_NOTIFY:
3002 	if (((LPNMHDR) lParam)->idFrom == IDC_VOLUMELIST)
3003 	    harddiskdlg_volume_notify (hDlg, (NM_LISTVIEW *) lParam);
3004 	else {
3005 	    switch (((NMHDR *) lParam)->code) {
3006 	    case PSN_HELP:
3007 		HtmlHelp( NULL, help_file, HH_DISPLAY_TOPIC, "hard-drives.htm" );
3008 		break;
3009 	    case PSN_APPLY:
3010 		/* Copy stuff from workprefs and config_xxx settings */
3011 		gui_to_prefs ();
3012 		break;
3013 	    case PSN_RESET:
3014 		if (allow_quit) {
3015 		    quit_program = 1;
3016 		    regs.spcflags |= SPCFLAG_BRK;
3017 		}
3018 		break;
3019 	    }
3020 	}
3021 	return TRUE;
3022     default:
3023 	return FALSE;
3024     }
3025 
3026     return FALSE;
3027 }
3028 
EnableFloppyButtons(HWND hDlg,int floppies)3029 static void EnableFloppyButtons( HWND hDlg, int floppies )
3030 {
3031     switch( floppies )
3032     {
3033 	case 1:
3034 	    EnableWindow( GetDlgItem( hDlg, IDC_DISABLE1 ), TRUE );
3035 	    EnableWindow( GetDlgItem( hDlg, IDC_DF1TEXT ), FALSE );
3036 	    EnableWindow( GetDlgItem( hDlg, IDC_DF1 ), FALSE );
3037 	    EnableWindow( GetDlgItem( hDlg, IDC_EJECT1 ), FALSE );
3038 
3039 	    EnableWindow( GetDlgItem( hDlg, IDC_DISABLE2 ), FALSE );
3040 	    EnableWindow( GetDlgItem( hDlg, IDC_DF2TEXT ), FALSE );
3041 	    EnableWindow( GetDlgItem( hDlg, IDC_DF2 ), FALSE );
3042 	    EnableWindow( GetDlgItem( hDlg, IDC_EJECT2 ), FALSE );
3043 
3044 	    EnableWindow( GetDlgItem( hDlg, IDC_DISABLE3 ), FALSE );
3045 	    EnableWindow( GetDlgItem( hDlg, IDC_DF3TEXT ), FALSE );
3046 	    EnableWindow( GetDlgItem( hDlg, IDC_DF3 ), FALSE );
3047 	    EnableWindow( GetDlgItem( hDlg, IDC_EJECT3 ), FALSE );
3048 
3049 	    CheckDlgButton( hDlg, IDC_DISABLE1, BST_CHECKED );
3050 	    CheckDlgButton( hDlg, IDC_DISABLE2, BST_CHECKED );
3051 	    CheckDlgButton( hDlg, IDC_DISABLE3, BST_CHECKED );
3052 	break;
3053 	case 2:
3054 	    EnableWindow( GetDlgItem( hDlg, IDC_DISABLE1 ), TRUE );
3055 	    EnableWindow( GetDlgItem( hDlg, IDC_DF1TEXT ), TRUE );
3056 	    EnableWindow( GetDlgItem( hDlg, IDC_DF1 ), TRUE );
3057 	    EnableWindow( GetDlgItem( hDlg, IDC_EJECT1 ), TRUE );
3058 
3059 	    EnableWindow( GetDlgItem( hDlg, IDC_DISABLE2 ), TRUE );
3060 	    EnableWindow( GetDlgItem( hDlg, IDC_DF2TEXT ), FALSE );
3061 	    EnableWindow( GetDlgItem( hDlg, IDC_DF2 ), FALSE );
3062 	    EnableWindow( GetDlgItem( hDlg, IDC_EJECT2 ), FALSE );
3063 
3064 	    EnableWindow( GetDlgItem( hDlg, IDC_DISABLE3 ), FALSE );
3065 	    EnableWindow( GetDlgItem( hDlg, IDC_DF3TEXT ), FALSE );
3066 	    EnableWindow( GetDlgItem( hDlg, IDC_DF3 ), FALSE );
3067 	    EnableWindow( GetDlgItem( hDlg, IDC_EJECT3 ), FALSE );
3068 
3069 	    CheckDlgButton( hDlg, IDC_DISABLE2, BST_CHECKED );
3070 	    CheckDlgButton( hDlg, IDC_DISABLE3, BST_CHECKED );
3071 	break;
3072 	case 3:
3073 	    EnableWindow( GetDlgItem( hDlg, IDC_DISABLE2 ), TRUE );
3074 	    EnableWindow( GetDlgItem( hDlg, IDC_DF2TEXT ), TRUE );
3075 	    EnableWindow( GetDlgItem( hDlg, IDC_DF2 ), TRUE );
3076 	    EnableWindow( GetDlgItem( hDlg, IDC_EJECT2 ), TRUE );
3077 
3078 	    EnableWindow( GetDlgItem( hDlg, IDC_DISABLE3 ), TRUE );
3079 	    EnableWindow( GetDlgItem( hDlg, IDC_DF3TEXT ), FALSE );
3080 	    EnableWindow( GetDlgItem( hDlg, IDC_DF3 ), FALSE );
3081 	    EnableWindow( GetDlgItem( hDlg, IDC_EJECT3 ), FALSE );
3082 
3083 	    CheckDlgButton( hDlg, IDC_DISABLE3, BST_CHECKED );
3084 	break;
3085 	case 4:
3086 	    EnableWindow( GetDlgItem( hDlg, IDC_DISABLE3 ), TRUE );
3087 	    EnableWindow( GetDlgItem( hDlg, IDC_DF3TEXT ), TRUE );
3088 	    EnableWindow( GetDlgItem( hDlg, IDC_DF3 ), TRUE );
3089 	    EnableWindow( GetDlgItem( hDlg, IDC_EJECT3 ), TRUE );
3090 	break;
3091     }
3092 }
3093 
FloppyDlgProc(HWND hDlg,UINT msg,WPARAM wParam,LPARAM lParam)3094 static BOOL CALLBACK FloppyDlgProc (HWND hDlg, UINT msg, WPARAM wParam, LPARAM lParam)
3095 {
3096     static int recursive = 0;
3097 
3098     switch (msg)
3099     {
3100     case WM_INITDIALOG:
3101 	pages[FLOPPY_ID] = hDlg;
3102 	EnableFloppyButtons( hDlg, workprefs.nr_floppies );
3103 
3104     case WM_USER:
3105 	recursive++;
3106 	SetDlgItemText (hDlg, IDC_DF0TEXT, workprefs.df[0]);
3107 	SetDlgItemText (hDlg, IDC_DF1TEXT, workprefs.df[1]);
3108 	SetDlgItemText (hDlg, IDC_DF2TEXT, workprefs.df[2]);
3109 	SetDlgItemText (hDlg, IDC_DF3TEXT, workprefs.df[3]);
3110 	recursive--;
3111 	break;
3112 
3113     case WM_COMMAND:
3114 	if (recursive > 0)
3115 	    break;
3116 	recursive++;
3117 	switch (wParam)
3118 	{
3119 	case IDC_DISABLE1:
3120 	    if( IsDlgButtonChecked( hDlg, IDC_DISABLE1 ) == BST_CHECKED )
3121 	    {
3122 		EnableFloppyButtons( hDlg, 1 );
3123 		workprefs.nr_floppies = 1;
3124 	    }
3125 	    else
3126 	    {
3127 		EnableFloppyButtons( hDlg, 2 );
3128 		workprefs.nr_floppies = 2;
3129 	    }
3130 	    break;
3131 	case IDC_DISABLE2:
3132 	    if( IsDlgButtonChecked( hDlg, IDC_DISABLE2 ) == BST_CHECKED )
3133 	    {
3134 		EnableWindow( GetDlgItem( hDlg, IDC_DISABLE3 ), FALSE );
3135 		CheckDlgButton( hDlg, IDC_DISABLE3, BST_CHECKED );
3136 		EnableFloppyButtons( hDlg, 2 );
3137 		workprefs.nr_floppies = 2;
3138 	    }
3139 	    else
3140 	    {
3141 		EnableFloppyButtons( hDlg, 3 );
3142 		workprefs.nr_floppies = 3;
3143 	    }
3144 	    break;
3145 	case IDC_DISABLE3:
3146 	    if( IsDlgButtonChecked( hDlg, IDC_DISABLE3 ) == BST_CHECKED )
3147 	    {
3148 		EnableFloppyButtons( hDlg, 3 );
3149 		workprefs.nr_floppies = 3;
3150 	    }
3151 	    else
3152 	    {
3153 		EnableFloppyButtons( hDlg, 4 );
3154 		workprefs.nr_floppies = 4;
3155 	    }
3156 	    break;
3157 	case IDC_DF0:
3158 	    DiskSelection (hDlg, wParam, 0, &workprefs );
3159 	    break;
3160 	case IDC_DF1:
3161 	    DiskSelection (hDlg, wParam, 0, &workprefs );
3162 	    break;
3163 	case IDC_DF2:
3164 	    DiskSelection (hDlg, wParam, 0, &workprefs );
3165 	    break;
3166 	case IDC_DF3:
3167 	    DiskSelection (hDlg, wParam, 0, &workprefs );
3168 	    break;
3169 	case IDC_EJECT0:
3170 	    disk_eject(0);
3171 	    SetDlgItemText (hDlg, IDC_DF0TEXT, "");
3172 	    workprefs.df[0][0] = 0;
3173 	    break;
3174 	case IDC_EJECT1:
3175 	    disk_eject(1);
3176 	    SetDlgItemText (hDlg, IDC_DF1TEXT, "");
3177 	    workprefs.df[1][0] = 0;
3178 	    break;
3179 	case IDC_EJECT2:
3180 	    disk_eject(2);
3181 	    SetDlgItemText (hDlg, IDC_DF2TEXT, "");
3182 	    workprefs.df[2][0] = 0;
3183 	    break;
3184 	case IDC_EJECT3:
3185 	    disk_eject(3);
3186 	    SetDlgItemText (hDlg, IDC_DF3TEXT, "");
3187 	    workprefs.df[3][0] = 0;
3188 	    break;
3189 	case IDC_CREATE:
3190 	    DiskSelection (hDlg, wParam, 1, &workprefs );
3191 	    break;
3192 	case IDC_CREATE_RAW:
3193 	    DiskSelection( hDlg, wParam, 1, &workprefs );
3194 	    break;
3195 	}
3196 	if( SendMessage( GetDlgItem( hDlg, IDC_DF0TEXT ), EM_GETMODIFY, 0, 0 ) )
3197 	{
3198 	    GetDlgItemText (hDlg, IDC_DF0TEXT, workprefs.df[0], 255);
3199 	    SendMessage( GetDlgItem( hDlg, IDC_DF0TEXT ), EM_SETMODIFY, 0, 0 );
3200 	}
3201 
3202 	if( SendMessage( GetDlgItem( hDlg, IDC_DF1TEXT ), EM_GETMODIFY, 0, 0 ) )
3203 	{
3204 	    GetDlgItemText (hDlg, IDC_DF1TEXT, workprefs.df[1], 255);
3205 	    SendMessage( GetDlgItem( hDlg, IDC_DF1TEXT ), EM_SETMODIFY, 0, 0 );
3206 	}
3207 
3208 	if( SendMessage( GetDlgItem( hDlg, IDC_DF2TEXT ), EM_GETMODIFY, 0, 0 ) )
3209 	{
3210 	    GetDlgItemText (hDlg, IDC_DF2TEXT, workprefs.df[2], 255);
3211 	    SendMessage( GetDlgItem( hDlg, IDC_DF2TEXT ), EM_SETMODIFY, 0, 0 );
3212 	}
3213 
3214 	if( SendMessage( GetDlgItem( hDlg, IDC_DF3TEXT ), EM_GETMODIFY, 0, 0 ) )
3215 	{
3216 	    GetDlgItemText (hDlg, IDC_DF3TEXT, workprefs.df[3], 255);
3217 	    SendMessage( GetDlgItem( hDlg, IDC_DF3TEXT ), EM_SETMODIFY, 0, 0 );
3218 	}
3219 	recursive--;
3220 	break;
3221 
3222     case WM_NOTIFY:
3223 	switch (((NMHDR *) lParam)->code)
3224 	{
3225 	case PSN_HELP:
3226 	    HtmlHelp( NULL, help_file, HH_DISPLAY_TOPIC, "floppies.htm" );
3227 	    break;
3228 	case PSN_APPLY:
3229 	    /* Copy stuff from workprefs and config_xxx settings */
3230 	    gui_to_prefs ();
3231 	    break;
3232 	case PSN_RESET:
3233 	    if (allow_quit) {
3234 		quit_program = 1;
3235 		regs.spcflags |= SPCFLAG_BRK;
3236 	    }
3237 	    break;
3238 	}
3239 	return TRUE;
3240     default:
3241 	return FALSE;
3242     }
3243 
3244     return FALSE;
3245 }
3246 
3247 PRINTER_INFO_1 *pInfo = NULL;
3248 DWORD dwEnumeratedPrinters = 0;
3249 
3250 static int joy0idc[] = {
3251     IDC_PORT0_JOY0, IDC_PORT0_JOY1, IDC_PORT0_MOUSE, IDC_PORT0_KBDA, IDC_PORT0_KBDB, IDC_PORT0_KBDC
3252 };
3253 
3254 static int joy1idc[] = {
3255     IDC_PORT1_JOY0, IDC_PORT1_JOY1, IDC_PORT1_MOUSE, IDC_PORT1_KBDA, IDC_PORT1_KBDB, IDC_PORT1_KBDC
3256 };
3257 
3258 static BOOL bNoMidiIn = FALSE;
3259 
enable_for_portsdlg(HWND hDlg)3260 static void enable_for_portsdlg( HWND hDlg )
3261 {
3262     int i;
3263     if (! full_property_sheet)
3264     {
3265 	/* Disable certain controls which are only to be set once at start-up... */
3266 	EnableWindow( GetDlgItem( hDlg, IDC_SERIAL ), FALSE );
3267 	EnableWindow( GetDlgItem( hDlg, IDC_PARALLEL ), FALSE );
3268 	EnableWindow( GetDlgItem( hDlg, IDC_MIDIOUTLIST ), FALSE );
3269 	EnableWindow( GetDlgItem( hDlg, IDC_MIDIINLIST ), FALSE );
3270 	EnableWindow( GetDlgItem( hDlg, IDC_SHARED ), FALSE );
3271     }
3272     for( i = 0; i < 6; i++ )
3273     {
3274 	EnableWindow( GetDlgItem( hDlg, joy0idc[i] ), TRUE );
3275 	EnableWindow( GetDlgItem( hDlg, joy1idc[i] ), TRUE );
3276     }
3277 }
3278 
UpdatePortRadioButtons(HWND hDlg)3279 static void UpdatePortRadioButtons( HWND hDlg )
3280 {
3281     int which_button1, which_button2;
3282 
3283     enable_for_portsdlg( hDlg );
3284 	which_button1 = joy0idc[workprefs.jport0];
3285 	if (CheckRadioButton (hDlg, IDC_PORT0_JOY0, IDC_PORT0_KBDC, which_button1) == 0)
3286 	    which_button1 = 0;
3287     else
3288     {
3289 	EnableWindow( GetDlgItem( hDlg, joy1idc[workprefs.jport0] ), FALSE );
3290     }
3291 	which_button2 = joy1idc[workprefs.jport1];
3292     if( workprefs.jport1 == workprefs.jport0 )
3293     {
3294 	if( which_button2 == IDC_PORT1_KBDC )
3295 	    which_button2 = IDC_PORT1_KBDB;
3296 	else
3297 	    which_button2++;
3298     }
3299 	if (CheckRadioButton (hDlg, IDC_PORT1_JOY0, IDC_PORT1_KBDC, which_button2) == 0)
3300 	    which_button2 = 0;
3301     else
3302     {
3303 	EnableWindow( GetDlgItem( hDlg, joy0idc[ workprefs.jport1 ] ), FALSE );
3304     }
3305 }
3306 
values_from_portsdlg(HWND hDlg)3307 static void values_from_portsdlg (HWND hDlg)
3308 {
3309     int item;
3310     /* 0 - joystick 0
3311      * 1 - joystick 1
3312      * 2 - mouse
3313      * 3 - numpad
3314      * 4 - cursor keys
3315      * 5 - elsewhere
3316      */
3317     if (IsDlgButtonChecked (hDlg, IDC_PORT0_JOY0)) {
3318 	    workprefs.jport0 = 0;
3319     }
3320     if (IsDlgButtonChecked (hDlg, IDC_PORT0_JOY1)) {
3321 	    workprefs.jport0 = 1;
3322     }
3323     if (IsDlgButtonChecked (hDlg, IDC_PORT0_MOUSE))
3324 	    workprefs.jport0 = 2;
3325     if (IsDlgButtonChecked (hDlg, IDC_PORT0_KBDA))
3326 	    workprefs.jport0 = 3;
3327     if (IsDlgButtonChecked (hDlg, IDC_PORT0_KBDB))
3328 	    workprefs.jport0 = 4;
3329     if (IsDlgButtonChecked (hDlg, IDC_PORT0_KBDC))
3330 	    workprefs.jport0 = 5;
3331 
3332     if (IsDlgButtonChecked (hDlg, IDC_PORT1_JOY0)) {
3333 	    workprefs.jport1 = 0;
3334     }
3335     if (IsDlgButtonChecked (hDlg, IDC_PORT1_JOY1)) {
3336 	    workprefs.jport1 = 1;
3337     }
3338     if (IsDlgButtonChecked (hDlg, IDC_PORT1_MOUSE))
3339 	    workprefs.jport1 = 2;
3340     if (IsDlgButtonChecked (hDlg, IDC_PORT1_KBDA))
3341 	    workprefs.jport1 = 3;
3342     if (IsDlgButtonChecked (hDlg, IDC_PORT1_KBDB))
3343 	    workprefs.jport1 = 4;
3344     if (IsDlgButtonChecked (hDlg, IDC_PORT1_KBDC))
3345 	    workprefs.jport1 = 5;
3346 
3347     item = SendDlgItemMessage( hDlg, IDC_PRINTERLIST, CB_GETCURSEL, 0, 0L );
3348     if( item != CB_ERR )
3349     {
3350 	if( item )
3351 	    strcpy( workprefs.prtname, pInfo[item-1].pName );
3352 	else
3353 	    strcpy( workprefs.prtname, "" );
3354     }
3355 
3356     item = SendDlgItemMessage (hDlg, IDC_SERIAL, CB_GETCURSEL, 0, 0L);
3357     switch( item )
3358     {
3359 	case 1:
3360 	case 2:
3361 	case 3:
3362 	case 4:
3363 	case 5:
3364 	case 6:
3365 	case 7:
3366 	case 8:
3367 	    workprefs.use_serial = 1;
3368 	    sprintf( workprefs.sername, "COM%d", item );
3369 	    EnableWindow( GetDlgItem( hDlg, IDC_MIDIOUTLIST ), TRUE );
3370 	    EnableWindow( GetDlgItem( hDlg, IDC_MIDIINLIST ), TRUE );
3371 	break;
3372 
3373 	default:
3374 	    workprefs.use_serial = 0;
3375 	    strcpy( workprefs.sername, "none" );
3376 	    EnableWindow( GetDlgItem( hDlg, IDC_MIDIOUTLIST ), FALSE );
3377 	    EnableWindow( GetDlgItem( hDlg, IDC_MIDIINLIST ), FALSE );
3378 	break;
3379     }
3380     if( IsDlgButtonChecked( hDlg, IDC_SHARED ) )
3381 	workprefs.serial_demand = 1;
3382     else
3383 	workprefs.serial_demand = 0;
3384 }
3385 
values_to_portsdlg(HWND hDlg)3386 static void values_to_portsdlg (HWND hDlg)
3387 {
3388     LONG item_height, result = 0;
3389     RECT rect;
3390 
3391     if( *workprefs.prtname )
3392     {
3393 	result = SendDlgItemMessage( hDlg, IDC_PRINTERLIST, CB_FINDSTRINGEXACT, -1, (LPARAM)workprefs.prtname );
3394 	if( result < 0 )
3395 	{
3396 	    // Warn the user that their printer-port selection is not valid on this machine
3397 	    char szMessage[ MAX_PATH ];
3398 	    WIN32GUI_LoadUIString( IDS_INVALIDPRTPORT, szMessage, MAX_PATH );
3399 	    gui_message( szMessage );
3400 
3401 	    // Disable the invalid parallel-port selection
3402 	    strcpy( workprefs.prtname, "none" );
3403 
3404 	    result = 0;
3405 	}
3406     }
3407     SendDlgItemMessage( hDlg, IDC_PRINTERLIST, CB_SETCURSEL, result, 0 );
3408 
3409     CheckDlgButton( hDlg, IDC_SHARED, workprefs.serial_demand );
3410 
3411     if( strcasecmp( workprefs.sername, szNone ) == 0 )
3412     {
3413 	SendDlgItemMessage (hDlg, IDC_SERIAL, CB_SETCURSEL, 0, 0L);
3414 	workprefs.use_serial = 0;
3415     }
3416     else
3417     {
3418 	int t = (workprefs.sername[0] == '\0' ? 0 : workprefs.sername[3] - '0');
3419 	result = SendDlgItemMessage( hDlg, IDC_SERIAL, CB_SETCURSEL, t, 0L );
3420 	if( result < 0 )
3421 	{
3422 	    if (t > 0) {
3423 		// Warn the user that their COM-port selection is not valid on this machine
3424 		char szMessage[ MAX_PATH ];
3425 		WIN32GUI_LoadUIString( IDS_INVALIDCOMPORT, szMessage, MAX_PATH );
3426 		gui_message( szMessage );
3427 
3428 		// Select "none" as the COM-port
3429 		SendDlgItemMessage( hDlg, IDC_SERIAL, CB_SETCURSEL, 0L, 0L );
3430 	    }
3431 	    // Disable the chosen serial-port selection
3432 	    strcpy( workprefs.sername, "none" );
3433 	    workprefs.use_serial = 0;
3434 	}
3435 	else
3436 	{
3437 	    workprefs.use_serial = 1;
3438 	}
3439     }
3440 
3441     if( workprefs.use_serial )
3442     {
3443 	EnableWindow( GetDlgItem( hDlg, IDC_MIDIOUTLIST ), TRUE );
3444 	if( !bNoMidiIn )
3445 	    EnableWindow( GetDlgItem( hDlg, IDC_MIDIINLIST ), TRUE );
3446     }
3447     else
3448     {
3449 	EnableWindow( GetDlgItem( hDlg, IDC_MIDIOUTLIST ), FALSE );
3450 	EnableWindow( GetDlgItem( hDlg, IDC_MIDIINLIST ), FALSE );
3451     }
3452     /* Retrieve the height, in pixels, of a list item. */
3453     item_height = SendDlgItemMessage (hDlg, IDC_SERIAL, CB_GETITEMHEIGHT, 0, 0L);
3454     if (item_height != CB_ERR) {
3455 	/* Get actual box position and size. */
3456 	GetWindowRect (GetDlgItem (hDlg, IDC_SERIAL), &rect);
3457 	rect.bottom = (rect.top + item_height * 5
3458 	    + SendDlgItemMessage (hDlg, IDC_SERIAL, CB_GETITEMHEIGHT, (WPARAM) - 1, 0L)
3459 	    + item_height);
3460 	SetWindowPos (GetDlgItem (hDlg, IDC_SERIAL), 0, 0, 0, rect.right - rect.left,
3461 	    rect.bottom - rect.top, SWP_NOMOVE | SWP_NOZORDER);
3462     }
3463 }
3464 
3465 #define MAX_PRINTERS 10
3466 
init_portsdlg(HWND hDlg)3467 static void init_portsdlg( HWND hDlg )
3468 {
3469     int port, numdevs;
3470     char comport[5];
3471     COMMCONFIG cc;
3472     DWORD size = sizeof(COMMCONFIG);
3473 
3474     MIDIOUTCAPS midiOutCaps;
3475     MIDIINCAPS midiInCaps;
3476 
3477     DWORD cbNeeded = 0;
3478 
3479     SendDlgItemMessage (hDlg, IDC_SERIAL, CB_RESETCONTENT, 0, 0L);
3480     SendDlgItemMessage (hDlg, IDC_SERIAL, CB_ADDSTRING, 0, (LPARAM)szNone );
3481     for( port = 0; port < 8; port++ )
3482     {
3483 	sprintf( comport, "COM%d", port );
3484 	if( GetDefaultCommConfig( comport, &cc, &size ) )
3485 	{
3486 	    SendDlgItemMessage( hDlg, IDC_SERIAL, CB_ADDSTRING, 0, (LPARAM)comport );
3487 	}
3488     }
3489 
3490     SendDlgItemMessage (hDlg, IDC_PRINTERLIST, CB_RESETCONTENT, 0, 0L);
3491     SendDlgItemMessage (hDlg, IDC_PRINTERLIST, CB_ADDSTRING, 0, (LPARAM)szNone );
3492     if( !pInfo )
3493     {
3494 	if( !EnumPrinters( PRINTER_ENUM_LOCAL, NULL, 1, (LPBYTE)pInfo, 0, &cbNeeded, &dwEnumeratedPrinters ) )
3495 	{
3496 	    if( cbNeeded )
3497 	    {
3498 		pInfo = calloc( 1, cbNeeded );
3499 		if( EnumPrinters( PRINTER_ENUM_LOCAL, NULL, 1, (LPBYTE)pInfo, cbNeeded, &cbNeeded, &dwEnumeratedPrinters ) )
3500 		{
3501 		    for( port = 0; port < dwEnumeratedPrinters; port++ )
3502 		    {
3503 			SendDlgItemMessage( hDlg, IDC_PRINTERLIST, CB_ADDSTRING, 0, (LPARAM)pInfo[port].pName );
3504 		    }
3505 		}
3506 	    }
3507 	    else
3508 	    {
3509 		EnableWindow( GetDlgItem( hDlg, IDC_PRINTERLIST ), FALSE );
3510 	    }
3511 	}
3512     }
3513 
3514     if( ( numdevs = midiOutGetNumDevs() ) == 0 )
3515     {
3516 	EnableWindow( GetDlgItem( hDlg, IDC_MIDIOUTLIST ), FALSE );
3517     }
3518     else
3519     {
3520 	char szMidiOut[ MAX_PATH ];
3521 	WIN32GUI_LoadUIString( IDS_DEFAULTMIDIOUT, szMidiOut, MAX_PATH );
3522 	SendDlgItemMessage( hDlg, IDC_MIDIOUTLIST, CB_RESETCONTENT, 0, 0L );
3523 	SendDlgItemMessage( hDlg, IDC_MIDIOUTLIST, CB_ADDSTRING, 0, (LPARAM)szMidiOut );
3524 
3525 	for( port = 0; port < numdevs; port++ )
3526 	{
3527 	    if( midiOutGetDevCaps( port, &midiOutCaps, sizeof( midiOutCaps ) ) == MMSYSERR_NOERROR )
3528 	    {
3529 		SendDlgItemMessage( hDlg, IDC_MIDIOUTLIST, CB_ADDSTRING, 0, (LPARAM)midiOutCaps.szPname );
3530 	    }
3531 	}
3532     }
3533 
3534     if( ( numdevs = midiInGetNumDevs() ) == 0 )
3535     {
3536 	EnableWindow( GetDlgItem( hDlg, IDC_MIDIINLIST ), FALSE );
3537 	bNoMidiIn = TRUE;
3538     }
3539     else
3540     {
3541 	SendDlgItemMessage( hDlg, IDC_MIDIINLIST, CB_RESETCONTENT, 0, 0L );
3542 
3543 	for( port = 0; port < numdevs; port++ )
3544 	{
3545 	    if( midiInGetDevCaps( port, &midiInCaps, sizeof( midiInCaps ) ) == MMSYSERR_NOERROR )
3546 	    {
3547 		SendDlgItemMessage( hDlg, IDC_MIDIINLIST, CB_ADDSTRING, 0, (LPARAM)midiInCaps.szPname );
3548 	    }
3549 	}
3550     }
3551 }
3552 
3553 /* Handle messages for the Joystick Settings page of our property-sheet */
PortsDlgProc(HWND hDlg,UINT msg,WPARAM wParam,LPARAM lParam)3554 static BOOL CALLBACK PortsDlgProc (HWND hDlg, UINT msg, WPARAM wParam, LPARAM lParam)
3555 {
3556     static int recursive = 0;
3557     int temp;
3558 
3559     switch (msg)
3560     {
3561     case WM_INITDIALOG:
3562 	pages[PORTS_ID] = hDlg;
3563 	init_portsdlg( hDlg );
3564 
3565     case WM_USER:
3566 	recursive++;
3567 	enable_for_portsdlg( hDlg );
3568 	values_to_portsdlg (hDlg);
3569 	UpdatePortRadioButtons( hDlg );
3570 	recursive--;
3571 	return TRUE;
3572 
3573     case WM_COMMAND:
3574 	if( wParam == IDC_SWAP )
3575 	{
3576 	    temp = workprefs.jport0;
3577 	    workprefs.jport0 = workprefs.jport1;
3578 	    workprefs.jport1 = temp;
3579 	    UpdatePortRadioButtons( hDlg );
3580 	}
3581 	else
3582 	{
3583 	    if (recursive > 0)
3584 		break;
3585 	    recursive++;
3586 	    values_from_portsdlg (hDlg);
3587 	    UpdatePortRadioButtons( hDlg );
3588 	    recursive--;
3589 	}
3590 	break;
3591 
3592     case WM_NOTIFY:
3593 	switch (((NMHDR *) lParam)->code)
3594 	{
3595 	case PSN_HELP:
3596 	    HtmlHelp( NULL, help_file, HH_DISPLAY_TOPIC, "ports.htm" );
3597 	    break;
3598 	case PSN_APPLY:
3599 	    /* Copy stuff from workprefs and config_xxx settings */
3600 	    gui_to_prefs ();
3601 	    break;
3602 	case PSN_RESET:
3603 	    if (allow_quit) {
3604 		quit_program = 1;
3605 		regs.spcflags |= SPCFLAG_BRK;
3606 	    }
3607 	    break;
3608 	}
3609 	return FALSE;
3610     }
3611     return FALSE;
3612 }
3613 
InitPropertySheet(HWND hDlg,UINT msg,LPARAM lParam)3614 static void CALLBACK InitPropertySheet (HWND hDlg, UINT msg, LPARAM lParam)
3615 {
3616     int i;
3617     hPropertySheet = hDlg;
3618 
3619     switch (msg)
3620     {
3621     case PSCB_INITIALIZED:
3622 	if (! full_property_sheet) {
3623 	    /* This shouldn't be necessary.  */
3624 	    PropSheet_RemovePage( hDlg, 0, NULL ); /* Remove LoadSave */
3625 	} else {
3626 	    for (i = 0; i < C_PAGES; i++)
3627 		pages[i] = NULL;
3628 	}
3629 	break;
3630     }
3631 }
3632 
init_page(PROPSHEETPAGE * ppage,int id,int tmpl,int icon,int title,BOOL (CALLBACK FAR * func)(HWND hDlg,UINT msg,WPARAM wParam,LPARAM lParam))3633 static void init_page (PROPSHEETPAGE *ppage, int id, int tmpl, int icon, int title,
3634 	       BOOL (CALLBACK FAR *func) (HWND hDlg, UINT msg, WPARAM wParam, LPARAM lParam))
3635 {
3636     ppage[id].dwSize = sizeof (PROPSHEETPAGE);
3637     ppage[id].dwFlags = PSP_USETITLE | PSP_USEICONID | ((id != ABOUT_ID ) ? PSP_HASHELP : 0);
3638     ppage[id].pszTemplate = MAKEINTRESOURCE (tmpl);
3639     ppage[id].hInstance = hUIDLL ? hUIDLL : hInst;
3640     ppage[id].pszIcon = MAKEINTRESOURCE (icon);
3641 
3642     if( hUIDLL )
3643     {
3644 	LPTSTR lpstrTitle = calloc( 1, MAX_PATH );
3645 	LoadString( hUIDLL, title, lpstrTitle, MAX_PATH );
3646 	ppage[id].pszTitle = lpstrTitle;
3647     }
3648     else
3649     {
3650 	ppage[id].pszTitle = MAKEINTRESOURCE (title);
3651     }
3652     ppage[id].pfnDlgProc = func;
3653     ppage[id].lParam = 0;
3654     ppage[id].pfnCallback = NULL;
3655     ppage[id].pcRefParent = NULL;
3656 }
3657 
GetSettings(int all_options)3658 int GetSettings (int all_options)
3659 {
3660     static int init_called = 0;
3661     int psresult;
3662     static PROPSHEETPAGE ppage[C_PAGES];
3663     PROPSHEETHEADER pHeader;
3664 
3665     full_property_sheet = all_options;
3666     allow_quit = all_options;
3667     pguiprefs = all_options ? &currprefs : &changed_prefs;
3668     default_prefs( &workprefs );
3669 
3670     WIN32GUI_LoadUIString( IDS_NONE, szNone, MAX_PATH );
3671 
3672     prefs_to_gui (&changed_prefs);
3673 
3674     if( !init_called )
3675     {
3676 	init_page (ppage, LOADSAVE_ID, IDD_LOADSAVE, IDI_LOADSAVE, IDS_LOADSAVE, LoadSaveDlgProc);
3677 	init_page (ppage, MEMORY_ID, IDD_MEMORY, IDI_MEMORY, IDS_MEMORY, MemoryDlgProc);
3678 	init_page (ppage, KICKSTART_ID, IDD_KICKSTART, IDI_MEMORY, IDS_KICKSTART, KickstartDlgProc);
3679 	init_page (ppage, CPU_ID, IDD_CPU, IDI_CPU, IDS_CPU, CPUDlgProc);
3680 	init_page (ppage, DISPLAY_ID, IDD_DISPLAY, IDI_DISPLAY, IDS_DISPLAY, DisplayDlgProc);
3681 	init_page (ppage, CHIPSET_ID, IDD_CHIPSET, IDI_DISPLAY, IDS_CHIPSET, ChipsetDlgProc);
3682 	init_page (ppage, SOUND_ID, IDD_SOUND, IDI_SOUND, IDS_SOUND, SoundDlgProc);
3683 	init_page (ppage, FLOPPY_ID, IDD_FLOPPY, IDI_FLOPPY, IDS_FLOPPY, FloppyDlgProc);
3684 	init_page (ppage, HARDDISK_ID, IDD_HARDDISK, IDI_HARDDISK, IDS_HARDDISK, HarddiskDlgProc);
3685 	init_page (ppage, PORTS_ID, IDD_PORTS, IDI_PORTS, IDS_PORTS, PortsDlgProc);
3686 	init_page (ppage, MISC_ID, IDD_MISC, IDI_MISC, IDS_MISC, MiscDlgProc);
3687 	init_page (ppage, ABOUT_ID, IDD_ABOUT, IDI_ABOUT, IDS_ABOUT, AboutDlgProc);
3688 
3689 	init_called = 1;
3690     }
3691 
3692     pHeader.dwSize = sizeof (PROPSHEETHEADER);
3693     pHeader.dwFlags = PSH_PROPSHEETPAGE | PSH_PROPTITLE | PSH_USEICONID | PSH_USECALLBACK | PSH_NOAPPLYNOW | PSH_HASHELP;
3694     if (! all_options && workprefs.gfx_afullscreen && workprefs.gfx_width < 640)
3695 	pHeader.hwndParent = NULL;
3696     else
3697 	pHeader.hwndParent = hAmigaWnd;
3698     pHeader.hInstance = hInst;
3699     pHeader.pszIcon = MAKEINTRESOURCE (IDI_APPICON);
3700     pHeader.pszCaption = "UAE/Win32";
3701     pHeader.nPages = C_PAGES;
3702     pHeader.nStartPage = 0;
3703     pHeader.ppsp = ppage;
3704     pHeader.pfnCallback = (PFNPROPSHEETCALLBACK) InitPropertySheet;
3705 
3706 
3707     psresult = PropertySheet (&pHeader);
3708 
3709     if (quit_program)
3710 	psresult = -2;
3711 
3712     return psresult;
3713 }
3714 
gui_init(void)3715 int gui_init (void)
3716 {
3717     return( GetSettings(1) );
3718 }
3719 
gui_update(void)3720 int gui_update (void)
3721 {
3722     return 1;
3723 }
3724 
gui_exit(void)3725 void gui_exit (void)
3726 {
3727 #if 0
3728     free_prefs( &workprefs, 1 );
3729 #endif
3730     closeprinter(); // Bernd Roesch
3731 }
3732 
3733 extern HWND hStatusWnd;
3734 struct gui_info gui_data;
3735 
check_prefs_changed_gui(void)3736 void check_prefs_changed_gui( void )
3737 {
3738 }
3739 
gui_led(int led,int on)3740 void gui_led (int led, int on)
3741 {
3742     WORD type;
3743     static char drive_text[5*6];
3744     char *ptr;
3745     extern int screen_is_picasso;
3746 
3747     if( hStatusWnd )
3748     {
3749 	if( on )
3750 	    type = SBT_POPOUT;
3751 	else
3752 	    type = 0;
3753 
3754 	ptr = drive_text + led*6;
3755 	if( led > 0 )
3756 	{
3757 	    sprintf( ptr , "%02d", gui_data.drive_track[led-1]);
3758 	}
3759 	else
3760 	{
3761 	    strcpy( ptr, "Power");
3762 	}
3763 	PostMessage (hStatusWnd, SB_SETTEXT, (WPARAM) ((led+2) | type), (LPARAM) ptr);
3764     }
3765 }
3766 
gui_fps(int fps)3767 void gui_fps( int fps )
3768 {
3769     static char fps_text[10];
3770 
3771     if( hStatusWnd )
3772     {
3773 	sprintf( fps_text, "FPS: %2u", fps+1 );
3774 	PostMessage( hStatusWnd, SB_SETTEXT, (WPARAM)( 1 ), (LPARAM)fps_text );
3775     }
3776 }
3777 
gui_filename(int num,const char * name)3778 void gui_filename (int num, const char *name)
3779 {
3780 }
3781 
gui_message(const char * format,...)3782 void gui_message(const char *format,...)
3783 {
3784     char msg[2048];
3785     char szTitle[ MAX_PATH ];
3786     va_list parms;
3787     int flipflop = 0;
3788     int fullscreen = 0;
3789     int reactivate_mouse = 0;
3790     HWND window = NULL;
3791 
3792     if( DirectDraw_GetCooperativeLevel( &window, &fullscreen ) && fullscreen )
3793 	flipflop = 1;
3794 
3795     pause_sound(0);
3796     if( flipflop )
3797 	ShowWindow( window, SW_MINIMIZE );
3798 
3799     va_start (parms, format);
3800     vsprintf( msg, format, parms );
3801     va_end (parms);
3802     write_log ( msg );
3803 
3804     WIN32GUI_LoadUIString( IDS_ERRORTITLE, szTitle, MAX_PATH );
3805     if( mouseactive )
3806     {
3807 	setmouseactive( 0 );
3808 	reactivate_mouse = 1;
3809     }
3810 
3811     MessageBox( NULL, msg, szTitle, MB_OK | MB_ICONWARNING | MB_TASKMODAL | MB_SETFOREGROUND );
3812 
3813     if( reactivate_mouse )
3814 	setmouseactive( 1 );
3815 
3816     if( flipflop )
3817 	ShowWindow( window, SW_RESTORE );
3818 
3819     resume_sound();
3820 }
3821 
gui_lock(void)3822 void gui_lock (void)
3823 {
3824 }
3825 
gui_unlock(void)3826 void gui_unlock (void)
3827 {
3828 }
3829