Jump to content

A Computer In Your Game


Recommended Posts

It finally happened guys. I told you within the week and i kept the promise. The pre-alpha build for the cpu is here.

arn vortex 16 byte v1.02.sav

Now, i haven't finished the push and pop functions, so no saving to the memory as of yet, but you can play around, maybe write your own code (and most importantly find bugs and report them here :D ).

So, a quick manual so that you know how to work around this lil' beast

First of, enter sandbox and dev mode (backspace and ctrl+F4).

To start the machine , toggle off the power button (if you go to electric grid overlay, the power button is inside the CLK area. Also it's the only switch in the map.)

The machine runs this program (if you dont know assembly, read the explanation below)

MOV NUL, AX

MOV IMM ($01) , BX

ADD AX,BX

MOV IMM ($0A), BX

CMP AX,BX

JLT IMM($01)

JMP IMM ($00)

So, what this program does, is this. It loads 0 to AX and 1 to BX. Adds them and puts the result in AX. Then loads 10 to BX and compares them. If AX is less than BX then go back to the second step and loop (load 1 to BX, add them, compare them etc). If AX is Equal or greater than BX then reset . Essentially the program is a loop that counts to 10 and then resets itself.

And a quick list of the opcodes for the daredevils that want to program it:

Spoiler

 

BIT| 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 |         X = don't care

      | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |        NOP

      | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 |        JMP

      | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0 |        JMC (jump if carry)

      | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 1 |        JNC ( jump if not carry)

      | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 0 |        JLT ( jump less than)

      | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 1 |        JNLT ( jump not less than)

      | 0 | 0 | 0 | 0 | 0 | 1 | 1 | 0 |        JLE (jump less than or equal)

      | 0 | 0 | 0 | 0 | 0 | 1 | 1 | 1 |         JNLE ( jump not less than or equal

      | 0 | 0 | 0 | 0 | 1 | 0 | 0 | 0 |         reserved

      | 0 | 0 | 0 | 0 | 1 | 0 | 0 | 1 |         reserved

      | 0 | 0 | 0 | 0 | 1 | 0 | 1 | 0 |         JE (jump if equal

      | 0 | 0 | 0 | 0 | 1 | 0 | 1 | 1 |         JNE (jump not equal

      | 0 | 0 | 0 | 0 | 1 | 1 | 0 | 0 |         JGT (jump greater than)

      | 0 | 0 | 0 | 0 | 1 | 1 | 0 | 1 |         JNGT (jump not greater than)

 

      | 0 | 0 | 0 | 0 | 1 | 1 | 1 | 0 |         JGE (jump greater than or equal)

      | 0 | 0 | 0 | 0 | 1 | 1 | 1 | 1 |         JNGE (jump not greater than or equal)

MOV| 0 | 1 | S | S | S | D | D | D |         MOVE's

the 3 bit for source and destination, are as follows

0 0 0 = NULL (no register)

0 0 1 = Sigma (a register that always holds the result of the last arithmetic function processed)

0 1 0 = AX

0 1 1 = BX

1 0 0 = IMM (immediate). Immediate is represented as the next memory location in the memory

1 0 1 = reserved

1 1 0 = PC (program counter)

1 1 1 = SP (stack pointer)

 

ALU|  1 | Y | Y | Y | Y | wrA/B| pnA | pnB

YYYY:

000X = NOT

001X = OR

010X = AND

011X = XOR

1000 = SHL

1001 = SHR

1010 = ROL

1011 = ROR

110X = ADD

111X = CMP

There is a small programmer for the RAM to the left most side. To start programming the ram, disconnect it from the cpu, or at least disconnect the address bus.

Manually set the adress, then connect the not gate to the right to the bus coming from above it., then, to the right, set the bits from highest to lowest and connect them to the two data busses . Then first disconnect the not gate, leave an automation tick to pass and then disconnect the to data lines..

 

That's it, have fun. A more in depth tutorial will be coming with the next update

 

Link to comment
Share on other sites

Excellent work.
I don't understand the core of it at all, but I played with it a bit, looking at the bits of information stored in the 16 bytes of RAM and the opcode in the quicklist.
There were two things that looked like bugs.

First, there is a misconfiguration in some of the ribbon readers that make up the RAM referenced by RAM address "1110".
1.thumb.jpg.dd72d99a2f5b0dafcb33f342d1c17a14.jpg

 

Second, there appears to be no difference between code JLT and code JLE.

8 hours ago, Arnadath said:

MOV NUL, AX

MOV IMM ($01) , BX

ADD AX,BX

MOV IMM ($0A), BX

CMP AX,BX

JLT IMM($01)

JMP IMM ($00)

I think the program code for the 6th step with JLT is in RAM addresses "0111" and "1000", but the inside view of RAM address "0111" is "00000110".
In the quick list, "00000110" is JLE, not JLT.
I don't know if it's simply a mistake in the quicklist or in the contents of the RAM, but for now I rewrote the contents of RAM address "0111" to "00000100 (JLT?)" and tried to run it.
During execution, I kept an eye on the memory toggles that make up the AX registers, but both JLT? and JLE? counted up to 10. So there seems to be no difference.
If it is JLE, then the AX register should count up to 11, so I think something is bugged.

Note that my knowledge of assembly is almost entirely based on information I got from a game called "SHENZHEN I/O", so what I'm saying may be completely misguided. I'm sorry if I'm wrong.

Link to comment
Share on other sites

4 hours ago, kbn said:

Excellent work.
I don't understand the core of it at all, but I played with it a bit, looking at the bits of information stored in the 16 bytes of RAM and the opcode in the quicklist.
There were two things that looked like bugs.

First, there is a misconfiguration in some of the ribbon readers that make up the RAM referenced by RAM address "1110".
1.thumb.jpg.dd72d99a2f5b0dafcb33f342d1c17a14.jpg

 

Second, there appears to be no difference between code JLT and code JLE.

I think the program code for the 6th step with JLT is in RAM addresses "0111" and "1000", but the inside view of RAM address "0111" is "00000110".
In the quick list, "00000110" is JLE, not JLT.
I don't know if it's simply a mistake in the quicklist or in the contents of the RAM, but for now I rewrote the contents of RAM address "0111" to "00000100 (JLT?)" and tried to run it.
During execution, I kept an eye on the memory toggles that make up the AX registers, but both JLT? and JLE? counted up to 10. So there seems to be no difference.
If it is JLE, then the AX register should count up to 11, so I think something is bugged.

Note that my knowledge of assembly is almost entirely based on information I got from a game called "SHENZHEN I/O", so what I'm saying may be completely misguided. I'm sorry if I'm wrong.

Really nice catch. I suspect that either i have swapped the equality and zero flags, or they didn't have enough time to settle after a CMP.

Link to comment
Share on other sites

That is a very respectable accomplishment, even with a few bugs (the ones I saw were already mentioned above)!

I kept seeing black holes though, I was wondering if you have experienced that too? I cut the setup down to 16 bytes memory and obviously the game was running faster at high speed then, but still some black holes even while I paused to make lunch. I'll start the process of disabling mods and look at the logs, because a) I am curious, and b) I want to play more with your CPU :)

Again, marvelous work here. Thanks for sharing this with us!

Link to comment
Share on other sites

8 minutes ago, molsen234 said:

That is a very respectable accomplishment, even with a few bugs (the ones I saw were already mentioned above)!

I kept seeing black holes though, I was wondering if you have experienced that too? I cut the setup down to 16 bytes memory and obviously the game was running faster at high speed then, but still some black holes even while I paused to make lunch. I'll start the process of disabling mods and look at the logs, because a) I am curious, and b) I want to play more with your CPU :)

Again, marvelous work here. Thanks for sharing this with us!

Thanks for your words of encouragement, and a happy new year as well. 

Indeed i get a lot of black holes, and i have no mods installed at all. My computer is a 6 year old coal burner with emphysima and severe alzheimer's, so i kinda hoped it would run smoother in better computers. Dunno what to tell you other than save often.

Link to comment
Share on other sites

1 hour ago, Arnadath said:

Thanks for your words of encouragement, and a happy new year as well. 

Indeed i get a lot of black holes, and i have no mods installed at all. My computer is a 6 year old coal burner with emphysima and severe alzheimer's, so i kinda hoped it would run smoother in better computers. Dunno what to tell you other than save often.

Well I disabled my whole heap of mods, and it has been running stable since my last post. So there is that :)

I installed the Lights Out mod yesterday while I was talking to someone about a mod suggestion, and had forgotten about it. That mod potentially does some heavy duty texture updates to the whole map. In combination with me running your save file with the automation overlay on (which I think uses the same mechanisms), I think that might have been the cause of my crashes. I didn't get a crash log, so can't tell for sure, but no crashes now.

Thanks for taking time to reply above, and best wishes for the new year!

Edit: I am back to running the full 32 bytes setup by the way.

Link to comment
Share on other sites

48 minutes ago, molsen234 said:

Well I disabled my whole heap of mods, and it has been running stable since my last post. So there is that :)

I installed the Lights Out mod yesterday while I was talking to someone about a mod suggestion, and had forgotten about it. That mod potentially does some heavy duty texture updates to the whole map. In combination with me running your save file with the automation overlay on (which I think uses the same mechanisms), I think that might have been the cause of my crashes. I didn't get a crash log, so can't tell for sure, but no crashes now.

Thanks for taking time to reply above, and best wishes for the new year!

Edit: I am back to running the full 32 bytes setup by the way.

Nice, that's encouraging. Hopefully i'll get a new pc some time in the future with more ram and i'll start programming a pong game.

Link to comment
Share on other sites

I am programming a Fibonacci sequence right now :D

I was playing with adding a programming interface, but there isn't much room to get around so I just follow your instructions for now. Also, I see you were using NOT gates for the programming, is there a reason for not using regular switches? It would look great with a toggle interface like on the PDP-8 :glee:

I just had a crash, again while paused and writing the above comment. Seems to be LogicRibbonReader.UpdateVisuals() that causes it. Anyway, not due to your design for sure! :)

Edit: Yes, I found it. It allocates a max of 256 animation handles, when it runs out it causes this crash. Strange that it is allocating animations when paused. Those animations will not play, so that will naturally pile up. I think I'll file a bug report later today or tomorrow.

Link to comment
Share on other sites

59 minutes ago, molsen234 said:

I am programming a Fibonacci sequence right now :D

I was playing with adding a programming interface, but there isn't much room to get around so I just follow your instructions for now. Also, I see you were using NOT gates for the programming, is there a reason for not using regular switches? It would look great with a toggle interface like on the PDP-8 :glee:

I just had a crash, again while paused and writing the above comment. Seems to be LogicRibbonReader.UpdateVisuals() that causes it. Anyway, not due to your design for sure! :)

