add test for sprite blending
This commit is contained in:
parent
c33a11ac03
commit
927189550a
|
@ -0,0 +1,138 @@
|
|||
#---------------------------------------------------------------------------------
|
||||
.SUFFIXES:
|
||||
#---------------------------------------------------------------------------------
|
||||
|
||||
ifeq ($(strip $(DEVKITARM)),)
|
||||
$(error "Please set DEVKITARM in your environment. export DEVKITARM=<path to>devkitARM")
|
||||
endif
|
||||
|
||||
include $(DEVKITARM)/ds_rules
|
||||
|
||||
#---------------------------------------------------------------------------------
|
||||
# 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
|
||||
#---------------------------------------------------------------------------------
|
||||
TARGET := $(shell basename $(CURDIR))
|
||||
BUILD := build
|
||||
SOURCES := source
|
||||
DATA :=
|
||||
INCLUDES := include
|
||||
GRAPHICS := data
|
||||
|
||||
#---------------------------------------------------------------------------------
|
||||
# options for code generation
|
||||
#---------------------------------------------------------------------------------
|
||||
ARCH := -mthumb -mthumb-interwork
|
||||
|
||||
CFLAGS := -g -Wall -O2\
|
||||
-march=armv5te -mtune=arm946e-s -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
|
||||
#---------------------------------------------------------------------------------
|
||||
LIBS := -lnds9
|
||||
|
||||
|
||||
#---------------------------------------------------------------------------------
|
||||
# list of directories containing libraries, this must be the top level containing
|
||||
# include and lib
|
||||
#---------------------------------------------------------------------------------
|
||||
LIBDIRS := $(LIBNDS)
|
||||
|
||||
#---------------------------------------------------------------------------------
|
||||
# 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)) \
|
||||
$(foreach dir,$(GRAPHICS),$(CURDIR)/$(dir))
|
||||
|
||||
export DEPSDIR := $(CURDIR)/$(BUILD)
|
||||
|
||||
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)/*.*)))
|
||||
PNGFILES := $(foreach dir,$(GRAPHICS),$(notdir $(wildcard $(dir)/*.png)))
|
||||
|
||||
#---------------------------------------------------------------------------------
|
||||
# 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)) \
|
||||
$(PNGFILES:.png=.o) \
|
||||
$(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 $(TARGET).ds.gba
|
||||
|
||||
|
||||
#---------------------------------------------------------------------------------
|
||||
else
|
||||
|
||||
DEPENDS := $(OFILES:.o=.d)
|
||||
|
||||
#---------------------------------------------------------------------------------
|
||||
# main targets
|
||||
#---------------------------------------------------------------------------------
|
||||
$(OUTPUT).nds : $(OUTPUT).elf
|
||||
$(OUTPUT).elf : $(OFILES)
|
||||
|
||||
#---------------------------------------------------------------------------------
|
||||
%.bin.o : %.bin
|
||||
#---------------------------------------------------------------------------------
|
||||
@echo $(notdir $<)
|
||||
@$(bin2o)
|
||||
|
||||
#---------------------------------------------------------------------------------
|
||||
%.s %.h : %.png %.grit
|
||||
#---------------------------------------------------------------------------------
|
||||
grit $< -fts -o$*
|
||||
|
||||
|
||||
-include $(DEPENDS)
|
||||
|
||||
#---------------------------------------------------------------------------------------
|
||||
endif
|
||||
#---------------------------------------------------------------------------------------
|
|
@ -0,0 +1,5 @@
|
|||
# 8 bit bitmap
|
||||
-gB8
|
||||
|
||||
# bitmap format
|
||||
-gb
|
Binary file not shown.
After Width: | Height: | Size: 28 KiB |
|
@ -0,0 +1,97 @@
|
|||
#include <nds.h>
|
||||
#include <nds/registers_alt.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "drunkenlogo.h"
|
||||
|
||||
int main(void)
|
||||
{
|
||||
//---------------------------------------------------------------------------------
|
||||
int i = 0;
|
||||
touchPosition touch;
|
||||
|
||||
videoSetMode(MODE_5_2D);
|
||||
videoSetModeSub(MODE_0_2D);
|
||||
|
||||
vramSetBankA(VRAM_A_MAIN_BG_0x06000000);
|
||||
vramSetBankB(VRAM_B_MAIN_SPRITE);
|
||||
|
||||
oamInit(&oamMain, SpriteMapping_1D_32, false);
|
||||
/*oamInit(&oamSub, SpriteMapping_1D_32, false);*/
|
||||
consoleDemoInit();
|
||||
int bg3 = bgInit(3, BgType_Bmp8, BgSize_B8_256x256, 0,0);
|
||||
|
||||
dmaCopy(drunkenlogoBitmap, bgGetGfxPtr(bg3), drunkenlogoBitmapLen);
|
||||
dmaCopy(drunkenlogoPal, BG_PALETTE, 256*2);
|
||||
|
||||
u16* gfx = oamAllocateGfx(&oamMain, SpriteSize_16x16, SpriteColorFormat_16Color);
|
||||
/*u16* gfxSub = oamAllocateGfx(&oamSub, SpriteSize_16x16, SpriteColorFormat_256Color);*/
|
||||
REG_BLDCNT = (1<<11) | (1<<6);
|
||||
|
||||
REG_WININ = 0x3F; //display everything, including color special effects, in window 0
|
||||
REG_WINOUT = 0x1F; //display everything, excluding color special effects, outside window 0
|
||||
REG_WIN0H = (0<<8) | 128; //window is x (0..128)
|
||||
REG_WIN0V = (0<<8) | 128; //window is y (0..128)
|
||||
REG_DISPCNT |= (1<<13); //enable use of window 0
|
||||
|
||||
for(i = 0; i < 16 * 16 / 2; i+=1)
|
||||
{
|
||||
gfx[i] = 0x1111;
|
||||
}
|
||||
|
||||
|
||||
SPRITE_PALETTE[1] = RGB15(31,31,31);
|
||||
|
||||
u8 eva = 0xf, evb = 0xf;
|
||||
|
||||
while(1)
|
||||
{
|
||||
|
||||
scanKeys();
|
||||
u32 keys = keysDown();
|
||||
|
||||
if(keysHeld() & KEY_TOUCH)
|
||||
touchRead(&touch);
|
||||
if(keys & KEY_LEFT && evb > 0)
|
||||
evb--;
|
||||
if(keys & KEY_RIGHT && evb < 0xf)
|
||||
evb++;
|
||||
if(keys & KEY_UP && eva > 0)
|
||||
eva--;
|
||||
if(keys & KEY_DOWN && eva < 0xf)
|
||||
eva++;
|
||||
|
||||
consoleClear();
|
||||
printf("eva %x evb %x\n", eva, evb);
|
||||
|
||||
oamSet(&oamMain, //main graphics engine context
|
||||
0, //oam index (0 to 127)
|
||||
touch.px, touch.py, //x and y pixle location of the sprite
|
||||
0, //priority, lower renders last (on top)
|
||||
0, //this is the palette index if multiple palettes or the alpha value if bmp sprite
|
||||
SpriteSize_16x16,
|
||||
SpriteColorFormat_16Color,
|
||||
gfx, //pointer to the loaded graphics
|
||||
-1, //sprite rotation data
|
||||
false, //double the size when rotating?
|
||||
false, //hide the sprite?
|
||||
false, false, //vflip, hflip
|
||||
false //apply mosaic
|
||||
);
|
||||
|
||||
|
||||
/*REG_BLDCNT = 0;*/
|
||||
REG_BLDALPHA = evb<<8|eva;
|
||||
|
||||
oamMain.oamMemory[0].blendMode = OBJMODE_BLENDED;
|
||||
|
||||
swiWaitForVBlank();
|
||||
|
||||
bgUpdate();
|
||||
oamUpdate(&oamMain);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
Loading…
Reference in New Issue