OSDN Git Service

[Refactor] #37353 ソースファイル改名。
[hengband/hengband.git] / src / z-term.c
index 357403e..4db323d 100644 (file)
@@ -1,4 +1,4 @@
-/* File: z-term.c */
+/* File: z-term.c */
 
 /*
  * Copyright (c) 1997 Ben Harrison
@@ -24,8 +24,8 @@
 #define AF_KANJI2  0x20
 #define AF_KANJIC  0x0f
 /*
- * Á´³Ñʸ»úÂбþ¡£
- * Â°À­¤ËÁ´³Ñʸ»ú¤Î£±¥Ð¥¤¥ÈÌÜ¡¢£²¥Ð¥¤¥ÈÌܤ⵭²±¡£
+ * 全角文字対応。
+ * 属性に全角文字の1バイト目、2バイト目も記憶。
  * By FIRST
  */
 #endif
@@ -425,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));
 }
@@ -443,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);
@@ -465,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);
@@ -482,10 +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)
  */
-static errr Term_pict_hack(int x, int y, int n, const byte *ap, const char *cp, const byte *tap, const char *tcp)
+static errr Term_pict_hack(int x, int y, int n, const byte *ap, cptr cp, const byte *tap, cptr tcp)
 {
-       /* Compiler silliness */
-       if (x || y || n || ap || cp || tap || tcp) return (-2);
+       /* Unused */
+       (void)x;
+       (void)y;
+       (void)n;
+       (void)ap;
+       (void)cp;
+       (void)tap;
+       (void)tcp;
 
        /* Oops */
        return (-1);
@@ -523,14 +535,19 @@ void Term_queue_char(int x, int y, byte a, char c, byte ta, char tc)
        *scr_tcc = tc;
 
        /* 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]--;
 }
 
@@ -552,15 +569,15 @@ void Term_queue_bigchar(int x, int y, byte a, char c, byte ta, char tc)
         * A table which relates each ascii character to a multibyte
         * character.
         *
-        * ¡Ö¢£¡×¤ÏÆóÇÜÉýƦÉå¤ÎÆâÉô¥³¡¼¥É¤Ë»ÈÍÑ¡£
+        * 「■」は二倍幅豆腐の内部コードに使用。
         */
        static char ascii_to_zenkaku[] =
-               "¡¡¡ª¡É¡ô¡ð¡ó¡õ¡Ç¡Ê¡Ë¡ö¡Ü¡¤¡Ý¡¥¡¿"
-               "£°£±£²£³£´£µ£¶£·£¸£¹¡§¡¨¡ã¡á¡ä¡©"
-               "¡÷£Á£Â£Ã£Ä£Å£Æ£Ç£È£É£Ê£Ë£Ì£Í£Î£Ï"
-               "£Ð£Ñ£Ò£Ó£Ô£Õ£Ö£×£Ø£Ù£Ú¡Î¡À¡Ï¡°¡²"
-               "¡Æ£á£â£ã£ä£å£æ£ç£è£é£ê£ë£ì£í£î£ï"
-               "£ð£ñ£ò£ó£ô£õ£ö£÷£ø£ù£ú¡Ð¡Ã¡Ñ¡Á¢£";
+               " !”#$%&’()*+,-./"
+               "0123456789:;<=>?"
+               "@ABCDEFGHIJKLMNO"
+               "PQRSTUVWXYZ[\]^_"
+               "‘abcdefghijklmno"
+               "pqrstuvwxyz{|}~■";
 #endif
 
        byte a2;
@@ -678,12 +695,12 @@ void Term_queue_line(int x, int y, int n, byte *a, char *c, byte *ta, char *tc)
        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;
        }
 }
 
@@ -716,12 +733,12 @@ void Term_queue_chars(int x, int y, int n, byte a, cptr s)
 
 
 #ifdef JP
