1
0
mirror of https://github.com/TomHarte/CLK.git synced 2024-11-25 16:31:42 +00:00

Corrects warnings in the CSW, CPC DSK, ZX8081 data encoding, and PRG and binary cartridges.

This commit is contained in:
Thomas Harte 2017-11-12 17:46:06 -05:00
parent d2ba7d7430
commit 792061a82b
5 changed files with 18 additions and 13 deletions

View File

@ -19,12 +19,12 @@ BinaryDump::BinaryDump(const char *file_name) {
stat(file_name, &file_stats);
// grab contents
FILE *file = fopen(file_name, "rb");
FILE *file = std::fopen(file_name, "rb");
if(!file) throw ErrorNotAccessible;
std::size_t data_length = static_cast<std::size_t>(file_stats.st_size);
std::vector<uint8_t> contents(data_length);
fread(&contents[0], 1, static_cast<std::size_t>(data_length), file);
fclose(file);
contents.resize(std::fread(&contents[0], 1, static_cast<std::size_t>(data_length), file));
std::fclose(file);
// enshrine
segments_.emplace_back(

View File

@ -10,6 +10,7 @@
#include <cstdio>
#include <sys/stat.h>
#include "../Encodings/CommodoreROM.hpp"
using namespace Storage::Cartridge;
@ -23,7 +24,7 @@ PRG::PRG(const char *file_name) {
throw ErrorNotROM;
// get the loading address, and the rest of the contents
FILE *file = fopen(file_name, "rb");
FILE *file = std::fopen(file_name, "rb");
int loading_address = fgetc(file);
loading_address |= fgetc(file) << 8;
@ -32,11 +33,11 @@ PRG::PRG(const char *file_name) {
std::size_t padded_data_length = 1;
while(padded_data_length < data_length) padded_data_length <<= 1;
std::vector<uint8_t> contents(padded_data_length);
fread(&contents[0], 1, static_cast<std::size_t>(data_length), file);
fclose(file);
std::size_t length = std::fread(contents.data(), 1, static_cast<std::size_t>(data_length), file);
std::fclose(file);
// accept only files intended to load at 0xa000
if(loading_address != 0xa000)
if(loading_address != 0xa000 || length != static_cast<std::size_t>(data_length))
throw ErrorNotROM;
// also accept only cartridges with the proper signature

View File

@ -27,7 +27,7 @@ static std::shared_ptr<File> ZX80FileFromData(const std::vector<uint8_t> &data)
uint16_t display_address = short_at(0xc, data);
// check that the end of file is contained within the supplied data
if(end_of_file - 0x4000 > data.size()) return nullptr;
if(static_cast<size_t>(end_of_file - 0x4000) > data.size()) return nullptr;
// check for the proper ordering of buffers
if(vars > end_of_file) return nullptr;

View File

@ -365,7 +365,7 @@ void CPCDSK::set_tracks(const std::map<::Storage::Disk::Track::Address, std::sha
}
// Move to next 256-byte boundary.
long distance = (256 - output.tell()&255)&255;
long distance = (256 - (output.tell()&255))&255;
output.putn(static_cast<std::size_t>(distance), 0);
// Output sector contents.
@ -376,7 +376,7 @@ void CPCDSK::set_tracks(const std::map<::Storage::Disk::Track::Address, std::sha
}
// Move to next 256-byte boundary.
distance = (256 - output.tell()&255)&255;
distance = (256 - (output.tell()&255))&255;
output.putn(static_cast<std::size_t>(distance), 0);
}
}

View File

@ -8,6 +8,8 @@
#include "CSW.hpp"
#include <cassert>
using namespace Storage::Tape;
CSW::CSW(const char *file_name) :
@ -90,6 +92,8 @@ uint8_t CSW::get_next_byte() {
source_data_pointer_++;
return result;
}
default: assert(false); break;
}
}
@ -107,7 +111,7 @@ uint32_t CSW::get_next_int32le() {
return result;
}
default: return 0;
default: assert(false); break;
}
}
@ -120,7 +124,7 @@ bool CSW::is_at_end() {
case CompressionType::RLE: return file_.eof();
case CompressionType::ZRLE: return source_data_pointer_ == source_data_.size();
default: return true;
default: assert(false); break;
}
}
@ -129,7 +133,7 @@ void CSW::virtual_reset() {
case CompressionType::RLE: file_.seek(rle_start_, SEEK_SET); break;
case CompressionType::ZRLE: source_data_pointer_ = 0; break;
default: break;
default: assert(false); break;
}
}