-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdebug.c
More file actions
205 lines (195 loc) · 5.02 KB
/
Copy pathdebug.c
File metadata and controls
205 lines (195 loc) · 5.02 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
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
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
/*
* This file is for referece only, does not get used by the core
* program as of now.
*/
void print_opcode_info(opcode *op) {
printf("Opcode: %x - ", op->bytes);
switch (op->head) {
case 0x0: /* Clear screen */
switch (op->NN) {
case 0xE0:
printf("Clear Screen\n");
break;
case 0xEE:
printf("Pop stack, set PC\n");
break;
}
break;
case 0x1: /* Jump */
printf("Jump PC to NNN\n");
break;
case 0x2:
printf("Push PC to stack, set PC to NNN\n");
break;
case 0x3:
printf("Skip instruction, if VX == NN\n");
break;
case 0x4:
printf("Skip instruction, if VX != NN\n");
break;
case 0x5:
printf("Skip instruction, if VY == NN\n");
break;
case 0x6:
printf("Set VX to NN\n");
break;
case 0x7:
printf("Add NN to VX\n");
break;
case 0x8:
switch (op->N) {
case 0x0:
printf("Set VX to VY\n");
break;
case 0x1:
printf("OR VX with VY\n");
break;
case 0x2:
printf("AND VX with VY\n");
break;
case 0x3:
printf("XOR VX with VY\n");
break;
case 0x4:
printf("Add VX + VY to VX\n");
break;
case 0x5:
printf("Sub VX - VY to VX\n");
break;
case 0x6:
printf("Shift VX one bit to right\n");
break;
case 0x7:
printf("Sub VY - VX to VX\n");
break;
case 0xe:
printf("Shift VX one bit to left\n");
break;
}
break;
case 0x9:
printf("Skip instruction, if VY == NN\n");
break;
case 0xA: /* Set index regiser I */
printf("Set memory in I to NNN\n");
break;
case 0xB:
printf("Jump with offset, PC to NNN+VX\n");
break;
case 0xC: {
printf("AND random number with NN, put in VX\n");
break;
} break;
case 0xD: /* Draw a sprite */
printf("Draw a sprit\n");
break;
case 0xE:
switch (op->NN) {
case 0x9E:
printf("Jump to next instruction if key is pressed\n");
break;
case 0xA1:
printf("Jump to next instruction if key is not pressed\n");
break;
}
break;
case 0xF:
switch (op->NN) {
// Timers
case 0x7:
printf("Set VX to current delay timer\n");
break;
case 0x15:
printf("Set delay timer to VX\n");
break;
case 0x18:
printf("Set sound timer to VX\n");
break;
// Get key input
case 0xA:
printf("Wait for key\n");
break;
// Add to index
case 0x1E:
printf("Add I with VX\n");
break;
// Font character
case 0x29:
printf("Points I to the correct font sprite\n");
break;
// Binary-coded decimal conversionPermalink
case 0x33:
printf("Binary-coded decimal\n");
break;
case 0x55:
printf("Stores V0 -> VX in Mem[I->I+X]\n");
break;
case 0x65:
printf("Stores Mem[I->I+X] in V0 -> VX\n");
break;
}
break;
}
}
int debug(uint8_t *ram, opcode *op) {
print_opcode_info(op);
char str[100];
do {
printf("[n]ext, [o]pcode, [r]ram, [q]uite: ");
fgets(str, 100, stdin);
switch (str[0]) {
case 'n':
break;
case '\n':
break;
case 'o':
print_opcode(*op);
break;
case 'r':
print_bytes(ram, RAM_SIZE);
break;
case 'q':
return 1;
default:
printf("Wrong input: %s\n", str);
}
} while (str[0] != 'n');
return 0;
}
void print_stack(stack *sp) {
if (sp == NULL) {
printf("stack emptry\n");
}
printf("stack(%d): [%d]", sp->size, sp->data);
stack *cur = sp;
while (cur->next != NULL) {
cur = cur->next;
printf(" -> [%d]", cur->data);
}
printf("\n");
}
void print_texture(Texture2D texture) {
Image image = LoadImageFromTexture(texture);
Color *colors = LoadImageColors(image);
for (int y = 0; y < image.height; y++) {
for (int x = 0; x < image.width; x++) {
Color pixel = GetPixelColor(colors + x + y * texture.width, 0);
if (pixel.r == BLACK.r && pixel.b == BLACK.g && pixel.g == BLACK.g)
printf("[B] ");
else
printf("[W] ");
}
printf("\n");
}
UnloadImageColors(colors);
UnloadImage(image);
}
void print_opcode(opcode op) {
printf("Head: %x\n"
"X: %x\n"
"Y: %x\n"
"N: %x\n"
"NN: %x\n"
"NNN: %x\n\n",
op.head, op.X, op.Y, op.N, op.NN, op.NNN);
}