3 /* Purpose: Simple support for MACINTOSH Angband */
6 * This file should only be compiled with the "Macintosh" version
8 * This file written by "Ben Harrison (benh@phial.com)".
10 * Some code adapted from "MacAngband 2.6.1" by Keith Randall
12 * Maarten Hazewinkel (mmhazewi@cs.ruu.nl) provided some initial
13 * suggestions for the PowerMac port.
15 * Steve Linberg (slinberg@crocker.com) provided the code surrounded
18 * The graphics code is adapted from an extremely minimal subset of
19 * the code from "Sprite World II", an amazing animation package.
21 * See "z-term.c" for info on the concept of the "generic terminal"
23 * The preference file is now a text file named "Angband preferences".
25 * Note that the "preference" file is now a simple text file called
26 * "Angband preferences", which contains the versions information, so
27 * that obsolete preference files can be ignored (this may be bad).
29 * Note that "init1.c", "init2.c", "load1.c", "load2.c", and "birth.c"
30 * should probably be "unloaded" as soon as they are no longer needed,
31 * to save space, but I do not know how to do this.
33 * Stange bug -- The first "ClipRect()" call crashes if the user closes
34 * all the windows, switches to another application, switches back, and
35 * then re-opens the main window, for example, using "command-a".
37 * By default, this file assumes that you will be using a 68020 or better
38 * machine, running System 7 and Color Quickdraw. In fact, the game will
39 * refuse to run unless these features are available. This allows the use
40 * of a variety of interesting features such as graphics and sound.
42 * To create a version which can be used on 68000 machines, or on machines
43 * which are not running System 7 or Color Quickdraw, simply activate the
44 * "ANGBAND_LITE_MAC" compilation flag in the proper header file. This
45 * will disable all "modern" features used in this file, including support
46 * for multiple sub-windows, color, graphics, and sound.
48 * When compiling with the "ANGBAND_LITE_MAC" flag, the "ANGBAND_LITE"
49 * flag will be automatically defined, which will disable many of the
50 * advanced features of the game itself, reducing the total memory usage.
52 * If you are never going to use "graphics" (especially if you are not
53 * compiling support for graphics anyway) then you can delete the "pict"
54 * resource with id "1001" with no dangerous side effects.
59 * Important Resources in the resource file:
61 * FREF 130 = 'A271' / 'APPL' (application)
62 * FREF 129 = 'A271' / 'SAVE' (save file)
63 * FREF 130 = 'A271' / 'TEXT' (bone file, generic text file)
64 * FREF 131 = 'A271' / 'DATA' (binary image file, score file)
66 * DLOG 128 = "About Angband..."
68 * ALRT 128 = unused (?)
69 * ALRT 129 = "Warning..."
70 * ALRT 130 = "Are you sure you want to quit without saving?"
72 * DITL 128 = body for DLOG 128
73 * DITL 129 = body for ALRT 129
74 * DITL 130 = body for ALRT 130
76 * ICON 128 = "warning" icon
78 * MENU 128 = apple (about, -, ...)
79 * MENU 129 = File (new, open, close, save, -, exit, quit)
80 * MENU 130 = Edit (undo, -, cut, copy, paste, clear)
82 * PICT 1001 = Graphics tile set
88 * all 'APEX' files have a filename of the form "*:apex:*" (?)
89 * all 'BONE' files have a filename of the form "*:bone:*" (?)
90 * all 'DATA' files have a filename of the form "*:data:*"
91 * all 'SAVE' files have a filename of the form "*:save:*"
92 * all 'USER' files have a filename of the form "*:user:*" (?)
94 * Perhaps we should attempt to set the "_ftype" flag inside this file,
95 * to avoid nasty file type information being spread all through the
96 * rest of the code. (?) This might require adding hooks into the
97 * "fd_open()" and "my_fopen()" functions in "util.c". XXX XXX XXX
102 * Reasons for each header file:
104 * angband.h = Angband header file
106 * Types.h = (included anyway)
107 * Gestalt.h = gestalt code
108 * QuickDraw.h = (included anyway)
109 * OSUtils.h = (included anyway)
110 * Files.h = file code
111 * Fonts.h = font code
112 * Menus.h = menu code
113 * Dialogs.h = dialog code
114 * Windows.h = (included anyway)
115 * Palettes.h = palette code
116 * StandardFile.h = file dialog box
117 * DiskInit.h = disk initialization
118 * ToolUtils.h = HiWord() / LoWord()
119 * Desk.h = OpenDeskAcc()
120 * Devices.h = OpenDeskAcc()
121 * Events.h = event code
122 * Resources.h = resource code
123 * Controls.h = button code
124 * SegLoad.h = ExitToShell(), AppFile, etc
125 * Memory.h = SetApplLimit(), NewPtr(), etc
126 * QDOffscreen.h = GWorld code
127 * Sound.h = Sound code
129 * For backwards compatibility:
130 * Use GestaltEqu.h instead of Gestalt.h
131 * Add Desk.h to include simply includes Menus.h, Devices.h, Events.h
139 #include <QuickDraw.h>
145 #include <Palettes.h>
146 #include <StandardFile.h>
147 #include <DiskInit.h>
148 #include <ToolUtils.h>
151 #include <Resources.h>
152 #include <Controls.h>
155 #include <QDOffscreen.h>
157 #if TARGET_API_MAC_CARBON
158 #include <Navigation.h>
159 #include <CFPreferences.h>
160 #include <CFNumber.h>
162 # include <CarbonStdCLib.h>
173 * Cleaning up a couple of things to make these easier to change --AR
176 #define PREF_FILE_NAME "Hengband Preferences"
178 #define PREF_FILE_NAME "Hengband-E Preferences"
182 * Use "malloc()" instead of "NewPtr()"
184 /* #define USE_MALLOC */
187 /* Default creator signature */
188 #ifndef ANGBAND_CREATOR
189 # define ANGBAND_CREATOR 'Heng'
193 #if defined(powerc) || defined(__powerc)
196 * Disable "LITE" version
198 # undef ANGBAND_LITE_MAC
203 #ifdef ANGBAND_LITE_MAC
206 * Maximum number of windows
208 # define MAX_TERM_DATA 1
210 #else /* ANGBAND_LITE_MAC */
213 * Maximum number of windows
215 # define MAX_TERM_DATA 8
218 * Activate some special code
220 # define USE_SFL_CODE
222 #endif /* ANGBAND_LITE_MAC */
229 * Include the necessary header files
231 #include <AppleEvents.h>
239 * Globals for MPW compilation
241 #if defined(MACH_O_CARBON) || defined(MAC_MPW)
243 #if !TARGET_API_MAC_CARBON
255 * The Angband Color Set (0 to 15):
256 * Black, White, Slate, Orange, Red, Blue, Green, Umber
257 * D-Gray, L-Gray, Violet, Yellow, L-Red, L-Blue, L-Green, L-Umber
259 * Colors 8 to 15 are basically "enhanced" versions of Colors 0 to 7.
261 * On the Macintosh, we use color quickdraw, and we use actual "RGB"
262 * values below to choose the 16 colors.
264 * If we are compiled for ancient machines, we bypass color and simply
265 * draw everything in white (letting "z-term.c" automatically convert
266 * "black" into "wipe" calls).
268 static RGBColor foo[16] =
270 {0x0000, 0x0000, 0x0000}, /* TERM_DARK */
271 {0xFFFF, 0xFFFF, 0xFFFF}, /* TERM_WHITE */
272 {0x8080, 0x8080, 0x8080}, /* TERM_SLATE */
273 {0xFFFF, 0x8080, 0x0000}, /* TERM_ORANGE */
274 {0xC0C0, 0x0000, 0x0000}, /* TERM_RED */
275 {0x0000, 0x8080, 0x4040}, /* TERM_GREEN */
276 {0x0000, 0x0000, 0xFFFF}, /* TERM_BLUE */
277 {0x8080, 0x4040, 0x0000}, /* TERM_UMBER */
278 {0x4040, 0x4040, 0x4040}, /* TERM_L_DARK */
279 {0xC0C0, 0xC0C0, 0xC0C0}, /* TERM_L_WHITE */
280 {0xFFFF, 0x0000, 0xFFFF}, /* TERM_VIOLET */
281 {0xFFFF, 0xFFFF, 0x0000}, /* TERM_YELLOW */
282 {0xFFFF, 0x0000, 0x0000}, /* TERM_L_RED */
283 {0x0000, 0xFFFF, 0x0000}, /* TERM_L_GREEN */
284 {0x0000, 0xFFFF, 0xFFFF}, /* TERM_L_BLUE */
285 {0xC0C0, 0x8080, 0x4040} /* TERM_L_UMBER */
294 typedef struct term_data term_data;
307 #ifdef ANGBAND_LITE_MAC
311 #else /* ANGBAND_LITE_MAC */
323 #endif /* ANGBAND_LITE_MAC */
366 * Forward declare -- see below
368 static bool CheckEvents(bool wait);
372 * Hack -- location of the main directory
374 static short app_vol;
379 * Delay handling of double-clicked savefiles
381 Boolean open_when_ready = FALSE;
384 * Delay handling of pre-emptive "quit" event
386 Boolean quit_when_ready = FALSE;
390 * Hack -- game in progress
392 static int game_in_progress = 0;
396 * Only do "SetPort()" when needed
398 static WindowPtr active = NULL;
403 * An array of term_data's
405 static term_data data[MAX_TERM_DATA];
410 * Note when "open"/"new" become valid
412 static bool initialized = FALSE;
415 * Version of Mac OS - for version specific bug workarounds (; ;)
417 static long mac_os_version;
421 * CodeWarrior uses Universal Procedure Pointers
423 static ModalFilterUPP ynfilterUPP;
430 AEEventHandlerUPP AEH_Start_UPP;
431 AEEventHandlerUPP AEH_Quit_UPP;
432 AEEventHandlerUPP AEH_Print_UPP;
433 AEEventHandlerUPP AEH_Open_UPP;
441 static int ext_sound = 0;
449 #define SND_CMD_ERROR 6
451 static int soundchoice[] = {
519 static short soundmode[8];
521 static int ext_graf = 0;
526 * Convert refnum+vrefnum+fname into a full file name
527 * Store this filename in 'buf' (make sure it is long enough)
528 * Note that 'fname' looks to be a "pascal" string
530 #if TARGET_API_MAC_CARBON
531 static void refnum_to_name(char *buf, long refnum, short vrefnum, char *fname)
547 for (j=1; j<=fname[0]; j++)
549 res[i-fname[0]+j] = fname[j];
558 pb.dirInfo.ioDrDirID=pb.dirInfo.ioDrParID;
559 err = FSMakeFSSpec( vref, dirID, "\p", &spec );
565 for (j=1; j<=spec.name[0]; j++)
567 res[i-spec.name[0]+j] = spec.name[j];
574 /* Extract the result */
575 for (j = 0, i++; res[i]; j++, i++) buf[j] = res[i];
579 static void refnum_to_name(char *buf, long refnum, short vrefnum, char *fname)
591 for (j=1; j<=fname[0]; j++)
593 res[i-fname[0]+j] = fname[j];
597 pb.ioCompletion=NULL;
599 pb.ioVRefNum=vrefnum;
605 pb.ioDrDirID=pb.ioDrParID;
606 err = PBGetCatInfo((CInfoPBPtr)&pb, FALSE);
608 for (j=1; j<=name[0]; j++)
610 res[i-name[0]+j] = name[j];
614 if (pb.ioDrDirID == fsRtDirID) break;
617 /* Extract the result */
618 for (j = 0, i++; res[i]; j++, i++) buf[j] = res[i];
623 #if TARGET_API_MAC_CARBON
624 pascal OSErr FSpLocationFromFullPath(short fullPathLength,
625 const void *fullPath,
633 /* Create a minimal alias from the full pathname */
634 nullString[0] = 0; /* null string to indicate no zone or server name */
635 result = NewAliasMinimalFromFullPath(fullPathLength, fullPath, nullString, nullString, &alias);
636 if ( result == noErr )
638 /* Let the Alias Manager resolve the alias. */
639 result = ResolveAlias(NULL, alias, spec, &wasChanged);
641 /* work around Alias Mgr sloppy volume matching bug */
642 if ( spec->vRefNum == 0 )
644 /* invalidate wrong FSSpec */
649 DisposeHandle((Handle)alias); /* Free up memory used */
658 * XXX XXX XXX Allow the system to ask us for a filename
660 static bool askfor_file(char *buf, int len)
668 /* Default file name */
669 sprintf((char*)dflt + 1, "%s's description", buf);
670 dflt[0] = strlen((char*)dflt + 1);
672 /* Ask for a file name */
673 topleft.h=(qd.screenBits.bounds.left+qd.screenBits.bounds.right)/2-344/2;
674 topleft.v=(2*qd.screenBits.bounds.top+qd.screenBits.bounds.bottom)/3-188/2;
675 SFPutFile(topleft, "\pSelect a filename:", dflt, NULL, &reply);
676 /* StandardPutFile("\pSelect a filename:", dflt, &reply); */
684 GetWDInfo(reply.vRefNum, &vrefnum, &drefnum, &junk);
686 /* Extract the name */
687 refnum_to_name(buf, drefnum, vrefnum, (char*)reply.fName);
699 static void local_to_global( Rect *r )
706 LocalToGlobal( &temp );
714 LocalToGlobal( &temp );
720 static void global_to_local( Rect *r )
727 GlobalToLocal( &temp );
735 GlobalToLocal( &temp );
745 * Convert pathname to an appropriate format, because MPW's
746 * CarbonStdCLib chose to use system's native path format,
747 * making our lives harder to create binaries that run on
748 * OS 8/9 and OS X :( -- pelpel
750 void convert_pathname(char* path)
754 /* Nothing has to be done for CarbonLib on Classic */
755 if (mac_os_version >= 0x1000)
757 /* Convert to POSIX style */
758 ConvertHFSPathToUnixPath(path, buf);
760 /* Copy the result back */
768 # ifdef CHECK_MODIFICATION_TIME
771 * Although there is no easy way to emulate fstat in the old interface,
772 * we still can do stat-like things, because Mac OS is an OS.
774 static int get_modification_time(cptr path, u32b *mod_time)
780 /* Paranoia - make sure the pathname fits in Str255 */
782 if (i > 255) return (-1);
784 /* Convert pathname to a Pascal string */
785 strncpy((char *)pathname + 1, path, 255);
788 /* Set up parameter block */
789 pb.hFileInfo.ioNamePtr = pathname;
790 pb.hFileInfo.ioFDirIndex = 0;
791 pb.hFileInfo.ioVRefNum = app_vol;
792 pb.hFileInfo.ioDirID = 0;
794 /* Get catalog information of the file */
795 if (PBGetCatInfoSync(&pb) != noErr) return (-1);
797 /* Set modification date and time */
798 *mod_time = pb.hFileInfo.ioFlMdDat;
806 * A (non-Mach-O) Mac OS version of check_modification_time, for those
807 * compilers without good enough POSIX-compatibility libraries XXX XXX
809 errr check_modification_date(int fd, cptr template_file)
812 u32b txt_stat, raw_stat;
817 /* Build the file name */
818 path_build(buf, sizeof(buf), ANGBAND_DIR_EDIT, template_file);
821 convert_pathname(buf);
823 /* Obtain modification time */
824 if (get_modification_time(buf, &txt_stat)) return (-1);
826 /* XXX Build filename of the corresponding *.raw file */
827 strnfmt(fname, sizeof(fname), "%s", template_file);
830 p = strrchr(fname, '.');
833 if (p == NULL) return (-1);
835 /* Substitute ".raw" for ".txt" */
838 /* Build the file name of the raw file */
839 path_build(buf, sizeof(buf), ANGBAND_DIR_DATA, fname);
842 convert_pathname(buf);
844 /* Obtain modification time */
845 if (get_modification_time(buf, &raw_stat)) return (-1);
847 /* Ensure the text file is not newer than the raw file */
848 if (txt_stat > raw_stat) return (-1);
850 /* Keep using the current .raw file */
854 # endif /* CHECK_MODIFICATION_TIME */
859 * Center a rectangle inside another rectangle
861 static void center_rect(Rect *r, Rect *s)
863 int centerx = (s->left + s->right)/2;
864 int centery = (2*s->top + s->bottom)/3;
865 int dx = centerx - (r->right - r->left)/2 - r->left;
866 int dy = centery - (r->bottom - r->top)/2 - r->top;
875 * Convert a pascal string in place
877 * This function may be defined elsewhere, but since it is so
878 * small, it is not worth finding the proper function name for
879 * all the different platforms.
881 static void ptocstr(StringPtr src)
885 /* Hack -- pointer */
886 char *s = (char*)(src);
888 /* Hack -- convert the string */
889 for (i = s[0]; i; i--, s++) s[0] = s[1];
891 /* Hack -- terminate the string */
896 #if defined(USE_SFL_CODE)
900 * The following three routines (pstrcat, pstrinsert, and PathNameFromDirID)
901 * were taken from the Think Reference section called "Getting a Full Pathname"
902 * (under the File Manager section). We need PathNameFromDirID to get the
903 * full pathname of the opened savefile, making no assumptions about where it
906 * I had to hack PathNameFromDirID a little for MetroWerks, but it's awfully
909 static void pstrcat(StringPtr dst, StringPtr src)
912 BlockMove(src + 1, dst + *dst + 1, *src);
914 /* adjust length byte */
919 * pstrinsert - insert string 'src' at beginning of string 'dst'
921 static void pstrinsert(StringPtr dst, StringPtr src)
923 /* make room for new string */
924 BlockMove(dst + 1, dst + *src + 1, *dst);
926 /* copy new string in */
927 BlockMove(src + 1, dst + 1, *src);
929 /* adjust length byte */
933 static void PathNameFromDirID(long dirID, short vRefNum, StringPtr fullPathName)
936 Str255 directoryName;
939 fullPathName[0] = '\0';
941 block.dirInfo.ioDrParID = dirID;
942 block.dirInfo.ioNamePtr = directoryName;
946 block.dirInfo.ioVRefNum = vRefNum;
947 block.dirInfo.ioFDirIndex = -1;
948 block.dirInfo.ioDrDirID = block.dirInfo.ioDrParID;
949 err = PBGetCatInfo(&block, FALSE);
950 pstrcat(directoryName, (StringPtr)"\p:");
951 pstrinsert(fullPathName, directoryName);
952 if (block.dirInfo.ioDrDirID == 2) break;
958 #if TARGET_API_MAC_CARBON
960 static OSErr ChooseFile( StringPtr filename, FSSpec selfld )
962 NavReplyRecord reply;
963 NavDialogOptions dialogOptions;
964 NavTypeListHandle navTypeList = NULL;
968 AECreateDesc( typeFSS, &selfld, sizeof(FSSpec), &deffld );
970 err = NavGetDefaultDialogOptions( &dialogOptions );
974 err = NavChooseFile( &deffld, &reply, &dialogOptions, NULL, NULL, NULL, navTypeList, NULL );
976 if ( reply.validRecord && err == noErr ){
977 // grab the target FSSpec from the AEDesc:
983 // retrieve the returned selection:
984 // there is only one selection here we get only the first AEDescList:
985 if (( err = AEGetNthPtr( &(reply.selection), 1, typeFSS, &keyWord, &typeCode, &finalFSSpec, sizeof( FSSpec ), &actualSize )) == noErr )
987 refnum_to_name( (char *)filename, finalFSSpec.parID, finalFSSpec.vRefNum, (char *)finalFSSpec.name );
988 // 'finalFSSpec' is the chosen file¥Î
991 err = NavDisposeReply( &reply );
993 if( navTypeList != NULL )
995 DisposeHandle( (Handle)navTypeList );
1000 AEDisposeDesc( &deffld );
1008 * Activate a given window, if necessary
1010 static void activate(WindowPtr w)
1016 #if TARGET_API_MAC_CARBON
1017 if (w) SetPortWindowPort(w);
1029 * Display a warning message
1031 static void mac_warning(cptr warning)
1036 /* Limit of 250 chars */
1037 len = strlen(warning);
1038 if (len > 250) len = 250;
1040 /* Make a "Pascal" string */
1042 for (i=0; i<len; i++) text[i+1] = warning[i];
1044 /* Prepare the dialog box values */
1045 ParamText(text, "\p", "\p", "\p");
1047 /* Display the Alert, wait for Okay */
1053 /*** Some generic functions ***/
1056 #ifdef ANGBAND_LITE_MAC
1059 * Hack -- activate a color (0 to 255)
1061 #define term_data_color(TD,A) /* Nothing */
1063 #else /* ANGBAND_LITE_MAC */
1066 * Hack -- activate a color (0 to 255)
1068 static void term_data_color(term_data *td, int a)
1074 /* Extract the R,G,B data */
1075 rv = angband_color_table[a][1];
1076 gv = angband_color_table[a][2];
1077 bv = angband_color_table[a][3];
1080 color.red = (rv | (rv << 8));
1081 color.green = (gv | (gv << 8));
1082 color.blue = (bv | (bv << 8));
1084 /* Activate the color */
1085 RGBForeColor(&color);
1087 /* Memorize color */
1091 #endif /* ANGBAND_LITE_MAC */
1095 * Hack -- Apply and Verify the "font" info
1097 * This should usually be followed by "term_data_check_size()"
1099 static void term_data_check_font(term_data *td)
1105 WindowPtr old = active;
1111 /* Instantiate font */
1112 TextFont(td->font_id);
1113 TextSize(td->font_size);
1114 TextFace(td->font_face);
1116 /* Extract the font info */
1119 /* Assume monospaced */
1120 td->font_mono = TRUE;
1122 /* Extract the font sizing values XXX XXX XXX */
1123 td->font_wid = CharWidth('@'); /* info.widMax; */
1124 td->font_hgt = info.ascent + info.descent;
1126 td->font_o_y = info.ascent;
1128 /* Check important characters */
1129 for (i = 33; i < 127; i++)
1131 /* Hack -- notice non-mono-space */
1132 if (td->font_wid != CharWidth(i)) td->font_mono = FALSE;
1134 /* Hack -- collect largest width */
1135 if (td->font_wid < CharWidth(i)) td->font_wid = CharWidth(i);
1138 /* Set default offsets */
1139 td->tile_o_x = td->font_o_x;
1140 td->tile_o_y = td->font_o_y;
1142 /* Set default tile size */
1143 if( td->tile_wid == 0 && td->tile_hgt == 0 ){
1144 td->tile_wid = td->font_wid;
1145 td->tile_hgt = td->font_hgt;
1148 /* Re-activate the old window */
1154 * Hack -- Apply and Verify the "size" info
1156 static void term_data_check_size(term_data *td)
1160 #if TARGET_API_MAC_CARBON
1161 GetQDGlobalsScreenBits( &screen );
1163 screen = qd.screenBits;
1165 /* Minimal window size */
1168 /* Enforce minimal size */
1169 if (td->cols < 80) td->cols = 80;
1170 if (td->rows < 24) td->rows = 24;
1173 /* Allow small windows for the rest */
1176 if (td->cols < 1) td->cols = 1;
1177 if (td->rows < 1) td->rows = 1;
1180 /* Minimal tile size */
1181 if (td->tile_wid < 4) td->tile_wid = 4;
1182 if (td->tile_hgt < 4) td->tile_hgt = 4;
1184 /* Default tile offsets */
1185 td->tile_o_x = (td->tile_wid - td->font_wid) / 2;
1186 td->tile_o_y = (td->tile_hgt - td->font_hgt) / 2;
1188 /* Minimal tile offsets */
1189 if (td->tile_o_x < 0) td->tile_o_x = 0;
1190 if (td->tile_o_y < 0) td->tile_o_y = 0;
1192 /* Apply font offsets */
1193 td->tile_o_x += td->font_o_x;
1194 td->tile_o_y += td->font_o_y;
1196 /* Calculate full window size */
1197 td->size_wid = td->cols * td->tile_wid + td->size_ow1 + td->size_ow2;
1198 td->size_hgt = td->rows * td->tile_hgt + td->size_oh1 + td->size_oh2;
1200 /* Verify the top */
1201 if (td->r.top > screen.bounds.bottom - td->size_hgt)
1203 td->r.top = screen.bounds.bottom - td->size_hgt;
1206 /* Verify the top */
1207 if (td->r.top < screen.bounds.top + 30)
1209 td->r.top = screen.bounds.top + 30;
1212 /* Verify the left */
1213 if (td->r.left > screen.bounds.right - td->size_wid)
1215 td->r.left = screen.bounds.right - td->size_wid;
1218 /* Verify the left */
1219 if (td->r.left < screen.bounds.left)
1221 td->r.left = screen.bounds.left;
1224 /* Calculate bottom right corner */
1225 td->r.right = td->r.left + td->size_wid;
1226 td->r.bottom = td->r.top + td->size_hgt;
1228 /* Assume no graphics */
1229 td->t->higher_pict = FALSE;
1230 td->t->always_pict = FALSE;
1232 #ifdef ANGBAND_LITE_MAC
1236 #else /* ANGBAND_LITE_MAC */
1238 /* Handle graphics */
1241 /* Use higher_pict whenever possible */
1242 if (td->font_mono) td->t->higher_pict = TRUE;
1244 /* Use always_pict only when necessary */
1245 else td->t->always_pict = TRUE;
1248 #endif /* ANGBAND_LITE_MAC */
1250 /* Fake mono-space */
1251 if (!td->font_mono ||
1252 (td->font_wid != td->tile_wid) ||
1253 (td->font_hgt != td->tile_hgt))
1255 /* Handle fake monospace -- this is SLOW */
1256 if (td->t->higher_pict) td->t->higher_pict = FALSE;
1257 td->t->always_pict = TRUE;
1262 * Hack -- resize a term_data
1264 * This should normally be followed by "term_data_resize()"
1266 static void term_data_resize(term_data *td)
1268 /* Actually resize the window */
1269 SizeWindow(td->w, td->size_wid, td->size_hgt, 0);
1275 * Hack -- redraw a term_data
1277 * Note that "Term_redraw()" calls "TERM_XTRA_CLEAR"
1279 static void term_data_redraw(term_data *td)
1283 /* Activate the term */
1284 Term_activate(td->t);
1286 /* Redraw the contents */
1289 /* Flush the output */
1292 /* Restore the old term */
1295 /* No need to redraw */
1296 #if TARGET_API_MAC_CARBON
1298 RgnHandle theRgn = NewRgn();
1299 GetWindowRegion( td->w, kWindowContentRgn, theRgn );
1300 ValidWindowRgn( (WindowRef)(td->w), theRgn );
1301 DisposeRgn( theRgn );
1304 ValidRect(&td->w->portRect);
1312 #ifdef ANGBAND_LITE_MAC
1316 #else /* ANGBAND_LITE_MAC */
1323 static int pictID = 1001; /* 8x8 tiles; 16x16 tiles are 1002 */
1325 static int grafWidth = 8; /* Always equal to grafHeight */
1326 static int grafHeight = 8; /* Either 8 or 16 */
1328 static bool arg_newstyle_graphics;
1329 static bool use_newstyle_graphics;
1334 typedef struct FrameRec FrameRec;
1339 * - GWorld for the frame image
1340 * - Handle to pix map (saved for unlocking/locking)
1341 * - Pointer to color pix map (valid only while locked)
1345 GWorldPtr framePort;
1346 PixMapHandle framePixHndl;
1353 * The global picture data
1355 static FrameRec *frameP = NULL;
1361 static void BenSWLockFrame(FrameRec *srcFrameP)
1363 PixMapHandle pixMapH;
1365 pixMapH = GetGWorldPixMap(srcFrameP->framePort);
1366 (void)LockPixels(pixMapH);
1367 HLockHi((Handle)pixMapH);
1368 srcFrameP->framePixHndl = pixMapH;
1369 #if TARGET_API_MAC_CARBON
1370 srcFrameP->framePix = (PixMapPtr)*(Handle)pixMapH;
1372 srcFrameP->framePix = (PixMapPtr)StripAddress(*(Handle)pixMapH);
1381 static void BenSWUnlockFrame(FrameRec *srcFrameP)
1383 if (srcFrameP->framePort != NULL)
1385 HUnlock((Handle)srcFrameP->framePixHndl);
1386 UnlockPixels(srcFrameP->framePixHndl);
1389 srcFrameP->framePix = NULL;
1393 static OSErr BenSWCreateGWorldFromPict(
1394 GWorldPtr *pictGWorld,
1398 GWorldPtr saveGWorld;
1399 GDHandle saveGDevice;
1400 GWorldPtr tempGWorld;
1409 depth = data[0].pixelDepth;
1412 theGDH = data[0].theGDH;
1414 /* Obtain size rectangle */
1415 pictRect = (**pictH).picFrame;
1416 OffsetRect(&pictRect, -pictRect.left, -pictRect.top);
1418 /* Create a GWorld */
1419 err = NewGWorld(&tempGWorld, depth, &pictRect, nil,
1420 theGDH, noNewDevice);
1429 *pictGWorld = tempGWorld;
1432 GetGWorld(&saveGWorld, &saveGDevice);
1435 SetGWorld(tempGWorld, nil);
1437 /* Dump the pict into the GWorld */
1438 (void)LockPixels(GetGWorldPixMap(tempGWorld));
1439 EraseRect(&pictRect);
1440 DrawPicture(pictH, &pictRect);
1441 UnlockPixels(GetGWorldPixMap(tempGWorld));
1443 /* Restore GWorld */
1444 SetGWorld(saveGWorld, saveGDevice);
1454 * Init the global "frameP"
1457 static errr globe_init(void)
1461 GWorldPtr tempPictGWorldP;
1465 /* Use window XXX XXX XXX */
1466 #if TARGET_API_MAC_CARBON
1467 SetPortWindowPort(data[0].w);
1473 /* Get the pict resource */
1474 newPictH = GetPicture(pictID);
1476 /* Analyze result */
1477 err = (newPictH ? 0 : -1);
1484 err = BenSWCreateGWorldFromPict(&tempPictGWorldP, newPictH);
1486 /* Release resource */
1487 ReleaseResource((Handle)newPictH);
1492 /* Create the frame */
1493 frameP = (FrameRec*)NewPtrClear((Size)sizeof(FrameRec));
1495 /* Analyze result */
1496 err = (frameP ? 0 : -1);
1502 frameP->framePort = tempPictGWorldP;
1505 BenSWLockFrame(frameP);
1516 * Nuke the global "frameP"
1518 static errr globe_nuke(void)
1524 BenSWUnlockFrame(frameP);
1526 /* Dispose of the GWorld */
1527 DisposeGWorld(frameP->framePort);
1529 /* Dispose of the memory */
1530 DisposePtr((Ptr)frameP);
1537 FlushEvents(everyEvent, 0);
1544 #endif /* ANGBAND_LITE_MAC */
1548 /*** Support for the "z-term.c" package ***/
1552 * Initialize a new Term
1554 * Note also the "window type" called "noGrowDocProc", which might be more
1555 * appropriate for the main "screen" window.
1557 * Note the use of "srcCopy" mode for optimized screen writes.
1559 static void Term_init_mac(term *t)
1561 term_data *td = (term_data*)(t->data);
1563 static RGBColor black = {0x0000,0x0000,0x0000};
1564 static RGBColor white = {0xFFFF,0xFFFF,0xFFFF};
1566 #ifdef ANGBAND_LITE_MAC
1568 /* Make the window */
1569 td->w = NewWindow(0, &td->r, td->title, 0, noGrowDocProc, (WindowPtr)-1, 1, 0L);
1571 #else /* ANGBAND_LITE_MAC */
1573 /* Make the window */
1574 td->w = NewCWindow(0, &td->r, td->title, 0, documentProc, (WindowPtr)-1, 1, 0L);
1576 #endif /* ANGBAND_LITE_MAC */
1578 /* Activate the window */
1581 /* Erase behind words */
1584 /* Apply and Verify */
1585 term_data_check_font(td);
1586 term_data_check_size(td);
1588 /* Resize the window */
1589 term_data_resize(td);
1591 #ifdef ANGBAND_LITE_MAC
1593 /* Prepare the colors (base colors) */
1594 BackColor(blackColor);
1595 ForeColor(whiteColor);
1597 #else /* ANGBAND_LITE_MAC */
1599 /* Prepare the colors (real colors) */
1600 RGBBackColor(&black);
1601 RGBForeColor(&white);
1608 GDHandle currentGDH;
1609 GWorldPtr windowGWorld;
1610 PixMapHandle basePixMap;
1612 /* Obtain the rect */
1613 #if TARGET_API_MAC_CARBON
1614 GetWindowBounds( (WindowRef)td->w, kWindowContentRgn, &globalRect );
1616 globalRect = td->w->portRect;
1617 LocalToGlobal((Point*)&globalRect.top);
1618 LocalToGlobal((Point*)&globalRect.bottom);
1621 /* Obtain the proper GDH */
1622 mainGDH = GetMaxDevice(&globalRect);
1624 /* Extract GWorld and GDH */
1625 GetGWorld(&windowGWorld, ¤tGDH);
1627 /* Obtain base pixmap */
1628 basePixMap = (**mainGDH).gdPMap;
1630 /* Save pixel depth */
1631 td->pixelDepth = (**basePixMap).pixelSize;
1633 /* Save Window GWorld */
1634 td->theGWorld = windowGWorld;
1636 /* Save Window GDH */
1637 td->theGDH = currentGDH;
1640 td->mainSWGDH = mainGDH;
1643 #endif /* ANGBAND_LITE_MAC */
1648 #if TARGET_API_MAC_CARBON
1649 GetWindowBounds( (WindowRef)td->w, kWindowContentRgn, &portRect );
1650 global_to_local( &portRect );
1652 portRect = td->w->portRect;
1654 /* Clip to the window */
1655 ClipRect(&portRect);
1657 /* Erase the window */
1658 EraseRect(&portRect);
1660 /* Invalidate the window */
1661 #if TARGET_API_MAC_CARBON
1662 InvalWindowRect((WindowRef)(td->w), (const Rect *)(&portRect));
1664 InvalRect(&portRect);
1667 /* Display the window if needed */
1668 if (td->mapped) ShowWindow(td->w);
1670 /* Hack -- set "mapped" flag */
1671 t->mapped_flag = td->mapped;
1677 /* if (err == noErr)
1688 static void Term_nuke_mac(term *t)
1701 static errr Term_user_mac(int n)
1715 static errr Term_xtra_mac_react(void)
1717 term_data *td = (term_data*)(Term->data);
1723 #ifdef ANGBAND_LITE_MAC
1727 #else /* ANGBAND_LITE_MAC */
1730 if (use_sound != arg_sound)
1733 use_sound = arg_sound;
1737 /* Handle transparency */
1738 if (use_newstyle_graphics != arg_newstyle_graphics)
1742 if (globe_init() != 0)
1744 plog("Cannot initialize graphics!");
1745 arg_graphics = FALSE;
1746 arg_newstyle_graphics = FALSE;
1750 use_newstyle_graphics = arg_newstyle_graphics;
1752 /* Apply and Verify */
1753 term_data_check_size(td);
1755 /* Resize the window */
1756 term_data_resize(td);
1762 /* Handle graphics */
1763 if (use_graphics != arg_graphics)
1765 /* Initialize graphics */
1767 if (!use_graphics && !frameP && (globe_init() != 0))
1770 plog("¥°¥é¥Õ¥£¥Ã¥¯¤Î½é´ü²½¤Ï½ÐÍè¤Þ¤»¤ó¤Ç¤·¤¿.");
1772 plog("Cannot initialize graphics!");
1774 arg_graphics = FALSE;
1778 use_graphics = arg_graphics;
1780 /* Apply and Verify */
1781 term_data_check_size(td);
1783 /* Resize the window */
1784 term_data_resize(td);
1790 #endif /* ANGBAND_LITE_MAC */
1798 * Do a "special thing"
1800 static errr Term_xtra_mac(int n, int v)
1802 term_data *td = (term_data*)(Term->data);
1810 case TERM_XTRA_NOISE:
1819 #ifdef ANGBAND_LITE_MAC
1823 #else /* ANGBAND_LITE_MAC */
1826 case TERM_XTRA_SOUND:
1836 /* Open the resource file */
1837 oldResFile = CurResFile();
1838 newResFile = OpenResFile(sound);
1840 /* Close the resource file */
1841 CloseResFile(newResFile);
1842 UseResFile(oldResFile);
1845 /* Get the proper sound name */
1846 sprintf((char*)sound + 1, "%.16s.wav", angband_sound_name[v]);
1847 sound[0] = strlen((char*)sound + 1);
1849 /* Obtain resource XXX XXX XXX */
1850 handle = Get1NamedResource('snd ', sound);
1851 if( handle == NULL || ext_sound )
1852 handle = GetNamedResource('snd ', sound);
1855 if (handle && soundmode[soundchoice[v]] == true)
1858 LoadResource(handle);
1861 /* Play sound (wait for completion) */
1862 SndPlay(nil, (SndListHandle)handle, true);
1864 /* Unlock and release */
1866 ReleaseResource(handle);
1872 #endif /* ANGBAND_LITE_MAC */
1874 /* Process random events */
1875 case TERM_XTRA_BORED:
1877 /* Process an event */
1878 (void)CheckEvents(FALSE);
1884 /* Process pending events */
1885 case TERM_XTRA_EVENT:
1887 /* Process an event */
1888 (void)CheckEvents(v);
1894 /* Flush all pending events (if any) */
1895 case TERM_XTRA_FLUSH:
1897 /* Hack -- flush all events */
1898 while (CheckEvents(TRUE)) /* loop */;
1904 /* Hack -- Change the "soft level" */
1905 case TERM_XTRA_LEVEL:
1907 /* Activate if requested */
1908 if (v) activate(td->w);
1914 /* Clear the screen */
1915 case TERM_XTRA_CLEAR:
1919 #if TARGET_API_MAC_CARBON
1920 GetWindowBounds( (WindowRef)td->w, kWindowContentRgn, &portRect );
1921 global_to_local( &portRect );
1923 portRect = td->w->portRect;
1926 /* No clipping XXX XXX XXX */
1927 ClipRect(&portRect);
1929 /* Erase the window */
1930 EraseRect(&portRect);
1933 term_data_color(td, TERM_WHITE);
1935 /* Frame the window in white */
1937 LineTo(0, td->size_hgt-1);
1938 LineTo(td->size_wid-1, td->size_hgt-1);
1939 LineTo(td->size_wid-1, 0);
1941 /* Clip to the new size */
1942 r.left = portRect.left + td->size_ow1;
1943 r.top = portRect.top + td->size_oh1;
1944 r.right = portRect.right - td->size_ow2;
1945 r.bottom = portRect.bottom - td->size_oh2;
1952 /* React to changes */
1953 case TERM_XTRA_REACT:
1955 /* React to changes */
1956 return (Term_xtra_mac_react());
1959 /* Delay (milliseconds) */
1960 case TERM_XTRA_DELAY:
1965 #if TARGET_API_MAC_CARBON
1969 /* Convert millisecs to ticks */
1970 ticks = (v * 60L) / 1000;
1973 * Hack? - Put the programme into sleep.
1974 * No events match ~everyEvent, so nothing
1975 * should be lost in Angband's event queue.
1976 * Even if ticks are 0, it's worth calling for
1977 * the above mentioned reasons.
1979 WaitNextEvent(~everyEvent, &tmp, ticks, nil);
1981 long m = TickCount() + (v * 60L) / 1000;
1984 while (TickCount() < m) /* loop */;
2000 * Low level graphics (Assumes valid input).
2001 * Draw a "cursor" at (x,y), using a "yellow box".
2002 * We are allowed to use "Term_grab()" to determine
2003 * the current screen contents (for inverting, etc).
2005 static errr Term_curs_mac(int x, int y)
2009 term_data *td = (term_data*)(Term->data);
2012 term_data_color(td, TERM_YELLOW);
2014 /* Frame the grid */
2015 r.left = x * td->tile_wid + td->size_ow1;
2016 r.right = r.left + td->tile_wid;
2017 r.top = y * td->tile_hgt + td->size_oh1;
2018 r.bottom = r.top + td->tile_hgt;
2028 * Low level graphics (Assumes valid input).
2029 * Draw a "big cursor" at (x,y), using a "yellow box".
2030 * We are allowed to use "Term_grab()" to determine
2031 * the current screen contents (for inverting, etc).
2033 static errr Term_bigcurs_mac(int x, int y)
2037 term_data *td = (term_data*)(Term->data);
2040 term_data_color(td, TERM_YELLOW);
2042 /* Frame the grid */
2043 r.left = x * td->tile_wid + td->size_ow1;
2044 r.right = r.left + 2 * td->tile_wid;
2045 r.top = y * td->tile_hgt + td->size_oh1;
2046 r.bottom = r.top + td->tile_hgt;
2056 * Low level graphics (Assumes valid input)
2058 * Erase "n" characters starting at (x,y)
2060 static errr Term_wipe_mac(int x, int y, int n)
2064 term_data *td = (term_data*)(Term->data);
2066 /* Erase the block of characters */
2067 r.left = x * td->tile_wid + td->size_ow1;
2068 r.right = r.left + n * td->tile_wid;
2069 r.top = y * td->tile_hgt + td->size_oh1;
2070 r.bottom = r.top + td->tile_hgt;
2079 * Low level graphics. Assumes valid input.
2081 * Draw several ("n") chars, with an attr, at a given location.
2083 static errr Term_text_mac(int x, int y, int n, byte a, const char *cp)
2087 term_data *td = (term_data*)(Term->data);
2090 term_data_color(td, (a & 0x0F));
2092 /* Starting pixel */
2093 xp = x * td->tile_wid + td->tile_o_x + td->size_ow1;
2094 yp = y * td->tile_hgt + td->tile_o_y + td->size_oh1;
2096 /* Move to the correct location */
2099 /* Draw the character */
2100 if (n == 1) DrawChar(*cp);
2102 /* Draw the string */
2103 else DrawText(cp, 0, n);
2111 * Low level graphics (Assumes valid input)
2113 * Erase "n" characters starting at (x,y)
2115 static errr Term_pict_mac(int x, int y, int n, const byte *ap, const char *cp,
2116 const byte *tap, const char *tcp)
2120 term_data *td = (term_data*)(Term->data);
2121 GDHandle saveGDevice;
2122 GWorldPtr saveGWorld;
2124 PixMapHandle PortPix;
2127 GetGWorld(&saveGWorld, &saveGDevice);
2129 r2.left = x * td->tile_wid + td->size_ow1;
2130 r2.right = r2.left + td->tile_wid;
2131 r2.top = y * td->tile_hgt + td->size_oh1;
2132 r2.bottom = r2.top + td->tile_hgt;
2136 /* Instantiate font */
2137 TextFont(td->font_id);
2138 TextSize(td->font_size);
2139 TextFace(td->font_face);
2141 /* Restore colors */
2142 BackColor(blackColor);
2143 ForeColor(whiteColor);
2147 /* Destination rectangle */
2148 /* r2.left = x * td->tile_wid + td->size_ow1;
2149 r2.top = y * td->tile_hgt + td->size_oh1;
2150 r2.bottom = r2.top + td->tile_hgt;*/
2154 /* Scan the input */
2155 for (i = 0; i < n; i++)
2162 /* Second byte of bigtile */
2163 if (use_bigtile && a == 255)
2166 r2.left += td->tile_wid;
2171 /* Prepare right of rectangle now */
2172 r2.right = r2.left + td->tile_wid;
2174 #ifdef ANGBAND_LITE_MAC
2178 #else /* ANGBAND_LITE_MAC */
2180 /* Graphics -- if Available and Needed */
2181 if (use_graphics && ((byte)a & 0x80) && ((byte)c & 0x80))
2183 #if TARGET_API_MAC_CARBON
2184 PixMapHandle srcBitMap = GetGWorldPixMap(frameP->framePort);
2185 PixMapHandle destBitMap;
2187 BitMapPtr srcBitMap = (BitMapPtr)(frameP->framePix);
2188 BitMapPtr destBitMap;
2195 bool terrain_flag = FALSE;
2199 if ((a != ta || c != tc) &&
2200 ((byte)ta & 0x80) && ((byte)tc & 0x80))
2203 row = ((byte)ta & 0x7F);
2204 col = ((byte)tc & 0x7F);
2206 /* Terrain Source rectangle */
2207 terrain_r.left = col * grafWidth;
2208 terrain_r.top = row * grafHeight;
2209 terrain_r.right = terrain_r.left + grafWidth;
2210 terrain_r.bottom = terrain_r.top + grafHeight;
2212 terrain_flag = TRUE;
2216 row = ((byte)a & 0x7F);
2217 col = ((byte)c & 0x7F);
2219 /* Source rectangle */
2220 r1.left = col * grafWidth;
2221 r1.top = row * grafHeight;
2222 r1.right = r1.left + grafWidth;
2223 r1.bottom = r1.top + grafHeight;
2225 /* Hardwire CopyBits */
2226 BackColor(whiteColor);
2227 ForeColor(blackColor);
2229 /* Draw the picture */
2230 #if TARGET_API_MAC_CARBON
2231 destBitMap = GetPortPixMap(GetWindowPort( td->w ));
2233 destBitMap = (BitMapPtr)&(td->w->portBits);
2235 if (use_bigtile) r2.right += td->tile_wid;
2240 * Source mode const = srcCopy:
2242 * determine how close the color of the source
2243 * pixel is to black, and assign this relative
2244 * amount of foreground color to the
2245 * destination pixel; determine how close the
2246 * color of the source pixel is to white, and
2247 * assign this relative amount of background
2248 * color to the destination pixel
2250 #if TARGET_API_MAC_CARBON
2251 CopyBits( (BitMap *) *srcBitMap, (BitMap *) *destBitMap, &terrain_r, &r2, srcCopy, NULL);
2253 CopyBits( srcBitMap, destBitMap, &terrain_r, &r2, srcCopy, NULL );
2256 * Draw transparent tile
2257 * BackColor is ignored and the destination is
2260 BackColor(blackColor);
2261 #if TARGET_API_MAC_CARBON
2262 CopyBits( (BitMap *) *srcBitMap, (BitMap *) *destBitMap, &r1, &r2, transparent, NULL);
2264 CopyBits( srcBitMap, destBitMap, &r1, &r2, transparent, NULL );
2269 #if TARGET_API_MAC_CARBON
2270 CopyBits( (BitMap *) *srcBitMap, (BitMap *) *destBitMap, &r1, &r2, srcCopy, NULL);
2272 CopyBits( srcBitMap, destBitMap, &r1, &r2, srcCopy, NULL );
2276 /* Restore colors */
2277 BackColor(blackColor);
2278 ForeColor(whiteColor);
2287 #endif /* ANGBAND_LITE_MAC */
2295 term_data_color(td, (a & 0x0F));
2297 /* Starting pixel */
2298 xp = r2.left + td->tile_o_x;
2299 yp = r2.top + td->tile_o_y;
2301 /* Move to the correct location */
2307 /* Double width rectangle */
2308 r2.right += td->tile_wid;
2313 /* Draw the character */
2318 r2.left += td->tile_wid;
2326 /* Draw the character */
2332 r2.left += td->tile_wid;
2341 * Create and initialize window number "i"
2343 static void term_data_link(int i)
2347 term_data *td = &data[i];
2352 /* Require mapped */
2353 if (!td->mapped) return;
2358 /* Initialize the term */
2359 term_init(td->t, td->cols, td->rows, td->keys);
2361 /* Use a "software" cursor */
2362 td->t->soft_cursor = TRUE;
2364 /* Erase with "white space" */
2365 td->t->attr_blank = TERM_WHITE;
2366 td->t->char_blank = ' ';
2368 /* Prepare the init/nuke hooks */
2369 td->t->init_hook = Term_init_mac;
2370 td->t->nuke_hook = Term_nuke_mac;
2372 /* Prepare the function hooks */
2373 td->t->user_hook = Term_user_mac;
2374 td->t->xtra_hook = Term_xtra_mac;
2375 td->t->wipe_hook = Term_wipe_mac;
2376 td->t->curs_hook = Term_curs_mac;
2377 td->t->bigcurs_hook = Term_bigcurs_mac;
2378 td->t->text_hook = Term_text_mac;
2379 td->t->pict_hook = Term_pict_mac;
2381 /* Link the local structure */
2382 td->t->data = (vptr)(td);
2385 Term_activate(td->t);
2387 /* Global pointer */
2388 angband_term[i] = td->t;
2398 * Set the "current working directory" (also known as the "default"
2399 * volume/directory) to the location of the current application.
2401 * Code by: Maarten Hazewinkel (mmhazewi@cs.ruu.nl)
2403 * This function does not appear to work correctly with System 6.
2405 static void SetupAppDir(void)
2409 char errString[100];
2411 /* Get the location of the Angband executable */
2412 fcbBlock.ioCompletion = NULL;
2413 fcbBlock.ioNamePtr = NULL;
2414 fcbBlock.ioVRefNum = 0;
2415 fcbBlock.ioRefNum = CurResFile();
2416 fcbBlock.ioFCBIndx = 0;
2417 err = PBGetFCBInfo(&fcbBlock, FALSE);
2421 sprintf(errString, "PBGetFCBInfo ¥¨¥é¡¼ #%d.\r ½ªÎ»¤·¤Þ¤¹.", err);
2423 sprintf(errString, "Fatal PBGetFCBInfo Error #%d.\r Exiting.", err);
2425 mac_warning(errString);
2429 /* Extract the Vol and Dir */
2430 app_vol = fcbBlock.ioFCBVRefNum;
2431 app_dir = fcbBlock.ioFCBParID;
2433 /* Set the current working directory to that location */
2434 err = HSetVol(NULL, app_vol, app_dir);
2438 sprintf(errString, "HSetVol ¥¨¥é¡¼ #%d.\r ½ªÎ»¤·¤Þ¤¹.", err);
2440 sprintf(errString, "Fatal HSetVol Error #%d.\r Exiting.", err);
2442 mac_warning(errString);
2449 #if TARGET_API_MAC_CARBON
2451 * Using Core Foundation's Preferences services -- pelpel
2453 * Requires OS 8.6 or greater with CarbonLib 1.1 or greater. Or OS X,
2456 * Without this, we can support older versions of OS 8 as well
2457 * (with CarbonLib 1.0.4).
2459 * Frequent allocation/deallocation of small chunks of data is
2460 * far from my liking, but since this is only called at the
2461 * beginning and the end of a session, I hope this hardly matters.
2466 * Store "value" as the value for preferences item name
2469 static void save_pref_short(const char *key, short value)
2472 CFNumberRef cf_value;
2474 /* allocate and initialise the key */
2475 cf_key = CFStringCreateWithCString(NULL, key, kTextEncodingUS_ASCII);
2477 /* allocate and initialise the value */
2478 cf_value = CFNumberCreate(NULL, kCFNumberShortType, &value);
2480 if ((cf_key != NULL) && (cf_value != NULL))
2482 /* Store the key-value pair in the applications preferences */
2483 CFPreferencesSetAppValue(
2486 kCFPreferencesCurrentApplication);
2490 * Free CF data - the reverse order is a vain attempt to
2491 * minimise memory fragmentation.
2493 if (cf_value) CFRelease(cf_value);
2494 if (cf_key) CFRelease(cf_key);
2499 * Load preference value for key, returns TRUE if it succeeds with
2500 * vptr updated appropriately, FALSE otherwise.
2502 static bool query_load_pref_short(const char *key, short *vptr)
2505 CFNumberRef cf_value;
2507 /* allocate and initialise the key */
2508 cf_key = CFStringCreateWithCString(NULL, key, kTextEncodingUS_ASCII);
2511 if (cf_key == NULL) return (FALSE);
2513 /* Retrieve value for the key */
2514 cf_value = CFPreferencesCopyAppValue(
2516 kCFPreferencesCurrentApplication);
2518 /* Value not found */
2519 if (cf_value == NULL)
2525 /* Convert the value to short */
2532 CFRelease(cf_value);
2541 * Update short data pointed by vptr only if preferences
2542 * value for key is located.
2544 static void load_pref_short(const char *key, short *vptr)
2548 if (query_load_pref_short(key, &tmp)) *vptr = tmp;
2554 * Save preferences to preferences file for current host+current user+
2555 * current application.
2557 static void cf_save_prefs()
2562 save_pref_short("version.major", FAKE_VERSION);
2563 save_pref_short("version.minor", FAKE_VER_MAJOR);
2564 save_pref_short("version.patch", FAKE_VER_MINOR);
2565 save_pref_short("version.extra", FAKE_VER_PATCH);
2568 save_pref_short("arg.arg_sound", arg_sound);
2569 save_pref_short("arg.arg_graphics", arg_graphics);
2570 save_pref_short("arg.arg_newstyle_graphics", arg_newstyle_graphics);
2571 save_pref_short("arg.arg_bigtile", arg_bigtile);
2574 for( i = 0 ; i < 7 ; i++ )
2575 save_pref_short(format("sound%d.on", i), soundmode[i]);
2578 for (i = 0; i < MAX_TERM_DATA; i++)
2580 term_data *td = &data[i];
2582 save_pref_short(format("term%d.mapped", i), td->mapped);
2584 save_pref_short(format("term%d.font_id", i), td->font_id);
2585 save_pref_short(format("term%d.font_size", i), td->font_size);
2586 save_pref_short(format("term%d.font_face", i), td->font_face);
2588 save_pref_short(format("term%d.tile_wid", i), td->tile_wid);
2589 save_pref_short(format("term%d.tile_hgt", i), td->tile_hgt);
2591 save_pref_short(format("term%d.cols", i), td->cols);
2592 save_pref_short(format("term%d.rows", i), td->rows);
2593 save_pref_short(format("term%d.left", i), td->r.left);
2594 save_pref_short(format("term%d.top", i), td->r.top);
2598 * Make sure preferences are persistent
2600 CFPreferencesAppSynchronize(
2601 kCFPreferencesCurrentApplication);
2606 * Load preferences from preferences file for current host+current user+
2607 * current application.
2609 static void cf_load_prefs()
2612 short pref_major, pref_minor, pref_patch, pref_extra;
2617 /* Assume nothing is wrong, yet */
2620 /* Load version information */
2621 ok &= query_load_pref_short("version.major", &pref_major);
2622 ok &= query_load_pref_short("version.minor", &pref_minor);
2623 ok &= query_load_pref_short("version.patch", &pref_patch);
2624 ok &= query_load_pref_short("version.extra", &pref_extra);
2626 /* Any of the above failed */
2629 /* This may be the first run */
2631 mac_warning("½é´üÀßÄê¥Õ¥¡¥¤¥ë¤¬¸«¤Ä¤«¤ê¤Þ¤»¤ó¡£");
2633 mac_warning("Preferences are not found.");
2636 /* Ignore the rest */
2643 if ((pref_major != PREF_VER_MAJOR) ||
2644 (pref_minor != PREF_VER_MINOR) ||
2645 (pref_patch != PREF_VER_PATCH) ||
2646 (pref_extra != PREF_VER_EXTRA))
2650 format("Ignoring %d.%d.%d.%d preferences.",
2651 pref_major, pref_minor, pref_patch, pref_extra));
2664 if (query_load_pref_short("arg.arg_sound", &pref_tmp))
2665 arg_sound = pref_tmp;
2668 if (query_load_pref_short("arg.arg_graphics", &pref_tmp))
2669 arg_graphics = pref_tmp;
2671 /*newstyle graphics*/
2672 if (query_load_pref_short("arg.arg_newstyle_graphics", &pref_tmp))
2674 use_newstyle_graphics = pref_tmp;
2677 if (use_newstyle_graphics == true)
2679 ANGBAND_GRAF = "new";
2680 arg_newstyle_graphics = true;
2681 grafWidth = grafHeight = 16;
2686 ANGBAND_GRAF = "old";
2687 arg_newstyle_graphics = false;
2688 grafWidth = grafHeight = 8;
2692 /* double-width tiles */
2693 if (query_load_pref_short("arg.arg_bigtile", &pref_tmp))
2695 use_bigtile = pref_tmp;
2701 for( i = 0 ; i < 7 ; i++ )
2703 query_load_pref_short(format("sound%d.on", i), &soundmode[i]);
2707 m = GetMenuHandle(134);
2709 /* Item "arg_sound" */
2710 CheckMenuItem(m, 1, arg_sound);
2712 /* Item "arg_graphics" */
2713 CheckMenuItem(m, 2, arg_graphics);
2715 /* Item "arg_newstyle_graphics"*/
2716 CheckMenuItem(m, 8, arg_newstyle_graphics);
2718 /* Item "arg_bigtile"*/
2719 CheckMenuItem(m, 9, arg_bigtile);
2722 for (i = 0; i < MAX_TERM_DATA; i++)
2724 term_data *td = &data[i];
2726 load_pref_short(format("term%d.mapped", i), &td->mapped);
2728 load_pref_short(format("term%d.font_id", i), &td->font_id);
2729 load_pref_short(format("term%d.font_size", i), &td->font_size);
2730 load_pref_short(format("term%d.font_face", i), &td->font_face);
2732 load_pref_short(format("term%d.tile_wid", i), &td->tile_wid);
2733 load_pref_short(format("term%d.tile_hgt", i), &td->tile_hgt);
2735 load_pref_short(format("term%d.cols", i), &td->cols);
2736 load_pref_short(format("term%d.rows", i), &td->rows);
2737 load_pref_short(format("term%d.left", i), &td->r.left);
2738 load_pref_short(format("term%d.top", i), &td->r.top);
2744 * Global "preference" file pointer
2749 * Read a "short" from the file
2751 static int getshort(void)
2755 if (0 == my_fgets(fff, buf, sizeof(buf))) x = atoi(buf);
2760 * Dump a "short" to the file
2762 static void putshort(int x)
2764 fprintf(fff, "%d\n", x);
2770 * Write the "preference" data to the current "file"
2772 static void save_prefs(void)
2779 /*** The current version ***/
2781 putshort(FAKE_VERSION);
2782 putshort(FAKE_VER_MAJOR);
2783 putshort(FAKE_VER_MINOR);
2784 putshort(FAKE_VER_PATCH);
2786 putshort(arg_sound);
2787 putshort(arg_graphics);
2788 putshort(arg_newstyle_graphics);
2789 putshort(arg_bigtile);
2792 for( i = 0 ; i < 7 ; i++ )
2793 putshort(soundmode[i]);
2796 for (i = 0; i < MAX_TERM_DATA; i++)
2801 putshort(td->mapped);
2803 putshort(td->font_id);
2804 putshort(td->font_size);
2805 putshort(td->font_face);
2807 putshort(td->tile_wid);
2808 putshort(td->tile_hgt);
2813 putshort(td->r.left);
2814 putshort(td->r.top);
2820 * Load the preferences from the current "file"
2822 * XXX XXX XXX Being able to undefine various windows is
2823 * slightly bizarre, and may cause problems.
2825 static void load_prefs(void)
2829 int old_version, old_major, old_minor, old_patch;
2834 /*** Version information ***/
2836 /* Preferences version */
2837 old_version = getshort();
2838 old_major = getshort();
2839 old_minor = getshort();
2840 old_patch = getshort();
2842 /* Hack -- Verify or ignore */
2843 if ((old_version != FAKE_VERSION) ||
2844 (old_major != FAKE_VER_MAJOR) ||
2845 (old_minor != FAKE_VER_MINOR) ||
2846 (old_patch != FAKE_VER_PATCH))
2850 mac_warning("¸Å¤¤½é´üÀßÄê¥Õ¥¡¥¤¥ë¤ò̵»ë¤·¤Þ¤¹.");
2852 mac_warning("Ignoring old preferences.");
2858 arg_sound = getshort();
2859 arg_graphics = getshort();
2860 arg_newstyle_graphics = getshort();
2861 use_newstyle_graphics = arg_newstyle_graphics;
2863 if (use_newstyle_graphics == true)
2865 ANGBAND_GRAF = "new";
2866 arg_newstyle_graphics = true;
2867 grafWidth = grafHeight = 16;
2872 ANGBAND_GRAF = "old";
2873 arg_newstyle_graphics = false;
2874 grafWidth = grafHeight = 8;
2878 arg_bigtile = getshort();
2879 use_bigtile = arg_bigtile;
2882 for( i = 0 ; i < 7 ; i++ )
2883 soundmode[i] = getshort();
2886 m = GetMenuHandle(134);
2888 /* Item "arg_sound" */
2889 CheckItem(m, 1, arg_sound);
2891 /* Item "arg_graphics" */
2892 CheckItem(m, 2, arg_graphics);
2894 /* Item "arg_newstyle_graphics"*/
2895 CheckItem(m, 8, arg_newstyle_graphics);
2897 /* Item "arg_bigtile"*/
2898 CheckItem(m, 9, arg_bigtile);
2901 for (i = 0; i < MAX_TERM_DATA; i++)
2906 td->mapped = getshort();
2908 td->font_id = getshort();
2909 td->font_size = getshort();
2910 td->font_face = getshort();
2912 td->tile_wid = getshort();
2913 td->tile_hgt = getshort();
2915 td->cols = getshort();
2916 td->rows = getshort();
2918 td->r.left = getshort();
2919 td->r.top = getshort();
2922 if (feof(fff)) break;
2925 #endif /* TARGET_API_MAC_CARBON */
2930 * Hack -- default data for a window
2932 static void term_data_hack(term_data *td)
2936 #if TARGET_API_MAC_CARBON
2938 /* Default to Osaka font (Japanese) */
2939 fid = FMGetFontFamilyFromName( "\pOsaka¡ÝÅùÉý" );
2941 /* Default to Monaco font */
2942 fid = FMGetFontFamilyFromName("\pmonaco");
2946 /* Default to ÅùÉýÌÀÄ« font (Japanese) */
2947 GetFNum( "\pÅùÉýÌÀÄ«", &fid);
2948 SetFScaleDisable( true );
2950 /* Default to Monaco font */
2951 GetFNum("\pmonaco", &fid);
2956 WIPE(td, term_data);
2961 /* Default borders */
2972 /* Default font size */
2975 /* Default font face */
2982 /* Default position */
2992 * Read the preference file, Create the windows.
2994 * We attempt to use "FindFolder()" to track down the preference file,
2995 * but if this fails, for any reason, we will try the "SysEnvirons()"
2996 * method, which may work better with System 6.
2998 static void init_windows(void)
3011 /*** Default values ***/
3013 /* Initialize (backwards) */
3014 for (i = MAX_TERM_DATA - 1; i >= 0; i--)
3027 s = angband_term_name[i];
3032 /* Maximal length */
3035 /* Copy the title */
3036 strncpy((char*)(td->title) + 1, s, n);
3038 /* Save the length */
3041 /* Tile the windows */
3042 td->r.left += (b * 30);
3043 td->r.top += (b * 30);
3050 /*** Load preferences ***/
3052 #if TARGET_API_MAC_CARBON
3055 /* Assume failure */
3058 /* Assume failure */
3071 /* Find the folder */
3072 err = FindFolder(kOnSystemDisk, kPreferencesFolderType, kCreateFolder,
3078 /* Extract a path name */
3079 PathNameFromDirID(dirID, vref, (StringPtr)foo);
3081 /* Convert the string */
3082 ptocstr((StringPtr)foo);
3084 /* Append the preference file name */
3085 strcat(foo, PREF_FILE_NAME);
3087 /* Open the preference file */
3088 fff = fopen(foo, "r");
3095 #endif /* USE_SFL_CODE */
3101 HGetVol(0, &savev, &saved);
3103 /* Go to the "system" folder */
3104 SysEnvirons(curSysEnvVers, &env);
3105 SetVol(0, env.sysVRefNum);
3108 fff = fopen(PREF_FILE_NAME, "r");
3111 HSetVol(0, savev, saved);
3114 /* Load preferences */
3117 /* Load a real preference file */
3120 /* Close the file */
3123 #endif /* TARGET_API_MAC_CARBON */
3126 /*** Instantiate ***/
3137 /* Link (backwards, for stacking order) */
3138 for (i = MAX_TERM_DATA - 1; i >= 0; i--)
3147 Term_activate(td->t);
3150 static void init_sound( void )
3154 SignedByte permission = fsRdPerm;
3160 /* Descend into "lib" folder */
3161 pb.dirInfo.ioCompletion = NULL;
3162 pb.dirInfo.ioNamePtr = "\plib";
3163 pb.dirInfo.ioVRefNum = app_vol;
3164 pb.dirInfo.ioDrDirID = app_dir;
3165 pb.dirInfo.ioFDirIndex = 0;
3167 /* Check for errors */
3168 err = PBGetCatInfo((CInfoPBPtr)&pb, FALSE);
3171 if ((err == noErr) && (pb.dirInfo.ioFlAttrib & 0x10))
3173 /* Descend into "lib/save" folder */
3174 pb.dirInfo.ioCompletion = NULL;
3175 pb.dirInfo.ioNamePtr = "\pxtra";
3176 pb.dirInfo.ioVRefNum = app_vol;
3177 pb.dirInfo.ioDrDirID = pb.dirInfo.ioDrDirID;
3178 pb.dirInfo.ioFDirIndex = 0;
3180 /* Check for errors */
3181 err = PBGetCatInfo((CInfoPBPtr)&pb, FALSE);
3184 if ((err == noErr) && (pb.dirInfo.ioFlAttrib & 0x10))
3186 /* Descend into "lib/save" folder */
3187 pb.dirInfo.ioCompletion = NULL;
3188 pb.dirInfo.ioNamePtr = "\psound";
3189 pb.dirInfo.ioVRefNum = app_vol;
3190 pb.dirInfo.ioDrDirID = pb.dirInfo.ioDrDirID;
3191 pb.dirInfo.ioFDirIndex = 0;
3193 /* Check for errors */
3194 err = PBGetCatInfo((CInfoPBPtr)&pb, FALSE);
3197 if ((err == noErr) && (pb.dirInfo.ioFlAttrib & 0x10))
3199 ret = HOpenResFile( app_vol , pb.dirInfo.ioDrDirID , "\psound.rsrc" , permission );
3203 for( i = 0 ; i < 7 ; i++ )
3204 soundmode[i] = false;
3206 for( i = 1 ; i < SOUND_MAX ; i++ ){
3207 /* Get the proper sound name */
3208 sprintf((char*)sound + 1, "%.16s.wav", angband_sound_name[i]);
3209 sound[0] = strlen((char*)sound + 1);
3211 /* Obtain resource XXX XXX XXX */
3212 handle = Get1NamedResource('snd ', sound);
3213 if( handle == NULL || ext_sound )
3214 handle = GetNamedResource('snd ', sound);
3217 soundmode[soundchoice[i]] = true;
3226 static void init_graf( void )
3230 SignedByte permission = fsRdPerm;
3236 /* Descend into "lib" folder */
3237 pb.dirInfo.ioCompletion = NULL;
3238 pb.dirInfo.ioNamePtr = "\plib";
3239 pb.dirInfo.ioVRefNum = app_vol;
3240 pb.dirInfo.ioDrDirID = app_dir;
3241 pb.dirInfo.ioFDirIndex = 0;
3243 /* Check for errors */
3244 err = PBGetCatInfo((CInfoPBPtr)&pb, FALSE);
3247 if ((err == noErr) && (pb.dirInfo.ioFlAttrib & 0x10))
3249 /* Descend into "lib/xtra" folder */
3250 pb.dirInfo.ioCompletion = NULL;
3251 pb.dirInfo.ioNamePtr = "\pxtra";
3252 pb.dirInfo.ioVRefNum = app_vol;
3253 pb.dirInfo.ioDrDirID = pb.dirInfo.ioDrDirID;
3254 pb.dirInfo.ioFDirIndex = 0;
3256 /* Check for errors */
3257 err = PBGetCatInfo((CInfoPBPtr)&pb, FALSE);
3260 if ((err == noErr) && (pb.dirInfo.ioFlAttrib & 0x10))
3262 /* Descend into "lib/xtra/graf" folder */
3263 pb.dirInfo.ioCompletion = NULL;
3264 pb.dirInfo.ioNamePtr = "\pgraf";
3265 pb.dirInfo.ioVRefNum = app_vol;
3266 pb.dirInfo.ioDrDirID = pb.dirInfo.ioDrDirID;
3267 pb.dirInfo.ioFDirIndex = 0;
3269 /* Check for errors */
3270 err = PBGetCatInfo((CInfoPBPtr)&pb, FALSE);
3273 if ((err == noErr) && (pb.dirInfo.ioFlAttrib & 0x10))
3275 ret = HOpenResFile( app_vol , pb.dirInfo.ioDrDirID , "\pgraf.rsrc" , permission );
3280 /* Obtain resource XXX XXX XXX */
3281 handle = Get1NamedResource('PICT', graf);
3282 if ( handle == NULL || ext_graf )
3283 handle = GetNamedResource('PICT', "\pgraf.rsrc");
3294 static void init_chuukei( void )
3300 path_build(path, sizeof(path), ANGBAND_DIR_XTRA, "chuukei.txt");
3302 fp = fopen(path, "r");
3307 if (fgets(tmp, 1024, fp)){
3309 int n = strlen(tmp);
3315 chuukei_server = TRUE;
3316 if(connect_chuukei_server(&tmp[2])<0){
3317 msg_print("connect fail");
3320 msg_print("connect");
3327 chuukei_client = TRUE;
3328 connect_chuukei_server(&tmp[2]);
3344 short InevrtCheck( DialogPtr targetDlg, short check )
3351 GetDialogItem( targetDlg, check, &itemType, &checkH, &box );
3352 result = (GetControlValue( (ControlHandle)checkH ) + 1 ) % 2;
3353 SetControlValue( (ControlHandle)checkH , result );
3361 short SetCheck( DialogPtr targetDlg, short check, long result )
3368 GetDialogItem( targetDlg, check, &itemType, &checkH, &box );
3369 SetControlValue( (ControlHandle)checkH , result );
3377 short GetCheck( DialogPtr targetDlg, short check )
3384 GetDialogItem( targetDlg, check, &itemType, &checkH, &box );
3385 result = GetControlValue( (ControlHandle)checkH );
3389 void SoundConfigDLog(void)
3396 dialog=GetNewDialog(131, 0, (WindowPtr)-1);
3397 SetDialogDefaultItem( dialog, ok );
3398 SetDialogCancelItem( dialog, cancel );
3399 for( i = 1 ; i < 7 ; i++ )
3400 SetCheck( dialog, i+2 , soundmode[i] );
3402 /* ShowWindow(dialog); */
3403 for( item_hit = 100 ; cancel < item_hit ; ){
3404 ModalDialog(0, &item_hit);
3408 for( i = 1 ; i < 7 ; i++ )
3409 soundmode[i] = GetCheck( dialog, i+2 );
3414 InevrtCheck( dialog, item_hit );
3417 DisposeDialog(dialog);
3425 #if TARGET_API_MAC_CARBON
3426 static void save_pref_file(void)
3431 static void save_pref_file(void)
3440 /* Assume failure */
3443 /* Assume failure */
3460 /* Find the folder */
3461 err = FindFolder(kOnSystemDisk, kPreferencesFolderType, kCreateFolder,
3467 /* Extract a path name */
3468 PathNameFromDirID(dirID, vref, (StringPtr)foo);
3470 /* Convert the string */
3471 ptocstr((StringPtr)foo);
3473 /* Append the preference file name */
3474 strcat(foo, PREF_FILE_NAME);
3476 /* Open the preference file */
3477 /* my_fopen set file type and file creator for MPW */
3478 fff = my_fopen(foo, "w");
3485 #endif /* USE_SFL_CODE */
3491 HGetVol(0, &savev, &saved);
3493 /* Go to "system" folder */
3494 SysEnvirons(curSysEnvVers, &env);
3495 SetVol(0, env.sysVRefNum);
3497 /* Open the preference file */
3498 /* my_fopen set file type and file creator for MPW */
3499 fff = fopen(PREF_FILE_NAME, "w");
3502 HSetVol(0, savev, saved);
3505 /* Save preferences */
3508 /* Write the preferences */
3520 * A simple "Yes/No" filter to parse "key press" events in dialog windows
3522 static pascal Boolean ynfilter(DialogPtr dialog, EventRecord *event, short *ip)
3524 /* Parse key press events */
3525 if (event->what == keyDown)
3530 /* Extract the pressed key */
3531 c = (event->message & charCodeMask);
3533 /* Accept "no" and <return> and <enter> */
3534 if ((c=='n') || (c=='N') || (c==13) || (c==3)) i = 1;
3537 else if ((c=='y') || (c=='Y')) i = 2;
3539 /* Handle "yes" or "no" */
3543 ControlHandle control;
3546 /* Get the button */
3547 GetDialogItem(dialog, i, &type, (Handle*)&control, &r);
3549 /* Blink button for 1/10 second */
3550 HiliteControl(control, 1);
3551 Term_xtra_mac(TERM_XTRA_DELAY, 100);
3552 HiliteControl(control, 0);
3565 #if TARGET_API_MAC_CARBON
3568 #ifdef MACH_O_CARBON
3570 /* Carbon File Manager utilities by pelpel */
3574 * Convert a pathname to a corresponding FSSpec.
3575 * Returns noErr on success.
3577 static OSErr path_to_spec(const char *path, FSSpec *spec)
3582 /* Convert pathname to FSRef ... */
3583 err = FSPathMakeRef(path, &ref, NULL);
3584 if (err != noErr) return (err);
3586 /* ... then FSRef to FSSpec */
3587 err = FSGetCatalogInfo(&ref, kFSCatInfoNone, NULL, NULL, spec, NULL);
3589 /* Inform caller of success or failure */
3596 * Convert a FSSpec to a corresponding pathname.
3597 * Returns noErr on success.
3599 static OSErr spec_to_path(const FSSpec *spec, char *buf, size_t size)
3604 /* Convert FSSpec to FSRef ... */
3605 err = FSpMakeFSRef(spec, &ref);
3606 if (err != noErr) return (err);
3608 /* ... then FSRef to pathname */
3609 err = FSRefMakePath(&ref, buf, size);
3611 /* Inform caller of success or failure */
3616 #endif /* MACH_O_CARBON */
3620 * Prepare savefile dialogue and set the variable
3621 * savefile accordingly. Returns true if it succeeds, false (or
3622 * aborts) otherwise. If all is false, only allow files whose type
3624 * Originally written by Peter Ammon
3626 static bool select_savefile(bool all)
3629 FSSpec theFolderSpec;
3630 FSSpec savedGameSpec;
3631 NavDialogOptions dialogOptions;
3632 NavReplyRecord reply;
3633 /* Used only when 'all' is true */
3634 NavTypeList types = {ANGBAND_CREATOR, 1, 1, {'SAVE'}};
3635 NavTypeListHandle myTypeList;
3636 AEDesc defaultLocation;
3638 #ifdef MACH_O_CARBON
3640 /* Find the save folder */
3641 err = path_to_spec(ANGBAND_DIR_SAVE, &theFolderSpec);
3645 /* Find :lib:save: folder */
3646 err = FSMakeFSSpec(app_vol, app_dir, "\p:lib:save:", &theFolderSpec);
3651 if (err != noErr) quit("Unable to find the folder :lib:save:");
3653 /* Get default Navigator dialog options */
3654 err = NavGetDefaultDialogOptions(&dialogOptions);
3656 /* Clear preview option */
3657 dialogOptions.dialogOptionFlags &= ~kNavAllowPreviews;
3659 /* Disable multiple file selection */
3660 dialogOptions.dialogOptionFlags &= ~kNavAllowMultipleFiles;
3662 /* Make descriptor for default location */
3663 err = AECreateDesc(typeFSS, &theFolderSpec, sizeof(FSSpec),
3667 if (err != noErr) quit("Unable to allocate descriptor");
3669 /* We are indifferent to signature and file types */
3672 myTypeList = (NavTypeListHandle)nil;
3675 /* Set up type handle */
3678 err = PtrToHand(&types, (Handle *)&myTypeList, sizeof(NavTypeList));
3681 if (err != noErr) quit("Error in PtrToHand. Try enlarging heap");
3685 /* Call NavGetFile() with the types list */
3686 err = NavChooseFile(&defaultLocation, &reply, &dialogOptions, NULL,
3687 NULL, NULL, myTypeList, NULL);
3689 /* Free type list */
3690 if (!all) DisposeHandle((Handle)myTypeList);
3698 /* Invalid response -- allow the user to cancel */
3699 else if (!reply.validRecord)
3701 /* Hack -- Fake error */
3705 /* Retrieve FSSpec from the reply */
3708 AEKeyword theKeyword;
3709 DescType actualType;
3712 /* Get a pointer to selected file */
3713 (void)AEGetNthPtr(&reply.selection, 1, typeFSS, &theKeyword,
3714 &actualType, &savedGameSpec, sizeof(FSSpec), &actualSize);
3716 /* Dispose NavReplyRecord, resources and descriptors */
3717 (void)NavDisposeReply(&reply);
3720 /* Dispose location info */
3721 AEDisposeDesc(&defaultLocation);
3724 if (err != noErr) return (FALSE);
3726 #ifdef MACH_O_CARBON
3728 /* Convert FSSpec to pathname and store it in variable savefile */
3729 (void)spec_to_path(&savedGameSpec, savefile, sizeof(savefile));
3733 /* Convert FSSpec to pathname and store it in variable savefile */
3736 savedGameSpec.parID,
3737 savedGameSpec.vRefNum,
3738 (char *)savedGameSpec.name);
3749 * Handle menu: "File" + "New"
3751 static void do_menu_file_new(void)
3756 /* Game is in progress */
3757 game_in_progress = 1;
3771 * Handle menu: "File" + "Open"
3773 #if TARGET_API_MAC_CARBON
3774 static void do_menu_file_open(bool all)
3776 /* Let the player to choose savefile */
3777 if (!select_savefile(all)) return;
3782 /* Game is in progress */
3783 game_in_progress = TRUE;
3795 static void do_menu_file_open(bool all)
3809 /* vrefnum = GetSFCurVol(); */
3810 vrefnum = -*((short*)0x214);
3812 /* drefnum = GetSFCurDir(); */
3813 drefnum = *((long*)0x398);
3815 /* Descend into "lib" folder */
3816 pb.ioCompletion = NULL;
3817 pb.ioNamePtr = "\plib";
3818 pb.ioVRefNum = vrefnum;
3819 pb.ioDrDirID = drefnum;
3822 /* Check for errors */
3823 err = PBGetCatInfo((CInfoPBPtr)&pb, FALSE);
3826 if ((err == noErr) && (pb.ioFlAttrib & 0x10))
3828 /* Descend into "lib/save" folder */
3829 pb.ioCompletion = NULL;
3830 pb.ioNamePtr = "\psave";
3831 pb.ioVRefNum = vrefnum;
3832 pb.ioDrDirID = pb.ioDrDirID;
3835 /* Check for errors */
3836 err = PBGetCatInfo((CInfoPBPtr)&pb, FALSE);
3839 if ((err == noErr) && (pb.ioFlAttrib & 0x10))
3841 /* SetSFCurDir(pb.ioDrDirID); */
3842 *((long*)0x398) = pb.ioDrDirID;
3846 /* Window location */
3847 topleft.h = (qd.screenBits.bounds.left+qd.screenBits.bounds.right)/2-344/2;
3848 topleft.v = (2*qd.screenBits.bounds.top+qd.screenBits.bounds.bottom)/3-188/2;
3850 /* Allow "all" files */
3854 SFGetFile(topleft, "\p", NULL, -1, types, NULL, &reply);
3857 /* Allow "save" files */
3864 SFGetFile(topleft, "\p", NULL, 1, types, NULL, &reply);
3868 if (!reply.good) return;
3870 /* Extract textual file name for save file */
3871 GetWDInfo(reply.vRefNum, &vrefnum, &drefnum, &junk);
3872 refnum_to_name(savefile, drefnum, vrefnum, (char*)reply.fName);
3877 /* Game is in progress */
3878 game_in_progress = 1;
3893 * Handle the "open_when_ready" flag
3895 static void handle_open_when_ready(void)
3897 /* Check the flag XXX XXX XXX make a function for this */
3898 if (open_when_ready && initialized && !game_in_progress)
3901 open_when_ready = FALSE;
3903 /* Game is in progress */
3904 game_in_progress = 1;
3923 * Initialize the menus
3925 * Verify menus 128, 129, 130
3926 * Create menus 131, 132, 133, 134
3928 * The standard menus are:
3930 * Apple (128) = { About, -, ... }
3931 * File (129) = { New,Open,Import,Close,Save,-,Exit,Quit }
3932 * Edit (130) = { Cut, Copy, Paste, Clear } (?)
3933 * Font (131) = { Bold, Extend, -, Monaco, ..., -, ... }
3934 * Size (132) = { ... }
3935 * Window (133) = { Angband, Mirror, Recall, Choice,
3936 * Term-4, Term-5, Term-6, Term-7 }
3937 * Special (134) = { arg_sound, arg_graphics, -,
3938 * arg_fiddle, arg_wizard }
3940 static void init_menubar(void)
3952 /* Get the "apple" menu */
3955 /* Insert the menu */
3958 /* Add the DA's to the "apple" menu */
3959 #if TARGET_API_MAC_CARBON
3961 AppendResMenu (m, 'DRVR');
3964 /* Get the "File" menu */
3965 #if TARGET_API_MAC_CARBON
3967 err = Gestalt( gestaltSystemVersion, &response );
3968 if ( (err == noErr) && (response >= 0x00000A00) )
3970 DeleteMenuItem( m, 7 );
3976 /* Insert the menu */
3980 /* Get the "Edit" menu */
3983 /* Insert the menu */
3987 /* Make the "Font" menu */
3989 m = NewMenu(131, "\p¥Õ¥©¥ó¥È");
3991 m = NewMenu(131, "\pFont");
3994 /* Insert the menu */
3998 AppendMenu(m, "\pBold");
4001 AppendMenu(m, "\pWide");
4003 /* Add a separator */
4004 AppendMenu(m, "\p-");
4007 r.left = r.right = r.top = r.bottom = 0;
4009 /* Make the fake window */
4010 tmpw = NewWindow(0, &r, "\p", false, documentProc, 0, 0, 0);
4012 /* Activate the "fake" window */
4013 #if TARGET_API_MAC_CARBON
4014 SetPortWindowPort(tmpw);
4025 /* Add the fonts to the menu */
4026 AppendResMenu(m, 'FONT');
4029 #if TARGET_API_MAC_CARBON
4030 n = CountMenuItems(m);
4036 for (i = n; i >= 4; i--)
4041 /* Acquire the font name */
4042 GetMenuItemText(m, i, tmpName);
4044 /* Acquire the font index */
4045 #if TARGET_API_MAC_CARBON
4046 fontNum = FMGetFontFamilyFromName( tmpName );
4048 GetFNum(tmpName, &fontNum);
4051 /* Apply the font index */
4054 /* Remove non-mono-spaced fonts */
4055 if ((CharWidth('i') != CharWidth('W')) || (CharWidth('W') == 0))
4057 /* Delete the menu item XXX XXX XXX */
4058 DeleteMenuItem (m, i);
4062 /* Destroy the old window */
4063 DisposeWindow(tmpw);
4065 /* Add a separator */
4066 AppendMenu(m, "\p-");
4068 /* Add the fonts to the menu */
4069 AppendResMenu (m, 'FONT');
4072 /* Make the "Size" menu */
4074 m = NewMenu(132, "\p¥µ¥¤¥º");
4076 m = NewMenu(132, "\pSize");
4079 /* Insert the menu */
4082 /* Add some sizes (stagger choices) */
4083 for (i = 8; i <= 32; i += ((i / 16) + 1))
4088 sprintf((char*)buf + 1, "%d", i);
4089 buf[0] = strlen((char*)buf + 1);
4096 /* Make the "Windows" menu */
4098 m = NewMenu(133, "\p¥¦¥¤¥ó¥É¥¦");
4100 m = NewMenu(133, "\pWindows");
4103 /* Insert the menu */
4106 /* Default choices */
4107 for (i = 0; i < MAX_TERM_DATA; i++)
4111 /* Describe the item */
4112 sprintf((char*)buf + 1, "%.15s", angband_term_name[i]);
4113 buf[0] = strlen((char*)buf + 1);
4118 /* Command-Key shortcuts */
4119 if (i < 8) SetItemCmd(m, i + 1, '0' + i);
4123 /* Make the "Special" menu */
4125 m = NewMenu(134, "\pÆÃÊÌ");
4127 m = NewMenu(134, "\pSpecial");
4130 /* Insert the menu */
4133 /* Append the choices */
4135 AppendMenu(m, "\p¥µ¥¦¥ó¥É»ÈÍÑ");
4136 AppendMenu(m, "\p¥°¥é¥Õ¥£¥Ã¥¯»ÈÍÑ");
4137 AppendMenu(m, "\p-");
4138 AppendMenu(m, "\parg_fiddle");
4139 AppendMenu(m, "\parg_wizard");
4140 AppendMenu(m, "\p-");
4141 AppendMenu(m, "\p¥µ¥¦¥ó¥ÉÀßÄê...");
4142 AppendMenu(m, "\p16X16¥°¥é¥Õ¥£¥Ã¥¯");
4143 AppendMenu(m, "\p£²ÇÜÉý¥¿¥¤¥ëɽ¼¨");
4145 AppendMenu(m, "\parg_sound");
4146 AppendMenu(m, "\parg_graphics");
4147 AppendMenu(m, "\p-");
4148 AppendMenu(m, "\parg_fiddle");
4149 AppendMenu(m, "\parg_wizard");
4150 AppendMenu(m, "\p-");
4151 AppendMenu(m, "\pSound config");
4152 AppendMenu(m, "\pAdam Bolt tile");
4153 AppendMenu(m, "\pBigtile Mode");
4156 /* Make the "TileWidth" menu */
4158 m = NewMenu(135, "\p¥¿¥¤¥ëÉý");
4160 m = NewMenu(135, "\pTileWidth");
4163 /* Insert the menu */
4166 /* Add some sizes */
4167 for (i = 4; i <= 32; i++)
4172 sprintf((char*)buf + 1, "%d", i);
4173 buf[0] = strlen((char*)buf + 1);
4180 /* Make the "TileHeight" menu */
4182 m = NewMenu(136, "\p¥¿¥¤¥ë¹â");
4184 m = NewMenu(136, "\pTileHeight");
4187 /* Insert the menu */
4190 /* Add some sizes */
4191 for (i = 4; i <= 32; i++)
4196 sprintf((char*)buf + 1, "%d", i);
4197 buf[0] = strlen((char*)buf + 1);
4204 /* Update the menu bar */
4212 static void setup_menus(void)
4222 term_data *td = NULL;
4225 /* Relevant "term_data" */
4226 for (i = 0; i < MAX_TERM_DATA; i++)
4229 if (!data[i].t) continue;
4231 /* Notice the matching window */
4232 if (data[i].w == FrontWindow()) td = &data[i];
4237 m = GetMenuHandle(129);
4240 #if TARGET_API_MAC_CARBON
4241 n = CountMenuItems(m);
4247 for (i = 1; i <= n; i++)
4250 #if TARGET_API_MAC_CARBON
4251 DisableMenuItem(m, i);
4252 CheckMenuItem(m, i, FALSE);
4255 CheckItem(m, i, FALSE);
4259 /* Enable "new"/"open..."/"import..." */
4260 if (initialized && !game_in_progress)
4262 #if TARGET_API_MAC_CARBON
4263 EnableMenuItem(m, 1);
4264 EnableMenuItem(m, 2);
4265 EnableMenuItem(m, 3);
4273 /* Enable "close" */
4276 #if TARGET_API_MAC_CARBON
4277 EnableMenuItem(m, 4);
4284 if (initialized && character_generated)
4286 #if TARGET_API_MAC_CARBON
4287 EnableMenuItem(m, 5);
4296 #if TARGET_API_MAC_CARBON
4297 EnableMenuItem(m, 7);
4305 m = GetMenuHandle(130);
4308 #if TARGET_API_MAC_CARBON
4309 n = CountMenuItems(m);
4315 for (i = 1; i <= n; i++)
4318 #if TARGET_API_MAC_CARBON
4319 DisableMenuItem(m, i);
4320 CheckMenuItem(m, i, FALSE);
4323 CheckItem(m, i, FALSE);
4327 /* Enable "edit" options if "needed" */
4330 #if TARGET_API_MAC_CARBON
4331 EnableMenuItem(m, 1);
4332 EnableMenuItem(m, 3);
4333 EnableMenuItem(m, 4);
4334 EnableMenuItem(m, 5);
4335 EnableMenuItem(m, 6);
4347 m = GetMenuHandle(131);
4350 #if TARGET_API_MAC_CARBON
4351 n = CountMenuItems(m);
4357 for (i = 1; i <= n; i++)
4360 #if TARGET_API_MAC_CARBON
4361 DisableMenuItem(m, i);
4362 CheckMenuItem(m, i, FALSE);
4365 CheckItem(m, i, FALSE);
4369 /* Hack -- look cute XXX XXX */
4370 /* SetItemStyle(m, 1, bold); */
4372 /* Hack -- look cute XXX XXX */
4373 /* SetItemStyle(m, 2, extend); */
4378 #if TARGET_API_MAC_CARBON
4380 EnableMenuItem(m, 1);
4382 /* Enable "extend" */
4383 EnableMenuItem(m, 2);
4385 /* Check the appropriate "bold-ness" */
4386 if (td->font_face & bold) CheckMenuItem(m, 1, TRUE);
4388 /* Check the appropriate "wide-ness" */
4389 if (td->font_face & extend) CheckMenuItem(m, 2, TRUE);
4392 for (i = 4; i <= n; i++)
4395 EnableMenuItem(m, i);
4398 GetMenuItemText(m, i, s);
4401 /* Check active font */
4402 if (td->font_id == value) CheckMenuItem(m, i, TRUE);
4408 /* Enable "extend" */
4411 /* Check the appropriate "bold-ness" */
4412 if (td->font_face & bold) CheckItem(m, 1, TRUE);
4414 /* Check the appropriate "wide-ness" */
4415 if (td->font_face & extend) CheckItem(m, 2, TRUE);
4418 for (i = 4; i <= n; i++)
4424 GetMenuItemText(m, i, s);
4427 /* Check active font */
4428 if (td->font_id == value) CheckItem(m, i, TRUE);
4435 m = GetMenuHandle(132);
4438 #if TARGET_API_MAC_CARBON
4439 n = CountMenuItems(m);
4445 for (i = 1; i <= n; i++)
4448 #if TARGET_API_MAC_CARBON
4449 DisableMenuItem(m, i);
4450 CheckMenuItem(m, i, FALSE);
4453 CheckItem(m, i, FALSE);
4461 for (i = 1; i <= n; i++)
4463 #if TARGET_API_MAC_CARBON
4465 GetMenuItemText(m, i, s);
4467 value = atoi((char*)(s+1));
4469 /* Enable the "real" sizes */
4470 if (RealFont(td->font_id, value)) EnableMenuItem(m, i);
4472 /* Check the current size */
4473 if (td->font_size == value) CheckMenuItem(m, i, TRUE);
4476 GetMenuItemText(m, i, s);
4478 value = atoi((char*)(s+1));
4480 /* Enable the "real" sizes */
4481 if (RealFont(td->font_id, value)) EnableItem(m, i);
4483 /* Check the current size */
4484 if (td->font_size == value) CheckItem(m, i, TRUE);
4491 m = GetMenuHandle(133);
4494 #if TARGET_API_MAC_CARBON
4495 n = CountMenuItems(m);
4500 /* Check active windows */
4501 for (i = 1; i <= n; i++)
4503 /* Check if needed */
4504 #if TARGET_API_MAC_CARBON
4505 CheckMenuItem(m, i, data[i-1].mapped);
4507 CheckItem(m, i, data[i-1].mapped);
4513 m = GetMenuHandle(134);
4516 #if TARGET_API_MAC_CARBON
4517 n = CountMenuItems(m);
4523 for (i = 1; i <= n; i++)
4526 #if TARGET_API_MAC_CARBON
4527 DisableMenuItem(m, i);
4528 CheckMenuItem(m, i, FALSE);
4531 CheckItem(m, i, FALSE);
4535 #if TARGET_API_MAC_CARBON
4536 /* Item "arg_sound" */
4537 EnableMenuItem(m, 1);
4538 CheckMenuItem(m, 1, arg_sound);
4540 /* Item "arg_graphics" */
4541 EnableMenuItem(m, 2);
4542 CheckMenuItem(m, 2, arg_graphics);
4544 /* Item "arg_fiddle" */
4545 EnableMenuItem(m, 4);
4546 CheckMenuItem(m, 4, arg_fiddle);
4548 /* Item "arg_wizard" */
4549 EnableMenuItem(m, 5);
4550 CheckMenuItem(m, 5, arg_wizard);
4552 /* Item "SoundSetting" */
4553 EnableMenuItem(m, 7);
4555 /* Item NewStyle Graphics */
4556 EnableMenuItem(m, 8);
4557 CheckMenuItem(m, 8, use_newstyle_graphics);
4559 /* Item Bigtile Mode */
4560 EnableMenuItem(m, 9);
4561 CheckMenuItem(m, 9, arg_bigtile);
4563 /* Item "arg_sound" */
4565 CheckItem(m, 1, arg_sound);
4567 /* Item "arg_graphics" */
4569 CheckItem(m, 2, arg_graphics);
4571 /* Item "arg_fiddle" */
4573 CheckItem(m, 4, arg_fiddle);
4575 /* Item "arg_wizard" */
4577 CheckItem(m, 5, arg_wizard);
4579 /* Item "SoundSetting" */
4582 /* Item NewStyle Graphics */
4584 CheckItem(m, 8, use_newstyle_graphics);
4586 /* Item Bigtile Mode */
4588 CheckItem(m, 9, arg_bigtile);
4591 /* TileWidth menu */
4592 m = GetMenuHandle(135);
4595 #if TARGET_API_MAC_CARBON
4596 n = CountMenuItems(m);
4602 for (i = 1; i <= n; i++)
4605 #if TARGET_API_MAC_CARBON
4606 DisableMenuItem(m, i);
4607 CheckMenuItem(m, i, FALSE);
4610 CheckItem(m, i, FALSE);
4618 for (i = 1; i <= n; i++)
4621 /* GetMenuItemText(m,i,s); */
4622 GetMenuItemText(m, i, s);
4624 value = atoi((char*)(s+1));
4626 #if TARGET_API_MAC_CARBON
4628 EnableMenuItem(m, i);
4630 /* Check the current size */
4631 if (td->tile_wid == value) CheckMenuItem(m, i, TRUE);
4636 /* Check the current size */
4637 if (td->tile_wid == value) CheckItem(m, i, TRUE);
4643 /* TileHeight menu */
4644 m = GetMenuHandle(136);
4647 #if TARGET_API_MAC_CARBON
4648 n = CountMenuItems(m);
4654 for (i = 1; i <= n; i++)
4657 #if TARGET_API_MAC_CARBON
4658 DisableMenuItem(m, i);
4659 CheckMenuItem(m, i, FALSE);
4662 CheckItem(m, i, FALSE);
4670 for (i = 1; i <= n; i++)
4673 GetMenuItemText(m, i, s);
4675 value = atoi((char*)(s+1));
4677 #if TARGET_API_MAC_CARBON
4679 EnableMenuItem(m, i);
4681 /* Check the current size */
4682 if (td->tile_hgt == value) CheckMenuItem(m, i, TRUE);
4687 /* Check the current size */
4688 if (td->tile_hgt == value) CheckItem(m, i, TRUE);
4696 * Process a menu selection (see above)
4698 * Hack -- assume that invalid menu selections are disabled above,
4699 * which I have been informed may not be reliable. XXX XXX XXX
4701 static void menu(long mc)
4705 int menuid, selection;
4707 static unsigned char s[1000];
4711 term_data *td = NULL;
4716 /* Analyze the menu command */
4717 menuid = HiWord(mc);
4718 selection = LoWord(mc);
4721 /* Find the window */
4722 for (i = 0; i < MAX_TERM_DATA; i++)
4724 /* Skip dead windows */
4725 if (!data[i].t) continue;
4727 /* Notice matches */
4728 if (data[i].w == FrontWindow()) td = &data[i];
4732 /* Branch on the menu */
4738 /* About Angband... */
4739 #if TARGET_API_MAC_CARBON
4745 /* Get the about dialogue */
4746 dialog=GetNewDialog(128, 0, (WindowPtr)-1);
4748 /* Move it to the middle of the screen */
4750 GetDialogWindow(dialog),
4752 kWindowCenterOnMainScreen);
4754 /* Show the dialog */
4755 TransitionWindow(GetDialogWindow(dialog),
4756 kWindowZoomTransitionEffect,
4757 kWindowShowTransitionAction,
4760 /* Wait for user to click on it */
4761 ModalDialog(0, &item_hit);
4763 /* Free the dialogue */
4764 DisposeDialog(dialog);
4774 dialog=GetNewDialog(128, 0, (WindowPtr)-1);
4777 center_rect(&r, &qd.screenBits.bounds);
4778 MoveWindow(dialog, r.left, r.top, 1);
4780 ModalDialog(0, &item_hit);
4781 DisposeDialog(dialog);
4785 /* Desk accessory */
4786 /* GetMenuItemText(GetMHandle(128),selection,s); */
4787 GetMenuItemText(GetMenuHandle(128), selection, s);
4808 do_menu_file_open(FALSE);
4815 do_menu_file_open(TRUE);
4829 td->t->mapped_flag = FALSE;
4831 /* Hide the window */
4842 plog("º£¤Ï¥»¡¼¥Ö¤¹¤ë¤³¤È¤Ï½ÐÍè¤Þ¤»¤ó¡£");
4844 plog("You may not do that right now.");
4849 /* Hack -- Forget messages */
4852 /* Hack -- Save the game */
4853 do_cmd_save_game(FALSE);
4858 /* Quit (with save) */
4861 /* Save the game (if necessary) */
4862 if (game_in_progress && character_generated)
4866 plog("º£¤Ï¥»¡¼¥Ö¤¹¤ë¤³¤È¤Ï½ÐÍè¤Þ¤»¤ó¡£");
4868 plog("You may not do that right now.");
4872 /* Hack -- Forget messages */
4877 do_cmd_save_game(FALSE);
4879 Term_key_push(SPECIAL_KEY_QUIT);
4901 /* Require a window */
4910 /* Toggle the "bold" setting */
4913 /* Toggle the setting */
4914 if (td->font_face & bold)
4916 td->font_face &= ~bold;
4920 td->font_face |= bold;
4923 /* Tile Width Hight Init */
4924 td->tile_wid = td->tile_hgt = 0;
4926 /* Apply and Verify */
4927 term_data_check_font(td);
4928 term_data_check_size(td);
4930 /* Resize and Redraw */
4931 term_data_resize(td);
4932 term_data_redraw(td);
4937 /* Toggle the "wide" setting */
4940 /* Toggle the setting */
4941 if (td->font_face & extend)
4943 td->font_face &= ~extend;
4947 td->font_face |= extend;
4950 /* Tile Width Hight Init */
4951 td->tile_wid = td->tile_hgt = 0;
4953 /* Apply and Verify */
4954 term_data_check_font(td);
4955 term_data_check_size(td);
4957 /* Resize and Redraw */
4958 term_data_resize(td);
4959 term_data_redraw(td);
4964 /* Get a new font name */
4965 GetMenuItemText(GetMenuHandle(131), selection, s);
4968 /* Save the new font id */
4971 /* Current size is bad for new font */
4972 if (!RealFont(td->font_id, td->font_size))
4974 /* Find similar size */
4975 for (i = 1; i <= 32; i++)
4977 /* Adjust smaller */
4978 if (td->font_size - i >= 8)
4980 if (RealFont(td->font_id, td->font_size - i))
4988 if (td->font_size + i <= 128)
4990 if (RealFont(td->font_id, td->font_size + i))
4999 /* Tile Width Hight Init */
5000 td->tile_wid = td->tile_hgt = 0;
5002 /* Apply and Verify */
5003 term_data_check_font(td);
5004 term_data_check_size(td);
5006 /* Resize and Redraw */
5007 term_data_resize(td);
5008 term_data_redraw(td);
5010 /* Restore the window */
5027 GetMenuItemText(GetMenuHandle(132), selection, s);
5029 td->font_size = atoi((char*)(s+1));
5031 /* Tile Width Hight Init */
5032 td->tile_wid = td->tile_hgt = 0;
5034 /* Apply and Verify */
5035 term_data_check_font(td);
5036 term_data_check_size(td);
5038 /* Resize and Redraw */
5039 term_data_resize(td);
5040 term_data_redraw(td);
5054 /* Check legality of choice */
5055 if ((i < 0) || (i >= MAX_TERM_DATA)) break;
5057 /* Obtain the window */
5067 td->t->mapped_flag = TRUE;
5069 /* Show the window */
5072 /* Bring to the front */
5073 SelectWindow(td->w);
5085 /* Toggle arg_sound */
5086 arg_sound = !arg_sound;
5088 /* React to changes */
5089 Term_xtra(TERM_XTRA_REACT, 0);
5096 /* Toggle arg_graphics */
5097 arg_graphics = !arg_graphics;
5098 if( arg_graphics == true ){
5099 ANGBAND_GRAF = "old";
5100 arg_newstyle_graphics = false;
5101 grafWidth = grafHeight = 8;
5105 /* Hack -- Force redraw */
5106 Term_key_push(KTRL('R'));
5113 arg_fiddle = !arg_fiddle;
5119 arg_wizard = !arg_wizard;
5130 if (streq(ANGBAND_GRAF, "old"))
5132 ANGBAND_GRAF = "new";
5133 arg_newstyle_graphics = true;
5134 grafWidth = grafHeight = 16;
5139 ANGBAND_GRAF = "old";
5140 arg_newstyle_graphics = false;
5141 grafWidth = grafHeight = 8;
5145 /* Hack -- Force redraw */
5146 Term_key_push(KTRL('R'));
5150 case 9: /* bigtile mode */
5152 term_data *td = &data[0];
5156 plog("º£¤ÏÊѹ¹½ÐÍè¤Þ¤»¤ó¡£");
5158 plog("You may not do that right now.");
5163 /* Toggle "arg_bigtile" */
5164 arg_bigtile = !arg_bigtile;
5167 Term_activate(td->t);
5169 /* Resize the term */
5170 Term_resize(td->cols, td->rows);
5180 /* TileWidth menu */
5191 GetMenuItemText(GetMenuHandle(135), selection, s);
5193 td->tile_wid = atoi((char*)(s+1));
5195 /* Apply and Verify */
5196 term_data_check_size(td);
5198 /* Resize and Redraw */
5199 term_data_resize(td);
5200 term_data_redraw(td);
5208 /* TileHeight menu */
5219 GetMenuItemText(GetMenuHandle(136), selection, s);
5221 td->tile_hgt = atoi((char*)(s+1));
5223 /* Apply and Verify */
5224 term_data_check_size(td);
5226 /* Resize and Redraw */
5227 term_data_resize(td);
5228 term_data_redraw(td);
5238 /* Clean the menu */
5247 * Check for extra required parameters -- From "Maarten Hazewinkel"
5249 static OSErr CheckRequiredAEParams(const AppleEvent *theAppleEvent)
5252 DescType returnedType;
5255 aeError = AEGetAttributePtr(theAppleEvent, keyMissedKeywordAttr, typeWildCard,
5256 &returnedType, NULL, 0, &actualSize);
5258 if (aeError == errAEDescNotFound) return (noErr);
5260 if (aeError == noErr) return (errAEParamMissed);
5267 * Apple Event Handler -- Open Application
5269 static pascal OSErr AEH_Start(const AppleEvent *theAppleEvent,
5270 AppleEvent *reply, long handlerRefCon)
5272 #pragma unused(reply, handlerRefCon)
5274 return (CheckRequiredAEParams(theAppleEvent));
5279 * Apple Event Handler -- Quit Application
5281 static pascal OSErr AEH_Quit(const AppleEvent *theAppleEvent,
5282 AppleEvent *reply, long handlerRefCon)
5284 #pragma unused(reply, handlerRefCon)
5285 #if TARGET_API_MAC_CARBON
5287 /* Save the game (if necessary) */
5288 if (game_in_progress && character_generated)
5292 plog("º£¤Ï¥»¡¼¥Ö¤¹¤ë¤³¤È¤Ï½ÐÍè¤Þ¤»¤ó¡£");
5294 plog("You may not do that right now.");
5298 /* Hack -- Forget messages */
5303 do_cmd_save_game(FALSE);
5305 Term_key_push(SPECIAL_KEY_QUIT);
5313 quit_when_ready = TRUE;
5315 /* Check arguments */
5316 return (CheckRequiredAEParams(theAppleEvent));
5322 * Apple Event Handler -- Print Documents
5324 static pascal OSErr AEH_Print(const AppleEvent *theAppleEvent,
5325 AppleEvent *reply, long handlerRefCon)
5327 #pragma unused(theAppleEvent, reply, handlerRefCon)
5329 return (errAEEventNotHandled);
5334 * Apple Event Handler by Steve Linberg (slinberg@crocker.com).
5336 * The old method of opening savefiles from the finder does not work
5337 * on the Power Macintosh, because CountAppFiles and GetAppFiles,
5338 * used to return information about the selected document files when
5339 * an application is launched, are part of the Segment Loader, which
5340 * is not present in the RISC OS due to the new memory architecture.
5342 * The "correct" way to do this is with AppleEvents. The following
5343 * code is modeled on the "Getting Files Selected from the Finder"
5344 * snippet from Think Reference 2.0. (The prior sentence could read
5345 * "shamelessly swiped & hacked")
5347 static pascal OSErr AEH_Open(const AppleEvent *theAppleEvent,
5348 AppleEvent* reply, long handlerRefCon)
5350 #pragma unused(reply, handlerRefCon)
5357 DescType returnedType;
5361 /* Put the direct parameter (a descriptor list) into a docList */
5362 err = AEGetParamDesc(theAppleEvent, keyDirectObject, typeAEList, &docList);
5363 if (err) return err;
5366 * We ignore the validity check, because we trust the FInder, and we only
5367 * allow one savefile to be opened, so we ignore the depth of the list.
5370 err = AEGetNthPtr(&docList, 1L, typeFSS, &keywd,
5371 &returnedType, (Ptr) &myFSS, sizeof(myFSS), &actualSize);
5372 if (err) return err;
5374 /* Only needed to check savefile type below */
5375 err = FSpGetFInfo(&myFSS, &myFileInfo);
5378 sprintf(foo, "Arg! FSpGetFInfo failed with code %d", err);
5383 /* Ignore non 'SAVE' files */
5384 if (myFileInfo.fdType != 'SAVE') return noErr;
5386 /* XXX XXX XXX Extract a file name */
5387 PathNameFromDirID(myFSS.parID, myFSS.vRefNum, (StringPtr)savefile);
5388 pstrcat((StringPtr)savefile, (StringPtr)&myFSS.name);
5390 /* Convert the string */
5391 ptocstr((StringPtr)savefile);
5393 /* Delay actual open */
5394 open_when_ready = TRUE;
5397 err = AEDisposeDesc(&docList);
5409 * Macintosh modifiers (event.modifier & ccc):
5410 * cmdKey, optionKey, shiftKey, alphaLock, controlKey
5413 * Macintosh Keycodes (0-63 normal, 64-95 keypad, 96-127 extra):
5458 * Optimize non-blocking calls to "CheckEvents()"
5459 * Idea from "Maarten Hazewinkel <mmhazewi@cs.ruu.nl>"
5461 #define EVENT_TICKS 6
5465 * Check for Events, return TRUE if we process any
5467 * Hack -- Handle AppleEvents if appropriate (ignore result code).
5469 static bool CheckEvents(bool wait)
5485 term_data *td = NULL;
5489 static huge lastTicks = 0L;
5492 /* Access the clock */
5493 curTicks = TickCount();
5495 /* Hack -- Allow efficient checking for non-pending events */
5496 if (!wait && (curTicks < lastTicks + EVENT_TICKS)) return (FALSE);
5498 /* Timestamp last check */
5499 lastTicks = curTicks;
5501 #if TARGET_API_MAC_CARBON
5502 WaitNextEvent( everyEvent, &event, 1L, nil );
5504 /* Let the "system" run */
5507 /* Get an event (or null) */
5508 GetNextEvent(everyEvent, &event);
5511 /* Hack -- Nothing is ready yet */
5512 if (event.what == nullEvent) return (FALSE);
5514 /* Analyze the event */
5522 w = (WindowPtr)event.message;
5533 /* Extract the window */
5534 w = (WindowPtr)event.message;
5536 /* Find the window */
5537 for (i = 0; i < MAX_TERM_DATA; i++)
5539 /* Skip dead windows */
5540 if (!data[i].t) continue;
5542 /* Notice matches */
5543 if (data[i].w == w) td = &data[i];
5546 /* Hack XXX XXX XXX */
5550 /* Redraw the window */
5551 if (td) term_data_redraw(td);
5559 /* Extract some modifiers */
5560 mc = (event.modifiers & controlKey) ? TRUE : FALSE;
5561 ms = (event.modifiers & shiftKey) ? TRUE : FALSE;
5562 mo = (event.modifiers & optionKey) ? TRUE : FALSE;
5563 mx = (event.modifiers & cmdKey) ? TRUE : FALSE;
5565 /* Keypress: (only "valid" if ck < 96) */
5566 ch = (event.message & charCodeMask) & 255;
5568 /* Keycode: see table above */
5569 ck = ((event.message & keyCodeMask) >> 8) & 255;
5571 /* Command + "normal key" -> menu action */
5572 if (mx && (ck < 64))
5574 /* Hack -- Prepare the menus */
5577 /* Run the Menu-Handler */
5580 /* Turn off the menus */
5588 /* Hide the mouse pointer */
5591 /* Normal key -> simple keypress */
5594 /* Enqueue the keypress */
5598 /* Bizarre key -> encoded keypress */
5601 /* Hack -- introduce with control-underscore */
5604 /* Send some modifier keys */
5605 if (mc) Term_keypress('C');
5606 if (ms) Term_keypress('S');
5607 if (mo) Term_keypress('O');
5608 if (mx) Term_keypress('X');
5610 /* Hack -- Downshift and encode the keycode */
5611 Term_keypress('0' + (ck - 64) / 10);
5612 Term_keypress('0' + (ck - 64) % 10);
5614 /* Hack -- Terminate the sequence */
5615 /* MPW can generate 10 or 13 for keycode of '\r' */
5616 /* -noMapCR option swaps '\r' and '\n' */
5617 Term_keypress('\r');
5627 /* Analyze click location */
5628 code = FindWindow(event.where, &w);
5630 /* Find the window */
5631 for (i = 0; i < MAX_TERM_DATA; i++)
5633 /* Skip dead windows */
5634 if (!data[i].t) continue;
5636 /* Notice matches */
5637 if (data[i].w == w) td = &data[i];
5646 menu(MenuSelect(event.where));
5650 #if !TARGET_API_MAC_CARBON
5653 SystemClick(&event, w);
5665 #if TARGET_API_MAC_CARBON
5666 GetQDGlobalsScreenBits( &screen );
5668 screen = qd.screenBits;
5671 r.top += 20; /* GetMBarHeight() XXX XXX XXX */
5672 InsetRect(&r, 4, 4);
5673 DragWindow(w, event.where, &r);
5685 #if TARGET_API_MAC_CARBON
5686 GetWindowBounds( (WindowRef)td->w, kWindowContentRgn, &portRect );
5688 portRect = td->w->portRect;
5689 local_to_global( &portRect );
5691 p.h = portRect.left;
5693 #if !TARGET_API_MAC_CARBON
5702 /* Apply and Verify */
5703 term_data_check_size(td);
5713 /* Track the go-away box */
5714 if (TrackGoAway(w, event.where))
5720 td->t->mapped_flag = FALSE;
5722 /* Hide the window */
5736 #if TARGET_API_MAC_CARBON
5737 GetQDGlobalsScreenBits( &screen );
5739 screen = qd.screenBits;
5744 /* Fake rectangle */
5745 r.left = 20 * td->tile_wid + td->size_ow1;
5746 r.right = screen.bounds.right;
5747 r.top = 1 * td->tile_hgt + td->size_oh1;
5748 r.bottom = screen.bounds.bottom;
5750 /* Grow the rectangle */
5751 newsize = GrowWindow(w, event.where, &r);
5754 if (!newsize) break;
5756 /* Extract the new size in pixels */
5757 y = HiWord(newsize) - td->size_oh1 - td->size_oh2;
5758 x = LoWord(newsize) - td->size_ow1 - td->size_ow2;
5760 /* Extract a "close" approximation */
5761 td->rows = y / td->tile_hgt;
5762 td->cols = x / td->tile_wid;
5764 /* Apply and Verify */
5765 term_data_check_size(td);
5767 Term_activate(td->t);
5769 /* Hack -- Resize the term */
5770 Term_resize(td->cols, td->rows);
5772 /* Resize and Redraw */
5773 term_data_resize(td);
5774 term_data_redraw(td);
5793 /* Disk Event -- From "Maarten Hazewinkel" */
5797 #if TARGET_API_MAC_CARBON
5799 /* check for error when mounting the disk */
5800 if (HiWord(event.message) != noErr)
5806 DIBadMount(p, event.message);
5813 /* OS Event -- From "Maarten Hazewinkel" */
5816 switch ((event.message >> 24) & 0x000000FF)
5818 case suspendResumeMessage:
5820 /* Resuming: activate the front window */
5821 if (event.message & resumeFlag)
5823 #if TARGET_API_MAC_CARBON
5826 SetPortWindowPort( FrontWindow() );
5828 GetQDGlobalsArrow( &arrow );
5831 SetPort(FrontWindow());
5832 SetCursor(&qd.arrow);
5836 /* Suspend: deactivate the front window */
5850 /* From "Steve Linberg" and "Maarten Hazewinkel" */
5851 case kHighLevelEvent:
5853 #if TARGET_API_MAC_CARBON
5854 AEProcessAppleEvent(&event);
5856 /* Process apple events */
5857 if (AEProcessAppleEvent(&event) != noErr)
5860 plog("Apple Event Handler¤Î¥¨¥é¡¼¤Ç¤¹.");
5862 plog("Error in Apple Event Handler!");
5866 /* Handle "quit_when_ready" */
5867 if (quit_when_ready)
5870 quit_when_ready = FALSE;
5872 /* Do the menu key */
5875 /* Turn off the menus */
5879 /* Handle "open_when_ready" */
5880 handle_open_when_ready();
5891 /* Something happened */
5898 /*** Some Hooks for various routines ***/
5902 * Mega-Hack -- emergency lifeboat
5904 static vptr lifeboat = NULL;
5908 * Hook to "release" memory
5910 static vptr hook_rnfree(vptr v, huge size)
5913 #pragma unused (size)
5917 /* Alternative method */
5932 * Hook to "allocate" memory
5934 static vptr hook_ralloc(huge size)
5939 /* Make a new pointer */
5940 return (malloc(size));
5944 /* Make a new pointer */
5945 return (NewPtr(size));
5952 * Hook to handle "out of memory" errors
5954 static vptr hook_rpanic(huge size)
5957 #pragma unused (size)
5961 /* Free the lifeboat */
5964 /* Free the lifeboat */
5965 DisposePtr(lifeboat);
5967 /* Forget the lifeboat */
5970 /* Mega-Hack -- Warning */
5972 mac_warning("¥á¥â¥ê¡¼¤¬Â¤ê¤Þ¤»¤ó!\rº£¤¹¤°½ªÎ»¤·¤Æ²¼¤µ¤¤!");
5974 mac_warning("Running out of Memory!\rAbort this process now!");
5977 /* Mega-Hack -- Never leave this function */
5978 while (TRUE) CheckEvents(TRUE);
5981 /* Mega-Hack -- Crash */
5987 * Hook to tell the user something important
5989 static void hook_plog(cptr str)
5991 /* Warning message */
5996 * Hook to tell the user something, and then quit
5998 static void hook_quit(cptr str)
6000 /* Warning if needed */
6001 if (str) mac_warning(str);
6003 /* Write a preference file */
6011 * Hook to tell the user something, and then crash
6013 static void hook_core(cptr str)
6015 /* XXX Use the debugger */
6016 /* DebugStr(str); */
6019 if (str) mac_warning(str);
6021 /* Warn, then save player */
6023 mac_warning("Ã×̿Ū¤Ê¥¨¥é¡¼¤Ç¤¹.\r¶¯À©Åª¤Ë¥»¡¼¥Ö¤·¤Æ½ªÎ»¤·¤Þ¤¹.");
6025 mac_warning("Fatal error.\rI will now attempt to save and quit.");
6028 /* Attempt to save */
6030 if (!save_player()) mac_warning("·Ù¹ð -- ¥»¡¼¥Ö¤Ë¼ºÇÔ¤·¤Þ¤·¤¿!");
6032 if (!save_player()) mac_warning("Warning -- save failed!");
6041 /*** Main program ***/
6047 * XXX XXX XXX Hack -- This function attempts to "fix" the nasty
6048 * "Macintosh Save Bug" by using "absolute" path names, since on
6049 * System 7 machines anyway, the "current working directory" often
6050 * "changes" due to background processes, invalidating any "relative"
6051 * path names. Note that the Macintosh is limited to 255 character
6052 * path names, so be careful about deeply embedded directories...
6054 * XXX XXX XXX Hack -- This function attempts to "fix" the nasty
6055 * "missing lib folder bug" by allowing the user to help find the
6056 * "lib" folder by hand if the "application folder" code fails...
6058 static void init_stuff(void)
6077 #if TARGET_API_MAC_CARBON
6079 NavDialogOptions dialogOptions;
6080 FSSpec theFolderSpec;
6081 NavReplyRecord theReply;
6083 /* Fake rectangle */
6090 #if TARGET_API_MAC_CARBON
6091 screenRect = GetQDGlobalsScreenBits(&screen)->bounds;
6093 screenRect = qd.screenBits.bounds;
6095 center_rect(&r, &screenRect);
6097 /* Extract corner */
6102 /* Default to the "lib" folder with the application */
6103 refnum_to_name(path, app_dir, app_vol, (char*)("\plib:"));
6106 /* Check until done */
6109 /* Prepare the paths */
6110 init_file_paths(path);
6112 /* Build the filename */
6114 path_build(path, sizeof(path), ANGBAND_DIR_FILE, "news_j.txt");
6116 path_build(path, sizeof(path), ANGBAND_DIR_FILE, "news.txt");
6119 /* Attempt to open and close that file */
6120 if (0 == fd_close(fd_open(path, O_RDONLY))) break;
6124 plog_fmt("'%s' ¥Õ¥¡¥¤¥ë¤ò¥ª¡¼¥×¥ó½ÐÍè¤Þ¤»¤ó.", path);
6126 plog_fmt("Unable to open the '%s' file.", path);
6131 plog("Hengband¤Î'lib'¥Õ¥©¥ë¥À¤¬Â¸ºß¤·¤Ê¤¤¤«Àµ¤·¤¯Ìµ¤¤²ÄǽÀ¤¬¤¢¤ê¤Þ¤¹.");
6133 plog("The Angband 'lib' folder is probably missing or misplaced.");
6138 plog("Please 'open' any file in any sub-folder of the 'lib' folder.");
6140 plog("Please 'open' any file in any sub-folder of the 'lib' folder.");
6143 #if TARGET_API_MAC_CARBON
6144 /* Ask the user to choose the lib folder */
6145 err = NavGetDefaultDialogOptions(&dialogOptions);
6148 if (err != noErr) quit(NULL);
6150 /* Set default location option */
6151 dialogOptions.dialogOptionFlags |= kNavSelectDefaultLocation;
6153 /* Clear preview option */
6154 dialogOptions.dialogOptionFlags &= ~(kNavAllowPreviews);
6156 /* Forbit selection of multiple files */
6157 dialogOptions.dialogOptionFlags &= ~(kNavAllowMultipleFiles);
6159 /* Display location */
6160 dialogOptions.location = topleft;
6162 /* Load the message for the missing folder from the resource fork */
6163 GetIndString(dialogOptions.message, 128, 1);
6165 /* Wait for the user to choose a folder */
6166 err = NavChooseFolder(
6174 /* Assume the player doesn't want to go on */
6175 if ((err != noErr) || !theReply.validRecord) quit(NULL);
6177 /* Retrieve FSSpec from the reply */
6179 AEKeyword theKeyword;
6180 DescType actualType;
6183 /* Get a pointer to selected folder */
6185 &(theReply.selection),
6195 if (err != noErr) quit(NULL);
6198 /* Free navitagor reply */
6199 err = NavDisposeReply(&theReply);
6202 if (err != noErr) quit(NULL);
6204 /* Extract textual file name for given file */
6207 theFolderSpec.parID,
6208 theFolderSpec.vRefNum,
6209 (char *)theFolderSpec.name);
6211 /* Allow "text" files */
6214 /* Allow "save" files */
6217 /* Allow "data" files */
6221 SFGetFile(topleft, "\p", NULL, 3, types, NULL, &reply);
6224 if (!reply.good) quit(NULL);
6226 /* Extract textual file name for given file */
6227 GetWDInfo(reply.vRefNum, &vrefnum, &drefnum, &junk);
6228 refnum_to_name(path, drefnum, vrefnum, (char*)reply.fName);
6231 /* Hack -- Remove the "filename" */
6232 i = strlen(path) - 1;
6233 while ((i > 0) && (path[i] != ':')) i--;
6234 if (path[i] == ':') path[i+1] = '\0';
6236 /* Hack -- allow "lib" folders */
6237 if (suffix(path, "lib:")) continue;
6239 /* Hack -- Remove the "sub-folder" */
6241 while ((i > 1) && (path[i] != ':')) i--;
6242 if (path[i] == ':') path[i+1] = '\0';
6248 * Macintosh Main loop
6252 EventRecord tempEvent;
6253 int numberOfMasters = 10;
6255 #if !TARGET_API_MAC_CARBON
6256 /* Increase stack space by 64K */
6257 SetApplLimit(GetApplLimit() - 131072L);//65536L);
6259 /* Stretch out the heap to full size */
6263 /* Get more Masters */
6264 while (numberOfMasters--) MoreMasters();
6266 #if !TARGET_API_MAC_CARBON
6267 /* Set up the Macintosh */
6268 InitGraf(&qd.thePort);
6282 FlushEvents(everyEvent, 0);
6284 /* Flush events some more (?) */
6285 (void)EventAvail(everyEvent, &tempEvent);
6286 (void)EventAvail(everyEvent, &tempEvent);
6287 (void)EventAvail(everyEvent, &tempEvent);
6290 #ifdef ANGBAND_LITE_MAC
6294 #else /* ANGBAND_LITE_MAC */
6296 # if defined(powerc) || defined(__powerc)
6298 /* Assume System 7 */
6300 /* Assume Color Quickdraw */
6310 /* Check the Gestalt */
6311 err = Gestalt(gestaltSystemVersion, &versionNumber);
6313 /* Check the version */
6314 if ((err != noErr) || (versionNumber < 0x0700))
6317 quit("¤³¤Î¥×¥í¥°¥é¥à¤Ï´Á»úTalk7.x.x°Ê¹ß¤ÇÆ°ºî¤·¤Þ¤¹.");
6319 quit("You must have System 7 to use this program.");
6329 /* Check the environs */
6330 if (SysEnvirons(1, &env) != noErr)
6333 quit("SysEnvirons ¥³¡¼¥ë¤Ï¼ºÇÔ¤·¤Þ¤·¤¿¡ª");
6335 quit("The SysEnvirons call failed!");
6339 /* Check for System Seven Stuff */
6340 if (env.systemVersion < 0x0700)
6343 quit("¤³¤Î¥×¥í¥°¥é¥à¤Ï´Á»úTalk7.x.x°Ê¹ß¤ÇÆ°ºî¤·¤Þ¤¹.");
6345 quit("You must have System 7 to use this program.");
6349 /* Check for Color Quickdraw */
6350 if (!env.hasColorQD)
6353 quit("¤³¤Î¥×¥í¥°¥é¥à¤ÏColor Quickdraw¤¬Ìµ¤¤¤ÈÆ°ºî¤·¤Þ¤»¤ó.");
6355 quit("You must have Color Quickdraw to use this program.");
6362 #endif /* ANGBAND_LITE_MAC */
6365 * Remember Mac OS version, in case we have to cope with version-specific
6368 (void)Gestalt(gestaltSystemVersion, &mac_os_version);
6371 /* Obtain a "Universal Procedure Pointer" */
6372 AEH_Start_UPP = NewAEEventHandlerUPP(AEH_Start);
6373 /* Install the hook (ignore error codes) */
6374 AEInstallEventHandler(kCoreEventClass, kAEOpenApplication, AEH_Start_UPP,
6377 /* Obtain a "Universal Procedure Pointer" */
6378 AEH_Quit_UPP = NewAEEventHandlerUPP(AEH_Quit);
6379 /* Install the hook (ignore error codes) */
6380 AEInstallEventHandler(kCoreEventClass, kAEQuitApplication, AEH_Quit_UPP,
6383 /* Obtain a "Universal Procedure Pointer" */
6384 AEH_Print_UPP = NewAEEventHandlerUPP(AEH_Print);
6385 /* Install the hook (ignore error codes) */
6386 AEInstallEventHandler(kCoreEventClass, kAEPrintDocuments, AEH_Print_UPP,
6389 /* Obtain a "Universal Procedure Pointer" */
6390 AEH_Open_UPP = NewAEEventHandlerUPP(AEH_Open);
6391 /* Install the hook (ignore error codes) */
6392 AEInstallEventHandler(kCoreEventClass, kAEOpenDocuments, AEH_Open_UPP,
6396 /* Find the current application */
6400 /* Mark ourself as the file creator */
6401 _fcreator = ANGBAND_CREATOR;
6403 /* Default to saving a "text" file */
6407 #if defined(__MWERKS__)
6409 /* Obtian a "Universal Procedure Pointer" */
6410 #if TARGET_API_MAC_CARBON
6411 ynfilterUPP = NewModalFilterUPP(ynfilter);
6413 ynfilterUPP = NewModalFilterProc(ynfilter);
6419 /* Hook in some "z-virt.c" hooks */
6420 rnfree_aux = hook_rnfree;
6421 ralloc_aux = hook_ralloc;
6422 rpanic_aux = hook_rpanic;
6424 /* Hooks in some "z-util.c" hooks */
6425 plog_aux = hook_plog;
6426 quit_aux = hook_quit;
6427 core_aux = hook_core;
6429 BackColor(blackColor);
6430 ForeColor(whiteColor);
6432 /* Show the "watch" cursor */
6433 SetCursor(*(GetCursor(watchCursor)));
6435 /* Prepare the menubar */
6438 /* Prepare the windows */
6445 /* Hack -- process all events */
6446 while (CheckEvents(TRUE)) /* loop */;
6448 /* Reset the cursor */
6449 #if TARGET_API_MAC_CARBON
6452 GetQDGlobalsArrow( &arrow );
6456 SetCursor( &qd.arrow );
6460 /* Mega-Hack -- Allocate a "lifeboat" */
6461 lifeboat = NewPtr(16384);
6463 /* Note the "system" */
6464 ANGBAND_SYS = "mac";
6469 /* Catch nasty signals */
6476 /* Hack -- process all events */
6477 while (CheckEvents(TRUE)) /* loop */;
6480 /* We are now initialized */
6484 /* Handle "open_when_ready" */
6485 handle_open_when_ready();
6491 /* Prompt the user */
6493 prt("'¥Õ¥¡¥¤¥ë'¥á¥Ë¥å¡¼¤è¤ê'¿·µ¬'¤Þ¤¿¤Ï'³«¤¯...'¤òÁªÂò¤·¤Æ¤¯¤À¤µ¤¤¡£", 23, 10);
6495 prt("[Choose 'New' or 'Open' from the 'File' menu]", 23, 15);
6498 /* Flush the prompt */
6502 /* Hack -- Process Events Forever */
6503 while (TRUE) CheckEvents(TRUE);