source: subversion/applications/lib/libimg/ImgHeader.cpp @ 34621

Last change on this file since 34621 was 11688, checked in by nienhueser, 11 years ago

compile.

File size: 4.7 KB
Line 
1/*
2    Copyright (C) 2007 Robert Hart, rob@bathterror.free-online.co.uk
3
4    This program is free software; you can redistribute it and/or modify
5    it under the terms of the GNU General Public License as published by
6    the Free Software Foundation; either version 2 of the License, or
7    (at your option) any later version.
8
9    This program is distributed in the hope that it will be useful,
10    but WITHOUT ANY WARRANTY; without even the implied warranty of
11    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12    GNU Lesser General Public License for more details.
13
14    You should have received a copy of the GNU General Public License
15    along with this program; if not, write to the Free Software
16    Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111 USA
17
18 */
19#include "Img.h"
20
21ImgHeader::ImgHeader() : ImgData() {
22  chksum = 0 ; 
23  SetDescription("ABCDEFGHIJKLMNOPQRSTUVWXYZ");
24}
25
26void ImgHeader::SetDescription(const char *desc){
27  description.assign(desc);
28  if (description.length()<50){
29    description += std::string (50-description.length(), ' ');
30  }
31  if (description.length()>50){
32    description = description.substr(0, 50);
33  }
34  description+='\0';
35}
36
37void ImgHeader::SetNumFatBlocks(int n){
38  nFatBlocks = n;
39}
40
41int ImgHeader::GetNumFatBlocks(){
42  return nFatBlocks;
43}
44
45void ImgHeader::CreateHeader(){
46  SetByte(0x00, xorbyte);       //XOR byte
47  SetByte(0x01, 0, 9);    //padding
48  SetByte(0x0A, updatetime.tm_mon);   //update month
49  SetByte(0x0B, (updatetime.tm_year>=100)?updatetime.tm_year-100:updatetime.tm_year); //update year
50  //SetByte(0x0B, updatetime.tm_year); //update year
51  SetByte(0x0C, 0, 3);    //padding
52  SetByte(0x0F, chksum);  //checksum - will need to calculate later
53  SetString(0x10, "DSKIMG\0"); // Signature
54  SetByte(0x17, 2);       //unknown
55  SetShort(0x18,  4);      //sectors
56  SetShort(0x1A, 16);      //heads
57  SetShort(0x1C, 32);      //cylinders
58  SetShort(0x1E,  0);      //unknown
59  SetByte(0x20, 0, 25);    //padding
60  SetShort(0x39, updatetime.tm_year+1900);    //creation year
61  SetByte(0x3B, updatetime.tm_mon);    //creation month
62  SetByte(0x3C, updatetime.tm_mday);      //creation day
63  SetByte(0x3D, updatetime.tm_hour);     //creation hour
64  SetByte(0x3E, updatetime.tm_min);   //creation minute
65  SetByte(0x3F, updatetime.tm_sec);   //creation second
66  SetByte(0x40, 2);        //Unknown
67  SetString(0x41, IDENT);  //Map file identifier
68  SetByte(0x48, 0);        //Padding?
69  SetString(0x49, description.substr(0, 20));
70  SetShort(0x5D, 16);      //heads?
71  SetShort(0x5F, 4);       //sectors?
72  SetByte(0x61, 9);        //block size E1
73  SetByte(0x62, 0);        //block size E2 (force block size to 512)
74  SetShort(0x63, 2048);        // (heads*sectors*cylinders)/2^(E2)
75  SetString(0x65, description.substr(20, 51));    //should be rest of description
76  SetByte(0x84, 0, 314);     // loads of padding!
77  //Partition table
78  SetByte(0x1BE, 0);       //boot?
79  SetByte(0x1BF, 0);       //start-head?
80  SetByte(0x1C0, 1);       //start-sector?
81  SetByte(0x1C1, 0);       //start-cylinder?
82  SetByte(0x1C2, 0);       //system-type?
83  SetByte(0x1C3, 15);      //end-head?
84  SetByte(0x1C4, 4);       //end-sector?
85  SetByte(0x1C5, 31);      //end-cylinder?
86  SetLong(0x1C6, 0);       //rel-cylinder?
87  SetLong(0x1CA, 2048);// number of sectors?
88  SetByte(0x1CE, 0, 48);   //padding?
89  SetShort(0x1FE, 0x55);
90  SetShort(0x1FF, 0xAA);
91
92  SetByte(0x200, 0, 512);  //padding?
93  SetByte(0x400, 1);       //?
94  SetByte(0x401, 0x20, 11);//?
95  SetLong(0x40C, blocksize*(nblocks+nFatBlocks)); //first file offset
96  SetByte(0x410, 3);       //?
97  SetByte(0x411, 0, 15);   //?
98  SetBlockList(0x420, 0, nblocks+nFatBlocks-1); //write out block count list
99
100}
101
102int ImgHeader::ReadFile(std::ifstream &in)
103{
104  int first;
105  blocksize = 512;
106  nblocks = 3;
107  xorbyte = 0;
108  in.read(data, blocksize * nblocks);
109
110  xorbyte           = DecodeByte(0x00);
111  cout << "xorbyte :" << (int)xorbyte << endl;
112  chksum            = DecodeByte(0x0F);
113  cout << "chksum :" << chksum << endl;
114
115  updatetime.tm_year= DecodeShort(0x39)-1900;
116  updatetime.tm_mon = DecodeByte(0x3B);
117  updatetime.tm_mday= DecodeByte(0x3C);
118  updatetime.tm_hour= DecodeByte(0x3D);
119  updatetime.tm_min = DecodeByte(0x3E);
120  updatetime.tm_sec = DecodeByte(0x3F);
121  cout << "update time is :" << asctime(&updatetime) << endl;
122  blocksize = 1<<   ( DecodeByte(0x61) +
123                      DecodeByte(0x62));
124
125  cout << "blocksize :" << blocksize << endl;
126
127  description.assign("");
128  DecodeString(0x49,20, description);
129  DecodeString(0x65,31, description);
130  DecodeBlockList(0x420, first, nFatBlocks);
131  cout << "header spans " << first << " to " << nFatBlocks << endl;
132  nFatBlocks-=nblocks-1;
133  cout << "description :" << description << endl;
134  return nblocks * blocksize;
135}
Note: See TracBrowser for help on using the repository browser.