We learned a lot about the basics of computers from the Ben Eater 8 bit CPU playlist:
Bad Apple!:

What it does

Plays "Bad Apple" on a 16x16 LED matrix

Basic Specs:
8 bit data width
16 bit memory addresses
32k RAM and 32k ROM (However we modified our computer to fit 5 64k ROMS in order to fit all of the video data)
8 bit Bitshifter and Comparator
16x16 LED matrix

The CPU has 16 OPCODES:

0000 - NOP - No operation
0001 - LDA - Load value from ROM into the A register
0010 - STA - Store value in A register to adress in RAM
0011 - LRA - Load value from RAM into the A register
0100 - LDB - Load value from A register into B register
0101 - MTX - Ouput 16 bit row data to LED Matrix  
0110 - BST - Shift value in A register by value in B register and store result into A
0111 - ADD - Add value in A regsister to value in B register and store sum into A
1000 - SUB - Subtract value in A register from value in B register and store difference into A
1001 - JMP - Jump to specified address
1010 - GJM - Jump to specified address if A > B
1011 - LJM - Jump to specified address if A < B
1100 - ZJM - Jump to specified address if 0 flag
1101 - OJM - Jump to specified address if overflow
1110 - OUT - Output value from A register to output register
1111 - HLT - Halt clock

How we built it

We used the logic simulator Digital:
The ROMS were programmed with a python script we made.
We took the original "Bad Apple!" video and reduced it to 16x16, then made a python script that turns the images into simple ones and zeros, and then formatted that data into bytecode that our 8 bit computer could read.

Challenges we ran into

At first the matrix would not sync perfectly with the data being sent to it, and a horizontal line could be seen moving through the matrix. This line made the video very choppy and irritable to watch. We solved this problem by using a de multiplexer instead of a decoder to control the matrix registers so that everything would be timed correctly.
Another challenge was fitting the entirety of "Bad Apple!" into the computer's memory. Initially the memory was split between 32k RAM and 32k ROM (Out of the 64k of memory, the upper half would be reserved for RAM and the lower half for ROM) but 32k ROM was not nearly enough for our demands. We calculated that if each frame took up 48 bytes, we would need at least 336000 bytes (336k) of ROM. However if we made our ROM chip bigger, we cannot actually address those slots of memory due to the fact that we could only address 16 bits. To solve this problem, we decided to break up the entire video into separate ROMS and switch between them. Every time the program counter resets, it enables a counter to index by 1 to enable the next ROM chip.

Accomplishments that we're proud of

We were able to build our very own CPU architecture successfully within the span of 2 days and create a cool program to run on it.   

What we learned

How basic displays work
How to write a compiler to take in data and format it in a way so that our computer could read it.
How to work with video/image data and format it.

What's next for Making a Computer to play "Bad Apple!"

We aim to play "Bad Apple!" in 32x32 in the future
Expand on the CPU to make it more powerful/efficient
Full color display
Build this in real life? 

Built With

Share this project: