Skip to content
This repository was archived by the owner on Nov 22, 2023. It is now read-only.

Commit 843e6e9

Browse files
(z80asm, ticks, dis) Add kc160_z80 cpu - compatible to z80_strict
1 parent be442eb commit 843e6e9

28 files changed

+52416
-17394
lines changed

src/common/z80asm_cpu.c

+5
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,11 @@ bool cpu_compatible(int code_cpu_id, int lib_cpu_id) {
143143
return false;
144144
case CPU_KC160:
145145
return false;
146+
case CPU_KC160_Z80:
147+
switch (lib_cpu_id) {
148+
case CPU_Z80_STRICT: case CPU_8080: return true;
149+
default: return false;
150+
}
146151
default:
147152
xassert(0);
148153
return false;

src/common/z80asm_cpu.def

+3-2
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@ X(CPU_R800, 12, "r800")
2020

2121
X(CPU_Z180, 3, "z180")
2222

23+
X(CPU_KC160, 15, "kc160")
24+
X(CPU_KC160_Z80, 16, "kc160_z80")
25+
2326
X(CPU_Z80_STRICT, 2, "z80_strict")
2427
X(CPU_8085, 11, "8085")
2528

@@ -34,6 +37,4 @@ X(CPU_EZ80, 5, "ez80")
3437

3538
X(CPU_8080, 10, "8080")
3639

37-
X(CPU_KC160, 15, "kc160")
38-
3940
#undef X

src/ticks/cpu.h

+17-14
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,19 @@
44
extern int c_cpu;
55
extern int c_adl_mode;
66

7-
#define CPU_Z80 1
8-
#define CPU_Z180 2
9-
#define CPU_R2KA 4
10-
#define CPU_R3K 8
11-
#define CPU_Z80N 16
12-
#define CPU_R800 32
13-
#define CPU_GBZ80 64
14-
#define CPU_8080 128
15-
#define CPU_8085 256
16-
#define CPU_EZ80 512
17-
#define CPU_R4K 1024
18-
#define CPU_KC160 2048
7+
#define CPU_Z80 1
8+
#define CPU_Z180 2
9+
#define CPU_R2KA 4
10+
#define CPU_R3K 8
11+
#define CPU_Z80N 16
12+
#define CPU_R800 32
13+
#define CPU_GBZ80 64
14+
#define CPU_8080 128
15+
#define CPU_8085 256
16+
#define CPU_EZ80 512
17+
#define CPU_R4K 1024
18+
#define CPU_KC160 2048
19+
#define CPU_KC160_Z80 4096
1920

2021
#define is8080() ( (c_cpu & CPU_8080) )
2122
#define is8085() ( (c_cpu & CPU_8085) )
@@ -28,12 +29,14 @@ extern int israbbit4k(void);
2829
#define isz180() ( c_cpu & (CPU_Z180))
2930
#define isez80() ( c_cpu & (CPU_EZ80))
3031
#define isz80n() ( c_cpu & CPU_Z80N )
31-
#define iskc160() ( c_cpu & CPU_KC160 )
32+
#define iskc160() ( c_cpu & (CPU_KC160|CPU_KC160_Z80) )
33+
#define iskc160z80() ( c_cpu & CPU_KC160_Z80 )
34+
#define iskc160ext() ( c_cpu & CPU_KC160 )
3235
#define canaltreg() ( ( c_cpu & (CPU_8080|CPU_8085|CPU_GBZ80)) == 0 )
3336
#define canindex() ( ( c_cpu & (CPU_8080|CPU_8085|CPU_GBZ80)) == 0 )
3437
#define canixh() ( c_cpu & (CPU_Z80|CPU_Z80N|CPU_R800|CPU_EZ80))
3538
#define cansll() ( c_cpu & (CPU_Z80|CPU_Z80N))
3639
#define canz180() ( c_cpu & (CPU_Z180|CPU_EZ80))
3740
#define cancbundoc() ( c_cpu & (CPU_Z80|CPU_Z80N))
3841

39-
#endif
42+
#endif

src/ticks/disassembler_alg.c

+16-16
Original file line numberDiff line numberDiff line change
@@ -287,15 +287,15 @@ static char *handle_hl(int index)
287287
static char* handle_kc_prefix(uint8_t pfx)
288288
{
289289
static char* kc160_prefix_table[] = { "x", "y", "a", "p", "", "", "", "z" };
290-
if (!iskc160() || pfx > 7)
290+
if (!iskc160ext() || pfx > 7)
291291
return "";
292292
else
293293
return kc160_prefix_table[pfx];
294294
}
295295

296296
static char* handle_kc_segment(uint8_t pfx)
297297
{
298-
if (!iskc160() || pfx > 7)
298+
if (!iskc160ext() || pfx > 7)
299299
return "";
300300
else {
301301
static char buffer[10]; // NOTE: not reentrant
@@ -404,7 +404,7 @@ static char* handle_ed_assorted_instructions(dcontext* state, uint8_t y)
404404
static char* kc160_table[] = { "ld i,a", "ld r,a", "ld a,i", "ld a,r", "rrd", "rld", "mul de,hl", "muls de,hl" };
405405

406406

407-
if (iskc160() && state->kc_prefix < 8 && (y == 4 || y == 5)) { // rrd, rld
407+
if (iskc160ext() && state->kc_prefix < 8 && (y == 4 || y == 5)) { // rrd, rld
408408
static char buffer[20]; // NOTE: not reentrant
409409
snprintf(buffer, sizeof(buffer), "%-10s(%shl)", kc160_table[y], handle_kc_prefix(state->kc_prefix));
410410
return buffer;
@@ -699,7 +699,7 @@ int disassemble2(int pc, char *bufstart, size_t buflen, int compact)
699699
} else {
700700
BUF_PRINTF("%-10s", "nop");
701701
}
702-
} else if ( iskc160() && z == y ) {
702+
} else if ( iskc160ext() && z == y ) {
703703
state->kc_prefix = z; continue;
704704
} else {
705705
if ( isez80() ) {
@@ -948,7 +948,7 @@ int disassemble2(int pc, char *bufstart, size_t buflen, int compact)
948948
else if ( b == 0x35 ) BUF_PRINTF("add de,%s",handle_immed16(state, opbuf1, sizeof(opbuf1)));
949949
else if ( b == 0x36 ) BUF_PRINTF("add bc,%s",handle_immed16(state, opbuf1, sizeof(opbuf1)));
950950
else BUF_PRINTF("nop");
951-
} else if (iskc160() ) {
951+
} else if (iskc160ext() ) {
952952
if ( q == 0 && z < 3 && p < 3 ) BUF_PRINTF("%-10s(%s%s),%s", "ld", kc160_handle_register_rel(state,z), handle_displacement(state, opbuf1,sizeof(opbuf1)), kc160_handle_register_r24(state, p));
953953
else if ( q == 1 && z < 3 && p < 3 ) BUF_PRINTF("%-10s%s,(%s%s)", "ld", kc160_handle_register_r24(state, p), kc160_handle_register_rel(state,z), handle_displacement(state, opbuf1,sizeof(opbuf1)));
954954
else if ( q == 0 && z == 7 && p < 3) BUF_PRINTF("%-10s%s","push", kc160_handle_register_r24(state, p));
@@ -1016,7 +1016,7 @@ int disassemble2(int pc, char *bufstart, size_t buflen, int compact)
10161016
else if ( y == 2 && isez80()) BUF_PRINTF("%-10six,iy%s",handle_ez80_am(state,"lea"),handle_displacement(state, opbuf1, sizeof(opbuf1)));
10171017
else if ( (y % 2 )&& p >= 0 && p <= 3 ) BUF_PRINTF("%-10s%s",p == 3 ? handle_ez80_am(state,"mlt") : "mlt", handle_register16(state,p,0));
10181018
else BUF_PRINTF("nop");
1019-
} else if ( iskc160() ) {
1019+
} else if ( iskc160ext() ) {
10201020
if ( y == 0 ) BUF_PRINTF("%-10s","neg");
10211021
else if ( y == 1 ) BUF_PRINTF("%-10s%s", "call3", handle_addr24(state, opbuf1, sizeof(opbuf1)));
10221022
else if ( y == 2 ) BUF_PRINTF("%-10s","tra");
@@ -1042,9 +1042,9 @@ int disassemble2(int pc, char *bufstart, size_t buflen, int compact)
10421042
else if ( isez80() && y == 4 ) BUF_PRINTF("%-10six%s",handle_ez80_am(state,"pea"),handle_displacement(state, opbuf1, sizeof(opbuf1)));
10431043
else if ( isez80() && y == 5 ) BUF_PRINTF("%-10smb,a","ld");
10441044
else if ( isez80() && y == 7 ) BUF_PRINTF("%-10s","stmix");
1045-
else if ( iskc160() && y == 2 ) BUF_PRINTF("%-10s","retn3");
1046-
else if ( iskc160() && y == 6 ) BUF_PRINTF("%-10sdehl,bc","div");
1047-
else if ( iskc160() && y == 7 ) BUF_PRINTF("%-10sdehl,bc","divs");
1045+
else if ( iskc160ext() && y == 2 ) BUF_PRINTF("%-10s","retn3");
1046+
else if ( iskc160ext() && y == 6 ) BUF_PRINTF("%-10sdehl,bc","div");
1047+
else if ( iskc160ext() && y == 7 ) BUF_PRINTF("%-10sdehl,bc","divs");
10481048
else if ( (isz180() || isez80() || iskc160()) && y != 0 ) BUF_PRINTF("nop");
10491049
else if ( !israbbit() ) { BUF_PRINTF("%-10s", handle_ez80_am(state,"retn")); dolf=1; }
10501050
break;
@@ -1091,7 +1091,7 @@ int disassemble2(int pc, char *bufstart, size_t buflen, int compact)
10911091
else if ( y == 3 ) BUF_PRINTF("lddsr");
10921092
} else if ( ((isez80() && z <= 4) || z <= 3) && y >= 4 ) {
10931093
BUF_PRINTF("%s", handle_ez80_am(state, handle_block_instruction(state, z, y)));
1094-
} else if ( iskc160()) {
1094+
} else if ( iskc160ext()) {
10951095
// KC160, 0x80 - 0xbf page
10961096
if ( q == 0 && z >=4 && z < 7 ) BUF_PRINTF("%-10s(%s%s),%s","ld",kc160_handle_register_rel(state, z - 4),handle_displacement(state, opbuf1, sizeof(opbuf1)), handle_register16(state, p, 0));
10971097
else if ( q == 1 && z >=4 && z < 7 ) BUF_PRINTF("%-10s%s,(%s%s)","ld", handle_register16(state, p, 0), kc160_handle_register_rel(state, z - 4),handle_displacement(state, opbuf1, sizeof(opbuf1)));
@@ -1155,12 +1155,12 @@ int disassemble2(int pc, char *bufstart, size_t buflen, int compact)
11551155
} else if ( z == 7 && y <= 2 && isez80() ) {
11561156
char *instrs[] = { "ld i,hl", "nop", "ld hl,i"};
11571157
BUF_PRINTF("%s",instrs[y]);
1158-
} else if ( iskc160() && y >= 4 && z < 4) BUF_PRINTF("%-10s%s", handle_ez80_am(state, handle_block_instruction(state, z, y)), z == 0 ? "xy" : "x");
1159-
else if( iskc160() && z == 2 ) BUF_PRINTF("%-10s%s,%s", "jp3", cc_table[y], handle_addr24(state,opbuf1,sizeof(opbuf1)));
1160-
else if ( iskc160() && b == 0xc3 ) BUF_PRINTF("%-10s%s", "jp3", handle_addr24(state,opbuf1,sizeof(opbuf1)));
1161-
else if ( iskc160() && q == 0 && z == 4 ) BUF_PRINTF("%-10s%s,%s","ld", kc160_p_table[p], kc160_p_table[3-p]);
1162-
else if ( iskc160() && q == 0 && z == 5 ) BUF_PRINTF("%-10s%s,%s","ld", kc160_p_table[p], kc160_p_table[(3-p+2)%4]);
1163-
else if ( iskc160() && q == 1 && z == 4 ) BUF_PRINTF("%-10s%s,%s","ld", kc160_p_table[p], kc160_p_table[(p+2)%4]);
1158+
} else if ( iskc160ext() && y >= 4 && z < 4) BUF_PRINTF("%-10s%s", handle_ez80_am(state, handle_block_instruction(state, z, y)), z == 0 ? "xy" : "x");
1159+
else if( iskc160ext() && z == 2 ) BUF_PRINTF("%-10s%s,%s", "jp3", cc_table[y], handle_addr24(state,opbuf1,sizeof(opbuf1)));
1160+
else if ( iskc160ext() && b == 0xc3 ) BUF_PRINTF("%-10s%s", "jp3", handle_addr24(state,opbuf1,sizeof(opbuf1)));
1161+
else if ( iskc160ext() && q == 0 && z == 4 ) BUF_PRINTF("%-10s%s,%s","ld", kc160_p_table[p], kc160_p_table[3-p]);
1162+
else if ( iskc160ext() && q == 0 && z == 5 ) BUF_PRINTF("%-10s%s,%s","ld", kc160_p_table[p], kc160_p_table[(3-p+2)%4]);
1163+
else if ( iskc160ext() && q == 1 && z == 4 ) BUF_PRINTF("%-10s%s,%s","ld", kc160_p_table[p], kc160_p_table[(p+2)%4]);
11641164
else if ( q == 1 && z == 1 && y == 3 && israbbit4k()) BUF_PRINTF("%-10s","exp");
11651165
else if ( q == 1 && z == 2 && y == 5 && israbbit4k()) BUF_PRINTF("%-10s(hl)","call");
11661166
else if ( q == 1 && z == 2 && y == 7 && israbbit4k()) BUF_PRINTF("%-10s(jkhl)","llcall");

src/ticks/disassembler_main.c

+3
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ static void usage(char *program)
4444
printf(" -m8080 Disassemble 8080 code (with z80 mnenomics)\n");
4545
printf(" -m8085 Disassemble 8085 code (with z80 mnenomics)\n");
4646
printf(" -mkc160 Disassemble KC160\n");
47+
printf(" -mkc160_z80 Disassemble KC160 in Z80 mode\n");
4748

4849
exit(1);
4950
}
@@ -132,6 +133,8 @@ int main(int argc, char **argv)
132133
c_adl_mode = 1;
133134
} else if ( strcmp(&argv[0][1],"mkc160") == 0 ) {
134135
c_cpu = CPU_KC160;
136+
} else if ( strcmp(&argv[0][1],"mkc160_z80") == 0 ) {
137+
c_cpu = CPU_Z80;
135138
} else {
136139
printf("Unknown CPU: %s\n",&argv[0][2]);
137140
}

0 commit comments

Comments
 (0)