gfx.c 10.8 KB
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412
/*====================================================================
 * gfx.c
 *
 * Synopsis:
 *
 * This code implements the application graphics stuff
 * 
 * 
 * 
 * Copyright 1993, Silicon Graphics, Inc.
 * All Rights Reserved.
 *
 * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics,
 * Inc.; the contents of this file may not be disclosed to third
 * parties, copied or duplicated in any form, in whole or in part,
 * without the prior written permission of Silicon Graphics, Inc.
 *
 * RESTRICTED RIGHTS LEGEND:
 * Use, duplication or disclosure by the Government is subject to
 * restrictions as set forth in subdivision (c)(1)(ii) of the Rights
 * in Technical Data and Computer Software clause at DFARS
 * 252.227-7013, and/or in similar or successor clauses in the FAR,
 * DOD or NASA FAR Supplement. Unpublished - rights reserved under the
 * Copyright Laws of the United States.
 *====================================================================*/

#include <ultralog.h>
#include "stats.h"

#include "gfx.h"

extern OSSched         sc;
extern OSMesgQueue     *sched_cmdQ;
extern OSMesgQueue     gfxFrameMsgQ;

extern s16      peaksL[],peaksR[];
extern OSTime   rspTimes[];
extern OSTime   cpuTimes[];
extern s32      usedVoices[];
extern s16      rspTimeCt,cpuTimeCt,usedVsCt;

extern OSTime   tTime[];
extern u32      tTimeCt;
extern u32      frameClockFactor;
extern u32      numAudCmds[];
extern u32      numDMAs[];
extern u32      numDMABufs[];
extern u32      numSynUpds[];
extern u32      numSeqEvts[];
/*
 * graphics globals
 */
GFXInfo         gInfo[2];
Gfx             *glistp;

void doStats(Dynamic *dynamicp);
void setNumVal(char *str, u32 index, u32 val);

#define NUM_TSTRINGS  9
char *messStr[]  = { "Cmmds 00000", 
		     "DMA's 00000",
		     "DMA Bufs 00000",
		     "Syn Upds 00000",
		     "Seq Evts 00000",
		     "RSP",
		     "CPU",
		     "Vcs",
		     "L  R"
 };

u32  scrn_cood[NUM_TSTRINGS][2] = {CMMD_STR_LEFT, CMMD_STR_TOP, 
				   DMAS_STR_LEFT, DMAS_STR_TOP,
				   DMAB_STR_LEFT, DMAB_STR_TOP,
				   UPDS_STR_LEFT, UPDS_STR_TOP,
				   EVTS_STR_LEFT, EVTS_STR_TOP,
				   RSP_STR_LEFT,  RSP_STR_TOP, 
				   CPU_STR_LEFT,  CPU_STR_TOP,
				   VCS_STR_LEFT,  VCS_STR_TOP,
				   L_R_STR_LEFT,  L_R_STR_TOP 
};


void initGFX(void) 
{    
    u32  cfbPtr;

    cfbPtr = (u32)cfb_16_a;
    cfbPtr = ((cfbPtr + 0x3F) & ~0x3F);
    gInfo[0].cfb = (unsigned short*)cfbPtr;

    cfbPtr = (u32)cfb_16_b;
    cfbPtr = ((cfbPtr + 0x3F) & ~0x3F);
    gInfo[1].cfb = (unsigned short*)cfbPtr;
    gInfo[1].msg.gen.type = OS_SC_DONE_MSG;
    gInfo[0].msg.gen.type = OS_SC_DONE_MSG;
    /* The Vi manager was started by scheduler by this point in time */
    osViSetSpecialFeatures(OS_VI_DITHER_FILTER_ON);

}


