changelog shortlog tags branches files raw gz bz2 help

Mercurial > hg > plan9front / changeset: games/blit: clean up cpu.c and make it pass tests

changeset 6897: 53034d183846
parent 6896: cceb691311bb
child 6898: adf1d1950ce6
author: aiju
date: Tue, 20 Nov 2018 09:18:20 +0000
files: sys/src/games/blit/cpu.c
description: games/blit: clean up cpu.c and make it pass tests
     1.1--- a/sys/src/games/blit/cpu.c
     1.2+++ b/sys/src/games/blit/cpu.c
     1.3@@ -132,7 +132,7 @@ amode(int m, int n, int s)
     1.4 			v = fetch16();
     1.5 			return (u32int)(pc + (s16int)v - 2);
     1.6 		case 3:
     1.7-			tim += s == 2 ? 14 : 4;
     1.8+			tim += s == 2 ? 14 : 10;
     1.9 			w = fetch16();
    1.10 			v = r[w >> 12];
    1.11 			if((w & 1<<11) == 0)
    1.12@@ -345,7 +345,8 @@ rot(u32int v, int m, int n, int s)
    1.13 	int l, ll, x, vf;
    1.14 	u32int msb;
    1.15 	
    1.16-	msb = 1 << ((8 << s) - 1);
    1.17+	/* abandon all hope ye who enter here */
    1.18+	msb = 1 << (8 << s) - 1;
    1.19 	v &= (msb << 1) - 1;
    1.20 	if(m == 0)
    1.21 		x = (v & msb) != 0;
    1.22@@ -364,7 +365,8 @@ rot(u32int v, int m, int n, int s)
    1.23 			l = (v & msb) != 0;
    1.24 			v <<= 1;
    1.25 		}
    1.26-		rS = rS & ~FLAGX | l << 4;
    1.27+		if((m & 6) != 6)
    1.28+			rS = rS & ~FLAGX | l << 4;
    1.29 		if(m >= 6)
    1.30 			x = l;
    1.31 		else if(m >= 4){
    1.32@@ -376,12 +378,12 @@ rot(u32int v, int m, int n, int s)
    1.33 				v |= msb;
    1.34 		}else
    1.35 			v |= x;
    1.36-		vf |= x ^ (v & msb) != 0;
    1.37+		vf |= l ^ (v & msb) != 0;
    1.38 		tim += 2;
    1.39 	}
    1.40 	nz(v, s);
    1.41 	rS |= l;
    1.42-	if(m <= 1 && vf)
    1.43+	if(m == 1 && vf)
    1.44 		rS |= FLAGV;
    1.45 	tim += s == 2 ? 8 : 6;
    1.46 	return v;
    1.47@@ -391,45 +393,49 @@ static u8int
    1.48 addbcd(u8int a, u8int b)
    1.49 {
    1.50 	int r;
    1.51+	u8int bc, dc, s;
    1.52 	
    1.53-	r = (a & 0xf) + (b & 0xf) + ((rS & FLAGX) != 0);
    1.54-	if(r > 0x09) r += 0x06;
    1.55-	if(r > 0x1f) r -= 0x10;
    1.56-	r += (a & 0xf0) + (b & 0xf0);
    1.57-	if(r > 0x9f) r += 0x60;
    1.58-	if((u8int)r != 0)
    1.59+	r = a + b + (rS >> 4 & 1);
    1.60+	bc = ((a ^ b ^ r) & 0x110) >> 1;
    1.61+	dc = ((r + 0x66 ^ r) & 0x110) >> 1;
    1.62+	s = r + (bc | dc) - ((bc | dc) >> 2);
    1.63+	rS &= ~(FLAGC|FLAGX|FLAGN|FLAGV);
    1.64+	if(((bc | r & ~s) & 0x80) != 0)
    1.65+		rS |= FLAGC|FLAGX;
    1.66+	if(s != 0)
    1.67 		rS &= ~FLAGZ;
    1.68-	if(r > 0xff)
    1.69-		rS |= FLAGC|FLAGX;
    1.70-	else
    1.71-		rS &= ~(FLAGC|FLAGX);
    1.72-	return r;
    1.73+	if((s & 0x80) != 0)
    1.74+		rS |= FLAGN;
    1.75+	if((~r & s & 0x80) != 0)
    1.76+		rS |= FLAGV;
    1.77+	return s;
    1.78 }
    1.79 
    1.80 static u8int
    1.81 subbcd(u8int a, u8int b)
    1.82 {
    1.83-	int x;
    1.84+	int r;
    1.85+	u8int bc, s;
    1.86 	
    1.87-	x = (a & 0xf) + (~b & 0xf) + ((rS & FLAGX) == 0);
    1.88-	if(x < 0x10) x -= 0x06;
    1.89-	if(x < 0) x += 0x10;
    1.90-	x += (a & 0xf0) + (~b & 0xf0);
    1.91-	if(x > 0xff)
    1.92-		rS &= ~(FLAGC|FLAGX);
    1.93-	else{
    1.94+	r = a - b - (rS >> 4 & 1);
    1.95+	bc = ((a ^ b ^ r) & 0x110) >> 1;
    1.96+	s = r - (bc - (bc >> 2));
    1.97+	rS &= ~(FLAGC|FLAGX|FLAGN|FLAGV);
    1.98+	if(((bc | (~r & s)) & 0x80) != 0)
    1.99 		rS |= FLAGC|FLAGX;
   1.100-		x -= 0x60;
   1.101-	}
   1.102-	if((u8int)x != 0)
   1.103+	if(s != 0)
   1.104 		rS &= ~FLAGZ;
   1.105-	return x;
   1.106+	if((s & 0x80) != 0)
   1.107+		rS |= FLAGN;
   1.108+	if((r & ~s & 0x80) != 0)
   1.109+		rS |= FLAGV;
   1.110+	return s;
   1.111 }
   1.112 
   1.113 static void
   1.114 dtime(u16int op, u8int s)
   1.115 {
   1.116-	if((op & 0x100) != 0){
   1.117+	if((op & 0x100) == 0){
   1.118 		if(s == 2)
   1.119 			if((op & 0x30) == 0 || (op & 0x3f) == 0x3c)
   1.120 				tim += 8;
   1.121@@ -501,19 +507,1001 @@ cpureset(void)
   1.122 	}
   1.123 }
   1.124 
   1.125+static void
   1.126+cputrace(void)
   1.127+{
   1.128+	int i;
   1.129+	static char buf[1024];
   1.130+	static u32int oldr[16];
   1.131+	char *p, *e;
   1.132+	
   1.133+	p = buf;
   1.134+	e = buf + sizeof(buf);
   1.135+	p = seprint(p, e, "%.6ux %.6uo %.4x %.8ux %.8ux |", curpc, op, rS, ra[7], asp);
   1.136+	for(i = 0; i < 16; i++)
   1.137+		if(oldr[i] != r[i])
   1.138+			p = seprint(p, e, " %c%d=%.8ux", i >= 8  ? 'A' : 'D', i & 7, r[i]);
   1.139+	print("%s\n", buf);
   1.140+	memcpy(oldr, r, sizeof(r));
   1.141+}
   1.142+
   1.143+static void
   1.144+ccr_sr_op(u16int op)
   1.145+{
   1.146+	int s;
   1.147+	u32int v, w;
   1.148+	
   1.149+	s = op >> 6 & 3;
   1.150+	if(s == 1 && (rS & FLAGS) == 0){
   1.151+		trap(8, curpc);
   1.152+		return;
   1.153+	}
   1.154+	v = rS;
   1.155+	w = fetch16();
   1.156+	switch(op >> 9 & 7){
   1.157+	case 0: v |= w; break;
   1.158+	case 1: v &= w; break;
   1.159+	case 5: v ^= w; break;
   1.160+	default: undef();
   1.161+	}
   1.162+	if(s != 1)
   1.163+		v = v & 0x1f | rS & 0xff00;
   1.164+	rS = v;
   1.165+	if(s == 1 && (rS & FLAGS) == 0){
   1.166+		v = ra[7];
   1.167+		ra[7] = asp;
   1.168+		asp = v;
   1.169+	}
   1.170+	tim += 20;
   1.171+}
   1.172+
   1.173+static void
   1.174+op_movep(u16int op)
   1.175+{
   1.176+	int s, n;
   1.177+	vlong a;
   1.178+	u32int v;
   1.179+
   1.180+	a = (u32int)(ra[op & 7] + (s16int)fetch16());
   1.181+	s = op >> 6 & 3;
   1.182+	n = op >> 9 & 7;
   1.183+	switch(s){
   1.184+	case 0:
   1.185+		v = (u8int)rmode(a, 0) << 8;
   1.186+		v |= (u8int)rmode(a + 2, 0);
   1.187+		r[n] = r[n] & 0xffff0000 | v;
   1.188+		tim += 16;
   1.189+		break;
   1.190+	case 1:
   1.191+		v = (u8int)rmode(a, 0) << 24;
   1.192+		v |= (u8int)rmode(a + 2, 0) << 16;
   1.193+		v |= (u8int)rmode(a + 4, 0) << 8;
   1.194+		v |= (u8int)rmode(a + 6, 0);
   1.195+		tim += 24;
   1.196+		r[n] = v;
   1.197+		break;
   1.198+	case 2:
   1.199+		wmode(a, 0, r[n] >> 8);
   1.200+		wmode(a + 2, 0, r[n]);
   1.201+		tim += 16;
   1.202+		break;
   1.203+	case 3:
   1.204+		wmode(a, 0, r[n] >> 24);
   1.205+		wmode(a + 2, 0, r[n] >> 16);
   1.206+		wmode(a + 4, 0, r[n] >> 8);
   1.207+		wmode(a + 6, 0, r[n]);
   1.208+		tim += 24;
   1.209+		break;
   1.210+	}
   1.211+}
   1.212+
   1.213+static void
   1.214+bitop(u16int op)
   1.215+{
   1.216+	int s, n;
   1.217+	u32int v, w;
   1.218+	vlong a;
   1.219+	
   1.220+	s = op >> 6 & 3;
   1.221+	n = op >> 9 & 7;
   1.222+	if((op & 0x100) != 0)
   1.223+		w = r[n];
   1.224+	else
   1.225+		w = fetch16();
   1.226+	if((op & 0x38) != 0){
   1.227+		n = 0;
   1.228+		w = 1<<(w & 7);
   1.229+	}else{
   1.230+		n = 2;
   1.231+		w = 1<<(w & 31);
   1.232+	}
   1.233+	a = amode(op >> 3, op, n);
   1.234+	v = rmode(a, n);
   1.235+	rS &= ~FLAGZ;
   1.236+	if((v & w) == 0)
   1.237+		rS |= FLAGZ;
   1.238+	switch(s){
   1.239+	case 1: v ^= w; break;
   1.240+	case 2: v &= ~w; if(n == 2) tim += 2; break;
   1.241+	case 3: v |= w; break;
   1.242+	}
   1.243+	if(s != 0){
   1.244+		wmode(a, n, v);
   1.245+		tim += (op & 0x100) != 0 ? 8 : 12;
   1.246+	}else{
   1.247+		tim += (op & 0x100) != 0 ? 4 : 8;
   1.248+		if(n == 2)
   1.249+			tim += 2;
   1.250+	}
   1.251+}
   1.252+
   1.253+static void
   1.254+immop(u16int op)
   1.255+{
   1.256+	int s, n;
   1.257+	u32int v, w;
   1.258+	vlong a;
   1.259+	
   1.260+	s = op >> 6 & 3;
   1.261+	n = op >> 9 & 7;
   1.262+	switch(s){
   1.263+	case 0: w = (s8int)fetch16(); break;
   1.264+	default: w = fetch16(); break;
   1.265+	case 2: w = fetch32(); break;
   1.266+	}
   1.267+	a = amode(op >> 3, op, s);
   1.268+	v = rmode(a, s);
   1.269+	switch(n){
   1.270+	case 0: nz(v |= w, s); break;
   1.271+	case 1: nz(v &= w, s); break;
   1.272+	case 2: rS |= FLAGZ; v = sub(v, w, 0, s); rS = rS & ~FLAGX | rS << 4 & FLAGX; break;
   1.273+	case 3: rS |= FLAGZ; v = add(v, w, 0, s); rS = rS & ~FLAGX | rS << 4 & FLAGX; break;
   1.274+	case 5: nz(v ^= w, s); break;
   1.275+	case 6: rS |= FLAGZ; sub(v, w, 0, s); break;
   1.276+	default: undef();
   1.277+	}
   1.278+	if(n == 6){
   1.279+		if(a < 0)
   1.280+			tim += s == 2 ? 14 : 8;
   1.281+		else
   1.282+			tim += s == 2 ? 12 : 8;
   1.283+	}else{
   1.284+		if(a < 0)
   1.285+			tim += s == 2 ? 16 : 8;
   1.286+		else
   1.287+			tim += s == 2 ? 20 : 12;
   1.288+	}
   1.289+	if(n != 6)
   1.290+		wmode(a, s, v);
   1.291+}
   1.292+
   1.293+void
   1.294+op_move(u16int op, int s)
   1.295+{
   1.296+	u32int v;
   1.297+
   1.298+	v = rmode(amode(op >> 3, op, s), s);
   1.299+	wmode(amode(op >> 6, op >> 9, s), s, v);
   1.300+	if((op & 0x1c0) != 0x40)
   1.301+		nz(v, s);
   1.302+	tim += 4;
   1.303+	if((op & 0700) == 0400)
   1.304+		tim -= 2;
   1.305+}
   1.306+
   1.307+static void
   1.308+op_lea(u16int op)
   1.309+{
   1.310+	int n;
   1.311+	
   1.312+	n = op >> 9 & 7;
   1.313+	ra[n] = amode(op >> 3, op, 1);
   1.314+	if((op & 070) == 060 || (op & 077) == 073) tim += 2;
   1.315+}
   1.316+
   1.317+static void
   1.318+op_chk(u16int op)
   1.319+{
   1.320+	int s, n;
   1.321+	u32int v;
   1.322+	vlong a;
   1.323+	
   1.324+	s = op >> 6 & 3;
   1.325+	n = op >> 9 & 7;
   1.326+	a = amode(op >> 3, op, s);
   1.327+	v = rmode(a, s);
   1.328+	if((s32int)r[n] < 0 || (s32int)r[n] > (s32int)v)
   1.329+		trap(6, curpc);
   1.330+	else
   1.331+		tim += 10;
   1.332+}
   1.333+
   1.334+static void
   1.335+op_movem(u16int op)
   1.336+{
   1.337+	int s, n, m;
   1.338+	u32int w;
   1.339+	vlong a;
   1.340+	
   1.341+	s = (op >> 6 & 1) + 1;
   1.342+	w = fetch16();
   1.343+	if((op & 0x38) == 0x18){
   1.344+		n = op & 7;
   1.345+		a = ra[n];
   1.346+		for(m = 0; m < 16; m++){
   1.347+			if((w & 1) != 0){
   1.348+				r[m] = rmode(a, s);
   1.349+				a += 1<<s;
   1.350+				tim += 2<<s;
   1.351+			}
   1.352+			w >>= 1;
   1.353+		}
   1.354+		ra[n] = a;
   1.355+		tim += 12;
   1.356+	}else if((op & 0x38) == 0x20){
   1.357+		n = op & 7;
   1.358+		a = ra[n];
   1.359+		for(m = 0; m < 16; m++){
   1.360+			if((w & 1) != 0){
   1.361+				a -= 1<<s;
   1.362+				wmode(a, s, r[15 - m]);
   1.363+				tim += 2<<s;
   1.364+			}
   1.365+			w >>= 1;
   1.366+		}
   1.367+		ra[n] = a;
   1.368+		tim += 8;
   1.369+	}else{
   1.370+		a = amode(op >> 3, op, s);
   1.371+		for(m = 0; m < 16; m++){
   1.372+			if((w & 1) != 0){
   1.373+				if((op & 0x400) != 0)
   1.374+					r[m] = rmode(a, s);
   1.375+				else
   1.376+					wmode(a, s, r[m]);
   1.377+				a += 1<<s;
   1.378+				tim += 2<<s;
   1.379+			}
   1.380+			w >>= 1;
   1.381+		}
   1.382+		tim += (op & 0x400) != 0 ? 8 : 4;
   1.383+		if(s == 2) tim -= 4;
   1.384+	}
   1.385+}
   1.386+
   1.387+static void
   1.388+op_move_from_sr(u16int op)
   1.389+{
   1.390+	vlong a;
   1.391+	
   1.392+	a = amode(op >> 3, op, 1);
   1.393+	wmode(a, 1, rS);
   1.394+	tim += a < 0 ? 6 : 8;
   1.395+}
   1.396+
   1.397+static void
   1.398+op_negx(u16int op)
   1.399+{
   1.400+	int s;
   1.401+	u32int v;
   1.402+	vlong a;
   1.403+	
   1.404+	s = op >> 6 & 3;
   1.405+	a = amode(op >> 3, op, s);
   1.406+	v = rmode(a, s);
   1.407+	wmode(a, s, sub(0, v, rS>>4 & 1, s));
   1.408+	rS = rS & ~FLAGX | rS << 4 & FLAGX;
   1.409+	stime(a < 0, s);
   1.410+}
   1.411+
   1.412+static void
   1.413+op_clr(u16int op)
   1.414+{
   1.415+	int s;
   1.416+	vlong a;
   1.417+	
   1.418+	s = op >> 6 & 3;
   1.419+	a = amode(op >> 3, op, s);
   1.420+	wmode(a, s, 0);
   1.421+	nz(0, 0);
   1.422+	stime(a < 0, s);
   1.423+}
   1.424+
   1.425+static void
   1.426+op_move_to_ccr(u16int op)
   1.427+{
   1.428+	rS = rS & 0xff00 | rmode(amode(op >> 3, op, 1), 1) & 0x1f;
   1.429+	tim += 12;
   1.430+}
   1.431+
   1.432+static void
   1.433+op_neg(u16int op)
   1.434+{
   1.435+	int s;
   1.436+	u32int v;
   1.437+	vlong a;
   1.438+	
   1.439+	s = op >> 6 & 3;
   1.440+	a = amode(op >> 3, op, s);
   1.441+	v = rmode(a, s);
   1.442+	rS |= FLAGZ;
   1.443+	wmode(a, s, sub(0, v, 0, s));
   1.444+	rS = rS & ~FLAGX | rS << 4 & FLAGX;
   1.445+	stime(a < 0, s);
   1.446+}
   1.447+
   1.448+static void
   1.449+op_move_to_sr(u16int op)
   1.450+{
   1.451+	u32int v;
   1.452+	
   1.453+	if((rS & FLAGS) != 0){
   1.454+		rS = rmode(amode(op >> 3, op, 1), 1);
   1.455+		if((rS & FLAGS) == 0){
   1.456+			v = asp;
   1.457+			asp = ra[7];
   1.458+			ra[7] = v;
   1.459+		}
   1.460+		tim += 12;
   1.461+	}else
   1.462+		trap(8, curpc);
   1.463+}
   1.464+
   1.465+static void
   1.466+op_not(u16int op)
   1.467+{
   1.468+	int s;
   1.469+	u32int v;
   1.470+	vlong a;
   1.471+	
   1.472+	s = op >> 6 & 3;
   1.473+	a = amode(op >> 3, op, s);
   1.474+	v = ~rmode(a, s);
   1.475+	nz(v, s);
   1.476+	wmode(a, s, v);
   1.477+	stime(a < 0, s);
   1.478+}
   1.479+
   1.480+static void
   1.481+op_nbcd(u16int op)
   1.482+{
   1.483+	u32int v;
   1.484+	vlong a;
   1.485+	
   1.486+	a = amode(op >> 3, op, 0);
   1.487+	v = rmode(a, 0);
   1.488+	wmode(a, 0, subbcd(0, v));
   1.489+	if(a < 0)
   1.490+		tim += 6;
   1.491+	else
   1.492+		tim += 8;
   1.493+}
   1.494+
   1.495+static void
   1.496+op_pea(u16int op)
   1.497+{
   1.498+	ra[7] -= 4;
   1.499+	wmode(ra[7], 2, amode(op >> 3, op, 1));
   1.500+	tim += 8;
   1.501+	if((op & 070) == 060 || (op & 077) == 073) tim += 2;
   1.502+}
   1.503+
   1.504+static void
   1.505+op_swap(u16int op)
   1.506+{
   1.507+	int n;
   1.508+	
   1.509+	n = op & 7;
   1.510+	nz(r[n] = r[n] >> 16 | r[n] << 16, 2);
   1.511+	tim += 4;
   1.512+}
   1.513+
   1.514+static void
   1.515+op_ext_b(u16int op)
   1.516+{
   1.517+	int n;
   1.518+	
   1.519+	n = op & 7;
   1.520+	nz(r[n] = r[n] & 0xffff0000 | (u16int)(s8int)r[n], 1);
   1.521+	tim += 4;
   1.522+}
   1.523+
   1.524+static void
   1.525+op_ext_w(u16int op)
   1.526+{
   1.527+	int n;
   1.528+	
   1.529+	n = op & 7;
   1.530+	nz(r[n] = (s16int)r[n], 2);
   1.531+	tim += 4;
   1.532+}
   1.533+
   1.534+static void
   1.535+op_tas(u16int op)
   1.536+{
   1.537+	u32int v;
   1.538+	vlong a;
   1.539+	
   1.540+	a = amode(op >> 3, op, 0);
   1.541+	v = rmode(a, 0);
   1.542+	nz(v, 0);
   1.543+	wmode(a, 0, v | 0x80);
   1.544+	tim += a < 0 ? 4 : 14;
   1.545+}
   1.546+
   1.547+static void
   1.548+op_tst(u16int op)
   1.549+{
   1.550+	int s;
   1.551+	vlong a;
   1.552+	
   1.553+	s = op >> 6 & 3;
   1.554+	a = amode(op >> 3, op, s);
   1.555+	nz(rmode(a, s), s);
   1.556+	tim += 4;
   1.557+}
   1.558+
   1.559+static void
   1.560+op_trap(u16int op)
   1.561+{
   1.562+	trap(0x20 | op & 0xf, pc);
   1.563+}
   1.564+
   1.565+static void
   1.566+op_link(u16int op)
   1.567+{
   1.568+	int n;
   1.569+	
   1.570+	n = op & 7;
   1.571+	push32(ra[n]);
   1.572+	ra[n] = ra[7];
   1.573+	ra[7] += (s16int)fetch16();
   1.574+	tim += 16;
   1.575+}
   1.576+
   1.577+static void
   1.578+op_unlk(u16int op)
   1.579+{
   1.580+	int n;
   1.581+	
   1.582+	n = op & 7;
   1.583+	ra[7] = ra[n];
   1.584+	ra[n] = pop32();
   1.585+	tim += 12;
   1.586+}
   1.587+
   1.588+static void
   1.589+op_move_usp(u16int op)
   1.590+{
   1.591+	int n;
   1.592+	
   1.593+	n = op & 7;
   1.594+	if((rS & FLAGS) != 0){
   1.595+		if((op & 8) != 0)
   1.596+			ra[n] = asp;
   1.597+		else
   1.598+			asp = ra[n];
   1.599+		tim += 4;
   1.600+	}else
   1.601+		trap(8, curpc);
   1.602+}
   1.603+
   1.604+static void
   1.605+jtime(int op)
   1.606+{
   1.607+	int a;
   1.608+	
   1.609+	a = op >> 3 & 7;
   1.610+	if(a == 2 || a == 6 || (op & 077) == 073)
   1.611+		tim += 2;
   1.612+	else if((op & 077) == 071)
   1.613+		tim -= 2;
   1.614+}
   1.615+
   1.616+static void
   1.617+op_jmp(u16int op)
   1.618+{
   1.619+	pc = amode(op >> 3, op, 1);
   1.620+	jtime(op);
   1.621+	tim += 2;
   1.622+}
   1.623+
   1.624+static void
   1.625+op_jsr(u16int op)
   1.626+{
   1.627+	vlong a;
   1.628+
   1.629+	a = amode(op >> 3, op, 1);
   1.630+	push32(pc);
   1.631+	pc = a;
   1.632+	jtime(op);
   1.633+	tim += 10;
   1.634+}
   1.635+
   1.636+static void
   1.637+op_reset(u16int op)
   1.638+{
   1.639+	USED(op);
   1.640+	tim += 132;
   1.641+}
   1.642+
   1.643+static void
   1.644+op_nop(u16int op)
   1.645+{
   1.646+	USED(op);
   1.647+	tim += 4;
   1.648+}
   1.649+
   1.650+static void
   1.651+op_stop(u16int op)
   1.652+{
   1.653+	USED(op);
   1.654+	if((rS & FLAGS) != 0){
   1.655+		rS = fetch16();
   1.656+		stop = 1;
   1.657+	}else
   1.658+		trap(8, curpc);
   1.659+	tim += 4;
   1.660+}
   1.661+
   1.662+static void
   1.663+op_rte(u16int op)
   1.664+{
   1.665+	u32int v;
   1.666+
   1.667+	USED(op);
   1.668+	if((rS & FLAGS) != 0){
   1.669+		v = rS;
   1.670+		rS = pop16();
   1.671+		pc = pop32();
   1.672+		if(((v ^ rS) & FLAGS) != 0){
   1.673+			v = asp;
   1.674+			asp = ra[7];
   1.675+			ra[7] = v;
   1.676+		}
   1.677+		tim += 20;
   1.678+	}else
   1.679+		trap(8, curpc);
   1.680+}
   1.681+
   1.682+static void
   1.683+op_rts(u16int op)
   1.684+{
   1.685+	USED(op);
   1.686+	pc = pop32();
   1.687+	tim += 16;
   1.688+}
   1.689+
   1.690+void
   1.691+op_trapv(u16int op)
   1.692+{
   1.693+	USED(op);
   1.694+	if((rS & FLAGV) != 0)
   1.695+		trap(7, curpc); 
   1.696+	tim += 4;
   1.697+}
   1.698+
   1.699+void
   1.700+op_rtr(u16int op)
   1.701+{
   1.702+	USED(op);
   1.703+	rS = rS & 0xff00 | pop16() & 0x1f;
   1.704+	pc = pop32();
   1.705+	tim += 20;
   1.706+}
   1.707+
   1.708+static void
   1.709+op_dbcc(u16int op)
   1.710+{
   1.711+	int n;
   1.712+	u32int v;
   1.713+	
   1.714+	n = op & 7;
   1.715+	v = (s16int)fetch16();
   1.716+	if(!cond((op >> 8) & 0xf)){
   1.717+		if((u16int)r[n] != 0){
   1.718+			r[n]--;
   1.719+			pc = pc + v - 2;
   1.720+			tim += 10;
   1.721+		}else{
   1.722+			r[n] |= 0xffff;
   1.723+			tim += 14;
   1.724+		}
   1.725+	}else
   1.726+		tim += 12;
   1.727+}
   1.728+
   1.729+static void
   1.730+op_scc(u16int op)
   1.731+{
   1.732+	u32int v;
   1.733+	vlong a;
   1.734+
   1.735+	a = amode(op >> 3, op, 0);
   1.736+	v = cond(op >> 8 & 0xf);
   1.737+	wmode(a, 0, -v);
   1.738+	if(a < 0)
   1.739+		tim += 4 + 2 * v;
   1.740+	else
   1.741+		tim += 8;
   1.742+}
   1.743+
   1.744+static void
   1.745+op_addq_subq(u16int op)
   1.746+{
   1.747+	int s, n;
   1.748+	u32int v;
   1.749+	vlong a;
   1.750+	
   1.751+	s = op >> 6 & 3;
   1.752+	n = op >> 9 & 7;
   1.753+	rS |= FLAGZ;
   1.754+	if((op & 0x38) == 0x08)
   1.755+		s = 2;
   1.756+	a = amode(op >> 3, op, s);
   1.757+	v = rmode(a, s);
   1.758+	if(n == 0)
   1.759+		n = 8;
   1.760+	if((op & 0x100) == 0)
   1.761+		v = add(v, n, 0, s);
   1.762+	else
   1.763+		v = sub(v, n, 0, s);
   1.764+	rS = rS & ~FLAGX | rS << 4 & FLAGX;
   1.765+	if(a < 0)
   1.766+		tim += s == 2 ? 8 : 4;
   1.767+	else
   1.768+		tim += s == 2 ? 12 : 8;
   1.769+	wmode(a, s, v);
   1.770+}
   1.771+
   1.772+static void
   1.773+op_addq_subq_a(u16int op)
   1.774+{
   1.775+	int s, n;
   1.776+	
   1.777+	s = op >> 6 & 3;
   1.778+	n = op >> 9 & 7;
   1.779+	if(n == 0)
   1.780+		n = 8;
   1.781+	tim += s == 2 || (op & 0x100) != 0 ? 8 : 4;
   1.782+	if((op & 0x100) == 0)
   1.783+		ra[op & 7] += n;
   1.784+	else
   1.785+		ra[op & 7] -= n;
   1.786+}
   1.787+
   1.788+static void
   1.789+op_bra(u16int op)
   1.790+{
   1.791+	u32int v;
   1.792+	
   1.793+	v = (s8int)op;
   1.794+	if(v == 0)
   1.795+		v = (s16int)fetch16();
   1.796+	else if(v == (u32int)-1)
   1.797+		v = fetch32();
   1.798+	if((op & 0xf00) == 0x100){ /* BSR */
   1.799+		push32(pc);
   1.800+		pc = curpc + 2 + v;
   1.801+		tim += 18;
   1.802+		return;
   1.803+	}
   1.804+	if(cond((op >> 8) & 0xf)){
   1.805+		pc = curpc + 2 + v;
   1.806+		tim += 10;
   1.807+	}else
   1.808+		tim += (u8int)(op + 1) <= 1 ? 12 : 8;
   1.809+}
   1.810+
   1.811+static void
   1.812+op_moveq(u16int op)
   1.813+{
   1.814+	int n;
   1.815+	
   1.816+	n = op >> 9 & 7;
   1.817+	r[n] = (s8int)op;
   1.818+	nz(r[n], 0);
   1.819+	tim += 4;
   1.820+}
   1.821+
   1.822+static void
   1.823+op_divu_divs(u16int op)
   1.824+{
   1.825+	int n;
   1.826+	u32int v, w;
   1.827+	vlong a;
   1.828+	
   1.829+	n = op >> 9 & 7;
   1.830+	a = amode(op >> 3, op, 1);
   1.831+	v = rmode(a, 1);
   1.832+	if(v == 0){
   1.833+		trap(5, curpc);
   1.834+		return;
   1.835+	}
   1.836+	if((op & 0x100) != 0){
   1.837+		w = (s32int)r[n] % (s16int)v;
   1.838+		v = (s32int)r[n] / (s16int)v;
   1.839+		if((s32int)(w ^ r[n]) < 0)
   1.840+			w = -w;
   1.841+		tim += 158;
   1.842+		if(v != (u32int)(s16int)v){
   1.843+			rS = rS & ~FLAGC | FLAGV;
   1.844+			return;
   1.845+		}
   1.846+	}else{
   1.847+		w = r[n] % (u16int)v;
   1.848+		v = r[n] / (u16int)v;
   1.849+		tim += 140;
   1.850+		if(v >= 0x10000){
   1.851+			rS = rS & ~FLAGC | FLAGV;
   1.852+			return;
   1.853+		}
   1.854+	}
   1.855+	r[n] = (u16int)v | w << 16;
   1.856+	nz(v, 1);
   1.857+}
   1.858+
   1.859+static void
   1.860+op_sbcd(u16int op)
   1.861+{
   1.862+	int n, m;
   1.863+	u32int v, w;
   1.864+	vlong src, dst;
   1.865+	
   1.866+	n = op >> 9 & 7;
   1.867+	m = op & 7;
   1.868+	if((op & 8) != 0){
   1.869+		src = amode(4, m, 0);
   1.870+		dst = amode(4, n, 0);
   1.871+		w = rmode(src, 0);
   1.872+		v = rmode(dst, 0);
   1.873+		v = subbcd(v, w);
   1.874+		wmode(dst, 0, v);
   1.875+	}else
   1.876+		r[n] = r[n] & 0xffffff00 | subbcd(r[n], r[m]);
   1.877+	tim += 6;
   1.878+}
   1.879+
   1.880+static void
   1.881+logic(u16int op)
   1.882+{
   1.883+	int s, n;
   1.884+	u32int v;
   1.885+	vlong a;
   1.886+	
   1.887+	s = op >> 6 & 3;
   1.888+	a = amode(op >> 3, op, s);
   1.889+	n = op >> 9 & 7;
   1.890+	v = rmode(a, s);
   1.891+	switch(op >> 12){
   1.892+	case 8: v |= r[n]; break;
   1.893+	case 11: v ^= r[n]; break;
   1.894+	case 12: v &= r[n]; break;
   1.895+	}
   1.896+	if((op & 0x100) == 0)
   1.897+		a = ~n;
   1.898+	wmode(a, s, v);
   1.899+	nz(v, s);
   1.900+	dtime(op, s);
   1.901+}
   1.902+
   1.903+static void
   1.904+op_cmpa(u16int op)
   1.905+{
   1.906+	int s, n;
   1.907+	vlong a;
   1.908+
   1.909+	n = op >> 9 & 7;
   1.910+	s = (op >> 8 & 1) + 1;
   1.911+	a = amode(op >> 3, op, s);
   1.912+	rS |= FLAGZ;
   1.913+	sub(ra[n], rmode(a, s), 0, 2);
   1.914+	tim += 6;
   1.915+}
   1.916+
   1.917+static void
   1.918+op_cmpm(u16int op)
   1.919+{
   1.920+	int s, n, m;
   1.921+	vlong src, dst;
   1.922+	u32int v, w;
   1.923+	
   1.924+	s = op >> 6 & 3;
   1.925+	n = op >> 9 & 7;
   1.926+	m = op & 7;
   1.927+	rS |= FLAGZ;
   1.928+	src = amode(3, m, s);
   1.929+	dst = amode(3, n, s);
   1.930+	v = rmode(src, s);
   1.931+	w = rmode(dst, s);
   1.932+	sub(w, v, 0, s);
   1.933+	tim += 4;
   1.934+}
   1.935+
   1.936+static void
   1.937+op_cmp(u16int op)
   1.938+{
   1.939+	int s, n;
   1.940+	vlong a;
   1.941+	
   1.942+	s = op >> 6 & 3;
   1.943+	n = op >> 9 & 7;
   1.944+	a = amode(op >> 3, op, s);
   1.945+	rS |= FLAGZ;
   1.946+	sub(r[n], rmode(a, s), 0, s);
   1.947+	tim += s == 2 ? 6 : 4;
   1.948+}
   1.949+
   1.950+static void
   1.951+op_mulu_muls(u16int op)
   1.952+{
   1.953+	int n;
   1.954+	u32int v;
   1.955+	vlong a;
   1.956+	
   1.957+	n = op >> 9 & 7;
   1.958+	a = amode(op >> 3, op, 1);
   1.959+	v = rmode(a, 1);
   1.960+	if((op & 0x100) != 0)
   1.961+		v *= (s16int)r[n];
   1.962+	else
   1.963+		v = (u16int)v * (u16int)r[n];
   1.964+	r[n] = v;
   1.965+	nz(v, 2);
   1.966+	tim += 70;
   1.967+}
   1.968+
   1.969+static void
   1.970+op_abcd(u16int op)
   1.971+{
   1.972+	int n, m;
   1.973+	u32int v, w;
   1.974+	vlong src, dst;
   1.975+	
   1.976+	n = op >> 9 & 7;
   1.977+	m = op & 7;
   1.978+	if((op & 8) != 0){
   1.979+		src = amode(4, m, 0);
   1.980+		dst = amode(4, n, 0);
   1.981+		v = rmode(src, 0);
   1.982+		w = rmode(dst, 0);
   1.983+		v = addbcd(v, w);
   1.984+		wmode(dst, 0, v);
   1.985+	}else
   1.986+		r[n] = r[n] & 0xffffff00 | addbcd(r[n], r[m]);
   1.987+	tim += 6;
   1.988+}
   1.989+
   1.990+static void
   1.991+op_exg(u16int op)
   1.992+{
   1.993+	int n, m;
   1.994+	u32int v;
   1.995+	
   1.996+	n = op >> 9 & 7;
   1.997+	m = op & 0xf;
   1.998+	if((op & 0xc8) == 0x48)
   1.999+		n |= 8;
  1.1000+	v = r[n];
  1.1001+	r[n] = r[m];
  1.1002+	r[m] = v;
  1.1003+	tim += 6;
  1.1004+}
  1.1005+
  1.1006+static void
  1.1007+op_adda_suba(u16int op)
  1.1008+{
  1.1009+	int s, n;
  1.1010+	vlong a;
  1.1011+	
  1.1012+	n = op >> 9 & 7;
  1.1013+	if((op & 0x100) != 0){
  1.1014+		s = 2;
  1.1015+		if((op & 0x30) == 0 || (op & 0x3f) == 0x3c)
  1.1016+			tim += 8;
  1.1017+		else
  1.1018+			tim += 6;
  1.1019+	}else{
  1.1020+		s = 1;
  1.1021+		tim += 8;
  1.1022+	}
  1.1023+	a = amode(op >> 3, op, s);
  1.1024+	if((op >> 12) == 13)
  1.1025+		ra[n] += rmode(a, s);
  1.1026+	else
  1.1027+		ra[n] -= rmode(a, s);
  1.1028+}
  1.1029+
  1.1030+static void
  1.1031+op_addx_subx(u16int op)
  1.1032+{
  1.1033+	int s, n, m;
  1.1034+	u32int v, w;
  1.1035+	vlong src, dst;
  1.1036+	
  1.1037+	s = op >> 6 & 3;
  1.1038+	n = op >> 9 & 7;
  1.1039+	m = op & 7;
  1.1040+	if((op & 8) != 0){
  1.1041+		src = amode(4, m, s);
  1.1042+		dst = amode(4, n, s);
  1.1043+		w = rmode(src, s);
  1.1044+		v = rmode(dst, s);
  1.1045+		tim += s == 2 ? 10 : 6;
  1.1046+	}else{
  1.1047+		w = r[m];
  1.1048+		v = r[n];
  1.1049+		dst = ~n;
  1.1050+		tim += s == 2 ? 8 : 4;
  1.1051+	}
  1.1052+	if((op >> 12) == 13)
  1.1053+		v = add(v, w, (rS & FLAGX) != 0, s);
  1.1054+	else
  1.1055+		v = sub(v, w, (rS & FLAGX) != 0, s);
  1.1056+	wmode(dst, s, v);
  1.1057+	rS = rS & ~FLAGX | rS << 4 & FLAGX;
  1.1058+}
  1.1059+
  1.1060+static void
  1.1061+op_add_sub(u16int op)
  1.1062+{
  1.1063+	int s, n, d;
  1.1064+	u32int v;
  1.1065+	vlong a;
  1.1066+	
  1.1067+	s = op >> 6 & 3;
  1.1068+	n = op >> 9 & 7;
  1.1069+	a = amode(op >> 3, op, s);
  1.1070+	rS |= FLAGZ;
  1.1071+	d = (op & 0x100) == 0;
  1.1072+	v = rmode(a, s);
  1.1073+	if((op >> 12) == 13)
  1.1074+		v = add(v, r[n], 0, s);
  1.1075+	else
  1.1076+		v = sub(d ? r[n] : v, d ? v : r[n], 0, s);
  1.1077+	rS = rS & ~FLAGX | rS << 4 & FLAGX;
  1.1078+	if(d)
  1.1079+		a = ~n;
  1.1080+	wmode(a, s, v);
  1.1081+	dtime(op, s);
  1.1082+}
  1.1083+
  1.1084+static void
  1.1085+shifts(u16int op)
  1.1086+{
  1.1087+	int s, n, m;
  1.1088+	vlong a;
  1.1089+
  1.1090+	s = op >> 6 & 3;
  1.1091+	if(s == 3){
  1.1092+		m = op >> 8 & 7;
  1.1093+		n = 1;
  1.1094+		s = 1;
  1.1095+		a = amode(op >> 3, op, s);
  1.1096+	}else{
  1.1097+		a = ~(uvlong)(op & 7);
  1.1098+		m = op >> 2 & 6 | op >> 8 & 1;
  1.1099+		n = (op >> 9) & 7;
  1.1100+		if((op & 0x20) != 0)
  1.1101+			n = r[n] & 63;
  1.1102+		else if(n == 0)
  1.1103+			n = 8;
  1.1104+	}
  1.1105+	wmode(a, s, rot(rmode(a, s), m, n, s));
  1.1106+}
  1.1107+
  1.1108 int
  1.1109 step(void)
  1.1110 {
  1.1111-	u32int v, w;
  1.1112-	vlong a;
  1.1113 	int s;
  1.1114-	int n, m, d;
  1.1115+	int n;
  1.1116 	static int cnt;
  1.1117 
  1.1118 	if(0 && pc == 0x4118c){
  1.1119 		trace++;
  1.1120 		print("%x\n", curpc);
  1.1121 	}
  1.1122+//	if(pc == 0x410de) trace++;
  1.1123 	tim = 0;
  1.1124 	curpc = pc;
  1.1125 	if(irq && (irqla[(rS >> 8) & 7] & irq) != 0){
  1.1126@@ -524,652 +1512,158 @@ step(void)
  1.1127 		return 1;
  1.1128 	op = fetch16();
  1.1129 	if(trace)
  1.1130-		print("%.6ux %.6uo %.4ux %.8ux | %.8ux %.8ux %.8ux %.8ux | %.8ux %.8ux %.8ux\n", curpc, op, rS, memread(ra[7])<<16|memread(ra[7]+2), r[0], r[1], r[2], r[3], ra[0], ra[6], ra[7]);
  1.1131+		cputrace();
  1.1132 	s = op >> 6 & 3;
  1.1133 	n = op >> 9 & 7;
  1.1134 	switch(op >> 12){
  1.1135 	case 0:
  1.1136-		if((op & 0x3f) == 0x3c){ /* (ORI|ANDI|EORI) to (CCR|SR) */
  1.1137-			if(s == 1 && (rS & FLAGS) == 0){
  1.1138-				trap(8, curpc);
  1.1139-				break;
  1.1140-			}
  1.1141-			v = rS;
  1.1142-			w = fetch16();
  1.1143-			switch(n){
  1.1144-			case 0: v |= w; break;
  1.1145-			case 1: v &= w; break;
  1.1146-			case 5: v ^= w; break;
  1.1147-			default: undef();
  1.1148-			}
  1.1149-			if(s != 1)
  1.1150-				v = v & 0xff | rS & 0xff00;
  1.1151-			rS = v;
  1.1152-			if(s == 1 && (rS & FLAGS) == 0){
  1.1153-				v = ra[7];
  1.1154-				ra[7] = asp;
  1.1155-				asp = v;
  1.1156-			}
  1.1157-			tim += 20;
  1.1158-			break;
  1.1159-		}
  1.1160-		if((op & 0x138) == 0x108){ /* MOVEP */
  1.1161-			a = ra[op & 7] + (s16int)fetch16();
  1.1162-			switch(s){
  1.1163+		if((op & 0x3f) == 0x3c)
  1.1164+			ccr_sr_op(op);
  1.1165+		else if((op & 0x138) == 0x108)
  1.1166+			op_movep(op);
  1.1167+		else if((op & 0x100) != 0 || n == 4)
  1.1168+			bitop(op);
  1.1169+		else
  1.1170+			immop(op);
  1.1171+		break;
  1.1172+	case 1: op_move(op, 0); break;
  1.1173+	case 2: op_move(op, 2); break;
  1.1174+	case 3: op_move(op, 1); break;
  1.1175+	case 4:
  1.1176+		if((op & 0x1c0) == 0x1c0)
  1.1177+			op_lea(op);
  1.1178+		else if((op & 0x1c0) == 0x180)
  1.1179+			op_chk(op);
  1.1180+		else if((op & 0xb80) == 0x880 && (op & 0x38) >= 0x10)
  1.1181+			op_movem(op);
  1.1182+		else
  1.1183+			switch(op >> 8 & 0xf){
  1.1184 			case 0:
  1.1185-				v = (u8int)rmode(a, 0) << 8;
  1.1186-				v |= (u8int)rmode(a + 2, 0);
  1.1187-				r[n] = r[n] & 0xff00 | v;
  1.1188-				tim += 16;
  1.1189-				break;
  1.1190-			case 1:
  1.1191-				v = (u8int)rmode(a, 0) << 24;
  1.1192-				v |= (u8int)rmode(a + 2, 0) << 16;
  1.1193-				v |= (u8int)rmode(a + 4, 0) << 8;
  1.1194-				v |= (u8int)rmode(a + 6, 0);
  1.1195-				tim += 24;
  1.1196-				r[n] = v;
  1.1197-				break;
  1.1198-			case 2:
  1.1199-				wmode(a, 0, r[n] >> 8);
  1.1200-				wmode(a + 2, 0, r[n]);
  1.1201-				tim += 16;
  1.1202-				break;
  1.1203-			case 3:
  1.1204-				wmode(a, 0, r[n] >> 24);
  1.1205-				wmode(a + 2, 0, r[n] >> 16);
  1.1206-				wmode(a + 4, 0, r[n] >> 8);
  1.1207-				wmode(a + 6, 0, r[n]);
  1.1208-				tim += 24;
  1.1209-				break;
  1.1210-			}
  1.1211-			break;
  1.1212-		}
  1.1213-		if((op & 0x100) != 0 || n == 4){ /* BTST, BCHG, BCLR, BSET */
  1.1214-			if((op & 0x100) != 0)
  1.1215-				w = r[n];
  1.1216-			else
  1.1217-				w = fetch16();
  1.1218-			if((op & 0x38) != 0){
  1.1219-				n = 0;
  1.1220-				w = 1<<(w & 7);
  1.1221-			}else{
  1.1222-				n = 2;
  1.1223-				w = 1<<(w & 31);
  1.1224-			}
  1.1225-			a = amode(op >> 3, op, n);
  1.1226-			v = rmode(a, n);
  1.1227-			rS &= ~FLAGZ;
  1.1228-			if((v & w) == 0)
  1.1229-				rS |= FLAGZ;
  1.1230-			switch(s){
  1.1231-			case 1: v ^= w; break;
  1.1232-			case 2: v &= ~w; if(n == 2) tim += 2; break;
  1.1233-			case 3: v |= w; break;
  1.1234-			}
  1.1235-			if(s != 0){
  1.1236-				wmode(a, n, v);
  1.1237-				tim += (op & 0x100) != 0 ? 8 : 12;
  1.1238-			}else{
  1.1239-				tim += (op & 0x100) != 0 ? 4 : 8;
  1.1240-				if(n == 2)
  1.1241-					tim += 2;
  1.1242-			}
  1.1243-			break;
  1.1244-		}
  1.1245-		switch(s){
  1.1246-		case 0: w = (s8int)fetch16(); break;
  1.1247-		default: w = fetch16(); break;
  1.1248-		case 2: w = fetch32(); break;
  1.1249-		}
  1.1250-		a = amode(op >> 3, op, s);
  1.1251-		v = rmode(a, s);
  1.1252-		switch(n){
  1.1253-		case 0: nz(v |= w, s); break;
  1.1254-		case 1: nz(v &= w, s); break;
  1.1255-		case 2: rS |= FLAGZ; v = sub(v, w, 0, s); break;
  1.1256-		case 3: rS |= FLAGZ; v = add(v, w, 0, s); break;
  1.1257-		case 5: nz(v ^= w, s); break;
  1.1258-		case 6: rS |= FLAGZ; sub(v, w, 0, s); break;
  1.1259-		default: undef();
  1.1260-		}
  1.1261-		if(a < 0)
  1.1262-			tim += s == 2 ? (n == 1 || n == 6 ? 14 : 16) : 8;
  1.1263-		else
  1.1264-			tim += s == 2 ? 20 : 12;
  1.1265-		if(n != 6)
  1.1266-			wmode(a, s, v);
  1.1267-		break;
  1.1268-	case 1: /* MOVE */
  1.1269-		s = 0;
  1.1270-		goto move;
  1.1271-	case 2:
  1.1272-		s = 2;
  1.1273-		goto move;
  1.1274-	case 3:
  1.1275-		s = 1;
  1.1276-	move:
  1.1277-		v = rmode(amode(op >> 3, op, s), s);
  1.1278-		wmode(amode(op >> 6, op >> 9, s), s, v);
  1.1279-		if((op & 0x1c0) != 0x40)
  1.1280-			nz(v, s);
  1.1281-		tim += 4;
  1.1282-		break;
  1.1283-	case 4:
  1.1284-		if((op & 0x1c0) == 0x1c0){ /* LEA */
  1.1285-			ra[n] = amode(op >> 3, op, 2);
  1.1286-			break;
  1.1287-		}
  1.1288-		if((op & 0x1c0) == 0x180){ /* CHK */
  1.1289-			a = amode(op >> 3, op, s);
  1.1290-			v = rmode(a, s);
  1.1291-			if((s32int)r[n] < 0 || (s32int)r[n] > (s32int)v)
  1.1292-				trap(6, curpc);
  1.1293-			else
  1.1294-				tim += 10;
  1.1295-		}
  1.1296-		if((op & 0xb80) == 0x880 && (op & 0x38) >= 0x10){ /* MOVEM */
  1.1297-			s = (op >> 6 & 1) + 1;
  1.1298-			w = fetch16();
  1.1299-			if((op & 0x38) == 0x18){
  1.1300-				n = op & 7;
  1.1301-				a = ra[n];
  1.1302-				for(m = 0; m < 16; m++){
  1.1303-					if((w & 1) != 0){
  1.1304-						r[m] = rmode(a, s);
  1.1305-						a += 1<<s;
  1.1306-						tim += 2<<s;
  1.1307-					}
  1.1308-					w >>= 1;
  1.1309-				}
  1.1310-				ra[n] = a;
  1.1311-				tim += 12;
  1.1312+				if(s == 3)
  1.1313+					op_move_from_sr(op);
  1.1314+				else
  1.1315+					op_negx(op);
  1.1316 				break;
  1.1317-			}
  1.1318-			if((op & 0x38) == 0x20){
  1.1319-				n = op & 7;
  1.1320-				a = ra[n];
  1.1321-				for(m = 0; m < 16; m++){
  1.1322-					if((w & 1) != 0){
  1.1323-						a -= 1<<s;
  1.1324-						wmode(a, s, r[15 - m]);
  1.1325-						tim += 2<<s;
  1.1326-					}
  1.1327-					w >>= 1;
  1.1328-				}
  1.1329-				ra[n] = a;
  1.1330-				tim += 8;
  1.1331-				break;
  1.1332-			}
  1.1333-			a = amode(op >> 3, op, s);
  1.1334-			for(m = 0; m < 16; m++){
  1.1335-				if((w & 1) != 0){
  1.1336-					if((op & 0x400) != 0)
  1.1337-						r[m] = rmode(a, s);
  1.1338-					else
  1.1339-						wmode(a, s, r[m]);
  1.1340-					a += 1<<s;
  1.1341-					tim += 2<<s;
  1.1342-				}
  1.1343-				w >>= 1;
  1.1344-			}
  1.1345-			tim += (op & 0x400) != 0 ? 8 : 12;
  1.1346-			break;
  1.1347-		}
  1.1348-		switch(op >> 8 & 0xf){
  1.1349-		case 0:
  1.1350-			if(s == 3){ /* MOVE from SR */
  1.1351-				if((rS & FLAGS) != 0){
  1.1352-					a = amode(op >> 3, op, 1);
  1.1353-					wmode(a, 1, rS);
  1.1354-					tim += a < 0 ? 6 : 8;
  1.1355-				}else
  1.1356-					trap(8, curpc);
  1.1357-				break;
  1.1358-			} /* NEGX */
  1.1359-			a = amode(op >> 3, op, s);
  1.1360-			m = (rS & FLAGX) != 0;
  1.1361-			d = 1<<(8<<s)-1;
  1.1362-			v = rmode(a, s);
  1.1363-			w = -(v+m) & (d << 1) - 1;
  1.1364-			rS &= ~(FLAGC|FLAGX|FLAGN|FLAGV);
  1.1365-			if((w & d) != 0)
  1.1366-				rS |= FLAGN;
  1.1367-			if(m && w == d)
  1.1368-				rS |= FLAGV;
  1.1369-			if(w != 0){
  1.1370-				rS |= FLAGC|FLAGX;
  1.1371-				rS &= ~FLAGZ;
  1.1372-			}
  1.1373-			wmode(a, s, w);
  1.1374-			stime(a < 0, s);
  1.1375-			break;
  1.1376-		case 2: /* CLR */
  1.1377-			a = amode(op >> 3, op, s);
  1.1378-			wmode(a, s, 0);
  1.1379-			nz(0, 0);
  1.1380-			stime(a < 0, s);
  1.1381-			break;
  1.1382-		case 4:
  1.1383-			if(s == 3){ /* MOVE to CCR */
  1.1384-				rS = rS & 0xff00 | rmode(amode(op >> 3, op, 1), 1);
  1.1385-				tim += 12;
  1.1386+			case 2: op_clr(op); break;
  1.1387+			case 4:
  1.1388+				if(s == 3)
  1.1389+					op_move_to_ccr(op);
  1.1390+				else
  1.1391+					op_neg(op);
  1.1392 				break;
  1.1393-			} /* NEG */
  1.1394-			a = amode(op >> 3, op, s);
  1.1395-			v = -rmode(a, s);
  1.1396-			nz(v, s);
  1.1397-			rS = rS & ~FLAGX | ~rS << 2 & FLAGX | ~rS >> 2 & FLAGC;
  1.1398-			wmode(a, s, v);
  1.1399-			stime(a < 0, s);
  1.1400-			break;
  1.1401-		case 6:
  1.1402-			if(s == 3){ /* MOVE to SR */
  1.1403-				if((rS & FLAGS) != 0){
  1.1404-					rS = rmode(amode(op >> 3, op, 1), 1);
  1.1405-					if((rS & FLAGS) == 0){
  1.1406-						v = asp;
  1.1407-						asp = ra[7];
  1.1408-						ra[7] = v;
  1.1409-					}
  1.1410-					tim += 12;
  1.1411-				}else
  1.1412-					trap(8, curpc);
  1.1413-				break;
  1.1414-			} /* NOT */
  1.1415-			a = amode(op >> 3, op, s);
  1.1416-			v = ~rmode(a, s);
  1.1417-			nz(v, s);
  1.1418-			wmode(a, s, v);
  1.1419-			stime(a < 0, s);
  1.1420-			break;
  1.1421-		case 8:
  1.1422-			n = op & 7;
  1.1423-			switch(s){
  1.1424-			case 0: /* NBCD */
  1.1425-				a = amode(op >> 3, op, 0);
  1.1426-				v = rmode(a, 0);
  1.1427-				wmode(a, 0, subbcd(0, v));
  1.1428-				if(a < 0)
  1.1429-					tim += 8;
  1.1430+			case 6:
  1.1431+				if(s == 3)
  1.1432+					op_move_to_sr(op);
  1.1433 				else
  1.1434-					tim += 6;
  1.1435+					op_not(op);
  1.1436 				break;
  1.1437-			case 1:
  1.1438-				if((op >> 3 & 7) != 0){
  1.1439-					push32(amode(op >> 3, op, 0)); /* PEA */
  1.1440-					tim += 8;
  1.1441-				}else{
  1.1442-					nz(r[n] = r[n] >> 16 | r[n] << 16, 2); /* SWAP */
  1.1443-					tim += 4;
  1.1444-				}
  1.1445-				break;
  1.1446-			case 2: /* EXT */
  1.1447-				nz(r[n] = r[n] & 0xffff0000 | (u16int)(s8int)r[n], 1);
  1.1448-				tim += 4;
  1.1449-				break;
  1.1450-			case 3: /* EXT */
  1.1451-				nz(r[n] = (s16int)r[n], 2);
  1.1452-				tim += 4;
  1.1453-				break;
  1.1454-			}
  1.1455-			break;
  1.1456-		case 10:
  1.1457-			if(s == 3){ /* TAS */
  1.1458-				a = amode(op >> 3, op, 0);
  1.1459-				v = rmode(a, 0);
  1.1460-				nz(v, 0);
  1.1461-				wmode(a, s, v | 0x80);
  1.1462-				tim += a < 0 ? 4 : 14;
  1.1463-				break;
  1.1464-			} /* TST */
  1.1465-			a = amode(op >> 3, op, s);
  1.1466-			nz(rmode(a, s), s);
  1.1467-			tim += 4;
  1.1468-			break;
  1.1469-		case 14:
  1.1470-			v = op >> 4 & 0xf;
  1.1471-			n = op & 7;
  1.1472-			if(v == 4){ /* TRAP */
  1.1473-				trap(0x20 | op & 0xf, pc);
  1.1474-				break;
  1.1475-			}else if(v == 5){
  1.1476-				if((op & 8) == 0){ /* LINK */
  1.1477-					push32(ra[n]);
  1.1478-					ra[n] = ra[7];
  1.1479-					ra[7] += (s16int)fetch16();
  1.1480-					tim += 16;
  1.1481-				}else{ /* UNLK */
  1.1482-					ra[7] = ra[n];
  1.1483-					ra[n] = pop32();
  1.1484-					tim += 12;
  1.1485+			case 8:
  1.1486+				switch(s){
  1.1487+				case 0: op_nbcd(op); break;
  1.1488+				case 1:
  1.1489+					if((op >> 3 & 7) != 0)
  1.1490+						op_pea(op);
  1.1491+					else
  1.1492+						op_swap(op);
  1.1493+					break;
  1.1494+				case 2: op_ext_b(op); break;
  1.1495+				case 3: op_ext_w(op); break;
  1.1496 				}
  1.1497 				break;
  1.1498-			}else if(v == 6){ /* MOVE USP */
  1.1499-				if((rS & FLAGS) != 0){
  1.1500-					if((op & 8) != 0)
  1.1501-						ra[n] = asp;
  1.1502-					else
  1.1503-						asp = ra[n];
  1.1504-					tim += 4;
  1.1505-				}else
  1.1506-					trap(8, curpc);
  1.1507-				break;
  1.1508-			}
  1.1509-			if((op & 0xc0) == 0xc0){ /* JMP */
  1.1510-				pc = amode(op >> 3, op, 2);
  1.1511-				tim += 4;
  1.1512-				break;
  1.1513-			}
  1.1514-			if((op & 0xc0) == 0x80){ /* JSR */
  1.1515-				a = amode(op >> 3, op, 2);
  1.1516-				push32(pc);
  1.1517-				pc = a;
  1.1518-				tim += 12;
  1.1519-				break;
  1.1520-			}
  1.1521-			switch(op){
  1.1522-			case 0x4e70: tim += 132; break; /* RESET */
  1.1523-			case 0x4e71: tim += 4; break; /* NOP */
  1.1524-			case 0x4e72: /* STOP */
  1.1525-				if((rS & FLAGS) != 0){
  1.1526-					rS = fetch16();
  1.1527-					stop = 1;
  1.1528-				}else
  1.1529-					trap(8, curpc);
  1.1530-				tim += 4;
  1.1531-				break;
  1.1532-			case 0x4e73: /* RTE */
  1.1533-				if((rS & FLAGS) != 0){
  1.1534-					v = rS;
  1.1535-					rS = pop16();
  1.1536-					pc = pop32();
  1.1537-					if(((v ^ rS) & FLAGS) != 0){
  1.1538-						v = asp;
  1.1539-						asp = ra[7];
  1.1540-						ra[7] = v;
  1.1541-					}
  1.1542-					tim += 20;
  1.1543-				}else
  1.1544-					trap(8, curpc);
  1.1545-				break;
  1.1546-			case 0x4e75: pc = pop32(); tim += 16; break; /* RTS */
  1.1547-			case 0x4e76: if((rS & FLAGV) != 0) trap(7, curpc); tim += 4; break; /* TRAPV */
  1.1548-			case 0x4e77: /* RTR */
  1.1549-				rS = rS & 0xff00 | pop16() & 0xff;
  1.1550-				pc = pop32();
  1.1551-				tim += 20;
  1.1552+			case 10:
  1.1553+				if(s == 3)
  1.1554+					op_tas(op);
  1.1555+				else
  1.1556+					op_tst(op);
  1.1557 				break;
  1.1558-			default: undef();
  1.1559-			}
  1.1560-			break;
  1.1561-		default:
  1.1562-			undef();
  1.1563-		}
  1.1564-		break;
  1.1565-	case 5:
  1.1566-		if((op & 0xf8) == 0xc8){ /* DBcc */
  1.1567-			n = op & 7;
  1.1568-			v = (s16int)fetch16();
  1.1569-			if(!cond((op >> 8) & 0xf)){
  1.1570-				if((u16int)r[n] != 0){
  1.1571-					r[n]--;
  1.1572-					pc = pc + v - 2;
  1.1573-					tim += 10;
  1.1574-				}else{
  1.1575-					r[n] |= 0xffff;
  1.1576-					tim += 14;
  1.1577+			case 14:
  1.1578+				switch(op >> 4 & 0xf){
  1.1579+				case 4: op_trap(op); break;
  1.1580+				case 5:
  1.1581+					if((op & 8) == 0)
  1.1582+						op_link(op);
  1.1583+					else
  1.1584+						op_unlk(op);
  1.1585+					break;
  1.1586+				case 6: op_move_usp(op); break;
  1.1587+				default:
  1.1588+					if((op & 0xc0) == 0xc0)
  1.1589+						op_jmp(op);
  1.1590+					else if((op & 0x80) == 0x80)
  1.1591+						op_jsr(op);
  1.1592+					else
  1.1593+						switch(op){
  1.1594+						case 0x4e70: op_reset(op); break;
  1.1595+						case 0x4e71: op_nop(op); break;
  1.1596+						case 0x4e72: op_stop(op); break;
  1.1597+						case 0x4e73: op_rte(op); break;
  1.1598+						case 0x4e75: op_rts(op); break;
  1.1599+						case 0x4e76: op_trapv(op); break;
  1.1600+						case 0x4e77: op_rtr(op); break;
  1.1601+						default: undef();
  1.1602+						}
  1.1603 				}
  1.1604-			}else
  1.1605-				tim += 12;
  1.1606-			break;
  1.1607-		}
  1.1608-		if(s == 3){ /* Scc */
  1.1609-			a = amode(op >> 3, op, 0);
  1.1610-			v = cond(op >> 8 & 0xf);
  1.1611-			wmode(a, 0, -v);
  1.1612-			if(a < 0)
  1.1613-				tim += 4 + 2 * v;
  1.1614-			else
  1.1615-				tim += 8;
  1.1616-			break;
  1.1617-		} /* ADDQ, SUBQ */
  1.1618-		rS |= FLAGZ;
  1.1619-		if((op & 0x38) == 0x08)
  1.1620-			s = 2;
  1.1621-		a = amode(op >> 3, op, s);
  1.1622-		v = rmode(a, s);
  1.1623-		if(n == 0)
  1.1624-			n = 8;
  1.1625-		if((op & 0x100) == 0)
  1.1626-			v = add(v, n, 0, s);
  1.1627-		else
  1.1628-			v = sub(v, n, 0, s);
  1.1629-		rS = rS & ~FLAGX | rS << 4 & FLAGX;
  1.1630-		if(a < 0)
  1.1631-			tim += s == 2 || (op & 0x130) == 0x110 ? 8 : 4;
  1.1632-		else
  1.1633-			tim += s == 2 ? 12 : 8;
  1.1634-		wmode(a, s, v);
  1.1635-		break;
  1.1636-	case 6: /* BRA */
  1.1637-		v = (s8int)op;
  1.1638-		if(v == 0)
  1.1639-			v = (s16int)fetch16();
  1.1640-		else if(v == (u32int)-1)
  1.1641-			v = fetch32();
  1.1642-		if((op & 0xf00) == 0x100){ /* BSR */
  1.1643-			push32(pc);
  1.1644-			pc = curpc + 2 + v;
  1.1645-			tim += 18;
  1.1646-			break;
  1.1647-		}
  1.1648-		if(cond((op >> 8) & 0xf)){
  1.1649-			pc = curpc + 2 + v;
  1.1650-			tim += 10;
  1.1651-		}else
  1.1652-			tim += (u8int)(op + 1) <= 1 ? 12 : 8;
  1.1653-		break;
  1.1654-	case 7: /* MOVEQ */
  1.1655-		r[n] = (s8int)op;
  1.1656-		nz(r[n], 0);
  1.1657-		tim += 4;
  1.1658-		break;
  1.1659-	case 8:
  1.1660-		if(s == 3){ /* DIVU, DIVS */
  1.1661-			a = amode(op >> 3, op, 1);
  1.1662-			v = rmode(a, 1);
  1.1663-			if(v == 0){
  1.1664-				trap(5, curpc);
  1.1665+				break;
  1.1666+			default:
  1.1667+				undef();
  1.1668 				break;
  1.1669 			}
  1.1670-			if((op & 0x100) != 0){
  1.1671-				w = (s32int)r[n] % (s16int)v;
  1.1672-				v = (s32int)r[n] / (s16int)v;
  1.1673-				if(((s16int)w ^ (s16int)v) < 0)
  1.1674-					w = -w;
  1.1675-				if(v != (u32int)(s16int)v){
  1.1676-					rS = rS & ~FLAGC | FLAGV;
  1.1677-					break;
  1.1678-				}
  1.1679-				tim += 158;
  1.1680-			}else{
  1.1681-				w = r[n] % (u16int)v;
  1.1682-				v = r[n] / (u16int)v;
  1.1683-				if(v >= 0x10000){
  1.1684-					rS = rS & ~FLAGC | FLAGV;
  1.1685-					break;
  1.1686-				}
  1.1687-				tim += 140;
  1.1688-			}
  1.1689-			r[n] = (u16int)v | w << 16;
  1.1690-			nz(v, 1);
  1.1691-			break;
  1.1692-		}
  1.1693-		if((op & 0x1f0) == 0x100){ /* SBCD */
  1.1694-			n = (op >> 9) & 7;
  1.1695-			m = op & 7;
  1.1696-			if((op & 8) != 0){
  1.1697-				a = amode(4, n, 0);
  1.1698-				v = rmode(a, 0);
  1.1699-				w = rmode(amode(4, m, 0), 0);
  1.1700-				v = subbcd(v, w);
  1.1701-				wmode(a, 0, v);
  1.1702-				tim += 18;
  1.1703-			}else{
  1.1704-				r[n] = r[n] & 0xffffff00 | subbcd((u8int)r[n], (u8int)r[m]);
  1.1705-				tim += 6;
  1.1706-			}
  1.1707-			break;
  1.1708-		}
  1.1709-	logic: /* OR, EOR, AND */
  1.1710-		a = amode(op >> 3, op, s);
  1.1711-		n = (op >> 9) & 7;
  1.1712-		v = rmode(a, s);
  1.1713-		switch(op >> 12){
  1.1714-		case 8: v |= r[n]; break;
  1.1715-		case 11: v ^= r[n]; break;
  1.1716-		case 12: v &= r[n]; break;
  1.1717-		}
  1.1718-		if((op & 0x100) == 0)
  1.1719-			a = ~n;
  1.1720-		wmode(a, s, v);
  1.1721-		nz(v, s);
  1.1722-		dtime(op, s);
  1.1723+		break;
  1.1724+	case 5:
  1.1725+		if((op & 0xf8) == 0xc8)
  1.1726+			op_dbcc(op);
  1.1727+		else if(s == 3)
  1.1728+			op_scc(op);
  1.1729+		else if((op & 070) == 010)
  1.1730+			op_addq_subq_a(op);
  1.1731+		else
  1.1732+			op_addq_subq(op);
  1.1733+		break;
  1.1734+	case 6:
  1.1735+		op_bra(op);
  1.1736+		break;
  1.1737+	case 7:
  1.1738+		op_moveq(op);
  1.1739+		break;
  1.1740+	case 8:
  1.1741+		if(s == 3)
  1.1742+			op_divu_divs(op);
  1.1743+		else if((op & 0x1f0) == 0x100)
  1.1744+			op_sbcd(op);
  1.1745+		else
  1.1746+			logic(op);
  1.1747 		break;
  1.1748 	case 11:
  1.1749-		if(s == 3){ /* CMPA */
  1.1750-			s = (op >> 8 & 1) + 1;
  1.1751-			a = amode(op >> 3, op, s);
  1.1752-			rS |= FLAGZ;
  1.1753-			sub(ra[n], rmode(a, s), 0, 2);
  1.1754-			tim += 6;
  1.1755-			break;
  1.1756-		}
  1.1757-		if((op & 0x138) == 0x108){ /* CMPM */
  1.1758-			m = op & 7;
  1.1759-			rS |= FLAGZ;
  1.1760-			sub(rmode(amode(3, n, s), s), rmode(amode(3, m, s), s), 0, s);
  1.1761-			tim += s == 2 ? 20 : 12;
  1.1762-			break;
  1.1763-		}
  1.1764-		if((op & 0x100) == 0){ /* CMP */
  1.1765-			a = amode(op >> 3, op, s);
  1.1766-			rS |= FLAGZ;
  1.1767-			sub(r[n], rmode(a, s), 0, s);
  1.1768-			tim += s == 2 ? 6 : 4;
  1.1769-			break;
  1.1770-		}
  1.1771-		goto logic;
  1.1772+		if(s == 3)
  1.1773+			op_cmpa(op);
  1.1774+		else if((op & 0x138) == 0x108)
  1.1775+			op_cmpm(op);
  1.1776+		else if((op & 0x100) == 0)
  1.1777+			op_cmp(op);
  1.1778+		else
  1.1779+			logic(op);
  1.1780+		break;
  1.1781 	case 12:
  1.1782-		if(s == 3){ /* MULU, MULS */
  1.1783-			a = amode(op >> 3, op, 1);
  1.1784-			v = rmode(a, 1);
  1.1785-			if((op & 0x100) != 0)
  1.1786-				v *= (s16int)r[n];
  1.1787-			else
  1.1788-				v = (u16int)v * (u16int)r[n];
  1.1789-			r[n] = v;
  1.1790-			nz(v, 1);
  1.1791-			tim += 70;
  1.1792-			break;
  1.1793-		}
  1.1794-		if((op & 0x1f0) == 0x100){ /* ABCD */
  1.1795-			n = (op >> 9) & 7;
  1.1796-			m = op & 7;
  1.1797-			if((op & 8) != 0){
  1.1798-				a = amode(4, n, 0);
  1.1799-				v = rmode(a, 0);
  1.1800-				w = rmode(amode(4, m, 0), 0);
  1.1801-				v = addbcd(v, w);
  1.1802-				wmode(a, 0, v);
  1.1803-				tim += 18;
  1.1804-			}else{
  1.1805-				r[n] = r[n] & 0xffffff00 | addbcd((u8int)r[n], (u8int)r[m]);
  1.1806-				tim += 6;
  1.1807-			}
  1.1808-			break;
  1.1809-		
  1.1810-		}
  1.1811-		if((op & 0x130) == 0x100){ /* EXG */
  1.1812-			m = op & 0xf;
  1.1813-			if((op & 0xc8) == 0x48)
  1.1814-				n |= 8;
  1.1815-			v = r[n];
  1.1816-			r[n] = r[m];
  1.1817-			r[m] = v;
  1.1818-			tim += 6;
  1.1819-			break;
  1.1820-		}
  1.1821-		goto logic;
  1.1822+		if(s == 3)
  1.1823+			op_mulu_muls(op);
  1.1824+		else if((op & 0x1f0) == 0x100)
  1.1825+			op_abcd(op);
  1.1826+		else if((op & 0x130) == 0x100)
  1.1827+			op_exg(op);
  1.1828+		else
  1.1829+			logic(op);
  1.1830+		break;
  1.1831 	case 9:
  1.1832 	case 13:
  1.1833-		if(s == 3){ /* ADDA, SUBA */
  1.1834-			if((op & 0x100) != 0){
  1.1835-				s = 2;
  1.1836-				tim += 6;
  1.1837-			}else{
  1.1838-				s = 1;
  1.1839-				tim += 8;
  1.1840-			}
  1.1841-			a = amode(op >> 3, op, s);
  1.1842-			if((op >> 12) == 13)
  1.1843-				ra[n] += rmode(a, s);
  1.1844-			else
  1.1845-				ra[n] -= rmode(a, s);
  1.1846-			break;
  1.1847-		}
  1.1848-		if((op & 0x130) == 0x100){ /* ADDX, SUBX */
  1.1849-			m = op & 7;
  1.1850-			if((op & 8) != 0){
  1.1851-				a = ra[n] -= 1<<s;
  1.1852-				v = rmode(a, s);
  1.1853-				w = rmode(ra[m] -= 1<<s, s);
  1.1854-				tim += s == 2 ? 30 : 18;
  1.1855-			}else{
  1.1856-				v = r[n];
  1.1857-				w = r[m];
  1.1858-				a = ~n;
  1.1859-				tim += s == 2 ? 8 : 4;
  1.1860-			}
  1.1861-			if((op >> 12) == 13)
  1.1862-				v = add(v, w, (rS & FLAGX) != 0, s);
  1.1863-			else
  1.1864-				v = sub(v, w, (rS & FLAGX) != 0, s);
  1.1865-			wmode(a, s, v);
  1.1866-			rS = rS & ~FLAGX | rS << 4 & FLAGX;
  1.1867-			break;
  1.1868-		} /* ADD, SUB */
  1.1869-		a = amode(op >> 3, op, s);
  1.1870-		rS |= FLAGZ;
  1.1871-		d = (op & 0x100) == 0;
  1.1872-		v = rmode(a, s);
  1.1873-		if((op >> 12) == 13)
  1.1874-			v = add(v, r[n], 0, s);
  1.1875+		if(s == 3)
  1.1876+			op_adda_suba(op);
  1.1877+		else if((op & 0x130) == 0x100)
  1.1878+			op_addx_subx(op);
  1.1879 		else
  1.1880-			v = sub(d ? r[n] : v, d ? v : r[n], 0, s);
  1.1881-		rS = rS & ~FLAGX | rS << 4 & FLAGX;
  1.1882-		if(d)
  1.1883-			a = ~n;
  1.1884-		wmode(a, s, v);
  1.1885-		dtime(op, s);
  1.1886+			op_add_sub(op);
  1.1887 		break;
  1.1888-	case 14: /* shifts */
  1.1889-		if(s == 3){
  1.1890-			m = op >> 8 & 7;
  1.1891-			n = 1;
  1.1892-			s = 1;
  1.1893-			a = amode(op >> 3, op, s);
  1.1894-		}else{
  1.1895-			a = ~(uvlong)(op & 7);
  1.1896-			m = op >> 2 & 6 | op >> 8 & 1;
  1.1897-			n = (op >> 9) & 7;
  1.1898-			if((op & 0x20) != 0)
  1.1899-				n = r[n] & 63;
  1.1900-			else if(n == 0)
  1.1901-				n = 8;
  1.1902-		}
  1.1903-		wmode(a, s, rot(rmode(a, s), m, n, s));
  1.1904+	case 14:
  1.1905+		shifts(op);
  1.1906 		break;
  1.1907 	case 10:
  1.1908 		trap(10, curpc);