X-Git-Url: http://shamusworld.gotdns.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=src%2Fjerry.cpp;h=e0255c49d394b071e5e290711a282d37a274996a;hb=69effddb777c2009d32f70e3315d5570973446ef;hp=671b08afdf2741458bf359dec086d345fc45ac3b;hpb=5da604521611a960140b58a2fb0f236c65610b70;p=virtualjaguar diff --git a/src/jerry.cpp b/src/jerry.cpp index 671b08a..e0255c4 100644 --- a/src/jerry.cpp +++ b/src/jerry.cpp @@ -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 // // WHO WHEN WHAT // --- ---------- ----------------------------------------------------------- @@ -163,30 +163,35 @@ #include "jaguar.h" #include "joystick.h" #include "log.h" +#include "m68000/m68kinterface.h" +#include "settings.h" +#include "tom.h" //#include "memory.h" #include "wavetable.h" //Note that 44100 Hz requires samples every 22.675737 usec. -#define NEW_TIMER_SYSTEM //#define JERRY_DEBUG -/*static*/ uint8 jerry_ram_8[0x10000]; +/*static*/ uint8_t jerry_ram_8[0x10000]; //#define JERRY_CONFIG 0x4002 // ??? What's this ??? -uint8 analog_x, analog_y; +uint8_t analog_x, analog_y; -static uint32 JERRYPIT1Prescaler; -static uint32 JERRYPIT1Divider; -static uint32 JERRYPIT2Prescaler; -static uint32 JERRYPIT2Divider; -static int32 jerry_timer_1_counter; -static int32 jerry_timer_2_counter; +static uint32_t JERRYPIT1Prescaler; +static uint32_t JERRYPIT1Divider; +static uint32_t JERRYPIT2Prescaler; +static uint32_t JERRYPIT2Divider; +static int32_t jerry_timer_1_counter; +static int32_t jerry_timer_2_counter; -uint32 JERRYI2SInterruptDivide = 8; -int32 JERRYI2SInterruptTimer = -1; -uint32 jerryI2SCycles; -uint32 jerryIntPending; +//uint32_t JERRYI2SInterruptDivide = 8; +int32_t JERRYI2SInterruptTimer = -1; +uint32_t jerryI2SCycles; +uint32_t jerryIntPending; + +static uint16_t jerryInterruptMask = 0; +static uint16_t jerryPendingInterrupt = 0; // Private function prototypes @@ -198,195 +203,109 @@ void JERRYPIT1Callback(void); void JERRYPIT2Callback(void); void JERRYI2SCallback(void); -//This approach is probably wrong, since the timer is continuously counting down, though -//it might only be a problem if the # of interrupts generated is greater than 1--the M68K's -//timeslice should be running during that phase... (The DSP needs to be aware of this!) - -//This is only used by the old system, so once the new timer system is working this -//should be safe to nuke. -void JERRYI2SExec(uint32 cycles) -{ -#ifndef NEW_TIMER_SYSTEM -#warning "externed var in source--should be in header file. !!! FIX !!!" - extern uint16 serialMode; // From DAC.CPP - if (serialMode & 0x01) // INTERNAL flag (JERRY is master) - { - - // Why is it called this? Instead of SCLK? Shouldn't this be read from DAC.CPP??? -//Yes, it should. !!! FIX !!! - JERRYI2SInterruptDivide &= 0xFF; - - if (JERRYI2SInterruptTimer == -1) - { - // We don't have to divide the RISC clock rate by this--the reason is a bit - // convoluted. Will put explanation here later... -// What's needed here is to find the ratio of the frequency to the number of clock cycles -// in one second. For example, if the sample rate is 44100, we divide the clock rate by -// this: 26590906 / 44100 = 602 cycles. -// Which means, every 602 cycles that go by we have to generate an interrupt. - jerryI2SCycles = 32 * (2 * (JERRYI2SInterruptDivide + 1)); - } - - JERYI2SInterruptTimer -= cycles; - if (JERRYI2SInterruptTimer <= 0) - { -//This is probably wrong as well (i.e., need to check enable lines)... !!! FIX !!! - DSPSetIRQLine(DSPIRQ_SSI, ASSERT_LINE); - JERRYI2SInterruptTimer += jerryI2SCycles; -#ifdef JERRY_DEBUG - if (JERRYI2SInterruptTimer < 0) - WriteLog("JERRY: Missed generating an interrupt (missed %u)!\n", (-JERRYI2SInterruptTimer / jerryI2SCycles) + 1); -#endif - } - } - else // JERRY is slave to external word clock - { - // This is just a temporary kludge to see if the CD bus mastering works - // I.e., this is totally faked...! -// The whole interrupt system is pretty much borked and is need of an overhaul. -// What we need is a way of handling these interrupts when they happen instead of -// scanline boundaries the way it is now. - JERRYI2SInterruptTimer -= cycles; - if (JERRYI2SInterruptTimer <= 0) - { -//This is probably wrong as well (i.e., need to check enable lines)... !!! FIX !!! [DONE] - if (ButchIsReadyToSend())//Not sure this is right spot to check... - { -// return GetWordFromButchSSI(offset, who); - SetSSIWordsXmittedFromButch(); - DSPSetIRQLine(DSPIRQ_SSI, ASSERT_LINE); - } - JERRYI2SInterruptTimer += 602; - } - } -#else - RemoveCallback(JERRYI2SCallback); - JERRYI2SCallback(); -#endif -} - -//NOTE: This is only used by the old execution core. Safe to nuke once it's stable. -void JERRYExecPIT(uint32 cycles) -{ -//This is wrong too: Counters are *always* spinning! !!! FIX !!! [DONE] -// if (jerry_timer_1_counter) - jerry_timer_1_counter -= cycles; - - if (jerry_timer_1_counter <= 0) - { -//Also, it can generate a CPU interrupt as well... !!! FIX !!! or does it? Maybe it goes Timer->GPU->CPU? - DSPSetIRQLine(DSPIRQ_TIMER0, ASSERT_LINE); // This does the 'IRQ enabled' checking... -// JERRYResetPIT1(); - jerry_timer_1_counter += (JERRYPIT1Prescaler + 1) * (JERRYPIT1Divider + 1); - } - -//This is wrong too: Counters are *always* spinning! !!! FIX !!! [DONE] -// if (jerry_timer_2_counter) - jerry_timer_2_counter -= cycles; - - if (jerry_timer_2_counter <= 0) - { -//Also, it can generate a CPU interrupt as well... !!! FIX !!! or does it? Maybe it goes Timer->GPU->CPU? - DSPSetIRQLine(DSPIRQ_TIMER1, ASSERT_LINE); // This does the 'IRQ enabled' checking... -// JERRYResetPIT2(); - jerry_timer_2_counter += (JERRYPIT2Prescaler + 1) * (JERRYPIT2Divider + 1); - } -} void JERRYResetI2S(void) { //WriteLog("i2s: reseting\n"); //This is really SCLK... !!! FIX !!! - JERRYI2SInterruptDivide = 8; + sclk = 8; JERRYI2SInterruptTimer = -1; } + void JERRYResetPIT1(void) { -#ifndef NEW_TIMER_SYSTEM -/* if (!JERRYPIT1Prescaler || !JERRYPIT1Divider) - jerry_timer_1_counter = 0; - else//*/ -//Small problem with this approach: Overflow if both are = $FFFF. !!! FIX !!! - jerry_timer_1_counter = (JERRYPIT1Prescaler + 1) * (JERRYPIT1Divider + 1); - -// if (jerry_timer_1_counter) -// WriteLog("jerry: reseting timer 1 to 0x%.8x (%i)\n",jerry_timer_1_counter,jerry_timer_1_counter); - -#else RemoveCallback(JERRYPIT1Callback); if (JERRYPIT1Prescaler | JERRYPIT1Divider) { double usecs = (float)(JERRYPIT1Prescaler + 1) * (float)(JERRYPIT1Divider + 1) * RISC_CYCLE_IN_USEC; - SetCallbackTime(JERRYPIT1Callback, usecs); + SetCallbackTime(JERRYPIT1Callback, usecs, EVENT_JERRY); } -#endif } + void JERRYResetPIT2(void) { -#ifndef NEW_TIMER_SYSTEM -/* if (!JERRYPIT2Prescaler || !JERRYPIT2Divider) - { - jerry_timer_2_counter = 0; - return; - } - else//*/ - jerry_timer_2_counter = (JERRYPIT2Prescaler + 1) * (JERRYPIT2Divider + 1); - -// if (jerry_timer_2_counter) -// WriteLog("jerry: reseting timer 2 to 0x%.8x (%i)\n",jerry_timer_2_counter,jerry_timer_2_counter); - -#else RemoveCallback(JERRYPIT2Callback); if (JERRYPIT1Prescaler | JERRYPIT1Divider) { double usecs = (float)(JERRYPIT2Prescaler + 1) * (float)(JERRYPIT2Divider + 1) * RISC_CYCLE_IN_USEC; - SetCallbackTime(JERRYPIT2Callback, usecs); + SetCallbackTime(JERRYPIT2Callback, usecs, EVENT_JERRY); } -#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 (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 + } + } +#endif + DSPSetIRQLine(DSPIRQ_TIMER0, ASSERT_LINE); // This does the 'IRQ enabled' checking... JERRYResetPIT1(); } + void JERRYPIT2Callback(void) { +#ifndef JERRY_NO_IRQS + if (TOMIRQEnabled(IRQ_DSP)) + { +//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(); } + void JERRYI2SCallback(void) { - // Why is it called this? Instead of SCLK? Shouldn't this be read from DAC.CPP??? -//Yes, it should. !!! FIX !!! -#warning "Why is it called this? Instead of SCLK? Shouldn't this be read from DAC.CPP??? Yes, it should. !!! FIX !!!" - JERRYI2SInterruptDivide &= 0xFF; // We don't have to divide the RISC clock rate by this--the reason is a bit // convoluted. Will put explanation here later... // What's needed here is to find the ratio of the frequency to the number of clock cycles // in one second. For example, if the sample rate is 44100, we divide the clock rate by // this: 26590906 / 44100 = 602 cycles. // Which means, every 602 cycles that go by we have to generate an interrupt. - jerryI2SCycles = 32 * (2 * (JERRYI2SInterruptDivide + 1)); + jerryI2SCycles = 32 * (2 * (sclk + 1)); +//This makes audio faster, but not enough and the pitch is wrong besides +// jerryI2SCycles = 32 * (2 * (sclk - 1)); -//This should be in this file with an extern reference in the header file so that -//DAC.CPP can see it... !!! FIX !!! - extern uint16 serialMode; // From DAC.CPP - - if (serialMode & 0x01) // INTERNAL flag (JERRY is master) + // If INTERNAL flag is set, then JERRY's SCLK is master + if (smode & SMODE_INTERNAL) { - DSPSetIRQLine(DSPIRQ_SSI, ASSERT_LINE); // This does the 'IRQ enabled' checking... - double usecs = (float)jerryI2SCycles * RISC_CYCLE_IN_USEC; - SetCallbackTime(JERRYI2SCallback, usecs); + // This does the 'IRQ enabled' checking... + DSPSetIRQLine(DSPIRQ_SSI, ASSERT_LINE); +// double usecs = (float)jerryI2SCycles * RISC_CYCLE_IN_USEC; +//this fix is almost enough to fix timings in tripper, but not quite enough... + double usecs = (float)jerryI2SCycles * (vjs.hardwareTypeNTSC ? RISC_CYCLE_IN_USEC : RISC_CYCLE_PAL_IN_USEC); + SetCallbackTime(JERRYI2SCallback, usecs, EVENT_JERRY); } - else // JERRY is slave to external word clock + else { + // JERRY is slave to external word clock + //Note that 44100 Hz requires samples every 22.675737 usec. //When JERRY is slave to the word clock, we need to do interrupts either at 44.1K //sample rate or at a 88.2K sample rate (11.332... usec). @@ -415,36 +334,32 @@ void JERRYI2SCallback(void) DSPSetIRQLine(DSPIRQ_SSI, ASSERT_LINE); } - SetCallbackTime(JERRYI2SCallback, 22.675737); + SetCallbackTime(JERRYI2SCallback, 22.675737, EVENT_JERRY); } } 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; JERRYPIT2Prescaler = 0xFFFF; JERRYPIT1Divider = 0xFFFF; JERRYPIT2Divider = 0xFFFF; + jerryInterruptMask = 0x0000; + jerryPendingInterrupt = 0x0000; + + DACInit(); } + void JERRYReset(void) { -// clock_reset(); -// anajoy_reset(); JoystickReset(); EepromReset(); JERRYResetI2S(); - DACReset(); memset(jerry_ram_8, 0x00, 0xD000); // Don't clear out the Wavetable ROM...! JERRYPIT1Prescaler = 0xFFFF; @@ -453,35 +368,42 @@ void JERRYReset(void) JERRYPIT2Divider = 0xFFFF; jerry_timer_1_counter = 0; jerry_timer_2_counter = 0; + jerryInterruptMask = 0x0000; + jerryPendingInterrupt = 0x0000; + + DACReset(); } + 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(); } + bool JERRYIRQEnabled(int irq) { // Read the word @ $F10020 - return jerry_ram_8[0x21] & (1 << irq); +// return jerry_ram_8[0x21] & (1 << irq); + return jerryInterruptMask & irq; } + void JERRYSetPendingIRQ(int irq) { // This is the shadow of INT (it's a split RO/WO register) - jerryIntPending |= (1 << irq); +// jerryIntPending |= (1 << irq); + jerryPendingInterrupt |= irq; } + // // JERRY byte access (read) // -uint8 JERRYReadByte(uint32 offset, uint32 who/*=UNKNOWN*/) +uint8_t JERRYReadByte(uint32_t offset, uint32_t who/*=UNKNOWN*/) { #ifdef JERRY_DEBUG WriteLog("JERRY: Reading byte at %06X\n", offset); @@ -506,60 +428,36 @@ uint8 JERRYReadByte(uint32 offset, uint32 who/*=UNKNOWN*/) //under the new system... !!! FIX !!! else if ((offset >= 0xF10036) && (offset <= 0xF1003D)) { -#ifndef NEW_TIMER_SYSTEM -// jerry_timer_1_counter = (JERRYPIT1Prescaler + 1) * (JERRYPIT1Divider + 1); - uint32 counter1Hi = (jerry_timer_1_counter / (JERRYPIT1Divider + 1)) - 1; - uint32 counter1Lo = (jerry_timer_1_counter % (JERRYPIT1Divider + 1)) - 1; - uint32 counter2Hi = (jerry_timer_2_counter / (JERRYPIT2Divider + 1)) - 1; - uint32 counter2Lo = (jerry_timer_2_counter % (JERRYPIT2Divider + 1)) - 1; - - switch(offset & 0x0F) - { - case 6: -// return JERRYPIT1Prescaler >> 8; - return counter1Hi >> 8; - case 7: -// return JERRYPIT1Prescaler & 0xFF; - return counter1Hi & 0xFF; - case 8: -// return JERRYPIT1Divider >> 8; - return counter1Lo >> 8; - case 9: -// return JERRYPIT1Divider & 0xFF; - return counter1Lo & 0xFF; - case 10: -// return JERRYPIT2Prescaler >> 8; - return counter2Hi >> 8; - case 11: -// return JERRYPIT2Prescaler & 0xFF; - return counter2Hi & 0xFF; - case 12: -// return JERRYPIT2Divider >> 8; - return counter2Lo >> 8; - case 13: -// return JERRYPIT2Divider & 0xFF; - return counter2Lo & 0xFF; - } -#else WriteLog("JERRY: Unhandled timer read (BYTE) at %08X...\n", offset); -#endif } // else if (offset >= 0xF10010 && offset <= 0xF10015) // return clock_byte_read(offset); // else if (offset >= 0xF17C00 && offset <= 0xF17C01) // return anajoy_byte_read(offset); else if (offset >= 0xF14000 && offset <= 0xF14003) - return JoystickReadByte(offset) | EepromReadByte(offset); +// return JoystickReadByte(offset) | EepromReadByte(offset); + { + uint16_t value = JoystickReadWord(offset & 0xFE); + + if (offset & 0x01) + value &= 0xFF; + else + value >>= 8; + + // This is wrong, should only have the lowest bit from $F14001 + return value | EepromReadByte(offset); + } else if (offset >= 0xF14000 && offset <= 0xF1A0FF) return EepromReadByte(offset); return jerry_ram_8[offset & 0xFFFF]; } + // // JERRY word access (read) // -uint16 JERRYReadWord(uint32 offset, uint32 who/*=UNKNOWN*/) +uint16_t JERRYReadWord(uint32_t offset, uint32_t who/*=UNKNOWN*/) { #ifdef JERRY_DEBUG WriteLog("JERRY: Reading word at %06X\n", offset); @@ -582,37 +480,13 @@ uint16 JERRYReadWord(uint32 offset, uint32 who/*=UNKNOWN*/) //in the jerry_timer_n_counter variables... !!! FIX !!! [DONE] else if ((offset >= 0xF10036) && (offset <= 0xF1003D)) { -#ifndef NEW_TIMER_SYSTEM -// jerry_timer_1_counter = (JERRYPIT1Prescaler + 1) * (JERRYPIT1Divider + 1); - uint32 counter1Hi = (jerry_timer_1_counter / (JERRYPIT1Divider + 1)) - 1; - uint32 counter1Lo = (jerry_timer_1_counter % (JERRYPIT1Divider + 1)) - 1; - uint32 counter2Hi = (jerry_timer_2_counter / (JERRYPIT2Divider + 1)) - 1; - uint32 counter2Lo = (jerry_timer_2_counter % (JERRYPIT2Divider + 1)) - 1; - - switch(offset & 0x0F) - { - case 6: -// return JERRYPIT1Prescaler; - return counter1Hi; - case 8: -// return JERRYPIT1Divider; - return counter1Lo; - case 10: -// return JERRYPIT2Prescaler; - return counter2Hi; - case 12: -// return JERRYPIT2Divider; - return counter2Lo; - } - // Unaligned word reads??? -#else WriteLog("JERRY: Unhandled timer read (WORD) at %08X...\n", offset); -#endif } // else if ((offset >= 0xF10010) && (offset <= 0xF10015)) // return clock_word_read(offset); else if (offset == 0xF10020) - return jerryIntPending; +// return jerryIntPending; + return jerryPendingInterrupt; // else if ((offset >= 0xF17C00) && (offset <= 0xF17C01)) // return anajoy_word_read(offset); else if (offset == 0xF14000) @@ -623,16 +497,17 @@ WriteLog("JERRY: Unhandled timer read (WORD) at %08X...\n", offset); return EepromReadWord(offset); /*if (offset >= 0xF1D000) - WriteLog("JERRY: Reading word at %08X [%04X]...\n", offset, ((uint16)jerry_ram_8[(offset+0)&0xFFFF] << 8) | jerry_ram_8[(offset+1)&0xFFFF]);//*/ + WriteLog("JERRY: Reading word at %08X [%04X]...\n", offset, ((uint16_t)jerry_ram_8[(offset+0)&0xFFFF] << 8) | jerry_ram_8[(offset+1)&0xFFFF]);//*/ offset &= 0xFFFF; // Prevent crashing...! - return ((uint16)jerry_ram_8[offset+0] << 8) | jerry_ram_8[offset+1]; + return ((uint16_t)jerry_ram_8[offset+0] << 8) | jerry_ram_8[offset+1]; } + // // JERRY byte access (write) // -void JERRYWriteByte(uint32 offset, uint8 data, uint32 who/*=UNKNOWN*/) +void JERRYWriteByte(uint32_t offset, uint8_t data, uint32_t who/*=UNKNOWN*/) { #ifdef JERRY_DEBUG WriteLog("jerry: writing byte %.2x at 0x%.6x\n",data,offset); @@ -649,23 +524,25 @@ void JERRYWriteByte(uint32 offset, uint8 data, uint32 who/*=UNKNOWN*/) } // SCLK ($F1A150--8 bits wide) //NOTE: This should be taken care of in DAC... +#if 0 else if ((offset >= 0xF1A152) && (offset <= 0xF1A153)) { +#if 0 // WriteLog("JERRY: Writing %02X to SCLK...\n", data); if ((offset & 0x03) == 2) - JERRYI2SInterruptDivide = (JERRYI2SInterruptDivide & 0x00FF) | ((uint32)data << 8); + sclk = (sclk & 0x00FF) | ((uint32_t)data << 8); else - JERRYI2SInterruptDivide = (JERRYI2SInterruptDivide & 0xFF00) | (uint32)data; - - JERRYI2SInterruptTimer = -1; -#ifndef NEW_TIMER_SYSTEM - jerry_i2s_exec(0); + sclk = (sclk & 0xFF00) | (uint32_t)data; #else + sclk = data; +#endif +#warning "!!! SCLK should be handled in dac.cpp !!!" + JERRYI2SInterruptTimer = -1; RemoveCallback(JERRYI2SCallback); JERRYI2SCallback(); -#endif // return; } +#endif // LTXD/RTXD/SCLK/SMODE $F1A148/4C/50/54 (really 16-bit registers...) else if (offset >= 0xF1A148 && offset <= 0xF1A157) { @@ -674,44 +551,7 @@ void JERRYWriteByte(uint32 offset, uint8 data, uint32 who/*=UNKNOWN*/) } else if (offset >= 0xF10000 && offset <= 0xF10007) { -#ifndef NEW_TIMER_SYSTEM - switch (offset & 0x07) - { - case 0: - JERRYPIT1Prescaler = (JERRYPIT1Prescaler & 0x00FF) | (data << 8); - JERRYResetPIT1(); - break; - case 1: - JERRYPIT1Prescaler = (JERRYPIT1Prescaler & 0xFF00) | data; - JERRYResetPIT1(); - break; - case 2: - JERRYPIT1Divider = (JERRYPIT1Divider & 0x00FF) | (data << 8); - JERRYResetPIT1(); - break; - case 3: - JERRYPIT1Divider = (JERRYPIT1Divider & 0xFF00) | data; - JERRYResetPIT1(); - break; - case 4: - JERRYPIT2Prescaler = (JERRYPIT2Prescaler & 0x00FF) | (data << 8); - JERRYResetPIT2(); - break; - case 5: - JERRYPIT2Prescaler = (JERRYPIT2Prescaler & 0xFF00) | data; - JERRYResetPIT2(); - break; - case 6: - JERRYPIT2Divider = (JERRYPIT2Divider & 0x00FF) | (data << 8); - JERRYResetPIT2(); - break; - case 7: - JERRYPIT2Divider = (JERRYPIT2Divider & 0xFF00) | data; - JERRYResetPIT2(); - } -#else WriteLog("JERRY: Unhandled timer write (BYTE) at %08X...\n", offset); -#endif return; } /* else if ((offset >= 0xF10010) && (offset <= 0xF10015)) @@ -720,9 +560,17 @@ WriteLog("JERRY: Unhandled timer write (BYTE) at %08X...\n", offset); return; }//*/ // JERRY -> 68K interrupt enables/latches (need to be handled!) - else if (offset >= 0xF10020 && offset <= 0xF10023) + else if (offset >= 0xF10020 && offset <= 0xF10021)//WAS:23) { -WriteLog("JERRY: (68K int en/lat - Unhandled!) Tried to write $%02X to $%08X!\n", data, offset); + if (offset == 0xF10020) + { + // Clear pending interrupts... + jerryPendingInterrupt &= ~data; + } + else if (offset == 0xF10021) + jerryInterruptMask = data; +//WriteLog("JERRY: (68K int en/lat - Unhandled!) Tried to write $%02X to $%08X!\n", data, offset); +//WriteLog("JERRY: (Previous is partially handled... IRQMask=$%04X)\n", jerryInterruptMask); } /* else if ((offset >= 0xF17C00) && (offset <= 0xF17C01)) { @@ -731,7 +579,10 @@ WriteLog("JERRY: (68K int en/lat - Unhandled!) Tried to write $%02X to $%08X!\n" }*/ else if ((offset >= 0xF14000) && (offset <= 0xF14003)) { - JoystickWriteByte(offset, data); +WriteLog("JERRYWriteByte: Unhandled byte write to JOYSTICK by %s.\n", whoName[who]); +// JoystickWriteByte(offset, data); + JoystickWriteWord(offset & 0xFE, (uint16_t)data); +// This is wrong, EEPROM is never written here EepromWriteByte(offset, data); return; } @@ -748,14 +599,40 @@ WriteLog("JERRY: (68K int en/lat - Unhandled!) Tried to write $%02X to $%08X!\n" jerry_ram_8[offset & 0xFFFF] = data; } + // // JERRY word access (write) // -void JERRYWriteWord(uint32 offset, uint16 data, uint32 who/*=UNKNOWN*/) +void JERRYWriteWord(uint32_t offset, uint16_t data, uint32_t who/*=UNKNOWN*/) { #ifdef JERRY_DEBUG WriteLog( "JERRY: Writing word %04X at %06X\n", data, offset); #endif +#if 1 +if (offset == 0xF10000) + WriteLog("JERRY: JPIT1 word written by %s: %u\n", whoName[who], data); +else if (offset == 0xF10002) + WriteLog("JERRY: JPIT2 word written by %s: %u\n", whoName[who], data); +else if (offset == 0xF10004) + WriteLog("JERRY: JPIT3 word written by %s: %u\n", whoName[who], data); +else if (offset == 0xF10006) + WriteLog("JERRY: JPIT4 word written by %s: %u\n", whoName[who], data); +else if (offset == 0xF10010) + WriteLog("JERRY: CLK1 word written by %s: %u\n", whoName[who], data); +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 (%s%s%s%s%s%s)\n", whoName[who], data, + (data & 0x01 ? "Extrnl " : ""), (data & 0x02 ? "DSP " : ""), + (data & 0x04 ? "Timer0 " : ""), (data & 0x08 ? "Timer1 " : ""), + (data & 0x10 ? "ASI " : ""), (data & 0x20 ? "I2S " : "")); +#endif if ((offset >= DSP_CONTROL_RAM_BASE) && (offset < DSP_CONTROL_RAM_BASE+0x20)) { @@ -768,22 +645,25 @@ void JERRYWriteWord(uint32 offset, uint16 data, uint32 who/*=UNKNOWN*/) return; } //NOTE: This should be taken care of in DAC... +#if 0 else if (offset == 0xF1A152) // Bottom half of SCLK ($F1A150) { - WriteLog("JERRY: Writing %04X to SCLK (by %s)...\n", data, whoName[who]); +#warning "!!! SCLK should be handled in dac.cpp !!!" + 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; -#ifndef NEW_TIMER_SYSTEM - jerry_i2s_exec(0); +#if 0 + sclk = (uint8_t)data; #else + sclk = data & 0xFF; +#endif + JERRYI2SInterruptTimer = -1; RemoveCallback(JERRYI2SCallback); JERRYI2SCallback(); -#endif DACWriteWord(offset, data, who); return; } +#endif // LTXD/RTXD/SCLK/SMODE $F1A148/4C/50/54 (really 16-bit registers...) else if (offset >= 0xF1A148 && offset <= 0xF1A156) { @@ -792,8 +672,6 @@ void JERRYWriteWord(uint32 offset, uint16 data, uint32 who/*=UNKNOWN*/) } else if (offset >= 0xF10000 && offset <= 0xF10007) { -//#ifndef NEW_TIMER_SYSTEM -#if 1 switch(offset & 0x07) { case 0: @@ -813,9 +691,7 @@ void JERRYWriteWord(uint32 offset, uint16 data, uint32 who/*=UNKNOWN*/) JERRYResetPIT2(); } // Need to handle (unaligned) cases??? -#else -WriteLog("JERRY: Unhandled timer write %04X (WORD) at %08X by %s...\n", data, offset, whoName[who]); -#endif + return; } /* else if (offset >= 0xF10010 && offset < 0xF10016) @@ -826,7 +702,11 @@ WriteLog("JERRY: Unhandled timer write %04X (WORD) at %08X by %s...\n", data, of // JERRY -> 68K interrupt enables/latches (need to be handled!) else if (offset >= 0xF10020 && offset <= 0xF10022) { -WriteLog("JERRY: (68K int en/lat - Unhandled!) Tried to write $%04X to $%08X!\n", data, offset); + jerryInterruptMask = data & 0xFF; + jerryPendingInterrupt &= ~(data >> 8); +//WriteLog("JERRY: (68K int en/lat - Unhandled!) Tried to write $%04X to $%08X!\n", data, offset); +//WriteLog("JERRY: (Previous is partially handled... IRQMask=$%04X)\n", jerryInterruptMask); + return; } /* else if (offset >= 0xF17C00 && offset < 0xF17C02) { @@ -853,3 +733,18 @@ WriteLog("JERRY: (68K int en/lat - Unhandled!) Tried to write $%04X to $%08X!\n" 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)); +} +