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