1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
|
// license:BSD-3-Clause
// copyright-holders:Sandro Ronco
/******************************************************************************
Sanyo LC8670 disassembler
******************************************************************************/
#include "emu.h"
#include "debugger.h"
#include "lc8670.h"
const lc8670_cpu_device::dasm_entry lc8670_cpu_device::s_dasm_table[] =
{
{ "NOP" , OP_NULL, OP_NULL, 0 }, // 0x0*
{ "BR" , OP_R8 , OP_NULL, 0 },
{ "LD" , OP_D9 , OP_NULL, 0 },
{ "LD" , OP_RI , OP_NULL, 0 },
{ "CALL", OP_A12 , OP_NULL, 0 },
{ "CALLR", OP_R16 , OP_NULL, 0 }, // 0x1*
{ "BRF" , OP_R16 , OP_NULL, 0 },
{ "ST" , OP_D9 , OP_NULL, 0 },
{ "ST" , OP_RI , OP_NULL, 0 },
{ "CALL", OP_A12 , OP_NULL, 0 },
{ "CALLF", OP_A16 , OP_NULL, 0 }, // 0x2*
{ "JMPF", OP_A16 , OP_NULL, 0 },
{ "MOV" , OP_D9 , OP_I8 , 1 },
{ "MOV" , OP_RI , OP_I8 , 1 },
{ "JMP" , OP_A12 , OP_NULL, 0 },
{ "MUL" , OP_NULL, OP_NULL, 0 }, // 0x3*
{ "BE" , OP_I8 , OP_R8 , 0 },
{ "BE" , OP_D9 , OP_R8 , 0 },
{ "BE" , OP_RII8, OP_R8 , 0 },
{ "JMP" , OP_A12 , OP_NULL, 0 },
{ "DIV" , OP_NULL, OP_NULL, 0 }, // 0x4*
{ "BNE" , OP_I8 , OP_R8 , 0 },
{ "BNE" , OP_D9 , OP_R8 , 0 },
{ "BNE" , OP_RII8, OP_R8 , 0 },
{ "BPC" , OP_D9B3, OP_R8 , 0 },
{ "LDF" , OP_NULL, OP_NULL, 0 }, // 0x5*
{ "STF" , OP_NULL, OP_NULL, 0 },
{ "DBNZ", OP_D9 , OP_R8 , 0 },
{ "DBNZ", OP_RI , OP_R8RI, 0 },
{ "BPC" , OP_D9B3, OP_R8 , 0 },
{ "PUSH", OP_D9 , OP_NULL, 0 }, // 0x6*
{ "PUSH", OP_D9 , OP_NULL, 0 },
{ "INC" , OP_D9 , OP_NULL, 0 },
{ "INC" , OP_RI , OP_NULL, 0 },
{ "BP" , OP_D9B3, OP_R8 , 0 },
{ "POP" , OP_D9 , OP_NULL, 0 }, // 0x7*
{ "POP" , OP_D9 , OP_NULL, 0 },
{ "DEC" , OP_D9 , OP_NULL, 0 },
{ "DEC" , OP_RI , OP_NULL, 0 },
{ "BP" , OP_D9B3, OP_R8 , 0 },
{ "BZ" , OP_R8 , OP_NULL, 0 }, // 0x8*
{ "ADD" , OP_I8 , OP_NULL, 0 },
{ "ADD" , OP_D9 , OP_NULL, 0 },
{ "ADD" , OP_RI , OP_NULL, 0 },
{ "BN" , OP_D9B3, OP_R8 , 0 },
{ "BNZ" , OP_R8 , OP_NULL, 0 }, // 0x9*
{ "ADDC", OP_I8 , OP_NULL, 0 },
{ "ADDC", OP_D9 , OP_NULL, 0 },
{ "ADDC", OP_RI , OP_NULL, 0 },
{ "BN" , OP_D9B3, OP_R8 , 0 },
{ "RET" , OP_NULL, OP_NULL, 0 }, // 0xa*
{ "SUB" , OP_I8 , OP_NULL, 0 },
{ "SUB" , OP_D9 , OP_NULL, 0 },
{ "SUB" , OP_RI , OP_NULL, 0 },
{ "NOT1", OP_D9B3, OP_NULL, 0 },
{ "RETI", OP_NULL, OP_NULL, 0 }, // 0xb*
{ "SUBC", OP_I8 , OP_NULL, 0 },
{ "SUBC", OP_D9 , OP_NULL, 0 },
{ "SUBC", OP_RI , OP_NULL, 0 },
{ "NOT1", OP_D9B3, OP_NULL, 0 },
{ "ROR" , OP_NULL, OP_NULL, 0 }, // 0xc*
{ "LDC" , OP_NULL, OP_NULL, 0 },
{ "XCH" , OP_D9 , OP_NULL, 0 },
{ "XCH" , OP_RI , OP_NULL, 0 },
{ "CLR1", OP_D9B3, OP_NULL, 0 },
{ "RORC", OP_NULL, OP_NULL, 0 }, // 0xd*
{ "OR" , OP_I8 , OP_NULL, 0 },
{ "OR" , OP_D9 , OP_NULL, 0 },
{ "OR" , OP_RI , OP_NULL, 0 },
{ "CLR1", OP_D9B3, OP_NULL, 0 },
{ "ROL" , OP_NULL, OP_NULL, 0 }, // 0xe*
{ "AND" , OP_I8 , OP_NULL, 0 },
{ "AND" , OP_D9 , OP_NULL, 0 },
{ "AND" , OP_RI , OP_NULL, 0 },
{ "SET1", OP_D9B3, OP_NULL, 0 },
{ "ROLC", OP_NULL, OP_NULL, 0 }, // 0xf*
{ "XOR" , OP_I8 , OP_NULL, 0 },
{ "XOR" , OP_D9 , OP_NULL, 0 },
{ "XOR" , OP_RI , OP_NULL, 0 },
{ "SET1", OP_D9B3, OP_NULL, 0 },
};
void lc8670_cpu_device::dasm_arg(uint8_t op, char *buffer, offs_t pc, int arg, const uint8_t *oprom, int &pos)
{
switch( arg )
{
case OP_NULL:
buffer[0] = '\0';
break;
case OP_R8:
pc++;
// fall through
case OP_R8RI:
buffer += sprintf(buffer, "%04x", (pc + 1 + oprom[pos] - (oprom[pos]&0x80 ? 0x100 : 0)) & 0xffff);
pos++;
break;
case OP_R16:
buffer += sprintf(buffer, "%04x", (pc + 2 + ((oprom[pos+1]<<8) | oprom[pos])) & 0xffff);
pos += 2;
break;
case OP_RI:
buffer += sprintf(buffer, "@%x", op & 0x03);
break;
case OP_A12:
buffer += sprintf(buffer, "%04x", ((pc + 2) & 0xf000) | ((op & 0x10)<<7) | ((op & 0x07)<<8) | oprom[pos]);
pos++;
break;
case OP_A16:
buffer += sprintf(buffer, "%04x", (oprom[pos]<<8) | oprom[pos+1]);
pos += 2;
break;
case OP_I8:
buffer += sprintf(buffer, "#$%02x", oprom[pos++]);
break;
case OP_B3:
buffer += sprintf(buffer, "%x", op & 0x07);
break;
case OP_D9:
buffer += sprintf(buffer, "($%03x)", ((op & 0x01)<<8) | oprom[pos]);
pos++;
break;
case OP_D9B3:
buffer += sprintf(buffer, "($%03x)", ((op & 0x10)<<4) | oprom[pos]);
buffer += sprintf(buffer, ",%x", op & 0x07);
pos++;
break;
case OP_RII8:
buffer += sprintf(buffer, "@%x", op & 0x03);
buffer += sprintf(buffer, ",#$%02x", oprom[pos]);
pos++;
break;
}
}
//-------------------------------------------------
// disasm_disassemble - call the disassembly
// helper function
//-------------------------------------------------
offs_t lc8670_cpu_device::disasm_disassemble(std::ostream &stream, offs_t pc, const uint8_t *oprom, const uint8_t *opram, uint32_t options)
{
int pos = 0;
char arg1[16], arg2[16];
uint8_t op = oprom[pos++];
int op_idx = decode_op(op);
const dasm_entry *inst = &s_dasm_table[op_idx];
util::stream_format(stream, "%-8s", inst->str);
dasm_arg(op, inst->inv ? arg2 : arg1, pc+0, inst->arg1, oprom, pos);
dasm_arg(op, inst->inv ? arg1 : arg2, pc+1, inst->arg2, oprom, pos);
stream << arg1;
if (inst->arg2 != OP_NULL)
stream << "," << arg2;
return pos;
}
//-------------------------------------------------
// disasm_disassemble - call the disassembly
// helper function
//-------------------------------------------------
offs_t lc8670_cpu_device::disasm_disassemble(char *buffer, offs_t pc, const uint8_t *oprom, const uint8_t *opram, uint32_t options)
{
std::ostringstream stream;
offs_t result = disasm_disassemble(stream, pc, oprom, opram, options);
std::string stream_str = stream.str();
strcpy(buffer, stream_str.c_str());
return result;
}
|