public void LoadSmallMap() { int ind = 0; room.decompressed = new byte[80]; room.overworld = new OverworldBlock[80]; int compression = room.compressionType; gb.BufferLocation = room.dataLocation; //Compression types //2 - 16-bit //1 - 8-bit //0 - uncompressed if (compression != 0) { byte filler = 0; while (ind < 80) { room.overworld[ind] = new OverworldBlock(); int bitmap = gb.ReadByte() + (compression == 2 ? (gb.ReadByte() << 8) : 0); if (bitmap != 0) { filler = gb.ReadByte(); } room.overworld[ind].x = (byte)(ind % 10); room.overworld[ind].y = (byte)(ind / 10); room.overworld[ind].set = (byte)((compression == 2 ? ind / 16 : ind / 8)); for (int i = 0; i < (compression == 2 ? 16 : 8); i++) { if ((bitmap & 1) == 1) { room.decompressed[ind] = filler; room.overworld[ind].id = filler; room.overworld[ind].type = 1; } else { room.decompressed[ind] = gb.ReadByte(); room.overworld[ind].id = room.decompressed[ind]; } bitmap >>= 1; ind++; } } } else { room.decompressed = gb.ReadBytes(80); for (int i = 0; i < 80; i++) { room.overworld[i] = new OverworldBlock(); room.overworld[i].id = room.decompressed[i]; room.overworld[i].x = (byte)(i % 10); room.overworld[i].y = (byte)(i / 10); } } }
public void loadWalls() { gb.BufferLocation = 0x50917; for (int i = 0; i < 9; i++) { byte b = 0; int count = 0; List <LAObject> listt = new List <LAObject>(); while ((b = gb.ReadByte()) != 0xFF) { LAObject t = new LAObject(); t.y = (byte)(b / 16); t.x = (byte)(b - (t.y * 16)); listt.Add(t); count++; } byte[] buffer = gb.ReadBytes(count); for (int k = 0; k < count; k++) { LAObject t = listt[k]; t.id = buffer[k]; listt[k] = t; wallTiles[i, k] = listt[k]; } } }
public void loadMinimapDData(byte dungeon) { minimapGraphics = gb.ReadBytes(0xA49A + (64 * dungeon), 64); if (dungeon == 0xFF) { minimapGraphics = gb.ReadBytes(0xA49A + (64 * 0x9), 64); } roomIndexes = gb.ReadBytes(0x50220 + (64 * dungeon), 64); if (dungeon == 0xFF) { roomIndexes = gb.ReadBytes(0x504E0, 64); } }
public void loadTilesetHeader(int src, byte bank, bool flag, int address2, int address3, ref byte a) { try { int writeLocation = 0; byte b; byte c; if (flag) { location = src; gb.BufferLocation = src; if (gb.ReadByte() == 0xFF) //Uncompressed hack { gb.BufferLocation = 0x101000 + gb.ReadByte() * 3; byte bb = gb.ReadByte(); gb.BufferLocation = bb * 0x4000 + gb.ReadByte() + ((gb.ReadByte() - 0x40) * 0x100); decompressedBuffer = vramBuffer = gb.ReadBytes(decompressedBuffer.Length); return; } gb.BufferLocation--; gb.BufferLocation = (bank * 0x4000) + gb.ReadByte() + ((gb.ReadByte() - 0x40) * 0x100); } else { b = (byte)(address3 >> 8); c = (byte)(address3 & 0xFF); //writeLocation = ((address2 >> 8) * 0x100) - 0x8800; writeLocation = ((address2 >> 8) * 0x100) - 0x8800; goto Main; } First: c = gb.ReadByte(); int address = gb.ReadByte() * 0x100 + gb.ReadByte() - 0x4000 + (bank * 0x4000); //Graphics data. pushed de address2 = (gb.ReadByte() * 0x100) + gb.ReadByte(); //de writeLocation = ((address2 >> 8) * 0x100) - 0x8800; b = (byte)(gb.ReadByte() & 0x7F); address3 = c + (b * 0x100); //bc gb.BufferLocation--; FF90Value = gb.BufferLocation; gb.BufferLocation = address - 0x4000; goto Main; //End of header. Begin loading data Secondary: a = 1; FF97Value = a; a = gb.ReadByte(FF90Value); bool carry1 = (a + a > 255); a = (byte)(a + a); if (carry1) { goto First; } return; Main: a = (byte)(address2 & 0xFF); a &= 0xF; a ^= (byte)(address2 & 0xFF); address2 = (ushort)(((address2 >> 8) * 0x100) + a); if (a != 0) { writeLocation += a; } //writeLocation = address2 - 0x8800; a = (byte)((address3 & 0xFF) & 0x3F); gfxBank = a; if (gb.BufferLocation / 0x4000 != gfxBank) { gb.BufferLocation = (gb.BufferLocation % 0x4000) + gfxBank * 0x4000; } address3 += 0x100; b++; a = (byte)((address3 & 0xFF) & 0xC0); if (a == 0) { goto Add6E0; } if (a == 0xC0) { goto Add6EE; } if (a == 0x40) { goto Add6F2; } a = (byte)(address3 >> 8); //amount of bytes to decompress decompress1(gb.BufferLocation, ref decompressedBuffer, ref writeLocation, a * 16); goto Secondary; Add6E0: c = 0x10; Add6E2: a = gb.ReadByte(); gfxBank = (byte)(gb.BufferLocation / 0x4000); decompressedBuffer[writeLocation] = a; writeLocation++; c--; if (c > 0) { goto Add6E2; } b--; if (b > 0) { goto Add6E0; } goto Secondary; Add6EE: a = 0xFF; goto Add6F5; Add6F2: a = 0; FF93Value = a; Add6F5: FF8EValue = a; b = (byte)(address3 >> 8); b = (byte)(((b & 0xF) << 4) + (b >> 4)); a = b; a &= 0xF0; c = a; a ^= b; b = a; a = 1; FF8BValue = a; Add703: a = FF8BValue; a--; FF8BValue = a; if (a != 0) { goto Add714; } a = 8; FF8BValue = a; a = gb.ReadByte(); FF8AValue = a; procedure776(ref a, ref b, ref c); Add714: a = FF8AValue; bool carry = (a + a > 255); a = (byte)(a + a); FF8AValue = a; if (carry) { goto Add721; } procedure772(ref a, ref b, ref c, ref writeLocation); if (a != 0) { goto Add703; } goto Secondary; Add721: a = FF8EValue; a |= a; if (a != 0) { goto Add734; } a = gb.ReadByte(); gb.BufferLocation--; a &= 0x1F; FF92Value = a; a ^= gb.ReadByte(); gb.BufferLocation--; if (a == 0) { goto Add749; } a = (byte)(((a & 0xF) >> 4) + (a >> 4)); a >>= 1; a++; goto Add74E; Add734: a = gb.ReadByte(); FF92Value = a; procedure776(ref a, ref b, ref c); a = gb.ReadByte(); gb.BufferLocation--; a &= 7; FF93Value = a; a ^= gb.ReadByte(); gb.BufferLocation--; if (a == 0) { goto Add749; } a >>= 3; a += 2; goto Add74E; Add749: gb.BufferLocation++; procedure776(ref a, ref b, ref c); a = gb.ReadByte(); gb.BufferLocation--; Add74E: //Copy FF8FValue = a; gb.BufferLocation++; procedure776(ref a, ref b, ref c); int temp = gb.BufferLocation; a = (byte)(0xFF - FF92Value); byte l = a; a = (byte)(0xFF - FF93Value); byte h = a; ushort copyAddress = (ushort)(writeLocation - (0xFFFF - (h * 0x100 + l)) - 1);//h * 0x100 + l - 0x8800; StartCopy: a = decompressedBuffer[copyAddress]; copyAddress++; decompressedBuffer[writeLocation] = a; writeLocation++; int i = b * 0x100 + c; i--; c = (byte)(i & 0xFF); b = (byte)(i >> 8); a = b; a |= c; if (a == 0) { //gb.BufferLocation = temp; goto Secondary; } a = FF8FValue; a--; FF8FValue = a; if (a != 0) { goto StartCopy; } gb.BufferLocation = temp; goto Add703; } catch (Exception) { //used to catch bad tileset loads since the header is a user-inputted value } }
public byte[, ,] loadTileset(byte dungeon, byte map, bool overworld, bool crystals, bool sideView) { List <byte> final = new List <byte>(); byte[] animated = new byte[0x40]; byte[] walls = new byte[0x200]; cDungeon = dungeon; cMap = map; overWorld = overworld; cSideView = sideView; foreach (byte b in loadFirstRow()) { final.Add(b); } animated = Animate(); if (!cSideView) { foreach (byte b in loadSOG(cMap, crystals)) { final.Add(b); } if (!overWorld) { foreach (byte b in loadThird()) { final.Add(b); } } foreach (byte b in loadMain()) { final.Add(b); } walls = Walls(); if (!overWorld) { for (int w = 0; w < 0x200; w++) { final[(0x300) + w] = walls[w]; } } } else { if ((dungeon < 10 || map == 0xE9) && dungeon != 6) { gb.BufferLocation = 0xB7800; } else { gb.BufferLocation = 0xB7000; } foreach (byte b in gb.ReadBytes(0x800)) { final.Add(b); } } for (int i = 0; i < 0x40; i++) { final[(0x7C * 16) + i] = animated[i]; } byte[, ,] data = new byte[144, 8, 8]; gb.ReadTiles(16, 9, final.ToArray(), ref data); return(data); }