Example #1
0
        public void CanLoadMemoryValueIntoDRegister()
        {
            var analyzer = new WooComputer.Chips.CPU16Bit.CPUAnalyzer();
            var cpu = new WooComputer.Chips.CPU16Bit(analyzer);
            var memory = new WooComputer.Chips.Memory(16);

            //1111110000010000
            //c instruction
            //a = 1
            // c = 110000 = compute M = get the value of M which is the memory that was just sent in?
            // c = 010 = destination is d = put the value that you computer into the d register
            // j = 000 =  no jump
            var output = cpu.Cycle(Functions.GetBitArrayFromInteger(5, 16), Functions.GetBitArrayFromInteger(64528, 16), false);
            Functions.CompareBitArray(analyzer.GetDContents(), Functions.GetBitArrayFromInteger(5, 16));
        }
Example #2
0
        public bool[] CycleInstructions(WooComputer.Chips.Memory memory, List<string> instructions)
        {
            var analyzer = new WooComputer.Chips.CPU16Bit.CPUAnalyzer();
            var cpu = new WooComputer.Chips.CPU16Bit(analyzer);

            Tuple<bool[],bool,bool[],bool[]> output = null;
            bool[] memoryValue = new bool[16];
            for (int i = 0; i < instructions.Count; i++) {
                if (output != null)
                    memoryValue = memory.Cycle(output.Item1, output.Item2, output.Item3);
                output = cpu.Cycle(memoryValue, Functions.GetBitArrayFromString(instructions[i]), false);
            }
            //is this necessary?
            memoryValue = memory.Cycle(output.Item1, output.Item2, output.Item3);
            return memoryValue;
        }
Example #3
0
            public void CanAccumulateTo100()
            {
                var analyzer = new WooComputer.Chips.CPU16Bit.CPUAnalyzer();
                var cpu = new WooComputer.Chips.CPU16Bit(analyzer);
                var memory = new WooComputer.Chips.Memory(16);

                //set A = memory location 0
                var output = cpu.Cycle(Functions.GetBitArrayFromInteger(0, 16), Functions.GetBitArrayFromInteger(0, 16), false);
                Functions.CompareBitArray(analyzer.GetAContents(), Functions.GetBitArrayFromInteger(0, 16));

                // set M = 1
                //1110111111001000
                output = cpu.Cycle(memory.Cycle(output.Item1, output.Item2, output.Item3), Functions.GetBitArrayFromInteger(61384, 16), false);
                Functions.CompareBitArray(analyzer.GetAContents(), Functions.GetBitArrayFromInteger(0, 16));
                Functions.CompareBitArray(output.Item1, Functions.GetBitArrayFromInteger(1, 16));
                Assert.IsTrue(output.Item2);

                //set D = M + 1
                //1111110111010000
                //the aluout should be 2 here
                output = cpu.Cycle(memory.Cycle(output.Item1, output.Item2, output.Item3), Functions.GetBitArrayFromInteger(64976, 16), false);
                //memory in 0 spot should now be 1
                Functions.CompareBitArray(memory.Cycle(new bool[16], false, Functions.GetBitArrayFromInteger(0, 16)), Functions.GetBitArrayFromInteger(1, 16));
                Functions.CompareBitArray(analyzer.GetDContents(), Functions.GetBitArrayFromInteger(2, 16));
                Functions.CompareBitArray(analyzer.GetAContents(), Functions.GetBitArrayFromInteger(0, 16));

                //set D = D + 1
                //1110011111010000
                for (int i = 3; i < 100; i++)
                {
                    output = cpu.Cycle(memory.Cycle(output.Item1, output.Item2, output.Item3), Functions.GetBitArrayFromInteger(59344, 16), false);
                    Assert.IsFalse(output.Item2);
                    Functions.CompareBitArray(output.Item1, Functions.GetBitArrayFromInteger(i, 16));
                    Functions.CompareBitArray(analyzer.GetDContents(), Functions.GetBitArrayFromInteger(i, 16));

                }
            }
