From 0982322d9c4a66da2e0a3b4a3872ed4574db1f93 Mon Sep 17 00:00:00 2001 From: Alexey 'Cluster' Avdyukhin Date: Tue, 25 Oct 2022 23:18:17 +0400 Subject: Examples --- Examples/README.md | 3 + Examples/mmc3_split2_animation/Makefile | 55 ++++++ Examples/mmc3_split2_animation/main.asm | 293 ++++++++++++++++++++++++++++++++ Examples/mmc3_split4/Makefile | 52 ++++++ Examples/mmc3_split4/main.asm | 260 ++++++++++++++++++++++++++++ Examples/nrom_group_scroll/Makefile | 49 ++++++ Examples/nrom_group_scroll/main.asm | 182 ++++++++++++++++++++ Examples/nrom_simple/Makefile | 45 +++++ Examples/nrom_simple/main.asm | 139 +++++++++++++++ Examples/nrom_simple_offset/Makefile | 46 +++++ Examples/nrom_simple_offset/main.asm | 139 +++++++++++++++ Examples/nrom_split/Makefile | 50 ++++++ Examples/nrom_split/main.asm | 164 ++++++++++++++++++ Examples/nrom_split_lossy/Makefile | 54 ++++++ Examples/nrom_split_lossy/main.asm | 164 ++++++++++++++++++ Examples/nrom_split_lossy/preview1.png | Bin 0 -> 5647 bytes Examples/nrom_split_lossy/preview2.png | Bin 0 -> 4613 bytes Examples/sprites8x16/Makefile | 38 +++++ Examples/sprites8x16/main.asm | 151 ++++++++++++++++ Examples/sprites8x8/Makefile | 38 +++++ Examples/sprites8x8/main.asm | 155 +++++++++++++++++ NesTiler/FastBitmap.cs | 122 ++++++------- Samples/mmc3_split2_animation/Makefile | 55 ------ Samples/mmc3_split2_animation/main.asm | 293 -------------------------------- Samples/mmc3_split4/Makefile | 52 ------ Samples/mmc3_split4/main.asm | 260 ---------------------------- Samples/nrom_group_scroll/Makefile | 49 ------ Samples/nrom_group_scroll/main.asm | 182 -------------------- Samples/nrom_simple/Makefile | 45 ----- Samples/nrom_simple/main.asm | 139 --------------- Samples/nrom_simple_offset/Makefile | 46 ----- Samples/nrom_simple_offset/main.asm | 139 --------------- Samples/nrom_split/Makefile | 50 ------ Samples/nrom_split/main.asm | 164 ------------------ Samples/nrom_split_lossy/Makefile | 54 ------ Samples/nrom_split_lossy/main.asm | 164 ------------------ Samples/nrom_split_lossy/preview1.png | Bin 5647 -> 0 bytes Samples/nrom_split_lossy/preview2.png | Bin 4613 -> 0 bytes Samples/sprites8x16/Makefile | 38 ----- Samples/sprites8x16/main.asm | 151 ---------------- Samples/sprites8x8/Makefile | 38 ----- Samples/sprites8x8/main.asm | 155 ----------------- 42 files changed, 2138 insertions(+), 2135 deletions(-) create mode 100644 Examples/README.md create mode 100644 Examples/mmc3_split2_animation/Makefile create mode 100644 Examples/mmc3_split2_animation/main.asm create mode 100644 Examples/mmc3_split4/Makefile create mode 100644 Examples/mmc3_split4/main.asm create mode 100644 Examples/nrom_group_scroll/Makefile create mode 100644 Examples/nrom_group_scroll/main.asm create mode 100644 Examples/nrom_simple/Makefile create mode 100644 Examples/nrom_simple/main.asm create mode 100644 Examples/nrom_simple_offset/Makefile create mode 100644 Examples/nrom_simple_offset/main.asm create mode 100644 Examples/nrom_split/Makefile create mode 100644 Examples/nrom_split/main.asm create mode 100644 Examples/nrom_split_lossy/Makefile create mode 100644 Examples/nrom_split_lossy/main.asm create mode 100644 Examples/nrom_split_lossy/preview1.png create mode 100644 Examples/nrom_split_lossy/preview2.png create mode 100644 Examples/sprites8x16/Makefile create mode 100644 Examples/sprites8x16/main.asm create mode 100644 Examples/sprites8x8/Makefile create mode 100644 Examples/sprites8x8/main.asm delete mode 100644 Samples/mmc3_split2_animation/Makefile delete mode 100644 Samples/mmc3_split2_animation/main.asm delete mode 100644 Samples/mmc3_split4/Makefile delete mode 100644 Samples/mmc3_split4/main.asm delete mode 100644 Samples/nrom_group_scroll/Makefile delete mode 100644 Samples/nrom_group_scroll/main.asm delete mode 100644 Samples/nrom_simple/Makefile delete mode 100644 Samples/nrom_simple/main.asm delete mode 100644 Samples/nrom_simple_offset/Makefile delete mode 100644 Samples/nrom_simple_offset/main.asm delete mode 100644 Samples/nrom_split/Makefile delete mode 100644 Samples/nrom_split/main.asm delete mode 100644 Samples/nrom_split_lossy/Makefile delete mode 100644 Samples/nrom_split_lossy/main.asm delete mode 100644 Samples/nrom_split_lossy/preview1.png delete mode 100644 Samples/nrom_split_lossy/preview2.png delete mode 100644 Samples/sprites8x16/Makefile delete mode 100644 Samples/sprites8x16/main.asm delete mode 100644 Samples/sprites8x8/Makefile delete mode 100644 Samples/sprites8x8/main.asm diff --git a/Examples/README.md b/Examples/README.md new file mode 100644 index 0000000..23079fc --- /dev/null +++ b/Examples/README.md @@ -0,0 +1,3 @@ +# NesTiler usage examples + + diff --git a/Examples/mmc3_split2_animation/Makefile b/Examples/mmc3_split2_animation/Makefile new file mode 100644 index 0000000..4b75587 --- /dev/null +++ b/Examples/mmc3_split2_animation/Makefile @@ -0,0 +1,55 @@ +NESASM=nesasm +EMU=fceux64 +TILER=nestiler +SOURCE=main.asm +EXECUTABLE=mmc3_split2_animation.nes + +IMAGE1?=../../TestImages/Images/jurassic.png +IMAGE2?=../../TestImages/Images/jurassic2.png + +HEIGHT1?=128 + +PATTERN_0_BIN=pattern_0.bin +PATTERN_1_BIN=pattern_1.bin +PATTERN_2_BIN=pattern_2.bin +PATTERN_3_BIN=pattern_3.bin +NAME_TABLE_0_BIN=name_table_0.bin +NAME_TABLE_1_BIN=name_table_1.bin +NAME_TABLE_2_BIN=name_table_2.bin +NAME_TABLE_3_BIN=name_table_3.bin +ATTR_TABLE_0_BIN=attr_table_0.bin +ATTR_TABLE_1_BIN=attr_table_1.bin +ATTR_TABLE_2_BIN=attr_table_2.bin +ATTR_TABLE_3_BIN=attr_table_3.bin +PALETTE_0_BIN=palette_0.bin +PALETTE_1_BIN=palette_1.bin +PALETTE_2_BIN=palette_2.bin +PALETTE_3_BIN=palette_3.bin + +build: $(EXECUTABLE) + +all: $(EXECUTABLE) + +clean: + rm -f *.nes *.lst *.nl *.bin + +run: $(EXECUTABLE) + $(EMU) $(EXECUTABLE) + +$(EXECUTABLE): $(SOURCE) \ +$(PATTERN_0_BIN) $(PATTERN_1_BIN) \ +$(NAME_TABLE_0_BIN) $(NAME_TABLE_1_BIN) \ +$(ATTR_TABLE_0_BIN) $(ATTR_TABLE_1_BIN) \ +$(PALETTE_0_BIN) $(PALETTE_1_BIN) + $(NESASM) $(SOURCE) -o $(EXECUTABLE) --symbols=$(notdir $(EXECUTABLE)) -iWss + +$(PATTERN_0_BIN) $(PATTERN_1_BIN) $(PATTERN_2_BIN) $(PATTERN_3_BIN) \ +$(NAME_TABLE_0_BIN) $(NAME_TABLE_1_BIN) $(NAME_TABLE_2_BIN) $(NAME_TABLE_3_BIN) \ +$(ATTR_TABLE_0_BIN) $(ATTR_TABLE_1_BIN) $(ATTR_TABLE_2_BIN) $(ATTR_TABLE_3_BIN) \ +$(PALETTE_0_BIN) $(PALETTE_1_BIN) $(PALETTE_2_BIN) $(PALETTE_3_BIN): $(IMAGE1) $(IMAGE2) + $(TILER) --mode bg --enable-palettes 0,1,2,3 \ + --in-0 $(IMAGE1):0:$(HEIGHT1) --in-1 $(IMAGE1):$(HEIGHT1) --in-2 $(IMAGE2):0:$(HEIGHT1) --in-3 $(IMAGE2):$(HEIGHT1) \ + --out-pattern-table-0 $(PATTERN_0_BIN) --out-pattern-table-1 $(PATTERN_1_BIN) --out-pattern-table-2 $(PATTERN_2_BIN) --out-pattern-table-3 $(PATTERN_3_BIN) \ + --out-name-table-0 $(NAME_TABLE_0_BIN) --out-name-table-1 $(NAME_TABLE_1_BIN) --out-name-table-2 $(NAME_TABLE_2_BIN) --out-name-table-3 $(NAME_TABLE_3_BIN) \ + --out-attribute-table-0 $(ATTR_TABLE_0_BIN) --out-attribute-table-1 $(ATTR_TABLE_1_BIN) --out-attribute-table-2 $(ATTR_TABLE_2_BIN) --out-attribute-table-3 $(ATTR_TABLE_3_BIN) \ + --out-palette-0 $(PALETTE_0_BIN) --out-palette-1 $(PALETTE_1_BIN) --out-palette-2 $(PALETTE_2_BIN) --out-palette-3 $(PALETTE_3_BIN) diff --git a/Examples/mmc3_split2_animation/main.asm b/Examples/mmc3_split2_animation/main.asm new file mode 100644 index 0000000..a4a4ad8 --- /dev/null +++ b/Examples/mmc3_split2_animation/main.asm @@ -0,0 +1,293 @@ + ; INES header stuff + .inesprg 1 ; 1 bank of PRG + .ineschr 2 ; 2 banks of CHR data + .inesmap 4 ; we use mapper 4 (MMC3) + + .rsset $0000 ; variables +COPY_SOURCE_ADDR .rs 2 +COPY_DEST_ADDR .rs 2 +CHR_BANK .rs 1 +FRAME .rs 1 + + .bank 1 + .org $FFFA ; reset vectors + .dw NMI + .dw Start + .dw IRQ + + .bank 0 + .org $C000 ; code starts here +Start: + ; disable interrupts + sei + ; reset stack + ldx #$ff + txs + + ; disable PPU + lda #%00000000 + sta PPUCTRL + lda #%00000000 + sta PPUMASK + + jsr waitblank_simple + + ; reset sound + lda #0 + sta $4000 + sta $4001 + sta $4002 + sta $4003 + sta $4004 + sta $4005 + sta $4006 + sta $4007 + sta $4009 + sta $400A + sta $400C + sta $400D + sta $400E + sta $400F + sta $4010 + sta $4011 + sta $4012 + sta $4013 + lda #$0F + sta $4015 + lda #$40 + sta $4017 + + ; vertical mirroring + lda #0 + sta $A000 + +load_palette: + lda #LOW(palette) + sta imagesCache = new Dictionary(); - - private FastBitmap(SKBitmap skBitmap, int verticalOffset = 0, int height = 0) - { - Width = skBitmap.Width; - Height = height <= 0 ? skBitmap.Height - verticalOffset : height; - var pixels = skBitmap.Pixels; - colors = skBitmap.Pixels.Skip(verticalOffset * Width).Take(Width * Height).Select(p => Color.FromArgb(p.Alpha, p.Red, p.Green, p.Blue)).ToArray(); - } - - public static FastBitmap Decode(string filename, int verticalOffset = 0, int height = 0) - { - using var image = SKBitmap.Decode(filename); - if (image == null) return null; - imagesCache[filename] = image; - return new FastBitmap(image, verticalOffset, height); - } - - public Color GetPixelColor(int x, int y) - { - return colors[y * Width + x]; - } - - public void SetPixelColor(int x, int y, Color color) - { - colors[y * Width + x] = color; - } - - public byte[] Encode(SKEncodedImageFormat format, int v) - { - using var skImage = new SKBitmap(Width, Height); - for (int y = 0; y < Height; y++) - { - for (int x = 0; x < Width; x++) - { - var color = colors[y * Width + x]; - var skColor = new SKColor(color.R, color.G, color.B); - skImage.SetPixel(x, y, skColor); - } - } - return skImage.Encode(format, v).ToArray(); - } - } -} +using SkiaSharp; +using System; +using System.Collections.Generic; +using System.Drawing; +using System.Linq; +using System.Runtime.CompilerServices; +using System.Text; +using System.Threading.Tasks; + +namespace com.clusterrr.Famicom.NesTiler +{ + public class FastBitmap + { + public int Width { get; } + public int Height { get; } + + private readonly Color[] colors; + private static Dictionary imagesCache = new Dictionary(); + + private FastBitmap(SKBitmap skBitmap, int verticalOffset = 0, int height = 0) + { + Width = skBitmap.Width; + Height = height <= 0 ? skBitmap.Height - verticalOffset : height; + var pixels = skBitmap.Pixels; + colors = skBitmap.Pixels.Skip(verticalOffset * Width).Take(Width * Height).Select(p => Color.FromArgb(p.Alpha, p.Red, p.Green, p.Blue)).ToArray(); + } + + public static FastBitmap Decode(string filename, int verticalOffset = 0, int height = 0) + { + using var image = SKBitmap.Decode(filename); + if (image == null) return null; + imagesCache[filename] = image; + return new FastBitmap(image, verticalOffset, height); + } + + public Color GetPixelColor(int x, int y) + { + return colors[y * Width + x]; + } + + public void SetPixelColor(int x, int y, Color color) + { + colors[y * Width + x] = color; + } + + public byte[] Encode(SKEncodedImageFormat format, int v) + { + using var skImage = new SKBitmap(Width, Height); + for (int y = 0; y < Height; y++) + { + for (int x = 0; x < Width; x++) + { + var color = colors[y * Width + x]; + var skColor = new SKColor(color.R, color.G, color.B); + skImage.SetPixel(x, y, skColor); + } + } + return skImage.Encode(format, v).ToArray(); + } + } +} diff --git a/Samples/mmc3_split2_animation/Makefile b/Samples/mmc3_split2_animation/Makefile deleted file mode 100644 index 4b75587..0000000 --- a/Samples/mmc3_split2_animation/Makefile +++ /dev/null @@ -1,55 +0,0 @@ -NESASM=nesasm -EMU=fceux64 -TILER=nestiler -SOURCE=main.asm -EXECUTABLE=mmc3_split2_animation.nes - -IMAGE1?=../../TestImages/Images/jurassic.png -IMAGE2?=../../TestImages/Images/jurassic2.png - -HEIGHT1?=128 - -PATTERN_0_BIN=pattern_0.bin -PATTERN_1_BIN=pattern_1.bin -PATTERN_2_BIN=pattern_2.bin -PATTERN_3_BIN=pattern_3.bin -NAME_TABLE_0_BIN=name_table_0.bin -NAME_TABLE_1_BIN=name_table_1.bin -NAME_TABLE_2_BIN=name_table_2.bin -NAME_TABLE_3_BIN=name_table_3.bin -ATTR_TABLE_0_BIN=attr_table_0.bin -ATTR_TABLE_1_BIN=attr_table_1.bin -ATTR_TABLE_2_BIN=attr_table_2.bin -ATTR_TABLE_3_BIN=attr_table_3.bin -PALETTE_0_BIN=palette_0.bin -PALETTE_1_BIN=palette_1.bin -PALETTE_2_BIN=palette_2.bin -PALETTE_3_BIN=palette_3.bin - -build: $(EXECUTABLE) - -all: $(EXECUTABLE) - -clean: - rm -f *.nes *.lst *.nl *.bin - -run: $(EXECUTABLE) - $(EMU) $(EXECUTABLE) - -$(EXECUTABLE): $(SOURCE) \ -$(PATTERN_0_BIN) $(PATTERN_1_BIN) \ -$(NAME_TABLE_0_BIN) $(NAME_TABLE_1_BIN) \ -$(ATTR_TABLE_0_BIN) $(ATTR_TABLE_1_BIN) \ -$(PALETTE_0_BIN) $(PALETTE_1_BIN) - $(NESASM) $(SOURCE) -o $(EXECUTABLE) --symbols=$(notdir $(EXECUTABLE)) -iWss - -$(PATTERN_0_BIN) $(PATTERN_1_BIN) $(PATTERN_2_BIN) $(PATTERN_3_BIN) \ -$(NAME_TABLE_0_BIN) $(NAME_TABLE_1_BIN) $(NAME_TABLE_2_BIN) $(NAME_TABLE_3_BIN) \ -$(ATTR_TABLE_0_BIN) $(ATTR_TABLE_1_BIN) $(ATTR_TABLE_2_BIN) $(ATTR_TABLE_3_BIN) \ -$(PALETTE_0_BIN) $(PALETTE_1_BIN) $(PALETTE_2_BIN) $(PALETTE_3_BIN): $(IMAGE1) $(IMAGE2) - $(TILER) --mode bg --enable-palettes 0,1,2,3 \ - --in-0 $(IMAGE1):0:$(HEIGHT1) --in-1 $(IMAGE1):$(HEIGHT1) --in-2 $(IMAGE2):0:$(HEIGHT1) --in-3 $(IMAGE2):$(HEIGHT1) \ - --out-pattern-table-0 $(PATTERN_0_BIN) --out-pattern-table-1 $(PATTERN_1_BIN) --out-pattern-table-2 $(PATTERN_2_BIN) --out-pattern-table-3 $(PATTERN_3_BIN) \ - --out-name-table-0 $(NAME_TABLE_0_BIN) --out-name-table-1 $(NAME_TABLE_1_BIN) --out-name-table-2 $(NAME_TABLE_2_BIN) --out-name-table-3 $(NAME_TABLE_3_BIN) \ - --out-attribute-table-0 $(ATTR_TABLE_0_BIN) --out-attribute-table-1 $(ATTR_TABLE_1_BIN) --out-attribute-table-2 $(ATTR_TABLE_2_BIN) --out-attribute-table-3 $(ATTR_TABLE_3_BIN) \ - --out-palette-0 $(PALETTE_0_BIN) --out-palette-1 $(PALETTE_1_BIN) --out-palette-2 $(PALETTE_2_BIN) --out-palette-3 $(PALETTE_3_BIN) diff --git a/Samples/mmc3_split2_animation/main.asm b/Samples/mmc3_split2_animation/main.asm deleted file mode 100644 index 1598d09..0000000 --- a/Samples/mmc3_split2_animation/main.asm +++ /dev/null @@ -1,293 +0,0 @@ - ; INES header stuff - .inesprg 1 ; 1 bank of PRG - .ineschr 2 ; 2 banks of CHR data - .inesmap 4 ; we use mapper 4 (MMC3) - - .rsset $0000 ; variables -COPY_SOURCE_ADDR .rs 2 -COPY_DEST_ADDR .rs 2 -CHR_BANK .rs 1 -FRAME .rs 1 - - .bank 1 - .org $FFFA ; reset vectors - .dw NMI - .dw Start - .dw IRQ - - .bank 0 - .org $C000 ; code starts here -Start: - ; disable interrupts - sei - ; reset stack - ldx #$ff - txs - - ; disable PPU - lda #%00000000 - sta PPUCTRL - lda #%00000000 - sta PPUMASK - - jsr waitblank_simple - - ; reset sound - lda #0 - sta $4000 - sta $4001 - sta $4002 - sta $4003 - sta $4004 - sta $4005 - sta $4006 - sta $4007 - sta $4009 - sta $400A - sta $400C - sta $400D - sta $400E - sta $400F - sta $4010 - sta $4011 - sta $4012 - sta $4013 - lda #$0F - sta $4015 - lda #$40 - sta $4017 - - ; vertical mirroring - lda #0 - sta $A000 - -load_palette: - lda #LOW(palette) - sta