Exemplo n.º 1
0
int main(int argc, char **argv)
{
	// Initialize services
	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);

	//Move the cursor to row 15 and column 19 and then prints "Hello World!" 
	//To move the cursor you have tu print "\x1b[r;cH", where r and c are respectively
	//the row and column where you want your cursor to move
	//The top screen has 30 rows and 50 columns
	//The bottom screen has 30 rows and 40 columns
	printf("\x1b[15;19HHello World!");

	//Move the cursor to the top left corner of the screen
	printf("\x1b[0;0H");

	//Print a REALLY crappy poeam with colored text
	//\x1b[cm set a SGR (Select Graphic Rendition) parameter, where c is the parameter that you want to set
	//Please refer to http://en.wikipedia.org/wiki/ANSI_escape_code#CSI_codes to see all the possible SGR parameters
	//As of now ctrulib support only these parameters:
	//Reset (0), Half bright colors (2), Reverse (7), Text color (30-37) and Background color (40-47)
	printf("Roses are \x1b[31mred\x1b[0m\n");
	printf("Violets are \x1b[34mblue\x1b[0m\n");
	printf("Piracy is bad\n");
	printf("While homebrews are good\n\n");

	//Black text on white background
	//In this example we set two parameter in a single escape sequence by separating them by a semicolon
	//\x1b[47;30m means that it will set a white background (47) and it will print white characters (30)
	//In this we also could have used the 
	printf("\x1b[47;30mBlack text on white background\x1b[0m");


	printf("\x1b[29;15HPress Start to exit.");
	// 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();
	}

	// Exit services
	gfxExit();
	
	return 0;
}
Exemplo n.º 2
0
void err_show(char file_name[], int line, char message[]) {
  quit_for_err = true;
  // Reset all screens
  consoleInit(GFX_TOP, &top_screen);
  consoleInit(GFX_BOTTOM, &debug_screen);
  consoleInit(GFX_BOTTOM, &instruction_screen);
  consoleSelect(&top_screen);
  printf("%s\n\t\tFATAL ERROR\n\n%s", BG_RED, RESET);
  printf("%s\n", file_name);
  printf("line %d\n", line);
  printf(message);
  printf("\n\nPlease raise an issue at:\ngithub.com/thatguywiththatname/3DES/issues\n");
  printf("With details of this error &\nwhat you were doing at the time\n");
  printf("\nPress A to close app\n");
  while (aptMainLoop()) {
    gspWaitForVBlank();
    hidScanInput();
    u32 exitkDown = hidKeysDown();
    if (exitkDown & KEY_A) {
      return;
    }
    gfxFlushBuffers();
    gfxSwapBuffers();
  }
}
Exemplo n.º 3
0
void ui_info_add(const char* info) {
    consoleSelect(&bottom_screen);
    printf(info);
    gfxFlushBuffers();
    gfxSwapBuffers();
    gspWaitForVBlank();
}
Exemplo n.º 4
0
STATIC bool fatal_error(bool restart) {
    bool should_restart = false;
    if (restart) {
        printf("\x1b[28;12HPress Select to restart.");
    }
    printf("\x1b[29;12H  Press Start to exit.  ");

    while (aptMainLoop()) {
        hidScanInput();

        int down = hidKeysDown();
        if (down & KEY_START) {
            break;
        } else if (restart && (down & KEY_SELECT)) {
            should_restart = true;
            break;
        }

        gfxFlushBuffers();
        gfxSwapBuffers();

        gspWaitForVBlank();
    }

    gfxExit();

    return should_restart;
}
Exemplo n.º 5
0
int main()
{
	gfxInitDefault();
	consoleInit(GFX_TOP, NULL);

	Result rc = romfsInit();
	if (rc)
		printf("romfsInit: %08lX\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 (aptMainLoop())
	{
		gspWaitForVBlank();
		hidScanInput();

		u32 kDown = hidKeysDown();
		if (kDown & KEY_START)
			break; // break in order to return to hbmenu
	}

	romfsExit();
	gfxExit();
	return 0;
}
Exemplo n.º 6
0
/*! draw console to screen */
void
console_render(void)
{
  font_t *font;

  /* clear all screens */
  u8 black_color[] = { 0, 0, 0 };
  clear_screen(GFX_TOP,    GFX_LEFT,  black_color);
  clear_screen(GFX_BOTTOM,    GFX_LEFT,  black_color);

  /* look up font for status bar and draw status bar */
  font = find_font("sans", 10);
  if(font != NULL) {
    draw_text(GFX_BOTTOM, GFX_LEFT,  font, status, 20, 4);
    draw_text(GFX_BOTTOM, GFX_LEFT,  font, STATUS_STRING, 20, 220);
  }
  else
    debug("%s: couldn't find 'sans 10pt'\n", __func__);


  /* look up font for console and draw console */
  font = find_font("sans", 8);
  if(font != NULL)
    draw_text(GFX_TOP, GFX_LEFT,  font, buffer, 20, 5);
  else
    debug("%s: couldn't find 'sans 8pt'\n", __func__);

  /* flush framebuffer */
  gfxFlushBuffers();
  gspWaitForVBlank();
  gfxSwapBuffers();
}
Exemplo n.º 7
0
void system_checkPolls() {
    APP_STATUS status;

	while((status=aptGetStatus()) != APP_RUNNING) {

        if(status == APP_SUSPENDING)
        {
            aptReturnToMenu();
        }
        else if(status == APP_PREPARE_SLEEPMODE)
        {
			aptSignalReadyForSleep();
            aptWaitStatusEvent();
        }
        else if (status == APP_SLEEPMODE) {

        }
        else if (status == APP_EXITING) {
            system_cleanup();
            exit(0);
        }

        gspWaitForVBlank();
    }

    gfxFlushBuffers();
    gfxMySwapBuffers();
    consoleCheckFramebuffers();
}
Exemplo n.º 8
0
s32 menu_cb_choose_file (s32 idx, void *param) {
	s32 curidx = idx;
	s32 loaded = 0;

	while (aptMainLoop()) {
		gspWaitForVBlank();

		curidx = print_file_list(curidx, &g_file_list);	           
		u32 kDown = wait_key(); 

		if (kDown & KEY_B) {
			break;
		}
		else if (kDown & KEY_A) {
			consoleClear();
			loaded = menu_execute_function(curidx, &g_file_list, &curidx);
			printf("%s\n", loaded? "[+] Success":"[!] Failure");
			wait_any_key();
			if (loaded)
				break;
		}
		else if (kDown & KEY_UP) {
			curidx--;
		}
		else if (kDown & KEY_DOWN) {
			curidx++;
		}
		gfxFlushBuffers();
		gfxSwapBuffers();
	}
	return 0;
}
Exemplo n.º 9
0
int main()
{
	gfxInitDefault();
	//gfxSet3D(true); // uncomment if using stereoscopic 3D

	// Main loop
	while (aptMainLoop())
	{
		gspWaitForVBlank();
		hidScanInput();

		// Your code goes here

		u32 kDown = hidKeysDown();
		if (kDown & KEY_START)
			break; // break in order to return to hbmenu

		// Example rendering code that displays a white pixel
		// Please note that the 3DS screens are sideways (thus 240x400 and 240x320)
		u8* fb = gfxGetFramebuffer(GFX_TOP, GFX_LEFT, nullptr, nullptr);
		memset(fb, 127, 240*400*3);
		fb[3*(10+10*240)] = 0xFF;
		fb[3*(10+10*240)+1] = 0xFF;
		fb[3*(10+10*240)+2] = 0xFF;

		// Flush and swap framebuffers
		gfxFlushBuffers();
		gfxSwapBuffers();
	}

	gfxExit();
	return 0;
}
Exemplo n.º 10
0
int main(int argc, char **argv)

{
	
	//Initialize some sounds for high quality sounding moans and SCREAMS from the ACTION!
	srvInit();
	aptInit();
	hidInit();
	csndInit();
	gfxInitDefault();
	consoleInit(GFX_TOP, NULL);



	printf("\x1b[1;5HGuess who is the freshest squid around?");
	wait(10000);
	printf("           ");
	printf("\x1b[5;19H\x1b[32m\ Marie Squid\x1b[0m\n");
	printf("\x1b[16;3HPress Start to know that such fresh exists.");
	printf("\x1b[17;3HPress A to get INTO IT!");

	

	// Main loop
	while (aptMainLoop())
	{
		//Scan all the inputs. This should be done once for each frame mostly for the shoots
		hidScanInput();
		

		//hidKeysDown returns information about which buttons have been just pressed (and they weren't in the previous frame)
		hidScanInput();
		u32 kDown = hidKeysDown();
		if (kDown & KEY_START){   //PRESS START TO RETURN TO HBL
		}
		if (kDown & KEY_A){   // PRESS A TO PLAY
			audio_load("squit.bin");
		}
		
		
		// Flush and swap framebuffers
		gfxFlushBuffers();
		gfxSwapBuffers();

		//Wait for VBlank
		gspWaitForVBlank();
	}

	// Exit services... I know you want to come back...

	audio_stop();
	audio_stop();
	csndExit();
	gfxExit();
	hidExit();
	aptExit();
	srvExit();
	return 0;
}
Exemplo n.º 11
0
/***
Disable the console.
@function disableConsole
*/
static int gfx_disableConsole(lua_State *L) {
	gfxSetScreenFormat(consoleScreen, GSP_BGR8_OES);
	gfxSetDoubleBuffering(consoleScreen, true);
	gfxSwapBuffersGpu();
	gspWaitForVBlank();
	
	return 0;
}
Exemplo n.º 12
0
/// A very bad implementation for consoleExit, only for debug.
PrintConsole* consoleExit(gfxScreen_t screen, PrintConsole* console)
{
	// TODO Future implementation!
	*currentConsole = *consoleGetDefault();
	gfxSetScreenFormat(screen, GSP_BGR8_OES);
	gfxSetDoubleBuffering(screen, true);
	gspWaitForVBlank();
	return console;
}
Exemplo n.º 13
0
void waitForStart()
{
    while (aptMainLoop())
    {
        gspWaitForVBlank();
        hidScanInput();
        u32 kDown = hidKeysDown();
        if (kDown & KEY_START)break;
    }
}
Exemplo n.º 14
0
void displaymessage_waitbutton()
{
	printf("\nPress the A button to continue.\n");
	while(1)
	{
		gspWaitForVBlank();
		hidScanInput();
		if(hidKeysDown() & KEY_A)break;
	}
}
Exemplo n.º 15
0
void sleep(int milliseconds)
{
    // attempts to emulate sleep in ms by assuming 60 fps
    int i;
    for (i = 0; i < (int)(milliseconds/16.67); i++)
    {
        gspWaitForVBlank();
        gfxFlushBuffers();
        gfxSwapBuffers();
    }
}
Exemplo n.º 16
0
int main(int argc, char** argv)
{

    gfxInitDefault();
    InitOutput();

    consoleClear();

    Print("Press A to begin...\n");

    // unsigned int test_counter = 0; // Moving it here causes this app to refuse to boot at all.

    while (aptMainLoop()) {
        gfxFlushBuffers();
        gfxSwapBuffers();

        hidScanInput();
        u32 kDown = hidKeysDown();
        if (kDown & KEY_START) {
            break;
        } else if (kDown & KEY_A) {
            consoleClear();

            unsigned int test_counter = 0; // This configuration works, but obviously only test 0 would run.

            TestCaller tests[] = {
                FS::TestAll,
                CPU::Integer::TestAll,
                CPU::Memory::TestAll,
                Kernel::TestAll,
                GPU::TestAll
            };

            if (test_counter < (sizeof(tests) / sizeof(tests[0]))) {
                tests[test_counter]();
                test_counter++;
            } else {
                break;
            }

            Log("\n");
            Print("Press A to continue...\n");
        }

        gspWaitForVBlank();
    }

    consoleClear();

    gfxExit();
    DeinitOutput();

    return 0;
}
Exemplo n.º 17
0
void mvd_colorconvert()
{
	Result ret;

	FILE *f = NULL;

	u8* bufAdr = gfxGetFramebuffer(GFX_BOTTOM, GFX_LEFT, NULL, NULL);
	u8* gfxtopadr = gfxGetFramebuffer(GFX_TOP, GFX_LEFT, NULL, NULL);

	MVDSTD_Config config;

	printf("mvd color-format-conversion example.\n");

	f = fopen("sdmc:/mvd_indata.bin", "r");
	if(f)
	{
		fread(inaddr, 1, 0x46500, f);
		fclose(f);
	}
	else
	{
		memcpy(inaddr, bufAdr, 320*240*3);
	}

	memset(gfxtopadr, 0, 0x46500);
	GSPGPU_FlushDataCache(inaddr, 0x46500);
	GSPGPU_FlushDataCache(gfxtopadr, 0x46500);

	ret = mvdstdInit(MVDMODE_COLORFORMATCONV, MVD_INPUT_YUYV422, MVD_OUTPUT_BGR565, 0, NULL);
	printf("mvdstdInit(): 0x%08x\n", (unsigned int)ret);

	if(ret==0)
	{
		mvdstdGenerateDefaultConfig(&config, 320, 240, 320, 240, (u32*)inaddr, (u32*)outaddr, (u32*)&outaddr[0x12c00]);

		ret = mvdstdConvertImage(&config);
		printf("mvdstdConvertImage(): 0x%08x\n", (unsigned int)ret);
	}

	f = fopen("sdmc:/mvd_outdata.bin", "w");
	if(f)
	{
		fwrite(outaddr, 1, 0x100000, f);
		fclose(f);
	}

	memcpy(gfxtopadr, outaddr, 0x46500);

	mvdstdExit();

	gfxFlushBuffers();
	gfxSwapBuffersGpu();
	gspWaitForVBlank();
}
Exemplo n.º 18
0
static int netloader_draw_progress(void) {
    char info[1024];
    sprintf(info, "Transferring: %s\n\n%s",netloadedPath,progress);
    drawError(GFX_BOTTOM, "NetLoader", info, 0);
    gfxFlushBuffers();
    gfxSwapBuffers();

    gspWaitForVBlank();

    return 0;
}
Exemplo n.º 19
0
/*! draw console to screen */
void
console_render(void)
{
  /* print tcp table */
  print_tcp_table();

  /* flush framebuffer */
  gfxFlushBuffers();
  gspWaitForVBlank();
  gfxSwapBuffers();
}
Exemplo n.º 20
0
void wait_key(const u32 key)
{
    while (aptMainLoop()) {
	hidScanInput();
	if (hidKeysDown() & key) break;

	gfxFlushBuffers();
	gfxSwapBuffers();

	gspWaitForVBlank();
    }
}
Exemplo n.º 21
0
int main(int argc, char** argv) {


	gfxInitDefault();

	consoleInit(GFX_TOP, NULL);


	svcCreateEvent(&threadRequest,0);
	u32 *threadStack = memalign(32, STACKSIZE);
	Result ret = svcCreateThread(&threadHandle, threadMain, 0, &threadStack[STACKSIZE/4], 0x3f, 0);

	printf("thread create returned %x\n", ret);

	// Main loop
	while (aptMainLoop())
	{
		gspWaitForVBlank();
		hidScanInput();

		printf("\x1b[5;0H");
		printf("thread counter = %d\n",threadcount);

		u32 kDown = hidKeysDown();
		if (kDown & KEY_START)
			break; // break in order to return to hbmenu

		if (kDown & KEY_A)
			svcSignalEvent(threadRequest);

		// Flush and swap framebuffers
		gfxFlushBuffers();
		gfxSwapBuffers();
	}

	// tell thread to exit
	threadExit = true;

	// signal the thread
	svcSignalEvent(threadRequest);

	// give it time to exit
	svcSleepThread(10000000ULL);

	// close handles and free allocated stack
	svcCloseHandle(threadRequest);
	svcCloseHandle(threadHandle);
	free(threadStack);


	gfxExit();
	return 0;
}
Exemplo n.º 22
0
int confirm() {
	while (aptMainLoop()) {
		hidScanInput();
		gspWaitForVBlank();

		u32 kDown = hidKeysDown();
		if (!(kDown & (KEY_A | KEY_B)))
			break;
	}
	while (aptMainLoop()) {
		hidScanInput();
		gspWaitForVBlank();

		u32 kDown = hidKeysDown();
		if (kDown & KEY_A)
			return true;
		if (kDown & KEY_B)
			return false;
	}
	return false;
}
Exemplo n.º 23
0
void waitForKey() {
    while (aptMainLoop()) {
        gfxSwapBuffers();
        gfxFlushBuffers();
        gspWaitForVBlank();

        hidScanInput();
        u32 kDown = hidKeysDown();

        if (kDown)
            break;
    }
}
Exemplo n.º 24
0
std::string getInput(HB_Keyboard* sHBKB, bool &bCancelled)
{
    sHBKB->HBKB_Clean();
    touchPosition touch;
    u8 KBState = 4;
    std::string input;
    while (KBState != 1 || input.length() == 0)
    {
        if (!aptMainLoop())
        {
            bCancelled = true;
            break;
        }

        hidScanInput();
        hidTouchRead(&touch);
        KBState = sHBKB->HBKB_CallKeyboard(touch);
        input = sHBKB->HBKB_CheckKeyboardInput();

        // If the user cancelled the input
        if (KBState == 3)
        {
            bCancelled = true;
            break;
        }
        // Otherwise if the user has entered a key
        else if (KBState != 4)
        {
            printf("%c[2K\r", 27);

            // If input string is > 50 characters, show just the right hand side
            if (input.length() > 49)
            {
                printf("%s", input.substr(input.length() - 49).c_str());
            }
            else
            {
                printf("%s", input.c_str());
            }
        }

        // Flush and swap framebuffers
        gfxFlushBuffers();
        gfxSwapBuffers();

        //Wait for VBlank
        gspWaitForVBlank();
    }
    printf("\n");
    return input;
}
Exemplo n.º 25
0
s32 main (void) {
	// Initialize services
	//gfxInitDefault();
	//gfxSwapBuffers(); 
	Result res;
	gfxInitDefault();
	gfxSwapBuffers(); 
	
	
	consoleInit(GFX_TOP,NULL);
	//printf("miniPasta2\n\n");

	res=suInit();
	printf("su init: %08X\n",res);

	//res=khaxInit();
	//printf("khax init: %08X\n",res);
	
	res=brahma_init();
	printf("brahma init: %08X\n",res);
	
    load_arm9_payload_from_mem (arm9payload_bin, arm9payload_bin_size);
	printf("payload loaded to RAM\n");
	
	res=firm_reboot();	
	printf("firm reboot: %08X\n",res);
	
	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 to hbmenu
	return 0;
}
Exemplo n.º 26
0
void 	waitKey(u32 keyWait)
{
 while (aptMainLoop())
  {
    hidScanInput();

    u32 kPressed = hidKeysDown();
    if (kPressed & keyWait) break;

    gfxFlushBuffers();
    gfxSwapBuffers();
    gspWaitForVBlank();
  } 
}
Exemplo n.º 27
0
int main()
{
    gfxInitDefault();
    hidInit(NULL);

    void* device = gfxCreateDevice(240, 400);
    gfxMakeCurrent(device);

    glViewport(0, 0, 240, 400);
    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();

    float near = 0.1f;
    float far = 100.0f;
    float fov = 90.0f;
    float aspect = 240.0f / 400.0f;
    float t = tan(fov * 3.14159 / 360.0) * near;
    float b = -t;
    float l = aspect * b;
    float r = aspect * t;
    glFrustumf(l, r, b, t, near, far);
    //3DS' framebuffers are sideways
    glRotatef(-90.0f, 0.0f, 0.0f, 1.0f);

    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();

    glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
    glEnable(GL_DEPTH_TEST);

    while (aptMainLoop())
    {
        hidScanInput();

        if (keysDown() & KEY_START)
            break;

        DrawGLScene();

        gfxFlush(gfxGetFramebuffer(GFX_TOP, GFX_LEFT, NULL, NULL));
        gfxFlushBuffers();
        gfxSwapBuffersGpu();
        gspWaitForVBlank();
    }

    // Exit services
    gfxExit();
    hidExit();
    return 0;
}
Exemplo n.º 28
0
int main() {
    gfxInitDefault();
    consoleInit(GFX_TOP, NULL);
    
    Filesystem fs;
    std::string path = "pk/save/main";
    
    if( fs.isInitialized() )
        std::cout << "X: Export save file\nY: Inject save file\n\nSTART: Exit\n\n";
    
    else 
        std::cout << "Failed to initialize filesystem, press START to exit.";

    while(aptMainLoop()) {
        hidScanInput();
        u32 kDown = hidKeysDown();
        
        if( fs.isInitialized() ) {
            if(kDown & KEY_X) {
                if( fs.exportSaveFile(path) )
                    std::cout << "Success! Savefile exported in " << path << ".\n";
                else 
                    std:: cout << "Failed!";
                
                waitA();
                consoleClear();
                std::cout << "X: Export save file\nY: Inject save file\n\nSTART: Exit\n\n";
            }
            
            if(kDown & KEY_Y) {
                if( fs.exportSaveFile(path) )
                    std::cout << "Success! Savefile imported\n";
                else 
                    std:: cout << "Failed!";
                
                waitA();
                consoleClear();
                std::cout << "X: Export save file\nY: Inject save file\n\nSTART: Exit\n\n";
            }
        }
        
        if(kDown & KEY_START) break;
        gfxFlushBuffers();
	gfxSwapBuffers();
        gspWaitForVBlank();
    }
    
    gfxExit();
    return 0;
}
Exemplo n.º 29
0
Arquivo: debug.c Projeto: KuroEX/rd3ds
void pause()
{
    while (1)
    {
        hidScanInput();

        u32 kDown = hidKeysDown();

        if (kDown & KEY_START)
            break;

        gspWaitForVBlank();
    }
}
Exemplo n.º 30
0
int main(int argc, char **argv)
{

	// Initialize services
	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);

    

	// 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

        printf("\x1b[0;0H shared page:\n");

        volatile u8 *spbase;
        spbase = (volatile u8 *)0x1FF81000;

        for(int i = 0; i<16; ++i){
            for(int j = 0; j<16; ++j){
                printf("%02X ", *spbase);
                ++spbase;
            }
            printf("\n");
        }

		// Flush and swap framebuffers
		gfxFlushBuffers();
		gfxSwapBuffers();

		//Wait for VBlank
		gspWaitForVBlank();
	}



	// Exit services
	gfxExit();
	return 0;
}