gfx.c 5.06 KB

/*====================================================================
 * gfx.c
 *
 * Audio performance monitoring tool graphics routines
 *
 * Copyright 1995, 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 <ramrom.h>
#include <assert.h>
#include <sched.h>
#include "misc.h"
#include "music.h"
#include "audio.h"
#include "cursor.h"
#include "musicUI.h"
#include "utils.h"		/* romCopy */


u8          *staticSegment = 0;
u64	    dram_stack[SP_DRAM_STACK_SIZE64];
Gfx         *glistp;


extern GFXInfo              gInfo[];
extern OSMesgQueue		    gfxFrameMsgQ;
extern OSMesg			    gfxFrameMsgBuf[MAX_MESGS];
extern OSSched              sc;


void
initGFX() 
{    
    int len = _staticSegmentRomEnd - _staticSegmentRomStart;
    staticSegment = _yieldSegmentEnd;
    romCopy(_staticSegmentRomStart, staticSegment, len);
    
    gInfo[0].msg.gen.type = OS_SC_DONE_MSG;
    gInfo[0].cfb = cfb_16_a;
    gInfo[1].msg.gen.type = OS_SC_DONE_MSG;
    gInfo[1].cfb = cfb_16_b;
}

void
createGfxTask(GFXInfo *i) 
{
    u32             clearcolor;
    Dynamic         *dynamicp;
    OSScTask        *t;
    Gfx *               glistpBegin;


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

    glistpBegin = glistp;

    
    /**** Tell RCP where each segment is *****/
    gSPSegment(glistp++, 0, 0);
    gSPSegment(glistp++, STATIC_SEGMENT,  osVirtualToPhysical(staticSegment));
    gSPSegment(glistp++, DYNAMIC_SEGMENT, osVirtualToPhysical(dynamicp));

    /**** Graphics pipeline state initialization ****/
    gSPDisplayList(glistp++, setup_rspstate);
    gSPDisplayList(glistp++, setup_rdpstate);
    gDPSetDepthImage(glistp++, osVirtualToPhysical(zbuffer));
    
    /**** clear z, z = max z, dz = 0 ****/
    gDPPipeSync(glistp++);
    gDPSetCycleType(glistp++, G_CYC_FILL);

    gDPSetColorImage(glistp++, G_IM_FMT_RGBA, G_IM_SIZ_16b, SCREEN_WD,
		osVirtualToPhysical(zbuffer));
    gDPSetFillColor(glistp++, GPACK_ZDZ(G_MAXFBZ,0) << 16 |
	GPACK_ZDZ(G_MAXFBZ,0));
    gDPFillRectangle(glistp++, 0, 0, SCREEN_WD-1, SCREEN_HT-1);
	
    /**** Clear framebuffer cvg = FULL or 1 ****/
    gDPPipeSync(glistp++);
    gDPSetColorImage(glistp++, G_IM_FMT_RGBA, G_IM_SIZ_16b, SCREEN_WD,
	osVirtualToPhysical(i->cfb));
    clearcolor = GPACK_RGBA5551(76, 76, 76, 1) << 16 | 
    		 GPACK_RGBA5551(76, 76, 76, 1);
    gDPSetFillColor(glistp++, clearcolor);
    gDPFillRectangle(glistp++, 0, 0, SCREEN_WD-1, SCREEN_HT-1);

    gDPPipeSync(glistp++);
    gDPSetCycleType(glistp++, G_CYC_1CYCLE);

    assert((void *)glistp < (void *)&i->msg);

    /* Draw music objects. */

    spInit (&glistp);			/* Initialize Sprites */

    UIDraw (&glistp); 

    Crsr_Draw (dynamicp);       /* This should be the last object drawn since it needs to be on top */

    spFinish (&glistp);

    glistp--; 


    
    /**** Force top-level display list to have an END. ****/
    gDPFullSync(glistp++);
    gSPEndDisplayList(glistp++);

    assert (glistp - glistpBegin < NUM_GFX_CMDS);

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

    /* build graphics task */
    t = &i->task;
    t->list.t.type = M_GFXTASK;
    t->list.t.flags = 0x0;
    t->list.t.ucode_boot = (u64 *)rspbootTextStart;
    t->list.t.ucode_boot_size =
        ((int) rspbootTextEnd - (int) rspbootTextStart);
    t->list.t.ucode = (u64 *) gspFast3DTextStart;
    t->list.t.ucode_size = 0;
    t->list.t.ucode_data = (u64 *) gspFast3DDataStart;
    t->list.t.ucode_data_size = 2048;
    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.data_ptr = (u64 *) dynamicp->glist;
    t->list.t.data_size = (int)(glistp - dynamicp->glist) * sizeof (Gfx);
    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;
    
    assert(t->list.t.data_size < NUM_GFX_CMDS*sizeof(Gfx));
    
    osSendMesg(osScGetCmdQ(&sc), (OSMesg) t, OS_MESG_BLOCK);
}