static void early_write(const char *s, unsigned n) { while (n-- > 0) { if (*s == '\n') printch('\r'); printch(*s); s++; } }
static void early_write(const char *s, unsigned n) { #ifndef CONFIG_EVB_PLATFORM if(first_print) { first_print = false; uart_init(); } #endif while (n-- > 0) { if (*s == '\n') printch('\r'); printch(*s); s++; } }
PROC refresh(int y,int x,int start,int endd, bool rest) { int sp; #if ST /* turn the cursor off */ asm(" clr.l -(sp) "); asm(" move.w #21,-(sp) "); asm(" trap #14 "); asm(" addq.l #6,sp "); #endif sp = start; while (sp <= endd) { writeline(y, x, sp); sp = 1+fseekeol(sp); y++; x = 0; } if (rest && sp >= bufmax) while (y<LINES-1) { /* fill screen with ~ */ mvcur(y, 0); printch('~'); strput(CE); y++; } #if ST /* turn the cursor back on */ asm(" clr.w -(sp) "); asm(" move.w #1,-(sp) "); asm(" move.w #21,-(sp) "); asm(" trap #14 "); asm(" addq.l #6,sp "); #endif }
void print(string ch) { uint16 i = 0; for(; i<strlen(ch); i++) { printch(ch[i]); } }
void printstr(u32* str, int x, int y, int tall) { int i; u32 kram = x + (y << 5); int len = strlen32(str); for(i = 0; i < len; i++) { printch(str[i], kram + i, tall); } }
int16_t player_hit(Player* player, int16_t x, int16_t y) { if( x < player->pos.x || x >= player->pos.x + 3 || y < player->pos.y || y >= player->pos.y + 2) { return 0; } explosion(x, y); draw_player(player); player->hull -= SHOT_DAMAGE; draw_stats(player); term_setpos(MSG_X, MSG_Y + 1); printstr("hit player "); printch(player->id); return 1; }
void catFile(fs_node_t* fsnode) { newline(); if ((fsnode->flags & 0x7) == FS_FILE) { const uint32 rbuff = fsnode->length; char buf[rbuff]; uint32 sz = read_fs(fsnode, 0, rbuff, (uint8*) buf); uint32 j; for (j = 0; j < sz; j++) printch(buf[j], 0x0F); newline(); } }
void board_init_f(ulong dummy) { /* Example code showing how to enable the debug UART on RK3188 */ #ifdef EARLY_UART #include <asm/arch/grf_rk3188.h> /* Enable early UART on the RK3188 */ #define GRF_BASE 0x20008000 struct rk3188_grf * const grf = (void *)GRF_BASE; rk_clrsetreg(&grf->gpio1b_iomux, GPIO1B1_MASK << GPIO1B1_SHIFT | GPIO1B0_MASK << GPIO1B0_SHIFT, GPIO1B1_UART2_SOUT << GPIO1B1_SHIFT | GPIO1B0_UART2_SIN << GPIO1B0_SHIFT); /* * Debug UART can be used from here if required: * * debug_uart_init(); * printch('a'); * printhex8(0x1234); * printascii("string"); */ debug_uart_init(); printch('t'); printch('p'); printch('l'); printch('-'); printch(rk3188_num_entries + 1 + '0'); printch('\n'); #endif rk3188_num_entries++; if (rk3188_num_entries == 1) { /* * The original loader did some very basic integrity * checking at this point, but the remaining few bytes * could be used for any improvement making sense * really early on. */ back_to_bootrom(); } else { /* * TPL part of the loader should now wait for us * at offset 0xC00 in the sram. Should never return * from there. */ jump_to_spl(); } }
void fillrect(int16_t x, int16_t y, int16_t w, int16_t h, int16_t ch) { int16_t i; char nextline[sizeof "\x1B[000B\x1B[1D"]; h += y; sprintf(nextline, "\x1B[%dB\x1B[1D", w); term_setpos(x, y); for(; y < h; ++y) { term_setpos(x, y); for(i = 0; i < w; ++i) { printch(ch); } printstr(nextline); } }
void getstr(void) { s8 buf[1024]; u16 bufptr = 0; memset(buf, 0, sizeof(buf)); while (1) { if (getport(PORT_KEYBOARD_READY) & 0x01) { u8 scancode = getport(PORT_KEYBOARD_CHAR); if (scancode == 0x1c) { docmd(buf); bufptr = 0; break; } if (!(scancode & 0x80)) { printch(KEYMAP[scancode]); buf[bufptr++] = KEYMAP[scancode]; } } } }
void arch_setup_gd(gd_t *new_gd) { global_data_ptr = new_gd; /* * TODO([email protected]): For some reason U-Boot does not boot * without this line. It fails to start up U-Boot proper and instead * restarts SPL. Need to figure out why: * * U-Boot SPL 2017.01 * * U-Boot SPL 2017.01 * CPU: Intel(R) Core(TM) i5-3427U CPU @ 1.80GHz * Trying to boot from SPIJumping to 64-bit U-Boot: Note many * features are missing * * U-Boot SPL 2017.01 */ #ifdef CONFIG_DEBUG_UART printch(' '); #endif }
void listTree() { // list the contents of int i = 0; struct dirent *node = 0; while ((node = readdir_fs(fs_root, i)) != 0) { fs_node_t *fsnode = finddir_fs(fs_root, node->name); if ((fsnode->flags & 0x7) == FS_DIRECTORY) { print("dir \t", 0x0F); print(node->name, 0x0F); printch('/', 0x0F); } else { print("file\t", 0x0F); print(node->name, 0x0F); } newline(); i++; } }
void printf(s8* str) { for (u16 i = 0; i < strlen(str); i++) { printch(str[i]); } }
void board_init_f(ulong dummy) { struct udevice *pinctrl, *dev; int ret; /* Example code showing how to enable the debug UART on RK3188 */ #ifdef EARLY_UART #include <asm/arch/grf_rk3188.h> /* Enable early UART on the RK3188 */ #define GRF_BASE 0x20008000 struct rk3188_grf * const grf = (void *)GRF_BASE; rk_clrsetreg(&grf->gpio1b_iomux, GPIO1B1_MASK << GPIO1B1_SHIFT | GPIO1B0_MASK << GPIO1B0_SHIFT, GPIO1B1_UART2_SOUT << GPIO1B1_SHIFT | GPIO1B0_UART2_SIN << GPIO1B0_SHIFT); /* * Debug UART can be used from here if required: * * debug_uart_init(); * printch('a'); * printhex8(0x1234); * printascii("string"); */ debug_uart_init(); printch('s'); printch('p'); printch('l'); printch('\n'); #endif ret = spl_early_init(); if (ret) { debug("spl_early_init() failed: %d\n", ret); hang(); } ret = rockchip_get_clk(&dev); if (ret) { debug("CLK init failed: %d\n", ret); return; } ret = uclass_get_device(UCLASS_PINCTRL, 0, &pinctrl); if (ret) { debug("Pinctrl init failed: %d\n", ret); return; } ret = uclass_get_device(UCLASS_RAM, 0, &dev); if (ret) { debug("DRAM init failed: %d\n", ret); return; } setup_arm_clock(); #if CONFIG_IS_ENABLED(ROCKCHIP_BACK_TO_BROM) && !defined(CONFIG_SPL_BOARD_INIT) back_to_bootrom(BROM_BOOT_NEXTSTAGE); #endif }
void board_init_f(ulong dummy) { struct udevice *pinctrl, *dev; struct rk3188_pmu *pmu; int ret; /* Example code showing how to enable the debug UART on RK3188 */ #ifdef EARLY_UART #include <asm/arch/grf_rk3188.h> /* Enable early UART on the RK3188 */ #define GRF_BASE 0x20008000 struct rk3188_grf * const grf = (void *)GRF_BASE; rk_clrsetreg(&grf->gpio1b_iomux, GPIO1B1_MASK << GPIO1B1_SHIFT | GPIO1B0_MASK << GPIO1B0_SHIFT, GPIO1B1_UART2_SOUT << GPIO1B1_SHIFT | GPIO1B0_UART2_SIN << GPIO1B0_SHIFT); /* * Debug UART can be used from here if required: * * debug_uart_init(); * printch('a'); * printhex8(0x1234); * printascii("string"); */ debug_uart_init(); printch('s'); printch('p'); printch('l'); printch('\n'); #endif ret = spl_early_init(); if (ret) { debug("spl_early_init() failed: %d\n", ret); hang(); } rockchip_timer_init(); ret = rockchip_get_clk(&dev); if (ret) { debug("CLK init failed: %d\n", ret); return; } /* * Recover the bootrom's stackpointer. * For whatever reason needs to run after rockchip_get_clk. */ pmu = syscon_get_first_range(ROCKCHIP_SYSCON_PMU); if (IS_ERR(pmu)) error("pmu syscon returned %ld\n", PTR_ERR(pmu)); SAVE_SP_ADDR = readl(&pmu->sys_reg[2]); ret = uclass_get_device(UCLASS_PINCTRL, 0, &pinctrl); if (ret) { debug("Pinctrl init failed: %d\n", ret); return; } ret = uclass_get_device(UCLASS_RAM, 0, &dev); if (ret) { debug("DRAM init failed: %d\n", ret); return; } setup_arm_clock(); #if defined(CONFIG_ROCKCHIP_SPL_BACK_TO_BROM) && !defined(CONFIG_SPL_BOARD_INIT) back_to_bootrom(); #endif }
void readStr(string buffstr, uint32 bufSize) { uint32 i = 0; bool reading = true; while(reading) { //exit the writer program when the Ctrl-Z key is pressed if (progexit && writing) { clearScreen(); updateCursor(); writing = false; progexit = false; print("Q-Kernel> ", 0x08); } if (newCmd && typingCmd) { startCmdX = cursorX; startCmdY = cursorY; newCmd = 0; } //Detect keypress and return string of characters pressed to the buffstr char array if(inportb(0x64) & 0x1) { uint8 value = inportb(0x60); if (deleteStopX > 0) { if ((cursorX == deleteStopX) && (cursorY == startCmdY)) { /* Make sure user cannot press delete anymore */ if (value == 14) continue; } } /* Make sure the user can only press delete */ if (buffOverflow) { if (value == 14) buffOverflow = false; else continue; } bool handled = false; switch(value) { case 29: // Left Ctrl Down ctrl = true; // Toggle On break; case 157: // Left Ctrl Up ctrl = false; // Toggle Off break; case 1: // Esc (Ctrl-z) if (writing) { progexit = true; reading = false; } else { i = pushCtrlChar(i, buffstr, 'Z', bufSize); } break; case 14: // Backspace if (lshift || rshift) { // On of the shifts are activated // Delete until space | non-word | different-cased-word i = backspaceMul(i, buffstr, bufSize); } else { // No shift -> delete one char i = backspaceOne(i, buffstr, bufSize); } break; case 25: if (ctrl) { if (writing) { moveUp(); handled = true; } } break; case 28: //This is the enter key, we need to add more functionality to it with Writer and other commands if (writing) { printch('\n',0x0F); buffstr[i] = '\n'; i++; } else { reading = false; } break; case 30: if (ctrl) { moveCursorX(-cursorX + deleteStopX); handled = true; } break; case 38: if (ctrl) { /* Make sure no clear screen during writer session */ if (!writing) { clearScreen(); // Returns command "skip" which does nothing strcpy(buffstr, "skip"); buffstr[4] = '\0'; /* Set EOL */ handled = true; return; } } break; case 42: //Left shift lshift = true; break; case 44: // z or Ctrl-Z if (ctrl) { if (writing) { progexit = true; reading = false; handled = true; } } break; case 48: if (ctrl) { moveCursorX(-1); handled = true; } break; case 49: if (ctrl) { if (writing) { moveDown(); handled = true; } } break; case 54: // Right shift on rshift = true; // Toggle On break; case 56: // Left/Right alt On alt = true; // Toggle On break; case 58: // Capslock down capslock = !capslock; break; case 72: //Up arrow if (writing) { moveUp(); } break; case 75: //Left Arrow moveCursorX(-1); break; case 77: //Right Arrow moveCursorX(1); break; case 80: //Down Arrow if (writing) { moveDown(); } break; case 170: // Left shift released (http://wiki.osdev.org/PS2_Keyboard) lshift = false; break; case 182: // Right shift released (http://wiki.osdev.org/PS2_Keyboard) rshift = false; // Toggle Off break; case 184: // Left/Right alt Off alt = false; // Toggle Off break; } if(!handled && chars[value]) { i = charKeyPressed(buffstr, value, i, bufSize); } } } buffstr[i] = 0; }
PROC docommand(cmdtype cmd) { cmdtype movecmd; /* movement command for y, d, c */ char cmdch; int oldc; /* old count */ int endp; /* end position before change */ extern bool s_wrapped; resetX(); /* un-derange the cursor */ oldc = newc = -1; endY = yp; newend = disp = curr; ok = TRUE; /* so far everything is working */ cmdch = ch; if (cmd != UNDO_C && cmd != YANK_C) { if (macro<0) zerostack(&undo); if (redoing != TRUE) { rcp = rcb; /* point at start of redo buffer */ if (count > 1) { /* put in a count? */ numtoa(rcb,count); rcp += strlen(rcb); } *rcp++ = cmdch; /* the command char goes in... */ xerox = TRUE; /* hoist the magical flags */ } } if (cmd <= YANK_C) { readchar(); if (ch >= '0' && ch <= '9') { oldc = count; gcount(); /* get a new count */ if (cmd == ADJUST_C) /* special for >>,<< wierdness */ swap(&count, &oldc); /* reverse sw & count */ else count = count*max(oldc,1); /* combine them */ } if (ch == cmdch) { /* diddle lines */ yank.lines = TRUE; endp = nextline(TRUE, curr, count); curr = bseekeol(curr); disp = curr; } else { /* diddle 'things' */ yank.lines = FALSE; movecmd = movemap[ch]; if (ok = (findCP(curr,&endp,movecmd) == LEGALMOVE)) { if (curr > endp) { swap(&curr,&endp); ok = (cmd != CHANGE_C); } if (adjcurr[movecmd]) curr++; if (adjendp[movecmd]) endp++; } if (!ok) { if (ch != ESC) error(); goto killredo; } } endY = setY(endp); newend = curr; disp = curr; switch (cmd) { case DELETE_C: ok = deletion(curr, endp); break; case ADJUST_C: adjuster((cmdch == '<'), endp-1, oldc); break; case CHANGE_C: if (endp <= pend+1) { mvcur(setY(endp-1), setX(endp-1)); printch('$'); mvcur(yp, xp); } if (deletion(curr, endp)) ok = ((newend = insertion(1, 0, &disp, &endY, TRUE)) >= 0); else ok = FALSE; break; case YANK_C: if (!doyank(curr, endp)) error(); return 0; /* xerox will not be true, nor will redoing */ } } else { endp = curr; endY = yp; switch (cmd) { case I_AT_NONWHITE: case A_AT_END: case APPEND_C: case INSERT_C: /* variations on insert */ if (cmd != INSERT_C) { if (cmd == APPEND_C) curr = min(curr+1, lend); else if (cmd == A_AT_END) curr = lend; else /* if (cmd == I_AT_NONWHITE) */ curr = skipws(lstart); xp = setX(curr); mvcur(yp,xp); } newend = insertion(count, 0, &disp, &endY, TRUE); ok = (newend >= 0); break; case OPEN_C: case OPENUP_C: newend = insertion(1,setstep[ (cmd==OPENUP_C)&1 ], &disp,&endY,TRUE)-1; ok = (newend >= 0); break; case REPLACE_C: case TWIDDLE_C: if (cmd == REPLACE_C) { if ((cmdch = readchar()) == ESC) goto killredo; } if (findCP(curr, &endp, GO_RIGHT) == LEGALMOVE) squiggle(endp-1, cmdch, (cmd==REPLACE_C)); break; case PUT_BEFORE: case PUT_AFTER: ok = put(cmd==PUT_AFTER); break; case BIG_REPL_C: bigreplace(); break; case RESUBST_C: ok = FALSE; if (dst[0] != 0) { newend = chop(curr, &lend, TRUE, &ok); if (newend >= 0) { endY = setY(newend+strlen(dst)); ok = TRUE; } } break; case JOIN_C: join(count); /* join lines */ break; case UNDO_C: /* undo last modification */ ok = fixcore(&newend) >= 0; disp = newend; endY = MAGICNUMBER; break; } } if (ok) { setpos((newc<0)?newend:newc); setend(); if (curr < ptop || curr > pend) { yp = settop(12); redisplay(TRUE); } else { yp = setY(curr); if (endY != setY(newend)) /* shuffled lines */ refresh(setY(disp), setX(disp), disp, pend, TRUE); else /* refresh to end position */ refresh(setY(disp), setX(disp), disp, newend, FALSE); } if (curr >= bufmax && bufmax > 0) { /* adjust off end of buffer */ setpos(bufmax-1); yp = setY(curr); } if (s_wrapped) { prompt(FALSE, "search wrapped around end of buffer"); s_wrapped = 0; } else clrprompt(); modified = TRUE; } else { error(); killredo: rcb[0] = 0; } mvcur(yp, xp); if (xerox) *rcp = 0; /* terminate the redo */ redoing = FALSE; xerox = FALSE; core[bufmax] = EOL; }
kmain() { clearScreen(); print("================================================================================\n",0x0F); print(" Welcome to Q OS\n\n",0x0F); print("================================================================================\n",0x0F); while (1) { print("\nQ-Kernel> ",0x0F); string ch = readStr(); if(strEql(ch,"help ")) { print("\nShowing Help for Q OS ",0x0F); } else if(strEql(ch,"do")) { print("\n> ",0x0F); string tmp = readStr(); if(strEql(tmp,"repeat")) { print("\nrepeat> ",0x0F); string tmp = readStr(); nano = 1; while(1) { printch('\n',0x0F); print(tmp,0x0F); } } if(strEql(tmp,"execute")) { print("\n",0x0F); } else { print("The 'do' command does not support the command you entered or it does not exist ",0x0F); } } else if(strEql(ch,"ls")) { print("\nNo Files Found on Disk ",0x0F); } else if(strEql(ch,"cd")) { print("\nThe specified directory was not found ",0x0F); } else if(strEql(ch,"nano")) { nano = 1; clearScreen(); print(" Q-OS Nano Text Editor Version 0.1 ",0xF0); print("\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n",0x0F); print(" Built for Q-OS by Raph Hennessy ",0xF0); cursorX = 0; cursorY = 1; updateCursor(); string nanoOutput = readStr(); } else if(strEql(ch,"clear")) { clearScreen(); } else if(strEql(ch,"sudo")) { print("\n",0x0F); } else if(strEql(ch,"exit")) { print("\n",0x0F); } else if(strEql(ch,"run")) { print("\n",0x0F); } else { print("\nCommand Not Found ",0x0F); } print("\n",0x0F); } }