diff --git a/Dockerfile b/Dockerfile index 514c8eabfd..7999a101e4 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,7 +1,11 @@ -FROM devkitpro/devkitarm:20240511 as build +FROM skylyrac/blocksds:slim-latest as build RUN apt update -RUN apt -y install build-essential bsdmainutils sox +RUN apt -y install \ + build-essential \ + bsdmainutils \ + python3 \ + sox RUN mkdir /sm64 WORKDIR /sm64 diff --git a/Makefile b/Makefile index 42fe8c8041..ff15ee4f1a 100644 --- a/Makefile +++ b/Makefile @@ -70,12 +70,19 @@ else ifeq ($(VERSION),cn) endif ifeq ($(TARGET_NDS),1) - OPT_FLAGS := -O2 -flto -ffast-math - GRUCODE := f3dex2 - COMPILER := gcc - DEVKITPRO ?= /opt/devkitpro - DEVKITARM ?= $(DEVKITPRO)/devkitARM - NDSTOOL ?= $(DEVKITPRO)/tools/bin/ndstool + OPT_FLAGS := -O2 -flto=auto -ffast-math + GRUCODE := f3dex2 + COMPILER := gcc + WONDERFUL_TOOLCHAIN ?= /opt/wonderful + ARM_NONE_EABI_PATH ?= $(WONDERFUL_TOOLCHAIN)/toolchain/gcc-arm-none-eabi/bin + BLOCKSDS ?= /opt/blocksds/core + BLOCKSDSEXT ?= /opt/blocksds/external + NDSTOOL ?= $(BLOCKSDS)/tools/ndstool/ndstool + GRIT ?= $(BLOCKSDS)/tools/grit/grit + SOX ?= $(call find-command,wf-sox) + ifeq (, $(SOX)) + SOX := sox + endif endif TARGET := sm64.$(VERSION) @@ -197,8 +204,6 @@ TOOLS_DIR := tools # in the makefile that we want should cover assets.) PYTHON := python3 -SOX := sox -GRIT := $(DEVKITPRO)/tools/bin/grit ifeq ($(filter clean distclean print-%,$(MAKECMDGOALS)),) @@ -371,13 +376,12 @@ IQUE_EGCS_PATH := $(TOOLS_DIR)/ique_egcs IQUE_LD_PATH := $(TOOLS_DIR)/ique_ld ifeq ($(TARGET_NDS),1) -AS := $(DEVKITARM)/bin/arm-none-eabi-as -CC := $(DEVKITARM)/bin/arm-none-eabi-gcc -CPP := $(DEVKITARM)/bin/arm-none-eabi-cpp -P -CXX := $(DEVKITARM)/bin/arm-none-eabi-g++ -LD := $(CXX) -OBJDUMP := $(DEVKITARM)/bin/arm-none-eabi-objdump -OBJCOPY := $(DEVKITARM)/bin/arm-none-eabi-objcopy +AS := $(ARM_NONE_EABI_PATH)/arm-none-eabi-as +CC := $(ARM_NONE_EABI_PATH)/arm-none-eabi-gcc +CPP := $(ARM_NONE_EABI_PATH)/arm-none-eabi-cpp -P +LD := $(ARM_NONE_EABI_PATH)/arm-none-eabi-ld +OBJDUMP := $(ARM_NONE_EABI_PATH)/arm-none-eabi-objdump +OBJCOPY := $(ARM_NONE_EABI_PATH)/arm-none-eabi-objcopy else # detect prefix for MIPS toolchain @@ -472,9 +476,9 @@ endif ifeq ($(TARGET_NDS),1) -LIBDIRS := $(DEVKITPRO)/libnds -TARGET_CFLAGS := -march=armv5te -mtune=arm946e-s -Wno-error=incompatible-pointer-types -Wno-error=implicit-function-declaration -Wno-error=int-conversion $(foreach dir,$(LIBDIRS),-I$(dir)/include) -DTARGET_NDS -DARM9 -D_LANGUAGE_C -DNO_SEGMENTED_MEMORY #-DENABLE_FPS -ARM7_TARGET_CFLAGS := -mcpu=arm7tdmi -mtune=arm7tdmi -Wno-error=implicit-function-declaration $(foreach dir,$(LIBDIRS),-I$(dir)/include) -DTARGET_NDS -DARM7 -D_LANGUAGE_C +LIBDIRS := $(BLOCKSDS)/libs/libnds +TARGET_CFLAGS := -mcpu=arm946e-s+nofp -Wno-error=incompatible-pointer-types -Wno-error=implicit-function-declaration -Wno-error=int-conversion $(foreach dir,$(LIBDIRS),-I$(dir)/include) -DTARGET_NDS -DARM9 -D_LANGUAGE_C -DNO_SEGMENTED_MEMORY #-DENABLE_FPS +ARM7_TARGET_CFLAGS := -mcpu=arm7tdmi -Wno-error=implicit-function-declaration $(foreach dir,$(LIBDIRS),-I$(dir)/include) -DTARGET_NDS -DARM7 -D_LANGUAGE_C CC_CHECK := $(CC) CC_CHECK_CFLAGS := -fsyntax-only -fsigned-char $(CC_CFLAGS) $(TARGET_CFLAGS) -Wall -Wextra -Wno-format-security -DNON_MATCHING -DAVOID_UB $(DEF_INC_CFLAGS) @@ -482,10 +486,10 @@ ARM7_CC_CHECK_CFLAGS := -fsyntax-only -fsigned-char $(CC_CFLAGS) $(ARM7_TARGET_C ASFLAGS := $(foreach i,$(INCLUDE_DIRS),-I$(i)) $(foreach d,$(DEFINES),--defsym $(d)) CFLAGS := -fno-strict-aliasing -fwrapv $(OPT_FLAGS) $(TARGET_CFLAGS) $(DEF_INC_CFLAGS) -LDFLAGS := -lfat -lnds9 -specs=dsi_arm9.specs -g -mthumb -mthumb-interwork $(foreach dir,$(LIBDIRS),-L$(dir)/lib) $(TARGET_CFLAGS) +LDFLAGS := -Wl,--start-group -lc -lnds9 -Wl,--end-group -specs=$(BLOCKSDS)/sys/crts/dsi_arm9.specs -g $(foreach dir,$(LIBDIRS),-L$(dir)/lib) $(TARGET_CFLAGS) ARM7_CFLAGS := -fno-strict-aliasing -fwrapv $(OPT_FLAGS) $(ARM7_TARGET_CFLAGS) $(DEF_INC_CFLAGS) -ARM7_LDFLAGS := -lnds7 -specs=ds_arm7.specs -g -mthumb-interwork $(foreach dir,$(LIBDIRS),-L$(dir)/lib) $(ARM7_TARGET_CFLAGS) +ARM7_LDFLAGS := -Wl,--start-group -lc -lnds7 -Wl,--end-group -specs=$(BLOCKSDS)/sys/crts/ds_arm7.specs -g $(foreach dir,$(LIBDIRS),-L$(dir)/lib) $(ARM7_TARGET_CFLAGS) else @@ -1026,11 +1030,11 @@ ifeq ($(TARGET_NDS),1) $(ARM7): $(ARM7_O_FILES) @$(PRINT) "$(GREEN)Linking ARM7 binary: $(BLUE)$@ $(NO_COL)\n" - $(V)$(LD) -L $(BUILD_DIR) -o $@ $(ARM7_O_FILES) $(ARM7_LDFLAGS) + $(V)$(CC) -L $(BUILD_DIR) -o $@ $(ARM7_O_FILES) $(ARM7_LDFLAGS) $(ARM9): $(GFX_O_FILES) $(O_FILES) $(MIO0_FILES:.mio0=.o) $(ULTRA_O_FILES) $(GODDARD_O_FILES) @$(PRINT) "$(GREEN)Linking ARM9 binary: $(BLUE)$@ $(NO_COL)\n" - $(V)$(LD) -L $(BUILD_DIR) -o $@ $(GFX_O_FILES) $(O_FILES) $(ULTRA_O_FILES) $(GODDARD_O_FILES) $(LDFLAGS) + $(V)$(CC) -L $(BUILD_DIR) -o $@ $(GFX_O_FILES) $(O_FILES) $(ULTRA_O_FILES) $(GODDARD_O_FILES) $(LDFLAGS) $(ROM): $(ARM7) $(ARM9) @$(PRINT) "$(GREEN)Building ROM: $(BLUE)$@ $(NO_COL)\n" diff --git a/README.md b/README.md index ed4d7a7b89..f35e017748 100644 --- a/README.md +++ b/README.md @@ -20,7 +20,9 @@ have to build it yourself; the process should be straightforward, but some techn * Once the build is complete, open the `build/us_nds` folder to find `sm64.us.nds` **Linux:** -* Install [devkitPro](https://devkitpro.org/wiki/Getting_Started) and its `nds-dev` package +* Install the BlocksDS toolchain [using their instructions here](https://blocksds.skylyrac.net/docs/setup/options/linux/) + * You do not need the optional packages + * Creating the symlink for BlocksDS or setting the `BLOCKSDS` environment variable as described is required * Install tools according to your distro * Debian/Ubuntu: `sudo apt install -y build-essential git python sox` * Fedora: `sudo dnf install gcc make git python sox` diff --git a/build_docker.sh b/build_docker.sh index 07101bc629..46b47167d7 100755 --- a/build_docker.sh +++ b/build_docker.sh @@ -1,3 +1,3 @@ #!/bin/sh docker build -t sm64dsi . -docker run --rm --mount type=bind,source="$(pwd)",destination=/sm64 sm64dsi make VERSION=us -j$(nproc) +docker run --rm --mount type=bind,source="$(pwd)",destination=/sm64 sm64dsi make VERSION=us -j$(nproc) "$@" diff --git a/src/nds/nds_renderer.c b/src/nds/nds_renderer.c index 72a8176962..107f94e399 100644 --- a/src/nds/nds_renderer.c +++ b/src/nds/nds_renderer.c @@ -94,13 +94,18 @@ u64 rspF3DDataStart[] = {}; struct Sprite sprites[MAX_SPRITES]; +// TODO adapt this for BlocksDS's libnds + +/* struct { const void *texture; gl_texture_data *tex; } glTexQueue[128]; +*/ static uint8_t glTexCount; static void glTexSync(); +/* // This is a modified (and simplified) version of glTexImage2D from libnds // The original updates texture VRAM right away, which causes tearing when done mid-frame @@ -197,6 +202,11 @@ static void glTexSync() { glTexCount = 0; } +*/ + +#define glTexImage2DAsync glTexImage2D +#define glTexSync() {} + static void load_texture() { // Look up the current texture using a simple hash calculated from its address