Ejemplo n.º 1
0
        public void addPotsItems()
        {
            int item_address_snes = (01 << 16) +
                                    (ROM.DATA[ConstantsReader.GetAddress("room_items_pointers") + (index * 2) + 1] << 8) +
                                    ROM.DATA[ConstantsReader.GetAddress("room_items_pointers") + (index * 2)];
            int item_address = Addresses.snestopc(item_address_snes);

            while (true)
            {
                byte b1 = ROM.DATA[item_address];
                byte b2 = ROM.DATA[item_address + 1];
                byte b3 = ROM.DATA[item_address + 2];
                //0x20 = bg2

                if (b1 == 0xFF && b2 == 0xFF)
                {
                    break;
                }
                int         address = ((b2 & 0x1F) << 8 | b1) >> 1;
                int         px      = address % 64;
                int         py      = address >> 6;
                roomPotSave p       = new roomPotSave(b3, (ushort)index, (byte)((px)), (byte)((py)), (b2 & 0x20) == 0x20 ? true : false);
                pot_items.Add(p);


                //bit 7 is set if the object is a special object holes, switches
                //after 0x16 it goes to 0x80

                item_address += 3;
            }
        }
Ejemplo n.º 2
0
        public void isdamagePit()
        {
            int pitCount   = (ROM.DATA[ConstantsReader.GetAddress("pit_count")] / 2);
            int pitPointer = AddressLoROM.SnesToPc(ConstantsReader.GetAddress("pit_pointer"));

            pitPointer = Addresses.snestopc(pitPointer);
            for (int i = 0; i < pitCount; i++)
            {
                if (((ROM.DATA[pitPointer + 1 + (i * 2)] << 8) + (ROM.DATA[pitPointer + (i * 2)])) == index)
                {
                    damagepit = true;
                    return;
                }
            }
        }
Ejemplo n.º 3
0
        public void writeOverworldItems(string path)
        {
            if (!Directory.Exists(path + "Overworld//Items"))
            {
                Directory.CreateDirectory(path + "Overworld//Items");
            }

            List <roomPotSave> items = new List <roomPotSave>();

            for (int i = 0; i < 128; i++)
            {
                int addr = (ConstantsReader.GetAddress("overworldItemsBank") << 16) +
                           (ROM.DATA[ConstantsReader.GetAddress("overworldItemsPointers") + (i * 2) + 1] << 8) +
                           (ROM.DATA[ConstantsReader.GetAddress("overworldItemsPointers") + (i * 2)]);

                addr = Addresses.snestopc(addr);

                if (all_maps[i].largeMap == true)
                {
                    if (mapParent[i] != (byte)i)
                    {
                        continue;
                    }
                }
                while (true)
                {
                    byte b1 = ROM.DATA[addr];
                    byte b2 = ROM.DATA[addr + 1];
                    byte b3 = ROM.DATA[addr + 2];
                    if (b1 == 0xFF && b2 == 0xFF)
                    {
                        break;
                    }

                    int p = (((b2 & 0x1F) << 8) + b1) >> 1;

                    int x = p % 64;
                    int y = p >> 6;

                    items.Add(new roomPotSave(b3, (ushort)i, (byte)x, (byte)y, false));
                    addr += 3;
                }
            }

            File.WriteAllText(path + "Overworld//Items/Items.json", JsonConvert.SerializeObject(items));
        }
