tests: Show that the LCD uses 18-bit colors, not 15-bit

This commit is contained in:
Antonio Niño Díaz 2023-10-15 21:28:41 +01:00
parent 8c323c7e2c
commit 06ac0eba5b
3 changed files with 406 additions and 0 deletions

View File

@ -0,0 +1,220 @@
#---------------------------------------------------------------------------------
.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
# DATA is a list of directories containing binary files embedded using bin2o
# GRAPHICS is a list of directories containing image files to be converted with grit
# AUDIO is a list of directories containing audio to be converted by maxmod
# ICON is the image used to create the game icon, leave blank to use default rule
# NITRO is a directory that will be accessible via NitroFS
#---------------------------------------------------------------------------------
TARGET := $(shell basename $(CURDIR))
BUILD := build
SOURCES := source
INCLUDES := include
DATA := data
GRAPHICS :=
AUDIO :=
ICON :=
# specify a directory which contains the nitro filesystem
# this is relative to the Makefile
NITRO :=
# These set the information text in the nds file
GAME_TITLE := $(shell basename $(CURDIR))
GAME_SUBTITLE1 := Nitro Engine example
GAME_SUBTITLE2 := github.com/AntonioND/nitro-engine
#---------------------------------------------------------------------------------
# options for code generation
#---------------------------------------------------------------------------------
ARCH := -marm -mthumb-interwork -march=armv5te -mtune=arm946e-s
CFLAGS := -g -Wall -O3\
$(ARCH) $(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 := -lNE -lfat -lnds9
# automatigically add libraries for NitroFS
ifneq ($(strip $(NITRO)),)
LIBS := -lfilesystem -lfat $(LIBS)
endif
# automagically add maxmod library
ifneq ($(strip $(AUDIO)),)
LIBS := -lmm9 $(LIBS)
endif
#---------------------------------------------------------------------------------
# list of directories containing libraries, this must be the top level containing
# include and lib
#---------------------------------------------------------------------------------
LIBDIRS := $(LIBNDS) $(PORTLIBS) $(DEVKITPRO)/nitro-engine
#---------------------------------------------------------------------------------
# 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 := $(CURDIR)/$(subst /,,$(dir $(ICON)))\
$(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)))
PNGFILES := $(foreach dir,$(GRAPHICS),$(notdir $(wildcard $(dir)/*.png)))
BINFILES := $(foreach dir,$(DATA),$(notdir $(wildcard $(dir)/*.*)))
# prepare NitroFS directory
ifneq ($(strip $(NITRO)),)
export NITRO_FILES := $(CURDIR)/$(NITRO)
endif
# get audio list for maxmod
ifneq ($(strip $(AUDIO)),)
export MODFILES := $(foreach dir,$(notdir $(wildcard $(AUDIO)/*.*)),$(CURDIR)/$(AUDIO)/$(dir))
# place the soundbank file in NitroFS if using it
ifneq ($(strip $(NITRO)),)
export SOUNDBANK := $(NITRO_FILES)/soundbank.bin
# otherwise, needs to be loaded from memory
else
export SOUNDBANK := soundbank.bin
BINFILES += $(SOUNDBANK)
endif
endif
#---------------------------------------------------------------------------------
# use CXX for linking C++ projects, CC for standard C
#---------------------------------------------------------------------------------
ifeq ($(strip $(CPPFILES)),)
#---------------------------------------------------------------------------------
export LD := $(CC)
#---------------------------------------------------------------------------------
else
#---------------------------------------------------------------------------------
export LD := $(CXX)
#---------------------------------------------------------------------------------
endif
#---------------------------------------------------------------------------------
export OFILES_BIN := $(addsuffix .o,$(BINFILES))
export OFILES_SOURCES := $(CPPFILES:.cpp=.o) $(CFILES:.c=.o) $(SFILES:.s=.o)
export OFILES := $(PNGFILES:.png=.o) $(OFILES_BIN) $(OFILES_SOURCES)
export HFILES := $(PNGFILES:.png=.h) $(addsuffix .h,$(subst .,_,$(BINFILES)))
export INCLUDE := $(foreach dir,$(INCLUDES),-iquote $(CURDIR)/$(dir))\
$(foreach dir,$(LIBDIRS),-I$(dir)/include)\
-I$(CURDIR)/$(BUILD)
export LIBPATHS := $(foreach dir,$(LIBDIRS),-L$(dir)/lib)
ifeq ($(strip $(ICON)),)
icons := $(wildcard *.bmp)
ifneq (,$(findstring $(TARGET).bmp,$(icons)))
export GAME_ICON := $(CURDIR)/$(TARGET).bmp
else
ifneq (,$(findstring icon.bmp,$(icons)))
export GAME_ICON := $(CURDIR)/icon.bmp
endif
endif
else
ifeq ($(suffix $(ICON)), .grf)
export GAME_ICON := $(CURDIR)/$(ICON)
else
export GAME_ICON := $(CURDIR)/$(BUILD)/$(notdir $(basename $(ICON))).grf
endif
endif
.PHONY: $(BUILD) clean
#---------------------------------------------------------------------------------
$(BUILD):
@mkdir -p $@
@$(MAKE) --no-print-directory -C $(BUILD) -f $(CURDIR)/Makefile
#---------------------------------------------------------------------------------
clean:
@echo clean ...
@rm -fr $(BUILD) $(TARGET).elf $(TARGET).nds $(SOUNDBANK)
#---------------------------------------------------------------------------------
else
#---------------------------------------------------------------------------------
# main targets
#---------------------------------------------------------------------------------
$(OUTPUT).nds: $(OUTPUT).elf $(GAME_ICON)
$(OUTPUT).elf: $(OFILES)
# source files depend on generated headers
$(OFILES_SOURCES) : $(HFILES)
# need to build soundbank first
$(OFILES): $(SOUNDBANK)
#---------------------------------------------------------------------------------
# rule to build solution from music files
#---------------------------------------------------------------------------------
$(SOUNDBANK) : $(MODFILES)
#---------------------------------------------------------------------------------
mmutil $^ -d -o$@ -hsoundbank.h
#---------------------------------------------------------------------------------
%.bin.o %_bin.h : %.bin
#---------------------------------------------------------------------------------
@echo $(notdir $<)
@$(bin2o)
#---------------------------------------------------------------------------------
# This rule creates assembly source files using grit
# grit takes an image file and a .grit describing how the file is to be processed
# add additional rules like this for each image extension
# you use in the graphics folders
#---------------------------------------------------------------------------------
%.s %.h: %.png %.grit
#---------------------------------------------------------------------------------
grit $< -fts -o$*
#---------------------------------------------------------------------------------
# Convert non-GRF game icon to GRF if needed
#---------------------------------------------------------------------------------
$(GAME_ICON): $(notdir $(ICON))
#---------------------------------------------------------------------------------
@echo convert $(notdir $<)
@grit $< -g -gt -gB4 -gT FF00FF -m! -p -pe 16 -fh! -ftr
-include $(DEPSDIR)/*.d
#---------------------------------------------------------------------------------------
endif
#---------------------------------------------------------------------------------------

View File

@ -0,0 +1,3 @@
BINDIRS := data
include ../../Makefile.example.blocksds

View File

@ -0,0 +1,183 @@
// SPDX-License-Identifier: CC0-1.0
//
// SPDX-FileContributor: Antonio Niño Díaz, 2023
//
// This file is part of Nitro Engine
// The LCD of the DS actually supports 6 bits for each one of the RGB components
// of a color. You can't access the least significative bits by software
// because all colors are defined with 5 bits per component. However, the 6th
// bit is connected to the video unit of the DS, and the 3D GPU also uses that
// additional bit when rendering.
//
// However, when video is captured (which is used in dual 3D modes) the last bit
// is lost. This demo shows the difference between different 3D modes. In order
// to do that it draws a colored quad that goes from a gray to a slightly
// different gray. This quad spans the whole screen, which means that there is a
// lot of space to interpolate. This makes the gradient steps easier to be seen
// by the human eye. Also, note that this is easier to see in a DSi than in a
// regular DS.
//
// This special output of this is demo can't be seen in most emulators (like
// DesMuME or no$gba). It works in melonDS and hardware.
//
// - Single 3D:
//
// The screen shows the direct output from the GPU (6 bits).
//
// - Dual 3D:
//
// The screens alternate between showing the direct output from the GPU (6 bit),
// or a stored image in VRAM (5 bit). This means that the output will be seen as
// something in between the two bit depths. It may end up blended or appear as a
// small flicker.
//
// - Dual 3D FB:
//
// Both screens show captured output that has been stored in VRAM, so the output
// is always using 5 bit depth images.
//
// The debug console doesn't work in this mode
//
// - Dual 3D DMA:
//
// Both screens show captured output that has been stored in VRAM, so the output
// is always using 5 bit depth images.
#include <NEMain.h>
#define ID_1 10
#define ID_2 11
uint32_t x = 80;
void Draw3DSceneBands(void)
{
NE_ClearColorSet(NE_Black, 31, 63);
NE_2DViewInit();
NE_PolyFormat(31, ID_1, 0, NE_CULL_NONE, 0);
NE_2DDrawQuadGradient(0, 0, 256, 192,
10,
RGB15(16, 16, 16), RGB15(12, 12, 12),
RGB15(12, 12, 12), RGB15(16, 16, 16));
NE_PolyFormat(15, ID_2, 0, NE_CULL_NONE, 0);
NE_2DDrawQuadGradient(0 + x, 128, 256 + x, 192,
9,
RGB15(16, 16, 16), RGB15(12, 12, 12),
RGB15(12, 12, 12), RGB15(16, 16, 16));
}
void Draw3DSceneEmpty(void)
{
NE_ClearColorSet(NE_Black, 31, 63);
}
int main(void)
{
// This is needed for special screen effects
irqEnable(IRQ_HBLANK);
irqSet(IRQ_VBLANK, NE_VBLFunc);
irqSet(IRQ_HBLANK, NE_HBLFunc);
// Init 3D mode and console
NE_Init3D();
NE_MainScreenSetOnTop();
consoleDemoInit();
while (1)
{
NE_WaitForVBL(0);
// Draw 3D scenes
switch (NE_CurrentExecutionMode())
{
case NE_ModeSingle3D:
NE_Process(Draw3DSceneBands);
break;
case NE_ModeDual3D:
case NE_ModeDual3D_FB:
case NE_ModeDual3D_DMA:
NE_ProcessDual(Draw3DSceneBands, Draw3DSceneEmpty);
break;
case NE_ModeUninitialized:
break;
}
// Refresh keys
scanKeys();
uint32_t keys = keysHeld();
uint32_t kdown = keysDown();
if (NE_CurrentExecutionMode() != NE_ModeDual3D_FB)
{
printf("\x1b[0;0H"
"A: One screen 3D (6 bit)\n"
"B: Dual 3D DMA (5 bit)\n"
"X: Dual 3D FB (5 bit, no text)\n"
"Y: Dual 3D (both 5 and 6 bit)\n"
"Left/Right: Move layer\n"
"\n"
"6 bit modes will display more\n"
"bands than 5 bit modes.\n"
"\n"
"Dual 3D mode alternates 5 and 6\n"
"bits, so it shows a blend or\n"
"flicker between more and fewer\n"
"color bands.\n"
"\n"
"Only melonDS emulates this.\n"
"\n"
"Note: Dual 3D FB disables the\n"
"text console\n"
"\n"
"\n"
"\n");
const char *modes[] = {
[NE_ModeSingle3D] = "Single 3D",
[NE_ModeDual3D] = "Dual 3D",
[NE_ModeDual3D_FB] = "Dual 3D FB",
[NE_ModeDual3D_DMA] = "Dual 3D DMA"
};
printf("Current mode: %s", modes[NE_CurrentExecutionMode()]);
}
if (keys & KEY_LEFT)
x--;
if (keys & KEY_RIGHT)
x++;
if (kdown & KEY_Y)
{
NE_InitDual3D();
NE_MainScreenSetOnBottom();
NE_InitConsole();
}
if (kdown & KEY_X)
{
NE_InitDual3D_FB();
NE_MainScreenSetOnBottom();
}
if (kdown & KEY_B)
{
NE_InitDual3D_DMA();
NE_MainScreenSetOnBottom();
NE_InitConsole();
}
if (kdown & KEY_A)
{
NE_Init3D();
NE_MainScreenSetOnTop();
consoleDemoInit();
}
}
return 0;
}