コード例 #1
0
        private void importTilesetToolStripMenuItem_Click(object sender, EventArgs e)
        {
            BattlefieldTileset tileset = new BattlefieldTileset();

            tileset = (BattlefieldTileset)Do.Import(tileset);
            if (tileset == null)
            {
                return;
            }
            //
            byte[] oldTileset = Bits.Copy(tileset.Tileset_bytes);
            //
            tileset.Palettes.BUFFER      = Model.ROM;
            this.battlefield.GraphicSetA = tileset.Battlefield.GraphicSetA;
            this.battlefield.GraphicSetB = tileset.Battlefield.GraphicSetB;
            this.battlefield.GraphicSetC = tileset.Battlefield.GraphicSetC;
            this.battlefield.GraphicSetD = tileset.Battlefield.GraphicSetD;
            this.battlefield.GraphicSetE = tileset.Battlefield.GraphicSetE;
            this.tileset.Palettes        = tileset.Palettes;
            this.tileset.Palettes.CopyTo(Model.PaletteSetsBF[palette]);
            this.tileset.Graphics      = tileset.Graphics;
            this.tileset.Tileset_tiles = tileset.Tileset_tiles;
            this.tileset.DrawTileset(this.tileset.Tileset_tiles, this.tileset.Tileset_bytes);
            this.tileset.Assemble(16, 16);
            //
            RefreshBattlefield();
            //
            if (!Bits.Compare(oldTileset, tileset.Tileset_bytes))
            {
                commandStack.Push(new TilesetCommand(tileset, oldTileset, this));
                commandStack.Push(1);
            }
        }
コード例 #2
0
 public bool CompareSubtiles(Tile source)
 {
     if (Bits.Compare(subtile_bytes, source.Subtile_bytes))
     {
         return(true);
     }
     return(false);
 }
コード例 #3
0
        private void Assemble()
        {
            int offset = 0;

            byte[]    temp         = new byte[0x700];
            MenuTexts lastMenuText = null;

            foreach (MenuTexts menuText in Model.MenuTexts)
            {
                if (lastMenuText != null && menuText.Length != 0 && Bits.Compare(menuText.Text, lastMenuText.Text))
                {
                    Bits.SetShort(Model.ROM, menuText.Index * 2 + 0x3EEF00, lastMenuText.Offset);
                    menuText.Offset = lastMenuText.Offset;
                    continue;
                }
                if (offset + menuText.Length + 1 >= 0x700)
                {
                    MessageBox.Show("Menu texts exceed allotted ROM space. Stopped saving at index " + menuText.Index + ".");
                    break;
                }
                menuText.Offset = offset;
                lastMenuText    = menuText;
                //
                Bits.SetShort(Model.ROM, menuText.Index * 2 + 0x3EEF00, offset);
                Bits.SetChars(temp, offset, menuText.Text);
                offset        += menuText.Length;
                temp[offset++] = 0;
                switch (menuText.Index)
                {
                case 14: Bits.SetByteBits(Model.ROM, 0x03328E, (byte)(menuText.X * 2), 0x3F); break;

                case 15: Bits.SetByteBits(Model.ROM, 0x03327E, (byte)(menuText.X * 2), 0x3F); break;

                case 16: Bits.SetByteBits(Model.ROM, 0x033282, (byte)(menuText.X * 2), 0x3F); break;

                case 17: Bits.SetByteBits(Model.ROM, 0x033286, (byte)(menuText.X * 2), 0x3F); break;

                case 18: Bits.SetByteBits(Model.ROM, 0x03328A, (byte)(menuText.X * 2), 0x3F); break;

                case 19: Bits.SetByteBits(Model.ROM, 0x03327A, (byte)(menuText.X * 2), 0x3F); break;
                }
            }
            Bits.SetBytes(Model.ROM, 0x3EF000, temp);
            //Bits.SetShort(Model.Data, 0x3EF600, 0x344F);
            menus.Assemble();
            menus.Modified = false;
            this.Modified  = false;
        }
