diff --git a/src/Makefile.mingw b/src/Makefile.mingw index 81c6e97f0..0e1f4ab17 100644 --- a/src/Makefile.mingw +++ b/src/Makefile.mingw @@ -6,9 +6,9 @@ # # This file is part of the 86Box distribution. # -# Modified Makefile for Win32 (MinGW32) environment. +# Makefile for Win32 (MinGW32) environment. # -# Version: @(#)Makefile.mingw 1.0.60 2017/10/14 +# Version: @(#)Makefile.mingw 1.0.61 2017/10/14 # # Authors: Miran Grca, # Fred N. van Kempen, @@ -404,10 +404,13 @@ LIBS := -mwindows \ -lddraw -ldinput8 -ldxguid -ld3d9 -ld3dx9 \ -lcomctl32 -lwinmm ifeq ($(VNC), y) -LIBS += $(VNCLIB) -lws2_32 -lz -lpthread +LIBS += $(VNCLIB) -lws2_32 -lz +endif +ifeq ($(RDP), y) +LIBS += $(RDPLIB) endif LIBS += -lkernel32 -lwsock32 -liphlpapi -lpsapi -LIBS += -static -lstdc++ -lgcc +LIBS += -lpthread -static -lstdc++ -lgcc LIBS += -Wl,--large-address-aware diff --git a/src/config.c b/src/config.c index 2be964650..3ba7b842e 100644 --- a/src/config.c +++ b/src/config.c @@ -8,7 +8,7 @@ * * Configuration file handler. * - * Version: @(#)config.c 1.0.20 2017/10/13 + * Version: @(#)config.c 1.0.21 2017/10/13 * * Authors: Sarah Walker, * Miran Grca, @@ -1990,24 +1990,6 @@ config_set_wstring(char *head, char *name, wchar_t *val) } -#if 0 -/* FIXME: should be moved elsewhere. --FvK */ -char * -get_filename(char *s) -{ - int c = strlen(s) - 1; - - while (c > 0) { - if (s[c] == '/' || s[c] == '\\') - return(&s[c+1]); - c--; - } - - return(s); -} -#endif - - /* FIXME: should be moved elsewhere. --FvK */ wchar_t * get_filename_w(wchar_t *s) @@ -2024,16 +2006,6 @@ get_filename_w(wchar_t *s) } -#if 0 -/* FIXME: should be moved elsewhere. --FvK */ -void -append_filename(char *dest, char *s1, char *s2, int size) -{ - sprintf(dest, "%s%s", s1, s2); -} -#endif - - /* FIXME: should be moved elsewhere. --FvK */ void append_filename_w(wchar_t *dest, wchar_t *s1, wchar_t *s2, int size) @@ -2043,19 +2015,6 @@ append_filename_w(wchar_t *dest, wchar_t *s1, wchar_t *s2, int size) } -#if 0 -/* FIXME: should be moved elsewhere. --FvK */ -void -put_backslash(char *s) -{ - int c = strlen(s) - 1; - - if (s[c] != '/' && s[c] != '\\') - s[c] = '/'; -} -#endif - - /* FIXME: should be moved elsewhere. --FvK */ void put_backslash_w(wchar_t *s) @@ -2067,27 +2026,6 @@ put_backslash_w(wchar_t *s) } -#if 0 -/* FIXME: should be moved elsewhere. --FvK */ -char * -get_extension(char *s) -{ - int c = strlen(s) - 1; - - if (c <= 0) - return(s); - - while (c && s[c] != '.') - c--; - - if (!c) - return(&s[strlen(s)]); - - return(&s[c+1]); -} -#endif - - /* FIXME: should be moved elsewhere. --FvK */ wchar_t *get_extension_w(wchar_t *s) diff --git a/src/config.h b/src/config.h index 84bccc1e9..bca7591d2 100644 --- a/src/config.h +++ b/src/config.h @@ -8,12 +8,13 @@ * * Configuration file handler header. * - * Version: @(#)config.h 1.0.2 2017/09/19 + * Version: @(#)config.h 1.0.3 2017/10/13 * * Authors: Sarah Walker, * Miran Grca, * Fred N. van Kempen, * Overdoze, + * * Copyright 2008-2017 Sarah Walker. * Copyright 2016,2017 Miran Grca. * Copyright 2017 Fred N. van Kempen. @@ -48,13 +49,9 @@ extern void config_set_mac(char *head, char *name, int val); extern void config_set_string(char *head, char *name, char *val); extern void config_set_wstring(char *head, char *name, wchar_t *val); -extern char *get_filename(char *s); extern wchar_t *get_filename_w(wchar_t *s); -extern void append_filename(char *dest, char *s1, char *s2, int size); extern void append_filename_w(wchar_t *dest, wchar_t *s1, wchar_t *s2, int size); -extern void put_backslash(char *s); extern void put_backslash_w(wchar_t *s); -extern char *get_extension(char *s); extern wchar_t *get_extension_w(wchar_t *s); diff --git a/src/floppy/fdi2raw.c b/src/floppy/fdi2raw.c index 84009b87a..84e2c7388 100644 --- a/src/floppy/fdi2raw.c +++ b/src/floppy/fdi2raw.c @@ -1608,7 +1608,7 @@ static void fdi2_decode (FDI *fdi, uint32_t totalavg, uae_u32 *avgp, uae_u32 *mi randval = rand(); if (randval < (RAND_MAX / 2)) { if (randval > (RAND_MAX / 4)) { - if (randval <= (3 * RAND_MAX / 8)) + if (randval <= (((3LL*RAND_MAX) / 8))) randval = (2 * randval) - (RAND_MAX /4); else randval = (4 * randval) - RAND_MAX; @@ -1617,7 +1617,7 @@ static void fdi2_decode (FDI *fdi, uint32_t totalavg, uae_u32 *avgp, uae_u32 *mi } else { randval -= RAND_MAX / 2; if (randval > (RAND_MAX / 4)) { - if (randval <= (3 * RAND_MAX / 8)) + if (randval <= (((3LL*RAND_MAX) / 8))) randval = (2 * randval) - (RAND_MAX /4); else randval = (4 * randval) - RAND_MAX; @@ -1643,7 +1643,7 @@ static void fdi2_decode (FDI *fdi, uint32_t totalavg, uae_u32 *avgp, uae_u32 *mi randval = rand(); if (randval < (RAND_MAX / 2)) { if (randval > (RAND_MAX / 4)) { - if (randval <= (3 * RAND_MAX / 8)) + if (randval <= (((3LL*RAND_MAX) / 8))) randval = (2 * randval) - (RAND_MAX /4); else randval = (4 * randval) - RAND_MAX; @@ -1652,7 +1652,7 @@ static void fdi2_decode (FDI *fdi, uint32_t totalavg, uae_u32 *avgp, uae_u32 *mi } else { randval -= RAND_MAX / 2; if (randval > (RAND_MAX / 4)) { - if (randval <= (3 * RAND_MAX / 8)) + if (randval <= (((3LL*RAND_MAX) / 8))) randval = (2 * randval) - (RAND_MAX /4); else randval = (4 * randval) - RAND_MAX; diff --git a/src/pc.c b/src/pc.c index 4adf9fd49..1e6a69bf3 100644 --- a/src/pc.c +++ b/src/pc.c @@ -8,7 +8,7 @@ * * Emulation core dispatcher. * - * Version: @(#)pc.c 1.0.24 2017/10/12 + * Version: @(#)pc.c 1.0.25 2017/10/14 * * Authors: Sarah Walker, * Miran Grca, @@ -214,7 +214,7 @@ usage: printf("-D or --dump - dump memory on exit\n"); printf("-F or --fullscreen - start in fullscreen mode\n"); printf("-P or --vmpath path - set 'path' to be root for vm\n"); - printf("\nA config file can be specified. If none ie, the default file will be used.\n"); + printf("\nA config file can be specified. If none is, the default file will be used.\n"); return(0); } else if (!wcscasecmp(argv[c], L"--dump") || !wcscasecmp(argv[c], L"-D")) { @@ -678,7 +678,7 @@ pollmouse(void) void pc_run(void) { - wchar_t s[200]; + wchar_t temp[200]; int done = 0; startblit(); @@ -753,11 +753,11 @@ pc_run(void) mbstowcs(wmachine, machine_getname(), strlen(machine_getname())+1); mbstowcs(wcpu, machines[machine].cpu[cpu_manufacturer].cpus[cpu].name, strlen(machines[machine].cpu[cpu_manufacturer].cpus[cpu].name)+1); - swprintf(s, 200, L"%ls v%ls - %i%% - %ls - %ls - %ls", + swprintf(temp, sizeof_w(temp), L"%ls v%ls - %i%% - %ls - %ls - %ls", EMU_NAME_W, EMU_VERSION_W, fps, wmachine, wcpu, (!mousecapture) ? plat_get_string(IDS_2077) : ((mouse_get_type(mouse_type) & MOUSE_TYPE_3BUTTON) ? plat_get_string(IDS_2078) : plat_get_string(IDS_2079))); - set_window_title(s); + set_window_title(temp); win_title_update = 0; } diff --git a/src/sound/snd_sb_dsp.c b/src/sound/snd_sb_dsp.c index 9acff4646..c142065c8 100644 --- a/src/sound/snd_sb_dsp.c +++ b/src/sound/snd_sb_dsp.c @@ -7,6 +7,8 @@ #include #include #include +#include +#include #include "../ibm.h" #include "../io.h" #include "../pic.h" diff --git a/src/video/vid_cga.c b/src/video/vid_cga.c index d63e9c0e6..384a0a5c5 100644 --- a/src/video/vid_cga.c +++ b/src/video/vid_cga.c @@ -8,7 +8,7 @@ * * Emulation of the old and new IBM CGA graphics cards. * - * Version: @(#)vid_cga.c 1.0.4 2017/10/10 + * Version: @(#)vid_cga.c 1.0.5 2017/10/13 * * Authors: Sarah Walker, * Miran Grca, @@ -74,13 +74,13 @@ void cga_out(uint16_t addr, uint8_t val, void *p) cga->cgamode = val; update_cga16_color(cga->cgamode); } -#ifndef __unix + if ((cga->cgamode ^ val) & 1) { cga_palette = (cga->rgb_type << 1); cgapal_rebuild(); } -#endif + cga->cgamode = val; return; case 0x3D9: @@ -478,7 +478,7 @@ void *cga_standalone_init(device_t *info) cga->snow_enabled = device_get_config_int("snow_enabled"); cga->vram = malloc(0x4000); - + cga_comp_init(cga->revision); timer_add(cga_poll, &cga->vidtime, TIMER_ALWAYS_ENABLED, cga); mem_mapping_add(&cga->mapping, 0xb8000, 0x08000, cga_read, NULL, NULL, cga_write, NULL, NULL, NULL, MEM_MAPPING_EXTERNAL, cga); @@ -486,12 +486,10 @@ void *cga_standalone_init(device_t *info) overscan_x = overscan_y = 16; -#ifndef __unix cga->rgb_type = device_get_config_int("rgb_type"); cga_palette = (cga->rgb_type << 1); cgapal_rebuild(); -#endif - + return cga; } @@ -506,7 +504,7 @@ void cga_close(void *p) void cga_speed_changed(void *p) { cga_t *cga = (cga_t *)p; - + cga_recalctimings(cga); } @@ -540,7 +538,6 @@ static device_config_t cga_config[] = } } }, -#ifndef __unix { "rgb_type", "RGB type", CONFIG_SELECTION, "", 0, { @@ -564,7 +561,6 @@ static device_config_t cga_config[] = } } }, -#endif { "snow_enabled", "Snow emulation", CONFIG_BINARY, "", 1 }, diff --git a/src/video/vid_cga.h b/src/video/vid_cga.h index 80dd1bad8..4ef61c4e2 100644 --- a/src/video/vid_cga.h +++ b/src/video/vid_cga.h @@ -49,9 +49,7 @@ typedef struct cga_t int revision; int composite; int snow_enabled; -#ifndef __unix int rgb_type; -#endif } cga_t; void cga_init(cga_t *cga); diff --git a/src/video/vid_hercules.c b/src/video/vid_hercules.c index ad1dfafb4..0329c9b7a 100644 --- a/src/video/vid_hercules.c +++ b/src/video/vid_hercules.c @@ -8,7 +8,7 @@ * * Hercules emulation. * - * Version: @(#)vid_hercules.c 1.0.1 2017/10/10 + * Version: @(#)vid_hercules.c 1.0.2 2017/10/13 * * Authors: Sarah Walker, * Miran Grca, @@ -362,14 +362,12 @@ void *hercules_init(device_t *info) overscan_x = overscan_y = 0; -#ifndef __unix cga_palette = device_get_config_int("rgb_type") << 1; if (cga_palette > 6) { cga_palette = 0; } cgapal_rebuild(); -#endif return hercules; } @@ -389,7 +387,6 @@ void hercules_speed_changed(void *p) hercules_recalctimings(hercules); } -#ifndef __unix static device_config_t hercules_config[] = { { @@ -416,7 +413,6 @@ static device_config_t hercules_config[] = "", "", -1 } }; -#endif device_t hercules_device = { @@ -429,9 +425,5 @@ device_t hercules_device = hercules_speed_changed, NULL, NULL, -#ifdef __unix - NULL -#else hercules_config -#endif }; diff --git a/src/video/vid_mda.c b/src/video/vid_mda.c index e456da414..942425cda 100644 --- a/src/video/vid_mda.c +++ b/src/video/vid_mda.c @@ -8,7 +8,7 @@ * * MDA emulation. * - * Version: @(#)vid_mda.c 1.0.1 2017/10/10 + * Version: @(#)vid_mda.c 1.0.2 2017/10/13 * * Authors: Sarah Walker, * Miran Grca, @@ -311,14 +311,12 @@ void *mda_init(device_t *info) overscan_x = overscan_y = 0; -#ifndef __unix cga_palette = device_get_config_int("rgb_type") << 1; if (cga_palette > 6) { cga_palette = 0; } cgapal_rebuild(); -#endif return mda; } @@ -338,7 +336,6 @@ void mda_speed_changed(void *p) mda_recalctimings(mda); } -#ifndef __unix static device_config_t mda_config[] = { { @@ -365,7 +362,6 @@ static device_config_t mda_config[] = "", "", -1 } }; -#endif device_t mda_device = { @@ -378,9 +374,5 @@ device_t mda_device = mda_speed_changed, NULL, NULL, -#ifdef __unix - NULL -#else mda_config -#endif }; diff --git a/src/video/video.c b/src/video/video.c index faf0e2378..bf745f7b7 100644 --- a/src/video/video.c +++ b/src/video/video.c @@ -40,7 +40,7 @@ * W = 3 bus clocks * L = 4 bus clocks * - * Version: @(#)video.c 1.0.1 2017/10/10 + * Version: @(#)video.c 1.0.2 2017/10/13 * * Authors: Sarah Walker, * Miran Grca, @@ -196,8 +196,8 @@ static struct { } blit_data; -void (*video_blit_memtoscreen_func)(int x, int y, int y1, int y2, int w, int h); -void (*video_blit_memtoscreen_8_func)(int x, int y, int w, int h); +static void (*memtoscreen_func)(int x, int y, int y1, int y2, int w, int h); +static void (*memtoscreen_8_func)(int x, int y, int w, int h); static @@ -208,9 +208,9 @@ void blit_thread(void *param) thread_reset_event(blit_data.wake_blit_thread); if (blit_data.blit8) - video_blit_memtoscreen_8_func(blit_data.x, blit_data.y, blit_data.w, blit_data.h); + memtoscreen_8_func(blit_data.x, blit_data.y, blit_data.w, blit_data.h); else - video_blit_memtoscreen_func(blit_data.x, blit_data.y, blit_data.y1, blit_data.y2, blit_data.w, blit_data.h); + memtoscreen_func(blit_data.x, blit_data.y, blit_data.y1, blit_data.y2, blit_data.w, blit_data.h); blit_data.busy = 0; thread_set_event(blit_data.blit_complete); @@ -218,6 +218,14 @@ void blit_thread(void *param) } +void +video_setblit(void(*blit8)(int,int,int,int),void(*blit)(int,int,int,int,int,int)) +{ + memtoscreen_func = blit; + memtoscreen_8_func = blit8; +} + + void video_blit_complete(void) { @@ -556,10 +564,8 @@ video_reset(void) { pclog("Video_reset(rom=%i, gfx=%i)\n", romset, gfxcard); -#ifndef __unix cga_palette = 0; cgapal_rebuild(); -#endif /* * Add and initialize the selected video card device. diff --git a/src/video/video.h b/src/video/video.h index ebec35101..1aaf09e84 100644 --- a/src/video/video.h +++ b/src/video/video.h @@ -76,8 +76,6 @@ extern "C" { /* Function handler pointers. */ extern void (*video_recalctimings)(void); -extern void (*video_blit_memtoscreen_func)(int x, int y, int y1, int y2, int w, int h); -extern void (*video_blit_memtoscreen_8_func)(int x, int y, int w, int h); /* Table functions. */ @@ -94,8 +92,11 @@ extern char *video_get_internal_name(int card); extern int video_get_video_from_internal_name(char *s); +extern void video_setblit(void(*blit8)(int,int,int,int), + void(*blit)(int,int,int,int,int,int)); extern void video_blit_memtoscreen(int x, int y, int y1, int y2, int w, int h); extern void video_blit_memtoscreen_8(int x, int y, int w, int h); +extern void video_blit_complete(void); extern void video_wait_for_blit(void); extern void video_wait_for_buffer(void); diff --git a/src/win/win_d3d.cc b/src/win/win_d3d.cc index 78ffb6fc9..91f6897cb 100644 --- a/src/win/win_d3d.cc +++ b/src/win/win_d3d.cc @@ -8,7 +8,7 @@ * * Direct3D 9 rendererer and screenshots taking. * - * Version: @(#)win_d3d.cc 1.0.3 2017/10/13 + * Version: @(#)win_d3d.cc 1.0.4 2017/10/13 * * Authors: Sarah Walker, * Miran Grca, @@ -26,14 +26,14 @@ extern "C" void fatal(const char *format, ...); extern "C" void pclog(const char *format, ...); extern "C" void device_force_redraw(void); -extern "C" void video_blit_complete(void); extern "C" void d3d_take_screenshot(wchar_t *fn); void d3d_init_objects(void); void d3d_close_objects(void); -void d3d_blit_memtoscreen(int x, int y, int y1, int y2, int w, int h); -void d3d_blit_memtoscreen_8(int x, int y, int w, int h); + +static void blit_memtoscreen(int x, int y, int y1, int y2, int w, int h); +static void blit_memtoscreen_8(int x, int y, int w, int h); static LPDIRECT3D9 d3d = NULL; static LPDIRECT3DDEVICE9 d3ddev = NULL; @@ -101,12 +101,7 @@ int d3d_init(HWND h) d3d_init_objects(); -#if 0 - video_setblit(d3d_blit_memtoscreen_8, d3d_blit_memtoscreen); -#else - video_blit_memtoscreen_func = d3d_blit_memtoscreen; - video_blit_memtoscreen_8_func = d3d_blit_memtoscreen_8; -#endif + video_setblit(blit_memtoscreen_8, blit_memtoscreen); return 1; } @@ -238,7 +233,7 @@ int d3d_pause(void) return(0); } -void d3d_blit_memtoscreen(int x, int y, int y1, int y2, int w, int h) +static void blit_memtoscreen(int x, int y, int y1, int y2, int w, int h) { HRESULT hr = D3D_OK; VOID* pVoid; @@ -332,7 +327,7 @@ void d3d_blit_memtoscreen(int x, int y, int y1, int y2, int w, int h) PostMessage(d3d_hwnd, WM_RESETD3D, 0, 0); } -void d3d_blit_memtoscreen_8(int x, int y, int w, int h) +static void blit_memtoscreen_8(int x, int y, int w, int h) { VOID* pVoid; D3DLOCKED_RECT dr; diff --git a/src/win/win_d3d_fs.cc b/src/win/win_d3d_fs.cc index 11612d75d..7e10b4fc5 100644 --- a/src/win/win_d3d_fs.cc +++ b/src/win/win_d3d_fs.cc @@ -8,7 +8,7 @@ * * Direct3D 9 full-screen rendererer. * - * Version: @(#)win_d3d_fs.cc 1.0.5 2017/10/13 + * Version: @(#)win_d3d_fs.cc 1.0.6 2017/10/13 * * Authors: Sarah Walker, * Miran Grca, @@ -35,8 +35,8 @@ extern "C" void d3d_fs_take_screenshot(wchar_t *fn); static void d3d_fs_init_objects(void); static void d3d_fs_close_objects(void); -static void d3d_fs_blit_memtoscreen(int x, int y, int y1, int y2, int w, int h); -static void d3d_fs_blit_memtoscreen_8(int x, int y, int w, int h); +static void blit_memtoscreen(int x, int y, int y1, int y2, int w, int h); +static void blit_memtoscreen_8(int x, int y, int w, int h); static LPDIRECT3D9 d3d = NULL; @@ -130,12 +130,7 @@ int d3d_fs_init(HWND h) d3d_fs_init_objects(); -#if 0 - video_setblit(d3d_fs_blit_memtoscreen_8, d3d_fs_blit_memtoscreen); -#else - video_blit_memtoscreen_func = d3d_fs_blit_memtoscreen; - video_blit_memtoscreen_8_func = d3d_fs_blit_memtoscreen_8; -#endif + video_setblit(blit_memtoscreen_8, blit_memtoscreen); return 1; } @@ -309,7 +304,7 @@ static void d3d_fs_size(RECT window_rect, double *l, double *t, double *r, doubl } } -static void d3d_fs_blit_memtoscreen(int x, int y, int y1, int y2, int w, int h) +static void blit_memtoscreen(int x, int y, int y1, int y2, int w, int h) { HRESULT hr = D3D_OK; VOID* pVoid; @@ -421,7 +416,7 @@ static void d3d_fs_blit_memtoscreen(int x, int y, int y1, int y2, int w, int h) PostMessage(hwndMain, WM_RESETD3D, 0, 0); } -static void d3d_fs_blit_memtoscreen_8(int x, int y, int w, int h) +static void blit_memtoscreen_8(int x, int y, int w, int h) { HRESULT hr = D3D_OK; VOID* pVoid; diff --git a/src/win/win_ddraw.cc b/src/win/win_ddraw.cc index 9c1cffb9d..ce02b4fa4 100644 --- a/src/win/win_ddraw.cc +++ b/src/win/win_ddraw.cc @@ -24,8 +24,6 @@ extern "C" int ddraw_pause(void); extern "C" void ddraw_close(void); extern "C" void ddraw_take_screenshot(wchar_t *fn); -extern "C" void video_blit_complete(void); - static LPDIRECTDRAW lpdd = NULL; static LPDIRECTDRAW7 lpdd7 = NULL; @@ -169,7 +167,7 @@ ddraw_common_take_screenshot(wchar_t *fn, IDirectDrawSurface7 *pDDSurface) static void -ddraw_blit_memtoscreen(int x, int y, int y1, int y2, int w, int h) +blit_memtoscreen(int x, int y, int y1, int y2, int w, int h) { RECT r_src; RECT r_dest; @@ -239,7 +237,7 @@ ddraw_blit_memtoscreen(int x, int y, int y1, int y2, int w, int h) static void -ddraw_blit_memtoscreen_8(int x, int y, int w, int h) +blit_memtoscreen_8(int x, int y, int w, int h) { RECT r_src; RECT r_dest; @@ -363,12 +361,7 @@ ddraw_init(HWND h) ddraw_hwnd = h; -#if 0 - video_setblit(ddraw_blit_memtoscreen_8, ddraw_blit_memtoscreen); -#else - video_blit_memtoscreen_func = ddraw_blit_memtoscreen; - video_blit_memtoscreen_8_func = ddraw_blit_memtoscreen_8; -#endif + video_setblit(blit_memtoscreen_8, blit_memtoscreen); return(1); } diff --git a/src/win/win_ddraw_fs.cc b/src/win/win_ddraw_fs.cc index 31c7ca584..5604def7b 100644 --- a/src/win/win_ddraw_fs.cc +++ b/src/win/win_ddraw_fs.cc @@ -29,11 +29,9 @@ extern "C" void ddraw_fs_take_screenshot(wchar_t *fn); extern void ddraw_common_take_screenshot(wchar_t *fn, IDirectDrawSurface7 *pDDSurface); -extern "C" void video_blit_complete(void); - -static void ddraw_fs_blit_memtoscreen(int, int, int, int, int, int); -static void ddraw_fs_blit_memtoscreen_8(int, int, int, int); +static void blit_memtoscreen(int, int, int, int, int, int); +static void blit_memtoscreen_8(int, int, int, int); int ddraw_fs_init(HWND h) @@ -93,12 +91,8 @@ int ddraw_fs_init(HWND h) pclog("DDRAW_INIT complete\n"); ddraw_hwnd = h; -#if 0 - video_setblit(ddraw_fs_blit_memtoscreen_8, ddraw_fs_blit_memtoscreen); -#else - video_blit_memtoscreen_func = ddraw_fs_blit_memtoscreen; - video_blit_memtoscreen_8_func = ddraw_fs_blit_memtoscreen_8; -#endif + + video_setblit(blit_memtoscreen_8, blit_memtoscreen); return 1; } @@ -182,7 +176,7 @@ static void ddraw_fs_size(RECT window_rect, RECT *r_dest, int w, int h) } } -static void ddraw_fs_blit_memtoscreen(int x, int y, int y1, int y2, int w, int h) +static void blit_memtoscreen(int x, int y, int y1, int y2, int w, int h) { RECT r_src; RECT r_dest; @@ -250,7 +244,7 @@ static void ddraw_fs_blit_memtoscreen(int x, int y, int y1, int y2, int w, int h } } -static void ddraw_fs_blit_memtoscreen_8(int x, int y, int w, int h) +static void blit_memtoscreen_8(int x, int y, int w, int h) { RECT r_src; RECT r_dest; diff --git a/src/win/win_vnc.c b/src/win/win_vnc.c new file mode 100644 index 000000000..8f4048ee6 --- /dev/null +++ b/src/win/win_vnc.c @@ -0,0 +1,315 @@ +/* + * 86Box A hypervisor and IBM PC system emulator that specializes in + * running old operating systems and software designed for IBM + * PC systems and compatibles from 1981 through fairly recent + * system designs based on the PCI bus. + * + * This file is part of the 86Box distribution. + * + * Implement the VNC renderer. + * + * Version: @(#)win_vnc.c 1.0.2 2017/10/13 + * + * Authors: RichardG, + * Fred N. van Kempen, + * + * Copyright 2017 Fred N. van Kempen. + */ +#include +#include +#include "../ibm.h" +#include "../device.h" +#include "../video/video.h" +#include "../plat.h" +#include "../plat_keyboard.h" +#include "../ui.h" +#define BITMAP MY_BITMAP +#include +#undef BITMAP +#include "win.h" +#include "win_vnc.h" + + +extern void video_blit_complete(void); + + +static rfbScreenInfoPtr rfbScreen; +static int vnc_clients; +static int updatingSize; +static int allowedX, + allowedY; + +static int keysyms_00[] = { + 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, // 00-07 + 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, // 08-0f + 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, // 10-17 + 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, // 18-1f + 0x0039, 0x2a02, 0x2a28, 0x2a04, 0x2a05, 0x2a06, 0x2a08, 0x0028, // 20-27 + 0x2a0a, 0x2a0b, 0x2a09, 0x2a0d, 0x0033, 0x000c, 0x0034, 0x0035, // 28-2f + 0x000b, 0x0002, 0x0003, 0x0004, 0x0005, 0x0006, 0x0007, 0x0008, // 30-37 + 0x0009, 0x000a, 0x2a27, 0x0027, 0x2a33, 0x000d, 0x2a34, 0x2a35, // 38-3f + 0x2a03, 0x2a1e, 0x2a30, 0x2a2e, 0x2a20, 0x2a12, 0x2a21, 0x2a22, // 40-47 + 0x2a23, 0x2a17, 0x2a24, 0x2a25, 0x2a26, 0x2a32, 0x2a31, 0x2a18, // 48-4f + 0x2a19, 0x2a10, 0x2a13, 0x2a1f, 0x2a14, 0x2a16, 0x2a2f, 0x2a11, // 50-57 + 0x2a2d, 0x2a15, 0x2a2c, 0x001a, 0x0000, 0x001b, 0x2a07, 0x2a0c, // 58-5f + 0x0029, 0x001e, 0x0030, 0x002e, 0x0020, 0x0012, 0x0021, 0x0022, // 60-67 + 0x0023, 0x0017, 0x0024, 0x0025, 0x0026, 0x0032, 0x0031, 0x0018, // 68-6f + 0x0019, 0x0010, 0x0013, 0x001f, 0x0014, 0x0016, 0x002f, 0x0011, // 70-77 + 0x002d, 0x0015, 0x002c, 0x2a1a, 0x0000, 0x2a1b, 0x2a29, 0x0000, // 78-7f + 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, // 80-87 + 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, // 88-8f + 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, // 90-97 + 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, // 98-9f + 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, // a0-a7 + 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, // a8-af + 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, // b0-b7 + 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, // b8-bf + 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, // c0-c7 + 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, // c8-cf + 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, // d0-d7 + 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, // d8-df + 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, // e0-e7 + 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, // e8-ef + 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, // f0-f7 + 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000 // f8-ff +}; + +static int keysyms_ff[] = { + 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, // 00-07 + 0x000e, 0x000f, 0x0000, 0x004c, 0x0000, 0x001c, 0x0000, 0x0000, // 08-0f + 0x0000, 0x0000, 0x0000, 0xff45, 0x0000, 0x0000, 0x0000, 0x0000, // 10-17 + 0x0000, 0x0000, 0x0000, 0x0001, 0x0000, 0x0000, 0x0000, 0x0000, // 18-1f + 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, // 20-27 + 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, // 28-2f + 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, // 30-37 + 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, // 38-3f + 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, // 40-47 + 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, // 48-4f + 0x0047, 0x00cb, 0xaac8, 0x00cd, 0x00d0, 0x0049, 0x0051, 0x004f, // 50-57 + 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, // 58-5f + 0x0000, 0x0000, 0x0000, 0x0052, 0x0000, 0x0000, 0x0000, 0x00dd, // 60-67 + 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, // 68-6f + 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, // 70-77 + 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, // 78-7f + 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, // 80-87 + 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x009c, 0x0000, 0x0000, // 88-8f + 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, // 90-97 + 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, // 98-9f + 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, // a0-a7 + 0x0000, 0x0000, 0x0037, 0x004e, 0x0000, 0x004a, 0x0000, 0x00b5, // a8-af + 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, // b0-b7 + 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x003b, 0x003c, // b8-bf + 0x003d, 0x003e, 0x003f, 0x0040, 0x0041, 0x0042, 0x0043, 0x0044, // c0-c7 + 0x0057, 0x0058, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, // c8-cf + 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, // d0-d7 + 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, // d8-df + 0x0000, 0x0036, 0x0000, 0x001d, 0x009d, 0x0000, 0x0000, 0x0000, // e0-e7 + 0x0000, 0x0038, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, // e8-ef + 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, // f0-f7 + 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0053 // f8-ff +}; + + +static void +vnc_clientgone(rfbClientPtr cl) +{ + pclog("VNC: client disconnected: %s\n", cl->host); + + if (vnc_clients > 0) + vnc_clients--; + if (vnc_clients == 0) { + /* No more clients, pause the emulator. */ + plat_pause(1); + + pclog("VNC: no clients, pausing..\n"); + } +} + + +static enum rfbNewClientAction +vnc_newclient(rfbClientPtr cl) +{ + /* Hook the ClientGone function so we know when they're gone. */ + cl->clientGoneHook = vnc_clientgone; + + pclog("VNC: new client: %s\n", cl->host); + if (++vnc_clients == 1) { + /* We now have clients, un-pause the emulator. */ + pclog("VNC: unpausing..\n"); + plat_pause(0); + } + + return(RFB_CLIENT_ACCEPT); +} + + +static void +vnc_display(rfbClientPtr cl) +{ + /* Avoid race condition between resize and update. */ + if (!updatingSize && cl->newFBSizePending) { + updatingSize = 1; + pclog("VNC: updatingSize=1\n"); + } else if (updatingSize && !cl->newFBSizePending) { + updatingSize = 0; + pclog("VNC: updatingSize=0\n"); + + allowedX = rfbScreen->width; + allowedY = rfbScreen->height; + } +} + + +static void +vnc_kbdevent(rfbBool down, rfbKeySym k, rfbClientPtr cl) +{ + int will_press = 0; + int key; + +#if 0 + pclog("VNC: kbdevent %d %x\n", down, k); +#endif + + if ((k >> 8) == 0x00) { + will_press = keysyms_00[k & 0xff]; + } else if ((k >> 8) == 0xff) { + will_press = keysyms_ff[k & 0xff]; + } + + if (will_press <= 0) return; + +#if 0 + pclog("VNC: translated to %x %x\n", + (will_press >> 8) & 0xff, will_press & 0xff); +#endif + + // first key + key = (will_press >> 8) & 0xff; + if (key > 0) + recv_key[key] = down; + + // second key + key = will_press & 0xff; + if (key > 0) + recv_key[key] = down; +} + + +static void +vnc_memtoscreen(int x, int y, int y1, int y2, int w, int h) +{ + int yy, i; + + /* y1 to = 0 && (y+yy) < 2048) + memcpy((uint32_t *) &(((uint8_t *) rfbScreen->frameBuffer)[yy*2048*4]), &(((uint32_t *)buffer32->line[y+yy])[x]), w*4); + } + + video_blit_complete(); + + if (! updatingSize) + rfbMarkRectAsModified(rfbScreen, 0,0, allowedX,allowedY); +} + + +static void +vnc_memtoscreen_8(int x, int y, int w, int h) +{ +#if 1 + pclog("VNC: memtoscreen_8 %i,%i %i,%i\n", x, y, w, h); +#endif +} + + +int +vnc_init(HWND h) +{ + rfbPixelFormat rpf = { + /* + * Screen format: + * 32bpp; 32 depth; + * little endian; + * true color; + * max 255 R/G/B; + * red shift 16; green shift 8; blue shift 0; + * padding + */ + 32, 32, 0, 1, 255,255,255, 16, 8, 0, 0, 0 + }; + + if (rfbScreen == NULL) { + updatingSize = 0; + allowedX = allowedY = 2048; + + rfbScreen = rfbGetScreen(0, NULL, 2048, 2048, 8, 3, 4); + rfbScreen->desktopName = "86Box"; + rfbScreen->frameBuffer = (char *)malloc(2048 * 2048 * 4); + +#if 1 + rfbScreen->serverFormat = rpf; +#else + rfbScreen->serverFormat = {32, 32, 0, 1, 255,255,255, 16, 8, 0, 0, 0}; +#endif + rfbScreen->alwaysShared = TRUE; + rfbScreen->displayHook = vnc_display; + rfbScreen->kbdAddEvent = vnc_kbdevent; + rfbScreen->newClientHook = vnc_newclient; + + rfbInitServer(rfbScreen); + + rfbRunEventLoop(rfbScreen, -1, TRUE); + } + + video_setblit(vnc_memtoscreen_8, vnc_memtoscreen); + + pclog("VNC: init complete.\n"); + + vnc_clients = 0; + + return(1); +} + + +void +vnc_close(void) +{ + pclog("VNC: closed.\n"); +} + + +void +vnc_resize(int x, int y) +{ + if ((x != rfbScreen->width || y != rfbScreen->height) && x > 160 && y > 0) { + pclog("VNC: updating resolution: %dx%d\n", x, y); + + allowedX = (rfbScreen->width < x) ? rfbScreen->width : x; + allowedY = (rfbScreen->width < y) ? rfbScreen->width : y; + + rfbScreen->width = x; + rfbScreen->height = y; + + rfbClientPtr cl; + rfbClientIteratorPtr iterator = rfbGetClientIterator(rfbScreen); + while ((cl = rfbClientIteratorNext(iterator)) != NULL) { + LOCK(cl->updateMutex); + cl->newFBSizePending = 1; + UNLOCK(cl->updateMutex); + } + } +} + + +int +vnc_pause(void) +{ + return((vnc_clients > 0) ? 0 : 1); +} + + +void +vnc_take_screenshot(wchar_t *fn) +{ + pclog("VNC: take_screenshot\n"); +} diff --git a/src/win/win_vnc.h b/src/win/win_vnc.h new file mode 100644 index 000000000..ba3d793e9 --- /dev/null +++ b/src/win/win_vnc.h @@ -0,0 +1,30 @@ +/* + * 86Box A hypervisor and IBM PC system emulator that specializes in + * running old operating systems and software designed for IBM + * PC systems and compatibles from 1981 through fairly recent + * system designs based on the PCI bus. + * + * This file is part of the 86Box distribution. + * + * Definitions for the VNC renderer. + * + * Version: @(#)win_vnc.h 1.0.1 2017/10/13 + * + * Authors: RichardG, + * Fred N. van Kempen, + * + * Copyright 2017 Fred N. van Kempen. + */ +#ifndef WIN_VNC_H +# define WIN_VNC_H + + +extern int vnc_init(HWND h); +extern void vnc_close(void); +extern void vnc_resize(int x, int y); +extern int vnc_pause(void); + +extern void vnc_take_screenshot(wchar_t *fn); + + +#endif /*WIN_VNC_H*/