wasm4 icon indicating copy to clipboard operation
wasm4 copied to clipboard

Could we get usable API functions for ALL registers vs RAW pointers?

Open joshgoebel opened this issue 4 years ago • 1 comments

This would make it easier to port WASM-4 goes too and from other platforms since one only needs to stub out the API.

Examples (in Zig)

Now:

pub const SYSTEM_FLAGS: *u8 = @intToPtr(*u8, 0x1f);

After:


pub const SYSTEM_FLAGS: *u8 = @intToPtr(*u8, 0x1f);
pub fn setSystemFlags(flag: u8) void {
  SYSTEM_FLAGS.* |= flag;
}
pub fn unsetSystemFlags(flag: u8) void {
  // ...
}

Porting to another platform would then only require implementing an equivalent (or stub) setSystemFlags function... and of course the compiler would likely optimize this down to nothing (by inlining the code) anyways, so I don't see a downside?

joshgoebel avatar Dec 27 '21 16:12 joshgoebel

Unless I've mistaken your intention, I don't see how this makes porting games easier unless you also force developers to use the getters and setters (and to never touch registers directly). This becomes pretty impractical for things like FRAMEBUFFER where voodoo with the raw data is less uncommon. Therefore, I'd say implementing the memory registers in a non-WASM runtime is actually easier than implementing the functions you proposed: just point the pointers in wasm.h to variables rather than absolute memory addresses and do what the current WASM-4 runtimes do with the data in them. I've started work on exactly this just for fun and it works great so far, so shoot me a message if you have any questions about how it could be done in practice.

JerwuQu avatar Feb 03 '22 11:02 JerwuQu