2018-05-04 22:02:36 +00:00
|
|
|
//
|
|
|
|
// StaticAnalyser.cpp
|
|
|
|
// Clock Signal
|
|
|
|
//
|
|
|
|
// Created by Thomas Harte on 03/05/2018.
|
2018-05-13 19:19:52 +00:00
|
|
|
// Copyright 2018 Thomas Harte. All rights reserved.
|
2018-05-04 22:02:36 +00:00
|
|
|
//
|
|
|
|
|
|
|
|
#include "StaticAnalyser.hpp"
|
2018-05-05 23:32:08 +00:00
|
|
|
|
2018-05-04 22:02:36 +00:00
|
|
|
#include "../AppleII/Target.hpp"
|
2020-11-12 22:35:27 +00:00
|
|
|
#include "../AppleIIgs/Target.hpp"
|
2018-05-05 23:32:08 +00:00
|
|
|
#include "../Oric/Target.hpp"
|
|
|
|
#include "../Disassembler/6502.hpp"
|
|
|
|
#include "../Disassembler/AddressMapper.hpp"
|
2018-05-04 22:02:36 +00:00
|
|
|
|
2018-05-05 03:11:12 +00:00
|
|
|
#include "../../../Storage/Disk/Track/TrackSerialiser.hpp"
|
|
|
|
#include "../../../Storage/Disk/Encodings/AppleGCR/SegmentParser.hpp"
|
|
|
|
|
2018-05-05 23:32:08 +00:00
|
|
|
namespace {
|
|
|
|
|
2020-11-12 22:35:27 +00:00
|
|
|
Analyser::Static::Target *AppleIITarget(const Storage::Encodings::AppleGCR::Sector *sector_zero) {
|
2018-05-05 23:32:08 +00:00
|
|
|
using Target = Analyser::Static::AppleII::Target;
|
2020-03-26 01:25:50 +00:00
|
|
|
auto *const target = new Target;
|
2018-05-05 23:32:08 +00:00
|
|
|
|
|
|
|
if(sector_zero && sector_zero->encoding == Storage::Encodings::AppleGCR::Sector::Encoding::FiveAndThree) {
|
|
|
|
target->disk_controller = Target::DiskController::ThirteenSector;
|
|
|
|
} else {
|
|
|
|
target->disk_controller = Target::DiskController::SixteenSector;
|
|
|
|
}
|
|
|
|
|
|
|
|
return target;
|
|
|
|
}
|
|
|
|
|
2020-11-12 22:35:27 +00:00
|
|
|
Analyser::Static::Target *AppleIIgsTarget() {
|
|
|
|
return new Analyser::Static::AppleIIgs::Target();
|
|
|
|
}
|
|
|
|
|
2020-05-30 04:58:10 +00:00
|
|
|
Analyser::Static::Target *OricTarget(const Storage::Encodings::AppleGCR::Sector *) {
|
2018-05-05 23:32:08 +00:00
|
|
|
using Target = Analyser::Static::Oric::Target;
|
2020-03-26 01:25:50 +00:00
|
|
|
auto *const target = new Target;
|
2018-05-09 02:05:43 +00:00
|
|
|
target->rom = Target::ROM::Pravetz;
|
|
|
|
target->disk_interface = Target::DiskInterface::Pravetz;
|
2018-05-13 23:30:44 +00:00
|
|
|
target->loading_command = "CALL 800\n";
|
2018-05-05 23:32:08 +00:00
|
|
|
return target;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2024-11-30 02:08:35 +00:00
|
|
|
Analyser::Static::TargetList Analyser::Static::DiskII::GetTargets(
|
|
|
|
const Media &media,
|
|
|
|
const std::string &,
|
|
|
|
TargetPlatform::IntType
|
|
|
|
) {
|
2018-05-05 03:11:12 +00:00
|
|
|
// This analyser can comprehend disks only.
|
|
|
|
if(media.disks.empty()) return {};
|
|
|
|
|
2020-11-12 22:35:27 +00:00
|
|
|
auto &disk = media.disks.front();
|
|
|
|
TargetList targets;
|
|
|
|
|
|
|
|
// If the disk image is too large for a 5.25" disk, map this to the IIgs.
|
|
|
|
if(disk->get_maximum_head_position() > Storage::Disk::HeadPosition(40)) {
|
|
|
|
targets.push_back(std::unique_ptr<Analyser::Static::Target>(AppleIIgsTarget()));
|
|
|
|
targets.back()->media = media;
|
|
|
|
return targets;
|
|
|
|
}
|
|
|
|
|
2018-05-05 23:32:08 +00:00
|
|
|
// Grab track 0, sector 0: the boot sector.
|
2024-11-30 02:08:35 +00:00
|
|
|
const auto track_zero =
|
|
|
|
disk->get_track_at_position(Storage::Disk::Track::Address(0, Storage::Disk::HeadPosition(0)));
|
2020-03-26 01:25:50 +00:00
|
|
|
const auto sector_map = Storage::Encodings::AppleGCR::sectors_from_segment(
|
2018-05-05 03:11:12 +00:00
|
|
|
Storage::Disk::track_serialisation(*track_zero, Storage::Time(1, 50000)));
|
|
|
|
|
2018-05-05 20:37:33 +00:00
|
|
|
const Storage::Encodings::AppleGCR::Sector *sector_zero = nullptr;
|
|
|
|
for(const auto &pair: sector_map) {
|
|
|
|
if(!pair.second.address.sector) {
|
|
|
|
sector_zero = &pair.second;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2018-05-04 22:02:36 +00:00
|
|
|
|
2018-05-05 23:32:08 +00:00
|
|
|
// If there's no boot sector then if there are also no sectors at all,
|
|
|
|
// decline to nominate a machine. Otherwise go with an Apple as the default.
|
|
|
|
if(!sector_zero) {
|
|
|
|
if(sector_map.empty()) {
|
|
|
|
return targets;
|
|
|
|
} else {
|
2020-11-12 22:35:27 +00:00
|
|
|
targets.push_back(std::unique_ptr<Analyser::Static::Target>(AppleIITarget(nullptr)));
|
2018-05-06 00:32:47 +00:00
|
|
|
targets.back()->media = media;
|
2018-05-05 23:32:08 +00:00
|
|
|
return targets;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// If the boot sector looks like it's intended for the Oric, create an Oric.
|
|
|
|
// Otherwise go with the Apple II.
|
|
|
|
|
2024-11-30 02:08:35 +00:00
|
|
|
const auto disassembly = Analyser::Static::MOS6502::Disassemble(
|
|
|
|
sector_zero->data, Analyser::Static::Disassembler::OffsetMapper(0xb800), {0xb800});
|
2018-05-05 23:32:08 +00:00
|
|
|
|
|
|
|
bool did_read_shift_register = false;
|
|
|
|
bool is_oric = false;
|
|
|
|
|
|
|
|
// Look for a tight BPL loop reading the Oric's shift register address of 0x31c. The Apple II just has RAM there,
|
|
|
|
// so the probability of such a loop is infinitesimal.
|
|
|
|
for(const auto &instruction: disassembly.instructions_by_address) {
|
|
|
|
// Is this a read of the shift register?
|
|
|
|
if(
|
|
|
|
(
|
|
|
|
(instruction.second.operation == Analyser::Static::MOS6502::Instruction::LDA) ||
|
|
|
|
(instruction.second.operation == Analyser::Static::MOS6502::Instruction::LDX) ||
|
|
|
|
(instruction.second.operation == Analyser::Static::MOS6502::Instruction::LDY)
|
|
|
|
) &&
|
|
|
|
instruction.second.addressing_mode == Analyser::Static::MOS6502::Instruction::Absolute &&
|
|
|
|
instruction.second.address == 0x031c) {
|
|
|
|
did_read_shift_register = true;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(did_read_shift_register) {
|
|
|
|
if(
|
|
|
|
instruction.second.operation == Analyser::Static::MOS6502::Instruction::BPL &&
|
|
|
|
instruction.second.address == 0xfb) {
|
|
|
|
is_oric = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
did_read_shift_register = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Check also for calls into the 0x3xx page above 0x320, as that's where the Oric's boot ROM is.
|
|
|
|
for(const auto address: disassembly.outward_calls) {
|
|
|
|
is_oric |= address >= 0x320 && address < 0x400;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(is_oric) {
|
|
|
|
targets.push_back(std::unique_ptr<Analyser::Static::Target>(OricTarget(sector_zero)));
|
|
|
|
} else {
|
2020-11-12 22:35:27 +00:00
|
|
|
targets.push_back(std::unique_ptr<Analyser::Static::Target>(AppleIITarget(sector_zero)));
|
2018-05-05 23:32:08 +00:00
|
|
|
}
|
2018-05-06 00:32:47 +00:00
|
|
|
targets.back()->media = media;
|
2018-05-04 22:02:36 +00:00
|
|
|
return targets;
|
|
|
|
}
|