OSDN Git Service

[Refactor] #37353 コメント整理。 / Refactor comments.
[hengband/hengband.git] / src / z-term.c
index ce8562e..76a167e 100644 (file)
@@ -1,4 +1,4 @@
-/* File: z-term.c */
+/* File: z-term.c */
 
 /*
  * Copyright (c) 1997 Ben Harrison
 
 #include "z-virt.h"
 
+/* Special flags in the attr data */
+#define AF_BIGTILE2 0xf0
+#define AF_TILE1   0x80
 
 #ifdef JP
-#define KANJI1  0x10
-#define KANJI2  0x20
-#define KANJIC  0x0f
+#define AF_KANJI1  0x10
+#define AF_KANJI2  0x20
+#define AF_KANJIC  0x0f
 /*
- * Á´³Ñʸ»úÂбþ¡£
- * Â°À­¤ËÁ´³Ñʸ»ú¤Î£±¥Ð¥¤¥ÈÌÜ¡¢£²¥Ð¥¤¥ÈÌܤ⵭²±¡£
+ * 全角文字対応。
+ * 属性に全角文字の1バイト目、2バイト目も記憶。
  * By FIRST
  */
 #endif
@@ -49,7 +52,8 @@
  * computers, and to check for "keypresses" from the user.  The major
  * concerns were thus portability and efficiency, so Angband could be
  * easily ported to many different systems, with minimal effort, and
- * yet would run quickly on each of these systems, no matter what kind
+ * yet would run quickly on each of these sys
+ tems, no matter what kind
  * of underlying hardware/software support was being used.
  *
  * It is important to understand the differences between the older
  *   Term->user_hook = Perform user actions
  *   Term->xtra_hook = Perform extra actions
  *   Term->curs_hook = Draw (or Move) the cursor
+ *   Term->bigcurs_hook = Draw (or Move) the big cursor (bigtile mode)
  *   Term->wipe_hook = Draw some blank spaces
  *   Term->text_hook = Draw some text in the window
  *   Term->pict_hook = Draw some attr/chars in the window
@@ -292,28 +297,24 @@ term *Term = NULL;
 /*
  * Nuke a term_win (see below)
  */
-static errr term_win_nuke(term_win *s, int w, int h)
+static errr term_win_nuke(term_win *s, TERM_LEN w, TERM_LEN h)
 {
        /* Free the window access arrays */
-       C_KILL(s->a, h, byte*);
+       C_KILL(s->a, h, TERM_COLOR*);
        C_KILL(s->c, h, char*);
 
        /* Free the window content arrays */
-       C_KILL(s->va, h * w, byte);
+       C_KILL(s->va, h * w, TERM_COLOR);
        C_KILL(s->vc, h * w, char);
 
-#ifdef USE_TRANSPARENCY
-
        /* Free the terrain access arrays */
-       C_KILL(s->ta, h, byte*);
+       C_KILL(s->ta, h, TERM_COLOR*);
        C_KILL(s->tc, h, char*);
 
        /* Free the terrain content arrays */
-       C_KILL(s->vta, h * w, byte);
+       C_KILL(s->vta, h * w, TERM_COLOR);
        C_KILL(s->vtc, h * w, char);
 
-#endif /* USE_TRANSPARENCY */
-
        /* Success */
        return (0);
 }
@@ -322,30 +323,26 @@ static errr term_win_nuke(term_win *s, int w, int h)
 /*
  * Initialize a "term_win" (using the given window size)
  */
-static errr term_win_init(term_win *s, int w, int h)
+static errr term_win_init(term_win *s, TERM_LEN w, TERM_LEN h)
 {
-       int y;
+       TERM_LEN y;
 
        /* Make the window access arrays */
-       C_MAKE(s->a, h, byte*);
+       C_MAKE(s->a, h, TERM_COLOR*);
        C_MAKE(s->c, h, char*);
 
        /* Make the window content arrays */
-       C_MAKE(s->va, h * w, byte);
+       C_MAKE(s->va, h * w, TERM_COLOR);
        C_MAKE(s->vc, h * w, char);
 
-#ifdef USE_TRANSPARENCY
-
        /* Make the terrain access arrays */
-       C_MAKE(s->ta, h, byte*);
+       C_MAKE(s->ta, h, TERM_COLOR*);
        C_MAKE(s->tc, h, char*);
 
        /* Make the terrain content arrays */
-       C_MAKE(s->vta, h * w, byte);
+       C_MAKE(s->vta, h * w, TERM_COLOR);
        C_MAKE(s->vtc, h * w, char);
 
-#endif /* USE_TRANSPARENCY */
-
 
        /* Prepare the window access arrays */
        for (y = 0; y < h; y++)
@@ -353,13 +350,8 @@ static errr term_win_init(term_win *s, int w, int h)
                s->a[y] = s->va + w * y;
                s->c[y] = s->vc + w * y;
 
-#ifdef USE_TRANSPARENCY
-
                s->ta[y] = s->vta + w * y;
                s->tc[y] = s->vtc + w * y;
-
-#endif /* USE_TRANSPARENCY */
-
        }
 
        /* Success */
@@ -370,38 +362,32 @@ static errr term_win_init(term_win *s, int w, int h)
 /*
  * Copy a "term_win" from another
  */
-static errr term_win_copy(term_win *s, term_win *f, int w, int h)
+static errr term_win_copy(term_win *s, term_win *f, TERM_LEN w, TERM_LEN h)
 {
-       int x, y;
+       TERM_LEN x, y;
 
        /* Copy contents */
        for (y = 0; y < h; y++)
        {
-               byte *f_aa = f->a[y];
+               TERM_COLOR *f_aa = f->a[y];
                char *f_cc = f->c[y];
 
-               byte *s_aa = s->a[y];
+               TERM_COLOR *s_aa = s->a[y];
                char *s_cc = s->c[y];
 
-#ifdef USE_TRANSPARENCY
-
-               byte *f_taa = f->ta[y];
+               TERM_COLOR *f_taa = f->ta[y];
                char *f_tcc = f->tc[y];
 
-               byte *s_taa = s->ta[y];
+               TERM_COLOR *s_taa = s->ta[y];
                char *s_tcc = s->tc[y];
 
-#endif /* USE_TRANSPARENCY */
-
                for (x = 0; x < w; x++)
                {
                        *s_aa++ = *f_aa++;
                        *s_cc++ = *f_cc++;
 
-#ifdef USE_TRANSPARENCY
                        *s_taa++ = *f_taa++;
                        *s_tcc++ = *f_tcc++;
-#endif /* USE_TRANSPARENCY */
                }
        }
 
@@ -440,10 +426,6 @@ errr Term_xtra(int n, int v)
        /* Verify the hook */
        if (!Term->xtra_hook) return (-1);
 
-#ifdef CHUUKEI
-       if( n == TERM_XTRA_CLEAR || n == TERM_XTRA_FRESH || n == TERM_XTRA_SHAPE )
-         send_xtra_to_chuukei_server(n);
-#endif
        /* Call the hook */
        return ((*Term->xtra_hook)(n, v));
 }
@@ -456,61 +438,65 @@ errr Term_xtra(int n, int v)
 /*
  * Hack -- fake hook for "Term_curs()" (see above)
  */
-static errr Term_curs_hack(int x, int y)
+static errr Term_curs_hack(TERM_LEN x, TERM_LEN y)
 {
-       /* Compiler silliness */
-       if (x || y) return (-2);
+       /* Unused */
+       (void)x;
+       (void)y;
 
-       /* Oops */
        return (-1);
 }
 
 /*
+ * Hack -- fake hook for "Term_bigcurs()" (see above)
+ */
+static errr Term_bigcurs_hack(TERM_LEN x, TERM_LEN y)
+{
+       return (*Term->curs_hook)(x, y);
+}
+
+/*
  * Hack -- fake hook for "Term_wipe()" (see above)
  */
-static errr Term_wipe_hack(int x, int y, int n)
+static errr Term_wipe_hack(TERM_LEN x, TERM_LEN y, int n)
 {
-       /* Compiler silliness */
-       if (x || y || n) return (-2);
+       /* Unused */
+       (void)x;
+       (void)y;
+       (void)n;
 
-       /* Oops */
        return (-1);
 }
 
 /*
  * Hack -- fake hook for "Term_text()" (see above)
  */
-#ifdef JP
-static errr Term_text_hack(int x, int y, int n, byte a, cptr cp)
-#else
-static errr Term_text_hack(int x, int y, int n, byte a, const char *cp)
-#endif
-
+static errr Term_text_hack(TERM_LEN x, TERM_LEN y, int n, TERM_COLOR a, concptr cp)
 {
-       /* Compiler silliness */
-       if (x || y || n || a || cp) return (-2);
+       /* Unused */
+       (void)x;
+       (void)y;
+       (void)n;
+       (void)a;
+       (void)cp;
 
-       /* Oops */
        return (-1);
 }
 
 /*
  * Hack -- fake hook for "Term_pict()" (see above)
  */
-#ifdef USE_TRANSPARENCY
-static errr Term_pict_hack(int x, int y, int n, const byte *ap, const char *cp, const byte *tap, const char *tcp)
-#else /* USE_TRANSPARENCY */
-static errr Term_pict_hack(int x, int y, int n, const byte *ap, const char *cp)
-#endif /* USE_TRANSPARENCY */
+static errr Term_pict_hack(TERM_LEN x, TERM_LEN y, int n, const TERM_COLOR *ap, concptr cp, const TERM_COLOR *tap, concptr tcp)
 {
-       /* Compiler silliness */
-#ifdef USE_TRANSPARENCY
-       if (x || y || n || ap || cp || tap || tcp) return (-2);
-#else /* USE_TRANSPARENCY */
-       if (x || y || n || ap || cp) return (-2);
-#endif /* USE_TRANSPARENCY */
-
-       /* Oops */
+       /* Unused */
+       (void)x;
+       (void)y;
+       (void)n;
+       (void)ap;
+       (void)cp;
+       (void)tap;
+       (void)tcp;
+
        return (-1);
 }
 
