diff --git a/trunk/src/boards/178.cpp b/trunk/src/boards/178.cpp index 775fece9..65e98a12 100644 --- a/trunk/src/boards/178.cpp +++ b/trunk/src/boards/178.cpp @@ -29,6 +29,12 @@ static uint8 reg[4]; static uint8 *WRAM = NULL; static uint32 WRAMSIZE; +// Tennis with VR sensor, very simple behaviour +extern void GetMouseData(uint32 (&md)[3]); +static uint32 MouseData[3], click, lastclick; +static int32 SensorDelay; + +// highly experimental, not actually working, just curious if it hapen to work with some other decoder // SND Registers static uint8 pcm_enable = 0; static int16 pcm_latch = 0x3F6, pcm_clock = 0x3F6; @@ -40,41 +46,41 @@ static SFORMAT StateRegs[] = { 0 } }; -static int16 step_size[49] = { - 16, 17, 19, 21, 23, 25, 28, 31, 34, 37, - 41, 45, 50, 55, 60, 66, 73, 80, 88, 97, - 107, 118, 130, 143, 157, 173, 190, 209, 230, 253, - 279, 307, 337, 371, 408, 449, 494, 544, 598, 658, - 724, 796, 876, 963, 1060, 1166, 1282, 1411, 1552 -}; //49 items -static int32 step_adj[16] = { -1, -1, -1, -1, 2, 5, 7, 9, -1, -1, -1, -1, 2, 5, 7, 9 }; +//static int16 step_size[49] = { +// 16, 17, 19, 21, 23, 25, 28, 31, 34, 37, +// 41, 45, 50, 55, 60, 66, 73, 80, 88, 97, +// 107, 118, 130, 143, 157, 173, 190, 209, 230, 253, +// 279, 307, 337, 371, 408, 449, 494, 544, 598, 658, +// 724, 796, 876, 963, 1060, 1166, 1282, 1411, 1552 +//}; //49 items +//static int32 step_adj[16] = { -1, -1, -1, -1, 2, 5, 7, 9, -1, -1, -1, -1, 2, 5, 7, 9 }; //decode stuff -static int32 jedi_table[16 * 49]; -static int32 acc = 0; //ADPCM accumulator, initial condition must be 0 -static int32 decstep = 0; //ADPCM decoding step, initial condition must be 0 +//static int32 jedi_table[16 * 49]; +//static int32 acc = 0; //ADPCM accumulator, initial condition must be 0 +//static int32 decstep = 0; //ADPCM decoding step, initial condition must be 0 -static void jedi_table_init() { - int step, nib; +//static void jedi_table_init() { +// int step, nib; +// +// for (step = 0; step < 49; step++) { +// for (nib = 0; nib < 16; nib++) { +// int value = (2 * (nib & 0x07) + 1) * step_size[step] / 8; +// jedi_table[step * 16 + nib] = ((nib & 0x08) != 0) ? -value : value; +// } +// } +//} - for (step = 0; step < 49; step++) { - for (nib = 0; nib < 16; nib++) { - int value = (2 * (nib & 0x07) + 1) * step_size[step] / 8; - jedi_table[step * 16 + nib] = ((nib & 0x08) != 0) ? -value : value; - } - } -} - -static uint8 decode(uint8 code) { - acc += jedi_table[decstep + code]; - if ((acc & ~0x7ff) != 0) // acc is > 2047 - acc |= ~0xfff; - else acc &= 0xfff; - decstep += step_adj[code & 7] * 16; - if (decstep < 0) decstep = 0; - if (decstep > 48 * 16) decstep = 48 * 16; - return (acc >> 8) & 0xff; -} +//static uint8 decode(uint8 code) { +// acc += jedi_table[decstep + code]; +// if ((acc & ~0x7ff) != 0) // acc is > 2047 +// acc |= ~0xfff; +// else acc &= 0xfff; +// decstep += step_adj[code & 7] * 16; +// if (decstep < 0) decstep = 0; +// if (decstep > 48 * 16) decstep = 48 * 16; +// return (acc >> 8) & 0xff; +//} static void Sync(void) { uint32 sbank = reg[1] & 0x7; @@ -109,11 +115,11 @@ static DECLFW(M178WriteSnd) { if (V & 0xF0) { pcm_enable = 1; // pcmwrite(0x4011, (V & 0xF) << 3); - pcmwrite(0x4011, decode(V & 0xf)); +// pcmwrite(0x4011, decode(V & 0xf)); } else pcm_enable = 0; - } else - FCEU_printf("misc %04x:%02x\n", A, V); + }// else +// FCEU_printf("misc %04x:%02x\n", A, V); } static DECLFR(M178ReadSnd) { @@ -123,13 +129,19 @@ static DECLFR(M178ReadSnd) { return X.DB; } +static DECLFR(M178ReadSensor) { + X6502_IRQEnd(FCEU_IQEXT); // hacky-hacky, actual reg is 6000 and it clear IRQ while reading, but then I need another mapper lol + return 0x00; +} + static void M178Power(void) { - reg[0] = reg[1] = reg[2] = reg[3] = 0; + reg[0] = reg[1] = reg[2] = reg[3] = SensorDelay = 0; Sync(); - pcmwrite = GetWriteHandler(0x4011); +// pcmwrite = GetWriteHandler(0x4011); SetWriteHandler(0x4800, 0x4fff, M178Write); SetWriteHandler(0x5800, 0x5fff, M178WriteSnd); SetReadHandler(0x5800, 0x5fff, M178ReadSnd); + SetReadHandler(0x5000, 0x5000, M178ReadSensor); SetReadHandler(0x6000, 0x7fff, CartBR); SetWriteHandler(0x6000, 0x7fff, CartBW); SetReadHandler(0x8000, 0xffff, CartBR); @@ -137,13 +149,25 @@ static void M178Power(void) { } static void M178SndClk(int a) { - if (pcm_enable) { - pcm_latch -= a; - if (pcm_latch <= 0) { - pcm_latch += pcm_clock; - pcm_enable = 0; - } + SensorDelay += a; + if(SensorDelay > 0x32768) { + SensorDelay -= 32768; + GetMouseData (MouseData); + lastclick = click; + click = MouseData[2] & 1; // to prevent from continuos IRQ trigger if button is held. + // actual circuit is just a D-C-R edge detector for IR-sensor + // triggered by the active IR bat. + if(lastclick && !click) + X6502_IRQBegin(FCEU_IQEXT); } + +// if (pcm_enable) { +// pcm_latch -= a; +// if (pcm_latch <= 0) { +// pcm_latch += pcm_clock; +// pcm_enable = 0; +// } +// } } static void M178Close(void) { @@ -162,7 +186,7 @@ void Mapper178_Init(CartInfo *info) { GameStateRestore = StateRestore; MapIRQHook = M178SndClk; - jedi_table_init(); +// jedi_table_init(); WRAMSIZE = 32768; WRAM = (uint8*)FCEU_gmalloc(WRAMSIZE); diff --git a/trunk/src/boards/addrlatch.cpp b/trunk/src/boards/addrlatch.cpp index dc0128ed..b18ac2d9 100644 --- a/trunk/src/boards/addrlatch.cpp +++ b/trunk/src/boards/addrlatch.cpp @@ -303,7 +303,7 @@ static void M212Sync(void) { } void Mapper212_Init(CartInfo *info) { - Latch_Init(info, M212Sync, M212Read, 0xFFFF, 0x8000, 0xFFFF, 0); + Latch_Init(info, M212Sync, M212Read, 0x0000, 0x8000, 0xFFFF, 0); } //------------------ Map 213 ---------------------------