Kevin Vigor's fix for Solaris
[fw/sdcc] / sim / ucsim / gui.src / a.cc
1 #include <curses.h>
2 #include <panel.h>
3
4 int sfr[4];
5 int port[4];
6
7 void
8 init_panel(PANEL *p)
9 {
10   int mask, x, y;
11   int na, ha;
12   int cursor= 2;
13   WINDOW *w= panel_window(p);
14   
15   if (has_colors())
16     {
17       na= COLOR_PAIR(1);
18       ha= COLOR_PAIR(2);
19     }
20   else
21     {
22       na= A_NORMAL;
23       ha= A_STANDOUT;
24     }
25   //wattron(w, COLOR_PAIR);
26   x= 0;
27   for (mask= 1, y= 0; mask < 0x100; mask<<= 1,y++)
28     {
29       wattrset(w, (y==cursor)?ha:na);
30       mvwprintw(w, y,x, "%s", (sfr[0]&mask)?"High":" Low");
31     }
32 }
33
34 wchar_t
35 wait_input(PANEL *p)
36 {
37   WINDOW *w= panel_window(p);
38   wchar_t c;
39
40   c= wgetch(w);
41   printw("%d 0x%x\n",c,c);
42   return(c);
43 }
44
45 int
46 main(int argc, char *argv[])
47 {
48   wchar_t c;
49
50   initscr();      /* initialize the curses library */
51   keypad(stdscr, TRUE);  /* enable keyboard mapping */
52   nonl();         /* tell curses not to do NL->CR/NL on output */
53   cbreak();       /* take input chars one at a time, no wait for \n */
54   noecho();       /* don't echo input */
55   if (has_colors())
56     {
57       start_color();
58       printw("has %d colors and %d pairs\n", COLORS, COLOR_PAIRS);
59       init_pair(1, COLOR_WHITE, COLOR_BLUE);
60       init_pair(2, COLOR_WHITE, COLOR_RED);
61     }
62
63   #ifdef NCURSES_VERSION
64   /* has_key is a ncurses specific function. */
65   if (has_key(KEY_UP))
66     printw("has UP KEY_UP=0x%x\n",KEY_UP);
67   else
68     printf("has no UP\n");
69   #endif
70   c= getch();
71   printw("got %d %x\n",c,c);
72
73   WINDOW *w= newwin(10,10, 3,3);
74   keypad(w, TRUE);
75   PANEL *p= new_panel(w);
76
77   sfr[0]= 0x5a;
78   init_panel(p);
79   update_panels();
80   doupdate();
81   c= wait_input(p);
82   //c= getch();
83
84   endwin();
85   if (c==KEY_UP)
86     printf("got UP\n");
87   else if (c==KEY_DOWN)
88     printf("got DOWN\n");
89   else
90     printf("got \"%d\"\n", c);
91 }