Skip to content

Commit ea01978

Browse files
authored
Merge pull request #746 from uyjulian/sio2man_changes_28032025
sio2man changes 28032025
2 parents d303cd9 + fe8fcb1 commit ea01978

File tree

2 files changed

+58
-32
lines changed

2 files changed

+58
-32
lines changed

iop/system/sio2man/src/exports.tab

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ DECLARE_EXPORT(sio2_data_in)
153153
DECLARE_EXPORT(sio2_stat_set)
154154
DECLARE_EXPORT(sio2_stat_get)
155155
DECLARE_EXPORT(sio2_pad_transfer_init_possiblysdk13x) // originally sio2_pad_transfer_init
156-
DECLARE_EXPORT(sio2_pad_transfer_init_possiblysdk13x) // originally sio2_mc_transfer_init
156+
DECLARE_EXPORT(sio2_mc_transfer_init_possiblysdk13x) // originally sio2_mc_transfer_init
157157
DECLARE_EXPORT(sio2_transfer)
158158
DECLARE_EXPORT(sio2_transfer_reset)
159159
DECLARE_EXPORT(sio2_ctrl_set2)

iop/system/sio2man/src/sio2man.c

Lines changed: 57 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,8 @@ struct sio2man_internal_data
4040
int m_intr_sema;
4141
int m_transfer_semaphore;
4242
// Unofficial: backwards compatibility for libraries using 1.3 SDK
43-
int m_sdk13x_flag;
43+
int m_sdk13x_curflag;
44+
int m_sdk13x_totalflag;
4445
sio2_mtap_change_slot_cb_t m_mtap_change_slot_cb;
4546
sio2_mtap_get_slot_max_cb_t m_mtap_get_slot_max_cb;
4647
sio2_mtap_get_slot_max2_cb_t m_mtap_get_slot_max2_cb;
@@ -311,12 +312,14 @@ int _start(int ac, char **av)
311312
if ( g_sio2man_data.m_inited )
312313
return 1;
313314
g_sio2man_data.m_inited = 1;
314-
g_sio2man_data.m_sdk13x_flag = 0;
315+
g_sio2man_data.m_sdk13x_curflag = 0;
316+
g_sio2man_data.m_sdk13x_totalflag = 3;
315317
// Unofficial: remove unneeded thread priority argument handler
316-
g_sio2man_data.m_mtap_change_slot_cb = 0;
317-
g_sio2man_data.m_mtap_get_slot_max_cb = 0;
318-
g_sio2man_data.m_mtap_get_slot_max2_cb = 0;
319-
g_sio2man_data.m_mtap_update_slots_cb = 0;
318+
// Unofficial: use setters instead of setting variable directly
319+
sio2_mtap_change_slot_set(NULL);
320+
sio2_mtap_get_slot_max_set(NULL);
321+
sio2_mtap_get_slot_max2_set(NULL);
322+
sio2_mtap_update_slots_set(NULL);
320323
// Unofficial: inlined
321324
sio2_ctrl_set(0x3BC);
322325
CpuSuspendIntr(&state);
@@ -408,7 +411,7 @@ int sio2_transfer(sio2_transfer_data_t *td)
408411
sio2_set_ctrl_1();
409412
sio2_wait_for_intr();
410413
recv_td(td);
411-
if ( g_sio2man_data.m_sdk13x_flag )
414+
if ( g_sio2man_data.m_sdk13x_curflag )
412415
sio2_transfer_reset();
413416
#ifdef SIO2LOG
414417
log_flush(0);
@@ -425,73 +428,96 @@ void sio2_pad_transfer_init(void)
425428
#ifdef SIO2LOG
426429
log_default(LOG_PAD_READY);
427430
#endif
428-
g_sio2man_data.m_sdk13x_flag = 0;
431+
g_sio2man_data.m_sdk13x_curflag = 0;
429432
}
430433

431434
void sio2_pad_transfer_init_possiblysdk13x(void)
432435
{
433436
sio2_pad_transfer_init();
434-
g_sio2man_data.m_sdk13x_flag = 1;
437+
g_sio2man_data.m_sdk13x_curflag |= g_sio2man_data.m_sdk13x_totalflag & 1;
438+
}
439+
440+
void sio2_mc_transfer_init_possiblysdk13x(void)
441+
{
442+
sio2_pad_transfer_init();
443+
g_sio2man_data.m_sdk13x_curflag |= g_sio2man_data.m_sdk13x_totalflag & 2;
435444
}
436445