void createGfxTask(GFXInfo *i) 
{
    static int firsttime = 1;
    Dynamic    *dynamicp;
    OSScTask   *t;


    /**** pointers to build the display list. ****/
    dynamicp = &i->dp;
    glistp   = i->dp.glist;

    /**** Tell RCP where each segment is  ****/
    gSPSegment(glistp++, 0, 0);	/* physical addressing segment */


    /**** Graphics pipeline state initialization ****/
    gSPDisplayList(glistp++, setup_rspstate);


    if (firsttime) {
        gSPDisplayList(glistp++, rdpstateinit_dl);
	firsttime = 0;
    }

    gSPDisplayList(glistp++, setup_rdpstate);


    /**** clear zbuffer, z = max z, dz = 0  ****/
    gDPPipeSync(glistp++);

    gDPSetCycleType(glistp++, G_CYC_FILL);


    /**** Clear framebuffer cvg = FULL or 1  ****/
    gDPPipeSync(glistp++);

    gDPSetColorImage(glistp++, G_IM_FMT_RGBA, G_IM_SIZ_16b, SCREEN_WD,
		     osVirtualToPhysical(i->cfb));

    /* clearcolor is 32-bits (2 pixels wide) because fill mode
     * does two pixels at a time.
     */

    gDPSetFillColor(glistp++, (GPACK_RGBA5551(0, 0, 0, 1) << 16 | 
			       GPACK_RGBA5551(0, 0, 0, 1)));

    gDPFillRectangle(glistp++, 0, 0, SCREEN_WD-1, SCREEN_HT-1);

    gDPPipeSync(glistp++);


    /**** Draw objects */

    doStats(dynamicp);

    /**** Put an end on the top-level display list  ****/
    gDPFullSync(glistp++);
    gSPEndDisplayList(glistp++);


    /* Flush the dynamic segment */
/*    osWritebackDCache(&i->dp, (s32)glistp - (s32)&i->dp); */
    osWritebackDCacheAll();

    /* build graphics task */
    t = &i->task;
    t->list.t.data_ptr = (u64 *) dynamicp->glist;
    t->list.t.data_size = (s32)(glistp - dynamicp->glist) * sizeof (Gfx);
    t->list.t.type = M_GFXTASK;
    t->list.t.flags = 0x0;
    t->list.t.ucode_boot = (u64 *)rspbootTextStart;
    t->list.t.ucode_boot_size = ((s32) rspbootTextEnd - 
				 (s32) rspbootTextStart);
    t->list.t.ucode = (u64 *) gspFast3DTextStart;
    t->list.t.ucode_data = (u64 *) gspFast3DDataStart;
    t->list.t.ucode_data_size = SP_UCODE_DATA_SIZE;
    t->list.t.dram_stack = (u64 *) dram_stack;
    t->list.t.dram_stack_size = SP_DRAM_STACK_SIZE8;
    t->list.t.output_buff = (u64 *) 0x0;
    t->list.t.output_buff_size = (u64 *) 0x0;
    t->list.t.yield_data_ptr = (u64 *) gfxYieldBuf;
    t->list.t.yield_data_size = OS_YIELD_DATA_SIZE;

    t->next     = 0;                   /* paranoia */
    t->flags	= (OS_SC_NEEDS_RSP | OS_SC_NEEDS_RDP | OS_SC_LAST_TASK |
		   OS_SC_SWAPBUFFER);
    t->msgQ     = &gfxFrameMsgQ;       /* reply to when finished */
    t->msg      = (OSMesg)&i->msg;     /* reply with this message */
    t->framebuffer = (void *)i->cfb;
    t->d.gd.endTicks = 0;
    t->d.gd.numYields = 0;
    osSendMesg(sched_cmdQ, (OSMesg) t, OS_MESG_BLOCK);  
}

#if 0
extern unsigned short fontTex[];
#endif
#include "font4bI.c"
Gfx setup_font[] = {
    gsSPTexture (0x8000, 0x8000, 0, G_TX_RENDERTILE, G_ON), 
    gsDPPipeSync(),
    gsSPClearGeometryMode(G_SHADE | G_SHADING_SMOOTH | G_CULL_BOTH |
			  G_FOG | G_LIGHTING | G_LOD ),

    gsDPSetRenderMode (G_RM_OPA_SURF, G_RM_OPA_SURF2),

    gsDPSetCombineMode (G_CC_DECALRGB, G_CC_DECALRGB), 
    gsDPSetTexturePersp (G_TP_NONE),
    gsDPSetTextureFilter (G_TF_POINT),

    gsDPPipeSync(),
    gsSPEndDisplayList(),
};

