int init_gui() { nio_InitConsole(&c1,64,27,0,0,0,15); nio_DrawConsole(&c1); nio_printf(&c1,"Chip8 Interpreter | Dev\n Build of %s at %s\n\n\n > ",__DATE__,__TIME__); nio_printf(&c1,"Type \"fb\" to open the filebrowser. You can also directly type\n > the name of the file you want to play\n > ###############\n\n > "); }
int gui(Exec_info exec_info) { unsigned char path[100] = {'\0'}; int exec_time, exec_frequency; int key = 0; int handle = -1; nio_DrawConsole(&c1); if(exec_info.cycles_count != 0) { exec_time = (int)((exec_info.tick_end - exec_info.tick_start)/128); exec_frequency = exec_info.cycles_count/(exec_time * 1000); nio_printf(&c1, "Game terminated. Execution time : %d s.\n > Average execution frequency : %d kHz\n > ", exec_time, exec_frequency); } #ifndef EMULATOR while(handle < 0) { nio_GetStr(&c1, path); if(!strcmp(path, "exit")) { while(1) { GetKey(&key); } } else if(!strcmp(path, "help")) nio_printf(&c1, "Type name of the file you want to load\n or, if you want to leave me , write 'exit' :(\n > "); else if(!strcmp(path, "fb")) { #endif fileBrowser(path, (unsigned char*)"*.ch", (unsigned char*)"*.CH8", (unsigned char*)"*.ch8", "Files"); nio_DrawConsole(&c1); if(strcmp(path, "")) { handle = CC_open_file(path+7); if(handle < 0) nio_printf(&c1, "Error opening %s ... Check if the file exists\n > ", path); else { return handle; } } #ifndef EMULATOR } else { handle = CC_open_file(path); if(handle < 0) nio_printf(&c1, "Error opening %s ... Check if the file exists\n > ", path); else { return handle; } } } #endif }
int main() { Bdisp_AllClr_VRAM(); Bdisp_EnableColor(1); // Initialize console 1. nio_console c1; // The screen can hold up to 64 columns and 27 rows // 64 columns, 14 rows. 0px offset for x/y. Background color 15 (white), foreground color 0 (black) nio_InitConsole(&c1,64,14,0,0, NIO_COLOR_BLACK, NIO_COLOR_WHITE); nio_DrawConsole(&c1); nio_console c2; nio_InitConsole(&c2,64,13,0,14*8, NIO_COLOR_BLACK, NIO_COLOR_WHITE); nio_DrawConsole(&c2); // Just showing printf nio_printf(&c1,"%s build at %s, %s\n",__FILE__,__DATE__,__TIME__); nio_printf(&c2,"256 text colors available! "); int i; for(i = 1; i<16; i++) { nio_SetColor(&c2, 0, i); nio_printf(&c2, "%d ", i); } nio_printf(&c2,"\n"); // Press EXE to exit while(1) { char text[100]; // If no text was entered, exit if(!nio_GetStr(&c1,text)) break; // Write the text into 2nd console nio_printf(&c2,"%s\n",text); //Bdisp_PutDisp_DD(); } nio_CleanUp(&c1); nio_CleanUp(&c2); return 0; }
int module_main(int argc, char *argv[]) { if (argc < 2) { // 不带参数执行 nio_printf("cat: missing file operand\n"); return 1; } char *path = malloc(MAX_PATH_LENGTH * sizeof(char)); sh_relativePathToAbsolute(path, argv[1]); FILE *fp = fopen(path, "r"); if (fp == NULL) { nio_printf("cat: %s: No such file\n", argv[1]); return 1; } char c; while (c = fgetc(fp), !feof(fp)) { // 先 fgetc 再判断文件末尾 nio_putc(c, nio_get_default()); } fclose(fp); free(path); return 0; }
int main(int argc, char *argv[]) { wait_no_key_pressed(); // Initialize console 1. nio_console c1; nio_init(&c1, NIO_MAX_COLS, NIO_MAX_ROWS, 0, 0, NIO_COLOR_BLACK, NIO_COLOR_WHITE, TRUE); nio_set_default(&c1); nio_fflush(&c1); nio_printf("%s built at %s, %s\n", __FILE__, __DATE__, __TIME__); nio_printf("For help with this console, type \"help\"!\n\n"); while (1) { char text[100]; nio_printf("> "); // If no text was entered, exit if (!nio_gets(text)) continue; // Check for interesting text if (!strcmp(text, "help")) { nio_printf("HexCellsLib Test Help\n"); nio_printf(" runtests\n"); nio_printf(" Runs the unit tests\n"); nio_printf(" setcursor cursor\n"); nio_printf(" Set the cursor type.\n"); nio_printf(" cursor can be from 0-3, where:\n"); nio_printf(" 0 is a block cursor\n"); nio_printf(" 1 is an underscore cursor\n"); nio_printf(" 2 is a verical bar cursor\n"); nio_printf(" 3 is a custom cursor\n"); nio_printf(" setcursorwidth\n"); nio_printf(" Set the cursor width.\n"); nio_printf(" clear\n"); nio_printf(" Clear the console.\n"); nio_printf(" exit\n"); nio_printf(" Exit this console.\n"); } if (!strcmp(text, "setcursor 0")) { nio_cursor_type(&c1, NIO_CURSOR_BLOCK); nio_printf(" Cursor type is now set to block cursor.\n"); } if (!strcmp(text, "setcursor 1")) { nio_cursor_type(&c1, NIO_CURSOR_UNDERSCORE); nio_printf(" Cursor type is now set to underscore cursor.\n"); } if (!strcmp(text, "setcursor 2")) { nio_cursor_type(&c1, NIO_CURSOR_VERTICAL); nio_printf(" Cursor type is now set to vertical bar cursor.\n"); } if (!strcmp(text, "setcursorwidth")) { nio_printf("Specify cursor width: "); char num[10]; nio_gets(num); nio_cursor_width(&c1, atoi(num)); } if (StartsWith(text, "RunTests")) { RunTests(); } if (!strcmp(text, "clear")) { nio_clear(&c1); } if (StartsWith(text, "exit")) break; } nio_free(&c1); //if(has_colors) // lcd_incolor(); return 0; }