FabGL
ESP32 Display Controller and Graphics Library
i8086.h
1
2
3#pragma once
4
5#include "fabgl.h"
6
7#include <stdint.h>
8
9
10#define I8086_SHOW_OPCODE_STATS 0
11
12#ifndef I80186MODE
13 #define I80186MODE 0
14#endif
15
16
17
18namespace fabgl {
19
20
21class i8086 {
22
23public:
24
25 // callbacks
26
27 typedef void (*WritePort)(void * context, int address, uint8_t value);
28 typedef uint8_t (*ReadPort)(void * context, int address);
29 typedef void (*WriteVideoMemory8)(void * context, int address, uint8_t value);
30 typedef void (*WriteVideoMemory16)(void * context, int address, uint16_t value);
31 typedef uint8_t (*ReadVideoMemory8)(void * context, int address);
32 typedef uint16_t (*ReadVideoMemory16)(void * context, int address);
33 typedef bool (*Interrupt)(void * context, int num);
34
35
36 static void setCallbacks(void * context, ReadPort readPort, WritePort writePort, WriteVideoMemory8 writeVideoMemory8, WriteVideoMemory16 writeVideoMemory16, ReadVideoMemory8 readVideoMemory8, ReadVideoMemory16 readVideoMemory16,Interrupt interrupt) {
37 s_context = context;
38 s_readPort = readPort;
39 s_writePort = writePort;
40 s_writeVideoMemory8 = writeVideoMemory8;
41 s_writeVideoMemory16 = writeVideoMemory16;
42 s_readVideoMemory8 = readVideoMemory8;
43 s_readVideoMemory16 = readVideoMemory16;
44 s_interrupt = interrupt;
45 }
46
47 static void setMemory(uint8_t * memory) { s_memory = memory; }
48
49 static void reset();
50
51 static void setAL(uint8_t value);
52 static void setAH(uint8_t value);
53 static void setBL(uint8_t value);
54 static void setBH(uint8_t value);
55 static void setCL(uint8_t value);
56 static void setCH(uint8_t value);
57 static void setDL(uint8_t value);
58 static void setDH(uint8_t value);
59
60 static uint8_t AL();
61 static uint8_t AH();
62 static uint8_t BL();
63 static uint8_t BH();
64 static uint8_t CL();
65 static uint8_t CH();
66 static uint8_t DL();
67 static uint8_t DH();
68
69 static void setAX(uint16_t value);
70 static void setBX(uint16_t value);
71 static void setCX(uint16_t value);
72 static void setDX(uint16_t value);
73 static void setDI(uint16_t value);
74 static void setCS(uint16_t value);
75 static void setDS(uint16_t value);
76 static void setSS(uint16_t value);
77 static void setES(uint16_t value);
78 static void setIP(uint16_t value);
79 static void setSP(uint16_t value);
80
81 static uint16_t AX();
82 static uint16_t BX();
83 static uint16_t CX();
84 static uint16_t DX();
85 static uint16_t BP();
86 static uint16_t SI();
87 static uint16_t DI();
88 static uint16_t SP();
89
90 static uint16_t CS();
91 static uint16_t ES();
92 static uint16_t DS();
93 static uint16_t SS();
94
95 static bool flagIF();
96 static bool flagTF();
97 static bool flagCF();
98 static bool flagZF();
99 static bool flagOF();
100 static bool flagDF();
101 static bool flagSF();
102 static bool flagAF();
103 static bool flagPF();
104
105 static void setFlagZF(bool value);
106 static void setFlagCF(bool value);
107
108 static uint16_t IP();
109
110 static bool halted() { return s_halted; }
111
112 static bool IRQ(uint8_t interrupt_num);
113
114 static void step();
115
116
117private:
118
119 static uint8_t WMEM8(int addr, uint8_t value);
120 static uint16_t WMEM16(int addr, uint16_t value);
121 static uint8_t RMEM8(int addr);
122 static uint16_t RMEM16(int addr);
123
124 static uint16_t make_flags();
125 static void set_flags(int new_flags);
126
127 static void pc_interrupt(uint8_t interrupt_num);
128
129 static uint8_t raiseDivideByZeroInterrupt();
130
131 static void stepEx(uint8_t const * opcode_stream);
132
133
134 static void * s_context;
135 static ReadPort s_readPort;
136 static WritePort s_writePort;
137 static WriteVideoMemory8 s_writeVideoMemory8;
138 static WriteVideoMemory16 s_writeVideoMemory16;
139 static ReadVideoMemory8 s_readVideoMemory8;
140 static ReadVideoMemory16 s_readVideoMemory16;
141 static Interrupt s_interrupt;
142
143 static bool s_pendingIRQ;
144 static uint8_t s_pendingIRQIndex;
145 static uint8_t * s_memory;
146 static bool s_halted;
147
148};
149
150
151} // namespace fabgl
This file is the all in one include file. Application can just include this file to use FabGL library...