Lots of stuff

This commit is contained in:
elasota
2019-11-11 00:11:59 -05:00
parent 49a35bb15b
commit c8472f7295
406 changed files with 58313 additions and 88 deletions

View File

@@ -0,0 +1,20 @@
#pragma once
#ifndef __PL_AE_HANDLER_DESC_H__
#define __PL_AE_HANDLER_DESC_H__
#include "PLAppleEventsCommonTypes.h"
#include <stdint.h>
namespace PortabilityLayer
{
struct AEHandlerDesc
{
AEEventClass m_eventClass;
AEEventID m_eventID;
AEEventHandler m_handler;
uint32_t m_ref;
};
}
#endif

View File

@@ -0,0 +1,73 @@
#include "AEManager.h"
#include "AEHandlerDesc.h"
#include <vector>
namespace PortabilityLayer
{
class AEManagerImpl final : public AEManager
{
public:
AEManagerImpl();
void Init() override;
void Shutdown() override;
void InstallEventHandler(AEEventClass eventClass, AEEventID eventID, AEEventHandler handler, uint32_t ref, bool isSysHandler) override;
void SetInteractAllowed(AEInteractAllowed interactAllowed) override;
static AEManagerImpl *GetInstance();
private:
std::vector<AEHandlerDesc> m_handlers;
AEInteractAllowed m_interactAllowed;
static AEManagerImpl ms_instance;
};
AEManagerImpl::AEManagerImpl()
: m_interactAllowed(kAEInteractUnknown)
{
}
void AEManagerImpl::Init()
{
m_interactAllowed = kAEInteractUnknown;
}
void AEManagerImpl::Shutdown()
{
m_handlers.clear();
}
void AEManagerImpl::InstallEventHandler(AEEventClass eventClass, AEEventID eventID, AEEventHandler handler, uint32_t ref, bool isSysHandler)
{
AEHandlerDesc desc;
desc.m_eventClass = eventClass;
desc.m_eventID = eventID;
desc.m_handler = handler;
desc.m_ref = ref;
m_handlers.push_back(desc);
}
void AEManagerImpl::SetInteractAllowed(AEInteractAllowed interactAllowed)
{
m_interactAllowed = interactAllowed;
}
AEManagerImpl *AEManagerImpl::GetInstance()
{
return &ms_instance;
}
AEManagerImpl AEManagerImpl::ms_instance;
AEManager *AEManager::GetInstance()
{
return AEManagerImpl::GetInstance();
}
}

View File

@@ -0,0 +1,24 @@
#pragma once
#ifndef __PL_AE_MANAGER_H__
#define __PL_AE_MANAGER_H__
#include "PLAppleEventsCommonTypes.h"
#include <stdint.h>
namespace PortabilityLayer
{
class AEManager
{
public:
virtual void Init() = 0;
virtual void Shutdown() = 0;
virtual void InstallEventHandler(AEEventClass eventClass, AEEventID eventID, AEEventHandler handler, uint32_t ref, bool isSysHandler) = 0;
virtual void SetInteractAllowed(AEInteractAllowed interactAllowed) = 0;
static AEManager *GetInstance();
};
}
#endif

View File

@@ -0,0 +1,302 @@
#include "BinHex4.h"
#include "IOStream.h"
#include <string.h>
#include <vector>
#include <assert.h>
// See: https://files.stairways.com/other/binhex-40-specs-info.txt
// Unfortunately, while the spec specifies that decoding is to be done high-to-low,
// it doesn't specify how the encoded 6-bit value is split.
#include "MacFileInfo.h"
#include "ByteUnpack.h"
#include "XModemCRC.h"
#include "MacFileMem.h"
namespace
{
static bool IsEOL(char c)
{
return c == '\r' || c == '\n';
}
static bool IsWhitespaceChar(char c)
{
return c == '\r' || c == '\n' || c == ' ' || c == '\t';
}
uint16_t BinHexCRCNoPadding(const uint8_t *bytes, size_t size, int initialValue)
{
uint16_t crc = initialValue;
for (size_t b = 0; b < size; b++)
{
uint8_t v = bytes[b];
for (int i = 0; i < 8; i++)
{
int temp = (crc & 0x8000);
crc = (crc << 1) | (v >> 7);
if (temp)
crc = crc ^ 0x1021;
v = (v << 1) & 0xff;
}
}
return static_cast<uint16_t>(crc);
}
uint16_t BinHexCRC(const uint8_t *bytes, size_t size)
{
const uint8_t zeroBytes[] = { 0, 0 };
uint16_t crc = BinHexCRCNoPadding(bytes, size, 0);
return BinHexCRCNoPadding(zeroBytes, 2, crc);
}
}
namespace PortabilityLayer
{
MacFileMem *BinHex4::LoadHQX(IOStream *stream)
{
const uint8_t errCodeChar = 64;
uint8_t charMap[128];
for (int i = 0; i < 128; i++)
charMap[i] = errCodeChar;
const char binHexCharacters[] = "!\"#$%&'()*+,-012345689@ABCDEFGHIJKLMNPQRSTUVXYZ[`abcdefhijklmpqr";
for (int i = 0; i < 64; i++)
charMap[binHexCharacters[i]] = static_cast<uint8_t>(i);
const char expectedPrefix[] = "(This file must be converted with BinHex";
const size_t prefixSizeChars = sizeof(expectedPrefix) - 1;
char prefix[prefixSizeChars];
if (stream->Read(prefix, prefixSizeChars) != prefixSizeChars)
return nullptr;
if (memcmp(prefix, expectedPrefix, prefixSizeChars))
return nullptr;
// Find end char
for (;;)
{
char nextChar;
if (!stream->Read(&nextChar, 1))
return nullptr;
if (IsEOL(nextChar))
break;
}
// Find start colon
for (;;)
{
char nextChar;
if (!stream->Read(&nextChar, 1))
return nullptr;
if (IsWhitespaceChar(nextChar))
continue;
else if (nextChar == ':')
break;
else
return nullptr;
}
std::vector<uint8_t> bytesAfter6To8;
if (stream->IsSeekable())
{
UFilePos_t filePos = stream->Tell();
if (stream->SeekEnd(0))
{
UFilePos_t endPos = stream->Tell();
if (!stream->SeekStart(filePos))
return nullptr;
if (endPos > filePos && (endPos - filePos) < SIZE_MAX / 6)
bytesAfter6To8.reserve(static_cast<size_t>(endPos - filePos) * 6 / 8);
}
}
// Undo 8-to-6 coding
const size_t bufferCapacity = 128;
size_t bufferReadPos = 0;
size_t bufferSize = 0;
char buffer[bufferCapacity];
bool isEOF = false;
int decodedByte = 0;
int decodedByteBitPos = 8;
for (;;)
{
if (bufferReadPos == bufferSize)
{
const size_t numRead = stream->Read(buffer, bufferCapacity);
if (numRead == 0)
return nullptr; // Missing terminator
bufferSize = numRead;
bufferReadPos = 0;
}
char nextChar = buffer[bufferReadPos++];
if (nextChar == ':')
break;
if (IsWhitespaceChar(nextChar))
continue;
if (nextChar < 0 || nextChar > 127)
return nullptr;
uint8_t value6Bit = charMap[nextChar];
if (value6Bit == errCodeChar)
return nullptr;
switch (decodedByteBitPos)
{
case 8:
decodedByte = value6Bit << 2;
decodedByteBitPos = 2;
break;
case 6:
decodedByte |= value6Bit;
bytesAfter6To8.push_back(decodedByte);
decodedByte = 0;
decodedByteBitPos = 8;
break;
case 4:
decodedByte |= (value6Bit >> 2);
bytesAfter6To8.push_back(decodedByte);
decodedByte = (value6Bit << 6) & 0xff;
decodedByteBitPos = 6;
break;
case 2:
decodedByte |= (value6Bit >> 4);
bytesAfter6To8.push_back(decodedByte);
decodedByte = (value6Bit << 4) & 0xff;
decodedByteBitPos = 4;
break;
default:
return nullptr;
}
}
const size_t bytesBeforeRLEDec = bytesAfter6To8.size();
size_t decodedDataSize = 0;
for (size_t i = 0; i < bytesBeforeRLEDec; i++)
{
const uint8_t b = bytesAfter6To8[i];
if (b == 0x90)
{
if (i == bytesBeforeRLEDec - 1)
return nullptr;
const uint8_t runLength = bytesAfter6To8[++i];
if (runLength == 0)
decodedDataSize++; // 0x90 literal
else
decodedDataSize += runLength - 1; // RLE, runs of length 1 are permitted
}
else
decodedDataSize++;
}
std::vector<uint8_t> decodedBytes;
decodedBytes.reserve(decodedDataSize);
for (size_t i = 0; i < bytesBeforeRLEDec; i++)
{
const uint8_t b = bytesAfter6To8[i];
if (b == 0x90)
{
const uint8_t runLength = bytesAfter6To8[++i];
if (runLength == 0)
decodedBytes.push_back(0x90);
else
{
if (decodedBytes.size() == 0)
return nullptr;
const uint8_t lastByte = *(decodedBytes.end() - 1);
for (size_t r = 1; r < runLength; r++)
decodedBytes.push_back(lastByte);
}
}
else
decodedBytes.push_back(b);
}
assert(decodedBytes.size() == decodedDataSize);
if (decodedBytes.size() == 0)
return nullptr;
const uint8_t nameLength = decodedBytes[0];
if (decodedBytes.size() < 22 + nameLength || nameLength > 63)
return nullptr;
// Header format:
// uint8_t nameLength
// char name[nameLength]
// char <null>
// char fileType[4]
// char fileCreator[4]
// word flags
// dword dataLength
// dword resourceLength
// word headerCRC
const size_t headerStartLoc = 2 + nameLength;
if (decodedBytes[nameLength + 1] != 0)
return nullptr;
MacFileInfo mfi;
mfi.m_fileName.Set(nameLength, reinterpret_cast<const char*>(&decodedBytes[1]));
memcpy(mfi.m_properties.m_fileType, &decodedBytes[headerStartLoc + 0], 4);
memcpy(mfi.m_properties.m_fileCreator, &decodedBytes[headerStartLoc + 4], 4);
mfi.m_properties.m_finderFlags = ByteUnpack::BigUInt16(&decodedBytes[headerStartLoc + 8]);
mfi.m_dataForkSize = ByteUnpack::BigUInt32(&decodedBytes[headerStartLoc + 10]);
mfi.m_resourceForkSize = ByteUnpack::BigUInt32(&decodedBytes[headerStartLoc + 14]);
const size_t availableDataSize = decodedBytes.size() - 26 - nameLength; // +4 bytes for CRCs
if (mfi.m_dataForkSize > availableDataSize || availableDataSize - mfi.m_dataForkSize < mfi.m_resourceForkSize)
return nullptr;
const uint16_t expectedHeaderCRC = ByteUnpack::BigUInt16(&decodedBytes[headerStartLoc + 18]);
const uint16_t actualHeaderCRC = BinHexCRC(&decodedBytes[0], headerStartLoc + 18);
if (expectedHeaderCRC != actualHeaderCRC)
return nullptr;
const size_t dataForkStart = headerStartLoc + 20;
const size_t dataForkCRCLoc = dataForkStart + mfi.m_dataForkSize;
const size_t resourceForkStart = dataForkCRCLoc + 2;
const size_t resourceForkCRCLoc = resourceForkStart + mfi.m_resourceForkSize;
const uint16_t expectedDataCRC = ByteUnpack::BigUInt16(&decodedBytes[dataForkCRCLoc]);
const uint16_t expectedResCRC = ByteUnpack::BigUInt16(&decodedBytes[resourceForkCRCLoc]);
if (expectedDataCRC != BinHexCRC(&decodedBytes[dataForkStart], mfi.m_dataForkSize))
return false;
if (expectedResCRC != BinHexCRC(&decodedBytes[resourceForkStart], mfi.m_resourceForkSize))
return false;
return new MacFileMem(&decodedBytes[dataForkStart], &decodedBytes[resourceForkStart], nullptr, mfi);
}
}

View File

@@ -0,0 +1,17 @@
#pragma once
#ifndef __PL_BINHEX4_H__
#define __PL_BINHEX4_H__
namespace PortabilityLayer
{
class IOStream;
class MacFileMem;
namespace BinHex4
{
MacFileMem *LoadHQX(IOStream *stream);
};
}
#endif

View File

@@ -0,0 +1,36 @@
#pragma once
#ifndef __PL_BINARY_SEARCH_H__
#define __PL_BINARY_SEARCH_H__
#include <stdint.h>
namespace PortabilityLayer
{
template<class TIterator, class TItem, class TPredicate>
TIterator BinarySearch(const TIterator &startInclusive, const TIterator &endExclusive, const TItem &item, const TPredicate &pred)
{
TIterator searchStartInclusive = startInclusive;
TIterator searchEndExclusive = endExclusive;
while (searchStartInclusive != searchEndExclusive)
{
const ptrdiff_t delta = searchEndExclusive - searchStartInclusive;
const ptrdiff_t halfDelta = delta / 2;
const TIterator midPoint = searchStartInclusive + halfDelta;
const int comparison = pred(item, *midPoint);
if (comparison < 0)
searchEndExclusive = midPoint;
else if (comparison > 0)
searchStartInclusive = midPoint + 1;
else
return midPoint;
}
return endExclusive;
}
}
#endif

View File

@@ -0,0 +1,76 @@
#pragma once
#ifndef __PL_BYTEPACK_H__
#define __PL_BYTEPACK_H__
#include "DataTypes.h"
namespace PortabilityLayer
{
namespace BytePack
{
void BigUInt64(uint8_t *bytes, uint64_t value);
void BigUInt32(uint8_t *bytes, uint32_t value);
void BigUInt16(uint8_t *bytes, uint16_t value);
}
}
namespace PortabilityLayer
{
namespace BytePack
{
inline void BigUInt64(uint8_t *bytes, uint64_t value)
{
bytes[0] = static_cast<uint8_t>((value >> 56) & 0xff);
bytes[1] = static_cast<uint8_t>((value >> 48) & 0xff);
bytes[2] = static_cast<uint8_t>((value >> 40) & 0xff);
bytes[3] = static_cast<uint8_t>((value >> 32) & 0xff);
bytes[4] = static_cast<uint8_t>((value >> 24) & 0xff);
bytes[5] = static_cast<uint8_t>((value >> 16) & 0xff);
bytes[6] = static_cast<uint8_t>((value >> 8) & 0xff);
bytes[7] = static_cast<uint8_t>(value & 0xff);
}
inline void BigUInt32(uint8_t *bytes, uint32_t value)
{
bytes[0] = static_cast<uint8_t>((value >> 24) & 0xff);
bytes[1] = static_cast<uint8_t>((value >> 16) & 0xff);
bytes[2] = static_cast<uint8_t>((value >> 8) & 0xff);
bytes[3] = static_cast<uint8_t>(value & 0xff);
}
inline void BigUInt16(uint8_t *bytes, uint16_t value)
{
bytes[0] = static_cast<uint8_t>((value >> 8) & 0xff);
bytes[1] = static_cast<uint8_t>(value & 0xff);
}
inline void BigInt64(uint8_t *bytes, int64_t value)
{
bytes[0] = static_cast<uint8_t>((value >> 56) & 0xff);
bytes[1] = static_cast<uint8_t>((value >> 48) & 0xff);
bytes[2] = static_cast<uint8_t>((value >> 40) & 0xff);
bytes[3] = static_cast<uint8_t>((value >> 32) & 0xff);
bytes[4] = static_cast<uint8_t>((value >> 24) & 0xff);
bytes[5] = static_cast<uint8_t>((value >> 16) & 0xff);
bytes[6] = static_cast<uint8_t>((value >> 8) & 0xff);
bytes[7] = static_cast<uint8_t>(value & 0xff);
}
inline void BigInt32(uint8_t *bytes, uint32_t value)
{
bytes[0] = static_cast<uint8_t>((value >> 24) & 0xff);
bytes[1] = static_cast<uint8_t>((value >> 16) & 0xff);
bytes[2] = static_cast<uint8_t>((value >> 8) & 0xff);
bytes[3] = static_cast<uint8_t>(value & 0xff);
}
inline void BigInt16(uint8_t *bytes, uint16_t value)
{
bytes[0] = static_cast<uint8_t>((value >> 8) & 0xff);
bytes[1] = static_cast<uint8_t>(value & 0xff);
}
}
}
#endif

View File

@@ -0,0 +1,37 @@
#include "ByteSwap.h"
namespace PortabilityLayer
{
namespace ByteSwap
{
void BigInt16(int16_t &v)
{
const uint8_t *asU8 = reinterpret_cast<const uint8_t*>(&v);
const int8_t *asS8 = reinterpret_cast<const int8_t*>(&v);
v = static_cast<int16_t>((asS8[0] << 8) | asU8[1]);
}
void BigInt32(int32_t &v)
{
const uint8_t *asU8 = reinterpret_cast<const uint8_t*>(&v);
const int8_t *asS8 = reinterpret_cast<const int8_t*>(&v);
v = static_cast<int32_t>((asS8[0] << 24) | (asU8[1] << 16) | (asU8[2] << 8) | asU8[3]);
}
void BigUInt16(uint16_t &v)
{
const uint8_t *asU8 = reinterpret_cast<const uint8_t*>(&v);
v = static_cast<uint16_t>((asU8[0] << 8) | asU8[1]);
}
void BigUInt32(uint32_t &v)
{
const uint8_t *asU8 = reinterpret_cast<const uint8_t*>(&v);
v = static_cast<uint32_t>((asU8[0] << 24) | (asU8[1] << 16) | (asU8[2] << 8) | asU8[3]);
}
}
}

View File

@@ -0,0 +1,18 @@
#pragma once
#ifndef __PL_BYTESWAP_H__
#define __PL_BYTESWAP_H__
#include <stdint.h>
namespace PortabilityLayer
{
namespace ByteSwap
{
void BigInt16(int16_t &v);
void BigInt32(int32_t &v);
void BigUInt16(uint16_t &v);
void BigUInt32(uint32_t &v);
}
}
#endif

View File

@@ -0,0 +1,78 @@
#pragma once
#ifndef __PL_BYTEUNPACK_H__
#define __PL_BYTEUNPACK_H__
#include "DataTypes.h"
namespace PortabilityLayer
{
namespace ByteUnpack
{
uint64_t BigUInt64(const uint8_t *bytes);
uint32_t BigUInt32(const uint8_t *bytes);
uint16_t BigUInt16(const uint8_t *bytes);
int64_t BigInt64(const uint8_t *bytes);
int32_t BigInt32(const uint8_t *bytes);
int16_t BigInt16(const uint8_t *bytes);
}
}
namespace PortabilityLayer
{
namespace ByteUnpack
{
inline uint64_t BigUInt64(const uint8_t *bytes)
{
return (static_cast<uint64_t>(bytes[0]) << 56)
| (static_cast<uint64_t>(bytes[1]) << 48)
| (static_cast<uint64_t>(bytes[2]) << 32)
| (static_cast<uint64_t>(bytes[3]) << 24)
| (static_cast<uint64_t>(bytes[4]) << 16)
| (static_cast<uint64_t>(bytes[5]) << 8)
| (static_cast<uint64_t>(bytes[6]));
}
inline uint32_t BigUInt32(const uint8_t *bytes)
{
return (static_cast<uint32_t>(bytes[0]) << 24)
| (static_cast<uint32_t>(bytes[1]) << 16)
| (static_cast<uint32_t>(bytes[2]) << 8)
| (static_cast<uint32_t>(bytes[3]));
}
inline uint16_t BigUInt16(const uint8_t *bytes)
{
return (static_cast<uint16_t>(bytes[0]) << 8)
| (static_cast<uint16_t>(bytes[1]));
}
inline int64_t BigInt64(const uint8_t *bytes)
{
return (static_cast<int64_t>(bytes[0]) << 56)
| (static_cast<int64_t>(bytes[1]) << 48)
| (static_cast<int64_t>(bytes[2]) << 32)
| (static_cast<int64_t>(bytes[3]) << 24)
| (static_cast<int64_t>(bytes[4]) << 16)
| (static_cast<int64_t>(bytes[5]) << 8)
| (static_cast<int64_t>(bytes[6]));
}
inline int32_t BigInt32(const uint8_t *bytes)
{
return (static_cast<int32_t>(bytes[0]) << 24)
| (static_cast<int32_t>(bytes[1]) << 16)
| (static_cast<int32_t>(bytes[2]) << 8)
| (static_cast<int32_t>(bytes[3]));
}
inline int16_t BigInt16(const uint8_t *bytes)
{
return (static_cast<int16_t>(bytes[0]) << 8)
| (static_cast<int16_t>(bytes[1]));
}
}
}
#endif

View File

