src/emu/debug/debugvw.c
| r3912 | r3913 | |
| 268 | 268 | static int memory_view_needs_recompute(debug_view *view); |
| 269 | 269 | static void memory_view_get_cursor_pos(debug_view *view, offs_t *address, UINT8 *shift); |
| 270 | 270 | static void memory_view_set_cursor_pos(debug_view *view, offs_t address, UINT8 shift); |
| 271 | | static UINT64 memory_view_read(debug_view_memory *memdata, UINT8 size, offs_t offs); |
| 271 | static int memory_view_read(debug_view_memory *memdata, UINT8 size, offs_t offs, UINT64 *data); |
| 272 | 272 | static void memory_view_write(debug_view_memory *memdata, UINT8 size, offs_t offs, UINT64 data); |
| 273 | 273 | |
| 274 | 274 | static const debug_view_callbacks callback_table[] = |
| r3912 | r3913 | |
| 2443 | 2443 | /* then add all the memory regions */ |
| 2444 | 2444 | for (rgntag = memory_region_next(machine, NULL); rgntag != NULL; rgntag = memory_region_next(machine, rgntag)) |
| 2445 | 2445 | { |
| 2446 | UINT32 length = memory_region_length(machine, rgntag); |
| 2446 | 2447 | UINT32 flags = memory_region_flags(machine, rgntag); |
| 2447 | | UINT8 little_endian = ((flags & ROMREGION_ENDIANMASK) == ROMREGION_LE); |
| 2448 | | UINT8 width = 1 << ((flags & ROMREGION_WIDTHMASK) >> 8); |
| 2449 | | memory_subview_item *subview; |
| 2450 | 2448 | |
| 2451 | | /* determine the string and allocate a subview large enough */ |
| 2452 | | astring_printf(tempstring, "Region '%s'", rgntag); |
| 2453 | | subview = auto_malloc(sizeof(*subview) + astring_len(tempstring)); |
| 2454 | | memset(subview, 0, sizeof(*subview)); |
| 2449 | if (length > 0 && (flags & ROMREGION_DATATYPEMASK) == ROMREGION_DATATYPEROM) |
| 2450 | { |
| 2451 | UINT8 little_endian = ((flags & ROMREGION_ENDIANMASK) == ROMREGION_LE); |
| 2452 | UINT8 width = 1 << ((flags & ROMREGION_WIDTHMASK) >> 8); |
| 2453 | memory_subview_item *subview; |
| 2455 | 2454 | |
| 2456 | | /* populate the subview */ |
| 2457 | | subview->next = NULL; |
| 2458 | | subview->index = curindex++; |
| 2459 | | subview->base = memory_region(machine, rgntag); |
| 2460 | | subview->length = memory_region_length(machine, rgntag); |
| 2455 | /* determine the string and allocate a subview large enough */ |
| 2456 | astring_printf(tempstring, "Region '%s'", rgntag); |
| 2457 | subview = auto_malloc(sizeof(*subview) + astring_len(tempstring)); |
| 2458 | memset(subview, 0, sizeof(*subview)); |
| 2459 | |
| 2460 | /* populate the subview */ |
| 2461 | subview->next = NULL; |
| 2462 | subview->index = curindex++; |
| 2463 | subview->base = memory_region(machine, rgntag); |
| 2464 | subview->length = memory_region_length(machine, rgntag); |
| 2461 | 2465 | #ifdef LSB_FIRST |
| 2462 | | subview->offsetxor = width - 1; |
| 2466 | subview->offsetxor = width - 1; |
| 2463 | 2467 | #else |
| 2464 | | subview->offsetxor = 0; |
| 2468 | subview->offsetxor = 0; |
| 2465 | 2469 | #endif |
| 2466 | | subview->endianness = little_endian ? ENDIANNESS_LITTLE : ENDIANNESS_BIG; |
| 2467 | | subview->prefsize = MIN(width, 8); |
| 2468 | | strcpy(subview->name, astring_c(tempstring)); |
| 2470 | subview->endianness = little_endian ? ENDIANNESS_LITTLE : ENDIANNESS_BIG; |
| 2471 | subview->prefsize = MIN(width, 8); |
| 2472 | strcpy(subview->name, astring_c(tempstring)); |
| 2469 | 2473 | |
| 2470 | | /* add to the list */ |
| 2471 | | *tailptr = subview; |
| 2472 | | tailptr = &subview->next; |
| 2474 | /* add to the list */ |
| 2475 | *tailptr = subview; |
| 2476 | tailptr = &subview->next; |
| 2477 | } |
| 2473 | 2478 | } |
| 2474 | 2479 | |
| 2475 | 2480 | /* finally add all global array symbols */ |
| r3912 | r3913 | |
| 2660 | 2665 | /* generate the data */ |
| 2661 | 2666 | for (chunknum = 0; chunknum < memdata->chunks_per_row; chunknum++) |
| 2662 | 2667 | { |
| 2663 | | UINT64 chunkdata = memory_view_read(memdata, memdata->bytes_per_chunk, addrbyte + chunknum * memdata->bytes_per_chunk); |
| 2664 | 2668 | int chunkindex = memdata->reverse_view ? (memdata->chunks_per_row - 1 - chunknum) : chunknum; |
| 2669 | UINT64 chunkdata; |
| 2670 | int ismapped; |
| 2665 | 2671 | |
| 2672 | ismapped = memory_view_read(memdata, memdata->bytes_per_chunk, addrbyte + chunknum * memdata->bytes_per_chunk, &chunkdata); |
| 2666 | 2673 | dest = destrow + memdata->section[1].pos + 1 + chunkindex * posdata->spacing; |
| 2667 | 2674 | for (ch = 0; ch < posdata->spacing; ch++, dest++) |
| 2668 | 2675 | if (dest >= destmin && dest < destmax) |
| 2669 | 2676 | { |
| 2670 | 2677 | UINT8 shift = posdata->shift[ch]; |
| 2671 | 2678 | if (shift < 64) |
| 2672 | | dest->byte = "0123456789ABCDEF"[(chunkdata >> shift) & 0x0f]; |
| 2679 | dest->byte = ismapped ? "0123456789ABCDEF"[(chunkdata >> shift) & 0x0f] : '*'; |
| 2673 | 2680 | } |
| 2674 | 2681 | } |
| 2675 | 2682 | |
| r3912 | r3913 | |
| 2680 | 2687 | for (ch = 0; ch < memdata->bytes_per_row; ch++, dest++) |
| 2681 | 2688 | if (dest >= destmin && dest < destmax) |
| 2682 | 2689 | { |
| 2683 | | UINT8 chval = memory_view_read(memdata, 1, addrbyte + ch); |
| 2684 | | dest->byte = isprint(chval) ? chval : '.'; |
| 2690 | int ismapped; |
| 2691 | UINT64 chval; |
| 2692 | |
| 2693 | ismapped = memory_view_read(memdata, 1, addrbyte + ch, &chval); |
| 2694 | dest->byte = (ismapped && isprint(chval)) ? chval : '.'; |
| 2685 | 2695 | } |
| 2686 | 2696 | } |
| 2687 | 2697 | } |
| r3912 | r3913 | |
| 2700 | 2710 | debug_view_memory *memdata = view->extra_data; |
| 2701 | 2711 | offs_t address; |
| 2702 | 2712 | char *hexchar; |
| 2713 | int ismapped; |
| 2703 | 2714 | UINT64 data; |
| 2704 | 2715 | UINT32 delta; |
| 2705 | 2716 | UINT8 shift; |
| r3912 | r3913 | |
| 2772 | 2783 | hexchar = strchr(hexvals, tolower(chval)); |
| 2773 | 2784 | if (hexchar == NULL) |
| 2774 | 2785 | break; |
| 2775 | | data = memory_view_read(memdata, memdata->bytes_per_chunk, address); |
| 2786 | |
| 2787 | ismapped = memory_view_read(memdata, memdata->bytes_per_chunk, address, &data); |
| 2788 | if (!ismapped) |
| 2789 | break; |
| 2776 | 2790 | data &= ~((UINT64)0x0f << shift); |
| 2777 | 2791 | data |= (UINT64)(hexchar - hexvals) << shift; |
| 2778 | 2792 | memory_view_write(memdata, memdata->bytes_per_chunk, address, data); |
| r3912 | r3913 | |
| 2879 | 2893 | } |
| 2880 | 2894 | |
| 2881 | 2895 | /* derive total sizes from that */ |
| 2882 | | view->total.y = (memdata->maxaddr - memdata->byte_offset + memdata->bytes_per_row - 1) / memdata->bytes_per_row; |
| 2896 | view->total.y = ((UINT64)memdata->maxaddr - (UINT64)memdata->byte_offset + (UINT64)memdata->bytes_per_row - 1) / memdata->bytes_per_row; |
| 2883 | 2897 | |
| 2884 | 2898 | /* reset the current cursor position */ |
| 2885 | 2899 | memory_view_set_cursor_pos(view, cursoraddr, cursorshift); |
| r3912 | r3913 | |
| 2997 | 3011 | reader |
| 2998 | 3012 | -------------------------------------------------*/ |
| 2999 | 3013 | |
| 3000 | | static UINT64 memory_view_read(debug_view_memory *memdata, UINT8 size, offs_t offs) |
| 3014 | static int memory_view_read(debug_view_memory *memdata, UINT8 size, offs_t offs, UINT64 *data) |
| 3001 | 3015 | { |
| 3002 | 3016 | /* if no raw data, just use the standard debug routines */ |
| 3003 | 3017 | if (memdata->desc->space != NULL) |
| 3004 | 3018 | { |
| 3005 | 3019 | const address_space *space = memdata->desc->space; |
| 3006 | | UINT64 result = ~(UINT64)0; |
| 3020 | offs_t dummyaddr = offs; |
| 3021 | int ismapped; |
| 3007 | 3022 | |
| 3008 | | switch (size) |
| 3023 | ismapped = memdata->no_translation ? TRUE : memory_address_physical(space, TRANSLATE_READ_DEBUG, &dummyaddr); |
| 3024 | if (ismapped) |
| 3009 | 3025 | { |
| 3010 | | case 1: result = debug_read_byte(space, offs, !memdata->no_translation); break; |
| 3011 | | case 2: result = debug_read_word(space, offs, !memdata->no_translation); break; |
| 3012 | | case 4: result = debug_read_dword(space, offs, !memdata->no_translation); break; |
| 3013 | | case 8: result = debug_read_qword(space, offs, !memdata->no_translation); break; |
| 3026 | switch (size) |
| 3027 | { |
| 3028 | case 1: *data = debug_read_byte(space, offs, !memdata->no_translation); break; |
| 3029 | case 2: *data = debug_read_word(space, offs, !memdata->no_translation); break; |
| 3030 | case 4: *data = debug_read_dword(space, offs, !memdata->no_translation); break; |
| 3031 | case 8: *data = debug_read_qword(space, offs, !memdata->no_translation); break; |
| 3032 | } |
| 3014 | 3033 | } |
| 3015 | | return result; |
| 3034 | |
| 3035 | return ismapped; |
| 3016 | 3036 | } |
| 3017 | 3037 | |
| 3018 | 3038 | /* if larger than a byte, reduce by half and recurse */ |
| 3019 | 3039 | if (size > 1) |
| 3020 | 3040 | { |
| 3041 | UINT64 data0, data1; |
| 3042 | int ismapped; |
| 3043 | |
| 3021 | 3044 | size /= 2; |
| 3045 | ismapped = memory_view_read(memdata, size, offs + 0 * size, &data0); |
| 3046 | ismapped |= memory_view_read(memdata, size, offs + 1 * size, &data1); |
| 3047 | |
| 3022 | 3048 | if (memdata->desc->endianness == ENDIANNESS_LITTLE) |
| 3023 | | return memory_view_read(memdata, size, offs + 0 * size) | ((UINT64)memory_view_read(memdata, size, offs + 1 * size) << (size * 8)); |
| 3049 | *data = data0 | (data1 << (size * 8)); |
| 3024 | 3050 | else |
| 3025 | | return memory_view_read(memdata, size, offs + 1 * size) | ((UINT64)memory_view_read(memdata, size, offs + 0 * size) << (size * 8)); |
| 3051 | *data = data1 | (data0 << (size * 8)); |
| 3052 | |
| 3053 | return ismapped; |
| 3026 | 3054 | } |
| 3027 | 3055 | |
| 3028 | 3056 | /* all 0xff if out of bounds */ |
| 3029 | 3057 | offs ^= memdata->desc->offsetxor; |
| 3030 | 3058 | if (offs >= memdata->desc->length) |
| 3031 | | return 0xff; |
| 3032 | | return *((UINT8 *)memdata->desc->base + offs); |
| 3059 | return FALSE; |
| 3060 | |
| 3061 | *data = *((UINT8 *)memdata->desc->base + offs); |
| 3062 | return TRUE; |
| 3033 | 3063 | } |
| 3034 | 3064 | |
| 3035 | 3065 | |