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 
18 namespace fabgl {
19 
20 
21 class i8086 {
22 
23 public:
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 
56  static uint8_t AL();
57  static uint8_t AH();
58  static uint8_t BL();
59  static uint8_t BH();
60  static uint8_t CL();
61  static uint8_t CH();
62 
63  static void setAX(uint16_t value);
64  static void setBX(uint16_t value);
65  static void setCX(uint16_t value);
66  static void setDX(uint16_t value);
67  static void setCS(uint16_t value);
68  static void setDS(uint16_t value);
69  static void setSS(uint16_t value);
70  static void setIP(uint16_t value);
71  static void setSP(uint16_t value);
72 
73  static uint16_t AX();
74  static uint16_t BX();
75  static uint16_t CX();
76  static uint16_t DX();
77  static uint16_t BP();
78  static uint16_t SI();
79  static uint16_t DI();
80  static uint16_t SP();
81 
82  static uint16_t CS();
83  static uint16_t ES();
84  static uint16_t DS();
85  static uint16_t SS();
86 
87  static bool flagIF();
88  static bool flagTF();
89  static bool flagCF();
90  static bool flagZF();
91 
92  static void setFlagZF(bool value);
93  static void setFlagCF(bool value);
94 
95  static bool halted() { return s_halted; }
96 
97  static bool IRQ(uint8_t interrupt_num);
98 
99  static void step();
100 
101 
102 private:
103 
104  static uint8_t WMEM8(int addr, uint8_t value);
105  static uint16_t WMEM16(int addr, uint16_t value);
106  static uint8_t RMEM8(int addr);
107  static uint16_t RMEM16(int addr);
108 
109  //static uint8_t & MEM8(int addr);
110  //static uint16_t & MEM16(int addr);
111 
112  static uint16_t make_flags();
113  static void set_flags(int new_flags);
114 
115  static void set_opcode(uint8_t opcode);
116 
117  static uint8_t pc_interrupt(uint8_t interrupt_num);
118 
119  static int AAA_AAS(int8_t which_operation);
120 
121  static uint8_t raiseDivideByZeroInterrupt();
122 
123  static void stepEx(uint8_t const * opcode_stream);
124 
125 
126  static void * s_context;
127  static ReadPort s_readPort;
128  static WritePort s_writePort;
129  static WriteVideoMemory8 s_writeVideoMemory8;
130  static WriteVideoMemory16 s_writeVideoMemory16;
131  static ReadVideoMemory8 s_readVideoMemory8;
132  static ReadVideoMemory16 s_readVideoMemory16;
133  static Interrupt s_interrupt;
134 
135  static bool s_pendingIRQ;
136  static uint8_t s_pendingIRQIndex;
137  static uint8_t * s_memory;
138  static bool s_halted;
139 
140 };
141 
142 
143 } // namespace fabgl
Definition: canvas.cpp:36
This file is the all in one include file. Application can just include this file to use FabGL library...