openMSX
RomAscii16_2.cc
Go to the documentation of this file.
1// ASCII 16kB based cartridges with SRAM
2//
3// Examples 2kB SRAM: Daisenryaku, Harry Fox MSX Special, Hydlide 2, Jyansei
4// Examples 8kB SRAM: A-Train
5//
6// this type is is almost completely a ASCII16 cartridge
7// However, it has 2 or 8kB of SRAM (and 128 kB ROM)
8// Use value 0x10 to select the SRAM.
9// SRAM in page 1 => read-only
10// SRAM in page 2 => read-write
11// The SRAM is mirrored in the 16 kB block
12//
13// The address to change banks (from ASCII16):
14// first 16kb: 0x6000 - 0x67FF (0x6000 used)
15// second 16kb: 0x7000 - 0x77FF (0x7000 and 0x77FF used)
16
17#include "RomAscii16_2.hh"
18#include "SRAM.hh"
19#include "serialize.hh"
20#include <memory>
21
22namespace openmsx {
23
24RomAscii16_2::RomAscii16_2(const DeviceConfig& config, Rom&& rom_, SubType subType)
25 : RomAscii16kB(config, std::move(rom_))
26{
27 unsigned size = (subType == ASCII16_8) ? 0x2000 // 8kB
28 : 0x0800; // 2kB
29 sram = std::make_unique<SRAM>(getName() + " SRAM", size, config);
30 reset(EmuTime::dummy());
31}
32
33void RomAscii16_2::reset(EmuTime::param time)
34{
35 sramEnabled = 0;
37}
38
39byte RomAscii16_2::readMem(word address, EmuTime::param time)
40{
41 if ((1 << (address >> 14)) & sramEnabled) {
42 return (*sram)[address & (sram->getSize() - 1)];
43 } else {
44 return RomAscii16kB::readMem(address, time);
45 }
46}
47
48const byte* RomAscii16_2::getReadCacheLine(word address) const
49{
50 if ((1 << (address >> 14)) & sramEnabled) {
51 return &(*sram)[address & (sram->getSize() - 1)];
52 } else {
53 return RomAscii16kB::getReadCacheLine(address);
54 }
55}
56
57void RomAscii16_2::writeMem(word address, byte value, EmuTime::param /*time*/)
58{
59 if ((0x6000 <= address) && (address < 0x7800) && !(address & 0x0800)) {
60 // bank switch
61 byte region = ((address >> 12) & 1) + 1;
62 if (value == 0x10) {
63 // SRAM block
64 sramEnabled |= (1 << region);
65 } else {
66 // ROM block
67 setRom(region, value);
68 sramEnabled &= ~(1 << region);
69 }
70 invalidateDeviceRWCache(0x4000 * region, 0x4000);
71 } else {
72 // write sram
73 if ((1 << (address >> 14)) & sramEnabled & 0x04) {
74 sram->write(address & (sram->getSize() - 1), value);
75 }
76 }
77}
78
80{
81 if ((1 << (address >> 14)) & sramEnabled & 0x04) {
82 // write sram
83 return nullptr;
84 } else {
85 return RomAscii16kB::getWriteCacheLine(address);
86 }
87}
88
89template<typename Archive>
90void RomAscii16_2::serialize(Archive& ar, unsigned /*version*/)
91{
92 ar.template serializeBase<RomAscii16kB>(*this);
93 ar.serialize("sramEnabled", sramEnabled);
94}
97
98} // namespace openmsx
virtual const std::string & getName() const
Returns a human-readable name for this device.
Definition: MSXDevice.cc:376
void invalidateDeviceRWCache()
Calls MSXCPUInterface::invalidateXXCache() for the specific (part of) the slot that this device is lo...
Definition: MSXDevice.hh:209
byte * getWriteCacheLine(word address) const override
Test that the memory in the interval [start, start + CacheLine::SIZE) is cacheable for writing.
Definition: RomAscii16_2.cc:79
RomAscii16_2(const DeviceConfig &config, Rom &&rom, SubType subType)
Definition: RomAscii16_2.cc:24
byte readMem(word address, EmuTime::param time) override
Read a byte from a location at a certain time from this device.
Definition: RomAscii16_2.cc:39
void serialize(Archive &ar, unsigned version)
Definition: RomAscii16_2.cc:90
void reset(EmuTime::param time) override
This method is called on reset.
Definition: RomAscii16_2.cc:33
void writeMem(word address, byte value, EmuTime::param time) override
Write a given byte to a given location at a certain time to this device.
Definition: RomAscii16_2.cc:57
const byte * getReadCacheLine(word address) const override
Test that the memory in the interval [start, start + CacheLine::SIZE) is cacheable for reading.
Definition: RomAscii16_2.cc:48
void reset(EmuTime::param time) override
This method is called on reset.
Definition: RomAscii16kB.cc:22
byte * getWriteCacheLine(word address) const override
Test that the memory in the interval [start, start + CacheLine::SIZE) is cacheable for writing.
Definition: RomAscii16kB.cc:38
std::unique_ptr< SRAM > sram
Definition: RomBlocks.hh:84
byte readMem(word address, EmuTime::param time) override
Read a byte from a location at a certain time from this device.
Definition: RomBlocks.cc:66
void setRom(byte region, unsigned block)
Selects a block of the ROM image for reading in a certain region.
Definition: RomBlocks.cc:105
const byte * getReadCacheLine(word address) const override
Test that the memory in the interval [start, start + CacheLine::SIZE) is cacheable for reading.
Definition: RomBlocks.cc:72
This file implemented 3 utility functions:
Definition: Autofire.cc:9
REGISTER_MSXDEVICE(ChakkariCopy, "ChakkariCopy")
uint16_t word
16 bit unsigned integer
Definition: openmsx.hh:29
STL namespace.
size_t size(std::string_view utf8)
#define INSTANTIATE_SERIALIZE_METHODS(CLASS)
Definition: serialize.hh:1009