Skip to content
/ 6902 Public

a simple, lightweight, and public domain 6502 emulator written in javascript.

License

Notifications You must be signed in to change notification settings

parabirb/6902

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

6902

6902 is a simple, lightweight, and public domain 6502 emulator library written in javascript.

info

the 6902 library is designed to provide a lightweight and modular interface to create a virtual cpu and step through clock cycles. on top of fully implementing the 6502 instruction set*, the 6902 library also provides multiple adapters for interfacing the CPU with VIAs**, LCDs***, RAM, and ROM. plus, it's remarkably simple to build adapters for any application you might need.

*BCD has not yet been implemented. illegal opcodes and 65c22-exclusive instructions have not been and will not be implemented. attempting to execute one will result in an error.

**VIAs have not yet been fully implemented. it is in a basic working state at the moment.

***the LCD driver has not yet been fully implemented. it is in a basic working state at the moment.

n.b.: the 6902 only takes one clock cycle per instruction, regardless of instruction or addressing mode. also, for jsr and brk, the program counter pushed to the stack is the location of the instruction that will be executed after return (either rti or rts).

example usage:

// deps
import {CPU, rom} from "./src/lib/index.js";

// create a rom full of nops
let buffer = Buffer.alloc(65536);
for (let i = 0; i < 65536; i++) {
    if (i === 0xfffc || i === 0xfffd) buffer[i] = 0;
    else buffer[i] = 0xea;
}

// create the CPU
let cpu = new CPU({
    dataBus: rom(buffer)
});

// go through one clock cycle and log the instruction executed
console.log(cpu.clock());

for more in-depth examples, see src/test.

special thanks

shoutout to pepsipu for telling me to write an emulator

thank you to:

these resources were immensely helpful for writing this emulator. if you want to write your own 6502 emulator, i would highly suggest reading the aforementioned resources.

About

a simple, lightweight, and public domain 6502 emulator written in javascript.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published