Skip to content

Instantly share code, notes, and snippets.

@city41
Created December 9, 2024 16:17
Show Gist options
  • Save city41/418b4bdef15204a32ea39b4bffada74b to your computer and use it in GitHub Desktop.
Save city41/418b4bdef15204a32ea39b4bffada74b to your computer and use it in GitHub Desktop.
# Makefile.z80Bin
#
# This Makefile takes a compiled z80 E-Reader app and bundles it up into raw cards, bmps and
# can also directly run the result in mGBA.
#
# The compiled z80 bin can either be one you have made via assembling a z80 program, or one you
# have extracted out of an existing e-reader card
#
# if using z80 assembly you wrote, then Makefile.asm might be a better template
SHELL :=/bin/bash
# the name of the z80 binary file that is the starting point of everything here
Z80_BIN_NAME=<<FILL THIS IN>>
# The primary name that will show up in the E-Reader interface
EREADER_NAME=<<FILL THIS IN>>
# The root name for the raw and bmp files, will be $OUTNAME.ereader1.raw, $OUTNAME.ereader2.raw, $OUTNAME.dotcode1.bmp, etc
OUTNAME=<<FILL THIS IN>>
# If running on Linux (and presumably MacOS), this is used to run the E-Reader tools through wine
# wine.sh is just a simple script that will take an installed wine command and allow it to run against
# exe's in the bin directory
WINE=../scripts/wine.sh
RAW2BMP=$(WINE) raw2bmp.exe
NEDCMAKE=$(WINE) nedcmake.exe
NEVPK=$(WINE) nevpk.exe
# this allows a custom mgba setup to execute and run the e-reader and have the cards ready to go
# your mgba binary
MGBA=mgbae.sh
# the location of a savestate that was taken right before scanning a card in the ereader
EREADER_MGBA_SAVESTATE=~/roms/gba/ereaderUSA_savestate
# the ereader rom
EREADER_MGBA_ROM=~/roms/gba/ereaderUSA.zip
# this craziness allows this Makefile to work no matter how many strips a given z80 binary needs
# so after nedcmake runs, if it made one raw or 8 raws, it will create new make rules for each created raw
# that way "make raws" or "make bmps" makes the correct number accounting for all needed strips
raws.mk: $(Z80_BIN_NAME).vpk
$(NEDCMAKE) -i $(Z80_BIN_NAME).vpk -o $(Z80_BIN_NAME).raw -type 1 -region 1 -name "$(EREADER_NAME)" -raw -save 0;
I=1; for r in $(Z80_BIN_NAME).raw*.raw; do \
echo "$(OUTNAME).ereader$$I.raw: $r"; \
echo " mv $$r $(OUTNAME).ereader$$I.raw"; \
echo "RAW_TARGETS += $(OUTNAME).ereader$$I.raw"; \
echo "MGBA_ECARD_FLAGS += --ecard $(OUTNAME).ereader$$I.raw"; \
echo "$(OUTNAME).ereader$$I.bmp: $(OUTNAME).ereader$$I.raw"; \
echo " $(RAW2BMP) -i $(OUTNAME).ereader$$I.raw -o $(OUTNAME).dotcode$$I -dpi 600"; \
echo "BMP_TARGETS += $(OUTNAME).ereader$$I.bmp"; \
((I = I + 1)); \
done > $@
-include raws.mk
raws: $(RAW_TARGETS)
bmps: $(BMP_TARGETS)
sav: $(OUTNAME).sav
$(OUTNAME).sav: $(Z80_ASM_NAME).vpk
$(NEFLMAKE) -i $(Z80_ASM_NAME).vpk -o $(OUTNAME).sav -type 1 -name "$(EREADER_NAME)" -region 1
$(Z80_BIN_NAME).vpk: $(Z80_BIN_NAME)
$(NEVPK) -i $(Z80_BIN_NAME) -o $(Z80_BIN_NAME).vpk -c -level 0
clean:
rm -rf $(OUTNAME).ereader*.raw $(Z80_BIN_NAME).vpk $(Z80_BIN_NAME).raw-*.raw raws.mk $(OUTNAME).dotcode*.bmp
runraws:
$(MGBA) --savestate $(EREADER_MGBA_SAVESTATE) $(EREADER_MGBA_ROM) $(MGBA_ECARD_FLAGS)
runsav: $(OUTNAME).sav
rm $(EREADER_MGBA_ROM_SAV);
cp $(OUTNAME).sav $(EREADER_MGBA_ROM_SAV);
$(MGBA) $(EREADER_MGBA_ROM)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment