pete-gordon / oricutron

Portable Oric-1/Atmos/Telestrat and Pravetz 8D emulator
http://www.petergordon.org.uk/oricutron/
GNU General Public License v2.0
69 stars 25 forks source link

How are .dsk files passed to OricutronJS upon clicking link to oricutron.html? #186

Closed jumpjack closed 1 year ago

jumpjack commented 1 year ago

I can't understand How .dsk files are passed to OricutronJS upon clicking a link to oricutron.html; I know how to load a .dsk file from local hard disk or remote server, and I would like to pass it to the emulator.

hialmar commented 1 year ago

The web app downloads the dsk and then puts it in the browser local storage: https://github.com/pete-gordon/oricutron/blob/www/main.c#L1823 https://github.com/pete-gordon/oricutron/blob/www/main.c#L1784 Then the emulator accesses it (in read and write mode) in the browser local storage which is mounted into the memory of the web app: https://github.com/pete-gordon/oricutron/blob/www/main.c#L1908

The details of what I used is presented in emscripten doc here: https://emscripten.org/docs/api_reference/fetch.html https://emscripten.org/docs/api_reference/Filesystem-API.html

jumpjack commented 1 year ago

Thanks but I'm stuck one step before: how does the webapp know that the filename to download is myfile.dsk? I just click this link in index.hml:

<a href="oricutron.html">myfile.dsk</a>

... and "magically" webapp receives the filename, but I don't understand how.

Unfortunately I don't know anything about wasm and emscripten.. I did put some dozens of console.log() commands in oricutron.js , but I can't yet find the moment when "myfile.dsk" string is passed to webapp.

hialmar commented 1 year ago

In the index.html I copy the filename in the sessionstorage: https://github.com/pete-gordon/oricutron/blob/www/www/index.html#L24

Then in oricutron.html I get the file name from the sessionstorage and copy it to the emulator's environment: https://github.com/pete-gordon/oricutron/blob/www/www/oricutron.html#L191

Lastly, in the emulator code I retrieve the filename from the environment: https://github.com/pete-gordon/oricutron/blob/www/main.c#L1826

iss000 commented 1 year ago

Not an issue.