home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
The World of Computer Software
/
World_Of_Computer_Software-02-385-Vol-1of3.iso
/
x
/
xtrsutl.zip
/
DUMPBIN.C
< prev
next >
Wrap
C/C++ Source or Header
|
1992-12-31
|
4KB
|
183 lines
/*
8/4/92
This program will dump a TRS-80 Disk BASIC program that has been
converted to a SYSTEM loadable format by cvtcmd.exe
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;
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);
strcat (filename,".BIN");
fptr = open(filename, O_RDONLY+O_BINARY); /* open for read binary */
if ( fptr == -1 )
{
printf("\nError! Opening %s \n",filename);
usage();
}
read(fptr,buffer,255);
read(fptr,buffer,1);
if (buffer[0] != 0x0a5)
printf("No sync byte, found=0x%02x\n",buffer[0]);
else
printf("Found sync byte....\n");
read(fptr,buffer,1);
if (buffer[0] != 0x55)
printf("No filename header byte, found=0x%02x\n",buffer[0]);
else
printf("Found filename header byte....\n");
read(fptr,buffer,6);
printf("name=%s\n",buffer);
loop:
read(fptr,buffer,1); /* get block type */
blk_type=buffer[0];
printf("Block type=0x%02X ----- ",blk_type);
if (blk_type == 0x3c) /* block type = data? */
{
get_blk(); /* get a block of data */
goto loop;
}
else if (blk_type != 0x78) /* 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;
}
read(fptr,buffer,1); /* read pass the block size */
read(fptr,buffer,1); /* get entry point address */
lsb = buffer[0];
read(fptr,buffer,1);
msb = buffer[0];
addr = msb*256+lsb;
printf("Entry point=0x%04X\n",addr);
close(fptr);
}
/****************************************************************************/
get_blk()
{
int bytes_rd, i;
unsigned char chksum, block_sz;
read(fptr,buffer,1); /* get block size */
blk_size=buffer[0];
printf("Block size=0x%02X\n",blk_size);
read(fptr,buffer,1); /* get destination address */
lsb = buffer[0];
chksum = lsb;
read(fptr,buffer,1);
msb = buffer[0];
chksum += msb;
addr = msb*256+lsb;
printf("Dest addr =0x%04X ----- ",addr);
blk_size--;
// if (blk_size == 0)
// blk_size = 255;
bytes_rd = read(fptr,buffer,blk_size+1); /* read in blk_size of data */
printf("Bytes read=0x%02X\n",bytes_rd);
for (i=0; i<bytes_rd; i++) /* calculate the checksum */
chksum += buffer[i];
printf("Cal CkSum =0x%02X ----- ",chksum);
read(fptr,buffer,1); /* get the checksum */
chksum=buffer[0];
printf("Check Sum =0x%02X\n\n",chksum);
}
/****************************************************************************/
mkupper(string)
char *string;
{
int i;
i = strlen(string);
while(i--)
{
*string = toupper(*string);
string++;
}
}
/****************************************************************************/
usage()
{
printf("\nTRS-80 Disk object program displayer\n");
printf("\nUsage: dumpbin <filename>\n");
printf("\nWhere <fileaname> is a TRS-80 Disk object program without\n");
printf(" an extension. The extension BIN is assumed.\n");
printf("\nThis program will display a TRS-80 disk object (machine\n");
printf("language) program that has been convert to a SYSTEM loadable\n");
printf("format by cvtcmd.exe onto the screen.\n");
printf("\nby Abel M. Hernandez 8/4/92 amh@hp835.mitek.com.\n");
exit(1);
}