Files changed (3)
- self.wins.append(curses.newwin(self.cpu.mem.read().b, self.cpu.mem.read().b, self.cpu.mem.read().b, self.cpu.mem.read().b))
+The CPU Hooks interface has changed a lot since it was first released, it no longer supports custom op-code creation, as that
+made little sense, as CPUs don't just get new op-codes when you insert new hardware. Rather they usually have their own
+memory addresses they access and that's how the CPU talks to the new hardware. This I believe is called DMA(direct memory access).
re is a Base class which must be sub-classed to make hooks work, there is an example Hook provided.
-Since these are custom op-codes being hooked into the CPU, there is of course no coder commands for these codes, as a result in order to use them, you must manually use the "set" coder command or add them via a hex-editor.
+The class you need to sub-class is BaseCPUHook, and you need to supply one class variable, called ports. Here is an
-A hook can also attach itself to the hosts network interface and allow your simulated CPU to access the Internet.
+Here we are telling the CPU that this virtual I/O device can be accessed on CPU I/O ports 32 and 33. And we supply some logic for
+these ports to work within the CPU/Virtual Machine. The first method "out_32" is an OUTPUT method, where the CPU can send some
+data over to this virtual device to process. This is in the form of a register, so it will be a 16-bit integer. The second
+method "in_32" allows the CPU to request data from this virtual device, the data returned should be a 16-bit integer.
-With this new updated version, you can select the opname along with the opcode in the subclass, and the coder will use it.
+By using the standard OUT and IN operations you can write and read data from your virtual I/O device.
This file is provided as an introduction to how this works internally, please see the other text files for usage.
-The CPU core is fully customizable, but if any of the memory sizes are changed, it can break compatibility with other binary files.
-That being said, if your goal of using this code is to build your own virtual machine for your application, then feel free to change the memory sizes to suit your requirements:
+The CPU core is fully customizable, but if any of the op-codes are changed, it can break compatibility with other binary files.
+That being said, if your goal of using this code is to build your own virtual machine for your application, then feel free to change the op-codes to suit your requirements.
- Here you can add new registers, which you will also need to add new op-codes for manipulating them.
In the __init__ of this class is where the CPU Memory, persistent storage, and shared memory is initialized.
- mem is a Memory class, using the default size of 64 bytes. Increase the 64 to increase the size of the binary files and available executable memory.
- storage is a Storage class, which is a subclass of Memory, using the default size of 4K. This is the persistent storage which is accessed using a software interrupt. Various code can storage and access data from here.
- imem is a Memory class, using the default size of 1K. This is the shared memory, where executable code can store non-executable data. If you want to execute data from here, you need to first move it into CPU Memory.
You can add a parameter into run() to tell it where to start executing, say if your binary file has a header.
+ This class is where all the magic happens, you shouldn't need to alter anything in here unless you have very specific requirements.
+ Instead you should either sub-class this and implement the needed __init__ method to initialize memory and devices, or
+ This class controls the CPU registers, you can subclass this and add/remove registers by changing the class variables.
+ pushable variable is a list of registers which can be pushed onto the stack without any adverse effects at runtime.
+ This exception is raised if there is a bytecode runtime error, usually caused by an error in the user's bytecode.
- This is an example CPU Hook to display how a hook is created and used, it provided 2 functions to your binary.
- Function 33 is an example of a debugging function which displays the current state of the CPU registers.
+ This is an example CPU Hook to display how a hook is created and used, it provided 3 functions to your binary.
+ I/O port 33 is an example of a debugging function which displays the current state of the CPU registers.
+ This implements a basic tty-based display and keyboard for basic input/output operations from the CPU.
This class is intended to be extended with your own CPU Hook code. Please see HelloWorldHook as an example.
There are many functions in this class which control the memory access facility, which the CPU uses.
These functions will not be directly edited or used by you, as they are already implemented in the CPU op-codes.
Essentually, this class is exposed as an array. The CPU gets and sets memory locations using array syntax:
This class also keeps track of the current pointer location, which is used by the CPU for various operations.
- It is also able to read a null-terminated string with a helper function
, which a software interrupt exposes.
- This class I sometimes wonder if I really should have created it and built everything around it...
- It controls the attribute setting to prevent values outside the 255 range, which this CPU simulator does not yet support.
+ This is the base data Unit which this CPU Virtual Machine uses to exchange data between code, memory, and disk.
+ This class is meant to be sub-classed, see other Unit classes below for examples on how sub-classing works.
-Please read the other included text files for more information on how to use this CPU simulator toolkit.
+ This is a Unit that only supports 16-bit integers. This Unit is mostly used with memory addresses.
+ This is a Unit that only supports 32-bit integers. This is not used much in the code at all, as the VM isn't really 32-bit address enabled.