コード例 #4
0
        private void clear_Click(object sender, EventArgs e)
        {
            byte[] oldTileset = Bits.Copy(tileset.Tileset_bytes);
            //
            ClearElements clearElements = new ClearElements(null, index, "CLEAR BATTLEFIELD TILESETS...");

            clearElements.ShowDialog();
            if (clearElements.DialogResult == DialogResult.Cancel)
            {
                return;
            }
            RefreshBattlefield();
            //
            if (!Bits.Compare(oldTileset, tileset.Tileset_bytes))
            {
                commandStack.Push(new TilesetCommand(tileset, oldTileset, this));
                commandStack.Push(1);
            }
        }
コード例 #5
0
        private int CalculateFreeSpace()
        {
            int       used         = 0;
            MenuTexts lastMenuText = null;

            foreach (MenuTexts menuText in Model.MenuTexts)
            {
                if (lastMenuText != null && menuText.Length != 0 && Bits.Compare(menuText.Text, lastMenuText.Text))
                {
                    continue;
                }
                lastMenuText = menuText;
                used        += menuText.Length + 1;
            }
            int left = 0x700 - used;

            this.charactersLeft.Text      = "(" + left.ToString() + " characters left)";
            this.charactersLeft.BackColor = left >= 0 ? SystemColors.Control : Color.Red;
            return(left);
        }
コード例 #6
0
        private void textBoxLocation_TextChanged(object sender, EventArgs e)
        {
            if (this.Updating)
            {
                return;
            }
            location.Name     = Do.ASCIIToRaw(textBoxLocation.Text, Lists.Keystrokes, textBoxLocation.Text.Length);
            this.Updating     = true;
            locationName.Text = textBoxLocation.Text;
            locationName.Invalidate();
            this.Updating = false;
            // check total length
            char[][] pointNames = new char[56][];
            char[]   tempB;
            int[]    duplicates = new int[56];  // the point it is a duplicate of
            int[]    levels     = new int[56];  // the location within the point it is a duplicate of
            bool[]   isdup      = new bool[56]; // if is a duplicate of something
            // set duplicates
            for (int i = 0; i < locations.Length; i++)
            {
                pointNames[i] = locations[i].Name;   // the name we'll be comparing everything to
                if (!isdup[i])
                {
                    for (int a = 0; a < locations.Length; a++)
                    {
                        if (a != i && !isdup[a])       // last condition checks if it already has duplicate
                        {
                            tempB = locations[a].Name; // the name that might be a duplicate of tempA
                            for (int b = 0; b < pointNames[i].Length; b++)
                            {
                                if (tempB.Length == pointNames[i].Length - b)
                                {
                                    if (Bits.Compare(pointNames[i], tempB, b, 0)) // if tempB is a duplicate of tempA at location b of tempA
                                    {
                                        levels[a]     = b;
                                        duplicates[a] = i;
                                        isdup[a]      = true;
                                        break;
                                    }
                                }
                                else if (tempB.Length > pointNames[i].Length - b)
                                {
                                    break;
                                }
                            }
                        }
                    }
                }
            }
            // assemble
            ushort[] pointers = new ushort[56];
            int      dOffset  = 0x3EFD80;
            ushort   pointer  = 0;

            // set all of the ones that aren't duplicates first (so we'll have pointers to use)
            for (int i = 0; i < locations.Length; i++)
            {
                if (!isdup[i])
                {
                    pointers[i] = pointer;
                    dOffset    += pointNames[i].Length;
                    pointer    += (ushort)pointNames[i].Length;
                    dOffset++; pointer++;
                    if (i != locations.Length - 1 && !isdup[i + 1] && dOffset > 0x3EFF1F)
                    {
                        break;
                    }
                }
            }
            dOffset--;
            nameFreeSpace.Text      = (0x3EFF1F - dOffset).ToString() + " characters left";
            nameFreeSpace.BackColor = dOffset > 0x3EFF1F ? Color.Red : SystemColors.Control;
            //
            SetWorldMapTextImage();
        }
