FDS fixed for asm core
[fceu.git] / fds.c
diff --git a/fds.c b/fds.c
index f0640a0..41b3a5d 100644 (file)
--- a/fds.c
+++ b/fds.c
@@ -144,6 +144,17 @@ static void FDSInit(void)
  FDSSoundReset();\r
  InDisk=0;\r
  SelectDisk=0;\r
+\r
+#ifdef ASM_6502\r
+ {\r
+  int page;\r
+  // asm code needs pages to be set again..\r
+  for (page=12; page<28; page++) // 0x6000-0xdfff 32K RAM\r
+   Page[page]=FDSRAM  - (page<<11) + ((page-12)<<11);\r
+  for (; page<32; page++)        // 0xe000-0xffff 8K BIOS\r
+   Page[page]=FDSBIOS - (page<<11) + ((page-28)<<11);\r
+ }\r
+#endif\r
 }\r
 \r
 void FCEU_FDSInsert(void)\r
@@ -188,7 +199,7 @@ void FCEU_FDSSelect(void)
 \r
 static void FP_FASTAPASS(1) FDSFix(int a)\r
 {\r
- if((IRQa&2) && IRQCount)\r
+ if(IRQCount && (IRQa&2))\r
  {\r
   IRQCount-=a;\r
   if(IRQCount<=0)\r
@@ -224,8 +235,13 @@ static DECLFR(FDSRead4030)
        uint8 ret=0;\r
 \r
        /* Cheap hack. */\r
+#ifndef ASM_6502\r
        if(X.IRQlow&FCEU_IQEXT) ret|=1;\r
        if(X.IRQlow&FCEU_IQEXT2) ret|=2;\r
+#else\r
+       if((nes_registers[4]>>8)&FCEU_IQEXT) ret|=1;\r
+       if((nes_registers[4]>>8)&FCEU_IQEXT2) ret|=2;\r
+#endif\r
 \r
        if(!fceuindbg)\r
        {\r
@@ -485,7 +501,7 @@ static INLINE void ClockFall(void)
  clockcount=(clockcount+1)&7;\r
 }\r
 \r
-static INLINE int32 FDSDoSound(void)\r
+static INLINE int32 FDSDoSound(int32 mul)\r
 {\r
  fdso.count+=fdso.cycles;\r
  if(fdso.count>=((int64)1<<40))\r
@@ -504,11 +520,14 @@ static INLINE int32 FDSDoSound(void)
  if(fdso.count>=32768) goto dogk;\r
 \r
  // Might need to emulate applying the amplitude to the waveform a bit better...\r
+/*\r
  {\r
   int k=amplitude[0];\r
   if(k>0x20) k=0x20;\r
   return (fdso.cwave[b24latch68>>19]*k)*4/((SPSG[0x9]&0x3)+2);\r
  }\r
+*/\r
+ return (fdso.cwave[b24latch68>>19]*mul)>>16;\r
 }\r
 \r
 static int32 FBC=0;\r
@@ -517,6 +536,7 @@ static void RenderSound(void)
 {\r
  int32 end, start;\r
  int32 x;\r
+ int32 mul;\r
 \r
  start=FBC;\r
  end=(SOUNDTS<<16)/soundtsinc;\r
@@ -524,10 +544,27 @@ static void RenderSound(void)
   return;\r
  FBC=end;\r
 \r
+ // hack for performance, might produce bad results..\r
+ if (!amplitude[0])\r
+  return;\r
+\r
+ switch (SPSG[0x9]&0x3)\r
+ {\r
+  default:mul = (4<<16)/2;\r
+  case 1: mul = (4<<16)/3;\r
+  case 2: mul = (4<<16)/4;\r
+  case 3: mul = (4<<16)/5;\r
+ }\r
+ {\r
+  int k=amplitude[0];\r
+  if(k>0x20) k=0x20;\r
+  mul *= k;\r
+ }\r
+\r
  if(!(SPSG[0x9]&0x80))\r
   for(x=start;x<end;x++)\r
   {\r
-   uint32 t=FDSDoSound();\r
+   uint32 t=FDSDoSound(mul);\r
    t+=t>>1;\r
    t>>=4;\r
    Wave[x>>4]+=t; //(t>>2)-(t>>3); //>>3;\r