3 /* Purpose: Simple support for MACINTOSH Angband */
6 * This file should only be compiled with the "Macintosh" version
8 * This file written by "Ben Harrison (benh@phial.com)".
10 * Some code adapted from "MacAngband 2.6.1" by Keith Randall
12 * Maarten Hazewinkel (mmhazewi@cs.ruu.nl) provided some initial
13 * suggestions for the PowerMac port.
15 * Steve Linberg (slinberg@crocker.com) provided the code surrounded
18 * The graphics code is adapted from an extremely minimal subset of
19 * the code from "Sprite World II", an amazing animation package.
21 * See "z-term.c" for info on the concept of the "generic terminal"
23 * The preference file is now a text file named "Angband preferences".
25 * Note that the "preference" file is now a simple text file called
26 * "Angband preferences", which contains the versions information, so
27 * that obsolete preference files can be ignored (this may be bad).
29 * Note that "init1.c", "init2.c", "load1.c", "load2.c", and "birth.c"
30 * should probably be "unloaded" as soon as they are no longer needed,
31 * to save space, but I do not know how to do this.
33 * Stange bug -- The first "ClipRect()" call crashes if the user closes
34 * all the windows, switches to another application, switches back, and
35 * then re-opens the main window, for example, using "command-a".
37 * By default, this file assumes that you will be using a 68020 or better
38 * machine, running System 7 and Color Quickdraw. In fact, the game will
39 * refuse to run unless these features are available. This allows the use
40 * of a variety of interesting features such as graphics and sound.
42 * To create a version which can be used on 68000 machines, or on machines
43 * which are not running System 7 or Color Quickdraw, simply activate the
44 * "ANGBAND_LITE_MAC" compilation flag in the proper header file. This
45 * will disable all "modern" features used in this file, including support
46 * for multiple sub-windows, color, graphics, and sound.
48 * When compiling with the "ANGBAND_LITE_MAC" flag, the "ANGBAND_LITE"
49 * flag will be automatically defined, which will disable many of the
50 * advanced features of the game itself, reducing the total memory usage.
52 * If you are never going to use "graphics" (especially if you are not
53 * compiling support for graphics anyway) then you can delete the "pict"
54 * resource with id "1001" with no dangerous side effects.
59 * Important Resources in the resource file:
61 * FREF 130 = 'A271' / 'APPL' (application)
62 * FREF 129 = 'A271' / 'SAVE' (save file)
63 * FREF 130 = 'A271' / 'TEXT' (bone file, generic text file)
64 * FREF 131 = 'A271' / 'DATA' (binary image file, score file)
66 * DLOG 128 = "About Angband..."
68 * ALRT 128 = unused (?)
69 * ALRT 129 = "Warning..."
70 * ALRT 130 = "Are you sure you want to quit without saving?"
72 * DITL 128 = body for DLOG 128
73 * DITL 129 = body for ALRT 129
74 * DITL 130 = body for ALRT 130
76 * ICON 128 = "warning" icon
78 * MENU 128 = apple (about, -, ...)
79 * MENU 129 = File (new, open, close, save, -, exit, quit)
80 * MENU 130 = Edit (undo, -, cut, copy, paste, clear)
82 * PICT 1001 = Graphics tile set
88 * all 'APEX' files have a filename of the form "*:apex:*" (?)
89 * all 'BONE' files have a filename of the form "*:bone:*" (?)
90 * all 'DATA' files have a filename of the form "*:data:*"
91 * all 'SAVE' files have a filename of the form "*:save:*"
92 * all 'USER' files have a filename of the form "*:user:*" (?)
94 * Perhaps we should attempt to set the "_ftype" flag inside this file,
95 * to avoid nasty file type information being spread all through the
96 * rest of the code. (?) This might require adding hooks into the
97 * "fd_open()" and "my_fopen()" functions in "util.c". XXX XXX XXX
102 * Reasons for each header file:
104 * angband.h = Angband header file
106 * Types.h = (included anyway)
107 * Gestalt.h = gestalt code
108 * QuickDraw.h = (included anyway)
109 * OSUtils.h = (included anyway)
110 * Files.h = file code
111 * Fonts.h = font code
112 * Menus.h = menu code
113 * Dialogs.h = dialog code
114 * Windows.h = (included anyway)
115 * Palettes.h = palette code
116 * StandardFile.h = file dialog box
117 * DiskInit.h = disk initialization
118 * ToolUtils.h = HiWord() / LoWord()
119 * Desk.h = OpenDeskAcc()
120 * Devices.h = OpenDeskAcc()
121 * Events.h = event code
122 * Resources.h = resource code
123 * Controls.h = button code
124 * SegLoad.h = ExitToShell(), AppFile, etc
125 * Memory.h = SetApplLimit(), NewPtr(), etc
126 * QDOffscreen.h = GWorld code
127 * Sound.h = Sound code
129 * For backwards compatibility:
130 * Use GestaltEqu.h instead of Gestalt.h
131 * Add Desk.h to include simply includes Menus.h, Devices.h, Events.h
139 #include <QuickDraw.h>
145 #include <Palettes.h>
146 #include <StandardFile.h>
147 #include <DiskInit.h>
148 #include <ToolUtils.h>
151 #include <Resources.h>
152 #include <Controls.h>
155 #include <QDOffscreen.h>
165 * Cleaning up a couple of things to make these easier to change --AR
168 #define PREF_FILE_NAME "Hengband Preferences"
170 #define PREF_FILE_NAME "Angband Preferences"
174 * Use "malloc()" instead of "NewPtr()"
176 /* #define USE_MALLOC */
179 #if defined(powerc) || defined(__powerc)
182 * Disable "LITE" version
184 # undef ANGBAND_LITE_MAC
189 #ifdef ANGBAND_LITE_MAC
192 * Maximum number of windows
194 # define MAX_TERM_DATA 1
196 #else /* ANGBAND_LITE_MAC */
199 * Maximum number of windows
201 # define MAX_TERM_DATA 8
204 * Activate some special code
206 # define USE_SFL_CODE
208 #endif /* ANGBAND_LITE_MAC */
215 * Include the necessary header files
217 #include <AppleEvents.h>
225 * Globals for MPW compilation
239 * The Angband Color Set (0 to 15):
240 * Black, White, Slate, Orange, Red, Blue, Green, Umber
241 * D-Gray, L-Gray, Violet, Yellow, L-Red, L-Blue, L-Green, L-Umber
243 * Colors 8 to 15 are basically "enhanced" versions of Colors 0 to 7.
245 * On the Macintosh, we use color quickdraw, and we use actual "RGB"
246 * values below to choose the 16 colors.
248 * If we are compiled for ancient machines, we bypass color and simply
249 * draw everything in white (letting "z-term.c" automatically convert
250 * "black" into "wipe" calls).
252 static RGBColor foo[16] =
254 {0x0000, 0x0000, 0x0000}, /* TERM_DARK */
255 {0xFFFF, 0xFFFF, 0xFFFF}, /* TERM_WHITE */
256 {0x8080, 0x8080, 0x8080}, /* TERM_SLATE */
257 {0xFFFF, 0x8080, 0x0000}, /* TERM_ORANGE */
258 {0xC0C0, 0x0000, 0x0000}, /* TERM_RED */
259 {0x0000, 0x8080, 0x4040}, /* TERM_GREEN */
260 {0x0000, 0x0000, 0xFFFF}, /* TERM_BLUE */
261 {0x8080, 0x4040, 0x0000}, /* TERM_UMBER */
262 {0x4040, 0x4040, 0x4040}, /* TERM_L_DARK */
263 {0xC0C0, 0xC0C0, 0xC0C0}, /* TERM_L_WHITE */
264 {0xFFFF, 0x0000, 0xFFFF}, /* TERM_VIOLET */
265 {0xFFFF, 0xFFFF, 0x0000}, /* TERM_YELLOW */
266 {0xFFFF, 0x0000, 0x0000}, /* TERM_L_RED */
267 {0x0000, 0xFFFF, 0x0000}, /* TERM_L_GREEN */
268 {0x0000, 0xFFFF, 0xFFFF}, /* TERM_L_BLUE */
269 {0xC0C0, 0x8080, 0x4040} /* TERM_L_UMBER */
278 typedef struct term_data term_data;
291 #ifdef ANGBAND_LITE_MAC
295 #else /* ANGBAND_LITE_MAC */
307 #endif /* ANGBAND_LITE_MAC */
310 GWorldPtr bufferPort;
311 PixMapHandle bufferPixHndl;
356 * Forward declare -- see below
358 static bool CheckEvents(bool wait);
362 * Hack -- location of the main directory
364 static short app_vol;
369 * Delay handling of double-clicked savefiles
371 Boolean open_when_ready = FALSE;
374 * Delay handling of pre-emptive "quit" event
376 Boolean quit_when_ready = FALSE;
380 * Hack -- game in progress
382 static int game_in_progress = 0;
386 * Only do "SetPort()" when needed
388 static WindowPtr active = NULL;
393 * An array of term_data's
395 static term_data data[MAX_TERM_DATA];
400 * Note when "open"/"new" become valid
402 static bool initialized = FALSE;
407 * CodeWarrior uses Universal Procedure Pointers
409 static ModalFilterUPP ynfilterUPP;
416 AEEventHandlerUPP AEH_Start_UPP;
417 AEEventHandlerUPP AEH_Quit_UPP;
418 AEEventHandlerUPP AEH_Print_UPP;
419 AEEventHandlerUPP AEH_Open_UPP;
427 static int ext_sound = 0;
435 #define SND_CMD_ERROR 6
437 static int soundchoice[] = {
505 static int soundmode[8];
512 * Convert refnum+vrefnum+fname into a full file name
513 * Store this filename in 'buf' (make sure it is long enough)
514 * Note that 'fname' looks to be a "pascal" string
516 static void refnum_to_name(char *buf, long refnum, short vrefnum, char *fname)
528 for (j=1; j<=fname[0]; j++)
530 res[i-fname[0]+j] = fname[j];
534 pb.ioCompletion=NULL;
536 pb.ioVRefNum=vrefnum;
542 pb.ioDrDirID=pb.ioDrParID;
543 err = PBGetCatInfo((CInfoPBPtr)&pb, FALSE);
545 for (j=1; j<=name[0]; j++)
547 res[i-name[0]+j] = name[j];
551 if (pb.ioDrDirID == fsRtDirID) break;
554 /* Extract the result */
555 for (j = 0, i++; res[i]; j++, i++) buf[j] = res[i];
563 * XXX XXX XXX Allow the system to ask us for a filename
565 static bool askfor_file(char *buf, int len)
573 /* Default file name */
574 sprintf((char*)dflt + 1, "%s's description", buf);
575 dflt[0] = strlen((char*)dflt + 1);
577 /* Ask for a file name */
578 topleft.h=(qd.screenBits.bounds.left+qd.screenBits.bounds.right)/2-344/2;
579 topleft.v=(2*qd.screenBits.bounds.top+qd.screenBits.bounds.bottom)/3-188/2;
580 SFPutFile(topleft, "\pSelect a filename:", dflt, NULL, &reply);
581 /* StandardPutFile("\pSelect a filename:", dflt, &reply); */
589 GetWDInfo(reply.vRefNum, &vrefnum, &drefnum, &junk);
591 /* Extract the name */
592 refnum_to_name(buf, drefnum, vrefnum, (char*)reply.fName);
607 * Center a rectangle inside another rectangle
609 static void center_rect(Rect *r, Rect *s)
611 int centerx = (s->left + s->right)/2;
612 int centery = (2*s->top + s->bottom)/3;
613 int dx = centerx - (r->right - r->left)/2 - r->left;
614 int dy = centery - (r->bottom - r->top)/2 - r->top;
623 * Convert a pascal string in place
625 * This function may be defined elsewhere, but since it is so
626 * small, it is not worth finding the proper function name for
627 * all the different platforms.
629 static void ptocstr(StringPtr src)
633 /* Hack -- pointer */
634 char *s = (char*)(src);
636 /* Hack -- convert the string */
637 for (i = s[0]; i; i--, s++) s[0] = s[1];
639 /* Hack -- terminate the string */
644 #if defined(USE_SFL_CODE)
648 * The following three routines (pstrcat, pstrinsert, and PathNameFromDirID)
649 * were taken from the Think Reference section called "Getting a Full Pathname"
650 * (under the File Manager section). We need PathNameFromDirID to get the
651 * full pathname of the opened savefile, making no assumptions about where it
654 * I had to hack PathNameFromDirID a little for MetroWerks, but it's awfully
657 static void pstrcat(StringPtr dst, StringPtr src)
660 BlockMove(src + 1, dst + *dst + 1, *src);
662 /* adjust length byte */
667 * pstrinsert - insert string 'src' at beginning of string 'dst'
669 static void pstrinsert(StringPtr dst, StringPtr src)
671 /* make room for new string */
672 BlockMove(dst + 1, dst + *src + 1, *dst);
674 /* copy new string in */
675 BlockMove(src + 1, dst + 1, *src);
677 /* adjust length byte */
681 static void PathNameFromDirID(long dirID, short vRefNum, StringPtr fullPathName)
684 Str255 directoryName;
687 fullPathName[0] = '\0';
689 block.dirInfo.ioDrParID = dirID;
690 block.dirInfo.ioNamePtr = directoryName;
694 block.dirInfo.ioVRefNum = vRefNum;
695 block.dirInfo.ioFDirIndex = -1;
696 block.dirInfo.ioDrDirID = block.dirInfo.ioDrParID;
697 err = PBGetCatInfo(&block, FALSE);
698 pstrcat(directoryName, (StringPtr)"\p:");
699 pstrinsert(fullPathName, directoryName);
700 if (block.dirInfo.ioDrDirID == 2) break;
709 * Activate a given window, if necessary
711 static void activate(WindowPtr w)
726 * Display a warning message
728 static void mac_warning(cptr warning)
733 /* Limit of 250 chars */
734 len = strlen(warning);
735 if (len > 250) len = 250;
737 /* Make a "Pascal" string */
739 for (i=0; i<len; i++) text[i+1] = warning[i];
741 /* Prepare the dialog box values */
742 ParamText(text, "\p", "\p", "\p");
744 /* Display the Alert, wait for Okay */
750 /*** Some generic functions ***/
753 #ifdef ANGBAND_LITE_MAC
756 * Hack -- activate a color (0 to 255)
758 #define term_data_color(TD,A) /* Nothing */
760 #else /* ANGBAND_LITE_MAC */
763 * Hack -- activate a color (0 to 255)
765 static void term_data_color(term_data *td, int a)
772 /* Extract the R,G,B data */
773 rv = angband_color_table[a][1];
774 gv = angband_color_table[a][2];
775 bv = angband_color_table[a][3];
778 color.red = (rv | (rv << 8));
779 color.green = (gv | (gv << 8));
780 color.blue = (bv | (bv << 8));
782 /* Activate the color */
783 RGBForeColor(&color);
788 /* Activate the color */
795 /* Extract the R,G,B data */
796 rv = angband_color_table[a][1];
797 gv = angband_color_table[a][2];
798 bv = angband_color_table[a][3];
801 color.red = (rv | (rv << 8));
802 color.green = (gv | (gv << 8));
803 color.blue = (bv | (bv << 8));
805 /* Activate the color */
806 RGBForeColor(&color);
814 #endif /* ANGBAND_LITE_MAC */
818 * Hack -- Apply and Verify the "font" info
820 * This should usually be followed by "term_data_check_size()"
822 static void term_data_check_font(term_data *td)
828 WindowPtr old = active;
834 /* Instantiate font */
835 TextFont(td->font_id);
836 TextSize(td->font_size);
837 TextFace(td->font_face);
839 /* Extract the font info */
842 /* Assume monospaced */
843 td->font_mono = TRUE;
845 /* Extract the font sizing values XXX XXX XXX */
846 td->font_wid = CharWidth('@'); /* info.widMax; */
847 td->font_hgt = info.ascent + info.descent;
849 td->font_o_y = info.ascent;
851 /* Check important characters */
852 for (i = 33; i < 127; i++)
854 /* Hack -- notice non-mono-space */
855 if (td->font_wid != CharWidth(i)) td->font_mono = FALSE;
857 /* Hack -- collect largest width */
858 if (td->font_wid < CharWidth(i)) td->font_wid = CharWidth(i);
861 /* Set default offsets */
862 td->tile_o_x = td->font_o_x;
863 td->tile_o_y = td->font_o_y;
865 /* Set default tile size */
867 if( td->tile_wid == 0 && td->tile_hgt == 0 ){
868 td->tile_wid = td->font_wid;
869 td->tile_hgt = td->font_hgt;
872 td->tile_wid = td->font_wid;
873 td->tile_hgt = td->font_hgt;
876 /* Re-activate the old window */
882 * Hack -- Apply and Verify the "size" info
884 static void term_data_check_size(term_data *td)
886 /* Minimal window size */
887 if (td->cols < 1) td->cols = 1;
888 if (td->rows < 1) td->rows = 1;
890 /* Minimal tile size */
891 if (td->tile_wid < 4) td->tile_wid = 4;
892 if (td->tile_hgt < 4) td->tile_hgt = 4;
894 /* Default tile offsets */
895 td->tile_o_x = (td->tile_wid - td->font_wid) / 2;
896 td->tile_o_y = (td->tile_hgt - td->font_hgt) / 2;
898 /* Minimal tile offsets */
899 if (td->tile_o_x < 0) td->tile_o_x = 0;
900 if (td->tile_o_y < 0) td->tile_o_y = 0;
902 /* Apply font offsets */
903 td->tile_o_x += td->font_o_x;
904 td->tile_o_y += td->font_o_y;
906 /* Calculate full window size */
907 td->size_wid = td->cols * td->tile_wid + td->size_ow1 + td->size_ow2;
908 td->size_hgt = td->rows * td->tile_hgt + td->size_oh1 + td->size_oh2;
911 if (td->r.top > qd.screenBits.bounds.bottom - td->size_hgt)
913 td->r.top = qd.screenBits.bounds.bottom - td->size_hgt;
917 if (td->r.top < qd.screenBits.bounds.top + 30)
919 td->r.top = qd.screenBits.bounds.top + 30;
922 /* Verify the left */
923 if (td->r.left > qd.screenBits.bounds.right - td->size_wid)
925 td->r.left = qd.screenBits.bounds.right - td->size_wid;
928 /* Verify the left */
929 if (td->r.left < qd.screenBits.bounds.left)
931 td->r.left = qd.screenBits.bounds.left;
934 /* Calculate bottom right corner */
935 td->r.right = td->r.left + td->size_wid;
936 td->r.bottom = td->r.top + td->size_hgt;
938 /* Assume no graphics */
939 td->t->always_pict = FALSE;
941 #ifdef ANGBAND_LITE_MAC
945 #else /* ANGBAND_LITE_MAC */
947 /* Handle graphics */
948 if (use_graphics && (td == &data[0]))
950 td->t->always_pict = TRUE;
953 #endif /* ANGBAND_LITE_MAC */
955 /* Fake mono-space */
956 if (!td->font_mono ||
957 (td->font_wid != td->tile_wid) ||
958 (td->font_hgt != td->tile_hgt))
960 /* Handle fake monospace */
961 td->t->always_pict = TRUE;
965 static OSErr XDDSWUpDateGWorldFromPict( term_data *td );
967 * Hack -- resize a term_data
969 * This should normally be followed by "term_data_resize()"
971 static void term_data_resize(term_data *td)
973 /* Actually resize the window */
974 SizeWindow(td->w, td->size_wid, td->size_hgt, 0);
977 XDDSWUpDateGWorldFromPict( td );
984 * Hack -- redraw a term_data
986 * Note that "Term_redraw()" calls "TERM_XTRA_CLEAR"
988 static void term_data_redraw(term_data *td)
992 /* Activate the term */
993 Term_activate(td->t);
995 /* Redraw the contents */
998 /* Flush the output */
1001 /* Restore the old term */
1004 /* No need to redraw */
1005 ValidRect(&td->w->portRect);
1011 #ifdef ANGBAND_LITE_MAC
1015 #else /* ANGBAND_LITE_MAC */
1022 #define kPictID 1001 /* Graf 'pict' resource */
1024 #define kGrafWidth 8 /* Graf Size (X) */
1025 #define kGrafHeight 8 /* Graf Size (Y) */
1031 typedef struct FrameRec FrameRec;
1036 * - GWorld for the frame image
1037 * - Handle to pix map (saved for unlocking/locking)
1038 * - Pointer to color pix map (valid only while locked)
1042 GWorldPtr framePort;
1043 PixMapHandle framePixHndl;
1050 * The global picture data
1052 static FrameRec *frameP = NULL;
1058 static void BenSWLockFrame(FrameRec *srcFrameP)
1060 PixMapHandle pixMapH;
1062 pixMapH = GetGWorldPixMap(srcFrameP->framePort);
1063 (void)LockPixels(pixMapH);
1064 HLockHi((Handle)pixMapH);
1065 srcFrameP->framePixHndl = pixMapH;
1066 srcFrameP->framePix = (PixMapPtr)StripAddress(*(Handle)pixMapH);
1074 static void XDDSWLockFrame( term_data *td )
1076 PixMapHandle pixMapH;
1078 pixMapH = GetGWorldPixMap(td->bufferPort);
1079 (void)LockPixels(pixMapH);
1080 HLockHi((Handle)pixMapH);
1081 td->bufferPixHndl = pixMapH;
1082 td->bufferPix = (PixMapPtr)*(Handle)pixMapH;
1090 static void BenSWUnlockFrame(FrameRec *srcFrameP)
1092 if (srcFrameP->framePort != NULL)
1094 HUnlock((Handle)srcFrameP->framePixHndl);
1095 UnlockPixels(srcFrameP->framePixHndl);
1098 srcFrameP->framePix = NULL;
1106 static void XDDSWUnlockFrame( term_data *td )
1108 if (td->bufferPort != NULL)
1110 HUnlock((Handle)td->bufferPixHndl);
1111 UnlockPixels(td->bufferPixHndl);
1114 td->bufferPix = NULL;
1118 static OSErr BenSWCreateGWorldFromPict(
1119 GWorldPtr *pictGWorld,
1123 GWorldPtr saveGWorld;
1124 GDHandle saveGDevice;
1125 GWorldPtr tempGWorld;
1134 depth = data[0].pixelDepth;
1137 theGDH = data[0].theGDH;
1139 /* Obtain size rectangle */
1140 pictRect = (**pictH).picFrame;
1141 OffsetRect(&pictRect, -pictRect.left, -pictRect.top);
1143 /* Create a GWorld */
1144 err = NewGWorld(&tempGWorld, depth, &pictRect, nil,
1145 theGDH, noNewDevice);
1154 *pictGWorld = tempGWorld;
1157 GetGWorld(&saveGWorld, &saveGDevice);
1160 SetGWorld(tempGWorld, nil);
1162 /* Dump the pict into the GWorld */
1163 (void)LockPixels(GetGWorldPixMap(tempGWorld));
1164 EraseRect(&pictRect);
1165 DrawPicture(pictH, &pictRect);
1166 UnlockPixels(GetGWorldPixMap(tempGWorld));
1168 /* Restore GWorld */
1169 SetGWorld(saveGWorld, saveGDevice);
1177 static OSErr XDDSWCreateGWorldFromPict(
1178 GWorldPtr *pictGWorld,
1182 /* GWorldPtr saveGWorld;
1183 GDHandle saveGDevice;*/
1184 GWorldPtr tempGWorld;
1187 /* GDHandle theGDH; */
1195 /* depth = td->pixelDepth; */
1198 /* theGDH = td->theGDH; */
1200 /* Obtain size rectangle */
1202 pictRect.right = td->size_wid;
1204 pictRect.bottom = td->tile_hgt;
1206 /* Create a GWorld */
1207 err = NewGWorld(&tempGWorld, 0, &pictRect, 0, 0, 0);
1216 *pictGWorld = tempGWorld;
1219 /* GetGWorld(&saveGWorld, &saveGDevice); */
1222 /* SetGWorld(tempGWorld, nil); */
1224 /* Dump the pict into the GWorld */
1225 /* (void)LockPixels(GetGWorldPixMap(tempGWorld)); */
1226 /* EraseRect(&pictRect); */
1227 /* DrawPicture(pictH, &pictRect); */
1228 /* UnlockPixels(GetGWorldPixMap(tempGWorld)); */
1230 /* Restore GWorld */
1231 /* SetGWorld(saveGWorld, saveGDevice); */
1237 static OSErr XDDSWUpDateGWorldFromPict( term_data *td )
1239 /* GWorldPtr saveGWorld; */
1240 /* GDHandle saveGDevice; */
1243 /* GDHandle theGDH; */
1245 GWorldFlags errflag;
1249 if( td->bufferPort == NULL )
1252 /* depth = td->pixelDepth; */
1255 /* theGDH = td->theGDH; */
1257 /* Obtain size rectangle */
1260 pictRect.right = td->size_wid;
1261 pictRect.bottom = td->tile_hgt;
1263 XDDSWUnlockFrame(td);
1265 errflag = UpdateGWorld( &td->bufferPort, 0, &pictRect, 0, 0, 0);
1267 if( errflag & gwFlagErr ){
1273 /* GetGWorld(&saveGWorld, &saveGDevice); */
1276 /* SetGWorld(td->bufferPort, nil); */
1278 /* Dump the pict into the GWorld */
1279 /* (void)LockPixels(GetGWorldPixMap(td->bufferPort)); */
1280 /* EraseRect(&td->bufferPort->portRect); */
1282 /* UnlockPixels(GetGWorldPixMap(td->bufferPort)); */
1284 /* Restore GWorld */
1285 /* SetGWorld(saveGWorld, saveGDevice); */
1291 * Init the global "frameP"
1294 static errr globe_init(void)
1298 GWorldPtr tempPictGWorldP;
1302 /* Use window XXX XXX XXX */
1306 /* Get the pict resource */
1307 newPictH = GetPicture(kPictID);
1309 /* Analyze result */
1310 err = (newPictH ? 0 : -1);
1317 err = BenSWCreateGWorldFromPict(&tempPictGWorldP, newPictH);
1319 /* Release resource */
1320 ReleaseResource((Handle)newPictH);
1325 /* Create the frame */
1326 frameP = (FrameRec*)NewPtrClear((Size)sizeof(FrameRec));
1328 /* Analyze result */
1329 err = (frameP ? 0 : -1);
1335 frameP->framePort = tempPictGWorldP;
1338 BenSWLockFrame(frameP);
1349 * Nuke the global "frameP"
1351 static errr globe_nuke(void)
1357 BenSWUnlockFrame(frameP);
1359 /* Dispose of the GWorld */
1360 DisposeGWorld(frameP->framePort);
1362 /* Dispose of the memory */
1363 DisposePtr((Ptr)frameP);
1370 FlushEvents(everyEvent, 0);
1377 #endif /* ANGBAND_LITE_MAC */
1381 /*** Support for the "z-term.c" package ***/
1385 * Initialize a new Term
1387 * Note also the "window type" called "noGrowDocProc", which might be more
1388 * appropriate for the main "screen" window.
1390 * Note the use of "srcCopy" mode for optimized screen writes.
1392 static void Term_init_mac(term *t)
1394 term_data *td = (term_data*)(t->data);
1396 static RGBColor black = {0x0000,0x0000,0x0000};
1397 static RGBColor white = {0xFFFF,0xFFFF,0xFFFF};
1399 #ifdef ANGBAND_LITE_MAC
1401 /* Make the window */
1402 td->w = NewWindow(0, &td->r, td->title, 0, noGrowDocProc, (WindowPtr)-1, 1, 0L);
1404 #else /* ANGBAND_LITE_MAC */
1406 /* Make the window */
1407 td->w = NewCWindow(0, &td->r, td->title, 0, documentProc, (WindowPtr)-1, 1, 0L);
1409 #endif /* ANGBAND_LITE_MAC */
1411 /* Activate the window */
1414 /* Erase behind words */
1417 /* Apply and Verify */
1418 term_data_check_font(td);
1419 term_data_check_size(td);
1421 /* Resize the window */
1422 term_data_resize(td);
1424 #ifdef ANGBAND_LITE_MAC
1426 /* Prepare the colors (base colors) */
1427 BackColor(blackColor);
1428 ForeColor(whiteColor);
1430 #else /* ANGBAND_LITE_MAC */
1432 /* Prepare the colors (real colors) */
1433 RGBBackColor(&black);
1434 RGBForeColor(&white);
1441 GDHandle currentGDH;
1442 GWorldPtr windowGWorld;
1443 PixMapHandle basePixMap;
1445 /* Obtain the rect */
1446 tempRect = td->w->portRect;
1448 /* Obtain the global rect */
1449 globalRect = tempRect;
1450 LocalToGlobal((Point*)&globalRect.top);
1451 LocalToGlobal((Point*)&globalRect.bottom);
1453 /* Obtain the proper GDH */
1454 mainGDH = GetMaxDevice(&globalRect);
1456 /* Extract GWorld and GDH */
1457 GetGWorld(&windowGWorld, ¤tGDH);
1459 /* Obtain base pixmap */
1460 basePixMap = (**mainGDH).gdPMap;
1462 /* Save pixel depth */
1463 td->pixelDepth = (**basePixMap).pixelSize;
1465 /* Save Window GWorld */
1466 td->theGWorld = windowGWorld;
1468 /* Save Window GDH */
1469 td->theGDH = currentGDH;
1472 td->mainSWGDH = mainGDH;
1475 #endif /* ANGBAND_LITE_MAC */
1477 /* Clip to the window */
1478 ClipRect(&td->w->portRect);
1480 /* Erase the window */
1481 EraseRect(&td->w->portRect);
1483 /* Invalidate the window */
1484 InvalRect(&td->w->portRect);
1486 /* Display the window if needed */
1487 if (td->mapped) ShowWindow(td->w);
1489 /* Hack -- set "mapped" flag */
1490 t->mapped_flag = td->mapped;
1495 XDDSWCreateGWorldFromPict( &td->bufferPort, td );
1497 XDDSWLockFrame( td );
1499 /* if (err == noErr)
1511 static void Term_nuke_mac(term *t)
1524 static errr Term_user_mac(int n)
1538 static errr Term_xtra_mac_react(void)
1540 term_data *td = (term_data*)(Term->data);
1546 #ifdef ANGBAND_LITE_MAC
1550 #else /* ANGBAND_LITE_MAC */
1553 if (use_sound != arg_sound)
1556 use_sound = arg_sound;
1559 /* Handle graphics */
1560 if ((td == &data[0]) && (use_graphics != arg_graphics))
1562 /* Initialize graphics */
1564 if (!use_graphics && !frameP && (globe_init() != 0))
1567 plog("¥°¥é¥Õ¥£¥Ã¥¯¤Î½é´ü²½¤Ï½ÐÍè¤Þ¤»¤ó¤Ç¤·¤¿.");
1569 plog("Cannot initialize graphics!");
1571 arg_graphics = FALSE;
1575 use_graphics = arg_graphics;
1577 /* Apply and Verify */
1578 term_data_check_size(td);
1580 /* Resize the window */
1581 term_data_resize(td);
1587 #endif /* ANGBAND_LITE_MAC */
1595 * Do a "special thing"
1597 static errr Term_xtra_mac(int n, int v)
1599 term_data *td = (term_data*)(Term->data);
1607 case TERM_XTRA_NOISE:
1616 #ifdef ANGBAND_LITE_MAC
1620 #else /* ANGBAND_LITE_MAC */
1623 case TERM_XTRA_SOUND:
1633 /* Open the resource file */
1634 oldResFile = CurResFile();
1635 newResFile = OpenResFile(sound);
1637 /* Close the resource file */
1638 CloseResFile(newResFile);
1639 UseResFile(oldResFile);
1642 /* Get the proper sound name */
1643 sprintf((char*)sound + 1, "%.16s.wav", angband_sound_name[v]);
1644 sound[0] = strlen((char*)sound + 1);
1646 /* Obtain resource XXX XXX XXX */
1648 handle = Get1NamedResource('snd ', sound);
1649 if( handle == NULL || ext_sound )
1650 handle = GetNamedResource('snd ', sound);
1653 if (handle && soundmode[soundchoice[v]] == true)
1656 LoadResource(handle);
1659 /* Play sound (wait for completion) */
1660 SndPlay(nil, (SndListHandle)handle, true);
1662 /* Unlock and release */
1664 ReleaseResource(handle);
1667 handle = GetNamedResource('snd ', sound);
1673 LoadResource(handle);
1676 /* Play sound (wait for completion) */
1677 SndPlay(nil, (SndListHandle)handle, true);
1679 /* Unlock and release */
1681 ReleaseResource(handle);
1688 #endif /* ANGBAND_LITE_MAC */
1690 /* Process random events */
1691 case TERM_XTRA_BORED:
1693 /* Process an event */
1694 (void)CheckEvents(0);
1700 /* Process pending events */
1701 case TERM_XTRA_EVENT:
1703 /* Process an event */
1704 (void)CheckEvents(v);
1710 /* Flush all pending events (if any) */
1711 case TERM_XTRA_FLUSH:
1713 /* Hack -- flush all events */
1714 while (CheckEvents(TRUE)) /* loop */;
1720 /* Hack -- Change the "soft level" */
1721 case TERM_XTRA_LEVEL:
1723 /* Activate if requested */
1724 if (v) activate(td->w);
1730 /* Clear the screen */
1731 case TERM_XTRA_CLEAR:
1733 /* No clipping XXX XXX XXX */
1734 ClipRect(&td->w->portRect);
1736 /* Erase the window */
1737 EraseRect(&td->w->portRect);
1740 term_data_color(td, TERM_WHITE);
1742 /* Frame the window in white */
1744 LineTo(0, td->size_hgt-1);
1745 LineTo(td->size_wid-1, td->size_hgt-1);
1746 LineTo(td->size_wid-1, 0);
1748 /* Clip to the new size */
1749 r.left = td->w->portRect.left + td->size_ow1;
1750 r.top = td->w->portRect.top + td->size_oh1;
1751 r.right = td->w->portRect.right - td->size_ow2;
1752 r.bottom = td->w->portRect.bottom - td->size_oh2;
1759 /* React to changes */
1760 case TERM_XTRA_REACT:
1762 /* React to changes */
1763 return (Term_xtra_mac_react());
1766 /* Delay (milliseconds) */
1767 case TERM_XTRA_DELAY:
1772 long m = TickCount() + (v * 60L) / 1000;
1775 while (TickCount() < m) /* loop */;
1790 * Low level graphics (Assumes valid input).
1791 * Draw a "cursor" at (x,y), using a "yellow box".
1792 * We are allowed to use "Term_grab()" to determine
1793 * the current screen contents (for inverting, etc).
1795 static errr Term_curs_mac(int x, int y)
1799 term_data *td = (term_data*)(Term->data);
1802 term_data_color(td, TERM_YELLOW);
1804 /* Frame the grid */
1805 r.left = x * td->tile_wid + td->size_ow1;
1806 r.right = r.left + td->tile_wid;
1807 r.top = y * td->tile_hgt + td->size_oh1;
1808 r.bottom = r.top + td->tile_hgt;
1817 * Low level graphics (Assumes valid input)
1819 * Erase "n" characters starting at (x,y)
1821 static errr Term_wipe_mac(int x, int y, int n)
1825 term_data *td = (term_data*)(Term->data);
1827 /* Erase the block of characters */
1828 r.left = x * td->tile_wid + td->size_ow1;
1829 r.right = r.left + n * td->tile_wid;
1830 r.top = y * td->tile_hgt + td->size_oh1;
1831 r.bottom = r.top + td->tile_hgt;
1840 * Low level graphics. Assumes valid input.
1842 * Draw several ("n") chars, with an attr, at a given location.
1844 static errr Term_text_mac(int x, int y, int n, byte a, const char *cp)
1848 term_data *td = (term_data*)(Term->data);
1851 term_data_color(td, (a & 0x0F));
1853 /* Starting pixel */
1854 xp = x * td->tile_wid + td->tile_o_x + td->size_ow1;
1855 yp = y * td->tile_hgt + td->tile_o_y + td->size_oh1;
1857 /* Move to the correct location */
1860 /* Draw the character */
1861 if (n == 1) DrawChar(*cp);
1863 /* Draw the string */
1864 else DrawText(cp, 0, n);
1872 * Low level graphics (Assumes valid input)
1874 * Erase "n" characters starting at (x,y)
1876 static errr Term_pict_mac(int x, int y, int n, const byte *ap, const char *cp)
1880 bool use_buffer = false;
1881 term_data *td = (term_data*)(Term->data);
1882 GDHandle saveGDevice;
1883 GWorldPtr saveGWorld;
1886 PixMapHandle PortPix;
1891 GetGWorld(&saveGWorld, &saveGDevice);
1895 /* Destination rectangle */
1896 r2.left = x * td->tile_wid + td->size_ow1;
1897 r2.right = r2.left + td->tile_wid;
1899 r2.bottom = r2.top + td->tile_hgt;
1902 SetGWorld(td->bufferPort, nil);
1904 PortPix = GetGWorldPixMap(td->bufferPort );
1905 LockPixels( PortPix );
1907 /* Instantiate font */
1908 TextFont(td->font_id);
1909 TextSize(td->font_size);
1910 TextFace(td->font_face);
1912 /* Restore colors */
1913 BackColor(blackColor);
1914 ForeColor(whiteColor);
1918 EraseRect(&td->bufferPort->portRect);
1925 /* Destination rectangle */
1926 r2.left = x * td->tile_wid + td->size_ow1;
1927 r2.right = r2.left + td->tile_wid;
1928 r2.top = y * td->tile_hgt + td->size_oh1;
1929 r2.bottom = r2.top + td->tile_hgt;
1931 /* no buffering, so we use the normal current port */
1936 /* Scan the input */
1937 for (i = 0; i < n; i++)
1944 #ifdef ANGBAND_LITE_MAC
1948 #else /* ANGBAND_LITE_MAC */
1950 /* Graphics -- if Available and Needed */
1951 if (use_graphics && ((td == &data[0]) || (td == &data[6])) &&
1952 ((byte)a & 0x80) && ((byte)c & 0x80))
1958 row = ((byte)a & 0x7F);
1959 col = ((byte)c & 0x7F);
1961 /* Source rectangle */
1962 r1.left = col * kGrafWidth;
1963 r1.top = row * kGrafHeight;
1964 r1.right = r1.left + kGrafWidth;
1965 r1.bottom = r1.top + kGrafHeight;
1967 /* Hardwire CopyBits */
1968 BackColor(whiteColor);
1969 ForeColor(blackColor);
1971 /* Draw the picture */
1973 BitMapPtr srcBitMap = (BitMapPtr)(frameP->framePix);
1974 BitMapPtr destBitMap;
1978 destBitMap = (BitMapPtr)(td->bufferPix);
1982 destBitMap = (BitMapPtr)&(td->w->portBits);
1985 /* draw transparent tile */
1986 /* BackColor is ignored and the destination is left untouched */
1987 BackColor(blackColor);
1988 CopyBits( srcBitMap, destBitMap, &r1, &r2, transparent, NULL );
1990 /* Restore colors */
1991 BackColor(blackColor);
1992 ForeColor(whiteColor);
2001 #endif /* ANGBAND_LITE_MAC */
2012 term_data_color(td, (a & 0x0F));
2014 /* Starting pixel */
2015 xp = r2.left + td->tile_o_x;
2016 yp = r2.top + td->tile_o_y;
2018 /* Move to the correct location */
2021 /* Draw the character */
2025 term_data_color(td, (a & 0x0F));
2027 /* Starting pixel */
2028 xp = r2.left + td->tile_o_x;
2031 /* Move to the correct location */
2035 /* Draw the character */
2040 r2.left += td->tile_wid;
2041 r2.right += td->tile_wid;
2043 /* Draw the character */
2050 r2.left += td->tile_wid;
2051 r2.right += td->tile_wid;
2056 /* Now we blast the buffer pixmap onto the screen in the right place */
2057 BitMapPtr srcBitMap = (BitMapPtr)(td->bufferPix);
2059 BitMapPtr destBitMap = (BitMapPtr)&(td->w->portBits);
2065 srcRect.left = x * td->tile_wid + td->size_ow1;
2067 srcRect.right = srcRect.left + (td->tile_wid * n);
2068 srcRect.bottom = td->tile_hgt;
2070 destRect.left = x * td->tile_wid + td->size_ow1;
2071 destRect.right = destRect.left + (td->tile_wid * n);
2072 destRect.top = y * td->tile_hgt + td->size_oh1;
2073 destRect.bottom = destRect.top + td->tile_hgt;
2076 UnlockPixels( PortPix );
2078 /* Restore GWorld */
2079 SetGWorld(saveGWorld, saveGDevice);
2081 /* Hardwire CopyBits */
2082 BackColor(whiteColor);
2083 ForeColor(blackColor);
2085 //CopyBits( srcBitMap, destBitMap, &srcRect, &destRect, srcCopy, NULL );
2086 CopyBits( (BitMapPtr)(td->bufferPix)
2087 , &(td->w->portBits), &srcRect, &destRect, srcCopy, NULL );
2089 /* Restore colors */
2090 BackColor(blackColor);
2091 ForeColor(whiteColor);
2104 * Create and initialize window number "i"
2106 static void term_data_link(int i)
2110 term_data *td = &data[i];
2115 /* Require mapped */
2116 if (!td->mapped) return;
2121 /* Initialize the term */
2122 term_init(td->t, td->cols, td->rows, td->keys);
2124 /* Use a "software" cursor */
2125 td->t->soft_cursor = TRUE;
2127 /* Erase with "white space" */
2128 td->t->attr_blank = TERM_WHITE;
2129 td->t->char_blank = ' ';
2131 /* Prepare the init/nuke hooks */
2132 td->t->init_hook = Term_init_mac;
2133 td->t->nuke_hook = Term_nuke_mac;
2135 /* Prepare the function hooks */
2136 td->t->user_hook = Term_user_mac;
2137 td->t->xtra_hook = Term_xtra_mac;
2138 td->t->wipe_hook = Term_wipe_mac;
2139 td->t->curs_hook = Term_curs_mac;
2140 td->t->text_hook = Term_text_mac;
2141 td->t->pict_hook = Term_pict_mac;
2143 /* Link the local structure */
2144 td->t->data = (vptr)(td);
2147 Term_activate(td->t);
2149 /* Global pointer */
2150 angband_term[i] = td->t;
2160 * Set the "current working directory" (also known as the "default"
2161 * volume/directory) to the location of the current application.
2163 * Code by: Maarten Hazewinkel (mmhazewi@cs.ruu.nl)
2165 * This function does not appear to work correctly with System 6.
2167 static void SetupAppDir(void)
2171 char errString[100];
2173 /* Get the location of the Angband executable */
2174 fcbBlock.ioCompletion = NULL;
2175 fcbBlock.ioNamePtr = NULL;
2176 fcbBlock.ioVRefNum = 0;
2177 fcbBlock.ioRefNum = CurResFile();
2178 fcbBlock.ioFCBIndx = 0;
2179 err = PBGetFCBInfo(&fcbBlock, FALSE);
2183 sprintf(errString, "PBGetFCBInfo ¥¨¥é¡¼ #%d.\r ½ªÎ»¤·¤Þ¤¹.", err);
2185 sprintf(errString, "Fatal PBGetFCBInfo Error #%d.\r Exiting.", err);
2187 mac_warning(errString);
2191 /* Extract the Vol and Dir */
2192 app_vol = fcbBlock.ioFCBVRefNum;
2193 app_dir = fcbBlock.ioFCBParID;
2195 /* Set the current working directory to that location */
2196 err = HSetVol(NULL, app_vol, app_dir);
2200 sprintf(errString, "HSetVol ¥¨¥é¡¼ #%d.\r ½ªÎ»¤·¤Þ¤¹.", err);
2202 sprintf(errString, "Fatal HSetVol Error #%d.\r Exiting.", err);
2204 mac_warning(errString);
2213 * Global "preference" file pointer
2218 * Read a "short" from the file
2220 static int getshort(void)
2224 if (0 == my_fgets(fff, buf, 256)) x = atoi(buf);
2229 * Dump a "short" to the file
2231 static void putshort(int x)
2233 fprintf(fff, "%d\n", x);
2239 * Write the "preference" data to the current "file"
2241 static void save_prefs(void)
2248 /*** The current version ***/
2250 putshort(VERSION_MAJOR);
2251 putshort(VERSION_MINOR);
2252 putshort(VERSION_PATCH);
2253 putshort(VERSION_EXTRA);
2255 putshort(arg_sound);
2256 putshort(arg_graphics);
2259 for( i = 0 ; i < 7 ; i++ )
2260 putshort(soundmode[i]);
2263 for (i = 0; i < MAX_TERM_DATA; i++)
2268 putshort(td->mapped);
2270 putshort(td->font_id);
2271 putshort(td->font_size);
2272 putshort(td->font_face);
2275 putshort(td->tile_wid);
2276 putshort(td->tile_hgt);
2282 putshort(td->r.left);
2283 putshort(td->r.top);
2289 * Load the preferences from the current "file"
2291 * XXX XXX XXX Being able to undefine various windows is
2292 * slightly bizarre, and may cause problems.
2294 static void load_prefs(void)
2298 int old_major, old_minor, old_patch, old_extra;
2303 /*** Version information ***/
2305 /* Preferences version */
2306 old_major = getshort();
2307 old_minor = getshort();
2308 old_patch = getshort();
2309 old_extra = getshort();
2311 /* Hack -- Verify or ignore */
2312 if ((old_major != VERSION_MAJOR) ||
2313 (old_minor != VERSION_MINOR) ||
2314 (old_patch != VERSION_PATCH) ||
2315 (old_extra != VERSION_EXTRA))
2319 mac_warning("¸Å¤¤½é´üÀßÄê¥Õ¥¡¥¤¥ë¤ò̵»ë¤·¤Þ¤¹.");
2321 mac_warning("Ignoring old preferences.");
2327 arg_sound = getshort();
2328 arg_graphics = getshort();
2331 for( i = 0 ; i < 7 ; i++ )
2332 soundmode[i] = getshort();
2335 m = GetMenuHandle(134); //m = GetMHandle(134);
2337 /* Item "arg_sound" */
2338 CheckItem(m, 1, arg_sound);
2340 /* Item "arg_graphics" */
2341 CheckItem(m, 2, arg_graphics);
2344 for (i = 0; i < MAX_TERM_DATA; i++)
2349 td->mapped = getshort();
2351 td->font_id = getshort();
2352 td->font_size = getshort();
2353 td->font_face = getshort();
2356 td->tile_wid = getshort();
2357 td->tile_hgt = getshort();
2360 td->cols = getshort();
2361 td->rows = getshort();
2363 td->r.left = getshort();
2364 td->r.top = getshort();
2367 if (feof(fff)) break;
2375 * Hack -- default data for a window
2377 static void term_data_hack(term_data *td)
2382 GetFNum( "\pÅùÉýÌÀÄ«", &fid); /* ¥Õ¥©¥ó¥È̾¤«¤éIDÈÖ¹æ¤òÄ´¤Ù¤ë */
2383 SetFScaleDisable( true );
2385 /* Default to Monaco font */
2386 GetFNum("\pmonaco", &fid);
2389 WIPE(td, term_data);
2394 /* Default borders */
2405 /* Default font size */
2408 /* Default font face */
2415 /* Default position */
2425 * Read the preference file, Create the windows.
2427 * We attempt to use "FindFolder()" to track down the preference file,
2428 * but if this fails, for any reason, we will try the "SysEnvirons()"
2429 * method, which may work better with System 6.
2431 static void init_windows(void)
2444 /*** Default values ***/
2446 /* Initialize (backwards) */
2447 for (i = MAX_TERM_DATA - 1; i >= 0; i--)
2460 s = angband_term_name[i];
2465 /* Maximal length */
2468 /* Copy the title */
2469 strncpy((char*)(td->title) + 1, s, n);
2471 /* Save the length */
2474 /* Tile the windows */
2475 td->r.left += (b * 30);
2476 td->r.top += (b * 30);
2483 /*** Load preferences ***/
2485 /* Assume failure */
2488 /* Assume failure */
2501 /* Find the folder */
2502 err = FindFolder(kOnSystemDisk, kPreferencesFolderType, kCreateFolder,
2508 /* Extract a path name */
2509 PathNameFromDirID(dirID, vref, (StringPtr)foo);
2511 /* Convert the string */
2512 ptocstr((StringPtr)foo);
2514 /* Append the preference file name */
2515 strcat(foo, PREF_FILE_NAME);
2517 /* Open the preference file */
2518 fff = fopen(foo, "r");
2525 #endif /* USE_SFL_CODE */
2531 HGetVol(0, &savev, &saved);
2533 /* Go to the "system" folder */
2534 SysEnvirons(curSysEnvVers, &env);
2535 SetVol(0, env.sysVRefNum);
2538 fff = fopen(PREF_FILE_NAME, "r");
2541 HSetVol(0, savev, saved);
2544 /* Load preferences */
2547 /* Load a real preference file */
2550 /* Close the file */
2555 /*** Instantiate ***/
2566 /* Link (backwards, for stacking order) */
2567 for (i = MAX_TERM_DATA - 1; i >= 0; i--)
2576 Term_activate(td->t);
2580 static void init_sound( void )
2584 SignedByte permission = fsRdPerm;
2590 /* Descend into "lib" folder */
2591 pb.ioCompletion = NULL;
2592 pb.ioNamePtr = "\plib";
2593 pb.ioVRefNum = app_vol;
2594 pb.ioDrDirID = app_dir;
2597 /* Check for errors */
2598 err = PBGetCatInfo((CInfoPBPtr)&pb, FALSE);
2601 if ((err == noErr) && (pb.ioFlAttrib & 0x10))
2603 /* Descend into "lib/save" folder */
2604 pb.ioCompletion = NULL;
2605 pb.ioNamePtr = "\pxtra";
2606 pb.ioVRefNum = app_vol;
2607 pb.ioDrDirID = pb.ioDrDirID;
2610 /* Check for errors */
2611 err = PBGetCatInfo((CInfoPBPtr)&pb, FALSE);
2614 if ((err == noErr) && (pb.ioFlAttrib & 0x10))
2616 /* Descend into "lib/save" folder */
2617 pb.ioCompletion = NULL;
2618 pb.ioNamePtr = "\psound";
2619 pb.ioVRefNum = app_vol;
2620 pb.ioDrDirID = pb.ioDrDirID;
2623 /* Check for errors */
2624 err = PBGetCatInfo((CInfoPBPtr)&pb, FALSE);
2627 if ((err == noErr) && (pb.ioFlAttrib & 0x10))
2629 ret = HOpenResFile( app_vol , pb.ioDrDirID , "\psound.rsrc" , permission );
2633 for( i = 0 ; i < 7 ; i++ )
2634 soundmode[i] = false;
2636 for( i = 1 ; i < SOUND_MAX ; i++ ){
2637 /* Get the proper sound name */
2638 sprintf((char*)sound + 1, "%.16s.wav", angband_sound_name[i]);
2639 sound[0] = strlen((char*)sound + 1);
2641 /* Obtain resource XXX XXX XXX */
2642 handle = Get1NamedResource('snd ', sound);
2643 if( handle == NULL || ext_sound )
2644 handle = GetNamedResource('snd ', sound);
2647 soundmode[soundchoice[i]] = true;
2660 static void init_chuukei( void )
2666 path_build(path, 1024, ANGBAND_DIR_XTRA, "chuukei.txt");
2668 fp = fopen(path, "r");
2673 if (fgets(tmp, 1024, fp)){
2675 int n = strlen(tmp);
2681 chuukei_server = TRUE;
2682 if(connect_chuukei_server(&tmp[2])<0){
2683 msg_print("connect fail");
2686 msg_print("connect");
2693 chuukei_client = TRUE;
2694 connect_chuukei_server(&tmp[2]);
2710 short InevrtCheck( DialogPtr targetDlg, short check )
2717 GetDialogItem( targetDlg, check, &itemType, &checkH, &box );
2718 result = (GetControlValue( (ControlHandle)checkH ) + 1 ) % 2;
2719 SetControlValue( (ControlHandle)checkH , result );
2727 short SetCheck( DialogPtr targetDlg, short check, long result )
2734 GetDialogItem( targetDlg, check, &itemType, &checkH, &box );
2735 SetControlValue( (ControlHandle)checkH , result );
2743 short GetCheck( DialogPtr targetDlg, short check )
2750 GetDialogItem( targetDlg, check, &itemType, &checkH, &box );
2751 result = GetControlValue( (ControlHandle)checkH );
2755 void SoundConfigDLog(void)
2762 dialog=GetNewDialog(131, 0, (WindowPtr)-1);
2763 SetDialogDefaultItem( dialog, ok );
2764 SetDialogCancelItem( dialog, cancel );
2765 for( i = 1 ; i < 7 ; i++ )
2766 SetCheck( dialog, i+2 , soundmode[i] );
2769 for( item_hit = 100 ; cancel < item_hit ; ){
2770 ModalDialog(0, &item_hit);
2774 for( i = 1 ; i < 7 ; i++ )
2775 soundmode[i] = GetCheck( dialog, i+2 );
2780 InevrtCheck( dialog, item_hit );
2783 DisposeDialog(dialog);
2792 static void save_pref_file(void)
2801 /* Assume failure */
2804 /* Assume failure */
2821 /* Find the folder */
2822 err = FindFolder(kOnSystemDisk, kPreferencesFolderType, kCreateFolder,
2828 /* Extract a path name */
2829 PathNameFromDirID(dirID, vref, (StringPtr)foo);
2831 /* Convert the string */
2832 ptocstr((StringPtr)foo);
2834 /* Append the preference file name */
2835 strcat(foo, PREF_FILE_NAME);
2837 /* Open the preference file */
2838 /* my_fopen set file type and file creator for MPW */
2839 fff = my_fopen(foo, "w");
2846 #endif /* USE_SFL_CODE */
2852 HGetVol(0, &savev, &saved);
2854 /* Go to "system" folder */
2855 SysEnvirons(curSysEnvVers, &env);
2856 SetVol(0, env.sysVRefNum);
2858 /* Open the preference file */
2859 /* my_fopen set file type and file creator for MPW */
2860 fff = fopen(PREF_FILE_NAME, "w");
2863 HSetVol(0, savev, saved);
2866 /* Save preferences */
2869 /* Write the preferences */
2880 * A simple "Yes/No" filter to parse "key press" events in dialog windows
2882 static pascal Boolean ynfilter(DialogPtr dialog, EventRecord *event, short *ip)
2884 /* Parse key press events */
2885 if (event->what == keyDown)
2890 /* Extract the pressed key */
2891 c = (event->message & charCodeMask);
2893 /* Accept "no" and <return> and <enter> */
2894 if ((c=='n') || (c=='N') || (c==13) || (c==3)) i = 1;
2897 else if ((c=='y') || (c=='Y')) i = 2;
2899 /* Handle "yes" or "no" */
2903 ControlHandle control;
2906 /* Get the button */
2907 GetDialogItem(dialog, i, &type, (Handle*)&control, &r); //GetDItem(dialog, i, &type, (Handle*)&control, &r);
2909 /* Blink button for 1/10 second */
2910 HiliteControl(control, 1);
2911 Term_xtra_mac(TERM_XTRA_DELAY, 100);
2912 HiliteControl(control, 0);
2926 * Handle menu: "File" + "New"
2928 static void do_menu_file_new(void)
2933 /* Game is in progress */
2934 game_in_progress = 1;
2948 * Handle menu: "File" + "Open"
2950 static void do_menu_file_open(bool all)
2964 /* vrefnum = GetSFCurVol(); */
2965 vrefnum = -*((short*)0x214);
2967 /* drefnum = GetSFCurDir(); */
2968 drefnum = *((long*)0x398);
2970 /* Descend into "lib" folder */
2971 pb.ioCompletion = NULL;
2972 pb.ioNamePtr = "\plib";
2973 pb.ioVRefNum = vrefnum;
2974 pb.ioDrDirID = drefnum;
2977 /* Check for errors */
2978 err = PBGetCatInfo((CInfoPBPtr)&pb, FALSE);
2981 if ((err == noErr) && (pb.ioFlAttrib & 0x10))
2983 /* Descend into "lib/save" folder */
2984 pb.ioCompletion = NULL;
2985 pb.ioNamePtr = "\psave";
2986 pb.ioVRefNum = vrefnum;
2987 pb.ioDrDirID = pb.ioDrDirID;
2990 /* Check for errors */
2991 err = PBGetCatInfo((CInfoPBPtr)&pb, FALSE);
2994 if ((err == noErr) && (pb.ioFlAttrib & 0x10))
2996 /* SetSFCurDir(pb.ioDrDirID); */
2997 *((long*)0x398) = pb.ioDrDirID;
3001 /* Window location */
3002 topleft.h = (qd.screenBits.bounds.left+qd.screenBits.bounds.right)/2-344/2;
3003 topleft.v = (2*qd.screenBits.bounds.top+qd.screenBits.bounds.bottom)/3-188/2;
3005 /* Allow "all" files */
3009 SFGetFile(topleft, "\p", NULL, -1, types, NULL, &reply);
3012 /* Allow "save" files */
3019 SFGetFile(topleft, "\p", NULL, 1, types, NULL, &reply);
3023 if (!reply.good) return;
3025 /* Extract textual file name for save file */
3026 GetWDInfo(reply.vRefNum, &vrefnum, &drefnum, &junk);
3027 refnum_to_name(savefile, drefnum, vrefnum, (char*)reply.fName);
3032 /* Game is in progress */
3033 game_in_progress = 1;
3047 * Handle the "open_when_ready" flag
3049 static void handle_open_when_ready(void)
3051 /* Check the flag XXX XXX XXX make a function for this */
3052 if (open_when_ready && initialized && !game_in_progress)
3055 open_when_ready = FALSE;
3057 /* Game is in progress */
3058 game_in_progress = 1;
3077 * Initialize the menus
3079 * Verify menus 128, 129, 130
3080 * Create menus 131, 132, 133, 134
3082 * The standard menus are:
3084 * Apple (128) = { About, -, ... }
3085 * File (129) = { New,Open,Import,Close,Save,-,Exit,Quit }
3086 * Edit (130) = { Cut, Copy, Paste, Clear } (?)
3087 * Font (131) = { Bold, Extend, -, Monaco, ..., -, ... }
3088 * Size (132) = { ... }
3089 * Window (133) = { Angband, Mirror, Recall, Choice,
3090 * Term-4, Term-5, Term-6, Term-7 }
3091 * Special (134) = { arg_sound, arg_graphics, -,
3092 * arg_fiddle, arg_wizard }
3094 static void init_menubar(void)
3105 /* Get the "apple" menu */
3108 /* Insert the menu */
3111 /* Add the DA's to the "apple" menu */
3112 AppendResMenu (m, 'DRVR'); //AddResMenu(m, 'DRVR');
3115 /* Get the "File" menu */
3118 /* Insert the menu */
3122 /* Get the "Edit" menu */
3125 /* Insert the menu */
3129 /* Make the "Font" menu */
3131 m = NewMenu(131, "\p¥Õ¥©¥ó¥È");
3133 m = NewMenu(131, "\pFont");
3136 /* Insert the menu */
3140 AppendMenu(m, "\pBold");
3143 AppendMenu(m, "\pWide");
3145 /* Add a separator */
3146 AppendMenu(m, "\p-");
3149 r.left = r.right = r.top = r.bottom = 0;
3151 /* Make the fake window */
3152 tmpw = NewWindow(0, &r, "\p", false, documentProc, 0, 0, 0);
3154 /* Activate the "fake" window */
3163 /* Add the fonts to the menu */
3164 AppendResMenu(m, 'FONT'); //AddResMenu(m, 'FONT');
3170 for (i = n; i >= 4; i--)
3175 /* Acquire the font name */
3176 /* GetMenuItemText(m, i, tmpName); */
3177 GetMenuItemText(m, i, tmpName); //GetItem(m, i, tmpName);
3179 /* Acquire the font index */
3180 GetFNum(tmpName, &fontNum);
3182 /* Apply the font index */
3185 /* Remove non-mono-spaced fonts */
3186 if ((CharWidth('i') != CharWidth('W')) || (CharWidth('W') == 0))
3188 /* Delete the menu item XXX XXX XXX */
3189 /* DeleteMenuItem(m, i); */
3190 DeleteMenuItem (m, i); //DelMenuItem(m, i);
3194 /* Destroy the old window */
3195 DisposeWindow(tmpw);
3197 /* Add a separator */
3198 AppendMenu(m, "\p-");
3200 /* Add the fonts to the menu */
3201 AppendResMenu (m, 'FONT'); //AddResMenu(m, 'FONT');
3204 /* Make the "Size" menu */
3206 m = NewMenu(132, "\p¥µ¥¤¥º");
3208 m = NewMenu(132, "\pSize");
3211 /* Insert the menu */
3214 /* Add some sizes (stagger choices) */
3215 for (i = 8; i <= 32; i += ((i / 16) + 1))
3220 sprintf((char*)buf + 1, "%d", i);
3221 buf[0] = strlen((char*)buf + 1);
3228 /* Make the "Windows" menu */
3230 m = NewMenu(133, "\p¥¦¥¤¥ó¥É¥¦");
3232 m = NewMenu(133, "\pWindows");
3235 /* Insert the menu */
3238 /* Default choices */
3239 for (i = 0; i < MAX_TERM_DATA; i++)
3243 /* Describe the item */
3244 sprintf((char*)buf + 1, "%.15s", angband_term_name[i]);
3245 buf[0] = strlen((char*)buf + 1);
3250 /* Command-Key shortcuts */
3251 if (i < 8) SetItemCmd(m, i + 1, '0' + i);
3255 /* Make the "Special" menu */
3257 m = NewMenu(134, "\pÆÃÊÌ");
3259 m = NewMenu(134, "\pSpecial");
3262 /* Insert the menu */
3265 /* Append the choices */
3267 AppendMenu(m, "\p¥µ¥¦¥ó¥É»ÈÍÑ");
3268 AppendMenu(m, "\p¥°¥é¥Õ¥£¥Ã¥¯»ÈÍÑ");
3269 AppendMenu(m, "\p-");
3270 AppendMenu(m, "\parg_fiddle");
3271 AppendMenu(m, "\parg_wizard");
3272 AppendMenu(m, "\p-");
3273 AppendMenu(m, "\p¥µ¥¦¥ó¥ÉÀßÄê...");
3275 AppendMenu(m, "\parg_sound");
3276 AppendMenu(m, "\parg_graphics");
3277 AppendMenu(m, "\p-");
3278 AppendMenu(m, "\parg_fiddle");
3279 AppendMenu(m, "\parg_wizard");
3282 /* Make the "TileWidth" menu */
3284 m = NewMenu(135, "\p¥¿¥¤¥ëÉý");
3286 m = NewMenu(135, "\pTileWidth");
3289 /* Insert the menu */
3292 /* Add some sizes */
3293 for (i = 4; i <= 32; i++)
3298 sprintf((char*)buf + 1, "%d", i);
3299 buf[0] = strlen((char*)buf + 1);
3306 /* Make the "TileHeight" menu */
3308 m = NewMenu(136, "\p¥¿¥¤¥ë¹â");
3310 m = NewMenu(136, "\pTileHeight");
3313 /* Insert the menu */
3316 /* Add some sizes */
3317 for (i = 4; i <= 32; i++)
3322 sprintf((char*)buf + 1, "%d", i);
3323 buf[0] = strlen((char*)buf + 1);
3330 /* Update the menu bar */
3338 static void setup_menus(void)
3348 term_data *td = NULL;
3351 /* Relevant "term_data" */
3352 for (i = 0; i < MAX_TERM_DATA; i++)
3355 if (!data[i].t) continue;
3357 /* Notice the matching window */
3358 if (data[i].w == FrontWindow()) td = &data[i];
3363 m = GetMenuHandle(129); //m = GetMHandle(129);
3369 for (i = 1; i <= n; i++)
3373 CheckItem(m, i, FALSE);
3376 /* Enable "new"/"open..."/"import..." */
3377 if (initialized && !game_in_progress)
3384 /* Enable "close" */
3391 if (initialized && character_generated)
3400 /* EnableItem(m, 8); */
3405 m = GetMenuHandle(130); //m = GetMHandle(130);
3411 for (i = 1; i <= n; i++)
3415 CheckItem(m, i, FALSE);
3418 /* Enable "edit" options if "needed" */
3430 m = GetMenuHandle(131); //m = GetMHandle(131);
3436 for (i = 1; i <= n; i++)
3440 CheckItem(m, i, FALSE);
3443 /* Hack -- look cute XXX XXX */
3444 /* SetItemStyle(m, 1, bold); */
3446 /* Hack -- look cute XXX XXX */
3447 /* SetItemStyle(m, 2, extend); */
3455 /* Enable "extend" */
3458 /* Check the appropriate "bold-ness" */
3459 if (td->font_face & bold) CheckItem(m, 1, TRUE);
3461 /* Check the appropriate "wide-ness" */
3462 if (td->font_face & extend) CheckItem(m, 2, TRUE);
3465 for (i = 4; i <= n; i++)
3471 /* GetMenuItemText(m,i,s); */
3472 GetMenuItemText(m, i, s); //GetItem(m, i, s);
3475 /* Check active font */
3476 if (td->font_id == value) CheckItem(m, i, TRUE);
3482 m = GetMenuHandle(132); //m = GetMHandle(132);
3488 for (i = 1; i <= n; i++)
3492 CheckItem(m, i, FALSE);
3499 for (i = 1; i <= n; i++)
3502 /* GetMenuItemText(m,i,s); */
3503 GetMenuItemText(m, i, s); //GetItem(m, i, s);
3505 value = atoi((char*)(s+1));
3507 /* Enable the "real" sizes */
3508 if (RealFont(td->font_id, value)) EnableItem(m, i);
3510 /* Check the current size */
3511 if (td->font_size == value) CheckItem(m, i, TRUE);
3517 m = GetMenuHandle(133); //m = GetMHandle(133);
3522 /* Check active windows */
3523 for (i = 1; i <= n; i++)
3525 /* Check if needed */
3526 CheckItem(m, i, data[i-1].mapped);
3531 m = GetMenuHandle(134); //m = GetMHandle(134);
3537 for (i = 1; i <= n; i++)
3541 CheckItem(m, i, FALSE);
3544 /* Item "arg_sound" */
3546 CheckItem(m, 1, arg_sound);
3548 /* Item "arg_graphics" */
3550 CheckItem(m, 2, arg_graphics);
3552 /* Item "arg_fiddle" */
3554 CheckItem(m, 4, arg_fiddle);
3556 /* Item "arg_wizard" */
3558 CheckItem(m, 5, arg_wizard);
3561 /* Item "SoundSetting" */
3565 /* EnableItem(m, 9); */
3568 /* TileWidth menu */
3569 m = GetMenuHandle(135); //m = GetMHandle(135);
3575 for (i = 1; i <= n; i++)
3579 CheckItem(m, i, FALSE);
3586 for (i = 1; i <= n; i++)
3589 /* GetMenuItemText(m,i,s); */
3590 GetMenuItemText(m, i, s); //GetItem(m, i, s);
3592 value = atoi((char*)(s+1));
3597 /* Check the current size */
3598 if (td->tile_wid == value) CheckItem(m, i, TRUE);
3603 /* TileHeight menu */
3604 m = GetMenuHandle(136); //m = GetMHandle(136);
3610 for (i = 1; i <= n; i++)
3614 CheckItem(m, i, FALSE);
3621 for (i = 1; i <= n; i++)
3624 /* GetMenuItemText(m,i,s); */
3625 GetMenuItemText(m, i, s); //GetItem(m, i, s);
3627 value = atoi((char*)(s+1));
3632 /* Check the current size */
3633 if (td->tile_hgt == value) CheckItem(m, i, TRUE);
3640 * Process a menu selection (see above)
3642 * Hack -- assume that invalid menu selections are disabled above,
3643 * which I have been informed may not be reliable. XXX XXX XXX
3645 static void menu(long mc)
3649 int menuid, selection;
3651 static unsigned char s[1000];
3655 term_data *td = NULL;
3660 /* Analyze the menu command */
3661 menuid = HiWord(mc);
3662 selection = LoWord(mc);
3665 /* Find the window */
3666 for (i = 0; i < MAX_TERM_DATA; i++)
3668 /* Skip dead windows */
3669 if (!data[i].t) continue;
3671 /* Notice matches */
3672 if (data[i].w == FrontWindow()) td = &data[i];
3676 /* Branch on the menu */
3682 /* About Angband... */
3689 dialog=GetNewDialog(128, 0, (WindowPtr)-1);
3691 /* r=dialog->portRect;
3692 center_rect(&r, &qd.screenBits.bounds);
3693 MoveWindow(dialog, r.left, r.top, 1);*/
3695 ModalDialog(0, &item_hit);
3696 DisposeDialog(dialog); //DisposDialog(dialog);
3700 /* Desk accessory */
3701 /* GetMenuItemText(GetMHandle(128),selection,s); */
3702 GetMenuItemText(GetMenuHandle(128), selection, s); //GetItem(GetMHandle(128), selection, s);
3722 do_menu_file_open(FALSE);
3729 do_menu_file_open(TRUE);
3743 td->t->mapped_flag = FALSE;
3745 /* Hide the window */
3756 plog("º£¤Ï¥»¡¼¥Ö¤¹¤ë¤³¤È¤Ï½ÐÍè¤Þ¤»¤ó¡£");
3758 plog("You may not do that right now.");
3763 /* Hack -- Forget messages */
3766 /* Hack -- Save the game */
3767 do_cmd_save_game(FALSE);
3772 /* Quit (with save) */
3775 /* Save the game (if necessary) */
3776 if (game_in_progress && character_generated)
3780 plog("º£¤Ï¥»¡¼¥Ö¤¹¤ë¤³¤È¤Ï½ÐÍè¤Þ¤»¤ó¡£");
3782 plog("You may not do that right now.");
3786 /* Hack -- Forget messages */
3790 do_cmd_save_game(FALSE);
3811 /* Require a window */
3820 /* Toggle the "bold" setting */
3823 /* Toggle the setting */
3824 if (td->font_face & bold)
3826 td->font_face &= ~bold;
3830 td->font_face |= bold;
3834 /* Tile Width Hight Init */
3835 td->tile_wid = td->tile_hgt = 0;
3837 /* Apply and Verify */
3838 term_data_check_font(td);
3839 term_data_check_size(td);
3841 /* Resize and Redraw */
3842 term_data_resize(td);
3843 term_data_redraw(td);
3848 /* Toggle the "wide" setting */
3851 /* Toggle the setting */
3852 if (td->font_face & extend)
3854 td->font_face &= ~extend;
3858 td->font_face |= extend;
3862 /* Tile Width Hight Init */
3863 td->tile_wid = td->tile_hgt = 0;
3865 /* Apply and Verify */
3866 term_data_check_font(td);
3867 term_data_check_size(td);
3869 /* Resize and Redraw */
3870 term_data_resize(td);
3871 term_data_redraw(td);
3876 /* Get a new font name */
3877 /* GetMenuItemText(GetMHandle(131), selection, s); */
3878 GetMenuItemText(GetMenuHandle(131), selection, s); //GetItem(GetMHandle(131), selection, s);
3881 /* Save the new font id */
3884 /* Current size is bad for new font */
3885 if (!RealFont(td->font_id, td->font_size))
3887 /* Find similar size */
3888 for (i = 1; i <= 32; i++)
3890 /* Adjust smaller */
3891 if (td->font_size - i >= 8)
3893 if (RealFont(td->font_id, td->font_size - i))
3901 if (td->font_size + i <= 128)
3903 if (RealFont(td->font_id, td->font_size + i))
3913 /* Tile Width Hight Init */
3914 td->tile_wid = td->tile_hgt = 0;
3916 /* Apply and Verify */
3917 term_data_check_font(td);
3918 term_data_check_size(td);
3920 /* Resize and Redraw */
3921 term_data_resize(td);
3922 term_data_redraw(td);
3924 /* Restore the window */
3941 /* GetMenuItemText(GetMHandle(132), selection, s); */
3942 GetMenuItemText(GetMenuHandle(132), selection, s); //GetItem(GetMHandle(132), selection, s);
3944 td->font_size = atoi((char*)(s+1));
3947 /* Tile Width Hight Init */
3948 td->tile_wid = td->tile_hgt = 0;
3950 /* Apply and Verify */
3951 term_data_check_font(td);
3952 term_data_check_size(td);
3954 /* Resize and Redraw */
3955 term_data_resize(td);
3956 term_data_redraw(td);
3970 /* Check legality of choice */
3971 if ((i < 0) || (i >= MAX_TERM_DATA)) break;
3973 /* Obtain the window */
3983 td->t->mapped_flag = TRUE;
3985 /* Show the window */
3988 /* Bring to the front */
3989 SelectWindow(td->w);
4001 /* Toggle arg_sound */
4002 arg_sound = !arg_sound;
4004 /* React to changes */
4005 Term_xtra(TERM_XTRA_REACT, 0);
4012 /* Toggle arg_graphics */
4013 arg_graphics = !arg_graphics;
4015 /* Hack -- Force redraw */
4016 Term_key_push(KTRL('R'));
4023 arg_fiddle = !arg_fiddle;
4029 arg_wizard = !arg_wizard;
4043 /* TileWidth menu */
4054 /* GetMenuItemText(GetMHandle(135), selection, s); */
4055 GetMenuItemText(GetMenuHandle(135), selection, s); //GetItem(GetMHandle(135), selection, s);
4057 td->tile_wid = atoi((char*)(s+1));
4059 /* Apply and Verify */
4060 term_data_check_size(td);
4062 /* Resize and Redraw */
4063 term_data_resize(td);
4064 term_data_redraw(td);
4072 /* TileHeight menu */
4083 /* GetMenuItemText(GetMHandle(136), selection, s); */
4084 GetMenuItemText(GetMenuHandle(136), selection, s); //GetItem(GetMHandle(136), selection, s);
4086 td->tile_hgt = atoi((char*)(s+1));
4088 /* Apply and Verify */
4089 term_data_check_size(td);
4091 /* Resize and Redraw */
4092 term_data_resize(td);
4093 term_data_redraw(td);
4103 /* Clean the menu */
4112 * Check for extra required parameters -- From "Maarten Hazewinkel"
4114 static OSErr CheckRequiredAEParams(const AppleEvent *theAppleEvent)
4117 DescType returnedType;
4120 aeError = AEGetAttributePtr(theAppleEvent, keyMissedKeywordAttr, typeWildCard,
4121 &returnedType, NULL, 0, &actualSize);
4123 if (aeError == errAEDescNotFound) return (noErr);
4125 if (aeError == noErr) return (errAEParamMissed);
4132 * Apple Event Handler -- Open Application
4134 static pascal OSErr AEH_Start(const AppleEvent *theAppleEvent,
4135 const AppleEvent *reply, long handlerRefCon)
4137 #pragma unused(reply, handlerRefCon)
4139 return (CheckRequiredAEParams(theAppleEvent));
4144 * Apple Event Handler -- Quit Application
4146 static pascal OSErr AEH_Quit(const AppleEvent *theAppleEvent,
4147 const AppleEvent *reply, long handlerRefCon)
4149 #pragma unused(reply, handlerRefCon)
4152 quit_when_ready = TRUE;
4154 /* Check arguments */
4155 return (CheckRequiredAEParams(theAppleEvent));
4160 * Apple Event Handler -- Print Documents
4162 static pascal OSErr AEH_Print(const AppleEvent *theAppleEvent,
4163 const AppleEvent *reply, long handlerRefCon)
4165 #pragma unused(theAppleEvent, reply, handlerRefCon)
4167 return (errAEEventNotHandled);
4172 * Apple Event Handler by Steve Linberg (slinberg@crocker.com).
4174 * The old method of opening savefiles from the finder does not work
4175 * on the Power Macintosh, because CountAppFiles and GetAppFiles,
4176 * used to return information about the selected document files when
4177 * an application is launched, are part of the Segment Loader, which
4178 * is not present in the RISC OS due to the new memory architecture.
4180 * The "correct" way to do this is with AppleEvents. The following
4181 * code is modeled on the "Getting Files Selected from the Finder"
4182 * snippet from Think Reference 2.0. (The prior sentence could read
4183 * "shamelessly swiped & hacked")
4185 static pascal OSErr AEH_Open(AppleEvent *theAppleEvent,
4186 AppleEvent* reply, long handlerRefCon)
4188 #pragma unused(reply, handlerRefCon)
4195 DescType returnedType;
4199 /* Put the direct parameter (a descriptor list) into a docList */
4200 err = AEGetParamDesc(theAppleEvent, keyDirectObject, typeAEList, &docList);
4201 if (err) return err;
4204 * We ignore the validity check, because we trust the FInder, and we only
4205 * allow one savefile to be opened, so we ignore the depth of the list.
4208 err = AEGetNthPtr(&docList, 1L, typeFSS, &keywd,
4209 &returnedType, (Ptr) &myFSS, sizeof(myFSS), &actualSize);
4210 if (err) return err;
4212 /* Only needed to check savefile type below */
4213 err = FSpGetFInfo(&myFSS, &myFileInfo);
4216 sprintf(foo, "Arg! FSpGetFInfo failed with code %d", err);
4221 /* Ignore non 'SAVE' files */
4222 if (myFileInfo.fdType != 'SAVE') return noErr;
4224 /* XXX XXX XXX Extract a file name */
4225 PathNameFromDirID(myFSS.parID, myFSS.vRefNum, (StringPtr)savefile);
4226 pstrcat((StringPtr)savefile, (StringPtr)&myFSS.name);
4228 /* Convert the string */
4229 ptocstr((StringPtr)savefile);
4231 /* Delay actual open */
4232 open_when_ready = TRUE;
4235 err = AEDisposeDesc(&docList);
4247 * Macintosh modifiers (event.modifier & ccc):
4248 * cmdKey, optionKey, shiftKey, alphaLock, controlKey
4251 * Macintosh Keycodes (0-63 normal, 64-95 keypad, 96-127 extra):
4296 * Optimize non-blocking calls to "CheckEvents()"
4297 * Idea from "Maarten Hazewinkel <mmhazewi@cs.ruu.nl>"
4299 #define EVENT_TICKS 6
4303 * Check for Events, return TRUE if we process any
4305 * Hack -- Handle AppleEvents if appropriate (ignore result code).
4307 static bool CheckEvents(bool wait)
4323 term_data *td = NULL;
4327 static huge lastTicks = 0L;
4330 /* Access the clock */
4331 curTicks = TickCount();
4333 /* Hack -- Allow efficient checking for non-pending events */
4334 if (!wait && (curTicks < lastTicks + EVENT_TICKS)) return (FALSE);
4336 /* Timestamp last check */
4337 lastTicks = curTicks;
4339 /* Let the "system" run */
4342 /* Get an event (or null) */
4343 GetNextEvent(everyEvent, &event);
4345 /* Hack -- Nothing is ready yet */
4346 if (event.what == nullEvent) return (FALSE);
4349 /* Analyze the event */
4357 w = (WindowPtr)event.message;
4368 /* Extract the window */
4369 w = (WindowPtr)event.message;
4371 /* Find the window */
4372 for (i = 0; i < MAX_TERM_DATA; i++)
4374 /* Skip dead windows */
4375 if (!data[i].t) continue;
4377 /* Notice matches */
4378 if (data[i].w == w) td = &data[i];
4381 /* Hack XXX XXX XXX */
4385 /* Redraw the window */
4386 if (td) term_data_redraw(td);
4394 /* Extract some modifiers */
4395 mc = (event.modifiers & controlKey) ? TRUE : FALSE;
4396 ms = (event.modifiers & shiftKey) ? TRUE : FALSE;
4397 mo = (event.modifiers & optionKey) ? TRUE : FALSE;
4398 mx = (event.modifiers & cmdKey) ? TRUE : FALSE;
4400 /* Keypress: (only "valid" if ck < 96) */
4401 ch = (event.message & charCodeMask) & 255;
4403 /* Keycode: see table above */
4404 ck = ((event.message & keyCodeMask) >> 8) & 255;
4406 /* Command + "normal key" -> menu action */
4407 if (mx && (ck < 64))
4409 /* Hack -- Prepare the menus */
4412 /* Mega-Hack -- allow easy exit if nothing to save */
4413 /* if (!character_generated && (ch=='Q' || ch=='q')) ch = 'e'; */
4415 /* Run the Menu-Handler */
4418 /* Turn off the menus */
4426 /* Hide the mouse pointer */
4429 /* Normal key -> simple keypress */
4432 /* Enqueue the keypress */
4436 /* Hack -- normal "keypad keys" -> special keypress */
4437 else if (!mc && !ms && !mo && !mx && (ck < 96))
4439 /* Hack -- "enter" is confused */
4440 if (ck == 76) ch = '\n';
4442 /* Send control-caret as a trigger */
4445 /* Send the "ascii" keypress */
4449 /* Bizarre key -> encoded keypress */
4452 /* Hack -- introduce with control-underscore */
4455 /* Send some modifier keys */
4456 if (mc) Term_keypress('C');
4457 if (ms) Term_keypress('S');
4458 if (mo) Term_keypress('O');
4459 if (mx) Term_keypress('X');
4461 /* Hack -- Downshift and encode the keycode */
4462 Term_keypress('0' + (ck - 64) / 10);
4463 Term_keypress('0' + (ck - 64) % 10);
4465 /* Hack -- Terminate the sequence */
4466 /* MPW can generate 10 or 13 for keycode of '\r' */
4467 /* -noMapCR option swaps '\r' and '\n' */
4468 Term_keypress('\r');
4478 /* Analyze click location */
4479 code = FindWindow(event.where, &w);
4481 /* Find the window */
4482 for (i = 0; i < MAX_TERM_DATA; i++)
4484 /* Skip dead windows */
4485 if (!data[i].t) continue;
4487 /* Notice matches */
4488 if (data[i].w == w) td = &data[i];
4497 menu(MenuSelect(event.where));
4504 SystemClick(&event, w);
4514 r = qd.screenBits.bounds;
4515 r.top += 20; /* GetMBarHeight() XXX XXX XXX */
4516 InsetRect(&r, 4, 4);
4517 DragWindow(w, event.where, &r);
4529 p.h = td->w->portRect.left;
4530 p.v = td->w->portRect.top;
4538 /* Apply and Verify */
4539 term_data_check_size(td);
4549 /* Track the go-away box */
4550 if (TrackGoAway(w, event.where))
4556 td->t->mapped_flag = FALSE;
4558 /* Hide the window */
4574 /* Fake rectangle */
4575 r.left = 20 * td->tile_wid + td->size_ow1;
4576 r.right = 80 * td->tile_wid + td->size_ow1 + td->size_ow2 + 1;
4577 r.top = 1 * td->tile_hgt + td->size_oh1;
4578 r.bottom = 24 * td->tile_hgt + td->size_oh1 + td->size_oh2 + 1;
4580 /* Grow the rectangle */
4581 newsize = GrowWindow(w, event.where, &r);
4584 if (!newsize) break;
4586 /* Extract the new size in pixels */
4587 y = HiWord(newsize) - td->size_oh1 - td->size_oh2;
4588 x = LoWord(newsize) - td->size_ow1 - td->size_ow2;
4590 /* Extract a "close" approximation */
4591 td->rows = y / td->tile_hgt;
4592 td->cols = x / td->tile_wid;
4594 /* Apply and Verify */
4595 term_data_check_size(td);
4598 Term_activate(td->t);
4600 /* Hack -- Resize the term */
4601 Term_resize(td->cols, td->rows);
4603 /* Resize and Redraw */
4604 term_data_resize(td);
4605 term_data_redraw(td);
4624 /* Disk Event -- From "Maarten Hazewinkel" */
4627 /* check for error when mounting the disk */
4628 if (HiWord(event.message) != noErr)
4634 DIBadMount(p, event.message);
4641 /* OS Event -- From "Maarten Hazewinkel" */
4644 switch ((event.message >> 24) & 0x000000FF)
4646 case suspendResumeMessage:
4648 /* Resuming: activate the front window */
4649 if (event.message & resumeFlag)
4651 SetPort(FrontWindow());
4652 SetCursor(&qd.arrow);
4655 /* Suspend: deactivate the front window */
4669 /* From "Steve Linberg" and "Maarten Hazewinkel" */
4670 case kHighLevelEvent:
4672 /* Process apple events */
4673 if (AEProcessAppleEvent(&event) != noErr)
4676 plog("Apple Event Handler¤Î¥¨¥é¡¼¤Ç¤¹.");
4678 plog("Error in Apple Event Handler!");
4682 /* Handle "quit_when_ready" */
4683 if (quit_when_ready)
4686 quit_when_ready = FALSE;
4688 /* Do the menu key */
4691 /* Turn off the menus */
4695 /* Handle "open_when_ready" */
4696 handle_open_when_ready();
4706 /* Something happened */
4713 /*** Some Hooks for various routines ***/
4717 * Mega-Hack -- emergency lifeboat
4719 static vptr lifeboat = NULL;
4723 * Hook to "release" memory
4725 static vptr hook_rnfree(vptr v, huge size)
4728 #pragma unused (size)
4732 /* Alternative method */
4747 * Hook to "allocate" memory
4749 static vptr hook_ralloc(huge size)
4754 /* Make a new pointer */
4755 return (malloc(size));
4759 /* Make a new pointer */
4760 return (NewPtr(size));
4767 * Hook to handle "out of memory" errors
4769 static vptr hook_rpanic(huge size)
4772 #pragma unused (size)
4776 /* Free the lifeboat */
4779 /* Free the lifeboat */
4780 DisposePtr(lifeboat);
4782 /* Forget the lifeboat */
4785 /* Mega-Hack -- Warning */
4787 mac_warning("¥á¥â¥ê¡¼¤¬Â¤ê¤Þ¤»¤ó!\rº£¤¹¤°½ªÎ»¤·¤Æ²¼¤µ¤¤!");
4789 mac_warning("Running out of Memory!\rAbort this process now!");
4792 /* Mega-Hack -- Never leave this function */
4793 while (TRUE) CheckEvents(TRUE);
4796 /* Mega-Hack -- Crash */
4802 * Hook to tell the user something important
4804 static void hook_plog(cptr str)
4806 /* Warning message */
4811 * Hook to tell the user something, and then quit
4813 static void hook_quit(cptr str)
4815 /* Warning if needed */
4816 if (str) mac_warning(str);
4818 /* Write a preference file */
4826 * Hook to tell the user something, and then crash
4828 static void hook_core(cptr str)
4830 /* XXX Use the debugger */
4831 /* DebugStr(str); */
4834 if (str) mac_warning(str);
4836 /* Warn, then save player */
4838 mac_warning("Ã×̿Ū¤Ê¥¨¥é¡¼¤Ç¤¹.\r¶¯À©Åª¤Ë¥»¡¼¥Ö¤·¤Æ½ªÎ»¤·¤Þ¤¹.");
4840 mac_warning("Fatal error.\rI will now attempt to save and quit.");
4843 /* Attempt to save */
4845 if (!save_player()) mac_warning("·Ù¹ð -- ¥»¡¼¥Ö¤Ë¼ºÇÔ¤·¤Þ¤·¤¿!");
4847 if (!save_player()) mac_warning("Warning -- save failed!");
4856 /*** Main program ***/
4862 * XXX XXX XXX Hack -- This function attempts to "fix" the nasty
4863 * "Macintosh Save Bug" by using "absolute" path names, since on
4864 * System 7 machines anyway, the "current working directory" often
4865 * "changes" due to background processes, invalidating any "relative"
4866 * path names. Note that the Macintosh is limited to 255 character
4867 * path names, so be careful about deeply embedded directories...
4869 * XXX XXX XXX Hack -- This function attempts to "fix" the nasty
4870 * "missing lib folder bug" by allowing the user to help find the
4871 * "lib" folder by hand if the "application folder" code fails...
4873 static void init_stuff(void)
4890 /* Fake rectangle */
4897 center_rect(&r, &qd.screenBits.bounds);
4899 /* Extract corner */
4904 /* Default to the "lib" folder with the application */
4905 refnum_to_name(path, app_dir, app_vol, (char*)("\plib:"));
4908 /* Check until done */
4911 /* Prepare the paths */
4912 init_file_paths(path);
4914 /* Build the filename */
4916 path_build(path, 1024, ANGBAND_DIR_FILE, "news_j.txt");
4918 path_build(path, 1024, ANGBAND_DIR_FILE, "news.txt");
4921 /* Attempt to open and close that file */
4922 if (0 == fd_close(fd_open(path, O_RDONLY))) break;
4926 plog_fmt("'%s' ¥Õ¥¡¥¤¥ë¤ò¥ª¡¼¥×¥ó½ÐÍè¤Þ¤»¤ó.", path);
4928 plog_fmt("Unable to open the '%s' file.", path);
4933 plog("Hengband¤Î'lib'¥Õ¥©¥ë¥À¤¬Â¸ºß¤·¤Ê¤¤¤«Àµ¤·¤¯Ìµ¤¤²ÄǽÀ¤¬¤¢¤ê¤Þ¤¹.");
4935 plog("The Angband 'lib' folder is probably missing or misplaced.");
4939 plog("Please 'open' any file in any sub-folder of the 'lib' folder.");
4941 /* Allow "text" files */
4944 /* Allow "save" files */
4947 /* Allow "data" files */
4951 SFGetFile(topleft, "\p", NULL, 3, types, NULL, &reply);
4954 if (!reply.good) quit(NULL);
4956 /* Extract textual file name for given file */
4957 GetWDInfo(reply.vRefNum, &vrefnum, &drefnum, &junk);
4958 refnum_to_name(path, drefnum, vrefnum, (char*)reply.fName);
4960 /* Hack -- Remove the "filename" */
4961 i = strlen(path) - 1;
4962 while ((i > 0) && (path[i] != ':')) i--;
4963 if (path[i] == ':') path[i+1] = '\0';
4965 /* Hack -- allow "lib" folders */
4966 if (suffix(path, "lib:")) continue;
4968 /* Hack -- Remove the "sub-folder" */
4970 while ((i > 1) && (path[i] != ':')) i--;
4971 if (path[i] == ':') path[i+1] = '\0';
4977 * Macintosh Main loop
4981 EventRecord tempEvent;
4982 int numberOfMasters = 10;
4984 /* Increase stack space by 64K */
4985 SetApplLimit(GetApplLimit() - 131072L);//65536L);
4987 /* Stretch out the heap to full size */
4990 /* Get more Masters */
4991 while (numberOfMasters--) MoreMasters();
4993 /* Set up the Macintosh */
4994 InitGraf(&qd.thePort);
5007 FlushEvents(everyEvent, 0);
5009 /* Flush events some more (?) */
5010 (void)EventAvail(everyEvent, &tempEvent);
5011 (void)EventAvail(everyEvent, &tempEvent);
5012 (void)EventAvail(everyEvent, &tempEvent);
5015 #ifdef ANGBAND_LITE_MAC
5019 #else /* ANGBAND_LITE_MAC */
5021 # if defined(powerc) || defined(__powerc)
5023 /* Assume System 7 */
5025 /* Assume Color Quickdraw */
5035 /* Check the Gestalt */
5036 err = Gestalt(gestaltSystemVersion, &versionNumber);
5038 /* Check the version */
5039 if ((err != noErr) || (versionNumber < 0x0700))
5042 quit("¤³¤Î¥×¥í¥°¥é¥à¤Ï´Á»úTalk7.x.x°Ê¹ß¤ÇÆ°ºî¤·¤Þ¤¹.");
5044 quit("You must have System 7 to use this program.");
5054 /* Check the environs */
5055 if (SysEnvirons(1, &env) != noErr)
5058 quit("SysEnvirons ¥³¡¼¥ë¤Ï¼ºÇÔ¤·¤Þ¤·¤¿¡ª");
5060 quit("The SysEnvirons call failed!");
5064 /* Check for System Seven Stuff */
5065 if (env.systemVersion < 0x0700)
5068 quit("¤³¤Î¥×¥í¥°¥é¥à¤Ï´Á»úTalk7.x.x°Ê¹ß¤ÇÆ°ºî¤·¤Þ¤¹.");
5070 quit("You must have System 7 to use this program.");
5074 /* Check for Color Quickdraw */
5075 if (!env.hasColorQD)
5078 quit("¤³¤Î¥×¥í¥°¥é¥à¤ÏColor Quickdraw¤¬Ìµ¤¤¤ÈÆ°ºî¤·¤Þ¤»¤ó.");
5080 quit("You must have Color Quickdraw to use this program.");
5087 #endif /* ANGBAND_LITE_MAC */
5092 /* Obtain a "Universal Procedure Pointer" */
5093 AEH_Start_UPP = NewAEEventHandlerProc(AEH_Start);
5095 /* Install the hook (ignore error codes) */
5096 AEInstallEventHandler(kCoreEventClass, kAEOpenApplication, AEH_Start_UPP,
5099 /* Obtain a "Universal Procedure Pointer" */
5100 AEH_Quit_UPP = NewAEEventHandlerProc(AEH_Quit);
5102 /* Install the hook (ignore error codes) */
5103 AEInstallEventHandler(kCoreEventClass, kAEQuitApplication, AEH_Quit_UPP,
5106 /* Obtain a "Universal Procedure Pointer" */
5107 AEH_Print_UPP = NewAEEventHandlerProc(AEH_Print);
5109 /* Install the hook (ignore error codes) */
5110 AEInstallEventHandler(kCoreEventClass, kAEPrintDocuments, AEH_Print_UPP,
5113 /* Obtain a "Universal Procedure Pointer" */
5114 AEH_Open_UPP = NewAEEventHandlerProc(AEH_Open);
5116 /* Install the hook (ignore error codes) */
5117 AEInstallEventHandler(kCoreEventClass, kAEOpenDocuments, AEH_Open_UPP,
5123 /* Find the current application */
5127 /* Mark ourself as the file creator */
5130 /* Default to saving a "text" file */
5134 #if defined(__MWERKS__)
5136 /* Obtian a "Universal Procedure Pointer" */
5137 ynfilterUPP = NewModalFilterProc(ynfilter);
5142 /* Hook in some "z-virt.c" hooks */
5143 rnfree_aux = hook_rnfree;
5144 ralloc_aux = hook_ralloc;
5145 rpanic_aux = hook_rpanic;
5147 /* Hooks in some "z-util.c" hooks */
5148 plog_aux = hook_plog;
5149 quit_aux = hook_quit;
5150 core_aux = hook_core;
5152 BackColor(blackColor);
5153 ForeColor(whiteColor);
5155 /* Show the "watch" cursor */
5156 SetCursor(*(GetCursor(watchCursor)));
5158 /* Prepare the menubar */
5161 /* Prepare the windows */
5168 /* Hack -- process all events */
5169 while (CheckEvents(TRUE)) /* loop */;
5171 /* Reset the cursor */
5172 SetCursor(&qd.arrow);
5175 /* Mega-Hack -- Allocate a "lifeboat" */
5176 lifeboat = NewPtr(16384);
5178 /* Note the "system" */
5179 ANGBAND_SYS = "mac";
5181 ANGBAND_GRAF = "new";
5183 ANGBAND_GRAF = "old";
5193 /* Hack -- process all events */
5194 while (CheckEvents(TRUE)) /* loop */;
5197 /* We are now initialized */
5201 /* Handle "open_when_ready" */
5202 handle_open_when_ready();
5208 /* Prompt the user */
5210 prt("'¥Õ¥¡¥¤¥ë'¥á¥Ë¥å¡¼¤è¤ê'¿·µ¬'¤Þ¤¿¤Ï'³«¤¯...'¤òÁªÂò¤·¤Æ¤¯¤À¤µ¤¤¡£", 23, 10);
5212 prt("[Choose 'New' or 'Open' from the 'File' menu]", 23, 15);
5215 /* Flush the prompt */
5219 /* Hack -- Process Events Forever */
5220 while (TRUE) CheckEvents(TRUE);