Skip to content

Commit

Permalink
Upgrade BuildTools + Default ARM7 to BlocksDS v11
Browse files Browse the repository at this point in the history
  • Loading branch information
NightScript370 committed Nov 19, 2023
1 parent 6b16f52 commit b6b2578
Show file tree
Hide file tree
Showing 6 changed files with 154 additions and 137 deletions.
3 changes: 1 addition & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,4 @@
*.elf
*.nds
*.o
arm7/build
arm9/build
build
21 changes: 21 additions & 0 deletions .vscode/c_cpp_properties.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"configurations": [
{
"name": "Win32",
"includePath": [
"${workspaceFolder}/**",
"C:/msys64/opt/wonderful/thirdparty/blocksds/core/libs/libnds/include/**"
],
"defines": [
"__NDS__",
"ARM9"
],
"windowsSdkVersion": "10.0.19041.0",
"compilerPath": "C:\\msys64\\ucrt64\\bin\\gcc.exe",
"cStandard": "c17",
"cppStandard": "c++17",
"intelliSenseMode": "windows-gcc-x64"
}
],
"version": 4
}
36 changes: 12 additions & 24 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@ BLOCKSDSEXT ?= /opt/blocksds/external
NAME := NeoDS

GAME_TITLE := NeoDS
GAME_SUBTITLE1 := Built with BlocksDS
GAME_SUBTITLE2 := github.com/blocksds/sdk
GAME_SUBTITLE1 := A NeoGeo emulator for DS
GAME_ICON := icon.bmp

# DLDI and internal SD slot of DSi
Expand All @@ -26,7 +25,7 @@ SDIMAGE := image.bin
# Source code paths
# -----------------

NITROFATDIR :=
NITROFSDIR ?=

# Tools
# -----
Expand All @@ -43,17 +42,10 @@ else
V := @
endif

# Directories
# -----------

ARM9DIR := arm9
ARM7DIR := arm7

# Build artfacts
# --------------

NITROFAT_IMG := build/nitrofat.bin
ROM := $(NAME).nds
ROM := $(NAME).nds

# Targets
# -------
Expand All @@ -74,16 +66,12 @@ arm9:
arm7:
$(V)+$(MAKE) -f arm7/Makefile --no-print-directory

ifneq ($(strip $(NITROFATDIR)),)
ifneq ($(strip $(NITROFSDIR)),)
# Additional arguments for ndstool
NDSTOOL_FAT := -F $(NITROFAT_IMG)

$(NITROFAT_IMG): $(NITROFATDIR)
@echo " MKFATIMG $@ $(NITROFATDIR)"
$(V)$(BLOCKSDS)/tools/mkfatimg/mkfatimg -t $(NITROFATDIR) $@ 0
NDSTOOL_ARGS := -d $(NITROFSDIR)

# Make the NDS ROM depend on the filesystem image only if it is needed
$(ROM): $(NITROFAT_IMG)
# Make the NDS ROM depend on the filesystem only if it is needed
$(ROM): $(NITROFSDIR)
endif

# Combine the title strings
Expand All @@ -98,13 +86,13 @@ $(ROM): arm9 arm7
$(V)$(BLOCKSDS)/tools/ndstool/ndstool -c $@ \
-7 build/arm7.elf -9 build/arm9.elf \
-b $(GAME_ICON) "$(GAME_FULL_TITLE)" \
$(NDSTOOL_FAT)
$(NDSTOOL_ARGS)

sdimage:
@echo " MKFATIMG $(SDIMAGE) $(SDROOT)"
$(V)$(BLOCKSDS)/tools/mkfatimg/mkfatimg -t $(SDROOT) $(SDIMAGE) 0
$(V)$(BLOCKSDS)/tools/mkfatimg/mkfatimg -t $(SDROOT) $(SDIMAGE)

