home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
The World of Computer Software
/
World_Of_Computer_Software-02-385-Vol-1of3.iso
/
x
/
xtrsutl.zip
/
CVTCMD.C
next >
Wrap
C/C++ Source or Header
|
1992-12-31
|
5KB
|
194 lines
/*
8/4/92
This program will convert a TRS-80 Disk BASIC program to a SYSTEM loadable
format to be used with xtrs1.0
By Abel M. Hernandez amh@hp835.mitek.com
*/
#include <stdio.h>
#include <stdlib.h>
#include <dos.h>
#include <io.h>
#include <fcntl.h>
#include <sys\types.h>
#include <sys\stat.h>
int fptr, optr;
unsigned char buffer[256];
char filename[20]; /* source file */
char mod_file[20]; /* destination file */
char cas_fname[10]; /* storage for cassette filename */
unsigned char blk_size, lsb, msb, blk_type;
int addr;
main(argc, argv)
int argc;
char *argv[];
{
int i;
if (argc < 2)
usage();
else
strcpy (filename,argv[1]);
mkupper(filename);
strcpy (cas_fname," "); /* setup cassette filename */
strncpy (cas_fname,filename,6);
strcpy (mod_file,filename); /* setup destination filename */
strcat (mod_file,".BIN");
strcat (filename,".CMD"); /* assume CMD extension */
fptr = open(filename, O_RDONLY+O_BINARY); /* open for read binary */
if ( fptr == -1 )
{
printf("\nError! Opening %s \n",filename);
usage();
}
optr = creat(mod_file, S_IWRITE); /* open for write */
if ( optr == -1 )
{
printf("\nError! Opening %s\n",mod_file);
exit(1);
}
setmode (optr,O_BINARY); /* set mode for binary */
for (i=0; i<256; i++)
buffer[i] = (unsigned int)0;
write(optr,buffer,255); /* 256 bytes of 0 for leader*/
write(optr,"\245",1); /* sync byte 0xa5 */
write(optr,"\125",1); /* 0x55 filename header */
write(optr,cas_fname,6); /* 6 char filename */
printf("\nConverting");
loop:
read(fptr,buffer,1); /* get block type */
blk_type=buffer[0];
if (blk_type == 0x01) /* block type = data? */
{
get_blk(); /* get a block of data */
goto loop;
}
else if (blk_type != 0x02) /* block type = entry point? */
{
printf("\nText Block: ");
read(fptr,buffer,1); /* get block size */
blk_size = buffer[0];
for (i=0; i<blk_size; i++)
{
read(fptr,buffer,1);
printf("%c",buffer[0]);
}
printf("\n");
goto loop;
}
blk_type = 0x78;
write(optr,&blk_type,1); /* write block type */
read(fptr,buffer,1); /* read pass the block size */
read(fptr,buffer,1); /* get entry point address */
lsb = buffer[0];
write(optr,&lsb,1); /* write lsb of destination address */
read(fptr,buffer,1);
msb = buffer[0];
write(optr,&msb,1); /* write msb of destination address */
addr = msb*256+lsb;
printf("\nEntry point=0x%04X\n",addr);
close(fptr);
close(optr);
}
/****************************************************************************/
get_blk()
{
int bytes_rd, i;
unsigned char chksum, block_sz;
printf(".");
blk_type = 0x3c;
write(optr,&blk_type,1); /* write block type */
read(fptr,buffer,1); /* get block size */
blk_size=buffer[0];
block_sz = blk_size -2;
write(optr,&block_sz,1); /* write block size */
blk_size -= 3;
read(fptr,buffer,1); /* get destination address */
lsb = buffer[0];
chksum = lsb;
write(optr,&lsb,1); /* write lsb of destination address */
read(fptr,buffer,1);
msb = buffer[0];
chksum += msb;
write(optr,&msb,1); /* write msb of destination address */
addr = msb*256+lsb;
bytes_rd = read(fptr,buffer,blk_size+1); /* read in blk_size of data */
bytes_rd = write(optr,buffer,bytes_rd); /* write data block */
for (i=0; i<bytes_rd; i++) /* calculate the checksum */
chksum += buffer[i];
write(optr,&chksum,1); /* write checksum */
}
/****************************************************************************/
mkupper(string)
char *string;
{
int i;
i = strlen(string);
while(i--)
{
*string = toupper(*string);
string++;
}
}
/****************************************************************************/
usage()
{
printf("\nTRS-80 Disk to Cassette program convertor\n");
printf("\nUsage: cvtcmd <filename>\n");
printf("\nWhere <fileaname> is a TRS-80 Disk object program without\n");
printf(" an extension. The extension CMD is assumed.\n");
printf("\nThis program will convert a TRS-80 disk object (machine\n");
printf("language) program to a cassette SYSTEM loadable format.\n");
printf("\nby Abel M. Hernandez 8/4/92 amh@hp835.mitek.com.\n");
exit(1);
}