mirror of
https://github.com/UpsilonNumworks/Upsilon.git
synced 2026-01-19 00:37:25 +01:00
[ion/3ds] Got something on screen!
This commit is contained in:
@@ -62,7 +62,7 @@ endif
|
||||
# Get rid of unused symbols. This is also useful even if LTO=1.
|
||||
LDFLAGS += -Wl,--gc-sections
|
||||
|
||||
LIBPATHS := $(foreach dir,$(LIBDIRS),-L$(dir)/lib)
|
||||
LIBPATHS := $(foreach dir,$(LIBDIRS),-L$(dir)/lib)
|
||||
|
||||
LDFLAGS += $(SFLAGS) $(LIBPATHS) $(LIBS) -lgcc
|
||||
|
||||
|
||||
@@ -1,4 +1,11 @@
|
||||
|
||||
ion_src += $(addprefix ion/src/simulator/3ds/, \
|
||||
main.cpp \
|
||||
callback.cpp \
|
||||
display.cpp \
|
||||
framebuffer.cpp \
|
||||
language.cpp \
|
||||
telemetry_init.cpp \
|
||||
keyboard.cpp \
|
||||
events_keyboard.cpp \
|
||||
)
|
||||
|
||||
8
ion/src/simulator/3ds/callback.cpp
Normal file
8
ion/src/simulator/3ds/callback.cpp
Normal file
@@ -0,0 +1,8 @@
|
||||
#include "platform.h"
|
||||
|
||||
void IonSimulatorCallbackDidRefresh() {
|
||||
}
|
||||
|
||||
void IonSimulatorCallbackDidScanKeyboard() {
|
||||
}
|
||||
|
||||
40
ion/src/simulator/3ds/display.cpp
Normal file
40
ion/src/simulator/3ds/display.cpp
Normal file
@@ -0,0 +1,40 @@
|
||||
#include "display.h"
|
||||
#include "framebuffer.h"
|
||||
#include <assert.h>
|
||||
#include <ion/display.h>
|
||||
#include <string.h>
|
||||
|
||||
namespace Ion {
|
||||
namespace Simulator {
|
||||
namespace Display {
|
||||
|
||||
void* pixels;
|
||||
|
||||
void init() {
|
||||
gfxSetScreenFormat(GFX_TOP, GSP_BGR8_OES);
|
||||
pixels = nullptr;
|
||||
}
|
||||
|
||||
void quit() {
|
||||
pixels = nullptr;
|
||||
}
|
||||
|
||||
void draw() {
|
||||
pixels = gfxGetFramebuffer(GFX_TOP, GFX_LEFT, NULL, NULL);
|
||||
|
||||
|
||||
for(int i = 0; i < Ion::Display::Width; i++) {
|
||||
for(int j = 0; j < Ion::Display::Height; j++) {
|
||||
((u8*)pixels)[239*3 - j*3 + 0 + i*3*240 + 3*240*40] = Framebuffer::address()[i + j * Ion::Display::Width].blue();
|
||||
((u8*)pixels)[239*3 - j*3 + 1 + i*3*240 + 3*240*40] = Framebuffer::address()[i + j * Ion::Display::Width].green();
|
||||
((u8*)pixels)[239*3 - j*3 + 2 + i*3*240 + 3*240*40] = Framebuffer::address()[i + j * Ion::Display::Width].red();
|
||||
}
|
||||
}
|
||||
|
||||
gfxFlushBuffers();
|
||||
gfxSwapBuffers();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
20
ion/src/simulator/3ds/display.h
Normal file
20
ion/src/simulator/3ds/display.h
Normal file
@@ -0,0 +1,20 @@
|
||||
#ifndef ION_SIMULATOR_DISPLAY_H
|
||||
#define ION_SIMULATOR_DISPLAY_H
|
||||
|
||||
#include <kandinsky.h>
|
||||
#include <3ds.h>
|
||||
|
||||
namespace Ion {
|
||||
namespace Simulator {
|
||||
namespace Display {
|
||||
|
||||
void init();
|
||||
void quit();
|
||||
|
||||
void draw();
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
20
ion/src/simulator/3ds/events_keyboard.cpp
Normal file
20
ion/src/simulator/3ds/events_keyboard.cpp
Normal file
@@ -0,0 +1,20 @@
|
||||
#include "main.h"
|
||||
#include "platform.h"
|
||||
|
||||
#include <assert.h>
|
||||
#include <ion/events.h>
|
||||
#include <string.h>
|
||||
|
||||
|
||||
namespace Ion {
|
||||
namespace Events {
|
||||
|
||||
|
||||
Event getPlatformEvent() {
|
||||
Event result = None;
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
50
ion/src/simulator/3ds/framebuffer.cpp
Normal file
50
ion/src/simulator/3ds/framebuffer.cpp
Normal file
@@ -0,0 +1,50 @@
|
||||
#include "framebuffer.h"
|
||||
#include <ion/display.h>
|
||||
#include "main.h"
|
||||
|
||||
static KDColor sPixels[Ion::Display::Width * Ion::Display::Height];
|
||||
static bool sFrameBufferActive = true;
|
||||
|
||||
namespace Ion {
|
||||
namespace Display {
|
||||
|
||||
static KDFrameBuffer sFrameBuffer = KDFrameBuffer(sPixels, KDSize(Ion::Display::Width, Ion::Display::Height));
|
||||
|
||||
void pushRect(KDRect r, const KDColor * pixels) {
|
||||
if (sFrameBufferActive) {
|
||||
Simulator::Main::setNeedsRefresh();
|
||||
sFrameBuffer.pushRect(r, pixels);
|
||||
}
|
||||
}
|
||||
|
||||
void pushRectUniform(KDRect r, KDColor c) {
|
||||
if (sFrameBufferActive) {
|
||||
Simulator::Main::setNeedsRefresh();
|
||||
sFrameBuffer.pushRectUniform(r, c);
|
||||
}
|
||||
}
|
||||
|
||||
void pullRect(KDRect r, KDColor * pixels) {
|
||||
if (sFrameBufferActive) {
|
||||
sFrameBuffer.pullRect(r, pixels);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
namespace Ion {
|
||||
namespace Simulator {
|
||||
namespace Framebuffer {
|
||||
|
||||
const KDColor * address() {
|
||||
return sPixels;
|
||||
}
|
||||
|
||||
void setActive(bool enabled) {
|
||||
sFrameBufferActive = enabled;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
18
ion/src/simulator/3ds/framebuffer.h
Normal file
18
ion/src/simulator/3ds/framebuffer.h
Normal file
@@ -0,0 +1,18 @@
|
||||
#ifndef ION_SIMULATOR_FRAMEBUFFER_H
|
||||
#define ION_SIMULATOR_FRAMEBUFFER_H
|
||||
|
||||
#include <kandinsky.h>
|
||||
|
||||
namespace Ion {
|
||||
namespace Simulator {
|
||||
namespace Framebuffer {
|
||||
|
||||
const KDColor * address();
|
||||
void setActive(bool enabled);
|
||||
void writeToFile(const char * filename);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
23
ion/src/simulator/3ds/keyboard.cpp
Normal file
23
ion/src/simulator/3ds/keyboard.cpp
Normal file
@@ -0,0 +1,23 @@
|
||||
#include <ion/keyboard.h>
|
||||
#include "platform.h"
|
||||
#include "main.h"
|
||||
|
||||
#include <3ds.h>
|
||||
|
||||
void IonSimulatorKeyboardKeyDown(int keyNumber) {
|
||||
}
|
||||
|
||||
void IonSimulatorKeyboardKeyUp(int keyNumber) {
|
||||
}
|
||||
|
||||
namespace Ion {
|
||||
namespace Keyboard {
|
||||
|
||||
State scan() {
|
||||
hidScanInput();
|
||||
Simulator::Main::refresh();
|
||||
return 0;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
25
ion/src/simulator/3ds/language.cpp
Normal file
25
ion/src/simulator/3ds/language.cpp
Normal file
@@ -0,0 +1,25 @@
|
||||
#include "platform.h"
|
||||
|
||||
#include <3ds.h>
|
||||
|
||||
const char* IonSimulatorGetLanguageCode() {
|
||||
u8 lang = 0;
|
||||
|
||||
CFGU_GetSystemLanguage(&lang);
|
||||
|
||||
switch(lang) {
|
||||
case CFG_LANGUAGE_FR:
|
||||
return "fr";
|
||||
case CFG_LANGUAGE_ES:
|
||||
return "es";
|
||||
case CFG_LANGUAGE_DE:
|
||||
return "de";
|
||||
case CFG_LANGUAGE_PT:
|
||||
return "pt";
|
||||
|
||||
// en fr es de pt hu
|
||||
default:
|
||||
return "en";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,28 +1,98 @@
|
||||
#include "main.h"
|
||||
#include "display.h"
|
||||
#include "platform.h"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <vector>
|
||||
|
||||
#include <ion.h>
|
||||
#include <ion/timing.h>
|
||||
#include <ion/events.h>
|
||||
|
||||
#include <3ds.h>
|
||||
|
||||
int main(int argc, char * argv[]) {
|
||||
gfxInitDefault();
|
||||
consoleInit(GFX_TOP, NULL);
|
||||
|
||||
printf("Hello, world!\n");
|
||||
|
||||
// Main loop
|
||||
while (aptMainLoop())
|
||||
{
|
||||
gspWaitForVBlank();
|
||||
gfxSwapBuffers();
|
||||
hidScanInput();
|
||||
|
||||
// Your code goes here
|
||||
u32 kDown = hidKeysDown();
|
||||
if (kDown & KEY_START)
|
||||
break; // break in order to return to hbmenu
|
||||
}
|
||||
|
||||
gfxExit();
|
||||
return 0;
|
||||
void Ion::Timing::msleep(uint32_t ms) {
|
||||
svcSleepThread((s64) ms * 1000);
|
||||
}
|
||||
|
||||
int main(int argc, char * argv[]) {
|
||||
Ion::Simulator::Main::init();
|
||||
|
||||
std::vector<const char *> arguments(argv, argv + argc);
|
||||
|
||||
const char * language = IonSimulatorGetLanguageCode();
|
||||
if (language != nullptr) {
|
||||
arguments.push_back("--language");
|
||||
arguments.push_back(language);
|
||||
}
|
||||
|
||||
ion_main(arguments.size(), &arguments[0]);
|
||||
Ion::Simulator::Main::quit();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
namespace Ion {
|
||||
namespace Simulator {
|
||||
namespace Main {
|
||||
|
||||
static bool sNeedsRefresh = false;
|
||||
|
||||
void init() {
|
||||
gfxInitDefault();
|
||||
cfguInit();
|
||||
|
||||
consoleInit(GFX_BOTTOM, NULL);
|
||||
consoleDebugInit(debugDevice_SVC);
|
||||
printf("Init!\n");
|
||||
relayout();
|
||||
}
|
||||
|
||||
void relayout() {
|
||||
int windowWidth = 800;
|
||||
int windowHeight = 240;
|
||||
|
||||
// Keep original aspect ration in screen_only mode.
|
||||
/*
|
||||
float scale = (float)(Ion::Display::Width) / (float)(Ion::Display::Height);
|
||||
if ((float)(windowHeight) * scale > float(windowWidth)) {
|
||||
sScreenRect.w = windowWidth;
|
||||
sScreenRect.h = (int)((float)(windowWidth) / scale);
|
||||
} else {
|
||||
sScreenRect.w = (int)((float)(windowHeight) * scale);
|
||||
sScreenRect.h = windowHeight;
|
||||
}
|
||||
|
||||
sScreenRect.x = (windowWidth - sScreenRect.w) / 2;
|
||||
sScreenRect.y = (windowHeight - sScreenRect.h) / 2;
|
||||
*/
|
||||
|
||||
setNeedsRefresh();
|
||||
}
|
||||
|
||||
void setNeedsRefresh() {
|
||||
sNeedsRefresh = true;
|
||||
}
|
||||
|
||||
void refresh() {
|
||||
if (!sNeedsRefresh) {
|
||||
return;
|
||||
}
|
||||
|
||||
Display::draw();
|
||||
|
||||
sNeedsRefresh = false;
|
||||
}
|
||||
|
||||
void quit() {
|
||||
printf("Exit\n");
|
||||
cfguExit();
|
||||
gfxExit();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
19
ion/src/simulator/3ds/main.h
Normal file
19
ion/src/simulator/3ds/main.h
Normal file
@@ -0,0 +1,19 @@
|
||||
#ifndef ION_SIMULATOR_MAIN_H
|
||||
#define ION_SIMULATOR_MAIN_H
|
||||
|
||||
namespace Ion {
|
||||
namespace Simulator {
|
||||
namespace Main {
|
||||
|
||||
void init();
|
||||
void quit();
|
||||
|
||||
void setNeedsRefresh();
|
||||
void refresh();
|
||||
void relayout();
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
23
ion/src/simulator/3ds/platform.h
Normal file
23
ion/src/simulator/3ds/platform.h
Normal file
@@ -0,0 +1,23 @@
|
||||
#ifndef ION_SIMULATOR_PLATFORM_H
|
||||
#define ION_SIMULATOR_PLATFORM_H
|
||||
|
||||
#include <stdbool.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* Those functions should be implemented per-platform.
|
||||
* They are defined as C function for easier interop. */
|
||||
|
||||
const char * IonSimulatorGetLanguageCode();
|
||||
|
||||
void IonSimulatorKeyboardKeyDown(int keyNumber);
|
||||
void IonSimulatorKeyboardKeyUp(int keyNumber);
|
||||
void IonSimulatorEventsPushEvent(int eventNumber);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
15
ion/src/simulator/3ds/telemetry_init.cpp
Normal file
15
ion/src/simulator/3ds/telemetry_init.cpp
Normal file
@@ -0,0 +1,15 @@
|
||||
#include "platform.h"
|
||||
|
||||
namespace Ion {
|
||||
namespace Simulator {
|
||||
namespace Telemetry {
|
||||
|
||||
void init() {
|
||||
}
|
||||
|
||||
void shutdown() {
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user