Skip to main content

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

Release files for td4 1.0.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for td4 1.0.2
File Size Uploaded
td4-1.0.2.tar.gz 5.0 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for td4 1.0.2
File Interpreter ABI Platform
td4-1.0.2-py3-none-any.whl Python 3 none any Details

Total release size: 11.3 kB

Release files / td4-1.0.2.tar.gz

Download URL td4-1.0.2.tar.gz
Size 5.0 kB
Tags Source
SHA-256 checksum
How to use checksums
f1d827ccbf90523bd6873492d3112c1229ab33fcd01c4a720b10265f488efc9b
BLAKE2b-256 checksum
How to use checksums
bee72ea3d953ff954cb5e3c419745afd7a05f91a20d872916eb1ed30146d4590
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.10.6

Release files / td4-1.0.2-py3-none-any.whl

Download URL td4-1.0.2-py3-none-any.whl
Size 6.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
f75d9407193e587e10c3d9e050762fc04ee1393edc3a3a20b05aee8ac008a2cb
BLAKE2b-256 checksum
How to use checksums
4176887741052a3cbb51ee7230fe6bd54edfd1f600bf5b029df01393c886ba24
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.10.6

Release history Release notifications | RSS feed

This release

1.0.2 This release

2 release files

1.0.1

2 release files

1.0.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page