#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;
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_);
}
}
}
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;
#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;
struct dcpu16_hw *hw = (struct dcpu16_hw *)cl->screen->screenData;
struct keyboard_ *keyboard = (struct keyboard_ *)hw->data;
-#ifdef DEBUG
- hw->vm->msg_cb_(DCPU16_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 */
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_(DCPU16_MSG_INFO, "keyboard buffer overflow");
+ MSG_INFO(hw->vm, "keyboard buffer overflow");
return;
}
keyboard->buf[keyboard->buf_tail] = dcpu_key;
keyboard->buf_head = 0;
keyboard->buf_tail = 0;
memset(keyboard->keys_pressed, 0, sizeof keyboard->keys_pressed);
+
+ MSG_DEBUG(vm, "%s>>", __func__);
}
static
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 */
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;
}
hw->data = calloc(1, sizeof(struct keyboard_));
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;
}
((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_(DCPU16_MSG_ERROR, "%s():%s", "malloc", strerror(errno));
+ MSG_ERROR(hw->vm, "%s():%s", "malloc", strerror(errno));
free(hw->data);
hw->data = NULL;
return -1;
}
if (buf_sz_in) {
-#ifdef DEBUG
- hw->vm->msg_cb_(DCPU16_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_(DCPU16_MSG_DEBUG, "%s():%s", "realloc", strerror(errno));
+ MSG_ERROR(hw->vm, "%s():%s", "realloc", strerror(errno));
return -1;
}
keyboard->buf = tmp_ptr;
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;
}
rfbScreen->screenData = hw;
rfbScreen->kbdAddEvent = keyboard_rfbevent_;
+ MSG_DEBUG(hw->vm, "%s>> %s rfbScreen:%p", __func__, "associate_rfbScreen", rfbScreen);
+
return 0;
}
#endif /* HAVE_LIBVNCSERVER */
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 */
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;
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;
}
display->blink_rate = *rate_in;
}
+ MSG_DEBUG(hw->vm, "%s>> %s now:%u was:%u", __func__, "blink_rate", *rate_in, *rate_out);
+
return 0;
}
display->refresh_rate = *rate_in;
}
+ MSG_DEBUG(hw->vm, "%s>> %s now:%u was:%u", __func__, "refresh_rate", *rate_in, *rate_out);
+
return 0;
}
*s_out = lem1802_rfb_new_(in->argc, in->argv);
+ MSG_DEBUG(hw->vm, "%s>> %s s:%p", __func__, "new_rfbScreen", *s_out);
+
return 0;
}
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 */
(void)lem1802_renderers_iter_(iterp, &parg->name, &parg->args);
+ MSG_DEBUG(hw->vm, "%s>> %s", __func__, "renderers_iter");
+
return 0;
}
display->renderer_data = data_in;
+ MSG_DEBUG(hw->vm, "%s>> %s data:%p", __func__, "renderer_data", data_in);
+
return 0;
}
#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;
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;
|| 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 */