#include #include #include #include #include "dma.h" #include "vif.h" #include "vu1.h" #include "gif.h" #include "gs.h" #include "material.h" #include "dmacalls.h" #include "vu1code.h" #include "switches.h" #include "render.h" namespace NxPs2 { uint8 *pSubroutine; uint32 *p_patch_PRMODE; uint32 *p_patch_ALPHA; uint32 *p_patch_ALPHA2; //----------------------------------------------------------- // H A N D L I N G D M A S U B R O U T I N E S //----------------------------------------------------------- // begin a subroutine uint8 *BeginDmaSubroutine(void) { dma::Align(0,16); pSubroutine = dma::pLoc; vu1::Loc = vu1::Buffer = 0; return pSubroutine; } // end a subroutine and return its address void EndDmaSubroutine(void) { ((uint16 *)pSubroutine)[1] |= vu1::Loc&0x3FF; } #if 0 // call a subroutine, Path1 void Gosub1(uint Num) { uint8 *pSub = Subroutines[Num]; dma::Tag(dma::call, 0, (uint)pSub); vif::BASE(vu1::Loc); vif::OFFSET(0); vu1::Loc += ((uint16 *)pSub)[1]; } // call a subroutine, Path2 void Gosub2(uint Num) { dma::Tag(dma::call, 0, (uint)Subroutines[Num]); vif::NOP(); vif::NOP(); } #endif //----------------------------------------- // D M A S U B R O U T I N E S //----------------------------------------- void BuildDmaSubroutines(void) { //------------------------------- // C L E A R V R A M //------------------------------- dma::BeginSub(dma::next); dma::BeginTag(dma::end,0); vif::BeginDIRECT(); gif::BeginTag2(gs::A_D, 1, PACKED, SPRITE, 1); gs::Reg2(gs::FRAME_1, PackFRAME(0,16,PSMCT32,0)); gs::Reg2(gs::ZBUF_1, PackZBUF(0,0,1)); gs::Reg2(gs::TEST_1, PackTEST(0,0,0,0,0,0,1,ZALWAYS)); gs::Reg2(gs::XYOFFSET_1, PackXYOFFSET(0,0)); gs::Reg2(gs::SCISSOR_1, PackSCISSOR(0,0x7FF,0,0x7FF)); gs::Reg2(gs::PRMODECONT, PackPRMODECONT(1)); gs::Reg2(gs::SCANMSK, PackSCANMSK(0)); gs::Reg2(gs::FBA_1, PackFBA(0)); gs::Reg2(gs::DTHE, PackDTHE(0)); gs::Reg2(gs::TEXA, PackTEXA(0x00,0,0x80)); gs::Reg2(gs::RGBAQ, PackRGBAQ(0,0,0,0,0)); gs::Reg2(gs::XYZ2, PackXYZ(0,0,0)); gs::Reg2(gs::XYZ2, PackXYZ(0x3FFF,0x3FFF,0)); gs::Reg2(gs::TEXFLUSH, 0); gif::EndTag2(1); vif::EndDIRECT(); vif::FLUSH(); dma::EndTag(); dma::Gosubs[CLEAR_VRAM] = dma::EndSub(); //--------------------------------------- // F L I P A N D C L E A R //--------------------------------------- #define CLEAR_COLOUR 0x00706050 uint32 screen_w = HRES << 4; uint32 screen_h = VRES << 4; // begin Path2 subroutine dma::BeginSub(dma::ref); // wait in case something's still drawing from last frame vif::FLUSHA(); // send everything PATH2 vif::BeginDIRECT(); // register setup gif::BeginTag2(gs::A_D, 1, PACKED, 0, 0); p_patch_ALPHA = (uint32*) (dma::pLoc + 4); gs::Reg2(gs::ALPHA_1, PackALPHA(0,1,2,1,128)); // tweak this alpha for motion blur! gs::Reg2(gs::DIMX, PackDIMX(-4,0,-3,1,2,-2,3,-1,-3,1,-4,0,3,-1,2,-2)); gs::Reg2(gs::DTHE, PackDTHE(1)); gs::Reg2(gs::FBA_1, PackFBA(0)); gs::Reg2(gs::FRAME_1, PackFRAME(DISPLAY_START,HRES/64,PSMCT16S,0x00000000)); gs::Reg2(gs::PRMODECONT, PackPRMODECONT(1)); gs::Reg2(gs::SCANMSK, PackSCANMSK(0)); gs::Reg2(gs::SCISSOR_1, PackSCISSOR(0,HRES - 1,0,VRES - 1)); gs::Reg2(gs::TEST_1, PackTEST(0,0,0,0,0,0,1,ZALWAYS)); gs::Reg2(gs::TEX0_1, PackTEX0(0,HRES/64,PSMCT32,10,10,1,DECAL,0,0,0,0,0)); gs::Reg2(gs::TEX1_1, PackTEX1(1,0,NEAREST,NEAREST,0,0,0)); gs::Reg2(gs::TEXFLUSH, 0); gs::Reg2(gs::XYOFFSET_1, PackXYOFFSET(0,0)); gs::Reg2(gs::ZBUF_1, PackZBUF(ZBUFFER_START,PSMZ24,0)); gif::EndTag2(0); // using a set of screen-high textured sprites, copy draw buffer to disp buffer and clear z-buffer gif::BeginTag2(gs::UV|gs::XYZ2<<4, 2, PACKED, SPRITE|TME|FST|ABE, 1); for (uint32 x=0x0000; x