2 // RMAC - Reboot's Macro Assembler for the Atari Jaguar Console System
3 // EAGEN0.C - Effective Address Code Generation
4 // Generated Code for eaN (Included twice by "eagen.c")
5 // Copyright (C) 199x Landon Dyer, 2017 Reboot and Friends
6 // RMAC derived from MADMAC v1.07 Written by Landon Dyer, 1986
7 // Source utilised with the kind permission of Landon Dyer
12 VALUE vbd, v = aNexval;
13 WORD wbd, w = (WORD)(aNexattr & DEFINED);
14 WORD tdbbd, tdb = (WORD)(aNexattr & TDB);
16 wbd = (WORD)(aNbdexattr & DEFINED);
17 tdbbd = (WORD)(aNbdexattr & TDB);
21 // "Do nothing" - they're in the opword
31 // This is a performance hit, though
39 MarkRelocatable(cursect, sloc, tdb, MWORD, NULL);
41 if ((v == 0) && optim_flags[OPT_INDIRECT_DISP] && !movep)
43 // If expr is 0, size optimise the opcode. Generally the lower
44 // 6 bits of the opcode for expr(ax) are 101rrr where rrr=the
45 // number of the register, then followed by a word containing
46 // 'expr'. We need to change that to 010rrr.
47 if ((siz & 0x8000) == 0)
49 chptr_opcode[0] &= ((0xFFC7 >> 8) & 255); // mask off bits
50 chptr_opcode[1] &= 0xFFC7 & 255; // mask off bits
51 chptr_opcode[0] |= ((0x0010 >> 8) & 255); // slap in 010 bits
52 chptr_opcode[1] |= 0x0010 & 255; // slap in 010 bits
56 // Special case for move ea,ea: there are two ea fields
57 // there and we get a signal if it's the second ea field
58 // from m_ea - siz's 16th bit is set
59 chptr_opcode[0] &= ((0xFE3F >> 8) & 255); // mask off bits
60 chptr_opcode[1] &= 0xFE3F & 255; // mask off bits
61 chptr_opcode[0] |= ((0x0080 >> 8) & 255); // slap in 010 bits
62 chptr_opcode[1] |= 0x0080 & 255; // slap in 010 bits
66 warn("0(An) converted to (An)");
71 if ((v + 0x8000) >= 0x18000)
72 return error(range_error);
78 // Arrange for fixup later on
79 AddFixup(FU_WORD | FU_SEXT, sloc, aNexpr);
88 if ((aNexattr & TDB) == cursect)
90 else if ((aNexattr & TDB) != ABS)
93 if (v + 0x8000 >= 0x10000)
94 return error(range_error);
100 // Arrange for fixup later on
101 AddFixup(FU_WORD | FU_SEXT | FU_PCREL, sloc, aNexpr);
107 // Compute ixreg and size+scale
108 w = (WORD)((aNixreg << 12) | aNixsiz);
110 if (aNexattr & DEFINED)
115 return error(abs_error);
117 if (v + 0x80 >= 0x180)
118 return error(range_error);
125 // Fixup the byte later
126 AddFixup(FU_BYTE | FU_SEXT, sloc + 1, aNexpr);
132 // Compute ixreg and size+scale
133 w = (WORD)((aNixreg << 12) | aNixsiz);
135 if (aNexattr & DEFINED)
138 if ((aNexattr & TDB) == cursect)
140 else if ((aNexattr & TDB) != ABS)
143 if (v + 0x80 >= 0x100)
144 return error(range_error);
151 // Fixup the byte later
152 AddFixup(FU_WBYTE | FU_SEXT | FU_PCREL, sloc, aNexpr);
164 return error("illegal byte-sized relative reference");
166 if (v + 0x100 >= 0x200)
167 return error(range_error);
173 AddFixup(FU_BYTE | FU_SEXT, sloc + 1, aNexpr);
182 if (v + 0x10000 >= 0x20000)
183 return error(range_error);
186 MarkRelocatable(cursect, sloc, tdb, MWORD, NULL);
192 AddFixup(FU_WORD | FU_SEXT, sloc, aNexpr);
201 MarkRelocatable(cursect, sloc, tdb, MLONG, NULL);
207 AddFixup(FU_LONG, sloc, aNexpr);
213 // IMMED size problem
219 // 68881/68882/68040 only
220 return error("Sorry, .p constant format is not implemented yet!");
226 MarkRelocatable(cursect, sloc, tdb, MWORD, NULL);
228 if (v + 0x8000 >= 0x10000)
229 return error(range_error);
235 AddFixup(FU_WORD | FU_SEXT, sloc, aNexpr);
244 MarkRelocatable(cursect, sloc, tdb, MLONG, NULL);
250 AddFixup(FU_LONG, sloc, aNexpr);
262 // Deposit bd (if not suppressed)
263 if ((aNexten&0x0030)==EXT_BDSIZE0)
265 // Don't deposit anything (suppressed)
267 else if ((aNexten&0x0030)==EXT_BDSIZEW)
274 MarkRelocatable(cursect, sloc, tdbbd, MWORD, NULL);
276 if (vbd + 0x8000 >= 0x10000)
277 return error(range_error);
283 // Arrange for fixup later on
284 AddFixup(FU_WORD|FU_SEXT, sloc, aNexpr);
295 MarkRelocatable(cursect, sloc, tdbbd, MLONG, NULL);
301 // Arrange for fixup later on
302 AddFixup(FU_LONG|FU_SEXT, sloc, aNexpr);
306 // Deposit od (if not suppressed)
307 if ((aNexten&7)==EXT_IISPRE0 || (aNexten&7)==EXT_IISPREN
308 || (aNexten&7)==EXT_IISNOIN || (aNexten&7)==EXT_IISPOSN)
310 // Don't deposit anything (suppressed)
312 else if ((aNexten&7)==EXT_IISPREW
313 || (aNexten&7)==EXT_IISPOSW || (aNexten&7)==EXT_IISNOIW)
320 MarkRelocatable(cursect, sloc, tdb, MWORD, NULL);
322 if (v + 0x8000 >= 0x10000)
323 return error(range_error);
329 // Arrange for fixup later on
330 AddFixup(FU_WORD|FU_SEXT, sloc, aNexpr);
341 MarkRelocatable(cursect, sloc, tdb, MLONG, NULL);
347 // Arrange for fixup later on
348 AddFixup(FU_LONG|FU_SEXT, sloc, aNexpr);
354 //return error("unsupported 68020 addressing mode");
356 // Bad addressing mode in ea gen
363 // Undefine dirty macros