void ulas_arch_set(enum ulas_archs arch) {
switch (arch) {
case ULAS_ARCH_SM83:
- ulas.arch = (struct ulas_arch){ULAS_SM83_REGS, ULAS_SM83_REGS_LEN,
+ ulas.arch = (struct ulas_arch){arch, ULAS_SM83_REGS, ULAS_SM83_REGS_LEN,
ULASINSTRS_SM83, ULAS_LE};
break;
default:
ULASPANIC("Unknown architecture\n");
}
}
+
+unsigned int ulas_arch_opcode_len(const char *buf, unsigned long read) {
+ if (read == 0) {
+ return 0;
+ }
+ switch (ulas.arch.type) {
+ case ULAS_ARCH_SM83:
+ if ((unsigned char)buf[0] == 0xCB) {
+ return 2;
+ }
+ return 1;
+ default:
+ return 0;
+ }
+}
enum ulas_archs { ULAS_ARCH_SM83 };
struct ulas_arch {
+ enum ulas_archs type;
const char **regs_names;
unsigned long regs_len;
void ulas_arch_set(enum ulas_archs arch);
+// returns how many bytes of an instruction are occupied
+// by the opcode based on its data
+unsigned int ulas_arch_opcode_len(const char *buf, unsigned long read);
+
#endif
ulas_dasm_print_addr(dst);
fprintf(dst, " %s ", instr->name);
- int bi = 0;
+ unsigned int bi = ulas_arch_opcode_len(buf, read);
for (int i = 0; instr->tokens[i]; i++) {
int dat = instr->tokens[i];
switch (dat) {
case ULAS_A8:
fprintf(dst, "0x%x", buf[bi++]);
break;
+ case ULAS_A16:
case ULAS_E16: {
unsigned short val = 0;
if (ulas.arch.endianess == ULAS_BE) {
-
+ val = (short)buf[bi + 1] | (short)(buf[bi] << 8);
} else {
- val = (char)buf[bi+1] | (char)(buf[bi] << 8);
+ val = (short)buf[bi] | (short)(buf[bi + 1] << 8);
}
- bi+=2;
+ bi += 2;
fprintf(dst, "0x%x", val);
break;
}
- case ULAS_A16:
- break;
default: {
const char *reg = ulas_asmregstr(dat);
if (reg) {