ApplyPrismPatch:
	seek #zero
	set #address, PrismPatch
	set #banks, BANKS
.loop
	gethalfwordinc #length, #address
	xordata #address, #length
	add #address, #length
	subtract #length, BANK_SIZE, #length
	fillbyte #length, 0xff
	decrement #banks
	jumpnz #banks, .loop
	truncatepos
	return

HandleReleasePrismBase:
	print .message
	menu #target, YesNoMenu
	jumpnz #target, .nope
	call MakeDebugVersion
	add #address, PrismHashes, HASH_SIZE
	checksha1 #result, #address
	jumpnz #result, PatchingError
	print PatchingCompletedMessage
.nope
	exit #target

.message
	string "The selected ROM is a current release version of Pokémon Prism. Do you want to convert it to the debug version?"

HandleDebugPrismBase:
	print .message
	menu #target, YesNoMenu
	jumpnz #target, .nope
	set #address, ReleasePatch
	call ApplyIPSPatch
	checksha1 #result, PrismHashes
	jumpnz #result, PatchingError
	print PatchingCompletedMessage
.nope
	exit #target
	
.message
	string "The selected ROM is a current debug version of Pokémon Prism. Do you want to convert it to the release version?"

ConvertCrystalVersion:
	set #address, CrystalPatch
	jump ApplyIPSPatch

MakeDebugVersion:
	set #address, DebugPatch
	; fallthrough

ApplyIPSPatch:
	seek #zero
	ipspatch #result, #address
	return
