Giter Site home page Giter Site logo

vremu6502's Introduction

vrEmu6502

6502/65C02 emulator written in standard C99 with no external dependencies.

Initially created for my HBC-56 (6502 on a backplane) Emulator

Includes:

  • Support for standard 6502/6510, 65C02, WDC65C02 and R65C02.
  • Supports all unofficial ("illegal") 6502/6510 opcodes (Use model value CPU_6502U).
  • Correct handling of Decimal mode.
  • Accurate instruction timing.
  • All WDC and Rockwell-specific 65C02 instructions.
  • User-supplied I/O callbacks.
  • IRQ and NMI signals.
  • Multiple CPU instances.
  • Instruction disassembler.
  • Test runner.

Test suite

Includes a test program which was designed to run Klaus Dormann's 6502 tests.

Passes all tests:

  • 6502_functional_test (all models)
  • 6502_decimal_test (with valid and invalid bcd) (6502)
  • 65C02_decimal_test (with valid and invalid bcd) (all 65C02 models)
  • 65C02_extended_opcodes_test (Standard 65C02)
  • W65C02_extended_opcodes_test (WDC65C02)
  • R65C02_extended_opcodes_test (R65C02)

See the test directory or more details.

Quick start

#include "vrEmu6502.h"

uint8_t ram[0x8000];
uint8_t rom[0x8000];

uint8_t My6502MemoryReadFunction(uint16_t addr, bool isDbg)
{
  if (addr < 0x8000)
  {
    return ram[addr];
  }
  return rom[addr & 0x7fff];
}

void My6502MemoryWriteFunction(uint16_t addr, uint8_t val)
{
  if (addr < 0x8000)
  {
    ram[addr] = val;
  }
}

/* fill rom with something that makes sense here */


/* create a new WDC 65C02. */  
VrEmu6502 *my6502 = vrEmu6502New(CPU_W65C02, My6502MemoryReadFunction, My6502MemoryWriteFunction);

if (my6502)
{
  /* if you want to interrupt the CPU, get a handle to its IRQ "pin" */
  vrEmu6502Interrupt *irq = vrEmu6502Int(my6502);

  /* reset the cpu (technically don't need to do this as vrEmu6502New does reset it) */
  vrEmu6502Reset(my6502);

  while (1)
  {
    /* call me once for each clock cycle (eg. 1,000,000 times per second for a 1MHz clock) */
    vrEmu6502Tick(my6502);
        
    /* interrupt it? */
    if (myHardwareWantsAttention)
    {
      *irq = IntRequested;
      
      /* at some point, the hardware will be happy and it will need to release the interrupt */
    }
  }

  vrEmu6502Destroy(my6502);
  my6502 = NULL;
}

See HBC-56 for real-life example usage.

License

This code is licensed under the MIT license

vremu6502's People

Contributors

troy-petrosys avatar visrealm avatar tschrapel avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.