summaryrefslogtreecommitdiff
path: root/disasm.c
blob: b79d55bbeefd25d41701a5da9fc0d6096535f3e9 (plain)
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
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
#include "sux.h"
#include "disasm.h"
#include <string.h>

#define ORTHO_1CC(mne, cc) \
	mne##_R##cc: case mne##_M##cc

#define ORTHO_1OP(mne) \
	mne##_R: case mne##_M

#define ORTHO_2OP(mne) \
	mne##_RR: case mne##_RM: case mne##_MR: case mne##_MM


void print_info(struct sux *cpu, WINDOW *w, uint8_t lines, uint8_t thread) {
	for (uint8_t i = (24*thread)+2; i <= 24*(thread+1); i++) {
		wmove(w, i, 0);
		waddch(w, (i == lines) ? '>' : ' ');
	}
	wmove(w, lines, 1);
	wclrtoeol(w);
	wprintw(w, "pc: $%04"PRIX64  , cpu->pc);
	wprintw(w, ", ps: %c%c---%c%c%c", cpu->ps.u8[thread] & N ? 'N' : '-'
					, cpu->ps.u8[thread] & V ? 'V' : '-'
					, cpu->ps.u8[thread] & I ? 'I' : '-'
					, cpu->ps.u8[thread] & Z ? 'Z' : '-'
					, cpu->ps.u8[thread] & C ? 'C' : '-');
	wprintw(w, ", inst: ");
}


void print_regs(struct sux *cpu, WINDOW *w) {
	for (int i = 0; i < 9; i++) {
		wmove(w, i, 0);
		wclrtoeol(w);
	}
	wmove(w, 0, 0);
	wprintw(w, "Registers:\n");
	wprintw(w, "  a: $%016"PRIX64",   b: $%016"PRIX64"\n", cpu->a, cpu->b);
	wprintw(w, "  x: $%016"PRIX64",   y: $%016"PRIX64"\n", cpu->x, cpu->y);
	wprintw(w, "  e: $%016"PRIX64",   c: $%016"PRIX64"\n", cpu->e, cpu->c);
	wprintw(w, "  d: $%016"PRIX64",   s: $%016"PRIX64"\n", cpu->d, cpu->s);
	wprintw(w, "  f: $%016"PRIX64",  sp: $%016"PRIX64"\n", cpu->f, cpu->sp);
	wprintw(w, " bp: $%016"PRIX64", r11: $%016"PRIX64"\n", cpu->bp, cpu->r11);
	wprintw(w, "r12: $%016"PRIX64", r13: $%016"PRIX64"\n", cpu->r12, cpu->r13);
	wprintw(w, "r14: $%016"PRIX64", r15: $%016"PRIX64"\n", cpu->r14, cpu->r15);
}

