-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathemulator.h
48 lines (32 loc) · 1011 Bytes
/
emulator.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
#ifndef EMULATOR_H_
#define EMULATOR_H_
#include <stddef.h>
#include <stdint.h>
#define MEMORY_SIZE (4 * 1024)
typedef struct {
uint8_t memory[MEMORY_SIZE];
uint8_t registers[16];
/// A 16-bit register called I.
uint16_t address_register;
uint8_t delay_timer;
uint8_t sound_timer;
uint16_t program_counter;
uint8_t stack_pointer;
uint16_t stack[16];
uint16_t keyboard;
uint8_t display[8 * 32];
int8_t waiting;
} Emulator;
/// Initialize the emulator state.
void emulator_init(Emulator *emu);
/// Load the given ROM source into the emulator memory.
void emulator_load_rom(Emulator *restrict emu, const uint8_t *restrict rom, size_t len);
/// Perform one tick on both the timers.
void emulator_tick_timers(Emulator *emu);
/// Fetch the next instruction.
uint16_t emulator_fetch(Emulator *emu);
/// Execute the given instruction.
void emulator_execute(Emulator *emu, uint16_t instr);
/// Perform one fetch-decode-execute cycle.
void emulator_cycle(Emulator *emu);
#endif // EMULATOR_H_