# this UNOFFICIAL patch lets you use x128's OPL2-ish adlib sound support on
# Linux even if you have a OPL3 soundcard like an SB16.
# Drawback is that the mode isn't reset after, so you're stuck with OPL2
# mode until reboot. If you use the FM stuff for other things, like
# playmidi etc., this may be bad news. But hey, it doesn't bother me... :-)
# check the comment in the code below for details.
#
# the patch is relative to x128 v0.5. And in case the author of x128
# wants to use this or something, this patch is hereby public domain,
# blah blah blah. Do what you want with it.
#
# NB: after some experimentation with this, it doesn't sound quite
# right. I don't know if this is simply inaccurate emulation, or what.
# But it's definitely better than nothing; in particular, Rainbow
# Islands sounds great.
#
# - Russell Marks.
#
# (No email addr; see ZCN in ftp.nvg.unit.no:/pub/cpc/nc100 for snail
# address. It's at the end of doc/zcn.txt in the zip.)
#
diff -u orig/ay8910.c x128/ay8910.c
--- orig/ay8910.c	Mon Jul  1 22:12:10 1996
+++ x128/ay8910.c	Sat Dec  7 08:53:06 1996
@@ -82,6 +82,7 @@
 UC InitAdlib(void)
 {
   UC I,A1,A2;
+  int J;
 
   /* If Adlib is not to be used, don't initialize */
   if(!UseAdlib) return(0);
@@ -99,6 +100,16 @@
   PutAdlib(0x04,0x80);    /* Reset timers            */
   if((A2!=0xC0)||A1) { UseAdlib=0;return(0); }
   /***************************************************/
+
+  /* disable OPL3/4 mode...
+   * (re-enabling again is probably tricky to say the least,
+   * so note that this will lose you OPL3/4 capability until reboot!
+   * i.e. `playmidi' etc. will sound really strange)
+   * FWIW, repeating this with the value as 0x03 rather than 0x00
+   * *should* reset things. But frankly, I'm not sure.
+   */
+  outp(0x38A,0x05);for(J=0;J<6;J++) inp(0x388);
+  outp(0x38B,0x00);for(J=0;J<35;J++) inp(0x388);
 
   /* Allow the FM chips to control WaveForm */
   for(I=0;I<255;I++) PutAdlib(I,0x00);
diff -u orig/x128_t.c x128/x128_t.c
--- orig/x128_t.c	Mon Jul  1 22:12:10 1996
+++ x128/x128_t.c	Sat Dec  7 08:30:42 1996
@@ -679,7 +679,7 @@
   {
 	printf("Can't open PC internal speaker i/o port.\n");
   }
-  if(ioperm(0x388,2,1))
+  if(ioperm(0x388,4,1))
   {
 	printf("Can't open adlib i/o ports.\n");
 	UseAdlib=adlib_present=0;
