Re: [hatari-devel] TT emulation crashes when there is no ACSI drive |
[ Thread Index |
Date Index
| More lists.tuxfamily.org/hatari-devel Archives
]
- To: hatari-devel@xxxxxxxxxxxxxxxxxxx
- Subject: Re: [hatari-devel] TT emulation crashes when there is no ACSI drive
- From: Christian Zietz <czietz@xxxxxxx>
- Date: Sun, 11 Aug 2019 10:33:51 +0200
- Autocrypt: addr=czietz@xxxxxxx; prefer-encrypt=mutual; keydata= mQGiBDdn2AURBADksdHVyN55nv0lx4qGx+GQMrbo7zs7lSkAfhkgmgqp84xUeUiWI/kj1on/ wxkmJ96Yzt0ktDbZYM0C9Z66M3rLfXE1vXALHhegeMuOy/tVWybcohRrhfB7tmANTESJOZke 0lZZ59DcIfFoqLYErb6qX8nLPYnOv6sFubxnhuF9QQCg/3GaIR1sVK9Xq+b4B9BtVxd7cHMD /i2hAEOX3WY3K7PNZJziYF54uBbGiVS88W41l1RARcaeogIZcAKpFH3on+Tf60fAC85MCp17 QIeP44hj4Cf46B+UTVhf3EFG4IOsLRxUonpt7dKO8txsKFN/OFsjlPOuDyg7XMpEWkTWZetm HC9/0pcApIXSDnggde4T8AX6nn/+A/4hBOhPxuvkV7Uw/ebLYwXrLo2vt9OvvC1VfeywNseq PIkFX/+n/+niBS+Cb2ess2SVQNKJ9vP5+vBxg5AMfQXqk1ONldGQ/ARHmL6+Iuo47mO51e7R i691hq13wHUvyKh1AN7fpKI2m3YW55XEQ+3iTMIZcqfjr6xYgG8GJTppdbQgQ2hyaXN0aWFu IFppZXR6IDxjemlldHpAZ214Lm5ldD6IYwQQEQIAIwIZAQIeAQIXgAUCVGD5IgcLCQgHAwIB BhUIAgkKCwQWAgMBAAoJEFLLl/ZtoCXKubQAoIHNaurSMQB8MHDoTk3B7WHk2ApoAJ0egA8q aNoVj0kU4+OjeGzFiSHMOrkCDQQ3Z9gFEAgA9kJXtwh/CBdyorrWqULzBej5UxE5T7bxbrlL OCDaAadWoxTpj0BV89AHxstDqZSt90xkhkn4DIO9ZekX1KHTUPj1WV/cdlJPPT2N286Z4VeS Wc39uK50T8X8dryDxUcwYc58yWb/Ffm7/ZFexwGq01uejaClcjrUGvC/RgBYK+X0iP1YTknb zSC0neSRBzZrM2w4DUUdD3yIsxx8Wy2O9vPJI8BD8KVbGI2Ou1WMuF040zT9fBdXQ6MdGGze MyEstSr/POGxKUAYEY18hKcKctaGxAMZyAcpesqVDNmWn6vQClCbAkbTCD1mpF1Bn5x8vYlL IhkmuquiXsNV6TILOwACAgf+JhucyZDzOWGht9e0U71kC2bxIOr4iz+ADd3sxS62okrocHXp B9zYDhmJ74BFfC7xMd9bwWNj7YR0yiUdOzY27OcXcEkVmhVBW6AqxuRAKfmYMvvnyR5z5OP6 vg2YSzgOmooc5vequa5YIjLmFkuRlglLiEgdW9gPBFtirNqxOtAqSxEcRrblSn8JBEU51Ii6 SVVuo1nXOP11g8rVO4YvEED89pHT4jgLZu4th1N+mDumNZlqyUIxZ4tQyw3X2OWvEbKWGn2j h0ZywaomUTpVA+wiwxndawP40oowFYT8LNeLtfZyq6xPpQmT2DaNhP4gdy3qkDfnmXkc2zFM YukXo4g/AwUYN2fYBVLLl/ZtoCXKEQKA3QCfTJstYzXurbt9ZnoTU3SFQQmG0/wAoNX91nWM nsS7JOepPAzOUoke4AIi
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gmx.net; s=badeba3b8450; t=1565512438; bh=B9I7ZFxUPqP49fhqyQKiUYNn8+pOZG6lPFx5nAgetCQ=; h=X-UI-Sender-Class:Subject:To:References:From:Date:In-Reply-To; b=eLADHzv6IBzh2xwF2SjnjMAjDbNgEZLz5QpAVfqWX5nWCEnh6idPrfuijEz5czVPp kFPwIg4lBVM2Bd08lm0xaCN5EQStmMkwJb34Z/aaqOgUnuDxSaEEB0RM9jcyHOmgIT dSnZO6v3+wy6GjqU9huue0m2m3nqKwXsYV+AKwEo=
- Openpgp: preference=signencrypt
Nicolas Pomarède schrieb:
> looking at the code, unlike what the commit's name imply, this is mostly
> about natfeat (which was merged with new MFP code).
I think the Tuxfamily Git web interface is misleading here because it
doesn't properly interpret the merge (without rebasing first) that you did..
Running "git diff 65dda3cf 50bf142e" shows you the true difference
between the two versions that Uwe tested. A diff is attached for easier
reference. It's indeed about the TT MFP.
Regards
Christian
--
Christian Zietz - CHZ-Soft - czietz@xxxxxxx
WWW: http://www.chzsoft.de/
PGP/GnuPG-Key-ID: 0x52CB97F66DA025CA / 0x6DA025CA
diff --git a/src/acia.c b/src/acia.c
index 07cc3f2c..539de6c7 100644
--- a/src/acia.c
+++ b/src/acia.c
@@ -363,11 +363,11 @@ static void ACIA_Set_Line_IRQ_MFP ( int bit )
* the irq bit is set and the MFP interrupt is triggered - for example
* the "V8 music system" demo depends on this behaviour.
* This 4 cycle delay is handled in mfp.c */
- MFP_GPIP_Set_Line_Input ( MFP_GPIP_LINE_ACIA , MFP_GPIP_STATE_LOW );
+ MFP_GPIP_Set_Line_Input ( pMFP_Main , MFP_GPIP_LINE_ACIA , MFP_GPIP_STATE_LOW );
}
else
{
- MFP_GPIP_Set_Line_Input ( MFP_GPIP_LINE_ACIA , MFP_GPIP_STATE_HIGH );
+ MFP_GPIP_Set_Line_Input ( pMFP_Main , MFP_GPIP_LINE_ACIA , MFP_GPIP_STATE_HIGH );
}
}
diff --git a/src/blitter.c b/src/blitter.c
index e0cfd3fe..6bf89377 100644
--- a/src/blitter.c
+++ b/src/blitter.c
@@ -895,7 +895,7 @@ Video_GetPosition ( &FrameCycles , &HblCounterVideo , &LineCycles );
BlitterPhase = BLITTER_PHASE_RUN_TRANSFER;
/* Busy=1, set line to high/1 and clear interrupt */
- MFP_GPIP_Set_Line_Input ( MFP_GPIP_LINE_GPU_DONE , MFP_GPIP_STATE_HIGH );
+ MFP_GPIP_Set_Line_Input ( pMFP_Main , MFP_GPIP_LINE_GPU_DONE , MFP_GPIP_STATE_HIGH );
/* Now we enter the main blitting loop */
do
@@ -916,7 +916,7 @@ Video_GetPosition ( &FrameCycles , &HblCounterVideo , &LineCycles );
BlitterRegs.ctrl &= ~(0x80|0x40);
/* Busy=0, set line to low/0 and request interrupt */
- MFP_GPIP_Set_Line_Input ( MFP_GPIP_LINE_GPU_DONE , MFP_GPIP_STATE_LOW );
+ MFP_GPIP_Set_Line_Input ( pMFP_Main , MFP_GPIP_LINE_GPU_DONE , MFP_GPIP_STATE_LOW );
BlitterPhase = BLITTER_PHASE_STOP;
diff --git a/src/cpu/hatari-glue.c b/src/cpu/hatari-glue.c
index bc9c65df..f2a88f52 100644
--- a/src/cpu/hatari-glue.c
+++ b/src/cpu/hatari-glue.c
@@ -64,7 +64,7 @@ void customreset(void)
PSG_Reset ();
/* Reset the MFP */
- MFP_Reset ();
+ MFP_Reset_All ();
/* Reset the FDC */
FDC_Reset ( false );
diff --git a/src/cpu/newcpu.c b/src/cpu/newcpu.c
index 6421bc61..5b54559c 100644
--- a/src/cpu/newcpu.c
+++ b/src/cpu/newcpu.c
@@ -3247,7 +3247,7 @@ static int iack_cycle(int nr)
while ( ( PendingInterruptCount <= 0 ) && ( PendingInterruptFunction ) )
CALL_VAR(PendingInterruptFunction);
if ( MFP_UpdateNeeded == true )
- MFP_UpdateIRQ ( 0 ); /* update MFP's state if some internal timers related to MFP expired */
+ MFP_UpdateIRQ_All ( 0 ); /* update MFP's state if some internal timers related to MFP expired */
pendingInterrupts &= ~( 1 << ( nr - 24 ) ); /* clear HBL or VBL pending bit (even if an MFP timer occurred during IACK) */
CPU_IACK = false;
}
@@ -5222,7 +5222,7 @@ static bool do_specialties_interrupt (int Pending)
/* Check for MFP ints (level 6) */
if (regs.spcflags & SPCFLAG_MFP) {
- if (MFP_ProcessIRQ() == true)
+ if (MFP_ProcessIRQ_All() == true)
return true; /* MFP exception was generated, no higher interrupt can happen */
}
@@ -5415,9 +5415,9 @@ static int do_specialties (int cycles)
while ( ( PendingInterruptCount <= 0 ) && ( PendingInterruptFunction ) )
CALL_VAR(PendingInterruptFunction);
if ( MFP_UpdateNeeded == true )
- MFP_UpdateIRQ ( 0 );
+ MFP_UpdateIRQ_All ( 0 );
- /* Check is there's an interrupt to process (could be a delayed MFP interrupt) */
+ /* Check if there's an interrupt to process (could be a delayed MFP interrupt) */
if (regs.spcflags & SPCFLAG_MFP) {
MFP_DelayIRQ (); /* Handle IRQ propagation */
M68000_Update_intlev (); /* Refresh the list of pending interrupts */
@@ -5704,7 +5704,7 @@ static void m68k_run_1 (void)
while ( ( PendingInterruptCount <= 0 ) && ( PendingInterruptFunction ) && ( ( regs.spcflags & SPCFLAG_STOP ) == 0 ) )
CALL_VAR(PendingInterruptFunction); /* call the interrupt handler */
if ( MFP_UpdateNeeded == true )
- MFP_UpdateIRQ ( 0 );
+ MFP_UpdateIRQ_All ( 0 );
#endif
if (r->spcflags) {
@@ -5856,7 +5856,7 @@ static void m68k_run_1_ce (void)
while ( ( PendingInterruptCount <= 0 ) && ( PendingInterruptFunction ) && ( ( regs.spcflags & SPCFLAG_STOP ) == 0 ) )
CALL_VAR(PendingInterruptFunction); /* call the interrupt handler */
if ( MFP_UpdateNeeded == true )
- MFP_UpdateIRQ ( 0 );
+ MFP_UpdateIRQ_All ( 0 );
#endif
if (cpu_tracer) {
@@ -6517,7 +6517,7 @@ static void m68k_run_mmu060 (void)
while ( ( PendingInterruptCount <= 0 ) && ( PendingInterruptFunction ) && ( ( regs.spcflags & SPCFLAG_STOP ) == 0 ) )
CALL_VAR(PendingInterruptFunction); /* call the interrupt handler */
if ( MFP_UpdateNeeded == true )
- MFP_UpdateIRQ ( 0 );
+ MFP_UpdateIRQ_All ( 0 );
#endif
if (regs.spcflags) {
if (do_specialties (cpu_cycles))
@@ -6617,7 +6617,7 @@ static void m68k_run_mmu040 (void)
while ( ( PendingInterruptCount <= 0 ) && ( PendingInterruptFunction ) && ( ( regs.spcflags & SPCFLAG_STOP ) == 0 ) )
CALL_VAR(PendingInterruptFunction); /* call the interrupt handler */
if ( MFP_UpdateNeeded == true )
- MFP_UpdateIRQ ( 0 );
+ MFP_UpdateIRQ_All ( 0 );
#endif
if (regs.spcflags) {
@@ -6782,7 +6782,7 @@ insretry:
while ( ( PendingInterruptCount <= 0 ) && ( PendingInterruptFunction ) && ( ( regs.spcflags & SPCFLAG_STOP ) == 0 ) )
CALL_VAR(PendingInterruptFunction); /* call the interrupt handler */
if ( MFP_UpdateNeeded == true )
- MFP_UpdateIRQ ( 0 );
+ MFP_UpdateIRQ_All ( 0 );
#endif
if (regs.spcflags) {
if (do_specialties (cpu_cycles))
@@ -6812,7 +6812,7 @@ insretry:
while ( ( PendingInterruptCount <= 0 ) && ( PendingInterruptFunction ) && ( ( regs.spcflags & SPCFLAG_STOP ) == 0 ) )
CALL_VAR(PendingInterruptFunction); /* call the interrupt handler */
if ( MFP_UpdateNeeded == true )
- MFP_UpdateIRQ ( 0 );
+ MFP_UpdateIRQ_All ( 0 );
#endif
if (regs.spcflags || time_for_interrupt ()) {
@@ -6930,7 +6930,7 @@ static void m68k_run_3ce (void)
while ( ( PendingInterruptCount <= 0 ) && ( PendingInterruptFunction ) && ( ( regs.spcflags & SPCFLAG_STOP ) == 0 ) )
CALL_VAR(PendingInterruptFunction); /* call the interrupt handler */
if ( MFP_UpdateNeeded == true )
- MFP_UpdateIRQ ( 0 );
+ MFP_UpdateIRQ_All ( 0 );
#endif
if (r->spcflags) {
if (do_specialties (0))
@@ -7028,7 +7028,7 @@ static void m68k_run_3p(void)
while ( ( PendingInterruptCount <= 0 ) && ( PendingInterruptFunction ) && ( ( regs.spcflags & SPCFLAG_STOP ) == 0 ) )
CALL_VAR(PendingInterruptFunction); /* call the interrupt handler */
if ( MFP_UpdateNeeded == true )
- MFP_UpdateIRQ ( 0 );
+ MFP_UpdateIRQ_All ( 0 );
#endif
if (r->spcflags) {
@@ -7221,7 +7221,7 @@ fprintf ( stderr , "cache valid %d tag1 %x lws1 %x ctag %x data %x mem=%x\n" , c
while ( ( PendingInterruptCount <= 0 ) && ( PendingInterruptFunction ) && ( ( regs.spcflags & SPCFLAG_STOP ) == 0 ) )
CALL_VAR(PendingInterruptFunction); /* call the interrupt handler */
if ( MFP_UpdateNeeded == true )
- MFP_UpdateIRQ ( 0 );
+ MFP_UpdateIRQ_All ( 0 );
#endif
cont:
@@ -7414,7 +7414,7 @@ cont:
while ( ( PendingInterruptCount <= 0 ) && ( PendingInterruptFunction ) && ( ( regs.spcflags & SPCFLAG_STOP ) == 0 ) )
CALL_VAR(PendingInterruptFunction); /* call the interrupt handler */
if ( MFP_UpdateNeeded == true )
- MFP_UpdateIRQ ( 0 );
+ MFP_UpdateIRQ_All ( 0 );
#endif
if (r->spcflags) {
@@ -7548,7 +7548,7 @@ static void m68k_run_2 (void)
while ( ( PendingInterruptCount <= 0 ) && ( PendingInterruptFunction ) && ( ( regs.spcflags & SPCFLAG_STOP ) == 0 ) )
CALL_VAR(PendingInterruptFunction); /* call the interrupt handler */
if ( MFP_UpdateNeeded == true )
- MFP_UpdateIRQ ( 0 );
+ MFP_UpdateIRQ_All ( 0 );
#endif
if (r->spcflags) {
diff --git a/src/cycInt.c b/src/cycInt.c
index c72f5aae..141c094e 100644
--- a/src/cycInt.c
+++ b/src/cycInt.c
@@ -82,10 +82,14 @@ static void (* const pIntHandlerFunctions[MAX_INTERRUPTS])(void) =
Video_InterruptHandler_VBL,
Video_InterruptHandler_HBL,
Video_InterruptHandler_EndLine,
- MFP_InterruptHandler_TimerA,
- MFP_InterruptHandler_TimerB,
- MFP_InterruptHandler_TimerC,
- MFP_InterruptHandler_TimerD,
+ MFP_Main_InterruptHandler_TimerA,
+ MFP_Main_InterruptHandler_TimerB,
+ MFP_Main_InterruptHandler_TimerC,
+ MFP_Main_InterruptHandler_TimerD,
+ MFP_TT_InterruptHandler_TimerA,
+ MFP_TT_InterruptHandler_TimerB,
+ MFP_TT_InterruptHandler_TimerC,
+ MFP_TT_InterruptHandler_TimerD,
ACIA_InterruptHandler_IKBD,
IKBD_InterruptHandler_ResetTimer,
IKBD_InterruptHandler_AutoSend,
diff --git a/src/dmaSnd.c b/src/dmaSnd.c
index 7eb41151..acb53633 100644
--- a/src/dmaSnd.c
+++ b/src/dmaSnd.c
@@ -446,8 +446,8 @@ static inline int DmaSnd_EndOfFrameReached(void)
LOG_TRACE(TRACE_DMASND, "DMA snd end of frame\n");
/* Raise end-of-frame interrupts (MFP-i7 and Time-A) */
- MFP_InputOnChannel ( MFP_INT_GPIP7 , 0 );
- MFP_TimerA_EventCount(); /* Update events count / interrupt for timer A if needed */
+ MFP_InputOnChannel ( pMFP_Main , MFP_INT_GPIP7 , 0 );
+ MFP_TimerA_EventCount ( pMFP_Main ); /* Update events count / interrupt for timer A if needed */
if (nDmaSoundControl & DMASNDCTRL_PLAYLOOP)
{
diff --git a/src/falcon/crossbar.c b/src/falcon/crossbar.c
index 19f23780..61f5a537 100644
--- a/src/falcon/crossbar.c
+++ b/src/falcon/crossbar.c
@@ -1534,13 +1534,13 @@ static void Crossbar_Process_DMAPlay_Transfer(void)
{
/* Send a MFP15_Int (I7) at end of replay buffer if enabled */
if (dmaPlay.mfp15_int) {
- MFP_InputOnChannel ( MFP_INT_GPIP7 , 0 );
+ MFP_InputOnChannel ( pMFP_Main , MFP_INT_GPIP7 , 0 );
LOG_TRACE(TRACE_CROSSBAR, "Crossbar : MFP15 (IT7) interrupt from DMA play\n");
}
/* Send a TimerA_Int at end of replay buffer if enabled */
if (dmaPlay.timerA_int) {
- MFP_TimerA_EventCount(); /* Update events count / interrupt for timer A if needed */
+ MFP_TimerA_EventCount ( pMFP_Main ); /* Update events count / interrupt for timer A if needed */
LOG_TRACE(TRACE_CROSSBAR, "Crossbar : MFP Timer A interrupt from DMA play\n");
}
@@ -1628,13 +1628,13 @@ void Crossbar_SendDataToDmaRecord(Sint16 value)
{
/* Send a MFP15_Int (I7) at end of record buffer if enabled */
if (dmaRecord.mfp15_int) {
- MFP_InputOnChannel ( MFP_INT_GPIP7 , 0 );
+ MFP_InputOnChannel ( pMFP_Main , MFP_INT_GPIP7 , 0 );
LOG_TRACE(TRACE_CROSSBAR, "Crossbar : MFP15 (IT7) interrupt from DMA record\n");
}
/* Send a TimerA_Int at end of record buffer if enabled */
if (dmaRecord.timerA_int) {
- MFP_TimerA_EventCount(); /* Update events count / interrupt for timer A if needed */
+ MFP_TimerA_EventCount ( pMFP_Main ); /* Update events count / interrupt for timer A if needed */
LOG_TRACE(TRACE_CROSSBAR, "Crossbar : MFP Timer A interrupt from DMA record\n");
}
diff --git a/src/fdc.c b/src/fdc.c
index c20e35f6..331833ae 100644
--- a/src/fdc.c
+++ b/src/fdc.c
@@ -1829,7 +1829,7 @@ void FDC_SetIRQ ( Uint8 IRQ_Source )
else
{
/* Acknowledge in MFP circuit, pass bit, enable, pending */
- MFP_GPIP_Set_Line_Input ( MFP_GPIP_LINE_FDC_HDC , MFP_GPIP_STATE_LOW );
+ MFP_GPIP_Set_Line_Input ( pMFP_Main , MFP_GPIP_LINE_FDC_HDC , MFP_GPIP_STATE_LOW );
LOG_TRACE(TRACE_FDC, "fdc set irq 0x%x source 0x%x VBL=%d HBL=%d\n" , FDC.IRQ_Signal , IRQ_Source , nVBLs , nHBL );
}
@@ -1865,7 +1865,7 @@ void FDC_ClearIRQ ( void )
if ( ( FDC.IRQ_Signal & FDC_IRQ_SOURCE_FORCED ) == 0 )
{
FDC.IRQ_Signal = 0;
- MFP_GPIP_Set_Line_Input ( MFP_GPIP_LINE_FDC_HDC , MFP_GPIP_STATE_HIGH );
+ MFP_GPIP_Set_Line_Input ( pMFP_Main , MFP_GPIP_LINE_FDC_HDC , MFP_GPIP_STATE_HIGH );
LOG_TRACE(TRACE_FDC, "fdc clear irq VBL=%d HBL=%d\n" , nVBLs , nHBL );
}
@@ -1881,7 +1881,7 @@ void FDC_ClearHdcIRQ(void)
FDC.IRQ_Signal &= ~FDC_IRQ_SOURCE_HDC;
if (FDC.IRQ_Signal == 0)
{
- MFP_GPIP_Set_Line_Input ( MFP_GPIP_LINE_FDC_HDC , MFP_GPIP_STATE_HIGH );
+ MFP_GPIP_Set_Line_Input ( pMFP_Main , MFP_GPIP_LINE_FDC_HDC , MFP_GPIP_STATE_HIGH );
}
}
diff --git a/src/ide.c b/src/ide.c
index 5183d64d..5a36e37e 100644
--- a/src/ide.c
+++ b/src/ide.c
@@ -1120,7 +1120,7 @@ static inline void ide_set_irq(IDEState *s)
if (!(s->cmd & IDE_CMD_DISABLE_IRQ))
{
/* Set IRQ (set line to low) */
- MFP_GPIP_Set_Line_Input ( MFP_GPIP_LINE_FDC_HDC , MFP_GPIP_STATE_LOW );
+ MFP_GPIP_Set_Line_Input ( pMFP_Main , MFP_GPIP_LINE_FDC_HDC , MFP_GPIP_STATE_LOW );
}
}
@@ -2369,7 +2369,7 @@ static uint32_t ide_ioport_read(void *opaque, uint32_t addr1)
ret = s->status;
/* Clear IRQ (set line to high) */
- MFP_GPIP_Set_Line_Input ( MFP_GPIP_LINE_FDC_HDC , MFP_GPIP_STATE_HIGH );
+ MFP_GPIP_Set_Line_Input ( pMFP_Main , MFP_GPIP_LINE_FDC_HDC , MFP_GPIP_STATE_HIGH );
break;
}
LOG_TRACE(TRACE_IDE, "IDE: read addr=0x%x val=%02x\n", addr1, ret);
diff --git a/src/includes/cycInt.h b/src/includes/cycInt.h
index 95c79d50..766dff11 100644
--- a/src/includes/cycInt.h
+++ b/src/includes/cycInt.h
@@ -15,10 +15,14 @@ typedef enum
INTERRUPT_VIDEO_VBL,
INTERRUPT_VIDEO_HBL,
INTERRUPT_VIDEO_ENDLINE,
- INTERRUPT_MFP_TIMERA,
- INTERRUPT_MFP_TIMERB,
- INTERRUPT_MFP_TIMERC,
- INTERRUPT_MFP_TIMERD,
+ INTERRUPT_MFP_MAIN_TIMERA,
+ INTERRUPT_MFP_MAIN_TIMERB,
+ INTERRUPT_MFP_MAIN_TIMERC,
+ INTERRUPT_MFP_MAIN_TIMERD,
+ INTERRUPT_MFP_TT_TIMERA,
+ INTERRUPT_MFP_TT_TIMERB,
+ INTERRUPT_MFP_TT_TIMERC,
+ INTERRUPT_MFP_TT_TIMERD,
INTERRUPT_ACIA_IKBD,
INTERRUPT_IKBD_RESETTIMER,
INTERRUPT_IKBD_AUTOSEND,
diff --git a/src/includes/mfp.h b/src/includes/mfp.h
index e438e069..c8763793 100644
--- a/src/includes/mfp.h
+++ b/src/includes/mfp.h
@@ -68,65 +68,142 @@
#define MFP_GPIP_STATE_HIGH 1
+typedef struct {
+ /* MFP 68901 internal registers */
+ Uint8 GPIP; /* General Purpose Pins / GPDR 0x01 */
+ Uint8 AER; /* Active Edge Register 0x03*/
+ Uint8 DDR; /* Data Direction Register */
+ Uint8 IERA; /* Interrupt Enable Register A 0x07 */
+ Uint8 IERB; /* Interrupt Enable Register B 0x09 */
+ Uint8 IPRA; /* Interrupt Pending Register A 0x0B */
+ Uint8 IPRB; /* Interrupt Pending Register B 0x0D */
+ Uint8 ISRA; /* Interrupt In-Service Register A 0x0F */
+ Uint8 ISRB; /* Interrupt In-Service Register B 0x11 */
+ Uint8 IMRA; /* Interrupt Mask Register A 0x13 */
+ Uint8 IMRB; /* Interrupt Mask Register B 0x15 */
+ Uint8 VR; /* Vector Register 0x17 */
+ Uint8 TACR; /* Timer A Control Register 0x19 */
+ Uint8 TBCR; /* Timer B Control Register 0x1B */
+ Uint8 TCDCR; /* Timer C/D Control Register 0x1D */
+ Uint8 TADR; /* Timer A Data Register 0x1F */
+ Uint8 TBDR; /* Timer B Data Register 0x21 */
+ Uint8 TCDR; /* Timer C Data Register 0x23 */
+ Uint8 TDDR; /* Timer D Data Register 0x25 */
+ Uint8 SCR; /* Synchronous Data Register 0x27 */
+ Uint8 UCR; /* USART Control Register 0x29 */
+ Uint8 RSR; /* Receiver Status Register 0x2B */
+ Uint8 TSR; /* Transmitter Status Register 0x2D */
+ Uint8 UDR; /* USART Data Register 0x2F */
+
+ Uint8 IRQ; /* IRQ signal (output) 1=IRQ requested*/
+
+ /* Emulation variables */
+ Uint8 TA_MAINCOUNTER;
+ Uint8 TB_MAINCOUNTER;
+ Uint8 TC_MAINCOUNTER;
+ Uint8 TD_MAINCOUNTER;
+
+ // TODO drop those 4 variables, as they are not really used in MFP_ReadTimer_xx
+ Uint32 TimerAClockCycles;
+ Uint32 TimerBClockCycles;
+ Uint32 TimerCClockCycles;
+ Uint32 TimerDClockCycles;
+
+ /* If a timer is stopped then restarted later without writing to the data register, */
+ /* we must resume the timer from where we left in the interrupts table, instead of */
+ /* computing a new number of clock cycles to restart the interrupt. */
+ bool TimerACanResume;
+ bool TimerBCanResume;
+ bool TimerCCanResume;
+ bool TimerDCanResume;
+
+ Uint8 PatchTimerD_Done; /* 0=false 1=true */
+ Uint8 PatchTimerD_TDDR_old; /* Value of TDDR before forcing it to PATCH_TIMER_TDDR_FAKE */
+
+ Sint16 Current_Interrupt;
+ Uint64 IRQ_Time; /* Time when IRQ was set to 1 */
+ Uint8 IRQ_CPU; /* Value of IRQ as seen by the CPU. There's a 4 cycle delay */
+ /* between a change of IRQ and its visibility at the CPU side */
+ Uint64 Pending_Time_Min; /* Clock value of the oldest pending int since last MFP_UpdateIRQ() */
+ Uint64 Pending_Time[ MFP_INT_MAX+1 ]; /* Clock value when pending is set to 1 for each non-masked int */
+
+ /* Other variables */
+ char NameSuffix[ 10 ]; /* "" or "_tt" */
+} MFP_STRUCT;
+
+
+#define MFP_MAX_NB 2 /* 1 MFP in all machines, except TT with 2 MFP */
+
+extern MFP_STRUCT MFP_Array[ MFP_MAX_NB ];
+extern MFP_STRUCT *pMFP_Main;
+extern MFP_STRUCT *pMFP_TT;
+
+
/* MFP Registers */
-extern bool MFP_UpdateNeeded;
-
-extern void MFP_Reset(void);
-extern void MFP_MemorySnapShot_Capture(bool bSave);
-
-extern Uint8 MFP_GetIRQ_CPU ( void );
-extern void MFP_DelayIRQ ( void );
-extern int MFP_ProcessIACK ( int OldVecNr );
-extern bool MFP_ProcessIRQ ( void );
-extern void MFP_UpdateIRQ ( Uint64 Event_Time );
-extern void MFP_InputOnChannel ( int Interrupt , int Interrupt_Delayed_Cycles );
-extern void MFP_GPIP_Set_Line_Input ( Uint8 LineNr , Uint8 Bit );
-
-extern void MFP_TimerA_EventCount(void);
-extern void MFP_TimerB_EventCount( int Delayed_Cycles );
-extern void MFP_InterruptHandler_TimerA(void);
-extern void MFP_InterruptHandler_TimerB(void);
-extern void MFP_InterruptHandler_TimerC(void);
-extern void MFP_InterruptHandler_TimerD(void);
-
-extern void MFP_GPIP_ReadByte(void);
-extern void MFP_ActiveEdge_ReadByte(void);
-extern void MFP_DataDirection_ReadByte(void);
-extern void MFP_EnableA_ReadByte(void);
-extern void MFP_EnableB_ReadByte(void);
-extern void MFP_PendingA_ReadByte(void);
-extern void MFP_PendingB_ReadByte(void);
-extern void MFP_InServiceA_ReadByte(void);
-extern void MFP_InServiceB_ReadByte(void);
-extern void MFP_MaskA_ReadByte(void);
-extern void MFP_MaskB_ReadByte(void);
-extern void MFP_VectorReg_ReadByte(void);
-extern void MFP_TimerACtrl_ReadByte(void);
-extern void MFP_TimerBCtrl_ReadByte(void);
-extern void MFP_TimerCDCtrl_ReadByte(void);
-extern void MFP_TimerAData_ReadByte(void);
-extern void MFP_TimerBData_ReadByte(void);
-extern void MFP_TimerCData_ReadByte(void);
-extern void MFP_TimerDData_ReadByte(void);
-
-extern void MFP_GPIP_WriteByte(void);
-extern void MFP_ActiveEdge_WriteByte(void);
-extern void MFP_DataDirection_WriteByte(void);
-extern void MFP_EnableA_WriteByte(void);
-extern void MFP_EnableB_WriteByte(void);
-extern void MFP_PendingA_WriteByte(void);
-extern void MFP_PendingB_WriteByte(void);
-extern void MFP_InServiceA_WriteByte(void);
-extern void MFP_InServiceB_WriteByte(void);
-extern void MFP_MaskA_WriteByte(void);
-extern void MFP_MaskB_WriteByte(void);
-extern void MFP_VectorReg_WriteByte(void);
-extern void MFP_TimerACtrl_WriteByte(void);
-extern void MFP_TimerBCtrl_WriteByte(void);
-extern void MFP_TimerCDCtrl_WriteByte(void);
-extern void MFP_TimerAData_WriteByte(void);
-extern void MFP_TimerBData_WriteByte(void);
-extern void MFP_TimerCData_WriteByte(void);
-extern void MFP_TimerDData_WriteByte(void);
+extern bool MFP_UpdateNeeded;
+
+extern void MFP_Init ( MFP_STRUCT *pAllMFP );
+extern void MFP_Reset_All ( void );
+extern void MFP_MemorySnapShot_Capture ( bool bSave );
+
+extern Uint8 MFP_GetIRQ_CPU ( void );
+extern void MFP_DelayIRQ ( void );
+extern int MFP_ProcessIACK ( int OldVecNr );
+extern bool MFP_ProcessIRQ_All ( void );
+extern void MFP_UpdateIRQ_All ( Uint64 Event_Time );
+extern void MFP_InputOnChannel ( MFP_STRUCT *pMFP , int Interrupt , int Interrupt_Delayed_Cycles );
+extern void MFP_GPIP_Set_Line_Input ( MFP_STRUCT *pMFP , Uint8 LineNr , Uint8 Bit );
+
+extern void MFP_TimerA_EventCount( MFP_STRUCT *pMFP );
+extern void MFP_TimerB_EventCount( MFP_STRUCT *pMFP , int Delayed_Cycles );
+
+extern void MFP_Main_InterruptHandler_TimerA(void);
+extern void MFP_Main_InterruptHandler_TimerB(void);
+extern void MFP_Main_InterruptHandler_TimerC(void);
+extern void MFP_Main_InterruptHandler_TimerD(void);
+extern void MFP_TT_InterruptHandler_TimerA(void);
+extern void MFP_TT_InterruptHandler_TimerB(void);
+extern void MFP_TT_InterruptHandler_TimerC(void);
+extern void MFP_TT_InterruptHandler_TimerD(void);
+
+extern void MFP_GPIP_ReadByte ( void );
+extern void MFP_ActiveEdge_ReadByte ( void );
+extern void MFP_DataDirection_ReadByte ( void );
+extern void MFP_EnableA_ReadByte ( void );
+extern void MFP_EnableB_ReadByte ( void );
+extern void MFP_PendingA_ReadByte ( void );
+extern void MFP_PendingB_ReadByte ( void );
+extern void MFP_InServiceA_ReadByte ( void );
+extern void MFP_InServiceB_ReadByte ( void );
+extern void MFP_MaskA_ReadByte ( void );
+extern void MFP_MaskB_ReadByte ( void );
+extern void MFP_VectorReg_ReadByte ( void );
+extern void MFP_TimerACtrl_ReadByte ( void );
+extern void MFP_TimerBCtrl_ReadByte ( void );
+extern void MFP_TimerCDCtrl_ReadByte ( void );
+extern void MFP_TimerAData_ReadByte ( void );
+extern void MFP_TimerBData_ReadByte ( void );
+extern void MFP_TimerCData_ReadByte ( void );
+extern void MFP_TimerDData_ReadByte ( void );
+
+extern void MFP_GPIP_WriteByte ( void );
+extern void MFP_ActiveEdge_WriteByte ( void );
+extern void MFP_DataDirection_WriteByte ( void );
+extern void MFP_EnableA_WriteByte ( void );
+extern void MFP_EnableB_WriteByte ( void );
+extern void MFP_PendingA_WriteByte ( void );
+extern void MFP_PendingB_WriteByte ( void );
+extern void MFP_InServiceA_WriteByte ( void );
+extern void MFP_InServiceB_WriteByte ( void );
+extern void MFP_MaskA_WriteByte ( void );
+extern void MFP_MaskB_WriteByte ( void );
+extern void MFP_VectorReg_WriteByte ( void );
+extern void MFP_TimerACtrl_WriteByte ( void );
+extern void MFP_TimerBCtrl_WriteByte ( void );
+extern void MFP_TimerCDCtrl_WriteByte ( void );
+extern void MFP_TimerAData_WriteByte ( void );
+extern void MFP_TimerBData_WriteByte ( void );
+extern void MFP_TimerCData_WriteByte ( void );
+extern void MFP_TimerDData_WriteByte ( void );
#endif
diff --git a/src/includes/ncr5380.h b/src/includes/ncr5380.h
index f24f0688..a9a32f09 100644
--- a/src/includes/ncr5380.h
+++ b/src/includes/ncr5380.h
@@ -17,6 +17,6 @@ void Ncr5380_DmaTransfer_Falcon(void);
void Ncr5380_IoMemTT_WriteByte(void);
void Ncr5380_IoMemTT_ReadByte(void);
void Ncr5380_TT_DMA_Ctrl_WriteWord(void);
-void Ncr5380_TT_GPIP_ReadByte(void);
+bool Ncr5380_TT_GetIRQ(void);
#endif
diff --git a/src/ioMemTabTT.c b/src/ioMemTabTT.c
index d33345c8..c0b7f5ee 100644
--- a/src/ioMemTabTT.c
+++ b/src/ioMemTabTT.c
@@ -228,31 +228,30 @@ const INTERCEPT_ACCESS_FUNC IoMemTable_TT[] =
{ 0xfffa3d, SIZE_BYTE, IoMem_VoidRead, IoMem_VoidWrite }, /* No bus error here */
{ 0xfffa3f, SIZE_BYTE, IoMem_VoidRead, IoMem_VoidWrite }, /* No bus error here */
- /* TODO: Second MFP of the TT ... */
- { 0xfffa81, SIZE_BYTE, Ncr5380_TT_GPIP_ReadByte, IoMem_VoidWrite }, /* TT MFP GPIP */
- { 0xfffa83, SIZE_BYTE, IoMem_VoidRead, IoMem_VoidWrite }, /* TT MFP AER */
- { 0xfffa85, SIZE_BYTE, IoMem_VoidRead, IoMem_VoidWrite }, /* TT MFP DDR */
- { 0xfffa87, SIZE_BYTE, IoMem_VoidRead, IoMem_VoidWrite }, /* TT MFP IERA */
- { 0xfffa89, SIZE_BYTE, IoMem_VoidRead, IoMem_VoidWrite }, /* TT MFP IERB */
- { 0xfffa8b, SIZE_BYTE, IoMem_VoidRead, IoMem_VoidWrite }, /* TT MFP IPRA */
- { 0xfffa8d, SIZE_BYTE, IoMem_VoidRead, IoMem_VoidWrite }, /* TT MFP IPRB */
- { 0xfffa8f, SIZE_BYTE, IoMem_VoidRead, IoMem_VoidWrite }, /* TT MFP ISRA */
- { 0xfffa91, SIZE_BYTE, IoMem_VoidRead, IoMem_VoidWrite }, /* TT MFP ISRB */
- { 0xfffa93, SIZE_BYTE, IoMem_VoidRead, IoMem_VoidWrite }, /* TT MFP IMRA */
- { 0xfffa95, SIZE_BYTE, IoMem_VoidRead, IoMem_VoidWrite }, /* TT MFP IMRB */
- { 0xfffa97, SIZE_BYTE, IoMem_VoidRead, IoMem_VoidWrite }, /* TT MFP VR */
- { 0xfffa99, SIZE_BYTE, IoMem_VoidRead, IoMem_VoidWrite }, /* TT MFP TACR */
- { 0xfffa9b, SIZE_BYTE, IoMem_VoidRead, IoMem_VoidWrite }, /* TT MFP TBCR */
- { 0xfffa9d, SIZE_BYTE, IoMem_VoidRead, IoMem_VoidWrite }, /* TT MFP TCDCR */
- { 0xfffa9f, SIZE_BYTE, IoMem_VoidRead, IoMem_VoidWrite }, /* TT MFP TADR */
- { 0xfffaa1, SIZE_BYTE, IoMem_VoidRead, IoMem_VoidWrite }, /* TT MFP TBDR */
- { 0xfffaa3, SIZE_BYTE, IoMem_VoidRead, IoMem_VoidWrite }, /* TT MFP TCDR */
- { 0xfffaa5, SIZE_BYTE, IoMem_VoidRead, IoMem_VoidWrite }, /* TT MFP TDDR */
- { 0xfffaa7, SIZE_BYTE, IoMem_VoidRead, IoMem_VoidWrite }, /* TT MFP SCR */
- { 0xfffaa9, SIZE_BYTE, IoMem_VoidRead, IoMem_VoidWrite }, /* TT MFP UCR */
- { 0xfffaab, SIZE_BYTE, IoMem_VoidRead, IoMem_VoidWrite }, /* TT MFP RSR */
- { 0xfffaad, SIZE_BYTE, IoMem_VoidRead, IoMem_VoidWrite }, /* TT MFP TSR */
- { 0xfffaaf, SIZE_BYTE, IoMem_VoidRead, IoMem_VoidWrite }, /* TT MFP UDR */
+ { 0xfffa81, SIZE_BYTE, MFP_GPIP_ReadByte, MFP_GPIP_WriteByte }, /* TT MFP GPIP */
+ { 0xfffa83, SIZE_BYTE, MFP_ActiveEdge_ReadByte, MFP_ActiveEdge_WriteByte }, /* TT MFP AER */
+ { 0xfffa85, SIZE_BYTE, MFP_DataDirection_ReadByte, MFP_DataDirection_WriteByte /* TT MFP DDR */},
+ { 0xfffa87, SIZE_BYTE, MFP_EnableA_ReadByte, MFP_EnableA_WriteByte }, /* TT MFP IERA */
+ { 0xfffa89, SIZE_BYTE, MFP_EnableB_ReadByte, MFP_EnableB_WriteByte }, /* TT MFP IERB */
+ { 0xfffa8b, SIZE_BYTE, MFP_PendingA_ReadByte, MFP_PendingA_WriteByte }, /* TT MFP IPRA */
+ { 0xfffa8d, SIZE_BYTE, MFP_PendingB_ReadByte, MFP_PendingB_WriteByte }, /* TT MFP IPRB */
+ { 0xfffa8f, SIZE_BYTE, MFP_InServiceA_ReadByte, MFP_InServiceA_WriteByte }, /* TT MFP ISRA */
+ { 0xfffa91, SIZE_BYTE, MFP_InServiceB_ReadByte, MFP_InServiceB_WriteByte }, /* TT MFP ISRB */
+ { 0xfffa93, SIZE_BYTE, MFP_MaskA_ReadByte, MFP_MaskA_WriteByte }, /* TT MFP IMRA */
+ { 0xfffa95, SIZE_BYTE, MFP_MaskB_ReadByte, MFP_MaskB_WriteByte }, /* TT MFP IMRB */
+ { 0xfffa97, SIZE_BYTE, MFP_VectorReg_ReadByte, MFP_VectorReg_WriteByte }, /* TT MFP VR */
+ { 0xfffa99, SIZE_BYTE, MFP_TimerACtrl_ReadByte, MFP_TimerACtrl_WriteByte }, /* TT MFP TACR */
+ { 0xfffa9b, SIZE_BYTE, MFP_TimerBCtrl_ReadByte, MFP_TimerBCtrl_WriteByte }, /* TT MFP TBCR */
+ { 0xfffa9d, SIZE_BYTE, MFP_TimerCDCtrl_ReadByte, MFP_TimerCDCtrl_WriteByte }, /* TT MFP TCDCR */
+ { 0xfffa9f, SIZE_BYTE, MFP_TimerAData_ReadByte, MFP_TimerAData_WriteByte }, /* TT MFP TADR */
+ { 0xfffaa1, SIZE_BYTE, MFP_TimerBData_ReadByte, MFP_TimerBData_WriteByte }, /* TT MFP TBDR */
+ { 0xfffaa3, SIZE_BYTE, MFP_TimerCData_ReadByte, MFP_TimerCData_WriteByte }, /* TT MFP TCDR */
+ { 0xfffaa5, SIZE_BYTE, MFP_TimerDData_ReadByte, MFP_TimerDData_WriteByte }, /* TT MFP TDDR */
+ { 0xfffaa7, SIZE_BYTE, IoMem_VoidRead, IoMem_VoidWrite }, /* TT MFP SCR */
+ { 0xfffaa9, SIZE_BYTE, IoMem_VoidRead, IoMem_VoidWrite }, /* TT MFP UCR */
+ { 0xfffaab, SIZE_BYTE, IoMem_VoidRead, IoMem_VoidWrite }, /* TT MFP RSR */
+ { 0xfffaad, SIZE_BYTE, IoMem_VoidRead, IoMem_VoidWrite }, /* TT MFP TSR */
+ { 0xfffaaf, SIZE_BYTE, IoMem_VoidRead, IoMem_VoidWrite }, /* TT MFP UDR */
{ 0xfffab1, SIZE_BYTE, IoMem_VoidRead, IoMem_VoidWrite }, /* No bus error here */
{ 0xfffab3, SIZE_BYTE, IoMem_VoidRead, IoMem_VoidWrite }, /* No bus error here */
diff --git a/src/main.c b/src/main.c
index 5e1586fa..045b7a00 100644
--- a/src/main.c
+++ b/src/main.c
@@ -24,6 +24,7 @@ const char Main_fileid[] = "Hatari main.c : " __DATE__ " " __TIME__;
#include "floppy_ipf.h"
#include "floppy_stx.h"
#include "gemdos.h"
+#include "mfp.h"
#include "fdc.h"
#include "hdc.h"
#include "ide.h"
@@ -746,6 +747,7 @@ static void Main_Init(void)
ACIA_Init( ACIA_Array , MachineClocks.ACIA_Freq , MachineClocks.ACIA_Freq );
IKBD_Init(); /* After ACIA_Init */
+ MFP_Init ( MFP_Array );
DSP_Init();
Floppy_Init();
M68000_Init(); /* Init CPU emulation */
diff --git a/src/mfp.c b/src/mfp.c
index 7c39fdcc..3b44555d 100644
--- a/src/mfp.c
+++ b/src/mfp.c
@@ -150,6 +150,7 @@ const char MFP_fileid[] = "Hatari mfp.c : " __DATE__ " " __TIME__;
#include "vdi.h"
#include "screen.h"
#include "video.h"
+#include "ncr5380.h"
/*
@@ -172,73 +173,55 @@ Input -----/ | ------------------------ |
/*
Emulation Note :
+
- MFP emulation doesn't run in parallel with the CPU emulation as it would take too much resources.
Instead, MFP emulation is called each time a CPU instruction is completely processed.
The drawback is that several MFP interrupts can happen during a single CPU instruction (especially
for long ones like MOVEM or DIV). In that case, we should not choose the highest priority interrupt
among all the interrupts, but we should keep only the interrupts that chronologically happened first
during this CPU instruction (and ignore the other interrupts' requests for this CPU instruction).
+
- When the MFP's main IRQ signal goes from 0 to 1, the signal is not immediately visible to the CPU, but only
4 cycles later. This 4 cycle delay should be taken into account, depending at what time the signal
went to 1 in the corresponding CPU instruction (the 4 cycle delay can be "included" in the CPU instruction
in some cases)
+
- When an interrupt happens in the MFP, an exception will be started in the CPU. Then after 12 cycles an IACK
sequence will be started by the CPU to request the interrupt vector from the MFP. During those 12 cycles,
it is possible that a new higher priority MFP interrupt happens and in that case we must replace the MFP
vector number that was initially computed at the start of the exception with the new one.
This is also after the IACK sequence that in service / pending bits must be handled for this MFP's interrupt.
+
+ - The TT uses 2 MFP which are daisy chained using IEI and IEO signals (as described in the 68901's documentation)
+ In that case, the TT's specific MFP (accessible between $FFFA81 and $FFFAAF) has the highest priority
+ and the "normal" MFP (accessible between $FFFA01 and $FFFA2F) has the lowest priority
+
*/
/*-----------------------------------------------------------------------*/
-/* MFP Registers */
-Uint8 MFP_GPIP; /* General Purpose Pins */
-Uint8 MFP_VR; /* Vector Register 0xfffa17 */
-Uint8 MFP_IERA,MFP_IERB; /* Interrupt Enable Registers A,B 0xfffa07,0xfffa09 */
-Uint8 MFP_IPRA,MFP_IPRB; /* Interrupt Pending Registers A,B 0xfffa0b,0xfffa0d */
-Uint8 MFP_TACR,MFP_TBCR; /* Timer A,B Control Registers */
-
-static Uint8 MFP_TCDCR; /* C+D Control Registers */
-static Uint8 MFP_AER,MFP_DDR; /* Active Edge Register, Data Direction Register */
-static Uint8 MFP_ISRA,MFP_ISRB; /* Interrupt In-Service Registers A,B 0xfffa0f,0xfffa11 */
-static Uint8 MFP_IMRA,MFP_IMRB; /* Interrupt Mask Registers A,B 0xfffa13,0xfffa15 */
-static Uint8 MFP_TADR,MFP_TBDR; /* Timer A,B Data Registers */
-static Uint8 MFP_TCDR,MFP_TDDR; /* Timer C,D Data Registers */
-static Uint8 MFP_TA_MAINCOUNTER; /* Timer A Main Counter (internal to MFP) */
-static Uint8 MFP_TB_MAINCOUNTER; /* Timer B Main Counter */
-static Uint8 MFP_TC_MAINCOUNTER; /* Timer C Main Counter (these are temp's, set when read as) */
-static Uint8 MFP_TD_MAINCOUNTER; /* Timer D Main Counter (as done via interrupts) */
-
-/* CPU clock cycle counts for each timer */
-static int TimerAClockCycles=0;
-static int TimerBClockCycles=0;
-static int TimerCClockCycles=0;
-static int TimerDClockCycles=0;
-
-/* If a timer is stopped then restarted later without writing to the data register, */
-/* we must resume the timer from where we left in the interrupts table, instead of */
-/* computing a new number of clock cycles to restart the interrupt. */
-static bool TimerACanResume = false;
-static bool TimerBCanResume = false;
-static bool TimerCCanResume = false;
-static bool TimerDCanResume = false;
+
+#define TRACE_MFP (1ll<<55)
+
+
+
+MFP_STRUCT MFP_Array[ MFP_MAX_NB ];
+MFP_STRUCT *pMFP_Main;
+MFP_STRUCT *pMFP_TT;
+
static bool bAppliedTimerDPatch; /* true if the Timer-D patch has been applied */
-static int nTimerDFakeValue; /* Faked Timer-D data register for the Timer-D patch */
+
+#define PATCH_TIMERD_TDDR_FAKE 0x64 /* TDDR value to slow down timer D */
+
static int PendingCyclesOver = 0; /* >= 0 value, used to "loop" a timer when data counter reaches 0 */
+bool MFP_UpdateNeeded = false; /* When set to true, main CPU loop should call MFP_UpdateIRQ() */
+
#define MFP_IRQ_DELAY_TO_CPU 4 /* When MFP_IRQ is set, it takes 4 CPU cycles before it's visible to the CPU */
-static int MFP_Current_Interrupt = -1;
-static Uint8 MFP_IRQ = 0;
-static Uint64 MFP_IRQ_Time = 0;
-static Uint8 MFP_IRQ_CPU = 0; /* Value of MFP_IRQ as seen by the CPU. There's a 4 cycle delay */
- /* between a change of MFP_IRQ and its visibility at the CPU side */
-bool MFP_UpdateNeeded = false; /* When set to true, main CPU loop should call MFP_UpdateIRQ() */
-static Uint64 MFP_Pending_Time_Min; /* Clock value of the oldest pending int since last MFP_UpdateIRQ() */
-static Uint64 MFP_Pending_Time[ MFP_INT_MAX+1 ]; /* Clock value when pending is set to 1 for each non-masked int */
static const Uint16 MFPDiv[] =
{
@@ -270,11 +253,67 @@ static const int MFP_GPIP_LineToIntNumber[] = { MFP_INT_GPIP0 , MFP_INT_GPIP1 ,
/* Local functions prototypes */
/*--------------------------------------------------------------*/
-static Uint8 MFP_ConvertIntNumber ( int Interrupt , Uint8 **pMFP_IER , Uint8 **pMFP_IPR , Uint8 **pMFP_ISR , Uint8 **pMFP_IMR );
-static void MFP_Exception ( int Interrupt );
-static bool MFP_InterruptRequest ( int Int , Uint8 Bit , Uint8 IPRx , Uint8 IMRx , Uint8 PriorityMaskA , Uint8 PriorityMaskB );
-static int MFP_CheckPendingInterrupts ( void );
-static void MFP_GPIP_Update_Interrupt ( Uint8 GPIP_old , Uint8 GPIP_new , Uint8 AER_old , Uint8 AER_new , Uint8 DDR_old , Uint8 DDR_new );
+static void MFP_Init_Pointers ( MFP_STRUCT *pAllMFP );
+static void MFP_Reset ( MFP_STRUCT *pMFP );
+
+static Uint8 MFP_ConvertIntNumber ( MFP_STRUCT *pMFP , Sint16 Interrupt , Uint8 **pMFP_IER , Uint8 **pMFP_IPR , Uint8 **pMFP_ISR , Uint8 **pMFP_IMR );
+static void MFP_Exception ( MFP_STRUCT *pMFP , Sint16 Interrupt );
+static bool MFP_ProcessIRQ ( MFP_STRUCT *pMFP );
+static void MFP_UpdateIRQ ( MFP_STRUCT *pMFP , Uint64 Event_Time );
+static bool MFP_InterruptRequest ( MFP_STRUCT *pMFP , int Int , Uint8 Bit , Uint8 IPRx , Uint8 IMRx , Uint8 PriorityMaskA , Uint8 PriorityMaskB );
+static int MFP_CheckPendingInterrupts ( MFP_STRUCT *pMFP );
+static void MFP_GPIP_Update_Interrupt ( MFP_STRUCT *pMFP , Uint8 GPIP_old , Uint8 GPIP_new , Uint8 AER_old , Uint8 AER_new , Uint8 DDR_old , Uint8 DDR_new );
+
+static void MFP_GPIP_ReadByte_Main ( MFP_STRUCT *pMFP );
+static void MFP_GPIP_ReadByte_TT ( MFP_STRUCT *pMFP );
+
+
+
+/*-----------------------------------------------------------------------*/
+/**
+ * Init the 2 MFPs ; the 2nd MFP is only used in TT mode
+ * This is called only once, when the emulator starts.
+ */
+void MFP_Init ( MFP_STRUCT *pAllMFP )
+{
+ int i;
+
+
+ LOG_TRACE ( TRACE_MFP , "mfp init\n" );
+
+ for ( i=0 ; i<MFP_MAX_NB ; i++ )
+ {
+ memset ( (void *)&(pAllMFP[ i ]) , 0 , sizeof ( MFP_STRUCT ) );
+ }
+
+ /* Set the default common callback functions + other pointers */
+ MFP_Init_Pointers ( pAllMFP );
+}
+
+
+
+/*-----------------------------------------------------------------------*/
+/**
+ * Init some functions/memory pointers for each MFP.
+ * This is called at Init and when restoring a memory snapshot.
+ */
+static void MFP_Init_Pointers ( MFP_STRUCT *pAllMFP )
+{
+ int i;
+
+
+ for ( i=0 ; i<MFP_MAX_NB ; i++ )
+ {
+ /* Set the default common callback functions */
+ }
+
+ strcpy ( pAllMFP[ 0 ].NameSuffix , "" ); /* No suffix for main MFP */
+ strcpy ( pAllMFP[ 1 ].NameSuffix , "_tt" );
+
+ pMFP_Main = &(pAllMFP[ 0 ]);
+ pMFP_TT = &(pAllMFP[ 1 ]);
+}
+
@@ -282,40 +321,73 @@ static void MFP_GPIP_Update_Interrupt ( Uint8 GPIP_old , Uint8 GPIP_new , Uint8
/**
* Reset all MFP variables and start interrupts on their way!
*/
-void MFP_Reset(void)
+void MFP_Reset_All ( void )
{
int i;
/* Reset MFP internal variables */
-
bAppliedTimerDPatch = false;
- MFP_GPIP = 0;
- MFP_AER = MFP_DDR = 0;
- MFP_IERA = MFP_IERB = 0;
- MFP_IPRA = MFP_IPRB = 0;
- MFP_ISRA = MFP_ISRB = 0;
- MFP_IMRA = MFP_IMRB = 0;
- MFP_VR = 0;
- MFP_TACR = MFP_TBCR = MFP_TCDCR = 0;
- MFP_TADR = MFP_TBDR = 0;
- MFP_TCDR = MFP_TDDR = 0;
- MFP_TA_MAINCOUNTER = MFP_TB_MAINCOUNTER = 0;
- MFP_TC_MAINCOUNTER = MFP_TD_MAINCOUNTER = 0;
+ for ( i=0 ; i<MFP_MAX_NB ; i++ )
+ {
+ MFP_Reset ( &(MFP_Array[ i ]) );
+ }
+
+}
+
+
+
+static void MFP_Reset ( MFP_STRUCT *pMFP )
+{
+ int i;
+
+ pMFP->GPIP = 0;
+ pMFP->AER = 0;
+ pMFP->DDR = 0;
+ pMFP->IERA = 0;
+ pMFP->IERB = 0;
+ pMFP->IPRA = 0;
+ pMFP->IPRB = 0;
+ pMFP->ISRA = 0;
+ pMFP->ISRB = 0;
+ pMFP->IMRA = 0;
+ pMFP->IMRB = 0;
+ pMFP->VR = 0;
+ pMFP->TACR = 0;
+ pMFP->TBCR = 0;
+ pMFP->TCDCR = 0;
+ pMFP->TADR = 0;
+ pMFP->TBDR = 0;
+ pMFP->TCDR = 0;
+ pMFP->TDDR = 0;
+
+ pMFP->TA_MAINCOUNTER = 0;
+ pMFP->TB_MAINCOUNTER = 0;
+ pMFP->TC_MAINCOUNTER = 0;
+ pMFP->TD_MAINCOUNTER = 0;
+
+ pMFP->TimerACanResume = false;
+ pMFP->TimerBCanResume = false;
+ pMFP->TimerCCanResume = false;
+ pMFP->TimerDCanResume = false;
/* Clear counters */
- TimerAClockCycles = TimerBClockCycles = 0;
- TimerCClockCycles = TimerDClockCycles = 0;
+ pMFP->TimerAClockCycles = 0;
+ pMFP->TimerBClockCycles = 0;
+ pMFP->TimerCClockCycles = 0;
+ pMFP->TimerDClockCycles = 0;
+
+ pMFP->PatchTimerD_Done = 0;
/* Clear IRQ */
- MFP_Current_Interrupt = -1;
- MFP_IRQ = 0;
- MFP_IRQ_CPU = 0;
- MFP_IRQ_Time = 0;
- MFP_UpdateNeeded = false;
- MFP_Pending_Time_Min = UINT64_MAX;
+ pMFP->Current_Interrupt = -1;
+ pMFP->IRQ = 0;
+ pMFP->IRQ_CPU = 0;
+ pMFP->IRQ_Time = 0;
+ pMFP->Pending_Time_Min = UINT64_MAX;
for ( i=0 ; i<=MFP_INT_MAX ; i++ )
- MFP_Pending_Time[ i ] = UINT64_MAX;
+ pMFP->Pending_Time[ i ] = UINT64_MAX;
+
}
@@ -323,47 +395,68 @@ void MFP_Reset(void)
/**
* Save/Restore snapshot of local variables('MemorySnapShot_Store' handles type)
*/
-void MFP_MemorySnapShot_Capture(bool bSave)
-{
- /* Save/Restore details */
- MemorySnapShot_Store(&MFP_GPIP, sizeof(MFP_GPIP));
- MemorySnapShot_Store(&MFP_AER, sizeof(MFP_AER));
- MemorySnapShot_Store(&MFP_DDR, sizeof(MFP_DDR));
- MemorySnapShot_Store(&MFP_IERA, sizeof(MFP_IERA));
- MemorySnapShot_Store(&MFP_IERB, sizeof(MFP_IERB));
- MemorySnapShot_Store(&MFP_IPRA, sizeof(MFP_IPRA));
- MemorySnapShot_Store(&MFP_IPRB, sizeof(MFP_IPRB));
- MemorySnapShot_Store(&MFP_ISRA, sizeof(MFP_ISRA));
- MemorySnapShot_Store(&MFP_ISRB, sizeof(MFP_ISRB));
- MemorySnapShot_Store(&MFP_IMRA, sizeof(MFP_IMRA));
- MemorySnapShot_Store(&MFP_IMRB, sizeof(MFP_IMRB));
- MemorySnapShot_Store(&MFP_VR, sizeof(MFP_VR));
- MemorySnapShot_Store(&MFP_TACR, sizeof(MFP_TACR));
- MemorySnapShot_Store(&MFP_TBCR, sizeof(MFP_TBCR));
- MemorySnapShot_Store(&MFP_TCDCR, sizeof(MFP_TCDCR));
- MemorySnapShot_Store(&MFP_TADR, sizeof(MFP_TADR));
- MemorySnapShot_Store(&MFP_TBDR, sizeof(MFP_TBDR));
- MemorySnapShot_Store(&MFP_TCDR, sizeof(MFP_TCDR));
- MemorySnapShot_Store(&MFP_TDDR, sizeof(MFP_TDDR));
- MemorySnapShot_Store(&MFP_TA_MAINCOUNTER, sizeof(MFP_TA_MAINCOUNTER));
- MemorySnapShot_Store(&MFP_TB_MAINCOUNTER, sizeof(MFP_TB_MAINCOUNTER));
- MemorySnapShot_Store(&MFP_TC_MAINCOUNTER, sizeof(MFP_TC_MAINCOUNTER));
- MemorySnapShot_Store(&MFP_TD_MAINCOUNTER, sizeof(MFP_TD_MAINCOUNTER));
- MemorySnapShot_Store(&TimerAClockCycles, sizeof(TimerAClockCycles));
- MemorySnapShot_Store(&TimerBClockCycles, sizeof(TimerBClockCycles));
- MemorySnapShot_Store(&TimerCClockCycles, sizeof(TimerCClockCycles));
- MemorySnapShot_Store(&TimerDClockCycles, sizeof(TimerDClockCycles));
- MemorySnapShot_Store(&TimerACanResume, sizeof(TimerACanResume));
- MemorySnapShot_Store(&TimerBCanResume, sizeof(TimerBCanResume));
- MemorySnapShot_Store(&TimerCCanResume, sizeof(TimerCCanResume));
- MemorySnapShot_Store(&TimerDCanResume, sizeof(TimerDCanResume));
- MemorySnapShot_Store(&MFP_Current_Interrupt, sizeof(MFP_Current_Interrupt));
- MemorySnapShot_Store(&MFP_IRQ, sizeof(MFP_IRQ));
- MemorySnapShot_Store(&MFP_IRQ_Time, sizeof(MFP_IRQ_Time));
- MemorySnapShot_Store(&MFP_IRQ_CPU, sizeof(MFP_IRQ_CPU));
+void MFP_MemorySnapShot_Capture ( bool bSave )
+{
+ MFP_STRUCT *pMFP;
+ int i;
+ int n;
+
MemorySnapShot_Store(&MFP_UpdateNeeded, sizeof(MFP_UpdateNeeded));
- MemorySnapShot_Store(&MFP_Pending_Time_Min, sizeof(MFP_Pending_Time_Min));
- MemorySnapShot_Store(&MFP_Pending_Time, sizeof(MFP_Pending_Time));
+
+ /* Save/Restore each MFP */
+ for ( n=0 ; n<MFP_MAX_NB ; n++ )
+ {
+ pMFP = &(MFP_Array[ n ]);
+
+ MemorySnapShot_Store(&(pMFP->GPIP), sizeof(pMFP->GPIP));
+ MemorySnapShot_Store(&(pMFP->AER), sizeof(pMFP->AER));
+ MemorySnapShot_Store(&(pMFP->DDR), sizeof(pMFP->DDR));
+ MemorySnapShot_Store(&(pMFP->IERA), sizeof(pMFP->IERA));
+ MemorySnapShot_Store(&(pMFP->IERB), sizeof(pMFP->IERB));
+ MemorySnapShot_Store(&(pMFP->IPRA), sizeof(pMFP->IPRA));
+ MemorySnapShot_Store(&(pMFP->IPRB), sizeof(pMFP->IPRB));
+ MemorySnapShot_Store(&(pMFP->ISRA), sizeof(pMFP->ISRA));
+ MemorySnapShot_Store(&(pMFP->ISRB), sizeof(pMFP->ISRB));
+ MemorySnapShot_Store(&(pMFP->IMRA), sizeof(pMFP->IMRA));
+ MemorySnapShot_Store(&(pMFP->IMRB), sizeof(pMFP->IMRB));
+ MemorySnapShot_Store(&(pMFP->VR), sizeof(pMFP->VR));
+ MemorySnapShot_Store(&(pMFP->TACR), sizeof(pMFP->TACR));
+ MemorySnapShot_Store(&(pMFP->TBCR), sizeof(pMFP->TBCR));
+ MemorySnapShot_Store(&(pMFP->TCDCR), sizeof(pMFP->TCDCR));
+ MemorySnapShot_Store(&(pMFP->TADR), sizeof(pMFP->TADR));
+ MemorySnapShot_Store(&(pMFP->TBDR), sizeof(pMFP->TBDR));
+ MemorySnapShot_Store(&(pMFP->TCDR), sizeof(pMFP->TCDR));
+ MemorySnapShot_Store(&(pMFP->TDDR), sizeof(pMFP->TDDR));
+
+ MemorySnapShot_Store(&(pMFP->TA_MAINCOUNTER), sizeof(pMFP->TA_MAINCOUNTER));
+ MemorySnapShot_Store(&(pMFP->TB_MAINCOUNTER), sizeof(pMFP->TB_MAINCOUNTER));
+ MemorySnapShot_Store(&(pMFP->TC_MAINCOUNTER), sizeof(pMFP->TC_MAINCOUNTER));
+ MemorySnapShot_Store(&(pMFP->TD_MAINCOUNTER), sizeof(pMFP->TD_MAINCOUNTER));
+
+ MemorySnapShot_Store(&(pMFP->TimerACanResume), sizeof(pMFP->TimerACanResume));
+ MemorySnapShot_Store(&(pMFP->TimerBCanResume), sizeof(pMFP->TimerBCanResume));
+ MemorySnapShot_Store(&(pMFP->TimerCCanResume), sizeof(pMFP->TimerCCanResume));
+ MemorySnapShot_Store(&(pMFP->TimerDCanResume), sizeof(pMFP->TimerDCanResume));
+
+ MemorySnapShot_Store(&(pMFP->TimerAClockCycles), sizeof(pMFP->TimerAClockCycles));
+ MemorySnapShot_Store(&(pMFP->TimerBClockCycles), sizeof(pMFP->TimerBClockCycles));
+ MemorySnapShot_Store(&(pMFP->TimerCClockCycles), sizeof(pMFP->TimerCClockCycles));
+ MemorySnapShot_Store(&(pMFP->TimerDClockCycles), sizeof(pMFP->TimerDClockCycles));
+
+ MemorySnapShot_Store(&(pMFP->PatchTimerD_Done), sizeof(pMFP->PatchTimerD_Done));
+ MemorySnapShot_Store(&(pMFP->PatchTimerD_TDDR_old), sizeof(pMFP->PatchTimerD_TDDR_old));
+
+ MemorySnapShot_Store(&(pMFP->Current_Interrupt), sizeof(pMFP->Current_Interrupt));
+ MemorySnapShot_Store(&(pMFP->IRQ), sizeof(pMFP->IRQ));
+ MemorySnapShot_Store(&(pMFP->IRQ_CPU), sizeof(pMFP->IRQ_CPU));
+ MemorySnapShot_Store(&(pMFP->IRQ_Time), sizeof(pMFP->IRQ_Time));
+ MemorySnapShot_Store(&(pMFP->Pending_Time_Min), sizeof(pMFP->Pending_Time_Min));
+ for ( i=0 ; i<=MFP_INT_MAX ; i++ )
+ MemorySnapShot_Store(&(pMFP->Pending_Time[ i ]), sizeof(pMFP->Pending_Time[ i ]));
+ }
+
+ if ( !bSave ) /* If restoring */
+ MFP_Init_Pointers ( MFP_Array ); /* Restore pointers */
}
@@ -375,25 +468,25 @@ void MFP_MemorySnapShot_Capture(bool bSave)
* to set/clear these registers.
* If an input pointer is NULL, we don't return the corresponding register.
*/
-static Uint8 MFP_ConvertIntNumber ( int Interrupt , Uint8 **pMFP_IER , Uint8 **pMFP_IPR , Uint8 **pMFP_ISR , Uint8 **pMFP_IMR )
+static Uint8 MFP_ConvertIntNumber ( MFP_STRUCT *pMFP , Sint16 Interrupt , Uint8 **pMFP_IER , Uint8 **pMFP_IPR , Uint8 **pMFP_ISR , Uint8 **pMFP_IMR )
{
Uint8 Bit;
if ( Interrupt > 7 )
{
Bit = 1 << ( Interrupt - 8 );
- if ( pMFP_IER ) *pMFP_IER = &MFP_IERA;
- if ( pMFP_IPR ) *pMFP_IPR = &MFP_IPRA;
- if ( pMFP_ISR ) *pMFP_ISR = &MFP_ISRA;
- if ( pMFP_IMR ) *pMFP_IMR = &MFP_IMRA;
+ if ( pMFP_IER ) *pMFP_IER = &(pMFP->IERA);
+ if ( pMFP_IPR ) *pMFP_IPR = &(pMFP->IPRA);
+ if ( pMFP_ISR ) *pMFP_ISR = &(pMFP->ISRA);
+ if ( pMFP_IMR ) *pMFP_IMR = &(pMFP->IMRA);
}
else
{
Bit = 1 << Interrupt;
- if ( pMFP_IER ) *pMFP_IER = &MFP_IERB;
- if ( pMFP_IPR ) *pMFP_IPR = &MFP_IPRB;
- if ( pMFP_ISR ) *pMFP_ISR = &MFP_ISRB;
- if ( pMFP_IMR ) *pMFP_IMR = &MFP_IMRB;
+ if ( pMFP_IER ) *pMFP_IER = &(pMFP->IERB);
+ if ( pMFP_IPR ) *pMFP_IPR = &(pMFP->IPRB);
+ if ( pMFP_ISR ) *pMFP_ISR = &(pMFP->ISRB);
+ if ( pMFP_IMR ) *pMFP_IMR = &(pMFP->IMRB);
}
return Bit;
@@ -409,18 +502,18 @@ static Uint8 MFP_ConvertIntNumber ( int Interrupt , Uint8 **pMFP_IER , Uint8 **p
* The upper 4 bits of the vector number are stored in the VR register 0xfffa17
* (default value is 0x40, which gives exceptions' handlers located at 0x100 in RAM)
*/
-static void MFP_Exception ( int Interrupt )
+static void MFP_Exception ( MFP_STRUCT *pMFP , Sint16 Interrupt )
{
unsigned int VecNr;
- VecNr = ( MFP_VR & 0xf0 ) + Interrupt;
+ VecNr = ( pMFP->VR & 0xf0 ) + Interrupt;
if (LOG_TRACE_LEVEL(TRACE_MFP_EXCEPTION))
{
int FrameCycles, HblCounterVideo, LineCycles;
Video_GetPosition ( &FrameCycles , &HblCounterVideo , &LineCycles );
- LOG_TRACE_PRINT("mfp excep int=%d vec=0x%x new_pc=0x%x video_cyc=%d %d@%d\n" ,
- Interrupt, VecNr * 4, STMemory_ReadLong ( VecNr * 4 ), FrameCycles, LineCycles, HblCounterVideo );
+ LOG_TRACE_PRINT("mfp%s excep int=%d vec=0x%x new_pc=0x%x video_cyc=%d %d@%d\n" ,
+ pMFP->NameSuffix, Interrupt, VecNr * 4, STMemory_ReadLong ( VecNr * 4 ), FrameCycles, LineCycles, HblCounterVideo );
}
#ifndef WINUAE_FOR_HATARI
@@ -440,10 +533,15 @@ static void MFP_Exception ( int Interrupt )
* CPU side after MFP_IRQ_DELAY_TO_CPU.
* MFP_IRQ_CPU holds the value seen by the CPU, it's updated with the value
* of MFP_IRQ when MFP_IRQ_DELAY_TO_CPU cycles passed.
+ *
+ * When the machine is a TT, we combine the IRQ from the 2 MFPs
*/
Uint8 MFP_GetIRQ_CPU ( void )
{
- return MFP_IRQ_CPU;
+ if ( !Config_IsMachineTT() ) /* Only 1 MFP */
+ return pMFP_Main->IRQ_CPU;
+ else /* 2nd MFP is only in TT machine */
+ return pMFP_Main->IRQ_CPU | pMFP_TT->IRQ_CPU;
}
@@ -453,6 +551,8 @@ Uint8 MFP_GetIRQ_CPU ( void )
/**
* A change in MFP_IRQ is visible to the CPU only after MFP_IRQ_DELAY_TO_CPU
* cycles. This function will update MFP_IRQ_CPU if the delay has expired.
+*
+ * When the machine is a TT, we update MFP_IRQ_CPU for pMFP_Main and pMFP_TT
*
* This function is called from the CPU emulation part when SPCFLAG_MFP is set.
*
@@ -461,25 +561,46 @@ Uint8 MFP_GetIRQ_CPU ( void )
*/
void MFP_DelayIRQ ( void )
{
- if ( MFP_IRQ == 1 )
+ MFP_STRUCT *pMFP;
+ int Nb_MFP;
+ int Nb_Unset;
+ int i;
+
+
+ Nb_MFP = 1; /* Only 1 MFP by default */
+ if ( Config_IsMachineTT() ) /* 2 MFPs for TT */
+ Nb_MFP = 2;
+
+ /* Process all the MFPs */
+ Nb_Unset = 0;
+ for ( i=0 ; i<Nb_MFP ; i++ )
{
- if ( CyclesGlobalClockCounter - MFP_IRQ_Time >= MFP_IRQ_DELAY_TO_CPU )
+ if ( i == 0 )
+ pMFP = pMFP_Main;
+ else
+ pMFP = pMFP_TT;
+
+ if ( pMFP->IRQ == 1 )
+ {
+ if ( CyclesGlobalClockCounter - pMFP->IRQ_Time >= MFP_IRQ_DELAY_TO_CPU )
+ {
+ pMFP->IRQ_CPU = pMFP->IRQ;
+ Nb_Unset++;
+ }
+ }
+ else /* MFP_IRQ == 0, no delay for now */
{
- MFP_IRQ_CPU = MFP_IRQ;
- M68000_UnsetSpecial ( SPCFLAG_MFP ); /* Update done, unset special MFP flag */
+ pMFP->IRQ_CPU = pMFP->IRQ;
+ Nb_Unset++;
}
}
- else /* MFP_IRQ == 0, no delay for now */
- {
- MFP_IRQ_CPU = MFP_IRQ;
- M68000_UnsetSpecial ( SPCFLAG_MFP ); /* Update done, unset special MFP flag */
- }
+ /* If we have as many "unset" as the number of MFP, we unset special MFP flag */
+ if ( Nb_Unset == Nb_MFP )
+ M68000_UnsetSpecial ( SPCFLAG_MFP );
}
-
-
/*-----------------------------------------------------------------------*/
/**
* Return the vector number associated to the current MFP interrupt.
@@ -487,40 +608,52 @@ void MFP_DelayIRQ ( void )
* We must call MFP_UpdateIRQ just before the IACK cycles to update
* MFP_Current_Interrupt in case a higher MFP interrupt happened
* or pending bit was set twice for the same interrupt during those 12 cycles (rare case)
+ *
+ * TT MFP has higher priority than main MFP, so IACK should be checked on TT MFP first if IRQ is set
*/
int MFP_ProcessIACK ( int OldVecNr )
{
- Uint8 *pPendingReg;
- Uint8 *pInServiceReg;
- Uint8 Bit;
- int NewVecNr;
+ MFP_STRUCT *pMFP;
+ Uint8 *pPendingReg;
+ Uint8 *pInServiceReg;
+ Uint8 Bit;
+ int NewVecNr;
+
+ /* If IRQ is set on TT MFP then we process IACK for TT MFP */
+ /* Else we process IACK for main MFP */
+// TODO : If pMFP->IRQ = 0 after updating then return -1 and do a "spurious interrupt" in the cpu ?
+ if ( Config_IsMachineTT() && pMFP_TT->IRQ )
+ pMFP = pMFP_TT;
+ else
+ pMFP = pMFP_Main;
/* Check if MFP interrupt vector number changed before IACK */
- MFP_UpdateIRQ ( CyclesGlobalClockCounter );
+ MFP_UpdateIRQ ( pMFP , CyclesGlobalClockCounter );
+
- NewVecNr = ( MFP_VR & 0xf0 ) + MFP_Current_Interrupt;
+ NewVecNr = ( pMFP->VR & 0xf0 ) + pMFP->Current_Interrupt;
/* Print traces if VecNr changed just before IACK */
if ( LOG_TRACE_LEVEL(TRACE_MFP_EXCEPTION) && ( OldVecNr != NewVecNr ) )
{
int FrameCycles, HblCounterVideo, LineCycles;
Video_GetPosition ( &FrameCycles , &HblCounterVideo , &LineCycles );
- LOG_TRACE_PRINT("mfp iack change old_vec=0x%x new_vec=0x%x new_pc=0x%x video_cyc=%d %d@%d\n" ,
- OldVecNr * 4, NewVecNr * 4, STMemory_ReadLong ( NewVecNr * 4 ) , FrameCycles, LineCycles, HblCounterVideo );
+ LOG_TRACE_PRINT("mfp%s iack change old_vec=0x%x new_vec=0x%x new_pc=0x%x video_cyc=%d %d@%d\n" ,
+ pMFP->NameSuffix, OldVecNr * 4, NewVecNr * 4, STMemory_ReadLong ( NewVecNr * 4 ) , FrameCycles, LineCycles, HblCounterVideo );
}
- Bit = MFP_ConvertIntNumber ( MFP_Current_Interrupt , NULL , &pPendingReg , &pInServiceReg , NULL );
+ Bit = MFP_ConvertIntNumber ( pMFP , pMFP->Current_Interrupt , NULL , &pPendingReg , &pInServiceReg , NULL );
*pPendingReg &= ~Bit; /* Clear pending bit */
/* Are we in 'auto' interrupt or 'manual' ? */
- if ( MFP_VR & 0x08 ) /* Software End-of-Interrupt (SEI) */
+ if ( pMFP->VR & 0x08 ) /* Software End-of-Interrupt (SEI) */
*pInServiceReg |= Bit; /* Set interrupt in service register */
else
*pInServiceReg &= ~Bit; /* Clear interrupt in service register */
- MFP_UpdateIRQ ( CyclesGlobalClockCounter );
+ MFP_UpdateIRQ ( pMFP , CyclesGlobalClockCounter );
return NewVecNr; /* Vector number */
}
@@ -544,14 +677,28 @@ int MFP_ProcessIACK ( int OldVecNr )
* Instead of using CycInt_AddRelativeInterrupt to simulate this 4 cycles delay,
* we use MFP_IRQ_Time to delay the exception processing until 4 cycles have
* passed.
+ *
+ * When the machine is a TT, both MFP are daisy chained using IEI and IEO signals
+ * and the TT MFP has higher priority than the main MFP. So we must check TT MFP first.
*/
-bool MFP_ProcessIRQ ( void )
+bool MFP_ProcessIRQ_All ( void )
+{
+ /* 2nd MFP is only in TT machine and has higher priority than main MFP */
+ if ( Config_IsMachineTT() && MFP_ProcessIRQ ( pMFP_TT ) )
+ return true; /* IRQ set on TT MFP, stop here */
+
+ /* 1st MFP is common to all machines */
+ return MFP_ProcessIRQ ( pMFP_Main );
+}
+
+
+static bool MFP_ProcessIRQ ( MFP_STRUCT *pMFP )
{
-//fprintf ( stderr , "process irq %d %lld %lld - ipr %x %x imr %x %x isr %x %x\n" , MFP_IRQ , CyclesGlobalClockCounter , MFP_IRQ_Time , MFP_IPRA , MFP_IPRB , MFP_IMRA , MFP_IMRB , MFP_ISRA , MFP_ISRB );
+//fprintf ( stderr , "process irq %d %lud %lud - ipr %x %x imr %x %x isr %x %x\n" , pMFP->IRQ , CyclesGlobalClockCounter , pMFP->IRQ_Time , pMFP->IPRA , pMFP->IPRB , pMFP->IMRA , pMFP->IMRB , pMFP->ISRA , pMFP->ISRB );
- if ( MFP_IRQ == 1 )
+ if ( pMFP->IRQ == 1 )
{
- if ( CyclesGlobalClockCounter - MFP_IRQ_Time < MFP_IRQ_DELAY_TO_CPU ) /* Is it time to trigger the exception ? */
+ if ( CyclesGlobalClockCounter - pMFP->IRQ_Time < MFP_IRQ_DELAY_TO_CPU ) /* Is it time to trigger the exception ? */
{
return false; /* For now, return without calling an exception (and try again later) */
}
@@ -559,7 +706,7 @@ bool MFP_ProcessIRQ ( void )
if (regs.intmask < 6)
{
/* The exception is possible ; pending / in service bits will be handled in MFP_ProcessIACK() */
- MFP_Exception ( MFP_Current_Interrupt );
+ MFP_Exception ( pMFP , pMFP->Current_Interrupt );
return true;
}
}
@@ -568,6 +715,20 @@ bool MFP_ProcessIRQ ( void )
}
+/*-----------------------------------------------------------------------*/
+/**
+ * Update the MFP IRQ signal for all the MFP
+ */
+void MFP_UpdateIRQ_All ( Uint64 Event_Time )
+{
+ /* 2nd MFP is only in TT machine */
+ if ( Config_IsMachineTT() )
+ MFP_UpdateIRQ ( pMFP_TT , Event_Time );
+
+ /* 1st MFP is common to all machines */
+ MFP_UpdateIRQ ( pMFP_Main , Event_Time );
+}
+
/*-----------------------------------------------------------------------*/
/**
@@ -584,51 +745,51 @@ bool MFP_ProcessIRQ ( void )
* internal timers, Event_Time will be 0 and we must use MFP_Pending_Time[ NewInt ].
* This way, MFP_IRQ_Time should always be correct to check the delay in MFP_ProcessIRQ().
*/
-void MFP_UpdateIRQ ( Uint64 Event_Time )
+static void MFP_UpdateIRQ ( MFP_STRUCT *pMFP , Uint64 Event_Time )
{
int NewInt;
-//fprintf ( stderr , "updirq0 %d - ipr %x %x imr %x %x isr %x %x\n" , MFP_IRQ , MFP_IPRA , MFP_IPRB , MFP_IMRA , MFP_IMRB , MFP_ISRA , MFP_ISRB );
+//fprintf ( stderr , "updirq0 %d - ipr %x %x imr %x %x isr %x %x\n" , pMFP->IRQ , pMFP->IPRA , pMFP->IPRB , pMFP->IMRA , pMFP->IMRB , pMFP->ISRA , pMFP->ISRB );
- if ( ( MFP_IPRA & MFP_IMRA ) | ( MFP_IPRB & MFP_IMRB ) )
+ if ( ( pMFP->IPRA & pMFP->IMRA ) | ( pMFP->IPRB & pMFP->IMRB ) )
{
- NewInt = MFP_CheckPendingInterrupts ();
+ NewInt = MFP_CheckPendingInterrupts ( pMFP );
if ( NewInt >= 0 )
{
- if ( MFP_IRQ == 0 ) /* MFP IRQ goes from 0 to 1 */
+ if ( pMFP->IRQ == 0 ) /* MFP IRQ goes from 0 to 1 */
{
if ( Event_Time != 0 )
- MFP_IRQ_Time = Event_Time;
+ pMFP->IRQ_Time = Event_Time;
else
- MFP_IRQ_Time = MFP_Pending_Time[ NewInt ];
+ pMFP->IRQ_Time = pMFP->Pending_Time[ NewInt ];
}
- MFP_IRQ = 1;
- MFP_Current_Interrupt = NewInt;
+ pMFP->IRQ = 1;
+ pMFP->Current_Interrupt = NewInt;
}
else
- MFP_IRQ = 0; /* Pending interrupts are blocked by in-service interrupts */
+ pMFP->IRQ = 0; /* Pending interrupts are blocked by in-service interrupts */
}
else
{
- MFP_IRQ = 0;
+ pMFP->IRQ = 0;
}
-//fprintf ( stderr , "updirq1 %d %lld - ipr %x %x imr %x %x isr %x %x\n" , MFP_IRQ , MFP_IRQ_Time , MFP_IPRA , MFP_IPRB , MFP_IMRA , MFP_IMRB , MFP_ISRA , MFP_ISRB );
+//fprintf ( stderr , "updirq1 %d %lud - ipr %x %x imr %x %x isr %x %x\n" , pMFP->IRQ , pMFP->IRQ_Time , pMFP->IPRA , pMFP->IPRB , pMFP->IMRA , pMFP->IMRB , pMFP->ISRA , pMFP->ISRB );
#ifndef WINUAE_FOR_HATARI
- if ( MFP_IRQ == 1 )
+ if ( pMFP->IRQ == 1 )
{
- M68000_SetSpecial(SPCFLAG_MFP);
+ M68000_SetSpecial ( SPCFLAG_MFP );
}
else
- M68000_UnsetSpecial(SPCFLAG_MFP);
+ M68000_UnsetSpecial ( SPCFLAG_MFP );
#else
- M68000_SetSpecial(SPCFLAG_MFP); /* CPU part should call MFP_Delay_IRQ() */
+ M68000_SetSpecial ( SPCFLAG_MFP ); /* CPU part should call MFP_Delay_IRQ() */
#endif
/* Update IRQ is done, reset Time_Min and UpdateNeeded */
- MFP_Pending_Time_Min = UINT64_MAX;
+ pMFP->Pending_Time_Min = UINT64_MAX;
MFP_UpdateNeeded = false;
}
@@ -640,15 +801,15 @@ void MFP_UpdateIRQ ( Uint64 Event_Time )
* Depending on the interrupt, we check either IPRA/IMRA or IPRB/IMRB
* @return true if the MFP interrupt request is allowed
*/
-static bool MFP_InterruptRequest ( int Int , Uint8 Bit , Uint8 IPRx , Uint8 IMRx , Uint8 PriorityMaskA , Uint8 PriorityMaskB )
+static bool MFP_InterruptRequest ( MFP_STRUCT *pMFP , int Int , Uint8 Bit , Uint8 IPRx , Uint8 IMRx , Uint8 PriorityMaskA , Uint8 PriorityMaskB )
{
-//fprintf ( stderr , "mfp int req %d %x %x %X %x %x %x %x\n" , Int , Bit , IPRx , IMRx , PriorityMaskA , PriorityMaskB , MFP_ISRA , MFP_ISRB );
+//fprintf ( stderr , "mfp int req %d %x %x %X %x %x %x %x\n" , Int , Bit , IPRx , IMRx , PriorityMaskA , PriorityMaskB , pMFP->ISRA , pMFP->ISRB );
if ( ( IPRx & IMRx & Bit ) /* Interrupt is pending and not masked */
- && ( MFP_Pending_Time[ Int ] <= MFP_Pending_Time_Min ) ) /* Process pending requests in chronological time */
+ && ( pMFP->Pending_Time[ Int ] <= pMFP->Pending_Time_Min ) )/* Process pending requests in chronological time */
{
/* Are any higher priority interrupts in service ? */
- if ( ( ( MFP_ISRA & PriorityMaskA ) == 0 ) && ( ( MFP_ISRB & PriorityMaskB ) == 0 ) )
+ if ( ( ( pMFP->ISRA & PriorityMaskA ) == 0 ) && ( ( pMFP->ISRB & PriorityMaskB ) == 0 ) )
return true; /* No higher int in service */
}
@@ -661,59 +822,59 @@ static bool MFP_InterruptRequest ( int Int , Uint8 Bit , Uint8 IPRx , Uint8 IMRx
* Check if any MFP interrupts can be serviced.
* @return MFP interrupt number for the highest interrupt allowed, else return -1.
*/
-static int MFP_CheckPendingInterrupts ( void )
+static int MFP_CheckPendingInterrupts ( MFP_STRUCT *pMFP )
{
- if ( MFP_IPRA & MFP_IMRA ) /* Check we have non masked pending ints */
+ if ( pMFP->IPRA & pMFP->IMRA ) /* Check we have non masked pending ints */
{
- if ( MFP_InterruptRequest ( MFP_INT_GPIP7 , MFP_GPIP7_BIT, MFP_IPRA, MFP_IMRA, 0x80, 0x00 ) ) /* Check MFP GPIP7 interrupt (bit 7) */
+ if ( MFP_InterruptRequest ( pMFP , MFP_INT_GPIP7 , MFP_GPIP7_BIT, pMFP->IPRA, pMFP->IMRA, 0x80, 0x00 ) ) /* Check MFP GPIP7 interrupt (bit 7) */
return MFP_INT_GPIP7;
- if ( MFP_InterruptRequest ( MFP_INT_GPIP6 , MFP_GPIP6_BIT, MFP_IPRA, MFP_IMRA, 0xc0, 0x00 ) ) /* Check MFP GPIP6 interrupt (bit 6) */
+ if ( MFP_InterruptRequest ( pMFP , MFP_INT_GPIP6 , MFP_GPIP6_BIT, pMFP->IPRA, pMFP->IMRA, 0xc0, 0x00 ) ) /* Check MFP GPIP6 interrupt (bit 6) */
return MFP_INT_GPIP6;
- if ( MFP_InterruptRequest ( MFP_INT_TIMER_A , MFP_TIMER_A_BIT, MFP_IPRA, MFP_IMRA, 0xe0, 0x00 ) ) /* Check Timer A (bit 5) */
+ if ( MFP_InterruptRequest ( pMFP , MFP_INT_TIMER_A , MFP_TIMER_A_BIT, pMFP->IPRA, pMFP->IMRA, 0xe0, 0x00 ) ) /* Check Timer A (bit 5) */
return MFP_INT_TIMER_A;
- if ( MFP_InterruptRequest ( MFP_INT_RCV_BUF_FULL , MFP_RCV_BUF_FULL_BIT, MFP_IPRA, MFP_IMRA, 0xf0, 0x00 ) ) /* Check Receive buffer full (bit 4) */
+ if ( MFP_InterruptRequest ( pMFP , MFP_INT_RCV_BUF_FULL , MFP_RCV_BUF_FULL_BIT, pMFP->IPRA, pMFP->IMRA, 0xf0, 0x00 ) ) /* Check Receive buffer full (bit 4) */
return MFP_INT_RCV_BUF_FULL;
- if ( MFP_InterruptRequest ( MFP_INT_RCV_ERR , MFP_RCV_ERR_BIT, MFP_IPRA, MFP_IMRA, 0xf8, 0x00 ) ) /* Check Receive error (bit 3) */
+ if ( MFP_InterruptRequest ( pMFP , MFP_INT_RCV_ERR , MFP_RCV_ERR_BIT, pMFP->IPRA, pMFP->IMRA, 0xf8, 0x00 ) ) /* Check Receive error (bit 3) */
return MFP_INT_RCV_ERR;
- if ( MFP_InterruptRequest ( MFP_INT_TRN_BUF_EMPTY , MFP_TRN_BUF_EMPTY_BIT, MFP_IPRA, MFP_IMRA, 0xfc, 0x00 ) ) /* Check Transmit buffer empty (bit 2) */
+ if ( MFP_InterruptRequest ( pMFP , MFP_INT_TRN_BUF_EMPTY , MFP_TRN_BUF_EMPTY_BIT, pMFP->IPRA, pMFP->IMRA, 0xfc, 0x00 ) ) /* Check Transmit buffer empty (bit 2) */
return MFP_INT_TRN_BUF_EMPTY;
- if ( MFP_InterruptRequest ( MFP_INT_TRN_ERR , MFP_TRN_ERR_BIT, MFP_IPRA, MFP_IMRA, 0xfe, 0x00 ) ) /* Check Transmit error empty (bit 1) */
+ if ( MFP_InterruptRequest ( pMFP , MFP_INT_TRN_ERR , MFP_TRN_ERR_BIT, pMFP->IPRA, pMFP->IMRA, 0xfe, 0x00 ) ) /* Check Transmit error empty (bit 1) */
return MFP_INT_TRN_ERR;
- if ( MFP_InterruptRequest ( MFP_INT_TIMER_B , MFP_TIMER_B_BIT, MFP_IPRA, MFP_IMRA, 0xff, 0x00 ) ) /* Check Timer B (bit 0) */
+ if ( MFP_InterruptRequest ( pMFP , MFP_INT_TIMER_B , MFP_TIMER_B_BIT, pMFP->IPRA, pMFP->IMRA, 0xff, 0x00 ) ) /* Check Timer B (bit 0) */
return MFP_INT_TIMER_B;
}
- if ( MFP_IPRB & MFP_IMRB ) /* Check we have non masked pending ints */
+ if ( pMFP->IPRB & pMFP->IMRB ) /* Check we have non masked pending ints */
{
- if ( MFP_InterruptRequest ( MFP_INT_GPIP5 , MFP_GPIP5_BIT, MFP_IPRB, MFP_IMRB, 0xff, 0x80 ) ) /* Check GPIP5 = FDC (bit 7) */
+ if ( MFP_InterruptRequest ( pMFP , MFP_INT_GPIP5 , MFP_GPIP5_BIT, pMFP->IPRB, pMFP->IMRB, 0xff, 0x80 ) ) /* Check GPIP5 = FDC (bit 7) */
return MFP_INT_GPIP5;
- if ( MFP_InterruptRequest ( MFP_INT_GPIP4 , MFP_GPIP4_BIT, MFP_IPRB, MFP_IMRB, 0xff, 0xc0 ) ) /* Check GPIP4 = ACIA (Keyboard or MIDI) (bit 6) */
+ if ( MFP_InterruptRequest ( pMFP , MFP_INT_GPIP4 , MFP_GPIP4_BIT, pMFP->IPRB, pMFP->IMRB, 0xff, 0xc0 ) ) /* Check GPIP4 = ACIA (Keyboard or MIDI) (bit 6) */
return MFP_INT_GPIP4;
- if ( MFP_InterruptRequest ( MFP_INT_TIMER_C , MFP_TIMER_C_BIT, MFP_IPRB, MFP_IMRB, 0xff, 0xe0 ) ) /* Check Timer C (bit 5) */
+ if ( MFP_InterruptRequest ( pMFP , MFP_INT_TIMER_C , MFP_TIMER_C_BIT, pMFP->IPRB, pMFP->IMRB, 0xff, 0xe0 ) ) /* Check Timer C (bit 5) */
return MFP_INT_TIMER_C;
- if ( MFP_InterruptRequest ( MFP_INT_TIMER_D , MFP_TIMER_D_BIT, MFP_IPRB, MFP_IMRB, 0xff, 0xf0 ) ) /* Check Timer D (bit 4) */
+ if ( MFP_InterruptRequest ( pMFP , MFP_INT_TIMER_D , MFP_TIMER_D_BIT, pMFP->IPRB, pMFP->IMRB, 0xff, 0xf0 ) ) /* Check Timer D (bit 4) */
return MFP_INT_TIMER_D;
- if ( MFP_InterruptRequest ( MFP_INT_GPIP3 , MFP_GPIP3_BIT, MFP_IPRB, MFP_IMRB, 0xff, 0xf8 ) ) /* Check GPIP3 = GPU/Blitter (bit 3) */
+ if ( MFP_InterruptRequest ( pMFP , MFP_INT_GPIP3 , MFP_GPIP3_BIT, pMFP->IPRB, pMFP->IMRB, 0xff, 0xf8 ) ) /* Check GPIP3 = GPU/Blitter (bit 3) */
return MFP_INT_GPIP3;
- if ( MFP_InterruptRequest ( MFP_INT_GPIP2 , MFP_GPIP2_BIT, MFP_IPRB, MFP_IMRB, 0xff, 0xfc ) ) /* Check GPIP2 (bit 2) */
+ if ( MFP_InterruptRequest ( pMFP , MFP_INT_GPIP2 , MFP_GPIP2_BIT, pMFP->IPRB, pMFP->IMRB, 0xff, 0xfc ) ) /* Check GPIP2 (bit 2) */
return MFP_INT_GPIP2;
- if ( MFP_InterruptRequest ( MFP_INT_GPIP1 , MFP_GPIP1_BIT, MFP_IPRB, MFP_IMRB, 0xff, 0xfe ) ) /* Check (Falcon) Centronics ACK / (ST) RS232 DCD (bit 1) */
+ if ( MFP_InterruptRequest ( pMFP , MFP_INT_GPIP1 , MFP_GPIP1_BIT, pMFP->IPRB, pMFP->IMRB, 0xff, 0xfe ) ) /* Check (Falcon) Centronics ACK / (ST) RS232 DCD (bit 1) */
return MFP_INT_GPIP1;
- if ( MFP_InterruptRequest ( MFP_INT_GPIP0 , MFP_GPIP0_BIT, MFP_IPRB, MFP_IMRB, 0xff, 0xff ) ) /* Check Centronics BUSY (bit 0) */
+ if ( MFP_InterruptRequest ( pMFP , MFP_INT_GPIP0 , MFP_GPIP0_BIT, pMFP->IPRB, pMFP->IMRB, 0xff, 0xff ) ) /* Check Centronics BUSY (bit 0) */
return MFP_INT_GPIP0;
}
@@ -735,15 +896,15 @@ static int MFP_CheckPendingInterrupts ( void )
* in the main CPU loop, when all inputs were received, to choose the oldest
* input's event time.
*/
-void MFP_InputOnChannel ( int Interrupt , int Interrupt_Delayed_Cycles )
+void MFP_InputOnChannel ( MFP_STRUCT *pMFP , int Interrupt , int Interrupt_Delayed_Cycles )
{
Uint8 *pEnableReg;
Uint8 *pPendingReg;
Uint8 *pMaskReg;
Uint8 Bit;
-//fprintf ( stderr , "mfp input %d delay %d clock %lld\n" , Interrupt , Interrupt_Delayed_Cycles , CyclesGlobalClockCounter );
- Bit = MFP_ConvertIntNumber ( Interrupt , &pEnableReg , &pPendingReg , NULL , &pMaskReg );
+//fprintf ( stderr , "mfp input %d delay %d clock %lud\n" , Interrupt , Interrupt_Delayed_Cycles , CyclesGlobalClockCounter );
+ Bit = MFP_ConvertIntNumber ( pMFP , Interrupt , &pEnableReg , &pPendingReg , NULL , &pMaskReg );
/* Input has occurred on MFP channel, set interrupt pending to request service when able */
if ( *pEnableReg & Bit )
@@ -754,20 +915,20 @@ void MFP_InputOnChannel ( int Interrupt , int Interrupt_Delayed_Cycles )
int FrameCycles, HblCounterVideo, LineCycles;
Video_GetPosition ( &FrameCycles , &HblCounterVideo , &LineCycles );
if ( *pPendingReg & Bit )
- LOG_TRACE_PRINT("mfp input, pending set again during iack for int=%d, skip one interrupt video_cyc=%d %d@%d\n" ,
- Interrupt , FrameCycles, LineCycles, HblCounterVideo );
+ LOG_TRACE_PRINT("mfp%s input, pending set again during iack for int=%d, skip one interrupt video_cyc=%d %d@%d\n" ,
+ pMFP->NameSuffix , Interrupt , FrameCycles, LineCycles, HblCounterVideo );
else
- LOG_TRACE_PRINT("mfp input, new pending set during iack for int=%d video_cyc=%d %d@%d\n" ,
- Interrupt , FrameCycles, LineCycles, HblCounterVideo );
+ LOG_TRACE_PRINT("mfp%s input, new pending set during iack for int=%d video_cyc=%d %d@%d\n" ,
+ pMFP->NameSuffix , Interrupt , FrameCycles, LineCycles, HblCounterVideo );
}
/* Set pending bit and event's time */
*pPendingReg |= Bit;
- MFP_Pending_Time[ Interrupt ] = CyclesGlobalClockCounter - Interrupt_Delayed_Cycles;
+ pMFP->Pending_Time[ Interrupt ] = CyclesGlobalClockCounter - Interrupt_Delayed_Cycles;
/* Store the time of the most ancient non-masked pending=1 event */
- if ( ( *pMaskReg & Bit ) && ( MFP_Pending_Time[ Interrupt ] < MFP_Pending_Time_Min ) )
- MFP_Pending_Time_Min = MFP_Pending_Time[ Interrupt ];
+ if ( ( *pMaskReg & Bit ) && ( pMFP->Pending_Time[ Interrupt ] < pMFP->Pending_Time_Min ) )
+ pMFP->Pending_Time_Min = pMFP->Pending_Time[ Interrupt ];
}
else
*pPendingReg &= ~Bit; /* Clear bit */
@@ -789,7 +950,7 @@ void MFP_InputOnChannel ( int Interrupt , int Interrupt_Delayed_Cycles )
* if AER is changed ! ('M' and 'Realtime' are doing bset #0,$fffa03
* then bclr #0,$fffa03)
*/
-static void MFP_GPIP_Update_Interrupt ( Uint8 GPIP_old , Uint8 GPIP_new , Uint8 AER_old , Uint8 AER_new , Uint8 DDR_old , Uint8 DDR_new )
+static void MFP_GPIP_Update_Interrupt ( MFP_STRUCT *pMFP , Uint8 GPIP_old , Uint8 GPIP_new , Uint8 AER_old , Uint8 AER_new , Uint8 DDR_old , Uint8 DDR_new )
{
Uint8 State_old;
Uint8 State_new;
@@ -812,7 +973,7 @@ static void MFP_GPIP_Update_Interrupt ( Uint8 GPIP_old , Uint8 GPIP_new , Uint8
if ( ( GPIP_new & BitMask ) == ( AER_new & BitMask ) )
{
//fprintf ( stderr , "gpip int bit=%d %d->%d\n" , Bit , (State_old & BitMask)>>Bit , (State_new & BitMask)>>Bit );
- MFP_InputOnChannel ( MFP_GPIP_LineToIntNumber[ Bit ] , 0 );
+ MFP_InputOnChannel ( pMFP , MFP_GPIP_LineToIntNumber[ Bit ] , 0 );
}
}
}
@@ -826,7 +987,7 @@ static void MFP_GPIP_Update_Interrupt ( Uint8 GPIP_old , Uint8 GPIP_new , Uint8
* If the new state is different from the previous one, we update GPIP and
* we request an interrupt on the corresponding channel.
*/
-void MFP_GPIP_Set_Line_Input ( Uint8 LineNr , Uint8 Bit )
+void MFP_GPIP_Set_Line_Input ( MFP_STRUCT *pMFP , Uint8 LineNr , Uint8 Bit )
{
Uint8 Mask;
Uint8 GPIP_old;
@@ -835,25 +996,26 @@ void MFP_GPIP_Set_Line_Input ( Uint8 LineNr , Uint8 Bit )
/* Check that corresponding line is defined as input in DDR (0=input 1=output) */
/* and that the bit is changing */
- if ( ( ( MFP_DDR & Mask ) == 0 )
- && ( ( MFP_GPIP & Mask ) != ( Bit << LineNr ) ) )
+ if ( ( ( pMFP->DDR & Mask ) == 0 )
+ && ( ( pMFP->GPIP & Mask ) != ( Bit << LineNr ) ) )
{
- GPIP_old = MFP_GPIP;
+ GPIP_old = pMFP->GPIP;
if ( Bit )
{
- MFP_GPIP |= Mask;
+ pMFP->GPIP |= Mask;
}
else
{
- MFP_GPIP &= ~Mask;
- /* TODO : For now, assume AER=0 and to an interrupt on 1->0 transition */
+ pMFP->GPIP &= ~Mask;
+ /* TODO : For now, assume AER=0 and do an interrupt on 1->0 transition */
// MFP_InputOnChannel ( MFP_GPIP_LineToIntNumber[ LineNr ] , 0 );
}
/* Update possible interrupts after changing GPIP */
- MFP_GPIP_Update_Interrupt ( GPIP_old , MFP_GPIP , MFP_AER , MFP_AER , MFP_DDR , MFP_DDR );
+ MFP_GPIP_Update_Interrupt ( pMFP , GPIP_old , pMFP->GPIP , pMFP->AER , pMFP->AER , pMFP->DDR , pMFP->DDR );
}
+//fprintf ( stderr , "gpip set %x %x\n" , GPIP_old , pMFP->GPIP );
}
@@ -862,26 +1024,26 @@ void MFP_GPIP_Set_Line_Input ( Uint8 LineNr , Uint8 Bit )
/**
* Generate Timer A Interrupt when in Event Count mode
*/
-void MFP_TimerA_EventCount(void)
+void MFP_TimerA_EventCount( MFP_STRUCT *pMFP )
{
- if ( MFP_TACR != 0x08 ) /* Not in event count mode */
+ if ( pMFP->TACR != 0x08 ) /* Not in event count mode */
return; /* Do nothing */
- if (MFP_TA_MAINCOUNTER == 1) /* Timer expired? If so, generate interrupt */
+ if ( pMFP->TA_MAINCOUNTER == 1) /* Timer expired? If so, generate interrupt */
{
- MFP_TA_MAINCOUNTER = MFP_TADR; /* Reload timer from data register */
+ pMFP->TA_MAINCOUNTER = pMFP->TADR; /* Reload timer from data register */
/* Acknowledge in MFP circuit, pass bit,enable,pending */
- MFP_InputOnChannel ( MFP_INT_TIMER_A , 0 );
+ MFP_InputOnChannel ( pMFP , MFP_INT_TIMER_A , 0 );
}
else
{
- MFP_TA_MAINCOUNTER--; /* Decrement timer main counter */
- /* As MFP_TA_MAINCOUNTER is Uint8, when we decrement MFP_TA_MAINCOUNTER=0 */
- /* we go to MFP_TA_MAINCOUNTER=255, which is the wanted behaviour because */
+ pMFP->TA_MAINCOUNTER--; /* Decrement timer main counter */
+ /* As TA_MAINCOUNTER is Uint8, when we decrement TA_MAINCOUNTER=0 */
+ /* we go to TA_MAINCOUNTER=255, which is the wanted behaviour because */
/* data reg = 0 means 256 in fact. So, the next 2 lines are redundant. */
-/* if ( MFP_TA_MAINCOUNTER < 0 )
- MFP_TA_MAINCOUNTER = 255;
+/* if ( TA_MAINCOUNTER < 0 )
+ TA_MAINCOUNTER = 255;
*/
}
}
@@ -891,28 +1053,30 @@ void MFP_TimerA_EventCount(void)
/**
* Generate Timer B Interrupt when in Event Count mode
*/
-void MFP_TimerB_EventCount ( int Delayed_Cycles )
+void MFP_TimerB_EventCount ( MFP_STRUCT *pMFP , int Delayed_Cycles )
{
- if ( MFP_TBCR != 0x08 ) /* Not in event count mode */
+ if ( pMFP->TBCR != 0x08 ) /* Not in event count mode */
return; /* Do nothing */
- LOG_TRACE(TRACE_VIDEO_HBL , "mfp/video timer B new event count %d, delay=%d\n" , MFP_TB_MAINCOUNTER-1 , Delayed_Cycles );
+ /* Video DE signal is connected to Timer B on the main MFP */
+ if ( pMFP == pMFP_Main )
+ LOG_TRACE(TRACE_VIDEO_HBL , "mfp/video timer B new event count %d, delay=%d\n" , pMFP->TB_MAINCOUNTER-1 , Delayed_Cycles );
- if (MFP_TB_MAINCOUNTER == 1) /* Timer expired? If so, generate interrupt */
+ if ( pMFP->TB_MAINCOUNTER == 1 ) /* Timer expired? If so, generate interrupt */
{
- MFP_TB_MAINCOUNTER = MFP_TBDR; /* Reload timer from data register */
+ pMFP->TB_MAINCOUNTER = pMFP->TBDR; /* Reload timer from data register */
/* Acknowledge in MFP circuit, pass bit,enable,pending */
- MFP_InputOnChannel ( MFP_INT_TIMER_B , Delayed_Cycles );
+ MFP_InputOnChannel ( pMFP , MFP_INT_TIMER_B , Delayed_Cycles );
}
else
{
- MFP_TB_MAINCOUNTER--; /* Decrement timer main counter */
- /* As MFP_TB_MAINCOUNTER is Uint8, when we decrement MFP_TB_MAINCOUNTER=0 */
- /* we go to MFP_TB_MAINCOUNTER=255, which is the wanted behaviour because */
+ pMFP->TB_MAINCOUNTER--; /* Decrement timer main counter */
+ /* As TB_MAINCOUNTER is Uint8, when we decrement TB_MAINCOUNTER=0 */
+ /* we go to TB_MAINCOUNTER=255, which is the wanted behaviour because */
/* data reg = 0 means 256 in fact. So, the next 2 lines are redundant. */
-/* if ( MFP_TB_MAINCOUNTER < 0 )
- MFP_TB_MAINCOUNTER = 255;
+/* if ( TB_MAINCOUNTER < 0 )
+ TB_MAINCOUNTER = 255;
*/
}
}
@@ -922,10 +1086,10 @@ void MFP_TimerB_EventCount ( int Delayed_Cycles )
/**
* Start Timer A or B - EventCount mode is done in HBL handler to time correctly
*/
-static int MFP_StartTimer_AB(Uint8 TimerControl, Uint16 TimerData, interrupt_id Handler,
+static Uint32 MFP_StartTimer_AB ( MFP_STRUCT *pMFP , Uint8 TimerControl, Uint16 TimerData, interrupt_id Handler,
bool bFirstTimer, bool *pTimerCanResume)
{
- int TimerClockCycles = 0;
+ Uint32 TimerClockCycles = 0;
/* When in pulse width mode, handle as in delay mode */
@@ -936,8 +1100,8 @@ static int MFP_StartTimer_AB(Uint8 TimerControl, Uint16 TimerData, interrupt_id
{
int FrameCycles, HblCounterVideo, LineCycles;
Video_GetPosition ( &FrameCycles , &HblCounterVideo , &LineCycles );
- LOG_TRACE_PRINT("mfp start AB handler=%d data=%d ctrl=%d timer_cyc=%d pending_cyc=%d video_cyc=%d %d@%d pc=%x instr_cyc=%d pulse mode->delay mode\n",
- Handler, TimerData, TimerControl, TimerClockCycles, PendingCyclesOver,
+ LOG_TRACE_PRINT("mfp%s start AB handler=%d data=%d ctrl=%d timer_cyc=%d pending_cyc=%d video_cyc=%d %d@%d pc=%x instr_cyc=%d pulse mode->delay mode\n",
+ pMFP->NameSuffix , Handler, TimerData, TimerControl, TimerClockCycles, PendingCyclesOver,
FrameCycles, LineCycles, HblCounterVideo, M68000_GetPC(), CurrentInstrCycles);
}
@@ -969,8 +1133,8 @@ static int MFP_StartTimer_AB(Uint8 TimerControl, Uint16 TimerData, interrupt_id
{
int FrameCycles, HblCounterVideo, LineCycles;
Video_GetPosition ( &FrameCycles , &HblCounterVideo , &LineCycles );
- LOG_TRACE_PRINT("mfp start AB handler=%d data=%d ctrl=%d timer_cyc=%d pending_cyc=%d video_cyc=%d %d@%d pc=%x instr_cyc=%d first=%s resume=%s\n",
- Handler, TimerData, TimerControl, TimerClockCycles, PendingCyclesOver,
+ LOG_TRACE_PRINT("mfp%s start AB handler=%d data=%d ctrl=%d timer_cyc=%d pending_cyc=%d video_cyc=%d %d@%d pc=%x instr_cyc=%d first=%s resume=%s\n",
+ pMFP->NameSuffix , Handler, TimerData, TimerControl, TimerClockCycles, PendingCyclesOver,
FrameCycles, LineCycles, HblCounterVideo, M68000_GetPC(), CurrentInstrCycles,
bFirstTimer?"true":"false", *pTimerCanResume?"true":"false");
}
@@ -1013,8 +1177,8 @@ static int MFP_StartTimer_AB(Uint8 TimerControl, Uint16 TimerData, interrupt_id
{
int FrameCycles, HblCounterVideo, LineCycles;
Video_GetPosition ( &FrameCycles , &HblCounterVideo , &LineCycles );
- LOG_TRACE_PRINT("mfp stop AB handler=%d data=%d ctrl=%d timer_cyc=%d pending_cyc=%d video_cyc=%d %d@%d pc=%x instr_cyc=%d first=%s resume=%s\n",
- Handler, TimerData, TimerControl, TimerClockCycles, PendingCyclesOver,
+ LOG_TRACE_PRINT("mfp%s stop AB handler=%d data=%d ctrl=%d timer_cyc=%d pending_cyc=%d video_cyc=%d %d@%d pc=%x instr_cyc=%d first=%s resume=%s\n",
+ pMFP->NameSuffix , Handler, TimerData, TimerControl, TimerClockCycles, PendingCyclesOver,
FrameCycles, LineCycles, HblCounterVideo, M68000_GetPC(), CurrentInstrCycles,
bFirstTimer?"true":"false", *pTimerCanResume?"true":"false");
}
@@ -1027,7 +1191,7 @@ static int MFP_StartTimer_AB(Uint8 TimerControl, Uint16 TimerData, interrupt_id
/* Make sure no outstanding interrupts in list if channel is disabled */
CycInt_RemovePendingInterrupt(Handler);
- if ( Handler == INTERRUPT_MFP_TIMERB ) /* we're starting timer B event count mode */
+ if ( Handler == INTERRUPT_MFP_MAIN_TIMERB ) /* we're starting timer B event count mode */
{
/* Store start cycle for handling interrupt in video.c */
TimerBEventCountCycleStart = Cycles_GetCounterOnWriteAccess(CYCLES_COUNTER_VIDEO);
@@ -1037,8 +1201,8 @@ static int MFP_StartTimer_AB(Uint8 TimerControl, Uint16 TimerData, interrupt_id
{
int FrameCycles, HblCounterVideo, LineCycles;
Video_GetPosition ( &FrameCycles , &HblCounterVideo , &LineCycles );
- LOG_TRACE_PRINT("mfp start AB handler=%d data=%d ctrl=%d timer_cyc=%d pending_cyc=%d video_cyc=%d %d@%d pc=%x instr_cyc=%d first=%s resume=%s\n",
- Handler, TimerData, TimerControl, TimerClockCycles, PendingCyclesOver,
+ LOG_TRACE_PRINT("mfp%s start AB handler=%d data=%d ctrl=%d timer_cyc=%d pending_cyc=%d video_cyc=%d %d@%d pc=%x instr_cyc=%d first=%s resume=%s\n",
+ pMFP->NameSuffix , Handler, TimerData, TimerControl, TimerClockCycles, PendingCyclesOver,
FrameCycles, LineCycles, HblCounterVideo, M68000_GetPC(), CurrentInstrCycles,
bFirstTimer?"true":"false", *pTimerCanResume?"true":"false");
}
@@ -1052,10 +1216,10 @@ static int MFP_StartTimer_AB(Uint8 TimerControl, Uint16 TimerData, interrupt_id
/**
* Start Timer C or D
*/
-static int MFP_StartTimer_CD(Uint8 TimerControl, Uint16 TimerData, interrupt_id Handler,
+static Uint32 MFP_StartTimer_CD ( MFP_STRUCT *pMFP , Uint8 TimerControl, Uint16 TimerData, interrupt_id Handler,
bool bFirstTimer, bool *pTimerCanResume)
{
- int TimerClockCycles = 0;
+ Uint32 TimerClockCycles = 0;
/* Is timer in delay mode ? */
if ((TimerControl&0x7) != 0)
@@ -1071,8 +1235,8 @@ static int MFP_StartTimer_CD(Uint8 TimerControl, Uint16 TimerData, interrupt_id
{
int FrameCycles, HblCounterVideo, LineCycles;
Video_GetPosition ( &FrameCycles , &HblCounterVideo , &LineCycles );
- LOG_TRACE_PRINT("mfp start CD handler=%d data=%d ctrl=%d timer_cyc=%d pending_cyc=%d video_cyc=%d %d@%d pc=%x instr_cyc=%d first=%s resume=%s\n" ,
- Handler, TimerData, TimerControl, TimerClockCycles, PendingCyclesOver,
+ LOG_TRACE_PRINT("mfp%s start CD handler=%d data=%d ctrl=%d timer_cyc=%d pending_cyc=%d video_cyc=%d %d@%d pc=%x instr_cyc=%d first=%s resume=%s\n" ,
+ pMFP->NameSuffix , Handler, TimerData, TimerControl, TimerClockCycles, PendingCyclesOver,
FrameCycles, LineCycles, HblCounterVideo, M68000_GetPC(), CurrentInstrCycles,
bFirstTimer?"true":"false" , *pTimerCanResume?"true":"false" );
}
@@ -1115,8 +1279,8 @@ static int MFP_StartTimer_CD(Uint8 TimerControl, Uint16 TimerData, interrupt_id
{
int FrameCycles, HblCounterVideo, LineCycles;
Video_GetPosition ( &FrameCycles , &HblCounterVideo , &LineCycles );
- LOG_TRACE_PRINT("mfp stop CD handler=%d data=%d ctrl=%d timer_cyc=%d pending_cyc=%d video_cyc=%d %d@%d pc=%x instr_cyc=%d first=%s resume=%s\n" ,
- Handler, TimerData, TimerControl, TimerClockCycles, PendingCyclesOver,
+ LOG_TRACE_PRINT("mfp%s stop CD handler=%d data=%d ctrl=%d timer_cyc=%d pending_cyc=%d video_cyc=%d %d@%d pc=%x instr_cyc=%d first=%s resume=%s\n" ,
+ pMFP->NameSuffix , Handler, TimerData, TimerControl, TimerClockCycles, PendingCyclesOver,
FrameCycles, LineCycles, HblCounterVideo, M68000_GetPC(), CurrentInstrCycles,
bFirstTimer?"true":"false" , *pTimerCanResume?"true":"false" );
}
@@ -1133,7 +1297,7 @@ static int MFP_StartTimer_CD(Uint8 TimerControl, Uint16 TimerData, interrupt_id
/**
* Read Timer A or B - If in EventCount MainCounter already has correct value
*/
-static Uint8 MFP_ReadTimer_AB(Uint8 TimerControl, Uint8 MainCounter, int TimerCycles, interrupt_id Handler, bool TimerIsStopping)
+static Uint8 MFP_ReadTimer_AB ( MFP_STRUCT *pMFP , Uint8 TimerControl, Uint8 MainCounter, Uint32 TimerCycles, interrupt_id Handler, bool TimerIsStopping)
{
// int TimerCyclesPassed;
@@ -1144,7 +1308,7 @@ static Uint8 MFP_ReadTimer_AB(Uint8 TimerControl, Uint8 MainCounter, int TimerCy
/* Find cycles passed since last interrupt */
//TimerCyclesPassed = TimerCycles - CycInt_FindCyclesPassed ( Handler, INT_MFP_CYCLE );
MainCounter = MFP_CYCLE_TO_REG ( CycInt_FindCyclesPassed ( Handler, INT_MFP_CYCLE ), TimerControl );
- //fprintf ( stderr , "mfp read AB passed %d count %d\n" , TimerCyclesPassed, MainCounter );
+ //fprintf ( stderr , "mfp read AB count %d\n" , MainCounter );
}
/* If the timer is stopped when the internal mfp data reg is already < 1 */
@@ -1155,8 +1319,8 @@ static Uint8 MFP_ReadTimer_AB(Uint8 TimerControl, Uint8 MainCounter, int TimerCy
if ( CycInt_FindCyclesPassed ( Handler, INT_MFP_CYCLE ) < MFP_REG_TO_CYCLES ( 1 , TimerControl ) )
{
MainCounter = 0; /* internal mfp counter becomes 0 (=256) */
- LOG_TRACE(TRACE_MFP_READ , "mfp read AB handler=%d stopping timer while data reg between 1 and 0 : forcing data to 256\n" ,
- Handler );
+ LOG_TRACE(TRACE_MFP_READ , "mfp%s read AB handler=%d stopping timer while data reg between 1 and 0 : forcing data to 256\n" ,
+ pMFP->NameSuffix , Handler );
}
}
@@ -1164,8 +1328,8 @@ static Uint8 MFP_ReadTimer_AB(Uint8 TimerControl, Uint8 MainCounter, int TimerCy
{
int FrameCycles, HblCounterVideo, LineCycles;
Video_GetPosition ( &FrameCycles , &HblCounterVideo , &LineCycles );
- LOG_TRACE_PRINT("mfp read AB handler=%d data=%d ctrl=%d timer_cyc=%d video_cyc=%d %d@%d pc=%x instr_cyc=%d\n" ,
- Handler, MainCounter, TimerControl, TimerCycles,
+ LOG_TRACE_PRINT("mfp%s read AB handler=%d data=%d ctrl=%d timer_cyc=%d video_cyc=%d %d@%d pc=%x instr_cyc=%d\n" ,
+ pMFP->NameSuffix , Handler, MainCounter, TimerControl, TimerCycles,
FrameCycles, LineCycles, HblCounterVideo, M68000_GetPC(), CurrentInstrCycles );
}
@@ -1177,7 +1341,7 @@ static Uint8 MFP_ReadTimer_AB(Uint8 TimerControl, Uint8 MainCounter, int TimerCy
/**
* Read Timer C or D
*/
-static Uint8 MFP_ReadTimerCD(Uint8 TimerControl, Uint8 TimerData, Uint8 MainCounter, int TimerCycles, interrupt_id Handler, bool TimerIsStopping)
+static Uint8 MFP_ReadTimer_CD ( MFP_STRUCT *pMFP , Uint8 TimerControl, Uint8 TimerData, Uint8 MainCounter, Uint32 TimerCycles, interrupt_id Handler, bool TimerIsStopping)
{
// int TimerCyclesPassed;
@@ -1188,7 +1352,7 @@ static Uint8 MFP_ReadTimerCD(Uint8 TimerControl, Uint8 TimerData, Uint8 MainCoun
/* Find cycles passed since last interrupt */
//TimerCyclesPassed = TimerCycles - CycInt_FindCyclesPassed ( Handler, INT_MFP_CYCLE );
MainCounter = MFP_CYCLE_TO_REG ( CycInt_FindCyclesPassed ( Handler, INT_MFP_CYCLE ), TimerControl);
- //fprintf ( stderr , "mfp read CD passed %d count %d\n" , TimerCyclesPassed, MainCounter );
+ //fprintf ( stderr , "mfp read CD count %d\n" , MainCounter );
}
/* If the timer is stopped when the internal mfp data reg is already < 1 */
@@ -1199,8 +1363,8 @@ static Uint8 MFP_ReadTimerCD(Uint8 TimerControl, Uint8 TimerData, Uint8 MainCoun
if ( CycInt_FindCyclesPassed ( Handler, INT_MFP_CYCLE ) < MFP_REG_TO_CYCLES ( 1 , TimerControl ) )
{
MainCounter = 0; /* internal mfp counter becomes 0 (=256) */
- LOG_TRACE(TRACE_MFP_READ , "mfp read CD handler=%d stopping timer while data reg between 1 and 0 : forcing data to 256\n" ,
- Handler );
+ LOG_TRACE(TRACE_MFP_READ , "mfp%s read CD handler=%d stopping timer while data reg between 1 and 0 : forcing data to 256\n" ,
+ pMFP->NameSuffix , Handler );
}
}
@@ -1208,8 +1372,8 @@ static Uint8 MFP_ReadTimerCD(Uint8 TimerControl, Uint8 TimerData, Uint8 MainCoun
{
int FrameCycles, HblCounterVideo, LineCycles;
Video_GetPosition ( &FrameCycles , &HblCounterVideo , &LineCycles );
- LOG_TRACE_PRINT("mfp read CD handler=%d data=%d ctrl=%d timer_cyc=%d video_cyc=%d %d@%d pc=%x instr_cyc=%d\n" ,
- Handler, MainCounter, TimerControl, TimerCycles,
+ LOG_TRACE_PRINT("mfp%s read CD handler=%d data=%d ctrl=%d timer_cyc=%d video_cyc=%d %d@%d pc=%x instr_cyc=%d\n" ,
+ pMFP->NameSuffix , Handler, MainCounter, TimerControl, TimerCycles,
FrameCycles, LineCycles, HblCounterVideo, M68000_GetPC(), CurrentInstrCycles );
}
@@ -1221,10 +1385,10 @@ static Uint8 MFP_ReadTimerCD(Uint8 TimerControl, Uint8 TimerData, Uint8 MainCoun
/**
* Start Timer A
*/
-static void MFP_StartTimerA(void)
+static void MFP_StartTimerA ( MFP_STRUCT *pMFP )
{
- TimerAClockCycles = MFP_StartTimer_AB(MFP_TACR, MFP_TA_MAINCOUNTER,
- INTERRUPT_MFP_TIMERA, true, &TimerACanResume);
+ pMFP->TimerAClockCycles = MFP_StartTimer_AB ( pMFP , pMFP->TACR , pMFP->TA_MAINCOUNTER ,
+ pMFP == pMFP_Main ? INTERRUPT_MFP_MAIN_TIMERA : INTERRUPT_MFP_TT_TIMERA , true , &(pMFP->TimerACanResume) );
}
@@ -1232,10 +1396,10 @@ static void MFP_StartTimerA(void)
/**
* Read Timer A
*/
-static void MFP_ReadTimerA(bool TimerIsStopping)
+static void MFP_ReadTimerA ( MFP_STRUCT *pMFP , bool TimerIsStopping)
{
- MFP_TA_MAINCOUNTER = MFP_ReadTimer_AB(MFP_TACR, MFP_TA_MAINCOUNTER,
- TimerAClockCycles, INTERRUPT_MFP_TIMERA, TimerIsStopping);
+ pMFP->TA_MAINCOUNTER = MFP_ReadTimer_AB ( pMFP , pMFP->TACR , pMFP->TA_MAINCOUNTER , pMFP->TimerAClockCycles ,
+ pMFP == pMFP_Main ? INTERRUPT_MFP_MAIN_TIMERA : INTERRUPT_MFP_TT_TIMERA , TimerIsStopping);
}
@@ -1245,10 +1409,10 @@ static void MFP_ReadTimerA(bool TimerIsStopping)
* (This does not start the EventCount mode time as this is taken care
* of by the HBL)
*/
-static void MFP_StartTimerB(void)
+static void MFP_StartTimerB ( MFP_STRUCT *pMFP )
{
- TimerBClockCycles = MFP_StartTimer_AB(MFP_TBCR, MFP_TB_MAINCOUNTER,
- INTERRUPT_MFP_TIMERB, true, &TimerBCanResume);
+ pMFP->TimerBClockCycles = MFP_StartTimer_AB ( pMFP , pMFP->TBCR , pMFP->TB_MAINCOUNTER ,
+ pMFP == pMFP_Main ? INTERRUPT_MFP_MAIN_TIMERB : INTERRUPT_MFP_TT_TIMERB , true , &(pMFP->TimerBCanResume) );
}
@@ -1256,10 +1420,10 @@ static void MFP_StartTimerB(void)
/**
* Read Timer B
*/
-static void MFP_ReadTimerB(bool TimerIsStopping)
+static void MFP_ReadTimerB ( MFP_STRUCT *pMFP , bool TimerIsStopping )
{
- MFP_TB_MAINCOUNTER = MFP_ReadTimer_AB(MFP_TBCR, MFP_TB_MAINCOUNTER,
- TimerBClockCycles, INTERRUPT_MFP_TIMERB, TimerIsStopping);
+ pMFP->TB_MAINCOUNTER = MFP_ReadTimer_AB ( pMFP , pMFP->TBCR , pMFP->TB_MAINCOUNTER , pMFP->TimerBClockCycles ,
+ pMFP == pMFP_Main ? INTERRUPT_MFP_MAIN_TIMERB : INTERRUPT_MFP_TT_TIMERB , TimerIsStopping);
}
@@ -1267,10 +1431,10 @@ static void MFP_ReadTimerB(bool TimerIsStopping)
/**
* Start Timer C
*/
-static void MFP_StartTimerC(void)
+static void MFP_StartTimerC ( MFP_STRUCT *pMFP )
{
- TimerCClockCycles = MFP_StartTimer_CD((MFP_TCDCR>>4)&7, MFP_TC_MAINCOUNTER,
- INTERRUPT_MFP_TIMERC , true, &TimerCCanResume);
+ pMFP->TimerCClockCycles = MFP_StartTimer_CD ( pMFP , (pMFP->TCDCR>>4)&7 , pMFP->TC_MAINCOUNTER ,
+ pMFP == pMFP_Main ? INTERRUPT_MFP_MAIN_TIMERC : INTERRUPT_MFP_TT_TIMERC , true , &(pMFP->TimerCCanResume) );
}
@@ -1278,10 +1442,10 @@ static void MFP_StartTimerC(void)
/**
* Read Timer C
*/
-static void MFP_ReadTimerC(bool TimerIsStopping)
+static void MFP_ReadTimerC ( MFP_STRUCT *pMFP , bool TimerIsStopping )
{
- MFP_TC_MAINCOUNTER = MFP_ReadTimerCD((MFP_TCDCR>>4)&7, MFP_TCDR, MFP_TC_MAINCOUNTER,
- TimerCClockCycles, INTERRUPT_MFP_TIMERC, TimerIsStopping);
+ pMFP->TC_MAINCOUNTER = MFP_ReadTimer_CD ( pMFP , (pMFP->TCDCR>>4)&7 , pMFP->TCDR , pMFP->TC_MAINCOUNTER , pMFP->TimerCClockCycles ,
+ pMFP == pMFP_Main ? INTERRUPT_MFP_MAIN_TIMERC : INTERRUPT_MFP_TT_TIMERC , TimerIsStopping);
}
@@ -1289,10 +1453,10 @@ static void MFP_ReadTimerC(bool TimerIsStopping)
/**
* Start Timer D
*/
-static void MFP_StartTimerD(void)
+static void MFP_StartTimerD ( MFP_STRUCT *pMFP )
{
- TimerDClockCycles = MFP_StartTimer_CD(MFP_TCDCR&7, MFP_TD_MAINCOUNTER,
- INTERRUPT_MFP_TIMERD, true, &TimerDCanResume);
+ pMFP->TimerDClockCycles = MFP_StartTimer_CD ( pMFP , pMFP->TCDCR&7 , pMFP->TD_MAINCOUNTER ,
+ pMFP == pMFP_Main ? INTERRUPT_MFP_MAIN_TIMERD : INTERRUPT_MFP_TT_TIMERD , true , &(pMFP->TimerDCanResume) );
}
@@ -1300,10 +1464,10 @@ static void MFP_StartTimerD(void)
/**
* Read Timer D
*/
-static void MFP_ReadTimerD(bool TimerIsStopping)
+static void MFP_ReadTimerD ( MFP_STRUCT *pMFP , bool TimerIsStopping )
{
- MFP_TD_MAINCOUNTER = MFP_ReadTimerCD(MFP_TCDCR&7, MFP_TDDR, MFP_TD_MAINCOUNTER,
- TimerDClockCycles, INTERRUPT_MFP_TIMERD, TimerIsStopping);
+ pMFP->TD_MAINCOUNTER = MFP_ReadTimer_CD ( pMFP , pMFP->TCDCR&7 , pMFP->TDDR , pMFP->TD_MAINCOUNTER , pMFP->TimerDClockCycles ,
+ pMFP == pMFP_Main ? INTERRUPT_MFP_MAIN_TIMERD : INTERRUPT_MFP_TT_TIMERD , TimerIsStopping);
}
@@ -1311,7 +1475,7 @@ static void MFP_ReadTimerD(bool TimerIsStopping)
/**
* Handle Timer A Interrupt
*/
-void MFP_InterruptHandler_TimerA(void)
+static void MFP_InterruptHandler_TimerA ( MFP_STRUCT *pMFP , interrupt_id Handler )
{
/* Number of internal cycles we went over for this timer ( <= 0 ),
* used when timer expires and needs to be restarted */
@@ -1321,11 +1485,23 @@ void MFP_InterruptHandler_TimerA(void)
CycInt_AcknowledgeInterrupt();
/* Acknowledge in MFP circuit, pass bit,enable,pending */
- if ((MFP_TACR&0xf) != 0) /* Is timer OK? */
- MFP_InputOnChannel ( MFP_INT_TIMER_A , INT_CONVERT_FROM_INTERNAL ( PendingCyclesOver , INT_CPU_CYCLE ) );
+ if ( ( pMFP->TACR & 0xf ) != 0 ) /* Is timer OK? */
+ MFP_InputOnChannel ( pMFP , MFP_INT_TIMER_A , INT_CONVERT_FROM_INTERNAL ( PendingCyclesOver , INT_CPU_CYCLE ) );
/* Start next interrupt, if need one - from current cycle count */
- TimerAClockCycles = MFP_StartTimer_AB(MFP_TACR, MFP_TADR, INTERRUPT_MFP_TIMERA, false, &TimerACanResume);
+ pMFP->TimerAClockCycles = MFP_StartTimer_AB ( pMFP , pMFP->TACR , pMFP->TADR , Handler , false , &(pMFP->TimerACanResume) );
+}
+
+
+void MFP_Main_InterruptHandler_TimerA ( void )
+{
+ MFP_InterruptHandler_TimerA ( pMFP_Main , INTERRUPT_MFP_MAIN_TIMERA );
+}
+
+
+void MFP_TT_InterruptHandler_TimerA ( void )
+{
+ MFP_InterruptHandler_TimerA ( pMFP_TT , INTERRUPT_MFP_TT_TIMERA );
}
@@ -1333,7 +1509,7 @@ void MFP_InterruptHandler_TimerA(void)
/**
* Handle Timer B Interrupt
*/
-void MFP_InterruptHandler_TimerB(void)
+static void MFP_InterruptHandler_TimerB ( MFP_STRUCT *pMFP , interrupt_id Handler )
{
/* Number of internal cycles we went over for this timer ( <= 0 ),
* used when timer expires and needs to be restarted */
@@ -1343,11 +1519,23 @@ void MFP_InterruptHandler_TimerB(void)
CycInt_AcknowledgeInterrupt();
/* Acknowledge in MFP circuit, pass bit, enable, pending */
- if ((MFP_TBCR&0xf) != 0) /* Is timer OK? */
- MFP_InputOnChannel ( MFP_INT_TIMER_B , INT_CONVERT_FROM_INTERNAL ( PendingCyclesOver , INT_CPU_CYCLE ) );
+ if ( ( pMFP->TBCR & 0xf ) != 0 ) /* Is timer OK? */
+ MFP_InputOnChannel ( pMFP , MFP_INT_TIMER_B , INT_CONVERT_FROM_INTERNAL ( PendingCyclesOver , INT_CPU_CYCLE ) );
/* Start next interrupt, if need one - from current cycle count */
- TimerBClockCycles = MFP_StartTimer_AB(MFP_TBCR, MFP_TBDR, INTERRUPT_MFP_TIMERB, false, &TimerBCanResume);
+ pMFP->TimerBClockCycles = MFP_StartTimer_AB ( pMFP , pMFP->TBCR , pMFP->TBDR , Handler , false , &(pMFP->TimerBCanResume) );
+}
+
+
+void MFP_Main_InterruptHandler_TimerB ( void )
+{
+ MFP_InterruptHandler_TimerB ( pMFP_Main , INTERRUPT_MFP_MAIN_TIMERB );
+}
+
+
+void MFP_TT_InterruptHandler_TimerB ( void )
+{
+ MFP_InterruptHandler_TimerB ( pMFP_TT , INTERRUPT_MFP_TT_TIMERB );
}
@@ -1355,7 +1543,7 @@ void MFP_InterruptHandler_TimerB(void)
/**
* Handle Timer C Interrupt
*/
-void MFP_InterruptHandler_TimerC(void)
+static void MFP_InterruptHandler_TimerC ( MFP_STRUCT *pMFP , interrupt_id Handler )
{
/* Number of internal cycles we went over for this timer ( <= 0 ),
* used when timer expires and needs to be restarted */
@@ -1365,11 +1553,23 @@ void MFP_InterruptHandler_TimerC(void)
CycInt_AcknowledgeInterrupt();
/* Acknowledge in MFP circuit, pass bit, enable, pending */
- if ((MFP_TCDCR&0x70) != 0) /* Is timer OK? */
- MFP_InputOnChannel ( MFP_INT_TIMER_C , INT_CONVERT_FROM_INTERNAL ( PendingCyclesOver , INT_CPU_CYCLE ) );
+ if ( ( pMFP->TCDCR & 0x70 ) != 0 ) /* Is timer OK? */
+ MFP_InputOnChannel ( pMFP , MFP_INT_TIMER_C , INT_CONVERT_FROM_INTERNAL ( PendingCyclesOver , INT_CPU_CYCLE ) );
/* Start next interrupt, if need one - from current cycle count */
- TimerCClockCycles = MFP_StartTimer_CD((MFP_TCDCR>>4)&7, MFP_TCDR, INTERRUPT_MFP_TIMERC, false, &TimerCCanResume);
+ pMFP->TimerCClockCycles = MFP_StartTimer_CD ( pMFP , (pMFP->TCDCR>>4)&7 , pMFP->TCDR , Handler , false , &(pMFP->TimerCCanResume) );
+}
+
+
+void MFP_Main_InterruptHandler_TimerC ( void )
+{
+ MFP_InterruptHandler_TimerC ( pMFP_Main , INTERRUPT_MFP_MAIN_TIMERC );
+}
+
+
+void MFP_TT_InterruptHandler_TimerC ( void )
+{
+ MFP_InterruptHandler_TimerC ( pMFP_TT , INTERRUPT_MFP_TT_TIMERC );
}
@@ -1377,7 +1577,7 @@ void MFP_InterruptHandler_TimerC(void)
/**
* Handle Timer D Interrupt
*/
-void MFP_InterruptHandler_TimerD(void)
+static void MFP_InterruptHandler_TimerD ( MFP_STRUCT *pMFP , interrupt_id Handler )
{
/* Number of internal cycles we went over for this timer ( <= 0 ),
* used when timer expires and needs to be restarted */
@@ -1387,18 +1587,43 @@ void MFP_InterruptHandler_TimerD(void)
CycInt_AcknowledgeInterrupt();
/* Acknowledge in MFP circuit, pass bit, enable, pending */
- if ((MFP_TCDCR&0x07) != 0) /* Is timer OK? */
- MFP_InputOnChannel ( MFP_INT_TIMER_D , INT_CONVERT_FROM_INTERNAL ( PendingCyclesOver , INT_CPU_CYCLE ) );
+ if ( ( pMFP->TCDCR & 0x07 ) != 0 ) /* Is timer OK? */
+ MFP_InputOnChannel ( pMFP , MFP_INT_TIMER_D , INT_CONVERT_FROM_INTERNAL ( PendingCyclesOver , INT_CPU_CYCLE ) );
/* Start next interrupt, if need one - from current cycle count */
- TimerDClockCycles = MFP_StartTimer_CD(MFP_TCDCR&7, MFP_TDDR, INTERRUPT_MFP_TIMERD, false, &TimerDCanResume);
+ pMFP->TimerDClockCycles = MFP_StartTimer_CD ( pMFP , pMFP->TCDCR&7 , pMFP->TDDR , Handler , false , &(pMFP->TimerDCanResume) );
+}
+
+
+void MFP_Main_InterruptHandler_TimerD ( void )
+{
+ MFP_InterruptHandler_TimerD ( pMFP_Main , INTERRUPT_MFP_MAIN_TIMERD );
+}
+
+
+void MFP_TT_InterruptHandler_TimerD ( void )
+{
+ MFP_InterruptHandler_TimerD ( pMFP_TT , INTERRUPT_MFP_TT_TIMERD );
}
+/*-----------------------------------------------------------------------*/
+/**
+ * Handle read from GPIP register (0xfffa01 or 0xfffa81)
+ * We call a different function depending on the MFP (Main or TT) as all
+ * the bits are specific
+ */
+void MFP_GPIP_ReadByte ( void )
+{
+ if ( IoAccessCurrentAddress == 0xfffa01 )
+ MFP_GPIP_ReadByte_Main ( pMFP_Main );
+ else
+ MFP_GPIP_ReadByte_TT ( pMFP_TT );
+}
/*-----------------------------------------------------------------------*/
/**
- * Handle read from GPIP pins register (0xfffa01).
+ * Handle read from main MFP GPIP pins register (0xfffa01).
*
* - Bit 0 is the BUSY signal of the printer port, it is SET if no printer
* is connected or on BUSY. Therefore we should assume it to be 0 in Hatari
@@ -1415,13 +1640,13 @@ void MFP_InterruptHandler_TimerD(void)
* When reading GPIP, output lines (DDR=1) should return the last value that was written,
* only input lines (DDR=0) should be updated.
*/
-void MFP_GPIP_ReadByte(void)
+void MFP_GPIP_ReadByte_Main ( MFP_STRUCT *pMFP )
{
Uint8 gpip_new;
M68000_WaitState(4);
- gpip_new = MFP_GPIP;
+ gpip_new = pMFP->GPIP;
if (!bUseHighRes)
gpip_new |= 0x80; /* Color monitor -> set top bit */
@@ -1451,580 +1676,1123 @@ void MFP_GPIP_ReadByte(void)
}
}
- gpip_new &= ~MFP_DDR; /* New input bits */
-
- MFP_GPIP = ( MFP_GPIP & MFP_DDR ) | gpip_new; /* Keep output bits unchanged and update input bits */
+ gpip_new &= ~pMFP->DDR; /* New input bits */
+ pMFP->GPIP = ( pMFP->GPIP & pMFP->DDR ) | gpip_new; /* Keep output bits unchanged and update input bits */
- IoMem[0xfffa01] = MFP_GPIP;
+ IoMem[IoAccessCurrentAddress] = pMFP->GPIP;
if ( LOG_TRACE_LEVEL( TRACE_MFP_READ ) )
{
int FrameCycles, HblCounterVideo, LineCycles;
Video_GetPosition ( &FrameCycles , &HblCounterVideo , &LineCycles );
- LOG_TRACE_PRINT("mfp read gpip fa01=0x%x video_cyc=%d %d@%d pc=%x instr_cycle %d\n" ,
- MFP_GPIP, FrameCycles, LineCycles, HblCounterVideo, M68000_GetPC(), CurrentInstrCycles );
+ LOG_TRACE_PRINT("mfp%s read gpip %x=0x%x video_cyc=%d %d@%d pc=%x instr_cycle %d\n" ,
+ pMFP->NameSuffix , IoAccessCurrentAddress, IoMem[IoAccessCurrentAddress],
+ FrameCycles, LineCycles, HblCounterVideo, M68000_GetPC(), CurrentInstrCycles );
}
}
/*-----------------------------------------------------------------------*/
/**
- * Handle read from active edge register (0xfffa03).
+ * Handle read from TT MFP GPIP pins register (0xfffa81)
+ *
+ *
+ * When reading GPIP, output lines (DDR=1) should return the last value that was written,
+ * only input lines (DDR=0) should be updated.
*/
-void MFP_ActiveEdge_ReadByte(void)
+void MFP_GPIP_ReadByte_TT ( MFP_STRUCT *pMFP )
{
+ Uint8 gpip_new;
+
M68000_WaitState(4);
- IoMem[0xfffa03] = MFP_AER;
+ /* TODO : handle all bits, default to 1 for now */
+ gpip_new = 0x7f;
+
+ if ( Ncr5380_TT_GetIRQ() )
+ gpip_new |= 0x80;
+
+ gpip_new &= ~pMFP->DDR; /* New input bits */
+ pMFP->GPIP = ( pMFP->GPIP & pMFP->DDR ) | gpip_new; /* Keep output bits unchanged and update input bits */
+
+ IoMem[IoAccessCurrentAddress] = pMFP->GPIP;
+
+ if ( LOG_TRACE_LEVEL( TRACE_MFP_READ ) )
+ {
+ int FrameCycles, HblCounterVideo, LineCycles;
+ Video_GetPosition ( &FrameCycles , &HblCounterVideo , &LineCycles );
+ LOG_TRACE_PRINT("mfp%s read gpip %x=0x%x video_cyc=%d %d@%d pc=%x instr_cycle %d\n" ,
+ pMFP->NameSuffix , IoAccessCurrentAddress, IoMem[IoAccessCurrentAddress],
+ FrameCycles, LineCycles, HblCounterVideo, M68000_GetPC(), CurrentInstrCycles );
+ }
}
/*-----------------------------------------------------------------------*/
/**
- * Handle read from data direction register (0xfffa05).
+ * Handle read from Active Edge Register AER (0xfffa03 or 0xfffa83)
*/
-void MFP_DataDirection_ReadByte(void)
+void MFP_ActiveEdge_ReadByte ( void )
{
+ MFP_STRUCT *pMFP;
+
M68000_WaitState(4);
- IoMem[0xfffa05] = MFP_DDR;
+ if ( IoAccessCurrentAddress == 0xfffa03 )
+ pMFP = pMFP_Main;
+ else
+ pMFP = pMFP_TT;
+
+ IoMem[IoAccessCurrentAddress] = pMFP->AER;
+
+ if ( LOG_TRACE_LEVEL( TRACE_MFP_READ ) )
+ {
+ int FrameCycles, HblCounterVideo, LineCycles;
+ Video_GetPosition ( &FrameCycles , &HblCounterVideo , &LineCycles );
+ LOG_TRACE_PRINT("mfp%s read aer %x=0x%x video_cyc=%d %d@%d pc=%x instr_cycle %d\n" ,
+ pMFP->NameSuffix , IoAccessCurrentAddress, IoMem[IoAccessCurrentAddress],
+ FrameCycles, LineCycles, HblCounterVideo, M68000_GetPC(), CurrentInstrCycles );
+ }
}
/*-----------------------------------------------------------------------*/
/**
- * Handle read from interrupt enable register A (0xfffa07).
+ * Handle read from Data Direction Register DDR (0xfffa05 or 0xfffa85)
*/
-void MFP_EnableA_ReadByte(void)
+void MFP_DataDirection_ReadByte ( void )
{
+ MFP_STRUCT *pMFP;
+
M68000_WaitState(4);
- IoMem[0xfffa07] = MFP_IERA;
+ if ( IoAccessCurrentAddress == 0xfffa05 )
+ pMFP = pMFP_Main;
+ else
+ pMFP = pMFP_TT;
+
+ IoMem[IoAccessCurrentAddress] = pMFP->DDR;
+
+ if ( LOG_TRACE_LEVEL( TRACE_MFP_READ ) )
+ {
+ int FrameCycles, HblCounterVideo, LineCycles;
+ Video_GetPosition ( &FrameCycles , &HblCounterVideo , &LineCycles );
+ LOG_TRACE_PRINT("mfp%s read ddr %x=0x%x video_cyc=%d %d@%d pc=%x instr_cycle %d\n" ,
+ pMFP->NameSuffix , IoAccessCurrentAddress, IoMem[IoAccessCurrentAddress],
+ FrameCycles, LineCycles, HblCounterVideo, M68000_GetPC(), CurrentInstrCycles );
+ }
}
/*-----------------------------------------------------------------------*/
/**
- * Handle read from interrupt enable register B (0xfffa09).
+ * Handle read from Interrupt Enable Register A IERA (0xfffa07 or 0xfffa87)
*/
-void MFP_EnableB_ReadByte(void)
+void MFP_EnableA_ReadByte ( void )
{
+ MFP_STRUCT *pMFP;
+
M68000_WaitState(4);
- IoMem[0xfffa09] = MFP_IERB;
+ if ( IoAccessCurrentAddress == 0xfffa07 )
+ pMFP = pMFP_Main;
+ else
+ pMFP = pMFP_TT;
+
+ IoMem[IoAccessCurrentAddress] = pMFP->IERA;
+
+ if ( LOG_TRACE_LEVEL( TRACE_MFP_READ ) )
+ {
+ int FrameCycles, HblCounterVideo, LineCycles;
+ Video_GetPosition ( &FrameCycles , &HblCounterVideo , &LineCycles );
+ LOG_TRACE_PRINT("mfp%s read iera %x=0x%x video_cyc=%d %d@%d pc=%x instr_cycle %d\n" ,
+ pMFP->NameSuffix , IoAccessCurrentAddress, IoMem[IoAccessCurrentAddress],
+ FrameCycles, LineCycles, HblCounterVideo, M68000_GetPC(), CurrentInstrCycles );
+ }
}
/*-----------------------------------------------------------------------*/
/**
- * Handle read from interrupt pending register A (0xfffa0b).
+ * Handle read from Interrupt Enable Register B IERB (0xfffa09 or 0xfffa89)
*/
-void MFP_PendingA_ReadByte(void)
+void MFP_EnableB_ReadByte ( void )
{
+ MFP_STRUCT *pMFP;
+
M68000_WaitState(4);
- IoMem[0xfffa0b] = MFP_IPRA;
+ if ( IoAccessCurrentAddress == 0xfffa09 )
+ pMFP = pMFP_Main;
+ else
+ pMFP = pMFP_TT;
+
+ IoMem[IoAccessCurrentAddress] = pMFP->IERB;
+
+ if ( LOG_TRACE_LEVEL( TRACE_MFP_READ ) )
+ {
+ int FrameCycles, HblCounterVideo, LineCycles;
+ Video_GetPosition ( &FrameCycles , &HblCounterVideo , &LineCycles );
+ LOG_TRACE_PRINT("mfp%s read ierb %x=0x%x video_cyc=%d %d@%d pc=%x instr_cycle %d\n" ,
+ pMFP->NameSuffix , IoAccessCurrentAddress, IoMem[IoAccessCurrentAddress],
+ FrameCycles, LineCycles, HblCounterVideo, M68000_GetPC(), CurrentInstrCycles );
+ }
}
/*-----------------------------------------------------------------------*/
/**
- * Handle read from interrupt pending register A (0xfffa0d).
+ * Handle read from Interrupt Pending Register A IPRA (0xfffa0b or 0xfffa8b)
*/
-void MFP_PendingB_ReadByte(void)
+void MFP_PendingA_ReadByte ( void )
{
+ MFP_STRUCT *pMFP;
+
M68000_WaitState(4);
- IoMem[0xfffa0d] = MFP_IPRB;
+ if ( IoAccessCurrentAddress == 0xfffa0b )
+ pMFP = pMFP_Main;
+ else
+ pMFP = pMFP_TT;
+
+ IoMem[IoAccessCurrentAddress] = pMFP->IPRA;
+
+ if ( LOG_TRACE_LEVEL( TRACE_MFP_READ ) )
+ {
+ int FrameCycles, HblCounterVideo, LineCycles;
+ Video_GetPosition ( &FrameCycles , &HblCounterVideo , &LineCycles );
+ LOG_TRACE_PRINT("mfp%s read ipra %x=0x%x video_cyc=%d %d@%d pc=%x instr_cycle %d\n" ,
+ pMFP->NameSuffix , IoAccessCurrentAddress, IoMem[IoAccessCurrentAddress],
+ FrameCycles, LineCycles, HblCounterVideo, M68000_GetPC(), CurrentInstrCycles );
+ }
}
/*-----------------------------------------------------------------------*/
/**
- * Handle read from interrupt in service register A (0xfffa0f).
+ * Handle read from Interrupt Pending Register B IPRB (0xfffa0d or 0xfffa8d)
*/
-void MFP_InServiceA_ReadByte(void)
+void MFP_PendingB_ReadByte ( void )
{
+ MFP_STRUCT *pMFP;
+
M68000_WaitState(4);
- IoMem[0xfffa0f] = MFP_ISRA;
+ if ( IoAccessCurrentAddress == 0xfffa0d )
+ pMFP = pMFP_Main;
+ else
+ pMFP = pMFP_TT;
+
+ IoMem[IoAccessCurrentAddress] = pMFP->IPRB;
+
+ if ( LOG_TRACE_LEVEL( TRACE_MFP_READ ) )
+ {
+ int FrameCycles, HblCounterVideo, LineCycles;
+ Video_GetPosition ( &FrameCycles , &HblCounterVideo , &LineCycles );
+ LOG_TRACE_PRINT("mfp%s read iprb %x=0x%x video_cyc=%d %d@%d pc=%x instr_cycle %d\n" ,
+ pMFP->NameSuffix , IoAccessCurrentAddress, IoMem[IoAccessCurrentAddress],
+ FrameCycles, LineCycles, HblCounterVideo, M68000_GetPC(), CurrentInstrCycles );
+ }
}
/*-----------------------------------------------------------------------*/
/**
- * Handle read from interrupt in service register B (0xfffa11).
+ * Handle read from Interrupt In Service Register A ISRA (0xfffa0f or 0xfffa8f)
*/
-void MFP_InServiceB_ReadByte(void)
+void MFP_InServiceA_ReadByte ( void )
{
+ MFP_STRUCT *pMFP;
+
M68000_WaitState(4);
- IoMem[0xfffa11] = MFP_ISRB;
+ if ( IoAccessCurrentAddress == 0xfffa0f )
+ pMFP = pMFP_Main;
+ else
+ pMFP = pMFP_TT;
+
+ IoMem[IoAccessCurrentAddress] = pMFP->ISRA;
+
+ if ( LOG_TRACE_LEVEL( TRACE_MFP_READ ) )
+ {
+ int FrameCycles, HblCounterVideo, LineCycles;
+ Video_GetPosition ( &FrameCycles , &HblCounterVideo , &LineCycles );
+ LOG_TRACE_PRINT("mfp%s read isra %x=0x%x video_cyc=%d %d@%d pc=%x instr_cycle %d\n" ,
+ pMFP->NameSuffix , IoAccessCurrentAddress, IoMem[IoAccessCurrentAddress],
+ FrameCycles, LineCycles, HblCounterVideo, M68000_GetPC(), CurrentInstrCycles );
+ }
}
/*-----------------------------------------------------------------------*/
/**
- * Handle read from interrupt mask register A (0xfffa13).
+ * Handle read from Interrupt In Service Register B ISRB (0xfffa11 or 0xfffa91)
*/
-void MFP_MaskA_ReadByte(void)
+void MFP_InServiceB_ReadByte ( void )
{
+ MFP_STRUCT *pMFP;
+
M68000_WaitState(4);
- IoMem[0xfffa13] = MFP_IMRA;
+ if ( IoAccessCurrentAddress == 0xfffa11 )
+ pMFP = pMFP_Main;
+ else
+ pMFP = pMFP_TT;
+
+ IoMem[IoAccessCurrentAddress] = pMFP->ISRB;
+
+ if ( LOG_TRACE_LEVEL( TRACE_MFP_READ ) )
+ {
+ int FrameCycles, HblCounterVideo, LineCycles;
+ Video_GetPosition ( &FrameCycles , &HblCounterVideo , &LineCycles );
+ LOG_TRACE_PRINT("mfp%s read isrb %x=0x%x video_cyc=%d %d@%d pc=%x instr_cycle %d\n" ,
+ pMFP->NameSuffix , IoAccessCurrentAddress, IoMem[IoAccessCurrentAddress],
+ FrameCycles, LineCycles, HblCounterVideo, M68000_GetPC(), CurrentInstrCycles );
+ }
}
/*-----------------------------------------------------------------------*/
/**
- * Handle read from interrupt mask register B (0xfffa15).
+ * Handle read from Interrupt Mask Register A IMRA (0xfffa13 or 0xfffa93)
*/
-void MFP_MaskB_ReadByte(void)
+void MFP_MaskA_ReadByte ( void )
{
+ MFP_STRUCT *pMFP;
+
M68000_WaitState(4);
- IoMem[0xfffa15] = MFP_IMRB;
+ if ( IoAccessCurrentAddress == 0xfffa13 )
+ pMFP = pMFP_Main;
+ else
+ pMFP = pMFP_TT;
+
+ IoMem[IoAccessCurrentAddress] = pMFP->IMRA;
+
+ if ( LOG_TRACE_LEVEL( TRACE_MFP_READ ) )
+ {
+ int FrameCycles, HblCounterVideo, LineCycles;
+ Video_GetPosition ( &FrameCycles , &HblCounterVideo , &LineCycles );
+ LOG_TRACE_PRINT("mfp%s read imra %x=0x%x video_cyc=%d %d@%d pc=%x instr_cycle %d\n" ,
+ pMFP->NameSuffix , IoAccessCurrentAddress, IoMem[IoAccessCurrentAddress],
+ FrameCycles, LineCycles, HblCounterVideo, M68000_GetPC(), CurrentInstrCycles );
+ }
}
/*-----------------------------------------------------------------------*/
/**
- * Handle read from MFP vector register (0xfffa17).
+ * Handle read from Interrupt Mask Register B IMRB (0xfffa15 or 0xfffa95)
*/
-void MFP_VectorReg_ReadByte(void)
+void MFP_MaskB_ReadByte ( void )
{
+ MFP_STRUCT *pMFP;
+
M68000_WaitState(4);
- IoMem[0xfffa17] = MFP_VR;
+ if ( IoAccessCurrentAddress == 0xfffa15 )
+ pMFP = pMFP_Main;
+ else
+ pMFP = pMFP_TT;
+
+ IoMem[IoAccessCurrentAddress] = pMFP->IMRB;
+
+ if ( LOG_TRACE_LEVEL( TRACE_MFP_READ ) )
+ {
+ int FrameCycles, HblCounterVideo, LineCycles;
+ Video_GetPosition ( &FrameCycles , &HblCounterVideo , &LineCycles );
+ LOG_TRACE_PRINT("mfp%s read imrb %x=0x%x video_cyc=%d %d@%d pc=%x instr_cycle %d\n" ,
+ pMFP->NameSuffix , IoAccessCurrentAddress, IoMem[IoAccessCurrentAddress],
+ FrameCycles, LineCycles, HblCounterVideo, M68000_GetPC(), CurrentInstrCycles );
+ }
}
/*-----------------------------------------------------------------------*/
/**
- * Handle read from timer A control register (0xfffa19).
+ * Handle read from MFP Vector Register VR (0xfffa17 or 0xfffa97)
*/
-void MFP_TimerACtrl_ReadByte(void)
+void MFP_VectorReg_ReadByte ( void )
{
+ MFP_STRUCT *pMFP;
+
M68000_WaitState(4);
- IoMem[0xfffa19] = MFP_TACR;
+ if ( IoAccessCurrentAddress == 0xfffa17 )
+ pMFP = pMFP_Main;
+ else
+ pMFP = pMFP_TT;
+
+ IoMem[IoAccessCurrentAddress] = pMFP->VR;
+
+ if ( LOG_TRACE_LEVEL( TRACE_MFP_READ ) )
+ {
+ int FrameCycles, HblCounterVideo, LineCycles;
+ Video_GetPosition ( &FrameCycles , &HblCounterVideo , &LineCycles );
+ LOG_TRACE_PRINT("mfp%s read vr %x=0x%x video_cyc=%d %d@%d pc=%x instr_cycle %d\n" ,
+ pMFP->NameSuffix , IoAccessCurrentAddress, IoMem[IoAccessCurrentAddress],
+ FrameCycles, LineCycles, HblCounterVideo, M68000_GetPC(), CurrentInstrCycles );
+ }
}
/*-----------------------------------------------------------------------*/
/**
- * Handle read from timer B control register (0xfffa1b).
+ * Handle read from Timer A Control Register TACR (0xfffa19 or 0xfffa99)
*/
-void MFP_TimerBCtrl_ReadByte(void)
+void MFP_TimerACtrl_ReadByte ( void )
{
+ MFP_STRUCT *pMFP;
+
M68000_WaitState(4);
- IoMem[0xfffa1b] = MFP_TBCR;
-}
+ if ( IoAccessCurrentAddress == 0xfffa19 )
+ pMFP = pMFP_Main;
+ else
+ pMFP = pMFP_TT;
+
+ IoMem[IoAccessCurrentAddress] = pMFP->TACR;
+
+ if ( LOG_TRACE_LEVEL( TRACE_MFP_READ ) )
+ {
+ int FrameCycles, HblCounterVideo, LineCycles;
+ Video_GetPosition ( &FrameCycles , &HblCounterVideo , &LineCycles );
+ LOG_TRACE_PRINT("mfp%s read tacr %x=0x%x video_cyc=%d %d@%d pc=%x instr_cycle %d\n" ,
+ pMFP->NameSuffix , IoAccessCurrentAddress, IoMem[IoAccessCurrentAddress],
+ FrameCycles, LineCycles, HblCounterVideo, M68000_GetPC(), CurrentInstrCycles );
+ }
+}
/*-----------------------------------------------------------------------*/
/**
- * Handle read from timer C/D control register (0xfffa1d).
+ * Handle read from Timer B Control Register TBCR (0xfffa1b or 0Xfffa9b)
*/
-void MFP_TimerCDCtrl_ReadByte(void)
+void MFP_TimerBCtrl_ReadByte ( void )
{
+ MFP_STRUCT *pMFP;
+
M68000_WaitState(4);
- IoMem[0xfffa1d] = MFP_TCDCR;
+ if ( IoAccessCurrentAddress == 0xfffa1b )
+ pMFP = pMFP_Main;
+ else
+ pMFP = pMFP_TT;
+
+ IoMem[IoAccessCurrentAddress] = pMFP->TBCR;
+
+ if ( LOG_TRACE_LEVEL( TRACE_MFP_READ ) )
+ {
+ int FrameCycles, HblCounterVideo, LineCycles;
+ Video_GetPosition ( &FrameCycles , &HblCounterVideo , &LineCycles );
+ LOG_TRACE_PRINT("mfp%s read tbcr %x=0x%x video_cyc=%d %d@%d pc=%x instr_cycle %d\n" ,
+ pMFP->NameSuffix , IoAccessCurrentAddress, IoMem[IoAccessCurrentAddress],
+ FrameCycles, LineCycles, HblCounterVideo, M68000_GetPC(), CurrentInstrCycles );
+ }
}
/*-----------------------------------------------------------------------*/
/**
- * Handle read from timer A data register (0xfffa1f).
+ * Handle read from Timer C/D Control Register TCDCR (0xfffa1d or 0xfffa9d)
*/
-void MFP_TimerAData_ReadByte(void)
+void MFP_TimerCDCtrl_ReadByte ( void )
{
+ MFP_STRUCT *pMFP;
+
M68000_WaitState(4);
- if (MFP_TACR != 8) /* Is event count? Need to re-calculate counter */
- MFP_ReadTimerA(false); /* Stores result in 'MFP_TA_MAINCOUNTER' */
+ if ( IoAccessCurrentAddress == 0xfffa1d )
+ pMFP = pMFP_Main;
+ else
+ pMFP = pMFP_TT;
+
+ IoMem[IoAccessCurrentAddress] = pMFP->TCDCR;
- IoMem[0xfffa1f] = MFP_TA_MAINCOUNTER;
+ if ( LOG_TRACE_LEVEL( TRACE_MFP_READ ) )
+ {
+ int FrameCycles, HblCounterVideo, LineCycles;
+ Video_GetPosition ( &FrameCycles , &HblCounterVideo , &LineCycles );
+ LOG_TRACE_PRINT("mfp%s read tcdcr %x=0x%x video_cyc=%d %d@%d pc=%x instr_cycle %d\n" ,
+ pMFP->NameSuffix , IoAccessCurrentAddress, IoMem[IoAccessCurrentAddress],
+ FrameCycles, LineCycles, HblCounterVideo, M68000_GetPC(), CurrentInstrCycles );
+ }
}
/*-----------------------------------------------------------------------*/
/**
- * Handle read from timer B data register (0xfffa21).
+ * Handle read from Timer A Data Egister TADR (0xfffa1f or 0xfffa9f)
*/
-void MFP_TimerBData_ReadByte(void)
+void MFP_TimerAData_ReadByte ( void )
{
- Uint8 TB_count;
+ MFP_STRUCT *pMFP;
M68000_WaitState(4);
- /* Is it event count mode or not? */
- if (MFP_TBCR != 8)
- {
- /* Not event count mode, so handle as normal timer
- * and store result in 'MFP_TB_MAINCOUNTER' */
- MFP_ReadTimerB(false);
- }
- else if (bUseVDIRes)
- {
- /* HBLs are disabled in VDI mode, but TOS expects to read a 1. */
- MFP_TB_MAINCOUNTER = 1;
- }
- /* Special case when reading $fffa21, we need to test if the current read instruction */
- /* overlaps the horizontal video position where $fffa21 is changed */
+ if ( IoAccessCurrentAddress == 0xfffa1f )
+ pMFP = pMFP_Main;
else
+ pMFP = pMFP_TT;
+
+ if ( pMFP->TACR != 8 ) /* Is event count? Need to update counter */
+ MFP_ReadTimerA ( pMFP , false ); /* Store result in 'TA_MAINCOUNTER' */
+
+ IoMem[IoAccessCurrentAddress] = pMFP->TA_MAINCOUNTER;
+
+ if ( LOG_TRACE_LEVEL( TRACE_MFP_READ ) )
{
- int FrameCycles, HblCounterVideo;
- int pos_start , pos_read;
+ int FrameCycles, HblCounterVideo, LineCycles;
+ Video_GetPosition ( &FrameCycles , &HblCounterVideo , &LineCycles );
+ LOG_TRACE_PRINT("mfp%s read tadr %x=0x%x video_cyc=%d %d@%d pc=%x instr_cycle %d\n" ,
+ pMFP->NameSuffix , IoAccessCurrentAddress, IoMem[IoAccessCurrentAddress],
+ FrameCycles, LineCycles, HblCounterVideo, M68000_GetPC(), CurrentInstrCycles );
+ }
+}
+
+/*-----------------------------------------------------------------------*/
+/**
+ * Handle read from Timer B Data Register TBDR (0xfffa21 or 0xfffaa1)
+ */
+void MFP_TimerBData_ReadByte(void)
+{
+ MFP_STRUCT *pMFP;
+ Uint8 TB_count;
- /* Cycle position of the start of the current instruction */
- //pos_start = nFrameCycles % nCyclesPerLine;
- Video_GetPosition ( &FrameCycles , &HblCounterVideo , &pos_start );
- pos_start >>= nCpuFreqShift;
+ M68000_WaitState(4);
- /* Cycle position of the read for the current instruction (approximatively, we consider */
- /* the read happens after 4 cycles (due to MFP wait states in that case)) */
- /* This is quite a hack, but hard to do without proper 68000 read cycle emulation */
- if ( CurrentInstrCycles <= 8 ) /* move.b (a0),d0 / cmp.b (a0),d0 ... */
- pos_read = pos_start + 4; /* wait state */
- else /* cmp.b $fa21.w,d0 (BIG Demo) ... */
- pos_read = pos_start + 8; /* more time needed to compute the effective address */
+ if ( IoAccessCurrentAddress == 0xfffa21 )
+ pMFP = pMFP_Main;
+ else
+ pMFP = pMFP_TT;
- TB_count = MFP_TB_MAINCOUNTER; /* default value */
+ /* Is it event count mode or not? */
+ if ( pMFP->TBCR != 8 )
+ {
+ /* Not event count mode, so handle as normal timer
+ * and store result in 'TB_MAINCOUNTER' */
+ MFP_ReadTimerB ( pMFP , false );
+ }
- /* If Timer B's change happens before the read cycle of the current instruction, we must return */
- /* the current value - 1 (because MFP_TimerB_EventCount_Interrupt was not called yet) */
- if ( (nHBL >= nStartHBL ) && ( nHBL < nEndHBL ) /* ensure display is ON and timer B can happen */
- && ( LineTimerBPos > pos_start ) && ( LineTimerBPos < pos_read ) )
+ /* Video DE signal is connected to Timer B on the main MFP */
+ if ( IoAccessCurrentAddress == 0xfffa21 )
+ {
+ if (bUseVDIRes)
{
- LOG_TRACE(TRACE_MFP_READ , "mfp read TB overlaps pos_start=%d TB_pos=%d pos_read=%d nHBL=%d \n",
- pos_start, LineTimerBPos, pos_read , HblCounterVideo );
-
- TB_count--;
- if ( TB_count == 0 ) /* going from 1 to 0 : timer restart, reload data reg */
- TB_count = MFP_TBDR;
- /* Going from 0 to -1 : data reg is in fact going from 256 to 255. As TB_count is Uint8, */
- /* this is already what we get when we decrement TB_count=0. So, the next 2 lines are redundant. */
-/* else if ( TB_count < 0 )
- TB_count = 255;
-*/
+ /* HBLs are disabled in VDI mode, but TOS expects to read a 1 */
+ pMFP->TB_MAINCOUNTER = 1;
}
+ /* Special case when reading $fffa21, we need to test if the current read instruction */
+ /* overlaps the horizontal video position where $fffa21 is changed */
+ else
+ {
+ int FrameCycles, HblCounterVideo;
+ int pos_start , pos_read;
+
+ /* Cycle position of the start of the current instruction */
+ //pos_start = nFrameCycles % nCyclesPerLine;
+ Video_GetPosition ( &FrameCycles , &HblCounterVideo , &pos_start );
+ pos_start >>= nCpuFreqShift;
+
+ /* Cycle position of the read for the current instruction (approximatively, we consider */
+ /* the read happens after 4 cycles (due to MFP wait states in that case)) */
+ /* This is quite a hack, but hard to do without proper 68000 read cycle emulation */
+ if ( CurrentInstrCycles <= 8 ) /* move.b (a0),d0 / cmp.b (a0),d0 ... */
+ pos_read = pos_start + 4; /* wait state */
+ else /* cmp.b $fa21.w,d0 (BIG Demo) ... */
+ pos_read = pos_start + 8; /* more time needed to compute the effective address */
+
+ TB_count = pMFP->TB_MAINCOUNTER; /* default value */
+
+ /* If Timer B's change happens before the read cycle of the current instruction, we must return */
+ /* the current value - 1 (because MFP_TimerB_EventCount_Interrupt was not called yet) */
+ if ( (nHBL >= nStartHBL ) && ( nHBL < nEndHBL ) /* ensure display is ON and timer B can happen */
+ && ( LineTimerBPos > pos_start ) && ( LineTimerBPos < pos_read ) )
+ {
+ LOG_TRACE(TRACE_MFP_READ , "mfp%s read tbdr overlaps pos_start=%d TB_pos=%d pos_read=%d nHBL=%d \n",
+ pMFP->NameSuffix , pos_start, LineTimerBPos, pos_read , HblCounterVideo );
+
+ TB_count--;
+ if ( TB_count == 0 ) /* going from 1 to 0 : timer restart, reload data reg */
+ TB_count = pMFP->TBDR;
+ /* Going from 0 to -1 : data reg is in fact going from 256 to 255. As TB_count is Uint8, */
+ /* this is already what we get when we decrement TB_count=0. So, the next 2 lines are redundant. */
+ /* else if ( TB_count < 0 )
+ TB_count = 255;
+ */
+ }
- LOG_TRACE(TRACE_MFP_READ , "mfp read TB data=%d video_cyc=%d %d@%d pc=%x instr_cyc=%d\n" ,
- TB_count, FrameCycles, pos_start, HblCounterVideo, M68000_GetPC(), CurrentInstrCycles );
- IoMem[0xfffa21] = TB_count;
- return;
+ LOG_TRACE(TRACE_MFP_READ , "mfp%s read tbdr data=%d video_cyc=%d %d@%d pc=%x instr_cyc=%d\n" ,
+ pMFP->NameSuffix , TB_count, FrameCycles, pos_start, HblCounterVideo, M68000_GetPC(), CurrentInstrCycles );
+ IoMem[IoAccessCurrentAddress] = TB_count;
+ return;
+ }
}
- IoMem[0xfffa21] = MFP_TB_MAINCOUNTER;
+ IoMem[IoAccessCurrentAddress] = pMFP->TB_MAINCOUNTER;
+
+ if ( LOG_TRACE_LEVEL( TRACE_MFP_READ ) )
+ {
+ int FrameCycles, HblCounterVideo, LineCycles;
+ Video_GetPosition ( &FrameCycles , &HblCounterVideo , &LineCycles );
+ LOG_TRACE_PRINT("mfp%s read tbdr %x=0x%x video_cyc=%d %d@%d pc=%x instr_cycle %d\n" ,
+ pMFP->NameSuffix , IoAccessCurrentAddress, IoMem[IoAccessCurrentAddress],
+ FrameCycles, LineCycles, HblCounterVideo, M68000_GetPC(), CurrentInstrCycles );
+ }
}
/*-----------------------------------------------------------------------*/
/**
- * Handle read from timer C data register (0xfffa23).
+ * Handle read from Timer C Data Register TCDR (0xfffa23 or 0xfffaa3)
*/
-void MFP_TimerCData_ReadByte(void)
+void MFP_TimerCData_ReadByte(void)
{
+ MFP_STRUCT *pMFP;
+
M68000_WaitState(4);
- MFP_ReadTimerC(false); /* Stores result in 'MFP_TC_MAINCOUNTER' */
+ if ( IoAccessCurrentAddress == 0xfffa23 )
+ pMFP = pMFP_Main;
+ else
+ pMFP = pMFP_TT;
+
+ MFP_ReadTimerC ( pMFP , false ); /* Store result in 'TC_MAINCOUNTER' */
+
+ IoMem[IoAccessCurrentAddress] = pMFP->TC_MAINCOUNTER;
- IoMem[0xfffa23] = MFP_TC_MAINCOUNTER;
+ if ( LOG_TRACE_LEVEL( TRACE_MFP_READ ) )
+ {
+ int FrameCycles, HblCounterVideo, LineCycles;
+ Video_GetPosition ( &FrameCycles , &HblCounterVideo , &LineCycles );
+ LOG_TRACE_PRINT("mfp%s read tcdr %x=0x%x video_cyc=%d %d@%d pc=%x instr_cycle %d\n" ,
+ pMFP->NameSuffix , IoAccessCurrentAddress, IoMem[IoAccessCurrentAddress],
+ FrameCycles, LineCycles, HblCounterVideo, M68000_GetPC(), CurrentInstrCycles );
+ }
}
/*-----------------------------------------------------------------------*/
/**
- * Handle read from timer D data register (0xfffa25).
+ * Handle read from Timer D Data Register TDDR (0xfffa25 or 0xfffaa5)
*/
-void MFP_TimerDData_ReadByte(void)
+void MFP_TimerDData_ReadByte ( void )
{
- Uint32 pc = M68000_GetPC();
+ MFP_STRUCT *pMFP;
+ Uint32 pc = M68000_GetPC();
M68000_WaitState(4);
- if (ConfigureParams.System.bPatchTimerD && pc >= TosAddress && pc <= TosAddress + TosSize)
+ if ( IoAccessCurrentAddress == 0xfffa25 )
+ pMFP = pMFP_Main;
+ else
+ pMFP = pMFP_TT;
+
+ /* Special case for the main MFP when bPatchTimerD is used */
+ /* NOTE : in TT mode TOS also starts useless timer D on the TT MFP, so we should restore */
+ /* 0xfffa25/0xfffaa5 for Main MFP and TT MFP when bPatchTimerD is enabled */
+ if ( ConfigureParams.System.bPatchTimerD && pc >= TosAddress && pc <= TosAddress + TosSize )
{
- /* Trick the tos to believe it was changed: */
- IoMem[0xfffa25] = nTimerDFakeValue;
+ /* Trick the tos to believe TDDR was not changed */
+ IoMem[IoAccessCurrentAddress] = pMFP->PatchTimerD_TDDR_old;
}
+
else
{
- MFP_ReadTimerD(false); /* Stores result in 'MFP_TD_MAINCOUNTER' */
- IoMem[0xfffa25] = MFP_TD_MAINCOUNTER;
+ MFP_ReadTimerD ( pMFP , false ); /* Store result in 'TD_MAINCOUNTER' */
+ IoMem[IoAccessCurrentAddress] = pMFP->TD_MAINCOUNTER;
+ }
+
+ if ( LOG_TRACE_LEVEL( TRACE_MFP_READ ) )
+ {
+ int FrameCycles, HblCounterVideo, LineCycles;
+ Video_GetPosition ( &FrameCycles , &HblCounterVideo , &LineCycles );
+ LOG_TRACE_PRINT("mfp%s read tddr %x=0x%x video_cyc=%d %d@%d pc=%x instr_cycle %d\n" ,
+ pMFP->NameSuffix , IoAccessCurrentAddress, IoMem[IoAccessCurrentAddress],
+ FrameCycles, LineCycles, HblCounterVideo, M68000_GetPC(), CurrentInstrCycles );
}
}
/*-----------------------------------------------------------------------*/
/**
- * Handle write to GPIP register (0xfffa01).
+ * Handle write to GPIP register (0xfffa01 or 0xfffa81)
*
* Only line configured as output in DDR can be changed (0=input 1=output)
* When reading GPIP, output lines should return the last value that was written,
* only input lines should be updated.
*/
-void MFP_GPIP_WriteByte(void)
+void MFP_GPIP_WriteByte ( void )
{
- Uint8 GPIP_new;
- Uint8 GPIP_old = MFP_GPIP;
+ MFP_STRUCT *pMFP;
+ Uint8 GPIP_old;
+ Uint8 GPIP_new;
M68000_WaitState(4);
- GPIP_new = IoMem[0xfffa01] & MFP_DDR; /* New output bits */
+ if ( IoAccessCurrentAddress == 0xfffa01 )
+ pMFP = pMFP_Main;
+ else
+ pMFP = pMFP_TT;
- MFP_GPIP = ( MFP_GPIP & ~MFP_DDR ) | GPIP_new; /* Keep input bits unchanged and update output bits */
+ if ( LOG_TRACE_LEVEL( TRACE_MFP_WRITE ) )
+ {
+ int FrameCycles, HblCounterVideo, LineCycles;
+ Video_GetPosition ( &FrameCycles , &HblCounterVideo , &LineCycles );
+ LOG_TRACE_PRINT("mfp%s write gpip %x=0x%x video_cyc=%d %d@%d pc=%x instr_cycle %d\n" ,
+ pMFP->NameSuffix , IoAccessCurrentAddress, IoMem[IoAccessCurrentAddress],
+ FrameCycles, LineCycles, HblCounterVideo, M68000_GetPC(), CurrentInstrCycles );
+ }
+
+ GPIP_old = pMFP->GPIP;
+ GPIP_new = IoMem[IoAccessCurrentAddress] & pMFP->DDR; /* New output bits */
+ pMFP->GPIP = ( GPIP_old & ~pMFP->DDR ) | GPIP_new; /* Keep input bits unchanged and update output bits */
/* Update possible interrupts after changing GPIP */
- MFP_GPIP_Update_Interrupt ( GPIP_old , MFP_GPIP , MFP_AER , MFP_AER , MFP_DDR , MFP_DDR );
+ MFP_GPIP_Update_Interrupt ( pMFP , GPIP_old , pMFP->GPIP , pMFP->AER , pMFP->AER , pMFP->DDR , pMFP->DDR );
}
/*-----------------------------------------------------------------------*/
/**
- * Handle write to AER (0xfffa03)
+ * Handle write to Active Edge Register AER (0xfffa03 or 0xfffa83)
*
- * Special case for bit 3 :
+ * Special case for bit 3 of main MFP (0xfffa03) :
* Bit 3 of AER is linked to timer B in event count mode.
* - If bit 3=0, timer B triggers on end of line when display goes off.
* - If bit 3=1, timer B triggers on start of line when display goes on.
*/
-void MFP_ActiveEdge_WriteByte(void)
+void MFP_ActiveEdge_WriteByte ( void )
{
- Uint8 AER_old;
+ MFP_STRUCT *pMFP;
+ Uint8 AER_old;
M68000_WaitState(4);
- AER_old = MFP_AER;
- MFP_AER = IoMem[0xfffa03];
-
- /* Update possible interrupts after changing AER */
- MFP_GPIP_Update_Interrupt ( MFP_GPIP , MFP_GPIP , AER_old , MFP_AER , MFP_DDR , MFP_DDR );
-
+ if ( IoAccessCurrentAddress == 0xfffa03 )
+ pMFP = pMFP_Main;
+ else
+ pMFP = pMFP_TT;
- /* Special case when changing bit 3 : we need to update the position of the timer B interrupt for 'event count' mode */
- if ( ( AER_old & ( 1 << 3 ) ) != ( MFP_AER & ( 1 << 3 ) ) )
+ if ( LOG_TRACE_LEVEL( TRACE_MFP_WRITE ) )
{
int FrameCycles, HblCounterVideo, LineCycles;
- int LineTimerBPos_old = LineTimerBPos;
-
Video_GetPosition ( &FrameCycles , &HblCounterVideo , &LineCycles );
+ LOG_TRACE_PRINT("mfp%s write aer %x=0x%x video_cyc=%d %d@%d pc=%x instr_cycle %d\n" ,
+ pMFP->NameSuffix , IoAccessCurrentAddress, IoMem[IoAccessCurrentAddress],
+ FrameCycles, LineCycles, HblCounterVideo, M68000_GetPC(), CurrentInstrCycles );
+ }
- /* 0 -> 1, timer B is now counting start of line events (cycle 56+28) */
- if ( ( AER_old & ( 1 << 3 ) ) == 0 )
- {
- LineTimerBPos = Video_TimerB_GetPos ( HblCounterVideo );
+ AER_old = pMFP->AER;
+ pMFP->AER = IoMem[IoAccessCurrentAddress];
- LOG_TRACE((TRACE_VIDEO_HBL | TRACE_MFP_WRITE),
- "mfp/video AER bit 3 0->1, timer B triggers on start of line,"
- " old_pos=%d new_pos=%d video_cyc=%d %d@%d pc=%x instr_cyc=%d\n",
- LineTimerBPos_old, LineTimerBPos,
- FrameCycles, LineCycles, nHBL, M68000_GetPC(), CurrentInstrCycles);
- }
+ /* Update possible interrupts after changing AER */
+ MFP_GPIP_Update_Interrupt ( pMFP , pMFP->GPIP , pMFP->GPIP , AER_old , pMFP->AER , pMFP->DDR , pMFP->DDR );
- /* 1 -> 0, timer B is now counting end of line events (cycle 376+28) */
- else if ( ( AER_old & ( 1 << 3 ) ) != 0 )
+ /* Special case when changing bit 3 in main MFP : */
+ /* Video DE signal is connected to Timer B on the main MFP */
+ /* We need to update the position of the timer B interrupt for 'event count' mode */
+ if ( IoAccessCurrentAddress == 0xfffa03 )
+ {
+ if ( ( AER_old & ( 1 << 3 ) ) != ( pMFP->AER & ( 1 << 3 ) ) )
{
- LineTimerBPos = Video_TimerB_GetPos ( HblCounterVideo );
+ int FrameCycles, HblCounterVideo, LineCycles;
+ int LineTimerBPos_old = LineTimerBPos;
- LOG_TRACE((TRACE_VIDEO_HBL | TRACE_MFP_WRITE),
- "mfp/video AER bit 3 1->0, timer B triggers on end of line,"
- " old_pos=%d new_pos=%d video_cyc=%d %d@%d pc=%x instr_cyc=%d\n",
- LineTimerBPos_old, LineTimerBPos,
- FrameCycles, LineCycles, nHBL, M68000_GetPC(), CurrentInstrCycles);
- }
+ Video_GetPosition ( &FrameCycles , &HblCounterVideo , &LineCycles );
- /* Timer B position changed, update the next interrupt */
- if ( LineTimerBPos_old != LineTimerBPos )
- Video_AddInterruptTimerB ( HblCounterVideo , LineCycles , LineTimerBPos );
+ /* 0 -> 1, timer B is now counting start of line events (cycle 56+28) */
+ if ( ( AER_old & ( 1 << 3 ) ) == 0 )
+ {
+ LineTimerBPos = Video_TimerB_GetPos ( HblCounterVideo );
+
+ LOG_TRACE((TRACE_VIDEO_HBL | TRACE_MFP_WRITE),
+ "mfp/video aer bit 3 0->1, timer B triggers on start of line,"
+ " old_pos=%d new_pos=%d video_cyc=%d %d@%d pc=%x instr_cyc=%d\n",
+ LineTimerBPos_old, LineTimerBPos,
+ FrameCycles, LineCycles, nHBL, M68000_GetPC(), CurrentInstrCycles);
+ }
+
+ /* 1 -> 0, timer B is now counting end of line events (cycle 376+28) */
+ else if ( ( AER_old & ( 1 << 3 ) ) != 0 )
+ {
+ LineTimerBPos = Video_TimerB_GetPos ( HblCounterVideo );
+
+ LOG_TRACE((TRACE_VIDEO_HBL | TRACE_MFP_WRITE),
+ "mfp/video aer bit 3 1->0, timer B triggers on end of line,"
+ " old_pos=%d new_pos=%d video_cyc=%d %d@%d pc=%x instr_cyc=%d\n",
+ LineTimerBPos_old, LineTimerBPos,
+ FrameCycles, LineCycles, nHBL, M68000_GetPC(), CurrentInstrCycles);
+ }
+
+ /* Timer B position changed, update the next interrupt */
+ if ( LineTimerBPos_old != LineTimerBPos )
+ Video_AddInterruptTimerB ( HblCounterVideo , LineCycles , LineTimerBPos );
+ }
}
}
/*-----------------------------------------------------------------------*/
/**
- * Handle write to data direction register (0xfffa05).
+ * Handle write to Data Direction Register DDR (0xfffa05 or 0xfffa85)
*/
-void MFP_DataDirection_WriteByte(void)
+void MFP_DataDirection_WriteByte ( void )
{
- Uint8 DDR_old;
+ MFP_STRUCT *pMFP;
+ Uint8 DDR_old;
M68000_WaitState(4);
- DDR_old = MFP_DDR;
- MFP_DDR = IoMem[0xfffa05];
+ if ( IoAccessCurrentAddress == 0xfffa05 )
+ pMFP = pMFP_Main;
+ else
+ pMFP = pMFP_TT;
- /* Update possible interrupts after changing AER */
- MFP_GPIP_Update_Interrupt ( MFP_GPIP , MFP_GPIP , MFP_AER , MFP_AER , DDR_old , MFP_DDR );
+ if ( LOG_TRACE_LEVEL( TRACE_MFP_WRITE ) )
+ {
+ int FrameCycles, HblCounterVideo, LineCycles;
+ Video_GetPosition ( &FrameCycles , &HblCounterVideo , &LineCycles );
+ LOG_TRACE_PRINT("mfp%s write ddr %x=0x%x video_cyc=%d %d@%d pc=%x instr_cycle %d\n" ,
+ pMFP->NameSuffix , IoAccessCurrentAddress, IoMem[IoAccessCurrentAddress],
+ FrameCycles, LineCycles, HblCounterVideo, M68000_GetPC(), CurrentInstrCycles );
+ }
+
+ DDR_old = pMFP->DDR;
+ pMFP->DDR = IoMem[IoAccessCurrentAddress];
+
+ /* Update possible interrupts after changing DDR */
+ MFP_GPIP_Update_Interrupt ( pMFP , pMFP->GPIP , pMFP->GPIP , pMFP->AER , pMFP->AER , DDR_old , pMFP->DDR );
}
/*-----------------------------------------------------------------------*/
/**
- * Handle write to interrupt enable register A (0xfffa07).
+ * Handle write to Interrupt Enable Register A IERA (0xfffa07 or 0xfffa87)
*/
-void MFP_EnableA_WriteByte(void)
+void MFP_EnableA_WriteByte ( void )
{
+ MFP_STRUCT *pMFP;
+
M68000_WaitState(4);
- MFP_IERA = IoMem[0xfffa07];
- MFP_IPRA &= MFP_IERA;
- MFP_UpdateIRQ ( Cycles_GetClockCounterOnWriteAccess() );
+ if ( IoAccessCurrentAddress == 0xfffa07 )
+ pMFP = pMFP_Main;
+ else
+ pMFP = pMFP_TT;
+
+ if ( LOG_TRACE_LEVEL( TRACE_MFP_WRITE ) )
+ {
+ int FrameCycles, HblCounterVideo, LineCycles;
+ Video_GetPosition ( &FrameCycles , &HblCounterVideo , &LineCycles );
+ LOG_TRACE_PRINT("mfp%s write iera %x=0x%x video_cyc=%d %d@%d pc=%x instr_cycle %d\n" ,
+ pMFP->NameSuffix , IoAccessCurrentAddress, IoMem[IoAccessCurrentAddress],
+ FrameCycles, LineCycles, HblCounterVideo, M68000_GetPC(), CurrentInstrCycles );
+ }
+
+ pMFP->IERA = IoMem[IoAccessCurrentAddress];
+ pMFP->IPRA &= pMFP->IERA;
+ MFP_UpdateIRQ ( pMFP , Cycles_GetClockCounterOnWriteAccess() );
}
/*-----------------------------------------------------------------------*/
/**
- * Handle write to interrupt enable register B (0xfffa09).
+ * Handle write to Interrupt Enable Register B IERB (0xfffa09 or 0xfffa89)
*/
-void MFP_EnableB_WriteByte(void)
+void MFP_EnableB_WriteByte ( void )
{
+ MFP_STRUCT *pMFP;
+
M68000_WaitState(4);
- MFP_IERB = IoMem[0xfffa09];
- MFP_IPRB &= MFP_IERB;
- MFP_UpdateIRQ ( Cycles_GetClockCounterOnWriteAccess() );
+ if ( IoAccessCurrentAddress == 0xfffa09 )
+ pMFP = pMFP_Main;
+ else
+ pMFP = pMFP_TT;
+
+ if ( LOG_TRACE_LEVEL( TRACE_MFP_WRITE ) )
+ {
+ int FrameCycles, HblCounterVideo, LineCycles;
+ Video_GetPosition ( &FrameCycles , &HblCounterVideo , &LineCycles );
+ LOG_TRACE_PRINT("mfp%s write ierb %x=0x%x video_cyc=%d %d@%d pc=%x instr_cycle %d\n" ,
+ pMFP->NameSuffix , IoAccessCurrentAddress, IoMem[IoAccessCurrentAddress],
+ FrameCycles, LineCycles, HblCounterVideo, M68000_GetPC(), CurrentInstrCycles );
+ }
+
+ pMFP->IERB = IoMem[IoAccessCurrentAddress];
+ pMFP->IPRB &= pMFP->IERB;
+ MFP_UpdateIRQ ( pMFP , Cycles_GetClockCounterOnWriteAccess() );
}
/*-----------------------------------------------------------------------*/
/**
- * Handle write to interrupt pending register A (0xfffa0b).
+ * Handle write to Interrupt Pending Register A IPRA (0xfffa0b or 0xfffa8b)
*/
-void MFP_PendingA_WriteByte(void)
+void MFP_PendingA_WriteByte ( void )
{
+ MFP_STRUCT *pMFP;
+
M68000_WaitState(4);
- MFP_IPRA &= IoMem[0xfffa0b]; /* Cannot set pending bits - only clear via software */
- MFP_UpdateIRQ ( Cycles_GetClockCounterOnWriteAccess() );
+ if ( IoAccessCurrentAddress == 0xfffa0b )
+ pMFP = pMFP_Main;
+ else
+ pMFP = pMFP_TT;
+
+ if ( LOG_TRACE_LEVEL( TRACE_MFP_WRITE ) )
+ {
+ int FrameCycles, HblCounterVideo, LineCycles;
+ Video_GetPosition ( &FrameCycles , &HblCounterVideo , &LineCycles );
+ LOG_TRACE_PRINT("mfp%s write ipra %x=0x%x video_cyc=%d %d@%d pc=%x instr_cycle %d\n" ,
+ pMFP->NameSuffix , IoAccessCurrentAddress, IoMem[IoAccessCurrentAddress],
+ FrameCycles, LineCycles, HblCounterVideo, M68000_GetPC(), CurrentInstrCycles );
+ }
+
+ pMFP->IPRA &= IoMem[IoAccessCurrentAddress]; /* Cannot set pending bits - only clear via software */
+ MFP_UpdateIRQ ( pMFP , Cycles_GetClockCounterOnWriteAccess() );
}
/*-----------------------------------------------------------------------*/
/**
- * Handle write to interrupt pending register B (0xfffa0d).
+ * Handle write to Interrupt Pending Register B IPRB (0xfffa0d or 0xfffa8d)
*/
-void MFP_PendingB_WriteByte(void)
+void MFP_PendingB_WriteByte ( void )
{
+ MFP_STRUCT *pMFP;
+
M68000_WaitState(4);
- MFP_IPRB &= IoMem[0xfffa0d]; /* Cannot set pending bits - only clear via software */
- MFP_UpdateIRQ ( Cycles_GetClockCounterOnWriteAccess() );
+ if ( IoAccessCurrentAddress == 0xfffa0d )
+ pMFP = pMFP_Main;
+ else
+ pMFP = pMFP_TT;
+
+ if ( LOG_TRACE_LEVEL( TRACE_MFP_WRITE ) )
+ {
+ int FrameCycles, HblCounterVideo, LineCycles;
+ Video_GetPosition ( &FrameCycles , &HblCounterVideo , &LineCycles );
+ LOG_TRACE_PRINT("mfp%s write iprb %x=0x%x video_cyc=%d %d@%d pc=%x instr_cycle %d\n" ,
+ pMFP->NameSuffix , IoAccessCurrentAddress, IoMem[IoAccessCurrentAddress],
+ FrameCycles, LineCycles, HblCounterVideo, M68000_GetPC(), CurrentInstrCycles );
+ }
+
+ pMFP->IPRB &= IoMem[IoAccessCurrentAddress]; /* Cannot set pending bits - only clear via software */
+ MFP_UpdateIRQ ( pMFP , Cycles_GetClockCounterOnWriteAccess() );
}
/*-----------------------------------------------------------------------*/
/**
- * Handle write to interrupt in service register A (0xfffa0f).
+ * Handle write to Interrupt In Service Register A ISRA (0xfffa0f or 0xfffa8f)
*/
-void MFP_InServiceA_WriteByte(void)
+void MFP_InServiceA_WriteByte ( void )
{
+ MFP_STRUCT *pMFP;
+
M68000_WaitState(4);
- MFP_ISRA &= IoMem[0xfffa0f]; /* Cannot set in-service bits - only clear via software */
- MFP_UpdateIRQ ( Cycles_GetClockCounterOnWriteAccess() );
+ if ( IoAccessCurrentAddress == 0xfffa0f )
+ pMFP = pMFP_Main;
+ else
+ pMFP = pMFP_TT;
+
+ if ( LOG_TRACE_LEVEL( TRACE_MFP_WRITE ) )
+ {
+ int FrameCycles, HblCounterVideo, LineCycles;
+ Video_GetPosition ( &FrameCycles , &HblCounterVideo , &LineCycles );
+ LOG_TRACE_PRINT("mfp%s write isra %x=0x%x video_cyc=%d %d@%d pc=%x instr_cycle %d\n" ,
+ pMFP->NameSuffix , IoAccessCurrentAddress, IoMem[IoAccessCurrentAddress],
+ FrameCycles, LineCycles, HblCounterVideo, M68000_GetPC(), CurrentInstrCycles );
+ }
+
+ pMFP->ISRA &= IoMem[IoAccessCurrentAddress]; /* Cannot set in-service bits - only clear via software */
+ MFP_UpdateIRQ ( pMFP , Cycles_GetClockCounterOnWriteAccess() );
}
/*-----------------------------------------------------------------------*/
/**
- * Handle write to interrupt in service register B (0xfffa11).
+ * Handle write to Interrupt In Service Register B ISRB (0xfffa11 or 0xfffa91).
*/
-void MFP_InServiceB_WriteByte(void)
+void MFP_InServiceB_WriteByte ( void )
{
+ MFP_STRUCT *pMFP;
+
M68000_WaitState(4);
- MFP_ISRB &= IoMem[0xfffa11]; /* Cannot set in-service bits - only clear via software */
- MFP_UpdateIRQ ( Cycles_GetClockCounterOnWriteAccess() );
+ if ( IoAccessCurrentAddress == 0xfffa11 )
+ pMFP = pMFP_Main;
+ else
+ pMFP = pMFP_TT;
+
+ if ( LOG_TRACE_LEVEL( TRACE_MFP_WRITE ) )
+ {
+ int FrameCycles, HblCounterVideo, LineCycles;
+ Video_GetPosition ( &FrameCycles , &HblCounterVideo , &LineCycles );
+ LOG_TRACE_PRINT("mfp%s write isrb %x=0x%x video_cyc=%d %d@%d pc=%x instr_cycle %d\n" ,
+ pMFP->NameSuffix , IoAccessCurrentAddress, IoMem[IoAccessCurrentAddress],
+ FrameCycles, LineCycles, HblCounterVideo, M68000_GetPC(), CurrentInstrCycles );
+ }
+
+ pMFP->ISRB &= IoMem[IoAccessCurrentAddress]; /* Cannot set in-service bits - only clear via software */
+ MFP_UpdateIRQ ( pMFP , Cycles_GetClockCounterOnWriteAccess() );
}
/*-----------------------------------------------------------------------*/
/**
- * Handle write to interrupt mask register A (0xfffa13).
+ * Handle write to Interrupt Mask Register A IMRA (0xfffa13 or 0xfffa93)
*/
-void MFP_MaskA_WriteByte(void)
+void MFP_MaskA_WriteByte ( void )
{
+ MFP_STRUCT *pMFP;
+
M68000_WaitState(4);
- MFP_IMRA = IoMem[0xfffa13];
- MFP_UpdateIRQ ( Cycles_GetClockCounterOnWriteAccess() );
+ if ( IoAccessCurrentAddress == 0xfffa13 )
+ pMFP = pMFP_Main;
+ else
+ pMFP = pMFP_TT;
+
+ if ( LOG_TRACE_LEVEL( TRACE_MFP_WRITE ) )
+ {
+ int FrameCycles, HblCounterVideo, LineCycles;
+ Video_GetPosition ( &FrameCycles , &HblCounterVideo , &LineCycles );
+ LOG_TRACE_PRINT("mfp%s write imra %x=0x%x video_cyc=%d %d@%d pc=%x instr_cycle %d\n" ,
+ pMFP->NameSuffix , IoAccessCurrentAddress, IoMem[IoAccessCurrentAddress],
+ FrameCycles, LineCycles, HblCounterVideo, M68000_GetPC(), CurrentInstrCycles );
+ }
+
+ pMFP->IMRA = IoMem[IoAccessCurrentAddress];
+ MFP_UpdateIRQ ( pMFP , Cycles_GetClockCounterOnWriteAccess() );
}
/*-----------------------------------------------------------------------*/
/**
- * Handle write to interrupt mask register B (0xfffa15).
+ * Handle write to Interrupt Mask Register B IMRB (0xfffa15 or 0xfffa95)
*/
-void MFP_MaskB_WriteByte(void)
+void MFP_MaskB_WriteByte ( void )
{
+ MFP_STRUCT *pMFP;
+
M68000_WaitState(4);
- MFP_IMRB = IoMem[0xfffa15];
- MFP_UpdateIRQ ( Cycles_GetClockCounterOnWriteAccess() );
+ if ( IoAccessCurrentAddress == 0xfffa15 )
+ pMFP = pMFP_Main;
+ else
+ pMFP = pMFP_TT;
+
+ if ( LOG_TRACE_LEVEL( TRACE_MFP_WRITE ) )
+ {
+ int FrameCycles, HblCounterVideo, LineCycles;
+ Video_GetPosition ( &FrameCycles , &HblCounterVideo , &LineCycles );
+ LOG_TRACE_PRINT("mfp%s write imrb %x=0x%x video_cyc=%d %d@%d pc=%x instr_cycle %d\n" ,
+ pMFP->NameSuffix , IoAccessCurrentAddress, IoMem[IoAccessCurrentAddress],
+ FrameCycles, LineCycles, HblCounterVideo, M68000_GetPC(), CurrentInstrCycles );
+ }
+
+ pMFP->IMRB = IoMem[IoAccessCurrentAddress];
+ MFP_UpdateIRQ ( pMFP , Cycles_GetClockCounterOnWriteAccess() );
}
/*-----------------------------------------------------------------------*/
/**
- * Handle write to MFP vector register (0xfffa17).
+ * Handle write to MFP Vector Register (0xfffa17 or 0xfffa97)
*/
-void MFP_VectorReg_WriteByte(void)
+void MFP_VectorReg_WriteByte ( void )
{
- Uint8 old_vr;
+ MFP_STRUCT *pMFP;
+ Uint8 old_vr;
M68000_WaitState(4);
- old_vr = MFP_VR; /* Copy for checking if set mode */
- MFP_VR = IoMem[0xfffa17];
-
- if ((MFP_VR^old_vr) & 0x08) /* Test change in end-of-interrupt mode */
- {
- /* Mode did change but was it to automatic mode? (ie bit is a zero) */
- if (!(MFP_VR & 0x08))
- {
- /* We are now in automatic mode, so clear all in-service bits! */
- MFP_ISRA = 0;
- MFP_ISRB = 0;
- MFP_UpdateIRQ ( Cycles_GetClockCounterOnWriteAccess() );
- }
- }
+ if ( IoAccessCurrentAddress == 0xfffa17 )
+ pMFP = pMFP_Main;
+ else
+ pMFP = pMFP_TT;
if ( LOG_TRACE_LEVEL( TRACE_MFP_WRITE ) )
{
int FrameCycles, HblCounterVideo, LineCycles;
Video_GetPosition ( &FrameCycles , &HblCounterVideo , &LineCycles );
- LOG_TRACE_PRINT("mfp write vector reg fa17=0x%x video_cyc=%d %d@%d pc=%x instr_cycle %d\n" ,
- MFP_VR, FrameCycles, LineCycles, HblCounterVideo, M68000_GetPC(), CurrentInstrCycles );
+ LOG_TRACE_PRINT("mfp%s write vr %x=0x%x video_cyc=%d %d@%d pc=%x instr_cycle %d\n" ,
+ pMFP->NameSuffix , IoAccessCurrentAddress, IoMem[IoAccessCurrentAddress],
+ FrameCycles, LineCycles, HblCounterVideo, M68000_GetPC(), CurrentInstrCycles );
}
+ old_vr = pMFP->VR; /* Copy for checking if set mode */
+ pMFP->VR = IoMem[IoAccessCurrentAddress];
+
+ if ((pMFP->VR^old_vr) & 0x08) /* Test change in end-of-interrupt mode */
+ {
+ /* Mode did change but was it to automatic mode ? (ie bit is a zero) */
+ if (!(pMFP->VR & 0x08))
+ {
+ /* We are now in automatic mode, so clear all in-service bits */
+ pMFP->ISRA = 0;
+ pMFP->ISRB = 0;
+ MFP_UpdateIRQ ( pMFP , Cycles_GetClockCounterOnWriteAccess() );
+ }
+ }
}
/*-----------------------------------------------------------------------*/
/**
- * Handle write to timer A control register (0xfffa19).
+ * Handle write to Timer A Control Register TACR (0xfffa19 or 0xfffa99)
*/
-void MFP_TimerACtrl_WriteByte(void)
+void MFP_TimerACtrl_WriteByte ( void )
{
- Uint8 new_tacr;
+ MFP_STRUCT *pMFP;
+ Uint8 new_tacr;
M68000_WaitState(4);
- new_tacr = IoMem[0xfffa19] & 0x0f; /* FIXME : ignore bit 4 (reset) ? */
+ if ( IoAccessCurrentAddress == 0xfffa19 )
+ pMFP = pMFP_Main;
+ else
+ pMFP = pMFP_TT;
+
+ if ( LOG_TRACE_LEVEL( TRACE_MFP_WRITE ) )
+ {
+ int FrameCycles, HblCounterVideo, LineCycles;
+ Video_GetPosition ( &FrameCycles , &HblCounterVideo , &LineCycles );
+ LOG_TRACE_PRINT("mfp%s write tacr %x=0x%x video_cyc=%d %d@%d pc=%x instr_cycle %d\n" ,
+ pMFP->NameSuffix , IoAccessCurrentAddress, IoMem[IoAccessCurrentAddress],
+ FrameCycles, LineCycles, HblCounterVideo, M68000_GetPC(), CurrentInstrCycles );
+ }
+
+ new_tacr = IoMem[IoAccessCurrentAddress] & 0x0f; /* FIXME : ignore bit 4 (reset) ? */
- if ( MFP_TACR != new_tacr ) /* Timer control changed */
+ if ( pMFP->TACR != new_tacr ) /* Timer control changed */
{
/* If we stop a timer which was in delay mode, we need to store
* the current value of the counter to be able to read it or to
* continue from where we left if the timer is restarted later
* without writing to the data register. */
- if ((new_tacr == 0) && (MFP_TACR >=1) && (MFP_TACR <= 7))
- MFP_ReadTimerA(true); /* Store result in 'MFP_TA_MAINCOUNTER' */
+ if ((new_tacr == 0) && (pMFP->TACR >=1) && (pMFP->TACR <= 7))
+ MFP_ReadTimerA ( pMFP , true); /* Store result in 'TA_MAINCOUNTER' */
- MFP_TACR = new_tacr; /* set to new value before calling MFP_StartTimer */
- MFP_StartTimerA(); /* start/stop timer depending on control reg */
+ pMFP->TACR = new_tacr; /* set to new value before calling MFP_StartTimer */
+ MFP_StartTimerA ( pMFP ); /* start/stop timer depending on control reg */
}
}
/*-----------------------------------------------------------------------*/
/**
- * Handle write to timer B control register (0xfffa1b).
+ * Handle write to Timer B Control Register TBCR (0xfffa1b or 0xfffa9b)
*/
void MFP_TimerBCtrl_WriteByte(void)
{
- Uint8 new_tbcr;
+ MFP_STRUCT *pMFP;
+ Uint8 new_tbcr;
M68000_WaitState(4);
- new_tbcr = IoMem[0xfffa1b] & 0x0f; /* FIXME : ignore bit 4 (reset) ? */
+ if ( IoAccessCurrentAddress == 0xfffa1b )
+ pMFP = pMFP_Main;
+ else
+ pMFP = pMFP_TT;
+
+ if ( LOG_TRACE_LEVEL( TRACE_MFP_WRITE ) )
+ {
+ int FrameCycles, HblCounterVideo, LineCycles;
+ Video_GetPosition ( &FrameCycles , &HblCounterVideo , &LineCycles );
+ LOG_TRACE_PRINT("mfp%s write tbcr %x=0x%x video_cyc=%d %d@%d pc=%x instr_cycle %d\n" ,
+ pMFP->NameSuffix , IoAccessCurrentAddress, IoMem[IoAccessCurrentAddress],
+ FrameCycles, LineCycles, HblCounterVideo, M68000_GetPC(), CurrentInstrCycles );
+ }
+
+ new_tbcr = IoMem[IoAccessCurrentAddress] & 0x0f; /* FIXME : ignore bit 4 (reset) ? */
- if (MFP_TBCR != new_tbcr) /* Timer control changed */
+ if ( pMFP->TBCR != new_tbcr ) /* Timer control changed */
{
/* If we stop a timer which was in delay mode, we need to store
* the current value of the counter to be able to read it or to
* continue from where we left if the timer is restarted later
* without writing to the data register. */
- if ((new_tbcr == 0) && (MFP_TBCR >= 1) && (MFP_TBCR <= 7))
- MFP_ReadTimerB(true); /* Store result in 'MFP_TB_MAINCOUNTER' */
+ if ((new_tbcr == 0) && (pMFP->TBCR >=1) && (pMFP->TBCR <= 7))
+ MFP_ReadTimerB ( pMFP , true); /* Store result in 'TA_MAINCOUNTER' */
- MFP_TBCR = new_tbcr; /* set to new value before calling MFP_StartTimer */
- MFP_StartTimerB(); /* start/stop timer depending on control reg */
+ pMFP->TBCR = new_tbcr; /* set to new value before calling MFP_StartTimer */
+ MFP_StartTimerB ( pMFP ); /* start/stop timer depending on control reg */
}
}
@@ -2032,16 +2800,31 @@ void MFP_TimerBCtrl_WriteByte(void)
/**
* Handle write to timer C/D control register (0xfffa1d).
*/
-void MFP_TimerCDCtrl_WriteByte(void)
+void MFP_TimerCDCtrl_WriteByte(void)
{
- Uint8 new_tcdcr;
- Uint8 old_tcdcr;
+ MFP_STRUCT *pMFP;
+ Uint8 new_tcdcr;
+ Uint8 old_tcdcr;
M68000_WaitState(4);
- new_tcdcr = IoMem[0xfffa1d];
- old_tcdcr = MFP_TCDCR;
-//fprintf ( stderr , "write fa1d new %x old %x\n" , IoMem[0xfffa1d] , MFP_TCDCR );
+ if ( IoAccessCurrentAddress == 0xfffa1d )
+ pMFP = pMFP_Main;
+ else
+ pMFP = pMFP_TT;
+
+ if ( LOG_TRACE_LEVEL( TRACE_MFP_WRITE ) )
+ {
+ int FrameCycles, HblCounterVideo, LineCycles;
+ Video_GetPosition ( &FrameCycles , &HblCounterVideo , &LineCycles );
+ LOG_TRACE_PRINT("mfp%s write tcdcr %x=0x%x video_cyc=%d %d@%d pc=%x instr_cycle %d\n" ,
+ pMFP->NameSuffix , IoAccessCurrentAddress, IoMem[IoAccessCurrentAddress],
+ FrameCycles, LineCycles, HblCounterVideo, M68000_GetPC(), CurrentInstrCycles );
+ }
+
+ new_tcdcr = IoMem[IoAccessCurrentAddress];
+ old_tcdcr = pMFP->TCDCR;
+//fprintf ( stderr , "write fa1d new %x old %x\n" , IoMem[IoAccessCurrentAddress] , pMFP->TCDCR );
if ((old_tcdcr & 0x70) != (new_tcdcr & 0x70)) /* Timer C control changed */
{
@@ -2050,163 +2833,206 @@ void MFP_TimerCDCtrl_WriteByte(void)
* continue from where we left if the timer is restarted later
* without writing to the data register. */
if ((new_tcdcr & 0x70) == 0)
- MFP_ReadTimerC(true); /* Store result in 'MFP_TC_MAINCOUNTER' */
+ MFP_ReadTimerC ( pMFP , true ); /* Store result in 'TC_MAINCOUNTER' */
- MFP_TCDCR = ( new_tcdcr & 0x70 ) | ( old_tcdcr & 0x07 ); /* we set TCCR and keep old TDDR in case we need to read it below */
- MFP_StartTimerC(); /* start/stop timer depending on control reg */
+ pMFP->TCDCR = ( new_tcdcr & 0x70 ) | ( old_tcdcr & 0x07 ); /* we set TCCR and keep old TDCR in case we need to read it below */
+ MFP_StartTimerC ( pMFP ); /* start/stop timer depending on control reg */
}
if ((old_tcdcr & 0x07) != (new_tcdcr & 0x07)) /* Timer D control changed */
{
Uint32 pc = M68000_GetPC();
- /* Need to change baud rate of RS232 emulation? */
- if (ConfigureParams.RS232.bEnableRS232)
+ /* Special case for main MFP and TT MFP when bPatchTimerD is used */
+ if (ConfigureParams.System.bPatchTimerD && !pMFP->PatchTimerD_Done
+ && pc >= TosAddress && pc <= TosAddress + TosSize)
{
- RS232_SetBaudRateFromTimerD();
+ /* Slow down Timer-D if set from TOS for the first time to gain
+ * more desktop performance.
+ * Obviously, we need to emulate all timers correctly but TOS sets
+ * up Timer-D at a very high rate (every couple of instructions).
+ * The interrupt isn't enabled but the emulator still needs to
+ * process the interrupt table and this HALVES our frame rate!!!
+ * Some games actually reference this timer but don't set it up
+ * (eg Paradroid, Speedball I) so we simply intercept the Timer-D
+ * setup code in TOS and fix the numbers with more 'laid-back'
+ * values. This still keeps 100% compatibility */
+ if ( new_tcdcr & 0x07 ) /* apply patch only if timer D is being started */
+ {
+ new_tcdcr = IoMem[IoAccessCurrentAddress] = (IoMem[IoAccessCurrentAddress] & 0xf0) | 7;
+ pMFP->PatchTimerD_Done = 1;
+ }
}
- if (ConfigureParams.System.bPatchTimerD && !bAppliedTimerDPatch
- && pc >= TosAddress && pc <= TosAddress + TosSize)
+ /* Special case for the main MFP when RS232 is enabled */
+ if ( IoAccessCurrentAddress == 0xfffa1d )
{
- /* Slow down Timer-D if set from TOS for the first time to gain
- * more desktop performance.
- * Obviously, we need to emulate all timers correctly but TOS sets
- * up Timer-D at a very high rate (every couple of instructions).
- * The interrupt isn't enabled but the emulator still needs to
- * process the interrupt table and this HALVES our frame rate!!!
- * Some games actually reference this timer but don't set it up
- * (eg Paradroid, Speedball I) so we simply intercept the Timer-D
- * setup code in TOS and fix the numbers with more 'laid-back'
- * values. This still keeps 100% compatibility */
- if ( new_tcdcr & 0x07 ) /* apply patch only if timer D is being started */
+ /* Need to change baud rate of RS232 emulation? */
+ if (ConfigureParams.RS232.bEnableRS232)
{
- new_tcdcr = IoMem[0xfffa1d] = (IoMem[0xfffa1d] & 0xf0) | 7;
- bAppliedTimerDPatch = true;
+ RS232_SetBaudRateFromTimerD();
}
}
- /* If we stop a timer which was in delay mode, we need to store the current value */
- /* of the counter to be able to read it or to continue from where we left if the timer is */
- /* restarted later without writing to the data register. */
+ /* If we stop a timer which was in delay mode, we need to store
+ * the current value of the counter to be able to read it or to
+ * continue from where we left if the timer is restarted later
+ * without writing to the data register. */
if ((new_tcdcr & 0x07) == 0)
- MFP_ReadTimerD(true); /* Stores result in 'MFP_TD_MAINCOUNTER' */
+ MFP_ReadTimerD ( pMFP , true ); /* Store result in 'TD_MAINCOUNTER' */
- MFP_TCDCR = new_tcdcr; /* set to new value before calling MFP_StartTimer */
- MFP_StartTimerD(); /* start/stop timer depending on control reg */
+ pMFP->TCDCR = new_tcdcr; /* set to new value before calling MFP_StartTimer */
+ MFP_StartTimerD ( pMFP ); /* start/stop timer depending on control reg */
}
}
/*-----------------------------------------------------------------------*/
/**
- * Handle write to timer A data register (0xfffa1f).
+ * Handle write to Timer A Data Register TADR (0xfffa1f or 0xfffa9f)
*/
-void MFP_TimerAData_WriteByte(void)
+void MFP_TimerAData_WriteByte ( void )
{
- M68000_WaitState(4);
+ MFP_STRUCT *pMFP;
- MFP_TADR = IoMem[0xfffa1f]; /* Store into data register */
+ M68000_WaitState(4);
- if (MFP_TACR == 0) /* Now check if timer is running - if so do not set */
- {
- MFP_TA_MAINCOUNTER = MFP_TADR; /* Timer is off, store to main counter */
- TimerACanResume = false; /* we need to set a new int when timer start */
- }
+ if ( IoAccessCurrentAddress == 0xfffa1f )
+ pMFP = pMFP_Main;
+ else
+ pMFP = pMFP_TT;
if ( LOG_TRACE_LEVEL( TRACE_MFP_WRITE ) )
{
int FrameCycles, HblCounterVideo, LineCycles;
Video_GetPosition ( &FrameCycles , &HblCounterVideo , &LineCycles );
- LOG_TRACE_PRINT("mfp write data reg A fa1f=0x%x new counter=0x%x video_cyc=%d %d@%d pc=%x instr_cycle %d\n" ,
- MFP_TADR, MFP_TA_MAINCOUNTER, FrameCycles, LineCycles, HblCounterVideo, M68000_GetPC(), CurrentInstrCycles );
+ LOG_TRACE_PRINT("mfp%s write tadr %x=0x%x video_cyc=%d %d@%d pc=%x instr_cycle %d\n" ,
+ pMFP->NameSuffix , IoAccessCurrentAddress, IoMem[IoAccessCurrentAddress],
+ FrameCycles, LineCycles, HblCounterVideo, M68000_GetPC(), CurrentInstrCycles );
+ }
+
+ pMFP->TADR = IoMem[IoAccessCurrentAddress]; /* Store into data register */
+
+ if ( pMFP->TACR == 0 ) /* Now check if timer is running - if so do not set */
+ {
+ pMFP->TA_MAINCOUNTER = pMFP->TADR; /* Timer is off, store to main counter */
+ pMFP->TimerACanResume = false; /* we need to set a new int when timer start */
}
}
/*-----------------------------------------------------------------------*/
/**
- * Handle write to timer B data register (0xfffa21).
+ * Handle write to Timer B Data Register TBDR (0xfffa21 or 0xfffaa1)
*/
-void MFP_TimerBData_WriteByte(void)
+void MFP_TimerBData_WriteByte ( void )
{
- M68000_WaitState(4);
+ MFP_STRUCT *pMFP;
- MFP_TBDR = IoMem[0xfffa21]; /* Store into data register */
+ M68000_WaitState(4);
- if (MFP_TBCR == 0) /* Now check if timer is running - if so do not set */
- {
- MFP_TB_MAINCOUNTER = MFP_TBDR; /* Timer is off, store to main counter */
- TimerBCanResume = false; /* we need to set a new int when timer start */
- }
+ if ( IoAccessCurrentAddress == 0xfffa21 )
+ pMFP = pMFP_Main;
+ else
+ pMFP = pMFP_TT;
if ( LOG_TRACE_LEVEL( TRACE_MFP_WRITE ) )
{
int FrameCycles, HblCounterVideo, LineCycles;
Video_GetPosition ( &FrameCycles , &HblCounterVideo , &LineCycles );
- LOG_TRACE_PRINT("mfp write data reg B fa21=0x%x new counter=0x%x video_cyc=%d %d@%d pc=%x instr_cycle %d\n" ,
- MFP_TBDR, MFP_TB_MAINCOUNTER, FrameCycles, LineCycles, HblCounterVideo, M68000_GetPC(), CurrentInstrCycles );
+ LOG_TRACE_PRINT("mfp%s write tbdr %x=0x%x video_cyc=%d %d@%d pc=%x instr_cycle %d\n" ,
+ pMFP->NameSuffix , IoAccessCurrentAddress, IoMem[IoAccessCurrentAddress],
+ FrameCycles, LineCycles, HblCounterVideo, M68000_GetPC(), CurrentInstrCycles );
+ }
+
+ pMFP->TBDR = IoMem[IoAccessCurrentAddress]; /* Store into data register */
+
+ if ( pMFP->TBCR == 0 ) /* Now check if timer is running - if so do not set */
+ {
+ pMFP->TB_MAINCOUNTER = pMFP->TBDR; /* Timer is off, store to main counter */
+ pMFP->TimerBCanResume = false; /* we need to set a new int when timer start */
}
}
/*-----------------------------------------------------------------------*/
/**
- * Handle write to timer C data register (0xfffa23).
+ * Handle write to Timer C Data Register TCDR (0xfffa23 or 0xfffaa3)
*/
-void MFP_TimerCData_WriteByte(void)
+void MFP_TimerCData_WriteByte ( void )
{
- M68000_WaitState(4);
+ MFP_STRUCT *pMFP;
- MFP_TCDR = IoMem[0xfffa23]; /* Store into data register */
+ M68000_WaitState(4);
- if ((MFP_TCDCR&0x70) == 0) /* Now check if timer is running - if so do not set */
- {
- MFP_TC_MAINCOUNTER = MFP_TCDR; /* Timer is off, store to main counter */
- TimerCCanResume = false; /* we need to set a new int when timer start */
- }
+ if ( IoAccessCurrentAddress == 0xfffa23 )
+ pMFP = pMFP_Main;
+ else
+ pMFP = pMFP_TT;
if ( LOG_TRACE_LEVEL( TRACE_MFP_WRITE ) )
{
int FrameCycles, HblCounterVideo, LineCycles;
Video_GetPosition ( &FrameCycles , &HblCounterVideo , &LineCycles );
- LOG_TRACE_PRINT("mfp write data reg C fa23=0x%x new counter=0x%x video_cyc=%d %d@%d pc=%x instr_cycle %d\n" ,
- MFP_TCDR, MFP_TC_MAINCOUNTER, FrameCycles, LineCycles, HblCounterVideo, M68000_GetPC(), CurrentInstrCycles );
+ LOG_TRACE_PRINT("mfp%s write tcdr %x=0x%x video_cyc=%d %d@%d pc=%x instr_cycle %d\n" ,
+ pMFP->NameSuffix , IoAccessCurrentAddress, IoMem[IoAccessCurrentAddress],
+ FrameCycles, LineCycles, HblCounterVideo, M68000_GetPC(), CurrentInstrCycles );
+ }
+
+ pMFP->TCDR = IoMem[IoAccessCurrentAddress]; /* Store into data register */
+
+ if ( (pMFP->TCDCR & 0x70) == 0 ) /* Now check if timer is running - if so do not set */
+ {
+ pMFP->TC_MAINCOUNTER = pMFP->TCDR; /* Timer is off, store to main counter */
+ pMFP->TimerCCanResume = false; /* we need to set a new int when timer start */
}
}
/*-----------------------------------------------------------------------*/
/**
- * Handle write to timer D data register (0xfffa25).
+ * Handle write to Timer D Data Register TDDR (0xfffa25 or 0xfffaa5)
*/
-void MFP_TimerDData_WriteByte(void)
+void MFP_TimerDData_WriteByte ( void )
{
- Uint32 pc = M68000_GetPC();
+ MFP_STRUCT *pMFP;
+ Uint32 pc = M68000_GetPC();
M68000_WaitState(4);
- /* Need to change baud rate of RS232 emulation? */
- if (ConfigureParams.RS232.bEnableRS232 && (IoMem[0xfffa1d] & 0x07))
+ if ( IoAccessCurrentAddress == 0xfffa25 )
+ pMFP = pMFP_Main;
+ else
+ pMFP = pMFP_TT;
+
+ if ( LOG_TRACE_LEVEL( TRACE_MFP_WRITE ) )
{
- RS232_SetBaudRateFromTimerD();
+ int FrameCycles, HblCounterVideo, LineCycles;
+ Video_GetPosition ( &FrameCycles , &HblCounterVideo , &LineCycles );
+ LOG_TRACE_PRINT("mfp%s write tddr %x=0x%x video_cyc=%d %d@%d pc=%x instr_cycle %d\n" ,
+ pMFP->NameSuffix , IoAccessCurrentAddress, IoMem[IoAccessCurrentAddress],
+ FrameCycles, LineCycles, HblCounterVideo, M68000_GetPC(), CurrentInstrCycles );
}
- /* Patch Timer-D for better performance? */
- if (ConfigureParams.System.bPatchTimerD && pc >= TosAddress && pc <= TosAddress + TosSize)
+ /* Patch Timer D for better performance ? */
+ /* NOTE : in TT mode TOS also starts useless timer D on the TT MFP, so we should patch */
+ /* Main MFP and TT MFP when bPatchTimerD is enabled */
+ if ( ConfigureParams.System.bPatchTimerD && pc >= TosAddress && pc <= TosAddress + TosSize )
{
- nTimerDFakeValue = IoMem[0xfffa25];
- IoMem[0xfffa25] = 0x64; /* Slow down the useless Timer-D setup from the bios */
+ pMFP->PatchTimerD_TDDR_old = IoMem[IoAccessCurrentAddress];
+ IoMem[IoAccessCurrentAddress] = PATCH_TIMERD_TDDR_FAKE; /* Slow down the useless Timer D setup from the bios */
}
- MFP_TDDR = IoMem[0xfffa25]; /* Store into data register */
- if ((MFP_TCDCR&0x07) == 0) /* Now check if timer is running - if so do not set */
+ if ( IoAccessCurrentAddress == 0xfffa25 )
{
- MFP_TD_MAINCOUNTER = MFP_TDDR; /* Timer is off, store to main counter */
- TimerDCanResume = false; /* we need to set a new int when timer start */
+ /* Need to change baud rate of RS232 emulation ? */
+ if ( ConfigureParams.RS232.bEnableRS232 && ( IoMem[0xfffa1d] & 0x07 ) )
+ {
+ RS232_SetBaudRateFromTimerD();
+ }
}
- if ( LOG_TRACE_LEVEL( TRACE_MFP_WRITE ) )
+ pMFP->TDDR = IoMem[IoAccessCurrentAddress]; /* Store into data register */
+
+ if ( (pMFP->TCDCR & 0x07) == 0 ) /* Now check if timer is running - if so do not set */
{
- int FrameCycles, HblCounterVideo, LineCycles;
- Video_GetPosition ( &FrameCycles , &HblCounterVideo , &LineCycles );
- LOG_TRACE_PRINT("mfp write data reg D fa25=0x%x new counter=0x%x video_cyc=%d %d@%d pc=%x instr_cycle %d\n" ,
- MFP_TDDR, MFP_TD_MAINCOUNTER, FrameCycles, LineCycles, HblCounterVideo, M68000_GetPC(), CurrentInstrCycles );
+ pMFP->TD_MAINCOUNTER = pMFP->TDDR; /* Timer is off, store to main counter */
+ pMFP->TimerDCanResume = false; /* we need to set a new int when timer start */
}
}
diff --git a/src/midi.c b/src/midi.c
index e1a36984..69dcf9ee 100644
--- a/src/midi.c
+++ b/src/midi.c
@@ -166,13 +166,13 @@ static void MIDI_UpdateIRQ ( void )
if ( irq_bit_new )
{
/* Request interrupt by setting GPIP to low/0 */
- MFP_GPIP_Set_Line_Input ( MFP_GPIP_LINE_ACIA , MFP_GPIP_STATE_LOW );
+ MFP_GPIP_Set_Line_Input ( pMFP_Main , MFP_GPIP_LINE_ACIA , MFP_GPIP_STATE_LOW );
MidiStatusRegister |= ACIA_SR_INTERRUPT_REQUEST;
}
else
{
/* Clear interrupt request by setting GPIP to high/1 */
- MFP_GPIP_Set_Line_Input ( MFP_GPIP_LINE_ACIA , MFP_GPIP_STATE_HIGH );
+ MFP_GPIP_Set_Line_Input ( pMFP_Main , MFP_GPIP_LINE_ACIA , MFP_GPIP_STATE_HIGH );
MidiStatusRegister &= ~ACIA_SR_INTERRUPT_REQUEST;
}
}
diff --git a/src/ncr5380.c b/src/ncr5380.c
index 4fc15e1f..6d5b83e0 100644
--- a/src/ncr5380.c
+++ b/src/ncr5380.c
@@ -1149,15 +1149,9 @@ void Ncr5380_TT_DMA_Ctrl_WriteWord(void)
/**
- * This is a temporary hack until we've got proper emulation of the
- * 2nd MFP in the TT
+ * Return true if IRQ is set ; used in MFP_GPIP_ReadByte_TT
*/
-void Ncr5380_TT_GPIP_ReadByte(void)
+bool Ncr5380_TT_GetIRQ(void)
{
- Uint8 val = 0x7f;
-
- if (ncr_soft_scsi.irq)
- val |= 0x80;
-
- IoMem[0xfffa81] = val;
+ return ncr_soft_scsi.irq;
}
diff --git a/src/psg.c b/src/psg.c
index 5c39603c..e89bca23 100644
--- a/src/psg.c
+++ b/src/psg.c
@@ -340,10 +340,10 @@ void PSG_Set_DataRegister(Uint8 val)
/* Seems like we want to print something... */
Printer_TransferByteTo(PSGRegisters[PSG_REG_IO_PORTB]);
/* Initiate a possible GPIP0 Printer BUSY interrupt */
- MFP_InputOnChannel ( MFP_INT_GPIP0 , 0 );
+ MFP_InputOnChannel ( pMFP_Main , MFP_INT_GPIP0 , 0 );
/* Initiate a possible GPIP1 Falcon ACK interrupt */
if (Config_IsMachineFalcon())
- MFP_InputOnChannel ( MFP_INT_GPIP1 , 0 );
+ MFP_InputOnChannel ( pMFP_Main , MFP_INT_GPIP1 , 0 );
}
}
LastStrobe = PSGRegisters[PSG_REG_IO_PORTA]&(1<<5);
diff --git a/src/reset.c b/src/reset.c
index fcd86dc7..a0b3417f 100644
--- a/src/reset.c
+++ b/src/reset.c
@@ -67,7 +67,7 @@ static int Reset_ST(bool bCold)
STMemory_Reset (bCold);
CycInt_Reset(); /* Reset interrupts */
- MFP_Reset(); /* Setup MFP chip */
+ MFP_Reset_All(); /* Setup MFPs */
Video_Reset(); /* Reset video */
VDI_Reset(); /* Reset internal VDI variables */
NvRam_Reset(); /* reset NvRAM (video) settings */
diff --git a/src/rs232.c b/src/rs232.c
index 8eb72681..cdee9efe 100644
--- a/src/rs232.c
+++ b/src/rs232.c
@@ -323,7 +323,7 @@ static int RS232_ThreadFunc(void *pData)
cInChar = iInChar;
RS232_AddBytesToInputBuffer(&cInChar, 1);
/* FIXME: Use semaphores to lock MFP variables? */
- MFP_InputOnChannel ( MFP_INT_RCV_BUF_FULL , 0 );
+ MFP_InputOnChannel ( pMFP_Main , MFP_INT_RCV_BUF_FULL , 0 );
Dprintf(("RS232: Read character $%x\n", iInChar));
/* Sleep for a while */
SDL_Delay(2);
@@ -631,7 +631,7 @@ static bool RS232_TransferBytesTo(Uint8 *pBytes, int nBytes)
if (fwrite(pBytes, 1, nBytes, hComOut))
{
Dprintf(("RS232: Sent %i bytes ($%x ...)\n", nBytes, *pBytes));
- MFP_InputOnChannel ( MFP_INT_TRN_BUF_EMPTY , 0 );
+ MFP_InputOnChannel ( pMFP_Main , MFP_INT_TRN_BUF_EMPTY , 0 );
return true; /* OK */
}
@@ -806,7 +806,7 @@ void RS232_UDR_ReadByte(void)
if (RS232_GetStatus()) /* More data waiting? */
{
/* Yes, generate another interrupt. */
- MFP_InputOnChannel ( MFP_INT_RCV_BUF_FULL , 0 );
+ MFP_InputOnChannel ( pMFP_Main , MFP_INT_RCV_BUF_FULL , 0 );
}
}
diff --git a/src/uae-cpu/hatari-glue.c b/src/uae-cpu/hatari-glue.c
index 956d3981..93428eb9 100644
--- a/src/uae-cpu/hatari-glue.c
+++ b/src/uae-cpu/hatari-glue.c
@@ -60,7 +60,7 @@ void customreset(void)
PSG_Reset ();
/* Reset the MFP */
- MFP_Reset ();
+ MFP_Reset_All ();
/* Reset the FDC */
FDC_Reset ( false );
diff --git a/src/uae-cpu/newcpu.c b/src/uae-cpu/newcpu.c
index c2a5164c..252d9be7 100644
--- a/src/uae-cpu/newcpu.c
+++ b/src/uae-cpu/newcpu.c
@@ -906,7 +906,7 @@ void Exception(int nr, uaecptr oldpc, int ExceptionSource)
while ( ( PendingInterruptCount <= 0 ) && ( PendingInterruptFunction ) )
CALL_VAR(PendingInterruptFunction);
if ( MFP_UpdateNeeded == true )
- MFP_UpdateIRQ ( 0 ); /* update MFP's state if some internal timers related to MFP expired */
+ MFP_UpdateIRQ_All ( 0 ); /* update MFP's state if some internal timers related to MFP expired */
pendingInterrupts &= ~( 1 << ( nr - 24 ) ); /* clear HBL or VBL pending bit */
CPU_IACK = false;
}
@@ -1639,7 +1639,7 @@ static bool do_specialties_interrupt (int Pending)
/* Check for MFP ints (level 6) */
if (regs.spcflags & SPCFLAG_MFP) {
- if (MFP_ProcessIRQ() == true)
+ if (MFP_ProcessIRQ_All() == true)
return true; /* MFP exception was generated, no higher interrupt can happen */
}
@@ -1705,9 +1705,9 @@ static int do_specialties (void)
while ( ( PendingInterruptCount <= 0 ) && ( PendingInterruptFunction ) )
CALL_VAR(PendingInterruptFunction);
if ( MFP_UpdateNeeded == true )
- MFP_UpdateIRQ ( 0 );
+ MFP_UpdateIRQ_All ( 0 );
- /* Check is there's an interrupt to process (could be a delayed MFP interrupt) */
+ /* Check if there's an interrupt to process (could be a delayed MFP interrupt) */
if ( do_specialties_interrupt(false) ) { /* test if there's an interrupt and add non pending jitter */
regs.stopped = 0;
unset_special (SPCFLAG_STOP);
@@ -1840,7 +1840,7 @@ static void m68k_run_1 (void)
while ( ( PendingInterruptCount <= 0 ) && ( PendingInterruptFunction ) && ( ( regs.spcflags & SPCFLAG_STOP ) == 0 ) )
CALL_VAR ( PendingInterruptFunction ); /* call the interrupt's handler */
if ( MFP_UpdateNeeded == true )
- MFP_UpdateIRQ ( 0 ); /* update MFP's state if some internal timers related to MFP expired */
+ MFP_UpdateIRQ_All ( 0 ); /* update MFP's state if some internal timers related to MFP expired */
}
if (regs.spcflags) {
@@ -1906,7 +1906,7 @@ static void m68k_run_2 (void)
while ( ( PendingInterruptCount <= 0 ) && ( PendingInterruptFunction ) )
CALL_VAR(PendingInterruptFunction);
if ( MFP_UpdateNeeded == true )
- MFP_UpdateIRQ ( 0 );
+ MFP_UpdateIRQ_All ( 0 );
}
if (regs.spcflags) {
diff --git a/src/video.c b/src/video.c
index 3bf08940..a860540f 100644
--- a/src/video.c
+++ b/src/video.c
@@ -3223,7 +3223,7 @@ void Video_InterruptHandler_EndLine(void)
/* before end of line, the interrupt should not be generated) */
if ( ( TimerBEventCountCycleStart == -1 ) /* timer B was started during a previous VBL */
|| ( TimerBEventCountCycleStart < FrameCycles-PendingCycles ) ) /* timer B was started before this possible interrupt */
- MFP_TimerB_EventCount ( PendingCycles ); /* Update events count / interrupt for timer B if needed */
+ MFP_TimerB_EventCount ( pMFP_Main , PendingCycles ); /* Update events count / interrupt for timer B if needed */
}
}