A CPU framework
Project description
Hello!
Have you ever tried to make a cpu simulation but don't want to write 300+ lines of code?
Well then you don't have to anymore!
AngelCPU does most of the heavy lifting for you, so let's get started before I fall asleep while typing this.
Getting Started
First lets install Angel
pip install angel-cpu
Now, let's start with some simple stuff, give me a second i'm setting up
from angel_cpu import *
ARCH=cpu("ARCH")
Alright now i'm done setting up. As you can see we have a class here
from angel_cpu import *
ARCH=cpu("ARCH")#THIS RIGHT HERE
Let's first set up the basic CPU ARCH
from angel_cpu import *
ARCH=cpu("ARCH")
# no reset does NOT reset the ARCH's registers and ram it just resets the ARCH's PC and Program
ARCH.reset()
# The name of the Register doesn't matter go crazy if you want
# The amount of Registers also don't matter, you can add like 50 of them and it wouldn't care
ARCH.add_register("Rxa")
ARCH.add_register("Rxb")
ARCH.add_register("Rxc")
ARCH.add_register("Rxe")
# the size is calculated by the x (400) times the y (200)
ARCH.add_ram(400,200)
# 32 bit integer limit
ARCH.set_max(0xffffffff)
# we're setting the command symbol to be ; so it's like real ASM
ARCH.set_comment_symbol(";")
huff that took me 30 minutes to write... (all of the time was because of the comments XD)
Anyway... let's go over what the eclipse is all of these before my head explodes
ARCH.reset()
Resets the ARCH's PC and Program
ARCH.add_register("Register name")
adds a register
ARCH.add_ram(400,200)
set's the ram size which with this one will be... give me a sec i'm calculating... 80000 cells... WOW
ARCH.set_max(0xffffffff)
sets the integer limit, I just put the 32 bit limit because it's the bare minimum trust me with this, you are going to need much more than 4294967295 bits trust me
ARCH.set_comment_symbol(";")
This Sets the comment symbol, any line that starts with it will be ignored in the assembler.\
Now that we got that covered it's time to add some opcodes so we can actually do stuff
from angel_cpu import *
ARCH=cpu("ARCH")
# no reset does NOT reset the ARCH's registers and ram it just resets the ARCH's PC and Program
ARCH.reset()
# The name of the Register doesn't matter go crazy if you want
# The amount of Registers also don't matter, you can add like 50 of them and it wouldn't care
ARCH.add_register("Rxa")
ARCH.add_register("Rxb")
ARCH.add_register("Rxc")
ARCH.add_register("Rxe")
# the size is calculated by the x (400) times the y (200)
ARCH.add_ram(400,200)
# 32 bit integer limit
ARCH.set_max(0xffffffff)
# we're setting the command symbol to be ; so it's like real ASM
ARCH.set_comment_symbol(";")
def MOV(reg,value):
ARCH.set_register(reg,value)
def LOG(txt):
if txt in ARCH.registers:
print(ARCH.registers[txt])
else:
print(txt)
# It's important to note that when adding opcodes don't put parentheses on the function
# ARCH.add_opcode(0x0,MOV()) <-- incorrect, paratheses arnt opposed to be in the opcodes
# ARCH.add_opcode(0x0,MOV) <-- correct
ARCH.add_opcode(0x0,MOV)
ARCH.add_opcode(0x1,LOG)
c="""
MOV Rxa 10
LOG Rxa
"""
ARCH.assemble(c)
ARCH.run()
Okay there's a lot of stuff here so let's talk about the things that changed
ARCH.add_opcode(hex_ID function)
This adds an opcode, and when adding the function, please, do not add parentheses
ARCH.assemble(code)
This assembles the code from ASM format into something that the CPU can actually understand, then it loads it into the CPU's program ready to run.
ARCH.run()
This takes the code from the Program and runs it, simple and very useful.
Now let's talk about the ASM format
MOV Rxa 10
LOG Rxa
The command comes first, each argument comes after the command separated by spaces, but then you might be wondering, "what about strings with spaces in them?" well, strings are strings so there has to be these (") surrounding them, without that it wouldn't be a string!
Alright this is taking a long time and I'm running out of time so I'll just give you a dump of the commands, you should be able to tell what they do...
add_regiser
add_ram
add_opcode
add_intruction
set_window_name
set_max
set_pc
set_register
set_ram
reset
set_comment_symbol
get_register
get_ram
get_pc
text
wait
scroll
is_Mouse_Touching_Surface
show_mouse
quit
frame
load_pixels
events
clear
clear_logs
is_held
render_surfaces
add_surface
add_pixel
text_input
mouse_down_on_group
mouse_pos
assemble
run
huff alright, that's all of them....
that's it for now, bye!
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file angel_cpu-0.2.tar.gz.
File metadata
- Download URL: angel_cpu-0.2.tar.gz
- Upload date:
- Size: 7.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
764433fc39411303fdc857ecb4e4e9a8aa79dbc1c364f7c67db88ca08b01c9b5
|
|
| MD5 |
5bd46fbf09a8cb773aaed5af8870074d
|
|
| BLAKE2b-256 |
fed8d880bfd3d69be333569423bce202cff1a17723c8b2becd57fe7da541ff27
|
File details
Details for the file angel_cpu-0.2-py3-none-any.whl.
File metadata
- Download URL: angel_cpu-0.2-py3-none-any.whl
- Upload date:
- Size: 7.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
63f7d9a1c07b196f2ef94d5c9f2b6a8314a36effcf7bbbc8f8b502f2cff1c2e6
|
|
| MD5 |
4f457cf74e43ca32b4217a1d9ae2d34e
|
|
| BLAKE2b-256 |
9b4c8d9adc22bf6ea86ad04ac56b075cc55551b26ea989b6003d4a4c32c6d694
|