Skip to content

nerdbeard/e65

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

42 Commits
 
 
 
 
 
 

Repository files navigation

Intro

I want to put together a complete 6502 environment in elisp.

Features:

  • simulate multiple systems concurrently
  • simulate common 65-series hardware environments and chips
  • assemble source code into ROMs and other images
  • emulate 6502, 6522, etc to run and debug code

Simulation goals:

  • Two 6502s communicating via a serial interface (6522?)
  • A group of 6502s communicating via packet radio

Interesting chips:

Components

Bus

The bus hosts a set of devices mediated by device managers that take the place of address decoders, CS logic, etc.

Devices can emit and receive read requests, write requests and signals via the bus. Reads and writes have a 16-bit address, signals have only a truth value in the form of their presence or absence.

There is no use case for clock cycle emulation yet but I believe it might become relevant as more emulated hardware is written.

Devices

6264 SRAM

file-backed ROM

Emulator

6502 to be provided by emacs-nes Bus emulation and 65xx series chip emulators to be written

Assembler

To be provided by or modelled after COMFY-65 or cl-comfy-6502

Disassembler

To be written

Decompile to COMFY-65? maybe not possible. In that case, the assembler can’t really be COMFY-65 either, we need another one to do round trip from the disassembler to editor to assembler to code back to disassembler.

cl-comfy-6502 compiles to a parsed assembly format, for example:

(compile-code (3 (1+ 100)))
  -->
((INC :ZERO-PAGE) (:ZERO-PAGE 100) 
 (INC :ZERO-PAGE) (:ZERO-PAGE 100) 
 (INC :ZERO-PAGE) (:ZERO-PAGE 100))

..which could totally be used as the dissassembly format.

COMFY-65 just outputs the raw code:

(comfy-init)
(seq-subseq comfy-mem (comfy-compile '(3 (1+ 100)) #x0680 nil))
[230 100 230 100 230 100 76 128 6]

I guess maybe I could port cl-comfy-6502 back to elisp. It has the same license as COMFY-65 though. Not that I aspire to have commercial applications, but there are licensing requirements I don’t want to deal with just for redistribution.

Monitor/debugger

To be written

References

emacs-nes

Just to demonstrate that the 6502 emulator works

hg clone git+https://github.com/gongo/emacs-nes
(add-to-list 'load-path (concat default-directory "emacs-nes"))
(load "nes.el")
"Loaded emacs-nes"

Tetris sourced from http://www.nesfiles.com/NES/Tetris/Tetris.nes

(nes "Tetris.nes")

Scratch

;; SRAM that appears twice
(defun e65-example-mapper (device addr)
  ;; Ignore the 10th bit causing this chip to be mapped to
  ;; 0x0000-0x1ffff and again to 0x2000-0x3ffff
  (let ((addr (logand addr (lognot #x2000))))
    ;; If modified addr is in lower 8K, use it.  otherwise return nil
    ;; to prevent the call to read/write on the device
    (and ((< addr #x2000) addr))))

;; Each cycle, write to the bus; everything else will get their
;; e65-device-write-function called
(defun e65-example-signal (device signals)
  (and (member :phi2 signals)
       (e65-device-write device #xabcd #xef)))

About

Build and simulate 6502 computers in elisp

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published