2013-04-18 03:29:41 +00:00
|
|
|
// Copyright 2013 Dolphin Emulator Project
|
|
|
|
// Licensed under GPLv2
|
|
|
|
// Refer to the license.txt file included.
|
2010-06-09 01:37:08 +00:00
|
|
|
|
2014-09-09 04:24:49 +00:00
|
|
|
#include "Core/ConfigManager.h"
|
2014-02-17 10:18:15 +00:00
|
|
|
#include "Core/Core.h"
|
|
|
|
#include "Core/HW/Memmap.h"
|
|
|
|
|
|
|
|
#include "VideoBackends/Software/BPMemLoader.h"
|
|
|
|
#include "VideoBackends/Software/EfbCopy.h"
|
2014-03-29 02:22:15 +00:00
|
|
|
#include "VideoBackends/Software/EfbInterface.h"
|
2014-02-17 10:18:15 +00:00
|
|
|
#include "VideoBackends/Software/Rasterizer.h"
|
|
|
|
#include "VideoBackends/Software/Tev.h"
|
|
|
|
|
2014-09-17 01:04:37 +00:00
|
|
|
#include "VideoCommon/BoundingBox.h"
|
2014-03-29 02:22:15 +00:00
|
|
|
#include "VideoCommon/PixelEngine.h"
|
2014-02-17 10:18:15 +00:00
|
|
|
#include "VideoCommon/TextureDecoder.h"
|
2014-02-19 11:14:09 +00:00
|
|
|
#include "VideoCommon/VideoCommon.h"
|
2010-06-09 01:37:08 +00:00
|
|
|
|
|
|
|
|
|
|
|
void InitBPMemory()
|
|
|
|
{
|
2013-04-14 03:54:02 +00:00
|
|
|
memset(&bpmem, 0, sizeof(bpmem));
|
|
|
|
bpmem.bpMask = 0xFFFFFF;
|
2010-06-09 01:37:08 +00:00
|
|
|
}
|
|
|
|
|
2011-02-03 19:55:30 +00:00
|
|
|
void SWLoadBPReg(u32 value)
|
2010-06-09 01:37:08 +00:00
|
|
|
{
|
2013-04-14 03:54:02 +00:00
|
|
|
//handle the mask register
|
2010-06-09 01:37:08 +00:00
|
|
|
int address = value >> 24;
|
|
|
|
int oldval = ((u32*)&bpmem)[address];
|
|
|
|
int newval = (oldval & ~bpmem.bpMask) | (value & bpmem.bpMask);
|
|
|
|
|
2013-04-14 03:54:02 +00:00
|
|
|
((u32*)&bpmem)[address] = newval;
|
2010-06-09 01:37:08 +00:00
|
|
|
|
|
|
|
//reset the mask register
|
|
|
|
if (address != 0xFE)
|
|
|
|
bpmem.bpMask = 0xFFFFFF;
|
|
|
|
|
2013-04-14 03:54:02 +00:00
|
|
|
SWBPWritten(address, newval);
|
2010-06-09 01:37:08 +00:00
|
|
|
}
|
|
|
|
|
2011-02-03 19:55:30 +00:00
|
|
|
void SWBPWritten(int address, int newvalue)
|
2010-06-09 01:37:08 +00:00
|
|
|
{
|
2013-04-14 03:54:02 +00:00
|
|
|
switch (address)
|
2010-12-31 06:45:18 +00:00
|
|
|
{
|
2013-04-14 03:54:02 +00:00
|
|
|
case BPMEM_SCISSORTL:
|
|
|
|
case BPMEM_SCISSORBR:
|
|
|
|
case BPMEM_SCISSOROFFSET:
|
|
|
|
Rasterizer::SetScissor();
|
|
|
|
break;
|
2010-06-09 01:37:08 +00:00
|
|
|
case BPMEM_SETDRAWDONE: // This is called when the game is done drawing (eg: like in DX: Begin(); Draw(); End();)
|
|
|
|
switch (bpmem.drawdone & 0xFF)
|
2013-04-14 03:54:02 +00:00
|
|
|
{
|
|
|
|
case 0x02:
|
2014-03-29 02:22:15 +00:00
|
|
|
PixelEngine::SetFinish(); // may generate interrupt
|
2013-04-14 03:54:02 +00:00
|
|
|
DEBUG_LOG(VIDEO, "GXSetDrawDone SetPEFinish (value: 0x%02X)", (bpmem.drawdone & 0xFFFF));
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
WARN_LOG(VIDEO, "GXSetDrawDone ??? (value 0x%02X)", (bpmem.drawdone & 0xFFFF));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
2010-06-09 01:37:08 +00:00
|
|
|
case BPMEM_PE_TOKEN_ID: // Pixel Engine Token ID
|
2013-04-14 03:54:02 +00:00
|
|
|
DEBUG_LOG(VIDEO, "SetPEToken 0x%04x", (bpmem.petoken & 0xFFFF));
|
2014-03-29 02:22:15 +00:00
|
|
|
PixelEngine::SetToken(static_cast<u16>(bpmem.petokenint & 0xFFFF), false);
|
2013-04-14 03:54:02 +00:00
|
|
|
break;
|
|
|
|
case BPMEM_PE_TOKEN_INT_ID: // Pixel Engine Interrupt Token ID
|
|
|
|
DEBUG_LOG(VIDEO, "SetPEToken + INT 0x%04x", (bpmem.petokenint & 0xFFFF));
|
2014-03-29 02:22:15 +00:00
|
|
|
PixelEngine::SetToken(static_cast<u16>(bpmem.petokenint & 0xFFFF), true);
|
2013-04-14 03:54:02 +00:00
|
|
|
break;
|
|
|
|
case BPMEM_TRIGGER_EFB_COPY:
|
|
|
|
EfbCopy::CopyEfb();
|
|
|
|
break;
|
|
|
|
case BPMEM_CLEARBBOX1:
|
2014-09-14 16:52:51 +00:00
|
|
|
BoundingBox::coords[BoundingBox::LEFT] = newvalue >> 10;
|
|
|
|
BoundingBox::coords[BoundingBox::RIGHT] = newvalue & 0x3ff;
|
2013-04-14 03:54:02 +00:00
|
|
|
break;
|
|
|
|
case BPMEM_CLEARBBOX2:
|
2014-09-14 16:52:51 +00:00
|
|
|
BoundingBox::coords[BoundingBox::TOP] = newvalue >> 10;
|
|
|
|
BoundingBox::coords[BoundingBox::BOTTOM] = newvalue & 0x3ff;
|
2013-04-14 03:54:02 +00:00
|
|
|
break;
|
2012-06-17 17:49:48 +00:00
|
|
|
case BPMEM_CLEAR_PIXEL_PERF:
|
2013-02-28 23:52:15 +00:00
|
|
|
// TODO: I didn't test if the value written to this register affects the amount of cleared registers
|
2014-03-29 02:22:15 +00:00
|
|
|
memset(EfbInterface::perf_values, 0, sizeof(EfbInterface::perf_values));
|
2012-06-17 17:49:48 +00:00
|
|
|
break;
|
2013-04-14 03:54:02 +00:00
|
|
|
case BPMEM_LOADTLUT0: // This one updates bpmem.tlutXferSrc, no need to do anything here.
|
2010-06-09 01:37:08 +00:00
|
|
|
break;
|
|
|
|
case BPMEM_LOADTLUT1: // Load a Texture Look Up Table
|
2013-04-14 03:54:02 +00:00
|
|
|
{
|
|
|
|
u32 tlutTMemAddr = (newvalue & 0x3FF) << 9;
|
2013-10-29 05:23:17 +00:00
|
|
|
u32 tlutXferCount = (newvalue & 0x1FFC00) >> 5;
|
2010-06-09 01:37:08 +00:00
|
|
|
|
2014-03-09 20:14:26 +00:00
|
|
|
u8 *ptr = nullptr;
|
2010-06-09 01:37:08 +00:00
|
|
|
|
2013-04-14 03:54:02 +00:00
|
|
|
// TODO - figure out a cleaner way.
|
2014-09-09 04:24:49 +00:00
|
|
|
if (SConfig::GetInstance().m_LocalCoreStartupParameter.bWii)
|
2012-01-29 20:17:22 +00:00
|
|
|
ptr = Memory::GetPointer(bpmem.tmem_config.tlut_src << 5);
|
2010-06-09 01:37:08 +00:00
|
|
|
else
|
2012-01-29 20:17:22 +00:00
|
|
|
ptr = Memory::GetPointer((bpmem.tmem_config.tlut_src & 0xFFFFF) << 5);
|
2010-06-09 01:37:08 +00:00
|
|
|
|
|
|
|
if (ptr)
|
2014-05-15 09:19:39 +00:00
|
|
|
memcpy(texMem + tlutTMemAddr, ptr, tlutXferCount);
|
2010-06-09 01:37:08 +00:00
|
|
|
else
|
2012-01-29 20:17:22 +00:00
|
|
|
PanicAlert("Invalid palette pointer %08x %08x %08x", bpmem.tmem_config.tlut_src, bpmem.tmem_config.tlut_src << 5, (bpmem.tmem_config.tlut_src & 0xFFFFF)<< 5);
|
2010-06-09 01:37:08 +00:00
|
|
|
break;
|
2013-04-14 03:54:02 +00:00
|
|
|
}
|
2012-11-03 14:36:40 +00:00
|
|
|
|
|
|
|
case BPMEM_PRELOAD_MODE:
|
|
|
|
if (newvalue != 0)
|
|
|
|
{
|
2013-01-09 09:19:18 +00:00
|
|
|
// TODO: Not quite sure if this is completely correct (likely not)
|
|
|
|
// NOTE: libogc's implementation of GX_PreloadEntireTexture seems flawed, so it's not necessarily a good reference for RE'ing this feature.
|
2012-11-03 14:36:40 +00:00
|
|
|
|
2013-01-09 09:19:18 +00:00
|
|
|
BPS_TmemConfig& tmem_cfg = bpmem.tmem_config;
|
|
|
|
u8* src_ptr = Memory::GetPointer(tmem_cfg.preload_addr << 5); // TODO: Should we add mask here on GC?
|
|
|
|
u32 size = tmem_cfg.preload_tile_info.count * TMEM_LINE_SIZE;
|
|
|
|
u32 tmem_addr_even = tmem_cfg.preload_tmem_even * TMEM_LINE_SIZE;
|
|
|
|
|
|
|
|
if (tmem_cfg.preload_tile_info.type != 3)
|
|
|
|
{
|
|
|
|
if (tmem_addr_even + size > TMEM_SIZE)
|
|
|
|
size = TMEM_SIZE - tmem_addr_even;
|
|
|
|
|
|
|
|
memcpy(texMem + tmem_addr_even, src_ptr, size);
|
|
|
|
}
|
|
|
|
else // RGBA8 tiles (and CI14, but that might just be stupid libogc!)
|
|
|
|
{
|
|
|
|
// AR and GB tiles are stored in separate TMEM banks => can't use a single memcpy for everything
|
|
|
|
u32 tmem_addr_odd = tmem_cfg.preload_tmem_odd * TMEM_LINE_SIZE;
|
|
|
|
|
2013-01-26 02:30:29 +00:00
|
|
|
for (unsigned int i = 0; i < tmem_cfg.preload_tile_info.count; ++i)
|
2013-01-09 09:19:18 +00:00
|
|
|
{
|
|
|
|
if (tmem_addr_even + TMEM_LINE_SIZE > TMEM_SIZE ||
|
2013-01-26 02:30:29 +00:00
|
|
|
tmem_addr_odd + TMEM_LINE_SIZE > TMEM_SIZE)
|
2013-01-09 09:19:18 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
memcpy(texMem + tmem_addr_even, src_ptr, TMEM_LINE_SIZE);
|
|
|
|
memcpy(texMem + tmem_addr_odd, src_ptr + TMEM_LINE_SIZE, TMEM_LINE_SIZE);
|
|
|
|
tmem_addr_even += TMEM_LINE_SIZE;
|
|
|
|
tmem_addr_odd += TMEM_LINE_SIZE;
|
|
|
|
src_ptr += TMEM_LINE_SIZE * 2;
|
|
|
|
}
|
|
|
|
}
|
2012-11-03 14:36:40 +00:00
|
|
|
}
|
2014-02-17 04:51:41 +00:00
|
|
|
break;
|
2012-11-03 14:36:40 +00:00
|
|
|
|
2014-09-17 16:46:23 +00:00
|
|
|
case BPMEM_TEV_COLOR_RA:
|
|
|
|
case BPMEM_TEV_COLOR_RA + 2:
|
|
|
|
case BPMEM_TEV_COLOR_RA + 4:
|
|
|
|
case BPMEM_TEV_COLOR_RA + 6:
|
2010-06-09 01:37:08 +00:00
|
|
|
{
|
|
|
|
int regNum = (address >> 1 ) & 0x3;
|
2014-03-10 15:15:40 +00:00
|
|
|
TevReg& reg = bpmem.tevregs[regNum];
|
2014-08-20 03:17:29 +00:00
|
|
|
bool is_konst = reg.type_ra != 0;
|
2010-06-09 01:37:08 +00:00
|
|
|
|
2014-08-20 03:17:29 +00:00
|
|
|
Rasterizer::SetTevReg(regNum, Tev::ALP_C, is_konst, static_cast<s16>(reg.alpha));
|
|
|
|
Rasterizer::SetTevReg(regNum, Tev::RED_C, is_konst, static_cast<s16>(reg.red));
|
2010-06-09 01:37:08 +00:00
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2014-09-17 16:46:23 +00:00
|
|
|
case BPMEM_TEV_COLOR_BG:
|
|
|
|
case BPMEM_TEV_COLOR_BG + 2:
|
|
|
|
case BPMEM_TEV_COLOR_BG + 4:
|
|
|
|
case BPMEM_TEV_COLOR_BG + 6:
|
2010-06-09 01:37:08 +00:00
|
|
|
{
|
|
|
|
int regNum = (address >> 1 ) & 0x3;
|
2014-03-10 15:15:40 +00:00
|
|
|
TevReg& reg = bpmem.tevregs[regNum];
|
2014-08-20 03:17:29 +00:00
|
|
|
bool is_konst = reg.type_bg != 0;
|
2010-06-09 01:37:08 +00:00
|
|
|
|
2014-08-20 03:17:29 +00:00
|
|
|
Rasterizer::SetTevReg(regNum, Tev::GRN_C, is_konst, static_cast<s16>(reg.green));
|
|
|
|
Rasterizer::SetTevReg(regNum, Tev::BLU_C, is_konst, static_cast<s16>(reg.blue));
|
2010-06-09 01:37:08 +00:00
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2013-04-14 03:54:02 +00:00
|
|
|
}
|
2010-06-09 01:37:08 +00:00
|
|
|
}
|
|
|
|
|