@@ -521,54 +507,124 @@ static errr Term_pict_hack(int x, int y, int n, const byte *ap, const char *cp)
 
 /*
  * Mentally draw an attr/char at a given location
- *
  * Assumes given location and values are valid.
  */
-#ifdef USE_TRANSPARENCY
-void Term_queue_char(int x, int y, byte a, char c, byte ta, char tc)
-#else /* USE_TRANSPARENCY */
-void Term_queue_char(int x, int y, byte a, char c)
-#endif /* USE_TRANSPARENCY */
+void Term_queue_char(TERM_LEN x, TERM_LEN y, TERM_COLOR a, char c, TERM_COLOR ta, char tc)
 {
        term_win *scrn = Term->scr; 
        
-       byte *scr_aa = &scrn->a[y][x];
+       TERM_COLOR *scr_aa = &scrn->a[y][x];
        char *scr_cc = &scrn->c[y][x];
 
-#ifdef USE_TRANSPARENCY
-
-       byte *scr_taa = &scrn->ta[y][x];
+       TERM_COLOR *scr_taa = &scrn->ta[y][x];
        char *scr_tcc = &scrn->tc[y][x];
 
        /* Hack -- Ignore non-changes */
        if ((*scr_aa == a) && (*scr_cc == c) &&
                 (*scr_taa == ta) && (*scr_tcc == tc)) return;
 
-#else /* USE_TRANSPARENCY */
-
-       /* Hack -- Ignore non-changes */
-       if ((*scr_aa == a) && (*scr_cc == c)) return;
-
-#endif /* USE_TRANSPARENCY */
-
        /* Save the "literal" information */
        *scr_aa = a;
        *scr_cc = c;
 
-#ifdef USE_TRANSPARENCY
-
        *scr_taa = ta;
        *scr_tcc = tc;
 
-#endif /* USE_TRANSPARENCY */
-
        /* Check for new min/max row info */
-       if (y < Term->y1) Term->y1 = y;
-       if (y > Term->y2) Term->y2 = y;
+       if (y < Term->y1) Term->y1 = (byte_hack)y;
+       if (y > Term->y2) Term->y2 = (byte_hack)y;
 
        /* Check for new min/max col info for this row */
-       if (x < Term->x1[y]) Term->x1[y] = x;
-       if (x > Term->x2[y]) Term->x2[y] = x;
+       if (x < Term->x1[y]) Term->x1[y] = (byte_hack)x;
+       if (x > Term->x2[y]) Term->x2[y] = (byte_hack)x;
+
+#ifdef JP
+       if (((scrn->a[y][x] & AF_BIGTILE2) == AF_BIGTILE2) ||
+           (scrn->a[y][x] & AF_KANJI2))
+#else
+       if ((scrn->a[y][x] & AF_BIGTILE2) == AF_BIGTILE2)
+#endif
+               if ((x - 1) < Term->x1[y]) Term->x1[y]--;
+}
+
+
+/*
+ * Bigtile version of Term_queue_char().
+ * If use_bigtile is FALSE, simply call Term_queue_char().
+ * Otherwise, mentally draw a pair of attr/char at a given location.
+ * Assumes given location and values are valid.
+ */
+void Term_queue_bigchar(TERM_LEN x, TERM_LEN y, TERM_COLOR a, char c, TERM_COLOR ta, char tc)
+{
+
+#ifdef JP
+       /*
+        * A table which relates each ascii character to a multibyte
+        * character.
+        *
+        * 「■」は二倍幅豆腐の内部コードに使用。
+        */
+       static char ascii_to_zenkaku[] =
+               " !”#$%&’()*+,-./"
+               "0123456789:;<=>?"
+               "@ABCDEFGHIJKLMNO"
+               "PQRSTUVWXYZ[\]^_"
+               "‘abcdefghijklmno"
+               "pqrstuvwxyz{|}~■";
+#endif
+
+       byte a2;
+       char c2;
+
+       /* If non bigtile mode, call orginal function */
+       if (!use_bigtile)
+       {
+               Term_queue_char(x, y, a, c, ta, tc);
+               return;
+       }
+
+       /* A tile becomes a Bigtile */
+       if ((a & AF_TILE1) && (c & 0x80))
+       {
+               /* Mark it as a Bigtile */
+               a2 = AF_BIGTILE2;
+
+               c2 = -1;
+
+               /* Ignore non-tile background */
+               if (!((ta & AF_TILE1) && (tc & 0x80)))
+               {
+                       ta = 0;
+                       tc = 0;
+               }
+       }
+
+#ifdef JP
+       /*
+        * Use a multibyte character instead of a dirty pair of ASCII
+        * characters.
+        */
+       else if (' ' <= c) /* isprint(c) */
+       {
+               c2 = ascii_to_zenkaku[2 * (c - ' ') + 1];
+               c = ascii_to_zenkaku[2 * (c - ' ')];
+
+               /* Mark it as a Kanji */
+               a2 = a | AF_KANJI2;
+               a |= AF_KANJI1;
+       }
+#endif
+
+       else
+       {
+               /* Dirty pair of ASCII characters */
+               a2 = TERM_WHITE;
+               c2 = ' ';
+       }
+
+       /* Display pair of attr/char */
+       Term_queue_char(x, y, a, c, ta, tc);
+       Term_queue_char(x + 1, y, a2, c2, 0, 0);
 }
 
 
@@ -580,35 +636,24 @@ void Term_queue_char(int x, int y, byte a, char c)
  * This function is designed to be fast, with no consistancy checking.
  * It is used to update the map in the game.
  */
