"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.SetupRomAccessors = exports.SetupMemoryAccessors = void 0;
const sPrimitiveTypes = [
    "u8",
    "u16",
    "u32",
    "u64",
    "s8",
    "s16",
    "s32",
    "s64",
    "f32",
    "f64"
];
const sPrimitiveTypesRom = [
    "u8",
    "u16",
    "u32"
];
function GenerateAccessorFunctions() {
    let fn = {};
    for (let index = 0; index < sPrimitiveTypes.length; index++) {
        let ptype = sPrimitiveTypes[index];
        let truncated = ptype;
        if (truncated.startsWith('u')) {
            truncated = truncated.slice(1);
        }
        truncated = truncated.toUpperCase();
        let object = {
            get: function (instance, address) {
                let addr = 0;
                addr = parseInt(address);
                return instance[`rdramRead${truncated}`](addr);
            },
            set: function (instance, address, value) {
                let addr = 0;
                addr = parseInt(address);
                instance[`rdramWrite${truncated}`](addr, value);
                return true;
            }
        };
        fn[ptype] = object;
    }
    return fn;
}
function GenerateAccessorFunctionsRom() {
    let fn = {};
    for (let index = 0; index < sPrimitiveTypesRom.length; index++) {
        let ptype = sPrimitiveTypesRom[index];
        let truncated = ptype;
        if (truncated.startsWith('u')) {
            truncated = truncated.slice(1);
        }
        truncated = truncated.toUpperCase();
        let object = {
            get: function (instance, address) {
                let addr = 0;
                addr = parseInt(address);
                return instance[`romRead${truncated}`](addr);
            },
            set: function (instance, address, value) {
                let addr = 0;
                addr = parseInt(address);
                instance[`romWrite${truncated}`](addr, value);
                return true;
            }
        };
        fn[ptype] = object;
    }
    return fn;
}
const AccessorFunctions = GenerateAccessorFunctions();
const AccessorFunctionsRom = GenerateAccessorFunctionsRom();
function SetupMemoryAccessors(memory) {
    for (let index = 0; index < sPrimitiveTypes.length; index++) {
        let ptype = sPrimitiveTypes[index];
        memory[ptype] = new Proxy(memory, AccessorFunctions[ptype]);
    }
}
exports.SetupMemoryAccessors = SetupMemoryAccessors;
function SetupRomAccessors(rom) {
    for (let index = 0; index < sPrimitiveTypesRom.length; index++) {
        let ptype = sPrimitiveTypesRom[index];
        rom[ptype] = new Proxy(rom, AccessorFunctionsRom[ptype]);
    }
}
exports.SetupRomAccessors = SetupRomAccessors;
//# sourceMappingURL=accessor.js.map