summaryrefslogtreecommitdiffstatshomepage
path: root/src/emu/cpu/mb86233/mb86233d.c
blob: 0068ff7f3d26fda369f685c73209df39883ae059 (plain) (blame)
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
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
// license:???
// copyright-holders:???
#include "emu.h"
#include "debugger.h"
#include "mb86233.h"

static char * COND(unsigned int cond)
{
	static char bufs[4][256];
	static int bufindex = 0;
	char *buf = &bufs[bufindex++][0];

	bufindex &= 3;

	switch(cond)
	{
		case 0x16:
			sprintf(buf,"always");
			return buf;

		case 0x00:
			sprintf(buf,"eq");
			return buf;

		case 0x01:
			sprintf(buf,"ge");
			return buf;

		case 0x02:
			sprintf(buf,"le");
			return buf;

		case 0x06:
			sprintf(buf,"never");
			return buf;

		case 0x10:
			sprintf(buf,"(--r12)!=0");
			return buf;

		case 0x11:
			sprintf(buf,"(--r13)!=0");
			return buf;
	}

	sprintf(buf,"unk (%x)",cond);
	return buf;
}

static char * REGS( UINT32 reg, int IsSource )
{
	static char bufs[4][256];
	static int bufindex = 0;
	char *buf = &bufs[bufindex++][0];
	int         mode = (reg >> 6 ) & 0x07;

	bufindex &= 3;

	reg &= 0x3f;

	if ( mode == 0 || mode == 1 || mode == 3 )
	{
		if ( reg < 0x10 )
		{
			sprintf(buf,"r%d",reg);
			return buf;
		}

		switch(reg)
		{
			case 0x10:
				sprintf(buf,"a");
			break;

			case 0x11:
				sprintf(buf,"a.e");
			break;

			case 0x12:
				sprintf(buf,"a.m");
			break;

			case 0x13:
				sprintf(buf,"b");
			break;

			case 0x14:
				sprintf(buf,"b.e");
			break;

			case 0x15:
				sprintf(buf,"b.m");
			break;

			case 0x19:
				sprintf(buf,"d");
			break;

			case 0x1a:
				sprintf(buf,"d.e");
			break;

			case 0x1b:
				sprintf(buf,"d.m");
			break;

			case 0x1c:
				sprintf(buf,"p");
			break;

			case 0x1d:
				sprintf(buf,"p.e");
			break;

			case 0x1e:
				sprintf(buf,"p.m");
			break;

			case 0x1f:
				sprintf(buf,"shift");
			break;

			case 0x20:
				sprintf(buf,"parport");
			break;

			case 0x21:
				sprintf(buf,"FIn");
			break;

			case 0x22:
				sprintf(buf,"FOut");
			break;

			case 0x23:
				sprintf(buf,"EB");
			break;

			default:
				sprintf(buf,"Unkreg (%x)",reg);
			break;
		}
	}
	else if ( mode == 2 )
	{
		char *p = buf;

		p += sprintf(p,"0x%x+",reg & 0x1f);

		if ( IsSource )
		{
			if ( !( reg & 0x20 ) )
				p += sprintf(p,"r0+");

			p += sprintf(p,"r2");
		}
		else
		{
			if ( !( reg & 0x20 ) )
				p += sprintf(p,"r1+");

			p += sprintf(p,"r3");
		}
	}
	else if ( mode == 6 )
	{
		char *p = buf;

		if ( IsSource )
		{
			if ( !( reg & 0x20 ) )
				p += sprintf(p,"r0+");

			p += sprintf(p,"r2");
		}
		else
		{
			if ( !( reg & 0x20 ) )
				p += sprintf(p,"r1+");

			p += sprintf(p,"r3");
		}

		if ( reg & 0x10 )
			p += sprintf(p,"--%d", 0x20 - ( reg & 0x1f ) );
		else
			p += sprintf(p,"++%d", reg & 0x1f );
	}
	else
	{
		sprintf(buf,"UNKMOD %x (0x%x)", mode, reg);
	}

	return buf;
}

