2019-07-30 08:05:21 +00:00
|
|
|
//
|
|
|
|
// 6502.h
|
|
|
|
// 6502
|
|
|
|
//
|
|
|
|
// Created by Tamas Rudnai on 7/22/19.
|
|
|
|
// Copyright © 2019 GameAlloy. All rights reserved.
|
|
|
|
//
|
|
|
|
|
|
|
|
#ifndef __6502_H__
|
|
|
|
#define __6502_H__
|
|
|
|
|
|
|
|
#import "stdint.h"
|
|
|
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
#define dbgPrintf(format, ...) printf (format, ## __VA_ARGS__)
|
|
|
|
#else
|
|
|
|
#define dbgPrintf(format, ...)
|
|
|
|
#endif
|
|
|
|
|
2019-09-09 07:27:31 +00:00
|
|
|
typedef enum {
|
|
|
|
NMI,
|
|
|
|
HARDRESET,
|
|
|
|
SOFTRESET,
|
|
|
|
} interrupt_t;
|
2019-07-30 08:05:21 +00:00
|
|
|
|
|
|
|
typedef struct m6502_s {
|
|
|
|
uint8_t A; // Accumulator
|
|
|
|
uint8_t X; // X index register
|
|
|
|
uint8_t Y; // Y index register
|
|
|
|
union {
|
|
|
|
uint8_t instr; // Instruction
|
|
|
|
struct {
|
|
|
|
uint8_t aaa:3;
|
|
|
|
uint8_t bbb:3;
|
|
|
|
uint8_t cc:2;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
union {
|
|
|
|
uint8_t sr; // Status Register as 1 byte
|
|
|
|
struct {
|
|
|
|
uint8_t N:1; // Negative Flag
|
|
|
|
uint8_t V:1; // Overflow Flag ???
|
|
|
|
uint8_t B:2; // B Flag
|
|
|
|
uint8_t D:1; // Decimal Flag
|
|
|
|
uint8_t I:1; // Interrupt Flag
|
|
|
|
uint8_t Z:1; // Zero Flag
|
|
|
|
uint8_t C:1; // Carry Flag
|
|
|
|
} flags; // Status Register
|
|
|
|
};
|
|
|
|
uint16_t pc; // Program Counter
|
2019-09-10 07:00:00 +00:00
|
|
|
uint8_t sp; // Stack Pointer ( stack addr = 0x01 + sp )
|
2019-07-30 08:05:21 +00:00
|
|
|
unsigned clk; // Clock Counter
|
2019-09-09 07:27:31 +00:00
|
|
|
|
|
|
|
union {
|
|
|
|
int interrupt_flag;
|
|
|
|
interrupt_t interrupt;
|
|
|
|
};
|
|
|
|
} m6502_t;
|
2019-07-30 08:05:21 +00:00
|
|
|
|
|
|
|
|
2019-09-09 07:27:31 +00:00
|
|
|
extern m6502_t m6502;
|
2019-09-07 23:18:05 +00:00
|
|
|
extern uint8_t RAM[ 64 * 1024 ];
|
2019-07-30 08:05:21 +00:00
|
|
|
|
|
|
|
extern void tst6502();
|
|
|
|
|
|
|
|
|
|
|
|
#endif /* __6502_H__ */
|