static void sub_dbg(struct sux *cpu, WINDOW *w, uint64_t address, uint64_t *ortho_addr, uint8_t thread) {
	uint8_t ln = 5;
	uint16_t line_idx = 0;
	uint32_t tmpad = 0x20247;
	int row, col;
	uint8_t iscursor = 0;
	union reg ptr;
	ptr.u64 = 0;
	uint32_t adr;
	if (address == CTRL_ADDR || ortho_addr[1] == CTRL_ADDR || addr[STEP_ADDR]) {
		adr = read_value(cpu, 0, tmpad, 7, 0, 0);
		tmpad += 8;
		wmove(w, 1, 0);
		wprintw(w, "scr_row: %02u, scr_col: %02u, scr_str: %02u, scr_end: %02u", addr[0], addr[1], addr[2], addr[3]);
		wmove(w, 2, 0);
		wprintw(w, "bitabl: ");
		for (uint8_t i = 0; i < 16; i++) {
			wprintw(w, "%s", showbits(addr[adr+i], 7, 0));
		}
		mvwprintw(w, ln++, 0, "buffer: ");
		wmove(w, ln++, 0);
		uint8_t maxrow = 10;
		int line_offset = (addr[0]-(maxrow-1) >= 0) ? addr[0]-(maxrow-1) : 0;
		adr = read_value(cpu, 0, tmpad, 7, 0, 0);
		for (uint8_t i = 0; i < maxrow; i++) {
			line_idx = (i+addr[2]+line_offset << 6) + (i+addr[2]+line_offset << 4);
			for (uint8_t j = 0; j < 0x50; j++) {
				wprintw(w, "%02X", addr[adr+j+line_idx]);
					if ((addr[0] == i+line_offset) && addr[1] == j) {
						iscursor=1;
						getyx(w,row, col);
						wmove(w, ln++, 0);
						wclrtoeol(w);
						wmove(w, row+1, col-2);
						wprintw(w, "/\\");
						wmove(w, row, col);
					}
			}
			wprintw(w, ", i: %02X", i);
			if (!iscursor) {
				wmove(w, ln, 0);
				wclrtoeol(w);
			}
			iscursor = 0;
			wmove(w, ln++, 0);
		}
	}
	/*wclrtoeol(w);
	wprintw(w, "rega: $%02X, ", addr[0x0A]);
	wprintw(w, "regb: $%02X, ", addr[0x0B]);
	wprintw(w, "regc: $%02X, ", addr[0x0C]);
	wprintw(w, "regd: $%02X, ", addr[0x0D]);
	wprintw(w, "rege: $%02X, ", addr[0x0E]);
	wprintw(w, "regf: $%02X, ", addr[0x0F]);
	wprintw(w, "regg: $%02X", addr[0x10]);*/

	wmove(w, 3, 0);
	wclrtoeol(w);

	adr = 0x25;
	ptr.u64 = read_value(cpu, 0, adr, 7, 0, 0);
	wprintw(w, "ptr1: $%04"PRIX64, ptr.u64);

	adr = 0x2D;
	ptr.u64 = read_value(cpu, 0, adr, 7, 0, 0);
	wprintw(w, ", ptr2: $%04"PRIX64, ptr.u64);

	adr = 0x35;
	ptr.u64 = read_value(cpu, 0, adr, 7, 0, 0);
	wprintw(w, ", ptr3: $%04"PRIX64, ptr.u64);

	adr = 0x02049A;
	ptr.u64 = read_value(cpu, 0, adr, 7, 0, 0);
	wprintw(w, ", idx0: $%04"PRIX64, ptr.u64);

	adr = 0x334BA;
	ptr.u64 = read_value(cpu, 0, adr, 7, 0, 0);
	wprintw(w, ", valbuf: $%016"PRIX64, ptr.u64);


	wmove(w, 4, 0);
	wclrtoeol(w);
	adr = 0x200CA;
	ptr.u64 = read_value(cpu, 0, adr, 3, 0, 0);
	wprintw(w, "t_id: $%02X", ptr.u8[0]);
	wprintw(w, ", t_type: $%02X", ptr.u8[1]);
	wprintw(w, ", t_space: $%02X", ptr.u8[2]);
	wprintw(w, ", t_tab: $%02X", ptr.u8[3]);
	adr += 4;
	ptr.u64 = read_value(cpu, 0, adr, 7, 0, 0);
	wprintw(w, ", t_val: $%"PRIX64, ptr.u64);
	adr += 8;
	ptr.u64 = read_value(cpu, 0, adr, 7, 0, 0);
	wprintw(w, ", t_str: $%"PRIX64, ptr.u64);
	adr += 8;
	ptr.u64 = read_value(cpu, 0, adr, 7, 0, 0);
	wprintw(w, ", t_sym: $%"PRIX64, ptr.u64);


	/*
	wmove(w, 47, 0);
	wclrtoeol(w);
	wprintw(w, "a: $%02X,",  addr[0x0A]);
	wprintw(w, " b: $%02X,", addr[0x0B]);
	wprintw(w, " c: $%02X,", addr[0x0C]);
	wprintw(w, " d: $%02X,", addr[0x0D]);
	wprintw(w, " e: $%02X,", addr[0x0E]);
	wprintw(w, " f: $%02X",  addr[0x0F]);
	tmpad += 8;
	adr = read_value(cpu, 0, tmpad, 7, 0, 0);
	line_idx = 0;
	wprintw(w, "cmd_buf:");
	for (uint8_t i = 0; i < 1; i++) {
		wmove(w, ln++, 0);
		wclrtoeol(w);
		line_idx = (i << 4)+(i << 6);
		for (uint8_t j = 0; j < 0x50; j++) {
			wprintw(w, "%02X", addr[adr+j+line_idx]);
		}
		wprintw(w, ", i: %02X", i);
	}*/
}

