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 */
855 /* Enforce minimal size */
856 if (td->cols < 80) td->cols = 80;
857 if (td->rows < 24) td->rows = 24;
860 /* Allow small windows for the rest */
864 if ((td->cols < 60) || (td->rows < 18))
870 if (td->cols < 1) td->cols = 1;
871 if (td->rows < 1) td->rows = 1;
875 /* Minimal tile size */
876 if (td->tile_wid < 4) td->tile_wid = 4;
877 if (td->tile_hgt < 4) td->tile_hgt = 4;
879 /* Default tile offsets */
880 td->tile_o_x = (td->tile_wid - td->font_wid) / 2;
881 td->tile_o_y = (td->tile_hgt - td->font_hgt) / 2;
883 /* Minimal tile offsets */
884 if (td->tile_o_x < 0) td->tile_o_x = 0;
885 if (td->tile_o_y < 0) td->tile_o_y = 0;
887 /* Apply font offsets */
888 td->tile_o_x += td->font_o_x;
889 td->tile_o_y += td->font_o_y;
891 /* Calculate full window size */
892 td->size_wid = td->cols * td->tile_wid + td->size_ow1 + td->size_ow2;
893 td->size_hgt = td->rows * td->tile_hgt + td->size_oh1 + td->size_oh2;
896 if (td->r.top > qd.screenBits.bounds.bottom - td->size_hgt)
898 td->r.top = qd.screenBits.bounds.bottom - td->size_hgt;
902 if (td->r.top < qd.screenBits.bounds.top + 30)
904 td->r.top = qd.screenBits.bounds.top + 30;
907 /* Verify the left */
908 if (td->r.left > qd.screenBits.bounds.right - td->size_wid)
910 td->r.left = qd.screenBits.bounds.right - td->size_wid;
913 /* Verify the left */
914 if (td->r.left < qd.screenBits.bounds.left)
916 td->r.left = qd.screenBits.bounds.left;
919 /* Calculate bottom right corner */
920 td->r.right = td->r.left + td->size_wid;
921 td->r.bottom = td->r.top + td->size_hgt;
923 /* Assume no graphics */
924 td->t->always_pict = FALSE;
926 #ifdef ANGBAND_LITE_MAC
930 #else /* ANGBAND_LITE_MAC */
932 /* Handle graphics */
933 td->t->higher_pict = TRUE;
935 #endif /* ANGBAND_LITE_MAC */
938 static OSErr XDDSWUpDateGWorldFromPict( term_data *td );
940 * Hack -- resize a term_data
942 * This should normally be followed by "term_data_resize()"
944 static void term_data_resize(term_data *td)
946 /* Actually resize the window */
947 SizeWindow(td->w, td->size_wid, td->size_hgt, 0);
949 XDDSWUpDateGWorldFromPict( td );
955 * Hack -- redraw a term_data
957 * Note that "Term_redraw()" calls "TERM_XTRA_CLEAR"
959 static void term_data_redraw(term_data *td)
963 /* Activate the term */
964 Term_activate(td->t);
966 /* Redraw the contents */
969 /* Flush the output */
972 /* Restore the old term */
975 /* No need to redraw */
976 ValidRect(&td->w->portRect);
982 #ifdef ANGBAND_LITE_MAC
986 #else /* ANGBAND_LITE_MAC */
993 static int pictID = 1001; /* 8x8 tiles; 16x16 tiles are 1002 */
995 static int grafWidth = 8; /* Always equal to grafHeight */
996 static int grafHeight = 8; /* Either 8 or 16 */
998 static bool arg_newstyle_graphics;
999 static bool use_newstyle_graphics;
1004 typedef struct FrameRec FrameRec;
1009 * - GWorld for the frame image
1010 * - Handle to pix map (saved for unlocking/locking)
1011 * - Pointer to color pix map (valid only while locked)
1015 GWorldPtr framePort;
1016 PixMapHandle framePixHndl;
1023 * The global picture data
1025 static FrameRec *frameP = NULL;
1031 static void BenSWLockFrame(FrameRec *srcFrameP)
1033 PixMapHandle pixMapH;
1035 pixMapH = GetGWorldPixMap(srcFrameP->framePort);
1036 (void)LockPixels(pixMapH);
1037 HLockHi((Handle)pixMapH);
1038 srcFrameP->framePixHndl = pixMapH;
1039 srcFrameP->framePix = (PixMapPtr)StripAddress(*(Handle)pixMapH);
1046 static void XDDSWLockFrame( term_data *td )
1048 PixMapHandle pixMapH;
1050 pixMapH = GetGWorldPixMap(td->bufferPort);
1051 (void)LockPixels(pixMapH);
1052 HLockHi((Handle)pixMapH);
1053 td->bufferPixHndl = pixMapH;
1054 td->bufferPix = (PixMapPtr)*(Handle)pixMapH;
1061 static void BenSWUnlockFrame(FrameRec *srcFrameP)
1063 if (srcFrameP->framePort != NULL)
1065 HUnlock((Handle)srcFrameP->framePixHndl);
1066 UnlockPixels(srcFrameP->framePixHndl);
1069 srcFrameP->framePix = NULL;
1076 static void XDDSWUnlockFrame( term_data *td )
1078 if (td->bufferPort != NULL)
1080 HUnlock((Handle)td->bufferPixHndl);
1081 UnlockPixels(td->bufferPixHndl);
1084 td->bufferPix = NULL;
1087 static OSErr BenSWCreateGWorldFromPict(
1088 GWorldPtr *pictGWorld,
1092 GWorldPtr saveGWorld;
1093 GDHandle saveGDevice;
1094 GWorldPtr tempGWorld;
1103 depth = data[0].pixelDepth;
1106 theGDH = data[0].theGDH;
1108 /* Obtain size rectangle */
1109 pictRect = (**pictH).picFrame;
1110 OffsetRect(&pictRect, -pictRect.left, -pictRect.top);
1112 /* Create a GWorld */
1113 err = NewGWorld(&tempGWorld, depth, &pictRect, nil,
1114 theGDH, noNewDevice);
1123 *pictGWorld = tempGWorld;
1126 GetGWorld(&saveGWorld, &saveGDevice);
1129 SetGWorld(tempGWorld, nil);
1131 /* Dump the pict into the GWorld */
1132 (void)LockPixels(GetGWorldPixMap(tempGWorld));
1133 EraseRect(&pictRect);
1134 DrawPicture(pictH, &pictRect);
1135 UnlockPixels(GetGWorldPixMap(tempGWorld));
1137 /* Restore GWorld */
1138 SetGWorld(saveGWorld, saveGDevice);
1145 static OSErr XDDSWCreateGWorldFromPict(
1146 GWorldPtr *pictGWorld,
1150 GWorldPtr saveGWorld;
1151 GDHandle saveGDevice;
1152 GWorldPtr tempGWorld;
1163 depth = td->pixelDepth;
1166 theGDH = td->theGDH;
1168 /* Obtain size rectangle */
1170 pictRect.right = td->size_wid;
1172 pictRect.bottom = td->tile_hgt;
1174 /* Create a GWorld */
1175 err = NewGWorld(&tempGWorld, 0, &pictRect, 0, 0, 0);
1184 *pictGWorld = tempGWorld;
1187 GetGWorld(&saveGWorld, &saveGDevice);
1190 SetGWorld(tempGWorld, nil);
1192 /* Dump the pict into the GWorld
1193 (void)LockPixels(GetGWorldPixMap(tempGWorld));
1194 EraseRect(&pictRect);
1195 // DrawPicture(pictH, &pictRect);
1196 UnlockPixels(GetGWorldPixMap(tempGWorld));
1198 /* Restore GWorld */
1199 SetGWorld(saveGWorld, saveGDevice);
1205 static OSErr XDDSWUpDateGWorldFromPict( term_data *td )
1207 GWorldPtr saveGWorld;
1208 GDHandle saveGDevice;
1213 GWorldFlags errflag;
1217 if( td->bufferPort == NULL )
1220 depth = td->pixelDepth;
1223 theGDH = td->theGDH;
1225 /* Obtain size rectangle */
1228 pictRect.right = td->size_wid;
1229 pictRect.bottom = td->tile_hgt;
1231 XDDSWUnlockFrame(td);
1233 errflag = UpdateGWorld( &td->bufferPort, depth, &pictRect, 0, 0, 0);
1235 if( errflag & gwFlagErr ){
1241 /* GetGWorld(&saveGWorld, &saveGDevice); */
1244 /* SetGWorld(td->bufferPort, nil); */
1246 /* Dump the pict into the GWorld */
1247 /* (void)LockPixels(GetGWorldPixMap(td->bufferPort)); */
1248 /* EraseRect(&td->bufferPort->portRect); */
1250 /* UnlockPixels(GetGWorldPixMap(td->bufferPort)); */
1252 /* Restore GWorld */
1253 /* SetGWorld(saveGWorld, saveGDevice); */
1258 * Init the global "frameP"
1261 static errr globe_init(void)
1265 GWorldPtr tempPictGWorldP;
1269 /* Use window XXX XXX XXX */
1273 /* Get the pict resource */
1274 newPictH = GetPicture(pictID);
1276 /* Analyze result */
1277 err = (newPictH ? 0 : -1);
1284 err = BenSWCreateGWorldFromPict(&tempPictGWorldP, newPictH);
1286 /* Release resource */
1287 ReleaseResource((Handle)newPictH);
1292 /* Create the frame */
1293 frameP = (FrameRec*)NewPtrClear((Size)sizeof(FrameRec));
1295 /* Analyze result */
1296 err = (frameP ? 0 : -1);
1302 frameP->framePort = tempPictGWorldP;
1305 BenSWLockFrame(frameP);
1316 * Nuke the global "frameP"
1318 static errr globe_nuke(void)
1324 BenSWUnlockFrame(frameP);
1326 /* Dispose of the GWorld */
1327 DisposeGWorld(frameP->framePort);
1329 /* Dispose of the memory */
1330 DisposePtr((Ptr)frameP);
1337 FlushEvents(everyEvent, 0);
1344 #endif /* ANGBAND_LITE_MAC */
1348 /*** Support for the "z-term.c" package ***/
1352 * Initialize a new Term
1354 * Note also the "window type" called "noGrowDocProc", which might be more
1355 * appropriate for the main "screen" window.
1357 * Note the use of "srcCopy" mode for optimized screen writes.
1359 static void Term_init_mac(term *t)
1361 term_data *td = (term_data*)(t->data);
1363 static RGBColor black = {0x0000,0x0000,0x0000};
1364 static RGBColor white = {0xFFFF,0xFFFF,0xFFFF};
1366 #ifdef ANGBAND_LITE_MAC
1368 /* Make the window */
1369 td->w = NewWindow(0, &td->r, td->title, 0, noGrowDocProc, (WindowPtr)-1, 1, 0L);
1371 #else /* ANGBAND_LITE_MAC */
1373 /* Make the window */
1374 td->w = NewCWindow(0, &td->r, td->title, 0, documentProc, (WindowPtr)-1, 1, 0L);
1376 #endif /* ANGBAND_LITE_MAC */
1378 /* Activate the window */
1381 /* Erase behind words */
1384 /* Apply and Verify */
1385 term_data_check_font(td);
1386 term_data_check_size(td);
1388 /* Resize the window */
1389 term_data_resize(td);
1391 #ifdef ANGBAND_LITE_MAC
1393 /* Prepare the colors (base colors) */
1394 BackColor(blackColor);
1395 ForeColor(whiteColor);
1397 #else /* ANGBAND_LITE_MAC */
1399 /* Prepare the colors (real colors) */
1400 RGBBackColor(&black);
1401 RGBForeColor(&white);
1408 GDHandle currentGDH;
1409 GWorldPtr windowGWorld;
1410 PixMapHandle basePixMap;
1412 /* Obtain the rect */
1413 tempRect = td->w->portRect;
1415 /* Obtain the global rect */
1416 globalRect = tempRect;
1417 LocalToGlobal((Point*)&globalRect.top);
1418 LocalToGlobal((Point*)&globalRect.bottom);
1420 /* Obtain the proper GDH */
1421 mainGDH = GetMaxDevice(&globalRect);
1423 /* Extract GWorld and GDH */
1424 GetGWorld(&windowGWorld, ¤tGDH);
1426 /* Obtain base pixmap */
1427 basePixMap = (**mainGDH).gdPMap;
1429 /* Save pixel depth */
1430 td->pixelDepth = (**basePixMap).pixelSize;
1432 /* Save Window GWorld */
1433 td->theGWorld = windowGWorld;
1435 /* Save Window GDH */
1436 td->theGDH = currentGDH;
1439 td->mainSWGDH = mainGDH;
1442 #endif /* ANGBAND_LITE_MAC */
1444 /* Clip to the window */
1445 ClipRect(&td->w->portRect);
1447 /* Erase the window */
1448 EraseRect(&td->w->portRect);
1450 /* Invalidate the window */
1451 InvalRect(&td->w->portRect);
1453 /* Display the window if needed */
1454 if (td->mapped) ShowWindow(td->w);
1456 /* Hack -- set "mapped" flag */
1457 t->mapped_flag = td->mapped;
1461 XDDSWCreateGWorldFromPict( &td->bufferPort, td );
1463 XDDSWLockFrame( td );
1465 /* if (err == noErr)
1476 static void Term_nuke_mac(term *t)
1489 static errr Term_user_mac(int n)
1503 static errr Term_xtra_mac_react(void)
1505 term_data *td = (term_data*)(Term->data);
1511 #ifdef ANGBAND_LITE_MAC
1515 #else /* ANGBAND_LITE_MAC */
1518 if (use_sound != arg_sound)
1521 use_sound = arg_sound;
1525 /* Handle transparency */
1526 if (use_newstyle_graphics != arg_newstyle_graphics)
1530 if (globe_init() != 0)
1532 plog("Cannot initialize graphics!");
1533 arg_graphics = FALSE;
1534 arg_newstyle_graphics = FALSE;
1538 use_newstyle_graphics = arg_newstyle_graphics;
1540 /* Apply and Verify */
1541 term_data_check_size(td);
1543 /* Resize the window */
1544 term_data_resize(td);
1550 /* Handle graphics */
1551 if (use_graphics != arg_graphics)
1553 /* Initialize graphics */
1555 if (!use_graphics && !frameP && (globe_init() != 0))
1558 plog("¥°¥é¥Õ¥£¥Ã¥¯¤Î½é´ü²½¤Ï½ÐÍè¤Þ¤»¤ó¤Ç¤·¤¿.");
1560 plog("Cannot initialize graphics!");
1562 arg_graphics = FALSE;
1566 use_graphics = arg_graphics;
1568 /* Apply and Verify */
1569 term_data_check_size(td);
1571 /* Resize the window */
1572 term_data_resize(td);
1578 #endif /* ANGBAND_LITE_MAC */
1586 * Do a "special thing"
1588 static errr Term_xtra_mac(int n, int v)
1590 term_data *td = (term_data*)(Term->data);
1598 case TERM_XTRA_NOISE:
1607 #ifdef ANGBAND_LITE_MAC
1611 #else /* ANGBAND_LITE_MAC */
1614 case TERM_XTRA_SOUND:
1624 /* Open the resource file */
1625 oldResFile = CurResFile();
1626 newResFile = OpenResFile(sound);
1628 /* Close the resource file */
1629 CloseResFile(newResFile);
1630 UseResFile(oldResFile);
1633 /* Get the proper sound name */
1634 sprintf((char*)sound + 1, "%.16s.wav", angband_sound_name[v]);
1635 sound[0] = strlen((char*)sound + 1);
1637 /* Obtain resource XXX XXX XXX */
1638 handle = Get1NamedResource('snd ', sound);
1639 if( handle == NULL || ext_sound )
1640 handle = GetNamedResource('snd ', sound);
1643 if (handle && soundmode[soundchoice[v]] == true)
1646 LoadResource(handle);
1649 /* Play sound (wait for completion) */
1650 SndPlay(nil, (SndListHandle)handle, true);
1652 /* Unlock and release */
1654 ReleaseResource(handle);
1660 #endif /* ANGBAND_LITE_MAC */
1662 /* Process random events */
1663 case TERM_XTRA_BORED:
1665 /* Process an event */
1666 (void)CheckEvents(0);
1672 /* Process pending events */
1673 case TERM_XTRA_EVENT:
1675 /* Process an event */
1676 (void)CheckEvents(v);
1682 /* Flush all pending events (if any) */
1683 case TERM_XTRA_FLUSH:
1685 /* Hack -- flush all events */
1686 while (CheckEvents(TRUE)) /* loop */;
1692 /* Hack -- Change the "soft level" */
1693 case TERM_XTRA_LEVEL:
1695 /* Activate if requested */
1696 if (v) activate(td->w);
1702 /* Clear the screen */
1703 case TERM_XTRA_CLEAR:
1705 /* No clipping XXX XXX XXX */
1706 ClipRect(&td->w->portRect);
1708 /* Erase the window */
1709 EraseRect(&td->w->portRect);
1712 term_data_color(td, TERM_WHITE);
1714 /* Frame the window in white */
1716 LineTo(0, td->size_hgt-1);
1717 LineTo(td->size_wid-1, td->size_hgt-1);
1718 LineTo(td->size_wid-1, 0);
1720 /* Clip to the new size */
1721 r.left = td->w->portRect.left + td->size_ow1;
1722 r.top = td->w->portRect.top + td->size_oh1;
1723 r.right = td->w->portRect.right - td->size_ow2;
1724 r.bottom = td->w->portRect.bottom - td->size_oh2;
1731 /* React to changes */
1732 case TERM_XTRA_REACT:
1734 /* React to changes */
1735 return (Term_xtra_mac_react());
1738 /* Delay (milliseconds) */
1739 case TERM_XTRA_DELAY:
1744 long m = TickCount() + (v * 60L) / 1000;
1747 while (TickCount() < m) /* loop */;
1762 * Low level graphics (Assumes valid input).
1763 * Draw a "cursor" at (x,y), using a "yellow box".
1764 * We are allowed to use "Term_grab()" to determine
1765 * the current screen contents (for inverting, etc).
1767 static errr Term_curs_mac(int x, int y)
1771 term_data *td = (term_data*)(Term->data);
1774 term_data_color(td, TERM_YELLOW);
1776 /* Frame the grid */
1777 r.left = x * td->tile_wid + td->size_ow1;
1778 r.right = r.left + td->tile_wid;
1779 r.top = y * td->tile_hgt + td->size_oh1;
1780 r.bottom = r.top + td->tile_hgt;
1783 if (x + 1 < Term->wid &&
1784 ((use_bigtile && Term->old->a[y][x+1] == 255)
1785 || (iskanji(Term->old->c[y][x]) && !(Term->old->a[y][x] & 0x80))))
1787 if (use_bigtile && x + 1 < Term->wid && Term->old->a[y][x+1] == 255)
1789 r.right += td->tile_wid;
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;
1867 PixMapHandle PortPix;
1871 GetGWorld(&saveGWorld, &saveGDevice);
1875 /* Destination rectangle */
1876 r2.left = x * td->tile_wid + td->size_ow1;
1877 r2.right = r2.left + td->tile_wid;
1879 r2.bottom = r2.top + td->tile_hgt;
1882 SetGWorld(td->bufferPort, nil);
1883 PortPix = GetGWorldPixMap(td->bufferPort );
1884 LockPixels( PortPix );
1886 /* Instantiate font */
1887 TextFont(td->font_id);
1888 TextSize(td->font_size);
1889 TextFace(td->font_face);
1891 /* Restore colors */
1892 BackColor(blackColor);
1893 ForeColor(whiteColor);
1896 EraseRect(&td->bufferPort->portRect);
1902 /* Destination rectangle */
1903 r2.left = x * td->tile_wid + td->size_ow1;
1904 r2.right = r2.left + td->tile_wid;
1905 r2.top = y * td->tile_hgt + td->size_oh1;
1906 r2.bottom = r2.top + td->tile_hgt;
1908 /* no buffering, so we use the normal current port */
1913 /* Scan the input */
1914 for (i = 0; i < n; i++)
1921 #ifdef ANGBAND_LITE_MAC
1925 #else /* ANGBAND_LITE_MAC */
1927 /* Graphics -- if Available and Needed */
1929 ((byte)a & 0x80) && ((byte)c & 0x80))
1935 row = ((byte)a & 0x7F);
1936 col = ((byte)c & 0x7F);
1938 /* Source rectangle */
1939 r1.left = col * grafWidth;
1940 r1.top = row * grafHeight;
1941 r1.right = r1.left + grafWidth;
1942 r1.bottom = r1.top + grafHeight;
1944 /* Hardwire CopyBits */
1945 BackColor(whiteColor);
1946 ForeColor(blackColor);
1948 /* Draw the picture */
1950 BitMapPtr srcBitMap = (BitMapPtr)(frameP->framePix);
1951 BitMapPtr destBitMap;
1955 destBitMap = (BitMapPtr)(td->bufferPix);
1959 destBitMap = (BitMapPtr)&(td->w->portBits);
1962 /* draw transparent tile */
1963 /* BackColor is ignored and the destination is left untouched */
1964 BackColor(blackColor);
1966 if (use_bigtile) r2.right += td->tile_wid;
1968 CopyBits( srcBitMap, destBitMap, &r1, &r2, transparent, NULL );
1969 if (use_bigtile) r2.right -= td->tile_wid;
1971 /* Restore colors */
1972 BackColor(blackColor);
1973 ForeColor(whiteColor);
1982 #endif /* ANGBAND_LITE_MAC */
1993 term_data_color(td, (a & 0x0F));
1995 /* Starting pixel */
1996 xp = r2.left + td->tile_o_x;
1997 yp = r2.top + td->tile_o_y;
1999 /* Move to the correct location */
2002 /* Draw the character */
2006 term_data_color(td, (a & 0x0F));
2008 /* Starting pixel */
2009 xp = r2.left + td->tile_o_x;
2012 /* Move to the correct location */
2016 /* Draw the character */
2021 r2.left += td->tile_wid;
2022 r2.right += td->tile_wid;
2024 /* Draw the character */
2031 r2.left += td->tile_wid;
2032 r2.right += td->tile_wid;
2037 /* Now we blast the buffer pixmap onto the screen in the right place */
2038 BitMapPtr srcBitMap = (BitMapPtr)(td->bufferPix);
2040 BitMapPtr destBitMap = (BitMapPtr)&(td->w->portBits);
2046 srcRect.left = x * td->tile_wid + td->size_ow1;
2048 srcRect.right = srcRect.left + (td->tile_wid * n);
2049 srcRect.bottom = td->tile_hgt;
2051 destRect.left = x * td->tile_wid + td->size_ow1;
2052 destRect.right = destRect.left + (td->tile_wid * n);
2053 destRect.top = y * td->tile_hgt + td->size_oh1;
2054 destRect.bottom = destRect.top + td->tile_hgt;
2058 srcRect.right += td->tile_wid * n;
2059 destRect.right += td->tile_wid * n;
2062 UnlockPixels( PortPix );
2064 /* Restore GWorld */
2065 SetGWorld(saveGWorld, saveGDevice);
2067 /* Hardwire CopyBits */
2068 BackColor(whiteColor);
2069 ForeColor(blackColor);
2071 //CopyBits( srcBitMap, destBitMap, &srcRect, &destRect, srcCopy, NULL );
2072 CopyBits( (BitMapPtr)(td->bufferPix)
2073 , &(td->w->portBits), &srcRect, &destRect, srcCopy, NULL );
2075 /* Restore colors */
2076 BackColor(blackColor);
2077 ForeColor(whiteColor);
2090 * Create and initialize window number "i"
2092 static void term_data_link(int i)
2096 term_data *td = &data[i];
2101 /* Require mapped */
2102 if (!td->mapped) return;
2107 /* Initialize the term */
2108 term_init(td->t, td->cols, td->rows, td->keys);
2110 /* Use a "software" cursor */
2111 td->t->soft_cursor = TRUE;
2113 /* Erase with "white space" */
2114 td->t->attr_blank = TERM_WHITE;
2115 td->t->char_blank = ' ';
2117 /* Prepare the init/nuke hooks */
2118 td->t->init_hook = Term_init_mac;
2119 td->t->nuke_hook = Term_nuke_mac;
2121 /* Prepare the function hooks */
2122 td->t->user_hook = Term_user_mac;
2123 td->t->xtra_hook = Term_xtra_mac;
2124 td->t->wipe_hook = Term_wipe_mac;
2125 td->t->curs_hook = Term_curs_mac;
2126 td->t->text_hook = Term_text_mac;
2127 td->t->pict_hook = Term_pict_mac;
2129 /* Link the local structure */
2130 td->t->data = (vptr)(td);
2133 Term_activate(td->t);
2135 /* Global pointer */
2136 angband_term[i] = td->t;
2146 * Set the "current working directory" (also known as the "default"
2147 * volume/directory) to the location of the current application.
2149 * Code by: Maarten Hazewinkel (mmhazewi@cs.ruu.nl)
2151 * This function does not appear to work correctly with System 6.
2153 static void SetupAppDir(void)
2157 char errString[100];
2159 /* Get the location of the Angband executable */
2160 fcbBlock.ioCompletion = NULL;
2161 fcbBlock.ioNamePtr = NULL;
2162 fcbBlock.ioVRefNum = 0;
2163 fcbBlock.ioRefNum = CurResFile();
2164 fcbBlock.ioFCBIndx = 0;
2165 err = PBGetFCBInfo(&fcbBlock, FALSE);
2169 sprintf(errString, "PBGetFCBInfo ¥¨¥é¡¼ #%d.\r ½ªÎ»¤·¤Þ¤¹.", err);
2171 sprintf(errString, "Fatal PBGetFCBInfo Error #%d.\r Exiting.", err);
2173 mac_warning(errString);
2177 /* Extract the Vol and Dir */
2178 app_vol = fcbBlock.ioFCBVRefNum;
2179 app_dir = fcbBlock.ioFCBParID;
2181 /* Set the current working directory to that location */
2182 err = HSetVol(NULL, app_vol, app_dir);
2186 sprintf(errString, "HSetVol ¥¨¥é¡¼ #%d.\r ½ªÎ»¤·¤Þ¤¹.", err);
2188 sprintf(errString, "Fatal HSetVol Error #%d.\r Exiting.", err);
2190 mac_warning(errString);
2199 * Global "preference" file pointer
2204 * Read a "short" from the file
2206 static int getshort(void)
2210 if (0 == my_fgets(fff, buf, 256)) x = atoi(buf);
2215 * Dump a "short" to the file
2217 static void putshort(int x)
2219 fprintf(fff, "%d\n", x);
2225 * Write the "preference" data to the current "file"
2227 static void save_prefs(void)
2234 /*** The current version ***/
2236 putshort(FAKE_VERSION);
2237 putshort(FAKE_VER_MAJOR);
2238 putshort(FAKE_VER_MINOR);
2239 putshort(FAKE_VER_PATCH);
2241 putshort(arg_sound);
2242 putshort(arg_graphics);
2243 putshort(arg_newstyle_graphics);
2244 putshort(arg_bigtile);
2247 for( i = 0 ; i < 7 ; i++ )
2248 putshort(soundmode[i]);
2251 for (i = 0; i < MAX_TERM_DATA; i++)
2256 putshort(td->mapped);
2258 putshort(td->font_id);
2259 putshort(td->font_size);
2260 putshort(td->font_face);
2262 putshort(td->tile_wid);
2263 putshort(td->tile_hgt);
2268 putshort(td->r.left);
2269 putshort(td->r.top);
2275 * Load the preferences from the current "file"
2277 * XXX XXX XXX Being able to undefine various windows is
2278 * slightly bizarre, and may cause problems.
2280 static void load_prefs(void)
2284 int old_version, old_major, old_minor, old_patch;
2289 /*** Version information ***/
2291 /* Preferences version */
2292 old_version = getshort();
2293 old_major = getshort();
2294 old_minor = getshort();
2295 old_patch = getshort();
2297 /* Hack -- Verify or ignore */
2298 if ((old_version != FAKE_VERSION) ||
2299 (old_major != FAKE_VER_MAJOR) ||
2300 (old_minor != FAKE_VER_MINOR) ||
2301 (old_patch != FAKE_VER_PATCH))
2305 mac_warning("¸Å¤¤½é´üÀßÄê¥Õ¥¡¥¤¥ë¤ò̵»ë¤·¤Þ¤¹.");
2307 mac_warning("Ignoring old preferences.");
2313 arg_sound = getshort();
2314 arg_graphics = getshort();
2315 arg_newstyle_graphics = getshort();
2316 use_newstyle_graphics = arg_newstyle_graphics;
2318 if (use_newstyle_graphics == true)
2320 ANGBAND_GRAF = "new";
2321 arg_newstyle_graphics = true;
2322 grafWidth = grafHeight = 16;
2327 ANGBAND_GRAF = "old";
2328 arg_newstyle_graphics = false;
2329 grafWidth = grafHeight = 8;
2333 arg_bigtile = getshort();
2334 use_bigtile = arg_bigtile;
2337 for( i = 0 ; i < 7 ; i++ )
2338 soundmode[i] = getshort();
2341 m = GetMenuHandle(134); //m = GetMHandle(134);
2343 /* Item "arg_sound" */
2344 CheckItem(m, 1, arg_sound);
2346 /* Item "arg_graphics" */
2347 CheckItem(m, 2, arg_graphics);
2349 /* Item "arg_newstyle_graphics"*/
2350 CheckItem(m, 8, arg_newstyle_graphics);
2353 for (i = 0; i < MAX_TERM_DATA; i++)
2358 td->mapped = getshort();
2360 td->font_id = getshort();
2361 td->font_size = getshort();
2362 td->font_face = getshort();
2364 td->tile_wid = getshort();
2365 td->tile_hgt = getshort();
2367 td->cols = getshort();
2368 td->rows = getshort();
2370 td->r.left = getshort();
2371 td->r.top = getshort();
2374 if (feof(fff)) break;
2382 * Hack -- default data for a window
2384 static void term_data_hack(term_data *td)
2389 GetFNum( "\pÅùÉýÌÀÄ«", &fid); /* ¥Õ¥©¥ó¥È̾¤«¤éIDÈÖ¹æ¤òÄ´¤Ù¤ë */
2390 SetFScaleDisable( true );
2392 /* Default to Monaco font */
2393 GetFNum("\pmonaco", &fid);
2396 WIPE(td, term_data);
2401 /* Default borders */
2412 /* Default font size */
2415 /* Default font face */
2422 /* Default position */
2432 * Read the preference file, Create the windows.
2434 * We attempt to use "FindFolder()" to track down the preference file,
2435 * but if this fails, for any reason, we will try the "SysEnvirons()"
2436 * method, which may work better with System 6.
2438 static void init_windows(void)
2451 /*** Default values ***/
2453 /* Initialize (backwards) */
2454 for (i = MAX_TERM_DATA - 1; i >= 0; i--)
2467 s = angband_term_name[i];
2472 /* Maximal length */
2475 /* Copy the title */
2476 strncpy((char*)(td->title) + 1, s, n);
2478 /* Save the length */
2481 /* Tile the windows */
2482 td->r.left += (b * 30);
2483 td->r.top += (b * 30);
2490 /*** Load preferences ***/
2492 /* Assume failure */
2495 /* Assume failure */
2508 /* Find the folder */
2509 err = FindFolder(kOnSystemDisk, kPreferencesFolderType, kCreateFolder,
2515 /* Extract a path name */
2516 PathNameFromDirID(dirID, vref, (StringPtr)foo);
2518 /* Convert the string */
2519 ptocstr((StringPtr)foo);
2521 /* Append the preference file name */
2522 strcat(foo, PREF_FILE_NAME);
2524 /* Open the preference file */
2525 fff = fopen(foo, "r");
2532 #endif /* USE_SFL_CODE */
2538 HGetVol(0, &savev, &saved);
2540 /* Go to the "system" folder */
2541 SysEnvirons(curSysEnvVers, &env);
2542 SetVol(0, env.sysVRefNum);
2545 fff = fopen(PREF_FILE_NAME, "r");
2548 HSetVol(0, savev, saved);
2551 /* Load preferences */
2554 /* Load a real preference file */
2557 /* Close the file */
2562 /*** Instantiate ***/
2573 /* Link (backwards, for stacking order) */
2574 for (i = MAX_TERM_DATA - 1; i >= 0; i--)
2583 Term_activate(td->t);
2586 static void init_sound( void )
2590 SignedByte permission = fsRdPerm;
2596 /* Descend into "lib" folder */
2597 pb.ioCompletion = NULL;
2598 pb.ioNamePtr = "\plib";
2599 pb.ioVRefNum = app_vol;
2600 pb.ioDrDirID = app_dir;
2603 /* Check for errors */
2604 err = PBGetCatInfo((CInfoPBPtr)&pb, FALSE);
2607 if ((err == noErr) && (pb.ioFlAttrib & 0x10))
2609 /* Descend into "lib/save" folder */
2610 pb.ioCompletion = NULL;
2611 pb.ioNamePtr = "\pxtra";
2612 pb.ioVRefNum = app_vol;
2613 pb.ioDrDirID = pb.ioDrDirID;
2616 /* Check for errors */
2617 err = PBGetCatInfo((CInfoPBPtr)&pb, FALSE);
2620 if ((err == noErr) && (pb.ioFlAttrib & 0x10))
2622 /* Descend into "lib/save" folder */
2623 pb.ioCompletion = NULL;
2624 pb.ioNamePtr = "\psound";
2625 pb.ioVRefNum = app_vol;
2626 pb.ioDrDirID = pb.ioDrDirID;
2629 /* Check for errors */
2630 err = PBGetCatInfo((CInfoPBPtr)&pb, FALSE);
2633 if ((err == noErr) && (pb.ioFlAttrib & 0x10))
2635 ret = HOpenResFile( app_vol , pb.ioDrDirID , "\psound.rsrc" , permission );
2639 for( i = 0 ; i < 7 ; i++ )
2640 soundmode[i] = false;
2642 for( i = 1 ; i < SOUND_MAX ; i++ ){
2643 /* Get the proper sound name */
2644 sprintf((char*)sound + 1, "%.16s.wav", angband_sound_name[i]);
2645 sound[0] = strlen((char*)sound + 1);
2647 /* Obtain resource XXX XXX XXX */
2648 handle = Get1NamedResource('snd ', sound);
2649 if( handle == NULL || ext_sound )
2650 handle = GetNamedResource('snd ', sound);
2653 soundmode[soundchoice[i]] = true;
2666 static void init_chuukei( void )
2672 path_build(path, 1024, ANGBAND_DIR_XTRA, "chuukei.txt");
2674 fp = fopen(path, "r");
2679 if (fgets(tmp, 1024, fp)){
2681 int n = strlen(tmp);
2687 chuukei_server = TRUE;
2688 if(connect_chuukei_server(&tmp[2])<0){
2689 msg_print("connect fail");
2692 msg_print("connect");
2699 chuukei_client = TRUE;
2700 connect_chuukei_server(&tmp[2]);
2716 short InevrtCheck( DialogPtr targetDlg, short check )
2723 GetDialogItem( targetDlg, check, &itemType, &checkH, &box );
2724 result = (GetControlValue( (ControlHandle)checkH ) + 1 ) % 2;
2725 SetControlValue( (ControlHandle)checkH , result );
2733 short SetCheck( DialogPtr targetDlg, short check, long result )
2740 GetDialogItem( targetDlg, check, &itemType, &checkH, &box );
2741 SetControlValue( (ControlHandle)checkH , result );
2749 short GetCheck( DialogPtr targetDlg, short check )
2756 GetDialogItem( targetDlg, check, &itemType, &checkH, &box );
2757 result = GetControlValue( (ControlHandle)checkH );
2761 void SoundConfigDLog(void)
2768 dialog=GetNewDialog(131, 0, (WindowPtr)-1);
2769 SetDialogDefaultItem( dialog, ok );
2770 SetDialogCancelItem( dialog, cancel );
2771 for( i = 1 ; i < 7 ; i++ )
2772 SetCheck( dialog, i+2 , soundmode[i] );
2775 for( item_hit = 100 ; cancel < item_hit ; ){
2776 ModalDialog(0, &item_hit);
2780 for( i = 1 ; i < 7 ; i++ )
2781 soundmode[i] = GetCheck( dialog, i+2 );
2786 InevrtCheck( dialog, item_hit );
2789 DisposeDialog(dialog);
2797 static void save_pref_file(void)
2806 /* Assume failure */
2809 /* Assume failure */
2826 /* Find the folder */
2827 err = FindFolder(kOnSystemDisk, kPreferencesFolderType, kCreateFolder,
2833 /* Extract a path name */
2834 PathNameFromDirID(dirID, vref, (StringPtr)foo);
2836 /* Convert the string */
2837 ptocstr((StringPtr)foo);
2839 /* Append the preference file name */
2840 strcat(foo, PREF_FILE_NAME);
2842 /* Open the preference file */
2843 /* my_fopen set file type and file creator for MPW */
2844 fff = my_fopen(foo, "w");
2851 #endif /* USE_SFL_CODE */
2857 HGetVol(0, &savev, &saved);
2859 /* Go to "system" folder */
2860 SysEnvirons(curSysEnvVers, &env);
2861 SetVol(0, env.sysVRefNum);
2863 /* Open the preference file */
2864 /* my_fopen set file type and file creator for MPW */
2865 fff = fopen(PREF_FILE_NAME, "w");
2868 HSetVol(0, savev, saved);
2871 /* Save preferences */
2874 /* Write the preferences */
2885 * A simple "Yes/No" filter to parse "key press" events in dialog windows
2887 static pascal Boolean ynfilter(DialogPtr dialog, EventRecord *event, short *ip)
2889 /* Parse key press events */
2890 if (event->what == keyDown)
2895 /* Extract the pressed key */
2896 c = (event->message & charCodeMask);
2898 /* Accept "no" and <return> and <enter> */
2899 if ((c=='n') || (c=='N') || (c==13) || (c==3)) i = 1;
2902 else if ((c=='y') || (c=='Y')) i = 2;
2904 /* Handle "yes" or "no" */
2908 ControlHandle control;
2911 /* Get the button */
2912 GetDialogItem(dialog, i, &type, (Handle*)&control, &r); //GetDItem(dialog, i, &type, (Handle*)&control, &r);
2914 /* Blink button for 1/10 second */
2915 HiliteControl(control, 1);
2916 Term_xtra_mac(TERM_XTRA_DELAY, 100);
2917 HiliteControl(control, 0);
2931 * Handle menu: "File" + "New"
2933 static void do_menu_file_new(void)
2938 /* Game is in progress */
2939 game_in_progress = 1;
2953 * Handle menu: "File" + "Open"
2955 static void do_menu_file_open(bool all)
2969 /* vrefnum = GetSFCurVol(); */
2970 vrefnum = -*((short*)0x214);
2972 /* drefnum = GetSFCurDir(); */
2973 drefnum = *((long*)0x398);
2975 /* Descend into "lib" folder */
2976 pb.ioCompletion = NULL;
2977 pb.ioNamePtr = "\plib";
2978 pb.ioVRefNum = vrefnum;
2979 pb.ioDrDirID = drefnum;
2982 /* Check for errors */
2983 err = PBGetCatInfo((CInfoPBPtr)&pb, FALSE);
2986 if ((err == noErr) && (pb.ioFlAttrib & 0x10))
2988 /* Descend into "lib/save" folder */
2989 pb.ioCompletion = NULL;
2990 pb.ioNamePtr = "\psave";
2991 pb.ioVRefNum = vrefnum;
2992 pb.ioDrDirID = pb.ioDrDirID;
2995 /* Check for errors */
2996 err = PBGetCatInfo((CInfoPBPtr)&pb, FALSE);
2999 if ((err == noErr) && (pb.ioFlAttrib & 0x10))
3001 /* SetSFCurDir(pb.ioDrDirID); */
3002 *((long*)0x398) = pb.ioDrDirID;
3006 /* Window location */
3007 topleft.h = (qd.screenBits.bounds.left+qd.screenBits.bounds.right)/2-344/2;
3008 topleft.v = (2*qd.screenBits.bounds.top+qd.screenBits.bounds.bottom)/3-188/2;
3010 /* Allow "all" files */
3014 SFGetFile(topleft, "\p", NULL, -1, types, NULL, &reply);
3017 /* Allow "save" files */
3024 SFGetFile(topleft, "\p", NULL, 1, types, NULL, &reply);
3028 if (!reply.good) return;
3030 /* Extract textual file name for save file */
3031 GetWDInfo(reply.vRefNum, &vrefnum, &drefnum, &junk);
3032 refnum_to_name(savefile, drefnum, vrefnum, (char*)reply.fName);
3037 /* Game is in progress */
3038 game_in_progress = 1;
3052 * Handle the "open_when_ready" flag
3054 static void handle_open_when_ready(void)
3056 /* Check the flag XXX XXX XXX make a function for this */
3057 if (open_when_ready && initialized && !game_in_progress)
3060 open_when_ready = FALSE;
3062 /* Game is in progress */
3063 game_in_progress = 1;
3082 * Initialize the menus
3084 * Verify menus 128, 129, 130
3085 * Create menus 131, 132, 133, 134
3087 * The standard menus are:
3089 * Apple (128) = { About, -, ... }
3090 * File (129) = { New,Open,Import,Close,Save,-,Exit,Quit }
3091 * Edit (130) = { Cut, Copy, Paste, Clear } (?)
3092 * Font (131) = { Bold, Extend, -, Monaco, ..., -, ... }
3093 * Size (132) = { ... }
3094 * Window (133) = { Angband, Mirror, Recall, Choice,
3095 * Term-4, Term-5, Term-6, Term-7 }
3096 * Special (134) = { arg_sound, arg_graphics, -,
3097 * arg_fiddle, arg_wizard }
3099 static void init_menubar(void)
3110 /* Get the "apple" menu */
3113 /* Insert the menu */
3116 /* Add the DA's to the "apple" menu */
3117 AppendResMenu (m, 'DRVR'); //AddResMenu(m, 'DRVR');
3120 /* Get the "File" menu */
3123 /* Insert the menu */
3127 /* Get the "Edit" menu */
3130 /* Insert the menu */
3134 /* Make the "Font" menu */
3136 m = NewMenu(131, "\p¥Õ¥©¥ó¥È");
3138 m = NewMenu(131, "\pFont");
3141 /* Insert the menu */
3145 AppendMenu(m, "\pBold");
3148 AppendMenu(m, "\pWide");
3150 /* Add a separator */
3151 AppendMenu(m, "\p-");
3154 r.left = r.right = r.top = r.bottom = 0;
3156 /* Make the fake window */
3157 tmpw = NewWindow(0, &r, "\p", false, documentProc, 0, 0, 0);
3159 /* Activate the "fake" window */
3168 /* Add the fonts to the menu */
3169 AppendResMenu(m, 'FONT'); //AddResMenu(m, 'FONT');
3175 for (i = n; i >= 4; i--)
3180 /* Acquire the font name */
3181 /* GetMenuItemText(m, i, tmpName); */
3182 GetMenuItemText(m, i, tmpName); //GetItem(m, i, tmpName);
3184 /* Acquire the font index */
3185 GetFNum(tmpName, &fontNum);
3187 /* Apply the font index */
3190 /* Remove non-mono-spaced fonts */
3191 if ((CharWidth('i') != CharWidth('W')) || (CharWidth('W') == 0))
3193 /* Delete the menu item XXX XXX XXX */
3194 /* DeleteMenuItem(m, i); */
3195 DeleteMenuItem (m, i); //DelMenuItem(m, i);
3199 /* Destroy the old window */
3200 DisposeWindow(tmpw);
3202 /* Add a separator */
3203 AppendMenu(m, "\p-");
3205 /* Add the fonts to the menu */
3206 AppendResMenu (m, 'FONT'); //AddResMenu(m, 'FONT');
3209 /* Make the "Size" menu */
3211 m = NewMenu(132, "\p¥µ¥¤¥º");
3213 m = NewMenu(132, "\pSize");
3216 /* Insert the menu */
3219 /* Add some sizes (stagger choices) */
3220 for (i = 8; i <= 32; i += ((i / 16) + 1))
3225 sprintf((char*)buf + 1, "%d", i);
3226 buf[0] = strlen((char*)buf + 1);
3233 /* Make the "Windows" menu */
3235 m = NewMenu(133, "\p¥¦¥¤¥ó¥É¥¦");
3237 m = NewMenu(133, "\pWindows");
3240 /* Insert the menu */
3243 /* Default choices */
3244 for (i = 0; i < MAX_TERM_DATA; i++)
3248 /* Describe the item */
3249 sprintf((char*)buf + 1, "%.15s", angband_term_name[i]);
3250 buf[0] = strlen((char*)buf + 1);
3255 /* Command-Key shortcuts */
3256 if (i < 8) SetItemCmd(m, i + 1, '0' + i);
3260 /* Make the "Special" menu */
3262 m = NewMenu(134, "\pÆÃÊÌ");
3264 m = NewMenu(134, "\pSpecial");
3267 /* Insert the menu */
3270 /* Append the choices */
3272 AppendMenu(m, "\p¥µ¥¦¥ó¥É»ÈÍÑ");
3273 AppendMenu(m, "\p¥°¥é¥Õ¥£¥Ã¥¯»ÈÍÑ");
3274 AppendMenu(m, "\p-");
3275 AppendMenu(m, "\parg_fiddle");
3276 AppendMenu(m, "\parg_wizard");
3277 AppendMenu(m, "\p-");
3278 AppendMenu(m, "\p¥µ¥¦¥ó¥ÉÀßÄê...");
3279 AppendMenu(m, "\p16X16¥°¥é¥Õ¥£¥Ã¥¯");
3280 AppendMenu(m, "\p£²ÇÜÉý¥¿¥¤¥ëɽ¼¨");
3282 AppendMenu(m, "\parg_sound");
3283 AppendMenu(m, "\parg_graphics");
3284 AppendMenu(m, "\p-");
3285 AppendMenu(m, "\parg_fiddle");
3286 AppendMenu(m, "\parg_wizard");
3287 AppendMenu(m, "\p-");
3288 AppendMenu(m, "\pSound config");
3289 AppendMenu(m, "\pAdam Bolt tile");
3290 AppendMenu(m, "\pBigtile Mode");
3293 /* Make the "TileWidth" menu */
3295 m = NewMenu(135, "\p¥¿¥¤¥ëÉý");
3297 m = NewMenu(135, "\pTileWidth");
3300 /* Insert the menu */
3303 /* Add some sizes */
3304 for (i = 4; i <= 32; i++)
3309 sprintf((char*)buf + 1, "%d", i);
3310 buf[0] = strlen((char*)buf + 1);
3317 /* Make the "TileHeight" menu */
3319 m = NewMenu(136, "\p¥¿¥¤¥ë¹â");
3321 m = NewMenu(136, "\pTileHeight");
3324 /* Insert the menu */
3327 /* Add some sizes */
3328 for (i = 4; i <= 32; i++)
3333 sprintf((char*)buf + 1, "%d", i);
3334 buf[0] = strlen((char*)buf + 1);
3341 /* Update the menu bar */
3349 static void setup_menus(void)
3359 term_data *td = NULL;
3362 /* Relevant "term_data" */
3363 for (i = 0; i < MAX_TERM_DATA; i++)
3366 if (!data[i].t) continue;
3368 /* Notice the matching window */
3369 if (data[i].w == FrontWindow()) td = &data[i];
3374 m = GetMenuHandle(129); //m = GetMHandle(129);
3380 for (i = 1; i <= n; i++)
3384 CheckItem(m, i, FALSE);
3387 /* Enable "new"/"open..."/"import..." */
3388 if (initialized && !game_in_progress)
3395 /* Enable "close" */
3402 if (initialized && character_generated)
3411 /* EnableItem(m, 8); */
3416 m = GetMenuHandle(130); //m = GetMHandle(130);
3422 for (i = 1; i <= n; i++)
3426 CheckItem(m, i, FALSE);
3429 /* Enable "edit" options if "needed" */
3441 m = GetMenuHandle(131); //m = GetMHandle(131);
3447 for (i = 1; i <= n; i++)
3451 CheckItem(m, i, FALSE);
3454 /* Hack -- look cute XXX XXX */
3455 /* SetItemStyle(m, 1, bold); */
3457 /* Hack -- look cute XXX XXX */
3458 /* SetItemStyle(m, 2, extend); */
3466 /* Enable "extend" */
3469 /* Check the appropriate "bold-ness" */
3470 if (td->font_face & bold) CheckItem(m, 1, TRUE);
3472 /* Check the appropriate "wide-ness" */
3473 if (td->font_face & extend) CheckItem(m, 2, TRUE);
3476 for (i = 4; i <= n; i++)
3482 /* GetMenuItemText(m,i,s); */
3483 GetMenuItemText(m, i, s); //GetItem(m, i, s);
3486 /* Check active font */
3487 if (td->font_id == value) CheckItem(m, i, TRUE);
3493 m = GetMenuHandle(132); //m = GetMHandle(132);
3499 for (i = 1; i <= n; i++)
3503 CheckItem(m, i, FALSE);
3510 for (i = 1; i <= n; i++)
3513 /* GetMenuItemText(m,i,s); */
3514 GetMenuItemText(m, i, s); //GetItem(m, i, s);
3516 value = atoi((char*)(s+1));
3518 /* Enable the "real" sizes */
3519 if (RealFont(td->font_id, value)) EnableItem(m, i);
3521 /* Check the current size */
3522 if (td->font_size == value) CheckItem(m, i, TRUE);
3528 m = GetMenuHandle(133); //m = GetMHandle(133);
3533 /* Check active windows */
3534 for (i = 1; i <= n; i++)
3536 /* Check if needed */
3537 CheckItem(m, i, data[i-1].mapped);
3542 m = GetMenuHandle(134); //m = GetMHandle(134);
3548 for (i = 1; i <= n; i++)
3552 CheckItem(m, i, FALSE);
3555 /* Item "arg_sound" */
3557 CheckItem(m, 1, arg_sound);
3559 /* Item "arg_graphics" */
3561 CheckItem(m, 2, arg_graphics);
3563 /* Item "arg_fiddle" */
3565 CheckItem(m, 4, arg_fiddle);
3567 /* Item "arg_wizard" */
3569 CheckItem(m, 5, arg_wizard);
3571 /* Item "SoundSetting" */
3574 /* Item NewStyle Graphics */
3576 CheckItem(m, 8, use_newstyle_graphics);
3578 /* Item Bigtile Mode */
3580 CheckItem(m, 9, arg_bigtile);
3583 /* EnableItem(m, 9); */
3586 /* TileWidth menu */
3587 m = GetMenuHandle(135); //m = GetMHandle(135);
3593 for (i = 1; i <= n; i++)
3597 CheckItem(m, i, FALSE);
3604 for (i = 1; i <= n; i++)
3607 /* GetMenuItemText(m,i,s); */
3608 GetMenuItemText(m, i, s); //GetItem(m, i, s);
3610 value = atoi((char*)(s+1));
3615 /* Check the current size */
3616 if (td->tile_wid == value) CheckItem(m, i, TRUE);
3621 /* TileHeight menu */
3622 m = GetMenuHandle(136); //m = GetMHandle(136);
3628 for (i = 1; i <= n; i++)
3632 CheckItem(m, i, FALSE);
3639 for (i = 1; i <= n; i++)
3642 /* GetMenuItemText(m,i,s); */
3643 GetMenuItemText(m, i, s); //GetItem(m, i, s);
3645 value = atoi((char*)(s+1));
3650 /* Check the current size */
3651 if (td->tile_hgt == value) CheckItem(m, i, TRUE);
3658 * Process a menu selection (see above)
3660 * Hack -- assume that invalid menu selections are disabled above,
3661 * which I have been informed may not be reliable. XXX XXX XXX
3663 static void menu(long mc)
3667 int menuid, selection;
3669 static unsigned char s[1000];
3673 term_data *td = NULL;
3678 /* Analyze the menu command */
3679 menuid = HiWord(mc);
3680 selection = LoWord(mc);
3683 /* Find the window */
3684 for (i = 0; i < MAX_TERM_DATA; i++)
3686 /* Skip dead windows */
3687 if (!data[i].t) continue;
3689 /* Notice matches */
3690 if (data[i].w == FrontWindow()) td = &data[i];
3694 /* Branch on the menu */
3700 /* About Angband... */
3707 dialog=GetNewDialog(128, 0, (WindowPtr)-1);
3710 center_rect(&r, &qd.screenBits.bounds);
3711 MoveWindow(dialog, r.left, r.top, 1);
3713 ModalDialog(0, &item_hit);
3714 DisposeDialog(dialog); //DisposDialog(dialog);
3718 /* Desk accessory */
3719 /* GetMenuItemText(GetMHandle(128),selection,s); */
3720 GetMenuItemText(GetMenuHandle(128), selection, s); //GetItem(GetMHandle(128), selection, s);
3740 do_menu_file_open(FALSE);
3747 do_menu_file_open(TRUE);
3761 td->t->mapped_flag = FALSE;
3763 /* Hide the window */
3774 plog("º£¤Ï¥»¡¼¥Ö¤¹¤ë¤³¤È¤Ï½ÐÍè¤Þ¤»¤ó¡£");
3776 plog("You may not do that right now.");
3781 /* Hack -- Forget messages */
3784 /* Hack -- Save the game */
3785 do_cmd_save_game(FALSE);
3790 /* Quit (with save) */
3793 /* Save the game (if necessary) */
3794 if (game_in_progress && character_generated)
3798 plog("º£¤Ï¥»¡¼¥Ö¤¹¤ë¤³¤È¤Ï½ÐÍè¤Þ¤»¤ó¡£");
3800 plog("You may not do that right now.");
3804 /* Hack -- Forget messages */
3808 // do_cmd_save_game(FALSE);
3809 Term_key_push(KTRL('X'));
3831 /* Require a window */
3840 /* Toggle the "bold" setting */
3843 /* Toggle the setting */
3844 if (td->font_face & bold)
3846 td->font_face &= ~bold;
3850 td->font_face |= bold;
3853 /* Tile Width Hight Init */
3854 td->tile_wid = td->tile_hgt = 0;
3856 /* Apply and Verify */
3857 term_data_check_font(td);
3858 term_data_check_size(td);
3860 /* Resize and Redraw */
3861 term_data_resize(td);
3862 term_data_redraw(td);
3867 /* Toggle the "wide" setting */
3870 /* Toggle the setting */
3871 if (td->font_face & extend)
3873 td->font_face &= ~extend;
3877 td->font_face |= extend;
3880 /* Tile Width Hight Init */
3881 td->tile_wid = td->tile_hgt = 0;
3883 /* Apply and Verify */
3884 term_data_check_font(td);
3885 term_data_check_size(td);
3887 /* Resize and Redraw */
3888 term_data_resize(td);
3889 term_data_redraw(td);
3894 /* Get a new font name */
3895 /* GetMenuItemText(GetMHandle(131), selection, s); */
3896 GetMenuItemText(GetMenuHandle(131), selection, s); //GetItem(GetMHandle(131), selection, s);
3899 /* Save the new font id */
3902 /* Current size is bad for new font */
3903 if (!RealFont(td->font_id, td->font_size))
3905 /* Find similar size */
3906 for (i = 1; i <= 32; i++)
3908 /* Adjust smaller */
3909 if (td->font_size - i >= 8)
3911 if (RealFont(td->font_id, td->font_size - i))
3919 if (td->font_size + i <= 128)
3921 if (RealFont(td->font_id, td->font_size + i))
3930 /* Tile Width Hight Init */
3931 td->tile_wid = td->tile_hgt = 0;
3933 /* Apply and Verify */
3934 term_data_check_font(td);
3935 term_data_check_size(td);
3937 /* Resize and Redraw */
3938 term_data_resize(td);
3939 term_data_redraw(td);
3941 /* Restore the window */
3958 /* GetMenuItemText(GetMHandle(132), selection, s); */
3959 GetMenuItemText(GetMenuHandle(132), selection, s); //GetItem(GetMHandle(132), selection, s);
3961 td->font_size = atoi((char*)(s+1));
3963 /* Tile Width Hight Init */
3964 td->tile_wid = td->tile_hgt = 0;
3966 /* Apply and Verify */
3967 term_data_check_font(td);
3968 term_data_check_size(td);
3970 /* Resize and Redraw */
3971 term_data_resize(td);
3972 term_data_redraw(td);
3986 /* Check legality of choice */
3987 if ((i < 0) || (i >= MAX_TERM_DATA)) break;
3989 /* Obtain the window */
3999 td->t->mapped_flag = TRUE;
4001 /* Show the window */
4004 /* Bring to the front */
4005 SelectWindow(td->w);
4017 /* Toggle arg_sound */
4018 arg_sound = !arg_sound;
4020 /* React to changes */
4021 Term_xtra(TERM_XTRA_REACT, 0);
4028 /* Toggle arg_graphics */
4029 arg_graphics = !arg_graphics;
4031 /* Hack -- Force redraw */
4032 Term_key_push(KTRL('R'));
4039 arg_fiddle = !arg_fiddle;
4045 arg_wizard = !arg_wizard;
4056 if (streq(ANGBAND_GRAF, "old"))
4058 ANGBAND_GRAF = "new";
4059 arg_newstyle_graphics = true;
4060 grafWidth = grafHeight = 16;
4065 ANGBAND_GRAF = "old";
4066 arg_newstyle_graphics = false;
4067 grafWidth = grafHeight = 8;
4071 /* Hack -- Force redraw */
4072 Term_key_push(KTRL('R'));
4076 case 9: /* bigtile mode */
4078 term_data *td = &data[0];
4082 plog("º£¤ÏÊѹ¹½ÐÍè¤Þ¤»¤ó¡£");
4084 plog("You may not do that right now.");
4089 /* Toggle "arg_bigtile" */
4090 arg_bigtile = !arg_bigtile;
4093 Term_activate(td->t);
4095 /* Resize the term */
4096 Term_resize(td->cols, td->rows);
4106 /* TileWidth menu */
4117 /* GetMenuItemText(GetMHandle(135), selection, s); */
4118 GetMenuItemText(GetMenuHandle(135), selection, s); //GetItem(GetMHandle(135), selection, s);
4120 td->tile_wid = atoi((char*)(s+1));
4122 /* Apply and Verify */
4123 term_data_check_size(td);
4125 /* Resize and Redraw */
4126 term_data_resize(td);
4127 term_data_redraw(td);
4135 /* TileHeight menu */
4146 /* GetMenuItemText(GetMHandle(136), selection, s); */
4147 GetMenuItemText(GetMenuHandle(136), selection, s); //GetItem(GetMHandle(136), selection, s);
4149 td->tile_hgt = atoi((char*)(s+1));
4151 /* Apply and Verify */
4152 term_data_check_size(td);
4154 /* Resize and Redraw */
4155 term_data_resize(td);
4156 term_data_redraw(td);
4166 /* Clean the menu */
4175 * Check for extra required parameters -- From "Maarten Hazewinkel"
4177 static OSErr CheckRequiredAEParams(const AppleEvent *theAppleEvent)
4180 DescType returnedType;
4183 aeError = AEGetAttributePtr(theAppleEvent, keyMissedKeywordAttr, typeWildCard,
4184 &returnedType, NULL, 0, &actualSize);
4186 if (aeError == errAEDescNotFound) return (noErr);
4188 if (aeError == noErr) return (errAEParamMissed);
4195 * Apple Event Handler -- Open Application
4197 static pascal OSErr AEH_Start(const AppleEvent *theAppleEvent,
4198 const AppleEvent *reply, long handlerRefCon)
4200 #pragma unused(reply, handlerRefCon)
4202 return (CheckRequiredAEParams(theAppleEvent));
4207 * Apple Event Handler -- Quit Application
4209 static pascal OSErr AEH_Quit(const AppleEvent *theAppleEvent,
4210 const AppleEvent *reply, long handlerRefCon)
4212 #pragma unused(reply, handlerRefCon)
4215 quit_when_ready = TRUE;
4217 /* Check arguments */
4218 return (CheckRequiredAEParams(theAppleEvent));
4223 * Apple Event Handler -- Print Documents
4225 static pascal OSErr AEH_Print(const AppleEvent *theAppleEvent,
4226 const AppleEvent *reply, long handlerRefCon)
4228 #pragma unused(theAppleEvent, reply, handlerRefCon)
4230 return (errAEEventNotHandled);
4235 * Apple Event Handler by Steve Linberg (slinberg@crocker.com).
4237 * The old method of opening savefiles from the finder does not work
4238 * on the Power Macintosh, because CountAppFiles and GetAppFiles,
4239 * used to return information about the selected document files when
4240 * an application is launched, are part of the Segment Loader, which
4241 * is not present in the RISC OS due to the new memory architecture.
4243 * The "correct" way to do this is with AppleEvents. The following
4244 * code is modeled on the "Getting Files Selected from the Finder"
4245 * snippet from Think Reference 2.0. (The prior sentence could read
4246 * "shamelessly swiped & hacked")
4248 static pascal OSErr AEH_Open(AppleEvent *theAppleEvent,
4249 AppleEvent* reply, long handlerRefCon)
4251 #pragma unused(reply, handlerRefCon)
4258 DescType returnedType;
4262 /* Put the direct parameter (a descriptor list) into a docList */
4263 err = AEGetParamDesc(theAppleEvent, keyDirectObject, typeAEList, &docList);
4264 if (err) return err;
4267 * We ignore the validity check, because we trust the FInder, and we only
4268 * allow one savefile to be opened, so we ignore the depth of the list.
4271 err = AEGetNthPtr(&docList, 1L, typeFSS, &keywd,
4272 &returnedType, (Ptr) &myFSS, sizeof(myFSS), &actualSize);
4273 if (err) return err;
4275 /* Only needed to check savefile type below */
4276 err = FSpGetFInfo(&myFSS, &myFileInfo);
4279 sprintf(foo, "Arg! FSpGetFInfo failed with code %d", err);
4284 /* Ignore non 'SAVE' files */
4285 if (myFileInfo.fdType != 'SAVE') return noErr;
4287 /* XXX XXX XXX Extract a file name */
4288 PathNameFromDirID(myFSS.parID, myFSS.vRefNum, (StringPtr)savefile);
4289 pstrcat((StringPtr)savefile, (StringPtr)&myFSS.name);
4291 /* Convert the string */
4292 ptocstr((StringPtr)savefile);
4294 /* Delay actual open */
4295 open_when_ready = TRUE;
4298 err = AEDisposeDesc(&docList);
4310 * Macintosh modifiers (event.modifier & ccc):
4311 * cmdKey, optionKey, shiftKey, alphaLock, controlKey
4314 * Macintosh Keycodes (0-63 normal, 64-95 keypad, 96-127 extra):
4359 * Optimize non-blocking calls to "CheckEvents()"
4360 * Idea from "Maarten Hazewinkel <mmhazewi@cs.ruu.nl>"
4362 #define EVENT_TICKS 6
4366 * Check for Events, return TRUE if we process any
4368 * Hack -- Handle AppleEvents if appropriate (ignore result code).
4370 static bool CheckEvents(bool wait)
4386 term_data *td = NULL;
4390 static huge lastTicks = 0L;
4393 /* Access the clock */
4394 curTicks = TickCount();
4396 /* Hack -- Allow efficient checking for non-pending events */
4397 if (!wait && (curTicks < lastTicks + EVENT_TICKS)) return (FALSE);
4399 /* Timestamp last check */
4400 lastTicks = curTicks;
4402 /* Let the "system" run */
4405 /* Get an event (or null) */
4406 GetNextEvent(everyEvent, &event);
4408 /* Hack -- Nothing is ready yet */
4409 if (event.what == nullEvent) return (FALSE);
4412 /* Analyze the event */
4420 w = (WindowPtr)event.message;
4431 /* Extract the window */
4432 w = (WindowPtr)event.message;
4434 /* Find the window */
4435 for (i = 0; i < MAX_TERM_DATA; i++)
4437 /* Skip dead windows */
4438 if (!data[i].t) continue;
4440 /* Notice matches */
4441 if (data[i].w == w) td = &data[i];
4444 /* Hack XXX XXX XXX */
4448 /* Redraw the window */
4449 if (td) term_data_redraw(td);
4457 /* Extract some modifiers */
4458 mc = (event.modifiers & controlKey) ? TRUE : FALSE;
4459 ms = (event.modifiers & shiftKey) ? TRUE : FALSE;
4460 mo = (event.modifiers & optionKey) ? TRUE : FALSE;
4461 mx = (event.modifiers & cmdKey) ? TRUE : FALSE;
4463 /* Keypress: (only "valid" if ck < 96) */
4464 ch = (event.message & charCodeMask) & 255;
4466 /* Keycode: see table above */
4467 ck = ((event.message & keyCodeMask) >> 8) & 255;
4469 /* Command + "normal key" -> menu action */
4470 if (mx && (ck < 64))
4472 /* Hack -- Prepare the menus */
4475 /* Mega-Hack -- allow easy exit if nothing to save */
4476 /* if (!character_generated && (ch=='Q' || ch=='q')) ch = 'e'; */
4478 /* Run the Menu-Handler */
4481 /* Turn off the menus */
4489 /* Hide the mouse pointer */
4492 /* Normal key -> simple keypress */
4495 /* Enqueue the keypress */
4499 /* Hack -- normal "keypad keys" -> special keypress */
4500 else if (!mc && !ms && !mo && !mx && (ck < 96))
4502 /* Hack -- "enter" is confused */
4503 if (ck == 76) ch = '\n';
4505 /* Send control-caret as a trigger */
4508 /* Send the "ascii" keypress */
4512 /* Bizarre key -> encoded keypress */
4515 /* Hack -- introduce with control-underscore */
4518 /* Send some modifier keys */
4519 if (mc) Term_keypress('C');
4520 if (ms) Term_keypress('S');
4521 if (mo) Term_keypress('O');
4522 if (mx) Term_keypress('X');
4524 /* Hack -- Downshift and encode the keycode */
4525 Term_keypress('0' + (ck - 64) / 10);
4526 Term_keypress('0' + (ck - 64) % 10);
4528 /* Hack -- Terminate the sequence */
4529 /* MPW can generate 10 or 13 for keycode of '\r' */
4530 /* -noMapCR option swaps '\r' and '\n' */
4531 Term_keypress('\r');
4541 /* Analyze click location */
4542 code = FindWindow(event.where, &w);
4544 /* Find the window */
4545 for (i = 0; i < MAX_TERM_DATA; i++)
4547 /* Skip dead windows */
4548 if (!data[i].t) continue;
4550 /* Notice matches */
4551 if (data[i].w == w) td = &data[i];
4560 menu(MenuSelect(event.where));
4567 SystemClick(&event, w);
4577 r = qd.screenBits.bounds;
4578 r.top += 20; /* GetMBarHeight() XXX XXX XXX */
4579 InsetRect(&r, 4, 4);
4580 DragWindow(w, event.where, &r);
4592 p.h = td->w->portRect.left;
4593 p.v = td->w->portRect.top;
4601 /* Apply and Verify */
4602 term_data_check_size(td);
4612 /* Track the go-away box */
4613 if (TrackGoAway(w, event.where))
4619 td->t->mapped_flag = FALSE;
4621 /* Hide the window */
4637 /* Fake rectangle */
4638 r.left = 20 * td->tile_wid + td->size_ow1;
4639 r.right = qd.screenBits.bounds.right;
4640 r.top = 1 * td->tile_hgt + td->size_oh1;
4641 r.bottom = qd.screenBits.bounds.bottom;
4643 /* Grow the rectangle */
4644 newsize = GrowWindow(w, event.where, &r);
4647 if (!newsize) break;
4649 /* Extract the new size in pixels */
4650 y = HiWord(newsize) - td->size_oh1 - td->size_oh2;
4651 x = LoWord(newsize) - td->size_ow1 - td->size_ow2;
4653 /* Extract a "close" approximation */
4654 td->rows = y / td->tile_hgt;
4655 td->cols = x / td->tile_wid;
4657 /* Apply and Verify */
4658 term_data_check_size(td);
4661 Term_activate(td->t);
4663 /* Hack -- Resize the term */
4664 Term_resize(td->cols, td->rows);
4666 /* Resize and Redraw */
4667 term_data_resize(td);
4668 term_data_redraw(td);
4687 /* Disk Event -- From "Maarten Hazewinkel" */
4690 /* check for error when mounting the disk */
4691 if (HiWord(event.message) != noErr)
4697 DIBadMount(p, event.message);
4704 /* OS Event -- From "Maarten Hazewinkel" */
4707 switch ((event.message >> 24) & 0x000000FF)
4709 case suspendResumeMessage:
4711 /* Resuming: activate the front window */
4712 if (event.message & resumeFlag)
4714 SetPort(FrontWindow());
4715 SetCursor(&qd.arrow);
4718 /* Suspend: deactivate the front window */
4732 /* From "Steve Linberg" and "Maarten Hazewinkel" */
4733 case kHighLevelEvent:
4735 /* Process apple events */
4736 if (AEProcessAppleEvent(&event) != noErr)
4739 plog("Apple Event Handler¤Î¥¨¥é¡¼¤Ç¤¹.");
4741 plog("Error in Apple Event Handler!");
4745 /* Handle "quit_when_ready" */
4746 if (quit_when_ready)
4749 quit_when_ready = FALSE;
4751 /* Do the menu key */
4754 /* Turn off the menus */
4758 /* Handle "open_when_ready" */
4759 handle_open_when_ready();
4769 /* Something happened */
4776 /*** Some Hooks for various routines ***/
4780 * Mega-Hack -- emergency lifeboat
4782 static vptr lifeboat = NULL;
4786 * Hook to "release" memory
4788 static vptr hook_rnfree(vptr v, huge size)
4791 #pragma unused (size)
4795 /* Alternative method */
4810 * Hook to "allocate" memory
4812 static vptr hook_ralloc(huge size)
4817 /* Make a new pointer */
4818 return (malloc(size));
4822 /* Make a new pointer */
4823 return (NewPtr(size));
4830 * Hook to handle "out of memory" errors
4832 static vptr hook_rpanic(huge size)
4835 #pragma unused (size)
4839 /* Free the lifeboat */
4842 /* Free the lifeboat */
4843 DisposePtr(lifeboat);
4845 /* Forget the lifeboat */
4848 /* Mega-Hack -- Warning */
4850 mac_warning("¥á¥â¥ê¡¼¤¬Â¤ê¤Þ¤»¤ó!\rº£¤¹¤°½ªÎ»¤·¤Æ²¼¤µ¤¤!");
4852 mac_warning("Running out of Memory!\rAbort this process now!");
4855 /* Mega-Hack -- Never leave this function */
4856 while (TRUE) CheckEvents(TRUE);
4859 /* Mega-Hack -- Crash */
4865 * Hook to tell the user something important
4867 static void hook_plog(cptr str)
4869 /* Warning message */
4874 * Hook to tell the user something, and then quit
4876 static void hook_quit(cptr str)
4878 /* Warning if needed */
4879 if (str) mac_warning(str);
4881 /* Write a preference file */
4889 * Hook to tell the user something, and then crash
4891 static void hook_core(cptr str)
4893 /* XXX Use the debugger */
4894 /* DebugStr(str); */
4897 if (str) mac_warning(str);
4899 /* Warn, then save player */
4901 mac_warning("Ã×̿Ū¤Ê¥¨¥é¡¼¤Ç¤¹.\r¶¯À©Åª¤Ë¥»¡¼¥Ö¤·¤Æ½ªÎ»¤·¤Þ¤¹.");
4903 mac_warning("Fatal error.\rI will now attempt to save and quit.");
4906 /* Attempt to save */
4908 if (!save_player()) mac_warning("·Ù¹ð -- ¥»¡¼¥Ö¤Ë¼ºÇÔ¤·¤Þ¤·¤¿!");
4910 if (!save_player()) mac_warning("Warning -- save failed!");
4919 /*** Main program ***/
4925 * XXX XXX XXX Hack -- This function attempts to "fix" the nasty
4926 * "Macintosh Save Bug" by using "absolute" path names, since on
4927 * System 7 machines anyway, the "current working directory" often
4928 * "changes" due to background processes, invalidating any "relative"
4929 * path names. Note that the Macintosh is limited to 255 character
4930 * path names, so be careful about deeply embedded directories...
4932 * XXX XXX XXX Hack -- This function attempts to "fix" the nasty
4933 * "missing lib folder bug" by allowing the user to help find the
4934 * "lib" folder by hand if the "application folder" code fails...
4936 static void init_stuff(void)
4953 /* Fake rectangle */
4960 center_rect(&r, &qd.screenBits.bounds);
4962 /* Extract corner */
4967 /* Default to the "lib" folder with the application */
4968 refnum_to_name(path, app_dir, app_vol, (char*)("\plib:"));
4971 /* Check until done */
4974 /* Prepare the paths */
4975 init_file_paths(path);
4977 /* Build the filename */
4979 path_build(path, 1024, ANGBAND_DIR_FILE, "news_j.txt");
4981 path_build(path, 1024, ANGBAND_DIR_FILE, "news.txt");
4984 /* Attempt to open and close that file */
4985 if (0 == fd_close(fd_open(path, O_RDONLY))) break;
4989 plog_fmt("'%s' ¥Õ¥¡¥¤¥ë¤ò¥ª¡¼¥×¥ó½ÐÍè¤Þ¤»¤ó.", path);
4991 plog_fmt("Unable to open the '%s' file.", path);
4996 plog("Hengband¤Î'lib'¥Õ¥©¥ë¥À¤¬Â¸ºß¤·¤Ê¤¤¤«Àµ¤·¤¯Ìµ¤¤²ÄǽÀ¤¬¤¢¤ê¤Þ¤¹.");
4998 plog("The Angband 'lib' folder is probably missing or misplaced.");
5002 plog("Please 'open' any file in any sub-folder of the 'lib' folder.");
5004 /* Allow "text" files */
5007 /* Allow "save" files */
5010 /* Allow "data" files */
5014 SFGetFile(topleft, "\p", NULL, 3, types, NULL, &reply);
5017 if (!reply.good) quit(NULL);
5019 /* Extract textual file name for given file */
5020 GetWDInfo(reply.vRefNum, &vrefnum, &drefnum, &junk);
5021 refnum_to_name(path, drefnum, vrefnum, (char*)reply.fName);
5023 /* Hack -- Remove the "filename" */
5024 i = strlen(path) - 1;
5025 while ((i > 0) && (path[i] != ':')) i--;
5026 if (path[i] == ':') path[i+1] = '\0';
5028 /* Hack -- allow "lib" folders */
5029 if (suffix(path, "lib:")) continue;
5031 /* Hack -- Remove the "sub-folder" */
5033 while ((i > 1) && (path[i] != ':')) i--;
5034 if (path[i] == ':') path[i+1] = '\0';
5040 * Macintosh Main loop
5044 EventRecord tempEvent;
5045 int numberOfMasters = 10;
5047 /* Increase stack space by 64K */
5048 SetApplLimit(GetApplLimit() - 131072L);//65536L);
5050 /* Stretch out the heap to full size */
5053 /* Get more Masters */
5054 while (numberOfMasters--) MoreMasters();
5056 /* Set up the Macintosh */
5057 InitGraf(&qd.thePort);
5070 FlushEvents(everyEvent, 0);
5072 /* Flush events some more (?) */
5073 (void)EventAvail(everyEvent, &tempEvent);
5074 (void)EventAvail(everyEvent, &tempEvent);
5075 (void)EventAvail(everyEvent, &tempEvent);
5078 #ifdef ANGBAND_LITE_MAC
5082 #else /* ANGBAND_LITE_MAC */
5084 # if defined(powerc) || defined(__powerc)
5086 /* Assume System 7 */
5088 /* Assume Color Quickdraw */
5098 /* Check the Gestalt */
5099 err = Gestalt(gestaltSystemVersion, &versionNumber);
5101 /* Check the version */
5102 if ((err != noErr) || (versionNumber < 0x0700))
5105 quit("¤³¤Î¥×¥í¥°¥é¥à¤Ï´Á»úTalk7.x.x°Ê¹ß¤ÇÆ°ºî¤·¤Þ¤¹.");
5107 quit("You must have System 7 to use this program.");
5117 /* Check the environs */
5118 if (SysEnvirons(1, &env) != noErr)
5121 quit("SysEnvirons ¥³¡¼¥ë¤Ï¼ºÇÔ¤·¤Þ¤·¤¿¡ª");
5123 quit("The SysEnvirons call failed!");
5127 /* Check for System Seven Stuff */
5128 if (env.systemVersion < 0x0700)
5131 quit("¤³¤Î¥×¥í¥°¥é¥à¤Ï´Á»úTalk7.x.x°Ê¹ß¤ÇÆ°ºî¤·¤Þ¤¹.");
5133 quit("You must have System 7 to use this program.");
5137 /* Check for Color Quickdraw */
5138 if (!env.hasColorQD)
5141 quit("¤³¤Î¥×¥í¥°¥é¥à¤ÏColor Quickdraw¤¬Ìµ¤¤¤ÈÆ°ºî¤·¤Þ¤»¤ó.");
5143 quit("You must have Color Quickdraw to use this program.");
5150 #endif /* ANGBAND_LITE_MAC */
5155 /* Obtain a "Universal Procedure Pointer" */
5156 AEH_Start_UPP = NewAEEventHandlerProc(AEH_Start);
5158 /* Install the hook (ignore error codes) */
5159 AEInstallEventHandler(kCoreEventClass, kAEOpenApplication, AEH_Start_UPP,
5162 /* Obtain a "Universal Procedure Pointer" */
5163 AEH_Quit_UPP = NewAEEventHandlerProc(AEH_Quit);
5165 /* Install the hook (ignore error codes) */
5166 AEInstallEventHandler(kCoreEventClass, kAEQuitApplication, AEH_Quit_UPP,
5169 /* Obtain a "Universal Procedure Pointer" */
5170 AEH_Print_UPP = NewAEEventHandlerProc(AEH_Print);
5172 /* Install the hook (ignore error codes) */
5173 AEInstallEventHandler(kCoreEventClass, kAEPrintDocuments, AEH_Print_UPP,
5176 /* Obtain a "Universal Procedure Pointer" */
5177 AEH_Open_UPP = NewAEEventHandlerProc(AEH_Open);
5179 /* Install the hook (ignore error codes) */
5180 AEInstallEventHandler(kCoreEventClass, kAEOpenDocuments, AEH_Open_UPP,
5186 /* Find the current application */
5190 /* Mark ourself as the file creator */
5193 /* Default to saving a "text" file */
5197 #if defined(__MWERKS__)
5199 /* Obtian a "Universal Procedure Pointer" */
5200 ynfilterUPP = NewModalFilterProc(ynfilter);
5205 /* Hook in some "z-virt.c" hooks */
5206 rnfree_aux = hook_rnfree;
5207 ralloc_aux = hook_ralloc;
5208 rpanic_aux = hook_rpanic;
5210 /* Hooks in some "z-util.c" hooks */
5211 plog_aux = hook_plog;
5212 quit_aux = hook_quit;
5213 core_aux = hook_core;
5215 BackColor(blackColor);
5216 ForeColor(whiteColor);
5218 /* Show the "watch" cursor */
5219 SetCursor(*(GetCursor(watchCursor)));
5221 /* Prepare the menubar */
5224 /* Prepare the windows */
5229 /* Hack -- process all events */
5230 while (CheckEvents(TRUE)) /* loop */;
5232 /* Reset the cursor */
5233 SetCursor(&qd.arrow);
5236 /* Mega-Hack -- Allocate a "lifeboat" */
5237 lifeboat = NewPtr(16384);
5239 /* Note the "system" */
5240 ANGBAND_SYS = "mac";
5242 ANGBAND_GRAF = "new";
5244 ANGBAND_GRAF = "old";
5254 /* Hack -- process all events */
5255 while (CheckEvents(TRUE)) /* loop */;
5258 /* We are now initialized */
5262 /* Handle "open_when_ready" */
5263 handle_open_when_ready();
5269 /* Prompt the user */
5271 prt("'¥Õ¥¡¥¤¥ë'¥á¥Ë¥å¡¼¤è¤ê'¿·µ¬'¤Þ¤¿¤Ï'³«¤¯...'¤òÁªÂò¤·¤Æ¤¯¤À¤µ¤¤¡£", 23, 10);
5273 prt("[Choose 'New' or 'Open' from the 'File' menu]", 23, 15);
5276 /* Flush the prompt */
5280 /* Hack -- Process Events Forever */
5281 while (TRUE) CheckEvents(TRUE);