Minecraft Redstone Project

Associate
Joined
1 Sep 2012
Posts
436
Location
Lancashire
I have challenged myself and a friend to build a CPU based on a PIC microcontroller in minecraft :O
This should end up being a bit more of a challenge than anything I have built before and as my friend has a slight idea about the electronics behind it I will hopefully be able to teach him about it during the build.
To help me along the way I will be using Feed The Beast Tech World with all core and jar mods enabled with redpower to reduce and simplify the circuitry.

modsx.png

Using the instruction set for the PIC16F627 I have come up with this list for planning. Each function is something that the CPU will do.
All functions work in binary which is a way of expressing numbers in terms of "1's and 0's" or "on and off"
Look at truth tables on wiki for the functions below if you have no idea what I'm talking about.

1. ADD - just the regular meaning (but in binary) 1+1=10 :)
2. AND - only when the two bits are 1 the output becomes one.
3.CLEAR (Registers and bits) - sets certain bits or a whole byte to 0.
4.DECREMENT (skip if 0) - takes 1 from the 1st register
5.INCREMENT (skip if 0) - adds 1 to the first register
6.OR - if one, the other or both inputs are 1 then the output will be 1
7.MOVE - takes data from one location and dumps it elsewhere
8.NO OPERATION - does nowt
9.ROTATE LEFT - shifts all the bits to the left (effectively multiplies by 2)
10.ROTATE RIGHT - shifts all the bits to the right (effectively divides by 2)
11.SUBTRACT - 101-1= 100 regular meaning
12.SWAP NIBBLES - A nibble is half a byte. swapping them, guess what, swaps them around.
13.EXOR - Same as or but when both inputs are 1 then the output is 0
14.(BIT TEST FILE(skip if 0/1)) - tests a bit, if it is a 1(or 0, depending on which one is used) then it skips the next operation
15.(CALL) - calls a subroutine. probably won't use subroutines
16.(CLEAR WDT) - have no idea why this is on here. WDT(watch dog timer) makes the program start again if it hasn't been reset within a certain time period. (useless)
17.(GOTO) - Goes to a certain line of the ROM
18.(RETURN FROM INTERUPT(with value)) - interrupts will probably not be included so this is pointless
19.(sleep) - Puts the cpu into a low power state. I will probably just stop the clock with an and gate
20.COMPLEMENT - makes the 1's into 0's and makes the 0's into 1's

2 input registers with display - data will show up on a display when a clock pulse is present.
1 output register with display - the answer will show up on the display (register not needed anymore)
Zero flag reg (1 bit) - when the answer is 0 then this flag will be 1
Carry flag reg (1 bit) - when the answer is too large to fit onto the screen this flag will be 1
Digit carry flag (1 bit) - when the lower nibble is all 1 then this flag will be 1
Temporary registers (ram) x16 - just somewhere to store data
5 bit mux - selects between 2^5 (32) inputs to get one output that will then be the answer

instructionset1.png

instructionset2.png

instructionset3.png

The CPU will be 8 bit to start with and by using wireless redstone I will be able to expand this easily to 16 bit or possibly 32 bit in the future.

I will try to keep this up to date as much as possible when I make progress with this project


How a CPU works.

A CPU is essentially a programmable ALU with some cache/RAM/register whatever you want to call it.
For the purpose of this project I will refer to them as registers.
So, an ALU (arithmetic logic unit) takes two inputs and performs arithmetic or logical functions on the two input pieces of data and outputs them.
The functions of this ALU are shown on the instruction list posted above.
The ALU requires a multiplexer or mux for short.
The mux takes one input and directs it to 1 of many outputs or in my case takes multiple inputs and chooses one for the output.
I would have preferred the first but redpower doesn't have this. So it may lag more than is necessary.
The mux will allow the multiple functions that the ALU performs to be selected individually by a binary number meaning it is easy to be programmed when I implement it.
The registers are where data is temporarily stored. These are made out of d-type flip flops which work by outputting what is a there input only when a clock pulse is sent.
The Program Counter (PC) is what tells the CPU which line of the ROM it is upto.
The ROM (Read Only Memory) is where the program is written.
On each line of the ROM there is a function and sometimes a number depending on which function is selected.
The ALU then calculates the answer from the function and the two input registers.
The first register is always the main one which is used when single register functions are used and it will be refered to as "A". So a subtract function would be "A-B"
The status registers are what tells you when the result is either "0"(zero), too big to fit into the output (carry) and when the first 4 bits are all "1" (digit carry).
These flags or status' can then be used to determine whether a number is negative or to determine the real value of a number that doesn't fit onto the answer or other things.
 
Last edited:
Just finished the 3, 8 bit, registers That I started yesterday.
Each bit in each register is stored using a d-type flip flop which only outputs/updates its data when the clock pulse is present.
These are made out of 4 NAND gates as you can see in the images.
Each register requires 32 NAND gates and a lot of wiring. Upgrading this to 16 bit is not difficult, it would just require double the amount of time xD

Blue-Input 1 Green-Input 2 White-Output
registerclose.png

registerwc.png
 
Last edited:
Mux selector finished. New register built for it.
Realized I didn't need the output register so that has been deactivated for now.
It can be used for RAM in the future.

muxselect1.png

muxselect2.png

muxregister.png
 
Found a piece of software on my computer that illustrates what I am trying to acheive

virtualpic.png

The working register is just a register in my project.
The ALU is yet to be made.
The Mux is done
The status flags will be made when the alu is done
The rest doesn't need to be considered yet. This will be done when I know that the ALU works.
 
I suppose just using the redpower computer would be far too simple :p

Seriously though, thats really great work. I wouldn't know where to start if you asked me to do that. imagine what the footprint would be if you used pre 1.5 vanilla redstone though :eek:
 
Thanks :) Redpower computer would be the easier way. But I want to test my understanding of electronics to build this :)
Without redpower I assume it would be 10-15 times larger due to not having or built gates, not having different coloured wire that has a long range, not being able to build directly adjacent to each of the circuits and finally no wireless redstone.
I think wireless redstone is going to be a problem though. With only 5000 channels to use I think I will exceed this so I may have to implement a bus somewhere or many :(
 
Work on the ALU has started :) The AND function has been finished and tied into the mux input of "00010" It works too :) It was easy enough :P

AND gate
andp.png

Hooked into MUX
andonmux.png

Working :)
andworking.png
 
Adder finished. Need to include the 3 status registers on the wall as it won't register the carry on a number larger than 255
b"10000000"+b"10000000"=b"00000000"+"1"in the carry

One adder
addfinished.png

Hooked onto MUX
addonmux.png

Working :) (from bottom working up(11+21=32)
addworking.png
 
Back
Top Bottom