@@ -0,0 +1,110 @@
#include "CFileStream.h"
namespace PortabilityLayer
{
CFileStream::CFileStream(FILE *f)
: m_file(f)
, m_readOnly(false)
, m_writeOnly(false)
, m_seekable(true)
{
}
CFileStream::CFileStream(FILE *f, bool isReadOnly, bool isWriteOnly, bool isSeekable)
: m_file(f)
, m_readOnly(isReadOnly)
, m_writeOnly(isWriteOnly)
, m_seekable(isSeekable)
{
}
size_t CFileStream::Read(void *bytesOut, size_t size)
{
if (!m_file || m_writeOnly)
return 0;
return fread(bytesOut, 1, size, m_file);
}
size_t CFileStream::Write(const void *bytes, size_t size)
{
if (!m_file || m_readOnly)
return 0;
return fwrite(bytes, 1, size, m_file);
}
bool CFileStream::IsSeekable() const
{
return m_seekable;
}
bool CFileStream::IsReadOnly() const
{
return m_readOnly;
}
bool CFileStream::IsWriteOnly() const
{
return m_writeOnly;
}
bool CFileStream::SeekStart(UFilePos_t loc)
{
if (!m_file)
return false;
return fseek(m_file, static_cast<long>(loc), SEEK_SET) == 0;
}
bool CFileStream::SeekCurrent(FilePos_t loc)
{
if (!m_file)
return false;
return fseek(m_file, static_cast<long>(loc), SEEK_CUR) == 0;;
}
bool CFileStream::SeekEnd(UFilePos_t loc)
{
if (!m_file)
return false;
return fseek(m_file, static_cast<long>(loc), SEEK_END) == 0;
}
bool CFileStream::Truncate(UFilePos_t loc)
{
return false;
}
UFilePos_t CFileStream::Tell() const
{
if (!m_file)
return 0;
return static_cast<UFilePos_t>(ftell(m_file));
}
void CFileStream::Close()
{
if (m_file)
{
fclose(m_file);
m_file = nullptr;
}
}
UFilePos_t CFileStream::Size() const
{
if (!m_file || !m_seekable)
return 0;
long oldPos = ftell(m_file);
fseek(m_file, SEEK_END, 0);
const UFilePos_t endPos = static_cast<UFilePos_t>(ftell(m_file));
fseek(m_file, oldPos, SEEK_SET);
return endPos;
}
}

View File

@@ -0,0 +1,42 @@
#pragma once
#ifndef __PL_CFILESTREAM_H__
#define __PL_CFILESTREAM_H__
#include <stdio.h>
#include "CoreDefs.h"
#include "IOStream.h"
namespace PortabilityLayer
{
class CFileStream final : public IOStream
{
public:
explicit CFileStream(FILE *f);
CFileStream(FILE *f, bool isReadOnly, bool isWriteOnly, bool isSeekable);
size_t Read(void *bytesOut, size_t size) override;
size_t Write(const void *bytes, size_t size) override;
bool IsSeekable() const override;
bool IsReadOnly() const override;
bool IsWriteOnly() const override;
bool SeekStart(UFilePos_t loc) override;
bool SeekCurrent(FilePos_t loc) override;
bool SeekEnd(UFilePos_t loc) override;
bool Truncate(UFilePos_t loc) override;
UFilePos_t Size() const override;
UFilePos_t Tell() const override;
void Close() override;
private:
CFileStream(const CFileStream &other) PL_DELETED;
FILE *m_file;
bool m_readOnly;
bool m_writeOnly;
bool m_seekable;
};
}
#endif

View File

@@ -0,0 +1,14 @@
#pragma once
#ifndef __PL_DATATYPES_H__
#define __PL_DATATYPES_H__
#include <stdint.h>
namespace PortabilityLayer
{
typedef int64_t LargestInt_t;
typedef uint64_t LargestUInt_t;
}
#endif

View File

@@ -0,0 +1,75 @@
#include "DisplayDeviceManager.h"
#include "PLQuickdraw.h"
#include "MemoryManager.h"
namespace PortabilityLayer
{
class DisplayDeviceManagerImpl final : public DisplayDeviceManager
{
public:
DisplayDeviceManagerImpl();
void Init() override;
void Shutdown() override;
GDevice **GetMainDevice() override;
void IncrementTickCount(uint32_t count) override;
uint32_t GetTickCount() override;
static DisplayDeviceManagerImpl *GetInstance();
private:
GDHandle m_mainDevice;
uint32_t m_tickCount;
static DisplayDeviceManagerImpl ms_instance;
};
DisplayDeviceManagerImpl::DisplayDeviceManagerImpl()
: m_mainDevice(nullptr)
, m_tickCount(1)
{
}
void DisplayDeviceManagerImpl::Init()
{
m_mainDevice = MemoryManager::GetInstance()->NewHandle<GDevice>();
}
void DisplayDeviceManagerImpl::Shutdown()
{
MemoryManager::GetInstance()->ReleaseHandle(reinterpret_cast<MMHandleBlock*>(m_mainDevice));
}
GDevice **DisplayDeviceManagerImpl::GetMainDevice()
{
return m_mainDevice;
}
void DisplayDeviceManagerImpl::IncrementTickCount(uint32_t count)
{
m_tickCount += count;
}
uint32_t DisplayDeviceManagerImpl::GetTickCount()
{
return m_tickCount;
}
DisplayDeviceManagerImpl *DisplayDeviceManagerImpl::GetInstance()
{
return &ms_instance;
}
DisplayDeviceManagerImpl DisplayDeviceManagerImpl::ms_instance;
DisplayDeviceManager *DisplayDeviceManager::GetInstance()
{
return DisplayDeviceManagerImpl::GetInstance();
}
}

View File

@@ -0,0 +1,25 @@
#pragma once
#ifndef __PL_DEVICE_MANAGER_H__
#define __PL_DEVICE_MANAGER_H__
#include <stdint.h>
struct GDevice;
namespace PortabilityLayer
{
class DisplayDeviceManager
{
public:
virtual void Init() = 0;
virtual void Shutdown() = 0;
virtual GDevice **GetMainDevice() = 0;
virtual void IncrementTickCount(uint32_t count) = 0;
virtual uint32_t GetTickCount() = 0;
static DisplayDeviceManager *GetInstance();
};
}
#endif

View File

@@ -0,0 +1,207 @@
#include "FileManager.h"
#include "HostFileSystem.h"
#include "HostMemoryBuffer.h"
#include "MemReaderStream.h"
#include "MacBinary2.h"
#include "MacFileMem.h"
#include "PLPasStr.h"
#include "PLErrorCodes.h"
#include <vector>
namespace PortabilityLayer
{
class VirtualFile;
class FileManagerImpl final : public FileManager
{
public:
bool FileExists(uint32_t dirID, const PLPasStr &filename) override;
int OpenFileDF(uint32_t dirID, const PLPasStr &filename, EFilePermission filePermission, short *outRefNum) override;
int OpenFileRF(uint32_t dirID, const PLPasStr &filename, EFilePermission filePermission, short *outRefNum) override;
int RawOpenFileDF(uint32_t dirID, const PLPasStr &filename, EFilePermission filePermission, bool ignoreMeta, IOStream **outStream) override;
int RawOpenFileRF(uint32_t dirID, const PLPasStr &filename, EFilePermission filePermission, bool ignoreMeta, IOStream **outStream) override;
static FileManagerImpl *GetInstance();
private:
typedef char ExtendedFileName_t[64 + 4];
struct OpenedFile
{
EVirtualDirectory m_dirID;
PascalStr<64> m_fileName;
IOStream *m_stream;
};
int OpenFileFork(uint32_t dirID, const PLPasStr &filename, const char *ext, EFilePermission permission, short *outRefNum);
int RawOpenFileFork(uint32_t dirID, const PLPasStr &filename, const char *ext, EFilePermission permission, bool ignoreMeta, IOStream **outStream);
static bool ConstructFilename(ExtendedFileName_t& extFN, const PLPasStr &fn, const char *extension);
std::vector<OpenedFile> m_refs;
static FileManagerImpl ms_instance;
};
bool FileManagerImpl::FileExists(uint32_t dirID, const PLPasStr &filename)
{
ExtendedFileName_t extFN;
if (!ConstructFilename(extFN, filename, ".gpf"))
return false;
return HostFileSystem::GetInstance()->FileExists(static_cast<EVirtualDirectory>(dirID), extFN);
}
int FileManagerImpl::OpenFileDF(uint32_t dirID, const PLPasStr &filename, EFilePermission permission, short *outRefNum)
{
return OpenFileFork(dirID, filename, ".gpd", permission, outRefNum);
}
int FileManagerImpl::OpenFileRF(uint32_t dirID, const PLPasStr &filename, EFilePermission permission, short *outRefNum)
{
return OpenFileFork(dirID, filename, ".gpr", permission, outRefNum);
}
int FileManagerImpl::RawOpenFileDF(uint32_t dirID, const PLPasStr &filename, EFilePermission permission, bool ignoreMeta, IOStream **outStream)
{
return RawOpenFileFork(dirID, filename, ".gpd", permission, ignoreMeta, outStream);
}
int FileManagerImpl::RawOpenFileRF(uint32_t dirID, const PLPasStr &filename, EFilePermission permission, bool ignoreMeta, IOStream **outStream)
{
return RawOpenFileFork(dirID, filename, ".gpr", permission, ignoreMeta, outStream);
}
FileManagerImpl *FileManagerImpl::GetInstance()
{
return &ms_instance;
}
int FileManagerImpl::OpenFileFork(uint32_t dirID, const PLPasStr &filename, const char *extension, EFilePermission permission, short *outRefNum)
{
const size_t numRefs = m_refs.size();
size_t refIndex = m_refs.size();
for (size_t i = 0; i < numRefs; i++)
{
if (m_refs[i].m_stream == nullptr)
{
refIndex = i;
break;
}
}
if (refIndex == 0x7fff)
return tmfoErr;
IOStream *stream = nullptr;
int openError = RawOpenFileFork(dirID, filename, extension, permission, false, &stream);
if (openError != 0)
return openError;
if (refIndex == numRefs)
m_refs.push_back(OpenedFile());
OpenedFile &of = m_refs[refIndex];
of.m_stream = stream;
of.m_dirID = static_cast<EVirtualDirectory>(dirID);
of.m_fileName.Set(filename.Length(), filename.Chars());
*outRefNum = static_cast<short>(refIndex + 1);
return noErr;
}
int FileManagerImpl::RawOpenFileFork(uint32_t dirID, const PLPasStr &filename, const char *ext, EFilePermission permission, bool ignoreMeta, IOStream **outStream)
{
ExtendedFileName_t gpfExtFN;
ExtendedFileName_t extFN;
if (filename.Length() > 63)
return bdNamErr;
if (!ignoreMeta)
{
if (!ConstructFilename(gpfExtFN, filename, ".gpf"))
return bdNamErr;
if (!HostFileSystem::GetInstance()->FileExists(static_cast<EVirtualDirectory>(dirID), gpfExtFN))
return fnfErr;
}
const bool needToCreate = !(ignoreMeta || HostFileSystem::GetInstance()->FileExists(static_cast<EVirtualDirectory>(dirID), extFN));
if (!ConstructFilename(extFN, filename, ext))
return bdNamErr;
IOStream *fstream = nullptr;
switch (permission)
{
case EFilePermission_Any:
fstream = HostFileSystem::GetInstance()->OpenFile(static_cast<EVirtualDirectory>(dirID), extFN, true, needToCreate);
if (fstream)
permission = EFilePermission_ReadWrite;
else
{
permission = EFilePermission_Read;
fstream = HostFileSystem::GetInstance()->OpenFile(static_cast<EVirtualDirectory>(dirID), extFN, false, needToCreate);
}
break;
case EFilePermission_Read:
fstream = HostFileSystem::GetInstance()->OpenFile(static_cast<EVirtualDirectory>(dirID), extFN, false, needToCreate);
break;
case EFilePermission_ReadWrite:
fstream = HostFileSystem::GetInstance()->OpenFile(static_cast<EVirtualDirectory>(dirID), extFN, true, needToCreate);
break;
}
if (!fstream)
return permErr;
*outStream = fstream;
return noErr;
}
bool FileManagerImpl::ConstructFilename(ExtendedFileName_t& extFN, const PLPasStr &fn, const char *extension)
{
const size_t fnameSize = fn.Length();
if (fnameSize >= 64)
return false;
memcpy(extFN, fn.Chars(), fnameSize);
memcpy(extFN + fnameSize, extension, strlen(extension) + 1);
for (size_t i = 0; i < fnameSize; i++)
{
const char c = extFN[i];
if (c >= '0' && c <= '9')
continue;
if (c == '_')
continue;
if (c == ' ' && i != 0 && i != fnameSize - 1)
continue;
if (c >= 'a' && c <= 'z')
continue;
if (c >= 'A' && c <= 'Z')
continue;
return false;
}
return true;
}
FileManagerImpl FileManagerImpl::ms_instance;
FileManager *FileManager::GetInstance()
{
return FileManagerImpl::GetInstance();
}
}

View File

@@ -0,0 +1,31 @@
#pragma once
#ifndef __PL_FILE_MANAGER_H__
#define __PL_FILE_MANAGER_H__
#include "FilePermission.h"
#include "CoreDefs.h"
#include <stdint.h>
class PLPasStr;
namespace PortabilityLayer
{
class IOStream;
class FileManager
{
public:
virtual bool FileExists(uint32_t dirID, const PLPasStr &filename) = 0;
virtual int OpenFileDF(uint32_t dirID, const PLPasStr &filename, EFilePermission filePermission, short *outRefNum) = 0;
virtual int OpenFileRF(uint32_t dirID, const PLPasStr &filename, EFilePermission filePermission, short *outRefNum) = 0;
virtual int RawOpenFileDF(uint32_t dirID, const PLPasStr &filename, EFilePermission filePermission, bool ignoreMeta, IOStream **outStream) = 0;
virtual int RawOpenFileRF(uint32_t dirID, const PLPasStr &filename, EFilePermission filePermission, bool ignoreMeta, IOStream **outStream) = 0;
static FileManager *GetInstance();
};
}
#endif

View File

@@ -0,0 +1,15 @@
#pragma once
#ifndef __PL_FILE_PERMISSION_H__
#define __PL_FILE_PERMISSION_H__
namespace PortabilityLayer
{
enum EFilePermission
{
EFilePermission_Any,
EFilePermission_Read,
EFilePermission_ReadWrite,
};
}
#endif

View File

@@ -0,0 +1,42 @@
#pragma once
#ifndef __GPAPP_INTERFACE_H__
#define __GPAPP_INTERFACE_H__
#include "HostSuspendHook.h"
#include <stdint.h>
#ifdef GP_APP_DLL
#ifdef GP_APP_DLL_EXPORT
#define GP_APP_DLL_EXPORT_API extern "C" __declspec(dllexport)
#else
#define GP_APP_DLL_EXPORT_API extern "C" __declspec(dllimport)
#endif
#else
#define GP_APP_DLL_EXPORT_API extern "C"
#endif
namespace PortabilityLayer
{
class HostFileSystem;
class HostDisplayDriver;
class HostSystemServices;
}
class GpAppInterface
{
public:
virtual int ApplicationMain() = 0;
virtual void PL_IncrementTickCounter(uint32_t count) = 0;
virtual void PL_HostFileSystem_SetInstance(PortabilityLayer::HostFileSystem *instance) = 0;
virtual void PL_HostDisplayDriver_SetInstance(PortabilityLayer::HostDisplayDriver *instance) = 0;
virtual void PL_HostSystemServices_SetInstance(PortabilityLayer::HostSystemServices *instance) = 0;
virtual void PL_InstallHostSuspendHook(PortabilityLayer::HostSuspendHook_t hook, void *context) = 0;
};
GP_APP_DLL_EXPORT_API GpAppInterface *GpAppInterface_Get();
#endif

View File

@@ -0,0 +1,16 @@
#include "HostDisplayDriver.h"
namespace PortabilityLayer
{
HostDisplayDriver *HostDisplayDriver::GetInstance()
{
return ms_instance;
}
void HostDisplayDriver::SetInstance(HostDisplayDriver *instance)
{
ms_instance = instance;
}
HostDisplayDriver *HostDisplayDriver::ms_instance;
}

View File

@@ -0,0 +1,21 @@
#pragma once
#ifndef __PL_HOST_DISPLAY_DRIVER_H__
#define __PL_HOST_DISPLAY_DRIVER_H__
namespace PortabilityLayer
{
class HostDisplayDriver
{
public:
virtual void GetDisplayResolution(unsigned int &width, unsigned int &height) = 0;
virtual void HideCursor() = 0;
static void SetInstance(HostDisplayDriver *instance);
static HostDisplayDriver *GetInstance();
private:
static HostDisplayDriver *ms_instance;
};
}
#endif

View File

@@ -0,0 +1,16 @@
#include "HostFileSystem.h"
namespace PortabilityLayer
{
HostFileSystem *HostFileSystem::GetInstance()
{
return ms_instance;
}
void HostFileSystem::SetInstance(HostFileSystem *instance)
{
ms_instance = instance;
}
HostFileSystem *HostFileSystem::ms_instance;
}

View File

@@ -0,0 +1,25 @@
#pragma once
#ifndef __PL_HOST_FILESYSTEM_H__
#define __PL_HOST_FILESYSTEM_H__
#include "VirtualDirectory.h"
namespace PortabilityLayer
{
class IOStream;
class HostFileSystem
{
public:
virtual bool FileExists(EVirtualDirectory virtualDirectory, const char *path) = 0;
virtual IOStream *OpenFile(EVirtualDirectory virtualDirectory, const char *path, bool writeAccess, bool create) = 0;
static HostFileSystem *GetInstance();
static void SetInstance(HostFileSystem *instance);
private:
static HostFileSystem *ms_instance;
};
}
#endif

View File

@@ -0,0 +1,20 @@
#pragma once
#ifndef __PL_HOST_MEMORYBUFFER_H__
#define __PL_HOST_MEMORYBUFFER_H__
#include <stdint.h>
#include "CoreDefs.h"
namespace PortabilityLayer
{
class HostMemoryBuffer
{
public:
virtual void *Contents() = 0;
virtual size_t Size() = 0;
virtual void Destroy() = 0;
};
}
#endif

View File

@@ -0,0 +1,17 @@
#pragma once
#include <stdint.h>
#include "HostSuspendCallID.h"
namespace PortabilityLayer
{
union HostSuspendCallArgument
{
uint32_t m_uint;
int32_t m_int;
size_t m_size;
void *m_pointer;
const void *m_constPointer;
};
}

View File

@@ -0,0 +1,15 @@
#pragma once
#ifndef __PL_HOST_API_CALL_ID_H__
#define __PL_HOST_API_CALL_ID_H__
namespace PortabilityLayer
{
enum HostSuspendCallID
{
HostSuspendCallID_Unknown,
HostSuspendCallID_Delay,
};
}
#endif

View File

@@ -0,0 +1,22 @@
#include "HostSuspendHook.h"
#include "HostSuspendCallArgument.h"
namespace
{
static PortabilityLayer::HostSuspendHook_t gs_suspendHook;
static void *gs_suspendContext;
}
namespace PortabilityLayer
{
void InstallHostSuspendHook(HostSuspendHook_t hook, void *context)
{
gs_suspendHook = hook;
gs_suspendContext = context;
}
void SuspendApplication(HostSuspendCallID callID, const HostSuspendCallArgument *args, HostSuspendCallArgument *returnValue)
{
gs_suspendHook(gs_suspendContext, callID, args, returnValue);
}
}

View File

@@ -0,0 +1,17 @@
#pragma once
#ifndef __PL_HOST_API_HOOK_H__
#define __PL_HOST_API_HOOK_H__
#include "HostSuspendCallID.h"
namespace PortabilityLayer
{
union HostSuspendCallArgument;
typedef void(*HostSuspendHook_t)(void *context, HostSuspendCallID callID, const HostSuspendCallArgument *args, HostSuspendCallArgument *returnValue);
void InstallHostSuspendHook(HostSuspendHook_t hook, void *context);
void SuspendApplication(HostSuspendCallID callID, const HostSuspendCallArgument *args, HostSuspendCallArgument *returnValue);
}
#endif

View File

@@ -0,0 +1,16 @@
#include "HostSystemServices.h"
namespace PortabilityLayer
{
void HostSystemServices::SetInstance(HostSystemServices *instance)
{
ms_instance = instance;
}
HostSystemServices *HostSystemServices::GetInstance()
{
return ms_instance;
}
HostSystemServices *HostSystemServices::ms_instance;
}

View File

@@ -0,0 +1,22 @@
#pragma once
#ifndef __PL_HOST_SYSTEM_SERVICES_H__
#define __PL_HOST_SYSTEM_SERVICES_H__
#include <stdint.h>
namespace PortabilityLayer
{
class HostSystemServices
{
public:
virtual uint32_t GetTime() const = 0;
static void SetInstance(HostSystemServices *instance);
static HostSystemServices *GetInstance();
private:
static HostSystemServices *ms_instance;
};
}
#endif

View File

@@ -0,0 +1,31 @@
#pragma once
#ifndef __PL_IOTREAM_H__
#define __PL_IOTREAM_H__
#include "DataTypes.h"
namespace PortabilityLayer
{
typedef int64_t FilePos_t;
typedef uint64_t UFilePos_t;
class IOStream
{
public:
virtual size_t Read(void *bytesOut, size_t size) = 0;
virtual size_t Write(const void *bytes, size_t size) = 0;
virtual bool IsSeekable() const = 0;
virtual bool IsReadOnly() const = 0;
virtual bool IsWriteOnly() const = 0;
virtual bool SeekStart(UFilePos_t loc) = 0;
virtual bool SeekCurrent(FilePos_t loc) = 0;
virtual bool SeekEnd(UFilePos_t loc) = 0;
virtual bool Truncate(UFilePos_t loc) = 0;
virtual UFilePos_t Size() const = 0;
virtual UFilePos_t Tell() const = 0;
virtual void Close() = 0;
};
}
#endif

View File

