X-Git-Url: http://git.squeep.com/?p=dcpu16;a=blobdiff_plain;f=hw_lem1802.c;fp=hw_lem1802.c;h=4cdaa2f4d6b69ed644a0300ad6e5a6f68d694c39;hp=1ae7b57d049452da312165b70444d0fd41ba5ec8;hb=052f0d9ed1165dabd061c8eac39c3be71184a5cf;hpb=1470698024f5511a3b94b7bb50b1097cc6659b32 diff --git a/hw_lem1802.c b/hw_lem1802.c index 1ae7b57..4cdaa2f 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 */ @@ -539,13 +540,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; @@ -670,12 +671,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>> renderer set to %s", __func__, renderer); return 0; } } - hw->vm->msg_cb_(MSG_ERROR, "unknown renderer '%s'", renderer); + MSG_ERROR(hw->vm, "unknown renderer '%s'", renderer); return -ENOENT; }