Exemple #1
0
        public AddBook()
        {
            InitializeComponent();
            String judul, penulis, penerbit, terbit, PPN, DIS, POK;
            Double harga, ppn, diskon, pokok;

            judul    = Tjudul.Text;
            penulis  = Tpenulis.Text;
            penerbit = Tpenerbit.Text;
            terbit   = Tterbit.Text;
            PPN      = Tppn.Text;
            DIS      = Tdiskon.Text;
            POK      = Tpokok.Text;
            ppn      = 0;
            diskon   = 0;
            pokok    = 0;
            if (!PPN.Equals(""))
            {
                ppn = double.Parse(PPN);
            }
            if (!DIS.Equals(""))
            {
                diskon = double.Parse(DIS);
            }
            if (!POK.Equals(""))
            {
                pokok = double.Parse(POK);
            }
        }
Exemple #2
0
    void OnGUI()
    {
        if (conf == null)
        {
            conf = Memory.LoadConfig();
            if (conf == null)
            {
                Memory.SaveConfig(new VSPConfig());
                conf = Memory.LoadConfig();
            }
            if (conf.VSPath != null)
            {
                VSPath = conf.VSPath;
                if (conf.VS_Version == "")
                {
                    conf.VS_Version = LBA.checkVSROM(VSPath);
                    Memory.SaveConfig(conf);
                }
            }
        }

        GUILayout.Label("Vagrant Story Path", EditorStyles.boldLabel);
        GUILayoutOption[] options = { GUILayout.Width(300), GUILayout.MaxWidth(400) };
        VSPath = EditorGUILayout.TextField("Vagrant Story CD path :", VSPath, options);

        GUILayoutOption[] options2 = { GUILayout.MaxWidth(30) };
        bool VSPathTrigger         = GUILayout.Button(new GUIContent("..."), options2);

        if (VSPathTrigger)
        {
            string path = EditorUtility.OpenFolderPanel("Path to Vagrant Story CD", "", "");
            VSPath = path + "/";
        }

        GUILayoutOption[] options3 = { GUILayout.Width(200), GUILayout.MaxWidth(400) };
        bool VSSaveTrigger         = GUILayout.Button(new GUIContent("Save Path"), options3);

        if (VSSaveTrigger)
        {
            conf.VSPath     = VSPath;
            conf.VS_Version = LBA.checkVSROM(VSPath);
            Memory.SaveConfig(conf);
        }

        GUILayout.Label("Vagrant Story Version : " + conf.VS_Version);
        GUILayout.Space(10f);

        GUILayout.Label("| One File import", EditorStyles.boldLabel);
        FilePath = EditorGUILayout.TextField("File path (VS Path relativ) :", FilePath, options);
        bool filePathTrigger = GUILayout.Button(new GUIContent("..."), options2);

        if (filePathTrigger)
        {
            string path = EditorUtility.OpenFilePanel("Path to File", VSPath, "");
            FilePath = path.Replace(VSPath, "");
        }
        bool fileLoadTrigger = GUILayout.Button(new GUIContent("Load"), options3);

        if (fileLoadTrigger && VSPath != "" && FilePath != "")
        {
            string[] hash     = FilePath.Split("/"[0]);
            string[] h2       = hash[hash.Length - 1].Split("."[0]);
            string   folder   = hash[0];
            string   fileName = h2[0];
            string   ext      = h2[1];


            switch (folder)
            {
            case "BATTLE":
                // BATTLE.PRG
                // BOG.DAT
                // INITBTL.PRG
                // SYSTEM.DAT
                switch (ext)
                {
                case "PRG":
                    PRG parser = new PRG();
                    parser.Parse(VSPath + FilePath);
                    break;
                }
                break;

            case "BG":
                // 001OP01A.FAR & TIM
                // 002OP01A.FAR & TIM
                // 007OP01A.FAR & TIM
                // 008OP01A.FAR & TIM
                break;

            case "EFFECT":
                // EFFPURGE.BIN maybe the PLG for E000.P
                // E*.P
                // E*.FBC
                // E*.FBT
                // PLG*.BIN lot of empty
                switch (ext)
                {
                case "P":
                    EFFECT effect = new EFFECT(VSPath + FilePath);
                    break;
                }
                break;

            case "ENDING":
                // ENDING.PRG
                // ENDING.XA
                // ILLUST06.BIN -> ILLUST16.BIN
                // NULL.DAT
                switch (ext)
                {
                case "BIN":
                    TIM parser = new TIM();
                    parser.ParseIllust(VSPath + FilePath);
                    break;
                }
                break;

            case "EVENT":
                // ****.EVT
                ParseEVT(VSPath + FilePath, true);
                break;

            case "MAP":
                // MAP***.MPD
                // Z***U**.ZUD
                // ZONE***.ZND
                switch (ext)
                {
                case "MPD":
                    ParseMPD(VSPath + FilePath, true);
                    break;

                case "ZUD":
                    ParseZUD(VSPath + FilePath, fileName, true);
                    break;

                case "ZND":
                    ParseZND(VSPath + FilePath, true);
                    break;
                }
                break;

            case "MENU":
                break;

            case "MOV":
                break;

            case "MUSIC":
                ParseAKAO(VSPath + FilePath, AKAO.MUSIC, true);
                break;

            case "OBJ":
                // **.SHP
                // **.SEQ
                // **.WEP
                switch (ext)
                {
                case "SHP":
                    ParseSHP(VSPath + FilePath, fileName, true, true);
                    break;

                case "WEP":
                    ParseWEP(VSPath + FilePath, true);
                    break;
                }
                break;

            case "SOUND":
                ParseAKAO(VSPath + FilePath, AKAO.SOUND, true);
                break;
            }
        }



        GUILayout.Label("| Batch imports", EditorStyles.boldLabel);
        GUILayout.BeginVertical();
        GUILayout.Label("3D Model Formats : ");
        bool LoadARMTrigger = GUILayout.Button(new GUIContent("Load MiniMaps.ARM"));

        if (LoadARMTrigger && VSPath != "")
        {
            string[] files       = Directory.GetFiles(VSPath + "SMALL/", "*.ARM");
            float    fileToParse = files.Length;
            float    fileParsed  = 0;
            foreach (string file in files)
            {
                string[] h        = file.Split("/"[0]);
                string   filename = h[h.Length - 1];
                EditorUtility.DisplayProgressBar("VS Parsing", "Parsing : " + filename + ", " + fileParsed + " files parsed.", (fileParsed / fileToParse));
                ARM parser = new ARM();
                //parser.UseDebug = true;
                parser.Parse(file);
                parser.BuildPrefab(true);
                fileParsed++;
            }
            EditorUtility.ClearProgressBar();
        }

        bool LoadWEPTrigger = GUILayout.Button(new GUIContent("Load Weapons.WEP"));

        if (LoadWEPTrigger && VSPath != "")
        {
            BuildDatabase();
            string[] files       = Directory.GetFiles(VSPath + "OBJ/", "*.WEP");
            float    fileToParse = files.Length;
            float    fileParsed  = 0f;

            foreach (string file in files)
            {
                string[] h        = file.Split("/"[0]);
                string   filename = h[h.Length - 1];
                EditorUtility.DisplayProgressBar("VS Parsing", "Parsing : " + filename + ", " + fileParsed + " files parsed.", (fileParsed / fileToParse));
                ParseWEP(file, true);
                fileParsed++;
            }
            EditorUtility.ClearProgressBar();
        }

        bool LoadSHPTrigger = GUILayout.Button(new GUIContent("Load 3D Models.SHP"));

        if (LoadSHPTrigger && VSPath != "")
        {
            string[] files       = Directory.GetFiles(VSPath + "OBJ/", "*.SHP");
            float    fileToParse = files.Length;
            float    fileParsed  = 0f;

            foreach (string file in files)
            {
                string[] h        = file.Split("/"[0]);
                string   filename = h[h.Length - 1];
                EditorUtility.DisplayProgressBar("VS Parsing", "Parsing : " + filename + ", " + fileParsed + " files parsed.", (fileParsed / fileToParse));
                ParseSHP(file, filename, false);
                fileParsed++;
            }
            EditorUtility.ClearProgressBar();
        }

        bool LoadZUDTrigger = GUILayout.Button(new GUIContent("Load Zones Units Datas.ZUD"));

        if (LoadZUDTrigger && VSPath != "")
        {
            string[] files       = Directory.GetFiles(VSPath + "MAP/", "*.ZUD");
            float    fileToParse = files.Length;
            float    fileParsed  = 0f;
            foreach (string file in files)
            {
                string[] h        = file.Split("/"[0]);
                string   filename = h[h.Length - 1];
                EditorUtility.DisplayProgressBar("VS Parsing", "Parsing : " + filename + ", " + fileParsed + " files parsed.", (fileParsed / fileToParse));
                ParseZUD(file, filename, false);
                fileParsed++;
            }
            EditorUtility.ClearProgressBar();
        }

        bool LoadMPDTrigger = GUILayout.Button(new GUIContent("Load Map Datas.MPD"));

        if (LoadMPDTrigger && VSPath != "")
        {
            string[] files       = Directory.GetFiles(VSPath + "MAP/", "*.MPD");
            float    fileToParse = files.Length;
            float    fileParsed  = 0f;

            foreach (string file in files)
            {
                string[] h        = file.Split("/"[0]);
                string   filename = h[h.Length - 1];
                EditorUtility.DisplayProgressBar("VS Parsing", "Parsing : " + filename + ", " + fileParsed + " files parsed.", (fileParsed / fileToParse));
                ParseMPD(file, false);
                fileParsed++;
            }
            EditorUtility.ClearProgressBar();
        }

        bool LoadEFFECTTrigger = GUILayout.Button(new GUIContent("Load EFFECT/E0*.P, E0*.FBC, E0*.FBT (Only Texture right now)"));

        if (LoadEFFECTTrigger && VSPath != "")
        {
            string[] files       = Directory.GetFiles(VSPath + "EFFECT/", "*.P");
            float    fileToParse = files.Length;

            float fileParsed = 0;
            foreach (string file in files)
            {
                string[] h        = file.Split("/"[0]);
                string   filename = h[h.Length - 1];
                EditorUtility.DisplayProgressBar("VS Parsing", "Parsing : " + filename + ", " + fileParsed + " files parsed.", (fileParsed / fileToParse));
                EFFECT effect = new EFFECT(file);
                fileParsed++;
            }


            //EFFECT effect = new EFFECT(VSPath + "EFFECT/E008.P");

            EditorUtility.ClearProgressBar();
        }
        GUILayout.EndVertical();

        GUILayout.BeginVertical();
        GUILayout.Label("Texture Formats : ");

        bool LoadGIMTrigger = GUILayout.Button(new GUIContent("Load GIM/*.GIM"));

        if (LoadGIMTrigger && VSPath != "")
        {
            string[] files       = Directory.GetFiles(VSPath + "GIM/", "*.GIM");
            float    fileToParse = files.Length;

            float fileParsed = 0;
            foreach (string file in files)
            {
                string[] h        = file.Split("/"[0]);
                string   filename = h[h.Length - 1];
                EditorUtility.DisplayProgressBar("VS Parsing", "Parsing : " + filename + ", " + fileParsed + " files parsed.", (fileParsed / fileToParse));
                GIM gim = new GIM(file);
                fileParsed++;
            }


            EditorUtility.ClearProgressBar();
        }

        bool LoadMENUBGTrigger = GUILayout.Button(new GUIContent("Load MENU/*BG.BIN"));

        if (LoadMENUBGTrigger && VSPath != "")
        {
            string[] files       = new string[] { VSPath + "MENU/MAPBG.BIN", VSPath + "MENU/MENUBG.BIN" };
            float    fileToParse = files.Length;

            float fileParsed = 0;
            foreach (string file in files)
            {
                string[] h        = file.Split("/"[0]);
                string   filename = h[h.Length - 1];
                EditorUtility.DisplayProgressBar("VS Parsing", "Parsing : " + filename + ", " + fileParsed + " files parsed.", (fileParsed / fileToParse));
                TIM bg = new TIM();
                bg.ParseBG(file);
                fileParsed++;
            }


            EditorUtility.ClearProgressBar();
        }

        bool LoadDISTrigger = GUILayout.Button(new GUIContent("Load SMALL/*.DIS"));

        if (LoadDISTrigger && VSPath != "")
        {
            string[] files       = Directory.GetFiles(VSPath + "SMALL/", "*.DIS");
            float    fileToParse = files.Length;

            float fileParsed = 0;
            foreach (string file in files)
            {
                string[] h        = file.Split("/"[0]);
                string   filename = h[h.Length - 1];
                EditorUtility.DisplayProgressBar("VS Parsing", "Parsing : " + filename + ", " + fileParsed + " files parsed.", (fileParsed / fileToParse));
                DIS dis = new DIS();
                dis.Parse(file);
                fileParsed++;
            }


            EditorUtility.ClearProgressBar();
        }

        bool LoadTIMTrigger = GUILayout.Button(new GUIContent("BG/*.TIM"));

        if (LoadTIMTrigger && VSPath != "")
        {
            string[] files       = Directory.GetFiles(VSPath + "BG/", "*.TIM");
            float    fileToParse = files.Length;

            float fileParsed = 0;
            foreach (string file in files)
            {
                string[] h        = file.Split("/"[0]);
                string   filename = h[h.Length - 1];
                EditorUtility.DisplayProgressBar("VS Parsing", "Parsing : " + filename + ", " + fileParsed + " files parsed.", (fileParsed / fileToParse));
                TIM parser = new TIM();
                parser.Parse(file);
                fileParsed++;
            }


            EditorUtility.ClearProgressBar();
        }

        bool LoadILLUSTTrigger = GUILayout.Button(new GUIContent("ENDING/ILLUST*.BIN (Not Working Yet)"));

        if (LoadILLUSTTrigger && VSPath != "")
        {
            // not working yet
            string[] files       = Directory.GetFiles(VSPath + "ENDING/", "*.BIN");
            float    fileToParse = files.Length;

            float fileParsed = 0;
            foreach (string file in files)
            {
                string[] h        = file.Split("/"[0]);
                string   filename = h[h.Length - 1];
                EditorUtility.DisplayProgressBar("VS Parsing", "Parsing : " + filename + ", " + fileParsed + " files parsed.", (fileParsed / fileToParse));
                TIM parser = new TIM();
                parser.ParseIllust(file);
                fileParsed++;
            }


            EditorUtility.ClearProgressBar();
        }
        GUILayout.EndVertical();


        GUILayout.BeginVertical();
        GUILayout.Label("Audio Formats : ");

        /*
         * bool LoadAKAOTrigger = GUILayout.Button(new GUIContent("Load Akao SOUND/WAVE*.DAT"));
         * if (LoadAKAOTrigger && VSPath != "")
         * {
         *  string[] files = Directory.GetFiles(VSPath + "SOUND/", "*.DAT");
         *  float fileToParse = files.Length;
         *  float fileParsed = 0;
         *  foreach (string file in files)
         *  {
         *      string[] h = file.Split("/"[0]);
         *      string filename = h[h.Length - 1];
         *      EditorUtility.DisplayProgressBar("VS Parsing", "Parsing : " + filename + ", " + fileParsed + " files parsed.", (fileParsed / fileToParse));
         *      AKAO parser = new AKAO();
         *      parser.UseDebug = true;
         *      parser.Parse(file, AKAO.SOUND);
         *      fileParsed++;
         *  }
         *
         *  EditorUtility.ClearProgressBar();
         * }
         */

        midTrigger = GUILayout.Toggle(midTrigger, new GUIContent("output a MIDI file ?"));
        sf2Trigger = GUILayout.Toggle(sf2Trigger, new GUIContent("output a SF2 (soundfont) file ?"));
        dlsTrigger = GUILayout.Toggle(dlsTrigger, new GUIContent("output a DLS (soundfont) file ? (Not working well yet)"));
        wavTrigger = GUILayout.Toggle(wavTrigger, new GUIContent("output a WAV file ? ( /_!_\\ heavy files)"));
        bool LoadAKAO2Trigger = GUILayout.Button(new GUIContent("Load Akao MUSIC/MUSIC*.DAT"));

        if (LoadAKAO2Trigger && VSPath != "")
        {
            string[] files       = Directory.GetFiles(VSPath + "MUSIC/", "*.DAT");
            float    fileToParse = files.Length;

            float fileParsed = 0;
            foreach (string file in files)
            {
                string[] h        = file.Split("/"[0]);
                string   filename = h[h.Length - 1];
                EditorUtility.DisplayProgressBar("VS Parsing", "Parsing : " + filename + ", " + fileParsed + " files parsed.", (fileParsed / fileToParse));
                ParseAKAO(file, AKAO.MUSIC, false);
                fileParsed++;
            }
            EditorUtility.ClearProgressBar();
        }
        GUILayout.EndVertical();

        GUILayout.BeginVertical();
        GUILayout.Label("Data Formats : ");
        bool LoadSYDTrigger = GUILayout.Button(new GUIContent("Load MENU DataBase.SYD"));

        if (LoadSYDTrigger && VSPath != "")
        {
            BuildDatabase();
        }

        bool LoadITEMTrigger = GUILayout.Button(new GUIContent("Load MENU ITEM*.BIN"));

        if (LoadITEMTrigger && VSPath != "")
        {
            BIN itemDB = new BIN();
            itemDB.BuildItems(VSPath + "MENU/ITEMNAME.BIN", VSPath + "MENU/ITEMHELP.BIN");
        }

        bool LoadEVENTTrigger = GUILayout.Button(new GUIContent("Load EVENT/*.EVT"));

        if (LoadEVENTTrigger && VSPath != "")
        {
            string[] files       = Directory.GetFiles(VSPath + "EVENT/", "*.EVT");
            float    fileToParse = files.Length;

            float fileParsed = 0;
            foreach (string file in files)
            {
                string[] h        = file.Split("/"[0]);
                string   filename = h[h.Length - 1];
                EditorUtility.DisplayProgressBar("VS Parsing", "Parsing : " + filename + ", " + fileParsed + " files parsed.", (fileParsed / fileToParse));

                ParseEVT(file, false);
                fileParsed++;
            }


            EditorUtility.ClearProgressBar();
        }

        bool LoadHFTrigger = GUILayout.Button(new GUIContent("Load InGame Help SMALL/*.HF"));

        if (LoadHFTrigger && VSPath != "")
        {
            string[] files       = Directory.GetFiles(VSPath + "SMALL/", "*.HF0");
            float    fileToParse = files.Length;

            float fileParsed = 0;
            foreach (string file in files)
            {
                string[] h        = file.Split("/"[0]);
                string   filename = h[h.Length - 1];
                EditorUtility.DisplayProgressBar("VS Parsing", "Parsing : " + filename + ", " + fileParsed + " files parsed.", (fileParsed / fileToParse));
                HF0 parser = new HF0();
                parser.Parse(file);
                fileParsed++;
            }


            EditorUtility.ClearProgressBar();
        }
        GUILayout.EndVertical();


        bool LoadEXPLOTrigger = GUILayout.Button(new GUIContent("Explore..."));

        if (LoadEXPLOTrigger && VSPath != "")
        {
            //BIN parser = new BIN();
            //parser.Explore(VSPath + "SLES_027.55"); // spell and skills
            // "BATTLE/INITBTL.PRG" // Fandango
            //parser.Explore(VSPath + "BATTLE/BOG.DAT");

            /*
             * string[] files = Directory.GetFiles(VSPath + "MENU/", "*.PRG");
             * ToolBox.FeedDatabases(files);
             */
            BIN parser = new BIN();
            parser.Explore(VSPath + "SLES_027.55"); // spell and skills
            //PRG parser = new PRG();
            //parser.Parse(VSPath + "TITLE/TITLE.PRG"); // spell and skills
            //parser.Parse(VSPath + "ENDING/ENDING.PRG");
            //parser.Parse(VSPath + "BATTLE/BATTLE.PRG");
            //parser.Parse(VSPath + "BATTLE/INITBTL.PRG");
        }
    }
        ///* disassembly */

        static int disop(DISTATE sp, DIS dp)
        {
            int tmp;
            int w;
            int err;

            StringBuilder opndbuf = new StringBuilder();
            StringBuilder commbuf = new StringBuilder();

            var opnd = opndbuf;

            int inst = dp.data[0];

            dp.flags = sp.flags;
            sp.flags = 0;

            switch (dp.opcode.type)
            {
                case itype.TYPE_A:
                    dp.i = (Reg)(0xF & inst);
                    dp.j = (Reg)(0xF & (inst >> 4));
                    break;
                case itype.TYPE_B:
                    dp.i = (Reg)(0xF & inst);
                    dp.x = (ulong)(0xFF & (inst >> 4));
                    dp.w = 8;
                    break;
                case itype.TYPE_C:
                    dp.i = (Reg)(0xF & inst);
                    dp.x = (ulong)(0xF & (inst >> 4));
                    dp.w = 4;
                    break;
                case itype.TYPE_D:
                    dp.x = (ulong)(0xFF & inst);
                    dp.w = 8;
                    break;
                case itype.TYPE_E:
                    dp.i = (Reg)(0xF & inst);
                    break;
                case itype.TYPE_F:
                    dp.x = (ulong)(0x7FF & inst);
                    dp.w = 11;
                    break;
                case itype.TYPE_Z:
                    dp.j = (Reg)(0xF & (inst >> 4));
                    break;
                case itype.TYPE_W:
                    dp.x = (ulong)(inst);
                    dp.w = 16;
                    break;
            }

            foreach (char s in dp.opcode.format)
            {
                switch (s)
                {
                    case '#':
                        opnd.Append(fmt.imm);
                        break;
                    case '&':
                        opnd.Append(fmt.and);
                        break;
                    case '(':
                        opnd.Append(fmt.par);
                        break;
                    case ')':
                        opnd.Append(fmt.ens);
                        break;
                    case '+':
                        opnd.Append(fmt.inc);
                        break;
                    case ',':
                        opnd.Append(fmt.nxt);
                        break;
                    case '-':
                        opnd.Append(fmt.dec);
                        break;
                    case ';':
                        opnd = commbuf;
                        break;
                    case '@':
                        opnd.Append(fmt.mem);
                        break;
                    case '2':
                        dp.x <<= 1;
                        dp.w += 1;
                        break;
                    case '4':
                        dp.x <<= 2;
                        dp.w += 2;
                        break;
                    case 'A':
                        opnd.Append(Reg.AC);
                        break;
                    case 'C':
                        opnd.Append(Reg.CCR);
                        break;
                    case 'F':
                        opnd.Append(Reg.FP);
                        break;
                    case 'J':
                        if (sp.IsValid(dp.j))
                        {
                            dp.x = sp.reg[(int)dp.j];
                            dp.w = 32;
                        }
                        else
                        {
                            dp.x = 0;
                            dp.w = 0;
                        }
                        break;
                    case 'I':
                        if (sp.IsValid(dp.i))
                        {
                            dp.x = sp.reg[(int)dp.i];
                            dp.w = 32;
                        }
                        else
                        {
                            dp.x = 0;
                            dp.w = 0;
                        }
                        break;
                    case 'M':
                        opnd.Append(Reg.ILM);
                        break;
                    case 'P':
                        opnd.Append(Reg.PS);
                        break;
                    case 'S':
                        opnd.Append(Reg.SP);
                        break;
                    case 'X':
                        /* constant extension word */
                        if ((err = getword(dp)) != 0)
                            return err;
                        dp.x = ((ulong)(dp.x << 16)) + ((ulong)dp.data[dp.n - 1]);
                        dp.w += 16;
                        break;
                    case 'Y':
                        /* coprocessor extension word */
                        if ((err = getword(dp)) != 0)
                            return err;
                        tmp = dp.data[dp.n - 1];
                        dp.x = (ulong)dp.i;
                        dp.w = 4;
                        dp.c = 0xFF & (tmp >> 8);
                        dp.j = (Reg)(0x0F & (tmp >> 4));
                        dp.i = (Reg)(0x0F & (tmp));
                        break;
                    case 'a':
                        w = dp.w;
                        while (w >= 8)
                        {
                            w -= 8;

                            opnd.Append(Asc((int)(dp.x >> w)));
                        }
                        break;
                    case 'b':
                        /* shift2 */
                        dp.x += 16;
                        dp.w += 1;
                        break;
                    case 'c':
                        /* coprocessor operation */
                        opnd.AppendFormat(fmt.u[8], dp.c);
                        break;
                    case 'd':
                        /* unsigned decimal */
                        opnd.AppendFormat(fmt.ud, dp.x);
                        break;
                    case 'f':
                        w = dp.w >> 1;
                        
                        tmp = (int)(((1ul << w) - 1) & (dp.x >> w));
                        int tmq = (int)(((1ul << w) - 1) & dp.x);
                        if (tmq != 0)
                            opnd.AppendFormat("{0:g}", ((double)tmp) / ((double)tmq));
                        else
                            opnd.Append("NaN");

                            break;
                    case 'g':
                        dp.i += SPECIALS;
                        goto case 'i';
                    case 'h':
                        dp.j += SPECIALS;
                        goto case 'j';
                    case 'i':
                        opnd.Append((Reg)dp.i);
                        break;
                    case 'j':
                        opnd.Append((Reg)dp.j);
                        break;
                    case 'k':
                        dp.i += COPROCESSOR;
                        goto case 'i';
                    case 'l':
                        dp.j += COPROCESSOR;
                        goto case 'j';
                    case 'n':
                        /* negative constant */
                        opnd.AppendFormat(fmt.u[dp.w + 1], dp.x);
                        //TODO opnd.AppendFormat(fmt.n[dp.w + 1], ((1ul << (dp.w + 1)) - 1) & NEG(dp.w, (1ul << dp.w) | dp.x));
                        break;
                    case 'p':
                        /* pair */
                        w = dp.w >> 1;
                        opnd.AppendFormat(fmt.u[w], ((1ul << w) - 1) & (dp.x >> w));
                        opnd.Append(fmt.nxt);
                        opnd.AppendFormat(fmt.u[w], ((1ul << w) - 1) & dp.x);
                        break;
                    case 'q':
                        /* rational */
                        w = dp.w >> 1;
                        opnd.AppendFormat(fmt.ud, ((1ul << w) - 1) & (dp.x >> w));
                        opnd.Append("/");
                        opnd.AppendFormat(fmt.ud, ((1ul << w) - 1) & dp.x);
                        break;
                    case 'r':
                        /* relative */
                        dp.x = (ulong)((long)dp.pc + 2 + SignExtend(dp.w, (int)dp.x));
                        dp.w = 32;
                        break;
                    case 's':
                        /* signed constant */
                        if (IsNeg(dp.w, dp.x))
                        {
                            if ((opt_outflag & OutOpt.OF_CSTYLE) != 0 && (opnd[-1] == '+'))
                                opnd.Remove(opnd.Length - 1, 1);
                            opnd.AppendFormat(fmt.n[dp.w], NEG(dp.w, (long)dp.x));
                        }
                        else
                        {
                            opnd.AppendFormat(fmt.u[dp.w - 1], dp.x);
                        }
                        break;
                    case 'u':
                        /* unsigned constant */
                        opnd.AppendFormat(fmt.u[dp.w], dp.x);
                        break;
                    case 'v':
                        /* vector */
                        opnd.AppendFormat(fmt.u[8], 0xFF - (0xFF & ((dp.pc - dp.memrange.start) / 4)));
                        break;
                    case 'x':
                        dp.x |= 0x100;
                        break;
                    case 'y':
                        dp.c += 8;
                        goto case 'z'; /*FALLTHROUGH*/
                    case 'z':
                        /* register list */
                        opnd.Append(fmt.par);
                        bool first = true;
                        for (int i = 0; i < 8; ++i)
                        {
                            if ((dp.x & (uint)(1 << i)) != 0)
                            {
                                if (first)
                                    first = false;
                                else
                                    opnd.Append(",");
                                if ((dp.x & 0x100) != 0)
                                    opnd.Append((Reg)(dp.c + 7 - i));
                                else
                                    opnd.Append((Reg)(dp.c + i));

                            }
                        }
                        opnd.Append(fmt.ens);
                        break;
                    default:
                        opnd.Append(s);
                        break;
                }
            }



            Reg r = Reg.NOREG;
            DF dflags = 0;
            foreach (var s in dp.opcode.action)
            {
                switch (s)
                {
                    case '!':
                        /* jump */
                        dflags |= DF.FLOW | DF.BREAK | DF.BRANCH;
                        break;
                    case '?':
                        /* branch */
                        dflags |= DF.FLOW | DF.BRANCH;
                        break;
                    case '(':
                        /* call */
                        dflags |= DF.FLOW | DF.CALL;
                        //Debug.WriteLine("CALL {0:X8} {1:x8}", dp.x, dp.pc);
                        break;
                    case ')':
                        /* return */
                        dflags |= DF.FLOW | DF.BREAK | DF.CALL;
                        break;
                    case '_':
                        /* delay */
                        dflags |= DF.DELAY;
                        break;
                    case 'A':
                        r = Reg.AC;
                        break;
                    case 'C':
                        r = Reg.CCR;
                        break;
                    case 'F':
                        r = Reg.FP;
                        break;
                    case 'P':
                        r = Reg.PS;
                        break;
                    case 'S':
                        r = Reg.SP;
                        break;
                    case 'i':
                        r = dp.i;
                        break;
                    case 'j':
                        r = dp.j;
                        break;
                    case 'w':
                        sp.SetInvalid(r);
                        break;
                    case 'v':
                        if (sp.OkReg(r))
                        {
                            sp.SetValid(r);
                            sp.reg[(int)r] = dp.x;
                        }
                        break;
                    case 'x':
                        r = Reg.NOREG;
                        break;
                    default:
                        Error("bad action '{0}'", s);
                        break;
                }
            }

            dp.flags |= dflags & DF.TO_KEEP;
            sp.flags |= dflags & DF.TO_COPY;
            if ((dflags & DF.DELAY) != 0)
                sp.flags |= dflags & DF.TO_DELAY;
            else
                dp.flags |= dflags & DF.TO_DELAY;

            /*XXX*/
            dp.opnds = opndbuf.ToString();
            if (commbuf.Length >0 && dp.memrange.data.mem == MemType.MEMTYPE_UNKNOWN)
            {
                //opnd = commbuf;
                for (int i = 0; i < dp.n; ++i)
                {
                    commbuf.Append(Asc(dp.data[i] >> 8));
                    commbuf.Append(Asc(dp.data[i]));
                }
            }
            dp.comment = commbuf.ToString();
            dp.writedis(outfp);


            return dp.n << 1;
        }
        static int getword(DIS dp) // this should be in the filemap class.
        {
            int a = infp.ReadByte();
            int b = infp.ReadByte();
            if (a < 0 || b < 0)
            {
                //TOOO
                //if (feof(infp))
                //    return -1;
                //return -(errno + 1);
            }

            dp.data[dp.n++] = opt_little ? (b << 8) | a : (a << 8) | b;
            return 0;
        }
        static int disdata(DISTATE sp)
        {

            int n = 0;

            foreach (var spec in sp.memrange.data.spec)
            {
                int err;
                DIS dp = new DIS(sp.pc, sp.memrange);
                if ((err = getword(dp)) != 0)
                    return err;

                dp.x = (ulong)dp.data[0];
                dp.w = 16;
                dp.opcode = opdata[(int)spec];

                n += disop(sp, dp);
            }

            return n;
        }
        static int discode(DISTATE sp)
        {
            DIS dp = new DIS(sp.pc, sp.memrange);
            int err = getword(dp);

            if (err != 0)
                return err;

            if ((dp.opcode = decode[dp.data[0]]) == null)
            {
                dp.opcode = opdata[(int)SpecType.MD_WORD];
            }

            int n = disop(sp, dp);
             return n;
        }