diff --git a/Notes.org b/Notes.org index 0d77595..010c06b 100644 --- a/Notes.org +++ b/Notes.org @@ -29,6 +29,27 @@ Chip-8 has a stack that is an array of 16 16-bit values, used to store the addresses that the Chip8 should return to when returning from a subroutine, meaning there can be 16 levels of nested subroutines. +*** The Character Set + +The Chip8 contains some sprites, called /character set/ which are a group of +sprites representing the hexadecimal digits from 0 to F. They are 5 bytes long +(8x5 pixels). They are stored in the area reserved for Chip8 (0x00-0x1FF). + +The following are some examples: + +#+begin_src artist + +----+--------+----+ +----+--------+----+ + |"0" |Binary |Hex | |"1" |Binary |Hex | + +----+--------+----| +----+--------+----+ + |****|11110000|0xF0| | 1 |00100000|0x20| + |* *|10010000|0x90| | 11 |01100000|0x60| + |* *|10010000|0x90| | 1 |00100000|0x20| + |* *|10010000|0x90| | 1 |00100000|0x20| + |****|11110000|0xF0| | 111|01110000|0x70| + +----+--------+----+ +----+--------+----+ +#+end_src + + ** Registers Chip8 has 16 8-bit data registers, each can hold 1 byte of information. diff --git a/include/config.h b/include/config.h index 39a2e1a..602532d 100644 --- a/include/config.h +++ b/include/config.h @@ -12,4 +12,6 @@ #define CHIP8_TOTAL_STACK_DEPTH 16 #define CHIP8_TOTAL_KEYS 16 +#define CHIP8_CHARACTER_SET_LOAD_ADDRESS 0x00 + #endif diff --git a/src/chip8.c b/src/chip8.c index 5cd565f..102e932 100644 --- a/src/chip8.c +++ b/src/chip8.c @@ -1,8 +1,28 @@ #include "chip8.h" #include +const char chip8_default_character_set[] = { + 0xf0, 0x90, 0x90, 0x90, 0xf0, // 1 + 0x20, 0x60, 0x20, 0x20, 0x70, // 2 + 0xf0, 0x10, 0xf0, 0x80, 0xf0, // 3 + 0xf0, 0x10, 0xf0, 0x10, 0xf0, // 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 +}; + void chip8_init (struct chip8 *chip8) { memset (chip8, 0, sizeof (struct chip8)); + memcpy (&chip8->memory.memory, chip8_default_character_set, + sizeof (chip8_default_character_set)); }