public RomData(RomIO rom) { Rom = rom ?? throw new ArgumentOutOfRangeException(nameof(rom)); if (Rom.HeaderlessSize < 0x200000) { throw new ArgumentException( "ROM data size is insufficient."); } AreaLoader = new AreaLoader(this); PaletteData = new PaletteData(this); GfxData = new GfxData(this); AreaBg2Map = new AreaBg2Map(this); Map16Data = new Obj16Tile[0x200]; var offsets = new byte[] { 0x00, 0x40, 0x80, 0xC0 }; var sizes = new byte[] { 0x2B, 0x38, 0x0E, 0x3E }; for (var i = 0; i < 4; i++) { var low = Rom.ReadByte(Map16DataLowByteAddress + i); var high = Rom.ReadByte(Map16DataHighByteAddress + i); var address = 0x030000 | (high << 8) | low; var tiles = Rom.ReadBytes(address, sizes[i] << 3, true); unsafe { fixed(byte *src = tiles) fixed(Obj16Tile * dest = Map16Data) { Buffer.MemoryCopy( src, dest + offsets[i], 0x800, tiles.Length); } } } TilemapLoader = new TilemapLoader(this); AreaObjectRenderer = new AreaObjectRenderer(AreaObjectLoader); AreaSpriteRenderer = new AreaSpriteRenderer(AreaSpriteLoader); AreaNumber = AreaLoader.GetAreaNumber(0, 0); }
private void UpdateArea() { var objectAddress = AreaObjectLoader.GetAreaAddress(AreaNumber); CurrentAreaHeader = AreaObjectLoader.GetAreaHeader(objectAddress); CurrentObjectData = new List <AreaObjectCommand>( AreaObjectLoader.GetAreaData(objectAddress + 2)); AreaObjectRenderer.RenderTileMap( AreaType, CurrentAreaHeader, CurrentObjectData); var spriteAddress = AreaSpriteLoader.GetAreaAddress(AreaNumber); CurrentSpriteData = new List <AreaSpriteCommand>( AreaSpriteLoader.GetAreaData(spriteAddress)); }
public AreaObjectParser( AreaObjectRenderer areaObjectRenderer, IList <AreaObjectCommand> areaObjectData, int bufferSize = DefaultBufferSize) { AreaObjectRenderer = areaObjectRenderer ?? throw new ArgumentNullException(nameof(areaObjectRenderer)); AreaData = new Collection <AreaObjectCommand>(areaObjectData); BufferSize = bufferSize >= 0 ? bufferSize : throw new ArgumentOutOfRangeException(nameof(bufferSize)); LengthBuffer = new int[BufferSize]; IndexBuffer = new int[BufferSize]; TreePlatformProperties = new bool[BufferSize]; MushroomPlatformCenterCoordinate = new int[BufferSize]; RenderCommands = new Dictionary <AreaObjectCode, Action>() { { AreaObjectCode.EnterablePipe, Pipe }, { AreaObjectCode.AreaSpecificPlatform, AreaSpecificPlatform }, { AreaObjectCode.HorizontalBricks, RowOfBricks }, { AreaObjectCode.HorizontalStones, RowOfStones }, { AreaObjectCode.HorizontalCoins, RowOfCoins }, { AreaObjectCode.VerticalBricks, ColumnOfBricks }, { AreaObjectCode.VerticalStones, ColumnOfStones }, { AreaObjectCode.UnenterablePipe, Pipe }, { AreaObjectCode.Hole, Hole }, { AreaObjectCode.BalanceHorizontalRope, BalanceHorizontalRope }, { AreaObjectCode.BridgeV7, HighBridge }, { AreaObjectCode.BridgeV8, MidBridge }, { AreaObjectCode.BridgeV10, LowBridge }, { AreaObjectCode.HoleWithWaterOrLava, HoleWithWaterOrLava }, { AreaObjectCode.HorizontalQuestionBlocksV3, HighRowOfCoinBlocks }, { AreaObjectCode.HorizontalQuestionBlocksV7, LowRowOfCoinBlocks }, { AreaObjectCode.QuestionBlockPowerup, ItemBlock }, { AreaObjectCode.QuestionBlockCoin, ItemBlock }, { AreaObjectCode.HiddenBlockCoin, ItemBlock }, { AreaObjectCode.HiddenBlock1UP, AreaTypeBlock }, { AreaObjectCode.BrickPowerup, AreaTypeBlock }, { AreaObjectCode.BrickBeanstalk, AreaTypeBlock }, { AreaObjectCode.BrickStar, AreaTypeBlock }, { AreaObjectCode.Brick10Coins, AreaTypeBlock }, { AreaObjectCode.Brick1UP, AreaTypeBlock }, { AreaObjectCode.SidewaysPipe, SidewaysPipe }, { AreaObjectCode.UsedBlock, FireBarBlock }, { AreaObjectCode.SpringBoard, SpringBoard }, { AreaObjectCode.JPipe, JPipe }, { AreaObjectCode.AltJPipe, JPipe }, { AreaObjectCode.FlagPole, FlagPole }, { AreaObjectCode.AltFlagPole, FlagPole }, { AreaObjectCode.BowserAxe, BowserAxe }, { AreaObjectCode.RopeForAxe, RopeForAxe }, { AreaObjectCode.BowserBridge, BowserBridge }, { AreaObjectCode.ForegroundChange, ForegroundChange }, { AreaObjectCode.BrickAndSceneryChange, TerrainModifier }, { AreaObjectCode.RopeForLift, RopeForLift }, { AreaObjectCode.PulleyRope, PulleyRope }, { AreaObjectCode.Castle, Castle }, { AreaObjectCode.CastleCeilingCap, CastleCeilineCap }, { AreaObjectCode.Staircase, StoneStairs }, { AreaObjectCode.CastleStairs, CastleDescendingSteps }, { AreaObjectCode.CastleRectangularCeilingTiles, CastleRectangularCeilingTiles }, { AreaObjectCode.CastleFloorRightEdge, CastleFloorRightEdge }, { AreaObjectCode.CastleFloorLeftEdge, CastleFloorLeftEdge }, { AreaObjectCode.CastleFloorLeftWall, CastleFloorLeftWall }, { AreaObjectCode.CastleFloorRightWall, CastleFloorRightWall }, { AreaObjectCode.VerticalSeaBlocks, VerticalSeaBlocks }, { AreaObjectCode.ExtendableJPipe, ExtendableJPipe }, { AreaObjectCode.VerticalBalls, VerticalClimbingObject }, }; }