-#ifdef USE_TRANSPARENCY
-void Term_queue_line(int x, int y, int n, byte *a, char *c, byte *ta, char *tc)
-#else /* USE_TRANSPARENCY */
-void Term_queue_line(int x, int y, int n, byte *a, char *c)
-#endif /* USE_TRANSPARENCY */
+void Term_queue_line(TERM_LEN x, TERM_LEN y, int n, TERM_COLOR *a, char *c, TERM_COLOR *ta, char *tc)
 {
        term_win *scrn = Term->scr;
 
-       int x1 = -1;
-       int x2 = -1;
+       TERM_LEN x1 = -1;
+       TERM_LEN x2 = -1;
 
-       byte *scr_aa = &scrn->a[y][x];
+       TERM_COLOR *scr_aa = &scrn->a[y][x];
        char *scr_cc = &scrn->c[y][x];
 
-#ifdef USE_TRANSPARENCY
-
-       byte *scr_taa = &scrn->ta[y][x];
+       TERM_COLOR *scr_taa = &scrn->ta[y][x];
        char *scr_tcc = &scrn->tc[y][x];
 
-#endif /* USE_TRANSPARENCY */
-
        while (n--)
        {
-
-#ifdef USE_TRANSPARENCY
-
                /* Hack -- Ignore non-changes */
                if ((*scr_aa == *a) && (*scr_cc == *c) &&
-                       (*scr_taa == *ta) && (*scr_tcc == *tc))
+                       (*scr_taa == *ta) && (*scr_tcc == *tc))
                {
                        x++;
                        a++;
@@ -626,21 +671,6 @@ void Term_queue_line(int x, int y, int n, byte *a, char *c)
                *scr_taa++ = *ta++;
                *scr_tcc++ = *tc++;
 
-#else /* USE_TRANSPARENCY */
-
-               /* Hack -- Ignore non-changes */
-               if ((*scr_aa == *a) && (*scr_cc == *c))
-               {
-                       x++;
-                       a++;
-                       c++;
-                       scr_aa++;
-                       scr_cc++;
-                       continue;
-               }
-
-#endif /* USE_TRANSPARENCY */
-
                /* Save the "literal" information */
                *scr_aa++ = *a++;
                *scr_cc++ = *c++;
@@ -658,12 +688,12 @@ void Term_queue_line(int x, int y, int n, byte *a, char *c)
        if (x1 >= 0)
        {
                /* Check for new min/max row info */
-               if (y < Term->y1) Term->y1 = y;
-               if (y > Term->y2) Term->y2 = y;
+               if (y < Term->y1) Term->y1 = (byte_hack)y;
+               if (y > Term->y2) Term->y2 = (byte_hack)y;
 
                /* Check for new min/max col info in this row */
-               if (x1 < Term->x1[y]) Term->x1[y] = x1;
-               if (x2 > Term->x2[y]) Term->x2[y] = x2;
+               if (x1 < Term->x1[y]) Term->x1[y] = (byte_hack)x1;
+               if (x2 > Term->x2[y]) Term->x2[y] = (byte_hack)x2;
        }
 }
 
@@ -677,72 +707,62 @@ void Term_queue_line(int x, int y, int n, byte *a, char *c)
  * a valid location, so the first "n" characters of "s" can all be added
  * starting at (x,y) without causing any illegal operations.
  */
-void Term_queue_chars(int x, int y, int n, byte a, cptr s)
+void Term_queue_chars(TERM_LEN x, TERM_LEN y, int n, TERM_COLOR a, concptr s)
 {
-       int x1 = -1, x2 = -1;
+       TERM_LEN x1 = -1, x2 = -1;
 
-       byte *scr_aa = Term->scr->a[y];
+       TERM_COLOR *scr_aa = Term->scr->a[y];
 #ifdef JP
-        unsigned char *scr_cc = (unsigned char *)Term->scr->c[y];
-
-#ifdef USE_TRANSPARENCY
-       byte *scr_taa = Term->scr->ta[y];
-       unsigned char *scr_tcc = Term->scr->tc[y];
-#endif /* USE_TRANSPARENCY */
+       char *scr_cc = Term->scr->c[y];
 
+       TERM_COLOR *scr_taa = Term->scr->ta[y];
+       char *scr_tcc = Term->scr->tc[y];
 #else
        char *scr_cc = Term->scr->c[y];
 
-#ifdef USE_TRANSPARENCY
-
-       byte *scr_taa = Term->scr->ta[y];
+       TERM_COLOR *scr_taa = Term->scr->ta[y];
        char *scr_tcc = Term->scr->tc[y];
-
-#endif /* USE_TRANSPARENCY */
 #endif
 
 
 #ifdef JP
-        /* É½¼¨Ê¸»ú¤Ê¤· */
-        if (n == 0 || *s == 0) return;
-        /*
-         * Á´³Ñʸ»ú¤Î±¦È¾Ê¬¤«¤éʸ»ú¤òɽ¼¨¤¹¤ë¾ì¹ç¡¢
-         * ½Å¤Ê¤Ã¤¿Ê¸»ú¤Îº¸Éôʬ¤ò¾Ãµî¡£
-         * É½¼¨³«»Ï°ÌÃÖ¤¬º¸Ã¼¤Ç¤Ê¤¤¤È²¾Äê¡£
-         */
-        if (scr_aa[x] & KANJI2)
-        {
-                scr_cc[x - 1] = ' ';
-                scr_aa[x - 1] &= KANJIC;
-                x1 = x2 = x - 1;
-        }
+       /* 表示文字なし */
+       if (n == 0 || *s == 0) return;
+       /*
+        * 全角文字の右半分から文字を表示する場合、
+        * 重なった文字の左部分を消去。
+        * 表示開始位置が左端でないと仮定。
+        */
+       if ((scr_aa[x] & AF_KANJI2) && (scr_aa[x] & AF_BIGTILE2) != AF_BIGTILE2)
+       {
+               scr_cc[x - 1] = ' ';
+               scr_aa[x - 1] &= AF_KANJIC;
+               x1 = x2 = x - 1;
+       }
 #endif
        /* Queue the attr/chars */
        for ( ; n; x++, s++, n--)
        {
 #ifdef JP
-               /* Æüìʸ»ú¤È¤·¤ÆMSB¤¬Î©¤Ã¤Æ¤¤¤ë²ÄǽÀ­¤¬¤¢¤ë */
-               /* ¤½¤Î¾ì¹çattr¤ÎMSB¤âΩ¤Ã¤Æ¤¤¤ë¤Î¤Ç¤³¤ì¤Ç¼±Ê̤¹¤ë */
+               /* 特殊文字としてMSBが立っている可能性がある */
+               /* その場合attrのMSBも立っているのでこれで識別する */
 /* check */
-               if (iskanji(*s) && !(a & 0x80))
+               if (!(a & AF_TILE1) && iskanji(*s))
                {
-                       int nc1 = *s++;
-                       int nc2 = *s;
+                       char nc1 = *s++;
+                       char nc2 = *s;
 
-                       int na1 = (a | KANJI1);
-                       int na2 = (a | KANJI2);
+                       byte na1 = (a | AF_KANJI1);
+                       byte na2 = (a | AF_KANJI2);
 
                        if((--n == 0) || !nc2) break;
-#ifdef USE_TRANSPARENCY
+
                        if(scr_aa[x++] == na1 && scr_aa[x] == na2 &&
                           scr_cc[x - 1] == nc1 && scr_cc[x] == nc2 &&
                           (scr_taa[x - 1] == 0) && (scr_taa[x]==0) &&
                           (scr_tcc[x - 1] == 0) && (scr_tcc[x]==0)    )
                                continue;
-#else
-                       if(scr_aa[x++] == na1 && scr_aa[x] == na2 &&
-                          scr_cc[x - 1] == nc1 && scr_cc[x] == nc2) continue;
-#endif
+
                        scr_aa[x - 1] = na1;
                        scr_aa[x] = na2;
                        scr_cc[x - 1] = nc1;
@@ -754,35 +774,22 @@ void Term_queue_chars(int x, int y, int n, byte a, cptr s)
                else
                {
 #endif
-               int oa = scr_aa[x];
-               int oc = scr_cc[x];
+               TERM_COLOR oa = scr_aa[x];
+               char oc = scr_cc[x];
 
-#ifdef USE_TRANSPARENCY
-
-               int ota = scr_taa[x];
-               int otc = scr_tcc[x];
+               TERM_COLOR ota = scr_taa[x];
+               char otc = scr_tcc[x];
 
                /* Hack -- Ignore non-changes */
                if ((oa == a) && (oc == *s) && (ota == 0) && (otc == 0)) continue;
 
-#else /* USE_TRANSPARENCY */
-
-               /* Hack -- Ignore non-changes */
-               if ((oa == a) && (oc == *s)) continue;
-
-#endif /* USE_TRANSPARENCY */
-
                /* Save the "literal" information */
                scr_aa[x] = a;
                scr_cc[x] = *s;
 
-#ifdef USE_TRANSPARENCY
-
                scr_taa[x] = 0;
                scr_tcc[x] = 0;
 
-#endif /* USE_TRANSPARENCY */
-
                /* Note the "range" of window updates */
                if (x1 < 0) x1 = x;
                x2 = x;
@@ -793,18 +800,18 @@ void Term_queue_chars(int x, int y, int n, byte a, cptr s)
 
 #ifdef JP
        /*
-        * Á´³Ñʸ»ú¤Îº¸È¾Ê¬¤Çɽ¼¨¤ò½ªÎ»¤¹¤ë¾ì¹ç¡¢
-        * ½Å¤Ê¤Ã¤¿Ê¸»ú¤Î±¦Éôʬ¤ò¾Ãµî¡£
-        * (¾ò·ïÄɲ᧥¿¥¤¥ë¤Î1ʸ»úÌܤǤʤ¤»ö¤ò³Î¤«¤á¤ë¤è¤¦¤Ë¡£)
+        * 全角文字の左半分で表示を終了する場合、
+        * 重なった文字の右部分を消去。
+        * (条件追加:タイルの1文字目でない事を確かめるように。)
         */
        {
 
                int w, h;
                Term_get_size(&w, &h);
-               if (x != w && !(scr_aa[x] & 0x80) && (scr_aa[x] & KANJI2))
+               if (x != w && !(scr_aa[x] & AF_TILE1) && (scr_aa[x] & AF_KANJI2))
                {
                        scr_cc[x] = ' ';
-                        scr_aa[x] &= KANJIC;
+                       scr_aa[x] &= AF_KANJIC;
                        if (x1 < 0) x1 = x;
                        x2 = x;
                }
@@ -814,12 +821,12 @@ void Term_queue_chars(int x, int y, int n, byte a, cptr s)
        if (x1 >= 0)
        {
                /* Check for new min/max row info */
-               if (y < Term->y1) Term->y1 = y;
-               if (y > Term->y2) Term->y2 = y;
+               if (y < Term->y1) Term->y1 = (byte_hack)y;
+               if (y > Term->y2) Term->y2 = (byte_hack)y;
 
                /* Check for new min/max col info in this row */
-               if (x1 < Term->x1[y]) Term->x1[y] = x1;
-               if (x2 > Term->x2[y]) Term->x2[y] = x2;
+               if (x1 < Term->x1[y]) Term->x1[y] = (byte_hack)x1;
+               if (x2 > Term->x2[y]) Term->x2[y] = (byte_hack)x2;
        }
 }
 
@@ -833,47 +840,43 @@ void Term_queue_chars(int x, int y, int n, byte a, cptr s)
  *
  * Display text using "Term_pict()"
  */
-static void Term_fresh_row_pict(int y, int x1, int x2)
+static void Term_fresh_row_pict(TERM_LEN y, TERM_LEN x1, TERM_LEN x2)
 {
-       int x;
+       TERM_LEN x;
 
-       byte *old_aa = Term->old->a[y];
+       TERM_COLOR *old_aa = Term->old->a[y];
        char *old_cc = Term->old->c[y];
 
-       byte *scr_aa = Term->scr->a[y];
+       TERM_COLOR *scr_aa = Term->scr->a[y];
        char *scr_cc = Term->scr->c[y];
 
-#ifdef USE_TRANSPARENCY
-
-       byte *old_taa = Term->old->ta[y];
+       TERM_COLOR *old_taa = Term->old->ta[y];
        char *old_tcc = Term->old->tc[y];
 
-       byte *scr_taa = Term->scr->ta[y];
+       TERM_COLOR *scr_taa = Term->scr->ta[y];
        char *scr_tcc = Term->scr->tc[y];
 
-       byte ota;
+       TERM_COLOR ota;
        char otc;
 
-       byte nta;
+       TERM_COLOR nta;
        char ntc;
 
-#endif /* USE_TRANSPARENCY */
-
 
        /* Pending length */
-       int fn = 0;
+       TERM_LEN fn = 0;
 
        /* Pending start */
-       int fx = 0;
+       TERM_LEN fx = 0;
 
-       byte oa;
+       TERM_COLOR oa;
        char oc;
 
-       byte na;
+       TERM_COLOR na;
        char nc;
 
 #ifdef JP
-       /* Á´³Ñʸ»ú¤Î£²¥Ð¥¤¥ÈÌܤ«¤É¤¦¤« */
+       /* 全角文字の2バイト目かどうか */
        int kanji = 0;
 #endif
        /* Scan "modified" columns */
@@ -890,19 +893,18 @@ static void Term_fresh_row_pict(int y, int x1, int x2)
 #ifdef JP
                if (kanji)
                {
-                       /* Á´³Ñʸ»ú£²¥Ð¥¤¥ÈÌÜ */
+                       /* 全角文字2バイト目 */
                        kanji = 0;
                        old_aa[x] = na;
                        old_cc[x] = nc;
                        fn++;
                        continue;
                }
-               /* Æüìʸ»ú¤È¤·¤ÆMSB¤¬Î©¤Ã¤Æ¤¤¤ë²ÄǽÀ­¤¬¤¢¤ë */
-               /* ¤½¤Î¾ì¹çattr¤ÎMSB¤âΩ¤Ã¤Æ¤¤¤ë¤Î¤Ç¤³¤ì¤Ç¼±Ê̤¹¤ë */
+               /* 特殊文字としてMSBが立っている可能性がある */
+               /* その場合attrのMSBも立っているのでこれで識別する */
 /* check */
-               kanji = (iskanji(nc) && !(na & 0x80));
+               kanji = (iskanji(nc) && !(na & AF_TILE1));
 #endif
-#ifdef USE_TRANSPARENCY
 
                ota = old_taa[x];
                otc = old_tcc[x];
@@ -914,45 +916,26 @@ static void Term_fresh_row_pict(int y, int x1, int x2)
 #ifdef JP
                if ((na == oa) && (nc == oc) && (nta == ota) && (ntc == otc)
                    &&(!kanji || (scr_aa[x + 1] == old_aa[x + 1] &&
-                                 scr_cc[x + 1] == old_cc[x + 1] &&
-                                  scr_taa[x + 1] == old_taa[x + 1] &&
-                                  scr_tcc[x + 1] == old_tcc[x + 1])))
+                                 scr_cc[x + 1] == old_cc[x + 1] &&
+                                 scr_taa[x + 1] == old_taa[x + 1] &&
+                                 scr_tcc[x + 1] == old_tcc[x + 1])))
 #else
                if ((na == oa) && (nc == oc) && (nta == ota) && (ntc == otc))
 #endif
-
-
-#else /* USE_TRANSPARENCY */
-
-               /* Handle unchanged grids */
-#ifdef JP
-               if ((na == oa) && (nc == oc) &&
-                   (!kanji || (scr_aa[x + 1] == old_aa[x + 1] &&
-                               scr_cc[x + 1] == old_cc[x + 1])))
-#else
-               if ((na == oa) && (nc == oc))
-#endif
-
-
-#endif /* USE_TRANSPARENCY */
                {
                        /* Flush */
                        if (fn)
                        {
                                /* Draw pending attr/char pairs */
-#ifdef USE_TRANSPARENCY
                                (void)((*Term->pict_hook)(fx, y, fn,
-                                      &scr_aa[fx], &scr_cc[fx],&scr_taa[fx], &scr_tcc[fx]));
-#else /* USE_TRANSPARENCY */
-                               (void)((*Term->pict_hook)(fx, y, fn, &scr_aa[fx], &scr_cc[fx]));
-#endif /* USE_TRANSPARENCY */
+                                      &scr_aa[fx], &scr_cc[fx], &scr_taa[fx], &scr_tcc[fx]));
 
                                /* Forget */
                                fn = 0;
                        }
 
 #ifdef JP
-                       /* Á´³Ñʸ»ú¤Î»þ¤ÏºÆ³«°ÌÃ֤ϡܣ± */
+                       /* 全角文字の時は再開位置は+1 */
                        if(kanji)
                        {
                                x++;
@@ -967,10 +950,8 @@ static void Term_fresh_row_pict(int y, int x1, int x2)
                old_aa[x] = na;
                old_cc[x] = nc;
 
-#ifdef USE_TRANSPARENCY
                old_taa[x] = nta;
                old_tcc[x] = ntc;
-#endif /* USE_TRANSPARENCY */
 
                /* Restart and Advance */
                if (fn++ == 0) fx = x;
@@ -980,12 +961,8 @@ static void Term_fresh_row_pict(int y, int x1, int x2)
        if (fn)
        {
                /* Draw pending attr/char pairs */
-#ifdef USE_TRANSPARENCY
                (void)((*Term->pict_hook)(fx, y, fn,
                        &scr_aa[fx], &scr_cc[fx], &scr_taa[fx], &scr_tcc[fx]));
-#else /* USE_TRANSPARENCY */
-               (void)((*Term->pict_hook)(fx, y, fn, &scr_aa[fx], &scr_cc[fx]));
-#endif /* USE_TRANSPARENCY */
        }
 }
 
@@ -997,27 +974,25 @@ static void Term_fresh_row_pict(int y, int x1, int x2)
  * Display text using "Term_text()" and "Term_wipe()",
  * but use "Term_pict()" for high-bit attr/char pairs
  */
-static void Term_fresh_row_both(int y, int x1, int x2)
+static void Term_fresh_row_both(TERM_LEN y, int x1, int x2)
 {
-       int x;
+       TERM_LEN x;
 
-       byte *old_aa = Term->old->a[y];
+       TERM_COLOR *old_aa = Term->old->a[y];
        char *old_cc = Term->old->c[y];
 
-       byte *scr_aa = Term->scr->a[y];
+       TERM_COLOR *scr_aa = Term->scr->a[y];
        char *scr_cc = Term->scr->c[y];
 
-#ifdef USE_TRANSPARENCY
-       byte *old_taa = Term->old->ta[y];
+       TERM_COLOR *old_taa = Term->old->ta[y];
        char *old_tcc = Term->old->tc[y];
-       byte *scr_taa = Term->scr->ta[y];
+       TERM_COLOR *scr_taa = Term->scr->ta[y];
        char *scr_tcc = Term->scr->tc[y];
 
-       byte ota;
+       TERM_COLOR ota;
        char otc;
-       byte nta;
+       TERM_COLOR nta;
        char ntc;
-#endif /* USE_TRANSPARENCY */
 
        /* The "always_text" flag */
        int always_text = Term->always_text;
@@ -1031,14 +1006,14 @@ static void Term_fresh_row_both(int y, int x1, int x2)
        /* Pending attr */
        byte fa = Term->attr_blank;
 
-       byte oa;
+       TERM_COLOR oa;
        char oc;
 
-       byte na;
+       TERM_COLOR na;
        char nc;
 
 #ifdef JP
-       /* Á´³Ñʸ»ú¤Î£²¥Ð¥¤¥ÈÌܤ«¤É¤¦¤« */
+       /* 全角文字の2バイト目かどうか */
        int kanji = 0;
 #endif
        /* Scan "modified" columns */
@@ -1055,20 +1030,19 @@ static void Term_fresh_row_both(int y, int x1, int x2)
 #ifdef JP
                if (kanji)
                {
-                       /* Á´³Ñʸ»ú£²¥Ð¥¤¥ÈÌÜ */
+                       /* 全角文字2バイト目 */
                        kanji = 0;
                        old_aa[x] = na;
                        old_cc[x] = nc;
                        fn++;
                        continue;
                }
-               /* Æüìʸ»ú¤È¤·¤ÆMSB¤¬Î©¤Ã¤Æ¤¤¤ë²ÄǽÀ­¤¬¤¢¤ë */
-               /* ¤½¤Î¾ì¹çattr¤ÎMSB¤âΩ¤Ã¤Æ¤¤¤ë¤Î¤Ç¤³¤ì¤Ç¼±Ê̤¹¤ë */
+               /* 特殊文字としてMSBが立っている可能性がある */
+               /* その場合attrのMSBも立っているのでこれで識別する */
 /* check */
 /*             kanji = (iskanji(nc));  */
-               kanji = (iskanji(nc) && !(na & 0x80));
+               kanji = (iskanji(nc) && !(na & AF_TILE1));
 #endif
-#ifdef USE_TRANSPARENCY
 
                ota = old_taa[x];
                otc = old_tcc[x];
@@ -1080,28 +1054,12 @@ static void Term_fresh_row_both(int y, int x1, int x2)
 #ifdef JP
                if ((na == oa) && (nc == oc) && (nta == ota) && (ntc == otc)&&
                    (!kanji || (scr_aa[x + 1] == old_aa[x + 1] &&
-                               scr_cc[x + 1] == old_cc[x + 1] &&
-                                scr_taa[x + 1] == old_taa[x + 1] &&
-                                scr_tcc[x + 1] == old_tcc[x + 1])))
+                               scr_cc[x + 1] == old_cc[x + 1] &&
+                               scr_taa[x + 1] == old_taa[x + 1] &&
+                               scr_tcc[x + 1] == old_tcc[x + 1])))
 #else
                if ((na == oa) && (nc == oc) && (nta == ota) && (ntc == otc))
 #endif