@@ -0,0 +1,12 @@
#include "MMBlock.h"
namespace PortabilityLayer
{
size_t MMBlock::AlignedSize()
{
const size_t paddedSize = sizeof(MMBlock) + PL_SYSTEM_MEMORY_ALIGNMENT - 1;
const size_t paddedSizeTruncated = paddedSize - (paddedSize % PL_SYSTEM_MEMORY_ALIGNMENT);
return paddedSizeTruncated;
}
}

View File

@@ -0,0 +1,20 @@
#pragma once
#ifndef __PL_MM_BLOCK_H__
#define __PL_MM_BLOCK_H__
#include <stdint.h>
#include "CoreDefs.h"
#include "SmallestInt.h"
namespace PortabilityLayer
{
struct MMBlock
{
SmallestUInt<PL_SYSTEM_MEMORY_ALIGNMENT>::ValueType_t m_offsetFromAllocLocation;
static size_t AlignedSize();
};
}
#endif

View File

@@ -0,0 +1,17 @@
#include "MMHandleBlock.h"
namespace PortabilityLayer
{
MMHandleBlock::MMHandleBlock(void *contents, size_t size)
: m_contents(contents)
, m_rmSelfRef(nullptr)
, m_size(size)
{
}
void **MMHandleBlock::AsHandle()
{
return &m_contents;
}
}

View File

@@ -0,0 +1,29 @@
#pragma once
#ifndef __PL_MM_HANDLE_BLOCK_H__
#define __PL_MM_HANDLE_BLOCK_H__
#include <stdint.h>
#include "CoreDefs.h"
namespace PortabilityLayer
{
struct ResourceCompiledRef;
struct MMHandleBlock
{
explicit MMHandleBlock(void *contents, size_t size);
void **AsHandle();
void *m_contents; // This must be the first field
ResourceCompiledRef *m_rmSelfRef;
size_t m_size;
private:
MMHandleBlock() PL_DELETED;
};
}
#endif

View File

@@ -0,0 +1,185 @@
#include "MacBinary2.h"
#include "BytePack.h"
#include "ByteUnpack.h"
#include "DataTypes.h"
#include "IOStream.h"
#include "MacFileMem.h"
#include "XModemCRC.h"
// See: https://files.stairways.com/other/macbinaryii-standard-info.txt
namespace
{
namespace MB2FileOffsets
{
const unsigned int Version = 0;
const unsigned int FileNameLength = 1;
const unsigned int FileName = 2;
const unsigned int FileType = 65;
const unsigned int FileCreator = 69;
const unsigned int FinderFlagsHigh = 73;
const unsigned int YPos = 75;
const unsigned int XPos = 77;
const unsigned int Protected = 81;
const unsigned int DataForkSize = 83;
const unsigned int ResourceForkSize = 87;
const unsigned int CreationDate = 91;
const unsigned int ModifiedDate = 95;
const unsigned int CommentLength = 99;
const unsigned int FinderFlagsLow = 101;
const unsigned int DecompressedSize = 116;
const unsigned int SecondaryHeaderLength = 120;
const unsigned int WriterVersion = 122;
const unsigned int MinVersion = 123;
const unsigned int Checksum = 124;
const unsigned int ContentStart = 128;
};
}
namespace PortabilityLayer
{
void MacBinary2::WriteBin(const MacFileMem *file, IOStream *stream)
{
const MacFileInfo &fileInfo = file->FileInfo();
uint8_t mb2Header[128];
memset(mb2Header, 0, sizeof(mb2Header));
mb2Header[MB2FileOffsets::Version] = 0;
size_t fileNameLength = fileInfo.m_fileName.Length();
if (fileNameLength == 0)
{
mb2Header[MB2FileOffsets::FileNameLength] = 1;
mb2Header[MB2FileOffsets::FileName] = '?';
}
else
{
if (fileNameLength > 63)
fileNameLength = 63;
mb2Header[MB2FileOffsets::FileNameLength] = static_cast<uint8_t>(fileNameLength);
memcpy(mb2Header + MB2FileOffsets::FileName, &fileInfo.m_fileName[0], fileNameLength);
}
memcpy(mb2Header + MB2FileOffsets::FileType, fileInfo.m_properties.m_fileType, 4);
memcpy(mb2Header + MB2FileOffsets::FileCreator, fileInfo.m_properties.m_fileCreator, 4);
mb2Header[MB2FileOffsets::FinderFlagsHigh] = static_cast<uint8_t>((fileInfo.m_properties.m_finderFlags >> 8) & 0xff);
BytePack::BigInt16(mb2Header + MB2FileOffsets::YPos, fileInfo.m_properties.m_yPos);
BytePack::BigInt16(mb2Header + MB2FileOffsets::XPos, fileInfo.m_properties.m_xPos);
mb2Header[MB2FileOffsets::Protected] = fileInfo.m_properties.m_protected;
BytePack::BigUInt32(mb2Header + MB2FileOffsets::DataForkSize, fileInfo.m_dataForkSize);
BytePack::BigUInt32(mb2Header + MB2FileOffsets::ResourceForkSize, fileInfo.m_resourceForkSize);
BytePack::BigUInt32(mb2Header + MB2FileOffsets::CreationDate, fileInfo.m_properties.m_creationDate);
BytePack::BigUInt32(mb2Header + MB2FileOffsets::ModifiedDate, fileInfo.m_properties.m_modifiedDate);
BytePack::BigUInt16(mb2Header + MB2FileOffsets::CommentLength, fileInfo.m_commentSize);
mb2Header[MB2FileOffsets::FinderFlagsLow] = static_cast<uint8_t>(fileInfo.m_properties.m_finderFlags & 0xff);
// DecompressedSize is unused
// SecondaryHeaderLength is zero
mb2Header[MB2FileOffsets::WriterVersion] = 129;
mb2Header[MB2FileOffsets::MinVersion] = 129;
BytePack::BigUInt16(mb2Header + MB2FileOffsets::Checksum, XModemCRC(mb2Header, 124, 0));
stream->Write(mb2Header, 128);
uint8_t *padding = mb2Header;
memset(padding, 0, 128);
const size_t dataForkPadding = 127 - ((fileInfo.m_dataForkSize + 127) % 128);
const size_t resourceForkPadding = 127 - ((fileInfo.m_resourceForkSize + 127) % 128);
stream->Write(file->DataFork(), fileInfo.m_dataForkSize);
stream->Write(padding, dataForkPadding);
stream->Write(file->ResourceFork(), fileInfo.m_resourceForkSize);
stream->Write(padding, resourceForkPadding);
}
MacFileMem *MacBinary2::ReadBin(IOStream *stream)
{
MacFileInfo fileInfo;
uint8_t mb2Header[128];
if (stream->Read(mb2Header, 128) != 128)
return nullptr;
if (mb2Header[MB2FileOffsets::Version] != 0)
return nullptr;
const uint8_t fileNameLength = mb2Header[MB2FileOffsets::FileNameLength];
if (fileNameLength < 1 || fileNameLength > 63)
return nullptr;
fileInfo.m_fileName.Set(fileNameLength, reinterpret_cast<const char*>(mb2Header + MB2FileOffsets::FileName));
memcpy(fileInfo.m_properties.m_fileType, mb2Header + MB2FileOffsets::FileType, 4);
memcpy(fileInfo.m_properties.m_fileCreator, mb2Header + MB2FileOffsets::FileCreator, 4);
fileInfo.m_properties.m_finderFlags = mb2Header[MB2FileOffsets::FinderFlagsHigh] << 8;
fileInfo.m_properties.m_yPos = ByteUnpack::BigInt16(mb2Header + MB2FileOffsets::YPos);
fileInfo.m_properties.m_xPos = ByteUnpack::BigInt16(mb2Header + MB2FileOffsets::XPos);
fileInfo.m_properties.m_protected = mb2Header[MB2FileOffsets::Protected];
fileInfo.m_dataForkSize = ByteUnpack::BigUInt32(mb2Header + MB2FileOffsets::DataForkSize);
fileInfo.m_resourceForkSize = ByteUnpack::BigUInt32(mb2Header + MB2FileOffsets::ResourceForkSize);
fileInfo.m_properties.m_creationDate = ByteUnpack::BigUInt32(mb2Header + MB2FileOffsets::CreationDate);
fileInfo.m_properties.m_modifiedDate = ByteUnpack::BigUInt32(mb2Header + MB2FileOffsets::ModifiedDate);
fileInfo.m_commentSize = ByteUnpack::BigUInt16(mb2Header + MB2FileOffsets::CommentLength);
fileInfo.m_properties.m_finderFlags |= mb2Header[MB2FileOffsets::FinderFlagsLow];
if (ByteUnpack::BigInt16(mb2Header + MB2FileOffsets::SecondaryHeaderLength) != 0)
return nullptr;
uint16_t crc = ByteUnpack::BigUInt16(mb2Header + MB2FileOffsets::Checksum);
uint16_t expectedCRC = XModemCRC(mb2Header, 124, 0);
if (fileInfo.m_dataForkSize > SIZE_MAX)
return nullptr;
if (fileInfo.m_resourceForkSize > SIZE_MAX)
return nullptr;
uint8_t *dataBuffer = nullptr;
uint8_t *rsrcBuffer = nullptr;
if (fileInfo.m_dataForkSize != 0)
dataBuffer = new uint8_t[fileInfo.m_dataForkSize];
if (fileInfo.m_resourceForkSize != 0)
rsrcBuffer = new uint8_t[fileInfo.m_resourceForkSize];
ScopedArray<uint8_t> dataContents = dataBuffer;
ScopedArray<uint8_t> rsrcContents = rsrcBuffer;
uint8_t *padding = mb2Header;
const size_t dataForkPadding = 127 - ((fileInfo.m_dataForkSize + 127) % 128);
const size_t resourceForkPadding = 127 - ((fileInfo.m_resourceForkSize + 127) % 128);
if (stream->Read(dataBuffer, fileInfo.m_dataForkSize) != fileInfo.m_dataForkSize)
return nullptr;
if (stream->Read(padding, dataForkPadding) != dataForkPadding)
return nullptr;
if (stream->Read(rsrcBuffer, fileInfo.m_resourceForkSize) != fileInfo.m_resourceForkSize)
return nullptr;
if (stream->Read(padding, resourceForkPadding) != resourceForkPadding)
return nullptr;
// Ignore comment for now
return new MacFileMem(dataBuffer, rsrcBuffer, nullptr, fileInfo);
}
}

View File

@@ -0,0 +1,18 @@
#pragma once
#ifndef __PL_MACBINARY2_H__
#define __PL_MACBINARY2_H__
namespace PortabilityLayer
{
class IOStream;
class MacFileMem;
namespace MacBinary2
{
void WriteBin(const MacFileMem *file, IOStream *stream);
MacFileMem *ReadBin(IOStream *stream);
};
}
#endif

View File

@@ -0,0 +1,63 @@
#include "MacFileInfo.h"
#include "PLBigEndian.h"
#include <string.h>
namespace PortabilityLayer
{
static const unsigned int kOffsetFileType = 0;
static const unsigned int kOffsetFileCreator = 4;
static const unsigned int kOffsetXPos = 8;
static const unsigned int kOffsetYPos = 10;
static const unsigned int kOffsetFinderFlags = 12;
static const unsigned int kProtected = 14;
static const unsigned int kCreationDate = 15;
static const unsigned int kModifiedDate = 19;
static const unsigned int kSize = 23;
uint8_t m_data[kSize];
void MacFilePropertiesSerialized::Deserialize(MacFileProperties &props) const
{
memcpy(props.m_fileType, m_data + kOffsetFileType, 4);
memcpy(props.m_fileCreator, m_data + kOffsetFileCreator, 4);
memcpy(&props.m_xPos, m_data + kOffsetXPos, 2);
memcpy(&props.m_yPos, m_data + kOffsetYPos, 2);
memcpy(&props.m_finderFlags, m_data + kOffsetFinderFlags, 2);
memcpy(&props.m_protected, m_data + kProtected, 1);
memcpy(&props.m_creationDate, m_data + kCreationDate, 4);
memcpy(&props.m_modifiedDate, m_data + kModifiedDate, 4);
PortabilityLayer::ByteSwap::BigInt16(props.m_xPos);
PortabilityLayer::ByteSwap::BigInt16(props.m_yPos);
PortabilityLayer::ByteSwap::BigUInt16(props.m_finderFlags);
PortabilityLayer::ByteSwap::BigUInt32(props.m_creationDate);
PortabilityLayer::ByteSwap::BigUInt32(props.m_modifiedDate);
}
void MacFilePropertiesSerialized::Serialize(const MacFileProperties &props)
{
int16_t xPos = props.m_xPos;
int16_t yPos = props.m_yPos;
uint16_t finderFlags = props.m_finderFlags;
uint32_t creationDate = props.m_creationDate;
uint32_t modifiedDate = props.m_modifiedDate;
PortabilityLayer::ByteSwap::BigInt16(xPos);
PortabilityLayer::ByteSwap::BigInt16(yPos);
PortabilityLayer::ByteSwap::BigUInt16(finderFlags);
PortabilityLayer::ByteSwap::BigUInt32(creationDate);
PortabilityLayer::ByteSwap::BigUInt32(modifiedDate);
memcpy(m_data + kOffsetFileType, props.m_fileType, 4);
memcpy(m_data + kOffsetFileCreator, props.m_fileCreator, 4);
memcpy(m_data + kOffsetXPos, &xPos, 2);
memcpy(m_data + kOffsetYPos, &yPos, 2);
memcpy(m_data + kOffsetFinderFlags, &finderFlags, 2);
memcpy(m_data + kProtected, &props.m_protected, 1);
memcpy(m_data + kCreationDate, &creationDate, 4);
memcpy(m_data + kModifiedDate, &modifiedDate, 4);
}
}

View File

@@ -0,0 +1,89 @@
#pragma once
#include "DataTypes.h"
#include "PascalStr.h"
namespace PortabilityLayer
{
enum FinderFileFlags
{
FINDER_FILE_FLAG_LOCKED = (1 << 15),
FINDER_FILE_FLAG_INVISIBLE = (1 << 14),
FINDER_FILE_FLAG_BUNDLE = (1 << 13),
FINDER_FILE_FLAG_SYSTEM = (1 << 12),
FINDER_FILE_FLAG_COPY_PROTECTED = (1 << 11),
FINDER_FILE_FLAG_BUSY = (1 << 10),
FINDER_FILE_FLAG_CHANGED = (1 << 9),
FINDER_FILE_FLAG_INITED = (1 << 8),
};
struct MacFileProperties
{
MacFileProperties();
char m_fileType[4];
char m_fileCreator[4];
int16_t m_xPos;
int16_t m_yPos;
uint16_t m_finderFlags;
uint8_t m_protected;
uint32_t m_creationDate;
uint32_t m_modifiedDate;
void Serialize(void *buffer);
void Deserialize(const void *buffer);
};
struct MacFilePropertiesSerialized
{
static const unsigned int kOffsetFileType = 0;
static const unsigned int kOffsetFileCreator = 4;
static const unsigned int kOffsetXPos = 8;
static const unsigned int kOffsetYPos = 10;
static const unsigned int kOffsetFinderFlags = 12;
static const unsigned int kProtected = 14;
static const unsigned int kCreationDate = 15;
static const unsigned int kModifiedDate = 19;
static const unsigned int kSize = 23;
uint8_t m_data[kSize];
void Deserialize(MacFileProperties &props) const;
void Serialize(const MacFileProperties &props);
};
struct MacFileInfo
{
MacFileInfo();
PascalStr<64> m_fileName;
uint16_t m_commentSize;
uint32_t m_dataForkSize;
uint32_t m_resourceForkSize;
MacFileProperties m_properties;
};
}
namespace PortabilityLayer
{
inline MacFileProperties::MacFileProperties()
: m_xPos(0)
, m_yPos(0)
, m_finderFlags(0)
, m_protected(0)
, m_creationDate(0)
, m_modifiedDate(0)
{
m_fileType[0] = m_fileType[1] = m_fileType[2] = m_fileType[3] = '\0';
m_fileCreator[0] = m_fileCreator[1] = m_fileCreator[2] = m_fileCreator[3] = '\0';
}
inline MacFileInfo::MacFileInfo()
: m_dataForkSize(0)
, m_resourceForkSize(0)
, m_commentSize(0)
{
}
}

View File

@@ -0,0 +1,26 @@
#include "MacFileMem.h"
namespace PortabilityLayer
{
MacFileMem::MacFileMem(const uint8_t *dataFork, const uint8_t *resourceFork, const char* comment, const MacFileInfo &fileInfo)
: m_info(fileInfo)
{
uint8_t *buffer = new uint8_t[fileInfo.m_dataForkSize + fileInfo.m_resourceForkSize + fileInfo.m_commentSize + 1];
m_data.Set(buffer);
memcpy(buffer, dataFork, fileInfo.m_dataForkSize);
buffer += fileInfo.m_dataForkSize;
memcpy(buffer, resourceFork, fileInfo.m_resourceForkSize);
buffer += fileInfo.m_resourceForkSize;
memcpy(buffer, comment, fileInfo.m_commentSize);
buffer += fileInfo.m_commentSize;
*buffer = 0;
}
MacFileMem::~MacFileMem()
{
}
}

View File

@@ -0,0 +1,52 @@
#pragma once
#ifndef __PL_MACFILEMEM_H__
#define __PL_MACFILEMEM_H__
#include "DataTypes.h"
#include "MacFileInfo.h"
#include "ScopedArray.h"
namespace PortabilityLayer
{
class MacFileMem
{
public:
MacFileMem(const uint8_t *dataFork, const uint8_t *resourceFork, const char* comment, const MacFileInfo &fileInfo);
~MacFileMem();
const MacFileInfo &FileInfo() const;
const uint8_t *DataFork() const;
const uint8_t *ResourceFork() const;
const char *Comment() const;
private:
ScopedArray<uint8_t> m_data;
MacFileInfo m_info;
};
}
namespace PortabilityLayer
{
inline const MacFileInfo &MacFileMem::FileInfo() const
{
return m_info;
}
inline const uint8_t *MacFileMem::DataFork() const
{
return m_data;
}
inline const uint8_t *MacFileMem::ResourceFork() const
{
return m_data + m_info.m_dataForkSize;
}
inline const char *MacFileMem::Comment() const
{
return reinterpret_cast<const char*>(m_data + m_info.m_dataForkSize + m_info.m_resourceForkSize);
}
}
#endif

View File

@@ -0,0 +1,14 @@
#pragma once
#ifndef __PL_MAC_FILE_WRITEABLE_MEM_H__
#define __PL_MAC_FILE_WRITEABLE_MEM_H__
namespace PortabilityLayer
{
class MacFileWriteableMem
{
public:
private:
};
}
#endif

View File

@@ -0,0 +1,21 @@
#pragma once
#ifndef __PL_MACRSRCHEADER_H__
#define __PL_MACRSRCHEADER_H__
#include "DataTypes.h"
namespace PortabilityLayer
{
struct MacRsrcHeader
{
uint32_t m_resDataOffset;
uint32_t m_resMapOffset;
uint32_t m_resDataSize;
uint32_t m_resMapSize;
void Load(const void *data);
};
}
#endif

View File

@@ -0,0 +1,20 @@
#pragma once
#ifndef __PL_MACRSRCMAP_H__
#define __PL_MACRSRCMAP_H__
#include "DataTypes.h"
namespace PortabilityLayer
{
struct MacRsrcMap
{
uint16_t m_resTypeListOffset;
uint16_t m_resNameListOffset;
uint16_t m_numTypesMinusOne;
void Load(const void *data);
};
}
#endif

View File

@@ -0,0 +1,110 @@
#include "MemReaderStream.h"
#include <string.h>
namespace PortabilityLayer
{
MemReaderStream::MemReaderStream(const void *memStream, size_t size)
: m_bytes(static_cast<const uint8_t*>(memStream))
, m_size(size)
, m_loc(0)
{
}
size_t MemReaderStream::Read(void *bytesOut, size_t size)
{
size_t available = m_size - m_loc;
if (size > available)
size = available;
memcpy(bytesOut, m_bytes + m_loc, size);
m_loc += size;
return size;
}
size_t MemReaderStream::Write(const void *bytes, size_t size)
{
return 0;
}
bool IsSeekable()
{
return true;
}
bool MemReaderStream::IsSeekable() const
{
return true;
}
bool MemReaderStream::IsReadOnly() const
{
return true;
}
bool MemReaderStream::IsWriteOnly() const
{
return false;
}
bool MemReaderStream::SeekStart(UFilePos_t loc)
{
if (loc > m_size)
m_loc = m_size;
else
m_loc = static_cast<size_t>(loc);
return true;
}
bool MemReaderStream::SeekCurrent(FilePos_t loc)
{
if (loc < 0)
{
if (static_cast<FilePos_t>(m_loc) + loc < 0)
m_loc = 0;
else
m_loc = static_cast<size_t>(static_cast<FilePos_t>(m_loc) + loc);
}
else
{
const size_t available = m_size - m_loc;
if (static_cast<UFilePos_t>(loc) > available)
m_loc = m_size;
else
m_loc = static_cast<size_t>(static_cast<FilePos_t>(m_loc) + loc);
}
return true;
}
bool MemReaderStream::SeekEnd(UFilePos_t loc)
{
if (m_size < loc)
m_loc = 0;
else
m_loc = m_size - static_cast<size_t>(loc);
return true;
}
bool MemReaderStream::Truncate(UFilePos_t loc)
{
return false;
}
UFilePos_t MemReaderStream::Size() const
{
return m_size;
}
UFilePos_t MemReaderStream::Tell() const
{
return static_cast<UFilePos_t>(m_loc);
}
void MemReaderStream::Close()
{
}
}

