CmpString (asmiigs - environment compare)

This commit is contained in:
Kelvin Sherlock 2013-02-17 18:08:39 -05:00
parent 4917ca2acc
commit 9564f13d85
4 changed files with 85 additions and 0 deletions

View File

@ -9,6 +9,7 @@
#include <string>
#include <cerrno>
#include <cctype>
#include <algorithm>
#include <sys/xattr.h>
#include <sys/stat.h>
@ -94,6 +95,8 @@ namespace OS
case 'a':
if (ext == "aii") // assembler
return true;
if (ext == "asm")
return true;
break;
case 'c':
@ -474,4 +477,60 @@ namespace OS
}
#pragma mark string utilities
uint16_t CmpString(uint16_t trap)
{
/*
* on entry:
* A0 Pointer to first character of first string
* A1 Pointer to first character of second string
* D0 (high) length of first string
* D0 (low) length of second string
*
* on exit:
* D0 0 if strings equal, 1 if strings not equal.
*
*/
bool caseSens = trap & (1 << 9);
//bool diacSens = trap & (1 << 10); // ignore for now...
uint32_t aStr = cpuGetAReg(0);
uint32_t bStr = cpuGetAReg(1);
uint32_t length = cpuGetDReg(0);
uint32_t aLen = (length >> 16);
uint32_t bLen = (length & 0xffff);
std::string a = ToolBox::ReadString(aStr, aLen);
std::string b = ToolBox::ReadString(bStr, bLen);
Log("%04x CmpString(%s, %s)\n", trap, a.c_str(), b.c_str());
if (aLen != bLen) return 1; // different length...
if (aStr == bStr) return 0; // same ptr...
bool eq;
eq = std::equal(
a.begin(),
a.end(),
b.begin(),
[caseSens](char a, char b){
if (a == b) return true;
if (!caseSens)
{
a = toupper(a);
b = toupper(b);
}
return a == b;
}
);
return eq ? 0 : 1;
}
}

View File

@ -112,6 +112,9 @@ namespace OS
uint16_t GetEOF(uint16_t trap);
uint16_t GetVol(uint16_t trap);
uint16_t CmpString(uint16_t trap);
}
#endif

View File

@ -101,6 +101,14 @@ namespace ToolBox {
d0 = Time::TickCount(trap);
break;
//_CmpString [MARKS,CASE]
case 0xa03c:
case 0xa23c:
case 0xa43c:
case 0xa63c:
d0 = OS::CmpString(trap);
break;
// NewPtr [Sys, Clear] (logicalSize: Size): Ptr;
case 0xa11e:
case 0xa31e:
@ -203,6 +211,18 @@ namespace ToolBox {
return tmp;
}
std::string ReadString(uint32_t address, uint32_t length)
{
std::string tmp;
if (address)
{
tmp.assign((char *)memoryPointer(address), length);
}
return tmp;
}
bool WritePString(uint32_t address, const std::string &s)
{
int length = s.length();

View File

@ -22,6 +22,9 @@ namespace ToolBox
std::string ReadCString(uint32_t address, bool fname = false);
std::string ReadPString(uint32_t address, bool fname = false);
std::string ReadString(uint32_t address, uint32_t length);
bool WritePString(uint32_t address, const std::string &s);
}