Changeset 183

Show
Ignore:
Timestamp:
06/10/07 19:18:15 (1 year ago)
Author:
takkaria
Message:

Add a bit of PDCurses magic to make the keypad work over there; also clean up a bit, more generally.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/src/main-gcu.c

    r155 r183  
    3737 * Consider the use of "savetty()" and "resetty()".  XXX XXX XXX 
    3838 */ 
    39  
    40  
    4139#include "angband.h" 
    4240 
     
    5452#define term System_term 
    5553 
     54 
    5655/* 
    5756 * Include the proper "header" file 
    5857 */ 
    5958#ifdef USE_NCURSES 
    60 # if defined(HAVE_STDBOOL_H) 
     59# ifdef HAVE_STDBOOL_H 
    6160#  define NCURSES_ENABLE_STDBOOL_H 0 
    6261# endif 
     
    7069 
    7170 
    72 #ifdef HAVE_CAN_CHANGE_COLOR 
    73  
    74 /* 
    75  * Try redefining the colors at startup. 
    76  */ 
    77 #define REDEFINE_COLORS 
    78  
     71#if !defined(HAVE_CAN_CHANGE_COLOR) && defined(PDCURSES) 
     72# define HAVE_CAN_CHANGE_COLOR 
    7973#endif /* HAVE_CAN_CHANGE_COLOR */ 
    8074 
     
    10195 */ 
    10296#ifdef USE_TPOSIX 
    103 /*# include <sys/ioctl.h>*/ 
    10497# include <termios.h> 
    10598#endif 
    10699 
    107 /* 
    108  * OPTION: Use old BSD curses. 
    109  * 
    110  * Some versions of curses does things a bit differently. 
    111  * 
    112  * If you have an old BSD 4.4 version of curses that isn't 
    113  * XSI Curses standard compatible enable this. 
    114  */ 
    115 /* #define USE_OLD_CURSES */ 
    116  
    117  
    118 /* 
    119  * Turn on options that are available in modern curses. 
    120  */ 
    121 #if defined (USE_OLD_CURSES) 
    122 /* Nothing */ 
    123 #else 
    124 # define USE_GETCH 
    125 # define USE_CURS_SET 
    126 #endif 
    127  
    128 /* 
    129  * You might want to turn on some of the options below this line 
    130  * if you had to turn on USE_OLD_CURSES 
    131  */ 
    132  
    133  
    134 /* 
    135  * OPTION: Use "blocking getch() calls" in "main-gcu.c". 
    136  */ 
    137 /* #define USE_GETCH */ 
    138  
    139 /* 
    140  * OPTION: Use the "curs_set()" call in "main-gcu.c". 
    141  */ 
    142 /* #define USE_CURS_SET */ 
    143  
    144  
    145  
    146 /* 
    147  * OPTION: some machines lack "cbreak()" 
    148  * On these machines, we use an older definition 
     100 
     101 
     102/* 
     103 * If you have errors relating to curs_set(), comment out the following line 
     104 */  
     105#define USE_CURS_SET 
     106 
     107 
     108/* 
     109 * If you have errors with any of the functions mentioned below, try 
     110 * uncommenting the line it's mentioned on. 
    149111 */ 
    150112/* #define cbreak() crmode() */ 
    151  
    152  
    153 /* 
    154  * OPTION: some machines cannot handle "nonl()" and "nl()" 
    155  * On these machines, we can simply ignore those commands. 
    156  */ 
    157113/* #define nonl() */ 
    158114/* #define nl() */ 
    159115 
    160116 
     117 
    161118/* 
    162119 * Save the "normal" and "angband" terminal settings 
     
    166123 
    167124static struct termios  norm_termios; 
    168  
    169125static struct termios  game_termios; 
    170126 
     
    175131 * Information about a term 
    176132 */ 
    177 typedef struct term_data term_data; 
    178  
    179 struct term_data 
     133typedef struct term_data 
    180134{ 
    181135        term t;                 /* All term info */ 
    182  
    183136        WINDOW *win;            /* Pointer to the curses window */ 
    184 }
     137} term_data
    185138 
    186139/* Max number of windows on screen */ 
     
    190143static term_data data[MAX_TERM_DATA]; 
    191144 
    192  
    193 /* 
    194  * Hack -- Number of initialized "term" structures 
    195  */ 
     145/* Number of initialized "term" structures */ 
    196146static int active = 0; 
     147 
    197148 
    198149 
     
    388339        term_data *td = (term_data *)(t->data); 
    389340 
    390 #ifdef USE_GETCH 
    391341        /* 
    392342         * This is necessary to keep the first call to getch() 
     
    394344         */ 
    395345        wrefresh(stdscr); 
    396 #endif /* USE_GETCH */ 
    397346 
    398347        /* Count init's, handle first */ 
     
    457406 
    458407 
    459 #ifdef USE_GETCH 
    460  
    461408/* 
    462409 * Process events, with optional wait 
     
    500447        } 
    501448 
     449#ifdef KEY_DOWN 
     450        /* Handle arrow keys */ 
     451        switch (i) 
     452        { 
     453                case KEY_DOWN:  i = ARROW_DOWN;  break; 
     454                case KEY_UP:    i = ARROW_UP;    break; 
     455                case KEY_LEFT:  i = ARROW_LEFT;  break; 
     456                case KEY_RIGHT: i = ARROW_RIGHT; break; 
     457        } 
     458#endif 
     459 
    502460        /* Enqueue the keypress */ 
    503461        Term_keypress(i); 
     
    507465} 
    508466 
    509 #else   /* USE_GETCH */ 
    510  
    511 /* 
    512  * Process events (with optional wait) 
    513  */ 
    514 static errr Term_xtra_gcu_event(int v) 
    515 { 
    516         int i, k; 
    517  
    518         char buf[2]; 
    519  
    520         /* Wait */ 
    521         if (v) 
    522         { 
    523                 /* Wait for one byte */ 
    524                 i = read(0, buf, 1); 
    525  
    526                 /* Hack -- Handle bizarre "errors" */ 
    527                 if ((i <= 0) && (errno != EINTR)) exit_game_panic(); 
    528         } 
    529  
    530         /* Do not wait */ 
    531         else 
    532         { 
    533                 /* Get the current flags for stdin */ 
    534                 k = fcntl(0, F_GETFL, 0); 
    535  
    536                 /* Oops */ 
    537                 if (k < 0) return (1); 
    538  
    539                 /* Tell stdin not to block */ 
    540                 if (fcntl(0, F_SETFL, k | O_NONBLOCK) < 0) return (1); 
    541  
    542                 /* Read one byte, if possible */ 
    543                 i = read(0, buf, 1); 
    544  
    545                 /* Replace the flags for stdin */ 
    546                 if (fcntl(0, F_SETFL, k)) return (1); 
    547         } 
    548  
    549         /* Ignore "invalid" keys */ 
    550         if ((i != 1) || (!buf[0])) return (1); 
    551  
    552         /* Enqueue the keypress */ 
    553         Term_keypress(buf[0]); 
    554  
    555         /* Success */ 
    556         return (0); 
    557 } 
    558  
    559 #endif  /* USE_GETCH */ 
    560467 
    561468/* 
     
    847754                         (COLORS >= 8) && (COLOR_PAIRS >= 8)); 
    848755 
    849 #ifdef REDEFINE_COLORS 
     756#ifdef HAVE_CAN_CHANGE_COLOR 
    850757 
    851758        /* Can we change colors? */ 
     
    916823        /*** Low level preparation ***/ 
    917824 
    918 #ifdef USE_GETCH 
    919  
    920825        /* Paranoia -- Assume no waiting */ 
    921826        nodelay(stdscr, FALSE); 
    922  
    923 #endif 
    924827 
    925828        /* Prepare */ 
     
    927830        noecho(); 
    928831        nonl(); 
     832 
     833#ifdef PDCURSES 
     834        keypad(stdscr, TRUE); 
     835#endif 
    929836 
    930837        /* Extract the game keymap */