Skip to content

Commit

Permalink
[NDSi] Port Vanilla-Conquer to Nintendo DSi.
Browse files Browse the repository at this point in the history
This commit introduces a new target platform to Vanilla-Conquer:
The mighty Nintendo DSi.

It includes:
  - A CMake toolchain file for devKitPro
  - A video interface to the game graphical engine relying purely on libnds.
  - A dedicated asynchronous sound engine running on the secondary ARM7.
  - Fixing many unaligned accesses problems in the engine.
  - Introduce ways of measuring how much RAM to allocate to BigShapeBuff.
  - Optimized functions for the platform and a macro that can be used
      by other developers to also change some functions optimizations
      according to their needs.

[NDSi] Fix tickling effect in music
  • Loading branch information
giulianobelinassi committed Jul 24, 2022
1 parent 11efe9b commit eebd762
Show file tree
Hide file tree
Showing 80 changed files with 5,573 additions and 198 deletions.
33 changes: 31 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ if(NOT DEFINED CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE "Debug" CACHE STRING "Choose the type of build, options are: Debug Release RelWithDebInfo" FORCE)
endif()

project(VanillaConquer CXX)
project(VanillaConquer CXX ASM)

option(BUILD_REMASTERTD "Build Tiberian Dawn remaster dll." OFF)
option(BUILD_REMASTERRA "Build Red Alert remaster dll." OFF)
Expand All @@ -34,13 +34,19 @@ if(WIN32 OR CMAKE_SYSTEM_NAME STREQUAL "Windows")
add_feature_info(DirectDraw DDRAW "DirectDraw video backend (deprecated)")
add_feature_info(SDL2 SDL2 "SDL2 video backend")
add_feature_info(OpenAL OPENAL "OpenAL audio backend")
elseif(NDS)
set(SDL2 FALSE)
set(OPENAL FALSE)
set(DSOUND FALSE)
set(DDRAW FALSE)
set(NETWORKING FALSE)
else()
set(SDL2 TRUE)
set(OPENAL TRUE)
endif()

if(APPLE OR ${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
option(MAKE_BUNDLE "Create a standard app bundle rather than command line program." ON)
option(MAKE_BUNDLE "Create a standard app bundle rather than command line program." ON)
add_feature_info(MakeBundle MAKE_BUNDLE "App bundles will be generated")
if(MAKE_BUNDLE)
set(MAKE_BUNDLE_OPTION MACOSX_BUNDLE)
Expand Down Expand Up @@ -74,6 +80,10 @@ if(NOT MSVC)
set(CMAKE_CXX_FLAGS_DEBUG "-gstabs3")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fpermissive")
set(STATIC_LIBS "-static-libstdc++ -static-libgcc")
elseif(NDS)
# We need to enable optimizations, else the code doesn't fit in
# correct address region.
set(CMAKE_CXX_FLAGS_DEBUG "-O2 -g3")
else()
set(CMAKE_CXX_FLAGS_DEBUG "-g3")
set(CMAKE_FIND_FRAMEWORK "LAST")
Expand Down Expand Up @@ -134,6 +144,25 @@ if(OPENAL)
set(DSOUND OFF)
endif()

if(NDS)
# This directory contains code that will run on the ARM7 chip. So we don't
# define the arch variables until this directory has already been compiled.
add_subdirectory(arm7)

# The code below will run on ARM9 chip.
add_definitions(-DARM9)

set(ARCH "-mthumb -mthumb-interwork -mcpu=arm946e-s -mtune=arm946e-s")
set(CMAKE_C_FLAGS "${ARCH} ${CMAKE_C_CFLAGS} -fomit-frame-pointer -fno-rtti -fno-exceptions -ffast-math -fno-unwind-tables")
set(CMAKE_CXX_FLAGS "${CMAKE_C_FLAGS} ${CMAKE_CXX_FLAGS}")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -specs=ds_arm9.specs -mthumb -mthumb-interwork -Wl,-Map,vanilla.map")

# Link with those libraries.
link_libraries("-lc") # C library
link_libraries("-lfat")
link_libraries("-lnds9")
endif()

if(BUILD_TESTS)
# Tests need to respect some options so need to occur after the options are set.
enable_testing()
Expand Down
20 changes: 20 additions & 0 deletions arm7/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
add_definitions(-DARM7 -D_NDS)

set(ARCH "-mthumb -mthumb-interwork -mcpu=arm7tdmi -mtune=arm7tdmi")
set(CMAKE_C_FLAGS "${ARCH} -g -fomit-frame-pointer -fno-rtti -fno-exceptions -ffast-math -fstack-protector-all")
set(CMAKE_CXX_FLAGS "${CMAKE_C_FLAGS} ${CMAKE_CXX_FLAGS}")
SET(CMAKE_CXX_FLAGS_DEBUG "-Os -g")
set(CMAKE_CXX_FLAGS_RELEASE "-Os")
set(CMAKE_EXE_LINKER_FLAGS "-specs=ds_arm7.specs -mthumb -mthumb-interwork -Wl,-Map,vanilla.map")

set(ARM7_SRC
main.cpp
audio.cpp
printf.cpp
)

# Link with those libraries
link_libraries("-lc") # C library
link_libraries("-lnds7d")

add_executable(arm7.elf ${ARM7_SRC})
Loading

0 comments on commit eebd762

Please sign in to comment.