static uint64_t get_offset(uint64_t value, uint8_t size, char **sign) {
	size = (size > 8) ? 8 : size;
	uint8_t msb = size*8;
	uint64_t mask = (-(uint64_t)1 >> ((8 - size) * 8));
	mask &= (1 << (msb-1));
	*sign = ((value >> (msb-1)) & 1) ? "-" : "+";
	if (*sign[0] == '-') {
		value &= mask;
		value = -(value+1);
	}
	return value;
}

/* Checks if the opcode, and operands required an ortho suffix. */
static int is_os(uint8_t opcode, operand *op) {
	uint8_t is_mem = (op[0].type == 1 && op[0].id != MEM_IMM);
	uint8_t is_idx = (is_mem && !op[1].type && (op[1].id == REG_X || op[1].id == REG_Y));
	int is_valid = 1;
	int is_sp = 0;
	if (is_mem || is_idx) {
		switch (op[0].id) {
			case MEM_AINDR:
			case MEM_ZINDR:
			case MEM_ARIND:
			case MEM_ZRIND:
			case MEM_SIB  : is_valid = 0; break;
			case MEM_ZMR  :
			case MEM_ABSR :
			case MEM_RIND :
			default       :
				if (is_mem && !op[1].type && op[1].id != REG_X && op[1].id != REG_Y) {
					is_valid = 0;
				} else if (op[0].id == MEM_ZMR || op[0].id == MEM_ABSR || op[0].id == MEM_RIND) {
					is_valid = (op[0].rind[0] == REG_SP);
					is_sp = (op[0].rind[0] == REG_SP);
				} else if (is_mem && op[1].type == 1) {
					is_valid = 0;
				}
				break;
		}
	}
	switch (opcode) {
		case ORTHO_2OP(CMP): return (is_idx && is_valid && ((is_sp && op[0].id == MEM_RIND) || (!is_sp && op[0].id == MEM_IND)));
		case ORTHO_2OP(LEA): return (is_idx && is_valid);
	}
	return 0;
}

static int is_1cc(uint8_t opcode) {
	switch (opcode) {
		case ORTHO_1CC(SET, NG):
		case ORTHO_1CC(SET, PO):
		case ORTHO_1CC(SET, CS):
		case ORTHO_1CC(SET, CC):
		case ORTHO_1CC(SET, EQ):
		case ORTHO_1CC(SET, NE):
		case ORTHO_1CC(SET, VS):
		case ORTHO_1CC(SET, VC): return 1;
	}
	return 0;
}

static int is_1op(uint8_t opcode) {
	switch (opcode) {
		case ORTHO_1OP(PSH):
		case ORTHO_1OP(PEA):
		case ORTHO_1OP(PUL):
		case ORTHO_1OP(SWP):
		case ORTHO_1OP(NOT):
		case ORTHO_1OP(NEG):
		case ORTHO_1OP(DEC):
		case ORTHO_1OP(INC):
		case ORTHO_1OP(CLZ):
		case ORTHO_1OP(CLO): return 1;
	}
	return 0;
}

static int is_2op(uint8_t opcode) {
	switch (opcode) {
		case ORTHO_2OP(MNG):
		case ORTHO_2OP(ADC):
		case ORTHO_2OP(ROR):
		case ORTHO_2OP(ADD):
		case ORTHO_2OP(MPO):
		case ORTHO_2OP(SBC):
		case ORTHO_2OP(MUL):
		case ORTHO_2OP(SUB):
		case ORTHO_2OP(MCS):
		case ORTHO_2OP(AND):
		case ORTHO_2OP(DIV):
		case ORTHO_2OP(PCN):
		case ORTHO_2OP(MCC):
		case ORTHO_2OP(OR ):
		case ORTHO_2OP(ASR):
		case ORTHO_2OP(LEA):
		case ORTHO_2OP(MEQ):
		case ORTHO_2OP(XOR):
		case ORTHO_2OP(CMP):
		case ORTHO_2OP(MNE):
		case ORTHO_2OP(LSL):
		case ORTHO_2OP(MOV):
		case ORTHO_2OP(MVS):
		case ORTHO_2OP(LSR):
		case ORTHO_2OP(IML):
		case ORTHO_2OP(MVC):
		case ORTHO_2OP(ROL):
		case ORTHO_2OP(IDV): return 1;
	}
	return 0;
}

