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 * Use "malloc()" instead of "NewPtr()"
167 /* #define USE_MALLOC */
170 #if defined(powerc) || defined(__powerc)
173 * Disable "LITE" version
175 # undef ANGBAND_LITE_MAC
180 #ifdef ANGBAND_LITE_MAC
183 * Maximum number of windows
185 # define MAX_TERM_DATA 1
187 #else /* ANGBAND_LITE_MAC */
190 * Maximum number of windows
192 # define MAX_TERM_DATA 8
195 * Activate some special code
197 # define USE_SFL_CODE
199 #endif /* ANGBAND_LITE_MAC */
206 * Include the necessary header files
208 #include <AppleEvents.h>
218 * The Angband Color Set (0 to 15):
219 * Black, White, Slate, Orange, Red, Blue, Green, Umber
220 * D-Gray, L-Gray, Violet, Yellow, L-Red, L-Blue, L-Green, L-Umber
222 * Colors 8 to 15 are basically "enhanced" versions of Colors 0 to 7.
224 * On the Macintosh, we use color quickdraw, and we use actual "RGB"
225 * values below to choose the 16 colors.
227 * If we are compiled for ancient machines, we bypass color and simply
228 * draw everything in white (letting "z-term.c" automatically convert
229 * "black" into "wipe" calls).
231 static RGBColor foo[16] =
233 {0x0000, 0x0000, 0x0000}, /* TERM_DARK */
234 {0xFFFF, 0xFFFF, 0xFFFF}, /* TERM_WHITE */
235 {0x8080, 0x8080, 0x8080}, /* TERM_SLATE */
236 {0xFFFF, 0x8080, 0x0000}, /* TERM_ORANGE */
237 {0xC0C0, 0x0000, 0x0000}, /* TERM_RED */
238 {0x0000, 0x8080, 0x4040}, /* TERM_GREEN */
239 {0x0000, 0x0000, 0xFFFF}, /* TERM_BLUE */
240 {0x8080, 0x4040, 0x0000}, /* TERM_UMBER */
241 {0x4040, 0x4040, 0x4040}, /* TERM_L_DARK */
242 {0xC0C0, 0xC0C0, 0xC0C0}, /* TERM_L_WHITE */
243 {0xFFFF, 0x0000, 0xFFFF}, /* TERM_VIOLET */
244 {0xFFFF, 0xFFFF, 0x0000}, /* TERM_YELLOW */
245 {0xFFFF, 0x0000, 0x0000}, /* TERM_L_RED */
246 {0x0000, 0xFFFF, 0x0000}, /* TERM_L_GREEN */
247 {0x0000, 0xFFFF, 0xFFFF}, /* TERM_L_BLUE */
248 {0xC0C0, 0x8080, 0x4040} /* TERM_L_UMBER */
257 typedef struct term_data term_data;
270 #ifdef ANGBAND_LITE_MAC
274 #else /* ANGBAND_LITE_MAC */
286 #endif /* ANGBAND_LITE_MAC */
289 GWorldPtr bufferPort;
290 PixMapHandle bufferPixHndl;
335 * Forward declare -- see below
337 static bool CheckEvents(bool wait);
341 * Hack -- location of the main directory
343 static short app_vol;
348 * Delay handling of double-clicked savefiles
350 Boolean open_when_ready = FALSE;
353 * Delay handling of pre-emptive "quit" event
355 Boolean quit_when_ready = FALSE;
359 * Hack -- game in progress
361 static int game_in_progress = 0;
365 * Only do "SetPort()" when needed
367 static WindowPtr active = NULL;
372 * An array of term_data's
374 static term_data data[MAX_TERM_DATA];
379 * Note when "open"/"new" become valid
381 static bool initialized = FALSE;
386 * CodeWarrior uses Universal Procedure Pointers
388 static ModalFilterUPP ynfilterUPP;
395 AEEventHandlerUPP AEH_Start_UPP;
396 AEEventHandlerUPP AEH_Quit_UPP;
397 AEEventHandlerUPP AEH_Print_UPP;
398 AEEventHandlerUPP AEH_Open_UPP;
406 static int ext_sound = 0;
414 #define SND_CMD_ERROR 6
416 static int soundchoice[] = {
484 static int soundmode[8];
491 * Convert refnum+vrefnum+fname into a full file name
492 * Store this filename in 'buf' (make sure it is long enough)
493 * Note that 'fname' looks to be a "pascal" string
495 static void refnum_to_name(char *buf, long refnum, short vrefnum, char *fname)
507 for (j=1; j<=fname[0]; j++)
509 res[i-fname[0]+j] = fname[j];
513 pb.ioCompletion=NULL;
515 pb.ioVRefNum=vrefnum;
521 pb.ioDrDirID=pb.ioDrParID;
522 err = PBGetCatInfo((CInfoPBPtr)&pb, FALSE);
524 for (j=1; j<=name[0]; j++)
526 res[i-name[0]+j] = name[j];
530 if (pb.ioDrDirID == fsRtDirID) break;
533 /* Extract the result */
534 for (j = 0, i++; res[i]; j++, i++) buf[j] = res[i];
542 * XXX XXX XXX Allow the system to ask us for a filename
544 static bool askfor_file(char *buf, int len)
552 /* Default file name */
553 sprintf((char*)dflt + 1, "%s's description", buf);
554 dflt[0] = strlen((char*)dflt + 1);
556 /* Ask for a file name */
557 topleft.h=(qd.screenBits.bounds.left+qd.screenBits.bounds.right)/2-344/2;
558 topleft.v=(2*qd.screenBits.bounds.top+qd.screenBits.bounds.bottom)/3-188/2;
559 SFPutFile(topleft, "\pSelect a filename:", dflt, NULL, &reply);
560 /* StandardPutFile("\pSelect a filename:", dflt, &reply); */
568 GetWDInfo(reply.vRefNum, &vrefnum, &drefnum, &junk);
570 /* Extract the name */
571 refnum_to_name(buf, drefnum, vrefnum, (char*)reply.fName);
586 * Center a rectangle inside another rectangle
588 static void center_rect(Rect *r, Rect *s)
590 int centerx = (s->left + s->right)/2;
591 int centery = (2*s->top + s->bottom)/3;
592 int dx = centerx - (r->right - r->left)/2 - r->left;
593 int dy = centery - (r->bottom - r->top)/2 - r->top;
602 * Convert a pascal string in place
604 * This function may be defined elsewhere, but since it is so
605 * small, it is not worth finding the proper function name for
606 * all the different platforms.
608 static void ptocstr(StringPtr src)
612 /* Hack -- pointer */
613 char *s = (char*)(src);
615 /* Hack -- convert the string */
616 for (i = s[0]; i; i--, s++) s[0] = s[1];
618 /* Hack -- terminate the string */
623 #if defined(USE_SFL_CODE)
627 * The following three routines (pstrcat, pstrinsert, and PathNameFromDirID)
628 * were taken from the Think Reference section called "Getting a Full Pathname"
629 * (under the File Manager section). We need PathNameFromDirID to get the
630 * full pathname of the opened savefile, making no assumptions about where it
633 * I had to hack PathNameFromDirID a little for MetroWerks, but it's awfully
636 static void pstrcat(StringPtr dst, StringPtr src)
639 BlockMove(src + 1, dst + *dst + 1, *src);
641 /* adjust length byte */
646 * pstrinsert - insert string 'src' at beginning of string 'dst'
648 static void pstrinsert(StringPtr dst, StringPtr src)
650 /* make room for new string */
651 BlockMove(dst + 1, dst + *src + 1, *dst);
653 /* copy new string in */
654 BlockMove(src + 1, dst + 1, *src);
656 /* adjust length byte */
660 static void PathNameFromDirID(long dirID, short vRefNum, StringPtr fullPathName)
663 Str255 directoryName;
666 fullPathName[0] = '\0';
668 block.dirInfo.ioDrParID = dirID;
669 block.dirInfo.ioNamePtr = directoryName;
673 block.dirInfo.ioVRefNum = vRefNum;
674 block.dirInfo.ioFDirIndex = -1;
675 block.dirInfo.ioDrDirID = block.dirInfo.ioDrParID;
676 err = PBGetCatInfo(&block, FALSE);
677 pstrcat(directoryName, (StringPtr)"\p:");
678 pstrinsert(fullPathName, directoryName);
679 if (block.dirInfo.ioDrDirID == 2) break;
688 * Activate a given window, if necessary
690 static void activate(WindowPtr w)
705 * Display a warning message
707 static void mac_warning(cptr warning)
712 /* Limit of 250 chars */
713 len = strlen(warning);
714 if (len > 250) len = 250;
716 /* Make a "Pascal" string */
718 for (i=0; i<len; i++) text[i+1] = warning[i];
720 /* Prepare the dialog box values */
721 ParamText(text, "\p", "\p", "\p");
723 /* Display the Alert, wait for Okay */
729 /*** Some generic functions ***/
732 #ifdef ANGBAND_LITE_MAC
735 * Hack -- activate a color (0 to 255)
737 #define term_data_color(TD,A) /* Nothing */
739 #else /* ANGBAND_LITE_MAC */
742 * Hack -- activate a color (0 to 255)
744 static void term_data_color(term_data *td, int a)
751 /* Extract the R,G,B data */
752 rv = angband_color_table[a][1];
753 gv = angband_color_table[a][2];
754 bv = angband_color_table[a][3];
757 color.red = (rv | (rv << 8));
758 color.green = (gv | (gv << 8));
759 color.blue = (bv | (bv << 8));
761 /* Activate the color */
762 RGBForeColor(&color);
767 /* Activate the color */
774 /* Extract the R,G,B data */
775 rv = angband_color_table[a][1];
776 gv = angband_color_table[a][2];
777 bv = angband_color_table[a][3];
780 color.red = (rv | (rv << 8));
781 color.green = (gv | (gv << 8));
782 color.blue = (bv | (bv << 8));
784 /* Activate the color */
785 RGBForeColor(&color);
793 #endif /* ANGBAND_LITE_MAC */
797 * Hack -- Apply and Verify the "font" info
799 * This should usually be followed by "term_data_check_size()"
801 static void term_data_check_font(term_data *td)
807 WindowPtr old = active;
813 /* Instantiate font */
814 TextFont(td->font_id);
815 TextSize(td->font_size);
816 TextFace(td->font_face);
818 /* Extract the font info */
821 /* Assume monospaced */
822 td->font_mono = TRUE;
824 /* Extract the font sizing values XXX XXX XXX */
825 td->font_wid = CharWidth('@'); /* info.widMax; */
826 td->font_hgt = info.ascent + info.descent;
828 td->font_o_y = info.ascent;
830 /* Check important characters */
831 for (i = 33; i < 127; i++)
833 /* Hack -- notice non-mono-space */
834 if (td->font_wid != CharWidth(i)) td->font_mono = FALSE;
836 /* Hack -- collect largest width */
837 if (td->font_wid < CharWidth(i)) td->font_wid = CharWidth(i);
840 /* Set default offsets */
841 td->tile_o_x = td->font_o_x;
842 td->tile_o_y = td->font_o_y;
844 /* Set default tile size */
846 if( td->tile_wid == 0 && td->tile_hgt == 0 ){
847 td->tile_wid = td->font_wid;
848 td->tile_hgt = td->font_hgt;
851 td->tile_wid = td->font_wid;
852 td->tile_hgt = td->font_hgt;
855 /* Re-activate the old window */
861 * Hack -- Apply and Verify the "size" info
863 static void term_data_check_size(term_data *td)
865 /* Minimal window size */
866 if (td->cols < 1) td->cols = 1;
867 if (td->rows < 1) td->rows = 1;
869 /* Minimal tile size */
870 if (td->tile_wid < 4) td->tile_wid = 4;
871 if (td->tile_hgt < 4) td->tile_hgt = 4;
873 /* Default tile offsets */
874 td->tile_o_x = (td->tile_wid - td->font_wid) / 2;
875 td->tile_o_y = (td->tile_hgt - td->font_hgt) / 2;
877 /* Minimal tile offsets */
878 if (td->tile_o_x < 0) td->tile_o_x = 0;
879 if (td->tile_o_y < 0) td->tile_o_y = 0;
881 /* Apply font offsets */
882 td->tile_o_x += td->font_o_x;
883 td->tile_o_y += td->font_o_y;
885 /* Calculate full window size */
886 td->size_wid = td->cols * td->tile_wid + td->size_ow1 + td->size_ow2;
887 td->size_hgt = td->rows * td->tile_hgt + td->size_oh1 + td->size_oh2;
890 if (td->r.top > qd.screenBits.bounds.bottom - td->size_hgt)
892 td->r.top = qd.screenBits.bounds.bottom - td->size_hgt;
896 if (td->r.top < qd.screenBits.bounds.top + 30)
898 td->r.top = qd.screenBits.bounds.top + 30;
901 /* Verify the left */
902 if (td->r.left > qd.screenBits.bounds.right - td->size_wid)
904 td->r.left = qd.screenBits.bounds.right - td->size_wid;
907 /* Verify the left */
908 if (td->r.left < qd.screenBits.bounds.left)
910 td->r.left = qd.screenBits.bounds.left;
913 /* Calculate bottom right corner */
914 td->r.right = td->r.left + td->size_wid;
915 td->r.bottom = td->r.top + td->size_hgt;
917 /* Assume no graphics */
918 td->t->always_pict = FALSE;
920 #ifdef ANGBAND_LITE_MAC
924 #else /* ANGBAND_LITE_MAC */
926 /* Handle graphics */
927 if (use_graphics && (td == &data[0]))
929 td->t->always_pict = TRUE;
932 #endif /* ANGBAND_LITE_MAC */
934 /* Fake mono-space */
935 if (!td->font_mono ||
936 (td->font_wid != td->tile_wid) ||
937 (td->font_hgt != td->tile_hgt))
939 /* Handle fake monospace */
940 td->t->always_pict = TRUE;
944 static OSErr XDDSWUpDateGWorldFromPict( term_data *td );
946 * Hack -- resize a term_data
948 * This should normally be followed by "term_data_resize()"
950 static void term_data_resize(term_data *td)
952 /* Actually resize the window */
953 SizeWindow(td->w, td->size_wid, td->size_hgt, 0);
956 XDDSWUpDateGWorldFromPict( td );
963 * Hack -- redraw a term_data
965 * Note that "Term_redraw()" calls "TERM_XTRA_CLEAR"
967 static void term_data_redraw(term_data *td)
971 /* Activate the term */
972 Term_activate(td->t);
974 /* Redraw the contents */
977 /* Flush the output */
980 /* Restore the old term */
983 /* No need to redraw */
984 ValidRect(&td->w->portRect);
990 #ifdef ANGBAND_LITE_MAC
994 #else /* ANGBAND_LITE_MAC */
1001 #define kPictID 1002 /* Graf 'pict' resource */
1003 #define kGrafWidth 16 /* Graf Size (X) */
1004 #define kGrafHeight 16 /* Graf Size (Y) */
1006 #define kPictCols 32 /* Number of Cols in Pict */
1007 #define kPictRows 60 /* Number of Rows in Pict */
1013 typedef struct FrameRec FrameRec;
1018 * - GWorld for the frame image
1019 * - Handle to pix map (saved for unlocking/locking)
1020 * - Pointer to color pix map (valid only while locked)
1024 GWorldPtr framePort;
1025 PixMapHandle framePixHndl;
1032 * The global picture data
1034 static FrameRec *frameP = NULL;
1040 static void BenSWLockFrame(FrameRec *srcFrameP)
1042 PixMapHandle pixMapH;
1044 pixMapH = GetGWorldPixMap(srcFrameP->framePort);
1045 (void)LockPixels(pixMapH);
1046 HLockHi((Handle)pixMapH);
1047 srcFrameP->framePixHndl = pixMapH;
1048 srcFrameP->framePix = (PixMapPtr)StripAddress(*(Handle)pixMapH);
1056 static void XDDSWLockFrame( term_data *td )
1058 PixMapHandle pixMapH;
1060 pixMapH = GetGWorldPixMap(td->bufferPort);
1061 (void)LockPixels(pixMapH);
1062 HLockHi((Handle)pixMapH);
1063 td->bufferPixHndl = pixMapH;
1064 td->bufferPix = (PixMapPtr)*(Handle)pixMapH;
1072 static void BenSWUnlockFrame(FrameRec *srcFrameP)
1074 if (srcFrameP->framePort != NULL)
1076 HUnlock((Handle)srcFrameP->framePixHndl);
1077 UnlockPixels(srcFrameP->framePixHndl);
1080 srcFrameP->framePix = NULL;
1088 static void XDDSWUnlockFrame( term_data *td )
1090 if (td->bufferPort != NULL)
1092 HUnlock((Handle)td->bufferPixHndl);
1093 UnlockPixels(td->bufferPixHndl);
1096 td->bufferPix = NULL;
1100 static OSErr BenSWCreateGWorldFromPict(
1101 GWorldPtr *pictGWorld,
1105 GWorldPtr saveGWorld;
1106 GDHandle saveGDevice;
1107 GWorldPtr tempGWorld;
1116 depth = data[0].pixelDepth;
1119 theGDH = data[0].theGDH;
1121 /* Obtain size rectangle */
1122 pictRect = (**pictH).picFrame;
1123 OffsetRect(&pictRect, -pictRect.left, -pictRect.top);
1125 /* Create a GWorld */
1126 err = NewGWorld(&tempGWorld, depth, &pictRect, nil,
1127 theGDH, noNewDevice);
1136 *pictGWorld = tempGWorld;
1139 GetGWorld(&saveGWorld, &saveGDevice);
1142 SetGWorld(tempGWorld, nil);
1144 /* Dump the pict into the GWorld */
1145 (void)LockPixels(GetGWorldPixMap(tempGWorld));
1146 EraseRect(&pictRect);
1147 DrawPicture(pictH, &pictRect);
1148 UnlockPixels(GetGWorldPixMap(tempGWorld));
1150 /* Restore GWorld */
1151 SetGWorld(saveGWorld, saveGDevice);
1159 static OSErr XDDSWCreateGWorldFromPict(
1160 GWorldPtr *pictGWorld,
1164 /* GWorldPtr saveGWorld;
1165 GDHandle saveGDevice;*/
1166 GWorldPtr tempGWorld;
1169 /* GDHandle theGDH; */
1177 /* depth = td->pixelDepth; */
1180 /* theGDH = td->theGDH; */
1182 /* Obtain size rectangle */
1184 pictRect.right = td->size_wid;
1186 pictRect.bottom = td->tile_hgt;
1188 /* Create a GWorld */
1189 err = NewGWorld(&tempGWorld, 0, &pictRect, 0, 0, 0);
1198 *pictGWorld = tempGWorld;
1201 /* GetGWorld(&saveGWorld, &saveGDevice); */
1204 /* SetGWorld(tempGWorld, nil); */
1206 /* Dump the pict into the GWorld */
1207 /* (void)LockPixels(GetGWorldPixMap(tempGWorld)); */
1208 /* EraseRect(&pictRect); */
1209 /* DrawPicture(pictH, &pictRect); */
1210 /* UnlockPixels(GetGWorldPixMap(tempGWorld)); */
1212 /* Restore GWorld */
1213 /* SetGWorld(saveGWorld, saveGDevice); */
1219 static OSErr XDDSWUpDateGWorldFromPict( term_data *td )
1221 /* GWorldPtr saveGWorld; */
1222 /* GDHandle saveGDevice; */
1225 /* GDHandle theGDH; */
1227 GWorldFlags errflag;
1231 if( td->bufferPort == NULL )
1234 /* depth = td->pixelDepth; */
1237 /* theGDH = td->theGDH; */
1239 /* Obtain size rectangle */
1242 pictRect.right = td->size_wid;
1243 pictRect.bottom = td->tile_hgt;
1245 XDDSWUnlockFrame(td);
1247 errflag = UpdateGWorld( &td->bufferPort, 0, &pictRect, 0, 0, 0);
1249 if( errflag & gwFlagErr ){
1255 /* GetGWorld(&saveGWorld, &saveGDevice); */
1258 /* SetGWorld(td->bufferPort, nil); */
1260 /* Dump the pict into the GWorld */
1261 /* (void)LockPixels(GetGWorldPixMap(td->bufferPort)); */
1262 /* EraseRect(&td->bufferPort->portRect); */
1264 /* UnlockPixels(GetGWorldPixMap(td->bufferPort)); */
1266 /* Restore GWorld */
1267 /* SetGWorld(saveGWorld, saveGDevice); */
1273 * Init the global "frameP"
1276 static errr globe_init(void)
1280 GWorldPtr tempPictGWorldP;
1284 /* Use window XXX XXX XXX */
1288 /* Get the pict resource */
1289 newPictH = GetPicture(kPictID);
1291 /* Analyze result */
1292 err = (newPictH ? 0 : -1);
1299 err = BenSWCreateGWorldFromPict(&tempPictGWorldP, newPictH);
1301 /* Release resource */
1302 ReleaseResource((Handle)newPictH);
1307 /* Create the frame */
1308 frameP = (FrameRec*)NewPtrClear((Size)sizeof(FrameRec));
1310 /* Analyze result */
1311 err = (frameP ? 0 : -1);
1317 frameP->framePort = tempPictGWorldP;
1320 BenSWLockFrame(frameP);
1331 * Nuke the global "frameP"
1333 static errr globe_nuke(void)
1339 BenSWUnlockFrame(frameP);
1341 /* Dispose of the GWorld */
1342 DisposeGWorld(frameP->framePort);
1344 /* Dispose of the memory */
1345 DisposePtr((Ptr)frameP);
1352 FlushEvents(everyEvent, 0);
1359 #endif /* ANGBAND_LITE_MAC */
1363 /*** Support for the "z-term.c" package ***/
1367 * Initialize a new Term
1369 * Note also the "window type" called "noGrowDocProc", which might be more
1370 * appropriate for the main "screen" window.
1372 * Note the use of "srcCopy" mode for optimized screen writes.
1374 static void Term_init_mac(term *t)
1376 term_data *td = (term_data*)(t->data);
1378 static RGBColor black = {0x0000,0x0000,0x0000};
1379 static RGBColor white = {0xFFFF,0xFFFF,0xFFFF};
1381 #ifdef ANGBAND_LITE_MAC
1383 /* Make the window */
1384 td->w = NewWindow(0, &td->r, td->title, 0, noGrowDocProc, (WindowPtr)-1, 1, 0L);
1386 #else /* ANGBAND_LITE_MAC */
1388 /* Make the window */
1389 td->w = NewCWindow(0, &td->r, td->title, 0, documentProc, (WindowPtr)-1, 1, 0L);
1391 #endif /* ANGBAND_LITE_MAC */
1393 /* Activate the window */
1396 /* Erase behind words */
1399 /* Apply and Verify */
1400 term_data_check_font(td);
1401 term_data_check_size(td);
1403 /* Resize the window */
1404 term_data_resize(td);
1406 #ifdef ANGBAND_LITE_MAC
1408 /* Prepare the colors (base colors) */
1409 BackColor(blackColor);
1410 ForeColor(whiteColor);
1412 #else /* ANGBAND_LITE_MAC */
1414 /* Prepare the colors (real colors) */
1415 RGBBackColor(&black);
1416 RGBForeColor(&white);
1423 GDHandle currentGDH;
1424 GWorldPtr windowGWorld;
1425 PixMapHandle basePixMap;
1427 /* Obtain the rect */
1428 tempRect = td->w->portRect;
1430 /* Obtain the global rect */
1431 globalRect = tempRect;
1432 LocalToGlobal((Point*)&globalRect.top);
1433 LocalToGlobal((Point*)&globalRect.bottom);
1435 /* Obtain the proper GDH */
1436 mainGDH = GetMaxDevice(&globalRect);
1438 /* Extract GWorld and GDH */
1439 GetGWorld(&windowGWorld, ¤tGDH);
1441 /* Obtain base pixmap */
1442 basePixMap = (**mainGDH).gdPMap;
1444 /* Save pixel depth */
1445 td->pixelDepth = (**basePixMap).pixelSize;
1447 /* Save Window GWorld */
1448 td->theGWorld = windowGWorld;
1450 /* Save Window GDH */
1451 td->theGDH = currentGDH;
1454 td->mainSWGDH = mainGDH;
1457 #endif /* ANGBAND_LITE_MAC */
1459 /* Clip to the window */
1460 ClipRect(&td->w->portRect);
1462 /* Erase the window */
1463 EraseRect(&td->w->portRect);
1465 /* Invalidate the window */
1466 InvalRect(&td->w->portRect);
1468 /* Display the window if needed */
1469 if (td->mapped) ShowWindow(td->w);
1471 /* Hack -- set "mapped" flag */
1472 t->mapped_flag = td->mapped;
1477 XDDSWCreateGWorldFromPict( &td->bufferPort, td );
1479 XDDSWLockFrame( td );
1481 /* if (err == noErr)
1493 static void Term_nuke_mac(term *t)
1506 static errr Term_user_mac(int n)
1520 static errr Term_xtra_mac_react(void)
1522 term_data *td = (term_data*)(Term->data);
1528 #ifdef ANGBAND_LITE_MAC
1532 #else /* ANGBAND_LITE_MAC */
1535 if (use_sound != arg_sound)
1538 use_sound = arg_sound;
1541 /* Handle graphics */
1542 if ((td == &data[0]) && (use_graphics != arg_graphics))
1544 /* Initialize graphics */
1546 if (!use_graphics && !frameP && (globe_init() != 0))
1549 plog("¥°¥é¥Õ¥£¥Ã¥¯¤Î½é´ü²½¤Ï½ÐÍè¤Þ¤»¤ó¤Ç¤·¤¿.");
1551 plog("Cannot initialize graphics!");
1553 arg_graphics = FALSE;
1557 use_graphics = arg_graphics;
1559 /* Apply and Verify */
1560 term_data_check_size(td);
1562 /* Resize the window */
1563 term_data_resize(td);
1569 #endif /* ANGBAND_LITE_MAC */
1577 * Do a "special thing"
1579 static errr Term_xtra_mac(int n, int v)
1581 term_data *td = (term_data*)(Term->data);
1589 case TERM_XTRA_NOISE:
1598 #ifdef ANGBAND_LITE_MAC
1602 #else /* ANGBAND_LITE_MAC */
1605 case TERM_XTRA_SOUND:
1615 /* Open the resource file */
1616 oldResFile = CurResFile();
1617 newResFile = OpenResFile(sound);
1619 /* Close the resource file */
1620 CloseResFile(newResFile);
1621 UseResFile(oldResFile);
1624 /* Get the proper sound name */
1625 sprintf((char*)sound + 1, "%.16s.wav", angband_sound_name[v]);
1626 sound[0] = strlen((char*)sound + 1);
1628 /* Obtain resource XXX XXX XXX */
1630 handle = Get1NamedResource('snd ', sound);
1631 if( handle == NULL || ext_sound )
1632 handle = GetNamedResource('snd ', sound);
1635 if (handle && soundmode[soundchoice[v]] == true)
1638 LoadResource(handle);
1641 /* Play sound (wait for completion) */
1642 SndPlay(nil, (SndListHandle)handle, true);
1644 /* Unlock and release */
1646 ReleaseResource(handle);
1649 handle = GetNamedResource('snd ', sound);
1655 LoadResource(handle);
1658 /* Play sound (wait for completion) */
1659 SndPlay(nil, (SndListHandle)handle, true);
1661 /* Unlock and release */
1663 ReleaseResource(handle);
1670 #endif /* ANGBAND_LITE_MAC */
1672 /* Process random events */
1673 case TERM_XTRA_BORED:
1675 /* Process an event */
1676 (void)CheckEvents(0);
1682 /* Process pending events */
1683 case TERM_XTRA_EVENT:
1685 /* Process an event */
1686 (void)CheckEvents(v);
1692 /* Flush all pending events (if any) */
1693 case TERM_XTRA_FLUSH:
1695 /* Hack -- flush all events */
1696 while (CheckEvents(TRUE)) /* loop */;
1702 /* Hack -- Change the "soft level" */
1703 case TERM_XTRA_LEVEL:
1705 /* Activate if requested */
1706 if (v) activate(td->w);
1712 /* Clear the screen */
1713 case TERM_XTRA_CLEAR:
1715 /* No clipping XXX XXX XXX */
1716 ClipRect(&td->w->portRect);
1718 /* Erase the window */
1719 EraseRect(&td->w->portRect);
1722 term_data_color(td, TERM_WHITE);
1724 /* Frame the window in white */
1726 LineTo(0, td->size_hgt-1);
1727 LineTo(td->size_wid-1, td->size_hgt-1);
1728 LineTo(td->size_wid-1, 0);
1730 /* Clip to the new size */
1731 r.left = td->w->portRect.left + td->size_ow1;
1732 r.top = td->w->portRect.top + td->size_oh1;
1733 r.right = td->w->portRect.right - td->size_ow2;
1734 r.bottom = td->w->portRect.bottom - td->size_oh2;
1741 /* React to changes */
1742 case TERM_XTRA_REACT:
1744 /* React to changes */
1745 return (Term_xtra_mac_react());
1748 /* Delay (milliseconds) */
1749 case TERM_XTRA_DELAY:
1754 long m = TickCount() + (v * 60L) / 1000;
1757 while (TickCount() < m) /* loop */;
1772 * Low level graphics (Assumes valid input).
1773 * Draw a "cursor" at (x,y), using a "yellow box".
1774 * We are allowed to use "Term_grab()" to determine
1775 * the current screen contents (for inverting, etc).
1777 static errr Term_curs_mac(int x, int y)
1781 term_data *td = (term_data*)(Term->data);
1784 term_data_color(td, TERM_YELLOW);
1786 /* Frame the grid */
1787 r.left = x * td->tile_wid + td->size_ow1;
1788 r.right = r.left + td->tile_wid;
1789 r.top = y * td->tile_hgt + td->size_oh1;
1790 r.bottom = r.top + td->tile_hgt;
1799 * Low level graphics (Assumes valid input)
1801 * Erase "n" characters starting at (x,y)
1803 static errr Term_wipe_mac(int x, int y, int n)
1807 term_data *td = (term_data*)(Term->data);
1809 /* Erase the block of characters */
1810 r.left = x * td->tile_wid + td->size_ow1;
1811 r.right = r.left + n * td->tile_wid;
1812 r.top = y * td->tile_hgt + td->size_oh1;
1813 r.bottom = r.top + td->tile_hgt;
1822 * Low level graphics. Assumes valid input.
1824 * Draw several ("n") chars, with an attr, at a given location.
1826 static errr Term_text_mac(int x, int y, int n, byte a, const char *cp)
1830 term_data *td = (term_data*)(Term->data);
1833 term_data_color(td, (a & 0x0F));
1835 /* Starting pixel */
1836 xp = x * td->tile_wid + td->tile_o_x + td->size_ow1;
1837 yp = y * td->tile_hgt + td->tile_o_y + td->size_oh1;
1839 /* Move to the correct location */
1842 /* Draw the character */
1843 if (n == 1) DrawChar(*cp);
1845 /* Draw the string */
1846 else DrawText(cp, 0, n);
1854 * Low level graphics (Assumes valid input)
1856 * Erase "n" characters starting at (x,y)
1858 static errr Term_pict_mac(int x, int y, int n, const byte *ap, const char *cp)
1862 bool use_buffer = false;
1863 term_data *td = (term_data*)(Term->data);
1864 GDHandle saveGDevice;
1865 GWorldPtr saveGWorld;
1868 PixMapHandle PortPix;
1873 GetGWorld(&saveGWorld, &saveGDevice);
1877 /* Destination rectangle */
1878 r2.left = x * td->tile_wid + td->size_ow1;
1879 r2.right = r2.left + td->tile_wid;
1881 r2.bottom = r2.top + td->tile_hgt;
1884 SetGWorld(td->bufferPort, nil);
1886 PortPix = GetGWorldPixMap(td->bufferPort );
1887 LockPixels( PortPix );
1889 /* Instantiate font */
1890 TextFont(td->font_id);
1891 TextSize(td->font_size);
1892 TextFace(td->font_face);
1894 /* Restore colors */
1895 BackColor(blackColor);
1896 ForeColor(whiteColor);
1900 EraseRect(&td->bufferPort->portRect);
1907 /* Destination rectangle */
1908 r2.left = x * td->tile_wid + td->size_ow1;
1909 r2.right = r2.left + td->tile_wid;
1910 r2.top = y * td->tile_hgt + td->size_oh1;
1911 r2.bottom = r2.top + td->tile_hgt;
1913 /* no buffering, so we use the normal current port */
1918 /* Scan the input */
1919 for (i = 0; i < n; i++)
1926 #ifdef ANGBAND_LITE_MAC
1930 #else /* ANGBAND_LITE_MAC */
1932 /* Graphics -- if Available and Needed */
1933 if (use_graphics && ((td == &data[0]) || (td == &data[6])) &&
1934 ((byte)a & 0x80) && ((byte)c & 0x80))
1940 row = ((byte)a & 0x7F);// % kPictRows;
1941 col = ((byte)c & 0x7F);// % kPictCols;
1943 /* Source rectangle */
1944 r1.left = col * kGrafWidth;
1945 r1.top = row * kGrafHeight;
1946 r1.right = r1.left + kGrafWidth;
1947 r1.bottom = r1.top + kGrafHeight;
1949 /* Hardwire CopyBits */
1950 BackColor(whiteColor);
1951 ForeColor(blackColor);
1953 /* Draw the picture */
1955 BitMapPtr srcBitMap = (BitMapPtr)(frameP->framePix);
1956 BitMapPtr destBitMap;
1960 destBitMap = (BitMapPtr)(td->bufferPix);
1964 destBitMap = (BitMapPtr)&(td->w->portBits);
1967 /* draw transparent tile */
1968 /* BackColor is ignored and the destination is left untouched */
1969 BackColor(blackColor);
1970 CopyBits( srcBitMap, destBitMap, &r1, &r2, transparent, NULL );
1972 /* Restore colors */
1973 BackColor(blackColor);
1974 ForeColor(whiteColor);
1983 #endif /* ANGBAND_LITE_MAC */
1994 term_data_color(td, (a & 0x0F));
1996 /* Starting pixel */
1997 xp = r2.left + td->tile_o_x;
1998 yp = r2.top + td->tile_o_y;
2000 /* Move to the correct location */
2003 /* Draw the character */
2007 term_data_color(td, (a & 0x0F));
2009 /* Starting pixel */
2010 xp = r2.left + td->tile_o_x;
2013 /* Move to the correct location */
2017 /* Draw the character */
2022 r2.left += td->tile_wid;
2023 r2.right += td->tile_wid;
2025 /* Draw the character */
2032 r2.left += td->tile_wid;
2033 r2.right += td->tile_wid;
2038 /* Now we blast the buffer pixmap onto the screen in the right place */
2039 BitMapPtr srcBitMap = (BitMapPtr)(td->bufferPix);
2041 BitMapPtr destBitMap = (BitMapPtr)&(td->w->portBits);
2047 srcRect.left = x * td->tile_wid + td->size_ow1;
2049 srcRect.right = srcRect.left + (td->tile_wid * n);
2050 srcRect.bottom = td->tile_hgt;
2052 destRect.left = x * td->tile_wid + td->size_ow1;
2053 destRect.right = destRect.left + (td->tile_wid * n);
2054 destRect.top = y * td->tile_hgt + td->size_oh1;
2055 destRect.bottom = destRect.top + td->tile_hgt;
2058 UnlockPixels( PortPix );
2060 /* Restore GWorld */
2061 SetGWorld(saveGWorld, saveGDevice);
2063 /* Hardwire CopyBits */
2064 BackColor(whiteColor);
2065 ForeColor(blackColor);
2067 //CopyBits( srcBitMap, destBitMap, &srcRect, &destRect, srcCopy, NULL );
2068 CopyBits( (BitMapPtr *)(td->bufferPix)
2069 , &(td->w->portBits), &srcRect, &destRect, srcCopy, NULL );
2071 /* Restore colors */
2072 BackColor(blackColor);
2073 ForeColor(whiteColor);
2086 * Create and initialize window number "i"
2088 static void term_data_link(int i)
2092 term_data *td = &data[i];
2097 /* Require mapped */
2098 if (!td->mapped) return;
2103 /* Initialize the term */
2104 term_init(td->t, td->cols, td->rows, td->keys);
2106 /* Use a "software" cursor */
2107 td->t->soft_cursor = TRUE;
2109 /* Erase with "white space" */
2110 td->t->attr_blank = TERM_WHITE;
2111 td->t->char_blank = ' ';
2113 /* Prepare the init/nuke hooks */
2114 td->t->init_hook = Term_init_mac;
2115 td->t->nuke_hook = Term_nuke_mac;
2117 /* Prepare the function hooks */
2118 td->t->user_hook = Term_user_mac;
2119 td->t->xtra_hook = Term_xtra_mac;
2120 td->t->wipe_hook = Term_wipe_mac;
2121 td->t->curs_hook = Term_curs_mac;
2122 td->t->text_hook = Term_text_mac;
2123 td->t->pict_hook = Term_pict_mac;
2125 /* Link the local structure */
2126 td->t->data = (vptr)(td);
2129 Term_activate(td->t);
2131 /* Global pointer */
2132 angband_term[i] = td->t;
2142 * Set the "current working directory" (also known as the "default"
2143 * volume/directory) to the location of the current application.
2145 * Code by: Maarten Hazewinkel (mmhazewi@cs.ruu.nl)
2147 * This function does not appear to work correctly with System 6.
2149 static void SetupAppDir(void)
2153 char errString[100];
2155 /* Get the location of the Angband executable */
2156 fcbBlock.ioCompletion = NULL;
2157 fcbBlock.ioNamePtr = NULL;
2158 fcbBlock.ioVRefNum = 0;
2159 fcbBlock.ioRefNum = CurResFile();
2160 fcbBlock.ioFCBIndx = 0;
2161 err = PBGetFCBInfo(&fcbBlock, FALSE);
2165 sprintf(errString, "PBGetFCBInfo ¥¨¥é¡¼ #%d.\r ½ªÎ»¤·¤Þ¤¹.", err);
2167 sprintf(errString, "Fatal PBGetFCBInfo Error #%d.\r Exiting.", err);
2169 mac_warning(errString);
2173 /* Extract the Vol and Dir */
2174 app_vol = fcbBlock.ioFCBVRefNum;
2175 app_dir = fcbBlock.ioFCBParID;
2177 /* Set the current working directory to that location */
2178 err = HSetVol(NULL, app_vol, app_dir);
2182 sprintf(errString, "HSetVol ¥¨¥é¡¼ #%d.\r ½ªÎ»¤·¤Þ¤¹.", err);
2184 sprintf(errString, "Fatal HSetVol Error #%d.\r Exiting.", err);
2186 mac_warning(errString);
2195 * Global "preference" file pointer
2200 * Read a "short" from the file
2202 static int getshort(void)
2206 if (0 == my_fgets(fff, buf, 256)) x = atoi(buf);
2211 * Dump a "short" to the file
2213 static void putshort(int x)
2215 fprintf(fff, "%d\n", x);
2221 * Write the "preference" data to the current "file"
2223 static void save_prefs(void)
2230 /*** The current version ***/
2232 putshort(VERSION_MAJOR);
2233 putshort(VERSION_MINOR);
2234 putshort(VERSION_PATCH);
2235 putshort(VERSION_EXTRA);
2237 putshort(arg_sound);
2238 putshort(arg_graphics);
2241 for( i = 0 ; i < 7 ; i++ )
2242 putshort(soundmode[i]);
2245 for (i = 0; i < MAX_TERM_DATA; i++)
2250 putshort(td->mapped);
2252 putshort(td->font_id);
2253 putshort(td->font_size);
2254 putshort(td->font_face);
2257 putshort(td->tile_wid);
2258 putshort(td->tile_hgt);
2264 putshort(td->r.left);
2265 putshort(td->r.top);
2271 * Load the preferences from the current "file"
2273 * XXX XXX XXX Being able to undefine various windows is
2274 * slightly bizarre, and may cause problems.
2276 static void load_prefs(void)
2280 int old_major, old_minor, old_patch, old_extra;
2285 /*** Version information ***/
2287 /* Preferences version */
2288 old_major = getshort();
2289 old_minor = getshort();
2290 old_patch = getshort();
2291 old_extra = getshort();
2293 /* Hack -- Verify or ignore */
2294 if ((old_major != VERSION_MAJOR) ||
2295 (old_minor != VERSION_MINOR) ||
2296 (old_patch != VERSION_PATCH) ||
2297 (old_extra != VERSION_EXTRA))
2301 mac_warning("¸Å¤¤½é´üÀßÄê¥Õ¥¡¥¤¥ë¤ò̵»ë¤·¤Þ¤¹.");
2303 mac_warning("Ignoring old preferences.");
2309 arg_sound = getshort();
2310 arg_graphics = getshort();
2313 for( i = 0 ; i < 7 ; i++ )
2314 soundmode[i] = getshort();
2317 m = GetMenuHandle(134); //m = GetMHandle(134);
2319 /* Item "arg_sound" */
2320 CheckItem(m, 1, arg_sound);
2322 /* Item "arg_graphics" */
2323 CheckItem(m, 2, arg_graphics);
2326 for (i = 0; i < MAX_TERM_DATA; i++)
2331 td->mapped = getshort();
2333 td->font_id = getshort();
2334 td->font_size = getshort();
2335 td->font_face = getshort();
2338 td->tile_wid = getshort();
2339 td->tile_hgt = getshort();
2342 td->cols = getshort();
2343 td->rows = getshort();
2345 td->r.left = getshort();
2346 td->r.top = getshort();
2349 if (feof(fff)) break;
2357 * Hack -- default data for a window
2359 static void term_data_hack(term_data *td)
2364 GetFNum( "\pÅùÉýÌÀÄ«", &fid); /* ¥Õ¥©¥ó¥È̾¤«¤éIDÈÖ¹æ¤òÄ´¤Ù¤ë */
2365 SetFScaleDisable( true );
2367 /* Default to Monaco font */
2368 GetFNum("\pmonaco", &fid);
2371 WIPE(td, term_data);
2376 /* Default borders */
2387 /* Default font size */
2390 /* Default font face */
2397 /* Default position */
2407 * Read the preference file, Create the windows.
2409 * We attempt to use "FindFolder()" to track down the preference file,
2410 * but if this fails, for any reason, we will try the "SysEnvirons()"
2411 * method, which may work better with System 6.
2413 static void init_windows(void)
2426 /*** Default values ***/
2428 /* Initialize (backwards) */
2429 for (i = MAX_TERM_DATA - 1; i >= 0; i--)
2442 s = angband_term_name[i];
2447 /* Maximal length */
2450 /* Copy the title */
2451 strncpy((char*)(td->title) + 1, s, n);
2453 /* Save the length */
2456 /* Tile the windows */
2457 td->r.left += (b * 30);
2458 td->r.top += (b * 30);
2465 /*** Load preferences ***/
2467 /* Assume failure */
2470 /* Assume failure */
2483 /* Find the folder */
2484 err = FindFolder(kOnSystemDisk, kPreferencesFolderType, kCreateFolder,
2490 /* Extract a path name */
2491 PathNameFromDirID(dirID, vref, (StringPtr)foo);
2493 /* Convert the string */
2494 ptocstr((StringPtr)foo);
2496 /* Append the preference file name */
2498 strcat(foo, "Hengband Preferences");
2500 strcat(foo, "Angband Preferences");
2502 /* Open the preference file */
2503 fff = fopen(foo, "r");
2510 #endif /* USE_SFL_CODE */
2516 HGetVol(0, &savev, &saved);
2518 /* Go to the "system" folder */
2519 SysEnvirons(curSysEnvVers, &env);
2520 SetVol(0, env.sysVRefNum);
2524 fff = fopen(":Preferences:Hengband Preferences", "r");
2525 if (!fff) fff = fopen(":Hengband Preferences", "r");
2527 fff = fopen(":Preferences:Angband Preferences", "r");
2528 if (!fff) fff = fopen(":Angband Preferences", "r");
2531 HSetVol(0, savev, saved);
2534 /* Load preferences */
2537 /* Load a real preference file */
2540 /* Close the file */
2545 /*** Instantiate ***/
2556 /* Link (backwards, for stacking order) */
2557 for (i = MAX_TERM_DATA - 1; i >= 0; i--)
2566 Term_activate(td->t);
2570 static void init_sound( void )
2574 SignedByte permission = fsRdPerm;
2580 /* Descend into "lib" folder */
2581 pb.ioCompletion = NULL;
2582 pb.ioNamePtr = "\plib";
2583 pb.ioVRefNum = app_vol;
2584 pb.ioDrDirID = app_dir;
2587 /* Check for errors */
2588 err = PBGetCatInfo((CInfoPBPtr)&pb, FALSE);
2591 if ((err == noErr) && (pb.ioFlAttrib & 0x10))
2593 /* Descend into "lib/save" folder */
2594 pb.ioCompletion = NULL;
2595 pb.ioNamePtr = "\pxtra";
2596 pb.ioVRefNum = app_vol;
2597 pb.ioDrDirID = pb.ioDrDirID;
2600 /* Check for errors */
2601 err = PBGetCatInfo((CInfoPBPtr)&pb, FALSE);
2604 if ((err == noErr) && (pb.ioFlAttrib & 0x10))
2606 /* Descend into "lib/save" folder */
2607 pb.ioCompletion = NULL;
2608 pb.ioNamePtr = "\psound";
2609 pb.ioVRefNum = app_vol;
2610 pb.ioDrDirID = pb.ioDrDirID;
2613 /* Check for errors */
2614 err = PBGetCatInfo((CInfoPBPtr)&pb, FALSE);
2617 if ((err == noErr) && (pb.ioFlAttrib & 0x10))
2619 ret = HOpenResFile( app_vol , pb.ioDrDirID , "\psound.rsrc" , permission );
2623 for( i = 0 ; i < 7 ; i++ )
2624 soundmode[i] = false;
2626 for( i = 1 ; i < SOUND_MAX ; i++ ){
2627 /* Get the proper sound name */
2628 sprintf((char*)sound + 1, "%.16s.wav", angband_sound_name[i]);
2629 sound[0] = strlen((char*)sound + 1);
2631 /* Obtain resource XXX XXX XXX */
2632 handle = Get1NamedResource('snd ', sound);
2633 if( handle == NULL || ext_sound )
2634 handle = GetNamedResource('snd ', sound);
2637 soundmode[soundchoice[i]] = true;
2650 static void init_chuukei( void )
2656 path_build(path, 1024, ANGBAND_DIR_XTRA, "chuukei.txt");
2658 fp = fopen(path, "r");
2663 if (fgets(tmp, 1024, fp)){
2665 int n = strlen(tmp);
2671 chuukei_server = TRUE;
2672 if(connect_chuukei_server(&tmp[2])<0){
2673 msg_print("connect fail");
2676 msg_print("connect");
2683 chuukei_client = TRUE;
2684 connect_chuukei_server(&tmp[2]);
2700 short InevrtCheck( DialogPtr targetDlg, short check )
2707 GetDialogItem( targetDlg, check, &itemType, &checkH, &box );
2708 result = (GetControlValue( (ControlHandle)checkH ) + 1 ) % 2;
2709 SetControlValue( (ControlHandle)checkH , result );
2717 short SetCheck( DialogPtr targetDlg, short check, long result )
2724 GetDialogItem( targetDlg, check, &itemType, &checkH, &box );
2725 SetControlValue( (ControlHandle)checkH , result );
2733 short GetCheck( DialogPtr targetDlg, short check )
2740 GetDialogItem( targetDlg, check, &itemType, &checkH, &box );
2741 result = GetControlValue( (ControlHandle)checkH );
2745 void SoundConfigDLog(void)
2752 dialog=GetNewDialog(131, 0, (WindowPtr)-1);
2753 SetDialogDefaultItem( dialog, ok );
2754 SetDialogCancelItem( dialog, cancel );
2755 for( i = 1 ; i < 7 ; i++ )
2756 SetCheck( dialog, i+2 , soundmode[i] );
2759 for( item_hit = 100 ; cancel < item_hit ; ){
2760 ModalDialog(0, &item_hit);
2764 for( i = 1 ; i < 7 ; i++ )
2765 soundmode[i] = GetCheck( dialog, i+2 );
2770 InevrtCheck( dialog, item_hit );
2773 DisposeDialog(dialog);
2782 static void save_pref_file(void)
2791 /* Assume failure */
2794 /* Assume failure */
2797 #if defined(MACINTOSH) && !defined(applec)
2813 /* Find the folder */
2814 err = FindFolder(kOnSystemDisk, kPreferencesFolderType, kCreateFolder,
2820 /* Extract a path name */
2821 PathNameFromDirID(dirID, vref, (StringPtr)foo);
2823 /* Convert the string */
2824 ptocstr((StringPtr)foo);
2826 /* Append the preference file name */
2828 strcat(foo, "Hengband Preferences");
2830 strcat(foo, "Angband Preferences");
2832 /* Open the preference file */
2833 fff = fopen(foo, "w");
2840 #endif /* USE_SFL_CODE */
2846 HGetVol(0, &savev, &saved);
2848 /* Go to "system" folder */
2849 SysEnvirons(curSysEnvVers, &env);
2850 SetVol(0, env.sysVRefNum);
2852 /* Open the preference file */
2854 fff = fopen(":Preferences:Hengband Preferences", "w");
2855 if (!fff) fff = fopen(":Hengband Preferences", "w");
2858 fff = fopen(":Preferences:Angband Preferences", "w");
2859 if (!fff) fff = fopen(":Angband Preferences", "w");
2862 HSetVol(0, savev, saved);
2865 /* Save preferences */
2868 /* Write the preferences */
2879 * A simple "Yes/No" filter to parse "key press" events in dialog windows
2881 static pascal Boolean ynfilter(DialogPtr dialog, EventRecord *event, short *ip)
2883 /* Parse key press events */
2884 if (event->what == keyDown)
2889 /* Extract the pressed key */
2890 c = (event->message & charCodeMask);
2892 /* Accept "no" and <return> and <enter> */
2893 if ((c=='n') || (c=='N') || (c==13) || (c==3)) i = 1;
2896 else if ((c=='y') || (c=='Y')) i = 2;
2898 /* Handle "yes" or "no" */
2902 ControlHandle control;
2905 /* Get the button */
2906 GetDialogItem(dialog, i, &type, (Handle*)&control, &r); //GetDItem(dialog, i, &type, (Handle*)&control, &r);
2908 /* Blink button for 1/10 second */
2909 HiliteControl(control, 1);
2910 Term_xtra_mac(TERM_XTRA_DELAY, 100);
2911 HiliteControl(control, 0);
2925 * Handle menu: "File" + "New"
2927 static void do_menu_file_new(void)
2932 /* Game is in progress */
2933 game_in_progress = 1;
2947 * Handle menu: "File" + "Open"
2949 static void do_menu_file_open(bool all)
2963 /* vrefnum = GetSFCurVol(); */
2964 vrefnum = -*((short*)0x214);
2966 /* drefnum = GetSFCurDir(); */
2967 drefnum = *((long*)0x398);
2969 /* Descend into "lib" folder */
2970 pb.ioCompletion = NULL;
2971 pb.ioNamePtr = "\plib";
2972 pb.ioVRefNum = vrefnum;
2973 pb.ioDrDirID = drefnum;
2976 /* Check for errors */
2977 err = PBGetCatInfo((CInfoPBPtr)&pb, FALSE);
2980 if ((err == noErr) && (pb.ioFlAttrib & 0x10))
2982 /* Descend into "lib/save" folder */
2983 pb.ioCompletion = NULL;
2984 pb.ioNamePtr = "\psave";
2985 pb.ioVRefNum = vrefnum;
2986 pb.ioDrDirID = pb.ioDrDirID;
2989 /* Check for errors */
2990 err = PBGetCatInfo((CInfoPBPtr)&pb, FALSE);
2993 if ((err == noErr) && (pb.ioFlAttrib & 0x10))
2995 /* SetSFCurDir(pb.ioDrDirID); */
2996 *((long*)0x398) = pb.ioDrDirID;
3000 /* Window location */
3001 topleft.h = (qd.screenBits.bounds.left+qd.screenBits.bounds.right)/2-344/2;
3002 topleft.v = (2*qd.screenBits.bounds.top+qd.screenBits.bounds.bottom)/3-188/2;
3004 /* Allow "all" files */
3008 SFGetFile(topleft, "\p", NULL, -1, types, NULL, &reply);
3011 /* Allow "save" files */
3018 SFGetFile(topleft, "\p", NULL, 1, types, NULL, &reply);
3022 if (!reply.good) return;
3024 /* Extract textual file name for save file */
3025 GetWDInfo(reply.vRefNum, &vrefnum, &drefnum, &junk);
3026 refnum_to_name(savefile, drefnum, vrefnum, (char*)reply.fName);
3031 /* Game is in progress */
3032 game_in_progress = 1;
3046 * Handle the "open_when_ready" flag
3048 static void handle_open_when_ready(void)
3050 /* Check the flag XXX XXX XXX make a function for this */
3051 if (open_when_ready && initialized && !game_in_progress)
3054 open_when_ready = FALSE;
3056 /* Game is in progress */
3057 game_in_progress = 1;
3076 * Initialize the menus
3078 * Verify menus 128, 129, 130
3079 * Create menus 131, 132, 133, 134
3081 * The standard menus are:
3083 * Apple (128) = { About, -, ... }
3084 * File (129) = { New,Open,Import,Close,Save,-,Exit,Quit }
3085 * Edit (130) = { Cut, Copy, Paste, Clear } (?)
3086 * Font (131) = { Bold, Extend, -, Monaco, ..., -, ... }
3087 * Size (132) = { ... }
3088 * Window (133) = { Angband, Mirror, Recall, Choice,
3089 * Term-4, Term-5, Term-6, Term-7 }
3090 * Special (134) = { arg_sound, arg_graphics, -,
3091 * arg_fiddle, arg_wizard }
3093 static void init_menubar(void)
3104 /* Get the "apple" menu */
3107 /* Insert the menu */
3110 /* Add the DA's to the "apple" menu */
3111 AppendResMenu (m, 'DRVR'); //AddResMenu(m, 'DRVR');
3114 /* Get the "File" menu */
3117 /* Insert the menu */
3121 /* Get the "Edit" menu */
3124 /* Insert the menu */
3128 /* Make the "Font" menu */
3130 m = NewMenu(131, "\p¥Õ¥©¥ó¥È");
3132 m = NewMenu(131, "\pFont");
3135 /* Insert the menu */
3139 AppendMenu(m, "\pBold");
3142 AppendMenu(m, "\pWide");
3144 /* Add a separator */
3145 AppendMenu(m, "\p-");
3148 r.left = r.right = r.top = r.bottom = 0;
3150 /* Make the fake window */
3151 tmpw = NewWindow(0, &r, "\p", false, documentProc, 0, 0, 0);
3153 /* Activate the "fake" window */
3162 /* Add the fonts to the menu */
3163 AppendResMenu(m, 'FONT'); //AddResMenu(m, 'FONT');
3169 for (i = n; i >= 4; i--)
3174 /* Acquire the font name */
3175 /* GetMenuItemText(m, i, tmpName); */
3176 GetMenuItemText(m, i, tmpName); //GetItem(m, i, tmpName);
3178 /* Acquire the font index */
3179 GetFNum(tmpName, &fontNum);
3181 /* Apply the font index */
3184 /* Remove non-mono-spaced fonts */
3185 if ((CharWidth('i') != CharWidth('W')) || (CharWidth('W') == 0))
3187 /* Delete the menu item XXX XXX XXX */
3188 /* DeleteMenuItem(m, i); */
3189 DeleteMenuItem (m, i); //DelMenuItem(m, i);
3193 /* Destroy the old window */
3194 DisposeWindow(tmpw);
3196 /* Add a separator */
3197 AppendMenu(m, "\p-");
3199 /* Add the fonts to the menu */
3200 AppendResMenu (m, 'FONT'); //AddResMenu(m, 'FONT');
3203 /* Make the "Size" menu */
3205 m = NewMenu(132, "\p¥µ¥¤¥º");
3207 m = NewMenu(132, "\pSize");
3210 /* Insert the menu */
3213 /* Add some sizes (stagger choices) */
3214 for (i = 8; i <= 32; i += ((i / 16) + 1))
3219 sprintf((char*)buf + 1, "%d", i);
3220 buf[0] = strlen((char*)buf + 1);
3227 /* Make the "Windows" menu */
3229 m = NewMenu(133, "\p¥¦¥¤¥ó¥É¥¦");
3231 m = NewMenu(133, "\pWindows");
3234 /* Insert the menu */
3237 /* Default choices */
3238 for (i = 0; i < MAX_TERM_DATA; i++)
3242 /* Describe the item */
3243 sprintf((char*)buf + 1, "%.15s", angband_term_name[i]);
3244 buf[0] = strlen((char*)buf + 1);
3249 /* Command-Key shortcuts */
3250 if (i < 8) SetItemCmd(m, i + 1, '0' + i);
3254 /* Make the "Special" menu */
3256 m = NewMenu(134, "\pÆÃÊÌ");
3258 m = NewMenu(134, "\pSpecial");
3261 /* Insert the menu */
3264 /* Append the choices */
3266 AppendMenu(m, "\p¥µ¥¦¥ó¥É»ÈÍÑ");
3267 AppendMenu(m, "\p¥°¥é¥Õ¥£¥Ã¥¯»ÈÍÑ");
3268 AppendMenu(m, "\p-");
3269 AppendMenu(m, "\parg_fiddle");
3270 AppendMenu(m, "\parg_wizard");
3271 AppendMenu(m, "\p-");
3272 AppendMenu(m, "\p¥µ¥¦¥ó¥ÉÀßÄê...");
3274 AppendMenu(m, "\parg_sound");
3275 AppendMenu(m, "\parg_graphics");
3276 AppendMenu(m, "\p-");
3277 AppendMenu(m, "\parg_fiddle");
3278 AppendMenu(m, "\parg_wizard");
3281 /* Make the "TileWidth" menu */
3283 m = NewMenu(135, "\p¥¿¥¤¥ëÉý");
3285 m = NewMenu(135, "\pTileWidth");
3288 /* Insert the menu */
3291 /* Add some sizes */
3292 for (i = 4; i <= 32; i++)
3297 sprintf((char*)buf + 1, "%d", i);
3298 buf[0] = strlen((char*)buf + 1);
3305 /* Make the "TileHeight" menu */
3307 m = NewMenu(136, "\p¥¿¥¤¥ë¹â");
3309 m = NewMenu(136, "\pTileHeight");
3312 /* Insert the menu */
3315 /* Add some sizes */
3316 for (i = 4; i <= 32; i++)
3321 sprintf((char*)buf + 1, "%d", i);
3322 buf[0] = strlen((char*)buf + 1);
3329 /* Update the menu bar */
3337 static void setup_menus(void)
3347 term_data *td = NULL;
3350 /* Relevant "term_data" */
3351 for (i = 0; i < MAX_TERM_DATA; i++)
3354 if (!data[i].t) continue;
3356 /* Notice the matching window */
3357 if (data[i].w == FrontWindow()) td = &data[i];
3362 m = GetMenuHandle(129); //m = GetMHandle(129);
3368 for (i = 1; i <= n; i++)
3372 CheckItem(m, i, FALSE);
3375 /* Enable "new"/"open..."/"import..." */
3376 if (initialized && !game_in_progress)
3383 /* Enable "close" */
3390 if (initialized && character_generated)
3399 /* EnableItem(m, 8); */
3404 m = GetMenuHandle(130); //m = GetMHandle(130);
3410 for (i = 1; i <= n; i++)
3414 CheckItem(m, i, FALSE);
3417 /* Enable "edit" options if "needed" */
3429 m = GetMenuHandle(131); //m = GetMHandle(131);
3435 for (i = 1; i <= n; i++)
3439 CheckItem(m, i, FALSE);
3442 /* Hack -- look cute XXX XXX */
3443 /* SetItemStyle(m, 1, bold); */
3445 /* Hack -- look cute XXX XXX */
3446 /* SetItemStyle(m, 2, extend); */
3454 /* Enable "extend" */
3457 /* Check the appropriate "bold-ness" */
3458 if (td->font_face & bold) CheckItem(m, 1, TRUE);
3460 /* Check the appropriate "wide-ness" */
3461 if (td->font_face & extend) CheckItem(m, 2, TRUE);
3464 for (i = 4; i <= n; i++)
3470 /* GetMenuItemText(m,i,s); */
3471 GetMenuItemText(m, i, s); //GetItem(m, i, s);
3474 /* Check active font */
3475 if (td->font_id == value) CheckItem(m, i, TRUE);
3481 m = GetMenuHandle(132); //m = GetMHandle(132);
3487 for (i = 1; i <= n; i++)
3491 CheckItem(m, i, FALSE);
3498 for (i = 1; i <= n; i++)
3501 /* GetMenuItemText(m,i,s); */
3502 GetMenuItemText(m, i, s); //GetItem(m, i, s);
3504 value = atoi((char*)(s+1));
3506 /* Enable the "real" sizes */
3507 if (RealFont(td->font_id, value)) EnableItem(m, i);
3509 /* Check the current size */
3510 if (td->font_size == value) CheckItem(m, i, TRUE);
3516 m = GetMenuHandle(133); //m = GetMHandle(133);
3521 /* Check active windows */
3522 for (i = 1; i <= n; i++)
3524 /* Check if needed */
3525 CheckItem(m, i, data[i-1].mapped);
3530 m = GetMenuHandle(134); //m = GetMHandle(134);
3536 for (i = 1; i <= n; i++)
3540 CheckItem(m, i, FALSE);
3543 /* Item "arg_sound" */
3545 CheckItem(m, 1, arg_sound);
3547 /* Item "arg_graphics" */
3549 CheckItem(m, 2, arg_graphics);
3551 /* Item "arg_fiddle" */
3553 CheckItem(m, 4, arg_fiddle);
3555 /* Item "arg_wizard" */
3557 CheckItem(m, 5, arg_wizard);
3560 /* Item "SoundSetting" */
3564 /* EnableItem(m, 9); */
3567 /* TileWidth menu */
3568 m = GetMenuHandle(135); //m = GetMHandle(135);
3574 for (i = 1; i <= n; i++)
3578 CheckItem(m, i, FALSE);
3585 for (i = 1; i <= n; i++)
3588 /* GetMenuItemText(m,i,s); */
3589 GetMenuItemText(m, i, s); //GetItem(m, i, s);
3591 value = atoi((char*)(s+1));
3596 /* Check the current size */
3597 if (td->tile_wid == value) CheckItem(m, i, TRUE);
3602 /* TileHeight menu */
3603 m = GetMenuHandle(136); //m = GetMHandle(136);
3609 for (i = 1; i <= n; i++)
3613 CheckItem(m, i, FALSE);
3620 for (i = 1; i <= n; i++)
3623 /* GetMenuItemText(m,i,s); */
3624 GetMenuItemText(m, i, s); //GetItem(m, i, s);
3626 value = atoi((char*)(s+1));
3631 /* Check the current size */
3632 if (td->tile_hgt == value) CheckItem(m, i, TRUE);
3639 * Process a menu selection (see above)
3641 * Hack -- assume that invalid menu selections are disabled above,
3642 * which I have been informed may not be reliable. XXX XXX XXX
3644 static void menu(long mc)
3648 int menuid, selection;
3650 static unsigned char s[1000];
3654 term_data *td = NULL;
3659 /* Analyze the menu command */
3660 menuid = HiWord(mc);
3661 selection = LoWord(mc);
3664 /* Find the window */
3665 for (i = 0; i < MAX_TERM_DATA; i++)
3667 /* Skip dead windows */
3668 if (!data[i].t) continue;
3670 /* Notice matches */
3671 if (data[i].w == FrontWindow()) td = &data[i];
3675 /* Branch on the menu */
3681 /* About Angband... */
3688 dialog=GetNewDialog(128, 0, (WindowPtr)-1);
3690 /* r=dialog->portRect;
3691 center_rect(&r, &qd.screenBits.bounds);
3692 MoveWindow(dialog, r.left, r.top, 1);*/
3694 ModalDialog(0, &item_hit);
3695 DisposeDialog(dialog); //DisposDialog(dialog);
3699 /* Desk accessory */
3700 /* GetMenuItemText(GetMHandle(128),selection,s); */
3701 GetMenuItemText(GetMenuHandle(128), selection, s); //GetItem(GetMHandle(128), selection, s);
3721 do_menu_file_open(FALSE);
3728 do_menu_file_open(TRUE);
3742 td->t->mapped_flag = FALSE;
3744 /* Hide the window */
3755 plog("º£¤Ï¥»¡¼¥Ö¤¹¤ë¤³¤È¤Ï½ÐÍè¤Þ¤»¤ó¡£");
3757 plog("You may not do that right now.");
3762 /* Hack -- Forget messages */
3765 /* Hack -- Save the game */
3766 do_cmd_save_game(FALSE);
3771 /* Quit (with save) */
3774 /* Save the game (if necessary) */
3775 if (game_in_progress && character_generated)
3779 plog("º£¤Ï¥»¡¼¥Ö¤¹¤ë¤³¤È¤Ï½ÐÍè¤Þ¤»¤ó¡£");
3781 plog("You may not do that right now.");
3785 /* Hack -- Forget messages */
3789 do_cmd_save_game(FALSE);
3810 /* Require a window */
3819 /* Toggle the "bold" setting */
3822 /* Toggle the setting */
3823 if (td->font_face & bold)
3825 td->font_face &= ~bold;
3829 td->font_face |= bold;
3833 /* Tile Width Hight Init */
3834 td->tile_wid = td->tile_hgt = 0;
3836 /* Apply and Verify */
3837 term_data_check_font(td);
3838 term_data_check_size(td);
3840 /* Resize and Redraw */
3841 term_data_resize(td);
3842 term_data_redraw(td);
3847 /* Toggle the "wide" setting */
3850 /* Toggle the setting */
3851 if (td->font_face & extend)
3853 td->font_face &= ~extend;
3857 td->font_face |= extend;
3861 /* Tile Width Hight Init */
3862 td->tile_wid = td->tile_hgt = 0;
3864 /* Apply and Verify */
3865 term_data_check_font(td);
3866 term_data_check_size(td);
3868 /* Resize and Redraw */
3869 term_data_resize(td);
3870 term_data_redraw(td);
3875 /* Get a new font name */
3876 /* GetMenuItemText(GetMHandle(131), selection, s); */
3877 GetMenuItemText(GetMenuHandle(131), selection, s); //GetItem(GetMHandle(131), selection, s);
3880 /* Save the new font id */
3883 /* Current size is bad for new font */
3884 if (!RealFont(td->font_id, td->font_size))
3886 /* Find similar size */
3887 for (i = 1; i <= 32; i++)
3889 /* Adjust smaller */
3890 if (td->font_size - i >= 8)
3892 if (RealFont(td->font_id, td->font_size - i))
3900 if (td->font_size + i <= 128)
3902 if (RealFont(td->font_id, td->font_size + i))
3912 /* Tile Width Hight Init */
3913 td->tile_wid = td->tile_hgt = 0;
3915 /* Apply and Verify */
3916 term_data_check_font(td);
3917 term_data_check_size(td);
3919 /* Resize and Redraw */
3920 term_data_resize(td);
3921 term_data_redraw(td);
3923 /* Restore the window */
3940 /* GetMenuItemText(GetMHandle(132), selection, s); */
3941 GetMenuItemText(GetMenuHandle(132), selection, s); //GetItem(GetMHandle(132), selection, s);
3943 td->font_size = atoi((char*)(s+1));
3946 /* Tile Width Hight Init */
3947 td->tile_wid = td->tile_hgt = 0;
3949 /* Apply and Verify */
3950 term_data_check_font(td);
3951 term_data_check_size(td);
3953 /* Resize and Redraw */
3954 term_data_resize(td);
3955 term_data_redraw(td);
3969 /* Check legality of choice */
3970 if ((i < 0) || (i >= MAX_TERM_DATA)) break;
3972 /* Obtain the window */
3982 td->t->mapped_flag = TRUE;
3984 /* Show the window */
3987 /* Bring to the front */
3988 SelectWindow(td->w);
4000 /* Toggle arg_sound */
4001 arg_sound = !arg_sound;
4003 /* React to changes */
4004 Term_xtra(TERM_XTRA_REACT, 0);
4011 /* Toggle arg_graphics */
4012 arg_graphics = !arg_graphics;
4014 /* Hack -- Force redraw */
4015 Term_key_push(KTRL('R'));
4022 arg_fiddle = !arg_fiddle;
4028 arg_wizard = !arg_wizard;
4042 /* TileWidth menu */
4053 /* GetMenuItemText(GetMHandle(135), selection, s); */
4054 GetMenuItemText(GetMenuHandle(135), selection, s); //GetItem(GetMHandle(135), selection, s);
4056 td->tile_wid = atoi((char*)(s+1));
4058 /* Apply and Verify */
4059 term_data_check_size(td);
4061 /* Resize and Redraw */
4062 term_data_resize(td);
4063 term_data_redraw(td);
4071 /* TileHeight menu */
4082 /* GetMenuItemText(GetMHandle(136), selection, s); */
4083 GetMenuItemText(GetMenuHandle(136), selection, s); //GetItem(GetMHandle(136), selection, s);
4085 td->tile_hgt = atoi((char*)(s+1));
4087 /* Apply and Verify */
4088 term_data_check_size(td);
4090 /* Resize and Redraw */
4091 term_data_resize(td);
4092 term_data_redraw(td);
4102 /* Clean the menu */
4111 * Check for extra required parameters -- From "Maarten Hazewinkel"
4113 static OSErr CheckRequiredAEParams(const AppleEvent *theAppleEvent)
4116 DescType returnedType;
4119 aeError = AEGetAttributePtr(theAppleEvent, keyMissedKeywordAttr, typeWildCard,
4120 &returnedType, NULL, 0, &actualSize);
4122 if (aeError == errAEDescNotFound) return (noErr);
4124 if (aeError == noErr) return (errAEParamMissed);
4131 * Apple Event Handler -- Open Application
4133 static pascal OSErr AEH_Start(const AppleEvent *theAppleEvent,
4134 const AppleEvent *reply, long handlerRefCon)
4136 #pragma unused(reply, handlerRefCon)
4138 return (CheckRequiredAEParams(theAppleEvent));
4143 * Apple Event Handler -- Quit Application
4145 static pascal OSErr AEH_Quit(const AppleEvent *theAppleEvent,
4146 const AppleEvent *reply, long handlerRefCon)
4148 #pragma unused(reply, handlerRefCon)
4151 quit_when_ready = TRUE;
4153 /* Check arguments */
4154 return (CheckRequiredAEParams(theAppleEvent));
4159 * Apple Event Handler -- Print Documents
4161 static pascal OSErr AEH_Print(const AppleEvent *theAppleEvent,
4162 const AppleEvent *reply, long handlerRefCon)
4164 #pragma unused(theAppleEvent, reply, handlerRefCon)
4166 return (errAEEventNotHandled);
4171 * Apple Event Handler by Steve Linberg (slinberg@crocker.com).
4173 * The old method of opening savefiles from the finder does not work
4174 * on the Power Macintosh, because CountAppFiles and GetAppFiles,
4175 * used to return information about the selected document files when
4176 * an application is launched, are part of the Segment Loader, which
4177 * is not present in the RISC OS due to the new memory architecture.
4179 * The "correct" way to do this is with AppleEvents. The following
4180 * code is modeled on the "Getting Files Selected from the Finder"
4181 * snippet from Think Reference 2.0. (The prior sentence could read
4182 * "shamelessly swiped & hacked")
4184 static pascal OSErr AEH_Open(AppleEvent *theAppleEvent,
4185 AppleEvent* reply, long handlerRefCon)
4187 #pragma unused(reply, handlerRefCon)
4194 DescType returnedType;
4198 /* Put the direct parameter (a descriptor list) into a docList */
4199 err = AEGetParamDesc(theAppleEvent, keyDirectObject, typeAEList, &docList);
4200 if (err) return err;
4203 * We ignore the validity check, because we trust the FInder, and we only
4204 * allow one savefile to be opened, so we ignore the depth of the list.
4207 err = AEGetNthPtr(&docList, 1L, typeFSS, &keywd,
4208 &returnedType, (Ptr) &myFSS, sizeof(myFSS), &actualSize);
4209 if (err) return err;
4211 /* Only needed to check savefile type below */
4212 err = FSpGetFInfo(&myFSS, &myFileInfo);
4215 sprintf(foo, "Arg! FSpGetFInfo failed with code %d", err);
4220 /* Ignore non 'SAVE' files */
4221 if (myFileInfo.fdType != 'SAVE') return noErr;
4223 /* XXX XXX XXX Extract a file name */
4224 PathNameFromDirID(myFSS.parID, myFSS.vRefNum, (StringPtr)savefile);
4225 pstrcat((StringPtr)savefile, (StringPtr)&myFSS.name);
4227 /* Convert the string */
4228 ptocstr((StringPtr)savefile);
4230 /* Delay actual open */
4231 open_when_ready = TRUE;
4234 err = AEDisposeDesc(&docList);
4246 * Macintosh modifiers (event.modifier & ccc):
4247 * cmdKey, optionKey, shiftKey, alphaLock, controlKey
4250 * Macintosh Keycodes (0-63 normal, 64-95 keypad, 96-127 extra):
4295 * Optimize non-blocking calls to "CheckEvents()"
4296 * Idea from "Maarten Hazewinkel <mmhazewi@cs.ruu.nl>"
4298 #define EVENT_TICKS 6
4302 * Check for Events, return TRUE if we process any
4304 * Hack -- Handle AppleEvents if appropriate (ignore result code).
4306 static bool CheckEvents(bool wait)
4322 term_data *td = NULL;
4326 static huge lastTicks = 0L;
4329 /* Access the clock */
4330 curTicks = TickCount();
4332 /* Hack -- Allow efficient checking for non-pending events */
4333 if (!wait && (curTicks < lastTicks + EVENT_TICKS)) return (FALSE);
4335 /* Timestamp last check */
4336 lastTicks = curTicks;
4338 /* Let the "system" run */
4341 /* Get an event (or null) */
4342 GetNextEvent(everyEvent, &event);
4344 /* Hack -- Nothing is ready yet */
4345 if (event.what == nullEvent) return (FALSE);
4348 /* Analyze the event */
4356 w = (WindowPtr)event.message;
4367 /* Extract the window */
4368 w = (WindowPtr)event.message;
4370 /* Find the window */
4371 for (i = 0; i < MAX_TERM_DATA; i++)
4373 /* Skip dead windows */
4374 if (!data[i].t) continue;
4376 /* Notice matches */
4377 if (data[i].w == w) td = &data[i];
4380 /* Hack XXX XXX XXX */
4384 /* Redraw the window */
4385 if (td) term_data_redraw(td);
4393 /* Extract some modifiers */
4394 mc = (event.modifiers & controlKey) ? TRUE : FALSE;
4395 ms = (event.modifiers & shiftKey) ? TRUE : FALSE;
4396 mo = (event.modifiers & optionKey) ? TRUE : FALSE;
4397 mx = (event.modifiers & cmdKey) ? TRUE : FALSE;
4399 /* Keypress: (only "valid" if ck < 96) */
4400 ch = (event.message & charCodeMask) & 255;
4402 /* Keycode: see table above */
4403 ck = ((event.message & keyCodeMask) >> 8) & 255;
4405 /* Command + "normal key" -> menu action */
4406 if (mx && (ck < 64))
4408 /* Hack -- Prepare the menus */
4411 /* Mega-Hack -- allow easy exit if nothing to save */
4412 /* if (!character_generated && (ch=='Q' || ch=='q')) ch = 'e'; */
4414 /* Run the Menu-Handler */
4417 /* Turn off the menus */
4425 /* Hide the mouse pointer */
4428 /* Normal key -> simple keypress */
4431 /* Enqueue the keypress */
4435 /* Hack -- normal "keypad keys" -> special keypress */
4436 else if (!mc && !ms && !mo && !mx && (ck < 96))
4438 /* Hack -- "enter" is confused */
4439 if (ck == 76) ch = '\n';
4441 /* Send control-caret as a trigger */
4444 /* Send the "ascii" keypress */
4448 /* Bizarre key -> encoded keypress */
4451 /* Hack -- introduce with control-underscore */
4454 /* Send some modifier keys */
4455 if (mc) Term_keypress('C');
4456 if (ms) Term_keypress('S');
4457 if (mo) Term_keypress('O');
4458 if (mx) Term_keypress('X');
4460 /* Hack -- Downshift and encode the keycode */
4461 Term_keypress('0' + (ck - 64) / 10);
4462 Term_keypress('0' + (ck - 64) % 10);
4464 /* Hack -- Terminate the sequence */
4475 /* Analyze click location */
4476 code = FindWindow(event.where, &w);
4478 /* Find the window */
4479 for (i = 0; i < MAX_TERM_DATA; i++)
4481 /* Skip dead windows */
4482 if (!data[i].t) continue;
4484 /* Notice matches */
4485 if (data[i].w == w) td = &data[i];
4494 menu(MenuSelect(event.where));
4501 SystemClick(&event, w);
4511 r = qd.screenBits.bounds;
4512 r.top += 20; /* GetMBarHeight() XXX XXX XXX */
4513 InsetRect(&r, 4, 4);
4514 DragWindow(w, event.where, &r);
4526 p.h = td->w->portRect.left;
4527 p.v = td->w->portRect.top;
4535 /* Apply and Verify */
4536 term_data_check_size(td);
4546 /* Track the go-away box */
4547 if (TrackGoAway(w, event.where))
4553 td->t->mapped_flag = FALSE;
4555 /* Hide the window */
4571 /* Fake rectangle */
4572 r.left = 20 * td->tile_wid + td->size_ow1;
4573 r.right = 80 * td->tile_wid + td->size_ow1 + td->size_ow2 + 1;
4574 r.top = 1 * td->tile_hgt + td->size_oh1;
4575 r.bottom = 24 * td->tile_hgt + td->size_oh1 + td->size_oh2 + 1;
4577 /* Grow the rectangle */
4578 newsize = GrowWindow(w, event.where, &r);
4581 if (!newsize) break;
4583 /* Extract the new size in pixels */
4584 y = HiWord(newsize) - td->size_oh1 - td->size_oh2;
4585 x = LoWord(newsize) - td->size_ow1 - td->size_ow2;
4587 /* Extract a "close" approximation */
4588 td->rows = y / td->tile_hgt;
4589 td->cols = x / td->tile_wid;
4591 /* Apply and Verify */
4592 term_data_check_size(td);
4595 Term_activate(td->t);
4597 /* Hack -- Resize the term */
4598 Term_resize(td->cols, td->rows);
4600 /* Resize and Redraw */
4601 term_data_resize(td);
4602 term_data_redraw(td);
4621 /* Disk Event -- From "Maarten Hazewinkel" */
4624 /* check for error when mounting the disk */
4625 if (HiWord(event.message) != noErr)
4631 DIBadMount(p, event.message);
4638 /* OS Event -- From "Maarten Hazewinkel" */
4641 switch ((event.message >> 24) & 0x000000FF)
4643 case suspendResumeMessage:
4645 /* Resuming: activate the front window */
4646 if (event.message & resumeFlag)
4648 SetPort(FrontWindow());
4649 SetCursor(&qd.arrow);
4652 /* Suspend: deactivate the front window */
4666 /* From "Steve Linberg" and "Maarten Hazewinkel" */
4667 case kHighLevelEvent:
4669 /* Process apple events */
4670 if (AEProcessAppleEvent(&event) != noErr)
4673 plog("Apple Event Handler¤Î¥¨¥é¡¼¤Ç¤¹.");
4675 plog("Error in Apple Event Handler!");
4679 /* Handle "quit_when_ready" */
4680 if (quit_when_ready)
4683 quit_when_ready = FALSE;
4685 /* Do the menu key */
4688 /* Turn off the menus */
4692 /* Handle "open_when_ready" */
4693 handle_open_when_ready();
4703 /* Something happened */
4710 /*** Some Hooks for various routines ***/
4714 * Mega-Hack -- emergency lifeboat
4716 static vptr lifeboat = NULL;
4720 * Hook to "release" memory
4722 static vptr hook_rnfree(vptr v, huge size)
4725 #pragma unused (size)
4729 /* Alternative method */
4744 * Hook to "allocate" memory
4746 static vptr hook_ralloc(huge size)
4751 /* Make a new pointer */
4752 return (malloc(size));
4756 /* Make a new pointer */
4757 return (NewPtr(size));
4764 * Hook to handle "out of memory" errors
4766 static vptr hook_rpanic(huge size)
4769 #pragma unused (size)
4773 /* Free the lifeboat */
4776 /* Free the lifeboat */
4777 DisposePtr(lifeboat);
4779 /* Forget the lifeboat */
4782 /* Mega-Hack -- Warning */
4784 mac_warning("¥á¥â¥ê¡¼¤¬Â¤ê¤Þ¤»¤ó!\rº£¤¹¤°½ªÎ»¤·¤Æ²¼¤µ¤¤!");
4786 mac_warning("Running out of Memory!\rAbort this process now!");
4789 /* Mega-Hack -- Never leave this function */
4790 while (TRUE) CheckEvents(TRUE);
4793 /* Mega-Hack -- Crash */
4799 * Hook to tell the user something important
4801 static void hook_plog(cptr str)
4803 /* Warning message */
4808 * Hook to tell the user something, and then quit
4810 static void hook_quit(cptr str)
4812 /* Warning if needed */
4813 if (str) mac_warning(str);
4815 /* Write a preference file */
4823 * Hook to tell the user something, and then crash
4825 static void hook_core(cptr str)
4827 /* XXX Use the debugger */
4828 /* DebugStr(str); */
4831 if (str) mac_warning(str);
4833 /* Warn, then save player */
4835 mac_warning("Ã×̿Ū¤Ê¥¨¥é¡¼¤Ç¤¹.\r¶¯À©Åª¤Ë¥»¡¼¥Ö¤·¤Æ½ªÎ»¤·¤Þ¤¹.");
4837 mac_warning("Fatal error.\rI will now attempt to save and quit.");
4840 /* Attempt to save */
4842 if (!save_player()) mac_warning("·Ù¹ð -- ¥»¡¼¥Ö¤Ë¼ºÇÔ¤·¤Þ¤·¤¿!");
4844 if (!save_player()) mac_warning("Warning -- save failed!");
4853 /*** Main program ***/
4859 * XXX XXX XXX Hack -- This function attempts to "fix" the nasty
4860 * "Macintosh Save Bug" by using "absolute" path names, since on
4861 * System 7 machines anyway, the "current working directory" often
4862 * "changes" due to background processes, invalidating any "relative"
4863 * path names. Note that the Macintosh is limited to 255 character
4864 * path names, so be careful about deeply embedded directories...
4866 * XXX XXX XXX Hack -- This function attempts to "fix" the nasty
4867 * "missing lib folder bug" by allowing the user to help find the
4868 * "lib" folder by hand if the "application folder" code fails...
4870 static void init_stuff(void)
4887 /* Fake rectangle */
4894 center_rect(&r, &qd.screenBits.bounds);
4896 /* Extract corner */
4901 /* Default to the "lib" folder with the application */
4902 refnum_to_name(path, app_dir, app_vol, (char*)("\plib:"));
4905 /* Check until done */
4908 /* Prepare the paths */
4909 init_file_paths(path);
4911 /* Build the filename */
4913 path_build(path, 1024, ANGBAND_DIR_FILE, "news_j.txt");
4915 path_build(path, 1024, ANGBAND_DIR_FILE, "news.txt");
4918 /* Attempt to open and close that file */
4919 if (0 == fd_close(fd_open(path, O_RDONLY))) break;
4923 plog_fmt("'%s' ¥Õ¥¡¥¤¥ë¤ò¥ª¡¼¥×¥ó½ÐÍè¤Þ¤»¤ó.", path);
4925 plog_fmt("Unable to open the '%s' file.", path);
4930 plog("Hengband¤Î'lib'¥Õ¥©¥ë¥À¤¬Â¸ºß¤·¤Ê¤¤¤«Àµ¤·¤¯Ìµ¤¤²ÄǽÀ¤¬¤¢¤ê¤Þ¤¹.");
4932 plog("The Angband 'lib' folder is probably missing or misplaced.");
4936 plog("Please 'open' any file in any sub-folder of the 'lib' folder.");
4938 /* Allow "text" files */
4941 /* Allow "save" files */
4944 /* Allow "data" files */
4948 SFGetFile(topleft, "\p", NULL, 3, types, NULL, &reply);
4951 if (!reply.good) quit(NULL);
4953 /* Extract textual file name for given file */
4954 GetWDInfo(reply.vRefNum, &vrefnum, &drefnum, &junk);
4955 refnum_to_name(path, drefnum, vrefnum, (char*)reply.fName);
4957 /* Hack -- Remove the "filename" */
4958 i = strlen(path) - 1;
4959 while ((i > 0) && (path[i] != ':')) i--;
4960 if (path[i] == ':') path[i+1] = '\0';
4962 /* Hack -- allow "lib" folders */
4963 if (suffix(path, "lib:")) continue;
4965 /* Hack -- Remove the "sub-folder" */
4967 while ((i > 1) && (path[i] != ':')) i--;
4968 if (path[i] == ':') path[i+1] = '\0';
4974 * Macintosh Main loop
4978 EventRecord tempEvent;
4979 int numberOfMasters = 10;
4981 /* Increase stack space by 64K */
4982 SetApplLimit(GetApplLimit() - 131072L);//65536L);
4984 /* Stretch out the heap to full size */
4987 /* Get more Masters */
4988 while (numberOfMasters--) MoreMasters();
4990 /* Set up the Macintosh */
4991 InitGraf(&qd.thePort);
5004 FlushEvents(everyEvent, 0);
5006 /* Flush events some more (?) */
5007 (void)EventAvail(everyEvent, &tempEvent);
5008 (void)EventAvail(everyEvent, &tempEvent);
5009 (void)EventAvail(everyEvent, &tempEvent);
5012 #ifdef ANGBAND_LITE_MAC
5016 #else /* ANGBAND_LITE_MAC */
5018 # if defined(powerc) || defined(__powerc)
5020 /* Assume System 7 */
5022 /* Assume Color Quickdraw */
5032 /* Check the Gestalt */
5033 err = Gestalt(gestaltSystemVersion, &versionNumber);
5035 /* Check the version */
5036 if ((err != noErr) || (versionNumber < 0x0700))
5039 quit("¤³¤Î¥×¥í¥°¥é¥à¤Ï´Á»úTalk7.x.x°Ê¹ß¤ÇÆ°ºî¤·¤Þ¤¹.");
5041 quit("You must have System 7 to use this program.");
5051 /* Check the environs */
5052 if (SysEnvirons(1, &env) != noErr)
5055 quit("SysEnvirons ¥³¡¼¥ë¤Ï¼ºÇÔ¤·¤Þ¤·¤¿¡ª");
5057 quit("The SysEnvirons call failed!");
5061 /* Check for System Seven Stuff */
5062 if (env.systemVersion < 0x0700)
5065 quit("¤³¤Î¥×¥í¥°¥é¥à¤Ï´Á»úTalk7.x.x°Ê¹ß¤ÇÆ°ºî¤·¤Þ¤¹.");
5067 quit("You must have System 7 to use this program.");
5071 /* Check for Color Quickdraw */
5072 if (!env.hasColorQD)
5075 quit("¤³¤Î¥×¥í¥°¥é¥à¤ÏColor Quickdraw¤¬Ìµ¤¤¤ÈÆ°ºî¤·¤Þ¤»¤ó.");
5077 quit("You must have Color Quickdraw to use this program.");
5084 #endif /* ANGBAND_LITE_MAC */
5089 /* Obtain a "Universal Procedure Pointer" */
5090 AEH_Start_UPP = NewAEEventHandlerProc(AEH_Start);
5092 /* Install the hook (ignore error codes) */
5093 AEInstallEventHandler(kCoreEventClass, kAEOpenApplication, AEH_Start_UPP,
5096 /* Obtain a "Universal Procedure Pointer" */
5097 AEH_Quit_UPP = NewAEEventHandlerProc(AEH_Quit);
5099 /* Install the hook (ignore error codes) */
5100 AEInstallEventHandler(kCoreEventClass, kAEQuitApplication, AEH_Quit_UPP,
5103 /* Obtain a "Universal Procedure Pointer" */
5104 AEH_Print_UPP = NewAEEventHandlerProc(AEH_Print);
5106 /* Install the hook (ignore error codes) */
5107 AEInstallEventHandler(kCoreEventClass, kAEPrintDocuments, AEH_Print_UPP,
5110 /* Obtain a "Universal Procedure Pointer" */
5111 AEH_Open_UPP = NewAEEventHandlerProc(AEH_Open);
5113 /* Install the hook (ignore error codes) */
5114 AEInstallEventHandler(kCoreEventClass, kAEOpenDocuments, AEH_Open_UPP,
5120 /* Find the current application */
5124 #if defined(MACINTOSH) && !defined(applec)
5126 /* Mark ourself as the file creator */
5129 /* Default to saving a "text" file */
5135 #if defined(__MWERKS__)
5137 /* Obtian a "Universal Procedure Pointer" */
5138 ynfilterUPP = NewModalFilterProc(ynfilter);
5143 /* Hook in some "z-virt.c" hooks */
5144 rnfree_aux = hook_rnfree;
5145 ralloc_aux = hook_ralloc;
5146 rpanic_aux = hook_rpanic;
5148 /* Hooks in some "z-util.c" hooks */
5149 plog_aux = hook_plog;
5150 quit_aux = hook_quit;
5151 core_aux = hook_core;
5153 BackColor(blackColor);
5154 ForeColor(whiteColor);
5156 /* Show the "watch" cursor */
5157 SetCursor(*(GetCursor(watchCursor)));
5159 /* Prepare the menubar */
5162 /* Prepare the windows */
5169 /* Hack -- process all events */
5170 while (CheckEvents(TRUE)) /* loop */;
5172 /* Reset the cursor */
5173 SetCursor(&qd.arrow);
5176 /* Mega-Hack -- Allocate a "lifeboat" */
5177 lifeboat = NewPtr(16384);
5179 /* Note the "system" */
5180 ANGBAND_SYS = "mac";
5181 ANGBAND_GRAF = "new";
5190 /* Hack -- process all events */
5191 while (CheckEvents(TRUE)) /* loop */;
5194 /* We are now initialized */
5198 /* Handle "open_when_ready" */
5199 handle_open_when_ready();
5205 /* Prompt the user */
5207 prt("'¥Õ¥¡¥¤¥ë'¥á¥Ë¥å¡¼¤è¤ê'¿·µ¬'¤Þ¤¿¤Ï'³«¤¯...'¤òÁªÂò¤·¤Æ¤¯¤À¤µ¤¤¡£", 23, 10);
5209 prt("[Choose 'New' or 'Open' from the 'File' menu]", 23, 15);
5212 /* Flush the prompt */
5216 /* Hack -- Process Events Forever */
5217 while (TRUE) CheckEvents(TRUE);