FabGL
ESP32 Display Controller and Graphics Library
i8080.h
Go to the documentation of this file.
1// Intel 8080 (KR580VM80A) microprocessor core model
2//
3// Copyright (C) 2012 Alexander Demin <alexander@demin.ws>
4//
5// Credits
6//
7// Viacheslav Slavinsky, Vector-06C FPGA Replica
8// http://code.google.com/p/vector06cc/
9//
10// Dmitry Tselikov, Bashrikia-2M and Radio-86RK on Altera DE1
11// http://bashkiria-2m.narod.ru/fpga.html
12//
13// Ian Bartholomew, 8080/8085 CPU Exerciser
14// http://www.idb.me.uk/sunhillow/8080.html
15//
16// Frank Cringle, The origianal exerciser for the Z80.
17//
18// Thanks to zx.pk.ru and nedopc.org/forum communities.
19//
20// This program is free software; you can redistribute it and/or modify
21// it under the terms of the GNU General Public License as published by
22// the Free Software Foundation; either version 2, or (at your option)
23// any later version.
24//
25// This program is distributed in the hope that it will be useful,
26// but WITHOUT ANY WARRANTY; without even the implied warranty of
27// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
28// GNU General Public License for more details.
29//
30// You should have received a copy of the GNU General Public License
31// along with this program; if not, write to the Free Software
32// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
33//
34//
35// 2020 adapted by Fabrizio Di Vittorio for fabgl ESP32 library
36
37
38#pragma once
39
40
49#include <stdint.h>
50
51
52namespace fabgl {
53
54
55
56
60class i8080 {
61
62 typedef union {
63 struct {
64 uint8_t l, h;
65 } b;
66 uint16_t w;
67 } reg_pair;
68
69
70 typedef struct {
71 uint8_t carry_flag;
72 uint8_t unused1;
73 uint8_t parity_flag;
74 uint8_t unused3;
75 uint8_t half_carry_flag;
76 uint8_t unused5;
77 uint8_t zero_flag;
78 uint8_t sign_flag;
79 } flag_reg;
80
81
82 struct Regs {
83 flag_reg f;
84 reg_pair af, bc, de, hl;
85 reg_pair sp, pc;
86 uint16_t iff;
87 uint16_t last_pc;
88 };
89
90public:
91
92
93 // callbacks
94 typedef int (*ReadByteCallback)(void * context, int addr);
95 typedef void (*WriteByteCallback)(void * context, int addr, int value);
96 typedef int (*ReadWordCallback)(void * context, int addr);
97 typedef void (*WriteWordCallback)(void * context, int addr, int value);
98 typedef int (*ReadIOCallback)(void * context, int addr);
99 typedef void (*WriteIOCallback)(void * context, int addr, int value);
100
101
102 void setCallbacks(void * context, ReadByteCallback readByte, WriteByteCallback writeByte, ReadWordCallback readWord, WriteWordCallback writeWord, ReadIOCallback readIO, WriteIOCallback writeIO) {
103 m_context = context;
104 m_readByte = readByte;
105 m_writeByte = writeByte;
106 m_readWord = readWord;
107 m_writeWord = writeWord;
108 m_readIO = readIO;
109 m_writeIO = writeIO;
110 }
111
112 void reset();
113 int step();
114
115 void setPC(int addr) { cpu.pc.w = addr & 0xffff; }
116 int getPC() { return cpu.pc.w; }
117
118 int regs_bc() { return cpu.bc.w; }
119 int regs_de() { return cpu.de.w; }
120 int regs_hl() { return cpu.hl.w; }
121 int regs_sp() { return cpu.sp.w; }
122
123 int regs_a() { return cpu.af.b.h; }
124 int regs_b() { return cpu.bc.b.h; }
125 int regs_c() { return cpu.bc.b.l; }
126 int regs_d() { return cpu.de.b.h; }
127 int regs_e() { return cpu.de.b.l; }
128 int regs_h() { return cpu.hl.b.h; }
129 int regs_l() { return cpu.hl.b.l; }
130
131
132private:
133
134 void store_flags();
135 void retrieve_flags();
136
137
138 Regs cpu;
139
140 uint32_t work32;
141 uint16_t work16;
142 uint8_t work8;
143 int index;
144 uint8_t carry;
145 uint8_t add;
146
147
148 // callbacks
149
150 void * m_context;
151
152 ReadByteCallback m_readByte;
153 WriteByteCallback m_writeByte;
154 ReadWordCallback m_readWord;
155 WriteWordCallback m_writeWord;
156 ReadIOCallback m_readIO;
157 WriteIOCallback m_writeIO;
158
159};
160
161
162}; // fabgl namespace
163
Intel 8080 CPU emulator.
Definition: i8080.h:60