97b26985 |
1 | #ifndef TAPE_BLOCK_H |
2 | #define TAPE_BLOCK_H |
3 | |
6c06db96 |
4 | #include <string> |
5 | #include <vector> |
6 | |
7 | using namespace std; |
8 | |
97b26985 |
9 | /*! |
0ec6e042 |
10 | *\brief Tape data block base class. |
97b26985 |
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 | /*! |
0ec6e042 |
20 | *\brief Initialisation state. |
97b26985 |
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 | /*! |
0ec6e042 |
32 | * Tape block types. |
97b26985 |
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 | |
97b26985 |
40 | public: // methods |
97b26985 |
41 | virtual ~tape_block(); |
6c06db96 |
42 | |
43 | tape_block(tape_block &); |
44 | void operator=(tape_block &); |
45 | |
97b26985 |
46 | tb_state_t get_state(); |
97b26985 |
47 | virtual int get_type(); |
97b26985 |
48 | virtual int get_subtype(); |
6c06db96 |
49 | virtual vector<string> get_description(); |
50 | int get_raw_size(); |
51 | unsigned char * get_raw_data(); |
52 | |
53 | static tape_block * gen_from_fd(int fd, |
54 | void(*input_start)(void *)=0, |
55 | void (*input_stop)(void *)=0, |
56 | void * start_stop_arg=0 |
57 | ); |
0ec6e042 |
58 | |
09cb0f4f |
59 | protected: // methods |
0ec6e042 |
60 | tape_block(); |
09cb0f4f |
61 | string get_typestring(); |
62 | |
63 | private: // methods |
0ec6e042 |
64 | tape_block (int fd_p, |
65 | void(*input_start)(void *)=0, |
66 | void (*input_stop)(void *)=0, |
67 | void * start_stop_arg=0 |
68 | ); |
6c06db96 |
69 | |
97b26985 |
70 | int init_words(void); |
97b26985 |
71 | int test_checksum(); |
72 | |
73 | protected: // members |
0ec6e042 |
74 | int block_type; //!< Type of this block. |
75 | tb_state_t init_state; //!< Initialisation state. |
76 | int data_read; //!< Total data consumption during intialisation. |
77 | unsigned char * raw_data; //!< Raw block data in bytes. |
78 | int raw_size; //!< Size of the raw data. |
79 | unsigned short * word_data; //!< Data organized in machine words. |
80 | int word_size; //!< Size of the blocks in machine words. |
6c06db96 |
81 | }; // class tape_block |
97b26985 |
82 | |
83 | |
84 | #endif |