void doStats(Dynamic *dynamicp)
{
    s16   peakL = 0, peakR = 0;
    s32   c, left, top, right;
    u32   index;
    static u32 fct = 0;
    u32   mCt;
    u8    mChar;
    u32   tile_left, tile_top, tile_right, tile_bottom;
    u32   scrn_left, scrn_top;
    u32   str_scrn_left, str_scrn_top;
    u32   s;
    u32   messageCt = 0;
    char  *messageSt;
    u32   val;


    gDPPipeSync(glistp++);
    gDPSetCycleType(glistp++, G_CYC_1CYCLE);
    gDPSetPrimColor(glistp++, 0, 0, 120, 120, 120, 255);
    gDPSetCombineMode(glistp++, G_CC_PRIMITIVE, G_CC_PRIMITIVE);
    gDPSetRenderMode(glistp++, G_RM_OPA_SURF, G_RM_OPA_SURF2);

    for(c = 0; c < NUM_PEAKS; c++)
    {
	if(peakL < peaksL[c])
	    peakL = peaksL[c];
	if(peakR < peaksR[c])
	    peakR = peaksR[c];
    }
    peakL = peakL >> 8;
    peakR = peakR >> 8;

    /* draw peak meter background */
    gDPFillRectangle(glistp++, PEAKL_LEFT, PEAK_TOP, PEAKL_RIGHT, PEAK_BASE);
    gDPFillRectangle(glistp++, PEAKR_LEFT, PEAK_TOP, PEAKR_RIGHT, PEAK_BASE);

    /* draw rsp and cpu backgrounds */
    gDPFillRectangle(glistp++, RSP_LEFT, RSP_TOP, RSP_RIGHT, RSP_BASE);
    gDPFillRectangle(glistp++, CPU_LEFT, CPU_TOP, CPU_RIGHT, CPU_BASE);
    gDPFillRectangle(glistp++, VOX_LEFT, VOX_TOP, VOX_RIGHT, VOX_BASE);

    gDPPipeSync(glistp++);
    gDPSetPrimColor(glistp++, 0, 0, 0, 240, 0, 255);

    /* draw peak meters */
    gDPFillRectangle(glistp++, PEAKL_LEFT, PEAK_BASE - peakL, PEAKL_RIGHT, PEAK_BASE);
    gDPFillRectangle(glistp++, PEAKR_LEFT, PEAK_BASE - peakR, PEAKR_RIGHT, PEAK_BASE);

    gDPPipeSync(glistp++);


    index = cpuTimeCt;

    for(c = 0; c < NUM_TIMES; c++, index++)
    {
	if(index == NUM_TIMES)
	    index = 0;
	left = CPU_LEFT + ( c * BAR_WIDTH );
	right = left + BAR_WIDTH;
	top = CPU_BASE - ((u32)cpuTimes[index] / frameClockFactor); 
	gDPFillRectangle(glistp++, left, top, right, CPU_BASE);

    }

    index = rspTimeCt;

    for(c = 0; c < NUM_TIMES; c++, index++)
    {
	if(index == NUM_TIMES)
	    index = 0;
	left = RSP_LEFT + ( c * BAR_WIDTH );
	right = left + BAR_WIDTH;
	top = RSP_BASE - (u32)(rspTimes[index] /frameClockFactor ); 
	gDPFillRectangle(glistp++, left, top, right, RSP_BASE); 
    }

    index = usedVsCt;

    for(c = 0; c < NUM_TIMES; c++, index++)
    {
	if(index == NUM_TIMES)
	    index = 0;
	if(usedVoices[index])
	{
	    left = VOX_LEFT + ( c * BAR_WIDTH );
	    right = left + BAR_WIDTH;
	    top = VOX_BASE - usedVoices[index];
	    gDPFillRectangle(glistp++, left, top, right, VOX_BASE); 
	}
    }

    gSPDisplayList(glistp++, setup_font);
 
    
    for(s = 0; s < NUM_TSTRINGS; s++)
    {
	switch(s)
	{
	    case 0: /* commands string */
		for(val = 0, c = 0; c < MAX_PROF_CT; c++)
		    if(numAudCmds[c] > val)
			val = numAudCmds[c];
		setNumVal(messStr[0], 6, val);
		break;
	    case 1: /* number dma's */
		for(val = 0, c = 0; c < MAX_PROF_CT; c++)
		    if(numDMAs[c] > val)
			val = numDMAs[c];
		setNumVal(messStr[1], 6, val);
		break;
	    case 2: /* number DMA Bufs */
		for(val = 0, c = 0; c < MAX_PROF_CT; c++)
		    if(numDMABufs[c] > val)
			val = numDMABufs[c];
		setNumVal(messStr[2], 9, val);
		break;
	    case 3: /* number synth updates used */
		for(val = 0, c = 0; c < MAX_PROF_CT; c++)
		    if(numSynUpds[c] > val)
			val = numSynUpds[c];
		setNumVal(messStr[3], 9, val);
		break;
	    case 4: /* number seq events used */
		for(val = 0, c = 0; c < MAX_PROF_CT; c++)
		    if(numSeqEvts[c] > val)
			val = numSeqEvts[c];
		setNumVal(messStr[4], 9, val);
		break;
	}

	str_scrn_left = scrn_cood[s][0];
	str_scrn_top = scrn_cood[s][1];

	messageSt = messStr[s]; 

	for(mCt = 0; messageSt[mCt] != 0; mCt++)
	{

	    mChar = messageSt[mCt];
	    if(mChar != ' ')
	    {
		mChar -= '!';
		tile_left = (mChar%8) * 10;
		tile_top = (mChar/8) * 16;
		tile_right = tile_left + 10;
		tile_bottom = tile_top + 16;
		scrn_left = ((mCt%28) * 10) + str_scrn_left;
		scrn_top = ((mCt/28) * 16) + str_scrn_top;

#if 0
		gDPLoadTextureTile (glistp++, fontTex, G_IM_FMT_RGBA, G_IM_SIZ_16b, 80, 192, 
				tile_left, tile_top, tile_right, tile_bottom, 0,
				G_TX_WRAP | G_TX_NOMIRROR, G_TX_WRAP | G_TX_NOMIRROR,
				G_TX_NOMASK, G_TX_NOMASK, G_TX_NOLOD, G_TX_NOLOD);
#endif
		gDPLoadTextureTile_4b (glistp++, font_tx, G_IM_FMT_I, 80, 192, 
				tile_left, tile_top, tile_right, tile_bottom, 0,
				G_TX_WRAP | G_TX_NOMIRROR, G_TX_WRAP | G_TX_NOMIRROR,
				G_TX_NOMASK, G_TX_NOMASK, G_TX_NOLOD, G_TX_NOLOD);


		gDPLoadSync(glistp++);

		gSPTextureRectangle(glistp++, (scrn_left<<2), (scrn_top<<2), 
				    ((scrn_left+10)<<2), ((scrn_top+16)<<2), 
				    G_TX_RENDERTILE, (tile_left << 5), (tile_top << 5), 
				    (1 << 10), (1 << 10));

		gDPPipeSync(glistp++);
	    }
	}
	/* messageCt--; */
    }
}


void setNumVal(char *str, u32 index, u32 val)
{
    str[index++] = (val / 10000) + '0';
    val = val % 10000;
    str[index++] = (val / 1000) + '0';
    val = val % 1000;
    str[index++] = (val / 100) + '0';
    val = val % 100;
    str[index++] = (val / 10) + '0';
    val = val % 10;
    str[index++] = val + '0';
    str[index] = 0;
}