Changeset 3604
- Timestamp:
- 09/26/08 20:36:26 (3 months ago)
- Location:
- trunk/payloads/libpayload
- Files:
-
- 5 modified
-
curses/keyboard.c (modified) (4 diffs)
-
curses/tinycurses.c (modified) (16 diffs)
-
drivers/serial.c (modified) (4 diffs)
-
include/curses.h (modified) (1 diff)
-
include/libpayload.h (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/payloads/libpayload/curses/keyboard.c
r3580 r3604 45 45 /* ============== Serial ==================== */ 46 46 47 #ifdef CONFIG_SERIAL_CONSOLE 47 48 /* We treat serial like a vt100 terminal. For now we 48 49 do the cooking in here, but we should probably eventually … … 136 137 } 137 138 } 139 #endif 138 140 139 141 /* ================ Keyboard ================ */ … … 216 218 curses_flags &= ~F_ENABLE_CONSOLE; 217 219 } 220 221 int curses_vga_enabled(void) 222 { 223 return (curses_flags & F_ENABLE_CONSOLE) != 0; 224 } 218 225 #else 219 226 void curses_enable_vga(int state) { } 227 int curses_vga_enabled(void) { return 0; } 220 228 #endif 221 229 … … 228 236 curses_flags &= ~F_ENABLE_SERIAL; 229 237 } 238 239 int curses_serial_enabled(void) 240 { 241 return (curses_flags & F_ENABLE_SERIAL) != 0; 242 } 243 230 244 #else 231 245 void curses_enable_serial(int state) { } 232 #endif 233 246 int curses_serial_enabled(void) { return 0; } 247 #endif 248 -
trunk/payloads/libpayload/curses/tinycurses.c
r3598 r3604 78 78 /* Globals */ 79 79 int COLORS; /* Currently unused? */ 80 int COLOR_PAIRS ;80 int COLOR_PAIRS = 255; 81 81 WINDOW *stdscr; 82 82 WINDOW *curscr; … … 112 112 }; 113 113 114 #ifdef CONFIG_SERIAL_CONSOLE 114 115 #ifdef CONFIG_SERIAL_ACS_FALLBACK 115 116 chtype serial_acs_map[128]; … … 136 137 }; 137 138 #endif 138 139 #endif 140 141 #ifdef CONFIG_VIDEO_CONSOLE 139 142 /* See acsc of linux. */ 140 143 chtype console_acs_map[128] = … … 157 160 '\263', '\363', '\362', '\343', '\330', '\234', '\376', 0, 158 161 }; 162 #endif 159 163 160 164 // FIXME: Ugly (and insecure!) hack! … … 197 201 int curs_set(int on) 198 202 { 203 #ifdef CONFIG_SERIAL_CONSOLE 199 204 if (curses_flags & F_ENABLE_SERIAL) { 200 // TODO 201 } 202 205 serial_cursor_enable(on); 206 } 207 #endif 208 #ifdef CONFIG_VIDEO_CONSOLE 203 209 if (curses_flags & F_ENABLE_CONSOLE) { 204 210 video_console_cursor_enable(on); 205 211 } 212 #endif 206 213 207 214 return OK; … … 285 292 int flushinp(void) { /* TODO */ return 0; } 286 293 // WINDOW *getwin (FILE *) {} 287 bool has_colors (void) { /* TODO */ return(*(bool *)0); }294 bool has_colors (void) { return(TRUE); } 288 295 // bool has_ic (void) {} 289 296 // bool has_il (void) {} … … 301 308 for (i = 0; i < 128; i++) 302 309 acs_map[i] = (chtype) i | A_ALTCHARSET; 303 310 #ifdef CONFIG_SERIAL_CONSOLE 304 311 if (curses_flags & F_ENABLE_SERIAL) { 305 312 serial_clear(); 306 313 } 307 314 #endif 315 #ifdef CONFIG_VIDEO_CONSOLE 308 316 if (curses_flags & F_ENABLE_CONSOLE) { 309 317 /* Clear the screen and kill the cursor */ … … 312 320 video_console_cursor_enable(0); 313 321 } 322 #endif 314 323 315 324 // Speaker init? 316 325 317 stdscr = newwin(SCREEN_Y, SCREEN_X , 0, 0);326 stdscr = newwin(SCREEN_Y, SCREEN_X + 1, 0, 0); 318 327 // TODO: curscr, newscr? 319 328 … … 694 703 int wnoutrefresh(WINDOW *win) 695 704 { 705 #ifdef CONFIG_SERIAL_CONSOLE 696 706 // FIXME. 697 707 int serial_is_bold = 0; 708 int serial_is_reverse = 0; 698 709 int serial_is_altcharset = 0; 699 710 int serial_cur_pair = 0; 700 711 712 int need_altcharset; 713 short fg, bg; 714 #endif 701 715 int x, y; 702 716 chtype ch; 703 int need_altcharset; 704 short fg, bg; 705 717 718 #ifdef CONFIG_SERIAL_CONSOLE 706 719 serial_end_bold(); 707 720 serial_end_altcharset(); 721 #endif 708 722 709 723 for (y = 0; y <= win->_maxy; y++) { … … 714 728 /* Position the serial cursor */ 715 729 730 #ifdef CONFIG_SERIAL_CONSOLE 716 731 if (curses_flags & F_ENABLE_SERIAL) 717 732 serial_set_cursor(win->_begy + y, win->_begx + 718 733 win->_line[y].firstchar); 734 #endif 719 735 720 736 for (x = win->_line[y].firstchar; x <= win->_line[y].lastchar; x++) { … … 724 740 ((int)color_pairs[PAIR_NUMBER(attr)]) << 8; 725 741 742 #ifdef CONFIG_SERIAL_CONSOLE 726 743 if (curses_flags & F_ENABLE_SERIAL) { 727 744 ch = win->_line[y].text[x].chars[0]; … … 732 749 serial_is_bold = 1; 733 750 } 734 } 735 else { 751 } else { 736 752 if (serial_is_bold) { 737 753 serial_end_bold(); 754 serial_is_bold = 0; 755 /* work around serial.c 756 * shortcoming: 757 */ 758 serial_is_reverse = 0; 759 serial_cur_pair = 0; 760 } 761 } 762 763 if (attr & A_REVERSE) { 764 if (!serial_is_reverse) { 765 serial_start_reverse(); 766 serial_is_reverse = 1; 767 } 768 } else { 769 if (serial_is_reverse) { 770 serial_end_reverse(); 771 serial_is_reverse = 0; 772 /* work around serial.c 773 * shortcoming: 774 */ 738 775 serial_is_bold = 0; 739 776 serial_cur_pair = 0; … … 768 805 769 806 } 770 807 #endif 808 #ifdef CONFIG_VIDEO_CONSOLE 771 809 c = SWAP_RED_BLUE(c); 772 810 … … 800 838 video_console_putc(win->_begy + y, win->_begx + x, c); 801 839 } 840 #endif 802 841 } 803 842 win->_line[y].firstchar = _NOCHANGE; … … 805 844 } 806 845 846 #ifdef CONFIG_SERIAL_CONSOLE 807 847 if (curses_flags & F_ENABLE_SERIAL) 808 848 serial_set_cursor(win->_begy + win->_cury, win->_begx + win->_curx); 809 849 #endif 850 851 #ifdef CONFIG_VIDEO_CONSOLE 810 852 if (curses_flags & F_ENABLE_CONSOLE) 811 853 video_console_set_cursor(win->_begx + win->_curx, win->_begy + win->_cury); 854 #endif 812 855 813 856 return OK; … … 824 867 return code; 825 868 } 826 // int wredrawln (WINDOW *,int,int) {} 869 870 int wredrawln (WINDOW *win, int beg_line, int num_lines) 871 { 872 int i; 873 874 for (i = beg_line; i < beg_line + num_lines; i++) { 875 win->_line[i].firstchar = 0; 876 win->_line[i].lastchar = win->_maxx; 877 } 878 879 return OK; 880 } 881 827 882 int wrefresh(WINDOW *win) 828 883 { -
trunk/payloads/libpayload/drivers/serial.c
r3565 r3604 33 33 34 34 #define IOBASE lib_sysinfo.ser_ioport 35 #define DIVISOR(x) (115200 / x) 35 36 36 #ifdef CONFIG_SERIAL_SET_SPEED 37 #define DIVISOR (115200 / CONFIG_SERIAL_BAUD_RATE) 38 #endif 37 void serial_hardware_init(int port, int speed, int word_bits, int parity, int stop_bits) 38 { 39 unsigned char reg; 40 41 /* We will assume 8n1 for now. Does anyone use anything else these days? */ 42 43 /* Disable interrupts. */ 44 outb(0, port + 0x01); 45 46 /* Assert RTS and DTR. */ 47 outb(3, port + 0x04); 48 49 /* Set the divisor latch. */ 50 reg = inb(port + 0x03); 51 outb(reg | 0x80, port + 0x03); 52 53 /* Write the divisor. */ 54 outb(DIVISOR(speed) & 0xFF, port); 55 outb(DIVISOR(speed) >> 8 & 0xFF, port + 1); 56 57 /* Restore the previous value of the divisor. */ 58 outb(reg &= ~0x80, port + 0x03); 59 } 39 60 40 61 void serial_init(void) 41 62 { 42 63 #ifdef CONFIG_SERIAL_SET_SPEED 43 unsigned char reg; 44 45 /* Disable interrupts. */ 46 outb(0, IOBASE + 0x01); 47 48 /* Assert RTS and DTR. */ 49 outb(3, IOBASE + 0x04); 50 51 /* Set the divisor latch. */ 52 reg = inb(IOBASE + 0x03); 53 outb(reg | 0x80, IOBASE + 0x03); 54 55 /* Write the divisor. */ 56 outb(DIVISOR & 0xFF, IOBASE); 57 outb(DIVISOR >> 8 & 0xFF, IOBASE + 1); 58 59 /* Restore the previous value of the divisor. */ 60 outb(reg &= ~0x80, IOBASE + 0x03); 64 serial_hardware_init(IOBASE, CONFIG_SERIAL_BAUD_RATE, 8, 0, 1); 61 65 #endif 62 66 } … … 82 86 83 87 #define VT100_CLEAR "\e[H\e[J" 88 /* These defines will fail if you use bold and reverse at the same time. 89 * Switching off one of them will switch off both. tinycurses knows about 90 * this and does the right thing. 91 */ 84 92 #define VT100_SBOLD "\e[1m" 85 93 #define VT100_EBOLD "\e[m" 94 #define VT100_SREVERSE "\e[7m" 95 #define VT100_EREVERSE "\e[m" 86 96 #define VT100_CURSOR_ADDR "\e[%d;%dH" 97 #define VT100_CURSOR_ON "\e[?25l" 98 #define VT100_CURSOR_OFF "\e[?25h" 87 99 /* The following smacs/rmacs are actually for xterm; a real vt100 has 88 100 enacs=\E(B\E)0, smacs=^N, rmacs=^O. */ … … 111 123 { 112 124 serial_putcmd(VT100_EBOLD); 125 } 126 127 void serial_start_reverse(void) 128 { 129 serial_putcmd(VT100_SREVERSE); 130 } 131 132 void serial_end_reverse(void) 133 { 134 serial_putcmd(VT100_EREVERSE); 113 135 } 114 136 … … 142 164 serial_putcmd(buffer); 143 165 } 166 167 void serial_cursor_enable(int state) 168 { 169 if (state) 170 serial_putcmd(VT100_CURSOR_ON); 171 else 172 serial_putcmd(VT100_CURSOR_OFF); 173 } -
trunk/payloads/libpayload/include/curses.h
r3234 r3604 1674 1674 void curses_enable_serial(int); 1675 1675 1676 int curses_vga_enabled(void); 1677 int curses_serial_enabled(void); 1678 1676 1679 #endif /* _CURSES_H */ -
trunk/payloads/libpayload/include/libpayload.h
r3561 r3604 132 132 */ 133 133 void serial_init(void); 134 void serial_hardware_init(int port, int speed, int word_bits, int parity, int stop_bits); 134 135 void serial_putchar(unsigned char c); 135 136 int serial_havechar(void); … … 138 139 void serial_start_bold(void); 139 140 void serial_end_bold(void); 141 void serial_start_reverse(void); 142 void serial_end_reverse(void); 140 143 void serial_start_altcharset(void); 141 144 void serial_end_altcharset(void); 142 145 void serial_set_color(short fg, short bg); 146 void serial_cursor_enable(int state); 143 147 void serial_set_cursor(int y, int x); 144 148 /** @} */
