diff --git a/src/cpu/386.c b/src/cpu/386.c index 771757b..ed20635 100644 --- a/src/cpu/386.c +++ b/src/cpu/386.c @@ -8,7 +8,7 @@ * * Implementation of the CPU. * - * Version: @(#)386.c 1.0.2 2018/03/09 + * Version: @(#)386.c 1.0.3 2018/05/02 * * Authors: Sarah Walker, * Miran Grca, @@ -93,6 +93,7 @@ uint32_t rmdat32; #define fetchdat rmdat32 uint32_t backupregs[16]; extern int oddeven; +int timetolive = 0; int inttype; diff --git a/src/cpu/808x.c b/src/cpu/808x.c index 034dc76..ab9c11e 100644 --- a/src/cpu/808x.c +++ b/src/cpu/808x.c @@ -18,7 +18,7 @@ * 2 clocks - fetch opcode 1 2 clocks - execute * 2 clocks - fetch opcode 2 etc * - * Version: @(#)808x.c 1.0.3 2018/04/26 + * Version: @(#)808x.c 1.0.4 2018/05/02 * * Authors: Sarah Walker, * Miran Grca, @@ -64,112 +64,126 @@ #include "../plat.h" -int xt_cpu_multi; -int nmi = 0; -int nmi_auto_clear = 0; +int xt_cpu_multi; +int nmi = 0; +int nmi_auto_clear = 0; +int nextcyc = 0; +int cycdiff; +int is8086 = 0; +int nopageerrors = 0; +uint16_t oldcs; +int oldcpl; +int tempc; +uint8_t opcode; +uint16_t pc2, + pc3; +int noint = 0; +int output = 0; +int ins = 0; +int fetchcycles = 0, + memcycs, + fetchclocks; +uint8_t prefetchqueue[6]; +uint16_t prefetchpc; +int prefetchw = 0; -int nextcyc=0; -int cycdiff; -int is8086=0; - -int memcycs; -int nopageerrors=0; - -void FETCHCOMPLETE(); - -uint8_t readmembl(uint32_t addr); -void writemembl(uint32_t addr, uint8_t val); -uint16_t readmemwl(uint32_t seg, uint32_t addr); -void writememwl(uint32_t seg, uint32_t addr, uint16_t val); -uint32_t readmemll(uint32_t seg, uint32_t addr); -void writememll(uint32_t seg, uint32_t addr, uint32_t val); #undef readmemb +uint8_t +readmemb(uint32_t a) +{ + if (a != (cs + cpu_state.pc)) memcycs += 4; + + if (readlookup2 == NULL) + return(readmembl(a)); + + if (readlookup2[(a) >> 12] == -1) + return(readmembl(a)); + else + return(*(uint8_t *)(readlookup2[(a) >> 12] + (a))); +} + + +uint8_t +readmembf(uint32_t a) +{ + if (readlookup2 == NULL) + return readmembl(a); + + if (readlookup2[(a)>>12]==-1) + return readmembl(a); + else + return *(uint8_t *)(readlookup2[(a) >> 12] + (a)); +} + + #undef readmemw -uint8_t readmemb(uint32_t a) +uint16_t +readmemw(uint32_t s, uint16_t a) { - if (a!=(cs+cpu_state.pc)) memcycs+=4; - if (readlookup2 == NULL) return readmembl(a); - if (readlookup2[(a)>>12]==-1) return readmembl(a); - else return *(uint8_t *)(readlookup2[(a) >> 12] + (a)); -} + if (a != (cs+cpu_state.pc)) + memcycs += (8 >> is8086); -uint8_t readmembf(uint32_t a) -{ - if (readlookup2 == NULL) return readmembl(a); - if (readlookup2[(a)>>12]==-1) return readmembl(a); - else return *(uint8_t *)(readlookup2[(a) >> 12] + (a)); -} + if (readlookup2 == NULL) + return readmemwl(s, a); -uint16_t readmemw(uint32_t s, uint16_t a) -{ - if (a!=(cs+cpu_state.pc)) memcycs+=(8>>is8086); - if (readlookup2 == NULL) return readmemwl(s,a); - if ((readlookup2[((s)+(a))>>12]==-1 || (s)==0xFFFFFFFF)) return readmemwl(s,a); - else return *(uint16_t *)(readlookup2[(s + a) >> 12] + s + a); -} - -void refreshread() { /*pclog("Refreshread\n"); */FETCHCOMPLETE(); memcycs+=4; } - -#undef fetchea -#define fetchea() { rmdat=FETCH(); \ - cpu_reg=(rmdat>>3)&7; \ - cpu_mod=(rmdat>>6)&3; \ - cpu_rm=rmdat&7; \ - if (cpu_mod!=3) fetcheal(); } - -void writemembl(uint32_t addr, uint8_t val); -void writememb(uint32_t a, uint8_t v) -{ - memcycs+=4; - if (writelookup2 == NULL) writemembl(a,v); - if (writelookup2[(a)>>12]==-1) writemembl(a,v); - else *(uint8_t *)(writelookup2[a >> 12] + a) = v; -} -void writememwl(uint32_t seg, uint32_t addr, uint16_t val); -void writememw(uint32_t s, uint32_t a, uint16_t v) -{ - memcycs+=(8>>is8086); - if (writelookup2 == NULL) writememwl(s,a,v); - if (writelookup2[((s)+(a))>>12]==-1 || (s)==0xFFFFFFFF) writememwl(s,a,v); - else *(uint16_t *)(writelookup2[(s + a) >> 12] + s + a) = v; -} -void writememll(uint32_t seg, uint32_t addr, uint32_t val); -void writememl(uint32_t s, uint32_t a, uint32_t v) -{ - if (writelookup2 == NULL) writememll(s,a,v); - if (writelookup2[((s)+(a))>>12]==-1 || (s)==0xFFFFFFFF) writememll(s,a,v); - else *(uint32_t *)(writelookup2[(s + a) >> 12] + s + a) = v; + if ((readlookup2[((s)+(a))>>12]==-1 || (s)==0xFFFFFFFF)) + return readmemwl(s,a); + else + return *(uint16_t *)(readlookup2[(s + a) >> 12] + s + a); } -void dumpregs(int); -uint16_t oldcs; -int oldcpl; +void +writememb(uint32_t a, uint8_t v) +{ + memcycs += 4; -int tempc; -uint8_t opcode; -uint16_t pc2,pc3; -int noint=0; + if (writelookup2 == NULL) + writemembl(a, v); -int output=0; + if (writelookup2[(a)>>12]==-1) + writemembl(a,v); + else + *(uint8_t *)(writelookup2[a >> 12] + a) = v; +} -#if 0 -/* Also in mem.c */ -int shadowbios=0; -#endif -int ins=0; +void +writememw(uint32_t s, uint32_t a, uint16_t v) +{ + memcycs += (8 >> is8086); -int fetchcycles=0,memcycs,fetchclocks; + if (writelookup2 == NULL) + writememwl(s, a, v); -uint8_t prefetchqueue[6]; -uint16_t prefetchpc; -int prefetchw=0; -static __inline uint8_t FETCH() + if (writelookup2[((s)+(a))>>12]==-1 || (s)==0xFFFFFFFF) + writememwl(s,a,v); + else + *(uint16_t *)(writelookup2[(s + a) >> 12] + s + a) = v; +} + + +void +writememl(uint32_t s, uint32_t a, uint32_t v) +{ + if (writelookup2 == NULL) + writememll(s, a, v); + + if (writelookup2[((s)+(a))>>12]==-1 || (s)==0xFFFFFFFF) + writememll(s, a, v); + else + *(uint32_t *)(writelookup2[(s + a) >> 12] + s + a) = v; +} + + +static __inline uint8_t +FETCH(void) { uint8_t temp; -/* temp=prefetchqueue[0]; + +#if 0 + temp=prefetchqueue[0]; prefetchqueue[0]=prefetchqueue[1]; prefetchqueue[1]=prefetchqueue[2]; prefetchqueue[2]=prefetchqueue[3]; @@ -182,7 +196,8 @@ static __inline uint8_t FETCH() { prefetchqueue[prefetchw++]=readmembf(cs+prefetchpc); prefetchpc++; } - }*/ + } +#endif if (prefetchw==0) { @@ -213,7 +228,9 @@ static __inline uint8_t FETCH() return temp; } -static __inline void FETCHADD(int c) + +static __inline void +FETCHADD(int c) { int d; if (c<0) return; @@ -239,7 +256,19 @@ static __inline void FETCHADD(int c) if (fetchcycles>16) fetchcycles=16; } -void FETCHCOMPLETE() + +static __inline void +FETCHCLEAR(void) +{ + prefetchpc=cpu_state.pc; + prefetchw=0; + memcycs=cycdiff-cycles; + fetchclocks=0; +} + + +void +FETCHCOMPLETE(void) { if (!(fetchcycles&3)) return; if (prefetchw>((is8086)?4:3)) return; @@ -261,21 +290,35 @@ void FETCHCOMPLETE() fetchcycles+=(4-(fetchcycles&3)); } -static __inline void FETCHCLEAR() + +void +refreshread(void) { - prefetchpc=cpu_state.pc; - prefetchw=0; - memcycs=cycdiff-cycles; - fetchclocks=0; +#if 0 + pclog("Refreshread\n"); +#endif + FETCHCOMPLETE(); + + memcycs += 4; } -static uint16_t getword() + +static uint16_t +getword(void) { uint8_t temp=FETCH(); return temp|(FETCH()<<8); } +#undef fetchea +#define fetchea() { rmdat=FETCH(); \ + cpu_reg=(rmdat>>3)&7; \ + cpu_mod=(rmdat>>6)&3; \ + cpu_rm=rmdat&7; \ + if (cpu_mod!=3) fetcheal(); } + + /*EA calculation*/ /*R/M - bits 0-2 - R/M bits 3-5 - Reg bits 6-7 - mod @@ -513,10 +556,6 @@ void makeznptable() if (c&0x8000) znptable16[c]|=N_FLAG; } } -#if 1 -/* Also in mem.c */ -int timetolive=0; -#endif extern uint32_t oldcs2; extern uint32_t oldpc2; @@ -531,7 +570,7 @@ void dumpregs(int force) #endif /* Only dump when needed, and only once.. */ - if (indump || (!force && !dump_on_exit)) return; + if (!ram || indump || (!force && !dump_on_exit)) return; #ifndef RELEASE_BUILD indump = 1; diff --git a/src/pc.c b/src/pc.c index af7af5c..0fa7b82 100644 --- a/src/pc.c +++ b/src/pc.c @@ -8,7 +8,7 @@ * * Main emulator module where most things are controlled. * - * Version: @(#)pc.c 1.0.31 2018/04/30 + * Version: @(#)pc.c 1.0.32 2018/05/01 * * Authors: Fred N. van Kempen, * Miran Grca, @@ -310,6 +310,11 @@ pc_version(const char *platform) #endif strcpy(emu_fullversion, emu_version); +#ifdef _MSC_VER + sprintf(temp, " [VC%d]", _MSC_VER); + strcat(emu_fullversion, temp); +#endif + #ifdef BUILD sprintf(temp, " (Build %d", BUILD); strcat(emu_fullversion, temp); diff --git a/src/plat.h b/src/plat.h index 46b4112..62a75d9 100644 --- a/src/plat.h +++ b/src/plat.h @@ -8,7 +8,7 @@ * * Define the various platform support functions. * - * Version: @(#)plat.h 1.0.10 2018/04/30 + * Version: @(#)plat.h 1.0.11 2018/05/03 * * Author: Fred N. van Kempen, * @@ -127,6 +127,7 @@ extern int plat_setvid(int api); extern void plat_vidsize(int x, int y); extern void plat_setfullscreen(int on); extern void plat_resize(int x, int y); +extern int plat_fdd_icon(int); /* Resource management. */ diff --git a/src/ui/ui_main.c b/src/ui/ui_main.c index 392e3d9..30f4349 100644 --- a/src/ui/ui_main.c +++ b/src/ui/ui_main.c @@ -11,7 +11,7 @@ * This code is called by the UI frontend modules, and, also, * depends on those same modules for lower-level functions. * - * Version: @(#)ui_main.c 1.0.6 2018/04/30 + * Version: @(#)ui_main.c 1.0.7 2018/04/30 * * Author: Fred N. van Kempen, * @@ -243,7 +243,9 @@ ui_menu_toggle_video_item(int idm, int *val) void ui_menu_reset_all(void) { +#ifdef ENABLE_LOG_TOGGLES int i; +#endif #ifndef DEV_BRANCH /* FIXME: until we fix these.. --FvK */ diff --git a/src/ui/ui_stbar.c b/src/ui/ui_stbar.c index 46ea14b..94dba7d 100644 --- a/src/ui/ui_stbar.c +++ b/src/ui/ui_stbar.c @@ -8,7 +8,7 @@ * * Common UI support functions for the Status Bar module. * - * Version: @(#)ui_stbar.c 1.0.2 2018/04/29 + * Version: @(#)ui_stbar.c 1.0.3 2018/05/03 * * Authors: Fred N. van Kempen, * Miran Grca, @@ -712,7 +712,7 @@ ui_sb_update(void) case SB_FLOPPY: /* Floppy */ drive = sb_tags[part] & 0x0f; sb_flags[part] = (wcslen(floppyfns[drive]) == 0) ? 256 : 0; - sb_icons[part] = sb_fdd_icon(fdd_get_type(drive)) | sb_flags[part]; + sb_icons[part] = plat_fdd_icon(fdd_get_type(drive)) | sb_flags[part]; sb_menu_create(part); menu_floppy(part, drive); ui_sb_tip_update(sb_tags[part]); diff --git a/src/version.h b/src/version.h index 4cfc67a..1718d9c 100644 --- a/src/version.h +++ b/src/version.h @@ -8,7 +8,7 @@ * * Define application version and build info. * - * Version: @(#)version.h 1.0.11 2018/04/29 + * Version: @(#)version.h 1.0.12 2018/05/03 * * Author: Fred N. van Kempen, * @@ -55,7 +55,7 @@ #define EMU_VER_MAJOR 0 #define EMU_VER_MINOR 1 #define EMU_VER_REV 5 -#define EMU_VER_PATCH 5 +#define EMU_VER_PATCH 6 /* Standard C preprocessor macros. */ diff --git a/src/win/mingw/Makefile.MinGW b/src/win/mingw/Makefile.MinGW index d6f08f4..125ec52 100644 --- a/src/win/mingw/Makefile.MinGW +++ b/src/win/mingw/Makefile.MinGW @@ -8,7 +8,7 @@ # # Makefile for Windows systems using the MinGW32 environment. # -# Version: @(#)Makefile.mingw 1.0.35 2018/04/28 +# Version: @(#)Makefile.mingw 1.0.37 2018/05/03 # # Author: Fred N. van Kempen, # @@ -364,7 +364,7 @@ ifneq ($(WX), n) else UIOBJ := win_ui.o \ win_ddraw.o win_d3d.o \ - win_dialog.o win_about.o win_status.o win_stbar.o \ + win_dialog.o win_about.o win_status.o \ win_settings.o win_devconf.o win_snd_gain.o \ win_new_floppy.o endif @@ -670,7 +670,7 @@ else endif -all: $(PROG).exe pcap_if.exe +all: $(PREBUILD) $(PROG).exe pcap_if.exe $(POSTBUILD) VARCem.res: VARCem.rc VARCem.mpp diff --git a/src/win/msvc/Makefile.VC b/src/win/msvc/Makefile.VC index 77c9146..3a45bcc 100644 --- a/src/win/msvc/Makefile.VC +++ b/src/win/msvc/Makefile.VC @@ -8,7 +8,7 @@ # # Makefile for Windows using Visual Studio 2015. # -# Version: @(#)Makefile.VC 1.0.22 2018/04/29 +# Version: @(#)Makefile.VC 1.0.24 2018/05/03 # # Author: Fred N. van Kempen, # @@ -229,13 +229,14 @@ else ARCH := x86 endif PREPROC := cl -nologo -EP +MCPP := mcpp.exe LINK := link -nologo WINDRES := rc -nologo -r SYSINC := -Iwin/msvc/Include -Iwin/mingw/include SYSLIB := -DEPS = -MMD -MF $*.d -c $< +DEPS = -MMD -MF $*.d DEPFILE := win\.depends-msvc # Set up the correct toolchain flags. @@ -251,6 +252,8 @@ COPTS := -W3 CXXOPTS := -EHsc DOPTS := LOPTS := -LIBPATH:win\msvc\Lib\$(ARCH) +LOPTS_C := -SUBSYSTEM:CONSOLE,5.01 +LOPTS_W := -SUBSYSTEM:WINDOWS,5.01 ifdef BUILD OPTS += -DBUILD=$(BUILD) endif @@ -271,7 +274,8 @@ ifeq ($(OPTIM), y) DOPTS := -march=native endif ifeq ($(DEBUG), y) - DOPTS += -Gs -Zi -D_DEBUG + OPTS += -D_DEBUG + DOPTS += -MTd -Gs -Zi ROPTS += -D_DEBUG LOPTS += -debug AOPTIM := @@ -279,7 +283,7 @@ ifeq ($(DEBUG), y) COPTIM := -Od endif else - DOPTS := -Gs + DOPTS := -MT -Gs ifndef COPTIM COPTIM := -O2 endif @@ -311,6 +315,9 @@ LIBS := ddraw.lib dinput8.lib dxguid.lib d3d9.lib d3dx9.lib \ comctl32.lib winmm.lib comdlg32.lib advapi32.lib \ gdi32.lib shell32.lib user32.lib kernel32.lib \ wsock32.lib iphlpapi.lib psapi.lib +ifeq ($(DEBUG), y) +LIBS += libcmtd.lib libvcruntimed.lib libucrtd.lib +endif # Optional modules. @@ -332,7 +339,7 @@ ifneq ($(WX), n) else UIOBJ := win_ui.obj \ win_ddraw.obj win_d3d.obj \ - win_dialog.obj win_about.obj win_status.obj win_stbar.obj \ + win_dialog.obj win_about.obj win_status.obj \ win_settings.obj win_devconf.obj win_snd_gain.obj \ win_new_floppy.obj endif @@ -494,7 +501,7 @@ DEVOBJ := bugger.obj \ keyboard.obj \ keyboard_xt.obj keyboard_at.obj \ mouse.obj \ - mouse_serial.obj mouse_ps2.obj mouse_bus.obj + mouse_serial.obj mouse_ps2.obj mouse_bus.obj \ joystick.obj \ js_standard.obj js_ch_fs_pro.obj \ js_sw_pad.obj js_tm_fcs.obj @@ -608,32 +615,28 @@ endif # Build module rules. ifeq ($(AUTODEP), y) %.obj: %.c -# @echo $< - @$(CC) $(CFLAGS) $(DEPS) -Fo$@ -c $< + @$(CC) $(CFLAGS) -Fo$@ -c $< + @$(MCPP) $(OPTS) $(DEPS) $< %.obj: %.cpp -# @echo $< - @$(CPP) $(CXXFLAGS) $(DEPS) -Fo$@ -c $< + @$(CPP) $(CXXFLAGS) -Fo$@ -c $< + @$(MCPP) $(OPTS) $(DEPS) $< else %.obj: %.c -# @echo $< @$(CC) $(CFLAGS) -Fo$@ -c $< %.obj: %.cpp -# @echo $< @$(CPP) $(CXXFLAGS) -Fo$@ -c $< %.d: %.c $(wildcard $*.d) -# @echo $< - @$(CC) $(CFLAGS) $(DEPS) -E $< >NUL + $(MCPP) $(OPTS) $(DEPS) $< >NUL %.d: %.cpp $(wildcard $*.d) -# @echo $< - @$(CPP) $(CXXFLAGS) $(DEPS) -E $< >NUL + $(MCPP) $(OPTS) $(DEPS) $< >NUL endif -all: $(PROG).exe pcap_if.exe +all: $(PREBUILD) $(PROG).exe pcap_if.exe $(POSTBUILD) VARCem.res: win/VARCem.rc win/VARCem.mpp @@ -645,7 +648,7 @@ VARCem.res: win/VARCem.rc win/VARCem.mpp $(PROG).exe: $(OBJ) VARCem.res @echo Linking $(PROG).exe .. - @$(LINK) $(LDFLAGS) -OUT:$(PROG).exe \ + @$(LINK) $(LDFLAGS) $(LOPTS_W) -OUT:$(PROG).exe \ $(OBJ) VARCem.res $(LIBS) pcap_if.res: pcap_if.rc @@ -654,11 +657,12 @@ pcap_if.res: pcap_if.rc pcap_if.exe: pcap_if.obj win_dynld.obj pcap_if.res @echo Linking pcap_if.exe .. - @$(LINK) $(LDFLAGS) -OUT:pcap_if.exe \ + @$(LINK) $(LDFLAGS) $(LOPTS_C) -OUT:pcap_if.exe \ pcap_if.obj win_dynld.obj pcap_if.res hello.exe: hello.obj - $(LINK) $(LDFLAGS) -OUT:hello.exe hello.obj $(WXLIBS) $(LIBS) + $(LINK) $(LDFLAGS) $(LOPTS_C) -OUT:hello.exe \ + hello.obj $(WXLIBS) $(LIBS) clean: diff --git a/src/win/resource.h b/src/win/resource.h index 4e1e7d7..67d1ece 100644 --- a/src/win/resource.h +++ b/src/win/resource.h @@ -8,7 +8,7 @@ * * Windows resource defines. * - * Version: @(#)resource.h 1.0.13 2018/04/28 + * Version: @(#)resource.h 1.0.14 2018/05/03 * * Authors: Fred N. van Kempen, * Miran Grca, @@ -243,9 +243,12 @@ #define IDC_JOY2 1211 #define IDC_JOY3 1212 #define IDC_JOY4 1213 + #define IDC_HDTYPE 1280 + #define IDC_RENDER 1281 -#define IDC_STATUS 1282 + +#define IDC_STATBAR 1282 /* HELP menu. */ diff --git a/src/win/win.c b/src/win/win.c index 5aa22a1..7cfa116 100644 --- a/src/win/win.c +++ b/src/win/win.c @@ -8,7 +8,7 @@ * * Platform main support module for Windows. * - * Version: @(#)win.c 1.0.15 2018/04/27 + * Version: @(#)win.c 1.0.16 2018/05/03 * * Authors: Fred N. van Kempen, * Miran Grca, @@ -39,6 +39,9 @@ #define UNICODE #define _WIN32_WINNT 0x0501 #include +#ifdef _MSC_VER +# include /* for _open_osfhandle() */ +#endif #include #include #include @@ -67,9 +70,6 @@ # include "win_ddraw.h" # include "win_d3d.h" #endif -#ifdef _MSC_VER -# include /* for _open_osfhandle() */ -#endif #include "win.h" @@ -79,14 +79,14 @@ typedef struct { /* Platform Public data, specific. */ -HINSTANCE hinstance; /* application instance */ -HANDLE ghMutex; +HINSTANCE hInstance; /* application instance */ LCID lang_id; /* current language ID used */ DWORD dwSubLangID; /* Local data. */ -static HANDLE thMain; +static HANDLE hBlitMutex, /* video mutex */ + thMain; /* main thread */ static rc_str_t *lpRCstr2048, *lpRCstr4096, *lpRCstr4352, @@ -165,87 +165,34 @@ LoadCommonStrings(void) lpRCstr7168 = (rc_str_t *)malloc(STR_NUM_7168*sizeof(rc_str_t)); for (i=0; i= 2048) && (i <= 3071)) - str = lpRCstr2048[i-2048].str; - else if ((i >= 4096) && (i <= 4351)) - str = lpRCstr4096[i-4096].str; - else if ((i >= 4352) && (i <= 4607)) - str = lpRCstr4352[i-4352].str; - else if ((i >= 4608) && (i <= 5119)) - str = lpRCstr4608[i-4608].str; - else if ((i >= 5120) && (i <= 5375)) - str = lpRCstr5120[i-5120].str; - else if ((i >= 5376) && (i <= 5631)) - str = lpRCstr5376[i-5376].str; - else if ((i >= 5632) && (i <= 5887)) - str = lpRCstr5632[i-5632].str; - else if ((i >= 5888) && (i <= 6143)) - str = lpRCstr5888[i-5888].str; - else if ((i >= 6144) && (i <= 7167)) - str = lpRCstr6144[i-6144].str; - else - str = lpRCstr7168[i-7168].str; - - return((wchar_t *)str); + LoadString(hInstance, 7168+i, lpRCstr7168[i].str, 512); } @@ -314,6 +261,128 @@ ProcessCommandLine(wchar_t ***argw) } +/* Load an icon from the resources. */ +HICON +LoadIconEx(PCTSTR name) +{ + return((HICON)LoadImage(hInstance, name, IMAGE_ICON, 16, 16, LR_SHARED)); +} + + +/* For the Windows platform, this is the start of the application. */ +int WINAPI +WinMain(HINSTANCE hInst, HINSTANCE hPrev, LPSTR lpszArg, int nCmdShow) +{ + wchar_t **argw = NULL; + int argc, i; + + /* Set this to the default value (windowed mode). */ + vid_fullscreen = 0; + + /* We need this later. */ + hInstance = hInst; + + /* Initialize the version data. CrashDump needs it early. */ + pc_version("Windows"); + +#ifdef USE_CRASHDUMP + /* Enable crash dump services. */ + InitCrashDump(); +#endif + + /* First, set our (default) language. */ + plat_set_language(0x0409); + + /* Create console window. */ + if (force_debug) + plat_console(1); + + /* Process the command line for options. */ + argc = ProcessCommandLine(&argw); + + /* Pre-initialize the system, this loads the config file. */ + if (! pc_init(argc, argw)) { + /* Detach from console. */ + plat_console(0); + return(1); + } + + /* Cleanup: we may no longer need the console. */ + if (! force_debug) + plat_console(0); + + /* Create a mutex for the video handler. */ + hBlitMutex = CreateMutex(NULL, FALSE, MUTEX_NAME); + + /* Handle our GUI. */ + i = ui_init(nCmdShow); + + return(i); +} + + +/* + * We do this here since there is platform-specific stuff + * going on here, and we do it in a function separate from + * main() so we can call it from the UI module as well. + */ +void +plat_start(void) +{ + LARGE_INTEGER qpc; + + /* We have not stopped yet. */ + quited = 0; + + /* Initialize the high-precision timer. */ + timeBeginPeriod(1); + QueryPerformanceFrequency(&qpc); + timer_freq = qpc.QuadPart; + pclog("Main timer precision: %llu\n", timer_freq); + + /* Start the emulator, really. */ + thMain = thread_create(pc_thread, &quited); + SetThreadPriority(thMain, THREAD_PRIORITY_HIGHEST); +} + + +/* Cleanly stop the emulator. */ +void +plat_stop(void) +{ + quited = 1; + + plat_delay_ms(100); + + pc_close(thMain); + + thMain = NULL; +} + + +/* Set (or re-set) the language for the application. */ +void +plat_set_language(int id) +{ + LCID lcidNew = MAKELCID(id, dwSubLangID); + + if (lang_id != lcidNew) { + /* Set our new language ID. */ + lang_id = lcidNew; + + SetThreadLocale(lang_id); + + /* Load the strings table for this ID. */ + LoadCommonStrings(); + +#if 0 + /* Update the menus for this ID. */ + MenuUpdate(); +#endif + } +} + + #ifndef USE_WX /* Create a console if we don't already have one. */ void @@ -357,101 +426,80 @@ plat_console(int init) } } } - - -/* For the Windows platform, this is the start of the application. */ -int WINAPI -WinMain(HINSTANCE hInst, HINSTANCE hPrev, LPSTR lpszArg, int nCmdShow) -{ - wchar_t **argw = NULL; - int argc, i; - - /* Set this to the default value (windowed mode). */ - vid_fullscreen = 0; - - /* We need this later. */ - hinstance = hInst; - - /* Initialize the version data. CrashDump needs it early. */ - pc_version("Windows"); - -#ifdef USE_CRASHDUMP - /* Enable crash dump services. */ - InitCrashDump(); -#endif - - /* First, set our (default) language. */ - set_language(0x0409); - - /* Create console window. */ - if (force_debug) - plat_console(1); - - /* Process the command line for options. */ - argc = ProcessCommandLine(&argw); - - /* Pre-initialize the system, this loads the config file. */ - if (! pc_init(argc, argw)) { - /* Detach from console. */ - plat_console(0); - return(1); - } - - /* Cleanup: we may no longer need the console. */ - if (! force_debug) - plat_console(0); - - /* Handle our GUI. */ - i = ui_init(nCmdShow); - - return(i); -} #endif /*USE_WX*/ -/* - * We do this here since there is platform-specific stuff - * going on here, and we do it in a function separate from - * main() so we can call it from the UI module as well. - */ -void -do_start(void) +/* Return icon number based on drive type. */ +int +plat_fdd_icon(int type) { - LARGE_INTEGER qpc; + int ret = 512; - /* We have not stopped yet. */ - quited = 0; + switch(type) { + case 0: + break; - /* Initialize the high-precision timer. */ - timeBeginPeriod(1); - QueryPerformanceFrequency(&qpc); - timer_freq = qpc.QuadPart; - pclog("Main timer precision: %llu\n", timer_freq); + case 1: + case 2: + case 3: + case 4: + case 5: + case 6: + ret = 128; + break; - /* Start the emulator, really. */ - thMain = thread_create(pc_thread, &quited); - SetThreadPriority(thMain, THREAD_PRIORITY_HIGHEST); + case 7: + case 8: + case 9: + case 10: + case 11: + case 12: + case 13: + ret = 144; + break; + + default: + break; + } + + return(ret); } -/* Cleanly stop the emulator. */ -void -do_stop(void) +wchar_t * +plat_get_string(int i) { - quited = 1; + LPTSTR str; - plat_delay_ms(100); + if ((i >= 2048) && (i <= 3071)) + str = lpRCstr2048[i-2048].str; + else if ((i >= 4096) && (i <= 4351)) + str = lpRCstr4096[i-4096].str; + else if ((i >= 4352) && (i <= 4607)) + str = lpRCstr4352[i-4352].str; + else if ((i >= 4608) && (i <= 5119)) + str = lpRCstr4608[i-4608].str; + else if ((i >= 5120) && (i <= 5375)) + str = lpRCstr5120[i-5120].str; + else if ((i >= 5376) && (i <= 5631)) + str = lpRCstr5376[i-5376].str; + else if ((i >= 5632) && (i <= 5887)) + str = lpRCstr5632[i-5632].str; + else if ((i >= 5888) && (i <= 6143)) + str = lpRCstr5888[i-5888].str; + else if ((i >= 6144) && (i <= 7167)) + str = lpRCstr6144[i-6144].str; + else + str = lpRCstr7168[i-7168].str; - pc_close(thMain); - - thMain = NULL; + return((wchar_t *)str); } void plat_get_exe_name(wchar_t *bufp, int size) { - GetModuleFileName(hinstance, bufp, size); + GetModuleFileName(hInstance, bufp, size); } @@ -676,9 +724,6 @@ plat_setvid(int api) /* Close the (old) API. */ vid_apis[0][vid_api].close(); -//#ifdef USE_WX -// ui_check_menu_item(IDM_View_WX+vid_api, 0); -//#endif vid_api = api; #ifndef USE_WX @@ -690,11 +735,14 @@ plat_setvid(int api) /* Initialize the (new) API. */ #ifdef USE_WX -// ui_check_menu_item(IDM_View_WX+vid_api, 1); i = vid_apis[0][vid_api].init(NULL); #else i = vid_apis[0][vid_api].init((void *)hwndRender); #endif + + /* Update the menu item. */ + menu_set_radio_item(IDM_RENDER_1, 4, vid_api); + endblit(); if (! i) return(0); @@ -763,8 +811,10 @@ plat_setfullscreen(int on) device_force_redraw(); /* Finally, handle the host's mouse cursor. */ - /* pclog("%s full screen, %s cursor\n", on ? "enter" : "leave", on ? "hide" : "show"); */ - show_cursor(vid_fullscreen ? 0 : -1); +#if 0 +pclog("%s full screen, %s cursor\n", on ? "enter" : "leave", on ? "hide" : "show"); +#endif + ui_show_cursor(vid_fullscreen ? 0 : -1); } @@ -822,12 +872,12 @@ take_screenshot(void) void /* plat_ */ startblit(void) { - WaitForSingleObject(ghMutex, INFINITE); + WaitForSingleObject(hBlitMutex, INFINITE); } void /* plat_ */ endblit(void) { - ReleaseMutex(ghMutex); + ReleaseMutex(hBlitMutex); } diff --git a/src/win/win.h b/src/win/win.h index 30dfd04..ffac08c 100644 --- a/src/win/win.h +++ b/src/win/win.h @@ -8,7 +8,7 @@ * * Platform support defintions for Win32. * - * Version: @(#)win.h 1.0.8 2018/04/29 + * Version: @(#)win.h 1.0.10 2018/05/03 * * Authors: Fred N. van Kempen, * Miran Grca, @@ -39,6 +39,7 @@ #ifndef PLAT_WIN_H # define PLAT_WIN_H + #ifdef __cplusplus extern "C" { #endif @@ -48,80 +49,70 @@ extern "C" { /* Class names and such. */ -#define CLASS_NAME L"VARCem.MainWnd" +#define MUTEX_NAME L"VARCem.BlitMutex" +#define CLASS_NAME L"VARCem.MainWindow" +#define FS_CLASS_NAME L"VARCem.FullScreen" #define MENU_NAME L"MainMenu" -#define ACCEL_NAME L"MainAccel" -#define SUB_CLASS_NAME L"VARCem.SubWnd" -#define SB_CLASS_NAME L"VARCem.StatusBar" #define SB_MENU_NAME L"StatusBarMenu" +#define ACCEL_NAME L"MainAccel" /* Application-specific window messages. */ -#define WM_RESETD3D WM_USER +#define WM_PAUSE WM_USER #define WM_LEAVEFULLSCREEN WM_USER+1 -#define WM_SAVESETTINGS 0x8888 -#define WM_SHOWSETTINGS 0x8889 -#define WM_PAUSE 0x8890 -#define WM_SENDHWND 0x8891 +#define WM_RESETD3D WM_USER+2 +#define WM_SAVESETTINGS WM_USER+3 +#define WM_SHOWSETTINGS WM_USER+4 -extern HINSTANCE hinstance; +/* Status bar definitions. */ +#define SB_HEIGHT 16 /* for 16x16 icons */ +#define SB_PADDING 1 /* 1px of padding */ + + +extern HINSTANCE hInstance; +extern HICON hIcon[512]; extern HWND hwndMain, hwndRender; -extern HANDLE ghMutex; + extern LCID lang_id; -extern HICON hIcon[512]; extern int status_is_open; extern DWORD filterindex; +/* Internal platform support functions. */ #ifdef USE_CRASHDUMP extern void InitCrashDump(void); #endif - -extern HICON LoadIconEx(PCTSTR pszIconName); - -/* Emulator start/stop support functions. */ -extern void do_start(void); -extern void do_stop(void); - -/* Internal platform support functions. */ -extern void set_language(int id); -extern int get_vidpause(void); -extern void show_cursor(int); - +extern HICON LoadIconEx(PCTSTR name); extern void keyboard_getkeymap(void); extern void keyboard_handle(LPARAM lParam, int infocus); - extern void win_mouse_init(void); extern void win_mouse_close(void); -extern intptr_t fdd_type_to_icon(int type); - -#ifdef EMU_DEVICE_H -extern uint8_t deviceconfig_open(HWND hwnd, device_t *device); -#endif -extern uint8_t joystickconfig_open(HWND hwnd, int joy_nr, int type); - -extern int getfile(HWND hwnd, char *f, char *fn); -extern int getsfile(HWND hwnd, char *f, char *fn); - -extern void hard_disk_add_open(HWND hwnd, int is_existing); -extern int hard_disk_was_added(void); - -/* Platform UI support functions. */ -extern int ui_init(int nCmdShow); - -/* Functions in win_stbar.c: */ -extern HWND hwndSBAR; -extern void StatusBarCreate(HWND hwndParent, uintptr_t idStatus, - HINSTANCE hInst); - -/* Functions in win_dialog.c: */ +/* Internal dialog functions. */ extern void dialog_center(HWND hdlg); extern int dlg_file_ex(HWND hwnd, const wchar_t *filt, const wchar_t *ifn, wchar_t *fn, int save); +#ifdef EMU_DEVICE_H +extern uint8_t dlg_devconf(HWND hwnd, device_t *device); +#endif +extern uint8_t dlg_jsconf(HWND hwnd, int joy_nr, int type); + +/* Platform support functions. */ +extern void plat_set_language(int id); +extern int get_vidpause(void); +extern int fdd_type_icon(int type); + +/* Emulator start/stop support functions. */ +extern void plat_start(void); +extern void plat_stop(void); + +/* Platform UI support functions. */ +extern int ui_init(int nCmdShow); +extern void ui_menu_update(void); +extern void ui_show_cursor(int); #ifdef __cplusplus } diff --git a/src/win/win_about.c b/src/win/win_about.c index a1d1658..8e302f8 100644 --- a/src/win/win_about.c +++ b/src/win/win_about.c @@ -8,7 +8,7 @@ * * Handle the About dialog. * - * Version: @(#)win_about.c 1.0.6 2018/04/27 + * Version: @(#)win_about.c 1.0.7 2018/05/02 * * Authors: Fred N. van Kempen, * Miran Grca, @@ -90,7 +90,7 @@ dlg_proc(HWND hdlg, UINT message, WPARAM wParam, LPARAM lParam) h = GetDlgItem(hdlg, IDC_ABOUT_ICON); SendMessage(h, STM_SETIMAGE, (WPARAM)IMAGE_ICON, - (LPARAM)LoadImage(hinstance,(PCTSTR)100,IMAGE_ICON,64,64,0)); + (LPARAM)LoadImage(hInstance,(PCTSTR)100,IMAGE_ICON,64,64,0)); SendDlgItemMessage(hdlg, IDT_TITLE, WM_SETTEXT, (WPARAM)NULL, (LPARAM)emu_title); set_font_bold(hdlg, IDT_TITLE); @@ -121,7 +121,7 @@ dlg_about(void) { plat_pause(1); - DialogBox(hinstance, (LPCTSTR)DLG_ABOUT, hwndMain, dlg_proc); + DialogBox(hInstance, (LPCTSTR)DLG_ABOUT, hwndMain, dlg_proc); plat_pause(0); } diff --git a/src/win/win_d3d.cpp b/src/win/win_d3d.cpp index 288401a..bf4df4e 100644 --- a/src/win/win_d3d.cpp +++ b/src/win/win_d3d.cpp @@ -8,7 +8,7 @@ * * Rendering module for Microsoft Direct3D 9. * - * Version: @(#)win_d3d.cpp 1.0.8 2018/04/25 + * Version: @(#)win_d3d.cpp 1.0.9 2018/05/02 * * Authors: Fred N. van Kempen, * Miran Grca, @@ -479,9 +479,8 @@ d3d_init_fs(HWND h) /*FIXME: should be done once, in win.c */ _swprintf(title, L"%s v%s", TEXT(EMU_NAME), TEXT(EMU_VERSION)); - d3d_device_window = CreateWindowEx ( - 0, - SUB_CLASS_NAME, + d3d_device_window = CreateWindow( + FS_CLASS_NAME, title, WS_POPUP, CW_USEDEFAULT, diff --git a/src/win/win_devconf.c b/src/win/win_devconf.c index 7a03f35..72d83b6 100644 --- a/src/win/win_devconf.c +++ b/src/win/win_devconf.c @@ -12,7 +12,7 @@ * and builds a complete Win32 DIALOG resource block in a * buffer in memory, and then passes that to the API handler. * - * Version: @(#)win_devconf.c 1.0.14 2018/04/29 + * Version: @(#)win_devconf.c 1.0.15 2018/05/02 * * Authors: Fred N. van Kempen, * Miran Grca, @@ -447,7 +447,7 @@ dlg_proc(HWND hdlg, UINT message, WPARAM wParam, LPARAM lParam) */ #define DLG_MAX_SIZE 16384 uint8_t -deviceconfig_open(HWND hwnd, device_t *device) +dlg_devconf(HWND hwnd, device_t *device) { char temp[128]; const device_config_t *cfg = device->config; @@ -703,7 +703,7 @@ deviceconfig_open(HWND hwnd, device_t *device) devconf_device = device; - DialogBoxIndirect(hinstance, dlg, hwnd, dlg_proc); + DialogBoxIndirect(hInstance, dlg, hwnd, dlg_proc); free(blk); diff --git a/src/win/win_joystick.cpp b/src/win/win_joystick.cpp index 107560e..a88ac1c 100644 --- a/src/win/win_joystick.cpp +++ b/src/win/win_joystick.cpp @@ -13,7 +13,7 @@ * NOTE: Hacks currently needed to compile with MSVC; DX needs to * be updated to 11 or 12 or so. --FvK * - * Version: @(#)win_joystick.cpp 1.0.10 2018/04/26 + * Version: @(#)win_joystick.cpp 1.0.11 2018/05/02 * * Authors: Fred N. van Kempen, * Miran Grca, @@ -180,7 +180,7 @@ joystick_init(void) joysticks_present = 0; - if (FAILED(DirectInput8Create(hinstance, + if (FAILED(DirectInput8Create(hInstance, DIRECTINPUT_VERSION, IID_IDirectInput8A, (void **) &lpdi, NULL))) fatal("joystick_init : DirectInputCreate failed\n"); @@ -615,7 +615,7 @@ dlg_proc(HWND hdlg, UINT message, WPARAM wParam, UNUSED(LPARAM lParam)) uint8_t -joystickconfig_open(HWND hwnd, int joy_nr, int type) +dlg_jsconf(HWND hwnd, int joy_nr, int type) { uint16_t *data_block = (uint16_t *)malloc(16384); uint16_t *data; @@ -831,7 +831,7 @@ joystickconfig_open(HWND hwnd, int joy_nr, int type) dlg->cy = y + 20; - DialogBoxIndirect(hinstance, dlg, hwnd, dlg_proc); + DialogBoxIndirect(hInstance, dlg, hwnd, dlg_proc); free(data_block); diff --git a/src/win/win_mouse.cpp b/src/win/win_mouse.cpp index e1a2511..709e574 100644 --- a/src/win/win_mouse.cpp +++ b/src/win/win_mouse.cpp @@ -8,7 +8,7 @@ * * Mouse interface to host device. * - * Version: @(#)win_mouse.cpp 1.0.4 2018/04/26 + * Version: @(#)win_mouse.cpp 1.0.5 2018/05/02 * * Authors: Fred N. van Kempen, * Miran Grca, @@ -62,7 +62,7 @@ win_mouse_init(void) mouse_capture = 0; - if (FAILED(DirectInput8Create(hinstance, DIRECTINPUT_VERSION, + if (FAILED(DirectInput8Create(hInstance, DIRECTINPUT_VERSION, IID_IDirectInput8A, (void **) &lpdi, NULL))) fatal("plat_mouse_init: DirectInputCreate failed\n"); diff --git a/src/win/win_new_floppy.c b/src/win/win_new_floppy.c index f8767c1..f569c7b 100644 --- a/src/win/win_new_floppy.c +++ b/src/win/win_new_floppy.c @@ -8,7 +8,7 @@ * * Implementation of the New Floppy Image dialog. * - * Version: @(#)win_new_floppy.c 1.0.11 2018/04/29 + * Version: @(#)win_new_floppy.c 1.0.12 2018/05/02 * * Authors: Fred N. van Kempen, * Miran Grca, @@ -265,5 +265,5 @@ dlg_new_floppy(int idm, int tag) fdd_id = idm & 0x7f; sb_part = tag; - DialogBox(hinstance, (LPCTSTR)DLG_NEW_FLOPPY, hwndMain, dlg_proc); + DialogBox(hInstance, (LPCTSTR)DLG_NEW_FLOPPY, hwndMain, dlg_proc); } diff --git a/src/win/win_settings.c b/src/win/win_settings.c index de67b5b..5bc9e41 100644 --- a/src/win/win_settings.c +++ b/src/win/win_settings.c @@ -8,7 +8,7 @@ * * Implementation of the Settings dialog. * - * Version: @(#)win_settings.c 1.0.26 2018/04/29 + * Version: @(#)win_settings.c 1.0.27 2018/05/02 * * Authors: Fred N. van Kempen, * Miran Grca, @@ -167,7 +167,7 @@ settings_msgbox(int type, void *arg) /* This does the initial read of global variables into the temporary ones. */ static void -dlg_init(void) +settings_init(void) { int i = 0; @@ -451,61 +451,61 @@ show_child(HWND hwndParent, DWORD child_id) switch(child_id) { case PAGE_MACHINE: - hwndChildDialog = CreateDialog(hinstance, + hwndChildDialog = CreateDialog(hInstance, (LPCWSTR)DLG_CFG_MACHINE, hwndParent, machine_proc); break; case PAGE_VIDEO: - hwndChildDialog = CreateDialog(hinstance, + hwndChildDialog = CreateDialog(hInstance, (LPCWSTR)DLG_CFG_VIDEO, hwndParent, video_proc); break; case PAGE_INPUT: - hwndChildDialog = CreateDialog(hinstance, + hwndChildDialog = CreateDialog(hInstance, (LPCWSTR)DLG_CFG_INPUT, hwndParent, input_proc); break; case PAGE_SOUND: - hwndChildDialog = CreateDialog(hinstance, + hwndChildDialog = CreateDialog(hInstance, (LPCWSTR)DLG_CFG_SOUND, hwndParent, sound_proc); break; case PAGE_NETWORK: - hwndChildDialog = CreateDialog(hinstance, + hwndChildDialog = CreateDialog(hInstance, (LPCWSTR)DLG_CFG_NETWORK, hwndParent, network_proc); break; case PAGE_PORTS: - hwndChildDialog = CreateDialog(hinstance, + hwndChildDialog = CreateDialog(hInstance, (LPCWSTR)DLG_CFG_PORTS, hwndParent, ports_proc); break; case PAGE_PERIPHERALS: - hwndChildDialog = CreateDialog(hinstance, + hwndChildDialog = CreateDialog(hInstance, (LPCWSTR)DLG_CFG_PERIPHERALS, hwndParent, peripherals_proc); break; case PAGE_HARD_DISKS: - hwndChildDialog = CreateDialog(hinstance, + hwndChildDialog = CreateDialog(hInstance, (LPCWSTR)DLG_CFG_DISK, hwndParent, disk_proc); break; case PAGE_FLOPPY_DRIVES: - hwndChildDialog = CreateDialog(hinstance, + hwndChildDialog = CreateDialog(hInstance, (LPCWSTR)DLG_CFG_FLOPPY, hwndParent, floppy_proc); break; case PAGE_OTHER_REMOVABLE_DEVICES: - hwndChildDialog = CreateDialog(hinstance, + hwndChildDialog = CreateDialog(hInstance, (LPCWSTR)DLG_CFG_RMV_DEVICES, hwndParent, rmv_devices_proc); break; @@ -531,7 +531,7 @@ image_list_init(HWND hwndList) ILC_MASK | ILC_COLOR32, 1, 1); for (i=0; i<10; i++) { - hiconItem = LoadIcon(hinstance, (LPCWSTR) (256 + (uintptr_t) i)); + hiconItem = LoadIcon(hInstance, (LPCWSTR) (256 + (uintptr_t) i)); ImageList_AddIcon(hSmall, hiconItem); DestroyIcon(hiconItem); } @@ -581,7 +581,7 @@ dlg_proc(HWND hdlg, UINT message, WPARAM wParam, LPARAM lParam) switch (message) { case WM_INITDIALOG: dialog_center(hdlg); - dlg_init(); + settings_init(); disk_track_init(); cdrom_track_init(); @@ -674,7 +674,7 @@ dlg_settings(int ask) } ask_sure = ask; - i = DialogBox(hinstance, (LPCWSTR)DLG_CONFIG, hwndMain, dlg_proc); + i = DialogBox(hInstance, (LPCWSTR)DLG_CONFIG, hwndMain, dlg_proc); return(i); } diff --git a/src/win/win_settings_disk.h b/src/win/win_settings_disk.h index bc63a79..a8bd276 100644 --- a/src/win/win_settings_disk.h +++ b/src/win/win_settings_disk.h @@ -8,7 +8,7 @@ * * Implementation of the Settings dialog. * - * Version: @(#)win_settings_disk.h 1.0.6 2018/04/29 + * Version: @(#)win_settings_disk.h 1.0.7 2018/05/02 * * Authors: Fred N. van Kempen, * Miran Grca, @@ -100,11 +100,11 @@ disk_image_list_init(HWND hwndList) GetSystemMetrics(SM_CYSMICON), ILC_MASK | ILC_COLOR32, 1, 1); - hiconItem = LoadIcon(hinstance, (LPCWSTR)208); + hiconItem = LoadIcon(hInstance, (LPCWSTR)208); ImageList_AddIcon(hSmall, hiconItem); DestroyIcon(hiconItem); - hiconItem = LoadIcon(hinstance, (LPCWSTR)192); + hiconItem = LoadIcon(hInstance, (LPCWSTR)192); ImageList_AddIcon(hSmall, hiconItem); DestroyIcon(hiconItem); @@ -1452,7 +1452,7 @@ disk_add_open(HWND hwnd, int is_existing) hard_disk_added = 0; - DialogBox(hinstance, (LPCWSTR)DLG_CFG_DISK_ADD, hwnd, disk_add_proc); + DialogBox(hInstance, (LPCWSTR)DLG_CFG_DISK_ADD, hwnd, disk_add_proc); } diff --git a/src/win/win_settings_floppy.h b/src/win/win_settings_floppy.h index 0c93fbc..720d583 100644 --- a/src/win/win_settings_floppy.h +++ b/src/win/win_settings_floppy.h @@ -8,7 +8,7 @@ * * Implementation of the Settings dialog. * - * Version: @(#)win_settings_floppy.h 1.0.3 2018/04/29 + * Version: @(#)win_settings_floppy.h 1.0.4 2018/05/03 * * Authors: Fred N. van Kempen, * Miran Grca, @@ -58,7 +58,7 @@ floppy_image_list_init(HWND hwndList) ILC_MASK | ILC_COLOR32, 1, 1); for (i = 0; i < 14; i++) { - hiconItem = LoadIcon(hinstance, (LPCWSTR)sb_fdd_icon(i)); + hiconItem = LoadIcon(hInstance, (LPCWSTR)plat_fdd_icon(i)); ImageList_AddIcon(hSmall, hiconItem); DestroyIcon(hiconItem); } diff --git a/src/win/win_settings_input.h b/src/win/win_settings_input.h index 77fcf55..7face04 100644 --- a/src/win/win_settings_input.h +++ b/src/win/win_settings_input.h @@ -8,7 +8,7 @@ * * Implementation of the Settings dialog. * - * Version: @(#)win_settings_input.h 1.0.6 2018/04/29 + * Version: @(#)win_settings_input.h 1.0.7 2018/05/02 * * Authors: Fred N. van Kempen, * Miran Grca, @@ -135,7 +135,7 @@ input_proc(HWND hdlg, UINT message, WPARAM wParam, LPARAM lParam) case IDC_CONFIGURE_MOUSE: h = GetDlgItem(hdlg, IDC_COMBO_MOUSE); temp_mouse = list_to_mouse[SendMessage(h, CB_GETCURSEL, 0, 0)]; - temp_deviceconfig |= deviceconfig_open(hdlg, (void *)mouse_get_device(temp_mouse)); + temp_deviceconfig |= dlg_devconf(hdlg, (void *)mouse_get_device(temp_mouse)); break; case IDC_COMBO_JOYSTICK: @@ -155,25 +155,25 @@ input_proc(HWND hdlg, UINT message, WPARAM wParam, LPARAM lParam) case IDC_JOY1: h = GetDlgItem(hdlg, IDC_COMBO_JOYSTICK); temp_joystick = SendMessage(h, CB_GETCURSEL, 0, 0); - temp_deviceconfig |= joystickconfig_open(hdlg, 0, temp_joystick); + temp_deviceconfig |= dlg_jsconf(hdlg, 0, temp_joystick); break; case IDC_JOY2: h = GetDlgItem(hdlg, IDC_COMBO_JOYSTICK); temp_joystick = SendMessage(h, CB_GETCURSEL, 0, 0); - temp_deviceconfig |= joystickconfig_open(hdlg, 1, temp_joystick); + temp_deviceconfig |= dlg_jsconf(hdlg, 1, temp_joystick); break; case IDC_JOY3: h = GetDlgItem(hdlg, IDC_COMBO_JOYSTICK); temp_joystick = SendMessage(h, CB_GETCURSEL, 0, 0); - temp_deviceconfig |= joystickconfig_open(hdlg, 2, temp_joystick); + temp_deviceconfig |= dlg_jsconf(hdlg, 2, temp_joystick); break; case IDC_JOY4: h = GetDlgItem(hdlg, IDC_COMBO_JOYSTICK); temp_joystick = SendMessage(h, CB_GETCURSEL, 0, 0); - temp_deviceconfig |= joystickconfig_open(hdlg, 3, temp_joystick); + temp_deviceconfig |= dlg_jsconf(hdlg, 3, temp_joystick); break; } return FALSE; diff --git a/src/win/win_settings_machine.h b/src/win/win_settings_machine.h index 05d22f8..195ab5c 100644 --- a/src/win/win_settings_machine.h +++ b/src/win/win_settings_machine.h @@ -8,7 +8,7 @@ * * Implementation of the Settings dialog. * - * Version: @(#)win_settings_machine.h 1.0.4 2018/04/29 + * Version: @(#)win_settings_machine.h 1.0.5 2018/05/02 * * Authors: Fred N. van Kempen, * Miran Grca, @@ -281,7 +281,7 @@ machine_proc(HWND hdlg, UINT message, WPARAM wParam, LPARAM lParam) h = GetDlgItem(hdlg, IDC_COMBO_MACHINE); temp_machine = listtomachine[SendMessage(h, CB_GETCURSEL, 0, 0)]; - temp_deviceconfig |= deviceconfig_open(hdlg, (void *)machine_getdevice(temp_machine)); + temp_deviceconfig |= dlg_devconf(hdlg, (void *)machine_getdevice(temp_machine)); break; } diff --git a/src/win/win_settings_network.h b/src/win/win_settings_network.h index b283a91..0e0fb8a 100644 --- a/src/win/win_settings_network.h +++ b/src/win/win_settings_network.h @@ -8,7 +8,7 @@ * * Implementation of the Settings dialog. * - * Version: @(#)win_settings_network.h 1.0.4 2018/04/29 + * Version: @(#)win_settings_network.h 1.0.5 2018/05/02 * * Authors: Fred N. van Kempen, * Miran Grca, @@ -184,7 +184,7 @@ network_proc(HWND hdlg, UINT message, WPARAM wParam, LPARAM lParam) h = GetDlgItem(hdlg, IDC_COMBO_NET); temp_net_card = list_to_nic[SendMessage(h, CB_GETCURSEL, 0, 0)]; - temp_deviceconfig |= deviceconfig_open(hdlg, (void *)network_card_getdevice(temp_net_card)); + temp_deviceconfig |= dlg_devconf(hdlg, (void *)network_card_getdevice(temp_net_card)); break; } return FALSE; diff --git a/src/win/win_settings_periph.h b/src/win/win_settings_periph.h index 436762b..c3837d4 100644 --- a/src/win/win_settings_periph.h +++ b/src/win/win_settings_periph.h @@ -8,7 +8,7 @@ * * Implementation of the Settings dialog. * - * Version: @(#)win_settings_periph.h 1.0.5 2018/04/29 + * Version: @(#)win_settings_periph.h 1.0.6 2018/05/02 * * Authors: Fred N. van Kempen, * Miran Grca, @@ -212,14 +212,14 @@ peripherals_proc(HWND hdlg, UINT message, WPARAM wParam, LPARAM lParam) h = GetDlgItem(hdlg, IDC_COMBO_SCSI); temp_scsi_card = list_to_scsi[SendMessage(h, CB_GETCURSEL, 0, 0)]; - temp_deviceconfig |= deviceconfig_open(hdlg, (void *)scsi_card_getdevice(temp_scsi_card)); + temp_deviceconfig |= dlg_devconf(hdlg, (void *)scsi_card_getdevice(temp_scsi_card)); break; case IDC_CONFIGURE_HDC: h = GetDlgItem(hdlg, IDC_COMBO_HDC); temp_hdc_type = hdc_get_from_internal_name(hdc_names[SendMessage(h, CB_GETCURSEL, 0, 0)]); - temp_deviceconfig |= deviceconfig_open(hdlg, (void *)hdc_get_device(temp_hdc_type)); + temp_deviceconfig |= dlg_devconf(hdlg, (void *)hdc_get_device(temp_hdc_type)); break; case IDC_COMBO_SCSI: diff --git a/src/win/win_settings_remov.h b/src/win/win_settings_remov.h index ad86eda..f2147f5 100644 --- a/src/win/win_settings_remov.h +++ b/src/win/win_settings_remov.h @@ -8,7 +8,7 @@ * * Implementation of the "Removable Devices" dialog. * - * Version: @(#)win_settings_remov.h 1.0.4 2018/04/30 + * Version: @(#)win_settings_remov.h 1.0.5 2018/05/02 * * Authors: Fred N. van Kempen, * Miran Grca, @@ -88,11 +88,11 @@ cdrom_image_list_init(HWND hwndList) GetSystemMetrics(SM_CYSMICON), ILC_MASK | ILC_COLOR32, 1, 1); - hiconItem = LoadIcon(hinstance, (LPCWSTR)514); + hiconItem = LoadIcon(hInstance, (LPCWSTR)514); ImageList_AddIcon(hSmall, hiconItem); DestroyIcon(hiconItem); - hiconItem = LoadIcon(hinstance, (LPCWSTR)160); + hiconItem = LoadIcon(hInstance, (LPCWSTR)160); ImageList_AddIcon(hSmall, hiconItem); DestroyIcon(hiconItem); @@ -435,11 +435,11 @@ zip_image_list_init(HWND hwndList) GetSystemMetrics(SM_CYSMICON), ILC_MASK | ILC_COLOR32, 1, 1); - hiconItem = LoadIcon(hinstance, (LPCWSTR)515); + hiconItem = LoadIcon(hInstance, (LPCWSTR)515); ImageList_AddIcon(hSmall, hiconItem); DestroyIcon(hiconItem); - hiconItem = LoadIcon(hinstance, (LPCWSTR)176); + hiconItem = LoadIcon(hInstance, (LPCWSTR)176); ImageList_AddIcon(hSmall, hiconItem); DestroyIcon(hiconItem); diff --git a/src/win/win_settings_sound.h b/src/win/win_settings_sound.h index 175cc53..dba9a63 100644 --- a/src/win/win_settings_sound.h +++ b/src/win/win_settings_sound.h @@ -8,7 +8,7 @@ * * Implementation of the Settings dialog. * - * Version: @(#)win_settings_sound.h 1.0.6 2018/04/29 + * Version: @(#)win_settings_sound.h 1.0.7 2018/05/02 * * Authors: Fred N. van Kempen, * Miran Grca, @@ -194,7 +194,7 @@ sound_proc(HWND hdlg, UINT message, WPARAM wParam, LPARAM lParam) h = GetDlgItem(hdlg, IDC_COMBO_SOUND); temp_sound_card = list_to_sound[SendMessage(h, CB_GETCURSEL, 0, 0)]; - temp_deviceconfig |= deviceconfig_open(hdlg, (void *)sound_card_getdevice(temp_sound_card)); + temp_deviceconfig |= dlg_devconf(hdlg, (void *)sound_card_getdevice(temp_sound_card)); break; case IDC_COMBO_MIDI: @@ -219,7 +219,7 @@ sound_proc(HWND hdlg, UINT message, WPARAM wParam, LPARAM lParam) h = GetDlgItem(hdlg, IDC_COMBO_MIDI); temp_midi_device = list_to_midi[SendMessage(h, CB_GETCURSEL, 0, 0)]; - temp_deviceconfig |= deviceconfig_open(hdlg, (void *)midi_device_getdevice(temp_midi_device)); + temp_deviceconfig |= dlg_devconf(hdlg, (void *)midi_device_getdevice(temp_midi_device)); break; case IDC_CHECK_MPU401: @@ -231,7 +231,7 @@ sound_proc(HWND hdlg, UINT message, WPARAM wParam, LPARAM lParam) break; case IDC_CONFIGURE_MPU401: - temp_deviceconfig |= deviceconfig_open(hdlg, (void *)&mpu401_device); + temp_deviceconfig |= dlg_devconf(hdlg, (void *)&mpu401_device); break; } return FALSE; diff --git a/src/win/win_settings_video.h b/src/win/win_settings_video.h index 78a79bf..0fa6807 100644 --- a/src/win/win_settings_video.h +++ b/src/win/win_settings_video.h @@ -8,7 +8,7 @@ * * Implementation of the Settings dialog. * - * Version: @(#)win_settings_video.h 1.0.3 2018/04/29 + * Version: @(#)win_settings_video.h 1.0.4 2018/05/02 * * Authors: Fred N. van Kempen, * Miran Grca, @@ -159,14 +159,14 @@ video_proc(HWND hdlg, UINT message, WPARAM wParam, LPARAM lParam) break; case IDC_BUTTON_VOODOO: - temp_deviceconfig |= deviceconfig_open(hdlg, (void *)&voodoo_device); + temp_deviceconfig |= dlg_devconf(hdlg, (void *)&voodoo_device); break; case IDC_CONFIGURE_VID: h = GetDlgItem(hdlg, IDC_COMBO_VIDEO); SendMessage(h, CB_GETLBTEXT, SendMessage(h, CB_GETCURSEL, 0, 0), (LPARAM)temp); wcstombs(tempA, temp, sizeof(temp)); - temp_deviceconfig |= deviceconfig_open(hdlg, (void *)video_card_getdevice(video_card_getid(tempA))); + temp_deviceconfig |= dlg_devconf(hdlg, (void *)video_card_getdevice(video_card_getid(tempA))); break; } diff --git a/src/win/win_snd_gain.c b/src/win/win_snd_gain.c index fabf8fc..32a2055 100644 --- a/src/win/win_snd_gain.c +++ b/src/win/win_snd_gain.c @@ -8,7 +8,7 @@ * * Implementation of the Sound Gain dialog. * - * Version: @(#)win_snd_gain.c 1.0.4 2018/04/29 + * Version: @(#)win_snd_gain.c 1.0.5 2018/05/01 * * Authors: Fred N. van Kempen, * Miran Grca, @@ -65,6 +65,7 @@ dlg_proc(HWND hdlg, UINT message, WPARAM wParam, LPARAM lParam) switch (message) { case WM_INITDIALOG: + dialog_center(hdlg); old_gain = sound_gain; h = GetDlgItem(hdlg, IDC_SLIDER_GAIN); SendMessage(h, TBM_SETRANGE, (WPARAM)1, (LPARAM)MAKELONG(0, 9)); @@ -107,5 +108,5 @@ dlg_proc(HWND hdlg, UINT message, WPARAM wParam, LPARAM lParam) void dlg_sound_gain(void) { - DialogBox(hinstance, (LPCTSTR)DLG_SND_GAIN, hwndMain, dlg_proc); + DialogBox(hInstance, (LPCTSTR)DLG_SND_GAIN, hwndMain, dlg_proc); } diff --git a/src/win/win_status.c b/src/win/win_status.c index 8b08466..6a9fa29 100644 --- a/src/win/win_status.c +++ b/src/win/win_status.c @@ -8,7 +8,7 @@ * * Implementation of the Status Window dialog. * - * Version: @(#)win_status.c 1.0.4 2018/04/27 + * Version: @(#)win_status.c 1.0.5 2018/05/02 * * Authors: Fred N. van Kempen, * Miran Grca, @@ -144,7 +144,7 @@ dlg_status(void) { HWND hwnd; - hwnd = CreateDialog(hinstance, (LPCSTR)DLG_STATUS, hwndMain, dlg_proc); + hwnd = CreateDialog(hInstance, (LPCSTR)DLG_STATUS, hwndMain, dlg_proc); ShowWindow(hwnd, SW_SHOW); } diff --git a/src/win/win_stbar.c b/src/win/win_stbar.c deleted file mode 100644 index 39c52f4..0000000 --- a/src/win/win_stbar.c +++ /dev/null @@ -1,337 +0,0 @@ -/* - * VARCem Virtual ARchaeological Computer EMulator. - * An emulator of (mostly) x86-based PC systems and devices, - * using the ISA,EISA,VLB,MCA and PCI system buses, roughly - * spanning the era between 1981 and 1995. - * - * This file is part of the VARCem Project. - * - * Implementation of the Status Bar module. - * - * Version: @(#)win_stbar.c 1.0.13 2018/04/29 - * - * Authors: Fred N. van Kempen, - * Miran Grca, - * - * Copyright 2017,2018 Fred N. van Kempen. - * Copyright 2016-2018 Miran Grca. - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the: - * - * Free Software Foundation, Inc. - * 59 Temple Place - Suite 330 - * Boston, MA 02111-1307 - * USA. - */ -#define UNICODE -#define WIN32_LEAN_AND_MEAN -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include "../emu.h" -#include "../ui/ui.h" -#include "../plat.h" -#include "win.h" - -#ifndef GWL_WNDPROC -#define GWL_WNDPROC GWLP_WNDPROC -#endif - - -#define SBAR_HEIGHT 17 /* for 16x16 icons */ - - -HWND hwndSBAR; - - -static LONG_PTR OriginalProcedure; -static HMENU menuSBAR; -static HMENU *sb_menu; -static int sb_nparts; - - -static VOID APIENTRY -PopupMenu(HWND hwnd, POINT pt, int part) -{ - if (part >= (sb_nparts - 1)) return; - - pt.x = part * SB_ICON_WIDTH; /* justify to the left */ - pt.y = 0; /* justify to the top */ - - ClientToScreen(hwnd, (LPPOINT)&pt); - - TrackPopupMenu(sb_menu[part], - TPM_LEFTALIGN | TPM_BOTTOMALIGN | TPM_LEFTBUTTON, - pt.x, pt.y, 0, hwndSBAR, NULL); -} - - -/* Handle messages for the Status Bar window. */ -#ifdef __amd64__ -static LRESULT CALLBACK -#else -static BOOL CALLBACK -#endif -dlg_proc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) -{ - RECT r; - POINT pt; - int idm, tag; - - switch (message) { - case WM_COMMAND: - idm = LOWORD(wParam) & 0xff00; /* low 8 bits */ - tag = LOWORD(wParam) & 0x00ff; /* high 8 bits */ - ui_sb_menu_command(idm, tag); - return(0); - - case WM_LBUTTONDOWN: - case WM_RBUTTONDOWN: - GetClientRect(hwnd, (LPRECT)&r); - pt.x = GET_X_LPARAM(lParam); - pt.y = GET_Y_LPARAM(lParam); - if (PtInRect((LPRECT)&r, pt)) - PopupMenu(hwnd, pt, (pt.x / SB_ICON_WIDTH)); - break; - - case WM_LBUTTONDBLCLK: - GetClientRect(hwnd, (LPRECT)&r); - pt.x = GET_X_LPARAM(lParam); - pt.y = GET_Y_LPARAM(lParam); - tag = (pt.x / SB_ICON_WIDTH); - if (PtInRect((LPRECT)&r, pt)) - ui_sb_click(tag); - break; - - default: - return(CallWindowProc((WNDPROC)OriginalProcedure, - hwnd, message, wParam, lParam)); - } - - return(0); -} - - -/* Create and set up the Status Bar window. */ -void -StatusBarCreate(HWND hwndParent, uintptr_t idStatus, HINSTANCE hInst) -{ - intptr_t i; - int dw, dh; - RECT r; - - /* Load our icons into the cache for faster access. */ - for (i = 128; i < 130; i++) - hIcon[i] = LoadIconEx((PCTSTR)i); - for (i = 144; i < 146; i++) - hIcon[i] = LoadIconEx((PCTSTR)i); - for (i = 160; i < 162; i++) - hIcon[i] = LoadIconEx((PCTSTR)i); - for (i = 176; i < 178; i++) - hIcon[i] = LoadIconEx((PCTSTR)i); - for (i = 192; i < 194; i++) - hIcon[i] = LoadIconEx((PCTSTR)i); - for (i = 208; i < 210; i++) - hIcon[i] = LoadIconEx((PCTSTR)i); - for (i = 224; i < 226; i++) - hIcon[i] = LoadIconEx((PCTSTR)i); - for (i = 259; i < 260; i++) - hIcon[i] = LoadIconEx((PCTSTR)i); - for (i = 384; i < 386; i++) - hIcon[i] = LoadIconEx((PCTSTR)i); - for (i = 400; i < 402; i++) - hIcon[i] = LoadIconEx((PCTSTR)i); - for (i = 416; i < 418; i++) - hIcon[i] = LoadIconEx((PCTSTR)i); - for (i = 432; i < 434; i++) - hIcon[i] = LoadIconEx((PCTSTR)i); - for (i = 448; i < 450; i++) - hIcon[i] = LoadIconEx((PCTSTR)i); - - GetWindowRect(hwndParent, &r); - dw = r.right - r.left; - dh = r.bottom - r.top; - - /* Load the Common Controls DLL if needed. */ - InitCommonControls(); - - /* Create the window, and make sure it's using the STATUS class. */ - hwndSBAR = CreateWindowEx(0, - STATUSCLASSNAME, - (LPCTSTR)NULL, - SBARS_SIZEGRIP|WS_CHILD|WS_VISIBLE|SBT_TOOLTIPS, - 0, dh-SBAR_HEIGHT, dw, SBAR_HEIGHT, - hwndParent, - (HMENU)idStatus, hInst, NULL); - - /* Replace the original procedure with ours. */ - OriginalProcedure = GetWindowLongPtr(hwndSBAR, GWLP_WNDPROC); - SetWindowLongPtr(hwndSBAR, GWL_WNDPROC, (LONG_PTR)&dlg_proc); - - SendMessage(hwndSBAR, SB_SETMINHEIGHT, (WPARAM)SBAR_HEIGHT, (LPARAM)0); - - /* Align the window with the parent (main) window. */ - GetWindowRect(hwndSBAR, &r); - SetWindowPos(hwndSBAR, - HWND_TOPMOST, - r.left, r.top, r.right-r.left, r.bottom-r.top, - SWP_SHOWWINDOW); - - /* Load the dummu menu for this window. */ - menuSBAR = LoadMenu(hInst, SB_MENU_NAME); - - /* Clear the menus, just in case.. */ - sb_nparts = 0; - sb_menu = NULL; -} - - -/* Also used by win_settings.c */ -int -sb_fdd_icon(int type) -{ - int ret = 512; - - switch(type) { - case 0: - break; - - case 1: - case 2: - case 3: - case 4: - case 5: - case 6: - ret = 128; - break; - - case 7: - case 8: - case 9: - case 10: - case 11: - case 12: - case 13: - ret = 144; - break; - - default: - break; - } - - return(ret); -} - - -void -sb_setup(int parts, const int *widths) -{ - SendMessage(hwndSBAR, SB_SETPARTS, (WPARAM)parts, (LPARAM)widths); - - if (sb_menu != NULL) - sb_menu_destroy(); - - sb_menu = (HMENU *)malloc(parts * sizeof(HMENU)); - memset(sb_menu, 0x00, parts * sizeof(HMENU)); - - sb_nparts = parts; -} - - -void -sb_menu_destroy(void) -{ - int i; - - if (!sb_nparts || (sb_menu == NULL)) return; - - for (i = 0; i < sb_nparts; i++) { - if (sb_menu[i] != NULL) - DestroyMenu(sb_menu[i]); - } - - free(sb_menu); - - sb_menu = NULL; -} - - -/* Create a menu for a status bar part. */ -void -sb_menu_create(int part) -{ - HMENU h; - - h = CreatePopupMenu(); - - sb_menu[part] = h; -} - - -/* Add an item to a (status bar) menu. */ -void -sb_menu_add_item(int part, int idm, const wchar_t *str) -{ - if (idm >= 0) - AppendMenu(sb_menu[part], MF_STRING, idm, str); - else - AppendMenu(sb_menu[part], MF_SEPARATOR, 0, NULL); -} - - -void -sb_menu_enable_item(int part, int idm, int val) -{ - EnableMenuItem(sb_menu[part], idm, - val ? MF_BYCOMMAND|MF_ENABLED : MF_BYCOMMAND|MF_GRAYED); -} - - -void -sb_menu_set_item(int part, int idm, int val) -{ - CheckMenuItem(sb_menu[part], idm, val ? MF_CHECKED : MF_UNCHECKED); -} - - -void -sb_set_icon(int part, int icon) -{ - HANDLE ptr; - - if (icon == -1) ptr = NULL; - else ptr = hIcon[(intptr_t)icon]; - - SendMessage(hwndSBAR, SB_SETICON, part, (LPARAM)ptr); -} - - -void -sb_set_text(int part, const wchar_t *str) -{ - SendMessage(hwndSBAR, SB_SETTEXT, part | SBT_NOBORDERS, (LPARAM)str); -} - - -void -sb_set_tooltip(int part, const wchar_t *str) -{ - SendMessage(hwndSBAR, SB_SETTIPTEXT, part, (LPARAM)str); -} diff --git a/src/win/win_ui.c b/src/win/win_ui.c index 0da8307..8eccfce 100644 --- a/src/win/win_ui.c +++ b/src/win/win_ui.c @@ -8,7 +8,7 @@ * * Implement the user Interface module. * - * Version: @(#)win_ui.c 1.0.16 2018/04/29 + * Version: @(#)win_ui.c 1.0.18 2018/05/03 * * Authors: Fred N. van Kempen, * Miran Grca, @@ -38,7 +38,9 @@ */ #define UNICODE #include +#include #include +#include #include #include #include @@ -58,13 +60,17 @@ #include "win_d3d.h" +#ifndef GWL_WNDPROC +# define GWL_WNDPROC GWLP_WNDPROC +#endif + + #define TIMER_1SEC 1 /* ID of the one-second timer */ /* Platform Public data, specific. */ -HWND hwndMain, /* application main window */ - hwndRender; /* machine render window */ -HMENU menuMain; /* application main menu */ +HWND hwndMain = NULL, /* application main window */ + hwndRender = NULL; /* machine render window */ HICON hIcon[512]; /* icon data loaded from resources */ RECT oldclip; /* mouse rect */ int infocus = 1; @@ -74,33 +80,156 @@ int infocus = 1; static wchar_t wTitle[512]; static RAWINPUTDEVICE device; static HHOOK hKeyboardHook; +static LONG_PTR OriginalProcedure; +static HWND hwndSBAR = NULL; /* application status bar */ +static HMENU menuMain = NULL, /* application menu bar */ + menuSBAR = NULL, /* status bar menu bar */ + *sb_menu = NULL; +static int sb_nparts; static int hook_enabled = 0; static int save_window_pos = 0; +static int cruft_x = 0, + cruft_y = 0, + cruft_sb = 0; -HICON -LoadIconEx(PCTSTR pszIconName) +static VOID APIENTRY +PopupMenu(HWND hwnd, POINT pt, int part) { - return((HICON)LoadImage(hinstance, pszIconName, IMAGE_ICON, - 16, 16, LR_SHARED)); + if (part >= (sb_nparts - 1)) return; + + pt.x = part * SB_ICON_WIDTH; /* justify to the left */ + pt.y = 1; /* justify to the top */ + + ClientToScreen(hwnd, (LPPOINT)&pt); + + TrackPopupMenu(sb_menu[part], + TPM_LEFTALIGN | TPM_BOTTOMALIGN | TPM_LEFTBUTTON, + pt.x, pt.y, 0, hwndSBAR, NULL); } -#if 0 -static void -menu_update(void) -{ - menuMain = LoadMenu(hinstance, L"MainMenu")); - - menuSBAR = LoadMenu(hinstance, L"StatusBarMenu"); - - initmenu(); - - SetMenu(memnuMain, menu); - - win_title_update = 1; -} +/* Handle messages for the Status Bar window. */ +#ifdef __amd64__ +static LRESULT CALLBACK +#else +static BOOL CALLBACK #endif +sb_dlg_proc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) +{ + RECT r; + POINT pt; + int idm, tag; + + switch (message) { + case WM_COMMAND: + idm = LOWORD(wParam) & 0xff00; /* low 8 bits */ + tag = LOWORD(wParam) & 0x00ff; /* high 8 bits */ + ui_sb_menu_command(idm, tag); + return(0); + + case WM_LBUTTONDOWN: + case WM_RBUTTONDOWN: + GetClientRect(hwnd, (LPRECT)&r); + pt.x = GET_X_LPARAM(lParam); + pt.y = GET_Y_LPARAM(lParam); + if (PtInRect((LPRECT)&r, pt)) + PopupMenu(hwnd, pt, (pt.x / SB_ICON_WIDTH)); + break; + + case WM_LBUTTONDBLCLK: + GetClientRect(hwnd, (LPRECT)&r); + pt.x = GET_X_LPARAM(lParam); + pt.y = GET_Y_LPARAM(lParam); + tag = (pt.x / SB_ICON_WIDTH); + if (PtInRect((LPRECT)&r, pt)) + ui_sb_click(tag); + break; + + default: + return(CallWindowProc((WNDPROC)OriginalProcedure, + hwnd, message, wParam, lParam)); + } + + return(0); +} + + +/* Create and set up the Status Bar window. */ +void +StatusBarCreate(uintptr_t id) +{ + int borders[3]; + intptr_t i; + int dw, dh; + RECT r; + + /* Load our icons into the cache for faster access. */ + for (i = 128; i < 130; i++) + hIcon[i] = LoadIconEx((PCTSTR)i); + for (i = 144; i < 146; i++) + hIcon[i] = LoadIconEx((PCTSTR)i); + for (i = 160; i < 162; i++) + hIcon[i] = LoadIconEx((PCTSTR)i); + for (i = 176; i < 178; i++) + hIcon[i] = LoadIconEx((PCTSTR)i); + for (i = 192; i < 194; i++) + hIcon[i] = LoadIconEx((PCTSTR)i); + for (i = 208; i < 210; i++) + hIcon[i] = LoadIconEx((PCTSTR)i); + for (i = 224; i < 226; i++) + hIcon[i] = LoadIconEx((PCTSTR)i); + for (i = 259; i < 260; i++) + hIcon[i] = LoadIconEx((PCTSTR)i); + for (i = 384; i < 386; i++) + hIcon[i] = LoadIconEx((PCTSTR)i); + for (i = 400; i < 402; i++) + hIcon[i] = LoadIconEx((PCTSTR)i); + for (i = 416; i < 418; i++) + hIcon[i] = LoadIconEx((PCTSTR)i); + for (i = 432; i < 434; i++) + hIcon[i] = LoadIconEx((PCTSTR)i); + for (i = 448; i < 450; i++) + hIcon[i] = LoadIconEx((PCTSTR)i); + + GetWindowRect(hwndMain, &r); + dw = r.right - r.left; + dh = r.bottom - r.top; + + /* Load the Common Controls DLL if needed. */ + InitCommonControls(); + + /* Create the window, and make sure it's using the STATUS class. */ + hwndSBAR = CreateWindow(STATUSCLASSNAME, + NULL, + SBARS_SIZEGRIP|WS_CHILD|WS_VISIBLE|SBT_TOOLTIPS, + 0, dh, + dw, SB_HEIGHT, + hwndMain, + (HMENU)id, + hInstance, + NULL); + + /* Retrieve the width of the border the status bar got. */ + memset(borders, 0x00, sizeof(borders)); + SendMessage(hwndSBAR, SB_GETBORDERS, 0, (LPARAM)borders); + if (borders[1] == 0) + borders[1] = 2; + cruft_sb = SB_HEIGHT + (2 * borders[1]) + (2 * SB_PADDING); + + /* Replace the original procedure with ours. */ + OriginalProcedure = GetWindowLongPtr(hwndSBAR, GWLP_WNDPROC); + SetWindowLongPtr(hwndSBAR, GWL_WNDPROC, (LONG_PTR)sb_dlg_proc); + + SendMessage(hwndSBAR, SB_SETMINHEIGHT, (WPARAM)SB_HEIGHT, (LPARAM)0); + + /* Load the dummy menu for this window. */ + menuSBAR = LoadMenu(hInstance, SB_MENU_NAME); + + /* Clear the menus, just in case.. */ + sb_nparts = 0; + sb_menu = NULL; +} static LRESULT CALLBACK @@ -139,9 +268,9 @@ LowLevelKeyboardProc(int nCode, WPARAM wParam, LPARAM lParam) static LRESULT CALLBACK MainWindowProcedure(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) { + DWORD flags; RECT rect; - int sb_borders[3]; - int temp_x, temp_y; + int x, y; int idm; switch (message) { @@ -164,34 +293,37 @@ MainWindowProcedure(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) break; case IDM_RESIZE: - GetWindowRect(hwnd, &rect); - if (vid_resize) - SetWindowLongPtr(hwnd, GWL_STYLE, (WS_OVERLAPPEDWINDOW) | WS_VISIBLE); - else - SetWindowLongPtr(hwnd, GWL_STYLE, (WS_OVERLAPPEDWINDOW & ~WS_SIZEBOX & ~WS_THICKFRAME & ~WS_MAXIMIZEBOX) | WS_VISIBLE); - - SendMessage(hwndSBAR, SB_GETBORDERS, 0, (LPARAM) sb_borders); + /* Set up for resizing if configured. */ + flags = WS_OVERLAPPEDWINDOW; + if (! vid_resize) + flags &= ~(WS_SIZEBOX | WS_THICKFRAME | + WS_MAXIMIZEBOX); + SetWindowLongPtr(hwnd, GWL_STYLE, flags); /* Main Window. */ + GetWindowRect(hwnd, &rect); MoveWindow(hwnd, rect.left, rect.top, - unscaled_size_x + (GetSystemMetrics(vid_resize ? SM_CXSIZEFRAME : SM_CXFIXEDFRAME) * 2), - unscaled_size_y + (GetSystemMetrics(SM_CYEDGE) * 2) + (GetSystemMetrics(vid_resize ? SM_CYSIZEFRAME : SM_CYFIXEDFRAME) * 2) + GetSystemMetrics(SM_CYMENUSIZE) + GetSystemMetrics(SM_CYCAPTION) + 17 + sb_borders[1] + 1, + unscaled_size_x + cruft_x, + unscaled_size_y + cruft_y + cruft_sb, TRUE); +#if 0 /* Render window. */ - MoveWindow(hwndRender, 0, 0, unscaled_size_x, unscaled_size_y, TRUE); - GetWindowRect(hwndRender, &rect); + MoveWindow(hwndRender, 0, 0, + unscaled_size_x, + unscaled_size_y, + TRUE); /* Status bar. */ + GetWindowRect(hwndRender, &rect); MoveWindow(hwndSBAR, - 0, rect.bottom + GetSystemMetrics(SM_CYEDGE), - unscaled_size_x, 17, TRUE); if (mouse_capture) { GetWindowRect(hwndRender, &rect); ClipCursor(&rect); } +#endif break; case IDM_REMEMBER: @@ -245,34 +377,38 @@ MainWindowProcedure(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) break; case WM_SIZE: - SendMessage(hwndSBAR, SB_GETBORDERS, 0, (LPARAM) sb_borders); + /* Note: this is the *client area* size!! */ + x = (lParam & 0xffff); + y = (lParam >> 16); + if (cruft_x == 0) { + /* Determine the window cruft. */ + cruft_x = (scrnsz_x - x); + cruft_y = (scrnsz_y - y); - temp_x = (lParam & 0xFFFF); - temp_y = (lParam >> 16) - (21 + sb_borders[1]); - if (temp_x < 1) - temp_x = 1; - if (temp_y < 1) - temp_y = 1; + /* Update window size with cruft. */ + x += cruft_x; + y += (cruft_y + cruft_sb); + } + y -= cruft_sb; - if ((temp_x != scrnsz_x) || (temp_y != scrnsz_y)) - doresize = 1; + /* Request a re-size if needed. */ + if ((x != scrnsz_x) || (y != scrnsz_y)) doresize = 1; - scrnsz_x = temp_x; - scrnsz_y = temp_y; + /* Set the new panel size. */ + scrnsz_x = x; + scrnsz_y = y; - MoveWindow(hwndRender, 0, 0, scrnsz_x, scrnsz_y, TRUE); + /* Update the render window. */ + if (hwndRender != NULL) + MoveWindow(hwndRender, 0, 0, scrnsz_x, scrnsz_y, TRUE); - GetWindowRect(hwndRender, &rect); - - /* Status bar. */ - MoveWindow(hwndSBAR, - 0, rect.bottom + GetSystemMetrics(SM_CYEDGE), - scrnsz_x, 17, TRUE); + /* Update the Status bar. */ + MoveWindow(hwndSBAR, 0, scrnsz_y, scrnsz_x, cruft_sb, TRUE); + /* Update the renderer if needed. */ plat_vidsize(scrnsz_x, scrnsz_y); - MoveWindow(hwndSBAR, 0, scrnsz_y + 6, scrnsz_x, 17, TRUE); - + /* Re-clip the mouse area if needed. */ if (mouse_capture) { GetWindowRect(hwndRender, &rect); @@ -280,7 +416,8 @@ MainWindowProcedure(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) } if (window_remember) { - GetWindowRect(hwnd, &rect); + GetWindowRect(hwndMain, &rect); + window_x = rect.left; window_y = rect.top; window_w = rect.right - rect.left; @@ -292,13 +429,16 @@ MainWindowProcedure(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) break; case WM_MOVE: - /* If window is not resizable, then tell the main thread to - resize it, as sometimes, moves can mess up the window size. */ - if (!vid_resize) + /* + * If window is not resizable, then tell the main thread * to resize it, as sometimes, moves can mess up the window + * size. + */ + if (! vid_resize) doresize = 1; if (window_remember) { - GetWindowRect(hwnd, &rect); + GetWindowRect(hwndMain, &rect); + window_x = rect.left; window_y = rect.top; window_w = rect.right - rect.left; @@ -308,9 +448,8 @@ MainWindowProcedure(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) break; case WM_TIMER: - if (wParam == TIMER_1SEC) { + if (wParam == TIMER_1SEC) pc_onesec(); - } break; case WM_RESETD3D: @@ -323,7 +462,9 @@ MainWindowProcedure(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) break; case WM_LEAVEFULLSCREEN: - /* pclog("leave full screen on window message\n"); */ +#if 0 + pclog("leave full screen on window message\n"); +#endif plat_setfullscreen(0); config_save(); break; @@ -366,10 +507,11 @@ MainWindowProcedure(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) return(DefWindowProc(hwnd, message, wParam, lParam)); } - return(0); + return(FALSE); } +/* Dummy window procedure, used by D3D when in full-screen mode. */ static LRESULT CALLBACK SubWindowProcedure(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) { @@ -383,8 +525,8 @@ ui_init(int nCmdShow) WCHAR title[200]; WNDCLASSEX wincl; /* buffer for main window's class */ MSG messages; /* received-messages buffer */ - HWND hwnd = 0; /* handle for our window */ HACCEL haccel; /* handle to accelerator table */ + DWORD flags; int ret; #if 0 @@ -395,10 +537,7 @@ ui_init(int nCmdShow) if (settings_only) { if (! pc_init_modules()) { /* Dang, no ROMs found at all! */ - MessageBox(hwnd, - plat_get_string(IDS_2056), - plat_get_string(IDS_2050), - MB_OK | MB_ICONERROR); + ui_msgbox(MBX_ERROR, (wchar_t *)IDS_2056); return(6); } @@ -408,13 +547,13 @@ ui_init(int nCmdShow) } /* Create our main window's class and register it. */ - wincl.hInstance = hinstance; + wincl.hInstance = hInstance; wincl.lpszClassName = CLASS_NAME; wincl.lpfnWndProc = MainWindowProcedure; wincl.style = CS_DBLCLKS; /* Catch double-clicks */ wincl.cbSize = sizeof(WNDCLASSEX); - wincl.hIcon = LoadIcon(hinstance, (LPCTSTR)100); - wincl.hIconSm = LoadIcon(hinstance, (LPCTSTR)100); + wincl.hIcon = LoadIcon(hInstance, (LPCTSTR)100); + wincl.hIconSm = LoadIcon(hInstance, (LPCTSTR)100); wincl.hCursor = NULL; wincl.lpszMenuName = NULL; wincl.cbClsExtra = 0; @@ -422,90 +561,78 @@ ui_init(int nCmdShow) wincl.hbrBackground = CreateSolidBrush(RGB(0,0,0)); if (! RegisterClassEx(&wincl)) return(2); - wincl.lpszClassName = SUB_CLASS_NAME; + + /* Register a class for the Fullscreen renderer window. */ + wincl.lpszClassName = FS_CLASS_NAME; wincl.lpfnWndProc = SubWindowProcedure; if (! RegisterClassEx(&wincl)) return(2); /* Load the Window Menu(s) from the resources. */ - menuMain = LoadMenu(hinstance, MENU_NAME); + menuMain = LoadMenu(hInstance, MENU_NAME); - /* Now create our main window. */ + /* Set up main window for resizing if configured. */ + flags = WS_OVERLAPPEDWINDOW; + if (! vid_resize) + flags &= ~(WS_SIZEBOX | WS_THICKFRAME | WS_MAXIMIZEBOX); + + /* + * Create our main window. + * + * We want our (initial) render panel to be a certain + * size (default 640x480), and we have no idea what + * our window decorations are, size-wise. + * + * Rather than depending on the GetSYstemMetrics API + * calls (which return incorrect data of Vista+), the + * simplest trick is to just set the desired window + * size, and create the window. The first WM_SIZE + * message will indicate the client size left after + * creating all the decorations, and the difference + * is the decoration overhead ('cruft') we need to + * always keep in mind when changing the window size. + */ wsprintf(title, L"%S", emu_version, sizeof_w(title)); - hwnd = CreateWindowEx ( - 0, /* no extended possibilites */ - CLASS_NAME, /* class name */ - title, /* Title Text */ - (WS_OVERLAPPEDWINDOW & ~WS_SIZEBOX) | DS_3DLOOK, - CW_USEDEFAULT, /* Windows decides the position */ - CW_USEDEFAULT, /* where window ends up on the screen */ - scrnsz_x+(GetSystemMetrics(SM_CXFIXEDFRAME)*2), /* width */ - scrnsz_y+(GetSystemMetrics(SM_CYFIXEDFRAME)*2)+GetSystemMetrics(SM_CYMENUSIZE)+GetSystemMetrics(SM_CYCAPTION)+1, /* and height in pixels */ - HWND_DESKTOP, /* window is a child to desktop */ - menuMain, /* menu */ - hinstance, /* Program Instance handler */ - NULL); /* no Window Creation data */ - hwndMain = hwnd; + hwndMain = CreateWindow( + CLASS_NAME, /* class name */ + title, /* Title Text */ + flags, /* style flags */ + CW_USEDEFAULT, CW_USEDEFAULT, /* no preset position */ + scrnsz_x, scrnsz_y, /* window size in pixels */ + HWND_DESKTOP, /* child of desktop */ + menuMain, /* menu */ + hInstance, /* Program Instance handler */ + NULL); /* no Window Creation data */ ui_window_title(title); - /* Set up main window for resizing if configured. */ - if (vid_resize) - SetWindowLongPtr(hwnd, GWL_STYLE, - (WS_OVERLAPPEDWINDOW)); - else - SetWindowLongPtr(hwnd, GWL_STYLE, - (WS_OVERLAPPEDWINDOW&~WS_SIZEBOX&~WS_THICKFRAME&~WS_MAXIMIZEBOX)); - /* Move to the last-saved position if needed. */ if (window_remember) - MoveWindow(hwnd, window_x, window_y, window_w, window_h, TRUE); + MoveWindow(hwndMain, window_x, window_y, window_w, window_h, FALSE); /* Reset all menus to their defaults. */ ui_menu_reset_all(); - /* Make the window visible on the screen. */ - ShowWindow(hwnd, nCmdShow); - /* Load the accelerator table */ - haccel = LoadAccelerators(hinstance, ACCEL_NAME); + haccel = LoadAccelerators(hInstance, ACCEL_NAME); if (haccel == NULL) { - MessageBox(hwndMain, - plat_get_string(IDS_2153), - plat_get_string(IDS_2050), - MB_OK | MB_ICONERROR); + ui_msgbox(MBX_CONFIG, (wchar_t *)IDS_2153); return(3); } - /* Initialize the input (keyboard, mouse, game) module. */ - device.usUsagePage = 0x01; - device.usUsage = 0x06; - device.dwFlags = RIDEV_NOHOTKEYS; - device.hwndTarget = hwnd; - if (! RegisterRawInputDevices(&device, 1, sizeof(device))) { - MessageBox(hwndMain, - plat_get_string(IDS_2154), - plat_get_string(IDS_2050), - MB_OK | MB_ICONERROR); - return(4); - } - keyboard_getkeymap(); - - /* Initialize the mouse module. */ - win_mouse_init(); - - /* Create the status bar window. */ - StatusBarCreate(hwndMain, IDC_STATUS, hinstance); - - /* - * Before we can create the Render window, we first have - * to prepare some other things that it depends on. - */ - ghMutex = CreateMutex(NULL, FALSE, L"VARCem.BlitMutex"); + /* Make the window visible on the screen. */ + ShowWindow(hwndMain, nCmdShow); /* Create the Machine Rendering window. */ - hwndRender = CreateWindow(L"STATIC", NULL, WS_CHILD|SS_BITMAP, - 0, 0, 1, 1, hwnd, NULL, hinstance, NULL); + hwndRender = CreateWindow(L"STATIC", + NULL, + WS_CHILD|SS_BITMAP, + 0, 0, + scrnsz_x, scrnsz_y, + hwndMain, + NULL, + hInstance, + NULL); /* That looks good, now continue setting up the machine. */ switch (pc_init_modules()) { @@ -531,10 +658,7 @@ ui_init(int nCmdShow) /* Initialize the configured Video API. */ if (! plat_setvid(vid_api)) { - MessageBox(hwnd, - plat_get_string(IDS_2095), - plat_get_string(IDS_2050), - MB_OK | MB_ICONERROR); + ui_msgbox(MBX_CONFIG, (wchar_t *)IDS_2095); return(5); } @@ -543,12 +667,25 @@ ui_init(int nCmdShow) plat_setfullscreen(1); /* Activate the render window, this will also set the screen size. */ - MoveWindow(hwndRender, 0, 0, scrnsz_x, scrnsz_y, TRUE); + if (hwndRender != NULL) + MoveWindow(hwndRender, 0, 0, scrnsz_x, scrnsz_y, TRUE); -#if 0 - /* Set up the current window size. */ - plat_resize(scrnsz_x, scrnsz_y); -#endif + /* Create the status bar window. */ + StatusBarCreate(IDC_STATBAR); + + /* Initialize the input (keyboard, mouse, game) module. */ + device.usUsagePage = 0x01; + device.usUsage = 0x06; + device.dwFlags = RIDEV_NOHOTKEYS; + device.hwndTarget = hwndMain; + if (! RegisterRawInputDevices(&device, 1, sizeof(device))) { + ui_msgbox(MBX_CONFIG, (wchar_t *)IDS_2154); + return(4); + } + keyboard_getkeymap(); + + /* Initialize the mouse module. */ + win_mouse_init(); /* Fire up the machine. */ pc_reset_hard(); @@ -562,7 +699,7 @@ ui_init(int nCmdShow) * real work, and we will hang in here, dealing with the * UI until we're done. */ - do_start(); + plat_start(); /* Run the message loop. It will run until GetMessage() returns 0 */ while (! quited) { @@ -578,7 +715,7 @@ ui_init(int nCmdShow) break; } - if (! TranslateAccelerator(hwnd, haccel, &messages)) { + if (! TranslateAccelerator(hwndMain, haccel, &messages)) { TranslateMessage(&messages); DispatchMessage(&messages); } @@ -601,10 +738,10 @@ ui_init(int nCmdShow) plat_mouse_capture(0); /* Close down the emulator. */ - do_stop(); + plat_stop(); - UnregisterClass(SUB_CLASS_NAME, hinstance); - UnregisterClass(CLASS_NAME, hinstance); + UnregisterClass(CLASS_NAME, hInstance); + UnregisterClass(FS_CLASS_NAME, hInstance); win_mouse_close(); @@ -612,6 +749,23 @@ ui_init(int nCmdShow) } +/* + * Re-load and reset all menus. + * + * We should have the language ID as a parameter. + */ +void +ui_menu_update(void) +{ + menuMain = LoadMenu(hInstance, MENU_NAME); + SetMenu(hwndMain, menuMain); + + menuSBAR = LoadMenu(hInstance, SB_MENU_NAME); + ui_menu_reset_all(); +} + + +/* Update the application's title bar. */ wchar_t * ui_window_title(wchar_t *s) { @@ -631,9 +785,9 @@ ui_window_title(wchar_t *s) } -/* Set host cursor visible or not. */ +/* Set cursor visible or not. */ void -show_cursor(int val) +ui_show_cursor(int val) { static int vis = -1; @@ -683,7 +837,6 @@ menu_set_radio_item(int idm, int num, int val) } -/* We should have the language ID as a parameter. */ void plat_pause(int p) { @@ -708,7 +861,7 @@ plat_pause(int p) dopause = p; - /* Update the actual menu. */ + /* Update the actual menu item. */ menu_set_item(IDM_PAUSE, dopause); } @@ -717,33 +870,17 @@ plat_pause(int p) void plat_resize(int x, int y) { - int sb_borders[3]; RECT r; -#if 0 -pclog("PLAT: VID[%d,%d] resizing to %dx%d\n", vid_fullscreen, vid_api, x, y); -#endif /* First, see if we should resize the UI window. */ - if (!vid_resize) { - video_wait_for_blit(); - SendMessage(hwndSBAR, SB_GETBORDERS, 0, (LPARAM) sb_borders); - GetWindowRect(hwndMain, &r); - MoveWindow(hwndRender, 0, 0, x, y, TRUE); + if (vid_resize) return; - GetWindowRect(hwndMain, &r); - MoveWindow(hwndMain, r.left, r.top, - x + (GetSystemMetrics(vid_resize ? SM_CXSIZEFRAME : SM_CXFIXEDFRAME) * 2), - y + (GetSystemMetrics(SM_CYEDGE) * 2) + (GetSystemMetrics(vid_resize ? SM_CYSIZEFRAME : SM_CYFIXEDFRAME) * 2) + GetSystemMetrics(SM_CYMENUSIZE) + GetSystemMetrics(SM_CYCAPTION) + 17 + sb_borders[1] + 1, - TRUE); - GetWindowRect(hwndMain, &r); + video_wait_for_blit(); - MoveWindow(hwndRender, 0, 0, x, y, TRUE); - - if (mouse_capture) { - GetWindowRect(hwndRender, &r); - ClipCursor(&r); - } - } + /* Re-position and re-size the main window. */ + GetWindowRect(hwndMain, &r); + MoveWindow(hwndMain, r.left, r.top, + x+cruft_x, y+cruft_y+cruft_sb, TRUE); } @@ -760,15 +897,113 @@ plat_mouse_capture(int on) GetClipCursor(&oldclip); GetWindowRect(hwndRender, &rect); ClipCursor(&rect); - /* pclog("mouse capture off, hide cursor\n"); */ - show_cursor(0); + + ui_show_cursor(0); + mouse_capture = 1; } else if (!on && mouse_capture) { /* Disable the in-app mouse. */ ClipCursor(&oldclip); - /* pclog("mouse capture on, show cursor\n"); */ - show_cursor(-1); + + ui_show_cursor(-1); mouse_capture = 0; } } + + +void +sb_setup(int parts, const int *widths) +{ + SendMessage(hwndSBAR, SB_SETPARTS, (WPARAM)parts, (LPARAM)widths); + + if (sb_menu != NULL) + sb_menu_destroy(); + + sb_menu = (HMENU *)malloc(parts * sizeof(HMENU)); + memset(sb_menu, 0x00, parts * sizeof(HMENU)); + + sb_nparts = parts; +} + + +void +sb_menu_destroy(void) +{ + int i; + + if (!sb_nparts || (sb_menu == NULL)) return; + + for (i = 0; i < sb_nparts; i++) { + if (sb_menu[i] != NULL) + DestroyMenu(sb_menu[i]); + } + + free(sb_menu); + + sb_menu = NULL; +} + + +/* Create a menu for a status bar part. */ +void +sb_menu_create(int part) +{ + HMENU h; + + h = CreatePopupMenu(); + + sb_menu[part] = h; +} + + +/* Add an item to a (status bar) menu. */ +void +sb_menu_add_item(int part, int idm, const wchar_t *str) +{ + if (idm >= 0) + AppendMenu(sb_menu[part], MF_STRING, idm, str); + else + AppendMenu(sb_menu[part], MF_SEPARATOR, 0, NULL); +} + + +void +sb_menu_enable_item(int part, int idm, int val) +{ + EnableMenuItem(sb_menu[part], idm, + val ? MF_BYCOMMAND|MF_ENABLED : MF_BYCOMMAND|MF_GRAYED); +} + + +void +sb_menu_set_item(int part, int idm, int val) +{ + CheckMenuItem(sb_menu[part], idm, val ? MF_CHECKED : MF_UNCHECKED); +} + + +void +sb_set_icon(int part, int icon) +{ + HANDLE ptr; + + if (icon == -1) ptr = NULL; + else ptr = hIcon[(intptr_t)icon]; + + SendMessage(hwndSBAR, SB_SETICON, part, (LPARAM)ptr); +} + + +void +sb_set_text(int part, const wchar_t *str) +{ + SendMessage(hwndSBAR, SB_SETTEXT, part | SBT_NOBORDERS, (LPARAM)str); +} + + +void +sb_set_tooltip(int part, const wchar_t *str) +{ + SendMessage(hwndSBAR, SB_SETTIPTEXT, part, (LPARAM)str); +}