dz80/dissz80.c
/* Create the output .asm file and header */
Create the output .asm file and header
Create the output . asm file and header
int CreateOutputASMFile(DISZ80 *d)
{
	char	MsgBuf[_MAX_PATH + 80];
	char	buf[256];
	time_t	secs_now;
	struct	tm *time_now;
	time(&secs_now);
	time_now = localtime(&secs_now);
	if (d->outFileName[0])
		{
		d->outStream = fopen(d->outFileName, "wt");
		if (d->outStream == NULL)
			{
			sprintf(buf, "Couldn't create the output file %s\n", d->outFileName);
			dZ80_Error(d, buf);
			DisZ80CleanUp(d);
			return DERR_COULDNTCREATEFILE;
			}
		sprintf(MsgBuf, "%sDisassembly of the file \"%s\"\n%s\n", d->layoutComment, d->srcFileName, d->layoutComment);
		fwrite(MsgBuf, strlen(MsgBuf), 1, d->outStream);
		sprintf(MsgBuf, "%sCPU Type: %s\n%s\n", d->layoutComment, dZ80CpuTypeNames[d->cpuType], d->layoutComment);
		fwrite(MsgBuf, strlen(MsgBuf), 1, d->outStream);
		if (d->opMapFileName[0])
			{
			sprintf(MsgBuf, "%sUsing the opcode map file \"%s\"\n%s", d->layoutComment, d->opMapFileName, d->layoutComment);
			fwrite(MsgBuf, strlen(MsgBuf), 1, d->outStream);
			}
		sprintf(MsgBuf, "%sCreated with dZ80 %s\n%s", d->layoutComment, VersionString, d->layoutComment);
		fwrite(MsgBuf, strlen(MsgBuf), 1, d->outStream);
		if (d->scriptFileName[0])
			{
			sprintf(MsgBuf, "   using script \"%s\"\n%s", d->scriptFileName, d->layoutComment);
			fwrite(MsgBuf, strlen(MsgBuf), 1, d->outStream);
			}
		sprintf(MsgBuf, "\n%s", d->layoutComment);
		fwrite(MsgBuf, strlen(MsgBuf), 1, d->outStream);
		strftime(MsgBuf, sizeof(MsgBuf), "on %A, %d of %B %Y at %I:%M %p", time_now);
		fwrite(MsgBuf, strlen(MsgBuf), 1, d->outStream);
		sprintf(MsgBuf, "\n%s\n", d->layoutComment);
		fwrite(MsgBuf, strlen(MsgBuf), 1, d->outStream);
		if (d->labelledOutput)
			{
			PrepareDisInstruction(d);
			AddToDisTab(d, "org");
			Make16BitNum(d, MsgBuf, d->disStart);
			strcat(MsgBuf,"\n");
			AddToDis(d, MsgBuf);
			WriteDisLine(d, d->lastPC);
			}
		}
	return DERR_NONE;
}
int CreateOutputASMFile ( DISZ80 * d ) { char MsgBuf [ _MAX_PATH + 80 ] ; char buf [ 256 ] ; time_t secs_now ; struct tm * time_now ; time ( & secs_now ) ; time_now = localtime ( & secs_now ) ; if ( d -> outFileName [ 0 ] ) { d -> outStream = fopen ( d -> outFileName , " " ) ; if ( d -> outStream == NULL ) { sprintf ( buf , " \n " , d -> outFileName ) ; dZ80_Error ( d , buf ) ; DisZ80CleanUp ( d ) ; return DERR_COULDNTCREATEFILE ; } sprintf ( MsgBuf , " \" \" \n \n " , d -> layoutComment , d -> srcFileName , d -> layoutComment ) ; fwrite ( MsgBuf , strlen ( MsgBuf ) , 1 , d -> outStream ) ; sprintf ( MsgBuf , " \n \n " , d -> layoutComment , dZ80CpuTypeNames [ d -> cpuType ] , d -> layoutComment ) ; fwrite ( MsgBuf , strlen ( MsgBuf ) , 1 , d -> outStream ) ; if ( d -> opMapFileName [ 0 ] ) { sprintf ( MsgBuf , " \" \" \n " , d -> layoutComment , d -> opMapFileName , d -> layoutComment ) ; fwrite ( MsgBuf , strlen ( MsgBuf ) , 1 , d -> outStream ) ; } sprintf ( MsgBuf , " \n " , d -> layoutComment , VersionString , d -> layoutComment ) ; fwrite ( MsgBuf , strlen ( MsgBuf ) , 1 , d -> outStream ) ; if ( d -> scriptFileName [ 0 ] ) { sprintf ( MsgBuf , " \" \" \n " , d -> scriptFileName , d -> layoutComment ) ; fwrite ( MsgBuf , strlen ( MsgBuf ) , 1 , d -> outStream ) ; } sprintf ( MsgBuf , " \n " , d -> layoutComment ) ; fwrite ( MsgBuf , strlen ( MsgBuf ) , 1 , d -> outStream ) ; strftime ( MsgBuf , sizeof ( MsgBuf ) , " " , time_now ) ; fwrite ( MsgBuf , strlen ( MsgBuf ) , 1 , d -> outStream ) ; sprintf ( MsgBuf , " \n \n " , d -> layoutComment ) ; fwrite ( MsgBuf , strlen ( MsgBuf ) , 1 , d -> outStream ) ; if ( d -> labelledOutput ) { PrepareDisInstruction ( d ) ; AddToDisTab ( d , " " ) ; Make16BitNum ( d , MsgBuf , d -> disStart ) ; strcat ( MsgBuf , " \n " ) ; AddToDis ( d , MsgBuf ) ; WriteDisLine ( d , d -> lastPC ) ; } } return DERR_NONE ; }
Create the output .asm file and header
Create the output . asm file and header
/* Set up the time structures */