3D RENDERER
I finally got the 3D renderer to work
It took SO long (18+ hours in total?
) but it’s so cool and really shows the capabilities of this tiny CPU 

It took so long to make because I had to write everything in assembly with 🚫 no functions, 🚫 no control structures and 🚫no variables


Obviously trying to program this CPU with such a tiny ISA and a stupid assembler is borderline impossible - you have to manually deal with register/pin addresses and memory addresses for jumps, so adding a single line changes everything after it and breaks your jumps. 
That’s why I added a few features to the assembler to make my life easier, namely address markers and constants.
- Address markers allow you to mark instructions and use those marker names within the program to refer to that instruction, which makes conditional stuff, jumps and other stuff much easier.
- Constants are… well, constants. With them I can assign names to memory addresses. (especially useful when you have more than 120 addresses
)
Additionally, I also introduced a dynamic constants thing in the assembler, which basically just reserves memory addresses and stuff for constants on it’s own, so now I don’t even need to think about those addresses.
new ALU stuff
I added a new ALU (Arithmetic & Logic Unit) function in the CPU for comparisons between two numbers.

The new COMP ALU operation compares the two values in ALU_A and ALU_B and sets the output to:
- 1 if A > B
- 2 of A < B
- 0 if A = B
Trying to make a 3D renderer without these functions is impossible 
renderererer
Ok, now onto how the renderer actually works.

The renderer is just one big program (1300+ lines of assembly) that does a bunch of stuff to try and render a spinning cube on the display. Basically all it does is:
-
Initialize the cube vertices -
Make the edge table for the lines of the cube -
Rotate all the points of the cube by a set amount every frame using a lot of scary math - 📽️ Project the new rotated 3D points of the cube into 2D points using even more math
-
Draw all the lines of the cube and refresh the display -
Repeat from step 3
Here’s a very simplified explanation of the entire program:

The initial positions of the points is hardcoded into the code, and there’s also a getVertex function to get the X, Y and Z coordinates for a specific vertex number.

To rotate the points, you need to do some matrix multiplication
on each of the points, with a rotation matrix thingy and magically rotation happens.

I don’t actually know what sin/cos is, they didn’t teach us in school yet
as far as I know it’s something to do with the angles of a right angle triangle or whatever who cares

To find the rotated points, it takes each of the coordinates and multiplies X by cos theta + Z * sin theta, and multiplies Z by -X * sin theta + Z * cos theta, where theta is the value it is being rotated by. Sin and Cos values for values 0-90 degrees are hardcoded into the program because it’s very hard to calculate 

Then the program takes those rotated points, and projects them into 2D points. Those equations are much easier:
Projected X = (X * FocalLength)/(Z+FocalLength)
and similarly,
Projected Y = (Y * FocalLength)/(Z+FocalLength)

Then it draws the lines between the points using a hardcoded edge table and bresenham’s line drawing algorithm. ![]()

It then releases the pixel buffer and gets ready to draw another frame!

And after a lot of debugging, it’s finally finished! 
(The video is at 500 kilohertz btw
)


A colour GPU
Work in progress text renderer terminal thing
Power Management Thing™ so that programs can view and adjust the processors clock speed
It does a lot of math and loop stuff to figure out which color should be at which position. I wrote it in like 80 lines of assembly using the new assembler


(Literally writing with numbers)




(java peak
but I managed to retrieve everything from the recycle bin 