Page 1 of 1

TileNipper: My graphics tile manipulation tool

Posted: Sun Dec 01, 2019 8:55 am
by gravelstudios
I realize this is well-trod ground already, but since switching my project from CNROM to UNROM I needed a tool for manipulating my CHR tile files more than TileLayerPro would allow for. So I made it myself. Introducing TileNipper, a command line tool for resizing and compressing data files.

the compression it uses is a very simple RLE scheme in which a positive control byte means copy that many following bytes in a row, a negative control byte means copy the following byte that many times, and a zero means end of data. I've used it on my own graphics tile data so far with decent results (I know there are compression schemes that would do much better than this, but I wanted something simple and easy to program). This code can be used to decompress the data:

Code: Select all

	LDY #0							;Y stays fixed on 0. increments are done on the pointers directly.
		LDA [pointerLo], Y 
		BEQ .Exit					;zero control byte is end of data. exit.
		TAX							;otherwise, it indicates the number of tiles to load.
		JSR IncrementPointers	;go to the first byte in the run.
		BMI .LoadRun				;a negative control byte indicates a run of identical tiles.
		JSR LoadNonCompressedTileBlock
		JMP .Loop
		LDA [pointerLo], Y 
		STA $2007
		BNE .LoadRun
		JSR IncrementPointers
		JMP .Loop
	LoadNonCompressedTileBlock:	;takes X as number of bytes to transfer.
	LDY #0
		LDA [pointerLo], Y 
		STA $2007
		JSR IncrementPointers
		BNE .Loop
		LDA <pointerLo
		ADC #1
		STA <pointerLo
		LDA <pointerHi
		ADC #0
		STA <pointerHi	
I'm curious what everybody thinks about this. I've already been using it in my own project, and have been happy with it. The compression works better on larger chunks of data than smaller chunks, and it works better the more repetitive the data is. Worst case is that a file ends up being two bytes larger (one at the beginning to indicate the length of the run of bytes [which is the whole file if nothing can be repeated], and a zero added to the end). Even without compression, It's nice to be able to break metatiles out into individual files and give them their own labels rather than always having everything in one single 8Kb chr file. Anyway, if anybody else might find this useful, please feel free to avail yourself of it.

Re: TileNipper: My graphics tile manipulation tool

Posted: Sun Dec 01, 2019 9:37 am
by tepples
Just from the description, it sounds a lot like Apple PackBits.