2 THE COMPUTER CODE CONTAINED HEREIN IS THE SOLE PROPERTY OF PARALLAX
3 SOFTWARE CORPORATION ("PARALLAX"). PARALLAX, IN DISTRIBUTING THE CODE TO
4 END-USERS, AND SUBJECT TO ALL OF THE TERMS AND CONDITIONS HEREIN, GRANTS A
5 ROYALTY-FREE, PERPETUAL LICENSE TO SUCH END-USERS FOR USE BY SUCH END-USERS
6 IN USING, DISPLAYING, AND CREATING DERIVATIVE WORKS THEREOF, SO LONG AS
7 SUCH USE, DISPLAY OR CREATION IS FOR NON-COMMERCIAL, ROYALTY OR REVENUE
8 FREE PURPOSES. IN NO EVENT SHALL THE END-USER USE THE COMPUTER CODE
9 CONTAINED HEREIN FOR REVENUE-BEARING PURPOSES. THE END-USER UNDERSTANDS
10 AND AGREES TO THE TERMS HEREIN AND ACCEPTS THE SAME BY USE OF THIS FILE.
11 COPYRIGHT 1993-1999 PARALLAX SOFTWARE CORPORATION. ALL RIGHTS RESERVED.
14 static unsigned poly_count;
25 #include "pa_enabl.h" // needs to occur early.
44 #define TEX_CACHE (64)
45 #define CHROMA_COLOR 0x0001
46 #define MODE_110 S3DTK_MODE640x480x15 // 640x480x15
48 #define DMA_VERT_WORDS (sizeof(S3DTK_VERTEX_TEX) / sizeof(unsigned long))
49 #define NDL 5 // stolen from main/game.h. how many filter levels there are.
51 enum { OP_TMAP, OP_FLAT, OP_BLIT, OP_BLIT_TRANSPARENT, OP_BLIT_SCALE };
56 extern ubyte scale_rle_data[1024]; // from 2d\scale.c
57 unsigned short pa_clut[256]; // translate from 8 bit pixels to 15 bit pixels.
58 static short pa_clut_save_buf[256]; // used to save/restore the clut.
59 int pa_filter_mode = NDL-1; // For Virge filtering control, set in Custom Detail Level menu.
62 static pa_initted = 0;
63 static pa_card_initted = 0; //$$hack, library doesn't seem to correctly init card twice.
64 static ULONG old_mode;
66 /* S3D Toolkit function list */
67 static S3DTK_LPFUNCTIONLIST pS3DTK_Funct;
68 static S3DTK_VERTEX_TEX verts[MAX_TMAP_VERTS];
69 static S3DTK_LPVERTEX_TEX trifan[MAX_TMAP_VERTS];
71 /* buffer definitions */
72 static int backBuffer = 1; /* index of back buffer */
73 static S3DTK_SURFACE displaySurf[2]; /* one for front buffer and one for back buffer */
74 static S3DTK_RECTAREA fullScreenRect = { 0, 0, 640, 480 };
76 /* physical properties */
77 static ULONG screenFormat = S3DTK_VIDEORGB15; /* format of the surface as defined in S3DTK.H */
78 static float width=640, height=480; /* screen's dimension */
80 // memory manager variables.
81 static ULONG totalMemory; /* frame buffer size */
82 static ULONG memoryUsed; /* frame buffer allocated */
83 static char *frameBuffer; /* linear address of frame buffer starts at */
86 static S3DTK_SURFACE cache_slots[TEX_CACHE];
91 } cache_tags[TEX_CACHE];
92 static int cache_age = 0;
95 static unsigned long dma_buf[DMA_SIZE]; // simulated dma ring buffer.
96 static int dma_head, dma_tail; // head and tail of ring buffer.
97 static op_extra_words[] = // how many extra words are needed besides the vertex info
98 { 7, 5, 10, 11, 5 }; // plus 1. avoids (head == tail) == (tail == head).
99 static filter_tmap[] = {
100 S3DTK_TEX1TPP, S3DTK_TEXM1TPP, S3DTK_TEX4TPP, S3DTK_TEX4TPP, S3DTK_TEXM4TPP
102 static filter_scale[] = {
103 S3DTK_TEX1TPP, S3DTK_TEX4TPP, S3DTK_TEX4TPP, S3DTK_TEX4TPP, S3DTK_TEX4TPP
105 static filter_robot[] = { // actually how to filter non-perspective triangles.
106 S3DTK_TEX1TPP, S3DTK_TEXM1TPP, S3DTK_TEXM1TPP, S3DTK_TEX4TPP, S3DTK_TEXM4TPP
110 static int pa_3d_x_off = 0, pa_3d_y_off = 0;
113 static int pa_cache_search(grs_bitmap *bp);
114 static BOOL allocSurf(S3DTK_SURFACE *surf, ULONG width, ULONG height, ULONG bpp, ULONG format);
115 extern uint texmerge_get_unique_id( grs_bitmap * bmp );
116 extern void decode_row(grs_bitmap * bmp, int y);
117 static unsigned get_pow2(unsigned wh);
118 static unsigned long dma_get(void);
119 static void dma_put(unsigned long d);
120 static int dma_space(void);
121 static int CheckForSpecificCard(void);
126 int pa_init(void) // init library.
130 void pa_reset(void) // cleans up library.
134 int pa_detect(int mode) // detect card and whether mode is supported.
138 void pa_set_mode(int mode) // sets display mode if valid PA mode.
142 // type 0==0..63, 1==0..255.
143 void pa_update_clut(unsigned char *pal, int start, int count, int type)
147 void pa_save_clut(void)
151 void pa_restore_clut(void)
155 void pa_step_up(int r, int g, int b)
159 // get the address of a card's framebuffer and lock it in.
160 void *pa_get_buffer_address(int which)
164 void pa_clear_buffer(int buffer, ushort color)
169 void pa_set_3d_offset(int x, int y) // where on screen the triangles should be drawn.
173 void pa_draw_tmap(grs_bitmap * srcb, g3ds_tmap * tmap, int transparency_on, int lighting_on, int perspective, fix min_z)
177 void pa_draw_flat(g3ds_tmap *tmap, int color, int alpha)
182 // perform a blit using hw if screen to screen, otherwise copy mem to mem.
184 void pa_blit(grs_bitmap *dst, int dx, int dy, grs_bitmap *src, int sx, int sy, int w, int h)
189 // perform a transparent blit using hw if screen to screen, otherwise copy mem to mem.
191 void pa_blit_transparent(grs_bitmap *dst, int dx, int dy, grs_bitmap *src, int sx, int sy, int w, int h)
196 // performs 2d scaling by applying a bitmap to a 3D sqaure and using the texture mapper to draw it.
197 // NOTE:Only support RLE bitmaps.
199 void pa_blit_scale(grs_bitmap *source_bmp, grs_bitmap *dest_bmp,
200 int x0, int y0, int x1, int y1,
201 fix u0, fix v0, fix u1, fix v1, int orient
206 int pa_blit_lit(grs_bitmap *dst, int dx, int dy, grs_bitmap *src, int sx, int sy, int w, int h)
210 int pa_rect(int sx, int sy, int ex, int ey)
214 void pa_swap_buffer(void)
218 #pragma off (unreferenced)
219 void pa_ibitblt(void *src, void *dst, void *mask)
220 #pragma on (unreferenced)
225 // Allocate space for TEX_CACHE textures on the 3D card.
227 void pa_init_cache(void)
232 // implements a primitive LRU to keep from destroying active textures. Primitive because it uses
233 // an array search to find the oldest element.
235 static int pa_cache_search(grs_bitmap *bmp)
239 /***************************************************************************
241 * Memory management routines
243 ***************************************************************************/
244 static BOOL initMemoryBuffer(void)
248 static void allocInit(S3DTK_LPFUNCTIONLIST pS3DTK_Funct)
252 static BOOL allocSurf(S3DTK_SURFACE *surf, ULONG width, ULONG height, ULONG bpp, ULONG format)
256 /* convert width/height to power of 2; if power of 2, return it. Else
257 subtract 1 from next higher power of 2 */
258 static unsigned get_pow2(unsigned wh)
262 int pa_dma_poll(void)
266 static unsigned long dma_get(void)
270 static void dma_put(unsigned long d)
274 // return number of free entries in dma_buf
275 static int dma_space(void)
279 static void dma_add_verts(int nv)
283 static void dma_get_verts(void)
287 // see's if a command of 'type' is in dma buffer. Intended use is to serialize access to scale sprite buffer.
288 static int op_pending(int type)
293 // waits for current async op to complete.
295 static pa_idle_cnt[2]; //$$
308 //used in Rendition version, but not in S3 version
309 void pa_about_to_flip()
314 void pa_set_write_mode (int mode)
319 void pa_set_frontbuffer_current(void)
323 #endif // defined POLY_ACC