forked from haldean/x6502
-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathcpu.h
More file actions
81 lines (71 loc) · 1.94 KB
/
Copy pathcpu.h
File metadata and controls
81 lines (71 loc) · 1.94 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
#ifndef __6502_CPU__
#define __6502_CPU__
#include <stdint.h>
#include <stdbool.h>
#include "via.h"
#include "lcd.h"
#include "keys.h"
#define MEMORY_SIZE 65536
#define STACK_START 0x0100
#define FLAG_NEGATIVE 0x80
#define FLAG_OVERFLOW 0x40
#define FLAG_BREAK 0x10
#define FLAG_DECIMAL 0x08
#define FLAG_INTERRUPT 0x04
#define FLAG_ZERO 0x02
#define FLAG_CARRY 0x01
// set if memory was modified during processing of the last instruction
#define EMU_FLAG_DIRTY 0x01
// set if the emulator should wait for an interrupt before continuing
#define EMU_FLAG_WAIT_FOR_INTERRUPT 0x02
#define CLOCK_SPRINT 0x00
#define CLOCK_TURBO 0x01
#define CLOCK_FAST 0x02
#define CLOCK_SLOW 0x04
#define CLOCK_STEP 0x08
typedef struct {
// clock mode
uint8_t clock_mode;
// program counter
uint16_t pc;
// flag indicating whether instruction set new pc
bool pc_set;
// actual value of program counter
uint16_t pc_actual;
// current opcode
uint8_t opcode;
// index registers
uint8_t x, y;
// stack pointer
uint8_t sp;
// accumulator
uint8_t ac;
// status register
uint8_t sr;
// emulator flag register (not in 6502 spec, not accessible from assembler)
uint8_t emu_flags;
// set to nonzero if there is an outstanding interrupt
uint8_t interrupt_waiting;
// RAM
uint8_t mem[MEMORY_SIZE];
// stores the address of memory modified by the last instruction
uint16_t dirty_mem_addr;
// cycle counter
uint32_t cycle;
//
bool lcd_8_bit;
// VIA1 subsystem
via* v1;
// LCD
lcd* l;
// keys
keys* k;
// whether we should switch to clock mode STEP when the next NOP is encountered
bool run_to_nop;
// if >0, will be incremented/decremented when encountering JSR/RTS respectively and we'll switch to
// STEP when it's decremented to zero, allowing "run until return"
int run_to_ret;
} cpu;
cpu * new_cpu();
void destroy_cpu(cpu* m);
#endif