Re: [hatari-devel] Falcon video counter

[ Thread Index | Date Index | More lists.tuxfamily.org/hatari-devel Archives ]


Hi,

On 11/16/2016 11:16 PM, Laurent Sallafranque wrote:
> I've done a quick test:
>
> Bound 3 works
> Bound 4 is freezed on the dolphin image
> Bound5 is only displaying the tiger image

Before my patch it stopped to white screen even before
showing "Bound 5" text.  Patch fixes just Videl address
counter freezes, not DSP sync ones. :-)


> Ishar 1 and 2 don't work better
> Ishar 3 is working

There's a problem with the patch, Video_EndHBL() shouldn't
be called with it, because video.c Video_RestartVideoCounter()
(which sets pVideoRaster() copied in Video_EndHBL()) isn't
called and starting Falcon with mono monitor would crash
to NULL pointer access when video.c:Video_EndHBL() tries to
copy raster line, like it's currently (uselessly) doing
with Hatari 2.0.

Attached is a new version.


	- Eero


Laurent



Le 16/11/2016 à 21:56, Laurent Sallafranque a écrit :
Hi,

I'll test the patch tonight ( I had in mind to test Ishar 1,2,3) ;)

I agree it may fix all of this, but that's not the good way to do it.
I have another version of the videl code that I'll try to reimplement
into this version of hatari (I did it with hatari v1.6).

Anyway, if this patch also solves the Ishar games, I think it should
be applied, also if I rework it later.
Maybe it was too early when I first tried to implement Videl.

Regards
Laurent

PS: I spent a lot of time with Mr Splash at the Sillyventure (the guy
who has coded falcamp and flaysid).
We've spent some time looking what's wrong with falcamp, I continue to
search with his help.
I wish I find the problem.




Le 16/11/2016 à 21:26, Eero Tamminen a écrit :
Hi,

On 11/16/2016 12:33 AM, Laurent Sallafranque wrote:
Thanks for this patch (remind me the command to include it in the
current version please).

At Hatari repo root:
    patch -p1 < videl-video-counter.patch


I'll have more time now that Sillyventure is over.
I'd like to retry to finish the Videl code I did 3 years ago.
> (it let Pinball dream work much better than the current version,
but need a better accurate CPU)

I'll test this patch.

Besides fixing DLDH2, it fixes also Moonspeeder preview 2
game, Bound3 & Bound5 demos (at least they start now), and
Hextracker gets past video address counter code [1].

I added info about these to compatibility doc.

If somebody has Ishar 1, 2 or 3, it would be good if
they could test whether it works with the patch.


    - Eero

[1] Hextracker doesn't seem to be otherwise Falcon compatible,
I guess that testing was from time when Paulo was trying
to use Hatari in making Hextracker Falcon compatible...

Le 15/11/2016 à 23:21, Eero Tamminen a écrit :
Hi,

Since Laurent moved all Videl register handling to falcon/videl.c
(sometime after Hatari v1.6), several programs have been broken
because that removed support for Falcon video address counter.

Attached is patch adding minimal support for that.  It fixes
"Lasers and Hommes" (DLDH2), that doesn't anymore freeze at
startup.  I assume the patch to fix most, if not all of those
regressions, but I haven't had yet time to test them.


Any comments on the patch?  Additional things that should be
taken into account / fixed (or at least add TODOs for)?


    - Eero

PS. Note that the patch needs to modify few items saved into
memory snapshots, so it breaks memory snapshot compatibility.














diff -r 1891d5125a83 src/falcon/videl.c
--- a/src/falcon/videl.c	Wed Nov 16 22:20:06 2016 +0200
+++ b/src/falcon/videl.c	Wed Nov 16 23:23:06 2016 +0200
@@ -85,7 +85,9 @@
 	bool   bUseSTShifter;			/* whether to use ST or Falcon palette */
 	Uint8  reg_ffff8006_save;		/* save reg_ffff8006 as it's a read only register */
 	Uint8  monitor_type;			/* 00 Monochrome (SM124) / 01 Color (SC1224) / 10 VGA Color / 11 Television ($FFFF8006) */
-	Uint32 videoBaseAddr;			/* Video base address, refreshed after each VBL */
+
+	Uint32 videoRaster;			/* Video raster offset, restarted on each VBL */
+	Uint16 vertFreqCounter;			/* Counter for VFC register $ff82a0, restarted on each VBL */
 
 	Sint16 leftBorderSize;			/* Size of the left border */
 	Sint16 rightBorderSize;			/* Size of the right border */
