static void printmem(FILE *fd, Loc *l, char spec) { if (l->type == Locmem) { if (l->mem.constdisp) fprintf(fd, "%ld", l->mem.constdisp); } else if (l->mem.lbldisp) { fprintf(fd, "%s", l->mem.lbldisp); } if (!l->mem.base || l->mem.base->reg.colour == Rrip) { fprintf(fd, "+0(SB)"); } else { fprintf(fd, "("); locprint(fd, l->mem.base, 'r'); fprintf(fd, ")"); } if (l->mem.idx) { fprintf(fd, "("); locprint(fd, l->mem.idx, 'r'); fprintf(fd, "*%d", l->mem.scale); fprintf(fd, ")"); } }
void printmem(FILE *fd, Loc *l, char spec) { if (l->type == Locmem) { if (l->mem.constdisp) fprintf(fd, "%ld", l->mem.constdisp); } else { if (l->mem.lbldisp) fprintf(fd, "%s", l->mem.lbldisp); } if (l->mem.base) { fprintf(fd, "("); locprint(fd, l->mem.base, 'r'); if (l->mem.idx) { fprintf(fd, ","); locprint(fd, l->mem.idx, 'r'); } if (l->mem.scale > 1) fprintf(fd, ",%d", l->mem.scale); if (l->mem.base) fprintf(fd, ")"); } else if (l->type != Locmeml) { die("Only locmeml can have unspecified base reg"); } }
/* displays a room's name */ void showroom(int i) { strcpy(Str1,""); strcpy(Str2,""); switch(Current_Environment) { case E_MANSION: strcpy(Str2,"A luxurious mansion: "); break; case E_HOUSE: strcpy(Str2,"A house: "); break; case E_HOVEL: strcpy(Str2,"A hovel: "); break; case E_CITY: strcpy(Str2,"The City of Rampart"); break; case E_VILLAGE: switch(Villagenum) { case 1: strcpy(Str2,"The Village of Star View"); break; case 2: strcpy(Str2,"The Village of Woodmere"); break; case 3: strcpy(Str2,"The Village of Stormwatch"); break; case 4: strcpy(Str2,"The Village of Thaumaris"); break; case 5: strcpy(Str2,"The Village of Skorch"); break; case 6: strcpy(Str2,"The Village of Whorfen"); break; } break; case E_CAVES: strcpy(Str2,"The Goblin Caves: "); break; case E_CASTLE: strcpy(Str2,"The Archmage's Castle: "); break; case E_ASTRAL: strcpy(Str2,"The Astral Plane: "); break; case E_VOLCANO: strcpy(Str2,"The Volcano: "); break; case E_PALACE: strcpy(Str2,"The Palace Dungeons: "); break; case E_SEWERS: strcpy(Str2,"The Sewers: "); break; case E_TACTICAL_MAP: strcpy(Str2,"The Tactical Map "); break; default: strcpy(Str2,""); break; } if (Current_Environment == Current_Dungeon) { strcpy(Str1,"Level "); if (Level->depth < 10) { Str1[6] = Level->depth + '0'; Str1[7] = 0; } else { Str1[6] = (Level->depth / 10) + '0'; Str1[7] = (Level->depth % 10) + '0'; Str1[8] = 0; } strcat(Str1," ("); strcat(Str1,roomname(i)); strcat(Str1,")"); } else if (strlen(Str2) == 0 || Current_Environment == E_MANSION || Current_Environment == E_HOUSE || Current_Environment == E_HOVEL) strcpy(Str1,roomname(i)); strcat(Str2,Str1); locprint(Str2); }
static void iprintf(FILE *fd, Insn *insn) { char *p; int i; int idx; /* x64 has a quirk; it has no movzlq because mov zero extends. This * means that we need to do a movl when we really want a movzlq. Since * we don't know the name of the reg to use, we need to sub it in when * writing... */ switch (insn->op) { case Imovzx: if (insn->args[0]->mode == ModeL && insn->args[1]->mode == ModeQ) { if (insn->args[1]->reg.colour) { insn->op = Imov; insn->args[1] = coreg(insn->args[1]->reg.colour, ModeL); } } break; case Imovs: if (insn->args[0]->reg.colour == Rnone || insn->args[1]->reg.colour == Rnone) break; /* moving a reg to itself is dumb. */ if (insn->args[0]->reg.colour == insn->args[1]->reg.colour) return; break; case Imov: assert(!isfloatmode(insn->args[0]->mode)); if (insn->args[0]->type != Locreg || insn->args[1]->type != Locreg) break; if (insn->args[0]->reg.colour == Rnone || insn->args[1]->reg.colour == Rnone) break; /* if one reg is a subreg of another, we can just use the right * mode to move between them. */ if (issubreg(insn->args[0], insn->args[1])) insn->args[0] = coreg(insn->args[0]->reg.colour, insn->args[1]->mode); /* moving a reg to itself is dumb. */ if (insn->args[0]->reg.colour == insn->args[1]->reg.colour) return; break; default: break; } p = insnfmt[insn->op]; i = 0; /* NB: this is 1 based indexing */ for (; *p; p++) { if (*p != '%') { fputc(*p, fd); continue; } /* %-formating */ p++; idx = i; again: switch (*p) { case '\0': goto done; /* skip the final p++ */ break; case 'R': /* int register */ case 'F': /* float register */ case 'M': /* memory */ case 'I': /* imm */ case 'V': /* reg/mem */ case 'U': /* reg/imm */ case 'X': /* reg/mem/imm */ locprint(fd, insn->args[idx], *p); i++; break; case 'T': fputs(modenames[insn->args[idx]->mode], fd); break; default: /* the asm description uses 1-based indexing, so that 0 * can be used as a sentinel. */ if (!isdigit(*p)) die("Invalid %%-specifier '%c'", *p); idx = strtol(p, &p, 10) - 1; goto again; break; } } done: return; }