mirror of
https://github.com/andwati/mos-6502.git
synced 2026-10-18 03:02:51 +00:00
implement Makefile and CPU module with reset and state print functions; update .gitignore to exclude build artifacts
This commit is contained in:
@@ -74,4 +74,7 @@ dkms.conf
|
||||
.history
|
||||
.ionide
|
||||
|
||||
bin/
|
||||
build/
|
||||
|
||||
# End of https://www.toptal.com/developers/gitignore/api/c,visualstudiocode
|
||||
|
||||
@@ -0,0 +1,32 @@
|
||||
cc := gcc
|
||||
CFLAGS := -std=c11 -Wall -Wextra -Wpedantic -O2
|
||||
CFLAGS_DEBUG := -std=c11 -Wall -Wextra -Wpedantic -g -O0
|
||||
|
||||
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)
|
||||
|
||||
all: $(TARGET)
|
||||
|
||||
$(TARGET): $(OBJ)
|
||||
@mkdir -p $(BIN_DIR)
|
||||
$(cc) $(OBJ) -o $(TARGET)
|
||||
|
||||
$(BUILD_DIR)/%.o: $(SRC_DIR)/%.c
|
||||
@mkdir -p $(BUILD_DIR)
|
||||
@mkdir -p $(dir $@)
|
||||
$(cc) $(CFLAGS) -c $< -o $@
|
||||
|
||||
debug: CFLAGS=$(CFLAGS_DEBUG)
|
||||
debug: clean $(TARGET)
|
||||
|
||||
clean:
|
||||
rm -rf $(BUILD_DIR) $(BIN_DIR)
|
||||
|
||||
rebuild: clean all
|
||||
.PHONY: all clean rebuild debug
|
||||
@@ -0,0 +1,23 @@
|
||||
#include <stdio.h>
|
||||
#include "cpu.h"
|
||||
|
||||
void cpu_reset(CPU6502 *cpu)
|
||||
{
|
||||
cpu->A = 0;
|
||||
cpu->X = 0;
|
||||
cpu->Y = 0;
|
||||
cpu->SP = 0xFD; // typical 6502 reset value??
|
||||
cpu->P = FLAG_U; // unused flag always 1
|
||||
cpu->PC = 0x0000; // loaded later from reset vector
|
||||
}
|
||||
|
||||
void cpu_print_state(CPU6502 *cpu)
|
||||
{
|
||||
printf("CPU State:\n");
|
||||
printf("A: 0x%02X\n", cpu->A);
|
||||
printf("X: 0x%02X\n", cpu->X);
|
||||
printf("Y: 0x%02X\n", cpu->Y);
|
||||
printf("SP: 0x%02X\n", cpu->SP);
|
||||
printf("PC: 0x%04X\n", cpu->PC);
|
||||
printf("P: 0x%02X\n", cpu->P);
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
#ifndef CPU_H
|
||||
#define CPU_H
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
typedef struct
|
||||
{
|
||||
uint8_t A; // accumulator
|
||||
uint8_t X; // index X
|
||||
uint8_t Y; // index y
|
||||
uint8_t SP; // stack pointer
|
||||
uint8_t PC; // program counter
|
||||
uint8_t P; // status flags
|
||||
} CPU6502;
|
||||
|
||||
// status flag masks
|
||||
#define FLAG_C 0x01
|
||||
#define FLAG_Z 0x02
|
||||
#define FLAG_I 0x04
|
||||
#define FLAG_D 0x08
|
||||
#define FLAG_B 0x10
|
||||
#define FLAG_U 0x20
|
||||
#define FLAG_V 0x40
|
||||
#define FLAG_N 0x80
|
||||
|
||||
void cpu_reset(CPU6502 *cpu);
|
||||
void cpu_print_state(CPU6502 *cpu);
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user