commit 8b89546910d16965dac0807842306e77c9287762
parent 934636d6f440f339294b052a15024ce8bcb31e3b
Author: Christos Margiolis <christos@margiolis.net>
Date: Wed, 2 Sep 2020 15:46:44 +0300
removed typedef and removed private functions from header
Diffstat:
4 files changed, 21 insertions(+), 18 deletions(-)
diff --git a/Makefile b/Makefile
@@ -8,8 +8,10 @@ BIN_DIR = bin
SRC = $(wildcard $(SRC_DIR)/*.c)
OBJ = $(SRC:$(SRC_DIR)/%.c=$(OBJ_DIR)/%.o)
+CP=cp
MOVE = mv
MKDIR_P = mkdir -p
+RM_DIR=rm -rf
CC = gcc
CPPFLAGS += -Iinclude -pedantic
@@ -34,7 +36,7 @@ run:
./$(BIN_DIR)/$(TARGET)
install: $(TARGET)
- cp $(BIN_DIR)/$(TARGET) $(INSTALL_PATH)
+ $(CP) $(BIN_DIR)/$(TARGET) $(INSTALL_PATH)
clean:
- $(RM) $(OBJ) $(BIN_DIR)/$(TARGET)
+ $(RM_DIR) $(OBJ_DIR) $(BIN_DIR)
diff --git a/src/chip8.c b/src/chip8.c
@@ -13,8 +13,11 @@
#define soundtimer chip8->soundtimer
#define drawflag chip8->drawflag
+static int chip8_decode(struct Chip8 *chip8);
+static void chip8_timers_update(struct Chip8 *chip8);
+
void
-chip8_init(Chip8 *chip8)
+chip8_init(struct Chip8 *chip8)
{
uint8_t fontset[80] = {
0xF0, 0x90, 0x90, 0x90, 0xF0, // 0
@@ -50,7 +53,7 @@ chip8_init(Chip8 *chip8)
}
int
-chip8_rom_load(Chip8 *chip8, const char *fpath)
+chip8_rom_load(struct Chip8 *chip8, const char *fpath)
{
FILE *rom = fopen(fpath, "rb");
if (rom == NULL)
@@ -92,7 +95,7 @@ chip8_rom_load(Chip8 *chip8, const char *fpath)
}
void
-chip8_emulate(Chip8 *chip8)
+chip8_emulate(struct Chip8 *chip8)
{
opcode = memory[pc] << 8 | memory[pc + 1]; // fetch
if (chip8_decode(chip8))
@@ -105,7 +108,7 @@ chip8_emulate(Chip8 *chip8)
}
int
-chip8_decode(Chip8 *chip8)
+chip8_decode(struct Chip8 *chip8)
{
switch (opcode & 0xF000)
{
@@ -298,7 +301,7 @@ chip8_decode(Chip8 *chip8)
}
void
-chip8_timers_update(Chip8 *chip8)
+chip8_timers_update(struct Chip8 *chip8)
{
if (delaytimer > 0) --delaytimer;
if (soundtimer > 0) --soundtimer;
diff --git a/src/chip8.h b/src/chip8.h
@@ -10,7 +10,7 @@
#define TRUE 1
#define FALSE 0
-typedef struct {
+struct Chip8 {
uint8_t memory[4096];
uint8_t V[16];
uint8_t gfx[64 * 32];
@@ -23,14 +23,12 @@ typedef struct {
uint16_t opcode;
uint16_t I;
uint16_t pc;
-} Chip8;
+};
-extern Chip8 chip8;
+extern struct Chip8 chip8;
-extern void chip8_init(Chip8 *chip8);
-extern int chip8_rom_load(Chip8 *chip8, const char *fpath);
-extern void chip8_emulate(Chip8 *chip8);
-extern int chip8_decode(Chip8 *chip8);
-extern void chip8_timers_update(Chip8 *chip8);
+extern void chip8_init(struct Chip8 *chip8);
+extern int chip8_rom_load(struct Chip8 *chip8, const char *fpath);
+extern void chip8_emulate(struct Chip8 *chip8);
#endif /* CHIP8_H */
diff --git a/src/main.c b/src/main.c
@@ -11,7 +11,7 @@ static const uint8_t keymap[16] = {
};
static int
-evts(Chip8 *chip8)
+evts(struct Chip8 *chip8)
{
int i;
SDL_Event e;
@@ -31,7 +31,7 @@ evts(Chip8 *chip8)
}
static void
-render(SDL_Renderer *ren, SDL_Texture *tex, Chip8 *chip8)
+render(SDL_Renderer *ren, SDL_Texture *tex, struct Chip8 *chip8)
{
int i;
uint32_t pixels[2048];
@@ -76,7 +76,7 @@ main(int argc, char **argv)
return EXIT_FAILURE;
}
- Chip8 chip8;
+ struct Chip8 chip8;
chip8_init(&chip8);
if (!chip8_rom_load(&chip8, argv[1])) return EXIT_FAILURE;
for (; evts(&chip8); usleep(1500))