Click here to Skip to main content
15,885,906 members
Articles / Containers / Virtual Machine

Twiggery Scripting Language

Rate me:
Please Sign up or sign in to vote.
4.82/5 (14 votes)
12 Aug 2010LGPL313 min read 63.7K   1.1K   36  
Twiggery Scripting Language
using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;
using AddressingMode = System.Int32;

namespace Twiggery
{
    /// <summary>
    /// ASM infomation display control
    /// </summary>
    public class TwiggeryAsmBox : ListView
    {
        /// <summary>
        /// TVM object
        /// </summary>
        private TVM tvm = null;

        /// <summary>
        /// ASM constructor
        /// </summary>
        public TwiggeryAsmBox()
        {
            Initialize();
            FullRowSelect = true;
        }

        /// <summary>
        /// ASM constructor
        /// </summary>
        /// <param name="vm">TVM object</param>
        public TwiggeryAsmBox(ref TVM vm)
        {
            tvm = vm;
            Initialize();
            FullRowSelect = true;
        }

        /// <summary>
        /// Initialization
        /// </summary>
        /// <param name="vm">TVM object</param>
        public void Initialize(ref TVM vm)
        {
            tvm = vm;
            try
            {
                base.Items.Clear();
                AddressingMode am = TVM.AM_NIL;
                AddressingMode am1 = TVM.AM_NIL;
                AddressingMode am2 = TVM.AM_NIL;
                for (int i = 0; i < tvm.AsmCount; i++)
                {
                    ListViewItem lvi = new ListViewItem();
                    lvi.SubItems.Clear();
                    lvi.SubItems[0].Text = i.ToString();
                    lvi.SubItems.Add(tvm[i].GetType().Name);
                    if (tvm[i].GetType() == typeof(TVM.LAM))
                    {
                        am = (AddressingMode)tvm[i].Operand[0];
                        am1 = TVM.DepartAddressingMode(am, 1);
                        am2 = TVM.DepartAddressingMode(am, 0);

                        lvi.SubItems.Add("0x" + String.Format("{0:X8}", (int)tvm[i].Operand[0]));
                    }
                    else if (tvm[i].GetType() == typeof(TVM.CALL) ||
                        tvm[i].GetType() == typeof(TVM.ARG))
                    {
                        lvi.SubItems.Add(tvm[i].Operand[0].ToString());
                        lvi.SubItems.Add(tvm[i].Operand[1].ToString());
                    }
                    else if (tvm[i].GetType() == typeof(TVM.JMP) ||
                            tvm[i].GetType() == typeof(TVM.JT) ||
                            tvm[i].GetType() == typeof(TVM.JF)||
                            tvm[i].GetType() == typeof(TVM.HAL))
                    {
                        lvi.SubItems.Add(tvm[i].Operand[0].ToString());
                    }
                    else if (tvm[i].Operand != null)
                    {
                        if (tvm[i].Operand.Length >= 1)
                        {
                            string operand = null;
                            switch (am1)
                            {
                                case TVM.AM_RAM:
                                    operand = "[" + tvm[i].Operand[0].ToString() + "]";
                                    break;
                                case TVM.AM_STK:
                                    operand = "[#]";
                                    break;
                                case TVM.AM_IMD:
                                    operand = tvm[i].Operand[0].ToString();
                                    break;
                            }
                            lvi.SubItems.Add(operand);
                        }
                        if (tvm[i].Operand.Length >= 2)
                        {
                            string operand = null;
                            switch (am2)
                            {
                                case TVM.AM_RAM:
                                    operand = "[" + tvm[i].Operand[1].ToString() + "]";
                                    break;
                                case TVM.AM_STK:
                                    operand = "[#]";
                                    break;
                                case TVM.AM_IMD:
                                    operand = tvm[i].Operand[1].ToString();
                                    break;
                            }
                            lvi.SubItems.Add(operand);
                        }
                    }
                    base.Items.Add(lvi);
                }
            }
            catch
            {
            }
        }

        /// <summary>
        /// Initialization
        /// </summary>
        public void Initialize()
        {
            ColumnHeader ch1 = new ColumnHeader();
            ch1.DisplayIndex = 0;
            ch1.Text = "ADD";
            ch1.Width = 50;

            ColumnHeader ch2 = new ColumnHeader();
            ch2.DisplayIndex = 1;
            ch2.Text = "ASM";
            ch2.Width = 50;

            ColumnHeader ch3 = new ColumnHeader();
            ch3.DisplayIndex = 2;
            ch3.Text = "OP1";
            ch3.Width = 90;

            ColumnHeader ch4 = new ColumnHeader();
            ch4.DisplayIndex = 3;
            ch4.Text = "OP2";
            ch4.Width = 60;

            base.Columns.AddRange(new ColumnHeader[] { ch1, ch2, ch3, ch4 });
        }
    }
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The GNU Lesser General Public License (LGPLv3)


Written By
Architect
China China
Video game player & creator; Hardware geek & maker.

Comments and Discussions