-
Notifications
You must be signed in to change notification settings - Fork 48
/
cpucore.cpp
87 lines (67 loc) · 2.13 KB
/
cpucore.cpp
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
// -----------------------------------------------------------------------------
// Altair 8800 Simulator
// Copyright (C) 2018 David Hansel
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software Foundation,
// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
// -----------------------------------------------------------------------------
#include "cpucore.h"
#include "Altair8800.h"
#include "cpucore_z80.h"
#include "cpucore_i8080.h"
// registers shared between i8080 and z80 implementation
union unionAF regAF;
union unionBC regBC;
union unionDE regDE;
union unionHL regHL;
union unionPC regPCU;
uint16_t regSP;
#if USE_Z80==0 // fixed I8080 CPU
void cpu_setup() {}
void cpu_print_registers() { cpucore_i8080_print_registers(); }
#elif USE_Z80==1 // fixed Z80 CPU
void cpu_setup() {}
void cpu_print_registers() { cpucore_z80_print_registers(); }
#elif USE_Z80==2 // CPU is switchable
CPUFUN cpu_opcodes[256];
static int processor = -1;
static int clock_KHz = 0;
void cpu_setup()
{
cpu_set_processor(config_use_z80() ? PROC_Z80 : PROC_I8080);
}
void cpu_set_processor(int p)
{
processor = p;
clock_KHz = processor==PROC_I8080 ? CPU_CLOCK_I8080 : CPU_CLOCK_Z80;
memcpy(cpu_opcodes, processor==PROC_I8080 ? cpucore_i8080_opcodes : cpucore_z80_opcodes, 256*sizeof(CPUFUN));
}
int cpu_get_processor()
{
return processor;
}
int cpu_clock_KHz()
{
return clock_KHz;
}
void cpu_print_registers()
{
if( processor==PROC_I8080 )
cpucore_i8080_print_registers();
else
cpucore_z80_print_registers();
}
#else
#error INVALID USE_Z80 setting
#endif