import {
call,
drop,
func,
i32,
importFunc,
importMemory,
Module,
} from "wasmati";
import { writeFileSync } from "fs";
function main() {
const memory = importMemory({ min: 4, max: 4 });
const cls = importFunc({ in: [i32], out: [] }, () => {});
const print = importFunc(
{ in: [i32, i32, i32, i32, i32, i32, i32], out: [i32] },
() => {}
);
const TIC = func({ in: [], out: [], locals: [] }, ([], [], _ctx) => {
call(cls, [13]);
call(print, [0, 84, 61, 15, 0, 1, 0]);
drop();
});
const module = Module({
exports: { TIC },
memory,
});
const wasm = module.toBytes();
writeFileSync("dist/cart.wasm", wasm);
}
main();
Thanks for the project!
I'm trying to generate WASM for TIC-80. I have encountered the following issues while trying to generate a hello world using wasmati:
I don't see how to import the memory.
importMemorydoesn't seem to take module/name parameters. My current result from wasmati looks like the following.One needs to do the following to gain access to the 256 KiB of memory TIC-80 provides.
I don't see how to import functions.
importFuncdoesn't seem to take module/name parameters, and it takes a JavaScript function parameter which I can't provide. My current result from wasmati looks like the following:Examples of importing functions provided by TIC-80:
I don't see how to add data with a starting offset. The content parameter to
importMemoryseems to write starting from zero.In TIC-80, The first 96 KiB are reserved for things such as video RAM and I/O. To write data into the beginning of the free RAM, one needs to do the following.
Apologies if I have missed how to do these things correctly.
A hello world in WAT
My closest attempt at implementing it using wasmati
The output from the above