Update console examples to use the new console API. Improved documentation of application template.

This commit is contained in:
fincs 2018-10-01 13:08:43 +02:00
parent 4c0e6cf201
commit 4894fcf472
18 changed files with 110 additions and 150 deletions

View File

@ -17,7 +17,6 @@ int main(int argc, char **argv)
char username[0x21]; char username[0x21];
gfxInitDefault();
consoleInit(NULL); consoleInit(NULL);
memset(&userdata, 0, sizeof(userdata)); memset(&userdata, 0, sizeof(userdata));
@ -82,11 +81,9 @@ int main(int argc, char **argv)
if (kDown & KEY_PLUS) break; // break in order to return to hbmenu if (kDown & KEY_PLUS) break; // break in order to return to hbmenu
gfxFlushBuffers(); consoleUpdate(NULL);
gfxSwapBuffers();
} }
gfxExit(); consoleExit(NULL);
return 0; return 0;
} }

View File

@ -17,7 +17,6 @@ int main(int argc, char **argv)
NacpLanguageEntry *langentry = NULL; NacpLanguageEntry *langentry = NULL;
char name[0x201]; char name[0x201];
gfxInitDefault();
consoleInit(NULL); consoleInit(NULL);
buf = (NsApplicationControlData*)malloc(sizeof(NsApplicationControlData)); buf = (NsApplicationControlData*)malloc(sizeof(NsApplicationControlData));
@ -78,11 +77,9 @@ int main(int argc, char **argv)
if (kDown & KEY_PLUS) break; // break in order to return to hbmenu if (kDown & KEY_PLUS) break; // break in order to return to hbmenu
gfxFlushBuffers(); consoleUpdate(NULL);
gfxSwapBuffers();
} }
gfxExit(); consoleExit(NULL);
return 0; return 0;
} }

View File

@ -11,7 +11,6 @@
int main(void) int main(void)
{ {
gfxInitDefault();
consoleInit(NULL); consoleInit(NULL);
printf("Simple audren demonstration program\n"); printf("Simple audren demonstration program\n");
@ -78,7 +77,6 @@ int main(void)
// Main loop // Main loop
while (appletMainLoop()) while (appletMainLoop())
{ {
gfxSwapBuffers();
hidScanInput(); hidScanInput();
u64 kDown = hidKeysDown(CONTROLLER_P1_AUTO); u64 kDown = hidKeysDown(CONTROLLER_P1_AUTO);
@ -102,7 +100,7 @@ int main(void)
printf("sample count = %" PRIu32 "\n", audrvVoiceGetPlayedSampleCount(&drv, 0)); printf("sample count = %" PRIu32 "\n", audrvVoiceGetPlayedSampleCount(&drv, 0));
} }
gfxFlushBuffers(); consoleUpdate(NULL);
} }
if (initedDriver) if (initedDriver)
@ -110,6 +108,6 @@ int main(void)
if (initedAudren) if (initedAudren)
audrenExit(); audrenExit();
gfxExit(); consoleExit(NULL);
return 0; return 0;
} }

View File

@ -19,8 +19,6 @@ int main(int argc, char **argv)
{ {
Result rc = 0; Result rc = 0;
gfxInitDefault();
// Initialize console. Using NULL as the second argument tells the console library to use the internal console structure as current one. // Initialize console. Using NULL as the second argument tells the console library to use the internal console structure as current one.
consoleInit(NULL); consoleInit(NULL);
@ -130,8 +128,7 @@ int main(int argc, char **argv)
audinAppendAudioInBuffer(released_in_buffer); audinAppendAudioInBuffer(released_in_buffer);
audoutAppendAudioOutBuffer(released_out_buffer); audoutAppendAudioOutBuffer(released_out_buffer);
gfxFlushBuffers(); consoleUpdate(NULL);
gfxSwapBuffers();
} }
// Stop audio capture. // Stop audio capture.
@ -146,6 +143,6 @@ int main(int argc, char **argv)
audinExit(); audinExit();
audoutExit(); audoutExit();
gfxExit(); consoleExit(NULL);
return 0; return 0;
} }

View File

