Created
November 8, 2017 22:26
-
-
Save ds84182/40e46129bd38b46a5100f15f96ba5eaf to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
Hello World example made by Aurelio Mannara for ctrulib | |
This code was modified for the last time on: 12/12/2014 21:00 UTC+1 | |
*/ | |
#include <3ds.h> | |
#include <stdio.h> | |
#include <cstdint> | |
#include <string> | |
#include <string_view> | |
#include <utility> | |
#include <vector> | |
static LightEvent test_event; | |
static s64 base_tick; | |
static std::vector<std::pair<std::string_view, s64>> thread_order; | |
int main(int argc, char **argv) | |
{ | |
gfxInitDefault(); | |
//Initialize console on top screen. Using NULL as the second argument tells the console library to use the internal console structure as current one | |
consoleInit(GFX_TOP, NULL); | |
LightEvent_Init(&test_event, ResetType::RESET_ONESHOT); | |
base_tick = svcGetSystemTick(); | |
threadCreate([](void *arg) { | |
thread_order.emplace_back("Thread 1 start!", svcGetSystemTick() - base_tick); | |
LightEvent_Wait(&test_event); | |
thread_order.emplace_back("Thread 1 done!", svcGetSystemTick() - base_tick); | |
}, nullptr, 0x1000, 0x20, 0, true); | |
thread_order.emplace_back("Created Thread 1", svcGetSystemTick() - base_tick); | |
threadCreate([](void *arg) { | |
thread_order.emplace_back("Thread 2 start!", svcGetSystemTick() - base_tick); | |
LightEvent_Wait(&test_event); | |
thread_order.emplace_back("Thread 2 done!", svcGetSystemTick() - base_tick); | |
}, nullptr, 0x1000, 0x20, 0, true); | |
thread_order.emplace_back("Created Thread 2", svcGetSystemTick() - base_tick); | |
thread_order.emplace_back("Allowing Thread 1 to start", svcGetSystemTick() - base_tick); | |
LightEvent_Signal(&thread_1_lock); | |
thread_order.emplace_back("Send signal 1", svcGetSystemTick() - base_tick); | |
LightEvent_Signal(&test_event); | |
svcSleepThread(500000ULL); | |
thread_order.emplace_back("Send signal 2", svcGetSystemTick() - base_tick); | |
LightEvent_Signal(&test_event); | |
thread_order.emplace_back("Test done", svcGetSystemTick() - base_tick); | |
printf("Hello World!\n"); | |
std::string str; | |
for (auto &sv : thread_order) { | |
str = sv.first; | |
printf("%s %lld\n", str.c_str(), sv.second); | |
} | |
printf("Press Start to exit.\n"); | |
// Main loop | |
while (aptMainLoop()) | |
{ | |
//Scan all the inputs. This should be done once for each frame | |
hidScanInput(); | |
//hidKeysDown returns information about which buttons have been just pressed (and they weren't in the previous frame) | |
u32 kDown = hidKeysDown(); | |
if (kDown & KEY_START) break; // break in order to return to hbmenu | |
// Flush and swap framebuffers | |
gfxFlushBuffers(); | |
gfxSwapBuffers(); | |
//Wait for VBlank | |
gspWaitForVBlank(); | |
} | |
gfxExit(); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment