1 /******************************************************************************
2 * to emulate the serial input and output of an 8051 controller *
3 * frontend.cc - the ncurses frontend *
4 ******************************************************************************/
14 #include "frontend.hh"
18 /* initalise the output screen */
23 intrflush(stdscr,FALSE);
26 /* clear the screen and off you go */
29 // get the coordinates for the box
30 /* create the subwindow */
31 win_c.min_x = win_c.min_y = 0;
32 getmaxyx(stdscr, win_c.max_y, win_c.max_x);
34 /* define the boxed size */
35 topleft.x = win_c.min_x + 1;
36 bottomright.x = win_c.max_x - 2;
37 topleft.y = win_c.min_y + 1;
38 bottomright.y = win_c.max_y - 2;
39 middle_y = (int)((bottomright.y-topleft.y)/2)+1;
40 middle_x = (int)((bottomright.x-topleft.x)/2)+1;
42 // draw the two subwindows
43 inp_c.min_x = outp_c.min_x = topleft.x;
44 inp_c.max_x = outp_c.max_x = bottomright.x;
45 inp_c.min_y = topleft.y;
46 inp_c.max_y = middle_y-topleft.y;
47 outp_c.min_y = middle_y+1;
48 outp_c.max_y = bottomright.y-middle_y;
49 inp = subwin(stdscr, inp_c.max_y, inp_c.max_x, inp_c.min_y, inp_c.min_x);
50 outp = subwin(stdscr, outp_c.max_y, outp_c.max_x, outp_c.min_y,outp_c.min_x);
52 // initalise the windows
66 // flush the input buffers
69 move(topleft.x,topleft.y);
82 void Viewer::DrawBox(void)
87 // save the current position
88 getyx(stdscr, current.y, current.x);
90 height = (bottomright.y - topleft.y)+1;
91 width = (bottomright.x - topleft.y)+1;
93 mvaddch(topleft.y-1, topleft.x-1, ACS_ULCORNER);
94 mvaddch(topleft.y-1, bottomright.x+1, ACS_URCORNER);
95 mvaddch(bottomright.y+1, bottomright.x+1, ACS_LRCORNER);
96 mvaddch(bottomright.y+1, topleft.x-1, ACS_LLCORNER);
98 /* wmove (screen, y, x) */
100 move(topleft.y-1, topleft.x);
101 hline(ACS_HLINE, width);
103 move(bottomright.y+1, topleft.x);
104 hline(ACS_HLINE, width);
105 move(bottomright.y+1, topleft.x);
106 hline(ACS_HLINE, width);
109 move(topleft.y, topleft.x-1);
110 vline(ACS_VLINE, height);
113 move(topleft.y, bottomright.x+1);
114 vline(ACS_VLINE, height);
117 mvaddch(middle_y, bottomright.x+1, ACS_RTEE);
118 mvaddch(middle_y, topleft.x-1, ACS_LTEE);
119 hline(ACS_HLINE, width);
122 mvaddstr(inp_c.min_y-1, middle_x-(strlen("Input")/2), "Input");
123 mvaddstr(middle_y, middle_x-(strlen("Output")/2), "Output");
124 move(current.y, current.x);
128 void Viewer::AddStrOutWin(char *string)
130 waddstr(outp, string);
134 void Viewer::GetStrInWin(char *string)
136 if(wgetstr(inp, string) == ERR) {
139 waddstr(inp, string);
144 void Viewer::AddChOutWin(char b)
150 char Viewer::GetChInWin(void)
157 waddch(inp, (chtype)b);