Beispiel #1
0
        public void Compile_CompilesOriginalDungeons()
        {
            var expected = new[]
            {
                "1111111", "0111110", "1111101", "0004000",
                "0001000", "0001111", "0011100", "0011101",
                "1014101", "1010101", "1011101", "1000001",
                "1000101", "1040101", "0011111", "0111111",
                "1111110", "0111011", "1100011", "1101011",
                "0000001", "1011111", "1111011", "1101110",
                "1110111", "1111611", "1101111", "1111010",
                "1011100", "0077211", "1177177", "1661111",
                "1111711", "1161111", "7111177", "1013101",
                "1012101", "0100113", "3777773", "3111113",
                "1111113", "0010011", "1101100", "0077311",
                "0000011", "0000000", "6666666", "1666661",
                "6666616", "1616161", "6161616", "1611161",
                "6166616", "6111116", "6166666", "1111112",
                "6661666", "1666666", "1661166", "7777777",
                "5555555", "1001001", "1777111", "1116111",
                "0100112", "2777772", "2111112", "0100111",
                "1112111", "1113111", "0777111", "1021101",
                "1031101", "1212121", "1212125", "1111155",
                "1111555", "1313131", "1313135"
            };

            // Load all data from the original cartridge
            var decompiler           = new UnderworldRoomDecompiler();
            var inColumnPointerTable = new WordPointerTable(new SourceBlock(Source, 0x16704), new SourceBlock(Source, 0xC000), 10);
            var inColumns            = new UnderworldColumnLibraryList(inColumnPointerTable);
            var inRoomList           = new UnderworldRoomLayoutList(new SourceBlock(Source, 0x160DE), 42);
            var inRooms = decompiler.Decompile(inColumns, inRoomList);

            // Compile it
            var compiler     = new UnderworldRoomCompiler();
            var output       = compiler.Compile(inRooms.Rooms);
            var columnOutput = output.ColumnData.ToArray();
            var mem          = new Source(columnOutput);

            // Read it out
            var library = new UnderworldColumnLibrary(mem, output.ColumnOffsets.Count());
            var columns = library.Select(dc => string.Join(string.Empty, dc.Select(t => $"{t:X1}")));

            columns.Should().BeEquivalentTo(expected);
        }
        /// <summary>
        /// Create a data adapter.
        /// </summary>
        public ZeldaCartridge(ISource source)
        {
            var conversionTable      = new Lazy <ITextConversionTable>(() => new TextConversionTable());
            var speechConverter      = new Lazy <IStringConverter>(() => new SpeechStringConverter(conversionTable.Value));
            var textConverter        = new Lazy <IStringConverter>(() => new TextStringConverter(conversionTable.Value));
            var fixedStringConverter = new Lazy <IFixedStringConverter>(() => new FixedStringConverter(conversionTable.Value));
            var speechFormatter      = new Lazy <IStringFormatter>(() => new StringFormatter());

            // Character Text
            _characterText = new Lazy <IList <string> >(() => new CharacterText(
                                                            new WordPointerTable(new SourceBlock(source, 0x4000), new SourceBlock(source, -0x4000), 0x26),
                                                            speechFormatter.Value,
                                                            speechConverter.Value,
                                                            0x556,
                                                            0x26));

            // Ending Text
            _endingText = new Lazy <IEndingText>(() => new EndingText(
                                                     new StringData(new SourceBlock(source, 0xA959), speechConverter.Value, 38),
                                                     new FixedStringData(new SourceBlock(source, 0xAB07), fixedStringConverter.Value, 8),
                                                     new FixedStringData(new SourceBlock(source, 0xAB0F), fixedStringConverter.Value, 24),
                                                     new FixedStringData(new SourceBlock(source, 0xAB27), fixedStringConverter.Value, 20)));

            // Menu Text
            _menuText = new Lazy <IMenuText>(() => new MenuText(
                                                 new FixedStringData(new SourceBlock(source, 0x09D48), fixedStringConverter.Value, 17),
                                                 new FixedStringData(new SourceBlock(source, 0x09D5E), fixedStringConverter.Value, 18),
                                                 new FixedStringData(new SourceBlock(source, 0x09D70), fixedStringConverter.Value, 8),
                                                 new FixedStringData(new SourceBlock(source, 0x09EEB), fixedStringConverter.Value, 5)));

            // Underworld
            _underworld = new Lazy <IUnderworld>(() =>
            {
                var underworldColumnPointers = new WordPointerTable(
                    new SourceBlock(source, 0x16704),
                    new SourceBlock(source, 0xC000), 10);
                var columnLibraries = new UnderworldColumnLibraryList(
                    underworldColumnPointers);
                var grids = new UnderworldGridList(
                    new SourceBlock(source, 0x18700),
                    4);
                var roomLayouts = new UnderworldRoomLayoutList(
                    new SourceBlock(source, 0x160DE),
                    42);
                var levels = new UnderworldLevelList(
                    new SourceBlock(source, 0x193FF),
                    9);

                return(new Underworld
                {
                    ColumnLibraries = columnLibraries,
                    Grids = grids,
                    Levels = levels,
                    RoomLayouts = roomLayouts
                });
            });

            // Overworld
            _overworld = new Lazy <IOverworld>(() =>
            {
                var overworldColumnPointers = new WordPointerTable(
                    new SourceBlock(source, 0x19D0F),
                    new SourceBlock(source, 0x0C000),
                    16);
                var columnLibraries = new OverworldColumnLibraryList(
                    overworldColumnPointers);
                var grid = new OverworldGrid(
                    new SourceBlock(source, 0x18580));
                var roomLayouts = new OverworldRoomLayoutList(
                    new SourceBlock(source, 0x15418),
                    124);
                var tiles = new OverworldTileList(
                    new SourceBlock(source, 0x1697C));
                var detailTiles = new OverworldDetailTileList(
                    new SourceBlock(source, 0x169B4));
                var sprites = new OverworldSpriteList(
                    new SourceBlock(source, 0x0C93B));
                var level = new OverworldLevel(
                    new SourceBlock(source, 0x19303));
                var start = new OverworldStart(
                    new SourceBlock(source, 0x19328));

                return(new Overworld
                {
                    ColumnLibraries = columnLibraries,
                    Grid = grid,
                    DetailTiles = detailTiles,
                    RoomLayouts = roomLayouts,
                    Tiles = tiles,
                    Sprites = sprites,
                    Level = level,
                    Start = start
                });
            });

            // Shops
            _shops = new Lazy <IReadOnlyList <IShop> >(() => new ShopList(
                                                           new SourceBlock(source, 0x18600),
                                                           new SourceBlock(source, 0x045A2),
                                                           new SourceBlock(source, 0x06E6F),
                                                           20));

            // Intro scene
            _introScene = new Lazy <IScene>(() => new Scene(
                                                new SourceBlock(source, 0x1A3FE),
                                                conversionTable.Value));

            // Title scene
            _titleScene = new Lazy <IScene>(() => new Scene(
                                                new SourceBlock(source, 0x1A869),
                                                conversionTable.Value));

            // Hit points
            _hitPointTable = new Lazy <HitPointTable>(() => new HitPointTable(
                                                          new SourceBlock(source, 0x1FB4E)));
        }
Beispiel #3
0
        protected override UnderworldColumnLibraryList GetTestSubject()
        {
            var columnPointerTable = new WordPointerTable(new SourceBlock(Source, 0x16704), new SourceBlock(Source, 0xC000), 10);

            return(new UnderworldColumnLibraryList(columnPointerTable));
        }