cleanup: cleanup2-w5 (gotos, comma conditions, placeholders) #1348
@@ -84,157 +84,139 @@ s32 TMCJPEGDEC_get_byte(u8* dst, TMCCJPEGDecWork* work) {
|
||||
}
|
||||
|
||||
s32 TMCJPEGDEC_get_wbyte(u16* dst, TMCCJPEGDecWork* work) {
|
||||
u8 byte_val;
|
||||
u32 byte_shifted;
|
||||
s32 r;
|
||||
u8 byte;
|
||||
u32 highByte;
|
||||
s32 result;
|
||||
|
||||
u8* cur;
|
||||
u8* end;
|
||||
u8* next;
|
||||
|
||||
if (work->pBufCur >= work->pBufEnd) {
|
||||
if (work->remaining != 0) {
|
||||
r = refillJpegBuffer(work);
|
||||
if (r < 0) {
|
||||
goto br;
|
||||
// MWCC needs the empty else branches to preserve refill branch direction.
|
||||
do {
|
||||
if (work->pBufCur >= work->pBufEnd) {
|
||||
if (work->remaining != 0) {
|
||||
result = refillJpegBuffer(work);
|
||||
if (result < 0) {
|
||||
break;
|
||||
} else {
|
||||
}
|
||||
} else {
|
||||
// This else-branch is load-bearing...
|
||||
// Forces bge instead of blt.
|
||||
result = TMCC_ERROR_UNDERFLOW;
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
r = TMCC_ERROR_UNDERFLOW;
|
||||
goto br;
|
||||
}
|
||||
|
||||
{
|
||||
u8* bufferCursor = work->pBufCur;
|
||||
end = work->pBufEnd;
|
||||
cur = bufferCursor;
|
||||
next = bufferCursor + 1;
|
||||
}
|
||||
|
||||
work->pBufCur = next;
|
||||
byte = *cur;
|
||||
if (next >= end) {
|
||||
if (work->remaining != 0) {
|
||||
result = refillJpegBuffer(work);
|
||||
if (result < 0) {
|
||||
break;
|
||||
} else {
|
||||
}
|
||||
} else {
|
||||
result = TMCC_ERROR_UNDERFLOW;
|
||||
break;
|
||||
}
|
||||
}
|
||||
result = 0;
|
||||
} while (0);
|
||||
highByte = (u32)byte << 8;
|
||||
if (result < 0) {
|
||||
return result;
|
||||
}
|
||||
|
||||
{
|
||||
u8* tmp = work->pBufCur;
|
||||
do {
|
||||
if (work->pBufCur >= work->pBufEnd) {
|
||||
if (work->remaining != 0) {
|
||||
result = refillJpegBuffer(work);
|
||||
if (result < 0) {
|
||||
break;
|
||||
} else {
|
||||
}
|
||||
} else {
|
||||
result = TMCC_ERROR_UNDERFLOW;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
cur = work->pBufCur;
|
||||
end = work->pBufEnd;
|
||||
cur = tmp;
|
||||
next = tmp + 1;
|
||||
}
|
||||
|
||||
work->pBufCur = next;
|
||||
byte_val = *cur;
|
||||
if (next < end) {
|
||||
goto o1;
|
||||
}
|
||||
|
||||
if (work->remaining != 0) {
|
||||
r = refillJpegBuffer(work);
|
||||
if (r >= 0) {
|
||||
goto o1;
|
||||
next = cur + 1;
|
||||
work->pBufCur = next;
|
||||
byte = *cur;
|
||||
if (next >= end) {
|
||||
if (work->remaining != 0) {
|
||||
result = refillJpegBuffer(work);
|
||||
if (result < 0) {
|
||||
break;
|
||||
} else {
|
||||
}
|
||||
} else {
|
||||
result = TMCC_ERROR_UNDERFLOW;
|
||||
break;
|
||||
}
|
||||
}
|
||||
goto br;
|
||||
} else {
|
||||
r = TMCC_ERROR_UNDERFLOW;
|
||||
goto br;
|
||||
}
|
||||
|
||||
o1:
|
||||
r = 0;
|
||||
|
||||
br:
|
||||
byte_shifted = (u32)byte_val << 8;
|
||||
if (r >= 0) {
|
||||
goto p2;
|
||||
}
|
||||
return r;
|
||||
|
||||
p2:
|
||||
if (work->pBufCur < work->pBufEnd) {
|
||||
goto r2;
|
||||
}
|
||||
if (work->remaining != 0) {
|
||||
r = refillJpegBuffer(work);
|
||||
if (r < 0)
|
||||
goto ez;
|
||||
else {
|
||||
// ...
|
||||
}
|
||||
} else {
|
||||
r = TMCC_ERROR_UNDERFLOW;
|
||||
goto ez;
|
||||
}
|
||||
|
||||
r2:
|
||||
cur = work->pBufCur;
|
||||
end = work->pBufEnd;
|
||||
next = cur + 1;
|
||||
work->pBufCur = next;
|
||||
byte_val = *cur;
|
||||
if (next < end) {
|
||||
goto o2;
|
||||
}
|
||||
|
||||
if (work->remaining != 0) {
|
||||
r = refillJpegBuffer(work);
|
||||
if (r < 0)
|
||||
goto ez;
|
||||
else {
|
||||
// ...
|
||||
}
|
||||
} else {
|
||||
r = TMCC_ERROR_UNDERFLOW;
|
||||
goto ez;
|
||||
}
|
||||
|
||||
o2:
|
||||
r = 0;
|
||||
ez:
|
||||
*dst = byte_shifted + byte_val;
|
||||
return r < 0 ? r : 0;
|
||||
result = 0;
|
||||
} while (0);
|
||||
*dst = highByte + byte;
|
||||
return result < 0 ? result : 0;
|
||||
}
|
||||
|
||||
s32 TMCJPEGDEC_get_sbyte(u8* dst, u32 count, TMCCJPEGDecWork* work) {
|
||||
int r = 0;
|
||||
int result = 0;
|
||||
u32 i;
|
||||
u8 byte;
|
||||
u8* cur;
|
||||
|
||||
for (i = 0; i < count; i++) {
|
||||
if (work->pBufCur >= work->pBufEnd) {
|
||||
if (work->remaining != 0) {
|
||||
r = refillJpegBuffer(work);
|
||||
if (r < 0) {
|
||||
goto copy_byte;
|
||||
// MWCC needs the empty else branches to preserve refill branch direction.
|
||||
do {
|
||||
if (work->pBufCur >= work->pBufEnd) {
|
||||
if (work->remaining != 0) {
|
||||
result = refillJpegBuffer(work);
|
||||
if (result < 0) {
|
||||
break;
|
||||
} else {
|
||||
}
|
||||
} else {
|
||||
// This else-branch is load-bearing...
|
||||
// Forces bge instead of blt.
|
||||
result = TMCC_ERROR_UNDERFLOW;
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
r = TMCC_ERROR_UNDERFLOW;
|
||||
goto copy_byte;
|
||||
}
|
||||
}
|
||||
|
||||
cur = work->pBufCur;
|
||||
work->pBufCur += 1;
|
||||
byte = *cur;
|
||||
cur = work->pBufCur;
|
||||
work->pBufCur += 1;
|
||||
byte = *cur;
|
||||
|
||||
if (work->pBufCur < work->pBufEnd) {
|
||||
goto r0;
|
||||
}
|
||||
if (work->remaining != 0) {
|
||||
r = refillJpegBuffer(work);
|
||||
if (r >= 0) {
|
||||
goto r0;
|
||||
if (work->pBufCur >= work->pBufEnd) {
|
||||
if (work->remaining != 0) {
|
||||
result = refillJpegBuffer(work);
|
||||
if (result < 0) {
|
||||
break;
|
||||
} else {
|
||||
}
|
||||
} else {
|
||||
result = TMCC_ERROR_UNDERFLOW;
|
||||
break;
|
||||
}
|
||||
}
|
||||
goto copy_byte;
|
||||
} else {
|
||||
r = TMCC_ERROR_UNDERFLOW;
|
||||
goto copy_byte;
|
||||
}
|
||||
|
||||
r0:
|
||||
r = 0;
|
||||
|
||||
copy_byte:
|
||||
result = 0;
|
||||
} while (0);
|
||||
*dst = byte;
|
||||
dst++;
|
||||
|
||||
if (r < 0)
|
||||
return r;
|
||||
if (result < 0)
|
||||
return result;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
@@ -243,51 +225,41 @@ s32 TMCJPEGDEC_move_ptr(s32 offset, TMCCJPEGDecWork* work) {
|
||||
s32 avail;
|
||||
s32 r;
|
||||
|
||||
if (offset < 0) {
|
||||
goto ng;
|
||||
if (offset >= 0) {
|
||||
while (work->pBufEnd - work->pBufCur <= offset) {
|
||||
avail = work->pBufEnd - work->pBufCur;
|
||||
offset -= avail;
|
||||
if (work->remaining != 0) {
|
||||
r = refillJpegBuffer(work);
|
||||
if (r >= 0) {
|
||||
continue;
|
||||
}
|
||||
return r;
|
||||
} else {
|
||||
return TMCC_ERROR_UNDERFLOW;
|
||||
}
|
||||
}
|
||||
work->pBufCur += offset;
|
||||
if (work->pBufEnd > work->pBufCur) {
|
||||
goto done;
|
||||
}
|
||||
if (work->remaining != 0) {
|
||||
r = refillJpegBuffer(work);
|
||||
if (r >= 0) {
|
||||
goto done;
|
||||
}
|
||||
return r;
|
||||
} else {
|
||||
return TMCC_ERROR_UNDERFLOW;
|
||||
}
|
||||
} else {
|
||||
offset = -offset;
|
||||
if (work->pBufCur - work->pBufStart < offset) {
|
||||
return TMCC_ERROR_UNDERFLOW;
|
||||
}
|
||||
work->pBufCur -= offset;
|
||||
}
|
||||
goto lc;
|
||||
|
||||
lp:
|
||||
offset -= avail;
|
||||
if (work->remaining == 0) {
|
||||
goto er1;
|
||||
}
|
||||
r = refillJpegBuffer(work);
|
||||
if (r >= 0) {
|
||||
goto lc;
|
||||
}
|
||||
return r;
|
||||
er1:
|
||||
return TMCC_ERROR_UNDERFLOW;
|
||||
|
||||
lc:
|
||||
avail = work->pBufEnd - work->pBufCur;
|
||||
if (avail <= offset) {
|
||||
goto lp;
|
||||
}
|
||||
work->pBufCur += offset;
|
||||
if (work->pBufEnd > work->pBufCur) {
|
||||
goto ret0;
|
||||
}
|
||||
if (work->remaining == 0) {
|
||||
goto er2;
|
||||
}
|
||||
r = refillJpegBuffer(work);
|
||||
if (r >= 0) {
|
||||
goto ret0;
|
||||
}
|
||||
return r;
|
||||
er2:
|
||||
return TMCC_ERROR_UNDERFLOW;
|
||||
|
||||
ng:
|
||||
offset = -offset;
|
||||
if (work->pBufCur - work->pBufStart < offset) {
|
||||
return TMCC_ERROR_UNDERFLOW;
|
||||
}
|
||||
work->pBufCur -= offset;
|
||||
ret0:
|
||||
done:
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -314,47 +286,45 @@ s32 TMCJPEGDEC_load_buff(TMCCJPEGDecWork* work) {
|
||||
work->bitBuf = bitBuf;
|
||||
work->bitCount = bitCount;
|
||||
work->pBufCur = cur;
|
||||
goto ret;
|
||||
} else {
|
||||
do {
|
||||
if (work->pBufEnd <= work->pBufCur) {
|
||||
if (work->remaining == 0) {
|
||||
break;
|
||||
}
|
||||
r = refillJpegBufferAfterFF(work);
|
||||
if (r < 0) {
|
||||
return r;
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
u32 bb = work->bitBuf;
|
||||
u8* c = work->pBufCur;
|
||||
u8* next;
|
||||
u8 byte = *c;
|
||||
|
||||
next = c + 1;
|
||||
work->pBufCur = next;
|
||||
work->bitBuf = (bb << 8) + byte;
|
||||
work->bitCount += 8;
|
||||
if (byte == 0xFF) {
|
||||
work->pBufCur = next + 1;
|
||||
}
|
||||
}
|
||||
|
||||
if (work->pBufEnd <= work->pBufCur) {
|
||||
if (work->remaining == 0) {
|
||||
break;
|
||||
}
|
||||
r = refillJpegBufferAfterFF(work);
|
||||
if (r < 0) {
|
||||
return r;
|
||||
}
|
||||
}
|
||||
} while (work->bitCount <= 24);
|
||||
}
|
||||
|
||||
do {
|
||||
if (work->pBufEnd <= work->pBufCur) {
|
||||
if (work->remaining == 0) {
|
||||
break;
|
||||
}
|
||||
r = refillJpegBufferAfterFF(work);
|
||||
if (r < 0) {
|
||||
return r;
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
u32 bb = work->bitBuf;
|
||||
u8* c = work->pBufCur;
|
||||
u8* next;
|
||||
u8 byte = *c;
|
||||
|
||||
next = c + 1;
|
||||
work->pBufCur = next;
|
||||
work->bitBuf = (bb << 8) + byte;
|
||||
work->bitCount += 8;
|
||||
if (byte == 0xFF) {
|
||||
work->pBufCur = next + 1;
|
||||
}
|
||||
}
|
||||
|
||||
if (work->pBufEnd <= work->pBufCur) {
|
||||
if (work->remaining == 0) {
|
||||
break;
|
||||
}
|
||||
r = refillJpegBufferAfterFF(work);
|
||||
if (r < 0) {
|
||||
return r;
|
||||
}
|
||||
}
|
||||
} while (work->bitCount <= 24);
|
||||
|
||||
ret:
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
@@ -35,9 +35,8 @@ size_t strnlen(const char* s, size_t maxlen) {
|
||||
}
|
||||
|
||||
static inline IOSError ipcFree(IOSRpcRequest* rpc) {
|
||||
IOSError ret = IPC_RESULT_OK;
|
||||
iosFree(hid, rpc);
|
||||
return ret;
|
||||
return IPC_RESULT_OK;
|
||||
}
|
||||
|
||||
static inline void __ipcSendRequest() {
|
||||
|
||||
@@ -198,17 +198,16 @@ static void* get_ring_buffer_by_kpad1_style(s32 chan, void* buffer, s32 style) {
|
||||
switch (style) {
|
||||
case WPAD_DEV_CORE:
|
||||
size = 0x2A;
|
||||
goto process;
|
||||
break;
|
||||
case WPAD_DEV_FREESTYLE:
|
||||
size = 0x32;
|
||||
goto process;
|
||||
break;
|
||||
case WPAD_DEV_CLASSIC:
|
||||
size = 0x36;
|
||||
goto process;
|
||||
break;
|
||||
default:
|
||||
return buffer;
|
||||
}
|
||||
process:
|
||||
enabled = OSDisableInterrupts();
|
||||
index = kpad->ringIndex - 1;
|
||||
latest = WPADGetLatestIndexInBuf(chan);
|
||||
@@ -622,6 +621,7 @@ static void read_kpad_acc(KPADInside* kpad, KPADSample* status) {
|
||||
kpad->status.acc_speed = (f32)sqrt(previous.z * previous.z + (previous.x * previous.x + previous.y * previous.y));
|
||||
calc_acc_horizon(kpad);
|
||||
calc_acc_vertical(kpad);
|
||||
// MWCC needs separate format exits to preserve both comparisons.
|
||||
if (status->error == WPAD_ERR_OK && status->device == WPAD_DEV_FREESTYLE) {
|
||||
if (status->dataFormat == WPAD_FMT_FS_BTN_ACC) {
|
||||
goto read_extension_acceleration;
|
||||
@@ -664,7 +664,7 @@ static s8 select_2obj_first(KPADInside* kpad) {
|
||||
object = kpad->dpdState.objects;
|
||||
do {
|
||||
if ((s8)object->metadata.bytes.flags != 0) {
|
||||
goto nextObject;
|
||||
continue;
|
||||
}
|
||||
other = object + 1;
|
||||
do {
|
||||
@@ -676,7 +676,7 @@ static s8 select_2obj_first(KPADInside* kpad) {
|
||||
f32 dot;
|
||||
f32 score;
|
||||
if ((s8)other->metadata.bytes.flags != 0) {
|
||||
goto nextOther;
|
||||
continue;
|
||||
}
|
||||
dx = other->x - object->x;
|
||||
dy = other->y - object->y;
|
||||
@@ -687,7 +687,7 @@ static s8 select_2obj_first(KPADInside* kpad) {
|
||||
direction.y = kpad->horizonTangent.y * dx - kpad->horizonTangent.x * dy;
|
||||
dist = kpad->dpdDistanceScale * scale;
|
||||
if (dist <= kpad->minDpdDistance || dist >= kp_err_dist_max) {
|
||||
goto nextOther;
|
||||
continue;
|
||||
}
|
||||
dot = kpad->horizonAxis.x * direction.x + kpad->horizonAxis.y * direction.y;
|
||||
score = dot;
|
||||
@@ -703,12 +703,8 @@ static s8 select_2obj_first(KPADInside* kpad) {
|
||||
first = object;
|
||||
second = other;
|
||||
}
|
||||
nextOther:
|
||||
++other;
|
||||
} while (other <= kpad->dpdState.objects + 3);
|
||||
nextObject:
|
||||
++object;
|
||||
} while (object < kpad->dpdState.objects + 3);
|
||||
} while (++other <= kpad->dpdState.objects + 3);
|
||||
} while (++object < kpad->dpdState.objects + 3);
|
||||
if (best == kp_err_first_inpr) {
|
||||
return 0;
|
||||
}
|
||||
@@ -726,7 +722,7 @@ static s8 select_2obj_continue(KPADInside* kpad) {
|
||||
object = kpad->dpdState.objects;
|
||||
do {
|
||||
if ((s8)object->metadata.bytes.flags != 0) {
|
||||
goto nextObject;
|
||||
continue;
|
||||
}
|
||||
other = object + 1;
|
||||
do {
|
||||
@@ -738,7 +734,7 @@ static s8 select_2obj_continue(KPADInside* kpad) {
|
||||
f32 dot;
|
||||
BOOL reverse;
|
||||
if ((s8)other->metadata.bytes.flags != 0) {
|
||||
goto nextOther;
|
||||
continue;
|
||||
}
|
||||
dx = other->x - object->x;
|
||||
dy = other->y - object->y;
|
||||
@@ -747,7 +743,7 @@ static s8 select_2obj_continue(KPADInside* kpad) {
|
||||
direction.y = dy * scale;
|
||||
scale *= kpad->dpdDistanceScale;
|
||||
if (scale <= kpad->minDpdDistance || scale >= kp_err_dist_max) {
|
||||
goto nextOther;
|
||||
continue;
|
||||
}
|
||||
scale -= kpad->dpdReferenceDistance;
|
||||
if (scale < 0.0f) {
|
||||
@@ -756,7 +752,7 @@ static s8 select_2obj_continue(KPADInside* kpad) {
|
||||
scale *= kpad->invDistSpeed;
|
||||
}
|
||||
if (scale >= 1.0f) {
|
||||
goto nextOther;
|
||||
continue;
|
||||
}
|
||||
dot = kpad->dpdObjectDirection.x * direction.x + kpad->dpdObjectDirection.y * direction.y;
|
||||
if (dot < 0.0f) {
|
||||
@@ -766,7 +762,7 @@ static s8 select_2obj_continue(KPADInside* kpad) {
|
||||
reverse = FALSE;
|
||||
}
|
||||
if (dot <= kp_err_next_inpr) {
|
||||
goto nextOther;
|
||||
continue;
|
||||
}
|
||||
scale += ((1.0f - dot) / (1.0f - kp_err_next_inpr));
|
||||
if (scale < best) {
|
||||
@@ -779,12 +775,8 @@ static s8 select_2obj_continue(KPADInside* kpad) {
|
||||
second = other;
|
||||
}
|
||||
}
|
||||
nextOther:
|
||||
++other;
|
||||
} while (other <= kpad->dpdState.objects + 3);
|
||||
nextObject:
|
||||
++object;
|
||||
} while (object < kpad->dpdState.objects + 3);
|
||||
} while (++other <= kpad->dpdState.objects + 3);
|
||||
} while (++object < kpad->dpdState.objects + 3);
|
||||
if (2.0f == best) {
|
||||
return 0;
|
||||
}
|
||||
@@ -1092,50 +1084,51 @@ static void read_kpad_dpd(KPADInside* kpad, KPADSample* status) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!(kpad->status.acc_vertical.x <= kp_err_up_inpr)) {
|
||||
if (kpad->status.dpd_valid_fg == 2 || kpad->status.dpd_valid_fg == -2) {
|
||||
if (kpad->dpdCount >= 2) {
|
||||
selected = select_2obj_continue(kpad);
|
||||
if (selected != 0) {
|
||||
goto updateSelection;
|
||||
do {
|
||||
if (!(kpad->status.acc_vertical.x <= kp_err_up_inpr)) {
|
||||
if (kpad->status.dpd_valid_fg == 2 || kpad->status.dpd_valid_fg == -2) {
|
||||
if (kpad->dpdCount >= 2) {
|
||||
selected = select_2obj_continue(kpad);
|
||||
if (selected != 0) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (kpad->dpdCount >= 1) {
|
||||
selected = select_1obj_continue(kpad);
|
||||
if (selected != 0) {
|
||||
goto updateSelection;
|
||||
if (kpad->dpdCount >= 1) {
|
||||
selected = select_1obj_continue(kpad);
|
||||
if (selected != 0) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
} else if (kpad->status.dpd_valid_fg == 1 || kpad->status.dpd_valid_fg == -1) {
|
||||
if (kpad->dpdCount >= 2) {
|
||||
selected = select_2obj_first(kpad);
|
||||
if (selected != 0) {
|
||||
goto updateSelection;
|
||||
} else if (kpad->status.dpd_valid_fg == 1 || kpad->status.dpd_valid_fg == -1) {
|
||||
if (kpad->dpdCount >= 2) {
|
||||
selected = select_2obj_first(kpad);
|
||||
if (selected != 0) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (kpad->dpdCount >= 1) {
|
||||
selected = select_1obj_continue(kpad);
|
||||
if (selected != 0) {
|
||||
goto updateSelection;
|
||||
if (kpad->dpdCount >= 1) {
|
||||
selected = select_1obj_continue(kpad);
|
||||
if (selected != 0) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (kpad->dpdCount >= 2) {
|
||||
selected = select_2obj_first(kpad);
|
||||
if (selected != 0) {
|
||||
goto updateSelection;
|
||||
} else {
|
||||
if (kpad->dpdCount >= 2) {
|
||||
selected = select_2obj_first(kpad);
|
||||
if (selected != 0) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (kpad->dpdCount == 1) {
|
||||
selected = select_1obj_first(kpad);
|
||||
if (selected != 0) {
|
||||
goto updateSelection;
|
||||
if (kpad->dpdCount == 1) {
|
||||
selected = select_1obj_first(kpad);
|
||||
if (selected != 0) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
selected = 0;
|
||||
updateSelection:
|
||||
selected = 0;
|
||||
} while (0);
|
||||
if (selected != 0) {
|
||||
f32 dy;
|
||||
f32 dx;
|
||||
|
||||
@@ -264,18 +264,17 @@ static void CloseCallbackFromReload(s32 result, NANDCommandBlock* block) {
|
||||
static void FinishFromReload() {
|
||||
SCStatus status;
|
||||
|
||||
_openFile:
|
||||
Control.openFileType++;
|
||||
|
||||
if (Control.openFileType < SC_CONF_FILE_MAX) {
|
||||
for (;;) {
|
||||
Control.openFileType++;
|
||||
if (Control.openFileType >= SC_CONF_FILE_MAX) {
|
||||
break;
|
||||
}
|
||||
Control.isFileOpen = FALSE;
|
||||
|
||||
if (NANDPrivateOpenAsync(Control.filePaths[Control.openFileType], &Control.fileInfo, NAND_ACCESS_READ, OpenCallbackFromReload,
|
||||
&Control.commandBlock) == NAND_RESULT_OK) {
|
||||
return;
|
||||
}
|
||||
|
||||
goto _openFile;
|
||||
}
|
||||
|
||||
switch (Control.asyncResult) {
|
||||
@@ -293,7 +292,7 @@ _openFile:
|
||||
}
|
||||
}
|
||||
|
||||
*(u8*)((u8*)OSPhysicalToCached(SC_CONFIG_FILE_PHYS_ADDRESS) + SC_CONFIG_FILE_LENGTH - 1) = '\0';
|
||||
((u8*)OSPhysicalToCached(SC_CONFIG_FILE_PHYS_ADDRESS))[SC_CONFIG_FILE_LENGTH - 1] = '\0';
|
||||
|
||||
if (Control.asyncCallback != NULL) {
|
||||
Control.asyncCallback(Control.asyncResult);
|
||||
@@ -442,6 +441,7 @@ static SCStatus ParseConfBuf(u8* conf, u32 size) {
|
||||
|
||||
// Build lookup table
|
||||
|
||||
// MWCC needs the name load in this loop condition to preserve scheduling.
|
||||
for (tblEnd = &tblIter[ItemIDMaxPlus1]; tblIter < tblEnd && (itName = tblIter->name) != (void*)NULL; tblIter++) {
|
||||
u32 itNameLen = strlen(itName);
|
||||
|
||||
@@ -726,6 +726,7 @@ static BOOL CreateItemByID(SCItemID id, u8 primType, const void* src, u32 len) {
|
||||
|
||||
itemSize += len;
|
||||
|
||||
// MWCC needs the name load in this loop condition to preserve both branches.
|
||||
for (; (itemName = it->name) != (void*)NULL; it++) {
|
||||
if (it->id == id) {
|
||||
break;
|
||||
@@ -1011,6 +1012,7 @@ void SCFlushAsync(SCFlushCallback callback) {
|
||||
static void MyNandCallback(s32 result, NANDCommandBlock* block) {
|
||||
SCControl* ctrl = &Control;
|
||||
|
||||
// MWCC needs shared switch paths to preserve branch layout.
|
||||
switch (ctrl->nandCbState) {
|
||||
case NAND_CB_STATE_GET_STATUS: {
|
||||
if (result == NAND_RESULT_OK && ctrl->fileType == NAND_TYPE_FILE) {
|
||||
@@ -1020,15 +1022,15 @@ static void MyNandCallback(s32 result, NANDCommandBlock* block) {
|
||||
goto _error;
|
||||
}
|
||||
} else {
|
||||
goto _case_1_lbl;
|
||||
goto deleteFile;
|
||||
}
|
||||
return;
|
||||
}
|
||||
case NAND_CB_STATE_DELETE: {
|
||||
if (result == NAND_RESULT_OK && ctrl->fileAttr.permission == NAND_PERM_ALL_RW) {
|
||||
goto _case_5_lbl;
|
||||
goto openFile;
|
||||
}
|
||||
_case_1_lbl:
|
||||
deleteFile:
|
||||
ctrl->nandCbState = NAND_CB_STATE_GET_TYPE;
|
||||
|
||||
if (NANDPrivateDeleteAsync(ConfFileName, MyNandCallback, &ctrl->commandBlock) != NAND_RESULT_OK) {
|
||||
@@ -1045,19 +1047,17 @@ static void MyNandCallback(s32 result, NANDCommandBlock* block) {
|
||||
return;
|
||||
}
|
||||
case NAND_CB_STATE_CREATE_DIR: {
|
||||
if (result == NAND_RESULT_OK && ctrl->fileType == NAND_TYPE_DIR) {
|
||||
goto _case_4_lbl;
|
||||
}
|
||||
if (result != NAND_RESULT_OK || ctrl->fileType != NAND_TYPE_DIR) {
|
||||
ctrl->nandCbState = NAND_CB_STATE_CREATE_FILE;
|
||||
|
||||
ctrl->nandCbState = NAND_CB_STATE_CREATE_FILE;
|
||||
|
||||
if (NANDPrivateCreateDirAsync(ConfDirName, NAND_PERM_ALL_RW, 0, MyNandCallback, &ctrl->commandBlock) != NAND_RESULT_OK) {
|
||||
goto _error;
|
||||
if (NANDPrivateCreateDirAsync(ConfDirName, NAND_PERM_ALL_RW, 0, MyNandCallback, &ctrl->commandBlock) != NAND_RESULT_OK) {
|
||||
goto _error;
|
||||
}
|
||||
return;
|
||||
}
|
||||
return;
|
||||
// FALLTHROUGH
|
||||
}
|
||||
case NAND_CB_STATE_CREATE_FILE: {
|
||||
_case_4_lbl:
|
||||
ctrl->nandCbState = NAND_CB_STATE_OPEN_FILE;
|
||||
if (NANDPrivateCreateAsync(ConfFileName, NAND_PERM_ALL_RW, 0, MyNandCallback, &ctrl->commandBlock) != NAND_RESULT_OK) {
|
||||
goto _error;
|
||||
@@ -1065,7 +1065,7 @@ static void MyNandCallback(s32 result, NANDCommandBlock* block) {
|
||||
return;
|
||||
}
|
||||
case NAND_CB_STATE_OPEN_FILE: {
|
||||
_case_5_lbl:
|
||||
openFile:
|
||||
ctrl->nandCbState = NAND_CB_STATE_WRITE_FILE;
|
||||
if (NANDPrivateOpenAsync(ConfFileName, &ctrl->fileInfo, NAND_ACCESS_WRITE, MyNandCallback, &ctrl->commandBlock) != NAND_RESULT_OK) {
|
||||
goto _error;
|
||||
|
||||
@@ -7,8 +7,6 @@
|
||||
|
||||
#include <string.h>
|
||||
|
||||
#pragma sym on
|
||||
|
||||
#define SD_SLOT_0_PATH "/dev/sdio/slot0"
|
||||
#define SD_SLOT_1_PATH "/dev/sdio/slot1"
|
||||
#define SD_SLOT_W_PATH "/dev/sdio/slotw"
|
||||
@@ -591,27 +589,32 @@ ISD_Error ISD_InitCard() {
|
||||
goto out;
|
||||
}
|
||||
|
||||
if ((__sdCmdBuffer = iosAlloc(__sdHeapId[0], 0x20)) == 0) {
|
||||
__sdCmdBuffer = iosAlloc(__sdHeapId[0], 0x20);
|
||||
if (__sdCmdBuffer == 0) {
|
||||
ret = IPC_RESULT_ALLOC_FAILED;
|
||||
goto out;
|
||||
}
|
||||
|
||||
if ((__sdResp = iosAlloc(__sdHeapId[0], 0x20)) == 0) {
|
||||
__sdResp = iosAlloc(__sdHeapId[0], 0x20);
|
||||
if (__sdResp == 0) {
|
||||
ret = IPC_RESULT_ALLOC_FAILED;
|
||||
goto out;
|
||||
}
|
||||
|
||||
if ((__sdResp2 = iosAlloc(__sdHeapId[0], 0x20)) == 0) {
|
||||
__sdResp2 = iosAlloc(__sdHeapId[0], 0x20);
|
||||
if (__sdResp2 == 0) {
|
||||
ret = IPC_RESULT_ALLOC_FAILED;
|
||||
goto out;
|
||||
}
|
||||
|
||||
if ((__sdReg = iosAlloc(__sdHeapId[0], 0x20)) == 0) {
|
||||
__sdReg = iosAlloc(__sdHeapId[0], 0x20);
|
||||
if (__sdReg == 0) {
|
||||
ret = IPC_RESULT_ALLOC_FAILED;
|
||||
goto out;
|
||||
}
|
||||
|
||||
if ((__sdVect = iosAlloc(__sdHeapId[0], 0x60)) == 0) {
|
||||
__sdVect = iosAlloc(__sdHeapId[0], 0x60);
|
||||
if (__sdVect == 0) {
|
||||
ret = IPC_RESULT_ALLOC_FAILED;
|
||||
goto out;
|
||||
}
|
||||
|
||||
@@ -334,7 +334,8 @@ IOSError IUSB_GetDeviceList(const char* path, USBDeviceInfo* deviceList, u8 maxD
|
||||
rv = IPC_RESULT_INVALID;
|
||||
goto out;
|
||||
}
|
||||
if ((fd = __openDevice(path)) < 0) {
|
||||
fd = __openDevice(path);
|
||||
if (fd < 0) {
|
||||
rv = fd;
|
||||
goto out;
|
||||
}
|
||||
@@ -658,7 +659,8 @@ static void _GetStrCb(IOSError ret, void* ctxt) {
|
||||
buf = (char*)req->msg.buffer;
|
||||
buflen = req->msg.length;
|
||||
USB_LOG("GetStrCb: buf = 0x%x buflen = %u\n", buf, buflen);
|
||||
if ((len = unicode2ascii(buf, buflen)) < 0)
|
||||
len = unicode2ascii(buf, buflen);
|
||||
if (len < 0)
|
||||
USB_ERR("Failed to convert buffer from unicode 2 ascii\n");
|
||||
else
|
||||
buf[len] = '\0';
|
||||
@@ -684,7 +686,8 @@ IOSError IUSB_GetAsciiStr(IOSFd fd, u8 ep, u16 index, u16 langId, char* buf, u16
|
||||
USB_ERR("Failed __CtrlMsg: %d", rv);
|
||||
goto out;
|
||||
}
|
||||
if ((len = unicode2ascii(buf, buflen)) < 0)
|
||||
len = unicode2ascii(buf, buflen);
|
||||
if (len < 0)
|
||||
USB_ERR("Failed to convert unicode 2 ascii\n");
|
||||
else
|
||||
buf[len] = '\0';
|
||||
@@ -912,7 +915,8 @@ IOSError IUSB_DeviceInsertionNotifyAsync(const char* path, u16 vid, u16 pid, USB
|
||||
rv = IPC_RESULT_INVALID;
|
||||
goto done;
|
||||
}
|
||||
if ((fd = IOS_Open(path, 0)) < 0) {
|
||||
fd = IOS_Open(path, 0);
|
||||
if (fd < 0) {
|
||||
rv = fd;
|
||||
USB_ERR("Open(%s) failed\n", path);
|
||||
goto done;
|
||||
@@ -975,7 +979,8 @@ IOSError IUSB_DeviceClassInsertionNotifyAsync(const char* path, u8 devClass, USB
|
||||
rv = IPC_RESULT_INVALID;
|
||||
goto done;
|
||||
}
|
||||
if ((fd = IOS_Open(path, 0)) < 0) {
|
||||
fd = IOS_Open(path, 0);
|
||||
if (fd < 0) {
|
||||
rv = fd;
|
||||
OSReport("Open(%s) failed\n", path);
|
||||
goto done;
|
||||
|
||||
100
tools/decomp-assist/cleanup2-w5.attempts.md
Normal file
100
tools/decomp-assist/cleanup2-w5.attempts.md
Normal file
@@ -0,0 +1,100 @@
|
||||
# cleanup2-w5 SDK and JPEG cleanup
|
||||
|
||||
Branch `agent/w1009/cleanup2-w5`, initial base `85d653b0`.
|
||||
Read cleanup-common.md fully, including wave-2 goto/comma guidance, and the local AGENTS.md.
|
||||
Initial full 43U build passed, all 1028 units and 12563 functions exact and linked.
|
||||
Initial completion checker returned `DECOMPLETE_OK`; DOL SHA1 `26116613f624061ba99c8d1a299aaa6efa85670d`.
|
||||
Owned units: usb, ipcclt, scsystem, sdi_api, KPAD, buffer_system.
|
||||
|
||||
## Method and references
|
||||
|
||||
Rebuild each trial at its real source path. Compare every allocated ELF section and its relocations against fresh baseline objects before retaining a change. Restore each rejected function before the next trial.
|
||||
Preserve SDK shared error and cleanup exits. Existing rx67/rx67b attempts explain USB diagnostic order; do not retry deleting those data owners.
|
||||
Public SDK references downloaded read-only into `/tmp/cleanup2-w5-*.c`:
|
||||
|
||||
- SC: https://github.com/SMGCommunity/Petari/blob/31a44d0a99fe61bcf150b2104db44ea671930ce5/src/RVL_SDK/sc/scsystem.c
|
||||
- SC: https://github.com/doldecomp/ogws/blob/27fa94a593096eed7442efc4e70981fd52025b9c/src/revolution/SC/scsystem.c
|
||||
- IPC and USB: SMGCommunity/Petari source, downloaded from the public master branch.
|
||||
- JPEG word-reader search found no separate public source reference.
|
||||
|
||||
## Compiled trials
|
||||
|
||||
- `kpad-ring-switch-break`: rejected: .rela.text; differing: 0 / 96.
|
||||
- `kpad-select_2obj_first-for-continue`: rejected: .rela.text, .text; differing: 103 / 124.
|
||||
- `kpad-select_2obj_continue-for-continue`: rejected: .rela.text, .text; differing: 119 / 140.
|
||||
- `kpad-acc-structured`: rejected: .rela.text, .text; differing: 197 / 400.
|
||||
- `sc-reload-while`: rejected: .rela.text, .text; differing: 77 / 80.
|
||||
- `sdi-no-symbol-pragma`: retained.
|
||||
- `sdi-ISD_InitCard-separate-allocations`: retained.
|
||||
- `usb-IUSB_GetDeviceList-separate-assignment`: retained.
|
||||
- `usb-_GetStrCb-separate-assignment`: retained.
|
||||
- `usb-IUSB_GetAsciiStr-separate-assignment`: retained.
|
||||
- `usb-IUSB_DeviceInsertionNotifyAsync-separate-assignment`: retained.
|
||||
- `usb-IUSB_DeviceClassInsertionNotifyAsync-separate-assignment`: retained.
|
||||
- `kpad-ring-switch-break-canonical-relocations`: retained.
|
||||
- `kpad-select_2obj_first-nested-guards`: retained.
|
||||
- `kpad-select_2obj_continue-nested-guards`: retained.
|
||||
- `jpeg-move-structured`: rejected: .rela.text, .text; differing: 49 / 57.
|
||||
- `jpeg-load-direct-return`: rejected: .rela.text, .text; differing: 51 / 74.
|
||||
- `kpad-dpd-break-selection`: retained.
|
||||
- `kpad-acc-nested-returns`: rejected: .text; differing: 7 / 400.
|
||||
- `sc-reload-for-loop`: retained.
|
||||
- `sc-flush-state-path-names`: retained.
|
||||
- `ipc-free-remove-redundant-local`: retained.
|
||||
- `kpad-select_2obj_first-sdk-do-continue`: retained.
|
||||
- `kpad-select_2obj_continue-sdk-do-continue`: retained.
|
||||
- `jpeg-load-if-else`: retained.
|
||||
- `jpeg-move-while`: rejected: .rela.text, .text; differing: 39 / 59.
|
||||
- `jpeg-sbyte-break-blocks`: rejected: .rela.text, .text; differing: 34 / 55.
|
||||
- `sc-create-file-fallthrough`: retained.
|
||||
- `kpad-acc-format-switch`: rejected: .rela.text, .text; differing: 197 / 401.
|
||||
- `jpeg-sbyte-inline-public-reader`: rejected: .rela.text, .text; differing: 52 / 55.
|
||||
- `jpeg-word-inline-public-reader`: rejected: .rela.text, .text; differing: 84 / 89.
|
||||
- `jpeg-move-while-success-continue`: retained.
|
||||
- `jpeg-word-direct-error-return`: retained.
|
||||
- `jpeg-word-second-buffer-guard`: retained.
|
||||
- `jpeg-sbyte-one-read-block`: retained.
|
||||
- `jpeg-word-first-read-block`: retained.
|
||||
- `jpeg-word-second-read-block`: retained.
|
||||
- `kpad-acc-format-if-else`: rejected: .rela.text, .text; differing: 195 / 401.
|
||||
- `sc-parse-separate-name-assignment`: COMPILE FAILED.
|
||||
- `sc-create-separate-name-assignment`: rejected: .text; differing: 9 / 158.
|
||||
- `sc-flush-shared-inline-actions`: rejected: .rela.data, .rela.text, .text; differing: 199 / 230.
|
||||
- `jpeg-TMCJPEGDEC_get_wbyte-remove-empty-else`: rejected: .text; differing: 8 / 89.
|
||||
- `jpeg-TMCJPEGDEC_get_sbyte-remove-empty-else`: rejected: .text; differing: 4 / 55.
|
||||
- `sc-parse-separate-name-c89`: rejected: .rela.text, .text; differing: 38 / 147.
|
||||
- `sc-product-terminator-index`: retained.
|
||||
- `sc-loop-spacing`: retained.
|
||||
- `kpad-explain-format-branches`: retained.
|
||||
- `kpad-name-freestyle-format-range`: rejected: .text; differing: 1 / 158.
|
||||
- `jpeg-reader-names-and-compiler-notes`: retained.
|
||||
- `sdi-allocation-spacing`: retained.
|
||||
|
||||
## Retained cleanup and remaining constraints
|
||||
|
||||
- usb.c: split five assignment-in-condition expressions. Preserve public-SDK error/cleanup exits and diagnostic emission order.
|
||||
- ipcclt.c: remove ipcFree's redundant result local. Preserve the public-SDK error/cleanup paths.
|
||||
- scsystem.c: replace the reload goto loop with for/break; replace the create-file jump with switch fallthrough; name the remaining delete/open labels; index the product-info terminator directly. Two shared switch paths remain because inline shared actions changed 199 aligned instructions and relocations. Name-table condition assignments remain because valid separated loads changed 38 and 9 aligned instructions. Each retained constraint has one compiler comment.
|
||||
- sdi_api.c: remove the symbol-debug pragma and split five allocation assignments from their conditions. Preserve shared SDK exits.
|
||||
- KPAD.c: remove 17 gotos with switch break, SDK-style do/continue loops, and a selection block. Petari's select_2obj functions use the same preincrement loop conditions. Two acceleration format branches remain because the valid structured variants changed 7 to 197 aligned instructions; the comment states the compiler constraint. Preserve common finish/callback exits. The wrapped format range remains because replacing it with enum subtraction changed one instruction.
|
||||
- buffer_system.c: remove 26 gotos. Byte and word reads use break blocks, pointer movement uses while/continue, and bit-buffer loading uses if/else. Rename word-reader byte/result locals. Keep the two common-success gotos. Empty else branches remain because deleting them changes 8 word-reader and 4 string-reader instructions; one comment per function explains this.
|
||||
|
||||
The initial ring-switch trial rejected only renamed compiler literal symbols such as @2027. The comparator was corrected to resolve defined relocation symbols to section plus address. The repeated trial preserved every allocated section and relocation destination, and fresh ctxdiff/objdiff confirmed exactness. All rejected source trials were restored; later retained trials may replace an earlier retained form.
|
||||
The first separated ParseConfBuf load failed because its added statement preceded a C89 declaration. The corrected C89 trial compiled and was rejected on byte differences.
|
||||
|
||||
## Final verification
|
||||
|
||||
- Fresh allocated section bytes, sizes and normalized relocation destinations equal the initial full-build objects for all six units.
|
||||
- pool_diff.py: identical in all six units, including all 54 USB, 7 SC and 4 SDI strings.
|
||||
- ctxdiff.py: word reader 89/89, string reader 55/55, pointer movement 57/57, bit-buffer loading 73/73, KPAD first/continue selection 122/122 and 138/138, KPAD DPD reader 278/278, SC reload 79/79 and SC NAND callback 206/206; each has diffs 0.
|
||||
- Final gate --quick over all six units: GATE PASS; full build passed; 0 regressions, 0 forbidden-pattern additions, 0 readability warnings. Output /tmp/cleanup2-w5-final-gate.txt.
|
||||
- Fresh build/43U/report.json and build/43U/ok passed; completion checker returned DECOMPLETE_OK. Global measures equal the fresh pre-cleanup baseline.
|
||||
- Exact functions before/after: USB 13/13, IPC 22/22, SC 30/30, SDI 22/22, KPAD 29/29, JPEG buffer 10/10. All owned sections and link measures remain 100%.
|
||||
- DOL SHA1: 26116613f624061ba99c8d1a299aaa6efa85670d.
|
||||
- Total goto reduction: 45. No push, PR, merge, rebase, header/config edit or other-worktree mutation.
|
||||
- Source commit: libs/RVL_SDK/src/usb/usb.c 3bf4cb1b.
|
||||
- Source commit: libs/RVL_SDK/src/ipc/ipcclt.c 403389a6.
|
||||
- Source commit: libs/RVL_SDK/src/sc/scsystem.c a4ecc152.
|
||||
- Source commit: libs/RVL_SDK/src/sdi/sdi_api.c 4a15421c.
|
||||
- Source commit: libs/RVL_SDK/src/kpad/KPAD.c 7d374d9f.
|
||||
- Source commit: libs/RVLMiddleware/TMC_JPEG/src/buffer/buffer_system.c 342be728.
|
||||
Reference in New Issue
Block a user