[0.5.4.1] 4-bit computer

#1
Well, wherever there has been a game with some sort of logistical system, there's been someone whose tried to make a computer out of it. Barotrauma already has pre-defined AND, OR and NOT gates so that makes it all the simpler.
Image
So, that's it so far. No, it's not done. I dare say not even close. At the bottom left you can see the oscillator with an external pause and internal stop button, the light-blue circuit is a 4-bit Adder with decoders, the light-green is an 8-bit simplified general-purpose registry, the purple is a serial-to-parallel shift circuit, the dark blue is the beginning of an ALU, and up the top is the RAM. (Only need 4 bytes right now, it's going to go up to 8. Maybe 16, probably not though.)

I am, in case it was not blatantly obvious, not experienced with this by any means. I have *some* experience with complex-ish circuitry, but none with computer-specific circuits.

What it does so far: Runs on a 2-second delay interval for debugging. I've made a simple I/O button that can turn on one bit in the general purpose registry, which then gets sent to the shift memory which atleast looks pretty cool. ALU has 1 finished bit, so I guess you could do 0+1 if you could be bothered to make an I/O for it.

What I want it to do: Well, it'll probably just be a calculator. A big-ass calculator. With it, you could program in instructions such as "CLOSE BRIDGE_DOOR" (actually I think you need an 8-bit computer to do that) or make it like, automatically seal flooded areas or begin charging the evacuation pod once _x_ rooms are flooded. It probably won't do much more than that, if even that. Even if it could support a decent-sized block of light components for hope of displaying 16x16 resolution nudes (it cant) lag would probably catch up to it eventually. (Lag is fine, for now, but it's not doing any maths yet and god knows what stuff like overflows or burn outs might do)

But yeah. I don't know what I'm doing. If anyone would like to point out anything, test it, help with it, or criticize me for spending an hour and a half of my free afternoon on making computers within computer games, do let me know.

EDIT: I made a crummy gif.
Spoiler
Image
Last edited by Esoudiere on Fri Dec 02, 2016 7:28 am, edited 2 times in total.

Re: [0.5.3.4] 4-bit computer

#3
Updated it. The ALU is finished.

These are the opcodes:
00 - OR
01 - AND
10 - NOT
11 - ADD

Down the bottom are two buttons, F0 and F1. Combine those to make one of those opcodes to perform that operation.
Up the top left is the input.

Note that both the input and output are in binary. Meaning the first 2 are considered to be worth '1' when adding, the second 2 are considered to be worth '2', the third two are worth '4', and the fourth two are worth '8'.

To the right, next to the ALU, you have the output. As I said, this is in binary. The computer simply cannot comprehend numbers above 15, (Thats 4 bits including the 0 digit {16 numbers}) and if you try, it'll give you some weird answer and a stack overflow error.

There's also an accumulator next to the first bit of the ALU. It's possible to load a number into that, however there is no way to get it back out yet. So yeah, it has no memory at the moment.

Image
In the picture above, I did the operation 1+1+4, which gives the answer of 0110, otherwise known as 6.

So yeah, if you're curious, I uploaded it to dropbox, so give it a go and if you encounter any mistakes, make sure to tell me about em. If you want to increase the clock speed ('overclocking' heh) find the delay circuit above the blue light in the bottom left corner, and set it to the desired number. It starts at 0.5Hz (half a cycle a second), I'd say don't increase it above 2Hz (2 cycles a second) or the game might start lagging and it's probably going to be unreliable.

EDIT: To start it, launch the submarine and press the button labelled 'clock'. Some things should begin like, flashing. The little purple circuit to the right of the clock button should have some green lights on it, that fade away on the falling edge of each cycle. Once they're all gone, it's 'booted up' (it just needs a moment to change all the registers from a null state to 0)

https://www.dropbox.com/s/qvqiyqnp162arlx/8bit.sub?dl=0

Re: [0.5.4.0] 4-bit computer

#4
Another update. Decided to try to make it 8 bit. That means it also needed another opcode. Whilst 2 opcodes allowed 4 arithmetic operations, 3 opcodes allows 9.

0x0 - ADD (A+B)
0x1 - ADC (A+B+1)
0x2 - SUB (A-B)
0x3 - SBC ((A-B)-1)
0x4 - OR (A || B)
0x5 - AND (A && B)
0x6 - XOR (!(A && B) & (A || B))
0x7 - NOT (!A)

0x8 - STM (Save accumulator to memory)
0x9 - LDM (Load memory into accumulator)
0xA - LDI (Save instructions into accumulator)

8 arithmetic/logic functions. The last 3 are separate to the ALU

NOTE: It now needs constant values in order to function. For the effect of realism, it gets the 0 constant from a water sensor, and the 1 constant (cheated a little and used regex) from an oxygen sensor. So if the room fills up or the oxygen runs out, the computer will be screwy.

Re: [0.5.4.1] 4-bit computer

#6
Okay. Finally got to updating this again. It now has FOUR opcodes (16 combinations) and two pairs of 4 operands (16 combinations each) aswell as a flag bit determining whether the information provided in the operand is a number or a register address. This however makes the instruction word a rather unwieldy number of 14, so I've had to build a seperate register for instructions. (You can only hold 4 instructions at the moment, though)

Obviously with those comes a program counter to cycle through the instructions, a way to program in instructions, and the beginning of making the decoder to start adding the data instructions. (Arithmetic is all done and dusted)

I sharn't bother updating the download or a picture, it's pretty messy and you can't actually do anything with it now, since the input no longer connects straight to the ALU. Next update should be it finished.

Re: [0.5.4.1] 4-bit computer

#7
Despite what I last said, no, it's not finished. Adding in the memory used a crap ton of performance, to the point that my laptop no longer runs it which makes it harder and slower to make it as I have to now use my actual computer, which I only have access to during the weekends (due to living somewhere else on weekdays) But here's a picture.
Image
For any still interested in this, I'll label it:
Top left: Program counter. Connects directly to program memory.
Middle Left: Program memory. Holds 4 programs.
Top Right: Start of data memory.
Mid Left, the little square thing: State decoder. Links to the ALU input MUX's.
To the left of the ALU: ALU input MUX's. Either inputs from memory or directly from the program itself.
The 4 big squares: The ALU. Does all arithmetic operations in the computer.
Bottom left: The inputs to put a program into the memory.

Re: [0.5.4.1] 4-bit computer

#8
Hey,
I highly suggest reading the book "The Elements of Computing Systems"
Available basically for free as the "Nand to Tetris"... course I guess, just google nand to tetris and it should be the first link.
It is a really good read and it explains things really well. You will gain a _FAR_ better understanding of what you are doing after following it.

Also, you don't have 4 opcodes. you have 16 opcodes. An opcode is, as the name suggests, an operation code. It is stored as a 4 bit value.
Better way to explain it is that you have a 4 bit opcode field or something like that I guess?
Not that it really matters, I am mostly just being a pedantic idiot...

Re: [0.5.4.1] 4-bit computer

#9
Zylanx wrote:Hey,
I highly suggest reading the book "The Elements of Computing Systems"
Available basically for free as the "Nand to Tetris"... course I guess, just google nand to tetris and it should be the first link.
It is a really good read and it explains things really well. You will gain a _FAR_ better understanding of what you are doing after following it.

Also, you don't have 4 opcodes. you have 16 opcodes. An opcode is, as the name suggests, an operation code. It is stored as a 4 bit value.
Better way to explain it is that you have a 4 bit opcode field or something like that I guess?
Not that it really matters, I am mostly just being a pedantic idiot...
tbh, copying large-scale schematics = not what I'm going for. I'm a believer of 'ingenuity comes from inexperience,' and by making mistakes I've noted what works and what doesn't, building my own understanding without reading websites or books filled with unnecessary jargon. (Which has led to unconventional, although notably worse, circuitry designs; Exactly my intention.) Even so, thanks for the link, I'll probably check it out one day when I'm inexplicably stuck on a problem, and need further explanation.

Re: [0.5.4.1] 4-bit computer

#10
Edit: What I was meaning to say in this post is "Fair enough. I have lots of respect, keep doing it like you are because it is really interesting to see"
------------------------------
Just like to add that the book isn't about copying large scale designs. I am personally designing another cpu that has nothing to do with the one they use as a working example in the book.
The book is more on the workings of components and the way they interconnect and it would certainly increase your understanding and provide a launching point. And I have a lot of respect for what you have already achieved on your own. It seems pretty good.
More than likely if you read the book, it would just give you a bit more of a deeper/technical understanding of things you already know. Dunno. But yeah, you are doing damn well without it!

Definitely going to download and work out how it works very soon!