Compare commits
3 Commits
45f4ddb4c4
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
| 169ae3d908 | |||
| 043096d54d | |||
| c66977023b |
4
Makefile
4
Makefile
@@ -1,11 +1,11 @@
|
||||
WASM3_C := $(wildcard wasm3/source/*.c)
|
||||
WASM3_O := $(WASM3_C:.c=.o)
|
||||
|
||||
uw8-wasm3: main.o $(WASM3_O) platform.o wasm-rt-impl.o
|
||||
uw8-wasm3: main.o $(WASM3_O) platform.o loader.o wasm-rt-impl.o
|
||||
gcc -g -lm -lSDL2 -o uw8-wasm3 $^
|
||||
|
||||
run: uw8-wasm3 .PHONY
|
||||
./uw8-wasm3 never_sleeps.uw8
|
||||
./uw8-wasm3 skipahead.uw8
|
||||
|
||||
run-ts:
|
||||
deno run --allow-read main.ts
|
||||
|
||||
54
loader.h
Normal file
54
loader.h
Normal file
@@ -0,0 +1,54 @@
|
||||
/* Automatically generated by wasm2c */
|
||||
#ifndef LOADER_H_GENERATED_
|
||||
#define LOADER_H_GENERATED_
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#include "wasm-rt.h"
|
||||
|
||||
/* TODO(binji): only use stdint.h types in header */
|
||||
#ifndef WASM_RT_CORE_TYPES_DEFINED
|
||||
#define WASM_RT_CORE_TYPES_DEFINED
|
||||
typedef uint8_t u8;
|
||||
typedef int8_t s8;
|
||||
typedef uint16_t u16;
|
||||
typedef int16_t s16;
|
||||
typedef uint32_t u32;
|
||||
typedef int32_t s32;
|
||||
typedef uint64_t u64;
|
||||
typedef int64_t s64;
|
||||
typedef float f32;
|
||||
typedef double f64;
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
struct Z_env_instance_t;
|
||||
extern wasm_rt_memory_t* Z_envZ_memory(struct Z_env_instance_t*);
|
||||
|
||||
typedef struct Z_loader_instance_t {
|
||||
/* import: 'env' 'memory' */
|
||||
wasm_rt_memory_t *Z_envZ_memory;
|
||||
u32 w2c_g0;
|
||||
u32 w2c_g1;
|
||||
u32 w2c_g2;
|
||||
} Z_loader_instance_t;
|
||||
|
||||
void Z_loader_init_module(void);
|
||||
void Z_loader_instantiate(Z_loader_instance_t*, struct Z_env_instance_t*);
|
||||
void Z_loader_free(Z_loader_instance_t*);
|
||||
|
||||
|
||||
/* export: 'load_uw8' */
|
||||
u32 Z_loaderZ_load_uw8(Z_loader_instance_t*, u32);
|
||||
|
||||
/* export: 'uncompress' */
|
||||
u32 Z_loaderZ_uncompress(Z_loader_instance_t*, u32, u32);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* LOADER_H_GENERATED_ */
|
||||
BIN
loader.wasm
BIN
loader.wasm
Binary file not shown.
271
main.c
271
main.c
@@ -1,5 +1,6 @@
|
||||
#include "wasm3/source/wasm3.h"
|
||||
#include "wasm3/source/m3_env.h"
|
||||
#include "loader.h"
|
||||
#include "platform.h"
|
||||
#include "SDL2/SDL.h"
|
||||
#include "SDL2/SDL_video.h"
|
||||
@@ -92,19 +93,48 @@ void linkSystemFunctions(IM3Runtime runtime, IM3Module mod) {
|
||||
}
|
||||
}
|
||||
|
||||
m3ApiRawFunction(platformTrampoline) {
|
||||
IM3Function func = (IM3Function)_ctx->userdata;
|
||||
uint32_t retCount = m3_GetRetCount(func);
|
||||
uint32_t argCount = m3_GetArgCount(func);
|
||||
const void* args[16];
|
||||
for(uint32_t i = 0; i < argCount; ++i) {
|
||||
args[i] = &_sp[retCount + i];
|
||||
}
|
||||
verifyM3(runtime, m3_Call(func, m3_GetArgCount(func), args));
|
||||
for(uint32_t i = 0; i < retCount; ++i) {
|
||||
args[i] = &_sp[i];
|
||||
}
|
||||
verifyM3(runtime, m3_GetResults(func, retCount, args));
|
||||
m3ApiRawFunction(callFmod) {
|
||||
*(f32*)&_sp[0] = Z_platformZ_fmod((Z_platform_instance_t*)_ctx->userdata, *(f32*)&_sp[1], *(f32*)&_sp[2]);
|
||||
m3ApiSuccess();
|
||||
}
|
||||
|
||||
m3ApiRawFunction(callRandom) {
|
||||
_sp[0] = Z_platformZ_random((Z_platform_instance_t*)_ctx->userdata);
|
||||
m3ApiSuccess();
|
||||
}
|
||||
|
||||
m3ApiRawFunction(callRandomf) {
|
||||
*(f32*)&_sp[0] = Z_platformZ_randomf((Z_platform_instance_t*)_ctx->userdata);
|
||||
m3ApiSuccess();
|
||||
}
|
||||
|
||||
m3ApiRawFunction(callRandomSeed) {
|
||||
Z_platformZ_randomSeed((Z_platform_instance_t*)_ctx->userdata, _sp[0]);
|
||||
m3ApiSuccess();
|
||||
}
|
||||
|
||||
m3ApiRawFunction(callCls) {
|
||||
Z_platformZ_cls((Z_platform_instance_t*)_ctx->userdata, _sp[0]);
|
||||
m3ApiSuccess();
|
||||
}
|
||||
|
||||
m3ApiRawFunction(callSetPixel) {
|
||||
Z_platformZ_setPixel((Z_platform_instance_t*)_ctx->userdata, _sp[0], _sp[1], _sp[2]);
|
||||
m3ApiSuccess();
|
||||
}
|
||||
|
||||
m3ApiRawFunction(callGetPixel) {
|
||||
_sp[0] = Z_platformZ_getPixel((Z_platform_instance_t*)_ctx->userdata, _sp[1], _sp[2]);
|
||||
m3ApiSuccess();
|
||||
}
|
||||
|
||||
m3ApiRawFunction(callHline) {
|
||||
Z_platformZ_hline((Z_platform_instance_t*)_ctx->userdata, _sp[0], _sp[1], _sp[2], _sp[3]);
|
||||
m3ApiSuccess();
|
||||
}
|
||||
|
||||
m3ApiRawFunction(callRectangle) {
|
||||
Z_platformZ_rectangle((Z_platform_instance_t*)_ctx->userdata, *(f32*)&_sp[0], *(f32*)&_sp[1], *(f32*)&_sp[2], *(f32*)&_sp[3],_sp[4]);
|
||||
m3ApiSuccess();
|
||||
}
|
||||
|
||||
@@ -113,73 +143,140 @@ m3ApiRawFunction(callCircle) {
|
||||
m3ApiSuccess();
|
||||
}
|
||||
|
||||
m3ApiRawFunction(callRectangleOutline) {
|
||||
Z_platformZ_rectangleOutline((Z_platform_instance_t*)_ctx->userdata, *(f32*)&_sp[0], *(f32*)&_sp[1], *(f32*)&_sp[2], *(f32*)&_sp[3],_sp[4]);
|
||||
m3ApiSuccess();
|
||||
}
|
||||
|
||||
m3ApiRawFunction(callCircleOutline) {
|
||||
Z_platformZ_circleOutline((Z_platform_instance_t*)_ctx->userdata, *(f32*)&_sp[0], *(f32*)&_sp[1], *(f32*)&_sp[2], _sp[3]);
|
||||
m3ApiSuccess();
|
||||
}
|
||||
|
||||
m3ApiRawFunction(callLine) {
|
||||
Z_platformZ_line((Z_platform_instance_t*)_ctx->userdata, *(f32*)&_sp[0], *(f32*)&_sp[1], *(f32*)&_sp[2], *(f32*)&_sp[3],_sp[4]);
|
||||
m3ApiSuccess();
|
||||
}
|
||||
|
||||
m3ApiRawFunction(callBlitSprite) {
|
||||
Z_platformZ_blitSprite((Z_platform_instance_t*)_ctx->userdata, _sp[0], _sp[1], _sp[2], _sp[3], _sp[4]);
|
||||
m3ApiSuccess();
|
||||
}
|
||||
|
||||
m3ApiRawFunction(callGrabSprite) {
|
||||
Z_platformZ_grabSprite((Z_platform_instance_t*)_ctx->userdata, _sp[0], _sp[1], _sp[2], _sp[3], _sp[4]);
|
||||
m3ApiSuccess();
|
||||
}
|
||||
|
||||
m3ApiRawFunction(callIsButtonPressed) {
|
||||
_sp[0] = Z_platformZ_isButtonPressed((Z_platform_instance_t*)_ctx->userdata, _sp[1]);
|
||||
m3ApiSuccess();
|
||||
}
|
||||
|
||||
m3ApiRawFunction(callIsButtonTriggered) {
|
||||
_sp[0] = Z_platformZ_isButtonTriggered((Z_platform_instance_t*)_ctx->userdata, _sp[1]);
|
||||
m3ApiSuccess();
|
||||
}
|
||||
|
||||
m3ApiRawFunction(callTime) {
|
||||
*(f32*)&_sp[0] = Z_platformZ_time((Z_platform_instance_t*)_ctx->userdata);
|
||||
m3ApiSuccess();
|
||||
}
|
||||
|
||||
m3ApiRawFunction(callPrintChar) {
|
||||
Z_platformZ_printChar((Z_platform_instance_t*)_ctx->userdata, _sp[0]);
|
||||
m3ApiSuccess();
|
||||
}
|
||||
|
||||
m3ApiRawFunction(callPrintString) {
|
||||
Z_platformZ_printString((Z_platform_instance_t*)_ctx->userdata, _sp[0]);
|
||||
m3ApiSuccess();
|
||||
}
|
||||
|
||||
m3ApiRawFunction(callPrintInt) {
|
||||
Z_platformZ_printInt((Z_platform_instance_t*)_ctx->userdata, _sp[0]);
|
||||
m3ApiSuccess();
|
||||
}
|
||||
|
||||
m3ApiRawFunction(callSetTextColor) {
|
||||
Z_platformZ_setTextColor((Z_platform_instance_t*)_ctx->userdata, _sp[0]);
|
||||
m3ApiSuccess();
|
||||
}
|
||||
|
||||
m3ApiRawFunction(callSetBackgroundColor) {
|
||||
Z_platformZ_setBackgroundColor((Z_platform_instance_t*)_ctx->userdata, _sp[0]);
|
||||
m3ApiSuccess();
|
||||
}
|
||||
|
||||
m3ApiRawFunction(callSetCursorPosition) {
|
||||
Z_platformZ_setCursorPosition((Z_platform_instance_t*)_ctx->userdata, _sp[0], _sp[1]);
|
||||
m3ApiSuccess();
|
||||
}
|
||||
|
||||
m3ApiRawFunction(callSndGes) {
|
||||
*(f32*)&_sp[0] = Z_platformZ_sndGes((Z_platform_instance_t*)_ctx->userdata, _sp[1]);
|
||||
m3ApiSuccess();
|
||||
}
|
||||
|
||||
m3ApiRawFunction(callPlayNote) {
|
||||
Z_platformZ_playNote((Z_platform_instance_t*)_ctx->userdata, _sp[0], _sp[1]);
|
||||
m3ApiSuccess();
|
||||
}
|
||||
|
||||
struct {
|
||||
const char* name;
|
||||
const char* signature;
|
||||
M3RawCall function;
|
||||
} cPlatformFunctions[] = {
|
||||
{ "fmod", "f(ff)", callFmod },
|
||||
{ "random", "i()", callRandom },
|
||||
{ "randomf", "f()", callRandomf },
|
||||
{ "randomSeed", "v(i)", callRandomSeed },
|
||||
{ "cls", "v(i)", callCls },
|
||||
{ "setPixel", "v(iii)", callSetPixel },
|
||||
{ "getPidel", "i(ii)", callGetPixel },
|
||||
{ "hline", "v(iiii)", callHline },
|
||||
{ "rectangle", "v(ffffi)", callRectangle },
|
||||
{ "circle", "v(fffi)", callCircle },
|
||||
{ "blitSprite", "v(iiiii)", callBlitSprite }
|
||||
{ "rectangleOutline", "v(ffffi)", callRectangleOutline },
|
||||
{ "circleOutline", "v(fffi)", callCircleOutline },
|
||||
{ "line", "v(ffffi)", callLine },
|
||||
{ "blitSprite", "v(iiiii)", callBlitSprite },
|
||||
{ "grabSprite", "v(iiiii)", callGrabSprite },
|
||||
{ "isButtonPressed", "i(i)", callIsButtonPressed },
|
||||
{ "isButtonTriggered", "i(i)", callIsButtonTriggered},
|
||||
{ "time", "f()", callTime },
|
||||
{ "printChar", "v(i)", callPrintChar },
|
||||
{ "printString", "v(i)", callPrintString },
|
||||
{ "printInt", "v(i)", callPrintInt },
|
||||
{ "setTextColor", "v(i)", callSetTextColor },
|
||||
{ "setBackgroundColor", "v(i)", callSetBackgroundColor },
|
||||
{ "setCursorPosition", "v(ii)", callSetCursorPosition },
|
||||
{ "playNote", "v(ii)", callPlayNote },
|
||||
{ "sndGes", "f(i)", callSndGes }
|
||||
};
|
||||
|
||||
void appendType(char* signature, M3ValueType type) {
|
||||
if(type == c_m3Type_i32) {
|
||||
strcat(signature, "i");
|
||||
} else if(type == c_m3Type_i64) {
|
||||
strcat(signature, "l");
|
||||
} else if(type == c_m3Type_f32) {
|
||||
strcat(signature, "f");
|
||||
} else {
|
||||
fprintf(stderr, "Unsupported platform type %d\n", type);
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
void linkPlatformFunctions(IM3Runtime runtime, IM3Module cartMod, IM3Module platformMod, Z_platform_instance_t* platformInstance) {
|
||||
for(u32 functionIndex = 0; functionIndex < platformMod->numFunctions; ++functionIndex) {
|
||||
M3Function function = platformMod->functions[functionIndex];
|
||||
if(function.export_name != NULL) {
|
||||
bool foundCImpl = false;
|
||||
void linkPlatformFunctions(IM3Runtime runtime, IM3Module cartMod, Z_platform_instance_t* platformInstance) {
|
||||
for(int i = 0; i * sizeof(cPlatformFunctions[0]) < sizeof(cPlatformFunctions); ++i) {
|
||||
if(strcmp(function.export_name, cPlatformFunctions[i].name) == 0) {
|
||||
m3_LinkRawFunctionEx(cartMod, "env", function.export_name, cPlatformFunctions[i].signature, cPlatformFunctions[i].function, platformInstance);
|
||||
foundCImpl = true;
|
||||
}
|
||||
}
|
||||
if(!foundCImpl) {
|
||||
IM3Function iFunc;
|
||||
verifyM3(runtime, m3_FindFunction(&iFunc, runtime, function.export_name));
|
||||
char signature[128] = { 0 };
|
||||
if(m3_GetRetCount(iFunc) > 0) {
|
||||
appendType(signature, m3_GetRetType(iFunc, 0));
|
||||
} else {
|
||||
strcat(signature, "v");
|
||||
}
|
||||
strcat(signature, "(");
|
||||
for(uint32_t i = 0; i < m3_GetArgCount(iFunc); ++i) {
|
||||
appendType(signature, m3_GetArgType(iFunc, i));
|
||||
}
|
||||
strcat(signature, ")");
|
||||
m3_LinkRawFunctionEx(cartMod, "env", function.export_name, signature, platformTrampoline, iFunc);
|
||||
}
|
||||
}
|
||||
m3_LinkRawFunctionEx(cartMod, "env", cPlatformFunctions[i].name, cPlatformFunctions[i].signature, cPlatformFunctions[i].function, platformInstance);
|
||||
}
|
||||
}
|
||||
|
||||
void* loadUw8(uint32_t* sizeOut, IM3Runtime runtime, IM3Function loadFunc, const char* filename) {
|
||||
void* loadUw8(uint32_t* sizeOut, IM3Runtime runtime, const char* filename) {
|
||||
size_t uw8Size;
|
||||
void* uw8 = loadFile(&uw8Size, filename);
|
||||
uint8_t* memory = m3_GetMemory(runtime, NULL, 0);
|
||||
memcpy(memory, uw8, uw8Size);
|
||||
verifyM3(runtime, m3_CallV(loadFunc, (uint32_t)uw8Size));
|
||||
verifyM3(runtime, m3_GetResultsV(loadFunc, sizeOut));
|
||||
|
||||
wasm_rt_memory_t memory;
|
||||
memory.data = m3_GetMemory(runtime, NULL, 0);
|
||||
memory.max_pages = memory.pages = 4;
|
||||
memory.size = 4 * 65536;
|
||||
Z_loader_instance_t loader;
|
||||
Z_loader_instantiate(&loader, (struct Z_env_instance_t*)&memory);
|
||||
|
||||
memcpy(memory.data, uw8, uw8Size);
|
||||
*sizeOut = Z_loaderZ_load_uw8(&loader, (uint32_t)uw8Size);
|
||||
void* wasm = malloc(*sizeOut);
|
||||
memcpy(wasm, memory, *sizeOut);
|
||||
memcpy(wasm, memory.data, *sizeOut);
|
||||
return wasm;
|
||||
}
|
||||
|
||||
@@ -190,14 +287,13 @@ const uint32_t uw8buttonScanCodes[] = {
|
||||
|
||||
typedef struct {
|
||||
IM3Runtime runtime;
|
||||
IM3Module platform;
|
||||
wasm_rt_memory_t memory_c;
|
||||
Z_platform_instance_t platform_c;
|
||||
IM3Module cart;
|
||||
} Uw8Runtime;
|
||||
|
||||
void initRuntime(Uw8Runtime* runtime, IM3Environment env,
|
||||
void* platform, size_t platformSize, void* cart, size_t cartSize) {
|
||||
void* cart, size_t cartSize) {
|
||||
runtime->runtime = m3_NewRuntime(env, 65536, NULL);
|
||||
runtime->runtime->memory.maxPages = 4;
|
||||
verifyM3(runtime->runtime, ResizeMemory(runtime->runtime, 4));
|
||||
@@ -208,18 +304,11 @@ void initRuntime(Uw8Runtime* runtime, IM3Environment env,
|
||||
runtime->memory_c.size = 256*1024;
|
||||
Z_platform_instantiate(&runtime->platform_c, (struct Z_env_instance_t*)&runtime->memory_c);
|
||||
|
||||
verifyM3(runtime->runtime, m3_ParseModule(env, &runtime->platform, platform, platformSize));
|
||||
runtime->platform->memoryImported = true;
|
||||
verifyM3(runtime->runtime, m3_LoadModule(runtime->runtime, runtime->platform));
|
||||
linkSystemFunctions(runtime->runtime, runtime->platform);
|
||||
verifyM3(runtime->runtime, m3_CompileModule(runtime->platform));
|
||||
verifyM3(runtime->runtime, m3_RunStart(runtime->platform));
|
||||
|
||||
verifyM3(runtime->runtime, m3_ParseModule(env, &runtime->cart, cart, cartSize));
|
||||
runtime->platform->memoryImported = true;
|
||||
runtime->cart->memoryImported = true;
|
||||
verifyM3(runtime->runtime, m3_LoadModule(runtime->runtime, runtime->cart));
|
||||
linkSystemFunctions(runtime->runtime, runtime->cart);
|
||||
linkPlatformFunctions(runtime->runtime, runtime->cart, runtime->platform, &runtime->platform_c);
|
||||
linkPlatformFunctions(runtime->runtime, runtime->cart, &runtime->platform_c);
|
||||
verifyM3(runtime->runtime, m3_CompileModule(runtime->cart));
|
||||
verifyM3(runtime->runtime, m3_RunStart(runtime->cart));
|
||||
}
|
||||
@@ -228,6 +317,7 @@ typedef struct AudioState {
|
||||
Uw8Runtime runtime;
|
||||
uint8_t* memory;
|
||||
IM3Function snd;
|
||||
bool hasSnd;
|
||||
uint8_t registers[32];
|
||||
uint32_t sampleIndex;
|
||||
} AudioState;
|
||||
@@ -238,8 +328,12 @@ void audioCallback(void* userdata, Uint8* stream, int len) {
|
||||
int numSamples = len / sizeof(float);
|
||||
memcpy(state->memory + 0x50, state->registers, 32);
|
||||
for(int i = 0; i < numSamples; ++i) {
|
||||
if(state->hasSnd) {
|
||||
m3_CallV(state->snd, state->sampleIndex++);
|
||||
m3_GetResultsV(state->snd, samples++);
|
||||
} else {
|
||||
*samples++ = Z_platformZ_sndGes(&state->runtime.platform_c, state->sampleIndex++);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -258,39 +352,24 @@ int main(int argc, const char** argv) {
|
||||
|
||||
uint32_t* pixels32 = malloc(320*240*4);
|
||||
|
||||
wasm_rt_init();
|
||||
Z_loader_init_module();
|
||||
Z_platform_init_module();
|
||||
|
||||
IM3Environment env = m3_NewEnvironment();
|
||||
IM3Runtime loaderRuntime = m3_NewRuntime(env, 65536, NULL);
|
||||
loaderRuntime->memory.maxPages = 4;
|
||||
verifyM3(loaderRuntime, ResizeMemory(loaderRuntime, 4));
|
||||
|
||||
size_t loaderSize;
|
||||
void* loaderWasm = loadFile(&loaderSize, "loader.wasm");
|
||||
|
||||
IM3Module loaderMod;
|
||||
verifyM3(loaderRuntime, m3_ParseModule(env, &loaderMod, loaderWasm, loaderSize));
|
||||
loaderMod->memoryImported = true;
|
||||
verifyM3(loaderRuntime, m3_LoadModule(loaderRuntime, loaderMod));
|
||||
verifyM3(loaderRuntime, m3_CompileModule(loaderMod));
|
||||
verifyM3(loaderRuntime, m3_RunStart(loaderMod));
|
||||
|
||||
IM3Function loadFunc;
|
||||
verifyM3(loaderRuntime, m3_FindFunction(&loadFunc, loaderRuntime, "load_uw8"));
|
||||
|
||||
uint32_t platformSize;
|
||||
void* platformWasm = loadUw8(&platformSize, loaderRuntime, loadFunc, "platform.uw8");
|
||||
|
||||
uint32_t cartSize;
|
||||
void* cartWasm = loadUw8(&cartSize, loaderRuntime, loadFunc, argv[1]);
|
||||
void* cartWasm = loadUw8(&cartSize, loaderRuntime, argv[1]);
|
||||
|
||||
m3_FreeRuntime(loaderRuntime);
|
||||
|
||||
wasm_rt_init();
|
||||
Z_platform_init_module();
|
||||
|
||||
bool quit = false;
|
||||
while(!quit) {
|
||||
Uw8Runtime runtime;
|
||||
initRuntime(&runtime, env, platformWasm, platformSize, cartWasm, cartSize);
|
||||
initRuntime(&runtime, env, cartWasm, cartSize);
|
||||
|
||||
uint8_t* memory = m3_GetMemory(runtime.runtime, NULL, 0);
|
||||
assert(memory != NULL);
|
||||
@@ -299,11 +378,9 @@ int main(int argc, const char** argv) {
|
||||
bool hasUpdFunc = m3_FindFunction(&updFunc, runtime.runtime, "upd") == NULL;
|
||||
|
||||
AudioState audioState;
|
||||
initRuntime(&audioState.runtime, env, platformWasm, platformSize, cartWasm, cartSize);
|
||||
initRuntime(&audioState.runtime, env, cartWasm, cartSize);
|
||||
audioState.memory = m3_GetMemory(audioState.runtime.runtime, NULL, 0);
|
||||
if(m3_FindFunction(&audioState.snd, audioState.runtime.runtime, "snd") != NULL) {
|
||||
verifyM3(audioState.runtime.runtime, m3_FindFunction(&audioState.snd, audioState.runtime.runtime, "sndGes"));
|
||||
}
|
||||
audioState.hasSnd = m3_FindFunction(&audioState.snd, audioState.runtime.runtime, "snd") == NULL;
|
||||
memcpy(audioState.registers, audioState.memory + 0x50, 32);
|
||||
audioState.sampleIndex = 0;
|
||||
|
||||
@@ -358,6 +435,8 @@ int main(int argc, const char** argv) {
|
||||
}
|
||||
memcpy(audioState.registers, memory + 0x50, 32);
|
||||
|
||||
Z_platformZ_endFrame(&runtime.platform_c);
|
||||
|
||||
uint32_t* palette = (uint32_t*)(memory + 0x13000);
|
||||
uint8_t* pixels = memory + 120;
|
||||
for(uint32_t i = 0; i < 320*240; ++i) {
|
||||
|
||||
24
main.ts
24
main.ts
@@ -1,24 +0,0 @@
|
||||
let U8 = (...a) => new Uint8Array(...a);
|
||||
|
||||
let memory = new WebAssembly.Memory({ initial: 4 });
|
||||
let memU8 = U8(memory.buffer);
|
||||
|
||||
let importObject = {
|
||||
env: {
|
||||
memory
|
||||
}
|
||||
};
|
||||
|
||||
let loaderWasm = await Deno.readFile("loader.wasm");
|
||||
let loader = (await WebAssembly.instantiate(loaderWasm, importObject)).instance;
|
||||
|
||||
let platformUw8 = await Deno.readFile("platform.uw8");
|
||||
console.log("platform.uw8 size: " + platformUw8.byteLength);
|
||||
memU8.set(U8(platformUw8));
|
||||
let platformSize = loader.exports.load_uw8(platformUw8.byteLength);
|
||||
let platformWasm = new ArrayBuffer(platformSize);
|
||||
U8(platformWasm).set(memU8.slice(0, platformSize));
|
||||
|
||||
console.log("Unpacked platform size: " + platformSize);
|
||||
|
||||
console.log("First byte: " + U8(platformWasm)[0]);
|
||||
BIN
never_sleeps.uw8
BIN
never_sleeps.uw8
Binary file not shown.
BIN
skipahead.uw8
Normal file
BIN
skipahead.uw8
Normal file
Binary file not shown.
Reference in New Issue
Block a user