VirtualC64 v5.0 beta
Commodore 64 Emulator
Loading...
Searching...
No Matches
DriveMemory.h
1// -----------------------------------------------------------------------------
2// This file is part of VirtualC64
3//
4// Copyright (C) Dirk W. Hoffmann. www.dirkwhoffmann.de
5// This FILE is dual-licensed. You are free to choose between:
6//
7// - The GNU General Public License v3 (or any later version)
8// - The Mozilla Public License v2
9//
10// SPDX-License-Identifier: GPL-3.0-or-later OR MPL-2.0
11// -----------------------------------------------------------------------------
12
13#pragma once
14
15#include "SubComponent.h"
16#include "DriveTypes.h"
17
18namespace vc64 {
19
20class DriveMemory final : public SubComponent {
21
22 Descriptions descriptions = {{
23
24 .name = "DriveMemory",
25 .description = "Drive Memory"
26 }};
27
28 // Reference to the connected disk drive
29 class Drive &drive;
30
31public:
32
33 /* RAM:
34 *
35 * VC1541 : 2KB at $0000 - $07FF
36 * Dolphin DOS 2 : 2KB at $0000 - $07FF, 8KB at $8000 - $9FFF
37 * Dolphin DOS 3 : 2KB at $0000 - $07FF, 8KB at $6000 - $7FFF
38 *
39 * ROM:
40 *
41 * VC1541 : 16KB at $C000 - $FFFF, Mirror at $8000
42 * Dolphin DOS 2 : 24KB at $A000 - $FFFF
43 * Dolphin DOS 3 : 32KB at $A000 - $FFFF (???)
44 */
45 u8 ram[0xA000];
46 u8 rom[0x8000] = {};
47
48 // Memory usage table (one entry for each KB)
49 DrvMemType usage[64];
50
51
52 //
53 // Methods
54 //
55
56public:
57
58 DriveMemory(C64 &ref, Drive &drive);
59
60 DriveMemory& operator= (const DriveMemory& other) {
61
62 CLONE_ARRAY(ram)
63 CLONE_ARRAY(rom)
64 CLONE_ARRAY(usage)
65
66 return *this;
67 }
68
69
70 //
71 // Methods from Serializable
72 //
73
74public:
75
76 template <class T>
77 void serialize(T& worker)
78 {
79 if (isResetter(worker)) return;
80
81 worker
82
83 << ram
84 << usage;
85 }
86
87 void operator << (SerResetter &worker) override { serialize(worker); }
88 void operator << (SerChecker &worker) override { serialize(worker); }
89 void operator << (SerCounter &worker) override;
90 void operator << (SerReader &worker) override;
91 void operator << (SerWriter &worker) override;
92
93
94 //
95 // Methods from CoreComponent
96 //
97
98public:
99
100 const Descriptions &getDescriptions() const override { return descriptions; }
101
102private:
103
104 void _dump(Category category, std::ostream& os) const override;
105 void _reset(bool hard) override;
106
107
108 //
109 // Working with Roms
110 //
111
112public:
113
114 // Returns the size and start address of the Rom
115 u16 romSize() const;
116 u16 romAddr() const;
117
118 // Indicates if a Rom is installed
119 bool hasRom() const { return romSize() != 0; }
120
121 // Computes a Rom checksum
122 u32 romCRC32() const;
123 u64 romFNV64() const;
124
125 // Removes the currently installed Rom
126 void deleteRom();
127
128 // Loads a Rom
129 void loadRom(const class RomFile &file);
130 void loadRom(const u8 *buf, isize size);
131
132 // Saves the currently installed Rom
133 void saveRom(const fs::path &path) throws;
134
135
136 //
137 // Accessing memory
138 //
139
140public:
141
142 // Reads a value from memory
143 u8 peek(u16 addr);
144 u8 peekZP(u8 addr) { return ram[addr]; }
145 u8 peekStack(u8 sp) { return ram[0x100 + sp]; }
146
147 // Emulates an idle read access
148 void peekIdle(u16 addr) { }
149 void peekZPIdle(u8 addr) { }
150 void peekStackIdle(u8 sp) { }
151 void peekIOIdle(u16 addr) { }
152
153 // Reads a value from memory without side effects
154 u8 spypeek(u16 addr) const;
155
156 // Writes a value into memory
157 void poke(u16 addr, u8 value);
158 void pokeZP(u8 addr, u8 value) { ram[addr] = value; }
159 void pokeStack(u8 sp, u8 value) { ram[0x100 + sp] = value; }
160
161 // Updates the bank map
162 void updateBankMap();
163};
164
165}
VirtualC64 project namespace.
Definition CmdQueue.cpp:16