Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

merge dev #479

Merged
merged 7 commits into from
Dec 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
71 changes: 53 additions & 18 deletions z80core/simdis.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
* Forward declarations
*/
static char *btoh(BYTE b, char *p);
static char *wtoa(WORD w, char *p);

#ifndef EXCLUDE_Z80

Expand Down Expand Up @@ -52,21 +53,21 @@ static const char *const optab_45[8] = {

static const char *const optab_67[64] = {
/*C0*/ "RET\tNZ", "POP\tBC", "JP\tNZ,w", "JP\tw",
/*C4*/ "CALL\tNZ,w", "PUSH\tBC", "ADD\tA,b", "RST\t00",
/*C4*/ "CALL\tNZ,w", "PUSH\tBC", "ADD\tA,b", "RST\t0H",
/*C8*/ "RET\tZ", "RET", "JP\tZ,w", "",
/*CC*/ "CALL\tZ,w", "CALL\tw", "ADC\tA,b", "RST\t08",
/*CC*/ "CALL\tZ,w", "CALL\tw", "ADC\tA,b", "RST\t8H",
/*D0*/ "RET\tNC", "POP\tDE", "JP\tNC,w", "OUT\t(b),A",
/*D4*/ "CALL\tNC,w", "PUSH\tDE", "SUB\tb", "RST\t10",
/*D4*/ "CALL\tNC,w", "PUSH\tDE", "SUB\tb", "RST\t10H",
/*D8*/ "RET\tC", "EXX", "JP\tC,w", "IN\tA,(b)",
/*DC*/ "CALL\tC,w", "", "SBC\tA,b", "RST\t18",
/*DC*/ "CALL\tC,w", "", "SBC\tA,b", "RST\t18H",
/*E0*/ "RET\tPO", "POP\ti", "JP\tPO,w", "EX\t(SP),i",
/*E4*/ "CALL\tPO,w", "PUSH\ti", "AND\tb", "RST\t20",
/*E4*/ "CALL\tPO,w", "PUSH\ti", "AND\tb", "RST\t20H",
/*E8*/ "RET\tPE", "JP\t(i)", "JP\tPE,w", "EX\tDE,HL",
/*EC*/ "CALL\tPE,w", "", "XOR\tb", "RST\t28",
/*EC*/ "CALL\tPE,w", "", "XOR\tb", "RST\t28H",
/*F0*/ "RET\tP", "POP\tAF", "JP\tP,w", "DI",
/*F4*/ "CALL\tP,w", "PUSH\tAF", "OR\tb", "RST\t30",
/*F4*/ "CALL\tP,w", "PUSH\tAF", "OR\tb", "RST\t30H",
/*F8*/ "RET\tM", "LD\tSP,i", "JP\tM,w", "EI",
/*FC*/ "CALL\tM,w", "", "CP\tb", "RST\t38"
/*FC*/ "CALL\tM,w", "", "CP\tb", "RST\t38H"
};

static const char *const optab_ed_23[64] = {
Expand Down Expand Up @@ -217,13 +218,13 @@ int disass(WORD addr)
if ((op & 0xdf) == 0xdd) {
ireg = 'X' + ((op >> 5) & 1);
op = getmem(a++);
undoc_ireg = undoc_ddfd[op >> 3] & (1 << (op & 7));
undoc_ireg = !!(undoc_ddfd[op >> 3] & (1 << (op & 7)));
}
reg1 = (op >> 3) & 7;
reg2 = op & 7;
if (op < 0x40) {
tmpl = optab_01[op];
if (ireg && reg1 == 6 && (reg2 >= 4 && reg2 <= 6))
if (ireg && reg1 == 6 && (4 <= reg2 && reg2 <= 6))
displ = getmem(a++);
} else if (op < 0x80) {
if (op == 0x76)
Expand Down Expand Up @@ -260,8 +261,9 @@ int disass(WORD addr)
}
} else if (op == 0xed) {
if (ireg) {
/* DD/FD followed by ED is an undoc'd NOP */
tmpl = "NOP";
a--;
tmpl = "NOP*";
} else {
op = getmem(a++);
if (0x40 <= op && op < 0x80)
Expand All @@ -271,6 +273,10 @@ int disass(WORD addr)
else
tmpl = "NOP*";
}
} else if (ireg && (op & 0xdf) == 0xdd) {
/* DD/FD followed by DD/FD is an undocumented NOP */
tmpl = "NOP";
a--;
} else
tmpl = optab_67[op & 0x3f];
break;
Expand Down Expand Up @@ -308,13 +314,12 @@ int disass(WORD addr)
switch (*tmpl) {
case 'b': /* byte */
b1 = getmem(a++);
p = btoh(b1, p);
p = wtoa(b1, p);
break;
case 'w': /* word */
b1 = getmem(a++);
b2 = getmem(a++);
p = btoh(b2, p);
p = btoh(b1, p);
p = wtoa((b2 << 8) | b1, p);
break;
case 'r': /* register */
switch (cpu) {
Expand Down Expand Up @@ -347,7 +352,7 @@ int disass(WORD addr)
*p++ = '-';
displ = -displ;
}
p = btoh(displ, p);
p = wtoa(displ, p);
}
} else {
*p++ = 'H';
Expand Down Expand Up @@ -383,22 +388,27 @@ int disass(WORD addr)
case 'j': /* relative jump address */
b1 = getmem(a++);
w = a + (SBYTE) b1;
p = btoh(w >> 8, p);
p = btoh(w & 0xff, p);
p = wtoa(w, p);
break;
case 'n': /* bit number */
*p++ = '0' + bit;
break;
case '\t':
if (undoc_ireg)
if (undoc_ireg) {
undoc_ireg++;
*p++ = '*';
}
#endif
/* fall through */ /* should really be inside #if */
default:
*p++ = *tmpl;
break;
}
}
#ifndef EXCLUDE_Z80
if (undoc_ireg == 1)
*p++ = '*';
#endif
*p++ = '\n';
*p = '\0';
len = a - addr;
Expand Down Expand Up @@ -442,4 +452,29 @@ static char *btoh(BYTE b, char *p)
return p;
}

