TileNipper: My graphics tile manipulation tool

Discuss technical or other issues relating to programming the Nintendo Entertainment System, Famicom, or compatible systems.

Moderator: Moderators

Post Reply
User avatar
gravelstudios
Posts: 74
Joined: Mon Mar 13, 2017 5:21 pm
Contact:

TileNipper: My graphics tile manipulation tool

Post by gravelstudios » Sun Dec 01, 2019 8:55 am

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.

http://gravelstudios.com/TileNipper1.0.zip

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

LoadCompressedTileBlock:
	LDY #0							;Y stays fixed on 0. increments are done on the pointers directly.
	.Loop:
		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.
		TXA
		BMI .LoadRun				;a negative control byte indicates a run of identical tiles.
		
		.LoadUnique:
		JSR LoadNonCompressedTileBlock
		JMP .Loop
		
		.LoadRun:
		LDA [pointerLo], Y 
		STA $2007
		INX
		BNE .LoadRun
		JSR IncrementPointers
		JMP .Loop
	
	.Exit:
	RTS
	
	LoadNonCompressedTileBlock:	;takes X as number of bytes to transfer.
	LDY #0
	.Loop:
		LDA [pointerLo], Y 
		STA $2007
		JSR IncrementPointers
		DEX
		BNE .Loop
		
	RTS
	
	IncrementPointers:
		LDA <pointerLo
		CLC
		ADC #1
		STA <pointerLo
		LDA <pointerHi
		ADC #0
		STA <pointerHi	
		
	RTS
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.

tepples
Posts: 21748
Joined: Sun Sep 19, 2004 11:12 pm
Location: NE Indiana, USA (NTSC)
Contact:

Re: TileNipper: My graphics tile manipulation tool

Post by tepples » Sun Dec 01, 2019 9:37 am

Just from the description, it sounds a lot like Apple PackBits.

Post Reply