PGF font support. Mostly an adaptation and cleanup of JPCSP's font system.

This commit is contained in:
Henrik Rydgard 2013-02-22 20:05:07 +01:00
parent 447180b45e
commit ba0362d817
16 changed files with 1603 additions and 337 deletions

View File

@ -28,7 +28,7 @@
// Unfortunately this is quite slow.
// #define LOG_MSC_OUTPUTDEBUG true
#define LOG_MSC_OUTPUTDEBUG false
#define LOG_MSC_OUTPUTDEBUG true
void GenericLog(LogTypes::LOG_LEVELS level, LogTypes::LOG_TYPE type,
const char *file, int line, const char* fmt, ...)

View File

@ -21,6 +21,7 @@ set(SRCS
ELF/ElfReader.cpp
ELF/ParamSFO.cpp
ELF/PrxDecrypter.cpp
Font/PGF.cpp
HLE/HLE.cpp
HLE/HLETables.cpp
HLE/sceAtrac.cpp

View File

@ -144,6 +144,7 @@
<ClCompile Include="FileSystems\DirectoryFileSystem.cpp" />
<ClCompile Include="FileSystems\ISOFileSystem.cpp" />
<ClCompile Include="FileSystems\MetaFileSystem.cpp" />
<ClCompile Include="Font\PGF.cpp" />
<ClCompile Include="HLE\HLE.cpp" />
<ClCompile Include="HLE\HLETables.cpp" />
<ClCompile Include="HLE\sceAtrac.cpp" />
@ -312,6 +313,7 @@
<ClInclude Include="FileSystems\FileSystem.h" />
<ClInclude Include="FileSystems\ISOFileSystem.h" />
<ClInclude Include="FileSystems\MetaFileSystem.h" />
<ClInclude Include="Font\PGF.h" />
<ClInclude Include="HLE\FunctionWrappers.h" />
<ClInclude Include="HLE\HLE.h" />
<ClInclude Include="HLE\HLETables.h" />
@ -412,7 +414,6 @@
<ClInclude Include="SaveState.h" />
<ClInclude Include="System.h" />
<ClInclude Include="Util\BlockAllocator.h" />
<ClInclude Include="Util\Pool.h" />
<ClInclude Include="Util\PPGeDraw.h" />
<ClInclude Include="Util\ppge_atlas.h" />
</ItemGroup>

View File

@ -49,6 +49,9 @@
<Filter Include="Ext\Snappy">
<UniqueIdentifier>{0b77054f-7fc7-4c33-ada3-762aecde69e5}</UniqueIdentifier>
</Filter>
<Filter Include="Font">
<UniqueIdentifier>{1c79e88d-1c48-450b-8af6-f22ce7d40c66}</UniqueIdentifier>
</Filter>
</ItemGroup>
<ItemGroup>
<ClCompile Include="ELF\ElfReader.cpp">
@ -375,6 +378,10 @@
<ClCompile Include="MIPS\ARM\ArmRegCacheFPU.cpp">
<Filter>MIPS\ARM</Filter>
</ClCompile>
<ClCompile Include="HLE\sceChnnlsv.cpp" />
<ClCompile Include="Font\PGF.cpp">
<Filter>Font</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="ELF\ElfReader.h">
@ -533,9 +540,6 @@
<ClInclude Include="Util\BlockAllocator.h">
<Filter>Util</Filter>
</ClInclude>
<ClInclude Include="Util\Pool.h">
<Filter>Util</Filter>
</ClInclude>
<ClInclude Include="Debugger\Breakpoints.h">
<Filter>Debugger</Filter>
</ClInclude>
@ -695,6 +699,10 @@
<ClInclude Include="MIPS\ARM\ArmRegCacheFPU.h">
<Filter>MIPS\ARM</Filter>
</ClInclude>
<ClInclude Include="HLE\sceChnnlsv.h" />
<ClInclude Include="Font\PGF.h">
<Filter>Font</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<None Include="CMakeLists.txt" />

531
Core/Font/PGF.cpp Normal file
View File

@ -0,0 +1,531 @@
// Copyright (c) 2012- PPSSPP 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 or later versions.
// 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 git repository and contact information can be found at
// https://github.com/hrydgard/ppsspp and http://www.ppsspp.org/.
// ============== NOTE!!!!
// Thanks to the JPCSP project! This sceFont implementation is basically a C++ take on JPCSP's font code.
// Some parts, especially in this file, were simply copied, so I guess this really makes this file GPL3.
#include "Common/CommonTypes.h"
#include "Core/MemMap.h"
#include "Core/Font/PGF.h"
// These fonts, created by ttf2pgf, don't have complete glyph info and need to be identified.
static bool isJPCSPFont(const char *fontName) {
return !strcmp(fontName, "Liberation") || !strcmp(fontName, "Sazanami") || !strcmp(fontName, "UnDotum");
}
// Gets a number of bits from an offset.
// TODO: Make more efficient.
static int getBits(int numBits, const u8 *buf, size_t pos) {
int v = 0;
for (int i = 0; i < numBits; i++) {
v = v | (((buf[pos >> 3] >> (pos & 7)) & 1) << i);
pos++;
}
return v;
}
static std::vector<int> getTable(const u8 *buf, int bpe, int length) {
std::vector<int> vec;
vec.resize(length);
for (int i = 0; i < length; i++) {
vec[i] = getBits(bpe, buf, bpe * i);
}
return vec;
}
PGF::PGF()
: fontData(0), charMap(0), shadowCharMap(0), charPointerTable(0) {
}
PGF::~PGF() {
delete [] fontData;
delete [] charMap;
delete [] shadowCharMap;
delete [] charPointerTable;
}
void PGF::DoState(PointerWrap &p) {
// TODO!
}
void PGF::ReadPtr(const u8 *ptr, size_t dataSize) {
const u8 *const startPtr = ptr;
INFO_LOG(HLE, "Reading %i bytes of PGF header", sizeof(header));
memcpy(&header, ptr, sizeof(header));
ptr += sizeof(header);
if (header.revision == 3) {
memcpy(&rev3extra, ptr, sizeof(rev3extra));
rev3extra.compCharMapLength1 &= 0xFFFF;
rev3extra.compCharMapLength2 &= 0xFFFF;
ptr += sizeof(rev3extra);
}
const u32 *wptr = (const u32 *)ptr;
dimensionTable[0].resize(header.dimTableLength);
dimensionTable[1].resize(header.dimTableLength);
for (int i = 0; i < header.dimTableLength; i++) {
dimensionTable[0][i] = *wptr++;
dimensionTable[1][i] = *wptr++;
}
xAdjustTable[0].resize(header.xAdjustTableLength);
xAdjustTable[1].resize(header.xAdjustTableLength);
for (int i = 0; i < header.xAdjustTableLength; i++) {
xAdjustTable[0][i] = *wptr++;
xAdjustTable[1][i] = *wptr++;
}
yAdjustTable[0].resize(header.yAdjustTableLength);
yAdjustTable[1].resize(header.yAdjustTableLength);
for (int i = 0; i < header.yAdjustTableLength; i++) {
yAdjustTable[0][i] = *wptr++;
yAdjustTable[1][i] = *wptr++;
}
advanceTable[0].resize(header.advanceTableLength);
advanceTable[1].resize(header.advanceTableLength);
for (int i = 0; i < header.advanceTableLength; i++) {
advanceTable[0][i] = *wptr++;
advanceTable[1][i] = *wptr++;
}
const u8 *uptr = (const u8 *)wptr;
int shadowCharMapSize = ((header.shadowMapLength * header.shadowMapBpe + 31) & ~31) / 8;
shadowCharMap = new u8[shadowCharMapSize];
for (int i = 0; i < shadowCharMapSize; i++) {
shadowCharMap[i] = *uptr++;
}
const u16 *sptr = (const u16 *)uptr;
if (header.revision == 3) {
charmapCompressionTable1[0].resize(rev3extra.compCharMapLength1);
charmapCompressionTable1[1].resize(rev3extra.compCharMapLength1);
for (int i = 0; i < rev3extra.compCharMapLength1; i++) {
charmapCompressionTable1[0][i] = *sptr++;
charmapCompressionTable1[1][i] = *sptr++;
}
charmapCompressionTable2[0].resize(rev3extra.compCharMapLength2);
charmapCompressionTable2[1].resize(rev3extra.compCharMapLength2);
for (int i = 0; i < rev3extra.compCharMapLength2; i++) {
charmapCompressionTable2[0][i] = *sptr++;
charmapCompressionTable2[1][i] = *sptr++;
}
}
uptr = (const u8 *)sptr;
int charMapSize = ((header.charMapLength * header.charMapBpe + 31) & ~31) / 8;
charMap = new u8[charMapSize];
for (int i = 0; i < charMapSize; i++) {
charMap[i] = *uptr++;
}
int charPointerSize = (((header.charPointerLength * header.charPointerBpe + 31) & ~31) / 8);
charPointerTable = new u8[charPointerSize];
for (int i = 0; i < charPointerSize; i++) {
charPointerTable[i] = *uptr++;
}
// PGF Fontdata.
u32 fontDataOffset = uptr - startPtr;
fontDataSize = dataSize - fontDataOffset;
fontData = new u8[fontDataSize];
memcpy(fontData, uptr, fontDataSize);
// charmap.resize();
charmap.resize(header.charMapLength);
int charmap_compr_len = header.revision == 3 ? 7 : 1;
charmap_compr.resize(charmap_compr_len * 4);
glyphs.resize(header.charPointerLength);
shadowGlyphs.resize(header.shadowMapLength);
firstGlyph = header.firstGlyph;
// Parse out the char map (array where each entry is an irregular number of bits)
// BPE = bits per entry, I think.
for (int i = 0; i < header.charMapLength; i++) {
charmap[i] = getBits(header.charMapBpe, charMap, i * header.charMapBpe);
// This check seems a little odd.
if ((size_t)charmap[i] >= glyphs.size())
charmap[i] = 65535;
}
std::vector<int> charPointers = getTable(charPointerTable, header.charPointerBpe, glyphs.size());
std::vector<int> shadowMap = getTable(shadowCharMap, header.shadowMapBpe, shadowGlyphs.size());
// Pregenerate glyphs.
for (size_t i = 0; i < glyphs.size(); i++) {
GetGlyph(fontData, charPointers[i] * 4 * 8 /* ??? */, FONT_PGF_CHARGLYPH, glyphs[i]);
}
// And shadow glyphs.
for (size_t i = 0; i < shadowGlyphs.size(); i++) {
size_t shadowId = glyphs[i].shadowID;
if (shadowId >= 0 && shadowId < shadowMap.size()) {
size_t charId = shadowMap[shadowId];
if (charId >= 0 && charId < glyphs.size()) {
// TODO: check for pre existing shadow glyph
GetGlyph(fontData, charPointers[charId] * 4 * 8 /* ??? */, FONT_PGF_SHADOWGLYPH, shadowGlyphs[i]);
}
}
}
}
int PGF::GetCharIndex(int charCode, const std::vector<int> &charmapCompressed) {
int charIndex = 0;
for (size_t i = 0; i < charmapCompressed.size(); i += 2) {
if (charCode >= charmapCompressed[i] && charCode < charmapCompressed[i] + charmapCompressed[i + 1]) {
charIndex += charCode - charmapCompressed[i];
return charIndex;
}
charIndex += charmapCompressed[i + 1];
}
return -1;
}
bool PGF::GetCharInfo(int charCode, PGFCharInfo *charInfo) {
Glyph glyph;
if (!GetCharGlyph(charCode, FONT_PGF_CHARGLYPH, glyph)) {
// Character not in font, return zeroed charInfo as on real PSP.
return false;
}
memset(charInfo, 0, sizeof(charInfo));
charInfo->bitmapWidth = glyph.w;
charInfo->bitmapHeight = glyph.h;
charInfo->bitmapLeft = glyph.left;
charInfo->bitmapTop = glyph.top;
charInfo->sfp26Width = glyph.dimensionWidth;
charInfo->sfp26Height = glyph.dimensionHeight;
charInfo->sfp26Ascender = glyph.top << 6;
charInfo->sfp26Descender = (glyph.h - glyph.top) << 6;
charInfo->sfp26BearingHX = glyph.xAdjustH;
charInfo->sfp26BearingHY = glyph.yAdjustH;
charInfo->sfp26BearingVX = glyph.xAdjustV;
charInfo->sfp26BearingVY = glyph.yAdjustV;
charInfo->sfp26AdvanceH = glyph.advanceH;
charInfo->sfp26AdvanceV = glyph.advanceV;
return true;
}
void PGF::GetFontInfo(PGFFontInfo *fi) {
fi->maxGlyphWidthI = header.maxSize[0];
fi->maxGlyphHeightI = header.maxSize[1];
fi->maxGlyphAscenderI = header.maxAscender;
fi->maxGlyphDescenderI = header.maxDescender;
fi->maxGlyphLeftXI = header.maxLeftXAdjust;
fi->maxGlyphBaseYI = header.maxBaseYAdjust;
fi->minGlyphCenterXI = header.minCenterXAdjust;
fi->maxGlyphTopYI = header.maxTopYAdjust;
fi->maxGlyphAdvanceXI = header.maxAdvance[0];
fi->maxGlyphAdvanceYI = header.maxAdvance[1];
fi->maxGlyphWidthF = header.maxSize[0] / 64.0f;
fi->maxGlyphHeightF = header.maxSize[1] / 64.0f;
fi->maxGlyphAscenderF = header.maxAscender / 64.0f;
fi->maxGlyphDescenderF = header.maxDescender / 64.0f;
fi->maxGlyphLeftXF = header.maxLeftXAdjust / 64.0f;
fi->maxGlyphBaseYF = header.maxBaseYAdjust / 64.0f;
fi->minGlyphCenterXF = header.minCenterXAdjust / 64.0f;
fi->maxGlyphTopYF = header.maxTopYAdjust / 64.0f;
fi->maxGlyphAdvanceXF = header.maxAdvance[0] / 64.0f;
fi->maxGlyphAdvanceYF = header.maxAdvance[1] / 64.0f;
fi->maxGlyphWidth = header.maxGlyphWidth;
fi->maxGlyphHeight = header.maxGlyphHeight;
fi->charMapLength = header.charMapLength;
fi->shadowMapLength = 0; // header.shadowMapLength; TODO
fi->BPP = header.bpp;
}
bool PGF::GetGlyph(const u8 *fontdata, size_t charPtr, int glyphType, Glyph &glyph) {
if (glyphType == FONT_PGF_SHADOWGLYPH) {
if (charPtr + 96 > fontDataSize * 8)
return false;
charPtr += getBits(14, fontdata, charPtr) * 8;
if (charPtr + 96 > fontDataSize * 8)
return false;
}
charPtr += 14;
glyph.w = getBits(7, fontdata, charPtr);
charPtr += 7;
glyph.h = getBits(7, fontdata, charPtr);
charPtr += 7;
glyph.left = getBits(7, fontdata, charPtr);
charPtr += 7;
if (glyph.left >= 64) {
glyph.left -= 128;
}
glyph.top = getBits(7, fontdata, charPtr);
charPtr += 7;
if (glyph.top >= 64) {
glyph.top -= 128;
}
glyph.flags = getBits(6, fontdata, charPtr);
charPtr += 6;
if (glyph.flags & FONT_PGF_CHARGLYPH) {
// Skip magic number
charPtr += 7;
glyph.shadowID = getBits(9, fontdata, charPtr);
charPtr += 9;
int dimensionIndex = getBits(8, fontdata, charPtr);
charPtr += 8;
int xAdjustIndex = getBits(8, fontdata, charPtr);
charPtr += 8;
int yAdjustIndex = getBits(8, fontdata, charPtr);
charPtr += 8;
charPtr +=
((glyph.flags & FONT_PGF_METRIC_FLAG1) ? 0 : 56) +
((glyph.flags & FONT_PGF_METRIC_FLAG2) ? 0 : 56) +
((glyph.flags & FONT_PGF_METRIC_FLAG3) ? 0 : 56);
int advanceIndex = getBits(8, fontdata, charPtr);
charPtr += 8;
if (dimensionIndex < header.dimTableLength) {
glyph.dimensionWidth = dimensionTable[0][dimensionIndex];
glyph.dimensionHeight = dimensionTable[1][dimensionIndex];
}
if (xAdjustIndex < header.xAdjustTableLength) {
glyph.xAdjustH = xAdjustTable[0][xAdjustIndex];
glyph.xAdjustV = xAdjustTable[1][xAdjustIndex];
}
if (yAdjustIndex < header.xAdjustTableLength) {
glyph.yAdjustH = yAdjustTable[0][yAdjustIndex];
glyph.yAdjustV = yAdjustTable[1][yAdjustIndex];
}
if (dimensionIndex == 0 && xAdjustIndex == 0 && yAdjustIndex == 0 && isJPCSPFont(fileName.c_str())) {
// Fonts created by ttf2pgf do not contain complete Glyph information.
// Provide default values.
glyph.dimensionWidth = glyph.w << 6;
glyph.dimensionHeight = glyph.h << 6;
// This stuff doesn't exactly look right.
glyph.xAdjustH = glyph.left << 6;
glyph.xAdjustV = glyph.left << 6;
glyph.yAdjustH = glyph.top << 6;
glyph.yAdjustV = glyph.top << 6;
}
if (advanceIndex < header.advanceTableLength) {
glyph.advanceH = advanceTable[0][advanceIndex];
glyph.advanceV = advanceTable[1][advanceIndex];
}
} else {
glyph.shadowID = 65535;
glyph.advanceH = 0;
}
glyph.ptr = (u32)(charPtr / 8);
return true;
}
bool PGF::GetCharGlyph(int charCode, int glyphType, Glyph &glyph) {
if (charCode < firstGlyph)
return false;
charCode -= firstGlyph;
if (charCode < (int)charmap.size()) {
charCode = charmap[charCode];
}
if (glyphType == FONT_PGF_CHARGLYPH) {
if (charCode >= (int)glyphs.size())
return false;
glyph = glyphs[charCode];
} else {
if (charCode >= (int)shadowGlyphs.size())
return false;
glyph = shadowGlyphs[charCode];
}
return true;
}
void PGF::DrawCharacter(u32 base, int bpl, int bufWidth, int bufHeight, int x, int y, int clipX, int clipY, int clipWidth, int clipHeight, int pixelformat, int charCode, int altCharCode, int glyphType) {
Glyph glyph;
if (!GetCharGlyph(charCode, glyphType, glyph)) {
// No Glyph available for this charCode, try to use the alternate char.
charCode = altCharCode;
if (!GetCharGlyph(charCode, glyphType, glyph)) {
return;
}
}
if (glyph.w <= 0 || glyph.h <= 0) {
return;
}
if (((glyph.flags & FONT_PGF_BMP_OVERLAY) != FONT_PGF_BMP_H_ROWS) &&
((glyph.flags & FONT_PGF_BMP_OVERLAY) != FONT_PGF_BMP_V_ROWS)) {
return;
}
u32 bitPtr = glyph.ptr * 8;
int numberPixels = glyph.w * glyph.h;
int pixelIndex = 0;
while (pixelIndex < numberPixels && bitPtr + 8 < fontDataSize * 8) {
// This is some kind of nibble based RLE compression.
int nibble = getBits(4, fontData, bitPtr);
bitPtr += 4;
int count;
int value;
if (nibble < 8) {
value = getBits(4, fontData, bitPtr);
bitPtr += 4;
count = nibble + 1;
} else {
count = 16 - nibble;
}
for (int i = 0; i < count && pixelIndex < numberPixels; i++) {
if (nibble >= 8) {
value = getBits(4, fontData, bitPtr);
bitPtr += 4;
}
int xx, yy;
if ((glyph.flags & FONT_PGF_BMP_OVERLAY) == FONT_PGF_BMP_H_ROWS) {
xx = pixelIndex % glyph.w;
yy = pixelIndex / glyph.w;
} else {
xx = pixelIndex / glyph.h;
yy = pixelIndex % glyph.h;
}
int pixelX = x + xx;
int pixelY = y + yy;
if (pixelX >= clipX && pixelX < clipX + clipWidth && pixelY >= clipY && pixelY < clipY + clipHeight) {
// 4-bit color value
int pixelColor = value;
switch (pixelformat) {
case PSP_FONT_PIXELFORMAT_8:
// 8-bit color value
pixelColor |= pixelColor << 4;
break;
case PSP_FONT_PIXELFORMAT_24:
// 24-bit color value
pixelColor |= pixelColor << 4;
pixelColor |= pixelColor << 8;
pixelColor |= pixelColor << 8;
break;
case PSP_FONT_PIXELFORMAT_32:
// 32-bit color value
pixelColor |= pixelColor << 4;
pixelColor |= pixelColor << 8;
pixelColor |= pixelColor << 16;
break;
}
SetFontPixel(base, bpl, bufWidth, bufHeight, pixelX, pixelY, pixelColor, pixelformat);
}
pixelIndex++;
}
}
}
void PGF::SetFontPixel(u32 base, int bpl, int bufWidth, int bufHeight, int x, int y, int pixelColor, int pixelformat) {
if (x < 0 || x >= bufWidth || y < 0 || y >= bufHeight) {
return;
}
static const u8 fontPixelSizeInBytes[] = { 0, 0, 1, 3, 4 }; // 0 means 2 pixels per byte
int pixelBytes = fontPixelSizeInBytes[pixelformat];
int bufMaxWidth = (pixelBytes == 0 ? bpl * 2 : bpl / pixelBytes);
if (x >= bufMaxWidth) {
return;
}
int framebufferAddr = base + (y * bpl) + (pixelBytes == 0 ? x / 2 : x * pixelBytes);
switch (pixelformat) {
case PSP_FONT_PIXELFORMAT_4:
case PSP_FONT_PIXELFORMAT_4_REV:
{
int oldColor = Memory::Read_U8(framebufferAddr);
int newColor;
if ((x & 1) != pixelformat) {
newColor = (pixelColor << 4) | (oldColor & 0xF);
} else {
newColor = (oldColor & 0xF0) | pixelColor;
}
Memory::Write_U8(newColor, framebufferAddr);
break;
}
case PSP_FONT_PIXELFORMAT_8:
{
Memory::Write_U8((u8)pixelColor, framebufferAddr);
break;
}
case PSP_FONT_PIXELFORMAT_24:
{
Memory::Write_U8(pixelColor & 0xFF, framebufferAddr + 0);
Memory::Write_U8(pixelColor >> 8, framebufferAddr + 1);
Memory::Write_U8(pixelColor >> 16, framebufferAddr + 2);
break;
}
case PSP_FONT_PIXELFORMAT_32:
{
Memory::Write_U32(pixelColor, framebufferAddr);
break;
}
}
}
u32 GetFontPixelColor(int color, int pixelformat) {
switch (pixelformat) {
case PSP_FONT_PIXELFORMAT_4:
case PSP_FONT_PIXELFORMAT_4_REV:
// Use only 4-bit alpha
color = (color >> 28) & 0xF;
break;
case PSP_FONT_PIXELFORMAT_8:
// Use only 8-bit alpha
color = (color >> 24) & 0xFF;
break;
case PSP_FONT_PIXELFORMAT_24:
// Use RGB with 8-bit values
color = color & 0x00FFFFFF;
break;
case PSP_FONT_PIXELFORMAT_32:
// Use RGBA with 8-bit values
break;
}
return color;
}

289
Core/Font/PGF.h Normal file
View File

@ -0,0 +1,289 @@
// Copyright (c) 2012- PPSSPP 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 or later versions.
// 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 git repository and contact information can be found at
// https://github.com/hrydgard/ppsspp and http://www.ppsspp.org/.
// Thanks to the JPCSP project! This sceFont implementation is basically a C++ take on JPCSP's font code.
#pragma once
#include <string>
#include <vector>
#include "Common/Log.h"
#include "Common/ChunkFile.h"
#include "Common/CommonTypes.h"
enum {
FONT_FILETYPE_PGF = 0x00,
FONT_FILETYPE_BWFON = 0x01,
};
enum {
FONT_PGF_BMP_H_ROWS = 0x01,
FONT_PGF_BMP_V_ROWS = 0x02,
FONT_PGF_BMP_OVERLAY = 0x03,
FONT_PGF_METRIC_FLAG1 = 0x04,
FONT_PGF_METRIC_FLAG2 = 0x08,
FONT_PGF_METRIC_FLAG3 = 0x10,
FONT_PGF_CHARGLYPH = 0x20,
FONT_PGF_SHADOWGLYPH = 0x40,
};
enum Family {
FONT_FAMILY_SANS_SERIF = 1,
FONT_FAMILY_SERIF = 2,
};
enum Style {
FONT_STYLE_REGULAR = 1,
FONT_STYLE_ITALIC = 2,
FONT_STYLE_BOLD = 5,
FONT_STYLE_BOLD_ITALIC = 6,
FONT_STYLE_DB = 103, // Demi-Bold / semi-bold
};
enum Language {
FONT_LANGUAGE_JAPANESE = 1,
FONT_LANGUAGE_LATIN = 2,
FONT_LANGUAGE_KOREAN = 3,
FONT_LANGUAGE_CHINESE = 4,
};
enum FontPixelFormat {
PSP_FONT_PIXELFORMAT_4 = 0, // 2 pixels packed in 1 byte (natural order)
PSP_FONT_PIXELFORMAT_4_REV = 1, // 2 pixels packed in 1 byte (reversed order)
PSP_FONT_PIXELFORMAT_8 = 2, // 1 pixel in 1 byte
PSP_FONT_PIXELFORMAT_24 = 3, // 1 pixel in 3 bytes (RGB)
PSP_FONT_PIXELFORMAT_32 = 4, // 1 pixel in 4 bytes (RGBA)
};
struct PGFFontStyle {
float fontH;
float fontV;
float fontHRes;
float fontVRes;
float fontWeight;
u16 fontFamily;
u16 fontStyle;
// Check.
u16 fontStyleSub;
u16 fontLanguage;
u16 fontRegion;
u16 fontCountry;
char fontName[64];
char fontFileName[64];
u32 fontAttributes;
u32 fontExpire;
};
class Glyph {
public:
int x;
int y;
int w;
int h;
int left;
int top;
int flags;
int shadowID;
int advanceH;
int advanceV;
int dimensionWidth, dimensionHeight;
int xAdjustH, xAdjustV;
int yAdjustH, yAdjustV;
u32 ptr;
};
#pragma pack(push,1)
struct PGFHeader
{
u16 headerOffset;
u16 headerSize;
char PGFMagic[4];
int revision;
int version;
int charMapLength;
int charPointerLength;
int charMapBpe;
int charPointerBpe;
u8 pad1[2];
u8 bpp;
u8 pad2[1];
int hSize;
int vSize;
int hResolution;
int vResolution;
u8 pad3[1];
char fontName[64];
char fontType[64];
u8 pad4[1];
u16 firstGlyph;
u16 lastGlyph;
u8 pad5[26];
int maxAscender;
int maxDescender;
int maxLeftXAdjust;
int maxBaseYAdjust;
int minCenterXAdjust;
int maxTopYAdjust;
int maxAdvance[2];
int maxSize[2];
u16 maxGlyphWidth;
u16 maxGlyphHeight;
u8 pad6[2];
u8 dimTableLength;
u8 xAdjustTableLength;
u8 yAdjustTableLength;
u8 advanceTableLength;
u8 pad7[102];
int shadowMapLength;
int shadowMapBpe;
float unknown1;
int shadowScale[2];
u8 pad8[8];
};
struct PGFHeaderRev3Extra {
int compCharMapBpe1;
int compCharMapLength1;
int compCharMapBpe2;
int compCharMapLength2;
u32 unknown;
};
struct PGFCharInfo {
u32 bitmapWidth;
u32 bitmapHeight;
u32 bitmapLeft;
u32 bitmapTop;
// Glyph metrics (in 26.6 signed fixed-point).
u32 sfp26Width;
u32 sfp26Height;
s32 sfp26Ascender;
s32 sfp26Descender;
s32 sfp26BearingHX;
s32 sfp26BearingHY;
s32 sfp26BearingVX;
s32 sfp26BearingVY;
s32 sfp26AdvanceH;
s32 sfp26AdvanceV;
u8 pad[4];
};
struct PGFFontInfo {
// Glyph metrics (in 26.6 signed fixed-point).
int maxGlyphWidthI;
int maxGlyphHeightI;
int maxGlyphAscenderI;
int maxGlyphDescenderI;
int maxGlyphLeftXI;
int maxGlyphBaseYI;
int minGlyphCenterXI;
int maxGlyphTopYI;
int maxGlyphAdvanceXI;
int maxGlyphAdvanceYI;
// Glyph metrics (replicated as float).
float maxGlyphWidthF;
float maxGlyphHeightF;
float maxGlyphAscenderF;
float maxGlyphDescenderF;
float maxGlyphLeftXF;
float maxGlyphBaseYF;
float minGlyphCenterXF;
float maxGlyphTopYF;
float maxGlyphAdvanceXF;
float maxGlyphAdvanceYF;
// Bitmap dimensions.
short maxGlyphWidth;
short maxGlyphHeight;
int charMapLength; // Number of elements in the font's charmap.
int shadowMapLength; // Number of elements in the font's shadow charmap.
// Font style (used by font comparison functions).
PGFFontStyle fontStyle;
int BPP; // Font's BPP.
};
#pragma pack(pop)
class PGF {
public:
PGF();
~PGF();
void ReadPtr(const u8 *ptr, size_t dataSize);
bool GetCharInfo(int charCode, PGFCharInfo *ci);
void GetFontInfo(PGFFontInfo *fi);
void DrawCharacter(u32 base, int bpl, int bufWidth, int bufHeight, int x, int y, int clipX, int clipY, int clipWidth, int clipHeight, int pixelformat, int charCode, int altCharCode, int glyphType);
void DoState(PointerWrap &p);
PGFHeader header;
private:
bool GetGlyph(const u8 *fontdata, size_t charPtr, int glyphType, Glyph &glyph);
bool GetCharGlyph(int charCode, int glyphType, Glyph &glyph);
// Unused
int GetCharIndex(int charCode, const std::vector<int> &charmapCompressed);
void SetFontPixel(u32 base, int bpl, int bufWidth, int bufHeight, int x, int y, int pixelColor, int pixelformat);
PGFHeaderRev3Extra rev3extra;
// Font character image data
u8 *fontData;
size_t fontDataSize;
std::string fileName;
std::vector<int> dimensionTable[2];
std::vector<int> xAdjustTable[2];
std::vector<int> yAdjustTable[2];
std::vector<int> advanceTable[2];
// Unused
std::vector<int> charmapCompressionTable1[2];
std::vector<int> charmapCompressionTable2[2];
u8 *charMap;
u8 *shadowCharMap;
u8 *charPointerTable;
std::vector<int> charmap_compr;
std::vector<int> charmap;
std::vector<Glyph> glyphs;
std::vector<Glyph> shadowGlyphs;
int firstGlyph;
};

View File

@ -96,6 +96,11 @@ template<float func()> void WrapF_V() {
RETURNF(func());
}
// TODO: Not sure about the floating point parameter passing
template<float func(int, float, u32)> void WrapF_IFU() {
RETURNF(func(PARAM(0), PARAMF(0), PARAM(1)));
}
template<u32 func(u32)> void WrapU_U() {
u32 retval = func(PARAM(0));
RETURN(retval);
@ -133,7 +138,7 @@ template<int func(u32, u32)> void WrapI_UU() {
template<int func(u32, float, float)> void WrapI_UFF() {
// Not sure about the float arguments.
int retval = func(PARAM(0), currentMIPS->f[0], currentMIPS->f[1]);
int retval = func(PARAM(0), currentMIPS->f[12], currentMIPS->f[13]);
RETURN(retval);
}
@ -481,6 +486,11 @@ template<u32 func(u32, u32, u32, u32)> void WrapU_UUUU() {
RETURN(retval);
}
template<u32 func(u32, const char *, u32, u32)> void WrapU_UCUU() {
u32 retval = func(PARAM(0), Memory::GetCharPointer(PARAM(1)), PARAM(2), PARAM(3));
RETURN(retval);
}
template<u32 func(u32, u32, u32, int)> void WrapU_UUUI() {
u32 retval = func(PARAM(0), PARAM(1), PARAM(2), PARAM(3));
RETURN(retval);

View File

@ -53,6 +53,7 @@ struct Syscall
};
#define PARAM(n) currentMIPS->r[4+n]
#define PARAMF(n) currentMIPS->f[12+n]
#define RETURN(n) currentMIPS->r[2]=n
#define RETURNF(fl) currentMIPS->f[0]=fl

File diff suppressed because it is too large Load Diff

View File

@ -5,4 +5,5 @@ class PointerWrap;
void Register_sceFont();
void __FontInit();
void __FontShutdown();
void __FontDoState(PointerWrap &p);

View File

@ -197,7 +197,7 @@ void __IoInit() {
char path_buffer[_MAX_PATH], drive[_MAX_DRIVE] ,dir[_MAX_DIR], file[_MAX_FNAME], ext[_MAX_EXT];
char memstickpath[_MAX_PATH];
char flashpath[_MAX_PATH];
char flash0path[_MAX_PATH];
GetModuleFileName(NULL,path_buffer,sizeof(path_buffer));
@ -210,24 +210,23 @@ void __IoInit() {
// Mount a couple of filesystems
sprintf(memstickpath, "%s%sMemStick\\", drive, dir);
sprintf(flashpath, "%s%sFlash\\", drive, dir);
sprintf(flash0path, "%s%sflash0\\", drive, dir);
#else
// TODO
std::string memstickpath = g_Config.memCardDirectory;
std::string flashpath = g_Config.flashDirectory;
std::string flash0path = g_Config.flashDirectory;
#endif
DirectoryFileSystem *memstick;
DirectoryFileSystem *flash;
memstick = new DirectoryFileSystem(&pspFileSystem, memstickpath);
flash = new DirectoryFileSystem(&pspFileSystem, flashpath);
DirectoryFileSystem *memstick = new DirectoryFileSystem(&pspFileSystem, memstickpath);
DirectoryFileSystem *flash0 = new DirectoryFileSystem(&pspFileSystem, flash0path);
DirectoryFileSystem *flash1 = new DirectoryFileSystem(&pspFileSystem, flash0path);
pspFileSystem.Mount("ms0:", memstick);
pspFileSystem.Mount("fatms0:", memstick);
pspFileSystem.Mount("fatms:", memstick);
pspFileSystem.Mount("flash0:", flash);
pspFileSystem.Mount("flash1:", flash);
pspFileSystem.Mount("flash0:", flash0);
pspFileSystem.Mount("flash1:", flash1);
__KernelListenThreadEnd(&TellFsThreadEnded);
}

View File

@ -128,6 +128,8 @@ void __KernelShutdown()
INFO_LOG(HLE, "Shutting down kernel - %i kernel objects alive", kernelObjects.GetCount());
kernelObjects.Clear();
__FontShutdown();
__MpegShutdown();
__PsmfShutdown();
__PPGeShutdown();

View File

@ -1,3 +1,20 @@
// Copyright (c) 2012- PPSSPP 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 or later versions.
// 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 git repository and contact information can be found at
// https://github.com/hrydgard/ppsspp and http://www.ppsspp.org/.
#include "Log.h"
#include "BlockAllocator.h"
#include "ChunkFile.h"

View File

@ -1,3 +1,19 @@
// Copyright (c) 2012- PPSSPP 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 or later versions.
// 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 git repository and contact information can be found at
// https://github.com/hrydgard/ppsspp and http://www.ppsspp.org/.
#pragma once
@ -9,8 +25,7 @@
class PointerWrap;
// Generic allocator thingy
// Allocates blocks from a range
// Generic allocator thingy. Allocates blocks from a range.
class BlockAllocator
{

View File

@ -1,25 +0,0 @@
#pragma once
#include "../../Globals.h"
// pool allocator
template <class T, int size>
class Pool
{
T pool[size];
int count;
public:
Pool()
{
Reset();
}
void Reset()
{
count=0;
}
T* Alloc()
{
_dbg_assert_msg_(CPU,count<size-1,"Pool allocator overrun!");
return &pool[count++];
}
};

View File

@ -116,6 +116,7 @@ LOCAL_SRC_FILES := \
$(SRC)/Core/Dialog/PSPPlaceholderDialog.cpp \
$(SRC)/Core/Dialog/PSPSaveDialog.cpp \
$(SRC)/Core/Dialog/SavedataParam.cpp \
$(SRC)/Core/Font/PGF.cpp \
$(SRC)/Core/HLE/HLETables.cpp \
$(SRC)/Core/HLE/HLE.cpp \
$(SRC)/Core/HLE/sceAtrac.cpp \