View File

@@ -0,0 +1,37 @@
#pragma once
#ifndef __PL_MEM_READER_STREAM_H__
#define __PL_MEM_READER_STREAM_H__
#include "CoreDefs.h"
#include "IOStream.h"
namespace PortabilityLayer
{
class MemReaderStream final : public IOStream
{
public:
MemReaderStream(const void *memStream, size_t size);
size_t Read(void *bytesOut, size_t size) override;
size_t Write(const void *bytes, size_t size) override;
bool IsSeekable() const override;
bool IsReadOnly() const override;
bool IsWriteOnly() const override;
bool SeekStart(UFilePos_t loc) override;
bool SeekCurrent(FilePos_t loc) override;
bool SeekEnd(UFilePos_t loc) override;
bool Truncate(UFilePos_t loc) override;
UFilePos_t Size() const override;
UFilePos_t Tell() const override;
void Close() override;
private:
MemReaderStream() PL_DELETED;
const uint8_t *m_bytes;
size_t m_size;
size_t m_loc;
};
}
#endif

View File

@@ -0,0 +1,106 @@
#include "MemoryManager.h"
#include "MMBlock.h"
#include "MMHandleBlock.h"
#include "ResourceCompiledRef.h"
#include <stdlib.h>
#include <new>
namespace PortabilityLayer
{
class MemoryManagerImpl final : public MemoryManager
{
public:
void Init() override;
void Shutdown() override;
void *Alloc(size_t size) override;
void Release(void *buf) override;
MMHandleBlock *AllocHandle(size_t size) override;
void ReleaseHandle(MMHandleBlock *hdl) override;
static MemoryManagerImpl *GetInstance();
private:
static MemoryManagerImpl ms_instance;
};
void MemoryManagerImpl::Init()
{
}
void MemoryManagerImpl::Shutdown()
{
}
void *MemoryManagerImpl::Alloc(size_t size)
{
if (size == 0)
return nullptr;
const size_t mmBlockSizeWithMaxPadding = MMBlock::AlignedSize() + PL_SYSTEM_MEMORY_ALIGNMENT - 1;
if (SIZE_MAX - size < mmBlockSizeWithMaxPadding)
return nullptr;
uint8_t *buffer = static_cast<uint8_t*>(malloc(size + mmBlockSizeWithMaxPadding));
if (!buffer)
return nullptr;
const intptr_t offsetFromAlignPoint = reinterpret_cast<intptr_t>(buffer) & static_cast<intptr_t>(PL_SYSTEM_MEMORY_ALIGNMENT - 1);
intptr_t alignPadding = 0;
if (offsetFromAlignPoint != 0)
alignPadding = static_cast<intptr_t>(PL_SYSTEM_MEMORY_ALIGNMENT) - offsetFromAlignPoint;
MMBlock *mmBlock = reinterpret_cast<MMBlock*>(buffer + alignPadding);
mmBlock->m_offsetFromAllocLocation = static_cast<SmallestUInt<PL_SYSTEM_MEMORY_ALIGNMENT>::ValueType_t>(alignPadding);
return buffer + alignPadding + MMBlock::AlignedSize();
}
void MemoryManagerImpl::Release(void *buf)
{
if (!buf)
return;
const size_t mmBlockSize = MMBlock::AlignedSize();
uint8_t *bytes = static_cast<uint8_t*>(buf);
const MMBlock *mmBlock = reinterpret_cast<const MMBlock*>(bytes - MMBlock::AlignedSize());
free(bytes - MMBlock::AlignedSize() - mmBlock->m_offsetFromAllocLocation);
}
MMHandleBlock *MemoryManagerImpl::AllocHandle(size_t size)
{
void *contents = Alloc(size);
MMHandleBlock *handleBlock = static_cast<MMHandleBlock*>(Alloc(sizeof(MMHandleBlock)));
return new (handleBlock) MMHandleBlock(contents, size);
}
void MemoryManagerImpl::ReleaseHandle(MMHandleBlock *hdl)
{
if (!hdl)
return;
if (hdl->m_rmSelfRef != nullptr)
hdl->m_rmSelfRef->m_handle = nullptr;
hdl->~MMHandleBlock();
Release(hdl);
}
MemoryManagerImpl *MemoryManagerImpl::GetInstance()
{
return &ms_instance;
}
MemoryManagerImpl MemoryManagerImpl::ms_instance;
MemoryManager *MemoryManager::GetInstance()
{
return MemoryManagerImpl::GetInstance();
}
}

View File

@@ -0,0 +1,51 @@
#pragma once
#ifndef __PL_MEMORY_MANAGER_H__
#define __PL_MEMORY_MANAGER_H__
#include <stdint.h>
namespace PortabilityLayer
{
struct MMHandleBlock;
class MemoryManager
{
public:
virtual void Init() = 0;
virtual void Shutdown() = 0;
virtual void *Alloc(size_t size) = 0;
virtual void Release(void *buf) = 0;
virtual MMHandleBlock *AllocHandle(size_t size) = 0;
virtual void ReleaseHandle(MMHandleBlock *hdl) = 0;
template<class T>
T **NewHandle();
static MemoryManager *GetInstance();
};
}
#include <new>
#include "CoreDefs.h"
#include "MMHandleBlock.h"
namespace PortabilityLayer
{
template<class T>
T **MemoryManager::NewHandle()
{
MMHandleBlock *hdl = this->AllocHandle(sizeof(T));
if (!hdl)
return nullptr;
T **objectHdl = reinterpret_cast<T**>(hdl);
T *objectPtr = *objectHdl;
new (objectPtr) T();
return objectHdl;
}
}
#endif

View File

@@ -0,0 +1,7 @@
#include "PLAliases.h"
OSErr ResolveAliasFile(FSSpecPtr fsSpec, Boolean recursive, Boolean *outIsFolder, Boolean *outWasAliased)
{
PL_NotYetImplemented();
return noErr;
}

View File

@@ -0,0 +1,9 @@
#pragma once
#ifndef __PL_ALIASES_H__
#define __PL_ALIASES_H__
#include "PLCore.h"
OSErr ResolveAliasFile(FSSpecPtr fsSpec, Boolean recursive, Boolean *outIsFolder, Boolean *outWasAliased);
#endif

View File

@@ -0,0 +1,49 @@
#include "PLAppleEvents.h"
#include "AEManager.h"
OSErr AEGetParamDesc(const AppleEvent *evt, AEKeyword keyword, DescType desiredType, AEDescList *descList)
{
PL_NotYetImplemented();
return noErr;
}
OSErr AEDisposeDesc(AEDescList *descList)
{
PL_NotYetImplemented();
return noErr;
}
OSErr AECountItems(AEDescList *descList, long *count)
{
PL_NotYetImplemented();
return noErr;
}
OSErr AEGetNthPtr(AEDescList *descList, long index, DescType desiredType, AEKeyword *keyword, DescType *type, void *data, Size maxSize, Size *actualSize)
{
PL_NotYetImplemented();
return noErr;
}
OSErr AEGetAttributePtr(const AppleEvent *evt, AEKeyword keyword, DescType desiredType, DescType *type, void *data, Size maxSize, Size *actualSize)
{
PL_NotYetImplemented();
return noErr;
}
OSErr AEInstallEventHandler(AEEventClass eventClass, AEEventID eventID, AEEventHandlerUPP handler, UInt32 ref, bool isSysHandler)
{
PortabilityLayer::AEManager::GetInstance()->InstallEventHandler(eventClass, eventID, handler, ref, isSysHandler);
return noErr;
}
OSErr AESetInteractionAllowed(AEInteractAllowed level)
{
PortabilityLayer::AEManager::GetInstance()->SetInteractAllowed(level);
return noErr;
}
AEEventHandlerUPP NewAEEventHandlerProc(AEEventHandler handler)
{
return handler;
}

View File

@@ -0,0 +1,32 @@
#pragma once
#ifndef __PL_APPLEEVENTS_H__
#define __PL_APPLEEVENTS_H__
#include "PLCore.h"
#include "PLAppleEventsCommonTypes.h"
struct AppleEvent
{
};
struct AEDescList
{
};
struct AEDesc
{
};
typedef AEEventHandler AEEventHandlerUPP;
OSErr AEGetParamDesc(const AppleEvent *evt, AEKeyword keyword, DescType desiredType, AEDescList *descList);
OSErr AEDisposeDesc(AEDescList *descList);
OSErr AECountItems(AEDescList *descList, long *count);
OSErr AEGetNthPtr(AEDescList *descList, long index, DescType desiredType, AEKeyword *keyword, DescType *type, void *data, Size maxSize, Size *actualSize);
OSErr AEGetAttributePtr(const AppleEvent *evt, AEKeyword keyword, DescType desiredType, DescType *type, void *data, Size maxSize, Size *actualSize);
OSErr AEInstallEventHandler(AEEventClass eventClass, AEEventID eventID, AEEventHandlerUPP handler, UInt32 ref, bool isSysHandler);
OSErr AESetInteractionAllowed(AEInteractAllowed level);
AEEventHandlerUPP NewAEEventHandlerProc(AEEventHandler handler);
#endif

View File

@@ -0,0 +1,50 @@
#pragma once
#ifndef __PL_APPLE_EVENTS_COMMON_TYPES_H__
#define __PL_APPLE_EVENTS_COMMON_TYPES_H__
#include <stdint.h>
struct AppleEvent;
enum AEError
{
errAEEventNotHandled = 1,
errAEDescNotFound,
errAEParamMissed,
};
enum AEKeyword
{
keyDirectObject,
keyMissedKeywordAttr,
};
enum DescType
{
typeAEList,
typeFSS,
typeWildCard,
};
enum AEEventID
{
kAEOpenApplication,
kAEOpenDocuments,
kAEPrintDocuments,
kAEQuitApplication
};
enum AEEventClass
{
kCoreEventClass
};
enum AEInteractAllowed
{
kAEInteractUnknown,
kAEInteractWithAll
};
typedef int(*AEEventHandler)(const AppleEvent *theAE, AppleEvent *reply, uint32_t ref);
#endif

View File

@@ -0,0 +1,23 @@
#include "PLApplication.h"
#include "PLCore.h"
#include <string.h>
#include <assert.h>
namespace PortabilityLayer
{
namespace Utils
{
void MakePStr(unsigned char *dest, size_t sz, const char *src)
{
assert(sz <= 255);
dest[0] = static_cast<uint8_t>(sz);
memcpy(dest + 1, src, sz);
}
}
}
void SysBeep(int duration)
{
PL_NotYetImplemented();
}

View File

@@ -0,0 +1,37 @@
#pragma once
#ifndef __PL_APPLICATION_H__
#define __PL_APPLICATION_H__
#include "PLCore.h"
namespace PortabilityLayer
{
template<size_t TSize>
class PascalStrLiteral;
}
namespace PortabilityLayer
{
namespace Utils
{
void MakePStr(unsigned char *dest, size_t sz, const char *src);
}
}
void PasStringCopy(const unsigned char *src, unsigned char *dest);
template<size_t TSize>
void PasStringCopy(const PortabilityLayer::PascalStrLiteral<TSize> &src, unsigned char *dest);
void SysBeep(int duration);
///////////////////////////////////////////////////////////////////////////////
#include "PascalStrLiteral.h"
template<size_t TSize>
inline void PasStringCopy(const PortabilityLayer::PascalStrLiteral<TSize> &src, unsigned char *dest)
{
PortabilityLayer::Utils::MakePStr(dest, TSize - 1, src.GetStr());
}
#endif

View File

@@ -0,0 +1,212 @@
#pragma once
#ifndef __PL_BIG_ENDIAN_H__
#define __PL_BIG_ENDIAN_H__
#include <stdint.h>
template<class T>
struct BEInteger
{
public:
BEInteger();
BEInteger(const BEInteger<T> &other);
explicit BEInteger(T i);
operator T() const;
BEInteger<T> &operator=(T value);
template<class TOther>
BEInteger<T> &operator+=(TOther value);
template<class TOther>
BEInteger<T> &operator-=(TOther value);
template<class TOther>
BEInteger<T> &operator*=(TOther value);
template<class TOther>
BEInteger<T> &operator/=(TOther value);
template<class TOther>
BEInteger<T> &operator%=(TOther value);
BEInteger<T>& operator--();
BEInteger<T> operator--(int);
BEInteger<T>& operator++();
BEInteger<T> operator++(int);
private:
T m_beValue;
};
template<class T>
struct BEInteger_SwapHelper
{
};
#include "ByteSwap.h"
template<>
struct BEInteger_SwapHelper<int16_t>
{
inline static void Swap(int16_t &v)
{
PortabilityLayer::ByteSwap::BigInt16(v);
}
};
template<>
struct BEInteger_SwapHelper<int32_t>
{
inline static void Swap(int32_t &v)
{
PortabilityLayer::ByteSwap::BigInt32(v);
}
};
template<>
struct BEInteger_SwapHelper<uint16_t>
{
inline static void Swap(uint16_t &v)
{
PortabilityLayer::ByteSwap::BigUInt16(v);
}
};
template<>
struct BEInteger_SwapHelper<uint32_t>
{
inline static void Swap(uint32_t &v)
{
PortabilityLayer::ByteSwap::BigUInt32(v);
}
};
// Int16
template<class T>
inline BEInteger<T>::BEInteger()
: m_beValue(0)
{
}
template<class T>
inline BEInteger<T>::BEInteger(const BEInteger<T> &other)
: m_beValue(other.m_beValue)
{
}
template<class T>
inline BEInteger<T>::BEInteger(T i)
: m_beValue(i)
{
BEInteger_SwapHelper<T>::Swap(m_beValue);
}
template<class T>
inline BEInteger<T>::operator T() const
{
int16_t result = m_beValue;
BEInteger_SwapHelper<T>::Swap(result);
return result;
}
template<class T>
inline BEInteger<T> &BEInteger<T>::operator=(T value)
{
BEInteger_SwapHelper<T>::Swap(value);
m_beValue = value;
return *this;
}
template<class T>
template<class TOther>
BEInteger<T> &BEInteger<T>::operator+=(TOther value)
{
BEInteger_SwapHelper<T>::Swap(m_beValue);
m_beValue += value;
BEInteger_SwapHelper<T>::Swap(m_beValue);
return *this;
}
template<class T>
template<class TOther>
BEInteger<T> &BEInteger<T>::operator-=(TOther value)
{
BEInteger_SwapHelper<T>::Swap(m_beValue);
m_beValue -= value;
BEInteger_SwapHelper<T>::Swap(m_beValue);
return *this;
}
template<class T>
template<class TOther>
BEInteger<T> &BEInteger<T>::operator*=(TOther value)
{
BEInteger_SwapHelper<T>::Swap(m_beValue);
m_beValue *= value;
BEInteger_SwapHelper<T>::Swap(m_beValue);
return *this;
}
template<class T>
template<class TOther>
BEInteger<T> &BEInteger<T>::operator/=(TOther value)
{
BEInteger_SwapHelper<T>::Swap(m_beValue);
m_beValue /= value;
BEInteger_SwapHelper<T>::Swap(m_beValue);
return *this;
}
template<class T>
template<class TOther>
BEInteger<T> &BEInteger<T>::operator%=(TOther value)
{
BEInteger_SwapHelper<T>::Swap(m_beValue);
m_beValue %= value;
BEInteger_SwapHelper<T>::Swap(m_beValue);
return *this;
}
template<class T>
BEInteger<T>& BEInteger<T>::operator--()
{
BEInteger_SwapHelper<T>::Swap(m_beValue);
m_beValue--;
BEInteger_SwapHelper<T>::Swap(m_beValue);
return *this;
}
template<class T>
BEInteger<T> BEInteger<T>::operator--(int)
{
BEInteger<T> orig(*this);
--(*this);
return orig;
}
template<class T>
BEInteger<T>& BEInteger<T>::operator++()
{
BEInteger_SwapHelper<T>::Swap(m_beValue);
m_beValue++;
BEInteger_SwapHelper<T>::Swap(m_beValue);
return *this;
}
template<class T>
BEInteger<T> BEInteger<T>::operator++(int)
{
BEInteger<T> orig(*this);
++(*this);
return orig;
}
typedef BEInteger<int16_t> BEInt16_t;
typedef BEInteger<int32_t> BEInt32_t;
typedef BEInteger<uint16_t> BEUInt16_t;
typedef BEInteger<uint32_t> BEUInt32_t;
#endif

View File

@@ -0,0 +1,72 @@
#include "PLControlDefinitions.h"
int FindControl(Point point, WindowPtr window, ControlHandle *outControl)
{
PL_NotYetImplemented();
return 0;
}
void SetControlValue(ControlHandle control, int value)
{
PL_NotYetImplemented();
}
void SetControlMaximum(ControlHandle control, int value)
{
PL_NotYetImplemented();
}
void MoveControl(ControlHandle control, int x, int y)
{
PL_NotYetImplemented();
}
void SizeControl(ControlHandle control, int width, int height)
{
PL_NotYetImplemented();
}
int GetControlValue(ControlHandle control)
{
PL_NotYetImplemented();
return 0;
}
ControlHandle NewControl(WindowPtr window, const Rect *rect, const PLPasStr &label, Boolean visible, int value, int minValue, int maxValue, int cdef, long userdata)
{
PL_NotYetImplemented();
return nullptr;
}
ControlActionUPP NewControlActionUPP(ControlActionProc proc)
{
return proc;
}
void DisposeControlActionUPP(ControlActionUPP upp)
{
}
Boolean TrackControl(ControlHandle control, Point point, ControlActionUPP proc)
{
PL_NotYetImplemented();
return false;
}
long GetControlReference(ControlHandle control)
{
PL_NotYetImplemented();
return 0;
}
ControlHandle GetNewControl(int resID, WindowPtr window)
{
PL_NotYetImplemented();
return nullptr;
}
void HiliteControl(ControlHandle control, int unknown)
{
PL_NotYetImplemented();
}

View File

@@ -0,0 +1,49 @@
#pragma once
#ifndef __PL_CONTROLDEFINITIONS_H__
#define __PL_CONTROLDEFINITIONS_H__
#include "PLCore.h"
struct Control
{
};
typedef Control *ControlPtr;
typedef ControlPtr *ControlHandle;
typedef void(*ControlActionProc)(ControlHandle control, short part);
typedef ControlActionProc ControlActionUPP;
enum BuiltinCDEFs
{
scrollBarProc = 16,
};
enum ControlParts
{
kControlUpButtonPart = 1,
kControlDownButtonPart,
kControlPageUpPart,
kControlPageDownPart,
kControlIndicatorPart,
kControlButtonPart,
};
int FindControl(Point point, WindowPtr window, ControlHandle *outControl); // Returns part
void SetControlValue(ControlHandle control, int value);
void SetControlMaximum(ControlHandle control, int value);
void MoveControl(ControlHandle control, int x, int y);
void SizeControl(ControlHandle control, int width, int height);
int GetControlValue(ControlHandle control);
ControlHandle NewControl(WindowPtr window, const Rect *rect, const PLPasStr &label, Boolean visible, int value, int minValue, int maxValue, int cdef, long userdata);
ControlActionUPP NewControlActionUPP(ControlActionProc proc);
void DisposeControlActionUPP(ControlActionUPP upp);
Boolean TrackControl(ControlHandle control, Point point, ControlActionUPP proc);
long GetControlReference(ControlHandle control); // Returns userdata
ControlHandle GetNewControl(int resID, WindowPtr window);
void HiliteControl(ControlHandle control, int unknown);
#endif

614
PortabilityLayer/PLCore.cpp Normal file
View File

