コード例 #1
0
        public void TestRenderScreenWithSpriteFlipped()
        {
            var romData = new ROMData();

            romData.Data[ROMs.PAC_MAN_COLOR.FileName]   = VideoHardwareTestData.COLOR_ROM;
            romData.Data[ROMs.PAC_MAN_PALETTE.FileName] = VideoHardwareTestData.PALETTE_ROM;
            romData.Data[ROMs.PAC_MAN_TILE.FileName]    = VideoHardwareTestData.TILE_ROM;
            romData.Data[ROMs.PAC_MAN_SPRITE.FileName]  = VideoHardwareTestData.SPRITE_ROM;

            var video = new VideoHardware(romData);

            video.InitializeColors();
            video.InitializePalettes();
            video.InitializeTiles();
            video.InitializeSprites();

            // Arrange: Load a VRAM dump which contains tiles positions and palettes for each tile.

            var rawMemory = new byte[0xFFFF];

            var vram = File.ReadAllBytes($"../../../TestData/maze-1.vram");

            Array.Copy(vram, 0, rawMemory, 0x4000, 0x0800);

            var memory = new SimpleMemory(rawMemory);

            // Arrange: Setup the sprites to show.

            // Pac-Man facing left sprite (46), flip X/Y (0x02).
            var flags = (byte)((46 << 2) | (0x02));

            memory.Write(0x4FF0, flags);
            memory.Write(0x4FF1, 9); // Palette.

            // Act: Render the image based on the tiles and palettes in memory.

            var spriteCoordinates = new byte[16]
            {
                220, // x
                252, // y
                0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
            };

            var image = video.Render(memory, spriteCoordinates, true);

            // Assert: the rendered image should be the same as the reference image.

            byte[] actualBytes = null;

            using (var steam = new MemoryStream())
            {
                image.Save(steam, new BmpEncoder());
                actualBytes = steam.ToArray();
            }

            var expectedBytes = File.ReadAllBytes($"../../../ReferenceData/render-maze-1-with-sprites-flipped.bmp");

            Assert.Equal(expectedBytes, actualBytes);
        }
コード例 #2
0
        public void TestRenderScreen(string vramFile, string expectedBitmapFile, bool flipScreen)
        {
            var romData = new ROMData();

            romData.Data[ROMs.PAC_MAN_COLOR.FileName]   = VideoHardwareTestData.COLOR_ROM;
            romData.Data[ROMs.PAC_MAN_PALETTE.FileName] = VideoHardwareTestData.PALETTE_ROM;
            romData.Data[ROMs.PAC_MAN_TILE.FileName]    = VideoHardwareTestData.TILE_ROM;
            romData.Data[ROMs.PAC_MAN_SPRITE.FileName]  = VideoHardwareTestData.SPRITE_ROM;

            var video = new VideoHardware(romData);

            video.InitializeColors();
            video.InitializePalettes();
            video.InitializeTiles();
            video.InitializeSprites();

            // Arrange: Load a VRAM dump which contains tiles positions and palettes for each tile.

            var rawMemory = new byte[0xFFFF];

            var vram = File.ReadAllBytes($"../../../TestData/{vramFile}");

            Array.Copy(vram, 0, rawMemory, 0x4000, 0x0800);

            var memory = new SimpleMemory(rawMemory);

            // Act: Render the image based on the tiles and palettes in memory.

            var spriteCoordinates = new byte[16];
            var image             = video.Render(memory, spriteCoordinates, flipScreen);

            // Assert: the rendered image should be the same as the reference image.

            byte[] actualBytes = null;

            using (var steam = new MemoryStream())
            {
                image.Save(steam, new BmpEncoder());
                actualBytes = steam.ToArray();
            }

            var expectedBytes = File.ReadAllBytes($"../../../ReferenceData/{expectedBitmapFile}");

            Assert.Equal(expectedBytes, actualBytes);
        }