# ===========================================================================
# Vectorgons -- Commodore 64 build
# ---------------------------------------------------------------------------
# Cross-compiles the C64 edition with cc65 and packs it onto a .d64 disk
# image with VICE's c1541.
#
#   make            -> vectorgons.prg  (raw C64 program, loads at $0801)
#   make d64        -> vectorgons.d64  (bootable disk image)
#   make run        -> build + launch in the VICE x64sc emulator
#   make clean
#
# cc65 need not be on PATH: set CC65_HOME / CL65 to point at an extracted
# install if it lives somewhere non-standard, e.g.
#   make CL65=/path/to/cl65 CC65_HOME=/path/to/share/cc65
# ===========================================================================

CL65      ?= cl65
C1541     ?= c1541
X64       ?= x64sc

TARGET     = vectorgons
PRG        = $(TARGET).prg
D64        = $(TARGET).d64
CFG        = c64-vg.cfg
SRC        = vectorgons.c

# Name shown in the C64 disk directory (PETSCII, <=16 chars).
DISKNAME   = vectorgons
DISKID     = vg
# Filename on the disk that the user LOADs.
DISKFILE   = vectorgons

CL65FLAGS  = -t c64 -O -C $(CFG)

.PHONY: all d64 run clean

all: $(PRG)

$(PRG): $(SRC) $(CFG)
	$(CL65) $(CL65FLAGS) $(SRC) -o $(PRG)

# Build a fresh, formatted .d64 and write the program into it.
d64: $(D64)

$(D64): $(PRG)
	$(C1541) -format "$(DISKNAME),$(DISKID)" d64 $(D64) \
	         -write $(PRG) $(DISKFILE)
	@echo "Wrote $(PRG) -> $(D64) as \"$(DISKFILE)\""
	@$(C1541) $(D64) -dir

run: $(D64)
	$(X64) -autostart $(D64)

clean:
	rm -f $(PRG) $(D64) *.map *.o shot*.png seq_*.png f_*.png
