10000 Cleanup for the da65 code base by kugelfuhr · Pull Request #2728 · cc65/cc65 · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Cleanup for the da65 code base #2728

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jun 23, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions doc/da65.sgml
Original file line number Diff line number Diff line change
Expand Up @@ -248,8 +248,8 @@ With the command line option <tt><ref id="option--cpu" name="--cpu"></tt>, the
disassembler may be told which CPU to support:

<itemize>
<item><ref id="6502-mode" name="6502 mode"> - NMOS 6502 (all legal instructions)
<item><ref id="6502X-mode" name="6502X mode"> - NMOS 6502 with all undocumented instructions
<item><ref id="6502-mode" name="6502"> - NMOS 6502 (all legal instructions)
<item><ref id="6502X-mode" name="6502X"> - NMOS 6502 with all undocumented instructions
<item><ref id="DTV-mode" name="6502DTV"> - the emulated CPU of the C64DTV device
<item><ref id="65SC02-mode" name="65SC02"> - first CMOS instruction set (no bit manipulation, no wai/stp)
<item><ref id="65C02-mode" name="65C02"> - full CMOS instruction set (has bit manipulation and wai/stp)
Expand Down
173 changes: 107 additions & 66 deletions src/da65/attrtab.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,11 @@



#include <inttypes.h>

/* common */
#include "xmalloc.h"

/* da65 */
#include "cpu.h"
#include "error.h"
Expand All @@ -46,68 +51,124 @@



/* Attribute table */
static unsigned short AttrTab[0x10000];
/* Attribute structure how it is found in the attribute table */
typedef struct Attribute Attribute;
struct Attribute {
struct Attribute* Next; /* Next entry in linked list */
uint32_t Addr; /* The full address */
attr_t Attr; /* Actual attribute */
};

/* 65816 attribute table */
#define MAX_LONG_ATTRS 256
static unsigned short LongAttrVal[MAX_LONG_ATTRS];
static unsigned LongAttrAddr[MAX_LONG_ATTRS];
static unsigned LongAttrsUsed;
/* Attributes use a hash table and a linear list for collision resolution. The
** hash function is easy and effective. It evaluates just the lower bits of
** the address.
*/
#define ATTR_HASH_SIZE 8192u /* Must be power of two */
static Attribute* AttributeTab[ATTR_HASH_SIZE];



/*****************************************************************************/
/* Code */
/* struct Attribute */
/*****************************************************************************/