@ -35,8 +35,6 @@ int main(int argc, char **argv)
7040, 3520, 1760, 880, 440 7040, 3520, 1760, 880, 440
}; };
gfxInitDefault();
// Initialize console. Using NULL as the second argument tells the console library to use the internal console structure as current one. // Initialize console. Using NULL as the second argument tells the console library to use the internal console structure as current one.
consoleInit(NULL); consoleInit(NULL);
@ -185,8 +183,7 @@ int main(int argc, char **argv)
play_tone = false; play_tone = false;
} }
gfxFlushBuffers(); consoleUpdate(NULL);
gfxSwapBuffers();
} }
// Stop audio playback. // Stop audio playback.
@ -196,6 +193,6 @@ int main(int argc, char **argv)
// Terminate the default audio output device. // Terminate the default audio output device.
audoutExit(); audoutExit();
gfxExit(); consoleExit(NULL);
return 0; return 0;
} }

View File

@ -30,7 +30,6 @@ void printfile(const char* path)
int main(int argc, char **argv) int main(int argc, char **argv)
{ {
gfxInitDefault();
consoleInit(NULL); consoleInit(NULL);
Result rc = romfsInit(); Result rc = romfsInit();
@ -55,12 +54,10 @@ int main(int argc, char **argv)
if (kDown & KEY_PLUS) break; // break in order to return to hbmenu if (kDown & KEY_PLUS) break; // break in order to return to hbmenu
gfxFlushBuffers(); consoleUpdate(NULL);
gfxSwapBuffers();
} }
romfsExit(); romfsExit();
gfxExit(); consoleExit(NULL);
return 0; return 0;
} }

View File

@ -51,7 +51,6 @@ int main(int argc, char **argv)
bool account_selected=0; bool account_selected=0;
u64 titleID=0x01007ef00011e000;//titleID of the save to mount, in this case BOTW. u64 titleID=0x01007ef00011e000;//titleID of the save to mount, in this case BOTW.
gfxInitDefault();
consoleInit(NULL); consoleInit(NULL);
//Get the userID for save mounting. To mount common savedata, use FS_SAVEDATA_USERID_COMMONSAVE. //Get the userID for save mounting. To mount common savedata, use FS_SAVEDATA_USERID_COMMONSAVE.
@ -136,11 +135,9 @@ int main(int argc, char **argv)
if (kDown & KEY_PLUS) break; // break in order to return to hbmenu if (kDown & KEY_PLUS) break; // break in order to return to hbmenu
gfxFlushBuffers(); consoleUpdate(NULL);
gfxSwapBuffers();
} }
gfxExit(); consoleExit(NULL);
return 0; return 0;
} }

View File

@ -9,7 +9,6 @@
int main(int argc, char **argv) int main(int argc, char **argv)
{ {
gfxInitDefault();
consoleInit(NULL); consoleInit(NULL);
DIR* dir; DIR* dir;
@ -42,11 +41,9 @@ int main(int argc, char **argv)
if (kDown & KEY_PLUS) break; // break in order to return to hbmenu if (kDown & KEY_PLUS) break; // break in order to return to hbmenu
gfxFlushBuffers(); consoleUpdate(NULL);
gfxSwapBuffers();
} }
gfxExit(); consoleExit(NULL);
return 0; return 0;
} }

View File

@ -5,8 +5,6 @@
int main(int argc, char **argv) int main(int argc, char **argv)
{ {
gfxInitDefault();
//Initialize console. Using NULL as the second argument tells the console library to use the internal console structure as current one. //Initialize console. Using NULL as the second argument tells the console library to use the internal console structure as current one.
consoleInit(NULL); consoleInit(NULL);
@ -25,11 +23,9 @@ int main(int argc, char **argv)
if (kDown & KEY_PLUS) break; // break in order to return to hbmenu if (kDown & KEY_PLUS) break; // break in order to return to hbmenu
gfxFlushBuffers(); consoleUpdate(NULL);
gfxSwapBuffers();
} }
gfxExit(); consoleExit(NULL);
return 0; return 0;
} }

View File

@ -5,10 +5,8 @@
int main(int argc, char **argv) int main(int argc, char **argv)
{ {
gfxInitDefault();
consoleInit(NULL); consoleInit(NULL);
// clear screen and home cursor // clear screen and home cursor
printf( CONSOLE_ESC(2J) ); printf( CONSOLE_ESC(2J) );
@ -73,11 +71,9 @@ int main(int argc, char **argv)
if (kDown & KEY_PLUS) break; // break in order to return to hbmenu if (kDown & KEY_PLUS) break; // break in order to return to hbmenu
gfxFlushBuffers(); consoleUpdate(NULL);
gfxSwapBuffers();
} }
gfxExit(); consoleExit(NULL);
return 0; return 0;
} }

