/* */
/* */
/* */
-/* (C) 1998-2003 Ullrich von Bassewitz */
-/* Römerstrasse 52 */
+/* (C) 1998-2007 Ullrich von Bassewitz */
+/* Roemerstrasse 52 */
/* D-70794 Filderstadt */
/* EMail: uz@cc65.org */
/* */
/* common */
#include "fragdefs.h"
+#include "inline.h"
#include "segdefs.h"
/* ca65 */
/*****************************************************************************/
-/* Data */
+/* Data */
/*****************************************************************************/
-/* Are we in absolute mode or in relocatable mode? */
-extern int RelocMode;
+/* Segment definition */
+typedef struct Segment Segment;
+struct Segment {
+ Segment* List; /* List of all segments */
+ Fragment* Root; /* Root of fragment list */
+ Fragment* Last; /* Pointer to last fragment */
+ unsigned long FragCount; /* Number of fragments */
+ unsigned Num; /* Segment number */
+ unsigned Align; /* Segment alignment */
+ int RelocMode; /* Relocatable mode if OrgPerSeg */
+ unsigned long PC; /* PC if in relocatable mode */
+ unsigned long AbsPC; /* PC if in local absolute mode */
+ /* (OrgPerSeg is true) */
+ SegDef* Def; /* Segment definition (name and type) */
+};
/* Definitions for predefined segments */
extern SegDef NullSegDef;
extern SegDef RODataSegDef;
extern SegDef CodeSegDef;
+/* List of all segments */
+extern Segment* SegmentList;
+
+/* Currently active segment */
+extern Segment* ActiveSeg;
+
/*****************************************************************************/
void UseSeg (const SegDef* D);
/* Use the given segment */
-const SegDef* GetCurrentSeg (void);
+#if defined(HAVE_INLINE)
+INLINE const SegDef* GetCurrentSegDef (void)
/* Get a pointer to the segment defininition of the current segment */
+{
+ return ActiveSeg->Def;
+}
+#else
+# define GetCurrentSegDef() (ActiveSeg->Def)
+#endif
-unsigned GetSegNum (void);
+#if defined(HAVE_INLINE)
+INLINE unsigned GetCurrentSegNum (void)
/* Get the number of the current segment */
+{
+ return ActiveSeg->Num;
+}
+#else
+# define GetCurrentSegNum() (ActiveSeg->Num)
+#endif
+
+#if defined(HAVE_INLINE)
+INLINE unsigned char GetCurrentSegAddrSize (void)
+/* Get the address size of the current segment */
+{
+ return ActiveSeg->Def->AddrSize;
+}
+#else
+# define GetCurrentSegAddrSize() (ActiveSeg->Def->AddrSize)
+#endif
void SegAlign (unsigned Power, int Val);
/* Align the PC segment to 2^Power. If Val is -1, emit fill fragments (the
* given value.
*/
-int IsZPSeg (void);
-/* Return true if the current segment is a zeropage segment */
-
-int IsFarSeg (void);
-/* Return true if the current segment is a far segment */
-
-unsigned GetSegType (unsigned SegNum);
-/* Return the type of the segment with the given number */
+unsigned char GetSegAddrSize (unsigned SegNum);
+/* Return the address size of the segment with the given number */
unsigned long GetPC (void);
/* Get the program counter of the current segment */
-void SetAbsPC (unsigned long AbsPC);
-/* Set the program counter in absolute mode */
+int GetRelocMode (void);
+/* Return true if we're currently in relocatable mode */
+
+void EnterAbsoluteMode (unsigned long AbsPC);
+/* Enter absolute (non relocatable mode). Depending on the OrgPerSeg flag,
+ * this will either switch the mode globally or for the current segment.
+ */
+
+void EnterRelocMode (void);
+/* Enter relocatable mode. Depending on the OrgPerSeg flag, this will either
+ * switch the mode globally or for the current segment.
+ */
void SegCheck (void);
/* Check the segments for range and other errors */
void SegDump (void);
/* Dump the contents of all segments */
+void InitSegments (void);
+/* Initialize segments */
+
void WriteSegments (void);
/* Write the segment data to the object file */