-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
cpu_cisc.h
162 lines (127 loc) · 3.11 KB
/
cpu_cisc.h
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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
#pragma once
#ifndef __CPU_CISC_H
#define __CPU_CISC_H
//
// Memory map
//
// interrupt vectors
#define RESET_VECTOR 0xFFFE // addr of reset interrupt handler
#define INT_VECTOR 0xFFFC // addr of timer interrupt handler
#define SWI_VECTOR 0xFFFA // addr of software interrupt handler
#define BRK_VECTOR 0xFFF8 // addr of breakpoint interrupt
// MMIO
#define MMIO_TIMER_REG 0xFF00 // current value of timer
#define MMIO_TIMER_ENA 0xFF01 // timer enabled/disabled
#define MMIO_TIMER_LIM 0xFF02 // timer limit
#define RAM_END 0xFE00 // above this address is reserved (e.g. MMIO, interrupt vectors)
//
// Machine word sizes
//
#define BYTE_SIZE 1
#define WORD_SIZE 2
#define DWORD_SIZE 4
// Opcodes
enum
{
OP_NOP, // no operation
// arithmetic
OP_ADD, // A = A + memory
OP_ADDI, // A = A + immediate
OP_ADC, // A = A + memory + C
OP_ADCI, // A = A + immediate + C
OP_AAX, // X = X + A
OP_AAY, // Y = Y + A
OP_SUB, // A = A - memory
OP_SUBI, // A = A - immediate
OP_SBB, // A = A - memory - C
OP_SBBI, // A = A - immediate - C
OP_CMP, // temp = A - memory
OP_CMPI, // temp = A - immediate
OP_CMPX, // temp = X - memory
OP_CMPXI, // temp = X - immediate
OP_CMPY, // temp = Y - memory
OP_CMPYI, // temp = Y - immediate
// logical
OP_AND,
OP_ANDI,
OP_OR,
OP_ORI,
OP_NOT, // A = ~A
OP_XOR,
OP_XORI,
//OP_ROL,
// OP_ROR,
OP_SHL, // A <<= 1
OP_SHR, // A >>= 1
// branching
OP_CALL, // branch to a function
OP_RET, // return from function
OP_RTI, // return from interrupt
OP_JMP, // unconditional jump
OP_JNE, // jump if not equal
OP_JEQ, // jump if equal
OP_JGT, // jump if greater than
OP_JLT, // jump if less than
// loads and stores
OP_LDA, // load A from memory
OP_LDAI, // load A from immediate value
OP_LDX, // load X from memory
OP_LDY, // load Y from memory
OP_LDXI, // load X from immediate value
OP_LDYI, // load Y from immediate value
OP_LEAX, // load X = X + immediate value
OP_LEAY, // load Y = Y + immediate value
OP_LAX, // load A from [X]
OP_LAY, // load A from [Y]
OP_LXX, // load X from [X]
OP_LYY, // load X from [Y]
OP_STA, // store A to memory
OP_STX, // store X to memory
OP_STY, // store Y to memory
OP_STAX, // store A to [X]
OP_STAY, // store A to [Y]
OP_STYX, // store Y to [X]
OP_STXY, // store X to [Y]
// stack
OP_PUSH, // push one or more registers on the stack
OP_POP, // pop one or more registers from the stack
// IO
OP_OUT, // output a byte to a port
OP_IN, // input a byte from a port
// software interrupts
OP_BRK, // breakpoint interrupt
OP_SWI, // software interrupt
};
//
// Register bit definitions
//
enum
{
REG_A = 1, // bit 0
REG_X = 2, // bit 1
REG_Y = 4, // bit 2
REG_SP = 8, // bit 3
REG_CC = 16, // bit 4
REG_PC = 32 // bit 5
};
//
// Flag bit definitions
//
enum
{
FLAG_C = 1, // carry flag, bit 0
FLAG_Z = 2, // zero flag, bit 1
FLAG_V = 4, // overflow flag, bit 2
FLAG_N = 8, // negative flag, bit 3
FLAG_I = 16, // interrupt flag, bit 4
FLAG_S = 32, // single step flag, bit 5
FLAG_ALL = 0xFF
};
//
// Interrupt definitions
//
enum
{
INT_TIMER = 1
};
#endif // __CPU_CISC_H