View File

@ -19,7 +19,6 @@ int main(int argc, char **argv)
"", "", "", "" "", "", "", ""
}; };
gfxInitDefault();
consoleInit(NULL); consoleInit(NULL);
u32 kDownOld = 0, kHeldOld = 0, kUpOld = 0; //In these variables there will be information about keys detected in the previous frame u32 kDownOld = 0, kHeldOld = 0, kUpOld = 0; //In these variables there will be information about keys detected in the previous frame
@ -81,11 +80,9 @@ int main(int argc, char **argv)
printf("\x1b[3;1H%04d; %04d", pos_left.dx, pos_left.dy); printf("\x1b[3;1H%04d; %04d", pos_left.dx, pos_left.dy);
printf("\x1b[5;1H%04d; %04d", pos_right.dx, pos_right.dy); printf("\x1b[5;1H%04d; %04d", pos_right.dx, pos_right.dy);
gfxFlushBuffers(); consoleUpdate(NULL);
gfxSwapBuffers();
} }
gfxExit(); consoleExit(NULL);
return 0; return 0;
} }

View File

@ -9,7 +9,6 @@ int main(int argc, char **argv)
{ {
u32 prev_touchcount=0; u32 prev_touchcount=0;
gfxInitDefault();
consoleInit(NULL); consoleInit(NULL);
printf("\x1b[1;1HPress PLUS to exit."); printf("\x1b[1;1HPress PLUS to exit.");
@ -52,11 +51,9 @@ int main(int argc, char **argv)
printf("[point_id=%d] px=%03d, py=%03d, dx=%03d, dy=%03d, angle=%03d\n", i, touch.px, touch.py, touch.dx, touch.dy, touch.angle); printf("[point_id=%d] px=%03d, py=%03d, dx=%03d, dy=%03d, angle=%03d\n", i, touch.px, touch.py, touch.dx, touch.dy, touch.angle);
} }
gfxFlushBuffers(); consoleUpdate(NULL);
gfxSwapBuffers();
} }
gfxExit(); consoleExit(NULL);
return 0; return 0;
} }

View File

@ -16,7 +16,6 @@ int main(int argc, char **argv)
HidVibrationValue VibrationValue_stop; HidVibrationValue VibrationValue_stop;
HidVibrationValue VibrationValues[2]; HidVibrationValue VibrationValues[2];
gfxInitDefault();
consoleInit(NULL); consoleInit(NULL);
printf("Press PLUS to exit.\n"); printf("Press PLUS to exit.\n");
@ -90,11 +89,9 @@ int main(int argc, char **argv)
if (R_FAILED(rc2)) printf("hidSendVibrationValues() for stop other device returned: 0x%x\n", rc2); if (R_FAILED(rc2)) printf("hidSendVibrationValues() for stop other device returned: 0x%x\n", rc2);
} }
gfxFlushBuffers(); consoleUpdate(NULL);
gfxSwapBuffers();
} }
gfxExit(); consoleExit(NULL);
return 0; return 0;
} }

View File

@ -13,7 +13,6 @@ int main(int argc, char **argv)
u64 (*funcptr)(void); u64 (*funcptr)(void);
u32 testcode[2] = {0xd2800000 | (0x7<<5), 0xd65f03c0};//"mov x0, #0x7" "ret" u32 testcode[2] = {0xd2800000 | (0x7<<5), 0xd65f03c0};//"mov x0, #0x7" "ret"
gfxInitDefault();
consoleInit(NULL); consoleInit(NULL);
rc = jitCreate(&j, 0x100000);//Adjust size as needed. rc = jitCreate(&j, 0x100000);//Adjust size as needed.
@ -58,11 +57,9 @@ int main(int argc, char **argv)
if (kDown & KEY_PLUS) break; // break in order to return to hbmenu if (kDown & KEY_PLUS) break; // break in order to return to hbmenu
gfxFlushBuffers(); consoleUpdate(NULL);
gfxSwapBuffers();
} }
gfxExit(); consoleExit(NULL);
return 0; return 0;
} }

