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 char poly_acc_rcsid[] = "$Id: poly_acc.c,v 1.1.1.1 2001-01-19 03:30:14 bradleyb Exp $";
15 static unsigned poly_count;
26 #include "pa_enabl.h" // needs to occur early.
45 #define TEX_CACHE (64)
46 #define CHROMA_COLOR 0x0001
47 #define MODE_110 S3DTK_MODE640x480x15 // 640x480x15
49 #define DMA_VERT_WORDS (sizeof(S3DTK_VERTEX_TEX) / sizeof(unsigned long))
50 #define NDL 5 // stolen from main/game.h. how many filter levels there are.
52 enum { OP_TMAP, OP_FLAT, OP_BLIT, OP_BLIT_TRANSPARENT, OP_BLIT_SCALE };
57 extern ubyte scale_rle_data[1024]; // from 2d\scale.c
58 unsigned short pa_clut[256]; // translate from 8 bit pixels to 15 bit pixels.
59 static short pa_clut_save_buf[256]; // used to save/restore the clut.
60 int pa_filter_mode = NDL-1; // For Virge filtering control, set in Custom Detail Level menu.
63 static pa_initted = 0;
64 static pa_card_initted = 0; //$$hack, library doesn't seem to correctly init card twice.
65 static ULONG old_mode;
67 /* S3D Toolkit function list */
68 static S3DTK_LPFUNCTIONLIST pS3DTK_Funct;
69 static S3DTK_VERTEX_TEX verts[MAX_TMAP_VERTS];
70 static S3DTK_LPVERTEX_TEX trifan[MAX_TMAP_VERTS];
72 /* buffer definitions */
73 static int backBuffer = 1; /* index of back buffer */
74 static S3DTK_SURFACE displaySurf[2]; /* one for front buffer and one for back buffer */
75 static S3DTK_RECTAREA fullScreenRect = { 0, 0, 640, 480 };
77 /* physical properties */
78 static ULONG screenFormat = S3DTK_VIDEORGB15; /* format of the surface as defined in S3DTK.H */
79 static float width=640, height=480; /* screen's dimension */
81 // memory manager variables.
82 static ULONG totalMemory; /* frame buffer size */
83 static ULONG memoryUsed; /* frame buffer allocated */
84 static char *frameBuffer; /* linear address of frame buffer starts at */
87 static S3DTK_SURFACE cache_slots[TEX_CACHE];
92 } cache_tags[TEX_CACHE];
93 static int cache_age = 0;
96 static unsigned long dma_buf[DMA_SIZE]; // simulated dma ring buffer.
97 static int dma_head, dma_tail; // head and tail of ring buffer.
98 static op_extra_words[] = // how many extra words are needed besides the vertex info
99 { 7, 5, 10, 11, 5 }; // plus 1. avoids (head == tail) == (tail == head).
100 static filter_tmap[] = {
101 S3DTK_TEX1TPP, S3DTK_TEXM1TPP, S3DTK_TEX4TPP, S3DTK_TEX4TPP, S3DTK_TEXM4TPP
103 static filter_scale[] = {
104 S3DTK_TEX1TPP, S3DTK_TEX4TPP, S3DTK_TEX4TPP, S3DTK_TEX4TPP, S3DTK_TEX4TPP
106 static filter_robot[] = { // actually how to filter non-perspective triangles.
107 S3DTK_TEX1TPP, S3DTK_TEXM1TPP, S3DTK_TEXM1TPP, S3DTK_TEX4TPP, S3DTK_TEXM4TPP
111 static int pa_3d_x_off = 0, pa_3d_y_off = 0;
114 static int pa_cache_search(grs_bitmap *bp);
115 static BOOL allocSurf(S3DTK_SURFACE *surf, ULONG width, ULONG height, ULONG bpp, ULONG format);
116 extern uint texmerge_get_unique_id( grs_bitmap * bmp );
117 extern void decode_row(grs_bitmap * bmp, int y);
118 static unsigned get_pow2(unsigned wh);
119 static unsigned long dma_get(void);
120 static void dma_put(unsigned long d);
121 static int dma_space(void);
122 static int CheckForSpecificCard(void);
127 int pa_init(void) // init library.
131 void pa_reset(void) // cleans up library.
135 int pa_detect(int mode) // detect card and whether mode is supported.
139 void pa_set_mode(int mode) // sets display mode if valid PA mode.
143 // type 0==0..63, 1==0..255.
144 void pa_update_clut(unsigned char *pal, int start, int count, int type)
148 void pa_save_clut(void)
152 void pa_restore_clut(void)
156 void pa_step_up(int r, int g, int b)
160 // get the address of a card's framebuffer and lock it in.
161 void *pa_get_buffer_address(int which)
165 void pa_clear_buffer(int buffer, ushort color)
170 void pa_set_3d_offset(int x, int y) // where on screen the triangles should be drawn.
174 void pa_draw_tmap(grs_bitmap * srcb, g3ds_tmap * tmap, int transparency_on, int lighting_on, int perspective, fix min_z)
178 void pa_draw_flat(g3ds_tmap *tmap, int color, int alpha)
183 // perform a blit using hw if screen to screen, otherwise copy mem to mem.
185 void pa_blit(grs_bitmap *dst, int dx, int dy, grs_bitmap *src, int sx, int sy, int w, int h)
190 // perform a transparent blit using hw if screen to screen, otherwise copy mem to mem.
192 void pa_blit_transparent(grs_bitmap *dst, int dx, int dy, grs_bitmap *src, int sx, int sy, int w, int h)
197 // performs 2d scaling by applying a bitmap to a 3D sqaure and using the texture mapper to draw it.
198 // NOTE:Only support RLE bitmaps.
200 void pa_blit_scale(grs_bitmap *source_bmp, grs_bitmap *dest_bmp,
201 int x0, int y0, int x1, int y1,
202 fix u0, fix v0, fix u1, fix v1, int orient
207 int pa_blit_lit(grs_bitmap *dst, int dx, int dy, grs_bitmap *src, int sx, int sy, int w, int h)
211 int pa_rect(int sx, int sy, int ex, int ey)
215 void pa_swap_buffer(void)
219 #pragma off (unreferenced)
220 void pa_ibitblt(void *src, void *dst, void *mask)
221 #pragma on (unreferenced)
226 // Allocate space for TEX_CACHE textures on the 3D card.
228 void pa_init_cache(void)
233 // implements a primitive LRU to keep from destroying active textures. Primitive because it uses
234 // an array search to find the oldest element.
236 static int pa_cache_search(grs_bitmap *bmp)
240 /***************************************************************************
242 * Memory management routines
244 ***************************************************************************/
245 static BOOL initMemoryBuffer(void)
249 static void allocInit(S3DTK_LPFUNCTIONLIST pS3DTK_Funct)
253 static BOOL allocSurf(S3DTK_SURFACE *surf, ULONG width, ULONG height, ULONG bpp, ULONG format)
257 /* convert width/height to power of 2; if power of 2, return it. Else
258 subtract 1 from next higher power of 2 */
259 static unsigned get_pow2(unsigned wh)
263 int pa_dma_poll(void)
267 static unsigned long dma_get(void)
271 static void dma_put(unsigned long d)
275 // return number of free entries in dma_buf
276 static int dma_space(void)
280 static void dma_add_verts(int nv)
284 static void dma_get_verts(void)
288 // see's if a command of 'type' is in dma buffer. Intended use is to serialize access to scale sprite buffer.
289 static int op_pending(int type)
294 // waits for current async op to complete.
296 static pa_idle_cnt[2]; //$$
309 //used in Rendition version, but not in S3 version
310 void pa_about_to_flip()
315 void pa_set_write_mode (int mode)
320 void pa_set_frontbuffer_current(void)
324 #endif // defined POLY_ACC