mirror of
https://github.com/TomHarte/CLK.git
synced 2024-11-23 03:32:32 +00:00
Merge pull request #190 from TomHarte/SingleImplicit
Corrects a couple of CPC static analysis pitfalls
This commit is contained in:
commit
ad3c9842d7
@ -9,6 +9,16 @@
|
|||||||
#include "StaticAnalyser.hpp"
|
#include "StaticAnalyser.hpp"
|
||||||
#include "../../Storage/Disk/Parsers/CPM.hpp"
|
#include "../../Storage/Disk/Parsers/CPM.hpp"
|
||||||
|
|
||||||
|
static bool strcmp_insensitive(const char *a, const char *b) {
|
||||||
|
if(strlen(a) != strlen(b)) return false;
|
||||||
|
while(*a) {
|
||||||
|
if(tolower(*a) != towlower(*b)) return false;
|
||||||
|
a++;
|
||||||
|
b++;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
static void InspectDataCatalogue(
|
static void InspectDataCatalogue(
|
||||||
const std::unique_ptr<Storage::Disk::CPM::Catalogue> &data_catalogue,
|
const std::unique_ptr<Storage::Disk::CPM::Catalogue> &data_catalogue,
|
||||||
StaticAnalyser::Target &target) {
|
StaticAnalyser::Target &target) {
|
||||||
@ -18,27 +28,33 @@ static void InspectDataCatalogue(
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// If only one file is [potentially] BASIC, run that one; otherwise if only one has no suffix,
|
// If only one file is [potentially] BASIC, run that one; otherwise if only one has a suffix
|
||||||
// pick that one.
|
// that AMSDOS allows to be omitted, pick that one.
|
||||||
int basic_files = 0;
|
int basic_files = 0;
|
||||||
int nonsuffixed_files = 0;
|
int implicit_suffixed_files = 0;
|
||||||
|
|
||||||
size_t last_basic_file = 0;
|
size_t last_basic_file = 0;
|
||||||
size_t last_nonsuffixed_file = 0;
|
size_t last_implicit_suffixed_file = 0;
|
||||||
|
|
||||||
for(size_t c = 0; c < data_catalogue->files.size(); c++) {
|
for(size_t c = 0; c < data_catalogue->files.size(); c++) {
|
||||||
// Check for whether this is [potentially] BASIC.
|
// Check for whether this is [potentially] BASIC.
|
||||||
if(!((data_catalogue->files[c].data[18] >> 1) & 7)) {
|
if(data_catalogue->files[c].data.size() >= 128 && !((data_catalogue->files[c].data[18] >> 1) & 7)) {
|
||||||
basic_files++;
|
basic_files++;
|
||||||
last_basic_file = c;
|
last_basic_file = c;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check suffix for emptiness.
|
// Check suffix for emptiness.
|
||||||
if(data_catalogue->files[c].type == " ") {
|
if(
|
||||||
nonsuffixed_files++;
|
data_catalogue->files[c].type == " " ||
|
||||||
last_nonsuffixed_file = c;
|
strcmp_insensitive(data_catalogue->files[c].type.c_str(), "BAS") ||
|
||||||
|
strcmp_insensitive(data_catalogue->files[c].type.c_str(), "BIN")
|
||||||
|
) {
|
||||||
|
implicit_suffixed_files++;
|
||||||
|
last_implicit_suffixed_file = c;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(basic_files == 1 || nonsuffixed_files == 1) {
|
if(basic_files == 1 || implicit_suffixed_files == 1) {
|
||||||
size_t selected_file = (basic_files == 1) ? last_basic_file : last_nonsuffixed_file;
|
size_t selected_file = (basic_files == 1) ? last_basic_file : last_implicit_suffixed_file;
|
||||||
target.loadingCommand = "run\"" + data_catalogue->files[selected_file].name + "\n";
|
target.loadingCommand = "run\"" + data_catalogue->files[selected_file].name + "\n";
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -432,10 +432,10 @@ std::shared_ptr<Sector> Parser::get_next_sector() {
|
|||||||
sector->track = get_next_byte();
|
sector->track = get_next_byte();
|
||||||
sector->side = get_next_byte();
|
sector->side = get_next_byte();
|
||||||
sector->sector = get_next_byte();
|
sector->sector = get_next_byte();
|
||||||
uint8_t size = get_next_byte();
|
sector->size = get_next_byte();
|
||||||
uint16_t header_crc = crc_generator_.get_value();
|
uint16_t header_crc = crc_generator_.get_value();
|
||||||
if((header_crc >> 8) != get_next_byte()) continue;
|
if((header_crc >> 8) != get_next_byte()) sector->has_header_crc_error = true;
|
||||||
if((header_crc & 0xff) != get_next_byte()) continue;
|
if((header_crc & 0xff) != get_next_byte()) sector->has_header_crc_error = true;
|
||||||
|
|
||||||
// look for data mark
|
// look for data mark
|
||||||
bool data_found = false;
|
bool data_found = false;
|
||||||
@ -462,14 +462,14 @@ std::shared_ptr<Sector> Parser::get_next_sector() {
|
|||||||
}
|
}
|
||||||
crc_generator_.add(DataAddressByte);
|
crc_generator_.add(DataAddressByte);
|
||||||
|
|
||||||
size_t data_size = (size_t)(128 << size);
|
size_t data_size = (size_t)(128 << sector->size);
|
||||||
sector->data.reserve(data_size);
|
sector->data.reserve(data_size);
|
||||||
for(size_t c = 0; c < data_size; c++) {
|
for(size_t c = 0; c < data_size; c++) {
|
||||||
sector->data.push_back(get_next_byte());
|
sector->data.push_back(get_next_byte());
|
||||||
}
|
}
|
||||||
uint16_t data_crc = crc_generator_.get_value();
|
uint16_t data_crc = crc_generator_.get_value();
|
||||||
if((data_crc >> 8) != get_next_byte()) continue;
|
if((data_crc >> 8) != get_next_byte()) sector->has_data_crc_error = true;
|
||||||
if((data_crc & 0xff) != get_next_byte()) continue;
|
if((data_crc & 0xff) != get_next_byte()) sector->has_data_crc_error = true;
|
||||||
|
|
||||||
// Put this sector into the cache.
|
// Put this sector into the cache.
|
||||||
int index = get_index(head_, track_, sector->sector);
|
int index = get_index(head_, track_, sector->sector);
|
||||||
|
Loading…
Reference in New Issue
Block a user