*** empty log message ***
[h316.git] / pc-tools / ldc2 / src / data_block.cpp
1 #include <stdlib.h>
2 #include <string.h>
3
4 #include "data_block.hh"
5 #include "data_block_0.hh"
6
7 #include <stdio.h>
8
9 using namespace std;
10
11 data_block::data_block(tape_block& idol)
12 :tape_block(idol)
13 {
14 }
15
16 data_block::~data_block(){
17 }
18
19 int data_block::get_type(){
20 if ((init_state==TBS_OK)&&word_data)
21 return (word_data[0]&0xf000)>>12;
22 else
23 return block_type;
24 }
25
26 int data_block::get_subtype(){
27 if (get_type()==0)
28 return (new data_block_0(*this))->get_subtype();
29 else return 0;
30 }
31
32 /*!
33 *\brief Get the block's size in 16 bit words.
34 *\return The block's 16-bit data buffer's size including header and checksum.
35 */
36 int data_block::get_word_size(){
37 return word_size;
38 }
39
40 /*!
41 *\brief Extract 6 byte symbol name from word memory.
42 *
43 *\param startbyte the first byte of the desired symbol name
44 *\return a string containing the symbol name.
45 * Trailing spaces are included.
46 *\note The word_data is handled system-intependently big endian!
47 */
48 string data_block::extract_string(int startbyte){
49 string result=""; // Start with empty string
50
51 // We don't accept negative arguments!
52 if (startbyte<0) return result;
53
54 // We also don't want segmentation faults!
55 if (word_size<(startbyte/2+1)) return result;
56
57 // Here we pick out the characters.
58 for (int posi=startbyte;posi<startbyte+6;posi++)
59 result+=(word_data[posi/2]>>(8*(1-posi%2)))&0x7f;
60 return result;
61 }