Skip to content

Commit

Permalink
Switch WASM to FBA
Browse files Browse the repository at this point in the history
  • Loading branch information
190n committed May 12, 2024
1 parent ea51734 commit ab0566f
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/bindings.zig
Original file line number Diff line number Diff line change
Expand Up @@ -118,12 +118,16 @@ export fn zip8CpuResetDrawBytes(cpu: ?*anyopaque) callconv(.C) void {
comptime {
if (@import("builtin").target.isWasm()) {
const wasm_only_functions = struct {
var buf: [65536]u8 = undefined;
var fba = std.heap.FixedBufferAllocator.init(&buf);
const allocator = fba.allocator();

fn zip8CpuAlloc() callconv(.C) ?[*]u8 {
return (std.heap.wasm_allocator.alignedAlloc(u8, @alignOf(Cpu), @sizeOf(Cpu)) catch return null).ptr;
return (allocator.alignedAlloc(u8, @alignOf(Cpu), @sizeOf(Cpu)) catch return null).ptr;
}

fn wasmAlloc(n: usize) callconv(.C) ?[*]u8 {
return (std.heap.wasm_allocator.alignedAlloc(u8, @import("builtin").target.maxIntAlignment(), n) catch return null).ptr;
return (allocator.alignedAlloc(u8, @import("builtin").target.maxIntAlignment(), n) catch return null).ptr;
}
};

Expand Down

0 comments on commit ab0566f

Please sign in to comment.