The problem i have with sonic 2 is due to the timings i use :
H-INT : 0
HBlankStart = H-INT + 130 MClks
HBlankEnd = H-INT + 130 MClks + 860 Mclks
So the delay between H-INT and HBlankEnd is 990 MClks
The 68K needs 44 Clks (308 Mclks) to fetch registers before executing first instruction of the interrupt.
So the 68k can execute 682 MClks before the end of HBlank.
The problem is :
Before testing HBlank Flag in status register, there are others instructions at start at interrupt processus.
With my timings, the 68k can execute this instructions and test the hblank flag during this 682 MClks (before end of hblank) so the display is switch Off during this Hblank juste after the H-Int (line 107).
That's not normal because line 107 don't have to be displayed off !!!
I think that in real hardware, when the 68k do the first test of hblank flag, the first hblank period must be ended, so the display will be switched off next line.
So my first conclusion is that this delay of 682 MClks is too much.
The delay of 860 MClks during hblank is confirmed so i think that the delay of 130 MClks between H-INT and HBlankStart is Wrong !!!
If I make HBlankStart = H-INT + 70 MClks (10 Clks 68K) -> The display is OK
IF I make delay between H-INt and HBlankStart longer than 70 MClks, the delay between H-Int and HBlankEnd is too long -> the HBlank flag can be tested -> The display is off -> The display is wrong
Here is interrupt routine (occurs line 107) with each instructions.
You can see the number of cycles the instruction start after H-Int :
Code: Select all
ROM:00000F54 HInt: ; DATA XREF: ROM:00000070o Start Length
ROM:00000F54 tst.w ($FFFFF644).w 309 84
ROM:00000F58 beq.w locret_FFE 393 84
ROM:00000F5C tst.w ($FFFFFFD8).w 477 84
ROM:00000F60 beq.w loc_1000 561 84
ROM:00000F64 move.w #0,($FFFFF644).w 645 112
ROM:00000F6A move.l a5,-(sp) 757 84
ROM:00000F6C move.l d0,-(sp) 841 84
ROM:00000F6E
ROM:00000F6E loc_F6E: ; CODE XREF: HInt+24j
ROM:00000F6E move.w (VDP_Control).l,d0 925
ROM:00000F74 andi.w #4,d0
ROM:00000F78 beq.s loc_F6E
ROM:00000F7A move.w ($FFFFF60C).w,d0
ROM:00000F7E andi.b #$BF,d0
ROM:00000F82 move.w d0,(VDP_Control).l
ROM:00000F88 move.w #$8228,(VDP_Control).l
ROM:00000F90 move.l #$40000010,(VDP_Control).l
ROM:00000F9A move.l ($FFFFEEEC).w,(VDP_Data).l
ROM:00000FA2 move.w #$100,(Z80BusReq).l ; D8 ( W) 0: BUSREQ CANCEL
ROM:00000FA2 ; 1: BUSREQ REQUEST
ROM:00000FA2 ; ( R) 0: CPU FUNCTION STOP ACCESSIBLE
ROM:00000FA2 ; 1: FUNCTIONING
ROM:00000FAA
As you can see, the hblank flag is tested at HInt + 925 Master cycles, so if HBlank End does not occured yet, the display is switched off immediately and the line 107 is not drawn !!!
So the delay between H-Int and the end of HBlank must be smaller than 925 Master cycles in real hardware, so the delay of 130 MClks between H-Int and HBlankStart seems not correct ...