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