Skip to main content

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


Download files

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

Source Distribution

angel_cpu-0.4.tar.gz (7.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

angel_cpu-0.4-py3-none-any.whl (7.9 kB view details)

Uploaded Python 3

File details

Details for the file angel_cpu-0.4.tar.gz.

File metadata

  • Download URL: angel_cpu-0.4.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

Hashes for angel_cpu-0.4.tar.gz
Algorithm Hash digest
SHA256 787743ca3fe976ff8a9de0047df462e9cc9398aeea9ca7a2f7fcfc1c32fc679d
MD5 19c5b838807e8d8c592fa68e51de193f
BLAKE2b-256 19b18ead5af552c60b09546ea944b47be041aefd4ecc6f71ee93bd2139d9f51a

See more details on using hashes here.

File details

Details for the file angel_cpu-0.4-py3-none-any.whl.

File metadata

  • Download URL: angel_cpu-0.4-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

Hashes for angel_cpu-0.4-py3-none-any.whl
Algorithm Hash digest
SHA256 840e3df24bbcd191da957b500782cbdcd6f673bb83c4ed69ebb0f79f9c23d4fe
MD5 619fc750f154500b57a614429a20ef5a
BLAKE2b-256 4b6d4f50b72657bf917f239a0988970edb5bdd8f8ce2005d5b8c0a44525c8866

See more details on using hashes here.

Supported by

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