@@ -0,0 +1,614 @@
#include "PLCore.h"
#include "PLApplication.h"
#include "PLPasStr.h"
#include "AEManager.h"
#include "DisplayDeviceManager.h"
#include "FileManager.h"
#include "FilePermission.h"
#include "HostSuspendCallArgument.h"
#include "HostSuspendHook.h"
#include "HostDisplayDriver.h"
#include "HostSystemServices.h"
#include "ResourceManager.h"
#include "MemoryManager.h"
#include "MMHandleBlock.h"
#include "ResTypeID.h"
#include "RandomNumberGenerator.h"
#include <assert.h>
void InitCursor()
{
}
OSErr FSClose(short fsRef)
{
PL_NotYetImplemented();
return noErr;
}
CursHandle GetCursor(int cursorID)
{
return reinterpret_cast<CursHandle>(GetResource('CURS', cursorID));
}
CCrsrHandle GetCCursor(int cursorID)
{
PortabilityLayer::ResourceManager *resManager = PortabilityLayer::ResourceManager::GetInstance();
PortabilityLayer::MMHandleBlock *ccRes = resManager->GetResource('crsr', cursorID);
if (!ccRes)
return nullptr;
PortabilityLayer::MMHandleBlock *copy = PortabilityLayer::MemoryManager::GetInstance()->AllocHandle(ccRes->m_size);
memcpy(copy->m_contents, ccRes->m_contents, ccRes->m_size);
return reinterpret_cast<CCrsrHandle>(copy);
}
void SetCCursor(CCrsrHandle handle)
{
PL_NotYetImplemented_Minor();
}
void HideCursor()
{
PortabilityLayer::HostDisplayDriver::GetInstance()->HideCursor();
}
void SetCursor(CursPtr cursor)
{
PL_NotYetImplemented();
}
void DisposeCCursor(CCrsrHandle handle)
{
PL_NotYetImplemented();
}
void Delay(int ticks, UInt32 *endTickCount)
{
if (ticks > 0)
{
PortabilityLayer::HostSuspendCallArgument args[1];
args[0].m_uint = static_cast<uint32_t>(ticks);
PortabilityLayer::SuspendApplication(PortabilityLayer::HostSuspendCallID_Delay, args, nullptr);
}
if (endTickCount)
*endTickCount = PortabilityLayer::DisplayDeviceManager::GetInstance()->GetTickCount();
}
short Alert(int dialogID, void *unknown)
{
PL_NotYetImplemented();
return 0;
}
Handle GetResource(int32_t resType, int id)
{
PortabilityLayer::MMHandleBlock *block = PortabilityLayer::ResourceManager::GetInstance()->GetResource(PortabilityLayer::ResTypeID(resType), id);
if (!block)
return nullptr;
return &block->m_contents;
}
Handle GetResource(const char(&resTypeLiteral)[5], int id)
{
PL_NotYetImplemented();
return nullptr;
}
short FindWindow(Point point, WindowPtr *window)
{
PL_NotYetImplemented();
return 0;
}
void DragWindow(WindowPtr window, Point start, Rect *bounds)
{
PL_NotYetImplemented();
}
void SendBehind(WindowPtr window, WindowPtr behind)
{
PL_NotYetImplemented();
}
void BringToFront(WindowPtr window)
{
PL_NotYetImplemented();
}
void ShowHide(WindowPtr window, Boolean hide)
{
PL_NotYetImplemented();
}
bool TrackGoAway(WindowPtr window, Point point)
{
PL_NotYetImplemented();
return false;
}
Int32 GrowWindow(WindowPtr window, Point start, Rect *size)
{
PL_NotYetImplemented();
return 0;
}
bool TrackBox(WindowPtr window, Point point, int part)
{
PL_NotYetImplemented();
return false;
}
void ZoomWindow(WindowPtr window, int part, bool bringToFront)
{
PL_NotYetImplemented();
}
void HiliteWindow(WindowPtr window, bool highlighted)
{
PL_NotYetImplemented();
}
void DisposeWindow(WindowPtr window)
{
PL_NotYetImplemented();
}
void GetWindowBounds(WindowPtr window, WindowRegionType windowRegion, Rect *rect)
{
PL_NotYetImplemented();
}
WindowPtr GetNewCWindow(int resID, void *storage, WindowPtr behind)
{
PL_NotYetImplemented();
return nullptr;
}
WindowPtr NewCWindow(void *storage, const Rect *bounds, const PLPasStr &title, Boolean visible, int wdef, WindowPtr behind, Boolean hasCloseBox, long userdata)
{
PL_NotYetImplemented();
return nullptr;
}
WindowPtr NewWindow(void *storage, const Rect *bounds, const PLPasStr &title, Boolean visible, int wdef, WindowPtr behind, Boolean hasCloseBox, long userdata)
{
PL_NotYetImplemented();
return nullptr;
}
void SizeWindow(WindowPtr window, int width, int height, Boolean addToUpdateRegion)
{
PL_NotYetImplemented();
}
void MoveWindow(WindowPtr window, int x, int y, Boolean moveToFront)
{
PL_NotYetImplemented();
}
void ShowWindow(WindowPtr window)
{
PL_NotYetImplemented();
}
void SetWTitle(WindowPtr window, const PLPasStr &title)
{
PL_NotYetImplemented();
}
bool GetNextEvent(int32_t eventMask, EventRecord *event)
{
PL_NotYetImplemented();
return noErr;
}
long MenuSelect(Point point)
{
PL_NotYetImplemented();
return noErr;
}
long MenuKey(int charCode)
{
PL_NotYetImplemented();
return noErr;
}
long TickCount()
{
return PortabilityLayer::DisplayDeviceManager::GetInstance()->GetTickCount();
}
void GetKeys(KeyMap keyMap)
{
PL_NotYetImplemented();
}
short LoWord(Int32 v)
{
return ((v ^ 0x8000) & 0xffff) - 0x8000;
}
short HiWord(Int32 v)
{
return (((v >> 16) ^ 0x8000) & 0xffff) - 0x8000;
}
bool BitTst(const KeyMap *keyMap, int bit)
{
PL_NotYetImplemented();
return noErr;
}
void NumToString(long number, unsigned char *str)
{
PL_NotYetImplemented();
}
void ParamText(const PLPasStr &title, const PLPasStr &a, const PLPasStr &b, const PLPasStr &c)
{
PL_NotYetImplemented();
}
UInt32 FreeMem()
{
PL_NotYetImplemented_Minor();
return 256 * 1024 * 1024;
}
OSErr AEProcessAppleEvent(EventRecord *evt)
{
PL_NotYetImplemented();
return noErr;
}
OSErr FindFolder(int refNum, int posType, bool createFolder, short *volumeRef, long *dirID)
{
switch (posType)
{
case kPreferencesFolderType:
*volumeRef = 0;
*dirID = PortabilityLayer::EVirtualDirectory_Prefs;
return noErr;
default:
return genericErr;
}
}
void GetIndString(unsigned char *str, int stringsID, int fnameIndex)
{
PL_NotYetImplemented();
}
OSErr PBDirCreate(HFileParam *fileParam, bool asynchronous)
{
PL_NotYetImplemented();
return noErr;
}
OSErr FSMakeFSSpec(int refNum, long dirID, const PLPasStr &fileName, FSSpec *spec)
{
if (fileName.Length() >= sizeof(spec->name))
return genericErr;
PortabilityLayer::Utils::MakePStr(spec->name, fileName.Length(), fileName.Chars());
spec->vRefNum = refNum;
spec->parID = dirID;
if (!PortabilityLayer::FileManager::GetInstance()->FileExists(dirID, fileName))
return fnfErr;
return noErr;
}
OSErr FSpCreate(const FSSpec *spec, UInt32 creator, UInt32 fileType, ScriptCode scriptTag)
{
PL_NotYetImplemented();
return noErr;
}
OSErr FSpDirCreate(const FSSpec *spec, ScriptCode script, long *outDirID)
{
PL_NotYetImplemented();
return noErr;
}
OSErr FSpOpenDF(const FSSpec *spec, int permission, short *refNum)
{
PortabilityLayer::EFilePermission perm = PortabilityLayer::EFilePermission_Any;
switch (permission)
{
case fsRdPerm:
perm = PortabilityLayer::EFilePermission_Read;
break;
case fsWrPerm:
case fsRdWrPerm:
perm = PortabilityLayer::EFilePermission_ReadWrite;
break;
case fsCurPerm:
perm = PortabilityLayer::EFilePermission_Any;
break;
default:
return permErr;
}
return PortabilityLayer::FileManager::GetInstance()->OpenFileDF(spec->parID, spec->name, perm, refNum);
}
OSErr FSWrite(short refNum, long *byteCount, const void *data)
{
PL_NotYetImplemented();
return noErr;
}
OSErr FSRead(short refNum, long *byteCount, void *data)
{
PL_NotYetImplemented();
return noErr;
}
OSErr FSpDelete(const FSSpec *spec)
{
PL_NotYetImplemented();
return noErr;
}
OSErr FSpGetFInfo(const FSSpec *spec, FInfo *finfo)
{
PL_NotYetImplemented();
return noErr;
}
OSErr SetFPos(short refNum, SetFPosWhere where, long offset)
{
PL_NotYetImplemented();
return noErr;
}
OSErr GetEOF(short refNum, long *byteCount)
{
PL_NotYetImplemented();
return noErr;
}
OSErr SetEOF(short refNum, long byteCount)
{
PL_NotYetImplemented();
return noErr;
}
OSErr PBGetCatInfo(CInfoPBPtr paramBlock, Boolean async)
{
PL_NotYetImplemented();
return noErr;
}
short StringWidth(const PLPasStr &str)
{
PL_NotYetImplemented();
return 0;
}
void GetMouse(Point *point)
{
PL_NotYetImplemented();
}
Boolean Button()
{
PL_NotYetImplemented();
return false;
}
Boolean StillDown()
{
PL_NotYetImplemented();
return false;
}
Boolean WaitMouseUp()
{
PL_NotYetImplemented();
return false;
}
void LocalToGlobal(Point *point)
{
PL_NotYetImplemented();
}
void GlobalToLocal(Point *point)
{
PL_NotYetImplemented();
}
short Random()
{
// Should return with range -32767..32767
uint32_t bits = PortabilityLayer::RandomNumberGenerator::GetInstance()->GetNextAndAdvance();
uint16_t rWord = (bits & 0xffff);
if (rWord == 0)
{
rWord = (bits >> 16) & 0xffff;
if (rWord == 0)
return 0; // This should be extremely rare
}
return static_cast<short>(static_cast<int32_t>(rWord) - 0x8000);
}
void GetDateTime(UInt32 *dateTime)
{
PL_NotYetImplemented();
}
void GetTime(DateTimeRec *dateTime)
{
PL_NotYetImplemented();
}
UInt32 GetDblTime()
{
PL_NotYetImplemented_Minor();
return 30;
}
void FlushEvents(int mask, int unknown)
{
PL_NotYetImplemented();
}
void ExitToShell()
{
PL_NotYetImplemented();
}
void InvalWindowRect(WindowPtr window, const Rect *rect)
{
PL_NotYetImplemented();
}
Handle NewHandle(Size size)
{
PortabilityLayer::MMHandleBlock *hBlock = PortabilityLayer::MemoryManager::GetInstance()->AllocHandle(size);
if (!hBlock)
return nullptr;
return &hBlock->m_contents;
}
void DisposeHandle(Handle handle)
{
PL_NotYetImplemented();
}
long GetHandleSize(Handle handle)
{
PL_NotYetImplemented();
return 0;
}
void HNoPurge(Handle hdl)
{
}
void MoveHHi(Handle hdl)
{
}
void HLock(Handle hdl)
{
}
void HUnlock(Handle hdl)
{
}
OSErr PtrAndHand(const void *data, Handle handle, Size size)
{
PL_NotYetImplemented();
return noErr;
}
void SetHandleSize(Handle hdl, Size newSize)
{
PL_NotYetImplemented();
}
void *NewPtr(Size size)
{
PL_NotYetImplemented();
return nullptr;
}
void *NewPtrClear(Size size)
{
PL_NotYetImplemented();
return nullptr;
}
void DisposePtr(void *ptr)
{
PL_NotYetImplemented();
}
Size MaxMem(Size *growBytes)
{
PL_NotYetImplemented();
return 0;
}
void PurgeSpace(long *totalFree, long *contiguousFree)
{
PL_NotYetImplemented();
}
void HSetState(Handle handle, char state)
{
PL_NotYetImplemented();
}
char HGetState(Handle handle)
{
PL_NotYetImplemented();
return 0;
}
OSErr MemError()
{
PL_NotYetImplemented();
return 0;
}
void BlockMove(const void *src, void *dest, Size size)
{
PL_NotYetImplemented();
}
Boolean WaitNextEvent(int eventMask, EventRecord *eventOut, long sleep, void *unknown)
{
PL_NotYetImplemented();
return 0;
}
void DrawControls(WindowPtr window)
{
PL_NotYetImplemented();
}
void DrawGrowIcon(WindowPtr window)
{
PL_NotYetImplemented();
}
void DebugStr(const PLPasStr &str)
{
PL_NotYetImplemented();
}
void PL_NotYetImplemented()
{
assert(false);
}
void PL_NotYetImplemented_Minor()
{
}
void PL_Init()
{
PortabilityLayer::MemoryManager::GetInstance()->Init();
PortabilityLayer::ResourceManager::GetInstance()->Init();
PortabilityLayer::DisplayDeviceManager::GetInstance()->Init();
PortabilityLayer::AEManager::GetInstance()->Init();
}

411
PortabilityLayer/PLCore.h Normal file
View File

@@ -0,0 +1,411 @@
#pragma once
#ifndef __PL_CORE_H__
#define __PL_CORE_H__
#include "DataTypes.h"
#include "PLErrorCodes.h"
#ifdef _MSC_VER
#pragma warning(error:4311) // Pointer truncation to int
#endif
namespace PortabilityLayer
{
struct MMHandleBlock;
}
typedef uint8_t Boolean;
typedef uint8_t Byte;
typedef uint8_t UInt8;
typedef int16_t SInt16;
typedef int32_t Int32;
typedef uint32_t UInt32;
typedef int OSErr;
typedef size_t Size;
typedef unsigned char Str15[16];
typedef unsigned char Str31[32];
typedef unsigned char Str63[64];
typedef unsigned char Str27[28];
typedef unsigned char Str32[33];
typedef unsigned char Str255[256];
typedef unsigned char *StringPtr;
class PLPasStr;
#define PL_DEAD(n) ((void)0)
typedef struct Point
{
short v;
short h;
} Point;
// FIXME: Audit
struct Rect
{
short top;
short left;
short bottom;
short right;
};
struct FinderInfoBlock
{
Int32 fdType;
Int32 fdCreator;
};
struct FileInfoBlock
{
void *ioCompletion;
short ioVRefNum; // Volume ref num
StringPtr ioNamePtr;
int ioFDirIndex; // Index (1-based!)
long ioDirID; // Input: Directory ID Output: File ID
int ioFlAttrib; // File attributes
FinderInfoBlock ioFlFndrInfo;
long ioFlParID;
};
struct DirInfoBlock
{
void *ioCompletion;
short ioVRefNum;
long ioDrDirID;
unsigned char *ioNamePtr;
short ioFDirIndex;
int ioFlAttrib;
};
struct CInfoPBRec
{
FileInfoBlock hFileInfo;
DirInfoBlock dirInfo;
};
struct Cursor
{
};
struct CCursor
{
};
struct CGraf
{
};
struct Window
{
};
struct Menu
{
};
struct Region
{
};
struct DateTimeRec
{
int month;
int hour;
int minute;
};
struct VersionRecord
{
Byte majorVer;
Byte minorVer;
Byte stage;
Byte rcVer;
short countryCode;
Str255 shortVersion;
Str255 unused;
};
struct ColorSpec
{
uint8_t r, g, b;
};
struct FSSpec
{
Str63 name;
UInt32 parID; // Directory ID
SInt16 vRefNum; // Volume ID
};
typedef struct FInfo
{
UInt32 fdType;
} FInfo;
struct HFileParam
{
int ioVRefNum;
long ioDirID;
const unsigned char *ioNamePtr;
void *ioCompletion;
};
struct EventRecord
{
Point where;
uint32_t when;
intptr_t message;
int what;
int modifiers;
};
typedef CGraf *CGrafPtr;
typedef CGrafPtr GWorldPtr;
typedef Window *WindowPtr;
typedef Cursor *CursPtr;
typedef CCursor *CCrsrPtr;
typedef FSSpec *FSSpecPtr;
typedef Menu *MenuPtr;
typedef Region *RgnPtr;
typedef CInfoPBRec *CInfoPBPtr;
typedef VersionRecord *VersRecPtr;
typedef CursPtr *CursHandle;
typedef CCrsrPtr *CCrsrHandle;
typedef MenuPtr *MenuHandle;
typedef RgnPtr *RgnHandle;
typedef VersRecPtr *VersRecHndl;
typedef void *Ptr;
typedef Ptr *Handle;
typedef WindowPtr WindowRef; // wtf?
typedef unsigned char KeyMap[16];
enum RegionID
{
inDesk,
inMenuBar,
inSysWindow,
inContent,
inDrag,
inGrow,
inGoAway,
inZoomIn,
inZoomOut,
};
enum WindowRegionType
{
kWindowContentRgn
};
enum EventCode
{
mouseDown,
mouseUp,
keyDown,
autoKey,
updateEvt,
osEvt,
kHighLevelEvent,
};
enum ScriptCode
{
smSystemScript,
};
enum FindFolderRefNum
{
kOnSystemDisk,
};
enum FindFolderType
{
kPreferencesFolderType,
};
enum SetFPosWhere
{
fsFromStart,
};
enum BuiltinWDEFs
{
noGrowDocProc = 4, // Movable, not resizable
};
static const int everyEvent = -1;
static const int iBeamCursor = 1;
static const int watchCursor = 4;
static const int charCodeMask = 0xff;
static const int keyCodeMask = 0xff00;
static const int shiftKey = 0x1;
static const int cmdKey = 0x2; // Ctrl
static const int optionKey = 0x4; // Alt
static const bool kCreateFolder = true;
static const bool kDontCreateFolder = false;
static const int fsRdPerm = 1;
static const int fsWrPerm = 2;
static const int fsRdWrPerm = (fsRdPerm | fsWrPerm);
static const int fsCurPerm = 4; // Any allowed permission
static const Boolean TRUE = 1;
static const Boolean FALSE = 0;
#define nil nullptr
static const int nullEvent = 0;
//void FlushEvents(int eventMask, int stopMask);
OSErr FSClose(short fsRef);
void InitCursor();
CursHandle GetCursor(int cursorID);
CCrsrHandle GetCCursor(int cursorID);
void SetCCursor(CCrsrHandle handle);
void HideCursor();
void SetCursor(CursPtr cursor);
void DisposeCCursor(CCrsrHandle handle);
void Delay(int ticks, UInt32 *endTickCount);
short Alert(int dialogID, void *unknown);
Handle GetResource(int32_t resType, int id);
Handle GetResource(const char(&resTypeLiteral)[5], int id);
short FindWindow(Point point, WindowPtr *window); // Translates global coordinates to window coordinates, returns a region ID
void DragWindow(WindowPtr window, Point start, Rect *bounds); // Drags the window (probably not implemented)
void SendBehind(WindowPtr window, WindowPtr behind);
void BringToFront(WindowPtr window);
void ShowHide(WindowPtr window, Boolean hide);
bool TrackGoAway(WindowPtr window, Point point); // Returns true if the close box was actually clicked (?)
Int32 GrowWindow(WindowPtr window, Point start, Rect *size);
bool TrackBox(WindowPtr window, Point point, int part); // Returns true if grow/shrink box was clicked (part corresponds to type)
void ZoomWindow(WindowPtr window, int part, bool bringToFront);
void HiliteWindow(WindowPtr window, bool highlighted);
void DisposeWindow(WindowPtr window);
void GetWindowBounds(WindowPtr window, WindowRegionType windowRegion, Rect *rect);
WindowPtr GetNewCWindow(int resID, void *storage, WindowPtr behind);
WindowPtr NewCWindow(void *storage, const Rect *bounds, const PLPasStr &title, Boolean visible, int wdef, WindowPtr behind, Boolean hasCloseBox, long userdata);
WindowPtr NewWindow(void *storage, const Rect *bounds, const PLPasStr &title, Boolean visible, int wdef, WindowPtr behind, Boolean hasCloseBox, long userdata);
void SizeWindow(WindowPtr window, int width, int height, Boolean addToUpdateRegion);
void MoveWindow(WindowPtr window, int x, int y, Boolean moveToFront);
void ShowWindow(WindowPtr window);
void SetWTitle(WindowPtr window, const PLPasStr &title);
bool GetNextEvent(int32_t eventMask, EventRecord *event);
long MenuSelect(Point point); // Breaks into menu select routine (in practice we'll just forward one from the queue?)
long MenuKey(int charCode);
long TickCount();
void GetKeys(KeyMap keyMap);
short LoWord(Int32 v);
short HiWord(Int32 v);
bool BitTst(const KeyMap *keyMap, int bit);
void NumToString(long number, unsigned char *str);
void ParamText(const PLPasStr &title, const PLPasStr &a, const PLPasStr &b, const PLPasStr &c);
UInt32 FreeMem();
OSErr AEProcessAppleEvent(EventRecord *evt);
OSErr FindFolder(int refNum, int posType, bool createFolder, short *volumeRef, long *dirID);
void GetIndString(unsigned char *str, int stringsID, int fnameIndex); // Fetches a string resource of some sort
OSErr PBDirCreate(HFileParam *fileParam, bool asynchronous);
OSErr FSMakeFSSpec(int refNum, long dirID, const PLPasStr &fileName, FSSpec *spec);
OSErr FSpCreate(const FSSpec *spec, UInt32 creator, UInt32 fileType, ScriptCode scriptTag);
OSErr FSpDirCreate(const FSSpec *spec, ScriptCode script, long *outDirID);
OSErr FSpOpenDF(const FSSpec *spec, int permission, short *refNum);
OSErr FSWrite(short refNum, long *byteCount, const void *data);
OSErr FSRead(short refNum, long *byteCount, void *data);
OSErr FSpDelete(const FSSpec *spec);
OSErr FSpGetFInfo(const FSSpec *spec, FInfo *finfo);
OSErr SetFPos(short refNum, SetFPosWhere where, long offset);
OSErr GetEOF(short refNum, long *byteCount);
OSErr SetEOF(short refNum, long byteCount);
OSErr PBGetCatInfo(CInfoPBPtr paramBlock, Boolean async);
short StringWidth(const PLPasStr &str);
void GetMouse(Point *point);
Boolean Button(); // Returns true if there's a mouse down event in the queue
Boolean StillDown();
Boolean WaitMouseUp();
void LocalToGlobal(Point *point);
void GlobalToLocal(Point *point);
short Random();
void GetDateTime(UInt32 *dateTime);
void GetTime(DateTimeRec *dateTime);
UInt32 GetDblTime();
void FlushEvents(int mask, int unknown);
void ExitToShell();
void InvalWindowRect(WindowPtr window, const Rect *rect);
Handle NewHandle(Size size);
void DisposeHandle(Handle handle);
long GetHandleSize(Handle handle);
void HNoPurge(Handle hdl); // Marks a handle as not purgeable
void MoveHHi(Handle hdl); // Relocates a block to the top of the heap
void HLock(Handle hdl); // Disable relocation
void HUnlock(Handle hdl); // Re-enable relocation
OSErr PtrAndHand(const void *data, Handle handle, Size size); // Appends data to the end of a handle
void SetHandleSize(Handle hdl, Size newSize);
void *NewPtr(Size size);
void *NewPtrClear(Size size);
void DisposePtr(void *ptr);
Size MaxMem(Size *growBytes);
void PurgeSpace(long *totalFree, long *contiguousFree);
void HSetState(Handle handle, char state);
char HGetState(Handle handle);
OSErr MemError();
void BlockMove(const void *src, void *dest, Size size);
Boolean WaitNextEvent(int eventMask, EventRecord *eventOut, long sleep, void *unknown);
void DrawControls(WindowPtr window);
void DrawGrowIcon(WindowPtr window);
void DebugStr(const PLPasStr &str);
static const Boolean PL_TRUE = 1;
static const Boolean PL_FALSE = 0;
void PL_NotYetImplemented();
void PL_NotYetImplemented_Minor();
void PL_Init();
#endif

