OSDN Git Service

[Refactor] #37353 grid.c(旧cave.c) にあったマップの処理 を view-mainwindow.c/h へ移動。
[hengband/hengband.git] / src / main-win.c
index 9b6eae2..cd6dd93 100644 (file)
-/* File: main-win.c */
-
-/*
- * Copyright (c) 1997 Ben Harrison, Skirmantas Kligys, and others
- *
- * This software may be copied and distributed for educational, research,
- * and not for profit purposes provided that this copyright and statement
- * are included in all such copies.
- */
-
-
-/*
- * This file helps Angband work with Windows computers.
- *
- * To use this file, use an appropriate "Makefile" or "Project File",
- * make sure that "WINDOWS" and/or "WIN32" are defined somewhere, and
- * make sure to obtain various extra files as described below.
- *
- * The official compilation uses the CodeWarrior Pro compiler, which
- * includes a special project file and precompilable header file.
- *
- *
- * See also "main-dos.c" and "main-ibm.c".
- *
- *
- * The "lib/user/pref-win.prf" file contains keymaps, macro definitions,
- * and/or color redefinitions.
- *
- * The "lib/user/font-win.prf" contains attr/char mappings for use with the
- * normal "lib/xtra/font/*.fon" font files.
- *
- * The "lib/user/graf-win.prf" contains attr/char mappings for use with the
- * special "lib/xtra/graf/*.bmp" bitmap files, which are activated by a menu
- * item.
- *
- *
- * Compiling this file, and using the resulting executable, requires
- * several extra files not distributed with the standard Angband code.
- * If "USE_GRAPHICS" is defined, then "readdib.h" and "readdib.c" must
- * be placed into "src/", and the "8X8.BMP" bitmap file must be placed
- * into "lib/xtra/graf".  In any case, some "*.fon" files (including
- * "8X13.FON" if nothing else) must be placed into "lib/xtra/font/".
- * If "USE_SOUND" is defined, then some special library (for example,
- * "winmm.lib") may need to be linked in, and desired "*.WAV" sound
- * files must be placed into "lib/xtra/sound/".  All of these extra
- * files can be found in the "ext-win" archive.
- *
- *
- * The "Term_xtra_win_clear()" function should probably do a low-level
- * clear of the current window, and redraw the borders and other things,
- * if only for efficiency.  XXX XXX XXX
- *
- * A simpler method is needed for selecting the "tile size" for windows.
- * XXX XXX XXX
- *
- * The various "warning" messages assume the existance of the "screen.w"
- * window, I think, and only a few calls actually check for its existance,
- * this may be okay since "NULL" means "on top of all windows". (?)  The
- * user must never be allowed to "hide" the main window, or the "menubar"
- * will disappear.  XXX XXX XXX
- *
- * Special "Windows Help Files" can be placed into "lib/xtra/help/" for
- * use with the "winhelp.exe" program.  These files *may* be available
- * at the ftp site somewhere, but I have not seen them.  XXX XXX XXX
- *
- *
- * Initial framework (and most code) by Ben Harrison (benh@phial.com).
- *
- * Original code by Skirmantas Kligys (kligys@scf.usc.edu).
- *
- * Additional code by Ross E Becker (beckerr@cis.ohio-state.edu),
- * and Chris R. Martin (crm7479@tam2000.tamu.edu).
- */
+/*!
+* @file main-win.c
+* @brief Windows版固有実装(メインエントリポイント含む)
+* @date 2018/03/16
+* @author Hengband Team
+* @detail
+*
+* <h3>概要</h3>
+* Windows98かその前後の頃を起点としたAPI実装。
+* 各種のゲームエンジンは無論、
+* DirectXといった昨今描画に標準的となったライブラリも用いていない。
+* タイルの描画処理などについては、現在動作の詳細を検証中。
+*
+* <h3>フォーク元の概要</h3>
+* <p>
+* Copyright (c) 1997 Ben Harrison, Skirmantas Kligys, and others
+*
+* This software may be copied and distributed for educational, research,
+* and not for profit purposes provided that this copyright and statement
+* are included in all such copies.
+* </p>
+* <p>
+* This file helps Angband work with Windows computers.
+*
+* To use this file, use an appropriate "Makefile" or "Project File",
+* make sure that "WINDOWS" and/or "WIN32" are defined somewhere, and
+* make sure to obtain various extra files as described below.
+*
+* The official compilation uses the CodeWarrior Pro compiler, which
+* includes a special project file and precompilable header file.
+* </p>
+*
+* <p>
+* <del>See also "main-dos.c" and "main-ibm.c".</del>
+* </p>
+*
+* <p>
+* The "lib/user/pref-win.prf" file contains keymaps, macro definitions,
+* and/or color redefinitions.
+* </p>
+*
+* <p>
+* The "lib/user/font-win.prf" contains attr/char mappings for use with the
+* normal "lib/xtra/font/*.fon" font files.
+* </p>
+*
+* <p>
+* The "lib/user/graf-win.prf" contains attr/char mappings for use with the
+* special "lib/xtra/graf/*.bmp" bitmap files, which are activated by a menu
+* item.
+* </p>
+*
+* <p>
+* Compiling this file, and using the resulting executable, requires
+* several extra files not distributed with the standard Angband code.
+* If "USE_GRAPHICS" is defined, then "readdib.h" and "readdib.c" must
+* be placed into "src/", and the "8X8.BMP" bitmap file must be placed
+* into "lib/xtra/graf".  In any case, some "*.fon" files (including
+* "8X13.FON" if nothing else) must be placed into "lib/xtra/font/".
+* If "USE_SOUND" is defined, then some special library (for example,
+* "winmm.lib") may need to be linked in, and desired "*.WAV" sound
+* files must be placed into "lib/xtra/sound/".  All of these extra
+* files can be found in the "ext-win" archive.
+* </p>
+*
+* <p>
+* The "Term_xtra_win_clear()" function should probably do a low-level
+* clear of the current window, and redraw the borders and other things,
+* if only for efficiency.  
+* </p>
+*
+* <p>
+* A simpler method is needed for selecting the "tile size" for windows.
+* </p>
+*
+* <p>
+* The various "warning" messages assume the existance of the "screen.w"
+* window, I think, and only a few calls actually check for its existance,
+* this may be okay since "NULL" means "on top of all windows". (?)  The
+* user must never be allowed to "hide" the main window, or the "menubar"
+* will disappear.  
+* </p>
+*
+* <p>
+* Special "Windows Help Files" can be placed into "lib/xtra/help/" for
+* use with the "winhelp.exe" program.  These files *may* be available
+* at the ftp site somewhere, but I have not seen them.  
+* </p>
+*
+* <p>
+* Initial framework (and most code) by Ben Harrison (benh@phial.com).
+*
+* Original code by Skirmantas Kligys (kligys@scf.usc.edu).
+*
+* Additional code by Ross E Becker (beckerr@cis.ohio-state.edu),
+* and Chris R. Martin (crm7479@tam2000.tamu.edu).
+* </p>
+*/
 
 #include "angband.h"
-
+#include "view-mainwindow.h"
 
 #ifdef WINDOWS
 #include <windows.h>
 #include <direct.h>
+#include <locale.h>
+#include "z-term.h"
 
 /*
  * Extract the "WIN32" flag from the compiler
 #define IDM_WINDOW_D_HGT_6             276
 #define IDM_WINDOW_D_HGT_7             277
 
-#define IDM_OPTIONS_NO_GRAPHICS         400
-#define IDM_OPTIONS_OLD_GRAPHICS 401
-#define IDM_OPTIONS_NEW_GRAPHICS 402
-#define IDM_OPTIONS_BIGTILE            409
-#define IDM_OPTIONS_SOUND              410
-#define IDM_OPTIONS_SAVER              420
-#define IDM_OPTIONS_MAP                        430
-#define IDM_OPTIONS_BG                 440
-#define IDM_OPTIONS_OPEN_BG            441
+#define IDM_OPTIONS_NO_GRAPHICS          400
+#define IDM_OPTIONS_OLD_GRAPHICS  401
+#define IDM_OPTIONS_NEW_GRAPHICS  402
+#define IDM_OPTIONS_NEW2_GRAPHICS 403
+#define IDM_OPTIONS_BIGTILE              409
+#define IDM_OPTIONS_SOUND                410
+#define IDM_OPTIONS_MUSIC                411
+#define IDM_OPTIONS_SAVER                420
+#define IDM_OPTIONS_MAP                          430
+#define IDM_OPTIONS_BG                   440
+#define IDM_OPTIONS_OPEN_BG              441
 
 #define IDM_DUMP_SCREEN_HTML   450
 
 #define IDM_HELP_CONTENTS       901
 
-
-
-/*
- * This may need to be removed for some compilers XXX XXX XXX
- */
-#if 0
-#define STRICT
-#endif
-
 /*
  * Exclude parts of WINDOWS.H that are not needed
  */
 #endif
 
 /*
- * Hack -- Fake declarations from "dos.h" XXX XXX XXX
+ * Hack -- Fake declarations from "dos.h" 
  */
 #ifdef WIN32
 #define INVALID_FILE_NAME (DWORD)0xFFFFFFFF
 #else /* WIN32 */
 #define FA_LABEL    0x08        /* Volume label */
 #define FA_DIREC    0x10        /* Directory */
-unsigned _cdecl _dos_getfileattr(const char *, unsigned *);
+unsigned _cdecl _dos_getfileattr(concptr , unsigned *);
 #endif /* WIN32 */
 
 /*
@@ -348,34 +368,41 @@ unsigned _cdecl _dos_getfileattr(const char *, unsigned *);
  */
 typedef struct _term_data term_data;
 
-/*
- * Extra "term" data
- *
+/*!
+ * @struct _term_data
+ * @brief ターム情報構造体 / Extra "term" data
+ * @details
+ * <p>
+ * pos_x / pos_y は各タームの左上点座標を指す。
+ * </p>
+ * <p>
+ * tile_wid / tile_hgt は[ウィンドウ]メニューのタイルの幅/高さを~を
+ * 1ドットずつ調整するステータスを指す。
+ * また、フォントを変更すると都度自動調整される。
+ * </p>
+ * <p>
  * Note the use of "font_want" for the names of the font file requested by
  * the user, and the use of "font_file" for the currently active font file.
  *
  * The "font_file" is uppercased, and takes the form "8X13.FON", while
  * "font_want" can be in almost any form as long as it could be construed
  * as attempting to represent the name of a font.
+ * </p>
  */
 struct _term_data
 {
        term t;
-
-       cptr s;
-
+       concptr s;
        HWND w;
-
        DWORD dwStyle;
        DWORD dwExStyle;
 
        uint keys;
+       TERM_LEN rows;  /* int -> uint */
+       TERM_LEN cols;
 
-       uint rows;      /* int -> uint */
-       uint cols;
-
-       uint pos_x;
-       uint pos_y;
+       uint pos_x; //!< タームの左上X座標
+       uint pos_y; //!< タームの左上Y座標
        uint size_wid;
        uint size_hgt;
        uint size_ow1;
@@ -384,24 +411,16 @@ struct _term_data
        uint size_oh2;
 
        bool size_hack;
-
        bool xtra_hack;
-
        bool visible;
-
        bool bizarre;
-
-       cptr font_want;
-
-       cptr font_file;
-
+       concptr font_want;
+       concptr font_file;
        HFONT font_id;
-
-       uint font_wid;
-       uint font_hgt;
-
-       uint tile_wid;
-       uint tile_hgt;
+       int font_wid;  //!< フォント横幅
+       int font_hgt;  //!< フォント縦幅
+       int tile_wid;  //!< タイル横幅
+       int tile_hgt;  //!< タイル縦幅
 
        uint map_tile_wid;
        uint map_tile_hgt;
@@ -413,33 +432,13 @@ struct _term_data
 
        bool posfix;
 
-/* bg */
-#if 0
-       char *bgfile;
-       int use_bg;
-#endif
 };
 
