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 "Hengband-E 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 */
309 GWorldPtr bufferPort;
310 PixMapHandle bufferPixHndl;
354 * Forward declare -- see below
356 static bool CheckEvents(bool wait);
360 * Hack -- location of the main directory
362 static short app_vol;
367 * Delay handling of double-clicked savefiles
369 Boolean open_when_ready = FALSE;
372 * Delay handling of pre-emptive "quit" event
374 Boolean quit_when_ready = FALSE;
378 * Hack -- game in progress
380 static int game_in_progress = 0;
384 * Only do "SetPort()" when needed
386 static WindowPtr active = NULL;
391 * An array of term_data's
393 static term_data data[MAX_TERM_DATA];
398 * Note when "open"/"new" become valid
400 static bool initialized = FALSE;
405 * CodeWarrior uses Universal Procedure Pointers
407 static ModalFilterUPP ynfilterUPP;
414 AEEventHandlerUPP AEH_Start_UPP;
415 AEEventHandlerUPP AEH_Quit_UPP;
416 AEEventHandlerUPP AEH_Print_UPP;
417 AEEventHandlerUPP AEH_Open_UPP;
425 static int ext_sound = 0;
433 #define SND_CMD_ERROR 6
435 static int soundchoice[] = {
503 static int soundmode[8];
509 * Convert refnum+vrefnum+fname into a full file name
510 * Store this filename in 'buf' (make sure it is long enough)
511 * Note that 'fname' looks to be a "pascal" string
513 static void refnum_to_name(char *buf, long refnum, short vrefnum, char *fname)
525 for (j=1; j<=fname[0]; j++)
527 res[i-fname[0]+j] = fname[j];
531 pb.ioCompletion=NULL;
533 pb.ioVRefNum=vrefnum;
539 pb.ioDrDirID=pb.ioDrParID;
540 err = PBGetCatInfo((CInfoPBPtr)&pb, FALSE);
542 for (j=1; j<=name[0]; j++)
544 res[i-name[0]+j] = name[j];
548 if (pb.ioDrDirID == fsRtDirID) break;
551 /* Extract the result */
552 for (j = 0, i++; res[i]; j++, i++) buf[j] = res[i];
560 * XXX XXX XXX Allow the system to ask us for a filename
562 static bool askfor_file(char *buf, int len)
570 /* Default file name */
571 sprintf((char*)dflt + 1, "%s's description", buf);
572 dflt[0] = strlen((char*)dflt + 1);
574 /* Ask for a file name */
575 topleft.h=(qd.screenBits.bounds.left+qd.screenBits.bounds.right)/2-344/2;
576 topleft.v=(2*qd.screenBits.bounds.top+qd.screenBits.bounds.bottom)/3-188/2;
577 SFPutFile(topleft, "\pSelect a filename:", dflt, NULL, &reply);
578 /* StandardPutFile("\pSelect a filename:", dflt, &reply); */
586 GetWDInfo(reply.vRefNum, &vrefnum, &drefnum, &junk);
588 /* Extract the name */
589 refnum_to_name(buf, drefnum, vrefnum, (char*)reply.fName);
604 * Center a rectangle inside another rectangle
606 static void center_rect(Rect *r, Rect *s)
608 int centerx = (s->left + s->right)/2;
609 int centery = (2*s->top + s->bottom)/3;
610 int dx = centerx - (r->right - r->left)/2 - r->left;
611 int dy = centery - (r->bottom - r->top)/2 - r->top;
620 * Convert a pascal string in place
622 * This function may be defined elsewhere, but since it is so
623 * small, it is not worth finding the proper function name for
624 * all the different platforms.
626 static void ptocstr(StringPtr src)
630 /* Hack -- pointer */
631 char *s = (char*)(src);
633 /* Hack -- convert the string */
634 for (i = s[0]; i; i--, s++) s[0] = s[1];
636 /* Hack -- terminate the string */
641 #if defined(USE_SFL_CODE)
645 * The following three routines (pstrcat, pstrinsert, and PathNameFromDirID)
646 * were taken from the Think Reference section called "Getting a Full Pathname"
647 * (under the File Manager section). We need PathNameFromDirID to get the
648 * full pathname of the opened savefile, making no assumptions about where it
651 * I had to hack PathNameFromDirID a little for MetroWerks, but it's awfully
654 static void pstrcat(StringPtr dst, StringPtr src)
657 BlockMove(src + 1, dst + *dst + 1, *src);
659 /* adjust length byte */
664 * pstrinsert - insert string 'src' at beginning of string 'dst'
666 static void pstrinsert(StringPtr dst, StringPtr src)
668 /* make room for new string */
669 BlockMove(dst + 1, dst + *src + 1, *dst);
671 /* copy new string in */
672 BlockMove(src + 1, dst + 1, *src);
674 /* adjust length byte */
678 static void PathNameFromDirID(long dirID, short vRefNum, StringPtr fullPathName)
681 Str255 directoryName;
684 fullPathName[0] = '\0';
686 block.dirInfo.ioDrParID = dirID;
687 block.dirInfo.ioNamePtr = directoryName;
691 block.dirInfo.ioVRefNum = vRefNum;
692 block.dirInfo.ioFDirIndex = -1;
693 block.dirInfo.ioDrDirID = block.dirInfo.ioDrParID;
694 err = PBGetCatInfo(&block, FALSE);
695 pstrcat(directoryName, (StringPtr)"\p:");
696 pstrinsert(fullPathName, directoryName);
697 if (block.dirInfo.ioDrDirID == 2) break;
706 * Activate a given window, if necessary
708 static void activate(WindowPtr w)
723 * Display a warning message
725 static void mac_warning(cptr warning)
730 /* Limit of 250 chars */
731 len = strlen(warning);
732 if (len > 250) len = 250;
734 /* Make a "Pascal" string */
736 for (i=0; i<len; i++) text[i+1] = warning[i];
738 /* Prepare the dialog box values */
739 ParamText(text, "\p", "\p", "\p");
741 /* Display the Alert, wait for Okay */
747 /*** Some generic functions ***/
750 #ifdef ANGBAND_LITE_MAC
753 * Hack -- activate a color (0 to 255)
755 #define term_data_color(TD,A) /* Nothing */
757 #else /* ANGBAND_LITE_MAC */
760 * Hack -- activate a color (0 to 255)
762 static void term_data_color(term_data *td, int a)
768 /* Extract the R,G,B data */
769 rv = angband_color_table[a][1];
770 gv = angband_color_table[a][2];
771 bv = angband_color_table[a][3];
774 color.red = (rv | (rv << 8));
775 color.green = (gv | (gv << 8));
776 color.blue = (bv | (bv << 8));
778 /* Activate the color */
779 RGBForeColor(&color);
785 #endif /* ANGBAND_LITE_MAC */
789 * Hack -- Apply and Verify the "font" info
791 * This should usually be followed by "term_data_check_size()"
793 static void term_data_check_font(term_data *td)
799 WindowPtr old = active;
805 /* Instantiate font */
806 TextFont(td->font_id);
807 TextSize(td->font_size);
808 TextFace(td->font_face);
810 /* Extract the font info */
813 /* Assume monospaced */
814 td->font_mono = TRUE;
816 /* Extract the font sizing values XXX XXX XXX */
817 td->font_wid = CharWidth('@'); /* info.widMax; */
818 td->font_hgt = info.ascent + info.descent;
820 td->font_o_y = info.ascent;
822 /* Check important characters */
823 for (i = 33; i < 127; i++)
825 /* Hack -- notice non-mono-space */
826 if (td->font_wid != CharWidth(i)) td->font_mono = FALSE;
828 /* Hack -- collect largest width */
829 if (td->font_wid < CharWidth(i)) td->font_wid = CharWidth(i);
832 /* Set default offsets */
833 td->tile_o_x = td->font_o_x;
834 td->tile_o_y = td->font_o_y;
836 /* Set default tile size */
837 if( td->tile_wid == 0 && td->tile_hgt == 0 ){
838 td->tile_wid = td->font_wid;
839 td->tile_hgt = td->font_hgt;
842 /* Re-activate the old window */
848 * Hack -- Apply and Verify the "size" info
850 static void term_data_check_size(term_data *td)
852 /* Minimal window size */
853 if (td->cols < 1) td->cols = 1;
854 if (td->rows < 1) td->rows = 1;
856 /* Minimal tile size */
857 if (td->tile_wid < 4) td->tile_wid = 4;
858 if (td->tile_hgt < 4) td->tile_hgt = 4;
860 /* Default tile offsets */
861 td->tile_o_x = (td->tile_wid - td->font_wid) / 2;
862 td->tile_o_y = (td->tile_hgt - td->font_hgt) / 2;
864 /* Minimal tile offsets */
865 if (td->tile_o_x < 0) td->tile_o_x = 0;
866 if (td->tile_o_y < 0) td->tile_o_y = 0;
868 /* Apply font offsets */
869 td->tile_o_x += td->font_o_x;
870 td->tile_o_y += td->font_o_y;
872 /* Calculate full window size */
873 td->size_wid = td->cols * td->tile_wid + td->size_ow1 + td->size_ow2;
874 td->size_hgt = td->rows * td->tile_hgt + td->size_oh1 + td->size_oh2;
877 if (td->r.top > qd.screenBits.bounds.bottom - td->size_hgt)
879 td->r.top = qd.screenBits.bounds.bottom - td->size_hgt;
883 if (td->r.top < qd.screenBits.bounds.top + 30)
885 td->r.top = qd.screenBits.bounds.top + 30;
888 /* Verify the left */
889 if (td->r.left > qd.screenBits.bounds.right - td->size_wid)
891 td->r.left = qd.screenBits.bounds.right - td->size_wid;
894 /* Verify the left */
895 if (td->r.left < qd.screenBits.bounds.left)
897 td->r.left = qd.screenBits.bounds.left;
900 /* Calculate bottom right corner */
901 td->r.right = td->r.left + td->size_wid;
902 td->r.bottom = td->r.top + td->size_hgt;
904 /* Assume no graphics */
905 td->t->always_pict = FALSE;
907 #ifdef ANGBAND_LITE_MAC
911 #else /* ANGBAND_LITE_MAC */
913 /* Handle graphics */
914 if (use_graphics && (td == &data[0]))
916 td->t->always_pict = TRUE;
919 #endif /* ANGBAND_LITE_MAC */
921 /* Fake mono-space */
922 if (!td->font_mono ||
923 (td->font_wid != td->tile_wid) ||
924 (td->font_hgt != td->tile_hgt))
926 /* Handle fake monospace */
927 td->t->always_pict = TRUE;
931 static OSErr XDDSWUpDateGWorldFromPict( term_data *td );
933 * Hack -- resize a term_data
935 * This should normally be followed by "term_data_resize()"
937 static void term_data_resize(term_data *td)
939 /* Actually resize the window */
940 SizeWindow(td->w, td->size_wid, td->size_hgt, 0);
942 XDDSWUpDateGWorldFromPict( td );
948 * Hack -- redraw a term_data
950 * Note that "Term_redraw()" calls "TERM_XTRA_CLEAR"
952 static void term_data_redraw(term_data *td)
956 /* Activate the term */
957 Term_activate(td->t);
959 /* Redraw the contents */
962 /* Flush the output */
965 /* Restore the old term */
968 /* No need to redraw */
969 ValidRect(&td->w->portRect);
975 #ifdef ANGBAND_LITE_MAC
979 #else /* ANGBAND_LITE_MAC */
986 static int pictID = 1001; /* 8x8 tiles; 16x16 tiles are 1002 */
988 static int grafWidth = 8; /* Always equal to grafHeight */
989 static int grafHeight = 8; /* Either 8 or 16 */
991 static bool arg_newstyle_graphics;
992 static bool use_newstyle_graphics;
997 typedef struct FrameRec FrameRec;
1002 * - GWorld for the frame image
1003 * - Handle to pix map (saved for unlocking/locking)
1004 * - Pointer to color pix map (valid only while locked)
1008 GWorldPtr framePort;
1009 PixMapHandle framePixHndl;
1016 * The global picture data
1018 static FrameRec *frameP = NULL;
1024 static void BenSWLockFrame(FrameRec *srcFrameP)
1026 PixMapHandle pixMapH;
1028 pixMapH = GetGWorldPixMap(srcFrameP->framePort);
1029 (void)LockPixels(pixMapH);
1030 HLockHi((Handle)pixMapH);
1031 srcFrameP->framePixHndl = pixMapH;
1032 srcFrameP->framePix = (PixMapPtr)StripAddress(*(Handle)pixMapH);
1039 static void XDDSWLockFrame( term_data *td )
1041 PixMapHandle pixMapH;
1043 pixMapH = GetGWorldPixMap(td->bufferPort);
1044 (void)LockPixels(pixMapH);
1045 HLockHi((Handle)pixMapH);
1046 td->bufferPixHndl = pixMapH;
1047 td->bufferPix = (PixMapPtr)*(Handle)pixMapH;
1054 static void BenSWUnlockFrame(FrameRec *srcFrameP)
1056 if (srcFrameP->framePort != NULL)
1058 HUnlock((Handle)srcFrameP->framePixHndl);
1059 UnlockPixels(srcFrameP->framePixHndl);
1062 srcFrameP->framePix = NULL;
1069 static void XDDSWUnlockFrame( term_data *td )
1071 if (td->bufferPort != NULL)
1073 HUnlock((Handle)td->bufferPixHndl);
1074 UnlockPixels(td->bufferPixHndl);
1077 td->bufferPix = NULL;
1080 static OSErr BenSWCreateGWorldFromPict(
1081 GWorldPtr *pictGWorld,
1085 GWorldPtr saveGWorld;
1086 GDHandle saveGDevice;
1087 GWorldPtr tempGWorld;
1096 depth = data[0].pixelDepth;
1099 theGDH = data[0].theGDH;
1101 /* Obtain size rectangle */
1102 pictRect = (**pictH).picFrame;
1103 OffsetRect(&pictRect, -pictRect.left, -pictRect.top);
1105 /* Create a GWorld */
1106 err = NewGWorld(&tempGWorld, depth, &pictRect, nil,
1107 theGDH, noNewDevice);
1116 *pictGWorld = tempGWorld;
1119 GetGWorld(&saveGWorld, &saveGDevice);
1122 SetGWorld(tempGWorld, nil);
1124 /* Dump the pict into the GWorld */
1125 (void)LockPixels(GetGWorldPixMap(tempGWorld));
1126 EraseRect(&pictRect);
1127 DrawPicture(pictH, &pictRect);
1128 UnlockPixels(GetGWorldPixMap(tempGWorld));
1130 /* Restore GWorld */
1131 SetGWorld(saveGWorld, saveGDevice);
1138 static OSErr XDDSWCreateGWorldFromPict(
1139 GWorldPtr *pictGWorld,
1143 GWorldPtr saveGWorld;
1144 GDHandle saveGDevice;
1145 GWorldPtr tempGWorld;
1156 depth = td->pixelDepth;
1159 theGDH = td->theGDH;
1161 /* Obtain size rectangle */
1163 pictRect.right = td->size_wid;
1165 pictRect.bottom = td->tile_hgt;
1167 /* Create a GWorld */
1168 err = NewGWorld(&tempGWorld, 0, &pictRect, 0, 0, 0);
1177 *pictGWorld = tempGWorld;
1180 GetGWorld(&saveGWorld, &saveGDevice);
1183 SetGWorld(tempGWorld, nil);
1185 /* Dump the pict into the GWorld
1186 (void)LockPixels(GetGWorldPixMap(tempGWorld));
1187 EraseRect(&pictRect);
1188 // DrawPicture(pictH, &pictRect);
1189 UnlockPixels(GetGWorldPixMap(tempGWorld));
1191 /* Restore GWorld */
1192 SetGWorld(saveGWorld, saveGDevice);
1198 static OSErr XDDSWUpDateGWorldFromPict( term_data *td )
1200 GWorldPtr saveGWorld;
1201 GDHandle saveGDevice;
1206 GWorldFlags errflag;
1210 if( td->bufferPort == NULL )
1213 depth = td->pixelDepth;
1216 theGDH = td->theGDH;
1218 /* Obtain size rectangle */
1221 pictRect.right = td->size_wid;
1222 pictRect.bottom = td->tile_hgt;
1224 XDDSWUnlockFrame(td);
1226 errflag = UpdateGWorld( &td->bufferPort, depth, &pictRect, 0, 0, 0);
1228 if( errflag & gwFlagErr ){
1234 /* GetGWorld(&saveGWorld, &saveGDevice); */
1237 /* SetGWorld(td->bufferPort, nil); */
1239 /* Dump the pict into the GWorld */
1240 /* (void)LockPixels(GetGWorldPixMap(td->bufferPort)); */
1241 /* EraseRect(&td->bufferPort->portRect); */
1243 /* UnlockPixels(GetGWorldPixMap(td->bufferPort)); */
1245 /* Restore GWorld */
1246 /* SetGWorld(saveGWorld, saveGDevice); */
1251 * Init the global "frameP"
1254 static errr globe_init(void)
1258 GWorldPtr tempPictGWorldP;
1262 /* Use window XXX XXX XXX */
1266 /* Get the pict resource */
1267 newPictH = GetPicture(pictID);
1269 /* Analyze result */
1270 err = (newPictH ? 0 : -1);
1277 err = BenSWCreateGWorldFromPict(&tempPictGWorldP, newPictH);
1279 /* Release resource */
1280 ReleaseResource((Handle)newPictH);
1285 /* Create the frame */
1286 frameP = (FrameRec*)NewPtrClear((Size)sizeof(FrameRec));
1288 /* Analyze result */
1289 err = (frameP ? 0 : -1);
1295 frameP->framePort = tempPictGWorldP;
1298 BenSWLockFrame(frameP);
1309 * Nuke the global "frameP"
1311 static errr globe_nuke(void)
1317 BenSWUnlockFrame(frameP);
1319 /* Dispose of the GWorld */
1320 DisposeGWorld(frameP->framePort);
1322 /* Dispose of the memory */
1323 DisposePtr((Ptr)frameP);
1330 FlushEvents(everyEvent, 0);
1337 #endif /* ANGBAND_LITE_MAC */
1341 /*** Support for the "z-term.c" package ***/
1345 * Initialize a new Term
1347 * Note also the "window type" called "noGrowDocProc", which might be more
1348 * appropriate for the main "screen" window.
1350 * Note the use of "srcCopy" mode for optimized screen writes.
1352 static void Term_init_mac(term *t)
1354 term_data *td = (term_data*)(t->data);
1356 static RGBColor black = {0x0000,0x0000,0x0000};
1357 static RGBColor white = {0xFFFF,0xFFFF,0xFFFF};
1359 #ifdef ANGBAND_LITE_MAC
1361 /* Make the window */
1362 td->w = NewWindow(0, &td->r, td->title, 0, noGrowDocProc, (WindowPtr)-1, 1, 0L);
1364 #else /* ANGBAND_LITE_MAC */
1366 /* Make the window */
1367 td->w = NewCWindow(0, &td->r, td->title, 0, documentProc, (WindowPtr)-1, 1, 0L);
1369 #endif /* ANGBAND_LITE_MAC */
1371 /* Activate the window */
1374 /* Erase behind words */
1377 /* Apply and Verify */
1378 term_data_check_font(td);
1379 term_data_check_size(td);
1381 /* Resize the window */
1382 term_data_resize(td);
1384 #ifdef ANGBAND_LITE_MAC
1386 /* Prepare the colors (base colors) */
1387 BackColor(blackColor);
1388 ForeColor(whiteColor);
1390 #else /* ANGBAND_LITE_MAC */
1392 /* Prepare the colors (real colors) */
1393 RGBBackColor(&black);
1394 RGBForeColor(&white);
1401 GDHandle currentGDH;
1402 GWorldPtr windowGWorld;
1403 PixMapHandle basePixMap;
1405 /* Obtain the rect */
1406 tempRect = td->w->portRect;
1408 /* Obtain the global rect */
1409 globalRect = tempRect;
1410 LocalToGlobal((Point*)&globalRect.top);
1411 LocalToGlobal((Point*)&globalRect.bottom);
1413 /* Obtain the proper GDH */
1414 mainGDH = GetMaxDevice(&globalRect);
1416 /* Extract GWorld and GDH */
1417 GetGWorld(&windowGWorld, ¤tGDH);
1419 /* Obtain base pixmap */
1420 basePixMap = (**mainGDH).gdPMap;
1422 /* Save pixel depth */
1423 td->pixelDepth = (**basePixMap).pixelSize;
1425 /* Save Window GWorld */
1426 td->theGWorld = windowGWorld;
1428 /* Save Window GDH */
1429 td->theGDH = currentGDH;
1432 td->mainSWGDH = mainGDH;
1435 #endif /* ANGBAND_LITE_MAC */
1437 /* Clip to the window */
1438 ClipRect(&td->w->portRect);
1440 /* Erase the window */
1441 EraseRect(&td->w->portRect);
1443 /* Invalidate the window */
1444 InvalRect(&td->w->portRect);
1446 /* Display the window if needed */
1447 if (td->mapped) ShowWindow(td->w);
1449 /* Hack -- set "mapped" flag */
1450 t->mapped_flag = td->mapped;
1454 XDDSWCreateGWorldFromPict( &td->bufferPort, td );
1456 XDDSWLockFrame( td );
1458 /* if (err == noErr)
1469 static void Term_nuke_mac(term *t)
1482 static errr Term_user_mac(int n)
1496 static errr Term_xtra_mac_react(void)
1498 term_data *td = (term_data*)(Term->data);
1504 #ifdef ANGBAND_LITE_MAC
1508 #else /* ANGBAND_LITE_MAC */
1511 if (use_sound != arg_sound)
1514 use_sound = arg_sound;
1518 /* Handle transparency */
1519 if (((td == &data[0]) || (td == &data[6])) && (use_newstyle_graphics != arg_newstyle_graphics))
1523 if (globe_init() != 0)
1525 plog("Cannot initialize graphics!");
1526 arg_graphics = FALSE;
1527 arg_newstyle_graphics = FALSE;
1531 use_newstyle_graphics = arg_newstyle_graphics;
1533 /* Apply and Verify */
1534 term_data_check_size(td);
1536 /* Resize the window */
1537 term_data_resize(td);
1543 /* Handle graphics */
1544 if ((td == &data[0]) && (use_graphics != arg_graphics))
1546 /* Initialize graphics */
1548 if (!use_graphics && !frameP && (globe_init() != 0))
1551 plog("¥°¥é¥Õ¥£¥Ã¥¯¤Î½é´ü²½¤Ï½ÐÍè¤Þ¤»¤ó¤Ç¤·¤¿.");
1553 plog("Cannot initialize graphics!");
1555 arg_graphics = FALSE;
1559 use_graphics = arg_graphics;
1561 /* Apply and Verify */
1562 term_data_check_size(td);
1564 /* Resize the window */
1565 term_data_resize(td);
1571 #endif /* ANGBAND_LITE_MAC */
1579 * Do a "special thing"
1581 static errr Term_xtra_mac(int n, int v)
1583 term_data *td = (term_data*)(Term->data);
1591 case TERM_XTRA_NOISE:
1600 #ifdef ANGBAND_LITE_MAC
1604 #else /* ANGBAND_LITE_MAC */
1607 case TERM_XTRA_SOUND:
1617 /* Open the resource file */
1618 oldResFile = CurResFile();
1619 newResFile = OpenResFile(sound);
1621 /* Close the resource file */
1622 CloseResFile(newResFile);
1623 UseResFile(oldResFile);
1626 /* Get the proper sound name */
1627 sprintf((char*)sound + 1, "%.16s.wav", angband_sound_name[v]);
1628 sound[0] = strlen((char*)sound + 1);
1630 /* Obtain resource XXX XXX XXX */
1631 handle = Get1NamedResource('snd ', sound);
1632 if( handle == NULL || ext_sound )
1633 handle = GetNamedResource('snd ', sound);
1636 if (handle && soundmode[soundchoice[v]] == true)
1639 LoadResource(handle);
1642 /* Play sound (wait for completion) */
1643 SndPlay(nil, (SndListHandle)handle, true);
1645 /* Unlock and release */
1647 ReleaseResource(handle);
1653 #endif /* ANGBAND_LITE_MAC */
1655 /* Process random events */
1656 case TERM_XTRA_BORED:
1658 /* Process an event */
1659 (void)CheckEvents(0);
1665 /* Process pending events */
1666 case TERM_XTRA_EVENT:
1668 /* Process an event */
1669 (void)CheckEvents(v);
1675 /* Flush all pending events (if any) */
1676 case TERM_XTRA_FLUSH:
1678 /* Hack -- flush all events */
1679 while (CheckEvents(TRUE)) /* loop */;
1685 /* Hack -- Change the "soft level" */
1686 case TERM_XTRA_LEVEL:
1688 /* Activate if requested */
1689 if (v) activate(td->w);
1695 /* Clear the screen */
1696 case TERM_XTRA_CLEAR:
1698 /* No clipping XXX XXX XXX */
1699 ClipRect(&td->w->portRect);
1701 /* Erase the window */
1702 EraseRect(&td->w->portRect);
1705 term_data_color(td, TERM_WHITE);
1707 /* Frame the window in white */
1709 LineTo(0, td->size_hgt-1);
1710 LineTo(td->size_wid-1, td->size_hgt-1);
1711 LineTo(td->size_wid-1, 0);
1713 /* Clip to the new size */
1714 r.left = td->w->portRect.left + td->size_ow1;
1715 r.top = td->w->portRect.top + td->size_oh1;
1716 r.right = td->w->portRect.right - td->size_ow2;
1717 r.bottom = td->w->portRect.bottom - td->size_oh2;
1724 /* React to changes */
1725 case TERM_XTRA_REACT:
1727 /* React to changes */
1728 return (Term_xtra_mac_react());
1731 /* Delay (milliseconds) */
1732 case TERM_XTRA_DELAY:
1737 long m = TickCount() + (v * 60L) / 1000;
1740 while (TickCount() < m) /* loop */;
1755 * Low level graphics (Assumes valid input).
1756 * Draw a "cursor" at (x,y), using a "yellow box".
1757 * We are allowed to use "Term_grab()" to determine
1758 * the current screen contents (for inverting, etc).
1760 static errr Term_curs_mac(int x, int y)
1764 term_data *td = (term_data*)(Term->data);
1767 term_data_color(td, TERM_YELLOW);
1769 /* Frame the grid */
1770 r.left = x * td->tile_wid + td->size_ow1;
1771 r.right = r.left + td->tile_wid;
1772 r.top = y * td->tile_hgt + td->size_oh1;
1773 r.bottom = r.top + td->tile_hgt;
1782 * Low level graphics (Assumes valid input)
1784 * Erase "n" characters starting at (x,y)
1786 static errr Term_wipe_mac(int x, int y, int n)
1790 term_data *td = (term_data*)(Term->data);
1792 /* Erase the block of characters */
1793 r.left = x * td->tile_wid + td->size_ow1;
1794 r.right = r.left + n * td->tile_wid;
1795 r.top = y * td->tile_hgt + td->size_oh1;
1796 r.bottom = r.top + td->tile_hgt;
1805 * Low level graphics. Assumes valid input.
1807 * Draw several ("n") chars, with an attr, at a given location.
1809 static errr Term_text_mac(int x, int y, int n, byte a, const char *cp)
1813 term_data *td = (term_data*)(Term->data);
1816 term_data_color(td, (a & 0x0F));
1818 /* Starting pixel */
1819 xp = x * td->tile_wid + td->tile_o_x + td->size_ow1;
1820 yp = y * td->tile_hgt + td->tile_o_y + td->size_oh1;
1822 /* Move to the correct location */
1825 /* Draw the character */
1826 if (n == 1) DrawChar(*cp);
1828 /* Draw the string */
1829 else DrawText(cp, 0, n);
1837 * Low level graphics (Assumes valid input)
1839 * Erase "n" characters starting at (x,y)
1841 static errr Term_pict_mac(int x, int y, int n, const byte *ap, const char *cp)
1845 bool use_buffer = false;
1846 term_data *td = (term_data*)(Term->data);
1847 GDHandle saveGDevice;
1848 GWorldPtr saveGWorld;
1850 PixMapHandle PortPix;
1854 GetGWorld(&saveGWorld, &saveGDevice);
1858 /* Destination rectangle */
1859 r2.left = x * td->tile_wid + td->size_ow1;
1860 r2.right = r2.left + td->tile_wid;
1862 r2.bottom = r2.top + td->tile_hgt;
1865 SetGWorld(td->bufferPort, nil);
1866 PortPix = GetGWorldPixMap(td->bufferPort );
1867 LockPixels( PortPix );
1869 /* Instantiate font */
1870 TextFont(td->font_id);
1871 TextSize(td->font_size);
1872 TextFace(td->font_face);
1874 /* Restore colors */
1875 BackColor(blackColor);
1876 ForeColor(whiteColor);
1879 EraseRect(&td->bufferPort->portRect);
1885 /* Destination rectangle */
1886 r2.left = x * td->tile_wid + td->size_ow1;
1887 r2.right = r2.left + td->tile_wid;
1888 r2.top = y * td->tile_hgt + td->size_oh1;
1889 r2.bottom = r2.top + td->tile_hgt;
1891 /* no buffering, so we use the normal current port */
1896 /* Scan the input */
1897 for (i = 0; i < n; i++)
1904 #ifdef ANGBAND_LITE_MAC
1908 #else /* ANGBAND_LITE_MAC */
1910 /* Graphics -- if Available and Needed */
1911 if (use_graphics && ((td == &data[0]) || (td == &data[6])) &&
1912 ((byte)a & 0x80) && ((byte)c & 0x80))
1918 row = ((byte)a & 0x7F);
1919 col = ((byte)c & 0x7F);
1921 /* Source rectangle */
1922 r1.left = col * grafWidth;
1923 r1.top = row * grafHeight;
1924 r1.right = r1.left + grafWidth;
1925 r1.bottom = r1.top + grafHeight;
1927 /* Hardwire CopyBits */
1928 BackColor(whiteColor);
1929 ForeColor(blackColor);
1931 /* Draw the picture */
1933 BitMapPtr srcBitMap = (BitMapPtr)(frameP->framePix);
1934 BitMapPtr destBitMap;
1938 destBitMap = (BitMapPtr)(td->bufferPix);
1942 destBitMap = (BitMapPtr)&(td->w->portBits);
1945 /* draw transparent tile */
1946 /* BackColor is ignored and the destination is left untouched */
1947 BackColor(blackColor);
1948 CopyBits( srcBitMap, destBitMap, &r1, &r2, transparent, NULL );
1950 /* Restore colors */
1951 BackColor(blackColor);
1952 ForeColor(whiteColor);
1961 #endif /* ANGBAND_LITE_MAC */
1972 term_data_color(td, (a & 0x0F));
1974 /* Starting pixel */
1975 xp = r2.left + td->tile_o_x;
1976 yp = r2.top + td->tile_o_y;
1978 /* Move to the correct location */
1981 /* Draw the character */
1985 term_data_color(td, (a & 0x0F));
1987 /* Starting pixel */
1988 xp = r2.left + td->tile_o_x;
1991 /* Move to the correct location */
1995 /* Draw the character */
2000 r2.left += td->tile_wid;
2001 r2.right += td->tile_wid;
2003 /* Draw the character */
2010 r2.left += td->tile_wid;
2011 r2.right += td->tile_wid;
2016 /* Now we blast the buffer pixmap onto the screen in the right place */
2017 BitMapPtr srcBitMap = (BitMapPtr)(td->bufferPix);
2019 BitMapPtr destBitMap = (BitMapPtr)&(td->w->portBits);
2025 srcRect.left = x * td->tile_wid + td->size_ow1;
2027 srcRect.right = srcRect.left + (td->tile_wid * n);
2028 srcRect.bottom = td->tile_hgt;
2030 destRect.left = x * td->tile_wid + td->size_ow1;
2031 destRect.right = destRect.left + (td->tile_wid * n);
2032 destRect.top = y * td->tile_hgt + td->size_oh1;
2033 destRect.bottom = destRect.top + td->tile_hgt;
2035 UnlockPixels( PortPix );
2037 /* Restore GWorld */
2038 SetGWorld(saveGWorld, saveGDevice);
2040 /* Hardwire CopyBits */
2041 BackColor(whiteColor);
2042 ForeColor(blackColor);
2044 //CopyBits( srcBitMap, destBitMap, &srcRect, &destRect, srcCopy, NULL );
2045 CopyBits( (BitMapPtr)(td->bufferPix)
2046 , &(td->w->portBits), &srcRect, &destRect, srcCopy, NULL );
2048 /* Restore colors */
2049 BackColor(blackColor);
2050 ForeColor(whiteColor);
2063 * Create and initialize window number "i"
2065 static void term_data_link(int i)
2069 term_data *td = &data[i];
2074 /* Require mapped */
2075 if (!td->mapped) return;
2080 /* Initialize the term */
2081 term_init(td->t, td->cols, td->rows, td->keys);
2083 /* Use a "software" cursor */
2084 td->t->soft_cursor = TRUE;
2086 /* Erase with "white space" */
2087 td->t->attr_blank = TERM_WHITE;
2088 td->t->char_blank = ' ';
2090 /* Prepare the init/nuke hooks */
2091 td->t->init_hook = Term_init_mac;
2092 td->t->nuke_hook = Term_nuke_mac;
2094 /* Prepare the function hooks */
2095 td->t->user_hook = Term_user_mac;
2096 td->t->xtra_hook = Term_xtra_mac;
2097 td->t->wipe_hook = Term_wipe_mac;
2098 td->t->curs_hook = Term_curs_mac;
2099 td->t->text_hook = Term_text_mac;
2100 td->t->pict_hook = Term_pict_mac;
2102 /* Link the local structure */
2103 td->t->data = (vptr)(td);
2106 Term_activate(td->t);
2108 /* Global pointer */
2109 angband_term[i] = td->t;
2119 * Set the "current working directory" (also known as the "default"
2120 * volume/directory) to the location of the current application.
2122 * Code by: Maarten Hazewinkel (mmhazewi@cs.ruu.nl)
2124 * This function does not appear to work correctly with System 6.
2126 static void SetupAppDir(void)
2130 char errString[100];
2132 /* Get the location of the Angband executable */
2133 fcbBlock.ioCompletion = NULL;
2134 fcbBlock.ioNamePtr = NULL;
2135 fcbBlock.ioVRefNum = 0;
2136 fcbBlock.ioRefNum = CurResFile();
2137 fcbBlock.ioFCBIndx = 0;
2138 err = PBGetFCBInfo(&fcbBlock, FALSE);
2142 sprintf(errString, "PBGetFCBInfo ¥¨¥é¡¼ #%d.\r ½ªÎ»¤·¤Þ¤¹.", err);
2144 sprintf(errString, "Fatal PBGetFCBInfo Error #%d.\r Exiting.", err);
2146 mac_warning(errString);
2150 /* Extract the Vol and Dir */
2151 app_vol = fcbBlock.ioFCBVRefNum;
2152 app_dir = fcbBlock.ioFCBParID;
2154 /* Set the current working directory to that location */
2155 err = HSetVol(NULL, app_vol, app_dir);
2159 sprintf(errString, "HSetVol ¥¨¥é¡¼ #%d.\r ½ªÎ»¤·¤Þ¤¹.", err);
2161 sprintf(errString, "Fatal HSetVol Error #%d.\r Exiting.", err);
2163 mac_warning(errString);
2172 * Global "preference" file pointer
2177 * Read a "short" from the file
2179 static int getshort(void)
2183 if (0 == my_fgets(fff, buf, 256)) x = atoi(buf);
2188 * Dump a "short" to the file
2190 static void putshort(int x)
2192 fprintf(fff, "%d\n", x);
2198 * Write the "preference" data to the current "file"
2200 static void save_prefs(void)
2207 /*** The current version ***/
2209 putshort(VERSION_MAJOR);
2210 putshort(VERSION_MINOR);
2211 putshort(VERSION_PATCH);
2212 putshort(VERSION_EXTRA);
2214 putshort(arg_sound);
2215 putshort(arg_graphics);
2216 putshort(arg_newstyle_graphics);
2219 for( i = 0 ; i < 7 ; i++ )
2220 putshort(soundmode[i]);
2223 for (i = 0; i < MAX_TERM_DATA; i++)
2228 putshort(td->mapped);
2230 putshort(td->font_id);
2231 putshort(td->font_size);
2232 putshort(td->font_face);
2234 putshort(td->tile_wid);
2235 putshort(td->tile_hgt);
2240 putshort(td->r.left);
2241 putshort(td->r.top);
2247 * Load the preferences from the current "file"
2249 * XXX XXX XXX Being able to undefine various windows is
2250 * slightly bizarre, and may cause problems.
2252 static void load_prefs(void)
2256 int old_major, old_minor, old_patch, old_extra;
2261 /*** Version information ***/
2263 /* Preferences version */
2264 old_major = getshort();
2265 old_minor = getshort();
2266 old_patch = getshort();
2267 old_extra = getshort();
2269 /* Hack -- Verify or ignore */
2270 if ((old_major != VERSION_MAJOR) ||
2271 (old_minor != VERSION_MINOR) ||
2272 (old_patch != VERSION_PATCH) ||
2273 (old_extra != VERSION_EXTRA))
2277 mac_warning("¸Å¤¤½é´üÀßÄê¥Õ¥¡¥¤¥ë¤ò̵»ë¤·¤Þ¤¹.");
2279 mac_warning("Ignoring old preferences.");
2285 arg_sound = getshort();
2286 arg_graphics = getshort();
2287 arg_newstyle_graphics = getshort();
2288 use_newstyle_graphics = arg_newstyle_graphics;
2290 if (use_newstyle_graphics == true)
2292 ANGBAND_GRAF = "new";
2293 arg_newstyle_graphics = true;
2294 grafWidth = grafHeight = 16;
2299 ANGBAND_GRAF = "old";
2300 arg_newstyle_graphics = false;
2301 grafWidth = grafHeight = 8;
2306 for( i = 0 ; i < 7 ; i++ )
2307 soundmode[i] = getshort();
2310 m = GetMenuHandle(134); //m = GetMHandle(134);
2312 /* Item "arg_sound" */
2313 CheckItem(m, 1, arg_sound);
2315 /* Item "arg_graphics" */
2316 CheckItem(m, 2, arg_graphics);
2318 /* Item "arg_newstyle_graphics"*/
2319 CheckItem(m, 8, arg_newstyle_graphics);
2322 for (i = 0; i < MAX_TERM_DATA; i++)
2327 td->mapped = getshort();
2329 td->font_id = getshort();
2330 td->font_size = getshort();
2331 td->font_face = getshort();
2333 td->tile_wid = getshort();
2334 td->tile_hgt = getshort();
2336 td->cols = getshort();
2337 td->rows = getshort();
2339 td->r.left = getshort();
2340 td->r.top = getshort();
2343 if (feof(fff)) break;
2351 * Hack -- default data for a window
2353 static void term_data_hack(term_data *td)
2358 GetFNum( "\pÅùÉýÌÀÄ«", &fid); /* ¥Õ¥©¥ó¥È̾¤«¤éIDÈÖ¹æ¤òÄ´¤Ù¤ë */
2359 SetFScaleDisable( true );
2361 /* Default to Monaco font */
2362 GetFNum("\pmonaco", &fid);
2365 WIPE(td, term_data);
2370 /* Default borders */
2381 /* Default font size */
2384 /* Default font face */
2391 /* Default position */
2401 * Read the preference file, Create the windows.
2403 * We attempt to use "FindFolder()" to track down the preference file,
2404 * but if this fails, for any reason, we will try the "SysEnvirons()"
2405 * method, which may work better with System 6.
2407 static void init_windows(void)
2420 /*** Default values ***/
2422 /* Initialize (backwards) */
2423 for (i = MAX_TERM_DATA - 1; i >= 0; i--)
2436 s = angband_term_name[i];
2441 /* Maximal length */
2444 /* Copy the title */
2445 strncpy((char*)(td->title) + 1, s, n);
2447 /* Save the length */
2450 /* Tile the windows */
2451 td->r.left += (b * 30);
2452 td->r.top += (b * 30);
2459 /*** Load preferences ***/
2461 /* Assume failure */
2464 /* Assume failure */
2477 /* Find the folder */
2478 err = FindFolder(kOnSystemDisk, kPreferencesFolderType, kCreateFolder,
2484 /* Extract a path name */
2485 PathNameFromDirID(dirID, vref, (StringPtr)foo);
2487 /* Convert the string */
2488 ptocstr((StringPtr)foo);
2490 /* Append the preference file name */
2491 strcat(foo, PREF_FILE_NAME);
2493 /* Open the preference file */
2494 fff = fopen(foo, "r");
2501 #endif /* USE_SFL_CODE */
2507 HGetVol(0, &savev, &saved);
2509 /* Go to the "system" folder */
2510 SysEnvirons(curSysEnvVers, &env);
2511 SetVol(0, env.sysVRefNum);
2514 fff = fopen(PREF_FILE_NAME, "r");
2517 HSetVol(0, savev, saved);
2520 /* Load preferences */
2523 /* Load a real preference file */
2526 /* Close the file */
2531 /*** Instantiate ***/
2542 /* Link (backwards, for stacking order) */
2543 for (i = MAX_TERM_DATA - 1; i >= 0; i--)
2552 Term_activate(td->t);
2555 static void init_sound( void )
2559 SignedByte permission = fsRdPerm;
2565 /* Descend into "lib" folder */
2566 pb.ioCompletion = NULL;
2567 pb.ioNamePtr = "\plib";
2568 pb.ioVRefNum = app_vol;
2569 pb.ioDrDirID = app_dir;
2572 /* Check for errors */
2573 err = PBGetCatInfo((CInfoPBPtr)&pb, FALSE);
2576 if ((err == noErr) && (pb.ioFlAttrib & 0x10))
2578 /* Descend into "lib/save" folder */
2579 pb.ioCompletion = NULL;
2580 pb.ioNamePtr = "\pxtra";
2581 pb.ioVRefNum = app_vol;
2582 pb.ioDrDirID = pb.ioDrDirID;
2585 /* Check for errors */
2586 err = PBGetCatInfo((CInfoPBPtr)&pb, FALSE);
2589 if ((err == noErr) && (pb.ioFlAttrib & 0x10))
2591 /* Descend into "lib/save" folder */
2592 pb.ioCompletion = NULL;
2593 pb.ioNamePtr = "\psound";
2594 pb.ioVRefNum = app_vol;
2595 pb.ioDrDirID = pb.ioDrDirID;
2598 /* Check for errors */
2599 err = PBGetCatInfo((CInfoPBPtr)&pb, FALSE);
2602 if ((err == noErr) && (pb.ioFlAttrib & 0x10))
2604 ret = HOpenResFile( app_vol , pb.ioDrDirID , "\psound.rsrc" , permission );
2608 for( i = 0 ; i < 7 ; i++ )
2609 soundmode[i] = false;
2611 for( i = 1 ; i < SOUND_MAX ; i++ ){
2612 /* Get the proper sound name */
2613 sprintf((char*)sound + 1, "%.16s.wav", angband_sound_name[i]);
2614 sound[0] = strlen((char*)sound + 1);
2616 /* Obtain resource XXX XXX XXX */
2617 handle = Get1NamedResource('snd ', sound);
2618 if( handle == NULL || ext_sound )
2619 handle = GetNamedResource('snd ', sound);
2622 soundmode[soundchoice[i]] = true;
2635 static void init_chuukei( void )
2641 path_build(path, 1024, ANGBAND_DIR_XTRA, "chuukei.txt");
2643 fp = fopen(path, "r");
2648 if (fgets(tmp, 1024, fp)){
2650 int n = strlen(tmp);
2656 chuukei_server = TRUE;
2657 if(connect_chuukei_server(&tmp[2])<0){
2658 msg_print("connect fail");
2661 msg_print("connect");
2668 chuukei_client = TRUE;
2669 connect_chuukei_server(&tmp[2]);
2685 short InevrtCheck( DialogPtr targetDlg, short check )
2692 GetDialogItem( targetDlg, check, &itemType, &checkH, &box );
2693 result = (GetControlValue( (ControlHandle)checkH ) + 1 ) % 2;
2694 SetControlValue( (ControlHandle)checkH , result );
2702 short SetCheck( DialogPtr targetDlg, short check, long result )
2709 GetDialogItem( targetDlg, check, &itemType, &checkH, &box );
2710 SetControlValue( (ControlHandle)checkH , result );
2718 short GetCheck( DialogPtr targetDlg, short check )
2725 GetDialogItem( targetDlg, check, &itemType, &checkH, &box );
2726 result = GetControlValue( (ControlHandle)checkH );
2730 void SoundConfigDLog(void)
2737 dialog=GetNewDialog(131, 0, (WindowPtr)-1);
2738 SetDialogDefaultItem( dialog, ok );
2739 SetDialogCancelItem( dialog, cancel );
2740 for( i = 1 ; i < 7 ; i++ )
2741 SetCheck( dialog, i+2 , soundmode[i] );
2744 for( item_hit = 100 ; cancel < item_hit ; ){
2745 ModalDialog(0, &item_hit);
2749 for( i = 1 ; i < 7 ; i++ )
2750 soundmode[i] = GetCheck( dialog, i+2 );
2755 InevrtCheck( dialog, item_hit );
2758 DisposeDialog(dialog);
2766 static void save_pref_file(void)
2775 /* Assume failure */
2778 /* Assume failure */
2795 /* Find the folder */
2796 err = FindFolder(kOnSystemDisk, kPreferencesFolderType, kCreateFolder,
2802 /* Extract a path name */
2803 PathNameFromDirID(dirID, vref, (StringPtr)foo);
2805 /* Convert the string */
2806 ptocstr((StringPtr)foo);
2808 /* Append the preference file name */
2809 strcat(foo, PREF_FILE_NAME);
2811 /* Open the preference file */
2812 /* my_fopen set file type and file creator for MPW */
2813 fff = my_fopen(foo, "w");
2820 #endif /* USE_SFL_CODE */
2826 HGetVol(0, &savev, &saved);
2828 /* Go to "system" folder */
2829 SysEnvirons(curSysEnvVers, &env);
2830 SetVol(0, env.sysVRefNum);
2832 /* Open the preference file */
2833 /* my_fopen set file type and file creator for MPW */
2834 fff = fopen(PREF_FILE_NAME, "w");
2837 HSetVol(0, savev, saved);
2840 /* Save preferences */
2843 /* Write the preferences */
2854 * A simple "Yes/No" filter to parse "key press" events in dialog windows
2856 static pascal Boolean ynfilter(DialogPtr dialog, EventRecord *event, short *ip)
2858 /* Parse key press events */
2859 if (event->what == keyDown)
2864 /* Extract the pressed key */
2865 c = (event->message & charCodeMask);
2867 /* Accept "no" and <return> and <enter> */
2868 if ((c=='n') || (c=='N') || (c==13) || (c==3)) i = 1;
2871 else if ((c=='y') || (c=='Y')) i = 2;
2873 /* Handle "yes" or "no" */
2877 ControlHandle control;
2880 /* Get the button */
2881 GetDialogItem(dialog, i, &type, (Handle*)&control, &r); //GetDItem(dialog, i, &type, (Handle*)&control, &r);
2883 /* Blink button for 1/10 second */
2884 HiliteControl(control, 1);
2885 Term_xtra_mac(TERM_XTRA_DELAY, 100);
2886 HiliteControl(control, 0);
2900 * Handle menu: "File" + "New"
2902 static void do_menu_file_new(void)
2907 /* Game is in progress */
2908 game_in_progress = 1;
2922 * Handle menu: "File" + "Open"
2924 static void do_menu_file_open(bool all)
2938 /* vrefnum = GetSFCurVol(); */
2939 vrefnum = -*((short*)0x214);
2941 /* drefnum = GetSFCurDir(); */
2942 drefnum = *((long*)0x398);
2944 /* Descend into "lib" folder */
2945 pb.ioCompletion = NULL;
2946 pb.ioNamePtr = "\plib";
2947 pb.ioVRefNum = vrefnum;
2948 pb.ioDrDirID = drefnum;
2951 /* Check for errors */
2952 err = PBGetCatInfo((CInfoPBPtr)&pb, FALSE);
2955 if ((err == noErr) && (pb.ioFlAttrib & 0x10))
2957 /* Descend into "lib/save" folder */
2958 pb.ioCompletion = NULL;
2959 pb.ioNamePtr = "\psave";
2960 pb.ioVRefNum = vrefnum;
2961 pb.ioDrDirID = pb.ioDrDirID;
2964 /* Check for errors */
2965 err = PBGetCatInfo((CInfoPBPtr)&pb, FALSE);
2968 if ((err == noErr) && (pb.ioFlAttrib & 0x10))
2970 /* SetSFCurDir(pb.ioDrDirID); */
2971 *((long*)0x398) = pb.ioDrDirID;
2975 /* Window location */
2976 topleft.h = (qd.screenBits.bounds.left+qd.screenBits.bounds.right)/2-344/2;
2977 topleft.v = (2*qd.screenBits.bounds.top+qd.screenBits.bounds.bottom)/3-188/2;
2979 /* Allow "all" files */
2983 SFGetFile(topleft, "\p", NULL, -1, types, NULL, &reply);
2986 /* Allow "save" files */
2993 SFGetFile(topleft, "\p", NULL, 1, types, NULL, &reply);
2997 if (!reply.good) return;
2999 /* Extract textual file name for save file */
3000 GetWDInfo(reply.vRefNum, &vrefnum, &drefnum, &junk);
3001 refnum_to_name(savefile, drefnum, vrefnum, (char*)reply.fName);
3006 /* Game is in progress */
3007 game_in_progress = 1;
3021 * Handle the "open_when_ready" flag
3023 static void handle_open_when_ready(void)
3025 /* Check the flag XXX XXX XXX make a function for this */
3026 if (open_when_ready && initialized && !game_in_progress)
3029 open_when_ready = FALSE;
3031 /* Game is in progress */
3032 game_in_progress = 1;
3051 * Initialize the menus
3053 * Verify menus 128, 129, 130
3054 * Create menus 131, 132, 133, 134
3056 * The standard menus are:
3058 * Apple (128) = { About, -, ... }
3059 * File (129) = { New,Open,Import,Close,Save,-,Exit,Quit }
3060 * Edit (130) = { Cut, Copy, Paste, Clear } (?)
3061 * Font (131) = { Bold, Extend, -, Monaco, ..., -, ... }
3062 * Size (132) = { ... }
3063 * Window (133) = { Angband, Mirror, Recall, Choice,
3064 * Term-4, Term-5, Term-6, Term-7 }
3065 * Special (134) = { arg_sound, arg_graphics, -,
3066 * arg_fiddle, arg_wizard }
3068 static void init_menubar(void)
3079 /* Get the "apple" menu */
3082 /* Insert the menu */
3085 /* Add the DA's to the "apple" menu */
3086 AppendResMenu (m, 'DRVR'); //AddResMenu(m, 'DRVR');
3089 /* Get the "File" menu */
3092 /* Insert the menu */
3096 /* Get the "Edit" menu */
3099 /* Insert the menu */
3103 /* Make the "Font" menu */
3105 m = NewMenu(131, "\p¥Õ¥©¥ó¥È");
3107 m = NewMenu(131, "\pFont");
3110 /* Insert the menu */
3114 AppendMenu(m, "\pBold");
3117 AppendMenu(m, "\pWide");
3119 /* Add a separator */
3120 AppendMenu(m, "\p-");
3123 r.left = r.right = r.top = r.bottom = 0;
3125 /* Make the fake window */
3126 tmpw = NewWindow(0, &r, "\p", false, documentProc, 0, 0, 0);
3128 /* Activate the "fake" window */
3137 /* Add the fonts to the menu */
3138 AppendResMenu(m, 'FONT'); //AddResMenu(m, 'FONT');
3144 for (i = n; i >= 4; i--)
3149 /* Acquire the font name */
3150 /* GetMenuItemText(m, i, tmpName); */
3151 GetMenuItemText(m, i, tmpName); //GetItem(m, i, tmpName);
3153 /* Acquire the font index */
3154 GetFNum(tmpName, &fontNum);
3156 /* Apply the font index */
3159 /* Remove non-mono-spaced fonts */
3160 if ((CharWidth('i') != CharWidth('W')) || (CharWidth('W') == 0))
3162 /* Delete the menu item XXX XXX XXX */
3163 /* DeleteMenuItem(m, i); */
3164 DeleteMenuItem (m, i); //DelMenuItem(m, i);
3168 /* Destroy the old window */
3169 DisposeWindow(tmpw);
3171 /* Add a separator */
3172 AppendMenu(m, "\p-");
3174 /* Add the fonts to the menu */
3175 AppendResMenu (m, 'FONT'); //AddResMenu(m, 'FONT');
3178 /* Make the "Size" menu */
3180 m = NewMenu(132, "\p¥µ¥¤¥º");
3182 m = NewMenu(132, "\pSize");
3185 /* Insert the menu */
3188 /* Add some sizes (stagger choices) */
3189 for (i = 8; i <= 32; i += ((i / 16) + 1))
3194 sprintf((char*)buf + 1, "%d", i);
3195 buf[0] = strlen((char*)buf + 1);
3202 /* Make the "Windows" menu */
3204 m = NewMenu(133, "\p¥¦¥¤¥ó¥É¥¦");
3206 m = NewMenu(133, "\pWindows");
3209 /* Insert the menu */
3212 /* Default choices */
3213 for (i = 0; i < MAX_TERM_DATA; i++)
3217 /* Describe the item */
3218 sprintf((char*)buf + 1, "%.15s", angband_term_name[i]);
3219 buf[0] = strlen((char*)buf + 1);
3224 /* Command-Key shortcuts */
3225 if (i < 8) SetItemCmd(m, i + 1, '0' + i);
3229 /* Make the "Special" menu */
3231 m = NewMenu(134, "\pÆÃÊÌ");
3233 m = NewMenu(134, "\pSpecial");
3236 /* Insert the menu */
3239 /* Append the choices */
3241 AppendMenu(m, "\p¥µ¥¦¥ó¥É»ÈÍÑ");
3242 AppendMenu(m, "\p¥°¥é¥Õ¥£¥Ã¥¯»ÈÍÑ");
3243 AppendMenu(m, "\p-");
3244 AppendMenu(m, "\parg_fiddle");
3245 AppendMenu(m, "\parg_wizard");
3246 AppendMenu(m, "\p-");
3247 AppendMenu(m, "\p¥µ¥¦¥ó¥ÉÀßÄê...");
3248 AppendMenu(m, "\p16X16¥°¥é¥Õ¥£¥Ã¥¯");
3250 AppendMenu(m, "\parg_sound");
3251 AppendMenu(m, "\parg_graphics");
3252 AppendMenu(m, "\p-");
3253 AppendMenu(m, "\parg_fiddle");
3254 AppendMenu(m, "\parg_wizard");
3255 AppendMenu(m, "\p-");
3256 AppendMenu(m, "\pSound config");
3257 AppendMenu(m, "\pAdam Bolt tile");
3260 /* Make the "TileWidth" menu */
3262 m = NewMenu(135, "\p¥¿¥¤¥ëÉý");
3264 m = NewMenu(135, "\pTileWidth");
3267 /* Insert the menu */
3270 /* Add some sizes */
3271 for (i = 4; i <= 32; i++)
3276 sprintf((char*)buf + 1, "%d", i);
3277 buf[0] = strlen((char*)buf + 1);
3284 /* Make the "TileHeight" menu */
3286 m = NewMenu(136, "\p¥¿¥¤¥ë¹â");
3288 m = NewMenu(136, "\pTileHeight");
3291 /* Insert the menu */
3294 /* Add some sizes */
3295 for (i = 4; i <= 32; i++)
3300 sprintf((char*)buf + 1, "%d", i);
3301 buf[0] = strlen((char*)buf + 1);
3308 /* Update the menu bar */
3316 static void setup_menus(void)
3326 term_data *td = NULL;
3329 /* Relevant "term_data" */
3330 for (i = 0; i < MAX_TERM_DATA; i++)
3333 if (!data[i].t) continue;
3335 /* Notice the matching window */
3336 if (data[i].w == FrontWindow()) td = &data[i];
3341 m = GetMenuHandle(129); //m = GetMHandle(129);
3347 for (i = 1; i <= n; i++)
3351 CheckItem(m, i, FALSE);
3354 /* Enable "new"/"open..."/"import..." */
3355 if (initialized && !game_in_progress)
3362 /* Enable "close" */
3369 if (initialized && character_generated)
3378 /* EnableItem(m, 8); */
3383 m = GetMenuHandle(130); //m = GetMHandle(130);
3389 for (i = 1; i <= n; i++)
3393 CheckItem(m, i, FALSE);
3396 /* Enable "edit" options if "needed" */
3408 m = GetMenuHandle(131); //m = GetMHandle(131);
3414 for (i = 1; i <= n; i++)
3418 CheckItem(m, i, FALSE);
3421 /* Hack -- look cute XXX XXX */
3422 /* SetItemStyle(m, 1, bold); */
3424 /* Hack -- look cute XXX XXX */
3425 /* SetItemStyle(m, 2, extend); */
3433 /* Enable "extend" */
3436 /* Check the appropriate "bold-ness" */
3437 if (td->font_face & bold) CheckItem(m, 1, TRUE);
3439 /* Check the appropriate "wide-ness" */
3440 if (td->font_face & extend) CheckItem(m, 2, TRUE);
3443 for (i = 4; i <= n; i++)
3449 /* GetMenuItemText(m,i,s); */
3450 GetMenuItemText(m, i, s); //GetItem(m, i, s);
3453 /* Check active font */
3454 if (td->font_id == value) CheckItem(m, i, TRUE);
3460 m = GetMenuHandle(132); //m = GetMHandle(132);
3466 for (i = 1; i <= n; i++)
3470 CheckItem(m, i, FALSE);
3477 for (i = 1; i <= n; i++)
3480 /* GetMenuItemText(m,i,s); */
3481 GetMenuItemText(m, i, s); //GetItem(m, i, s);
3483 value = atoi((char*)(s+1));
3485 /* Enable the "real" sizes */
3486 if (RealFont(td->font_id, value)) EnableItem(m, i);
3488 /* Check the current size */
3489 if (td->font_size == value) CheckItem(m, i, TRUE);
3495 m = GetMenuHandle(133); //m = GetMHandle(133);
3500 /* Check active windows */
3501 for (i = 1; i <= n; i++)
3503 /* Check if needed */
3504 CheckItem(m, i, data[i-1].mapped);
3509 m = GetMenuHandle(134); //m = GetMHandle(134);
3515 for (i = 1; i <= n; i++)
3519 CheckItem(m, i, FALSE);
3522 /* Item "arg_sound" */
3524 CheckItem(m, 1, arg_sound);
3526 /* Item "arg_graphics" */
3528 CheckItem(m, 2, arg_graphics);
3530 /* Item "arg_fiddle" */
3532 CheckItem(m, 4, arg_fiddle);
3534 /* Item "arg_wizard" */
3536 CheckItem(m, 5, arg_wizard);
3538 /* Item "SoundSetting" */
3541 /* Item NewStyle Graphics */
3543 CheckItem(m, 8, use_newstyle_graphics);
3546 /* EnableItem(m, 9); */
3549 /* TileWidth menu */
3550 m = GetMenuHandle(135); //m = GetMHandle(135);
3556 for (i = 1; i <= n; i++)
3560 CheckItem(m, i, FALSE);
3567 for (i = 1; i <= n; i++)
3570 /* GetMenuItemText(m,i,s); */
3571 GetMenuItemText(m, i, s); //GetItem(m, i, s);
3573 value = atoi((char*)(s+1));
3578 /* Check the current size */
3579 if (td->tile_wid == value) CheckItem(m, i, TRUE);
3584 /* TileHeight menu */
3585 m = GetMenuHandle(136); //m = GetMHandle(136);
3591 for (i = 1; i <= n; i++)
3595 CheckItem(m, i, FALSE);
3602 for (i = 1; i <= n; i++)
3605 /* GetMenuItemText(m,i,s); */
3606 GetMenuItemText(m, i, s); //GetItem(m, i, s);
3608 value = atoi((char*)(s+1));
3613 /* Check the current size */
3614 if (td->tile_hgt == value) CheckItem(m, i, TRUE);
3621 * Process a menu selection (see above)
3623 * Hack -- assume that invalid menu selections are disabled above,
3624 * which I have been informed may not be reliable. XXX XXX XXX
3626 static void menu(long mc)
3630 int menuid, selection;
3632 static unsigned char s[1000];
3636 term_data *td = NULL;
3641 /* Analyze the menu command */
3642 menuid = HiWord(mc);
3643 selection = LoWord(mc);
3646 /* Find the window */
3647 for (i = 0; i < MAX_TERM_DATA; i++)
3649 /* Skip dead windows */
3650 if (!data[i].t) continue;
3652 /* Notice matches */
3653 if (data[i].w == FrontWindow()) td = &data[i];
3657 /* Branch on the menu */
3663 /* About Angband... */
3670 dialog=GetNewDialog(128, 0, (WindowPtr)-1);
3673 center_rect(&r, &qd.screenBits.bounds);
3674 MoveWindow(dialog, r.left, r.top, 1);
3676 ModalDialog(0, &item_hit);
3677 DisposeDialog(dialog); //DisposDialog(dialog);
3681 /* Desk accessory */
3682 /* GetMenuItemText(GetMHandle(128),selection,s); */
3683 GetMenuItemText(GetMenuHandle(128), selection, s); //GetItem(GetMHandle(128), selection, s);
3703 do_menu_file_open(FALSE);
3710 do_menu_file_open(TRUE);
3724 td->t->mapped_flag = FALSE;
3726 /* Hide the window */
3737 plog("º£¤Ï¥»¡¼¥Ö¤¹¤ë¤³¤È¤Ï½ÐÍè¤Þ¤»¤ó¡£");
3739 plog("You may not do that right now.");
3744 /* Hack -- Forget messages */
3747 /* Hack -- Save the game */
3748 do_cmd_save_game(FALSE);
3753 /* Quit (with save) */
3756 /* Save the game (if necessary) */
3757 if (game_in_progress && character_generated)
3761 plog("º£¤Ï¥»¡¼¥Ö¤¹¤ë¤³¤È¤Ï½ÐÍè¤Þ¤»¤ó¡£");
3763 plog("You may not do that right now.");
3767 /* Hack -- Forget messages */
3771 do_cmd_save_game(FALSE);
3792 /* Require a window */
3801 /* Toggle the "bold" setting */
3804 /* Toggle the setting */
3805 if (td->font_face & bold)
3807 td->font_face &= ~bold;
3811 td->font_face |= bold;
3814 /* Tile Width Hight Init */
3815 td->tile_wid = td->tile_hgt = 0;
3817 /* Apply and Verify */
3818 term_data_check_font(td);
3819 term_data_check_size(td);
3821 /* Resize and Redraw */
3822 term_data_resize(td);
3823 term_data_redraw(td);
3828 /* Toggle the "wide" setting */
3831 /* Toggle the setting */
3832 if (td->font_face & extend)
3834 td->font_face &= ~extend;
3838 td->font_face |= extend;
3841 /* Tile Width Hight Init */
3842 td->tile_wid = td->tile_hgt = 0;
3844 /* Apply and Verify */
3845 term_data_check_font(td);
3846 term_data_check_size(td);
3848 /* Resize and Redraw */
3849 term_data_resize(td);
3850 term_data_redraw(td);
3855 /* Get a new font name */
3856 /* GetMenuItemText(GetMHandle(131), selection, s); */
3857 GetMenuItemText(GetMenuHandle(131), selection, s); //GetItem(GetMHandle(131), selection, s);
3860 /* Save the new font id */
3863 /* Current size is bad for new font */
3864 if (!RealFont(td->font_id, td->font_size))
3866 /* Find similar size */
3867 for (i = 1; i <= 32; i++)
3869 /* Adjust smaller */
3870 if (td->font_size - i >= 8)
3872 if (RealFont(td->font_id, td->font_size - i))
3880 if (td->font_size + i <= 128)
3882 if (RealFont(td->font_id, td->font_size + i))
3891 /* Tile Width Hight Init */
3892 td->tile_wid = td->tile_hgt = 0;
3894 /* Apply and Verify */
3895 term_data_check_font(td);
3896 term_data_check_size(td);
3898 /* Resize and Redraw */
3899 term_data_resize(td);
3900 term_data_redraw(td);
3902 /* Restore the window */
3919 /* GetMenuItemText(GetMHandle(132), selection, s); */
3920 GetMenuItemText(GetMenuHandle(132), selection, s); //GetItem(GetMHandle(132), selection, s);
3922 td->font_size = atoi((char*)(s+1));
3924 /* Tile Width Hight Init */
3925 td->tile_wid = td->tile_hgt = 0;
3927 /* Apply and Verify */
3928 term_data_check_font(td);
3929 term_data_check_size(td);
3931 /* Resize and Redraw */
3932 term_data_resize(td);
3933 term_data_redraw(td);
3947 /* Check legality of choice */
3948 if ((i < 0) || (i >= MAX_TERM_DATA)) break;
3950 /* Obtain the window */
3960 td->t->mapped_flag = TRUE;
3962 /* Show the window */
3965 /* Bring to the front */
3966 SelectWindow(td->w);
3978 /* Toggle arg_sound */
3979 arg_sound = !arg_sound;
3981 /* React to changes */
3982 Term_xtra(TERM_XTRA_REACT, 0);
3989 /* Toggle arg_graphics */
3990 arg_graphics = !arg_graphics;
3992 /* Hack -- Force redraw */
3993 Term_key_push(KTRL('R'));
4000 arg_fiddle = !arg_fiddle;
4006 arg_wizard = !arg_wizard;
4016 if (streq(ANGBAND_GRAF, "old"))
4018 ANGBAND_GRAF = "new";
4019 arg_newstyle_graphics = true;
4020 grafWidth = grafHeight = 16;
4025 ANGBAND_GRAF = "old";
4026 arg_newstyle_graphics = false;
4027 grafWidth = grafHeight = 8;
4031 /* Hack -- Force redraw */
4032 Term_key_push(KTRL('R'));
4040 /* TileWidth menu */
4051 /* GetMenuItemText(GetMHandle(135), selection, s); */
4052 GetMenuItemText(GetMenuHandle(135), selection, s); //GetItem(GetMHandle(135), selection, s);
4054 td->tile_wid = atoi((char*)(s+1));
4056 /* Apply and Verify */
4057 term_data_check_size(td);
4059 /* Resize and Redraw */
4060 term_data_resize(td);
4061 term_data_redraw(td);
4069 /* TileHeight menu */
4080 /* GetMenuItemText(GetMHandle(136), selection, s); */
4081 GetMenuItemText(GetMenuHandle(136), selection, s); //GetItem(GetMHandle(136), selection, s);
4083 td->tile_hgt = atoi((char*)(s+1));
4085 /* Apply and Verify */
4086 term_data_check_size(td);
4088 /* Resize and Redraw */
4089 term_data_resize(td);
4090 term_data_redraw(td);
4100 /* Clean the menu */
4109 * Check for extra required parameters -- From "Maarten Hazewinkel"
4111 static OSErr CheckRequiredAEParams(const AppleEvent *theAppleEvent)
4114 DescType returnedType;
4117 aeError = AEGetAttributePtr(theAppleEvent, keyMissedKeywordAttr, typeWildCard,
4118 &returnedType, NULL, 0, &actualSize);
4120 if (aeError == errAEDescNotFound) return (noErr);
4122 if (aeError == noErr) return (errAEParamMissed);
4129 * Apple Event Handler -- Open Application
4131 static pascal OSErr AEH_Start(const AppleEvent *theAppleEvent,
4132 const AppleEvent *reply, long handlerRefCon)
4134 #pragma unused(reply, handlerRefCon)
4136 return (CheckRequiredAEParams(theAppleEvent));
4141 * Apple Event Handler -- Quit Application
4143 static pascal OSErr AEH_Quit(const AppleEvent *theAppleEvent,
4144 const AppleEvent *reply, long handlerRefCon)
4146 #pragma unused(reply, handlerRefCon)
4149 quit_when_ready = TRUE;
4151 /* Check arguments */
4152 return (CheckRequiredAEParams(theAppleEvent));
4157 * Apple Event Handler -- Print Documents
4159 static pascal OSErr AEH_Print(const AppleEvent *theAppleEvent,
4160 const AppleEvent *reply, long handlerRefCon)
4162 #pragma unused(theAppleEvent, reply, handlerRefCon)
4164 return (errAEEventNotHandled);
4169 * Apple Event Handler by Steve Linberg (slinberg@crocker.com).
4171 * The old method of opening savefiles from the finder does not work
4172 * on the Power Macintosh, because CountAppFiles and GetAppFiles,
4173 * used to return information about the selected document files when
4174 * an application is launched, are part of the Segment Loader, which
4175 * is not present in the RISC OS due to the new memory architecture.
4177 * The "correct" way to do this is with AppleEvents. The following
4178 * code is modeled on the "Getting Files Selected from the Finder"
4179 * snippet from Think Reference 2.0. (The prior sentence could read
4180 * "shamelessly swiped & hacked")
4182 static pascal OSErr AEH_Open(AppleEvent *theAppleEvent,
4183 AppleEvent* reply, long handlerRefCon)
4185 #pragma unused(reply, handlerRefCon)
4192 DescType returnedType;
4196 /* Put the direct parameter (a descriptor list) into a docList */
4197 err = AEGetParamDesc(theAppleEvent, keyDirectObject, typeAEList, &docList);
4198 if (err) return err;
4201 * We ignore the validity check, because we trust the FInder, and we only
4202 * allow one savefile to be opened, so we ignore the depth of the list.
4205 err = AEGetNthPtr(&docList, 1L, typeFSS, &keywd,
4206 &returnedType, (Ptr) &myFSS, sizeof(myFSS), &actualSize);
4207 if (err) return err;
4209 /* Only needed to check savefile type below */
4210 err = FSpGetFInfo(&myFSS, &myFileInfo);
4213 sprintf(foo, "Arg! FSpGetFInfo failed with code %d", err);
4218 /* Ignore non 'SAVE' files */
4219 if (myFileInfo.fdType != 'SAVE') return noErr;
4221 /* XXX XXX XXX Extract a file name */
4222 PathNameFromDirID(myFSS.parID, myFSS.vRefNum, (StringPtr)savefile);
4223 pstrcat((StringPtr)savefile, (StringPtr)&myFSS.name);
4225 /* Convert the string */
4226 ptocstr((StringPtr)savefile);
4228 /* Delay actual open */
4229 open_when_ready = TRUE;
4232 err = AEDisposeDesc(&docList);
4244 * Macintosh modifiers (event.modifier & ccc):
4245 * cmdKey, optionKey, shiftKey, alphaLock, controlKey
4248 * Macintosh Keycodes (0-63 normal, 64-95 keypad, 96-127 extra):
4293 * Optimize non-blocking calls to "CheckEvents()"
4294 * Idea from "Maarten Hazewinkel <mmhazewi@cs.ruu.nl>"
4296 #define EVENT_TICKS 6
4300 * Check for Events, return TRUE if we process any
4302 * Hack -- Handle AppleEvents if appropriate (ignore result code).
4304 static bool CheckEvents(bool wait)
4320 term_data *td = NULL;
4324 static huge lastTicks = 0L;
4327 /* Access the clock */
4328 curTicks = TickCount();
4330 /* Hack -- Allow efficient checking for non-pending events */
4331 if (!wait && (curTicks < lastTicks + EVENT_TICKS)) return (FALSE);
4333 /* Timestamp last check */
4334 lastTicks = curTicks;
4336 /* Let the "system" run */
4339 /* Get an event (or null) */
4340 GetNextEvent(everyEvent, &event);
4342 /* Hack -- Nothing is ready yet */
4343 if (event.what == nullEvent) return (FALSE);
4346 /* Analyze the event */
4354 w = (WindowPtr)event.message;
4365 /* Extract the window */
4366 w = (WindowPtr)event.message;
4368 /* Find the window */
4369 for (i = 0; i < MAX_TERM_DATA; i++)
4371 /* Skip dead windows */
4372 if (!data[i].t) continue;
4374 /* Notice matches */
4375 if (data[i].w == w) td = &data[i];
4378 /* Hack XXX XXX XXX */
4382 /* Redraw the window */
4383 if (td) term_data_redraw(td);
4391 /* Extract some modifiers */
4392 mc = (event.modifiers & controlKey) ? TRUE : FALSE;
4393 ms = (event.modifiers & shiftKey) ? TRUE : FALSE;
4394 mo = (event.modifiers & optionKey) ? TRUE : FALSE;
4395 mx = (event.modifiers & cmdKey) ? TRUE : FALSE;
4397 /* Keypress: (only "valid" if ck < 96) */
4398 ch = (event.message & charCodeMask) & 255;
4400 /* Keycode: see table above */
4401 ck = ((event.message & keyCodeMask) >> 8) & 255;
4403 /* Command + "normal key" -> menu action */
4404 if (mx && (ck < 64))
4406 /* Hack -- Prepare the menus */
4409 /* Mega-Hack -- allow easy exit if nothing to save */
4410 /* if (!character_generated && (ch=='Q' || ch=='q')) ch = 'e'; */
4412 /* Run the Menu-Handler */
4415 /* Turn off the menus */
4423 /* Hide the mouse pointer */
4426 /* Normal key -> simple keypress */
4429 /* Enqueue the keypress */
4433 /* Hack -- normal "keypad keys" -> special keypress */
4434 else if (!mc && !ms && !mo && !mx && (ck < 96))
4436 /* Hack -- "enter" is confused */
4437 if (ck == 76) ch = '\n';
4439 /* Send control-caret as a trigger */
4442 /* Send the "ascii" keypress */
4446 /* Bizarre key -> encoded keypress */
4449 /* Hack -- introduce with control-underscore */
4452 /* Send some modifier keys */
4453 if (mc) Term_keypress('C');
4454 if (ms) Term_keypress('S');
4455 if (mo) Term_keypress('O');
4456 if (mx) Term_keypress('X');
4458 /* Hack -- Downshift and encode the keycode */
4459 Term_keypress('0' + (ck - 64) / 10);
4460 Term_keypress('0' + (ck - 64) % 10);
4462 /* Hack -- Terminate the sequence */
4463 /* MPW can generate 10 or 13 for keycode of '\r' */
4464 /* -noMapCR option swaps '\r' and '\n' */
4465 Term_keypress('\r');
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 /* Mark ourself as the file creator */
5127 /* Default to saving a "text" file */
5131 #if defined(__MWERKS__)
5133 /* Obtian a "Universal Procedure Pointer" */
5134 ynfilterUPP = NewModalFilterProc(ynfilter);
5139 /* Hook in some "z-virt.c" hooks */
5140 rnfree_aux = hook_rnfree;
5141 ralloc_aux = hook_ralloc;
5142 rpanic_aux = hook_rpanic;
5144 /* Hooks in some "z-util.c" hooks */
5145 plog_aux = hook_plog;
5146 quit_aux = hook_quit;
5147 core_aux = hook_core;
5149 BackColor(blackColor);
5150 ForeColor(whiteColor);
5152 /* Show the "watch" cursor */
5153 SetCursor(*(GetCursor(watchCursor)));
5155 /* Prepare the menubar */
5158 /* Prepare the windows */
5163 /* Hack -- process all events */
5164 while (CheckEvents(TRUE)) /* loop */;
5166 /* Reset the cursor */
5167 SetCursor(&qd.arrow);
5170 /* Mega-Hack -- Allocate a "lifeboat" */
5171 lifeboat = NewPtr(16384);
5173 /* Note the "system" */
5174 ANGBAND_SYS = "mac";
5176 ANGBAND_GRAF = "new";
5178 ANGBAND_GRAF = "old";
5188 /* Hack -- process all events */
5189 while (CheckEvents(TRUE)) /* loop */;
5192 /* We are now initialized */
5196 /* Handle "open_when_ready" */
5197 handle_open_when_ready();
5203 /* Prompt the user */
5205 prt("'¥Õ¥¡¥¤¥ë'¥á¥Ë¥å¡¼¤è¤ê'¿·µ¬'¤Þ¤¿¤Ï'³«¤¯...'¤òÁªÂò¤·¤Æ¤¯¤À¤µ¤¤¡£", 23, 10);
5207 prt("[Choose 'New' or 'Open' from the 'File' menu]", 23, 15);
5210 /* Flush the prompt */
5214 /* Hack -- Process Events Forever */
5215 while (TRUE) CheckEvents(TRUE);