mirror of
https://github.com/ksherlock/mpw.git
synced 2024-12-22 15:29:45 +00:00
GetResInfo, LoadResource
This commit is contained in:
parent
75606c72e2
commit
bf5b087514
@ -131,6 +131,7 @@ namespace RM
|
||||
namespace Native
|
||||
{
|
||||
|
||||
// not to be confused with MacOS LoadResource(theHandle)
|
||||
|
||||
template<class FX>
|
||||
uint16_t LoadResource(uint32_t type, uint32_t &theHandle, FX fx)
|
||||
@ -820,6 +821,101 @@ namespace RM
|
||||
return SetResError(::ResError());
|
||||
}
|
||||
|
||||
uint16_t GetResInfo(uint16_t trap)
|
||||
{
|
||||
// PROCEDURE GetResInfo (theResource: Handle;
|
||||
// VAR theID: INTEGER; VAR theType: ResType; VAR name: Str255);
|
||||
|
||||
uint32_t theResource;
|
||||
uint32_t theID;
|
||||
uint32_t theType;
|
||||
uint32_t name;
|
||||
StackFrame<16>(theResource, theID, theType, name);
|
||||
|
||||
Log("%04x GetResInfo(%08x)\n", trap, theResource);
|
||||
|
||||
auto iter = rhandle_map.find(theResource);
|
||||
if (iter == rhandle_map.end())
|
||||
{
|
||||
return SetResError(MacOS::resNotFound);
|
||||
}
|
||||
|
||||
Handle nativeHandle = iter->second;
|
||||
ResID nativeID = 0;
|
||||
ResType nativeType = 0;
|
||||
Str255 nativeName = {0};
|
||||
|
||||
::GetResInfo(nativeHandle, &nativeID, &nativeType, nativeName);
|
||||
|
||||
if (theID) memoryWriteWord(nativeID, theID);
|
||||
if (theType) memoryWriteLong(nativeType, theType);
|
||||
if (name)
|
||||
{
|
||||
std::string sname(nativeName + 1, nativeName + 1 + nativeName[0]);
|
||||
ToolBox::WritePString(name, sname);
|
||||
}
|
||||
|
||||
return SetResError(::ResError());
|
||||
}
|
||||
|
||||
uint16_t LoadResource(uint16_t trap)
|
||||
{
|
||||
// PROCEDURE LoadResource (theResource: Handle);
|
||||
|
||||
// this loads the resource from disk, if not already
|
||||
// loaded. (if purgeable or SetResLoad(false))
|
||||
|
||||
// this needs cooperation with MM to check if
|
||||
// handle was purged.
|
||||
|
||||
OSErr err;
|
||||
uint32_t theResource;
|
||||
|
||||
StackFrame<4>(theResource);
|
||||
|
||||
Log("%04x LoadResource(%08x)\n", trap, theResource);
|
||||
|
||||
auto iter = rhandle_map.find(theResource);
|
||||
if (iter == rhandle_map.end())
|
||||
{
|
||||
return SetResError(MacOS::resNotFound);
|
||||
}
|
||||
|
||||
|
||||
// if it has a size, it's loaded...
|
||||
uint32_t handleSize;
|
||||
err = MM::Native::GetHandleSize(theResource, handleSize);
|
||||
if (err) return SetResError(err);
|
||||
if (handleSize) return SetResError(0);
|
||||
|
||||
// otherwise, load it
|
||||
|
||||
Handle nativeHandle;
|
||||
uint32_t size;
|
||||
|
||||
nativeHandle = iter->second;
|
||||
|
||||
|
||||
::LoadResource(nativeHandle);
|
||||
err = ::ResError();
|
||||
if (err) return SetResError(err); // ?!?!
|
||||
|
||||
|
||||
size = ::GetHandleSize(nativeHandle);
|
||||
|
||||
err = MM::Native::ReallocHandle(theResource, size);
|
||||
if (err) return SetResError(err);
|
||||
|
||||
if (size)
|
||||
{
|
||||
uint32_t ptr = memoryReadLong(theResource);
|
||||
std::memcpy(memoryPointer(ptr), *(void **)nativeHandle, size);
|
||||
}
|
||||
|
||||
return SetResError(0);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
@ -48,6 +48,9 @@ namespace RM
|
||||
uint16_t RemoveResource(uint16_t trap);
|
||||
|
||||
uint16_t GetResourceSizeOnDisk(uint16_t trap);
|
||||
|
||||
uint16_t GetResInfo(uint16_t trap);
|
||||
uint16_t LoadResource(uint16_t trap);
|
||||
}
|
||||
|
||||
|
||||
|
@ -364,6 +364,10 @@ namespace ToolBox {
|
||||
d0 = RM::GetResource(trap);
|
||||
break;
|
||||
|
||||
case 0xa9a2:
|
||||
d0 = RM::LoadResource(trap);
|
||||
break;
|
||||
|
||||
// ReleaseResource (theResource: Handle);
|
||||
case 0xa9a3:
|
||||
d0 = RM::ReleaseResource(trap);
|
||||
@ -381,6 +385,10 @@ namespace ToolBox {
|
||||
d0 = RM::SetResAttrs(trap);
|
||||
break;
|
||||
|
||||
case 0xa9a8:
|
||||
d0 = RM::GetResInfo(trap);
|
||||
break;
|
||||
|
||||
case 0xa9ab:
|
||||
d0 = RM::AddResource(trap);
|
||||
break;
|
||||
|
Loading…
Reference in New Issue
Block a user