Used __builtin_wasm_memory_size(0) instead of having the Javascript code call init_mem with the initial page count. Added a simple <div> below the canvas that can hold any number of labels that can be filled/updated through jsSetLabel which lives in a new file misc_functions.js.

This commit is contained in:
2025-09-02 16:05:53 -07:00
parent f45c2d88e0
commit 04028b29d3
10 changed files with 117 additions and 30 deletions

View File

@@ -9,20 +9,19 @@ Description:
extern unsigned char __heap_base;
static void* heapBaseAddress = 0;
static void* heapBaseAddress = nullptr;
static size_t stdCurrentHeapSize = 0;
static size_t stdCurrentPageCount = 0;
WASM_EXPORT(init_mem) void init_mem(size_t numInitialPages)
{
heapBaseAddress = (void*)&__heap_base;
stdCurrentPageCount = numInitialPages;
}
//These are our own std-like functions for interacting with WebAssembly memory
void* grow_mem(size_t numBytes)
{
assert_msg(heapBaseAddress != nullptr, "growmem called before initmem! Make sure initmem is being called by the Javascript code!");
if (heapBaseAddress == nullptr)
{
stdCurrentPageCount = __builtin_wasm_memory_size(0);
heapBaseAddress = (void*)&__heap_base;
}
size_t memorySizeNeeded = ((size_t)heapBaseAddress) + stdCurrentHeapSize;
size_t numPagesNeeded = (memorySizeNeeded / WASM_MEMORY_PAGE_SIZE) + (((memorySizeNeeded % WASM_MEMORY_PAGE_SIZE) > 0) ? 1 : 0);
if (numPagesNeeded > WASM_MEMORY_MAX_NUM_PAGES)

View File

@@ -26,7 +26,6 @@ _Noreturn void abort_msg(const char* message);
// void* aligned_alloc(size_t numBytes, size_t alignmentSize);
//These are our own std-like functions for interacting with WebAssembly memory
WASM_EXPORT(init_mem) void init_mem(size_t numInitialPages);
void* grow_mem(size_t numBytes);
size_t get_mem();