]> cloudbase.mooo.com Git - z180-stamp.git/blame - avr/print-utils.c
clean up includes
[z180-stamp.git] / avr / print-utils.c
CommitLineData
35edb766 1/*
b35fcb2f 2 * (C) Copyright 2014,2018 Leo C. <erbl259-lmu@yahoo.de>
35edb766 3 *
b35fcb2f 4 * SPDX-License-Identifier: GPL-2.0
35edb766
L
5 */
6
e39cd2a2 7#include "common.h"
c748023e 8#include <stdint.h>
e39cd2a2 9#include "con-utils.h"
8f23e84c
L
10#include "print-utils.h"
11
12void print_blanks(uint_fast8_t count)
13{
14 while(count--)
15 putchar(' ');
16}
17
18
b35fcb2f 19ERRNUM eeprom_read_buf(uint8_t *buf, uint32_t addr, uint8_t count)
fc454c83
L
20{
21 eeprom_read_block((void *) buf, (const void *) (size_t) addr, count);
b35fcb2f 22 return ESUCCESS;
fc454c83
L
23}
24
b35fcb2f 25ERRNUM ram_read_buf(uint8_t *buf, uint32_t addr, uint8_t count)
fc454c83 26{
d9d8de47
L
27 while (count--)
28 *buf++ = *(uint8_t *) (size_t) addr++;
b35fcb2f 29 return ESUCCESS;
fc454c83
L
30}
31
b35fcb2f 32ERRNUM flash_read_buf(uint8_t *buf, uint32_t addr, uint8_t count)
c748023e 33{
d9d8de47
L
34 while (count--)
35 *buf++ = *(const __memx uint8_t *) (__uint24) addr++;
b35fcb2f 36 return ESUCCESS;
c748023e
L
37}
38
b35fcb2f
L
39ERRNUM dump_mem(uint32_t address, uint32_t offset, uint32_t len,
40 ERRNUM (*readfkt)(uint8_t *, uint32_t, uint8_t), char *title)
e39cd2a2
L
41{
42 uint8_t buf[16];
e39cd2a2 43 uint8_t llen = 16;
fc454c83
L
44 uint8_t pre = offset % 16;
45 offset = offset & ~0x0f;
e39cd2a2
L
46 len += pre;
47 uint8_t i;
48
49 if (title && *title) {
50 printf_P(PSTR("%s\n"),title);
e39cd2a2
L
51 }
52
53 while (len) {
54 if (len < 16)
55 llen = len;
e9d96859
L
56 ERRNUM err = readfkt(buf, address, llen - pre);
57 if (err != ESUCCESS)
58 return err;
e39cd2a2 59
209025e8
L
60 if (title)
61 print_blanks(4);
62 printf_P(PSTR("%.5lx:"),offset);
e39cd2a2
L
63 for (i = 0; i < llen; i++) {
64 if ((i % 8) == 0)
65 putchar(' ');
66 if (i < pre)
67 printf_P(PSTR(".. "));
68 else
69 printf_P(PSTR("%.2x "), buf[i-pre]);
70 }
71 /* fill line with whitespace for nice ASCII print */
72 print_blanks(3 * (16u - i) + (16u-i)/8 + 1 + pre);
73 /* Print data in ASCII characters */
74 for (i = pre; i < llen; i++)
75 printf_P(PSTR("%c"), isprint(buf[i-pre]) ? buf[i-pre] : '.');
76 putchar('\n');
77
fc454c83
L
78 address += llen - pre;
79 offset += 16;
e39cd2a2 80 pre = 0;
e39cd2a2
L
81 len -= llen;
82
83 if (ctrlc())
b35fcb2f 84 return EINTR;
e39cd2a2 85 }
b35fcb2f 86 return ESUCCESS;
e39cd2a2 87}
fc454c83
L
88
89void dump_eep(uint32_t addr, unsigned int len, char *title)
90{
91 dump_mem(addr, addr, len, eeprom_read_buf, title);
92}
93
cca42593 94void dump_ram(uint8_t *addr, size_t offset, unsigned int len, char *title)
fc454c83 95{
cca42593 96 dump_mem((uint32_t) (size_t) addr, offset, len, ram_read_buf, title);
fc454c83 97}