VirtualC64 v5.0 beta
Commodore 64 Emulator
Loading...
Searching...
No Matches
ExpansionPort.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 "ExpansionPortTypes.h"
16#include "CmdQueueTypes.h"
17#include "SubComponent.h"
18#include "Cartridge.h"
19
20namespace vc64 {
21
22/*
23 * For more information: http://www.c64-wiki.com/index.php/Cartridge
24 *
25 * "The cartridge system implemented in the C64 provides an easy way to
26 * hook 8 or 16 kilobytes of ROM into the computer's address space:
27 * This allows for applications and games up to 16 K, or BASIC expansions
28 * up to 8 K in size and appearing to the CPU along with the built-in
29 * BASIC ROM. In theory, such a cartridge need only contain the
30 * ROM circuit without any extra support electronics."
31 *
32 * Bank switching info: http://www.c64-wiki.com/index.php/Bankswitching
33 * http://www.harries.dk/files/C64MemoryMaps.pdf
34 *
35 * As well read the Commodore 64 Programmers Reference Guide pages 260-267.
36 */
37
38class ExpansionPort final : public SubComponent, public Inspectable<CartridgeInfo> {
39
40 Descriptions descriptions = {{
41
42 .name = "Expansion",
43 .description = "Expansion Port"
44 }};
45
46 // Attached cartridge or nullptr
47 std::unique_ptr<Cartridge> cartridge;
48
49 // Type of the attached cartridge
50 CartridgeType crtType = CRT_NONE;
51
52 // Values of the Game and the Exrom line (true if no cartridge is attached)
53 bool gameLine = 1;
54 bool exromLine = 1;
55
56
57 //
58 // Methods
59 //
60
61public:
62
63 ExpansionPort(C64 &ref) : SubComponent(ref) { };
64 ExpansionPort& operator= (const ExpansionPort& other);
65
66
67 //
68 // Methods from Serializable
69 //
70
71public:
72
73 template <class T>
74 void serialize(T& worker)
75 {
76 if (isResetter(worker)) return;
77
78 worker
79
80 << crtType
81 << gameLine
82 << exromLine;
83 }
84
85 void operator << (SerResetter &worker) override;
86 void operator << (SerChecker &worker) override;
87 void operator << (SerCounter &worker) override;
88 void operator << (SerReader &worker) override;
89 void operator << (SerWriter &worker) override;
90
91
92 //
93 // Methods from CoreComponent
94 //
95
96public:
97
98 const Descriptions &getDescriptions() const override { return descriptions; }
99
100private:
101
102 void _dump(Category category, std::ostream& os) const override;
103 void _reset(bool hard) override;
104
105
106 //
107 // Analyzing
108 //
109
110public:
111
112 const CartridgeTraits &getCartridgeTraits() const;
113 const CartridgeInfo &getInfo() const;
114 CartridgeRomInfo getRomInfo(isize nr) const;
115 CartridgeType getCartridgeType() const;
116
117
118 //
119 // Accessing cartrige memory
120 //
121
122public:
123
124 u8 peek(u16 addr);
125 u8 spypeek(u16 addr) const;
126 u8 peekIO1(u16 addr);
127 u8 spypeekIO1(u16 addr) const;
128 u8 peekIO2(u16 addr);
129 u8 spypeekIO2(u16 addr) const;
130
131 void poke(u16 addr, u8 value);
132 void pokeIO1(u16 addr, u8 value);
133 void pokeIO2(u16 addr, u8 value);
134
135
136 //
137 // Controlling the Game and Exrom lines
138 //
139
140public:
141
142 bool getGameLine() const { return gameLine; }
143 void setGameLine(bool value);
144
145 bool getExromLine() const { return exromLine; }
146 void setExromLine(bool value);
147
148 void setGameAndExrom(bool game, bool exrom);
149
150 CRTMode getCartridgeMode() const;
151 void setCartridgeMode(CRTMode mode);
152
153 void resetCartConfig();
154
155
156 //
157 // Attaching and detaching
158 //
159
160 // Attaches a cartridge to the expansion port
161 void attachCartridge(const fs::path &path, bool reset = true) throws;
162 void attachCartridge(const MediaFile &file, bool reset = true) throws;
163 void attachCartridge(Cartridge *c);
164 void attachReu(isize capacity);
165 void attachGeoRam(isize capacity);
166 void attachIsepicCartridge();
167
168 // Removes a cartridge from the expansion port (if any)
169 void detachCartridge();
170
171
172 //
173 // Operating buttons, switches, and LEDs
174 //
175
176 // Presses a button (make sure to call releaseButton() afterwards)
177 void pressButton(isize nr);
178
179 // Releases a button (make sure to call pressButton() before)
180 void releaseButton(isize nr);
181
182 // Puts the switch in the provided position
183 void setSwitch(isize pos) { if (cartridge) cartridge->setSwitch(pos); }
184
185 // Switches the LED on or off
186 void setLED(bool value);
187
188
189 //
190 // Processing commands
191 //
192
193public:
194
195 // Processes a cartridge command
196 void processCommand(const Cmd &cmd);
197
198
199 //
200 // Handling delegation calls
201 //
202
203 /* Emulator thread callback. This function is invoked by the expansion port.
204 * Only a few cartridges such as EpyxFastLoader will do some action here.
205 */
206 void execute();
207
208 /* Modifies the memory source lookup tables if required. This function is
209 * called in C64::updatePeekPokeLookupTables() to allow cartridges to
210 * manipulate the lookup tables after the default values have been set.
211 * Background: Some cartridges such as StarDos change the game and exrom
212 * line on-the-fly to achieve very special memory mappings. For most
213 * cartridges, this function does nothing.
214 */
215 void updatePeekPokeLookupTables();
216
217 // Called when the C64 CPU is about to trigger an NMI
218 void nmiWillTrigger();
219
220 // Called after the C64 CPU has processed the NMI instruction
221 void nmiDidTrigger();
222};
223
224}
VirtualC64 project namespace.
Definition CmdQueue.cpp:16