Skip to content

Commit

Permalink
3DS: Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Cruel committed Apr 6, 2016
1 parent f6c3363 commit e2b9572
Show file tree
Hide file tree
Showing 19 changed files with 1,697 additions and 9 deletions.
53 changes: 53 additions & 0 deletions backends/platform/3ds/3ds.mk
@@ -0,0 +1,53 @@
TARGET := scummvm

APP_TITLE := ScummVM
APP_DESCRIPTION := Point-and-click adventure game engines
APP_AUTHOR := ScummVM Team
APP_ICON := backends/platform/3ds/icon.png

ARCH := -march=armv6k -mtune=mpcore -mfloat-abi=hard -mtp=soft
CXXFLAGS += -std=gnu++11
ASFLAGS += -mfloat-abi=hard
LDFLAGS += -specs=3dsx.specs $(ARCH) -L$(DEVKITPRO)/libctru/lib -L$(DEVKITPRO)/portlibs/3ds/lib

.PHONY: clean_3ds

all: $(TARGET).3dsx

clean: clean_3ds

clean_3ds:
$(RM) $(TARGET).3dsx

$(TARGET).smdh: $(APP_ICON) $(MAKEFILE_LIST)
@smdhtool --create "$(APP_TITLE)" "$(APP_DESCRIPTION)" "$(APP_AUTHOR)" $(APP_ICON) $@
@echo built ... $(notdir $@)

$(TARGET).3dsx: $(EXECUTABLE) $(TARGET).smdh
@3dsxtool $< $@ --smdh=$(TARGET).smdh
@echo built ... $(notdir $@)

#---------------------------------------------------------------------------------
# rules for assembling GPU shaders
#---------------------------------------------------------------------------------
define shader-as
$(eval FILEPATH := $(patsubst %.shbin.o,%.shbin,$@))
$(eval FILE := $(patsubst %.shbin.o,%.shbin,$(notdir $@)))
picasso -o $(FILEPATH) $1
bin2s $(FILEPATH) | $(AS) -o $@
echo "extern const u8" `(echo $(FILE) | sed -e 's/^\([0-9]\)/_\1/' | tr . _)`"_end[];" > `(echo $(FILEPATH) | tr . _)`.h
echo "extern const u8" `(echo $(FILE) | sed -e 's/^\([0-9]\)/_\1/' | tr . _)`"[];" >> `(echo $(FILEPATH) | tr . _)`.h
echo "extern const u32" `(echo $(FILE) | sed -e 's/^\([0-9]\)/_\1/' | tr . _)`_size";" >> `(echo $(FILEPATH) | tr . _)`.h
endef

%.shbin.o : %.v.pica %.g.pica
@echo $(notdir $^)
@$(call shader-as,$^)

%.shbin.o : %.v.pica
@echo $(notdir $<)
@$(call shader-as,$<)

%.shbin.o : %.shlist
@echo $(notdir $<)
@$(call shader-as,$(foreach file,$(shell cat $<),$(dir $<)/$(file)))
46 changes: 46 additions & 0 deletions backends/platform/3ds/gui.cpp
@@ -0,0 +1,46 @@
/* ScummVM - Graphic Adventure Engine
*
* ScummVM is the legal property of its developers, whose names
* are too numerous to list here. Please refer to the COPYRIGHT
* file distributed with this source distribution.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
*/

#include "backends/platform/3ds/gui.h"
#include "common/system.h"

StatusMessageDialog* StatusMessageDialog::_opened = 0;

StatusMessageDialog::StatusMessageDialog(const Common::String &message, uint32 duration)
: MessageDialog(message, 0, 0) {
_timer = g_system->getMillis() + duration;
if (_opened)
_opened->close();
_opened = this;
}

void StatusMessageDialog::handleTickle() {
MessageDialog::handleTickle();
if (g_system->getMillis() > _timer)
close();
}

void StatusMessageDialog::close() {
GUI::Dialog::close();
if (_opened)
_opened = 0;
}
41 changes: 41 additions & 0 deletions backends/platform/3ds/gui.h
@@ -0,0 +1,41 @@
/* ScummVM - Graphic Adventure Engine
*
* ScummVM is the legal property of its developers, whose names
* are too numerous to list here. Please refer to the COPYRIGHT
* file distributed with this source distribution.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
*/

#ifndef GUI_3DS_H
#define GUI_3DS_H

#include "gui/message.h"

class StatusMessageDialog : public GUI::MessageDialog {
public:
StatusMessageDialog(const Common::String &message, uint32 duration);

void handleTickle();

protected:
virtual void close();

uint32 _timer;
static StatusMessageDialog* _opened;
};

