Accessing FileSystem in js-dos

powersoffour 02/18/2021

First prototype of dosbox-in-jupyterlab working.

Image

@caiiiycuk Would you be open to exposing a bit of the webassembly module instance on DosWorker, for instance the filesystem? Or, have some semi-private/protected way of getting right at the module instance?

caiiiycuk 02/18/2021

It’s straightforward for DosDirect, you can use filesystem API from emscripten. But for DosWorker we need to add API layer to create/update/delete files, because you need to send/recv messages to/from worker thread. However this api should be useful, can you say which fs api you need?

powersoffour 02/18/2021

@caiiiycuk Just being able to list, read, and write (and I suppose delete?) would be amazing. I’ll probably get started with DosDirect for now. Would a proxy system like GitHub - GoogleChromeLabs/comlink: Comlink makes WebWorkers enjoyable. make this easier? What I’m eventually hoping to use this for is debugging and as a tool for disassembly; being able to access the internal DOS state (even just SaveMemory from debug.cpp) from JS, and then syncing it back to the python kernel, would be pretty exciting.

GitHub

GoogleChromeLabs/comlink

Comlink makes WebWorkers enjoyable. Contribute to GoogleChromeLabs/comlink development by creating an account on GitHub.

Image

caiiiycuk 02/18/2021

When you use direct, you can access emscripten module through ci.module var and then use emscripten FS api that have everything you need File System API — Emscripten 3.1.3-git (dev) documentation Regarding to debug features, if you want to activate something that built in dosbox then you need to recompile emulators wasm files with enabled debugging. However, if you just need to read process memory you can easily do it by using ci.module.HEAP8 (or HEAPU8, HEAP32, HEAPU32, …)

powersoffour 02/18/2021

@caiiiycuk I was thinking getting the process memory. I think getting the integer value of MemBase and the contents of CPU_Regs might be sufficient. I’m going to experiment with getting this info via some EM_JS functions to see if it’s productive… getting the MemBase and the segment/register info, then using that to index the HEAP might be enough to get a pretty complete memory dump.

caiiiycuk 02/18/2021

Actually while we stay in Direct emulation it’s pretty easy task

You can access arbitrary c/c++ function from javascript. I mean you can easily call c/c++ function from js. So you can add cpp file to direct.cmake with following content:

extern "C" size_t EMSCRIPTEN_KEEPALIVE getMemBase() {
...
}

and then in js you can call it like ci.module._getMemBase() and it will return what you need

powersoffour 02/18/2021

@caiiiycuk outstanding – thank you so much for your help with this. I’m going to try this right away. Your docker file was really helpful for building, by the way. If I get this to work I’ll issue a PR to your repo that you can accept/decline, in case it’s interesting.

  • caiiiycuk 02/18/2021

regarding to docker, many thanks to @rodlo

powersoffour 02/18/2021

@rodlo thank you!

caiiiycuk 02/18/2021

so when you add this c++ file you need to gulp, and then fom dist folder you should cp wdirect* to your frontend. But it’s important to update version in packages.json because everything is cached in indexed db. so you need to up version each time, or remove database using borwser console. I usually use private tab for testing, anyway you need drop db each time even in private tab

powersoffour 02/18/2021

oh, thanks – I definitely would have messed that up.