Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -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

Expand Down
48 changes: 26 additions & 22 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)),)

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -472,20 +476,20 @@ 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)
ARM7_CC_CHECK_CFLAGS := -fsyntax-only -fsigned-char $(CC_CFLAGS) $(ARM7_TARGET_CFLAGS) -Wall -Wextra -Wno-format-security $(DEF_INC_CFLAGS)

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

Expand Down Expand Up @@ -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"
Expand Down
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`
Expand Down
2 changes: 1 addition & 1 deletion build_docker.sh
Original file line number Diff line number Diff line change
@@ -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) "$@"
10 changes: 10 additions & 0 deletions src/nds/nds_renderer.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down