OSDN Git Service

[Refacotr] #37353 使われていないプリプロUSE_TERMIOを部分的に削除 / Removed unused preprocessors USE_TER...
[hengband/hengband.git] / src / main-cap.c
1 /* File: main-cap.c */
2
3 /* Purpose: Support for "term.c" using "termcap" calls */
4
5 #include "angband.h"
6
7 #ifdef USE_CAP
8
9
10 /*
11  * This file is a total hack, but is often very helpful.  :-)
12  *
13  * This file allows use of the terminal without requiring the
14  * "curses" routines.  In fact, if "USE_HARDCODE" is defined,
15  * this file will attempt to use various hard-coded "vt100"
16  * escape sequences to also avoid the use of the "termcap"
17  * routines.  I do not know if this will work on System V.
18  *
19  * This file is intended for use only on those machines which are
20  * unable, for whatever reason, to compile the "main-gcu.c" file,
21  * but which seem to be able to support the "termcap" library, or
22  * which at least seem able to support "vt100" terminals.
23  *
24  * Large portions of this file were stolen from "main-gcu.c"
25  *
26  * This file incorrectly handles output to column 80, I think.
27  */
28
29
30 /*
31  * Require a "system"
32  */
33 #if !defined(USE_TERMCAP) && !defined(USE_HARDCODE)
34 # define USE_TERMCAP
35 #endif
36
37 /*
38  * Hack -- try to guess which systems use what commands
39  * Hack -- allow one of the "USE_Txxxxx" flags to be pre-set.
40  * Mega-Hack -- try to guess when "POSIX" is available.
41  * If the user defines two of these, we will probably crash.
42  */
43 # if && !defined(USE_TCHARS)
44 #  if defined(_POSIX_VERSION)
45 #   define USE_TPOSIX
46 #  else
47 #   if defined(linux)
48 #    define USE_TERMIO
49 #   else
50 #    define USE_TCHARS
51 #   endif
52 #  endif
53 # endif
54
55
56 /*
57  * POSIX stuff
58  */
59 #ifdef USE_TPOSIX
60 # include <sys/ioctl.h>
61 # include <termios.h>
62 #endif
63
64 /*
65  * One version needs these files
66  */
67 #ifdef USE_TERMIO
68 # include <sys/ioctl.h>
69 # include <termio.h>
70 #endif
71
72 /*
73  * The other needs these files
74  */
75 #ifdef USE_TCHARS
76 # include <sys/ioctl.h>
77 # include <sys/resource.h>
78 # include <sys/param.h>
79 # include <sys/file.h>
80 # include <sys/types.h>
81 #endif
82
83
84 /*
85  * XXX XXX Hack -- POSIX uses "O_NONBLOCK" instead of "O_NDELAY"
86  *
87  * They should both work due to the "(i != 1)" test in the code
88  * which checks for the result of the "read()" command.
89  */
90 #ifndef O_NDELAY
91 # define O_NDELAY O_NONBLOCK
92 #endif
93
94
95
96
97 #ifdef USE_TERMCAP
98
99 /*
100  * Termcap string information
101  */
102
103 static char blob[1024];         /* The "termcap" entry */
104 static char area[1024];         /* The string extraction buffer */
105 static char *next = area;       /* The current "index" into "area" */
106 static char *desc;              /* The terminal name */
107
108 #endif
109
110
111 /*
112  * Pointers into the "area"
113  */
114
115 static char *cm;        /* Move cursor */
116 static char *ch;        /* Move cursor to horizontal location */
117 static char *cv;        /* Move cursor to vertical location */
118 static char *ho;        /* Move cursor to top left */
119 static char *ll;        /* Move cursor to bottom left */
120 static char *cs;        /* Set scroll area */
121 static char *cl;        /* Clear screen */
122 static char *cd;        /* Clear to end of display */
123 static char *ce;        /* Clear to end of line */
124 static char *cr;        /* Move to start of line */
125 static char *so;        /* Turn on standout */
126 static char *se;        /* Turn off standout */
127 static char *md;        /* Turn on bold */
128 static char *me;        /* Turn off bold */
129 static char *vi;        /* Cursor - invisible */
130 static char *ve;        /* Cursor - normal */
131 static char *vs;        /* Cursor - bright */
132
133
134 /*
135  * State variables
136  */
137
138 static int rows;        /* Screen size (Y) */
139 static int cols;        /* Screen size (X) */
140 static int curx;        /* Cursor location (X) */
141 static int cury;        /* Cursor location (Y) */
142 static int curv;        /* Cursor visibility */
143
144
145 /*
146  * Extern functions
147  */
148 extern char *getenv();
149 extern char *tgoto();
150 extern char *tgetstr();
151
152
153 /*
154  * Write some chars to the terminal
155  */
156 static void ewrite(char *str)
157 {
158         int numtowrite, numwritten;
159
160         /* See how much work we have */
161         numtowrite = strlen(str);
162
163         /* Write until done */
164         while (numtowrite > 0)
165         {
166                 /* Try to write the chars */
167                 numwritten = write(1, str, numtowrite);
168
169                 /* Handle FIFOs and EINTR */
170                 if (numwritten < 0) numwritten = 0;
171
172                 /* See what we completed */
173                 numtowrite -= numwritten;
174                 str += numwritten;
175
176                 /* Hack -- sleep if not done */
177                 if (numtowrite > 0) sleep(1);
178         }
179 }
180
181
182
183 #ifdef USE_TERMCAP
184
185 static char write_buffer[128];
186 static char *write_buffer_ptr;
187
188 static void output_one(char c)
189 {
190         *write_buffer_ptr++ = c;
191 }
192
193 static void tp(char *s)
194 {
195         /* Dump the string into us */
196         write_buffer_ptr = write_buffer;
197
198         /* Write the string with padding */
199         tputs (s, 1, output_one);
200
201         /* Finish the string */
202         *write_buffer_ptr = '\0';
203
204         /* Dump the recorded buffer */
205         ewrite (write_buffer);
206 }
207
208 #endif
209
210 #ifdef USE_HARDCODE
211
212 static void tp(char *s)
213 {
214         ewrite(s);
215 }
216
217 #endif
218
219
220
221
222
223
224
225 /*
226  * Clear the screen
227  */
228 static void do_cl(void)
229 {
230         if (cl) tp (cl);
231 }
232
233 /*
234  * Clear to the end of the line
235  */
236 static void do_ce(void)
237 {
238         if (ce) tp(ce);
239 }
240
241
242 /*
243  * Set the cursor visibility (0 = invis, 1 = normal, 2 = bright)
244  */
245 static void curs_set(int vis)
246 {
247         char *v = NULL;
248
249         if (!vis)
250         {
251                 v = vi;
252         }
253         else if (vis > 1)
254         {
255                 v = vs ? vs : ve;
256         }
257         else
258         {
259                 v = ve ? ve : vs;
260         }
261
262         if (v) tp(v);
263 }
264
265
266
267 /*
268  * Restrict scrolling to within these rows
269  */
270 static void do_cs(int y1, int y2)
271 {
272
273 #ifdef USE_TERMCAP
274         if (cs) tp(tgoto(cs, y2, y1));
275 #endif
276
277 #ifdef USE_HARDCODE
278         char temp[64];
279         sprintf(temp, cs, y1, y2);
280         tp (temp);
281 #endif
282
283 }
284
285
286
287 /*
288  * Go to the given screen location directly
289  */
290 static void do_cm(int x, int y)
291 {
292
293 #ifdef USE_TERMCAP
294         if (cm) tp(tgoto(cm, x, y));
295 #endif
296
297 #ifdef USE_HARDCODE
298         char temp[64];
299         sprintf(temp, cm, y+1, x+1);
300         tp(temp);
301 #endif
302
303 }
304
305
306 /*
307  * Go to the given screen location in a "clever" manner
308  *
309  * XXX XXX XXX This function could use some work!
310  */
311 static void do_move(int x1, int y1, int x2, int y2)
312 {
313         /* Hack -- unknown start location */
314         if ((x1 == x2) && (y1 == y2)) do_cm(x2, y2);
315
316         /* Left edge */
317         else if (x2 == 0)
318         {
319                 if ((y2 <= 0) && ho) tp(ho);
320                 else if ((y2 >= rows-1) && ll) tp(ll);
321                 else if ((y2 == y1) && cr) tp(cr);
322                 else do_cm(x2, y2);
323         }
324
325         /* Default -- go directly there */
326         else do_cm(x2, y2);
327 }
328
329
330
331
332 /*
333  * Help initialize this file (see below)
334  */
335 errr init_cap_aux(void)
336 {
337
338 #ifdef USE_TERMCAP
339
340         /* Get the terminal name (if possible) */
341         desc = getenv("TERM");
342         if (!desc) return (1);
343
344         /* Get the terminal info */
345         if (tgetent(blob, desc) != 1) return (2);
346
347         /* Get the (initial) columns and rows, or default */
348         if ((cols = tgetnum("co")) == -1) cols = 80;
349         if ((rows = tgetnum("li")) == -1) rows = 24;
350
351         /* Find out how to move the cursor to a given location */
352         cm = tgetstr("cm", &next);
353         if (!cm) return (10);
354
355         /* Find out how to move the cursor to a given position */
356         ch = tgetstr("ch", &next);
357         cv = tgetstr("cv", &next);
358
359         /* Find out how to "home" the screen */
360         ho = tgetstr("ho", &next);
361
362         /* Find out how to "last-line" the screen */
363         ll = tgetstr("ll", &next);
364
365         /* Find out how to do a "carriage return" */
366         cr = tgetstr("cr", &next);
367         if (!cr) cr = "\r";
368
369         /* Find out how to clear the screen */
370         cl = tgetstr("cl", &next);
371         if (!cl) return (11);
372
373         /* Find out how to clear to the end of display */
374         cd = tgetstr("cd", &next);
375
376         /* Find out how to clear to the end of the line */
377         ce = tgetstr("ce", &next);
378
379         /* Find out how to scroll (set the scroll region) */
380         cs = tgetstr("cs", &next);
381
382         /* Find out how to hilite */
383         so = tgetstr("so", &next);
384         se = tgetstr("se", &next);
385         if (!so || !se) so = se = NULL;
386
387         /* Find out how to bold */
388         md = tgetstr("md", &next);
389         me = tgetstr("me", &next);
390         if (!md || !me) md = me = NULL;
391
392         /* Check the cursor visibility stuff */
393         vi = tgetstr("vi", &next);
394         vs = tgetstr("vs", &next);
395         ve = tgetstr("ve", &next);
396
397 #endif
398
399 #ifdef USE_HARDCODE
400
401         /* Assume some defualt information */
402         rows = 24;
403         cols = 80;
404
405         /* Clear screen */
406         cl = "\033[2J\033[H";   /* --]--]-- */
407
408         /* Clear to end of line */
409         ce = "\033[K";  /* --]-- */
410
411         /* Hilite on/off */
412         so = "\033[7m"; /* --]-- */
413         se = "\033[m";  /* --]-- */
414
415         /* Scroll region */
416         cs = "\033[%d;%dr";     /* --]-- */
417
418         /* Move cursor */
419         cm = "\033[%d;%dH";     /* --]-- */
420
421 #endif
422
423         /* Success */
424         return (0);
425 }
426
427
428
429
430
431
432
433 /*
434  * Save the "normal" and "angband" terminal settings
435  */
436
437 #ifdef USE_TPOSIX
438
439 static struct termios  norm_termios;
440
441 static struct termios  game_termios;
442
443 #endif
444
445 #ifdef USE_TERMIO
446
447 static struct termio  norm_termio;
448
449 static struct termio  game_termio;
450
451 #endif
452
453 #ifdef USE_TCHARS
454
455 static struct sgttyb  norm_ttyb;
456 static struct tchars  norm_tchars;
457 static struct ltchars norm_ltchars;
458 static int            norm_local_chars;
459
460 static struct sgttyb  game_ttyb;
461 static struct tchars  game_tchars;
462 static struct ltchars game_ltchars;
463 static int            game_local_chars;
464
465 #endif
466
467
468
469 /*
470  * Are we active?  Not really needed.
471  */
472 static int active = FALSE;
473
474
475 /*
476  * The main screen (no sub-screens)
477  */
478 static term term_screen_body;
479
480
481
482 /*
483  * Place the "keymap" into its "normal" state
484  */
485 static void keymap_norm(void)
486 {
487
488 #ifdef USE_TPOSIX
489
490         /* restore the saved values of the special chars */
491         (void)tcsetattr(0, TCSAFLUSH, &norm_termios);
492
493 #endif
494
495 #ifdef USE_TERMIO
496
497         /* restore the saved values of the special chars */
498         (void)ioctl(0, TCSETA, (char *)&norm_termio);
499
500 #endif
501
502 #ifdef USE_TCHARS
503
504         /* restore the saved values of the special chars */
505         (void)ioctl(0, TIOCSETP, (char *)&norm_ttyb);
506         (void)ioctl(0, TIOCSETC, (char *)&norm_tchars);
507         (void)ioctl(0, TIOCSLTC, (char *)&norm_ltchars);
508         (void)ioctl(0, TIOCLSET, (char *)&norm_local_chars);
509
510 #endif
511
512 }
513
514
515 /*
516  * Place the "keymap" into the "game" state
517  */
518 static void keymap_game(void)
519 {
520
521 #ifdef USE_TPOSIX
522
523         /* restore the saved values of the special chars */
524         (void)tcsetattr(0, TCSAFLUSH, &game_termios);
525
526 #endif
527
528 #ifdef USE_TERMIO
529
530         /* restore the saved values of the special chars */
531         (void)ioctl(0, TCSETA, (char *)&game_termio);
532
533 #endif
534
535 #ifdef USE_TCHARS
536
537         /* restore the saved values of the special chars */
538         (void)ioctl(0, TIOCSETP, (char *)&game_ttyb);
539         (void)ioctl(0, TIOCSETC, (char *)&game_tchars);
540         (void)ioctl(0, TIOCSLTC, (char *)&game_ltchars);
541         (void)ioctl(0, TIOCLSET, (char *)&game_local_chars);
542
543 #endif
544
545 }
546
547
548 /*
549  * Save the normal keymap
550  */
551 static void keymap_norm_prepare(void)
552 {
553
554 #ifdef USE_TPOSIX
555
556         /* Get the normal keymap */
557         tcgetattr(0, &norm_termios);
558
559 #endif
560
561 #ifdef USE_TERMIO
562
563         /* Get the normal keymap */
564         (void)ioctl(0, TCGETA, (char *)&norm_termio);
565
566 #endif
567
568 #ifdef USE_TCHARS
569
570         /* Get the normal keymap */
571         (void)ioctl(0, TIOCGETP, (char *)&norm_ttyb);
572         (void)ioctl(0, TIOCGETC, (char *)&norm_tchars);
573         (void)ioctl(0, TIOCGLTC, (char *)&norm_ltchars);
574         (void)ioctl(0, TIOCLGET, (char *)&norm_local_chars);
575
576 #endif
577
578 }
579
580
581 /*
582  * Save the keymaps (normal and game)
583  */
584 static void keymap_game_prepare(void)
585 {
586
587 #ifdef USE_TPOSIX
588
589         /* Acquire the current mapping */
590         tcgetattr(0, &game_termios);
591
592         /* Force "Ctrl-C" to interupt */
593         game_termios.c_cc[VINTR] = (char)3;
594
595         /* Force "Ctrl-Z" to suspend */
596         game_termios.c_cc[VSUSP] = (char)26;
597
598         /* Hack -- Leave "VSTART/VSTOP" alone */
599
600         /* Disable the standard control characters */
601         game_termios.c_cc[VQUIT] = (char)-1;
602         game_termios.c_cc[VERASE] = (char)-1;
603         game_termios.c_cc[VKILL] = (char)-1;
604         game_termios.c_cc[VEOF] = (char)-1;
605         game_termios.c_cc[VEOL] = (char)-1;
606
607         /* Normally, block until a character is read */
608         game_termios.c_cc[VMIN] = 1;
609         game_termios.c_cc[VTIME] = 0;
610
611         /* Hack -- Turn off "echo" and "canonical" mode */
612         game_termios.c_lflag &= ~(ECHO | ICANON);
613
614         /* Turn off flow control */
615         game_termios.c_iflag &= ~IXON;
616
617 #endif
618
619 #ifdef USE_TERMIO
620
621         /* Acquire the current mapping */
622         (void)ioctl(0, TCGETA, (char *)&game_termio);
623
624         /* Force "Ctrl-C" to interupt */
625         game_termio.c_cc[VINTR] = (char)3;
626
627         /* Force "Ctrl-Z" to suspend */
628         game_termio.c_cc[VSUSP] = (char)26;
629
630         /* Hack -- Leave "VSTART/VSTOP" alone */
631
632         /* Disable the standard control characters */
633         game_termio.c_cc[VQUIT] = (char)-1;
634         game_termio.c_cc[VERASE] = (char)-1;
635         game_termio.c_cc[VKILL] = (char)-1;
636         game_termio.c_cc[VEOF] = (char)-1;
637         game_termio.c_cc[VEOL] = (char)-1;
638
639         /* Normally, block until a character is read */
640         game_termio.c_cc[VMIN] = 1;
641         game_termio.c_cc[VTIME] = 0;
642
643         /* Hack -- Turn off "echo" and "canonical" mode */
644         game_termio.c_lflag &= ~(ECHO | ICANON);
645
646         /* Turn off flow control */
647         game_termio.c_iflag &= ~IXON;
648
649 #endif
650
651 #ifdef USE_TCHARS
652
653         /* Get the default game characters */
654         (void)ioctl(0, TIOCGETP, (char *)&game_ttyb);
655         (void)ioctl(0, TIOCGETC, (char *)&game_tchars);
656         (void)ioctl(0, TIOCGLTC, (char *)&game_ltchars);
657         (void)ioctl(0, TIOCLGET, (char *)&game_local_chars);
658
659         /* Force interupt (^C) */
660         game_tchars.t_intrc = (char)3;
661
662         /* Force start/stop (^Q, ^S) */
663         game_tchars.t_startc = (char)17;
664         game_tchars.t_stopc = (char)19;
665
666         /* Cancel some things */
667         game_tchars.t_quitc = (char)-1;
668         game_tchars.t_eofc = (char)-1;
669         game_tchars.t_brkc = (char)-1;
670
671         /* Force suspend (^Z) */
672         game_ltchars.t_suspc = (char)26;
673
674         /* Cancel some things */
675         game_ltchars.t_dsuspc = (char)-1;
676         game_ltchars.t_rprntc = (char)-1;
677         game_ltchars.t_flushc = (char)-1;
678         game_ltchars.t_werasc = (char)-1;
679         game_ltchars.t_lnextc = (char)-1;
680
681         /* XXX XXX XXX XXX Verify this before use */
682         /* Hack -- Turn off "echo" and "canonical" mode */
683         /* game_termios.c_lflag &= ~(ECHO | ICANON); */
684         game_ttyb.flag &= ~(ECHO | ICANON);
685
686         /* XXX XXX XXX  Should maybe turn off flow control too.  How? */
687
688 #endif
689
690 }
691
692
693
694
695
696
697
698
699 /*
700  * Suspend/Resume
701  */
702 static errr Term_xtra_cap_alive(int v)
703 {
704         /* Suspend */
705         if (!v)
706         {
707                 if (!active) return (1);
708
709                 /* Hack -- make sure the cursor is visible */
710                 curs_set(1);
711
712                 /* Move to bottom right */
713                 do_move(0, rows - 1, 0, rows - 1);
714
715                 /* Go to normal keymap mode */
716                 keymap_norm();
717
718                 /* No longer active */
719                 active = FALSE;
720         }
721
722         /* Resume */
723         else
724         {
725                 if (active) return (1);
726
727                 /* Hack -- restore the cursor location */
728                 do_move(curx, cury, curx, cury);
729
730                 /* Hack -- restore the cursor visibility */
731                 curs_set(curv);
732
733                 /* Go to angband keymap mode */
734                 keymap_game();
735
736                 /* Now we are active */
737                 active = TRUE;
738         }
739
740         /* Success */
741         return (0);
742 }
743
744
745
746 /*
747  * Process an event
748  */
749 static errr Term_xtra_cap_event(int v)
750 {
751         int i, arg;
752         char buf[2];
753
754         /* Wait */
755         if (v)
756         {
757                 /* Wait for one byte */
758                 i = read(0, buf, 1);
759
760                 /* Hack -- Handle "errors" */
761                 if ((i <= 0) && (errno != EINTR)) exit_game_panic(p_ptr);
762         }
763
764         /* Do not wait */
765         else
766         {
767                 /* Get the current flags for stdin */
768                 if ((arg = fcntl(0, F_GETFL, 0)) < 1) return (1);
769
770                 /* Tell stdin not to block */
771                 if (fcntl(0, F_SETFL, arg | O_NDELAY) < 0) return (1);
772
773                 /* Read one byte, if possible */
774                 i = read(0, buf, 1);
775
776                 /* Replace the flags for stdin */
777                 if (fcntl(0, F_SETFL, arg)) return (1);
778         }
779
780         /* No keys ready */
781         if ((i != 1) || (!buf[0])) return (1);
782
783         /* Enqueue the keypress */
784         Term_keypress(buf[0]);
785
786         /* Success */
787         return (0);
788 }
789
790
791
792
793 /*
794  * Actually move the hardware cursor
795  */
796 static errr Term_curs_cap(int x, int y)
797 {
798         /* Literally move the cursor */
799         do_move(curx, cury, x, y);
800
801         /* Save the cursor location */
802         curx = x;
803         cury = y;
804
805         /* Success */
806         return (0);
807 }
808
809
810 /*
811  * Erase a grid of space
812  *
813  * XXX XXX XXX Note that we will never be asked to clear the
814  * bottom line all the way to the bottom right edge, since we
815  * have set the "avoid the bottom right corner" flag.
816  */
817 static errr Term_wipe_cap(int x, int y, int n)
818 {
819         int dx;
820
821         /* Place the cursor */
822         Term_curs_cap(x, y);
823
824         /* Wipe to end of line */
825         if (x + n >= 80)
826         {
827                 do_ce();
828         }
829
830         /* Wipe region */
831         else
832         {
833                 for (dx = 0; dx < n; ++dx)
834                 {
835                         putc(' ', stdout);
836                         curx++;
837                 }
838         }
839
840         /* Success */
841         return (0);
842 }
843
844
845 /*
846  * Place some text on the screen using an attribute
847  */
848 static errr Term_text_cap(int x, int y, int n, byte a, concptr s)
849 {
850         int i;
851
852         /* Move the cursor */
853         Term_curs_cap(x, y);
854
855         /* Dump the text, advance the cursor */
856         for (i = 0; s[i]; i++)
857         {
858                 /* Dump the char */
859                 putc(s[i], stdout);
860
861                 /* Advance cursor 'X', and wrap */
862                 if (++curx >= cols)
863                 {
864                         /* Reset cursor 'X' */
865                         curx = 0;
866
867                         /* Hack -- Advance cursor 'Y', and wrap */
868                         if (++cury == rows) cury = 0;
869                 }
870         }
871
872         /* Success */
873         return (0);
874 }
875
876
877 /*
878  * Handle a "special request"
879  */
880 static errr Term_xtra_cap(int n, int v)
881 {
882         /* Analyze the request */
883         switch (n)
884         {
885                 /* Clear the screen */
886                 case TERM_XTRA_CLEAR:
887                 do_cl();
888                 do_move(0, 0, 0, 0);
889                 return (0);
890
891                 /* Make a noise */
892                 case TERM_XTRA_NOISE:
893                 (void)write(1, "\007", 1);
894                 return (0);
895
896                 /* Change the cursor visibility */
897                 case TERM_XTRA_SHAPE:
898                 curv = v;
899                 curs_set(v);
900                 return (0);
901
902                 /* Suspend/Resume */
903                 case TERM_XTRA_ALIVE:
904                 return (Term_xtra_cap_alive(v));
905
906                 /* Process events */
907                 case TERM_XTRA_EVENT:
908                 return (Term_xtra_cap_event(v));
909
910                 /* Flush events */
911                 case TERM_XTRA_FLUSH:
912                 while (!Term_xtra_cap_event(FALSE));
913                 return (0);
914
915                 /* Delay */
916                 case TERM_XTRA_DELAY:
917                 usleep(1000 * v);
918                 return (0);
919         }
920
921         /* Not parsed */
922         return (1);
923 }
924
925
926
927
928 /*
929  * Init a "term" for this file
930  */
931 static void Term_init_cap(term *t)
932 {
933         if (active) return;
934
935         /* Assume cursor at top left */
936         curx = 0;
937         cury = 0;
938
939         /* Assume visible cursor */
940         curv = 1;
941
942         /* Clear the screen */
943         do_cl();
944
945         /* Hack -- visible cursor */
946         curs_set(1);
947
948         /* Assume active */
949         active = TRUE;
950 }
951
952
953 /*
954  * Nuke a "term" for this file
955  */
956 static void Term_nuke_cap(term *t)
957 {
958         if (!active) return;
959
960         /* Hack -- make sure the cursor is visible */
961         curs_set(1);
962
963         /* Move to bottom right */
964         do_move(0, rows - 1, 0, rows - 1);
965
966         /* Normal keymap */
967         keymap_norm();
968
969         /* No longer active */
970         active = FALSE;
971 }
972
973
974
975
976
977
978
979
980
981
982 /*
983  * Prepare this file for Angband usage
984  */
985 errr init_cap(void)
986 {
987         term *t = &term_screen_body;
988
989
990         /*** Initialize ***/
991
992         /* Initialize the screen */
993         if (init_cap_aux()) return (-1);
994
995         /* Hack -- Require large screen, or Quit with message */
996         if ((rows < 24) || (cols < 80)) quit("Screen too small!");
997
998
999         /*** Prepare to play ***/
1000
1001         /* Extract the normal keymap */
1002         keymap_norm_prepare();
1003
1004         /* Extract the game keymap */
1005         keymap_game_prepare();
1006
1007         /* Hack -- activate the game keymap */
1008         keymap_game();
1009
1010         /* Hack -- Do NOT buffer stdout */
1011         setbuf(stdout, NULL);
1012
1013
1014         /*** Now prepare the term ***/
1015
1016         /* Initialize the term */
1017         term_init(t, 80, 24, 256);
1018
1019         /* Avoid the bottom right corner */
1020         t->icky_corner = TRUE;
1021
1022         /* Erase with "white space" */
1023         t->attr_blank = TERM_WHITE;
1024         t->char_blank = ' ';
1025
1026         /* Set some hooks */
1027         t->init_hook = Term_init_cap;
1028         t->nuke_hook = Term_nuke_cap;
1029
1030         /* Set some more hooks */
1031         t->text_hook = Term_text_cap;
1032         t->wipe_hook = Term_wipe_cap;
1033         t->curs_hook = Term_curs_cap;
1034         t->xtra_hook = Term_xtra_cap;
1035
1036         /* Save the term */
1037         term_screen = t;
1038
1039         /* Activate it */
1040         Term_activate(term_screen);
1041
1042         /* Success */
1043         return (0);
1044 }
1045
1046
1047 #endif /* USE_CAP */
1048
1049