-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFetch.cc
More file actions
83 lines (74 loc) · 1.58 KB
/
Fetch.cc
File metadata and controls
83 lines (74 loc) · 1.58 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
#include "Fetch.h"
#include "Registers.h"
#define FON 1
extern Memory Mem;
#ifdef FON
Fetch::Fetch()
{
}
bool Fetch::Open(std::string name )
{
Fin.open(name.c_str(),std::ios::in);
if (!Fin)
{
return false;
}
std::cout<<"DEBUG :: File Opened Successfully";
return true;
}
bool Fetch::loadupmemory()
{
//start loading from 100
char * file;
Fin.seekg(0,std::ios::end);
int size =0;
size = Fin.tellg();
Fin.seekg(0,std::ios::beg);
file = new char[size +1];
Fin.getline(file,size+1,EOF);
//parse file and kill comments
for ( int i =0 ; i <size +1 ; i ++)
{
if ( file[i]== '/')
{
while ( file [i] != '\n')
{
file[i] = ' '; //white space the worse kind of space there is :P
i++;
}
}
}
std::istringstream iss(file);
std::string Segname;
int TotalVariables;
iss>>Segname;
if ( Segname == "DATA")
{
iss>>TotalVariables;
for ( int i =0 ; i <TotalVariables ; i++)
{
short int x=0;
iss>>x;
iss>>Mem.mem[x];
std::cout<<"\nDEBUG :: Stored "<<Mem.mem[x]<<" to @0x"<<std::hex<<x<<std::endl;
}
}
iss>>Segname;
if (Segname == "MAIN")
{
int i=0;
for( i =100 ; Mem.mem[i-1] != 0x7001 ; i ++)
{
iss>>std::hex>>Mem.mem[i];
if ( i >4096)
{
std::cerr<<"ERROR :: Program Not ended with 0x7001";
return false;
}
}
}
std::cout<<"\nDEBUG :: Successfully Loaded"<<std::endl;
delete [] file;
return true;
}
#endif