mirror of
https://github.com/pevans/erc-c.git
synced 2025-01-02 09:29:58 +00:00
Add hexdump function for vm_segment
This commit is contained in:
parent
1ff5d17f19
commit
87c7aa9249
@ -72,6 +72,7 @@ extern vm_8bit vm_segment_get(vm_segment *, size_t);
|
||||
extern vm_segment *vm_segment_create(size_t);
|
||||
extern void *vm_segment_get_map_machine();
|
||||
extern void vm_segment_free(vm_segment *);
|
||||
extern void vm_segment_hexdump(vm_segment *, FILE *, size_t, size_t);
|
||||
extern void vm_segment_set_map_machine(void *);
|
||||
|
||||
#endif
|
||||
|
@ -7,6 +7,7 @@
|
||||
* etc.
|
||||
*/
|
||||
|
||||
#include <ctype.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
@ -352,3 +353,33 @@ vm_segment_set16(vm_segment *segment, size_t addr, vm_16bit value)
|
||||
// code.
|
||||
return err;
|
||||
}
|
||||
|
||||
void
|
||||
vm_segment_hexdump(vm_segment *seg, FILE *stream, size_t from, size_t to)
|
||||
{
|
||||
char nbuf[51], sbuf[17];
|
||||
int ni = 0, si = 0;
|
||||
int bytes = 0;
|
||||
vm_8bit byte;
|
||||
|
||||
while (from < to) {
|
||||
byte = vm_segment_get(seg, from);
|
||||
|
||||
ni += sprintf(nbuf + ni, "%02X ", byte);
|
||||
si += sprintf(sbuf + si, "%c", isprint(byte) ? byte : '.');
|
||||
|
||||
from++;
|
||||
bytes++;
|
||||
|
||||
if (bytes == 8) {
|
||||
ni += sprintf(nbuf + ni, " ");
|
||||
}
|
||||
|
||||
if (bytes >= 16) {
|
||||
fprintf(stream, "%08zX %s [%s]\n", from - bytes, nbuf, sbuf);
|
||||
bytes = 0;
|
||||
ni = 0;
|
||||
si = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user