|
|
|
@@ -1,3 +1,4 @@ |
|
|
|
#include <inttypes.h> |
|
|
|
#include <limits.h> |
|
|
|
#include <stdlib.h> |
|
|
|
#include <time.h> |
|
|
|
@@ -42,10 +43,16 @@ static nes sys = {0}; |
|
|
|
int main(int argc, char* argv[]) { |
|
|
|
int status = 0; |
|
|
|
|
|
|
|
int n_loops = (argc > 1) ? atoi(argv[1]) : 0; |
|
|
|
if (n_loops <= 0) n_loops = INT_MAX; |
|
|
|
FILE* cart_file = stdin; |
|
|
|
if (argc > 1) cart_file = fopen(argv[1], "rb"); |
|
|
|
if (NULL == cart_file) { |
|
|
|
status = -1; |
|
|
|
fprintf(stderr, "Could not open %s\n", argv[1]); |
|
|
|
} |
|
|
|
|
|
|
|
status = nes_cart_init_file(&sys.cart, stdin); |
|
|
|
if (status == 0) { |
|
|
|
status = nes_cart_init_file(&sys.cart, cart_file); |
|
|
|
} |
|
|
|
|
|
|
|
nes_Renderer* rend = &sdl_renderer; |
|
|
|
if (status == 0) { |
|
|
|
@@ -76,7 +83,7 @@ int main(int argc, char* argv[]) { |
|
|
|
uint64_t cycle_last_frame = 0; |
|
|
|
|
|
|
|
uint64_t total_cycles = 0; |
|
|
|
for (int i = 0; i < n_loops && status == 0; ++i) { |
|
|
|
for (int i = 0; status == 0; ++i) { |
|
|
|
int run = 0; |
|
|
|
nes_ppu_Result result = nes_step(&sys, &run); |
|
|
|
total_cycles += run; |
|
|
|
@@ -122,7 +129,7 @@ int main(int argc, char* argv[]) { |
|
|
|
float ms_run = ( total_cycles * 1000. * |
|
|
|
nes_clock_master_den) / |
|
|
|
nes_clock_master_num; |
|
|
|
fprintf(stdout, "Ran %f ms, %lu master cycles (%s)\n", |
|
|
|
fprintf(stdout, "Ran %f ms, %"PRIu64" master cycles (%s)\n", |
|
|
|
ms_run, total_cycles, |
|
|
|
status == 0 ? "OK" : "Halted"); |
|
|
|
} |
|
|
|
|