Skip to content

Commit

Permalink
Add bit shifting, attempt fix of logisim but still doesnt work
Browse files Browse the repository at this point in the history
  • Loading branch information
sam-astro committed Aug 11, 2022
1 parent 606d987 commit 674b23c
Show file tree
Hide file tree
Showing 33 changed files with 9,266 additions and 410 deletions.
Binary file modified Astro8-Emulator/.vs/Astro8-Emulator/v17/.suo
Binary file not shown.
Binary file modified Astro8-Emulator/.vs/Astro8-Emulator/v17/Preview/Browse.VC.db
Binary file not shown.
111 changes: 71 additions & 40 deletions Astro8-Emulator/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
") </dev/tty")
#endif

#define DEV_MODE false
#define DEV_MODE true


#if UNIX
Expand Down Expand Up @@ -68,50 +68,52 @@ std::string projectDirectory;

// Refer to https://sam-astro.github.io/Astro8-Computer/docs/Architecture/Micro%20Instructions.html

#define MICROINSTR_SIZE 14
#define MICROINSTR_SIZE 15
using MicroInstruction = uint16_t;
static_assert(sizeof(MicroInstruction) * 8 >= MICROINSTR_SIZE,
"Size of MicroInstruction is too small, increase its width...");

MicroInstruction microinstructionData[2048];
MicroInstruction microinstructionData[4096];

enum ALUInstruction : MicroInstruction {
ALU_SU = 0b00000000000001,
ALU_MU = 0b00000000000010,
ALU_DI = 0b00000000000011,
ALU_MASK = 0b00000000000011,
ALU_SU = 0b000000000000001,
ALU_MU = 0b000000000000010,
ALU_DI = 0b000000000000011,
ALU_SL = 0b000000000000100,
ALU_SR = 0b000000000000101,
ALU_MASK = 0b000000000000111,
};

enum ReadInstruction : MicroInstruction {
READ_RA = 0b00000000000100,
READ_RB = 0b00000000001000,
READ_RC = 0b00000000001100,
READ_RM = 0b00000000010000,
READ_IR = 0b00000000010100,
READ_CR = 0b00000000011000,
READ_RE = 0b00000000011100,
READ_MASK = 0b00000000011100,
READ_RA = 0b000000000001000,
READ_RB = 0b000000000010000,
READ_RC = 0b000000000011000,
READ_RM = 0b000000000100000,
READ_IR = 0b000000000101000,
READ_CR = 0b000000000110000,
READ_RE = 0b000000000111000,
READ_MASK = 0b000000000111000,
};

enum WriteInstruction : MicroInstruction {
WRITE_WA = 0b00000000100000,
WRITE_WB = 0b00000001000000,
WRITE_WC = 0b00000001100000,
WRITE_IW = 0b00000010000000,
WRITE_DW = 0b00000010100000,
WRITE_WM = 0b00000011000000,
WRITE_J = 0b00000011100000,
WRITE_AW = 0b00000100000000,
WRITE_WE = 0b00000100100000,
WRITE_MASK = 0b00000111100000,
WRITE_WA = 0b000000001000000,
WRITE_WB = 0b000000010000000,
WRITE_WC = 0b000000011000000,
WRITE_IW = 0b000000100000000,
WRITE_DW = 0b000000101000000,
WRITE_WM = 0b000000110000000,
WRITE_J = 0b000000111000000,
WRITE_AW = 0b000001000000000,
WRITE_WE = 0b000001001000000,
WRITE_MASK = 0b000001111000000,
};

enum StandaloneInstruction : MicroInstruction {
STANDALONE_FL = 0b00001000000000,
STANDALONE_EI = 0b00010000000000,
STANDALONE_ST = 0b00100000000000,
STANDALONE_CE = 0b01000000000000,
STANDALONE_EO = 0b10000000000000,
STANDALONE_FL = 0b000010000000000,
STANDALONE_EI = 0b000100000000000,
STANDALONE_ST = 0b001000000000000,
STANDALONE_CE = 0b010000000000000,
STANDALONE_EO = 0b100000000000000,
};


Expand Down Expand Up @@ -143,12 +145,12 @@ SDL_Texture* texture;
std::vector< unsigned char > pixels(64 * 64 * 4, 0);


