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

@ -18,23 +18,21 @@
int main(int argc, char **argv) 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);
AudioInBuffer audin_buf; AudioInBuffer audin_buf;
AudioOutBuffer audout_buf; AudioOutBuffer audout_buf;
AudioInBuffer *released_in_buffer; AudioInBuffer *released_in_buffer;
AudioOutBuffer *released_out_buffer; AudioOutBuffer *released_out_buffer;
u32 released_in_count; u32 released_in_count;
u32 released_out_count; u32 released_out_count;
// Make sure the sample buffer size is aligned to 0x1000 bytes. // Make sure the sample buffer size is aligned to 0x1000 bytes.
u32 data_size = (SAMPLECOUNT * CHANNELCOUNT * BYTESPERSAMPLE); u32 data_size = (SAMPLECOUNT * CHANNELCOUNT * BYTESPERSAMPLE);
u32 buffer_size = (data_size + 0xfff) & ~0xfff; u32 buffer_size = (data_size + 0xfff) & ~0xfff;
// Allocate the buffers. // Allocate the buffers.
u8* in_buf_data = memalign(0x1000, buffer_size); u8* in_buf_data = memalign(0x1000, buffer_size);
u8* out_buf_data = memalign(0x1000, buffer_size); u8* out_buf_data = memalign(0x1000, buffer_size);
@ -45,65 +43,65 @@ int main(int argc, char **argv)
rc = MAKERESULT(Module_Libnx, LibnxError_OutOfMemory); rc = MAKERESULT(Module_Libnx, LibnxError_OutOfMemory);
printf("Failed to allocate sample data buffers\n"); printf("Failed to allocate sample data buffers\n");
} }
if (R_SUCCEEDED(rc)) if (R_SUCCEEDED(rc))
{ {
memset(in_buf_data, 0, buffer_size); memset(in_buf_data, 0, buffer_size);
memset(out_buf_data, 0, buffer_size); memset(out_buf_data, 0, buffer_size);
} }
if (R_SUCCEEDED(rc)) if (R_SUCCEEDED(rc))
{ {
// Initialize the default audio input device. // Initialize the default audio input device.
rc = audinInitialize(); rc = audinInitialize();
printf("audinInitialize() returned 0x%x\n", rc); printf("audinInitialize() returned 0x%x\n", rc);
} }
if (R_SUCCEEDED(rc)) if (R_SUCCEEDED(rc))
{ {
// Initialize the default audio output device. // Initialize the default audio output device.
rc = audoutInitialize(); rc = audoutInitialize();
printf("audoutInitialize() returned 0x%x\n", rc); printf("audoutInitialize() returned 0x%x\n", rc);
} }
if (R_SUCCEEDED(rc)) if (R_SUCCEEDED(rc))
{ {
// Start audio capture. // Start audio capture.
rc = audinStartAudioIn(); rc = audinStartAudioIn();
printf("audinStartAudioIn() returned 0x%x\n", rc); printf("audinStartAudioIn() returned 0x%x\n", rc);
} }
if (R_SUCCEEDED(rc)) if (R_SUCCEEDED(rc))
{ {
// Start audio playback. // Start audio playback.
rc = audoutStartAudioOut(); rc = audoutStartAudioOut();
printf("audoutStartAudioOut() returned 0x%x\n", rc); printf("audoutStartAudioOut() returned 0x%x\n", rc);
} }
// Prepare the input buffer. // Prepare the input buffer.
audin_buf.next = NULL; audin_buf.next = NULL;
audin_buf.buffer = in_buf_data; audin_buf.buffer = in_buf_data;
audin_buf.buffer_size = buffer_size; audin_buf.buffer_size = buffer_size;
audin_buf.data_size = data_size; audin_buf.data_size = data_size;
audin_buf.data_offset = 0; audin_buf.data_offset = 0;
// Prepare the output buffer. // Prepare the output buffer.
audout_buf.next = NULL; audout_buf.next = NULL;
audout_buf.buffer = out_buf_data; audout_buf.buffer = out_buf_data;
audout_buf.buffer_size = buffer_size; audout_buf.buffer_size = buffer_size;
audout_buf.data_size = data_size; audout_buf.data_size = data_size;
audout_buf.data_offset = 0; audout_buf.data_offset = 0;
// Prepare pointers and counters for released buffers. // Prepare pointers and counters for released buffers.
released_in_buffer = NULL; released_in_buffer = NULL;
released_out_buffer = NULL; released_out_buffer = NULL;
released_in_count = 0; released_in_count = 0;
released_out_count = 0; released_out_count = 0;
// Append the initial input buffer. // Append the initial input buffer.
rc = audinAppendAudioInBuffer(&audin_buf); rc = audinAppendAudioInBuffer(&audin_buf);
printf("audinAppendAudioInBuffer() returned 0x%x\n", rc); printf("audinAppendAudioInBuffer() returned 0x%x\n", rc);
// Append the initial output buffer. // Append the initial output buffer.
rc = audoutAppendAudioOutBuffer(&audout_buf); rc = audoutAppendAudioOutBuffer(&audout_buf);
printf("audoutAppendAudioOutBuffer() returned 0x%x\n", rc); printf("audoutAppendAudioOutBuffer() returned 0x%x\n", rc);
@ -117,21 +115,20 @@ int main(int argc, char **argv)
u64 kDown = hidKeysDown(CONTROLLER_P1_AUTO); u64 kDown = hidKeysDown(CONTROLLER_P1_AUTO);
if (kDown & KEY_PLUS) break; // break in order to return to hbmenu if (kDown & KEY_PLUS) break; // break in order to return to hbmenu
// Wait for audio capture and playback to finish. // Wait for audio capture and playback to finish.
audinWaitCaptureFinish(&released_in_buffer, &released_in_count, U64_MAX); audinWaitCaptureFinish(&released_in_buffer, &released_in_count, U64_MAX);
audoutWaitPlayFinish(&released_out_buffer, &released_out_count, U64_MAX); audoutWaitPlayFinish(&released_out_buffer, &released_out_count, U64_MAX);
// Copy the captured audio data into the playback buffer. // Copy the captured audio data into the playback buffer.
if ((released_in_buffer != NULL) && (released_out_buffer != NULL)) if ((released_in_buffer != NULL) && (released_out_buffer != NULL))
memcpy(released_out_buffer->buffer, released_in_buffer->buffer, released_in_buffer->data_size); memcpy(released_out_buffer->buffer, released_in_buffer->buffer, released_in_buffer->data_size);
// Append the released buffers again. // Append the released buffers again.
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

