1 // Emacs style mode select -*- C++ -*-
2 //-----------------------------------------------------------------------------
6 // Copyright (C) 1993-1996 by id Software, Inc.
8 // This source is available for distribution and/or modification
9 // only under the terms of the DOOM Source Code License as
10 // published by id Software. All rights reserved.
12 // The source is distributed in the hope that it will be useful,
13 // but WITHOUT ANY WARRANTY; without even the implied warranty of
14 // FITNESS FOR A PARTICULAR PURPOSE. See the DOOM Source Code License
18 // Revision 1.1 2000/02/29 18:21:05 stegerg
19 // Doom port based on ADoomPPC. Read README.AROS!
23 // Gamma correction LUT stuff.
24 // Functions to draw patches (by post) directly to screen.
25 // Functions to blit a block to the screen.
27 //-----------------------------------------------------------------------------
32 #include <exec/exec.h>
35 #define MEMF_NOCACHESYNCPPC 0
36 #define MEMF_NOCACHESYNCM68K 0
37 #define PPCAllocVec(size,flags) I_AllocLow(size)
39 #include <powerup/clib/ppc_protos.h>
40 #include <powerup/ppclib/memory.h>
61 extern int weirdaspect
;
63 // Screen buffer memory
66 // Each screen is [SCREENWIDTH*SCREENHEIGHT];
73 // Now where did these came from?
74 byte gammatable
[5][256] =
76 {1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,
77 17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,
78 33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,
79 49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,64,
80 65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80,
81 81,82,83,84,85,86,87,88,89,90,91,92,93,94,95,96,
82 97,98,99,100,101,102,103,104,105,106,107,108,109,110,111,112,
83 113,114,115,116,117,118,119,120,121,122,123,124,125,126,127,128,
84 128,129,130,131,132,133,134,135,136,137,138,139,140,141,142,143,
85 144,145,146,147,148,149,150,151,152,153,154,155,156,157,158,159,
86 160,161,162,163,164,165,166,167,168,169,170,171,172,173,174,175,
87 176,177,178,179,180,181,182,183,184,185,186,187,188,189,190,191,
88 192,193,194,195,196,197,198,199,200,201,202,203,204,205,206,207,
89 208,209,210,211,212,213,214,215,216,217,218,219,220,221,222,223,
90 224,225,226,227,228,229,230,231,232,233,234,235,236,237,238,239,
91 240,241,242,243,244,245,246,247,248,249,250,251,252,253,254,255},
93 {2,4,5,7,8,10,11,12,14,15,16,18,19,20,21,23,24,25,26,27,29,30,31,
94 32,33,34,36,37,38,39,40,41,42,44,45,46,47,48,49,50,51,52,54,55,
95 56,57,58,59,60,61,62,63,64,65,66,67,69,70,71,72,73,74,75,76,77,
96 78,79,80,81,82,83,84,85,86,87,88,89,90,91,92,93,94,95,96,97,98,
97 99,100,101,102,103,104,105,106,107,108,109,110,111,112,113,114,
98 115,116,117,118,119,120,121,122,123,124,125,126,127,128,129,129,
99 130,131,132,133,134,135,136,137,138,139,140,141,142,143,144,145,
100 146,147,148,148,149,150,151,152,153,154,155,156,157,158,159,160,
101 161,162,163,163,164,165,166,167,168,169,170,171,172,173,174,175,
102 175,176,177,178,179,180,181,182,183,184,185,186,186,187,188,189,
103 190,191,192,193,194,195,196,196,197,198,199,200,201,202,203,204,
104 205,205,206,207,208,209,210,211,212,213,214,214,215,216,217,218,
105 219,220,221,222,222,223,224,225,226,227,228,229,230,230,231,232,
106 233,234,235,236,237,237,238,239,240,241,242,243,244,245,245,246,
107 247,248,249,250,251,252,252,253,254,255},
109 {4,7,9,11,13,15,17,19,21,22,24,26,27,29,30,32,33,35,36,38,39,40,42,
110 43,45,46,47,48,50,51,52,54,55,56,57,59,60,61,62,63,65,66,67,68,69,
111 70,72,73,74,75,76,77,78,79,80,82,83,84,85,86,87,88,89,90,91,92,93,
112 94,95,96,97,98,100,101,102,103,104,105,106,107,108,109,110,111,112,
113 113,114,114,115,116,117,118,119,120,121,122,123,124,125,126,127,128,
114 129,130,131,132,133,133,134,135,136,137,138,139,140,141,142,143,144,
115 144,145,146,147,148,149,150,151,152,153,153,154,155,156,157,158,159,
116 160,160,161,162,163,164,165,166,166,167,168,169,170,171,172,172,173,
117 174,175,176,177,178,178,179,180,181,182,183,183,184,185,186,187,188,
118 188,189,190,191,192,193,193,194,195,196,197,197,198,199,200,201,201,
119 202,203,204,205,206,206,207,208,209,210,210,211,212,213,213,214,215,
120 216,217,217,218,219,220,221,221,222,223,224,224,225,226,227,228,228,
121 229,230,231,231,232,233,234,235,235,236,237,238,238,239,240,241,241,
122 242,243,244,244,245,246,247,247,248,249,250,251,251,252,253,254,254,
125 {8,12,16,19,22,24,27,29,31,34,36,38,40,41,43,45,47,49,50,52,53,55,
126 57,58,60,61,63,64,65,67,68,70,71,72,74,75,76,77,79,80,81,82,84,85,
127 86,87,88,90,91,92,93,94,95,96,98,99,100,101,102,103,104,105,106,107,
128 108,109,110,111,112,113,114,115,116,117,118,119,120,121,122,123,124,
129 125,126,127,128,129,130,131,132,133,134,135,135,136,137,138,139,140,
130 141,142,143,143,144,145,146,147,148,149,150,150,151,152,153,154,155,
131 155,156,157,158,159,160,160,161,162,163,164,165,165,166,167,168,169,
132 169,170,171,172,173,173,174,175,176,176,177,178,179,180,180,181,182,
133 183,183,184,185,186,186,187,188,189,189,190,191,192,192,193,194,195,
134 195,196,197,197,198,199,200,200,201,202,202,203,204,205,205,206,207,
135 207,208,209,210,210,211,212,212,213,214,214,215,216,216,217,218,219,
136 219,220,221,221,222,223,223,224,225,225,226,227,227,228,229,229,230,
137 231,231,232,233,233,234,235,235,236,237,237,238,238,239,240,240,241,
138 242,242,243,244,244,245,246,246,247,247,248,249,249,250,251,251,252,
139 253,253,254,254,255},
141 {16,23,28,32,36,39,42,45,48,50,53,55,57,60,62,64,66,68,69,71,73,75,76,
142 78,80,81,83,84,86,87,89,90,92,93,94,96,97,98,100,101,102,103,105,106,
143 107,108,109,110,112,113,114,115,116,117,118,119,120,121,122,123,124,
144 125,126,128,128,129,130,131,132,133,134,135,136,137,138,139,140,141,
145 142,143,143,144,145,146,147,148,149,150,150,151,152,153,154,155,155,
146 156,157,158,159,159,160,161,162,163,163,164,165,166,166,167,168,169,
147 169,170,171,172,172,173,174,175,175,176,177,177,178,179,180,180,181,
148 182,182,183,184,184,185,186,187,187,188,189,189,190,191,191,192,193,
149 193,194,195,195,196,196,197,198,198,199,200,200,201,202,202,203,203,
150 204,205,205,206,207,207,208,208,209,210,210,211,211,212,213,213,214,
151 214,215,216,216,217,217,218,219,219,220,220,221,221,222,223,223,224,
152 224,225,225,226,227,227,228,228,229,229,230,230,231,232,232,233,233,
153 234,234,235,235,236,236,237,237,238,239,239,240,240,241,241,242,242,
154 243,243,244,244,245,245,246,246,247,247,248,248,249,249,250,250,251,
155 251,252,252,253,254,254,255,255}
173 M_AddToBox (dirtybox, x, y);
174 M_AddToBox (dirtybox, x+width-1, y+height-1);
198 ||srcx
+width
>SCREENWIDTH
200 || srcy
+height
>SCREENHEIGHT
201 ||destx
<0||destx
+width
>SCREENWIDTH
203 || desty
+height
>SCREENHEIGHT
204 || (unsigned)srcscrn
>4
205 || (unsigned)destscrn
>4)
207 I_Error ("Bad V_CopyRect");
210 src
= screens
[srcscrn
]+SCREENWIDTH
*srcy
+srcx
;
211 dest
= screens
[destscrn
]+SCREENWIDTH
*desty
+destx
;
213 for ( ; height
>0 ; height
--)
215 memcpy (dest
, src
, width
);
221 I_MarkRect (destx
, desty
, width
, height
);
227 // Masks a column based masked pic to the screen.
246 y
-= SWAPSHORT(patch
->topoffset
);
247 x
-= SWAPSHORT(patch
->leftoffset
);
250 ||x
+SWAPSHORT(patch
->width
) >SCREENWIDTH
252 || y
+SWAPSHORT(patch
->height
)>SCREENHEIGHT
255 fprintf( stderr
, "Patch at %d,%d exceeds LFB\n", x
,y
);
256 // No I_Error abort - what is up with TNT.WAD?
257 fprintf( stderr
, "V_DrawPatch: bad patch (ignored)\n");
264 desttop
= screens
[scrn
]+y
*SCREENWIDTH
+x
;
266 w
= SWAPSHORT(patch
->width
);
268 for ( ; col
<w
; x
++, col
++, desttop
++)
270 column
= (column_t
*)((byte
*)patch
+ SWAPLONG(patch
->columnofs
[col
]));
272 // step through the posts in a column
273 while (column
->topdelta
!= 0xff )
275 source
= (byte
*)column
+ 3;
276 dest
= desttop
+ column
->topdelta
*SCREENWIDTH
;
277 count
= column
->length
;
284 column
= (column_t
*)( (byte
*)column
+ column
->length
289 I_MarkRect (x0
, y
, SWAPSHORT(patch
->width
), SWAPSHORT(patch
->height
));
293 // V_DrawPatchFlipped
294 // Masks a column based masked pic to the screen.
295 // Flips horizontally, e.g. to mirror face.
314 y
-= SWAPSHORT(patch
->topoffset
);
315 x
-= SWAPSHORT(patch
->leftoffset
);
318 ||x
+SWAPSHORT(patch
->width
) >SCREENWIDTH
320 || y
+SWAPSHORT(patch
->height
)>SCREENHEIGHT
323 fprintf( stderr
, "Patch origin %d,%d exceeds LFB\n", x
,y
);
324 I_Error ("Bad V_DrawPatch in V_DrawPatchFlipped");
330 desttop
= screens
[scrn
]+y
*SCREENWIDTH
+x
;
332 w
= SWAPSHORT(patch
->width
);
334 for ( ; col
<w
; x
++, col
++, desttop
++)
336 column
= (column_t
*)((byte
*)patch
+ SWAPLONG(patch
->columnofs
[w
-1-col
]));
338 // step through the posts in a column
339 while (column
->topdelta
!= 0xff )
341 source
= (byte
*)column
+ 3;
342 dest
= desttop
+ column
->topdelta
*SCREENWIDTH
;
343 count
= column
->length
;
350 column
= (column_t
*)( (byte
*)column
+ column
->length
355 I_MarkRect (x0
, y
, SWAPSHORT(patch
->width
), SWAPSHORT(patch
->height
));
362 // Draws directly to the screen on the pc.
371 V_DrawPatch (x
,y
,scrn
, patch
);
374 void //stretches bitmap to fill screen
390 int deltax
,deltay
,deltaxi
,deltayi
,stretchx
,stretchy
;
393 y
-= SWAPSHORT(patch
->topoffset
);
394 x
-= SWAPSHORT(patch
->leftoffset
);
398 ||x
+SWAPSHORT(patch
->width
)>320
400 || y
+SWAPSHORT(patch
->height
)>200
403 fprintf( stderr
, "Patch at %d,%d exceeds LFB\n", x
,y
);
404 // No I_Error abort - what is up with TNT.WAD?
405 fprintf( stderr
, "V_DrawPatch: bad patch (ignored)\n");
410 deltax
=(SCREENWIDTH
<<16)/320;
411 deltaxi
=(320<<16)/SCREENWIDTH
;
412 deltay
=(SCREENHEIGHT
<<16)/200;
413 deltayi
=(200<<16)/SCREENHEIGHT
;
414 stretchx
=(x
*deltax
)>>16;
415 stretchy
=(y
*deltay
)>>16;
419 desttop
= screens
[scrn
]+stretchy
*SCREENWIDTH
+stretchx
;
421 w
= SWAPSHORT(patch
->width
)<<16;
423 for ( ; col
< w
; x
++, col
+= deltaxi
, desttop
++) {
424 column
= (column_t
*)((byte
*)patch
+ SWAPLONG(patch
->columnofs
[col
>>16]));
426 // step through the posts in a column
427 while (column
->topdelta
!= 0xff ) {
428 source
= (byte
*)column
+ 3;
429 dest
= desttop
+((column
->topdelta
*deltay
)>>16)*SCREENWIDTH
;
430 collen
= count
= (column
->length
*deltay
)>>16;
433 *dest
= source
[srccol
>>16];
437 column
= (column_t
*)((byte
*)column
+ (column
->length
)+4);
441 I_MarkRect (x0
, y
, SWAPSHORT(patch
->width
), SWAPSHORT(patch
->height
));
445 void //stretches bitmap to fill screen
446 V_DrawPatchInDirectFlipped
460 int deltax
,deltay
,deltaxi
,deltayi
,stretchx
,stretchy
;
463 y
-= SWAPSHORT(patch
->topoffset
);
464 x
-= SWAPSHORT(patch
->leftoffset
);
467 ||x
+SWAPSHORT(patch
->width
) >320
469 || y
+SWAPSHORT(patch
->height
)>200
472 fprintf( stderr
, "Patch at %d,%d exceeds LFB\n", x
,y
);
473 // No I_Error abort - what is up with TNT.WAD?
474 fprintf( stderr
, "V_DrawPatch: bad patch (ignored)\n");
479 deltax
=(SCREENWIDTH
<<16)/320;
480 deltaxi
=(320<<16)/SCREENWIDTH
;
481 deltay
=(SCREENHEIGHT
<<16)/200;
482 deltayi
=(200<<16)/SCREENHEIGHT
;
483 stretchx
=(x
*deltax
)>>16;
484 stretchy
=(y
*deltay
)>>16;
487 desttop
= screens
[scrn
]+stretchy
*SCREENWIDTH
+stretchx
;
489 w
= SWAPSHORT(patch
->width
)<<16;
491 for ( ; col
< w
; x
++, col
+= deltaxi
, desttop
++) {
492 column
= (column_t
*)((byte
*)patch
+
493 SWAPLONG(patch
->columnofs
[SWAPSHORT(patch
->width
)-1-(col
>>16)]));
495 // step through the posts in a column
496 while (column
->topdelta
!= 0xff) {
497 source
= (byte
*)column
+ 3;
498 dest
= desttop
+((column
->topdelta
*deltay
)>>16)*SCREENWIDTH
;
499 collen
= count
= (column
->length
*deltay
)>>16;
502 *dest
=source
[srccol
>>16];
506 column
= (column_t
*)((byte
*)column
+(column
->length
)+4);
510 I_MarkRect (stretchx
,stretchy
,(SWAPSHORT(patch
->width
)*deltax
)>>16,
511 (SWAPSHORT(patch
->height
)*deltax
)>>16);
518 // Draw a linear block of pixels into the view buffer.
534 ||x
+width
>SCREENWIDTH
536 || y
+height
>SCREENHEIGHT
537 || (unsigned)scrn
>4 )
539 I_Error ("Bad V_DrawBlock");
544 dest
= screens
[scrn
] + y
*SCREENWIDTH
+x
;
548 memcpy (dest
, src
, width
);
553 I_MarkRect (x
, y
, width
, height0
);
560 // Gets a linear block of pixels from the view buffer.
575 ||x
+width
>SCREENWIDTH
577 || y
+height
>SCREENHEIGHT
578 || (unsigned)scrn
>4 )
580 I_Error ("Bad V_DrawBlock");
584 src
= screens
[scrn
] + y
*SCREENWIDTH
+x
;
588 memcpy (dest
, src
, width
);
596 extern int video_graffiti
;
612 if (M_CheckParm ("-graffitilo")) {
616 } else if (M_CheckParm ("-graffitihi")) {
623 p
= M_CheckParm ("-width");
624 if (p
&& p
< myargc
-1)
625 SCREENWIDTH
= atoi(myargv
[p
+1]);
629 p
= M_CheckParm ("-height");
630 if (p
&& p
< myargc
-1)
631 SCREENHEIGHT
= atoi(myargv
[p
+1]);
639 printf ("Resolution: %d x %d\n", SCREENWIDTH
, SCREENHEIGHT
);
641 if (SCREENWIDTH
< 320 || SCREENWIDTH
> MAXSCREENWIDTH
||
642 SCREENWIDTH
% 32 != 0 ||
643 SCREENHEIGHT
< 200 || SCREENHEIGHT
> MAXSCREENHEIGHT
)
644 I_Error ("Resolution out of range or width is not a multiple of 32");
646 if ((SCREENHEIGHT
*8) == (SCREENWIDTH
*5)) // 640x400, 320x200
648 else if ((SCREENHEIGHT
*4) == (SCREENWIDTH
*3)) // 640x480, 320x240
652 printf("Warning: Bad aspect ratio, things might look screwy\n");
656 //allocate all the res-dependant vars
660 xtoviewangle
= (angle_t
*)I_calloc (SCREENWIDTH
+1, sizeof(angle_t
));
661 negonearray
= (short *)I_calloc (SCREENWIDTH
, sizeof(short));
662 screenheightarray
= (short *)I_calloc (SCREENWIDTH
, sizeof(short));
664 // stick these in low dos memory on PCs
666 vid_flags
= MEMF_CLEAR
+MEMF_FAST
+MEMF_PUBLIC
;
667 if (M_CheckParm ("-mmu"))
668 vid_flags
+= MEMF_NOCACHESYNCPPC
+MEMF_NOCACHESYNCM68K
;
669 vid_size
= SCREENWIDTH
*SCREENHEIGHT
*4+SCREENWIDTH
*ST_HEIGHT
;
670 vid_mem
= PPCAllocVec(vid_size
+ 100, vid_flags
);
672 I_Error ("Couldn't allocate memory for screens\n");
673 printf ("Screen memory located at $%08lx\n", (long)vid_mem
);
675 for (i
=0 ; i
<4 ; i
++)
676 screens
[i
] = vid_mem
+ 100 + i
*SCREENWIDTH
*SCREENHEIGHT
;
677 screens
[4] = vid_mem
+ SCREENWIDTH
*SCREENHEIGHT
*4;