| 338 | } |
| 339 | |
| 340 | void MemoryViewTable::InsertAtCurrentSelection(const QString& text, DebugInterface& cpu) |
| 341 | { |
| 342 | if (!cpu.isValidAddress(selectedAddress)) |
| 343 | return; |
| 344 | |
| 345 | if (displayType == MemoryViewType::FLOAT) |
| 346 | { |
| 347 | // Convert string into float value |
| 348 | bool isValidFloat = false; |
| 349 | const float newFloatVal = text.toFloat(&isValidFloat); |
| 350 | if (!isValidFloat) |
| 351 | { |
| 352 | AsyncDialogs::warning(parent, tr("Input Error"), tr("Invalid float value")); |
| 353 | return; |
| 354 | } |
| 355 | |
| 356 | // Write new float value back to memory |
| 357 | u32 newIntVal = 0; |
| 358 | std::memcpy(&newIntVal, &newFloatVal, sizeof(newIntVal)); |
| 359 | newIntVal = convertEndian(newIntVal); |
| 360 | |
| 361 | const QPointer<MemoryViewTable> table(this); |
| 362 | Host::RunOnCPUThread([table, address = selectedAddress, &cpu, val = newIntVal] { |
| 363 | cpu.Write32(address, val); |
| 364 | |
| 365 | QtHost::RunOnUIThread([table] { |
| 366 | if (!table) |
| 367 | return; |
| 368 | |
| 369 | table->parent->update(); |
| 370 | }); |
| 371 | }); |
| 372 | } |
| 373 | else |
| 374 | { |
| 375 | // If pasting into the hex view, also decode the input as hex bytes. |
| 376 | // This approach prevents one from pasting on a nibble boundary, but that is almost always |
| 377 | // user error, and we don't have an undo function in this view, so best to stay conservative. |
| 378 | QByteArray input = selectedText ? text.toUtf8() : QByteArray::fromHex(text.toUtf8()); |
| 379 | |
| 380 | const QPointer<MemoryViewTable> table(this); |
| 381 | const MemoryViewType display_type = displayType; |
| 382 | const bool little_endian = littleEndian; |
| 383 | Host::RunOnCPUThread([table, address = selectedAddress, &cpu, input, display_type, little_endian] { |
| 384 | u32 currAddr = address; |
| 385 | for (int i = 0; i < input.size(); i++) |
| 386 | { |
| 387 | cpu.Write8(currAddr, input[i]); |
| 388 | currAddr = nextAddress(currAddr, address, display_type, little_endian); |
| 389 | } |
| 390 | |
| 391 | u32 end_address = address + input.size(); |
| 392 | QtHost::RunOnUIThread([table, end_address] { |
| 393 | if (!table) |
| 394 | return; |
| 395 | |
| 396 | table->UpdateSelectedAddress(end_address); |
| 397 | table->parent->update(); |
no test coverage detected