X-Git-Url: http://shamusworld.gotdns.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=src%2Fjerry.cpp;h=32f8c92c85582af67ad833d3e9aefd8dc2037bac;hb=refs%2Ftags%2F2.1.1;hp=0b44b8f731fd036a3bb2b7765cf46eb09524c60f;hpb=10f249cb763ddc00cd80e1d47940784e25d3e4a7;p=virtualjaguar diff --git a/src/jerry.cpp b/src/jerry.cpp index 0b44b8f..32f8c92 100644 --- a/src/jerry.cpp +++ b/src/jerry.cpp @@ -163,7 +163,7 @@ #include "jaguar.h" #include "joystick.h" #include "log.h" -#include "m68k.h" +#include "m68000/m68kinterface.h" #include "settings.h" #include "tom.h" //#include "memory.h" @@ -172,26 +172,42 @@ //Note that 44100 Hz requires samples every 22.675737 usec. //#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; - -static uint32 JERRYPIT1Prescaler; -static uint32 JERRYPIT1Divider; -static uint32 JERRYPIT2Prescaler; -static uint32 JERRYPIT2Divider; -static int32 jerry_timer_1_counter; -static int32 jerry_timer_2_counter; - -uint32 JERRYI2SInterruptDivide = 8; -int32 JERRYI2SInterruptTimer = -1; -uint32 jerryI2SCycles; -uint32 jerryIntPending; - -static uint16 jerryInterruptMask = 0; -static uint16 jerryPendingInterrupt = 0; +// JERRY Registers (write, offset from $F10000) +#define JPIT1 0x00 +#define JPIT2 0x02 +#define JPIT3 0x04 +#define JPIT4 0x08 +#define CLK1 0x10 +#define CLK2 0x12 +#define CLK3 0x14 +#define JINTCTRL 0x20 +#define ASIDATA 0x30 +#define ASICTRL 0x32 +#define ASICLK 0x34 +#define SCLK 0xA150 +#define SMODE 0xA154 + + +uint8_t analog_x, analog_y; + +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_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 @@ -208,7 +224,7 @@ void JERRYResetI2S(void) { //WriteLog("i2s: reseting\n"); //This is really SCLK... !!! FIX !!! - JERRYI2SInterruptDivide = 8; + sclk = 8; JERRYI2SInterruptTimer = -1; } @@ -282,30 +298,30 @@ void JERRYPIT2Callback(void) 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; + // 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). @@ -377,6 +393,7 @@ void JERRYReset(void) void JERRYDone(void) { + JERRYDumpIORegistersToLog(); WriteLog("JERRY: M68K Interrupt control ($F10020) = %04X\n", GET16(jerry_ram_8, 0x20)); JoystickDone(); DACDone(); @@ -399,11 +416,35 @@ void JERRYSetPendingIRQ(int irq) jerryPendingInterrupt |= irq; } +// +// Dump all JERRY register values to the log +// +void JERRYDumpIORegistersToLog(void) +{ + WriteLog("\n\n---------------------------------------------------------------------\n"); + WriteLog("JERRY I/O Registers\n"); + WriteLog("---------------------------------------------------------------------\n"); + WriteLog("F1%04X (JPIT1): $%04X\n", JPIT1, GET16(jerry_ram_8, JPIT1)); + WriteLog("F1%04X (JPIT2): $%04X\n", JPIT2, GET16(jerry_ram_8, JPIT2)); + WriteLog("F1%04X (JPIT3): $%04X\n", JPIT3, GET16(jerry_ram_8, JPIT3)); + WriteLog("F1%04X (JPIT4): $%04X\n", JPIT4, GET16(jerry_ram_8, JPIT4)); + WriteLog("F1%04X (CLK1): $%04X\n", CLK1, GET16(jerry_ram_8, CLK1)); + WriteLog("F1%04X (CLK2): $%04X\n", CLK2, GET16(jerry_ram_8, CLK2)); + WriteLog("F1%04X (CLK3): $%04X\n", CLK3, GET16(jerry_ram_8, CLK3)); + WriteLog("F1%04X (JINTCTRL): $%04X\n", JINTCTRL, GET16(jerry_ram_8, JINTCTRL)); + WriteLog("F1%04X (ASIDATA): $%04X\n", ASIDATA, GET16(jerry_ram_8, ASIDATA)); + WriteLog("F1%04X (ASICTRL): $%04X\n", ASICTRL, GET16(jerry_ram_8, ASICTRL)); + WriteLog("F1%04X (ASICLK): $%04X\n", ASICLK, GET16(jerry_ram_8, ASICLK)); + WriteLog("F1%04X (SCLK): $%04X\n", SCLK, GET16(jerry_ram_8, SCLK)); + WriteLog("F1%04X (SMODE): $%04X\n", SMODE, GET16(jerry_ram_8, SMODE)); + WriteLog("---------------------------------------------------------------------\n\n\n"); +} + // // 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); @@ -435,7 +476,18 @@ WriteLog("JERRY: Unhandled timer read (BYTE) at %08X...\n", 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); @@ -446,7 +498,7 @@ WriteLog("JERRY: Unhandled timer read (BYTE) at %08X...\n", offset); // // 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); @@ -486,46 +538,55 @@ 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*/) { + // Moved here tentatively, so we can see everything written to JERRY. + jerry_ram_8[offset & 0xFFFF] = data; + #ifdef JERRY_DEBUG WriteLog("jerry: writing byte %.2x at 0x%.6x\n",data,offset); #endif - if ((offset >= DSP_CONTROL_RAM_BASE) && (offset < DSP_CONTROL_RAM_BASE+0x20)) + if ((offset >= DSP_CONTROL_RAM_BASE) && (offset < DSP_CONTROL_RAM_BASE + 0x20)) { DSPWriteByte(offset, data, who); return; } - else if ((offset >= DSP_WORK_RAM_BASE) && (offset < DSP_WORK_RAM_BASE+0x2000)) + else if ((offset >= DSP_WORK_RAM_BASE) && (offset < DSP_WORK_RAM_BASE + 0x2000)) { DSPWriteByte(offset, data, who); return; } // 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; - + sclk = (sclk & 0xFF00) | (uint32_t)data; +#else + sclk = data; +#endif +#warning "!!! SCLK should be handled in dac.cpp !!!" JERRYI2SInterruptTimer = -1; RemoveCallback(JERRYI2SCallback); JERRYI2SCallback(); // return; } +#endif // LTXD/RTXD/SCLK/SMODE $F1A148/4C/50/54 (really 16-bit registers...) else if (offset >= 0xF1A148 && offset <= 0xF1A157) { @@ -562,7 +623,10 @@ WriteLog("JERRY: Unhandled timer write (BYTE) at %08X...\n", offset); }*/ 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; } @@ -576,15 +640,19 @@ WriteLog("JERRY: Unhandled timer write (BYTE) at %08X...\n", offset); if (offset >= 0xF1D000 && offset <= 0xF1DFFF) return; - jerry_ram_8[offset & 0xFFFF] = data; +// 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*/) { + // Moved here tentatively, so we can see everything written to JERRY. + jerry_ram_8[(offset+0) & 0xFFFF] = (data >> 8) & 0xFF; + jerry_ram_8[(offset+1) & 0xFFFF] = data & 0xFF; + #ifdef JERRY_DEBUG WriteLog( "JERRY: Writing word %04X at %06X\n", data, offset); #endif @@ -614,22 +682,28 @@ else if (offset == 0xF10020) (data & 0x10 ? "ASI " : ""), (data & 0x20 ? "I2S " : "")); #endif - if ((offset >= DSP_CONTROL_RAM_BASE) && (offset < DSP_CONTROL_RAM_BASE+0x20)) + if ((offset >= DSP_CONTROL_RAM_BASE) && (offset < DSP_CONTROL_RAM_BASE + 0x20)) { DSPWriteWord(offset, data, who); return; } - else if ((offset >= DSP_WORK_RAM_BASE) && (offset < DSP_WORK_RAM_BASE+0x2000)) + else if ((offset >= DSP_WORK_RAM_BASE) && (offset < DSP_WORK_RAM_BASE + 0x2000)) { DSPWriteWord(offset, data, who); return; } //NOTE: This should be taken care of in DAC... +#if 0 else if (offset == 0xF1A152) // Bottom half of SCLK ($F1A150) { +#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; +#if 0 + sclk = (uint8_t)data; +#else + sclk = data & 0xFF; +#endif JERRYI2SInterruptTimer = -1; RemoveCallback(JERRYI2SCallback); JERRYI2SCallback(); @@ -637,6 +711,7 @@ else if (offset == 0xF10020) DACWriteWord(offset, data, who); return; } +#endif // LTXD/RTXD/SCLK/SMODE $F1A148/4C/50/54 (really 16-bit registers...) else if (offset >= 0xF1A148 && offset <= 0xF1A156) { @@ -667,11 +742,6 @@ else if (offset == 0xF10020) return; } -/* else if (offset >= 0xF10010 && offset < 0xF10016) - { - clock_word_write(offset, data); - return; - }//*/ // JERRY -> 68K interrupt enables/latches (need to be handled!) else if (offset >= 0xF10020 && offset <= 0xF10022) { @@ -681,12 +751,6 @@ else if (offset == 0xF10020) //WriteLog("JERRY: (Previous is partially handled... IRQMask=$%04X)\n", jerryInterruptMask); return; } -/* else if (offset >= 0xF17C00 && offset < 0xF17C02) - { -//I think this was removed from the Jaguar. If so, then we don't need this...! - anajoy_word_write(offset, data); - return; - }*/ else if (offset >= 0xF14000 && offset < 0xF14003) { JoystickWriteWord(offset, data); @@ -703,18 +767,21 @@ else if (offset == 0xF10020) if (offset >= 0xF1D000 && offset <= 0xF1DFFF) return; - jerry_ram_8[(offset+0) & 0xFFFF] = (data >> 8) & 0xFF; - jerry_ram_8[(offset+1) & 0xFFFF] = data & 0xFF; +// 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)); } +