add makefile, cfg and chr files

This commit is contained in:
Safyrus 2022-02-03 21:12:30 +01:00
parent 76f100b8cb
commit 29114cbd2a
3 changed files with 160 additions and 0 deletions

25
Boilerplate.cfg Normal file
View File

@ -0,0 +1,25 @@
MEMORY {
ZP: start = $0000, size = $0100, type = rw, define = yes;
OAM: start = $0200, size = $0100, type = rw, define = yes;
RAM: start = $0300, size = $0500, type = rw, define = yes;
HEADER: start = $0000, size = $0010, type = ro, file = %O, fill = yes, fillval = $00;
PRG: start = $8000, size = $8000, type = ro, file = %O, fill = yes, fillval = $00, define = yes;
CHR: start = $0000, size = $2000, type = ro, file = %O, fill = yes, fillval = $00;
}
SEGMENTS {
HEADER: load = HEADER, type = ro;
STARTUP: load = PRG, type = ro, define = yes;
LOWCODE: load = PRG, type = ro, optional = yes;
INIT: load = PRG, type = ro, define = yes, optional = yes;
CODE: load = PRG, type = ro, define = yes;
RODATA: load = PRG, type = ro, define = yes;
DATA: load = PRG, run = RAM, type = rw, define = yes;
ONCE: load = PRG, type = ro, define = yes, optional = yes;
VECTORS: load = PRG, type = ro, start = $FFFA;
OAM: load = OAM, type = rw;
BSS: load = RAM, type = bss, define = yes;
HEAP: load = RAM, type = bss, optional = yes;
ZEROPAGE: load = ZP, type = zp;
CHARS: load = CHR, type = ro;
}

BIN
Boilerplate.chr Normal file

Binary file not shown.

135
Makefile Normal file
View File

@ -0,0 +1,135 @@
# - - - - - - - - - - - - - #
# Variables to change #
# - - - - - - - - - - - - - #
# CC65 executable locations
CC65 = ../../cc65/bin/cc65.exe
# CA65 executable locations
CA65 = ../../cc65/bin/ca65.exe
# LD65 executable locations
LD65 = ../../cc65/bin/ld65.exe
# NES lib locations
NESLIB = ../../cc65/lib/nes.lib
# asminc folder locations
ASMINC = ../../cc65/asminc
# Emulator executable location
EMULATOR = ../../Mesen/Mesen.exe
# Hexdump executable location
HEXDUMP = ..\..\hexdump.exe
# Game name
GAME_NAME = Boilerplate
# Folder with h files to include
INC = include
# Folder with c sources files
SRC = src
# Bin folder for binary output
BIN = bin
# Folder with assembler sources files
ASM = asm
# Change this to 0 if you don't want FamiStudio
FAMISTUDIO = 1
# ! - - - - - - - - - - - - - - - - ! #
# DO NOT CHANGE ANYTHING AFTER THIS #
# ! - - - - - - - - - - - - - - - - ! #
# get all c files
SRCFILE = $(call rwildcard,$(SRC),*.c)
rwildcard=$(foreach d,$(wildcard $(1:=/*)),$(call rwildcard,$d,$2) $(filter $(subst *,%,$2),$d))
# make the nes game from assembler files and from c files
all:
make asm
make c
# make the nes game from c files
c: $(GAME_NAME)_c.nes
make clean
# make the nes game from assembler files
asm: $(GAME_NAME)_a.nes
make clean
# create the nes file from assembler sources
$(GAME_NAME)_a.nes:
# create folder if it does not exist
@-if not exist "$(BIN)" ( mkdir "$(BIN)" )
# assemble main file
.\$(CA65) asm/crt0.asm -o $(BIN)/$(GAME_NAME).o --debug-info -DFAMISTUDIO=$(FAMISTUDIO)
# link files
.\$(LD65) $(BIN)/$(GAME_NAME).o -C $(GAME_NAME).cfg -o $(GAME_NAME)_a.nes --dbgfile $(GAME_NAME)_a.DBG
# create the nes file from c sources
$(GAME_NAME)_c.nes: $(addprefix $(BIN)/,$(SRCFILE:.c=.o))
# assemble main file
$(CA65) $(ASM)/crt0.asm -g -o $(BIN)/$(GAME_NAME).o -I$(ASMINC) -DC_CODE -DFAMISTUDIO=$(FAMISTUDIO)
# link files
$(LD65) $(BIN)/$(GAME_NAME).o $^ -C $(GAME_NAME).cfg -o $@ $(NESLIB) --dbgfile $(GAME_NAME)_c.DBG
# assemble object files
$(BIN)/%.o: $(BIN)/%.asm
# create folder if it does not exist
@-if not exist "$(@D)" ( mkdir "$(@D)" )
# assemble a file
$(CA65) -g -I$(INC) -I$(ASMINC) -o $@ $^ -DC_CODE -DFAMISTUDIO=$(FAMISTUDIO)
# compile c files
$(BIN)/%.asm: %.c
# create folder if it does not exist
@-if not exist "$(@D)" ( mkdir "$(@D)" )
# compile a file
$(CC65) -O -g -I$(INC) -I$(ASM) -o $@ $^ $(NESLIB) --add-source
# clean object files
clean:
@-if exist "$(BIN)" ( rmdir /Q /S "$(BIN)" )
# clean all generated files
clean_all:
make clean
del $(GAME_NAME)_a.nes
del $(GAME_NAME)_a.DBG
del $(GAME_NAME)_c.nes
del $(GAME_NAME)_c.DBG
del dump_$(GAME_NAME)_a.txt
del dump_$(GAME_NAME)_c.txt
# run the nes game generated with c sources
run_c:
$(EMULATOR) $(GAME_NAME)_c.nes
# run the nes game generated with assembler sources
run_a:
$(EMULATOR) $(GAME_NAME)_a.nes
# dump the nes files binary into hexa text
hex:
$(HEXDUMP) $(GAME_NAME)_a.nes > dump_$(GAME_NAME)_a.txt
$(HEXDUMP) $(GAME_NAME)_c.nes > dump_$(GAME_NAME)_c.txt