const c64 = @import("c64");

extern module FixedMath = fixed_math {
    fn bias(value: u8) u8;
}

memory {
    region window_ram: c64 at 0x6000 size 0x1000;
    region staging_ram: c64 at 0x9000 size 0x0800;
    region frame_ram: c64 at 0xc800 size 0x0400;
    region module_cache: reu at 0x030000 size 0x2000;
    stack in frame_ram;
}

module_loader {
    window main in window_ram;
    disk_staging in staging_ram;
    reu_cache in module_cache;
    capacity = 2;
    current {
        file = "calculator";
    }
    dependency fixed_math {
        file = "fixedmath";
        load = .on_demand;
    }
}

module calculator abi 1 {
    export base;
    dependency fixed_math;
}

fn base() callconv(.stack) u8 {
    return 0x20;
}

export fn main() void {
    c64.console.clear();
    const input = base();
    if (FixedMath.bias(input)) |value| {
        c64.console.print("BIAS {x}\n", .{value});
        c64.vic.border = 5;
    } else {
        c64.console.print("FIXEDMATH UNAVAILABLE\n", .{});
        c64.vic.border = 2;
    }
}