std::string instructions[] = { "NOP", "AIN", "BIN", "CIN", "LDIA", "LDIB", "RDEXP", "WREXP", "STA", "STC", "ADD", "SUB", "MULT", "DIV", "JMP", "JMPZ","JMPC", "JREG", "LDAIN", "STAOUT", "LDLGE", "STLGE", "LDW", "SWP", "SWPC" };
std::string instructions[] = { "NOP", "AIN", "BIN", "CIN", "LDIA", "LDIB", "RDEXP", "WREXP", "STA", "STC", "ADD", "SUB", "MULT", "DIV", "JMP", "JMPZ","JMPC", "JREG", "LDAIN", "STAOUT", "LDLGE", "STLGE", "LDW", "SWP", "SWPC", "BSL", "BSR" };

std::string microinstructions[] = { "EO", "CE", "ST", "EI", "FL" };
std::string writeInstructionSpecialAddress[] = { "WA", "WB", "WC", "IW", "DW", "WM", "J", "AW", "WE" };
std::string readInstructionSpecialAddress[] = { "RA", "RB", "RC", "RM", "IR", "CR", "RE" };
std::string aluInstructionSpecialAddress[] = { "SU", "MU", "DI" };
std::string aluInstructionSpecialAddress[] = { "SU", "MU", "DI", "SL", "SR" };
std::string flagtypes[] = { "ZEROFLAG", "CARRYFLAG" };

std::string instructioncodes[] = {
Expand Down Expand Up @@ -177,6 +179,8 @@ std::string instructioncodes[] = {
"ldw( 2=cr,aw & 3=ce,rm,wa & 4=ei", // Load value directly after counter into A, and advance counter by 2
"swp( 2=ra,wc & 3=wa,rb & 4=rc,wb & 5=ei", // Swap register A and register B (this will overwrite the contents of register C, using it as a temporary swap area)
"swpc( 2=ra,wb & 3=wa,rc & 4=rb,wc & 5=ei", // Swap register A and register C (this will overwrite the contents of register B, using it as a temporary swap area)
"bsl( 2=sl,wa,eo,fl & 3=ei", // Bit shift left A register, the number of bits to shift determined by the value in register B
"bsr( 2=sr,wa,eo,fl & 3=ei", // Bit shift left A register, the number of bits to shift determined by the value in register B
};


Expand Down Expand Up @@ -620,6 +624,32 @@ void Update()
}
break;

case ALU_SL: // Shift left
bus = AReg << (BReg & 0b1111);

if (bus == 0)
flags[0] = 1;

if (bus >= 65534)
{
bus = bus - 65534;
flags[1] = 1;
}
break;

case ALU_SR: // Shift right
bus = AReg >> (BReg & 0b1111);

if (bus == 0)
flags[0] = 1;

if (bus >= 65534)
{
bus = bus - 65534;
flags[1] = 1;
}
break;

default: // Add
if (AReg + BReg == 0)
flags[0] = 1;
Expand Down Expand Up @@ -929,7 +959,7 @@ vector<std::string> parseCode(const std::string& input)
if (trim(splitcode[i]) == "")
{
continue;
}
}

vector<std::string> splitBySpace = explode(splitcode[i], ' ');

Expand All @@ -954,7 +984,7 @@ vector<std::string> parseCode(const std::string& input)
cout << ("-\t" + splitcode[i] + "\t ~ ~\n");
#endif
continue;
}
}

// Set the current location in memory equal to a value: here <value>
if (splitBySpace[0] == "HERE")
Expand Down Expand Up @@ -989,7 +1019,7 @@ vector<std::string> parseCode(const std::string& input)
cout << DecToBinFilled(f, 5);
#endif
outputBytes[memaddr] = DecToBinFilled(f, 5);
}
}
}

// Check if any args are after the command
Expand Down Expand Up @@ -1084,9 +1114,10 @@ void ComputeStepInstructions(const std::string& stepContents, char* stepComputed
{ // Check all ALU instruction types
if (stepContents.find(aluInstructionSpecialAddress[minsother]) != std::string::npos)
{
std::string binaryval = DecToBinFilled(minsother + 1, 2);
std::string binaryval = DecToBinFilled(minsother + 1, 3);
stepComputedInstruction[12] = binaryval[0];
stepComputedInstruction[13] = binaryval[1];
stepComputedInstruction[14] = binaryval[2];
}
}

Expand Down Expand Up @@ -1160,7 +1191,7 @@ void GenerateMicrocode()

std::string midaddress = DecToBinFilled(actualStep, 4);

char stepComputedInstruction[MICROINSTR_SIZE] = { '0','0', '0','0', '0','0', '0','0', '0','0', '0','0', '0','0' };
char stepComputedInstruction[MICROINSTR_SIZE] = { '0','0', '0','0', '0','0', '0','0', '0','0', '0','0', '0','0','0' };
ComputeStepInstructions(stepContents, stepComputedInstruction);


Expand Down Expand Up @@ -1227,7 +1258,7 @@ void GenerateMicrocode()

std::string midaddress = DecToBinFilled(actualStep, 4);

char stepComputedInstruction[MICROINSTR_SIZE] = { '0','0', '0','0', '0','0', '0','0', '0','0', '0','0', '0','0' };
char stepComputedInstruction[MICROINSTR_SIZE] = { '0','0', '0','0', '0','0', '0','0', '0','0', '0','0', '0','0','0' };
ComputeStepInstructions(stepContents, stepComputedInstruction);


Expand Down Expand Up @@ -1277,7 +1308,7 @@ void GenerateMicrocode()
#endif
output[BinToDec(startaddress + midaddress + charToString(newendaddress))] = BinToHexFilled(stepComputedInstruction, 5);
}
}
}
}

