UNPKG

broken-neees

Version:

A really broken NEEES emulator that introduces glitches and random bugs on purpose!

61 lines (55 loc) 3.24 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.default = void 0; var _byte = _interopRequireDefault(require("./lib/byte")); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); } function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor); } } function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; } function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); } function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); } var RAM_SIZE = 2048; var CPUMemory = /*#__PURE__*/function () { function CPUMemory() { _classCallCheck(this, CPUMemory); this.ram = new Uint8Array(RAM_SIZE); } _createClass(CPUMemory, [{ key: "onLoad", value: function onLoad(ppu, apu, mapper, controllers) { this.ppu = ppu; this.apu = apu; this.mapper = mapper; this.controllers = controllers; } }, { key: "read", value: function read(address) { // 2 KiB internal RAM if (address <= 0x07ff) return this.ram[address]; // Mirrors of $0000-$07FF if (address >= 0x0800 && address <= 0x1fff) return this.read(0x0000 + (address - 0x0800) % 0x0800); /* 🐒 The rest of the components are mapped in `NEEES` */ return 0; } }, { key: "write", value: function write(address, value) { // 2 KiB internal RAM if (address <= 0x07ff) return this.ram[address] = value; // Mirrors of $0000-$07FF if (address >= 0x0800 && address <= 0x1fff) return this.write(0x0000 + (address - 0x0800) % 0x0800, value); /* 🐒 The rest of the components are mapped in `NEEES` */ } }, { key: "read16", value: function read16(address) { return _byte.default.buildU16(this.read(address + 1), this.read(address)); } }]); return CPUMemory; }(); exports.default = CPUMemory;