-
-
-#else /* USE_TRANSPARENCY */
-
-               /* Handle unchanged grids */
-#ifdef JP
-               if ((na == oa) && (nc == oc) &&
-                   (!kanji || (scr_aa[x + 1] == old_aa[x + 1] &&
-                               scr_cc[x + 1] == old_cc[x + 1])))
-#else
-               if ((na == oa) && (nc == oc))
-#endif
-
-
-#endif /* USE_TRANSPARENCY */
-
                {
                        /* Flush */
                        if (fn)
@@ -1109,18 +1067,12 @@ static void Term_fresh_row_both(int y, int x1, int x2)
                                /* Draw pending chars (normal) */
                                if (fa || always_text)
                                {
-#ifdef CHUUKEI
-                       send_text_to_chuukei_server(fx, y, fn, fa, &scr_cc[fx]);
-#endif
                                        (void)((*Term->text_hook)(fx, y, fn, fa, &scr_cc[fx]));
                                }
 
                                /* Draw pending chars (black) */
                                else
                                {
-#ifdef CHUUKEI
-                       send_wipe_to_chuukei_server(fx, y, fn);
-#endif
                                        (void)((*Term->wipe_hook)(fx, y, fn));
                                }
 
@@ -1129,7 +1081,7 @@ static void Term_fresh_row_both(int y, int x1, int x2)
                        }
 
 #ifdef JP
-                       /* Á´³Ñʸ»ú¤Î»þ¤ÏºÆ³«°ÌÃ֤ϡܣ± */
+                       /* 全角文字の時は再開位置は+1 */
                        if(kanji)
                        {
                                x++;
@@ -1145,18 +1097,14 @@ static void Term_fresh_row_both(int y, int x1, int x2)
                old_aa[x] = na;
                old_cc[x] = nc;
 
-#ifdef USE_TRANSPARENCY
-
                old_taa[x] = nta;
                old_tcc[x] = ntc;
 
-#endif /* USE_TRANSPARENCY */
-
                /* 2nd byte of bigtile */
-               if (na == 255) continue;
+               if ((na & AF_BIGTILE2) == AF_BIGTILE2) continue;
 
                /* Handle high-bit attr/chars */
-               if ((na & 0x80) && (nc & 0x80))
+               if ((na & AF_TILE1) && (nc & 0x80))
                {
                        /* Flush */
                        if (fn)
@@ -1164,18 +1112,12 @@ static void Term_fresh_row_both(int y, int x1, int x2)
                                /* Draw pending chars (normal) */
                                if (fa || always_text)
                                {
-#ifdef CHUUKEI
-                       send_text_to_chuukei_server(fx, y, fn, fa, &scr_cc[fx]);
-#endif
                                        (void)((*Term->text_hook)(fx, y, fn, fa, &scr_cc[fx]));
                                }
 
                                /* Draw pending chars (black) */
                                else
                                {
-#ifdef CHUUKEI
-                       send_wipe_to_chuukei_server(fx, y, fn);
-#endif
                                        (void)((*Term->wipe_hook)(fx, y, fn));
                                }
 
@@ -1183,25 +1125,16 @@ static void Term_fresh_row_both(int y, int x1, int x2)
                                fn = 0;
                        }
 
-#ifdef USE_TRANSPARENCY
-
                        /* Hack -- Draw the special attr/char pair */
                        (void)((*Term->pict_hook)(x, y, 1, &na, &nc, &nta, &ntc));
 
-#else /* USE_TRANSPARENCY */
-
-                       /* Hack -- Draw the special attr/char pair */
-                       (void)((*Term->pict_hook)(x, y, 1, &na, &nc));
-
-#endif /* USE_TRANSPARENCY */
-
                        /* Skip */
                        continue;
                }
 
                /* Notice new color */
 #ifdef JP
