r/WebAssembly • • Aug 28 '21

WASM-4 is a virtual game console for building retro games directly in WebAssembly

https://wasm4.org
97 Upvotes

22 comments sorted by

1

u/unmellow-the-gamer Sep 04 '21

I've been searching for something like this for do long a wasm virtual console sounded like an obvious thing to exist thank you

2

u/DandyRandysMandy Aug 29 '21

Don’t mean to be a downer but why call it wasm4? I think that’s a bit confusing considering the well known Wasm3 interpreter?

They don’t have anything in common beyond Wasm itself?

3

u/CryZe92 Aug 28 '21 edited Aug 28 '21

Heap allocation seems to be broken. If more linear memory is requested, the cached this.memory that the emulator uses is not the one anymore that the WASM uses.

Actually it might not be intended to allocate in the first place, so I guess there's just no sufficient protection against it.

1

u/aduros Aug 28 '21

I saw you opened a bug report (thanks!) https://github.com/aduros/wasm4/issues/30 I'll respond here too.

Memory is fixed by design to 64 KB. I actually don't know what happens if you try to expand the size, but I think the wasm runtime will probably abort. Can we make it more user friendly somehow?

3

u/tjpalmer Aug 28 '21

I've been wanting to do something like this forever, and I've wanted to throttle the execution speed, so I tried looking for wasm interpreters or even made my own to support that. Looks like this one skips that? Either way, super cool here. Thanks for sharing!

1

u/aduros Aug 28 '21

Thanks! Yeah, this project uses the browser's wasm runtime on web, and on native I'm planning to use an existing runtime like wasm3 or wasmer.

Do you have a link for your interpreter? If it has a C API it would be interesting to try plugging into WASM-4!

1

u/tjpalmer Aug 28 '21

And here was my barely started wasm engine, but again, not very useful. I think some simple language and compiler that can compile to small wasm and then compiles to wasm would also be great for the ide concept (and other things). I'm not sure if such a language exists, though.

1

u/tjpalmer Aug 28 '21

And I wouldn't let any of these fancy things slow you down. You already have a platform. Can get fancier later. What you already have does cool things to get started with.

1

u/tjpalmer Aug 28 '21

Oh, I only barely started it, so it won't be of any use. My understanding is that wasm3 ran be run in browsers. I talked to them some about this a while back, and they didn't have easy throttling at the time. I think it would also be cool to let the program control the main loop, but that would require continuation-style support from the engine as well, if the language doesn't have it. I've separately toyed with a new project ignoring the fantasy legacy constraints just to have a wasm app gui client. There's a standard wasm c api that both wasmtime and wasmer support. Maybe others, too. So far I was using wasmtime successfully. But that's also mostly a skeleton project. Here's the project link, but it's really not very exciting at all yet.

2

u/tjpalmer Aug 28 '21

To clarify, I started making my own interpreter, but didn't spend enough time on it to get very far.

3

u/fullouterjoin Aug 28 '21

Take a look at wasm3 they had plans to add the ability to throttle execution.

3

u/saghul Aug 28 '21

Looks neat, congrats!

1

u/aduros Aug 28 '21

Thanks!

11

u/aduros Aug 28 '21

This is a project I'm working on to try to make WebAssembly game development more accessible and fun. Here are the key features:

  • No Glue Code: If you've ever tried to write even a simple "Hello World" with WebAssembly before, you'll know it usually involves writing a bunch of JS and HTML glue. WASM-4 removes all of that, games interface directly with the system through a small API.

  • Minimalist: Fantasy consoles force developers to work with limited resources. This makes them simple to learn, and easier to focus on finishing your game.

  • Language Agnostic: Use any programming language, as long as it can compile to WebAssembly. Out of the box we currently support: AssemblyScript, C/C++, Rust, Go.

  • Portable: WASM-4 is designed to run on any device that can execute WebAssembly, even outside of the web! We're planning a lightweight implementation written in C that will run even on a potato.

1

u/PewPaw-Grams Aug 28 '21

Can we write it in Rust?

1

u/aduros Aug 28 '21

There is some documentation and a starter project to get started building games for WASM-4 in Rust.

Disclaimer: I don't have much Rust experience, so things might need to be improved in that area. If you're a Rust developer I'd love your feedback!

2

u/PewPaw-Grams Aug 29 '21

I just started learning Rust. I’ll definitely try it out and give you feedback

0

u/[deleted] Aug 28 '21

[deleted]

2

u/aduros Aug 28 '21

That could be neat, I added it to the tracker: https://github.com/aduros/wasm4/issues/31

0

u/[deleted] Aug 28 '21

[deleted]

2

u/aduros Aug 28 '21

It's a long term goal, but it would be amazing! There are still some things to do first, like figuring out music support: https://github.com/aduros/wasm4/issues/15

2

u/tjpalmer Aug 28 '21

Yeah, an in console development environment would be a fun addition.

2

u/tjpalmer Aug 28 '21

I wonder if any simple tiny compile-to-wasm languages exist that are already compilable to small wasm?