#endif // GUI_3DS_H
Binary file added backends/platform/3ds/icon.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
50 changes: 50 additions & 0 deletions backends/platform/3ds/main.cpp
@@ -0,0 +1,50 @@
/* ScummVM - Graphic Adventure Engine
*
* ScummVM is the legal property of its developers, whose names
* are too numerous to list here. Please refer to the COPYRIGHT
* file distributed with this source distribution.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
*/

#define FORBIDDEN_SYMBOL_ALLOW_ALL

#include "osystem.h"
#include <3ds.h>

int main(int argc, char *argv[]) {
// Initialize basic libctru stuff
gfxInitDefault();
cfguInit();
osSetSpeedupEnable(true);
// consoleInit(GFX_TOP, NULL);

g_system = new OSystem_3DS();
assert(g_system);

// Invoke the actual ScummVM main entry point
// if (argc > 2)
// res = scummvm_main(argc-2, &argv[2]);
// else
// res = scummvm_main(argc, argv);
scummvm_main(0, nullptr);

delete dynamic_cast<OSystem_3DS*>(g_system);

cfguExit();
gfxExit();
return 0;
}
16 changes: 16 additions & 0 deletions backends/platform/3ds/module.mk
@@ -0,0 +1,16 @@
MODULE := backends/platform/3ds

MODULE_OBJS := \
main.o \
shader.shbin.o \
sprite.o \
gui.o \
osystem.o \
osystem-graphics.o \
osystem-audio.o \
osystem-events.o

# We don't use rules.mk but rather manually update OBJS and MODULE_DIRS.
MODULE_OBJS := $(addprefix $(MODULE)/, $(MODULE_OBJS))
OBJS := $(MODULE_OBJS) $(OBJS)
MODULE_DIRS += $(sort $(dir $(MODULE_OBJS)))
107 changes: 107 additions & 0 deletions backends/platform/3ds/osystem-audio.cpp
@@ -0,0 +1,107 @@
/* ScummVM - Graphic Adventure Engine
*
* ScummVM is the legal property of its developers, whose names
* are too numerous to list here. Please refer to the COPYRIGHT
* file distributed with this source distribution.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
*/

#include "osystem.h"

static bool exitAudioThread = false;
static bool hasAudio = false;

static void audioThreadFunc(void* arg) {
Audio::MixerImpl *mixer = (Audio::MixerImpl *) arg;
OSystem_3DS *osys = (OSystem_3DS*)g_system;

int i;
const int channel = 0;
int bufferIndex = 0;
const int bufferCount = 3;
const int bufferSize = 80000; // Can't be too small, based on delayMillis duration
const int sampleRate = 22050;
int sampleLen = 0;
uint32 lastTime = osys->getMillis(true);
uint32 time = lastTime;
ndspWaveBuf buffers[bufferCount];

for(i = 0; i < bufferCount; ++i) {
memset(&buffers[i], 0, sizeof(ndspWaveBuf));
buffers[i].data_vaddr = linearAlloc(bufferSize);
buffers[i].looping = false;
buffers[i].status = NDSP_WBUF_FREE;
}

ndspChnReset(channel);
ndspChnSetInterp(channel, NDSP_INTERP_LINEAR);
ndspChnSetRate(channel, sampleRate);
ndspChnSetFormat(channel, NDSP_FORMAT_STEREO_PCM16);

while(!exitAudioThread) {
bufferIndex++;
bufferIndex %= bufferCount;
ndspWaveBuf* buf = &buffers[bufferIndex];

osys->delayMillis(100); // Note: Increasing the delay requires a bigger buffer

time = osys->getMillis(true);
sampleLen = (time - lastTime) * 22 * 4; // sampleRate / 1000 * channelCount * sizeof(int16);
lastTime = time;

if (sampleLen > 0) {
buf->nsamples = mixer->mixCallback(buf->data_adpcm, sampleLen);
if (buf->nsamples > 0) {
DSP_FlushDataCache(buf->data_vaddr, bufferSize);
ndspChnWaveBufAdd(channel, buf);
}
}
}

for(i = 0; i < bufferCount; ++i)
linearFree(buffers[i].data_pcm8);
}

void OSystem_3DS::initAudio() {
_mixer = new Audio::MixerImpl(this, 22050);

hasAudio = R_SUCCEEDED(ndspInit());
_mixer->setReady(false);

if (hasAudio) {
s32 prio = 0;
svcGetThreadPriority(&prio, CUR_THREAD_HANDLE);
audioThread = threadCreate(&audioThreadFunc, _mixer, 32*1048, prio-1, -2, false);
}
}

void OSystem_3DS::destroyAudio() {
if (hasAudio) {
exitAudioThread = true;
threadJoin(audioThread, U64_MAX);
threadFree(audioThread);
ndspExit();
}

delete _mixer;
_mixer = 0;
}

Audio::Mixer *OSystem_3DS::getMixer() {
assert(_mixer);
return _mixer;
}

0 comments on commit e2b9572

Please sign in to comment.