From ff3d78d4e1781afbac5d2e9e0fe8361f850bbccb Mon Sep 17 00:00:00 2001 From: Justin Wind Date: Thu, 24 May 2012 18:38:38 -0700 Subject: [PATCH] further cleanup of message callback changes --- dcpu16.c | 10 ++++---- dcpu16.h | 11 ++++----- hw_clock.c | 13 +++++++++-- hw_keyboard.c | 39 +++++++++++++++++++++++-------- hw_lem1802.c | 63 +++++++++++++++++++++++++++++++++------------------ hw_spc2000.c | 13 +++++++++-- vm-dcpu16.c | 2 +- 7 files changed, 103 insertions(+), 48 deletions(-) diff --git a/dcpu16.c b/dcpu16.c index c63c800..0b1d391 100644 --- a/dcpu16.c +++ b/dcpu16.c @@ -55,15 +55,15 @@ const char * const dcpu16_reg_names[] = { }; #define MSG_(__level__, __vm__, ...) do { ((__vm__) ? ((struct dcpu16 *)(__vm__))->msg_cb_ : dcpu16_msg_)((__level__), __VA_ARGS__); } while (0) -#define MSG_INFO(__vm__,...) MSG_(MSG_INFO, __vm__, __VA_ARGS__) -#define MSG_ERROR(__vm__,...) MSG_(MSG_ERROR, __vm__, __VA_ARGS__) +#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_(MSG_DEBUG, __vm__, __VA_ARGS__) +#define MSG_DEBUG(__vm__,...) MSG_(DCPU16_MSG_DEBUG, __vm__, __VA_ARGS__) #else /* DEBUG */ #define MSG_DEBUG(__vm__,...) do {} while (0) #endif /* DEBUG */ #ifdef DEBUG_DECODE -#define MSG_DEBUG_DECODE (MSG_DEBUG + 2) +#define MSG_DEBUG_DECODE (DCPU16_MSG_DEBUG + 2) #endif /* DEBUG_DECODE /* messages could be sent nowhere */ @@ -74,7 +74,7 @@ static void msg_default_(unsigned int, char *, ...) __attribute__((format(printf static inline void msg_default_(unsigned int l, char *fmt, ...) { static const char * const msg_tag_[] = { "info", "error", "debug" }; - FILE *f = (l <= MSG_INFO) ? stderr : stdout; + FILE *f = (l <= DCPU16_MSG_INFO) ? stderr : stdout; va_list ap; if (l < sizeof msg_tag_ / sizeof *msg_tag_) diff --git a/dcpu16.h b/dcpu16.h index 1f46d45..b571078 100644 --- a/dcpu16.h +++ b/dcpu16.h @@ -32,17 +32,16 @@ typedef void (dcpu16_msg_cb_t)(unsigned int, char *, ...); /* we may emit any of these types of messages */ enum dcpu16_msg_type { - MSG_ERROR = 0, - MSG_INFO, - MSG_DEBUG + DCPU16_MSG_ERROR = 0, + DCPU16_MSG_INFO, + DCPU16_MSG_DEBUG }; /* update the default message handler */ dcpu16_msg_cb_t *dcpu16_msg_set_default(dcpu16_msg_cb_t *); -/* -extern dcpu16_msg_cb_t *dcpu16_msg; -*/ +/* hardware devices may want to call this directly, without a core context */ +extern dcpu16_msg_cb_t *dcpu16_msg_; /* a self-contained dcpu16 core */ struct dcpu16 { diff --git a/hw_clock.c b/hw_clock.c index ebd58fd..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_(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_(MSG_ERROR, "%s():%s", "calloc", strerror(errno)); + MSG_ERROR(hw->vm, "%s():%s", "calloc", strerror(errno)); return -1; } return 0; diff --git a/hw_keyboard.c b/hw_keyboard.c index f69b8f4..89f91ec 100644 --- a/hw_keyboard.c +++ b/hw_keyboard.c @@ -18,6 +18,15 @@ #define VOIDP(__x__) (__x__) #endif +#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 keyboard_ { char *buf; size_t buf_sz; @@ -70,9 +79,7 @@ void keyboard_rfbevent_(rfbBool down, rfbKeySym key, rfbClientPtr cl) { struct dcpu16_hw *hw = (struct dcpu16_hw *)cl->screen->screenData; struct keyboard_ *keyboard = (struct keyboard_ *)hw->data; -#ifdef DEBUG - hw->vm->msg_cb_(MSG_DEBUG, "%s>> down:%u rfb_key:0x%04x", down, key); -#endif /* DEBUG */ + MSG_DEBUG(hw->vm, "%s>> down:%u rfb_key:0x%04x", down, key); if (keysym_rfbtodcpu(key, &dcpu_key)) { /* unhandled key event */ @@ -82,7 +89,7 @@ void keyboard_rfbevent_(rfbBool down, rfbKeySym key, rfbClientPtr cl) { keyboard->keys_pressed[dcpu_key] = (down ? 1 : 0); if (down) { if ((keyboard->buf_tail + 1) % keyboard->buf_sz == keyboard->buf_head) { - hw->vm->msg_cb_(MSG_INFO, "keyboard buffer overflow"); + MSG_INFO(hw->vm, "keyboard buffer overflow"); return; } keyboard->buf[keyboard->buf_tail] = dcpu_key; @@ -105,6 +112,8 @@ void keyboard_reset_(struct dcpu16 *vm, struct dcpu16_hw *hw) { keyboard->buf_head = 0; keyboard->buf_tail = 0; memset(keyboard->keys_pressed, 0, sizeof keyboard->keys_pressed); + + MSG_DEBUG(vm, "%s>>", __func__); } static @@ -125,6 +134,8 @@ void keyboard_hwi_(struct dcpu16 *vm, struct dcpu16_hw *hw) { memset(keyboard->buf, 0, keyboard->buf_sz); keyboard->buf_head = 0; keyboard->buf_tail = 0; + + MSG_DEBUG(vm, "%s>> buffer cleared", __func__); break; case 1: /* get next key from buffer as C */ @@ -133,14 +144,20 @@ void keyboard_hwi_(struct dcpu16 *vm, struct dcpu16_hw *hw) { vm->reg[DCPU16_REG_C] = keyboard->buf[keyboard->buf_head]; keyboard->buf_head += 1; keyboard->buf_head %= keyboard->buf_sz; + + MSG_DEBUG(vm, "%s>> next key: %u", __func__, vm->reg[DCPU16_REG_C]); break; case 2: /* get currently-pressed-state of key in B as C */ vm->reg[DCPU16_REG_C] = keyboard->keys_pressed[reg_b & 0x00ff]; + + MSG_DEBUG(vm, "%s>> state of key 0x%02x: %spressed", __func__, reg_b & 0x00ff, keyboard->keys_pressed[reg_b & 0x00ff] ? "" : "not "); break; case 3: /* set interrupt state */ keyboard->interrupt_message = reg_b; + + MSG_DEBUG(vm, "%s>> interrupt_message:0x%04x", __func__, reg_b); break; } @@ -152,13 +169,13 @@ int keyboard_data_init_(struct dcpu16_hw *hw, void *data) { hw->data = calloc(1, sizeof(struct keyboard_)); if (hw->data == NULL) { - hw->vm->msg_cb_(MSG_ERROR, "%s():%s", "calloc", strerror(errno)); + MSG_ERROR(hw->vm, "%s():%s", "calloc", strerror(errno)); return -1; } ((struct keyboard_ *)(hw->data))->buf = malloc(buf_sz * sizeof *((struct keyboard_ *)(hw->data))->buf); if (((struct keyboard_ *)(hw->data))->buf == NULL) { - hw->vm->msg_cb_(MSG_ERROR, "%s():%s", "malloc", strerror(errno)); + MSG_ERROR(hw->vm, "%s():%s", "malloc", strerror(errno)); free(hw->data); hw->data = NULL; return -1; @@ -201,13 +218,11 @@ int keyboard_data_ctl_(struct dcpu16_hw *hw, const char *cmd, void *data_in, voi } if (buf_sz_in) { -#ifdef DEBUG - hw->vm->msg_cb_(MSG_DEBUG, "%s>> resizing buffer from %zu to %zu", __func__, keyboard->buf_sz, *buf_sz_in); -#endif /* DEBUG */ + MSG_DEBUG(hw->vm, "%s>> resizing buffer from %zu to %zu", __func__, keyboard->buf_sz, *buf_sz_in); tmp_ptr = realloc(keyboard->buf, *buf_sz_in); if (tmp_ptr == NULL) { - hw->vm->msg_cb_(MSG_DEBUG, "%s():%s", "realloc", strerror(errno)); + MSG_ERROR(hw->vm, "%s():%s", "realloc", strerror(errno)); return -1; } keyboard->buf = tmp_ptr; @@ -215,6 +230,8 @@ int keyboard_data_ctl_(struct dcpu16_hw *hw, const char *cmd, void *data_in, voi keyboard->buf_head = keyboard->buf_tail = 0; } + MSG_DEBUG(hw->vm, "%s>> %s now:%zu was:%zu", __func__, "buffer_size", *buf_sz_in, *buf_sz_out); + return 0; } @@ -229,6 +246,8 @@ int keyboard_data_ctl_(struct dcpu16_hw *hw, const char *cmd, void *data_in, voi rfbScreen->screenData = hw; rfbScreen->kbdAddEvent = keyboard_rfbevent_; + MSG_DEBUG(hw->vm, "%s>> %s rfbScreen:%p", __func__, "associate_rfbScreen", rfbScreen); + return 0; } #endif /* HAVE_LIBVNCSERVER */ diff --git a/hw_lem1802.c b/hw_lem1802.c index 1ae7b57..c54455d 100644 --- a/hw_lem1802.c +++ b/hw_lem1802.c @@ -24,10 +24,13 @@ * multiple vnc displays */ +#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 TRACE(...) do { printf("[debug] "); printf(__VA_ARGS__); printf("\n"); } while (0) +#define MSG_DEBUG(__vm__, ...) MSG_(DCPU16_MSG_DEBUG, __vm__, __VA_ARGS__) #else /* DEBUG */ -#define TRACE(...) do {} while (0) +#define MSG_DEBUG(__vm__, ...) do { } while (0) #endif /* DEBUG */ #ifdef WANT_VARIADIC_VOIDP_CAST @@ -140,7 +143,7 @@ static void pixbuf_border_paint_(struct pixel_ *pixbuf, struct pixel_ *border) { size_t x, y, i; - TRACE("%s>> painting border", __func__); + MSG_DEBUG(NULL, "%s>> painting border", __func__); /* top */ for (y = 0; y < PIX_BORDER; y++) { @@ -167,7 +170,7 @@ void font_tile_paint_(struct pixel_ *p, struct pixel_ *fg, struct pixel_ *bg, DC unsigned char *font_bitmap = (unsigned char *)tile; #if 0 - TRACE("%s>> fg:(%u,%u,%u) bg:(%u,%u,%u) font_bitmap:%02x %02x %02x %02x", __func__, + MSG_DEBUG(NULL, "%s>> fg:(%u,%u,%u) bg:(%u,%u,%u) font_bitmap:%02x %02x %02x %02x", __func__, fg->r, fg->g, fg->b, bg->r, bg->g, bg->b, font_bitmap[0], font_bitmap[1], font_bitmap[2], font_bitmap[3]); @@ -196,7 +199,7 @@ void pixbuf_addr_paint_(struct pixel_ *pixbuf, DCPU16_WORD *mem, DCPU16_WORD bas cell_y = (addr - base) / CELL_X; #if 0 - TRACE("%s>> addr:0x%04x col:%u row:%u v:%hu", + MSG_DEBUG(NULL, "%s>> addr:0x%04x col:%u row:%u v:%hu", __func__, addr, cell_x, cell_y, mem[addr]); @@ -228,7 +231,7 @@ void lem1802_pixbuf_refresh_full_(struct lem1802_ *display, DCPU16_WORD *mem) { size_t tile; #if 0 - TRACE("%s>> video_base:0x%04x", __func__, display->video_base); + MSG_DEBUG(NULL, "%s>> video_base:0x%04x", __func__, display->video_base); #endif if (display->cycles_until_active_) { @@ -339,8 +342,8 @@ rfbScreenInfoPtr lem1802_rfb_new_(int argc, char *argv[]) { s->httpDir = "../classes"; #endif - TRACE("%s>> s:%p", __func__, VOIDP(s)); - TRACE("%s>> s->kbdAddEvent:%p s->frameBuffer:%p", __func__, VOIDFP(s->kbdAddEvent), s->frameBuffer); + MSG_DEBUG(NULL, "%s>> s:%p", __func__, VOIDP(s)); + MSG_DEBUG(NULL, "%s>> s->kbdAddEvent:%p s->frameBuffer:%p", __func__, VOIDFP(s->kbdAddEvent), s->frameBuffer); return s; } @@ -354,13 +357,13 @@ int pixbuf_render_vnc_(void *data, struct pixel_ *pixbuf, size_t x, size_t y) { (void)pixbuf; - TRACE("%s>> s:%p", __func__, s); + MSG_DEBUG(NULL, "%s>> s:%p", __func__, s); /* derp */ if (s) rfbMarkRectAsModified(s, 0, 0, x, y); - TRACE("%s>>", __func__); + MSG_DEBUG(NULL, "%s>>", __func__); return retval; } @@ -387,9 +390,7 @@ void lem1802_reset_(struct dcpu16 *vm, struct dcpu16_hw *hw) { display->cycle_state_ = 0; -#if DEBUG - vm->msg_cb_(MSG_DEBUG, "%s>>", __func__); -#endif /* DEBUG */ + MSG_DEBUG(vm, "%s>>", __func__); } static @@ -408,14 +409,14 @@ void lem1802_cycle_(struct dcpu16 *vm, struct dcpu16_hw *hw) { if (display->blink_tally_ >= display->blink_rate) { display->blink_tally_ = 0; display->blink_state ^= 1; - TRACE("%s>> blink:%u (%u cycles)", __func__, display->blink_state, display->blink_rate); + MSG_DEBUG(vm, "%s>> blink:%u (%u cycles)", __func__, display->blink_state, display->blink_rate); } display->refresh_tally_++; if (display->refresh_tally_ >= display->refresh_rate) { display->refresh_tally_ = 0; if (display->render) - TRACE("%s>> refresh", __func__); + MSG_DEBUG(vm, "%s>> refresh", __func__); lem1802_pixbuf_refresh_full_(display, vm->ram); display->render(display->renderer_data, display->pixbuf, PIX_X, PIX_Y); } @@ -425,7 +426,7 @@ void lem1802_cycle_(struct dcpu16 *vm, struct dcpu16_hw *hw) { break; case CYCLE_COPY_TO_RAM: - TRACE("%s>> copy_to_ram words:%zu src:%p dst_addr:0x%04x", + MSG_DEBUG(vm, "%s>> copy_to_ram words:%zu src:%p dst_addr:0x%04x", __func__, display->cycle_state_copy_words_, VOIDP(display->cycle_state_copy_src_ptr_), @@ -443,7 +444,7 @@ void lem1802_cycle_(struct dcpu16 *vm, struct dcpu16_hw *hw) { if (display->cycles_until_active_) { display->cycles_until_active_--; if (display->cycles_until_active_ == 0) { - TRACE("%s>> display now active", __func__); + MSG_DEBUG(vm, "%s>> display now active", __func__); } } } @@ -454,7 +455,7 @@ void lem1802_hwi_(struct dcpu16 *vm, struct dcpu16_hw *hw) { DCPU16_WORD reg_a = vm->reg[DCPU16_REG_A]; DCPU16_WORD reg_b = vm->reg[DCPU16_REG_B]; - TRACE("%s>> A:0x%04x B:0x%04x", __func__, reg_a, reg_b); + MSG_DEBUG(vm, "%s>> A:0x%04x B:0x%04x", __func__, reg_a, reg_b); switch (reg_a) { case 0: /* MEM_MAP_SCREEN */ @@ -465,18 +466,22 @@ void lem1802_hwi_(struct dcpu16 *vm, struct dcpu16_hw *hw) { display->video_base = reg_b; if (reg_b == 0) display->cycle_activated = 0; + MSG_DEBUG(vm, "%s>> video_base:0x%04x", __func__, reg_b); break; case 1: /* MEM_MAP_FONT */ display->font_base = reg_b; + MSG_DEBUG(vm, "%s>> font_base:0x%04x", __func__, reg_b); break; case 2: /* MEM_MAP_PALETTE */ display->palette_base = reg_b; + MSG_DEBUG(vm, "%s>> palette_base:0x%04x", __func__, reg_b); break; case 3: /* SET_BORDER_COLOR */ display->border_color = reg_b & 0x000f; + MSG_DEBUG(vm, "%s>> border_color_index:0x%01x", __func__, reg_b & 0x000f); break; case 4: /* MEM_DUMP_FONT */ @@ -484,6 +489,7 @@ void lem1802_hwi_(struct dcpu16 *vm, struct dcpu16_hw *hw) { display->cycle_state_copy_dst_addr_ = reg_b; display->cycle_state_copy_words_ = 256; display->cycle_state_ = CYCLE_COPY_TO_RAM; + MSG_DEBUG(vm, "%s>> copying default font into 0x%04x - 0x%04x", __func__, reg_b, reg_b + 256); dcpu16_cycle_inc(vm, 256); break; @@ -492,6 +498,7 @@ void lem1802_hwi_(struct dcpu16 *vm, struct dcpu16_hw *hw) { display->cycle_state_copy_dst_addr_ = reg_b; display->cycle_state_copy_words_ = 16; display->cycle_state_ = CYCLE_COPY_TO_RAM; + MSG_DEBUG(vm, "%s>> copying default palette into 0x%04x - 0x%04x", __func__, reg_b, reg_b + 16); dcpu16_cycle_inc(vm, 16); break; } @@ -539,13 +546,13 @@ int lem1802_data_init_(struct dcpu16_hw *hw, void *data) { hw->data = calloc(1, sizeof(struct lem1802_)); if (hw->data == NULL) { - hw->vm->msg_cb_(MSG_ERROR, "%s():%s", "calloc", strerror(errno)); + MSG_ERROR(hw->vm, "%s():%s", "calloc", strerror(errno)); return -1; } ((struct lem1802_ *)(hw->data))->pixbuf = calloc(PIX_X * PIX_Y, sizeof *((struct lem1802_ *)(hw->data))->pixbuf); if (((struct lem1802_ *)(hw->data))->pixbuf == NULL) { - hw->vm->msg_cb_(MSG_ERROR, "%s():%s", "calloc", strerror(errno)); + MSG_ERROR(hw->vm, "%s():%s", "calloc", strerror(errno)); free(hw->data); hw->data = NULL; return -1; @@ -599,6 +606,8 @@ int lem1802_data_ctl_(struct dcpu16_hw *hw, const char *cmd, void *data_in, void display->blink_rate = *rate_in; } + MSG_DEBUG(hw->vm, "%s>> %s now:%u was:%u", __func__, "blink_rate", *rate_in, *rate_out); + return 0; } @@ -615,6 +624,8 @@ int lem1802_data_ctl_(struct dcpu16_hw *hw, const char *cmd, void *data_in, void display->refresh_rate = *rate_in; } + MSG_DEBUG(hw->vm, "%s>> %s now:%u was:%u", __func__, "refresh_rate", *rate_in, *rate_out); + return 0; } @@ -628,6 +639,8 @@ int lem1802_data_ctl_(struct dcpu16_hw *hw, const char *cmd, void *data_in, void *s_out = lem1802_rfb_new_(in->argc, in->argv); + MSG_DEBUG(hw->vm, "%s>> %s s:%p", __func__, "new_rfbScreen", *s_out); + return 0; } @@ -642,6 +655,8 @@ int lem1802_data_ctl_(struct dcpu16_hw *hw, const char *cmd, void *data_in, void rfbScreen->desktopName = "NYA ELEKTRISKA LEM1802"; rfbScreen->frameBuffer = (char *)display->pixbuf; + MSG_DEBUG(hw->vm, "%s>> %s rfbScreen:%p", __func__, "associate_rfbScreen", rfbScreen); + return 0; } #endif /* HAVE_LIBVNCSERVER */ @@ -658,6 +673,8 @@ int lem1802_data_ctl_(struct dcpu16_hw *hw, const char *cmd, void *data_in, void (void)lem1802_renderers_iter_(iterp, &parg->name, &parg->args); + MSG_DEBUG(hw->vm, "%s>> %s", __func__, "renderers_iter"); + return 0; } @@ -670,12 +687,12 @@ int lem1802_data_ctl_(struct dcpu16_hw *hw, const char *cmd, void *data_in, void for (r = lem1802_renderers_; r->renderer; r++) { if (strcmp(renderer, r->name) == 0) { display->render = r->renderer; - TRACE("%s>> renderer set to %s", __func__, renderer); + MSG_DEBUG(hw->vm, "%s>> %s set to %s", __func__, "renderer", renderer); return 0; } } - hw->vm->msg_cb_(MSG_ERROR, "unknown renderer '%s'", renderer); + MSG_ERROR(hw->vm, "unknown renderer '%s'", renderer); return -ENOENT; } @@ -686,6 +703,8 @@ int lem1802_data_ctl_(struct dcpu16_hw *hw, const char *cmd, void *data_in, void display->renderer_data = data_in; + MSG_DEBUG(hw->vm, "%s>> %s data:%p", __func__, "renderer_data", data_in); + return 0; } diff --git a/hw_spc2000.c b/hw_spc2000.c index f34b276..151b98c 100644 --- a/hw_spc2000.c +++ b/hw_spc2000.c @@ -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_(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_(MSG_INFO, "spc2000 triggered\n"); + MSG_INFO(vm, "spc2000 triggered\n"); break; case 1: /* SET_UNIT_TO_SKIP */ diff --git a/vm-dcpu16.c b/vm-dcpu16.c index aefbcf1..e46f27b 100644 --- a/vm-dcpu16.c +++ b/vm-dcpu16.c @@ -803,7 +803,7 @@ COMMAND_HELP(help) { static void msg_verbose_filter_(unsigned int level, char *fmt, ...) { static const char * const levels[] = { "error", "info", "debug" }; - FILE *f = (level <= MSG_ERROR) ? stderr : stdout; + FILE *f = (level <= DCPU16_MSG_ERROR) ? stderr : stdout; va_list ap; if (level + 2 > opt_.verbose) -- 2.45.2