437446
void sio2_transfer_reset(void)
438447
{
439-
g_sio2man_data.m_sdk13x_flag = 0;
448+
g_sio2man_data.m_sdk13x_curflag = 0;
440449
SignalSema(g_sio2man_data.m_transfer_semaphore);
441450
#ifdef SIO2LOG
442451
log_default(LOG_RESET);
443452
#endif
444453
}
445454

455+
static int sio2_mtap_change_slot_default(s32 *arg)
456+
{
457+
int sum;
458+
int i;
459+
460+
sum = 0;
461+
for ( i = 0; i < 4; i += 1 )
462+
{
463+
arg[i + 4] = ((arg[i] + 1) < 2);
464+
sum += arg[i + 4];
465+
}
466+
return sum == 4;
467+
}
468+
469+
static int sio2_mtap_get_slot_max_default(int port)
470+
{
471+
return 1;
472+
}
473+
474+
static void sio2_mtap_update_slots_default(void) {}
475+
446476
void sio2_mtap_change_slot_set(sio2_mtap_change_slot_cb_t cb)
447477
{
448-
g_sio2man_data.m_mtap_change_slot_cb = cb;
478+
// Unofficial: use default callback if NULL
479+
g_sio2man_data.m_mtap_change_slot_cb = cb ? cb : sio2_mtap_change_slot_default;
449480
}
450481

451482
void sio2_mtap_get_slot_max_set(sio2_mtap_get_slot_max_cb_t cb)
452483
{
453-
g_sio2man_data.m_mtap_get_slot_max_cb = cb;
484+
// Unofficial: use default callback if NULL
485+
g_sio2man_data.m_mtap_get_slot_max_cb = cb ? cb : sio2_mtap_get_slot_max_default;
454486
}
455487

456488
void sio2_mtap_get_slot_max2_set(sio2_mtap_get_slot_max2_cb_t cb)
457489
{
458-
g_sio2man_data.m_mtap_get_slot_max2_cb = cb;
490+
// Unofficial: use default callback if NULL
491+
g_sio2man_data.m_mtap_get_slot_max2_cb = cb ? cb : sio2_mtap_get_slot_max_default;
459492
}
460493

461494
void sio2_mtap_update_slots_set(sio2_mtap_update_slots_t cb)
462495
{
463-
g_sio2man_data.m_mtap_update_slots_cb = cb;
496+
// Unofficial: use default callback if NULL
497+
g_sio2man_data.m_mtap_update_slots_cb = cb ? cb : sio2_mtap_update_slots_default;
464498
}
465499

466500
int sio2_mtap_change_slot(s32 *arg)
467501
{
468-
int sum;
469-
int i;
470-
471-
g_sio2man_data.m_sdk13x_flag = 0;
472-
if ( g_sio2man_data.m_mtap_change_slot_cb )
473-
return g_sio2man_data.m_mtap_change_slot_cb(arg);
474-
sum = 0;
475-
for ( i = 0; i < 4; i += 1 )
476-
{
477-
arg[i + 4] = ((arg[i] + 1) < 2);
478-
sum += arg[i + 4];
479-
}
480-
return sum == 4;
502+
g_sio2man_data.m_sdk13x_totalflag &= ~g_sio2man_data.m_sdk13x_curflag;
503+
// Unofficial: unconditionally call callback
504+
return g_sio2man_data.m_mtap_change_slot_cb(arg);
481505
}
482506

483507
int sio2_mtap_get_slot_max(int port)
484508
{
485-
return g_sio2man_data.m_mtap_get_slot_max_cb ? g_sio2man_data.m_mtap_get_slot_max_cb(port) : 1;
509+
// Unofficial: unconditionally call callback
510+
return g_sio2man_data.m_mtap_get_slot_max_cb(port);
486511
}
487512

488513
int sio2_mtap_get_slot_max2(int port)
489514
{
490-
return g_sio2man_data.m_mtap_get_slot_max2_cb ? g_sio2man_data.m_mtap_get_slot_max2_cb(port) : 1;
515+
// Unofficial: unconditionally call callback
516+
return g_sio2man_data.m_mtap_get_slot_max2_cb(port);
491517
}
492518

493519
void sio2_mtap_update_slots(void)
494520
{
495-
if ( g_sio2man_data.m_mtap_update_slots_cb )
496-
g_sio2man_data.m_mtap_update_slots_cb();
521+
// Unofficial: unconditionally call callback
522+
g_sio2man_data.m_mtap_update_slots_cb();
497523
}

0 commit comments

Comments
 (0)