dldipatch: $(ROM)
@echo " DLDITOOL $(ROM)"
$(V)$(BLOCKSDS)/tools/dlditool/dlditool \
$(BLOCKSDS)/tools/dldi/r4tfv2.dldi $(ROM)
@echo " DLDIPATCH $(ROM)"
$(V)$(BLOCKSDS)/tools/dldipatch/dldipatch patch \
$(BLOCKSDS)/sys/dldi_r4/r4tf.dldi $(ROM)
34 changes: 24 additions & 10 deletions arm7/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,26 @@
BLOCKSDS ?= /opt/blocksds/core
BLOCKSDSEXT ?= /opt/blocksds/external

WONDERFUL_TOOLCHAIN ?= /opt/wonderful
ARM_NONE_EABI_PATH ?= $(WONDERFUL_TOOLCHAIN)/toolchain/gcc-arm-none-eabi/bin/

# Source code paths
# -----------------

SOURCEDIRS := arm7/source common/source
INCLUDEDIRS := common/source arm7/source
BINDIRS :=
SOURCEDIRS ?= arm7/source common/source
INCLUDEDIRS ?= common/source arm7/source
BINDIRS ?=

# Defines passed to all files
# ---------------------------

DEFINES :=
DEFINES ?=

# Libraries
# ---------

LIBS := -lnds7 -lc
LIBDIRS := $(BLOCKSDS)/libs/libnds \
$(BLOCKSDS)/libs/libc7
LIBS ?= -lnds7
LIBDIRS += $(BLOCKSDS)/libs/libnds

# Build artifacts
# -----------------
Expand All @@ -36,7 +38,7 @@ MAP := build/$(NAME).map
# Tools
# -----

PREFIX := arm-none-eabi-
PREFIX := $(ARM_NONE_EABI_PATH)arm-none-eabi-
CC := $(PREFIX)gcc
CXX := $(PREFIX)g++
OBJDUMP := $(PREFIX)objdump
Expand Down Expand Up @@ -74,9 +76,11 @@ ARCH := -mcpu=arm7tdmi -mtune=arm7tdmi
WARNFLAGS := -Wall

ifeq ($(SOURCES_CPP),)
LD := $(CC)
LD := $(CC)
LIBS += -lc
else
LD := $(CXX)
LD := $(CXX)
LIBS += -lstdc++ -lc
endif

INCLUDEFLAGS := $(foreach path,$(INCLUDEDIRS),-I$(path)) \
Expand Down Expand Up @@ -154,11 +158,21 @@ $(BUILDDIR)/%.c.o : %.c
@$(MKDIR) -p $(@D)
$(V)$(CC) $(CFLAGS) -MMD -MP -c -o $@ $<

$(BUILDDIR)/%.arm.c.o : %.arm.c
@echo " CC.7 $<"
@$(MKDIR) -p $(@D)
$(V)$(CC) $(CFLAGS) -MMD -MP -marm -mlong-calls -c -o $@ $<

$(BUILDDIR)/%.cpp.o : %.cpp
@echo " CXX.7 $<"
@$(MKDIR) -p $(@D)
$(V)$(CXX) $(CXXFLAGS) -MMD -MP -c -o $@ $<

$(BUILDDIR)/%.arm.cpp.o : %.arm.cpp
@echo " CXX.7 $<"
@$(MKDIR) -p $(@D)
$(V)$(CXX) $(CXXFLAGS) -MMD -MP -marm -mlong-calls -c -o $@ $<

$(BUILDDIR)/%.bin.o $(BUILDDIR)/%_bin.h : %.bin
@echo " BIN2C.7 $<"
@$(MKDIR) -p $(@D)
Expand Down
147 changes: 64 additions & 83 deletions arm7/source/template.c
Original file line number Diff line number Diff line change
@@ -1,109 +1,90 @@
// SPDX-License-Identifier: Zlib
// SPDX-FileNotice: Modified from the original version by the BlocksDS project.
//
// Copyright (C) 2005 Michael Noland (joat)
// Copyright (C) 2005 Jason Rogers (Dovoto)
// Copyright (C) 2005-2015 Dave Murphy (WinterMute)
// Copyright (C) 2023 Antonio Niño Díaz

// Default ARM7 core

#include <nds.h>
#include <stdlib.h>
#include "NeoSystem7.h"
#include "NeoCpuZ80.h"
#include "NeoYM2610.h"
#include "NeoIPC.h"
#include "NeoAudio.h"