static void disasm_ortho(struct sux *cpu, WINDOW *w, uint8_t opcode, uint8_t prefix, uint8_t prefix2, uint64_t *value, char *inst_name, char *postfix, operand *op, uint8_t rs, uint8_t thread) {
	char opr[2][256];
	char address[2][17];
	char *rind[2] = {"", ""};
	char *sign[2] = {"", ""};
	char *ind[2] = {"", ""};
	char idx[2][33];
	char scale[2][5];
	char *reg[2] = {"", ""};
	memset(opr, 0, sizeof(opr));
	memset(address, 0, sizeof(address));
	memset(idx, 0, sizeof(idx));
	memset(scale, 0, sizeof(scale));

	for (int i = 0; i < 2; i++) {
		int is_ind = 0;
		int is_rind = 0;
		uint64_t val = 0;
		if (op[i].type) {
			uint8_t addr_size = get_ortho_addrsize(prefix, op[i].id);
			if (addr_size != 0xFF) {
				uint64_t value = get_offset(op[i].value, addr_size+1, &sign[i]);
				sprintf(address[i], "$%0*"PRIX64, (addr_size+1)*2, value);
			}
			if (op[i].id == MEM_SIB) {
				sprintf(scale[i], "%u*", op[i].scale+1);
			} else if (op[i].id == MEM_IMM) {
				val = read_value(cpu, 0, value[i], rs-1, 0, 0);
			}
			switch (op[i].id) {
				case MEM_ABSR :
				case MEM_ZMR  :
				case MEM_AINDR:
				case MEM_AIND :
				case MEM_ZINDR:
				case MEM_ARIND:
				case MEM_ZRIND:
				case MEM_SIB  :
				case MEM_RIND : is_rind = 1; break;
			}
			if (is_rind) {
				for (int j = 0; j < 2 && op[i].rind[j] != 0xFF; j++) {
					switch (op[i].rind[j]) {
						case REG_A  : rind[j] =   "A";	break;
						case REG_B  : rind[j] =   "B";	break;
						case REG_X  : rind[j] =   "X";	break;
						case REG_Y  : rind[j] =   "Y";	break;
						case REG_E  : rind[j] =   "E";	break;
						case REG_C  : rind[j] =   "C";	break;
						case REG_D  : rind[j] =   "D";	break;
						case REG_S  : rind[j] =   "S";	break;
						case REG_F  : rind[j] =   "F";	break;
						case REG_SP : rind[j] =  "SP";	break;
						case REG_BP : rind[j] =  "BP";	break;
						case REG_R11: rind[j] = "R11";	break;
						case REG_R12: rind[j] = "R12";	break;
						case REG_R13: rind[j] = "R13";	break;
						case REG_R14: rind[j] = "R14";	break;
						case REG_R15: rind[j] = "R15";	break;
					}
				}
			}
			sprintf(idx[i], "%s%s%s%s", scale[i], rind[0], (op[i].rind[1] != 0xFF) ? "+" : "", rind[1]);
			switch (op[i].id) {
				case MEM_AINDR:
				case MEM_AIND :
				case MEM_ZINDR:
				case MEM_IND  : is_ind = 1; break;
				case MEM_ARIND:
				case MEM_ZRIND:
				case MEM_SIB  :
				case MEM_RIND : is_ind = 2; break;
				case MEM_IMM  : is_ind = 3; break;
			}
			if (!is_rind) {
				sign[i] = "";
			}
		} else {
			is_ind = 4;
			switch (op[i].id) {
				case REG_A  : reg[i] =   "A";	break;
				case REG_B  : reg[i] =   "B";	break;
				case REG_X  : reg[i] =   "X";	break;
				case REG_Y  : reg[i] =   "Y";	break;
				case REG_E  : reg[i] =   "E";	break;
				case REG_C  : reg[i] =   "C";	break;
				case REG_D  : reg[i] =   "D";	break;
				case REG_S  : reg[i] =   "S";	break;
				case REG_F  : reg[i] =   "F";	break;
				case REG_SP : reg[i] =  "SP";	break;
				case REG_BP : reg[i] =  "BP";	break;
				case REG_R11: reg[i] = "R11";	break;
				case REG_R12: reg[i] = "R12";	break;
				case REG_R13: reg[i] = "R13";	break;
				case REG_R14: reg[i] = "R14";	break;
				case REG_R15: reg[i] = "R15";	break;
			}
		}
		switch (is_ind) {
			case 0: sprintf(opr[i], "%s%s%s", idx[i], sign[i], address[i]); break;
			case 1: sprintf(opr[i], "%s%s(%s)", idx[i], sign[i], address[i]); break;
			case 2: sprintf(opr[i], "(%s%s%s)", idx[i], sign[i], address[i]); break;
			case 3: sprintf(opr[i], "#$%0*"PRIX64, rs*2, val); break;
			case 4: sprintf(opr[i], "%s", reg[i]); break;
		}
	}
	const char *cc = "";
	char *op2 = "";
	int op_count;
	char *os = ""; /* Ortho Suffix. */
	if (is_os(opcode, op)) {
		os = (postfix && postfix[0] == '.') ? "O" : ".O";
	}
	if (is_1cc(opcode) || is_2op(opcode)) {
		op_count = 2;
	} else if (is_1op(opcode)) {
		op_count = 1;
	}
	if (is_1cc(opcode)) {
		cc = set_cc[opcode >> 5];
		/*switch (opcode) {
			case ORTHO_1CC(SET, NG): cc = "NG"; break;
			case ORTHO_1CC(SET, PO): cc = "PO"; break;
			case ORTHO_1CC(SET, CS): cc = "CS"; break;
			case ORTHO_1CC(SET, CC): cc = "CC"; break;
			case ORTHO_1CC(SET, EQ): cc = "EQ"; break;
			case ORTHO_1CC(SET, NE): cc = "NE"; break;
			case ORTHO_1CC(SET, VS): cc = "VS"; break;
			case ORTHO_1CC(SET, VC): cc = "VC"; break;
		}*/
		op2 = (char *)cc;
	} else if (is_2op(opcode)) {
		op2 = opr[1];
	}
	wprintw(w, "%s%s%s %s%s %s", inst_name, postfix, os, opr[0], (op_count == 2) ? "," : "", op2);
	wmove(w, getmaxy(w)-2, 0);
	wclrtoeol(w);
	for (int i = 0; i < 2; i++) {
		if (op[i].type) {
			sprintf(address[i], "$%04"PRIX64, value[i]);
		} else {
			sprintf(address[i], "none");
		}
	}
	wprintw(w, "destination address: %s, source address: %s", address[0], address[1]);
}


