diff options
author | Manuel Palenzuela <manuelpalenzuelamerino@gmail.com> | 2021-07-19 14:54:33 +0100 |
---|---|---|
committer | Manuel Palenzuela <manuelpalenzuelamerino@gmail.com> | 2021-07-19 14:54:33 +0100 |
commit | d0737d93433f09d9d1024d768a5c97b83f311a6a (patch) | |
tree | 4c564fd8b23c4842d2609ecca2d18b9243291d3d | |
parent | Misc: Load roms after 0x200 (diff) | |
download | CHIP8-Emulator-d0737d93433f09d9d1024d768a5c97b83f311a6a.tar.gz CHIP8-Emulator-d0737d93433f09d9d1024d768a5c97b83f311a6a.tar.bz2 CHIP8-Emulator-d0737d93433f09d9d1024d768a5c97b83f311a6a.zip |
Feature: Added a font
-rw-r--r-- | emulator.c | 26 | ||||
-rw-r--r-- | emulator.h | 4 | ||||
-rw-r--r-- | main.c | 4 |
3 files changed, 32 insertions, 2 deletions
diff --git a/emulator.c b/emulator.c index 699999c..1c02036 100644 --- a/emulator.c +++ b/emulator.c @@ -1,5 +1,31 @@ #include <emulator.h> +int emulator_initialise(Emulator* emulator) +{ + uint8_t font[] = { + 0xF0, 0x90, 0x90, 0x90, 0xF0, // 0 + 0x20, 0x60, 0x20, 0x20, 0x70, // 1 + 0xF0, 0x10, 0xF0, 0x80, 0xF0, // 2 + 0xF0, 0x10, 0xF0, 0x10, 0xF0, // 3 + 0x90, 0x90, 0xF0, 0x10, 0x10, // 4 + 0xF0, 0x80, 0xF0, 0x10, 0xF0, // 5 + 0xF0, 0x80, 0xF0, 0x90, 0xF0, // 6 + 0xF0, 0x10, 0x20, 0x40, 0x40, // 7 + 0xF0, 0x90, 0xF0, 0x90, 0xF0, // 8 + 0xF0, 0x90, 0xF0, 0x10, 0xF0, // 9 + 0xF0, 0x90, 0xF0, 0x90, 0x90, // A + 0xE0, 0x90, 0xE0, 0x90, 0xE0, // B + 0xF0, 0x80, 0x80, 0x80, 0xF0, // C + 0xE0, 0x90, 0x90, 0x90, 0xE0, // D + 0xF0, 0x80, 0xF0, 0x80, 0xF0, // E + 0xF0, 0x80, 0xF0, 0x80, 0x80 // F + }; + + memcpy(emulator->memory + 0x50, font, sizeof(font)); + + return 0; +} + int emulator_load_rom(Emulator* emulator, char* rom_name) { printf("load rom!: %s\n", rom_name); diff --git a/emulator.h b/emulator.h index b685bea..cfbbeff 100644 --- a/emulator.h +++ b/emulator.h @@ -2,7 +2,8 @@ #define _EMULATOR_H_ #include <stdio.h> -#include <sys/stat.h> +#include <sys/stat.h> +#include <string.h> typedef struct { @@ -37,6 +38,7 @@ typedef struct uint8_t memory[4096]; } Emulator; +int emulator_initialise(Emulator* emulator); int emulator_load_rom(Emulator* emulator, char* rom_name); int emulator_tick(Emulator* emulator); diff --git a/main.c b/main.c index 48d35ee..7c5a2fc 100644 --- a/main.c +++ b/main.c @@ -16,6 +16,8 @@ int main(int argc, char** argv) Emulator emulator; + emulator_initialise(&emulator); + if(emulator_load_rom(&emulator, argv[1]) != 0) return 2; @@ -23,7 +25,7 @@ int main(int argc, char** argv) for(int i = 0; i < sizeof(emulator.memory); ++i) { - printf("%c ", emulator.memory[i]); + printf("0x%x ", emulator.memory[i]); } putchar('\n'); |