gfx.c 3.45 KB
#include <assert.h>

#include "gfx.h"
#include "viewer.h"
#include "pagetop.h"
#include "pagegame.h"
#include "pagebind.h"
#include "pagecontrol.h"
#include "pagegpak.h"
#include "pagecpak.h"
#include "status.h"

extern OSMesgQueue  *gpSchedCmdQ;
extern GFXInfo       gpGfxInfo[];

void initGFX(void) 
{   
    gpGfxInfo[0].msg.gen.type = OS_SC_DONE_MSG;
    gpGfxInfo[0].cfb = cfb_16_a;
    gpGfxInfo[1].msg.gen.type = OS_SC_DONE_MSG;
    gpGfxInfo[1].cfb = cfb_16_b;

    /* The Vi manager was started by scheduler by this point in time */
    osViSetSpecialFeatures(OS_VI_DITHER_FILTER_ON);
}

void createGfxTask(GFXInfo *i) 
{
    Dynamic *pDynamic;
    OSScTask *t;

    pDynamic = &i->dp;
    gpGfxList   = i->dp.glist;
    assert((void *)gpGfxList < (void *)&i->msg);

    gSPDisplayList(gpGfxList++, rdpinit_dl);
    gSPDisplayList(gpGfxList++, rspinit_dl);

    gDPPipeSync(gpGfxList++);
    gDPSetCycleType(gpGfxList++, G_CYC_FILL);
    if (osViGetCurrentMode()==OS_VI_NTSC_HAF1) {
        gDPSetColorImage(gpGfxList++, G_IM_FMT_RGBA, G_IM_SIZ_16b, SCREEN_WD,
                         osVirtualToPhysical(i->cfb));
    } else if (osViGetCurrentMode()==OS_VI_NTSC_LAN1) {
        gDPSetColorImage(gpGfxList++, G_IM_FMT_RGBA, G_IM_SIZ_16b, SCREEN_WD/2,
                         osVirtualToPhysical(i->cfb));
    }
    gDPSetFillColor(gpGfxList++, (GPACK_RGBA5551(0, 0, 0, 1) << 16 | 
                   GPACK_RGBA5551(0, 0, 0, 1)));
    gDPFillRectangle(gpGfxList++, 0, 0, SCREEN_WD-1, SCREEN_HT-1);
    gDPPipeSync(gpGfxList++);

    switch (gPageNo) {
        case PAGE_TOP: 
            doPageTop();
            break;
        case PAGE_GAME:
            doPageGame();
            break;
        case PAGE_BIND:
            doPageBind();
            break;
        case PAGE_CONTROL:
            doPageControl();
            break;
#ifdef PAK_COPY
        case PAGE_GPAK:
            doPageGpak();
            break;
        case PAGE_CPAK:
            doPageCpak();
            break;
#endif
        default:
            break;
    };

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

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

    /* build graphics task */
    t = &i->task;
    t->list.t.data_ptr = (u64 *) pDynamic->glist;
    t->list.t.data_size = (s32)(gpGfxList - pDynamic->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     = &gGfxFrameMsgQ;       /* reply to when finished */
    t->msg      = (OSMesg)&i->msg;     /* reply with this message */
    t->framebuffer = (void *)i->cfb;
#ifndef _FINALROM
    t->totalTime = 0;
#endif
    osSendMesg(gpSchedCmdQ, (OSMesg) t, OS_MESG_BLOCK); 
}