Ejemplo n.º 1
0
static int SPUTL(unsigned long u, int base, int width, int fill_char, char *obuf)
{
  int r = 0;
  static char outbuf[32];
  char *t;
  char *buf = obuf;

  t = outbuf;

  do {
    *t++ = "0123456789abcdef"[u % base];
    u /= base;
    width--;
  } while (u > 0);

  while (width-- > 0) {
    buf += SPUTC(fill_char,buf);
    r++;
  }
  while (t != outbuf) {
    buf += SPUTC(*--t, buf);
    r++;
  }
  return buf-obuf;
}
Ejemplo n.º 2
0
static void vgaterm_draw_scrollback() {
    for (int y = 0; y < ROWS; y++) {
        uint16_t row = scrollback_start + (scrollback_top + y) * COLS;
        if (row >= scrollback_lines * COLS) row -= scrollback_lines * COLS;
        for (int x = 0; x < COLS; x++) {
            LOC(x, y) = COLOR | *(vga_scrollback_buffer + row + x);
        }
    }

    if (scrolling) {
        // draw a scrollbar.
        SPUTC(SCROLLBAR_X, EDGE_L);
        // buffer is [0, scrollback_max + ROWS). display port is [scrollback_top, scrollback_top + ROWS).
        float bottom = scrollback_max + ROWS;
        float start = (float) scrollback_top / bottom, end = (float) (scrollback_top + ROWS) / bottom;
        for (int x = 0; x < SCROLLBAR_WIDTH; x++) {
            float left = (float) x / (float) SCROLLBAR_WIDTH;
            float middle = ((float) x + 0.5) / (float) SCROLLBAR_WIDTH;
            float right = ((float) x + 1.0) / (float) SCROLLBAR_WIDTH;
            bool left_on = left >= start && middle < end;
            bool right_on = middle >= start && right < end;
            SPUTC(SCROLLBAR_X + x + 1, left_on ? (right_on ? BLOCK_LR : BLOCK_L) : (right_on ? BLOCK_R : ' '));
        }
        SPUTC(SCROLLBAR_X + SCROLLBAR_WIDTH + 1, EDGE_R);
    } else {
        for (int x = 0; x < SCROLLBAR_WIDTH + 2; x++) SPUTC(SCROLLBAR_X + x, ' ');
        STATUS_DISPLAY(SCROLLBAR_X, "Use \x19\x18 for scrollback");
    }
}
Ejemplo n.º 3
0
static void vgaterm_update_status_bar(void) {
    SPUTC(78, '0' + (clock.minute % 10));
    SPUTC(77, '0' + (clock.minute / 10));
    SPUTC(76, ':');
    SPUTC(75, '0' + (clock.hour % 10));
    SPUTC(74, '0' + (clock.hour / 10));
}
Ejemplo n.º 4
0
static int SPUTS(char *s, char *obuf)
{
  char *buf = obuf;
    while (*s) {
      buf += SPUTC(*s++, buf);
    }
    return buf-obuf;
}
Ejemplo n.º 5
0
int _dosprnt(const char *fmt, va_list args, char *obuf)
{
  char c, fill_char;
  char *s_arg;
  int i_arg;
  long l_arg;
  int width;
  int precision;
  char fstr[20];

  char *buf = obuf;
  while( (c = *fmt++) != 0 ) {

    if (c != '%') {
      buf += SPUTC(c, buf);
      continue;
    }
    c = *fmt++;
    width = 0;
    precision = 6;
    fill_char = ' ';
    if (c == '0') fill_char = '0';
    while (c && isdigit(c)) {
      width = 10*width + (c-'0');
      c = *fmt++;
    }
    if(c == '.') {
      precision = 0;
      c = *fmt++;
      while (c && isdigit(c)) {
        precision = 10*precision + (c-'0');
        c = *fmt++;
      }
    }
    if (!c)
      break;

    switch (c) {

      case '%':
        buf += SPUTC(c, buf);
        break;
  
      case 'b':
          l_arg = va_arg(args, int);
        buf += SPUTL(l_arg, 2, width, fill_char, buf);
        break;
  
      case 'c':
        i_arg = va_arg(args, int);
        buf += SPUTC(i_arg, buf);
        break;
  
      case 's':
        s_arg = va_arg(args, char *);
        buf += SPUTS(s_arg, buf);
        break;
  
      case 'd':
      case 'u':
        l_arg = va_arg(args, int);
        if (l_arg < 0 && c == 'd') {
          buf += SPUTC('-', buf);
          width--;
          l_arg = -l_arg;
        }
        buf += SPUTL(l_arg, 10, width, fill_char, buf);
        break;
#if 0
      case 'e':
      case 'g':
      {
        union { float f; int i; } a;
        a.i = va_arg(args, int);
        buf += SPUTS(floatToScientific(a.f), buf);
        break;
      }
#endif
      case 'f': {
        double d = va_arg(args, double);
        buf += SPUTS(float2string((float) d, fstr, width, precision), buf);
        break;
      }

      case 'x': {
        l_arg = va_arg(args, unsigned int);
        buf += SPUTL(l_arg, 16, width, fill_char, buf);
        break;
      }
    }
  }
  *buf = '\0';
  return buf-obuf;
}