-
Notifications
You must be signed in to change notification settings - Fork 0
/
code.c
169 lines (161 loc) · 3.42 KB
/
code.c
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
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
#include <stdio.h>
#include <stdlib.h>
#include "code.h"
static void chartohex(char in, char* outh, char* outl)
{
*outl = in & 0x0f;
if(*outl > 9)
{
*outl += 55;
}
else{
*outl += 48;
}
*outh = in >> 4;
if(*outh > 9)
{
*outh += 55;
}
else{
*outh += 48;
}
}
static void updateaddress(char* a, char* b, char* c)
{
if(*c == 99)
{
*c = 48;
*b += 1;
}
else{
*c += 4;
}
if(*c > 57)
{
*c = 99;
}
if(*b == 58)
{
*b = 97;
}
if(*b == 103)
{
*a += 1;
*b = 48;
}
}
int createout(char* infile, char* codefile)
{
FILE* fptr = fopen(infile, "r");
if(!fptr)
{
return 0;
}
fseek(fptr, 0, SEEK_END);
int size = ftell(fptr);
fseek(fptr, 0, SEEK_SET);
fprintf(stdout, "%d\n", size);
char end = size % 2;
if(end)
{
if((((size / 2) * 12) + 18) > 512)
{
fclose(fptr);
return 0;
}
}
else if((((size / 2) * 12) + 14) > 512)
{
fclose(fptr);
return 0;
}
FILE* fptrc = fopen(codefile, "w");
if(!fptrc)
{
return 0;
}
size -= end;
char a = 48;
char b = 48;
char c = 48;
char r1p = -1;
char r0 = 0;
char r1 = 0;
char r0h;
char r0l;
char r1h;
char r1l;
for(int i = 0; i < size; i += 2){
if(r1p == '\n')
{
r0 = 13;
end ++;
end %= 2;
size ++;
}
else{
fread(&r0, sizeof(char), 1, fptr);
}
if(r0 == '\n')
{
r1 = 13;
end ++;
end %= 2;
size ++;
}
else{
fread(&r1, sizeof(char), 1, fptr);
}
if(r0 == r1p)
{
chartohex(r1, &r1h, &r1l);
fprintf(fptrc, "storage[16'h0%c%c%c>>2] = two16(16'h8011, 16'h61%c%c);\n", a, b, c, r1h, r1l);
}
else if(r0 == r1)
{
chartohex(r1, &r0h, &r0l);
fprintf(fptrc, "storage[16'h0%c%c%c>>2] = two16(16'h60%c%c, 16'h8110);\n", a, b, c, r0h, r0l);
}
else{
chartohex(r0, &r0h, &r0l);
chartohex(r1, &r1h, &r1l);
fprintf(fptrc, "storage[16'h0%c%c%c>>2] = two16(16'h60%c%c, 16'h61%c%c);\n", a, b, c, r0h, r0l, r1h, r1l);
}
updateaddress(&a, &b, &c);
fprintf(fptrc, "storage[16'h0%c%c%c>>2] = two16(16'hc000, 16'hff00);\n", a, b, c);
updateaddress(&a, &b, &c);
fprintf(fptrc, "storage[16'h0%c%c%c>>2] = two16(16'hc100, 16'hff00);\n", a, b, c);
updateaddress(&a, &b, &c);
if(a >= 50)
{
return 0;
}
r1p = r1;
}
if(end)
{
fread(&r0, sizeof(char), 1, fptr);
chartohex(r1, &r0h, &r0l);
fprintf(fptrc, "storage[16'h0%c%c%c>>2] = two16(16'h60%c%c, 16'h610d);\n", a, b, c, r0h, r0l);
updateaddress(&a, &b, &c);
fprintf(fptrc, "storage[16'h0%c%c%c>>2] = two16(16'hc000, 16'hff00);\n", a, b, c);
updateaddress(&a, &b, &c);
fprintf(fptrc, "storage[16'h0%c%c%c>>2] = two16(16'hc100, 16'hff00);\n", a, b, c);
updateaddress(&a, &b, &c);
fprintf(fptrc, "storage[16'h0%c%c%c>>2] = two16(16'h600a, 16'hc000);\n", a, b, c);
updateaddress(&a, &b, &c);
fprintf(fptrc, "storage[16'h0%c%c%c>>2] = two16(16'hff00, 16'hdf00);\n", a, b, c);
}
else{
fprintf(fptrc, "storage[16'h0%c%c%c>>2] = two16(16'h600d, 16'h610a);\n", a, b, c);
updateaddress(&a, &b, &c);
fprintf(fptrc, "storage[16'h0%c%c%c>>2] = two16(16'hc000, 16'hff00);\n", a, b, c);
updateaddress(&a, &b, &c);
fprintf(fptrc, "storage[16'h0%c%c%c>>2] = two16(16'hc100, 16'hff00);\n", a, b, c);
updateaddress(&a, &b, &c);
fprintf(fptrc, "storage[16'h0%c%c%c>>2] = two16(16'hdf00, 16'h0000);\n", a, b, c);
}
fclose(fptr);
fclose(fptrc);
return 1;
}