Add _RelString support, fix the case-sensitive flag in _CmpString

This commit is contained in:
Kelvin Sherlock 2023-09-02 14:50:02 -04:00
parent 6151ca1e87
commit f460696b4f
4 changed files with 69 additions and 2 deletions

View File

@ -835,6 +835,15 @@ namespace ToolBox {
d0 = OS::CmpString(trap); d0 = OS::CmpString(trap);
break; break;
//_RelString [MARKS,CASE]
case 0xa050:
case 0xa250:
case 0xa450:
case 0xa650:
d0 = OS::RelString(trap);
break;
// NewPtr [Sys, Clear] (logicalSize: Size): Ptr; // NewPtr [Sys, Clear] (logicalSize: Size): Ptr;
case 0xa11e: case 0xa11e:
case 0xa31e: case 0xa31e:

View File

@ -800,8 +800,8 @@ namespace OS
* *
*/ */
bool caseSens = trap & (1 << 9); //bool diacSens = trap & (1 << 9); // ignore for now...
//bool diacSens = trap & (1 << 10); // ignore for now... bool caseSens = trap & (1 << 10);
uint32_t aStr = cpuGetAReg(0); uint32_t aStr = cpuGetAReg(0);
uint32_t bStr = cpuGetAReg(1); uint32_t bStr = cpuGetAReg(1);
@ -838,6 +838,55 @@ namespace OS
} }
uint16_t RelString(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 first < second, 1 if first > second
*
*/
//bool diacSens = trap & (1 << 9); // ignore for now...
bool caseSens = trap & (1 << 10);
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 RelString(%s, %s)\n", trap, a.c_str(), b.c_str());
if (aStr == bStr) return 0; // same ptr...
for (uint32_t i = 0; i < std::min(aLen, bLen); ++i) {
unsigned aa = a[i];
unsigned bb = b[i];
if (!caseSens) {
aa = toupper(aa);
bb = toupper(bb);
}
if (aa == bb) continue;
return aa < bb ? -1 : 1;
}
if (aLen == bLen) return 0;
return aLen < bLen ? -1 : 1;
}
#pragma mark - Time Utilities #pragma mark - Time Utilities
time_t UnixToMac(time_t t) time_t UnixToMac(time_t t)

View File

@ -71,6 +71,7 @@ namespace OS
#pragma mark String Utilities #pragma mark String Utilities
uint16_t CmpString(uint16_t trap); uint16_t CmpString(uint16_t trap);
uint16_t RelString(uint16_t trap);
#pragma mark - Time Utilities #pragma mark - Time Utilities

View File

@ -199,6 +199,14 @@ namespace ToolBox {
d0 = OS::SetFPos(trap); d0 = OS::SetFPos(trap);
break; break;
// _RelString [,MARKS, CASE]
case 0xa050:
case 0xa250:
case 0xa450:
case 0xa650:
d0 = OS::RelString(trap);
break;
case 0xa051: case 0xa051:
d0 = OS::ReadXPRam(trap); d0 = OS::ReadXPRam(trap);
break; break;