X-Git-Url: http://git.squeep.com/?p=dcpu16;a=blobdiff_plain;f=hw_clock.c;h=252c08f28096d78832a99736a2bc70e57d94b129;hp=fb9e195abe410b6f3c29fe82c4f110a3fbb09bef;hb=HEAD;hpb=052f0d9ed1165dabd061c8eac39c3be71184a5cf diff --git a/hw_clock.c b/hw_clock.c index fb9e195..252c08f 100644 --- a/hw_clock.c +++ b/hw_clock.c @@ -5,6 +5,15 @@ #include "dcpu16.h" #include "hw_clock.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 clock_ { DCPU16_WORD cycle_; DCPU16_WORD rate; @@ -39,7 +48,7 @@ void clock_cycle_(struct dcpu16 *vm, struct dcpu16_hw *hw) { if (clock->interrupt_message) { if (dcpu16_interrupt(vm, clock->interrupt_message)) - vm->msg_cb_(DCPU16_MSG_ERROR, "%s: could not send interrupt", hw->mod->name_); + MSG_ERROR(vm, "%s: could not send interrupt", hw->mod->name_); } } } @@ -71,7 +80,7 @@ int clock_data_init_(struct dcpu16_hw *hw, void *data) { hw->data = calloc(1, sizeof(struct clock_)); 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;