示例#1
0
        public void loadSmallTiles(int tileset, Program.GameTypes game)
        {
            // For ages, get this address from the code that reads it. This will allow for
            // some flexibility for ROMs modified by the disassembly.
            // The corresponding address for Seasons hasn't been looked into yet.
            if (game == Program.GameTypes.Ages)
            {
                gb.BufferLocation = 0x7aa;
                int address = gb.ReadByte() + gb.ReadByte() * 0x100;
                gb.BufferLocation = 0x7a2;
                gb.BufferLocation = gb.ReadByte() * 0x4000 + (address & 0x3fff);
                Console.WriteLine(gb.BufferLocation);
                // For an unmodified rom, gb.BufferLocation should be 0x787e now.
            }
            else
            {
                gb.BufferLocation = 0x7964;
            }
            gb.BufferLocation += tileset * 2;
            gb.BufferLocation  = gb.ReadByte() + gb.ReadByte() * 0x100;
            byte[] ram = new byte[0x10000];

            byte a = gb.ReadByte();
            int  headerLocation = gb.BufferLocation;

            gb.BufferLocation = (game == Program.GameTypes.Ages ? 0x7870 : 0x794E) + (a * 2);
            gb.BufferLocation = gb.ReadByte() + gb.ReadByte() * 0x100; //Uses bank 1
            a                 = gb.ReadByte();
            FF8FValue         = a;
            FF90Value         = gb.ReadByte() + gb.ReadByte() * 0x100;
            gb.BufferLocation = headerLocation;

            byte bank = gb.ReadByte();

            FF8EValue = bank;
            ushort de = (ushort)(gb.ReadByte() * 0x100 + gb.ReadByte());
            ushort bc;
            int    pushedDE = de;

            de                 = (ushort)(gb.ReadByte() * 0x100 + gb.ReadByte());
            a                  = (byte)(gb.ReadByte() & 0x7F);
            FF8DValue          = a;
            a                  = gb.ReadByte();
            gb.BufferLocation -= 2;
            FF8CValue          = a;
            FF92Value          = (gb.BufferLocation >> 8) + ((gb.BufferLocation & 0xFF) * 0x100);
            gb.BufferLocation  = pushedDE;

            //Some procedure at 07FE
            a  = (byte)((de & 0xFF) & 0xF);
            a ^= (byte)(de & 0xFF);
            de = (ushort)(((de >> 8) * 0x100) + a);
            gb.BufferLocation -= 0x4000;
Add807:     //Not exactly 807...
            if (gb.BufferLocation < FF8EValue * 0x4000)
            {
                gb.BufferLocation += FF8EValue * 0x4000;
            }
            a         = gb.ReadByte();
            FF8BValue = a;
            bc        = 0x800;
Add813:
            //bool carry = ((a & 1) == 1);//((bc >> 8) + 1) > 255;
            a         = FF8EValue;
            FF97Value = a;
            a         = FF8BValue;
            a         = Decompressor.RotateRight(a);
            FF8BValue = a;
            bool carry = ((a & 1) == 1);

            if (carry)
            {
                goto Add82D;
            }
            a       = gb.ReadByte();
            ram[de] = a;
            de++;
            Procedure878(ref a);
            if (a == 0)
            {
                goto End;
            }
            bc -= 0x100;
            if (bc >> 8 != 0)
            {
                goto Add813;
            }
            goto Add807;
Add82D:
            ushort pushedBC = bc;

            a = FF8FValue;
            if (a >> 7 == 1)
            {
                goto Add848;
            }
            bc        = (ushort)((bc >> 8) * 0x100 + gb.ReadByte());
            a         = gb.ReadByte();
            FF8AValue = a;
            a        &= 0xF;
            bc        = (ushort)(a * 0x100 + (bc & 0xFF));
            a         = FF8AValue;
            a       >>= 4;
            a        += 3;
            FF8AValue = a;
            goto Add84F;
Add848:
            a         = gb.ReadByte();
            FF8AValue = a;
            bc        = (ushort)(gb.ReadByte() + gb.ReadByte() * 0x100);
Add84F:
            int temp = gb.BufferLocation;

            gb.BufferLocation  = FF8EValue * 0x4000 + ((FF90Value & 0xFF) * 0x100 + (FF90Value >> 8)) - 0x4000;
            gb.BufferLocation += bc;
            a                  = FF8AValue;
            bc                 = (ushort)(a * 0x100 + (bc & 0xFF));
            a                  = (byte)(FF8FValue & 0x3F);
            FF97Value          = a;
            gb.BufferLocation  = gb.BufferLocation % 0x4000;
            gb.BufferLocation += a * 0x4000;
Add863:
            a       = gb.ReadByte();
            ram[de] = a;
            de++;
            Procedure878(ref a);
            if (a == 0)
            {
                goto Add875;
            }
            bc -= 0x100;
            if (bc >> 8 > 0)
            {
                goto Add863;
            }
            gb.BufferLocation = temp;
            bc  = pushedBC;
            bc -= 0x100;
            if (bc >> 8 > 0)
            {
                goto Add813;
            }
            goto Add807;
Add875:
            gb.BufferLocation = temp;
            bc = pushedBC;
            //Above are assumptions...

End:
            SmallTiles = ram;
        }
        public void loadSmallTiles(int tileset, Program.GameTypes game)
        {
            gb.BufferLocation  = game == Program.GameTypes.Ages ? 0x787E : 0x7964;
            gb.BufferLocation += tileset * 2;
            gb.BufferLocation  = gb.ReadByte() + gb.ReadByte() * 0x100;
            byte[] ram = new byte[0x10000];

            byte a = gb.ReadByte();
            int  headerLocation = gb.BufferLocation;

            gb.BufferLocation = (game == Program.GameTypes.Ages ? 0x7870 : 0x794E) + (a * 2);
            gb.BufferLocation = gb.ReadByte() + gb.ReadByte() * 0x100; //Uses bank 1
            a                 = gb.ReadByte();
            FF8FValue         = a;
            FF90Value         = gb.ReadByte() + gb.ReadByte() * 0x100;
            gb.BufferLocation = headerLocation;

            byte bank = gb.ReadByte();

            FF8EValue = bank;
            ushort de = (ushort)(gb.ReadByte() * 0x100 + gb.ReadByte());
            ushort bc;
            int    pushedDE = de;

            de                 = (ushort)(gb.ReadByte() * 0x100 + gb.ReadByte());
            a                  = (byte)(gb.ReadByte() & 0x7F);
            FF8DValue          = a;
            a                  = gb.ReadByte();
            gb.BufferLocation -= 2;
            FF8CValue          = a;
            FF92Value          = (gb.BufferLocation >> 8) + ((gb.BufferLocation & 0xFF) * 0x100);
            gb.BufferLocation  = pushedDE;

            //Some procedure at 07FE
            a  = (byte)((de & 0xFF) & 0xF);
            a ^= (byte)(de & 0xFF);
            de = (ushort)(((de >> 8) * 0x100) + a);
            gb.BufferLocation -= 0x4000;
Add807:     //Not exactly 807...
            if (gb.BufferLocation < FF8EValue * 0x4000)
            {
                gb.BufferLocation += FF8EValue * 0x4000;
            }
            a         = gb.ReadByte();
            FF8BValue = a;
            bc        = 0x800;
Add813:
            //bool carry = ((a & 1) == 1);//((bc >> 8) + 1) > 255;
            a         = FF8EValue;
            FF97Value = a;
            a         = FF8BValue;
            a         = Decompressor.RotateRight(a);
            FF8BValue = a;
            bool carry = ((a & 1) == 1);

            if (carry)
            {
                goto Add82D;
            }
            a       = gb.ReadByte();
            ram[de] = a;
            de++;
            Procedure878(ref a);
            if (a == 0)
            {
                goto End;
            }
            bc -= 0x100;
            if (bc >> 8 != 0)
            {
                goto Add813;
            }
            goto Add807;
Add82D:
            ushort pushedBC = bc;

            a = FF8FValue;
            if (a >> 7 == 1)
            {
                goto Add848;
            }
            bc        = (ushort)((bc >> 8) * 0x100 + gb.ReadByte());
            a         = gb.ReadByte();
            FF8AValue = a;
            a        &= 0xF;
            bc        = (ushort)(a * 0x100 + (bc & 0xFF));
            a         = FF8AValue;
            a       >>= 4;
            a        += 3;
            FF8AValue = a;
            goto Add84F;
Add848:
            a         = gb.ReadByte();
            FF8AValue = a;
            bc        = (ushort)(gb.ReadByte() + gb.ReadByte() * 0x100);
Add84F:
            int temp = gb.BufferLocation;

            gb.BufferLocation  = FF8EValue * 0x4000 + ((FF90Value & 0xFF) * 0x100 + (FF90Value >> 8)) - 0x4000;
            gb.BufferLocation += bc;
            a                  = FF8AValue;
            bc                 = (ushort)(a * 0x100 + (bc & 0xFF));
            a                  = (byte)(FF8FValue & 0x3F);
            FF97Value          = a;
            gb.BufferLocation  = gb.BufferLocation % 0x4000;
            gb.BufferLocation += a * 0x4000;
Add863:
            a       = gb.ReadByte();
            ram[de] = a;
            de++;
            Procedure878(ref a);
            if (a == 0)
            {
                goto Add875;
            }
            bc -= 0x100;
            if (bc >> 8 > 0)
            {
                goto Add863;
            }
            gb.BufferLocation = temp;
            bc  = pushedBC;
            bc -= 0x100;
            if (bc >> 8 > 0)
            {
                goto Add813;
            }
            goto Add807;
Add875:
            gb.BufferLocation = temp;
            bc = pushedBC;
            //Above are assumptions...

End:
            SmallTiles = ram;
        }