bitbang: Convert logging to AVR_LOG()
[simavr] / simavr / sim / sim_avr.h
index f7ac26d..db41e41 100644 (file)
@@ -55,12 +55,27 @@ enum {
        R_SREG  = 32+0x3f,
 
        // maximum number of IO registers, on normal AVRs
-       MAX_IOs = 256,  // Bigger AVRs need more than 256-32 (mega1280)
+       MAX_IOs = 279,  // Bigger AVRs need more than 256-32 (mega1280)
 };
 
 #define AVR_DATA_TO_IO(v) ((v) - 32)
 #define AVR_IO_TO_DATA(v) ((v) + 32)
 
+/**
+ * Logging macros and associated log levels.
+ * The current log level is kept in avr->log.
+ */
+enum {
+       LOG_ERROR = 1,
+       LOG_WARNING,
+       LOG_TRACE,
+};
+#define AVR_LOG(avr, level, ...) \
+       do { \
+               if (avr->log >= level) \
+                       fprintf(stdout, __VA_ARGS__); \
+       } while(0)
+
 /*
  * Core states.
  */
@@ -245,7 +260,7 @@ typedef struct avr_t {
        avr_int_table_t interrupts;
 
        // DEBUG ONLY -- value ignored if CONFIG_SIMAVR_TRACE = 0
-       int             trace : 1,
+       uint8_t trace : 1,
                        log : 2; // log level, default to 1
 
        // Only used if CONFIG_SIMAVR_TRACE is defined