1+ #include " mod.h"
2+ #include " console.h"
3+ #include " patch.h"
4+
5+ #include < ttyd/dispdrv.h>
6+ #include < ttyd/evtmgr.h>
7+ #include < gc/demo.h>
8+
9+ namespace mod {
10+
11+ ConIntVar evt_show_table (" evt_show_table" , 0 );
12+
13+ MOD_UPDATE_FUNCTION ()
14+ {
15+ if (!evt_show_table.value )
16+ return ;
17+
18+ ttyd::dispdrv::dispEntry (ttyd::dispdrv::CameraId::kDebug , 1 , 0 .f , [](ttyd::dispdrv::CameraId layerId, void *user)
19+ {
20+ auto wp = ttyd::evtmgr::evtGetWork ();
21+
22+ if (!wp || !wp->entries )
23+ {
24+ return ;
25+ }
26+
27+ // Draw evt table.
28+ gc::demo::DEMOInitCaption (2 , 608 , 480 );
29+
30+ int allocatedCount = 0 ;
31+ const int kEvtCapacity = 256 ;
32+ const int kColumnCount = 8 ;
33+ const int kRowCount = kEvtCapacity / kColumnCount ;
34+ for (int col = 0 ; col < kColumnCount ; ++col)
35+ {
36+ for (int row = 0 ; row < kRowCount ; ++row)
37+ {
38+ int evtIndex = col * kRowCount + row;
39+ auto evt = &wp->entries [evtIndex];
40+
41+ int x = 2 + col * (9 * 8 + 4 );
42+ int y = 64 + row * 8 ;
43+
44+ char statusCode;
45+ if (!(evt->flags & 1 ))
46+ {
47+ statusCode = ' U' ;
48+ }
49+ else if (evt->flags & 0x02 )
50+ {
51+ statusCode = ' S' ;
52+ }
53+ else if (evt->flags & 0x10 )
54+ {
55+ statusCode = ' W' ;
56+ }
57+ else
58+ {
59+ statusCode = ' R' ;
60+ }
61+
62+ if (evt->flags & 1 )
63+ {
64+ ++allocatedCount;
65+ }
66+
67+ void *addr = evt->wCurrentCommandPtr ;
68+ if (!(reinterpret_cast <uint32_t >(addr) & 0x01000000 ))
69+ {
70+ statusCode += 0x20 ;
71+ }
72+
73+ gc::demo::DEMOPrintf (
74+ x, y, 0 ,
75+ " %02x%c%06x" ,
76+ evtIndex,
77+ statusCode,
78+ reinterpret_cast <uint32_t >(addr) & 0x00ffffff
79+ );
80+ }
81+ }
82+
83+ gc::demo::DEMOPrintf (2 , 56 , 0 , " capacity: %d/%d" , allocatedCount, wp->entryCount );
84+ }, nullptr );
85+ }
86+
87+ #if TTYD_US
88+ MOD_INIT_FUNCTION ()
89+ {
90+ patch::hookInstruction (
91+ reinterpret_cast <uint8_t *>(ttyd::evtmgr::evtEntry) + 0x6c ,
92+ [](gc::os::OSContext *context, void *user)
93+ {
94+ if (context->ctr == 0 )
95+ {
96+ gConsole ->logError (" evt overflow\n " );
97+ }
98+ }
99+ );
100+ }
101+ #endif
102+
103+ }
0 commit comments