home *** CD-ROM | disk | FTP | other *** search
/ ftp.whtech.com / ftp.whtech.com.7z / ftp.whtech.com / emulators / v9t9 / linux / sources / V9t9 / source / log.h < prev    next >
Encoding:
C/C++ Source or Header  |  2006-10-19  |  3.7 KB  |  176 lines

  1. /*
  2.  *    Logging routines
  3.  */
  4.  
  5. #ifndef __LOG_H__
  6. #define __LOG_H__
  7.  
  8. #include <stdarg.h>
  9. #include "16bit.h"
  10. #include "v9t9_types.h"
  11. #include "centry.h"
  12.  
  13. #ifdef __LOG__
  14. static char *log_src[] =
  15. {
  16.     "",
  17.     "OS",
  18.     "Timer",
  19.     "Parser",
  20.     "CPU",
  21.     "Memory",
  22.     "CRU",
  23.     "ROM",
  24.     "Video",
  25.     "Sprites",
  26.     "Sound",
  27.     "Keyboard",
  28.     "Speech",
  29.  
  30.     "RealDsk",
  31.     "EmuDsk",
  32.     "RS232",
  33.  
  34.     "Modules",        
  35.     "Internal",
  36.     "Demo"
  37. };
  38. #endif
  39.  
  40. enum
  41. {
  42.     LOG_GENERAL    = 0,
  43.     LOG_HOSTOS,
  44.     LOG_TIMER,
  45.     LOG_COMMANDS,
  46.     LOG_CPU,
  47.     LOG_MEMORY,
  48.     LOG_CRU,
  49.     LOG_ROMS,
  50.     LOG_VIDEO,
  51.     LOG_SPRITES,
  52.     LOG_SOUND,
  53.     LOG_KEYBOARD,
  54.     LOG_SPEECH,
  55.  
  56.     LOG_REALDISK,
  57.     LOG_EMUDISK,
  58.     LOG_RS232,
  59.  
  60.     LOG_MODULES,    // v9t9 modules, not roms
  61.     LOG_INTERNAL,    // assertion failures
  62.     LOG_DEMO,        // demo
  63.  
  64.     LOG_NUM_SRC,
  65.  
  66.     LOG_SRC_MASK = 0x1f,
  67.     LOG_SRC_SHIFT = 0,
  68.  
  69.     /////
  70.  
  71.     LOG_USER    = 0x100,        // user message, force visible
  72.  
  73.     // levels
  74.  
  75.     L_0            = 0 << 16,        // always
  76.     L_1            = 1 << 16,        // level 1
  77.     L_2            = 2 << 16,
  78.     L_3            = 3 << 16,
  79.     L_4            = 4 << 16,
  80.  
  81.     LOG_VERBOSE_MASK = 15 << 16,
  82.     LOG_VERBOSE_SHIFT = 16,
  83.  
  84.     /////
  85.  
  86.     LOG_INFO    = 0 << 29,    // no header
  87.     LOG_WARN    = 1 << 29,    // warning:
  88.     LOG_ERROR    = 2 << 29,    // error:
  89.     LOG_DEBUG    = 3 << 29,    // #ifdef DEBUG:  debug:
  90.     LOG_FATAL    = 4 << 29,    // fatal:
  91.  
  92.     LOG_TYPE_MASK = 7 << 29
  93. };
  94.  
  95. //    Test whether we echo this to the screen or not
  96. #define LOG_IS_VISIBLE(f) ((f & LOG_USER) || ((f & LOG_TYPE_MASK) == LOG_FATAL))
  97.  
  98. //    Initialize log
  99. void    initlog(void);
  100. //    Add commands
  101. void    log_add_commands(void);
  102. //    Terminate log
  103. void     termlog(void);
  104.  
  105. int        log_level(int src);
  106. const char *log_name(int src);
  107.  
  108. //    Is logging enabled given these flags?
  109. bool     log_enabled(int srcflags);
  110.  
  111. //    Return source flags coerced to add LOG_USER if necessary
  112. int        log_coerced_to_user(int srcflags);
  113.  
  114. //    Log something.  srcflags=bitmask of LOG_xxx
  115. void    vlogger(u32 srcflags, const char *format, va_list va);
  116.  
  117. void    logger(u32 srcflags, const char *format, ...);
  118.  
  119. //    Print an OS error
  120. void    OSerror(int err, char *format, ...);
  121.  
  122. //    Definitions for various status items for the UI
  123. //
  124. //    The comments in (...) indicate the varargs provided to report_status().
  125. typedef enum
  126. {
  127.     STATUS_CYCLES_SECOND,        // execution speed:
  128.                                 // avg cycles per second (#),
  129.                                 // (#) average insts per second
  130.     STATUS_FRAMES_SECOND,        // video update frames per second (#)
  131.     STATUS_DISK_ACCESS,            // disk DSR active (disk # 1-xx, bool on/off)
  132.     STATUS_RS232_ACCESS,        // RS232 DSR active (port # 1-xx, bool on/off)
  133.  
  134.     // these are only reported when ST_DEBUG is set in stateflag
  135.     STATUS_DEBUG_REFRESH,        // for each cycle
  136.     STATUS_CPU_PC,                // PC value (addr)
  137.     STATUS_CPU_STATUS,            // status value (#)
  138.     STATUS_CPU_WP,                // WP value (addr)
  139.     STATUS_CPU_REGISTER_VIEW,    // register view changed (wp, ptr to 16 regs)
  140.     STATUS_CPU_REGISTER_READ,    // register read (reg#, val)
  141.     STATUS_CPU_REGISTER_WRITE,    // register changed (reg#, val)
  142.     STATUS_CPU_INSTRUCTION,        // instruction (Instruction *, hex, opdisasm, op1, op2)
  143.     STATUS_CPU_INSTRUCTION_LAST,// last instruction (Instruction *, op1, op2)
  144.  
  145.     // a memory view is 'debugger_memory_view_size' bytes long
  146.     STATUS_MEMORY_VIEW,            // memory view changes (Memory*)
  147.     STATUS_MEMORY_READ,            // memory read in view (Memory*)
  148.     STATUS_MEMORY_WRITE,        // memory write in view (Memory*)
  149. }    status_item;
  150.  
  151. //    Print a status item for frontend
  152. //    The descriptions above tell what parameters will follow.
  153. void
  154. report_status(status_item item, ...);
  155.  
  156. //    Format status item into text, if verbosity allows it
  157. void
  158. report_status_text(status_item item, va_list va, char *buffer, int bufsz);
  159.  
  160. void    my_assert_func(char *file, int line, char *message);
  161.  
  162. #define _(x)    x
  163.  
  164. void    my_assert_func(char *file, int line, char *message);
  165.  
  166. #define my_assert(x) \
  167. do { if (!(x)) my_assert_func(__FILE__, __LINE__, #x); } while (0)
  168.  
  169. #define DEBUG
  170.  
  171. #include "cexit.h"
  172.  
  173. #endif
  174.  
  175.  
  176.