github.com/SleepingInsomniac/sapcpu

BE-SAP1 8bit CPU emulator

5 stars
0 dependents
License: MIT

Nothing has been indexed for 0.1.3 yet. The tag is recorded, its shard.yml has not been read, so the manifest and dependency list below are empty because they are unknown rather than because they are absent.

Installation

# Add this to your shard.yml
dependencies:
  sapcpu:
    github: SleepingInsomniac/sapcpu
    version: ~> 0.1.3

Then run:

shards install

shard.yml

No shard.yml has been indexed for 0.1.3. You can read it on the repository.

Dependencies

Unknown: the shard.yml for this version has not been read yet.

README

This README is the one indexed from the repository at its latest ref, not from the tag for this version.

SAP 8-bit CPU Emulator

Emulates a version of the "Simple As Possible" 8-bit CPU

Installation

macOS

  1. Install crystal: brew install crystal
  2. build the program: shards build --release

The build will be placed in bin

CLI Usage

Build a program:

$ sapcpu build examples/multiply.asm -o a.out

Run a program:

$ sapcpu run examples/multiply.eat

Run and build a program:

$ sapcpu run examples/multiply.asm -a
Usage: sapcpu [arguments]
    -v, --verbose                    Run verbosely
    build                            assemble a file
    dasm                             dis-assemble a binary
    run                              run a program
    -h, --help                       Show this help

Usage: sapcpu build [arguments]
    -v, --verbose                    Run verbosely
    -h, --help                       Show this help
    -o NAME                          Output file name

Usage: sapcpu dasm [arguments]
    -v, --verbose                    Run verbosely
    -h, --help                       Show this help

Usage: sapcpu run [arguments]
    -v, --verbose                    Run verbosely
    -h, --help                       Show this help
    -a, --asm                        Assemble before running
    -g, --gui                        Run with a gui
    -d DELAY, --delay DELAY          Add a delay to each clock pulse (s)

Instructions

  NOP -  No-op
  LDA -  Load A
  ADD -  Add A with memory
  SUB -  Subtract A with memory
  STA -  Store A to memory
  LDI -  Load Immediate to A
  JMP -  Jump to Immediate
  JC  -  Jump on Carry
  JZ  -  Jump on Zero
  ADI -  Add immediate
  OUT -  Output                    (Prints to STDOUT)
  HLT -  Halt execution            (Exits the emulator)

CPU Layout

                    Bus
 Memory Address     ●●●●●●●●           Prog Counter  RAM
     ●●●● ⫦-------⫣ ⎪⎪⎪⎪⎪⎪⎪⎪ ⫦-------⫣ ●●●●●●●●      00: 00000000
 $00                ⎪⎪⎪⎪⎪⎪⎪⎪           $00           01: 00000000
 Memory Contents    ⎪⎪⎪⎪⎪⎪⎪⎪           A Register    02: 00000000
 ●●●●●●●● ⫦-------⫣ ⎪⎪⎪⎪⎪⎪⎪⎪ ⫦-------⫣ ●●●●●●●●      03: 00000000
 $00                ⎪⎪⎪⎪⎪⎪⎪⎪           000           04: 00000000
 Instruction        ⎪⎪⎪⎪⎪⎪⎪⎪           Sum Register  05: 00000000
 ●●●●●●●● ⫦-------⫣ ⎪⎪⎪⎪⎪⎪⎪⎪ ⫦-------⫣ ●●●●●●●●      06: 00000000
 HLT                ⎪⎪⎪⎪⎪⎪⎪⎪           000           07: 00000000
 Flags  MC Step     ⎪⎪⎪⎪⎪⎪⎪⎪           B Register    08: 00000000
 ●●     ●●●         ⎪⎪⎪⎪⎪⎪⎪⎪ ⫦-------⫣ ●●●●●●●●
 ZC                 ⎪⎪⎪⎪⎪⎪⎪⎪           000
 Control Word       ⎪⎪⎪⎪⎪⎪⎪⎪           Output
 ●●●●●●●●●●●●●●●●●● ⎪⎪⎪⎪⎪⎪⎪⎪ ⫦-------⫣ ●●●●●●●●
 JJFJCCOBSEAAIIRRMH                    000
 ZCI OEIIUOOIIOOIIL
                  T

Contributors