OSDN Git Service

#37287 (2.2.0.85) z-term.c, z-rand.c, z-form.c 中のVCコンパイラ警告を修正。C4710は抑制。 / Fix warning...
[hengband/hengband.git] / src / z-term.c
index 5814361..da4d9f8 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
  *   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
@@ -302,8 +306,6 @@ static errr term_win_nuke(term_win *s, int w, int h)
        C_KILL(s->va, h * w, byte);
        C_KILL(s->vc, h * w, char);
 
-#ifdef USE_TRANSPARENCY
-
        /* Free the terrain access arrays */
        C_KILL(s->ta, h, byte*);
        C_KILL(s->tc, h, char*);
@@ -312,8 +314,6 @@ static errr term_win_nuke(term_win *s, int w, int h)
        C_KILL(s->vta, h * w, byte);
        C_KILL(s->vtc, h * w, char);
 
-#endif /* USE_TRANSPARENCY */
-
        /* Success */
        return (0);
 }
@@ -334,8 +334,6 @@ static errr term_win_init(term_win *s, int w, int h)
        C_MAKE(s->va, h * w, byte);
        C_MAKE(s->vc, h * w, char);
 
-#ifdef USE_TRANSPARENCY
-
        /* Make the terrain access arrays */
        C_MAKE(s->ta, h, byte*);
        C_MAKE(s->tc, h, char*);
@@ -344,8 +342,6 @@ static errr term_win_init(term_win *s, int w, int h)
        C_MAKE(s->vta, h * w, byte);
        C_MAKE(s->vtc, h * w, char);
 
-#endif /* USE_TRANSPARENCY */
-
 
        /* Prepare the window access arrays */
        for (y = 0; y < h; y++)
@@ -353,13 +349,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 */
@@ -383,25 +374,19 @@ static errr term_win_copy(term_win *s, term_win *f, int w, int h)
                byte *s_aa = s->a[y];
                char *s_cc = s->c[y];
 
-#ifdef USE_TRANSPARENCY
-
                byte *f_taa = f->ta[y];
                char *f_tcc = f->tc[y];
 
                byte *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 +425,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));
 }
@@ -458,20 +439,31 @@ errr Term_xtra(int n, int v)
  */
 static errr Term_curs_hack(int x, int 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(int x, int 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)
 {
-       /* Compiler silliness */
-       if (x || y || n) return (-2);
+       /* Unused */
+       (void)x;
+       (void)y;
+       (void)n;
 
        /* Oops */
        return (-1);
@@ -480,15 +472,14 @@ static errr Term_wipe_hack(int x, int y, int n)
 /*
  * 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
-
 {
-       /* Compiler silliness */
-       if (x || y || n || a || cp) return (-2);
+       /* Unused */
+       (void)x;
+       (void)y;
+       (void)n;
+       (void)a;
+       (void)cp;
 
        /* Oops */
        return (-1);
@@ -497,18 +488,16 @@ static errr Term_text_hack(int x, int y, int n, byte a, const char *cp)
 /*
  * 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(int x, int y, int n, const byte *ap, cptr cp, const byte *tap, cptr 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 */
+       /* Unused */
+       (void)x;
+       (void)y;
+       (void)n;
+       (void)ap;
+       (void)cp;
+       (void)tap;
+       (void)tcp;
 
        /* Oops */
        return (-1);
@@ -524,19 +513,13 @@ static errr Term_pict_hack(int x, int y, int n, const byte *ap, const char *cp)
  *
  * 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 */
 {
        term_win *scrn = Term->scr; 
        
        byte *scr_aa = &scrn->a[y][x];
        char *scr_cc = &scrn->c[y][x];
 
-#ifdef USE_TRANSPARENCY
-
        byte *scr_taa = &scrn->ta[y][x];
        char *scr_tcc = &scrn->tc[y][x];
 
@@ -544,38 +527,115 @@ void Term_queue_char(int x, int y, byte a, char c)
        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;
 
-       if (scrn->a[y][x] == 255)
+#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(int x, int y, byte a, char c, byte 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);
+}
+
+
+/*
  * Mentally draw a string of attr/chars at a given location
  *
  * Assumes given location and values are valid.
@@ -583,11 +643,7 @@ 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 */
 {
        term_win *scrn = Term->scr;
 
@@ -597,21 +653,14 @@ void Term_queue_line(int x, int y, int n, byte *a, char *c)
        byte *scr_aa = &scrn->a[y][x];
        char *scr_cc = &scrn->c[y][x];
 
-#ifdef USE_TRANSPARENCY
-
        byte *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++;
@@ -629,21 +678,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++;
@@ -661,12 +695,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;
        }
 }
 
@@ -686,66 +720,56 @@ void Term_queue_chars(int x, int y, int n, byte a, cptr s)
 
        byte *scr_aa = Term->scr->a[y];
 #ifdef JP
-        unsigned char *scr_cc = (unsigned char *)Term->scr->c[y];
+       char *scr_cc = 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_tcc = Term->scr->tc[y];
 #else
        char *scr_cc = Term->scr->c[y];
 
-#ifdef USE_TRANSPARENCY
-
        byte *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_aa[x] != 255)