Example #4
0
        public void CanLoadValueIntoMemoryLocation()
        {
            var analyzer = new WooComputer.Chips.CPU16Bit.CPUAnalyzer();
            var cpu = new WooComputer.Chips.CPU16Bit(analyzer);
            var memory = new WooComputer.Chips.Memory(16);

            //set A = memory location 0
            var output = cpu.Cycle(Functions.GetBitArrayFromInteger(0, 16), Functions.GetBitArrayFromInteger(0, 16), false);
            Functions.CompareBitArray(analyzer.GetAContents(), Functions.GetBitArrayFromInteger(0, 16));

            // set M = 1
            //1110111111001000
            output = cpu.Cycle(memory.Cycle(output.Item1, output.Item2, output.Item3), Functions.GetBitArrayFromInteger(61384, 16), false);
            Functions.CompareBitArray(analyzer.GetAContents(), Functions.GetBitArrayFromInteger(0, 16));
            Functions.CompareBitArray(output.Item1, Functions.GetBitArrayFromInteger(1, 16));

            //set D = M + 1
            //1111110111010000
               //the aluout should be 2 here
            output = cpu.Cycle(memory.Cycle(output.Item1, output.Item2, output.Item3), Functions.GetBitArrayFromInteger(64976, 16), false);
            //memory in 0 spot should now be one
            Functions.CompareBitArray(memory.Cycle(new bool[16],false, Functions.GetBitArrayFromInteger(0, 16)), Functions.GetBitArrayFromInteger(1, 16));
            Functions.CompareBitArray(analyzer.GetDContents(), Functions.GetBitArrayFromInteger(2, 16));
            Functions.CompareBitArray(analyzer.GetAContents(), Functions.GetBitArrayFromInteger(0, 16));

            //0000000000000001  -  set A register to 1
            output = cpu.Cycle(memory.Cycle(output.Item1, output.Item2, output.Item3), Functions.GetBitArrayFromInteger(1, 16), false);
            Functions.CompareBitArray(analyzer.GetAContents(), Functions.GetBitArrayFromInteger(1, 16));

            // 1110001100001000  - M=D put whatever is in D into memory which is pointing to address 2
            output = cpu.Cycle(memory.Cycle(output.Item1, output.Item2, output.Item3), Functions.GetBitArrayFromInteger(58120, 16), false);
            Functions.CompareBitArray(analyzer.GetAContents(), Functions.GetBitArrayFromInteger(1, 16));

            var finalmemory = memory.Cycle(output.Item1, output.Item2, output.Item3);
            Functions.CompareBitArray(finalmemory, Functions.GetBitArrayFromInteger(2, 16));
        }
Example #5
0
        public void CanLoadARegister()
        {
            var analyzer = new WooComputer.Chips.CPU16Bit.CPUAnalyzer();
            var cpu = new WooComputer.Chips.CPU16Bit(analyzer);
            var memory = new WooComputer.Chips.Memory(16);
            //0000000011111111
            var ouput = cpu.Cycle(new bool[16], Functions.GetBitArrayFromInteger(255, 16), false);
            Functions.CompareBitArray(analyzer.GetAContents(), Functions.GetBitArrayFromInteger(255, 16));

            ouput = cpu.Cycle(new bool[16], Functions.GetBitArrayFromInteger(21, 16), false);
            Functions.CompareBitArray(analyzer.GetAContents(), Functions.GetBitArrayFromInteger(21, 16));

            ouput = cpu.Cycle(new bool[16], Functions.GetBitArrayFromInteger(1023, 16), false);
            Functions.CompareBitArray(analyzer.GetAContents(), Functions.GetBitArrayFromInteger(1023, 16));

            ouput = cpu.Cycle(new bool[16], Functions.GetBitArrayFromInteger(682, 16), false);
            Functions.CompareBitArray(analyzer.GetAContents(), Functions.GetBitArrayFromInteger(682, 16));

            ouput = cpu.Cycle(new bool[16], Functions.GetBitArrayFromInteger(767, 16), false);
            Functions.CompareBitArray(analyzer.GetAContents(), Functions.GetBitArrayFromInteger(767, 16));

            ouput = cpu.Cycle(new bool[16], Functions.GetBitArrayFromInteger(353, 16), false);
            Functions.CompareBitArray(analyzer.GetAContents(), Functions.GetBitArrayFromInteger(353, 16));
        }
Example #6
0
        public void CanJumpLessThanZero()
        {
            var analyzer = new WooComputer.Chips.CPU16Bit.CPUAnalyzer();
            var cpu = new WooComputer.Chips.CPU16Bit(analyzer);
            var memory = new WooComputer.Chips.Memory(16);

            /*
             * load a calculation that results in whatever jump you want
             * JEQ  if computation = 0
             * load A register with the address of where you want to jump to
             */

            //set A = memory location 16
            var output = cpu.Cycle(Functions.GetBitArrayFromInteger(0, 16), Functions.GetBitArrayFromInteger(355, 16), false);
            Functions.CompareBitArray(analyzer.GetAContents(), Functions.GetBitArrayFromInteger(355, 16));

            // set D = -1, and jmp if this results in less than zero. -1 < 0 duh
            //1110111010010100
            output = cpu.Cycle(memory.Cycle(output.Item1, output.Item2, output.Item3), Functions.GetBitArrayFromInteger(61076, 16), false);
            Functions.CompareBitArray(analyzer.GetAContents(), Functions.GetBitArrayFromInteger(355, 16));
            Assert.IsFalse(output.Item2);
            //the program counter output should now be 16 which was what was in register A and should be used as the jump should be done
            Functions.CompareBitArray(output.Item4, Functions.GetBitArrayFromInteger(355, 15));
        }