コード例 #7
0
        private void AssembleLocationTexts()
        {
            char[][] pointNames = new char[56][];
            char[]   tempB;
            int[]    duplicates = new int[56];  // the point it is a duplicate of
            int[]    levels     = new int[56];  // the location within the point it is a duplicate of
            bool[]   isdup      = new bool[56]; // if is a duplicate of something
            // set duplicates
            for (int i = 0; i < locations.Length; i++)
            {
                pointNames[i] = locations[i].Name;   // the name we'll be comparing everything to
                if (!isdup[i])
                {
                    for (int a = 0; a < locations.Length; a++)
                    {
                        if (a != i && !isdup[a])       // last condition checks if it already has duplicate
                        {
                            tempB = locations[a].Name; // the name that might be a duplicate of tempA
                            for (int b = 0; b < pointNames[i].Length; b++)
                            {
                                if (tempB.Length == pointNames[i].Length - b)
                                {
                                    if (Bits.Compare(pointNames[i], tempB, b, 0)) // if tempB is a duplicate of tempA at location b of tempA
                                    {
                                        levels[a]     = b;
                                        duplicates[a] = i;
                                        isdup[a]      = true;
                                        break;
                                    }
                                }
                                else if (tempB.Length > pointNames[i].Length - b)
                                {
                                    break;
                                }
                            }
                        }
                    }
                }
            }
            // assemble
            ushort[] pointers = new ushort[56];
            int      pOffset  = 0x3EFD00;
            int      dOffset  = 0x3EFD80;
            ushort   pointer  = 0;

            // set all of the ones that aren't duplicates first (so we'll have pointers to use)
            for (int i = 0; i < locations.Length; i++)
            {
                if (!isdup[i])
                {
                    pointers[i] = pointer;
                    Bits.SetShort(Model.ROM, i * 2 + pOffset, pointers[i]);
                    Bits.SetChars(Model.ROM, dOffset, pointNames[i]);
                    dOffset           += pointNames[i].Length;
                    pointer           += (ushort)pointNames[i].Length;
                    Model.ROM[dOffset] = 6; dOffset++; pointer++;
                    if (i != locations.Length - 1 && !isdup[i + 1] && dOffset > 0x3EFF1F)
                    {
                        MessageBox.Show("The total compressed size of all location names is too large. Some data might not have been saved correctly. Please reduce the length of one or more location names.", "LAZY SHELL");
                    }
                }
            }
            // set duplicates
            pOffset = 0x3EFD00;
            pointer = 0;
            for (int i = 0; i < locations.Length; i++)
            {
                if (isdup[i])
                {
                    pointers[i] = (ushort)(pointers[duplicates[i]] + levels[i]);
                    Bits.SetShort(Model.ROM, i * 2 + pOffset, pointers[i]);
                }
            }
        }
コード例 #8
0
        // class functions
        public int Length()
        {
            int length = 0;

            // first make sure each channel ends with a termination command
            for (int i = 0; i < 2; i++)
            {
                if (channels[i] != null && channels[i].Count > 0)
                {
                    SPCCommand lastSSC = channels[i][channels[i].Count - 1];
                    if (lastSSC.Opcode != 0xD0 && lastSSC.Opcode != 0xCD && lastSSC.Opcode != 0xCE)
                    {
                        length++;
                    }
                }
            }
            //
            int channelSize1 = 0;
            int channelSize2 = 0;

            if (channels[0] != null && activeChannels[0])
            {
                foreach (SPCCommand ssc in channels[0])
                {
                    channelSize1 += ssc.Length;
                }
            }
            if (channels[1] != null && activeChannels[1])
            {
                foreach (SPCCommand ssc in channels[1])
                {
                    channelSize2 += ssc.Length;
                }
            }
            //
            bool channel2in1 = true;

            if (channels[0] != null && channels[1] != null &&
                activeChannels[0] && activeChannels[1] &&
                channelSize2 <= channelSize1)
            {
                for (int a = channels[0].Count - 1, b = channels[1].Count - 1; a >= 0 && b >= 0; a--, b--)
                {
                    if (!Bits.Compare(channels[0][a].CommandData, channels[1][b].CommandData))
                    {
                        channel2in1 = false;
                    }
                }
            }
            else
            {
                channel2in1 = false;
            }
            //
            if (channel2in1)
            {
                length += channelSize1;
            }
            else
            {
                length += channelSize1 + channelSize2;
            }
            return(length);
        }
