//--------------------------------------------------------------------------------- static void consoleClearLine(char mode) { //--------------------------------------------------------------------------------- int i = 0; int colTemp; switch (mode) { case '[': case '0': { colTemp = currentConsole->cursorX ; while(i++ < (currentConsole->windowWidth - colTemp)) { consolePrintChar(' '); } currentConsole->cursorX = colTemp; break; } case '1': { colTemp = currentConsole->cursorX ; currentConsole->cursorX = 0; while(i++ < ((currentConsole->windowWidth - colTemp)-2)) { consolePrintChar(' '); } currentConsole->cursorX = colTemp; break; } case '2': { colTemp = currentConsole->cursorX ; currentConsole->cursorX = 0; while(i++ < currentConsole->windowWidth) { consolePrintChar(' '); } currentConsole->cursorX = colTemp; break; } } gfxFlushBuffers(); }
//--------------------------------------------------------------------------------- static void consoleCls(char mode) { //--------------------------------------------------------------------------------- int i = 0; int colTemp,rowTemp; switch (mode) { case '[': case '0': { colTemp = currentConsole->cursorX ; rowTemp = currentConsole->cursorY ; while(i++ < ((currentConsole->windowHeight * currentConsole->windowWidth) - (rowTemp * currentConsole->consoleWidth + colTemp))) consolePrintChar(' '); currentConsole->cursorX = colTemp; currentConsole->cursorY = rowTemp; break; } case '1': { colTemp = currentConsole->cursorX ; rowTemp = currentConsole->cursorY ; currentConsole->cursorY = 0; currentConsole->cursorX = 0; while (i++ < (rowTemp * currentConsole->windowWidth + colTemp)) consolePrintChar(' '); currentConsole->cursorX = colTemp; currentConsole->cursorY = rowTemp; break; } case '2': { currentConsole->cursorY = 0; currentConsole->cursorX = 0; while(i++ < currentConsole->windowHeight * currentConsole->windowWidth) consolePrintChar(' '); currentConsole->cursorY = 0; currentConsole->cursorX = 0; break; } } gfxFlushBuffers(); }
//--------------------------------------------------------------------------------- static void consoleCls(char mode) { //--------------------------------------------------------------------------------- int i = 0; int colTemp,rowTemp; switch (mode) { case '0': { colTemp = col; rowTemp = row; while(i++ < ((CONSOLE_HEIGHT * CONSOLE_WIDTH) - (rowTemp * CONSOLE_WIDTH + colTemp))) consolePrintChar(' '); col = colTemp; row = rowTemp; break; } case '1': { colTemp = col; rowTemp = row; row = 0; col = 0; while (i++ < (rowTemp * CONSOLE_WIDTH + colTemp)) consolePrintChar(' '); col = colTemp; row = rowTemp; break; } case '2': { row = 0; col = 0; while(i++ < CONSOLE_HEIGHT * CONSOLE_WIDTH) consolePrintChar(' '); row = 0; col = 0; break; } } }
int puts(const char *s) { #ifdef ARM9 int i; for(i=0; i<strlen(s); i++)consolePrintChar(s[i]); #endif return 0; }
int iprintf(const char *format, ...) { int ret = 0, i; va_list args; #ifdef ARM9 memset(print_strbuf, 0, 0x200); va_start(args, format); ret = vsnprintf(print_strbuf, 0x1ff, format, args); for(i=0; i<strlen(print_strbuf); i++)consolePrintChar(print_strbuf[i]); #endif return ret; }
//--------------------------------------------------------------------------------- ssize_t con_write(struct _reent *r,int fd,const char *ptr, size_t len) { //--------------------------------------------------------------------------------- char chr; int i, count = 0; char *tmp = (char*)ptr; if(!tmp || len<=0) return -1; i = 0; while(i<len) { chr = *(tmp++); i++; count++; if ( chr == 0x1b && *tmp == '[' ) { bool escaping = true; char *escapeseq = tmp++; int escapelen = 1; i++; count++; do { chr = *(tmp++); i++; count++; escapelen++; int parameter, assigned, consumed; // make sure parameters are positive values and delimited by semicolon if((chr >= '0' && chr <= '9') || chr == ';') continue; switch (chr) { //--------------------------------------- // Cursor directional movement //--------------------------------------- case 'A': consumed = 0; assigned = sscanf(escapeseq,"[%dA%n", ¶meter, &consumed); if (assigned==0) parameter = 1; if (consumed) currentConsole->cursorY = (currentConsole->cursorY - parameter) < 0 ? 0 : currentConsole->cursorY - parameter; escaping = false; break; case 'B': consumed = 0; assigned = sscanf(escapeseq,"[%dB%n", ¶meter, &consumed); if (assigned==0) parameter = 1; if (consumed) currentConsole->cursorY = (currentConsole->cursorY + parameter) > currentConsole->windowHeight - 1 ? currentConsole->windowHeight - 1 : currentConsole->cursorY + parameter; escaping = false; break; case 'C': consumed = 0; assigned = sscanf(escapeseq,"[%dC%n", ¶meter, &consumed); if (assigned==0) parameter = 1; if (consumed) currentConsole->cursorX = (currentConsole->cursorX + parameter) > currentConsole->windowWidth - 1 ? currentConsole->windowWidth - 1 : currentConsole->cursorX + parameter; escaping = false; break; case 'D': consumed = 0; assigned = sscanf(escapeseq,"[%dD%n", ¶meter, &consumed); if (assigned==0) parameter = 1; if (consumed) currentConsole->cursorX = (currentConsole->cursorX - parameter) < 0 ? 0 : currentConsole->cursorX - parameter; escaping = false; break; //--------------------------------------- // Cursor position movement //--------------------------------------- case 'H': case 'f': { int x, y; char c; if(sscanf(escapeseq,"[%d;%d%c", &y, &x, &c) == 3 && (c == 'f' || c == 'H')) { currentConsole->cursorX = x; currentConsole->cursorY = y; escaping = false; break; } x = y = 1; if(sscanf(escapeseq,"[%d;%c", &y, &c) == 2 && (c == 'f' || c == 'H')) { currentConsole->cursorX = x; currentConsole->cursorY = y; escaping = false; break; } x = y = 1; if(sscanf(escapeseq,"[;%d%c", &x, &c) == 2 && (c == 'f' || c == 'H')) { currentConsole->cursorX = x; currentConsole->cursorY = y; escaping = false; break; } x = y = 1; if(sscanf(escapeseq,"[;%c", &c) == 1 && (c == 'f' || c == 'H')) { currentConsole->cursorX = x; currentConsole->cursorY = y; escaping = false; break; } // invalid format escaping = false; break; } //--------------------------------------- // Screen clear //--------------------------------------- case 'J': if(escapelen <= 3) consoleCls(escapeseq[escapelen-2]); escaping = false; break; //--------------------------------------- // Line clear //--------------------------------------- case 'K': if(escapelen <= 3) consoleClearLine(escapeseq[escapelen-2]); escaping = false; break; //--------------------------------------- // Save cursor position //--------------------------------------- case 's': if(escapelen == 2) { currentConsole->prevCursorX = currentConsole->cursorX ; currentConsole->prevCursorY = currentConsole->cursorY ; } escaping = false; break; //--------------------------------------- // Load cursor position //--------------------------------------- case 'u': if(escapelen == 2) { currentConsole->cursorX = currentConsole->prevCursorX ; currentConsole->cursorY = currentConsole->prevCursorY ; } escaping = false; break; //--------------------------------------- // Color scan codes //--------------------------------------- case 'm': escapeseq++; escapelen--; do { parameter = 0; if (escapelen == 1) { consumed = 1; } else if (memchr(escapeseq,';',escapelen)) { sscanf(escapeseq,"%d;%n", ¶meter, &consumed); } else { sscanf(escapeseq,"%dm%n", ¶meter, &consumed); } escapeseq += consumed; escapelen -= consumed; switch(parameter) { case 0: // reset currentConsole->flags = 0; currentConsole->bg = 0; currentConsole->fg = 7; break; case 1: // bold currentConsole->flags &= ~CONSOLE_COLOR_FAINT; currentConsole->flags |= CONSOLE_COLOR_BOLD; break; case 2: // faint currentConsole->flags &= ~CONSOLE_COLOR_BOLD; currentConsole->flags |= CONSOLE_COLOR_FAINT; break; case 3: // italic currentConsole->flags |= CONSOLE_ITALIC; break; case 4: // underline currentConsole->flags |= CONSOLE_UNDERLINE; break; case 5: // blink slow currentConsole->flags &= ~CONSOLE_BLINK_FAST; currentConsole->flags |= CONSOLE_BLINK_SLOW; break; case 6: // blink fast currentConsole->flags &= ~CONSOLE_BLINK_SLOW; currentConsole->flags |= CONSOLE_BLINK_FAST; break; case 7: // reverse video currentConsole->flags |= CONSOLE_COLOR_REVERSE; break; case 8: // conceal currentConsole->flags |= CONSOLE_CONCEAL; break; case 9: // crossed-out currentConsole->flags |= CONSOLE_CROSSED_OUT; break; case 21: // bold off currentConsole->flags &= ~CONSOLE_COLOR_BOLD; break; case 22: // normal color currentConsole->flags &= ~CONSOLE_COLOR_BOLD; currentConsole->flags &= ~CONSOLE_COLOR_FAINT; break; case 23: // italic off currentConsole->flags &= ~CONSOLE_ITALIC; break; case 24: // underline off currentConsole->flags &= ~CONSOLE_UNDERLINE; break; case 25: // blink off currentConsole->flags &= ~CONSOLE_BLINK_SLOW; currentConsole->flags &= ~CONSOLE_BLINK_FAST; break; case 27: // reverse off currentConsole->flags &= ~CONSOLE_COLOR_REVERSE; break; case 29: // crossed-out off currentConsole->flags &= ~CONSOLE_CROSSED_OUT; break; case 30 ... 37: // writing color currentConsole->fg = parameter - 30; break; case 39: // reset foreground color currentConsole->fg = 7; break; case 40 ... 47: // screen color currentConsole->bg = parameter - 40; break; case 49: // reset background color currentConsole->fg = 0; break; } } while (escapelen > 0); escaping = false; break; default: // some sort of unsupported escape; just gloss over it escaping = false; break; } } while (escaping); continue; } consolePrintChar(chr); }
//--------------------------------------------------------------------------------- ssize_t con_write(struct _reent *r,int fd,const char *ptr, size_t len) { //--------------------------------------------------------------------------------- char chr; int i, count = 0; char *tmp = (char*)ptr; int intensity = 0; if(!tmp || len<=0) return -1; i = 0; while(*tmp!='\0' && i<len) { chr = *(tmp++); i++; count++; if ( chr == 0x1b && *tmp == '[' ) { bool escaping = true; char *escapeseq = tmp; int escapelen = 0; do { chr = *(tmp++); i++; count++; escapelen++; int parameter; switch (chr) { ///////////////////////////////////////// // Cursor directional movement ///////////////////////////////////////// case 'A': siscanf(escapeseq,"[%dA", ¶meter); currentConsole->cursorY = (currentConsole->cursorY - parameter) < 0 ? 0 : currentConsole->cursorY - parameter; escaping = false; break; case 'B': siscanf(escapeseq,"[%dB", ¶meter); currentConsole->cursorY = (currentConsole->cursorY + parameter) > currentConsole->windowHeight - 1 ? currentConsole->windowHeight - 1 : currentConsole->cursorY + parameter; escaping = false; break; case 'C': siscanf(escapeseq,"[%dC", ¶meter); currentConsole->cursorX = (currentConsole->cursorX + parameter) > currentConsole->windowWidth - 1 ? currentConsole->windowWidth - 1 : currentConsole->cursorX + parameter; escaping = false; break; case 'D': siscanf(escapeseq,"[%dD", ¶meter); currentConsole->cursorX = (currentConsole->cursorX - parameter) < 0 ? 0 : currentConsole->cursorX - parameter; escaping = false; break; ///////////////////////////////////////// // Cursor position movement ///////////////////////////////////////// case 'H': case 'f': siscanf(escapeseq,"[%d;%df", ¤tConsole->cursorY , ¤tConsole->cursorX ); escaping = false; break; ///////////////////////////////////////// // Screen clear ///////////////////////////////////////// case 'J': consoleCls(escapeseq[escapelen-2]); escaping = false; break; ///////////////////////////////////////// // Line clear ///////////////////////////////////////// case 'K': consoleClearLine(escapeseq[escapelen-2]); escaping = false; break; ///////////////////////////////////////// // Save cursor position ///////////////////////////////////////// case 's': currentConsole->prevCursorX = currentConsole->cursorX ; currentConsole->prevCursorY = currentConsole->cursorY ; escaping = false; break; ///////////////////////////////////////// // Load cursor position ///////////////////////////////////////// case 'u': currentConsole->cursorX = currentConsole->prevCursorX ; currentConsole->cursorY = currentConsole->prevCursorY ; escaping = false; break; ///////////////////////////////////////// // Color scan codes ///////////////////////////////////////// case 'm': siscanf(escapeseq,"[%d;%dm", ¶meter, &intensity); //only handle 30-37,39 and intensity for the color changes parameter -= 30; //39 is the reset code if(parameter == 9){ parameter = 15; } else if(parameter > 8){ parameter -= 2; } else if(intensity){ parameter += 8; } if(parameter < 16 && parameter >= 0){ currentConsole->fontCurPal = parameter << 12; } escaping = false; break; } } while (escaping); continue; } consolePrintChar(chr); } return count; }
//--------------------------------------------------------------------------------- int con_write(struct _reent *r,int fd,const char *ptr,int len) { //--------------------------------------------------------------------------------- if (!consoleInitialised) return -1; char chr; int i, count = 0; char *tmp = (char*)ptr; if(!tmp || len<=0) return -1; i = 0; while(*tmp!='\0' && i<len) { chr = *(tmp++); i++; count++; if ( chr == 0x1b && *tmp == '[' ) { bool escaping = true; char *escapeseq = tmp; int escapelen = 0; do { chr = *(tmp++); i++; count++; escapelen++; int parameter; switch (chr) { ///////////////////////////////////////// // Cursor directional movement ///////////////////////////////////////// case 'A': siscanf(escapeseq,"[%dA", ¶meter); row = (row - parameter) < 0 ? 0 : row - parameter; escaping = false; break; case 'B': siscanf(escapeseq,"[%dB", ¶meter); row = (row + parameter) > CONSOLE_HEIGHT - 1 ? CONSOLE_HEIGHT - 1 : row + parameter; escaping = false; break; case 'C': siscanf(escapeseq,"[%dC", ¶meter); col = (col + parameter) > CONSOLE_WIDTH - 1 ? CONSOLE_WIDTH - 1 : col + parameter; escaping = false; break; case 'D': siscanf(escapeseq,"[%dC", ¶meter); col = (col - parameter) < 0 ? 0 : col - parameter; escaping = false; break; ///////////////////////////////////////// // Cursor position movement ///////////////////////////////////////// case 'H': case 'f': siscanf(escapeseq,"[%d;%df", &row, &col); escaping = false; break; ///////////////////////////////////////// // Screen clear ///////////////////////////////////////// case 'J': consoleCls(escapeseq[escapelen-2]); escaping = false; break; ///////////////////////////////////////// // Line clear ///////////////////////////////////////// case 'K': consoleClearLine(escapeseq[escapelen-2]); escaping = false; break; ///////////////////////////////////////// // Save cursor position ///////////////////////////////////////// case 's': savedX = col; savedY = row; escaping = false; break; ///////////////////////////////////////// // Load cursor position ///////////////////////////////////////// case 'u': col = savedX; row = savedY; escaping = false; break; } } while (escaping); continue; } consolePrintChar(chr); } return count; }
//--------------------------------------------------------------------------------- static void consoleClearLine(char mode) { //--------------------------------------------------------------------------------- int i = 0; int colTemp; switch (mode) { case '0': { colTemp = col; while(i++ < (CONSOLE_WIDTH - colTemp)) { consolePrintChar(' '); } col = colTemp; break; } case '1': { colTemp = col; col = 0; while(i++ < ((CONSOLE_WIDTH - colTemp)-2)) { consolePrintChar(' '); } col = colTemp; break; } case '2': { colTemp = col; col = 0; while(i++ < CONSOLE_WIDTH) { consolePrintChar(' '); } col = colTemp; break; } default: { colTemp = col; while(i++ < (CONSOLE_WIDTH - colTemp)) { consolePrintChar(' '); } col = colTemp; break; } } }
//--------------------------------------------------------------------------------- ssize_t con_write(struct _reent *r,void *fileStruct ,const char *ptr,size_t len) { //--------------------------------------------------------------------------------- char chr; if (!consoleInitialised) return -1; int i, count = 0; char *tmp = (char*)ptr; if(!tmp || len<=0) return -1; i = 0; while(*tmp!='\0' && i<len) { chr = *(tmp++); i++; count++; if ( chr == 0x1b && *tmp == '[' ) { bool escaping = true; char *escapeseq = tmp; int escapelen = 0; do { chr = *(tmp++); i++; count++; escapelen++; int parameter; switch (chr) { case 'H': siscanf(escapeseq,"[%d;%dH", &consoleY, &consoleX); escaping = false; break; case 'f': siscanf(escapeseq,"[%d;%df", &consoleY, &consoleX); escaping = false; break; case 'A': siscanf(escapeseq,"[%dA", ¶meter); consoleY = (consoleY - parameter) < 0 ? 0 : consoleY - parameter; escaping = false; break; case 'B': siscanf(escapeseq,"[%dB", ¶meter); consoleY = (consoleY + parameter) > CONSOLE_HEIGHT - 1 ? CONSOLE_HEIGHT - 1 : consoleY + parameter; escaping = false; break; case 'C': siscanf(escapeseq,"[%dC", ¶meter); consoleX = (consoleX + parameter) > CONSOLE_WIDTH - 1 ? CONSOLE_WIDTH - 1 : consoleX + parameter; escaping = false; break; case 'D': siscanf(escapeseq,"[%dC", ¶meter); consoleX = (consoleX - parameter) < 0 ? 0 : consoleX - parameter; escaping = false; break; case 'K': escaping = false; break; case 's': savedX = consoleX; savedY = consoleY; escaping = false; break; case 'u': consoleX = savedX; consoleY = savedY; escaping = false; break; case 'J': if ( escapeseq[escapelen-2] == '2') { consoleCls(); consoleX = 0; consoleY = 0; } escaping = false; break; } } while (escaping); continue; } consolePrintChar(chr); } return count; }