1
0
mirror of https://github.com/cc65/cc65.git synced 2025-01-10 19:29:45 +00:00

Fixed a bug (offset was not correct if more than one module was used).

Added support for the new simple o65 addressing format.


git-svn-id: svn://svn.cc65.org/cc65/trunk@1280 b7a2c559-68d2-44c3-8de9-860c34a00d81
This commit is contained in:
cuz 2002-05-18 21:39:35 +00:00
parent 25c317dcc3
commit b0ceece52a

View File

@ -66,10 +66,22 @@
#define MF_CPU_6502 0x0000 /* Executable is for the 6502 */
#define MF_CPU_MASK 0x8000 /* Mask to extract CPU type */
#define MF_RELOC_PAGE 0x4000 /* Page wise relocation */
#define MF_RELOC_BYTE 0x0000 /* Byte wise relocation */
#define MF_RELOC_MASK 0x4000 /* Mask to extract relocation type */
#define MF_SIZE_32BIT 0x2000 /* All size words are 32bit */
#define MF_SIZE_16BIT 0x0000 /* All size words are 16bit */
#define MF_SIZE_MASK 0x2000 /* Mask to extract size */
#define MF_FTYPE_OBJ 0x1000 /* Object file */
#define MF_FTYPE_EXE 0x0000 /* Executable file */
#define MF_FTYPE_MASK 0x1000 /* Mask to extract type */
#define MF_ADDR_SIMPLE 0x0800 /* Simple addressing */
#define MF_ADDR_DEFAULT 0x0000 /* Default addressing */
#define MF_ADDR_MASK 0x0800 /* Mask to extract addressing */
#define MF_ALIGN_1 0x0000 /* Bytewise alignment */
#define MF_ALIGN_2 0x0001 /* Align words */
#define MF_ALIGN_4 0x0002 /* Align longwords */
@ -277,6 +289,7 @@ static void O65ParseExpr (ExprNode* Expr, ExprDesc* D, int Sign)
*/
{
Export* E;
unsigned long Val;
switch (Expr->Op) {
@ -322,6 +335,13 @@ static void O65ParseExpr (ExprNode* Expr, ExprDesc* D, int Sign)
} else {
/* Remember the segment reference */
D->SegRef = GetExprSection (Expr);
/* Add the offset of the section to the constant value */
Val = D->SegRef->Offs + D->SegRef->Seg->PC;
if (Sign < 0) {
D->Val -= Val;
} else {
D->Val += Val;
}
}
break;
@ -464,7 +484,6 @@ static void O65WriteHeader (O65Desc* D)
O65Option* O;
/* Write the fixed header */
WriteData (D->F, Trailer, sizeof (Trailer));
Write8 (D->F, D->Header.Version);
@ -1141,6 +1160,7 @@ static void O65SetupSegments (O65Desc* D, Memory* M)
/* Next segment node */
N = N->Next;
}
}
@ -1161,6 +1181,38 @@ static int O65Unresolved (const char* Name, void* D)
static void O65SetupHeader (O65Desc* D)
/* Set additional stuff in the header */
{
/* Set the base addresses of the segments */
if (D->TextCount > 0) {
SegDesc* FirstSeg = D->TextSeg [0];
D->Header.TextBase = FirstSeg->Seg->PC;
}
if (D->DataCount > 0) {
SegDesc* FirstSeg = D->DataSeg [0];
D->Header.DataBase = FirstSeg->Seg->PC;
}
if (D->BssCount > 0) {
SegDesc* FirstSeg = D->BssSeg [0];
D->Header.BssBase = FirstSeg->Seg->PC;
}
if (D->ZPCount > 0) {
SegDesc* FirstSeg = D->ZPSeg [0];
D->Header.ZPBase = FirstSeg->Seg->PC;
}
/* If we have byte wise relocation and an alignment of 1, we can set
* the "simple addressing" bit in the header.
*/
if ((D->Header.Mode & MF_RELOC_MASK) == MF_RELOC_BYTE &&
(D->Header.Mode & MF_ALIGN_MASK) == MF_ALIGN_1) {
D->Header.Mode = (D->Header.Mode & ~MF_ADDR_MASK) | MF_ADDR_SIMPLE;
}
}
void O65WriteTarget (O65Desc* D, File* F)
/* Write an o65 output file */
{
@ -1190,6 +1242,9 @@ void O65WriteTarget (O65Desc* D, File* F)
/* Setup the segment arrays */
O65SetupSegments (D, M);
/* Setup additional stuff in the header */
O65SetupHeader (D);
/* Open the file */
D->F = fopen (F->Name, "wb");
if (D->F == 0) {