-        {
-                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;
@@ -757,35 +781,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];
+               byte oa = scr_aa[x];
+               char oc = scr_cc[x];
 
-#ifdef USE_TRANSPARENCY
-
-               int ota = scr_taa[x];
-               int otc = scr_tcc[x];
+               byte 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;
@@ -796,18 +807,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;
                }
@@ -817,12 +828,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;
        }
 }
 
@@ -846,8 +857,6 @@ static void Term_fresh_row_pict(int y, int x1, int x2)
        byte *scr_aa = Term->scr->a[y];
        char *scr_cc = Term->scr->c[y];
 
-#ifdef USE_TRANSPARENCY
-
        byte *old_taa = Term->old->ta[y];
        char *old_tcc = Term->old->tc[y];
 
@@ -860,8 +869,6 @@ static void Term_fresh_row_pict(int y, int x1, int x2)
        byte nta;
        char ntc;
 
-#endif /* USE_TRANSPARENCY */
-
 
        /* Pending length */
        int fn = 0;
@@ -876,7 +883,7 @@ static void Term_fresh_row_pict(int y, int x1, int x2)
        char nc;
 
 #ifdef JP
-       /* Á´³Ñʸ»ú¤Î£²¥Ð¥¤¥ÈÌܤ«¤É¤¦¤« */
+       /* 全角文字の2バイト目かどうか */
        int kanji = 0;
 #endif
        /* Scan "modified" columns */
@@ -893,19 +900,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];
@@ -917,45 +923,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 */
 
                                /* Forget */
                                fn = 0;
                        }
 
 #ifdef JP
-                       /* Á´³Ñʸ»ú¤Î»þ¤ÏºÆ³«°ÌÃ֤ϡܣ± */
+                       /* 全角文字の時は再開位置は+1 */
                        if(kanji)
                        {
                                x++;
@@ -970,10 +957,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;
@@ -983,12 +968,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 */
        }
 }
 
@@ -1010,7 +991,6 @@ static void Term_fresh_row_both(int y, int x1, int x2)
        byte *scr_aa = Term->scr->a[y];
        char *scr_cc = Term->scr->c[y];
 
-#ifdef USE_TRANSPARENCY
        byte *old_taa = Term->old->ta[y];
        char *old_tcc = Term->old->tc[y];
        byte *scr_taa = Term->scr->ta[y];
@@ -1020,7 +1000,6 @@ static void Term_fresh_row_both(int y, int x1, int x2)
        char otc;
        byte nta;
        char ntc;
-#endif /* USE_TRANSPARENCY */
 
        /* The "always_text" flag */
        int always_text = Term->always_text;
@@ -1041,7 +1020,7 @@ static void Term_fresh_row_both(int y, int x1, int x2)
        char nc;
 
 #ifdef JP
-       /* Á´³Ñʸ»ú¤Î£²¥Ð¥¤¥ÈÌܤ«¤É¤¦¤« */
+       /* 全角文字の2バイト目かどうか */
        int kanji = 0;
 #endif
        /* Scan "modified" columns */
@@ -1058,20 +1037,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];
@@ -1083,28 +1061,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)
@@ -1112,18 +1074,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));
                                }
 
@@ -1132,7 +1088,7 @@ static void Term_fresh_row_both(int y, int x1, int x2)
                        }
 
 #ifdef JP
-                       /* Á´³Ñʸ»ú¤Î»þ¤ÏºÆ³«°ÌÃ֤ϡܣ± */
+                       /* 全角文字の時は再開位置は+1 */
                        if(kanji)
                        {
                                x++;
@@ -1148,18 +1104,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)
@@ -1167,18 +1119,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));
                                }
 
