Move some code out of the plugins into VideoCommon. No functional change.

git-svn-id: https://dolphin-emu.googlecode.com/svn/trunk@255 8ced0084-cf51-0410-be5f-012b33b47a6e
This commit is contained in:
hrydgard
2008-08-21 17:49:06 +00:00
parent 5e4da92d42
commit 3ef0eb979d
17 changed files with 52 additions and 297 deletions

View File

@ -1270,10 +1270,6 @@
RelativePath=".\Src\OpcodeDecoding.cpp"
>
</File>
<File
RelativePath=".\Src\OpcodeDecoding.h"
>
</File>
<File
RelativePath=".\Src\VertexHandler.cpp"
>
@ -1451,14 +1447,6 @@
>
</File>
</Filter>
<File
RelativePath=".\Src\Fifo.cpp"
>
</File>
<File
RelativePath=".\Src\Fifo.h"
>
</File>
<File
RelativePath=".\Src\Globals.cpp"
>

View File

@ -1,171 +0,0 @@
// Copyright (C) 2003-2008 Dolphin Project.
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, version 2.0.
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License 2.0 for more details.
// A copy of the GPL 2.0 should have been included with the program.
// If not, see http://www.gnu.org/licenses/
// Official SVN repository and contact information can be found at
// http://code.google.com/p/dolphin-emu/
#include <stdio.h>
#include <stdlib.h>
#include "Common.h"
#include "Utils.h"
#include "Fifo.h"
#include "main.h"
#include "OpcodeDecoding.h"
#define FIFO_SIZE (1024*1024)
FifoReader fifo;
static u8 *videoBuffer;
int size = 0;
int readptr = 0;
void Fifo_Init()
{
//VirtualFree((LPVOID)buffer,CMDBUFFER_SIZE,MEM_RELEASE);
videoBuffer = (u8*)VirtualAlloc(0, FIFO_SIZE, MEM_COMMIT, PAGE_READWRITE);
fifo.Init(videoBuffer, videoBuffer); //zero length. there is no data yet.
}
void Fifo_Shutdown()
{
VirtualFree(videoBuffer, FIFO_SIZE, MEM_RELEASE);
}
int FAKE_GetFifoSize()
{
if (size < readptr)
{
PanicAlert("GFX Fifo underrun encountered (size = %i, readptr = %i)", size, readptr);
}
return (size - readptr);
}
u8 FAKE_PeekFifo8(u32 _uOffset)
{
return videoBuffer[readptr + _uOffset];
}
u16 FAKE_PeekFifo16(u32 _uOffset)
{
return _byteswap_ushort(*(u16*)&videoBuffer[readptr + _uOffset]);
}
u32 FAKE_PeekFifo32(u32 _uOffset)
{
return _byteswap_ulong(*(u32*)&videoBuffer[readptr + _uOffset]);
}
u8 FAKE_ReadFifo8()
{
return videoBuffer[readptr++];
}
u16 FAKE_ReadFifo16()
{
u16 val = _byteswap_ushort(*(u16*)(videoBuffer+readptr));
readptr += 2;
return val;
}
u32 FAKE_ReadFifo32()
{
u32 val = _byteswap_ulong(*(u32*)(videoBuffer+readptr));
readptr += 4;
return val;
}
void FAKE_SkipFifo(u32 skip)
{
readptr += skip;
}
void Video_SendFifoData(BYTE *_uData)
{
memcpy(videoBuffer + size, _uData, 32);
size += 32;
if (size + 32 >= FIFO_SIZE)
{
if (FAKE_GetFifoSize() > readptr)
{
PanicAlert("FIFO out of bounds", "video-plugin", MB_OK);
exit(1);
}
DebugLog("FAKE BUFFER LOOPS");
memmove(&videoBuffer[0], &videoBuffer[readptr], FAKE_GetFifoSize());
// memset(&videoBuffer[FAKE_GetFifoSize()], 0, FIFO_SIZE - FAKE_GetFifoSize());
size = FAKE_GetFifoSize();
readptr = 0;
}
OpcodeDecoder_Run();
}
//TODO - turn inside out, have the "reader" ask for bytes instead
// See Core.cpp for threading idea
void Video_EnterLoop()
{
SCPFifoStruct &fifo = *g_VideoInitialize.pCPFifo;
// TODO(ector): Don't peek so often!
while (g_VideoInitialize.pPeekMessages())
{
if (fifo.CPReadWriteDistance < 1) //fifo.CPLoWatermark)
Sleep(1);
//etc...
// check if we are able to run this buffer
if ((fifo.bFF_GPReadEnable) && !(fifo.bFF_BPEnable && fifo.bFF_Breakpoint))
{
int count = 200;
while(fifo.CPReadWriteDistance > 0 && count)
{
// check if we are on a breakpoint
if (fifo.bFF_BPEnable)
{
//MessageBox(0,"Breakpoint enabled",0,0);
if (fifo.CPReadPointer == fifo.CPBreakpoint)
{
fifo.bFF_Breakpoint = 1;
g_VideoInitialize.pUpdateInterrupts();
break;
}
}
// read the data and send it to the VideoPlugin
u8 *uData = Memory_GetPtr(fifo.CPReadPointer);
EnterCriticalSection(&fifo.sync);
fifo.CPReadPointer += 32;
Video_SendFifoData(uData);
InterlockedExchangeAdd((LONG*)&fifo.CPReadWriteDistance, -32);
LeaveCriticalSection(&fifo.sync);
// increase the ReadPtr
if (fifo.CPReadPointer >= fifo.CPEnd)
{
fifo.CPReadPointer = fifo.CPBase;
//LOG(COMMANDPROCESSOR, "BUFFER LOOP");
// MessageBox(NULL, "loop", "now", MB_OK);
}
count--;
}
}
}
}

