From: hachti Date: Sun, 19 Nov 2006 05:34:50 +0000 (+0000) Subject: *** empty log message *** X-Git-Url: http://gitweb.hachti.de/?a=commitdiff_plain;h=6c06db96fb1c7482f8cb7e1d14eee91603fbb894;p=h316.git *** empty log message *** --- diff --git a/pc-tools/ldc2/src/data_block.cpp b/pc-tools/ldc2/src/data_block.cpp index 15702b5..f0c9153 100644 --- a/pc-tools/ldc2/src/data_block.cpp +++ b/pc-tools/ldc2/src/data_block.cpp @@ -4,6 +4,9 @@ #include "data_block.hh" #include "data_block_0.hh" +#include + +using namespace std; data_block::data_block(tape_block& idol) :tape_block(idol) @@ -25,3 +28,34 @@ int data_block::get_subtype(){ return (new data_block_0(*this))->get_subtype(); else return 0; } + +/*! + *\brief Get the block's size in 16 bit words. + *\return The block's 16-bit data buffer's size including header and checksum. + */ +int data_block::get_word_size(){ + return word_size; +} + +/*! + *\brief Extract 6 byte symbol name from word memory. + * + *\param startbyte the first byte of the desired symbol name + *\return a string containing the symbol name. + * Trailing spaces are included. + *\note The word_data is handled system-intependently big endian! + */ +string data_block::extract_string(int startbyte){ + string result=""; // Start with empty string + + // We don't accept negative arguments! + if (startbyte<0) return result; + + // We also don't want segmentation faults! + if (word_size<(startbyte/2+1)) return result; + + // Here we pick out the characters. + for (int posi=startbyte;posi>(8*(1-posi%2)))&0x7f; + return result; +} diff --git a/pc-tools/ldc2/src/data_block.hh b/pc-tools/ldc2/src/data_block.hh index 8b44754..f6047ff 100644 --- a/pc-tools/ldc2/src/data_block.hh +++ b/pc-tools/ldc2/src/data_block.hh @@ -1,21 +1,26 @@ #ifndef DATA_BLOCK_HH #define DATA_BLOCK_HH +#include #include "tape_block.hh" +using namespace std; + class data_block : public tape_block { - //private: - //data_block(); // Private constructor! - +private: + data_block(); + public: - data_block(tape_block&); + data_block(tape_block&); ~data_block(); - -virtual int get_type(); -virtual int get_subtype(); - + + virtual int get_type(); + virtual int get_subtype(); + int get_word_size(); + //protected: + string extract_string(int startbyte); }; diff --git a/pc-tools/ldc2/src/data_block_0.cpp b/pc-tools/ldc2/src/data_block_0.cpp index 2fe8c5d..dec8e9b 100644 --- a/pc-tools/ldc2/src/data_block_0.cpp +++ b/pc-tools/ldc2/src/data_block_0.cpp @@ -1,3 +1,5 @@ +#include + #include "data_block_0.hh" #include "data_block.hh" @@ -18,3 +20,4 @@ int data_block_0::get_subtype(){ return (word_data[0]&0x0fc0)>>6; } + diff --git a/pc-tools/ldc2/src/data_block_0.hh b/pc-tools/ldc2/src/data_block_0.hh index 7d42c9f..a29f68e 100644 --- a/pc-tools/ldc2/src/data_block_0.hh +++ b/pc-tools/ldc2/src/data_block_0.hh @@ -1,9 +1,12 @@ #ifndef DATA_BLOCK_0_H #define DATA_BLOCK_0_H +#include #include "data_block.hh" - +/*! + *\brief Class for block type (0-*). + */ class data_block_0 : public data_block { @@ -11,6 +14,7 @@ class data_block_0 data_block_0(data_block&); virtual ~data_block_0(); int get_subtype(); +protected: }; #endif diff --git a/pc-tools/ldc2/src/discard_block.cpp b/pc-tools/ldc2/src/discard_block.cpp new file mode 100644 index 0000000..e69de29 diff --git a/pc-tools/ldc2/src/discard_block.hh b/pc-tools/ldc2/src/discard_block.hh new file mode 100644 index 0000000..e69de29 diff --git a/pc-tools/ldc2/src/eot_block.cpp b/pc-tools/ldc2/src/eot_block.cpp new file mode 100644 index 0000000..e69de29 diff --git a/pc-tools/ldc2/src/eot_block.hh b/pc-tools/ldc2/src/eot_block.hh new file mode 100644 index 0000000..700e3a8 --- /dev/null +++ b/pc-tools/ldc2/src/eot_block.hh @@ -0,0 +1,25 @@ + +#ifndef EOT_BLOCK_H +#define EOT_BLOCK_H + +#include +using namespace std; + +class eot_block + : public tape_block +{ +private: + eot_block(); + +public: + eot_block(tape_block&); + ~eot_block(); + + virtual int get_type(); + virtual int get_subtype(); + int get_word_size(); + + +}; + +#endif diff --git a/pc-tools/ldc2/src/tape_block.cpp b/pc-tools/ldc2/src/tape_block.cpp index 8b29bc6..30f9819 100644 --- a/pc-tools/ldc2/src/tape_block.cpp +++ b/pc-tools/ldc2/src/tape_block.cpp @@ -2,6 +2,9 @@ #include #include +#include +#include + #include "tape_block.hh" #include "data_block.hh" #include "data_block_0.hh" @@ -9,7 +12,176 @@ #include "silent_code.hh" #include "hw_constants.hh" +using namespace std; + +/***************************************************************/ +/*! + *\brief Destructor. + */ +tape_block::~tape_block(){ + free(raw_data); + free(word_data); +} + +/***************************************************************/ +/*! + *\brief Copy constructor. + */ +tape_block::tape_block(tape_block & org){ + operator=(org); +} + +/***************************************************************/ +/*! + *\brief Assignment operator. + */ +void tape_block::operator=(tape_block &org){ + block_type=org.block_type; + init_state=org.init_state; + data_read=org.data_read; + raw_data=0; + raw_size=org.raw_size; + word_data=0; + word_size=org.word_size; + if (raw_size){ + raw_data=(unsigned char *)malloc(raw_size); + memcpy(raw_data,org.raw_data,raw_size); + } + if (word_size){ + word_data=(unsigned short *)malloc(word_size*sizeof(unsigned short)); + memcpy(word_data,org.word_data,word_size*sizeof(unsigned short)); + } +} + +/***************************************************************/ +/*! + *\brief Query the block's state. + * + * If the state is not TBS_OK, the block must be discarded. + *\return The block's initialisation state + */ +tape_block::tb_state_t tape_block::get_state(){ + return init_state; +} +/***************************************************************/ +/*! + *\brief Determine the block's type + * + * This routine returns the block's type.\\ + *\retval TBT_DATA if it's a data block + *\retval TBT_EOT if it's an end of tape mark + *\retval TBR_DISCARD if the block is unusable + * + *\note This function is virtual. That means that if the tape block in + * question is of the subtype data_block which overwrites this method, + * it will return the block type contained in the upper 4 bits of the + * first data word! Try to avoid testing for TBT_DATA. \n + * Blocks generated by gen_from_fd should never have TBT_DATA. + */ +int tape_block::get_type(){ + return block_type; +} + +/***************************************************************/ +/*! + *\brief Determine the block's subtype + * + * Some data block types have a subtype. + *\note This is a virtual method and to be used in derived classes. + *\return Always 0 + */ +int tape_block::get_subtype(){ + return 0; +} + +/***************************************************************/ +/*! + *\brief Get a cleartext description of the block. + *\return ldc style descriptive line for the block + */ +vector tape_block:: get_description(){ + char buffer[100]; + sprintf(buffer," (%0o-%02o) Untyped tape block", + get_type(),get_subtype()); + vector result; + result.insert(result.end(),buffer); + return result; +} + +/***************************************************************/ +/*! + *\brief Get size of the internal raw data buffer + *\return The size of the internal raw data buffer + */ +int tape_block::get_raw_size(){ + return raw_size; +} + +/***************************************************************/ +/*! + *\brief Access internal raw data buffer + * + * The raw data buffer contains all block data except the \ \ + * block start delimiter and block end delimiter. + *\return Pointer to internal raw data buffer of the block + */ +unsigned char * tape_block::get_raw_data(){ + return raw_data; +} + +/***************************************************************/ +/*! + *\brief Static factory method with file descriptor support. + * + * This method creates a tape_block by using the private + * constructor with file descriptor support.\t + * It always returns a valid pointer, errors + * or exceptional conditions during creation are marked in the + * object's state.\n + * The factory method tries to determine the block's type and then + * looks for appropriate subclasses. If there's an appropriate + * subclass fitting the newly-created object, an + * object of the subclass will be created and a pointer to this + * object will be returned to the caller.\n + * This allows for easy use of the object using it's virtual + * interface methods or a cast of the pointer to a sub type pointer + * according to the type information, and then using the subtype's + * methods not already present in tape_block.\t + * Objects of the following subclasses are automagically generated:\t + * - eot_block + * - data_block + * -data_block_0 + * -data_block_0_0 + * -data_block_0_1 + * -data_block_0_2 + * -data_block_0_3 + * -data_block_0_4 + * -data_block_0_10 + * -data_block_0_14 + * -data_block_0_24 + * -data_block_0_30 + * -data_block_0_50 + * -data_block_0_54 + * -data_block_0_60 + * -data_block_1 + * -data_block_2 + * -data_block_3 + * -data_block_4 + * -data_block_5 + * -data_block_6 + * -data_block_7 + * + *\return Pointer to an object of type tape_block or a subclass. + *\param fd A file descriptor where the read is taken from. + *\param input_start A pointer to a function + * called before reading data from fd. + *\param input_stop A pointer to a function + * called after reading data from fd. + * + *\param start_stop_arg A pointer passed to input_start + * and input_stop(). Can be anything. + */ tape_block * tape_block::gen_from_fd(int fd, void(*input_start)(void *), void (*input_stop)(void *), @@ -63,6 +235,7 @@ tape_block * tape_block::gen_from_fd(int fd, // case 030: d0_block=new data_block_0_30(d0_block); break; // case 054: d0_block=new data_block_0_54(d0_block); break; // case 060: d0_block=new data_block_0_60(d0_block); break; +// case 060: d0_block=new data_block_0_50(d0_block); break; default: return res_block; } @@ -72,30 +245,14 @@ tape_block * tape_block::gen_from_fd(int fd, return res_block; } +/***************************************************************/ /*! *\brief Default constructor. */ tape_block::tape_block(){} -tape_block::tape_block(tape_block & org){ - block_type=org.block_type; - init_state=org.init_state; - data_read=org.data_read; - raw_data=0; - raw_size=org.raw_size; - word_data=0; - word_size=org.word_size; - if (raw_size){ - raw_data=(unsigned char *)malloc(raw_size); - memcpy(raw_data,org.raw_data,raw_size); - } - if (word_size){ - word_data=(unsigned short *)malloc(word_size*sizeof(unsigned short)); - memcpy(word_data,org.word_data,word_size*sizeof(unsigned short)); - } -} - +/***************************************************************/ /*! *\brief Automatic constructor with file descriptor support * @@ -236,78 +393,12 @@ tape_block::tape_block (int fd, init_state=TBS_OK; } -/*! - *\brief Default destructor. - */ -tape_block::~tape_block(){ - free(raw_data); - free(word_data); -} - -/*! - *\brief Query the block's state. - * - * If the state is not TBS_OK, the block must be discarded. - *\return The block's initialisation state - */ -tape_block::tb_state_t tape_block::get_state(){ - return init_state; -} - - -/*! - *\brief Get size of the internal raw data buffer - *\return The size of the internal raw data buffer - */ -int tape_block::get_raw_size(){ - return raw_size; -} - -/*! - *\brief Access internal raw data buffer - * - * The raw data buffer contains all block data except the \ \ - * block start delimiter and block end delimiter. - *\return Pointer to internal raw data buffer of the block - */ -unsigned char * tape_block::get_raw_data(){ - return raw_data; -} +/***************************************************************/ /*! - *\brief Determine the block's type - * - * This routine returns the block's type.\\ - *\retval TBT_DATA if it's a data block - *\retval TBT_EOT if it's an end of tape mark - *\retval TBR_DISCARD if the block is unusable - * - *\note This function is virtual. That means that if the tape block in - * question is of the subtype data_block which overwrites this method, - * it will return the block type contained in the upper 4 bits of the - * first data word! Try to avoid testing for TBT_DATA. \n - * Blocks generated by gen_from_fd should never have TBT_DATA. - */ -int tape_block::get_type(){ - return block_type; -} - -/*! - *\brief Determine the block's subtype - * - * Some data block types have a subtype. - *\note This is to be used in derived classes. - *\return Always 0 - */ -int tape_block::get_subtype(){ - return 0; -} - - -/*! - *\brief Initialize word representation of data - *\retval 0 on success - *\retval 1 on error + *\brief Initialize word representation of data. + *\retval 0 on success. + *\retval 1 on error. */ int tape_block::init_words(){ word_size=raw_size/3; @@ -318,10 +409,11 @@ int tape_block::init_words(){ return 0; } +/***************************************************************/ /*! - *\brief Calculate and check checksum - *\retval 0 on success - *\retval 1 on error + *\brief Calculate and check checksum. + *\retval 0 on success. + *\retval 1 on error. */ int tape_block::test_checksum(){ unsigned short sum=0; @@ -330,3 +422,4 @@ int tape_block::test_checksum(){ if (sum==word_data[word_size-1]) return 0; else return 1; } + diff --git a/pc-tools/ldc2/src/tape_block.hh b/pc-tools/ldc2/src/tape_block.hh index 9f162df..f023ead 100644 --- a/pc-tools/ldc2/src/tape_block.hh +++ b/pc-tools/ldc2/src/tape_block.hh @@ -1,6 +1,11 @@ #ifndef TAPE_BLOCK_H #define TAPE_BLOCK_H +#include +#include + +using namespace std; + /*! *\brief Tape data block base class. * @@ -33,26 +38,23 @@ public: // types } tb_type_t; public: // methods - - static tape_block * - gen_from_fd(int fd, - void(*input_start)(void *)=0, - void (*input_stop)(void *)=0, - void * start_stop_arg=0 - ); - virtual ~tape_block(); + + tape_block(tape_block &); + void operator=(tape_block &); + tb_state_t get_state(); - int get_raw_size(); - unsigned char * get_raw_data(); virtual int get_type(); virtual int get_subtype(); - -protected: // methods - tape_block(tape_block &); - -private: // methods - + virtual vector get_description(); + int get_raw_size(); + unsigned char * get_raw_data(); + + static tape_block * gen_from_fd(int fd, + void(*input_start)(void *)=0, + void (*input_stop)(void *)=0, + void * start_stop_arg=0 + ); private: // methods tape_block(); @@ -61,6 +63,7 @@ private: // methods void (*input_stop)(void *)=0, void * start_stop_arg=0 ); + int init_words(void); int test_checksum(); @@ -72,8 +75,7 @@ protected: // members int raw_size; //!< Size of the raw data. unsigned short * word_data; //!< Data organized in machine words. int word_size; //!< Size of the blocks in machine words. - -}; // tape_block +}; // class tape_block #endif diff --git a/pc-tools/ldc2/src/test.cpp b/pc-tools/ldc2/src/test.cpp index 41d45cf..36cb22e 100644 --- a/pc-tools/ldc2/src/test.cpp +++ b/pc-tools/ldc2/src/test.cpp @@ -3,6 +3,7 @@ #include #include "tape_block.hh" +#include "data_block.hh" void tape_start(void* m){ printf("tape_start\n"); @@ -17,7 +18,19 @@ int main(){ do{ if (myblock) delete myblock; myblock=tape_block::gen_from_fd(0); - printf ("Block type:%2o-%o\n",myblock->get_type(),myblock->get_subtype()); + + vector desc=myblock->get_description(); + for (vector::iterator iter=desc.begin(); + iter!=desc.end();iter++) + printf("%s\n",(*iter).c_str()); + + +// if ((myblock->get_type()==0)&&(myblock->get_subtype()==050)){ +// data_block * dp=(data_block *)myblock; +// printf ("0-50 symbol name: %s\n",dp->extract_string(4).c_str()); +// printf ("0-50 symbol name: %s\n",dp->extract_string(11).c_str()); +// printf ("Block size:%i\n",dp->get_word_size()); +// } } while (myblock->get_state()==tape_block::TBS_OK); printf("---"); printf("State:%i\n",myblock->get_state());