2016-09-06 10:39:40 +00:00
|
|
|
//
|
|
|
|
// CommodoreAnalyser.cpp
|
|
|
|
// Clock Signal
|
|
|
|
//
|
|
|
|
// Created by Thomas Harte on 06/09/2016.
|
2018-05-13 19:19:52 +00:00
|
|
|
// Copyright 2016 Thomas Harte. All rights reserved.
|
2016-09-06 10:39:40 +00:00
|
|
|
//
|
|
|
|
|
2016-09-15 23:24:59 +00:00
|
|
|
#include "StaticAnalyser.hpp"
|
2016-09-06 10:39:40 +00:00
|
|
|
|
2018-01-25 02:48:44 +00:00
|
|
|
#include "Disk.hpp"
|
2016-09-13 11:26:51 +00:00
|
|
|
#include "File.hpp"
|
2016-09-06 10:39:40 +00:00
|
|
|
#include "Tape.hpp"
|
2018-03-09 21:07:29 +00:00
|
|
|
#include "Target.hpp"
|
2018-01-25 02:48:44 +00:00
|
|
|
#include "../../../Storage/Cartridge/Encodings/CommodoreROM.hpp"
|
2019-03-02 23:07:05 +00:00
|
|
|
#include "../../../Outputs/Log.hpp"
|
2016-09-06 10:39:40 +00:00
|
|
|
|
2018-04-07 00:07:10 +00:00
|
|
|
#include <algorithm>
|
2017-05-06 23:55:42 +00:00
|
|
|
#include <sstream>
|
|
|
|
|
2018-01-25 02:48:44 +00:00
|
|
|
using namespace Analyser::Static::Commodore;
|
2016-09-06 10:39:40 +00:00
|
|
|
|
2018-01-24 03:18:16 +00:00
|
|
|
static std::vector<std::shared_ptr<Storage::Cartridge::Cartridge>>
|
|
|
|
Vic20CartridgesFrom(const std::vector<std::shared_ptr<Storage::Cartridge::Cartridge>> &cartridges) {
|
|
|
|
std::vector<std::shared_ptr<Storage::Cartridge::Cartridge>> vic20_cartridges;
|
2016-09-29 23:39:13 +00:00
|
|
|
|
2017-12-02 21:01:30 +00:00
|
|
|
for(const auto &cartridge : cartridges) {
|
|
|
|
const auto &segments = cartridge->get_segments();
|
2016-09-29 23:39:13 +00:00
|
|
|
|
|
|
|
// only one mapped item is allowed
|
|
|
|
if(segments.size() != 1) continue;
|
|
|
|
|
|
|
|
// which must be 16 kb in size
|
|
|
|
Storage::Cartridge::Cartridge::Segment segment = segments.front();
|
|
|
|
if(segment.start_address != 0xa000) continue;
|
|
|
|
if(!Storage::Cartridge::Encodings::CommodoreROM::isROM(segment.data)) continue;
|
|
|
|
|
|
|
|
vic20_cartridges.push_back(cartridge);
|
|
|
|
}
|
|
|
|
|
|
|
|
return vic20_cartridges;
|
|
|
|
}
|
|
|
|
|
2018-04-14 16:12:12 +00:00
|
|
|
Analyser::Static::TargetList Analyser::Static::Commodore::GetTargets(const Media &media, const std::string &file_name, TargetPlatform::IntType potential_platforms) {
|
2018-04-14 23:46:15 +00:00
|
|
|
TargetList destination;
|
2018-04-14 16:12:12 +00:00
|
|
|
|
2018-01-25 03:35:54 +00:00
|
|
|
std::unique_ptr<Target> target(new Target);
|
|
|
|
target->machine = Machine::Vic20; // TODO: machine estimation
|
2018-03-07 19:24:52 +00:00
|
|
|
target->confidence = 0.5; // TODO: a proper estimation
|
2016-09-06 10:39:40 +00:00
|
|
|
|
2016-09-13 11:26:51 +00:00
|
|
|
int device = 0;
|
2018-01-24 03:18:16 +00:00
|
|
|
std::vector<File> files;
|
2016-09-15 23:21:09 +00:00
|
|
|
bool is_disk = false;
|
2016-09-13 11:26:51 +00:00
|
|
|
|
2016-09-06 10:39:40 +00:00
|
|
|
// strip out inappropriate cartridges
|
2018-01-25 03:35:54 +00:00
|
|
|
target->media.cartridges = Vic20CartridgesFrom(media.cartridges);
|
2016-09-06 10:39:40 +00:00
|
|
|
|
2016-09-13 11:26:51 +00:00
|
|
|
// check disks
|
2017-08-17 14:48:29 +00:00
|
|
|
for(auto &disk : media.disks) {
|
2018-01-24 03:18:16 +00:00
|
|
|
std::vector<File> disk_files = GetFiles(disk);
|
2017-09-05 00:54:38 +00:00
|
|
|
if(!disk_files.empty()) {
|
2016-09-15 23:21:09 +00:00
|
|
|
is_disk = true;
|
2018-01-24 03:18:16 +00:00
|
|
|
files.insert(files.end(), disk_files.begin(), disk_files.end());
|
2018-01-25 03:35:54 +00:00
|
|
|
target->media.disks.push_back(disk);
|
2016-09-13 11:26:51 +00:00
|
|
|
if(!device) device = 8;
|
|
|
|
}
|
|
|
|
}
|
2016-09-07 11:39:47 +00:00
|
|
|
|
2016-09-13 11:26:51 +00:00
|
|
|
// check tapes
|
2017-08-17 14:48:29 +00:00
|
|
|
for(auto &tape : media.tapes) {
|
2018-01-24 03:18:16 +00:00
|
|
|
std::vector<File> tape_files = GetFiles(tape);
|
2017-07-13 01:34:08 +00:00
|
|
|
tape->reset();
|
2017-09-05 00:54:38 +00:00
|
|
|
if(!tape_files.empty()) {
|
2018-01-24 03:18:16 +00:00
|
|
|
files.insert(files.end(), tape_files.begin(), tape_files.end());
|
2018-01-25 03:35:54 +00:00
|
|
|
target->media.tapes.push_back(tape);
|
2016-09-13 11:26:51 +00:00
|
|
|
if(!device) device = 1;
|
|
|
|
}
|
|
|
|
}
|
2016-09-08 02:17:19 +00:00
|
|
|
|
2017-09-05 00:54:38 +00:00
|
|
|
if(!files.empty()) {
|
2018-03-09 21:07:29 +00:00
|
|
|
target->memory_model = Target::MemoryModel::Unexpanded;
|
2017-05-06 23:55:42 +00:00
|
|
|
std::ostringstream string_stream;
|
|
|
|
string_stream << "LOAD\"" << (is_disk ? "*" : "") << "\"," << device << ",";
|
2018-11-24 03:32:32 +00:00
|
|
|
if(files.front().is_basic()) {
|
2017-05-06 23:55:42 +00:00
|
|
|
string_stream << "0";
|
2017-03-26 18:34:47 +00:00
|
|
|
} else {
|
2017-05-06 23:55:42 +00:00
|
|
|
string_stream << "1";
|
2016-09-13 11:26:51 +00:00
|
|
|
}
|
2017-05-06 23:55:42 +00:00
|
|
|
string_stream << "\nRUN\n";
|
2018-01-25 03:35:54 +00:00
|
|
|
target->loading_command = string_stream.str();
|
2016-09-13 11:26:51 +00:00
|
|
|
|
|
|
|
// make a first guess based on loading address
|
2017-03-26 18:34:47 +00:00
|
|
|
switch(files.front().starting_address) {
|
2018-04-01 00:58:16 +00:00
|
|
|
default:
|
2019-03-02 23:07:05 +00:00
|
|
|
LOG("Unrecognised loading address for Commodore program: " << PADHEX(4) << files.front().starting_address);
|
2016-09-13 11:26:51 +00:00
|
|
|
case 0x1001:
|
2018-04-01 00:58:16 +00:00
|
|
|
target->memory_model = Target::MemoryModel::Unexpanded;
|
|
|
|
break;
|
2016-09-13 11:26:51 +00:00
|
|
|
case 0x1201:
|
2018-03-09 21:07:29 +00:00
|
|
|
target->memory_model = Target::MemoryModel::ThirtyTwoKB;
|
2016-09-13 11:26:51 +00:00
|
|
|
break;
|
|
|
|
case 0x0401:
|
2018-03-09 21:07:29 +00:00
|
|
|
target->memory_model = Target::MemoryModel::EightKB;
|
2016-09-13 11:26:51 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
// General approach: increase memory size conservatively such that the largest file found will fit.
|
2018-03-25 17:37:33 +00:00
|
|
|
// for(File &file : files) {
|
|
|
|
// std::size_t file_size = file.data.size();
|
2016-09-13 11:26:51 +00:00
|
|
|
// bool is_basic = file.is_basic();
|
2016-09-09 01:09:37 +00:00
|
|
|
|
2016-09-13 11:26:51 +00:00
|
|
|
/*if(is_basic)
|
2016-09-13 02:06:03 +00:00
|
|
|
{
|
2016-09-13 11:26:51 +00:00
|
|
|
// BASIC files may be relocated, so the only limit is size.
|
|
|
|
//
|
|
|
|
// An unexpanded machine has 3583 bytes free for BASIC;
|
|
|
|
// a 3kb expanded machine has 6655 bytes free.
|
|
|
|
if(file_size > 6655)
|
2018-01-25 03:35:54 +00:00
|
|
|
target->vic20.memory_model = Vic20MemoryModel::ThirtyTwoKB;
|
|
|
|
else if(target->vic20.memory_model == Vic20MemoryModel::Unexpanded && file_size > 3583)
|
|
|
|
target->vic20.memory_model = Vic20MemoryModel::EightKB;
|
2016-09-13 02:06:03 +00:00
|
|
|
}
|
2016-09-13 11:26:51 +00:00
|
|
|
else
|
|
|
|
{*/
|
|
|
|
// if(!file.type == File::NonRelocatableProgram)
|
|
|
|
// {
|
|
|
|
// Non-BASIC files may be relocatable but, if so, by what logic?
|
|
|
|
// Given that this is unknown, take starting address as literal
|
|
|
|
// and check against memory windows.
|
|
|
|
//
|
|
|
|
// (ignoring colour memory...)
|
|
|
|
// An unexpanded Vic has memory between 0x0000 and 0x0400; and between 0x1000 and 0x2000.
|
|
|
|
// A 3kb expanded Vic fills in the gap and has memory between 0x0000 and 0x2000.
|
|
|
|
// A 32kb expanded Vic has memory in the entire low 32kb.
|
2018-03-25 17:37:33 +00:00
|
|
|
// uint16_t starting_address = file.starting_address;
|
2016-09-09 01:09:37 +00:00
|
|
|
|
2016-09-13 11:26:51 +00:00
|
|
|
// If anything above the 8kb mark is touched, mark as a 32kb machine; otherwise if the
|
|
|
|
// region 0x0400 to 0x1000 is touched and this is an unexpanded machine, mark as 3kb.
|
2018-03-25 17:37:33 +00:00
|
|
|
// if(starting_address + file_size > 0x2000)
|
|
|
|
// target->memory_model = Target::MemoryModel::ThirtyTwoKB;
|
|
|
|
// else if(target->memory_model == Target::MemoryModel::Unexpanded && !(starting_address >= 0x1000 || starting_address+file_size < 0x0400))
|
|
|
|
// target->memory_model = Target::MemoryModel::ThirtyTwoKB;
|
2016-09-13 11:26:51 +00:00
|
|
|
// }
|
2018-03-25 17:37:33 +00:00
|
|
|
// }
|
2016-09-06 10:39:40 +00:00
|
|
|
}
|
2016-09-07 11:39:47 +00:00
|
|
|
|
2018-04-06 21:42:24 +00:00
|
|
|
if(!target->media.empty()) {
|
|
|
|
// Inspect filename for a region hint.
|
|
|
|
std::string lowercase_name = file_name;
|
|
|
|
std::transform(lowercase_name.begin(), lowercase_name.end(), lowercase_name.begin(), ::tolower);
|
|
|
|
if(lowercase_name.find("ntsc") != std::string::npos) {
|
|
|
|
target->region = Analyser::Static::Commodore::Target::Region::American;
|
|
|
|
}
|
|
|
|
|
2018-04-08 21:37:39 +00:00
|
|
|
// Attach a 1540 if there are any disks here.
|
|
|
|
target->has_c1540 = !target->media.disks.empty();
|
|
|
|
|
2018-01-25 03:35:54 +00:00
|
|
|
destination.push_back(std::move(target));
|
2018-04-06 21:42:24 +00:00
|
|
|
}
|
2018-04-14 16:12:12 +00:00
|
|
|
|
|
|
|
return destination;
|
2016-09-08 02:17:19 +00:00
|
|
|
}
|