VirtualC64 v5.0 beta
Commodore 64 Emulator
Loading...
Searching...
No Matches
FinalIII.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 "Cartridge.h"
16
17namespace vc64 {
18
19class FinalIII final : public Cartridge {
20
21 CartridgeTraits traits = {
22
23 .type = CRT_FINAL_III,
24 .title = "Final Cartridge III",
25
26 .buttons = 2,
27 .button1 = "Freeze",
28 .button2 = "Reset"
29 };
30
31 virtual const CartridgeTraits &getCartridgeTraits() const override { return traits; }
32
33 // Indicates whether the freeze button is pressed
34 bool freeezeButtonIsPressed = false;
35
36 /* The QD pin of the Final Cartridge III's 4-bit counter. The counter's
37 * purpose is to delay the grounding the Game line when the freeze button
38 * is pressed. Doing so lets the CPU read the NMI vector with the old
39 * Game/Exrom combination.
40 */
41 bool qD = true;
42
43
44 //
45 // Initializing
46 //
47
48public:
49
50 using Cartridge::Cartridge;
51 void resetCartConfig() override;
52
53
54 //
55 // Methods from CoreObject
56 //
57
58private:
59
60 void _dump(Category category, std::ostream& os) const override;
61
62
63 //
64 // Methods from CoreComponent
65 //
66
67public:
68
69 FinalIII& operator= (const FinalIII& other) {
70
71 Cartridge::operator=(other);
72
73 CLONE(qD)
74 CLONE(freeezeButtonIsPressed)
75
76 return *this;
77 }
78 virtual void clone(const Cartridge &other) override { *this = (const FinalIII &)other; }
79
80 template <class T>
81 void serialize(T& worker)
82 {
83 worker
84
85 << qD;
86
87 if (isResetter(worker)) return;
88
89 worker
90
91 << freeezeButtonIsPressed;
92
93 } CARTRIDGE_SERIALIZERS(serialize);
94
95 void _reset(bool hard) override;
96
97
98 //
99 // Accessing cartridge memory
100 //
101
102public:
103
104 u8 peekIO1(u16 addr) override;
105 u8 spypeekIO1(u16 addr) const override;
106 u8 peekIO2(u16 addr) override;
107 u8 spypeekIO2(u16 addr) const override;
108 void pokeIO2(u16 addr, u8 value) override;
109 void nmiDidTrigger() override;
110
111
112 //
113 // Accessing the control register
114 //
115
116private:
117
118 void setControlReg(u8 value);
119 bool hidden() const { return (control & 0x80) != 0; }
120 bool nmi() const { return (control & 0x40) != 0; }
121 bool game() const { return (control & 0x20) != 0; }
122 bool exrom() const { return (control & 0x10) != 0; }
123 u8 bank() const { return (control & 0x03); }
124
125 /* Indicates if the control register is write enabled. Final Cartridge III
126 * enables and disables the control register by masking the clock signal.
127 */
128 bool writeEnabled() const;
129
130 /* Updates the NMI line. The NMI line is driven by the control register and
131 * the current position of the freeze button.
132 */
133 void updateNMI();
134
135 /* Updates the Game line. The game line is driven by the control register
136 * and counter output qD.
137 */
138 void updateGame();
139
140
141 //
142 // Operating buttons
143 //
144
145 isize numButtons() const override { return 2; }
146 const char *getButtonTitle(isize nr) const override;
147 void pressButton(isize nr) override;
148 void releaseButton(isize nr) override;
149};
150
151}
VirtualC64 project namespace.
Definition CmdQueue.cpp:16