forked from hrydgard/ppsspp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathJitCompareScreen.cpp
559 lines (490 loc) · 18 KB
/
JitCompareScreen.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
#include <algorithm>
#include "UI/JitCompareScreen.h"
#include "Core/MemMap.h"
#include "Core/MIPS/MIPSTables.h"
#include "Core/MIPS/JitCommon/JitBlockCache.h"
#include "Core/MIPS/JitCommon/JitCommon.h"
#include "Core/MIPS/JitCommon/JitState.h"
JitCompareScreen::JitCompareScreen() : UIDialogScreenWithBackground() {
JitBlockCacheDebugInterface *blockCacheDebug = MIPSComp::jit->GetBlockCacheDebugInterface();
// The only defaults that make sense.
if (blockCacheDebug->SupportsProfiling()) {
listSort_ = ListSort::TIME_SPENT;
} else {
listSort_ = ListSort::BLOCK_LENGTH_DESC;
}
FillBlockList();
}
void JitCompareScreen::Flip() {
using namespace UI;
// If we add more, let's convert to a for loop.
switch (viewMode_) {
case ViewMode::DISASM:
comparisonView_->SetVisibility(V_VISIBLE);
blockListView_->SetVisibility(V_GONE);
statsView_->SetVisibility(V_GONE);
break;
case ViewMode::BLOCK_LIST:
comparisonView_->SetVisibility(V_GONE);
blockListView_->SetVisibility(V_VISIBLE);
statsView_->SetVisibility(V_GONE);
break;
case ViewMode::STATS:
comparisonView_->SetVisibility(V_GONE);
blockListView_->SetVisibility(V_GONE);
statsView_->SetVisibility(V_VISIBLE);
break;
}
}
// Three panes: Block chooser, MIPS view, ARM/x86 view
void JitCompareScreen::CreateViews() {
auto di = GetI18NCategory(I18NCat::DIALOG);
auto dev = GetI18NCategory(I18NCat::DEVELOPER);
using namespace UI;
root_ = new LinearLayout(ORIENT_HORIZONTAL);
ScrollView *leftColumnScroll = root_->Add(new ScrollView(ORIENT_VERTICAL, new LinearLayoutParams(200, FILL_PARENT)));
LinearLayout *leftColumn = leftColumnScroll->Add(new LinearLayout(ORIENT_VERTICAL));
comparisonView_ = root_->Add(new LinearLayout(ORIENT_VERTICAL, new LinearLayoutParams(1.0f)));
comparisonView_->SetVisibility(V_VISIBLE);
LinearLayout *blockTopBar = comparisonView_->Add(new LinearLayout(ORIENT_HORIZONTAL, new LinearLayoutParams(FILL_PARENT, WRAP_CONTENT)));
blockTopBar->Add(new Button("", ImageID("I_ARROW_UP")))->OnClick.Add([this](UI::EventParams &e) {
viewMode_ = ViewMode::BLOCK_LIST;
Flip();
return UI::EVENT_DONE;
});
blockTopBar->Add(new Button("", ImageID("I_ARROW_LEFT")))->OnClick.Add([=](UI::EventParams &e) {
if (currentBlock_ >= 1)
currentBlock_--;
UpdateDisasm();
return UI::EVENT_DONE;
});
blockTopBar->Add(new Button("", ImageID("I_ARROW_RIGHT")))->OnClick.Add([=](UI::EventParams &e) {
if (currentBlock_ < blockList_.size() - 1)
currentBlock_++;
UpdateDisasm();
return UI::EVENT_DONE;
});
blockTopBar->Add(new Button(dev->T("Random")))->OnClick.Add([=](UI::EventParams &e) {
if (blockList_.empty()) {
return UI::EVENT_DONE;
}
currentBlock_ = rand() % blockList_.size();
UpdateDisasm();
return UI::EVENT_DONE;
});
blockAddr_ = blockTopBar->Add(new TextEdit("", dev->T("Block address"), ""));
blockAddr_->OnEnter.Handle(this, &JitCompareScreen::OnAddressChange);
blockName_ = blockTopBar->Add(new TextView(dev->T("No block")));
blockStats_ = blockTopBar->Add(new TextView(""));
LinearLayout *columns = comparisonView_->Add(new LinearLayout(ORIENT_HORIZONTAL, new LinearLayoutParams(1.0f)));
ScrollView *midColumnScroll = columns->Add(new ScrollView(ORIENT_VERTICAL, new LinearLayoutParams(1.0f)));
LinearLayout *midColumn = midColumnScroll->Add(new LinearLayout(ORIENT_VERTICAL));
midColumn->SetTag("JitCompareLeftDisasm");
leftDisasm_ = midColumn->Add(new LinearLayout(ORIENT_VERTICAL));
leftDisasm_->SetSpacing(0.0f);
ScrollView *rightColumnScroll = columns->Add(new ScrollView(ORIENT_VERTICAL, new LinearLayoutParams(1.0f)));
rightColumnScroll->SetTag("JitCompareRightDisasm");
LinearLayout *rightColumn = rightColumnScroll->Add(new LinearLayout(ORIENT_VERTICAL));
rightDisasm_ = rightColumn->Add(new LinearLayout(ORIENT_VERTICAL));
rightDisasm_->SetSpacing(0.0f);
blockListView_ = root_->Add(new LinearLayout(ORIENT_VERTICAL, new LinearLayoutParams(1.0f)));
blockListView_->SetVisibility(V_GONE);
// Should match the ListSort enum
static ContextMenuItem sortMenu[] = {
{ "Block number", "I_ARROW_UP" },
{ "Block length", "I_ARROW_DOWN" },
{ "Block length", "I_ARROW_UP" },
{ "Time spent", "I_ARROW_DOWN" },
{ "Executions", "I_ARROW_DOWN" },
};
int sortCount = ARRAY_SIZE(sortMenu);
if (MIPSComp::jit) {
JitBlockCacheDebugInterface *blockCacheDebug = MIPSComp::jit->GetBlockCacheDebugInterface();
if (!blockCacheDebug->SupportsProfiling()) {
sortCount -= 2;
}
}
LinearLayout *listTopBar = blockListView_->Add(new LinearLayout(ORIENT_HORIZONTAL, new LinearLayoutParams(FILL_PARENT, WRAP_CONTENT)));
Button *sortButton = new Button(dev->T("Sort..."));
listTopBar->Add(sortButton)->OnClick.Add([this, sortButton, sortCount](UI::EventParams &e) {
PopupContextMenuScreen *contextMenu = new UI::PopupContextMenuScreen(sortMenu, sortCount, I18NCat::DEVELOPER, sortButton);
screenManager()->push(contextMenu);
contextMenu->OnChoice.Add([=](EventParams &e) -> UI::EventReturn {
if (e.a < (int)ListSort::MAX) {
listSort_ = (ListSort)e.a;
UpdateDisasm();
}
return UI::EVENT_DONE;
});
return UI::EVENT_DONE;
});
ScrollView *blockScroll = blockListView_->Add(new ScrollView(ORIENT_VERTICAL, new LinearLayoutParams(1.0f)));
blockListContainer_ = blockScroll->Add(new LinearLayout(ORIENT_VERTICAL));
statsView_ = root_->Add(new LinearLayout(ORIENT_VERTICAL, new LinearLayoutParams(1.0f)));
statsView_->SetVisibility(V_GONE);
LinearLayout *statsTopBar = statsView_->Add(new LinearLayout(ORIENT_HORIZONTAL, new LinearLayoutParams(FILL_PARENT, WRAP_CONTENT)));
ScrollView *statsScroll = statsView_->Add(new ScrollView(ORIENT_VERTICAL, new LinearLayoutParams(1.0f)));
statsContainer_ = statsScroll->Add(new LinearLayout(ORIENT_VERTICAL, new LinearLayoutParams(FILL_PARENT, WRAP_CONTENT)));
// leftColumn->Add(new Choice(dev->T("By Address")))->OnClick.Handle(this, &JitCompareScreen::OnSelectBlock);
leftColumn->Add(new Choice(dev->T("All")))->OnClick.Add([=](UI::EventParams &e) {
listType_ = ListType::ALL_BLOCKS;
viewMode_ = ViewMode::BLOCK_LIST;
UpdateDisasm();
return UI::EVENT_DONE;
});
leftColumn->Add(new Choice(dev->T("FPU")))->OnClick.Add([=](UI::EventParams &e) {
listType_ = ListType::FPU_BLOCKS;
viewMode_ = ViewMode::BLOCK_LIST;
UpdateDisasm();
return UI::EVENT_DONE;
});
leftColumn->Add(new Choice(dev->T("VFPU")))->OnClick.Add([=](UI::EventParams &e) {
listType_ = ListType::VFPU_BLOCKS;
viewMode_ = ViewMode::BLOCK_LIST;
UpdateDisasm();
return UI::EVENT_DONE;
});
leftColumn->Add(new Choice(dev->T("Stats")))->OnClick.Handle(this, &JitCompareScreen::OnShowStats);
leftColumn->Add(new Choice(di->T("Back")))->OnClick.Handle<UIScreen>(this, &UIScreen::OnBack);
UpdateDisasm();
}
void JitCompareScreen::FillBlockList() {
JitBlockCacheDebugInterface *blockCacheDebug = MIPSComp::jit->GetBlockCacheDebugInterface();
blockList_.clear();
int64_t sumTotalNanos = 0;
int64_t sumExecutions = 0;
bool profiling = blockCacheDebug->SupportsProfiling();
for (int i = 0; i < blockCacheDebug->GetNumBlocks(); i++) {
if (!blockCacheDebug->IsValidBlock(i)) {
continue;
}
switch (listType_) {
case ListType::ALL_BLOCKS:
blockList_.push_back(i);
break;
case ListType::FPU_BLOCKS:
case ListType::VFPU_BLOCKS:
{
const uint64_t flags = listType_ == ListType::FPU_BLOCKS ? IS_FPU : IS_VFPU;
// const uint64_t antiFlags = IS_SYSCALL;
const uint64_t antiFlags = 0;
JitBlockMeta meta = blockCacheDebug->GetBlockMeta(i);
if (meta.valid) {
for (u32 addr = meta.addr; addr < meta.addr + meta.sizeInBytes; addr += 4) {
MIPSOpcode opcode = Memory::Read_Instruction(addr);
MIPSInfo info = MIPSGetInfo(opcode);
if ((info & flags) && !(info & antiFlags)) {
blockList_.push_back(i);
break;
}
}
}
}
default:
break;
}
if (profiling) {
JitBlockProfileStats stats = blockCacheDebug->GetBlockProfileStats(i);
sumTotalNanos += stats.totalNanos;
sumExecutions += stats.executions;
}
}
sumTotalNanos_ = sumTotalNanos;
sumExecutions_ = sumExecutions;
if (listSort_ == ListSort::BLOCK_NUM) {
// Already sorted, effectively.
return;
}
std::sort(blockList_.begin(), blockList_.end(), [=](const int &a_index, const int &b_index) {
// First, check metadata sorts.
switch (listSort_) {
case ListSort::BLOCK_LENGTH_DESC:
{
JitBlockMeta a_meta = blockCacheDebug->GetBlockMeta(a_index);
JitBlockMeta b_meta = blockCacheDebug->GetBlockMeta(b_index);
return a_meta.sizeInBytes > b_meta.sizeInBytes; // reverse for descending
}
case ListSort::BLOCK_LENGTH_ASC:
{
JitBlockMeta a_meta = blockCacheDebug->GetBlockMeta(a_index);
JitBlockMeta b_meta = blockCacheDebug->GetBlockMeta(b_index);
return a_meta.sizeInBytes < b_meta.sizeInBytes;
}
default:
break;
}
JitBlockProfileStats a_stats = blockCacheDebug->GetBlockProfileStats(a_index);
JitBlockProfileStats b_stats = blockCacheDebug->GetBlockProfileStats(b_index);
switch (listSort_) {
case ListSort::EXECUTIONS:
return a_stats.executions > b_stats.executions;
case ListSort::TIME_SPENT:
return a_stats.totalNanos > b_stats.totalNanos;
default:
return false;
}
});
}
void JitCompareScreen::UpdateDisasm() {
leftDisasm_->Clear();
rightDisasm_->Clear();
using namespace UI;
if (!MIPSComp::jit) {
return;
}
JitBlockCacheDebugInterface *blockCacheDebug = MIPSComp::jit->GetBlockCacheDebugInterface();
if (viewMode_ == ViewMode::DISASM && (currentBlock_ < 0 || currentBlock_ >= (int)blockList_.size())) {
viewMode_ = ViewMode::BLOCK_LIST;
}
FillBlockList();
Flip();
if (viewMode_ == ViewMode::DISASM) {
char temp[256];
snprintf(temp, sizeof(temp), "%d/%d", currentBlock_, (int)blockList_.size());
blockName_->SetText(temp);
int blockNum = blockList_[currentBlock_];
if (!blockCacheDebug->IsValidBlock(blockNum)) {
auto dev = GetI18NCategory(I18NCat::DEVELOPER);
leftDisasm_->Add(new TextView(dev->T("No block")));
rightDisasm_->Add(new TextView(dev->T("No block")));
blockStats_->SetText("");
return;
}
JitBlockDebugInfo debugInfo = blockCacheDebug->GetBlockDebugInfo(blockNum);
snprintf(temp, sizeof(temp), "%08x", debugInfo.originalAddress);
blockAddr_->SetText(temp);
// Alright. First generate the MIPS disassembly.
// TODO: Need a way to communicate branch continuing.
for (const auto &line : debugInfo.origDisasm) {
leftDisasm_->Add(new TextView(line, FLAG_DYNAMIC_ASCII, false))->SetFocusable(true);
}
// TODO : When we have both target and IR, need a third column.
if (debugInfo.targetDisasm.size()) {
for (const auto &line : debugInfo.targetDisasm) {
rightDisasm_->Add(new TextView(line, FLAG_DYNAMIC_ASCII, false))->SetFocusable(true);
}
} else {
for (const auto &line : debugInfo.irDisasm) {
rightDisasm_->Add(new TextView(line, FLAG_DYNAMIC_ASCII, false))->SetFocusable(true);
}
}
int numMips = leftDisasm_->GetNumSubviews();
int numHost = rightDisasm_->GetNumSubviews();
double bloat = 100.0 * numHost / numMips;
if (blockCacheDebug->SupportsProfiling()) {
JitBlockProfileStats stats = blockCacheDebug->GetBlockProfileStats(blockNum);
int execs = (int)stats.executions;
double us = (double)stats.totalNanos / 1000000.0;
double percentage = 100.0 * (double)stats.totalNanos / (double)sumTotalNanos_;
snprintf(temp, sizeof(temp), "%d runs, %0.2f ms, %0.2f%%, bloat: %0.1f%%", execs, us, percentage, bloat);
} else {
snprintf(temp, sizeof(temp), "bloat: %0.1f%%", bloat);
}
blockStats_->SetText(temp);
} else if (viewMode_ == ViewMode::BLOCK_LIST) {
blockListContainer_->Clear();
bool profiling = blockCacheDebug->SupportsProfiling();
for (int i = 0; i < std::min(100, (int)blockList_.size()); i++) {
int blockNum = blockList_[i];
JitBlockMeta meta = blockCacheDebug->GetBlockMeta(blockNum);
char temp[512], small[512];
if (profiling) {
JitBlockProfileStats stats = blockCacheDebug->GetBlockProfileStats(blockNum);
int execs = (int)stats.executions;
double us = (double)stats.totalNanos / 1000000.0;
double percentage = 100.0 * (double)stats.totalNanos / (double)sumTotalNanos_;
snprintf(temp, sizeof(temp), "%08x: %d instrs (%d runs, %0.2f ms, %0.2f%%)", meta.addr, meta.sizeInBytes / 4, execs, us, percentage);
} else {
snprintf(temp, sizeof(temp), "%08x: %d instrs", meta.addr, meta.sizeInBytes / 4);
}
snprintf(small, sizeof(small), "Small text");
Choice *blockChoice = blockListContainer_->Add(new Choice(temp, small));
blockChoice->OnClick.Handle(this, &JitCompareScreen::OnBlockClick);
}
} else { // viewMode_ == ViewMode::STATS
statsContainer_->Clear();
BlockCacheStats bcStats;
blockCacheDebug->ComputeStats(bcStats);
char stats[1024];
snprintf(stats, sizeof(stats),
"Num blocks: %d\n"
"Average Bloat: %0.2f%%\n"
"Min Bloat: %0.2f%% (%08x)\n"
"Max Bloat: %0.2f%% (%08x)\n",
blockCacheDebug->GetNumBlocks(),
100.0 * bcStats.avgBloat,
100.0 * bcStats.minBloat, bcStats.minBloatBlock,
100.0 * bcStats.maxBloat, bcStats.maxBloatBlock);
statsContainer_->Add(new TextView(stats));
}
}
UI::EventReturn JitCompareScreen::OnBlockClick(UI::EventParams &e) {
int blockIndex = blockListContainer_->IndexOfSubview(e.v);
if (blockIndex >= 0) {
viewMode_ = ViewMode::DISASM;
currentBlock_ = blockIndex;
UpdateDisasm();
}
return UI::EVENT_DONE;
}
UI::EventReturn JitCompareScreen::OnAddressChange(UI::EventParams &e) {
std::lock_guard<std::recursive_mutex> guard(MIPSComp::jitLock);
if (!MIPSComp::jit) {
return UI::EVENT_DONE;
}
JitBlockCacheDebugInterface *blockCache = MIPSComp::jit->GetBlockCacheDebugInterface();
if (!blockCache)
return UI::EVENT_DONE;
u32 addr;
if (blockAddr_->GetText().size() > 8)
return UI::EVENT_DONE;
if (1 == sscanf(blockAddr_->GetText().c_str(), "%08x", &addr)) {
if (Memory::IsValidAddress(addr)) {
currentBlock_ = blockCache->GetBlockNumberFromStartAddress(addr);
UpdateDisasm();
}
}
return UI::EVENT_DONE;
}
UI::EventReturn JitCompareScreen::OnShowStats(UI::EventParams &e) {
std::lock_guard<std::recursive_mutex> guard(MIPSComp::jitLock);
if (!MIPSComp::jit) {
return UI::EVENT_DONE;
}
viewMode_ = ViewMode::STATS;
UpdateDisasm();
return UI::EVENT_DONE;
}
UI::EventReturn JitCompareScreen::OnSelectBlock(UI::EventParams &e) {
auto dev = GetI18NCategory(I18NCat::DEVELOPER);
auto addressPrompt = new AddressPromptScreen(dev->T("Block address"));
addressPrompt->OnChoice.Handle(this, &JitCompareScreen::OnBlockAddress);
screenManager()->push(addressPrompt);
return UI::EVENT_DONE;
}
UI::EventReturn JitCompareScreen::OnBlockAddress(UI::EventParams &e) {
std::lock_guard<std::recursive_mutex> guard(MIPSComp::jitLock);
if (!MIPSComp::jit) {
return UI::EVENT_DONE;
}
JitBlockCacheDebugInterface *blockCache = MIPSComp::jit->GetBlockCacheDebugInterface();
if (!blockCache)
return UI::EVENT_DONE;
if (Memory::IsValidAddress(e.a)) {
currentBlock_ = blockCache->GetBlockNumberFromStartAddress(e.a);
} else {
currentBlock_ = -1;
}
UpdateDisasm();
return UI::EVENT_DONE;
}
/*
void JitCompareScreen::OnRandomBlock(int flag) {
std::lock_guard<std::recursive_mutex> guard(MIPSComp::jitLock);
if (!MIPSComp::jit) {
return;
}
JitBlockCacheDebugInterface *blockCache = MIPSComp::jit->GetBlockCacheDebugInterface();
if (!blockCache)
return;
int numBlocks = blockCache->GetNumBlocks();
if (numBlocks > 0) {
bool anyWanted = false;
int tries = 0;
while (!anyWanted && tries < numBlocks) {
currentBlock_ = rand() % numBlocks;
if (blockCache->IsValidBlock(currentBlock_)) {
JitBlockDebugInfo b = blockCache->GetBlockDebugInfo(currentBlock_);
u32 mipsBytes = (u32)b.origDisasm.size() * 4;
for (u32 addr = b.originalAddress; addr < b.originalAddress + mipsBytes; addr += 4) {
MIPSOpcode opcode = Memory::Read_Instruction(addr);
if (MIPSGetInfo(opcode) & flag) {
char temp[256];
MIPSDisAsm(opcode, addr, temp, sizeof(temp));
// INFO_LOG(HLE, "Stopping at random instruction: %08x %s", addr, temp);
anyWanted = true;
break;
}
}
}
tries++;
}
if (!anyWanted)
currentBlock_ = -1;
}
UpdateDisasm();
}*/
void AddressPromptScreen::CreatePopupContents(UI::ViewGroup *parent) {
using namespace UI;
auto dev = GetI18NCategory(I18NCat::DEVELOPER);
addrView_ = new TextView(dev->T("Enter address"), ALIGN_HCENTER, false);
parent->Add(addrView_);
ViewGroup *grid = new GridLayout(GridLayoutSettings(60, 40));
parent->Add(grid);
for (int i = 0; i < 16; ++i) {
char temp[16];
snprintf(temp, 16, " %X ", i);
buttons_[i] = new Button(temp);
grid->Add(buttons_[i])->OnClick.Handle(this, &AddressPromptScreen::OnDigitButton);
}
parent->Add(new Button(dev->T("Backspace")))->OnClick.Handle(this, &AddressPromptScreen::OnBackspace);
}
void AddressPromptScreen::OnCompleted(DialogResult result) {
if (result == DR_OK) {
UI::EventParams e{};
e.v = root_;
e.a = addr_;
OnChoice.Trigger(e);
}
}
UI::EventReturn AddressPromptScreen::OnDigitButton(UI::EventParams &e) {
for (int i = 0; i < 16; ++i) {
if (buttons_[i] == e.v) {
AddDigit(i);
}
}
return UI::EVENT_DONE;
}
UI::EventReturn AddressPromptScreen::OnBackspace(UI::EventParams &e) {
BackspaceDigit();
return UI::EVENT_DONE;
}
void AddressPromptScreen::AddDigit(int n) {
if ((addr_ & 0xF0000000) == 0) {
addr_ = addr_ * 16 + n;
}
UpdatePreviewDigits();
}
void AddressPromptScreen::BackspaceDigit() {
addr_ /= 16;
UpdatePreviewDigits();
}
void AddressPromptScreen::UpdatePreviewDigits() {
if (addr_ != 0) {
char temp[32];
snprintf(temp, 32, "%8X", addr_);
addrView_->SetText(temp);
} else {
auto dev = GetI18NCategory(I18NCat::DEVELOPER);
addrView_->SetText(dev->T("Enter address"));
}
}
bool AddressPromptScreen::key(const KeyInput &key) {
if (key.flags & KEY_DOWN) {
if (key.keyCode >= NKCODE_0 && key.keyCode <= NKCODE_9) {
AddDigit(key.keyCode - NKCODE_0);
} else if (key.keyCode >= NKCODE_A && key.keyCode <= NKCODE_F) {
AddDigit(10 + key.keyCode - NKCODE_A);
// NKCODE_DEL is backspace.
} else if (key.keyCode == NKCODE_DEL) {
BackspaceDigit();
} else if (key.keyCode == NKCODE_ENTER) {
TriggerFinish(DR_OK);
} else {
return UIDialogScreen::key(key);
}
} else {
return UIDialogScreen::key(key);
}
return true;
}