void AddrCheck (unsigned Addr)
/* Check if the given address has a valid range */
static Attribute* NewAttribute (uint32_t Addr, attr_t Attr)
/* Create a new attribute structure and return it */
{
if (Addr >= 0x10000 && CPU != CPU_65816) {
Error ("Address out of range: %08X", Addr);
/* Create a new attribute */
Attribute* A = xmalloc (sizeof (Attribute));

/* Fill in the data */
A->Next = 0;
A->Addr = Addr;
A->Attr = Attr;

/* Return the attribute just created */
return A;
}



static uint32_t GetAttributeHash (uint32_t Addr)
/* Get the hash for an attribute at the given address */
{
return (Addr & (ATTR_HASH_SIZE - 1));
}



static Attribute* FindAttribute (uint32_t Addr)
/* Search for an attribute for the given address and return it. Returns NULL
** if no attribute exists for the address.
*/
{
Attribute* A = AttributeTab[GetAttributeHash (Addr)];
while (A) {
if (A->Addr == Addr) {
break;
}
A = A->Next;
}
return A;
}


unsigned char IsLongAddr (unsigned Addr)
/* Is it 24-bit? */

static void InsertAttribute (Attribute* A)
/* Insert an attribute into the hash table */
{
return Addr >= 0x10000 && CPU == CPU_65816;
uint32_t Hash = GetAttributeHash (A->Addr);
A->Next = AttributeTab[Hash];
AttributeTab[Hash] = A;
}



attr_t GetAttr (unsigned Addr)
/* Return the attribute for the given address */
/*****************************************************************************/
/* Code */
/*****************************************************************************/



void AddrCheck (uint32_t Addr)
/* Check if the given address has a valid range */
{
/* Check the given address */
AddrCheck (Addr);
if (Addr >= 0x10000 && CPU != CPU_65816) {
Error ("Address out of range: $%04" PRIX32, Addr);
}
}


if (IsLongAddr (Addr)) {
unsigned i;
for (i = 0; i < LongAttrsUsed; i++) {
if (LongAttrAddr[i] == Addr) {
return LongAttrVal[i];
}
}

return 0;
attr_t GetAttr (uint32_t Addr)
/* Return the attribute for the given address */
{
/* As a small optimization we cache the last used attribute so when the
** function is called several times with the same address we do already
** know it.
*/
static const Attribute* A = 0;
if (A != 0 && A->Addr == Addr) {
return A->Attr;
}

/* Check the given address */
AddrCheck (Addr);

/* Return the attribute */
return AttrTab[Addr];
A = FindAttribute (Addr);
return A? A->Attr : atDefault;
}



int SegmentDefined (unsigned Start, unsigned End)
int SegmentDefined (uint32_t Start, uint32_t End)
/* Return true if the atSegment bit is set somewhere in the given range */
{
while (Start <= End) {
if (AttrTab[Start++] & atSegment) {
if (GetAttr (Start++) & atSegment) {
return 1;
}
}
Expand All @@ -116,15 +177,15 @@ int SegmentDefined (unsigned Start, unsigned End)



int IsSegmentEnd (unsigned Addr)
int IsSegmentEnd (uint32_t Addr)
/* Return true if a segment ends at the given address */
{
return (GetAttr (Addr) & atSegmentEnd) != 0x0000;
}



int IsSegmentStart (unsigned Addr)
int IsSegmentStart (uint32_t Addr)
/* Return true if a segment starts at the given address */
{
return (GetAttr (Addr) & atSegmentStart) != 0x0000;
Expand Down Expand Up @@ -155,7 +216,7 @@ unsigned GetGranularity (attr_t Style)



void MarkRange (unsigned Start, unsigned End, attr_t Attr)
void MarkRange (uint32_t Start, uint32_t End, attr_t Attr)
/* Mark a range with the given attribute */
{
/* Do it easy here... */
Expand All @@ -166,53 +227,33 @@ void MarkRange (unsigned Start, unsigned End, attr_t Attr)



void MarkAddr (unsigned Addr, attr_t Attr)
void MarkAddr (uint32_t Addr, attr_t Attr)
/* Mark an address with an attribute */
{
/* Check the given address */
AddrCheck (Addr);

if (IsLongAddr (Addr)) {
unsigned i;
for (i = 0; i < LongAttrsUsed; i++) {
if (LongAttrAddr[i] == Addr) {

/* We must not have more than one style bit */
if (Attr & atStyleMask) {
if (LongAttrVal[i] & atStyleMask) {
Error ("Duplicate style for long address %06X", Addr);
}
}
LongAttrVal[i] |= Attr;

return;
}
}

if (LongAttrsUsed >= MAX_LONG_ATTRS) {
Error ("Too many long addresses");
}
LongAttrVal[LongAttrsUsed] |= Attr;
LongAttrAddr[LongAttrsUsed] = Addr;
LongAttrsUsed++;

return;
}
/* Get an existing attribute entry */
Attribute* A = FindAttribute (Addr);

/* We must not have more than one style bit */
if (Attr & atStyleMask) {
if (AttrTab[Addr] & atStyleMask) {
Error ("Duplicate style for address %04X", Addr);
if (A != 0 && (Attr & atStyleMask) != 0) {
if ((A->Attr & atStyleMask) != 0) {
Error ("Duplicate style for address %04" PRIX32, Addr);
}
}

/* Set the style */
AttrTab[Addr] |= Attr;
if (A) {
A->Attr |= Attr;
} else {
InsertAttribute (NewAttribute (Addr, Attr));
}
}



attr_t GetStyleAttr (unsigned Addr)
attr_t GetStyleAttr (uint32_t Addr)
/* Return the style attribute for the given address */
{
/* Check the given address */
Expand All @@ -224,7 +265,7 @@ attr_t GetStyleAttr (unsigned Addr)



attr_t GetLabelAttr (unsigned Addr)
attr_t GetLabelAttr (uint32_t Addr)
/* Return the label attribute for the given address */
{
/* Check the given address */
Expand Down
24 changes: 14 additions & 10 deletions src/da65/attrtab.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@



#include <stdint.h>



/*****************************************************************************/
/* Data */
/*****************************************************************************/
Expand Down Expand Up @@ -95,37 +99,37 @@ typedef enum attr_t {



void AddrCheck (unsigned Addr);
void AddrCheck (uint32_t Addr);
/* Check if the given address has a valid range */

unsigned char IsLongAddr (unsigned Addr);
unsigned char IsLongAddr (uint32_t Addr);
/* Check if the given address is 24-bit */

attr_t GetAttr (unsigned Addr);
attr_t GetAttr (uint32_t Addr);
/* Return the attribute for the given address */

int SegmentDefined (unsigned Start, unsigned End);
int SegmentDefined (uint32_t Start, unsigned End);
/* Return true if the atSegment bit is set somewhere in the given range */

int IsSegmentEnd (unsigned Addr);
int IsSegmentEnd (uint32_t Addr);
/* Return true if a segment ends at the given address */

int IsSegmentStart (unsigned Addr);
int IsSegmentStart (uint32_t Addr);
/* Return true if a segment starts at the given address */

unsigned GetGranularity (attr_t Style);
/* Get the granularity for the given style */

void MarkRange (unsigned Start, unsigned End, attr_t Attr);
void MarkRange (uint32_t Start, uint32_t End, attr_t Attr);
/* Mark a range with the given attribute */

void MarkAddr (unsigned Addr, attr_t Attr);
void MarkAddr (uint32_t Addr, attr_t Attr);
/* Mark an address with an attribute */

attr_t GetStyleAttr (unsigned Addr);
attr_t GetStyleAttr (uint32_t Addr);
/* Return the style attribute for the given address */

attr_t GetLabelAttr (unsigned Addr);
attr_t GetLabelAttr (uint32_t Addr);
/* Return the label attribute for the given address */


Expand Down
Loading
0