-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.c
More file actions
71 lines (50 loc) · 1.68 KB
/
main.c
File metadata and controls
71 lines (50 loc) · 1.68 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
// gcc main.c ccd.c -o ccd -O3
#include <stdio.h>
#include <stdlib.h>
#include "ccd.h"
int main(int argc, char* argv[]) {
if (argc >= 2) {
double start = ((double)timeInMilliseconds()) / 1000;
int32_t fileLen;
uint8_t* buffer = readFile(argv[1], &fileLen);
int i = 0;
// skip past the buffer
while (buffer[i] != 0x1d || buffer[i + 1] != 0x1d || buffer[i + 2] != 0x1d || buffer[i + 3] != 0x1d)
++i;
int headerSize = i;
int opcodeCount = 0;
uint8_t encounteredError = 0;
printHeader();
i += 4;
while (i < fileLen) {
++opcodeCount;
printf("%s%08X%s | ", RED, i, NORM);
int start = i;
int8_t width = getOpcodeWidth(buffer[i]);
printf("%s", YELLOW);
for (int j = 0; j < width; j++)
printf("%02x ", (uint8_t)buffer[i++]);
printf("%s", NORM);
for (int j = 0; j < (9 - width); j++)
printf(" ");
printf("| ");
printf("%s", encounteredError ? RED : MAGENTA);
uint8_t error = printDisassembly(buffer, start);
if (error) {
encounteredError = 1;
}
printf("%s", NORM);
puts("");
}
printf("\n%sinfo:%s\n", GREEN, NORM);
printf("%sheader size:%s %d bytes\n", RED, YELLOW, headerSize);
printf("%sopcode count:%s %d opcodes\n", RED, YELLOW, opcodeCount);
printf("%stotal ccb size:%s %d bytes\n", RED, YELLOW, fileLen);
double end = ((double)timeInMilliseconds()) / 1000;
printf("%sdisassembly time:%s %.3f seconds\n", RED, YELLOW, end - start);
printf("%sdisassembler version:%s %s\n", RED, YELLOW, DISASSEMBLER_VERSION);
printf("%s", NORM);
} else {
printf("CC Disassembler %s", DISASSEMBLER_VERSION);
}
}