New console text

* New font for console.
* Top screen initialized so it's not all white.
* NitroFS as source for pad.bin disabled due to bug with write tests
overwriting the NDS file!
* Read/Write functions have ITCM_CODE flag to maybe improve performance
a bit.
This commit is contained in:
ApacheThunder 2024-03-15 15:48:04 -05:00
parent c169ca61cf
commit 32a60d767c
5 changed files with 288 additions and 21 deletions

182
Makefile Normal file
View File

@ -0,0 +1,182 @@
#---------------------------------------------------------------------------------
.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 data
# GRAPHICS is a list of directories containing files to be processed by grit
#
# All directories are specified relative to the project directory where
# the makefile is found
#
#---------------------------------------------------------------------------------
TARGET := nds-sd-benchmark
BUILD := build
SOURCES := source
DATA := data
INCLUDES := include
GRAPHICS := gfx
# specify a directory which contains the nitro filesystem
# this is relative to the Makefile
# NITRO := nitrofs
#---------------------------------------------------------------------------------
# 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 := -lfat -lnds329
#---------------------------------------------------------------------------------
# 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 ($(BUILDDIR), $(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)/*.*)))
BMPFILES := $(foreach dir,$(GRAPHICS),$(notdir $(wildcard $(dir)/*.bmp)))
# NitroFS disabled for this project until overwrite bug is fixed
# prepare NitroFS directory
#ifneq ($(strip $(NITRO)),)
# export NITRO_FILES := $(CURDIR)/$(NITRO)
#endif
# automatigically add libraries for NitroFS
#ifneq ($(strip $(NITRO)),)
#LIBS := -lfilesystem -lfat $(LIBS)
#endif
#---------------------------------------------------------------------------------
# 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)) \
$(BMPFILES:.bmp=.o) \
$(CPPFILES:.cpp=.o) $(CFILES:.c=.o) $(SFILES:.s=.o)
export INCLUDE := $(foreach dir,$(INCLUDES),-I$(CURDIR)/$(dir)) \
$(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) BUILDDIR=`cd $(BUILD) && pwd` --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 $(NITRO_FILES)
$(OUTPUT).elf : $(OFILES)
#---------------------------------------------------------------------------------
# The bin2o rule should be copied and modified
# for each extension used in the data directories
#---------------------------------------------------------------------------------
#---------------------------------------------------------------------------------
# This rule links in binary data with the .bin extension
#---------------------------------------------------------------------------------
%.bin.o : %.bin
#---------------------------------------------------------------------------------
@echo $(notdir $<)
@$(bin2o)
#---------------------------------------------------------------------------------
# This rule links in binary data with the .raw extension
#---------------------------------------------------------------------------------
%.raw.o : %.raw
#---------------------------------------------------------------------------------
@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 : %.bmp %.grit
#---------------------------------------------------------------------------------
grit $< -fts -o$*
-include $(DEPENDS)
#---------------------------------------------------------------------------------------
endif
#---------------------------------------------------------------------------------------

View File

@ -2,6 +2,16 @@
Simple filesystem I/O benchmark for NDS homebrew.
# Changes from original build
* Compiled with nds329 for 32KB DLDI support.
* Better font for console text.
* Top screen initialized so it doesn't remain white.
* nitroFS as source for pad.bin temporarily disabled. pad.bin is expected to be on root of flashcart's file system now. This is due to bug in write code that ends up overwriting the NDS file!
* BlocksDS makefile hasn't been updated to support the new font file. Someone else should look into this as I'm unfamiliar with that make system right now.
* Random Write function appears to be broken. (hangs on first 0.5MiB write test). This bug existed in original build...I do not know why it's happening right now so remains unfixed.
* ITCM_CODE flag used for read/write functions...may improve performance a bit?
## Building
$ ./generate_padding.sh

BIN
gfx/font.bmp Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.1 KiB

25
gfx/font.grit Normal file
View File

@ -0,0 +1,25 @@
#-------------------------------------------------------
# graphics in tile format
#-------------------------------------------------------
-gt
#-------------------------------------------------------
# output first 16 colors of the palette
#-------------------------------------------------------
-pw16
#-------------------------------------------------------
# no tile reduction
#-------------------------------------------------------
-mR!
#-------------------------------------------------------
# no map output
#-------------------------------------------------------
-m!
#-------------------------------------------------------
# graphics bit depth is 4 (16 color)
#-------------------------------------------------------
-gB4

View File

@ -9,14 +9,22 @@
#include <nds/arm9/dldi.h>
#include "font.h"
const char *nds_filename;
uint8_t *io_buffer;
int io_buffer_size;
int io_read_offset = 0;
bool lookup_cache_enabled = true;
static inline uint32_t my_rand(void)
{
static PrintConsole tpConsole;
static PrintConsole btConsole;
static int bg;
static int bgSub;
static inline uint32_t my_rand(void) {
static uint32_t seed = 0;
seed = seed * 0xFDB97531 + 0x2468ACE;
@ -28,7 +36,7 @@ static inline uint32_t get_ticks(void) {
return TIMER0_DATA | (TIMER1_DATA << 16);
}
static void benchmark_read(bool sequential) {
ITCM_CODE static void benchmark_read(bool sequential) {
FILE *file = fopen(nds_filename, "rb");
if (file == NULL) {
printf("\x1b[41mCould not open '%s'!\n", nds_filename);
@ -89,7 +97,7 @@ static void benchmark_read(bool sequential) {
fclose(file);
}
static void benchmark_write(bool sequential) {
ITCM_CODE static void benchmark_write(bool sequential) {
FILE *file = fopen(nds_filename, "r+b");
int file_offset = 8*1024*1024;
if (file == NULL) {
@ -120,11 +128,10 @@ static void benchmark_write(bool sequential) {
uint32_t reads = 0;
if (sequential) {
int pos = 0;
while (reads < reads_count) {
if (pos == 0)
fseek(file, io_read_offset, SEEK_SET);
while (reads < reads_count) {
if (pos == 0)fseek(file, io_read_offset, SEEK_SET);
fwrite(io_buffer, curr_size, 1, file);
pos = (pos + curr_size) & 0x1FFFFF;
pos = (pos + curr_size) & 0x1FFFFF;
reads++;
}
} else {
@ -165,7 +172,7 @@ static bool run_menu(int options_count, int *selection) {
while (1) {
if (last_selection != *selection) {
printf("\x1b[2J"); // Clear console
consoleClear();
for (int i = 0; i < options_count; i++) {
printf("\x1b[%dC\x1b[46m%c\x1b[39m %s\n", menu_left, i == *selection ? '>' : ' ', options[i]);
}
@ -198,22 +205,45 @@ static void press_start_to_continue(void) {
}
}
void CustomConsoleInit() {
videoSetMode(MODE_0_2D);
videoSetModeSub(MODE_0_2D);
vramSetBankA (VRAM_A_MAIN_BG);
vramSetBankC (VRAM_C_SUB_BG);
bg = bgInit(3, BgType_Bmp8, BgSize_B8_256x256, 1, 0);
bgSub = bgInitSub(3, BgType_Bmp8, BgSize_B8_256x256, 1, 0);
consoleInit(&btConsole, 3, BgType_Text4bpp, BgSize_T_256x256, 20, 0, false, false);
consoleInit(&tpConsole, 3, BgType_Text4bpp, BgSize_T_256x256, 20, 0, true, false);
ConsoleFont font;
font.gfx = (u16*)fontTiles;
font.pal = (u16*)fontPal;
font.numChars = 95;
font.numColors = fontPalLen / 2;
font.bpp = 4;
font.asciiOffset = 32;
font.convertSingleColor = true;
consoleSetFont(&btConsole, &font);
consoleSetFont(&tpConsole, &font);
consoleSelect(&btConsole);
}
int main(int argc, char **argv) {
consoleDemoInit();
CustomConsoleInit();
printf("\x1b[2J"); // Clear console
// 01234567890123456789012345678901
consoleClear();
// 01234567890123456789012345678901
printf(" \x1b[43m*\x1b[39m SD file system benchmark \x1b[43m*\x1b[39m\n");
printf("\x1b[37mDLDI: %s\x1b[39m\n\n", io_dldi_data->friendlyName);
// set window
consoleSetWindow(NULL, 0, 3, 32, 25);
if (argc <= 0 || argv[0][0] == 0) {
printf("\x1b[41mCould not find argv!\n");
goto exit;
}
// consoleSetWindow(NULL, 0, 3, 32, 25);
consoleSetWindow(&btConsole, 0, 3, 32, 25);
consoleSetWindow(&tpConsole, 0, 3, 32, 25);
io_buffer_size = 2*1024*1024;
io_buffer = malloc(io_buffer_size);
@ -222,8 +252,28 @@ int main(int argc, char **argv) {
goto exit;
}
fatInitDefault();
nds_filename = argv[0];
if (!fatInitDefault()) {
printf("\x1b[41mFAT Init Failed!\n");
goto exit;
}
/*if (argc <= 0 || argv[0][0] == 0) {
// arg not passed. Try and use external file instead.
nds_filename = "/pad.bin";
// printf("\x1b[41mCould not find argv!\n");
// goto exit;
} else {
nds_filename = argv[0];
}*/
// NitroFS support removed until nds file overwrite bug is fixed
nds_filename = "/pad.bin";
if (access(nds_filename, F_OK) != 0) {
printf("\x1b[41mCould not find pad.bin!\n");
goto exit;
}
TIMER0_DATA = 0;
TIMER1_DATA = 0;