DCPU16_WORD pc = (DCPU16_WORD)(vm->reg[DCPU16_REG_PC] + *pc_adjust),
sp = (DCPU16_WORD)(vm->reg[DCPU16_REG_PC] + *sp_adjust);
- TRACE("%s: pc:0x%04x sp:0x%04x value_data:0x%04x\n",
+ TRACE("%s>> is_a:%u pc:0x%04x sp:0x%04x value_data:0x%04x\n",
__func__,
+ value_is_a,
pc,
sp,
value_data);
*a = (mem[addr] >> (OPCODE_BASIC_BITS + OPCODE_OPERAND_B_BITS)) & ((1 << OPCODE_OPERAND_A_BITS) - 1);
*instr_len = 1;
- if ( (*b >= 0x10 && *b <= 0x17) || *b == 0x1e || *b == 0x1f ) {
+ if ((*opcode != 0x0000) &&
+ ( (*b >= 0x10 && *b <= 0x17) || *b == 0x1e || *b == 0x1f ) ) {
*b_data = mem + (DCPU16_WORD)(addr + *instr_len);
- TRACE("**b_data:%hu", **b_data);
*instr_len += 1;
} else {
*b_data = NULL;
if ( (*opcode != 0x0000 || (*opcode == 0 && *b != 0x0000) )
&& ( (*a >= 0x10 && *a <= 0x17) || *a == 0x1e || *a == 0x1f) ) {
*a_data = mem + (DCPU16_WORD)(addr + *instr_len);
- TRACE("**a_data:%hu", **a_data);
*instr_len += 1;
} else {
*a_data = NULL;
}
-#if 0
TRACE("\n%s: [0x%04x]:0x%04x op:0x%02x b:0x%02x (b_data:0x%04x) a:0x%02x (a_data:0x%04x) len:0x%02x\n",
__func__,
addr,
*a,
*a_data ? **a_data : 0,
*instr_len);
-#endif
}
/* dcpu16_mnemonify_buf
size_t i;
const struct opcode_entry *e;
- if (!vm) return;
+ if (!vm)
+ return;
/* signal interested parties that a new cycle has ticked */
- TRACE("%s: sending global cycle event", __func__);
+ TRACE("%s>> sending global cycle event", __func__);
acct_event_(vm, DCPU16_ACCT_EV_CYCLE, vm->reg[DCPU16_REG_PC]);
/* signal attached hardware */
for (i = 0; i < vm->hw_table_entries_; i++) {
if (vm->hw_table_[i].cycle) {
- TRACE("%s: sending cycle to %s", __func__, vm->hw_table_[i].name_);
+ TRACE("%s>> sending cycle to %s", __func__, vm->hw_table_[i].name_);
vm->hw_table_[i].cycle(vm, vm->hw_table_[i].data);
}
}
message = interrupt_dequeue_(vm);
if (vm->reg[DCPU16_REG_IA]) {
- TRACE("servicing interrupt IA:0x%04x message:0x%04x \n", vm->reg[DCPU16_REG_IA], message);
+ TRACE("%s>> servicing interrupt IA:0x%04x message:0x%04x \n", __func__, vm->reg[DCPU16_REG_IA], message);
/* then service the next interrupt */
vm->interrupts_deferred_ = 1;
vm->ram[--vm->reg[DCPU16_REG_SP]] = vm->reg[DCPU16_REG_PC];
vm->reg[DCPU16_REG_PC] = vm->reg[DCPU16_REG_IA];
vm->reg[DCPU16_REG_A] = message;
} else {
- TRACE("ignoring interrupt IA:0");
+ TRACE("%s>> ignoring interrupt IA:0", __func__);
}
}
}
if (!vm || !hw)
return -1;
+ TRACE("%s>> name:%s ID:0x%04x%04x MFG:0x%04x%04x VER:0x%04x",
+ __func__,
+ hw->name_,
+ hw->id_h, hw->id_l,
+ hw->mfg_l, hw->mfg_h,
+ hw->ver);
+
if (vm->hw_table_entries_ == 0xffff) {
WARN("maximum hardware entries reached");
return -1;
memcpy(vm->hw_table_ + vm->hw_table_entries_, hw, sizeof *hw);
vm->hw_table_entries_++;
+ TRACE("%s>> added hw entry %zu", __func__, vm->hw_table_entries_);
+
return 0;
}
memcpy(vm->cb_table_ + vm->cb_table_entries_, &cb, sizeof cb);
vm->cb_table_entries_++;
+ TRACE("%s>> attached event callback %zu", __func__, vm->cb_table_entries_);
+
return 0;
}
if (!vm)
return;
+ TRACE("%s>> reset", __func__);
+
vm->skip_ = 0;
vm->interrupts_deferred_ = 0;
vm->on_fire_ = 0;
#include "chargen-4x8.h"
#include "hw_lem1802.h"
+#ifdef DEBUG
+#define TRACE(...) do { printf("[debug] "); printf(__VA_ARGS__); printf("\n"); } while (0)
+#else /* DEBUG */
+#define TRACE(...) do {} while (0)
+#endif /* DEBUG */
+
static dcpu16_hw_signal_t lem1802_reset_;
static dcpu16_hw_signal_t lem1802_cycle_;
static dcpu16_hw_signal_t lem1802_hwi_;
.data = (struct lem1802_ *)NULL
};
-#define PIX_X 160
-#define PIX_Y 128
-#define PIX_BORDER 16
+#define PIX_X 160 /* pixels in display */
+#define PIX_Y 128 /* pixels in display */
+#define PIX_BORDER 16 /* border pixels from edge to first tile */
#define CELL_X_SZ 4
#define CELL_Y_SZ 8
+#define CELL_X ((PIX_X - (2 * PIX_BORDER)) / CELL_X_SZ) /* tiles in display */
+#define CELL_Y ((PIX_Y - (2 * PIX_BORDER)) / CELL_Y_SZ) /* tiles in display */
#define PALETTE_ENTRIES 16
static const DCPU16_WORD palette_default_[PALETTE_ENTRIES] = {
void pixbuf_border_paint_(struct pixel_ *pixbuf, struct pixel_ *border) {
size_t x, y, i;
+ TRACE("%s>> painted border", __func__);
+
/* top */
for (y = 0; y < PIX_BORDER; y++) {
for (x = 0; x < PIX_X; x++) {
size_t pix_x, pix_y;
unsigned char *font_bitmap = (unsigned char *)tile;
+ TRACE("%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]);
+
for (pix_x = 0; pix_x < CELL_X_SZ; pix_x++) {
for (pix_y = 0; pix_y < CELL_Y_SZ; pix_y++) {
if ((font_bitmap[pix_x] >> pix_y) & 0x01)
}
static
-void pixbuf_addr_paint_(struct pixel_ *pixbuf, DCPU16_WORD *mem, DCPU16_WORD addr, DCPU16_WORD *palette, DCPU16_WORD *tiles, unsigned int blink_state) {
+void pixbuf_addr_paint_(struct pixel_ *pixbuf, DCPU16_WORD *mem, DCPU16_WORD base, DCPU16_WORD addr, DCPU16_WORD *palette, DCPU16_WORD *tiles, unsigned int blink_state) {
struct pixel_ *tilestart = pixbuf; /* start of display */
unsigned int cell_x = addr % (PIX_X / CELL_X_SZ),
cell_y = addr / (PIX_X / CELL_X_SZ);
DCPU16_WORD *font_bitmap;
int blink;
- cell_x = addr % (PIX_X / CELL_X_SZ);
- cell_y = addr / (PIX_X / CELL_X_SZ);
+ cell_x = (addr - base) % CELL_X;
+ cell_y = (addr - base) / CELL_X;
+
+ TRACE("%s>> addr:0x%04x col:%u row:%u v:%hu",
+ __func__,
+ addr,
+ cell_x, cell_y, mem[addr]);
blink = mem[addr] & 0x0080;
struct pixel_ border;
size_t tile;
+ TRACE("%s>> video_base:0x%04x", __func__, display->video_base);
+
if (display->video_base == 0) {
/* disconnected, blank display. static might be fun, too */
memset(display->pixbuf, 0, PIX_X * PIX_Y * sizeof *display->pixbuf);
pixel_color_(&border, display->border_color);
pixbuf_border_paint_(display->pixbuf, &border);
- for (tile = 0; tile < (PIX_X / CELL_X_SZ) * (PIX_Y / CELL_Y_SZ); tile++) {
+ for (tile = 0; tile < CELL_X * CELL_Y; tile++) {
pixbuf_addr_paint_(display->pixbuf,
mem,
+ display->video_base,
display->video_base + tile,
display->palette_base ? mem + display->palette_base : palette_default_,
display->font_base ? mem + display->font_base : (unsigned short *)chargen_4x8_glyphs,
return NULL;
}
- s->rfbScreen->desktopName = "lem1802";
+ s->rfbScreen->desktopName = "NYA ELEKTRISKA LEM1802";
s->rfbScreen->alwaysShared = TRUE;
#if 0
rfbRunEventLoop(s->rfbScreen,-1,TRUE);
+ TRACE("%s>> initialized new vnc server", __func__);
+
return s;
}
/* derp */
rfbMarkRectAsModified(s->rfbScreen,0,0,x,y);
+ TRACE("%s>>", __func__);
+
return retval;
}
#endif /* HAVE_LIBVNCSERVER */
void lem1802_reset_(struct dcpu16 *vm, void *data) {
struct lem1802_ *display = (struct lem1802_ *)data;
- display->cycle_activated = vm->cycle;
+ (void)vm;
+ display->cycle_activated = 0;
display->video_base = 0;
display->font_base = 0;
display->palette_base = 0;
display->refresh_tally_ = 0;
display->blink_tally_ = 0;
display->blink_state = 0;
+
+#if DEBUG
+ vm->trace_cb_("%s>>", __func__);
+#endif /* DEBUG */
}
static
*/
display->blink_tally_++;
- if (display->blink_tally_ >= display->blink_rate)
+ 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);
+ }
display->refresh_tally_++;
if (display->refresh_tally_ >= display->refresh_rate) {
display->refresh_tally_ = 0;
if (display->render)
+ TRACE("%s>> refresh", __func__);
+ lem1802_pixbuf_refresh_full_(display, vm->ram);
display->render(display->renderer_data, display->pixbuf, PIX_X, PIX_Y);
}
-
- if (display->render) {
- lem1802_pixbuf_refresh_full_(display, vm->ram);
- display->render(display->renderer_data, display->pixbuf, PIX_X, PIX_Y);
- }
}
static
DCPU16_WORD reg_b = vm->reg[DCPU16_REG_B];
size_t i;
+ TRACE("%s>> A:0x%04x B:0x%04x", __func__, reg_a, reg_b);
+
switch (reg_a) {
case 0: /* MEM_MAP_SCREEN */
if (display->cycle_activated == 0 && reg_b) {
display->cycle_activated = vm->cycle;
}
display->video_base = reg_b;
+ if (reg_b == 0)
+ display->cycle_activated = 0;
break;
case 1: /* MEM_MAP_FONT */
if (strcmp(renderer, r->name) == 0) {
((struct lem1802_ *)(hw->data))->render = r->renderer;
((struct lem1802_ *)(hw->data))->renderer_data = data;
+ TRACE("%s>> renderer set to %s", __func__, renderer);
return 0;
}
}
return NULL;
}
+ ((struct lem1802_ *)(hw->data))->refresh_rate = 1666;
+ ((struct lem1802_ *)(hw->data))->blink_rate = 75000;
+
return hw;
}