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.1 2008/09/02 21:50:20 dillon 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
44 mvcur(cur_row, cur_col, HEIGHT, 0);
49 (void) fflush(stdout);
50 tcsetattr(0, TCSADRAIN, &__orig_termios);
51 (void) kill(getpid(), SIGSTOP);
52 (void) signal(SIGTSTP, tstp);
53 tcsetattr(0, TCSADRAIN, &saved_tty);
58 _puts(tgoto(CM, cur_row, cur_col));
59 display_redraw_screen();
60 (void) fflush(stdout);
72 if (!isatty(0) || (term = getenv("TERM")) == NULL)
73 errx(1, "no terminal type");
79 tcgetattr(0, &saved_tty);
83 (void) signal(SIGTSTP, tstp);
104 (void) fflush(stdout);
109 * clear to end of line, without moving cursor
115 tputs(CE, 1, __cputchar);
117 fwrite(blanks, sizeof (char), SCREEN_WIDTH - cur_col, stdout);
118 if (COLS != SCREEN_WIDTH)
119 mvcur(cur_row, SCREEN_WIDTH, cur_row, cur_col);
121 mvcur(cur_row + 1, 0, cur_row, cur_col);
123 mvcur(cur_row, SCREEN_WIDTH - 1, cur_row, cur_col);
125 memcpy(&screen[cur_row][cur_col], blanks, SCREEN_WIDTH - cur_col);
130 * put one character on the screen, move the cursor right one,
138 fprintf(stderr, "r,c,ch: %d,%d,%d", cur_row, cur_col, ch);
141 screen[cur_row][cur_col] = ch;
143 if (++cur_col >= COLS) {
147 if (++cur_row >= LINES)
154 * put a string of characters on the screen
157 display_put_str(const char *s)
164 * display_clear_the_screen:
165 * clear the screen; move cursor to top left
168 display_clear_the_screen()
172 if (blanks[0] == '\0')
173 for (i = 0; i < SCREEN_WIDTH; i++)
177 tputs(CL, LINES, __cputchar);
178 for (i = 0; i < SCREEN_HEIGHT; i++)
179 memcpy(screen[i], blanks, SCREEN_WIDTH);
181 for (i = 0; i < SCREEN_HEIGHT; i++) {
182 mvcur(cur_row, cur_col, i, 0);
187 mvcur(cur_row, cur_col, 0, 0);
189 cur_row = cur_col = 0;
200 mvcur(cur_row, cur_col, y, x);
210 display_getyx(yp, xp)
224 tcsetattr(0, TCSADRAIN, &__orig_termios);
231 * return a character from the screen
241 * display_redraw_screen:
245 display_redraw_screen()
249 mvcur(cur_row, cur_col, 0, 0);
250 for (i = 0; i < SCREEN_HEIGHT - 1; i++) {
251 fwrite(screen[i], sizeof (char), SCREEN_WIDTH, stdout);
252 if (COLS > SCREEN_WIDTH || (COLS == SCREEN_WIDTH && !AM))
255 fwrite(screen[SCREEN_HEIGHT - 1], sizeof (char), SCREEN_WIDTH - 1,
257 mvcur(SCREEN_HEIGHT - 1, SCREEN_WIDTH - 1, cur_row, cur_col);
260 #else /* CURSES */ /* --------------------------------------------------- */
299 display_put_str(const char *s)
305 display_clear_the_screen()
320 display_getyx(yp, xp)
323 getyx(stdscr, *yp, *xp);
339 display_getyx(&oy, &ox);
340 c = mvwinch(stdscr, y, x) & 0x7f;
341 display_move(oy, ox);
346 display_redraw_screen()
348 clearok(stdscr, TRUE);
353 display_iserasechar(ch)
356 return ch == erasechar();
360 display_iskillchar(ch)
363 return ch == killchar();