static void cga_putc(int c) { // each screen character is represented by 2 bytes; the layout of // bits is presented below: // ----------------------------------------------------------------- // | attribute | character | // |-------------------------------+-------------------------------| // | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 | // |---+-----------+---------------+-------------------------------| // | b | backgrnd | foreground | code point | // ----------------------------------------------------------------- // where "b" stands for blink bit; if (!(c & ~0xFF)) c |= 0x0700; switch (c & 0xff) { case '\b': if (crt_pos > 0) { crt_pos--; crt_buf[crt_pos] = (c & ~0xff) | ' '; } break; case '\n': crt_pos += CRT_COLS; /* fallthru */ case '\r': crt_pos -= (crt_pos % CRT_COLS); break; case '\t': cons_putc(' '); cons_putc(' '); cons_putc(' '); cons_putc(' '); cons_putc(' '); break; default: crt_buf[crt_pos++] = c; /* write the character */ break; } // What is the purpose of this? if (crt_pos >= CRT_SIZE) { int i; memmove(crt_buf, crt_buf + CRT_COLS, (CRT_SIZE - CRT_COLS) * sizeof(uint16_t)); for (i = CRT_SIZE - CRT_COLS; i < CRT_SIZE; i++) crt_buf[i] = 0x0700 | ' '; crt_pos -= CRT_COLS; } /* move that little blinky thing */ outb(addr_6845, 14); outb(addr_6845 + 1, crt_pos >> 8); outb(addr_6845, 15); outb(addr_6845 + 1, crt_pos); }
// Print to the console. only understands %d, %x, %p, %s. void cprintf(char *fmt, ...) { int i, c, state, locking; uint *argp; char *s; locking = use_console_lock; if(locking) acquire(&console_lock); argp = (uint*)(void*)&fmt + 1; state = 0; for(i = 0; fmt[i]; i++) { c = fmt[i] & 0xff; switch(state) { case 0: if(c == '%') state = '%'; else cons_putc(c); break; case '%': switch(c) { case 'd': printint(*argp++, 10, 1); break; case 'x': case 'p': printint(*argp++, 16, 0); break; case 's': s = (char*)*argp++; if(s == 0) s = "(null)"; for(; *s; s++) cons_putc(*s); break; case '%': cons_putc('%'); break; default: // Print unknown % sequence to draw attention. cons_putc('%'); cons_putc(c); break; } state = 0; break; } } if(locking) release(&console_lock); }
static void cga_putc(int c) { // set user_setcolor c |= (user_setcolor << 8); // if no attribute given, then use black on white if (!(c & ~0xFF)) c |= 0x0700; switch (c & 0xff) { case '\b': if (crt_pos > 0) { crt_pos--; crt_buf[crt_pos] = (c & ~0xff) | ' '; } break; case '\n': crt_pos += CRT_COLS; /* fallthru */ case '\r': crt_pos -= (crt_pos % CRT_COLS); break; case '\t': cons_putc(' '); cons_putc(' '); cons_putc(' '); cons_putc(' '); cons_putc(' '); break; default: crt_buf[crt_pos++] = c; /* write the character */ break; } // What is the purpose of this? // out of cols, need to remove the top crt_buf if (crt_pos >= CRT_SIZE) { int i; memmove(crt_buf, crt_buf + CRT_COLS, (CRT_SIZE - CRT_COLS) * sizeof(uint16_t)); for (i = CRT_SIZE - CRT_COLS; i < CRT_SIZE; i++) crt_buf[i] = 0x0700 | ' '; crt_pos -= CRT_COLS; } /* move that little blinky thing */ outb(addr_6845, 14); outb(addr_6845 + 1, crt_pos >> 8); outb(addr_6845, 15); outb(addr_6845 + 1, crt_pos); }
void cga_putc(int c) { // if no attribute given, then use black on white if (!(c & ~0xFF)) c |= 0x0700; switch (c & 0xff) { case '\b': if (crt_pos > 0) { crt_pos--; crt_buf[crt_pos] = (c & ~0xff) | ' '; } break; case '\n': crt_pos += CRT_COLS; /* fallthru */ case '\r': crt_pos -= (crt_pos % CRT_COLS); break; case '\t': cons_putc(' '); cons_putc(' '); cons_putc(' '); cons_putc(' '); cons_putc(' '); break; default: crt_buf[crt_pos++] = c; /* write the character */ break; } // when the cft_pos is a bit larger than the CRT_SIZE // we need to cut the first line of the screen and scroll one line if (crt_pos >= CRT_SIZE) { int i; //copy the entire crt_buf to a higher position memmove(crt_buf, crt_buf + CRT_COLS, (CRT_SIZE - CRT_COLS) * sizeof(uint16_t)); //clear current line //otherwise the current line will be positioned with duplicate last line for (i = CRT_SIZE - CRT_COLS; i < CRT_SIZE; i++) crt_buf[i] = 0x0700 | ' '; //reset the current position crt_pos -= CRT_COLS; } /* move that little blinky thing */ outb(addr_6845, 14); outb(addr_6845 + 1, crt_pos >> 8); outb(addr_6845, 15); outb(addr_6845 + 1, crt_pos); }
static void cga_putc(int c) { // if no attribute given, then use black on white if (!(c & ~0xFF)) c |= 0x0700; // Most significant nibble is for background color and the next one is for text or foreground color switch (c & 0xff) { case '\b': if (crt_pos > 0) { crt_pos--; crt_buf[crt_pos] = (c & ~0xff) | ' '; } break; case '\n': crt_pos += CRT_COLS; /* fallthru */ case '\r': crt_pos -= (crt_pos % CRT_COLS); break; case '\t': cons_putc(' '); cons_putc(' '); cons_putc(' '); cons_putc(' '); cons_putc(' '); break; default: crt_buf[crt_pos++] = c; /* write the character */ break; } // What is the purpose of this? if (crt_pos >= CRT_SIZE) { int i; memmove(crt_buf, crt_buf + CRT_COLS, (CRT_SIZE - CRT_COLS) * sizeof(uint16_t)); for (i = CRT_SIZE - CRT_COLS; i < CRT_SIZE; i++) crt_buf[i] = 0x0700 | ' '; crt_pos -= CRT_COLS; } /* move that little blinky thing */ outb(addr_6845, 14); outb(addr_6845 + 1, crt_pos >> 8); outb(addr_6845, 15); outb(addr_6845 + 1, crt_pos); }
/*cprintfのための関数*/ static void printint (int xx, int base, int sign) { static char digits[] = "0123456789abcdef"; char buf[16]; int i; uint x; if (sign && (sign = xx < 0)) { x = -xx; } else { x = xx; } i = 0; do { buf[i++] = digits[x % base]; } while ((x /= base) != 0); if (sign) { buf[i++] = '-'; } while (--i >= 0) { cons_putc(buf[i]); } }
void radio_received(__xdata uint8_t *inpkt) { uint16_t i; if ( inpkt[1]==0xFD && inpkt[2] == cmd[2] && inpkt[2] == cmd[2] && inpkt[2] == cmd[2] ) { rf_ack=1; } if ( inpkt[1]==0xFD && inpkt[2] == 3 ) { for (i=0;i<64;i++) rambuf[i+inpkt[4]*64]=inpkt[i+5]; } else if (inpkt[1]==0xFD && inpkt[2]==0x10) { cons_putc('W'); } else { /* cons_puthex8(count >> 8); cons_puthex8(count & 0xFF); cons_puts(": "); for (i=0;i<inpkt[0]+1;i++) cons_puthex8(inpkt[i]); cons_puts("\r\n"); */ } count++; }
// Synchronize the root process's console special files // with the actual console I/O device. bool cons_io(void) { int num_io = 0; // Get output file fileinode *fi = &files->fi[FILEINO_CONSOUT]; int c; // spinlock_acquire(&cons_lock); while(cons_out_pos < fi->size) { c = ((char*)FILEDATA(FILEINO_CONSOUT))[cons_out_pos]; cons_putc(c); num_io++; cons_out_pos++; } // spinlock_release(&cons_lock); // Input file fi = &files->fi[FILEINO_CONSIN]; // Read from console while(fi->size <= FILE_MAXSIZE && (c = cons_getc())) { // And appened to CONSIN ((char*)FILEDATA(FILEINO_CONSIN))[fi->size++] = c; num_io++; } return num_io; }
// `High'-level console I/O. Used by readline and cprintf. void cputs(const char *str) { char ch; while (*str) cons_putc(*str++); }
void puts(const char *s) { /* use console api * _cputs(s); */ for (;*s != 0 ; s++) cons_putc(*s); }
static int stdout_io(struct device *dev, struct iobuf *iob, bool write) { if (write) { char *data = iob->io_base; for (; iob->io_resid != 0; iob->io_resid--) { cons_putc(*data++); } return 0; } return -E_INVAL; }
void clear_screen( void ) { curr_col = 0; curr_row = 0; int i; for (i = 0; i < VRAM_SIZE; i++) cons_putc(' '); curr_col = 0; curr_row = 0; }
void bootmain(void) { int i; for(i=0;i<25;i++) cons_putc(message[i]); for(;;) { } }
void console_intr(int (*getc)(void)) { int c; acquire(&input.lock); while((c = getc()) >= 0) { switch(c) { case C('P'): // Process listing. procdump(); break; case C('U'): // Kill line. while(input.e != input.w && input.buf[(input.e-1) % INPUT_BUF] != '\n') { input.e--; cons_putc(BACKSPACE); } break; case C('H'): // Backspace if(input.e != input.w) { input.e--; cons_putc(BACKSPACE); } break; default: if(c != 0 && input.e-input.r < INPUT_BUF) { input.buf[input.e++ % INPUT_BUF] = c; cons_putc(c); if(c == '\n' || c == C('D') || input.e == input.r+INPUT_BUF) { input.w = input.e; wakeup(&input.r); } } break; } } release(&input.lock); }
int console_write(struct inode *ip, char *buf, int n) { int i; iunlock(ip); acquire(&console_lock); for(i = 0; i < n; i++) cons_putc(buf[i] & 0xff); release(&console_lock); ilock(ip); return n; }
/* bootmain - the entry of bootloader */ void bootmain(void) { // read the 1st page off disk readseg((uintptr_t)ELFHDR, SECTSIZE * 8, 0); // is this a valid ELF? if (ELFHDR->e_magic != ELF_MAGIC) { goto bad; } cons_putc('B'); /* do nothing */ while (1); bad: cons_putc('E'); outw(0x8A00, 0x8A00); outw(0x8A00, 0x8E00); /* do nothing */ while (1); }
// `High'-level console I/O. Used by readline and cprintf. void cputs(const char *str) { if (read_cs() & 3) return sys_cputs(str); // use syscall from user mode // Hold the console spinlock while printing the entire string, // so that the output of different cputs calls won't get mixed. // Implement ad hoc recursive locking for debugging convenience. bool already = spinlock_holding(&cons_lock); if (!already) spinlock_acquire(&cons_lock); char ch; while (*str) cons_putc(*str++); if (!already) spinlock_release(&cons_lock); }
// Place a character on next screen position static void cons_putc(int c) { switch (c) { case '\t': do { cons_putc(' '); } while ((curr_col % 8) != 0); break; case '\r': curr_col = 0; break; case '\n': curr_row += 1; if (curr_row >= MAX_ROW) { curr_row = 0; } break; case '\b': if (curr_col > 0) { curr_col -= 1; PUT(' '); } break; default: PUT(c); curr_col += 1; if (curr_col >= MAX_COL) { curr_col = 0; curr_row += 1; if (curr_row >= MAX_ROW) { curr_row = 0; } } }; }
uint8_t radio_cmd (void) { uint16_t delay_count=0; uint8_t retry=10; rf_ack=0; while (retry && !rf_ack) { if (delay_count==0) { radio_tx(cmd); //cons_puts("Sending cmd\r\n"); delay_count=5000; retry--; } delay_count--; radio_tick(); } if (retry) { return 1; } else { cons_putc(1); return 0; } }
void printint(int xx, int base, int sgn) { static char digits[] = "0123456789ABCDEF"; char buf[16]; int i = 0, neg = 0; uint x; if(sgn && xx < 0) { neg = 1; x = 0 - xx; } else { x = xx; } do { buf[i++] = digits[x % base]; } while((x /= base) != 0); if(neg) buf[i++] = '-'; while(--i >= 0) cons_putc(buf[i]); }
/* * * cputch - writes a single character @c to stdout, and it will * increace the value of counter pointed by @cnt. * */ static void cputch(int c, int *cnt, int fd) { cons_putc(c); (*cnt)++; }
void cons_puts(const char *s) { while(0 != *s) cons_putc((uint8_t )(*s++)); }
void app_tick(void) { uint8_t ch,data; uint8_t page,seg; uint16_t c,d; if (cons_getch(&ch)) { switch (ch) { case 'e': while (!cons_getch(&page)); cmd[0]=4; cmd[1]=0xFE; cmd[2]=1; cmd[3]=page&0x1F; cmd[4]=0; if (radio_cmd()) goto ack; break; case 'p': while (!cons_getch(&page)); cmd[0]=4; cmd[1]=0xFE; cmd[2]=2; cmd[3]=page&0x1F; cmd[4]=0; if (radio_cmd()) goto ack; break; case 'r': while (!cons_getch(&page)); for (seg=0;seg<16;seg++) { cmd[0]=4; cmd[1]=0xFE; cmd[2]=3; cmd[3]=page&0x1F; cmd[4]=seg&0x0F; if (!radio_cmd()) break; } for (c=0;c<1024;c++) { cons_putc(rambuf[c]); //cons_puthex8(rambuf[c]); } goto ack; break; case 'l': for (c=0;c<1024;c++) { while (!cons_getch(&data)); rambuf[c]=data; //cons_puthex8(data); } c=0; for (seg=0;seg<16;seg++) { cmd[0]=68; cmd[1]=0xFE; cmd[2]=4; cmd[3]=0; cmd[4]=seg&0x0F; for (d=5;d<69;d++) { cmd[d]=rambuf[c++]; } if (!radio_cmd()) break; } goto ack; break; case 'j': cmd[0]=2; cmd[1]=0xFE; cmd[2]=5; if (radio_cmd()) goto ack; break; case 0: cmd[0]=4; cmd[1]=0xFE; cmd[2]=0; cmd[3]=0; cmd[4]=0; radio_cmd(); break; ack: cons_putc(0); //cons_puts("ACK\r\n"); } } }
void putchar( int c ) { if (c == '\n') cons_putc('\r'); cons_putc(c); }
void app_tick(void) { uint8_t ch; if (cons_getch(&ch)) cons_putc(ch); }
/* // Print to the console. only understands %d, %x, %p, %s. */ void cprintf (char *fmt, ...) { int i, c, locking; uint *argp; char *s; locking = cons.locking; if (locking) { acquire(&cons.lock); } if (fmt == 0) { panic("null fmt"); } argp = (uint*) (void*) (&fmt + 1); for (i = 0; (c = fmt[i] & 0xff) != 0; i++) { if (c != '%') { cons_putc(c); continue; } c = fmt[++i] & 0xff; if (c == 0) { break; } switch (c) { case 'd': printint(*argp++, 10, 1); break; case 'x': case 'p': printint(*argp++, 16, 0); break; case 's': if ((s = (char*) *argp++) == 0) { s = "(null)"; } for (; *s; s++) { cons_putc(*s); } break; case '%': cons_putc('%'); break; default: // Print unknown % sequence to draw attention. cons_putc('%'); cons_putc(c); break; } } if (locking) { release(&cons.lock); } }
static uint32_t sys_putc(uint32_t arg[]) { int c = (int)arg[0]; cons_putc(c); return 0; }
static void cga_putc(int c) { #if CRT_SAVEROWS > 0 // unscroll if necessary if (crtsave_backscroll > 0) { cga_savebuf_copy(crtsave_pos + crtsave_size, 1); crtsave_backscroll = 0; } #endif // if no attribute given, then use light gray on black if (!(c & ~0xFF)) c |= 0x0700; switch (c & 0xff) { case '\b': if (crt_pos > 0) { crt_pos--; crt_buf[crt_pos] = (c & ~0xff) | ' '; } break; case '\n': crt_pos += CRT_COLS; /* fallthru */ case '\r': crt_pos -= (crt_pos % CRT_COLS); break; case '\t': cons_putc(' '); cons_putc(' '); cons_putc(' '); cons_putc(' '); cons_putc(' '); break; default: crt_buf[crt_pos++] = c; /* write the character */ break; } // What is the purpose of this? if (crt_pos >= CRT_SIZE) { int i; #if CRT_SAVEROWS > 0 // Save the scrolled-back row if (crtsave_size == CRT_SAVEROWS - CRT_ROWS) crtsave_pos = (crtsave_pos + 1) % CRT_SAVEROWS; else crtsave_size++; memcpy(crtsave_buf + ((crtsave_pos + crtsave_size - 1) % CRT_SAVEROWS) * CRT_COLS, crt_buf, CRT_COLS * sizeof(uint16_t)); #endif memcpy(crt_buf, crt_buf + CRT_COLS, (CRT_SIZE - CRT_COLS) * sizeof(uint16_t)); for (i = CRT_SIZE - CRT_COLS; i < CRT_SIZE; i++) crt_buf[i] = 0x0700 | ' '; crt_pos -= CRT_COLS; } /* move that little blinky thing */ outb(addr_6845, 14); outb(addr_6845 + 1, crt_pos >> 8); outb(addr_6845, 15); outb(addr_6845 + 1, crt_pos); }
void cputchar(int c) { cons_putc(c); }
void putchar(char c) { cons_putc(c); }