Skip to content

Irratix/mini6502

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

mini6502

An attempt to make the smallest standalone 6502 CPU simulator in JavaScript (< 1kb zipped)

Developed for my mini NES emulator: https://github.com/xem/jsnes-lite

A writeup is available on: https://xem.github.io/articles/nes.html

Commented source code: https://github.com/xem/mini6502/6502.js

Minified: https://github.com/xem/mini6502/6502.min.js

Zipped: https://github.com/xem/mini6502/6502.min.zip

Demo: https://xem.github.io/mini6502/demo



Features:

  • Initialization of memory (m), registers (A, X, Y, S, PC, P), flags (C, Z, I, D, B, V, N) and cycle counter (c) as global vars
  • Memory helpers (read: r(addr), write: w(addr,value), push: h(value), pop: g())
  • Emulation of the 151 official 6502 opcodes and 3 interrupts
  • Emulation of the hardware bugs and quirks (JMP, cross-page reads...)
  • Cycle-accurate
  • Optimized to run properly at 1.76M cycles/second


NES features not included:

  • Memory mirrorings (same data available at different addresses)
  • I/O registers (graphics, sound, joypads...)
  • Mappers (ROM bank switching, save slot, ...)


How to use:

  • Include 6502.js in your project
  • Put the contents of a ROM in the memory m (an array of integers between 0 and 127)
  • Reset the CPU with op(2) or set PC at the address where the ROM starts
  • Call op() repeatedly to simulate opcodes one by one
  • Call op(1) for a NMI interrupt, op(2) for a Reset and op(3) for an IRQ


Useful resources:

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • JavaScript 100.0%