started to work in memory
This commit is contained in:
parent
73a23407e4
commit
c70bbca209
6
Makefile
6
Makefile
@ -3,7 +3,7 @@ ECHO=echo -e
|
||||
CFLAGS=-Wall -Werror -std=gnu99 -O0 -g -Iinclude
|
||||
LIBS=-lSDL2
|
||||
|
||||
FILES=build/main.o
|
||||
FILES=build/main.o build/mem.o
|
||||
OUT=bin/chip8.out
|
||||
|
||||
all: $(FILES)
|
||||
@ -14,6 +14,10 @@ build/main.o: src/main.c
|
||||
@$(ECHO) "CC\t\t"$<
|
||||
@$(CC) $(CFLAGS) $< -c -o $@ $(LIBS)
|
||||
|
||||
build/mem.o: src/mem.c
|
||||
@$(ECHO) "CC\t\t"$<
|
||||
@$(CC) $(CFLAGS) $< -c -o $@ $(LIBS)
|
||||
|
||||
run: all
|
||||
@$(ECHO) "Runing the Chip8 compiler"
|
||||
@$(OUT)
|
||||
|
@ -2,9 +2,11 @@
|
||||
#define __CHIP8_H
|
||||
|
||||
#include "config.h"
|
||||
#include "mem.h"
|
||||
|
||||
struct chip8
|
||||
{
|
||||
struct chip8_memory memory;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
14
include/mem.h
Normal file
14
include/mem.h
Normal file
@ -0,0 +1,14 @@
|
||||
#ifndef __MEM_H
|
||||
#define __MEM_H
|
||||
|
||||
#include "config.h"
|
||||
|
||||
struct chip8_memory
|
||||
{
|
||||
unsigned char memory[CHIP8_MEMORY_SIZE];
|
||||
};
|
||||
|
||||
void chip8_memory_set (struct chip8_memory *mem, int index, unsigned char val);
|
||||
unsigned char chip8_memory_get (struct chip8_memory *mem, int index);
|
||||
|
||||
#endif
|
@ -5,6 +5,10 @@
|
||||
int
|
||||
main (int argc, char **argv)
|
||||
{
|
||||
struct chip8 chip8 = { 0 };
|
||||
chip8_memory_set (&chip8.memory, 50, 'Z');
|
||||
printf ("%c\n", chip8_memory_get (&chip8.memory, 50));
|
||||
|
||||
SDL_Init (SDL_INIT_EVERYTHING);
|
||||
SDL_Window *window = SDL_CreateWindow (
|
||||
EMULATOR_WINDOW_TITLE, SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED,
|
||||
|
23
src/mem.c
Normal file
23
src/mem.c
Normal file
@ -0,0 +1,23 @@
|
||||
#include "mem.h"
|
||||
|
||||
#include <assert.h>
|
||||
|
||||
static void
|
||||
chip8_is_mem_in_bounds (int index)
|
||||
{
|
||||
assert (index >= 0 && index < CHIP8_MEMORY_SIZE);
|
||||
}
|
||||
|
||||
void
|
||||
chip8_memory_set (struct chip8_memory *mem, int index, unsigned char val)
|
||||
{
|
||||
chip8_is_mem_in_bounds (index);
|
||||
mem->memory[index] = val;
|
||||
}
|
||||
|
||||
unsigned char
|
||||
chip8_memory_get (struct chip8_memory *mem, int index)
|
||||
{
|
||||
chip8_is_mem_in_bounds (index);
|
||||
return mem->memory[index];
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user