src/main.c
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
/* x1phosura 2021 */ #include <assert.h> #include <stdbool.h> #include <stdint.h> #include <stdio.h> #include <stdlib.h> #include <string.h> #include "vm.h" #include "rom.h" // automatically generated from rom.bin by `make` int main() { char user_input[64]; uint8_t *memory = NULL; struct CPU cpu; // believe me, I _really_ tried to put the below calloc() in vm_init() memory = calloc(RAM_SIZE, sizeof(uint8_t)); if (memory == NULL) perror("Failed to allocate memory. Aborting..."); // src_rom_bin* comes from "rom.h", generated by make from rom.bin vm_init(&cpu, memory, src_rom_bin, src_rom_bin_len); printf("Type in any user input here: "); fgets(user_input, 63, stdin); user_input[strcspn(user_input, "\n")] = 0; // trim trailing newline //printf("User input: %s\n\n", user_input); for (uint8_t i = 0; i < strlen(user_input); ++i) memory[128+i] = (uint8_t)user_input[i]; #ifdef TRACE printf("[DEBUG MODE]: Running VM in debugger...\n"); #endif vm_run(&cpu, memory); // Note: once the emulator's finished, you can check results by reading // memory[], which is the emulator's "RAM" free(memory); return EXIT_SUCCESS; } |