diff --git a/.gitignore b/.gitignore index 488a764..0038c39 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,6 @@ dsgmLib/build/ +template/build/ +template/*.elf examples/*/build/ examples/*/*.elf .DS_Store \ No newline at end of file diff --git a/template/Makefile b/template/Makefile new file mode 100644 index 0000000..929de6f --- /dev/null +++ b/template/Makefile @@ -0,0 +1,144 @@ +#--------------------------------------------------------------------------------- +.SUFFIXES: +#--------------------------------------------------------------------------------- + +ifeq ($(strip $(DEVKITARM)),) +$(error "Please set DEVKITARM in your environment. export DEVKITARM=devkitARM") +endif + +include $(DEVKITARM)/ds_rules + +ifeq ($(strip $(DSGMLIB)),) +$(error "Please set in your environment. export DSGMLIB=") +endif + +#--------------------------------------------------------------------------------- +# TARGET is the name of the output +# BUILD is the directory where object files & intermediate files will be placed +# SOURCES is a list of directories containing source code +# INCLUDES is a list of directories containing extra header files +# MAXMOD_SOUNDBANK contains a directory of music and sound effect files +#--------------------------------------------------------------------------------- +TARGET := $(shell basename $(CURDIR)) +BUILD := build +SOURCES := source +DATA := data +INCLUDES := include $(DSGMLIB)/include +NITRODATA := nitrofiles +MAXMOD_SOUNDBANK := music + +#--------------------------------------------------------------------------------- +# options for code generation +#--------------------------------------------------------------------------------- +ARCH := -mthumb -mthumb-interwork -march=armv5te -mtune=arm946e-s + +CFLAGS := -g -Wall -O2 -fms-extensions\ + -fomit-frame-pointer\ + -ffast-math \ + $(ARCH) + +CFLAGS += $(INCLUDE) -DARM9 +CXXFLAGS := $(CFLAGS) -fno-rtti -fno-exceptions + +ASFLAGS := -g $(ARCH) +LDFLAGS = -specs=ds_arm9.specs -g $(ARCH) -Wl,-Map,$(notdir $*.map) + +#--------------------------------------------------------------------------------- +# any extra libraries we wish to link with the project (order is important) +#--------------------------------------------------------------------------------- +LIBS := $(DSGMLIB)/dsgmLib.a -lfilesystem -lfat -lnds9 -lmm9 + + +#--------------------------------------------------------------------------------- +# list of directories containing libraries, this must be the top level containing +# include and lib +#--------------------------------------------------------------------------------- +LIBDIRS := $(LIBNDS) $(DSGMLIB) + +#--------------------------------------------------------------------------------- +# no real need to edit anything past this point unless you need to add additional +# rules for different file extensions +#--------------------------------------------------------------------------------- +ifneq ($(BUILD),$(notdir $(CURDIR))) +#--------------------------------------------------------------------------------- + +export OUTPUT := $(CURDIR)/$(TARGET) + +export VPATH := $(foreach dir,$(SOURCES),$(CURDIR)/$(dir)) \ + $(foreach dir,$(DATA),$(CURDIR)/$(dir)) + +export DEPSDIR := $(CURDIR)/$(BUILD) + +ifneq ($(strip $(NITRODATA)),) + export NITRO_FILES := $(CURDIR)/$(NITRODATA) +endif + +CFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.c))) +CPPFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.cpp))) +SFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.s))) +BINFILES := $(foreach dir,$(DATA),$(notdir $(wildcard $(dir)/*.*))) + +export AUDIOFILES := $(foreach dir,$(notdir $(wildcard $(MAXMOD_SOUNDBANK)/*.*)),$(CURDIR)/$(MAXMOD_SOUNDBANK)/$(dir)) + +#--------------------------------------------------------------------------------- +# use CXX for linking C++ projects, CC for standard C +#--------------------------------------------------------------------------------- +ifeq ($(strip $(CPPFILES)),) +#--------------------------------------------------------------------------------- + export LD := $(CC) +#--------------------------------------------------------------------------------- +else +#--------------------------------------------------------------------------------- + export LD := $(CXX) +#--------------------------------------------------------------------------------- +endif +#--------------------------------------------------------------------------------- + +export OFILES := $(addsuffix .o,$(BINFILES)) \ + $(CPPFILES:.cpp=.o) $(CFILES:.c=.o) $(SFILES:.s=.o) + +export INCLUDE := $(foreach dir,$(INCLUDES),-I$(CURDIR)/$(dir)) \ + $(foreach dir,$(LIBDIRS),-I$(dir)/include) \ + $(foreach dir,$(LIBDIRS),-I$(dir)/include) \ + -I$(CURDIR)/$(BUILD) + +export LIBPATHS := $(foreach dir,$(LIBDIRS),-L$(dir)/lib) + +.PHONY: $(BUILD) clean + +#--------------------------------------------------------------------------------- +$(BUILD): + @[ -d $@ ] || mkdir -p $@ + @make --no-print-directory -C $(BUILD) -f $(CURDIR)/Makefile + +#--------------------------------------------------------------------------------- +clean: + @echo clean ... + @rm -fr $(BUILD) $(TARGET).elf $(TARGET).nds + +#--------------------------------------------------------------------------------- +else + +#--------------------------------------------------------------------------------- +# main targets +#--------------------------------------------------------------------------------- +$(OUTPUT).nds : $(OUTPUT).elf +$(OUTPUT).elf : $(OFILES) soundbank.h + +soundbank.h: ../$(NITRODATA)/soundbank.bin + +../$(NITRODATA)/soundbank.bin: $(AUDIOFILES) +#--------------------------------------------------------------------------------- + mmutil $^ -d -o../$(NITRODATA)/soundbank.bin -hsoundbank.h + +#--------------------------------------------------------------------------------- +%.bin.o : %.bin +#--------------------------------------------------------------------------------- + @echo $(notdir $<) + $(bin2o) + +-include $(DEPSDIR)/*.d + +#--------------------------------------------------------------------------------------- +endif +#--------------------------------------------------------------------------------------- diff --git a/template/include/project.h b/template/include/project.h new file mode 100644 index 0000000..a5e9bab --- /dev/null +++ b/template/include/project.h @@ -0,0 +1,55 @@ +#pragma once + +#define DSGM_SOUND_STREAM_COUNT 0 +#define DSGM_SOUND_EFFECT_COUNT 0 +#define DSGM_SOUND_COUNT (DSGM_SOUND_STREAM_COUNT + DSGM_SOUND_EFFECT_COUNT) +#define DSGM_BACKGROUND_COUNT 0 +#define DSGM_PALETTE_COUNT 0 +#define DSGM_SPRITE_COUNT 0 +#define DSGM_OBJECT_COUNT 1 +#define DSGM_ROOM_COUNT 1 + +// Include backgrounds, palettes and sprites to be loaded from RAM + +// No sounds, no enum +//typedef enum { +//} DSGM_SoundNames; + +// No backgrounds, no enum +//typedef enum { +//} DSGM_BackgroundNames; + +// No palettes, no enum +//typedef enum { +//} DSGM_PaletteNames; + +// No sprites, no enum +//typedef enum { +//} DSGM_SpriteNames; + +typedef enum { + hello, +} DSGM_ObjectNames; + +typedef struct { + DSGM_ObjectInstanceBase; + struct { + } *variables; +} helloObjectInstance; + +typedef enum { + Room_1, +} DSGM_RoomNames; + +extern DSGM_Sound DSGM_Sounds[DSGM_SOUND_COUNT]; +extern DSGM_Background DSGM_Backgrounds[DSGM_BACKGROUND_COUNT]; +extern DSGM_Palette DSGM_Palettes[DSGM_PALETTE_COUNT]; +extern DSGM_Sprite DSGM_Sprites[DSGM_SPRITE_COUNT]; +extern DSGM_Object DSGM_Objects[DSGM_OBJECT_COUNT]; +extern DSGM_Room DSGM_Rooms[DSGM_ROOM_COUNT]; + +extern int DSGM_currentRoom; + +void DSGM_SetupRooms(int room); + +void hello_create(helloObjectInstance *me); diff --git a/template/nitrofiles/.gitkeep b/template/nitrofiles/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/template/source/main.c b/template/source/main.c new file mode 100644 index 0000000..eff39e0 --- /dev/null +++ b/template/source/main.c @@ -0,0 +1,17 @@ +#include "DSGM.h" + +void DSGM_Init(void); + +int main(int argc, char **argv) { + DSGM_Init(); + + DSGM_LoadRoom(&DSGM_Rooms[DSGM_currentRoom]); + + while(1) { + DSGM_LoopRoom(&DSGM_Rooms[DSGM_currentRoom]); + + DSGM_Update(); + } + + return 0; +} diff --git a/template/source/project.c b/template/source/project.c new file mode 100644 index 0000000..0ed89ff --- /dev/null +++ b/template/source/project.c @@ -0,0 +1,200 @@ +#include "DSGM.h" + +#include "DSGM_projectHelper.h" + +// User variables / declarations + +// Resources +DSGM_Sound DSGM_Sounds[DSGM_SOUND_COUNT] = { +}; + +DSGM_Background DSGM_Backgrounds[DSGM_BACKGROUND_COUNT] = { +}; + +DSGM_Palette DSGM_Palettes[DSGM_PALETTE_COUNT] = { +}; + +DSGM_Sprite DSGM_Sprites[DSGM_SPRITE_COUNT] = { +}; + +DSGM_Object DSGM_Objects[DSGM_OBJECT_COUNT] = { + // hello + { + DSGM_NO_SPRITE, + (DSGM_Event)hello_create, + DSGM_NO_EVENT, + DSGM_NO_EVENT, + DSGM_NO_EVENT, + NULL, 0, + + sizeof(*((helloObjectInstance *)0)->variables) + }, +}; + +DSGM_Room DSGM_Rooms[DSGM_ROOM_COUNT] = { + // Room_1 + { + // Backgrounds + { + // Bottom screen + { + // Layer 0 + { + DSGM_TEXT_BACKGROUND, // Background + DSGM_BOTTOM, // Screen + 0, // Layer + false, // Attached to view system + 7, // Map base + 0, // Tile base + 0, 0, 0 + }, + + // Layer 1 + { + DSGM_NO_BACKGROUND, // Background + DSGM_BOTTOM, // Screen + 1, // Layer + true, // Attached to view system + 0, // Map base + 0, // Tile base + 0, 0, 0 + }, + + // Layer 2 + { + DSGM_NO_BACKGROUND, // Background + DSGM_BOTTOM, // Screen + 2, // Layer + true, // Attached to view system + 0, // Map base + 0, // Tile base + 0, 0, 0 + }, + + // Layer 3 + { + DSGM_NO_BACKGROUND, // Background + DSGM_BOTTOM, // Screen + 3, // Layer + true, // Attached to view system + 0, // Map base + 0, // Tile base + 0, 0, 0 + }, + }, + + // Top screen + { + // Layer 0 + { + DSGM_TEXT_BACKGROUND, // Background + DSGM_TOP, // Screen + 0, // Layer + false, // Attached to view system + 7, // Map base + 0, // Tile base + 0, 0, 0 + }, + + // Layer 1 + { + DSGM_NO_BACKGROUND, // Background + DSGM_TOP, // Screen + 1, // Layer + true, // Attached to view system + 0, // Map base + 0, // Tile base + 0, 0, 0 + }, + + // Layer 2 + { + DSGM_NO_BACKGROUND, // Background + DSGM_TOP, // Screen + 2, // Layer + true, // Attached to view system + 0, // Map base + 0, // Tile base + 0, 0, 0 + }, + + // Layer 3 + { + DSGM_NO_BACKGROUND, // Background + DSGM_TOP, // Screen + 3, // Layer + true, // Attached to view system + 0, // Map base + 0, // Tile base + 0, 0, 0 + }, + } + }, + + // Initial views + { + // Bottom screen + { + 0, 0 + }, + + // Top screen + { + 0, 0 + } + }, + + // Views + { + // Bottom screen + { + 0, 0 + }, + + // Top screen + { + 0, 0 + } + }, + + // Object groups are dynamic, so must be set up at run time, see DSGM_SetupRooms. + { + NULL, + NULL + }, + { + 0, + 0 + } + }, +}; + +int DSGM_currentRoom = Room_1; + +void DSGM_SetupRooms(int room) { + if(room != DSGM_ALL_ROOMS) { + switch(room) { + case Room_1: goto Room_1; break; + } + } + + Room_1: + DSGM_Debug("Room_1 reset\n"); + DSGM_LeaveRoom(&DSGM_Rooms[Room_1]); + + DSGM_SetupViews(&DSGM_Rooms[Room_1]); + + DSGM_SetupObjectGroups(&DSGM_Rooms[Room_1], DSGM_TOP, 0); + + DSGM_SetupObjectGroups(&DSGM_Rooms[Room_1], DSGM_BOTTOM, 1); + + DSGM_SetupObjectInstances(&DSGM_Rooms[Room_1].objectGroups[DSGM_BOTTOM][0], &DSGM_Objects[hello], DSGM_BOTTOM, 1, + 0, 0 + ); + + if(room != DSGM_ALL_ROOMS) return; +} + +void hello_create(helloObjectInstance *me) { + DSGM_DrawText(DSGM_BOTTOM, 1, 1, "Hello!"); +} diff --git a/template/template.nds b/template/template.nds new file mode 100644 index 0000000..b0e2c3a Binary files /dev/null and b/template/template.nds differ