Close
0%
0%

6502/65C02 Emulator Library

Open source 6502 emulator library written in C99 with no dependencies.

Public Chat
Similar projects worth following
6502/65c02 emulator written in standard C99 with no external dependencies.

Support for standard 6502, 65C02, WDC65C02 and R65C02.

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, 65C02, WDC65C02 and R65C02.
  • All WDC and Rockwell-specific instructions.
  • Correct handling of Decimal mode.
  • Accurate instruction timing.
  • 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)

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 */

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;
}

 License

This code is licensed under the MIT license

  • Support for all unofficial 6502/6510 opcodes

    Troy Schrapel02/03/2022 at 01:41 0 comments

    The latest update to the vrEmu6502 emulation library now includes (optional) support for all of the unofficial 6502/6510 opcodes.

    Use CPU_6502U when creating the new VrEmu6502 instance.

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

    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.

    Check it out here: https://github.com/visrealm/vrEmu6502

View project log

Enjoy this project?

Share

Discussions

Similar Projects

Does this project spark your interest?

Become a member to follow this project and never miss any updates