Skip to main content

4bit CPU emulator

Project description

td4-py

This repository is a 4bit CPU emulator written by Python.
The original is CPUの創りかた.

example

features

  • Read from plain text files, td4 format files
  • Variable clock, manual clock selectable
  • Beep support
  • Runs in CLI

Install

https://pypi.org/project/td4

pip3 install td4

Usage

args

td4 [-h] [-i INPUT] [-c CLOCK] [-b] file

file

File to read.
Check https://github.com/yashikota/td4-py#support-file-format for the supported format.

example

td4 program.txt
td4 Knight2K.td4

help

Show help message and exit.

example

td4 -h

input

Any binary can be specified.
Default is 0000.

example

td4 -i 0000
td4 --input 1111

clock

Any number or manual can be specified.
Default is 10.

example

td4 -c 1
td4 --clock 10
td4 -c manual

beep

Specifies whether a beep is sounded.
Operates when the MSB of out is set to 1.
Default is False.

example

td4 -b
td4 --beep

Support file format

Input from plain text files supports several patterns.

Pattern 1

Opcode(Assembly LowerCase) + Space + Immediate data

out 0011
out 0110
out 1100
out 1000
out 1000
out 1100
out 0110
out 0011
out 0001
jmp 0000

Pattern2

Opcode(Assembly UpperCase) + Space + Immediate data

OUT 0111
ADD A,0001
JNC 0111
ADD A,0001
JNC 0011
OUT 0110
ADD A,0001
JNC 0110
ADD A,0001
JNC 1000
OUT 0000
OUT 0100
ADD 0001
JNC 1010
OUT 1000
JMP 1111

Pattern3

Opcode(binary) + Immediate data

10110011
10110110
10111100
10111000
10111000
10111100
10110110
10110011
10110001
10010000

Pattern4

Opcode(binary) + Space + Immediate data

1011 0011
1011 0110
1011 1100
1011 1000
1011 1000
1011 1100
1011 0110
1011 0011
1011 0001
1001 0000

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

td4-1.0.1.tar.gz (4.9 kB view details)

Uploaded Source

Built Distribution

td4-1.0.1-py3-none-any.whl (6.3 kB view details)

Uploaded Python 3

File details

Details for the file td4-1.0.1.tar.gz.

File metadata

  • Download URL: td4-1.0.1.tar.gz
  • Upload date:
  • Size: 4.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.10.6

File hashes

Hashes for td4-1.0.1.tar.gz
Algorithm Hash digest
SHA256 ead61ed243e7569ced92838e8f9dcd8548927257a042c0a942887815ab99e8ca
MD5 06f1b43568865690eddfadc40260a91c
BLAKE2b-256 3ea18658d9e181c5f78d6b326181dcc3c9d161aae35a8f5bd5ed8afdf7011754

See more details on using hashes here.

File details

Details for the file td4-1.0.1-py3-none-any.whl.

File metadata

  • Download URL: td4-1.0.1-py3-none-any.whl
  • Upload date:
  • Size: 6.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.10.6

File hashes

Hashes for td4-1.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 11a6151cea3db7e8e60d0bfacfcb74466ddef0ca2a994b25000fdc5cdf129dea
MD5 d4f224c08f13ce0b2748c6848c20ba36
BLAKE2b-256 aa72ae6622ba84572445734b9dfe28c7f825b61dd070016abfa907329e4fde69

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page