View File

@ -1,40 +0,0 @@
#ifndef _FIFO_H
#define _FIFO_H
#include "Common.h"
// inline for speed!
class FifoReader
{
u8 *ptr;
u8 *end;
u8 *tempPtr; //single element stack :P
u8 *tempEnd;
bool pushed;
public:
void Init(u8 *_ptr, u8 *_end)
{
ptr = _ptr; end = _end; pushed = false;
}
bool IsPushed() {return pushed;}
void Push(u8 *_ptr, u8 *_end) {pushed = true; tempPtr = ptr; tempEnd = end; ptr = _ptr; end = _end;}
void Pop() {pushed = false; ptr = tempPtr; end = tempEnd;}
u8 Peek8 (int offset) { return ptr[offset]; }
u16 Peek16(int offset) { return _byteswap_ushort(*(u16*)(ptr+offset)); }
u32 Peek32(int offset) { return _byteswap_ulong(*(u32*)(ptr+offset)); }
u8 Read8 () {return *ptr++;}
u16 Read16() {const u16 value = _byteswap_ushort(*((u16*)ptr)); ptr+=2; return value;}
u32 Read32() {const u32 value = _byteswap_ulong(*((u32*)ptr)); ptr+=4; return value;}
float Read32F() {const u32 value = _byteswap_ulong(*((u32*)ptr)); ptr+=4; return *(float*)&value;}
size_t GetRemainSize() const { return (int)(end - ptr); }
u8 *GetPtr() const { return ptr; }
void MoveEndForward() { end += 32; }
u8 *GetEnd() const { return end; }
};
extern FifoReader fifo;
void Fifo_Init();
void Fifo_Shutdown();
#endif

View File

@ -15,7 +15,7 @@ void Config::Load()
iniFile.Get("Hardware", "WindowedRes", &iWindowedRes, 0);
iniFile.Get("Hardware", "FullscreenRes", &iFSResolution, 0);
iniFile.Get("Hardware", "Fullscreen", &bFullscreen, 0);
iniFile.Get("Hardware", "RenderInMainframe", &renderToMainframe, true);
iniFile.Get("Hardware", "RenderInMainframe", &renderToMainframe, false);
iniFile.Get("Hardware", "VSync", &bVsync, 0);
if (iAdapter == -1)
iAdapter = 0;

View File

@ -1,37 +0,0 @@
#ifndef _OPCODE_DECODING_H
#define _OPCODE_DECODING_H
#include "PluginSpecs_Video.h"
#include "Common.h"
#define GX_NOP 0x00
#define GX_LOAD_BP_REG 0x61
#define GX_LOAD_CP_REG 0x08
#define GX_LOAD_XF_REG 0x10
#define GX_LOAD_INDX_A 0x20
#define GX_LOAD_INDX_B 0x28
#define GX_LOAD_INDX_C 0x30
#define GX_LOAD_INDX_D 0x38
#define GX_CMD_CALL_DL 0x40
#define GX_CMD_INVL_VC 0x48
#define GX_PRIMITIVE_MASK 0x78
#define GX_PRIMITIVE_SHIFT 3
#define GX_VAT_MASK 0x07
//these are defined 1/8th of their real values and without their top bit
#define GX_DRAW_QUADS 0x0 //0x80
#define GX_DRAW_TRIANGLES 0x2 //0x90
#define GX_DRAW_TRIANGLE_STRIP 0x3 //0x98
#define GX_DRAW_TRIANGLE_FAN 0x4 //0xA0
#define GX_DRAW_LINES 0x5 //0xA8
#define GX_DRAW_LINE_STRIP 0x6 //0xB0
#define GX_DRAW_POINTS 0x7 //0xB8
void OpcodeDecoder_Init();
void OpcodeDecoder_Shutdown();
void OpcodeDecoder_Run();
#endif

View File

@ -165,6 +165,11 @@ void Video_Initialize(SVideoInitialize* _pVideoInitialize)
}
void Video_EnterLoop()
{
Fifo_EnterLoop(g_VideoInitialize);
}
void Video_Prepare(void)
{
Renderer::Init(g_VideoInitialize);