Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // ------------------------------------------------------------------------------------------------------- [Project] PPC2C ------------------------------------------------------------------------------------------------------- //
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Drawing;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Windows.Forms;
- // Made by XeClutch :)
- // Alpha Build #5
- namespace PowerPC2C
- {
- public partial class Form1 : Form
- {
- public Form1()
- {
- InitializeComponent();
- }
- private void convertcode_Click(object sender, EventArgs e)
- {
- int instr = 0;
- string[] lines = codebox_ppc.Text.Split("\n".ToCharArray());
- string output = "";
- foreach (string str in lines)
- {
- try
- {
- #region PPC:add
- if (lines[instr].StartsWith("add ")) // Add
- {
- lines[instr] = lines[instr].Replace("add ", "");
- string reg = lines[instr].ToCharArray()[0].ToString();
- reg += lines[instr].ToCharArray()[1].ToString();
- if (lines[instr].ToCharArray()[2].ToString() != ",")
- reg += lines[instr].ToCharArray()[2].ToString();
- output += reg + " = (";
- lines[instr] = lines[instr].Replace(reg + ", ", "");
- string reg2 = lines[instr].ToCharArray()[0].ToString();
- reg2 += lines[instr].ToCharArray()[1].ToString();
- if (lines[instr].ToCharArray()[2].ToString() != ",")
- reg2 += lines[instr].ToCharArray()[2].ToString();
- output += reg2 + " + ";
- lines[instr] = lines[instr].Replace(reg2 + ", ", "");
- string val = lines[instr];
- output += val + ");\n";
- }
- #endregion
- #region PPC:addi
- if (lines[instr].StartsWith("addi ")) // # Add Immediate
- {
- lines[instr] = lines[instr].Replace("addi ", "");
- string reg = lines[instr].ToCharArray()[0].ToString();
- reg += lines[instr].ToCharArray()[1].ToString();
- if (lines[instr].ToCharArray()[2].ToString() != ",")
- reg += lines[instr].ToCharArray()[2].ToString();
- output += reg + " = (";
- lines[instr] = lines[instr].Replace(reg + ", ", "");
- string reg2 = lines[instr].ToCharArray()[0].ToString();
- reg2 += lines[instr].ToCharArray()[1].ToString();
- if (lines[instr].ToCharArray()[2].ToString() != ",")
- reg2 += lines[instr].ToCharArray()[2].ToString();
- output += reg2 + " + ";
- lines[instr] = lines[instr].Replace(reg2 + ", ", "");
- string val = lines[instr];
- output += val + ");\n";
- }
- #endregion
- #region PPC:and
- if (lines[instr].StartsWith("and "))
- {
- lines[instr] = lines[instr].Replace("and ", "");
- string reg = lines[instr].ToCharArray()[0].ToString();
- reg += lines[instr].ToCharArray()[1].ToString();
- if (lines[instr].ToCharArray()[2].ToString() != ",")
- reg += lines[instr].ToCharArray()[2].ToString();
- output += reg + " &= ";
- lines[instr] = lines[instr].Replace(reg + ", ", "");
- string val = lines[instr];
- output += val + ";\n";
- }
- #endregion
- #region PPC:andi
- if (lines[instr].StartsWith("andi "))
- {
- lines[instr] = lines[instr].Replace("andi ", "");
- string reg = lines[instr].ToCharArray()[0].ToString();
- reg += lines[instr].ToCharArray()[1].ToString();
- if (lines[instr].ToCharArray()[2].ToString() != ",")
- reg += lines[instr].ToCharArray()[2].ToString();
- output += reg + " &= ";
- lines[instr] = lines[instr].Replace(reg + ", ", "");
- string val = lines[instr];
- output += val + ";\n";
- }
- #endregion
- #region PPC:andis
- if (lines[instr].StartsWith("andis "))
- {
- lines[instr] = lines[instr].Replace("andis ", "");
- string reg = lines[instr].ToCharArray()[0].ToString();
- reg += lines[instr].ToCharArray()[1].ToString();
- if (lines[instr].ToCharArray()[2].ToString() != ",")
- reg += lines[instr].ToCharArray()[2].ToString();
- output += reg + " &= (";
- lines[instr] = lines[instr].Replace(reg + ", ", "");
- string val = lines[instr];
- output += val + " << 16);\n";
- }
- #endregion
- #region PPC:divw
- if (lines[instr].StartsWith("divw ")) // # Divide Word
- {
- lines[instr] = lines[instr].Replace("divw ", "");
- string reg = lines[instr].ToCharArray()[0].ToString();
- reg += lines[instr].ToCharArray()[1].ToString();
- if (lines[instr].ToCharArray()[2].ToString() != ",")
- reg += lines[instr].ToCharArray()[2].ToString();
- output += reg + " = (";
- lines[instr] = lines[instr].Replace(reg + ", ", "");
- string reg2 = lines[instr].ToCharArray()[0].ToString();
- reg2 += lines[instr].ToCharArray()[1].ToString();
- if (lines[instr].ToCharArray()[2].ToString() != ",")
- reg2 += lines[instr].ToCharArray()[2].ToString();
- output += reg2 + " / ";
- lines[instr] = lines[instr].Replace(reg2 + ", ", "");
- string val = lines[instr];
- output += val + ");\n";
- }
- #endregion
- #region PPC:li
- if (lines[instr].StartsWith("li ")) // # Load Immediate
- {
- lines[instr] = lines[instr].Replace("li ", "");
- string reg = lines[instr].ToCharArray()[0].ToString();
- reg += lines[instr].ToCharArray()[1].ToString();
- if (lines[instr].ToCharArray()[2].ToString() != ",")
- reg += lines[instr].ToCharArray()[2].ToString();
- output += reg + " = ";
- lines[instr] = lines[instr].Replace(reg + ", ", "");
- string val = lines[instr];
- output += val + ";\n";
- }
- #endregion
- #region PPC:lis
- if (lines[instr].StartsWith("lis ")) // # Load Immediate Shifted
- {
- lines[instr] = lines[instr].Replace("lis ", "");
- string reg = lines[instr].ToCharArray()[0].ToString();
- reg += lines[instr].ToCharArray()[1].ToString();
- if (lines[instr].ToCharArray()[2].ToString() != ",")
- reg += lines[instr].ToCharArray()[2].ToString();
- output += reg + " = (";
- lines[instr] = lines[instr].Replace(reg + ", ", "");
- string val = lines[instr];
- output += val + " << 16);\n";
- }
- #endregion
- #region PPC:mr
- if (lines[instr].StartsWith("mr ")) // # Move Register
- {
- lines[instr] = lines[instr].Replace("mr ", "");
- string reg = lines[instr].ToCharArray()[0].ToString();
- reg += lines[instr].ToCharArray()[1].ToString();
- if (lines[instr].ToCharArray()[2].ToString() != ",")
- reg += lines[instr].ToCharArray()[2].ToString();
- output += reg + " = ";
- lines[instr] = lines[instr].Replace(reg + ", ", "");
- string val = lines[instr];
- output += val + ";\n";
- }
- #endregion
- #region PPC:mulli
- if (lines[instr].StartsWith("mulli ")) // # Multiply Immediate
- {
- lines[instr] = lines[instr].Replace("mulli ", "");
- string reg = lines[instr].ToCharArray()[0].ToString();
- reg += lines[instr].ToCharArray()[1].ToString();
- if (lines[instr].ToCharArray()[2].ToString() != ",")
- reg += lines[instr].ToCharArray()[2].ToString();
- output += reg + " = (";
- lines[instr] = lines[instr].Replace(reg + ", ", "");
- string reg2 = lines[instr].ToCharArray()[0].ToString();
- reg2 += lines[instr].ToCharArray()[1].ToString();
- if (lines[instr].ToCharArray()[2].ToString() != ",")
- reg2 += lines[instr].ToCharArray()[2].ToString();
- output += reg2 + " * ";
- lines[instr] = lines[instr].Replace(reg2 + ", ", "");
- string val = lines[instr];
- output += val + ");\n";
- }
- #endregion
- #region PPC:mullw
- if (lines[instr].StartsWith("mullw ")) // # Multiply Word
- {
- lines[instr] = lines[instr].Replace("mullw ", "");
- string reg = lines[instr].ToCharArray()[0].ToString();
- reg += lines[instr].ToCharArray()[1].ToString();
- if (lines[instr].ToCharArray()[2].ToString() != ",")
- reg += lines[instr].ToCharArray()[2].ToString();
- output += reg + " = (";
- lines[instr] = lines[instr].Replace(reg + ", ", "");
- string reg2 = lines[instr].ToCharArray()[0].ToString();
- reg2 += lines[instr].ToCharArray()[1].ToString();
- if (lines[instr].ToCharArray()[2].ToString() != ",")
- reg2 += lines[instr].ToCharArray()[2].ToString();
- output += reg2 + " * ";
- lines[instr] = lines[instr].Replace(reg2 + ", ", "");
- string val = lines[instr];
- output += val + ");\n";
- }
- #endregion
- #region PPC:or
- if (lines[instr].StartsWith("or "))
- {
- lines[instr] = lines[instr].Replace("or ", "");
- string reg = lines[instr].ToCharArray()[0].ToString();
- reg += lines[instr].ToCharArray()[1].ToString();
- if (lines[instr].ToCharArray()[2].ToString() != ",")
- reg += lines[instr].ToCharArray()[2].ToString();
- output += reg + " |= ";
- lines[instr] = lines[instr].Replace(reg + ", ", "");
- string val = lines[instr];
- output += val + ";\n";
- }
- #endregion
- #region PPC:ori
- if (lines[instr].StartsWith("ori "))
- {
- lines[instr] = lines[instr].Replace("ori ", "");
- string reg = lines[instr].ToCharArray()[0].ToString();
- reg += lines[instr].ToCharArray()[1].ToString();
- if (lines[instr].ToCharArray()[2].ToString() != ",")
- reg += lines[instr].ToCharArray()[2].ToString();
- output += reg + " |= ";
- lines[instr] = lines[instr].Replace(reg + ", ", "");
- string val = lines[instr];
- output += val + ";\n";
- }
- #endregion
- #region PPC:oris
- if (lines[instr].StartsWith("oris "))
- {
- lines[instr] = lines[instr].Replace("oris ", "");
- string reg = lines[instr].ToCharArray()[0].ToString();
- reg += lines[instr].ToCharArray()[1].ToString();
- if (lines[instr].ToCharArray()[2].ToString() != ",")
- reg += lines[instr].ToCharArray()[2].ToString();
- output += reg + " |= (";
- lines[instr] = lines[instr].Replace(reg + ", ", "");
- string val = lines[instr];
- output += val + " << 16);\n";
- }
- #endregion
- #region PPC:slw
- if (lines[instr].StartsWith("slw ")) // # Shift Left Word
- {
- lines[instr] = lines[instr].Replace("slw ", "");
- string reg = lines[instr].ToCharArray()[0].ToString();
- reg += lines[instr].ToCharArray()[1].ToString();
- if (lines[instr].ToCharArray()[2].ToString() != ",")
- reg += lines[instr].ToCharArray()[2].ToString();
- output += reg + " = (";
- lines[instr] = lines[instr].Replace(reg + ", ", "");
- string reg2 = lines[instr].ToCharArray()[0].ToString();
- reg2 += lines[instr].ToCharArray()[1].ToString();
- if (lines[instr].ToCharArray()[2].ToString() != ",")
- reg2 += lines[instr].ToCharArray()[2].ToString();
- output += reg2 + " << ";
- lines[instr] = lines[instr].Replace(reg2 + ", ", "");
- string val = lines[instr];
- output += val + ");\n";
- }
- #endregion
- #region PPC:slwi
- if (lines[instr].StartsWith("slwi ")) // # Shift Left Word Immediate
- {
- lines[instr] = lines[instr].Replace("slwi ", "");
- string reg = lines[instr].ToCharArray()[0].ToString();
- reg += lines[instr].ToCharArray()[1].ToString();
- if (lines[instr].ToCharArray()[2].ToString() != ",")
- reg += lines[instr].ToCharArray()[2].ToString();
- output += reg + " = (";
- lines[instr] = lines[instr].Replace(reg + ", ", "");
- string reg2 = lines[instr].ToCharArray()[0].ToString();
- reg2 += lines[instr].ToCharArray()[1].ToString();
- if (lines[instr].ToCharArray()[2].ToString() != ",")
- reg2 += lines[instr].ToCharArray()[2].ToString();
- output += reg2 + " << ";
- lines[instr] = lines[instr].Replace(reg2 + ", ", "");
- string val = lines[instr];
- output += val + ");\n";
- }
- #endregion
- #region PPC:srw
- if (lines[instr].StartsWith("srw ")) // # Shift Right Word Immediate
- {
- lines[instr] = lines[instr].Replace("srw ", "");
- string reg = lines[instr].ToCharArray()[0].ToString();
- reg += lines[instr].ToCharArray()[1].ToString();
- if (lines[instr].ToCharArray()[2].ToString() != ",")
- reg += lines[instr].ToCharArray()[2].ToString();
- output += reg + " = (";
- lines[instr] = lines[instr].Replace(reg + ", ", "");
- string reg2 = lines[instr].ToCharArray()[0].ToString();
- reg2 += lines[instr].ToCharArray()[1].ToString();
- if (lines[instr].ToCharArray()[2].ToString() != ",")
- reg2 += lines[instr].ToCharArray()[2].ToString();
- output += reg2 + " >> ";
- lines[instr] = lines[instr].Replace(reg2 + ", ", "");
- string val = lines[instr];
- output += val + ");\n";
- }
- #endregion
- #region PPC:srwi
- if (lines[instr].StartsWith("srwi ")) // # Shift Right Word Immediate
- {
- lines[instr] = lines[instr].Replace("srwi ", "");
- string reg = lines[instr].ToCharArray()[0].ToString();
- reg += lines[instr].ToCharArray()[1].ToString();
- if (lines[instr].ToCharArray()[2].ToString() != ",")
- reg += lines[instr].ToCharArray()[2].ToString();
- output += reg + " = (";
- lines[instr] = lines[instr].Replace(reg + ", ", "");
- string reg2 = lines[instr].ToCharArray()[0].ToString();
- reg2 += lines[instr].ToCharArray()[1].ToString();
- if (lines[instr].ToCharArray()[2].ToString() != ",")
- reg2 += lines[instr].ToCharArray()[2].ToString();
- output += reg2 + " >> ";
- lines[instr] = lines[instr].Replace(reg2 + ", ", "");
- string val = lines[instr];
- output += val + ");\n";
- }
- #endregion
- #region PPC:subf
- if (lines[instr].StartsWith("subf ")) // # Subtract
- {
- lines[instr] = lines[instr].Replace("subf ", "");
- string reg = lines[instr].ToCharArray()[0].ToString();
- reg += lines[instr].ToCharArray()[1].ToString();
- if (lines[instr].ToCharArray()[2].ToString() != ",")
- reg += lines[instr].ToCharArray()[2].ToString();
- output += reg + " = (";
- lines[instr] = lines[instr].Replace(reg + ", ", "");
- string reg2 = lines[instr].ToCharArray()[0].ToString();
- reg2 += lines[instr].ToCharArray()[1].ToString();
- if (lines[instr].ToCharArray()[2].ToString() != ",")
- reg2 += lines[instr].ToCharArray()[2].ToString();
- lines[instr] = lines[instr].Replace(reg2 + ", ", "");
- string val = lines[instr];
- output += val + " - " + reg2 + ");\n";
- }
- #endregion
- #region PPC:subi
- if (lines[instr].StartsWith("subi ")) // # Subtract Immediate
- {
- lines[instr] = lines[instr].Replace("subi ", "");
- string reg = lines[instr].ToCharArray()[0].ToString();
- reg += lines[instr].ToCharArray()[1].ToString();
- if (lines[instr].ToCharArray()[2].ToString() != ",")
- reg += lines[instr].ToCharArray()[2].ToString();
- output += reg + " = (";
- lines[instr] = lines[instr].Replace(reg + ", ", "");
- string reg2 = lines[instr].ToCharArray()[0].ToString();
- reg2 += lines[instr].ToCharArray()[1].ToString();
- if (lines[instr].ToCharArray()[2].ToString() != ",")
- reg2 += lines[instr].ToCharArray()[2].ToString();
- output += reg2 + " - ";
- lines[instr] = lines[instr].Replace(reg2 + ", ", "");
- string val = lines[instr];
- output += val + ");\n";
- }
- #endregion
- #region PPC:xor
- if (lines[instr].StartsWith("xor "))
- {
- lines[instr] = lines[instr].Replace("xor ", "");
- string reg = lines[instr].ToCharArray()[0].ToString();
- reg += lines[instr].ToCharArray()[1].ToString();
- if (lines[instr].ToCharArray()[2].ToString() != ",")
- reg += lines[instr].ToCharArray()[2].ToString();
- output += reg + " ^= ";
- lines[instr] = lines[instr].Replace(reg + ", ", "");
- string val = lines[instr];
- output += val + ";\n";
- }
- #endregion
- #region PPC:xori
- if (lines[instr].StartsWith("xori "))
- {
- lines[instr] = lines[instr].Replace("xori ", "");
- string reg = lines[instr].ToCharArray()[0].ToString();
- reg += lines[instr].ToCharArray()[1].ToString();
- if (lines[instr].ToCharArray()[2].ToString() != ",")
- reg += lines[instr].ToCharArray()[2].ToString();
- output += reg + " ^= ";
- lines[instr] = lines[instr].Replace(reg + ", ", "");
- string val = lines[instr];
- output += val + ";\n";
- }
- #endregion
- #region PPC:xoris
- if (lines[instr].StartsWith("xoris "))
- {
- lines[instr] = lines[instr].Replace("xoris ", "");
- string reg = lines[instr].ToCharArray()[0].ToString();
- reg += lines[instr].ToCharArray()[1].ToString();
- if (lines[instr].ToCharArray()[2].ToString() != ",")
- reg += lines[instr].ToCharArray()[2].ToString();
- output += reg + " ^= (";
- lines[instr] = lines[instr].Replace(reg + ", ", "");
- string val = lines[instr];
- output += val + " << 16);\n";
- }
- #endregion
- instr++;
- }
- catch (Exception ex)
- {
- MessageBox.Show("Could not convert instruction! :/\n\n" + ex);
- }
- }
- codebox_c.Text = output;
- }
- }
- }
- // ------------------------------------------------------------------------------------------------------- [Project] PPC2C ------------------------------------------------------------------------------------------------------- //
- //Credits: XeClutch - https://pastebin.com/r1Hptrbm#
- //BaSs_HaXoR
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement