mirror of
https://github.com/ksherlock/mpw.git
synced 2024-06-14 11:29:28 +00:00
FSpOpenResFile support
This commit is contained in:
parent
240a3ac480
commit
8257050afc
|
@ -48,6 +48,7 @@
|
|||
#include <macos/errors.h>
|
||||
|
||||
#include "os.h"
|
||||
#include "rm.h"
|
||||
#include "os_internal.h"
|
||||
#include "toolbox.h"
|
||||
#include "stackframe.h"
|
||||
|
@ -222,6 +223,7 @@ namespace OS {
|
|||
|
||||
|
||||
|
||||
|
||||
uint16_t ResolveAliasFile()
|
||||
{
|
||||
uint32_t spec;
|
||||
|
@ -262,6 +264,24 @@ namespace OS {
|
|||
uint16_t HighLevelHFSDispatch(uint16_t trap)
|
||||
{
|
||||
|
||||
/*
|
||||
* $0001 FSMakeFSSpec
|
||||
* $0002 FSpOpenDF
|
||||
* $0003 FSpOpenRF
|
||||
* $0004 FSpCreate
|
||||
* $0005 FSpDirCreate
|
||||
* $0006 FSpDelete
|
||||
* $0007 FSpGetFInfo
|
||||
* $0008 FSpSetFInfo
|
||||
* $0009 FSpSetFLock
|
||||
* $000A FSpRstFLock
|
||||
* $000B FSpRename
|
||||
* $000C FSpCatMove
|
||||
* $000D FSpOpenResFile
|
||||
* $000E FSpCreateResFile
|
||||
* $000F FSpExchangeFiles
|
||||
*/
|
||||
|
||||
uint16_t selector;
|
||||
|
||||
selector = cpuGetDReg(0) & 0xffff;
|
||||
|
@ -281,6 +301,9 @@ namespace OS {
|
|||
return FSpSetFInfo();
|
||||
break;
|
||||
|
||||
case 0x000d:
|
||||
return RM::FSpOpenResFile();
|
||||
|
||||
default:
|
||||
fprintf(stderr, "selector %04x not yet supported\n", selector);
|
||||
exit(1);
|
||||
|
|
|
@ -43,6 +43,7 @@
|
|||
|
||||
#include <macos/sysequ.h>
|
||||
#include <macos/errors.h>
|
||||
#include <macos/tool_return.h>
|
||||
|
||||
#include "stackframe.h"
|
||||
#include "fs_spec.h"
|
||||
|
@ -51,6 +52,8 @@ using ToolBox::Log;
|
|||
using namespace OS::Internal;
|
||||
using namespace ToolBox;
|
||||
|
||||
using MacOS::tool_return;
|
||||
|
||||
namespace
|
||||
{
|
||||
|
||||
|
@ -101,6 +104,8 @@ namespace
|
|||
case 0x434f4445: // 'CODE' (Link)
|
||||
case 0x5041434b: // 'PACK' (PascalIIgs)
|
||||
case 0x4b4f4445: // 'KODE' (Link 32-bit Startup)
|
||||
case 0x45525253: // 'ERRS' (PPCLink)
|
||||
case 0x63667267: // 'cfrg' (PPCLink)
|
||||
return true;
|
||||
default:
|
||||
return false;
|
||||
|
@ -453,6 +458,32 @@ namespace RM
|
|||
}
|
||||
|
||||
|
||||
tool_return<int16_t> OpenResCommon(const std::string &path, uint16_t permission = 0)
|
||||
{
|
||||
OSErr error;
|
||||
FSRef ref;
|
||||
ResFileRefNum refNum;
|
||||
|
||||
error = ::FSPathMakeRef( (const UInt8 *)path.c_str(), &ref, NULL);
|
||||
if (error != noErr)
|
||||
return (MacOS::macos_error)error;
|
||||
|
||||
HFSUniStr255 fork = {0,{0}};
|
||||
::FSGetResourceForkName(&fork);
|
||||
|
||||
refNum = -1;
|
||||
error = ::FSOpenResourceFile(&ref,
|
||||
fork.length,
|
||||
fork.unicode,
|
||||
permission,
|
||||
&refNum);
|
||||
|
||||
if (error != noErr)
|
||||
return (MacOS::macos_error)error;
|
||||
|
||||
return refNum;
|
||||
}
|
||||
|
||||
uint16_t OpenResFile(uint16_t trap)
|
||||
{
|
||||
// OpenResFile (fileName: Str255) : INTEGER;
|
||||
|
@ -552,6 +583,32 @@ namespace RM
|
|||
return SetResError(0);
|
||||
}
|
||||
|
||||
uint16_t FSpOpenResFile(void)
|
||||
{
|
||||
// FUNCTION FSpOpenResFile (spec: FSSpec; permission: SignedByte): Integer;
|
||||
|
||||
uint32_t sp;
|
||||
uint32_t spec;
|
||||
uint16_t permission;
|
||||
|
||||
sp = StackFrame<6>(spec, permission);
|
||||
|
||||
|
||||
int parentID = memoryReadLong(spec + 2);
|
||||
|
||||
std::string sname = ToolBox::ReadPString(spec + 6, false);
|
||||
sname = OS::FSSpecManager::ExpandPath(sname, parentID);
|
||||
|
||||
Log(" FSpOpenResFile(%s, %04x)\n", sname.c_str(), permission);
|
||||
|
||||
|
||||
auto rv = OpenResCommon(sname, permission);
|
||||
|
||||
ToolReturn<2>(sp, rv.value_or(-1));
|
||||
|
||||
return SetResError(rv.error());
|
||||
}
|
||||
|
||||
|
||||
uint16_t OpenRFPerm(uint16_t trap)
|
||||
{
|
||||
|
|
|
@ -57,6 +57,8 @@ namespace RM
|
|||
uint16_t Get1IndType(uint16_t trap);
|
||||
|
||||
|
||||
uint16_t FSpOpenResFile(void);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user