Advertisement
IAmXeClutch

[Project] PPC2C2

Mar 26th, 2015
1,518
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 28.35 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.IO;
  7. using System.Linq;
  8. using System.Text;
  9. using System.Threading.Tasks;
  10. using System.Windows.Forms;
  11.  
  12. // Made by XeClutch
  13. //
  14. // Got a question? Contact me on 7S or Twitter
  15.  
  16. namespace PPC2C_v2
  17. {
  18.     public partial class MainForm : Form
  19.     {
  20.         private string ProcessInstruction(string instruction)
  21.         {
  22.             string str = "";
  23.             #region PPC:add
  24.             if (instruction.StartsWith("add "))
  25.             {
  26.                 instruction = instruction.Replace("add ", "");
  27.                 string[] operands = instruction.Replace(" ", "").Split(",".ToCharArray());
  28.                 if (operands[0] != operands[1])
  29.                     str = string.Format("{0} = {1} + {2};", operands[0], operands[1], operands[2]);
  30.                 else
  31.                     str = string.Format("{0} += {1};", operands[1], operands[2]);
  32.             }
  33.             #endregion
  34.             #region PPC:addi
  35.             else if (instruction.StartsWith("addi "))
  36.             {
  37.                 instruction = instruction.Replace("addi ", "");
  38.                 string[] operands = instruction.Replace(" ", "").Split(",".ToCharArray());
  39.                 if (operands[0] != operands[1])
  40.                     str = string.Format("{0} = {1} + {2};", operands[0], operands[1], operands[2]);
  41.                 else
  42.                     str = string.Format("{0} += {1};", operands[1], operands[2]);
  43.             }
  44.             #endregion
  45.             #region PPC:and
  46.             else if (instruction.StartsWith("and "))
  47.             {
  48.                 instruction = instruction.Replace("and ", "");
  49.                 string[] operands = instruction.Replace(" ", "").Split(",".ToCharArray());
  50.                 if (operands[0] != operands[1])
  51.                     str = string.Format("{0} = {1} & {2};", operands[0], operands[1], operands[2]);
  52.                 else
  53.                     str = string.Format("{0} &= {1};", operands[1], operands[2]);
  54.             }
  55.             #endregion
  56.             #region PPC:andi
  57.             else if (instruction.StartsWith("andi "))
  58.             {
  59.                 instruction = instruction.Replace("andi ", "");
  60.                 string[] operands = instruction.Replace(" ", "").Split(",".ToCharArray());
  61.                 if (operands[0] != operands[1])
  62.                     str = string.Format("{0} = {1} & {2};", operands[0], operands[1], operands[2]);
  63.                 else
  64.                     str = string.Format("{0} &= {1};", operands[1], operands[2]);
  65.             }
  66.             #endregion
  67.             #region PPC:andis
  68.             else if (instruction.StartsWith("andis "))
  69.             {
  70.                 instruction = instruction.Replace("andis ", "");
  71.                 string[] operands = instruction.Replace(" ", "").Split(",".ToCharArray());
  72.                 if (operands[0] != operands[1])
  73.                     str = string.Format("{0} = ({1} & {2}) << 16;", operands[0], operands[1], operands[2]);
  74.                 else
  75.                     str = string.Format("{0} &= {1} << 16;", operands[1], operands[2]);
  76.             }
  77.             #endregion
  78.             #region PPC:beq
  79.             else if (instruction.StartsWith("beq "))
  80.             {
  81.                 instruction = instruction.Replace("beq ", "");
  82.                 string[] operands = instruction.Replace(" ", "").Split(",".ToCharArray());
  83.                 str = string.Format("if ({0} == 4) {1};", operands[0], operands[1].StartsWith("sub") ? (operands[1] + "()") : ("goto " + operands[1]));
  84.             }
  85.             #endregion
  86.             #region PPC:bgt
  87.             else if (instruction.StartsWith("bgt "))
  88.             {
  89.                 instruction = instruction.Replace("bgt ", "");
  90.                 string[] operands = instruction.Replace(" ", "").Split(",".ToCharArray());
  91.                 str = string.Format("if ({0} == 2) {1};", operands[0], operands[1].StartsWith("sub") ? (operands[1] + "()") : ("goto " + operands[1]));
  92.             }
  93.             #endregion
  94.             #region PPC:bl
  95.             else if (instruction.StartsWith("bl "))
  96.             {
  97.                 instruction = instruction.Replace("bl ", "");
  98.                 string[] operands = instruction.Replace(" ", "").Split(",".ToCharArray());
  99.                 str = string.Format("{0};", operands[0].StartsWith("sub") ? (operands[0] + "()") : ("goto " + operands[0]));
  100.             }
  101.             #endregion
  102.             #region PPC:blr
  103.             else if (instruction.StartsWith("blr "))
  104.                 str = "return;";
  105.             #endregion
  106.             #region PPC:blt
  107.             else if (instruction.StartsWith("blt "))
  108.             {
  109.                 instruction = instruction.Replace("blt ", "");
  110.                 string[] operands = instruction.Replace(" ", "").Split(",".ToCharArray());
  111.                 str = string.Format("if ({0} == 1) {1};", operands[0], operands[1].StartsWith("sub") ? (operands[1] + "()") : ("goto " + operands[1]));
  112.             }
  113.             #endregion
  114.             #region PPC:bne
  115.             else if (instruction.StartsWith("bne "))
  116.             {
  117.                 instruction = instruction.Replace("bne ", "");
  118.                 string[] operands = instruction.Replace(" ", "").Split(",".ToCharArray());
  119.                 str = string.Format("if ({0} != 4) {1};", operands[0], operands[1].StartsWith("sub") ? (operands[1] + "()") : ("goto " + operands[1]));
  120.             }
  121.             #endregion
  122.             #region PPC:divw
  123.             else if (instruction.StartsWith("divw "))
  124.             {
  125.                 instruction = instruction.Replace("divw ", "");
  126.                 string[] operands = instruction.Replace(" ", "").Split(",".ToCharArray());
  127.                 if (operands[0] != operands[1])
  128.                     str = string.Format("{0} = {1} / {2};", operands[0], operands[1], operands[2]);
  129.                 else
  130.                     str = string.Format("{0} /= {1};", operands[1], operands[2]);
  131.             }
  132.             #endregion
  133.             #region PPC:eqv
  134.             else if (instruction.StartsWith("eqv "))
  135.             {
  136.                 instruction = instruction.Replace("eqv ", "");
  137.                 string[] operands = instruction.Replace(" ", "").Split(",".ToCharArray());
  138.                 if (operands[0] != operands[1])
  139.                     str = string.Format("{0} = {1} ^ {2};", operands[0], operands[1], operands[2]);
  140.                 else
  141.                     str = string.Format("{0} ^= {1};", operands[1], operands[2]);
  142.             }
  143.             #endregion
  144.             #region PPC:lbz
  145.             else if (instruction.StartsWith("lbz "))
  146.             {
  147.                 instruction = instruction.Replace("lbz ", "");
  148.                 string[] operands = instruction.Replace(" ", "").Split(",".ToCharArray());
  149.                 str = string.Format("{0} = *(byte*)({1} + {2});", operands[0], operands[1].Split("(".ToCharArray())[0], operands[1].Split("(".ToCharArray())[1].Replace(")", ""));
  150.             }
  151.             #endregion
  152.             #region PPC:lbzu
  153.             else if (instruction.StartsWith("lbzu "))
  154.             {
  155.                 instruction = instruction.Replace("lbzu ", "");
  156.                 string[] operands = instruction.Replace(" ", "").Split(",".ToCharArray());
  157.                 str = string.Format("{0} = *(byte*)({1} = ({2} + {3}));", operands[0], operands[1].Split("(".ToCharArray())[0], operands[1].Split("(".ToCharArray())[0], operands[1].Split("(".ToCharArray())[1].Replace(")", ""));
  158.             }
  159.             #endregion
  160.             #region PPC:lhz
  161.             else if (instruction.StartsWith("lhz "))
  162.             {
  163.                 instruction = instruction.Replace("lhz ", "");
  164.                 string[] operands = instruction.Replace(" ", "").Split(",".ToCharArray());
  165.                 str = string.Format("{0} = *(word*)({1} + {2});", operands[0], operands[1].Split("(".ToCharArray())[0], operands[1].Split("(".ToCharArray())[1].Replace(")", ""));
  166.             }
  167.             #endregion
  168.             #region PPC:lhzu
  169.             else if (instruction.StartsWith("lhzu "))
  170.             {
  171.                 instruction = instruction.Replace("lhzu ", "");
  172.                 string[] operands = instruction.Replace(" ", "").Split(",".ToCharArray());
  173.                 str = string.Format("{0} = *(word*)({1} = ({2} + {3}));", operands[0], operands[1].Split("(".ToCharArray())[0], operands[1].Split("(".ToCharArray())[0], operands[1].Split("(".ToCharArray())[1].Replace(")", ""));
  174.             }
  175.             #endregion
  176.             #region PPC:li
  177.             else if (instruction.StartsWith("li "))
  178.             {
  179.                 instruction = instruction.Replace("li ", "");
  180.                 string[] operands = instruction.Replace(" ", "").Split(",".ToCharArray());
  181.                 str = string.Format("{0} = {1};", operands[0], operands[1]);
  182.             }
  183.             #endregion
  184.             #region PPC:lis
  185.             else if (instruction.StartsWith("lis "))
  186.             {
  187.                 instruction = instruction.Replace("lis ", "");
  188.                 string[] operands = instruction.Replace(" ", "").Split(",".ToCharArray());
  189.                 str = string.Format("{0} = {1} << 16;", operands[0], operands[1]);
  190.             }
  191.             #endregion
  192.             #region PPC:lwz
  193.             else if (instruction.StartsWith("lwz "))
  194.             {
  195.                 instruction = instruction.Replace("lwz ", "");
  196.                 string[] operands = instruction.Replace(" ", "").Split(",".ToCharArray());
  197.                 str = string.Format("{0} = *(dword*)({1} + {2});", operands[0], operands[1].Split("(".ToCharArray())[0], operands[1].Split("(".ToCharArray())[1].Replace(")", ""));
  198.             }
  199.             #endregion
  200.             #region PPC:lwzu
  201.             else if (instruction.StartsWith("lwzu "))
  202.             {
  203.                 instruction = instruction.Replace("lwzu ", "");
  204.                 string[] operands = instruction.Replace(" ", "").Split(",".ToCharArray());
  205.                 str = string.Format("{0} = *(dword*)({1} = ({2} + {3}));", operands[0], operands[1].Split("(".ToCharArray())[0], operands[1].Split("(".ToCharArray())[0], operands[1].Split("(".ToCharArray())[1].Replace(")", ""));
  206.             }
  207.             #endregion
  208.             #region PPC:mfcr
  209.             else if (instruction.StartsWith("mfcr "))
  210.             {
  211.                 instruction = instruction.Replace("mfcr ", "");
  212.                 string[] operands = instruction.Replace(" ", "").Split(",".ToCharArray());
  213.                 str = string.Format("{0} = CR;", operands[0]);
  214.             }
  215.             #endregion
  216.             #region PPC:mr
  217.             else if (instruction.StartsWith("mr "))
  218.             {
  219.                 instruction = instruction.Replace("mr ", "");
  220.                 string[] operands = instruction.Replace(" ", "").Split(",".ToCharArray());
  221.                 str = string.Format("{0} = {1};", operands[0], operands[1]);
  222.             }
  223.             #endregion
  224.             #region PPC:mulli
  225.             else if (instruction.StartsWith("mulli "))
  226.             {
  227.                 instruction = instruction.Replace("mulli ", "");
  228.                 string[] operands = instruction.Replace(" ", "").Split(",".ToCharArray());
  229.                 if (operands[0] != operands[1])
  230.                     str = string.Format("{0} = {1} * {2};", operands[0], operands[1], operands[2]);
  231.                 else
  232.                     str = string.Format("{0} *= {1};", operands[1], operands[2]);
  233.             }
  234.             #endregion
  235.             #region PPC:mullw
  236.             else if (instruction.StartsWith("mullw "))
  237.             {
  238.                 instruction = instruction.Replace("mullw ", "");
  239.                 string[] operands = instruction.Replace(" ", "").Split(",".ToCharArray());
  240.                 if (operands[0] != operands[1])
  241.                     str = string.Format("{0} = {1} * {2};", operands[0], operands[1], operands[2]);
  242.                 else
  243.                     str = string.Format("{0} *= {1};", operands[1], operands[2]);
  244.             }
  245.             #endregion
  246.             #region PPC:or
  247.             else if (instruction.StartsWith("or "))
  248.             {
  249.                 instruction = instruction.Replace("or ", "");
  250.                 string[] operands = instruction.Replace(" ", "").Split(",".ToCharArray());
  251.                 if (operands[0] != operands[1])
  252.                     str = string.Format("{0} = {1} | {2};", operands[0], operands[1], operands[2]);
  253.                 else
  254.                     str = string.Format("{0} |= {1};", operands[1], operands[2]);
  255.             }
  256.             #endregion
  257.             #region PPC:ori
  258.             else if (instruction.StartsWith("ori "))
  259.             {
  260.                 instruction = instruction.Replace("ori ", "");
  261.                 string[] operands = instruction.Replace(" ", "").Split(",".ToCharArray());
  262.                 if (operands[0] != operands[1])
  263.                     str = string.Format("{0} = {1} | {2};", operands[0], operands[1], operands[2]);
  264.                 else
  265.                     str = string.Format("{0} |= {1};", operands[1], operands[2]);
  266.             }
  267.             #endregion
  268.             #region PPC:oris
  269.             else if (instruction.StartsWith("oris "))
  270.             {
  271.                 instruction = instruction.Replace("oris ", "");
  272.                 string[] operands = instruction.Replace(" ", "").Split(",".ToCharArray());
  273.                 if (operands[0] != operands[1])
  274.                     str = string.Format("{0} = ({1} | {2}) << 16;", operands[0], operands[1], operands[2]);
  275.                 else
  276.                     str = string.Format("{0} |= {1} << 16;", operands[1], operands[2]);
  277.             }
  278.             #endregion
  279.             #region PPC:slw
  280.             else if (instruction.StartsWith("slw "))
  281.             {
  282.                 instruction = instruction.Replace("slw ", "");
  283.                 string[] operands = instruction.Replace(" ", "").Split(",".ToCharArray());
  284.                 if (operands[0] != operands[1])
  285.                     str = string.Format("{0} = {1} << {2}", operands[0], operands[1], operands[2]);
  286.                 else
  287.                     str = string.Format("{0} <<= {1}", operands[1], operands[2]);
  288.             }
  289.             #endregion
  290.             #region PPC:slwi
  291.             else if (instruction.StartsWith("slwi "))
  292.             {
  293.                 instruction = instruction.Replace("slwi ", "");
  294.                 string[] operands = instruction.Replace(" ", "").Split(",".ToCharArray());
  295.                 if (operands[0] != operands[1])
  296.                     str = string.Format("{0} = {1} << {2}", operands[0], operands[1], operands[2]);
  297.                 else
  298.                     str = string.Format("{0} <<= {1}", operands[1], operands[2]);
  299.             }
  300.             #endregion
  301.             #region PPC:srw
  302.             else if (instruction.StartsWith("srw "))
  303.             {
  304.                 instruction = instruction.Replace("srw ", "");
  305.                 string[] operands = instruction.Replace(" ", "").Split(",".ToCharArray());
  306.                 if (operands[0] != operands[1])
  307.                     str = string.Format("{0} = {1} >> {2}", operands[0], operands[1], operands[2]);
  308.                 else
  309.                     str = string.Format("{0} >>= {1}", operands[1], operands[2]);
  310.             }
  311.             #endregion
  312.             #region PPC:srwi
  313.             else if (instruction.StartsWith("srwi "))
  314.             {
  315.                 instruction = instruction.Replace("srwi ", "");
  316.                 string[] operands = instruction.Replace(" ", "").Split(",".ToCharArray());
  317.                 if (operands[0] != operands[1])
  318.                     str = string.Format("{0} = {1} >> {2}", operands[0], operands[1], operands[2]);
  319.                 else
  320.                     str = string.Format("{0} >>= {1}", operands[1], operands[2]);
  321.             }
  322.             #endregion
  323.             #region PPC:stb
  324.             else if (instruction.StartsWith("stb "))
  325.             {
  326.                 instruction = instruction.Replace("stb ", "");
  327.                 string[] operands = instruction.Replace(" ", "").Split(",".ToCharArray());
  328.                 str = string.Format("*(byte*)({0} + {1}) = (byte){2};", operands[1].Split("(".ToCharArray())[0], operands[1].Split("(".ToCharArray())[1].Replace(")", ""), operands[0]);
  329.             }
  330.             #endregion
  331.             #region PPC:stbu
  332.             else if (instruction.StartsWith("stbu "))
  333.             {
  334.                 instruction = instruction.Replace("stbu ", "");
  335.                 string[] operands = instruction.Replace(" ", "").Split(",".ToCharArray());
  336.                 str = string.Format("*(byte*)({0} = ({1} + {2})) = (byte){3};", operands[1].Split("(".ToCharArray())[0], operands[1].Split("(".ToCharArray())[0], operands[1].Split("(".ToCharArray())[1].Replace(")", ""), operands[0]);
  337.             }
  338.             #endregion
  339.             #region PPC:sth
  340.             else if (instruction.StartsWith("sth "))
  341.             {
  342.                 instruction = instruction.Replace("sth ", "");
  343.                 string[] operands = instruction.Replace(" ", "").Split(",".ToCharArray());
  344.                 str = string.Format("*(word*)({0} + {1}) = (word){2};", operands[1].Split("(".ToCharArray())[0], operands[1].Split("(".ToCharArray())[1].Replace(")", ""), operands[0]);
  345.             }
  346.             #endregion
  347.             #region PPC:sthu
  348.             else if (instruction.StartsWith("sthu "))
  349.             {
  350.                 instruction = instruction.Replace("sthu ", "");
  351.                 string[] operands = instruction.Replace(" ", "").Split(",".ToCharArray());
  352.                 str = string.Format("*(byte*)({0} = ({1} + {2})) = (byte){3};", operands[1].Split("(".ToCharArray())[0], operands[1].Split("(".ToCharArray())[0], operands[1].Split("(".ToCharArray())[1].Replace(")", ""), operands[0]);
  353.             }
  354.             #endregion
  355.             #region PPC:stw
  356.             else if (instruction.StartsWith("stw "))
  357.             {
  358.                 instruction = instruction.Replace("stw ", "");
  359.                 string[] operands = instruction.Replace(" ", "").Split(",".ToCharArray());
  360.                 str = string.Format("*(dword*)({0} + {1}) = (dword){2};", operands[1].Split("(".ToCharArray())[0], operands[1].Split("(".ToCharArray())[1].Replace(")", ""), operands[0]);
  361.             }
  362.             #endregion
  363.             #region PPC:stwu
  364.             else if (instruction.StartsWith("stwu "))
  365.             {
  366.                 instruction = instruction.Replace("stwu ", "");
  367.                 string[] operands = instruction.Replace(" ", "").Split(",".ToCharArray());
  368.                 str = string.Format("*(byte*)({0} = ({1} + {2})) = (byte){3};", operands[1].Split("(".ToCharArray())[0], operands[1].Split("(".ToCharArray())[0], operands[1].Split("(".ToCharArray())[1].Replace(")", ""), operands[0]);
  369.             }
  370.             #endregion
  371.             #region PPC:subf
  372.             else if (instruction.StartsWith("subf "))
  373.             {
  374.                 instruction = instruction.Replace("subf ", "");
  375.                 string[] operands = instruction.Replace(" ", "").Split(",".ToCharArray());
  376.                 if (operands[0] != operands[1])
  377.                     str = string.Format("{0} = {1} - {2};", operands[0], operands[1], operands[2]);
  378.                 else
  379.                     str = string.Format("{0} -= {1};", operands[1], operands[2]);
  380.             }
  381.             #endregion
  382.             #region PPC:subi
  383.             else if (instruction.StartsWith("subi "))
  384.             {
  385.                 instruction = instruction.Replace("subi ", "");
  386.                 string[] operands = instruction.Replace(" ", "").Split(",".ToCharArray());
  387.                 if (operands[0] != operands[1])
  388.                     str = string.Format("{0} = {1} - {2};", operands[0], operands[1], operands[2]);
  389.                 else
  390.                     str = string.Format("{0} -= {1};", operands[1], operands[2]);
  391.             }
  392.             #endregion
  393.             #region PPC:xor
  394.             else if (instruction.StartsWith("xor "))
  395.             {
  396.                 instruction = instruction.Replace("xor ", "");
  397.                 string[] operands = instruction.Replace(" ", "").Split(",".ToCharArray());
  398.                 if (operands[0] != operands[1])
  399.                     str = string.Format("{0} = {1} ^ {2};", operands[0], operands[1], operands[2]);
  400.                 else
  401.                     str = string.Format("{0} ^= {1};", operands[1], operands[2]);
  402.             }
  403.             #endregion
  404.             #region PPC:xori
  405.             else if (instruction.StartsWith("xori "))
  406.             {
  407.                 instruction = instruction.Replace("xori ", "");
  408.                 string[] operands = instruction.Replace(" ", "").Split(",".ToCharArray());
  409.                 if (operands[0] != operands[1])
  410.                     str = string.Format("{0} = {1} ^ {2};", operands[0], operands[1], operands[2]);
  411.                 else
  412.                     str = string.Format("{0} ^= {1};", operands[1], operands[2]);
  413.             }
  414.             #endregion
  415.             #region PPC:xoris
  416.             else if (instruction.StartsWith("xoris "))
  417.             {
  418.                 instruction = instruction.Replace("xoris ", "");
  419.                 string[] operands = instruction.Replace(" ", "").Split(",".ToCharArray());
  420.                 if (operands[0] != operands[1])
  421.                     str = string.Format("{0} = ({1} ^ {2}) << 16;", operands[0], operands[1], operands[2]);
  422.                 else
  423.                     str = string.Format("{0} ^= {1} << 16;", operands[1], operands[2]);
  424.             }
  425.             #endregion
  426.             #region PPC:?
  427.             else if (instruction != "")
  428.                 str = "//" + instruction.Replace("#", "");
  429.             #endregion
  430.             #region PPC:#
  431.             str = str.Replace("#", "//");
  432.             #endregion
  433.             return str + "\n";
  434.         }
  435.  
  436.         public MainForm()
  437.         {
  438.             InitializeComponent();
  439.             MinimumSize = new Size(663, 483);
  440.             MaximumSize = new Size(663, 800);
  441.  
  442.             /// Format PPC code box
  443.             // Comments
  444.             richTextBox1.Settings.Comment = "#";
  445.             richTextBox1.Settings.CommentColor = Color.Green;
  446.             richTextBox1.Settings.EnableComments = true;
  447.             // Integers
  448.             richTextBox1.Settings.IntegerColor = Color.Orange;
  449.             richTextBox1.Settings.EnableIntegers = true;
  450.             // Strings
  451.             richTextBox1.Settings.StringColor = Color.Red;
  452.             richTextBox1.Settings.EnableStrings = true;
  453.             // Keywords
  454.             richTextBox1.Settings.Keywords.Add("add");
  455.             richTextBox1.Settings.Keywords.Add("addi");
  456.             richTextBox1.Settings.Keywords.Add("addis");
  457.             richTextBox1.Settings.Keywords.Add("and");
  458.             richTextBox1.Settings.Keywords.Add("andi");
  459.             richTextBox1.Settings.Keywords.Add("andis");
  460.             richTextBox1.Settings.Keywords.Add("beq");
  461.             richTextBox1.Settings.Keywords.Add("bgt");
  462.             richTextBox1.Settings.Keywords.Add("bl");
  463.             richTextBox1.Settings.Keywords.Add("blr");
  464.             richTextBox1.Settings.Keywords.Add("blt");
  465.             richTextBox1.Settings.Keywords.Add("bne");
  466.             richTextBox1.Settings.Keywords.Add("divw");
  467.             richTextBox1.Settings.Keywords.Add("eqv");
  468.             richTextBox1.Settings.Keywords.Add("lbz");
  469.             richTextBox1.Settings.Keywords.Add("lbzu");
  470.             richTextBox1.Settings.Keywords.Add("lhz");
  471.             richTextBox1.Settings.Keywords.Add("lhzu");
  472.             richTextBox1.Settings.Keywords.Add("li");
  473.             richTextBox1.Settings.Keywords.Add("lis");
  474.             richTextBox1.Settings.Keywords.Add("lwz");
  475.             richTextBox1.Settings.Keywords.Add("lwzu");
  476.             richTextBox1.Settings.Keywords.Add("mfcr");
  477.             richTextBox1.Settings.Keywords.Add("mulli");
  478.             richTextBox1.Settings.Keywords.Add("mullw");
  479.             richTextBox1.Settings.Keywords.Add("mr");
  480.             richTextBox1.Settings.Keywords.Add("or");
  481.             richTextBox1.Settings.Keywords.Add("ori");
  482.             richTextBox1.Settings.Keywords.Add("oris");
  483.             richTextBox1.Settings.Keywords.Add("slw");
  484.             richTextBox1.Settings.Keywords.Add("slwi");
  485.             richTextBox1.Settings.Keywords.Add("srw");
  486.             richTextBox1.Settings.Keywords.Add("srwi");
  487.             richTextBox1.Settings.Keywords.Add("stb");
  488.             richTextBox1.Settings.Keywords.Add("stbu");
  489.             richTextBox1.Settings.Keywords.Add("sth");
  490.             richTextBox1.Settings.Keywords.Add("sthu");
  491.             richTextBox1.Settings.Keywords.Add("stw");
  492.             richTextBox1.Settings.Keywords.Add("stwu");
  493.             richTextBox1.Settings.Keywords.Add("subf");
  494.             richTextBox1.Settings.Keywords.Add("subi");
  495.             richTextBox1.Settings.Keywords.Add("xor");
  496.             richTextBox1.Settings.Keywords.Add("xori");
  497.             richTextBox1.Settings.Keywords.Add("xoris");
  498.             richTextBox1.Settings.KeywordColor = Color.Blue;
  499.             richTextBox1.CompileKeywords();
  500.  
  501.             /// Format C code box
  502.             // Comments
  503.             richTextBox2.Settings.Comment = "//";
  504.             richTextBox2.Settings.CommentColor = Color.Green;
  505.             richTextBox2.Settings.EnableComments = true;
  506.             // Integers
  507.             richTextBox2.Settings.IntegerColor = Color.Orange;
  508.             richTextBox2.Settings.EnableIntegers = true;
  509.             // Strings
  510.             richTextBox2.Settings.StringColor = Color.Red;
  511.             richTextBox2.Settings.EnableStrings = true;
  512.             // Keywords
  513.             richTextBox2.Settings.Keywords.Add("byte");
  514.             richTextBox2.Settings.Keywords.Add("dword");
  515.             richTextBox2.Settings.Keywords.Add("if");
  516.             richTextBox2.Settings.Keywords.Add("goto");
  517.             richTextBox2.Settings.Keywords.Add("word");
  518.             richTextBox2.Settings.Keywords.Add(">>");
  519.             richTextBox2.Settings.Keywords.Add("<<");
  520.             richTextBox2.Settings.Keywords.Add("=");
  521.             richTextBox2.Settings.Keywords.Add("|");
  522.             richTextBox2.Settings.Keywords.Add("&");
  523.             richTextBox2.Settings.Keywords.Add("!");
  524.             richTextBox2.Settings.Keywords.Add("^");
  525.             richTextBox2.Settings.Keywords.Add("~");
  526.             richTextBox2.Settings.KeywordColor = Color.Blue;
  527.             richTextBox2.CompileKeywords();
  528.         }
  529.  
  530.         private void openPPCFileToolStripMenuItem_Click(object sender, EventArgs e)
  531.         {
  532.             OpenFileDialog ofd = new OpenFileDialog();
  533.             ofd.Title = "Load a file containing PowerPC instructions..";
  534.             ofd.Filter = "PPC File (*.ppc)|*.ppc";
  535.             if (ofd.ShowDialog() == DialogResult.OK)
  536.             {
  537.                 richTextBox1.Text = "";
  538.                 string[] lines = File.ReadAllLines(ofd.FileName);
  539.                 for (int i = 0; i < lines.Count(); i++)
  540.                     richTextBox1.Text += lines[i] + "\n";
  541.                 richTextBox1.ProcessAllLines();
  542.             }
  543.         }
  544.  
  545.         private void saveCFileToolStripMenuItem_Click(object sender, EventArgs e)
  546.         {
  547.             SaveFileDialog sfd = new SaveFileDialog();
  548.             sfd.Title = "Create a new file that will contain C code..";
  549.             sfd.Filter = "C File (*.c)|*.c";
  550.             if (sfd.ShowDialog() == DialogResult.OK)
  551.                 File.WriteAllText(sfd.FileName, richTextBox2.Text.Replace("\n", Environment.NewLine));
  552.         }
  553.  
  554.         private void aboutToolStripMenuItem_Click(object sender, EventArgs e)
  555.         {
  556.             new AboutForm().ShowDialog();
  557.         }
  558.  
  559.         private void convert_Click(object sender, EventArgs e)
  560.         {
  561.             if (richTextBox1.Text == "")
  562.                 return;
  563.             richTextBox2.Text = "// Converted using PPC2C2 by XeClutch\n";
  564.             string[] lines = richTextBox1.Text.Split("\n".ToCharArray());
  565.  
  566.             foreach (string line in lines)
  567.                 richTextBox2.Text += ProcessInstruction(line);
  568.             richTextBox2.Text = richTextBox2.Text.TrimEnd("\n".ToCharArray());
  569.             richTextBox1.ProcessAllLines();
  570.             richTextBox2.ProcessAllLines();
  571.         }
  572.  
  573.         private void richTextBox1_TextChanged(object sender, EventArgs e)
  574.         {
  575.             richTextBox1.ProcessAllLines();
  576.         }
  577.  
  578.         private void richTextBox2_TextChanged(object sender, EventArgs e)
  579.         {
  580.             richTextBox2.ProcessAllLines();
  581.         }
  582.     }
  583. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement