[hatari-devel] Wotanoid problem : final fix before commit

LAURENT SALLAFRANQUE laurent.sallafranque at arkea.com
Mon Jan 25 10:42:36 CET 2010


Hello,

After that Georges reported that the files open under falcon with $ffffffff, I've written the patch diferently.

I've separated the Falcon and St management.
(This patch is just for the example, it can be cleaned before being commited).

Do you think this way is better ?

PS : I still don't know if D2 is changed in Fopen TRAP.
I'll try to have a look at this tonight at home.

Regards,

Laurent



/*-----------------------------------------------------------------------*/
/**
 * GEMDOS Read file
 * Call 0x3F
 */
static bool GemDOS_Read(Uint32 Params)
{
	char *pBuffer;
	long CurrentPos, FileSize, nBytesRead, nBytesLeft;
	Uint32 Addr;
+	Uint32 falc_Size;
	Sint32 Size;
	int Handle;

	/* Read details from stack */
	Handle = STMemory_ReadWord(Params);
	Size = STMemory_ReadLong(Params+SIZE_WORD);
	Addr = STMemory_ReadLong(Params+SIZE_WORD+SIZE_LONG);
	pBuffer = (char *)STRAM_ADDR(Addr);

	LOG_TRACE(TRACE_OS_GEMDOS, "GEMDOS Fread(%i, %i, 0x%x)\n", 
	          Handle, Size, Addr);

	Handle -= BASE_FILEHANDLE;

	/* Check handle was valid */
	if (GemDOS_IsInvalidFileHandle(Handle))
	{
		/* assume it was TOS one -> redirect */
		return false;
	}

	/* To quick check to see where our file pointer is and how large the file is */
	CurrentPos = ftell(FileHandles[Handle].FileHandle);
	fseek(FileHandles[Handle].FileHandle, 0, SEEK_END);
	FileSize = ftell(FileHandles[Handle].FileHandle);
	fseek(FileHandles[Handle].FileHandle, CurrentPos, SEEK_SET);

	nBytesLeft = FileSize-CurrentPos;
	
	/* Size parameter is a signed value except for Falcon (unsigned value). */
+	if (ConfigureParams.System.nMachineType == MACHINE_FALCON){
+		falc_Size = (Uint32)Size;
+		/* Check for End Of File */
...		if (falc_Size == 0 || nBytesLeft <= 0){
			/* return zero (bytes read) as original GEMDOS/EmuTOS */
			Regs[REG_D0] = 0;
			return true;
		}

		/* Limit to size of file to prevent errors */
		if (falc_Size > nBytesLeft) {
			falc_Size = nBytesLeft;
			/* TODO: fill reg D0 with "EOF reached" value ? */
		}
		
		/* Check that read is to valid memory area */
		if (!STMemory_ValidArea(Addr, falc_Size)){
			Log_Printf(LOG_TODO, "GEMDOS Fread() failed due to invalid RAM range 0x%x+%i\n", Addr, falc_Size);
			Regs[REG_D0] = GEMDOS_ERANGE;
			return true;
		}
		/* And read data in */
		nBytesRead = fread(pBuffer, 1, falc_Size, FileHandles[Handle].FileHandle);
	
		/* Return number of bytes read */
		Regs[REG_D0] = nBytesRead;
	
		return true;
	}
	else {
		/* Check for bad size and End Of File */
		if (Size <= 0 || nBytesLeft <= 0)
		{
			/* return zero (bytes read) as original GEMDOS/EmuTOS */
			Regs[REG_D0] = 0;
			return true;
		}

		/* Limit to size of file to prevent errors */
		if (Size > nBytesLeft) {
			Size = nBytesLeft;
			/* TODO: fill reg D0 with "EOF reached" value ? */
		}

		/* Check that read is to valid memory area */
		if (!STMemory_ValidArea(Addr, Size))
		{
			Log_Printf(LOG_TODO, "GEMDOS Fread() failed due to invalid RAM range 0x%x+%i\n", Addr, Size);
			Regs[REG_D0] = GEMDOS_ERANGE;
			return true;
		}
		/* And read data in */
		nBytesRead = fread(pBuffer, 1, Size, FileHandles[Handle].FileHandle);
	
		/* Return number of bytes read */
		Regs[REG_D0] = nBytesRead;
	
		return true;
	}
}

--
Ce message et  toutes les pieces jointes (ci-apres  le "message") sont
confidentiels et etablis a l'intention exclusive de ses destinataires.
Toute  utilisation ou  diffusion  non autorisee  est interdite.   Tout
message  etant  susceptible  d'alteration,  l'emetteur  decline  toute
responsabilite au titre de  ce message  s'il a  ete altere, deforme ou
falsifie.
                -----------------------------------
This message and any  attachments (the "message") are confidential and
intended  solely   for  the   addressees.  Any  unauthorised   use  or
dissemination is prohibited. As e-mails are susceptible to alteration,
the issuer shall  not be  liable for  the  message if altered, changed
or falsified.



More information about the hatari-devel mailing list