@@ -1186,25 +1132,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
@@ -1216,18 +1153,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));
                                }
 
@@ -1237,7 +1168,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
@@ -1254,18 +1185,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));
                }
        }
@@ -1306,11 +1231,11 @@ static void Term_fresh_row_text(int y, int x1, int x2)
        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)
                        {
@@ -1335,23 +1260,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
@@ -1363,18 +1288,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));
                                }
 
@@ -1383,7 +1302,7 @@ static void Term_fresh_row_text(int y, int x1, int x2)
                        }
 
 #ifdef JP
-                       /* Á´³Ñʸ»ú¤Î»þ¤ÏºÆ³«°ÌÃ֤ϡܣ± */
+                       /* 全角文字の時は再開位置は+1 */
                        if(kanji)
                        {
                                x++;
@@ -1401,7 +1320,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
@@ -1413,18 +1332,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));
                                }
 
@@ -1434,7 +1347,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
@@ -1451,18 +1364,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));
                }
        }
@@ -1596,7 +1503,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);
@@ -1615,13 +1524,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)
        {
@@ -1640,13 +1542,9 @@ errr Term_fresh(void)
                        byte *aa = old->a[y];
                        char *cc = old->c[y];
 
-#ifdef USE_TRANSPARENCY
-
                        byte *taa = old->ta[y];
                        char *tcc = old->tc[y];
 
-#endif /* USE_TRANSPARENCY */
-
 
                        /* Wipe each column */
                        for (x = 0; x < w; x++)
@@ -1655,13 +1553,8 @@ errr Term_fresh(void)
                                *aa++ = na;
                                *cc++ = nc;
 
-#ifdef USE_TRANSPARENCY
-
                                *taa++ = na;
                                *tcc++ = nc;
-
-#endif /* USE_TRANSPARENCY */
-
                        }
                }
 
@@ -1694,55 +1587,44 @@ errr Term_fresh(void)
                        byte *old_aa = old->a[ty];
                        char *old_cc = old->c[ty];
 
-#ifdef USE_TRANSPARENCY
                        byte *old_taa = old->ta[ty];
                        char *old_tcc = old->tc[ty];
 
                        byte 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;
 #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));
                        }
                }
@@ -1810,7 +1692,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 +1701,7 @@ errr Term_fresh(void)
                }
 
                /* No rows are invalid */
-               Term->y1 = h;
+               Term->y1 = (byte_hack)h;
                Term->y2 = 0;
        }
 
@@ -1830,11 +1712,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 +1738,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 +1748,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 +1758,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 +1796,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);
@@ -1933,8 +1818,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;
@@ -1962,11 +1847,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);
@@ -2000,11 +1881,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 +1898,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(byte 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
@@ -2063,7 +1975,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;
@@ -2160,10 +2072,8 @@ errr Term_erase(int x, int y, int n)
        byte *scr_aa;
        char *scr_cc;
 
-#ifdef USE_TRANSPARENCY
        byte *scr_taa;
        char *scr_tcc;
-#endif /* USE_TRANSPARENCY */
 
        /* Place cursor */
        if (Term_gotoxy(x, y)) return (-1);
@@ -2175,24 +2085,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 +2113,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 +2141,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 */
@@ -2274,10 +2181,8 @@ errr Term_clear(void)
                byte *scr_aa = Term->scr->a[y];
                char *scr_cc = Term->scr->c[y];
 
-#ifdef USE_TRANSPARENCY
                byte *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 +2190,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 */
@@ -2344,8 +2246,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 +2258,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];
    
@@ -2499,7 +2401,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,7 +2431,7 @@ 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);
@@ -2880,8 +2782,8 @@ errr Term_resize(int w, int h)
        }
 
        /* Save new size */
-       Term->wid = w;
-       Term->hgt = h;
+       Term->wid = (byte_hack)w;
+       Term->hgt = (byte_hack)h;
 
        /* Force "total erase" */
        Term->total_erase = TRUE;
@@ -3038,15 +2940,15 @@ 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);
 
 
        /* Save the size */
-       t->wid = w;
-       t->hgt = h;
+       t->wid = (byte_hack)w;
+       t->hgt = (byte_hack)h;
 
        /* Allocate change arrays */
        C_MAKE(t->x1, h, byte);
@@ -3088,6 +2990,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);
 }