diff --git a/Machines/Apple/Macintosh/Macintosh.cpp b/Machines/Apple/Macintosh/Macintosh.cpp index 4f34e0cca..13899d11a 100644 --- a/Machines/Apple/Macintosh/Macintosh.cpp +++ b/Machines/Apple/Macintosh/Macintosh.cpp @@ -66,7 +66,7 @@ template class ConcreteMachin ConcreteMachine(const Target &target, const ROMMachine::ROMFetcher &rom_fetcher) : mc68000_(*this), iwm_(CLOCK_RATE), - video_(ram_, audio_, drive_speed_accumulator_), + video_(audio_, drive_speed_accumulator_), via_(via_port_handler_), via_port_handler_(*this, clock_, keyboard_, video_, audio_, iwm_, mouse_), drives_{ @@ -95,7 +95,7 @@ template class ConcreteMachin break; case Model::Mac512ke: case Model::MacPlus: { - ram_size = 512*1024; + ram_size = ((model == Model::MacPlus) ? 4096 : 512)*1024; rom_size = 128*1024; const std::initializer_list crc32s = { 0x4fa5b399, 0x7cacd18f, 0xb2102e8e }; rom_descriptions.emplace_back(machine_name, "the Macintosh Plus ROM", "macplus.rom", 128*1024, crc32s); @@ -103,7 +103,8 @@ template class ConcreteMachin } ram_mask_ = (ram_size >> 1) - 1; rom_mask_ = (rom_size >> 1) - 1; - video_.set_ram_mask(ram_mask_); + ram_.resize(ram_size >> 1); + video_.set_ram(ram_.data(), ram_mask_); // Grab a copy of the ROM and convert it into big-endian data. const auto roms = rom_fetcher(rom_descriptions); @@ -114,7 +115,7 @@ template class ConcreteMachin Memory::PackBigEndian16(*roms[0], rom_); // Randomise memory contents. - Memory::Fuzz(ram_, sizeof(ram_) / sizeof(*ram_)); + Memory::Fuzz(ram_); // Attach the drives to the IWM. iwm_->set_drive(0, &drives_[0]); @@ -254,7 +255,7 @@ template class ConcreteMachin const auto result = scsi_.read(register_address); if(cycle.operation & Microcycle::SelectWord) { // Data is loaded on the top part of the bus only. - cycle.value->full = (result << 8) | 0xff; + cycle.value->full = uint16_t((result << 8) | 0xff); } else { cycle.value->halves.low = result; } @@ -310,7 +311,7 @@ template class ConcreteMachin if(word_address > ram_mask_ - 0x6c80) update_video(); - memory_base = ram_; + memory_base = ram_.data(); word_address &= ram_mask_; // Apply a delay due to video contention if applicable; technically this is @@ -766,8 +767,8 @@ template class ConcreteMachin uint32_t ram_mask_ = 0; uint32_t rom_mask_ = 0; - uint16_t rom_[64*1024]; - uint16_t ram_[256*1024]; + uint16_t rom_[64*1024]; // i.e. up to 128kb in size. + std::vector ram_; }; } diff --git a/Machines/Apple/Macintosh/Video.cpp b/Machines/Apple/Macintosh/Video.cpp index 0ab4ae4c5..e1b3254c8 100644 --- a/Machines/Apple/Macintosh/Video.cpp +++ b/Machines/Apple/Macintosh/Video.cpp @@ -33,11 +33,10 @@ const int sync_end = 38; // "The visible portion of a full-screen display consists of 342 horizontal scan lines... // During the vertical blanking interval, the turned-off beam ... traces out an additional 28 scan lines," // -Video::Video(uint16_t *ram, DeferredAudio &audio, DriveSpeedAccumulator &drive_speed_accumulator) : +Video::Video(DeferredAudio &audio, DriveSpeedAccumulator &drive_speed_accumulator) : audio_(audio), drive_speed_accumulator_(drive_speed_accumulator), - crt_(704, 1, 370, Outputs::Display::ColourSpace::YIQ, 1, 1, 6, false, Outputs::Display::InputDataType::Luminance1), - ram_(ram) { + crt_(704, 1, 370, Outputs::Display::ColourSpace::YIQ, 1, 1, 6, false, Outputs::Display::InputDataType::Luminance1) { crt_.set_display_type(Outputs::Display::DisplayType::RGB); crt_.set_visible_area(Outputs::Display::Rect(0.08f, -0.025f, 0.82f, 0.82f)); @@ -196,6 +195,7 @@ void Video::set_use_alternate_buffers(bool use_alternate_screen_buffer, bool use use_alternate_audio_buffer_ = use_alternate_audio_buffer; } -void Video::set_ram_mask(uint32_t mask) { +void Video::set_ram(uint16_t *ram, uint32_t mask) { + ram_ = ram; ram_mask_ = mask; } diff --git a/Machines/Apple/Macintosh/Video.hpp b/Machines/Apple/Macintosh/Video.hpp index 9b8bfd683..ab4d0bac8 100644 --- a/Machines/Apple/Macintosh/Video.hpp +++ b/Machines/Apple/Macintosh/Video.hpp @@ -29,7 +29,7 @@ class Video { Constructs an instance of @c Video sourcing its pixel data from @c ram and providing audio and drive-speed bytes to @c audio and @c drive_speed_accumulator. */ - Video(uint16_t *ram, DeferredAudio &audio, DriveSpeedAccumulator &drive_speed_accumulator); + Video(DeferredAudio &audio, DriveSpeedAccumulator &drive_speed_accumulator); /*! Sets the target device for video data. @@ -47,10 +47,10 @@ class Video { void set_use_alternate_buffers(bool use_alternate_screen_buffer, bool use_alternate_audio_buffer); /*! - Provides a mask indicating which parts of the generated video and audio/drive addresses are + Provides a base address and a mask indicating which parts of the generated video and audio/drive addresses are actually decoded, accessing *word-sized memory*; e.g. for a 128kb Macintosh this should be (1 << 16) - 1 = 0xffff. */ - void set_ram_mask(uint32_t); + void set_ram(uint16_t *ram, uint32_t mask); /*! @returns @c true if the video is currently outputting a vertical sync, @c false otherwise. diff --git a/Machines/Utility/MemoryFuzzer.cpp b/Machines/Utility/MemoryFuzzer.cpp index c423cc5d1..4bab8a062 100644 --- a/Machines/Utility/MemoryFuzzer.cpp +++ b/Machines/Utility/MemoryFuzzer.cpp @@ -26,7 +26,3 @@ void Memory::Fuzz(uint8_t *buffer, std::size_t size) { void Memory::Fuzz(uint16_t *buffer, std::size_t size) { Fuzz(reinterpret_cast(buffer), size * sizeof(uint16_t)); } - -void Memory::Fuzz(std::vector &buffer) { - Fuzz(buffer.data(), buffer.size()); -} diff --git a/Machines/Utility/MemoryFuzzer.hpp b/Machines/Utility/MemoryFuzzer.hpp index 9beecd2f6..a40406acd 100644 --- a/Machines/Utility/MemoryFuzzer.hpp +++ b/Machines/Utility/MemoryFuzzer.hpp @@ -22,7 +22,9 @@ void Fuzz(uint8_t *buffer, std::size_t size); void Fuzz(uint16_t *buffer, std::size_t size); /// Replaces all existing vector contents with random bytes. -void Fuzz(std::vector &buffer); +template void Fuzz(std::vector &buffer) { + Fuzz(reinterpret_cast(buffer.data()), buffer.size() * sizeof(buffer[0])); +} }