From 93d9b2657514a1c198234e610de9a6483ab9f74f Mon Sep 17 00:00:00 2001 From: "B. Watson" Date: Thu, 25 Apr 2024 16:18:58 -0400 Subject: xexamine: add -s option (show only one segment). --- Makefile | 2 +- xexamine.1 | 12 ++++++++++++ xexamine.c | 25 ++++++++++++++++++++----- xexamine.rst | 8 ++++++++ 4 files changed, 41 insertions(+), 6 deletions(-) diff --git a/Makefile b/Makefile index 9fb8a1d..0144efa 100644 --- a/Makefile +++ b/Makefile @@ -126,7 +126,7 @@ blob2xex: blob2xex.c get_address.o $(CC) $(CFLAGS) -o blob2xex blob2xex.c xex.o get_address.o # This is a work-in-progress, not ready yet. -xexamine: xexamine.c xex.o +xexamine: xexamine.c xex.o get_address.o unmac65.xex: unmac65.c @rm -f unmac65.o diff --git a/xexamine.1 b/xexamine.1 index 0d2cb03..5b90e3e 100644 --- a/xexamine.1 +++ b/xexamine.1 @@ -62,6 +62,18 @@ heuristics, and as such, isn\(aqt 100% accurate. .UNINDENT .UNINDENT .SH OPTIONS +.\" TODO: +. +.\" -d +. +.\" Disassemble +. +.INDENT 0.0 +.TP +.B \-s \fIsegment\-number\fP +Only show information on one segment. Segments are numbered starting +at one. +.UNINDENT .INDENT 0.0 .TP .B \-h diff --git a/xexamine.c b/xexamine.c index a07da6a..6a04237 100644 --- a/xexamine.c +++ b/xexamine.c @@ -5,6 +5,7 @@ #include #include +#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; diff --git a/xexamine.rst b/xexamine.rst index a76ed16..60d217e 100644 --- a/xexamine.rst +++ b/xexamine.rst @@ -42,6 +42,14 @@ Segment type: OPTIONS ======= +.. TODO: +.. -d +.. Disassemble + +-s *segment-number* + Only show information on one segment. Segments are numbered starting + at one. + -h Print a short help message and exit. -- cgit v1.2.3