-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGenerate.cs
135 lines (103 loc) · 5.11 KB
/
Generate.cs
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
using System;
using System.Collections.Generic;
using System.Text;
namespace TimerGenerator
{
public static class Generate
{
public static bool GenerateOneLoop(double duree, double freq, int max_nop, out string result, string loopName, string varName, string procedureName)
{
int GEN_TIME_LOST_ONE_LOOP = 6;
result = string.Empty;
double clock_speed_us = (1 /freq ) * 4;
// On enlève les temps perdu en générale
duree -= clock_speed_us * GEN_TIME_LOST_ONE_LOOP;
int cpt, Y_nop = 0, X_nop = 0;
for (Y_nop = 0; Y_nop <= max_nop; Y_nop++)
{
for (cpt = 255; cpt >= 0; cpt--)
{
for (X_nop = 0; X_nop <= max_nop; X_nop++)
{
if (duree == (Y_nop + ((X_nop + 3) * cpt) -1) * clock_speed_us)
{
// Le résultat est trouvé
result = string.Format("{0}\n MOVLW D'{1}'\n MOVWF {2}\n{3}\n",
procedureName, cpt, varName, loopName);
for (; X_nop > 0; X_nop--)
result += " NOP\n";
result += string.Format(" DECFSZ {0}, F\n GOTO {1}\n", varName, loopName);
for (; Y_nop > 0; Y_nop--)
result += " NOP\n";
result += " RETURN";
return true;
}
}
}
}
return false;
}
public static bool GenerateTwoLoop(double duree, double freq, int max_nop, out string result, string loopName1, string varName1, string procedureName, string loopName2, string varName2)
{
// Déclaration et définition des variables
int TIME_CALL_RETURN_INIT = 7;
int MAX_TIME_LP_1 = (max_nop + 3) * 255 - 1;
int MAX_TIME_LP_2 = (MAX_TIME_LP_1 + max_nop + 4) * 255 - 1;
int MAX_TIME = MAX_TIME_LP_2 + TIME_CALL_RETURN_INIT;
result = string.Empty;
double clock_speed_us = (1 / freq) * 4;
// On enlève les temps perdu en générale
duree -= clock_speed_us * TIME_CALL_RETURN_INIT;
double dureeTemp = duree;
int cpt1, cpt2, Z_nop, Y_nop, X_nop;
/*
BOUCLE 1 = (X + 3) * cpt1 -1
BOUCLE 2 = (boucle1 + Y + 4) * cpt2 -1
TOTAL = boucle2 + Z + 7
RES = Z + 7 - 1 + cpt2*((X+3)*cpt1 - 1 + Y + 4)
*/
for (Z_nop = 0; Z_nop <= max_nop; Z_nop++)
{
for (cpt2 = 255; cpt2 > 0; cpt2--)
{
dureeTemp = duree - Z_nop + 1;
///
/// BOUCLE 2
///
if (dureeTemp % cpt2 == 0 && dureeTemp / cpt2 <= (max_nop+3)*255+max_nop+3)
{
for (Y_nop = 0; Y_nop <= max_nop; Y_nop++)
{
for (cpt1 = 255; cpt1 > 0; cpt1--)
{
///
/// BOUCLE 1
///
if (((dureeTemp / cpt2) + 1 - Y_nop - 4) % cpt1 == 0)
{
X_nop = (int)(dureeTemp / cpt2 + 1 - Y_nop - 4) / cpt1;
if (X_nop <= max_nop && X_nop >= 3) {
// Le résultat est trouvé
result = string.Format("{0}\n MOVLW D'{1}'\n MOVWF {2}\n MOVLW D'{3}'\n{4}\n MOVWF {5}\n{6}\n",
procedureName, cpt2, varName2, cpt1, loopName2, varName1, loopName1);
for (X_nop -= 3; X_nop > 0; X_nop--)
result += " NOP\n";
result += string.Format(" DECFSZ {0}, F\n GOTO {1}\n", varName1, loopName1);
for (; Y_nop > 0; Y_nop--)
result += " NOP\n";
result += string.Format(" DECFSZ {0}, F\n GOTO {1}\n", varName2, loopName2);
for (; Z_nop > 0; Z_nop--)
result += " NOP\n";
result += " RETURN";
return true;
}
}
}
}
}
}
}
return false;
}
}
}