From: Greg King Date: Sun, 30 Nov 2014 05:40:45 +0000 (-0500) Subject: Fixed the detection of where to start and stop segments. X-Git-Tag: V2.15~28^2~1 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=155f00f25e7d484cf136dbbc397cf2ed3080b740;p=cc65 Fixed the detection of where to start and stop segments. --- diff --git a/src/da65/attrtab.c b/src/da65/attrtab.c index d288d1298..a9143584a 100644 --- a/src/da65/attrtab.c +++ b/src/da65/attrtab.c @@ -107,14 +107,6 @@ int IsSegmentStart (unsigned Addr) -int HaveSegmentChange (unsigned Addr) -/* Return true if the segment change attributes are set for the given address */ -{ - return (GetAttr (Addr) & (atSegmentStart | atSegmentEnd)) != 0x0000; -} - - - unsigned GetGranularity (attr_t Style) /* Get the granularity for the given style */ { diff --git a/src/da65/attrtab.h b/src/da65/attrtab.h index b2dc6c455..18515ce49 100644 --- a/src/da65/attrtab.h +++ b/src/da65/attrtab.h @@ -100,9 +100,6 @@ int IsSegmentEnd (unsigned Addr); int IsSegmentStart (unsigned Addr); /* Return true if a segment starts at the given address */ -int HaveSegmentChange (unsigned Addr); -/* Return true if the segment change attributes are set for the given address */ - unsigned GetGranularity (attr_t Style); /* Get the granularity for the given style */ diff --git a/src/da65/main.c b/src/da65/main.c index 05c4a7bfd..8c37e1ae2 100644 --- a/src/da65/main.c +++ b/src/da65/main.c @@ -348,6 +348,8 @@ static void OptVersion (const char* Opt attribute ((unused)), static void OneOpcode (unsigned RemainingBytes) /* Disassemble one opcode */ { + unsigned I; + /* Get the opcode from the current address */ unsigned char OPC = GetCodeByte (PC); @@ -380,7 +382,8 @@ static void OneOpcode (unsigned RemainingBytes) ** - ...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 those conditions is false, switch to data mode. + ** - ...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) { @@ -390,16 +393,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)) { + for (I = PC + D->Size; --I > PC; ) { + if (HaveLabel (I) || IsSegmentStart (I)) { Style = atIllegal; MarkAddr (PC, Style); break; } } - for (I = 1; I < D->Size - 1u; ++I) { - if (HaveSegmentChange (PC+I)) { + for (I = 0; I < D->Size - 1u; ++I) { + if (IsSegmentEnd (PC + I)) { Style = atIllegal; MarkAddr (PC, Style); break; @@ -422,7 +424,6 @@ static void OneOpcode (unsigned RemainingBytes) */ if (D->Size <= RemainingBytes) { /* Output labels within the next insn */ - unsigned I; for (I = 1; I < D->Size; ++I) { ForwardLabel (I); } @@ -469,11 +470,16 @@ static void OneOpcode (unsigned RemainingBytes) DataByteLine (1); ++PC; break; - } - if (IsSegmentEnd (PC - 1)) { - EndSegment (); + /* Change back to the default CODE segment if + ** a named segment stops at the current address. + */ + for (I = D->Size; I >= 1; --I) { + if (IsSegmentEnd (PC - I)) { + EndSegment (); + break; + } } }