-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathf4.h
52 lines (44 loc) · 1.18 KB
/
f4.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
#ifndef F4CPU_H
#define F4CPU_H
#include <stdbool.h>
// http://www.dakeng.com/misc.html
// word size. For now 16bit
typedef unsigned short int w_size;
// The state of cpu. Should be filled initially
struct STATE{
w_size a; // A register. Accumulator
w_size pc; // Program Counter
bool overflow; // overflow flag
// Non F4 CPU specific data
unsigned int size; // size of code in words (w_size - 16 bit currently)
struct INSTR *code; // pointer to code array
};
// possible CPU instructions
enum INSTRUCTIONS{
ADDi=1, // imm+(A) --> A
ADDm, // (addr)+(A) --> A
ADDpc, // PC+(A) --> A
BVS, // (addr) --> PC if <v>=1
LDAi, // imm --> A
LDAm, // (addr) --> A
LDApc, // PC --> A
STAm, // A --> (addr)
STApc // A --> PC
};
#define NO_PARAM 0 // to pass no parameters
// format of one instruction
struct INSTR{
w_size cmd; //INSTRUCTIONS
w_size param; // 16 bit , 0 in case no param
};
/* Run one cpu iteration
Input:
STATE - CPU current state
Return:
0 - SUCCESS
1 - ERROR
*/
int RunIteration(struct STATE *);
/* Reset to zero/default values */
void Reset(struct STATE *);
#endif