Example #7
0
        public void ProgramCounterOutputWorks()
        {
            var cpu = new WooComputer.Chips.CPU16Bit();
            var memory = new WooComputer.Chips.Memory(16);

            for(int i = 0; i < 100 ; i++){
                var output = cpu.Cycle(new bool[16], new bool[16], false);
                 Functions.CompareBitArray(Functions.GetBitArrayFromInteger(i+1, 15), output.Item4);
            }
            var resetOutput = cpu.Cycle(new bool[16], new bool[16], true);
            Functions.CompareBitArray(Functions.GetBitArrayFromInteger(0, 15), resetOutput.Item4);
        }
Example #8
0
        public void CanTakeValueFromMemoryAddress0AndMemoryAddress1ThenSumThemAndPutIntoMemoryAddress2ehehe()
        {
            /* you need to rewatch lesson 4 to remember what all this means
             0000000000000000  - @0  set A register to 0, address memory location 0
             1111110000010000  - D=M make the d register have the value of whatever is in the memory location at A (which is the zero location)
             0000000000000001  - @1 set A register to 1, M will now have the value of whatever is in memory at location 1
             1111000010010000  - D= D+M add what is in the d register to whatever is in memory at location A
             0000000000000010  - @2 set A register to 2
             1110001100001000  - M=D put whatever is in D into memory which is pointing to address 2
             * */

            var analyzer = new WooComputer.Chips.CPU16Bit.CPUAnalyzer();
            var cpu = new WooComputer.Chips.CPU16Bit(analyzer);
            var memory = new WooComputer.Chips.Memory(16);

            var valueInMemoryLocation0 = Functions.GetBitArrayFromInteger(5, 16);
            var valueInMemoryLocation1 = Functions.GetBitArrayFromInteger(4, 16);

            memory.Cycle(valueInMemoryLocation0, true, new bool[15]);
            memory.Cycle(valueInMemoryLocation1, true, Functions.GetBitArrayFromInteger(1, 15));

            Functions.CompareBitArray(memory.Cycle(new bool[16], false, new bool[15]), valueInMemoryLocation0);
            Functions.CompareBitArray(memory.Cycle(new bool[16], false, Functions.GetBitArrayFromInteger(1, 15)), valueInMemoryLocation1);

            //I STILL DON'T GET WHERE MEMORY VALUE COMES FROM - WHAT MEMORY ADDRESS ARE YOU SUPPOSE TO PULL THE VALUE FROM AND PUT INTO THE CPU

            //this is the trick, the CPU outputs the memory address which goes into the memory and then the value at that address is pulled out and sent back into the cpu
            //but who controls this, and again what address is used on first cycle

            //#1 -  @0  set A register to 0, address memory location 0
            //this is the first cycle so the Program Counter would be at zero, so you send in the value that exists in memory location zero which in our case is 5 because that is what we specifically put in there from line above
            var output = cpu.Cycle(valueInMemoryLocation0, new bool[16], false);
            //okay well we put the value in from memory but does that affect what comes out from the ALU ???
            //at this point it is not coming out from the ALU/cpu output, is that bad???
            //it is coming out on the next cycle - is that okay?
               Functions.CompareBitArray(new bool[16], output.Item1);
            //write memory should be false as this is a instruction to get memory not write to it
               Assert.IsFalse(output.Item2);
            //the program counter should now be 1 since it cycled once so 1 +0 = 1;
               Functions.CompareBitArray(Functions.GetBitArrayFromInteger(1,16), output.Item4);

               //#2  D=M make the d register have the value of whatever is in the memory location at A (which is the zero location)
               //64528
               output = cpu.Cycle(memory.Cycle(output.Item1,output.Item2,output.Item3), Functions.GetBitArrayFromInteger(64528, 16), false);
            //the value that was input from the previous cycle is now being outputted, is that how it should be?????
               Functions.CompareBitArray(valueInMemoryLocation0, output.Item1);
               Assert.IsFalse(output.Item2);

            //the program counter should now be at 2 since it has been run twice
               Functions.CompareBitArray(Functions.GetBitArrayFromInteger(2, 16), output.Item4);

            // @1 set A register to 1, M will now have the value of whatever is in memory at location 1
               output = cpu.Cycle(memory.Cycle(output.Item1, output.Item2, output.Item3), Functions.GetBitArrayFromInteger(1, 16), false);
               //the program counter should now be at 3
               Functions.CompareBitArray(Functions.GetBitArrayFromInteger(3, 16), output.Item4);

               //  1111000010010000  - D= D+M add what is in the d register to whatever is in memory at location A
               output = cpu.Cycle(memory.Cycle(output.Item1, output.Item2, output.Item3), Functions.GetBitArrayFromInteger(61584, 16), false);
               Functions.CompareBitArray(Functions.GetBitArrayFromInteger(4, 16), output.Item4);

            //0000000000000010  - @2 set A register to 2
               output = cpu.Cycle(memory.Cycle(output.Item1, output.Item2, output.Item3), Functions.GetBitArrayFromInteger(2, 16), false);
               Functions.CompareBitArray(Functions.GetBitArrayFromInteger(5, 16), output.Item4);

            //1110001100001000  - M=D put whatever is in D into memory which is pointing to address 2
               output = cpu.Cycle(memory.Cycle(output.Item1, output.Item2, output.Item3), Functions.GetBitArrayFromInteger(58120, 16), false);
               Functions.CompareBitArray(Functions.GetBitArrayFromInteger(6, 16), output.Item4);

               memory.Cycle(output.Item1, output.Item2, output.Item3);

            //something should be 0000000000001001

            //f**k the output never has a value, its always ZERO
            //Functions.CompareBitArray(analyzer.GetDContents(), valueInMemoryLocation1);
        }
