/* * NAME * tools.c -17-May-97 18:44:43 * * AUTHOR * Jon Rocatis * * DESCRIPTION * Contains some helper functions. Nothing serious. * */ #include #include #include #include #include #include #include #include #include "upload_protos.h" #include "serial_protos.h" #include "tools_protos.h" #include "myecoff.h" #include "upload.h" /* * NAME * DisplayBuffer * * FUNCTION * Displays some bytes from the serial ring buffer * */ void DisplayBuffer() { LONG y,x; for ( y = 0; y < 8; y++ ) { printf("%08x: ", y*16); for ( x = 0; x < 16; x++ ) { printf("%02x ", buffer[y*16+x]); } for ( x = 0; x < 16; x++ ) { if (isprint(buffer[y*16+x])) printf("%c", buffer[y*16+x]); else printf("."); } printf("\n"); } } /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// void DisplaySectionInfo( struct Section *s ) { printf( "Name: %s\n", s->name ); printf( "LoadAddr: $%08x\n", s->loadAddr ); printf( "Size: $%08x (%d)\n", s->size, s->size ); printf( "FilePos: $%08x\n", s->fpos ); printf( "\n" ); } /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// /* * NAME * GetFileSize * * FUNCTION * Gets the size of a file in bytes * * INPUT * fname - filename * * RESULT * size or -1 if failure * */ LONG GetFileSize( char *fname ) { struct FileInfoBlock *fib; BPTR fh; LONG size = -1; if (fib = (struct FileInfoBlock *)AllocDosObject(DOS_FIB, NULL)) { if (fh = Open( fname, MODE_OLDFILE) ) { ExamineFH(fh,fib); Close(fh); size = fib->fib_Size; } FreeDosObject(DOS_FIB, fib); } return(size); } /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// int GetBaudRate() { FILE *fp; char buffer[80]; int baudrate; static int legal[] = {2400,4800,9600,19200,38400,57600,76800,96000,115200,-1}; LONG idx; if ( fp = fopen( "PROGDIR:baudrate.txt", "r" ) ) { fgets( buffer, sizeof(buffer), fp ); baudrate = atoi( buffer ); fclose(fp); idx = 0; while (legal[idx] != -1) { if ( legal[idx++] == baudrate ) return( baudrate ); } } return(-1); } ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////