1 /* NetHack 3.6 amirip.c $NHDT-Date: 1450453302 2015/12/18 15:41:42 $ $NHDT-Branch: NetHack-3.6.0 $:$NHDT-Revision: 1.16 $ */
2 /* Copyright (c) Kenneth Lorber, Bethesda, Maryland 1991,1992,1993,1995,1996.
4 /* NetHack may be freely redistributed. See license for details. */
7 #include <exec/types.h>
9 #include <exec/alerts.h>
10 #include <exec/devices.h>
11 #include <devices/console.h>
12 #include <devices/conunit.h>
13 #include <graphics/gfxbase.h>
14 #include <graphics/gfxmacros.h>
15 #include <intuition/intuition.h>
16 #include <libraries/dosextens.h>
24 static struct RastPort
*rp
;
32 #include <functions.h>
35 #include <clib/dos_protos.h>
36 #include <clib/exec_protos.h>
37 #include <clib/console_protos.h>
38 #include <clib/diskfont_protos.h>
40 #include <proto/dos.h>
41 #include <proto/exec.h>
42 #include <proto/console.h>
43 #include <proto/diskfont.h>
46 static char *load_list
[] = { "tomb.iff", 0 };
47 static BitMapHeader tomb_bmhd
;
48 static struct BitMap
*tbmp
[1] = { 0 };
50 static int cols
[2] = { 154, 319 }; /* X location of center of columns */
51 static int cno
= 0; /* current column */
52 #define TEXT_TOP (65 + yoff)
54 static xoff
, yoff
; /* image centering */
57 /* this is why prototypes should have ONLY types in them! */
63 #include <clib/graphics_protos.h>
64 #include <clib/intuition_protos.h>
66 #include <proto/graphics.h>
67 #include <proto/intuition.h>
71 static struct Window
*ripwin
= 0;
72 static void tomb_text(char *);
73 static void dofade(int, int, int);
74 static int search_cmap(int, int, int);
76 #define STONE_LINE_LEN \
77 13 /* # chars that fit on one line \
78 * (note 1 ' ' border) */
83 static unsigned short tomb_line
;
85 extern struct amii_DisplayDesc
*amiIDisplay
;
86 extern struct Screen
*HackScreen
;
89 static unsigned short transpalette
[AMII_MAXCOLORS
] = {
93 static struct NewWindow newwin
= { 0, 0, 640, 200, 1, 0,
94 MOUSEBUTTONS
| VANILLAKEY
| NOCAREREFRESH
,
95 BORDERLESS
| ACTIVATE
| SMART_REFRESH
,
96 NULL
, NULL
, (UBYTE
*) NULL
, NULL
, NULL
, -1,
97 -1, 0xffff, 0xffff, CUSTOMSCREEN
};
99 int wh
; /* was local in outrip, but needed for SCALE macro */
101 int cmap_white
, cmap_black
;
104 amii_outrip(tmpwin
, how
, when
)
111 struct IntuiMessage
*imsg
;
119 if (!WINVERS_AMIV
|| HackScreen
->RastPort
.BitMap
->Depth
< 4)
122 /* Use the users display size */
123 newwin
.Height
= amiIDisplay
->ypix
- newwin
.TopEdge
;
124 newwin
.Width
= amiIDisplay
->xpix
;
125 newwin
.Screen
= HackScreen
;
127 for (i
= 0; i
< amii_numcolors
; ++i
)
128 sysflags
.amii_curmap
[i
] = GetRGB4(HackScreen
->ViewPort
.ColorMap
, i
);
130 ripwin
= OpenWindow((void *) &newwin
);
134 LoadRGB4(&HackScreen
->ViewPort
, transpalette
, amii_numcolors
);
142 SetFont(rp
, HackFont
);
145 tomb_bmhd
= ReadImageFiles(load_list
, tbmp
, &errstr
);
148 if (tomb_bmhd
.w
> ww
|| tomb_bmhd
.h
> wh
)
151 #define GENOFF(full, used) ((((full) - (used)) / 2) & ~7)
152 xoff
= GENOFF(ww
, tomb_bmhd
.w
);
153 yoff
= GENOFF(wh
, tomb_bmhd
.h
);
154 for (i
= 0; i
< SIZE(cols
); i
++)
157 cmap_white
= search_cmap(0, 0, 0);
158 cmap_black
= search_cmap(15, 15, 15);
160 BltBitMap(*tbmp
, 0, 0, rp
->BitMap
, xoff
, yoff
, tomb_bmhd
.w
, tomb_bmhd
.h
,
163 /* Put together death description */
164 formatkiller(buf
, sizeof buf
, how
, FALSE
);
166 tw
= TextLength(rp
, buf
, STONE_LINE_LEN
) + 40;
171 for (x
= STONE_LINE_LEN
; x
; x
--)
174 tmp
= TextLength(rp
, buf
, STONE_LINE_LEN
) + 40;
178 /* There are 5 lines of text on the stone. */
179 rtxth
= ripwin
->RPort
->TxHeight
* 5;
181 SetAfPt(rp
, (UWORD
*) NULL
, 0);
184 tomb_line
= TEXT_TOP
;
188 /* Put name on stone */
189 Sprintf(buf
, "%s", plname
);
190 buf
[STONE_LINE_LEN
] = 0;
194 Sprintf(buf
, "%ld Au", done_money
);
195 buf
[STONE_LINE_LEN
] = 0; /* It could be a *lot* of gold :-) */
198 /* Put together death description */
199 formatkiller(buf
, sizeof buf
, how
, FALSE
);
201 /* Put death type on stone */
202 for (line
= DEATH_LINE
, dpx
= buf
; line
< YEAR_LINE
; line
++) {
206 if ((i0
= strlen(dpx
)) > STONE_LINE_LEN
) {
207 for (i
= STONE_LINE_LEN
; ((i0
> STONE_LINE_LEN
) && i
); i
--) {
219 if (tmpchar
!= ' ') {
227 /* Put year on stone */
228 year
= yyyymmdd(when
) / 10000L;
229 Sprintf(buf
, "%4ld", year
);
232 #ifdef NH320_DEDICATION
235 tomb_line
= TEXT_TOP
;
236 tomb_text("This release");
237 tomb_text("of NetHack");
238 tomb_text("is dedicated");
240 tomb_text("memory of");
243 tomb_text(" Miller");
245 tomb_text("1935-1994");
247 tomb_text("Ascended");
249 /* Fade from black to full color */
252 /* Flush all messages to avoid typeahead */
253 while (imsg
= (struct IntuiMessage
*) GetMsg(ripwin
->UserPort
))
254 ReplyMsg((struct Message
*) imsg
);
257 WaitPort(ripwin
->UserPort
);
258 while (imsg
= (struct IntuiMessage
*) GetMsg(ripwin
->UserPort
)) {
259 switch (imsg
->Class
) {
265 ReplyMsg((struct Message
*) imsg
);
274 /* free everything */
277 while (imsg
= (struct IntuiMessage
*) GetMsg(ripwin
->UserPort
))
278 ReplyMsg((struct Message
*) imsg
);
282 LoadRGB4(&HackScreen
->ViewPort
, sysflags
.amii_curmap
, amii_numcolors
);
285 FreeImageFiles(load_list
, tbmp
);
288 /* fall back to the straight-ASCII version */
289 genl_outrip(tmpwin
, how
, when
);
296 char buf
[STONE_LINE_LEN
* 2];
299 tomb_line
+= rp
->TxHeight
;
303 sprintf(buf
, " %s ", p
);
304 l
= TextLength(rp
, buf
, strlen(buf
));
306 SetAPen(rp
, cmap_white
);
307 Move(rp
, cols
[cno
] - (l
/ 2) - 1, tomb_line
);
308 Text(rp
, buf
, strlen(buf
));
310 SetAPen(rp
, cmap_white
);
311 Move(rp
, cols
[cno
] - (l
/ 2) + 1, tomb_line
);
312 Text(rp
, buf
, strlen(buf
));
314 SetAPen(rp
, cmap_white
);
315 Move(rp
, cols
[cno
] - (l
/ 2), tomb_line
- 1);
316 Text(rp
, buf
, strlen(buf
));
318 SetAPen(rp
, cmap_white
);
319 Move(rp
, cols
[cno
] - (l
/ 2), tomb_line
+ 1);
320 Text(rp
, buf
, strlen(buf
));
322 SetAPen(rp
, cmap_black
);
323 Move(rp
, cols
[cno
] - (l
/ 2), tomb_line
);
324 Text(rp
, buf
, strlen(buf
));
327 /* search colormap for best match to given color */
329 search_cmap(int r0
, int g0
, int b0
)
332 int bdiff
= 0x0fffffff;
334 for (x
= 0; x
< amii_numcolors
; x
++) {
335 int r
= r0
- ((amiv_init_map
[x
] >> 8) & 15);
336 int g
= g0
- ((amiv_init_map
[x
] >> 4) & 15);
337 int b
= b0
- ((amiv_init_map
[x
]) & 15);
338 int diff
= (r
* r
) + (g
* g
) + (b
* b
);
347 /* caution: this is NOT general! */
349 dofade(int start
, int stop
, int inc
)
352 for (i
= start
; (i
* inc
) <= stop
; i
+= inc
) {
353 for (j
= 0; j
< amii_numcolors
; ++j
) {
356 r
= (amiv_init_map
[j
] & 0xf00) >> 8;
357 g
= (amiv_init_map
[j
] & 0xf0) >> 4;
358 b
= (amiv_init_map
[j
] & 0xf);
362 transpalette
[j
] = ((r
<< 8) | (g
<< 4) | b
);
364 LoadRGB4(&HackScreen
->ViewPort
, transpalette
, amii_numcolors
);
369 #endif /* AMII_GRAPHICS */
374 fix ReadImageFiles to return error instead of panic on error