add 6502 CPU emu

This commit is contained in:
Thomas Bernard
2019-11-23 16:46:39 +01:00
parent 317239c9cf
commit 6d69200bc3
5 changed files with 144 additions and 1 deletions

2
src/.gitignore vendored
View File

@@ -1,2 +1,4 @@
recoil.c
recoil.h
6502.c
6502.h

85
src/6502types.h Normal file
View File

@@ -0,0 +1,85 @@
#ifndef F6502TYPES_H_INCLUDED
#define F6502TYPES_H_INCLUDED
#if defined(__BEOS__) || defined(__TRU64__)
#include <inttypes.h>
#else
#include <stdint.h>
#endif
typedef unsigned int zusize;
typedef uint8_t zuint8;
typedef uint16_t zuint16;
typedef uint8_t zboolean;
typedef unsigned int zuint;
typedef int8_t zsint8;
#ifndef NULL
#define NULL ((void *)0)
#endif
#ifndef FALSE
#define FALSE 0
#endif
#ifndef TRUE
#define TRUE 1
#endif
/* MARK: - Addresses */
#define Z_6502_ADDRESS_NMI_POINTER 0xFFFA
#define Z_6502_ADDRESS_RESET_POINTER 0XFFFC
#define Z_6502_ADDRESS_IRQ_POINTER 0xFFFE
#define Z_6502_ADDRESS_BRK_POINTER 0xFFFE
#define Z_6502_ADDRESS_STACK 0x0100
/* MARK: - Values after power on */
#define Z_6502_VALUE_AFTER_POWER_ON_PC 0x0000
#define Z_6502_VALUE_AFTER_POWER_ON_S 0xFD
#define Z_6502_VALUE_AFTER_POWER_ON_P 0x36
#define Z_6502_VALUE_AFTER_POWER_ON_A 0x00
#define Z_6502_VALUE_AFTER_POWER_ON_X 0x00
#define Z_6502_VALUE_AFTER_POWER_ON_Y 0x00
/* MARK: - State storage type */
typedef struct {
zuint16 pc;
zuint8 s, p, a, x, y;
struct {zuint8 irq :1;
zuint8 nmi :1;
} internal;
} Z6502State;
#define Z_6502_STATE_PC( object) (object)->pc
#define Z_6502_STATE_S( object) (object)->s
#define Z_6502_STATE_P( object) (object)->p
#define Z_6502_STATE_A( object) (object)->a
#define Z_6502_STATE_X( object) (object)->x
#define Z_6502_STATE_Y( object) (object)->y
#define Z_6502_STATE_NMI(object) (object)->internal.nmi
#define Z_6502_STATE_IRQ(object) (object)->internal.irq
#define Z_6502_STATE_MEMBER_PC pc
#define Z_6502_STATE_MEMBER_S s
#define Z_6502_STATE_MEMBER_P p
#define Z_6502_STATE_MEMBER_A a
#define Z_6502_STATE_MEMBER_X x
#define Z_6502_STATE_MEMBER_Y y
#define Z_6502_STATE_MEMBER_NMI internal.nmi
#define Z_6502_STATE_MEMBER_IRQ internal.irq
#ifdef __cplusplus
# define Z_C_SYMBOLS_BEGIN extern "C" {
# define Z_C_SYMBOLS_END }
#else
# define Z_C_SYMBOLS_BEGIN
# define Z_C_SYMBOLS_END
#endif
#define Z_INLINE
#define Z_EMPTY_(dummy)
#define Z_EMPTY Z_EMPTY_(.)
#endif

View File

@@ -1160,6 +1160,17 @@ $(OBJDIR)/loadrecoil.o: recoil.c recoil.h
if [ -d ../3rdparty ] ; then $(MAKE) -C ../3rdparty recoil ; fi
endif
6502.h: 6502.c
6502.c: ../3rdparty/6502/sources/6502.c
$(CP) $< $@
$(CP) ../3rdparty/6502/API/emulation/CPU/6502.h 6502.h
../3rdparty/6502/sources/6502.c:
if [ -d ../3rdparty ] ; then $(MAKE) -C ../3rdparty 6502 ; fi
$(OBJDIR)/6502.o: CFLAGS += -DCPU_6502_STATIC -DCPU_6502_USE_LOCAL_HEADER -DCPU_6502_DEPENDENCIES_H=\"6502types.h\"
$(OBJ): $(CFLAGS_CACHE)
$(OBJDIR)/%.o : %.c