]> cloudbase.mooo.com Git - z180-stamp.git/commitdiff
One dump_mem() for all memory types (avr eeprom and ram, z180 ram)
authorLeo C <erbl259-lmu@yahoo.de>
Fri, 21 Nov 2014 01:15:16 +0000 (02:15 +0100)
committerLeo C <erbl259-lmu@yahoo.de>
Fri, 21 Nov 2014 01:15:16 +0000 (02:15 +0100)
avr/cmd_mem.c
avr/debug.c
avr/print-utils.c
include/debug.h
include/print-utils.h

index 500b973dcc6ec2a4445a4dba57b2ebe7ac01b4b7..975cab4fd965e4778b4f81d9c76fe690e6157d2a 100644 (file)
@@ -38,66 +38,15 @@ static      uint32_t        base_address = 0;
 
 /*--------------------------------------------------------------------------*/
 
-int z180_dump_mem(uint32_t startaddr, uint32_t len, const char *title)
-{
-       uint8_t buf[16];
-       uint8_t llen = 16;
-       uint8_t pre = startaddr % 16;
-       uint32_t addr = startaddr & ~0x0f;
-       len += pre;
-       uint8_t i;
-
-       if (title && *title)
-               printf_P(PSTR("%s\n"),title);
-
-       while (len) {
-               if (len < 16)
-                       llen = len;
 
+void z180_read_buf(uint8_t *buf, uint32_t addr, uint8_t count)
+{
                z80_bus_cmd(Request);
-               for (i = pre; i < llen; i++)
-                       buf[i] = z80_read(addr + i);
+               while (count--)
+                       *buf++ = z80_read(addr++);
                z80_bus_cmd(Release);
-
-               printf_P(PSTR("%.5lx:"), addr);
-#if 0
-               print_blanks(3 * pre);
-
-               /* Print hex values */
-               for (i = pre; i < llen; i++)
-                       printf_P(PSTR(" %.2x"), buf[i]);
-#else
-               for (i = 0; i < llen; i++) {
-                       if ((i % 8) == 0)
-                               putchar(' ');
-                       if (i < pre)
-                               printf_P(PSTR(".. "));
-                       else
-                               printf_P(PSTR("%.2x "), buf[i]);
-               }
-#endif
-               /* fill line with whitespace for nice ASCII print */
-#if 1
-               print_blanks(3 * (16u - i) + (16u-i)/8 + 1 + pre);
-#else
-
-#endif
-               /* Print data in ASCII characters */
-               for (i = pre; i < llen; i++)
-                       printf_P(PSTR("%c"), isprint(buf[i]) ? buf[i] : '.');
-               putchar('\n');
-
-               pre = 0;
-               addr += 16;
-               len -= llen;
-
-               if (ctrlc())
-                       return -1;
-       }
-       return 0;
 }
 
-
 /*--------------------------------------------------------------------------*/
 
 /* Memory Display
@@ -139,7 +88,7 @@ command_ret_t do_mem_md(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[
        }
 
        /* Print the lines. */
-       z180_dump_mem(addr, length, NULL);
+       dump_mem(addr, length, z180_read_buf, NULL);
 
        dp_last_addr = addr + length;
        dp_last_length = length;
index 47b11b097cc5b51130f460eb760e5d4fd6564231..1940eb003d240db4fe3d6936d7ec83fe1a8191cc 100644 (file)
@@ -5,77 +5,35 @@
 #include <avr/eeprom.h>
 
 #include "command.h"
+#include "print-utils.h"
 #include "debug.h"
-
 /*
  * Debugging
  */
+
 #ifdef DEBUG
 
-static void print_blanks(uint_fast8_t count)
-{
-       while(count--)
-               putchar(' ');
-}
 
-static uint8_t ram_read_byte(const uint8_t *p)
+void eeprom_read_buf(uint8_t *buf, uint32_t addr, uint8_t count)
 {
-       return *p;
+       eeprom_read_block((void *) buf, (const void *) (size_t) addr, count);
 }
 
-void dump_mem(const uint8_t *startaddr, int len,
-               uint8_t (*readfkt)(const uint8_t *), char *title)
+void ram_read_buf(uint8_t *buf, uint32_t addr, uint8_t count)
 {
-       uint8_t buf[16];
-       char *indent = NULL;
-       uint8_t llen = 16;
-       uint8_t pre = (size_t) startaddr % 16;
-       const uint8_t *addr = (uint8_t *) ((size_t) startaddr & ~0x0f);
-       len += pre;
-       uint8_t i;
-
-       if (title && *title) {
-               printf_P(PSTR("%s\n"),title);
-               indent = "    ";
-       }
-
-       while (len) {
-               if (len < 16)
-                       llen = len;
-
-               for (i = pre; i < llen; i++)
-                       buf[i] = readfkt(addr + i);
-
-               printf_P(PSTR("%s%04x:"),indent, addr);
-               for (i = 0; i < llen; i++) {
-                       if ((i % 8) == 0)
-                               putchar(' ');
-                       if (i < pre)
-                               printf_P(PSTR(".. "));
-                       else
-                               printf_P(PSTR("%.2x "), buf[i]);
-               }
-               /* fill line with whitespace for nice ASCII print */
-               print_blanks(3 * (16u - i) + (16u-i)/8 + 1 + pre);
-               /* Print data in ASCII characters */
-               for (i = pre; i < llen; i++)
-                       printf_P(PSTR("%c"), isprint(buf[i]) ? buf[i] : '.');
-               putchar('\n');
-
-               pre = 0;
-               addr += 16;
-               len -= llen;
-       }
+               while (count--)
+                       *buf++ = *(uint8_t *) (size_t) addr++;
 }
 
-void dump_eep(const uint8_t *addr, unsigned int len, char *title)
+
+void dump_eep(uint32_t addr, unsigned int len, char *title)
 {
-       dump_mem(addr, len, eeprom_read_byte, title);
+       dump_mem(addr, len, eeprom_read_buf, title);
 }
 
-void dump_ram(const uint8_t *addr, unsigned int len, char *title)
+void dump_ram(uint32_t addr, unsigned int len, char *title)
 {
-       dump_mem(addr, len, ram_read_byte, title);
+       dump_mem(addr, len, ram_read_buf, title);
 }
 
 
@@ -84,7 +42,7 @@ void dump_heap(void)
 {
        extern unsigned int __brkval;
 
-       dump_ram((uint8_t *) __malloc_heap_start,
+       dump_ram(__malloc_heap_start,
                __brkval - (unsigned int) __malloc_heap_start,
                "=== Heap:");
 }
@@ -97,27 +55,25 @@ void dump_heap(void)
  */
 command_ret_t do_dump_mem(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
 {
-//     static const uint8_t *addr;
-//     static uint16_t length = 128;
-       uint8_t (*readhow)(const uint8_t *);
+       void (*readhow)(uint8_t *buf, uint32_t addr, uint8_t count);
 
        (void) cmdtp; (void) flag;
 
        if (argc < 2)
                return CMD_RET_USAGE;
 
-       const uint8_t *addr;
-       uint16_t length = 128;
+       uint32_t addr;
+       uint32_t length = 128;
 
        if (strchr(argv[0],'r') != NULL)
-               readhow = ram_read_byte;
+               readhow = ram_read_buf;
        else if (strchr(argv[0],'e') != NULL)
-               readhow = eeprom_read_byte;
+               readhow = eeprom_read_buf;
        else
                return CMD_RET_USAGE;
 
        /* Address is specified since argc > 1 */
-       addr = (const uint8_t *) (size_t) strtoul(argv[1], NULL, 16);
+       addr =  strtoul(argv[1], NULL, 16);
 
        /* If another parameter, it is the length to display. */
        if (argc > 2)
@@ -227,4 +183,3 @@ printfreelist(const char * title)
 #endif
 
 #endif /* DEBUG */
-
index b814d97e1d59e4b544450c8497387702e7f37b31..2bd132873b75f9b528e73f337a988e1b2eb6ec3a 100644 (file)
@@ -1,4 +1,7 @@
+#include "common.h"
 #include <stdio.h>
+#include <ctype.h>
+#include "con-utils.h"
 #include "print-utils.h"
 
 void print_blanks(uint_fast8_t count)
@@ -8,3 +11,49 @@ void print_blanks(uint_fast8_t count)
 }
 
 
+int dump_mem(uint32_t startaddr, uint32_t len,
+               void (*readfkt)(uint8_t *, uint32_t, uint8_t), char *title)
+{
+       uint8_t buf[16];
+       char *indent = NULL;
+       uint8_t llen = 16;
+       uint8_t pre = startaddr % 16;
+       uint32_t addr = startaddr & ~0x0f;
+       len += pre;
+       uint8_t i;
+
+       if (title && *title) {
+               printf_P(PSTR("%s\n"),title);
+               indent = "    ";
+       }
+
+       while (len) {
+               if (len < 16)
+                       llen = len;
+               readfkt(buf, addr + pre, llen - pre);
+
+               printf_P(PSTR("%s%.5lx:"),indent, addr);
+               for (i = 0; i < llen; i++) {
+                       if ((i % 8) == 0)
+                               putchar(' ');
+                       if (i < pre)
+                               printf_P(PSTR(".. "));
+                       else
+                               printf_P(PSTR("%.2x "), buf[i-pre]);
+               }
+               /* fill line with whitespace for nice ASCII print */
+               print_blanks(3 * (16u - i) + (16u-i)/8 + 1 + pre);
+               /* Print data in ASCII characters */
+               for (i = pre; i < llen; i++)
+                       printf_P(PSTR("%c"), isprint(buf[i-pre]) ? buf[i-pre] : '.');
+               putchar('\n');
+
+               pre = 0;
+               addr += 16;
+               len -= llen;
+
+               if (ctrlc())
+                       return -1;
+       }
+       return 0;
+}
index 45a1d504e0499d280917327687c9b88b3c1d8e32..70039a6483390f9daa4164823d6beb4c2f7ecf8a 100644 (file)
 #endif /* 0 */
 
 
-void dump_eep(const uint8_t *addr, unsigned int len, char *title);
-void dump_ram(const uint8_t *addr, unsigned int len, char *title);
+void dump_eep(uint32_t addr, unsigned int len, char *title);
+void dump_ram(uint32_t addr, unsigned int len, char *title);
 void printfreelist(const char * title);
 
 
 #endif /* DEBUG_H_ */
-
index bcd9505c90da63f7f6b1e976c624b55de87c601d..e76cba7a994388c0487b4e0db784c91242cd71cb 100644 (file)
@@ -1,2 +1,3 @@
 void print_blanks(uint_fast8_t count);
-
+int dump_mem(uint32_t startaddr, uint32_t len,
+               void (*readfkt)(uint8_t *, uint32_t, uint8_t), char *title);