From a4c22da1039c711c7053d398112f747e22ddeb2c Mon Sep 17 00:00:00 2001 From: Cameron Cawley Date: Thu, 3 Feb 2022 18:02:55 +0000 Subject: [PATCH 1/2] Add examples for building with CMake --- cmake/Makefile | 5 ++ cmake/arm9/CMakeLists.txt | 5 ++ cmake/arm9/source/main.c | 20 ++++++ cmake/combined/CMakeLists.txt | 10 +++ cmake/combined/arm7/CMakeLists.txt | 5 ++ cmake/combined/arm7/source/template.c | 98 +++++++++++++++++++++++++++ cmake/combined/arm9/CMakeLists.txt | 4 ++ cmake/combined/arm9/source/template.c | 33 +++++++++ 8 files changed, 180 insertions(+) create mode 100644 cmake/Makefile create mode 100644 cmake/arm9/CMakeLists.txt create mode 100644 cmake/arm9/source/main.c create mode 100644 cmake/combined/CMakeLists.txt create mode 100644 cmake/combined/arm7/CMakeLists.txt create mode 100644 cmake/combined/arm7/source/template.c create mode 100644 cmake/combined/arm9/CMakeLists.txt create mode 100644 cmake/combined/arm9/source/template.c diff --git a/cmake/Makefile b/cmake/Makefile new file mode 100644 index 0000000..9e2652b --- /dev/null +++ b/cmake/Makefile @@ -0,0 +1,5 @@ +SUBDIRS:= `ls | egrep -v '^(CVS)$$'` +all: + @for i in $(SUBDIRS); do if test -e $$i/CMakeLists.txt ; then (arm-none-eabi-cmake -B $$i/build -S $$i && cmake --build $$i/build) || { exit 1;} fi; done; +clean: + @for i in $(SUBDIRS); do rm -rf $$i/build; done; diff --git a/cmake/arm9/CMakeLists.txt b/cmake/arm9/CMakeLists.txt new file mode 100644 index 0000000..a287299 --- /dev/null +++ b/cmake/arm9/CMakeLists.txt @@ -0,0 +1,5 @@ +cmake_minimum_required(VERSION 3.7) +project(cmake-example LANGUAGES C) + +add_executable(cmake-example source/main.c) +nds_create_rom(cmake-example) diff --git a/cmake/arm9/source/main.c b/cmake/arm9/source/main.c new file mode 100644 index 0000000..5f443b1 --- /dev/null +++ b/cmake/arm9/source/main.c @@ -0,0 +1,20 @@ +/*--------------------------------------------------------------------------------- + + Basic template code for starting a DS app + +---------------------------------------------------------------------------------*/ +#include +#include +//--------------------------------------------------------------------------------- +int main(void) { +//--------------------------------------------------------------------------------- + consoleDemoInit(); + iprintf("Hello World!"); + while(1) { + swiWaitForVBlank(); + scanKeys(); + int pressed = keysDown(); + if(pressed & KEY_START) break; + } + +} diff --git a/cmake/combined/CMakeLists.txt b/cmake/combined/CMakeLists.txt new file mode 100644 index 0000000..30df18d --- /dev/null +++ b/cmake/combined/CMakeLists.txt @@ -0,0 +1,10 @@ +cmake_minimum_required(VERSION 3.7) +project(cmake-example LANGUAGES C) + +nds_build_arm7(cmake-example-arm7 + SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/arm7 +) + +add_subdirectory(arm9) + +nds_create_rom(cmake-example ARM9 cmake-example-arm9 ARM7 cmake-example-arm7) diff --git a/cmake/combined/arm7/CMakeLists.txt b/cmake/combined/arm7/CMakeLists.txt new file mode 100644 index 0000000..b5ccc8e --- /dev/null +++ b/cmake/combined/arm7/CMakeLists.txt @@ -0,0 +1,5 @@ +cmake_minimum_required(VERSION 3.7) +project(cmake-example-arm7 LANGUAGES C) + +add_executable(cmake-example-arm7 source/template.c) +target_link_libraries(cmake-example-arm7 dswifi7 mm7) diff --git a/cmake/combined/arm7/source/template.c b/cmake/combined/arm7/source/template.c new file mode 100644 index 0000000..00592c3 --- /dev/null +++ b/cmake/combined/arm7/source/template.c @@ -0,0 +1,98 @@ +/*--------------------------------------------------------------------------------- + + default ARM7 core + + Copyright (C) 2005 - 2010 + Michael Noland (joat) + Jason Rogers (dovoto) + Dave Murphy (WinterMute) + + This software is provided 'as-is', without any express or implied + warranty. In no event will the authors be held liable for any + damages arising from the use of this software. + + Permission is granted to anyone to use this software for any + purpose, including commercial applications, and to alter it and + redistribute it freely, subject to the following restrictions: + + 1. The origin of this software must not be misrepresented; you + must not claim that you wrote the original software. If you use + this software in a product, an acknowledgment in the product + documentation would be appreciated but is not required. + + 2. Altered source versions must be plainly marked as such, and + must not be misrepresented as being the original software. + + 3. This notice may not be removed or altered from any source + distribution. + +---------------------------------------------------------------------------------*/ +#include +#include +#include + +//--------------------------------------------------------------------------------- +void VblankHandler(void) { +//--------------------------------------------------------------------------------- + Wifi_Update(); +} + + +//--------------------------------------------------------------------------------- +void VcountHandler() { +//--------------------------------------------------------------------------------- + inputGetAndSend(); +} + +volatile bool exitflag = false; + +//--------------------------------------------------------------------------------- +void powerButtonCB() { +//--------------------------------------------------------------------------------- + exitflag = true; +} + +//--------------------------------------------------------------------------------- +int main() { +//--------------------------------------------------------------------------------- + // clear sound registers + dmaFillWords(0, (void*)0x04000400, 0x100); + + REG_SOUNDCNT |= SOUND_ENABLE; + writePowerManagement(PM_CONTROL_REG, ( readPowerManagement(PM_CONTROL_REG) & ~PM_SOUND_MUTE ) | PM_SOUND_AMP ); + powerOn(POWER_SOUND); + + readUserSettings(); + ledBlink(0); + + irqInit(); + // Start the RTC tracking IRQ + initClockIRQ(); + fifoInit(); + touchInit(); + + mmInstall(FIFO_MAXMOD); + + SetYtrigger(80); + + installWifiFIFO(); + installSoundFIFO(); + + installSystemFIFO(); + + irqSet(IRQ_VCOUNT, VcountHandler); + irqSet(IRQ_VBLANK, VblankHandler); + + irqEnable( IRQ_VBLANK | IRQ_VCOUNT | IRQ_NETWORK); + + setPowerButtonCB(powerButtonCB); + + // Keep the ARM7 mostly idle + while (!exitflag) { + if ( 0 == (REG_KEYINPUT & (KEY_SELECT | KEY_START | KEY_L | KEY_R))) { + exitflag = true; + } + swiWaitForVBlank(); + } + return 0; +} diff --git a/cmake/combined/arm9/CMakeLists.txt b/cmake/combined/arm9/CMakeLists.txt new file mode 100644 index 0000000..389c8a2 --- /dev/null +++ b/cmake/combined/arm9/CMakeLists.txt @@ -0,0 +1,4 @@ +cmake_minimum_required(VERSION 3.7) +project(cmake-example-arm9 LANGUAGES C) + +add_executable(cmake-example-arm9 source/template.c) diff --git a/cmake/combined/arm9/source/template.c b/cmake/combined/arm9/source/template.c new file mode 100644 index 0000000..4d4c34a --- /dev/null +++ b/cmake/combined/arm9/source/template.c @@ -0,0 +1,33 @@ +/*--------------------------------------------------------------------------------- + + Simple console print demo + -- dovoto + +---------------------------------------------------------------------------------*/ +#include +#include + +//--------------------------------------------------------------------------------- +int main(void) { +//--------------------------------------------------------------------------------- + touchPosition touch; + + consoleDemoInit(); //setup the sub screen for printing + + iprintf("\n\n\tHello DS dev'rs\n"); + iprintf("\twww.drunkencoders.com\n"); + iprintf("\twww.devkitpro.org"); + + while(1) { + + touchRead(&touch); + iprintf("\x1b[10;0HTouch x = %04i, %04i\n", touch.rawx, touch.px); + iprintf("Touch y = %04i, %04i\n", touch.rawy, touch.py); + + swiWaitForVBlank(); + scanKeys(); + if (keysDown()&KEY_START) break; + } + + return 0; +} From 7a99af77a9daacb00188f448067ff6afcb35e032 Mon Sep 17 00:00:00 2001 From: Cameron Cawley Date: Thu, 10 Feb 2022 21:44:22 +0000 Subject: [PATCH 2/2] Remove the combined CMake example for now --- cmake/combined/CMakeLists.txt | 10 --- cmake/combined/arm7/CMakeLists.txt | 5 -- cmake/combined/arm7/source/template.c | 98 --------------------------- cmake/combined/arm9/CMakeLists.txt | 4 -- cmake/combined/arm9/source/template.c | 33 --------- 5 files changed, 150 deletions(-) delete mode 100644 cmake/combined/CMakeLists.txt delete mode 100644 cmake/combined/arm7/CMakeLists.txt delete mode 100644 cmake/combined/arm7/source/template.c delete mode 100644 cmake/combined/arm9/CMakeLists.txt delete mode 100644 cmake/combined/arm9/source/template.c diff --git a/cmake/combined/CMakeLists.txt b/cmake/combined/CMakeLists.txt deleted file mode 100644 index 30df18d..0000000 --- a/cmake/combined/CMakeLists.txt +++ /dev/null @@ -1,10 +0,0 @@ -cmake_minimum_required(VERSION 3.7) -project(cmake-example LANGUAGES C) - -nds_build_arm7(cmake-example-arm7 - SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/arm7 -) - -add_subdirectory(arm9) - -nds_create_rom(cmake-example ARM9 cmake-example-arm9 ARM7 cmake-example-arm7) diff --git a/cmake/combined/arm7/CMakeLists.txt b/cmake/combined/arm7/CMakeLists.txt deleted file mode 100644 index b5ccc8e..0000000 --- a/cmake/combined/arm7/CMakeLists.txt +++ /dev/null @@ -1,5 +0,0 @@ -cmake_minimum_required(VERSION 3.7) -project(cmake-example-arm7 LANGUAGES C) - -add_executable(cmake-example-arm7 source/template.c) -target_link_libraries(cmake-example-arm7 dswifi7 mm7) diff --git a/cmake/combined/arm7/source/template.c b/cmake/combined/arm7/source/template.c deleted file mode 100644 index 00592c3..0000000 --- a/cmake/combined/arm7/source/template.c +++ /dev/null @@ -1,98 +0,0 @@ -/*--------------------------------------------------------------------------------- - - default ARM7 core - - Copyright (C) 2005 - 2010 - Michael Noland (joat) - Jason Rogers (dovoto) - Dave Murphy (WinterMute) - - This software is provided 'as-is', without any express or implied - warranty. In no event will the authors be held liable for any - damages arising from the use of this software. - - Permission is granted to anyone to use this software for any - purpose, including commercial applications, and to alter it and - redistribute it freely, subject to the following restrictions: - - 1. The origin of this software must not be misrepresented; you - must not claim that you wrote the original software. If you use - this software in a product, an acknowledgment in the product - documentation would be appreciated but is not required. - - 2. Altered source versions must be plainly marked as such, and - must not be misrepresented as being the original software. - - 3. This notice may not be removed or altered from any source - distribution. - ----------------------------------------------------------------------------------*/ -#include -#include -#include - -//--------------------------------------------------------------------------------- -void VblankHandler(void) { -//--------------------------------------------------------------------------------- - Wifi_Update(); -} - - -//--------------------------------------------------------------------------------- -void VcountHandler() { -//--------------------------------------------------------------------------------- - inputGetAndSend(); -} - -volatile bool exitflag = false; - -//--------------------------------------------------------------------------------- -void powerButtonCB() { -//--------------------------------------------------------------------------------- - exitflag = true; -} - -//--------------------------------------------------------------------------------- -int main() { -//--------------------------------------------------------------------------------- - // clear sound registers - dmaFillWords(0, (void*)0x04000400, 0x100); - - REG_SOUNDCNT |= SOUND_ENABLE; - writePowerManagement(PM_CONTROL_REG, ( readPowerManagement(PM_CONTROL_REG) & ~PM_SOUND_MUTE ) | PM_SOUND_AMP ); - powerOn(POWER_SOUND); - - readUserSettings(); - ledBlink(0); - - irqInit(); - // Start the RTC tracking IRQ - initClockIRQ(); - fifoInit(); - touchInit(); - - mmInstall(FIFO_MAXMOD); - - SetYtrigger(80); - - installWifiFIFO(); - installSoundFIFO(); - - installSystemFIFO(); - - irqSet(IRQ_VCOUNT, VcountHandler); - irqSet(IRQ_VBLANK, VblankHandler); - - irqEnable( IRQ_VBLANK | IRQ_VCOUNT | IRQ_NETWORK); - - setPowerButtonCB(powerButtonCB); - - // Keep the ARM7 mostly idle - while (!exitflag) { - if ( 0 == (REG_KEYINPUT & (KEY_SELECT | KEY_START | KEY_L | KEY_R))) { - exitflag = true; - } - swiWaitForVBlank(); - } - return 0; -} diff --git a/cmake/combined/arm9/CMakeLists.txt b/cmake/combined/arm9/CMakeLists.txt deleted file mode 100644 index 389c8a2..0000000 --- a/cmake/combined/arm9/CMakeLists.txt +++ /dev/null @@ -1,4 +0,0 @@ -cmake_minimum_required(VERSION 3.7) -project(cmake-example-arm9 LANGUAGES C) - -add_executable(cmake-example-arm9 source/template.c) diff --git a/cmake/combined/arm9/source/template.c b/cmake/combined/arm9/source/template.c deleted file mode 100644 index 4d4c34a..0000000 --- a/cmake/combined/arm9/source/template.c +++ /dev/null @@ -1,33 +0,0 @@ -/*--------------------------------------------------------------------------------- - - Simple console print demo - -- dovoto - ----------------------------------------------------------------------------------*/ -#include -#include - -//--------------------------------------------------------------------------------- -int main(void) { -//--------------------------------------------------------------------------------- - touchPosition touch; - - consoleDemoInit(); //setup the sub screen for printing - - iprintf("\n\n\tHello DS dev'rs\n"); - iprintf("\twww.drunkencoders.com\n"); - iprintf("\twww.devkitpro.org"); - - while(1) { - - touchRead(&touch); - iprintf("\x1b[10;0HTouch x = %04i, %04i\n", touch.rawx, touch.px); - iprintf("Touch y = %04i, %04i\n", touch.rawy, touch.py); - - swiWaitForVBlank(); - scanKeys(); - if (keysDown()&KEY_START) break; - } - - return 0; -}