Ejemplo n.º 4
0
        public void loadHeader()
        {
            //address of the room header

            int headerPointer = AddressLoROM.SnesToPc(ConstantsReader.GetAddress("room_header_pointer"));

            headerPointer = Addresses.snestopc(headerPointer);
            int address = (ROM.DATA[ConstantsReader.GetAddress("room_header_pointers_bank")] << 16) +
                          (ROM.DATA[(headerPointer + 1) + (index * 2)] << 8) +
                          ROM.DATA[(headerPointer) + (index * 2)];

            header_location = Addresses.snestopc(address);

            bg2       = (byte)((ROM.DATA[header_location] >> 5) & 0x07);
            collision = (byte)((ROM.DATA[header_location] >> 2) & 0x07);
            light     = (((ROM.DATA[header_location]) & 0x01) == 1 ? true : false);

            if (light)
            {
                bg2 = 00;
            }

            palette   = (byte)((ROM.DATA[header_location + 1] & 0x3F));
            blockset  = (byte)((ROM.DATA[header_location + 2]));
            spriteset = (byte)((ROM.DATA[header_location + 3]));
            effect    = (byte)((ROM.DATA[header_location + 4]));
            tag1      = (byte)((ROM.DATA[header_location + 5]));
            tag2      = (byte)((ROM.DATA[header_location + 6]));

            holewarp_plane     = (byte)((ROM.DATA[header_location + 7]) & 0x03);
            staircase_plane[0] = (byte)((ROM.DATA[header_location + 7] >> 2) & 0x03);
            staircase_plane[1] = (byte)((ROM.DATA[header_location + 7] >> 4) & 0x03);
            staircase_plane[2] = (byte)((ROM.DATA[header_location + 7] >> 6) & 0x03);
            staircase_plane[3] = (byte)((ROM.DATA[header_location + 8]) & 0x03);

            holewarp           = (byte)((ROM.DATA[header_location + 9]));
            staircase_rooms[0] = (byte)((ROM.DATA[header_location + 10]));
            staircase_rooms[1] = (byte)((ROM.DATA[header_location + 11]));
            staircase_rooms[2] = (byte)((ROM.DATA[header_location + 12]));
            staircase_rooms[3] = (byte)((ROM.DATA[header_location + 13]));
        }
Ejemplo n.º 5
0
        public void loadChests(ref List <ChestData> chests_in_room)
        {
            int cpos = AddressLoROM.SnesToPc(ConstantsReader.GetAddress("chests_data_pointer1"));

            cpos = Addresses.snestopc(cpos);
            int clength = (ROM.DATA[ConstantsReader.GetAddress("chests_length_pointer") + 1] << 8) + (ROM.DATA[ConstantsReader.GetAddress("chests_length_pointer")]);

            for (int i = 0; i < (clength); i++)
            {
                if ((((ROM.DATA[cpos + (i * 3) + 1] << 8) + (ROM.DATA[cpos + (i * 3)])) & 0x7FFF) == index)
                {
                    //there's a chest in that room !
                    bool big = false;
                    if ((((ROM.DATA[cpos + (i * 3) + 1] << 8) + (ROM.DATA[cpos + (i * 3)])) & 0x8000) == 0x8000) //?????
                    {
                        big = true;
                    }
                    chests_in_room.Add(new ChestData(ROM.DATA[cpos + (i * 3) + 2], big));
                    //
                }
            }
        }
