From a8e052bb72a13ce7a3c87a14d809cc51b7b3df84 Mon Sep 17 00:00:00 2001 From: plutoo Date: Wed, 7 Mar 2018 18:51:41 +0100 Subject: [PATCH] Untabify --- audio/echo/source/main.c | 252 +++++++------- audio/playtone/source/main.c | 356 ++++++++++---------- fs/romfs/source/main.c | 90 ++--- fs/sdmc/source/main.c | 66 ++-- graphics/printing/hello-world/source/main.c | 40 +-- graphics/printing/vt52-demo/source/main.c | 112 +++--- graphics/simplegfx/source/main.c | 96 +++--- hid/irsensor/source/main.c | 184 +++++----- hid/read-controls/source/main.c | 130 +++---- hid/touch-screen/source/main.c | 74 ++-- hid/vibration/source/main.c | 110 +++--- settings/get_system_language/source/main.c | 86 ++--- templates/application/source/main.c | 36 +- templates/library/source/templatelib.c | 4 +- time/source/main.c | 58 ++-- usb/usbds/source/main.c | 184 +++++----- 16 files changed, 939 insertions(+), 939 deletions(-) diff --git a/audio/echo/source/main.c b/audio/echo/source/main.c index 9dc087c..229d91f 100644 --- a/audio/echo/source/main.c +++ b/audio/echo/source/main.c @@ -17,136 +17,136 @@ int main(int argc, char **argv) { - Result rc = 0; - - gfxInitDefault(); + 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. - consoleInit(NULL); - - AudioInBuffer audin_buf; - AudioOutBuffer audout_buf; - AudioInBuffer *released_in_buffer; - AudioOutBuffer *released_out_buffer; - u32 released_in_count; - u32 released_out_count; - - // Make sure the sample buffer size is aligned to 0x1000 bytes. - u32 data_size = (SAMPLECOUNT * CHANNELCOUNT * BYTESPERSAMPLE); - u32 buffer_size = (data_size + 0xfff) & ~0xfff; - - // Allocate the buffers. - u8* in_buf_data = memalign(0x1000, buffer_size); - u8* out_buf_data = memalign(0x1000, buffer_size); + // Initialize console. Using NULL as the second argument tells the console library to use the internal console structure as current one. + consoleInit(NULL); + + AudioInBuffer audin_buf; + AudioOutBuffer audout_buf; + AudioInBuffer *released_in_buffer; + AudioOutBuffer *released_out_buffer; + u32 released_in_count; + u32 released_out_count; + + // Make sure the sample buffer size is aligned to 0x1000 bytes. + u32 data_size = (SAMPLECOUNT * CHANNELCOUNT * BYTESPERSAMPLE); + u32 buffer_size = (data_size + 0xfff) & ~0xfff; + + // Allocate the buffers. + u8* in_buf_data = memalign(0x1000, buffer_size); + u8* out_buf_data = memalign(0x1000, buffer_size); - // Ensure buffers were properly allocated. - if ((in_buf_data == NULL) || (out_buf_data == NULL)) - { - rc = MAKERESULT(Module_Libnx, LibnxError_OutOfMemory); - printf("Failed to allocate sample data buffers\n"); - } - - if (R_SUCCEEDED(rc)) - { - memset(in_buf_data, 0, buffer_size); - memset(out_buf_data, 0, buffer_size); - } - - if (R_SUCCEEDED(rc)) - { - // Initialize the default audio input device. - rc = audinInitialize(); - printf("audinInitialize() returned 0x%x\n", rc); - } - - if (R_SUCCEEDED(rc)) - { - // Initialize the default audio output device. - rc = audoutInitialize(); - printf("audoutInitialize() returned 0x%x\n", rc); - } - - if (R_SUCCEEDED(rc)) - { - // Start audio capture. - rc = audinStartAudioIn(); - printf("audinStartAudioIn() returned 0x%x\n", rc); - } - - if (R_SUCCEEDED(rc)) - { - // Start audio playback. - rc = audoutStartAudioOut(); - printf("audoutStartAudioOut() returned 0x%x\n", rc); - } - - // Prepare the input buffer. - audin_buf.next = NULL; - audin_buf.buffer = in_buf_data; - audin_buf.buffer_size = buffer_size; - audin_buf.data_size = data_size; - audin_buf.data_offset = 0; - - // Prepare the output buffer. - audout_buf.next = NULL; - audout_buf.buffer = out_buf_data; - audout_buf.buffer_size = buffer_size; - audout_buf.data_size = data_size; - audout_buf.data_offset = 0; - - // Prepare pointers and counters for released buffers. - released_in_buffer = NULL; - released_out_buffer = NULL; - released_in_count = 0; - released_out_count = 0; - - // Append the initial input buffer. - rc = audinAppendAudioInBuffer(&audin_buf); - printf("audinAppendAudioInBuffer() returned 0x%x\n", rc); - - // Append the initial output buffer. - rc = audoutAppendAudioOutBuffer(&audout_buf); - printf("audoutAppendAudioOutBuffer() returned 0x%x\n", rc); + // Ensure buffers were properly allocated. + if ((in_buf_data == NULL) || (out_buf_data == NULL)) + { + rc = MAKERESULT(Module_Libnx, LibnxError_OutOfMemory); + printf("Failed to allocate sample data buffers\n"); + } + + if (R_SUCCEEDED(rc)) + { + memset(in_buf_data, 0, buffer_size); + memset(out_buf_data, 0, buffer_size); + } + + if (R_SUCCEEDED(rc)) + { + // Initialize the default audio input device. + rc = audinInitialize(); + printf("audinInitialize() returned 0x%x\n", rc); + } + + if (R_SUCCEEDED(rc)) + { + // Initialize the default audio output device. + rc = audoutInitialize(); + printf("audoutInitialize() returned 0x%x\n", rc); + } + + if (R_SUCCEEDED(rc)) + { + // Start audio capture. + rc = audinStartAudioIn(); + printf("audinStartAudioIn() returned 0x%x\n", rc); + } + + if (R_SUCCEEDED(rc)) + { + // Start audio playback. + rc = audoutStartAudioOut(); + printf("audoutStartAudioOut() returned 0x%x\n", rc); + } + + // Prepare the input buffer. + audin_buf.next = NULL; + audin_buf.buffer = in_buf_data; + audin_buf.buffer_size = buffer_size; + audin_buf.data_size = data_size; + audin_buf.data_offset = 0; + + // Prepare the output buffer. + audout_buf.next = NULL; + audout_buf.buffer = out_buf_data; + audout_buf.buffer_size = buffer_size; + audout_buf.data_size = data_size; + audout_buf.data_offset = 0; + + // Prepare pointers and counters for released buffers. + released_in_buffer = NULL; + released_out_buffer = NULL; + released_in_count = 0; + released_out_count = 0; + + // Append the initial input buffer. + rc = audinAppendAudioInBuffer(&audin_buf); + printf("audinAppendAudioInBuffer() returned 0x%x\n", rc); + + // Append the initial output buffer. + rc = audoutAppendAudioOutBuffer(&audout_buf); + printf("audoutAppendAudioOutBuffer() returned 0x%x\n", rc); - while (appletMainLoop()) - { - //Scan all the inputs. This should be done once for each frame - hidScanInput(); + while (appletMainLoop()) + { + //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(CONTROLLER_P1_AUTO); + //hidKeysDown returns information about which buttons have been just pressed (and they weren't in the previous frame) + u32 kDown = hidKeysDown(CONTROLLER_P1_AUTO); - if (kDown & KEY_PLUS) break; // break in order to return to hbmenu - - // Wait for audio capture and playback to finish. - audinWaitCaptureFinish(&released_in_buffer, &released_in_count, U64_MAX); - audoutWaitPlayFinish(&released_out_buffer, &released_out_count, U64_MAX); - - // Copy the captured audio data into the playback buffer. - if ((released_in_buffer != NULL) && (released_out_buffer != NULL)) - memcpy(released_out_buffer->buffer, released_in_buffer->buffer, released_in_buffer->data_size); - - // Append the released buffers again. - audinAppendAudioInBuffer(released_in_buffer); - audoutAppendAudioOutBuffer(released_out_buffer); - - gfxFlushBuffers(); - gfxSwapBuffers(); - gfxWaitForVsync(); - } - - // Stop audio capture. - rc = audinStopAudioIn(); - printf("audinStopAudioIn() returned 0x%x\n", rc); - - // Stop audio playback. - rc = audoutStopAudioOut(); - printf("audoutStopAudioOut() returned 0x%x\n", rc); + if (kDown & KEY_PLUS) break; // break in order to return to hbmenu + + // Wait for audio capture and playback to finish. + audinWaitCaptureFinish(&released_in_buffer, &released_in_count, U64_MAX); + audoutWaitPlayFinish(&released_out_buffer, &released_out_count, U64_MAX); + + // Copy the captured audio data into the playback buffer. + if ((released_in_buffer != NULL) && (released_out_buffer != NULL)) + memcpy(released_out_buffer->buffer, released_in_buffer->buffer, released_in_buffer->data_size); + + // Append the released buffers again. + audinAppendAudioInBuffer(released_in_buffer); + audoutAppendAudioOutBuffer(released_out_buffer); + + gfxFlushBuffers(); + gfxSwapBuffers(); + gfxWaitForVsync(); + } + + // Stop audio capture. + rc = audinStopAudioIn(); + printf("audinStopAudioIn() returned 0x%x\n", rc); + + // Stop audio playback. + rc = audoutStopAudioOut(); + printf("audoutStopAudioOut() returned 0x%x\n", rc); - // Terminate the default audio devices. - audinExit(); - audoutExit(); - - gfxExit(); - return 0; + // Terminate the default audio devices. + audinExit(); + audoutExit(); + + gfxExit(); + return 0; } diff --git a/audio/playtone/source/main.c b/audio/playtone/source/main.c index 1240cfb..445b250 100644 --- a/audio/playtone/source/main.c +++ b/audio/playtone/source/main.c @@ -12,191 +12,191 @@ #define BYTESPERSAMPLE 2 void fill_audio_buffer(void* audio_buffer, size_t offset, size_t size, int frequency) { - if (audio_buffer == NULL) return; - - u32* dest = (u32*) audio_buffer; - for (int i = 0; i < size; i++) { - // This is a simple sine wave, with a frequency of `frequency` Hz, and an amplitude 30% of maximum. - s16 sample = 0.3 * 0x7FFF * sin(frequency * (2 * M_PI) * (offset + i) / SAMPLERATE); + if (audio_buffer == NULL) return; + + u32* dest = (u32*) audio_buffer; + for (int i = 0; i < size; i++) { + // This is a simple sine wave, with a frequency of `frequency` Hz, and an amplitude 30% of maximum. + s16 sample = 0.3 * 0x7FFF * sin(frequency * (2 * M_PI) * (offset + i) / SAMPLERATE); - // Stereo samples are interleaved: left and right channels. - dest[i] = (sample << 16) | (sample & 0xffff); - } + // Stereo samples are interleaved: left and right channels. + dest[i] = (sample << 16) | (sample & 0xffff); + } } int main(int argc, char **argv) { - Result rc = 0; - - int notefreq[] = { - 220, - 440, 880, 1760, 3520, 7040, - 14080, - 7040, 3520, 1760, 880, 440 - }; - - gfxInitDefault(); + Result rc = 0; + + int notefreq[] = { + 220, + 440, 880, 1760, 3520, 7040, + 14080, + 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. - consoleInit(NULL); - - AudioOutBuffer audout_buf; - AudioOutBuffer *audout_released_buf; - - // Make sure the sample buffer size is aligned to 0x1000 bytes. - u32 data_size = (SAMPLECOUNT * CHANNELCOUNT * BYTESPERSAMPLE); - u32 buffer_size = (data_size + 0xfff) & ~0xfff; - - // Allocate the buffer. - u8* out_buf_data = memalign(0x1000, buffer_size); - - // Ensure buffers were properly allocated. - if (out_buf_data == NULL) - { - rc = MAKERESULT(Module_Libnx, LibnxError_OutOfMemory); - printf("Failed to allocate sample data buffers\n"); - } - - if (R_SUCCEEDED(rc)) - memset(out_buf_data, 0, buffer_size); - - if (R_SUCCEEDED(rc)) - { - // Initialize the default audio output device. - rc = audoutInitialize(); - printf("audoutInitialize() returned 0x%x\n", rc); - } - - if (R_SUCCEEDED(rc)) - { - printf("Sample rate: 0x%x\n", audoutGetSampleRate()); - printf("Channel count: 0x%x\n", audoutGetChannelCount()); - printf("PCM format: 0x%x\n", audoutGetPcmFormat()); - printf("Device state: 0x%x\n", audoutGetDeviceState()); - - // Start audio playback. - rc = audoutStartAudioOut(); - printf("audoutStartAudioOut() returned 0x%x\n", rc); - } - - 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"); - - while (appletMainLoop()) - { - //Scan all the inputs. This should be done once for each frame - hidScanInput(); + // Initialize console. Using NULL as the second argument tells the console library to use the internal console structure as current one. + consoleInit(NULL); + + AudioOutBuffer audout_buf; + AudioOutBuffer *audout_released_buf; + + // Make sure the sample buffer size is aligned to 0x1000 bytes. + u32 data_size = (SAMPLECOUNT * CHANNELCOUNT * BYTESPERSAMPLE); + u32 buffer_size = (data_size + 0xfff) & ~0xfff; + + // Allocate the buffer. + u8* out_buf_data = memalign(0x1000, buffer_size); + + // Ensure buffers were properly allocated. + if (out_buf_data == NULL) + { + rc = MAKERESULT(Module_Libnx, LibnxError_OutOfMemory); + printf("Failed to allocate sample data buffers\n"); + } + + if (R_SUCCEEDED(rc)) + memset(out_buf_data, 0, buffer_size); + + if (R_SUCCEEDED(rc)) + { + // Initialize the default audio output device. + rc = audoutInitialize(); + printf("audoutInitialize() returned 0x%x\n", rc); + } + + if (R_SUCCEEDED(rc)) + { + printf("Sample rate: 0x%x\n", audoutGetSampleRate()); + printf("Channel count: 0x%x\n", audoutGetChannelCount()); + printf("PCM format: 0x%x\n", audoutGetPcmFormat()); + printf("Device state: 0x%x\n", audoutGetDeviceState()); + + // Start audio playback. + rc = audoutStartAudioOut(); + printf("audoutStartAudioOut() returned 0x%x\n", rc); + } + + 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"); + + while (appletMainLoop()) + { + //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(CONTROLLER_P1_AUTO); + //hidKeysDown returns information about which buttons have been just pressed (and they weren't in the previous frame) + u32 kDown = hidKeysDown(CONTROLLER_P1_AUTO); - if (kDown & KEY_PLUS) break; // break in order to return to hbmenu - - if (kDown & KEY_A) - { - fill_audio_buffer(out_buf_data, 0, data_size, notefreq[0]); - play_tone = true; - } - - if (kDown & KEY_B) - { - fill_audio_buffer(out_buf_data, 0, data_size, notefreq[1]); - play_tone = true; - } - - if (kDown & KEY_Y) - { - fill_audio_buffer(out_buf_data, 0, data_size, notefreq[2]); - play_tone = true; - } - - if (kDown & KEY_X) - { - fill_audio_buffer(out_buf_data, 0, data_size, notefreq[3]); - play_tone = true; - } - - if (kDown & KEY_DLEFT) - { - fill_audio_buffer(out_buf_data, 0, data_size, notefreq[4]); - play_tone = true; - } - - if (kDown & KEY_DUP) - { - fill_audio_buffer(out_buf_data, 0, data_size, notefreq[5]); - play_tone = true; - } - - if (kDown & KEY_DRIGHT) - { - fill_audio_buffer(out_buf_data, 0, data_size, notefreq[6]); - play_tone = true; - } - - if (kDown & KEY_DDOWN) - { - fill_audio_buffer(out_buf_data, 0, data_size, notefreq[7]); - play_tone = true; - } - - if (kDown & KEY_L) - { - fill_audio_buffer(out_buf_data, 0, data_size, notefreq[8]); - play_tone = true; - } - - if (kDown & KEY_R) - { - fill_audio_buffer(out_buf_data, 0, data_size, notefreq[9]); - play_tone = true; - } - - if (kDown & KEY_ZL) - { - fill_audio_buffer(out_buf_data, 0, data_size, notefreq[10]); - play_tone = true; - } - - if (kDown & KEY_ZR) - { - fill_audio_buffer(out_buf_data, 0, data_size, notefreq[11]); - play_tone = true; - } - - if (R_SUCCEEDED(rc) && play_tone) - { - // Prepare the audio data source buffer. - audout_buf.next = NULL; - audout_buf.buffer = out_buf_data; - audout_buf.buffer_size = buffer_size; - audout_buf.data_size = data_size; - audout_buf.data_offset = 0; - - // Prepare pointer for the released buffer. - audout_released_buf = NULL; - - // Play the buffer. - rc = audoutPlayBuffer(&audout_buf, &audout_released_buf); - - if (R_FAILED(rc)) - printf("audoutPlayBuffer() returned 0x%x\n", rc); - - play_tone = false; - } - - gfxFlushBuffers(); - gfxSwapBuffers(); - gfxWaitForVsync(); - } - - // Stop audio playback. - rc = audoutStopAudioOut(); - printf("audoutStopAudioOut() returned 0x%x\n", rc); + if (kDown & KEY_PLUS) break; // break in order to return to hbmenu + + if (kDown & KEY_A) + { + fill_audio_buffer(out_buf_data, 0, data_size, notefreq[0]); + play_tone = true; + } + + if (kDown & KEY_B) + { + fill_audio_buffer(out_buf_data, 0, data_size, notefreq[1]); + play_tone = true; + } + + if (kDown & KEY_Y) + { + fill_audio_buffer(out_buf_data, 0, data_size, notefreq[2]); + play_tone = true; + } + + if (kDown & KEY_X) + { + fill_audio_buffer(out_buf_data, 0, data_size, notefreq[3]); + play_tone = true; + } + + if (kDown & KEY_DLEFT) + { + fill_audio_buffer(out_buf_data, 0, data_size, notefreq[4]); + play_tone = true; + } + + if (kDown & KEY_DUP) + { + fill_audio_buffer(out_buf_data, 0, data_size, notefreq[5]); + play_tone = true; + } + + if (kDown & KEY_DRIGHT) + { + fill_audio_buffer(out_buf_data, 0, data_size, notefreq[6]); + play_tone = true; + } + + if (kDown & KEY_DDOWN) + { + fill_audio_buffer(out_buf_data, 0, data_size, notefreq[7]); + play_tone = true; + } + + if (kDown & KEY_L) + { + fill_audio_buffer(out_buf_data, 0, data_size, notefreq[8]); + play_tone = true; + } + + if (kDown & KEY_R) + { + fill_audio_buffer(out_buf_data, 0, data_size, notefreq[9]); + play_tone = true; + } + + if (kDown & KEY_ZL) + { + fill_audio_buffer(out_buf_data, 0, data_size, notefreq[10]); + play_tone = true; + } + + if (kDown & KEY_ZR) + { + fill_audio_buffer(out_buf_data, 0, data_size, notefreq[11]); + play_tone = true; + } + + if (R_SUCCEEDED(rc) && play_tone) + { + // Prepare the audio data source buffer. + audout_buf.next = NULL; + audout_buf.buffer = out_buf_data; + audout_buf.buffer_size = buffer_size; + audout_buf.data_size = data_size; + audout_buf.data_offset = 0; + + // Prepare pointer for the released buffer. + audout_released_buf = NULL; + + // Play the buffer. + rc = audoutPlayBuffer(&audout_buf, &audout_released_buf); + + if (R_FAILED(rc)) + printf("audoutPlayBuffer() returned 0x%x\n", rc); + + play_tone = false; + } + + gfxFlushBuffers(); + gfxSwapBuffers(); + gfxWaitForVsync(); + } + + // Stop audio playback. + rc = audoutStopAudioOut(); + printf("audoutStopAudioOut() returned 0x%x\n", rc); - // Terminate the default audio output device. - audoutExit(); - - gfxExit(); - return 0; + // Terminate the default audio output device. + audoutExit(); + + gfxExit(); + return 0; } diff --git a/fs/romfs/source/main.c b/fs/romfs/source/main.c index 9b9a18d..3510a1f 100644 --- a/fs/romfs/source/main.c +++ b/fs/romfs/source/main.c @@ -5,60 +5,60 @@ void printfile(const char* path) { - FILE* f = fopen(path, "r"); - if (f) - { - char mystring[100]; - while (fgets(mystring, sizeof(mystring), f)) - { - int a = strlen(mystring); - if (mystring[a-1] == '\n') - { - mystring[a-1] = 0; - if (mystring[a-2] == '\r') - mystring[a-2] = 0; - } - puts(mystring); - } - printf(">>EOF<<\n"); - fclose(f); - } + FILE* f = fopen(path, "r"); + if (f) + { + char mystring[100]; + while (fgets(mystring, sizeof(mystring), f)) + { + int a = strlen(mystring); + if (mystring[a-1] == '\n') + { + mystring[a-1] = 0; + if (mystring[a-2] == '\r') + mystring[a-2] = 0; + } + puts(mystring); + } + printf(">>EOF<<\n"); + fclose(f); + } } int main(int argc, char **argv) { - gfxInitDefault(); - consoleInit(NULL); + gfxInitDefault(); + consoleInit(NULL); - Result rc = romfsInit(); - if (rc) - printf("romfsInit: %08X\n", rc); - else - { - printf("romfs Init Successful!\n"); - printfile("romfs:/folder/file.txt"); - // Test reading a file with non-ASCII characters in the name - printfile("romfs:/フォルダ/ファイル.txt"); - } + Result rc = romfsInit(); + if (rc) + printf("romfsInit: %08X\n", rc); + else + { + printf("romfs Init Successful!\n"); + printfile("romfs:/folder/file.txt"); + // Test reading a file with non-ASCII characters in the name + printfile("romfs:/フォルダ/ファイル.txt"); + } - // Main loop - while(appletMainLoop()) - { - //Scan all the inputs. This should be done once for each frame - hidScanInput(); + // Main loop + while(appletMainLoop()) + { + //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(CONTROLLER_P1_AUTO); + //hidKeysDown returns information about which buttons have been just pressed (and they weren't in the previous frame) + u32 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 - gfxFlushBuffers(); - gfxSwapBuffers(); - gfxWaitForVsync(); - } + gfxFlushBuffers(); + gfxSwapBuffers(); + gfxWaitForVsync(); + } - romfsExit(); - gfxExit(); - return 0; + romfsExit(); + gfxExit(); + return 0; } diff --git a/fs/sdmc/source/main.c b/fs/sdmc/source/main.c index 9a31128..bea5a91 100644 --- a/fs/sdmc/source/main.c +++ b/fs/sdmc/source/main.c @@ -9,45 +9,45 @@ int main(int argc, char **argv) { - gfxInitDefault(); - consoleInit(NULL); + gfxInitDefault(); + consoleInit(NULL); - DIR* dir; - struct dirent* ent; + DIR* dir; + struct dirent* ent; - dir = opendir("");//Open current-working-directory. - if(dir==NULL) - { - printf("Failed to open dir.\n"); - } - else - { - printf("Dir-listing for '':\n"); - while ((ent = readdir(dir))) - { - printf("d_name: %s\n", ent->d_name); - } - closedir(dir); - printf("Done.\n"); - } + dir = opendir("");//Open current-working-directory. + if(dir==NULL) + { + printf("Failed to open dir.\n"); + } + else + { + printf("Dir-listing for '':\n"); + while ((ent = readdir(dir))) + { + printf("d_name: %s\n", ent->d_name); + } + closedir(dir); + printf("Done.\n"); + } - // Main loop - while(appletMainLoop()) - { - //Scan all the inputs. This should be done once for each frame - hidScanInput(); + // Main loop + while(appletMainLoop()) + { + //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(CONTROLLER_P1_AUTO); + //hidKeysDown returns information about which buttons have been just pressed (and they weren't in the previous frame) + u32 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 - gfxFlushBuffers(); - gfxSwapBuffers(); - gfxWaitForVsync(); - } + gfxFlushBuffers(); + gfxSwapBuffers(); + gfxWaitForVsync(); + } - gfxExit(); - return 0; + gfxExit(); + return 0; } diff --git a/graphics/printing/hello-world/source/main.c b/graphics/printing/hello-world/source/main.c index bcb1229..798ffdc 100644 --- a/graphics/printing/hello-world/source/main.c +++ b/graphics/printing/hello-world/source/main.c @@ -5,32 +5,32 @@ int main(int argc, char **argv) { - gfxInitDefault(); + gfxInitDefault(); - //Initialize console. Using NULL as the second argument tells the console library to use the internal console structure as current one. - consoleInit(NULL); + //Initialize console. Using NULL as the second argument tells the console library to use the internal console structure as current one. + consoleInit(NULL); - //Move the cursor to row 16 and column 20 and then prints "Hello World!" - //To move the cursor you have to print "\x1b[r;cH", where r and c are respectively - //the row and column where you want your cursor to move - printf("\x1b[16;20HHello World!"); + //Move the cursor to row 16 and column 20 and then prints "Hello World!" + //To move the cursor you have to print "\x1b[r;cH", where r and c are respectively + //the row and column where you want your cursor to move + printf("\x1b[16;20HHello World!"); - while(appletMainLoop()) - { - //Scan all the inputs. This should be done once for each frame - hidScanInput(); + while(appletMainLoop()) + { + //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(CONTROLLER_P1_AUTO); + //hidKeysDown returns information about which buttons have been just pressed (and they weren't in the previous frame) + u32 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 - gfxFlushBuffers(); - gfxSwapBuffers(); - gfxWaitForVsync(); - } + gfxFlushBuffers(); + gfxSwapBuffers(); + gfxWaitForVsync(); + } - gfxExit(); - return 0; + gfxExit(); + return 0; } diff --git a/graphics/printing/vt52-demo/source/main.c b/graphics/printing/vt52-demo/source/main.c index 02bd8d3..39852e6 100644 --- a/graphics/printing/vt52-demo/source/main.c +++ b/graphics/printing/vt52-demo/source/main.c @@ -5,80 +5,80 @@ int main(int argc, char **argv) { - gfxInitDefault(); - consoleInit(NULL); + gfxInitDefault(); + consoleInit(NULL); - // clear screen and home cursor - printf( CONSOLE_ESC(2J) ); + // clear screen and home cursor + printf( CONSOLE_ESC(2J) ); - // Set print co-ordinates - // /x1b[row;columnH - printf(CONSOLE_ESC(10;10H) "VT52 codes demo"); + // Set print co-ordinates + // /x1b[row;columnH + printf(CONSOLE_ESC(10;10H) "VT52 codes demo"); - // move cursor up - // /x1b[linesA - printf(CONSOLE_ESC(10A)"Line 0"); + // move cursor up + // /x1b[linesA + printf(CONSOLE_ESC(10A)"Line 0"); - // move cursor left - // /x1b[columnsD - printf(CONSOLE_ESC(28D)"Column 0"); + // move cursor left + // /x1b[columnsD + printf(CONSOLE_ESC(28D)"Column 0"); - // move cursor down - // /x1b[linesB - printf(CONSOLE_ESC(19B)"Line 19"); + // move cursor down + // /x1b[linesB + printf(CONSOLE_ESC(19B)"Line 19"); - // move cursor right - // /x1b[columnsC - printf(CONSOLE_ESC(5C)"Column 20"); + // move cursor right + // /x1b[columnsC + printf(CONSOLE_ESC(5C)"Column 20"); - printf("\n"); + printf("\n"); - // Color codes and attributes - for(int i=0; i<8; i++) - { - printf( CONSOLE_ESC(%1$d;1m) /* Set color */ - "Default " - CONSOLE_ESC(1m) "Bold " - CONSOLE_ESC(7m) "Reversed " + // Color codes and attributes + for(int i=0; i<8; i++) + { + printf( CONSOLE_ESC(%1$d;1m) /* Set color */ + "Default " + CONSOLE_ESC(1m) "Bold " + CONSOLE_ESC(7m) "Reversed " - CONSOLE_ESC(0m) /* revert attributes*/ - CONSOLE_ESC(%1$d;1m) + CONSOLE_ESC(0m) /* revert attributes*/ + CONSOLE_ESC(%1$d;1m) - CONSOLE_ESC(2m) "Light " - CONSOLE_ESC(7m) "Reversed " + CONSOLE_ESC(2m) "Light " + CONSOLE_ESC(7m) "Reversed " - CONSOLE_ESC(0m) /* revert attributes*/ - CONSOLE_ESC(%1$d;1m) - CONSOLE_ESC(4m) "Underline " + CONSOLE_ESC(0m) /* revert attributes*/ + CONSOLE_ESC(%1$d;1m) + CONSOLE_ESC(4m) "Underline " - CONSOLE_ESC(0m) /* revert attributes*/ - CONSOLE_ESC(%1$d;1m) - CONSOLE_ESC(9m) "Strikethrough " - "\n" - CONSOLE_ESC(0m) /* revert attributes*/ - , i + 30); - } + CONSOLE_ESC(0m) /* revert attributes*/ + CONSOLE_ESC(%1$d;1m) + CONSOLE_ESC(9m) "Strikethrough " + "\n" + CONSOLE_ESC(0m) /* revert attributes*/ + , i + 30); + } - // Main loop - while(appletMainLoop()) - { - //Scan all the inputs. This should be done once for each frame - hidScanInput(); + // Main loop + while(appletMainLoop()) + { + //Scan all the inputs. This should be done once for each frame + hidScanInput(); - // 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) - u32 kDown = hidKeysDown(CONTROLLER_P1_AUTO); + //hidKeysDown returns information about which buttons have been just pressed (and they weren't in the previous frame) + u32 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 - gfxFlushBuffers(); - gfxSwapBuffers(); - gfxWaitForVsync(); - } + gfxFlushBuffers(); + gfxSwapBuffers(); + gfxWaitForVsync(); + } - gfxExit(); - return 0; + gfxExit(); + return 0; } diff --git a/graphics/simplegfx/source/main.c b/graphics/simplegfx/source/main.c index 37f5155..a4dd81e 100644 --- a/graphics/simplegfx/source/main.c +++ b/graphics/simplegfx/source/main.c @@ -10,63 +10,63 @@ int main(int argc, char **argv) { - u32* framebuf; - u32 cnt=0; - #ifdef DISPLAY_IMAGE - u8* imageptr = (u8*)image_bin; - #endif + u32* framebuf; + u32 cnt=0; + #ifdef DISPLAY_IMAGE + u8* imageptr = (u8*)image_bin; + #endif - //Enable max-1080p support. Remove for 720p-only resolution. - //gfxInitResolutionDefault(); + //Enable max-1080p support. Remove for 720p-only resolution. + //gfxInitResolutionDefault(); - gfxInitDefault(); + gfxInitDefault(); - //Set current resolution automatically depending on current/changed OperationMode. Only use this when using gfxInitResolution*(). - //gfxConfigureAutoResolutionDefault(true); + //Set current resolution automatically depending on current/changed OperationMode. Only use this when using gfxInitResolution*(). + //gfxConfigureAutoResolutionDefault(true); - while(appletMainLoop()) - { - //Scan all the inputs. This should be done once for each frame - hidScanInput(); + while(appletMainLoop()) + { + //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(CONTROLLER_P1_AUTO); + //hidKeysDown returns information about which buttons have been just pressed (and they weren't in the previous frame) + u32 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 - u32 width, height; - u32 pos; - framebuf = (u32*) gfxGetFramebuffer((u32*)&width, (u32*)&height); + u32 width, height; + u32 pos; + framebuf = (u32*) gfxGetFramebuffer((u32*)&width, (u32*)&height); - if(cnt==60) - { - cnt=0; - } - else - { - cnt++; - } + if(cnt==60) + { + cnt=0; + } + else + { + cnt++; + } - //Each pixel is 4-bytes due to RGBA8888. - u32 x, y; - for (y=0; ytm_hour; - int minutes = timeStruct->tm_min; - int seconds = timeStruct->tm_sec; - int day = timeStruct->tm_mday; - int month = timeStruct->tm_mon; - int year = timeStruct->tm_year +1900; - int wday = timeStruct->tm_wday; + int hours = timeStruct->tm_hour; + int minutes = timeStruct->tm_min; + int seconds = timeStruct->tm_sec; + int day = timeStruct->tm_mday; + int month = timeStruct->tm_mon; + int year = timeStruct->tm_year +1900; + int wday = timeStruct->tm_wday; - printf("\x1b[1;1H%02i:%02i:%02i", hours, minutes, seconds); - printf("\n%s %s %i %i", weekDays[wday], months[month], day, year); + printf("\x1b[1;1H%02i:%02i:%02i", hours, minutes, seconds); + printf("\n%s %s %i %i", weekDays[wday], months[month], day, year); - gfxFlushBuffers(); - gfxSwapBuffers(); - gfxWaitForVsync(); - } + gfxFlushBuffers(); + gfxSwapBuffers(); + gfxWaitForVsync(); + } - gfxExit(); - return 0; + gfxExit(); + return 0; } diff --git a/usb/usbds/source/main.c b/usb/usbds/source/main.c index 8773728..726463e 100644 --- a/usb/usbds/source/main.c +++ b/usb/usbds/source/main.c @@ -10,136 +10,136 @@ Result usbds_test(u8 *tmpbuf) { - Result ret=0; - s32 tmpindex=0; - UsbDsInterface* interface = NULL; - UsbDsEndpoint *endpoint_in = NULL, *endpoint_out = NULL; + Result ret=0; + s32 tmpindex=0; + UsbDsInterface* interface = NULL; + UsbDsEndpoint *endpoint_in = NULL, *endpoint_out = NULL; - struct usb_interface_descriptor interface_descriptor = { - .bLength = USB_DT_INTERFACE_SIZE, - .bDescriptorType = USB_DT_INTERFACE, - .bInterfaceNumber = USBDS_DEFAULT_InterfaceNumber, + struct usb_interface_descriptor interface_descriptor = { + .bLength = USB_DT_INTERFACE_SIZE, + .bDescriptorType = USB_DT_INTERFACE, + .bInterfaceNumber = USBDS_DEFAULT_InterfaceNumber, .bInterfaceClass = USB_CLASS_VENDOR_SPEC, .bInterfaceSubClass = USB_CLASS_VENDOR_SPEC, .bInterfaceProtocol = USB_CLASS_VENDOR_SPEC, - }; + }; - struct usb_endpoint_descriptor endpoint_descriptor_in = { - .bLength = USB_DT_ENDPOINT_SIZE, - .bDescriptorType = USB_DT_ENDPOINT, - .bEndpointAddress = USB_ENDPOINT_IN, + struct usb_endpoint_descriptor endpoint_descriptor_in = { + .bLength = USB_DT_ENDPOINT_SIZE, + .bDescriptorType = USB_DT_ENDPOINT, + .bEndpointAddress = USB_ENDPOINT_IN, .bmAttributes = USB_TRANSFER_TYPE_BULK, .wMaxPacketSize = 0x200, - }; + }; - struct usb_endpoint_descriptor endpoint_descriptor_out = { - .bLength = USB_DT_ENDPOINT_SIZE, - .bDescriptorType = USB_DT_ENDPOINT, - .bEndpointAddress = USB_ENDPOINT_OUT, + struct usb_endpoint_descriptor endpoint_descriptor_out = { + .bLength = USB_DT_ENDPOINT_SIZE, + .bDescriptorType = USB_DT_ENDPOINT, + .bEndpointAddress = USB_ENDPOINT_OUT, .bmAttributes = USB_TRANSFER_TYPE_BULK, .wMaxPacketSize = 0x200, - }; + }; - //Setup interface. + //Setup interface. ret = usbDsGetDsInterface(&interface, &interface_descriptor, "usb"); - if(R_FAILED(ret))return ret; + if(R_FAILED(ret))return ret; - //Setup endpoints. - ret = usbDsInterface_GetDsEndpoint(interface, &endpoint_in, &endpoint_descriptor_in);//device->host - if(R_FAILED(ret))return ret; + //Setup endpoints. + ret = usbDsInterface_GetDsEndpoint(interface, &endpoint_in, &endpoint_descriptor_in);//device->host + if(R_FAILED(ret))return ret; - ret = usbDsInterface_GetDsEndpoint(interface, &endpoint_out, &endpoint_descriptor_out);//host->device - if(R_FAILED(ret))return ret; + ret = usbDsInterface_GetDsEndpoint(interface, &endpoint_out, &endpoint_descriptor_out);//host->device + if(R_FAILED(ret))return ret; - ret = usbDsInterface_EnableInterface(interface); - if(R_FAILED(ret))return ret; + ret = usbDsInterface_EnableInterface(interface); + if(R_FAILED(ret))return ret; - //Wait for initialization to finish where data-transfer is usable. This includes waiting for the usb cable to be inserted if it's not already. - ret = usbDsWaitReady(); - if(R_FAILED(ret))return ret; + //Wait for initialization to finish where data-transfer is usable. This includes waiting for the usb cable to be inserted if it's not already. + ret = usbDsWaitReady(); + if(R_FAILED(ret))return ret; - u32 somepos; - for(somepos=0; somepos<0x101; somepos++) - { - memset(tmpbuf, 0, 0x1000); - char *strptr = "\n";//"Hello World!\n"; + u32 somepos; + for(somepos=0; somepos<0x101; somepos++) + { + memset(tmpbuf, 0, 0x1000); + char *strptr = "\n";//"Hello World!\n"; - tmpbuf[0] = 0x11; - tmpbuf[1] = 0x1; - if(somepos==0 || somepos==0x101) - { - strncpy((char*)&tmpbuf[2], strptr, 0x1000-2); - ret = usbDsEndpoint_PostBufferAsync(endpoint_in, tmpbuf, 2+strlen(strptr), NULL); - } - else - { - tmpbuf[2] = somepos-1; - ret = usbDsEndpoint_PostBufferAsync(endpoint_in, tmpbuf, 2+1, NULL); - } + tmpbuf[0] = 0x11; + tmpbuf[1] = 0x1; + if(somepos==0 || somepos==0x101) + { + strncpy((char*)&tmpbuf[2], strptr, 0x1000-2); + ret = usbDsEndpoint_PostBufferAsync(endpoint_in, tmpbuf, 2+strlen(strptr), NULL); + } + else + { + tmpbuf[2] = somepos-1; + ret = usbDsEndpoint_PostBufferAsync(endpoint_in, tmpbuf, 2+1, NULL); + } - //Start a device->host transfer. - //ret = usbDsEndpoint_PostBufferAsync(endpoint_in, tmpbuf, 2+1, NULL); - //ret = usbDsEndpoint_PostBufferAsync(endpoint_in, tmpbuf, 2+strlen(strptr), NULL); - if(R_FAILED(ret))return ret; - //Wait for the transfer to finish. - svcWaitSynchronization(&tmpindex, &endpoint_in->CompletionEvent, 1, U64_MAX); - svcClearEvent(endpoint_in->CompletionEvent); - } + //Start a device->host transfer. + //ret = usbDsEndpoint_PostBufferAsync(endpoint_in, tmpbuf, 2+1, NULL); + //ret = usbDsEndpoint_PostBufferAsync(endpoint_in, tmpbuf, 2+strlen(strptr), NULL); + if(R_FAILED(ret))return ret; + //Wait for the transfer to finish. + svcWaitSynchronization(&tmpindex, &endpoint_in->CompletionEvent, 1, U64_MAX); + svcClearEvent(endpoint_in->CompletionEvent); + } - //Start a host->device transfer. - ret = usbDsEndpoint_PostBufferAsync(endpoint_out, tmpbuf, 0x200, NULL); - if(R_FAILED(ret))return ret; + //Start a host->device transfer. + ret = usbDsEndpoint_PostBufferAsync(endpoint_out, tmpbuf, 0x200, NULL); + if(R_FAILED(ret))return ret; - //Wait for the transfer to finish. - svcWaitSynchronization(&tmpindex, &endpoint_out->CompletionEvent, 1, U64_MAX); - svcClearEvent(endpoint_out->CompletionEvent); + //Wait for the transfer to finish. + svcWaitSynchronization(&tmpindex, &endpoint_out->CompletionEvent, 1, U64_MAX); + svcClearEvent(endpoint_out->CompletionEvent); - memcpy(&tmpbuf[0x400], tmpbuf, 0x200-2); - tmpbuf[0] = 0x11; - tmpbuf[1] = 0x1; - memcpy(&tmpbuf[2], &tmpbuf[0x400], 0x200-2); + memcpy(&tmpbuf[0x400], tmpbuf, 0x200-2); + tmpbuf[0] = 0x11; + tmpbuf[1] = 0x1; + memcpy(&tmpbuf[2], &tmpbuf[0x400], 0x200-2); - //Start a device->host transfer. - ret = usbDsEndpoint_PostBufferAsync(endpoint_in, tmpbuf, 0x2+1, NULL); - if(R_FAILED(ret))return ret; + //Start a device->host transfer. + ret = usbDsEndpoint_PostBufferAsync(endpoint_in, tmpbuf, 0x2+1, NULL); + if(R_FAILED(ret))return ret; - //Wait for the transfer to finish. - svcWaitSynchronization(&tmpindex, &endpoint_in->CompletionEvent, 1, U64_MAX); - svcClearEvent(endpoint_in->CompletionEvent); + //Wait for the transfer to finish. + svcWaitSynchronization(&tmpindex, &endpoint_in->CompletionEvent, 1, U64_MAX); + svcClearEvent(endpoint_in->CompletionEvent); - svcSleepThread(5000000000);//Delay 5s + svcSleepThread(5000000000);//Delay 5s - return 0; + return 0; } int main(int argc, char **argv) { - Result ret; + Result ret; - usbDsDeviceInfo deviceinfo = { - .idVendor = 0x0403, // "Future Technology Devices International, Ltd" - .idProduct = 0x6001, // "FT232 USB-Serial (UART) IC" - .bcdDevice = 0x0200, - .Manufacturer = "libnx", - .Product = "usbds-example", - .SerialNumber = "1337", - }; + usbDsDeviceInfo deviceinfo = { + .idVendor = 0x0403, // "Future Technology Devices International, Ltd" + .idProduct = 0x6001, // "FT232 USB-Serial (UART) IC" + .bcdDevice = 0x0200, + .Manufacturer = "libnx", + .Product = "usbds-example", + .SerialNumber = "1337", + }; - ret = usbDsInitialize(UsbComplexId_Default, &deviceinfo); + ret = usbDsInitialize(UsbComplexId_Default, &deviceinfo); - if (R_SUCCEEDED(ret)) { - u8 *tmpbuf = memalign(0x1000, 0x1000);//The buffer for PostBufferAsync commands must be 0x1000-byte aligned. - if(tmpbuf==NULL)ret = -4; + if (R_SUCCEEDED(ret)) { + u8 *tmpbuf = memalign(0x1000, 0x1000);//The buffer for PostBufferAsync commands must be 0x1000-byte aligned. + if(tmpbuf==NULL)ret = -4; - if (R_SUCCEEDED(ret)) ret = usbds_test(tmpbuf); + if (R_SUCCEEDED(ret)) ret = usbds_test(tmpbuf); - usbDsExit(); - } + usbDsExit(); + } if(R_FAILED(ret))fatalSimple(ret); - svcSleepThread(5000000000);//Delay 5s + svcSleepThread(5000000000);//Delay 5s - return 0; + return 0; }