#!/bin/bash
# verify.sh - reassemble every source file with ca65 and compare against the original bytes.
set -e
cd "$(dirname "$0")"
mkdir -p build
fail=0
ca65 -t none -I . -o build/boot_eaBootFile.o boot/eaBootFile.s && ld65 -C build/link.cfg -o build/boot_eaBootFile.bin build/boot_eaBootFile.o && (cmp -s build/boot_eaBootFile.bin build/boot_eaBootFile.orig.bin && echo 'OK   boot/eaBootFile' || { echo 'FAIL boot/eaBootFile'; fail=1; })
ca65 -t none -I . -o build/boot_fastLoaderC000.o boot/fastLoaderC000.s && ld65 -C build/link.cfg -o build/boot_fastLoaderC000.bin build/boot_fastLoaderC000.o && (cmp -s build/boot_fastLoaderC000.bin build/boot_fastLoaderC000.orig.bin && echo 'OK   boot/fastLoaderC000' || { echo 'FAIL boot/fastLoaderC000'; fail=1; })
ca65 -t none -I . -o build/boot_titleColorRam9800.o boot/titleColorRam9800.s && ld65 -C build/link.cfg -o build/boot_titleColorRam9800.bin build/boot_titleColorRam9800.o && (cmp -s build/boot_titleColorRam9800.bin build/boot_titleColorRam9800.orig.bin && echo 'OK   boot/titleColorRam9800' || { echo 'FAIL boot/titleColorRam9800'; fail=1; })
ca65 -t none -I . -o build/boot_titleScreenRam9C00.o boot/titleScreenRam9C00.s && ld65 -C build/link.cfg -o build/boot_titleScreenRam9C00.bin build/boot_titleScreenRam9C00.o && (cmp -s build/boot_titleScreenRam9C00.bin build/boot_titleScreenRam9C00.orig.bin && echo 'OK   boot/titleScreenRam9C00' || { echo 'FAIL boot/titleScreenRam9C00'; fail=1; })
ca65 -t none -I . -o build/boot_titleBitmapA000.o boot/titleBitmapA000.s && ld65 -C build/link.cfg -o build/boot_titleBitmapA000.bin build/boot_titleBitmapA000.o && (cmp -s build/boot_titleBitmapA000.bin build/boot_titleBitmapA000.orig.bin && echo 'OK   boot/titleBitmapA000' || { echo 'FAIL boot/titleBitmapA000'; fail=1; })
ca65 -t none -I . -o build/game_tileRules0200.o game/tileRules0200.s && ld65 -C build/link.cfg -o build/game_tileRules0200.bin build/game_tileRules0200.o && (cmp -s build/game_tileRules0200.bin build/game_tileRules0200.orig.bin && echo 'OK   game/tileRules0200' || { echo 'FAIL game/tileRules0200'; fail=1; })
ca65 -t none -I . -o build/game_trainerPlaybook0200.o game/trainerPlaybook0200.s && ld65 -C build/link.cfg -o build/game_trainerPlaybook0200.bin build/game_trainerPlaybook0200.o && (cmp -s build/game_trainerPlaybook0200.bin build/game_trainerPlaybook0200.orig.bin && echo 'OK   game/trainerPlaybook0200' || { echo 'FAIL game/trainerPlaybook0200'; fail=1; })
ca65 -t none -I . -o build/game_scratchAndMessages0400.o game/scratchAndMessages0400.s && ld65 -C build/link.cfg -o build/game_scratchAndMessages0400.bin build/game_scratchAndMessages0400.o && (cmp -s build/game_scratchAndMessages0400.bin build/game_scratchAndMessages0400.orig.bin && echo 'OK   game/scratchAndMessages0400' || { echo 'FAIL game/scratchAndMessages0400'; fail=1; })
ca65 -t none -I . -o build/game_mainProgram0800.o game/mainProgram0800.s && ld65 -C build/link.cfg -o build/game_mainProgram0800.bin build/game_mainProgram0800.o && (cmp -s build/game_mainProgram0800.bin build/game_mainProgram0800.orig.bin && echo 'OK   game/mainProgram0800' || { echo 'FAIL game/mainProgram0800'; fail=1; })
ca65 -t none -I . -o build/game_mapGenerator6F00.o game/mapGenerator6F00.s && ld65 -C build/link.cfg -o build/game_mapGenerator6F00.bin build/game_mapGenerator6F00.o && (cmp -s build/game_mapGenerator6F00.bin build/game_mapGenerator6F00.orig.bin && echo 'OK   game/mapGenerator6F00' || { echo 'FAIL game/mapGenerator6F00'; fail=1; })
ca65 -t none -I . -o build/game_comcenScreens6F00.o game/comcenScreens6F00.s && ld65 -C build/link.cfg -o build/game_comcenScreens6F00.bin build/game_comcenScreens6F00.o && (cmp -s build/game_comcenScreens6F00.bin build/game_comcenScreens6F00.orig.bin && echo 'OK   game/comcenScreens6F00' || { echo 'FAIL game/comcenScreens6F00'; fail=1; })
ca65 -t none -I . -o build/game_messages8800.o game/messages8800.s && ld65 -C build/link.cfg -o build/game_messages8800.bin build/game_messages8800.o && (cmp -s build/game_messages8800.bin build/game_messages8800.orig.bin && echo 'OK   game/messages8800' || { echo 'FAIL game/messages8800'; fail=1; })
ca65 -t none -I . -o build/game_graphicsData9300.o game/graphicsData9300.s && ld65 -C build/link.cfg -o build/game_graphicsData9300.bin build/game_graphicsData9300.o && (cmp -s build/game_graphicsData9300.bin build/game_graphicsData9300.orig.bin && echo 'OK   game/graphicsData9300' || { echo 'FAIL game/graphicsData9300'; fail=1; })
ca65 -t none -I . -o build/game_textEngineC000.o game/textEngineC000.s && ld65 -C build/link.cfg -o build/game_textEngineC000.bin build/game_textEngineC000.o && (cmp -s build/game_textEngineC000.bin build/game_textEngineC000.orig.bin && echo 'OK   game/textEngineC000' || { echo 'FAIL game/textEngineC000'; fail=1; })
ca65 -t none -I . -o build/game_trainerAiE000.o game/trainerAiE000.s && ld65 -C build/link.cfg -o build/game_trainerAiE000.bin build/game_trainerAiE000.o && (cmp -s build/game_trainerAiE000.bin build/game_trainerAiE000.orig.bin && echo 'OK   game/trainerAiE000' || { echo 'FAIL game/trainerAiE000'; fail=1; })
ca65 -t none -I . -o build/game_modemDriverE000.o game/modemDriverE000.s && ld65 -C build/link.cfg -o build/game_modemDriverE000.bin build/game_modemDriverE000.o && (cmp -s build/game_modemDriverE000.bin build/game_modemDriverE000.orig.bin && echo 'OK   game/modemDriverE000' || { echo 'FAIL game/modemDriverE000'; fail=1; })
ca65 -t none -I . -o build/game_trainerSetupEC00.o game/trainerSetupEC00.s && ld65 -C build/link.cfg -o build/game_trainerSetupEC00.bin build/game_trainerSetupEC00.o && (cmp -s build/game_trainerSetupEC00.bin build/game_trainerSetupEC00.orig.bin && echo 'OK   game/trainerSetupEC00' || { echo 'FAIL game/trainerSetupEC00'; fail=1; })
ca65 -t none -I . -o build/game_droneAiEE00.o game/droneAiEE00.s && ld65 -C build/link.cfg -o build/game_droneAiEE00.bin build/game_droneAiEE00.o && (cmp -s build/game_droneAiEE00.bin build/game_droneAiEE00.orig.bin && echo 'OK   game/droneAiEE00' || { echo 'FAIL game/droneAiEE00'; fail=1; })
ca65 -t none -I . -o build/game_unitStartTemplatesF000.o game/unitStartTemplatesF000.s && ld65 -C build/link.cfg -o build/game_unitStartTemplatesF000.bin build/game_unitStartTemplatesF000.o && (cmp -s build/game_unitStartTemplatesF000.bin build/game_unitStartTemplatesF000.orig.bin && echo 'OK   game/unitStartTemplatesF000' || { echo 'FAIL game/unitStartTemplatesF000'; fail=1; })
ca65 -t none -I . -o build/game_highMemoryFBB8.o game/highMemoryFBB8.s && ld65 -C build/link.cfg -o build/game_highMemoryFBB8.bin build/game_highMemoryFBB8.o && (cmp -s build/game_highMemoryFBB8.bin build/game_highMemoryFBB8.orig.bin && echo 'OK   game/highMemoryFBB8' || { echo 'FAIL game/highMemoryFBB8'; fail=1; })
ca65 -t none -I . -o build/boot_c128BootSector.o boot/c128BootSector.s && ld65 -C build/link.cfg -o build/boot_c128BootSector.bin build/boot_c128BootSector.o && (cmp -s build/boot_c128BootSector.bin build/boot_c128BootSector.orig.bin && echo 'OK   boot/c128BootSector' || { echo 'FAIL boot/c128BootSector'; fail=1; })
ca65 -t none -I . -o build/boot_c64CartridgeStub8000.o boot/c64CartridgeStub8000.s && ld65 -C build/link.cfg -o build/boot_c64CartridgeStub8000.bin build/boot_c64CartridgeStub8000.o && (cmp -s build/boot_c64CartridgeStub8000.bin build/boot_c64CartridgeStub8000.orig.bin && echo 'OK   boot/c64CartridgeStub8000' || { echo 'FAIL boot/c64CartridgeStub8000'; fail=1; })
ca65 -t none -I . -o build/drive_driveBootstrap.o drive/driveBootstrap.s && ld65 -C build/link.cfg -o build/drive_driveBootstrap.bin build/drive_driveBootstrap.o && (cmp -s build/drive_driveBootstrap.bin build/drive_driveBootstrap.orig.bin && echo 'OK   drive/driveBootstrap' || { echo 'FAIL drive/driveBootstrap'; fail=1; })
ca65 -t none -I . -o build/drive_driveFastLoader.o drive/driveFastLoader.s && ld65 -C build/link.cfg -o build/drive_driveFastLoader.bin build/drive_driveFastLoader.o && (cmp -s build/drive_driveFastLoader.bin build/drive_driveFastLoader.orig.bin && echo 'OK   drive/driveFastLoader' || { echo 'FAIL drive/driveFastLoader'; fail=1; })
exit $fail