Edit: Yes, I found it. It allocates a max of 256 animation handles, when it runs out it causes this crash. Strange that it is allocating animations when paused. Those animations will not play, so that will naturally pile up. I think I'll file a bug report later today or tomorrow.

The idea was that  bootloader would insert the program contents in memory. Iwas planning to make this using a liquid reservoir and element sensors to encode binary information. 

Also automation updates when the game is paused. That's acctually useful for us. Try for eample placing an automation ribbon over another ribbon while paused. Every time you click, it updates the automation, and you can use it to time things and calculate timing.

32 minutes ago, molsen234 said:

Edit2: IMPORTANT - It just occurred to me that I need to ask your permission to submit your save file if I log a bug report.

Of course you can. I love that what i made sparks creativity. Actually i should post an update, because i solved the issue with the flags and also i need to connect the  bitshifting gizmo. Expect that later today

Link to comment
Share on other sites

Thanks for the insights on the animation of automation! I'll wait with further programming until I see the update then!

My fibonacci code in case you are interested:

L0: MOV IMM ($01), AX
MOVE IMM ($01), BX
L1: ADD AX,BX
ADD BX,AX
JNC L1
JMP L0

The next number will be in alternating AX and BX, or every time in sigma of course if all goes well :)

Link to comment
Share on other sites

