Xemu [doxygen]  hyppo 0a42be3a057156924bc1b626a687bd6e27349c45 @ Sat 19 Mar 02:15:11 CET 2022
z180.c
Go to the documentation of this file.
1 /* Xep128: Minimalistic Enterprise-128 emulator with focus on "exotic" hardware
2  Copyright (C)2015,2016 LGB (Gábor Lénárt) <lgblgblgb@gmail.com>
3  http://xep128.lgb.hu/
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 "xep128.h"
20 #include "z180.h"
21 #include "cpu.h"
22 
23 #ifdef CONFIG_Z180
24 
25 int z180_port_start;
26 static Uint8 z180_ports[0x40];
27 static int z180_incompatibility_reported = 0;
28 
29 
30 // These "default" values from a real Z180, at least reading it from software (non-readable ports can be a problem though)
31 static const Uint8 _z180_ports_default[0x40] = {
32  0x10, 0x00, 0x27, 0x07, 0x04, 0x02, 0xFF, 0xFF,
33  0xFF, 0xFF, 0x0F, 0x00, 0xFF, 0xFF, 0xFF, 0xFF,
34  0x00, 0xFF, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0xFF,
35  0x7A, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x3F, 0x80,
36  0x00, 0xFE, 0x00, 0x00, 0xFE, 0x00, 0x00, 0xFE,
37  0x00, 0xFE, 0x00, 0x00, 0xFE, 0x00, 0x00, 0xFE,
38  0x32, 0xC1, 0x00, 0x00, 0x39, 0xFF, 0xFC, 0xFF,
39  0x00, 0x00, 0xF0, 0xFF, 0xFF, 0xFF, 0xFF, 0x1F
40 };
41 
42 
43 /* A callback only used in Z180 mode */
44 void z80ex_z180_cb (Z80EX_WORD pc, Z80EX_BYTE prefix, Z80EX_BYTE series, Z80EX_BYTE opcode, Z80EX_BYTE itc76)
45 {
46  z180_ports[0x34] = (z180_ports[0x34] & 0x3F) | itc76; // set ITC register up
47  DEBUG("Z180: setting ICT register to: %02Xh" NL, z180_ports[0x34]);
48  DEBUG("Z180: Invalid Z180 opcode <prefix=%02Xh series=%02Xh opcode=%02Xh> at PC=%04Xh [%02Xh:%04Xh]" NL,
49  prefix, series, opcode,
50  pc,
51  ports[0xB0 | (pc >> 14)],
52  pc & 0x3FFF
53  );
54  if (z180_incompatibility_reported) return;
55  z180_incompatibility_reported = 1;
56  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 :)",
57  prefix, series, opcode,
58  pc,
59  ports[0xB0 | (pc >> 14)],
60  pc & 0x3FFF
61  );
62 }
63 
64 
65 void z180_internal_reset ( void )
66 {
67  z180_port_start = 0;
68  memcpy(z180_ports, _z180_ports_default, 0x40);
69  z180_incompatibility_reported = 0;
70  // z180_ports[0x34] = 0x39; // ITC register
71  // z180_ports[0x3F] = 0x1F; // ICR - I/O control register
72 }
73 
74 
75 void z180_port_write ( Uint8 port, Uint8 value )
76 {
77  DEBUG("Z180: write internal port (%02Xh/%02Xh) data = %02Xh" NL, port, port | z180_port_start, value);
78  switch (port) {
79  case 0x34: // ITC register
80  value = (z180_ports[port] & 0x07) | 0x38; // change was: 47->07 in hex
81  break;
82  case 0x3F: // I/O control register (ICR)
83  z180_port_start = value & 0xC0;
84  DEBUG("Z180: internal ports are moved to %02Xh-%02Xh" NL, z180_port_start, z180_port_start + 0x3F);
85  value = (value & 0xE0) | 0x1F; // only first three bits are interpreted, the rest are '1' for read
86  break;
87  }
88  z180_ports[port] = value;
89 }
90 
91 
92 Uint8 z180_port_read ( Uint8 port )
93 {
94  DEBUG("Z180: read internal port (%02Xh/%02Xh)" NL, port, port | z180_port_start);
95  return z180_ports[port];
96 }
97 
98 #endif
pc
Uint16 pc
Definition: z8k1.c:127
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
cpu.h
Z80EX_BYTE
unsigned char Z80EX_BYTE
Definition: z80ex.h:49
NL
#define NL
Definition: fat32.c:37
xep128.h
z180.h
value
int value
Definition: dma65.c:90
DEBUG
#define DEBUG(...)
Definition: emutools_basicdefs.h:167