]> Shamusworld >> Repos - virtualjaguar/blobdiff - src/jerry.cpp
Initial fixes for audio subsystem. Fragile; may break in unexpected ways.
[virtualjaguar] / src / jerry.cpp
index 2212cf285b8b4914567691817ba967e6ee3d9cdb..cba9571c808a666326dc71e58dab7e7a383767ed 100644 (file)
@@ -3,9 +3,9 @@
 //
 // Originally by David Raingeard
 // GCC/SDL port by Niels Wagenaar (Linux/WIN32) and Carwin Jones (BeOS)
-// Cleanups/rewrites/fixes by James L. Hammons
+// Cleanups/rewrites/fixes by James Hammons
 //
-// JLH = James L. Hammons
+// JLH = James Hammons <jlhamm@acm.org>
 //
 // WHO  WHEN        WHAT
 // ---  ----------  -----------------------------------------------------------
 #include "joystick.h"
 #include "log.h"
 #include "m68k.h"
+#include "settings.h"
+#include "tom.h"
 //#include "memory.h"
 #include "wavetable.h"
 
@@ -352,16 +354,24 @@ void JERRYResetPIT2(void)
 #endif
 }
 
+// This is the cause of the regressions in Cybermorph and Missile Command 3D...
+// Solution: Probably have to check the DSP enable bit before sending these thru.
+//#define JERRY_NO_IRQS
 void JERRYPIT1Callback(void)
 {
+#ifndef JERRY_NO_IRQS
 //WriteLog("JERRY: In PIT1 callback, IRQM=$%04X\n", jerryInterruptMask);
-       if (jerryInterruptMask & IRQ2_TIMER1)           // CPU Timer 1 IRQ
+       if (TOMIRQEnabled(IRQ_DSP))
        {
+               if (jerryInterruptMask & IRQ2_TIMER1)           // CPU Timer 1 IRQ
+               {
 // Not sure, but I think we don't generate another IRQ if one's already going...
 // But this seems to work... :-/
-               jerryPendingInterrupt |= IRQ2_TIMER1;
-               m68k_set_irq(2);                                                // Generate 68K IPL 2
+                       jerryPendingInterrupt |= IRQ2_TIMER1;
+                       m68k_set_irq(2);                                                // Generate 68K IPL 2
+               }
        }
+#endif
 
        DSPSetIRQLine(DSPIRQ_TIMER0, ASSERT_LINE);      // This does the 'IRQ enabled' checking...
        JERRYResetPIT1();
@@ -369,12 +379,17 @@ void JERRYPIT1Callback(void)
 
 void JERRYPIT2Callback(void)
 {
-//WriteLog("JERRY: In PIT2 callback, IRQM=$%04X\n", jerryInterruptMask);
-       if (jerryInterruptMask & IRQ2_TIMER2)           // CPU Timer 2 IRQ
+#ifndef JERRY_NO_IRQS
+       if (TOMIRQEnabled(IRQ_DSP))
        {
-               jerryPendingInterrupt |= IRQ2_TIMER2;
-               m68k_set_irq(2);                                                // Generate 68K IPL 2
+//WriteLog("JERRY: In PIT2 callback, IRQM=$%04X\n", jerryInterruptMask);
+               if (jerryInterruptMask & IRQ2_TIMER2)           // CPU Timer 2 IRQ
+               {
+                       jerryPendingInterrupt |= IRQ2_TIMER2;
+                       m68k_set_irq(2);                                                // Generate 68K IPL 2
+               }
        }
+#endif
 
        DSPSetIRQLine(DSPIRQ_TIMER1, ASSERT_LINE);      // This does the 'IRQ enabled' checking...
        JERRYResetPIT2();
@@ -441,13 +456,8 @@ void JERRYI2SCallback(void)
 
 void JERRYInit(void)
 {
-//     clock_init();
-//     anajoy_init();
        JoystickInit();
        DACInit();
-//This should be handled with the cart initialization...
-//     eeprom_init();
-//     memory_malloc_secure((void **)&jerry_ram_8, 0x10000, "JERRY RAM/ROM");
        memcpy(&jerry_ram_8[0xD000], waveTableROM, 0x1000);
 
        JERRYPIT1Prescaler = 0xFFFF;
@@ -460,8 +470,6 @@ void JERRYInit(void)
 
 void JERRYReset(void)
 {
-//     clock_reset();
-//     anajoy_reset();
        JoystickReset();
        EepromReset();
        JERRYResetI2S();
@@ -481,9 +489,6 @@ void JERRYReset(void)
 void JERRYDone(void)
 {
        WriteLog("JERRY: M68K Interrupt control ($F10020) = %04X\n", GET16(jerry_ram_8, 0x20));
-//     memory_free(jerry_ram_8);
-//     clock_done();
-//     anajoy_done();
        JoystickDone();
        DACDone();
        EepromDone();
@@ -805,6 +810,10 @@ else if (offset == 0xF10012)
        WriteLog("JERRY: CLK2 word written by %s: %u\n", whoName[who], data);
 else if (offset == 0xF10014)
        WriteLog("JERRY: CLK3 word written by %s: %u\n", whoName[who], data);
+//else if (offset == 0xF1A100)
+//     WriteLog("JERRY: D_FLAGS word written by %s: %u\n", whoName[who], data);
+//else if (offset == 0xF1A102)
+//     WriteLog("JERRY: D_FLAGS+2 word written by %s: %u\n", whoName[who], data);
 //else if (offset == 0xF10020)
 //     WriteLog("JERRY: JINTCTRL word written by %s: $%04X\n", whoName[who], data);
 #endif
@@ -822,7 +831,7 @@ else if (offset == 0xF10014)
 //NOTE: This should be taken care of in DAC...
        else if (offset == 0xF1A152)                                    // Bottom half of SCLK ($F1A150)
        {
-               WriteLog("JERRY: Writing %04X to SCLK (by %s)...\n", data, whoName[who]);
+               WriteLog("JERRY: Writing $%X to SCLK (by %s)...\n", data, whoName[who]);
 //This should *only* be enabled when SMODE has its INTERNAL bit set! !!! FIX !!!
                JERRYI2SInterruptDivide = (uint8)data;
                JERRYI2SInterruptTimer = -1;
@@ -909,3 +918,15 @@ WriteLog("JERRY: Unhandled timer write %04X (WORD) at %08X by %s...\n", data, of
        jerry_ram_8[(offset+0) & 0xFFFF] = (data >> 8) & 0xFF;
        jerry_ram_8[(offset+1) & 0xFFFF] = data & 0xFF;
 }
+
+int JERRYGetPIT1Frequency(void)
+{
+       int systemClockFrequency = (vjs.hardwareTypeNTSC ? RISC_CLOCK_RATE_NTSC : RISC_CLOCK_RATE_PAL);
+       return systemClockFrequency / ((JERRYPIT1Prescaler + 1) * (JERRYPIT1Divider + 1));
+}
+
+int JERRYGetPIT2Frequency(void)
+{
+       int systemClockFrequency = (vjs.hardwareTypeNTSC ? RISC_CLOCK_RATE_NTSC : RISC_CLOCK_RATE_PAL);
+       return systemClockFrequency / ((JERRYPIT2Prescaler + 1) * (JERRYPIT2Divider + 1));
+}