X-Git-Url: http://gitweb.hachti.de/?a=blobdiff_plain;f=pc-tools%2Fldc2%2Fsrc%2Ftape_block.cpp;h=0d011ebb0392b59635a3becec22f5c71eb3776c6;hb=09cb0f4f1082875e0e87d169c0cd373a7d3f9d80;hp=8b29bc62d1a0008257d32712143d96379c9f9198;hpb=0ec6e0426b19388fdac1312216a0095c7bed04a0;p=h316.git diff --git a/pc-tools/ldc2/src/tape_block.cpp b/pc-tools/ldc2/src/tape_block.cpp index 8b29bc6..0d011eb 100644 --- a/pc-tools/ldc2/src/tape_block.cpp +++ b/pc-tools/ldc2/src/tape_block.cpp @@ -1,15 +1,199 @@ #include #include #include +#include #include "tape_block.hh" #include "data_block.hh" #include "data_block_0.hh" +#include "data_block_0_0.hh" +#include "data_block_0_1.hh" +#include "data_block_0_2.hh" +#include "data_block_0_3.hh" +#include "data_block_0_4.hh" +#include "data_block_0_10.hh" +#include "data_block_0_14.hh" +#include "data_block_0_24.hh" +#include "data_block_0_44.hh" +#include "data_block_0_30.hh" +#include "data_block_0_54.hh" +#include "data_block_0_60.hh" +#include "data_block_0_50.hh" +#include "eot_block.hh" +#include "discard_block.hh" #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(){ + vector result; + result.insert(result.end(), + "***** "+get_typestring()+"Untyped tape block"); + 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.\n + * 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.\n + * Objects of the following subclasses are automagically generated:\n + * - eot_block + * - discard_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 *), @@ -17,9 +201,11 @@ tape_block * tape_block::gen_from_fd(int fd, { tape_block * res_block; res_block=new tape_block(fd,input_start,input_stop,start_stop_arg); - data_block * d_block; - data_block_0 * d0_block; - + data_block * d_block; + data_block_0 * d0_block; + eot_block * e_block; + discard_block * di_block; + // Retype to data_block if possible switch(res_block->get_type()){ case tape_block::TBT_DATA: // Make pointer a data block @@ -27,6 +213,16 @@ tape_block * tape_block::gen_from_fd(int fd, delete res_block; res_block=d_block; break; + case tape_block::TBT_EOT: + e_block=new eot_block(*res_block); + delete res_block; + res_block=e_block; + break; + case tape_block::TBT_DISCARD: + di_block=new discard_block(*res_block); + delete res_block; + res_block=di_block; + break; default: // All other cases return res_block; } @@ -52,17 +248,19 @@ tape_block * tape_block::gen_from_fd(int fd, res_block=d_block; if (res_block->get_type()==0) switch(d0_block->get_subtype()){ -// case 000: d0_block=new data_block_0_00(d0_block); break; -// case 001: d0_block=new data_block_0_01(d0_block); break; -// case 002: d0_block=new data_block_0_02(d0_block); break; -// case 003: d0_block=new data_block_0_03(d0_block); break; -// case 004: d0_block=new data_block_0_04(d0_block); break; -// case 010: d0_block=new data_block_0_10(d0_block); break; -// case 014: d0_block=new data_block_0_14(d0_block); break; -// case 024: d0_block=new data_block_0_24(d0_block); break; -// 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 000: d0_block=new data_block_0_0(*d0_block); break; + case 001: d0_block=new data_block_0_1(*d0_block); break; + case 002: d0_block=new data_block_0_2(*d0_block); break; + case 003: d0_block=new data_block_0_3(*d0_block); break; + case 004: d0_block=new data_block_0_4(*d0_block); break; + case 010: d0_block=new data_block_0_10(*d0_block); break; + case 014: d0_block=new data_block_0_14(*d0_block); break; + case 024: d0_block=new data_block_0_24(*d0_block); break; + case 044: d0_block=new data_block_0_44(*d0_block); break; + 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 050: d0_block=new data_block_0_50(*d0_block); break; default: return res_block; } @@ -72,30 +270,28 @@ 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 get a short type description string. + *\return A small string to be used in description methods. + * + * The string is always 19 characters long.\n + * An example is "(99-99) ". + */ +string tape_block::get_typestring(){ + char buffer[13]; + sprintf(buffer,"(%o-%o) ",get_type(),get_subtype()); + buffer[10]=0; + return string(buffer); } +/***************************************************************/ /*! *\brief Automatic constructor with file descriptor support * @@ -236,78 +432,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 +448,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 +461,4 @@ int tape_block::test_checksum(){ if (sum==word_data[word_size-1]) return 0; else return 1; } +