Debian Codegraph @

src/kc/muglerpc/ports.cc

raw
1 /*
2 * KCemu -- The emulator for the KC85 homecomputer series and much more.
3 * Copyright (C) 1997-2010 Torsten Paul
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 along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 */
19
20 #include <stdio.h>
21 #include <iostream>
22 #include <iomanip>
23
24 #include "kc/system.h"
25
26 #include "kc/kc.h"
27 #include "kc/muglerpc/ports.h"
28 #include "kc/muglerpc/memory.h"
29
30 #include "libdbg/dbg.h"
31
32 #define memory ((MemoryMuglerPC *)memory)
33
34 PortsMuglerPC::PortsMuglerPC(void)
35 {
36 _val_0x94 = 0;
37 }
38
39 PortsMuglerPC::~PortsMuglerPC(void)
40 {
41 }
42
43 byte_t
44 PortsMuglerPC::in(word_t addr)
45 {
46 byte_t val;
47 byte_t a = addr & 0xff;
48
49 switch (a)
50 {
51 case 0x94:
52 case 0x95:
53 case 0x96:
54 case 0x97:
55 val = _val_0x94;
56 break;
57 default:
58 DBG(0, form("KCemu/internal_error",
59 "PortsMuglerPC: called in() with undefined address %04xh\n",
60 addr));
61 val = 0xff;
62 break;
63 }
64
65 DBG(2, form("KCemu/Ports/muglerpc/in",
66 "PortsMuglerPC: in() addr = %04x (returning %02x)\n",
67 addr, val));
68
69 return val;
70 }
71
72 void
73 PortsMuglerPC::out(word_t addr, byte_t val)
74 {
75 byte_t a = addr & 0xff;
76
77 DBG(2, form("KCemu/Ports/muglerpc/out",
78 "PortsMuglerPC: out() addr = %04x, val = %02x\n",
79 addr, val));
80
81 switch (a)
82 {
83 case 0x94:
84 case 0x95:
85 case 0x96:
86 case 0x97:
87 change_0x94(_val_0x94 ^ val, val);
88 _val_0x94 = val;
89 break;
90 default:
91 DBG(0, form("KCemu/internal_error",
92 "PortsMuglerPC: called out() with undefined address %04xh (val = %02xh)\n",
93 addr, val));
94 break;
95 }
96 }
97
98 void
99 PortsMuglerPC::change_0x94(byte_t changed, byte_t val)
100 {
101 /*
102 * memory switch:
103 *
104 * bit 0: \
105 * bit 1: > ram block select (block 0 to 2 on base system)
106 * bit 2: /
107 * bit 3: SEL 0 (on system connector X3)
108 * bit 4: SEL 1 (on system connector X3)
109 * bit 5: SEL 2 (on system connector X3)
110 * bit 6: force block 0 at c000h - ffffh
111 * bit 7: enable/disable EPROM at 0000h (0 = on, 1 = off)
112 *
113 */
114 if (changed & 0x47)
115 {
116 DBG(2, form("KCemu/Ports/muglerpc/change/94",
117 "PortsMuglerPC: change_0x94() select ram block %d, %sforce block 0 at c000h\n",
118 val & 7,
119 (val & 0x40) ? "" : "don't "));
120 memory->select_ram_block(val & 7, (val & 0x40) == 0x40);
121 }
122 if (changed & 0x80)
123 {
124 DBG(2, form("KCemu/Ports/muglerpc/change/94",
125 "PortsMuglerPC: change_0x94() set eprom %s\n",
126 (val & 0x80) ? "inactive" : "active"));
127 memory->select_eprom((val & 0x80) == 0);
128 }
129 }