summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--chip8.c13
-rw-r--r--chip8.h2
-rw-r--r--main.c28
3 files changed, 15 insertions, 28 deletions
diff --git a/chip8.c b/chip8.c
index 1e7a857..f181494 100644
--- a/chip8.c
+++ b/chip8.c
@@ -129,7 +129,8 @@ void
chip8_beep()
{
// TODO: holy shit this is terrible, do something better
- puts("\a");
+ printf("\a");
+ fflush(stdout);
}
void
@@ -157,7 +158,7 @@ chip8_cycle()
uint8_t x = (opcode >> 8) & 0x000F; // lower 4 bits of the high byte, we discard the low byte by right shifting it out
uint8_t y = (opcode >> 4) & 0x000F; // upper 4 bits of the low byte, so we need to discard the lower 4 bits
uint8_t kk = opcode & 0x00FF; // lowest 8 bits
- printf("parsing at 0x%03X opcode = 0x%04X\n", PC, opcode);
+ //printf("parsing at 0x%03X opcode = 0x%04X\n", PC, opcode);
PC += 2; // TODO: remove
switch (opcode & 0xF000)
{
@@ -170,7 +171,6 @@ chip8_cycle()
switch (kk)
{
case 0x00E0: /* cls (clear screen) */
- puts("clear");
memset(video, 0, (WIDTH*HEIGHT) * sizeof(uint32_t));
draw_flag = 1;
break;
@@ -351,7 +351,7 @@ chip8_cycle()
// TODO: not tested
for(int i = 0; i <= x; ++i)
{
- memory[I + i] = V[i];
+ memory[I + i] = V[i];
}
break;
}
@@ -360,7 +360,7 @@ chip8_cycle()
// TODO: not tested
for(int i = 0; i <= x; ++i)
{
- V[i] = memory[I + i];
+ V[i] = memory[I + i];
}
break;
}
@@ -372,7 +372,10 @@ chip8_cycle()
}
default: unknown_opcode(opcode);
}
+}
+void chip8_timer_cycle()
+{
/* timers */
if (delay_timer > 0)
delay_timer--;
diff --git a/chip8.h b/chip8.h
index d19f439..287dacc 100644
--- a/chip8.h
+++ b/chip8.h
@@ -35,6 +35,7 @@
#define FONT_BYTE_SIZE 80
#define BYTE_MASK 0x80
#define PIXEL_COLOR 0xFFFFFF
+#define TIMER_FREQUENCY 60
int load_rom();
void chip8_init();
@@ -42,5 +43,6 @@ void chip8_draw_sprite(int startx, int starty, uint16_t mem, uint8_t size);
void chip8_cycle();
void chip8_beep();
void unknown_opcode(uint16_t bad_opcode);
+void chip8_timer_cycle();
#endif
diff --git a/main.c b/main.c
index 0b7eb83..44a7bfc 100644
--- a/main.c
+++ b/main.c
@@ -29,7 +29,6 @@
*/
//#define VIDEO_SCALE 5
-#define STEPPING 0 // set to 1 to step manually through program
SDL_Window *window;
SDL_Renderer *renderer;
@@ -236,30 +235,13 @@ int main(int argc, char *argv[])
// logic
do_quit = handle_sdl_events();
- if (STEPPING)
- {
- if (step_cycle == 1)
- {
- chip8_cycle();
+ chip8_cycle();
+ chip8_timer_cycle();
- if (draw_flag)
- {
- update_video();
- draw_flag = 0;
- }
-
- step_cycle = 0;
- }
- }
- else
+ if (draw_flag)
{
- chip8_cycle();
-
- if (draw_flag)
- {
- update_video();
- draw_flag = 0;
- }
+ update_video();
+ draw_flag = 0;
}
frame_time = SDL_GetTicks() - frame_start;