From 1a3647c557fa4fe0fa4fa1229615eefc655eade1 Mon Sep 17 00:00:00 2001 From: andwati Date: Sun, 21 Dec 2025 18:52:11 +0300 Subject: [PATCH] refactor Makefile and update CPU struct: rename stack pointer field for clarity --- Makefile | 38 ++++++++++++++------------------------ include/cpu.h | 2 +- 2 files changed, 15 insertions(+), 25 deletions(-) diff --git a/Makefile b/Makefile index 20f97e2..ba973b9 100644 --- a/Makefile +++ b/Makefile @@ -1,32 +1,22 @@ -cc := gcc -CFLAGS := -std=c11 -Wall -Wextra -Wpedantic -O2 -CFLAGS_DEBUG := -std=c11 -Wall -Wextra -Wpedantic -g -O0 +CC = gcc +CFLAGS = -Wall -Wextra -O3 -Iinclude +SRC_DIR = src +OBJ_DIR = build +BIN_DIR = bin -SRC_DIR := src -BUILD_DIR := build -BIN_DIR := bin - -TARGET := $(BIN_DIR)/mos6502 - -SRC := $(shell find $(SRC_DIR) -name '*.c') -OBJ := $(SRC:$(SRC_DIR)/%.c=$(BUILD_DIR)/%.o) +SOURCES = $(wildcard $(SRC_DIR)/*.c) +OBJECTS = $(SOURCES:$(SRC_DIR)/%.c=$(OBJ_DIR)/%.o) +TARGET = $(BIN_DIR)/mos6502 all: $(TARGET) -$(TARGET): $(OBJ) +$(TARGET): $(OBJECTS) @mkdir -p $(BIN_DIR) - $(cc) $(OBJ) -o $(TARGET) + $(CC) $(OBJECTS) -o $@ -$(BUILD_DIR)/%.o: $(SRC_DIR)/%.c - @mkdir -p $(BUILD_DIR) - @mkdir -p $(dir $@) - $(cc) $(CFLAGS) -c $< -o $@ - -debug: CFLAGS=$(CFLAGS_DEBUG) -debug: clean $(TARGET) +$(OBJ_DIR)/%.o: $(SRC_DIR)/%.c + @mkdir -p $(OBJ_DIR) + $(CC) $(CFLAGS) -c $< -o $@ clean: - rm -rf $(BUILD_DIR) $(BIN_DIR) - -rebuild: clean all -.PHONY: all clean rebuild debug \ No newline at end of file + rm -rf $(OBJ_DIR) $(BIN_DIR) \ No newline at end of file diff --git a/include/cpu.h b/include/cpu.h index 235da9c..d936646 100644 --- a/include/cpu.h +++ b/include/cpu.h @@ -8,7 +8,7 @@ typedef struct uint8_t A; // accumulator uint8_t X; // index X uint8_t Y; // index y - uint8_t S; // stack pointer + uint8_t SP; // stack pointer uint8_t PC; // program counter uint8_t P; // status flags } CPU6502;