Compare commits

...

1 Commits

5 changed files with 390 additions and 145 deletions

View File

@@ -56,14 +56,14 @@ typedef struct KPADDPDObject {
typedef struct KPADInside {
KPADStatus status;
f32 posParamX;
f32 posParamY;
f32 value8C;
f32 value90;
f32 value94;
f32 value98;
f32 value9C;
f32 valueA0;
f32 posPlayRadius;
f32 posSensitivity;
f32 horizonPlayRadius;
f32 horizonSensitivity;
f32 distPlayRadius;
f32 distSensitivity;
f32 accPlayRadius;
f32 accSensitivity;
f32 referenceDistance;
Vec2 accelNormal;
Vec2 horizonTangent;
@@ -87,7 +87,7 @@ typedef struct KPADInside {
Vec2 horizonAxis;
Vec2 horizonCircle;
u16 horizonCircleCount;
u8 value4CA;
u8 dpdValidPairCount;
u16 repeatCount;
u16 repeatCount2;
u16 repeatDelay;
@@ -95,26 +95,26 @@ typedef struct KPADInside {
u16 repeatCurrent;
u16 repeatCurrent2;
KPADCallback dpdCallback;
f32 value4DC;
f32 value4E0;
f32 value4E4;
f32 value4E8;
f32 value4EC;
f32 value4F0;
f32 value4F4;
f32 value4F8;
f32 value4FC;
f32 value500;
f32 value504;
f32 value508;
f32 value50C;
f32 value510;
f32 value514;
f32 accScaleX;
f32 accScaleY;
f32 accScaleZ;
f32 fsAccScaleX;
f32 fsAccScaleY;
f32 fsAccScaleZ;
f32 dpdFrameMinX;
f32 dpdFrameMinY;
f32 dpdFrameMaxX;
f32 dpdFrameMaxY;
f32 invDistSpeed;
f32 negInvDistSpeed;
f32 horizonCircleRadiusSquared;
f32 dpdDistanceScale;
f32 minDpdDistance;
WPADSamplingCallback samplingCallback;
u8 samplingInProgress;
u8 flag51D;
u8 flag51E;
u8 flag51F;
u8 resetPending;
u8 extensionResetPending;
u8 dpdCommandPending;
u8 dpdEnable;
u8 dpdFormat;
u8 dpdCallbackFired;
@@ -261,10 +261,10 @@ void KPADSetBtnRepeat(s32 chan, f32 delay, f32 pulse) {
kpad->repeatCurrent2 = kpad->repeatDelay;
}
void KPADSetPosParam(s32 chan, f32 x, f32 y) {
void KPADSetPosParam(s32 chan, f32 playRadius, f32 sensitivity) {
KPADInside* kpad = &inside_kpads[chan];
kpad->posParamX = x;
kpad->posParamY = y;
kpad->posPlayRadius = playRadius;
kpad->posSensitivity = sensitivity;
}
extern const f32 sensorIntervalConversion;
@@ -291,25 +291,25 @@ static void reset_kpad(KPADInside* kpad) {
lowerY = -0.75f;
upperY = 0.75f;
sensorDistance = kpad->referenceDistance;
kpad->flag51D = 0;
kpad->value4F4 = negativeOne + kp_err_outside_frame;
kpad->value4FC = one - kp_err_outside_frame;
kpad->value4F8 = lowerY + kp_err_outside_frame;
kpad->value500 = upperY - kp_err_outside_frame;
kpad->value504 = one / kp_err_dist_speed;
kpad->value508 = negativeOne / kp_err_dist_speed;
kpad->value50C = kp_ah_circle_radius * kp_ah_circle_radius;
kpad->value514 = kp_err_dist_min;
kpad->resetPending = 0;
kpad->dpdFrameMinX = negativeOne + kp_err_outside_frame;
kpad->dpdFrameMaxX = one - kp_err_outside_frame;
kpad->dpdFrameMinY = lowerY + kp_err_outside_frame;
kpad->dpdFrameMaxY = upperY - kp_err_outside_frame;
kpad->invDistSpeed = one / kp_err_dist_speed;
kpad->negInvDistSpeed = negativeOne / kp_err_dist_speed;
kpad->horizonCircleRadiusSquared = kp_ah_circle_radius * kp_ah_circle_radius;
kpad->minDpdDistance = kp_err_dist_min;
calibratedDistance = kp_dist_vv1;
distanceValue = calibratedDistance / sensorDistance;
kpad->value510 = calibratedDistance;
kpad->dpdDistanceScale = calibratedDistance;
kpad->status.release = 0;
kpad->status.trig = 0;
kpad->status.hold = 0;
kpad->repeatCount = 0;
kpad->repeatCount2 = kpad->repeatDelay;
kpad->status.dpd_valid_fg = 0;
kpad->value4CA = 0;
kpad->dpdValidPairCount = 0;
kpad->status.pos = kpad->status.vec = Vec2_0;
kpad->horizonAxis.x = one;
kpad->horizonAxis.y = zero;
@@ -349,7 +349,7 @@ static void reset_kpad(KPADInside* kpad) {
--object;
} while ((u32)object >= (u32)kpad->dpdState.candidates);
kpad->ringCount = 0;
kpad->flag51E = 1;
kpad->extensionResetPending = 1;
}
void KPADGetProjectionPos(Vec2* dest, Vec2* src, const Rect* rect, f32 scale) {
@@ -515,7 +515,7 @@ static void calc_acc_horizon(KPADInside* kpad) {
circleY = oldCircleY + kp_ah_circle_pw * (unitY - oldCircleY);
deltaCircleY = unitY - circleY;
kpad->horizonCircle.y = circleY;
if (deltaCircleX * deltaCircleX + deltaCircleY * deltaCircleY <= kpad->value50C) {
if (deltaCircleX * deltaCircleX + deltaCircleY * deltaCircleY <= kpad->horizonCircleRadiusSquared) {
if (kpad->horizonCircleCount != 0) {
kpad->horizonCircleCount--;
}
@@ -579,14 +579,14 @@ static inline void smooth_acc_value(KPADInside* kpad, f32 value, f32* result) {
} else {
amount = delta;
}
if (amount >= kpad->value9C) {
if (amount >= kpad->accPlayRadius) {
amount = 1.0f;
} else {
amount /= kpad->value9C;
amount /= kpad->accPlayRadius;
amount *= amount;
amount *= amount;
}
amount *= kpad->valueA0;
amount *= kpad->accSensitivity;
*result += amount * delta;
}
@@ -604,9 +604,9 @@ static void read_kpad_acc(KPADInside* kpad, KPADSample* status) {
default:
return;
}
kpad->acceleration.x = clamp_acc_value((f32)-(s32)status->accX * kpad->value4DC, kp_rm_acc_max);
kpad->acceleration.y = clamp_acc_value((f32)-(s32)status->accZ * kpad->value4E4, kp_rm_acc_max);
kpad->acceleration.z = clamp_acc_value((f32)status->accY * kpad->value4E0, kp_rm_acc_max);
kpad->acceleration.x = clamp_acc_value((f32)-(s32)status->accX * kpad->accScaleX, kp_rm_acc_max);
kpad->acceleration.y = clamp_acc_value((f32)-(s32)status->accZ * kpad->accScaleZ, kp_rm_acc_max);
kpad->acceleration.z = clamp_acc_value((f32)status->accY * kpad->accScaleY, kp_rm_acc_max);
previous = kpad->status.acc;
smooth_acc_value(kpad, kpad->acceleration.x, &kpad->status.acc.x);
smooth_acc_value(kpad, kpad->acceleration.y, &kpad->status.acc.y);
@@ -630,9 +630,9 @@ static void read_kpad_acc(KPADInside* kpad, KPADSample* status) {
read_extension_acceleration:
{
Vec extensionPrevious;
raw.x = clamp_acc_value((f32)-(s32)status->extension.fs.accX * kpad->value4E8, kp_fs_acc_max);
raw.y = clamp_acc_value((f32)-(s32)status->extension.fs.accZ * kpad->value4F0, kp_fs_acc_max);
raw.z = clamp_acc_value((f32)status->extension.fs.accY * kpad->value4EC, kp_fs_acc_max);
raw.x = clamp_acc_value((f32)-(s32)status->extension.fs.accX * kpad->fsAccScaleX, kp_fs_acc_max);
raw.y = clamp_acc_value((f32)-(s32)status->extension.fs.accZ * kpad->fsAccScaleZ, kp_fs_acc_max);
raw.z = clamp_acc_value((f32)status->extension.fs.accY * kpad->fsAccScaleY, kp_fs_acc_max);
if (kpad->freeStyleAccelRotation != 0) {
PSMTXMultVec((const f32 (*)[4])initial_rotation_matrix, &raw, &raw);
}
@@ -681,8 +681,8 @@ static s8 select_2obj_first(KPADInside* kpad) {
dy *= scale;
direction.x = kpad->horizonTangent.x * dx + kpad->horizonTangent.y * dy;
direction.y = kpad->horizonTangent.y * dx - kpad->horizonTangent.x * dy;
dist = kpad->value510 * scale;
if (dist <= kpad->value514 || dist >= kp_err_dist_max) {
dist = kpad->dpdDistanceScale * scale;
if (dist <= kpad->minDpdDistance || dist >= kp_err_dist_max) {
goto nextOther;
}
dot = kpad->horizonAxis.x * direction.x + kpad->horizonAxis.y * direction.y;
@@ -741,15 +741,15 @@ static s8 select_2obj_continue(KPADInside* kpad) {
scale = 1.0f / (f32)sqrt(dx * dx + dy * dy);
direction.x = dx * scale;
direction.y = dy * scale;
scale *= kpad->value510;
if (scale <= kpad->value514 || scale >= kp_err_dist_max) {
scale *= kpad->dpdDistanceScale;
if (scale <= kpad->minDpdDistance || scale >= kp_err_dist_max) {
goto nextOther;
}
scale -= kpad->dpdReferenceDistance;
if (scale < 0.0f) {
scale *= kpad->value508;
scale *= kpad->negInvDistSpeed;
} else {
scale *= kpad->value504;
scale *= kpad->invDistSpeed;
}
if (scale >= 1.0f) {
goto nextOther;
@@ -803,15 +803,15 @@ static s8 select_1obj_first(KPADInside* kpad) {
leftPosition.y = object->y - offsetY;
rightPosition.x = object->x + offsetX;
rightPosition.y = object->y + offsetY;
if (leftPosition.x <= kpad->value4F4 || leftPosition.x >= kpad->value4FC || leftPosition.y <= kpad->value4F8 || leftPosition.y >= kpad->value500) {
if (rightPosition.x > kpad->value4F4 && rightPosition.x < kpad->value4FC && rightPosition.y > kpad->value4F8 && rightPosition.y < kpad->value500) {
if (leftPosition.x <= kpad->dpdFrameMinX || leftPosition.x >= kpad->dpdFrameMaxX || leftPosition.y <= kpad->dpdFrameMinY || leftPosition.y >= kpad->dpdFrameMaxY) {
if (rightPosition.x > kpad->dpdFrameMinX && rightPosition.x < kpad->dpdFrameMaxX && rightPosition.y > kpad->dpdFrameMinY && rightPosition.y < kpad->dpdFrameMaxY) {
kpad->dpdState.candidates[1] = *object;
kpad->dpdState.candidates[0].position = leftPosition;
kpad->dpdState.candidates[0].metadata.bytes.flags = 0;
kpad->dpdState.candidates[0].metadata.bytes.status = -1;
return -1;
}
} else if (rightPosition.x <= kpad->value4F4 || rightPosition.x >= kpad->value4FC || rightPosition.y <= kpad->value4F8 || rightPosition.y >= kpad->value500) {
} else if (rightPosition.x <= kpad->dpdFrameMinX || rightPosition.x >= kpad->dpdFrameMaxX || rightPosition.y <= kpad->dpdFrameMinY || rightPosition.y >= kpad->dpdFrameMaxY) {
kpad->dpdState.candidates[0] = *object;
kpad->dpdState.candidates[1].position = rightPosition;
kpad->dpdState.candidates[1].metadata.bytes.flags = 0;
@@ -919,14 +919,14 @@ static void calc_dpd_variable(KPADInside* kpad, s8 valid) {
delta.x = point.x - kpad->status.horizon.x;
delta.y = point.y - kpad->status.horizon.y;
length = (f32)sqrt(delta.x * delta.x + delta.y * delta.y);
if (length >= kpad->value8C) {
if (length >= kpad->horizonPlayRadius) {
amount = 1.0f;
} else {
amount = length / kpad->value8C;
amount = length / kpad->horizonPlayRadius;
amount *= amount;
amount *= amount;
}
amount *= kpad->value90;
amount *= kpad->horizonSensitivity;
delta.x = kpad->status.horizon.x + amount * delta.x;
delta.y = kpad->status.horizon.y + amount * delta.y;
length = (f32)sqrt(delta.x * delta.x + delta.y * delta.y);
@@ -939,7 +939,7 @@ static void calc_dpd_variable(KPADInside* kpad, s8 valid) {
}
}
{
f32 value = kpad->value510 / kpad->dpdObjectDistance;
f32 value = kpad->dpdDistanceScale / kpad->dpdObjectDistance;
if (kpad->status.dpd_valid_fg == 0) {
kpad->status.dist = value;
kpad->status.dist_vec = 0.0f;
@@ -954,14 +954,14 @@ static void calc_dpd_variable(KPADInside* kpad, s8 valid) {
} else {
magnitude = dx;
}
if (magnitude >= kpad->value94) {
if (magnitude >= kpad->distPlayRadius) {
magnitude = 1.0f;
} else {
magnitude /= kpad->value94;
magnitude /= kpad->distPlayRadius;
magnitude *= magnitude;
magnitude *= magnitude;
}
magnitude *= kpad->value98;
magnitude *= kpad->distSensitivity;
next = magnitude * dx;
kpad->status.dist_vec = next;
if (next < 0.0f) {
@@ -994,14 +994,14 @@ static void calc_dpd_variable(KPADInside* kpad, s8 valid) {
delta.x = point.x - kpad->status.pos.x;
delta.y = point.y - kpad->status.pos.y;
length = (f32)sqrt(delta.x * delta.x + delta.y * delta.y);
if (length >= kpad->posParamX) {
if (length >= kpad->posPlayRadius) {
amount = 1.0f;
} else {
amount = length / kpad->posParamX;
amount = length / kpad->posPlayRadius;
amount *= amount;
amount *= amount;
}
amount *= kpad->posParamY;
amount *= kpad->posSensitivity;
kpad->status.vec.x = amount * delta.x;
kpad->status.vec.y = amount * delta.y;
kpad->status.speed = (f32)sqrt(kpad->status.vec.x * kpad->status.vec.x + kpad->status.vec.y * kpad->status.vec.y);
@@ -1052,8 +1052,8 @@ static void read_kpad_dpd(KPADInside* kpad, KPADSample* status) {
KPADDPDObject* current = last;
for (;;) {
if ((s8)current->metadata.bytes.flags >= 0 &&
(current->x <= kpad->value4F4 || current->x >= kpad->value4FC ||
current->y <= kpad->value4F8 || current->y >= kpad->value500)) {
(current->x <= kpad->dpdFrameMinX || current->x >= kpad->dpdFrameMaxX ||
current->y <= kpad->dpdFrameMinY || current->y >= kpad->dpdFrameMaxY)) {
current->metadata.bytes.flags |= 1;
}
current--;
@@ -1147,7 +1147,7 @@ updateSelection:
dy *= scale;
kpad->dpdObjectDistance = length;
kpad->dpdObjectDirection.x = dx;
kpad->dpdReferenceDistance = kpad->value510 * scale;
kpad->dpdReferenceDistance = kpad->dpdDistanceScale * scale;
kpad->dpdObjectDirection.y = dy;
axisX = kpad->horizonTangent.x * kpad->dpdObjectDirection.x + kpad->horizonTangent.y * kpad->dpdObjectDirection.y;
axisY = kpad->horizonTangent.y * kpad->dpdObjectDirection.x - kpad->horizonTangent.x * kpad->dpdObjectDirection.y;
@@ -1159,16 +1159,16 @@ updateSelection:
kpad->dpdState.candidates[0].metadata.bytes.flags = 1;
}
if (kpad->status.dpd_valid_fg == 2 && selected == 2) {
if (kpad->value4CA == 0xC8) {
if (kpad->dpdValidPairCount == 0xC8) {
kpad->dpdObjectScale = kpad->dpdObjectDistance;
} else {
kpad->value4CA++;
kpad->dpdValidPairCount++;
}
} else {
kpad->value4CA = 0;
kpad->dpdValidPairCount = 0;
}
} else {
kpad->value4CA = 0;
kpad->dpdValidPairCount = 0;
}
calc_dpd_variable(kpad, selected);
}
@@ -1258,8 +1258,8 @@ static void read_kpad_stick(KPADInside* kpad, KPADSample* status) {
if (device == 1) {
format = status->dataFormat;
if ((u8)(format + 0xFD) <= 2) {
if (kpad->flag51E != 0) {
kpad->flag51E = 0;
if (kpad->extensionResetPending != 0) {
kpad->extensionResetPending = 0;
extension->fs.stick = Vec2_0;
extension->fs.acc.z = 0.0f;
extension->fs.acc.x = 0.0f;
@@ -1276,8 +1276,8 @@ static void read_kpad_stick(KPADInside* kpad, KPADSample* status) {
if ((u8)(format + 0xFA) > 2) {
return;
}
if (kpad->flag51E != 0) {
kpad->flag51E = 0;
if (kpad->extensionResetPending != 0) {
kpad->extensionResetPending = 0;
extension->cl.lstick = Vec2_0;
extension->cl.rstick = Vec2_0;
extension->cl.rtrigger = 0.0f;
@@ -1349,10 +1349,10 @@ s32 KPADRead(s32 chan, KPADStatus* statuses, u32 count) {
kpad->dpdCallback(chan, 1);
kpad->dpdCallbackFired = 0;
}
kpad->flag51F = 0;
kpad->dpdCommandPending = 0;
}
OSRestoreInterrupts(interruptState);
if (kpad->flag51D != 0) {
if (kpad->resetPending != 0) {
kpad->status.wpad_err = probe;
reset_kpad(kpad);
}
@@ -1392,23 +1392,23 @@ s32 KPADRead(s32 chan, KPADStatus* statuses, u32 count) {
WPADAccGravityUnit extensionGravity = {1, 1, 1};
WPADGetAccGravityUnit(chan, WPAD_ACC_GRAVITY_UNIT_CORE, &gravity);
if (gravity.x * gravity.y * gravity.z != 0) {
kpad->value4DC = 1.0f / gravity.x;
kpad->value4E0 = 1.0f / gravity.y;
kpad->value4E4 = 1.0f / gravity.z;
kpad->accScaleX = 1.0f / gravity.x;
kpad->accScaleY = 1.0f / gravity.y;
kpad->accScaleZ = 1.0f / gravity.z;
} else {
kpad->value4DC = 0.01f;
kpad->value4E0 = 0.01f;
kpad->value4E4 = 0.01f;
kpad->accScaleX = 0.01f;
kpad->accScaleY = 0.01f;
kpad->accScaleZ = 0.01f;
}
WPADGetAccGravityUnit(chan, WPAD_ACC_GRAVITY_UNIT_FS, &extensionGravity);
if (extensionGravity.x * extensionGravity.y * extensionGravity.z != 0) {
kpad->value4E8 = 1.0f / extensionGravity.x;
kpad->value4EC = 1.0f / extensionGravity.y;
kpad->value4F0 = 1.0f / extensionGravity.z;
kpad->fsAccScaleX = 1.0f / extensionGravity.x;
kpad->fsAccScaleY = 1.0f / extensionGravity.y;
kpad->fsAccScaleZ = 1.0f / extensionGravity.z;
} else {
kpad->value4E8 = 0.005f;
kpad->value4EC = 0.005f;
kpad->value4F0 = 0.005f;
kpad->fsAccScaleX = 0.005f;
kpad->fsAccScaleY = 0.005f;
kpad->fsAccScaleZ = 0.005f;
}
remainingSamples = available;
output = statuses + available;
@@ -1477,7 +1477,7 @@ s32 KPADRead(s32 chan, KPADStatus* statuses, u32 count) {
kpad->status.wpad_err = sample->error;
if (kpad->status.dev_type != sample->device && (u8)(sample->error + 2) <= 2) {
kpad->status.dev_type = sample->device;
kpad->flag51E = 1;
kpad->extensionResetPending = 1;
}
kpad->status.data_format = sample->dataFormat;
switch (sample->error) {
@@ -1549,14 +1549,14 @@ void KPADInit(void) {
}
referenceWidth = referenceWidth < referenceHeight ? referenceWidth : referenceHeight;
kpad->sensorBarScale = sensorDistance / referenceWidth;
kpad->value9C = zero;
kpad->value94 = zero;
kpad->value8C = zero;
kpad->posParamX = zero;
kpad->valueA0 = one;
kpad->value98 = one;
kpad->value90 = one;
kpad->posParamY = one;
kpad->accPlayRadius = zero;
kpad->distPlayRadius = zero;
kpad->horizonPlayRadius = zero;
kpad->posPlayRadius = zero;
kpad->accSensitivity = one;
kpad->distSensitivity = one;
kpad->horizonSensitivity = one;
kpad->posSensitivity = one;
kpad->repeatDelay = 40000;
kpad->repeatInterval = 0;
kpad->repeatCount = 0;
@@ -1607,7 +1607,7 @@ void KPADInit(void) {
WPADControlMotor(chan, 0);
}
chan--;
kpad->flag51D = 1;
kpad->resetPending = 1;
kpad--;
} while (chan >= 0);
OSRegisterVersion(__KPADVersion);
@@ -1709,8 +1709,8 @@ static void KPADiSamplingCallback(s32 chan) {
kpad->dpdCallback(chan, 0);
kpad->dpdCallbackPending = 0;
}
if (kpad->flag51F == 0) {
kpad->flag51F = 1;
if (kpad->dpdCommandPending == 0) {
kpad->dpdCommandPending = 1;
if (WPADControlDpd(chan, dpdModeTable[tableIndex], KPADiControlDpdCallback) == 0) {
kpad->dpdFormat = dpdModeTable[tableIndex];
}
@@ -1732,5 +1732,5 @@ static void KPADiControlDpdCallback(s32 chan, s32 result) {
kpad->dpdCallback(chan, 1);
kpad->dpdCallbackFired = 0;
}
kpad->flag51F = 0;
kpad->dpdCommandPending = 0;
}

View File

@@ -4,7 +4,7 @@
#include <private/cdb/CDBAttr.h>
#include <private/cdb/CDBBridge.h>
#include <revolution/types.h>
#ifdef CDB_RECORD_IMPLEMENTATION
#if defined(CDB_RECORD_IMPLEMENTATION) || defined(CDB_SYSTEM_IMPLEMENTATION)
#include <revolution/os.h>
#endif
@@ -13,7 +13,7 @@ extern "C" {
#endif // __cplusplus
typedef struct _CDBRecordFile {
#ifdef CDB_RECORD_IMPLEMENTATION
#if defined(CDB_RECORD_IMPLEMENTATION) || defined(CDB_SYSTEM_IMPLEMENTATION)
OSMutex mutex;
BOOL used;
#else
@@ -24,7 +24,7 @@ typedef struct _CDBRecordFile {
CDBBridgeFile bridgeFile; // 0x42C
u8 unk_0x434[0x438 - 0x434];
CDBRecordKey key; // 0x438
#ifdef CDB_RECORD_IMPLEMENTATION
#if defined(CDB_RECORD_IMPLEMENTATION) || defined(CDB_SYSTEM_IMPLEMENTATION)
u32 database;
u8 reserved[0x480 - 0x46C];
#else

View File

@@ -1,3 +1,4 @@
#define CDB_SYSTEM_IMPLEMENTATION
#include <private/cdb.h>
#include <revolution/cdb.h>
@@ -11,9 +12,9 @@
typedef struct {
u32 used;
u8 padding[0xC00C];
u8 state[0xC00C];
u32 flags;
u32 unk;
u32 database;
} CDBDatabaseInstanceWork;
static OSMutex s_mutex;
@@ -69,9 +70,9 @@ void CDBRecordPoolInit(void* work) {
s_recordPool = (u8*)work + 0x18030;
for (i = 0; i < 5; i++) {
*(u32*)(s_recordPool + i * 0x470 + 0x18) = 0;
((CDBRecordFile*)(s_recordPool + i * 0x470))->used = 0;
if (!s_mutexInitialized) {
OSInitMutex((OSMutex*)(s_recordPool + i * 0x470));
OSInitMutex(&((CDBRecordFile*)(s_recordPool + i * 0x470))->mutex);
}
}
}
@@ -150,8 +151,8 @@ CDBErr CDBDatabaseFree(CDBDatabase* database) {
OSLockMutex(&s_mutex);
for (i = 0, offset = 0; i < 5; i++, offset += 0x470) {
if (CDBRecordInstanceIsUsed(s_recordPool + offset) &&
*(CDBDatabase**)(s_recordPool + offset + 0x468) == database) {
CDBReportError("can't close database; record %s is opened\n", s_recordPool + offset + 0x438);
(CDBDatabase*)((CDBRecordFile*)(s_recordPool + offset))->database == database) {
CDBReportError("can't close database; record %s is opened\n", ((CDBRecordFile*)(s_recordPool + offset))->key.keyString);
hasOpenRecord = TRUE;
}
}
@@ -193,7 +194,7 @@ CDBErr CDBDatabaseCheckOpenRecord() {
OSLockMutex(&s_mutex);
for (i = 0, offset = 0; i < 5; i++, offset += 0x470) {
if (CDBRecordInstanceIsUsed(s_recordPool + offset)) {
CDBReportError("record %s is opened\n", s_recordPool + offset + 0x438);
CDBReportError("record %s is opened\n", ((CDBRecordFile*)(s_recordPool + offset))->key.keyString);
hasOpenRecord = TRUE;
}
}
@@ -210,7 +211,7 @@ CDBErr CDBRecordAllocate(CDBRecord* record, int flag) {
int writeFlag;
int offset;
int i;
CDBDatabaseInstanceWork* databaseInstance = ((CDBDatabase*)*(CDBDatabase**)record)->instance;
CDBDatabaseInstanceWork* databaseInstance = ((CDBDatabase*)record->database)->instance;
OSLockMutex(&s_mutex);
if (databaseInstance == NULL) {
@@ -228,9 +229,9 @@ CDBErr CDBRecordAllocate(CDBRecord* record, int flag) {
writeFlag = flag & CDB_RECORD_ALLOC_WRITE;
for (i = 0, offset = 0; i < 5; i++, offset += 0x470) {
if (CDBRecordInstanceIsUsed(s_recordPool + offset) &&
CDBRecordKeyCompare(&record->key, (CDBRecordKey*)(s_recordPool + offset + 0x438)) == FALSE &&
*(s32*)((u8*)record + 0x30) == *(s32*)(s_recordPool + offset + 0x460)) {
if ((*(u32*)(s_recordPool + offset + 0x1c) & CDB_RECORD_ALLOC_WRITE) != 0) {
CDBRecordKeyCompare(&record->key, &((CDBRecordFile*)(s_recordPool + offset))->key) == FALSE &&
record->key.location == ((CDBRecordFile*)(s_recordPool + offset))->key.location) {
if ((((CDBRecordFile*)(s_recordPool + offset))->allocFlag & CDB_RECORD_ALLOC_WRITE) != 0) {
CDBReportError("can't open the record as WRITE mode; another record discripter opened the record as WRITE mode\n");
OSUnlockMutex(&s_mutex);
return 0x19;
@@ -262,9 +263,9 @@ CDBErr CDBRecordFree(CDBRecord* record) {
CDBRecordFile* recordFile = record->file;
OSLockMutex(&s_mutex);
OSLockMutex((OSMutex*)recordFile);
*(u32*)&recordFile->unk_0x00[0x18] = 0;
OSUnlockMutex((OSMutex*)recordFile);
OSLockMutex(&recordFile->mutex);
recordFile->used = 0;
OSUnlockMutex(&recordFile->mutex);
recordFile->allocFlag = 0;
record->file = NULL;
OSUnlockMutex(&s_mutex);

View File

@@ -182,9 +182,9 @@ pf_s32 VFiPFENT_LoadLFNEntryFieldsFromBuf(PF_DIR_ENT* p_ent, const pf_u8* buf, p
pf_u8 check_sum;
pf_u32 is_first;
pf_u32 is_last_LFN_ent;
pf_u8* p;
pf_u16* q;
pf_u16* q_after;
pf_u8* nameSegment;
pf_u16* nameChar;
pf_u16* nameEnd;
is_first = 1;
is_last_LFN_ent = 0;
@@ -224,27 +224,27 @@ pf_s32 VFiPFENT_LoadLFNEntryFieldsFromBuf(PF_DIR_ENT* p_ent, const pf_u8* buf, p
}
p_ent->ordinal = ordinal;
p_ent->check_sum = check_sum;
p = (pf_u8*)p_ent->long_name;
p += (ordinal - 1) * 0x1A;
VFipf_memcpy(&p[0x0], (pf_s8*)&buf[0x1], 10);
VFipf_memcpy(&p[10], (pf_s8*)&buf[0xE], 0xC);
VFipf_memcpy(&p[0x16], (pf_s8*)&buf[0x1C], 4U);
VFiPF_LE16_TO_U16_STR(&p[0x0], 10);
VFiPF_LE16_TO_U16_STR(&p[10], 0xC);
VFiPF_LE16_TO_U16_STR(&p[0x16], 4U);
nameSegment = (pf_u8*)p_ent->long_name;
nameSegment += (ordinal - 1) * 0x1A;
VFipf_memcpy(&nameSegment[0x0], (pf_s8*)&buf[0x1], 10);
VFipf_memcpy(&nameSegment[10], (pf_s8*)&buf[0xE], 0xC);
VFipf_memcpy(&nameSegment[0x16], (pf_s8*)&buf[0x1C], 4U);
VFiPF_LE16_TO_U16_STR(&nameSegment[0x0], 10);
VFiPF_LE16_TO_U16_STR(&nameSegment[10], 0xC);
VFiPF_LE16_TO_U16_STR(&nameSegment[0x16], 4U);
if (is_last_LFN_ent != 0) {
*(pf_u16*)(p + 0x1A) = 0;
q = (pf_u16*)p;
q_after = (pf_u16*)&p[0x1A];
for (; q < q_after; q++) {
if (*q == 0) {
q++;
((pf_u16*)nameSegment)[13] = 0;
nameChar = (pf_u16*)nameSegment;
nameEnd = (pf_u16*)&nameSegment[0x1A];
for (; nameChar < nameEnd; nameChar++) {
if (*nameChar == 0) {
nameChar++;
break;
}
}
for (; q < q_after; q++) {
if (*q != 0xFFFF) {
for (; nameChar < nameEnd; nameChar++) {
if (*nameChar != 0xFFFF) {
p_ent->num_entry_LFNs = 0;
return 33;
}

View File

@@ -0,0 +1,244 @@
# rx27 readability evidence
Base: `efa1859f6cc1a36c7a40c74427c6f026a4eeee3f`, branch `agent/w1005/rx27`.
Readability-only task: preserve every unit's code, data, exact-function count,
and linked DOL. The generic matching-round requirement for additional exact
functions does not apply to identifier renames.
## Ownership
`src/channelScript/CHANSVm.c` is both listed in scope and explicitly protected
by task rule 3. The explicit protection wins. Its 18 placeholder occurrences
remain, 15 `unk` and 3 `unk0`. There are no `unk_`, `var_`, `field_`, or `valueNN` tokens in that file.
No protected source or cross-worktree file is edited.
There is no separate private KPAD header in this checkout. `KPADInside` is
private to `KPAD.c`; the public `revolution/kpad.h` supplies `KPADStatus` and is
unchanged. A whole-tree search of `src`, `libs`, and `include` found the renamed
KPAD fields only in the owned `KPAD.c`.
## KPAD names
Evidence: `/mnt/drive2/projects/wii-ipl-workers/_refs/prior/SMGCommunity_Petari__KPAD.c`,
the public `KPADStatus` fields, and the matching accesses in this checkout.
The reference is an older SDK, so names are mapped by use and field order;
its entire private layout is not substituted. Existing scalar field types,
order, anonymous unions, declarations, and expressions stay intact.
- `posParamX` -> `posPlayRadius`: KPADSetPosParam play_radius in the SMG reference; divisor and threshold for status.pos deltas.
- `posParamY` -> `posSensitivity`: KPADSetPosParam sensitivity in the SMG reference; gain applied to status.pos deltas.
- `value8C` -> `horizonPlayRadius`: SMG hori_play_radius; threshold and divisor of status.horizon delta length.
- `value90` -> `horizonSensitivity`: SMG hori_sensitivity; gain applied before normalizing status.horizon.
- `value94` -> `distPlayRadius`: SMG dist_play_radius; threshold and divisor of status.dist delta magnitude.
- `value98` -> `distSensitivity`: SMG dist_sensitivity; gain applied to status.dist_vec.
- `value9C` -> `accPlayRadius`: SMG acc_play_radius; threshold and divisor in calc_acc.
- `valueA0` -> `accSensitivity`: SMG acc_sensitivity; gain applied in calc_acc.
- `value4CA` -> `dpdValidPairCount`: SMG dpd_valid2_ct; saturates at 200 consecutive samples with two valid DPD objects.
- `value4DC` -> `accScaleX`: 1 / WPADGetAccGravityUnit CORE gravity.x, multiplied by raw accX.
- `value4E0` -> `accScaleY`: 1 / WPADGetAccGravityUnit CORE gravity.y, multiplied by raw accY.
- `value4E4` -> `accScaleZ`: 1 / WPADGetAccGravityUnit CORE gravity.z, multiplied by raw accZ.
- `value4E8` -> `fsAccScaleX`: 1 / WPADGetAccGravityUnit FS gravity.x, multiplied by extension.fs.accX.
- `value4EC` -> `fsAccScaleY`: 1 / WPADGetAccGravityUnit FS gravity.y, multiplied by extension.fs.accY.
- `value4F0` -> `fsAccScaleZ`: 1 / WPADGetAccGravityUnit FS gravity.z, multiplied by extension.fs.accZ.
- `value4F4` -> `dpdFrameMinX`: SMG kobj_frame_min.x; -1 + kp_err_outside_frame and lower x rejection bound.
- `value4F8` -> `dpdFrameMinY`: SMG kobj_frame_min.y; -0.75 + kp_err_outside_frame and lower y rejection bound.
- `value4FC` -> `dpdFrameMaxX`: SMG kobj_frame_max.x; 1 - kp_err_outside_frame and upper x rejection bound.
- `value500` -> `dpdFrameMaxY`: SMG kobj_frame_max.y; 0.75 - kp_err_outside_frame and upper y rejection bound.
- `value504` -> `invDistSpeed`: SMG err_dist_speed_1; 1 / kp_err_dist_speed scales positive distance changes.
- `value508` -> `negInvDistSpeed`: SMG err_dist_speedM_1; -1 / kp_err_dist_speed scales negative distance changes.
- `value50C` -> `horizonCircleRadiusSquared`: SMG ah_circle_radius2; kp_ah_circle_radius squared and squared-distance comparison.
- `value510` -> `dpdDistanceScale`: SMG dist_vv1; kp_dist_vv1 divided by DPD-object spacing to recover distance.
- `value514` -> `minDpdDistance`: SMG err_dist_min; initialized from kp_err_dist_min and rejects distances at or below it.
- `flag51D` -> `resetPending`: SMG resetReq; set by KPADInit, tested by KPADRead, cleared by reset_kpad.
- `flag51E` -> `extensionResetPending`: SMG exResetReq; resets FreeStyle or Classic extension status in read_kpad_stick.
- `flag51F` -> `dpdCommandPending`: guards WPADControlDpd submission; cleared by KPADiControlDpdCallback or disconnection.
- `KPADSetPosParam` parameters `x`/`y` -> `playRadius`/`sensitivity`: the same
reference setter names these as the positional filter radius and gain.
## Baseline
Fresh 43U quick gate: `GATE PASS`, zero regressions, zero added forbidden or
readability patterns, DOL SHA1 `26116613f624061ba99c8d1a299aaa6efa85670d`.
The baseline report and all 1027 compiled-object SHA256 values were captured
under `/tmp/rx27-baseline` before edits. The final clean gate passed.
## CDB members
The existing private `CDBRecordFile` names are exposed to `CDBSystem.c` with
`CDB_SYSTEM_IMPLEMENTATION`. The header uses the same declarations already
used by `CDBRecord.c`. Other translation units retain their original view.
No struct size, member order, pool stride, variable type, or declaration order
is changed. The pool remains a byte pointer with its existing 0x470 stride;
this round does not change the existing 0x480 private record-file view.
| Original access | Member | Evidence |
| --- | --- | --- |
| record-pool + 0x00 | `mutex` | `OSMutex` is 0x18 bytes; `CDBRecordInstanceInit` locks this prefix |
| record-pool + 0x18 | `used` | `CDBRecordInstanceInit` sets this flag; `CDBRecordInstanceIsUsed` returns it |
| record-pool + 0x1C | `allocFlag` | initialized from allocation flags and tested against `CDB_RECORD_ALLOC_WRITE` |
| record-pool + 0x438 | `key` / `key.keyString` | `CDBRecordInstanceInit` copies `record->key`; key comparator and `%s` reports consume it |
| record-pool + 0x460 | `key.location` | `CDBRecordKey.location` is at 0x28 within `key` |
| record-pool + 0x468 | `database` | `CDBRecordInstanceInit` copies `record->database` here |
| record + 0x00 | `database` | public record declaration and `CDBRecordInitDescriptor` |
| record + 0x30 | `key.location` | public key starts at 0x08, location at 0x28 |
| `CDBDatabaseInstanceWork.unk` | `database` | sibling `CDBDatabaseState.database` at 0xC014; `CDBDatabaseInstanceInit` assigns the descriptor |
| `CDBDatabaseInstanceWork.padding` | `state` | sibling `CDBDatabaseState.state` at 0x04 has the same 0xC00C extent |
## Raw-buffer audit and trials
- `OSFont.c:Decode` reads the on-disk Yay0 header: decompressed length at
0x04, link-table offset at 0x08, literal-stream offset at 0x0C. `GetFontSize`
checks the Yay signature and reads the same length. The other cast reads a
variable-position mask word. These are big-endian serialized data accesses,
not accesses to an opaque in-memory object. Retained under the task's explicit
file-header exception. No existing Yay0 struct appears in the matching headers.
- `rvl_dec.c` reads Yaz/ASH serialized headers and variable-position bitstream
words. The ASH workspace accesses address 16-bit Huffman-tree nodes and a
shared stack in an existing byte array; they are not hidden object members.
Its assembly uses the same 0x7FE/0x1FFE tree strides. All listed C casts are
in non-MWCC fallback branches; the accepted 43U output comes from the existing
assembly paths. Retained: inventing a struct or changing `work` would violate
the requested type/layout/expression freeze, and the 43U gate could not
validate the excluded fallback code. No assembly is added or changed.
- `pf_entry.c` uses `p` as a byte cursor into `PF_DIR_ENT.long_name`. Each LFN
entry contributes 13 UTF-16 code units, assembled from 10 + 12 + 4 bytes.
The +0x1A store terminates the following code unit; it is an array index,
not a distinct struct field.
| Trial | Result |
| --- | --- |
| KPAD evidence-backed field and parameter renames | Entire object byte-identical to baseline; pool identical |
| CDB existing private members and database-state names | All sections except `.strtab` byte-identical; `.strtab` only renumbers compiler `@NNNN` local symbols; pool identical; allocation/free ctxdiff 0 |
| LFN `p_ent->long_name[ordinal * 13] = 0` | Rejected: 135 instructions versus 136, extra live ordinal and changed registers/prologue |
| LFN `((pf_u16*)p)[13] = 0` | Accepted: entire object byte-identical; 136/136 instructions, ctxdiff 0 |
- LFN locals `p` -> `nameSegment`, `q` -> `nameChar`, `q_after` -> `nameEnd`:
the source assigns the first cursor from `long_name` plus the LFN ordinal,
then uses the other two to scan UTF-16 code units for the terminator and
validate 0xFFFF fill. Their types and declaration order are unchanged.
The accepted array access uses the existing cursor into `long_name` and
preserves the store width and address. It does not invent a segment struct.
## Placeholder counts
Counts are identifier-token occurrences, including declarations and uses.
Pattern: `unk`, numbered/underscored `unk`, `var_`, `field_`, hexadecimal
`valueNN` and `flagNN`. Distinct names are shown separately.
| File | Occurrences before -> after | Distinct names before -> after |
| --- | --- | --- |
| `libs/RVL_SDK/src/kpad/KPAD.c` | 110 -> 0 | 25 -> 0 |
| `libs/RVL_SDK/src/os/OSFont.c` | 0 -> 0 | 0 -> 0 |
| `libs/RevoEX/src/cdb/CDBSystem.c` | 2 -> 0 | 2 -> 0 |
| `libs/RevoEX/src/vf/fatfs/pf_entry.c` | 0 -> 0 | 0 -> 0 |
| `src/system/rvl_dec.c` | 0 -> 0 | 0 -> 0 |
| `src/channelScript/CHANSVm.c` | 18 -> 18 | 2 -> 2 |
| `libs/RVL_SDK/include/revolution/kpad.h` | 0 -> 0 | 0 -> 0 |
| `libs/RevoEX/include/private/cdb/CDBRecord.h` | 4 -> 4 | 4 -> 4 |
The CDB header's existing legacy views and unrelated gap remain unchanged.
Only its existing `mutex`, `used`, and `database` declarations are made visible
to the owned unit. There are no unrenamed placeholder references in CDBSystem.
Raw `*(T*)(base + offset)` accesses removed: CDBSystem 5 expressions on
4 lines, plus its `unk_0x00` access and raw key/mutex accesses; pf_entry 1.
OSFont's 5 and rvl_dec's 19 matching lines are retained for the reasons above.
The full raw-access audit includes the nested ASH header offset and dynamic
Huffman-table accesses, not only casts whose base explicitly spells `u8*`.
## Final clean gate
Command run from the owned worktree, without `--quick`:
```sh
python3 /mnt/drive2/projects/wii-ipl-workers/_restore0928-tools/gate.py \
libs/RVL_SDK/src/kpad/KPAD libs/RevoEX/src/cdb/CDBSystem \
libs/RevoEX/src/vf/fatfs/pf_entry libs/RVL_SDK/src/os/OSFont src/system/rvl_dec
```
```text
full build: ok
main.dol sha1: 26116613f624061ba99c8d1a299aaa6efa85670d
[libs/RVL_SDK/src/kpad/KPAD] pool: IDENTICAL
[libs/RVL_SDK/src/kpad/KPAD] objdiff: code 13056/13056 data 8032/8032 functions 29/29 fuzzy 100.0000 linked code 13056
[libs/RVL_SDK/src/kpad/KPAD] instruction-exact functions: 29/29
[libs/RVL_SDK/src/kpad/KPAD] section .bss size 7680 match 100.0
[libs/RVL_SDK/src/kpad/KPAD] section .data size 88 match 100.0
[libs/RVL_SDK/src/kpad/KPAD] section .sbss size 32 match 100.0
[libs/RVL_SDK/src/kpad/KPAD] section .sdata size 112 match 100.0
[libs/RVL_SDK/src/kpad/KPAD] section .sdata2 size 120 match 100.0
[libs/RVL_SDK/src/kpad/KPAD] section .text size 13056 match 100.0
[libs/RVL_SDK/src/kpad/KPAD] baseline: code 13056/13056 data 8032 functions 29 fuzzy 100.0000
[libs/RevoEX/src/cdb/CDBSystem] pool: IDENTICAL
[libs/RevoEX/src/cdb/CDBSystem] objdiff: code 5076/5076 data 1464/1464 functions 36/36 fuzzy 100.0000 linked code 5076
[libs/RevoEX/src/cdb/CDBSystem] instruction-exact functions: 36/36
[libs/RevoEX/src/cdb/CDBSystem] section .bss size 96 match 100.0
[libs/RevoEX/src/cdb/CDBSystem] section .data size 1312 match 100.0
[libs/RevoEX/src/cdb/CDBSystem] section .sbss size 32 match 100.0
[libs/RevoEX/src/cdb/CDBSystem] section .sdata size 24 match 100.0
[libs/RevoEX/src/cdb/CDBSystem] section .text size 5076 match 100.0
[libs/RevoEX/src/cdb/CDBSystem] baseline: code 5076/5076 data 1464 functions 36 fuzzy 100.0000
[libs/RevoEX/src/vf/fatfs/pf_entry] pool: IDENTICAL
[libs/RevoEX/src/vf/fatfs/pf_entry] objdiff: code 7152/7152 data 24/24 functions 22/22 fuzzy 100.0000 linked code 7152
[libs/RevoEX/src/vf/fatfs/pf_entry] instruction-exact functions: 22/22
[libs/RevoEX/src/vf/fatfs/pf_entry] section .data size 16 match 100.0
[libs/RevoEX/src/vf/fatfs/pf_entry] section .sdata2 size 8 match 100.0
[libs/RevoEX/src/vf/fatfs/pf_entry] section .text size 7152 match 100.0
[libs/RevoEX/src/vf/fatfs/pf_entry] baseline: code 7152/7152 data 24 functions 22 fuzzy 100.0000
[libs/RVL_SDK/src/os/OSFont] pool: IDENTICAL
[libs/RVL_SDK/src/os/OSFont] objdiff: code 3356/3356 data 2864/2864 functions 9/9 fuzzy 100.0000 linked code 3356
[libs/RVL_SDK/src/os/OSFont] instruction-exact functions: 9/9
[libs/RVL_SDK/src/os/OSFont] section .data size 2832 match 100.0
[libs/RVL_SDK/src/os/OSFont] section .sbss size 16 match 100.0
[libs/RVL_SDK/src/os/OSFont] section .sdata size 8 match 100.0
[libs/RVL_SDK/src/os/OSFont] section .sdata2 size 8 match 100.0
[libs/RVL_SDK/src/os/OSFont] section .text size 3356 match 100.0
[libs/RVL_SDK/src/os/OSFont] baseline: code 3356/3356 data 2864 functions 9 fuzzy 100.0000
[src/system/rvl_dec] pool: IDENTICAL
[src/system/rvl_dec] objdiff: code 2600/2600 data 36872/36872 functions 4/4 fuzzy 100.0000 linked code 2600
[src/system/rvl_dec] instruction-exact functions: 4/4
[src/system/rvl_dec] section .bss size 36872 match 100.0
[src/system/rvl_dec] section .text size 2600 match 100.0
[src/system/rvl_dec] baseline: code 2600/2600 data 36872 functions 4 fuzzy 100.0000
regressions vs baseline: 0
global matched_code_percent: 93.68224 -> 93.68224
global fuzzy_match_percent: 99.79766 -> 99.79766
global complete_code_percent: 79.26653 -> 79.26653
global matched_data_percent: 99.99410 -> 99.99410
forbidden patterns added (net, per file): 0
readability warnings (net, per file; must be 0 in the final result): 0
GATE PASS
```
All 87 functions in the three touched units were exact before and remain
exact. Matched code stays 25,284 bytes; matched data stays 9,520 bytes. Including
the unchanged OSFont and rvl_dec audit units gives 100 exact functions,
31,240 matched code bytes and 49,256 matched data bytes before and after.
There are no remaining non-matching functions in these five units, so no
matching experiments or three-attempt exhaustion claims are needed.
## Independent preservation check
Compared the clean rebuild with the fresh pre-edit snapshot, then reran
`pool_diff.py` and exact-name `ctxdiff.py` for all 100 functions in the five
audited units. The snapshot report comparison checks every unit and every
function, including size and fuzzy score. Result:
```text
Objects: 1026/1027 whole objects byte-identical; CDBSystem differs only in compiler local-symbol names
CDBSystem: identical section headers, code, data, relocations and symbol entries; 19 @NNNN name changes
Reports: all 1027 units retain exactly the baseline measures, function sizes and fuzzy scores
libs/RVL_SDK/src/kpad/KPAD POOL IDENTICAL up to 0 (mine=0 base=0)
libs/RVL_SDK/src/kpad/KPAD ctxdiff zero for all 29 exact-name functions
libs/RevoEX/src/cdb/CDBSystem POOL IDENTICAL up to 27 (mine=27 base=27)
libs/RevoEX/src/cdb/CDBSystem ctxdiff zero for all 36 exact-name functions
libs/RevoEX/src/vf/fatfs/pf_entry POOL IDENTICAL up to 1 (mine=1 base=1)
libs/RevoEX/src/vf/fatfs/pf_entry ctxdiff zero for all 22 exact-name functions
libs/RVL_SDK/src/os/OSFont POOL IDENTICAL up to 0 (mine=0 base=0)
libs/RVL_SDK/src/os/OSFont ctxdiff zero for all 9 exact-name functions
src/system/rvl_dec POOL IDENTICAL up to 0 (mine=0 base=0)
src/system/rvl_dec ctxdiff zero for all 4 exact-name functions
DOL SHA1: 26116613f624061ba99c8d1a299aaa6efa85670d
Independent byte/metric/pool/ctxdiff verification: PASS
```