X-Git-Url: http://shamusworld.gotdns.org/cgi-bin/gitweb.cgi?p=rmac;a=blobdiff_plain;f=sect.c;h=cbb15187fa8f6514af7386463d1f1ac1b128e99f;hp=b58d441709681244e395a0bb2683d607cf4e00f1;hb=2161b198b7b333147c89ef0346d8e9bb6ab9ffd9;hpb=60f204cb9e3905100da0d89f14bb40db764acd9e diff --git a/sect.c b/sect.c index b58d441..cbb1518 100644 --- a/sect.c +++ b/sect.c @@ -7,6 +7,7 @@ // #include "sect.h" +#include "6502.h" #include "direct.h" #include "error.h" #include "expr.h" @@ -85,7 +86,7 @@ void InitSection(void) MakeSection(TEXT, SUSED | TEXT ); // TEXT MakeSection(DATA, SUSED | DATA ); // DATA MakeSection(BSS, SUSED | BSS | SBSS); // BSS -// MakeSection(M6502, SUSED | TEXT ); // 6502 code section + MakeSection(M6502, SUSED | TEXT ); // 6502 code section // Switch to TEXT for starters SwitchSection(TEXT); @@ -115,6 +116,8 @@ void SwitchSection(int sno) cursect = sno; SECT * p = §[sno]; + m6502 = (sno == M6502); /* set 6502-mode */ + // Copy section vars scattr = p->scattr; sloc = p->sloc; @@ -127,6 +130,11 @@ void SwitchSection(int sno) challoc = cp->challoc; ch_size = cp->ch_size; chptr = cp->chptr + ch_size; + if (m6502) + { + // For 6502 mode, add the last org'd address + chptr = cp->chptr + orgaddr; + } } else challoc = ch_size = 0; @@ -409,6 +417,12 @@ int ResolveFixups(int sno) if (cch == NULL) return 0; + /* + * Wire the 6502 segment's size to its allocated size (64K) + */ + if (sno == M6502) + cch->ch_size = cch->challoc; + do { fup.cp = ch->chptr; // fup -> start of chunk @@ -583,6 +597,25 @@ int ResolveFixups(int sno) *locp = (uint8_t)eval; break; + // Fixup high/low byte off word for 6502 + case FU_BYTEH: + if (!(eattr & DEFINED)) + { + error("external byte reference"); + continue; + } + + *locp = (uint8_t)((eval >> 8) & 0xFF); + break; + case FU_BYTEL: + if (!(eattr & DEFINED)) + { + error("external byte reference"); + continue; + } + + *locp = (uint8_t)(eval & 0xFF); + break; // Fixup WORD forward references; // the word could be unaligned in the section buffer, so we have to // be careful. @@ -713,7 +746,12 @@ int ResolveFixups(int sno) } } - SETBE16(locp, 0, eval); + // 6502 words are little endian, so handle that here + if (sno == M6502) + SETLE16(locp, 0, eval) + else + SETBE16(locp, 0, eval) + break; // Fixup LONG forward references; // the long could be unaligned in the section buffer, so be careful @@ -793,6 +831,8 @@ int ResolveAllFixups(void) ResolveFixups(TEXT); DEBUG printf("Resolving DATA sections...\n"); ResolveFixups(DATA); + DEBUG printf("Resolving 6502 sections...\n"); + ResolveFixups(M6502); /* fixup 6502 section (if any) */ return 0; }