#compdef rgbfix

_mbc_names() {
	local mbc_names=(
		'ROM:$00'
		'MBC1:$01'
		'MBC1+RAM:$02'
		'MBC1+RAM+BATTERY:$03'
		'MBC2:$05'
		'MBC2+BATTERY:$06'
		'ROM+RAM:$08'
		'ROM+RAM+BATTERY:$09'
		'MMM01:$0B'
		'MMM01+RAM:$0C'
		'MMM01+RAM+BATTERY:$0D'
		'MBC3+TIMER+BATTERY:$0F'
		'MBC3+TIMER+RAM+BATTERY:$10'
		'MBC3:$11'
		'MBC3+RAM:$12'
		'MBC3+RAM+BATTERY:$13'
		'MBC5:$19'
		'MBC5+RAM:$1A'
		'MBC5+RAM+BATTERY:$1B'
		'MBC5+RUMBLE:$1C'
		'MBC5+RUMBLE+RAM:$1D'
		'MBC5+RUMBLE+RAM+BATTERY:$1E'
		'MBC6:$20'
		'MBC7+SENSOR+RUMBLE+RAM+BATTERY:$22'
		'POCKET_CAMERA:$FC'
		'BANDAI_TAMA5:$FD'
		'HUC3:$FE'
		'HUC1+RAM+BATTERY:$FF'
	)
	_describe "MBC name" mbc_names
}

_rgbfix_warnings() {
	local warnings=(
		'error:Turn all warnings into errors'

		'all:Enable most warning messages'
		'everything:Enable literally everything'

		'mbc:Warn about issues with MBC specs'
		'obsolete:Warn when using deprecated features'
		'overwrite:Warn when overwriting non-zero bytes'
		'sgb:Warn when SGB flag conflicts with old licensee code'
		'truncation:Warn when values are truncated to fit'
	)
	_describe warning warnings
}

local args=(
	# Arguments are listed here in the same order as in the manual, except for the version and help
	'(- : * options)'{-V,--version}'[Print version number and exit]'
	'(- : * options)'{-h,--help}'[Print help text and exit]'

	'(-C --color-only -c --color-compatible)'{-C,--color-only}'[Mark ROM as GBC-only]'
	'(-C --color-only -c --color-compatible)'{-c,--color-compatible}'[Mark ROM as GBC-compatible]'
	'(-j --non-japanese)'{-j,--non-japanese}'[Set the non-Japanese region flag]'
	'(-O --overwrite)'{-O,--overwrite}'[Allow overwriting non-zero bytes]'
	'(-s --sgb-compatible)'{-s,--sgb-compatible}'[Set the SGB flag]'
	'(-f --fix-spec -v --validate)'{-v,--validate}'[Shorthand for -f lhg]'
	-w'[Disable all warnings]'

	--color'[Whether to use color in output]:color:(auto always never)'
	'(-f --fix-spec -v --validate)'{-f,--fix-spec}'+[Fix or trash some header values]:fix spec:'
	'(-i --game-id)'{-i,--game-id}'+[Set game ID string]:4-char game ID:'
	'(-k --new-licensee)'{-k,--new-licensee}'+[Set new licensee string]:2-char licensee ID:'
	'(-l --old-licensee)'{-l,--old-licensee}'+[Set old licensee ID]:licensee number:'
	'(-L --logo)'{-L,--logo}'+[Set custom logo]:1bpp image:'
	'(-m --mbc-type)'{-m,--mbc-type}"+[Set MBC flags]:mbc name:_mbc_names"
	'(-n --rom-version)'{-n,--rom-version}'+[Set ROM version]:rom version byte:'
	'(-o --output)'{-o,--output}"+[Output file]:output file:_files -g '*.{gb,sgb,gbc}'"
	'(-p --pad-value)'{-p,--pad-value}'+[Pad to next valid size using this byte as padding]:padding byte:'
	'(-r --ram-size)'{-r,--ram-size}'+[Set RAM size]:ram size byte:'
	'(-t --title)'{-t,--title}'+[Set title string]:11-char title string:'
	'(-W --warning)'{-W,--warning}'+[Toggle warning flags]:warning flag:_rgbfix_warnings'

	'*'":ROM files:_files -g '*.{gb,sgb,gbc}'"
)
_arguments -s -S : $args
