diff --git a/native/dhry2/dhry2.cpp b/native/dhry2/dhry2.cpp index 4f7590cf..0e2933ca 100644 --- a/native/dhry2/dhry2.cpp +++ b/native/dhry2/dhry2.cpp @@ -13,7 +13,7 @@ #include "dosbox_conf.h" void client_frame_set_size(int width, int height) {} -void client_frame_update_lines(uint32_t* lines, uint32_t count, void* rgba) {} +void client_frame_update_lines(uint32_t* lines, uint32_t count, void* rgba, bool bgra) {} void client_sound_init(int freq) {} void client_sound_push(const float* samples, int num_samples) {} void client_stdout(const char* data, uint32_t amount) { @@ -70,3 +70,11 @@ void client_error(const char* tag, const char* message) {} void client_network_connected(enum NetworkType networkType, const char* address) {} void client_network_disconnected(enum NetworkType networkType) {} void client_tick() {} +int server_net_connect(const char* address) { + return NETWORK_NA; +} +int server_net_send(int networkId, const void *datap, int len) { + return -1; +} +void server_net_disconnect(int networkId) { +} diff --git a/native/dosbox-x b/native/dosbox-x index 4da462e5..0f3eb6ba 160000 --- a/native/dosbox-x +++ b/native/dosbox-x @@ -1 +1 @@ -Subproject commit 4da462e5764ad088ff1c3197baca54fb5cffea00 +Subproject commit 0f3eb6ba8e53064f20218fd81e924d313625849c diff --git a/native/jsdos/dosbox-x/jsdos-x-main.cpp b/native/jsdos/dosbox-x/jsdos-x-main.cpp index 0d4d111a..5c35d648 100644 --- a/native/jsdos/dosbox-x/jsdos-x-main.cpp +++ b/native/jsdos/dosbox-x/jsdos-x-main.cpp @@ -3040,7 +3040,8 @@ void GFX_EndUpdate(const uint16_t *changedLines) { } index++; } - client_frame_update_lines(lines.data(), lines.size() / 3, (uint32_t*) sdl.surface->pixels); + client_frame_update_lines(lines.data(), lines.size() / 3, (uint32_t *) sdl.surface->pixels, + vga.mode == M_LIN16 || vga.mode == M_LIN24 || vga.mode == M_LIN32); } } diff --git a/native/jsdos/dosbox/jsdos-main.cpp b/native/jsdos/dosbox/jsdos-main.cpp index fa5ecebd..779c809a 100644 --- a/native/jsdos/dosbox/jsdos-main.cpp +++ b/native/jsdos/dosbox/jsdos-main.cpp @@ -14,6 +14,7 @@ #include #include #include +#include #include #include "timer.h" @@ -100,7 +101,8 @@ void GFX_EndUpdate(const Bit16u *changedLines) { } index++; } - client_frame_update_lines(lines.data(), lines.size() / 3, (uint32_t*) surface); + client_frame_update_lines(lines.data(), lines.size() / 3, (uint32_t*) surface, + vga.mode == M_LIN16 || vga.mode == M_LIN32); } surfaceUpdating = false; diff --git a/native/sokol/protocol-sokol.cpp b/native/sokol/protocol-sokol.cpp index 1eca3b56..c6333019 100644 --- a/native/sokol/protocol-sokol.cpp +++ b/native/sokol/protocol-sokol.cpp @@ -105,7 +105,7 @@ void client_frame_set_size(int width, int height) { frameRgba = new uint32_t[width * height]; } -void client_frame_update_lines(uint32_t *lines, uint32_t count, void *rgba) { +void client_frame_update_lines(uint32_t *lines, uint32_t count, void *rgba, bool bgra) { std::lock_guard g(mutex); if (!frameRgba) { @@ -113,11 +113,20 @@ void client_frame_update_lines(uint32_t *lines, uint32_t count, void *rgba) { } for (uint32_t i = 0; i < count; ++i) { - uint32_t start = lines[i * 3]; - uint32_t count = lines[i * 3 + 1]; + uint32_t start = lines[i * 3] * frameWidth; + uint32_t count = lines[i * 3 + 1] * sizeof(uint32_t) * frameWidth; uint32_t offset = lines[i * 3 + 2]; - memcpy(&frameRgba[start * frameWidth], (char *)rgba + offset, - sizeof(uint32_t) * count * frameWidth); + memcpy(&frameRgba[start], (char *)rgba + offset, count); + if (bgra) { + auto begin = (uint8_t*) &frameRgba[start]; + auto end = begin + count; + while (begin < end) { + auto r = begin[0]; + begin[0] = begin[2]; + begin[2] = r; + begin += sizeof(uint32_t); + } + } } frameCount++; @@ -236,8 +245,8 @@ int main(int argc, char *argv[]) { int server_net_connect(const char* address) { return NETWORK_NA; } -int server_net_send(int networkId, const void *datap, int len) { - return 0; +int server_net_send(int networkId, const void *datap, int len) { + return -1; } void server_net_disconnect(int networkId) { } diff --git a/package.json b/package.json index 6167dded..389e8830 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "emulators", - "version": "8.1.8", + "version": "8.1.9", "description": "Emulators (dos) with standartized API", "main": "dist/emulators.js", "types": "dist/types/emulators.d.ts", diff --git a/src/build.ts b/src/build.ts index 20a2cd2d..e24adeb5 100644 --- a/src/build.ts +++ b/src/build.ts @@ -5,22 +5,22 @@ // gulpfile.ts/wasm.ts --> generateBuildInfo export const Build = { - version: "8.1.7 (5afea1bc2cb60b124720255837fe8a68)", - buildSeed: 1724405863345, + version: "8.1.8 (98fe757e5f9a84c1b21e0849e289c8ba)", + buildSeed: 1724939828246, "wdosbox-x.wasm": { - "size": 6304113, + "size": 6304303, "gzSize": 0 }, "wdosbox-x.js": { - "size": 230628, + "size": 230427, "gzSize": 0 }, "wdosbox.wasm": { - "size": 1467599, + "size": 1467787, "gzSize": 0 }, "wdosbox.js": { - "size": 108371, + "size": 108170, "gzSize": 0 }, "wlibzip.wasm": { diff --git a/src/dos/dosbox/cpp/worker-protocol.cpp b/src/dos/dosbox/cpp/worker-protocol.cpp index a4db9031..b1244859 100644 --- a/src/dos/dosbox/cpp/worker-protocol.cpp +++ b/src/dos/dosbox/cpp/worker-protocol.cpp @@ -14,6 +14,7 @@ std::string connectToAddress(""); int frameHeight = 0; int frameWidth = 0; +uint8_t *frameRgb = nullptr; // clang-format off EM_JS(void, ws_init_runtime, (const char* sessionId), { @@ -388,25 +389,13 @@ EM_JS(void, emsc_ws_client_frame_set_size, (int width, int height), { Module.sendMessage("ws-frame-set-size", {width : width, height : height}); }); -EM_JS(bool, emsc_start_frame_update, (void* rgba), { +EM_JS(void, emsc_start_frame_update, (), { Module.frame_update_lines = []; Module.frame_update_lines_transferable = []; - return true; }); -EM_JS(void, emsc_add_frame_line, (uint32_t start, char* ptr, uint32_t bpp4len), { - var bpp3 = new Uint8Array(bpp4len / 4 * 3); - var bpp4 = Module.HEAPU8; - - var bpp3Offset = 0; - var bpp4Offset = ptr; - while (bpp3Offset < bpp3.length) { - bpp3[bpp3Offset++] = bpp4[bpp4Offset++]; - bpp3[bpp3Offset++] = bpp4[bpp4Offset++]; - bpp3[bpp3Offset++] = bpp4[bpp4Offset++]; - bpp4Offset++; - } - +EM_JS(void, emsc_add_frame_line, (uint32_t start, uint8_t* ptr, uint32_t len), { + var bpp3 = Module.HEAPU8.slice(ptr, ptr + len); Module.frame_update_lines.push({start : start, heapu8 : bpp3}); Module.frame_update_lines_transferable.push(bpp3.buffer); }); @@ -557,23 +546,46 @@ EM_JS(void, emsc_pack_fs_to_bundle, (bool onlyChanges), { // clang-format on void client_frame_set_size(int width, int height) { + if (frameRgb) { + delete[] frameRgb; + } frameHeight = height; frameWidth = width; + frameRgb = new uint8_t[width * height * 3]; emsc_ws_client_frame_set_size(width, height); } -void client_frame_update_lines(uint32_t *lines, uint32_t batchCount, void *rgba) { - if (!emsc_start_frame_update(rgba)) { - return; +void client_frame_update_lines(uint32_t *lines, uint32_t batchCount, void *rgba, bool bgra) { + if (!frameRgb) { + return; } + uint8_t r = 0; + uint8_t b = 2; + if (bgra) { + r = 2; + b = 0; + } + + emsc_start_frame_update(); for (uint32_t i = 0; i < batchCount; ++i) { uint32_t base = i * 3; uint32_t start = lines[base]; uint32_t count = lines[base + 1]; uint32_t offset = lines[base + 2]; - emsc_add_frame_line(start, (char *)rgba + offset, - sizeof(uint32_t) * count * frameWidth); + + uint8_t* bpp3Begin = frameRgb + start * frameWidth * 3; + uint8_t* bpp3 = bpp3Begin; + uint8_t* bpp4 = (uint8_t*) rgba + offset; + uint8_t* bpp4End = bpp4 + sizeof(uint32_t) * count * frameWidth; + while (bpp4 < bpp4End) { + bpp3[0] = bpp4[r]; + bpp3[1] = bpp4[1]; + bpp3[2] = bpp4[b]; + bpp3 += 3; + bpp4 += 4; + } + emsc_add_frame_line(start, bpp3Begin, 3 * count * frameWidth); } emsc_end_frame_update(); } @@ -824,7 +836,8 @@ EM_ASYNC_JS(int, em_net_connect, (const char* address), { EM_JS(bool, em_net_send, (int networkId, const void *datap, int len), { if (Module.wsNetIds[networkId]) { - Module.sendMessage("ws-net-send", { networkId, data: Module.HEAPU8.slice(datap, datap + len) }); + const data = Module.HEAPU8.slice(datap, datap + len); + Module.sendMessage("ws-net-send", { networkId, data }, [ data.buffer ]); } return Module.wsNetIds[networkId] === true; }); diff --git a/src/protocol/protocol.h b/src/protocol/protocol.h index 5e1fcc63..a46b2545 100644 --- a/src/protocol/protocol.h +++ b/src/protocol/protocol.h @@ -18,7 +18,7 @@ typedef int NetworkId; // -- Client (Web Page) void client_frame_set_size(int width, int height); -void client_frame_update_lines(uint32_t* lines, uint32_t count, void* rgba); +void client_frame_update_lines(uint32_t* lines, uint32_t count, void* rgba, bool bgra); void client_sound_init(int freq); void client_sound_push(const float* samples, int num_samples); void client_stdout(const char* data, uint32_t amount);