Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ if(${CMAKE_SYSTEM_NAME} MATCHES "Emscripten")
set(USE_FLAGS "-pthread -s USE_SDL=2 -s USE_PTHREADS=1")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O2 ${USE_FLAGS}")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -O2 ${USE_FLAGS}")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${USE_FLAGS} -s ALLOW_MEMORY_GROWTH=1 -s PTHREAD_POOL_SIZE=2 --preload-file ${CMAKE_SOURCE_DIR}/sqlux.ini@./sqlux.ini --preload-file ${CMAKE_SOURCE_DIR}/roms/MIN198.rom@./roms/MIN198.rom --preload-file ${CMAKE_SOURCE_DIR}/roms/TK232.rom@./roms/TK232.rom" )
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${USE_FLAGS} -s ALLOW_MEMORY_GROWTH=1 -s PTHREAD_POOL_SIZE=2 -lidbfs.js --preload-file ${CMAKE_SOURCE_DIR}/sqlux_wasm.ini@./sqlux.ini --preload-file ${CMAKE_SOURCE_DIR}/roms/MIN198.rom@./roms/MIN198.rom --preload-file ${CMAKE_SOURCE_DIR}/roms/TK232.rom@./roms/TK232.rom --preload-file ${CMAKE_SOURCE_DIR}/default.img@./default_win1.win" )
configure_file(sqlux_wrapper_sample.html index.html COPYONLY)
else()
find_package(SDL2 REQUIRED)
Expand Down Expand Up @@ -134,6 +134,9 @@ add_dependencies(sqlux SubmarineGitVersion)
if (${CMAKE_SYSTEM_NAME} MATCHES "Windows")
target_sources(sqlux PRIVATE sQLuxLogo.rc)
endif ()
if(${CMAKE_SYSTEM_NAME} MATCHES "Emscripten")
target_sources(sqlux PRIVATE src/wasm_support.c)
endif()

if (SUPPORT_SHADERS)
message("Enabling shader support")
Expand Down
Binary file added default.img
Binary file not shown.
7 changes: 7 additions & 0 deletions include/wasm_support.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#ifndef _WASMSUPPORT_H
#define _WASMSUPPORT_H

int wasm_does_boot_file_exist(void);
void wasm_init_storage(void);

#endif
22 changes: 22 additions & 0 deletions sqlux_wasm.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Example configuration

SYSROM = MIN198.rom
ROMPORT = TK232.rom
RAMTOP = 4096
PRINT = lpr
CPU_HOG = 0
FAST_STARTUP = 0
#BOOT_DEVICE = WIN1
BOOT_DEVICE = FLP1
DEVICE = WIN1,/local/win1.win,qdos-fs
DEVICE = FLP1,/local/win1.win,qdos-fs
DEVICE = RAM1,/tmp/.ram1-%x,clean,qdos-like
#DEVICE = RAM1,/tmp/.ram1-%x,clean,qdos-like
#DEVICE = RAM2,/tmp/.ram2-%x,clean,qdos-like
#DEVICE = RAM8,/tmp/.ram8-%x,clean,qdos-like
WIN_SIZE = max
FILTER = 1
FIXASPECT = 1
KBD = GB
SOUND = 1
SPEED = 0.0
79 changes: 54 additions & 25 deletions sqlux_wrapper_sample.html
Original file line number Diff line number Diff line change
@@ -1,28 +1,57 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>
<body>
<script type='text/javascript'>
var Module = {};
fetch('sqlux.wasm')
.then(response =>
response.arrayBuffer()
).then(buffer => {
Module.canvas = document.getElementById("canvas");
Module.wasmBinary = buffer;
var script = document.createElement('script');
script.src = "sqlux.js";
script.onload = function() {
console.log("Emscripten boilerplate loaded.")
}
document.body.appendChild(script);
});
</script>
<!--canvas id="canvas" style="width:720px; height:450px" width="1440" height="900"></canvas-->
<canvas id="canvas" style="width:100%; height:100%" width="1440" height="900"></canvas>

</body>
</html>
<head>
<meta charset="utf-8">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>

<body>
<label style="margin-right: 10px;">Upload flp/win image</label><input type="file" id="myfile" onchange="load_file()">
<label style="margin-right: 10px;">Save changes</label><button onclick="sync()">Save</button>
<br>
<script type='text/javascript'>
var Module = {};
fetch('sqlux.wasm')
.then(response =>
response.arrayBuffer()
).then(buffer => {
Module.canvas = document.getElementById("canvas");
Module.canvas.oncontextmenu = function() {
return false;
}
Module.wasmBinary = buffer;
var script = document.createElement('script');
script.src = "sqlux.js";
script.onload = function () {
console.log("Emscripten boilerplate loaded.")
}
document.body.appendChild(script);
});
</script>
<canvas id="canvas" style="width: 1024px;height: 512px;" width="1024" height="512" oncontextmenu = "function(e) { e.preventDefault(); e.stopPropagation(); }"></canvas>
<script type="text/javascript">
let reader = new FileReader();

