| 1 | #ifndef TAPE_BLOCK_H |
| 2 | #define TAPE_BLOCK_H |
| 3 | |
| 4 | #include <string> |
| 5 | #include <vector> |
| 6 | |
| 7 | using namespace std; |
| 8 | |
| 9 | /*! |
| 10 | *\brief Tape data block base class. |
| 11 | * |
| 12 | * This class represents a Honeywell paper tape block. |
| 13 | * That may be some kind of data block or a end of tape mark. |
| 14 | */ |
| 15 | class tape_block{ |
| 16 | |
| 17 | public: // types |
| 18 | |
| 19 | /*! |
| 20 | *\brief Initialisation state. |
| 21 | */ |
| 22 | typedef enum { |
| 23 | TBS_OK, //!< Block successfully initialised |
| 24 | TBS_EOF_LEGAL, //!< Legal EOF while initialising |
| 25 | TBS_EOF_ILLEGAL, //!< Illegal EOF while initialising |
| 26 | TBS_CHECKSUM, //!< Checksum error |
| 27 | TBS_IOERR, //!< I/O-Error while reading |
| 28 | TBS_DEFAULT //!< Block not initialised. |
| 29 | } tb_state_t; |
| 30 | |
| 31 | /*! |
| 32 | * Tape block types. |
| 33 | */ |
| 34 | typedef enum { |
| 35 | TBT_DATA=0x10, //!< Data block |
| 36 | TBT_EOT, //!< End of tape block |
| 37 | TBT_DISCARD //!< Invalid block, check block_type |
| 38 | } tb_type_t; |
| 39 | |
| 40 | public: // methods |
| 41 | virtual ~tape_block(); |
| 42 | |
| 43 | tape_block(tape_block &); |
| 44 | void operator=(tape_block &); |
| 45 | |
| 46 | tb_state_t get_state(); |
| 47 | virtual int get_type(); |
| 48 | virtual int get_subtype(); |
| 49 | virtual vector<string> get_description(); |
| 50 | int get_raw_size(); |
| 51 | int get_discarded_bytes(); |
| 52 | unsigned char * get_raw_data(); |
| 53 | |
| 54 | static tape_block * gen_from_fd(int fd, |
| 55 | void(*input_start)(void *)=0, |
| 56 | void (*input_stop)(void *)=0, |
| 57 | void * start_stop_arg=0 |
| 58 | ); |
| 59 | |
| 60 | protected: // methods |
| 61 | tape_block(); |
| 62 | string get_typestring(); |
| 63 | |
| 64 | private: // methods |
| 65 | tape_block (int fd_p, |
| 66 | void(*input_start)(void *)=0, |
| 67 | void (*input_stop)(void *)=0, |
| 68 | void * start_stop_arg=0 |
| 69 | ); |
| 70 | |
| 71 | int init_words(void); |
| 72 | int test_checksum(); |
| 73 | |
| 74 | protected: // members |
| 75 | int block_type; //!< Type of this block. |
| 76 | tb_state_t init_state; //!< Initialisation state. |
| 77 | int discarded_bytes; //!< Amount of bytes discarded before beginning. |
| 78 | unsigned char * raw_data; //!< Raw block data in bytes. |
| 79 | int raw_size; //!< Size of the raw data. |
| 80 | unsigned short * word_data; //!< Data organized in machine words. |
| 81 | int word_size; //!< Size of the blocks in machine words. |
| 82 | int poolsize; //!< Amount of data malloc'ed |
| 83 | }; // class tape_block |
| 84 | |
| 85 | |
| 86 | #endif |