Ejemplo n.º 6
0
        public static byte[] DecompressTiles() //to gfx.bin
        {
            int gfxPointer1 = Addresses.snestopc((ROM.DATA[ConstantsReader.GetAddress("gfx_1_pointer") + 1] << 8) + (ROM.DATA[ConstantsReader.GetAddress("gfx_1_pointer")])),
                gfxPointer2 = Addresses.snestopc((ROM.DATA[ConstantsReader.GetAddress("gfx_2_pointer") + 1] << 8) + (ROM.DATA[ConstantsReader.GetAddress("gfx_2_pointer")])),
                gfxPointer3 = Addresses.snestopc((ROM.DATA[ConstantsReader.GetAddress("gfx_3_pointer") + 1] << 8) + (ROM.DATA[ConstantsReader.GetAddress("gfx_3_pointer")]));

            byte[]
            buffer = new byte[0x6F800],    // (185)
            bufferBlock;

            int bufferPos = 0;

            for (int i = 0; i < 96; i++)
            {
                byte[] b    = new byte[] { ROM.DATA[gfxPointer3 + i], ROM.DATA[gfxPointer2 + i], ROM.DATA[gfxPointer1 + i], 0 };
                int    addr = BitConverter.ToInt32(b, 0);
                addresses[i] = Addresses.snestopc(addr);
                //Console.WriteLine(Addresses.snestopc(addr).ToString("X6"));
                byte[] tbufferBlock = Decompress.ALTTPDecompressGraphics(ROM.DATA, Addresses.snestopc(addr), 0x800, ref blockSize[i]);
                bufferBlock = tbufferBlock;
                if (tbufferBlock.Length != 0x600)
                {
                    bpp[i]      = 2;
                    bufferBlock = new byte[0x600];
                    for (int j = 0; j < 0x600; j++)
                    {
                        bufferBlock[j] = tbufferBlock[j];
                    }
                }
                else
                {
                    bpp[i] = 3;
                }
                //bufferBlock = Decompress(Addresses.snestopc(addr), ROM.DATA);
                for (int j = 0; j < bufferBlock.Length; j++)
                {
                    buffer[bufferPos] = bufferBlock[j];
                    bufferPos++;
                }
            }

            for (int i = 96; i < 223; i++)
            {
                bpp[i] = 3;
                if (i < 115 || i > 126) //not compressed
                {
                    byte[] b    = new byte[] { ROM.DATA[gfxPointer3 + i], ROM.DATA[gfxPointer2 + i], ROM.DATA[gfxPointer1 + i], 0 };
                    int    addr = BitConverter.ToInt32(b, 0);
                    addresses[i] = Addresses.snestopc(addr);
                    byte[] tbufferBlock = Decompress.ALTTPDecompressGraphics(ROM.DATA, Addresses.snestopc(addr), 0x800, ref blockSize[i]);
                    bufferBlock = tbufferBlock;
                    if (tbufferBlock.Length != 0x600)
                    {
                        bpp[i]      = 2;
                        bufferBlock = new byte[0xC00];
                        //Console.WriteLine(tbufferBlock.Length);
                        for (int j = 0; j < tbufferBlock.Length; j++)
                        {
                            bufferBlock[j] = tbufferBlock[j];
                        }
                        //Console.WriteLine("Buffer Size :" + tbufferBlock.Length.ToString("X4"));
                    }

                    for (int j = 0; j < bufferBlock.Length; j++)
                    {
                        buffer[bufferPos] = bufferBlock[j];
                        bufferPos++;
                    }
                }
                else
                {
                    byte[] b    = new byte[] { ROM.DATA[gfxPointer3 + i], ROM.DATA[gfxPointer2 + i], ROM.DATA[gfxPointer1 + i], 0 };
                    int    addr = BitConverter.ToInt32(b, 0);
                    addr   = Addresses.snestopc(addr);
                    bpp[i] = 3;
                    for (int j = 0; j < 0x600; j++)
                    {
                        buffer[bufferPos] = ROM.DATA[addr + j];
                        bufferPos++;
                    }
                }
            }

            /*FileStream fs = new FileStream("testgfx.gfx", FileMode.OpenOrCreate, FileAccess.Write);
             * fs.Write(buffer.ToArray(), 0, buffer.Length);
             * fs.Close();*/
            return(buffer);
        }