void disasm(struct sux *cpu, WINDOW *w, uint8_t lines, uint8_t opcode, uint8_t prefix, uint8_t ext_prefix, uint8_t prefix2, uint8_t *op_type, uint8_t *op_id, uint8_t thread) {
	uint64_t value;
	uint64_t address = 0;
	operand ortho_op[2];
	uint64_t ortho_addr[2] = {0, 0};
	if (ext_prefix != 0x1D) {
		address = get_addr(cpu, opcode, prefix, ext_prefix, 0, 0, thread);
	} else {
		get_ortho_addr(cpu, prefix, cpu->pc, ortho_op, ortho_addr, op_type, op_id, 0, 0, thread);
	}
	uint8_t rs = (prefix >> 4) & 3;
	char *postfix;
	char *of;
	char op[4];
	char *sign = "";
	char *ind  = "";
	uint8_t tmp = 0;
	union reg mask;
	mask.u64 = 0;
	const char *inst_name;
	uint8_t inst_type;
	op[3] = 0;
	switch (rs) {
		case 0: postfix = ""; break;
		case 1: postfix = ".W"; break;
		case 2: postfix = ".D"; break;
		case 3: postfix = ".Q"; break;
	}
	if (prefix >> 6) {
		tmp = 0;
	}
	switch (prefix >> 6) {
		default: of = ""; break;
		case 1 : of = "SP"; break;
		case 2 : of = "PC"; break;
	}
	if (ext_prefix != 0x1D) {
		if ((ext_prefix & 0xF) == 0xD) {
			switch (ext_prefix >> 4) {
				case 0x0: inst_name = ext_opname[opcode]; inst_type = ext_optype[opcode]; break;
			}
		} else {
			inst_name = opname[opcode];
			inst_type = optype[opcode];
		}
		memcpy(op, inst_name, 3);

		char *idx;
		uint8_t addrsize = 0;
		switch (inst_type) {
			case AIND : case IND : idx =    ")"; break;
			case AINDX: case INDX: idx = ", x)"; break;
			case AINDY: case INDY: idx = "), y"; break;
			case ABSX : case ZMX : idx =  ", x"; break;
			case ABSY : case ZMY : idx =  ", y"; break;
			default: idx = ""; break;
		}
		switch (inst_type) {
			case ZM   :
			case ZMX  :
			case ZMY  :
			case IND  :
			case INDX :
			case INDY : addrsize = get_addrsize(prefix,  ZM); break;
			case ABS  :
			case AIND :
			case AINDX:
			case AINDY:
			case ABSX :
			case ABSY : addrsize = get_addrsize(prefix, ABS); break;
			case IMM  :
			case REL  : addrsize = (1 << rs)-1; break;
		}
		mask.u64 = (-(uint64_t)1 >> ((7 - addrsize) * 8));
		value = read_value(cpu, 0, cpu->pc, addrsize, 0, 0);
		if ((prefix >> 6) == 1 || (prefix >> 6) == 2 || inst_type == REL) {
			switch (addrsize) {
				case 0 : sign = ((int8_t )value < 0) ? "-" : "+"; break;
				case 1 : sign = ((int16_t)value < 0) ? "-" : "+"; break;
				case 2 :
				case 3 : sign = ((int32_t)value < 0) ? "-" : "+"; break;
				case 4 :
				case 5 :
				case 6 :
				case 7 : sign = ((int64_t)value < 0) ? "-" : "+"; break;
			}
			value = (sign[0] == '-') ? (~value + 1) & mask.u64 : value;
		}
		switch (inst_type) {
			case BREG :
			case IMPL : wprintw(w, "%s%s" , inst_name, postfix); break;
			case EIND : wprintw(w, "%s%s (E)" , op, postfix); break;
			case IMM  : wprintw(w, "%s%s #$%0*"PRIX64 , op, postfix, (addrsize+1) << 1, value); break;
			case AIND :
			case AINDX:
			case AINDY:
			case IND  :
			case INDX :
			case INDY : ind = "("; /* Falls through. */
			case ZMX  :
			case ZMY  :
			case ABSX :
			case ABSY :
			case ZM   :
			case ABS  : wprintw(w, "%s%s %s%s%s$%0*" PRIX64"%s" , op, postfix, ind, of, sign, (addrsize+1) << 1, value, idx); break;
			case REL  : wprintw(w, "%s%s %s$%0*"PRIX64 , op, postfix, sign, (addrsize+1) << 1, value); break;
		}
	} else {
		inst_name = ortho_opname[opcode];
		memcpy(op, inst_name, 3);
		disasm_ortho(cpu, w, opcode, prefix, prefix2, ortho_addr, op, postfix, ortho_op, (1 << rs), thread);
	}
	int y = getmaxy(w);
	if (ext_prefix != 0x1D) {
		wmove(w, y-2, 0);
		wclrtoeol(w);
		wprintw(w, "address: $%04"PRIX64, address);
	}
	if (address == TX_ADDR || ortho_addr[0] == TX_ADDR || address == RX_ADDR || ortho_addr[1] == RX_ADDR) {
		wmove(w, y-1, 0);
		wprintw(w, "TX_ADDR: $%02X, RX_ADDR: $%02X", addr[TX_ADDR], addr[RX_ADDR]);
	}
	if (subdbg) {
		sub_dbg(cpu, dbg_win, address, ortho_addr, thread);
	}
}

#undef ORTHO_1CC
#undef ORTHO_1OP
#undef ORTHO_2OP