Dual Photon Computer

  • resicuts
    13th August Member 1 Permalink

    This thread discusses the save

     

    It's a computer for calculating simple programs like incrementing or adding numbers.

     

     

    Structure


    The computer has a RAM (64 filt) and 2 operational variables. When the computer makes a binary operation (and, xor etc.), the 2 operational variables are compared (example: xored). The result is saved in a predefined RAM pixel.

     

     

    Programming


    Programming device:


    To program it, you have to specify 2 things:

    1. Operation (what you want to do)

    2. Address (from where to take the value/where you want to save the result)

     

    Quick Tutorial (Example program: AND):

     

    1. First you have to copy the first value from your RAM into var1. To do that, push set var1 and set the address to 000000 (already set at start. Switch the switches with pscn/nscn. 0 means off, 1 means on). Because computers start counting at 0, you take the value from RAM 0, the first variable of the RAM.

     

    2. Copy the value at 000001 (second variable) to var2.

     

    3. Now we are ready to perform the calculation. Push the AND button and set the address to 000010 (RAM 2/third variable). The computer calculates the AND value of the two variables (explanation of bitwise operations: here) and saves the result at 000010.

     

    4. To display the result on the 7-Segment-Display, push out var and set the address to 000010 (RAM 2).

     

    5. Just push the Program end button and do what the device tells you to do.

     

    6. When you see the program ready sign light up, ctrl+c the photons. Then switch to the computer and paste them left from the sign copy/paste the photons in here. Then select the PROP tool, set it to ctype and type one+Enter, click on the first filt pixel (from the right) of the RAM. Do the same thing to the next pixel but set it to 3.

     

    7. Push the start button. If you did the steps before correctly, the 7-Segment-Display should show a 1.

     

    If you have a problem, you can start a conversation with me.

     

     

    Lua compiler

     

    I also have written a lua compiler for this computer (and probably for the next too). You can download it here. When you finished downloading, you should place the file in the TPT folder. Then open it and write the file name (explanation on how to write a program in the next paragraph) you want to compile in the second line (marked). After, start TPT and open the programming device, then run dofile("compiler file name"), do NOT push Program end, delete not used filt and push Ready (not lighted), then do everything from step 6 in the instructions up there.

     

     

    Programming Syntax

     

    Right now there is pretty much nothing new. You first write the operation and then the address (in decimal) separated by a space. For the next operation start a new line. When you write a bitwise operation (all: and, or, xor, not), you should append an op before it (opAnd, opOr).

     

    Other operations: subColor, rShift, lShift, random, setVar1, setVar2, outputVar, outputSignal.

     

    rShift and lShift are actually variable shifts because the compiler doesn't support just shifting by one bit. It's not important if you write it in UPPERCASE or lowercase, like you can write "oPanD" and the compiler will just compile it normally, but that doesn't look clean and is harder to read so better just write in lowercase. Also, you have to write an address to each operation even if it doesn't need it, the computer will just ignore it when calculating, otherwise the compiler won't compile.

     

    You don't need anything else to write a program than the compiler. Just create a .txt file with a name you like in the same folder as the compiler (!important!) and write the program in it WITH a "NULL 0" at the end.

     

     

    Mass Photon Storage


    The Mass Photon Storage (MPS) is a memory for saving lots of data in one pixel. In this computer it is used for saving the program. The main problem is, that it can only read the data for one time (many programs reuse the same code for multiple times so this is a really big disadvantage). This makes loops and other operarations that need to reuse code impossible on this computer.

     

    I originally wanted to implement a Dual Photon Memory (hence the name of the computer. DPM, the same thing but doesn't delete the data), but I just understood that it doesn't make really much sense: The DPM needs much time to access data far from the pointer what stops the computer from doing anything in this time. Also "scrolling" trough the data requires a lot of complex electronics. This makes a filt memory a better choice because it always needs the same time to access any data, despite the space it needs. The next computer I'm already planning would have a normal filt memory what would allow making loops and functions, the base of programming.

     

    P.S: While writing this I already have an idea on how to make the DPM faster so maybe the next computer will still use one.

     

    Technical Data


    The computer has no registers or cache because the speed of the filt memory is independent from the size (the main reason for building in registers in computers irl).

    It only has a RAM with 64 filts.

    For each task, the computer needs exactly 8 frames. Therefore, when running TPT at 60 fps, the processor has a speed of 7.5 Hertz, so it can process 7.5 tasks a second. In comparison to real computers, this is literaly nothing, but in comparison to other TPT computers, it's still nothing.

     

     

    Program codes

     

    When you program something on the programming device, it translates your pushes on the buttons into machine code. Here are all the codes for each operation and address. This is only for people that want to upgrade or understand the computer or are just interested.

     

    The first 5 bits (from the right) define the operation:

    and

    00001

    or

    00010

    xor

    00011

    not

    00100

    sub Color

    00101

    RShift

    00110

    BShift

    00111

    VRShift

    01000

    VBShift

    01001

    random

    01010

    [Empty]

    01011

    set var1

    01100

    set var2

    01101

    output var

    01110

    output signal

    01111

    Program end

    11111

     

     

    The next 6 bits define the address in the RAM. Example:

    000000 = first variable

    000010 = third variable

    Edited 23 times by resicuts. Last: 8th September
  • Jerehmia
    15th August Member 1 Permalink

    Nice, the RShift and BShift instructions won't be very useful tho because by how many bits the data is shifted is determined by the temperature of the FILT that does the shifting.

     

    If you want to add relatively simple but slow Add and Subtract instructions here's a thread that shows how to build them: Serial addition. I also implemented the serial multiplicator mentioned at the end but I can't find the relevant thread so I'll post the save itself:

  • resicuts
    15th August Member 0 Permalink

    @Jerehmia (View Post)

     Ok, thank you. Didn't know RShift/BShift is dependent on temperature. I should maybe delete them. I added them because I thought shifting a number by one bit is pretty useful but I never used it myself.

     

    Also, I want to add a fast adder/subtractor because of how common these instructions are but I don't know how to make one yet, and the speed of this algorithm is fast enough for a start so thank you.

     

    I also plan building another computer because I learned a lot from this project and adding all the upgrades I want to add would mean rebuilding the whole computer, so why don't make another one?

  • 12034056
    15th August Member 1 Permalink

    'Old QRTZ scattering' isn't completely random, it seems to just return 1st, 9th and 17th bits that are sometimes shifted left 1 bit or removed and fills left part after random one of them, so it probably shouldn't be used as random.

  • resicuts
    15th August Member 0 Permalink

    @12034056 (View Post)

     I have noticed there is some pattern too but wasn't really interested so just marked it as "random". The next computer will still have this function but will calculate it otherwise. Thank you. I'll research on that further.

     

     

    Edit:

     So, I searched in the source code of TPT and found this:

     

                int t1 = (origWl & 0x0000FF) + sim->rng.between(-2, 2);
                int t2 = ((origWl & 0x00FF00)>>8) + sim->rng.between(-2, 2);
                int t3 = ((origWl & 0xFF0000)>>16) + sim->rng.between(-2, 2);
                return (origWl & 0xFF000000) | (t3<<16) | (t2<<8) | t1;

     

    It has some randomness but it's not fully random. origWl is the original Wavelenght (value originally stored in the bray/phot). So it's not assigning a fully random number to the bray but calculating it from the original wavelenght with random numbers. So the origWl still plays a role. I hope you can understand at least some c++.

    Edited 2 times by resicuts. Last: 16th August
  • Jerehmia
    16th August Member 1 Permalink

    @resicuts (View Post)

     It's possible to create 1-frame adders but they're rather costly in terms of space if you don't use aggressive particle stacking, and you have to take advantage of the game's particle update order.

     

    Here is an example of a 1-frame adder for demonstration purposes that doesn't use stacking:

  • 12034056
    16th August Member 0 Permalink

    I checked all 1073741824 possible combinations and found that original wavelength of 393344 results in most "average" distribution (most bits have ~ 50% chance to be 1) and original wavelength of 263172 results in least "average" distribution (most bits are 0). Here is a save that shows both of them:

     

    Edit 2: Previous values are wrong, here are the right ones:

    Most "average": 32639 (all bits have ~ 50% chance to be 1)

    Least "average": 131589 (most bits are 0 or have higher chance of being 0 or 1)

     

    'Most average distribution' value is still not completely random, but gives much better random than default value of 0x1F or 1, so if you will continue using 'Old QRTZ scattering' as random I recommend using this value instead.

    Additionally, you can add a XOR gate after it with some random number like 0x1942972E to make output even more random.

    Edited 4 times by 12034056. Last: 16th August
  • resicuts
    17th August Member 0 Permalink

    @12034056 (View Post)

     Ok, thanks. I will implement that in the next computer.

     

    @Jerehmia (View Post)

     Thank you. I'll research on that one then.