# HG changeset patch # User Michael Pavone # Date 1491277693 25200 # Node ID b27d7bf1107ea1b60047345bdfccb8803328bd2a # Parent 9ab3f6781202c0347aac589cca8d6b5a89578810 Improved printing of word at absolute address to support reading from all address types. Implemented support for printing the value pointed to by a register. Removed abuse of read_dma_value in internal debugger. diff -r 9ab3f6781202 -r b27d7bf1107e backend.c --- a/backend.c Fri Mar 31 19:11:04 2017 -0700 +++ b/backend.c Mon Apr 03 20:48:13 2017 -0700 @@ -93,6 +93,42 @@ return NULL; } +uint16_t read_word(uint32_t address, void **mem_pointers, cpu_options *opts, void *context) +{ + memmap_chunk const *chunk = find_map_chunk(address, opts, 0, NULL); + if (!chunk) { + return 0xFFFF; + } + uint32_t offset = (address - chunk->start) & chunk->mask; + if (chunk->flags & MMAP_READ) { + uint8_t *base; + if (chunk->flags & MMAP_PTR_IDX) { + base = mem_pointers[chunk->ptr_index]; + } else { + base = chunk->buffer; + } + if (base) { + uint16_t val; + if ((chunk->flags & MMAP_ONLY_ODD) || (chunk->flags & MMAP_ONLY_EVEN)) { + offset /= 2; + uint16_t val = base[offset]; + if (chunk->flags & MMAP_ONLY_ODD) { + val |= 0xFF00; + } else { + val = val << 8 | 0xFF; + } + } else { + val = *(uint16_t *)(base + offset); + } + return val; + } + } + if ((!(chunk->flags & MMAP_READ) || (chunk->flags & MMAP_FUNC_NULL)) && chunk->read_16) { + return chunk->read_16(offset, context); + } + return 0xFFFF; +} + uint32_t chunk_size(cpu_options *opts, memmap_chunk const *chunk) { if (chunk->mask == opts->address_mask) { diff -r 9ab3f6781202 -r b27d7bf1107e backend.h --- a/backend.h Fri Mar 31 19:11:04 2017 -0700 +++ b/backend.h Mon Apr 03 20:48:13 2017 -0700 @@ -125,6 +125,7 @@ code_ptr gen_mem_fun(cpu_options * opts, memmap_chunk const * memmap, uint32_t num_chunks, ftype fun_type, code_ptr *after_inc); void * get_native_pointer(uint32_t address, void ** mem_pointers, cpu_options * opts); +uint16_t read_word(uint32_t address, void **mem_pointers, cpu_options *opts, void *context); memmap_chunk const *find_map_chunk(uint32_t address, cpu_options *opts, uint16_t flags, uint32_t *size_sum); uint32_t chunk_size(cpu_options *opts, memmap_chunk const *chunk); uint32_t ram_size(cpu_options *opts); diff -r 9ab3f6781202 -r b27d7bf1107e debug.c --- a/debug.c Fri Mar 31 19:11:04 2017 -0700 +++ b/debug.c Mon Apr 03 20:48:13 2017 -0700 @@ -88,6 +88,16 @@ } } +uint16_t m68k_read_word(uint32_t address, m68k_context *context) +{ + return read_word(address, (void **)context->mem_pointers, &context->options->gen, context); +} + +uint32_t m68k_read_long(uint32_t address, m68k_context *context) +{ + return m68k_read_word(address, context) << 16 | m68k_read_word(address + 2, context); +} + void debugger_print(m68k_context *context, char format_char, char *param) { uint32_t value; @@ -136,13 +146,11 @@ value = gen->vdp->frame; } else if ((param[0] == '0' && param[1] == 'x') || param[0] == '$') { uint32_t p_addr = strtol(param+(param[0] == '0' ? 2 : 1), NULL, 16); - if ((p_addr & 0xFFFFFF) == 0xC00004) { - genesis_context * gen = context->system; - value = vdp_hv_counter_read(gen->vdp); - } else { - uint16_t *word = get_native_pointer(p_addr & 0xFFFFFE, (void **)context->mem_pointers, &context->options->gen); - value = *word; - } + value = m68k_read_word(p_addr, context); + } else if(param[0] == '(' && (param[1] == 'a' || param[1] == 'd') && param[2] >= '0' && param[2] <= '7' && param[3] == ')') { + uint8_t reg = param[2] - '0'; + uint32_t p_addr = param[1] == 'a' ? context->aregs[reg] : context->dregs[reg]; + value = m68k_read_word(p_addr, context); } else { fprintf(stderr, "Unrecognized parameter to p: %s\n", param); return; @@ -714,9 +722,9 @@ break; case 'n': if (inst.op == M68K_RTS) { - after = (read_dma_value(context->aregs[7]/2) << 16) | read_dma_value(context->aregs[7]/2 + 1); + after = m68k_read_long(context->aregs[7], context); } else if (inst.op == M68K_RTE || inst.op == M68K_RTR) { - after = (read_dma_value((context->aregs[7]+2)/2) << 16) | read_dma_value((context->aregs[7]+2)/2 + 1); + after = m68k_read_long(context->aregs[7] + 2, context); } else if(m68k_is_noncall_branch(&inst)) { if (inst.op == M68K_BCC && inst.extra.cond != COND_TRUE) { branch_f = after; @@ -740,9 +748,9 @@ return 0; case 'o': if (inst.op == M68K_RTS) { - after = (read_dma_value(context->aregs[7]/2) << 16) | read_dma_value(context->aregs[7]/2 + 1); + after = m68k_read_long(context->aregs[7], context); } else if (inst.op == M68K_RTE || inst.op == M68K_RTR) { - after = (read_dma_value((context->aregs[7]+2)/2) << 16) | read_dma_value((context->aregs[7]+2)/2 + 1); + after = m68k_read_long(context->aregs[7] + 2, context); } else if(m68k_is_noncall_branch(&inst)) { if (inst.op == M68K_BCC && inst.extra.cond != COND_TRUE) { branch_t = m68k_branch_target(&inst, context->dregs, context->aregs) & 0xFFFFFF; @@ -771,9 +779,9 @@ return 0; case 's': if (inst.op == M68K_RTS) { - after = (read_dma_value(context->aregs[7]/2) << 16) | read_dma_value(context->aregs[7]/2 + 1); + after = m68k_read_long(context->aregs[7], context); } else if (inst.op == M68K_RTE || inst.op == M68K_RTR) { - after = (read_dma_value((context->aregs[7]+2)/2) << 16) | read_dma_value((context->aregs[7]+2)/2 + 1); + after = m68k_read_long(context->aregs[7] + 2, context); } else if(m68k_is_branch(&inst)) { if (inst.op == M68K_BCC && inst.extra.cond != COND_TRUE) { branch_f = after;