floooh / chips-test

Tests and sample code for https://github.com/floooh/chips
MIT License
387 stars 46 forks source link

JavaScript API to control the computer? #30

Closed karlvr closed 7 months ago

karlvr commented 1 year ago

Is there a JavaScript API that I can use to load a file when the user clicks a button? Or to type some text? I feel like there is or nearly is!

floooh commented 1 year ago

Doesn't exist unfortunately.

It would be quite trivial to add (I did this in my older emulators which have an HTML UI overlay (https://floooh.github.io/virtualkc/), but didn't get around adding the same to the chips emulators.

karlvr commented 1 year ago

@floooh thank you, I'm happy to have a crack at it. I'll take a look this weekend. If there are any other pointers you think would help me end up somewhere you're happy with (in case it turns into a PR?) let me know, otherwise I'll report back with what happens!

karlvr commented 8 months ago

@floooh hiya, it's like half a year on and I didn't make any progress on this... I'm still interested though. Do you have a moment to give me a bit more of a pointer for adding this?

floooh commented 8 months ago

Right, in the meantime such a Javascript API exists, I added this when creating this VSCode extension:

https://marketplace.visualstudio.com/items?itemName=floooh.vscode-kcide

The basic C code to implement this "web API" is here:

https://github.com/floooh/chips-test/blob/master/examples/common/webapi.c

https://github.com/floooh/chips-test/blob/master/examples/common/webapi.h

...with a specific implementation for the KC85 emulators here:

https://github.com/floooh/chips-test/blob/b0c6513ff0d6d1ac10c00cc09acfdc76a95e82de/examples/sokol/kc85.c#L532-L690

...and the Javascript glue code between the VSCode extension and WASM emulator is here (this shows how to call C functions via Module._func_name():

https://github.com/floooh/vscode-kcide/blob/0e86a4a6046b17c3262c03ca1b5cc6eea46aa5a2/media/shell.js#L25-L216

karlvr commented 7 months ago

@floooh thanks for the above, I'm able to make progress with it so I'll close up this issue.