Fix bug with FX0A

This commit is contained in:
2018-10-29 18:25:06 -04:00
parent 8795f83f75
commit 6bd3a22e5b

16
main.c
View File

@@ -53,6 +53,7 @@ int main(int argc, char **argv) {
int frame = 0;
int press = 0;
int wait = 0;
int store = 0;
while (1) {
if (DEBUG) printf("0x%x ", state.program_counter);
@@ -66,10 +67,7 @@ int main(int argc, char **argv) {
press = 0;
}
clock_t start = clock() / (CLOCKS_PER_SEC/1000);
// opcodes are 16 bits
word opcode = (state.memory[state.program_counter++] << 8) | (state.memory[state.program_counter++]);
SDL_PollEvent(&e);
if (e.type == SDL_QUIT) break;
@@ -91,13 +89,15 @@ int main(int argc, char **argv) {
for (int i = 0; i < 0x10; ++i) {
if (state.input[i] != 0)
{
state.registers[0xF] = i;
state.registers[store] = i;
break;
}
}
wait = 0;
}
word opcode = (state.memory[state.program_counter++] << 8) | (state.memory[state.program_counter++]);
switch (opcode & 0xF000)
{
case 0x0000: // screen clear or function return
@@ -284,9 +284,11 @@ int main(int argc, char **argv) {
byte data = state.memory[state.address_I + line];
for (int xpos = 0; xpos < 8; ++xpos)
{
int ypos = y + line;
if (ypos > 63) ypos -= 64;
if (!(data & (1 << xpos))) continue;
if (state.screen[x + (7 - xpos)][y + line]) state.registers[0xF] = 1;
state.screen[x + (7 - xpos)][y + line] ^= 1;
if (state.screen[x + (7 - xpos)][ypos]) state.registers[0xF] = 1;
state.screen[x + (7 - xpos)][ypos] ^= 1;
}
}
@@ -329,6 +331,7 @@ int main(int argc, char **argv) {
case 0x0A:
wait = 1;
store = reg;
break;
case 0x15:
@@ -393,7 +396,6 @@ int main(int argc, char **argv) {
SDL_RenderPresent(renderer);
clock_t stop = clock() / (CLOCKS_PER_SEC/1000);
SDL_Delay(1);
++frame;
// SDL_DestroyWindow(window);