Ejemplo n.º 7
0
        public void loadTilesObjects(bool floor = true)
        {
            //adddress of the room objects
            int objectPointer = (ROM.DATA[ConstantsReader.GetAddress("room_object_pointer") + 2] << 16) + (ROM.DATA[ConstantsReader.GetAddress("room_object_pointer") + 1] << 8) + (ROM.DATA[ConstantsReader.GetAddress("room_object_pointer")]);

            objectPointer = Addresses.snestopc(objectPointer);
            int room_address = objectPointer + (index * 3);
            int tile_address = (ROM.DATA[room_address + 2] << 16) +
                               (ROM.DATA[room_address + 1] << 8) +
                               ROM.DATA[room_address];

            int objects_location = Addresses.snestopc(tile_address);

            if (floor)
            {
                floor1 = (byte)(ROM.DATA[objects_location] & 0x0F);
                floor2 = (byte)((ROM.DATA[objects_location] >> 4) & 0x0F);
            }
            layout = (byte)((ROM.DATA[objects_location + 1] >> 2) & 0x07);

            List <ChestData> chests_in_room = new List <ChestData>();

            loadChests(ref chests_in_room);

            int   pos     = objects_location + 2;
            byte  b1      = 0;
            byte  b2      = 0;
            byte  b3      = 0;
            byte  posX    = 0;
            byte  posY    = 0;
            byte  sizeX   = 0;
            byte  sizeY   = 0;
            byte  sizeXY  = 0;
            short oid     = 0;
            int   layer   = 0;
            bool  door    = false;
            bool  endRead = false;

            while (endRead == false)
            {
                b1 = ROM.DATA[pos];
                b2 = ROM.DATA[pos + 1];
                if (b1 == 0xFF && b2 == 0xFF)
                {
                    pos += 2; //we jump to layer2
                    layer++;
                    door = false;
                    if (layer == 3)
                    {
                        endRead = true;
                        break;
                    }
                    continue;
                }

                if (b1 == 0xF0 && b2 == 0xFF)
                {
                    pos += 2; //we jump to layer2
                    door = true;
                    continue;
                }
                b3 = ROM.DATA[pos + 2];
                if (door)
                {
                    pos += 2;
                }
                else
                {
                    pos += 3;
                }

                if (door == false)
                {
                    if (b3 >= 0xF8)
                    {
                        oid    = (short)((b3 << 4) | 0x80 + (((b2 & 0x03) << 2) + ((b1 & 0x03))));
                        posX   = (byte)((b1 & 0xFC) >> 2);
                        posY   = (byte)((b2 & 0xFC) >> 2);
                        sizeXY = (byte)((((b1 & 0x03) << 2) + (b2 & 0x03)));
                    }
                    else //subtype1
                    {
                        oid    = b3;
                        posX   = (byte)((b1 & 0xFC) >> 2);
                        posY   = (byte)((b2 & 0xFC) >> 2);
                        sizeX  = (byte)((b1 & 0x03));
                        sizeY  = (byte)((b2 & 0x03));
                        sizeXY = (byte)(((sizeX << 2) + sizeY));
                    }
                    if (b1 >= 0xFC) //subtype2 (not scalable? )
                    {
                        oid    = (short)((b3 & 0x3F) + 0x100);
                        posX   = (byte)(((b2 & 0xF0) >> 4) + ((b1 & 0x3) << 4));
                        posY   = (byte)(((b2 & 0x0F) << 2) + ((b3 & 0xC0) >> 6));
                        sizeXY = 0;
                    }

                    tilesObjects.Add(new Room_Object(oid, posX, posY, sizeXY, (byte)layer));

                    //IF Object is a chest loaded and there's object in the list chest
                    if (oid == 0xF99)
                    {
                        if (chests_in_room.Count > 0)
                        {
                            chest_list.Add(new ChestData(chests_in_room[0].itemIn, false));
                            chests_in_room.RemoveAt(0);
                        }
                    }
                    else if (oid == 0xFB1)
                    {
                        if (chests_in_room.Count > 0)
                        {
                            chest_list.Add(new ChestData(chests_in_room[0].itemIn, true));
                            chests_in_room.RemoveAt(0);
                        }
                    }
                }
                else
                {
                    doors.Add(new DoorSave((short)((b2 << 8) + b1)));
                    continue;
                }
            }
        }