-               if (fa != (na & KANJIC))
+               if (fa != (na & AF_KANJIC))
 #else
                if (fa != na)
 #endif
@@ -1213,18 +1146,12 @@ static void Term_fresh_row_both(int y, int x1, int x2)
                                /* Draw the pending chars */
                                if (fa || always_text)
                                {
-#ifdef CHUUKEI
-                       send_text_to_chuukei_server(fx, y, fn, fa, &scr_cc[fx]);
-#endif
                                        (void)((*Term->text_hook)(fx, y, fn, fa, &scr_cc[fx]));
                                }
 
                                /* Hack -- Erase "leading" spaces */
                                else
                                {
-#ifdef CHUUKEI
-                       send_wipe_to_chuukei_server(fx, y, fn);
-#endif
                                        (void)((*Term->wipe_hook)(fx, y, fn));
                                }
 
@@ -1234,7 +1161,7 @@ static void Term_fresh_row_both(int y, int x1, int x2)
 
                        /* Save the new color */
 #ifdef JP
-                       fa = (na & KANJIC);
+                       fa = (na & AF_KANJIC);
 #else
                        fa = na;
 #endif
@@ -1251,18 +1178,12 @@ static void Term_fresh_row_both(int y, int x1, int x2)
                /* Draw pending chars (normal) */
                if (fa || always_text)
                {
-#ifdef CHUUKEI
-                       send_text_to_chuukei_server(fx, y, fn, fa, &scr_cc[fx]);
-#endif
                        (void)((*Term->text_hook)(fx, y, fn, fa, &scr_cc[fx]));
                }
 
                /* Draw pending chars (black) */
                else
                {
-#ifdef CHUUKEI
-                       send_wipe_to_chuukei_server(fx, y, fn);
-#endif
                        (void)((*Term->wipe_hook)(fx, y, fn));
                }
        }
@@ -1274,14 +1195,14 @@ static void Term_fresh_row_both(int y, int x1, int x2)
  *
  * Display text using "Term_text()" and "Term_wipe()"
  */
-static void Term_fresh_row_text(int y, int x1, int x2)
+static void Term_fresh_row_text(TERM_LEN y, TERM_LEN x1, TERM_LEN x2)
 {
-       int x;
+       TERM_LEN x;
 
-       byte *old_aa = Term->old->a[y];
+       TERM_COLOR *old_aa = Term->old->a[y];
        char *old_cc = Term->old->c[y];
 
-       byte *scr_aa = Term->scr->a[y];
+       TERM_COLOR *scr_aa = Term->scr->a[y];
        char *scr_cc = Term->scr->c[y];
 
        /* The "always_text" flag */
@@ -1296,18 +1217,18 @@ static void Term_fresh_row_text(int y, int x1, int x2)
        /* Pending attr */
        byte fa = Term->attr_blank;
 
-       byte oa;
+       TERM_COLOR oa;
        char oc;
 
-       byte na;
+       TERM_COLOR na;
        char nc;
 
 #ifdef JP
-       /* Á´³Ñʸ»ú¤Î£²¥Ð¥¤¥ÈÌܤ«¤É¤¦¤« */
+       /* 全角文字の2バイト目かどうか */
        int kanji = 0;
 
        for (x = 0; x < x1; x++)
-               if (!(old_aa[x] & 0x80) && iskanji(old_cc[x]))
+               if (!(old_aa[x] & AF_TILE1) && iskanji(old_cc[x]))
                {
                        if (x == x1 - 1)
                        {
@@ -1332,23 +1253,23 @@ static void Term_fresh_row_text(int y, int x1, int x2)
 #ifdef JP
                if (kanji)
                {
-                       /* Á´³Ñʸ»ú£²¥Ð¥¤¥ÈÌÜ */
+                       /* 全角文字2バイト目 */
                        kanji = 0;
                        old_aa[x] = na;
                        old_cc[x] = nc;
                        fn++;
                        continue;
                }
-               /* Æüìʸ»ú¤È¤·¤ÆMSB¤¬Î©¤Ã¤Æ¤¤¤ë²ÄǽÀ­¤¬¤¢¤ë */
-               /* ¤½¤Î¾ì¹çattr¤ÎMSB¤âΩ¤Ã¤Æ¤¤¤ë¤Î¤Ç¤³¤ì¤Ç¼±Ê̤¹¤ë */
+               /* 特殊文字としてMSBが立っている可能性がある */
+               /* その場合attrのMSBも立っているのでこれで識別する */
 /* check */
-               kanji = (iskanji(nc) && !(na & 0x80));
+               kanji = (iskanji(nc) && !(na & AF_TILE1));
 #endif
                /* Handle unchanged grids */
 #ifdef JP
                if ((na == oa) && (nc == oc) &&
                    (!kanji || (scr_aa[x + 1] == old_aa[x + 1] &&
-                               scr_cc[x + 1] == old_cc[x + 1])))
+                               scr_cc[x + 1] == old_cc[x + 1])))
 #else
                if ((na == oa) && (nc == oc))
 #endif
@@ -1360,18 +1281,12 @@ static void Term_fresh_row_text(int y, int x1, int x2)
                                /* Draw pending chars (normal) */
                                if (fa || always_text)
                                {
-#ifdef CHUUKEI
-                       send_text_to_chuukei_server(fx, y, fn, fa, &scr_cc[fx]);
-#endif
                                        (void)((*Term->text_hook)(fx, y, fn, fa, &scr_cc[fx]));
                                }
 
                                /* Draw pending chars (black) */
                                else
                                {
-#ifdef CHUUKEI
-                       send_wipe_to_chuukei_server(fx, y, fn);
-#endif
                                        (void)((*Term->wipe_hook)(fx, y, fn));
                                }
 
@@ -1380,7 +1295,7 @@ static void Term_fresh_row_text(int y, int x1, int x2)
                        }
 
 #ifdef JP
-                       /* Á´³Ñʸ»ú¤Î»þ¤ÏºÆ³«°ÌÃ֤ϡܣ± */
+                       /* 全角文字の時は再開位置は+1 */
                        if(kanji)
                        {
                                x++;
@@ -1398,7 +1313,7 @@ static void Term_fresh_row_text(int y, int x1, int x2)
 
                /* Notice new color */
 #ifdef JP
-               if (fa != (na & KANJIC))
+               if (fa != (na & AF_KANJIC))
 #else
                if (fa != na)
 #endif
@@ -1410,18 +1325,12 @@ static void Term_fresh_row_text(int y, int x1, int x2)
                                /* Draw the pending chars */
                                if (fa || always_text)
                                {
-#ifdef CHUUKEI
-                       send_text_to_chuukei_server(fx, y, fn, fa, &scr_cc[fx]);
-#endif
                                        (void)((*Term->text_hook)(fx, y, fn, fa, &scr_cc[fx]));
                                }
 
                                /* Hack -- Erase "leading" spaces */
                                else
                                {
-#ifdef CHUUKEI
-                       send_wipe_to_chuukei_server(fx, y, fn);
-#endif
                                        (void)((*Term->wipe_hook)(fx, y, fn));
                                }
 
@@ -1431,7 +1340,7 @@ static void Term_fresh_row_text(int y, int x1, int x2)
 
                        /* Save the new color */
 #ifdef JP
-                       fa = (na & KANJIC);
+                       fa = (na & AF_KANJIC);
 #else
                        fa = na;
 #endif
@@ -1448,18 +1357,12 @@ static void Term_fresh_row_text(int y, int x1, int x2)
                /* Draw pending chars (normal) */
                if (fa || always_text)
                {
-#ifdef CHUUKEI
-                       send_text_to_chuukei_server(fx, y, fn, fa, &scr_cc[fx]);
-#endif
                        (void)((*Term->text_hook)(fx, y, fn, fa, &scr_cc[fx]));
                }
 
                /* Draw pending chars (black) */
                else
                {
-#ifdef CHUUKEI
-                       send_wipe_to_chuukei_server(fx, y, fn);
-#endif
                        (void)((*Term->wipe_hook)(fx, y, fn));
                }
        }
@@ -1565,7 +1468,7 @@ static void Term_fresh_row_text(int y, int x1, int x2)
  * On systems with a "soft" cursor, we must explicitly erase the cursor
  * before flushing the output, if needed, to prevent a "jumpy" refresh.
  * The actual method for this is horrible, but there is very little that
- * we can do to simplify it efficiently.  XXX XXX XXX
+ * we can do to simplify it efficiently.  
  *
  * On systems with a "hard" cursor, we will "hide" the cursor before
  * flushing the output, if needed, to avoid a "flickery" refresh.  It
@@ -1583,7 +1486,7 @@ static void Term_fresh_row_text(int y, int x1, int x2)
  */
 errr Term_fresh(void)
 {
-       int x, y;
+       TERM_LEN x, y;
 
        int w = Term->wid;
        int h = Term->hgt;
@@ -1593,7 +1496,9 @@ errr Term_fresh(void)
 
        term_win *old = Term->old;
        term_win *scr = Term->scr;
-
+       
+       /* Before initialize (Advice from Mr.shimitei)*/
+       if (!old || !scr) return (1);
 
        /* Do nothing unless "mapped" */
        if (!Term->mapped_flag) return (1);
@@ -1612,13 +1517,6 @@ errr Term_fresh(void)
        }
 
 
