11#include " functions.h"
2- #include < unordered_map>
2+ #include < fmt/color.h>
3+ #include < fmt/core.h>
4+ #include < magic_enum.hpp>
35#include " debugger/debugger.h"
46#include " system.h"
5- #include " utils/logger.h"
67#include " utils/string.h"
78
89namespace bios {
@@ -23,7 +24,7 @@ Function::Function(const std::string& prototype, std::function<bool(System* sys)
2324 auto delim = sArg .find_last_of (' ' );
2425
2526 if (delim == std::string::npos) {
26- throw std::runtime_error (string_format ( " %s -> Invalid parameter without type" , prototype. c_str ()). c_str ( ));
27+ throw std::runtime_error (fmt::format ( " {} -> Invalid parameter without type" , prototype));
2728 }
2829
2930 auto sType = trim (sArg .substr (0 , delim));
@@ -44,7 +45,7 @@ Function::Function(const std::string& prototype, std::function<bool(System* sys)
4445 else if (sType == " void*" )
4546 arg.type = Type::POINTER;
4647 else
47- throw std::runtime_error (string_format ( " %s -> Invalid parameter type" , prototype. c_str ()). c_str ( ));
48+ throw std::runtime_error (fmt::format ( " {} -> Invalid parameter type" , prototype));
4849
4950 this ->args .push_back (arg);
5051 }
@@ -65,7 +66,7 @@ inline bool dbgOutputString(System* sys) {
6566 for (int i = 0 ; i < 80 ; i++) {
6667 char c = sys->readMemory8 (sys->cpu ->reg [4 ] + i);
6768 if (c == 0 ) {
68- printf (" \n " );
69+ fmt::print (" \n " );
6970 return false ;
7071 }
7172 putchar (c);
@@ -90,20 +91,36 @@ inline bool unresolvedException(System* sys) {
9091 auto cause = sys->cpu ->cop0 .cause ;
9192 uint32_t epc = sys->cpu ->cop0 .epc ;
9293
93- logger::printf (" 🔴Unresolved exception⚪️: 🅱️%s❌⚪️ (%u), epc=🔵0x%08x⚪️, ra=🔵0x%08x\n " ,
94- cause.getExceptionName (), cause.exception , epc, sys->cpu ->reg [31 ]);
94+ #define RED fmt::fg (fmt::terminal_color::red)
95+ #define WHITE fmt::fg (fmt::terminal_color::white)
96+ #define BLUE fmt::fg (fmt::terminal_color::blue)
97+ #define BOLD fmt::emphasis::bold
98+
99+ // Unresolved exception: {EXCEPTION_NAME} (EXCEPTION_NUMBER), epc={EPC}, ra={RA}
100+ fmt::print (RED, " Unresolved exception" );
101+ fmt::print (" : " );
102+ fmt::print (WHITE | BOLD, " {}" , magic_enum::enum_name (cause.exception ));
103+ fmt::print (" ({})" , static_cast <int >(cause.exception ));
104+ fmt::print (" , epc=" );
105+ fmt::print (BLUE, " 0x{:08x}" , epc);
106+ fmt::print (" , ra=" );
107+ fmt::print (BLUE, " 0x{:08x}\n " , sys->cpu ->reg [31 ]);
108+
95109 for (uint32_t addr = epc - howManyInstructionsToDisassemble * 4 ; addr <= epc; addr += 4 ) {
96110 auto opcode = mips::Opcode (sys->readMemory32 (addr));
97111 auto ins = debugger::decodeInstruction (opcode);
98112
113+ fmt::print (BLUE, " 0x{:08x}: " , addr);
114+ fmt::print (WHITE, " {:<8} {}" , ins.mnemonic , ins.parameters );
115+
99116 if (addr == epc) {
100- ins.parameters += " 🅱️ <---- Caused the exception" ;
117+ fmt::print (WHITE | BOLD, " <---- Caused the exception\n " );
118+ } else {
119+ fmt::print (" \n " );
101120 }
102-
103- logger::printf (" 🔵0x%08x:⚪️ %-8s %s\n " , addr, ins.mnemonic .c_str (), ins.parameters .c_str ());
104121 }
105- logger::printf ( " 🔴 This is most likely bug in Avocado, please report it.\n " );
106- logger::printf ( " 🔴 🅱️Emulation stopped.\n " );
122+ fmt::print (RED, " This is most likely bug in Avocado, please report it.\n " );
123+ fmt::print (RED | BOLD, " Emulation stopped.\n " );
107124
108125 sys->state = System::State::halted;
109126 return false ;
0 commit comments