diff --git a/gba/cartest/Makefile b/gba/cartest/Makefile new file mode 100644 index 0000000..d172c22 --- /dev/null +++ b/gba/cartest/Makefile @@ -0,0 +1,137 @@ +#--------------------------------------------------------------------------------- +# Clear the implicit built in rules +#--------------------------------------------------------------------------------- +.SUFFIXES: +#--------------------------------------------------------------------------------- +ifeq ($(strip $(DEVKITARM)),) +$(error "Please set DEVKITARM in your environment. export DEVKITARM=devkitARM) +endif + +include $(DEVKITARM)/gba_rules + +#--------------------------------------------------------------------------------- +# TARGET is the name of the output, if this ends with _mb generates a multiboot image +# 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 +#--------------------------------------------------------------------------------- +TARGET := logosplash_mb +BUILD := build +SOURCES := src data +INCLUDES := + +#--------------------------------------------------------------------------------- +# options for code generation +#--------------------------------------------------------------------------------- +ARCH := -mthumb -mthumb-interwork + +CFLAGS := -g -Wall -O0\ + -mcpu=arm7tdmi -mtune=arm7tdmi\ + -fomit-frame-pointer\ + -ffast-math \ + $(ARCH) + +CFLAGS += $(INCLUDE) + +ASFLAGS := $(ARCH) +LDFLAGS = -g $(ARCH) -Wl,-Map,$(notdir $@).map + +#--------------------------------------------------------------------------------- +# path to tools - this can be deleted if you set the path in windows +#--------------------------------------------------------------------------------- +export PATH := $(DEVKITARM)/bin:$(PATH) + +#--------------------------------------------------------------------------------- +# any extra libraries we wish to link with the project +#--------------------------------------------------------------------------------- +LIBS := -lgba + +#--------------------------------------------------------------------------------- +# list of directories containing libraries, this must be the top level containing +# include and lib +#--------------------------------------------------------------------------------- +LIBDIRS := $(LIBGBA) + +#--------------------------------------------------------------------------------- +# 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)) +export PATH := $(DEVKITARM)/bin:$(PATH) +export DEPSDIR := $(CURDIR)/$(BUILD) + +#--------------------------------------------------------------------------------- +# automatically build a list of object files for our project +#--------------------------------------------------------------------------------- +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,$(SOURCES),$(notdir $(wildcard $(dir)/*.bin))) + +#--------------------------------------------------------------------------------- +# use CXX for linking C++ projects, CC for standard C +#--------------------------------------------------------------------------------- +ifeq ($(strip $(CPPFILES)),) +#--------------------------------------------------------------------------------- + export LD := $(CC) +#--------------------------------------------------------------------------------- +else +#--------------------------------------------------------------------------------- + export LD := $(CXX) +#--------------------------------------------------------------------------------- +endif +#--------------------------------------------------------------------------------- + +export OFILES := $(BINFILES:.bin=.o) $(PCXFILES:.pcx=.o) $(CPPFILES:.cpp=.o) $(CFILES:.c=.o) $(SFILES:.s=.o) + +#--------------------------------------------------------------------------------- +# build a list of include paths +#--------------------------------------------------------------------------------- +export INCLUDE := $(foreach dir,$(INCLUDES),-I$(CURDIR)/$(dir)) \ + $(foreach dir,$(LIBDIRS),-I$(dir)/include) \ + -I$(CURDIR)/$(BUILD) + +#--------------------------------------------------------------------------------- +# build a list of library paths +#--------------------------------------------------------------------------------- +export LIBPATHS := $(foreach dir,$(LIBDIRS),-L$(dir)/lib) + +.PHONY: $(BUILD) clean + +#--------------------------------------------------------------------------------- +$(BUILD): + @[ -d $@ ] || mkdir -p $@ + @make --no-print-directory -C $(BUILD) -f $(CURDIR)/Makefile + +all : $(BUILD) +#--------------------------------------------------------------------------------- +clean: + @echo clean ... + @rm -fr $(BUILD) $(TARGET).elf $(TARGET).gba + +#--------------------------------------------------------------------------------- +else + +DEPENDS := $(OFILES:.o=.d) + +#--------------------------------------------------------------------------------- +# main targets +#--------------------------------------------------------------------------------- +$(OUTPUT).gba : $(OUTPUT).elf + +$(OUTPUT).elf : $(OFILES) + +%.o : %.bin + @echo $(notdir $<) + @$(bin2o) + +-include $(DEPENDS) + +#--------------------------------------------------------------------------------- +endif +#--------------------------------------------------------------------------------- diff --git a/gba/cartest/data/car_orig.pcx b/gba/cartest/data/car_orig.pcx new file mode 100644 index 0000000..827b61e Binary files /dev/null and b/gba/cartest/data/car_orig.pcx differ diff --git a/gba/cartest/src/logosplash.c b/gba/cartest/src/logosplash.c new file mode 100644 index 0000000..351a1a2 --- /dev/null +++ b/gba/cartest/src/logosplash.c @@ -0,0 +1,138 @@ +//--------------------------------------------------------------------------------- +// Initial code from devkitARM - http://www.devkit.tk +//--------------------------------------------------------------------------------- +#include "gba_video.h" +#include "gba_systemcalls.h" +#include "gba_input.h" +#include "gba_interrupt.h" +#include "gba_sprites.h" +#include "gba_dma.h" +#include "pcx.h" +#include "fade.h" + +#include +#include + +//--------------------------------------------------------------------------------- +// header for binary data generated by bin2o macro in makefile +//--------------------------------------------------------------------------------- +#include "s_piece_bin.h" +#include "helds_logo_bin.h" +#include "helds_pal_bin.h" +#include "frog_bin.h" +#include "turret_bin.h" + +//--------------------------------------------------------------------------------- +// storage space for palette data +//--------------------------------------------------------------------------------- +u16 PaletteBuffer[256]; +OBJATTR s_sprite, frog_sprite; + +unsigned int frame; + +typedef struct +{ + OBJATTR oam; + u8 frames; + u8 direction; + s8 frame; +} AnimSprite; + +AnimSprite turret; + +//--------------------------------------------------------------------------------- +void VblankInterrupt() +//--------------------------------------------------------------------------------- +{ + frame += 1; + ScanKeys(); +} + +void move_show_and_wait(u16 x, u16 y, u16 wait_ticks) { + // assume we are in vblank + s_sprite.attr1 = OBJ_X(x); + s_sprite.attr0 = OBJ_256_COLOR | OBJ_Y(y); + CpuFastSet(&s_sprite, OAM, COPY32 | sizeof(s_sprite)/4); + u16 i; + for (i=0; ioam.attr2 = OBJ_CHAR(char_base + sprite->frame*8); + VBlankIntrWait(); + CpuFastSet(&sprite->oam, OAM + oam_index*sizeof(OBJATTR), + COPY32 | sizeof(OBJATTR)/4); +} + +//--------------------------------------------------------------------------------- +// Program entry point +//--------------------------------------------------------------------------------- +int main(void) +//--------------------------------------------------------------------------------- +{ + // Set up the interrupt handlers + InitInterrupt(); + + SetInterrupt( IE_VBL, VblankInterrupt); + + // Enable Vblank Interrupt to allow VblankIntrWait + EnableInterrupt(IE_VBL); + + // Allow Interrupts + REG_IME = 1; + + // screen mode, background and objects to display + SetMode( MODE_4 | BG2_ON | OBJ_ON | OBJ_1D_MAP ); + + CpuFastSet(helds_logo_bin, (u16*)VRAM, COPY32 | helds_logo_bin_size/4); + CpuFastSet(helds_pal_bin, PaletteBuffer, COPY32 | helds_pal_bin_size / 4); + FadeToPalette( PaletteBuffer, 60); + + CpuFastSet(s_piece_bin, BITMAP_OBJ_BASE_ADR, COPY32 | s_piece_bin_size/4); + CpuFastSet(frog_bin, BITMAP_OBJ_BASE_ADR + s_piece_bin_size, + COPY32 | frog_bin_size/4); + CpuFastSet(turret_bin, BITMAP_OBJ_BASE_ADR + s_piece_bin_size + frog_bin_size, + COPY32 | turret_bin_size/4); + CpuFastSet(PaletteBuffer, OBJ_COLORS, COPY32 | sizeof(PaletteBuffer)/4); + + memset(&s_sprite, 0, sizeof(s_sprite)); + memset(&frog_sprite, 0, sizeof(frog_sprite)); + memset(&turret, 0, sizeof(turret)); + s_sprite.attr2 = OBJ_CHAR(512); + + frog_sprite.attr2 = OBJ_CHAR(514); + frog_sprite.attr1 = OBJ_SIZE(1) | OBJ_X(175); + frog_sprite.attr0 = OBJ_256_COLOR | OBJ_Y(49); + + // each frame is 16x16=256 bytes + turret.frames = 5; + turret.oam.attr2 = OBJ_CHAR(516); + turret.oam.attr1 = OBJ_SIZE(1) | OBJ_X(43); + turret.oam.attr0 = OBJ_256_COLOR | OBJ_Y(73); + + VBlankIntrWait(); + CpuFastSet(&frog_sprite, OAM + sizeof(s_sprite), COPY32 | sizeof(frog_sprite)/4); + + u16 i; + + while (1) + { + for (i=0; i<3; i++) VBlankIntrWait(); + + if (turret.direction) + turret.frame += 1; + else + turret.frame -= 1; + + if (turret.frame >= turret.frames) { + turret.frame = turret.frames - 1; + turret.direction = 0; + } else if (turret.frame < 0) { + turret.frame = 0; + turret.direction = 1; + } + update_sprite(&turret, 522, 2); + } +} + +