X-Git-Url: https://git.sur5r.net/?a=blobdiff_plain;f=src%2Fda65%2Fmain.c;h=1454d01fb831bf1b3ff158bb874f072e85209f54;hb=13a485d88507b2a3f9f87d293015a51141f11b9b;hp=921951f3a04b779df17b21924be2d786de0f4fb4;hpb=4185caf8558690ae4720d4a83d829ed3ed087ae9;p=cc65 diff --git a/src/da65/main.c b/src/da65/main.c index 921951f3a..1454d01fb 100644 --- a/src/da65/main.c +++ b/src/da65/main.c @@ -6,10 +6,10 @@ /* */ /* */ /* */ -/* (C) 1998-2011, Ullrich von Bassewitz */ -/* Roemerstrasse 52 */ -/* D-70794 Filderstadt */ -/* EMail: uz@cc65.org */ +/* (C) 1998-2014, Ullrich von Bassewitz */ +/* Roemerstrasse 52 */ +/* D-70794 Filderstadt */ +/* EMail: uz@cc65.org */ /* */ /* */ /* This software is provided 'as-is', without any expressed or implied */ @@ -60,6 +60,7 @@ #include "opctable.h" #include "output.h" #include "scanner.h" +#include "segment.h" @@ -108,8 +109,8 @@ static void Usage (void) static void RangeCheck (const char* Opt, unsigned long Val, unsigned long Min, unsigned long Max) /* Do a range check for the given option and abort if there's a range - * error. - */ +** error. +*/ { if (Val < Min || Val > Max) { Error ("Argument for %s outside valid range (%ld-%ld)", Opt, Min, Max); @@ -120,8 +121,8 @@ static void RangeCheck (const char* Opt, unsigned long Val, static unsigned long CvtNumber (const char* Arg, const char* Number) /* Convert a number from a string. Allow '$' and '0x' prefixes for hex - * numbers. - */ +** numbers. +*/ { unsigned long Val; int Converted; @@ -339,7 +340,8 @@ static void OptVersion (const char* Opt attribute ((unused)), const char* Arg attribute ((unused))) /* Print the disassembler version */ { - fprintf (stderr, "da65 V%s\n", GetVersionAsString ()); + fprintf (stderr, "%s V%s\n", ProgName, GetVersionAsString ()); + exit(EXIT_SUCCESS); } @@ -347,6 +349,9 @@ static void OptVersion (const char* Opt attribute ((unused)), static void OneOpcode (unsigned RemainingBytes) /* Disassemble one opcode */ { + unsigned I; + unsigned OldPC = PC; + /* Get the opcode from the current address */ unsigned char OPC = GetCodeByte (PC); @@ -356,9 +361,17 @@ static void OneOpcode (unsigned RemainingBytes) /* Get the output style for the current PC */ attr_t Style = GetStyleAttr (PC); + /* If a segment begins here, then name that segment. + ** Note that the segment is named even if its code is being skipped, + ** because some of its later code might not be skipped. + */ + if (IsSegmentStart (PC)) { + StartSegment (GetSegmentStartName (PC), GetSegmentAddrSize (PC)); + } + /* If we have a label at this address, output the label and an attached - * comment, provided that we aren't in a skip area. - */ + ** comment, provided that we aren't in a skip area. + */ if (Style != atSkip && MustDefLabel (PC)) { const char* Comment = GetComment (PC); if (Comment) { @@ -368,11 +381,12 @@ static void OneOpcode (unsigned RemainingBytes) } /* Check... - * - ...if we have enough bytes remaining for the code at this address. - * - ...if the current instruction is valid for the given CPU. - * - ...if there is no label somewhere between the instruction bytes. - * If any of these conditions is false, switch to data mode. - */ + ** - ...if we have enough bytes remaining for the code at this address. + ** - ...if the current instruction is valid for the given CPU. + ** - ...if there is no label somewhere between the instruction bytes. + ** - ...if there is no segment change between the instruction bytes. + ** If any one of those conditions is false, switch to data mode. + */ if (Style == atDefault) { if (D->Size > RemainingBytes) { Style = atIllegal; @@ -381,9 +395,15 @@ static void OneOpcode (unsigned RemainingBytes) Style = atIllegal; MarkAddr (PC, Style); } else { - unsigned I; - for (I = 1; I < D->Size; ++I) { - if (HaveLabel (PC+I) || HaveSegmentChange (PC+I)) { + for (I = PC + D->Size; --I > PC; ) { + if (HaveLabel (I) || IsSegmentStart (I)) { + Style = atIllegal; + MarkAddr (PC, Style); + break; + } + } + for (I = 0; I < D->Size - 1u; ++I) { + if (IsSegmentEnd (PC + I)) { Style = atIllegal; MarkAddr (PC, Style); break; @@ -402,11 +422,10 @@ static void OneOpcode (unsigned RemainingBytes) case atCode: /* Beware: If we don't have enough bytes left to disassemble the - * following insn, fall through to byte mode. - */ + ** following insn, fall through to byte mode. + */ if (D->Size <= RemainingBytes) { /* Output labels within the next insn */ - unsigned I; for (I = 1; I < D->Size; ++I) { ForwardLabel (I); } @@ -453,7 +472,16 @@ static void OneOpcode (unsigned RemainingBytes) DataByteLine (1); ++PC; break; + } + /* Change back to the default CODE segment if + ** a named segment stops at the current address. + */ + for (I = PC - OldPC; I > 0; --I) { + if (IsSegmentEnd (PC - I)) { + EndSegment (); + break; + } } } @@ -594,9 +622,9 @@ int main (int argc, char* argv []) } /* Check the formatting options for reasonable values. Note: We will not - * really check that they make sense, just that they aren't complete - * garbage. - */ + ** really check that they make sense, just that they aren't complete + ** garbage. + */ if (MCol >= ACol) { AbEnd ("mnemonic-column value must be smaller than argument-column value"); } @@ -613,8 +641,8 @@ int main (int argc, char* argv []) } /* Get the current time and convert it to string so it can be used in - * the output page headers. - */ + ** the output page headers. + */ T = time (0); strftime (Now, sizeof (Now), "%Y-%m-%d %H:%M:%S", localtime (&T));