View File

@@ -0,0 +1,84 @@
#include "PLDialogs.h"
void DrawDialog(DialogPtr dialog)
{
PL_NotYetImplemented();
}
WindowPtr GetDialogWindow(DialogPtr dialog)
{
PL_NotYetImplemented();
return nullptr;
}
DialogPtr GetNewDialog(int resID, void *unknown, WindowPtr behind)
{
PL_NotYetImplemented();
return nullptr;
}
CGrafPtr GetDialogPort(DialogPtr dialog)
{
PL_NotYetImplemented();
return nullptr;
}
void GetDialogItem(DialogPtr dialog, int index, short *itemType, Handle *itemHandle, Rect *itemRect)
{
PL_NotYetImplemented();
}
void GetDialogItemText(Handle handle, StringPtr str)
{
PL_NotYetImplemented();
}
void SetDialogItem(DialogPtr dialog, int index, short itemType, Handle itemHandle, const Rect *itemRect)
{
PL_NotYetImplemented();
}
void SetDialogItemText(Handle handle, const PLPasStr &str)
{
PL_NotYetImplemented();
}
void SelectDialogItemText(DialogPtr dialog, int item, int firstSelChar, int lastSelCharExclusive)
{
PL_NotYetImplemented();
}
ModalFilterUPP NewModalFilterUPP(ModalFilterUPP func)
{
return func;
}
void ModalDialog(ModalFilterUPP filter, short *item)
{
PL_NotYetImplemented();
}
void DisposeDialog(DialogPtr dialog)
{
PL_NotYetImplemented();
}
void DisposeModalFilterUPP(ModalFilterUPP upp)
{
PL_NotYetImplemented();
}
void ShowDialogItem(DialogPtr dialog, int item)
{
PL_NotYetImplemented();
}
void HideDialogItem(DialogPtr dialog, int item)
{
PL_NotYetImplemented();
}
void TETextBox(const PLPasStr &str, short len, const Rect *rect, TEMode teMode)
{
PL_NotYetImplemented();
}

View File

@@ -0,0 +1,57 @@
#pragma once
#ifndef __PL_DIALOGS_H__
#define __PL_DIALOGS_H__
#include "PLCore.h"
class PLPasStr;
struct Dialog
{
};
struct DialogTemplate
{
// FIXME: Audit
Rect boundsRect;
};
enum TEMode
{
teCenter
};
typedef Dialog *DialogPtr;
typedef DialogTemplate *DialogTPtr;
typedef DialogTPtr *DialogTHndl;
typedef Boolean(*ModalFilterUPP)(DialogPtr dial, EventRecord *event, short *item);
void DrawDialog(DialogPtr dialog);
WindowPtr GetDialogWindow(DialogPtr dialog);
DialogPtr GetNewDialog(int resID, void *unknown, WindowPtr behind);
CGrafPtr GetDialogPort(DialogPtr dialog);
void GetDialogItem(DialogPtr dialog, int index, short *itemType, Handle *itemHandle, Rect *itemRect);
void GetDialogItemText(Handle handle, StringPtr str);
void SetDialogItem(DialogPtr dialog, int index, short itemType, Handle itemHandle, const Rect *itemRect);
void SetDialogItemText(Handle handle, const PLPasStr &str);
void SelectDialogItemText(DialogPtr dialog, int item, int firstSelChar, int lastSelCharExclusive);
ModalFilterUPP NewModalFilterUPP(ModalFilterUPP func);
void ModalDialog(ModalFilterUPP filter, short *item);
void DisposeDialog(DialogPtr dialog);
void DisposeModalFilterUPP(ModalFilterUPP upp);
void ShowDialogItem(DialogPtr dialog, int item);
void HideDialogItem(DialogPtr dialog, int item);
void TETextBox(const PLPasStr &str, short len, const Rect *rect, TEMode teMode);
#endif

View File

@@ -0,0 +1,32 @@
#pragma once
#ifndef __PL_ERROR_CODES_H__
#define __PL_ERROR_CODES_H__
enum ErrorCodes
{
noErr,
fnfErr,
eofErr,
userCanceledErr,
dirFulErr,
dskFulErr,
ioErr,
bdNamErr,
fnOpnErr,
mFulErr,
tmfoErr,
wPrErr,
fLckdErr,
vLckdErr,
fBsyErr,
dupFNErr,
opWrErr,
volOffLinErr,
permErr,
wrPermErr,
genericErr,
};
#endif

View File

@@ -0,0 +1 @@
#pragma once

View File

@@ -0,0 +1 @@
#pragma once

View File

@@ -0,0 +1 @@
#pragma once

View File

@@ -0,0 +1,53 @@
#include "PLMenus.h"
MenuHandle GetMenu(int resID)
{
PL_NotYetImplemented();
return nullptr;
}
void AppendResMenu(MenuHandle menu, UInt32 resType)
{
PL_NotYetImplemented();
}
void InsertMenu(MenuHandle menu, int index)
{
PL_NotYetImplemented();
}
void DeleteMenu(int menuID)
{
PL_NotYetImplemented();
}
void DrawMenuBar()
{
PL_NotYetImplemented();
}
void HiliteMenu(int menu)
{
PL_NotYetImplemented();
}
void EnableMenuItem(MenuHandle menu, int index)
{
PL_NotYetImplemented();
}
void DisableMenuItem(MenuHandle menu, int index)
{
PL_NotYetImplemented();
}
void CheckMenuItem(MenuHandle menu, int index, Boolean checked)
{
PL_NotYetImplemented();
}
void SetMenuItemText(MenuHandle menu, int index, const PLPasStr &text)
{
PL_NotYetImplemented();
}

View File

@@ -0,0 +1,21 @@
#pragma once
#ifndef __PL_MENUS_H__
#define __PL_MENUS_H__
#include "PLCore.h"
class PLPasStr;
MenuHandle GetMenu(int resID);
void AppendResMenu(MenuHandle menu, UInt32 resType); // Appends all menus of a given type
void InsertMenu(MenuHandle menu, int index);
void DeleteMenu(int menuID); // ???
void DrawMenuBar();
void HiliteMenu(int menu);
void EnableMenuItem(MenuHandle menu, int index);
void DisableMenuItem(MenuHandle menu, int index);
void CheckMenuItem(MenuHandle menu, int index, Boolean checked);
void SetMenuItemText(MenuHandle menu, int index, const PLPasStr &text);
#endif

View File

@@ -0,0 +1,141 @@
#include "PLMovies.h"
OSErr EnterMovies()
{
PL_NotYetImplemented();
return noErr;
}
UserData GetMovieUserData(Movie movie)
{
PL_NotYetImplemented();
return nullptr;
}
int CountUserDataType(UserData userData, UInt32 type)
{
PL_NotYetImplemented();
return 0;
}
OSErr RemoveUserData(UserData userData, UInt32 type, int index)
{
PL_NotYetImplemented();
return noErr;
}
OSErr AddUserData(UserData userData, Handle data, UInt32 type)
{
PL_NotYetImplemented();
return noErr;
}
OSErr OpenMovieFile(const FSSpec *fsSpec, short *outRefNum, int permissions)
{
PL_NotYetImplemented();
return noErr;
}
OSErr NewMovieFromFile(Movie *movie, short refNum, const short *optResId, StringPtr resName, int flags, Boolean *unused)
{
PL_NotYetImplemented();
return noErr;
}
OSErr CloseMovieFile(short refNum)
{
PL_NotYetImplemented();
return noErr;
}
OSErr GoToBeginningOfMovie(Movie movie)
{
PL_NotYetImplemented();
return noErr;
}
OSErr LoadMovieIntoRam(Movie movie, TimeValue time, TimeValue duration, int flags)
{
PL_NotYetImplemented();
return noErr;
}
TimeValue GetMovieTime(Movie movie, TimeRecord *outCurrentTime)
{
PL_NotYetImplemented();
return 0;
}
TimeValue GetMovieDuration(Movie movie)
{
PL_NotYetImplemented();
return 0;
}
OSErr PrerollMovie(Movie movie, TimeValue time, UInt32 rate)
{
PL_NotYetImplemented();
return noErr;
}
TimeBase GetMovieTimeBase(Movie movie)
{
PL_NotYetImplemented();
return nullptr;
}
OSErr SetTimeBaseFlags(TimeBase timeBase, int flags)
{
PL_NotYetImplemented();
return noErr;
}
void SetMovieMasterTimeBase(Movie movie, TimeBase timeBase, void *unused)
{
PL_NotYetImplemented();
}
void GetMovieBox(Movie movie, Rect *rect)
{
PL_NotYetImplemented();
}
void StopMovie(Movie movie)
{
PL_NotYetImplemented();
}
void DisposeMovie(Movie movie)
{
PL_NotYetImplemented();
}
void SetMovieGWorld(Movie movie, CGrafPtr graf, void *unknown)
{
PL_NotYetImplemented();
}
void SetMovieActive(Movie movie, Boolean active)
{
PL_NotYetImplemented();
}
void StartMovie(Movie movie)
{
PL_NotYetImplemented();
}
void MoviesTask(Movie movie, int unknown)
{
PL_NotYetImplemented();
}
void SetMovieBox(Movie movie, const Rect *rect)
{
PL_NotYetImplemented();
}
void SetMovieDisplayClipRgn(Movie movie, RgnHandle region)
{
PL_NotYetImplemented();
}

View File

@@ -0,0 +1,64 @@
#pragma once
#ifndef __PL_MOVIES_H__
#define __PL_MOVIES_H__
#include "PLApplication.h"
struct UserDataObject;
struct TimeBaseObject;
struct MovieObject;
struct UserDataBackingStorage
{
};
typedef int64_t TimeValue;
struct TimeRecord
{
};
enum MovieFlags
{
newMovieActive = 1,
flushFromRam = 2,
};
enum TimeBaseFlags
{
loopTimeBase = 1,
};
typedef UserDataObject *UserData;
typedef TimeBaseObject *TimeBase;
typedef MovieObject *Movie;
OSErr EnterMovies();
UserData GetMovieUserData(Movie movie);
int CountUserDataType(UserData userData, UInt32 type);
OSErr RemoveUserData(UserData userData, UInt32 type, int index); // Index is 1-based
OSErr AddUserData(UserData userData, Handle data, UInt32 type);
OSErr OpenMovieFile(const FSSpec *fsSpec, short *outRefNum, int permissions);
OSErr NewMovieFromFile(Movie *movie, short refNum, const short *optResId, StringPtr resName, int flags, Boolean *unused);
OSErr CloseMovieFile(short refNum);
OSErr GoToBeginningOfMovie(Movie movie);
OSErr LoadMovieIntoRam(Movie movie, TimeValue time, TimeValue duration, int flags);
TimeValue GetMovieTime(Movie movie, TimeRecord *outCurrentTime);
TimeValue GetMovieDuration(Movie movie);
OSErr PrerollMovie(Movie movie, TimeValue time, UInt32 rate);
TimeBase GetMovieTimeBase(Movie movie);
OSErr SetTimeBaseFlags(TimeBase timeBase, int flags);
void SetMovieMasterTimeBase(Movie movie, TimeBase timeBase, void *unused);
void GetMovieBox(Movie movie, Rect *rect);
void StopMovie(Movie movie);
void DisposeMovie(Movie movie);
void SetMovieGWorld(Movie movie, CGrafPtr graf, void *unknown);
void SetMovieActive(Movie movie, Boolean active);
void StartMovie(Movie movie);
void MoviesTask(Movie movie, int unknown);
void SetMovieBox(Movie movie, const Rect *rect);
void SetMovieDisplayClipRgn(Movie movie, RgnHandle region);
#endif

View File

@@ -0,0 +1,13 @@
#include "PLNavigation.h"
OSErr NavGetDefaultDialogOptions(NavDialogOptions *options)
{
PL_NotYetImplemented();
return noErr;
}
OSErr NavPutFile(AEDesc *defaultLocation, NavReplyRecord *reply, NavDialogOptions *dlgOptions, void *unknown, UInt32 fileType, UInt32 fileCreator, void *unknown2)
{
PL_NotYetImplemented();
return noErr;
}

View File

@@ -0,0 +1,27 @@
#pragma once
#ifndef __PL_NAVIGATION_H__
#define __PL_NAVIGATION_H__
#include "PLCore.h"
#include "PLAppleEvents.h"
struct AEDesc;
struct NavReplyRecord
{
bool validRecord;
bool replacing;
int vRefNum;
long parID; // Directory?
AEDescList selection;
ScriptCode keyScript; // ???
};
struct NavDialogOptions
{
};
OSErr NavGetDefaultDialogOptions(NavDialogOptions *options);
OSErr NavPutFile(AEDesc *defaultLocation, NavReplyRecord *reply, NavDialogOptions *dlgOptions, void *unknown, UInt32 fileType, UInt32 fileCreator, void *unknown2);
#endif

View File

@@ -0,0 +1,52 @@
#include "PLNumberFormatting.h"
#include "PLPasStr.h"
void StringToNum(const PLPasStr &str, long *num)
{
if (str.Length() == 0)
{
num = 0;
return;
}
const size_t len = str.Length();
const char *chars = str.Chars();
const char *charsEnd = chars + len;
long result = 0;
if (chars[0] == '-')
{
chars++;
while (chars != charsEnd)
{
const char c = *chars++;
if (c < '0' || c > '9')
{
num = 0;
return;
}
result = result * 10 - (c - '0');
}
}
else
{
while (chars != charsEnd)
{
const char c = *chars++;
if (c < '0' || c > '9')
{
num = 0;
return;
}
result = result * 10 + (c - '0');
}
}
*num = result;
}

View File

@@ -0,0 +1,9 @@
#pragma once
#ifndef __PL_NUMBERFORMATTING_H__
#define __PL_NUMBERFORMATTING_H__
class PLPasStr;
void StringToNum(const PLPasStr &str, long *num);
#endif

View File

@@ -0,0 +1,5 @@
#pragma once
#ifndef __PL_PALETTES_H__
#define __PL_PALETTES_H__
#endif

View File

@@ -0,0 +1,79 @@
#pragma once
#ifndef __PL_PASSTR_H__
#define __PL_PASSTR_H__
#include "CoreDefs.h"
namespace PortabilityLayer
{
template<size_t TSize>
class PascalStrLiteral;
}
class PLPasStr
{
public:
PLPasStr();
PLPasStr(const unsigned char *str);
template<size_t TSize> PLPasStr(const PortabilityLayer::PascalStrLiteral<TSize> &pstrLiteral);
PLPasStr(const PLPasStr &other);
PLPasStr(unsigned char length, const char *str);
unsigned char Length() const;
const char *Chars() const;
const unsigned char *UChars() const;
private:
unsigned char m_length;
const char *m_chars;
};
#include "PascalStrLiteral.h"
inline PLPasStr::PLPasStr()
: m_length(0)
, m_chars(nullptr)
{
}
inline PLPasStr::PLPasStr(const unsigned char *str)
: m_length(str[0])
, m_chars(reinterpret_cast<const char*>(str) + 1)
{
}
template<size_t TSize>
inline PLPasStr::PLPasStr(const PortabilityLayer::PascalStrLiteral<TSize> &pstrLiteral)
: m_length(pstrLiteral.kLength)
, m_chars(pstrLiteral.GetStr())
{
}
inline PLPasStr::PLPasStr(const PLPasStr &other)
: m_length(other.m_length)
, m_chars(other.m_chars)
{
}
inline PLPasStr::PLPasStr(uint8_t length, const char *str)
: m_length(length)
, m_chars(str)
{
}
inline unsigned char PLPasStr::Length() const
{
return m_length;
}
inline const char *PLPasStr::Chars() const
{
return m_chars;
}
inline const unsigned char *PLPasStr::UChars() const
{
return reinterpret_cast<const unsigned char*>(m_chars);
}
#endif

View File

@@ -0,0 +1,50 @@
#include "PLQDOffscreen.h"
OSErr NewGWorld(GWorldPtr *gworld, int depth, Rect *bounds, CTabHandle colorTable, GDHandle device, int flags)
{
PL_NotYetImplemented();
return noErr;
}
void DisposeGWorld(GWorldPtr gworld)
{
PL_NotYetImplemented();
}
PixMapHandle GetGWorldPixMap(GWorldPtr gworld)
{
PL_NotYetImplemented();
return nullptr;
}
void LockPixels(PixMapHandle pixmap)
{
PL_NotYetImplemented();
}
PicHandle GetPicture(short resID)
{
PL_NotYetImplemented();
return nullptr;
}
void OffsetRect(Rect *rect, int right, int down)
{
PL_NotYetImplemented();
}
void DrawPicture(PicHandle pict, Rect *bounds)
{
PL_NotYetImplemented();
}
void GetGWorld(CGrafPtr *gw, GDHandle *gdHandle)
{
PL_NotYetImplemented();
}
void SetGWorld(CGrafPtr gw, GDHandle gdHandle)
{
PL_NotYetImplemented();
}

View File

@@ -0,0 +1,51 @@
#pragma once
#ifndef __PL_QDOFFSCREEN_H__
#define __PL_QDOFFSCREEN_H__
#include "PLCore.h"
#include "PLQuickdraw.h"
struct ColorTable
{
};
struct PixMap
{
};
struct Picture
{
Rect picFrame;
};
typedef ColorTable *CTabPtr;
typedef CTabPtr *CTabHandle;
typedef PixMap *PixMapPtr;
typedef PixMapPtr *PixMapHandle;
typedef Picture *PicPtr;
typedef PicPtr *PicHandle;
enum QDFlags
{
useTempMem = 1,
};
OSErr NewGWorld(GWorldPtr *gworld, int depth, Rect *bounds, CTabHandle colorTable, GDHandle device, int flags);
void DisposeGWorld(GWorldPtr gworld);
PixMapHandle GetGWorldPixMap(GWorldPtr gworld);
void LockPixels(PixMapHandle pixmap);
PicHandle GetPicture(short resID);
void OffsetRect(Rect *rect, int right, int down);
void DrawPicture(PicHandle pict, Rect *bounds);
void GetGWorld(CGrafPtr *gw, GDHandle *gdHandle);
void SetGWorld(CGrafPtr gw, GDHandle gdHandle);
#endif

View File

