-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathChanges.cpp
153 lines (144 loc) · 3.36 KB
/
Changes.cpp
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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
tcount =0;
fcount=0;
cexec=0;
/************editting the call, DJNZ, JP and JR ******************/
case 0x04: /* CALL (dst) IRR */
/* get destination */
dst = prog_mem_fetch();
dest = (read_rm(dst++))<<8;
dest = (dest|read_rm(dst));
/* SP <-- SP-2 */
sp = SP;
sp =-0x02;
/* updating the SP */
write_rm(SPL, LSBY(sp));
if(SPLOC == 0){ // stack is in data memory
write_rm(SPH, MSBY(sp));
/* @SP <-- PC */
write_dm(sp++, MSBY(pc));
write_dm(sp++, LSBY(pc));
}else{ // stack is in register memory
/* @SP <-- PC */
write_rm(sp++, MSBY(pc));
write_rm(sp++, LSBY(pc));
}
/* PC <-- dst */
pc = dest;
/******IF ADDITION ******/
//can force tcount, fcount, cexec to zero
tcount =0;
fcount=0;
cexec=0;
/***********************/
sys_clock +=20; // 20 cycles
break;
case 0x06: /* CALL (dst) DA */
/* get destination */
dst = prog_mem_fetch();
dest = dst<<8;
dst = prog_mem_fetch();
dest = (dest|dst);
/* SP <-- SP-2 */
sp = SP;
sp =-0x02;
write_rm(SPL, LSBY(sp));
if(SPLOC==0){ // stack is in data mem
write_rm(SPH, MSBY(sp));
/* @SP <-- PC */
write_dm( sp++, MSBY(pc));
write_dm(sp, LSBY(pc));
}else{// stack is in reg mem
/* @SP <-- PC */
write_rm( sp++, MSBY(pc));
write_rm(sp, LSBY(pc));
#ifdef VEIW_STACK
printf(" stack holds : lo: %2x hi: %2x \n", read_rm(sp--), read_rm(sp));
#endif
}
/* PC <-- dst */
pc = dest;
/*increment system clock */
sys_clock +=20; // 20 cycles
/******IF ADDITION ******/
//can force tcount, fcount, cexec to zero
tcount =0;
fcount=0;
cexec=0;
/***********************/
#ifdef VEIW_MEM
printf("pc holds : %4x \n", pc);
#endif
break;
case 0x0A: /* DJNZ r, dst */
dst = prog_mem_fetch();
src = RPBLK|high_nib;
regval = read_rm(src);
regval -= 1;
if (regval != 0)
{
/* Reg != 0 -- repeat loop */
/* Signed extend dst to 16 bits if -ve */
pc = pc + SIGN_EXT(dst);
#ifdef JUMP
printf("pc after jump is : %x \n", pc);
printf("contents of prog mem(pc) is %x \n", read_pm(pc));
#endif
/***********IF ADDITION *************/
tcount =0;
fcount=0;
cexec=0;
#ifdef IF_TEST
printf("flow of control tcount: %x fcount: %x cexec: %x \n", tcount, fcount, cexec);
#endif
/***********************************/
sys_clock +=2;
}
write_rm(src, regval);
sys_clock +=10; // total of 12 cycles if JUMP is taken
break;
case 0x0B: /* JR cc,RA */
dst = prog_mem_fetch(); // RA
if(cond_handler(high_nib)){
#ifdef JUMP
printf("pc before jump is : %x \n", pc);
printf("contents of prog mem(pc) is %x \n", read_pm(pc));
#endif
pc = pc + SIGN_EXT(dst);
#ifdef JUMP
printf( "JUMP TAKEN: "
"dst = %x , pc = %x \n", dst, pc);
printf("contents of prog mem(pc) is %x \n", read_pm(pc));
#endif
/***********IF ADDITION *************/
tcount =0;
fcount=0;
cexec=0;
#ifdef IF_TEST
printf("flow of control tcount: %x fcount: %x cexec: %x \n", tcount, fcount, cexec);
#endif
/***********************************/
sys_clock += 2; // total of 12 cycles if jump is taken
}
break;
case 0x0D: /* JP cc, DA */
/* get DA */
dest = (prog_mem_fetch() <<8);
dest|=(prog_mem_fetch());
if(cond_handler(high_nib)){
// condition code is true
/* PC <-- dst */
pc = dest;
#ifdef JUMP
printf("JUMP TAKEN, NEW PC = %x \n", pc);
#endif
/***********IF ADDITION *************/
tcount =0;
fcount=0;
cexec=0;
#ifdef IF_TEST
printf("flow of control tcount: %x fcount: %x cexec: %x \n", tcount, fcount, cexec);
#endif
/***********************************/
sys_clock += 2; // total of 12 cycles if jump is taken
}
break;