static char * INDIRECT( UINT32 reg, int IsSource )
{
	static char bufs[4][256];
	static int bufindex = 0;
	char *buf = &bufs[bufindex++][0];
	int         mode = ( reg >> 6 ) & 0x07;

	bufindex &= 3;

	if ( mode == 0 || mode == 3 || mode == 1)
	{
		sprintf(buf,"0x%x",reg);
	}
	else if ( mode == 2 )
	{
		char *p = buf;

		p += sprintf(p,"0x%x+",reg&0x1f);

		if ( IsSource )
		{
			if ( !(reg & 0x20) )
				p += sprintf(p,"r0+");

			p += sprintf(p,"r2");
		}
		else
		{
			if ( !(reg & 0x20) )
				p += sprintf(p,"r1+");

			p += sprintf(p,"r3");
		}
	}
	else if ( mode == 6 || mode == 7 )
	{
		char *p = buf;

		if ( IsSource )
		{
			if ( !( reg & 0x20 ) )
				p += sprintf(p,"r0+");

			p += sprintf(p,"r2");
		}
		else
		{
			if( !( reg & 0x20 ) )
				p += sprintf(p,"r1+");

			p += sprintf(p,"r3");
		}

		if ( reg & 0x10 )
			p += sprintf(p,"--%d",0x20 - ( reg & 0x1f ));
		else
			p += sprintf(p,"++%d",reg & 0x1f);
	}
	else
	{
		sprintf(buf,"UNKMOD %x (0x%x)", mode, reg);
	}

	return buf;
}


static char * ALU( UINT32 alu)
{
	static char bufs[4][256];
	static int bufindex = 0;
	char *buf = &bufs[bufindex++][0];

	bufindex &= 3;

	switch( alu )
	{
		case 0x0:
			buf[0] = 0;
		break;

		case 0x1:
			sprintf(buf,"d=d&a");
		break;

		case 0x2:
			sprintf(buf,"d=d|a");
		break;

		case 0x3:
			sprintf(buf,"d=d^a");
		break;

		case 0x5:
			sprintf(buf,"cmp d,a");
		break;

		case 0x6:
			sprintf(buf,"d=d+a");
		break;

		case 0x7:
			sprintf(buf,"d=d-a");
		break;

		case 0x8:
			sprintf(buf,"p=a*b");
		break;

		case 0x9:
			sprintf(buf,"d=d+p, p=a*b");
		break;

		case 0xa:
			sprintf(buf,"d=d-p, p=a*b");
		break;

		case 0xb:
			sprintf(buf,"d=fabs d");
		break;

		case 0xc:
			sprintf(buf,"d=d+p");
		break;

		case 0xd:
			sprintf(buf,"d=p, p=a*b");
		break;

		case 0xe:
			sprintf(buf,"d=float(d)");
		break;

		case 0xf:
			sprintf(buf,"d=int(d)");
		break;

		case 0x10:
			sprintf(buf,"d=d/a");
		break;

		case 0x11:
			sprintf(buf,"d=-d");
		break;

		case 0x13:
			sprintf(buf,"d=a+b");
		break;

		case 0x14:
			sprintf(buf,"d=b-a");
		break;

		case 0x16:
			sprintf(buf,"d=(lsr d,shift)");
		break;

		case 0x17:
			sprintf(buf,"d=(lsl d,shift)");
		break;

		case 0x18:
			sprintf(buf,"d=(asr d,shift)");
		break;

		case 0x1a:
			sprintf(buf,"d=d+a (int)");
		break;

		case 0x1b:
			sprintf(buf,"d=d-a (int)");
		break;

		default:
			sprintf(buf,"ALU UNK(%x)",alu);
		break;
	}

	return buf;
}

