const c64 = @import("c64");
extern module EnemyRuntime = enemy_runtime {
    fn border(seed: u8) u8;
}

memory {
    region call_stack: c64 at 0xc800 size 0x0400;
    region module_window: c64 at 0xc000 size 0x0800;
    region module_cache: reu at 0x030000 size 0x010000;
    region staging_ram: c64 at 0x9000 size 0x0800;

    stack in call_stack;
}

module_loader {
    window main in module_window;
    reu_cache in module_cache;
    disk_staging in staging_ram;
}

module enemy_runtime abi 1 {
    export border = borderColor;
}

fn borderColor(seed: u8) callconv(.stack) u8 {
    return seed + 2;
}

export fn main() void {
    c64.console.clear();
    c64.console.print("DISK LOAD REAL\n", .{});
    if (EnemyRuntime.loadFromDisk("enemyrt")) {
        const maybe_border = EnemyRuntime.border(3);
        if (maybe_border) |border| {
            c64.console.print("REAL LOAD OK\n", .{});
            c64.vic.border = border;
        } else {
            c64.console.print("REAL CALL FAIL\n", .{});
            c64.vic.border = 2;
        }
    } else {
        c64.console.print("REAL LOAD FAIL\n", .{});
        c64.vic.border = 2;
    }
}
