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 <Carbon/Carbon.h>
140 #include <QuickTime/QuickTime.h>
141 #include <CoreServices/CoreServices.h>
142 #include <CoreFoundation/CoreFoundation.h>
144 #define TARGET_API_MAC_CARBON 1
146 #else /* MACH_O_CARBON */
150 #include <QuickDraw.h>
156 #include <Palettes.h>
157 #include <StandardFile.h>
158 #include <DiskInit.h>
159 #include <ToolUtils.h>
162 #include <Resources.h>
163 #include <Controls.h>
166 #include <QDOffscreen.h>
168 #if TARGET_API_MAC_CARBON
169 #include <Navigation.h>
170 #include <CFPreferences.h>
171 #include <CFNumber.h>
173 # include <CarbonStdCLib.h>
183 #endif /* MACH_O_CARBON */
186 * Cleaning up a couple of things to make these easier to change --AR
189 #define PREF_FILE_NAME "Hengband Preferences"
191 #define PREF_FILE_NAME "Hengband-E Preferences"
195 * Use "malloc()" instead of "NewPtr()"
197 /* #define USE_MALLOC */
200 /* Default creator signature */
201 #ifndef ANGBAND_CREATOR
202 # define ANGBAND_CREATOR 'Heng'
206 #if defined(powerc) || defined(__powerc)
209 * Disable "LITE" version
211 # undef ANGBAND_LITE_MAC
216 #ifdef ANGBAND_LITE_MAC
219 * Maximum number of windows
221 # define MAX_TERM_DATA 1
223 #else /* ANGBAND_LITE_MAC */
226 * Maximum number of windows
228 # define MAX_TERM_DATA 8
231 * Activate some special code
233 # define USE_SFL_CODE
236 * Use rewritten asynchronous sound player
238 #define USE_ASYNC_SOUND
245 #endif /* MACH_O_CARBON */
246 #endif /* ANGBAND_LITE_MAC */
250 #ifndef MACH_O_CARBON
254 * Include the necessary header files
256 #include <AppleEvents.h>
261 #endif /* !MACH_O_CARBON */
264 * Globals for MPW compilation
266 #if defined(MACH_O_CARBON) || defined(MAC_MPW)
268 #if !TARGET_API_MAC_CARBON
280 * The Angband Color Set (0 to 15):
281 * Black, White, Slate, Orange, Red, Blue, Green, Umber
282 * D-Gray, L-Gray, Violet, Yellow, L-Red, L-Blue, L-Green, L-Umber
284 * Colors 8 to 15 are basically "enhanced" versions of Colors 0 to 7.
286 * On the Macintosh, we use color quickdraw, and we use actual "RGB"
287 * values below to choose the 16 colors.
289 * If we are compiled for ancient machines, we bypass color and simply
290 * draw everything in white (letting "z-term.c" automatically convert
291 * "black" into "wipe" calls).
293 static RGBColor foo[16] =
295 {0x0000, 0x0000, 0x0000}, /* TERM_DARK */
296 {0xFFFF, 0xFFFF, 0xFFFF}, /* TERM_WHITE */
297 {0x8080, 0x8080, 0x8080}, /* TERM_SLATE */
298 {0xFFFF, 0x8080, 0x0000}, /* TERM_ORANGE */
299 {0xC0C0, 0x0000, 0x0000}, /* TERM_RED */
300 {0x0000, 0x8080, 0x4040}, /* TERM_GREEN */
301 {0x0000, 0x0000, 0xFFFF}, /* TERM_BLUE */
302 {0x8080, 0x4040, 0x0000}, /* TERM_UMBER */
303 {0x4040, 0x4040, 0x4040}, /* TERM_L_DARK */
304 {0xC0C0, 0xC0C0, 0xC0C0}, /* TERM_L_WHITE */
305 {0xFFFF, 0x0000, 0xFFFF}, /* TERM_VIOLET */
306 {0xFFFF, 0xFFFF, 0x0000}, /* TERM_YELLOW */
307 {0xFFFF, 0x0000, 0x0000}, /* TERM_L_RED */
308 {0x0000, 0xFFFF, 0x0000}, /* TERM_L_GREEN */
309 {0x0000, 0xFFFF, 0xFFFF}, /* TERM_L_BLUE */
310 {0xC0C0, 0x8080, 0x4040} /* TERM_L_UMBER */
319 typedef struct term_data term_data;
332 #ifdef ANGBAND_LITE_MAC
336 #else /* ANGBAND_LITE_MAC */
348 #endif /* ANGBAND_LITE_MAC */
391 * Forward declare -- see below
393 static bool CheckEvents(bool wait);
395 #ifndef MACH_O_CARBON
398 * Hack -- location of the main directory
400 static short app_vol;
403 #endif /* !MACH_O_CARBON */
406 * Delay handling of double-clicked savefiles
408 Boolean open_when_ready = FALSE;
411 * Delay handling of pre-emptive "quit" event
413 Boolean quit_when_ready = FALSE;
417 * Hack -- game in progress
419 static int game_in_progress = 0;
423 * Only do "SetPort()" when needed
425 static WindowPtr active = NULL;
430 * An array of term_data's
432 static term_data data[MAX_TERM_DATA];
437 * Note when "open"/"new" become valid
439 static bool initialized = FALSE;
442 * Version of Mac OS - for version specific bug workarounds (; ;)
444 static long mac_os_version;
447 #if defined(__MWERKS__)
449 * CodeWarrior uses Universal Procedure Pointers
451 static ModalFilterUPP ynfilterUPP;
453 #endif /* __MWERKS__ */
460 AEEventHandlerUPP AEH_Start_UPP;
461 AEEventHandlerUPP AEH_Quit_UPP;
462 AEEventHandlerUPP AEH_Print_UPP;
463 AEEventHandlerUPP AEH_Open_UPP;
468 * Convert refnum+vrefnum+fname into a full file name
469 * Store this filename in 'buf' (make sure it is long enough)
470 * Note that 'fname' looks to be a "pascal" string
472 #if TARGET_API_MAC_CARBON
473 static void refnum_to_name(char *buf, long refnum, short vrefnum, char *fname)
488 for (j=1; j<=fname[0]; j++)
490 res[i-fname[0]+j] = fname[j];
499 pb.dirInfo.ioDrDirID=pb.dirInfo.ioDrParID;
500 err = FSMakeFSSpec( vref, dirID, "\p", &spec );
506 for (j=1; j<=spec.name[0]; j++)
508 res[i-spec.name[0]+j] = spec.name[j];
515 /* Extract the result */
516 for (j = 0, i++; res[i]; j++, i++) buf[j] = res[i];
520 static void refnum_to_name(char *buf, long refnum, short vrefnum, char *fname)
532 for (j=1; j<=fname[0]; j++)
534 res[i-fname[0]+j] = fname[j];
538 pb.ioCompletion=NULL;
540 pb.ioVRefNum=vrefnum;
546 pb.ioDrDirID=pb.ioDrParID;
547 err = PBGetCatInfo((CInfoPBPtr)&pb, FALSE);
549 for (j=1; j<=name[0]; j++)
551 res[i-name[0]+j] = name[j];
555 if (pb.ioDrDirID == fsRtDirID) break;
558 /* Extract the result */
559 for (j = 0, i++; res[i]; j++, i++) buf[j] = res[i];
564 #if TARGET_API_MAC_CARBON
565 pascal OSErr FSpLocationFromFullPath(short fullPathLength,
566 const void *fullPath,
574 /* Create a minimal alias from the full pathname */
575 nullString[0] = 0; /* null string to indicate no zone or server name */
576 result = NewAliasMinimalFromFullPath(fullPathLength, fullPath, nullString, nullString, &alias);
577 if ( result == noErr )
579 /* Let the Alias Manager resolve the alias. */
580 result = ResolveAlias(NULL, alias, spec, &wasChanged);
582 /* work around Alias Mgr sloppy volume matching bug */
583 if ( spec->vRefNum == 0 )
585 /* invalidate wrong FSSpec */
590 DisposeHandle((Handle)alias); /* Free up memory used */
599 * XXX XXX XXX Allow the system to ask us for a filename
601 static bool askfor_file(char *buf, int len)
609 /* Default file name */
610 sprintf((char*)dflt + 1, "%s's description", buf);
611 dflt[0] = strlen((char*)dflt + 1);
613 /* Ask for a file name */
614 topleft.h=(qd.screenBits.bounds.left+qd.screenBits.bounds.right)/2-344/2;
615 topleft.v=(2*qd.screenBits.bounds.top+qd.screenBits.bounds.bottom)/3-188/2;
616 SFPutFile(topleft, "\pSelect a filename:", dflt, NULL, &reply);
617 /* StandardPutFile("\pSelect a filename:", dflt, &reply); */
625 GetWDInfo(reply.vRefNum, &vrefnum, &drefnum, &junk);
627 /* Extract the name */
628 refnum_to_name(buf, drefnum, vrefnum, (char*)reply.fName);
640 #if !TARGET_API_MAC_CARBON
641 static void local_to_global( Rect *r )
648 LocalToGlobal( &temp );
656 LocalToGlobal( &temp );
661 #endif /* !TARGET_API_MAC_CARBON */
663 static void global_to_local( Rect *r )
670 GlobalToLocal( &temp );
678 GlobalToLocal( &temp );
688 * Convert pathname to an appropriate format, because MPW's
689 * CarbonStdCLib chose to use system's native path format,
690 * making our lives harder to create binaries that run on
691 * OS 8/9 and OS X :( -- pelpel
693 void convert_pathname(char* path)
697 /* Nothing has to be done for CarbonLib on Classic */
698 if (mac_os_version >= 0x1000)
700 /* Convert to POSIX style */
701 ConvertHFSPathToUnixPath(path, buf);
703 /* Copy the result back */
711 # ifdef CHECK_MODIFICATION_TIME
714 * Although there is no easy way to emulate fstat in the old interface,
715 * we still can do stat-like things, because Mac OS is an OS.
717 static int get_modification_time(cptr path, u32b *mod_time)
723 /* Paranoia - make sure the pathname fits in Str255 */
725 if (i > 255) return (-1);
727 /* Convert pathname to a Pascal string */
728 strncpy((char *)pathname + 1, path, 255);
731 /* Set up parameter block */
732 pb.hFileInfo.ioNamePtr = pathname;
733 pb.hFileInfo.ioFDirIndex = 0;
734 pb.hFileInfo.ioVRefNum = app_vol;
735 pb.hFileInfo.ioDirID = 0;
737 /* Get catalog information of the file */
738 if (PBGetCatInfoSync(&pb) != noErr) return (-1);
740 /* Set modification date and time */
741 *mod_time = pb.hFileInfo.ioFlMdDat;
749 * A (non-Mach-O) Mac OS version of check_modification_time, for those
750 * compilers without good enough POSIX-compatibility libraries XXX XXX
752 errr check_modification_date(int fd, cptr template_file)
755 u32b txt_stat, raw_stat;
760 /* Build the file name */
761 path_build(buf, sizeof(buf), ANGBAND_DIR_EDIT, template_file);
764 convert_pathname(buf);
766 /* Obtain modification time */
767 if (get_modification_time(buf, &txt_stat)) return (-1);
769 /* XXX Build filename of the corresponding *.raw file */
770 strnfmt(fname, sizeof(fname), "%s", template_file);
773 p = strrchr(fname, '.');
776 if (p == NULL) return (-1);
778 /* Substitute ".raw" for ".txt" */
781 /* Build the file name of the raw file */
782 path_build(buf, sizeof(buf), ANGBAND_DIR_DATA, fname);
785 convert_pathname(buf);
787 /* Obtain modification time */
788 if (get_modification_time(buf, &raw_stat)) return (-1);
790 /* Ensure the text file is not newer than the raw file */
791 if (txt_stat > raw_stat) return (-1);
793 /* Keep using the current .raw file */
797 # endif /* CHECK_MODIFICATION_TIME */
802 * Center a rectangle inside another rectangle
804 static void center_rect(Rect *r, Rect *s)
806 int centerx = (s->left + s->right)/2;
807 int centery = (2*s->top + s->bottom)/3;
808 int dx = centerx - (r->right - r->left)/2 - r->left;
809 int dy = centery - (r->bottom - r->top)/2 - r->top;
819 /* Carbon File Manager utilities by pelpel */
823 * Convert a pathname to a corresponding FSSpec.
824 * Returns noErr on success.
826 static OSErr path_to_spec(const char *path, FSSpec *spec)
831 /* Convert pathname to FSRef ... */
832 err = FSPathMakeRef(path, &ref, NULL);
833 if (err != noErr) return (err);
835 /* ... then FSRef to FSSpec */
836 err = FSGetCatalogInfo(&ref, kFSCatInfoNone, NULL, NULL, spec, NULL);
838 /* Inform caller of success or failure */
845 * Convert a FSSpec to a corresponding pathname.
846 * Returns noErr on success.
848 static OSErr spec_to_path(const FSSpec *spec, char *buf, size_t size)
853 /* Convert FSSpec to FSRef ... */
854 err = FSpMakeFSRef(spec, &ref);
855 if (err != noErr) return (err);
857 /* ... then FSRef to pathname */
858 err = FSRefMakePath(&ref, buf, size);
860 /* Inform caller of success or failure */
866 * (Carbon) [via path_to_spec]
867 * Set creator and filetype of a file specified by POSIX-style pathname.
868 * Returns 0 on success, -1 in case of errors.
870 void fsetfileinfo(cptr pathname, OSType fcreator, OSType ftype)
876 /* Convert pathname to FSSpec */
877 if (path_to_spec(pathname, &spec) != noErr) return;
879 /* Obtain current finder info of the file */
880 if (FSpGetFInfo(&spec, &info) != noErr) return;
882 /* Overwrite creator and type */
883 info.fdCreator = fcreator;
885 err = FSpSetFInfo(&spec, &info);
892 #else /* MACH_O_CARBON */
896 * Convert a pascal string in place
898 * This function may be defined elsewhere, but since it is so
899 * small, it is not worth finding the proper function name for
900 * all the different platforms.
902 static void ptocstr(StringPtr src)
906 /* Hack -- pointer */
907 char *s = (char*)(src);
909 /* Hack -- convert the string */
910 for (i = s[0]; i; i--, s++) s[0] = s[1];
912 /* Hack -- terminate the string */
917 #if defined(USE_SFL_CODE)
921 * The following three routines (pstrcat, pstrinsert, and PathNameFromDirID)
922 * were taken from the Think Reference section called "Getting a Full Pathname"
923 * (under the File Manager section). We need PathNameFromDirID to get the
924 * full pathname of the opened savefile, making no assumptions about where it
927 * I had to hack PathNameFromDirID a little for MetroWerks, but it's awfully
930 static void pstrcat(StringPtr dst, StringPtr src)
933 BlockMove(src + 1, dst + *dst + 1, *src);
935 /* adjust length byte */
940 * pstrinsert - insert string 'src' at beginning of string 'dst'
942 static void pstrinsert(StringPtr dst, StringPtr src)
944 /* make room for new string */
945 BlockMove(dst + 1, dst + *src + 1, *dst);
947 /* copy new string in */
948 BlockMove(src + 1, dst + 1, *src);
950 /* adjust length byte */
954 static void PathNameFromDirID(long dirID, short vRefNum, StringPtr fullPathName)
957 Str255 directoryName;
960 fullPathName[0] = '\0';
962 block.dirInfo.ioDrParID = dirID;
963 block.dirInfo.ioNamePtr = directoryName;
967 block.dirInfo.ioVRefNum = vRefNum;
968 block.dirInfo.ioFDirIndex = -1;
969 block.dirInfo.ioDrDirID = block.dirInfo.ioDrParID;
970 err = PBGetCatInfo(&block, FALSE);
971 pstrcat(directoryName, (StringPtr)"\p:");
972 pstrinsert(fullPathName, directoryName);
973 if (block.dirInfo.ioDrDirID == 2) break;
978 #endif /* MACH_O_CARBON */
981 * Activate a given window, if necessary
983 static void activate(WindowPtr w)
989 #if TARGET_API_MAC_CARBON
990 if (w) SetPortWindowPort(w);
1002 * Display a warning message
1004 static void mac_warning(cptr warning)
1009 /* Limit of 250 chars */
1010 len = strlen(warning);
1011 if (len > 250) len = 250;
1013 /* Make a "Pascal" string */
1015 for (i=0; i<len; i++) text[i+1] = warning[i];
1017 /* Prepare the dialog box values */
1018 ParamText(text, "\p", "\p", "\p");
1020 /* Display the Alert, wait for Okay */
1026 /*** Some generic functions ***/
1029 #ifdef ANGBAND_LITE_MAC
1032 * Hack -- activate a color (0 to 255)
1034 #define term_data_color(TD,A) /* Nothing */
1036 #else /* ANGBAND_LITE_MAC */
1039 * Hack -- activate a color (0 to 255)
1041 static void term_data_color(term_data *td, int a)
1047 /* Extract the R,G,B data */
1048 rv = angband_color_table[a][1];
1049 gv = angband_color_table[a][2];
1050 bv = angband_color_table[a][3];
1053 color.red = (rv | (rv << 8));
1054 color.green = (gv | (gv << 8));
1055 color.blue = (bv | (bv << 8));
1057 /* Activate the color */
1058 RGBForeColor(&color);
1060 /* Memorize color */
1064 #endif /* ANGBAND_LITE_MAC */
1068 * Hack -- Apply and Verify the "font" info
1070 * This should usually be followed by "term_data_check_size()"
1072 static void term_data_check_font(term_data *td)
1078 WindowPtr old = active;
1084 /* Instantiate font */
1085 TextFont(td->font_id);
1086 TextSize(td->font_size);
1087 TextFace(td->font_face);
1089 /* Extract the font info */
1092 /* Assume monospaced */
1093 td->font_mono = TRUE;
1095 /* Extract the font sizing values XXX XXX XXX */
1096 td->font_wid = CharWidth('@'); /* info.widMax; */
1097 td->font_hgt = info.ascent + info.descent;
1099 td->font_o_y = info.ascent;
1101 /* Check important characters */
1102 for (i = 33; i < 127; i++)
1104 /* Hack -- notice non-mono-space */
1105 if (td->font_wid != CharWidth(i)) td->font_mono = FALSE;
1107 /* Hack -- collect largest width */
1108 if (td->font_wid < CharWidth(i)) td->font_wid = CharWidth(i);
1111 /* Set default offsets */
1112 td->tile_o_x = td->font_o_x;
1113 td->tile_o_y = td->font_o_y;
1115 /* Set default tile size */
1116 if( td->tile_wid == 0 && td->tile_hgt == 0 ){
1117 td->tile_wid = td->font_wid;
1118 td->tile_hgt = td->font_hgt;
1121 /* Re-activate the old window */
1127 * Hack -- Apply and Verify the "size" info
1129 static void term_data_check_size(term_data *td)
1133 #if TARGET_API_MAC_CARBON
1134 GetQDGlobalsScreenBits( &screen );
1136 screen = qd.screenBits;
1138 /* Minimal window size */
1141 /* Enforce minimal size */
1142 if (td->cols < 80) td->cols = 80;
1143 if (td->rows < 24) td->rows = 24;
1146 /* Allow small windows for the rest */
1149 if (td->cols < 1) td->cols = 1;
1150 if (td->rows < 1) td->rows = 1;
1153 /* Minimal tile size */
1154 if (td->tile_wid < 4) td->tile_wid = 4;
1155 if (td->tile_hgt < 4) td->tile_hgt = 4;
1157 /* Default tile offsets */
1158 td->tile_o_x = (td->tile_wid - td->font_wid) / 2;
1159 td->tile_o_y = (td->tile_hgt - td->font_hgt) / 2;
1161 /* Minimal tile offsets */
1162 if (td->tile_o_x < 0) td->tile_o_x = 0;
1163 if (td->tile_o_y < 0) td->tile_o_y = 0;
1165 /* Apply font offsets */
1166 td->tile_o_x += td->font_o_x;
1167 td->tile_o_y += td->font_o_y;
1169 /* Calculate full window size */
1170 td->size_wid = td->cols * td->tile_wid + td->size_ow1 + td->size_ow2;
1171 td->size_hgt = td->rows * td->tile_hgt + td->size_oh1 + td->size_oh2;
1173 /* Verify the top */
1174 if (td->r.top > screen.bounds.bottom - td->size_hgt)
1176 td->r.top = screen.bounds.bottom - td->size_hgt;
1179 /* Verify the top */
1180 if (td->r.top < screen.bounds.top + 30)
1182 td->r.top = screen.bounds.top + 30;
1185 /* Verify the left */
1186 if (td->r.left > screen.bounds.right - td->size_wid)
1188 td->r.left = screen.bounds.right - td->size_wid;
1191 /* Verify the left */
1192 if (td->r.left < screen.bounds.left)
1194 td->r.left = screen.bounds.left;
1197 /* Calculate bottom right corner */
1198 td->r.right = td->r.left + td->size_wid;
1199 td->r.bottom = td->r.top + td->size_hgt;
1201 /* Assume no graphics */
1202 td->t->higher_pict = FALSE;
1203 td->t->always_pict = FALSE;
1205 #ifdef ANGBAND_LITE_MAC
1209 #else /* ANGBAND_LITE_MAC */
1211 /* Handle graphics */
1214 /* Use higher_pict whenever possible */
1215 if (td->font_mono) td->t->higher_pict = TRUE;
1217 /* Use always_pict only when necessary */
1218 else td->t->always_pict = TRUE;
1221 #endif /* ANGBAND_LITE_MAC */
1223 /* Fake mono-space */
1224 if (!td->font_mono ||
1225 (td->font_wid != td->tile_wid) ||
1226 (td->font_hgt != td->tile_hgt))
1228 /* Handle fake monospace -- this is SLOW */
1229 if (td->t->higher_pict) td->t->higher_pict = FALSE;
1230 td->t->always_pict = TRUE;
1235 * Hack -- resize a term_data
1237 * This should normally be followed by "term_data_resize()"
1239 static void term_data_resize(term_data *td)
1241 /* Actually resize the window */
1242 SizeWindow(td->w, td->size_wid, td->size_hgt, 0);
1248 * Hack -- redraw a term_data
1250 * Note that "Term_redraw()" calls "TERM_XTRA_CLEAR"
1252 static void term_data_redraw(term_data *td)
1256 /* Activate the term */
1257 Term_activate(td->t);
1259 /* Redraw the contents */
1262 /* Flush the output */
1265 /* Restore the old term */
1268 /* No need to redraw */
1269 #if TARGET_API_MAC_CARBON
1271 RgnHandle theRgn = NewRgn();
1272 GetWindowRegion( td->w, kWindowContentRgn, theRgn );
1273 ValidWindowRgn( (WindowRef)(td->w), theRgn );
1274 DisposeRgn( theRgn );
1277 ValidRect(&td->w->portRect);
1285 #ifdef ANGBAND_LITE_MAC
1289 #else /* ANGBAND_LITE_MAC */
1297 * PICT id of image tiles, set by Term_xtra_mac_react
1299 #ifdef MACH_O_CARBON
1300 static CFStringRef pictID = NULL;
1302 static int pictID = 0;
1303 #endif /* MACH_O_CARBON */
1306 * Width and height of a tile in pixels
1308 static int grafWidth = 0;
1309 static int grafHeight = 0;
1312 * Numbers of rows and columns in tiles, calculated by
1313 * the PICT loading code
1315 static int pictCols = 0;
1316 static int pictRows = 0;
1319 * Available graphics modes - 32x32 tiles don't work on Classic
1321 #define GRAF_MODE_NONE 0
1322 #define GRAF_MODE_8X8 1
1323 #define GRAF_MODE_16X16 2
1324 #define GRAF_MODE_32X32 3
1327 * Current and requested graphics modes
1329 static int graf_mode = GRAF_MODE_NONE;
1330 static int graf_mode_req = GRAF_MODE_NONE;
1336 typedef struct FrameRec FrameRec;
1341 * - GWorld for the frame image
1342 * - Handle to pix map (saved for unlocking/locking)
1343 * - Pointer to color pix map (valid only while locked)
1347 GWorldPtr framePort;
1348 PixMapHandle framePixHndl;
1355 * The global picture data
1357 static FrameRec *frameP = NULL;
1363 static void BenSWLockFrame(FrameRec *srcFrameP)
1365 PixMapHandle pixMapH;
1367 pixMapH = GetGWorldPixMap(srcFrameP->framePort);
1368 (void)LockPixels(pixMapH);
1369 HLockHi((Handle)pixMapH);
1370 srcFrameP->framePixHndl = pixMapH;
1371 #if TARGET_API_MAC_CARBON
1372 srcFrameP->framePix = (PixMapPtr)*(Handle)pixMapH;
1374 srcFrameP->framePix = (PixMapPtr)StripAddress(*(Handle)pixMapH);
1383 static void BenSWUnlockFrame(FrameRec *srcFrameP)
1385 if (srcFrameP->framePort != NULL)
1387 HUnlock((Handle)srcFrameP->framePixHndl);
1388 UnlockPixels(srcFrameP->framePixHndl);
1391 srcFrameP->framePix = NULL;
1395 #ifdef MACH_O_CARBON
1398 * Moving graphics resources into data fork -- pelpel
1401 * Given base and type names of a resource, find a file in the
1402 * current application bundle and return its FSSpec in the third argument.
1403 * Returns true on success, false otherwise.
1404 * e.g. get_resource_spec(CFSTR("8x8"), CFSTR("png"), &spec);
1406 static Boolean get_resource_spec(
1407 CFStringRef base_name, CFStringRef type_name, FSSpec *spec)
1412 /* Find resource (=file) in the current bundle */
1413 res_url = CFBundleCopyResourceURL(
1414 CFBundleGetMainBundle(), base_name, type_name, NULL);
1417 if (res_url == NULL) return (false);
1419 /* Convert CFURL to FSRef */
1420 (void)CFURLGetFSRef(res_url, &ref);
1422 /* Convert FSRef to FSSpec */
1423 (void)FSGetCatalogInfo(&ref, kFSCatInfoNone, NULL, NULL, spec, NULL);
1425 /* Free allocated CF data */
1435 * Create a off-screen GWorld from contents of a file specified by a FSSpec.
1436 * Based on BenSWCreateGWorldFromPict.
1438 * Globals referenced: data[0], graf_height, graf_width
1439 * Globals updated: pict_rows, pict_cols.
1441 static OSErr create_gworld_from_spec(
1442 GWorldPtr *tile_gw, FSSpec *tile_spec)
1445 GraphicsImportComponent gi;
1446 GWorldPtr gw, tmp_gw;
1447 GDHandle gdh, tmp_gdh;
1451 /* See if QuickTime understands the file format */
1452 err = GetGraphicsImporterForFile(tile_spec, &gi);
1455 if (err != noErr) return (err);
1458 depth = data[0].pixelDepth;
1461 gdh = data[0].theGDH;
1463 /* Retrieve the rect of the image */
1464 err = GraphicsImportGetNaturalBounds(gi, &r);
1466 /* Adjust it, so that the upper left corner becomes (0, 0) */
1467 OffsetRect(&r, -r.left, -r.top);
1469 /* Calculate and set numbers of rows and columns */
1470 pictRows = r.bottom / grafHeight;
1471 pictCols = r.right / grafWidth;
1473 /* Create a GWorld */
1474 err = NewGWorld(&gw, depth, &r, NULL, gdh, noNewDevice);
1477 if (err != noErr) return (err);
1479 /* Save the pointer to the GWorld */
1482 /* Save the current GWorld */
1483 GetGWorld(&tmp_gw, &tmp_gdh);
1485 /* Activate the newly created GWorld */
1486 (void)GraphicsImportSetGWorld(gi, gw, NULL);
1488 /* Prevent pixmap from moving while drawing */
1489 (void)LockPixels(GetGWorldPixMap(gw));
1491 /* Clear the pixels */
1494 /* Draw the image into it */
1495 (void)GraphicsImportDraw(gi);
1497 /* Release the lock*/
1498 UnlockPixels(GetGWorldPixMap(gw));
1500 /* Restore GWorld */
1501 SetGWorld(tmp_gw, tmp_gdh);
1503 /* Close the image importer */
1510 #else /* MACH_O_CARBON */
1512 static OSErr BenSWCreateGWorldFromPict(
1513 GWorldPtr *pictGWorld,
1517 GWorldPtr saveGWorld;
1518 GDHandle saveGDevice;
1519 GWorldPtr tempGWorld;
1528 depth = data[0].pixelDepth;
1531 theGDH = data[0].theGDH;
1533 /* Obtain size rectangle */
1534 pictRect = (**pictH).picFrame;
1535 OffsetRect(&pictRect, -pictRect.left, -pictRect.top);
1537 /* Create a GWorld */
1538 err = NewGWorld(&tempGWorld, depth, &pictRect, nil,
1539 theGDH, noNewDevice);
1548 *pictGWorld = tempGWorld;
1551 GetGWorld(&saveGWorld, &saveGDevice);
1554 SetGWorld(tempGWorld, nil);
1556 /* Dump the pict into the GWorld */
1557 (void)LockPixels(GetGWorldPixMap(tempGWorld));
1558 EraseRect(&pictRect);
1559 DrawPicture(pictH, &pictRect);
1560 UnlockPixels(GetGWorldPixMap(tempGWorld));
1562 /* Restore GWorld */
1563 SetGWorld(saveGWorld, saveGDevice);
1569 #endif /* MACH_O_CARBON */
1573 * Init the global "frameP"
1576 static errr globe_init(void)
1580 GWorldPtr tempPictGWorldP;
1582 #ifdef MACH_O_CARBON
1586 #endif /* MACH_O_CARBON */
1588 /* Use window XXX XXX XXX */
1589 #if TARGET_API_MAC_CARBON
1590 SetPortWindowPort(data[0].w);
1596 #ifdef MACH_O_CARBON
1598 /* Get the tile resources */
1599 if (!get_resource_spec(pictID, CFSTR("png"), &pict_spec)) return (-1);
1602 err = create_gworld_from_spec(&tempPictGWorldP, &pict_spec);
1605 if (err != noErr) return (err);
1607 /* Create the frame */
1608 frameP = (FrameRec*)NewPtrClear((Size)sizeof(FrameRec));
1610 /* Analyze result */
1613 /* Dispose of image GWorld */
1614 DisposeGWorld(tempPictGWorldP);
1616 /* Fake error code */
1621 frameP->framePort = tempPictGWorldP;
1624 BenSWLockFrame(frameP);
1626 #else /* MACH_O_CARBON */
1628 /* Get the pict resource */
1629 newPictH = GetPicture(pictID);
1631 /* Analyze result */
1632 err = (newPictH ? 0 : -1);
1639 err = BenSWCreateGWorldFromPict(&tempPictGWorldP, newPictH);
1641 /* Release resource */
1642 ReleaseResource((Handle)newPictH);
1647 /* Create the frame */
1648 frameP = (FrameRec*)NewPtrClear((Size)sizeof(FrameRec));
1650 /* Analyze result */
1651 err = (frameP ? 0 : -1);
1657 frameP->framePort = tempPictGWorldP;
1660 BenSWLockFrame(frameP);
1664 #endif /* MACH_O_CARBON */
1673 * Nuke the global "frameP"
1675 static errr globe_nuke(void)
1681 BenSWUnlockFrame(frameP);
1683 /* Dispose of the GWorld */
1684 DisposeGWorld(frameP->framePort);
1686 /* Dispose of the memory */
1687 DisposePtr((Ptr)frameP);
1694 FlushEvents(everyEvent, 0);
1701 # ifdef USE_ASYNC_SOUND
1704 * Asynchronous sound player revised
1706 #if defined(USE_QT_SOUND) && !defined(MACH_O_CARBON)
1707 # undef USE_QT_SOUND
1708 #endif /* USE_QT_SOUND && !MACH_O_CARBON */
1712 * Number of channels in the channel pool
1714 #if TARGET_API_MAC_CARBON
1715 #define MAX_CHANNELS 8
1717 #define MAX_CHANNELS 4
1721 * A pool of sound channels
1723 static SndChannelPtr channels[MAX_CHANNELS];
1726 * Status of the channel pool
1728 static Boolean channel_initialised = FALSE;
1731 * Data handles containing sound samples
1733 static SndListHandle samples[SOUND_MAX];
1736 * Reference counts of sound samples
1738 static SInt16 sample_refs[SOUND_MAX];
1744 * These constants aren't used by the program at the moment.
1746 #define SOUND_VOLUME_MIN 0 /* Default minimum sound volume */
1747 #define SOUND_VOLUME_MAX 255 /* Default maximum sound volume */
1748 #define VOLUME_MIN 0 /* Minimum sound volume in % */
1749 #define VOLUME_MAX 100 /* Maximum sound volume in % */
1750 #define VOLUME_INC 5 /* Increment sound volume in % */
1752 /* I'm just too lazy to write a panel for this XXX XXX */
1753 static SInt16 sound_volume = SOUND_VOLUME_MAX;
1758 * QuickTime sound, by Ron Anderson
1760 * I didn't choose to use Windows-style .ini files (Ron wrote a parser
1761 * for it, but...), nor did I use lib/xtra directory, hoping someone
1762 * would code plist-based configuration code in the future -- pelpel
1767 * Load sound effects from data-fork resources. They are wav files
1768 * with the same names as angband_sound_name[] (variable.c)
1770 * Globals referenced: angband_sound_name[]
1771 * Globals updated: samples[] (they can be *huge*)
1773 static void load_sounds(void)
1778 /* Start QuickTime */
1779 err = EnterMovies();
1782 if (err != noErr) return;
1785 * This loop may take a while depending on the count and size of samples
1788 * We should use a progress dialog for this.
1790 for (i = 1; i < SOUND_MAX; i++)
1792 /* Apple APIs always give me headacke :( */
1803 /* Allocate CFString with the name of sound event to be processed */
1804 name = CFStringCreateWithCString(NULL, angband_sound_name[i],
1805 kTextEncodingUS_ASCII);
1808 if (name == NULL) continue;
1810 /* Find sound sample resource with the same name */
1811 res = get_resource_spec(name, CFSTR("wav"), &spec);
1813 /* Free the reference to CFString */
1819 /* Open the sound file */
1820 err = OpenMovieFile(&spec, &file_id, fsRdPerm);
1823 if (err != noErr) continue;
1825 /* Create Movie from the file */
1826 err = NewMovieFromFile(&movie, file_id, &res_id, movie_name,
1827 newMovieActive, NULL);
1830 if (err != noErr) goto close_file;
1832 /* Get the first track of the movie */
1833 track = GetMovieIndTrackType(movie, 1, AudioMediaCharacteristic,
1834 movieTrackCharacteristic | movieTrackEnabledOnly );
1837 if (track == NULL) goto close_movie;
1839 /* Allocate a handle to store sample */
1843 if (h == NULL) goto close_track;
1845 /* Dump the sample into the handle */
1846 err = PutMovieIntoTypedHandle(movie, track, soundListRsrc, h, 0,
1847 GetTrackDuration(track), 0L, NULL);
1852 /* Store the handle in the sample list */
1853 samples[i] = (SndListHandle)h;
1859 /* Free unused handle */
1863 /* Free the track */
1864 close_track: DisposeMovieTrack(track);
1866 /* Free the movie */
1867 close_movie: DisposeMovie(movie);
1869 /* Close the movie file */
1870 close_file: CloseMovieFile(file_id);
1873 /* Stop QuickTime */
1877 #else /* USE_QT_SOUND */
1880 * Return a handle of 'snd ' resource given Angband sound event number,
1881 * or NULL if it isn't found.
1883 * Globals referenced: angband_sound_name[] (variable.c)
1885 static SndListHandle find_sound(int num)
1889 /* Get the proper sound name */
1890 strnfmt((char*)sound + 1, 255, "%.16s.wav", angband_sound_name[num]);
1891 sound[0] = strlen((char*)sound + 1);
1893 /* Obtain resource XXX XXX XXX */
1894 return ((SndListHandle)GetNamedResource('snd ', sound));
1897 #endif /* USE_QT_SOUND */
1901 * Clean up sound support - to be called when the game exits.
1903 * Globals referenced: channels[], samples[], sample_refs[].
1905 static void cleanup_sound(void)
1909 /* No need to clean it up */
1910 if (!channel_initialised) return;
1912 /* Dispose channels */
1913 for (i = 0; i < MAX_CHANNELS; i++)
1915 /* Drain sound commands and free the channel */
1916 SndDisposeChannel(channels[i], TRUE);
1919 /* Free sound data */
1920 for (i = 1; i < SOUND_MAX; i++)
1923 if ((sample_refs[i] > 0) && (samples[i] != NULL))
1926 HUnlock((Handle)samples[i]);
1929 #ifndef USE_QT_SOUND
1932 if (samples[i]) ReleaseResource((Handle)samples[i]);
1936 if (samples[i]) DisposeHandle((Handle)samples[i]);
1937 #endif /* !USE_QT_SOUND */
1943 * Play sound effects asynchronously -- pelpel
1945 * I don't believe those who first started using the previous implementations
1946 * imagined this is *much* more complicated as it may seem. Anyway,
1947 * introduced round-robin scheduling of channels and made it much more
1948 * paranoid about HLock/HUnlock.
1950 * XXX XXX de-refcounting, HUnlock and ReleaseResource should be done
1951 * using channel's callback procedures, which set global flags, and
1952 * a procedure hooked into CheckEvents does housekeeping. On the other
1953 * hand, this lazy reclaiming strategy keeps things simple (no interrupt
1954 * time code) and provides a sort of cache for sound data.
1956 * Globals referenced: channel_initialised, channels[], samples[],
1958 * Globals updated: ditto.
1960 static void play_sound(int num, SInt16 vol)
1969 static int next_chan;
1970 static SInt16 channel_occupants[MAX_CHANNELS];
1971 static SndCommand volume_cmd, quiet_cmd;
1974 /* Initialise sound channels */
1975 if (!channel_initialised)
1977 for (i = 0; i < MAX_CHANNELS; i++)
1979 /* Paranoia - Clear occupant table */
1980 /* channel_occupants[i] = 0; */
1982 /* Create sound channel for all sounds to play from */
1983 err = SndNewChannel(&channels[i], sampledSynth, initMono, 0L);
1991 SndDisposeChannel(channels[i], TRUE);
1996 plog("¥µ¥¦¥ó¥É¥Á¥ã¥ó¥Í¥ë¤ò½é´ü²½½ÐÍè¤Þ¤»¤ó!");
1998 plog("Cannot initialise sound channels!");
2001 /* Cancel request */
2002 use_sound = arg_sound = FALSE;
2009 /* First channel to use */
2012 /* Prepare volume command */
2013 volume_cmd.cmd = volumeCmd;
2014 volume_cmd.param1 = 0;
2015 volume_cmd.param2 = 0;
2017 /* Prepare quiet command */
2018 quiet_cmd.cmd = quietCmd;
2019 quiet_cmd.param1 = 0;
2020 quiet_cmd.param2 = 0;
2022 /* Initialisation complete */
2023 channel_initialised = TRUE;
2027 if ((num <= 0) || (num >= SOUND_MAX)) return;
2029 /* Prepare volume command */
2030 volume_cmd.param2 = ((SInt32)vol << 16) | vol;
2032 /* Channel to use (round robin) */
2033 chan = channels[next_chan];
2035 /* See if the resource is already in use */
2036 if (sample_refs[num] > 0)
2038 /* Resource in use */
2041 /* Increase the refcount */
2045 /* Sound is not currently in use */
2048 /* Get handle for the sound */
2052 h = find_sound(num);
2053 #endif /* USE_QT_SOUND */
2055 /* Sample not available */
2056 if (h == NULL) return;
2058 #ifndef USE_QT_SOUND
2061 LoadResource((Handle)h);
2066 #endif /* !USE_QT_SOUND */
2068 /* Lock the handle */
2071 /* Initialise refcount */
2072 sample_refs[num] = 1;
2075 /* Poll the channel */
2076 err = SndChannelStatus(chan, sizeof(SCStatus), &status);
2078 /* It isn't available */
2079 if ((err != noErr) || status.scChannelBusy)
2082 SndDoImmediate(chan, &quiet_cmd);
2085 /* Previously played sound on this channel */
2086 prev_num = channel_occupants[next_chan];
2088 /* Process previously played sound */
2091 /* Decrease refcount */
2092 sample_refs[prev_num]--;
2094 /* We can free it now */
2095 if (sample_refs[prev_num] <= 0)
2098 HUnlock((Handle)samples[prev_num]);
2100 #ifndef USE_QT_SOUND
2103 ReleaseResource((Handle)samples[prev_num]);
2106 samples[prev_num] = NULL;
2108 #endif /* !USE_QT_SOUND */
2111 sample_refs[prev_num] = 0;
2115 /* Remember this sound as the current occupant of the channel */
2116 channel_occupants[next_chan] = num;
2118 /* Set up volume for channel */
2119 SndDoImmediate(chan, &volume_cmd);
2121 /* Play new sound asynchronously */
2122 SndPlay(chan, h, TRUE);
2124 /* Schedule next channel (round robin) */
2126 if (next_chan >= MAX_CHANNELS) next_chan = 0;
2129 # else /* USE_ASYNC_SOUND */
2132 * Play sound synchronously
2134 * This may not be your choice, but much safer and much less resource hungry.
2136 static void play_sound(int num, SInt16 vol)
2141 /* Get the proper sound name */
2142 strnfmt((char*)sound + 1, 255, "%.16s.wav", angband_sound_name[num]);
2143 sound[0] = strlen((char*)sound + 1);
2145 /* Obtain resource XXX XXX XXX */
2146 handle = GetNamedResource('snd ', sound);
2149 if (handle == NULL) return;
2152 LoadResource(handle);
2155 /* Play sound (wait for completion) */
2156 SndPlay(NULL, (SndListHandle)handle, FALSE);
2158 /* Unlock and release */
2160 ReleaseResource(handle);
2163 # endif /* USE_ASYNC_SOUND */
2170 static short soundmode[8];
2173 #define SND_ATTACK 1
2178 #define SND_CMD_ERROR 6
2180 #ifndef MACH_O_CARBON
2182 static int soundchoice[] = {
2250 static int ext_sound = 0;
2251 static int ext_graf = 0;
2253 #endif /* !MACH_O_CARBON */
2255 #endif /* ANGBAND_LITE_MAC */
2259 /*** Support for the "z-term.c" package ***/
2263 * Initialize a new Term
2265 * Note also the "window type" called "noGrowDocProc", which might be more
2266 * appropriate for the main "screen" window.
2268 * Note the use of "srcCopy" mode for optimized screen writes.
2270 static void Term_init_mac(term *t)
2272 term_data *td = (term_data*)(t->data);
2274 static RGBColor black = {0x0000,0x0000,0x0000};
2275 static RGBColor white = {0xFFFF,0xFFFF,0xFFFF};
2277 #ifdef ANGBAND_LITE_MAC
2279 /* Make the window */
2280 td->w = NewWindow(0, &td->r, td->title, 0, noGrowDocProc, (WindowPtr)-1, 1, 0L);
2282 #else /* ANGBAND_LITE_MAC */
2284 /* Make the window */
2285 td->w = NewCWindow(0, &td->r, td->title, 0, documentProc, (WindowPtr)-1, 1, 0L);
2287 #endif /* ANGBAND_LITE_MAC */
2289 /* Activate the window */
2292 /* Erase behind words */
2295 /* Apply and Verify */
2296 term_data_check_font(td);
2297 term_data_check_size(td);
2299 /* Resize the window */
2300 term_data_resize(td);
2302 #ifdef ANGBAND_LITE_MAC
2304 /* Prepare the colors (base colors) */
2305 BackColor(blackColor);
2306 ForeColor(whiteColor);
2308 #else /* ANGBAND_LITE_MAC */
2310 /* Prepare the colors (real colors) */
2311 RGBBackColor(&black);
2312 RGBForeColor(&white);
2318 GDHandle currentGDH;
2319 GWorldPtr windowGWorld;
2320 PixMapHandle basePixMap;
2322 /* Obtain the rect */
2323 #if TARGET_API_MAC_CARBON
2324 GetWindowBounds( (WindowRef)td->w, kWindowContentRgn, &globalRect );
2326 globalRect = td->w->portRect;
2327 LocalToGlobal((Point*)&globalRect.top);
2328 LocalToGlobal((Point*)&globalRect.bottom);
2331 /* Obtain the proper GDH */
2332 mainGDH = GetMaxDevice(&globalRect);
2334 /* Extract GWorld and GDH */
2335 GetGWorld(&windowGWorld, ¤tGDH);
2337 /* Obtain base pixmap */
2338 basePixMap = (**mainGDH).gdPMap;
2340 /* Save pixel depth */
2341 td->pixelDepth = (**basePixMap).pixelSize;
2343 /* Save Window GWorld */
2344 td->theGWorld = windowGWorld;
2346 /* Save Window GDH */
2347 td->theGDH = currentGDH;
2350 td->mainSWGDH = mainGDH;
2353 #endif /* ANGBAND_LITE_MAC */
2358 #if TARGET_API_MAC_CARBON
2359 GetWindowBounds( (WindowRef)td->w, kWindowContentRgn, &portRect );
2360 global_to_local( &portRect );
2362 portRect = td->w->portRect;
2364 /* Clip to the window */
2365 ClipRect(&portRect);
2367 /* Erase the window */
2368 EraseRect(&portRect);
2370 /* Invalidate the window */
2371 #if TARGET_API_MAC_CARBON
2372 InvalWindowRect((WindowRef)(td->w), (const Rect *)(&portRect));
2374 InvalRect(&portRect);
2377 /* Display the window if needed */
2378 if (td->mapped) ShowWindow(td->w);
2380 /* Hack -- set "mapped" flag */
2381 t->mapped_flag = td->mapped;
2387 /* if (err == noErr)
2398 static void Term_nuke_mac(term *t)
2411 static errr Term_user_mac(int n)
2425 static errr Term_xtra_mac_react(void)
2427 term_data *td = (term_data*)(Term->data);
2433 #ifdef ANGBAND_LITE_MAC
2437 #else /* ANGBAND_LITE_MAC */
2440 if (use_sound != arg_sound)
2443 use_sound = arg_sound;
2447 /* Handle graphics */
2448 if (graf_mode_req != graf_mode)
2450 /* dispose old GWorld's if present */
2453 /* Setup parameters according to request */
2454 switch (graf_mode_req)
2456 /* ASCII - no graphics whatsoever */
2457 case GRAF_MODE_NONE:
2459 use_graphics = arg_graphics = GRAPHICS_NONE;
2464 * 8x8 tiles (PICT id 1001)
2465 * no transparency effect
2466 * "old" graphics definitions
2470 use_graphics = arg_graphics = GRAPHICS_ORIGINAL;
2471 ANGBAND_GRAF = "old";
2472 #ifdef MACH_O_CARBON
2473 pictID = CFSTR("8x8");
2476 #endif /* MACH_O_CARBON */
2477 grafWidth = grafHeight = 8;
2482 * 16x16 tiles (images: PICT id 1002)
2483 * with transparency effect
2484 * "new" graphics definitions
2486 case GRAF_MODE_16X16:
2488 use_graphics = arg_graphics = GRAPHICS_ADAM_BOLT;
2489 ANGBAND_GRAF = "new";
2490 #ifdef MACH_O_CARBON
2491 pictID = CFSTR("16x16");
2494 #endif /* MACH_O_CARBON */
2495 grafWidth = grafHeight = 16;
2500 if ((graf_mode_req != GRAF_MODE_NONE) && !frameP && (globe_init() != 0))
2503 plog("¥°¥é¥Õ¥£¥Ã¥¯¤Î½é´ü²½¤Ï½ÐÍè¤Þ¤»¤ó¤Ç¤·¤¿.");
2505 plog("Cannot initialize graphics!");
2508 /* reject request */
2509 graf_mode_req = GRAF_MODE_NONE;
2511 /* reset graphics flags */
2512 use_graphics = arg_graphics = FALSE;
2516 /* update current graphics mode */
2517 graf_mode = graf_mode_req;
2519 /* Apply and Verify */
2520 term_data_check_size(td);
2522 /* Resize the window */
2523 term_data_resize(td);
2529 #endif /* ANGBAND_LITE_MAC */
2537 * Do a "special thing"
2539 static errr Term_xtra_mac(int n, int v)
2541 term_data *td = (term_data*)(Term->data);
2549 case TERM_XTRA_NOISE:
2558 #ifdef ANGBAND_LITE_MAC
2562 #else /* ANGBAND_LITE_MAC */
2565 case TERM_XTRA_SOUND:
2568 play_sound(v, sound_volume);
2574 #endif /* ANGBAND_LITE_MAC */
2576 /* Process random events */
2577 case TERM_XTRA_BORED:
2579 /* Process an event */
2580 (void)CheckEvents(FALSE);
2586 /* Process pending events */
2587 case TERM_XTRA_EVENT:
2589 /* Process an event */
2590 (void)CheckEvents(v);
2596 /* Flush all pending events (if any) */
2597 case TERM_XTRA_FLUSH:
2599 /* Hack -- flush all events */
2600 while (CheckEvents(TRUE)) /* loop */;
2606 /* Hack -- Change the "soft level" */
2607 case TERM_XTRA_LEVEL:
2609 /* Activate if requested */
2610 if (v) activate(td->w);
2616 /* Clear the screen */
2617 case TERM_XTRA_CLEAR:
2621 #if TARGET_API_MAC_CARBON
2622 GetWindowBounds( (WindowRef)td->w, kWindowContentRgn, &portRect );
2623 global_to_local( &portRect );
2625 portRect = td->w->portRect;
2628 /* No clipping XXX XXX XXX */
2629 ClipRect(&portRect);
2631 /* Erase the window */
2632 EraseRect(&portRect);
2635 term_data_color(td, TERM_WHITE);
2637 /* Frame the window in white */
2639 LineTo(0, td->size_hgt-1);
2640 LineTo(td->size_wid-1, td->size_hgt-1);
2641 LineTo(td->size_wid-1, 0);
2643 /* Clip to the new size */
2644 r.left = portRect.left + td->size_ow1;
2645 r.top = portRect.top + td->size_oh1;
2646 r.right = portRect.right - td->size_ow2;
2647 r.bottom = portRect.bottom - td->size_oh2;
2654 /* React to changes */
2655 case TERM_XTRA_REACT:
2657 /* React to changes */
2658 return (Term_xtra_mac_react());
2661 /* Delay (milliseconds) */
2662 case TERM_XTRA_DELAY:
2667 #if TARGET_API_MAC_CARBON
2671 /* Convert millisecs to ticks */
2672 ticks = (v * 60L) / 1000;
2675 * Hack? - Put the programme into sleep.
2676 * No events match ~everyEvent, so nothing
2677 * should be lost in Angband's event queue.
2678 * Even if ticks are 0, it's worth calling for
2679 * the above mentioned reasons.
2681 WaitNextEvent((EventMask)~everyEvent, &tmp, ticks, nil);
2683 long m = TickCount() + (v * 60L) / 1000;
2686 while (TickCount() < m) /* loop */;
2702 * Low level graphics (Assumes valid input).
2703 * Draw a "cursor" at (x,y), using a "yellow box".
2704 * We are allowed to use "Term_grab()" to determine
2705 * the current screen contents (for inverting, etc).
2707 static errr Term_curs_mac(int x, int y)
2711 term_data *td = (term_data*)(Term->data);
2714 term_data_color(td, TERM_YELLOW);
2716 /* Frame the grid */
2717 r.left = x * td->tile_wid + td->size_ow1;
2718 r.right = r.left + td->tile_wid;
2719 r.top = y * td->tile_hgt + td->size_oh1;
2720 r.bottom = r.top + td->tile_hgt;
2730 * Low level graphics (Assumes valid input).
2731 * Draw a "big cursor" at (x,y), using a "yellow box".
2732 * We are allowed to use "Term_grab()" to determine
2733 * the current screen contents (for inverting, etc).
2735 static errr Term_bigcurs_mac(int x, int y)
2739 term_data *td = (term_data*)(Term->data);
2742 term_data_color(td, TERM_YELLOW);
2744 /* Frame the grid */
2745 r.left = x * td->tile_wid + td->size_ow1;
2746 r.right = r.left + 2 * td->tile_wid;
2747 r.top = y * td->tile_hgt + td->size_oh1;
2748 r.bottom = r.top + td->tile_hgt;
2758 * Low level graphics (Assumes valid input)
2760 * Erase "n" characters starting at (x,y)
2762 static errr Term_wipe_mac(int x, int y, int n)
2766 term_data *td = (term_data*)(Term->data);
2768 /* Erase the block of characters */
2769 r.left = x * td->tile_wid + td->size_ow1;
2770 r.right = r.left + n * td->tile_wid;
2771 r.top = y * td->tile_hgt + td->size_oh1;
2772 r.bottom = r.top + td->tile_hgt;
2781 * Low level graphics. Assumes valid input.
2783 * Draw several ("n") chars, with an attr, at a given location.
2785 static errr Term_text_mac(int x, int y, int n, byte a, const char *cp)
2789 term_data *td = (term_data*)(Term->data);
2792 term_data_color(td, (a & 0x0F));
2794 /* Starting pixel */
2795 xp = x * td->tile_wid + td->tile_o_x + td->size_ow1;
2796 yp = y * td->tile_hgt + td->tile_o_y + td->size_oh1;
2798 /* Move to the correct location */
2801 /* Draw the character */
2802 if (n == 1) DrawChar(*cp);
2804 /* Draw the string */
2805 else DrawText(cp, 0, n);
2813 * Low level graphics (Assumes valid input)
2815 * Erase "n" characters starting at (x,y)
2817 static errr Term_pict_mac(int x, int y, int n, const byte *ap, const char *cp,
2818 const byte *tap, const char *tcp)
2822 term_data *td = (term_data*)(Term->data);
2823 GDHandle saveGDevice;
2824 GWorldPtr saveGWorld;
2827 GetGWorld(&saveGWorld, &saveGDevice);
2829 r2.left = x * td->tile_wid + td->size_ow1;
2830 r2.right = r2.left + td->tile_wid;
2831 r2.top = y * td->tile_hgt + td->size_oh1;
2832 r2.bottom = r2.top + td->tile_hgt;
2836 /* Instantiate font */
2837 TextFont(td->font_id);
2838 TextSize(td->font_size);
2839 TextFace(td->font_face);
2841 /* Restore colors */
2842 BackColor(blackColor);
2843 ForeColor(whiteColor);
2847 /* Destination rectangle */
2848 /* r2.left = x * td->tile_wid + td->size_ow1;
2849 r2.top = y * td->tile_hgt + td->size_oh1;
2850 r2.bottom = r2.top + td->tile_hgt;*/
2854 /* Scan the input */
2855 for (i = 0; i < n; i++)
2862 /* Second byte of bigtile */
2863 if (use_bigtile && a == 255)
2866 r2.left += td->tile_wid;
2871 /* Prepare right of rectangle now */
2872 r2.right = r2.left + td->tile_wid;
2874 #ifdef ANGBAND_LITE_MAC
2878 #else /* ANGBAND_LITE_MAC */
2880 /* Graphics -- if Available and Needed */
2881 if (use_graphics && ((byte)a & 0x80) && ((byte)c & 0x80))
2883 #if TARGET_API_MAC_CARBON
2884 PixMapHandle srcBitMap = GetGWorldPixMap(frameP->framePort);
2885 PixMapHandle destBitMap;
2887 BitMapPtr srcBitMap = (BitMapPtr)(frameP->framePix);
2888 BitMapPtr destBitMap;
2895 bool terrain_flag = FALSE;
2899 if ((a != ta || c != tc) &&
2900 ((byte)ta & 0x80) && ((byte)tc & 0x80))
2903 row = ((byte)ta & 0x7F);
2904 col = ((byte)tc & 0x7F);
2906 /* Terrain Source rectangle */
2907 terrain_r.left = col * grafWidth;
2908 terrain_r.top = row * grafHeight;
2909 terrain_r.right = terrain_r.left + grafWidth;
2910 terrain_r.bottom = terrain_r.top + grafHeight;
2912 terrain_flag = TRUE;
2916 row = ((byte)a & 0x7F);
2917 col = ((byte)c & 0x7F);
2919 /* Source rectangle */
2920 r1.left = col * grafWidth;
2921 r1.top = row * grafHeight;
2922 r1.right = r1.left + grafWidth;
2923 r1.bottom = r1.top + grafHeight;
2925 /* Hardwire CopyBits */
2926 BackColor(whiteColor);
2927 ForeColor(blackColor);
2929 /* Draw the picture */
2930 #if TARGET_API_MAC_CARBON
2931 destBitMap = GetPortPixMap(GetWindowPort( td->w ));
2933 destBitMap = (BitMapPtr)&(td->w->portBits);
2935 if (use_bigtile) r2.right += td->tile_wid;
2940 * Source mode const = srcCopy:
2942 * determine how close the color of the source
2943 * pixel is to black, and assign this relative
2944 * amount of foreground color to the
2945 * destination pixel; determine how close the
2946 * color of the source pixel is to white, and
2947 * assign this relative amount of background
2948 * color to the destination pixel
2950 #if TARGET_API_MAC_CARBON
2951 CopyBits( (BitMap *) *srcBitMap, (BitMap *) *destBitMap, &terrain_r, &r2, srcCopy, NULL);
2953 CopyBits( srcBitMap, destBitMap, &terrain_r, &r2, srcCopy, NULL );
2956 * Draw transparent tile
2957 * BackColor is ignored and the destination is
2960 BackColor(blackColor);
2961 #if TARGET_API_MAC_CARBON
2962 CopyBits( (BitMap *) *srcBitMap, (BitMap *) *destBitMap, &r1, &r2, transparent, NULL);
2964 CopyBits( srcBitMap, destBitMap, &r1, &r2, transparent, NULL );
2969 #if TARGET_API_MAC_CARBON
2970 CopyBits( (BitMap *) *srcBitMap, (BitMap *) *destBitMap, &r1, &r2, srcCopy, NULL);
2972 CopyBits( srcBitMap, destBitMap, &r1, &r2, srcCopy, NULL );
2976 /* Restore colors */
2977 BackColor(blackColor);
2978 ForeColor(whiteColor);
2987 #endif /* ANGBAND_LITE_MAC */
2995 term_data_color(td, (a & 0x0F));
2997 /* Starting pixel */
2998 xp = r2.left + td->tile_o_x;
2999 yp = r2.top + td->tile_o_y;
3001 /* Move to the correct location */
3007 /* Double width rectangle */
3008 r2.right += td->tile_wid;
3013 /* Draw the character */
3018 r2.left += td->tile_wid;
3026 /* Draw the character */
3032 r2.left += td->tile_wid;
3041 * Create and initialize window number "i"
3043 static void term_data_link(int i)
3047 term_data *td = &data[i];
3052 /* Require mapped */
3053 if (!td->mapped) return;
3058 /* Initialize the term */
3059 term_init(td->t, td->cols, td->rows, td->keys);
3061 /* Use a "software" cursor */
3062 td->t->soft_cursor = TRUE;
3064 /* Erase with "white space" */
3065 td->t->attr_blank = TERM_WHITE;
3066 td->t->char_blank = ' ';
3068 /* Prepare the init/nuke hooks */
3069 td->t->init_hook = Term_init_mac;
3070 td->t->nuke_hook = Term_nuke_mac;
3072 /* Prepare the function hooks */
3073 td->t->user_hook = Term_user_mac;
3074 td->t->xtra_hook = Term_xtra_mac;
3075 td->t->wipe_hook = Term_wipe_mac;
3076 td->t->curs_hook = Term_curs_mac;
3077 td->t->bigcurs_hook = Term_bigcurs_mac;
3078 td->t->text_hook = Term_text_mac;
3079 td->t->pict_hook = Term_pict_mac;
3081 /* Link the local structure */
3082 td->t->data = (vptr)(td);
3085 Term_activate(td->t);
3087 /* Global pointer */
3088 angband_term[i] = td->t;
3096 #ifdef MACH_O_CARBON
3100 * Return a POSIX pathname of the lib directory, or NULL if it can't be
3101 * located. Caller must supply a buffer along with its size in bytes,
3102 * where returned pathname will be stored.
3103 * I prefer use of goto's to several nested if's, if they involve error
3104 * handling. Sorry if you are offended by their presence. Modern
3105 * languages have neater constructs for this kind of jobs -- pelpel
3107 static char *locate_lib(char *buf, size_t size)
3109 CFURLRef main_url = NULL;
3110 CFStringRef main_str = NULL;
3114 /* Obtain the URL of the main bundle */
3115 main_url = CFBundleCopyBundleURL(CFBundleGetMainBundle());
3118 if (main_url == NULL) goto ret;
3120 /* Convert it to POSIX pathname */
3121 main_str = CFURLCopyFileSystemPath(main_url, kCFURLPOSIXPathStyle);
3124 if (main_str == NULL) goto ret;
3126 /* Convert it again from darn unisomething encoding to ASCII */
3127 if (CFStringGetCString(main_str, buf, size, kTextEncodingUS_ASCII) == FALSE)
3130 /* Find the last '/' in the pathname */
3131 p = strrchr(buf, '/');
3133 /* Paranoia - cannot happen */
3134 if (p == NULL) goto ret;
3136 /* Remove the trailing path */
3140 * Paranoia - bounds check, with 5 being the length of "/lib/"
3141 * and 1 for terminating '\0'.
3143 if (strlen(buf) + 5 + 1 > size) goto ret;
3145 /* Append "/lib/" */
3146 strcat(buf, "/lib/");
3153 /* Release objects allocated and implicitly retained by the program */
3154 if (main_str) CFRelease(main_str);
3155 if (main_url) CFRelease(main_url);
3157 /* pathname of the lib folder or NULL */
3162 #else /* MACH_O_CARBON */
3166 * Set the "current working directory" (also known as the "default"
3167 * volume/directory) to the location of the current application.
3169 * Code by: Maarten Hazewinkel (mmhazewi@cs.ruu.nl)
3171 * This function does not appear to work correctly with System 6.
3173 static void SetupAppDir(void)
3177 char errString[100];
3179 /* Get the location of the Angband executable */
3180 fcbBlock.ioCompletion = NULL;
3181 fcbBlock.ioNamePtr = NULL;
3182 fcbBlock.ioVRefNum = 0;
3183 fcbBlock.ioRefNum = CurResFile();
3184 fcbBlock.ioFCBIndx = 0;
3185 err = PBGetFCBInfo(&fcbBlock, FALSE);
3189 sprintf(errString, "PBGetFCBInfo ¥¨¥é¡¼ #%d.\r ½ªÎ»¤·¤Þ¤¹.", err);
3191 sprintf(errString, "Fatal PBGetFCBInfo Error #%d.\r Exiting.", err);
3193 mac_warning(errString);
3197 /* Extract the Vol and Dir */
3198 app_vol = fcbBlock.ioFCBVRefNum;
3199 app_dir = fcbBlock.ioFCBParID;
3201 /* Set the current working directory to that location */
3202 err = HSetVol(NULL, app_vol, app_dir);
3206 sprintf(errString, "HSetVol ¥¨¥é¡¼ #%d.\r ½ªÎ»¤·¤Þ¤¹.", err);
3208 sprintf(errString, "Fatal HSetVol Error #%d.\r Exiting.", err);
3210 mac_warning(errString);
3219 #if TARGET_API_MAC_CARBON
3221 * Using Core Foundation's Preferences services -- pelpel
3223 * Requires OS 8.6 or greater with CarbonLib 1.1 or greater. Or OS X,
3226 * Without this, we can support older versions of OS 8 as well
3227 * (with CarbonLib 1.0.4).
3229 * Frequent allocation/deallocation of small chunks of data is
3230 * far from my liking, but since this is only called at the
3231 * beginning and the end of a session, I hope this hardly matters.
3236 * Store "value" as the value for preferences item name
3239 static void save_pref_short(const char *key, short value)
3242 CFNumberRef cf_value;
3244 /* allocate and initialise the key */
3245 cf_key = CFStringCreateWithCString(NULL, key, kTextEncodingUS_ASCII);
3247 /* allocate and initialise the value */
3248 cf_value = CFNumberCreate(NULL, kCFNumberShortType, &value);
3250 if ((cf_key != NULL) && (cf_value != NULL))
3252 /* Store the key-value pair in the applications preferences */
3253 CFPreferencesSetAppValue(
3256 kCFPreferencesCurrentApplication);
3260 * Free CF data - the reverse order is a vain attempt to
3261 * minimise memory fragmentation.
3263 if (cf_value) CFRelease(cf_value);
3264 if (cf_key) CFRelease(cf_key);
3269 * Load preference value for key, returns TRUE if it succeeds with
3270 * vptr updated appropriately, FALSE otherwise.
3272 static bool query_load_pref_short(const char *key, short *vptr)
3275 CFNumberRef cf_value;
3277 /* allocate and initialise the key */
3278 cf_key = CFStringCreateWithCString(NULL, key, kTextEncodingUS_ASCII);
3281 if (cf_key == NULL) return (FALSE);
3283 /* Retrieve value for the key */
3284 cf_value = CFPreferencesCopyAppValue(
3286 kCFPreferencesCurrentApplication);
3288 /* Value not found */
3289 if (cf_value == NULL)
3295 /* Convert the value to short */
3302 CFRelease(cf_value);
3311 * Update short data pointed by vptr only if preferences
3312 * value for key is located.
3314 static void load_pref_short(const char *key, short *vptr)
3318 if (query_load_pref_short(key, &tmp)) *vptr = tmp;
3324 * Save preferences to preferences file for current host+current user+
3325 * current application.
3327 static void cf_save_prefs()
3332 save_pref_short("version.major", FAKE_VERSION);
3333 save_pref_short("version.minor", FAKE_VER_MAJOR);
3334 save_pref_short("version.patch", FAKE_VER_MINOR);
3335 save_pref_short("version.extra", FAKE_VER_PATCH);
3338 save_pref_short("arg.arg_sound", arg_sound);
3339 save_pref_short("arg.graf_mode", graf_mode);
3340 save_pref_short("arg.arg_bigtile", use_bigtile);
3343 for( i = 0 ; i < 7 ; i++ )
3344 save_pref_short(format("sound%d.on", i), soundmode[i]);
3347 for (i = 0; i < MAX_TERM_DATA; i++)
3349 term_data *td = &data[i];
3351 save_pref_short(format("term%d.mapped", i), td->mapped);
3353 save_pref_short(format("term%d.font_id", i), td->font_id);
3354 save_pref_short(format("term%d.font_size", i), td->font_size);
3355 save_pref_short(format("term%d.font_face", i), td->font_face);
3357 save_pref_short(format("term%d.tile_wid", i), td->tile_wid);
3358 save_pref_short(format("term%d.tile_hgt", i), td->tile_hgt);
3360 save_pref_short(format("term%d.cols", i), td->cols);
3361 save_pref_short(format("term%d.rows", i), td->rows);
3362 save_pref_short(format("term%d.left", i), td->r.left);
3363 save_pref_short(format("term%d.top", i), td->r.top);
3367 * Make sure preferences are persistent
3369 CFPreferencesAppSynchronize(
3370 kCFPreferencesCurrentApplication);
3375 * Load preferences from preferences file for current host+current user+
3376 * current application.
3378 static void cf_load_prefs()
3381 short pref_major, pref_minor, pref_patch, pref_extra;
3384 /* Assume nothing is wrong, yet */
3387 /* Load version information */
3388 ok &= query_load_pref_short("version.major", &pref_major);
3389 ok &= query_load_pref_short("version.minor", &pref_minor);
3390 ok &= query_load_pref_short("version.patch", &pref_patch);
3391 ok &= query_load_pref_short("version.extra", &pref_extra);
3393 /* Any of the above failed */
3396 /* This may be the first run */
3398 mac_warning("½é´üÀßÄê¥Õ¥¡¥¤¥ë¤¬¸«¤Ä¤«¤ê¤Þ¤»¤ó¡£");
3400 mac_warning("Preferences are not found.");
3403 /* Ignore the rest */
3412 if (query_load_pref_short("arg.arg_sound", &pref_tmp))
3413 arg_sound = pref_tmp;
3416 if (query_load_pref_short("arg.graf_mode", &pref_tmp))
3417 graf_mode_req = pref_tmp;
3419 /* double-width tiles */
3420 if (query_load_pref_short("arg.arg_bigtile", &pref_tmp))
3422 use_bigtile = pref_tmp;
3428 for( i = 0 ; i < 7 ; i++ )
3430 query_load_pref_short(format("sound%d.on", i), &soundmode[i]);
3434 for (i = 0; i < MAX_TERM_DATA; i++)
3436 term_data *td = &data[i];
3438 load_pref_short(format("term%d.mapped", i), &td->mapped);
3440 load_pref_short(format("term%d.font_id", i), &td->font_id);
3441 load_pref_short(format("term%d.font_size", i), &td->font_size);
3442 load_pref_short(format("term%d.font_face", i), &td->font_face);
3444 load_pref_short(format("term%d.tile_wid", i), &td->tile_wid);
3445 load_pref_short(format("term%d.tile_hgt", i), &td->tile_hgt);
3447 load_pref_short(format("term%d.cols", i), &td->cols);
3448 load_pref_short(format("term%d.rows", i), &td->rows);
3449 load_pref_short(format("term%d.left", i), &td->r.left);
3450 load_pref_short(format("term%d.top", i), &td->r.top);
3456 * Global "preference" file pointer
3461 * Read a "short" from the file
3463 static int getshort(void)
3467 if (0 == my_fgets(fff, buf, sizeof(buf))) x = atoi(buf);
3472 * Dump a "short" to the file
3474 static void putshort(int x)
3476 fprintf(fff, "%d\n", x);
3482 * Write the "preference" data to the current "file"
3484 static void save_prefs(void)
3491 /*** The current version ***/
3493 putshort(FAKE_VERSION);
3494 putshort(FAKE_VER_MAJOR);
3495 putshort(FAKE_VER_MINOR);
3496 putshort(FAKE_VER_PATCH);
3498 putshort(arg_sound);
3499 putshort(graf_mode);
3500 putshort(arg_bigtile);
3503 for( i = 0 ; i < 7 ; i++ )
3504 putshort(soundmode[i]);
3507 for (i = 0; i < MAX_TERM_DATA; i++)
3512 putshort(td->mapped);
3514 putshort(td->font_id);
3515 putshort(td->font_size);
3516 putshort(td->font_face);
3518 putshort(td->tile_wid);
3519 putshort(td->tile_hgt);
3524 putshort(td->r.left);
3525 putshort(td->r.top);
3531 * Load the preferences from the current "file"
3533 * XXX XXX XXX Being able to undefine various windows is
3534 * slightly bizarre, and may cause problems.
3536 static void load_prefs(void)
3540 int old_version, old_major, old_minor, old_patch;
3545 /*** Version information ***/
3547 /* Preferences version */
3548 old_version = getshort();
3549 old_major = getshort();
3550 old_minor = getshort();
3551 old_patch = getshort();
3553 /* Hack -- Verify or ignore */
3554 if ((old_version != FAKE_VERSION) ||
3555 (old_major != FAKE_VER_MAJOR) ||
3556 (old_minor != FAKE_VER_MINOR) ||
3557 (old_patch != FAKE_VER_PATCH))
3561 mac_warning("¸Å¤¤½é´üÀßÄê¥Õ¥¡¥¤¥ë¤ò̵»ë¤·¤Þ¤¹.");
3563 mac_warning("Ignoring old preferences.");
3569 arg_sound = getshort();
3570 graf_mode_req = getshort();
3571 arg_bigtile = getshort();
3572 use_bigtile = arg_bigtile;
3575 for( i = 0 ; i < 7 ; i++ )
3576 soundmode[i] = getshort();
3579 for (i = 0; i < MAX_TERM_DATA; i++)
3584 td->mapped = getshort();
3586 td->font_id = getshort();
3587 td->font_size = getshort();
3588 td->font_face = getshort();
3590 td->tile_wid = getshort();
3591 td->tile_hgt = getshort();
3593 td->cols = getshort();
3594 td->rows = getshort();
3596 td->r.left = getshort();
3597 td->r.top = getshort();
3600 if (feof(fff)) break;
3603 #endif /* TARGET_API_MAC_CARBON */
3608 * Hack -- default data for a window
3610 static void term_data_hack(term_data *td)
3614 #if TARGET_API_MAC_CARBON
3616 /* Default to Osaka font (Japanese) */
3617 fid = FMGetFontFamilyFromName( "\pOsaka¡ÝÅùÉý" );
3619 /* Default to Monaco font */
3620 fid = FMGetFontFamilyFromName("\pmonaco");
3624 /* Default to ÅùÉýÌÀÄ« font (Japanese) */
3625 GetFNum( "\pÅùÉýÌÀÄ«", &fid);
3626 SetFScaleDisable( true );
3628 /* Default to Monaco font */
3629 GetFNum("\pmonaco", &fid);
3634 WIPE(td, term_data);
3639 /* Default borders */
3650 /* Default font size */
3653 /* Default font face */
3660 /* Default position */
3670 * Read the preference file, Create the windows.
3672 * We attempt to use "FindFolder()" to track down the preference file,
3673 * but if this fails, for any reason, we will try the "SysEnvirons()"
3674 * method, which may work better with System 6.
3676 static void init_windows(void)
3682 #if !TARGET_API_MAC_CARBON
3690 #endif /* !TARGET_API_MAC_CARBON */
3693 /*** Default values ***/
3695 /* Initialize (backwards) */
3696 for (i = MAX_TERM_DATA - 1; i >= 0; i--)
3709 s = angband_term_name[i];
3714 /* Maximal length */
3717 /* Copy the title */
3718 strncpy((char*)(td->title) + 1, s, n);
3720 /* Save the length */
3723 /* Tile the windows */
3724 td->r.left += (b * 30);
3725 td->r.top += (b * 30);
3732 /*** Load preferences ***/
3734 #if TARGET_API_MAC_CARBON
3737 /* Assume failure */
3740 /* Assume failure */
3753 /* Find the folder */
3754 err = FindFolder(kOnSystemDisk, kPreferencesFolderType, kCreateFolder,
3760 /* Extract a path name */
3761 PathNameFromDirID(dirID, vref, (StringPtr)foo);
3763 /* Convert the string */
3764 ptocstr((StringPtr)foo);
3766 /* Append the preference file name */
3767 strcat(foo, PREF_FILE_NAME);
3769 /* Open the preference file */
3770 fff = fopen(foo, "r");
3777 #endif /* USE_SFL_CODE */
3783 HGetVol(0, &savev, &saved);
3785 /* Go to the "system" folder */
3786 SysEnvirons(curSysEnvVers, &env);
3787 SetVol(0, env.sysVRefNum);
3790 fff = fopen(PREF_FILE_NAME, "r");
3793 HSetVol(0, savev, saved);
3796 /* Load preferences */
3799 /* Load a real preference file */
3802 /* Close the file */
3805 #endif /* TARGET_API_MAC_CARBON */
3808 /*** Instantiate ***/
3819 /* Link (backwards, for stacking order) */
3820 for (i = MAX_TERM_DATA - 1; i >= 0; i--)
3829 Term_activate(td->t);
3832 #ifndef MACH_O_CARBON
3834 static void init_sound( void )
3838 SignedByte permission = fsRdPerm;
3844 /* Descend into "lib" folder */
3845 pb.dirInfo.ioCompletion = NULL;
3846 pb.dirInfo.ioNamePtr = "\plib";
3847 pb.dirInfo.ioVRefNum = app_vol;
3848 pb.dirInfo.ioDrDirID = app_dir;
3849 pb.dirInfo.ioFDirIndex = 0;
3851 /* Check for errors */
3852 err = PBGetCatInfo((CInfoPBPtr)&pb, FALSE);
3855 if ((err == noErr) && (pb.dirInfo.ioFlAttrib & 0x10))
3857 /* Descend into "lib/save" folder */
3858 pb.dirInfo.ioCompletion = NULL;
3859 pb.dirInfo.ioNamePtr = "\pxtra";
3860 pb.dirInfo.ioVRefNum = app_vol;
3861 pb.dirInfo.ioDrDirID = pb.dirInfo.ioDrDirID;
3862 pb.dirInfo.ioFDirIndex = 0;
3864 /* Check for errors */
3865 err = PBGetCatInfo((CInfoPBPtr)&pb, FALSE);
3868 if ((err == noErr) && (pb.dirInfo.ioFlAttrib & 0x10))
3870 /* Descend into "lib/save" folder */
3871 pb.dirInfo.ioCompletion = NULL;
3872 pb.dirInfo.ioNamePtr = "\psound";
3873 pb.dirInfo.ioVRefNum = app_vol;
3874 pb.dirInfo.ioDrDirID = pb.dirInfo.ioDrDirID;
3875 pb.dirInfo.ioFDirIndex = 0;
3877 /* Check for errors */
3878 err = PBGetCatInfo((CInfoPBPtr)&pb, FALSE);
3881 if ((err == noErr) && (pb.dirInfo.ioFlAttrib & 0x10))
3883 ret = HOpenResFile( app_vol , pb.dirInfo.ioDrDirID , "\psound.rsrc" , permission );
3887 for( i = 0 ; i < 7 ; i++ )
3888 soundmode[i] = false;
3890 for( i = 1 ; i < SOUND_MAX ; i++ ){
3891 /* Get the proper sound name */
3892 sprintf((char*)sound + 1, "%.16s.wav", angband_sound_name[i]);
3893 sound[0] = strlen((char*)sound + 1);
3895 /* Obtain resource XXX XXX XXX */
3896 handle = Get1NamedResource('snd ', sound);
3897 if( handle == NULL || ext_sound )
3898 handle = GetNamedResource('snd ', sound);
3901 soundmode[soundchoice[i]] = true;
3910 static void init_graf( void )
3914 SignedByte permission = fsRdPerm;
3920 /* Descend into "lib" folder */
3921 pb.dirInfo.ioCompletion = NULL;
3922 pb.dirInfo.ioNamePtr = "\plib";
3923 pb.dirInfo.ioVRefNum = app_vol;
3924 pb.dirInfo.ioDrDirID = app_dir;
3925 pb.dirInfo.ioFDirIndex = 0;
3927 /* Check for errors */
3928 err = PBGetCatInfo((CInfoPBPtr)&pb, FALSE);
3931 if ((err == noErr) && (pb.dirInfo.ioFlAttrib & 0x10))
3933 /* Descend into "lib/xtra" folder */
3934 pb.dirInfo.ioCompletion = NULL;
3935 pb.dirInfo.ioNamePtr = "\pxtra";
3936 pb.dirInfo.ioVRefNum = app_vol;
3937 pb.dirInfo.ioDrDirID = pb.dirInfo.ioDrDirID;
3938 pb.dirInfo.ioFDirIndex = 0;
3940 /* Check for errors */
3941 err = PBGetCatInfo((CInfoPBPtr)&pb, FALSE);
3944 if ((err == noErr) && (pb.dirInfo.ioFlAttrib & 0x10))
3946 /* Descend into "lib/xtra/graf" folder */
3947 pb.dirInfo.ioCompletion = NULL;
3948 pb.dirInfo.ioNamePtr = "\pgraf";
3949 pb.dirInfo.ioVRefNum = app_vol;
3950 pb.dirInfo.ioDrDirID = pb.dirInfo.ioDrDirID;
3951 pb.dirInfo.ioFDirIndex = 0;
3953 /* Check for errors */
3954 err = PBGetCatInfo((CInfoPBPtr)&pb, FALSE);
3957 if ((err == noErr) && (pb.dirInfo.ioFlAttrib & 0x10))
3959 ret = HOpenResFile( app_vol , pb.dirInfo.ioDrDirID , "\pgraf.rsrc" , permission );
3964 /* Obtain resource XXX XXX XXX */
3965 handle = Get1NamedResource('PICT', graf);
3966 if ( handle == NULL || ext_graf )
3967 handle = GetNamedResource('PICT', "\pgraf.rsrc");
3974 #endif /* MACH_O_CARBON */
3980 static void init_chuukei( void )
3986 path_build(path, sizeof(path), ANGBAND_DIR_XTRA, "chuukei.txt");
3988 fp = fopen(path, "r");
3993 if (fgets(tmp, 1024, fp)){
3995 int n = strlen(tmp);
4001 chuukei_server = TRUE;
4002 if(connect_chuukei_server(&tmp[2])<0){
4003 msg_print("connect fail");
4006 msg_print("connect");
4013 chuukei_client = TRUE;
4014 connect_chuukei_server(&tmp[2]);
4030 short InevrtCheck( DialogPtr targetDlg, short check )
4037 GetDialogItem( targetDlg, check, &itemType, &checkH, &box );
4038 result = (GetControlValue( (ControlHandle)checkH ) + 1 ) % 2;
4039 SetControlValue( (ControlHandle)checkH , result );
4047 short SetCheck( DialogPtr targetDlg, short check, long result )
4054 GetDialogItem( targetDlg, check, &itemType, &checkH, &box );
4055 SetControlValue( (ControlHandle)checkH , result );
4063 short GetCheck( DialogPtr targetDlg, short check )
4070 GetDialogItem( targetDlg, check, &itemType, &checkH, &box );
4071 result = GetControlValue( (ControlHandle)checkH );
4075 void SoundConfigDLog(void)
4081 dialog=GetNewDialog(131, 0, (WindowPtr)-1);
4082 SetDialogDefaultItem( dialog, ok );
4083 SetDialogCancelItem( dialog, cancel );
4084 for( i = 1 ; i < 7 ; i++ )
4085 SetCheck( dialog, i+2 , soundmode[i] );
4087 /* ShowWindow(dialog); */
4088 for( item_hit = 100 ; cancel < item_hit ; ){
4089 ModalDialog(0, &item_hit);
4093 for( i = 1 ; i < 7 ; i++ )
4094 soundmode[i] = GetCheck( dialog, i+2 );
4099 InevrtCheck( dialog, item_hit );
4102 DisposeDialog(dialog);
4110 #if TARGET_API_MAC_CARBON
4111 static void save_pref_file(void)
4116 static void save_pref_file(void)
4125 /* Assume failure */
4128 /* Assume failure */
4145 /* Find the folder */
4146 err = FindFolder(kOnSystemDisk, kPreferencesFolderType, kCreateFolder,
4152 /* Extract a path name */
4153 PathNameFromDirID(dirID, vref, (StringPtr)foo);
4155 /* Convert the string */
4156 ptocstr((StringPtr)foo);
4158 /* Append the preference file name */
4159 strcat(foo, PREF_FILE_NAME);
4161 /* Open the preference file */
4162 /* my_fopen set file type and file creator for MPW */
4163 fff = my_fopen(foo, "w");
4170 #endif /* USE_SFL_CODE */
4176 HGetVol(0, &savev, &saved);
4178 /* Go to "system" folder */
4179 SysEnvirons(curSysEnvVers, &env);
4180 SetVol(0, env.sysVRefNum);
4182 /* Open the preference file */
4183 /* my_fopen set file type and file creator for MPW */
4184 fff = fopen(PREF_FILE_NAME, "w");
4187 HSetVol(0, savev, saved);
4190 /* Save preferences */
4193 /* Write the preferences */
4204 #if defined(__MWERKS__)
4207 * A simple "Yes/No" filter to parse "key press" events in dialog windows
4209 static pascal Boolean ynfilter(DialogPtr dialog, EventRecord *event, short *ip)
4211 /* Parse key press events */
4212 if (event->what == keyDown)
4217 /* Extract the pressed key */
4218 c = (event->message & charCodeMask);
4220 /* Accept "no" and <return> and <enter> */
4221 if ((c=='n') || (c=='N') || (c==13) || (c==3)) i = 1;
4224 else if ((c=='y') || (c=='Y')) i = 2;
4226 /* Handle "yes" or "no" */
4230 ControlHandle control;
4233 /* Get the button */
4234 GetDialogItem(dialog, i, &type, (Handle*)&control, &r);
4236 /* Blink button for 1/10 second */
4237 HiliteControl(control, 1);
4238 Term_xtra_mac(TERM_XTRA_DELAY, 100);
4239 HiliteControl(control, 0);
4251 #endif /* __MWERKS__ */
4254 #if TARGET_API_MAC_CARBON
4257 * Prepare savefile dialogue and set the variable
4258 * savefile accordingly. Returns true if it succeeds, false (or
4259 * aborts) otherwise. If all is false, only allow files whose type
4261 * Originally written by Peter Ammon
4263 static bool select_savefile(bool all)
4266 FSSpec theFolderSpec;
4267 FSSpec savedGameSpec;
4268 NavDialogOptions dialogOptions;
4269 NavReplyRecord reply;
4270 /* Used only when 'all' is true */
4271 NavTypeList types = {ANGBAND_CREATOR, 1, 1, {'SAVE'}};
4272 NavTypeListHandle myTypeList;
4273 AEDesc defaultLocation;
4275 #ifdef MACH_O_CARBON
4277 /* Find the save folder */
4278 err = path_to_spec(ANGBAND_DIR_SAVE, &theFolderSpec);
4282 /* Find :lib:save: folder */
4283 err = FSMakeFSSpec(app_vol, app_dir, "\p:lib:save:", &theFolderSpec);
4288 if (err != noErr) quit("Unable to find the folder :lib:save:");
4290 /* Get default Navigator dialog options */
4291 err = NavGetDefaultDialogOptions(&dialogOptions);
4293 /* Clear preview option */
4294 dialogOptions.dialogOptionFlags &= ~kNavAllowPreviews;
4296 /* Disable multiple file selection */
4297 dialogOptions.dialogOptionFlags &= ~kNavAllowMultipleFiles;
4299 /* Make descriptor for default location */
4300 err = AECreateDesc(typeFSS, &theFolderSpec, sizeof(FSSpec),
4304 if (err != noErr) quit("Unable to allocate descriptor");
4306 /* We are indifferent to signature and file types */
4309 myTypeList = (NavTypeListHandle)nil;
4312 /* Set up type handle */
4315 err = PtrToHand(&types, (Handle *)&myTypeList, sizeof(NavTypeList));
4318 if (err != noErr) quit("Error in PtrToHand. Try enlarging heap");
4322 /* Call NavGetFile() with the types list */
4323 err = NavChooseFile(&defaultLocation, &reply, &dialogOptions, NULL,
4324 NULL, NULL, myTypeList, NULL);
4326 /* Free type list */
4327 if (!all) DisposeHandle((Handle)myTypeList);
4335 /* Invalid response -- allow the user to cancel */
4336 else if (!reply.validRecord)
4338 /* Hack -- Fake error */
4342 /* Retrieve FSSpec from the reply */
4345 AEKeyword theKeyword;
4346 DescType actualType;
4349 /* Get a pointer to selected file */
4350 (void)AEGetNthPtr(&reply.selection, 1, typeFSS, &theKeyword,
4351 &actualType, &savedGameSpec, sizeof(FSSpec), &actualSize);
4353 /* Dispose NavReplyRecord, resources and descriptors */
4354 (void)NavDisposeReply(&reply);
4357 /* Dispose location info */
4358 AEDisposeDesc(&defaultLocation);
4361 if (err != noErr) return (FALSE);
4363 #ifdef MACH_O_CARBON
4365 /* Convert FSSpec to pathname and store it in variable savefile */
4366 (void)spec_to_path(&savedGameSpec, savefile, sizeof(savefile));
4370 /* Convert FSSpec to pathname and store it in variable savefile */
4373 savedGameSpec.parID,
4374 savedGameSpec.vRefNum,
4375 (char *)savedGameSpec.name);
4386 * Handle menu: "File" + "New"
4388 static void do_menu_file_new(void)
4393 /* Game is in progress */
4394 game_in_progress = 1;
4408 * Handle menu: "File" + "Open"
4410 #if TARGET_API_MAC_CARBON
4411 static void do_menu_file_open(bool all)
4413 /* Let the player to choose savefile */
4414 if (!select_savefile(all)) return;
4419 /* Game is in progress */
4420 game_in_progress = TRUE;
4432 static void do_menu_file_open(bool all)
4446 /* vrefnum = GetSFCurVol(); */
4447 vrefnum = -*((short*)0x214);
4449 /* drefnum = GetSFCurDir(); */
4450 drefnum = *((long*)0x398);
4452 /* Descend into "lib" folder */
4453 pb.ioCompletion = NULL;
4454 pb.ioNamePtr = "\plib";
4455 pb.ioVRefNum = vrefnum;
4456 pb.ioDrDirID = drefnum;
4459 /* Check for errors */
4460 err = PBGetCatInfo((CInfoPBPtr)&pb, FALSE);
4463 if ((err == noErr) && (pb.ioFlAttrib & 0x10))
4465 /* Descend into "lib/save" folder */
4466 pb.ioCompletion = NULL;
4467 pb.ioNamePtr = "\psave";
4468 pb.ioVRefNum = vrefnum;
4469 pb.ioDrDirID = pb.ioDrDirID;
4472 /* Check for errors */
4473 err = PBGetCatInfo((CInfoPBPtr)&pb, FALSE);
4476 if ((err == noErr) && (pb.ioFlAttrib & 0x10))
4478 /* SetSFCurDir(pb.ioDrDirID); */
4479 *((long*)0x398) = pb.ioDrDirID;
4483 /* Window location */
4484 topleft.h = (qd.screenBits.bounds.left+qd.screenBits.bounds.right)/2-344/2;
4485 topleft.v = (2*qd.screenBits.bounds.top+qd.screenBits.bounds.bottom)/3-188/2;
4487 /* Allow "all" files */
4491 SFGetFile(topleft, "\p", NULL, -1, types, NULL, &reply);
4494 /* Allow "save" files */
4501 SFGetFile(topleft, "\p", NULL, 1, types, NULL, &reply);
4505 if (!reply.good) return;
4507 /* Extract textual file name for save file */
4508 GetWDInfo(reply.vRefNum, &vrefnum, &drefnum, &junk);
4509 refnum_to_name(savefile, drefnum, vrefnum, (char*)reply.fName);
4514 /* Game is in progress */
4515 game_in_progress = 1;
4530 * Handle the "open_when_ready" flag
4532 static void handle_open_when_ready(void)
4534 /* Check the flag XXX XXX XXX make a function for this */
4535 if (open_when_ready && initialized && !game_in_progress)
4538 open_when_ready = FALSE;
4540 /* Game is in progress */
4541 game_in_progress = 1;
4560 * Initialize the menus
4562 * Apple (128) = { About, -, ... }
4563 * File (129) = { New,Open,Import,Close,Save,-,Exit,Quit }
4564 * Edit (130) = { Cut, Copy, Paste, Clear } (?)
4565 * Font (131) = { Bold, Extend, -, Monaco, ..., -, ... }
4566 * Size (132) = { ... }
4567 * Window (133) = { Angband, Mirror, Recall, Choice,
4568 * Term-4, Term-5, Term-6, Term-7 }
4569 * Special (134) = { Sound, Graphics, TileWidth, TileHeight, -,
4574 #define MENU_APPLE 128
4575 #define ITEM_ABOUT 1
4578 #define MENU_FILE 129
4580 # define ITEM_OPEN 2
4581 # define ITEM_IMPORT 3
4582 # define ITEM_CLOSE 4
4583 # define ITEM_SAVE 5
4584 # define ITEM_QUIT 7
4587 #define MENU_EDIT 130
4588 # define ITEM_UNDO 1
4590 # define ITEM_COPY 4
4591 # define ITEM_PASTE 5
4592 # define ITEM_CLEAR 6
4595 #define MENU_FONT 131
4596 # define ITEM_BOLD 1
4597 # define ITEM_WIDE 2
4600 #define MENU_SIZE 132
4603 #define MENU_WINDOWS 133
4606 #define MENU_SPECIAL 134
4607 # define ITEM_SOUND 1
4608 # define ITEM_GRAPH 2
4609 # define ITEM_TILEWIDTH 3
4610 # define ITEM_TILEHEIGHT 4
4611 # define ITEM_FIDDLE 6
4612 # define ITEM_WIZARD 7
4614 /* Sounds submenu */
4615 #define SUBMENU_SOUND 143
4616 # define ITEM_USE_SOUND 1
4617 # define ITEM_SOUND_SETTING 2
4619 /* Graphics submenu */
4620 #define SUBMENU_GRAPH 144
4621 # define ITEM_NONE 1
4623 # define ITEM_16X16 3
4624 # define ITEM_BIGTILE 5
4626 /* TileWidth submenu */
4627 #define SUBMENU_TILEWIDTH 145
4629 /* TileHeight submenu */
4630 #define SUBMENU_TILEHEIGHT 146
4633 static void init_menubar(void)
4645 #if TARGET_API_MAC_CARBON
4650 /* Get the "apple" menu */
4651 mbar = GetNewMBar(128);
4655 if (mbar == nil) quit("¥á¥Ë¥å¡¼¥Ð¡¼ ID 128¤ò¸«¤Ä¤±¤ë»ö¤¬¤Ç¤¤Þ¤»¤ó!");
4657 if (mbar == nil) quit("Cannot find menubar('MBAR') id 128!");
4660 /* Insert them into the current menu list */
4664 DisposeHandle(mbar);
4666 #if !TARGET_API_MAC_CARBON
4667 /* Apple menu (id 128) */
4668 m = GetMenuHandle(MENU_APPLE);
4670 /* Add the DA's to the "apple" menu */
4671 AppendResMenu (m, 'DRVR');
4674 /* Get the "File" menu */
4675 #if TARGET_API_MAC_CARBON
4676 m = GetMenu(MENU_FILE);
4677 err = Gestalt( gestaltSystemVersion, &response );
4678 if ( (err == noErr) && (response >= 0x00000A00) )
4680 DeleteMenuItem(m, ITEM_QUIT);
4684 /* Edit menu (id 130) - we don't have to do anything */
4687 * Font menu (id 131) - append names of mono-spaced fonts
4688 * followed by all available ones
4690 m = GetMenuHandle(MENU_FONT);
4693 r.left = r.right = r.top = r.bottom = 0;
4695 /* Make the fake window */
4696 tmpw = NewWindow(0, &r, "\p", false, documentProc, 0, 0, 0);
4698 /* Activate the "fake" window */
4699 #if TARGET_API_MAC_CARBON
4700 SetPortWindowPort(tmpw);
4711 /* Add the fonts to the menu */
4712 AppendResMenu(m, 'FONT');
4715 #if TARGET_API_MAC_CARBON
4716 n = CountMenuItems(m);
4722 for (i = n; i >= 4; i--)
4727 /* Acquire the font name */
4728 GetMenuItemText(m, i, tmpName);
4730 /* Acquire the font index */
4731 #if TARGET_API_MAC_CARBON
4732 fontNum = FMGetFontFamilyFromName( tmpName );
4734 GetFNum(tmpName, &fontNum);
4737 /* Apply the font index */
4740 /* Remove non-mono-spaced fonts */
4741 if ((CharWidth('i') != CharWidth('W')) || (CharWidth('W') == 0))
4743 /* Delete the menu item XXX XXX XXX */
4744 DeleteMenuItem (m, i);
4748 /* Destroy the old window */
4749 DisposeWindow(tmpw);
4751 /* Add a separator */
4752 AppendMenu(m, "\p-");
4754 /* Add the fonts to the menu */
4755 AppendResMenu (m, 'FONT');
4758 /* Size menu (id 132) */
4759 m = GetMenuHandle(MENU_SIZE);
4761 /* Add some sizes (stagger choices) */
4762 for (i = 8; i <= 32; i += ((i / 16) + 1))
4767 sprintf((char*)buf + 1, "%d", i);
4768 buf[0] = strlen((char*)buf + 1);
4775 /* Windows menu (id 133) */
4776 m = GetMenuHandle(MENU_WINDOWS);
4778 /* Default choices */
4779 for (i = 0; i < MAX_TERM_DATA; i++)
4783 /* Describe the item */
4784 sprintf((char*)buf + 1, "%.15s", angband_term_name[i]);
4785 buf[0] = strlen((char*)buf + 1);
4790 /* Command-Key shortcuts */
4791 if (i < 8) SetItemCmd(m, i + 1, '0' + i);
4795 #if TARGET_API_MAC_CARBON && !defined(MAC_MPW)
4797 /* CW or gcc -- Use recommended interface for hierarchical menus */
4799 /* Special menu (id 134) */
4800 m = GetMenuHandle(MENU_SPECIAL);
4802 /* Insert Graphics submenu (id 143) */
4806 /* Get the submenu */
4807 submenu = GetMenu(SUBMENU_SOUND);
4810 SetMenuItemHierarchicalMenu(m, ITEM_SOUND, submenu);
4813 /* Insert Graphics submenu (id 144) */
4817 /* Get the submenu */
4818 submenu = GetMenu(SUBMENU_GRAPH);
4821 SetMenuItemHierarchicalMenu(m, ITEM_GRAPH, submenu);
4824 /* Insert TileWidth submenu (id 145) */
4828 /* Get the submenu */
4829 submenu = GetMenu(SUBMENU_TILEWIDTH);
4831 /* Add some sizes */
4832 for (i = 4, n = 1; i <= 32; i++, n++)
4837 strnfmt((char*)buf + 1, 15, "%d", i);
4838 buf[0] = strlen((char*)buf + 1);
4841 AppendMenu(submenu, buf);
4845 SetMenuItemHierarchicalMenu(m, ITEM_TILEWIDTH, submenu);
4848 /* Insert TileHeight submenu (id 146) */
4852 /* Get the submenu */
4853 submenu = GetMenu(SUBMENU_TILEHEIGHT);
4856 /* Add some sizes */
4857 for (i = 4, n = 1; i <= 32; i++, n++)
4862 strnfmt((char*)buf + 1, 15, "%d", i);
4863 buf[0] = strlen((char*)buf + 1);
4866 AppendMenu(submenu, buf);
4870 SetMenuItemHierarchicalMenu(m, ITEM_TILEHEIGHT, submenu);
4875 /* Special menu (id 134) */
4877 /* Get graphics (sub)menu (id 143) */
4878 m = GetMenu(SUBMENU_SOUND);
4880 /* Insert it as a submenu */
4881 InsertMenu(m, hierMenu);
4884 /* Get graphics (sub)menu (id 144) */
4885 m = GetMenu(SUBMENU_GRAPH);
4887 /* Insert it as a submenu */
4888 InsertMenu(m, hierMenu);
4891 /* Get TileWidth (sub)menu (id 145) */
4892 m = GetMenu(SUBMENU_TILEWIDTH);
4894 /* Add some sizes */
4895 for (i = 4; i <= 32; i++)
4900 sprintf((char*)buf + 1, "%d", i);
4901 buf[0] = strlen((char*)buf + 1);
4908 /* Insert it as a submenu */
4909 InsertMenu(m, hierMenu);
4911 /* Get TileHeight (sub)menu (id 146) */
4912 m = GetMenu(SUBMENU_TILEHEIGHT);
4914 /* Add some sizes */
4915 for (i = 4; i <= 32; i++)
4920 sprintf((char*)buf + 1, "%d", i);
4921 buf[0] = strlen((char*)buf + 1);
4928 /* Insert the menu */
4929 InsertMenu(m, hierMenu);
4932 /* Update the menu bar */
4940 static void setup_menus(void)
4950 term_data *td = NULL;
4953 /* Relevant "term_data" */
4954 for (i = 0; i < MAX_TERM_DATA; i++)
4957 if (!data[i].t) continue;
4959 /* Notice the matching window */
4960 if (data[i].w == FrontWindow()) td = &data[i];
4965 m = GetMenuHandle(MENU_FILE);
4968 #if TARGET_API_MAC_CARBON
4969 n = CountMenuItems(m);
4975 for (i = 1; i <= n; i++)
4978 #if TARGET_API_MAC_CARBON
4979 DisableMenuItem(m, i);
4980 CheckMenuItem(m, i, FALSE);
4983 CheckItem(m, i, FALSE);
4987 /* Enable "new"/"open..."/"import..." */
4988 if (initialized && !game_in_progress)
4990 #if TARGET_API_MAC_CARBON
4991 EnableMenuItem(m, ITEM_NEW);
4992 EnableMenuItem(m, ITEM_OPEN);
4993 EnableMenuItem(m, ITEM_IMPORT);
4995 EnableItem(m, ITEM_NEW);
4996 EnableItem(m, ITEM_OPEN);
4997 EnableItem(m, ITEM_IMPORT);
5001 /* Enable "close" */
5004 #if TARGET_API_MAC_CARBON
5005 EnableMenuItem(m, ITEM_CLOSE);
5007 EnableItem(m, ITEM_CLOSE);
5012 if (initialized && character_generated)
5014 #if TARGET_API_MAC_CARBON
5015 EnableMenuItem(m, ITEM_SAVE);
5017 EnableItem(m, ITEM_SAVE);
5024 #if TARGET_API_MAC_CARBON
5025 EnableMenuItem(m, ITEM_QUIT);
5027 EnableItem(m, ITEM_QUIT);
5033 m = GetMenuHandle(MENU_EDIT);
5036 #if TARGET_API_MAC_CARBON
5037 n = CountMenuItems(m);
5043 for (i = 1; i <= n; i++)
5046 #if TARGET_API_MAC_CARBON
5047 DisableMenuItem(m, i);
5048 CheckMenuItem(m, i, FALSE);
5051 CheckItem(m, i, FALSE);
5055 /* Enable "edit" options if "needed" */
5058 #if TARGET_API_MAC_CARBON
5059 EnableMenuItem(m, ITEM_UNDO);
5060 EnableMenuItem(m, ITEM_CUT);
5061 EnableMenuItem(m, ITEM_COPY);
5062 EnableMenuItem(m, ITEM_PASTE);
5063 EnableMenuItem(m, ITEM_CLEAR);
5065 EnableItem(m, ITEM_UNDO);
5066 EnableItem(m, ITEM_CUT);
5067 EnableItem(m, ITEM_COPY);
5068 EnableItem(m, ITEM_PASTE);
5069 EnableItem(m, ITEM_CLEAR);
5075 m = GetMenuHandle(MENU_FONT);
5078 #if TARGET_API_MAC_CARBON
5079 n = CountMenuItems(m);
5085 for (i = 1; i <= n; i++)
5088 #if TARGET_API_MAC_CARBON
5089 DisableMenuItem(m, i);
5090 CheckMenuItem(m, i, FALSE);
5093 CheckItem(m, i, FALSE);
5097 /* Hack -- look cute XXX XXX */
5098 /* SetItemStyle(m, 1, bold); */
5100 /* Hack -- look cute XXX XXX */
5101 /* SetItemStyle(m, 2, extend); */
5106 #if TARGET_API_MAC_CARBON
5108 EnableMenuItem(m, ITEM_BOLD);
5110 /* Enable "extend" */
5111 EnableMenuItem(m, ITEM_WIDE);
5113 /* Check the appropriate "bold-ness" */
5114 if (td->font_face & bold) CheckMenuItem(m, ITEM_BOLD, TRUE);
5116 /* Check the appropriate "wide-ness" */
5117 if (td->font_face & extend) CheckMenuItem(m, ITEM_WIDE, TRUE);
5120 for (i = 4; i <= n; i++)
5123 EnableMenuItem(m, i);
5126 GetMenuItemText(m, i, s);
5129 /* Check active font */
5130 if (td->font_id == value) CheckMenuItem(m, i, TRUE);
5134 EnableItem(m, ITEM_BOLD);
5136 /* Enable "extend" */
5137 EnableItem(m, ITEM_WIDE);
5139 /* Check the appropriate "bold-ness" */
5140 if (td->font_face & bold) CheckItem(m, ITEM_BOLD, TRUE);
5142 /* Check the appropriate "wide-ness" */
5143 if (td->font_face & extend) CheckItem(m, ITEM_WIDE, TRUE);
5146 for (i = 4; i <= n; i++)
5152 GetMenuItemText(m, i, s);
5155 /* Check active font */
5156 if (td->font_id == value) CheckItem(m, i, TRUE);
5163 m = GetMenuHandle(MENU_SIZE);
5166 #if TARGET_API_MAC_CARBON
5167 n = CountMenuItems(m);
5173 for (i = 1; i <= n; i++)
5176 #if TARGET_API_MAC_CARBON
5177 DisableMenuItem(m, i);
5178 CheckMenuItem(m, i, FALSE);
5181 CheckItem(m, i, FALSE);
5189 for (i = 1; i <= n; i++)
5192 GetMenuItemText(m, i, s);
5194 value = atoi((char*)(s+1));
5196 #if TARGET_API_MAC_CARBON
5197 /* Enable the "real" sizes */
5198 if (RealFont(td->font_id, value)) EnableMenuItem(m, i);
5200 /* Check the current size */
5201 if (td->font_size == value) CheckMenuItem(m, i, TRUE);
5203 /* Enable the "real" sizes */
5204 if (RealFont(td->font_id, value)) EnableItem(m, i);
5206 /* Check the current size */
5207 if (td->font_size == value) CheckItem(m, i, TRUE);
5214 m = GetMenuHandle(MENU_WINDOWS);
5217 #if TARGET_API_MAC_CARBON
5218 n = CountMenuItems(m);
5223 /* Check active windows */
5224 for (i = 1; i <= n; i++)
5226 /* Check if needed */
5227 #if TARGET_API_MAC_CARBON
5228 CheckMenuItem(m, i, data[i-1].mapped);
5230 CheckItem(m, i, data[i-1].mapped);
5236 m = GetMenuHandle(MENU_SPECIAL);
5239 #if TARGET_API_MAC_CARBON
5240 n = CountMenuItems(m);
5246 for (i = 1; i <= n; i++)
5249 #if TARGET_API_MAC_CARBON
5250 DisableMenuItem(m, i);
5253 /* XXX Oh no, this removes submenu... */
5254 if ((i != ITEM_SOUND) &&
5255 (i != ITEM_GRAPH) &&
5256 (i != ITEM_TILEWIDTH) &&
5257 (i != ITEM_TILEHEIGHT)) CheckMenuItem(m, i, FALSE);
5260 CheckMenuItem(m, i, FALSE);
5266 /* XXX Oh no, this removes submenu... */
5267 if ((i != ITEM_SOUND) &&
5268 (i != ITEM_GRAPH) &&
5269 (i != ITEM_TILEWIDTH) &&
5270 (i != ITEM_TILEHEIGHT)) CheckItem(m, i, FALSE);
5274 #if TARGET_API_MAC_CARBON
5275 /* Item "arg_sound" */
5276 EnableMenuItem(m, ITEM_SOUND);
5282 /* MPW's Universal Interface is a bit out of date */
5284 /* Graphics submenu */
5285 submenu = GetMenuHandle(SUBMENU_SOUND);
5289 /* Graphics submenu */
5290 (void)GetMenuItemHierarchicalMenu(m, ITEM_SOUND, &submenu);
5295 n = CountMenuItems(submenu);
5298 for (i = 1; i <= n; i++)
5301 DisableMenuItem(submenu, i);
5302 CheckMenuItem(submenu, i, FALSE);
5305 /* Item "Sound On/Off" */
5306 EnableMenuItem(submenu, ITEM_USE_SOUND);
5307 CheckMenuItem(submenu, ITEM_USE_SOUND, arg_sound);
5309 /* Item "Sounf Config" */
5310 #ifndef MACH_O_CARBON
5311 EnableMenuItem(submenu, ITEM_SOUND_SETTING);
5315 /* Item "Graphics" */
5316 EnableMenuItem(m, ITEM_GRAPH);
5322 /* MPW's Universal Interface is a bit out of date */
5324 /* Graphics submenu */
5325 submenu = GetMenuHandle(SUBMENU_GRAPH);
5329 /* Graphics submenu */
5330 (void)GetMenuItemHierarchicalMenu(m, ITEM_GRAPH, &submenu);
5335 n = CountMenuItems(submenu);
5338 for (i = 1; i <= n; i++)
5341 DisableMenuItem(submenu, i);
5342 CheckMenuItem(submenu, i, FALSE);
5346 EnableMenuItem(submenu, ITEM_NONE);
5347 CheckMenuItem(submenu, ITEM_NONE, (graf_mode == GRAF_MODE_NONE));
5350 EnableMenuItem(submenu, ITEM_8X8);
5351 CheckMenuItem(submenu, ITEM_8X8, (graf_mode == GRAF_MODE_8X8));
5354 EnableMenuItem(submenu, ITEM_16X16);
5355 CheckMenuItem(submenu, ITEM_16X16, (graf_mode == GRAF_MODE_16X16));
5357 /* Item "Big tiles" */
5358 EnableMenuItem(submenu, ITEM_BIGTILE);
5359 CheckMenuItem(submenu, ITEM_BIGTILE, arg_bigtile);
5362 /* Item "TileWidth" */
5363 EnableMenuItem(m, ITEM_TILEWIDTH);
5369 /* MPW's Universal Interface is a bit out of date */
5371 /* TIleWidth submenu */
5372 submenu = GetMenuHandle(SUBMENU_TILEWIDTH);
5376 /* TileWidth submenu */
5377 (void)GetMenuItemHierarchicalMenu(m, ITEM_TILEWIDTH, &submenu);
5382 n = CountMenuItems(submenu);
5385 for (i = 1; i <= n; i++)
5388 DisableMenuItem(submenu, i);
5389 CheckMenuItem(submenu, i, FALSE);
5396 for (i = 1; i <= n; i++)
5399 /* GetMenuItemText(m,i,s); */
5400 GetMenuItemText(submenu, i, s);
5402 value = atoi((char*)(s+1));
5405 if (value >= td->font_wid) EnableMenuItem(submenu, i);
5407 /* Check the current size */
5408 if (td->tile_wid == value) CheckMenuItem(submenu, i, TRUE);
5413 /* Item "TileHeight" */
5414 EnableMenuItem(m, ITEM_TILEHEIGHT);
5420 /* MPW's Universal Interface is a bit out of date */
5422 /* TileHeight submenu */
5423 submenu = GetMenuHandle(SUBMENU_TILEHEIGHT);
5427 /* TileWidth submenu */
5428 (void)GetMenuItemHierarchicalMenu(m, ITEM_TILEHEIGHT, &submenu);
5433 n = CountMenuItems(submenu);
5436 for (i = 1; i <= n; i++)
5439 DisableMenuItem(submenu, i);
5440 CheckMenuItem(submenu, i, FALSE);
5447 for (i = 1; i <= n; i++)
5450 /* GetMenuItemText(m,i,s); */
5451 GetMenuItemText(submenu, i, s);
5453 value = atoi((char*)(s+1));
5456 if (value >= td->font_hgt) EnableMenuItem(submenu, i);
5458 /* Check the current size */
5459 if (td->tile_hgt == value) CheckMenuItem(submenu, i, TRUE);
5464 /* Item "arg_fiddle" */
5465 EnableMenuItem(m, ITEM_FIDDLE);
5466 CheckMenuItem(m, ITEM_FIDDLE, arg_fiddle);
5468 /* Item "arg_wizard" */
5469 EnableMenuItem(m, ITEM_WIZARD);
5470 CheckMenuItem(m, ITEM_WIZARD, arg_wizard);
5473 /* Item "arg_sound" */
5474 EnableItem(m, ITEM_SOUND);
5476 /* Item "arg_graphics" */
5477 EnableItem(m, ITEM_GRAPH);
5479 /* Item "TileWidth" */
5480 EnableItem(m, ITEM_TILEWIDTH);
5482 /* Item "TileHeight" */
5483 EnableItem(m, ITEM_TILEHEIGHT);
5485 /* Item "arg_fiddle" */
5486 EnableItem(m, ITEM_FIDDLE);
5487 CheckItem(m, ITEM_FIDDLE, arg_fiddle);
5489 /* Item "arg_wizard" */
5490 EnableItem(m, ITEM_WIZARD);
5491 CheckItem(m, ITEM_WIZARD, arg_wizard);
5493 /* Sounds submenu */
5494 m = GetMenuHandle(SUBMENU_SOUND);
5500 for (i = 1; i <= n; i++)
5504 CheckItem(m, i, FALSE);
5507 /* Item "Sound On/Off" */
5508 EnableItem(m, ITEM_USE_SOUND);
5509 CheckItem(m, ITEM_USE_SOUND, arg_sound);
5511 /* Item "Sound Config" */
5512 EnableItem(m, ITEM_SOUND_SETTING);
5514 /* Graphics submenu */
5515 m = GetMenuHandle(SUBMENU_GRAPH);
5521 for (i = 1; i <= n; i++)
5525 CheckItem(m, i, FALSE);
5529 EnableItem(m, ITEM_NONE);
5530 CheckItem(m, ITEM_NONE, (graf_mode == GRAF_MODE_NONE));
5533 EnableItem(m, ITEM_8X8);
5534 CheckItem(m, ITEM_8X8, (graf_mode == GRAF_MODE_8X8));
5537 EnableItem(m, ITEM_16X16);
5538 CheckItem(m, ITEM_16X16, (graf_mode == GRAF_MODE_16X16));
5540 /* Item "Bigtile" */
5541 EnableItem(m, ITEM_BIGTILE);
5542 CheckItem(m, ITEM_BIGTILE, arg_bigtile);
5545 /* TIleWidth submenu */
5546 m = GetMenuHandle(SUBMENU_TILEWIDTH);
5552 for (i = 1; i <= n; i++)
5556 CheckItem(m, i, FALSE);
5563 for (i = 1; i <= n; i++)
5566 /* GetMenuItemText(m,i,s); */
5567 GetMenuItemText(m, i, s);
5569 value = atoi((char*)(s+1));
5572 if (value >= td->font_wid) EnableItem(m, i);
5574 /* Check the current size */
5575 if (td->tile_wid == value) CheckItem(m, i, TRUE);
5580 /* TileHeight submenu */
5581 m = GetMenuHandle(SUBMENU_TILEHEIGHT);
5587 for (i = 1; i <= n; i++)
5591 CheckItem(m, i, FALSE);
5598 for (i = 1; i <= n; i++)
5601 GetMenuItemText(m, i, s);
5603 value = atoi((char*)(s+1));
5606 if (value >= td->font_hgt) EnableItem(m, i);
5608 /* Check the current size */
5609 if (td->tile_hgt == value) CheckItem(m, i, TRUE);
5618 * Process a menu selection (see above)
5620 * Hack -- assume that invalid menu selections are disabled above,
5621 * which I have been informed may not be reliable. XXX XXX XXX
5623 static void menu(long mc)
5627 int menuid, selection;
5629 static unsigned char s[1000];
5633 term_data *td = NULL;
5638 /* Analyze the menu command */
5639 menuid = HiWord(mc);
5640 selection = LoWord(mc);
5643 /* Find the window */
5644 for (i = 0; i < MAX_TERM_DATA; i++)
5646 /* Skip dead windows */
5647 if (!data[i].t) continue;
5649 /* Notice matches */
5650 if (data[i].w == FrontWindow()) td = &data[i];
5654 /* Branch on the menu */
5660 /* About Angband... */
5661 #if TARGET_API_MAC_CARBON
5662 if (selection == ITEM_ABOUT)
5667 /* Get the about dialogue */
5668 dialog=GetNewDialog(128, 0, (WindowPtr)-1);
5670 /* Move it to the middle of the screen */
5672 GetDialogWindow(dialog),
5674 kWindowCenterOnMainScreen);
5676 /* Show the dialog */
5677 TransitionWindow(GetDialogWindow(dialog),
5678 kWindowZoomTransitionEffect,
5679 kWindowShowTransitionAction,
5682 /* Wait for user to click on it */
5683 ModalDialog(0, &item_hit);
5685 /* Free the dialogue */
5686 DisposeDialog(dialog);
5690 if (selection == ITEM_ABOUT)
5696 dialog=GetNewDialog(128, 0, (WindowPtr)-1);
5699 center_rect(&r, &qd.screenBits.bounds);
5700 MoveWindow(dialog, r.left, r.top, 1);
5702 ModalDialog(0, &item_hit);
5703 DisposeDialog(dialog);
5707 /* Desk accessory */
5708 GetMenuItemText(GetMenuHandle(MENU_APPLE), selection, s);
5729 do_menu_file_open(FALSE);
5736 do_menu_file_open(TRUE);
5750 td->t->mapped_flag = FALSE;
5752 /* Hide the window */
5763 plog("º£¤Ï¥»¡¼¥Ö¤¹¤ë¤³¤È¤Ï½ÐÍè¤Þ¤»¤ó¡£");
5765 plog("You may not do that right now.");
5770 /* Hack -- Forget messages */
5773 /* Hack -- Save the game */
5774 do_cmd_save_game(FALSE);
5779 /* Quit (with save) */
5782 /* Save the game (if necessary) */
5783 if (game_in_progress && character_generated)
5787 plog("º£¤Ï¥»¡¼¥Ö¤¹¤ë¤³¤È¤Ï½ÐÍè¤Þ¤»¤ó¡£");
5789 plog("You may not do that right now.");
5793 /* Hack -- Forget messages */
5798 do_cmd_save_game(FALSE);
5800 Term_key_push(SPECIAL_KEY_QUIT);
5822 /* Require a window */
5831 /* Toggle the "bold" setting */
5832 if (selection == ITEM_BOLD)
5834 /* Toggle the setting */
5835 if (td->font_face & bold)
5837 td->font_face &= ~bold;
5841 td->font_face |= bold;
5844 /* Tile Width Hight Init */
5845 td->tile_wid = td->tile_hgt = 0;
5847 /* Apply and Verify */
5848 term_data_check_font(td);
5849 term_data_check_size(td);
5851 /* Resize and Redraw */
5852 term_data_resize(td);
5853 term_data_redraw(td);
5858 /* Toggle the "wide" setting */
5859 if (selection == ITEM_WIDE)
5861 /* Toggle the setting */
5862 if (td->font_face & extend)
5864 td->font_face &= ~extend;
5868 td->font_face |= extend;
5871 /* Tile Width Hight Init */
5872 td->tile_wid = td->tile_hgt = 0;
5874 /* Apply and Verify */
5875 term_data_check_font(td);
5876 term_data_check_size(td);
5878 /* Resize and Redraw */
5879 term_data_resize(td);
5880 term_data_redraw(td);
5885 /* Get a new font name */
5886 GetMenuItemText(GetMenuHandle(MENU_FONT), selection, s);
5889 /* Save the new font id */
5892 /* Current size is bad for new font */
5893 if (!RealFont(td->font_id, td->font_size))
5895 /* Find similar size */
5896 for (i = 1; i <= 32; i++)
5898 /* Adjust smaller */
5899 if (td->font_size - i >= 8)
5901 if (RealFont(td->font_id, td->font_size - i))
5909 if (td->font_size + i <= 128)
5911 if (RealFont(td->font_id, td->font_size + i))
5920 /* Tile Width Hight Init */
5921 td->tile_wid = td->tile_hgt = 0;
5923 /* Apply and Verify */
5924 term_data_check_font(td);
5925 term_data_check_size(td);
5927 /* Resize and Redraw */
5928 term_data_resize(td);
5929 term_data_redraw(td);
5931 /* Restore the window */
5948 GetMenuItemText(GetMenuHandle(MENU_SIZE), selection, s);
5950 td->font_size = atoi((char*)(s+1));
5952 /* Tile Width Hight Init */
5953 td->tile_wid = td->tile_hgt = 0;
5955 /* Apply and Verify */
5956 term_data_check_font(td);
5957 term_data_check_size(td);
5959 /* Resize and Redraw */
5960 term_data_resize(td);
5961 term_data_redraw(td);
5975 /* Check legality of choice */
5976 if ((i < 0) || (i >= MAX_TERM_DATA)) break;
5978 /* Obtain the window */
5988 td->t->mapped_flag = TRUE;
5990 /* Show the window */
5993 /* Bring to the front */
5994 SelectWindow(td->w);
6006 arg_fiddle = !arg_fiddle;
6012 arg_wizard = !arg_wizard;
6020 /* Sounds submenu */
6025 case ITEM_USE_SOUND:
6027 /* Toggle arg_sound */
6028 arg_sound = !arg_sound;
6030 /* React to changes */
6031 Term_xtra(TERM_XTRA_REACT, 0);
6036 case ITEM_SOUND_SETTING:
6047 /* Graphics submenu */
6054 graf_mode_req = GRAF_MODE_NONE;
6061 graf_mode_req = GRAF_MODE_8X8;
6068 graf_mode_req = GRAF_MODE_16X16;
6076 term_data *td = &data[0];
6078 /* Toggle "arg_bigtile" */
6079 arg_bigtile = !arg_bigtile;
6082 Term_activate(td->t);
6084 /* Resize the term */
6085 Term_resize(td->cols, td->rows);
6094 /* Hack -- Force redraw */
6095 Term_key_push(KTRL('R'));
6100 /* TileWidth submenu */
6101 case SUBMENU_TILEWIDTH:
6112 GetMenuItemText(GetMenuHandle(SUBMENU_TILEWIDTH), selection, s);
6114 td->tile_wid = atoi((char*)(s+1));
6116 /* Apply and Verify */
6117 term_data_check_size(td);
6119 /* Resize and Redraw */
6120 term_data_resize(td);
6121 term_data_redraw(td);
6129 /* TileHeight submenu */
6130 case SUBMENU_TILEHEIGHT:
6141 GetMenuItemText(GetMenuHandle(SUBMENU_TILEHEIGHT), selection, s);
6143 td->tile_hgt = atoi((char*)(s+1));
6145 /* Apply and Verify */
6146 term_data_check_size(td);
6148 /* Resize and Redraw */
6149 term_data_resize(td);
6150 term_data_redraw(td);
6160 /* Clean the menu */
6169 * Check for extra required parameters -- From "Maarten Hazewinkel"
6171 static OSErr CheckRequiredAEParams(const AppleEvent *theAppleEvent)
6174 DescType returnedType;
6177 aeError = AEGetAttributePtr(theAppleEvent, keyMissedKeywordAttr, typeWildCard,
6178 &returnedType, NULL, 0, &actualSize);
6180 if (aeError == errAEDescNotFound) return (noErr);
6182 if (aeError == noErr) return (errAEParamMissed);
6189 * Apple Event Handler -- Open Application
6191 static pascal OSErr AEH_Start(const AppleEvent *theAppleEvent,
6192 AppleEvent *reply, long handlerRefCon)
6194 #pragma unused(reply, handlerRefCon)
6196 return (CheckRequiredAEParams(theAppleEvent));
6201 * Apple Event Handler -- Quit Application
6203 static pascal OSErr AEH_Quit(const AppleEvent *theAppleEvent,
6204 AppleEvent *reply, long handlerRefCon)
6206 #pragma unused(reply, handlerRefCon)
6207 #if TARGET_API_MAC_CARBON
6208 #pragma unused(theAppleEvent)
6210 /* Save the game (if necessary) */
6211 if (game_in_progress && character_generated)
6215 plog("º£¤Ï¥»¡¼¥Ö¤¹¤ë¤³¤È¤Ï½ÐÍè¤Þ¤»¤ó¡£");
6217 plog("You may not do that right now.");
6221 /* Hack -- Forget messages */
6226 do_cmd_save_game(FALSE);
6228 Term_key_push(SPECIAL_KEY_QUIT);
6236 quit_when_ready = TRUE;
6238 /* Check arguments */
6239 return (CheckRequiredAEParams(theAppleEvent));
6245 * Apple Event Handler -- Print Documents
6247 static pascal OSErr AEH_Print(const AppleEvent *theAppleEvent,
6248 AppleEvent *reply, long handlerRefCon)
6250 #pragma unused(theAppleEvent, reply, handlerRefCon)
6252 return (errAEEventNotHandled);
6257 * Apple Event Handler by Steve Linberg (slinberg@crocker.com).
6259 * The old method of opening savefiles from the finder does not work
6260 * on the Power Macintosh, because CountAppFiles and GetAppFiles,
6261 * used to return information about the selected document files when
6262 * an application is launched, are part of the Segment Loader, which
6263 * is not present in the RISC OS due to the new memory architecture.
6265 * The "correct" way to do this is with AppleEvents. The following
6266 * code is modeled on the "Getting Files Selected from the Finder"
6267 * snippet from Think Reference 2.0. (The prior sentence could read
6268 * "shamelessly swiped & hacked")
6270 static pascal OSErr AEH_Open(const AppleEvent *theAppleEvent,
6271 AppleEvent* reply, long handlerRefCon)
6273 #pragma unused(reply, handlerRefCon)
6280 DescType returnedType;
6284 /* Put the direct parameter (a descriptor list) into a docList */
6285 err = AEGetParamDesc(theAppleEvent, keyDirectObject, typeAEList, &docList);
6286 if (err) return err;
6289 * We ignore the validity check, because we trust the FInder, and we only
6290 * allow one savefile to be opened, so we ignore the depth of the list.
6293 err = AEGetNthPtr(&docList, 1L, typeFSS, &keywd,
6294 &returnedType, (Ptr) &myFSS, sizeof(myFSS), &actualSize);
6295 if (err) return err;
6297 /* Only needed to check savefile type below */
6298 err = FSpGetFInfo(&myFSS, &myFileInfo);
6301 sprintf(foo, "Arg! FSpGetFInfo failed with code %d", err);
6306 /* Ignore non 'SAVE' files */
6307 if (myFileInfo.fdType != 'SAVE') return noErr;
6309 #ifdef MACH_O_CARBON
6311 /* Extract a file name */
6312 (void)spec_to_path(&myFSS, savefile, sizeof(savefile));
6316 /* XXX XXX XXX Extract a file name */
6317 PathNameFromDirID(myFSS.parID, myFSS.vRefNum, (StringPtr)savefile);
6318 pstrcat((StringPtr)savefile, (StringPtr)&myFSS.name);
6320 /* Convert the string */
6321 ptocstr((StringPtr)savefile);
6323 #endif /* MACH_O_CARBON */
6325 /* Delay actual open */
6326 open_when_ready = TRUE;
6329 err = AEDisposeDesc(&docList);
6341 * Macintosh modifiers (event.modifier & ccc):
6342 * cmdKey, optionKey, shiftKey, alphaLock, controlKey
6345 * Macintosh Keycodes (0-63 normal, 64-95 keypad, 96-127 extra):
6390 * Optimize non-blocking calls to "CheckEvents()"
6391 * Idea from "Maarten Hazewinkel <mmhazewi@cs.ruu.nl>"
6393 #define EVENT_TICKS 6
6397 * Check for Events, return TRUE if we process any
6399 * Hack -- Handle AppleEvents if appropriate (ignore result code).
6401 static bool CheckEvents(bool wait)
6417 term_data *td = NULL;
6421 static huge lastTicks = 0L;
6424 /* Access the clock */
6425 curTicks = TickCount();
6427 /* Hack -- Allow efficient checking for non-pending events */
6428 if (!wait && (curTicks < lastTicks + EVENT_TICKS)) return (FALSE);
6430 /* Timestamp last check */
6431 lastTicks = curTicks;
6433 #if TARGET_API_MAC_CARBON
6434 WaitNextEvent( everyEvent, &event, 1L, nil );
6436 /* Let the "system" run */
6439 /* Get an event (or null) */
6440 GetNextEvent(everyEvent, &event);
6443 /* Hack -- Nothing is ready yet */
6444 if (event.what == nullEvent) return (FALSE);
6446 /* Analyze the event */
6454 w = (WindowPtr)event.message;
6465 /* Extract the window */
6466 w = (WindowPtr)event.message;
6468 /* Find the window */
6469 for (i = 0; i < MAX_TERM_DATA; i++)
6471 /* Skip dead windows */
6472 if (!data[i].t) continue;
6474 /* Notice matches */
6475 if (data[i].w == w) td = &data[i];
6478 /* Hack XXX XXX XXX */
6482 /* Redraw the window */
6483 if (td) term_data_redraw(td);
6491 /* Extract some modifiers */
6492 mc = (event.modifiers & controlKey) ? TRUE : FALSE;
6493 ms = (event.modifiers & shiftKey) ? TRUE : FALSE;
6494 mo = (event.modifiers & optionKey) ? TRUE : FALSE;
6495 mx = (event.modifiers & cmdKey) ? TRUE : FALSE;
6497 /* Keypress: (only "valid" if ck < 96) */
6498 ch = (event.message & charCodeMask) & 255;
6500 /* Keycode: see table above */
6501 ck = ((event.message & keyCodeMask) >> 8) & 255;
6503 /* Command + "normal key" -> menu action */
6504 if (mx && (ck < 64))
6506 /* Hack -- Prepare the menus */
6509 /* Run the Menu-Handler */
6512 /* Turn off the menus */
6520 /* Hide the mouse pointer */
6523 /* Normal key -> simple keypress */
6526 /* Enqueue the keypress */
6530 /* Bizarre key -> encoded keypress */
6533 /* Hack -- introduce with control-underscore */
6536 /* Send some modifier keys */
6537 if (mc) Term_keypress('C');
6538 if (ms) Term_keypress('S');
6539 if (mo) Term_keypress('O');
6540 if (mx) Term_keypress('X');
6542 /* Hack -- Downshift and encode the keycode */
6543 Term_keypress('0' + (ck - 64) / 10);
6544 Term_keypress('0' + (ck - 64) % 10);
6546 /* Hack -- Terminate the sequence */
6547 /* MPW can generate 10 or 13 for keycode of '\r' */
6548 /* -noMapCR option swaps '\r' and '\n' */
6549 Term_keypress('\r');
6559 /* Analyze click location */
6560 code = FindWindow(event.where, &w);
6562 /* Find the window */
6563 for (i = 0; i < MAX_TERM_DATA; i++)
6565 /* Skip dead windows */
6566 if (!data[i].t) continue;
6568 /* Notice matches */
6569 if (data[i].w == w) td = &data[i];
6578 menu(MenuSelect(event.where));
6582 #if !TARGET_API_MAC_CARBON
6585 SystemClick(&event, w);
6597 #if TARGET_API_MAC_CARBON
6598 GetQDGlobalsScreenBits( &screen );
6600 screen = qd.screenBits;
6603 r.top += 20; /* GetMBarHeight() XXX XXX XXX */
6604 InsetRect(&r, 4, 4);
6605 DragWindow(w, event.where, &r);
6617 #if TARGET_API_MAC_CARBON
6618 GetWindowBounds( (WindowRef)td->w, kWindowContentRgn, &portRect );
6620 portRect = td->w->portRect;
6621 local_to_global( &portRect );
6623 p.h = portRect.left;
6625 #if !TARGET_API_MAC_CARBON
6634 /* Apply and Verify */
6635 term_data_check_size(td);
6645 /* Track the go-away box */
6646 if (TrackGoAway(w, event.where))
6652 td->t->mapped_flag = FALSE;
6654 /* Hide the window */
6668 #if TARGET_API_MAC_CARBON
6669 GetQDGlobalsScreenBits( &screen );
6671 screen = qd.screenBits;
6676 /* Fake rectangle */
6677 r.left = 20 * td->tile_wid + td->size_ow1;
6678 r.right = screen.bounds.right;
6679 r.top = 1 * td->tile_hgt + td->size_oh1;
6680 r.bottom = screen.bounds.bottom;
6682 /* Grow the rectangle */
6683 newsize = GrowWindow(w, event.where, &r);
6686 if (!newsize) break;
6688 /* Extract the new size in pixels */
6689 y = HiWord(newsize) - td->size_oh1 - td->size_oh2;
6690 x = LoWord(newsize) - td->size_ow1 - td->size_ow2;
6692 /* Extract a "close" approximation */
6693 td->rows = y / td->tile_hgt;
6694 td->cols = x / td->tile_wid;
6696 /* Apply and Verify */
6697 term_data_check_size(td);
6699 Term_activate(td->t);
6701 /* Hack -- Resize the term */
6702 Term_resize(td->cols, td->rows);
6704 /* Resize and Redraw */
6705 term_data_resize(td);
6706 term_data_redraw(td);
6725 /* Disk Event -- From "Maarten Hazewinkel" */
6729 #if TARGET_API_MAC_CARBON
6731 /* check for error when mounting the disk */
6732 if (HiWord(event.message) != noErr)
6738 DIBadMount(p, event.message);
6745 /* OS Event -- From "Maarten Hazewinkel" */
6748 switch ((event.message >> 24) & 0x000000FF)
6750 case suspendResumeMessage:
6752 /* Resuming: activate the front window */
6753 if (event.message & resumeFlag)
6755 #if TARGET_API_MAC_CARBON
6758 SetPortWindowPort( FrontWindow() );
6760 GetQDGlobalsArrow( &arrow );
6763 SetPort(FrontWindow());
6764 SetCursor(&qd.arrow);
6768 /* Suspend: deactivate the front window */
6782 /* From "Steve Linberg" and "Maarten Hazewinkel" */
6783 case kHighLevelEvent:
6785 #if TARGET_API_MAC_CARBON
6786 AEProcessAppleEvent(&event);
6788 /* Process apple events */
6789 if (AEProcessAppleEvent(&event) != noErr)
6792 plog("Apple Event Handler¤Î¥¨¥é¡¼¤Ç¤¹.");
6794 plog("Error in Apple Event Handler!");
6798 /* Handle "quit_when_ready" */
6799 if (quit_when_ready)
6802 quit_when_ready = FALSE;
6804 /* Do the menu key */
6807 /* Turn off the menus */
6811 /* Handle "open_when_ready" */
6812 handle_open_when_ready();
6823 /* Something happened */
6830 /*** Some Hooks for various routines ***/
6834 * Mega-Hack -- emergency lifeboat
6836 static vptr lifeboat = NULL;
6840 * Hook to "release" memory
6842 static vptr hook_rnfree(vptr v, huge size)
6845 #pragma unused (size)
6849 /* Alternative method */
6864 * Hook to "allocate" memory
6866 static vptr hook_ralloc(huge size)
6871 /* Make a new pointer */
6872 return (malloc(size));
6876 /* Make a new pointer */
6877 return (NewPtr(size));
6884 * Hook to handle "out of memory" errors
6886 static vptr hook_rpanic(huge size)
6889 #pragma unused (size)
6891 /* vptr mem = NULL; */
6893 /* Free the lifeboat */
6896 /* Free the lifeboat */
6897 DisposePtr(lifeboat);
6899 /* Forget the lifeboat */
6902 /* Mega-Hack -- Warning */
6904 mac_warning("¥á¥â¥ê¡¼¤¬Â¤ê¤Þ¤»¤ó!\rº£¤¹¤°½ªÎ»¤·¤Æ²¼¤µ¤¤!");
6906 mac_warning("Running out of Memory!\rAbort this process now!");
6909 /* Mega-Hack -- Never leave this function */
6910 while (TRUE) CheckEvents(TRUE);
6913 /* Mega-Hack -- Crash */
6919 * Hook to tell the user something important
6921 static void hook_plog(cptr str)
6923 /* Warning message */
6928 * Hook to tell the user something, and then quit
6930 static void hook_quit(cptr str)
6932 /* Warning if needed */
6933 if (str) mac_warning(str);
6935 #ifdef USE_ASYNC_SOUND
6937 /* Clean up sound support */
6940 #endif /* USE_ASYNC_SOUND */
6942 /* Write a preference file */
6950 * Hook to tell the user something, and then crash
6952 static void hook_core(cptr str)
6954 /* XXX Use the debugger */
6955 /* DebugStr(str); */
6958 if (str) mac_warning(str);
6960 /* Warn, then save player */
6962 mac_warning("Ã×̿Ū¤Ê¥¨¥é¡¼¤Ç¤¹.\r¶¯À©Åª¤Ë¥»¡¼¥Ö¤·¤Æ½ªÎ»¤·¤Þ¤¹.");
6964 mac_warning("Fatal error.\rI will now attempt to save and quit.");
6967 /* Attempt to save */
6969 if (!save_player()) mac_warning("·Ù¹ð -- ¥»¡¼¥Ö¤Ë¼ºÇÔ¤·¤Þ¤·¤¿!");
6971 if (!save_player()) mac_warning("Warning -- save failed!");
6980 /*** Main program ***/
6986 * XXX XXX XXX Hack -- This function attempts to "fix" the nasty
6987 * "Macintosh Save Bug" by using "absolute" path names, since on
6988 * System 7 machines anyway, the "current working directory" often
6989 * "changes" due to background processes, invalidating any "relative"
6990 * path names. Note that the Macintosh is limited to 255 character
6991 * path names, so be careful about deeply embedded directories...
6993 * XXX XXX XXX Hack -- This function attempts to "fix" the nasty
6994 * "missing lib folder bug" by allowing the user to help find the
6995 * "lib" folder by hand if the "application folder" code fails...
6997 static void init_stuff(void)
7001 #if !TARGET_API_MAC_CARBON
7018 #if TARGET_API_MAC_CARBON
7020 NavDialogOptions dialogOptions;
7021 FSSpec theFolderSpec;
7022 NavReplyRecord theReply;
7024 /* Fake rectangle */
7031 #if TARGET_API_MAC_CARBON
7032 screenRect = GetQDGlobalsScreenBits(&screen)->bounds;
7034 screenRect = qd.screenBits.bounds;
7036 center_rect(&r, &screenRect);
7038 /* Extract corner */
7043 /* Default to the "lib" folder with the application */
7044 #ifdef MACH_O_CARBON
7045 if (locate_lib(path, sizeof(path)) == NULL) quit(NULL);
7047 refnum_to_name(path, app_dir, app_vol, (char*)("\plib:"));
7051 /* Check until done */
7054 /* Prepare the paths */
7055 init_file_paths(path);
7057 /* Build the filename */
7059 path_build(path, sizeof(path), ANGBAND_DIR_FILE, "news_j.txt");
7061 path_build(path, sizeof(path), ANGBAND_DIR_FILE, "news.txt");
7064 /* Attempt to open and close that file */
7065 if (0 == fd_close(fd_open(path, O_RDONLY))) break;
7069 plog_fmt("'%s' ¥Õ¥¡¥¤¥ë¤ò¥ª¡¼¥×¥ó½ÐÍè¤Þ¤»¤ó.", path);
7071 plog_fmt("Unable to open the '%s' file.", path);
7076 plog("Hengband¤Î'lib'¥Õ¥©¥ë¥À¤¬Â¸ºß¤·¤Ê¤¤¤«Àµ¤·¤¯Ìµ¤¤²ÄǽÀ¤¬¤¢¤ê¤Þ¤¹.");
7078 plog("The Angband 'lib' folder is probably missing or misplaced.");
7083 plog("Please 'open' any file in any sub-folder of the 'lib' folder.");
7085 plog("Please 'open' any file in any sub-folder of the 'lib' folder.");
7088 #if TARGET_API_MAC_CARBON
7089 /* Ask the user to choose the lib folder */
7090 err = NavGetDefaultDialogOptions(&dialogOptions);
7093 if (err != noErr) quit(NULL);
7095 /* Set default location option */
7096 dialogOptions.dialogOptionFlags |= kNavSelectDefaultLocation;
7098 /* Clear preview option */
7099 dialogOptions.dialogOptionFlags &= ~(kNavAllowPreviews);
7101 /* Forbit selection of multiple files */
7102 dialogOptions.dialogOptionFlags &= ~(kNavAllowMultipleFiles);
7104 /* Display location */
7105 dialogOptions.location = topleft;
7107 /* Load the message for the missing folder from the resource fork */
7108 GetIndString(dialogOptions.message, 128, 1);
7110 /* Wait for the user to choose a folder */
7111 err = NavChooseFolder(
7119 /* Assume the player doesn't want to go on */
7120 if ((err != noErr) || !theReply.validRecord) quit(NULL);
7122 /* Retrieve FSSpec from the reply */
7124 AEKeyword theKeyword;
7125 DescType actualType;
7128 /* Get a pointer to selected folder */
7130 &(theReply.selection),
7140 if (err != noErr) quit(NULL);
7143 /* Free navitagor reply */
7144 err = NavDisposeReply(&theReply);
7147 if (err != noErr) quit(NULL);
7149 /* Extract textual file name for given file */
7152 theFolderSpec.parID,
7153 theFolderSpec.vRefNum,
7154 (char *)theFolderSpec.name);
7156 /* Allow "text" files */
7159 /* Allow "save" files */
7162 /* Allow "data" files */
7166 SFGetFile(topleft, "\p", NULL, 3, types, NULL, &reply);
7169 if (!reply.good) quit(NULL);
7171 /* Extract textual file name for given file */
7172 GetWDInfo(reply.vRefNum, &vrefnum, &drefnum, &junk);
7173 refnum_to_name(path, drefnum, vrefnum, (char*)reply.fName);
7176 /* Hack -- Remove the "filename" */
7177 i = strlen(path) - 1;
7178 while ((i > 0) && (path[i] != ':')) i--;
7179 if (path[i] == ':') path[i+1] = '\0';
7181 /* Hack -- allow "lib" folders */
7182 if (suffix(path, "lib:")) continue;
7184 /* Hack -- Remove the "sub-folder" */
7186 while ((i > 1) && (path[i] != ':')) i--;
7187 if (path[i] == ':') path[i+1] = '\0';
7193 * Macintosh Main loop
7197 EventRecord tempEvent;
7198 int numberOfMasters = 10;
7200 #if !TARGET_API_MAC_CARBON
7201 /* Increase stack space by 64K */
7202 SetApplLimit(GetApplLimit() - 131072L);//65536L);
7204 /* Stretch out the heap to full size */
7208 /* Get more Masters */
7209 while (numberOfMasters--) MoreMasters();
7211 #if !TARGET_API_MAC_CARBON
7212 /* Set up the Macintosh */
7213 InitGraf(&qd.thePort);
7227 FlushEvents(everyEvent, 0);
7229 /* Flush events some more (?) */
7230 (void)EventAvail(everyEvent, &tempEvent);
7231 (void)EventAvail(everyEvent, &tempEvent);
7232 (void)EventAvail(everyEvent, &tempEvent);
7235 #ifdef ANGBAND_LITE_MAC
7239 #else /* ANGBAND_LITE_MAC */
7241 # if defined(powerc) || defined(__powerc)
7243 /* Assume System 7 */
7245 /* Assume Color Quickdraw */
7249 #if TARGET_API_MAC_CARBON
7255 /* Check for existence of Carbon */
7256 err = Gestalt(gestaltCarbonVersion, &response);
7258 if (err != noErr) quit("This program requires Carbon API");
7268 /* Check the Gestalt */
7269 err = Gestalt(gestaltSystemVersion, &versionNumber);
7271 /* Check the version */
7272 if ((err != noErr) || (versionNumber < 0x0700))
7275 quit("¤³¤Î¥×¥í¥°¥é¥à¤Ï´Á»úTalk7.x.x°Ê¹ß¤ÇÆ°ºî¤·¤Þ¤¹.");
7277 quit("You must have System 7 to use this program.");
7287 /* Check the environs */
7288 if (SysEnvirons(1, &env) != noErr)
7291 quit("SysEnvirons ¥³¡¼¥ë¤Ï¼ºÇÔ¤·¤Þ¤·¤¿¡ª");
7293 quit("The SysEnvirons call failed!");
7297 /* Check for System Seven Stuff */
7298 if (env.systemVersion < 0x0700)
7301 quit("¤³¤Î¥×¥í¥°¥é¥à¤Ï´Á»úTalk7.x.x°Ê¹ß¤ÇÆ°ºî¤·¤Þ¤¹.");
7303 quit("You must have System 7 to use this program.");
7307 /* Check for Color Quickdraw */
7308 if (!env.hasColorQD)
7311 quit("¤³¤Î¥×¥í¥°¥é¥à¤ÏColor Quickdraw¤¬Ìµ¤¤¤ÈÆ°ºî¤·¤Þ¤»¤ó.");
7313 quit("You must have Color Quickdraw to use this program.");
7321 #endif /* ANGBAND_LITE_MAC */
7324 * Remember Mac OS version, in case we have to cope with version-specific
7327 (void)Gestalt(gestaltSystemVersion, &mac_os_version);
7330 /* Obtain a "Universal Procedure Pointer" */
7331 AEH_Start_UPP = NewAEEventHandlerUPP(AEH_Start);
7332 /* Install the hook (ignore error codes) */
7333 AEInstallEventHandler(kCoreEventClass, kAEOpenApplication, AEH_Start_UPP,
7336 /* Obtain a "Universal Procedure Pointer" */
7337 AEH_Quit_UPP = NewAEEventHandlerUPP(AEH_Quit);
7338 /* Install the hook (ignore error codes) */
7339 AEInstallEventHandler(kCoreEventClass, kAEQuitApplication, AEH_Quit_UPP,
7342 /* Obtain a "Universal Procedure Pointer" */
7343 AEH_Print_UPP = NewAEEventHandlerUPP(AEH_Print);
7344 /* Install the hook (ignore error codes) */
7345 AEInstallEventHandler(kCoreEventClass, kAEPrintDocuments, AEH_Print_UPP,
7348 /* Obtain a "Universal Procedure Pointer" */
7349 AEH_Open_UPP = NewAEEventHandlerUPP(AEH_Open);
7350 /* Install the hook (ignore error codes) */
7351 AEInstallEventHandler(kCoreEventClass, kAEOpenDocuments, AEH_Open_UPP,
7355 #ifndef MACH_O_CARBON
7356 /* Find the current application */
7360 /* Mark ourself as the file creator */
7361 _fcreator = ANGBAND_CREATOR;
7363 /* Default to saving a "text" file */
7367 #if defined(__MWERKS__)
7369 /* Obtian a "Universal Procedure Pointer" */
7370 #if TARGET_API_MAC_CARBON
7371 ynfilterUPP = NewModalFilterUPP(ynfilter);
7373 ynfilterUPP = NewModalFilterProc(ynfilter);
7379 /* Hook in some "z-virt.c" hooks */
7380 rnfree_aux = hook_rnfree;
7381 ralloc_aux = hook_ralloc;
7382 rpanic_aux = hook_rpanic;
7384 /* Hooks in some "z-util.c" hooks */
7385 plog_aux = hook_plog;
7386 quit_aux = hook_quit;
7387 core_aux = hook_core;
7389 BackColor(blackColor);
7390 ForeColor(whiteColor);
7392 /* Show the "watch" cursor */
7393 SetCursor(*(GetCursor(watchCursor)));
7395 /* Prepare the menubar */
7398 /* Prepare the windows */
7401 #ifndef MACH_O_CARBON
7409 /* Hack -- process all events */
7410 while (CheckEvents(TRUE)) /* loop */;
7412 /* Reset the cursor */
7413 #if TARGET_API_MAC_CARBON
7416 GetQDGlobalsArrow( &arrow );
7420 SetCursor( &qd.arrow );
7424 /* Mega-Hack -- Allocate a "lifeboat" */
7425 lifeboat = NewPtr(16384);
7429 /* Load sound effect resources */
7432 #endif /* USE_QT_SOUND */
7434 /* Note the "system" */
7435 ANGBAND_SYS = "mac";
7440 /* Catch nasty signals */
7447 /* Hack -- process all events */
7448 while (CheckEvents(TRUE)) /* loop */;
7451 /* We are now initialized */
7455 /* Handle "open_when_ready" */
7456 handle_open_when_ready();
7462 /* Prompt the user */
7464 prt("'¥Õ¥¡¥¤¥ë'¥á¥Ë¥å¡¼¤è¤ê'¿·µ¬'¤Þ¤¿¤Ï'³«¤¯...'¤òÁªÂò¤·¤Æ¤¯¤À¤µ¤¤¡£", 23, 10);
7466 prt("[Choose 'New' or 'Open' from the 'File' menu]", 23, 15);
7469 /* Flush the prompt */
7473 /* Hack -- Process Events Forever */
7474 while (TRUE) CheckEvents(TRUE);