function load_file() {
let files = document.getElementById('myfile').files;
let file = files[0];
reader.addEventListener('loadend', update_win1);
reader.readAsArrayBuffer(file);
}

function update_win1(e) {
let result = reader.result;
const uint8_view = new Uint8Array(result);
console.log("Writing new image...");
FS.writeFile('/local/win1.win', uint8_view)
FS.syncfs(false, function (err) { console.log("New image written and synced."); });
}

function sync() {
FS.syncfs(false, function (err) { console.log("Sync done."); });
}
</script>
</body>

</html>
61 changes: 40 additions & 21 deletions src/SDL2main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ extern "C" {

#if __EMSCRIPTEN__
#include <emscripten/emscripten.h>
extern "C" {
#include "wasm_support.h"
}
#endif

static SDL_Thread *emuThread = NULL;
Expand All @@ -25,19 +28,19 @@ void CleanRAMDev()
int i, j;

for (i = 0; i < MAXDEV; i++) {
if (qdevs[i].qname && strcmp(qdevs[i].qname, "RAM") == 0) {
for (j = 0; j < 8; j++) {
if ((qdevs[i].mountPoints[j] != NULL) &&
qdevs[i].clean[j]) {
if (qdevs[i].qname && strcmp(qdevs[i].qname, "RAM") == 0) {
for (j = 0; j < 8; j++) {
if ((qdevs[i].mountPoints[j] != NULL) &&
qdevs[i].clean[j]) {
if (V2) {
std::cout << "Cleaning: " << qdevs[i].mountPoints[j] << "\n";
}
std::filesystem::remove_all(qdevs[i].mountPoints[j]);
}
}
break;
}
}
std::filesystem::remove_all(qdevs[i].mountPoints[j]);
}
}
break;
}
}
}

extern "C" void emu_shutdown()
Expand All @@ -51,8 +54,33 @@ extern "C" void emu_shutdown()
CleanRAMDev();
}

extern "C" void emu_loop() {
static int init_done = 0;
int boot_file_ready = 1;

#if __EMSCRIPTEN__
if(!init_done) {
boot_file_ready = wasm_does_boot_file_exist();
}
#endif
if(boot_file_ready && !init_done) {
emulator::deviceParse();
emulator::init();
QLSDLScreen();
initSound(optionInt("SOUND"));
emuThread = SDL_CreateThread(QLRun, "sQLux Emulator", NULL);
init_done = 1;
}
if(init_done) {
QLSDLProcessEvents();
}
}

extern "C" int main(int argc, char *argv[])
{
#if __EMSCRIPTEN__
wasm_init_storage();
#endif
// set the homedir for the OS first
SetHome();

Expand All @@ -78,20 +106,11 @@ extern "C" int main(int argc, char *argv[])
}
free(boot_cmd);

emulator::deviceParse();

emulator::init();

QLSDLScreen();

initSound(optionInt("SOUND"));

emuThread = SDL_CreateThread(QLRun, "sQLux Emulator", NULL);

#if __EMSCRIPTEN__
emscripten_set_main_loop(QLSDLProcessEvents, -1, 1);
emscripten_set_main_loop(emu_loop, -1, 1);
#else
QLSDLProcessEvents();
emu_loop();
#endif

emu_shutdown();
Expand Down
27 changes: 27 additions & 0 deletions src/wasm_support.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#include "emscripten.h"
#include "wasm_support.h"

EM_JS(int, wasm_does_boot_file_exist, (), {
if (!FS.analyzePath(localWinFile).exists) {
return 0;
}
return 1;
});

EM_JS(void, wasm_init_storage, (), {
var localStoragePath = '/local';
var defaultWinFile = 'win1.win';
localWinFile = localStoragePath + '/' + defaultWinFile;
FS.mkdir(localStoragePath);
FS.mount(IDBFS, {}, localStoragePath);
FS.syncfs(
true, function(err) {
if (!FS.analyzePath(localWinFile).exists) {
console.log('Copy default win1 file.');
var wincontent =
FS.readFile('/default_win1.win');
FS.writeFile(localWinFile, wincontent);
FS.syncfs(false, function(err){});
}
});
});