Skip to content

Commit

Permalink
v8.1.9 #322 r<>b channels swap
Browse files Browse the repository at this point in the history
  • Loading branch information
caiiiycuk committed Aug 29, 2024
1 parent ab953a4 commit 7d49dd3
Show file tree
Hide file tree
Showing 9 changed files with 73 additions and 40 deletions.
10 changes: 9 additions & 1 deletion native/dhry2/dhry2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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) {
}
2 changes: 1 addition & 1 deletion native/dosbox-x
Submodule dosbox-x updated 1 files
+2 −0 src/dosbox.cpp
3 changes: 2 additions & 1 deletion native/jsdos/dosbox-x/jsdos-x-main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

Expand Down
4 changes: 3 additions & 1 deletion native/jsdos/dosbox/jsdos-main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#include <protocol.h>
#include <video.h>
#include <mouse.h>
#include <vga.h>
#include <cstdarg>

#include "timer.h"
Expand Down Expand Up @@ -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;
Expand Down
23 changes: 16 additions & 7 deletions native/sokol/protocol-sokol.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -105,19 +105,28 @@ 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<std::mutex> g(mutex);

if (!frameRgba) {
return;
}

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++;
Expand Down Expand Up @@ -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) {
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
12 changes: 6 additions & 6 deletions src/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
55 changes: 34 additions & 21 deletions src/dos/dosbox/cpp/worker-protocol.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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), {
Expand Down Expand Up @@ -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);
});
Expand Down Expand Up @@ -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();
}
Expand Down Expand Up @@ -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;
});
Expand Down
2 changes: 1 addition & 1 deletion src/protocol/protocol.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 7d49dd3

Please sign in to comment.