diff --git a/.github/workflows/c-cpp.yml b/.github/workflows/c-cpp.yml index 0c4ecd6b7..8899d9943 100644 --- a/.github/workflows/c-cpp.yml +++ b/.github/workflows/c-cpp.yml @@ -74,12 +74,11 @@ jobs: - uses: actions/checkout@v3 - name: make run: >- - make -fwin/makefile.mingw -j + make -fwin/Makefile.mingw -j DEV_BUILD=${{ matrix.build.dev }} DEBUG=${{ matrix.build.debug }} NEW_DYNAREC=${{ matrix.dynarec.new }} X64=${{ matrix.environment.x64 }} - VNC=n working-directory: ./src - uses: actions/upload-artifact@v3 with: diff --git a/.github/workflows/cmake.yml b/.github/workflows/cmake.yml index 6876e83bc..1c1a58e32 100644 --- a/.github/workflows/cmake.yml +++ b/.github/workflows/cmake.yml @@ -100,7 +100,6 @@ jobs: -D CMAKE_INSTALL_PREFIX=./build/artifacts -D QT=${{ matrix.ui.qt }} -D STATIC_BUILD=${{ matrix.ui.static }} - -D VNC=n - name: Build run: cmake --build build - name: Generate package @@ -169,7 +168,7 @@ jobs: run: echo "C:/Program Files/LLVM/bin" >> $env:GITHUB_PATH - name: Download Ninja run: > - Invoke-WebRequest https://github.com/ninja-build/ninja/releases/download/v1.10.2/ninja-win.zip -OutFile ninja-win.zip && + Invoke-WebRequest https://github.com/ninja-build/ninja/releases/download/v1.11.1/ninja-win.zip -OutFile ninja-win.zip && Expand-Archive ninja-win.zip -DestinationPath . - name: Setup NuGet Credentials run: > @@ -247,6 +246,7 @@ jobs: qtbase5-dev qttools5-dev libopenal-dev + libvncserver-dev - uses: actions/checkout@v3 - name: Configure CMake run: >- @@ -297,6 +297,7 @@ jobs: rtmidi qt@5 openal-soft + libvncserver - uses: actions/checkout@v3 - name: Configure CMake run: >- diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 94a6f1821..476c27439 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -52,11 +52,14 @@ if(DEV_BRANCH) endif() if(VNC) - add_compile_definitions(USE_VNC) - add_library(vnc OBJECT vnc.c vnc_keymap.c) - target_link_libraries(86Box vnc vncserver) - if(WIN32) - target_link_libraries(86Box ws2_32) + find_package(LibVNCServer) + if(LibVNCServer_FOUND) + add_compile_definitions(USE_VNC) + add_library(vnc OBJECT vnc.c vnc_keymap.c) + target_link_libraries(86Box vnc LibVNCServer::vncserver) + if(WIN32) + target_link_libraries(86Box ws2_32) + endif() endif() endif() diff --git a/src/device/mouse.c b/src/device/mouse.c index 422161a83..f628d1efa 100644 --- a/src/device/mouse.c +++ b/src/device/mouse.c @@ -88,6 +88,7 @@ static const device_t *mouse_curr; static void *mouse_priv; static int mouse_nbut; static int (*mouse_dev_poll)(int x, int y, int z, int b, void *priv); +static void (*mouse_poll_ex)(void) = NULL; #ifdef ENABLE_MOUSE_LOG int mouse_do_log = ENABLE_MOUSE_LOG; @@ -164,13 +165,22 @@ mouse_set_buttons(int buttons) mouse_nbut = buttons; } +void +mouse_set_poll_ex(void (*poll_ex)(void)) +{ + mouse_poll_ex = poll_ex; +} + void mouse_process(void) { if (mouse_curr == NULL) return; - mouse_poll(); + if (mouse_poll_ex) + mouse_poll_ex(); + else + mouse_poll(); if ((mouse_dev_poll != NULL) || (mouse_curr->poll != NULL)) { if (mouse_curr->poll != NULL) diff --git a/src/floppy/fdd_img.c b/src/floppy/fdd_img.c index 3ebfeefd9..e0847c010 100644 --- a/src/floppy/fdd_img.c +++ b/src/floppy/fdd_img.c @@ -486,9 +486,9 @@ img_seek(int drive, int track) for (side = 0; side < dev->sides; side++) { if (dev->disk_at_once) { cur_pos = (track * dev->sectors * ssize * dev->sides) + (side * dev->sectors * ssize); - memcpy(dev->track_data[side], dev->disk_data + cur_pos, dev->sectors * ssize); + memcpy(dev->track_data[side], dev->disk_data + cur_pos, (size_t) dev->sectors * ssize); } else { - read_bytes = fread(dev->track_data[side], 1, dev->sectors * ssize, dev->f); + read_bytes = fread(dev->track_data[side], 1, (size_t) dev->sectors * ssize, dev->f); if (read_bytes < (dev->sectors * ssize)) memset(dev->track_data[side] + read_bytes, 0xf6, (dev->sectors * ssize) - read_bytes); } diff --git a/src/include/86box/mouse.h b/src/include/86box/mouse.h index 434360589..aa046b81c 100644 --- a/src/include/86box/mouse.h +++ b/src/include/86box/mouse.h @@ -65,6 +65,7 @@ extern void mouse_init(void); extern void mouse_close(void); extern void mouse_reset(void); extern void mouse_set_buttons(int buttons); +extern void mouse_set_poll_ex(void (*poll_ex)(void)); extern void mouse_process(void); extern void mouse_set_poll(int (*f)(int, int, int, int, void *), void *); extern void mouse_poll(void); diff --git a/src/printer/prt_escp.c b/src/printer/prt_escp.c index e0a83da31..e7c9e0442 100644 --- a/src/printer/prt_escp.c +++ b/src/printer/prt_escp.c @@ -407,7 +407,7 @@ new_page(escp_t *dev, int8_t save, int8_t resetx) dev->curr_y = dev->top_margin; if (dev->page) { dev->page->dirty = 0; - memset(dev->page->pixels, 0x00, dev->page->pitch * dev->page->h); + memset(dev->page->pixels, 0x00, (size_t) dev->page->pitch * dev->page->h); } /* Make the page's file name. */ @@ -444,16 +444,16 @@ fill_palette(uint8_t redmax, uint8_t greenmax, uint8_t bluemax, uint8_t colorID, uint8_t colormask; int i; - float red = (float) redmax / (float) 30.9; - float green = (float) greenmax / (float) 30.9; - float blue = (float) bluemax / (float) 30.9; + double red = (double) redmax / (double) 30.9; + double green = (double) greenmax / (double) 30.9; + double blue = (double) bluemax / (double) 30.9; colormask = colorID <<= 5; for (i = 0; i < 32; i++) { - dev->palcol[i + colormask].r = 255 - (uint8_t) floor(red * (float) i); - dev->palcol[i + colormask].g = 255 - (uint8_t) floor(green * (float) i); - dev->palcol[i + colormask].b = 255 - (uint8_t) floor(blue * (float) i); + dev->palcol[i + colormask].r = 255 - (uint8_t) floor(red * (double) i); + dev->palcol[i + colormask].g = 255 - (uint8_t) floor(green * (double) i); + dev->palcol[i + colormask].b = 255 - (uint8_t) floor(blue * (double) i); } } @@ -2043,8 +2043,8 @@ escp_init(void *lpt) dev->page->w = (int) (dev->dpi * dev->page_width); dev->page->h = (int) (dev->dpi * dev->page_height); dev->page->pitch = dev->page->w; - dev->page->pixels = (uint8_t *) malloc(dev->page->pitch * dev->page->h); - memset(dev->page->pixels, 0x00, dev->page->pitch * dev->page->h); + dev->page->pixels = (uint8_t *) malloc((size_t) dev->page->pitch * dev->page->h); + memset(dev->page->pixels, 0x00, (size_t) dev->page->pitch * dev->page->h); /* Initialize parameters. */ for (i = 0; i < 32; i++) { diff --git a/src/qt/qt_mainwindow.cpp b/src/qt/qt_mainwindow.cpp index d707fc7ea..c87348663 100644 --- a/src/qt/qt_mainwindow.cpp +++ b/src/qt/qt_mainwindow.cpp @@ -1070,7 +1070,7 @@ std::array x11_to_xt_2 { 0x53, 0x138, 0x55, - 0x35, + 0x56, 0x57, 0x58, 0x56, diff --git a/src/sound/midi_rtmidi.cpp b/src/sound/midi_rtmidi.cpp index 743b828ad..354c7f61b 100644 --- a/src/sound/midi_rtmidi.cpp +++ b/src/sound/midi_rtmidi.cpp @@ -39,6 +39,7 @@ extern "C" { // Disable c99-designator to avoid the warnings in rtmidi_*_device #ifdef __clang__ # if __has_warning("-Wc99-designator") +# pragma clang diagnostic push # pragma clang diagnostic ignored "-Wc99-designator" # endif #endif @@ -302,4 +303,11 @@ const device_t rtmidi_input_device = { .force_redraw = NULL, .config = midi_input_config }; + +#ifdef __clang__ +# if __has_warning("-Wc99-designator") +# pragma clang diagnostic pop +# endif +#endif + } diff --git a/src/sound/snd_opl_ymfm.cpp b/src/sound/snd_opl_ymfm.cpp index bb52f3c55..012e77bdb 100644 --- a/src/sound/snd_opl_ymfm.cpp +++ b/src/sound/snd_opl_ymfm.cpp @@ -29,6 +29,15 @@ extern "C" { #include <86box/snd_opl.h> #include <86box/mem.h> #include <86box/rom.h> + +// Disable c99-designator to avoid the warnings in *_ymfm_device +#ifdef __clang__ +# if __has_warning("-Wc99-designator") +# pragma clang diagnostic push +# pragma clang diagnostic ignored "-Wc99-designator" +# endif +#endif + } #define RSM_FRAC 10 @@ -432,4 +441,11 @@ const fm_drv_t ymfm_drv { &ymfm_drv_set_do_cycles, NULL, }; + +#ifdef __clang__ +# if __has_warning("-Wc99-designator") +# pragma clang diagnostic pop +# endif +#endif + } diff --git a/src/video/vid_pgc.c b/src/video/vid_pgc.c index 89d1505bb..eb28540fc 100644 --- a/src/video/vid_pgc.c +++ b/src/video/vid_pgc.c @@ -2663,8 +2663,8 @@ pgc_init(pgc_t *dev, int maxw, int maxh, int visw, int vish, dev->visw = visw; dev->vish = vish; - dev->vram = (uint8_t *) malloc(maxw * maxh); - memset(dev->vram, 0x00, maxw * maxh); + dev->vram = (uint8_t *) malloc((size_t) maxw * maxh); + memset(dev->vram, 0x00, (size_t) maxw * maxh); dev->cga_vram = (uint8_t *) malloc(16384); memset(dev->cga_vram, 0x00, 16384); diff --git a/src/video/vid_svga_render.c b/src/video/vid_svga_render.c index 30d2c93b0..c67a46e0d 100644 --- a/src/video/vid_svga_render.c +++ b/src/video/vid_svga_render.c @@ -68,7 +68,7 @@ svga_render_blank(svga_t *svga) } uint32_t *line_ptr = &buffer32->line[svga->displine + svga->y_add][svga->x_add]; - uint32_t line_width = (svga->hdisp + svga->scrollcache) * char_width * sizeof(uint32_t); + uint32_t line_width = (uint32_t) (svga->hdisp + svga->scrollcache) * char_width * sizeof(uint32_t); memset(line_ptr, 0, line_width); } diff --git a/src/video/video.c b/src/video/video.c index 18f2e1427..096ea89e1 100644 --- a/src/video/video.c +++ b/src/video/video.c @@ -804,7 +804,7 @@ create_bitmap(int x, int y) bitmap_t *b = malloc(sizeof(bitmap_t) + (y * sizeof(uint32_t *))); int c; - b->dat = malloc(x * y * 4); + b->dat = malloc((size_t) x * y * 4); for (c = 0; c < y; c++) b->line[c] = &(b->dat[c * x]); b->w = x; diff --git a/src/vnc.c b/src/vnc.c index 3bffdcd9d..ef388939a 100644 --- a/src/vnc.c +++ b/src/vnc.c @@ -44,6 +44,15 @@ static int allowedX, allowedY; static int ptr_x, ptr_y, ptr_but; +typedef struct { + int buttons; + int dx; + int dy; + int dwheel; +} MOUSESTATE; + +static MOUSESTATE ms; + #ifdef ENABLE_VNC_LOG int vnc_do_log = ENABLE_VNC_LOG; @@ -71,29 +80,43 @@ vnc_kbdevent(rfbBool down, rfbKeySym k, rfbClientPtr cl) vnc_kbinput(down ? 1 : 0, (int) k); } +void +vnc_mouse_poll(void) +{ + static int b = 0; + if (ms.dx != 0 || ms.dy != 0) { + mouse_x += ms.dx; + mouse_y += ms.dy; + + ms.dx = 0; + ms.dy = 0; + + // pclog("dx=%d, dy=%d, dwheel=%d\n", mouse_x, mouse_y, mouse_z); + } + + if (b != ms.buttons) { + mouse_buttons = ms.buttons; + b = ms.buttons; + } +} + static void vnc_ptrevent(int but, int x, int y, rfbClientPtr cl) { - if (x >= 0 && x < allowedX && y >= 0 && y < allowedY) { - /* VNC uses absolute positions within the window, no deltas. */ - if (x != ptr_x || y != ptr_y) { - mouse_x += (x - ptr_x) / 100; - mouse_y += (y - ptr_y) / 100; - ptr_x = x; - ptr_y = y; - } + ms.buttons = 0; + if (but & 0x01) + ms.buttons |= 0x01; + if (but & 0x02) + ms.buttons |= 0x04; + if (but & 0x04) + ms.buttons |= 0x02; + ptr_but = but; - if (but != ptr_but) { - mouse_buttons = 0; - if (but & 0x01) - mouse_buttons |= 0x01; - if (but & 0x02) - mouse_buttons |= 0x04; - if (but & 0x04) - mouse_buttons |= 0x02; - ptr_but = but; - } - } + /* VNC uses absolute positions within the window, no deltas. */ + ms.dx += (x - ptr_x) / 0.96; /* TODO: Figure out the correct scale factor for X and Y. */ + ms.dy += (y - ptr_y) / 0.96; + ptr_x = x; + ptr_y = y; rfbDefaultPtrAddEvent(but, x, y, cl); } @@ -110,7 +133,8 @@ vnc_clientgone(rfbClientPtr cl) vnc_log("VNC: no clients, pausing..\n"); /* Disable the mouse. */ - plat_mouse_capture(0); + // plat_mouse_capture(0); + mouse_set_poll_ex(NULL); plat_pause(1); } @@ -129,12 +153,14 @@ vnc_newclient(rfbClientPtr cl) ptr_y = allowedY / 2; mouse_x = mouse_y = mouse_z = 0; mouse_buttons = 0x00; + memset(&ms, 0, sizeof(MOUSESTATE)); /* We now have clients, un-pause the emulator if needed. */ vnc_log("VNC: unpausing..\n"); /* Enable the mouse. */ - plat_mouse_capture(1); + // plat_mouse_capture(1); + mouse_set_poll_ex(vnc_mouse_poll); plat_pause(0); } @@ -160,20 +186,15 @@ vnc_display(rfbClientPtr cl) static void vnc_blit(int x, int y, int w, int h, int monitor_index) { - uint32_t *p; - int yy; + int row; - if (monitor_index || (x < 0) || (y < 0) || (w <= 0) || (h <= 0) || (w > 2048) || (h > 2048) || (buffer32 == NULL)) { + if (monitor_index || (x < 0) || (y < 0) || (w < VNC_MIN_X) || (h < VNC_MIN_Y) || (w > VNC_MAX_X) || (h > VNC_MAX_Y) || (buffer32 == NULL)) { video_blit_complete_monitor(monitor_index); return; } - for (yy = 0; yy < h; yy++) { - p = (uint32_t *) &(((uint32_t *) rfb->frameBuffer)[yy * VNC_MAX_X]); - - if ((y + yy) >= 0 && (y + yy) < VNC_MAX_Y) - video_copy(p, &(buffer32->line[yy]), w * sizeof(uint32_t)); - } + for (row = 0; row < h; ++row) + video_copy(&(((uint8_t *) rfb->frameBuffer)[row * 2048 * sizeof(uint32_t)]), &(buffer32->line[y + row][x]), w * sizeof(uint32_t)); if (screenshots) video_screenshot((uint32_t *) rfb->frameBuffer, 0, 0, VNC_MAX_X); @@ -265,7 +286,7 @@ vnc_resize(int x, int y) return; /* TightVNC doesn't like certain sizes.. */ - if (x < VNC_MIN_X || x > VNC_MAX_X || y < VNC_MIN_Y || y > VNC_MAX_Y) { + if ((x < VNC_MIN_X) || (x > VNC_MAX_X) || (y < VNC_MIN_Y) || (y > VNC_MAX_Y)) { vnc_log("VNC: invalid resoltion %dx%d requested!\n", x, y); return; } diff --git a/src/win/Makefile.mingw b/src/win/Makefile.mingw index 040b14aee..e39792966 100644 --- a/src/win/Makefile.mingw +++ b/src/win/Makefile.mingw @@ -416,7 +416,7 @@ ifeq ($(VNC), y) OPTS += -I$(VNC_PATH)\INCLUDE VNCLIB := -L$(VNC_PATH)\LIB endif - VNCLIB += -lvncserver + VNCLIB += -lvncserver.dll VNCOBJ := vnc.o vnc_keymap.o endif