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;
3779 /* Game is in progress */
3780 game_in_progress = TRUE;
3792 static void do_menu_file_open(bool all)
3806 /* vrefnum = GetSFCurVol(); */
3807 vrefnum = -*((short*)0x214);
3809 /* drefnum = GetSFCurDir(); */
3810 drefnum = *((long*)0x398);
3812 /* Descend into "lib" folder */
3813 pb.ioCompletion = NULL;
3814 pb.ioNamePtr = "\plib";
3815 pb.ioVRefNum = vrefnum;
3816 pb.ioDrDirID = drefnum;
3819 /* Check for errors */
3820 err = PBGetCatInfo((CInfoPBPtr)&pb, FALSE);
3823 if ((err == noErr) && (pb.ioFlAttrib & 0x10))
3825 /* Descend into "lib/save" folder */
3826 pb.ioCompletion = NULL;
3827 pb.ioNamePtr = "\psave";
3828 pb.ioVRefNum = vrefnum;
3829 pb.ioDrDirID = pb.ioDrDirID;
3832 /* Check for errors */
3833 err = PBGetCatInfo((CInfoPBPtr)&pb, FALSE);
3836 if ((err == noErr) && (pb.ioFlAttrib & 0x10))
3838 /* SetSFCurDir(pb.ioDrDirID); */
3839 *((long*)0x398) = pb.ioDrDirID;
3843 /* Window location */
3844 topleft.h = (qd.screenBits.bounds.left+qd.screenBits.bounds.right)/2-344/2;
3845 topleft.v = (2*qd.screenBits.bounds.top+qd.screenBits.bounds.bottom)/3-188/2;
3847 /* Allow "all" files */
3851 SFGetFile(topleft, "\p", NULL, -1, types, NULL, &reply);
3854 /* Allow "save" files */
3861 SFGetFile(topleft, "\p", NULL, 1, types, NULL, &reply);
3865 if (!reply.good) return;
3867 /* Extract textual file name for save file */
3868 GetWDInfo(reply.vRefNum, &vrefnum, &drefnum, &junk);
3869 refnum_to_name(savefile, drefnum, vrefnum, (char*)reply.fName);
3874 /* Game is in progress */
3875 game_in_progress = 1;
3890 * Handle the "open_when_ready" flag
3892 static void handle_open_when_ready(void)
3894 /* Check the flag XXX XXX XXX make a function for this */
3895 if (open_when_ready && initialized && !game_in_progress)
3898 open_when_ready = FALSE;
3900 /* Game is in progress */
3901 game_in_progress = 1;
3920 * Initialize the menus
3922 * Verify menus 128, 129, 130
3923 * Create menus 131, 132, 133, 134
3925 * The standard menus are:
3927 * Apple (128) = { About, -, ... }
3928 * File (129) = { New,Open,Import,Close,Save,-,Exit,Quit }
3929 * Edit (130) = { Cut, Copy, Paste, Clear } (?)
3930 * Font (131) = { Bold, Extend, -, Monaco, ..., -, ... }
3931 * Size (132) = { ... }
3932 * Window (133) = { Angband, Mirror, Recall, Choice,
3933 * Term-4, Term-5, Term-6, Term-7 }
3934 * Special (134) = { arg_sound, arg_graphics, -,
3935 * arg_fiddle, arg_wizard }
3937 static void init_menubar(void)
3949 /* Get the "apple" menu */
3952 /* Insert the menu */
3955 /* Add the DA's to the "apple" menu */
3956 #if TARGET_API_MAC_CARBON
3958 AppendResMenu (m, 'DRVR');
3961 /* Get the "File" menu */
3962 #if TARGET_API_MAC_CARBON
3964 err = Gestalt( gestaltSystemVersion, &response );
3965 if ( (err == noErr) && (response >= 0x00000A00) )
3967 DeleteMenuItem( m, 7 );
3973 /* Insert the menu */
3977 /* Get the "Edit" menu */
3980 /* Insert the menu */
3984 /* Make the "Font" menu */
3986 m = NewMenu(131, "\p¥Õ¥©¥ó¥È");
3988 m = NewMenu(131, "\pFont");
3991 /* Insert the menu */
3995 AppendMenu(m, "\pBold");
3998 AppendMenu(m, "\pWide");
4000 /* Add a separator */
4001 AppendMenu(m, "\p-");
4004 r.left = r.right = r.top = r.bottom = 0;
4006 /* Make the fake window */
4007 tmpw = NewWindow(0, &r, "\p", false, documentProc, 0, 0, 0);
4009 /* Activate the "fake" window */
4010 #if TARGET_API_MAC_CARBON
4011 SetPortWindowPort(tmpw);
4022 /* Add the fonts to the menu */
4023 AppendResMenu(m, 'FONT');
4026 #if TARGET_API_MAC_CARBON
4027 n = CountMenuItems(m);
4033 for (i = n; i >= 4; i--)
4038 /* Acquire the font name */
4039 GetMenuItemText(m, i, tmpName);
4041 /* Acquire the font index */
4042 #if TARGET_API_MAC_CARBON
4043 fontNum = FMGetFontFamilyFromName( tmpName );
4045 GetFNum(tmpName, &fontNum);
4048 /* Apply the font index */
4051 /* Remove non-mono-spaced fonts */
4052 if ((CharWidth('i') != CharWidth('W')) || (CharWidth('W') == 0))
4054 /* Delete the menu item XXX XXX XXX */
4055 DeleteMenuItem (m, i);
4059 /* Destroy the old window */
4060 DisposeWindow(tmpw);
4062 /* Add a separator */
4063 AppendMenu(m, "\p-");
4065 /* Add the fonts to the menu */
4066 AppendResMenu (m, 'FONT');
4069 /* Make the "Size" menu */
4071 m = NewMenu(132, "\p¥µ¥¤¥º");
4073 m = NewMenu(132, "\pSize");
4076 /* Insert the menu */
4079 /* Add some sizes (stagger choices) */
4080 for (i = 8; i <= 32; i += ((i / 16) + 1))
4085 sprintf((char*)buf + 1, "%d", i);
4086 buf[0] = strlen((char*)buf + 1);
4093 /* Make the "Windows" menu */
4095 m = NewMenu(133, "\p¥¦¥¤¥ó¥É¥¦");
4097 m = NewMenu(133, "\pWindows");
4100 /* Insert the menu */
4103 /* Default choices */
4104 for (i = 0; i < MAX_TERM_DATA; i++)
4108 /* Describe the item */
4109 sprintf((char*)buf + 1, "%.15s", angband_term_name[i]);
4110 buf[0] = strlen((char*)buf + 1);
4115 /* Command-Key shortcuts */
4116 if (i < 8) SetItemCmd(m, i + 1, '0' + i);
4120 /* Make the "Special" menu */
4122 m = NewMenu(134, "\pÆÃÊÌ");
4124 m = NewMenu(134, "\pSpecial");
4127 /* Insert the menu */
4130 /* Append the choices */
4132 AppendMenu(m, "\p¥µ¥¦¥ó¥É»ÈÍÑ");
4133 AppendMenu(m, "\p¥°¥é¥Õ¥£¥Ã¥¯»ÈÍÑ");
4134 AppendMenu(m, "\p-");
4135 AppendMenu(m, "\parg_fiddle");
4136 AppendMenu(m, "\parg_wizard");
4137 AppendMenu(m, "\p-");
4138 AppendMenu(m, "\p¥µ¥¦¥ó¥ÉÀßÄê...");
4139 AppendMenu(m, "\p16X16¥°¥é¥Õ¥£¥Ã¥¯");
4140 AppendMenu(m, "\p£²ÇÜÉý¥¿¥¤¥ëɽ¼¨");
4142 AppendMenu(m, "\parg_sound");
4143 AppendMenu(m, "\parg_graphics");
4144 AppendMenu(m, "\p-");
4145 AppendMenu(m, "\parg_fiddle");
4146 AppendMenu(m, "\parg_wizard");
4147 AppendMenu(m, "\p-");
4148 AppendMenu(m, "\pSound config");
4149 AppendMenu(m, "\pAdam Bolt tile");
4150 AppendMenu(m, "\pBigtile Mode");
4153 /* Make the "TileWidth" menu */
4155 m = NewMenu(135, "\p¥¿¥¤¥ëÉý");
4157 m = NewMenu(135, "\pTileWidth");
4160 /* Insert the menu */
4163 /* Add some sizes */
4164 for (i = 4; i <= 32; i++)
4169 sprintf((char*)buf + 1, "%d", i);
4170 buf[0] = strlen((char*)buf + 1);
4177 /* Make the "TileHeight" menu */
4179 m = NewMenu(136, "\p¥¿¥¤¥ë¹â");
4181 m = NewMenu(136, "\pTileHeight");
4184 /* Insert the menu */
4187 /* Add some sizes */
4188 for (i = 4; i <= 32; i++)
4193 sprintf((char*)buf + 1, "%d", i);
4194 buf[0] = strlen((char*)buf + 1);
4201 /* Update the menu bar */
4209 static void setup_menus(void)
4219 term_data *td = NULL;
4222 /* Relevant "term_data" */
4223 for (i = 0; i < MAX_TERM_DATA; i++)
4226 if (!data[i].t) continue;
4228 /* Notice the matching window */
4229 if (data[i].w == FrontWindow()) td = &data[i];
4234 m = GetMenuHandle(129);
4237 #if TARGET_API_MAC_CARBON
4238 n = CountMenuItems(m);
4244 for (i = 1; i <= n; i++)
4247 #if TARGET_API_MAC_CARBON
4248 DisableMenuItem(m, i);
4249 CheckMenuItem(m, i, FALSE);
4252 CheckItem(m, i, FALSE);
4256 /* Enable "new"/"open..."/"import..." */
4257 if (initialized && !game_in_progress)
4259 #if TARGET_API_MAC_CARBON
4260 EnableMenuItem(m, 1);
4261 EnableMenuItem(m, 2);
4262 EnableMenuItem(m, 3);
4270 /* Enable "close" */
4273 #if TARGET_API_MAC_CARBON
4274 EnableMenuItem(m, 4);
4281 if (initialized && character_generated)
4283 #if TARGET_API_MAC_CARBON
4284 EnableMenuItem(m, 5);
4293 #if TARGET_API_MAC_CARBON
4294 EnableMenuItem(m, 7);
4302 m = GetMenuHandle(130);
4305 #if TARGET_API_MAC_CARBON
4306 n = CountMenuItems(m);
4312 for (i = 1; i <= n; i++)
4315 #if TARGET_API_MAC_CARBON
4316 DisableMenuItem(m, i);
4317 CheckMenuItem(m, i, FALSE);
4320 CheckItem(m, i, FALSE);
4324 /* Enable "edit" options if "needed" */
4327 #if TARGET_API_MAC_CARBON
4328 EnableMenuItem(m, 1);
4329 EnableMenuItem(m, 3);
4330 EnableMenuItem(m, 4);
4331 EnableMenuItem(m, 5);
4332 EnableMenuItem(m, 6);
4344 m = GetMenuHandle(131);
4347 #if TARGET_API_MAC_CARBON
4348 n = CountMenuItems(m);
4354 for (i = 1; i <= n; i++)
4357 #if TARGET_API_MAC_CARBON
4358 DisableMenuItem(m, i);
4359 CheckMenuItem(m, i, FALSE);
4362 CheckItem(m, i, FALSE);
4366 /* Hack -- look cute XXX XXX */
4367 /* SetItemStyle(m, 1, bold); */
4369 /* Hack -- look cute XXX XXX */
4370 /* SetItemStyle(m, 2, extend); */
4375 #if TARGET_API_MAC_CARBON
4377 EnableMenuItem(m, 1);
4379 /* Enable "extend" */
4380 EnableMenuItem(m, 2);
4382 /* Check the appropriate "bold-ness" */
4383 if (td->font_face & bold) CheckMenuItem(m, 1, TRUE);
4385 /* Check the appropriate "wide-ness" */
4386 if (td->font_face & extend) CheckMenuItem(m, 2, TRUE);
4389 for (i = 4; i <= n; i++)
4392 EnableMenuItem(m, i);
4395 GetMenuItemText(m, i, s);
4398 /* Check active font */
4399 if (td->font_id == value) CheckMenuItem(m, i, TRUE);
4405 /* Enable "extend" */
4408 /* Check the appropriate "bold-ness" */
4409 if (td->font_face & bold) CheckItem(m, 1, TRUE);
4411 /* Check the appropriate "wide-ness" */
4412 if (td->font_face & extend) CheckItem(m, 2, TRUE);
4415 for (i = 4; i <= n; i++)
4421 GetMenuItemText(m, i, s);
4424 /* Check active font */
4425 if (td->font_id == value) CheckItem(m, i, TRUE);
4432 m = GetMenuHandle(132);
4435 #if TARGET_API_MAC_CARBON
4436 n = CountMenuItems(m);
4442 for (i = 1; i <= n; i++)
4445 #if TARGET_API_MAC_CARBON
4446 DisableMenuItem(m, i);
4447 CheckMenuItem(m, i, FALSE);
4450 CheckItem(m, i, FALSE);
4458 for (i = 1; i <= n; i++)
4460 #if TARGET_API_MAC_CARBON
4462 GetMenuItemText(m, i, s);
4464 value = atoi((char*)(s+1));
4466 /* Enable the "real" sizes */
4467 if (RealFont(td->font_id, value)) EnableMenuItem(m, i);
4469 /* Check the current size */
4470 if (td->font_size == value) CheckMenuItem(m, i, TRUE);
4473 GetMenuItemText(m, i, s);
4475 value = atoi((char*)(s+1));
4477 /* Enable the "real" sizes */
4478 if (RealFont(td->font_id, value)) EnableItem(m, i);
4480 /* Check the current size */
4481 if (td->font_size == value) CheckItem(m, i, TRUE);
4488 m = GetMenuHandle(133);
4491 #if TARGET_API_MAC_CARBON
4492 n = CountMenuItems(m);
4497 /* Check active windows */
4498 for (i = 1; i <= n; i++)
4500 /* Check if needed */
4501 #if TARGET_API_MAC_CARBON
4502 CheckMenuItem(m, i, data[i-1].mapped);
4504 CheckItem(m, i, data[i-1].mapped);
4510 m = GetMenuHandle(134);
4513 #if TARGET_API_MAC_CARBON
4514 n = CountMenuItems(m);
4520 for (i = 1; i <= n; i++)
4523 #if TARGET_API_MAC_CARBON
4524 DisableMenuItem(m, i);
4525 CheckMenuItem(m, i, FALSE);
4528 CheckItem(m, i, FALSE);
4532 #if TARGET_API_MAC_CARBON
4533 /* Item "arg_sound" */
4534 EnableMenuItem(m, 1);
4535 CheckMenuItem(m, 1, arg_sound);
4537 /* Item "arg_graphics" */
4538 EnableMenuItem(m, 2);
4539 CheckMenuItem(m, 2, arg_graphics);
4541 /* Item "arg_fiddle" */
4542 EnableMenuItem(m, 4);
4543 CheckMenuItem(m, 4, arg_fiddle);
4545 /* Item "arg_wizard" */
4546 EnableMenuItem(m, 5);
4547 CheckMenuItem(m, 5, arg_wizard);
4549 /* Item "SoundSetting" */
4550 EnableMenuItem(m, 7);
4552 /* Item NewStyle Graphics */
4553 EnableMenuItem(m, 8);
4554 CheckMenuItem(m, 8, use_newstyle_graphics);
4556 /* Item Bigtile Mode */
4557 EnableMenuItem(m, 9);
4558 CheckMenuItem(m, 9, arg_bigtile);
4560 /* Item "arg_sound" */
4562 CheckItem(m, 1, arg_sound);
4564 /* Item "arg_graphics" */
4566 CheckItem(m, 2, arg_graphics);
4568 /* Item "arg_fiddle" */
4570 CheckItem(m, 4, arg_fiddle);
4572 /* Item "arg_wizard" */
4574 CheckItem(m, 5, arg_wizard);
4576 /* Item "SoundSetting" */
4579 /* Item NewStyle Graphics */
4581 CheckItem(m, 8, use_newstyle_graphics);
4583 /* Item Bigtile Mode */
4585 CheckItem(m, 9, arg_bigtile);
4588 /* TileWidth menu */
4589 m = GetMenuHandle(135);
4592 #if TARGET_API_MAC_CARBON
4593 n = CountMenuItems(m);
4599 for (i = 1; i <= n; i++)
4602 #if TARGET_API_MAC_CARBON
4603 DisableMenuItem(m, i);
4604 CheckMenuItem(m, i, FALSE);
4607 CheckItem(m, i, FALSE);
4615 for (i = 1; i <= n; i++)
4618 /* GetMenuItemText(m,i,s); */
4619 GetMenuItemText(m, i, s);
4621 value = atoi((char*)(s+1));
4623 #if TARGET_API_MAC_CARBON
4625 EnableMenuItem(m, i);
4627 /* Check the current size */
4628 if (td->tile_wid == value) CheckMenuItem(m, i, TRUE);
4633 /* Check the current size */
4634 if (td->tile_wid == value) CheckItem(m, i, TRUE);
4640 /* TileHeight menu */
4641 m = GetMenuHandle(136);
4644 #if TARGET_API_MAC_CARBON
4645 n = CountMenuItems(m);
4651 for (i = 1; i <= n; i++)
4654 #if TARGET_API_MAC_CARBON
4655 DisableMenuItem(m, i);
4656 CheckMenuItem(m, i, FALSE);
4659 CheckItem(m, i, FALSE);
4667 for (i = 1; i <= n; i++)
4670 GetMenuItemText(m, i, s);
4672 value = atoi((char*)(s+1));
4674 #if TARGET_API_MAC_CARBON
4676 EnableMenuItem(m, i);
4678 /* Check the current size */
4679 if (td->tile_hgt == value) CheckMenuItem(m, i, TRUE);
4684 /* Check the current size */
4685 if (td->tile_hgt == value) CheckItem(m, i, TRUE);
4693 * Process a menu selection (see above)
4695 * Hack -- assume that invalid menu selections are disabled above,
4696 * which I have been informed may not be reliable. XXX XXX XXX
4698 static void menu(long mc)
4702 int menuid, selection;
4704 static unsigned char s[1000];
4708 term_data *td = NULL;
4713 /* Analyze the menu command */
4714 menuid = HiWord(mc);
4715 selection = LoWord(mc);
4718 /* Find the window */
4719 for (i = 0; i < MAX_TERM_DATA; i++)
4721 /* Skip dead windows */
4722 if (!data[i].t) continue;
4724 /* Notice matches */
4725 if (data[i].w == FrontWindow()) td = &data[i];
4729 /* Branch on the menu */
4735 /* About Angband... */
4736 #if TARGET_API_MAC_CARBON
4742 /* Get the about dialogue */
4743 dialog=GetNewDialog(128, 0, (WindowPtr)-1);
4745 /* Move it to the middle of the screen */
4747 GetDialogWindow(dialog),
4749 kWindowCenterOnMainScreen);
4751 /* Show the dialog */
4752 TransitionWindow(GetDialogWindow(dialog),
4753 kWindowZoomTransitionEffect,
4754 kWindowShowTransitionAction,
4757 /* Wait for user to click on it */
4758 ModalDialog(0, &item_hit);
4760 /* Free the dialogue */
4761 DisposeDialog(dialog);
4771 dialog=GetNewDialog(128, 0, (WindowPtr)-1);
4774 center_rect(&r, &qd.screenBits.bounds);
4775 MoveWindow(dialog, r.left, r.top, 1);
4777 ModalDialog(0, &item_hit);
4778 DisposeDialog(dialog);
4782 /* Desk accessory */
4783 /* GetMenuItemText(GetMHandle(128),selection,s); */
4784 GetMenuItemText(GetMenuHandle(128), selection, s);
4805 do_menu_file_open(FALSE);
4812 do_menu_file_open(TRUE);
4826 td->t->mapped_flag = FALSE;
4828 /* Hide the window */
4839 plog("º£¤Ï¥»¡¼¥Ö¤¹¤ë¤³¤È¤Ï½ÐÍè¤Þ¤»¤ó¡£");
4841 plog("You may not do that right now.");
4846 /* Hack -- Forget messages */
4849 /* Hack -- Save the game */
4850 do_cmd_save_game(FALSE);
4855 /* Quit (with save) */
4858 /* Save the game (if necessary) */
4859 if (game_in_progress && character_generated)
4863 plog("º£¤Ï¥»¡¼¥Ö¤¹¤ë¤³¤È¤Ï½ÐÍè¤Þ¤»¤ó¡£");
4865 plog("You may not do that right now.");
4869 /* Hack -- Forget messages */
4874 do_cmd_save_game(FALSE);
4876 Term_key_push(SPECIAL_KEY_QUIT);
4898 /* Require a window */
4907 /* Toggle the "bold" setting */
4910 /* Toggle the setting */
4911 if (td->font_face & bold)
4913 td->font_face &= ~bold;
4917 td->font_face |= bold;
4920 /* Tile Width Hight Init */
4921 td->tile_wid = td->tile_hgt = 0;
4923 /* Apply and Verify */
4924 term_data_check_font(td);
4925 term_data_check_size(td);
4927 /* Resize and Redraw */
4928 term_data_resize(td);
4929 term_data_redraw(td);
4934 /* Toggle the "wide" setting */
4937 /* Toggle the setting */
4938 if (td->font_face & extend)
4940 td->font_face &= ~extend;
4944 td->font_face |= extend;
4947 /* Tile Width Hight Init */
4948 td->tile_wid = td->tile_hgt = 0;
4950 /* Apply and Verify */
4951 term_data_check_font(td);
4952 term_data_check_size(td);
4954 /* Resize and Redraw */
4955 term_data_resize(td);
4956 term_data_redraw(td);
4961 /* Get a new font name */
4962 GetMenuItemText(GetMenuHandle(131), selection, s);
4965 /* Save the new font id */
4968 /* Current size is bad for new font */
4969 if (!RealFont(td->font_id, td->font_size))
4971 /* Find similar size */
4972 for (i = 1; i <= 32; i++)
4974 /* Adjust smaller */
4975 if (td->font_size - i >= 8)
4977 if (RealFont(td->font_id, td->font_size - i))
4985 if (td->font_size + i <= 128)
4987 if (RealFont(td->font_id, td->font_size + i))
4996 /* Tile Width Hight Init */
4997 td->tile_wid = td->tile_hgt = 0;
4999 /* Apply and Verify */
5000 term_data_check_font(td);
5001 term_data_check_size(td);
5003 /* Resize and Redraw */
5004 term_data_resize(td);
5005 term_data_redraw(td);
5007 /* Restore the window */
5024 GetMenuItemText(GetMenuHandle(132), selection, s);
5026 td->font_size = atoi((char*)(s+1));
5028 /* Tile Width Hight Init */
5029 td->tile_wid = td->tile_hgt = 0;
5031 /* Apply and Verify */
5032 term_data_check_font(td);
5033 term_data_check_size(td);
5035 /* Resize and Redraw */
5036 term_data_resize(td);
5037 term_data_redraw(td);
5051 /* Check legality of choice */
5052 if ((i < 0) || (i >= MAX_TERM_DATA)) break;
5054 /* Obtain the window */
5064 td->t->mapped_flag = TRUE;
5066 /* Show the window */
5069 /* Bring to the front */
5070 SelectWindow(td->w);
5082 /* Toggle arg_sound */
5083 arg_sound = !arg_sound;
5085 /* React to changes */
5086 Term_xtra(TERM_XTRA_REACT, 0);
5093 /* Toggle arg_graphics */
5094 arg_graphics = !arg_graphics;
5095 if( arg_graphics == true ){
5096 ANGBAND_GRAF = "old";
5097 arg_newstyle_graphics = false;
5098 grafWidth = grafHeight = 8;
5102 /* Hack -- Force redraw */
5103 Term_key_push(KTRL('R'));
5110 arg_fiddle = !arg_fiddle;
5116 arg_wizard = !arg_wizard;
5127 if (streq(ANGBAND_GRAF, "old"))
5129 ANGBAND_GRAF = "new";
5130 arg_newstyle_graphics = true;
5131 grafWidth = grafHeight = 16;
5136 ANGBAND_GRAF = "old";
5137 arg_newstyle_graphics = false;
5138 grafWidth = grafHeight = 8;
5142 /* Hack -- Force redraw */
5143 Term_key_push(KTRL('R'));
5147 case 9: /* bigtile mode */
5149 term_data *td = &data[0];
5153 plog("º£¤ÏÊѹ¹½ÐÍè¤Þ¤»¤ó¡£");
5155 plog("You may not do that right now.");
5160 /* Toggle "arg_bigtile" */
5161 arg_bigtile = !arg_bigtile;
5164 Term_activate(td->t);
5166 /* Resize the term */
5167 Term_resize(td->cols, td->rows);
5177 /* TileWidth menu */
5188 GetMenuItemText(GetMenuHandle(135), selection, s);
5190 td->tile_wid = atoi((char*)(s+1));
5192 /* Apply and Verify */
5193 term_data_check_size(td);
5195 /* Resize and Redraw */
5196 term_data_resize(td);
5197 term_data_redraw(td);
5205 /* TileHeight menu */
5216 GetMenuItemText(GetMenuHandle(136), selection, s);
5218 td->tile_hgt = atoi((char*)(s+1));
5220 /* Apply and Verify */
5221 term_data_check_size(td);
5223 /* Resize and Redraw */
5224 term_data_resize(td);
5225 term_data_redraw(td);
5235 /* Clean the menu */
5244 * Check for extra required parameters -- From "Maarten Hazewinkel"
5246 static OSErr CheckRequiredAEParams(const AppleEvent *theAppleEvent)
5249 DescType returnedType;
5252 aeError = AEGetAttributePtr(theAppleEvent, keyMissedKeywordAttr, typeWildCard,
5253 &returnedType, NULL, 0, &actualSize);
5255 if (aeError == errAEDescNotFound) return (noErr);
5257 if (aeError == noErr) return (errAEParamMissed);
5264 * Apple Event Handler -- Open Application
5266 static pascal OSErr AEH_Start(const AppleEvent *theAppleEvent,
5267 AppleEvent *reply, long handlerRefCon)
5269 #pragma unused(reply, handlerRefCon)
5271 return (CheckRequiredAEParams(theAppleEvent));
5276 * Apple Event Handler -- Quit Application
5278 static pascal OSErr AEH_Quit(const AppleEvent *theAppleEvent,
5279 AppleEvent *reply, long handlerRefCon)
5281 #pragma unused(reply, handlerRefCon)
5282 #if TARGET_API_MAC_CARBON
5284 /* Save the game (if necessary) */
5285 if (game_in_progress && character_generated)
5289 plog("º£¤Ï¥»¡¼¥Ö¤¹¤ë¤³¤È¤Ï½ÐÍè¤Þ¤»¤ó¡£");
5291 plog("You may not do that right now.");
5295 /* Hack -- Forget messages */
5300 do_cmd_save_game(FALSE);
5302 Term_key_push(SPECIAL_KEY_QUIT);
5310 quit_when_ready = TRUE;
5312 /* Check arguments */
5313 return (CheckRequiredAEParams(theAppleEvent));
5319 * Apple Event Handler -- Print Documents
5321 static pascal OSErr AEH_Print(const AppleEvent *theAppleEvent,
5322 AppleEvent *reply, long handlerRefCon)
5324 #pragma unused(theAppleEvent, reply, handlerRefCon)
5326 return (errAEEventNotHandled);
5331 * Apple Event Handler by Steve Linberg (slinberg@crocker.com).
5333 * The old method of opening savefiles from the finder does not work
5334 * on the Power Macintosh, because CountAppFiles and GetAppFiles,
5335 * used to return information about the selected document files when
5336 * an application is launched, are part of the Segment Loader, which
5337 * is not present in the RISC OS due to the new memory architecture.
5339 * The "correct" way to do this is with AppleEvents. The following
5340 * code is modeled on the "Getting Files Selected from the Finder"
5341 * snippet from Think Reference 2.0. (The prior sentence could read
5342 * "shamelessly swiped & hacked")
5344 static pascal OSErr AEH_Open(const AppleEvent *theAppleEvent,
5345 AppleEvent* reply, long handlerRefCon)
5347 #pragma unused(reply, handlerRefCon)
5354 DescType returnedType;
5358 /* Put the direct parameter (a descriptor list) into a docList */
5359 err = AEGetParamDesc(theAppleEvent, keyDirectObject, typeAEList, &docList);
5360 if (err) return err;
5363 * We ignore the validity check, because we trust the FInder, and we only
5364 * allow one savefile to be opened, so we ignore the depth of the list.
5367 err = AEGetNthPtr(&docList, 1L, typeFSS, &keywd,
5368 &returnedType, (Ptr) &myFSS, sizeof(myFSS), &actualSize);
5369 if (err) return err;
5371 /* Only needed to check savefile type below */
5372 err = FSpGetFInfo(&myFSS, &myFileInfo);
5375 sprintf(foo, "Arg! FSpGetFInfo failed with code %d", err);
5380 /* Ignore non 'SAVE' files */
5381 if (myFileInfo.fdType != 'SAVE') return noErr;
5383 /* XXX XXX XXX Extract a file name */
5384 PathNameFromDirID(myFSS.parID, myFSS.vRefNum, (StringPtr)savefile);
5385 pstrcat((StringPtr)savefile, (StringPtr)&myFSS.name);
5387 /* Convert the string */
5388 ptocstr((StringPtr)savefile);
5390 /* Delay actual open */
5391 open_when_ready = TRUE;
5394 err = AEDisposeDesc(&docList);
5406 * Macintosh modifiers (event.modifier & ccc):
5407 * cmdKey, optionKey, shiftKey, alphaLock, controlKey
5410 * Macintosh Keycodes (0-63 normal, 64-95 keypad, 96-127 extra):
5455 * Optimize non-blocking calls to "CheckEvents()"
5456 * Idea from "Maarten Hazewinkel <mmhazewi@cs.ruu.nl>"
5458 #define EVENT_TICKS 6
5462 * Check for Events, return TRUE if we process any
5464 * Hack -- Handle AppleEvents if appropriate (ignore result code).
5466 static bool CheckEvents(bool wait)
5482 term_data *td = NULL;
5486 static huge lastTicks = 0L;
5489 /* Access the clock */
5490 curTicks = TickCount();
5492 /* Hack -- Allow efficient checking for non-pending events */
5493 if (!wait && (curTicks < lastTicks + EVENT_TICKS)) return (FALSE);
5495 /* Timestamp last check */
5496 lastTicks = curTicks;
5498 #if TARGET_API_MAC_CARBON
5499 WaitNextEvent( everyEvent, &event, 1L, nil );
5501 /* Let the "system" run */
5504 /* Get an event (or null) */
5505 GetNextEvent(everyEvent, &event);
5508 /* Hack -- Nothing is ready yet */
5509 if (event.what == nullEvent) return (FALSE);
5511 /* Analyze the event */
5519 w = (WindowPtr)event.message;
5530 /* Extract the window */
5531 w = (WindowPtr)event.message;
5533 /* Find the window */
5534 for (i = 0; i < MAX_TERM_DATA; i++)
5536 /* Skip dead windows */
5537 if (!data[i].t) continue;
5539 /* Notice matches */
5540 if (data[i].w == w) td = &data[i];
5543 /* Hack XXX XXX XXX */
5547 /* Redraw the window */
5548 if (td) term_data_redraw(td);
5556 /* Extract some modifiers */
5557 mc = (event.modifiers & controlKey) ? TRUE : FALSE;
5558 ms = (event.modifiers & shiftKey) ? TRUE : FALSE;
5559 mo = (event.modifiers & optionKey) ? TRUE : FALSE;
5560 mx = (event.modifiers & cmdKey) ? TRUE : FALSE;
5562 /* Keypress: (only "valid" if ck < 96) */
5563 ch = (event.message & charCodeMask) & 255;
5565 /* Keycode: see table above */
5566 ck = ((event.message & keyCodeMask) >> 8) & 255;
5568 /* Command + "normal key" -> menu action */
5569 if (mx && (ck < 64))
5571 /* Hack -- Prepare the menus */
5574 /* Run the Menu-Handler */
5577 /* Turn off the menus */
5585 /* Hide the mouse pointer */
5588 /* Normal key -> simple keypress */
5591 /* Enqueue the keypress */
5595 /* Bizarre key -> encoded keypress */
5598 /* Hack -- introduce with control-underscore */
5601 /* Send some modifier keys */
5602 if (mc) Term_keypress('C');
5603 if (ms) Term_keypress('S');
5604 if (mo) Term_keypress('O');
5605 if (mx) Term_keypress('X');
5607 /* Hack -- Downshift and encode the keycode */
5608 Term_keypress('0' + (ck - 64) / 10);
5609 Term_keypress('0' + (ck - 64) % 10);
5611 /* Hack -- Terminate the sequence */
5612 /* MPW can generate 10 or 13 for keycode of '\r' */
5613 /* -noMapCR option swaps '\r' and '\n' */
5614 Term_keypress('\r');
5624 /* Analyze click location */
5625 code = FindWindow(event.where, &w);
5627 /* Find the window */
5628 for (i = 0; i < MAX_TERM_DATA; i++)
5630 /* Skip dead windows */
5631 if (!data[i].t) continue;
5633 /* Notice matches */
5634 if (data[i].w == w) td = &data[i];
5643 menu(MenuSelect(event.where));
5647 #if !TARGET_API_MAC_CARBON
5650 SystemClick(&event, w);
5662 #if TARGET_API_MAC_CARBON
5663 GetQDGlobalsScreenBits( &screen );
5665 screen = qd.screenBits;
5668 r.top += 20; /* GetMBarHeight() XXX XXX XXX */
5669 InsetRect(&r, 4, 4);
5670 DragWindow(w, event.where, &r);
5682 #if TARGET_API_MAC_CARBON
5683 GetWindowBounds( (WindowRef)td->w, kWindowContentRgn, &portRect );
5685 portRect = td->w->portRect;
5686 local_to_global( &portRect );
5688 p.h = portRect.left;
5690 #if !TARGET_API_MAC_CARBON
5699 /* Apply and Verify */
5700 term_data_check_size(td);
5710 /* Track the go-away box */
5711 if (TrackGoAway(w, event.where))
5717 td->t->mapped_flag = FALSE;
5719 /* Hide the window */
5733 #if TARGET_API_MAC_CARBON
5734 GetQDGlobalsScreenBits( &screen );
5736 screen = qd.screenBits;
5741 /* Fake rectangle */
5742 r.left = 20 * td->tile_wid + td->size_ow1;
5743 r.right = screen.bounds.right;
5744 r.top = 1 * td->tile_hgt + td->size_oh1;
5745 r.bottom = screen.bounds.bottom;
5747 /* Grow the rectangle */
5748 newsize = GrowWindow(w, event.where, &r);
5751 if (!newsize) break;
5753 /* Extract the new size in pixels */
5754 y = HiWord(newsize) - td->size_oh1 - td->size_oh2;
5755 x = LoWord(newsize) - td->size_ow1 - td->size_ow2;
5757 /* Extract a "close" approximation */
5758 td->rows = y / td->tile_hgt;
5759 td->cols = x / td->tile_wid;
5761 /* Apply and Verify */
5762 term_data_check_size(td);
5764 Term_activate(td->t);
5766 /* Hack -- Resize the term */
5767 Term_resize(td->cols, td->rows);
5769 /* Resize and Redraw */
5770 term_data_resize(td);
5771 term_data_redraw(td);
5790 /* Disk Event -- From "Maarten Hazewinkel" */
5794 #if TARGET_API_MAC_CARBON
5796 /* check for error when mounting the disk */
5797 if (HiWord(event.message) != noErr)
5803 DIBadMount(p, event.message);
5810 /* OS Event -- From "Maarten Hazewinkel" */
5813 switch ((event.message >> 24) & 0x000000FF)
5815 case suspendResumeMessage:
5817 /* Resuming: activate the front window */
5818 if (event.message & resumeFlag)
5820 #if TARGET_API_MAC_CARBON
5823 SetPortWindowPort( FrontWindow() );
5825 GetQDGlobalsArrow( &arrow );
5828 SetPort(FrontWindow());
5829 SetCursor(&qd.arrow);
5833 /* Suspend: deactivate the front window */
5847 /* From "Steve Linberg" and "Maarten Hazewinkel" */
5848 case kHighLevelEvent:
5850 #if TARGET_API_MAC_CARBON
5851 AEProcessAppleEvent(&event);
5853 /* Process apple events */
5854 if (AEProcessAppleEvent(&event) != noErr)
5857 plog("Apple Event Handler¤Î¥¨¥é¡¼¤Ç¤¹.");
5859 plog("Error in Apple Event Handler!");
5863 /* Handle "quit_when_ready" */
5864 if (quit_when_ready)
5867 quit_when_ready = FALSE;
5869 /* Do the menu key */
5872 /* Turn off the menus */
5876 /* Handle "open_when_ready" */
5877 handle_open_when_ready();
5888 /* Something happened */
5895 /*** Some Hooks for various routines ***/
5899 * Mega-Hack -- emergency lifeboat
5901 static vptr lifeboat = NULL;
5905 * Hook to "release" memory
5907 static vptr hook_rnfree(vptr v, huge size)
5910 #pragma unused (size)
5914 /* Alternative method */
5929 * Hook to "allocate" memory
5931 static vptr hook_ralloc(huge size)
5936 /* Make a new pointer */
5937 return (malloc(size));
5941 /* Make a new pointer */
5942 return (NewPtr(size));
5949 * Hook to handle "out of memory" errors
5951 static vptr hook_rpanic(huge size)
5954 #pragma unused (size)
5958 /* Free the lifeboat */
5961 /* Free the lifeboat */
5962 DisposePtr(lifeboat);
5964 /* Forget the lifeboat */
5967 /* Mega-Hack -- Warning */
5969 mac_warning("¥á¥â¥ê¡¼¤¬Â¤ê¤Þ¤»¤ó!\rº£¤¹¤°½ªÎ»¤·¤Æ²¼¤µ¤¤!");
5971 mac_warning("Running out of Memory!\rAbort this process now!");
5974 /* Mega-Hack -- Never leave this function */
5975 while (TRUE) CheckEvents(TRUE);
5978 /* Mega-Hack -- Crash */
5984 * Hook to tell the user something important
5986 static void hook_plog(cptr str)
5988 /* Warning message */
5993 * Hook to tell the user something, and then quit
5995 static void hook_quit(cptr str)
5997 /* Warning if needed */
5998 if (str) mac_warning(str);
6000 /* Write a preference file */
6008 * Hook to tell the user something, and then crash
6010 static void hook_core(cptr str)
6012 /* XXX Use the debugger */
6013 /* DebugStr(str); */
6016 if (str) mac_warning(str);
6018 /* Warn, then save player */
6020 mac_warning("Ã×̿Ū¤Ê¥¨¥é¡¼¤Ç¤¹.\r¶¯À©Åª¤Ë¥»¡¼¥Ö¤·¤Æ½ªÎ»¤·¤Þ¤¹.");
6022 mac_warning("Fatal error.\rI will now attempt to save and quit.");
6025 /* Attempt to save */
6027 if (!save_player()) mac_warning("·Ù¹ð -- ¥»¡¼¥Ö¤Ë¼ºÇÔ¤·¤Þ¤·¤¿!");
6029 if (!save_player()) mac_warning("Warning -- save failed!");
6038 /*** Main program ***/
6044 * XXX XXX XXX Hack -- This function attempts to "fix" the nasty
6045 * "Macintosh Save Bug" by using "absolute" path names, since on
6046 * System 7 machines anyway, the "current working directory" often
6047 * "changes" due to background processes, invalidating any "relative"
6048 * path names. Note that the Macintosh is limited to 255 character
6049 * path names, so be careful about deeply embedded directories...
6051 * XXX XXX XXX Hack -- This function attempts to "fix" the nasty
6052 * "missing lib folder bug" by allowing the user to help find the
6053 * "lib" folder by hand if the "application folder" code fails...
6055 static void init_stuff(void)
6074 #if TARGET_API_MAC_CARBON
6076 NavDialogOptions dialogOptions;
6077 FSSpec theFolderSpec;
6078 NavReplyRecord theReply;
6080 /* Fake rectangle */
6087 #if TARGET_API_MAC_CARBON
6088 screenRect = GetQDGlobalsScreenBits(&screen)->bounds;
6090 screenRect = qd.screenBits.bounds;
6092 center_rect(&r, &screenRect);
6094 /* Extract corner */
6099 /* Default to the "lib" folder with the application */
6100 refnum_to_name(path, app_dir, app_vol, (char*)("\plib:"));
6103 /* Check until done */
6106 /* Prepare the paths */
6107 init_file_paths(path);
6109 /* Build the filename */
6111 path_build(path, sizeof(path), ANGBAND_DIR_FILE, "news_j.txt");
6113 path_build(path, sizeof(path), ANGBAND_DIR_FILE, "news.txt");
6116 /* Attempt to open and close that file */
6117 if (0 == fd_close(fd_open(path, O_RDONLY))) break;
6121 plog_fmt("'%s' ¥Õ¥¡¥¤¥ë¤ò¥ª¡¼¥×¥ó½ÐÍè¤Þ¤»¤ó.", path);
6123 plog_fmt("Unable to open the '%s' file.", path);
6128 plog("Hengband¤Î'lib'¥Õ¥©¥ë¥À¤¬Â¸ºß¤·¤Ê¤¤¤«Àµ¤·¤¯Ìµ¤¤²ÄǽÀ¤¬¤¢¤ê¤Þ¤¹.");
6130 plog("The Angband 'lib' folder is probably missing or misplaced.");
6135 plog("Please 'open' any file in any sub-folder of the 'lib' folder.");
6137 plog("Please 'open' any file in any sub-folder of the 'lib' folder.");
6140 #if TARGET_API_MAC_CARBON
6141 /* Ask the user to choose the lib folder */
6142 err = NavGetDefaultDialogOptions(&dialogOptions);
6145 if (err != noErr) quit(NULL);
6147 /* Set default location option */
6148 dialogOptions.dialogOptionFlags |= kNavSelectDefaultLocation;
6150 /* Clear preview option */
6151 dialogOptions.dialogOptionFlags &= ~(kNavAllowPreviews);
6153 /* Forbit selection of multiple files */
6154 dialogOptions.dialogOptionFlags &= ~(kNavAllowMultipleFiles);
6156 /* Display location */
6157 dialogOptions.location = topleft;
6159 /* Load the message for the missing folder from the resource fork */
6160 GetIndString(dialogOptions.message, 128, 1);
6162 /* Wait for the user to choose a folder */
6163 err = NavChooseFolder(
6171 /* Assume the player doesn't want to go on */
6172 if ((err != noErr) || !theReply.validRecord) quit(NULL);
6174 /* Retrieve FSSpec from the reply */
6176 AEKeyword theKeyword;
6177 DescType actualType;
6180 /* Get a pointer to selected folder */
6182 &(theReply.selection),
6192 if (err != noErr) quit(NULL);
6195 /* Free navitagor reply */
6196 err = NavDisposeReply(&theReply);
6199 if (err != noErr) quit(NULL);
6201 /* Extract textual file name for given file */
6204 theFolderSpec.parID,
6205 theFolderSpec.vRefNum,
6206 (char *)theFolderSpec.name);
6208 /* Allow "text" files */
6211 /* Allow "save" files */
6214 /* Allow "data" files */
6218 SFGetFile(topleft, "\p", NULL, 3, types, NULL, &reply);
6221 if (!reply.good) quit(NULL);
6223 /* Extract textual file name for given file */
6224 GetWDInfo(reply.vRefNum, &vrefnum, &drefnum, &junk);
6225 refnum_to_name(path, drefnum, vrefnum, (char*)reply.fName);
6228 /* Hack -- Remove the "filename" */
6229 i = strlen(path) - 1;
6230 while ((i > 0) && (path[i] != ':')) i--;
6231 if (path[i] == ':') path[i+1] = '\0';
6233 /* Hack -- allow "lib" folders */
6234 if (suffix(path, "lib:")) continue;
6236 /* Hack -- Remove the "sub-folder" */
6238 while ((i > 1) && (path[i] != ':')) i--;
6239 if (path[i] == ':') path[i+1] = '\0';
6245 * Macintosh Main loop
6249 EventRecord tempEvent;
6250 int numberOfMasters = 10;
6252 #if !TARGET_API_MAC_CARBON
6253 /* Increase stack space by 64K */
6254 SetApplLimit(GetApplLimit() - 131072L);//65536L);
6256 /* Stretch out the heap to full size */
6260 /* Get more Masters */
6261 while (numberOfMasters--) MoreMasters();
6263 #if !TARGET_API_MAC_CARBON
6264 /* Set up the Macintosh */
6265 InitGraf(&qd.thePort);
6279 FlushEvents(everyEvent, 0);
6281 /* Flush events some more (?) */
6282 (void)EventAvail(everyEvent, &tempEvent);
6283 (void)EventAvail(everyEvent, &tempEvent);
6284 (void)EventAvail(everyEvent, &tempEvent);
6287 #ifdef ANGBAND_LITE_MAC
6291 #else /* ANGBAND_LITE_MAC */
6293 # if defined(powerc) || defined(__powerc)
6295 /* Assume System 7 */
6297 /* Assume Color Quickdraw */
6307 /* Check the Gestalt */
6308 err = Gestalt(gestaltSystemVersion, &versionNumber);
6310 /* Check the version */
6311 if ((err != noErr) || (versionNumber < 0x0700))
6314 quit("¤³¤Î¥×¥í¥°¥é¥à¤Ï´Á»úTalk7.x.x°Ê¹ß¤ÇÆ°ºî¤·¤Þ¤¹.");
6316 quit("You must have System 7 to use this program.");
6326 /* Check the environs */
6327 if (SysEnvirons(1, &env) != noErr)
6330 quit("SysEnvirons ¥³¡¼¥ë¤Ï¼ºÇÔ¤·¤Þ¤·¤¿¡ª");
6332 quit("The SysEnvirons call failed!");
6336 /* Check for System Seven Stuff */
6337 if (env.systemVersion < 0x0700)
6340 quit("¤³¤Î¥×¥í¥°¥é¥à¤Ï´Á»úTalk7.x.x°Ê¹ß¤ÇÆ°ºî¤·¤Þ¤¹.");
6342 quit("You must have System 7 to use this program.");
6346 /* Check for Color Quickdraw */
6347 if (!env.hasColorQD)
6350 quit("¤³¤Î¥×¥í¥°¥é¥à¤ÏColor Quickdraw¤¬Ìµ¤¤¤ÈÆ°ºî¤·¤Þ¤»¤ó.");
6352 quit("You must have Color Quickdraw to use this program.");
6359 #endif /* ANGBAND_LITE_MAC */
6362 * Remember Mac OS version, in case we have to cope with version-specific
6365 (void)Gestalt(gestaltSystemVersion, &mac_os_version);
6368 /* Obtain a "Universal Procedure Pointer" */
6369 AEH_Start_UPP = NewAEEventHandlerUPP(AEH_Start);
6370 /* Install the hook (ignore error codes) */
6371 AEInstallEventHandler(kCoreEventClass, kAEOpenApplication, AEH_Start_UPP,
6374 /* Obtain a "Universal Procedure Pointer" */
6375 AEH_Quit_UPP = NewAEEventHandlerUPP(AEH_Quit);
6376 /* Install the hook (ignore error codes) */
6377 AEInstallEventHandler(kCoreEventClass, kAEQuitApplication, AEH_Quit_UPP,
6380 /* Obtain a "Universal Procedure Pointer" */
6381 AEH_Print_UPP = NewAEEventHandlerUPP(AEH_Print);
6382 /* Install the hook (ignore error codes) */
6383 AEInstallEventHandler(kCoreEventClass, kAEPrintDocuments, AEH_Print_UPP,
6386 /* Obtain a "Universal Procedure Pointer" */
6387 AEH_Open_UPP = NewAEEventHandlerUPP(AEH_Open);
6388 /* Install the hook (ignore error codes) */
6389 AEInstallEventHandler(kCoreEventClass, kAEOpenDocuments, AEH_Open_UPP,
6393 /* Find the current application */
6397 /* Mark ourself as the file creator */
6398 _fcreator = ANGBAND_CREATOR;
6400 /* Default to saving a "text" file */
6404 #if defined(__MWERKS__)
6406 /* Obtian a "Universal Procedure Pointer" */
6407 #if TARGET_API_MAC_CARBON
6408 ynfilterUPP = NewModalFilterUPP(ynfilter);
6410 ynfilterUPP = NewModalFilterProc(ynfilter);
6416 /* Hook in some "z-virt.c" hooks */
6417 rnfree_aux = hook_rnfree;
6418 ralloc_aux = hook_ralloc;
6419 rpanic_aux = hook_rpanic;
6421 /* Hooks in some "z-util.c" hooks */
6422 plog_aux = hook_plog;
6423 quit_aux = hook_quit;
6424 core_aux = hook_core;
6426 BackColor(blackColor);
6427 ForeColor(whiteColor);
6429 /* Show the "watch" cursor */
6430 SetCursor(*(GetCursor(watchCursor)));
6432 /* Prepare the menubar */
6435 /* Prepare the windows */
6442 /* Hack -- process all events */
6443 while (CheckEvents(TRUE)) /* loop */;
6445 /* Reset the cursor */
6446 #if TARGET_API_MAC_CARBON
6449 GetQDGlobalsArrow( &arrow );
6453 SetCursor( &qd.arrow );
6457 /* Mega-Hack -- Allocate a "lifeboat" */
6458 lifeboat = NewPtr(16384);
6460 /* Note the "system" */
6461 ANGBAND_SYS = "mac";
6466 /* Catch nasty signals */
6473 /* Hack -- process all events */
6474 while (CheckEvents(TRUE)) /* loop */;
6477 /* We are now initialized */
6481 /* Handle "open_when_ready" */
6482 handle_open_when_ready();
6488 /* Prompt the user */
6490 prt("'¥Õ¥¡¥¤¥ë'¥á¥Ë¥å¡¼¤è¤ê'¿·µ¬'¤Þ¤¿¤Ï'³«¤¯...'¤òÁªÂò¤·¤Æ¤¯¤À¤µ¤¤¡£", 23, 10);
6492 prt("[Choose 'New' or 'Open' from the 'File' menu]", 23, 15);
6495 /* Flush the prompt */
6499 /* Hack -- Process Events Forever */
6500 while (TRUE) CheckEvents(TRUE);