{"_id":"6502-emulator","_rev":"1-28e6211185f0c9b73d010c727cec3309","name":"6502-emulator","dist-tags":{"latest":"1.0.0"},"versions":{"1.0.0":{"name":"6502-emulator","description":"Emulator for the MOS6502 CPU. Designed for simulating custom logic boards that use the 6502.","version":"1.0.0","main":"dist/index.js","types":"dist/index.d.ts","repository":{"type":"git","url":"git+https://github.com/jyelewis/cpu-6502-emulator.git"},"author":{"name":"Jye Lewis","email":"jye@jyelewis.com"},"license":"ISC","keywords":["6502","emulator","cpu","processor","electronics","simulation"],"dependencies":{},"devDependencies":{"prettier":"^2.0.5","fs-extra-promise":"^1.0.1","@types/fs-extra-promise":"^1.0.9","@types/node":"^14.0.14","typescript":"^3.9.5"},"scripts":{"build":"tsc -d","format":"prettier --write \"src/**/*.ts\"","prepublishOnly":"tsc -d"},"gitHead":"833531d0e7d9411d1d83fb8d8ad8d8958e6751e6","bugs":{"url":"https://github.com/jyelewis/cpu-6502-emulator/issues"},"homepage":"https://github.com/jyelewis/cpu-6502-emulator#readme","_id":"6502-emulator@1.0.0","_nodeVersion":"12.16.3","_npmVersion":"6.14.4","dist":{"integrity":"sha512-nrP1CpQLJZbYiKb2hPI/jyyYVC3W48Hx3uclCZp9Y9Xm1hweubduUhmMnAykkLQ4QSns18AOvhUNtqaK6VMIWA==","shasum":"55d406c90f3d0b7177d77acd18296bc401ca3a0e","tarball":"https://registry.npmjs.org/6502-emulator/-/6502-emulator-1.0.0.tgz","fileCount":30,"unpackedSize":90527,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.4\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJe//+LCRA9TVsSAnZWagAAqx0P/1IKD7X5hkGdWEiQ+AgB\n3vDxoRRbe2b6pf8hrNGUsGA9gi/Y2Z4uo8dEVSq80YTQl6bOvOOZNvuR4B6U\npYig37ecxwLi1+YjVF8MToam6YPhzDQvzeyH72NrF5fOkzraJY/4KTtlGhss\nvpM02qQp1KsKltwMh7EZt/1jchJjnv7Cb/83uPO92EQd32lANKiqXGlPk0z+\nDs0fabHz0+uV6uSPXYYt2FW3s+4cZGvAa5libmFzDhWSdQK4UyuIkWArtLQv\nK1EnNGaOFaygoyLaW6pQ4bSOZGlYeEFtwuudzca+eVAcyiSWbcdEV9Z7qKYR\n557ifc+VWTS0fla25t7QBp6PfHBbpI+cdKxDwYCMH0KeC8hmaSBzTty52/+1\nRq+PWXSNS/Hq8GOHFe01SXrc8hyMbGuVIgO5/ymq1iKuSumJ7ZC40TDuEY4x\nypkfjhJF/Bl5wxNEWsaZSq4ufi2tlhzfbkHh+m3KTSL2X75ZhE3+1i7Bl+aL\nTFpYr3a9geFXRaXALR1ErJK7GZpJI6WCmyJyH7riP6WLI07BUTEdOn3k5TgV\nsn8HpMDcyQXAdyxiqZEkeVBLUyIZVRif8OVI4Zr3Lou7kJ8jQmcBY5b+DoUU\n0onbjr5z6s5DG5rcshwaobLeGZZAFvLNDd9nphBKZ6g75Af5WqImkuOxfOcr\n4yiG\r\n=vBPS\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCIHEMe6KrTQdQRbxP6/RnR0dmeXdvXYTi0W0MHIwMY9MkAiBInU5isTtZjMYpLbp33vfSXCK5wHcPAGeNT4syq4MOnw=="}]},"maintainers":[{"name":"jyelewis","email":"jye@jyelewis.com"}],"_npmUser":{"name":"jyelewis","email":"jye@jyelewis.com"},"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/6502-emulator_1.0.0_1593835402595_0.5411255892553295"},"_hasShrinkwrap":false}},"time":{"created":"2020-07-04T04:03:22.595Z","1.0.0":"2020-07-04T04:03:22.711Z","modified":"2022-04-04T10:23:39.714Z"},"maintainers":[{"name":"jyelewis","email":"jye@jyelewis.com"}],"description":"Emulator for the MOS6502 CPU. Designed for simulating custom logic boards that use the 6502.","homepage":"https://github.com/jyelewis/cpu-6502-emulator#readme","keywords":["6502","emulator","cpu","processor","electronics","simulation"],"repository":{"type":"git","url":"git+https://github.com/jyelewis/cpu-6502-emulator.git"},"author":{"name":"Jye Lewis","email":"jye@jyelewis.com"},"bugs":{"url":"https://github.com/jyelewis/cpu-6502-emulator/issues"},"license":"ISC","readme":"# CPU6502 Emulator\nA javascript emulator for the MOS6502 (WDC 65c02 compatible) CPU.\nDesigned for simulating custom logic boards that use the 6502.\n\nAll memory read/writes call out to a delegate function, allowing custom memory logic, I/O logic and address decoding.\n\n## Configuration\n```javascript 1.8\nconst cpu = new CPU6502({\n  accessMemory, // function to be called when CPU reads/writes to memory\n  logInstructions: false, // output each instruction to console, for advanced debugging\n  logInternalState: false, // output internal processor state after each instruction for advanced debugging\n  maxInstructions: 50 // automatically pause execution after 50 instructions\n});\n```\n\n## Usage\n\n### Available methods\n```javascript 1.8\nconst cpu = new CPU6502();\n\ncpu.reset(); // trigger reset sequence\ncpu.triggerIRQB(); // trigger IRQB interrupt\ncpu.triggerNMIB(); // trigger NMIB interrupt\n\ncpu.pauseClock(); // pause clock, stop executing instructions\ncpu.startClock(); // start/resume clock\n\n// accessing internal state\nconsole.log(cpu.reg_a);\nconsole.log(cpu.reg_x);\nconsole.log(cpu.reg_y);\nconsole.log(cpu.programCounter);\nconsole.log(cpu.stackPointer);\nconsole.log(cpu.processorStatus);\n```\n\n### Example 1: Executing simple machine code\n```javascript 1.8\nimport { CPU6502, ReadWrite } from \"6502-emulator\";\n\n// instruction opcodes\nconst I_NOOP = 0xea;\nconst I_LDA = 0xa9;\nconst I_STA = 0x8d;\nconst I_JMP = 0x4c;\n\n// set up memory\nconst ram = new Uint8ClampedArray(0xffff); // 64kb ram\nram.fill(I_NOOP); // fill ram with noop instructions\n\n// store reset vector as 0200 (little endian)\nram[0xfffc] = 0x00;\nram[0xfffd] = 0x02;\n\n// create a basic program\nram.set(\n  [\n    I_LDA, 0x55, // lda 55\n    I_STA, 0x00, 0x60, // 55 -> 6000 (output 55 to address 0x6000)\n\n    I_LDA, 0xaa, // lda AA\n    I_STA, 0x00, 0x60, // AA -> 6000 (output AA to address 0x6000)\n\n    I_JMP, 0x00, 0x02  // jump back to start of program\n  ],\n  0x0200\n);\n\nconst accessMemory = (readWrite, address, value) => {\n  // capture a write to 0x6000 as a magic output address, print to console\n  if (address === 0x6000 && readWrite === ReadWrite.write) {\n    console.log(\"Output: \", value.toString(16));\n    return;\n  }\n  \n  // write value to RAM (processor is reading from [address])\n  if (readWrite === ReadWrite.read) {\n    return ram[address];\n  }\n\n  // store value in RAM (processor is writing [value] to [address])\n  ram[address] = value;\n};\n\nconst cpu = new CPU6502({ accessMemory });\n// trigger a reset to start the clock & jump to the reset vector\ncpu.reset();\n```\n\n### Example 2: Load ROM image from disk\n```javascript 1.8\nimport { CPU6502, ReadWrite } from \"6502-emulator\";\n\n// load image from disk\nconst ramImagePath = \"./myROMFile\";\nconst ramImage = fs.readFileSync(ramImagePath);\n  \n// set up memory\nconst ram = Uint8ClampedArray.from(ramImage);\n\nconst accessMemory = (readWrite, address, value) => {\n  // capture a write to 0x6000 as a magic output address, print to console\n  if (address === 0x6000 && readWrite === ReadWrite.write) {\n    console.log(\"Output: \", value.toString(16));\n    return;\n  }\n\n  // capture a write to 0x6005 as a magic output address, pause the clock\n  if (address === 0x6005 && readWrite === ReadWrite.write) {\n    console.log(\"Exit captured! pausing clock\");\n    cpu.pauseClock();\n    return;\n  }\n\n  // write value to RAM (processor is reading from [address])\n  if (readWrite === ReadWrite.read) {\n    return ram[address];\n  }\n\n  // store value in RAM (processor is writing [value] to [address])\n  ram[address] = value;\n}\n\nconst cpu = new CPU6502({ accessMemory });\n// trigger a reset to start the clock & jump to the reset vector\ncpu.reset();\n```","readmeFilename":"readme.md"}