aboutsummaryrefslogtreecommitdiff
path: root/xexamine.c
diff options
context:
space:
mode:
Diffstat (limited to 'xexamine.c')
-rw-r--r--xexamine.c25
1 files changed, 20 insertions, 5 deletions
diff --git a/xexamine.c b/xexamine.c
index a07da6a..6a04237 100644
--- a/xexamine.c
+++ b/xexamine.c
@@ -5,6 +5,7 @@
#include <unistd.h>
#include <errno.h>
+#include "get_address.h"
#include "xex.h"
#define SELF "xexamine"
@@ -41,7 +42,7 @@ void crc32(const void *data, size_t n_bytes, uint32_t* crc) {
}
void usage(int status) {
- printf("Usage: " SELF " [-v] file.xex\n");
+ printf("Usage: " SELF " [-v] [-s segment] file.xex\n");
if(status) fprintf(stderr, "Try '%s -h' for help\n", SELF);
exit(status);
}
@@ -309,11 +310,15 @@ int main(int argc, char **argv) {
xex_segment seg;
unsigned char buffer[65536];
char *filename;
- int opt, segcount = 0;
+ int opt, segcount = 0, only_segment = 0, header_printed = 0;
uint32_t crc;
- while((opt = getopt(argc, argv, "vh")) != -1) {
+ while((opt = getopt(argc, argv, "vhs:")) != -1) {
switch(opt) {
+ case 's':
+ if( (only_segment = get_address(SELF, optarg)) < 0 )
+ exit(1);
+ break;
case 'v':
xex_verbose = 1;
break;
@@ -340,11 +345,16 @@ int main(int argc, char **argv) {
seg.object = buffer;
while(xex_fread_seg(&seg, f)) {
- if(!segcount)
+ segcount++;
+ if(only_segment && (only_segment != segcount))
+ continue;
+ if(!header_printed) {
printf("Seg | Start | End | Bytes | CRC32 | Type\n");
+ header_printed++;
+ }
crc32(seg.object, seg.len, &crc);
printf("%3d | $%04x | $%04x | %5d | %08x | ",
- ++segcount, seg.start_addr, seg.end_addr, seg.len, crc);
+ segcount, seg.start_addr, seg.end_addr, seg.len, crc);
if(seg.start_addr == XEX_RUNAD && seg.len > 1)
printf("Run $%04x", (seg.object[0] | (seg.object[1] << 8)));
else if(seg.start_addr == XEX_INITAD && seg.len > 1)
@@ -354,6 +364,11 @@ int main(int argc, char **argv) {
putchar('\n');
}
+ if(only_segment && (segcount < only_segment)) {
+ fprintf(stderr, SELF ": can't show segment %d, only %d segments in file.\n", only_segment, segcount);
+ return 1;
+ }
+
if(!segcount) {
fprintf(stderr, SELF ": %s is not an Atari 8-bit executable.\n", filename);
return 1;