Example #9
0
        public void CanTakeValueFromMemoryAddress0AndMemoryAddress1ThenSumThemAndPutIntoMemoryAddress2()
        {
            var analyzer = new WooComputer.Chips.CPU16Bit.CPUAnalyzer();
            var cpu = new WooComputer.Chips.CPU16Bit(analyzer);
            var memory = new WooComputer.Chips.Memory(16);
            var valueInMemoryLocation0 = Functions.GetBitArrayFromInteger(5, 16);
            var valueInMemoryLocation1 = Functions.GetBitArrayFromInteger(4, 16);

            memory.Cycle(valueInMemoryLocation0, true, new bool[15]);
            memory.Cycle(valueInMemoryLocation1, true, Functions.GetBitArrayFromInteger(1, 15));

            //#1 -  @0  set A register to 0, address memory location 0
            //still don't understand what value should go into memory on the first cycle, does it matter, it would just be false
            var output = cpu.Cycle(new bool[16], new bool[16], false);

            //#2  D=M make the d register have the value of whatever is in the memory location at A (which is the zero location)
            //64528
            output = cpu.Cycle(memory.Cycle(output.Item1, output.Item2, output.Item3), Functions.GetBitArrayFromInteger(64528, 16), false);

            Functions.CompareBitArray(valueInMemoryLocation0, output.Item1);
            Functions.CompareBitArray(analyzer.GetDContents(), output.Item1);
            Functions.CompareBitArray(analyzer.GetDContents(), Functions.GetBitArrayFromInteger(5, 16));

            // @1 set A register to 1, M will now have the value of whatever is in memory at location 1
            output = cpu.Cycle(memory.Cycle(output.Item1, output.Item2, output.Item3), Functions.GetBitArrayFromInteger(1, 16), false);
            Functions.CompareBitArray(analyzer.GetAContents(), Functions.GetBitArrayFromInteger(1, 16));

            //  1111000010010000  - D= D+M add what is in the d register to whatever is in memory at location A
            output = cpu.Cycle(memory.Cycle(output.Item1, output.Item2, output.Item3), Functions.GetBitArrayFromInteger(61584, 16), false);
            Functions.CompareBitArray(analyzer.GetDContents(), Functions.GetBitArrayFromInteger(9, 16));
            Functions.CompareBitArray(output.Item1, Functions.GetBitArrayFromInteger(9, 16));

            //0000000000000010  - @2 set A register to 2
            output = cpu.Cycle(memory.Cycle(output.Item1, output.Item2, output.Item3), Functions.GetBitArrayFromInteger(2, 16), false);
            Functions.CompareBitArray(analyzer.GetAContents(), Functions.GetBitArrayFromInteger(2, 16));

            //1110001100001000  - M=D put whatever is in D into memory which is pointing to address 2
            output = cpu.Cycle(memory.Cycle(output.Item1, output.Item2, output.Item3), Functions.GetBitArrayFromInteger(58120, 16), false);
            memory.Cycle(output.Item1, output.Item2, output.Item3);
            Functions.CompareBitArray(output.Item1, Functions.GetBitArrayFromInteger(9, 16));

            //so after all that the value in memory spot 2 should be 9
            var memoryValueInSpot2 = memory.Cycle(new bool[16], false, Functions.GetBitArrayFromInteger(2, 15));
            Functions.CompareBitArray(memoryValueInSpot2, Functions.GetBitArrayFromInteger(9, 16));
        }