1 /* SCCS Id: @(#)amirip.c 3.2 96/02/04 */
2 /* Copyright (c) Kenneth Lorber, Bethesda, Maryland 1991,1992,1993,1995,1996. */
3 /* NetHack may be freely redistributed. See license for details. */
6 #include <exec/types.h>
8 #include <exec/alerts.h>
9 #include <exec/devices.h>
10 #include <devices/console.h>
11 #include <devices/conunit.h>
12 #include <graphics/gfxbase.h>
13 #include <graphics/gfxmacros.h>
14 #include <intuition/intuition.h>
15 #include <libraries/dosextens.h>
23 static struct RastPort *rp;
31 # include <functions.h>
34 # include <clib/dos_protos.h>
35 # include <clib/exec_protos.h>
36 # include <clib/console_protos.h>
37 # include <clib/diskfont_protos.h>
39 # include <proto/dos.h>
40 # include <proto/exec.h>
41 # include <proto/console.h>
42 # include <proto/diskfont.h>
45 static char *load_list[]={"tomb.iff",0};
46 static BitMapHeader tomb_bmhd;
47 static struct BitMap *tbmp[ 1 ] = {0};
49 static int cols[2]={154,319}; /* X location of center of columns */
50 static int cno = 0; /* current column */
51 #define TEXT_TOP (65+yoff)
53 static xoff, yoff; /* image centering */
56 /* this is why prototypes should have ONLY types in them! */
62 # include <clib/graphics_protos.h>
63 # include <clib/intuition_protos.h>
65 # include <proto/graphics.h>
66 # include <proto/intuition.h>
70 extern char *killed_by_prefix[];
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 13 /* # chars that fit on one line
77 * (note 1 ' ' border) */
82 static unsigned short tomb_line;
84 extern struct amii_DisplayDesc *amiIDisplay;
85 extern struct Screen *HackScreen;
88 static unsigned short transpalette[ AMII_MAXCOLORS ] = { 0x0000, };
90 static struct NewWindow newwin =
93 MOUSEBUTTONS|VANILLAKEY|NOCAREREFRESH,
94 BORDERLESS|ACTIVATE|SMART_REFRESH,
95 NULL,NULL,(UBYTE*)NULL,NULL,NULL,-1,-1,0xffff,0xffff,CUSTOMSCREEN
98 int wh; /* was local in outrip, but needed for SCALE macro */
100 int cmap_white, cmap_black;
103 amii_outrip( tmpwin, how )
109 struct IntuiMessage *imsg;
116 if(!WINVERS_AMIV || HackScreen->RastPort.BitMap->Depth < 4)goto cleanup;
118 /* Use the users display size */
119 newwin.Height = amiIDisplay->ypix - newwin.TopEdge;
120 newwin.Width = amiIDisplay->xpix;
121 newwin.Screen = HackScreen;
123 for( i = 0; i < amii_numcolors; ++i )
124 flags.amii_curmap[i] = GetRGB4( HackScreen->ViewPort.ColorMap, i );
126 ripwin = OpenWindow( (void *)&newwin );
127 if( !ripwin ) goto cleanup;
129 LoadRGB4( &HackScreen->ViewPort, transpalette, amii_numcolors );
137 SetFont(rp, HackFont);
140 tomb_bmhd = ReadImageFiles(load_list, tbmp, &errstr );
141 if(errstr)goto cleanup;
142 if(tomb_bmhd.w > ww || tomb_bmhd.h > wh)goto cleanup;
144 #define GENOFF(full,used) ((((full)-(used))/2) & ~7)
145 xoff = GENOFF(ww,tomb_bmhd.w);
146 yoff = GENOFF(wh,tomb_bmhd.h);
147 for(i=0;i<SIZE(cols);i++)cols[i]+=xoff;
149 cmap_white = search_cmap(0,0,0);
150 cmap_black = search_cmap(15,15,15);
152 BltBitMap(*tbmp, 0, 0, rp->BitMap, xoff, yoff, tomb_bmhd.w, tomb_bmhd.h, 0xc0, 0xff, NULL);
154 /* Put together death description */
155 switch (killer_format) {
157 impossible("bad killer format?");
159 Strcpy(buf, killed_by_prefix[how]);
160 Strcat(buf, an(killer));
163 Strcpy(buf, killed_by_prefix[how]);
166 case NO_KILLER_PREFIX:
171 tw = TextLength(rp,buf,STONE_LINE_LEN) + 40;
176 for(x=STONE_LINE_LEN;x;x--)*p++='W';
178 tmp = TextLength(rp,buf,STONE_LINE_LEN) + 40;
182 /* There are 5 lines of text on the stone. */
183 rtxth = ripwin->RPort->TxHeight * 5;
185 SetAfPt( rp, (UWORD *)NULL, 0 );
186 SetDrPt( rp, 0xFFFF );
192 /* Put name on stone */
193 Sprintf(buf, "%s", plname);
194 buf[STONE_LINE_LEN] = 0;
198 Sprintf(buf, "%ld Au",
204 buf[STONE_LINE_LEN] = 0; /* It could be a *lot* of gold :-) */
207 /* Put together death description */
208 switch (killer_format) {
210 impossible("bad killer format?");
212 Strcpy(buf, killed_by_prefix[how]);
213 Strcat(buf, an(killer));
216 Strcpy(buf, killed_by_prefix[how]);
219 case NO_KILLER_PREFIX:
224 /* Put death type on stone */
225 for (line=DEATH_LINE, dpx = buf; line<YEAR_LINE; line++)
230 if ( (i0=strlen(dpx)) > STONE_LINE_LEN)
232 for(i=STONE_LINE_LEN;((i0 > STONE_LINE_LEN) && i); i--)
256 /* Put year on stone */
257 Sprintf(buf, "%4d", getyear());
260 #ifdef NH320_DEDICATION
264 tomb_text("This release");
265 tomb_text("of NetHack");
266 tomb_text("is dedicated");
268 tomb_text("memory of");
271 tomb_text(" Miller");
273 tomb_text("1935-1994");
275 tomb_text("Ascended");
277 /* Fade from black to full color */
280 /* Flush all messages to avoid typeahead */
281 while( imsg = (struct IntuiMessage *)GetMsg( ripwin->UserPort ) )
282 ReplyMsg( (struct Message *) imsg );
286 WaitPort( ripwin->UserPort );
287 while( imsg = (struct IntuiMessage *)GetMsg(ripwin->UserPort) )
289 switch( imsg->Class )
296 ReplyMsg( (struct Message *)imsg );
305 /* free everything */
308 while( imsg = (struct IntuiMessage *)GetMsg( ripwin->UserPort ) )
309 ReplyMsg( (struct Message *)imsg );
310 CloseWindow( ripwin );
313 LoadRGB4( &HackScreen->ViewPort, flags.amii_curmap, amii_numcolors );
315 if(tbmp[0])FreeImageFiles(load_list, tbmp);
316 if(just_return) return;
317 /* fall back to the straight-ASCII version */
318 genl_outrip(tmpwin, how);
321 static void tomb_text(p)
324 char buf[STONE_LINE_LEN*2];
327 tomb_line += rp->TxHeight;
331 sprintf(buf," %s ",p);
332 l=TextLength(rp,buf,strlen(buf));
334 SetAPen(rp,cmap_white);
335 Move(rp,cols[cno]-(l/2)-1, tomb_line);
336 Text(rp,buf,strlen(buf));
338 SetAPen(rp,cmap_white);
339 Move(rp,cols[cno]-(l/2)+1, tomb_line);
340 Text(rp,buf,strlen(buf));
342 SetAPen(rp,cmap_white);
343 Move(rp,cols[cno]-(l/2), tomb_line-1);
344 Text(rp,buf,strlen(buf));
346 SetAPen(rp,cmap_white);
347 Move(rp,cols[cno]-(l/2), tomb_line+1);
348 Text(rp,buf,strlen(buf));
350 SetAPen(rp,cmap_black);
351 Move(rp,cols[cno]-(l/2), tomb_line);
352 Text(rp,buf,strlen(buf));
355 /* search colormap for best match to given color */
357 search_cmap(int r0, int g0, int b0){
359 int bdiff = 0x0fffffff;
361 for(x=0;x<amii_numcolors; x++){
362 int r = r0- ((amiv_init_map[x] >> 8) & 15);
363 int g = g0-((amiv_init_map[x] >> 4) & 15);
364 int b = b0-((amiv_init_map[x] ) & 15);
365 int diff = (r*r) + (g*g) + (b*b);
374 /* caution: this is NOT general! */
376 dofade(int start, int stop, int inc){
378 for( i = start; (i*inc) <= stop; i+=inc )
380 for( j = 0; j < amii_numcolors; ++j )
384 r = ( amiv_init_map[ j ] & 0xf00 ) >> 8;
385 g = ( amiv_init_map[ j ] & 0xf0 ) >> 4;
386 b = ( amiv_init_map[ j ] & 0xf );
390 transpalette[ j ] = ((r<<8)|(g<<4)|b);
392 LoadRGB4( &HackScreen->ViewPort, transpalette, amii_numcolors );
399 #endif /* AMII_GRAPHICS */
404 fix ReadImageFiles to return error instead of panic on error