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
|
2019-09-22 08:31:09 +00:00
|
|
|
//#define dbgPrintf(format, ...) printf (format, ## __VA_ARGS__)
|
|
|
|
#define dbgPrintf(format, ...)
|
2019-09-17 09:12:05 +00:00
|
|
|
#define dbgPrintf2(format, ...) printf (format, ## __VA_ARGS__)
|
2019-07-30 08:05:21 +00:00
|
|
|
#else
|
|
|
|
#define dbgPrintf(format, ...)
|
2019-09-17 09:12:05 +00:00
|
|
|
#define dbgPrintf2(format, ...)
|
2019-07-30 08:05:21 +00:00
|
|
|
#endif
|
|
|
|
|
2019-09-09 07:27:31 +00:00
|
|
|
typedef enum {
|
2019-09-17 09:12:05 +00:00
|
|
|
NO_INT,
|
|
|
|
HLT,
|
2019-09-09 07:27:31 +00:00
|
|
|
NMI,
|
|
|
|
HARDRESET,
|
|
|
|
SOFTRESET,
|
|
|
|
} interrupt_t;
|
2019-07-30 08:05:21 +00:00
|
|
|
|
2019-09-22 08:31:09 +00:00
|
|
|
typedef enum {
|
|
|
|
NO_DEBUG,
|
|
|
|
DISASSEMBLY,
|
|
|
|
DEBUGBRK,
|
|
|
|
STEPBYSTEP,
|
|
|
|
} debugLevel_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
|
2019-09-15 11:02:22 +00:00
|
|
|
// union {
|
|
|
|
// uint8_t instr; // Instruction
|
|
|
|
// struct {
|
|
|
|
// uint8_t cc:2;
|
|
|
|
// uint8_t bbb:3;
|
|
|
|
// uint8_t aaa:3;
|
|
|
|
// };
|
|
|
|
// };
|
2019-07-30 08:05:21 +00:00
|
|
|
union {
|
2019-09-15 11:02:22 +00:00
|
|
|
uint8_t SR; // Status Register
|
2019-07-30 08:05:21 +00:00
|
|
|
struct {
|
|
|
|
uint8_t C:1; // Carry Flag
|
2019-09-15 11:02:22 +00:00
|
|
|
uint8_t Z:1; // Zero Flag
|
|
|
|
uint8_t I:1; // Interrupt Flag
|
|
|
|
uint8_t D:1; // Decimal Flag
|
|
|
|
uint8_t B:1; // B Flag
|
|
|
|
uint8_t res:1; // reserved -- should be always 1
|
|
|
|
uint8_t V:1; // Overflow Flag ???
|
|
|
|
uint8_t N:1; // Negative Flag
|
|
|
|
};
|
2019-07-30 08:05:21 +00:00
|
|
|
};
|
2019-09-15 11:02:22 +00:00
|
|
|
uint16_t PC; // Program Counter
|
|
|
|
uint8_t SP; // Stack Pointer ( stack addr = 0x01 + sp )
|
2019-07-30 08:05:21 +00:00
|
|
|
unsigned clk; // Clock Counter
|
2019-09-22 08:31:09 +00:00
|
|
|
debugLevel_t dbgLevel; // 0: No Debug, 1: Disassembly Only, 2: Run till BRK, 3: StepByStep
|
2019-09-09 07:27:31 +00:00
|
|
|
|
|
|
|
union {
|
2019-09-17 09:12:05 +00:00
|
|
|
unsigned int IF; // interrut flag
|
2019-09-09 07:27:31 +00:00
|
|
|
interrupt_t interrupt;
|
|
|
|
};
|
|
|
|
} m6502_t;
|
2019-07-30 08:05:21 +00:00
|
|
|
|
|
|
|
|
2019-09-22 08:31:09 +00:00
|
|
|
typedef struct disassembly_s {
|
|
|
|
char codeAddr[5]; // 4 digits + \0
|
|
|
|
char hex[4 * 3 + 1]; // max 4 bytes * (2 digits + 1 space) + \0
|
|
|
|
char * pHex;
|
|
|
|
char inst[6 + 1]; // 3 char (unknown instr? -- give it 6 chars) + \0
|
|
|
|
char addr[4 + 2 + 1 + 1 + 1]; // 4 digits + 2 brackets + 1 comma + 1 index + \0
|
|
|
|
char comment[256]; // to be able to add some comments
|
|
|
|
} disassembly_t;
|
|
|
|
|
|
|
|
|
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
|
|
|
|
2019-09-17 09:12:05 +00:00
|
|
|
extern double mips;
|
|
|
|
extern double mhz;
|
2019-09-22 08:31:09 +00:00
|
|
|
extern const unsigned int fps;
|
2019-07-30 08:05:21 +00:00
|
|
|
|
2019-09-17 09:12:05 +00:00
|
|
|
extern void tst6502();
|
|
|
|
extern void m6502_Reset();
|
|
|
|
extern void m6502_Run();
|
2019-09-22 08:31:09 +00:00
|
|
|
extern void kbdInput ( uint8_t code );
|
2019-07-30 08:05:21 +00:00
|
|
|
|
|
|
|
#endif /* __6502_H__ */
|