4 ms·
Writing a CHIP-8 Emulator with Rust and WebAssembly
- kodablah 9y agoIt's not done here, but I've had success returning/accepting pointers over the Rust/JS boundary [0] using Box w/ raw pointers and mem::forget as necessary. They are just JS ints to places in the mem array like the mem refs in this blog. This can help you not require the "Cpu" instance as a static singleton but instead instantiate it as needed. 0 - https://github.com/cretz/asmble/blob/master/examples/rust-regex/src/lib.rs https://github.com/cretz/asmble/blob/master/examples/rust-re...
- inferiorhuman 9y agoYeah I've used malloc+free+forget as well to allocate multi-megabyte strings (JSON encoded objects) to exchange data between JS and rust. Seems to work a treat.
- harel 9y agoExcellent! More and more posts like this push me to start learning rust by doing a WebAssembly project. Thank you.
- adefa 9y agoVery cool! I also started writing a CHIP-8 emulator in Rust, though I had some problems getting graphics working with SDL. https://github.com/TrevorS/rustychip8 https://github.com/TrevorS/rustychip8