/* Get the start address of this memory area */
unsigned long Addr = M->Start;
- /* Get a pointer to the first segment node */
- MemListNode* N = M->SegList;
- while (N) {
+ /* Walk over all segments in this memory area */
+ unsigned I;
+ for (I = 0; I < CollCount (&M->SegList); ++I) {
int DoWrite;
- /* Get the segment from the list node */
- SegDesc* S = N->Seg;
+ /* Get the segment */
+ SegDesc* S = CollAtUnchecked (&M->SegList, I);
/* Keep the user happy */
Print (stdout, 1, " Writing `%s'\n", GetString (S->Name));
/* Calculate the new address */
Addr += S->Seg->Size;
-
- /* Next segment node */
- N = N->Next;
}
/* If a fill was requested, fill the remaining space */
void BinWriteTarget (BinDesc* D, struct File* F)
/* Write a binary output file */
-{
+{
unsigned I;
/* Place the filename in the control structure */
Print (stdout, 1, "Opened `%s'...\n", D->Filename);
/* Dump all memory areas */
- for (I = 0; I < CollCount (&F->MemList); ++I) {
+ for (I = 0; I < CollCount (&F->MemList); ++I) {
/* Get this entry */
Memory* M = CollAtUnchecked (&F->MemList, I);
Print (stdout, 1, " Dumping `%s'\n", GetString (M->Name));
static void MemoryInsert (Memory* M, SegDesc* S)
/* Insert the segment descriptor into the memory area list */
{
- /* Create a new node for the entry */
- MemListNode* N = xmalloc (sizeof (MemListNode));
- N->Seg = S;
- N->Next = 0;
-
- if (M->SegLast == 0) {
- /* First entry */
- M->SegList = N;
- } else {
- M->SegLast->Next = N;
- }
- M->SegLast = N;
+ /* Insert the segment into the segment list of the memory area */
+ CollAppend (&M->SegList, S);
}
M->FillLevel = 0;
M->FillVal = 0;
M->Relocatable = 0;
- M->SegList = 0;
- M->SegLast = 0;
+ InitCollection (&M->SegList);
M->F = 0;
/* Insert the struct into the list */
unsigned I;
for (I = 0; I < CollCount (&MemoryList); ++I) {
- MemListNode* N;
+ unsigned J;
/* Get this entry */
Memory* M = CollAtUnchecked (&MemoryList, I);
M->Relocatable = RelocatableBinFmt (M->F->Format);
/* Walk through the segments in this memory area */
- N = M->SegList;
- while (N) {
+ for (J = 0; J < CollCount (&M->SegList); ++J) {
- /* Get the segment from the node */
- SegDesc* S = N->Seg;
+ /* Get the segment */
+ SegDesc* S = CollAtUnchecked (&M->SegList, J);
/* Some actions depend on wether this is the load or run memory
* area.
/* Calculate the new address */
Addr += S->Seg->Size;
- /* Next segment */
- N = N->Next;
}
/* If requested, define symbols for start and size of the memory area */
unsigned J;
for (J = 0; J < CollCount (&F->MemList); ++J) {
- MemListNode* N;
+ unsigned K;
/* Get this entry */
Memory* M = CollAtUnchecked (&F->MemList, J);
Print (stdout, 2, "Skipping `%s'...\n", GetString (M->Name));
/* Walk throught the segments */
- N = M->SegList;
- while (N) {
- if (N->Seg->Load == M) {
+ for (K = 0; K < CollCount (&M->SegList); ++K) {
+ SegDesc* S = CollAtUnchecked (&M->SegList, K);
+ if (S->Load == M) {
/* Load area - mark the segment as dumped */
- N->Seg->Seg->Dumped = 1;
+ S->Seg->Dumped = 1;
}
-
- /* Next segment node */
- N = N->Next;
}
}
}
Collection MemList; /* List of memory areas in this file */
};
-/* Segment list node. Needed because there are two lists (RUN & LOAD) */
-typedef struct MemListNode MemListNode;
-struct MemListNode {
- MemListNode* Next; /* Next entry */
- struct SegDesc* Seg; /* Segment */
-};
-
/* Memory list entry */
typedef struct Memory Memory;
struct Memory {
unsigned long FillLevel; /* Actual fill level of segment */
unsigned char FillVal; /* Value used to fill rest of seg */
unsigned char Relocatable; /* Memory area is relocatable */
- MemListNode* SegList; /* List of segments for this section */
- MemListNode* SegLast; /* Last segment in this section */
+ Collection SegList; /* List of segments for this section */
File* F; /* File that contains the entry */
};
/* Get the memory area from the expression */
Memory* M = ED->MemRef;
- /* Get the list of segments in this memory area */
- MemListNode* N = M->SegList;
-
/* Remember the "nearest" segment and its offset */
Segment* Nearest = 0;
unsigned long Offs = ULONG_MAX;
/* Walk over all segments */
- while (N != 0) {
+ unsigned I;
+ for (I = 0; I < CollCount (&M->SegList); ++I) {
- /* Get the segment from this node and check if it's a run segment */
- SegDesc* S = N->Seg;
+ /* Get the segment and check if it's a run segment */
+ SegDesc* S = CollAtUnchecked (&M->SegList, I);
if (S->Run == M) {
unsigned long O;
}
}
}
-
- /* Next segment */
- N = N->Next;
}
/* If we found a segment, use it and adjust the offset */
static void O65SetupSegments (O65Desc* D, File* F)
/* Setup segment assignments */
-{
+{
unsigned I;
unsigned TextIdx, DataIdx, BssIdx, ZPIdx;
Memory* M = CollAtUnchecked (&F->MemList, I);
/* Walk through the segment list and count the segment types */
- MemListNode* N = M->SegList;
- while (N) {
+ unsigned J;
+ for (J = 0; J < CollCount (&M->SegList); ++J) {
- /* Get the segment from the list node */
- SegDesc* S = N->Seg;
+ /* Get the segment */
+ SegDesc* S = CollAtUnchecked (&M->SegList, J);
/* Check the segment type. */
switch (O65SegType (S)) {
case O65SEG_DATA: D->DataCount++; break;
case O65SEG_BSS: D->BssCount++; break;
case O65SEG_ZP: D->ZPCount++; break;
- default: Internal ("Invalid return from O65SegType");
+ default: Internal ("Invalid return from O65SegType");
}
-
- /* Next segment node */
- N = N->Next;
}
}
Memory* M = CollAtUnchecked (&F->MemList, I);
/* Walk over the segment list and check the segment types */
- MemListNode* N = M->SegList;
- while (N) {
+ unsigned J;
+ for (J = 0; J < CollCount (&M->SegList); ++J) {
- /* Get the segment from the list node */
- SegDesc* S = N->Seg;
+ /* Get the segment */
+ SegDesc* S = CollAtUnchecked (&M->SegList, J);
/* Check the segment type. */
switch (O65SegType (S)) {
case O65SEG_ZP: D->ZPSeg [ZPIdx++] = S; break;
default: Internal ("Invalid return from O65SegType");
}
-
- /* Next segment node */
- N = N->Next;
}
}
}