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 <stdlib.h>
21 #include <fstream>
22
23 #include "kc/system.h"
24 #include "kc/prefs/types.h"
25
26 #include "kc/kc.h"
27 #include "kc/z80.h"
28 #include "kc/c80/memory.h"
29
30 using namespace std;
31
MemoryC80(void)32 MemoryC80::MemoryC80(void) : Memory()
33 {
34 load_rom(SystemROM::ROM_KEY_SYSTEM, &_rom_monitor);
35
36 if (!load_rom(SystemROM::ROM_KEY_USER, &_rom_user))
37 memset(_rom_user, 0xff, 0x400);
38
39 memory_group_t mem[] = {
40 { &_m_scr, "-", 0x0000, 0x10000, 0, 256, 0, 1, -1 },
41 { &_m_rom_monitor, "Monitor", 0x0000, 0x0400, &_rom_monitor[0], 1, 1, 1, -1 },
42 { &_m_rom_user, "User ROM", 0x0400, 0x0400, &_rom_user[0], 1, 1, 1, -1 },
43 { &_m_ram_mirror, "RAM (mirror)", 0x0800, 0x0400, &_ram[0], 1, 0, 1, -1 },
44 { &_m_ram, "RAM", 0x0c00, 0x0400, &_ram[0], 1, 0, 1, -1 },
45 { 0, },
46 };
47 init_memory_groups(mem);
48
49 reset(true);
50 z80->register_ic(this);
51 }
52
~MemoryC80(void)53 MemoryC80::~MemoryC80(void)
54 {
55 z80->unregister_ic(this);
56
57 delete _m_scr;
58 delete _m_rom_monitor;
59 delete _m_rom_user;
60 delete _m_ram_mirror;
61 delete _m_ram;
62 }
63
64 byte_t
memRead8(word_t addr)65 MemoryC80::memRead8(word_t addr)
66 {
67 return _memrptr[addr >> MemArea::PAGE_SHIFT][addr & MemArea::PAGE_MASK];
68 }
69
70 void
memWrite8(word_t addr,byte_t val)71 MemoryC80::memWrite8(word_t addr, byte_t val)
72 {
73 _memwptr[addr >> MemArea::PAGE_SHIFT][addr & MemArea::PAGE_MASK] = val;
74 }
75
76 byte_t *
get_irm(void)77 MemoryC80::get_irm(void)
78 {
79 return 0;
80 }
81
82 byte_t *
get_char_rom(void)83 MemoryC80::get_char_rom(void)
84 {
85 return 0;
86 }
87
88 void
reset(bool power_on)89 MemoryC80::reset(bool power_on)
90 {
91 if (!power_on)
92 return;
93
94 scratch_mem(&_ram[0], 0x0400);
95 }
96
97 void
dumpCore(void)98 MemoryC80::dumpCore(void)
99 {
100 ofstream os;
101
102 os.open("core.z80");
103
104 cerr << "Memory: dumping core..." << endl;
105 if (!os)
106 {
107 cerr << "Memory: can't write 'core.z80'" << endl;
108 return;
109 }
110
111 for (int a = 0;a < 0x10000;a++)
112 os.put(memRead8(a));
113
114 os.close();
115 cerr << "Memory: done." << endl;
116 }
117