#define NB_COLS 80 #define NB_ROWS 25 #define BPC 2 #define BPR (BPC * NB_COLS) #define VIDEO_BUFFER 0xB8000 /* XXX doest not always handle memory overlaps */ static void my_memmove(void *_dest, const void *_src, int n) { char *dest = _dest; const char *src = _src; for (int i = 0; i < n; ++i) { dest[i] = src[i]; } } static void my_memset(void *_dest, int c, int n) { char *dest = _dest; for (int i = 0; i < n; ++i) { dest[i] = c; } } static void clear_line(void *_addr) { char *addr = _addr; for (int i = 0; i < NB_COLS; ++i) { if (i % BPC == 0) { *addr++ = ' '; } else { *addr++ = 0x7; } } } int printk(const char *str) { static const long int offset = VIDEO_BUFFER; static char *addr = (char *) VIDEO_BUFFER; int count = 0; for (int i = 0; str[i]; ++i) { /* TODO add the serial port handling */ char chr; char *new_addr = addr; char *addr_line = (char *)(((long)(addr - offset) / BPR) * BPR) + offset; if ((long)addr >= offset + NB_ROWS * BPR) { /* shift up */ addr -= BPR; addr_line -= BPR; my_memmove((void *)offset, (void *)offset + BPR, BPR * (NB_ROWS - 1)); clear_line(addr_line); } switch (str[i]) { case '\n': new_addr = addr_line + BPR; chr = '\0'; break; default: new_addr = addr + BPC; chr = str[i]; break; } if (chr) *addr = chr; addr = new_addr; ++count; } return count; } int main(void) { }