Ejemplo n.º 1
0
int Adc::Execute(Processor* proc) {

	Operand* dst = mOperands[Operand::DST];
	Operand* src = mOperands[Operand::SRC];

	if(!dst || !src) {
		return INVALID_ARGS;
	}

	unsigned int dstVal = dst->GetValue();
	unsigned int srcVal = src->GetValue();
	unsigned int sign = dst->GetBitmask() == 0xFF ? 0x80 : 0x8000;
	unsigned int newVal = dstVal + srcVal + (proc->GetFlag(FLAGS_CF) ? 1 : 0);
	proc->SetFlag(FLAGS_CF, newVal > dst->GetBitmask());
	newVal &= dst->GetBitmask();

	proc->SetFlag(FLAGS_OF, OverflowAdd(dstVal, srcVal, sign == 0x80 ? 1 : 2));
	proc->SetFlag(FLAGS_SF, newVal >= sign);
	proc->SetFlag(FLAGS_ZF, newVal == 0x00);
	proc->SetFlag(FLAGS_AF, AdjustAdd(dstVal, srcVal));
	proc->SetFlag(FLAGS_PF, Parity(newVal));

	dst->SetValue(newVal);

	return 0;
}
Ejemplo n.º 2
0
/* This routine should be called after a transfer finishes, even if no
 * progress reports were done.  Besides cleaning up the progress stuff,
 * we also do our logging here.
 */
void EndProgress(XferSpecPtr xp)
{
	double elapsedTime, xRate, xferred;
	char *unitStr;
	char *shortName;
	string statMsg;
	longstring fullRemote;
	long kb, hsecs;
	int wantStats;
	int localFileIsStdout;

	wantStats = 0;
	if ((xp->doReports) && (xp->bytesTransferred > 0) && (gVerbosity != kQuiet)) {
		ProgressReport(xp, kPrLastUpdateMsg);
		wantStats = (InForeGround()) &&
			((*xp->prProc)(xp, kPrEndMsg) == kPrWantStatsMsg);
	}
	(void) Gettimeofday(&xp->endTime);

	/* Compute transfer stats. */
	xRate = TransferRate(
		xp->bytesTransferred,
		&xp->startTime,
		&xp->endTime,
		&unitStr,
		&elapsedTime
	);

	/* Print the stats, if requested. */
	if (wantStats) {
		shortName = strrchr(xp->localFileName, '/');
		if (shortName == NULL)
			shortName = xp->localFileName;
		else
			shortName++;
		sprintf(statMsg, "%s:  %ld bytes %s%s in %.2f seconds",
			shortName,
			xp->bytesTransferred,
			NETREADING(xp) ? "received" : "sent",
			xp->startPoint ? " and appended to existing file" : "",
			elapsedTime
		);
		if (xRate > 0.0) {
			sprintf(statMsg + strlen(statMsg), ", %.2f %s",
				xRate,
				unitStr
			);
		}
		STRNCAT(statMsg, ".");
	
		/* Make sure echoing is back on! */
		Echo(stdin, 1);

		/* Make sure the rest of the line is padded with spaces, so it will
		 * erase junk that may have been leftover from a progress meter.
		 */
		EPrintF("%-79s\n", statMsg);
		FlushListWindow();
	} else {
		if (xRate > 0.0) {
			DebugMsg("%ld bytes transferred in %.2f seconds, %.2f %s.\n",
				xp->bytesTransferred,
				elapsedTime,
				xRate,
				unitStr
			);
		} else {
			DebugMsg("%ld bytes transferred in %.2f seconds.\n",
				xp->bytesTransferred,
				elapsedTime
			);
		}
	}

	/* Only log stuff if there was a remote filename specified.
	 * We don't want to log directory listings or globbings.
	 */
	if ((xp->remoteFileName != NULL)) {
		/* Get kilobytes transferred, rounding to the nearest kB. */
		kb = ((long) xp->bytesTransferred + 512L) / 1024L;
		OverflowAdd(&gTotalXferKiloBytes, kb);
		OverflowAdd(&gRmtInfo.xferKbytes, kb);

		/* Get hundredths of seconds, rounded up to nearest. */
		hsecs = (long) (100.0 * (elapsedTime + 0.0050));
		OverflowAdd(&gTotalXferHSeconds, hsecs);
		OverflowAdd(&gRmtInfo.xferHSeconds, hsecs);
		if (gTotalXferHSeconds < 0)
			gTotalXferHSeconds = 1L;
		if (gRmtInfo.xferHSeconds <= 0)
			gRmtInfo.xferHSeconds = 1L;

		localFileIsStdout =
			(STREQ(xp->remoteFileName, kLocalFileIsStdout));
	    /* If a simple path is given, try to log the full path. */
		if ((xp->remoteFileName[0] == '/') || (localFileIsStdout)) {
			/* Use what we had in the xp. */
			STRNCPY(fullRemote, xp->remoteFileName);
		} else {
			/* Make full path by appending what we had in the xp
			 * to the current remote directory.
			 */
			STRNCPY(fullRemote, gRemoteCWD);
			STRNCAT(fullRemote, "/");
			STRNCAT(fullRemote, xp->remoteFileName);
		}
	
		/* Save transfers to the user's logfile.  We only log something to
		 * the user log if we are actually saving a file;  we don't log
		 * to the user log if we are piping the remote output into something,
		 * or dumping it to stdout.
		 */
		if ((gLogFile != NULL) && (!localFileIsStdout)) {
			xferred = FileSize((double) xp->bytesTransferred, &unitStr, NULL);
			(void) fprintf(gLogFile, "  %-3s  %6.2f %-2s  ftp://%s%s\n",
				NETREADING(xp) ? "get" : "put",
				xferred,
				unitStr,
				gRmtInfo.name,
				fullRemote
			);
			fflush(gLogFile);
		}

#ifdef SYSLOG
    	{
        longstring infoPart1;

        /* Some syslog()'s can't take an unlimited number of arguments,
         * so shorten our call to syslog to 5 arguments total.
         */
        STRNCPY(infoPart1, gUserInfo.userName);
        if (NETREADING(xp)) {
            STRNCAT(infoPart1, " received ");
            STRNCAT(infoPart1, fullRemote);	/* kLocalFileIsStdout is ok. */
            STRNCAT(infoPart1, " as ");
            STRNCAT(infoPart1, xp->localFileName);
            STRNCAT(infoPart1, " from ");
        } else {
            STRNCAT(infoPart1, " sent ");
            STRNCAT(infoPart1, xp->localFileName);
            STRNCAT(infoPart1, " as ");
            STRNCAT(infoPart1, fullRemote);
            STRNCAT(infoPart1, " to ");
        }
        STRNCAT(infoPart1, gActualHostName);
#ifndef LOG_INFO
#	define LOG_INFO 6		/* Don't know if this is standard! */
#endif
        syslog (LOG_INFO, "%s (%ld bytes).", infoPart1, xp->bytesTransferred);
    	}
#endif  /* SYSLOG */
	}
}									   /* EndProgress */