+#define MAX_TERM_DATA 8        //!< Maximum number of windows 
 
-/*
- * Maximum number of windows XXX XXX XXX
- */
-#define MAX_TERM_DATA 8
-
-/*
- * An array of term_data's
- */
-static term_data data[MAX_TERM_DATA];
-
-/*
- * Hack -- global "window creation" pointer
- */
-static term_data *my_td;
-
-/*
- * Remember normal size of main window when maxmized
- */
-POINT normsize;
+static term_data data[MAX_TERM_DATA]; //!< An array of term_data's
+static term_data *my_td; //!< Hack -- global "window creation" pointer
+POINT normsize; //!< Remember normal size of main window when maxmized
 
 /*
  * was main window maximized on previous playing
@@ -488,8 +487,8 @@ static HPALETTE hPal;
 
 /* bg */
 static HBITMAP hBG = NULL;
-static int use_bg = 0;
-static char bg_bitmap_file[1024] = "bg.bmp";
+static int use_bg = 0; //!< 背景使用フラグ、1なら私用。
+static char bg_bitmap_file[1024] = "bg.bmp"; //!< 現在の背景ビットマップファイル名。
 
 #ifdef USE_SAVER
 
@@ -503,10 +502,11 @@ static HWND hwndSaver;
 
 #ifdef USE_GRAPHICS
 
-/*
+/*!
+ * 現在使用中のタイルID(0ならば未使用)
  * Flag set once "graphics" has been initialized
  */
-static bool can_use_graphics = FALSE;
+static byte_hack current_graphics_mode = 0;
 
 /*
  * The global bitmap
@@ -529,41 +529,60 @@ static DIBINIT infMask;
 static bool can_use_sound = FALSE;
 
 #define SAMPLE_MAX 8
-
 /*
  * An array of sound file names
  */
-static cptr sound_file[SOUND_MAX][SAMPLE_MAX];
+static concptr sound_file[SOUND_MAX][SAMPLE_MAX];
 
 #endif /* USE_SOUND */
 
 
+
+#ifdef USE_MUSIC
+
+#define SAMPLE_MUSIC_MAX 16
+static concptr music_file[MUSIC_BASIC_MAX][SAMPLE_MUSIC_MAX];
+static concptr dungeon_music_file[1000][SAMPLE_MUSIC_MAX];
+static concptr town_music_file[1000][SAMPLE_MUSIC_MAX];
+static concptr quest_music_file[1000][SAMPLE_MUSIC_MAX];
+static bool can_use_music = FALSE;
+
+static MCI_OPEN_PARMS mop;
+static char mci_device_type[256];
+
+int current_music_type = 0;
+int current_music_id = 0;
+
+#endif /* USE_MUSIC */
+
+
 /*
  * Full path to ANGBAND.INI
  */
-static cptr ini_file = NULL;
+static concptr ini_file = NULL;
 
 /*
  * Name of application
  */
-static cptr AppName = "ANGBAND";
+static concptr AppName = "ANGBAND";
 
 /*
  * Name of sub-window type
  */
-static cptr AngList = "AngList";
+static concptr AngList = "AngList";
 
 /*
  * Directory names
  */
-static cptr ANGBAND_DIR_XTRA_GRAF;
-static cptr ANGBAND_DIR_XTRA_SOUND;
-static cptr ANGBAND_DIR_XTRA_HELP;
+static concptr ANGBAND_DIR_XTRA_GRAF;
+static concptr ANGBAND_DIR_XTRA_SOUND;
+static concptr ANGBAND_DIR_XTRA_MUSIC;
+static concptr ANGBAND_DIR_XTRA_HELP;
 #if 0 /* #ifndef JP */
-static cptr ANGBAND_DIR_XTRA_FONT;
+static concptr ANGBAND_DIR_XTRA_FONT;
 #endif
 #ifdef USE_MUSIC
-static cptr ANGBAND_DIR_XTRA_MUSIC;
+static concptr ANGBAND_DIR_XTRA_MUSIC;
 #endif
 
 
@@ -583,17 +602,15 @@ static bool Term_no_press = FALSE;
  */
 static bool mouse_down = FALSE;
 static bool paint_rect = FALSE;
-static int mousex = 0, mousey = 0;
-static int oldx, oldy;
+static TERM_LEN mousex = 0, mousey = 0;
+static TERM_LEN oldx, oldy;
 
 
-/*
- * The "simple" color values
- *
+/*!
+ * @brief The "simple" color values
+ * @details
  * See "main-ibm.c" for original table information
- *
  * The entries below are taken from the "color bits" defined above.
- *
  * Note that many of the choices below suck, but so do crappy monitors.
  */
 static BYTE win_pal[256] =
@@ -736,6 +753,12 @@ static byte special_key_list[] =
 };
 #endif
 
+
+/* Function prototype */
+
+static bool is_already_running(void);
+
+
 /* bg */
 static void delete_bg(void)
 {
@@ -755,33 +778,10 @@ static int init_bg(void)
 
        hBG = LoadImage(NULL, bmfile,  IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE);
        if (!hBG) {
-#ifdef JP
-               plog_fmt("ÊÉ»æÍѥӥåȥޥåנ'%s' ¤òÆɤ߹þ¤á¤Þ¤»¤ó¡£", bmfile);
-#else
-               plog_fmt("Can't load the bitmap file '%s'.", bmfile);
-#endif
+               plog_fmt(_("壁紙用ビットマップ '%s' を読み込めません。", "Can't load the bitmap file '%s'."), bmfile);
                use_bg = 0;
                return 0;
        }
-#if 0 /* gomi */
-       HDC wnddc, dcimage, dcbg;
-       HBITMAP bmimage, bmimage_old, bmbg_old;
-       int i, j;
-
-       delete_bg();
-
-       wnddc = GetDC(hwnd);
-       dcimage = CreateCompatibleDC(wnddc);
-       dcbg = CreateCompatibleDC(wnddc);
-
-       bmimage = LoadImage(NULL, "bg.bmp", LR_LOADFROMFILE, 0, 0, 0);
-       if (!bmimage) quit("bg.bmp¤¬Æɤߤ³¤á¤Ê¤¤¡ª");
-       bmimage_old = SelectObject(dcimage, bmimage);
-
-       CreateCompatibleBitmap();
-
-       ReleaseDC(hwnd, wnddc);
-#endif
        use_bg = 1;
        return 1;
 }
@@ -825,9 +825,9 @@ static void DrawBG(HDC hdc, RECT *r)
 /*
  * Hack -- given a pathname, point at the filename
  */
-static cptr extract_file_name(cptr s)
+static concptr extract_file_name(concptr s)
 {
-       cptr p;
+       concptr p;
 
        /* Start at the end */
        p = s + strlen(s) - 1;
@@ -881,8 +881,6 @@ static char *analyze_font(char *path, int *wp, int *hp)
        /* Save results */
        (*wp) = wid;
        (*hp) = hgt;
-
-       /* Result */
        return (p);
 }
 #endif
@@ -891,7 +889,7 @@ static char *analyze_font(char *path, int *wp, int *hp)
 /*
  * Check for existance of a file
  */