@@ -0,0 +1,366 @@
#include "PLQuickdraw.h"
#include "DisplayDeviceManager.h"
void GetPort(GrafPtr *graf)
{
PL_NotYetImplemented();
}
void SetPort(GrafPtr graf)
{
PL_NotYetImplemented();
}
void BeginUpdate(GrafPtr graf)
{
PL_NotYetImplemented();
}
void EndUpdate(GrafPtr graf)
{
PL_NotYetImplemented();
}
OSErr GetIconSuite(Handle *suite, short resID, IconSuiteFlags flags)
{
PL_NotYetImplemented();
return noErr;
}
OSErr PlotIconSuite(Rect *rect, IconAlignmentType alignType, IconTransformType transformType, Handle iconSuite)
{
PL_NotYetImplemented();
return noErr;
}
CIconHandle GetCIcon(short resID)
{
PL_NotYetImplemented();
return nullptr;
}
OSErr PlotCIcon(Rect *rect, CIconHandle icon)
{
PL_NotYetImplemented();
return noErr;
}
void DisposeCIcon(CIconHandle icon)
{
PL_NotYetImplemented();
}
void SetRect(Rect *rect, short left, short top, short right, short bottom)
{
rect->left = left;
rect->top = top;
rect->bottom = bottom;
rect->right = right;
}
GDHandle GetMainDevice()
{
return PortabilityLayer::DisplayDeviceManager::GetInstance()->GetMainDevice();
}
void SetPortWindowPort(WindowPtr window)
{
PL_NotYetImplemented();
}
void SetPortDialogPort(Dialog *dialog)
{
PL_NotYetImplemented();
}
void TextSize(int sz)
{
PL_NotYetImplemented();
}
void TextFace(int face)
{
PL_NotYetImplemented();
}
void TextFont(int fontID)
{
PL_NotYetImplemented();
}
int TextWidth(const PLPasStr &str, int firstChar1Based, int length)
{
PL_NotYetImplemented();
return 0;
}
void MoveTo(int x, int y)
{
PL_NotYetImplemented();
}
void LineTo(int x, int y)
{
PL_NotYetImplemented();
}
void SetOrigin(int x, int y)
{
PL_NotYetImplemented();
}
void ForeColor(SystemColorID color)
{
PL_NotYetImplemented();
}
void BackColor(SystemColorID color)
{
PL_NotYetImplemented();
}
void GetForeColor(RGBColor *color)
{
PL_NotYetImplemented();
}
void Index2Color(int index, RGBColor *color)
{
PL_NotYetImplemented();
}
void RGBForeColor(const RGBColor *color)
{
PL_NotYetImplemented();
}
void DrawString(const PLPasStr &str)
{
PL_NotYetImplemented();
}
void PaintRect(const Rect *rect)
{
PL_NotYetImplemented();
}
void PaintOval(const Rect *rect)
{
PL_NotYetImplemented();
}
void PaintRgn(RgnHandle region)
{
PL_NotYetImplemented();
}
void ClipRect(const Rect *rect)
{
PL_NotYetImplemented();
}
void FrameRect(const Rect *rect)
{
PL_NotYetImplemented();
}
void FrameOval(const Rect *rect)
{
PL_NotYetImplemented();
}
void FrameRoundRect(const Rect *rect, int w, int h)
{
PL_NotYetImplemented();
}
void PenMode(int mode)
{
PL_NotYetImplemented();
}
void PenMode(PenModeID penMode)
{
PL_NotYetImplemented();
}
void PenMode(CopyBitsMode copyBitsMode)
{
PL_NotYetImplemented();
}
void PenPat(const Pattern *pattern)
{
PL_NotYetImplemented();
}
void PenSize(int w, int h)
{
PL_NotYetImplemented();
}
void PenNormal()
{
PL_NotYetImplemented();
}
void EraseRect(const Rect *rect)
{
PL_NotYetImplemented();
}
void InvertRect(const Rect *rect)
{
PL_NotYetImplemented();
}
void InsetRect(Rect *rect, int x, int y)
{
PL_NotYetImplemented();
}
void Line(int x, int y)
{
PL_NotYetImplemented();
}
Pattern *GetQDGlobalsGray(Pattern *pattern)
{
PL_NotYetImplemented();
return nullptr;
}
Pattern *GetQDGlobalsBlack(Pattern *pattern)
{
PL_NotYetImplemented();
return nullptr;
}
void GetIndPattern(Pattern *pattern, int patListID, int index)
{
PL_NotYetImplemented();
}
void CopyBits(const BitMap *srcBitmap, BitMap *destBitmap, const Rect *srcRect, const Rect *destRect, CopyBitsMode copyMode, RgnHandle maskRegion)
{
PL_NotYetImplemented();
}
void CopyMask(const BitMap *srcBitmap, const BitMap *maskBitmap, BitMap *destBitmap, const Rect *srcRect, const Rect *maskRect, const Rect *destRect)
{
PL_NotYetImplemented();
}
RgnHandle NewRgn()
{
PL_NotYetImplemented();
return nullptr;
}
void RectRgn(RgnHandle region, const Rect *rect)
{
PL_NotYetImplemented();
}
void UnionRgn(RgnHandle regionA, RgnHandle regionB, RgnHandle regionC)
{
PL_NotYetImplemented();
}
void DisposeRgn(RgnHandle rgn)
{
PL_NotYetImplemented();
}
void OpenRgn()
{
PL_NotYetImplemented();
}
void CloseRgn(RgnHandle rgn)
{
PL_NotYetImplemented();
}
Boolean PtInRgn(Point point, RgnHandle rgn)
{
PL_NotYetImplemented();
return false;
}
void GetClip(RgnHandle rgn)
{
PL_NotYetImplemented();
}
void SetClip(RgnHandle rgn)
{
PL_NotYetImplemented();
}
BitMap *GetPortBitMapForCopyBits(CGrafPtr grafPtr)
{
PL_NotYetImplemented();
return nullptr;
}
CGrafPtr GetWindowPort(WindowPtr window)
{
PL_NotYetImplemented();
return nullptr;
}
RgnHandle GetPortVisibleRegion(CGrafPtr port, RgnHandle region)
{
PL_NotYetImplemented();
return nullptr;
}
Int32 DeltaPoint(Point pointA, Point pointB)
{
PL_NotYetImplemented();
return 0;
}
void SubPt(Point srcPoint, Point *destPoint)
{
PL_NotYetImplemented();
}
Boolean SectRect(const Rect *rectA, const Rect *rectB, Rect *outIntersection)
{
PL_NotYetImplemented();
return false;
}
Boolean PtInRect(Point point, const Rect *rect)
{
PL_NotYetImplemented();
return false;
}
void RestoreDeviceClut(void *unknown)
{
PL_NotYetImplemented();
}
void PaintBehind(void *unknown, RgnHandle region)
{
PL_NotYetImplemented();
}
RgnHandle GetGrayRgn()
{
PL_NotYetImplemented();
return nullptr;
}

View File

@@ -0,0 +1,217 @@
#pragma once
#ifndef __PL_QUICKDRAW_H__
#define __PL_QUICKDRAW_H__
#include "PLCore.h"
struct Dialog;
enum IconAlignmentType
{
atNone
};
enum IconTransformType
{
ttNone
};
enum IconSuiteFlags
{
svAllLargeData = 1,
};
enum TextFlags
{
bold = 1,
italicBit = 2,
ulineBit = 4,
outlineBit = 8,
shadowBit = 16,
condenseBit = 32,
extendBit = 64,
};
enum SystemFontID
{
systemFont = 0, // System font
applFont = 1, // Application font
newYork = 2,
geneva = 3,
monaco = 4,
venice = 5,
london = 6,
athens = 7,
sanFran = 8,
toronto = 9,
cairo = 11,
losAngeles = 12,
times = 20,
helvetica = 21,
courier = 22,
symbol = 23,
mobile = 24,
};
// wtf?
enum SystemColorID
{
whiteColor = 30,
blackColor = 33,
yellowColor = 69,
magentaColor = 137,
redColor = 205,
cyanColor = 273,
greenColor = 341,
blueColor = 409,
};
enum CopyBitsMode
{
srcCopy,
srcOr,
srcXor,
srcBic,
notSrcCopy,
notSrcOr,
notSrcXor,
notSrcBic,
transparent
};
enum PenModeID
{
patCopy = 8,
patOr,
patXor,
patBic,
notPatCopy,
notPatOr,
notPatXor,
notPatBic,
};
enum HiliteMode
{
hilite = 50,
};
struct CIcon
{
};
struct GDevice
{
};
struct BitMap
{
};
struct RGBColor
{
unsigned short red;
unsigned short green;
unsigned short blue;
};
typedef GDevice *GDPtr;
typedef GDPtr *GDHandle;
typedef CIcon *CIconPtr;
typedef CIconPtr *CIconHandle;
typedef WindowPtr GrafPtr;
typedef Byte Pattern[8];
void GetPort(GrafPtr *graf);
void SetPort(GrafPtr graf);
void SetPortWindowPort(WindowPtr window);
void SetPortDialogPort(Dialog *dialog);
void BeginUpdate(GrafPtr graf);
void EndUpdate(GrafPtr graf);
OSErr GetIconSuite(Handle *suite, short resID, IconSuiteFlags flags);
OSErr PlotIconSuite(Rect *rect, IconAlignmentType alignType, IconTransformType transformType, Handle iconSuite);
CIconHandle GetCIcon(short resID);
OSErr PlotCIcon(Rect *rect, CIconHandle icon);
void DisposeCIcon(CIconHandle icon);
void SetRect(Rect *rect, short left, short top, short right, short bottom);
GDHandle GetMainDevice();
void TextSize(int sz);
void TextFace(int face);
void TextFont(int fontID);
int TextWidth(const PLPasStr &str, int firstChar1Based, int length);
void MoveTo(int x, int y);
void LineTo(int x, int y);
void SetOrigin(int x, int y);
void ForeColor(SystemColorID color);
void BackColor(SystemColorID color);
void GetForeColor(RGBColor *color);
void Index2Color(int index, RGBColor *color);
void RGBForeColor(const RGBColor *color);
void DrawString(const PLPasStr &str);
void PaintRect(const Rect *rect);
void PaintOval(const Rect *rect);
void PaintRgn(RgnHandle region);
void ClipRect(const Rect *rect); // Sets the clipping area
void FrameRect(const Rect *rect);
void FrameOval(const Rect *rect);
void FrameRoundRect(const Rect *rect, int w, int h);
void PenMode(int mode); // Can be CopyBitsMode, PenModeID, and possibly add "50" to hilite
void PenPat(const Pattern *pattern);
void PenSize(int w, int h);
void PenNormal();
void EraseRect(const Rect *rect);
void InvertRect(const Rect *rect);
void InsetRect(Rect *rect, int x, int y);
void Line(int x, int y); // FIXME: Is this relative or absolute?
Pattern *GetQDGlobalsGray(Pattern *pattern);
Pattern *GetQDGlobalsBlack(Pattern *pattern);
// Finds a pattern from a 'PAT#' resource
// Index is 1-based
void GetIndPattern(Pattern *pattern, int patListID, int index);
void CopyBits(const BitMap *srcBitmap, BitMap *destBitmap, const Rect *srcRect, const Rect *destRect, CopyBitsMode copyMode, RgnHandle maskRegion);
void CopyMask(const BitMap *srcBitmap, const BitMap *maskBitmap, BitMap *destBitmap, const Rect *srcRect, const Rect *maskRect, const Rect *destRect);
RgnHandle NewRgn();
void RectRgn(RgnHandle region, const Rect *rect);
void UnionRgn(RgnHandle regionA, RgnHandle regionB, RgnHandle regionC);
void DisposeRgn(RgnHandle rgn);
void OpenRgn();
void CloseRgn(RgnHandle rgn);
Boolean PtInRgn(Point point, RgnHandle rgn);
void GetClip(RgnHandle rgn);
void SetClip(RgnHandle rgn);
BitMap *GetPortBitMapForCopyBits(CGrafPtr grafPtr);
CGrafPtr GetWindowPort(WindowPtr window);
RgnHandle GetPortVisibleRegion(CGrafPtr port, RgnHandle region);
// Computes A - B and returns it packed?
Int32 DeltaPoint(Point pointA, Point pointB);
// Subtracts srcPoint from destPoint (reverse of DeltaPoint)
void SubPt(Point srcPoint, Point *destPoint);
Boolean SectRect(const Rect *rectA, const Rect *rectB, Rect *outIntersection);
Boolean PtInRect(Point point, const Rect *rect);
void RestoreDeviceClut(void *unknown);
void PaintBehind(void *unknown, RgnHandle region);
RgnHandle GetGrayRgn(); // Returns the region not occupied by the menu bar
#endif

View File

@@ -0,0 +1,138 @@
#include "ResourceManager.h"
#include "VirtualDirectory.h"
#include "FileManager.h"
#include "HostFileSystem.h"
#include "HostMemoryBuffer.h"
#include "IOStream.h"
#include "MacBinary2.h"
#include "MacFileMem.h"
#include "MemReaderStream.h"
#include "ResourceFile.h"
#include "PLPasStr.h"
#include "PLErrorCodes.h"
#include <vector>
namespace PortabilityLayer
{
class ResourceManagerImpl final : public ResourceManager
{
public:
ResourceManagerImpl();
void Init() override;
void Shutdown() override;
void SetResLoad(bool load) override;
short OpenResFork(EVirtualDirectory virtualDir, const PLPasStr &filename) override;
MMHandleBlock *GetResource(const ResTypeID &resType, int id) override;
short GetCurrentResFile() const override;
void SetCurrentResFile(short ref) override;
static ResourceManagerImpl *GetInstance();
private:
std::vector<ResourceFile*> m_resFiles;
short m_currentResFile;
bool m_load;
static ResourceManagerImpl ms_instance;
};
ResourceManagerImpl::ResourceManagerImpl()
: m_currentResFile(0)
, m_load(true)
{
}
void ResourceManagerImpl::Init()
{
m_currentResFile = OpenResFork(EVirtualDirectory_ApplicationData, PSTR("ApplicationResources"));
}
void ResourceManagerImpl::Shutdown()
{
for (std::vector<ResourceFile*>::iterator it = m_resFiles.begin(), itEnd = m_resFiles.end(); it != itEnd; ++it)
delete (*it);
m_resFiles.clear();
}
short ResourceManagerImpl::GetCurrentResFile() const
{
return m_currentResFile;
}
void ResourceManagerImpl::SetCurrentResFile(short ref)
{
m_currentResFile = ref;
}
ResourceManagerImpl *ResourceManagerImpl::GetInstance()
{
return &ms_instance;
}
void ResourceManagerImpl::SetResLoad(bool load)
{
m_load = load;
}
short ResourceManagerImpl::OpenResFork(EVirtualDirectory virtualDir, const PLPasStr &filename)
{
const size_t numSlots = m_resFiles.size();
size_t resFileIndex = numSlots;
for (size_t i = 0; i < numSlots; i++)
{
if (m_resFiles[i] == nullptr)
{
resFileIndex = i;
break;
}
}
if (resFileIndex == 0x7fff)
return 0;
IOStream *fStream = nullptr;
if (FileManager::GetInstance()->RawOpenFileRF(virtualDir, filename, EFilePermission_Read, true, &fStream) != noErr)
return 0;
ResourceFile *resFile = new ResourceFile();
bool loaded = resFile->Load(fStream);
fStream->Close();
if (!loaded)
{
delete resFile;
return 0;
}
if (resFileIndex == numSlots)
m_resFiles.push_back(resFile);
else
m_resFiles[resFileIndex] = resFile;
return static_cast<short>(resFileIndex + 1);
}
MMHandleBlock *ResourceManagerImpl::GetResource(const ResTypeID &resType, int id)
{
if (!m_currentResFile)
return nullptr;
ResourceFile *resFile = m_resFiles[m_currentResFile - 1];
if (!resFile)
return nullptr;
return resFile->GetResource(resType, id, m_load);
}
ResourceManagerImpl ResourceManagerImpl::ms_instance;
ResourceManager *ResourceManager::GetInstance() { return ResourceManagerImpl::GetInstance(); }
}

View File

@@ -0,0 +1,88 @@
#include "PLResources.h"
#include "MMHandleBlock.h"
#include "ResourceManager.h"
#include "ResourceCompiledRef.h"
void DetachResource(Handle hdl)
{
PL_NotYetImplemented();
}
void ReleaseResource(Handle hdl)
{
PL_NotYetImplemented();
}
short CurResFile()
{
return PortabilityLayer::ResourceManager::GetInstance()->GetCurrentResFile();
}
void UseResFile(short fid)
{
PL_NotYetImplemented();
}
Handle Get1Resource(UInt32 resID, int index)
{
PL_NotYetImplemented();
return nullptr;
}
Handle Get1IndResource(UInt32 resID, int index)
{
PL_NotYetImplemented();
return nullptr;
}
int Count1Resources(UInt32 resType)
{
PL_NotYetImplemented();
return 0;
}
void HCreateResFile(int refNum, long dirID, const PLPasStr &name)
{
PL_NotYetImplemented();
}
OSErr ResError()
{
PL_NotYetImplemented();
return noErr;
}
short FSpOpenResFile(const FSSpec *spec, int permission)
{
PL_NotYetImplemented();
return 0;
}
void CloseResFile(short refNum)
{
PL_NotYetImplemented();
}
void SetResLoad(Boolean load)
{
PortabilityLayer::ResourceManager::GetInstance()->SetResLoad(load != 0);
}
long GetMaxResourceSize(Handle res)
{
const PortabilityLayer::MMHandleBlock *hBlock = reinterpret_cast<PortabilityLayer::MMHandleBlock*>(res);
const PortabilityLayer::ResourceCompiledRef *resRef = hBlock->m_rmSelfRef;
return resRef->GetSize();
}
void GetResInfo(Handle res, short *resID, ResType *resType, Str255 resName)
{
PL_NotYetImplemented();
}
short HOpenResFile(short refNum, long parID, const PLPasStr &name, int permissions)
{
PL_NotYetImplemented();
return 0;
}

View File

@@ -0,0 +1,37 @@
#pragma once
#ifndef __PL_RESOURCES_H__
#define __PL_RESOURCES_H__
#include "PLCore.h"
struct ResType
{
};
class PLPasStr;
void DetachResource(Handle hdl);
void ReleaseResource(Handle hdl);
short CurResFile();
void UseResFile(short fid);
Handle Get1Resource(UInt32 resID, int index);
Handle Get1IndResource(UInt32 resID, int index);
int Count1Resources(UInt32 resType);
void HCreateResFile(int refNum, long dirID, const PLPasStr &name);
OSErr ResError();
short FSpOpenResFile(const FSSpec *spec, int permission);
void CloseResFile(short refNum);
void SetResLoad(Boolean load); // Sets whether resources should be loaded when requested
long GetMaxResourceSize(Handle res);
void GetResInfo(Handle res, short *resID, ResType *resType, Str255 resName);
// This should return -1 on error?
short HOpenResFile(short refNum, long parID, const PLPasStr &name, int permissions);
#endif

View File

@@ -0,0 +1 @@
#pragma once

View File

@@ -0,0 +1,53 @@
#include "PLSound.h"
OSErr GetDefaultOutputVolume(long *vol)
{
short leftVol = 0x100;
short rightVol = 0x100;
PL_NotYetImplemented_Minor();
*vol = (leftVol) | (rightVol << 16);
return noErr;
}
OSErr SetDefaultOutputVolume(long vol)
{
return noErr;
}
SndCallBackUPP NewSndCallBackProc(SndCallBackProc callback)
{
return callback;
}
void DisposeSndCallBackUPP(SndCallBackUPP upp)
{
}
OSErr SndNewChannel(SndChannelPtr *outChannel, SndSynthType synthType, int initFlags, SndCallBackUPP callback)
{
PL_NotYetImplemented();
return noErr;
}
OSErr SndDisposeChannel(SndChannelPtr channel, Boolean flush)
{
PL_NotYetImplemented();
return noErr;
}
OSErr SndDoCommand(SndChannelPtr channel, const SndCommand *command, Boolean failIfFull)
{
PL_NotYetImplemented();
return noErr;
}
OSErr SndDoImmediate(SndChannelPtr channel, const SndCommand *command)
{
PL_NotYetImplemented();
return noErr;
}

View File

@@ -0,0 +1,56 @@
#pragma once
#ifndef __PL_SOUND_H__
#define __PL_SOUND_H__
#include "PLCore.h"
enum SndCommandType
{
nullCmd,
bufferCmd, // Param1: 0 Param2: Offset to sound header
callBackCmd,
flushCmd,
quietCmd
};
struct SndChannel
{
};
struct SndCommand
{
SndCommandType cmd;
intptr_t param1;
intptr_t param2;
};
enum SndSynthType
{
sampledSynth
};
enum SndInitFlags
{
initNoInterp = 1,
initMono = 2,
};
typedef SndChannel *SndChannelPtr;
typedef void(*SndCallBackProc)(SndChannelPtr channel, SndCommand *command);
typedef SndCallBackProc SndCallBackUPP;
// Vol seems to be a packed stereo DWord
OSErr GetDefaultOutputVolume(long *vol);
OSErr SetDefaultOutputVolume(long vol);
SndCallBackUPP NewSndCallBackProc(SndCallBackProc callback);
void DisposeSndCallBackUPP(SndCallBackUPP upp);
OSErr SndNewChannel(SndChannelPtr *outChannel, SndSynthType synthType, int initFlags, SndCallBackUPP callback);
OSErr SndDisposeChannel(SndChannelPtr channel, Boolean flush);
OSErr SndDoCommand(SndChannelPtr channel, const SndCommand *command, Boolean failIfFull);
OSErr SndDoImmediate(SndChannelPtr channel, const SndCommand *command);
#endif

View File

@@ -0,0 +1,7 @@
#include "PLStringCompare.h"
Boolean EqualString(const PLPasStr &string1, const PLPasStr &string2, Boolean caseSensitive, Boolean diacriticSensitive)
{
PL_NotYetImplemented();
return false;
}

View File

@@ -0,0 +1,10 @@
#pragma once
#ifndef __PL_STRINGCOMPARE_H__
#define __PL_STRINGCOMPARE_H__
#include "PLCore.h"
#include "PLPasStr.h"
Boolean EqualString(const PLPasStr &string1, const PLPasStr &string2, Boolean caseSensitive, Boolean diacriticSensitive);
#endif

View File

@@ -0,0 +1 @@
#pragma once

View File

@@ -0,0 +1 @@
#pragma once

View File

@@ -0,0 +1,36 @@
#pragma once
#ifndef __PL_PASCALSTR_H__
#define __PL_PASCALSTR_H__
#include "UnsafePascalStr.h"
namespace PortabilityLayer
{
template<size_t TSize>
class PascalStr : public UnsafePascalStr<TSize, true>
{
public:
PascalStr();
PascalStr(size_t size, const char *str);
};
}
#include <string.h>
namespace PortabilityLayer
{
template<size_t TSize>
inline PascalStr<TSize>::PascalStr()
: UnsafePascalStr<TSize, true>(0, nullptr)
{
}
template<size_t TSize>
PascalStr<TSize>::PascalStr(size_t size, const char *str)
: UnsafePascalStr<TSize, true>(size, str)
{
}
}
#endif

View File

