Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Initial Nintendo DS port #4

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
Open
Changes from 1 commit
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
Next Next commit
Initial Nintendo DS port
  • Loading branch information
ccawley2011 committed Jan 1, 2025
commit 111d186dd2224d2da1bdc20f91776c3578f7db90
32 changes: 32 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -180,6 +180,38 @@ riscpkg: $(TARGET)
mkdir ArcEm/Apps/Misc/hostfs
endif

ifeq (${SYSTEM},nds)
CC=arm-none-eabi-gcc
LD=$(CC)
ARM9_ARCH = -mthumb -mthumb-interwork -march=armv5te -mtune=arm946e-s
CFLAGS += $(ARM9_ARCH) -ffunction-sections -fdata-sections -DSYSTEM_nds -DARM9 -DUSE_FAKEMAIN -DNO_OPEN64 -isystem $(DEVKITPRO)/libnds/include -Wno-cast-align -Wno-format
LDFLAGS += -specs=ds_arm9.specs -g $(ARM9_ARCH) -Wl,--gc-sections -L$(DEVKITPRO)/libnds/lib
LIBS += -lfilesystem -lfat -lnds9
OBJS += nds/main.o
ifneq ($(DEBUG),yes)
CFLAGS += -DNDEBUG
endif

TARGET = ArcEm.elf
all: ArcEm.nds

