void BinWriteTarget (BinDesc* D, struct File* F)
/* Write a binary output file */
-{
- Memory* M;
+{
+ unsigned I;
/* Place the filename in the control structure */
D->Filename = GetString (F->Name);
Print (stdout, 1, "Opened `%s'...\n", D->Filename);
/* Dump all memory areas */
- M = F->MemList;
- while (M) {
+ 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));
BinWriteMem (D, M);
- M = M->FNext;
}
/* Close the file */
/* common */
#include "bitops.h"
#include "check.h"
-#include "coll.h"
#include "print.h"
#include "xmalloc.h"
#include "xsprintf.h"
/* Insert the memory area into the files list */
{
M->F = F;
- if (F->MemList == 0) {
- /* First entry */
- F->MemList = M;
- } else {
- F->MemLast->FNext = M;
- }
- F->MemLast = M;
+ CollAppend (&F->MemList, M);
}
F->Name = Name;
F->Flags = 0;
F->Format = BINFMT_DEFAULT;
- F->MemList = 0;
- F->MemLast = 0;
+ InitCollection (&F->MemList);
/* Insert the struct into the list */
CollAppend (&FileList, F);
/* Initialize the fields */
M->Name = Name;
- M->FNext = 0;
M->Attr = 0;
M->Flags = 0;
M->Start = 0;
File* F = CollAtUnchecked (&FileList, I);
/* We don't need to look at files with no memory areas */
- if (F->MemList) {
+ if (CollCount (&F->MemList) > 0) {
/* Is there an output file? */
if (SB_GetLen (GetStrBuf (F->Name)) > 0) {
/* No output file. Walk through the list and mark all segments
* loading into these memory areas in this file as dumped.
- */
- Memory* M = F->MemList;
- while (M) {
+ */
+ unsigned J;
+ for (J = 0; J < CollCount (&F->MemList); ++J) {
MemListNode* N;
+ /* Get this entry */
+ Memory* M = CollAtUnchecked (&F->MemList, J);
+
/* Debugging */
Print (stdout, 2, "Skipping `%s'...\n", GetString (M->Name));
/* Next segment node */
N = N->Next;
}
- /* Next memory area */
- M = M->FNext;
}
}
}
+/* common */
+#include "coll.h"
+
/* ld65 */
#include "segments.h"
typedef struct File File;
struct File {
unsigned Name; /* Name index of the file */
- unsigned Flags;
- unsigned Format; /* Output format */
- struct Memory* MemList; /* List of memory areas in this file */
- struct Memory* MemLast; /* Last memory area in this file */
+ unsigned Flags;
+ unsigned Format; /* Output format */
+ Collection MemList; /* List of memory areas in this file */
};
/* Segment list node. Needed because there are two lists (RUN & LOAD) */
typedef struct Memory Memory;
struct Memory {
unsigned Name; /* Name index of the memory section */
- Memory* FNext; /* Next in file list */
unsigned Attr; /* Which values are valid? */
unsigned Flags; /* Set of bitmapped flags */
unsigned long Start; /* Start address */
static void O65SetupSegments (O65Desc* D, File* F)
/* Setup segment assignments */
-{
- Memory* M;
- MemListNode* N;
- SegDesc* S;
+{
+ unsigned I;
unsigned TextIdx, DataIdx, BssIdx, ZPIdx;
/* Initialize the counters */
D->ZPCount = 0;
/* Walk over the memory list */
- M = F->MemList;
- while (M) {
+ for (I = 0; I < CollCount (&F->MemList); ++I) {
+ /* Get this entry */
+ Memory* M = CollAtUnchecked (&F->MemList, I);
+
/* Walk through the segment list and count the segment types */
- N = M->SegList;
+ MemListNode* N = M->SegList;
while (N) {
/* Get the segment from the list node */
- S = N->Seg;
+ SegDesc* S = N->Seg;
/* Check the segment type. */
switch (O65SegType (S)) {
/* Next segment node */
N = N->Next;
}
- /* Next memory area */
- M = M->FNext;
}
/* Allocate memory according to the numbers */
/* Walk again through the list and setup the segment arrays */
TextIdx = DataIdx = BssIdx = ZPIdx = 0;
- M = F->MemList;
- while (M) {
+ for (I = 0; I < CollCount (&F->MemList); ++I) {
+ /* Get this entry */
+ Memory* M = CollAtUnchecked (&F->MemList, I);
- N = M->SegList;
+ /* Walk over the segment list and check the segment types */
+ MemListNode* N = M->SegList;
while (N) {
/* Get the segment from the list node */
- S = N->Seg;
+ SegDesc* S = N->Seg;
/* Check the segment type. */
switch (O65SegType (S)) {
/* Next segment node */
N = N->Next;
}
- /* Next memory area */
- M = M->FNext;
}
}