-       /* Paranoia -- use "fake" hooks to prevent core dumps */
-       if (!Term->curs_hook) Term->curs_hook = Term_curs_hack;
-       if (!Term->wipe_hook) Term->wipe_hook = Term_wipe_hack;
-       if (!Term->text_hook) Term->text_hook = Term_text_hack;
-       if (!Term->pict_hook) Term->pict_hook = Term_pict_hack;
-
-
        /* Handle "total erase" */
        if (Term->total_erase)
        {
@@ -1634,16 +1532,12 @@ errr Term_fresh(void)
                /* Wipe each row */
                for (y = 0; y < h; y++)
                {
-                       byte *aa = old->a[y];
+                       TERM_COLOR *aa = old->a[y];
                        char *cc = old->c[y];
 
-#ifdef USE_TRANSPARENCY
-
-                       byte *taa = old->ta[y];
+                       TERM_COLOR *taa = old->ta[y];
                        char *tcc = old->tc[y];
 
-#endif /* USE_TRANSPARENCY */
-
 
                        /* Wipe each column */
                        for (x = 0; x < w; x++)
@@ -1652,13 +1546,8 @@ errr Term_fresh(void)
                                *aa++ = na;
                                *cc++ = nc;
 
-#ifdef USE_TRANSPARENCY
-
                                *taa++ = na;
                                *tcc++ = nc;
-
-#endif /* USE_TRANSPARENCY */
-
                        }
                }
 
@@ -1685,64 +1574,50 @@ errr Term_fresh(void)
                if (!old->cu && old->cv)
                {
                        int csize = 1;
-                       int tx = old->cx;
-                       int ty = old->cy;
+                       TERM_LEN tx = old->cx;
+                       TERM_LEN ty = old->cy;
 
-                       byte *old_aa = old->a[ty];
+                       TERM_COLOR *old_aa = old->a[ty];
                        char *old_cc = old->c[ty];
 
-#ifdef USE_TRANSPARENCY
-                       byte *old_taa = old->ta[ty];
+                       TERM_COLOR *old_taa = old->ta[ty];
                        char *old_tcc = old->tc[ty];
 
-                       byte ota = old_taa[tx];
+                       TERM_COLOR ota = old_taa[tx];
                        char otc = old_tcc[tx];
-#endif /* USE_TRANSPARENCY */
 
 #ifdef JP
-                       if (tx + 1 < Term->wid && !(old_aa[tx] & 0x80)
+                       if (tx + 1 < Term->wid && !(old_aa[tx] & AF_TILE1)
                            && iskanji(old_cc[tx]))
                                csize = 2;
-#ifdef WINDOWS
-                       if (old_cc[tx] == 127 && use_bigtile) csize = 2;
-#endif
 #endif
                        /* Hack -- use "Term_pict()" always */
                        if (Term->always_pict)
                        {
-#ifdef USE_TRANSPARENCY
                                (void)((*Term->pict_hook)(tx, ty, csize, &old_aa[tx], &old_cc[tx], &ota, &otc));
-#else /* USE_TRANSPARENCY */
-                               (void)((*Term->pict_hook)(tx, ty, csize, &old_aa[tx], &old_cc[tx]));
-#endif /* USE_TRANSPARENCY */
                        }
 
                        /* Hack -- use "Term_pict()" sometimes */
-                       else if (Term->higher_pict && (old_aa[tx] & 0x80) && (old_cc[tx] & 0x80))
+                       else if (Term->higher_pict && (old_aa[tx] & AF_TILE1) && (old_cc[tx] & 0x80))
                        {
-#ifdef USE_TRANSPARENCY
                                (void)((*Term->pict_hook)(tx, ty, 1, &old_aa[tx], &old_cc[tx], &ota, &otc));
-#else /* USE_TRANSPARENCY */
-                               (void)((*Term->pict_hook)(tx, ty, 1, &old_aa[tx], &old_cc[tx]));
-#endif /* USE_TRANSPARENCY */
                        }
-
-                       /* Hack -- restore the actual character */
-                       else if (old_aa[tx] || Term->always_text)
-                       {
-
-#ifdef CHUUKEI
-                               send_text_to_chuukei_server(tx, ty, csize, (old_aa[tx] & 0xf), &old_cc[tx]);
-#endif
-                               (void)((*Term->text_hook)(tx, ty, csize, (old_aa[tx] & 0xf), &old_cc[tx]));
+                       
+                       /*
+                        * Hack -- restore the actual character
+                        * 元の文字の描画範囲がカーソルより小さいと、
+                        * 上書きされなかった部分がゴミとして残る。
+                        * wipe_hook でカーソルを消去して text_hook で書き直す。
+                        */
+                       else if (old_aa[tx] || Term->always_text)
+                       {
+                               (void)((*Term->wipe_hook)(tx, ty, 1));
+                               (void)((*Term->text_hook)(tx, ty, csize, (unsigned char) (old_aa[tx] & 0xf), &old_cc[tx]));
                        }
 
                        /* Hack -- erase the grid */
                        else
                        {
-#ifdef CHUUKEI
-                       send_wipe_to_chuukei_server(tx, ty, 1);
-#endif
                                (void)((*Term->wipe_hook)(tx, ty, 1));
                        }
                }
@@ -1782,8 +1657,8 @@ errr Term_fresh(void)
                /* Scan the "modified" rows */
                for (y = y1; y <= y2; ++y)
                {
-                       int x1 = Term->x1[y];
-                       int x2 = Term->x2[y];
+                       TERM_LEN x1 = Term->x1[y];
+                       TERM_LEN x2 = Term->x2[y];
 
                        /* Flush each "modified" row */
                        if (x1 <= x2)
@@ -1810,7 +1685,7 @@ errr Term_fresh(void)
                                }
 
                                /* This row is all done */
-                               Term->x1[y] = w;
+                               Term->x1[y] = (byte_hack)w;
                                Term->x2[y] = 0;
 
                                /* Hack -- Flush that row (if allowed) */
@@ -1819,7 +1694,7 @@ errr Term_fresh(void)
                }
 
                /* No rows are invalid */
-               Term->y1 = h;
+               Term->y1 = (byte_hack)h;
                Term->y2 = 0;
        }
 
@@ -1830,11 +1705,23 @@ errr Term_fresh(void)
                /* Draw the cursor */
                if (!scr->cu && scr->cv)
                {
-#ifdef CHUUKEI
-                 send_curs_to_chuukei_server(scr->cx, scr->cy);
+#ifdef JP
+                       if ((scr->cx + 1 < w) &&
+                           ((old->a[scr->cy][scr->cx + 1] & AF_BIGTILE2) == AF_BIGTILE2 ||
+                            (!(old->a[scr->cy][scr->cx] & AF_TILE1) &&
+                             iskanji(old->c[scr->cy][scr->cx]))))
+#else
+                       if ((scr->cx + 1 < w) && (old->a[scr->cy][scr->cx + 1] & AF_BIGTILE2) == AF_BIGTILE2)
 #endif
-                       /* Call the cursor display routine */
-                       (void)((*Term->curs_hook)(scr->cx, scr->cy));
+                       {
+                               /* Double width cursor for the Bigtile mode */
+                               (void)((*Term->bigcurs_hook)(scr->cx, scr->cy));
+                       }
+                       else
+                       {
+                               /* Call the cursor display routine */
+                               (void)((*Term->curs_hook)(scr->cx, scr->cy));
+                       }
                }
        }
 