-       /* É½¼¨Ê¸»ú¤Ê¤· */
+       /* 表示文字なし */
        if (n == 0 || *s == 0) return;
        /*
-        * Á´³Ñʸ»ú¤Î±¦È¾Ê¬¤«¤éʸ»ú¤òɽ¼¨¤¹¤ë¾ì¹ç¡¢
-        * ½Å¤Ê¤Ã¤¿Ê¸»ú¤Îº¸Éôʬ¤ò¾Ãµî¡£
-        * É½¼¨³«»Ï°ÌÃÖ¤¬º¸Ã¼¤Ç¤Ê¤¤¤È²¾Äê¡£
+        * 全角文字の右半分から文字を表示する場合、
+        * 重なった文字の左部分を消去。
+        * 表示開始位置が左端でないと仮定。
         */
        if ((scr_aa[x] & AF_KANJI2) && (scr_aa[x] & AF_BIGTILE2) != AF_BIGTILE2)
        {
@@ -734,8 +751,8 @@ void Term_queue_chars(int x, int y, int n, byte a, cptr s)
        for ( ; n; x++, s++, n--)
        {
 #ifdef JP
-               /* Æüìʸ»ú¤È¤·¤ÆMSB¤¬Î©¤Ã¤Æ¤¤¤ë²ÄǽÀ­¤¬¤¢¤ë */
-               /* ¤½¤Î¾ì¹çattr¤ÎMSB¤âΩ¤Ã¤Æ¤¤¤ë¤Î¤Ç¤³¤ì¤Ç¼±Ê̤¹¤ë */
+               /* 特殊文字としてMSBが立っている可能性がある */
+               /* その場合attrのMSBも立っているのでこれで識別する */
 /* check */
                if (!(a & AF_TILE1) && iskanji(*s))
                {
@@ -790,9 +807,9 @@ void Term_queue_chars(int x, int y, int n, byte a, cptr s)
 
 #ifdef JP
        /*
-        * Á´³Ñʸ»ú¤Îº¸È¾Ê¬¤Çɽ¼¨¤ò½ªÎ»¤¹¤ë¾ì¹ç¡¢
-        * ½Å¤Ê¤Ã¤¿Ê¸»ú¤Î±¦Éôʬ¤ò¾Ãµî¡£
-        * (¾ò·ïÄɲ᧥¿¥¤¥ë¤Î1ʸ»úÌܤǤʤ¤»ö¤ò³Î¤«¤á¤ë¤è¤¦¤Ë¡£)
+        * 全角文字の左半分で表示を終了する場合、
+        * 重なった文字の右部分を消去。
+        * (条件追加:タイルの1文字目でない事を確かめるように。)
         */
        {
 
@@ -811,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;
        }
 }
 
@@ -866,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 */
@@ -883,15 +900,15 @@ 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 & AF_TILE1));
 #endif
@@ -925,7 +942,7 @@ static void Term_fresh_row_pict(int y, int x1, int x2)
                        }
 
 #ifdef JP
-                       /* Á´³Ñʸ»ú¤Î»þ¤ÏºÆ³«°ÌÃ֤ϡܣ± */
+                       /* 全角文字の時は再開位置は+1 */
                        if(kanji)
                        {
                                x++;
@@ -1003,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 */
@@ -1020,15 +1037,15 @@ 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 & AF_TILE1));
@@ -1057,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));
                                }
 
@@ -1077,7 +1088,7 @@ static void Term_fresh_row_both(int y, int x1, int x2)
                        }
 
 #ifdef JP
-                       /* Á´³Ñʸ»ú¤Î»þ¤ÏºÆ³«°ÌÃ֤ϡܣ± */
+                       /* 全角文字の時は再開位置は+1 */
                        if(kanji)
                        {
                                x++;
@@ -1108,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));
                                }
 
@@ -1148,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));
                                }
 
@@ -1186,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));
                }
        }
@@ -1238,7 +1231,7 @@ 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++)
@@ -1267,15 +1260,15 @@ 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 & AF_TILE1));
 #endif
@@ -1295,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));
                                }
 
@@ -1315,7 +1302,7 @@ static void Term_fresh_row_text(int y, int x1, int x2)
                        }
 
 #ifdef JP
