display-name: "Games/Clyde's Adventure"
meta: {"Working": "Some images"}

if (file.name like "volume_1.*")
{
	image
	{
		format: "I1"		
		width: 8
		height: 8
		tile-count: 90
		tiles-across: 30
	}
}

sprite-images:
{
	0: { "number-of-images": 3, "images-before": 0},
	1: { "number-of-images": 32, "images-before": 3},
	2: { "number-of-images": 6, "images-before": 35},
	3: { "number-of-images": 1, "images-before": 41}
}


if (file.name like "volume_2.*")
{
	folder: "Sprites"	

	current-group: 0	
	image-layout-width: 320
		
	image-layout
	{
		loop (4)
		{
			current-image: 0
	
			loop (sprite-images[current-group].number-of-images)
			{
				at 0:

				image
				{
					format: "I4A1"
					plane-offset: [
						(sprite-images[current-group].images-before * 96 * 5) + (current-image * 96 * 4),
						(sprite-images[current-group].images-before * 96 * 5) + (current-image * 96 * 4) + 96,
						(sprite-images[current-group].images-before * 96 * 5) + (current-image * 96 * 4) + 96 + 96,
						(sprite-images[current-group].images-before * 96 * 5) + (current-image * 96 * 4) + 96 + 96 + 96,
						(sprite-images[current-group].images-before * 96 * 5) + (sprite-images[current-group].number-of-images * 96 * 4) + (current-image * 96)
					]

					width: 24
					height: 32

					bit-stride: width * height				
				}

				current-image = current-image + 1
			}

			current-group = current-group + 1
		}
	}
}

if (file.name like "volume_3.*")
{
	file [2]: i
	{
		unsigned32 _offset
		name: "File " + i

		offset: _offset// + 0x411

		//compressed "clydesadcomp1"
	}
}

if (file.name like "volume_4.*")
{
	file [16]: i
	{
		unsigned32 offset
		name: "File " + i
	}
}

if (file.name like "volume_5.*")
{
	file [3]: i
	{
		unsigned32 offset
		name: "File " + i

		compressed "clydesadcomp1"
		interpret-as "clydesad-fullscreen"
	}
}

if (file.name like "volume_6.*")
{
	unsigned32 first-offset
	max-file-count: (first-offset / 6)

	at 0:
	file[max-file-count]: i
	{
		unsigned32 offset
		skip-if ((offset == 0) or (i == 19))
		
		at (max-file-count * 4) + (i * 2)
		{
			unsigned16 size
		}

		if (i > 17)
		{
			interpret-as "sound-VOC"
		}

		if ((file.name like "volume_6.ca?") and (i < 13))
		{
			compressed "clydesadcomp1"
			interpret-as "clydesad-fullscreen"
		}

		name: "Data " + (i + 1)
	}
}

file-format clydesad-fullscreen
{
	image
	{
		format: "I4"
		width: 320
		height: 200
		bit-stride: width * height
	}
}

function clydesadcomp1
{
	read unsigned8 current-state

	loop while (file.remaining-bytes > 0)
	{
		if (current-state != 2)
		{
			read unsigned8 repeat
			read unsigned8 repeat-val

			loop (repeat)
			{
				write unsigned8 repeat-val
			}

			current-state = 2
		}
		else
		{
			read unsigned8 copy-count
			if (copy-count != 0xFF)
			{
				current-state = 1
			}
			else
			{
				copy-count = 0x100
			}			

			loop (copy-count)
			{
				read unsigned8 val
				write unsigned8 val
			}
		}

	}
}