GE-115 Emulator
An Emulator of the General Electrics GE-115 computer
log.c
Go to the documentation of this file.
1 #include "log.h"
2 
3 #include <stdarg.h>
4 #include <stdio.h>
5 
6 static ge_log_type active_log_types = -1; // ~(LOG_CONDS | LOG_STATES);
7 
8 static const char *log_type_name(ge_log_type type)
9 {
10  switch (type) {
11  case LOG_ERR: return "error ";
12  case LOG_DEBUG: return "debug ";
13  case LOG_REGS: return "regs ";
14  case LOG_STATES: return "states ";
15  case LOG_CONDS: return "conds ";
16  case LOG_REGS_V: return "regs v ";
17  case LOG_FUTURE: return "future ";
18  case LOG_CYCLE: return "cycle ";
19  case LOG_PERI: return "periph ";
20  case LOG_READER: return "reader ";
21  case LOG_CMDS: return "cmds ";
22  default: return " ";
23  }
24 }
25 
27 {
28  active_log_types = types;
29 }
30 
31 void ge_log(ge_log_type type, const char *format, ...)
32 {
33  static char line[0x1000];
34  va_list args;
35 
36  if (!(active_log_types & type))
37  return;
38 
39  va_start (args, format);
40  vsnprintf(line, sizeof(line), format, args);
41  va_end (args);
42 
43  printf(" %-7s ] %s", log_type_name(type), line);
44 }
45 
46 uint8_t ge_log_enabled(ge_log_type type) {
47  return !!(active_log_types & type);
48 }
static ge_log_type active_log_types
Definition: log.c:6
static const char * log_type_name(ge_log_type type)
Definition: log.c:8
void ge_log_set_active_types(ge_log_type types)
Set active log types.
Definition: log.c:26
void ge_log(ge_log_type type, const char *format,...)
Log message.
Definition: log.c:31
uint8_t ge_log_enabled(ge_log_type type)
Check if a log type is enabled.
Definition: log.c:46
int ge_log_type
Definition: log.h:6
@ LOG_REGS_V
Register trace per pulse.
Definition: log.h:23
@ LOG_ERR
Emulator unrecoverable condition.
Definition: log.h:18
@ LOG_FUTURE
Future state network debug.
Definition: log.h:24
@ LOG_REGS
Register trace per cycle.
Definition: log.h:20
@ LOG_STATES
State trace.
Definition: log.h:21
@ LOG_CONDS
MSL conditions trace.
Definition: log.h:22
@ LOG_CYCLE
Cycle attribution debug.
Definition: log.h:25
@ LOG_CMDS
MSL commands trace.
Definition: log.h:29
@ LOG_PERI
Peripherals IO.
Definition: log.h:27
@ LOG_DEBUG
General detailed debug information.
Definition: log.h:19
@ LOG_READER
Integrated Reader.
Definition: log.h:28