Version 0.106

New in version 0.106:

  • added Shiru's NESlib RLE Nametable import/export support (code improved by Tepples)
  • now when pasting an external image if there's a single tile selected it will not crop it to 8x8 pixels
  • improved how NAW interprets NAM tile selection: single tile also selects a CHR tile, rectangle selection doesn't
  • fixed tile selection bug when selecting from bottom-right to top-left

RLE decompression code is provided in neslib, but Tepples made an improvement that is described here. Basically it removes a restriction in the original format, at a small ROM/CPU cost:

After the edits, this is how it goes:

; Used to unpack NESST rle packed nametables. Those are packed horizontally so not very
; much use for a side scroller game's stages, but still very useful for its static screens.
; Includes Tepples improvement
; Util constants
_RLE_LOW = temp
_RLE_HIGH = temp+1
_RLE_TAG = temp+2 ; this value marks the end of the sequence
_RLE_BYTE = temp+3
; Decompresses a stream compressed with Shiru RLE to video memory.
; The first byte in the stream is the run marker.
; After that, any byte other than the run marker is copied literally to the output.
; A run marker followed by a byte with value 1-255 writes
; that many copies of the most recently written byte to the stream.
; A run marker followed by 0 ends the stream.
; There appears to be no way to include the run marker in the stream, meaning nametables that use all 256 byte values cannot be packed.
; @param XA pointer to start of stream
  ; Set up
  stx <_RLE_HIGH
  lda #0
  sta <_RLE_LOW
  ; Read byte that does not appear in data, used to signal a run
  lda (_RLE_LOW),y
  sta <_RLE_TAG
  bne @tag_nowrap
    inc <_RLE_HIGH
  ; Read a byte from the stream
  lda (_RLE_LOW),y
  bne @main_nowrap
    inc <_RLE_HIGH
; If it doesn't match the run marker, output it
  cmp <_RLE_TAG
  beq @is_rle
    sta _PPUDATA_2007
    sta <_RLE_BYTE
    bne @decodeloop
  ; We just saw a run marker.  Load the length, stopping if zero
  lda (_RLE_LOW),y
  beq @done
  bne @len_nowrap
    inc <_RLE_HIGH
  ; The run marker followed by $01 means itself
  cmp #$01
  bcs @is_run
    lda <_RLE_TAG
    bcc @is_literal
  tax  ; X = length of run
  ; Output the most recent byte X times
  lda <_RLE_BYTE
    sta _PPUDATA_2007
    bne @runloop
  beq @decodeloop


Sep 14, 2022

Get NES Assets Workshop: NAW

Download NowName your own price

Leave a comment

Log in with to leave a comment.