%.nds: %.elf %.arm7.elf nds/arc.bmp
mkdir -p romfs/extnrom
cp support_modules/*/*,ffa romfs/extnrom
ndstool -c $@ -9 $< -7 $*.arm7.elf -b nds/arc.bmp "ArcEm;Archimedes Emulator;WIP" -d romfs

ARM7_ARCH = -mthumb -mthumb-interwork -march=armv4t -mtune=arm7tdmi
ARM7_CFLAGS = $(ARM7_ARCH) -Os -ffunction-sections -fdata-sections -DARM7 -isystem $(DEVKITPRO)/libnds/include
ARM7_LDFLAGS = -specs=ds_arm7.specs -g $(ARM7_ARCH) -Wl,--gc-sections -L$(DEVKITPRO)/libnds/lib
ARM7_LIBS = -lnds7

ArcEm.arm7.elf: nds/arm7/main.arm7.o
$(LD) $(ARM7_LDFLAGS) $^ $(ARM7_LIBS) -o $@

%.arm7.o: %.c
$(CC) $(ARM7_CFLAGS) -o $@ -c $<
endif

ifeq (${SYSTEM},SDL)
SDL_CONFIG=sdl2-config
CFLAGS += -DSYSTEM_SDL -DUSE_FAKEMAIN $(shell $(SDL_CONFIG) --cflags)
11 changes: 10 additions & 1 deletion arch/ArcemConfig.c
Original file line number Diff line number Diff line change
@@ -76,7 +76,11 @@ void ArcemConfig_SetupDefaults(ArcemConfig *pConfig)

#if defined(EXTNROM_SUPPORT)
/* The default directory is extnrom in the current working directory */
#ifdef SYSTEM_nds
pConfig->sEXTNDirectory = arcemconfig_StringDuplicate("nitro:/extnrom");
#else
pConfig->sEXTNDirectory = arcemconfig_StringDuplicate("extnrom");
#endif
/* If we've run out of memory this early, something is very wrong */
if(NULL == pConfig->sEXTNDirectory) {
ControlPane_Error(EXIT_FAILURE,"Failed to allocate memory for initial configuration. Please free up more memory.\n");
@@ -239,6 +243,7 @@ void ArcemConfig_ParseCommandLine(ArcemConfig *pConfig, int argc, char *argv[])
{
unsigned int uValue;
int iArgument = 0;
#ifndef SYSTEM_nds
char sHelpString[] =
"Arcem <Options>\n"
" Where options are one or more of the following\n"
@@ -270,6 +275,7 @@ void ArcemConfig_ParseCommandLine(ArcemConfig *pConfig, int argc, char *argv[])
" --menukeys <a> <b> - Specify which key numbers open the tweak menu\n"
#endif /* SYSTEM_riscos_single */
;
#endif

/* No commandline arguments? */
if(0 == argc) {
@@ -290,6 +296,7 @@ void ArcemConfig_ParseCommandLine(ArcemConfig *pConfig, int argc, char *argv[])
iArgument = 1;

while(iArgument < argc) {
#ifndef SYSTEM_nds
if(0 == strcmp("--version", argv[iArgument])) {
printf("Arcem %s\n", Version);

@@ -300,7 +307,9 @@ void ArcemConfig_ParseCommandLine(ArcemConfig *pConfig, int argc, char *argv[])

exit(EXIT_SUCCESS);
}
else if(0 == strcmp("--config", argv[iArgument])) {
else
#endif
if(0 == strcmp("--config", argv[iArgument])) {
if(iArgument+1 < argc) { /* Is there a following argument? */
ini_parse(argv[iArgument + 1], ArcemConfig_Handler, pConfig);
iArgument += 2;
17 changes: 17 additions & 0 deletions arch/dbugsys.h
Original file line number Diff line number Diff line change
@@ -9,6 +9,7 @@
#ifndef _DBUGSYS_H_
#define _DBUGSYS_H_

#include "c99.h"
#include <stdio.h>
#include <stdarg.h>

@@ -26,6 +27,21 @@
#undef DEBUG_HDC63463
#undef DEBUG_CONFIG

#ifdef SYSTEM_nds
#undef IOC_WARN
#undef WARN
#undef WARN_MEMC
#undef WARN_I2C
#undef WARN_DATA
#undef WARN_DMAWRITE
#undef WARN_DMAREAD
#undef WARN_INTS
#undef WARN_VIDC
#undef WARN_KEYBOARD
#undef WARN_FDC1772
#undef WARN_HDC63463
#undef WARN_CONFIG
#else
#define IOC_WARN
#define WARN
#define WARN_MEMC
@@ -39,6 +55,7 @@
#define WARN_FDC1772
#define WARN_HDC63463
#define WARN_CONFIG
#endif

#define dbug_stdout printf

2 changes: 1 addition & 1 deletion armdefs.h
Original file line number Diff line number Diff line change
@@ -269,7 +269,7 @@ struct ARMul_State {

};

#ifdef AMIGA
#if defined(AMIGA) || defined(SYSTEM_nds)
extern void *state_alloc(int s);
extern void state_free(void *p);
#else
18 changes: 18 additions & 0 deletions c99.h
Original file line number Diff line number Diff line change
@@ -64,4 +64,22 @@ typedef unsigned char bool;
#define inline __inline
#endif

#ifdef SYSTEM_nds
/* Use integer only versions of printf and scanf to reduce the executable size */
#include <stdio.h>

#define printf iprintf
#define fprintf fiprintf
#define sprintf siprintf
#define snprintf sniprintf

#define vprintf viprintf
#define vfprintf vfiprintf
#define vsprintf vsiprintf
#define vsnprintf vsniprintf

#define sscanf siscanf
#define fscanf fiscanf
#endif

#endif
10 changes: 5 additions & 5 deletions dagstandalone.c
Original file line number Diff line number Diff line change
@@ -39,6 +39,7 @@
/**************************************************************/
#ifndef _WIN32
#ifndef AMIGA
#ifndef SYSTEM_nds
static void dagstandalone_handlesignal(int sig) {
dbug("Terminate ARMulator - excecution\n");
#ifdef BENCHMARKEXIT
@@ -53,6 +54,7 @@ static void dagstandalone_handlesignal(int sig) {
}
#endif
#endif
#endif

static void InitFail(int exitcode, char const *which) {
ControlPane_Error(exitcode,"%s interface failed to initialise. Exiting\n",
@@ -68,22 +70,20 @@ static void InitFail(int exitcode, char const *which) {
*
*/
void dagstandalone(ArcemConfig *pConfig) {
ARMul_State *emu_state = NULL;
#ifndef _WIN32
#ifndef AMIGA
#ifndef SYSTEM_nds
struct sigaction action;
#endif
#endif
ARMul_State *emu_state = NULL;

#ifndef _WIN32
#ifndef AMIGA
/* Setup a signal handler for SIGUSR1 */
action.sa_handler = dagstandalone_handlesignal;
sigemptyset (&action.sa_mask);
action.sa_flags = 0;

sigaction(SIGUSR1, &action, (struct sigaction *) 0);
#endif
#endif
#endif

ARMul_EmulateInit();
4 changes: 4 additions & 0 deletions hostfs.c
Original file line number Diff line number Diff line change
@@ -221,6 +221,9 @@ dbug_hostfs(const char *format, ...)
}
#endif

#ifdef SYSTEM_nds
static inline void warn_hostfs(const char *format, ...) {}
#else
static void
warn_hostfs(const char *format, ...)
{
@@ -230,6 +233,7 @@ warn_hostfs(const char *format, ...)
vfprintf(stderr, format, ap);
va_end(ap);
}
#endif

static void
path_construct(ARMul_State *state, const char *old_path, const char *ro_path,
57 changes: 57 additions & 0 deletions nds/ControlPane.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
/* Redraw and other services for the control pane */
/* (c) David Alan Gilbert 1995 - see Readme file for copying info */


#include "armdefs.h"
#include "archio.h"
#include "armarc.h"
#include "ControlPane.h"
#include "../arch/keyboard.h"

#include <stdarg.h>
#include <stdio.h>

#include <nds.h>

bool hasKeyboard = false;

void ControlPane_Init(ARMul_State *state)
{
videoSetModeSub(MODE_0_2D | DISPLAY_BG0_ACTIVE);
vramSetBankH(VRAM_H_SUB_BG);

#ifndef NDEBUG
scanKeys();

int held = keysHeld();
if (held & KEY_SELECT) {
consoleInit(NULL, 0, BgType_Text4bpp, BgSize_T_256x256, 15, 0, false, true);
} else
#endif
{
Keyboard *keyboard = keyboardInit(NULL, 0, BgType_Text4bpp, BgSize_T_256x512, 15, 0, false, true);
keyboard->OnKeyPressed = OnKeyPressed;
keyboard->OnKeyReleased = OnKeyReleased;
keyboardShow();
hasKeyboard = true;
}
}

void ControlPane_Error(int code,const char *fmt,...)
{
va_list args;
va_start(args,fmt);

/* Log it */
vprintf(fmt,args);

while(1) {
swiWaitForVBlank();
scanKeys();
if (keysDown() & KEY_START)
break;
}

/* Quit */
exit(code);
}
13 changes: 13 additions & 0 deletions nds/ControlPane.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
/* (c) David Alan Gilbert 1995 - see Readme file for copying info */
#ifndef CONTROLPANE_HEADER
#define CONTROLPANE_HEADER

void ControlPane_Init(ARMul_State *state);

/* Report an error and exit */
void ControlPane_Error(int code,const char *fmt,...);

void OnKeyPressed(int key);
void OnKeyReleased(int key);

#endif
Loading