7 hours ago, molsen234 said:

Thanks for the insights on the animation of automation! I'll wait with further programming until I see the update then!

My fibonacci code in case you are interested:

L0: MOV IMM ($01), AX
MOVE IMM ($01), BX
L1: ADD AX,BX
ADD BX,AX
JNC L1
JMP L0

The next number will be in alternating AX and BX, or every time in sigma of course if all goes well :)

Well, here's the update. Also programmed your code in it. Well almost... Instead of JNC L1, it just jumps to L1 anyway. Also it mov's 0 to AX in the beggining.  I'll leave the rest up to you my devoted choosen xD

arn vortex 16 byte v1.04.sav

Link to comment
Share on other sites

I would imagine that relative addressing would not be that hard to do. You could use 101 as signifying relative addressing, then the next memory location would be the constant offset if the topmost bit is 0. If the topmost bit is 1, then the address would be AX+offset instead of PC+offset.

Link to comment
Share on other sites

8 hours ago, he77789 said:

I would imagine that relative addressing would not be that hard to do. You could use 101 as signifying relative addressing, then the next memory location would be the constant offset if the topmost bit is 0. If the topmost bit is 1, then the address would be AX+offset instead of PC+offset.

You can already do that, You can mov pc to bx, add ax and mov it back to pc. Thing is, it isn't one instruction, but rather three.

Link to comment
Share on other sites

I am still having fun with the CPU, today it has not crashed yet, as I try to not pause the game. That seems to help.

There is a burning question though: Are you planning on adding memory write to the MOV instruction, or perhaps a STA / STB instruction (might be more intuitive)? It would be a great next step :)

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

Please be aware that the content of this thread may be outdated and no longer applicable.

×
  • Create New...