+ else
+ {
+ if (aop->aopu.aop_stk >= 0)
+ offset += _G.stack.param_offset;
+ tsprintf (s, "!*ixx", aop->aopu.aop_stk + offset);
+ }
+
+ return traceAlloc(&_G.trace.aops, Safe_strdup(s));
+
+ case AOP_CRY:
+ wassertl (0, "Tried to fetch from a bit variable");
+
+ case AOP_ACC:
+ if (!offset)
+ {
+ return "a";
+ }
+ else
+ {
+ tsprintf(s, "!zero");
+ return traceAlloc(&_G.trace.aops, Safe_strdup(s));
+ }
+
+ case AOP_HLREG:
+ wassert (offset < 2);
+ return aop->aopu.aop_str[offset];
+
+ case AOP_LIT:
+ return aopLiteral (aop->aopu.aop_lit, offset);
+
+ case AOP_SIMPLELIT:
+ {
+ unsigned long v = aop->aopu.aop_simplelit;
+
+ v >>= (offset * 8);
+ tsprintf (s, "!immedbyte", (unsigned int) v & 0xff);
+
+ return traceAlloc(&_G.trace.aops, Safe_strdup(s));
+ }
+ case AOP_STR:
+ aop->coff = offset;
+ return aop->aopu.aop_str[offset];
+
+ case AOP_PAIRPTR:
+ setupPair (aop->aopu.aop_pairId, aop, offset);
+ sprintf (s, "(%s)", _pairs[aop->aopu.aop_pairId].name);
+
+ return traceAlloc(&_G.trace.aops, Safe_strdup(s));
+
+ default:
+ break;
+ }
+ wassertl (0, "aopget got unsupported aop->type");
+ exit (0);
+}
+
+bool
+isRegString (const char *s)
+{
+ if (!strcmp (s, "b") ||
+ !strcmp (s, "c") ||
+ !strcmp (s, "d") ||
+ !strcmp (s, "e") ||
+ !strcmp (s, "a") ||
+ !strcmp (s, "h") ||
+ !strcmp (s, "l"))
+ return TRUE;
+ return FALSE;
+}
+
+bool
+isConstant (const char *s)
+{
+ /* This is a bit of a hack... */
+ return (*s == '#' || *s == '$');
+}
+
+bool
+canAssignToPtr (const char *s)
+{
+ if (isRegString (s))
+ return TRUE;
+ if (isConstant (s))
+ return TRUE;
+ return FALSE;
+}
+
+/*-----------------------------------------------------------------*/
+/* aopPut - puts a string for a aop */
+/*-----------------------------------------------------------------*/
+static void
+aopPut (asmop * aop, const char *s, int offset)
+{
+ char buffer2[256];
+
+ if (aop->size && offset > (aop->size - 1))
+ {
+ werror (E_INTERNAL_ERROR, __FILE__, __LINE__,
+ "aopPut got offset > aop->size");
+ exit (0);
+ }
+
+ // PENDING
+ tsprintf(buffer2, s);
+ s = buffer2;
+
+ /* will assign value to value */
+ /* depending on where it is ofcourse */
+ switch (aop->type)
+ {
+ case AOP_DIR:
+ /* Direct. Hmmm. */
+ wassert (IS_GB);
+ if (strcmp (s, "a"))
+ emit2 ("ld a,%s", s);
+ emit2 ("ld (%s+%d),a", aop->aopu.aop_dir, offset);
+ break;
+
+ case AOP_SFR:
+ wassert (IS_GB);
+ if (strcmp (s, "a"))
+ emit2 ("ld a,%s", s);
+ emit2 ("ldh (%s+%d),a", aop->aopu.aop_dir, offset);
+ break;
+
+ case AOP_REG:
+ if (!strcmp (s, "!*hl"))
+ emit2 ("ld %s,!*hl", aop->aopu.aop_reg[offset]->name);
+ else
+ emit2 ("ld %s,%s",
+ aop->aopu.aop_reg[offset]->name, s);
+ break;
+
+ case AOP_IY:
+ wassert (!IS_GB);
+ if (!canAssignToPtr (s))
+ {
+ emit2 ("ld a,%s", s);
+ setupPair (PAIR_IY, aop, offset);
+ emit2 ("ld !*iyx,a", offset);
+ }
+ else
+ {
+ setupPair (PAIR_IY, aop, offset);
+ emit2 ("ld !*iyx,%s", offset, s);
+ }
+ break;
+