Xemu [doxygen]  hyppo 0a42be3a057156924bc1b626a687bd6e27349c45 @ Sat 19 Mar 02:15:11 CET 2022
z180.c
Go to the documentation of this file.
1 /* Minimalistic Enterprise-128 emulator with focus on "exotic" hardware
2  Part of the Xemu project, please visit: https://github.com/lgblgblgb/xemu
3  Copyright (C)2015-2016,2020 LGB (Gábor Lénárt) <lgblgblgb@gmail.com>
4 
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
9 
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
14 
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
18 
19 #include "xemu/emutools.h"
20 #include "enterprise128.h"
21 #include "z180.h"
22 #include "cpu.h"
23 
24 #ifdef CONFIG_Z180
25 
26 int z180_port_start;
27 static Uint8 z180_ports[0x40];
28 static int z180_incompatibility_reported = 0;
29 
30 
31 // These "default" values from a real Z180, at least reading it from software (non-readable ports can be a problem though)
32 static const Uint8 _z180_ports_default[0x40] = {
33  0x10, 0x00, 0x27, 0x07, 0x04, 0x02, 0xFF, 0xFF,
34  0xFF, 0xFF, 0x0F, 0x00, 0xFF, 0xFF, 0xFF, 0xFF,
35  0x00, 0xFF, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0xFF,
36  0x7A, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x3F, 0x80,
37  0x00, 0xFE, 0x00, 0x00, 0xFE, 0x00, 0x00, 0xFE,
38  0x00, 0xFE, 0x00, 0x00, 0xFE, 0x00, 0x00, 0xFE,
39  0x32, 0xC1, 0x00, 0x00, 0x39, 0xFF, 0xFC, 0xFF,
40  0x00, 0x00, 0xF0, 0xFF, 0xFF, 0xFF, 0xFF, 0x1F
41 };
42 
43 
44 /* A callback only used in Z180 mode */
45 void z80ex_z180_cb (Z80EX_WORD pc, Z80EX_BYTE prefix, Z80EX_BYTE series, Z80EX_BYTE opcode, Z80EX_BYTE itc76)
46 {
47  z180_ports[0x34] = (z180_ports[0x34] & 0x3F) | itc76; // set ITC register up
48  DEBUG("Z180: setting ICT register to: %02Xh" NL, z180_ports[0x34]);
49  DEBUG("Z180: Invalid Z180 opcode <prefix=%02Xh series=%02Xh opcode=%02Xh> at PC=%04Xh [%02Xh:%04Xh]" NL,
50  prefix, series, opcode,
51  pc,
52  ports[0xB0 | (pc >> 14)],
53  pc & 0x3FFF
54  );
55  if (z180_incompatibility_reported) return;
56  z180_incompatibility_reported = 1;
57  INFO_WINDOW("Z180: Invalid Z180 opcode <prefix=%02Xh series=%02Xh opcode=%02Xh> at PC=%04Xh [%02Xh:%04Xh]\nThere will be NO further error reports about this kind of problem to avoid window flooding :)",
58  prefix, series, opcode,
59  pc,
60  ports[0xB0 | (pc >> 14)],
61  pc & 0x3FFF
62  );
63 }
64 
65 
66 void z180_internal_reset ( void )
67 {
68  z180_port_start = 0;
69  memcpy(z180_ports, _z180_ports_default, 0x40);
70  z180_incompatibility_reported = 0;
71  // z180_ports[0x34] = 0x39; // ITC register
72  // z180_ports[0x3F] = 0x1F; // ICR - I/O control register
73 }
74 
75 
76 void z180_port_write ( Uint8 port, Uint8 value )
77 {
78  DEBUG("Z180: write internal port (%02Xh/%02Xh) data = %02Xh" NL, port, port | z180_port_start, value);
79  switch (port) {
80  case 0x34: // ITC register
81  value = (z180_ports[port] & 0x07) | 0x38; // change was: 47->07 in hex
82  break;
83  case 0x3F: // I/O control register (ICR)
84  z180_port_start = value & 0xC0;
85  DEBUG("Z180: internal ports are moved to %02Xh-%02Xh" NL, z180_port_start, z180_port_start + 0x3F);
86  value = (value & 0xE0) | 0x1F; // only first three bits are interpreted, the rest are '1' for read
87  break;
88  }
89  z180_ports[port] = value;
90 }
91 
92 
93 Uint8 z180_port_read ( Uint8 port )
94 {
95  DEBUG("Z180: read internal port (%02Xh/%02Xh)" NL, port, port | z180_port_start);
96  return z180_ports[port];
97 }
98 
99 #endif
pc
Uint16 pc
Definition: z8k1.c:127
emutools.h
INFO_WINDOW
#define INFO_WINDOW(...)
Definition: xep128.h:114
Z80EX_WORD
unsigned short Z80EX_WORD
Definition: z80ex.h:51
Uint8
uint8_t Uint8
Definition: fat32.c:51
Z80EX_BYTE
unsigned char Z80EX_BYTE
Definition: z80ex.h:49
cpu.h
NL
#define NL
Definition: fat32.c:37
z180.h
value
int value
Definition: dma65.c:90
enterprise128.h
DEBUG
#define DEBUG(...)
Definition: emutools_basicdefs.h:167