angel-cpu 0.1__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
angel_cpu-0.1/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 ERROR-Xmakernotfound
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
angel_cpu-0.1/PKG-INFO ADDED
@@ -0,0 +1,184 @@
1
+ Metadata-Version: 2.4
2
+ Name: angel-cpu
3
+ Version: 0.1
4
+ Summary: A CPU framework
5
+ Home-page:
6
+ Author: ERROR-Xmakernotfound
7
+ Author-email:
8
+ Requires-Python: >=3.8
9
+ Description-Content-Type: text/markdown
10
+ License-File: LICENSE
11
+ Requires-Dist: pygame
12
+ Dynamic: author
13
+ Dynamic: description
14
+ Dynamic: description-content-type
15
+ Dynamic: license-file
16
+ Dynamic: requires-dist
17
+ Dynamic: requires-python
18
+ Dynamic: summary
19
+
20
+ Hello!\
21
+ Have you ever tried to make a cpu simulation but don't want to write 300+ lines of code?\
22
+ Well then you don't have to anymore!\
23
+ AngelCPU does most of the heavy lifting for you, so let's get started before I fall asleep while typing this.
24
+ # Getting Started
25
+ First lets install Angel
26
+ ```bash
27
+ pip install angel-cpu
28
+ ```
29
+ Now, let's start with some simple stuff,
30
+ *give me a second i'm setting up*
31
+ ```python
32
+ from angel_cpu import *
33
+ ARCH=cpu("ARCH")
34
+ ```
35
+ *Alright now i'm done setting up.*
36
+ As you can see we have a class here
37
+ ```python
38
+ from angel_cpu import *
39
+ ARCH=cpu("ARCH")#THIS RIGHT HERE
40
+ ```
41
+ Let's first set up the basic CPU ARCH
42
+ ```python
43
+ from angel_cpu import *
44
+ ARCH=cpu("ARCH")
45
+ # no reset does NOT reset the ARCH's registers and ram it just resets the ARCH's PC and Program
46
+ ARCH.reset()
47
+ # The name of the Register doesn't matter go crazy if you want
48
+ # The amount of Registers also don't matter, you can add like 50 of them and it wouldn't care
49
+ ARCH.add_register("Rxa")
50
+ ARCH.add_register("Rxb")
51
+ ARCH.add_register("Rxc")
52
+ ARCH.add_register("Rxe")
53
+ # the size is calculated by the x (400) times the y (200)
54
+ ARCH.add_ram(400,200)
55
+ # 32 bit integer limit
56
+ ARCH.set_max(0xffffffff)
57
+ # we're setting the command symbol to be ; so it's like real ASM
58
+ ARCH.set_comment_symbol(";")
59
+ ```
60
+ *huff* that took me 30 minutes to write... (all of the time was because of the comments XD)\
61
+ Anyway... let's go over what the eclipse is all of these before my head explodes
62
+
63
+ `ARCH.reset()`
64
+
65
+ Resets the ARCH's PC and Program
66
+
67
+ `ARCH.add_register("Register name")`
68
+
69
+ adds a register
70
+
71
+ `ARCH.add_ram(400,200)`
72
+
73
+ set's the ram size which with this one will be... *give me a sec i'm calculating...* 80000 cells... *WOW*
74
+
75
+ `ARCH.set_max(0xffffffff)`
76
+
77
+ 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***
78
+
79
+ `ARCH.set_comment_symbol(";")`
80
+
81
+ This Sets the comment symbol, any line that starts with it will be ignored in the assembler.\
82
+
83
+ Now that we got that covered it's time to add some opcodes so we can actually do stuff
84
+ ```python
85
+ from angel_cpu import *
86
+ ARCH=cpu("ARCH")
87
+ # no reset does NOT reset the ARCH's registers and ram it just resets the ARCH's PC and Program
88
+ ARCH.reset()
89
+ # The name of the Register doesn't matter go crazy if you want
90
+ # The amount of Registers also don't matter, you can add like 50 of them and it wouldn't care
91
+ ARCH.add_register("Rxa")
92
+ ARCH.add_register("Rxb")
93
+ ARCH.add_register("Rxc")
94
+ ARCH.add_register("Rxe")
95
+ # the size is calculated by the x (400) times the y (200)
96
+ ARCH.add_ram(400,200)
97
+ # 32 bit integer limit
98
+ ARCH.set_max(0xffffffff)
99
+ # we're setting the command symbol to be ; so it's like real ASM
100
+ ARCH.set_comment_symbol(";")
101
+ def MOV(reg,value):
102
+ ARCH.set_register(reg,value)
103
+ def LOG(txt):
104
+ if txt in ARCH.registers:
105
+ print(ARCH.registers[txt])
106
+ else:
107
+ print(txt)
108
+ # It's important to note that when adding opcodes don't put parentheses on the function
109
+ # ARCH.add_opcode(0x0,MOV()) <-- incorrect, paratheses arnt opposed to be in the opcodes
110
+ # ARCH.add_opcode(0x0,MOV) <-- correct
111
+ ARCH.add_opcode(0x0,MOV)
112
+ ARCH.add_opcode(0x1,LOG)
113
+ c="""
114
+ MOV Rxa 10
115
+ LOG Rxa
116
+ """
117
+ ARCH.assemble(c)
118
+ ARCH.run()
119
+ ```
120
+ Okay there's a lot of stuff here so let's talk about the things that changed
121
+
122
+ `ARCH.add_opcode(hex_ID function)`
123
+
124
+ This adds an opcode, and when adding the function, please, **do not add parentheses**
125
+
126
+ `ARCH.assemble(code)`
127
+
128
+ 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.
129
+
130
+ `ARCH.run()`
131
+
132
+ This takes the code from the Program and runs it, simple and very useful.
133
+
134
+ Now let's talk about the ASM format
135
+ ```AngelASM
136
+ MOV Rxa 10
137
+ LOG Rxa
138
+ ```
139
+ 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!
140
+
141
+ 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...
142
+ ```ASM_helper
143
+ add_regiser
144
+ add_ram
145
+ add_opcode
146
+ add_intruction
147
+
148
+ set_window_name
149
+ set_max
150
+ set_pc
151
+ set_register
152
+ set_ram
153
+ reset
154
+ set_comment_symbol
155
+
156
+ get_register
157
+ get_ram
158
+ get_pc
159
+
160
+ text
161
+ wait
162
+ scroll
163
+ is_Mouse_Touching_Surface
164
+ show_mouse
165
+ quit
166
+ frame
167
+ load_pixels
168
+ events
169
+ clear
170
+ clear_logs
171
+ is_held
172
+ render_surfaces
173
+ add_surface
174
+ add_pixel
175
+ text_input
176
+ mouse_down_on_group
177
+ mouse_pos
178
+
179
+ assemble
180
+
181
+ run
182
+ ```
183
+ *huff* alright, that's all of them....\
184
+ that's it for now, bye!
@@ -0,0 +1,165 @@
1
+ Hello!\
2
+ Have you ever tried to make a cpu simulation but don't want to write 300+ lines of code?\
3
+ Well then you don't have to anymore!\
4
+ AngelCPU does most of the heavy lifting for you, so let's get started before I fall asleep while typing this.
5
+ # Getting Started
6
+ First lets install Angel
7
+ ```bash
8
+ pip install angel-cpu
9
+ ```
10
+ Now, let's start with some simple stuff,
11
+ *give me a second i'm setting up*
12
+ ```python
13
+ from angel_cpu import *
14
+ ARCH=cpu("ARCH")
15
+ ```
16
+ *Alright now i'm done setting up.*
17
+ As you can see we have a class here
18
+ ```python
19
+ from angel_cpu import *
20
+ ARCH=cpu("ARCH")#THIS RIGHT HERE
21
+ ```
22
+ Let's first set up the basic CPU ARCH
23
+ ```python
24
+ from angel_cpu import *
25
+ ARCH=cpu("ARCH")
26
+ # no reset does NOT reset the ARCH's registers and ram it just resets the ARCH's PC and Program
27
+ ARCH.reset()
28
+ # The name of the Register doesn't matter go crazy if you want
29
+ # The amount of Registers also don't matter, you can add like 50 of them and it wouldn't care
30
+ ARCH.add_register("Rxa")
31
+ ARCH.add_register("Rxb")
32
+ ARCH.add_register("Rxc")
33
+ ARCH.add_register("Rxe")
34
+ # the size is calculated by the x (400) times the y (200)
35
+ ARCH.add_ram(400,200)
36
+ # 32 bit integer limit
37
+ ARCH.set_max(0xffffffff)
38
+ # we're setting the command symbol to be ; so it's like real ASM
39
+ ARCH.set_comment_symbol(";")
40
+ ```
41
+ *huff* that took me 30 minutes to write... (all of the time was because of the comments XD)\
42
+ Anyway... let's go over what the eclipse is all of these before my head explodes
43
+
44
+ `ARCH.reset()`
45
+
46
+ Resets the ARCH's PC and Program
47
+
48
+ `ARCH.add_register("Register name")`
49
+
50
+ adds a register
51
+
52
+ `ARCH.add_ram(400,200)`
53
+
54
+ set's the ram size which with this one will be... *give me a sec i'm calculating...* 80000 cells... *WOW*
55
+
56
+ `ARCH.set_max(0xffffffff)`
57
+
58
+ 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***
59
+
60
+ `ARCH.set_comment_symbol(";")`
61
+
62
+ This Sets the comment symbol, any line that starts with it will be ignored in the assembler.\
63
+
64
+ Now that we got that covered it's time to add some opcodes so we can actually do stuff
65
+ ```python
66
+ from angel_cpu import *
67
+ ARCH=cpu("ARCH")
68
+ # no reset does NOT reset the ARCH's registers and ram it just resets the ARCH's PC and Program
69
+ ARCH.reset()
70
+ # The name of the Register doesn't matter go crazy if you want
71
+ # The amount of Registers also don't matter, you can add like 50 of them and it wouldn't care
72
+ ARCH.add_register("Rxa")
73
+ ARCH.add_register("Rxb")
74
+ ARCH.add_register("Rxc")
75
+ ARCH.add_register("Rxe")
76
+ # the size is calculated by the x (400) times the y (200)
77
+ ARCH.add_ram(400,200)
78
+ # 32 bit integer limit
79
+ ARCH.set_max(0xffffffff)
80
+ # we're setting the command symbol to be ; so it's like real ASM
81
+ ARCH.set_comment_symbol(";")
82
+ def MOV(reg,value):
83
+ ARCH.set_register(reg,value)
84
+ def LOG(txt):
85
+ if txt in ARCH.registers:
86
+ print(ARCH.registers[txt])
87
+ else:
88
+ print(txt)
89
+ # It's important to note that when adding opcodes don't put parentheses on the function
90
+ # ARCH.add_opcode(0x0,MOV()) <-- incorrect, paratheses arnt opposed to be in the opcodes
91
+ # ARCH.add_opcode(0x0,MOV) <-- correct
92
+ ARCH.add_opcode(0x0,MOV)
93
+ ARCH.add_opcode(0x1,LOG)
94
+ c="""
95
+ MOV Rxa 10
96
+ LOG Rxa
97
+ """
98
+ ARCH.assemble(c)
99
+ ARCH.run()
100
+ ```
101
+ Okay there's a lot of stuff here so let's talk about the things that changed
102
+
103
+ `ARCH.add_opcode(hex_ID function)`
104
+
105
+ This adds an opcode, and when adding the function, please, **do not add parentheses**
106
+
107
+ `ARCH.assemble(code)`
108
+
109
+ 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.
110
+
111
+ `ARCH.run()`
112
+
113
+ This takes the code from the Program and runs it, simple and very useful.
114
+
115
+ Now let's talk about the ASM format
116
+ ```AngelASM
117
+ MOV Rxa 10
118
+ LOG Rxa
119
+ ```
120
+ 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!
121
+
122
+ 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...
123
+ ```ASM_helper
124
+ add_regiser
125
+ add_ram
126
+ add_opcode
127
+ add_intruction
128
+
129
+ set_window_name
130
+ set_max
131
+ set_pc
132
+ set_register
133
+ set_ram
134
+ reset
135
+ set_comment_symbol
136
+
137
+ get_register
138
+ get_ram
139
+ get_pc
140
+
141
+ text
142
+ wait
143
+ scroll
144
+ is_Mouse_Touching_Surface
145
+ show_mouse
146
+ quit
147
+ frame
148
+ load_pixels
149
+ events
150
+ clear
151
+ clear_logs
152
+ is_held
153
+ render_surfaces
154
+ add_surface
155
+ add_pixel
156
+ text_input
157
+ mouse_down_on_group
158
+ mouse_pos
159
+
160
+ assemble
161
+
162
+ run
163
+ ```
164
+ *huff* alright, that's all of them....\
165
+ that's it for now, bye!
@@ -0,0 +1,388 @@
1
+ import pygame
2
+ import sys
3
+ from ctypes import *
4
+ import shlex
5
+ import ast
6
+ import os
7
+ __Version__="0.1"
8
+ if sys.platform == "win32":
9
+ from ctypes import windll
10
+ try:
11
+ windll.shcore.SetProcessDpiAwareness(1)
12
+ except:
13
+ pass
14
+ class screen:
15
+ def __init__(self,font="consolas",fontsize=24):
16
+ pygame.init()
17
+ pygame.display.set_caption("<Undefined ARCH>")
18
+ self.clock=pygame.time.Clock()
19
+ self.clock.tick(60)
20
+ self.screen = pygame.display.set_mode((600, 600))
21
+ self.font = pygame.font.SysFont(font, fontsize)
22
+ self.pixel_layer=pygame.Surface(self.screen.get_size(), pygame.SRCALPHA)
23
+ self.printBuffer=[]
24
+ self.y=0
25
+ self.held_keys = {}
26
+ self.txtlog=[]
27
+ self.colorlog=[]
28
+ self.endlog=[]
29
+ self.xlog=[]
30
+ self.pixellog=[]
31
+ self.surfaces={}
32
+ self.ylog=[]
33
+ def text(self,txt,x,color=(255,255,255),AddToTxtLog=True,end="\n",customy=(False,0)):
34
+ lines=txt.split("\n")
35
+ for line in lines:
36
+ if customy[0]==True:
37
+ self.screen.blit(self.font.render(line, True, color),(x,customy[1]))
38
+ else:
39
+ self.screen.blit(self.font.render(line, True, color), (x, self.y))
40
+ if end=="\n" and customy[0]==False:
41
+ self.y+=20
42
+ if AddToTxtLog:
43
+ self.txtlog.append(line)
44
+ self.colorlog.append(color)
45
+ self.endlog.append(end)
46
+ self.xlog.append(x)
47
+ if customy[0]==True:
48
+ self.ylog.append(customy)
49
+ else:
50
+ self.ylog.append((False,self.y))
51
+ def clear(self):
52
+ self.screen.fill((0, 0, 0))
53
+ self.pixel_layer.fill((0,0,0,0))
54
+ self.y=0
55
+ def events(self):
56
+ ES = "n"
57
+ for event in pygame.event.get():
58
+ if event.type == pygame.QUIT:
59
+ pygame.quit()
60
+ sys.exit()
61
+ elif event.type == pygame.KEYDOWN:
62
+ key_name = pygame.key.name(event.key)
63
+ ES = f"kDWN{key_name}"
64
+ self.held_keys[key_name] = True
65
+ elif event.type == pygame.KEYUP:
66
+ key_name = pygame.key.name(event.key)
67
+ ES = f"kUP{key_name}"
68
+ self.held_keys[key_name] = False
69
+ elif event.type == pygame.MOUSEBUTTONDOWN:
70
+ ES = ("mDWN",pygame.mouse.get_pos())
71
+ elif event.type == pygame.MOUSEBUTTONUP:
72
+ ES = ("mUP",pygame.mouse.get_pos())
73
+ return ES
74
+ def isHeld(self, kName):
75
+ return self.held_keys.get(kName, False)
76
+ def input(self, prompt="", promptcolor=(255, 255, 255), promtend="", promptx = 0):
77
+ itext = ""
78
+ basey=self.y
79
+ blink=""
80
+ blinktime=0
81
+ while True:
82
+ self.clear()
83
+ self.loadpixels()
84
+ i=0
85
+ for line in self.txtlog:
86
+ display = "".join(line)
87
+ color=self.colorlog[i]
88
+ end=self.endlog[i]
89
+ x=self.xlog[i]
90
+ y=self.ylog[i]
91
+ i+=1
92
+ self.text(display, x,color,False,end=end,customy=(y))
93
+ i2=0
94
+ for j in self.pixellog:
95
+ px = self.pixellog[i2][0][0]
96
+ py = self.pixellog[i2][0][1]
97
+ pcol = self.pixellog[i2][1]
98
+ psize = self.pixellog[i2][2]
99
+ pgroup = self.pixellog[i2][3]
100
+ self.pixel(px, py, pcol, psize, pgroup, False)
101
+ i2+=1
102
+ self.text(prompt + itext+blink, promptx, promptcolor, False, end=promtend,) # display current input
103
+ self.loadpixels()
104
+ pygame.display.flip()
105
+ event=pygame.event.wait()
106
+ if event.type == pygame.QUIT:
107
+ sys.exit() # user closed the window
108
+ elif event.type == pygame.KEYDOWN:
109
+ key_name = pygame.key.name(event.key)
110
+ if key_name == "backspace":
111
+ itext = itext[:-1]
112
+ elif key_name == "return":
113
+ return itext
114
+ elif key_name == "space":
115
+ itext += " "
116
+ elif len(key_name) == 1:
117
+ itext += self.keyNameWithShift(event)
118
+ def clearlogs(self):
119
+ self.txtlog=[]
120
+ self.colorlog=[]
121
+ self.endlog=[]
122
+ self.xlog=[]
123
+ self.pixellog=[]
124
+ self.surfaces={}
125
+ self.ylog=[]
126
+ def keyNameWithShift(self, event):
127
+ key_name = pygame.key.name(event.key)
128
+ shift_held = pygame.key.get_mods() & pygame.KMOD_SHIFT
129
+ if key_name.isalpha() and shift_held:
130
+ key_name = key_name.upper()
131
+ shift_map = {
132
+ '1': '!', '2': '@', '3': '#', '4': '$', '5': '%',
133
+ '6': '^', '7': '&', '8': '*', '9': '(', '0': ')',
134
+ '-': '_', '=': '+', '[': '{', ']': '}', '\\': '|',
135
+ ';': ':', "'": '"', ',': '<', '.': '>', '/': '?',
136
+ '`': '~'
137
+ }
138
+ if key_name in shift_map and shift_held:
139
+ key_name = shift_map[key_name]
140
+ return key_name
141
+ def newframe(self):
142
+ self.rendersurfaces()
143
+ self.screen.blit(self.pixel_layer, (0, 0))
144
+ pygame.display.flip()
145
+ self.clock.tick(60)
146
+ def pixel(self, x=0, y=0, color=(255, 255, 255),size=1,group=None,addtopixellog=True):
147
+ pygame.draw.rect(self.pixel_layer, color, (x, y, size, size))
148
+ if addtopixellog==True:
149
+ self.pixellog.append(((x,y), color, size,group))
150
+ else:
151
+ pass
152
+ def loadpixels(self):
153
+ self.screen.blit(self.pixel_layer, (0, 0))
154
+ def MouseClickedOnGroup(self, event, group=None):
155
+ if isinstance(event, tuple) and event[0] == "mDWN":
156
+ mouse_x, mouse_y = event[1]
157
+ for px, color, size, pxgroup in self.pixellog:
158
+ if pxgroup == group:
159
+ px_x, px_y = px
160
+ if px_x <= mouse_x < px_x + size and px_y <= mouse_y < px_y + size:
161
+ return True
162
+ return False
163
+ def MousePos(self):
164
+ return pygame.mouse.get_pos()
165
+ def showmouse(self,visibility=True):
166
+ pygame.mouse.set_visible(visibility)
167
+ def quit(self):
168
+ pygame.quit()
169
+ sys.exit()
170
+ def addsurface(self,name,width,height,col=(0,0,255),posx=0,posy=0):
171
+ self.surfaces[name]={}
172
+ self.surfaces[name]["data"]=pygame.Surface((width,height),pygame.SRCALPHA)
173
+ self.surfaces[name]["data"].fill(col)
174
+ self.surfaces[name]["pos"]=(posx,posy)
175
+ self.surfaces[name]["rect"]= self.surfaces[name]["data"].get_rect(topleft=(posx, posy))
176
+ def rendersurfaces(self):
177
+ for name in self.surfaces:
178
+ self.screen.blit(self.surfaces[name]["data"], self.surfaces[name]["pos"])
179
+ def mouseTouchingSurface(self, name):
180
+ mouse_pos = pygame.mouse.get_pos()
181
+ return self.surfaces[name]["rect"].collidepoint(mouse_pos)
182
+ def wait(self,t):
183
+ pygame.time.wait(t)
184
+ def scroll(self,dx,dy):
185
+ self.screen.scroll(dx,dy)
186
+ def SetWindowName(self,name):
187
+ pygame.display.set_caption(f"{name}")
188
+ class cpu:
189
+ def __init__(self,Arch_name="Undefined ARCH"):
190
+ self.registers={}
191
+ self.ram={}
192
+ self.opcodes={}
193
+ self.pc=0
194
+ self.MaxValue=0xffffffff
195
+ self.program=[]
196
+ self.sc=screen()
197
+ self.comment_symbol=";"
198
+ self.Arch_name=Arch_name
199
+ self.sc.SetWindowName(Arch_name)
200
+ self.BuildCommands={}
201
+ #-/main/-#
202
+ def main(self):
203
+ self.set_window_name("<ANGEL>")
204
+ self.text("welcome to Angel-CPU",0)
205
+ self.frame()
206
+ self.text("Type CMD for a list of commands",0)
207
+ self.frame()
208
+ while True:
209
+ i=self.text_input(">",(255,0,0))
210
+ if i == "CMD":
211
+ self.clear()
212
+ self.clear_logs()
213
+ self.text("CMD: lists commands",0)
214
+ self.text("INFO: Displays Information about Angel",0)
215
+ self.text("Version: Displays Angel's Version",0)
216
+ self.frame()
217
+ self.text_input("press enter to continue...")
218
+ elif i == "INFO":
219
+ self.clear()
220
+ self.clear_logs()
221
+ self.text("<Angel>: A CPU framework for",0)
222
+ self.text("building virtual CPUs in python,",0)
223
+ self.text("You can find more information about",0)
224
+ self.text("Angel in the README file.",0)
225
+ self.frame()
226
+ self.text_input("press enter to continue...")
227
+ elif i == "Version":
228
+ self.text(f"Angel Version:{__Version__}",0)
229
+ self.text_input("press enter to continue...")
230
+ self.clear_logs()
231
+ self.clear()
232
+ #-/add's/-#
233
+ def add_register(self,register):
234
+ self.registers[register]=0x0
235
+ def add_ram(self,size_x,size_y):
236
+ self.ram=[0x0]*size_x*size_y
237
+ def add_opcode(self,opcode,command):
238
+ self.opcodes[opcode]=command
239
+ def add_instruction(self,instruction):
240
+ self.program.append(instruction)
241
+ #-/set's/-#
242
+ def set_window_name(self,name):
243
+ self.sc.SetWindowName(name)
244
+ def set_max(self,max):
245
+ self.MaxValue=max
246
+ def set_pc(self,pc):
247
+ self.pc=pc
248
+ def set_register(self,register,value):
249
+ if type(value) == int:
250
+ if value <= self.MaxValue:
251
+ self.registers[register]=value
252
+ else:
253
+ self.registers[register]=0x0
254
+ elif type(value) == str:
255
+ if len(value) <= self.MaxValue:
256
+ self.registers[register]=value
257
+ else:
258
+ self.registers[register]=""
259
+ elif type(value) == tuple:
260
+ if len(value) <= self.MaxValue:
261
+ self.registers[register]=value
262
+ else:
263
+ self.registers[register]=()
264
+ elif type(value) == list:
265
+ if len(value) <= self.MaxValue:
266
+ self.registers[register]=value
267
+ else:
268
+ self.registers[register]=[]
269
+ elif type(value) == dict:
270
+ if len(value) <= self.MaxValue:
271
+ self.registers[register]=value
272
+ else:
273
+ self.registers[register]={}
274
+ def set_ram(self,addr,value):
275
+ if type(addr) == int:
276
+ if addr <= self.MaxValue:
277
+ self.ram[addr]=value
278
+ else:
279
+ self.ram[addr]=0x0
280
+ if type(addr) == str:
281
+ if len(addr) <= self.MaxValue:
282
+ self.ram[addr]=value
283
+ else:
284
+ self.ram[addr]=""
285
+ if type(addr) == tuple:
286
+ if len(addr) <= self.MaxValue:
287
+ self.ram[addr]=value
288
+ else:
289
+ self.ram[addr]=()
290
+ if type(addr) == list:
291
+ if len(addr) <= self.MaxValue:
292
+ self.ram[addr]=value
293
+ else:
294
+ self.ram[addr]=[]
295
+ if type(addr) == dict:
296
+ if len(addr) <= self.MaxValue:
297
+ self.ram[addr]=value
298
+ else:
299
+ self.ram[addr]={}
300
+ def reset(self):
301
+ self.pc=0
302
+ self.program=[]
303
+ def set_comment_symbol(self,symbol):
304
+ self.comment_symbol=symbol
305
+ #-/Get's/-#
306
+ def get_register(self,register):
307
+ return self.registers[register]
308
+ def get_ram(self,addr):
309
+ return self.ram[addr]
310
+ def get_pc(self):
311
+ return self.pc
312
+ #-/screen/-#
313
+ def text(self, txt, x, color=(255, 255, 255), AddToTxtLog=True, end="\n", customy=(False, 0)):
314
+ self.sc.text(txt, x, color, AddToTxtLog, end, customy)
315
+ def wait(self,t):
316
+ self.sc.wait(t)
317
+ def scroll(self,dx,dy):
318
+ self.sc.scroll(dx,dy)
319
+ def is_Mouse_Touching_Surface(self,name):
320
+ return self.sc.mouseTouchingSurface(name)
321
+ def show_mouse(self,visibility=True):
322
+ self.sc.showmouse(visibility)
323
+ def quit(self):
324
+ pygame.quit()
325
+ sys.exit()
326
+ def frame(self):
327
+ self.sc.newframe()
328
+ def load_pixels(self):
329
+ self.sc.loadpixels()
330
+ def events(self):
331
+ self.sc.events()
332
+ def clear(self):
333
+ self.sc.clear()
334
+ def clear_logs(self):
335
+ self.sc.clearlogs()
336
+ def is_held(self,key):
337
+ return self.sc.isHeld(key)
338
+ def render_surfaces(self):
339
+ self.sc.rendersurfaces()
340
+ def add_surface(self,name,width,height,col=(0,0,255),posx=0,posy=0):
341
+ self.sc.addsurface(name,width,height,col,posx,posy)
342
+ def add_pixel(self, x=0, y=0, color=(255, 255, 255),size=1,group=None,addtopixellog=True):
343
+ self.sc.pixel(x,y,color,size,group,addtopixellog)
344
+ def text_input(self, prompt="", promptcolor=(255, 255, 255), promtend="", promptx = 0):
345
+ return self.sc.input(prompt,promptcolor,promtend,promptx)
346
+ def mouse_down_on_group(self,event,group=None):
347
+ return self.sc.MouseClickedOnGroup(event,group)
348
+ def mouse_pos(self):
349
+ return self.sc.MousePos()
350
+ #-/assembler/-#
351
+ def assemble(self, code):
352
+ lines = code.strip().split("\n")
353
+ name_to_opcode = {}
354
+ for opcode, func in self.opcodes.items():
355
+ name_to_opcode[func.__name__.upper()] = opcode
356
+ for line in lines:
357
+ line = line.strip()
358
+ if line.startswith(self.comment_symbol):
359
+ continue
360
+ if not line:
361
+ continue
362
+ parts = shlex.split(line)
363
+ inst_name = parts[0].upper()
364
+ args = []
365
+ for arg in parts[1:]:
366
+ try:
367
+ value = ast.literal_eval(arg)
368
+ except:
369
+ value = arg
370
+ args.append(value)
371
+ if inst_name in name_to_opcode:
372
+ self.add_instruction((name_to_opcode[inst_name], tuple(args)))
373
+ else:
374
+ raise Exception(f"Unknown instruction: {inst_name}")
375
+ #-/run/-#
376
+ def run(self):
377
+ while self.pc<len(self.program):
378
+ command=self.program[self.pc][0]
379
+ args=self.program[self.pc][1]
380
+ self.pc+=1
381
+ for opcode in self.opcodes:
382
+ if opcode==command:
383
+ self.opcodes[opcode](*args)
384
+ def main():
385
+ Angel = cpu("<Angel>")
386
+ Angel.main()
387
+ if __name__ == "__main__":
388
+ main()
@@ -0,0 +1 @@
1
+ from Angel import *
@@ -0,0 +1,184 @@
1
+ Metadata-Version: 2.4
2
+ Name: angel-cpu
3
+ Version: 0.1
4
+ Summary: A CPU framework
5
+ Home-page:
6
+ Author: ERROR-Xmakernotfound
7
+ Author-email:
8
+ Requires-Python: >=3.8
9
+ Description-Content-Type: text/markdown
10
+ License-File: LICENSE
11
+ Requires-Dist: pygame
12
+ Dynamic: author
13
+ Dynamic: description
14
+ Dynamic: description-content-type
15
+ Dynamic: license-file
16
+ Dynamic: requires-dist
17
+ Dynamic: requires-python
18
+ Dynamic: summary
19
+
20
+ Hello!\
21
+ Have you ever tried to make a cpu simulation but don't want to write 300+ lines of code?\
22
+ Well then you don't have to anymore!\
23
+ AngelCPU does most of the heavy lifting for you, so let's get started before I fall asleep while typing this.
24
+ # Getting Started
25
+ First lets install Angel
26
+ ```bash
27
+ pip install angel-cpu
28
+ ```
29
+ Now, let's start with some simple stuff,
30
+ *give me a second i'm setting up*
31
+ ```python
32
+ from angel_cpu import *
33
+ ARCH=cpu("ARCH")
34
+ ```
35
+ *Alright now i'm done setting up.*
36
+ As you can see we have a class here
37
+ ```python
38
+ from angel_cpu import *
39
+ ARCH=cpu("ARCH")#THIS RIGHT HERE
40
+ ```
41
+ Let's first set up the basic CPU ARCH
42
+ ```python
43
+ from angel_cpu import *
44
+ ARCH=cpu("ARCH")
45
+ # no reset does NOT reset the ARCH's registers and ram it just resets the ARCH's PC and Program
46
+ ARCH.reset()
47
+ # The name of the Register doesn't matter go crazy if you want
48
+ # The amount of Registers also don't matter, you can add like 50 of them and it wouldn't care
49
+ ARCH.add_register("Rxa")
50
+ ARCH.add_register("Rxb")
51
+ ARCH.add_register("Rxc")
52
+ ARCH.add_register("Rxe")
53
+ # the size is calculated by the x (400) times the y (200)
54
+ ARCH.add_ram(400,200)
55
+ # 32 bit integer limit
56
+ ARCH.set_max(0xffffffff)
57
+ # we're setting the command symbol to be ; so it's like real ASM
58
+ ARCH.set_comment_symbol(";")
59
+ ```
60
+ *huff* that took me 30 minutes to write... (all of the time was because of the comments XD)\
61
+ Anyway... let's go over what the eclipse is all of these before my head explodes
62
+
63
+ `ARCH.reset()`
64
+
65
+ Resets the ARCH's PC and Program
66
+
67
+ `ARCH.add_register("Register name")`
68
+
69
+ adds a register
70
+
71
+ `ARCH.add_ram(400,200)`
72
+
73
+ set's the ram size which with this one will be... *give me a sec i'm calculating...* 80000 cells... *WOW*
74
+
75
+ `ARCH.set_max(0xffffffff)`
76
+
77
+ 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***
78
+
79
+ `ARCH.set_comment_symbol(";")`
80
+
81
+ This Sets the comment symbol, any line that starts with it will be ignored in the assembler.\
82
+
83
+ Now that we got that covered it's time to add some opcodes so we can actually do stuff
84
+ ```python
85
+ from angel_cpu import *
86
+ ARCH=cpu("ARCH")
87
+ # no reset does NOT reset the ARCH's registers and ram it just resets the ARCH's PC and Program
88
+ ARCH.reset()
89
+ # The name of the Register doesn't matter go crazy if you want
90
+ # The amount of Registers also don't matter, you can add like 50 of them and it wouldn't care
91
+ ARCH.add_register("Rxa")
92
+ ARCH.add_register("Rxb")
93
+ ARCH.add_register("Rxc")
94
+ ARCH.add_register("Rxe")
95
+ # the size is calculated by the x (400) times the y (200)
96
+ ARCH.add_ram(400,200)
97
+ # 32 bit integer limit
98
+ ARCH.set_max(0xffffffff)
99
+ # we're setting the command symbol to be ; so it's like real ASM
100
+ ARCH.set_comment_symbol(";")
101
+ def MOV(reg,value):
102
+ ARCH.set_register(reg,value)
103
+ def LOG(txt):
104
+ if txt in ARCH.registers:
105
+ print(ARCH.registers[txt])
106
+ else:
107
+ print(txt)
108
+ # It's important to note that when adding opcodes don't put parentheses on the function
109
+ # ARCH.add_opcode(0x0,MOV()) <-- incorrect, paratheses arnt opposed to be in the opcodes
110
+ # ARCH.add_opcode(0x0,MOV) <-- correct
111
+ ARCH.add_opcode(0x0,MOV)
112
+ ARCH.add_opcode(0x1,LOG)
113
+ c="""
114
+ MOV Rxa 10
115
+ LOG Rxa
116
+ """
117
+ ARCH.assemble(c)
118
+ ARCH.run()
119
+ ```
120
+ Okay there's a lot of stuff here so let's talk about the things that changed
121
+
122
+ `ARCH.add_opcode(hex_ID function)`
123
+
124
+ This adds an opcode, and when adding the function, please, **do not add parentheses**
125
+
126
+ `ARCH.assemble(code)`
127
+
128
+ 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.
129
+
130
+ `ARCH.run()`
131
+
132
+ This takes the code from the Program and runs it, simple and very useful.
133
+
134
+ Now let's talk about the ASM format
135
+ ```AngelASM
136
+ MOV Rxa 10
137
+ LOG Rxa
138
+ ```
139
+ 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!
140
+
141
+ 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...
142
+ ```ASM_helper
143
+ add_regiser
144
+ add_ram
145
+ add_opcode
146
+ add_intruction
147
+
148
+ set_window_name
149
+ set_max
150
+ set_pc
151
+ set_register
152
+ set_ram
153
+ reset
154
+ set_comment_symbol
155
+
156
+ get_register
157
+ get_ram
158
+ get_pc
159
+
160
+ text
161
+ wait
162
+ scroll
163
+ is_Mouse_Touching_Surface
164
+ show_mouse
165
+ quit
166
+ frame
167
+ load_pixels
168
+ events
169
+ clear
170
+ clear_logs
171
+ is_held
172
+ render_surfaces
173
+ add_surface
174
+ add_pixel
175
+ text_input
176
+ mouse_down_on_group
177
+ mouse_pos
178
+
179
+ assemble
180
+
181
+ run
182
+ ```
183
+ *huff* alright, that's all of them....\
184
+ that's it for now, bye!
@@ -0,0 +1,11 @@
1
+ LICENSE
2
+ README.md
3
+ setup.py
4
+ angel_cpu/Angel.py
5
+ angel_cpu/__init__.py
6
+ angel_cpu.egg-info/PKG-INFO
7
+ angel_cpu.egg-info/SOURCES.txt
8
+ angel_cpu.egg-info/dependency_links.txt
9
+ angel_cpu.egg-info/entry_points.txt
10
+ angel_cpu.egg-info/requires.txt
11
+ angel_cpu.egg-info/top_level.txt
@@ -0,0 +1,2 @@
1
+ [console_scripts]
2
+ Angel = Angel:main
@@ -0,0 +1 @@
1
+ pygame
@@ -0,0 +1 @@
1
+ angel_cpu
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+
angel_cpu-0.1/setup.py ADDED
@@ -0,0 +1,21 @@
1
+ from setuptools import setup, find_packages
2
+ setup(
3
+ name="angel-cpu",
4
+ version="0.1",
5
+ author="ERROR-Xmakernotfound",
6
+ author_email="",
7
+ description="A CPU framework",
8
+ long_description=open("README.md", encoding="utf-8").read(),
9
+ long_description_content_type="text/markdown",
10
+ url="",
11
+ packages=find_packages(),
12
+ python_requires=">=3.8",
13
+ install_requires=[
14
+ "pygame",
15
+ ],
16
+ entry_points={
17
+ "console_scripts": [
18
+ "Angel=Angel:main",
19
+ ],
20
+ },
21
+ )