static unsigned dasm_mb86233(char *buffer, UINT32 opcode )
{
	char *p = buffer;
	UINT32  grp = ( opcode >> 26 ) & 0x3f;

	switch( grp )
	{
		case 0x0:   /* Dual move */
		{
			UINT32 r1=opcode & 0x1ff;
			UINT32 r2=(opcode>>9) & 0x7f;
			UINT32 alu=(opcode>>21) & 0x1f;
			UINT32 op=(opcode>>16) & 0x1f;

			if ( alu != 0 )
				p += sprintf(p, "%s, ", ALU(alu) );

			switch( op )
			{
				case 0x0c:  /* a = RAM[addr], b = BRAM[addr] */
					p += sprintf(p,"LAB RAM(0x%x)->a,BRAM(0x%x)->b",r1,r2);
				break;

				case 0x0d:  /* a = RAM[addr], b = BRAM[addr] */
					p += sprintf(p,"LAB RAM(0x%x)->a,BRAM(%s)->b",r1,INDIRECT(r2|(2<<6),0));
				break;

				case 0x0f:  /* a = RAM[addr], b = BRAM[reg] */
					p += sprintf(p,"LAB RAM(0x%x)->a,BRAM(%s)->b",r1,INDIRECT(r2|(6<<6),0));
				break;

				case 0x10:  /* a = BRAM[reg], b = RAM[addr] */
					p += sprintf(p,"LAB BRAM(%s)->a,RAM(0x%x)->b",INDIRECT(r1,1),r2);
				break;

				default:
					p += sprintf(p,"UNKDUAL (%x)",op);
				break;
			}
		}
		break;

		case 0x7:   /* LD/MOV */
		{
			UINT32 r1=opcode & 0x1ff;
			UINT32 r2=(opcode>>9) & 0x7f;
			UINT32 alu=(opcode>>21) & 0x1f;
			UINT32 op=(opcode>>16) & 0x1f;

			if ( alu != 0 )
			{
				p += sprintf(p, "%s", ALU(alu) );

				if ( !(op == 0x1f && r1 == 0x10 && r2 == 0x0f) )
					p += sprintf(p, ", ");
			}

			switch(op)
			{
				case 0x03:  /* RAM->External Indirect */
				{
					p += sprintf(p,"MOV RAM(0x%x)->E(EB+%s)",r1,INDIRECT(r2|(6<<6),0));
				}
				break;

				case 0x04:  /* MOV RAM->External */
				{
					p += sprintf(p,"MOV RAM(0x%x)->E(EB+0x%x)",r1,r2);
				}
				break;

				case 0x07:  /* RAMInd->External */
				{
					p += sprintf(p,"MOV RAM(%s)->E(EB+%s)",INDIRECT(r1,1),INDIRECT(r2|(6<<6),0));
				}
				break;

				case 0x08:  /* External->RAM */
				{
					p += sprintf(p,"MOV EXT(EB+");
					p += sprintf(p,"%s",INDIRECT(r1,1));
					p += sprintf(p,")->RAM(0x%x)",r2);
				}
				break;

				case 0x0b:  /* External->RAMInd */
				{
					int mode = ( r1 >> 6 ) & 0x07;

					p += sprintf(p,"MOV EXT(EB+");

					if ( mode == 0 || mode == 3 || mode == 1 )
						p += sprintf(p,"RAM(");

					p += sprintf(p,"%s",INDIRECT(r1,1));

					if ( mode == 0 || mode == 3 || mode == 1)
						p += sprintf(p,")");

					p += sprintf(p,")->RAM(%s)",INDIRECT(r2|(6<<6),0));
				}
				break;

				case 0x0c:  /* MOV RAM->BRAM */
					p += sprintf(p,"MOV RAM(0x%x)->BRAM(0x%x)",r1,r2);
				break;

				case 0x0f:  /* MOV RAMInd->BRAMInd */
					p += sprintf(p,"MOV RAM(%s)->BRAM(%s)",INDIRECT(r1,1),INDIRECT(r2|(6<<6),0));
				break;

				case 0x10:  /* MOV BRAMInd->RAM */
					p += sprintf(p,"MOV BRAM(%s)->RAM(0x%x)",INDIRECT(r1,1),r2);
				break;

				case 0x13:  /* MOV BRAMInd->RAMInd */
					p += sprintf(p,"MOV BRAM(%s)->RAM(%s)",INDIRECT(r1,1),INDIRECT(r2|(6<<6),0));
				break;

				case 0x1c:  /* MOV Reg->RAMInd */
					if ( ( r2 >> 6 ) & 0x01)
					{
						p += sprintf(p,"MOV %s->EXT(EB+%s)",REGS(r2,1),INDIRECT(r1,0));
					}
					else
					{
						p += sprintf(p,"MOV %s->RAM(%s)",REGS(r2,1),INDIRECT(r1,0));
					}
				break;

				case 0x1d:  /* MOV RAM->Reg */
				{
					if ( r1 & 0x180 )
					{
						p += sprintf(p,"MOV RAM(%s)->%s",REGS(r1,0),REGS(r2,0));
					}
					else
					{
						p += sprintf(p,"MOV RAM(0x%x)->%s",r1,REGS(r2,0));
					}
				}
				break;

				case 0x1e:  /* External->Reg */
				{
					int     mode2 = (r2 >> 6) & 1;
					p += sprintf(p,"MOV EXT(EB+%s)->%s",INDIRECT(r1,mode2),REGS(r2,0));
				}
				break;

				case 0x1f:  /* MOV Reg->Reg */
					if ( !(r1 == 0x10 && r2 == 0x0f) )
					{
						p += sprintf(p,"MOV %s->%s",REGS(r1,1),REGS(r2,0));
					}
				break;

				default:
					p += sprintf(p,"UNKMV (0x%x)",op);
				break;
			}
		}
		break;

		case 0x0e:  /* Load 24 bit val */
		{
			UINT32 sub=(opcode>>24)&0x3;
			static const char regs[4] = { 'p', 'a', 'b', 'd' };

			p += sprintf(p,"LDIMM24 0x%X->%c",opcode&0xffffff, regs[sub]);
		}
		break;

		case 0x0f:  /* repeat */
		{
			UINT32  alu = ( opcode >> 20 ) & 0x1f;
			UINT32  sub2 = ( opcode >> 16 ) & 0x0f;

			if ( alu != 0 )
				p += sprintf(p, "%s, ", ALU(alu) );

			if ( sub2 == 0x00 )
			{
				p += sprintf(p,"CLEAR ");

				switch( opcode & 0x3f )
				{
					case 0x04: p += sprintf(p, "a" ); break;
					case 0x08: p += sprintf(p, "b" ); break;
					case 0x10: p += sprintf(p, "d" ); break;
					default: p += sprintf(p, "UNKNOWN REG(%x)",opcode&0x3F); break;
				}
			}
			else if ( sub2 == 0x02 )
				p += sprintf(p,"CLRFLAG 0x%x",opcode&0xffff);
			else if ( sub2==0x4 )
			{
				if ( (opcode & 0xfff) == 0 )
					p += sprintf(p,"REP 0x100");
				else
					p += sprintf(p,"REP 0x%x",opcode&0xff);
			}
			else if ( sub2 == 0x06 )
				p += sprintf(p,"SETFLAG 0x%x",opcode&0xffff);
		}
		break;

		case 0x10:
		{
			UINT32  dst=(opcode>>24)&0xf;
			UINT32  imm=(opcode)&0xFFFF;

			if ( dst <= 3 )
				p += sprintf(p,"LDIMM 0x%x->r%d",imm,dst);
			else
				p += sprintf(p,"LDIMM 0x%x->UNKDST(0x%x)",imm,dst);
		}
		break;

		case 0x13:
		{
			UINT32 sub = ( opcode >> 24 ) & 0x03;

			p += sprintf(p,"LDIMM 0x%X->",opcode&0xffffff);

			if ( sub == 0 ) p += sprintf(p,"r12");
			else if ( sub == 1 ) p += sprintf(p,"r13");
			else p += sprintf(p,"UNKREG(%x)", sub);
		}
		break;

		case 0x14:
		{
			UINT32 sub = ( opcode >> 24 ) & 0x03;

			p += sprintf(p,"LDIMM 0x%X->",opcode&0xffffff);

			if ( sub == 0 ) p += sprintf(p,"a.exp");
			else if ( sub == 1 ) p += sprintf(p,"a.e");
			else if ( sub == 2 ) p += sprintf(p,"a.m");
			else p += sprintf(p,"UNKREG(%x)", sub);
		}
		break;

		case 0x15:
		{
			UINT32 sub = ( opcode >> 24 ) & 0x03;

			p += sprintf(p,"LDIMM 0x%X->",opcode&0xffffff);

			if ( sub == 0 ) p += sprintf(p,"b.exp");
			else if ( sub == 1 ) p += sprintf(p,"b.e");
			else if ( sub == 2 ) p += sprintf(p,"b.m");
			else p += sprintf(p,"UNKREG(%x)", sub);
		}
		break;

		case 0x16:
		{
			UINT32 sub = ( opcode >> 24 ) & 0x03;

			p += sprintf(p,"LDIMM 0x%X->",opcode&0xffffff);

			if ( sub == 2 ) p += sprintf(p,"d.e");
			else if ( sub == 3 ) p += sprintf(p,"d.m");
			else p += sprintf(p,"UNKREG(%x)", sub);
		}
		break;

		case 0x17:
		{
			UINT32 sub = ( opcode >> 24 ) & 0x03;

			p += sprintf(p,"LDIMM 0x%X->",opcode&0xffffff);

			if ( sub == 0x03 ) p += sprintf(p,"shift");
			else p += sprintf(p,"UNKREG(%x)", sub);
		}
		break;

		case 0x18:
		{
			UINT32 sub = ( opcode >> 24 ) & 0x03;

			p += sprintf(p,"LDIMM24 0x%X->",opcode&0xffffff);

			if ( sub == 0x03 ) p += sprintf(p,"EB");
			else p += sprintf(p,"UNKREG(%x)", sub);
		}
		break;

		case 0x2f:
		{
			UINT32 cond = ( opcode >> 20 ) & 0x1f;
			UINT32 subtype = ( opcode >> 16 ) & 0x0f;
			UINT32 data = opcode & 0xffff;

			switch( subtype )
			{
				case 0:
					p += sprintf(p,"BRIF %s 0x%X", COND(cond), data);
				break;

				case 2:
					p += sprintf(p,"BRIF %s ", COND(cond));
					if ( data & 0x4000 )
						p += sprintf(p,"%s",REGS(data&0x3f,0));
					else
						p += sprintf(p,"RAM(0x%x)",data);
				break;

				case 4:
					p += sprintf(p,"BSIF %s 0x%X", COND(cond), data);
				break;

				case 0x6:
					p += sprintf(p,"BSIF %s ", COND(cond));
					if ( data & 0x4000 )
						p += sprintf(p,"%s",REGS(data&0x3f,0));
					else
						p += sprintf(p,"RAM(0x%x)",data);
				break;

				case 0xa:
					p += sprintf(p,"RTIF %s", COND(cond));
				break;

				case 0xc:
					p += sprintf(p,"LDIF %s RAM(0x%x)->%s", COND(cond),data&0x1ff,REGS((data>>9)&0x3f,0));
				break;

				case 0xe:
					p += sprintf(p,"RIIF %s", COND(cond));
				break;

				default:
					p += sprintf(p,"UNKG5 (%x cond %x)",subtype,cond);
				break;
			}
		}
		break;

		case 0x3f:
		{
			UINT32 cond = ( opcode >> 20 ) & 0x1f;
			UINT32 subtype = ( opcode >> 16 ) & 0x0f;
			UINT32 data = opcode & 0xffff;

			switch( subtype )
			{
				case 0:
					p += sprintf(p,"BRUL %s 0x%X", COND(cond), data);
				break;

				case 2:
					p += sprintf(p,"BRUL %s ", COND(cond));
					if ( data & 0x4000 )
						p += sprintf(p,"%s",REGS(data&0x3f,0));
					else
						p += sprintf(p,"RAM(0x%x)",data);
				break;

				case 4:
					p += sprintf(p,"BSUL %s 0x%X", COND(cond), data);
				break;

				case 0x6:
					p += sprintf(p,"BSUL %s ", COND(cond));
					if ( data & 0x4000 )
						p += sprintf(p,"%s",REGS(data&0x3f,0));
					else
						p += sprintf(p,"RAM(0x%x)",data);
				break;

				case 0xa:
					p += sprintf(p,"RTUL %s", COND(cond));
				break;

				case 0xc:
					p += sprintf(p,"LDUL %s RAM(0x%x)->%s", COND(cond),data&0x1ff,REGS((data>>9)&0x3f,0));
				break;

				case 0xe:
					p += sprintf(p,"RIUL %s", COND(cond));
				break;

				default:
					p += sprintf(p,"UNKG5 (%x cond %x)",subtype,cond);
				break;
			}
		}
		break;

		default:
			p += sprintf(p,"UNKOP");
		break;
	}

	return (1 | DASMFLAG_SUPPORTED);
}

CPU_DISASSEMBLE( mb86233 )
{
	UINT32 op = *(UINT32 *)oprom;
	op = LITTLE_ENDIANIZE_INT32(op);
	return dasm_mb86233(buffer, op);
}