diff --git a/.travis.yml b/.travis.yml index f92e913c..b59f7214 100644 --- a/.travis.yml +++ b/.travis.yml @@ -7,14 +7,22 @@ script: - cd travis-build - git clone https://github.com/emscripten-core/emsdk.git - cd emsdk - - ./emsdk install latest-upstream - - ./emsdk activate latest-upstream + - ./emsdk install latest + - ./emsdk install latest-fastcomp + - ./emsdk activate latest - source ./emsdk_env.sh - cd .. - emcmake cmake .. - - make + - make wdosbox wdosbox-nosync - mkdir ../build - cp wdosbox.* ../build + - rm -rf ./* + - ./emsdk/emsdk activate latest-fastcomp + - emcc --clear-ports + - emcmake cmake .. + - make wdosbox-emterp + - mkdir ../build-emterp + - cp wdosbox* ../build-enterp - source /etc/environment - nvm use 11.8 - npm install -g gulp diff --git a/CMakeLists.txt b/CMakeLists.txt index f342a3ce..f596e9d9 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,8 +1,5 @@ cmake_minimum_required(VERSION 3.6) -set(ASYNCIFY ON) -set(EMTERPRETIFY OFF) - if(${EMSCRIPTEN}) set(OPT_FLAG "-Oz") set(USE_PORTS "-s USE_ZLIB=1") @@ -24,17 +21,10 @@ if(${EMSCRIPTEN}) -s EXPORT_NAME='WDOSBOX' \ -s FORCE_FILESYSTEM=1 \ -s EXTRA_EXPORTED_RUNTIME_METHODS=\"['getMemory', 'addRunDependency', 'removeRunDependency','FS', 'FS_createPath', 'FS_createPreloadedFile', \ - 'FS_createDataFile', 'lengthBytesUTF8', 'stringToUTF8', 'UTF16ToString']\" \ + 'FS_createDataFile', 'lengthBytesUTF8', 'stringToUTF8', 'UTF16ToString', 'callMain']\" \ -s NO_EXIT_RUNTIME=1 \ -s ERROR_ON_UNDEFINED_SYMBOLS=0") add_definitions(-DEMSCRIPTEN) - - if(ASYNCIFY) - set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -s ASYNCIFY -s ASYNCIFY_WHITELIST=@${CMAKE_CURRENT_LIST_DIR}/js-dos-cpp/asyncify.txt") - # -s ASYNCIFY_IGNORE_INDIRECT \ - elseif(EMTERPRETIFY) - set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -s EMTERPRETIFY=1 -s EMTERPRETIFY_ASYNC=1 -s EMTERPRETIFY_WHITELIST=@${CMAKE_CURRENT_LIST_DIR}/js-dos-cpp/emterpretify.txt") - endif() else() set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Werror=return-type -Wno-deprecated") add_definitions(-DDEBUG -DEMSCRIPTEN_KEEPALIVE=) @@ -44,13 +34,6 @@ endif() add_definitions(-DHAVE_CONFIG_H -DGET_X86_FUNCTIONS -DJSDOS) -if(ASYNCIFY) - add_definitions(-DEMTERPRETER_SYNC -DASYNCIFY -Demscripten_sleep_with_yield=emscripten_sleep) -elseif(EMTERPRETIFY) - add_definitions(-DEMTERPRETER_SYNC) -endif() - - include( "${CMAKE_CURRENT_LIST_DIR}/3rd-party/3rd-party.cmake" ) @@ -194,10 +177,31 @@ set(SOURCES ) if(${EMSCRIPTEN}) - add_library(bin-obj OBJECT ${SOURCES} ${SOURCES_CXX11} ${SOURCES_3RDPARTY}) - add_executable(wdosbox $) + add_library(bin-asyncify OBJECT ${SOURCES} ${SOURCES_CXX11} ${SOURCES_3RDPARTY}) + target_compile_definitions(bin-asyncify PUBLIC -DEMTERPRETER_SYNC -DASYNCIFY -Demscripten_sleep_with_yield=emscripten_sleep) + add_executable(wdosbox $) set_target_properties(wdosbox PROPERTIES SUFFIX .js) - set_target_properties(wdosbox PROPERTIES LINK_FLAGS "-s WASM=1") + set_target_properties(wdosbox PROPERTIES LINK_FLAGS "-s WASM=1 -s ASYNCIFY -s ASYNCIFY_WHITELIST=@${CMAKE_CURRENT_LIST_DIR}/js-dos-cpp/asyncify.txt") + add_executable(dosbox $) + set_target_properties(dosbox PROPERTIES SUFFIX .js) + set_target_properties(dosbox PROPERTIES LINK_FLAGS "-s WASM=0 -s ASYNCIFY -s ASYNCIFY_WHITELIST=@${CMAKE_CURRENT_LIST_DIR}/js-dos-cpp/asyncify.txt") + + add_library(bin-emterp OBJECT ${SOURCES} ${SOURCES_CXX11} ${SOURCES_3RDPARTY}) + target_compile_definitions(bin-emterp PUBLIC -DEMTERPRETER_SYNC) + add_executable(wdosbox-emterp $) + set_target_properties(wdosbox-emterp PROPERTIES SUFFIX .js) + set_target_properties(wdosbox-emterp PROPERTIES LINK_FLAGS "-s WASM=1 -s EMTERPRETIFY=1 -s EMTERPRETIFY_ASYNC=1 -s EMTERPRETIFY_WHITELIST=@${CMAKE_CURRENT_LIST_DIR}/js-dos-cpp/emterpretify.txt") + add_executable(dosbox-emterp $) + set_target_properties(dosbox-emterp PROPERTIES SUFFIX .js) + set_target_properties(dosbox-emterp PROPERTIES LINK_FLAGS "-s WASM=0 -s EMTERPRETIFY=1 -s EMTERPRETIFY_ASYNC=1 -s EMTERPRETIFY_WHITELIST=@${CMAKE_CURRENT_LIST_DIR}/js-dos-cpp/emterpretify.txt") + + add_library(bin-nosync OBJECT ${SOURCES} ${SOURCES_CXX11} ${SOURCES_3RDPARTY}) + add_executable(wdosbox-nosync $) + set_target_properties(wdosbox-nosync PROPERTIES SUFFIX .js) + set_target_properties(wdosbox-nosync PROPERTIES LINK_FLAGS "-s WASM=1") + add_executable(dosbox-nosync $) + set_target_properties(dosbox-nosync PROPERTIES SUFFIX .js) + set_target_properties(dosbox-nosync PROPERTIES LINK_FLAGS "-s WASM=0") else() add_executable(bin ${SOURCES} ${SOURCES_CXX11} ${SOURCES_3RDPARTY}) target_link_libraries(bin diff --git a/README.md b/README.md index b4acb15b..bbd2215d 100644 --- a/README.md +++ b/README.md @@ -98,6 +98,8 @@ You can obtain latest build using this links: - js-dos client api: https://js-dos.com/6.22/current/js-dos.js - dosbox wasm wrapper: https://js-dos.com/6.22/current/wdosbox.js - dosbox wasm file: https://js-dos.com/6.22/current/wdosbox.wasm.js + - dosbox wasm-emterp file: https://js-dos.com/6.22/current/wdosbox-emterp.wasm.js + - dosbox wasm-nosync file: https://js-dos.com/6.22/current/wdosbox-nosync.wasm.js **NOTE**: do not try to use this links to serve your copy of dosbox. Because this links always pointing to latest version, and newest version can have breaking changes. Is better to use npx bootstrap command (above), or download latest @@ -159,6 +161,18 @@ You can do this by passing `wdosboxUrl` property as second argument: Dos(canvas, { wdosboxUrl: "/wdosbox.js" }).ready(...); ``` +### Changing dosbox variant + +By changing wdosboxUrl (see above) you can select different dosbox variants: + +* `wdosbox.js` - default variant. This version compiled with latest emscripten and in theory should work best. +* `wdosbox-emterp.js` - This version compiled with legacy fastcomp backend, can be useful in rare cases (e.g. if you have problem with default version). +* `wdosbox-nosync.js` - Fastest possible version, but limited. You can't run console programs/shell emulation using it. + +```javascript + Dos(canvas, { wdosboxUrl: "/wdosbox-nosync.js" }).ready(...); +``` + ### How to handle errors You can handle errors by defining `onerror` property, or by using `catch` of promise. @@ -269,7 +283,9 @@ By default dosbox mouse will follow browser cursor without locking. It means tha Dos(canvas, { autolock: true }).ready((fs, main) => { main([...]); }); -// OR +``` +** OR ** +```javascript Dos(canvas).ready((fs, main) => { fs.createFile("dosbox.conf", ` [sdl] @@ -454,3 +470,10 @@ Output will be placed in dist folder. Also in dist folder you can find test page ``` firefox dist/test/test.html ``` + +Additionaly you can run same tests on other variants of js-dos (emterp, nosync). BUT, not all tests will pass. + +``` +firefox dist/test/test-emterp.html +firefox dist/test/test-nosync.html +``` diff --git a/dist/docs/api/js-dos-ts/js-dos-build.md b/dist/docs/api/js-dos-ts/js-dos-build.md index 5acccecd..895655e2 100644 --- a/dist/docs/api/js-dos-ts/js-dos-build.md +++ b/dist/docs/api/js-dos-ts/js-dos-build.md @@ -20,11 +20,11 @@ gulpfile.js --> generateBuildInfo ``` export const Build = { - version: "6.22.37 (2b23342d2ba488bb3653b8506b7e2667)", - jsVersion: "353e9136ae42c6641ab325375f89ac2f17245287", + version: "6.22.38 (4e5c30d285294adc0f9332460249b7d3)", + jsVersion: "3140a1c193a98193602c66e8094056dc3bb16b8f", jsSize: 199660, - wasmVersion: "eb83536935802be3c617c911dfce7e28", - wasmSize: 1809140, + wasmVersion: "ab1e5dfd0a5aa35a0ba806d5e2c8b3eb", + wasmSize: 1809135, }; diff --git a/dist/docs/api/js-dos-ts/js-dos-host.md b/dist/docs/api/js-dos-ts/js-dos-host.md index 05b3ca29..595298df 100644 --- a/dist/docs/api/js-dos-ts/js-dos-host.md +++ b/dist/docs/api/js-dos-ts/js-dos-host.md @@ -240,7 +240,7 @@ If dosbox is not yet resolved, then: responseType: "arraybuffer", progress: (total, loaded) => { if (module.onprogress) { - module.onprogress("Resolving DosBox", buildTotal, loaded); + module.onprogress("Resolving DosBox", buildTotal, Math.min(Build.wasmSize, loaded)); } }, fail: (url: string, status: number, message: string) => { @@ -301,7 +301,8 @@ If dosbox is not yet resolved, then: cache, progress: (total, loaded) => { if (module.onprogress) { - module.onprogress("Resolving DosBox", buildTotal, Build.wasmSize + loaded); + module.onprogress("Resolving DosBox", buildTotal, + Math.min(buildTotal, Build.wasmSize + loaded)); } }, fail: (url: string, status: number, message: string) => { diff --git a/dist/docs/api/js-dos-ts/js-dos-options.md b/dist/docs/api/js-dos-ts/js-dos-options.md index c2e8cedf..f7e80158 100644 --- a/dist/docs/api/js-dos-ts/js-dos-options.md +++ b/dist/docs/api/js-dos-ts/js-dos-options.md @@ -13,6 +13,21 @@ class, to configure emulation layer ``` export class DosBoxConfig { + +``` + + + + + + + +### cycles + + + + +``` public cycles?: number | string; ``` @@ -23,21 +38,27 @@ export class DosBoxConfig { - cycles: Amount of instructions DOSBox tries to emulate each millisecond. - Setting this value too high results in sound dropouts and lags. + Amount of instructions DOSBox tries to emulate each millisecond. + Setting this value too high results in sound dropouts and lags. + + Cycles can be set in 3 ways: + + * `auto` - tries to guess what a game needs. It usually works, but can fail for certain games. + * `fixed #number` - will set a fixed amount of cycles. This is what you +usually need if 'auto' fails. (Example: fixed 4000). + * `max` - will allocate as much cycles as your computer is able to handle. + - Cycles can be set in 3 ways: - 'auto' tries to guess what a game needs. - It usually works, but can fail for certain games. - 'fixed #number' will set a fixed amount of cycles. This is what you usually need if 'auto' fails. - (Example: fixed 4000). - 'max' will allocate as much cycles as your computer is able to handle. + +### autolock + + ``` @@ -51,7 +72,7 @@ export class DosBoxConfig { - autolock: Mouse will automatically lock, if you click on the screen. (Press CTRL-F10 to unlock) + Mouse will automatically lock, if you click on the screen. (Press CTRL-F10 to unlock) By default dosbox mouse will follow browser cursor without locking. It means that js-dos will not take exclusive control over mouse pointer. @@ -193,13 +214,19 @@ you can provide log function, to override logging, by default js-dos uses consol -you can set alternative url for downloading js-dos script, default is 'wdosbox.js' +you can set alternative url for downloading js-dos script, default is `wdosbox.js`. +Additionaly you can change which variant of js-dos script to use: + +* `wdosbox.js` - default variant. This version compiled with latest emscripten and in theory should work best +* `wdosbox-emterp.js` - This version compiled with legacy fastcomp backend, can be useful in rare cases +(e.g. if you have problems with default version) +* `wdosbox-nosync.js` - Fastest possible version, but limited. You can't run console programs/shell +emulation using it ``` - } export const DosBoxConfigDefaults: DosBoxConfig = { diff --git a/gulpfile.js b/gulpfile.js index 5bae638d..521d2f1c 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -54,16 +54,17 @@ gulp.task('generateBuildInfo', function() { }) gulp.task('copyAssets', function () { - return gulp.src(['test/index.html', 'build/wdosbox.js', 'build/wdosbox.js.symbols']) + return gulp.src(['test/index.html', 'build/wdosbox.js', 'build/wdosbox.js.symbols', + 'build/wdosbox-nosync.js', 'build/wdosbox-nosync.js.symbols', + 'build-emterp/wdosbox-emterp.js', 'build-emterp/wdosbox-emterp.js.symobls']) .pipe(gulp.dest('dist')); }); gulp.task('copyWasm', function () { - return gulp.src('build/wdosbox.wasm') - .pipe(rename("wdosbox.wasm.js")) + return gulp.src(['build/wdosbox.wasm', 'build/wdosbox-nosync.wasm', 'build-emterp/wdosbox-emterp.wasm']) + .pipe(rename({extname: ".wasm.js"})) .pipe(gulp.dest('dist')); }); - gulp.task('copyTypeScript', function() { return gulp.src('js-dos-ts/*') .pipe(gulp.dest('dist/typescript')); diff --git a/js-dos-ts/js-dos-build.ts b/js-dos-ts/js-dos-build.ts index d47014ac..2faa8622 100644 --- a/js-dos-ts/js-dos-build.ts +++ b/js-dos-ts/js-dos-build.ts @@ -3,9 +3,9 @@ // gulpfile.js --> generateBuildInfo export const Build = { - version: "6.22.37 (2b23342d2ba488bb3653b8506b7e2667)", - jsVersion: "353e9136ae42c6641ab325375f89ac2f17245287", + version: "6.22.38 (4e5c30d285294adc0f9332460249b7d3)", + jsVersion: "3140a1c193a98193602c66e8094056dc3bb16b8f", jsSize: 199660, - wasmVersion: "eb83536935802be3c617c911dfce7e28", - wasmSize: 1809140, + wasmVersion: "ab1e5dfd0a5aa35a0ba806d5e2c8b3eb", + wasmSize: 1809135, }; diff --git a/js-dos-ts/js-dos-host.ts b/js-dos-ts/js-dos-host.ts index 23a9240c..f3176054 100644 --- a/js-dos-ts/js-dos-host.ts +++ b/js-dos-ts/js-dos-host.ts @@ -133,7 +133,7 @@ class DosHost { responseType: "arraybuffer", progress: (total, loaded) => { if (module.onprogress) { - module.onprogress("Resolving DosBox", buildTotal, loaded); + module.onprogress("Resolving DosBox", buildTotal, Math.min(Build.wasmSize, loaded)); } }, fail: (url: string, status: number, message: string) => { @@ -166,7 +166,8 @@ class DosHost { cache, progress: (total, loaded) => { if (module.onprogress) { - module.onprogress("Resolving DosBox", buildTotal, Build.wasmSize + loaded); + module.onprogress("Resolving DosBox", buildTotal, + Math.min(buildTotal, Build.wasmSize + loaded)); } }, fail: (url: string, status: number, message: string) => { diff --git a/js-dos-ts/js-dos-options.ts b/js-dos-ts/js-dos-options.ts index 723d83ee..58801e03 100644 --- a/js-dos-ts/js-dos-options.ts +++ b/js-dos-ts/js-dos-options.ts @@ -4,22 +4,22 @@ // class, to configure emulation layer export class DosBoxConfig { +// ### cycles public cycles?: number | string; -// cycles: Amount of instructions DOSBox tries to emulate each millisecond. -// Setting this value too high results in sound dropouts and lags. +// Amount of instructions DOSBox tries to emulate each millisecond. +// Setting this value too high results in sound dropouts and lags. // -// Cycles can be set in 3 ways: +// Cycles can be set in 3 ways: // -// 'auto' tries to guess what a game needs. -// It usually works, but can fail for certain games. -// -// 'fixed #number' will set a fixed amount of cycles. This is what you usually need if 'auto' fails. -// (Example: fixed 4000). -// -// 'max' will allocate as much cycles as your computer is able to handle. +// * `auto` - tries to guess what a game needs. It usually works, but can fail for certain games. +// * `fixed #number` - will set a fixed amount of cycles. This is what you +// usually need if 'auto' fails. (Example: fixed 4000). +// * `max` - will allocate as much cycles as your computer is able to handle. // + +// ### autolock public autolock?: boolean; -// autolock: Mouse will automatically lock, if you click on the screen. (Press CTRL-F10 to unlock) +// Mouse will automatically lock, if you click on the screen. (Press CTRL-F10 to unlock) // // By default dosbox mouse will follow browser cursor without locking. // It means that js-dos will not take exclusive control over mouse pointer. @@ -56,8 +56,14 @@ export class DosOptions extends DosBoxConfig { // ### wdosboxUrl public wdosboxUrl?: string; - // you can set alternative url for downloading js-dos script, default is 'wdosbox.js' - + // you can set alternative url for downloading js-dos script, default is `wdosbox.js`. + // Additionaly you can change which variant of js-dos script to use: + // + // * `wdosbox.js` - default variant. This version compiled with latest emscripten and in theory should work best + // * `wdosbox-emterp.js` - This version compiled with legacy fastcomp backend, can be useful in rare cases + // (e.g. if you have problems with default version) + // * `wdosbox-nosync.js` - Fastest possible version, but limited. You can't run console programs/shell + // emulation using it } export const DosBoxConfigDefaults: DosBoxConfig = { diff --git a/package.json b/package.json index 8d757713..71cf69a0 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "js-dos", - "version": "6.22.37", + "version": "6.22.38", "description": "Easiest API to run dos programs in browser", "main": "dist/js-dos.js", "types": "dist/typescript/js-dos.ts", diff --git a/test/test-emterp.html b/test/test-emterp.html index 77e2af52..e7211ce6 100644 --- a/test/test-emterp.html +++ b/test/test-emterp.html @@ -12,6 +12,7 @@