public void Input_Click(object sender, System.EventArgs e) { PublicStuff.MF.WriteToRegister(PublicStuff.Registers.X1, Microsoft.VisualBasic.Interaction.InputBox("(POINT 1) Enter X1: ", "RedCompiler - GPU Screen Input X1", "0")); PublicStuff.MF.WriteToRegister(PublicStuff.Registers.Y1, Microsoft.VisualBasic.Interaction.InputBox("(POINT 1) Enter Y1: ", "RedCompiler - GPU Screen Input Y1", "0")); PublicStuff.MF.WriteToRegister(PublicStuff.Registers.X2, Microsoft.VisualBasic.Interaction.InputBox("(POINT 2) Enter X2: ", "RedCompiler - GPU Screen Input X2", "0")); PublicStuff.MF.WriteToRegister(PublicStuff.Registers.Y2, Microsoft.VisualBasic.Interaction.InputBox("(POINT 2) Enter Y2: ", "RedCompiler - GPU Screen Input Y2", "0")); string mode = Microsoft.VisualBasic.Interaction.InputBox("Select the mode for the GPU.\n1. Full Rectangle\n2. First Half\n3. Second half\n4. Dot mode\n5. Pixels\n\nEnter the number below."); if (Convert.ToInt16(mode) < 0) { System.Windows.Forms.Application.Exit(); } tempMode = IntToMode((Convert.ToInt16(mode))); GPU_Draw(System.Convert.ToInt16(PublicStuff.MF.ReadFromRegister(PublicStuff.Registers.X1)), System.Convert.ToInt16(PublicStuff.MF.ReadFromRegister(PublicStuff.Registers.X2)), System.Convert.ToInt16(PublicStuff.MF.ReadFromRegister(PublicStuff.Registers.Y1)), System.Convert.ToInt16(PublicStuff.MF.ReadFromRegister(PublicStuff.Registers.Y2)), tempMode); }
public void ClearMemory() { ShowNumber("0000"); RAM = new String[33]; m = PublicStuff.DrawMode.FullRectangle; RegisterRead = new String[7]; RegisterWrite = new String[7]; Switch1 = false; Switch2 = false; Switch3 = false; Switch4 = false; PublicStuff.gpu = new frmGPU(); // PRGMEM = new String[59]; }
public MainForm() { InitializeComponent(); m = PublicStuff.DrawMode.FullRectangle; }
public void RedCompile(short pc) { PC = pc; Branch = false; BranchAllowed = true; while (AllowedToRun) { TemporaryLine = Code[PC].Split(' '); Output("PC: " + PC + ".", true); if (TemporaryLine.Length >= 5) { ifgreater = TemporaryLine[5].ToCharArray(); ifzero = TemporaryLine[4].ToCharArray(); command = TemporaryLine[3].ToCharArray(); load = TemporaryLine[2].ToCharArray(); save = TemporaryLine[1].ToCharArray(); goTo = TemporaryLine[0].ToCharArray(); #region "COMMAND" if (command.ToString() != "000000") { if (RGCommandExists(command, "*****0")) { Output("Command Mode: ALU.", true); if (RGCommandExists(command, "*001#*")) { Output("Command selected: ADD.", true); WriteToROM(PublicStuff.ROMs.ALU_Answer, Convert.ToString((int)(Convert.ToInt32(ReadFromRegister(PublicStuff.Registers.ALU1)) + Convert.ToInt32(ReadFromRegister(PublicStuff.Registers.ALU2))))); } if (RGCommandExists(command, "*010#*")) { Output("Command selected: SUB.", true); WriteToROM(PublicStuff.ROMs.ALU_Answer, Convert.ToString((int)(Convert.ToInt32(ReadFromRegister(PublicStuff.Registers.ALU1)) - Convert.ToInt32(ReadFromRegister(PublicStuff.Registers.ALU2))))); } if (RGCommandExists(command, "*011#*")) { Output("Command selected: XOR.", true); WriteToROM(PublicStuff.ROMs.ALU_Answer, Convert.ToString((int)(Convert.ToInt32(ReadFromRegister(PublicStuff.Registers.ALU1)) ^ Convert.ToInt32(ReadFromRegister(PublicStuff.Registers.ALU2))))); } if (RGCommandExists(command, "*100#*")) { Output("Command selected: OR.", true); WriteToROM(PublicStuff.ROMs.ALU_Answer, Convert.ToString(Convert.ToBoolean(ReadFromRegister(PublicStuff.Registers.ALU1)) | Convert.ToBoolean(ReadFromRegister(PublicStuff.Registers.ALU2)))); } if (RGCommandExists(command, "*101#*")) { Output("Command selected: IMPLIES.", true); } if (RGCommandExists(command, "*110#*")) { Output("Command selected: AND.", true); WriteToROM(PublicStuff.ROMs.ALU_Answer, Convert.ToString(Convert.ToBoolean(ReadFromRegister(PublicStuff.Registers.ALU1)) & Convert.ToBoolean(ReadFromRegister(PublicStuff.Registers.ALU2)))); } if (RGCommandExists(command, "*111#*")) { Output("Command selected: Shift LEFT & RIGHT", true); WriteToRegister(PublicStuff.Registers.ALU1, Convert.ToString((int)(Convert.ToInt32(ReadFromRegister(PublicStuff.Registers.ALU1)) << 1))); WriteToRegister(PublicStuff.Registers.ALU2, Convert.ToString((int)(Convert.ToInt32(ReadFromRegister(PublicStuff.Registers.ALU2)) >> 1))); } } else if (RGCommandExists(command, "*****1")) { Output("Command Mode: GPU.", true); if (RGCommandExists(command, "1*****")) { Output("Command selected: G-Indicator (ON)", true); gi.BackColor = ON; } else if (RGCommandExists(command, "0*****")) { Output("Command selected: G-Indicator (OFF)", true); gi.BackColor = OFF; } if (RGCommandExists(command, "*00***")) { Output("Command selected: Dot.", true); m = PublicStuff.DrawMode.Dot; } if (RGCommandExists(command, "*01***")) { Output("Command selected: 1st half of Hollow Rectangle.", true); m = PublicStuff.DrawMode.FirstHalf; } if (RGCommandExists(command, "*10***")) { Output("Command selected: 2nd half of Hollow Rectangle.", true); m = PublicStuff.DrawMode.SecondHalf; } if (RGCommandExists(command, "*11***")) { Output("Command selected: Full Rectangle.", true); m = PublicStuff.DrawMode.FullRectangle; } if (RGCommandExists(command, "***11*")) { Output("Command selected: Update Screen.", true); UpdateScreen = true; } if (RGCommandExists(command, "***01*")) { Output("Command selected: Draw Shape.", true); PublicStuff.gpu.Show(); PublicStuff.gpu.GPU_Draw(Convert.ToInt32(ReadFromRegister(PublicStuff.Registers.X1)), Convert.ToInt32(ReadFromRegister(PublicStuff.Registers.X2)), Convert.ToInt32(ReadFromRegister(PublicStuff.Registers.Y1)), Convert.ToInt32(ReadFromRegister(PublicStuff.Registers.Y2)), PublicStuff.MF.m); } if (RGCommandExists(command, "***10*")) { Output("Command selected: Clear Screen.", true); PublicStuff.gpu.ResetScreen(); } } } #endregion #region "LOAD" if (load.ToString() != "000000") { if (RGCommandExists(load, "*****0")) { Output("Loading Mode: ROM.", true); if (RGCommandExists(load, "001***")) { Output("Loading from ROM #1", true); SetLoadedValue(ReadFromROM(PublicStuff.ROMs.ROM1)); } if (RGCommandExists(load, "010***")) { if (RNG) { Output("Loading from RNG", true); WriteToROM(PublicStuff.ROMs.RNG, new Random().Next(0, 0x400).ToString()); SetLoadedValue(ReadFromROM(PublicStuff.ROMs.RNG)); } else { Output("RNG is not on. Loaded value is set to zero.", true); SetLoadedValue("0"); } } if (RGCommandExists(load, "011***")) { Output("Loading from ROM #3", true); SetLoadedValue(ReadFromROM(PublicStuff.ROMs.ROM3)); } if (RGCommandExists(load, "100***")) { Output("Loading from ALU Answer", true); SetLoadedValue(ReadFromROM(PublicStuff.ROMs.ALU_Answer)); } if (RGCommandExists(load, "101***")) { Output("Loading from ROM #2", true); SetLoadedValue(ReadFromROM(PublicStuff.ROMs.ROM2)); } if (RGCommandExists(load, "110***")) { Output("Loading from UI", true); Continue = false; if (PublicStuff.prgstopped.IsDisposed) { PublicStuff.prgstopped = new frmProgramStopped(); } PublicStuff.prgstopped.Show(); while (!Continue) { Application.DoEvents(); } SetLoadedValue(ReadFromROM(PublicStuff.ROMs.UI)); } if (RGCommandExists(load, "111***")) { Output("Loading from ROM #4", true); SetLoadedValue(ReadFromROM(PublicStuff.ROMs.ROM4)); } } else if (RGCommandExists(load, "*****1")) { Output("Loading Mode: RAM.", true); temp = Convert.ToString(string.Concat(new object[] { save[0], " ", load[1], " ", load[2], " ", load[3], " ", load[4] })).Replace(" ", ""); LoadedValue = GetValFromRAM(temp); Output("Loaded address: " + temp + ". Value: " + GetValFromRAM(temp) + ".", true); } } #endregion #region "SAVE" if (save.ToString() != "000000") { if (RGCommandExists(save, "*****0")) { Output("Saving Mode: ROM.", true); if (RGCommandExists(save, "001***")) { Output("Save Location: Y1.", true); WriteToRegister(PublicStuff.Registers.Y1, GetLoadedValue()); Output("Stored value: " + GetLoadedValue() + " to Y1", true); } if (RGCommandExists(save, "010***")) { Output("Save Location: ALU 1.", true); WriteToRegister(PublicStuff.Registers.ALU1, GetLoadedValue()); Output("Stored value: " + GetLoadedValue() + " to ALU1", true); } if (RGCommandExists(save, "011***")) { Output("Save Location: Y2.", true); WriteToRegister(PublicStuff.Registers.Y2, GetLoadedValue()); Output("Stored value: " + GetLoadedValue() + " to Y2", true); } if (RGCommandExists(save, "100***")) { Output("Save Location: ALU 2.", true); WriteToRegister(PublicStuff.Registers.ALU2, GetLoadedValue()); Output("Stored value: " + GetLoadedValue() + " to ALU 2", true); } if (RGCommandExists(save, "101***")) { Output("Save Location: X2.", true); WriteToRegister(PublicStuff.Registers.X2, GetLoadedValue()); Output("Stored value: " + GetLoadedValue() + " to X2", true); } if (RGCommandExists(save, "110***")) { Output("Save Location: X1.", true); WriteToRegister(PublicStuff.Registers.X1, GetLoadedValue()); Output("Stored value: " + GetLoadedValue() + " to X1", true); } if (RGCommandExists(save, "111***")) { Output("Save Location: Number Screen.", true); WriteToRegister(PublicStuff.Registers.Numberscreen, GetLoadedValue()); if (UpdateScreen) { ShowNumber(ReadFromRegister(PublicStuff.Registers.Numberscreen)); Output("Stored " + ReadFromRegister(PublicStuff.Registers.Numberscreen) + " to Number Screen", true); UpdateScreen = false; } } } else if (RGCommandExists(save, "*****1")) { Output("Saving Mode: RAM.", true); temp = Convert.ToString(string.Concat(new object[] { save[0], " ", save[1], " ", save[2], " ", save[3], " ", save[4] })).Replace(" ", ""); if (!WriteToRAM(temp, LoadedValue)) { Output("Error while saving to ram, value: " + LoadedValue, false); } Output("Saved to RAM. Address: " + temp + ". Value: " + LoadedValue, true); } } #endregion #region "GOTO" if (goTo.ToString() != "0000") { if (RGCommandExists(goTo, "0***")) { if (RGCommandExists(goTo, "0010")) { Output("Goto: Switch #1", true); BranchAllowed = Switch1; } if (RGCommandExists(goTo, "0011")) { Output("Goto: Switch #2", true); BranchAllowed = Switch2; } if (RGCommandExists(goTo, "0100")) { Output("Goto: RNG", true); BranchAllowed = RNG; } if (RGCommandExists(goTo, "0001")) { Output("Goto: Switch #4", true); BranchAllowed = Switch4; } if (RGCommandExists(goTo, "0101")) { Output("Goto: ALU if 0", true); if (ReadFromROM(PublicStuff.ROMs.ALU_Answer) == "0") { BranchAllowed = true; } else { BranchAllowed = false; } } } else if (RGCommandExists(goTo, "1***") && RNG) { Output("Goto: Random line between 0 and " + (Code.Length - 1) + "."); newline = Convert.ToInt16(new Random().Next(0, Code.Length - 1)); RedCompile(newline); } } #endregion #region "Condtional Branching" Output(string.Concat(new object[] { "IF Loaded value = 0: ", TemporaryLine[4], " (Decimal: ", Convert.ToInt16(FromBinary(TemporaryLine[4])), ")" }), true); Output(string.Concat(new object[] { "IF Loaded value > 0: ", TemporaryLine[5], " (Decimal: ", Convert.ToInt16(FromBinary(TemporaryLine[5])), ")" }), true); if (Convert.ToInt16(LoadedValue) <= 0) { newline = Convert.ToInt16(FromBinary(TemporaryLine[4])); Branch = true; } if (Convert.ToInt16(LoadedValue) > 0) { newline = Convert.ToInt16(FromBinary(TemporaryLine[5])); Branch = true; } #endregion #region "Clock" for (short i = 0; i < (overclock * 10); i++) Application.DoEvents(); Output("\r\n", true); #endregion #region "The actual branching part" if (BranchAllowed && Branch) { newline--; if (newline <= 0) { branchToLineZero(); return; } else if (newline > 0) { RedCompile(newline); } } #endregion } } }