Skip to content

Commit

Permalink
Merge branch 'banked_game_data'
Browse files Browse the repository at this point in the history
  • Loading branch information
jorgegv committed Sep 25, 2021
2 parents 61cffde + 3275907 commit 95777c4
Show file tree
Hide file tree
Showing 68 changed files with 2,949 additions and 876 deletions.
182 changes: 26 additions & 156 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,52 +2,16 @@
##
## RAGE1 - Retro Adventure Game Engine, release 1
## (c) Copyright 2020 Jorge Gonzalez Villalonga <jorgegv@daikon.es>
##
## This code is ublished under a GNU GPL license version 3 or later. See
##
## This code is published under a GNU GPL license version 3 or later. See
## LICENSE file in the distribution for details.
##
##
################################################################################

# directory configurations
ENGINE_DIR = engine
BUILD_DIR = build
GENERATED_DIR = $(BUILD_DIR)/generated
GAME_SRC_DIR = $(BUILD_DIR)/game_src
GAME_DATA_DIR = $(BUILD_DIR)/game_data

# Sources
CSRC = $(wildcard $(GAME_SRC_DIR)/*.c) $(wildcard $(ENGINE_DIR)/src/*.c) $(wildcard $(GENERATED_DIR)/*.c)
ASMSRC = $(wildcard $(GAME_SRC_DIR)/*.asm) $(wildcard $(ENGINE_DIR)/src/*.asm) $(wildcard $(GENERATED_DIR)/*.asm)
SRC = $(CSRC) $(ASMSRC)

# Objs:
OBJS = $(CSRC:.c=.o) $(ASMSRC:.asm=.o)

# compiler
ZCC = zcc

# compiler flags
INC = -I$(ENGINE_DIR)/include -I$(GENERATED_DIR)
CFLAGS = +zx -vn -SO3 -m -compiler=sdcc -clib=sdcc_iy --max-allocs-per-node200000 -pragma-include zpragma.inc $(INC)
CFLAGS_TO_ASM = -a --c-code-in-asm --list

# generic rules
%.o: %.c
@echo Compiling $*.c ...
@$(ZCC) $(CFLAGS) -c $*.c

%.o: %.asm
@echo Assembling $*.asm ...
@$(ZCC) $(CFLAGS) -c $*.asm

# rule for inspecting generated asm code - run 'make myfile.c.asm' to
# get the .c.asm assembler generated from C file, with C code as comments
%.c.asm: %.c
@echo Generating ASM for $*.c ...
@$(ZCC) $(CFLAGS) $(CFLAGS_TO_ASM) -c $*.c
-include Makefile.common

# build targets
.PHONY: data all build clean data_depend build-data help
.PHONY: data all build clean clean-config data_depend build-data help

help:
@echo "============================================================"
Expand All @@ -63,136 +27,42 @@ help:
@echo "* Use 'make update-game' for updating library code in an existing game"
@echo ""

all: data_depend game.tap

build:
@$(MAKE) -s clean
@$(MAKE) -s config
@$(MAKE) -s data
@$(MAKE) -s -j8 all

# include minimal game configuration. If the Makefile has been copied to a
# Game directory 'make build' works as usual. If it is the Makefile on the
# RAGE1 directory, it will include minimal-game config and allow to use it
-include minimal-game.mk

clean:
@-rm -rf *.{lis,bin,tap,c.asm,map,log} \
$(GENERATED_DIR)/*.{c,h,map,lis,o,c.asm,dep,dmp} \
$(ENGINE_DIR)/src/*.{map,lis,o,c.asm} \
$(BUILD_DIR)/{game_src,game_data,generated} \
$(ENGINE_DIR)/src/*.{map,lis,o,c.asm} $(ENGINE_DIR)/lowmem/*.{map,lis,o,c.asm}\
$(GAME_SRC_DIR)/*.{map,lis,o,c.asm} \
$(GAME_DATA_DIR)/*.{map,lis,o,c.asm} \
2>/dev/null
clean-config:
@-rm -rf $(GAME_SRC_DIR)/* $(GAME_DATA_DIR)/* 2>/dev/null

config:
@$(MAKE) -s clean-config
@-mkdir -p $(GAME_SRC_DIR)/ $(GAME_DATA_DIR)/ $(GENERATED_DIR)/
@-rm -rf $(GAME_SRC_DIR)/* $(GAME_DATA_DIR)/* 2>/dev/null
@-mkdir -p $(GAME_SRC_DIR)/ $(GAME_DATA_DIR)/ $(GENERATED_DIR)/ $(GENERATED_DIR_DATASETS)/ $(GENERATED_DIR_LOWMEM)/
@cp -r game/game_data/* $(GAME_DATA_DIR)/
@cp -r game/game_src/* $(GAME_SRC_DIR)/
@echo "Build config: REGULAR GAME"
@grep -qE 'ZX_TARGET.+(48|128)$$' game/game_data/game_config/*.gdata || \
( echo "** Error: ZX_TARGET must be defined as 48|128" && exit 1 )
@echo "Build target: $(ZX_TARGET)K"

game.tap: $(OBJS)
@echo Bulding game.tap ...
@$(ZCC) $(CFLAGS) $(INCLUDE) $(LIBDIR) $(LIBS) $(OBJS) -startup=31 -create-app -o game.bin
@echo Build completed SUCCESSFULLY

##
## Generated source code targets
##

$(GENERATED_DIR)/game_data_home.c: $(GENERATED_DIR)/game_data.dep
@$(MAKE) -s data

$(GENERATED_DIR)/game_data_banked.c: $(GENERATED_DIR)/game_data.dep
build:
@$(MAKE) -s clean
@$(MAKE) -s config
@$(MAKE) -s data
@$(MAKE) -s -f Makefile-$(ZX_TARGET) build

$(GENERATED_DIR)/game_data.dep: data_depend

data:
@./tools/datagen.pl -c -d $(GENERATED_DIR) $(GAME_DATA_DIR)/{game_config,btiles,sprites,map,heroes,flow}/*.gdata

data_depend:
@if [ ! -f $(GENERATED_DIR)/game_data.dep ]; then ls -1 $(GAME_DATA_DIR)/{game_config,btiles,sprites,map,heroes}/*.gdata | xargs -l stat -c '%n%Y' | sha256sum > $(GENERATED_DIR)/game_data.dep; fi
@ls -1 $(GAME_DATA_DIR)/{game_config,btiles,sprites,map,heroes}/*.gdata | xargs -l stat -c '%n%Y' | sha256sum > /tmp/game_data.dep
@if ( ! cmp -s $(GENERATED_DIR)/game_data.dep /tmp/game_data.dep ) then rm $(GENERATED_DIR)/game_data.dep; mv /tmp/game_data.dep $(GENERATED_DIR)/game_data.dep; fi

##
## Run options and target
##

FUSE_RUN_OPTS=--machine 48
run: game.tap
@fuse $(FUSE_RUN_OPTS) game.tap

runz: game.tap
@../zesarux/src/zesarux game.tap

##
## Tests
##

# target to build all tests
tests: test1 test2 beeptest

# individual tests

TEST1_OBJS=memory.o sp1engine.o map.o
test1: tests/test1.c $(TEST1_OBJS)
$(ZCC) $(CFLAGS) $(INCLUDE) $(LIBDIR) $(LIBS) tests/test1.c $(TEST1_OBJS) -startup=31 -create-app -o test1.bin

TEST2_OBJS=beeper.o
test2: tests/test2.c $(TEST2_OBJS)
$(ZCC) $(CFLAGS) $(INCLUDE) $(LIBDIR) $(LIBS) tests/test2.c $(TEST2_OBJS) -startup=31 -create-app -o test2.bin

BEEPTEST_OBJS=beeper.o
beeptest: tests/beeptest.c $(BEEPTEST_OBJS)
$(ZCC) $(CFLAGS) $(INCLUDE) $(LIBDIR) $(LIBS) tests/beeptest.c $(BEEPTEST_OBJS) -startup=31 -create-app -o beeptest.bin

TEXTBOX_OBJS=$(OBJS)
textbox: tests/textbox.c $(TEXTBOX_OBJS)
$(ZCC) $(CFLAGS) $(INCLUDE) $(LIBDIR) $(LIBS) tests/textbox.c $(TEXTBOX_OBJS) -startup=31 -create-app -o textbox.bin

##
## Update and sync targets for games using the library. See USAGE-OVERVIEW.md document
##

# template files and directories needed for game creation and update

# these are pure library files that will be overwritten when updating the library
# do not modify these in your game!
LIB_ENGINE_FILES = engine tools Makefile zpragma.inc .gitignore env.sh

# these are game data directories that will be copied from the template when creating
# a new game, but will _not_ be overwritten when updating the library. These contain
# your game!
LIB_GAME_DATA_DIRS = minimal_game/game_data minimal_game/game_src

# needed directories that will be created empty if they do not exist
LIB_ENGINE_EMPTY_DIRS = build/generated tests

# create a minimal game using the library
new-game:
@if [ -z "$(target)" ]; then echo "Usage: make new-game target=<game-directory>"; exit 1; fi
@if [ -d "$(target)" ]; then echo "Existing game directory $(target) found, use 'make update-game' instead"; exit 2; fi
@echo "Creating game directory $(target)..."
@mkdir -p "$(target)/game"
@echo -n "Syncing library and game template files... "
@rsync -ap $(LIB_ENGINE_FILES) "$(target)"
@rsync -ap $(LIB_GAME_DATA_DIRS) "$(target)/game"
@for i in $(LIB_ENGINE_EMPTY_DIRS); do mkdir -p "$(target)/$$i"; done
@echo "Done!"

# update the library for an existing game
update-game:
@if [ -z "$(target)" ]; then echo "Usage: make update-game target=<game-directory>"; exit 1; fi
@if [ ! -d "$(target)" ]; then echo "Game directory $(target) not found, use 'make new-game' instead"; exit 2; fi
@echo -n "Syncing library and game template files... "
@rsync -ap --delete $(LIB_ENGINE_FILES) "$(target)"
@-for i in $(LIB_ENGINE_EMPTY_DIRS); do mkdir -p "$(target)/$$i"; done 2>/dev/null
@echo "Done!"
build48:
@$(MAKE) -s clean
@$(MAKE) -s ZX_TARGET=48 config
@$(MAKE) -s ZX_TARGET=48 data
@$(MAKE) -s -f Makefile-48 build

# tools
mem:
./tools/memmap.pl game.map
build128:
@$(MAKE) -s clean
@$(MAKE) -s ZX_TARGET=128 config
@$(MAKE) -s ZX_TARGET=128 data
@$(MAKE) -s -f Makefile-128 build
60 changes: 60 additions & 0 deletions Makefile-128
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
################################################################################
##
## RAGE1 - Retro Adventure Game Engine, release 1
## (c) Copyright 2020 Jorge Gonzalez Villalonga <jorgegv@daikon.es>
##
## This code is ublished under a GNU GPL license version 3 or later. See
## LICENSE file in the distribution for details.
##
################################################################################

MYMAKE = $(MAKE) -f Makefile-128
ZPRAGMA_INC = zpragma-128.inc

# All taps
TAPS = $(BAS_LOADER_TAP) $(BSWITCH_TAP) $(BANK_TAPS) $(MAIN_TAP)

-include Makefile.common

build:
@$(MYMAKE) -s -j8 datasets
@$(MYMAKE) -s -j8 banks
@$(MYMAKE) -s bank_switcher
@$(MYMAKE) -s -j8 main
@$(MYMAKE) -s -j8 taps
@$(MYMAKE) -s final

## Banks

banks:
@echo "Building Bank binaries, BASIC loader and Dataset map..."
@./tools/r1banktool.pl -i $(GENERATED_DIR_DATASETS) -o $(GENERATED_DIR) -l $(GENERATED_DIR_LOWMEM) -b .zx0

bank_switcher: $(BSWITCH_BIN)

$(BSWITCH_BIN):
@echo "Assembling bank switch routine..."
@$(ZCC) $(CFLAGS) --list --no-crt $(BSWITCH_SRC) -o $(BSWITCH_BIN)

## Taps

taps: $(TAPS)

# we set org at 0xC000 for the banks
bank_%.tap: bank_%.bin
@echo "Creating TAP $@..."
@z88dk-appmake +zx --noloader --org 0xC000 -b $<

# we set org at 0x8184 for 128 mode, 0x5F00 for 48 mode
$(MAIN_TAP): $(MAIN_BIN)
@echo "Creating TAP $@..."
@z88dk-appmake +zx --noloader --org 0x8184 -b $<

# we set org at 0x8000 for bank switcher
$(BSWITCH_TAP): $(BSWITCH_BIN)
@echo "Creating TAP $@..."
@z88dk-appmake +zx --noloader --org 0x8000 -b $<

## Run options

FUSE_RUN_OPTS = --machine 128
36 changes: 36 additions & 0 deletions Makefile-48
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
################################################################################
##
## RAGE1 - Retro Adventure Game Engine, release 1
## (c) Copyright 2020 Jorge Gonzalez Villalonga <jorgegv@daikon.es>
##
## This code is ublished under a GNU GPL license version 3 or later. See
## LICENSE file in the distribution for details.
##
################################################################################

MYMAKE = $(MAKE) -f Makefile-48
ZPRAGMA_INC = zpragma-48.inc

# All taps
TAPS = $(BAS_LOADER_TAP) $(MAIN_TAP)

-include Makefile.common

build:
@cp $(ENGINE_DIR)/loader48/loader.bas $(BAS_LOADER)
@$(MYMAKE) -s -j8 main
@$(MYMAKE) -s -j8 taps
@$(MYMAKE) -s final

## Taps

taps: $(TAPS)

# we set org at 0x5F00 for 48 mode
$(MAIN_TAP): $(MAIN_BIN)
@echo "Creating TAP $@..."
@z88dk-appmake +zx --noloader --org 0x5F00 -b $<

## Run options

FUSE_RUN_OPTS = --machine 48
Loading

0 comments on commit 95777c4

Please sign in to comment.