// Print the output
Expand Down Expand Up @@ -1309,4 +1340,4 @@ void GenerateMicrocode()
fstream myStream;
myStream.open("./microinstructions_cpu", ios::out);
myStream << processedOutput;
}
}
Binary file modified Astro8-Emulator/x64/Release/Astro8-Emulator.exe
Binary file not shown.
Binary file modified Astro8-Emulator/x64/Release/Astro8-Emulator.iobj
Binary file not shown.
Binary file modified Astro8-Emulator/x64/Release/Astro8-Emulator.ipdb
Binary file not shown.
38 changes: 13 additions & 25 deletions Astro8-Emulator/x64/Release/Astro8-Emulator.log
Original file line number Diff line number Diff line change
@@ -1,35 +1,23 @@
 armstrong-compiler.cpp
 main.cpp
D:\Code\Astro8-Computer\Astro8-Emulator\processing.h(71,30): warning C4267: 'initializing': conversion from 'size_t' to 'int', possible loss of data
D:\Code\Astro8-Computer\Astro8-Emulator\processing.h(134,30): warning C4267: '=': conversion from 'size_t' to 'int', possible loss of data
D:\Code\Astro8-Computer\Astro8-Emulator\processing.h(135,30): warning C4267: '=': conversion from 'size_t' to 'int', possible loss of data
D:\Code\Astro8-Computer\Astro8-Emulator\processing.h(136,30): warning C4267: '=': conversion from 'size_t' to 'int', possible loss of data
D:\Code\Astro8-Computer\Astro8-Emulator\processing.h(137,30): warning C4267: '=': conversion from 'size_t' to 'int', possible loss of data
D:\Code\Astro8-Computer\Astro8-Emulator\processing.h(138,29): warning C4267: '=': conversion from 'size_t' to 'int', possible loss of data
D:\Code\Astro8-Computer\Astro8-Emulator\processing.h(139,29): warning C4267: '=': conversion from 'size_t' to 'int', possible loss of data
D:\Code\Astro8-Computer\Astro8-Emulator\armstrong-compiler.cpp(91,28): warning C4244: '+=': conversion from 'double' to 'unsigned long', possible loss of data
D:\Code\Astro8-Computer\Astro8-Emulator\armstrong-compiler.cpp(94,28): warning C4244: '+=': conversion from 'double' to 'unsigned long', possible loss of data
D:\Code\Astro8-Computer\Astro8-Emulator\armstrong-compiler.cpp(97,28): warning C4244: '+=': conversion from 'double' to 'unsigned long', possible loss of data
D:\Code\Astro8-Computer\Astro8-Emulator\armstrong-compiler.cpp(302,32): warning C4267: 'return': conversion from 'size_t' to 'int', possible loss of data
assembler.cpp
main.cpp
D:\Code\Astro8-Computer\Astro8-Emulator\processing.h(71,30): warning C4267: 'initializing': conversion from 'size_t' to 'int', possible loss of data
D:\Code\Astro8-Computer\Astro8-Emulator\processing.h(134,30): warning C4267: '=': conversion from 'size_t' to 'int', possible loss of data
D:\Code\Astro8-Computer\Astro8-Emulator\processing.h(135,30): warning C4267: '=': conversion from 'size_t' to 'int', possible loss of data
D:\Code\Astro8-Computer\Astro8-Emulator\processing.h(136,30): warning C4267: '=': conversion from 'size_t' to 'int', possible loss of data
D:\Code\Astro8-Computer\Astro8-Emulator\processing.h(137,30): warning C4267: '=': conversion from 'size_t' to 'int', possible loss of data
D:\Code\Astro8-Computer\Astro8-Emulator\processing.h(138,29): warning C4267: '=': conversion from 'size_t' to 'int', possible loss of data
D:\Code\Astro8-Computer\Astro8-Emulator\processing.h(139,29): warning C4267: '=': conversion from 'size_t' to 'int', possible loss of data
D:\Code\Astro8-Computer\Astro8-Emulator\main.cpp(465,24): warning C4244: 'argument': conversion from 'int' to 'float', possible loss of data
D:\Code\Astro8-Computer\Astro8-Emulator\main.cpp(545,24): warning C5051: attribute 'likely' requires at least '/std:c++20'; ignored
D:\Code\Astro8-Computer\Astro8-Emulator\main.cpp(563,10): warning C4244: '=': conversion from 'uint64_t' to 'int', possible loss of data
D:\Code\Astro8-Computer\Astro8-Emulator\main.cpp(575,32): warning C5051: attribute 'unlikely' requires at least '/std:c++20'; ignored
D:\Code\Astro8-Computer\Astro8-Emulator\main.cpp(641,5): warning C5051: attribute 'likely' requires at least '/std:c++20'; ignored
D:\Code\Astro8-Computer\Astro8-Emulator\main.cpp(670,32): warning C5051: attribute 'unlikely' requires at least '/std:c++20'; ignored
D:\Code\Astro8-Computer\Astro8-Emulator\main.cpp(783,45): warning C4244: 'argument': conversion from 'int' to 'float', possible loss of data
D:\Code\Astro8-Computer\Astro8-Emulator\main.cpp(783,32): warning C4244: 'argument': conversion from 'int' to 'float', possible loss of data
D:\Code\Astro8-Computer\Astro8-Emulator\main.cpp(1140,42): warning C4267: '=': conversion from 'size_t' to 'int', possible loss of data
D:\Code\Astro8-Computer\Astro8-Emulator\main.cpp(469,24): warning C4244: 'argument': conversion from 'int' to 'float', possible loss of data
D:\Code\Astro8-Computer\Astro8-Emulator\main.cpp(549,24): warning C5051: attribute 'likely' requires at least '/std:c++20'; ignored
D:\Code\Astro8-Computer\Astro8-Emulator\main.cpp(567,10): warning C4244: '=': conversion from 'uint64_t' to 'int', possible loss of data
D:\Code\Astro8-Computer\Astro8-Emulator\main.cpp(579,32): warning C5051: attribute 'unlikely' requires at least '/std:c++20'; ignored
D:\Code\Astro8-Computer\Astro8-Emulator\main.cpp(671,5): warning C5051: attribute 'likely' requires at least '/std:c++20'; ignored
D:\Code\Astro8-Computer\Astro8-Emulator\main.cpp(700,32): warning C5051: attribute 'unlikely' requires at least '/std:c++20'; ignored
D:\Code\Astro8-Computer\Astro8-Emulator\main.cpp(813,45): warning C4244: 'argument': conversion from 'int' to 'float', possible loss of data
D:\Code\Astro8-Computer\Astro8-Emulator\main.cpp(813,32): warning C4244: 'argument': conversion from 'int' to 'float', possible loss of data
D:\Code\Astro8-Computer\Astro8-Emulator\main.cpp(1171,42): warning C4267: '=': conversion from 'size_t' to 'int', possible loss of data
Generating code
Previous IPDB and IOBJ mismatch, fall back to full compilation.
All 1207 functions were compiled because no usable IPDB/IOBJ from previous compilation was found.
2 of 1207 functions ( 0.2%) were compiled, the rest were copied from previous compilation.
0 functions were new in current compilation
0 functions had inline decision re-evaluated but remain unchanged
Finished generating code
Astro8-Emulator.vcxproj -> D:\Code\Astro8-Computer\Astro8-Emulator\x64\Release\Astro8-Emulator.exe
Binary file modified Astro8-Emulator/x64/Release/Astro8-Emulator.pdb
Binary file not shown.
Binary file not shown.
Binary file modified Astro8-Emulator/x64/Release/Astro8-Emulator.tlog/CL.read.1.tlog
Binary file not shown.
Binary file modified Astro8-Emulator/x64/Release/Astro8-Emulator.tlog/CL.write.1.tlog
Binary file not shown.
Binary file modified Astro8-Emulator/x64/Release/main.obj
Binary file not shown.
Loading

0 comments on commit 674b23c

Please sign in to comment.