Index: ram/dopatch.c
===================================================================
--- ram/dopatch.c	(revision 8c8b4e5664e0c1a049b4575d5003752b342481d6)
+++ ram/dopatch.c	(revision 6099cacb5e0cb602156d4647cb268ee3302d40a5)
@@ -29,5 +29,5 @@
 int16_t	lg2base[7] = { 0, 3, 7, 10, 14, 17, 21};	/* LED group bases */
 
-int8_t	vgtype[] = {
+uint8_t	vgtype[] = {
 
 	ST_NUL,		/* PA_NULL */
@@ -76,5 +76,5 @@
 	if (slot) {		/* waveshape slot B */
 
-		vbufs[voice].idhwsb = wsn;
+		vbufs[voice].idhwsb = (int8_t)wsn;
 
 		memcpyw(vbufs[voice].idhwvbf, &wslib[wsn],
@@ -85,10 +85,10 @@
 		memcpyw(fpuws, vbufs[voice].idhwvbf, NUMWPNT);
 
-		*(fpuws - 1) = vbufs[voice].idhwvbf[0];
-		*(fpuws + NUMWPNT) = vbufs[voice].idhwvbf[NUMWPNT - 1];
+		*(fpuws - 1) = (uint16_t)vbufs[voice].idhwvbf[0];
+		*(fpuws + NUMWPNT) = (uint16_t)vbufs[voice].idhwvbf[NUMWPNT - 1];
 
 	} else {		/* waveshape slot A */
 
-		vbufs[voice].idhwsa = wsn;
+		vbufs[voice].idhwsa = (int8_t)wsn;
 
 		memcpyw(vbufs[voice].idhwvaf, &wslib[wsn],
@@ -99,6 +99,6 @@
 		memcpyw(fpuws, vbufs[curvce].idhwvaf, NUMWPNT);
 
-		*(fpuws - 1) = vbufs[voice].idhwvaf[0];
-		*(fpuws + NUMWPNT) = vbufs[voice].idhwvaf[NUMWPNT - 1];
+		*(fpuws - 1) = (uint16_t)vbufs[voice].idhwvaf[0];
+		*(fpuws + NUMWPNT) = (uint16_t)vbufs[voice].idhwvaf[NUMWPNT - 1];
 
 	}
@@ -111,5 +111,5 @@
 */
 
-void pfpufn(uint16_t voice, uint16_t par, uint16_t dat1, uint16_t dat2)
+void pfpufn(int16_t voice, int16_t par, uint16_t dat1, uint16_t dat2)
 {
 	volatile uint16_t *fpu;
@@ -125,15 +125,15 @@
 	case PSA_MLT:		/* multiplier */
 
-		*(fpu + (int32_t)FPU_TSF1) = dat2;
+		*(fpu + FPU_TSF1) = dat2;
 		break;
 
 	case PSA_TIM:		/* time */
 
-		*(fpu + (int32_t)FPU_TMNT) = (((int32_t)dat2 & 0x0000FFF0L)
-			* ((int32_t)timemlt & 0x0000FFFFL)) >> 15;
+		*(fpu + FPU_TMNT) = (uint16_t)(((uint32_t)(dat2 & 0xFFF0)
+			* (uint32_t)timemlt) >> 15);
 
 		++delay;
 
-		*(fpu + (int32_t)FPU_TEXP) = expbit[dat2 & 0x000F];
+		*(fpu + FPU_TEXP) = expbit[dat2 & 0x000F];
 
 		break;
@@ -141,5 +141,5 @@
 	case PSA_VAL:		/* value */
 
-		sendval(voice, par, dat2);
+		sendval(voice, par, (int16_t)dat2);
 		break;
 
@@ -179,5 +179,6 @@
 	volatile uint8_t *ser;
 	int8_t *iorec;
-	uint16_t chan, oldsr, osc, port, spec, sat,trig, vgr, vgn, vgt;
+	uint16_t oldsr;
+	int16_t chan, osc, port, spec, sat, trig, vgr, vgn, vgt;
 	int16_t baseled, curled, ledctl;
 
@@ -191,6 +192,6 @@
 	if (ST_VGT & sat) {		/* vg, osc sub-address types */
 
-		vgr  = 0x00FF & (suba >>  8);		/* voice / group */
-		osc  = 0x00FF &  suba;			/* oscillator */
+		vgr  = (int16_t)(0x00FF & (suba >> 8));		/* voice / group */
+		osc  = (int16_t)(0x00FF &  suba);		/* oscillator */
 
 		if (vgr > 11) {		/* sort out voices from groups */
@@ -235,5 +236,5 @@
 			putwq(&ptefifo, suba);		/* closure */
 
-		seqdupd |= (1 << trig);
+		seqdupd |= ((uint16_t)1 << trig);
 		break;
 
@@ -259,16 +260,16 @@
 		case 0:				/* transient */
 
-			*ser = temp | 0x0082;			/* on */
-			*ser = (temp & 0x00FD) | 0x0080;	/* off */
+			*ser = (uint8_t)(temp | 0x0082);		/* on */
+			*ser = (uint8_t)((temp & 0x00FD) | 0x0080);	/* off */
 			break;
 
 		case 1:				/* off */
 
-			*ser = (temp & 0x00FD) | 0x0080;	/* off */
+			*ser = (uint8_t)((temp & 0x00FD) | 0x0080);	/* off */
 			break;
 
 		case 2:				/* on */
 
-			*ser = temp | 0x0082;			/* on */
+			*ser = (uint8_t)(temp | 0x0082);		/* on */
 			break;
 		}
@@ -290,10 +291,10 @@
 
 				ledstat[curled] = TRUE;
-				io_leds = curled;
+				io_leds = (uint8_t)curled;
 
 			} else if (ledctl EQ 2) {		/* off */
 
 				ledstat[curled] = FALSE;
-				io_leds = curled | 0x0080;
+				io_leds = (uint8_t)(curled | 0x0080);
 
 			} else if (ledctl EQ 3) {		/* toggle */
@@ -302,10 +303,10 @@
 
 					ledstat[curled] = FALSE;
-					io_leds = curled | 0x0080;
+					io_leds = (uint8_t)(curled | 0x0080);
 
 				} else {			/* off -> on */
 
 					ledstat[curled] = TRUE;
-					io_leds = curled;
+					io_leds = (uint8_t)curled;
 				}
 			}
@@ -317,5 +318,5 @@
 
 		seqline[suba] = dat1;
-		seqdupd |= (1 << suba);
+		seqdupd |= ((uint16_t)1 << suba);
 		break;
 
@@ -347,10 +348,10 @@
 		}
 
-		seqdupd |= (1 << suba);
+		seqdupd |= ((uint16_t)1 << suba);
 		break;
 
 	case PA_TUNE:		/* tuning table */
 
-		gettun(dat1);
+		gettun((int16_t)dat1);
 		break;
 
@@ -358,10 +359,10 @@
 
 		sregval[suba] = dat1 ? sregval[dat2] : dat2;
-		seqdupd |= (1 << suba);
+		seqdupd |= ((uint16_t)1 << suba);
 		break;
 
 	case PA_RADD:		/* regsister add */
 
-		temp = sregval[suba] + (dat1 ? sregval[dat2] : dat2);
+		temp = (int16_t)(sregval[suba] + (dat1 ? sregval[dat2] : dat2));
 
 		if (temp > 99)
@@ -370,6 +371,6 @@
 			temp = 0;
 
-		sregval[suba] = temp;
-		seqdupd |= (1 << suba);
+		sregval[suba] = (uint16_t)temp;
+		seqdupd |= ((uint16_t)1 << suba);
 		break;
 
@@ -378,5 +379,5 @@
 		if (vgt) {	/* group */
 
-			ins2grp[vgn] = (ins2grp[vgn] & 0xFF00) | dat1;
+			ins2grp[vgn] = (ins2grp[vgn] & (int16_t)0xFF00) | (int16_t)dat1;
 			setv2gi(vgn);
 
@@ -384,8 +385,8 @@
 
 			if (curvce EQ vgn)
-				curinst = dat1;
-
-			s_inst[vgn] = dat1;
-			execins(vgn, dat1, 1);
+				curinst = (int16_t)dat1;
+
+			s_inst[vgn] = (int16_t)dat1;
+			execins(vgn, (int16_t)dat1, 1);
 		}
 
@@ -398,9 +399,9 @@
 			for (i = 0; i < 12; i++)
 				if (vce2grp[i] EQ (1 + vgn))
-					pdoctl(i, osc, dat1, dat2);
+					pdoctl(i, osc, (int16_t)dat1, (int16_t)dat2);
 
 		} else {		/* voice */
 
-			pdoctl(vgn, osc, dat1, dat2);
+			pdoctl(vgn, osc, (int16_t)dat1, (int16_t)dat2);
 		}
 
@@ -413,9 +414,9 @@
 			for (i = 0; i < 12; i++)
 				if (vce2grp[i] EQ (1 + vgn))
-					pdows(0, i, dat1);
+					pdows(0, i, (int16_t)dat1);
 
 		} else {		/* voice */
 
-			pdows(0, vgn, dat1);
+			pdows(0, vgn, (int16_t)dat1);
 		}
 
@@ -428,9 +429,9 @@
 			for (i = 0; i < 12; i++)
 				if (vce2grp[i] EQ (1 + vgn))
-					pdows(1, i, dat1);
+					pdows(1, i, (int16_t)dat1);
 
 		} else {		/* voice */
 
-			pdows(1, vgn, dat1);
+			pdows(1, vgn, (int16_t)dat1);
 		}
 
@@ -444,10 +445,10 @@
 				if (vce2grp[i] EQ (1 + vgn)) {
 
-					vbufs[i].idhcfg = dat1;
+					vbufs[i].idhcfg = (int8_t)dat1;
 					dosync(i);
 				}
 		} else {
 
-			vbufs[vgn].idhcfg = dat1;
+			vbufs[vgn].idhcfg = (int8_t)dat1;
 			dosync(vgn);
 		}
