Explorar el Código

Fix bug with FX0A

Alex hace 6 años
padre
commit
6bd3a22e5b
Se han modificado 1 ficheros con 9 adiciones y 7 borrados
  1. 9
    7
      main.c

+ 9
- 7
main.c Ver fichero

@@ -53,6 +53,7 @@ int main(int argc, char **argv) {
53 53
 	int frame = 0;
54 54
 	int press = 0;
55 55
 	int wait = 0;
56
+	int store = 0;
56 57
 
57 58
 	while (1) {
58 59
 		if (DEBUG) printf("0x%x ", state.program_counter);
@@ -66,10 +67,7 @@ int main(int argc, char **argv) {
66 67
 			press = 0;
67 68
 		}
68 69
 
69
-		clock_t start = clock() / (CLOCKS_PER_SEC/1000);
70
-
71 70
 		// opcodes are 16 bits
72
-		word opcode = (state.memory[state.program_counter++] << 8) | (state.memory[state.program_counter++]);
73 71
 
74 72
 		SDL_PollEvent(&e);
75 73
 		if (e.type == SDL_QUIT) break;
@@ -91,13 +89,15 @@ int main(int argc, char **argv) {
91 89
 			for (int i = 0; i < 0x10; ++i) {
92 90
 				if (state.input[i] != 0)
93 91
 				{
94
-					state.registers[0xF] = i;
92
+					state.registers[store] = i;
95 93
 					break;
96 94
 				}
97 95
 			}
98 96
 			wait = 0;
99 97
 		}
100 98
 
99
+		word opcode = (state.memory[state.program_counter++] << 8) | (state.memory[state.program_counter++]);
100
+
101 101
 		switch (opcode & 0xF000) 
102 102
 		{
103 103
 			case 0x0000: // screen clear or function return 
@@ -284,9 +284,11 @@ int main(int argc, char **argv) {
284 284
 					byte data = state.memory[state.address_I + line];
285 285
 					for (int xpos = 0; xpos < 8; ++xpos)
286 286
 					{
287
+						int ypos = y + line;
288
+						if (ypos > 63) ypos -= 64;
287 289
 						if (!(data & (1 << xpos))) continue;
288
-						if (state.screen[x + (7 - xpos)][y + line]) state.registers[0xF] = 1;
289
-						state.screen[x + (7 - xpos)][y + line] ^= 1;
290
+						if (state.screen[x + (7 - xpos)][ypos]) state.registers[0xF] = 1;
291
+						state.screen[x + (7 - xpos)][ypos] ^= 1;
290 292
 					}
291 293
 				}
292 294
 
@@ -329,6 +331,7 @@ int main(int argc, char **argv) {
329 331
 
330 332
 					case 0x0A:
331 333
 						wait = 1;
334
+						store = reg;
332 335
 						break;
333 336
 
334 337
 					case 0x15:
@@ -393,7 +396,6 @@ int main(int argc, char **argv) {
393 396
 
394 397
 		SDL_RenderPresent(renderer);
395 398
 
396
-		clock_t stop = clock() / (CLOCKS_PER_SEC/1000);
397 399
 		SDL_Delay(1);
398 400
 		++frame;
399 401
 		// SDL_DestroyWindow(window);