Ejemplo n.º 8
0
        public static void readAllText()
        {
            int maxMessage = 0;
            int pos        = 0xE0000;
            int msgid      = 0;

            while (true)
            {
                messages.Add("");
                messagesPos[msgid] = pos;
                messages[msgid]    = "";
                byte byteRead = ROM.DATA[pos];
                if (byteRead == 0xFF)
                {
                    break;
                }
                while (byteRead != 0x7F) //7F = end of string
                {
                    if (byteRead == 0x80)
                    {
                        pos      = 0x75F40;
                        byteRead = ROM.DATA[pos];
                    }

                    if (getTextCharacter(byteRead, msgid))
                    {
                        pos++;
                    }

                    //Commands
                    else if (byteRead == 0x67) // $67[NextPic] command
                    {
                        messages[msgid] += "[PIC]";
                        pos++;
                    }
                    else if (byteRead == 0x68) //$68[Choose] command
                    {
                        messages[msgid] += "[CHS]";
                        pos++;
                    }
                    else if (byteRead == 0x69) //$69[Item] command(for waterfall of wishing)
                    {
                        messages[msgid] += "[ITM]";
                        pos++;
                    }
                    else if (byteRead == 0x6A) //$6A[Name] command(insert's player's name)
                    {
                        messages[msgid] += "[NAM]";
                        pos++;
                    }
                    else if (byteRead == 0x6B) //$6B[Window XX] command(takes next byte as argument)
                    {
                        messages[msgid] += "[WND=";
                        pos++;
                        byteRead         = ROM.DATA[pos];
                        messages[msgid] += byteRead.ToString("X2") + "]";
                        pos++;
                    }
                    else if (byteRead == 0x6C) // $6C[Number XX] command(takes next byte as argument)
                    {
                        messages[msgid] += "[NBR=";
                        pos++;
                        byteRead         = ROM.DATA[pos];
                        messages[msgid] += byteRead.ToString("X2") + "]";
                        pos++;
                    }
                    else if (byteRead == 0x6D) // $6D[Position XX] command(takes next byte as argument)
                    {
                        messages[msgid] += "[POS=";
                        pos++;
                        byteRead         = ROM.DATA[pos];
                        messages[msgid] += byteRead.ToString("X2") + "]";
                        pos++;
                    }
                    else if (byteRead == 0x6E) //$6E[ScrollSpd XX] command(takes next byte as argument)
                    {
                        messages[msgid] += "[SSP=";
                        pos++;
                        byteRead         = ROM.DATA[pos];
                        messages[msgid] += byteRead.ToString("X2") + "]";
                        pos++;
                    }
                    else if (byteRead == 0x6F) //$6F[SelChng] command
                    {
                        messages[msgid] += "[SCH]";
                        pos++;
                    }
                    else if (byteRead == 0x70) //$70 (Crash)
                    {
                        messages[msgid] += "[REM]";
                        pos++;
                    }
                    else if (byteRead == 0x71) //$71[Choose2] command
                    {
                        messages[msgid] += "[CH1]";
                        pos++;
                    }
                    else if (byteRead == 0x72) //$71[Choose3] command
                    {
                        messages[msgid] += "[CH2]";
                        pos++;
                    }
                    else if (byteRead == 0x73) //$73[SCROLL] command
                    {
                        messages[msgid] += "[SCL]";
                        pos++;
                    }
                    else if (byteRead == 0x74) //$74[1] command(aka[Line1])
                    {
                        messages[msgid] += "[LN1]";
                        pos++;
                    }
                    else if (byteRead == 0x75) //$75[1] command(aka[Line2])
                    {
                        messages[msgid] += "[LN2]";
                        pos++;
                    }
                    else if (byteRead == 0x76) //$76[1] command(aka[Line3])
                    {
                        messages[msgid] += "[LN3]";
                        pos++;
                    }
                    else if (byteRead == 0x77) //$77[Color XX] command(takes next byte as argument)
                    {
                        messages[msgid] += "[COL=";
                        pos++;
                        byteRead         = ROM.DATA[pos];
                        messages[msgid] += byteRead.ToString("X2") + "]";
                        pos++;
                    }
                    else if (byteRead == 0x78) //$78[Wait  XX] command(takes next byte as argument)
                    {
                        messages[msgid] += "[WAI=";
                        pos++;
                        byteRead         = ROM.DATA[pos];
                        messages[msgid] += byteRead.ToString("X2") + "]";
                        pos++;
                    }
                    else if (byteRead == 0x79) //$79[Sound XX] command(takes next byte as argument)
                    {
                        messages[msgid] += "[SND=";
                        pos++;
                        byteRead         = ROM.DATA[pos];
                        messages[msgid] += byteRead.ToString("X2") + "]";
                        pos++;
                    }
                    else if (byteRead == 0x7A) //$7A[Speed XX] command(takes next byte as argument)
                    {
                        messages[msgid] += "[SPD=";
                        pos++;
                        byteRead         = ROM.DATA[pos];
                        messages[msgid] += byteRead.ToString("X2") + "]";
                        pos++;
                    }
                    else if (byteRead == 0x7E) //$7A[Speed XX] command(takes next byte as argument)
                    {
                        messages[msgid] += "[WFK]";
                        pos++;
                    }
                    else if (byteRead == 0x80)
                    {
                        pos++;
                        break;
                    }
                    else if (byteRead >= 0x88 && byteRead <= 0xF9)
                    {
                        //Dictionary
                        byte dictionaryIndex = (byte)(byteRead - 0x88);
                        byte a0            = 0x0E;
                        byte a1            = ROM.DATA[0x74703 + (dictionaryIndex * 2) + 1];
                        byte a2            = ROM.DATA[0x74703 + (dictionaryIndex * 2)];
                        int  dictionaryPos = Addresses.snestopc(((a0 << 16) | (a1 << 8) | (a2)));

                        a0 = 0x0E;
                        a1 = ROM.DATA[0x74703 + (dictionaryIndex * 2) + 3];
                        a2 = ROM.DATA[0x74703 + (dictionaryIndex * 2) + 2];
                        int dictionaryNextPos = Addresses.snestopc(((a0 << 16) | (a1 << 8) | (a2)));

                        byte length = (byte)(dictionaryNextPos - dictionaryPos);

                        for (int i = 0; i < length; i++)
                        {
                            getTextCharacter(ROM.DATA[dictionaryPos + i], msgid);
                        }
                        pos++;
                    }
                    else
                    {
                        //Console.WriteLine(byteRead.ToString("X2"));
                        break;
                    }
                    byteRead = ROM.DATA[pos];

                    if (pos >= 0xE8000)
                    {
                        maxMessage = msgid;
                        break;
                    }

                    continue;
                }

                if (pos >= 0xE8000)
                {
                    maxMessage = msgid;
                    break;
                }

                pos++;
                msgid++;
                byteRead = ROM.DATA[pos];
            }
        }