@@ -0,0 +1,40 @@
#pragma once
#ifndef __PL_PASCAL_STR_LITERAL_H__
#define __PL_PASCAL_STR_LITERAL_H__
#include "DataTypes.h"
namespace PortabilityLayer
{
template<size_t TSize>
class PascalStrLiteral
{
public:
PascalStrLiteral(const char (&literalStr)[TSize]);
const char *GetStr() const;
static const uint8_t kLength = TSize - 1;
private:
const char *m_literal;
};
}
namespace PortabilityLayer
{
template<size_t TSize>
inline PascalStrLiteral<TSize>::PascalStrLiteral(const char(&literalStr)[TSize])
: m_literal(literalStr)
{
}
template<size_t TSize>
inline const char *PascalStrLiteral<TSize>::GetStr() const
{
return m_literal;
}
}
#define PSTR(n) (::PortabilityLayer::PascalStrLiteral<sizeof(n)>(n))
#endif

View File

@@ -0,0 +1,238 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup Label="ProjectConfigurations">
<ProjectConfiguration Include="Debug|Win32">
<Configuration>Debug</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|Win32">
<Configuration>Release</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Debug|x64">
<Configuration>Debug</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|x64">
<Configuration>Release</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
</ItemGroup>
<PropertyGroup Label="Globals">
<VCProjectVersion>15.0</VCProjectVersion>
<ProjectGuid>{6EC62B0F-9353-40A4-A510-3788F1368B33}</ProjectGuid>
<RootNamespace>PortabilityLayer</RootNamespace>
<WindowsTargetPlatformVersion>10.0.16299.0</WindowsTargetPlatformVersion>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v141</PlatformToolset>
<CharacterSet>MultiByte</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v141</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>MultiByte</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
<ConfigurationType>StaticLibrary</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v141</PlatformToolset>
<CharacterSet>MultiByte</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
<ConfigurationType>StaticLibrary</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v141</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>MultiByte</CharacterSet>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings">
</ImportGroup>
<ImportGroup Label="Shared">
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
<Import Project="..\Common.props" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
<Import Project="..\Common.props" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
<Import Project="..\Common.props" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
<Import Project="..\Common.props" />
</ImportGroup>
<PropertyGroup Label="UserMacros" />
<PropertyGroup />
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<Optimization>Disabled</Optimization>
<SDLCheck>true</SDLCheck>
<ConformanceMode>true</ConformanceMode>
</ClCompile>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<Optimization>Disabled</Optimization>
<SDLCheck>true</SDLCheck>
<ConformanceMode>true</ConformanceMode>
</ClCompile>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<Optimization>MaxSpeed</Optimization>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<SDLCheck>true</SDLCheck>
<ConformanceMode>true</ConformanceMode>
</ClCompile>
<Link>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<Optimization>MaxSpeed</Optimization>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<SDLCheck>true</SDLCheck>
<ConformanceMode>true</ConformanceMode>
</ClCompile>
<Link>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
</Link>
</ItemDefinitionGroup>
<ItemGroup>
<ClInclude Include="AEHandlerDesc.h" />
<ClInclude Include="AEManager.h" />
<ClInclude Include="BinarySearch.h" />
<ClInclude Include="BinHex4.h" />
<ClInclude Include="BytePack.h" />
<ClInclude Include="ByteSwap.h" />
<ClInclude Include="ByteUnpack.h" />
<ClInclude Include="CFileStream.h" />
<ClInclude Include="DataTypes.h" />
<ClInclude Include="DisplayDeviceManager.h" />
<ClInclude Include="FileManager.h" />
<ClInclude Include="FilePermission.h" />
<ClInclude Include="GpAppInterface.h" />
<ClInclude Include="HostSuspendCallArgument.h" />
<ClInclude Include="HostSuspendCallID.h" />
<ClInclude Include="HostSuspendHook.h" />
<ClInclude Include="HostDisplayDriver.h" />
<ClInclude Include="HostSystemServices.h" />
<ClInclude Include="IOStream.h" />
<ClInclude Include="MacBinary2.h" />
<ClInclude Include="MacFileMem.h" />
<ClInclude Include="MacFileInfo.h" />
<ClInclude Include="MacFileWriteableMem.h" />
<ClInclude Include="MacRsrcHeader.h" />
<ClInclude Include="MacRsrcMap.h" />
<ClInclude Include="MemoryManager.h" />
<ClInclude Include="MemReaderStream.h" />
<ClInclude Include="MMBlock.h" />
<ClInclude Include="MMHandleBlock.h" />
<ClInclude Include="PascalStr.h" />
<ClInclude Include="PascalStrLiteral.h" />
<ClInclude Include="PLAliases.h" />
<ClInclude Include="HostMemoryBuffer.h" />
<ClInclude Include="HostFileSystem.h" />
<ClInclude Include="PLAppleEvents.h" />
<ClInclude Include="PLAppleEventsCommonTypes.h" />
<ClInclude Include="PLApplication.h" />
<ClInclude Include="PLBigEndian.h" />
<ClInclude Include="PLControlDefinitions.h" />
<ClInclude Include="PLCore.h" />
<ClInclude Include="PLDialogs.h" />
<ClInclude Include="PLErrorCodes.h" />
<ClInclude Include="PLFolders.h" />
<ClInclude Include="PLLowMem.h" />
<ClInclude Include="PLMacTypes.h" />
<ClInclude Include="RandomNumberGenerator.h" />
<ClInclude Include="ResourceCompiledRef.h" />
<ClInclude Include="ResourceFile.h" />
<ClInclude Include="PLMenus.h" />
<ClInclude Include="PLNavigation.h" />
<ClInclude Include="PLNumberFormatting.h" />
<ClInclude Include="PLPalettes.h" />
<ClInclude Include="PLPasStr.h" />
<ClInclude Include="PLQDOffscreen.h" />
<ClInclude Include="PLMovies.h" />
<ClInclude Include="PLQuickdraw.h" />
<ClInclude Include="ResourceManager.h" />
<ClInclude Include="PLResources.h" />
<ClInclude Include="PLScript.h" />
<ClInclude Include="PLSound.h" />
<ClInclude Include="PLStringCompare.h" />
<ClInclude Include="PLTextUtils.h" />
<ClInclude Include="PLToolUtils.h" />
<ClInclude Include="ResTypeID.h" />
<ClInclude Include="ResTypeIDCodec.h" />
<ClInclude Include="VirtualDirectory.h" />
<ClInclude Include="RCPtr.h" />
<ClInclude Include="RefCounted.h" />
<ClInclude Include="ScopedArray.h" />
<ClInclude Include="ScopedPtr.h" />
<ClInclude Include="SmallestInt.h" />
<ClInclude Include="UnsafePascalStr.h" />
<ClInclude Include="XModemCRC.h" />
</ItemGroup>
<ItemGroup>
<ClCompile Include="AEManager.cpp" />
<ClCompile Include="BinHex4.cpp" />
<ClCompile Include="ByteSwap.cpp" />
<ClCompile Include="CFileStream.cpp" />
<ClCompile Include="DisplayDeviceManager.cpp" />
<ClCompile Include="FileManager.cpp" />
<ClCompile Include="HostDisplayDriver.cpp" />
<ClCompile Include="HostFileSystem.cpp" />
<ClCompile Include="HostSuspendHook.cpp" />
<ClCompile Include="HostSystemServices.cpp" />
<ClCompile Include="MacBinary2.cpp" />
<ClCompile Include="MacFileInfo.cpp" />
<ClCompile Include="MacFileMem.cpp" />
<ClCompile Include="MemoryManager.cpp" />
<ClCompile Include="MemReaderStream.cpp" />
<ClCompile Include="MMBlock.cpp" />
<ClCompile Include="MMHandleBlock.cpp" />
<ClCompile Include="PLAliases.cpp" />
<ClCompile Include="PLAppleEvents.cpp" />
<ClCompile Include="PLApplication.cpp" />
<ClCompile Include="PLControlDefinitions.cpp" />
<ClCompile Include="PLCore.cpp" />
<ClCompile Include="PLDialogs.cpp" />
<ClCompile Include="PLMenus.cpp" />
<ClCompile Include="PLMovies.cpp" />
<ClCompile Include="PLNavigation.cpp" />
<ClCompile Include="PLNumberFormatting.cpp" />
<ClCompile Include="PLQDOffscreen.cpp" />
<ClCompile Include="PLQuickdraw.cpp" />
<ClCompile Include="PLResourceManager.cpp" />
<ClCompile Include="PLResources.cpp" />
<ClCompile Include="PLSound.cpp" />
<ClCompile Include="PLStringCompare.cpp" />
<ClCompile Include="RandomNumberGenerator.cpp" />
<ClCompile Include="ResourceCompiledRef.cpp" />
<ClCompile Include="ResourceFile.cpp" />
<ClCompile Include="XModemCRC.cpp" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
</Project>

View File

@@ -0,0 +1,351 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
<Filter Include="Source Files">
<UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier>
<Extensions>cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx</Extensions>
</Filter>
<Filter Include="Header Files">
<UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier>
<Extensions>h;hh;hpp;hxx;hm;inl;inc;xsd</Extensions>
</Filter>
<Filter Include="Resource Files">
<UniqueIdentifier>{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}</UniqueIdentifier>
<Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms</Extensions>
</Filter>
</ItemGroup>
<ItemGroup>
<ClInclude Include="RefCounted.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="CFileStream.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="IOStream.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="RCPtr.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="DataTypes.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="XModemCRC.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="MacFileMem.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="MacFileInfo.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="BinHex4.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="ScopedPtr.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="ScopedArray.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="PascalStr.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="SmallestInt.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="ByteUnpack.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="UnsafePascalStr.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="MacRsrcHeader.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="MacRsrcMap.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="MacBinary2.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="BytePack.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="PLApplication.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="PascalStrLiteral.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="PLCore.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="PLMenus.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="PLQDOffscreen.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="PLMovies.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="PLQuickdraw.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="PLMacTypes.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="PLResources.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="PLAppleEvents.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="PLToolUtils.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="PLPasStr.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="PLSound.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="PLNavigation.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="PLNumberFormatting.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="PLDialogs.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="PLAliases.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="PLStringCompare.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="PLTextUtils.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="PLFolders.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="PLScript.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="PLControlDefinitions.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="PLPalettes.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="PLLowMem.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="MemReaderStream.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="HostFileSystem.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="HostMemoryBuffer.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="ResourceFile.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="VirtualDirectory.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="ResourceManager.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="GpAppInterface.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="MemoryManager.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="MMHandleBlock.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="MMBlock.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="DisplayDeviceManager.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="HostDisplayDriver.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="PLAppleEventsCommonTypes.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="AEManager.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="AEHandlerDesc.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="ByteSwap.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="ResTypeID.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="ResTypeIDCodec.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="BinarySearch.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="PLBigEndian.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="MacFileWriteableMem.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="FileManager.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="FilePermission.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="PLErrorCodes.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="HostSystemServices.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="RandomNumberGenerator.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="HostSuspendCallID.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="HostSuspendHook.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="HostSuspendCallArgument.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="ResourceCompiledRef.h">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ClCompile Include="CFileStream.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="XModemCRC.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="BinHex4.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="MacFileMem.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="MacBinary2.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="PLCore.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="PLApplication.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="PLMovies.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="PLResources.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="PLQuickdraw.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="PLSound.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="PLQDOffscreen.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="PLAppleEvents.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="PLAliases.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="PLStringCompare.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="PLMenus.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="PLDialogs.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="PLNavigation.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="PLNumberFormatting.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="PLControlDefinitions.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="PLResourceManager.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="MemReaderStream.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="HostFileSystem.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="ResourceFile.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="MemoryManager.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="MMBlock.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="MMHandleBlock.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="DisplayDeviceManager.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="HostDisplayDriver.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="AEManager.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="ByteSwap.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="FileManager.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="MacFileInfo.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="RandomNumberGenerator.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="HostSystemServices.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="HostSuspendHook.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="ResourceCompiledRef.cpp">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
</Project>

121
PortabilityLayer/RCPtr.h Normal file
View File

@@ -0,0 +1,121 @@
#pragma once
#include "CoreDefs.h"
namespace PortabilityLayer
{
class RefCountedBase;
template<class T>
class RCPtr
{
public:
RCPtr();
RCPtr(T *other);
RCPtr(const RCPtr<T> &other);
#if IS_CPP11
RCPtr(RCPtr<T> &&other);
#endif
~RCPtr();
operator T*() const;
T* operator ->() const;
RCPtr<T> &operator=(T *other);
#if IS_CPP11
RCPtr<T> &operator=(RCPtr<T> &&other);
#endif
T *Get() const;
private:
RefCountedBase *m_target;
};
}
#include "RefCounted.h"
template<class T>
inline PortabilityLayer::RCPtr<T>::RCPtr()
: m_target(nullptr)
{
}
template<class T>
inline PortabilityLayer::RCPtr<T>::RCPtr(const RCPtr<T> &other)
: m_target(other.m_target)
{
if (m_target)
m_target->IncRef();
}
template<class T>
inline PortabilityLayer::RCPtr<T>::RCPtr(T *other)
: m_target(other)
{
if (other)
other->IncRef();
}
#if IS_CPP11
template<class T>
inline PortabilityLayer::RCPtr<T>::RCPtr(RCPtr<T> &&other)
: m_target(other.m_target)
{
other.m_target = nullptr;
}
#endif
template<class T>
inline PortabilityLayer::RCPtr<T>::~RCPtr()
{
if (m_target)
m_target->DecRef();
}
template<class T>
inline T *PortabilityLayer::RCPtr<T>::operator T*() const
{
return m_target;
}
template<class T>
inline T *PortabilityLayer::RCPtr<T>::operator->() const
{
return m_target;
}
template<class T>
inline PortabilityLayer::RCPtr<T>::RCPtr<T> &PortabilityLayer::RCPtr<T>::operator=(T *other)
{
RefCountedBase *old = m_target;
m_target = other;
if (other)
other->IncRef();
if (old)
old->DecRef();
return *this;
}
#if IS_CPP11
template<class T>
inline PortabilityLayer::RCPtr<T>& PortabilityLayer::RCPtr<T>::RCPtr<T> &operator=(RCPtr<TOther> &&other)
{
RefCountedBase *old = m_target;
RefCountedBase *newRC = other.m_target;
other.m_target = nullptr;
m_target = newRC;
if (newRC)
newRC->IncRef();
if (old)
old->DecRef();
return *this;
}
#endif

View File

@@ -0,0 +1,85 @@
#include "RandomNumberGenerator.h"
namespace PortabilityLayer
{
class RandomNumberGeneratorMT19937 final : public RandomNumberGenerator
{
public:
RandomNumberGeneratorMT19937();
void Seed(uint32_t seed) override;
uint32_t GetNextAndAdvance() override;
static RandomNumberGeneratorMT19937 *GetInstance();
private:
static const uint32_t kA = 0x9908b0df;
static const int kW = 32;
static const int kN = 624;
static const int kM = 397;
static const int kR = 31;
static const uint32_t kLowMask = (1 << kR) - 1;
static const uint32_t kHighMask = ~kLowMask;
void Twist();
uint32_t m_state[kN];
int m_index;
static RandomNumberGeneratorMT19937 ms_instance;
};
RandomNumberGeneratorMT19937::RandomNumberGeneratorMT19937()
{
Seed(0x243F6A88); // First 8 hex digits of pi
}
void RandomNumberGeneratorMT19937::Seed(uint32_t seed)
{
m_index = kN;
m_state[0] = seed;
for (unsigned int i = 1; i < kN; i++)
{
const uint32_t prev = m_state[i - 1];
m_state[i] = static_cast<uint32_t>((static_cast<uint64_t>(1812433253) * static_cast<uint64_t>(prev ^ (prev >> 30)) + i) & 0xffffffff);
}
}
uint32_t RandomNumberGeneratorMT19937::GetNextAndAdvance()
{
if (m_index == kN)
Twist();
uint32_t x = m_state[m_index++];
x ^= (x >> 11);
x ^= (x >> 7) & 0x9d2c5680;
x ^= (x << 15) & 0xefc60000;
return x ^ (x >> 18);
}
void RandomNumberGeneratorMT19937::Twist()
{
for (unsigned int i = 0; i < kN; i++)
{
uint32_t x = (m_state[i] & kHighMask) + (m_state[(i + 1) % kN] & kLowMask);
uint32_t xA = x >> 1;
if ((x & 1) == 1)
xA ^= kA;
m_state[i] = m_state[(i + kM) % kN] ^ kA;
}
m_index = 0;
}
RandomNumberGeneratorMT19937 *RandomNumberGeneratorMT19937::GetInstance()
{
return &ms_instance;
}
RandomNumberGeneratorMT19937 RandomNumberGeneratorMT19937::ms_instance;
RandomNumberGenerator* RandomNumberGenerator::GetInstance()
{
return RandomNumberGeneratorMT19937::GetInstance();
}
}

View File

@@ -0,0 +1,19 @@
#pragma once
#ifndef __PL_RANDOM_NUMBER_GENERATOR_H__
#define __PL_RANDOM_NUMBER_GENERATOR_H__
#include <stdint.h>
namespace PortabilityLayer
{
class RandomNumberGenerator
{
public:
virtual void Seed(uint32_t seed) = 0;
virtual uint32_t GetNextAndAdvance() = 0;
static RandomNumberGenerator *GetInstance();
};
}
#endif

View File

@@ -0,0 +1,38 @@
#pragma once
namespace PortabilityLayer
{
class RefCountedBase
{
public:
RefCountedBase();
virtual ~RefCountedBase();
virtual void Release() = 0;
void IncRef();
void DecRef();
private:
unsigned int m_refCount;
};
}
inline PortabilityLayer::RefCountedBase::RefCountedBase()
: m_refCount(0)
{
}
inline PortabilityLayer::RefCountedBase::~RefCountedBase()
{
}
inline void PortabilityLayer::RefCountedBase::IncRef()
{
m_refCount++;
}
inline void PortabilityLayer::RefCountedBase::DecRef()
{
if (--m_refCount == 0)
this->Release();
}

View File

@@ -0,0 +1,68 @@
#pragma once
#ifndef __PL_RES_TYPE_ID_H__
#define __PL_RES_TYPE_ID_H__
#include <stdint.h>
namespace PortabilityLayer
{
class ResTypeID
{
public:
ResTypeID();
ResTypeID(int32_t i);
ResTypeID(const ResTypeID &other);
explicit ResTypeID(const char *chars);
ResTypeID &operator=(const ResTypeID &other);
bool operator==(const ResTypeID &other) const;
bool operator!=(const ResTypeID &other) const;
private:
char m_id[4];
};
}
#include "ResTypeIDCodec.h"
#include <string.h>
namespace PortabilityLayer
{
inline ResTypeID::ResTypeID()
{
m_id[0] = m_id[1] = m_id[2] = m_id[3] = 0;
}
inline ResTypeID::ResTypeID(int32_t i)
{
ResTypeIDCodec::Encode(i, m_id);
}
inline ResTypeID::ResTypeID(const ResTypeID &other)
{
memcpy(m_id, other.m_id, 4);
}
inline ResTypeID::ResTypeID(const char *chars)
{
memcpy(m_id, chars, 4);
}
inline ResTypeID &ResTypeID::operator=(const ResTypeID &other)
{
memcpy(m_id, other.m_id, 4);
return *this;
}
inline bool ResTypeID::operator==(const ResTypeID &other) const
{
return memcmp(m_id, other.m_id, 4) == 0;
}
inline bool ResTypeID::operator!=(const ResTypeID &other) const
{
return memcmp(m_id, other.m_id, 4) != 0;
}
}
#endif

View File

@@ -0,0 +1,70 @@
#pragma once
#ifndef __PL_RES_TYPE_ID_CODEC_H__
#define __PL_RES_TYPE_ID_CODEC_H__
#include <stdint.h>
namespace PortabilityLayer
{
template<int32_t T>
class ResTypeIDCodecResolver
{
};
template<>
class ResTypeIDCodecResolver<0x64636261>
{
public:
static void Encode(int32_t id, char *chars);
static int32_t Decode(char *chars);
};
template<>
class ResTypeIDCodecResolver<0x61626364>
{
public:
static void Encode(int32_t id, char *chars);
static int32_t Decode(char *chars);
};
typedef ResTypeIDCodecResolver<'abcd'> ResTypeIDCodec;
}
namespace PortabilityLayer
{
inline void ResTypeIDCodecResolver<0x64636261>::Encode(int32_t id, char *chars)
{
chars[0] = static_cast<char>((id >> 0) & 0xff);
chars[1] = static_cast<char>((id >> 8) & 0xff);
chars[2] = static_cast<char>((id >> 16) & 0xff);
chars[3] = static_cast<char>((id >> 24) & 0xff);
}
inline int32_t ResTypeIDCodecResolver<0x64636261>::Decode(char *chars)
{
return static_cast<int32_t>(
((chars[0] & 0xff) << 0)
| ((chars[1] & 0xff) << 8)
| ((chars[2] & 0xff) << 16)
| ((chars[3] & 0xff) << 24));
}
inline void ResTypeIDCodecResolver<0x61626364>::Encode(int32_t id, char *chars)
{
chars[0] = static_cast<char>((id >> 24) & 0xff);
chars[1] = static_cast<char>((id >> 16) & 0xff);
chars[2] = static_cast<char>((id >> 8) & 0xff);
chars[3] = static_cast<char>((id >> 0) & 0xff);
}
inline int32_t ResTypeIDCodecResolver<0x61626364>::Decode(char *chars)
{
return static_cast<int32_t>(
((chars[0] & 0xff) << 24)
| ((chars[1] & 0xff) << 16)
| ((chars[2] & 0xff) << 8)
| ((chars[3] & 0xff) << 0));
}
}
#endif

Some files were not shown because too many files have changed in this diff Show More