-static bool check_file(cptr s)
+static bool check_file(concptr s)
 {
        char path[1024];
 
@@ -940,7 +938,7 @@ static bool check_file(cptr s)
 /*
  * Check for existance of a directory
  */
-static bool check_dir(cptr s)
+static bool check_dir(concptr s)
 {
        int i;
 
@@ -997,17 +995,12 @@ static bool check_dir(cptr s)
 /*
  * Validate a file
  */
-static void validate_file(cptr s)
+static void validate_file(concptr s)
 {
        /* Verify or fail */
        if (!check_file(s))
        {
-#ifdef JP
-               quit_fmt("ɬÍפʥե¡¥¤¥ë[%s]¤¬¸«¤¢¤¿¤ê¤Þ¤»¤ó¡£", s);
-#else
-               quit_fmt("Cannot find required file:\n%s", s);
-#endif
-
+               quit_fmt(_("必要なファイル[%s]が見あたりません。", "Cannot find required file:\n%s"), s);
        }
 }
 
@@ -1015,7 +1008,7 @@ static void validate_file(cptr s)
 /*
  * Validate a directory
  */
-static void validate_dir(cptr s, bool vital)
+static void validate_dir(concptr s, bool vital)
 {
        /* Verify or fail */
        if (!check_dir(s))
@@ -1023,12 +1016,7 @@ static void validate_dir(cptr s, bool vital)
                /* This directory contains needed data */
                if (vital)
                {
-#ifdef JP
-               quit_fmt("ɬÍפʥǥ£¥ì¥¯¥È¥ê[%s]¤¬¸«¤¢¤¿¤ê¤Þ¤»¤ó¡£", s);
-#else
-                       quit_fmt("Cannot find required directory:\n%s", s);
-#endif
-
+                       quit_fmt(_("必要なディレクトリ[%s]が見あたりません。", "Cannot find required directory:\n%s"), s);
                }
                /* Attempt to create this directory */
                else if (mkdir(s))
@@ -1039,16 +1027,13 @@ static void validate_dir(cptr s, bool vital)
 }
 
 
-/*
- * Get the "size" for a window
+/*!
+ * @brief (Windows版固有実装)Get the "size" for a window
  */
 static void term_getsize(term_data *td)
 {
        RECT rc;
-
-       int wid, hgt;
-
-       /* Paranoia */
+       TERM_LEN wid, hgt;
        if (td->cols < 1) td->cols = 1;
        if (td->rows < 1) td->rows = 1;
 
@@ -1062,7 +1047,6 @@ static void term_getsize(term_data *td)
        rc.top = 0;
        rc.bottom = rc.top + hgt;
 
-       /* XXX XXX XXX */
        /* rc.right += 1; */
        /* rc.bottom += 1; */
 
@@ -1091,13 +1075,11 @@ static void term_getsize(term_data *td)
 static void save_prefs_aux(int i)
 {
        term_data *td = &data[i];
-       char sec_name[128];
+       GAME_TEXT sec_name[128];
        char buf[1024];
 
        RECT rc;
        WINDOWPLACEMENT lpwndpl;
-
-       /* Paranoia */
        if (!td->w) return;
 
        /* Make section name */
@@ -1112,7 +1094,7 @@ static void save_prefs_aux(int i)
 
        /* Font */
 #ifdef JP
-       strcpy(buf, td->lf.lfFaceName[0]!='\0' ? td->lf.lfFaceName : "£Í£Ó ¥´¥·¥Ã¥¯");
+       strcpy(buf, td->lf.lfFaceName[0]!='\0' ? td->lf.lfFaceName : "ï¼­ï¼³ ã\82´ã\82·ã\83\83ã\82¯");
 #else
 #if 0
        strcpy(buf, td->font_file ? td->font_file : "8X13.FON");
@@ -1189,7 +1171,6 @@ static void save_prefs_aux(int i)
 
 /*
  * Write the "prefs"
- *
  * We assume that the windows have all been initialized
  */
 static void save_prefs(void)
@@ -1210,6 +1191,10 @@ static void save_prefs(void)
        strcpy(buf, arg_sound ? "1" : "0");
        WritePrivateProfileString("Angband", "Sound", buf, ini_file);
 
+       /* Save the "arg_sound" flag */
+       strcpy(buf, arg_music ? "1" : "0");
+       WritePrivateProfileString("Angband", "Music", buf, ini_file);
+
        /* bg */
        strcpy(buf, use_bg ? "1" : "0");
        WritePrivateProfileString("Angband", "BackGround", buf, ini_file);
@@ -1230,12 +1215,14 @@ static void save_prefs(void)
 static void load_prefs_aux(int i)
 {
        term_data *td = &data[i];
-       char sec_name[128];
+       GAME_TEXT sec_name[128];
        char tmp[1024];
 
        int wid, hgt, posx, posy;
        int dispx = GetSystemMetrics( SM_CXVIRTUALSCREEN);
        int dispy = GetSystemMetrics( SM_CYVIRTUALSCREEN);
+       posx=0;
+       posy=0;
        
        /* Make section name */
        sprintf(sec_name, "Term-%d", i);
@@ -1251,7 +1238,7 @@ static void load_prefs_aux(int i)
 
        /* Desired font, with default */
 #ifdef JP
-       GetPrivateProfileString(sec_name, "Font", "£Í£Ó ¥´¥·¥Ã¥¯", tmp, 127, ini_file);
+       GetPrivateProfileString(sec_name, "Font", "ï¼­ï¼³ ã\82´ã\82·ã\83\83ã\82¯", tmp, 127, ini_file);
 #else
 #if 0
        GetPrivateProfileString(sec_name, "Font", "8X13.FON", tmp, 127, ini_file);
@@ -1294,7 +1281,7 @@ static void load_prefs_aux(int i)
        /* Window size */
        if (i == 0)
        {
-               win_maximized = GetPrivateProfileInt(sec_name, "Maximized", win_maximized, ini_file);
+               win_maximized = (GetPrivateProfileInt(sec_name, "Maximized", win_maximized, ini_file) != 0);
        }
 
        /* Window position */
@@ -1306,7 +1293,7 @@ static void load_prefs_aux(int i)
        /* Window Z position */
        if (i > 0)
        {
-               td->posfix = GetPrivateProfileInt(sec_name, "PositionFix", td->posfix, ini_file);
+               td->posfix = (GetPrivateProfileInt(sec_name, "PositionFix", td->posfix, ini_file) != 0);
        }
 }
 
@@ -1319,15 +1306,18 @@ static void load_prefs(void)
        int i;
 
        /* Extract the "arg_graphics" flag */
-       arg_graphics = GetPrivateProfileInt("Angband", "Graphics", GRAPHICS_NONE, ini_file);
+       arg_graphics = (byte_hack)GetPrivateProfileInt("Angband", "Graphics", GRAPHICS_NONE, ini_file);
 
        /* Extract the "arg_bigtile" flag */
-       arg_bigtile = GetPrivateProfileInt("Angband", "Bigtile", FALSE, ini_file);
+       arg_bigtile = (GetPrivateProfileInt("Angband", "Bigtile", FALSE, ini_file) != 0);
        use_bigtile = arg_bigtile;
 
        /* Extract the "arg_sound" flag */
        arg_sound = (GetPrivateProfileInt("Angband", "Sound", 0, ini_file) != 0);
 
+       /* Extract the "arg_sound" flag */
+       arg_music = (GetPrivateProfileInt("Angband", "Music", 0, ini_file) != 0);
+
        /* bg */
        use_bg = GetPrivateProfileInt("Angband", "BackGround", 0, ini_file);
        GetPrivateProfileString("Angband", "BackGroundBitmap", "bg.bmp", bg_bitmap_file, 1023, ini_file);
@@ -1339,10 +1329,10 @@ static void load_prefs(void)
        }
 }
 
-#ifdef USE_SOUND
+#if defined(USE_SOUND) || defined(USE_MUSIC)
 
 /*
- * XXX XXX XXX - Taken from files.c.
+ * - Taken from files.c.
  *
  * Extract "tokens" from a buffer
  *
@@ -1358,24 +1348,22 @@ static void load_prefs(void)
  */
 static s16b tokenize_whitespace(char *buf, s16b num, char **tokens)
 {
-       int k = 0;
-
+       s16b k = 0;
        char *s = buf;
 
-
        /* Process */
        while (k < num)
        {
                char *t;
 
                /* Skip leading whitespace */
-               for ( ; *s && isspace(*s); ++s) /* loop */;
+               for ( ; *s && iswspace(*s); ++s) /* loop */;
 
                /* All done */
                if (!*s) break;
 
                /* Find next whitespace, if any */
-               for (t = s; *t && !isspace(*t); ++t) /* loop */;
+               for (t = s; *t && !iswspace(*t); ++t) /* loop */;
 
                /* Nuke and advance (if necessary) */
                if (*t) *t++ = '\0';
@@ -1391,6 +1379,10 @@ static s16b tokenize_whitespace(char *buf, s16b num, char **tokens)
        return (k);
 }
 
+#endif /* USE_SOUND || USE_MUSIC */
+
+#ifdef USE_SOUND
+
 static void load_sound_prefs(void)
 {
        int i, j, num;
@@ -1400,6 +1392,7 @@ static void load_sound_prefs(void)
        char *zz[SAMPLE_MAX];
 
        /* Access the sound.cfg */
+
        path_build(ini_path, 1024, ANGBAND_DIR_XTRA_SOUND, "sound.cfg");
 
        for (i = 0; i < SOUND_MAX; i++)
@@ -1422,6 +1415,99 @@ static void load_sound_prefs(void)
 
 #endif /* USE_SOUND */
 
+#ifdef USE_MUSIC
+
+static void load_music_prefs(void)
+{
+       int i, j, num;
+       char tmp[1024];
+       char ini_path[1024];
+       char wav_path[1024];
+       char *zz[SAMPLE_MAX];
+       char key[80];
+
+       /* Access the music.cfg */
+
+       path_build(ini_path, 1024, ANGBAND_DIR_XTRA_MUSIC, "music.cfg");
+
+       GetPrivateProfileString("Device", "type", "", mci_device_type, 256, ini_path);
+
+       for (i = 0; i < MUSIC_BASIC_MAX; i++)
+       {
+               GetPrivateProfileString("Basic", angband_music_basic_name[i], "", tmp, 1024, ini_path);
+
+               num = tokenize_whitespace(tmp, SAMPLE_MUSIC_MAX, zz);
+
+               for (j = 0; j < num; j++)
+               {
+                       /* Access the sound */
+                       path_build(wav_path, 1024, ANGBAND_DIR_XTRA_MUSIC, zz[j]);
+
+                       /* Save the sound filename, if it exists */
+                       if (check_file(wav_path))
+                               music_file[i][j] = string_make(zz[j]);
+               }
+       }
+
+       for (i = 0; i < max_d_idx; i++)
+       {
+               sprintf(key, "dungeon%03d", i);
+               GetPrivateProfileString("Dungeon", key, "", tmp, 1024, ini_path);
+
+               num = tokenize_whitespace(tmp, SAMPLE_MUSIC_MAX, zz);
+
+               for (j = 0; j < num; j++)
+               {
+                       /* Access the sound */
+                       path_build(wav_path, 1024, ANGBAND_DIR_XTRA_MUSIC, zz[j]);
+
+                       /* Save the sound filename, if it exists */
+                       if (check_file(wav_path))
+                               dungeon_music_file[i][j] = string_make(zz[j]);
+               }
+       }
+
+       for (i = 0; i < max_q_idx; i++)
+       {
+               sprintf(key, "quest%03d", i);
+               GetPrivateProfileString("Quest", key, "", tmp, 1024, ini_path);
+
+               num = tokenize_whitespace(tmp, SAMPLE_MUSIC_MAX, zz);
+
+               for (j = 0; j < num; j++)
+               {
+                       /* Access the sound */
+                       path_build(wav_path, 1024, ANGBAND_DIR_XTRA_MUSIC, zz[j]);
+
+                       /* Save the sound filename, if it exists */
+                       if (check_file(wav_path))
+                               quest_music_file[i][j] = string_make(zz[j]);
+               }
+       }
+
+       for (i = 0; i < 1000; i++) /*!< @todo 町最大数指定 */
+       {
+               sprintf(key, "town%03d", i);
+               GetPrivateProfileString("Town", key, "", tmp, 1024, ini_path);
+
+               num = tokenize_whitespace(tmp, SAMPLE_MUSIC_MAX, zz);
+
+               for (j = 0; j < num; j++)
+               {
+                       /* Access the sound */
+                       path_build(wav_path, 1024, ANGBAND_DIR_XTRA_MUSIC, zz[j]);
+
+                       /* Save the sound filename, if it exists */
+                       if (check_file(wav_path))
+                               town_music_file[i][j] = string_make(zz[j]);
+               }
+       }
+
+
+}
+
+#endif /* USE_MUSIC */
+
 /*
  * Create the new global palette based on the bitmap palette
  * (if any), and the standard 16 entry palette derived from
@@ -1471,12 +1557,7 @@ static int new_palette(void)
                if ((nEntries == 0) || (nEntries > 220))
                {
                        /* Warn the user */
-#ifdef JP
-                       plog("²èÌ̤ò16¥Ó¥Ã¥È¤«24¥Ó¥Ã¥È¥«¥é¡¼¥â¡¼¥É¤Ë¤·¤Æ²¼¤µ¤¤¡£");
-#else
-                       plog("Please switch to high- or true-color mode.");
-#endif
-
+                       plog(_("画面を16ビットか24ビットカラーモードにして下さい。", "Please switch to high- or true-color mode."));
 
                        /* Cleanup */
                        rnfree(lppe, lppeSize);
@@ -1528,12 +1609,7 @@ static int new_palette(void)
 
        /* Create a new palette, or fail */
        hNewPal = CreatePalette(pLogPal);
-#ifdef JP
-       if (!hNewPal) quit("¥Ñ¥ì¥Ã¥È¤òºîÀ®¤Ç¤­¤Þ¤»¤ó¡ª");
-#else
-       if (!hNewPal) quit("Cannot create palette!");
-#endif
-
+       if (!hNewPal) quit(_("パレットを作成できません!", "Cannot create palette!"));
 
        /* Free the palette */
        rnfree(pLogPal, pLogPalSize);
@@ -1546,11 +1622,7 @@ static int new_palette(void)
        SelectPalette(hdc, hNewPal, 0);
        i = RealizePalette(hdc);
        ReleaseDC(td->w, hdc);
-#ifdef JP
-       if (i == 0) quit("¥Ñ¥ì¥Ã¥È¤ò¥·¥¹¥Æ¥à¥¨¥ó¥È¥ê¤Ë¥Þ¥Ã¥×¤Ç¤­¤Þ¤»¤ó¡ª");
-#else
-       if (i == 0) quit("Cannot realize palette!");
-#endif
+       if (i == 0) quit(_("パレットをシステムエントリにマップできません!", "Cannot realize palette!"));
 
 
        /* Sub-windows */
@@ -1575,92 +1647,154 @@ static int new_palette(void)
 
 
 #ifdef USE_GRAPHICS
-/*
- * Initialize graphics
+/*!
+ * @brief グラフィクスを初期化する / Initialize graphics
+ * @details
+ * <ul>
+ * <li>メニュー[オプション]>[グラフィクス]が「なし」以外の時に描画処理を初期化する。</li>
+ * <li>呼び出されるタイミングはロード時、及び同メニューで「なし」以外に変更される毎になる。</li>
+ * </ul>
  */
 static bool init_graphics(void)
 {
        /* Initialize once */
-       /* if (can_use_graphics != arg_graphics) */
-       {
-               char buf[1024];
-               int wid, hgt;
-               cptr name;
+       char buf[1024];
+       BYTE wid, hgt, twid, thgt, ox, oy;
+       concptr name;
 
-               if (arg_graphics == GRAPHICS_ADAM_BOLT)
-               {
-                       wid = 16;
-                       hgt = 16;
+       if (arg_graphics == GRAPHICS_ADAM_BOLT)
+       {
+               wid = 16;
+               hgt = 16;
+               twid = 16;
+               thgt = 16;
+               ox = 0;
+               oy = 0;
+               name = "16X16.BMP";
+
+               ANGBAND_GRAF = "new";
+       }
+       else if (arg_graphics == GRAPHICS_HENGBAND)
+       {
+               /*! @todo redraw
+               wid = 64;
+               hgt = 64;
+               twid = 32;
+               thgt = 32;
+               ox = -16;
+               oy = -24;
+               name = "64X64.BMP";
+               */
+
+               wid = 32;
+               hgt = 32;
+               twid = 32;
+               thgt = 32;
+               ox = 0;
+               oy = 0;
+               name = "32X32.BMP";
+
+               ANGBAND_GRAF = "ne2";
+       }
+       else
+       {
+               wid = 8;
+               hgt = 8;
+               twid = 8;
+               thgt = 8;
+               ox = 0;
+               oy = 0;
+               name = "8X8.BMP";
+               ANGBAND_GRAF = "old";
+       }
 
-                       name = "16X16.BMP";
+       /* Access the bitmap file */
+       path_build(buf, sizeof(buf), ANGBAND_DIR_XTRA_GRAF, name);
 
-                       ANGBAND_GRAF = "new";
-               }
-               else
-               {
-                       wid = 8;
-                       hgt = 8;
+       /* Load the bitmap or quit */
+       if (!ReadDIB(data[0].w, buf, &infGraph))
+       {
+               plog_fmt(_("ビットマップ '%s' を読み込めません。", "Cannot read bitmap file '%s'"), name);
+               return (FALSE);
+       }
 
-                       name = "8X8.BMP";
-                       ANGBAND_GRAF = "old";
-               }
+       /* Save the new sizes */
+       infGraph.CellWidth = wid;
+       infGraph.CellHeight = hgt;
+       infGraph.TileWidth = twid;
+       infGraph.TileHeight = thgt;
+       infGraph.OffsetX = ox;
+       infGraph.OffsetY = oy;
 
-               /* Access the bitmap file */
-               path_build(buf, sizeof(buf), ANGBAND_DIR_XTRA_GRAF, name);
+       if (arg_graphics == GRAPHICS_ADAM_BOLT)
+       {
+               /* Access the mask file */
+               path_build(buf, sizeof(buf), ANGBAND_DIR_XTRA_GRAF, "mask.bmp");
 
                /* Load the bitmap or quit */
-               if (!ReadDIB(data[0].w, buf, &infGraph))
+               if (!ReadDIB(data[0].w, buf, &infMask))
                {
-#ifdef JP
-                       plog_fmt("¥Ó¥Ã¥È¥Þ¥Ã¥× '%s' ¤òÆɤ߹þ¤á¤Þ¤»¤ó¡£", name);
-#else
-                       plog_fmt("Cannot read bitmap file '%s'", name);
-#endif
-
+                       plog_fmt("Cannot read bitmap file '%s'", buf);
                        return (FALSE);
                }
+       }
+       if (arg_graphics == GRAPHICS_HENGBAND)
+       {
+               /* Access the mask file */
+               path_build(buf, sizeof(buf), ANGBAND_DIR_XTRA_GRAF, "mask32.bmp");
 
-               /* Save the new sizes */
-               infGraph.CellWidth = wid;
-               infGraph.CellHeight = hgt;
-
-               if (arg_graphics == GRAPHICS_ADAM_BOLT)
+               /* Load the bitmap or quit */
+               if (!ReadDIB(data[0].w, buf, &infMask))
                {
-                       /* Access the mask file */
-                       path_build(buf, sizeof(buf), ANGBAND_DIR_XTRA_GRAF, "mask.bmp");
-
-                       /* Load the bitmap or quit */
-                       if (!ReadDIB(data[0].w, buf, &infMask))
-                       {
-                               plog_fmt("Cannot read bitmap file '%s'", buf);
-                               return (FALSE);
-                       }
+                       plog_fmt("Cannot read bitmap file '%s'", buf);
+                       return (FALSE);
                }
+       }
 
-               /* Activate a palette */
-               if (!new_palette())
-               {
-                       /* Free bitmap XXX XXX XXX */
+       /* Activate a palette */
+       if (!new_palette())
+       {
+               /* Free bitmap */
 
-                       /* Oops */
-#ifdef JP
-                       plog("¥Ñ¥ì¥Ã¥È¤ò¼Â¸½¤Ç¤­¤Þ¤»¤ó¡ª");
-#else
-                       plog("Cannot activate palette!");
-#endif
+               plog(_("パレットを実現できません!", "Cannot activate palette!"));
+               return (FALSE);
+       }
 
-                       return (FALSE);
-               }
+       /* Graphics available */
+       current_graphics_mode = arg_graphics;
+       return (current_graphics_mode);
+}
+#endif /* USE_GRAPHICS */
+
+
+#ifdef USE_MUSIC
+/*
+ * Initialize music
+ */
+static bool init_music(void)
+{
+       /* Initialize once */
+       if (!can_use_music)
+       {
+               /* Load the prefs */
+               load_music_prefs();
 
-               /* Graphics available */
-               can_use_graphics = arg_graphics;
+               /* Sound available */
+               can_use_music = TRUE;
        }
+       return (can_use_music);
+}
 
-       /* Result */
-       return (can_use_graphics);
+/*
+ * Hack -- Stop a music
+ */
+static void stop_music(void)
+{
+       mciSendCommand(mop.wDeviceID, MCI_STOP, 0, 0);
+       mciSendCommand(mop.wDeviceID, MCI_CLOSE, 0, 0);
 }
-#endif /* USE_GRAPHICS */
 
+#endif /* USE_MUSIC */
 
 #ifdef USE_SOUND
 /*
@@ -1677,8 +1811,6 @@ static bool init_sound(void)
                /* Sound available */
                can_use_sound = TRUE;
        }
-
-       /* Result */
        return (can_use_sound);
 }
 #endif /* USE_SOUND */
@@ -1711,7 +1843,7 @@ static void term_window_resize(term_data *td)
  *
  * Note that the "font name" must be capitalized!!!
  */
-static errr term_force_font(term_data *td, cptr path)
+static errr term_force_font(term_data *td, concptr path)
 {
        int wid, hgt;
 
@@ -1991,8 +2123,8 @@ static void Term_nuke_win(term *t)
 #endif
 
 
-/*
- * Interact with the User
+/*!
+ * @brief //!< Windows版ユーザ設定項目実装部(実装必須) /Interact with the User
  */
 static errr Term_user_win(int n)
 {
@@ -2011,7 +2143,6 @@ static errr Term_xtra_win_react(void)
 {
        int i;
 
-
        /* Simple color */
        if (colors16)
        {
@@ -2068,12 +2199,7 @@ static errr Term_xtra_win_react(void)
                if (arg_sound && !init_sound())
                {
                        /* Warning */
-#ifdef JP
-                       plog("¥µ¥¦¥ó¥É¤ò½é´ü²½¤Ç¤­¤Þ¤»¤ó¡ª");
-#else
-                       plog("Cannot initialize sound!");
-#endif
-
+                       plog(_("サウンドを初期化できません!", "Cannot initialize sound!"));
 
                        /* Cannot enable */
                        arg_sound = FALSE;
@@ -2085,6 +2211,30 @@ static errr Term_xtra_win_react(void)
 
 #endif
 
+#ifdef USE_MUSIC
+
+       /* Handle "arg_sound" */
+       if (use_music != arg_music)
+       {
+               /* Initialize (if needed) */
+               if (arg_music && !init_music())
+               {
+                       /* Warning */
+                       plog(_("BGMを初期化できません!", "Cannot initialize BGM!"));
+                       /* Cannot enable */
+                       arg_music = FALSE;
+               }
+
+               /* Change setting */
+               use_music = arg_music;
+
+               if(!arg_music) stop_music();
+               else select_floor_music();
+
+       }
+
+#endif
+
 
 #ifdef USE_GRAPHICS
 
@@ -2095,12 +2245,7 @@ static errr Term_xtra_win_react(void)
                if (arg_graphics && !init_graphics())
                {
                        /* Warning */
-#ifdef JP
-                       plog("¥°¥é¥Õ¥£¥Ã¥¯¥¹¤ò½é´ü²½¤Ç¤­¤Þ¤»¤ó!");
-#else
-                       plog("Cannot initialize graphics!");
-#endif
-
+                       plog(_("グラフィックスを初期化できません!", "Cannot initialize graphics!"));
 
                        /* Cannot enable */
                        arg_graphics = GRAPHICS_NONE;
@@ -2128,7 +2273,7 @@ static errr Term_xtra_win_react(void)
                term_data *td = &data[i];
 
                /* Update resized windows */
-               if ((td->cols != (uint)td->t.wid) || (td->rows != (uint)td->t.hgt))
+               if ((td->cols != td->t.wid) || (td->rows != td->t.hgt))
                {
                        /* Activate */
                        Term_activate(&td->t);
@@ -2138,8 +2283,6 @@ static errr Term_xtra_win_react(void)
 
                        /* Redraw the contents */
                        Term_redraw();
-
-                       /* Restore */
                        Term_activate(old);
                }
        }
@@ -2206,7 +2349,7 @@ static errr Term_xtra_win_flush(void)
 /*
  * Hack -- clear the screen
  *
- * Make this more efficient XXX XXX XXX
+ * Make this more efficient 
  */
 static errr Term_xtra_win_clear(void)
 {
@@ -2279,7 +2422,7 @@ static errr Term_xtra_win_sound(int v)
        if (i == 0) return (1);
 
        /* Build the path */
-       path_build(buf, 1024, ANGBAND_DIR_XTRA_SOUND, sound_file[v][Rand_simple(i)]);
+       path_build(buf, 1024, ANGBAND_DIR_XTRA_SOUND, sound_file[v][Rand_external(i)]);
 
 #ifdef WIN32
 
@@ -2295,12 +2438,123 @@ static errr Term_xtra_win_sound(int v)
 
 #else /* USE_SOUND */
 
-       /* Oops */
        return (1);
 
 #endif /* USE_SOUND */
 }
 
+/*
+ * Hack -- play a music
+ */
+static errr Term_xtra_win_music(int n, int v)
+{
+#ifdef USE_MUSIC
+       int i = 0;
+       char buf[1024];
+#endif /* USE_MUSIC */
+
+       /* Sound disabled */
+
+       if(!use_music) return (1);
+
+       /* Illegal sound */
+       if(n == TERM_XTRA_MUSIC_BASIC && ((v < 0) || (v >= MUSIC_BASIC_MAX))) return (1);
+       else if(v < 0 || v >= 1000) return(1); /*!< TODO */
+
+#ifdef USE_MUSIC
+
+       switch(n)
+       {
+       case TERM_XTRA_MUSIC_BASIC:
+               for (i = 0; i < SAMPLE_MAX; i++) if(!music_file[v][i]) break;
+               break;
+       case TERM_XTRA_MUSIC_DUNGEON:
+               for (i = 0; i < SAMPLE_MAX; i++) if(!dungeon_music_file[v][i]) break;
+               break;
+       case TERM_XTRA_MUSIC_QUEST:
+               for (i = 0; i < SAMPLE_MAX; i++) if(!quest_music_file[v][i]) break;
+               break;
+       case TERM_XTRA_MUSIC_TOWN:
+               for (i = 0; i < SAMPLE_MAX; i++) if(!town_music_file[v][i]) break;
+               break;
+       }
+
+       /* No sample */
+       if (i == 0)
+       {
+               //mciSendCommand(mop.wDeviceID, MCI_STOP, 0, 0);
+               //mciSendCommand(mop.wDeviceID, MCI_CLOSE, 0, 0);
+               return (1);
+       }
+
+       switch(n)
+       {
+       case TERM_XTRA_MUSIC_BASIC:
+               for (i = 0; i < SAMPLE_MAX; i++) if(!music_file[v][i]) break;
+               break;
+       case TERM_XTRA_MUSIC_DUNGEON:
+               for (i = 0; i < SAMPLE_MAX; i++) if(!dungeon_music_file[v][i]) break;
+               break;
+       case TERM_XTRA_MUSIC_QUEST:
+               for (i = 0; i < SAMPLE_MAX; i++) if(!quest_music_file[v][i]) break;
+               break;
+       case TERM_XTRA_MUSIC_TOWN:
+               for (i = 0; i < SAMPLE_MAX; i++) if(!town_music_file[v][i]) break;
+               break;
+       }
+
+       /* No sample */
+       if (i == 0)
+       {
+               mciSendCommand(mop.wDeviceID, MCI_STOP, 0, 0);
+               mciSendCommand(mop.wDeviceID, MCI_CLOSE, 0, 0);
+               return (1);
+       }
+
+       switch(n)
+       {
+       case TERM_XTRA_MUSIC_BASIC:
+               path_build(buf, 1024, ANGBAND_DIR_XTRA_MUSIC, music_file[v][Rand_external(i)]);
+               break;
+       case TERM_XTRA_MUSIC_DUNGEON:
+               path_build(buf, 1024, ANGBAND_DIR_XTRA_MUSIC, dungeon_music_file[v][Rand_external(i)]);
+               break;
+       case TERM_XTRA_MUSIC_QUEST:
+               path_build(buf, 1024, ANGBAND_DIR_XTRA_MUSIC, quest_music_file[v][Rand_external(i)]);
+               break;
+       case TERM_XTRA_MUSIC_TOWN:
+               path_build(buf, 1024, ANGBAND_DIR_XTRA_MUSIC, town_music_file[v][Rand_external(i)]);
+               break;
+       }
+
+       if(current_music_type == n && current_music_id == v)
+       {
+               return (0);
+       }
+       current_music_type = n;
+       current_music_id = v;
+
+#ifdef WIN32
+
+       mop.lpstrDeviceType = mci_device_type;  
+       mop.lpstrElementName = buf;
+       mciSendCommand(mop.wDeviceID, MCI_STOP, 0, 0);
+       mciSendCommand(mop.wDeviceID, MCI_CLOSE, 0, 0);
+       mciSendCommand(mop.wDeviceID, MCI_OPEN, MCI_OPEN_TYPE | MCI_OPEN_ELEMENT, (DWORD)&mop);
+       mciSendCommand(mop.wDeviceID, MCI_SEEK, MCI_SEEK_TO_START, 0);
+       mciSendCommand(mop.wDeviceID, MCI_PLAY, MCI_NOTIFY, (DWORD)&mop);
+       return (0);
+
+#endif /* WIN32 */
+
+#else /* USE_MUSIC */
+
+       return (1);
+
+#endif /* USE_MUSIC */
+
+}
+
 
 /*
  * Delay for "x" milliseconds
@@ -2353,6 +2607,15 @@ static errr Term_xtra_win(int n, int v)
                        return (Term_xtra_win_noise());
                }
 
+               /* Play a music */
+               case TERM_XTRA_MUSIC_BASIC:
+               case TERM_XTRA_MUSIC_DUNGEON:
+               case TERM_XTRA_MUSIC_QUEST:
+               case TERM_XTRA_MUSIC_TOWN:
+               {
+                       return (Term_xtra_win_music(n, v));
+               }
+
                /* Make a special sound */
                case TERM_XTRA_SOUND:
                {
@@ -2396,7 +2659,6 @@ static errr Term_xtra_win(int n, int v)
                }
        }
 
-       /* Oops */
        return 1;
 }
 
@@ -2527,9 +2789,9 @@ static errr Term_wipe_win(int x, int y, int n)
  *
  * One would think there is a more efficient method for telling a window
  * what color it should be using to draw with, but perhaps simply changing
- * it every time is not too inefficient.  XXX XXX XXX
+ * it every time is not too inefficient.  
  */
-static errr Term_text_win(int x, int y, int n, byte a, const char *s)
+static errr Term_text_win(int x, int y, int n, TERM_COLOR a, concptr s)
 {
        term_data *td = (term_data*)(Term->data);
        RECT rc;
@@ -2603,7 +2865,7 @@ static errr Term_text_win(int x, int y, int n, byte a, const char *s)
                for (i = 0; i < n; i++)
                {
 #ifdef JP
-                       if (use_bigtile && *(s+i)=="¢£"[0] && *(s+i+1)=="¢£"[1])
+                       if (use_bigtile && *(s+i)=="■"[0] && *(s+i+1)=="■"[1])
                        {
                                rc.right += td->font_wid;
 
@@ -2622,7 +2884,7 @@ static errr Term_text_win(int x, int y, int n, byte a, const char *s)
                                rc.left += 2 * td->tile_wid;
                                rc.right += 2 * td->tile_wid;
                        }
-                       else if ( iskanji(*(s+i)) )  /*  £²¥Ð¥¤¥Èʸ»ú  */
+                       else if ( iskanji(*(s+i)) )  /*  2バイト文字  */
                        {
                                rc.right += td->font_wid;
                                /* Dump the text */
@@ -2722,24 +2984,22 @@ static errr Term_text_win(int x, int y, int n, byte a, const char *s)
  *
  * If "graphics" is not available, we simply "wipe" the given grids.
  */
-static errr Term_pict_win(int x, int y, int n, const byte *ap, const char *cp, const byte *tap, const char *tcp)
+static errr Term_pict_win(TERM_LEN x, TERM_LEN y, int n, const TERM_COLOR *ap, concptr cp, const TERM_COLOR *tap, concptr tcp)
 {
        term_data *td = (term_data*)(Term->data);
 
 #ifdef USE_GRAPHICS
 
        int i;
-       int x1, y1, w1, h1;
-       int x2, y2, w2, h2, tw2;
-       int x3, y3;
+       TERM_LEN x1, y1, w1, h1, tw1, th1;
+       TERM_LEN x2, y2, w2, h2, tw2 = 0;
+       TERM_LEN x3, y3;
 
-       HDC hdcMask;
+       HDC hdcMask = NULL;
 
        HDC hdc;
        HDC hdcSrc;
        HBITMAP hbmSrcOld;
-
-       /* Paranoia */
        if (!use_graphics)
        {
                /* Erase the grids */
@@ -2749,6 +3009,8 @@ static errr Term_pict_win(int x, int y, int n, const byte *ap, const char *cp, c
        /* Size of bitmap cell */
        w1 = infGraph.CellWidth;
        h1 = infGraph.CellHeight;
+       tw1 = infGraph.TileWidth;
+       th1 = infGraph.TileHeight;
 
        /* Size of window cell */
        if (td->map_active)
@@ -2767,8 +3029,8 @@ static errr Term_pict_win(int x, int y, int n, const byte *ap, const char *cp, c
        }
 
        /* Location of window cell */
-       x2 = x * w2 + td->size_ow1;
-       y2 = y * h2 + td->size_oh1;
+       x2 = x * w2 + td->size_ow1 + infGraph.OffsetX;
+       y2 = y * h2 + td->size_oh1 + infGraph.OffsetY;
 
        /* Info */
        hdc = GetDC(td->w);
@@ -2777,7 +3039,7 @@ static errr Term_pict_win(int x, int y, int n, const byte *ap, const char *cp, c
        hdcSrc = CreateCompatibleDC(hdc);
        hbmSrcOld = SelectObject(hdcSrc, infGraph.hBitmap);
 
-       if (arg_graphics == GRAPHICS_ADAM_BOLT)
+       if (arg_graphics == GRAPHICS_ADAM_BOLT || arg_graphics == GRAPHICS_HENGBAND)
        {
                hdcMask = CreateCompatibleDC(hdc);
                SelectObject(hdcMask, infMask.hBitmap);
@@ -2786,9 +3048,10 @@ static errr Term_pict_win(int x, int y, int n, const byte *ap, const char *cp, c
        /* Draw attr/char pairs */
        for (i = 0; i < n; i++, x2 += w2)
        {
-               byte a = ap[i];
+               TERM_COLOR a = ap[i];
                char c = cp[i];
 
+
                /* Extract picture */
                int row = (a & 0x7F);
                int col = (c & 0x7F);
@@ -2797,13 +3060,15 @@ static errr Term_pict_win(int x, int y, int n, const byte *ap, const char *cp, c
                x1 = col * w1;
                y1 = row * h1;
 
-               if (arg_graphics == GRAPHICS_ADAM_BOLT)
+               if (arg_graphics == GRAPHICS_ADAM_BOLT || arg_graphics == GRAPHICS_HENGBAND)
                {
                        x3 = (tcp[i] & 0x7F) * w1;
                        y3 = (tap[i] & 0x7F) * h1;
+                       tw2 = tw2 * w1 / tw1;
+                       h2 = h2 * h1 / th1;
 
                        /* Perfect size */
-                       if ((w1 == tw2) && (h1 == h2))
+                       if ((tw1 == tw2) && (th1 == h2))
                        {
                                /* Copy the terrain picture from the bitmap to the window */
                                BitBlt(hdc, x2, y2, tw2, h2, hdcSrc, x3, y3, SRCCOPY);
@@ -2822,7 +3087,9 @@ static errr Term_pict_win(int x, int y, int n, const byte *ap, const char *cp, c
                                SetStretchBltMode(hdc, COLORONCOLOR);
 
                                /* Copy the terrain picture from the bitmap to the window */
-                               StretchBlt(hdc, x2, y2, tw2, h2, hdcSrc, x3, y3, w1, h1, SRCCOPY);
+                               StretchBlt(hdc, x2, y2, tw2, h2, hdcMask, x3, y3, w1, h1, SRCAND);
+
+                               StretchBlt(hdc, x2, y2, tw2, h2, hdcSrc, x3, y3, w1, h1, SRCPAINT);
 
                                /* Only draw if terrain and overlay are different */
                                if ((x1 != x3) || (y1 != y3))
@@ -2860,7 +3127,7 @@ static errr Term_pict_win(int x, int y, int n, const byte *ap, const char *cp, c
        SelectObject(hdcSrc, hbmSrcOld);
        DeleteDC(hdcSrc);
 
-       if (arg_graphics == GRAPHICS_ADAM_BOLT)
+       if (arg_graphics == GRAPHICS_ADAM_BOLT || arg_graphics == GRAPHICS_HENGBAND)
        {
                /* Release */
                SelectObject(hdcMask, hbmSrcOld);
@@ -2885,16 +3152,16 @@ static errr Term_pict_win(int x, int y, int n, const byte *ap, const char *cp, c
 static void windows_map(void)
 {
        term_data *td = &data[0];
-       byte a, c;
-       int x, min_x, max_x;
-       int y, min_y, max_y;
+       TERM_COLOR a;
+       char c;
+       TERM_LEN x, min_x, max_x;
+       TERM_LEN y, min_y, max_y;
 
-       byte ta, tc;
+       TERM_COLOR ta;
+       char tc;
 
        /* Only in graphics mode */
        if (!use_graphics) return;
-
-       /* Clear screen */
        Term_xtra_win_clear();
 
        td->map_tile_wid = (td->tile_wid * td->cols) / MAX_WID;
@@ -2904,8 +3171,8 @@ static void windows_map(void)
        {
                min_x = 0;
                min_y = 0;
-               max_x = cur_wid;
-               max_y = cur_hgt;
+               max_x = current_floor_ptr->width;
+               max_y = current_floor_ptr->height;
        }
 
        /* Draw the map */
@@ -2924,7 +3191,7 @@ static void windows_map(void)
        }
 
        /* Hilite the player */
-       Term_curs_win(px - min_x, py - min_y);
+       Term_curs_win(p_ptr->x - min_x, p_ptr->y - min_y);
 
        /* Wait for a keypress, flush key buffer */
        Term_inkey(&c, TRUE, TRUE);
@@ -2989,7 +3256,7 @@ static void term_data_link(term_data *td)
  * to over-ride selected values, then create the windows, and fonts.
  *
  * Must use SW_SHOW not SW_SHOWNA, since on 256 color display
- * must make active to realize the palette.  XXX XXX XXX
+ * must make active to realize the palette.  
  */
 static void init_windows(void)
 {
@@ -3005,7 +3272,7 @@ static void init_windows(void)
        td = &data[0];
        WIPE(td, term_data);
 #ifdef JP
-       td->s = "ÊѶòÈÚÅÜ";
+       td->s = "変愚蛮怒";
 #else
        td->s = angband_term_name[0];
 #endif
@@ -3079,8 +3346,8 @@ static void init_windows(void)
                td->lf.lfPitchAndFamily = FIXED_PITCH | FF_DONTCARE;
                /* Activate the chosen font */
                term_force_font(td, NULL);
-               td->tile_wid = td->font_wid;
-               td->tile_hgt = td->font_hgt;
+               if(!td->tile_wid) td->tile_wid = td->font_wid;
+               if(!td->tile_hgt) td->tile_hgt = td->font_hgt;
 #else
                /* Access the standard font file */
                path_build(buf, sizeof(buf), ANGBAND_DIR_XTRA_FONT, td->font_want);
@@ -3094,7 +3361,6 @@ static void init_windows(void)
                        /* Force the use of that font */
                        (void)term_force_font(td, buf);
 
-                       /* Oops */
                        td->tile_wid = 8;
                        td->tile_hgt = 13;
 
@@ -3124,12 +3390,7 @@ static void init_windows(void)
                                       td->size_wid, td->size_hgt,
                                       HWND_DESKTOP, NULL, hInstance, NULL);
                my_td = NULL;
-#ifdef JP
-               if (!td->w) quit("¥µ¥Ö¥¦¥£¥ó¥É¥¦¤ËºîÀ®¤Ë¼ºÇÔ¤·¤Þ¤·¤¿");
-#else
-               if (!td->w) quit("Failed to create sub-window");
-#endif
-
+               if (!td->w) quit(_("サブウィンドウに作成に失敗しました", "Failed to create sub-window"));
 
                if (td->visible)
                {
@@ -3169,12 +3430,7 @@ static void init_windows(void)
                               td->size_wid, td->size_hgt,
                               HWND_DESKTOP, NULL, hInstance, NULL);
        my_td = NULL;
-#ifdef JP
-       if (!td->w) quit("¥á¥¤¥ó¥¦¥£¥ó¥É¥¦¤ÎºîÀ®¤Ë¼ºÇÔ¤·¤Þ¤·¤¿");
-#else
-       if (!td->w) quit("Failed to create Angband window");
-#endif
-
+       if (!td->w) quit(_("メインウィンドウの作成に失敗しました", "Failed to create Angband window"));
 
        term_data_link(td);
        angband_term[0] = &td->t;
@@ -3189,7 +3445,7 @@ static void init_windows(void)
        SetWindowPos(td->w, HWND_TOP, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE);
 
 
-       /* New palette XXX XXX XXX */
+       /* New palette */
        (void)new_palette();
 
 
@@ -3397,8 +3653,12 @@ static void setup_menus(void)
                      (arg_graphics == GRAPHICS_ORIGINAL ? MF_CHECKED : MF_UNCHECKED));
        CheckMenuItem(hm, IDM_OPTIONS_NEW_GRAPHICS,
                      (arg_graphics == GRAPHICS_ADAM_BOLT ? MF_CHECKED : MF_UNCHECKED));
+       CheckMenuItem(hm, IDM_OPTIONS_NEW2_GRAPHICS,
+                     (arg_graphics == GRAPHICS_HENGBAND ? MF_CHECKED : MF_UNCHECKED));
        CheckMenuItem(hm, IDM_OPTIONS_BIGTILE,
                      (arg_bigtile ? MF_CHECKED : MF_UNCHECKED));
+       CheckMenuItem(hm, IDM_OPTIONS_MUSIC,
+                     (arg_music ? MF_CHECKED : MF_UNCHECKED));
        CheckMenuItem(hm, IDM_OPTIONS_SOUND,
                      (arg_sound ? MF_CHECKED : MF_UNCHECKED));
        CheckMenuItem(hm, IDM_OPTIONS_BG,
@@ -3482,21 +3742,11 @@ static void process_menus(WORD wCmd)
                {
                        if (!initialized)
                        {
-#ifdef JP
-                               plog("¤Þ¤À½é´ü²½Ãæ¤Ç¤¹...");
-#else
-                               plog("You cannot do that yet...");
-#endif
-
+                               plog(_("まだ初期化中です...", "You cannot do that yet..."));
                        }
                        else if (game_in_progress)
                        {
-#ifdef JP
-                               plog("¥×¥ì¥¤Ãæ¤Ï¿·¤·¤¤¥²¡¼¥à¤ò»Ï¤á¤ë¤³¤È¤¬¤Ç¤­¤Þ¤»¤ó¡ª");
-#else
-                               plog("You can't start a new game while you're still playing!");
-#endif
-
+                               plog(_("プレイ中は新しいゲームを始めることができません!", "You can't start a new game while you're still playing!"));
                        }
                        else
                        {
@@ -3513,21 +3763,11 @@ static void process_menus(WORD wCmd)
                {
                        if (!initialized)
                        {
-#ifdef JP
-                               plog("¤Þ¤À½é´ü²½Ãæ¤Ç¤¹...");
-#else
-                               plog("You cannot do that yet...");
-#endif
-
+                               plog(_("まだ初期化中です...", "You cannot do that yet..."));
                        }
                        else if (game_in_progress)
                        {
-#ifdef JP
-                               plog("¥×¥ì¥¤Ãæ¤Ï¥²¡¼¥à¤ò¥í¡¼¥É¤¹¤ë¤³¤È¤¬¤Ç¤­¤Þ¤»¤ó¡ª");
-#else
-                               plog("You can't open a new game while you're still playing!");
-#endif
-
+                               plog(_("プレイ中はゲームをロードすることができません!", "You can't open a new game while you're still playing!"));
                        }
                        else
                        {
@@ -3559,15 +3799,9 @@ static void process_menus(WORD wCmd)
                {
                        if (game_in_progress && character_generated)
                        {
-                               /* Paranoia */
                                if (!can_save)
                                {
-#ifdef JP
-                                       plog("º£¤Ï¥»¡¼¥Ö¤¹¤ë¤³¤È¤Ï½ÐÍè¤Þ¤»¤ó¡£");
-#else
-                                       plog("You may not do that right now.");
-#endif
-
+                                       plog(_("今はセーブすることは出来ません。", "You may not do that right now."));
                                        break;
                                }
 
@@ -3583,12 +3817,7 @@ static void process_menus(WORD wCmd)
                        }
                        else
                        {
-#ifdef JP
-                               plog("º£¡¢¥»¡¼¥Ö¤¹¤ë¤³¤È¤Ï½ÐÍè¤Þ¤»¤ó¡£");
-#else
-                               plog("You may not do that right now.");
-#endif
-
+                               plog(_("今、セーブすることは出来ません。", "You may not do that right now."));
                        }
                        break;
                }
@@ -3598,15 +3827,9 @@ static void process_menus(WORD wCmd)
                {
                        if (game_in_progress && character_generated)
                        {
-                               /* Paranoia */
                                if (!can_save)
                                {
-#ifdef JP
-                                       plog("º£¤Ï½ªÎ»¤Ç¤­¤Þ¤»¤ó¡£");
-#else
-                                       plog("You may not do that right now.");
-#endif
-
+                                       plog(_("今は終了できません。", "You may not do that right now."));
                                        break;
                                }
 
@@ -3648,10 +3871,7 @@ static void process_menus(WORD wCmd)
                        }
                        else
                        {
-                               /* Save Screen */
                                screen_save();
-
-                               /* Clear screen */
                                Term_clear();
 
                                /* Display the scores */
@@ -3662,8 +3882,6 @@ static void process_menus(WORD wCmd)
 
                                /* Forget the high score fd */
                                highscore_fd = -1;
-
-                               /* Load screen */
                                screen_load();
 
                                /* Hack - Flush it */
@@ -3678,19 +3896,11 @@ static void process_menus(WORD wCmd)
                {
                        if (!initialized)
                        {
-#ifdef JP
-                               plog("¤Þ¤À½é´ü²½Ãæ¤Ç¤¹...");
-#else
-                               plog("You cannot do that yet...");
-#endif
+                               plog(_("まだ初期化中です...", "You cannot do that yet..."));
                        }
                        else if (game_in_progress)
                        {
-#ifdef JP
-                               plog("¥×¥ì¥¤Ãæ¤Ï¥à¡¼¥Ó¡¼¤ò¥í¡¼¥É¤¹¤ë¤³¤È¤¬¤Ç¤­¤Þ¤»¤ó¡ª");
-#else
-                               plog("You can't open a movie while you're playing!");
-#endif
+                               plog(_("プレイ中はムービーをロードすることができません!", "You can't open a movie while you're playing!"));
                        }
                        else
                        {
@@ -3719,13 +3929,7 @@ static void process_menus(WORD wCmd)
 
                case IDM_WINDOW_VIS_0:
                {
-#ifdef JP
-                       plog("¥á¥¤¥ó¥¦¥£¥ó¥É¥¦¤ÏÈóɽ¼¨¤Ë¤Ç¤­¤Þ¤»¤ó¡ª");
-#else
-                       plog("You are not allowed to do that!");
-#endif
-
-
+                       plog(_("メインウィンドウは非表示にできません!", "You are not allowed to do that!"));
                        break;
                }
 
@@ -3937,7 +4141,6 @@ static void process_menus(WORD wCmd)
 
                case IDM_OPTIONS_NO_GRAPHICS:
                {
-                       /* Paranoia */
                        if (!inkey_flag)
                        {
                                plog("You may not do that right now.");
@@ -3961,7 +4164,6 @@ static void process_menus(WORD wCmd)
 
                case IDM_OPTIONS_OLD_GRAPHICS:
                {
-                       /* Paranoia */
                        if (!inkey_flag)
                        {
                                plog("You may not do that right now.");
@@ -3985,7 +4187,6 @@ static void process_menus(WORD wCmd)
 
                case IDM_OPTIONS_NEW_GRAPHICS:
                {
-                       /* Paranoia */
                        if (!inkey_flag)
                        {
                                plog("You may not do that right now.");
@@ -4007,11 +4208,32 @@ static void process_menus(WORD wCmd)
                        break;
                }
 
-               case IDM_OPTIONS_BIGTILE:
+               case IDM_OPTIONS_NEW2_GRAPHICS:
                {
-                       term_data *td = &data[0];
+                       if (!inkey_flag)
+                       {
+                               plog("You may not do that right now.");
+                               break;
+                       }
+
+                       /* Toggle "arg_graphics" */
+                       if (arg_graphics != GRAPHICS_HENGBAND)
+                       {
+                               arg_graphics = GRAPHICS_HENGBAND;
+
+                               /* React to changes */
+                               Term_xtra_win_react();
+
+                               /* Hack -- Force redraw */
+                               Term_key_push(KTRL('R'));
+                       }
+
+                       break;
+               }
 
-                       /* Paranoia */
+               case IDM_OPTIONS_BIGTILE:
+               {
+                       td = &data[0];
                        if (!inkey_flag)
                        {
                                plog("You may not do that right now.");
@@ -4033,9 +4255,28 @@ static void process_menus(WORD wCmd)
                        break;
                }
 
+               case IDM_OPTIONS_MUSIC:
+               {
+                       if (!inkey_flag)
+                       {
+                               plog("You may not do that right now.");
+                               break;
+                       }
+
+                       /* Toggle "arg_sound" */
+                       arg_music = !arg_music;
+
+                       /* React to changes */
+                       Term_xtra_win_react();
+
+                       /* Hack -- Force redraw */
+                       Term_key_push(KTRL('R'));
+
+                       break;
+               }
+
                case IDM_OPTIONS_SOUND:
                {
-                       /* Paranoia */
                        if (!inkey_flag)
                        {
                                plog("You may not do that right now.");
@@ -4057,7 +4298,6 @@ static void process_menus(WORD wCmd)
                /* bg */
                case IDM_OPTIONS_BG:
                {
-                       /* Paranoia */
                        if (!inkey_flag)
                        {
                                plog("You may not do that right now.");
@@ -4081,7 +4321,6 @@ static void process_menus(WORD wCmd)
                /* bg */
                case IDM_OPTIONS_OPEN_BG:
                {
-                       /* Paranoia */
                        if (!inkey_flag)
                        {
                                plog("You may not do that right now.");
@@ -4097,11 +4336,7 @@ static void process_menus(WORD wCmd)
                                ofn.lpstrFile = bg_bitmap_file;
                                ofn.nMaxFile = 1023;
                                ofn.lpstrInitialDir = NULL;
-#ifdef JP
-                               ofn.lpstrTitle = "ÊÉ»æ¤òÁª¤ó¤Ç¤Í¡£";
-#else
-                               ofn.lpstrTitle = "Choose wall paper.";
-#endif
+                               ofn.lpstrTitle = _("壁紙を選んでね。", "Choose wall paper.");
                                ofn.Flags = OFN_FILEMUSTEXIST | OFN_HIDEREADONLY;
 
                                if (GetOpenFileName(&ofn))
@@ -4132,11 +4367,7 @@ static void process_menus(WORD wCmd)
                        ofn.nMaxFile = 1023;
                        ofn.lpstrDefExt = "html";
                        ofn.lpstrInitialDir = NULL;
-#ifdef JP
-                       ofn.lpstrTitle = "HTML¤Ç¥¹¥¯¥ê¡¼¥ó¥À¥ó¥×¤òÊݸ";
-#else
-                       ofn.lpstrTitle = "Save screen dump as HTML.";
-#endif
+                       ofn.lpstrTitle = _("HTMLでスクリーンダンプを保存", "Save screen dump as HTML.");
                        ofn.Flags = OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT;
 
                        if (GetSaveFileName(&ofn))
@@ -4167,17 +4398,12 @@ static void process_menus(WORD wCmd)
 
                                if (hwndSaver)
                                {
-                                       /* Push the window to the bottom XXX XXX XXX */
+                                       /* Push the window to the bottom */
                                        SetWindowPos(hwndSaver, HWND_BOTTOM, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE);
                                }
                                else
                                {
-#ifdef JP
-                                       plog("¥¦¥£¥ó¥É¥¦¤òºîÀ®½ÐÍè¤Þ¤»¤ó");
-#else
-                                       plog("Failed to create saver window");
-#endif
-
+                                       plog(_("ウィンドウを作成出来ません", "Failed to create saver window"));
                                }
                        }
                        break;
@@ -4202,14 +4428,8 @@ static void process_menus(WORD wCmd)
                        }
                        else
                        {
-#ifdef JP
-                               plog_fmt("¥Ø¥ë¥×¥Õ¥¡¥¤¥ë[%s]¤¬¸«ÉÕ¤«¤ê¤Þ¤»¤ó¡£", tmp);
-                               plog("Âå¤ï¤ê¤Ë¥ª¥ó¥é¥¤¥ó¥Ø¥ë¥×¤ò»ÈÍѤ·¤Æ¤¯¤À¤µ¤¤¡£");
-#else
-                               plog_fmt("Cannot find help file: %s", tmp);
-                               plog("Use the online help files instead.");
-#endif
-
+                               plog_fmt(_("ヘルプファイル[%s]が見付かりません。", "Cannot find help file: %s"), tmp);
+                               plog(_("代わりにオンラインヘルプを使用してください。", "Use the online help files instead."));
                        }
                        break;
 #else /* HTML_HELP */
@@ -4223,13 +4443,8 @@ static void process_menus(WORD wCmd)
                        }
                        else
                        {
-#ifdef JP
-                               plog_fmt("¥Ø¥ë¥×¥Õ¥¡¥¤¥ë[%s]¤¬¸«ÉÕ¤«¤ê¤Þ¤»¤ó¡£", tmp);
-                               plog("Âå¤ï¤ê¤Ë¥ª¥ó¥é¥¤¥ó¥Ø¥ë¥×¤ò»ÈÍѤ·¤Æ¤¯¤À¤µ¤¤¡£");
-#else
-                               plog_fmt("Cannot find help file: %s", tmp);
-                               plog("Use the online help files instead.");
-#endif
+                               plog_fmt(_("ヘルプファイル[%s]が見付かりません。", "Cannot find help file: %s"), tmp);
+                               plog(_("代わりにオンラインヘルプを使用してください。", "Use the online help files instead."));
 
                        }
                        break;
@@ -4336,8 +4551,7 @@ LRESULT FAR PASCAL AngbandWndProc(HWND hWnd, UINT uMsg,
 LRESULT FAR PASCAL AngbandWndProc(HWND hWnd, UINT uMsg,
                                  WPARAM wParam, LPARAM lParam)
 #else /* __MWERKS__ */
-LRESULT FAR PASCAL AngbandWndProc(HWND hWnd, UINT uMsg,
-                                         WPARAM wParam, LPARAM lParam)
+LRESULT FAR PASCAL AngbandWndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
 #endif /* __MWERKS__ */
 {
        PAINTSTRUCT ps;
@@ -4356,16 +4570,17 @@ LRESULT FAR PASCAL AngbandWndProc(HWND hWnd, UINT uMsg,
        /* Handle message */
        switch (uMsg)
        {
-               /* XXX XXX XXX */
                case WM_NCCREATE:
                {
                        SetWindowLong(hWnd, 0, (LONG)(my_td));
                        break;
                }
 
-               /* XXX XXX XXX */
                case WM_CREATE:
                {
+#ifdef USE_MUSIC
+                       mop.dwCallback=(DWORD)hWnd;
+#endif
                        return 0;
                }
 
@@ -4403,6 +4618,18 @@ LRESULT FAR PASCAL AngbandWndProc(HWND hWnd, UINT uMsg,
                        return 0;
                }
 
+#ifdef USE_MUSIC
+               case MM_MCINOTIFY:
+               {
+                       if(wParam == MCI_NOTIFY_SUCCESSFUL)
+                       {
+                               mciSendCommand(mop.wDeviceID, MCI_SEEK, MCI_SEEK_TO_START, 0);
+                               mciSendCommand(mop.wDeviceID, MCI_PLAY, MCI_NOTIFY, (DWORD)&mop);
+                       }
+                       return 0;
+               }
+#endif
+
                case WM_SYSKEYDOWN:
                case WM_KEYDOWN:
                {
@@ -4432,11 +4659,11 @@ LRESULT FAR PASCAL AngbandWndProc(HWND hWnd, UINT uMsg,
                {
                        HGLOBAL hGlobal;
                        LPSTR lpStr;
-                       int i, j, sz;
-                       int dx = abs(oldx - mousex) + 1;
-                       int dy = abs(oldy - mousey) + 1;
-                       int ox = (oldx > mousex) ? mousex : oldx;
-                       int oy = (oldy > mousey) ? mousey : oldy;
+                       int j, sz;
+                       TERM_LEN dx = abs(oldx - mousex) + 1;
+                       TERM_LEN dy = abs(oldy - mousey) + 1;
+                       TERM_LEN ox = (oldx > mousex) ? mousex : oldx;
+                       TERM_LEN oy = (oldy > mousey) ? mousey : oldy;
 
                        mouse_down = FALSE;
                        paint_rect = FALSE;
@@ -4548,11 +4775,7 @@ LRESULT FAR PASCAL AngbandWndProc(HWND hWnd, UINT uMsg,
                        {
                                if (!can_save)
                                {
-#ifdef JP
-                                       plog("º£¤Ï½ªÎ»¤Ç¤­¤Þ¤»¤ó¡£");
-#else
-                                       plog("You may not do that right now.");
-#endif
+                                       plog(_("今は終了できません。", "You may not do that right now."));
                                        return 0;
                                }
 
@@ -4585,12 +4808,7 @@ LRESULT FAR PASCAL AngbandWndProc(HWND hWnd, UINT uMsg,
 
                                /* Mega-Hack -- Delay death */
                                if (p_ptr->chp < 0) p_ptr->is_dead = FALSE;
-
-#ifdef JP
-                               do_cmd_write_nikki(NIKKI_GAMESTART, 0, "----¥²¡¼¥àÃæÃÇ----");
-#else
-                               do_cmd_write_nikki(NIKKI_GAMESTART, 0, "---- Save and Exit Game ----");
-#endif
+                               do_cmd_write_nikki(NIKKI_GAMESTART, 0, _("----ゲーム中断----", "---- Save and Exit Game ----"));
 
                                /* Hardcode panic save */
                                p_ptr->panic_save = 1;
@@ -4599,11 +4817,7 @@ LRESULT FAR PASCAL AngbandWndProc(HWND hWnd, UINT uMsg,
                                signals_ignore_tstp();
 
                                /* Indicate panic save */
-#ifdef JP
-                               (void)strcpy(p_ptr->died_from, "(¶ÛµÞ¥»¡¼¥Ö)");
-#else
-                               (void)strcpy(p_ptr->died_from, "(panic save)");
-#endif
+                               (void)strcpy(p_ptr->died_from, _("(緊急セーブ)", "(panic save)"));
 
                                /* Panic save */
                                (void)save_player();
@@ -4649,13 +4863,13 @@ LRESULT FAR PASCAL AngbandWndProc(HWND hWnd, UINT uMsg,
 
                                case SIZE_MAXIMIZED:
                                {
-                                       /* fall through XXX XXX XXX */
+                                       /* fall through */
                                }
 
                                case SIZE_RESTORED:
                                {
-                                       uint cols = (LOWORD(lParam) - td->size_ow1) / td->tile_wid;
-                                       uint rows = (HIWORD(lParam) - td->size_oh1) / td->tile_hgt;
+                                       TERM_LEN cols = (LOWORD(lParam) - td->size_ow1) / td->tile_wid;
+                                       TERM_LEN rows = (HIWORD(lParam) - td->size_oh1) / td->tile_hgt;
 
                                        /* New size */
                                        if ((td->cols != cols) || (td->rows != rows))
@@ -4792,14 +5006,12 @@ LRESULT FAR PASCAL AngbandListProc(HWND hWnd, UINT uMsg,
        /* Process message */
        switch (uMsg)
        {
-               /* XXX XXX XXX */
                case WM_NCCREATE:
                {
                        SetWindowLong(hWnd, 0, (LONG)(my_td));
                        break;
                }
 
-               /* XXX XXX XXX */
                case WM_CREATE:
                {
                        return 0;
@@ -4832,8 +5044,8 @@ LRESULT FAR PASCAL AngbandListProc(HWND hWnd, UINT uMsg,
 
                case WM_SIZE:
                {
-                       uint cols;
-                       uint rows;
+                       TERM_LEN cols;
+                       TERM_LEN rows;
                        
                        /* this message was sent before WM_NCCREATE */
                        if (!td) return 1;
@@ -4873,7 +5085,7 @@ LRESULT FAR PASCAL AngbandListProc(HWND hWnd, UINT uMsg,
 
                                /* HACK - Redraw all windows */
                                p_ptr->window = 0xFFFFFFFF;
-                               window_stuff();
+                               handle_stuff();
                        }
 
                        td->size_hack = FALSE;
@@ -4973,7 +5185,6 @@ LRESULT FAR PASCAL AngbandSaverProc(HWND hWnd, UINT uMsg,
        /* Process */
        switch (uMsg)
        {
-               /* XXX XXX XXX */
                case WM_NCCREATE:
                {
                        break;
@@ -5035,7 +5246,6 @@ LRESULT FAR PASCAL AngbandSaverProc(HWND hWnd, UINT uMsg,
                }
        }
 
-       /* Oops */
        return DefWindowProc(hWnd, uMsg, wParam, lParam);
 }
 
@@ -5051,13 +5261,13 @@ LRESULT FAR PASCAL AngbandSaverProc(HWND hWnd, UINT uMsg,
 /*
  * Display warning message (see "z-util.c")
  */
-static void hack_plog(cptr str)
+static void hack_plog(concptr str)
 {
        /* Give a warning */
        if (str)
        {
 #ifdef JP
-               MessageBox(NULL, str, "·Ù¹ð¡ª",
+               MessageBox(NULL, str, "警告!",
                           MB_ICONEXCLAMATION | MB_OK);
 #else
                MessageBox(NULL, str, "Warning",
@@ -5071,13 +5281,13 @@ static void hack_plog(cptr str)
 /*
  * Display error message and quit (see "z-util.c")
  */
-static void hack_quit(cptr str)
+static void hack_quit(concptr str)
 {
        /* Give a warning */
        if (str)
        {
 #ifdef JP
-               MessageBox(NULL, str, "¥¨¥é¡¼¡ª",
+               MessageBox(NULL, str, "エラー!",
                           MB_ICONEXCLAMATION | MB_OK | MB_ICONSTOP);
 #else
                MessageBox(NULL, str, "Error",
@@ -5104,13 +5314,13 @@ static void hack_quit(cptr str)
 /*
  * Display warning message (see "z-util.c")
  */
-static void hook_plog(cptr str)
+static void hook_plog(concptr str)
 {
        /* Warning */
        if (str)
        {
 #ifdef JP
-               MessageBox(data[0].w, str, "·Ù¹ð¡ª",
+               MessageBox(data[0].w, str, "警告!",
                           MB_ICONEXCLAMATION | MB_OK);
 #else
                MessageBox(data[0].w, str, "Warning",
@@ -5124,7 +5334,7 @@ static void hook_plog(cptr str)
 /*
  * Display error message and quit (see "z-util.c")
  */
-static void hook_quit(cptr str)
+static void hook_quit(concptr str)
 {
        int i;
 
@@ -5133,7 +5343,7 @@ static void hook_quit(cptr str)
        if (str)
        {
 #ifdef JP
-               MessageBox(data[0].w, str, "¥¨¥é¡¼¡ª",
+               MessageBox(data[0].w, str, "エラー!",
                           MB_ICONEXCLAMATION | MB_OK | MB_ICONSTOP);
 #else
                MessageBox(data[0].w, str, "Error",
@@ -5147,7 +5357,7 @@ static void hook_quit(cptr str)
        save_prefs();
 
 
-       /*** Could use 'Term_nuke_win()' XXX XXX XXX */
+       /*** Could use 'Term_nuke_win()' */
 
        /* Destroy all windows */
        for (i = MAX_TERM_DATA - 1; i >= 0; --i)
@@ -5202,7 +5412,7 @@ static void init_stuff(void)
        /* Get program name with full path */
        GetModuleFileName(hInstance, path, 512);
 
-       /* Save the "program name" XXX XXX XXX */
+       /* Save the "program name" */
        argv0 = path;
 
        /* Get the name of the "*.ini" file */
@@ -5258,12 +5468,7 @@ static void init_stuff(void)
        validate_dir(ANGBAND_DIR_XTRA, TRUE);
 
        /* Build the filename */
-#ifdef JP
-       path_build(path, sizeof(path), ANGBAND_DIR_FILE, "news_j.txt");
-#else
-       path_build(path, sizeof(path), ANGBAND_DIR_FILE, "news.txt");
-#endif
-
+       path_build(path, sizeof(path), ANGBAND_DIR_FILE, _("news_j.txt", "news.txt"));
 
        /* Hack -- Validate the "news.txt" file */
        validate_file(path);
@@ -5337,7 +5542,26 @@ static void init_stuff(void)
        /* validate_dir(ANGBAND_DIR_XTRA_HELP); */
 }
 
+/*!
+ * @brief (Windows固有)変愚蛮怒が起動済かどうかのチェック
+ */
+static bool is_already_running(void)
+{
+       bool result = FALSE;
+       HANDLE hMutex;
+
+       hMutex = CreateMutex(NULL, TRUE, VERSION_NAME);
+       if (GetLastError() == ERROR_ALREADY_EXISTS)
+       {
+               result = TRUE;
+       }
+       return result;
+}
+
 
+/*!
+ * @brief (Windows固有)Windowsアプリケーションとしてのエントリポイント
+ */
 int FAR PASCAL WinMain(HINSTANCE hInst, HINSTANCE hPrevInst,
                       LPSTR lpCmdLine, int nCmdShow)
 {
@@ -5347,13 +5571,25 @@ int FAR PASCAL WinMain(HINSTANCE hInst, HINSTANCE hPrevInst,
        HDC hdc;
        MSG msg;
 
+       setlocale(LC_ALL, "ja_JP.utf8");
+
        /* Unused */
        (void)nCmdShow;
 
        /* Save globally */
        hInstance = hInst;
+       
+       
+       /* Prevent multiple run */
+       if (is_already_running())
+       {
+               MessageBox(NULL,
+                               _("変愚蛮怒はすでに起動しています。", "Hengband is already running."), 
+                               _("エラー!", "Error") ,
+                               MB_ICONEXCLAMATION | MB_OK | MB_ICONSTOP);
+               return FALSE;
+       }
 
-       /* Initialize */
        if (hPrevInst == NULL)
        {
                wc.style         = CS_CLASSDC;
@@ -5468,7 +5704,7 @@ int FAR PASCAL WinMain(HINSTANCE hInst, HINSTANCE hPrevInst,
        /* Catch nasty signals */
        signals_init();
 
-       /* Initialize */
+       Term_activate(term_screen);
        init_angband();
 
        /* We are now initialized */
@@ -5523,11 +5759,7 @@ int FAR PASCAL WinMain(HINSTANCE hInst, HINSTANCE hPrevInst,
 #endif
 
        /* Prompt the user */
-#ifdef JP
-       prt("[¥Õ¥¡¥¤¥ë] ¥á¥Ë¥å¡¼¤Î [¿·µ¬] ¤Þ¤¿¤Ï [³«¤¯] ¤òÁªÂò¤·¤Æ¤¯¤À¤µ¤¤¡£", 23, 8);
-#else
-       prt("[Choose 'New' or 'Open' from the 'File' menu]", 23, 17);
-#endif
+       prt(_("[ファイル] メニューの [新規] または [開く] を選択してください。", "[Choose 'New' or 'Open' from the 'File' menu]"), 23, _(8, 17));
 
        Term_fresh();
 
@@ -5537,11 +5769,7 @@ int FAR PASCAL WinMain(HINSTANCE hInst, HINSTANCE hPrevInst,
                TranslateMessage(&msg);
                DispatchMessage(&msg);
        }
-
-       /* Paranoia */
        quit(NULL);
-
-       /* Paranoia */
        return (0);
 }