mirror of
https://github.com/TomHarte/CLK.git
synced 2025-04-14 03:37:04 +00:00
Merge pull request #272 from TomHarte/UnusedResults
Resolves all GCC warnings
This commit is contained in:
commit
ebdb80c908
@ -111,7 +111,7 @@ void WD1770::run_for(const Cycles cycles) {
|
||||
#define WAIT_FOR_TIME(ms) resume_point_ = __LINE__; delay_time_ = ms * 8000; WAIT_FOR_EVENT(Event1770::Timer);
|
||||
#define WAIT_FOR_BYTES(count) resume_point_ = __LINE__; distance_into_section_ = 0; WAIT_FOR_EVENT(Event::Token); if(get_latest_token().type == Token::Byte) distance_into_section_++; if(distance_into_section_ < count) { interesting_event_mask_ = static_cast<int>(Event::Token); return; }
|
||||
#define BEGIN_SECTION() switch(resume_point_) { default:
|
||||
#define END_SECTION() 0; }
|
||||
#define END_SECTION() (void)0; }
|
||||
|
||||
#define READ_ID() \
|
||||
if(new_event_type == static_cast<int>(Event::Token)) { \
|
||||
@ -656,7 +656,6 @@ void WD1770::posit_event(int new_event_type) {
|
||||
status.lost_data = false;
|
||||
});
|
||||
|
||||
write_track_test_write_protect:
|
||||
if(get_drive().get_is_read_only()) {
|
||||
update_status([] (Status &status) {
|
||||
status.write_protect = true;
|
||||
|
@ -42,7 +42,7 @@ class Speaker: public ::Outputs::Filter<Speaker> {
|
||||
template <class T> class MOS6560 {
|
||||
public:
|
||||
MOS6560() :
|
||||
crt_(new Outputs::CRT::CRT(65*4, 4, Outputs::CRT::NTSC60, 2)),
|
||||
crt_(new Outputs::CRT::CRT(65*4, 4, Outputs::CRT::DisplayType::NTSC60, 2)),
|
||||
speaker_(new Speaker) {
|
||||
crt_->set_composite_sampling_function(
|
||||
"float composite_sample(usampler2D texID, vec2 coordinate, vec2 iCoordinate, float phase, float amplitude)"
|
||||
@ -102,9 +102,9 @@ template <class T> class MOS6560 {
|
||||
Outputs::CRT::DisplayType display_type;
|
||||
|
||||
switch(output_mode) {
|
||||
case OutputMode::PAL:
|
||||
default:
|
||||
chrominances = pal_chrominances;
|
||||
display_type = Outputs::CRT::PAL50;
|
||||
display_type = Outputs::CRT::DisplayType::PAL50;
|
||||
timing_.cycles_per_line = 71;
|
||||
timing_.line_counter_increment_offset = 0;
|
||||
timing_.lines_per_progressive_field = 312;
|
||||
@ -113,7 +113,7 @@ template <class T> class MOS6560 {
|
||||
|
||||
case OutputMode::NTSC:
|
||||
chrominances = ntsc_chrominances;
|
||||
display_type = Outputs::CRT::NTSC60;
|
||||
display_type = Outputs::CRT::DisplayType::NTSC60;
|
||||
timing_.cycles_per_line = 65;
|
||||
timing_.line_counter_increment_offset = 65 - 33; // TODO: this is a bit of a hack; separate vertical and horizontal counting
|
||||
timing_.lines_per_progressive_field = 261;
|
||||
|
@ -210,7 +210,7 @@ uint8_t i8272::get_register(int address) {
|
||||
else if(get_latest_token().type == Token::ID) goto CONCAT(header_found, __LINE__); \
|
||||
\
|
||||
if(index_hole_limit_) goto CONCAT(find_header, __LINE__); \
|
||||
CONCAT(header_found, __LINE__): 0;\
|
||||
CONCAT(header_found, __LINE__): (void)0;\
|
||||
|
||||
#define FIND_DATA() \
|
||||
set_data_mode(DataMode::Scanning); \
|
||||
@ -563,7 +563,6 @@ void i8272::posit_event(int event_type) {
|
||||
// Sets a maximum index hole limit of 2 then waits either until it finds a header mark or sees too many index holes.
|
||||
// If a header mark is found, reads in the following bytes that produce a header. Otherwise branches to data not found.
|
||||
index_hole_limit_ = 2;
|
||||
read_id_find_next_sector:
|
||||
FIND_HEADER();
|
||||
if(!index_hole_limit_) {
|
||||
SetMissingAddressMark();
|
||||
|
@ -300,7 +300,7 @@ class CRTCBusHandler {
|
||||
"return vec3(float((sample >> 4) & 3u), float((sample >> 2) & 3u), float(sample & 3u)) / 2.0;"
|
||||
"}");
|
||||
crt_->set_visible_area(Outputs::CRT::Rect(0.075f, 0.05f, 0.9f, 0.9f));
|
||||
crt_->set_output_device(Outputs::CRT::Monitor);
|
||||
crt_->set_output_device(Outputs::CRT::OutputDevice::Monitor);
|
||||
}
|
||||
|
||||
/// Destructs the CRT.
|
||||
|
@ -23,7 +23,7 @@ namespace {
|
||||
TIA::TIA(bool create_crt) {
|
||||
if(create_crt) {
|
||||
crt_.reset(new Outputs::CRT::CRT(cycles_per_line * 2 - 1, 1, Outputs::CRT::DisplayType::NTSC60, 1));
|
||||
crt_->set_output_device(Outputs::CRT::Television);
|
||||
crt_->set_output_device(Outputs::CRT::OutputDevice::Television);
|
||||
set_output_mode(OutputMode::NTSC);
|
||||
}
|
||||
|
||||
|
@ -19,6 +19,7 @@ const char *::Commodore::Serial::StringForLine(Line line) {
|
||||
case Clock: return "Clock";
|
||||
case Data: return "Data";
|
||||
case Reset: return "Reset";
|
||||
default: return nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -456,6 +456,10 @@ class ConcreteMachine:
|
||||
ROM character_rom;
|
||||
ROM kernel_rom;
|
||||
switch(region_) {
|
||||
default:
|
||||
character_rom = CharactersEnglish;
|
||||
kernel_rom = KernelPAL;
|
||||
break;
|
||||
case American:
|
||||
character_rom = CharactersEnglish;
|
||||
kernel_rom = KernelNTSC;
|
||||
@ -468,10 +472,6 @@ class ConcreteMachine:
|
||||
character_rom = CharactersJapanese;
|
||||
kernel_rom = KernelJapanese;
|
||||
break;
|
||||
case European:
|
||||
character_rom = CharactersEnglish;
|
||||
kernel_rom = KernelPAL;
|
||||
break;
|
||||
case Swedish:
|
||||
character_rom = CharactersSwedish;
|
||||
kernel_rom = KernelSwedish;
|
||||
|
@ -41,7 +41,7 @@ VideoOutput::VideoOutput(uint8_t *memory) :
|
||||
);
|
||||
crt_->set_composite_function_type(Outputs::CRT::CRT::CompositeSourceType::DiscreteFourSamplesPerCycle, 0.0f);
|
||||
|
||||
set_output_device(Outputs::CRT::Television);
|
||||
set_output_device(Outputs::CRT::OutputDevice::Television);
|
||||
crt_->set_visible_area(crt_->get_rect_for_area(53, 224, 16 * 6, 40 * 6, 4.0f / 3.0f));
|
||||
}
|
||||
|
||||
@ -129,7 +129,7 @@ void VideoOutput::run_for(const Cycles cycles) {
|
||||
if(control_byte & 0x60) {
|
||||
if(pixel_target_) {
|
||||
uint16_t colours[2];
|
||||
if(output_device_ == Outputs::CRT::Monitor) {
|
||||
if(output_device_ == Outputs::CRT::OutputDevice::Monitor) {
|
||||
colours[0] = static_cast<uint8_t>(paper_ ^ inverse_mask);
|
||||
colours[1] = static_cast<uint8_t>(ink_ ^ inverse_mask);
|
||||
} else {
|
||||
@ -183,7 +183,7 @@ void VideoOutput::run_for(const Cycles cycles) {
|
||||
pixel_target_[0] = pixel_target_[1] =
|
||||
pixel_target_[2] = pixel_target_[3] =
|
||||
pixel_target_[4] = pixel_target_[5] =
|
||||
(output_device_ == Outputs::CRT::Monitor) ? paper_ ^ inverse_mask : colour_forms_[paper_ ^ inverse_mask];
|
||||
(output_device_ == Outputs::CRT::OutputDevice::Monitor) ? paper_ ^ inverse_mask : colour_forms_[paper_ ^ inverse_mask];
|
||||
}
|
||||
}
|
||||
if(pixel_target_) pixel_target_ += 6;
|
||||
|
@ -51,6 +51,8 @@ template<typename T> class TypedDynamicMachine: public ::Machine::DynamicMachine
|
||||
case StaticAnalyser::Target::Oric: return new TypedDynamicMachine<Oric::Machine>(Oric::Machine::Oric());
|
||||
case StaticAnalyser::Target::Vic20: return new TypedDynamicMachine<Commodore::Vic20::Machine>(Commodore::Vic20::Machine::Vic20());
|
||||
case StaticAnalyser::Target::ZX8081: return new TypedDynamicMachine<ZX8081::Machine>(ZX8081::Machine::ZX8081(target));
|
||||
|
||||
default: return nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
@ -62,5 +64,7 @@ std::string Machine::NameForTarget(const StaticAnalyser::Target &target) {
|
||||
case StaticAnalyser::Target::Oric: return "Oric";
|
||||
case StaticAnalyser::Target::Vic20: return "Vic20";
|
||||
case StaticAnalyser::Target::ZX8081: return "ZX8081";
|
||||
|
||||
default: return "";
|
||||
}
|
||||
}
|
||||
|
@ -3644,11 +3644,15 @@
|
||||
"$(USER_LIBRARY_DIR)/Frameworks",
|
||||
);
|
||||
GCC_TREAT_IMPLICIT_FUNCTION_DECLARATIONS_AS_ERRORS = YES;
|
||||
GCC_TREAT_INCOMPATIBLE_POINTER_TYPE_WARNINGS_AS_ERRORS = YES;
|
||||
GCC_WARN_ABOUT_MISSING_NEWLINE = YES;
|
||||
GCC_WARN_ABOUT_MISSING_PROTOTYPES = YES;
|
||||
GCC_WARN_FOUR_CHARACTER_CONSTANTS = YES;
|
||||
GCC_WARN_INITIALIZER_NOT_FULLY_BRACKETED = YES;
|
||||
GCC_WARN_SHADOW = YES;
|
||||
GCC_WARN_SIGN_COMPARE = YES;
|
||||
GCC_WARN_UNKNOWN_PRAGMAS = YES;
|
||||
GCC_WARN_UNUSED_LABEL = YES;
|
||||
INFOPLIST_FILE = "Clock Signal/Info.plist";
|
||||
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks";
|
||||
OTHER_CPLUSPLUSFLAGS = (
|
||||
@ -3682,11 +3686,15 @@
|
||||
"$(USER_LIBRARY_DIR)/Frameworks",
|
||||
);
|
||||
GCC_TREAT_IMPLICIT_FUNCTION_DECLARATIONS_AS_ERRORS = YES;
|
||||
GCC_TREAT_INCOMPATIBLE_POINTER_TYPE_WARNINGS_AS_ERRORS = YES;
|
||||
GCC_WARN_ABOUT_MISSING_NEWLINE = YES;
|
||||
GCC_WARN_ABOUT_MISSING_PROTOTYPES = YES;
|
||||
GCC_WARN_FOUR_CHARACTER_CONSTANTS = YES;
|
||||
GCC_WARN_INITIALIZER_NOT_FULLY_BRACKETED = YES;
|
||||
GCC_WARN_SHADOW = YES;
|
||||
GCC_WARN_SIGN_COMPARE = YES;
|
||||
GCC_WARN_UNKNOWN_PRAGMAS = YES;
|
||||
GCC_WARN_UNUSED_LABEL = YES;
|
||||
INFOPLIST_FILE = "Clock Signal/Info.plist";
|
||||
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks";
|
||||
OTHER_CPLUSPLUSFLAGS = (
|
||||
|
@ -41,7 +41,7 @@
|
||||
- (void)setUseTelevisionOutput:(BOOL)useTelevisionOutput {
|
||||
@synchronized(self) {
|
||||
_useTelevisionOutput = useTelevisionOutput;
|
||||
_electron->get_crt()->set_output_device(useTelevisionOutput ? Outputs::CRT::Television : Outputs::CRT::Monitor);
|
||||
_electron->get_crt()->set_output_device(useTelevisionOutput ? Outputs::CRT::OutputDevice::Television : Outputs::CRT::OutputDevice::Monitor);
|
||||
}
|
||||
}
|
||||
@end
|
||||
|
@ -36,7 +36,7 @@
|
||||
- (void)setUseCompositeOutput:(BOOL)useCompositeOutput {
|
||||
@synchronized(self) {
|
||||
_useCompositeOutput = useCompositeOutput;
|
||||
_oric->set_output_device(useCompositeOutput ? Outputs::CRT::Television : Outputs::CRT::Monitor);
|
||||
_oric->set_output_device(useCompositeOutput ? Outputs::CRT::OutputDevice::Television : Outputs::CRT::OutputDevice::Monitor);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -69,7 +69,8 @@ SOURCES += glob.glob('../../Storage/Tape/Formats/*.cpp')
|
||||
SOURCES += glob.glob('../../Storage/Tape/Parsers/*.cpp')
|
||||
|
||||
# add additional compiler flags
|
||||
env.Append(CCFLAGS = ['--std=c++11', '-O3'])
|
||||
env.Append(CCFLAGS = ['--std=c++11', '-Wall', '-O3'])
|
||||
|
||||
# add additional libraries to link against
|
||||
env.Append(LIBS = ['libz', 'pthread', 'GL'])
|
||||
|
||||
|
@ -183,10 +183,10 @@ int main(int argc, char *argv[]) {
|
||||
std::vector<std::unique_ptr<std::vector<uint8_t>>> results;
|
||||
for(auto &name: names) {
|
||||
std::string local_path = "/usr/local/share/CLK/" + machine + "/" + name;
|
||||
FILE *file = fopen(local_path.c_str(), "r");
|
||||
FILE *file = std::fopen(local_path.c_str(), "rb");
|
||||
if(!file) {
|
||||
std::string path = "/usr/share/CLK/" + machine + "/" + name;
|
||||
file = fopen(path.c_str(), "r");
|
||||
file = std::fopen(path.c_str(), "rb");
|
||||
}
|
||||
|
||||
if(!file) {
|
||||
@ -196,13 +196,16 @@ int main(int argc, char *argv[]) {
|
||||
|
||||
std::unique_ptr<std::vector<uint8_t>> data(new std::vector<uint8_t>);
|
||||
|
||||
fseek(file, 0, SEEK_END);
|
||||
data->resize(ftell(file));
|
||||
fseek(file, 0, SEEK_SET);
|
||||
fread(data->data(), 1, data->size(), file);
|
||||
fclose(file);
|
||||
std::fseek(file, 0, SEEK_END);
|
||||
data->resize(std::ftell(file));
|
||||
std::fseek(file, 0, SEEK_SET);
|
||||
std::size_t read = fread(data->data(), 1, data->size(), file);
|
||||
std::fclose(file);
|
||||
|
||||
results.emplace_back(std::move(data));
|
||||
if(read == data->size())
|
||||
results.emplace_back(std::move(data));
|
||||
else
|
||||
results.emplace_back(nullptr);
|
||||
}
|
||||
|
||||
return results;
|
||||
|
@ -26,17 +26,17 @@ struct Rect {
|
||||
origin({x, y}), size({width, height}) {}
|
||||
};
|
||||
|
||||
enum DisplayType {
|
||||
enum class DisplayType {
|
||||
PAL50,
|
||||
NTSC60
|
||||
};
|
||||
|
||||
enum ColourSpace {
|
||||
enum class ColourSpace {
|
||||
YIQ,
|
||||
YUV
|
||||
};
|
||||
|
||||
enum OutputDevice {
|
||||
enum class OutputDevice {
|
||||
Monitor,
|
||||
Television
|
||||
};
|
||||
|
@ -7,8 +7,9 @@
|
||||
|
||||
#include "../CRT.hpp"
|
||||
|
||||
#include <cstdlib>
|
||||
#include <cassert>
|
||||
#include <cmath>
|
||||
#include <cstdlib>
|
||||
|
||||
#include "CRTOpenGL.hpp"
|
||||
#include "../../../SignalProcessing/FIRFilter.hpp"
|
||||
@ -71,7 +72,7 @@ OpenGLOutputBuilder::~OpenGLOutputBuilder() {
|
||||
}
|
||||
|
||||
bool OpenGLOutputBuilder::get_is_television_output() {
|
||||
return output_device_ == Television || !rgb_input_shader_program_;
|
||||
return output_device_ == OutputDevice::Television || !rgb_input_shader_program_;
|
||||
}
|
||||
|
||||
void OpenGLOutputBuilder::draw_frame(unsigned int output_width, unsigned int output_height, bool only_if_dirty) {
|
||||
@ -369,6 +370,8 @@ void OpenGLOutputBuilder::set_colour_space_uniforms() {
|
||||
fromRGB = rgbToYUV;
|
||||
toRGB = yuvToRGB;
|
||||
break;
|
||||
|
||||
default: assert(false); break;
|
||||
}
|
||||
|
||||
if(composite_input_shader_program_) composite_input_shader_program_->set_colour_conversion_matrices(fromRGB, toRGB);
|
||||
|
@ -32,7 +32,7 @@ std::unique_ptr<IntermediateShader> IntermediateShader::make_shader(const std::s
|
||||
const char *input_variable = input_is_inputPosition ? "inputPosition" : "outputPosition";
|
||||
|
||||
char *vertex_shader;
|
||||
asprintf(&vertex_shader,
|
||||
int length = asprintf(&vertex_shader,
|
||||
"#version 150\n"
|
||||
|
||||
"in vec2 inputStart;"
|
||||
@ -107,8 +107,10 @@ std::unique_ptr<IntermediateShader> IntermediateShader::make_shader(const std::s
|
||||
"gl_Position = vec4(eyePosition, 0.0, 1.0);"
|
||||
"}", sampler_type, input_variable);
|
||||
|
||||
if(length <= 0) return nullptr;
|
||||
|
||||
std::unique_ptr<IntermediateShader> shader(new IntermediateShader(vertex_shader, fragment_shader, bindings));
|
||||
free(vertex_shader);
|
||||
std::free(vertex_shader);
|
||||
|
||||
return shader;
|
||||
}
|
||||
@ -117,7 +119,7 @@ std::unique_ptr<IntermediateShader> IntermediateShader::make_source_conversion_s
|
||||
char *derived_composite_sample = nullptr;
|
||||
const char *composite_sample = composite_shader.c_str();
|
||||
if(!composite_shader.size()) {
|
||||
asprintf(&derived_composite_sample,
|
||||
int length = asprintf(&derived_composite_sample,
|
||||
"%s\n"
|
||||
"uniform mat3 rgbToLumaChroma;"
|
||||
"float composite_sample(usampler2D texID, vec2 coordinate, vec2 iCoordinate, float phase, float amplitude)"
|
||||
@ -128,11 +130,14 @@ std::unique_ptr<IntermediateShader> IntermediateShader::make_source_conversion_s
|
||||
"return dot(lumaChromaColour, vec3(1.0 - amplitude, quadrature));"
|
||||
"}",
|
||||
rgb_shader.c_str());
|
||||
if(length <= 0) {
|
||||
derived_composite_sample = nullptr;
|
||||
}
|
||||
composite_sample = derived_composite_sample;
|
||||
}
|
||||
|
||||
char *fragment_shader;
|
||||
asprintf(&fragment_shader,
|
||||
int length = asprintf(&fragment_shader,
|
||||
"#version 150\n"
|
||||
|
||||
"in vec2 inputPositionsVarying[11];"
|
||||
@ -150,17 +155,19 @@ std::unique_ptr<IntermediateShader> IntermediateShader::make_source_conversion_s
|
||||
"fragColour = vec4(composite_sample(texID, inputPositionsVarying[5], iInputPositionVarying, phaseAndAmplitudeVarying.x, phaseAndAmplitudeVarying.y));"
|
||||
"}"
|
||||
, composite_sample);
|
||||
free(derived_composite_sample);
|
||||
std::free(derived_composite_sample);
|
||||
|
||||
if(!length) return nullptr;
|
||||
|
||||
std::unique_ptr<IntermediateShader> shader = make_shader(fragment_shader, true, true);
|
||||
free(fragment_shader);
|
||||
std::free(fragment_shader);
|
||||
|
||||
return shader;
|
||||
}
|
||||
|
||||
std::unique_ptr<IntermediateShader> IntermediateShader::make_rgb_source_shader(const std::string &rgb_shader) {
|
||||
char *fragment_shader;
|
||||
asprintf(&fragment_shader,
|
||||
int length = asprintf(&fragment_shader,
|
||||
"#version 150\n"
|
||||
|
||||
"in vec2 inputPositionsVarying[11];"
|
||||
@ -179,8 +186,10 @@ std::unique_ptr<IntermediateShader> IntermediateShader::make_rgb_source_shader(c
|
||||
"}"
|
||||
, rgb_shader.c_str());
|
||||
|
||||
if(length <= 0) return nullptr;
|
||||
|
||||
std::unique_ptr<IntermediateShader> shader = make_shader(fragment_shader, true, true);
|
||||
free(fragment_shader);
|
||||
std::free(fragment_shader);
|
||||
|
||||
return shader;
|
||||
}
|
||||
@ -340,8 +349,8 @@ void IntermediateShader::set_filter_coefficients(float sampling_rate, float cuto
|
||||
|
||||
// int sample = 0;
|
||||
// int c = 0;
|
||||
memset(weights, 0, sizeof(float)*12);
|
||||
memset(offsets, 0, sizeof(float)*5);
|
||||
std::memset(weights, 0, sizeof(float)*12);
|
||||
std::memset(offsets, 0, sizeof(float)*5);
|
||||
|
||||
unsigned int half_size = (taps >> 1);
|
||||
for(unsigned int c = 0; c < taps; c++) {
|
||||
|
@ -25,7 +25,7 @@ std::unique_ptr<OutputShader> OutputShader::make_shader(const char *fragment_met
|
||||
const char *sampler_type = use_usampler ? "usampler2D" : "sampler2D";
|
||||
|
||||
char *vertex_shader;
|
||||
asprintf(&vertex_shader,
|
||||
int vertex_length = asprintf(&vertex_shader,
|
||||
"#version 150\n"
|
||||
|
||||
"in vec2 horizontal;"
|
||||
@ -64,7 +64,7 @@ std::unique_ptr<OutputShader> OutputShader::make_shader(const char *fragment_met
|
||||
"}", sampler_type);
|
||||
|
||||
char *fragment_shader;
|
||||
asprintf(&fragment_shader,
|
||||
int fragment_length = asprintf(&fragment_shader,
|
||||
"#version 150\n"
|
||||
|
||||
"in float lateralVarying;"
|
||||
@ -84,9 +84,11 @@ std::unique_ptr<OutputShader> OutputShader::make_shader(const char *fragment_met
|
||||
"}",
|
||||
sampler_type, fragment_methods, colour_expression);
|
||||
|
||||
if(vertex_length <= 0 || fragment_length <= 0) return nullptr;
|
||||
|
||||
std::unique_ptr<OutputShader> result(new OutputShader(vertex_shader, fragment_shader, bindings));
|
||||
free(vertex_shader);
|
||||
free(fragment_shader);
|
||||
std::free(vertex_shader);
|
||||
std::free(fragment_shader);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
@ -23,7 +23,7 @@ bool StaticAnalyser::Commodore::File::is_basic() {
|
||||
// ... null-terminated code ...
|
||||
// (with a next line address of 0000 indicating end of program)ß
|
||||
while(1) {
|
||||
if(line_address - starting_address >= data.size() + 2) break;
|
||||
if(static_cast<size_t>(line_address - starting_address) >= data.size() + 2) break;
|
||||
|
||||
uint16_t next_line_address = data[line_address - starting_address];
|
||||
next_line_address |= data[line_address - starting_address + 1] << 8;
|
||||
@ -33,7 +33,7 @@ bool StaticAnalyser::Commodore::File::is_basic() {
|
||||
}
|
||||
if(next_line_address < line_address + 5) break;
|
||||
|
||||
if(line_address - starting_address >= data.size() + 5) break;
|
||||
if(static_cast<size_t>(line_address - starting_address) >= data.size() + 5) break;
|
||||
uint16_t next_line_number = data[line_address - starting_address + 2];
|
||||
next_line_number |= data[line_address - starting_address + 3] << 8;
|
||||
|
||||
|
@ -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(
|
||||
|
@ -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
|
||||
|
@ -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;
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
@ -89,7 +89,7 @@ std::shared_ptr<Track> G64::get_track_at_position(Track::Address address) {
|
||||
unsigned int start_byte_in_current_speed = 0;
|
||||
for(unsigned int byte = 0; byte < track_length; byte ++) {
|
||||
unsigned int byte_speed = speed_zone_contents[byte >> 2] >> (6 - (byte&3)*2);
|
||||
if(byte_speed != current_speed || byte == (track_length-1)) {
|
||||
if(byte_speed != current_speed || byte == static_cast<uint16_t>(track_length-1)) {
|
||||
unsigned int number_of_bytes = byte - start_byte_in_current_speed;
|
||||
|
||||
PCMSegment segment;
|
||||
|
@ -14,7 +14,7 @@
|
||||
using namespace Storage;
|
||||
|
||||
FileHolder::~FileHolder() {
|
||||
if(file_) fclose(file_);
|
||||
if(file_) std::fclose(file_);
|
||||
}
|
||||
|
||||
FileHolder::FileHolder(const std::string &file_name, FileMode ideal_mode)
|
||||
@ -24,17 +24,17 @@ FileHolder::FileHolder(const std::string &file_name, FileMode ideal_mode)
|
||||
|
||||
switch(ideal_mode) {
|
||||
case FileMode::ReadWrite:
|
||||
file_ = fopen(file_name.c_str(), "rb+");
|
||||
file_ = std::fopen(file_name.c_str(), "rb+");
|
||||
if(file_) break;
|
||||
is_read_only_ = true;
|
||||
|
||||
// deliberate fallthrough...
|
||||
case FileMode::Read:
|
||||
file_ = fopen(file_name.c_str(), "rb");
|
||||
file_ = std::fopen(file_name.c_str(), "rb");
|
||||
break;
|
||||
|
||||
case FileMode::Rewrite:
|
||||
file_ = fopen(file_name.c_str(), "w");
|
||||
file_ = std::fopen(file_name.c_str(), "w");
|
||||
break;
|
||||
}
|
||||
|
||||
@ -42,69 +42,69 @@ FileHolder::FileHolder(const std::string &file_name, FileMode ideal_mode)
|
||||
}
|
||||
|
||||
uint32_t FileHolder::get32le() {
|
||||
uint32_t result = (uint32_t)fgetc(file_);
|
||||
result |= (uint32_t)(fgetc(file_) << 8);
|
||||
result |= (uint32_t)(fgetc(file_) << 16);
|
||||
result |= (uint32_t)(fgetc(file_) << 24);
|
||||
uint32_t result = (uint32_t)std::fgetc(file_);
|
||||
result |= (uint32_t)(std::fgetc(file_) << 8);
|
||||
result |= (uint32_t)(std::fgetc(file_) << 16);
|
||||
result |= (uint32_t)(std::fgetc(file_) << 24);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
uint32_t FileHolder::get32be() {
|
||||
uint32_t result = (uint32_t)(fgetc(file_) << 24);
|
||||
result |= (uint32_t)(fgetc(file_) << 16);
|
||||
result |= (uint32_t)(fgetc(file_) << 8);
|
||||
result |= (uint32_t)fgetc(file_);
|
||||
uint32_t result = (uint32_t)(std::fgetc(file_) << 24);
|
||||
result |= (uint32_t)(std::fgetc(file_) << 16);
|
||||
result |= (uint32_t)(std::fgetc(file_) << 8);
|
||||
result |= (uint32_t)std::fgetc(file_);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
uint32_t FileHolder::get24le() {
|
||||
uint32_t result = (uint32_t)fgetc(file_);
|
||||
result |= (uint32_t)(fgetc(file_) << 8);
|
||||
result |= (uint32_t)(fgetc(file_) << 16);
|
||||
uint32_t result = (uint32_t)std::fgetc(file_);
|
||||
result |= (uint32_t)(std::fgetc(file_) << 8);
|
||||
result |= (uint32_t)(std::fgetc(file_) << 16);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
uint32_t FileHolder::get24be() {
|
||||
uint32_t result = (uint32_t)(fgetc(file_) << 16);
|
||||
result |= (uint32_t)(fgetc(file_) << 8);
|
||||
result |= (uint32_t)fgetc(file_);
|
||||
uint32_t result = (uint32_t)(std::fgetc(file_) << 16);
|
||||
result |= (uint32_t)(std::fgetc(file_) << 8);
|
||||
result |= (uint32_t)std::fgetc(file_);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
uint16_t FileHolder::get16le() {
|
||||
uint16_t result = static_cast<uint16_t>(fgetc(file_));
|
||||
result |= static_cast<uint16_t>(fgetc(file_) << 8);
|
||||
uint16_t result = static_cast<uint16_t>(std::fgetc(file_));
|
||||
result |= static_cast<uint16_t>(std::fgetc(file_) << 8);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
uint16_t FileHolder::get16be() {
|
||||
uint16_t result = static_cast<uint16_t>(fgetc(file_) << 8);
|
||||
result |= static_cast<uint16_t>(fgetc(file_));
|
||||
uint16_t result = static_cast<uint16_t>(std::fgetc(file_) << 8);
|
||||
result |= static_cast<uint16_t>(std::fgetc(file_));
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
uint8_t FileHolder::get8() {
|
||||
return static_cast<uint8_t>(fgetc(file_));
|
||||
return static_cast<uint8_t>(std::fgetc(file_));
|
||||
}
|
||||
|
||||
void FileHolder::put16be(uint16_t value) {
|
||||
fputc(value >> 8, file_);
|
||||
fputc(value, file_);
|
||||
std::fputc(value >> 8, file_);
|
||||
std::fputc(value, file_);
|
||||
}
|
||||
|
||||
void FileHolder::put16le(uint16_t value) {
|
||||
fputc(value, file_);
|
||||
fputc(value >> 8, file_);
|
||||
std::fputc(value, file_);
|
||||
std::fputc(value >> 8, file_);
|
||||
}
|
||||
|
||||
void FileHolder::put8(uint8_t value) {
|
||||
fputc(value, file_);
|
||||
std::fputc(value, file_);
|
||||
}
|
||||
|
||||
void FileHolder::putn(std::size_t repeats, uint8_t value) {
|
||||
@ -113,36 +113,36 @@ void FileHolder::putn(std::size_t repeats, uint8_t value) {
|
||||
|
||||
std::vector<uint8_t> FileHolder::read(std::size_t size) {
|
||||
std::vector<uint8_t> result(size);
|
||||
fread(result.data(), 1, size, file_);
|
||||
result.resize(std::fread(result.data(), 1, size, file_));
|
||||
return result;
|
||||
}
|
||||
|
||||
std::size_t FileHolder::read(uint8_t *buffer, std::size_t size) {
|
||||
return fread(buffer, 1, size, file_);
|
||||
return std::fread(buffer, 1, size, file_);
|
||||
}
|
||||
|
||||
std::size_t FileHolder::write(const std::vector<uint8_t> &buffer) {
|
||||
return fwrite(buffer.data(), 1, buffer.size(), file_);
|
||||
return std::fwrite(buffer.data(), 1, buffer.size(), file_);
|
||||
}
|
||||
|
||||
std::size_t FileHolder::write(const uint8_t *buffer, std::size_t size) {
|
||||
return fwrite(buffer, 1, size, file_);
|
||||
return std::fwrite(buffer, 1, size, file_);
|
||||
}
|
||||
|
||||
void FileHolder::seek(long offset, int whence) {
|
||||
fseek(file_, offset, whence);
|
||||
std::fseek(file_, offset, whence);
|
||||
}
|
||||
|
||||
long FileHolder::tell() {
|
||||
return ftell(file_);
|
||||
return std::ftell(file_);
|
||||
}
|
||||
|
||||
void FileHolder::flush() {
|
||||
fflush(file_);
|
||||
std::fflush(file_);
|
||||
}
|
||||
|
||||
bool FileHolder::eof() {
|
||||
return feof(file_);
|
||||
return std::feof(file_);
|
||||
}
|
||||
|
||||
FileHolder::BitStream FileHolder::get_bitstream(bool lsb_first) {
|
||||
@ -154,8 +154,8 @@ bool FileHolder::check_signature(const char *signature, std::size_t length) {
|
||||
|
||||
// read and check the file signature
|
||||
std::vector<uint8_t> stored_signature = read(length);
|
||||
if(stored_signature.size() != length) return false;
|
||||
if(memcmp(stored_signature.data(), signature, length)) return false;
|
||||
if(stored_signature.size() != length) return false;
|
||||
if(std::memcmp(stored_signature.data(), signature, length)) return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -170,12 +170,12 @@ std::string FileHolder::extension() {
|
||||
}
|
||||
|
||||
void FileHolder::ensure_is_at_least_length(long length) {
|
||||
fseek(file_, 0, SEEK_END);
|
||||
std::fseek(file_, 0, SEEK_END);
|
||||
long bytes_to_write = length - ftell(file_);
|
||||
if(bytes_to_write > 0) {
|
||||
uint8_t *empty = new uint8_t[static_cast<std::size_t>(bytes_to_write)];
|
||||
memset(empty, 0, static_cast<std::size_t>(bytes_to_write));
|
||||
fwrite(empty, sizeof(uint8_t), static_cast<std::size_t>(bytes_to_write), file_);
|
||||
std::memset(empty, 0, static_cast<std::size_t>(bytes_to_write));
|
||||
std::fwrite(empty, sizeof(uint8_t), static_cast<std::size_t>(bytes_to_write), file_);
|
||||
delete[] empty;
|
||||
}
|
||||
}
|
||||
|
@ -8,6 +8,8 @@
|
||||
|
||||
#include "CSW.hpp"
|
||||
|
||||
#include <cassert>
|
||||
|
||||
using namespace Storage::Tape;
|
||||
|
||||
CSW::CSW(const char *file_name) :
|
||||
@ -36,7 +38,7 @@ CSW::CSW(const char *file_name) :
|
||||
pulse_.length.clock_rate = file_.get16le();
|
||||
|
||||
if(file_.get8() != 1) throw ErrorNotCSW;
|
||||
compression_type_ = RLE;
|
||||
compression_type_ = CompressionType::RLE;
|
||||
|
||||
pulse_.type = (file_.get8() & 1) ? Pulse::High : Pulse::Low;
|
||||
|
||||
@ -45,8 +47,8 @@ CSW::CSW(const char *file_name) :
|
||||
pulse_.length.clock_rate = file_.get32le();
|
||||
number_of_waves = file_.get32le();
|
||||
switch(file_.get8()) {
|
||||
case 1: compression_type_ = RLE; break;
|
||||
case 2: compression_type_ = ZRLE; break;
|
||||
case 1: compression_type_ = CompressionType::RLE; break;
|
||||
case 2: compression_type_ = CompressionType::ZRLE; break;
|
||||
default: throw ErrorNotCSW;
|
||||
}
|
||||
|
||||
@ -57,7 +59,7 @@ CSW::CSW(const char *file_name) :
|
||||
file_.seek(0x34 + extension_length, SEEK_SET);
|
||||
}
|
||||
|
||||
if(compression_type_ == ZRLE) {
|
||||
if(compression_type_ == CompressionType::ZRLE) {
|
||||
// The only clue given by CSW as to the output size in bytes is that there will be
|
||||
// number_of_waves waves. Waves are usually one byte, but may be five. So this code
|
||||
// is pessimistic.
|
||||
@ -83,20 +85,22 @@ CSW::CSW(const char *file_name) :
|
||||
|
||||
uint8_t CSW::get_next_byte() {
|
||||
switch(compression_type_) {
|
||||
case RLE: return file_.get8();
|
||||
case ZRLE: {
|
||||
case CompressionType::RLE: return file_.get8();
|
||||
case CompressionType::ZRLE: {
|
||||
if(source_data_pointer_ == source_data_.size()) return 0xff;
|
||||
uint8_t result = source_data_[source_data_pointer_];
|
||||
source_data_pointer_++;
|
||||
return result;
|
||||
}
|
||||
|
||||
default: assert(false); break;
|
||||
}
|
||||
}
|
||||
|
||||
uint32_t CSW::get_next_int32le() {
|
||||
switch(compression_type_) {
|
||||
case RLE: return file_.get32le();
|
||||
case ZRLE: {
|
||||
case CompressionType::RLE: return file_.get32le();
|
||||
case CompressionType::ZRLE: {
|
||||
if(source_data_pointer_ > source_data_.size() - 4) return 0xffff;
|
||||
uint32_t result = (uint32_t)(
|
||||
(source_data_[source_data_pointer_ + 0] << 0) |
|
||||
@ -106,6 +110,8 @@ uint32_t CSW::get_next_int32le() {
|
||||
source_data_pointer_ += 4;
|
||||
return result;
|
||||
}
|
||||
|
||||
default: assert(false); break;
|
||||
}
|
||||
}
|
||||
|
||||
@ -115,15 +121,19 @@ void CSW::invert_pulse() {
|
||||
|
||||
bool CSW::is_at_end() {
|
||||
switch(compression_type_) {
|
||||
case RLE: return file_.eof();
|
||||
case ZRLE: return source_data_pointer_ == source_data_.size();
|
||||
case CompressionType::RLE: return file_.eof();
|
||||
case CompressionType::ZRLE: return source_data_pointer_ == source_data_.size();
|
||||
|
||||
default: assert(false); break;
|
||||
}
|
||||
}
|
||||
|
||||
void CSW::virtual_reset() {
|
||||
switch(compression_type_) {
|
||||
case RLE: file_.seek(rle_start_, SEEK_SET); break;
|
||||
case ZRLE: source_data_pointer_ = 0; break;
|
||||
case CompressionType::RLE: file_.seek(rle_start_, SEEK_SET); break;
|
||||
case CompressionType::ZRLE: source_data_pointer_ = 0; break;
|
||||
|
||||
default: assert(false); break;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -44,7 +44,7 @@ class CSW: public Tape {
|
||||
Pulse virtual_get_next_pulse();
|
||||
|
||||
Pulse pulse_;
|
||||
enum CompressionType {
|
||||
enum class CompressionType {
|
||||
RLE,
|
||||
ZRLE
|
||||
} compression_type_;
|
||||
|
Loading…
x
Reference in New Issue
Block a user