//static int vcount = 80;
//static touchPosition first,tempPos;
volatile bool exit_loop = false;

/*static void handleInput()
void power_button_callback(void)
{
static int lastbut = -1;
uint16 but=0, x=0, y=0, xpx=0, ypx=0, z1=0, z2=0;
but = REG_KEYXY;
if (!( (but ^ lastbut) & (1<<6))) {
tempPos = touchReadXY();
if ( tempPos.x == 0 || tempPos.y == 0 ) {
but |= (1 <<6);
lastbut = but;
} else {
x = tempPos.x;
y = tempPos.y;
xpx = tempPos.px;
ypx = tempPos.py;
z1 = tempPos.z1;
z2 = tempPos.z2;
}
} else {
lastbut = but;
but |= (1 <<6);
}
if ( vcount == 80 ) {
first = tempPos;
} else {
if ( abs( xpx - first.px) > 10 || abs( ypx - first.py) > 10 ||
(but & ( 1<<6)) ) {
but |= (1 <<6);
lastbut = but;
} else {
IPC->mailBusy = 1;
IPC->touchX = x;
IPC->touchY = y;
IPC->touchXpx = xpx;
IPC->touchYpx = ypx;
IPC->touchZ1 = z1;
IPC->touchZ2 = z2;
IPC->mailBusy = 0;
}
}
IPC->buttons = but;
vcount ^= (80 ^ 130);
}*/

static void VcountHandler()
exit_loop = true;
}

void vblank_handler(void)
{
inputGetAndSend();
inputGetAndSend();
}

/* static void VblankHandler()
int main(int argc, char *argv[])
{
neoIPCInit();
//Reset the clock if needed
rtcReset();

} */
// Initialize sound hardware
enableSound();

//from DrZ80.asm
//extern u32 DAATABLE_LOCAL;
// Read user information from the firmware (name, birthday, etc)
readUserSettings();

int main(int argc, char ** argv)
{
irqInit();
initClockIRQ();
touchInit();
fifoInit();
installSystemFIFO();
// Stop LED blinking
ledBlink(0);

neoIPCInit();
//irqSet(IRQ_VBLANK, VblankHandler);
// Using the calibration values read from the firmware with
// readUserSettings(), calculate some internal values to convert raw
// coordinates into screen coordinates.
touchInit();

irqInit();
irqSet(IRQ_VBLANK, vblank_handler);
SetYtrigger(0);
irqSet(IRQ_VCOUNT, VcountHandler);
irqSet(IRQ_TIMER3, neoAudioEventHandler);
irqEnable(IRQ_VCOUNT | IRQ_TIMER3);

//wait for arm9 to reset us
neoIPCWaitCommand(NEOARM7_RESET);
fifoInit();

//kinda messy...we keep the DaaTable in main ram on the arm9 side,
//give the arm7 a pointer through the IPC struct here
//DAATABLE_LOCAL = (u32)NEOIPC->pZ80DaaTable;

neoSystem7Init();
installSystemFIFO(); // Sleep mode, storage, firmware...

neoIPCAckCommand();
// This sets a callback that is called when the power button in a DSi
// console is pressed. It has no effect in a DS.
setPowerButtonCB(power_button_callback);

neoSystem7Execute();
// Read current date from the RTC and setup an interrupt to update the time
// regularly. The interrupt simply adds one second every time, it doesn't
// read the date. Reading the RTC is very slow, so it's a bad idea to do it
// frequently.
initClockIRQTimer(3);

return 0;
}
irqEnable(IRQ_VBLANK);
REG_IME = 1;

neoIPCWaitCommand(NEOARM7_RESET);

while (!exit_loop)
{
const uint16_t key_mask = KEY_SELECT | KEY_START | KEY_L | KEY_R;
uint16_t keys_pressed = ~REG_KEYINPUT;

if ((keys_pressed & key_mask) == key_mask)
exit_loop = true;

swiWaitForVBlank();
}

neoSystem7Init();
neoIPCAckCommand();
neoSystem7Execute();

return 0;
}
Loading

0 comments on commit b6b2578

Please sign in to comment.