ppcBranchOrigin = 0 means relative branch, non-zero means absolute branch will be shown
| 512 | |
| 513 | // ppcBranchOrigin = 0 means relative branch, non-zero means absolute branch will be shown |
| 514 | std::string formatMemoryToString(const char* memory, const MemType type, const size_t length, |
| 515 | const MemBase base, const bool isUnsigned, const bool withBSwap, |
| 516 | const u32 ppcBranchOrigin) |
| 517 | { |
| 518 | std::stringstream ss; |
| 519 | switch (base) |
| 520 | { |
| 521 | case Common::MemBase::base_octal: |
| 522 | ss << std::oct; |
| 523 | break; |
| 524 | case Common::MemBase::base_decimal: |
| 525 | ss << std::dec; |
| 526 | break; |
| 527 | case Common::MemBase::base_hexadecimal: |
| 528 | ss << std::hex << std::uppercase; |
| 529 | break; |
| 530 | default: |
| 531 | break; |
| 532 | } |
| 533 | |
| 534 | switch (type) |
| 535 | { |
| 536 | case Common::MemType::type_byte: |
| 537 | { |
| 538 | if (isUnsigned || base == Common::MemBase::base_binary) |
| 539 | { |
| 540 | u8 unsignedByte = 0; |
| 541 | std::memcpy(&unsignedByte, memory, sizeof(u8)); |
| 542 | if (base == Common::MemBase::base_binary) |
| 543 | return std::bitset<sizeof(u8) * 8>(unsignedByte).to_string(); |
| 544 | // This has to be converted to an integer type because printing a uint8_t would resolve to a |
| 545 | // char and print a single character. |
| 546 | ss << static_cast<unsigned int>(unsignedByte); |
| 547 | return ss.str(); |
| 548 | } |
| 549 | |
| 550 | s8 aByte = 0; |
| 551 | std::memcpy(&aByte, memory, sizeof(s8)); |
| 552 | // This has to be converted to an integer type because printing a uint8_t would resolve to a |
| 553 | // char and print a single character. Additionaly, casting a signed type to a larger signed |
| 554 | // type will extend the sign to match the size of the destination type, this is required for |
| 555 | // signed values in decimal, but must be bypassed for other bases, this is solved by first |
| 556 | // casting to u8 then to signed int. |
| 557 | if (base == Common::MemBase::base_decimal) |
| 558 | ss << static_cast<int>(aByte); |
| 559 | else |
| 560 | ss << static_cast<int>(static_cast<u8>(aByte)); |
| 561 | return ss.str(); |
| 562 | } |
| 563 | case Common::MemType::type_halfword: |
| 564 | { |
| 565 | char* memoryCopy = new char[sizeof(u16)]; |
| 566 | std::memcpy(memoryCopy, memory, sizeof(u16)); |
| 567 | if (withBSwap) |
| 568 | { |
| 569 | u16 halfword = 0; |
| 570 | std::memcpy(&halfword, memoryCopy, sizeof(u16)); |
| 571 | halfword = Common::bSwap16(halfword); |
no test coverage detected