Re: [hatari-devel] Some patch suggestions

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


On Montag, 23. April 2018 19:29:49 CEST Thomas Huth wrote:
> patches committed now

Thanks. And here another small patch i was talking about in the other thread, 
which redirects Fwrite(1) and Fwrite(2) in tos-less mode. That should allow 
using normal printf() in test programs.
# HG changeset patch
# User Thorsten Otto <admin@xxxxxxxxxxx>
# Date 1524472417 -7200
#      Mon Apr 23 10:33:37 2018 +0200
# Node ID 190455576334286527caee77ffc3837ca476b883
# Parent  a061d1d94495dab22fbd6285628abf892c8c7cf7
Allow writing to GEMDOS handles 1&2 when no tos is loaded,
and redirect them to stdout/stderr

diff -r a061d1d94495 -r 190455576334 src/gemdos.c
--- a/src/gemdos.c	Sun Apr 22 11:53:58 2018 +0200
+++ b/src/gemdos.c	Mon Apr 23 10:33:37 2018 +0200
@@ -2159,7 +2159,7 @@
 	long nBytesWritten;
 	Uint32 Addr;
 	Sint32 Size;
-	int Handle;
+	int Handle, RealHandle;
 	FILE *fp;
 
 	/* Read details from stack */
@@ -2172,11 +2172,25 @@
 		  CallingPC);
 
 	/* Get internal handle */
-	if ((Handle = GemDOS_GetValidFileHandle(Handle)) < 0)
+	if ((RealHandle = GemDOS_GetValidFileHandle(Handle)) < 0)
 	{
+		if (!bUseTos)
+		{
+			if (Handle == 1)
+			{
+				fp = stdout;
+				goto do_write;
+			}
+			if (Handle == 2 || Handle == -1)
+			{
+				fp = stderr;
+				goto do_write;
+			}
+		}
 		/* assume it was TOS one -> redirect */
 		return false;
 	}
+	fp = FileHandles[RealHandle].FileHandle;
 
 	/* write protected device? */
 	if (ConfigureParams.HardDisk.nWriteProtection == WRITEPROT_ON)
@@ -2186,6 +2200,7 @@
 		return true;
 	}
 
+do_write:
 	/* Check that write is from valid memory area */
 	if ( !STMemory_CheckAreaType ( Addr, Size, ABFLAG_RAM ) )
 	{
@@ -2195,12 +2210,11 @@
 	}
 
 	pBuffer = (char *)STMemory_STAddrToPointer(Addr);
-	fp = FileHandles[Handle].FileHandle;
 	nBytesWritten = fwrite(pBuffer, 1, Size, fp);
 	if (ferror(fp))
 	{
 		Log_Printf(LOG_WARN, "GEMDOS failed to write to '%s'\n",
-			   FileHandles[Handle].szActualName );
+			   FileHandles[RealHandle].szActualName );
 		Regs[REG_D0] = errno2gemdos(errno, ERROR_FILE);
 	}
 	else


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