Ejemplo n.º 9
0
        public int getLongPointerSnestoPc(int pos)
        {
            int p = (ROM.DATA[pos + 2] << 16) + (ROM.DATA[pos + 1] << 8) + (ROM.DATA[pos]);

            return(Addresses.snestopc(p));
        }
Ejemplo n.º 10
0
        public void writeOverworldSprites(string path)
        {
            if (!Directory.Exists(path + "Overworld//Sprites"))
            {
                Directory.CreateDirectory(path + "Overworld//Sprites");
            }


            List <Room_Sprite> sprites = new List <Room_Sprite>();

            int spritesAddress = ConstantsReader.GetAddress("overworldSpritesBegining");

            //09 bank ? Need to check if HM change that
            for (int i = 0; i < 64; i++)
            {
                if (all_maps[i].largeMap == true)
                {
                    if (mapParent[i] != (byte)i)
                    {
                        continue;
                    }
                }
                int sprite_address_snes = (09 << 16) +
                                          (ROM.DATA[spritesAddress + (i * 2) + 1] << 8) +
                                          ROM.DATA[spritesAddress + (i * 2)];
                int sprite_address = Addresses.snestopc(sprite_address_snes);



                while (true)
                {
                    byte b1 = ROM.DATA[sprite_address];
                    byte b2 = ROM.DATA[sprite_address + 1];
                    byte b3 = ROM.DATA[sprite_address + 2];

                    if (b1 == 0xFF)
                    {
                        break;
                    }

                    sprites.Add(new Room_Sprite(b3, (byte)(b2 & 0x3F), (byte)(b1 & 0x3F), (ushort)i, Sprites_Names.name[b3], 0, 0, 0, 0));
                    sprite_address += 3;
                }
            }
            File.WriteAllText(path + "Overworld//Sprites//Beginning Sprites.json", JsonConvert.SerializeObject(sprites));

            sprites.Clear();
            spritesAddress = ConstantsReader.GetAddress("overworldSpritesZelda");



            for (int i = 0; i < 143; i++)
            {
                if (all_maps[i].largeMap == true)
                {
                    if (mapParent[i] != (byte)i)
                    {
                        continue;
                    }
                }
                int sprite_address_snes = (09 << 16) +
                                          (ROM.DATA[spritesAddress + (i * 2) + 1] << 8) +
                                          ROM.DATA[spritesAddress + (i * 2)];
                int sprite_address = Addresses.snestopc(sprite_address_snes);
                while (true)
                {
                    byte b1 = ROM.DATA[sprite_address];
                    byte b2 = ROM.DATA[sprite_address + 1];
                    byte b3 = ROM.DATA[sprite_address + 2];

                    if (b1 == 0xFF)
                    {
                        break;
                    }

                    sprites.Add(new Room_Sprite(b3, (byte)(b2 & 0x3F), (byte)(b1 & 0x3F), (ushort)i, Sprites_Names.name[b3], 0, 0, 0, 0));
                    sprite_address += 3;
                }
            }
            File.WriteAllText(path + "Overworld//Sprites//ZeldaRescued Sprites.json", JsonConvert.SerializeObject(sprites));

            sprites.Clear();
            spritesAddress = ConstantsReader.GetAddress("overworldSpritesAgahnim");


            for (int i = 0; i < 143; i++)
            {
                if (all_maps[i].largeMap == true)
                {
                    if (mapParent[i] != (byte)i)
                    {
                        continue;
                    }
                }
                int sprite_address_snes = (09 << 16) +
                                          (ROM.DATA[spritesAddress + (i * 2) + 1] << 8) +
                                          ROM.DATA[spritesAddress + (i * 2)];
                int sprite_address = Addresses.snestopc(sprite_address_snes);
                while (true)
                {
                    byte b1 = ROM.DATA[sprite_address];
                    byte b2 = ROM.DATA[sprite_address + 1];
                    byte b3 = ROM.DATA[sprite_address + 2];

                    if (b1 == 0xFF)
                    {
                        break;
                    }

                    sprites.Add(new Room_Sprite(b3, (byte)(b2 & 0x3F), (byte)(b1 & 0x3F), (ushort)i, Sprites_Names.name[b3], 0, 0, 0, 0));
                    sprite_address += 3;
                }
            }

            File.WriteAllText(path + "Overworld//Sprites//AgahnimDefeated Sprites.json", JsonConvert.SerializeObject(sprites));
        }