コード例 #9
0
        public void Assemble(ref int offset)
        {
            // first make sure each channel ends with a termination command
            for (int i = 0; i < 2; i++)
            {
                if (channels[i] != null && channels[i].Count > 0)
                {
                    SPCCommand lastSSC = channels[i][channels[i].Count - 1];
                    if (lastSSC.Opcode != 0xD0 && lastSSC.Opcode != 0xCD && lastSSC.Opcode != 0xCE)
                    {
                        channels[i].Add(new SPCCommand(new byte[] { 0xD0 }, this, 0));
                    }
                }
            }
            //
            int channelSize1 = 0;
            int channelSize2 = 0;

            if (channels[0] != null && activeChannels[0])
            {
                foreach (SPCCommand ssc in channels[0])
                {
                    channelSize1 += ssc.Length;
                }
            }
            if (channels[1] != null && activeChannels[1])
            {
                foreach (SPCCommand ssc in channels[1])
                {
                    channelSize2 += ssc.Length;
                }
            }
            //
            int offsetStart1 = offset;
            int offsetStart2 = offset + channelSize1;

            if (channels[0] == null || !activeChannels[0])
            {
                offsetStart1 = 0;
            }
            if (channels[1] == null || !activeChannels[1])
            {
                offsetStart2 = 0;
            }
            //
            bool channel2in1 = true;

            if (offsetStart1 != 0 && offsetStart2 != 0 && channelSize2 <= channelSize1)
            {
                for (int a = channels[0].Count - 1, b = channels[1].Count - 1; a >= 0 && b >= 0; a--, b--)
                {
                    if (!Bits.Compare(channels[0][a].CommandData, channels[1][b].CommandData))
                    {
                        channel2in1 = false;
                    }
                }
            }
            else
            {
                channel2in1 = false;
            }
            if (channel2in1)
            {
                offsetStart2 -= channelSize2;
            }
            //
            if (type == 0)
            {
                if (offsetStart1 == 0)
                {
                    Bits.SetShort(rom, index * 4 + 0x042826, 0);
                }
                else
                {
                    Bits.SetShort(rom, index * 4 + 0x042826, offsetStart1 - 0x042C26 + 0x3400);
                }
                if (offsetStart2 == 0)
                {
                    Bits.SetShort(rom, index * 4 + 0x042826 + 2, 0);
                }
                else
                {
                    Bits.SetShort(rom, index * 4 + 0x042826 + 2, offsetStart2 - 0x042C26 + 0x3400);
                }
            }
            else
            {
                if (offsetStart1 == 0)
                {
                    Bits.SetShort(rom, index * 4 + 0x043E26, 0);
                }
                else
                {
                    Bits.SetShort(rom, index * 4 + 0x043E26, offsetStart1 - 0x044226 + 0x3400);
                }
                if (offsetStart2 == 0)
                {
                    Bits.SetShort(rom, index * 4 + 0x043E26 + 2, 0);
                }
                else
                {
                    Bits.SetShort(rom, index * 4 + 0x043E26 + 2, offsetStart2 - 0x044226 + 0x3400);
                }
            }
            if (channels[0] != null && activeChannels[0])
            {
                foreach (SPCCommand ssc in channels[0])
                {
                    Bits.SetBytes(rom, offsetStart1, ssc.CommandData);
                    offsetStart1 += ssc.Length;
                }
            }
            if (channels[1] != null && activeChannels[1])
            {
                foreach (SPCCommand ssc in channels[1])
                {
                    Bits.SetBytes(rom, offsetStart2, ssc.CommandData);
                    offsetStart2 += ssc.Length;
                }
            }
            if (channel2in1)
            {
                offset += channelSize1;
            }
            else
            {
                offset += channelSize1 + channelSize2;
            }
        }