3 * David Leonard <d@openbsd.org>, 1999. Public domain.
5 * $OpenBSD: display.c,v 1.4 2002/02/19 19:39:36 millert Exp $
6 * $DragonFly: src/games/hunt/hunt/display.c,v 1.2 2008/09/04 16:12:51 swildner Exp $
11 #include <sys/cdefs.h>
14 #if !defined(USE_CURSES)
21 #define _USE_OLD_CURSES_
26 static struct termios saved_tty;
28 char screen[SCREEN_HEIGHT][SCREEN_WIDTH2];
29 char blanks[SCREEN_WIDTH];
34 * Handle stop and start signals
43 mvcur(cur_row, cur_col, HEIGHT, 0);
48 (void) fflush(stdout);
49 tcsetattr(0, TCSADRAIN, &__orig_termios);
50 (void) kill(getpid(), SIGSTOP);
51 (void) signal(SIGTSTP, tstp);
52 tcsetattr(0, TCSADRAIN, &saved_tty);
57 _puts(tgoto(CM, cur_row, cur_col));
58 display_redraw_screen();
59 (void) fflush(stdout);
71 if (!isatty(0) || (term = getenv("TERM")) == NULL)
72 errx(1, "no terminal type");
78 tcgetattr(0, &saved_tty);
82 (void) signal(SIGTSTP, tstp);
101 display_refresh(void)
103 (void) fflush(stdout);
108 * clear to end of line, without moving cursor
111 display_clear_eol(void)
114 tputs(CE, 1, __cputchar);
116 fwrite(blanks, sizeof (char), SCREEN_WIDTH - cur_col, stdout);
117 if (COLS != SCREEN_WIDTH)
118 mvcur(cur_row, SCREEN_WIDTH, cur_row, cur_col);
120 mvcur(cur_row + 1, 0, cur_row, cur_col);
122 mvcur(cur_row, SCREEN_WIDTH - 1, cur_row, cur_col);
124 memcpy(&screen[cur_row][cur_col], blanks, SCREEN_WIDTH - cur_col);
129 * put one character on the screen, move the cursor right one,
133 display_put_ch(char ch)
136 fprintf(stderr, "r,c,ch: %d,%d,%d", cur_row, cur_col, ch);
139 screen[cur_row][cur_col] = ch;
141 if (++cur_col >= COLS) {
145 if (++cur_row >= LINES)
152 * put a string of characters on the screen
155 display_put_str(const char *s)
162 * display_clear_the_screen:
163 * clear the screen; move cursor to top left
166 display_clear_the_screen(void)
170 if (blanks[0] == '\0')
171 for (i = 0; i < SCREEN_WIDTH; i++)
175 tputs(CL, LINES, __cputchar);
176 for (i = 0; i < SCREEN_HEIGHT; i++)
177 memcpy(screen[i], blanks, SCREEN_WIDTH);
179 for (i = 0; i < SCREEN_HEIGHT; i++) {
180 mvcur(cur_row, cur_col, i, 0);
185 mvcur(cur_row, cur_col, 0, 0);
187 cur_row = cur_col = 0;
195 display_move(int y, int x)
197 mvcur(cur_row, cur_col, y, x);
207 display_getyx(int *yp, int *xp)
220 tcsetattr(0, TCSADRAIN, &__orig_termios);
227 * return a character from the screen
230 display_atyx(int y, int x)
236 * display_redraw_screen:
240 display_redraw_screen(void)
244 mvcur(cur_row, cur_col, 0, 0);
245 for (i = 0; i < SCREEN_HEIGHT - 1; i++) {
246 fwrite(screen[i], sizeof (char), SCREEN_WIDTH, stdout);
247 if (COLS > SCREEN_WIDTH || (COLS == SCREEN_WIDTH && !AM))
250 fwrite(screen[SCREEN_HEIGHT - 1], sizeof (char), SCREEN_WIDTH - 1,
252 mvcur(SCREEN_HEIGHT - 1, SCREEN_WIDTH - 1, cur_row, cur_col);
255 #else /* CURSES */ /* --------------------------------------------------- */
275 display_refresh(void)
281 display_clear_eol(void)
287 display_put_ch(char c)
293 display_put_str(const char *s)
299 display_clear_the_screen(void)
307 display_move(int y, int x)
313 display_getyx(int *yp, int *xp)
315 getyx(stdscr, *yp, *xp);
325 display_atyx(int y, int x)
330 display_getyx(&oy, &ox);
331 c = mvwinch(stdscr, y, x) & 0x7f;
332 display_move(oy, ox);
337 display_redraw_screen(void)
339 clearok(stdscr, TRUE);
344 display_iserasechar(char ch)
346 return ch == erasechar();
350 display_iskillchar(char ch)
352 return ch == killchar();