-                       /* Á´³Ñʸ»ú¤Î»þ¤ÏºÆ³«°ÌÃ֤ϡܣ± */
+                       /* 全角文字の時は再開位置は+1 */
                        if(kanji)
                        {
                                x++;
@@ -1345,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));
                                }
 
@@ -1383,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));
                }
        }
@@ -1528,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);
@@ -1547,14 +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->bigcurs_hook) Term->bigcurs_hook = Term->curs_hook;
-       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,23 +1609,22 @@ errr Term_fresh(void)
                        {
                                (void)((*Term->pict_hook)(tx, ty, 1, &old_aa[tx], &old_cc[tx], &ota, &otc));
                        }
-
-                       /* 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, (unsigned char) (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));
                        }
                }
@@ -1724,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) */
@@ -1733,7 +1701,7 @@ errr Term_fresh(void)
                }
 
                /* No rows are invalid */
-               Term->y1 = h;
+               Term->y1 = (byte_hack)h;
                Term->y2 = 0;
        }
 
@@ -1744,10 +1712,6 @@ errr Term_fresh(void)
                /* Draw the cursor */
                if (!scr->cu && scr->cv)
                {
-#ifdef CHUUKEI
-                       send_curs_to_chuukei_server(scr->cx, scr->cy);
-#endif
-
 #ifdef JP
                        if ((scr->cx + 1 < w) &&
                            ((old->a[scr->cy][scr->cx + 1] & AF_BIGTILE2) == AF_BIGTILE2 ||
@@ -1774,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));
 
@@ -1787,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));
 
@@ -1800,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));
 
@@ -1841,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);
@@ -1863,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;
@@ -2020,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;
@@ -2135,8 +2090,8 @@ errr Term_erase(int x, int y, int n)
 
 #ifdef JP
        /*
-        * Á´³Ñʸ»ú¤Î±¦È¾Ê¬¤«¤éʸ»ú¤òɽ¼¨¤¹¤ë¾ì¹ç¡¢
-        * ½Å¤Ê¤Ã¤¿Ê¸»ú¤Îº¸Éôʬ¤ò¾Ãµî¡£
+        * 全角文字の右半分から文字を表示する場合、
+        * 重なった文字の左部分を消去。
         */
        if (n > 0 && (((scr_aa[x] & AF_KANJI2) && !(scr_aa[x] & AF_TILE1))
                      || (scr_aa[x] & AF_BIGTILE2) == AF_BIGTILE2))
@@ -2159,18 +2114,18 @@ errr Term_erase(int x, int y, int n)
 
 #ifdef JP
                /*
-                * Á´³Ñʸ»ú¤Îº¸È¾Ê¬¤Çɽ¼¨¤ò½ªÎ»¤¹¤ë¾ì¹ç¡¢
-                * ½Å¤Ê¤Ã¤¿Ê¸»ú¤Î±¦Éôʬ¤ò¾Ãµî¡£
+                * 全角文字の左半分で表示を終了する場合、
+                * 重なった文字の右部分を消去。
                 *
                 * 2001/04/29 -- Habu
-                * ¹Ô¤Î±¦Ã¼¤Î¾ì¹ç¤Ï¤³¤Î½èÍý¤ò¤·¤Ê¤¤¤è¤¦¤Ë½¤Àµ¡£
+                * 行の右端の場合はこの処理をしないように修正。
                 */
                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;
 
                scr_taa[x] = 0;
                scr_tcc[x] = 0;
@@ -2186,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 */
@@ -2291,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++)
@@ -2311,8 +2266,8 @@ errr Term_redraw_section(int x1, int y1, int x2, int y2)
                        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];
    
@@ -2365,7 +2320,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_POSITION *w, TERM_POSITION *h)
 {
        /* Access the cursor */
        (*w) = Term->wid;
@@ -2446,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;
@@ -2476,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);
@@ -2827,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;
@@ -2985,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);
@@ -3035,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);
 }