GetXResource -> Native::GetResource

This commit is contained in:
Kelvin Sherlock 2013-03-26 23:54:08 -04:00
parent 240ac7b898
commit a95efd9e3f
2 changed files with 57 additions and 38 deletions

View File

@ -64,15 +64,25 @@ namespace
return std::string(tmp); return std::string(tmp);
} }
uint32_t GetXResource(uint32_t type, uint16_t id)
}
namespace RM
{
namespace Native
{
uint16_t GetResource(uint32_t type, uint16_t id, uint32_t &theHandle)
{ {
uint32_t handle;
uint32_t ptr; uint32_t ptr;
uint16_t error; uint16_t error;
Handle nativeHandle; Handle nativeHandle;
uint32_t size; uint32_t size;
theHandle = 0;
switch (type) switch (type)
{ {
case 0x76657273: // 'vers'; case 0x76657273: // 'vers';
@ -83,27 +93,28 @@ namespace
case 0x72547970: // rTyp (rezIIgs) case 0x72547970: // rTyp (rezIIgs)
break; break;
default: default:
return 0; return SetResError(resNotFound);
} }
nativeHandle = ::Get1Resource(type, id); nativeHandle = ::Get1Resource(type, id);
if (!nativeHandle) return 0; if (!nativeHandle) return SetResError(resNotFound);
size = ::GetHandleSize(nativeHandle); size = ::GetHandleSize(nativeHandle);
error = MM::Native::NewHandle(size, false, handle, ptr); error = MM::Native::NewHandle(size, false, theHandle, ptr);
if (!handle) return 0; if (!theHandle)
{
::ReleaseResource(nativeHandle);
return error;
}
std::memcpy(memoryPointer(ptr), *(void **)nativeHandle, size); std::memcpy(memoryPointer(ptr), *(void **)nativeHandle, size);
::ReleaseResource(nativeHandle); ::ReleaseResource(nativeHandle);
return handle; return 0;
} }
}
}
namespace RM
{
uint16_t CloseResFile(uint16_t trap) uint16_t CloseResFile(uint16_t trap)
{ {
@ -172,6 +183,7 @@ namespace RM
uint32_t sp; uint32_t sp;
uint32_t theType; uint32_t theType;
uint16_t theID; uint16_t theID;
uint32_t d0;
uint32_t resourceHandle; uint32_t resourceHandle;
@ -180,10 +192,10 @@ namespace RM
Log("%04x GetResource(%08x ('%s'), %04x)\n", trap, theType, TypeToString(theType).c_str(), theID); Log("%04x GetResource(%08x ('%s'), %04x)\n", trap, theType, TypeToString(theType).c_str(), theID);
resourceHandle = GetXResource(theType, theID); d0 = Native::GetResource(theType, theID, resourceHandle);
ToolReturn<4>(sp, resourceHandle); ToolReturn<4>(sp, resourceHandle);
return SetResError(resourceHandle ? 0 : resNotFound); return d0;
} }
@ -209,16 +221,17 @@ namespace RM
uint16_t theID; uint16_t theID;
uint32_t resourceHandle; uint32_t resourceHandle;
uint32_t d0;
sp = StackFrame<6>(theType, theID); sp = StackFrame<6>(theType, theID);
Log("%04x Get1Resource(%08x ('%s'), %04x)\n", trap, theType, TypeToString(theType).c_str(), theID); Log("%04x Get1Resource(%08x ('%s'), %04x)\n", trap, theType, TypeToString(theType).c_str(), theID);
resourceHandle = GetXResource(theType, theID); d0 = Native::GetResource(theType, theID, resourceHandle);
ToolReturn<4>(sp, resourceHandle); ToolReturn<4>(sp, resourceHandle);
return SetResError(resourceHandle ? 0 : resNotFound); return d0;
} }

View File

@ -5,6 +5,12 @@
namespace RM namespace RM
{ {
namespace Native
{
uint16_t GetResource(uint32_t type, uint16_t id, uint32_t &theHandle);
}
uint16_t CloseResFile(uint16_t trap); uint16_t CloseResFile(uint16_t trap);
uint16_t GetNamedResource(uint16_t trap); uint16_t GetNamedResource(uint16_t trap);
uint16_t Get1NamedResource(uint16_t trap); uint16_t Get1NamedResource(uint16_t trap);