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 <string.h>
22
23 #include "kc/system.h"
24
25 #include "kc/mod_4m.h"
26
Module4M(Module4M & tmpl)27 Module4M::Module4M(Module4M &tmpl) :
28 ModuleInterface(tmpl.get_name(), tmpl.get_id(), tmpl.get_type())
29 {
30 bool valid = true;
31 for (int a = 0;a < 4;a++)
32 {
33 _master[a] = NULL;
34 _module[a] = tmpl.get_master(a)->clone();
35 valid = valid & _module[a]->is_valid();
36 }
37 set_valid(valid);
38 }
39
Module4M(const char * name,byte_t id)40 Module4M::Module4M(const char *name, byte_t id) :
41 ModuleInterface(name, id, KC_MODULE_KC_85_3)
42 {
43 for (int a = 0;a < 4;a++)
44 {
45 char buf[100];
46 snprintf(buf, 100, "%s/%d", name, a);
47 _master[a] = new Module1M(buf, id);
48 _module[a] = NULL;
49 }
50
51 set_valid(true);
52 }
53
~Module4M(void)54 Module4M::~Module4M(void)
55 {
56 for (int a = 0;a < 4;a++)
57 if (_module[a])
58 delete _module[a];
59
60 for (int a = 0;a < 4;a++)
61 if (_master[a])
62 delete _master[a];
63 }
64
65 Module1M *
get_master(int idx)66 Module4M::get_master(int idx)
67 {
68 return _master[idx];
69 }
70
71 byte_t
m_in(word_t addr)72 Module4M::m_in(word_t addr)
73 {
74 int idx = (addr >> 8) & 3;
75 return _module[idx]->m_in(addr & 0xfcff);
76 }
77
78 void
m_out(word_t addr,byte_t val)79 Module4M::m_out(word_t addr, byte_t val)
80 {
81 int idx = (addr >> 8) & 3;
82 _module[idx]->m_out(addr & 0xfcff, val);
83 }
84
85 ModuleInterface *
clone(void)86 Module4M::clone(void)
87 {
88 return new Module4M(*this);
89 }
90
91 void
reset(bool power_on)92 Module4M::reset(bool power_on)
93 {
94 for (int a = 0;a < 4;a++)
95 _module[a]->reset(power_on);
96 }
97