8080-Emulator  0.1
An Intel 8080 emulator for Space Invaders
cpu_8080.h
Go to the documentation of this file.
1 
9 #ifndef CPU_8080_H
10 #define CPU_8080_H
11 
12 #include <inttypes.h>
13 #include "memory_8080.h"
14 
16 #define UNUSED __attribute__((unused))
17 
22 typedef struct {
23  uint8_t carry;
24  uint8_t aux;
25  uint8_t sign;
26  uint8_t zero;
27  uint8_t parity;
29 
34 typedef enum {
35  SIGN_FLAG = 1 << 0,
36  ZERO_FLAG = 1 << 1,
37  AUX_FLAG = 1 << 3,
38  PARITY_FLAG = 1 << 5,
39  CARRY_FLAG = 1 << 7,
40 } flag_bits;
42 # define ALL_BUT_AUX_FLAG (SIGN_FLAG | ZERO_FLAG | PARITY_FLAG | CARRY_FLAG)
43 
48 typedef enum {
49  NZ_check = 0x0,
50  Z_check = 0x1,
51  NC_check = 0x2,
52  C_check = 0x3,
53  PO_check = 0x4,
54  PE_check = 0x5,
55  P_check = 0x6,
56  M_check = 0x7,
58 
63 typedef struct {
65 
66  union{
67  struct {
68  uint8_t C;
69  uint8_t B;
70  uint8_t E;
71  uint8_t D;
72  uint8_t L;
73  uint8_t H;
74  };
75  struct {
76  uint16_t BC;
77  uint16_t DE;
78  uint16_t HL;
79  };
80  };
82  // TODO: Add The memory ref reg 6!?
83  uint8_t ACC;
87 
88  uint16_t SP;
89  uint16_t PC;
90  uint8_t intt; //(Don't know if works)
91  uint8_t pend_intt;
93 
95 
96  uint8_t (*IN_Func)(uint8_t);
97  void (*OUT_Func)(uint8_t, uint8_t);
99 
101 
103  uint16_t rom_size;
104  uint8_t halt;
106 } cpu_state;
107 
122 cpu_state* init_cpu_8080(uint16_t pc, uint8_t (*in_cb)(uint8_t), void (*out_cb)(uint8_t, uint8_t));
123 
130 int exec_inst(cpu_state* cpu);
131 
139 int decompile_inst(cpu_state* cpu, uint16_t* next_inst);
140 
147 void io_machine_OUT(uint8_t port, uint8_t data);
148 
155 uint8_t io_machine_IN(uint8_t port);
156 
162 void print_state(const cpu_state cpu);
163 
164 #endif
condition_flags
different condition checks for JMP, conditional OPS
Definition: cpu_8080.h:48
@ P_check
Definition: cpu_8080.h:55
@ NC_check
Definition: cpu_8080.h:51
@ PO_check
Definition: cpu_8080.h:53
@ NZ_check
Definition: cpu_8080.h:49
@ M_check
Definition: cpu_8080.h:56
@ C_check
Definition: cpu_8080.h:52
@ Z_check
Definition: cpu_8080.h:50
@ PE_check
Definition: cpu_8080.h:54
void io_machine_OUT(uint8_t port, uint8_t data)
Function to write data to the IO port.
flag_bits
ENUMS for PSW_FLAGS.
Definition: cpu_8080.h:34
void print_state(const cpu_state cpu)
Print the state of CPU.
Definition: cpu_8080.c:113
cpu_state * init_cpu_8080(uint16_t pc, uint8_t(*in_cb)(uint8_t), void(*out_cb)(uint8_t, uint8_t))
Initialize a new cpu_8080 instance structure. Everything is initialized to 0.
Definition: cpu_8080.c:18
int decompile_inst(cpu_state *cpu, uint16_t *next_inst)
Recompile mode.
Definition: cpu_8080.c:69
int exec_inst(cpu_state *cpu)
Executes the instruction pc is pointing to after incrementing it.
Definition: cpu_8080.c:36
uint8_t io_machine_IN(uint8_t port)
Function to read a byte of data from the port.
Memory abstraction for 8080 cpu.
cpu_state: This structure keeps runtime state of all the registers in the CPU.
Definition: cpu_8080.h:63
uint16_t SP
Definition: cpu_8080.h:88
uint8_t D
Definition: cpu_8080.h:71
uint16_t rom_size
Definition: cpu_8080.h:103
uint16_t BC
Definition: cpu_8080.h:76
uint8_t H
Definition: cpu_8080.h:73
uint8_t L
Definition: cpu_8080.h:72
uint8_t pend_intt
Definition: cpu_8080.h:91
uint8_t E
Definition: cpu_8080.h:70
uint16_t HL
Definition: cpu_8080.h:78
program_status_word PSW
Definition: cpu_8080.h:84
v_memory mem
Definition: cpu_8080.h:102
uint8_t ACC
Definition: cpu_8080.h:83
uint16_t DE
Definition: cpu_8080.h:77
uint8_t intt
Definition: cpu_8080.h:90
uint8_t B
Definition: cpu_8080.h:69
uint8_t halt
Definition: cpu_8080.h:104
uint16_t PC
Definition: cpu_8080.h:89
uint8_t C
Definition: cpu_8080.h:68
program_status_word: An exdended PSW for easy checks and sets of PSW without flagging.
Definition: cpu_8080.h:22
uint8_t aux
Definition: cpu_8080.h:24
uint8_t zero
Definition: cpu_8080.h:26
uint8_t carry
Definition: cpu_8080.h:23
uint8_t sign
Definition: cpu_8080.h:25
uint8_t parity
Definition: cpu_8080.h:27
Memory wrapper.
Definition: memory_8080.h:18