/*
* convert WORD into assembler hex and copy to string at p
* returns p increased by number of characters produced
*/
static char *wtoa(WORD w, char *p)
{
register char c;
register int onlyz, shift;

onlyz = 1;
for (shift = 12; shift >= 0; shift -= 4) {
c = (w >> shift) & 0xf;
if (onlyz && c > 9)
*p++ = '0';
if (!onlyz || c) {
*p++ = c + (c < 10 ? '0' : '7');
onlyz = 0;
}
}
if (onlyz)
*p++ = '0';
*p++ = 'H';
return p;
}

#endif /* WANT_ICE */
31 changes: 21 additions & 10 deletions z80core/simice.c
Original file line number Diff line number Diff line change
Expand Up @@ -374,8 +374,11 @@ static void do_dump(char *s)
wrk_addr = exatoi(s) & ~0xf;
while (*s != ',' && *s != '\0')
s++;
if (*s && isdigit((unsigned char) *++s))
n = atoi(s);
if (*s && isxdigit((unsigned char) *++s)) {
n = ((exatoi(s) & ~0xf) - wrk_addr) / 16 + 1;
if (n <= 0)
n = 1;
}
printf("Addr ");
for (i = 0; i < 16; i++)
printf("%02x ", i);
Expand All @@ -399,19 +402,27 @@ static void do_dump(char *s)
static void do_list(char *s)
{
register int i;
int n = 10;
register WORD a;

while (isspace((unsigned char) *s))
s++;
if (isxdigit((unsigned char) *s))
wrk_addr = exatoi(s);
while (*s != ',' && *s != '\0')
s++;
if (*s && isdigit((unsigned char) *++s))
n = atoi(s);
for (i = 0; i < n; i++) {
printf("%04x - ", (unsigned int) wrk_addr);
wrk_addr += disass(wrk_addr);
if (*s && isxdigit((unsigned char) *++s)) {
a = exatoi(s);
if (a < wrk_addr)
a = wrk_addr;
while (wrk_addr <= a) {
printf("%04x - ", (unsigned int) wrk_addr);
wrk_addr += disass(wrk_addr);
}
} else {
for (i = 0; i < 10; i++) {
printf("%04x - ", (unsigned int) wrk_addr);
wrk_addr += disass(wrk_addr);
}
}
}

Expand Down Expand Up @@ -1000,8 +1011,8 @@ static void do_show(void)
*/
static void do_help(void)
{
puts("d [address][,count] dump memory");
puts("l [address][,count] list memory");
puts("d [from][,to] dump memory");
puts("l [from][,to] list memory");
puts("m [address] modify memory");
puts("f address,count,value fill memory");
puts("v from,to,count move memory");
Expand Down
Loading