@@ -1844,9 +1731,6 @@ errr Term_fresh(void)
                /* The cursor is useless, hide it */
                if (scr->cu)
                {
-#ifdef CHUUKEI
-                 send_curs_to_chuukei_server(w - 1, scr->cy);
-#endif
                        /* Paranoia -- Put the cursor NEAR where it belongs */
                        (void)((*Term->curs_hook)(w - 1, scr->cy));
 
@@ -1857,9 +1741,6 @@ errr Term_fresh(void)
                /* The cursor is invisible, hide it */
                else if (!scr->cv)
                {
-#ifdef CHUUKEI
-                 send_curs_to_chuukei_server(scr->cx, scr->cy);
-#endif
                        /* Paranoia -- Put the cursor where it belongs */
                        (void)((*Term->curs_hook)(scr->cx, scr->cy));
 
@@ -1870,9 +1751,6 @@ errr Term_fresh(void)
                /* The cursor is visible, display it correctly */
                else
                {
-#ifdef CHUUKEI
-                 send_curs_to_chuukei_server(scr->cx, scr->cy);
-#endif
                        /* Put the cursor where it belongs */
                        (void)((*Term->curs_hook)(scr->cx, scr->cy));
 
@@ -1911,7 +1789,7 @@ errr Term_set_cursor(int v)
        if (Term->scr->cv == v) return (1);
 
        /* Change */
-       Term->scr->cv = v;
+       Term->scr->cv = (bool_hack)v;
 
        /* Success */
        return (0);
@@ -1923,7 +1801,7 @@ errr Term_set_cursor(int v)
  *
  * Note -- "illegal" requests do not move the cursor.
  */
-errr Term_gotoxy(int x, int y)
+errr Term_gotoxy(TERM_LEN x, TERM_LEN y)
 {
        int w = Term->wid;
        int h = Term->hgt;
@@ -1933,8 +1811,8 @@ errr Term_gotoxy(int x, int y)
        if ((y < 0) || (y >= h)) return (-1);
 
        /* Remember the cursor */
-       Term->scr->cx = x;
-       Term->scr->cy = y;
+       Term->scr->cx = (byte_hack)x;
+       Term->scr->cy = (byte_hack)y;
 
        /* The cursor is not useless */
        Term->scr->cu = 0;
@@ -1949,7 +1827,7 @@ errr Term_gotoxy(int x, int y)
  * Do not change the cursor position
  * No visual changes until "Term_fresh()".
  */
-errr Term_draw(int x, int y, byte a, char c)
+errr Term_draw(TERM_LEN x, TERM_LEN y, TERM_COLOR a, char c)
 {
        int w = Term->wid;
        int h = Term->hgt;
@@ -1962,11 +1840,7 @@ errr Term_draw(int x, int y, byte a, char c)
        if (!c) return (-2);
 
        /* Queue it for later */
-#ifdef USE_TRANSPARENCY
        Term_queue_char(x, y, a, c, 0, 0);
-#else /* USE_TRANSPARENCY */
-       Term_queue_char(x, y, a, c);
-#endif /* USE_TRANSPARENCY */
 
        /* Success */
        return (0);
@@ -1989,9 +1863,9 @@ errr Term_draw(int x, int y, byte a, char c)
  * positive value, future calls to either function will
  * return negative ones.
  */
-errr Term_addch(byte a, char c)
+errr Term_addch(TERM_COLOR a, char c)
 {
-       int w = Term->wid;
+       TERM_LEN w = Term->wid;
 
        /* Handle "unusable" cursor */
        if (Term->scr->cu) return (-1);
@@ -2000,11 +1874,7 @@ errr Term_addch(byte a, char c)
        if (!c) return (-2);
 
        /* Queue the given character for display */
-#ifdef USE_TRANSPARENCY
        Term_queue_char(Term->scr->cx, Term->scr->cy, a, c, 0, 0);
-#else /* USE_TRANSPARENCY */
-       Term_queue_char(Term->scr->cx, Term->scr->cy, a, c);
-#endif /* USE_TRANSPARENCY */
 
        /* Advance the cursor */
        Term->scr->cx++;
@@ -2021,6 +1891,41 @@ errr Term_addch(byte a, char c)
 
 
 /*
+ * Bigtile version of Term_addch().
+ *
+ * If use_bigtile is FALSE, simply call Term_addch() .
+ *
+ * Otherwise, queue a pair of attr/char for display at the current
+ * cursor location, and advance the cursor to the right by two.
+ */
+errr Term_add_bigch(TERM_COLOR a, char c)
+{
+       if (!use_bigtile) return Term_addch(a, c);
+
+       /* Handle "unusable" cursor */
+       if (Term->scr->cu) return (-1);
+
+       /* Paranoia -- no illegal chars */
+       if (!c) return (-2);
+
+       /* Queue the given character for display */
+       Term_queue_bigchar(Term->scr->cx, Term->scr->cy, a, c, 0, 0);
+
+       /* Advance the cursor */
+       Term->scr->cx += 2;
+
+       /* Success */
+       if (Term->scr->cx < Term->wid) return (0);
+
+       /* Note "Useless" cursor */
+       Term->scr->cu = 1;
+
+       /* Note "Useless" cursor */
+       return (1);
+}
+
+
+/*
  * At the current location, using an attr, add a string
  *
  * We also take a length "n", using negative values to imply
@@ -2039,12 +1944,10 @@ errr Term_addch(byte a, char c)
  * positive value, future calls to either function will
  * return negative ones.
  */
-errr Term_addstr(int n, byte a, cptr s)
+errr Term_addstr(int n, TERM_COLOR a, concptr s)
 {
        int k;
-
-       int w = Term->wid;
-
+       TERM_LEN w = Term->wid;
        errr res = 0;
 
        /* Handle "unusable" cursor */
@@ -2063,7 +1966,7 @@ errr Term_addstr(int n, byte a, cptr s)
        Term_queue_chars(Term->scr->cx, Term->scr->cy, n, a, s);
 
        /* Advance the cursor */
-       Term->scr->cx += n;
+       Term->scr->cx += (byte_hack)n;
 
        /* Hack -- Notice "Useless" cursor */
        if (res) Term->scr->cu = 1;
@@ -2076,7 +1979,7 @@ errr Term_addstr(int n, byte a, cptr s)
 /*
  * Move to a location and, using an attr, add a char
  */
-errr Term_putch(int x, int y, byte a, char c)
+errr Term_putch(TERM_LEN x, TERM_LEN y, TERM_COLOR a, char c)
 {
        errr res;
 
@@ -2094,7 +1997,7 @@ errr Term_putch(int x, int y, byte a, char c)
 /*
  * Move to a location and, using an attr, add a string
  */
-errr Term_putstr(int x, int y, int n, byte a, cptr s)
+errr Term_putstr(TERM_LEN x, TERM_LEN y, int n, TERM_COLOR a, concptr s)
 {
        errr res;
 
@@ -2112,7 +2015,7 @@ errr Term_putstr(int x, int y, int n, byte a, cptr s)
 /*
  * Move to a location and, using an attr, add a string vertically
  */
-errr Term_putstr_v(int x, int y, int n, byte a, cptr s)
+errr Term_putstr_v(TERM_LEN x, TERM_LEN y, int n, byte a, concptr s)
 {
        errr res;
        int i;
@@ -2144,26 +2047,24 @@ errr Term_putstr_v(int x, int y, int n, byte a, cptr s)
 /*
  * Place cursor at (x,y), and clear the next "n" chars
  */
-errr Term_erase(int x, int y, int n)
+errr Term_erase(TERM_LEN x, TERM_LEN y, int n)
 {
        int i;
 
-       int w = Term->wid;
+       TERM_LEN w = Term->wid;
        /* int h = Term->hgt; */
 
-       int x1 = -1;
-       int x2 = -1;
+       TERM_LEN x1 = -1;
+       TERM_LEN x2 = -1;
 
        int na = Term->attr_blank;
        int nc = Term->char_blank;
 
-       byte *scr_aa;
+       TERM_COLOR *scr_aa;
        char *scr_cc;
 
-#ifdef USE_TRANSPARENCY
-       byte *scr_taa;
+       TERM_COLOR *scr_taa;
        char *scr_tcc;
-#endif /* USE_TRANSPARENCY */
 
        /* Place cursor */
        if (Term_gotoxy(x, y)) return (-1);
@@ -2175,24 +2076,23 @@ errr Term_erase(int x, int y, int n)
        scr_aa = Term->scr->a[y];
        scr_cc = Term->scr->c[y];
 
-#ifdef USE_TRANSPARENCY
        scr_taa = Term->scr->ta[y];
        scr_tcc = Term->scr->tc[y];
-#endif /* USE_TRANSPARENCY */
 
 #ifdef JP
-        /*
-         * Á´³Ñʸ»ú¤Î±¦È¾Ê¬¤«¤éʸ»ú¤òɽ¼¨¤¹¤ë¾ì¹ç¡¢
-         * ½Å¤Ê¤Ã¤¿Ê¸»ú¤Îº¸Éôʬ¤ò¾Ãµî¡£
-         */
-        if (n > 0 && (scr_aa[x] & KANJI2))
+       /*
+        * 全角文字の右半分から文字を表示する場合、
+        * 重なった文字の左部分を消去。
+        */
+       if (n > 0 && (((scr_aa[x] & AF_KANJI2) && !(scr_aa[x] & AF_TILE1))
+                     || (scr_aa[x] & AF_BIGTILE2) == AF_BIGTILE2))
 #else
-        if (n > 0 && (byte)scr_cc[x] == 255 && scr_aa[x] == 255)
+       if (n > 0 && (scr_aa[x] & AF_BIGTILE2) == AF_BIGTILE2)
 #endif
-        {
-                x--;
-                n++;
-        }
+       {
+               x--;
+               n++;
+       }
 
        /* Scan every column */
        for (i = 0; i < n; i++, x++)
@@ -2204,24 +2104,22 @@ errr Term_erase(int x, int y, int n)
                if ((oa == na) && (oc == nc)) continue;
 
 #ifdef JP
-                /*
-                 * Á´³Ñʸ»ú¤Îº¸È¾Ê¬¤Çɽ¼¨¤ò½ªÎ»¤¹¤ë¾ì¹ç¡¢
-                 * ½Å¤Ê¤Ã¤¿Ê¸»ú¤Î±¦Éôʬ¤ò¾Ãµî¡£
+               /*
+                * 全角文字の左半分で表示を終了する場合、
+                * 重なった文字の右部分を消去。
                 *
                 * 2001/04/29 -- Habu
-                * ¹Ô¤Î±¦Ã¼¤Î¾ì¹ç¤Ï¤³¤Î½èÍý¤ò¤·¤Ê¤¤¤è¤¦¤Ë½¤Àµ¡£
-                 */
-                if ((oa & KANJI1) && (i + 1) == n && x != w - 1)
-                        n++;
+                * 行の右端の場合はこの処理をしないように修正。
+                */
+               if ((oa & AF_KANJI1) && (i + 1) == n && x != w - 1)
+                       n++;
 #endif
                /* Save the "literal" information */
-               scr_aa[x] = na;
-               scr_cc[x] = nc;
+               scr_aa[x] = (byte_hack)na;
+               scr_cc[x] = (char)nc;
 
-#ifdef USE_TRANSPARENCY
                scr_taa[x] = 0;
                scr_tcc[x] = 0;
-#endif /* USE_TRANSPARENCY */
 
                /* Track minimum changed column */
                if (x1 < 0) x1 = x;
@@ -2234,12 +2132,12 @@ errr Term_erase(int x, int y, int n)
        if (x1 >= 0)
        {
                /* Check for new min/max row info */
-               if (y < Term->y1) Term->y1 = y;
-               if (y > Term->y2) Term->y2 = y;
+               if (y < Term->y1) Term->y1 = (byte_hack)y;
+               if (y > Term->y2) Term->y2 = (byte_hack)y;
 
                /* Check for new min/max col info in this row */
-               if (x1 < Term->x1[y]) Term->x1[y] = x1;
-               if (x2 > Term->x2[y]) Term->x2[y] = x2;
+               if (x1 < Term->x1[y]) Term->x1[y] = (byte_hack)x1;
+               if (x2 > Term->x2[y]) Term->x2[y] = (byte_hack)x2;
        }
 
        /* Success */
@@ -2254,12 +2152,12 @@ errr Term_erase(int x, int y, int n)
  */
 errr Term_clear(void)
 {
-       int x, y;
+       TERM_LEN x, y;
 
-       int w = Term->wid;
-       int h = Term->hgt;
+       TERM_LEN w = Term->wid;
+       TERM_LEN h = Term->hgt;
 
-       byte na = Term->attr_blank;
+       TERM_COLOR na = Term->attr_blank;
        char nc = Term->char_blank;
 
        /* Cursor usable */
@@ -2271,13 +2169,11 @@ errr Term_clear(void)
        /* Wipe each row */
        for (y = 0; y < h; y++)
        {
-               byte *scr_aa = Term->scr->a[y];
+               TERM_COLOR *scr_aa = Term->scr->a[y];
                char *scr_cc = Term->scr->c[y];
 
-#ifdef USE_TRANSPARENCY
-               byte *scr_taa = Term->scr->ta[y];
+               TERM_COLOR *scr_taa = Term->scr->ta[y];
                char *scr_tcc = Term->scr->tc[y];
-#endif /* USE_TRANSPARENCY */
 
                /* Wipe each column */
                for (x = 0; x < w; x++)
@@ -2285,11 +2181,8 @@ errr Term_clear(void)
                        scr_aa[x] = na;
                        scr_cc[x] = nc;
 
-#ifdef USE_TRANSPARENCY
                        scr_taa[x] = 0;
                        scr_tcc[x] = 0;
-#endif /* USE_TRANSPARENCY */
-
                }
 
                /* This row has changed */
@@ -2329,9 +2222,9 @@ errr Term_redraw(void)
 
 
 /*
- * Redraw part of a widow.
+ * Redraw part of a window.
  */
-errr Term_redraw_section(int x1, int y1, int x2, int y2)
+errr Term_redraw_section(TERM_LEN x1, TERM_LEN y1, TERM_LEN x2, TERM_LEN y2)
 {
        int i, j;
 
@@ -2344,8 +2237,8 @@ errr Term_redraw_section(int x1, int y1, int x2, int y2)
        if (x1 < 0) x1 = 0;
 
        /* Set y limits */
-       Term->y1 = y1;
-       Term->y2 = y2;
+       Term->y1 = (byte_hack)y1;
+       Term->y2 = (byte_hack)y2;
 
        /* Set the x limits */
        for (i = Term->y1; i <= Term->y2; i++)
@@ -2356,16 +2249,16 @@ errr Term_redraw_section(int x1, int y1, int x2, int y2)
    
                if (x1j > 0)
                {
-                       if (Term->scr->a[i][x1j] & KANJI2) x1j--;
+                       if (Term->scr->a[i][x1j] & AF_KANJI2) x1j--;
                }
    
                if (x2j < Term->wid - 1)
                {
-                       if (Term->scr->a[i][x2j] & KANJI1) x2j++;
+                       if (Term->scr->a[i][x2j] & AF_KANJI1) x2j++;
                }
    
-               Term->x1[i] = x1j;
-               Term->x2[i] = x2j;
+               Term->x1[i] = (byte_hack)x1j;
+               Term->x2[i] = (byte_hack)x2j;
    
                c_ptr = Term->old->c[i];
    
@@ -2418,7 +2311,7 @@ errr Term_get_cursor(int *v)
 /*
  * Extract the current window size
  */
-errr Term_get_size(int *w, int *h)
+errr Term_get_size(TERM_LEN *w, TERM_LEN *h)
 {
        /* Access the cursor */
        (*w) = Term->wid;
@@ -2432,7 +2325,7 @@ errr Term_get_size(int *w, int *h)
 /*
  * Extract the current cursor location
  */
-errr Term_locate(int *x, int *y)
+errr Term_locate(TERM_LEN *x, TERM_LEN *y)
 {
        /* Access the cursor */
        (*x) = Term->scr->cx;
@@ -2451,10 +2344,10 @@ errr Term_locate(int *x, int *y)
  * Note that this refers to what will be on the window after the
  * next call to "Term_fresh()".  It may or may not already be there.
  */
-errr Term_what(int x, int y, byte *a, char *c)
+errr Term_what(TERM_LEN x, TERM_LEN y, TERM_COLOR *a, char *c)
 {
-       int w = Term->wid;
-       int h = Term->hgt;
+       TERM_LEN w = Term->wid;
+       TERM_LEN h = Term->hgt;
 
        /* Verify location */
        if ((x < 0) || (x >= w)) return (-1);
@@ -2499,7 +2392,7 @@ errr Term_keypress(int k)
        if (!k) return (-1);
 
        /* Store the char, advance the queue */
-       Term->key_queue[Term->key_head++] = k;
+       Term->key_queue[Term->key_head++] = (char)k;
 
        /* Circular queue, handle wrap */
        if (Term->key_head == Term->key_size) Term->key_head = 0;
@@ -2529,16 +2422,11 @@ errr Term_key_push(int k)
        if (Term->key_tail == 0) Term->key_tail = Term->key_size;
 
        /* Back up, Store the char */
-       Term->key_queue[--Term->key_tail] = k;
+       Term->key_queue[--Term->key_tail] = (char)k;
 
        /* Success (unless overflow) */
        if (Term->key_head != Term->key_tail) return (0);
 
-#if 0
-       /* Hack -- Forget the oldest key */
-       if (++Term->key_tail == Term->key_size) Term->key_tail = 0;
-#endif
-
        /* Problem */
        return (1);
 }
@@ -2620,8 +2508,8 @@ errr Term_inkey(char *ch, bool wait, bool take)
  */
 errr Term_save(void)
 {
-       int w = Term->wid;
-       int h = Term->hgt;
+       TERM_LEN w = Term->wid;
+       TERM_LEN h = Term->hgt;
 
        /* Create */
        if (!Term->mem)
@@ -2648,10 +2536,10 @@ errr Term_save(void)
  */
 errr Term_load(void)
 {
-       int y;
+       TERM_LEN y;
 
-       int w = Term->wid;
-       int h = Term->hgt;
+       TERM_LEN w = Term->wid;
+       TERM_LEN h = Term->hgt;
 
        /* Create */
        if (!Term->mem)
@@ -2688,10 +2576,10 @@ errr Term_load(void)
  */
 errr Term_exchange(void)
 {
-       int y;
+       TERM_LEN y;
 
-       int w = Term->wid;
-       int h = Term->hgt;
+       TERM_LEN w = Term->wid;
+       TERM_LEN h = Term->hgt;
 
        term_win *exchanger;
 
@@ -2732,14 +2620,14 @@ errr Term_exchange(void)
 /*
  * React to a new physical window size.
  */
-errr Term_resize(int w, int h)
+errr Term_resize(TERM_LEN w, TERM_LEN h)
 {
        int i;
 
-       int wid, hgt;
+       TERM_LEN wid, hgt;
 
-       byte *hold_x1;
-       byte *hold_x2;
+       TERM_LEN *hold_x1;
+       TERM_LEN *hold_x2;
 
        term_win *hold_old;
        term_win *hold_scr;
@@ -2780,8 +2668,8 @@ errr Term_resize(int w, int h)
        hold_tmp = Term->tmp;
 
        /* Create new scanners */
-       C_MAKE(Term->x1, h, byte);
-       C_MAKE(Term->x2, h, byte);
+       C_MAKE(Term->x1, h, TERM_LEN);
+       C_MAKE(Term->x2, h, TERM_LEN);
 
        /* Create new window */
        MAKE(Term->old, term_win);
@@ -2828,8 +2716,8 @@ errr Term_resize(int w, int h)
        }
 
        /* Free some arrays */
-       C_KILL(hold_x1, Term->hgt, byte);
-       C_KILL(hold_x2, Term->hgt, byte);
+       C_KILL(hold_x1, Term->hgt, TERM_LEN);
+       C_KILL(hold_x2, Term->hgt, TERM_LEN);
 
        /* Nuke */
        term_win_nuke(hold_old, Term->wid, Term->hgt);
@@ -2957,8 +2845,8 @@ errr Term_activate(term *t)
  */
 errr term_nuke(term *t)
 {
-       int w = t->wid;
-       int h = t->hgt;
+       TERM_LEN w = t->wid;
+       TERM_LEN h = t->hgt;
 
 
        /* Hack -- Call the special "nuke" hook */
@@ -3008,8 +2896,8 @@ errr term_nuke(term *t)
        }
 
        /* Free some arrays */
-       C_KILL(t->x1, h, byte);
-       C_KILL(t->x2, h, byte);
+       C_KILL(t->x1, h, TERM_LEN);
+       C_KILL(t->x2, h, TERM_LEN);
 
        /* Free the input queue */
        C_KILL(t->key_queue, t->key_size, char);
@@ -3025,9 +2913,9 @@ errr term_nuke(term *t)
  * By default, the cursor starts out "invisible"
  * By default, we "erase" using "black spaces"
  */
-errr term_init(term *t, int w, int h, int k)
+errr term_init(term *t, TERM_LEN w, TERM_LEN h, int k)
 {
-       int y;
+       TERM_LEN y;
 
 
        /* Wipe it */
@@ -3038,7 +2926,7 @@ errr term_init(term *t, int w, int h, int k)
        t->key_head = t->key_tail = 0;
 
        /* Determine the input queue size */
-       t->key_size = k;
+       t->key_size = (u16b)k;
 
        /* Allocate the input queue */
        C_MAKE(t->key_queue, t->key_size, char);
@@ -3049,8 +2937,8 @@ errr term_init(term *t, int w, int h, int k)
        t->hgt = h;
 
        /* Allocate change arrays */
-       C_MAKE(t->x1, h, byte);
-       C_MAKE(t->x2, h, byte);
+       C_MAKE(t->x1, h, TERM_LEN);
+       C_MAKE(t->x2, h, TERM_LEN);
 
 
        /* Allocate "displayed" */
@@ -3088,6 +2976,14 @@ errr term_init(term *t, int w, int h, int k)
        t->char_blank = ' ';
 
 
+       /* Prepare "fake" hooks to prevent core dumps */
+       t->curs_hook = Term_curs_hack;
+       t->bigcurs_hook = Term_bigcurs_hack;
+       t->wipe_hook = Term_wipe_hack;
+       t->text_hook = Term_text_hack;
+       t->pict_hook = Term_pict_hack;
+
+
        /* Success */
        return (0);
 }