@@ -103,7 +105,6 @@
 
 static struct videl_s videl;
 
-Uint16 vfc_counter;			/* counter for VFC register $ff82a0 (to be internalized when VIDEL emulation is complete) */
 
 /**
  * Called upon startup (and via VIDEL_reset())
@@ -131,7 +132,7 @@
 	videl.reg_ffff8006_save = IoMem_ReadByte(0xff8006);
 	videl.monitor_type = videl.reg_ffff8006_save & 0xc0;
 
-	vfc_counter = 0;
+	VIDEL_RestartVideoCounter();
 
 	/* Reset IO register (some are not initialized by TOS) */
 	IoMem_WriteWord(0xff820e, 0);    /* Line offset */
@@ -148,7 +149,6 @@
 {
 	/* Save/Restore details */
 	MemorySnapShot_Store(&videl, sizeof(videl));
-	MemorySnapShot_Store(&vfc_counter, sizeof(vfc_counter));
 }
 
 /**
@@ -200,10 +200,7 @@
  */
 void VIDEL_ScreenCounter_ReadByte(void)
 {
-//	Uint32 addr;	// To be used
-	Uint32 addr = 0; // To be removed
-
-	// addr = Videl_CalculateAddress();		/* TODO: get current video address */
+	Uint32 addr = videl.videoRaster;
 	IoMem[0xff8205] = ( addr >> 16 ) & 0xff;
 	IoMem[0xff8207] = ( addr >> 8 ) & 0xff;
 	IoMem[0xff8209] = addr & 0xff;
@@ -216,10 +213,8 @@
  */
 void VIDEL_ScreenCounter_WriteByte(void)
 {
-	Uint32 addr_new = 0;
-	Uint8 AddrByte;
-
-	AddrByte = IoMem[ IoAccessCurrentAddress ];
+	Uint32 addr_new = videl.videoRaster;
+	Uint8 AddrByte = IoMem[ IoAccessCurrentAddress ];
 
 	/* Compute the new video address with one modified byte */
 	if ( IoAccessCurrentAddress == 0xff8205 )
@@ -229,7 +224,8 @@
 	else if ( IoAccessCurrentAddress == 0xff8209 )
 		addr_new = ( addr_new & 0xffff00 ) | ( AddrByte );
 
-	// TODO: save the value in a table for the final rendering
+	videl.videoRaster = addr_new;
+	LOG_TRACE(TRACE_VIDEL, "Videl : $ff8205/07/09 Sync Mode write: 0x%08x\n", addr_new);
 }
 
 /**
@@ -479,8 +475,8 @@
  */
 void VIDEL_VFC_ReadWord(void)
 {
-	IoMem_WriteWord(0xff82a0, vfc_counter);
-	LOG_TRACE(TRACE_VIDEL, "Videl : $ff82a0 Vertical Frequency Counter (VFC) read: 0x%04x\n", vfc_counter);
+	IoMem_WriteWord(0xff82a0, videl.vertFreqCounter);
+	LOG_TRACE(TRACE_VIDEL, "Videl : $ff82a0 Vertical Frequency Counter (VFC) read: 0x%04x\n", videl.vertFreqCounter);
 }
 
 /**
@@ -571,6 +567,31 @@
 	return videoBase;
 }
 
+/**
+ * Reset appropriate registers on VBL etc
+ */
+void VIDEL_RestartVideoCounter(void)
+{
+	videl.videoRaster = VIDEL_getVideoramAddress();
+	/* counter for VFC register $ff82a0 */
+	videl.vertFreqCounter = 0;
+}
+
+/**
+ * Increment appropriate registers on HBL
+ */
+void VIDEL_VideoRasterHBL(void)
+{
+	int lineoffset = IoMem_ReadWord(0xff820e) & 0x01ff; /* 9 bits */
+	int linewidth = IoMem_ReadWord(0xff8210) & 0x03ff;  /* 10 bits */
+
+	videl.videoRaster += linewidth + lineoffset;
+
+	/* TODO: VFC is incremented every half line, here, we increment it every line */
+	videl.vertFreqCounter++;
+}
+
+
 static Uint16 VIDEL_getScreenBpp(void)
 {
 	Uint16 f_shift = IoMem_ReadWord(0xff8266);
@@ -863,7 +884,7 @@
 
 	bool change = false;
 
-	videl.videoBaseAddr = VIDEL_getVideoramAddress(); // Todo: to be removed when all code is in Videl
+	Uint32 videoBase = VIDEL_getVideoramAddress();
 
 	if (vw > 0 && vw != videl.save_scrWidth) {
 		LOG_TRACE(TRACE_VIDEL, "Videl : width change from %d to %d\n", videl.save_scrWidth, vw);
@@ -913,7 +934,7 @@
 
 	VIDEL_UpdateColors();
 
-	Screen_GenConvert(&STRam[videl.videoBaseAddr], videl.XSize, videl.YSize,
+	Screen_GenConvert(&STRam[videoBase], videl.XSize, videl.YSize,
 	                  videl.save_scrBpp, nextline, hscrolloffset,
 	                  videl.leftBorderSize, videl.rightBorderSize,
 	                  videl.upperBorderSize, videl.lowerBorderSize);
diff -r 1891d5125a83 src/falcon/videl.h
--- a/src/falcon/videl.h	Wed Nov 16 22:20:06 2016 +0200
+++ b/src/falcon/videl.h	Wed Nov 16 23:23:06 2016 +0200
@@ -8,9 +8,6 @@
 #ifndef HATARI_VIDEL_H
 #define HATARI_VIDEL_H
 
-/* To be removed when Videl emulation is complete */
-extern Uint16 vfc_counter;			/* counter for VFC register $ff82a0 */
-
 extern bool VIDEL_renderScreen(void);
 
 extern void Videl_Init(void);
@@ -19,6 +16,9 @@
 extern void VIDEL_ZoomModeChanged(bool bForceChange);
 extern void VIDEL_UpdateColors(void);
 
+extern void VIDEL_RestartVideoCounter(void);
+extern void VIDEL_VideoRasterHBL(void);
+
 /* Called from ioMemTabFalcon.c */
 extern void VIDEL_Monitor_WriteByte(void);
 extern void VIDEL_SyncMode_WriteByte(void);
diff -r 1891d5125a83 src/video.c
--- a/src/video.c	Wed Nov 16 22:20:06 2016 +0200
+++ b/src/video.c	Wed Nov 16 23:23:06 2016 +0200
@@ -2773,11 +2773,9 @@
 	}
 
 
-	/* Videl Vertical counter increment (To be removed when Videl emulation is finished) */
-	/* VFC is incremented every half line, here, we increment it every line (should be completed) */
 	if (Config_IsMachineFalcon())
 	{
-		vfc_counter += 1;
+		VIDEL_VideoRasterHBL();
 	}
 
 	
@@ -2807,7 +2805,10 @@
 	M68000_Exception(EXCEPTION_NR_HBLANK , M68000_EXC_SRC_AUTOVEC);	/* Horizontal blank interrupt, level 2 */
 
 
-	Video_EndHBL();					/* Check some borders removal and copy line to display buffer */
+	if (!Config_IsMachineFalcon())
+	{
+		Video_EndHBL();				/* Check some borders removal and copy line to display buffer */
+	}
 
 	DmaSnd_STE_HBL_Update();			/* Update STE DMA sound if needed */
 
@@ -3179,6 +3180,8 @@
 static void Video_CopyScreenLineMono(void)
 {
 	/* Copy one line - 80 bytes in ST high resolution */
+	assert(pSTScreen);
+	assert(pVideoRaster);
 	memcpy(pSTScreen, pVideoRaster, SCREENBYTES_MONOLINE);
 	pVideoRaster += SCREENBYTES_MONOLINE;
 
@@ -3908,10 +3911,13 @@
 
 	Video_ResetShifterTimings();
 
-	Video_RestartVideoCounter();
+        if (Config_IsMachineFalcon())
+		VIDEL_RestartVideoCounter();
+	else
+		Video_RestartVideoCounter();
 
 	pSTScreen = pFrameBuffer->pSTScreen;
-
+		 
 	Video_SetScreenRasters();
 	Video_InitShifterLines();
 	Spec512_StartVBL();
@@ -4283,12 +4289,6 @@
 	nVBLs++;
 	/* Set video registers for frame */
 	Video_ClearOnVBL();
-
-	/* Videl Vertical counter reset (To be removed when Videl emulation is finished) */
-	if (Config_IsMachineFalcon())
-	{
-		vfc_counter = 0;
-	}
 	
 	/* Since we don't execute HBL functions in VDI mode, we've got to
 	 * initialize the first HBL palette here when VDI mode is enabled. */


Mail converted by MHonArc 2.6.19+ http://listengine.tuxfamily.org/