The GHOST Simulator set
Ghost is a computer architecture I made as a thought experiment, and also as an easy way to introduce people to the ideas of assembly. I've dubbed it a 'fantasy CPU': think a 'fantasy console' except it's just a CPU architecture.
This project has many components, each in their own folder.
Simulator
This is the heart of the projects. It steps through given programs and executes them, drawing on the screen, and handling other IO. It also includes a debugger, with breakpoints, and a full memory and register inspector that also helps parse the hardware stack pointers. Features such as: break on access of a certain memory location, manually editing registers, and arbitrary jumps are planned, but not yet implemented.
Assembler
This is the go-to home for development for GHOST. It takes the custom assembly language, and converts it to bytes for the simulator to execute. See the docs for the instruction set, and other notes on the architecture such as memory layout.
Programs
Various assembly programs, including:
- Memory management
- A full ram-based filesystem
- A WIP shell
- Text graphics routines
Lang
The beginnnings of a C compiler, built in python, targeting GHOST
Hmm
This is a WIP circuit-level logisim model of the GHOST computer. As of the most recent change, I believe many core instructions are implemented. However I haven't added interrupts yet, and graphics might be impractical, given the speed of the simulation.
Docs
Documentation, including to-do lists, system architecture notes, IO notes, memory layout notes, instruction set notes, program notes, and more scattered notes. Also contains various helper files: sublime syntax highlighting for the assembly, sublime build system for assembly, a script to read the instruction set from the docs and parse it into cpp code, then inject it into the simulator source code.
Huge progress
While not accompanied by a release, it's been over a year since the last update!
So much has changed, a changelog would be impracticle. It seems more reasonable to instead list the features of the new elements!
In the C++ simulator, we now have a debugger, featuring:
- Memory Inspector
- Register Inspector
- Interpretting stack variables: highlights stack
- Highlights program counter: can automatically follow it
- Breakpoints
The assembler remains largely unchanged, except for bugfixes. However I'm working on adding a whole new way of programming for GHOST: a C compiler!
- Tokenization, AST-building, and assembly generation all work to some degree
- Currently constructing a semantic pass to perform typechecking
- Can be included in ramdisks
- Allows inline assmebly
And, a new way to run your code as well, thanks to a logisim simulation!
- Implements most of the instructions using a complex instruction architecture.
- Does not implement graphics, and it is not planned
- Does not implement interrupts, but is planned
Complete Rewrite!
After loads of incremental changes, a complete rewrite, and then even more changes we've arrived at Release 3!
- More features in the assembler (Org, sketchy macros, better data types)
- Include other binary/assembly files in assembler
- There's only one stack
- Better interrupts
- Better documentation included in the repo in markdown
- Wrote a kernel thing! malloc!
- Some more programs, but now snake is broken
Efficiency and speed greatly improved
Mostly just performance changes.
- Changed instructionSet to remove the 'R' prefix, so that integers can be directly compared in C# later
- Added configuration options via settings.ini
- binColor uses math instead of string manipulation, which was stupid in the first place
- Uses match/state, which is slightly faster
- Uses ctypes.c_ushort for the MEMORY, which much faster
Upload of old version: Ghost 18!
This is an upload of an old version, but it's special enough to deserve an upload because it comes with a bit of a bonus: it has a circuit simulator to go with it. Attatched is a circuitverse file that will let you watch how the computer works in real-time! However, I cannot remember how many of the instructions are implemented, nor how effectivly. Nevertheless, it was an amazingly fun project that whiled away many hours.
Also attached is a very cool piece of what I'm calling 'live documentation'. Attatched is a python script that has some pretty cool capabilities, listed below:
Index
This is the most interesting one! Loops through the whole database and reads the information from it to store in the reference file. However, it also recompiles the micro ASM, a simple simple language, into the microcode. The micro ASM is a list of symbols seperated by commas that are intended to be human readable, where an arrow designates a move from one location to another, and special codes are 4 bit data prefixed with the code 'area'. There are two areas, MF for math flags, and MC for mini commands. The mini commands are commands that don't need a 'to' and 'from' section, so can be seperated from the rest. The microcode architecture is built such that the first four bits are the 'from' or the area code, while the last four bits are the 'to' section or, if in an area, the instruction within the area. This 'index' command validates the microcode, checks the unique assembly name, and saves all of it to the reference file.
ROM Creator
The rom creator takes information stored in the reference file and compiles the microcode into a ROM for the simulated computer
Compiler
Missnamed by ignorance, this assembler uses the reference file to assemble into a hex format that can be pasted into the circuitverse simulator.
Simulator
Because it doesn't have a screen, this release of Ghost uses a beautiful python-curses terminal simulator that can display tons of information at once, including decoding the microcode instructions for each instruction and a cool scrolling memory dump.
First release of GHOST!
Running todo list:
- Rename the project, ghost is too generic
- Handle errors better in all aspects of the program
- Simplify the confusion between addresses and values, especially in the JMP and DD commands
- Clean up Readmes
- Add keybind to toggle power button
Changlog:
- Assembler outputs to hex by default, and the simulator can read it
- Finished the snak game demo
- Added register dump on an exception
- Added JumpRegister to support conditionals
- Added function to update just the GUI or Stack sections of the screen
- Better conditionals for jumps, calls, and returns
- Fixed syntax highlighting