if (ch == 0) {
return 0;
}
- extern tty_t default_tty;
+ extern tty_t *const default_tty;
if (ch == '\b') {
if (!empty(&cnsl.wr_q)) {
- tty_color_putc(&default_tty, '\b', TTY_FG_HIGHLIGHT | TTY_WHITE, TTY_BLACK);
+ tty_color_putc(default_tty, '\b', TTY_FG_HIGHLIGHT | TTY_WHITE, TTY_BLACK);
}
// tty_color_putc(default_tty, '\b', TTY_WHITE, TTY_BLACK);
erase(&cnsl.wr_q);
} else {
put(&cnsl.wr_q, ch);
put(&cnsl.sc_q, ch);
- tty_color_putc(&default_tty, ch, TTY_FG_HIGHLIGHT | TTY_WHITE, TTY_BLACK);
+ tty_color_putc(default_tty, ch, TTY_FG_HIGHLIGHT | TTY_WHITE, TTY_BLACK);
}
if (ch == '\n') {
add_irq_bh_handler(kbd_bh_handler);
}
-extern tty_t default_tty;
-extern tty_t monitor_tty;
-extern tty_t debug_tty;
-
-static tty_t *ttys[] = {&default_tty, &monitor_tty, &debug_tty};
-static int tty_no = 0;
+extern tty_t *const default_tty;
+extern tty_t *const monitor_tty;
+extern tty_t *const debug_tty;
+extern void tty_switch_to_next();
void kbd_debug(uint8_t scan_code) {
static unsigned long kbd_cnt = 0;
// printd("[%02x]", scan_code);
if (scan_code == 0x3B) { // F1
- tty_switch(&default_tty);
+ tty_switch(default_tty);
} else if (scan_code == 0x3C) { // F2
- tty_switch(&monitor_tty);
+ tty_switch(monitor_tty);
} else if (scan_code == 0x3D) { // F3
- tty_switch(&debug_tty);
+ tty_switch(debug_tty);
}
if (scan_code == 0x3F) // F5
}
if (scan_code == 0x58) { // F12
- // current_tty = current_tty != &default_tty ? &default_tty : &monitor_tty;
- current_tty = ttys[++tty_no % (sizeof(ttys) / sizeof(ttys[0]))];
- tty_switch(current_tty);
+ tty_switch_to_next();
}
// ide_status();
void tty_set_cursor(tty_t *tty);
void tty_switch(tty_t *tty);
-extern tty_t *current_tty;
\ No newline at end of file
+void tty_switch_to_next();
+
+extern tty_t *current_tty;
int vsprintf(char *buf, const char *fmt, char *args);
char pkbuf[1024];
-extern tty_t default_tty;
+extern tty_t *const default_tty;
int printk(const char *fmtstr, ...) {
unsigned long iflags;
irq_save(iflags);
char *args = (char *)(((char *)&fmtstr) + 4);
int size = vsprintf(pkbuf, fmtstr, args);
- tty_write(&default_tty, pkbuf, (size_t)size);
+ tty_write(default_tty, pkbuf, (size_t)size);
irq_restore(iflags);
return 0;
}
-extern tty_t debug_tty;
+extern tty_t *const debug_tty;
char pdbuf[1024];
int printd(const char *fmtstr, ...) {
unsigned long iflags;
irq_save(iflags);
char *args = (char *)(((char *)&fmtstr) + 4);
int size = vsprintf(pdbuf, fmtstr, args);
- tty_write(&debug_tty, pdbuf, (size_t)size);
+ tty_write(debug_tty, pdbuf, (size_t)size);
irq_restore(iflags);
return 0;
}
char plobuf[1024];
-extern tty_t monitor_tty;
+extern tty_t *const monitor_tty;
int printlo(unsigned int xpos, unsigned int ypos, const char *fmtstr, ...) {
unsigned long iflags;
irq_save(iflags);
char *args = (char *)(((char *)&fmtstr) + 4);
int size = vsprintf(plobuf, fmtstr, args);
- tty_write_at(&monitor_tty, xpos, ypos, plobuf, (size_t)size);
+ tty_write_at(monitor_tty, xpos, ypos, plobuf, (size_t)size);
irq_restore(iflags);
return 0;
}
printk(version);
boot_delay(DEFAULT_BOOT_DELAY_TICKS);
- extern tty_t monitor_tty;
- // tty_switch(&monitor_tty);
+ extern tty_t *const monitor_tty;
+ // tty_switch(monitor_tty);
boot_delay(DEFAULT_BOOT_DELAY_TICKS);
const uint32_t VADDR = (uint32_t)pa2va(PHY_VADDR);
#define TTY_VRAM_SIZE (0x1000)
+#define NR_TTYS 8
+tty_t ttys[NR_TTYS];
+
#define MAX_X 80
#define MAX_Y 25
#define CHARS_PER_LINE (MAX_X)
#define BYTES_PER_LINE (CHARS_PER_LINE * 2)
#define TAB_SPACE 4
-tty_t default_tty;
-tty_t monitor_tty;
-tty_t debug_tty;
+tty_t *const default_tty = ttys + 0;
+tty_t *const monitor_tty = ttys + 1;
+tty_t *const debug_tty = ttys + 2;
void tty_clear(tty_t *tty) {
char *dst = (char *)tty->base_addr;
void init_tty(tty_t *tty, const char *name, unsigned long base) {
assert(0 != tty);
- memset(tty, 0, sizeof(tty_t));
-
strlcpy(tty->name, name, sizeof(tty->name));
tty->fg_color = TTY_FG_HIGHLIGHT | TTY_GREEN; // 高亮
void init_ttys() {
assert(irq_disabled());
- init_tty(&default_tty, "tty.default", VADDR + 0 * TTY_VRAM_SIZE);
- init_tty(&monitor_tty, "tty.monitor", VADDR + 1 * TTY_VRAM_SIZE);
- init_tty(&debug_tty, "tty.debug", VADDR + 7 * TTY_VRAM_SIZE);
+ for (int i = 0; i < NR_TTYS; i++) {
+ tty_t *tty = ttys + i;
+ char name[sizeof(tty->name)];
+ sprintf(name, "tty.%u", i);
+ init_tty(tty, name, VADDR + i * TTY_VRAM_SIZE);
- monitor_tty.fg_color = TTY_FG_HIGHLIGHT | TTY_WHITE;
- monitor_tty.bg_color = TTY_BLUE;
+ if (i != TTY_WHITE) {
+ tty->fg_color = TTY_FG_HIGHLIGHT | TTY_WHITE;
+ tty->bg_color = i;
+ } else {
+ tty->fg_color = TTY_FG_HIGHLIGHT | TTY_BLACK;
+ tty->bg_color = TTY_WHITE;
+ }
+ }
- debug_tty.fg_color = TTY_FG_HIGHLIGHT | TTY_WHITE;
- debug_tty.bg_color = TTY_CYAN;
+ default_tty->fg_color = TTY_FG_HIGHLIGHT | TTY_GREEN;
+ default_tty->bg_color = TTY_BLACK;
- tty_clear(&monitor_tty);
- tty_clear(&debug_tty);
+ monitor_tty->fg_color = TTY_FG_HIGHLIGHT | TTY_WHITE;
+ monitor_tty->bg_color = TTY_BLUE;
- current_tty = &default_tty;
+ debug_tty->fg_color = TTY_FG_HIGHLIGHT | TTY_WHITE;
+ debug_tty->bg_color = TTY_BLACK; // TTY_CYAN;
+
+ for (int i = 0; i < NR_TTYS; i++) {
+ tty_t *tty = ttys + i;
+ tty_clear(tty);
+ }
+ current_tty = default_tty;
}
void tty_do_scroll_up(tty_t *tty) {
tty_set_cursor(current_tty);
}
+void tty_switch_to_next() {
+ tty_t *tty = ttys + ((current_tty - ttys + 1) % NR_TTYS);
+ tty_switch(tty);
+}
+
tty_t *current_tty;