1 2 #ifndef SRC_UI_H_ 3 #define SRC_UI_H_ 4 5 #include <stdarg.h> 6 #include <stdio.h> 7 #include <iosfwd> 8 9 #include "exports.h" 10 #include "glib.h" 11 12 class Register; 13 class RegisterValue; 14 15 class ISimConsole { 16 public: ~ISimConsole()17 virtual ~ISimConsole() 18 { 19 } 20 21 virtual void Printf(const char *fmt, ...) = 0; 22 virtual void VPrintf(const char *fmt, va_list argptr) = 0; 23 virtual void Puts(const char*) = 0; 24 virtual void Putc(const char) = 0; 25 virtual const char* Gets(char *, int) = 0; 26 }; 27 28 29 class IUserInterface { 30 public: 31 enum { 32 eHex, 33 eDec, 34 eOct, 35 }; 36 IUserInterface()37 IUserInterface() : m_uVerbose(0) {} 38 ~IUserInterface()39 virtual ~IUserInterface() 40 { 41 } 42 43 virtual ISimConsole &GetConsole() = 0; 44 virtual void SetConsole(ISimConsole *pConsole) = 0; 45 virtual void DisplayMessage(unsigned int uStringID, ...) = 0; 46 virtual void DisplayMessage(FILE * pOut, unsigned int uStringID, ...) = 0; 47 virtual void DisplayMessage(const char *fmt, ...) = 0; 48 virtual void DisplayMessage(FILE * pOut, const char *fmt, ...) = 0; 49 50 // To be implemented to test on GetVerbosity() 51 // virtual void TraceMessage(unsigned int uStringID, ...) = 0; 52 // virtual void TraceMessage(const char *fmt, ...) = 0; 53 54 virtual const char * FormatProgramAddress(unsigned int uAddress, 55 unsigned int uMask) = 0; 56 virtual const char * FormatProgramAddress(unsigned int uAddress, 57 unsigned int uMask, int iRadix) = 0; 58 virtual const char * FormatRegisterAddress(unsigned int uAddress, 59 unsigned int uMask) = 0; 60 virtual const char * FormatRegisterAddress(Register *) = 0; 61 virtual const char * FormatLabeledValue(const char * pLabel, 62 unsigned int uValue) = 0; 63 virtual const char * FormatValue(unsigned int uValue) = 0; 64 virtual const char * FormatValue(gint64 uValue) = 0; 65 virtual const char * FormatValue(gint64 uValue, guint64 uMask) = 0; 66 virtual const char * FormatValue(gint64 uValue, guint64 uMask, 67 int iRadix) = 0; 68 69 virtual const char * FormatValue(char *str, int len, 70 int iRegisterSize, RegisterValue value) = 0; 71 72 virtual void SetProgramAddressRadix(int iRadix) = 0; 73 virtual void SetRegisterAddressRadix(int iRadix) = 0; 74 virtual void SetValueRadix(int iRadix) = 0; 75 76 virtual void SetProgramAddressMask(unsigned int uMask) = 0; 77 virtual void SetRegisterAddressMask(unsigned int uMask) = 0; 78 virtual void SetValueMask(unsigned int uMask) = 0; 79 80 typedef void (*FNNOTIFYEXITONBREAK)(int); 81 virtual void SetExitOnBreak(FNNOTIFYEXITONBREAK) = 0; 82 virtual void NotifyExitOnBreak(int iExitCode) = 0; 83 FNNOTIFYEXITONBREAK m_pfnNotifyOnExit = nullptr; 84 SetVerbosity(unsigned int uVerbose)85 inline void SetVerbosity(unsigned int uVerbose) 86 { 87 m_uVerbose = uVerbose; 88 } 89 GetVerbosity()90 inline unsigned int GetVerbosity() 91 { 92 return m_uVerbose; 93 } 94 GetVerbosityReference()95 inline unsigned int &GetVerbosityReference() 96 { 97 return m_uVerbose; 98 } 99 100 private: 101 unsigned int m_uVerbose; 102 }; 103 104 105 // extern "C" IUserInterface & GetUserInterface(void); 106 LIBGPSIM_EXPORT IUserInterface & GetUserInterface(); 107 LIBGPSIM_EXPORT void SetUserInterface(IUserInterface * rGpsimUI); 108 LIBGPSIM_EXPORT void SetUserInterface(std::streambuf* pOutStreamBuf); 109 110 class GlobalVerbosityAccessor { 111 public: GlobalVerbosityAccessor()112 GlobalVerbosityAccessor() 113 { 114 } 115 116 inline operator unsigned int() { 117 return GetUserInterface().GetVerbosity(); 118 } 119 // This gives the statements if(verbose) access 120 inline operator bool() 121 { 122 return GetUserInterface().GetVerbosity() != 0; 123 } 124 125 friend unsigned int operator&(const GlobalVerbosityAccessor& rVerbosity, int iValue); 126 }; 127 128 129 // This gives the statements if(verbose & 4) access 130 inline unsigned int operator&(const GlobalVerbosityAccessor& /* rVerbosity */, int iValue) 131 { 132 return (GetUserInterface().GetVerbosity() & iValue) != 0; 133 } 134 135 136 extern GlobalVerbosityAccessor verbose; 137 138 /// 139 /// Gpsim string IDs 140 #define IDS_BREAK_READING_REG 1 141 #define IDS_BREAK_READING_REG_VALUE 2 142 #define IDS_BREAK_READING_REG_OP_VALUE 3 143 #define IDS_BREAK_WRITING_REG 4 144 #define IDS_BREAK_WRITING_REG_VALUE 5 145 #define IDS_BREAK_WRITING_REG_OP_VALUE 6 146 #define IDS_BREAK_ON_EXEC_ADDRESS 7 147 #define IDS_PROGRAM_FILE_PROCESSOR_NOT_KNOWN 8 148 #define IDS_FILE_NAME_TOO_LONG 9 149 #define IDS_FILE_NOT_FOUND 10 150 #define IDS_FILE_BAD_FORMAT 11 151 #define IDS_NO_PROCESSOR_SPECIFIED 12 152 #define IDS_PROCESSOR_INIT_FAILED 13 153 #define IDS_FILE_NEED_PROCESSOR_SPECIFIED 14 154 #define IDS_LIST_FILE_NOT_FOUND 15 155 #define IDS_HIT_BREAK 16 156 #define IDS_LAST_VALID_GPSIM_ID 17 157 158 #endif 159