mirror of
https://github.com/ksherlock/mpw.git
synced 2024-06-06 19:29:45 +00:00
Utility::NewString (for DumpObj)
This commit is contained in:
parent
09b0eb102f
commit
240ac7b898
|
@ -14,6 +14,7 @@ set(TOOLBOX_SRC
|
|||
os_highlevel.cpp
|
||||
qd.cpp
|
||||
sane.cpp
|
||||
utility.cpp
|
||||
)
|
||||
|
||||
|
||||
|
|
|
@ -13,7 +13,7 @@
|
|||
#include "os.h"
|
||||
#include "qd.h"
|
||||
#include "sane.h"
|
||||
|
||||
#include "utility.h"
|
||||
|
||||
// yuck. TST.W d0
|
||||
extern "C" void cpuSetFlagsNZ00NewW(UWO res);
|
||||
|
@ -281,6 +281,12 @@ namespace ToolBox {
|
|||
d0 = SANE::decstr68k(trap);
|
||||
break;
|
||||
|
||||
// utility
|
||||
|
||||
case 0xa906:
|
||||
d0 = Utility::NewString(trap);
|
||||
break;
|
||||
|
||||
default:
|
||||
fprintf(stderr, "Unsupported tool trap: %04x\n", trap);
|
||||
fprintf(stderr, "pc: %08x\n", cpuGetPC());
|
||||
|
|
55
toolbox/utility.cpp
Normal file
55
toolbox/utility.cpp
Normal file
|
@ -0,0 +1,55 @@
|
|||
#include "utility.h"
|
||||
#include "toolbox.h"
|
||||
#include "mm.h"
|
||||
|
||||
#include <cpu/defs.h>
|
||||
#include <cpu/CpuModule.h>
|
||||
#include <cpu/fmem.h>
|
||||
|
||||
#include "stackframe.h"
|
||||
|
||||
using ToolBox::Log;
|
||||
|
||||
namespace Utility {
|
||||
|
||||
|
||||
uint16_t NewString(uint16_t trap)
|
||||
{
|
||||
/*
|
||||
* NewString allocates the specified string as a relocatable object
|
||||
* in the heap and returns a handle to it.
|
||||
*/
|
||||
|
||||
uint32_t theString;
|
||||
uint32_t theHandle;
|
||||
uint32_t sp;
|
||||
uint32_t length = 0;
|
||||
uint32_t d0;
|
||||
|
||||
std::string s;
|
||||
|
||||
sp = StackFrame<4>(theString);
|
||||
|
||||
s = ToolBox::ReadPString(theString);
|
||||
|
||||
Log("%04x NewString(%s)\n", trap, s.c_str());
|
||||
|
||||
length = s.length() + 1;
|
||||
|
||||
// if (length) // always true...
|
||||
{
|
||||
uint32_t ptr;
|
||||
d0 = MM::Native::NewHandle(s.length(), false, theHandle, ptr);
|
||||
|
||||
if (!d0)
|
||||
{
|
||||
ToolBox::WritePString(ptr, s);
|
||||
}
|
||||
}
|
||||
|
||||
ToolReturn<4>(sp, theHandle);
|
||||
return d0;
|
||||
}
|
||||
|
||||
|
||||
}
|
13
toolbox/utility.h
Normal file
13
toolbox/utility.h
Normal file
|
@ -0,0 +1,13 @@
|
|||
#ifndef __mpw_utility_h__
|
||||
#define __mpw_utility_h__
|
||||
|
||||
#include <cstdint>
|
||||
|
||||
namespace Utility
|
||||
{
|
||||
|
||||
uint16_t NewString(uint16_t trap);
|
||||
uint16_t GetString(uint16_t trap);
|
||||
}
|
||||
|
||||
#endif
|
Loading…
Reference in New Issue
Block a user