merge
[dcpu16] / hw_spc2000.c
index 47b0bf905425206df89a54452b643ee20b6c0818..151b98cdd29d0eab82072cf7b9613a9e64fbbcf8 100644 (file)
@@ -5,6 +5,15 @@
 #include "dcpu16.h"
 #include "hw_spc2000.h"
 
+#define MSG_(__level__, __vm__, ...) do { ((__vm__) ? ((struct dcpu16 *)(__vm__))->msg_cb_ : dcpu16_msg_)(__level__, __VA_ARGS__); } while (0)
+#define MSG_INFO(__vm__, ...) MSG_(DCPU16_MSG_INFO, __vm__, __VA_ARGS__)
+#define MSG_ERROR(__vm__, ...) MSG_(DCPU16_MSG_ERROR, __vm__, __VA_ARGS__)
+#ifdef DEBUG
+#define MSG_DEBUG(__vm__, ...) MSG_(DCPU16_MSG_DEBUG, __vm__, __VA_ARGS__)
+#else /* DEBUG  */
+#define MSG_DEBUG(__vm__, ...) do { } while (0)
+#endif /* DEBUG */
+
 struct spc2000_ {
     DCPU16_WORD skip_unit;
     long long skip;
@@ -16,7 +25,7 @@ int spc2000_data_init_(struct dcpu16_hw *hw, void *data) {
 
     hw->data = calloc(1, sizeof(struct spc2000_));
     if (hw->data == NULL) {
-        hw->vm->msg_cb_(DCPU16_MSG_ERROR, "%s():%s", "calloc", strerror(errno));
+        MSG_ERROR(hw->vm, "%s():%s", "calloc", strerror(errno));
         return -1;
     }
     return 0;
@@ -66,7 +75,7 @@ void spc2000_hwi_(struct dcpu16 *vm, struct dcpu16_hw *hw) {
             ||  vm->reg[DCPU16_REG_C] != 0)
                 break;
             /* trigger */
-            vm->msg_cb_(DCPU16_MSG_INFO, "spc2000 triggered\n");
+            MSG_INFO(vm, "spc2000 triggered\n");
             break;
 
         case 1: /* SET_UNIT_TO_SKIP */