2020-03-31 18:55:57 +02:00
|
|
|
#ifndef EMULATOR_H
|
|
|
|
#define EMULATOR_H
|
|
|
|
|
|
|
|
#include "EMULATOR_PLATFORM_SETUP.H"
|
|
|
|
#include "LIBGPU.H"
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stddef.h>
|
|
|
|
|
|
|
|
#ifndef TRUE
|
|
|
|
#define TRUE 1
|
|
|
|
#endif
|
|
|
|
#ifndef FALSE
|
|
|
|
#define FALSE 0
|
|
|
|
#endif
|
|
|
|
#ifndef NULL
|
|
|
|
#define NULL 0
|
|
|
|
#endif
|
|
|
|
|
2020-03-31 19:09:22 +02:00
|
|
|
#if !((defined OGL) || (defined(OGLES) && OGLES_VERSION == 3))
|
2020-04-23 09:25:56 +02:00
|
|
|
#define glGenVertexArrays glGenVertexArraysOES
|
|
|
|
#define glBindVertexArray glBindVertexArrayOES
|
|
|
|
#define glDeleteVertexArrays glDeleteVertexArraysOES
|
2020-03-31 19:09:22 +02:00
|
|
|
#endif
|
|
|
|
|
2020-03-31 18:55:57 +02:00
|
|
|
#ifdef _MSC_VER
|
|
|
|
#define FUNCNAME __FUNCTION__
|
|
|
|
#else
|
|
|
|
#define FUNCNAME __func__
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if defined(__ANDROID__)
|
|
|
|
#include <android/log.h>
|
|
|
|
#define LOG_TAG_EMU "[EMU] "
|
|
|
|
#define eprintf(fmt, ...) __android_log_print(ANDROID_LOG_DEBUG, LOG_TAG_EMU, fmt, ##__VA_ARGS__)
|
|
|
|
#define eprinterr(fmt, ...) eprintf("[%s] - " fmt, FUNCNAME, ##__VA_ARGS__);
|
|
|
|
#else
|
|
|
|
#define eprintf(fmt, ...) printf("[EMU] " fmt, ##__VA_ARGS__)
|
|
|
|
#define eprinterr(fmt, ...) eprintf("[%s] - " fmt, FUNCNAME, ##__VA_ARGS__);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if defined(__EMSCRIPTEN__)
|
|
|
|
#define UNIMPLEMENTED() 0;
|
|
|
|
#else
|
|
|
|
#define UNIMPLEMENTED() eprinterr("Unimplemented!\n");
|
|
|
|
#endif
|
|
|
|
|
2020-04-05 17:39:14 +02:00
|
|
|
#if defined(OGL)
|
2020-04-23 09:25:56 +02:00
|
|
|
#define VRAM_FORMAT GL_RG
|
|
|
|
#define VRAM_INTERNAL_FORMAT GL_RG8
|
2020-04-05 17:39:14 +02:00
|
|
|
#elif defined(OGLES)
|
2020-04-23 09:25:56 +02:00
|
|
|
#define VRAM_FORMAT GL_LUMINANCE_ALPHA
|
|
|
|
#define VRAM_INTERNAL_FORMAT GL_LUMINANCE_ALPHA
|
2020-04-05 17:39:14 +02:00
|
|
|
#endif
|
|
|
|
|
2020-03-31 19:09:22 +02:00
|
|
|
#define VRAM_WIDTH (1024)
|
|
|
|
#define VRAM_HEIGHT (512)
|
2020-03-31 18:55:57 +02:00
|
|
|
|
|
|
|
#define TPAGE_WIDTH (256)
|
|
|
|
#define TPAGE_HEIGHT (256)
|
|
|
|
|
|
|
|
#define CLUT_WIDTH (16)
|
|
|
|
#define CLUT_HEIGHT (1)
|
|
|
|
|
|
|
|
#define CTR_RUNNING (0)
|
|
|
|
#define CTR_STOPPED (1)
|
|
|
|
|
|
|
|
#define CTR_MODE_TO_FFFF (0)
|
|
|
|
#define CTR_MODE_TO_TARG (1)
|
|
|
|
|
|
|
|
#define CTR_CLOCK_SYS (0)
|
|
|
|
#define CTR_CLOCK_PIXEL (1)
|
|
|
|
#define CTR_HORIZ_RETRACE (1)
|
|
|
|
|
|
|
|
#define CTR_CLOCK_SYS_ONE (0)
|
|
|
|
#define CTR_CLOCK_SYS_ONE_EIGHTH (1)
|
|
|
|
|
2020-03-31 19:09:22 +02:00
|
|
|
#define GET_TPAGE_X(tpage) (((tpage << 6) & 0x7C0) % (VRAM_WIDTH))
|
|
|
|
#define GET_TPAGE_Y(tpage) (((((tpage << 4) & 0x100) + ((tpage >> 2) & 0x200))) % (VRAM_HEIGHT))
|
2020-04-02 14:03:23 +02:00
|
|
|
#define GET_TPAGE_FORMAT(tpage) ((TexFormat)((tpage >> 7) & 0x3))
|
|
|
|
#define GET_TPAGE_BLEND(tpage) ((BlendMode)(((page >> 5) & 3) + 1))
|
|
|
|
|
2020-03-31 19:09:22 +02:00
|
|
|
// TODO
|
|
|
|
#define GET_TPAGE_DITHER(tpage) 1
|
|
|
|
//#define GET_TPAGE_DITHER(tpage) 1((tpage >> 9) & 0x1)
|
|
|
|
|
|
|
|
#define GET_CLUT_X(clut) ((clut & 0x3F) << 4)
|
|
|
|
#define GET_CLUT_Y(clut) (clut >> 6)
|
2020-03-31 18:55:57 +02:00
|
|
|
|
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
unsigned int i_cycle;
|
|
|
|
|
|
|
|
union
|
|
|
|
{
|
|
|
|
unsigned short cycle;
|
|
|
|
unsigned short unk00;
|
|
|
|
};
|
|
|
|
|
|
|
|
unsigned int i_value;
|
|
|
|
|
|
|
|
union
|
|
|
|
{
|
|
|
|
unsigned short value;
|
|
|
|
unsigned short unk01;
|
|
|
|
};
|
|
|
|
|
|
|
|
unsigned int i_target;
|
|
|
|
|
|
|
|
union
|
|
|
|
{
|
|
|
|
unsigned short target;
|
|
|
|
unsigned short unk02;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
unsigned int padding00;
|
|
|
|
unsigned int padding01;
|
|
|
|
} SysCounter;
|
|
|
|
|
|
|
|
extern SysCounter counters[3];
|
|
|
|
|
|
|
|
#pragma pack(push,1)
|
|
|
|
struct Vertex
|
|
|
|
{
|
2020-04-05 17:39:14 +02:00
|
|
|
#if defined(PGXP)
|
|
|
|
float x, y, page, clut;
|
|
|
|
#else
|
2020-03-31 19:09:22 +02:00
|
|
|
short x, y, page, clut;
|
2020-04-05 17:39:14 +02:00
|
|
|
#endif
|
2020-03-31 19:09:22 +02:00
|
|
|
u_char u, v, bright, dither;
|
|
|
|
u_char r, g, b, a;
|
2020-03-31 18:55:57 +02:00
|
|
|
};
|
|
|
|
#pragma pack(pop)
|
|
|
|
|
2020-03-31 19:09:22 +02:00
|
|
|
enum ShaderAttrib
|
|
|
|
{
|
|
|
|
a_position,
|
|
|
|
a_texcoord,
|
2020-04-02 14:03:23 +02:00
|
|
|
a_color
|
2020-03-31 19:09:22 +02:00
|
|
|
};
|
2020-03-31 18:55:57 +02:00
|
|
|
|
|
|
|
enum BlendMode
|
|
|
|
{
|
2020-04-02 14:03:23 +02:00
|
|
|
BM_NONE,
|
|
|
|
BM_AVERAGE,
|
2020-03-31 18:55:57 +02:00
|
|
|
BM_ADD,
|
|
|
|
BM_SUBTRACT,
|
2020-03-31 19:09:22 +02:00
|
|
|
BM_ADD_QUATER_SOURCE
|
2020-03-31 18:55:57 +02:00
|
|
|
};
|
|
|
|
|
2020-04-02 14:03:23 +02:00
|
|
|
enum TexFormat
|
|
|
|
{
|
|
|
|
TF_4_BIT,
|
|
|
|
TF_8_BIT,
|
|
|
|
TF_16_BIT
|
|
|
|
};
|
|
|
|
|
2020-03-31 19:09:22 +02:00
|
|
|
#define MAX_NUM_POLY_BUFFER_VERTICES (12040)
|
|
|
|
#define MAX_NUM_INDEX_BUFFERS (4096)
|
|
|
|
|
|
|
|
#if defined(OGLES) || defined(OGL)
|
2020-04-23 09:25:56 +02:00
|
|
|
typedef GLuint TextureID;
|
|
|
|
typedef GLuint ShaderID;
|
|
|
|
typedef GLuint RenderTargetID;
|
2020-03-31 18:55:57 +02:00
|
|
|
#elif defined(D3D9)
|
2020-04-23 09:25:56 +02:00
|
|
|
typedef IDirect3DTexture9* TextureID;
|
2020-03-31 19:09:22 +02:00
|
|
|
|
2020-04-23 09:25:56 +02:00
|
|
|
struct ShaderID {
|
|
|
|
IDirect3DVertexShader9* VS;
|
|
|
|
IDirect3DPixelShader9* PS;
|
|
|
|
};
|
2020-03-31 19:09:22 +02:00
|
|
|
|
2020-04-23 09:25:56 +02:00
|
|
|
typedef IDirect3DSurface9* RenderTargetID;
|
2020-03-31 19:09:22 +02:00
|
|
|
#else
|
2020-04-23 09:25:56 +02:00
|
|
|
#error
|
2020-03-31 18:55:57 +02:00
|
|
|
#endif
|
2020-03-31 19:09:22 +02:00
|
|
|
|
2020-04-27 09:53:23 +02:00
|
|
|
typedef void(*GameDebugKeysHandlerFunc)(int nKey, bool down);
|
|
|
|
extern GameDebugKeysHandlerFunc gameDebugKeys;
|
|
|
|
|
2020-03-31 19:09:22 +02:00
|
|
|
extern int Emulator_Initialise();
|
2020-04-05 17:39:14 +02:00
|
|
|
extern void Emulator_StoreFrameBuffer(int x, int y, int w, int h);
|
2020-03-31 18:55:57 +02:00
|
|
|
extern void Emulator_SaveVRAM(const char* outputFileName, int x, int y, int width, int height, int bReadFromFrameBuffer);
|
2020-04-23 09:25:56 +02:00
|
|
|
extern void Emulator_CopyVRAM(unsigned short* src, int x, int y, int w, int h, int dst_x, int dst_y);
|
|
|
|
extern void Emulator_ReadVRAM(unsigned short* dst, int x, int y, int dst_w, int dst_h);
|
2020-03-31 19:09:22 +02:00
|
|
|
extern void Emulator_UpdateVRAM();
|
|
|
|
extern void Emulator_BlitVRAM();
|
2020-03-31 18:55:57 +02:00
|
|
|
extern void Emulator_ShutDown();
|
|
|
|
extern void Emulator_SwapWindow();
|
2020-04-02 14:03:23 +02:00
|
|
|
extern void Emulator_SetBlendMode(BlendMode blendMode);
|
2020-03-31 18:55:57 +02:00
|
|
|
extern void Emulator_CounterLoop();
|
2020-04-05 17:39:14 +02:00
|
|
|
|
|
|
|
extern void Emulator_GenerateLineArray(struct Vertex* vertex, short* p0, short* p1);
|
|
|
|
extern void Emulator_GenerateVertexArrayTriangle(struct Vertex* vertex, short* p0, short* p1, short* p2);
|
|
|
|
extern void Emulator_GenerateVertexArrayQuad(struct Vertex* vertex, short* p0, short* p1, short* p2, short* p3);
|
|
|
|
extern void Emulator_GenerateVertexArrayRect(struct Vertex* vertex, short* p0, short w, short h);
|
|
|
|
|
|
|
|
extern void Emulator_GenerateTexcoordArrayTriangle(struct Vertex* vertex, unsigned char* uv0, unsigned char* uv1, unsigned char* uv2, short page, short clut, unsigned char dither);
|
2020-03-31 19:09:22 +02:00
|
|
|
extern void Emulator_GenerateTexcoordArrayQuad(struct Vertex* vertex, unsigned char* uv0, unsigned char* uv1, unsigned char* uv2, unsigned char* uv3, short page, short clut, unsigned char dither);
|
|
|
|
extern void Emulator_GenerateTexcoordArrayRect(struct Vertex* vertex, unsigned char* uv, short page, short clut, short w, short h);
|
2020-04-05 17:39:14 +02:00
|
|
|
extern void Emulator_GenerateTexcoordArrayLineZero(struct Vertex* vertex, unsigned char dither);
|
|
|
|
extern void Emulator_GenerateTexcoordArrayTriangleZero(struct Vertex* vertex, unsigned char dither);
|
|
|
|
extern void Emulator_GenerateTexcoordArrayQuadZero(struct Vertex* vertex, unsigned char dither);
|
|
|
|
|
|
|
|
extern void Emulator_GenerateColourArrayLine(struct Vertex* vertex, unsigned char* col0, unsigned char* col1);
|
|
|
|
extern void Emulator_GenerateColourArrayTriangle(struct Vertex* vertex, unsigned char* col0, unsigned char* col1, unsigned char* col2);
|
2020-03-31 19:09:22 +02:00
|
|
|
extern void Emulator_GenerateColourArrayQuad(struct Vertex* vertex, unsigned char* col0, unsigned char* col1, unsigned char* col2, unsigned char* col3);
|
2020-04-05 17:39:14 +02:00
|
|
|
|
2020-03-31 19:09:22 +02:00
|
|
|
extern void Emulator_DestroyTexture(TextureID texture);
|
|
|
|
extern void Emulator_Clear(int x, int y, int w, int h, unsigned char r, unsigned char g, unsigned char b);
|
2020-03-31 18:55:57 +02:00
|
|
|
extern void Emulator_SetViewPort(int x, int y, int width, int height);
|
2020-04-02 14:03:23 +02:00
|
|
|
extern void Emulator_SetTexture(TextureID texture, TexFormat texFormat);
|
2020-04-23 09:25:56 +02:00
|
|
|
extern void Emulator_SetRenderTarget(const RenderTargetID& render_target);
|
2020-03-31 19:09:22 +02:00
|
|
|
extern void Emulator_SetWireframe(bool enable);
|
2020-04-23 09:25:56 +02:00
|
|
|
extern void Emulator_UpdateVertexBuffer(const Vertex* vertices, int count);
|
2020-03-31 19:09:22 +02:00
|
|
|
extern void Emulator_DrawTriangles(int start_vertex, int triangles);
|
|
|
|
|
2020-03-31 18:55:57 +02:00
|
|
|
#if defined(D3D9)
|
|
|
|
extern IDirect3DDevice9* d3ddev;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#endif
|