You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
42 lines
819 B
42 lines
819 B
|
|
#include "chip.h" |
|
|
|
#include <stdio.h> |
|
#include <unistd.h> |
|
|
|
int main(int argc, char **argv) { |
|
|
|
emu_state state = {}; |
|
|
|
if (argc < 2) { |
|
printf("No program given.\n"); |
|
return 1; |
|
} |
|
|
|
initialize(&state); |
|
FILE *f = fopen(argv[1], "r"); |
|
size_t err = 0; |
|
size_t bytes = 0; |
|
|
|
do { |
|
err = fread(state.memory.main_memory, sizeof(char), |
|
sizeof(state.memory.main_memory), f); |
|
bytes += err; |
|
} while (err > 0); |
|
fclose(f); |
|
printf("Read bytes %ld\n", bytes); |
|
|
|
info("Read program in"); |
|
hexdump(state.memory.all_memory, sizeof(state.memory.all_memory)); |
|
|
|
print_display(&state.display); |
|
info("Starting."); |
|
|
|
while (!chip_errored) { |
|
loop(&state); |
|
usleep(3000); |
|
} |
|
|
|
// hexdump(state.memory.all_memory, sizeof(state.memory.all_memory)); |
|
print_display(&state.display); |
|
}
|
|
|