source: buchla-68k/iolib/mdump.c@ 9519422

Last change on this file since 9519422 was 7848656, checked in by Thomas Lopatic <thomas@…>, 7 years ago

Spaces to tabs.

  • Property mode set to 100644
File size: 2.1 KB
Line 
1/*
2 =============================================================================
3 mdump.c -- Hexadecimal memory dump
4 Version 5 -- 1987-10-29 -- D.N. Lynx Crowe
5
6 Displays the contents of memory in hexadecimal.
7 If a byte is printable, it is also printed.
8
9 The format of the output is :
10
11 hex_add byte byte byte byte ... byte byte byte byte string
12
13 where:
14
15 hex_add Start address for that line in hex.
16 byte Representation of a byte in hex. Two characters
17 for each byte. PERLINE bytes per line.
18 string If the character is printable, it is printed,
19 otherwise a '.' is printed.
20 =============================================================================
21*/
22
23#define TESTER 0
24
25#include "stddefs.h"
26#include "stdio.h"
27#include "ctype.h"
28
29#define PERLINE 16
30
31/*
32
33*/
34
35/*
36 =============================================================================
37 pipc() -- print if printable characters
38 =============================================================================
39*/
40
41static void pipc(int8_t chars[], int16_t length)
42{
43 int16_t i;
44
45 for (i = 0; i < length; i++)
46 if (isascii(0x00FF & chars[i]) AND (isprint(0x00FF & chars[i])))
47 printf("%c", chars[i]);
48 else
49 printf(".");
50}
51
52/*
53
54*/
55
56/*
57 =============================================================================
58 mdump() -- dump a memory area in hexadecimal
59 =============================================================================
60*/
61
62void mdump(int8_t *begin, int8_t *end, int32_t start)
63{
64 int32_t i, ii;
65 int16_t j, jj, k;
66 int8_t c, chars[PERLINE];
67
68 i = 0L;
69 ii = start;
70 j = 0;
71
72 if (begin GT end)
73 return;
74
75 while (begin LE end) {
76
77 c = *begin++;
78
79 if (! (i % PERLINE)) {
80
81 if (i) {
82
83 j=0;
84 printf(" ");
85 pipc(chars, PERLINE);
86 }
87
88 printf("\n%08lX:", ii);
89 }
90
91 ii++;
92 i++;
93
94 printf(" %02.2X", (c & 0x00FF));
95 chars[j++] = c;
96 }
97
98 if (k = (i % PERLINE)) {
99
100 k = PERLINE - k;
101
102 for (jj = 0; jj < (3 * k); ++jj)
103 printf(" ");
104 }
105
106 printf(" ");
107 pipc(chars, PERLINE);
108 printf("\n");
109}
110
111/*
112
113*/
114
115#if TESTER
116
117char area[128];
118
119main()
120{
121 register short i;
122
123 for (i = 0; i < 128; i++)
124 area[i] = i + 128;
125
126 mdump(area, (area + 127), area);
127}
128
129#endif
Note: See TracBrowser for help on using the repository browser.