- add DR_MOVE to ParseLinkedPrimitiveList

- Every textured polygon is affecting active DRAWENV texture page
- added rendering skip if unhandled primitive encountered
- add some 'unimplemented' methods required by Driver 2
- compilation fix
- added key bind to save VRAM
This commit is contained in:
Ilya Shurumov 2020-03-31 23:00:33 +06:00
parent 08403ce5c4
commit ee87194914
6 changed files with 116 additions and 10 deletions

View File

@ -28,7 +28,7 @@
#include <stdio.h>
#include <stdlib.h>
#include <SDL_syswm.h>
#include <SDL.h>
SDL_Window* g_window = NULL;
@ -1826,6 +1826,8 @@ void Emulator_SaveVRAM(const char* outputFileName, int x, int y, int width, int
#endif
#if defined(OGL) || defined(OGLES)
glBindFramebuffer(GL_READ_FRAMEBUFFER, vramFrameBuffer);
FILE* f = fopen(outputFileName, "wb");
if (f == NULL)
{
@ -1957,20 +1959,31 @@ void Emulator_DoDebugKeys()
if (keyboardState[SDL_SCANCODE_1])
{
g_wireframeMode ^= 1;
eprintf("wireframe mode: %d\n", g_wireframeMode);
}
if (keyboardState[SDL_SCANCODE_2])
{
g_texturelessMode ^= 1;
eprintf("textureless mode: %d\n", g_texturelessMode);
}
#if !defined(__EMSCRIPTEN__) && !defined(__ANDROID__)
if (keyboardState[SDL_SCANCODE_3])
{
eprintf("saving screenshot\n");
Emulator_TakeScreenshot();
}
#endif
if (keyboardState[SDL_SCANCODE_4])
{
eprintf("saving VRAM.TGA\n");
Emulator_SaveVRAM("VRAM.TGA", 0, 0, VRAM_WIDTH, VRAM_HEIGHT, TRUE);
}
lastTime = currentTime;
}
}
@ -2405,9 +2418,10 @@ IDirect3DTexture9* Emulator_GenerateTpage(unsigned short tpage, unsigned short c
{
unsigned short* tpage = (unsigned short*)SDL_malloc(TPAGE_WIDTH * TPAGE_HEIGHT * sizeof(unsigned short));
#if defined(OGL) || defined(OGLES)
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 256, 256, 0, GL_RGBA, GL_UNSIGNED_BYTE, &tpage[0]);
glReadPixels(tpageX, tpageY, TPAGE_WIDTH, TPAGE_HEIGHT, GL_RGBA, TEXTURE_FORMAT, &tpage[0]);
//glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 256, 256, 0, GL_RGBA, GL_UNSIGNED_BYTE, &tpage[0]);
#endif
SDL_free(tpage);
#if defined(_DEBUG) && 0
char buff[64];
sprintf(&buff[0], "TPAGE_%d_%d.TGA", tpage, clut);
@ -2419,6 +2433,7 @@ IDirect3DTexture9* Emulator_GenerateTpage(unsigned short tpage, unsigned short c
fwrite(&tpage[0], sizeof(char), 256 * 256 * 2, f);
fclose(f);
#endif
SDL_free(tpage);
break;
}
case TP_4BIT:

View File

@ -56,7 +56,7 @@ struct Sector
CdlFILE* CdSearchFile(CdlFILE* fp, char* name)
{
SDL_memset(fp, 0, sizeof(CdlFILE));
memset(fp, 0, sizeof(CdlFILE));
if (name[0] == '\\')
{
@ -227,7 +227,7 @@ int CdSync(int mode, u_char * result)
int CdInit(void)
{
SDL_memset(&comQueue, 0, sizeof(comQueue));
memset(&comQueue, 0, sizeof(comQueue));
currentSector = 0;
openFile = fopen(DISC_IMAGE_FILENAME, "rb");

View File

@ -9,6 +9,12 @@
void(*vsync_callback)(void) = NULL;
int StopCallback(void)
{
UNIMPLEMENTED();
return 0;
}
int ResetCallback(void)
{
vsync_callback = NULL;
@ -56,3 +62,9 @@ long GetVideoMode(void)
{
return MODE_NTSC;
}
long SetVideoMode(long mode)
{
UNIMPLEMENTED();
return MODE_NTSC;
}

View File

@ -246,6 +246,12 @@ int ClearImage(RECT16* rect, u_char r, u_char g, u_char b)
return 0;
}
int ClearImage2(RECT16* rect, u_char r, u_char g, u_char b)
{
return ClearImage(rect, r, g, b);
}
int DrawSync(int mode)
{
if (drawsync_callback != NULL)
@ -550,6 +556,24 @@ void SetDrawMode(DR_MODE* p, int dfe, int dtd, int tpage, RECT16* tw)
setDrawMode(p, dfe, dtd, tpage, tw);
}
void SetDrawMove(DR_MOVE *p, RECT16 *RECT16, int x, int y)
{
char uVar1;
ulong uVar2;
uVar1 = 5;
if ((RECT16->w == 0) || (RECT16->h == 0)) {
uVar1 = 0;
}
p->code[0] = 0x1000000;
p->code[1] = 0x80000000;
*(char *)((int)&p->tag + 3) = uVar1;
uVar2 = *(ulong *)RECT16;
p->code[3] = y << 0x10 | x & 0xffffU;
p->code[2] = uVar2;
p->code[4] = *(ulong *)&RECT16->w;
}
u_long DrawSyncCallback(void(*func)(void))
{
drawsync_callback = func;
@ -736,7 +760,9 @@ void ParseLinkedPrimitiveList(unsigned int packetStart, unsigned int packetEnd)/
{
unsigned int currentAddress = packetStart;
while (currentAddress != packetEnd)
bool bailout = false;
while (currentAddress != packetEnd && !bailout)
{
P_TAG* pTag = (P_TAG*)currentAddress;
@ -811,6 +837,9 @@ void ParseLinkedPrimitiveList(unsigned int packetStart, unsigned int packetEnd)/
case 0x24:
{
POLY_FT3* poly = (POLY_FT3*)pTag;
{
activeDrawEnv.tpage = poly->tpage;
}
if (lastTpage == 0xFFFF || lastClut == 0xFFFF || lastSemiTrans == 0xFFFF || lastPolyType == 0xFFFF)
{
@ -901,6 +930,10 @@ void ParseLinkedPrimitiveList(unsigned int packetStart, unsigned int packetEnd)/
{
POLY_FT4* poly = (POLY_FT4*)pTag;
{
activeDrawEnv.tpage = poly->tpage;
}
if (lastTpage == 0xFFFF || lastClut == 0xFFFF || lastSemiTrans == 0xFFFF || lastPolyType == 0xFFFF)
{
lastPolyType = POLY_TYPE_TRIANGLES;
@ -991,6 +1024,10 @@ void ParseLinkedPrimitiveList(unsigned int packetStart, unsigned int packetEnd)/
{
POLY_GT3* poly = (POLY_GT3*)pTag;
{
activeDrawEnv.tpage = poly->tpage;
}
if (lastTpage == 0xFFFF || lastClut == 0xFFFF || lastSemiTrans == 0xFFFF || lastPolyType == 0xFFFF)
{
lastPolyType = POLY_TYPE_TRIANGLES;
@ -1082,6 +1119,10 @@ void ParseLinkedPrimitiveList(unsigned int packetStart, unsigned int packetEnd)/
{
POLY_GT4* poly = (POLY_GT4*)pTag;
{
activeDrawEnv.tpage = poly->tpage;
}
if (lastTpage == 0xFFFF || lastClut == 0xFFFF || lastSemiTrans == 0xFFFF || lastPolyType == 0xFFFF)
{
lastPolyType = POLY_TYPE_TRIANGLES;
@ -1633,9 +1674,15 @@ void ParseLinkedPrimitiveList(unsigned int packetStart, unsigned int packetEnd)/
}
break;
}
case 0x80: {
eprinterr("DR_MOVE unimplemented\n");
currentAddress += sizeof(DR_MOVE);
break;
}
default:
//Unhandled poly type
eprinterr("Unhandled primitive type: %02X type2:%02X\n", pTag->code, pTag->code & ~3);
bailout = true;
break;
}
}
@ -1711,6 +1758,10 @@ void ParsePrimitive(P_TAG* pTag)
{
POLY_FT3* poly = (POLY_FT3*)pTag;
{
activeDrawEnv.tpage = poly->tpage;
}
if (lastTpage == 0xFFFF || lastClut == 0xFFFF || lastSemiTrans == 0xFFFF || lastPolyType == 0xFFFF)
{
lastPolyType = POLY_TYPE_TRIANGLES;
@ -1792,6 +1843,10 @@ void ParsePrimitive(P_TAG* pTag)
{
POLY_FT4* poly = (POLY_FT4*)pTag;
{
activeDrawEnv.tpage = poly->tpage;
}
if (lastTpage == 0xFFFF || lastClut == 0xFFFF || lastSemiTrans == 0xFFFF || lastPolyType == 0xFFFF)
{
lastPolyType = POLY_TYPE_TRIANGLES;
@ -1915,7 +1970,7 @@ void ParsePrimitive(P_TAG* pTag)
lastTpage = activeDrawEnv.tpage;
lastSemiTrans = semi_transparent;
g_splitIndices[g_numSplitIndices].primitiveType = lastPolyType;
g_splitIndices[g_numSplitIndices].textureId = Emulator_GenerateTpage(lastTpage, lastClut);
g_splitIndices[g_numSplitIndices].textureId = nullWhiteTexture;
g_splitIndices[g_numSplitIndices].semiTrans = semi_transparent;
g_splitIndices[g_numSplitIndices].abr = (activeDrawEnv.tpage >> 5) & 3;
g_splitIndices[g_numSplitIndices++].splitIndex = g_vertexIndex;
@ -1926,7 +1981,20 @@ void ParsePrimitive(P_TAG* pTag)
lastTpage = activeDrawEnv.tpage;
lastSemiTrans = semi_transparent;
g_splitIndices[g_numSplitIndices].primitiveType = lastPolyType;
g_splitIndices[g_numSplitIndices].textureId = Emulator_GenerateTpage(lastTpage, lastClut);
g_splitIndices[g_numSplitIndices].textureId = nullWhiteTexture;
g_splitIndices[g_numSplitIndices].semiTrans = semi_transparent;
g_splitIndices[g_numSplitIndices].abr = (activeDrawEnv.tpage >> 5) & 3;
g_splitIndices[g_numSplitIndices - 1].numVertices = numVertices;
g_splitIndices[g_numSplitIndices++].splitIndex = g_vertexIndex;
numVertices = 0;
}
else
{
lastPolyType = POLY_TYPE_TRIANGLES;
lastTpage = activeDrawEnv.tpage;
lastSemiTrans = semi_transparent;
g_splitIndices[g_numSplitIndices].primitiveType = lastPolyType;
g_splitIndices[g_numSplitIndices].textureId = nullWhiteTexture;
g_splitIndices[g_numSplitIndices].semiTrans = semi_transparent;
g_splitIndices[g_numSplitIndices].abr = (activeDrawEnv.tpage >> 5) & 3;
g_splitIndices[g_numSplitIndices - 1].numVertices = numVertices;
@ -2442,7 +2510,8 @@ void ParsePrimitive(P_TAG* pTag)
break;
}
g_splitIndices[g_numSplitIndices - 1].numVertices = numVertices;
if(g_numSplitIndices > 0)
g_splitIndices[g_numSplitIndices - 1].numVertices = numVertices;
}
void SetSprt16(SPRT_16* p)
@ -2514,7 +2583,7 @@ void DrawOTag(u_long* p)
{
#if defined(OGL) || defined(OGLES)
/* Tell the shader to discard black */
glUniform1i(glGetUniformLocation(g_defaultShaderProgram, "bDiscardBlack"), TRUE);
//glUniform1i(glGetUniformLocation(g_defaultShaderProgram, "bDiscardBlack"), TRUE);
#endif
if (activeDrawEnv.dtd)
@ -2824,6 +2893,7 @@ void DrawPrim(void* p)
#if defined(OGL) || defined(OGLES)
glBufferData(GL_ARRAY_BUFFER, sizeof(struct Vertex) * MAX_NUM_POLY_BUFFER_VERTICES, &g_vertexBuffer[0], GL_STATIC_DRAW);
#endif
for (int i = 0; i < g_numSplitIndices; i++)
{
if (g_texturelessMode)

View File

@ -2,6 +2,8 @@
#include "EMULATOR.H"
#include <SDL.h>
SDL_GameController* padHandle[MAX_CONTROLLERS];
unsigned char* padData[MAX_CONTROLLERS];
const unsigned char* keyboardState;

View File

@ -220,6 +220,13 @@ void SpuInit(void)
_SpuInit(0);
}
long SpuSetMute(long on_off)
{
UNIMPLEMENTED();
return 0;
}
long SpuSetReverb(long on_off)
{
UNIMPLEMENTED();