View File

@ -16,9 +16,8 @@
#include <switch.h> #include <switch.h>
int main(int argc, char **argv) { int main(int argc, char **argv)
{
gfxInitDefault();
consoleInit(NULL); consoleInit(NULL);
// Initialise sockets // Initialise sockets
@ -62,11 +61,10 @@ int main(int argc, char **argv) {
printf("B Pressed\n"); printf("B Pressed\n");
} }
gfxFlushBuffers(); consoleUpdate(NULL);
gfxSwapBuffers();
} }
socketExit(); socketExit();
gfxExit(); consoleExit(NULL);
return 0; return 0;
} }

View File

@ -10,7 +10,6 @@ int main(int argc, char **argv)
u64 LanguageCode=0; u64 LanguageCode=0;
s32 Language=0; s32 Language=0;
gfxInitDefault();
consoleInit(NULL); consoleInit(NULL);
Result rc = setInitialize(); Result rc = setInitialize();
@ -58,12 +57,10 @@ int main(int argc, char **argv)
if (kDown & KEY_PLUS) break; // break in order to return to hbmenu if (kDown & KEY_PLUS) break; // break in order to return to hbmenu
gfxFlushBuffers(); consoleUpdate(NULL);
gfxSwapBuffers();
} }
setExit(); setExit();
gfxExit(); consoleExit(NULL);
return 0; return 0;
} }

View File

@ -1,33 +1,44 @@
#include <string.h> // Include the most common headers from the C standard library
#include <stdio.h> #include <stdio.h>
#include <stdlib.h>
#include <string.h>
// Include the main libnx system header, for Switch development
#include <switch.h> #include <switch.h>
int main(int argc, char **argv) // Main program entrypoint
int main(int argc, char* argv[])
{ {
gfxInitDefault(); // This example uses a text console, as a simple way to output text to the screen.
// If you want to write a software-rendered graphics application,
// take a look at the graphics/simplegfx example, which uses the libnx gfx API instead.
// If on the other hand you want to write an OpenGL based application,
// take a look at the graphics/opengl set of examples, which uses EGL instead.
consoleInit(NULL); consoleInit(NULL);
printf("Hello World!"); // Other initialization goes here. As a demonstration, we print hello world.
printf("Hello World!\n");
// Main loop // Main loop
while(appletMainLoop()) while (appletMainLoop())
{ {
//Scan all the inputs. This should be done once for each frame // Scan all the inputs. This should be done once for each frame
hidScanInput(); hidScanInput();
// hidKeysDown returns information about which buttons have been
// just pressed in this frame compared to the previous one
u64 kDown = hidKeysDown(CONTROLLER_P1_AUTO);
if (kDown & KEY_PLUS)
break; // break in order to return to hbmenu
// Your code goes here // Your code goes here
//hidKeysDown returns information about which buttons have been just pressed (and they weren't in the previous frame) // Update the console, sending a new frame to the display
u64 kDown = hidKeysDown(CONTROLLER_P1_AUTO); consoleUpdate(NULL);
if (kDown & KEY_PLUS) break; // break in order to return to hbmenu
gfxFlushBuffers();
gfxSwapBuffers();
} }
gfxExit(); // Deinitialize and clean up resources used by the console (important!)
consoleExit(NULL);
return 0; return 0;
} }

View File

@ -10,7 +10,6 @@ const char* const weekDays[7] = {"Sunday", "Monday", "Tuesday", "Wednesday", "Th
int main(int argc, char **argv) int main(int argc, char **argv)
{ {
gfxInitDefault();
consoleInit(NULL); consoleInit(NULL);
printf("\x1b[16;16HPress PLUS to exit."); printf("\x1b[16;16HPress PLUS to exit.");
@ -41,11 +40,9 @@ int main(int argc, char **argv)
printf("\x1b[1;1H%02i:%02i:%02i", hours, minutes, seconds); printf("\x1b[1;1H%02i:%02i:%02i", hours, minutes, seconds);
printf("\n%s %s %i %i", weekDays[wday], months[month], day, year); printf("\n%s %s %i %i", weekDays[wday], months[month], day, year);
gfxFlushBuffers(); consoleUpdate(NULL);
gfxSwapBuffers();
} }
gfxExit(); consoleExit(NULL);
return 0; return 0;
} }