@ -27,61 +27,59 @@ void fill_audio_buffer(void* audio_buffer, size_t offset, size_t size, int frequ
int main(int argc, char **argv) int main(int argc, char **argv)
{ {
Result rc = 0; Result rc = 0;
int notefreq[] = { int notefreq[] = {
220, 220,
440, 880, 1760, 3520, 7040, 440, 880, 1760, 3520, 7040,
14080, 14080,
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);
AudioOutBuffer audout_buf; AudioOutBuffer audout_buf;
AudioOutBuffer *audout_released_buf; AudioOutBuffer *audout_released_buf;
// Make sure the sample buffer size is aligned to 0x1000 bytes. // Make sure the sample buffer size is aligned to 0x1000 bytes.
u32 data_size = (SAMPLECOUNT * CHANNELCOUNT * BYTESPERSAMPLE); u32 data_size = (SAMPLECOUNT * CHANNELCOUNT * BYTESPERSAMPLE);
u32 buffer_size = (data_size + 0xfff) & ~0xfff; u32 buffer_size = (data_size + 0xfff) & ~0xfff;
// Allocate the buffer. // Allocate the buffer.
u8* out_buf_data = memalign(0x1000, buffer_size); u8* out_buf_data = memalign(0x1000, buffer_size);
// Ensure buffers were properly allocated. // Ensure buffers were properly allocated.
if (out_buf_data == NULL) if (out_buf_data == NULL)
{ {
rc = MAKERESULT(Module_Libnx, LibnxError_OutOfMemory); rc = MAKERESULT(Module_Libnx, LibnxError_OutOfMemory);
printf("Failed to allocate sample data buffers\n"); printf("Failed to allocate sample data buffers\n");
} }
if (R_SUCCEEDED(rc)) if (R_SUCCEEDED(rc))
memset(out_buf_data, 0, buffer_size); memset(out_buf_data, 0, buffer_size);
if (R_SUCCEEDED(rc)) if (R_SUCCEEDED(rc))
{ {
// Initialize the default audio output device. // Initialize the default audio output device.
rc = audoutInitialize(); rc = audoutInitialize();
printf("audoutInitialize() returned 0x%x\n", rc); printf("audoutInitialize() returned 0x%x\n", rc);
} }
if (R_SUCCEEDED(rc)) if (R_SUCCEEDED(rc))
{ {
printf("Sample rate: 0x%x\n", audoutGetSampleRate()); printf("Sample rate: 0x%x\n", audoutGetSampleRate());
printf("Channel count: 0x%x\n", audoutGetChannelCount()); printf("Channel count: 0x%x\n", audoutGetChannelCount());
printf("PCM format: 0x%x\n", audoutGetPcmFormat()); printf("PCM format: 0x%x\n", audoutGetPcmFormat());
printf("Device state: 0x%x\n", audoutGetDeviceState()); printf("Device state: 0x%x\n", audoutGetDeviceState());
// Start audio playback. // Start audio playback.
rc = audoutStartAudioOut(); rc = audoutStartAudioOut();
printf("audoutStartAudioOut() returned 0x%x\n", rc); printf("audoutStartAudioOut() returned 0x%x\n", rc);
} }
bool play_tone = false; bool play_tone = false;
printf("Press A, B, Y, X, Left, Up, Right, Down, L, R, ZL or ZR to play a different tone.\n"); printf("Press A, B, Y, X, Left, Up, Right, Down, L, R, ZL or ZR to play a different tone.\n");
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
@ -91,79 +89,79 @@ int main(int argc, char **argv)
u64 kDown = hidKeysDown(CONTROLLER_P1_AUTO); u64 kDown = hidKeysDown(CONTROLLER_P1_AUTO);
if (kDown & KEY_PLUS) break; // break in order to return to hbmenu if (kDown & KEY_PLUS) break; // break in order to return to hbmenu
if (kDown & KEY_A) if (kDown & KEY_A)
{ {
fill_audio_buffer(out_buf_data, 0, data_size, notefreq[0]); fill_audio_buffer(out_buf_data, 0, data_size, notefreq[0]);
play_tone = true; play_tone = true;
} }
if (kDown & KEY_B) if (kDown & KEY_B)
{ {
fill_audio_buffer(out_buf_data, 0, data_size, notefreq[1]); fill_audio_buffer(out_buf_data, 0, data_size, notefreq[1]);
play_tone = true; play_tone = true;
} }
if (kDown & KEY_Y) if (kDown & KEY_Y)
{ {
fill_audio_buffer(out_buf_data, 0, data_size, notefreq[2]); fill_audio_buffer(out_buf_data, 0, data_size, notefreq[2]);
play_tone = true; play_tone = true;
} }
if (kDown & KEY_X) if (kDown & KEY_X)
{ {
fill_audio_buffer(out_buf_data, 0, data_size, notefreq[3]); fill_audio_buffer(out_buf_data, 0, data_size, notefreq[3]);
play_tone = true; play_tone = true;
} }
if (kDown & KEY_DLEFT) if (kDown & KEY_DLEFT)
{ {
fill_audio_buffer(out_buf_data, 0, data_size, notefreq[4]); fill_audio_buffer(out_buf_data, 0, data_size, notefreq[4]);
play_tone = true; play_tone = true;
} }
if (kDown & KEY_DUP) if (kDown & KEY_DUP)
{ {
fill_audio_buffer(out_buf_data, 0, data_size, notefreq[5]); fill_audio_buffer(out_buf_data, 0, data_size, notefreq[5]);
play_tone = true; play_tone = true;
} }
if (kDown & KEY_DRIGHT) if (kDown & KEY_DRIGHT)
{ {
fill_audio_buffer(out_buf_data, 0, data_size, notefreq[6]); fill_audio_buffer(out_buf_data, 0, data_size, notefreq[6]);
play_tone = true; play_tone = true;
} }
if (kDown & KEY_DDOWN) if (kDown & KEY_DDOWN)
{ {
fill_audio_buffer(out_buf_data, 0, data_size, notefreq[7]); fill_audio_buffer(out_buf_data, 0, data_size, notefreq[7]);
play_tone = true; play_tone = true;
} }
if (kDown & KEY_L) if (kDown & KEY_L)
{ {
fill_audio_buffer(out_buf_data, 0, data_size, notefreq[8]); fill_audio_buffer(out_buf_data, 0, data_size, notefreq[8]);
play_tone = true; play_tone = true;
} }
if (kDown & KEY_R) if (kDown & KEY_R)
{ {
fill_audio_buffer(out_buf_data, 0, data_size, notefreq[9]); fill_audio_buffer(out_buf_data, 0, data_size, notefreq[9]);
play_tone = true; play_tone = true;
} }
if (kDown & KEY_ZL) if (kDown & KEY_ZL)
{ {
fill_audio_buffer(out_buf_data, 0, data_size, notefreq[10]); fill_audio_buffer(out_buf_data, 0, data_size, notefreq[10]);
play_tone = true; play_tone = true;
} }
if (kDown & KEY_ZR) if (kDown & KEY_ZR)
{ {
fill_audio_buffer(out_buf_data, 0, data_size, notefreq[11]); fill_audio_buffer(out_buf_data, 0, data_size, notefreq[11]);
play_tone = true; play_tone = true;
} }
if (R_SUCCEEDED(rc) && play_tone) if (R_SUCCEEDED(rc) && play_tone)
{ {
// Prepare the audio data source buffer. // Prepare the audio data source buffer.
@ -172,30 +170,29 @@ int main(int argc, char **argv)
audout_buf.buffer_size = buffer_size; audout_buf.buffer_size = buffer_size;
audout_buf.data_size = data_size; audout_buf.data_size = data_size;
audout_buf.data_offset = 0; audout_buf.data_offset = 0;
// Prepare pointer for the released buffer. // Prepare pointer for the released buffer.
audout_released_buf = NULL; audout_released_buf = NULL;
// Play the buffer. // Play the buffer.
rc = audoutPlayBuffer(&audout_buf, &audout_released_buf); rc = audoutPlayBuffer(&audout_buf, &audout_released_buf);
if (R_FAILED(rc)) if (R_FAILED(rc))
printf("audoutPlayBuffer() returned 0x%x\n", rc); printf("audoutPlayBuffer() returned 0x%x\n", rc);
play_tone = false; play_tone = false;
} }
gfxFlushBuffers(); consoleUpdate(NULL);
gfxSwapBuffers();
} }
// Stop audio playback. // Stop audio playback.
rc = audoutStopAudioOut(); rc = audoutStopAudioOut();
printf("audoutStopAudioOut() returned 0x%x\n", rc); printf("audoutStopAudioOut() returned 0x%x\n", rc);
// 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;
} }