Ejemplo n.º 11
0
        public void writeOverlays(string path)
        {
            for (int index = 0; index < 128; index++)
            {
                overlaysDatas[index] = new List <OverlayData>();
                //overlayPointers
                int addr = (ConstantsReader.GetAddress("overlayPointersBank") << 16) +
                           (ROM.DATA[ConstantsReader.GetAddress("overlayPointers") + (index * 2) + 1] << 8) +
                           ROM.DATA[ConstantsReader.GetAddress("overlayPointers") + (index * 2)];
                addr = Addresses.snestopc(addr);

                int a   = 0;
                int x   = 0;
                int sta = 0;
                //16-bit mode :
                //A9 (LDA #$)
                //A2 (LDX #$)
                //8D (STA $xxxx)
                //9D (STA $xxxx ,x)
                //8F (STA $xxxxxx)
                //1A (INC A)
                //4C (JMP)
                //60 (END)
                byte b = 0;
                while (b != 0x60)
                {
                    b = ROM.DATA[addr];
                    if (b == 0xFF)
                    {
                        break;
                    }
                    else if (b == 0xA9) //LDA #$xxxx (Increase addr+3)
                    {
                        a = (ROM.DATA[addr + 2] << 8) +
                            ROM.DATA[addr + 1];
                        addr += 3;
                        continue;
                    }
                    else if (b == 0xA2) //LDX #$xxxx (Increase addr+3)
                    {
                        x = (ROM.DATA[addr + 2] << 8) +
                            ROM.DATA[addr + 1];
                        addr += 3;
                        continue;
                    }
                    else if (b == 0x8D) //STA $xxxx (Increase addr+3)
                    {
                        sta = (ROM.DATA[addr + 2] << 8) +
                              ROM.DATA[addr + 1];

                        //draw tile at sta position
                        //Console.WriteLine("Draw Tile" + a + " at " + sta.ToString("X4"));
                        //64
                        sta = sta & 0x1FFF;
                        int yp = ((sta / 2) / 0x40);
                        int xp = (sta / 2) - (yp * 0x40);
                        overlaysDatas[index].Add(new OverlayData((byte)xp, (byte)yp, (ushort)a));
                        addr += 3;
                        continue;
                    }
                    else if (b == 0x9D) //STA $xxxx, x (Increase addr+3)
                    {
                        sta = (ROM.DATA[addr + 2] << 8) +
                              ROM.DATA[addr + 1];
                        //draw tile at sta,X position
                        //Console.WriteLine("Draw Tile" + a + " at " + (sta + x).ToString("X4"));

                        int stax = (sta & 0x1FFF) + x;
                        int yp   = ((stax / 2) / 0x40);
                        int xp   = (stax / 2) - (yp * 0x40);
                        overlaysDatas[index].Add(new OverlayData((byte)xp, (byte)yp, (ushort)a));

                        addr += 3;
                        continue;
                    }
                    else if (b == 0x8F) //STA $xxxxxx (Increase addr+4)
                    {
                        sta = (ROM.DATA[addr + 2] << 8) +
                              ROM.DATA[addr + 1];
                        //draw tile at sta,X position
                        //Console.WriteLine("Draw Tile" + a + " at " + (sta + x).ToString("X4"));

                        int stax = (sta & 0x1FFF) + x;
                        int yp   = ((stax / 2) / 0x40);
                        int xp   = (stax / 2) - (yp * 0x40);
                        overlaysDatas[index].Add(new OverlayData((byte)xp, (byte)yp, (ushort)a));

                        addr += 4;
                        continue;
                    }
                    else if (b == 0x1A) //INC A (Increase addr+1)
                    {
                        a    += 1;
                        addr += 1;
                        continue;
                    }
                    else if (b == 0x4C) //JMP $xxxx (move addr to the new address)
                    {
                        addr = (ConstantsReader.GetAddress("overlayPointersBank") << 16) +
                               (ROM.DATA[addr + 2] << 8) +
                               ROM.DATA[addr + 1];
                        addr = Addresses.snestopc(addr);
                        continue;
                    }
                    else if (b == 0x60) //RTS
                    {
                        break;          //just to be sure
                    }
                }
            }

            File.WriteAllText(path + "Overworld//Overlays.json", JsonConvert.SerializeObject(overlaysDatas));
        }