1
0
mirror of https://github.com/TomHarte/CLK.git synced 2024-06-29 00:29:34 +00:00

Doubles down on <cX> over <X.h> for C includes, and usage of the namespace for those types and functions.

This commit is contained in:
Thomas Harte 2017-11-11 15:28:40 -05:00
parent 6a176082a0
commit 2e15fab651
99 changed files with 359 additions and 355 deletions

View File

@ -291,7 +291,7 @@ void i8272::posit_event(int event_type) {
WAIT_FOR_EVENT(Event8272::CommandByte) WAIT_FOR_EVENT(Event8272::CommandByte)
SetBusy(); SetBusy();
static const size_t required_lengths[32] = { static const std::size_t required_lengths[32] = {
0, 0, 9, 3, 2, 9, 9, 2, 0, 0, 9, 3, 2, 9, 9, 2,
1, 9, 2, 0, 9, 6, 0, 3, 1, 9, 2, 0, 9, 6, 0, 3,
0, 9, 0, 0, 0, 0, 0, 0, 0, 9, 0, 0, 0, 0, 0, 0,
@ -833,7 +833,7 @@ void i8272::posit_event(int event_type) {
// last thing in it will be returned first. // last thing in it will be returned first.
post_result: post_result:
printf("Result to %02x, main %02x: ", command_[0] & 0x1f, main_status_); printf("Result to %02x, main %02x: ", command_[0] & 0x1f, main_status_);
for(size_t c = 0; c < result_stack_.size(); c++) { for(std::size_t c = 0; c < result_stack_.size(); c++) {
printf("%02x ", result_stack_[result_stack_.size() - 1 - c]); printf("%02x ", result_stack_[result_stack_.size() - 1 - c]);
} }
printf("\n"); printf("\n");

View File

@ -13,7 +13,7 @@ using namespace Inputs;
Keyboard::Keyboard() {} Keyboard::Keyboard() {}
void Keyboard::set_key_pressed(Key key, bool is_pressed) { void Keyboard::set_key_pressed(Key key, bool is_pressed) {
size_t key_offset = static_cast<size_t>(key); std::size_t key_offset = static_cast<std::size_t>(key);
if(key_offset >= key_states_.size()) { if(key_offset >= key_states_.size()) {
key_states_.resize(key_offset+1, false); key_states_.resize(key_offset+1, false);
} }
@ -32,7 +32,7 @@ void Keyboard::set_delegate(Delegate *delegate) {
} }
bool Keyboard::get_key_state(Key key) { bool Keyboard::get_key_state(Key key) {
size_t key_offset = static_cast<size_t>(key); std::size_t key_offset = static_cast<std::size_t>(key);
if(key_offset >= key_states_.size()) return false; if(key_offset >= key_states_.size()) return false;
return key_states_[key_offset]; return key_states_[key_offset];
} }

View File

@ -935,7 +935,7 @@ class ConcreteMachine:
"amsdos.rom" "amsdos.rom"
}); });
for(size_t index = 0; index < roms.size(); ++index) { for(std::size_t index = 0; index < roms.size(); ++index) {
auto &data = roms[index]; auto &data = roms[index];
if(!data) return false; if(!data) return false;
set_rom(static_cast<ROMType>(index), *data); set_rom(static_cast<ROMType>(index), *data);

View File

@ -7,8 +7,9 @@
// //
#include "Atari2600.hpp" #include "Atari2600.hpp"
#include <algorithm> #include <algorithm>
#include <stdio.h> #include <cstdio>
#include "Cartridges/Atari8k.hpp" #include "Cartridges/Atari8k.hpp"
#include "Cartridges/Atari16k.hpp" #include "Cartridges/Atari16k.hpp"
@ -32,7 +33,7 @@ namespace Atari2600 {
class Joystick: public Inputs::Joystick { class Joystick: public Inputs::Joystick {
public: public:
Joystick(Bus *bus, size_t shift, size_t fire_tia_input) : Joystick(Bus *bus, std::size_t shift, std::size_t fire_tia_input) :
bus_(bus), shift_(shift), fire_tia_input_(fire_tia_input) {} bus_(bus), shift_(shift), fire_tia_input_(fire_tia_input) {}
void set_digital_input(DigitalInput digital_input, bool is_active) { void set_digital_input(DigitalInput digital_input, bool is_active) {
@ -54,7 +55,7 @@ class Joystick: public Inputs::Joystick {
private: private:
Bus *bus_; Bus *bus_;
size_t shift_, fire_tia_input_; std::size_t shift_, fire_tia_input_;
}; };
class ConcreteMachine: class ConcreteMachine:
@ -159,7 +160,7 @@ class ConcreteMachine:
// to satisfy Outputs::CRT::Delegate // to satisfy Outputs::CRT::Delegate
void crt_did_end_batch_of_frames(Outputs::CRT::CRT *crt, unsigned int number_of_frames, unsigned int number_of_unexpected_vertical_syncs) override { void crt_did_end_batch_of_frames(Outputs::CRT::CRT *crt, unsigned int number_of_frames, unsigned int number_of_unexpected_vertical_syncs) override {
const size_t number_of_frame_records = sizeof(frame_records_) / sizeof(frame_records_[0]); const std::size_t number_of_frame_records = sizeof(frame_records_) / sizeof(frame_records_[0]);
frame_records_[frame_record_pointer_ % number_of_frame_records].number_of_frames = number_of_frames; frame_records_[frame_record_pointer_ % number_of_frame_records].number_of_frames = number_of_frames;
frame_records_[frame_record_pointer_ % number_of_frame_records].number_of_unexpected_vertical_syncs = number_of_unexpected_vertical_syncs; frame_records_[frame_record_pointer_ % number_of_frame_records].number_of_unexpected_vertical_syncs = number_of_unexpected_vertical_syncs;
frame_record_pointer_ ++; frame_record_pointer_ ++;
@ -167,13 +168,13 @@ class ConcreteMachine:
if(frame_record_pointer_ >= 6) { if(frame_record_pointer_ >= 6) {
unsigned int total_number_of_frames = 0; unsigned int total_number_of_frames = 0;
unsigned int total_number_of_unexpected_vertical_syncs = 0; unsigned int total_number_of_unexpected_vertical_syncs = 0;
for(size_t c = 0; c < number_of_frame_records; c++) { for(std::size_t c = 0; c < number_of_frame_records; c++) {
total_number_of_frames += frame_records_[c].number_of_frames; total_number_of_frames += frame_records_[c].number_of_frames;
total_number_of_unexpected_vertical_syncs += frame_records_[c].number_of_unexpected_vertical_syncs; total_number_of_unexpected_vertical_syncs += frame_records_[c].number_of_unexpected_vertical_syncs;
} }
if(total_number_of_unexpected_vertical_syncs >= total_number_of_frames >> 1) { if(total_number_of_unexpected_vertical_syncs >= total_number_of_frames >> 1) {
for(size_t c = 0; c < number_of_frame_records; c++) { for(std::size_t c = 0; c < number_of_frame_records; c++) {
frame_records_[c].number_of_frames = 0; frame_records_[c].number_of_frames = 0;
frame_records_[c].number_of_unexpected_vertical_syncs = 0; frame_records_[c].number_of_unexpected_vertical_syncs = 0;
} }

View File

@ -14,7 +14,7 @@ namespace Cartridge {
class ActivisionStack: public BusExtender { class ActivisionStack: public BusExtender {
public: public:
ActivisionStack(uint8_t *rom_base, size_t rom_size) : ActivisionStack(uint8_t *rom_base, std::size_t rom_size) :
BusExtender(rom_base, rom_size), BusExtender(rom_base, rom_size),
rom_ptr_(rom_base), rom_ptr_(rom_base),
last_opcode_(0x00) {} last_opcode_(0x00) {}

View File

@ -16,7 +16,7 @@ namespace Cartridge {
class Atari16k: public BusExtender { class Atari16k: public BusExtender {
public: public:
Atari16k(uint8_t *rom_base, size_t rom_size) : Atari16k(uint8_t *rom_base, std::size_t rom_size) :
BusExtender(rom_base, rom_size), BusExtender(rom_base, rom_size),
rom_ptr_(rom_base) {} rom_ptr_(rom_base) {}
@ -37,7 +37,7 @@ class Atari16k: public BusExtender {
class Atari16kSuperChip: public BusExtender { class Atari16kSuperChip: public BusExtender {
public: public:
Atari16kSuperChip(uint8_t *rom_base, size_t rom_size) : Atari16kSuperChip(uint8_t *rom_base, std::size_t rom_size) :
BusExtender(rom_base, rom_size), BusExtender(rom_base, rom_size),
rom_ptr_(rom_base) {} rom_ptr_(rom_base) {}

View File

@ -16,7 +16,7 @@ namespace Cartridge {
class Atari32k: public BusExtender { class Atari32k: public BusExtender {
public: public:
Atari32k(uint8_t *rom_base, size_t rom_size) : BusExtender(rom_base, rom_size), rom_ptr_(rom_base) {} Atari32k(uint8_t *rom_base, std::size_t rom_size) : BusExtender(rom_base, rom_size), rom_ptr_(rom_base) {}
void perform_bus_operation(CPU::MOS6502::BusOperation operation, uint16_t address, uint8_t *value) { void perform_bus_operation(CPU::MOS6502::BusOperation operation, uint16_t address, uint8_t *value) {
address &= 0x1fff; address &= 0x1fff;
@ -35,7 +35,7 @@ class Atari32k: public BusExtender {
class Atari32kSuperChip: public BusExtender { class Atari32kSuperChip: public BusExtender {
public: public:
Atari32kSuperChip(uint8_t *rom_base, size_t rom_size) : BusExtender(rom_base, rom_size), rom_ptr_(rom_base) {} Atari32kSuperChip(uint8_t *rom_base, std::size_t rom_size) : BusExtender(rom_base, rom_size), rom_ptr_(rom_base) {}
void perform_bus_operation(CPU::MOS6502::BusOperation operation, uint16_t address, uint8_t *value) { void perform_bus_operation(CPU::MOS6502::BusOperation operation, uint16_t address, uint8_t *value) {
address &= 0x1fff; address &= 0x1fff;

View File

@ -16,7 +16,7 @@ namespace Cartridge {
class Atari8k: public BusExtender { class Atari8k: public BusExtender {
public: public:
Atari8k(uint8_t *rom_base, size_t rom_size) : BusExtender(rom_base, rom_size), rom_ptr_(rom_base) {} Atari8k(uint8_t *rom_base, std::size_t rom_size) : BusExtender(rom_base, rom_size), rom_ptr_(rom_base) {}
void perform_bus_operation(CPU::MOS6502::BusOperation operation, uint16_t address, uint8_t *value) { void perform_bus_operation(CPU::MOS6502::BusOperation operation, uint16_t address, uint8_t *value) {
address &= 0x1fff; address &= 0x1fff;
@ -36,7 +36,7 @@ class Atari8k: public BusExtender {
class Atari8kSuperChip: public BusExtender { class Atari8kSuperChip: public BusExtender {
public: public:
Atari8kSuperChip(uint8_t *rom_base, size_t rom_size) : BusExtender(rom_base, rom_size), rom_ptr_(rom_base) {} Atari8kSuperChip(uint8_t *rom_base, std::size_t rom_size) : BusExtender(rom_base, rom_size), rom_ptr_(rom_base) {}
void perform_bus_operation(CPU::MOS6502::BusOperation operation, uint16_t address, uint8_t *value) { void perform_bus_operation(CPU::MOS6502::BusOperation operation, uint16_t address, uint8_t *value) {
address &= 0x1fff; address &= 0x1fff;

View File

@ -16,7 +16,7 @@ namespace Cartridge {
class CBSRAMPlus: public BusExtender { class CBSRAMPlus: public BusExtender {
public: public:
CBSRAMPlus(uint8_t *rom_base, size_t rom_size) : BusExtender(rom_base, rom_size), rom_ptr_(rom_base) {} CBSRAMPlus(uint8_t *rom_base, std::size_t rom_size) : BusExtender(rom_base, rom_size), rom_ptr_(rom_base) {}
void perform_bus_operation(CPU::MOS6502::BusOperation operation, uint16_t address, uint8_t *value) { void perform_bus_operation(CPU::MOS6502::BusOperation operation, uint16_t address, uint8_t *value) {
address &= 0x1fff; address &= 0x1fff;

View File

@ -17,13 +17,13 @@ namespace Cartridge {
class BusExtender: public CPU::MOS6502::BusHandler { class BusExtender: public CPU::MOS6502::BusHandler {
public: public:
BusExtender(uint8_t *rom_base, size_t rom_size) : rom_base_(rom_base), rom_size_(rom_size) {} BusExtender(uint8_t *rom_base, std::size_t rom_size) : rom_base_(rom_base), rom_size_(rom_size) {}
void advance_cycles(int cycles) {} void advance_cycles(int cycles) {}
protected: protected:
uint8_t *rom_base_; uint8_t *rom_base_;
size_t rom_size_; std::size_t rom_size_;
}; };
template<class T> class Cartridge: template<class T> class Cartridge:

View File

@ -16,7 +16,7 @@ namespace Cartridge {
class CommaVid: public BusExtender { class CommaVid: public BusExtender {
public: public:
CommaVid(uint8_t *rom_base, size_t rom_size) : BusExtender(rom_base, rom_size) {} CommaVid(uint8_t *rom_base, std::size_t rom_size) : BusExtender(rom_base, rom_size) {}
void perform_bus_operation(CPU::MOS6502::BusOperation operation, uint16_t address, uint8_t *value) { void perform_bus_operation(CPU::MOS6502::BusOperation operation, uint16_t address, uint8_t *value) {
if(!(address & 0x1000)) return; if(!(address & 0x1000)) return;

View File

@ -16,7 +16,7 @@ namespace Cartridge {
class MNetwork: public BusExtender { class MNetwork: public BusExtender {
public: public:
MNetwork(uint8_t *rom_base, size_t rom_size) : MNetwork(uint8_t *rom_base, std::size_t rom_size) :
BusExtender(rom_base, rom_size) { BusExtender(rom_base, rom_size) {
rom_ptr_[0] = rom_base + rom_size_ - 4096; rom_ptr_[0] = rom_base + rom_size_ - 4096;
rom_ptr_[1] = rom_ptr_[0] + 2048; rom_ptr_[1] = rom_ptr_[0] + 2048;

View File

@ -16,7 +16,7 @@ namespace Cartridge {
class MegaBoy: public BusExtender { class MegaBoy: public BusExtender {
public: public:
MegaBoy(uint8_t *rom_base, size_t rom_size) : MegaBoy(uint8_t *rom_base, std::size_t rom_size) :
BusExtender(rom_base, rom_size), BusExtender(rom_base, rom_size),
rom_ptr_(rom_base), rom_ptr_(rom_base),
current_page_(0) { current_page_(0) {

View File

@ -16,7 +16,7 @@ namespace Cartridge {
class ParkerBros: public BusExtender { class ParkerBros: public BusExtender {
public: public:
ParkerBros(uint8_t *rom_base, size_t rom_size) : ParkerBros(uint8_t *rom_base, std::size_t rom_size) :
BusExtender(rom_base, rom_size) { BusExtender(rom_base, rom_size) {
rom_ptr_[0] = rom_base + 4096; rom_ptr_[0] = rom_base + 4096;
rom_ptr_[1] = rom_ptr_[0] + 1024; rom_ptr_[1] = rom_ptr_[0] + 1024;

View File

@ -14,7 +14,7 @@ namespace Cartridge {
class Pitfall2: public BusExtender { class Pitfall2: public BusExtender {
public: public:
Pitfall2(uint8_t *rom_base, size_t rom_size) : Pitfall2(uint8_t *rom_base, std::size_t rom_size) :
BusExtender(rom_base, rom_size), BusExtender(rom_base, rom_size),
rom_ptr_(rom_base) {} rom_ptr_(rom_base) {}

View File

@ -16,7 +16,7 @@ namespace Cartridge {
class Tigervision: public BusExtender { class Tigervision: public BusExtender {
public: public:
Tigervision(uint8_t *rom_base, size_t rom_size) : Tigervision(uint8_t *rom_base, std::size_t rom_size) :
BusExtender(rom_base, rom_size) { BusExtender(rom_base, rom_size) {
rom_ptr_[0] = rom_base + rom_size - 4096; rom_ptr_[0] = rom_base + rom_size - 4096;
rom_ptr_[1] = rom_ptr_[0] + 2048; rom_ptr_[1] = rom_ptr_[0] + 2048;

View File

@ -16,7 +16,7 @@ namespace Cartridge {
class Unpaged: public BusExtender { class Unpaged: public BusExtender {
public: public:
Unpaged(uint8_t *rom_base, size_t rom_size) : BusExtender(rom_base, rom_size) {} Unpaged(uint8_t *rom_base, std::size_t rom_size) : BusExtender(rom_base, rom_size) {}
void perform_bus_operation(CPU::MOS6502::BusOperation operation, uint16_t address, uint8_t *value) { void perform_bus_operation(CPU::MOS6502::BusOperation operation, uint16_t address, uint8_t *value) {
if(isReadOperation(operation) && (address & 0x1000)) { if(isReadOperation(operation) && (address & 0x1000)) {

View File

@ -91,7 +91,7 @@ bool Machine::set_rom_fetcher(const std::function<std::vector<std::unique_ptr<st
auto roms = roms_with_names("Commodore1540", {rom_name}); auto roms = roms_with_names("Commodore1540", {rom_name});
if(!roms[0]) return false; if(!roms[0]) return false;
memcpy(rom_, roms[0]->data(), std::min(sizeof(rom_), roms[0]->size())); std::memcpy(rom_, roms[0]->data(), std::min(sizeof(rom_), roms[0]->size()));
return true; return true;
} }

View File

@ -318,7 +318,7 @@ class ConcreteMachine:
"basic.bin" "basic.bin"
}); });
for(size_t index = 0; index < roms.size(); ++index) { for(std::size_t index = 0; index < roms.size(); ++index) {
auto &data = roms[index]; auto &data = roms[index];
if(!data) return false; if(!data) return false;
if(index < 9) roms_[index] = *data; else basic_rom_ = *data; if(index < 9) roms_[index] = *data; else basic_rom_ = *data;
@ -372,7 +372,7 @@ class ConcreteMachine:
rom_length_ = static_cast<uint16_t>(rom_image.size()); rom_length_ = static_cast<uint16_t>(rom_image.size());
rom_ = new uint8_t[0x2000]; rom_ = new uint8_t[0x2000];
memcpy(rom_, rom_image.data(), rom_image.size()); std::memcpy(rom_, rom_image.data(), rom_image.size());
write_to_map(processor_read_memory_map_, rom_, rom_address_, 0x2000); write_to_map(processor_read_memory_map_, rom_, rom_address_, 0x2000);
} }
@ -543,7 +543,7 @@ class ConcreteMachine:
// perform a via-processor_write_memory_map_ memcpy // perform a via-processor_write_memory_map_ memcpy
uint8_t *data_ptr = data->data.data(); uint8_t *data_ptr = data->data.data();
size_t data_left = data->data.size(); std::size_t data_left = data->data.size();
while(data_left && start_address != end_address) { while(data_left && start_address != end_address) {
uint8_t *page = processor_write_memory_map_[start_address >> 10]; uint8_t *page = processor_write_memory_map_[start_address >> 10];
if(page) page[start_address & 0x3ff] = *data_ptr; if(page) page[start_address & 0x3ff] = *data_ptr;

View File

@ -53,7 +53,7 @@ class ConcreteMachine:
break; break;
} }
memcpy(target, &data[0], std::min(static_cast<size_t>(16384), data.size())); std::memcpy(target, &data[0], std::min(static_cast<std::size_t>(16384), data.size()));
} }
// Obtains the system ROMs. // Obtains the system ROMs.
@ -71,7 +71,7 @@ class ConcreteMachine:
ROMSlotBASIC, ROMSlotOS ROMSlotBASIC, ROMSlotOS
}; };
for(size_t index = 0; index < roms.size(); ++index) { for(std::size_t index = 0; index < roms.size(); ++index) {
auto &data = roms[index]; auto &data = roms[index];
if(!data) return false; if(!data) return false;
set_rom(slots[index], *data, false); set_rom(slots[index], *data, false);

View File

@ -124,7 +124,7 @@ class VideoOutput {
void setup_screen_map(); void setup_screen_map();
void emplace_blank_line(); void emplace_blank_line();
void emplace_pixel_line(); void emplace_pixel_line();
size_t screen_map_pointer_ = 0; std::size_t screen_map_pointer_ = 0;
int cycles_into_draw_action_ = 0; int cycles_into_draw_action_ = 0;
}; };

View File

@ -212,7 +212,7 @@ class ConcreteMachine:
"microdisc.rom", "colour.rom" "microdisc.rom", "colour.rom"
}); });
for(size_t index = 0; index < roms.size(); ++index) { for(std::size_t index = 0; index < roms.size(); ++index) {
auto &data = roms[index]; auto &data = roms[index];
if(!data) return false; if(!data) return false;
set_rom(static_cast<ROM>(index), *data); set_rom(static_cast<ROM>(index), *data);
@ -254,14 +254,14 @@ class ConcreteMachine:
} }
if(target.oric.use_atmos_rom) { if(target.oric.use_atmos_rom) {
memcpy(rom_, basic11_rom_.data(), std::min(basic11_rom_.size(), sizeof(rom_))); std::memcpy(rom_, basic11_rom_.data(), std::min(basic11_rom_.size(), sizeof(rom_)));
is_using_basic11_ = true; is_using_basic11_ = true;
tape_get_byte_address_ = 0xe6c9; tape_get_byte_address_ = 0xe6c9;
scan_keyboard_address_ = 0xf495; scan_keyboard_address_ = 0xf495;
tape_speed_address_ = 0x024d; tape_speed_address_ = 0x024d;
} else { } else {
memcpy(rom_, basic10_rom_.data(), std::min(basic10_rom_.size(), sizeof(rom_))); std::memcpy(rom_, basic10_rom_.data(), std::min(basic10_rom_.size(), sizeof(rom_)));
is_using_basic11_ = false; is_using_basic11_ = false;
tape_get_byte_address_ = 0xe630; tape_get_byte_address_ = 0xe630;

View File

@ -51,8 +51,8 @@ void VideoOutput::set_output_device(Outputs::CRT::OutputDevice output_device) {
} }
void VideoOutput::set_colour_rom(const std::vector<uint8_t> &rom) { void VideoOutput::set_colour_rom(const std::vector<uint8_t> &rom) {
for(size_t c = 0; c < 8; c++) { for(std::size_t c = 0; c < 8; c++) {
size_t index = (c << 2); std::size_t index = (c << 2);
uint16_t rom_value = static_cast<uint16_t>((static_cast<uint16_t>(rom[index]) << 8) | static_cast<uint16_t>(rom[index+1])); uint16_t rom_value = static_cast<uint16_t>((static_cast<uint16_t>(rom[index]) << 8) | static_cast<uint16_t>(rom[index+1]));
rom_value = (rom_value & 0xff00) | ((rom_value >> 4)&0x000f) | ((rom_value << 4)&0x00f0); rom_value = (rom_value & 0xff00) | ((rom_value >> 4)&0x000f) | ((rom_value << 4)&0x00f0);
colour_forms_[c] = rom_value; colour_forms_[c] = rom_value;
@ -61,7 +61,7 @@ void VideoOutput::set_colour_rom(const std::vector<uint8_t> &rom) {
// check for big endianness and byte swap if required // check for big endianness and byte swap if required
uint16_t test_value = 0x0001; uint16_t test_value = 0x0001;
if(*reinterpret_cast<uint8_t *>(&test_value) != 0x01) { if(*reinterpret_cast<uint8_t *>(&test_value) != 0x01) {
for(size_t c = 0; c < 8; c++) { for(std::size_t c = 0; c < 8; c++) {
colour_forms_[c] = static_cast<uint16_t>((colour_forms_[c] >> 8) | (colour_forms_[c] << 8)); colour_forms_[c] = static_cast<uint16_t>((colour_forms_[c] >> 8) | (colour_forms_[c] << 8));
} }
} }

View File

@ -10,7 +10,7 @@
#include <cstdlib> #include <cstdlib>
void Memory::Fuzz(uint8_t *buffer, size_t size) { void Memory::Fuzz(uint8_t *buffer, std::size_t size) {
unsigned int divider = (static_cast<unsigned int>(RAND_MAX) + 1) / 256; unsigned int divider = (static_cast<unsigned int>(RAND_MAX) + 1) / 256;
unsigned int shift = 1, value = 1; unsigned int shift = 1, value = 1;
while(value < divider) { while(value < divider) {
@ -18,7 +18,7 @@ void Memory::Fuzz(uint8_t *buffer, size_t size) {
shift++; shift++;
} }
for(size_t c = 0; c < size; c++) { for(std::size_t c = 0; c < size; c++) {
buffer[c] = static_cast<uint8_t>(std::rand() >> shift); buffer[c] = static_cast<uint8_t>(std::rand() >> shift);
} }
} }

View File

@ -16,7 +16,7 @@
namespace Memory { namespace Memory {
/// Stores @c size random bytes from @c buffer onwards. /// Stores @c size random bytes from @c buffer onwards.
void Fuzz(uint8_t *buffer, size_t size); void Fuzz(uint8_t *buffer, std::size_t size);
// Replaces all existing vector contents with random bytes. // Replaces all existing vector contents with random bytes.
void Fuzz(std::vector<uint8_t> &buffer); void Fuzz(std::vector<uint8_t> &buffer);

View File

@ -18,8 +18,8 @@ Typer::Typer(const char *string, HalfCycles delay, HalfCycles frequency, std::un
counter_(-delay), counter_(-delay),
delegate_(delegate), delegate_(delegate),
character_mapper_(std::move(character_mapper)) { character_mapper_(std::move(character_mapper)) {
size_t string_size = strlen(string) + 3; std::size_t string_size = std::strlen(string) + 3;
string_ = (char *)malloc(string_size); string_ = (char *)std::malloc(string_size);
snprintf(string_, string_size, "%c%s%c", Typer::BeginString, string, Typer::EndString); snprintf(string_, string_size, "%c%s%c", Typer::BeginString, string, Typer::EndString);
} }
@ -63,7 +63,7 @@ bool Typer::type_next_character() {
if(!try_type_next_character()) { if(!try_type_next_character()) {
phase_ = 0; phase_ = 0;
if(!string_[string_pointer_]) { if(!string_[string_pointer_]) {
free(string_); std::free(string_);
string_ = nullptr; string_ = nullptr;
return false; return false;
} }
@ -77,13 +77,13 @@ bool Typer::type_next_character() {
} }
Typer::~Typer() { Typer::~Typer() {
free(string_); std::free(string_);
} }
#pragma mark - Character mapper #pragma mark - Character mapper
uint16_t *CharacterMapper::table_lookup_sequence_for_character(KeySequence *sequences, size_t length, char character) { uint16_t *CharacterMapper::table_lookup_sequence_for_character(KeySequence *sequences, std::size_t length, char character) {
size_t ucharacter = static_cast<size_t>((unsigned char)character); std::size_t ucharacter = static_cast<std::size_t>((unsigned char)character);
if(ucharacter > (length / sizeof(KeySequence))) return nullptr; if(ucharacter > (length / sizeof(KeySequence))) return nullptr;
if(sequences[ucharacter][0] == KeyboardMachine::Machine::KeyNotMapped) return nullptr; if(sequences[ucharacter][0] == KeyboardMachine::Machine::KeyNotMapped) return nullptr;
return sequences[ucharacter]; return sequences[ucharacter];

View File

@ -32,7 +32,7 @@ class CharacterMapper {
with @c length entries, returns the sequence for character @c character if it exists; otherwise with @c length entries, returns the sequence for character @c character if it exists; otherwise
returns @c nullptr. returns @c nullptr.
*/ */
uint16_t *table_lookup_sequence_for_character(KeySequence *sequences, size_t length, char character); uint16_t *table_lookup_sequence_for_character(KeySequence *sequences, std::size_t length, char character);
}; };
/*! /*!
@ -63,7 +63,7 @@ class Typer {
private: private:
char *string_; char *string_;
size_t string_pointer_ = 0; std::size_t string_pointer_ = 0;
HalfCycles frequency_; HalfCycles frequency_;
HalfCycles counter_; HalfCycles counter_;

View File

@ -129,7 +129,7 @@ template<bool is_zx81> class ConcreteMachine:
z80_.set_interrupt_line(false); z80_.set_interrupt_line(false);
} }
if(has_latched_video_byte_) { if(has_latched_video_byte_) {
size_t char_address = static_cast<size_t>((address & 0xfe00) | ((latched_video_byte_ & 0x3f) << 3) | line_counter_); std::size_t char_address = static_cast<std::size_t>((address & 0xfe00) | ((latched_video_byte_ & 0x3f) << 3) | line_counter_);
uint8_t mask = (latched_video_byte_ & 0x80) ? 0x00 : 0xff; uint8_t mask = (latched_video_byte_ & 0x80) ? 0x00 : 0xff;
if(char_address < ram_base_) { if(char_address < ram_base_) {
latched_video_byte_ = rom_[char_address & rom_mask_] ^ mask; latched_video_byte_ = rom_[char_address & rom_mask_] ^ mask;
@ -299,7 +299,7 @@ template<bool is_zx81> class ConcreteMachine:
"zx80.rom", "zx81.rom", "zx80.rom", "zx81.rom",
}); });
for(size_t index = 0; index < roms.size(); ++index) { for(std::size_t index = 0; index < roms.size(); ++index) {
auto &data = roms[index]; auto &data = roms[index];
if(!data) return false; if(!data) return false;
set_rom(static_cast<ROMType>(index), *data); set_rom(static_cast<ROMType>(index), *data);

View File

@ -72,16 +72,16 @@ struct MachineDelegate: CRTMachine::Machine::Delegate, public LockProtectedDeleg
_speakerDelegate.machineAccessLock = _delegateMachineAccessLock; _speakerDelegate.machineAccessLock = _delegateMachineAccessLock;
_machine->set_delegate(&_machineDelegate); _machine->set_delegate(&_machineDelegate);
_machine->set_rom_fetcher( [] (const std::string &machine, const std::vector<std::string> &names) -> std::vector<std::unique_ptr<std::vector<uint8_t>>> { _machine->set_rom_fetcher( [] (const std::string &machine, const std::vector<std::string> &names) -> std::vector<std::unique_ptr<std::vector<std::uint8_t>>> {
NSString *subDirectory = [@"ROMImages/" stringByAppendingString:[NSString stringWithUTF8String:machine.c_str()]]; NSString *subDirectory = [@"ROMImages/" stringByAppendingString:[NSString stringWithUTF8String:machine.c_str()]];
std::vector<std::unique_ptr<std::vector<uint8_t>>> results; std::vector<std::unique_ptr<std::vector<std::uint8_t>>> results;
for(auto &name: names) { for(auto &name: names) {
NSData *fileData = [[NSBundle mainBundle] dataForResource:[NSString stringWithUTF8String:name.c_str()] withExtension:nil subdirectory:subDirectory]; NSData *fileData = [[NSBundle mainBundle] dataForResource:[NSString stringWithUTF8String:name.c_str()] withExtension:nil subdirectory:subDirectory];
if(!fileData) if(!fileData)
results.emplace_back(nullptr); results.emplace_back(nullptr);
else { else {
std::unique_ptr<std::vector<uint8_t>> data(new std::vector<uint8_t>); std::unique_ptr<std::vector<std::uint8_t>> data(new std::vector<std::uint8_t>);
*data = fileData.stdVector8; *data = fileData.stdVector8;
results.emplace_back(std::move(data)); results.emplace_back(std::move(data));
} }

View File

@ -13,6 +13,6 @@
@interface NSData (StdVector) @interface NSData (StdVector)
- (std::vector<uint8_t>)stdVector8; - (std::vector<std::uint8_t>)stdVector8;
@end @end

View File

@ -218,17 +218,17 @@ void CRT::advance_cycles(unsigned int number_of_cycles, bool hsync_requested, bo
output_x2() = static_cast<uint16_t>(horizontal_flywheel_->get_current_output_position()); output_x2() = static_cast<uint16_t>(horizontal_flywheel_->get_current_output_position());
} }
openGL_output_builder_.array_builder.flush( openGL_output_builder_.array_builder.flush(
[=] (uint8_t *input_buffer, size_t input_size, uint8_t *output_buffer, size_t output_size) { [=] (uint8_t *input_buffer, std::size_t input_size, uint8_t *output_buffer, std::size_t output_size) {
openGL_output_builder_.texture_builder.flush( openGL_output_builder_.texture_builder.flush(
[=] (const std::vector<TextureBuilder::WriteArea> &write_areas, size_t number_of_write_areas) { [=] (const std::vector<TextureBuilder::WriteArea> &write_areas, std::size_t number_of_write_areas) {
assert(number_of_write_areas * SourceVertexSize == input_size); assert(number_of_write_areas * SourceVertexSize == input_size);
for(size_t run = 0; run < number_of_write_areas; run++) { for(std::size_t run = 0; run < number_of_write_areas; run++) {
*reinterpret_cast<uint16_t *>(&input_buffer[run * SourceVertexSize + SourceVertexOffsetOfInputStart + 0]) = write_areas[run].x; *reinterpret_cast<uint16_t *>(&input_buffer[run * SourceVertexSize + SourceVertexOffsetOfInputStart + 0]) = write_areas[run].x;
*reinterpret_cast<uint16_t *>(&input_buffer[run * SourceVertexSize + SourceVertexOffsetOfInputStart + 2]) = write_areas[run].y; *reinterpret_cast<uint16_t *>(&input_buffer[run * SourceVertexSize + SourceVertexOffsetOfInputStart + 2]) = write_areas[run].y;
*reinterpret_cast<uint16_t *>(&input_buffer[run * SourceVertexSize + SourceVertexOffsetOfEnds + 0]) = write_areas[run].x + write_areas[run].length; *reinterpret_cast<uint16_t *>(&input_buffer[run * SourceVertexSize + SourceVertexOffsetOfEnds + 0]) = write_areas[run].x + write_areas[run].length;
} }
}); });
for(size_t position = 0; position < input_size; position += SourceVertexSize) { for(std::size_t position = 0; position < input_size; position += SourceVertexSize) {
(*reinterpret_cast<uint16_t *>(&input_buffer[position + SourceVertexOffsetOfOutputStart + 2])) = output_y; (*reinterpret_cast<uint16_t *>(&input_buffer[position + SourceVertexOffsetOfOutputStart + 2])) = output_y;
} }
}); });

View File

@ -9,7 +9,7 @@
#ifndef CRT_hpp #ifndef CRT_hpp
#define CRT_hpp #define CRT_hpp
#include <stdint.h> #include <cstdint>
#include "CRTTypes.hpp" #include "CRTTypes.hpp"
#include "Internals/Flywheel.hpp" #include "Internals/Flywheel.hpp"
@ -221,7 +221,7 @@ class CRT {
@param required_length The number of samples to allocate. @param required_length The number of samples to allocate.
@returns A pointer to the allocated area if room is available; @c nullptr otherwise. @returns A pointer to the allocated area if room is available; @c nullptr otherwise.
*/ */
inline uint8_t *allocate_write_area(size_t required_length, size_t required_alignment = 1) { inline uint8_t *allocate_write_area(std::size_t required_length, std::size_t required_alignment = 1) {
std::unique_lock<std::mutex> output_lock = openGL_output_builder_.get_output_lock(); std::unique_lock<std::mutex> output_lock = openGL_output_builder_.get_output_lock();
return openGL_output_builder_.texture_builder.allocate_write_area(required_length, required_alignment); return openGL_output_builder_.texture_builder.allocate_write_area(required_length, required_alignment);
} }

View File

@ -12,11 +12,11 @@
using namespace Outputs::CRT; using namespace Outputs::CRT;
ArrayBuilder::ArrayBuilder(size_t input_size, size_t output_size) : ArrayBuilder::ArrayBuilder(std::size_t input_size, std::size_t output_size) :
output_(output_size, nullptr), output_(output_size, nullptr),
input_(input_size, nullptr) {} input_(input_size, nullptr) {}
ArrayBuilder::ArrayBuilder(size_t input_size, size_t output_size, std::function<void(bool is_input, uint8_t *, size_t)> submission_function) : ArrayBuilder::ArrayBuilder(std::size_t input_size, std::size_t output_size, std::function<void(bool is_input, uint8_t *, std::size_t)> submission_function) :
output_(output_size, submission_function), output_(output_size, submission_function),
input_(input_size, submission_function) {} input_(input_size, submission_function) {}
@ -26,17 +26,17 @@ bool ArrayBuilder::is_full() {
return was_full; return was_full;
} }
uint8_t *ArrayBuilder::get_input_storage(size_t size) { uint8_t *ArrayBuilder::get_input_storage(std::size_t size) {
return get_storage(size, input_); return get_storage(size, input_);
} }
uint8_t *ArrayBuilder::get_output_storage(size_t size) { uint8_t *ArrayBuilder::get_output_storage(std::size_t size) {
return get_storage(size, output_); return get_storage(size, output_);
} }
void ArrayBuilder::flush(const std::function<void(uint8_t *input, size_t input_size, uint8_t *output, size_t output_size)> &function) { void ArrayBuilder::flush(const std::function<void(uint8_t *input, std::size_t input_size, uint8_t *output, std::size_t output_size)> &function) {
if(!is_full_) { if(!is_full_) {
size_t input_size = 0, output_size = 0; std::size_t input_size = 0, output_size = 0;
uint8_t *input = input_.get_unflushed(input_size); uint8_t *input = input_.get_unflushed(input_size);
uint8_t *output = output_.get_unflushed(output_size); uint8_t *output = output_.get_unflushed(output_size);
function(input, input_size, output, output_size); function(input, input_size, output, output_size);
@ -68,7 +68,7 @@ ArrayBuilder::Submission ArrayBuilder::submit() {
return submission; return submission;
} }
ArrayBuilder::Buffer::Buffer(size_t size, std::function<void(bool is_input, uint8_t *, size_t)> submission_function) : ArrayBuilder::Buffer::Buffer(std::size_t size, std::function<void(bool is_input, uint8_t *, std::size_t)> submission_function) :
submission_function_(submission_function) { submission_function_(submission_function) {
if(!submission_function_) { if(!submission_function_) {
glGenBuffers(1, &buffer); glGenBuffers(1, &buffer);
@ -83,13 +83,13 @@ ArrayBuilder::Buffer::~Buffer() {
glDeleteBuffers(1, &buffer); glDeleteBuffers(1, &buffer);
} }
uint8_t *ArrayBuilder::get_storage(size_t size, Buffer &buffer) { uint8_t *ArrayBuilder::get_storage(std::size_t size, Buffer &buffer) {
uint8_t *pointer = buffer.get_storage(size); uint8_t *pointer = buffer.get_storage(size);
if(!pointer) is_full_ = true; if(!pointer) is_full_ = true;
return pointer; return pointer;
} }
uint8_t *ArrayBuilder::Buffer::get_storage(size_t size) { uint8_t *ArrayBuilder::Buffer::get_storage(std::size_t size) {
if(is_full || allocated_data + size > data.size()) { if(is_full || allocated_data + size > data.size()) {
is_full = true; is_full = true;
return nullptr; return nullptr;
@ -99,7 +99,7 @@ uint8_t *ArrayBuilder::Buffer::get_storage(size_t size) {
return pointer; return pointer;
} }
uint8_t *ArrayBuilder::Buffer::get_unflushed(size_t &size) { uint8_t *ArrayBuilder::Buffer::get_unflushed(std::size_t &size) {
if(is_full) { if(is_full) {
return nullptr; return nullptr;
} }
@ -118,14 +118,14 @@ void ArrayBuilder::Buffer::flush() {
flushed_data = allocated_data; flushed_data = allocated_data;
} }
size_t ArrayBuilder::Buffer::submit(bool is_input) { std::size_t ArrayBuilder::Buffer::submit(bool is_input) {
size_t length = flushed_data; std::size_t length = flushed_data;
if(submission_function_) { if(submission_function_) {
submission_function_(is_input, data.data(), length); submission_function_(is_input, data.data(), length);
} else { } else {
glBindBuffer(GL_ARRAY_BUFFER, buffer); glBindBuffer(GL_ARRAY_BUFFER, buffer);
uint8_t *destination = static_cast<uint8_t *>(glMapBufferRange(GL_ARRAY_BUFFER, 0, (GLsizeiptr)length, GL_MAP_WRITE_BIT | GL_MAP_UNSYNCHRONIZED_BIT | GL_MAP_FLUSH_EXPLICIT_BIT)); uint8_t *destination = static_cast<uint8_t *>(glMapBufferRange(GL_ARRAY_BUFFER, 0, (GLsizeiptr)length, GL_MAP_WRITE_BIT | GL_MAP_UNSYNCHRONIZED_BIT | GL_MAP_FLUSH_EXPLICIT_BIT));
memcpy(destination, data.data(), length); std::memcpy(destination, data.data(), length);
glFlushMappedBufferRange(GL_ARRAY_BUFFER, 0, (GLsizeiptr)length); glFlushMappedBufferRange(GL_ARRAY_BUFFER, 0, (GLsizeiptr)length);
glUnmapBuffer(GL_ARRAY_BUFFER); glUnmapBuffer(GL_ARRAY_BUFFER);
} }

View File

@ -30,20 +30,20 @@ class ArrayBuilder {
public: public:
/// Creates an instance of ArrayBuilder with @c output_size bytes of storage for the output buffer and /// Creates an instance of ArrayBuilder with @c output_size bytes of storage for the output buffer and
/// @c input_size bytes of storage for the input buffer. /// @c input_size bytes of storage for the input buffer.
ArrayBuilder(size_t input_size, size_t output_size); ArrayBuilder(std::size_t input_size, std::size_t output_size);
/// Creates an instance of ArrayBuilder with @c output_size bytes of storage for the output buffer and /// Creates an instance of ArrayBuilder with @c output_size bytes of storage for the output buffer and
/// @c input_size bytes of storage for the input buffer that, rather than using OpenGL, will submit data /// @c input_size bytes of storage for the input buffer that, rather than using OpenGL, will submit data
/// to the @c submission_function. [Teleological: this is provided as a testing hook.] /// to the @c submission_function. [Teleological: this is provided as a testing hook.]
ArrayBuilder(size_t input_size, size_t output_size, std::function<void(bool is_input, uint8_t *, size_t)> submission_function); ArrayBuilder(std::size_t input_size, std::size_t output_size, std::function<void(bool is_input, uint8_t *, std::size_t)> submission_function);
/// Attempts to add @c size bytes to the input set. /// Attempts to add @c size bytes to the input set.
/// @returns a pointer to the allocated area if allocation was possible; @c nullptr otherwise. /// @returns a pointer to the allocated area if allocation was possible; @c nullptr otherwise.
uint8_t *get_input_storage(size_t size); uint8_t *get_input_storage(std::size_t size);
/// Attempts to add @c size bytes to the output set. /// Attempts to add @c size bytes to the output set.
/// @returns a pointer to the allocated area if allocation was possible; @c nullptr otherwise. /// @returns a pointer to the allocated area if allocation was possible; @c nullptr otherwise.
uint8_t *get_output_storage(size_t size); uint8_t *get_output_storage(std::size_t size);
/// @returns @c true if either of the input or output storage areas is currently exhausted; @c false otherwise. /// @returns @c true if either of the input or output storage areas is currently exhausted; @c false otherwise.
bool is_full(); bool is_full();
@ -51,7 +51,7 @@ class ArrayBuilder {
/// If neither input nor output was exhausted since the last flush, atomically commits both input and output /// If neither input nor output was exhausted since the last flush, atomically commits both input and output
/// up to the currently allocated size for use upon the next @c submit, giving the supplied function a /// up to the currently allocated size for use upon the next @c submit, giving the supplied function a
/// chance to perform last-minute processing. Otherwise acts as a no-op. /// chance to perform last-minute processing. Otherwise acts as a no-op.
void flush(const std::function<void(uint8_t *input, size_t input_size, uint8_t *output, size_t output_size)> &); void flush(const std::function<void(uint8_t *input, std::size_t input_size, uint8_t *output, std::size_t output_size)> &);
/// Binds the input array to GL_ARRAY_BUFFER. /// Binds the input array to GL_ARRAY_BUFFER.
void bind_input(); void bind_input();
@ -60,7 +60,7 @@ class ArrayBuilder {
void bind_output(); void bind_output();
struct Submission { struct Submission {
size_t input_size, output_size; std::size_t input_size, output_size;
}; };
/// Submits all flushed input and output data to the corresponding arrays. /// Submits all flushed input and output data to the corresponding arrays.
@ -70,27 +70,27 @@ class ArrayBuilder {
private: private:
class Buffer { class Buffer {
public: public:
Buffer(size_t size, std::function<void(bool is_input, uint8_t *, size_t)> submission_function); Buffer(std::size_t size, std::function<void(bool is_input, uint8_t *, std::size_t)> submission_function);
~Buffer(); ~Buffer();
uint8_t *get_storage(size_t size); uint8_t *get_storage(std::size_t size);
uint8_t *get_unflushed(size_t &size); uint8_t *get_unflushed(std::size_t &size);
void flush(); void flush();
size_t submit(bool is_input); std::size_t submit(bool is_input);
void bind(); void bind();
void reset(); void reset();
private: private:
bool is_full = false; bool is_full = false;
GLuint buffer = 0; GLuint buffer = 0;
std::function<void(bool is_input, uint8_t *, size_t)> submission_function_; std::function<void(bool is_input, uint8_t *, std::size_t)> submission_function_;
std::vector<uint8_t> data; std::vector<uint8_t> data;
size_t allocated_data = 0; std::size_t allocated_data = 0;
size_t flushed_data = 0; std::size_t flushed_data = 0;
size_t submitted_data = 0; std::size_t submitted_data = 0;
} output_, input_; } output_, input_;
uint8_t *get_storage(size_t size, Buffer &buffer); uint8_t *get_storage(std::size_t size, Buffer &buffer);
bool is_full_ = false; bool is_full_ = false;
}; };

View File

@ -27,7 +27,7 @@ namespace {
static const GLenum work_texture_unit = GL_TEXTURE2; static const GLenum work_texture_unit = GL_TEXTURE2;
} }
OpenGLOutputBuilder::OpenGLOutputBuilder(size_t bytes_per_pixel) : OpenGLOutputBuilder::OpenGLOutputBuilder(std::size_t bytes_per_pixel) :
visible_area_(Rect(0, 0, 1, 1)), visible_area_(Rect(0, 0, 1, 1)),
composite_src_output_y_(0), composite_src_output_y_(0),
last_output_width_(0), last_output_width_(0),
@ -51,7 +51,7 @@ OpenGLOutputBuilder::OpenGLOutputBuilder(size_t bytes_per_pixel) :
// //
// for(GLuint c = 0; c < (GLuint)number_of_extensions; c++) { // for(GLuint c = 0; c < (GLuint)number_of_extensions; c++) {
// const char *extension_name = (const char *)glGetStringi(GL_EXTENSIONS, c); // const char *extension_name = (const char *)glGetStringi(GL_EXTENSIONS, c);
// if(!strcmp(extension_name, "GL_NV_texture_barrier")) { // if(!std::strcmp(extension_name, "GL_NV_texture_barrier")) {
// supports_texture_barrier = true; // supports_texture_barrier = true;
// } // }
// } // }

View File

@ -105,7 +105,7 @@ class OpenGLOutputBuilder {
TextureBuilder texture_builder; TextureBuilder texture_builder;
ArrayBuilder array_builder; ArrayBuilder array_builder;
OpenGLOutputBuilder(size_t bytes_per_pixel); OpenGLOutputBuilder(std::size_t bytes_per_pixel);
~OpenGLOutputBuilder(); ~OpenGLOutputBuilder();
inline void set_colour_format(ColourSpace colour_space, unsigned int colour_cycle_numerator, unsigned int colour_cycle_denominator) { inline void set_colour_format(ColourSpace colour_space, unsigned int colour_cycle_numerator, unsigned int colour_cycle_denominator) {

View File

@ -9,7 +9,7 @@
#ifndef Flywheel_hpp #ifndef Flywheel_hpp
#define Flywheel_hpp #define Flywheel_hpp
#include <stdlib.h> #include <cstdlib>
namespace Outputs { namespace Outputs {
namespace CRT { namespace CRT {

View File

@ -9,9 +9,9 @@
#ifndef IntermediateShader_hpp #ifndef IntermediateShader_hpp
#define IntermediateShader_hpp #define IntermediateShader_hpp
#include <stdio.h>
#include "Shader.hpp" #include "Shader.hpp"
#include <cstdio>
#include <memory> #include <memory>
namespace OpenGL { namespace OpenGL {

View File

@ -8,8 +8,8 @@
#include "OutputShader.hpp" #include "OutputShader.hpp"
#include <stdlib.h> #include <cstdlib>
#include <math.h> #include <cmath>
using namespace OpenGL; using namespace OpenGL;

View File

@ -30,7 +30,7 @@ GLuint Shader::compile_shader(const std::string &source, GLenum type) {
GLint logLength; GLint logLength;
glGetShaderiv(shader, GL_INFO_LOG_LENGTH, &logLength); glGetShaderiv(shader, GL_INFO_LOG_LENGTH, &logLength);
if(logLength > 0) { if(logLength > 0) {
GLchar *log = new GLchar[static_cast<size_t>(logLength)]; GLchar *log = new GLchar[static_cast<std::size_t>(logLength)];
glGetShaderInfoLog(shader, logLength, &logLength, log); glGetShaderInfoLog(shader, logLength, &logLength, log);
printf("Compile log:\n%s\n", log); printf("Compile log:\n%s\n", log);
delete[] log; delete[] log;
@ -67,7 +67,7 @@ Shader::Shader(const std::string &vertex_shader, const std::string &fragment_sha
GLint logLength; GLint logLength;
glGetProgramiv(shader_program_, GL_INFO_LOG_LENGTH, &logLength); glGetProgramiv(shader_program_, GL_INFO_LOG_LENGTH, &logLength);
if(logLength > 0) { if(logLength > 0) {
GLchar *log = new GLchar[static_cast<size_t>(logLength)]; GLchar *log = new GLchar[static_cast<std::size_t>(logLength)];
glGetProgramInfoLog(shader_program_, logLength, &logLength, log); glGetProgramInfoLog(shader_program_, logLength, &logLength, log);
printf("Link log:\n%s\n", log); printf("Link log:\n%s\n", log);
delete[] log; delete[] log;
@ -187,9 +187,9 @@ void Shader::set_uniform(const std::string &name, GLuint value1, GLuint value2,
} }
void Shader::set_uniform(const std::string &name, GLint size, GLsizei count, const GLint *values) { void Shader::set_uniform(const std::string &name, GLint size, GLsizei count, const GLint *values) {
size_t number_of_values = static_cast<size_t>(count) * static_cast<size_t>(size); std::size_t number_of_values = static_cast<std::size_t>(count) * static_cast<std::size_t>(size);
GLint *values_copy = new GLint[number_of_values]; GLint *values_copy = new GLint[number_of_values];
memcpy(values_copy, values, sizeof(*values) * static_cast<size_t>(number_of_values)); std::memcpy(values_copy, values, sizeof(*values) * static_cast<std::size_t>(number_of_values));
enqueue_function([name, size, count, values_copy, this] { enqueue_function([name, size, count, values_copy, this] {
switch(size) { switch(size) {
@ -203,9 +203,9 @@ void Shader::set_uniform(const std::string &name, GLint size, GLsizei count, con
} }
void Shader::set_uniform(const std::string &name, GLint size, GLsizei count, const GLfloat *values) { void Shader::set_uniform(const std::string &name, GLint size, GLsizei count, const GLfloat *values) {
size_t number_of_values = static_cast<size_t>(count) * static_cast<size_t>(size); std::size_t number_of_values = static_cast<std::size_t>(count) * static_cast<std::size_t>(size);
GLfloat *values_copy = new GLfloat[number_of_values]; GLfloat *values_copy = new GLfloat[number_of_values];
memcpy(values_copy, values, sizeof(*values) * static_cast<size_t>(number_of_values)); std::memcpy(values_copy, values, sizeof(*values) * static_cast<std::size_t>(number_of_values));
enqueue_function([name, size, count, values_copy, this] { enqueue_function([name, size, count, values_copy, this] {
switch(size) { switch(size) {
@ -219,9 +219,9 @@ void Shader::set_uniform(const std::string &name, GLint size, GLsizei count, con
} }
void Shader::set_uniform(const std::string &name, GLint size, GLsizei count, const GLuint *values) { void Shader::set_uniform(const std::string &name, GLint size, GLsizei count, const GLuint *values) {
size_t number_of_values = static_cast<size_t>(count) * static_cast<size_t>(size); std::size_t number_of_values = static_cast<std::size_t>(count) * static_cast<std::size_t>(size);
GLuint *values_copy = new GLuint[number_of_values]; GLuint *values_copy = new GLuint[number_of_values];
memcpy(values_copy, values, sizeof(*values) * static_cast<size_t>(number_of_values)); std::memcpy(values_copy, values, sizeof(*values) * static_cast<std::size_t>(number_of_values));
enqueue_function([name, size, count, values_copy, this] { enqueue_function([name, size, count, values_copy, this] {
switch(size) { switch(size) {
@ -239,9 +239,9 @@ void Shader::set_uniform_matrix(const std::string &name, GLint size, bool transp
} }
void Shader::set_uniform_matrix(const std::string &name, GLint size, GLsizei count, bool transpose, const GLfloat *values) { void Shader::set_uniform_matrix(const std::string &name, GLint size, GLsizei count, bool transpose, const GLfloat *values) {
size_t number_of_values = static_cast<size_t>(count) * static_cast<size_t>(size) * static_cast<size_t>(size); std::size_t number_of_values = static_cast<std::size_t>(count) * static_cast<std::size_t>(size) * static_cast<std::size_t>(size);
GLfloat *values_copy = new GLfloat[number_of_values]; GLfloat *values_copy = new GLfloat[number_of_values];
memcpy(values_copy, values, sizeof(*values) * number_of_values); std::memcpy(values_copy, values, sizeof(*values) * number_of_values);
enqueue_function([name, size, count, transpose, values_copy, this] { enqueue_function([name, size, count, transpose, values_copy, this] {
GLboolean glTranspose = transpose ? GL_TRUE : GL_FALSE; GLboolean glTranspose = transpose ? GL_TRUE : GL_FALSE;

View File

@ -9,13 +9,14 @@
#include "TextureBuilder.hpp" #include "TextureBuilder.hpp"
#include "CRTOpenGL.hpp" #include "CRTOpenGL.hpp"
#include "OpenGL.hpp" #include "OpenGL.hpp"
#include <string.h>
#include <cstring>
using namespace Outputs::CRT; using namespace Outputs::CRT;
namespace { namespace {
const GLint internalFormatForDepth(size_t depth) { const GLint internalFormatForDepth(std::size_t depth) {
switch(depth) { switch(depth) {
default: return GL_FALSE; default: return GL_FALSE;
case 1: return GL_R8UI; case 1: return GL_R8UI;
@ -25,7 +26,7 @@ const GLint internalFormatForDepth(size_t depth) {
} }
} }
const GLenum formatForDepth(size_t depth) { const GLenum formatForDepth(std::size_t depth) {
switch(depth) { switch(depth) {
default: return GL_FALSE; default: return GL_FALSE;
case 1: return GL_RED_INTEGER; case 1: return GL_RED_INTEGER;
@ -37,20 +38,20 @@ const GLenum formatForDepth(size_t depth) {
struct DefaultBookender: public TextureBuilder::Bookender { struct DefaultBookender: public TextureBuilder::Bookender {
public: public:
DefaultBookender(size_t bytes_per_pixel) : bytes_per_pixel_(bytes_per_pixel) {} DefaultBookender(std::size_t bytes_per_pixel) : bytes_per_pixel_(bytes_per_pixel) {}
void add_bookends(uint8_t *const left_value, uint8_t *const right_value, uint8_t *left_bookend, uint8_t *right_bookend) { void add_bookends(uint8_t *const left_value, uint8_t *const right_value, uint8_t *left_bookend, uint8_t *right_bookend) {
memcpy(left_bookend, left_value, bytes_per_pixel_); std::memcpy(left_bookend, left_value, bytes_per_pixel_);
memcpy(right_bookend, right_value, bytes_per_pixel_); std::memcpy(right_bookend, right_value, bytes_per_pixel_);
} }
private: private:
size_t bytes_per_pixel_; std::size_t bytes_per_pixel_;
}; };
} }
TextureBuilder::TextureBuilder(size_t bytes_per_pixel, GLenum texture_unit) : TextureBuilder::TextureBuilder(std::size_t bytes_per_pixel, GLenum texture_unit) :
bytes_per_pixel_(bytes_per_pixel) { bytes_per_pixel_(bytes_per_pixel) {
image_.resize(bytes_per_pixel * InputBufferBuilderWidth * InputBufferBuilderHeight); image_.resize(bytes_per_pixel * InputBufferBuilderWidth * InputBufferBuilderHeight);
glGenTextures(1, &texture_name_); glGenTextures(1, &texture_name_);
@ -74,7 +75,7 @@ inline uint8_t *TextureBuilder::pointer_to_location(uint16_t x, uint16_t y) {
return &image_[((y * InputBufferBuilderWidth) + x) * bytes_per_pixel_]; return &image_[((y * InputBufferBuilderWidth) + x) * bytes_per_pixel_];
} }
uint8_t *TextureBuilder::allocate_write_area(size_t required_length, size_t required_alignment) { uint8_t *TextureBuilder::allocate_write_area(std::size_t required_length, std::size_t required_alignment) {
// Keep a flag to indicate whether the buffer was full at allocate_write_area; if it was then // Keep a flag to indicate whether the buffer was full at allocate_write_area; if it was then
// don't return anything now, and decline to act upon follow-up methods. is_full_ may be reset // don't return anything now, and decline to act upon follow-up methods. is_full_ may be reset
// by asynchronous calls to submit. was_full_ will not be touched by it. // by asynchronous calls to submit. was_full_ will not be touched by it.
@ -83,7 +84,7 @@ uint8_t *TextureBuilder::allocate_write_area(size_t required_length, size_t requ
// If there's not enough space on this line, move to the next. If the next is where the current // If there's not enough space on this line, move to the next. If the next is where the current
// submission group started, trigger is/was_full_ and return nothing. // submission group started, trigger is/was_full_ and return nothing.
size_t alignment_offset = (required_alignment - ((write_areas_start_x_ + 1) % required_alignment)) % required_alignment; std::size_t alignment_offset = (required_alignment - ((write_areas_start_x_ + 1) % required_alignment)) % required_alignment;
if(write_areas_start_x_ + required_length + 2 + alignment_offset > InputBufferBuilderWidth) { if(write_areas_start_x_ + required_length + 2 + alignment_offset > InputBufferBuilderWidth) {
write_areas_start_x_ = 0; write_areas_start_x_ = 0;
alignment_offset = required_alignment - 1; alignment_offset = required_alignment - 1;
@ -105,7 +106,7 @@ uint8_t *TextureBuilder::allocate_write_area(size_t required_length, size_t requ
return pointer_to_location(write_area_.x, write_area_.y); return pointer_to_location(write_area_.x, write_area_.y);
} }
void TextureBuilder::reduce_previous_allocation_to(size_t actual_length) { void TextureBuilder::reduce_previous_allocation_to(std::size_t actual_length) {
// If the previous allocate_write_area declined to act, decline also. // If the previous allocate_write_area declined to act, decline also.
if(was_full_) return; if(was_full_) return;
@ -187,7 +188,7 @@ void TextureBuilder::submit() {
is_full_ = false; is_full_ = false;
} }
void TextureBuilder::flush(const std::function<void(const std::vector<WriteArea> &write_areas, size_t count)> &function) { void TextureBuilder::flush(const std::function<void(const std::vector<WriteArea> &write_areas, std::size_t count)> &function) {
// Just throw everything currently in the flush queue to the provided function, and note that // Just throw everything currently in the flush queue to the provided function, and note that
// the queue is now empty. // the queue is now empty.
if(number_of_write_areas_) { if(number_of_write_areas_) {

View File

@ -63,18 +63,18 @@ class TextureBuilder {
public: public:
/// Constructs an instance of InputTextureBuilder that contains a texture of colour depth @c bytes_per_pixel; /// Constructs an instance of InputTextureBuilder that contains a texture of colour depth @c bytes_per_pixel;
/// this creates a new texture and binds it to the current active texture unit. /// this creates a new texture and binds it to the current active texture unit.
TextureBuilder(size_t bytes_per_pixel, GLenum texture_unit); TextureBuilder(std::size_t bytes_per_pixel, GLenum texture_unit);
virtual ~TextureBuilder(); virtual ~TextureBuilder();
/// Finds the first available space of at least @c required_length pixels in size which is suitably aligned /// Finds the first available space of at least @c required_length pixels in size which is suitably aligned
/// for writing of @c required_alignment number of pixels at a time. /// for writing of @c required_alignment number of pixels at a time.
/// Calls must be paired off with calls to @c reduce_previous_allocation_to. /// Calls must be paired off with calls to @c reduce_previous_allocation_to.
/// @returns a pointer to the allocated space if any was available; @c nullptr otherwise. /// @returns a pointer to the allocated space if any was available; @c nullptr otherwise.
uint8_t *allocate_write_area(size_t required_length, size_t required_alignment = 1); uint8_t *allocate_write_area(std::size_t required_length, std::size_t required_alignment = 1);
/// Announces that the owner is finished with the region created by the most recent @c allocate_write_area /// Announces that the owner is finished with the region created by the most recent @c allocate_write_area
/// and indicates that its actual final size was @c actual_length. /// and indicates that its actual final size was @c actual_length.
void reduce_previous_allocation_to(size_t actual_length); void reduce_previous_allocation_to(std::size_t actual_length);
/// Allocated runs are provisional; they will not appear in the next flush queue unless retained. /// Allocated runs are provisional; they will not appear in the next flush queue unless retained.
/// @returns @c true if a retain succeeded; @c false otherwise. /// @returns @c true if a retain succeeded; @c false otherwise.
@ -96,7 +96,7 @@ class TextureBuilder {
/// Finalises all write areas allocated since the last call to @c flush. Only finalised areas will be /// Finalises all write areas allocated since the last call to @c flush. Only finalised areas will be
/// submitted upon the next @c submit. The supplied function will be called with a list of write areas /// submitted upon the next @c submit. The supplied function will be called with a list of write areas
/// allocated, indicating their final resting locations and their lengths. /// allocated, indicating their final resting locations and their lengths.
void flush(const std::function<void(const std::vector<WriteArea> &write_areas, size_t count)> &); void flush(const std::function<void(const std::vector<WriteArea> &write_areas, std::size_t count)> &);
/// A Bookender helps to paper over precision errors when rendering; its job is to provide single-sample /// A Bookender helps to paper over precision errors when rendering; its job is to provide single-sample
/// extensions that duplicate the left and right edges of a written area. By default the texture builder will /// extensions that duplicate the left and right edges of a written area. By default the texture builder will
@ -116,7 +116,7 @@ class TextureBuilder {
private: private:
// the buffer size // the buffer size
size_t bytes_per_pixel_; std::size_t bytes_per_pixel_;
// the buffer // the buffer
std::vector<uint8_t> image_; std::vector<uint8_t> image_;
@ -127,7 +127,7 @@ class TextureBuilder {
// the list of write areas that have ascended to the flush queue // the list of write areas that have ascended to the flush queue
std::vector<WriteArea> write_areas_; std::vector<WriteArea> write_areas_;
size_t number_of_write_areas_ = 0; std::size_t number_of_write_areas_ = 0;
bool is_full_ = false, was_full_ = false; bool is_full_ = false, was_full_ = false;
uint16_t first_unsubmitted_y_ = 0; uint16_t first_unsubmitted_y_ = 0;
inline uint8_t *pointer_to_location(uint16_t x, uint16_t y); inline uint8_t *pointer_to_location(uint16_t x, uint16_t y);

View File

@ -7,8 +7,9 @@
// //
#include "TextureTarget.hpp" #include "TextureTarget.hpp"
#include <math.h>
#include <stdlib.h> #include <cmath>
#include <cstdlib>
using namespace OpenGL; using namespace OpenGL;
@ -26,7 +27,7 @@ TextureTarget::TextureTarget(GLsizei width, GLsizei height, GLenum texture_unit,
glGenTextures(1, &_texture); glGenTextures(1, &_texture);
glActiveTexture(texture_unit); glActiveTexture(texture_unit);
glBindTexture(GL_TEXTURE_2D, _texture); glBindTexture(GL_TEXTURE_2D, _texture);
uint8_t *blank_buffer = static_cast<uint8_t *>(calloc(static_cast<size_t>(_expanded_width * _expanded_height), 4)); uint8_t *blank_buffer = static_cast<uint8_t *>(calloc(static_cast<std::size_t>(_expanded_width * _expanded_height), 4));
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, (GLsizei)_expanded_width, (GLsizei)_expanded_height, 0, GL_RGBA, GL_UNSIGNED_BYTE, blank_buffer); glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, (GLsizei)_expanded_width, (GLsizei)_expanded_height, 0, GL_RGBA, GL_UNSIGNED_BYTE, blank_buffer);
free(blank_buffer); free(blank_buffer);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, mag_filter); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, mag_filter);

View File

@ -57,12 +57,12 @@ class Speaker {
void set_output_rate(float cycles_per_second, int buffer_size) { void set_output_rate(float cycles_per_second, int buffer_size) {
output_cycles_per_second_ = cycles_per_second; output_cycles_per_second_ = cycles_per_second;
buffer_in_progress_.resize(static_cast<size_t>(buffer_size)); buffer_in_progress_.resize(static_cast<std::size_t>(buffer_size));
set_needs_updated_filter_coefficients(); set_needs_updated_filter_coefficients();
} }
void set_output_quality(int number_of_taps) { void set_output_quality(int number_of_taps) {
requested_number_of_taps_ = static_cast<size_t>(number_of_taps); requested_number_of_taps_ = static_cast<std::size_t>(number_of_taps);
set_needs_updated_filter_coefficients(); set_needs_updated_filter_coefficients();
} }
@ -108,9 +108,9 @@ class Speaker {
std::vector<int16_t> buffer_in_progress_; std::vector<int16_t> buffer_in_progress_;
float high_frequency_cut_off_ = -1.0; float high_frequency_cut_off_ = -1.0;
size_t buffer_in_progress_pointer_ = 0; std::size_t buffer_in_progress_pointer_ = 0;
size_t number_of_taps_; std::size_t number_of_taps_;
size_t requested_number_of_taps_ = 0; std::size_t requested_number_of_taps_ = 0;
bool coefficients_are_dirty_; bool coefficients_are_dirty_;
Delegate *delegate_ = nullptr; Delegate *delegate_ = nullptr;
@ -153,10 +153,10 @@ template <class T> class Filter: public Speaker {
// if input and output rates exactly match, just accumulate results and pass on // if input and output rates exactly match, just accumulate results and pass on
if(input_cycles_per_second_ == output_cycles_per_second_ && high_frequency_cut_off_ < 0.0) { if(input_cycles_per_second_ == output_cycles_per_second_ && high_frequency_cut_off_ < 0.0) {
while(cycles_remaining) { while(cycles_remaining) {
unsigned int cycles_to_read = static_cast<unsigned int>(buffer_in_progress_.size() - static_cast<size_t>(buffer_in_progress_pointer_)); unsigned int cycles_to_read = static_cast<unsigned int>(buffer_in_progress_.size() - static_cast<std::size_t>(buffer_in_progress_pointer_));
if(cycles_to_read > cycles_remaining) cycles_to_read = cycles_remaining; if(cycles_to_read > cycles_remaining) cycles_to_read = cycles_remaining;
static_cast<T *>(this)->get_samples(cycles_to_read, &buffer_in_progress_[static_cast<size_t>(buffer_in_progress_pointer_)]); static_cast<T *>(this)->get_samples(cycles_to_read, &buffer_in_progress_[static_cast<std::size_t>(buffer_in_progress_pointer_)]);
buffer_in_progress_pointer_ += cycles_to_read; buffer_in_progress_pointer_ += cycles_to_read;
// announce to delegate if full // announce to delegate if full
@ -176,13 +176,13 @@ template <class T> class Filter: public Speaker {
// if the output rate is less than the input rate, use the filter // if the output rate is less than the input rate, use the filter
if(input_cycles_per_second_ > output_cycles_per_second_ || (input_cycles_per_second_ == output_cycles_per_second_ && high_frequency_cut_off_ >= 0.0)) { if(input_cycles_per_second_ > output_cycles_per_second_ || (input_cycles_per_second_ == output_cycles_per_second_ && high_frequency_cut_off_ >= 0.0)) {
while(cycles_remaining) { while(cycles_remaining) {
unsigned int cycles_to_read = static_cast<unsigned int>(std::min(static_cast<size_t>(cycles_remaining), number_of_taps_ - input_buffer_depth_)); unsigned int cycles_to_read = static_cast<unsigned int>(std::min(static_cast<std::size_t>(cycles_remaining), number_of_taps_ - input_buffer_depth_));
static_cast<T *>(this)->get_samples(cycles_to_read, &input_buffer_[static_cast<size_t>(input_buffer_depth_)]); static_cast<T *>(this)->get_samples(cycles_to_read, &input_buffer_[static_cast<std::size_t>(input_buffer_depth_)]);
cycles_remaining -= cycles_to_read; cycles_remaining -= cycles_to_read;
input_buffer_depth_ += cycles_to_read; input_buffer_depth_ += cycles_to_read;
if(input_buffer_depth_ == number_of_taps_) { if(input_buffer_depth_ == number_of_taps_) {
buffer_in_progress_[static_cast<size_t>(buffer_in_progress_pointer_)] = filter_->apply(input_buffer_.data()); buffer_in_progress_[static_cast<std::size_t>(buffer_in_progress_pointer_)] = filter_->apply(input_buffer_.data());
buffer_in_progress_pointer_++; buffer_in_progress_pointer_++;
// announce to delegate if full // announce to delegate if full
@ -199,7 +199,7 @@ template <class T> class Filter: public Speaker {
uint64_t steps = stepper_->step(); uint64_t steps = stepper_->step();
if(steps < number_of_taps_) { if(steps < number_of_taps_) {
int16_t *input_buffer = input_buffer_.data(); int16_t *input_buffer = input_buffer_.data();
memmove(input_buffer, &input_buffer[steps], sizeof(int16_t) * (static_cast<size_t>(number_of_taps_) - static_cast<size_t>(steps))); memmove(input_buffer, &input_buffer[steps], sizeof(int16_t) * (static_cast<std::size_t>(number_of_taps_) - static_cast<std::size_t>(steps)));
input_buffer_depth_ -= steps; input_buffer_depth_ -= steps;
} else { } else {
if(steps > number_of_taps_) if(steps > number_of_taps_)
@ -221,14 +221,14 @@ template <class T> class Filter: public Speaker {
std::unique_ptr<SignalProcessing::FIRFilter> filter_; std::unique_ptr<SignalProcessing::FIRFilter> filter_;
std::vector<int16_t> input_buffer_; std::vector<int16_t> input_buffer_;
size_t input_buffer_depth_; std::size_t input_buffer_depth_;
void update_filter_coefficients() { void update_filter_coefficients() {
// make a guess at a good number of taps if this hasn't been provided explicitly // make a guess at a good number of taps if this hasn't been provided explicitly
if(requested_number_of_taps_) { if(requested_number_of_taps_) {
number_of_taps_ = requested_number_of_taps_; number_of_taps_ = requested_number_of_taps_;
} else { } else {
number_of_taps_ = static_cast<size_t>(ceilf((input_cycles_per_second_ + output_cycles_per_second_) / output_cycles_per_second_)); number_of_taps_ = static_cast<std::size_t>(ceilf((input_cycles_per_second_ + output_cycles_per_second_) / output_cycles_per_second_));
number_of_taps_ *= 2; number_of_taps_ *= 2;
number_of_taps_ |= 1; number_of_taps_ |= 1;
} }
@ -246,7 +246,7 @@ template <class T> class Filter: public Speaker {
} }
filter_.reset(new SignalProcessing::FIRFilter(static_cast<unsigned int>(number_of_taps_), static_cast<float>(input_cycles_per_second_), 0.0, high_pass_frequency, SignalProcessing::FIRFilter::DefaultAttenuation)); filter_.reset(new SignalProcessing::FIRFilter(static_cast<unsigned int>(number_of_taps_), static_cast<float>(input_cycles_per_second_), 0.0, high_pass_frequency, SignalProcessing::FIRFilter::DefaultAttenuation));
input_buffer_.resize(static_cast<size_t>(number_of_taps_)); input_buffer_.resize(static_cast<std::size_t>(number_of_taps_));
input_buffer_depth_ = 0; input_buffer_depth_ = 0;
} }
}; };

View File

@ -7,8 +7,9 @@
// //
#include "6502AllRAM.hpp" #include "6502AllRAM.hpp"
#include <algorithm> #include <algorithm>
#include <string.h> #include <cstring>
using namespace CPU::MOS6502; using namespace CPU::MOS6502;

View File

@ -10,19 +10,19 @@
using namespace CPU; using namespace CPU;
AllRAMProcessor::AllRAMProcessor(size_t memory_size) : AllRAMProcessor::AllRAMProcessor(std::size_t memory_size) :
memory_(memory_size), memory_(memory_size),
traps_(memory_size, false), traps_(memory_size, false),
timestamp_(0) {} timestamp_(0) {}
void AllRAMProcessor::set_data_at_address(uint16_t startAddress, size_t length, const uint8_t *data) { void AllRAMProcessor::set_data_at_address(uint16_t startAddress, std::size_t length, const uint8_t *data) {
size_t endAddress = std::min(startAddress + length, static_cast<size_t>(65536)); std::size_t endAddress = std::min(startAddress + length, static_cast<std::size_t>(65536));
memcpy(&memory_[startAddress], data, endAddress - startAddress); std::memcpy(&memory_[startAddress], data, endAddress - startAddress);
} }
void AllRAMProcessor::get_data_at_address(uint16_t startAddress, size_t length, uint8_t *data) { void AllRAMProcessor::get_data_at_address(uint16_t startAddress, std::size_t length, uint8_t *data) {
size_t endAddress = std::min(startAddress + length, static_cast<size_t>(65536)); std::size_t endAddress = std::min(startAddress + length, static_cast<std::size_t>(65536));
memcpy(data, &memory_[startAddress], endAddress - startAddress); std::memcpy(data, &memory_[startAddress], endAddress - startAddress);
} }
HalfCycles AllRAMProcessor::get_timestamp() { HalfCycles AllRAMProcessor::get_timestamp() {

View File

@ -19,10 +19,10 @@ namespace CPU {
class AllRAMProcessor { class AllRAMProcessor {
public: public:
AllRAMProcessor(size_t memory_size); AllRAMProcessor(std::size_t memory_size);
HalfCycles get_timestamp(); HalfCycles get_timestamp();
void set_data_at_address(uint16_t startAddress, size_t length, const uint8_t *data); void set_data_at_address(uint16_t startAddress, std::size_t length, const uint8_t *data);
void get_data_at_address(uint16_t startAddress, size_t length, uint8_t *data); void get_data_at_address(uint16_t startAddress, std::size_t length, uint8_t *data);
class TrapHandler { class TrapHandler {
public: public:

View File

@ -893,12 +893,12 @@ template < class T,
bool uses_bus_request, bool uses_bus_request,
bool uses_wait_line> void Processor <T, uses_bus_request, uses_wait_line> bool uses_wait_line> void Processor <T, uses_bus_request, uses_wait_line>
::assemble_page(InstructionPage &target, InstructionTable &table, bool add_offsets) { ::assemble_page(InstructionPage &target, InstructionTable &table, bool add_offsets) {
size_t number_of_micro_ops = 0; std::size_t number_of_micro_ops = 0;
size_t lengths[256]; std::size_t lengths[256];
// Count number of micro-ops required. // Count number of micro-ops required.
for(int c = 0; c < 256; c++) { for(int c = 0; c < 256; c++) {
size_t length = 0; std::size_t length = 0;
while(!isTerminal(table[c][length].type)) length++; while(!isTerminal(table[c][length].type)) length++;
length++; length++;
lengths[c] = length; lengths[c] = length;
@ -906,15 +906,15 @@ template < class T,
} }
// Allocate a landing area. // Allocate a landing area.
std::vector<size_t> operation_indices; std::vector<std::size_t> operation_indices;
target.all_operations.reserve(number_of_micro_ops); target.all_operations.reserve(number_of_micro_ops);
target.instructions.resize(256, nullptr); target.instructions.resize(256, nullptr);
// Copy in all programs, recording where they go. // Copy in all programs, recording where they go.
size_t destination = 0; std::size_t destination = 0;
for(size_t c = 0; c < 256; c++) { for(std::size_t c = 0; c < 256; c++) {
operation_indices.push_back(target.all_operations.size()); operation_indices.push_back(target.all_operations.size());
for(size_t t = 0; t < lengths[c];) { for(std::size_t t = 0; t < lengths[c];) {
// Skip zero-length bus cycles. // Skip zero-length bus cycles.
if(table[c][t].type == MicroOp::BusOperation && table[c][t].machine_cycle.length.as_int() == 0) { if(table[c][t].type == MicroOp::BusOperation && table[c][t].machine_cycle.length.as_int() == 0) {
t++; t++;
@ -944,8 +944,8 @@ template < class T,
} }
// Since the vector won't change again, it's now safe to set pointers. // Since the vector won't change again, it's now safe to set pointers.
size_t c = 0; std::size_t c = 0;
for(size_t index : operation_indices) { for(std::size_t index : operation_indices) {
target.instructions[c] = &target.all_operations[index]; target.instructions[c] = &target.all_operations[index];
c++; c++;
} }
@ -955,9 +955,9 @@ template < class T,
bool uses_bus_request, bool uses_bus_request,
bool uses_wait_line> void Processor <T, uses_bus_request, uses_wait_line> bool uses_wait_line> void Processor <T, uses_bus_request, uses_wait_line>
::copy_program(const MicroOp *source, std::vector<MicroOp> &destination) { ::copy_program(const MicroOp *source, std::vector<MicroOp> &destination) {
size_t length = 0; std::size_t length = 0;
while(!isTerminal(source[length].type)) length++; while(!isTerminal(source[length].type)) length++;
size_t pointer = 0; std::size_t pointer = 0;
while(true) { while(true) {
// TODO: This test is duplicated from assemble_page; can a better factoring be found? // TODO: This test is duplicated from assemble_page; can a better factoring be found?
// Skip optional waits if this instance doesn't use the wait line. // Skip optional waits if this instance doesn't use the wait line.

View File

@ -513,7 +513,7 @@ void ProcessorStorage::assemble_base_page(InstructionPage &target, RegisterPair
InstructionTable copy_table = { InstructionTable copy_table = {
StdInstr(FINDEX(), Read5Inc(pc_, temp8_), Write3(INDEX_ADDR(), temp8_)) StdInstr(FINDEX(), Read5Inc(pc_, temp8_), Write3(INDEX_ADDR(), temp8_))
}; };
memcpy(&base_program_table[0x36], &copy_table[0], sizeof(copy_table[0])); std::memcpy(&base_program_table[0x36], &copy_table[0], sizeof(copy_table[0]));
} }
assemble_cb_page(cb_page, index, add_offsets); assemble_cb_page(cb_page, index, add_offsets);

View File

@ -7,7 +7,7 @@
// //
#include "FIRFilter.hpp" #include "FIRFilter.hpp"
#include <math.h> #include <cmath>
using namespace SignalProcessing; using namespace SignalProcessing;
@ -46,7 +46,7 @@ float FIRFilter::ino(float a) {
return s; return s;
} }
void FIRFilter::coefficients_for_idealised_filter_response(short *filter_coefficients, float *A, float attenuation, size_t number_of_taps) { void FIRFilter::coefficients_for_idealised_filter_response(short *filter_coefficients, float *A, float attenuation, std::size_t number_of_taps) {
/* calculate alpha, which is the Kaiser-Bessel window shape factor */ /* calculate alpha, which is the Kaiser-Bessel window shape factor */
float a; // to take the place of alpha in the normal derivation float a; // to take the place of alpha in the normal derivation
@ -62,7 +62,7 @@ void FIRFilter::coefficients_for_idealised_filter_response(short *filter_coeffic
std::vector<float> filter_coefficients_float(number_of_taps); std::vector<float> filter_coefficients_float(number_of_taps);
/* work out the right hand side of the filter coefficients */ /* work out the right hand side of the filter coefficients */
size_t Np = (number_of_taps - 1) / 2; std::size_t Np = (number_of_taps - 1) / 2;
float I0 = ino(a); float I0 = ino(a);
float Np_squared = static_cast<float>(Np * Np); float Np_squared = static_cast<float>(Np * Np);
for(unsigned int i = 0; i <= Np; ++i) { for(unsigned int i = 0; i <= Np; ++i) {
@ -73,19 +73,19 @@ void FIRFilter::coefficients_for_idealised_filter_response(short *filter_coeffic
} }
/* coefficients are symmetrical, so copy from right hand side to left side */ /* coefficients are symmetrical, so copy from right hand side to left side */
for(size_t i = 0; i < Np; ++i) { for(std::size_t i = 0; i < Np; ++i) {
filter_coefficients_float[i] = filter_coefficients_float[number_of_taps - 1 - i]; filter_coefficients_float[i] = filter_coefficients_float[number_of_taps - 1 - i];
} }
/* scale back up so that we retain 100% of input volume */ /* scale back up so that we retain 100% of input volume */
float coefficientTotal = 0.0f; float coefficientTotal = 0.0f;
for(size_t i = 0; i < number_of_taps; ++i) { for(std::size_t i = 0; i < number_of_taps; ++i) {
coefficientTotal += filter_coefficients_float[i]; coefficientTotal += filter_coefficients_float[i];
} }
/* we'll also need integer versions, potentially */ /* we'll also need integer versions, potentially */
float coefficientMultiplier = 1.0f / coefficientTotal; float coefficientMultiplier = 1.0f / coefficientTotal;
for(size_t i = 0; i < number_of_taps; ++i) { for(std::size_t i = 0; i < number_of_taps; ++i) {
filter_coefficients[i] = static_cast<short>(filter_coefficients_float[i] * FixedMultiplier * coefficientMultiplier); filter_coefficients[i] = static_cast<short>(filter_coefficients_float[i] * FixedMultiplier * coefficientMultiplier);
} }
} }
@ -98,7 +98,7 @@ std::vector<float> FIRFilter::get_coefficients() const {
return coefficients; return coefficients;
} }
FIRFilter::FIRFilter(size_t number_of_taps, float input_sample_rate, float low_frequency, float high_frequency, float attenuation) { FIRFilter::FIRFilter(std::size_t number_of_taps, float input_sample_rate, float low_frequency, float high_frequency, float attenuation) {
// we must be asked to filter based on an odd number of // we must be asked to filter based on an odd number of
// taps, and at least three // taps, and at least three
if(number_of_taps < 3) number_of_taps = 3; if(number_of_taps < 3) number_of_taps = 3;
@ -111,7 +111,7 @@ FIRFilter::FIRFilter(size_t number_of_taps, float input_sample_rate, float low_f
filter_coefficients_.resize(number_of_taps); filter_coefficients_.resize(number_of_taps);
/* calculate idealised filter response */ /* calculate idealised filter response */
size_t Np = (number_of_taps - 1) / 2; std::size_t Np = (number_of_taps - 1) / 2;
float two_over_sample_rate = 2.0f / input_sample_rate; float two_over_sample_rate = 2.0f / input_sample_rate;
std::vector<float> A(Np+1); std::vector<float> A(Np+1);
@ -139,7 +139,7 @@ FIRFilter FIRFilter::operator+(const FIRFilter &rhs) const {
std::vector<float> rhs_coefficients = rhs.get_coefficients(); std::vector<float> rhs_coefficients = rhs.get_coefficients();
std::vector<float> sum; std::vector<float> sum;
for(size_t i = 0; i < coefficients.size(); ++i) { for(std::size_t i = 0; i < coefficients.size(); ++i) {
sum.push_back((coefficients[i] + rhs_coefficients[i]) / 2.0f); sum.push_back((coefficients[i] + rhs_coefficients[i]) / 2.0f);
} }
@ -151,7 +151,7 @@ FIRFilter FIRFilter::operator*(const FIRFilter &rhs) const {
std::vector<float> rhs_coefficients = rhs.get_coefficients(); std::vector<float> rhs_coefficients = rhs.get_coefficients();
std::vector<float> sum; std::vector<float> sum;
for(size_t i = 0; i < coefficients.size(); ++i) { for(std::size_t i = 0; i < coefficients.size(); ++i) {
sum.push_back(coefficients[i] * rhs_coefficients[i]); sum.push_back(coefficients[i] * rhs_coefficients[i]);
} }

View File

@ -38,7 +38,7 @@ class FIRFilter {
@param high_frequency The highest frequency of signal to retain in the output. @param high_frequency The highest frequency of signal to retain in the output.
@param attenuation The attenuation of the discarded frequencies. @param attenuation The attenuation of the discarded frequencies.
*/ */
FIRFilter(size_t number_of_taps, float input_sample_rate, float low_frequency, float high_frequency, float attenuation); FIRFilter(std::size_t number_of_taps, float input_sample_rate, float low_frequency, float high_frequency, float attenuation);
FIRFilter(const std::vector<float> &coefficients); FIRFilter(const std::vector<float> &coefficients);
/*! A suggested default attenuation value. */ /*! A suggested default attenuation value. */
@ -57,7 +57,7 @@ class FIRFilter {
return result; return result;
#else #else
int outputValue = 0; int outputValue = 0;
for(size_t c = 0; c < filter_coefficients_.size(); ++c) { for(std::size_t c = 0; c < filter_coefficients_.size(); ++c) {
outputValue += filter_coefficients_[c] * src[c]; outputValue += filter_coefficients_[c] * src[c];
} }
return static_cast<short>(outputValue >> FixedShift); return static_cast<short>(outputValue >> FixedShift);
@ -65,7 +65,7 @@ class FIRFilter {
} }
/*! @returns The number of taps used by this filter. */ /*! @returns The number of taps used by this filter. */
inline size_t get_number_of_taps() const { inline std::size_t get_number_of_taps() const {
return filter_coefficients_.size(); return filter_coefficients_.size();
} }
@ -87,7 +87,7 @@ class FIRFilter {
private: private:
std::vector<short> filter_coefficients_; std::vector<short> filter_coefficients_;
static void coefficients_for_idealised_filter_response(short *filterCoefficients, float *A, float attenuation, size_t numberOfTaps); static void coefficients_for_idealised_filter_response(short *filterCoefficients, float *A, float attenuation, std::size_t numberOfTaps);
static float ino(float a); static float ino(float a);
}; };

View File

@ -9,7 +9,7 @@
#ifndef Stepper_hpp #ifndef Stepper_hpp
#define Stepper_hpp #define Stepper_hpp
#include <stdint.h> #include <cstdint>
namespace SignalProcessing { namespace SignalProcessing {

View File

@ -43,7 +43,7 @@ std::unique_ptr<Catalogue> StaticAnalyser::Acorn::GetDFSCatalogue(const std::sha
// DFS files are stored contiguously, and listed in descending order of distance from track 0. // DFS files are stored contiguously, and listed in descending order of distance from track 0.
// So iterating backwards implies the least amount of seeking. // So iterating backwards implies the least amount of seeking.
for(size_t file_offset = final_file_offset - 8; file_offset > 0; file_offset -= 8) { for(std::size_t file_offset = final_file_offset - 8; file_offset > 0; file_offset -= 8) {
File new_file; File new_file;
char name[10]; char name[10];
snprintf(name, 10, "%c.%.7s", names->samples[0][file_offset + 7] & 0x7f, &names->samples[0][file_offset]); snprintf(name, 10, "%c.%.7s", names->samples[0][file_offset + 7] & 0x7f, &names->samples[0][file_offset]);
@ -54,7 +54,7 @@ std::unique_ptr<Catalogue> StaticAnalyser::Acorn::GetDFSCatalogue(const std::sha
long data_length = static_cast<long>(details->samples[0][file_offset+4] | (details->samples[0][file_offset+5] << 8) | ((details->samples[0][file_offset+6]&0x30) << 12)); long data_length = static_cast<long>(details->samples[0][file_offset+4] | (details->samples[0][file_offset+5] << 8) | ((details->samples[0][file_offset+6]&0x30) << 12));
int start_sector = details->samples[0][file_offset+7] | ((details->samples[0][file_offset+6]&0x03) << 8); int start_sector = details->samples[0][file_offset+7] | ((details->samples[0][file_offset+6]&0x03) << 8);
new_file.data.reserve(static_cast<size_t>(data_length)); new_file.data.reserve(static_cast<std::size_t>(data_length));
if(start_sector < 2) continue; if(start_sector < 2) continue;
while(data_length > 0) { while(data_length > 0) {

View File

@ -82,9 +82,9 @@ void StaticAnalyser::Acorn::AddTargets(const Media &media, std::list<Target> &de
// check also for a continuous threading of BASIC lines; if none then this probably isn't BASIC code, // check also for a continuous threading of BASIC lines; if none then this probably isn't BASIC code,
// so that's also justification to *RUN // so that's also justification to *RUN
size_t pointer = 0; std::size_t pointer = 0;
uint8_t *data = &files.front().data[0]; uint8_t *data = &files.front().data[0];
size_t data_size = files.front().data.size(); std::size_t data_size = files.front().data.size();
while(1) { while(1) {
if(pointer >= data_size-1 || data[pointer] != 13) { if(pointer >= data_size-1 || data[pointer] != 13) {
is_basic = false; is_basic = false;

View File

@ -38,7 +38,7 @@ static std::unique_ptr<File::Chunk> GetNextChunk(const std::shared_ptr<Storage::
// read out name // read out name
char name[11]; char name[11];
size_t name_ptr = 0; std::size_t name_ptr = 0;
while(!tape->is_at_end() && name_ptr < sizeof(name)) { while(!tape->is_at_end() && name_ptr < sizeof(name)) {
name[name_ptr] = (char)parser.get_next_byte(tape); name[name_ptr] = (char)parser.get_next_byte(tape);
if(!name[name_ptr]) break; if(!name[name_ptr]) break;

View File

@ -15,9 +15,9 @@
#include "../../Storage/Disk/Encodings/MFM/Parser.hpp" #include "../../Storage/Disk/Encodings/MFM/Parser.hpp"
static bool strcmp_insensitive(const char *a, const char *b) { static bool strcmp_insensitive(const char *a, const char *b) {
if(strlen(a) != strlen(b)) return false; if(std::strlen(a) != std::strlen(b)) return false;
while(*a) { while(*a) {
if(tolower(*a) != tolower(*b)) return false; if(std::tolower(*a) != std::tolower(*b)) return false;
a++; a++;
b++; b++;
} }
@ -104,10 +104,10 @@ static void InspectCatalogue(
int basic_files = 0; int basic_files = 0;
int implicit_suffixed_files = 0; int implicit_suffixed_files = 0;
size_t last_basic_file = 0; std::size_t last_basic_file = 0;
size_t last_implicit_suffixed_file = 0; std::size_t last_implicit_suffixed_file = 0;
for(size_t c = 0; c < candidate_files.size(); c++) { for(std::size_t c = 0; c < candidate_files.size(); c++) {
// Files with nothing but spaces in their name can't be loaded by the user, so disregard them. // Files with nothing but spaces in their name can't be loaded by the user, so disregard them.
if(candidate_files[c]->type == " " && candidate_files[c]->name == " ") if(candidate_files[c]->type == " " && candidate_files[c]->name == " ")
continue; continue;
@ -125,7 +125,7 @@ static void InspectCatalogue(
} }
} }
if(basic_files == 1 || implicit_suffixed_files == 1) { if(basic_files == 1 || implicit_suffixed_files == 1) {
size_t selected_file = (basic_files == 1) ? last_basic_file : last_implicit_suffixed_file; std::size_t selected_file = (basic_files == 1) ? last_basic_file : last_implicit_suffixed_file;
target.loadingCommand = RunCommandFor(*candidate_files[selected_file]); target.loadingCommand = RunCommandFor(*candidate_files[selected_file]);
return; return;
} }
@ -133,8 +133,8 @@ static void InspectCatalogue(
// One more guess: if only one remaining candidate file has a different name than the others, // One more guess: if only one remaining candidate file has a different name than the others,
// assume it is intended to stand out. // assume it is intended to stand out.
std::map<std::string, int> name_counts; std::map<std::string, int> name_counts;
std::map<std::string, size_t> indices_by_name; std::map<std::string, std::size_t> indices_by_name;
size_t index = 0; std::size_t index = 0;
for(auto file : candidate_files) { for(auto file : candidate_files) {
name_counts[file->name]++; name_counts[file->name]++;
indices_by_name[file->name] = index; indices_by_name[file->name] = index;
@ -160,7 +160,7 @@ static bool CheckBootSector(const std::shared_ptr<Storage::Disk::Disk> &disk, St
// Check that the first 64 bytes of the sector aren't identical; if they are then probably // Check that the first 64 bytes of the sector aren't identical; if they are then probably
// this disk was formatted and the filler byte never replaced. // this disk was formatted and the filler byte never replaced.
bool matched = true; bool matched = true;
for(size_t c = 1; c < 64; c++) { for(std::size_t c = 1; c < 64; c++) {
if(boot_sector->samples[0][c] != boot_sector->samples[0][0]) { if(boot_sector->samples[0][c] != boot_sector->samples[0][0]) {
matched = false; matched = false;
break; break;

View File

@ -22,9 +22,9 @@ static void DeterminePagingFor2kCartridge(StaticAnalyser::Target &target, const
// a CommaVid start address needs to be outside of its RAM // a CommaVid start address needs to be outside of its RAM
if(entry_address < 0x1800 || break_address < 0x1800) return; if(entry_address < 0x1800 || break_address < 0x1800) return;
std::function<size_t(uint16_t address)> high_location_mapper = [](uint16_t address) { std::function<std::size_t(uint16_t address)> high_location_mapper = [](uint16_t address) {
address &= 0x1fff; address &= 0x1fff;
return static_cast<size_t>(address - 0x1800); return static_cast<std::size_t>(address - 0x1800);
}; };
StaticAnalyser::MOS6502::Disassembly high_location_disassembly = StaticAnalyser::MOS6502::Disassembly high_location_disassembly =
StaticAnalyser::MOS6502::Disassemble(segment.data, high_location_mapper, {entry_address, break_address}); StaticAnalyser::MOS6502::Disassemble(segment.data, high_location_mapper, {entry_address, break_address});
@ -125,9 +125,9 @@ static void DeterminePagingForCartridge(StaticAnalyser::Target &target, const St
entry_address = static_cast<uint16_t>(segment.data[segment.data.size() - 4] | (segment.data[segment.data.size() - 3] << 8)); entry_address = static_cast<uint16_t>(segment.data[segment.data.size() - 4] | (segment.data[segment.data.size() - 3] << 8));
break_address = static_cast<uint16_t>(segment.data[segment.data.size() - 2] | (segment.data[segment.data.size() - 1] << 8)); break_address = static_cast<uint16_t>(segment.data[segment.data.size() - 2] | (segment.data[segment.data.size() - 1] << 8));
std::function<size_t(uint16_t address)> address_mapper = [](uint16_t address) { std::function<std::size_t(uint16_t address)> address_mapper = [](uint16_t address) {
if(!(address & 0x1000)) return static_cast<size_t>(-1); if(!(address & 0x1000)) return static_cast<std::size_t>(-1);
return static_cast<size_t>(address & 0xfff); return static_cast<std::size_t>(address & 0xfff);
}; };
std::vector<uint8_t> final_4k(segment.data.end() - 4096, segment.data.end()); std::vector<uint8_t> final_4k(segment.data.end() - 4096, segment.data.end());
@ -162,7 +162,7 @@ static void DeterminePagingForCartridge(StaticAnalyser::Target &target, const St
if( target.atari.paging_model != StaticAnalyser::Atari2600PagingModel::CBSRamPlus && if( target.atari.paging_model != StaticAnalyser::Atari2600PagingModel::CBSRamPlus &&
target.atari.paging_model != StaticAnalyser::Atari2600PagingModel::MNetwork) { target.atari.paging_model != StaticAnalyser::Atari2600PagingModel::MNetwork) {
bool has_superchip = true; bool has_superchip = true;
for(size_t address = 0; address < 128; address++) { for(std::size_t address = 0; address < 128; address++) {
if(segment.data[address] != segment.data[address+128]) { if(segment.data[address] != segment.data[address+128]) {
has_superchip = false; has_superchip = false;
break; break;

View File

@ -149,7 +149,7 @@ class CommodoreGCRParser: public Storage::Disk::Controller {
} }
checksum = 0; checksum = 0;
for(size_t c = 0; c < 256; c++) { for(std::size_t c = 0; c < 256; c++) {
sector->data[c] = static_cast<uint8_t>(get_next_byte()); sector->data[c] = static_cast<uint8_t>(get_next_byte());
checksum ^= sector->data[c]; checksum ^= sector->data[c];
} }
@ -188,7 +188,7 @@ std::list<File> StaticAnalyser::Commodore::GetFiles(const std::shared_ptr<Storag
} }
// parse directory // parse directory
size_t header_pointer = static_cast<size_t>(-32); std::size_t header_pointer = static_cast<std::size_t>(-32);
while(header_pointer+32+31 < directory.size()) { while(header_pointer+32+31 < directory.size()) {
header_pointer += 32; header_pointer += 32;
@ -207,12 +207,12 @@ std::list<File> StaticAnalyser::Commodore::GetFiles(const std::shared_ptr<Storag
next_sector = directory[header_pointer + 4]; next_sector = directory[header_pointer + 4];
new_file.raw_name.reserve(16); new_file.raw_name.reserve(16);
for(size_t c = 0; c < 16; c++) { for(std::size_t c = 0; c < 16; c++) {
new_file.raw_name.push_back(directory[header_pointer + 5 + c]); new_file.raw_name.push_back(directory[header_pointer + 5 + c]);
} }
new_file.name = Storage::Data::Commodore::petscii_from_bytes(&new_file.raw_name[0], 16, false); new_file.name = Storage::Data::Commodore::petscii_from_bytes(&new_file.raw_name[0], 16, false);
size_t number_of_sectors = static_cast<size_t>(directory[header_pointer + 0x1e]) + (static_cast<size_t>(directory[header_pointer + 0x1f]) << 8); std::size_t number_of_sectors = static_cast<std::size_t>(directory[header_pointer + 0x1e]) + (static_cast<std::size_t>(directory[header_pointer + 0x1f]) << 8);
new_file.data.reserve((number_of_sectors - 1) * 254 + 252); new_file.data.reserve((number_of_sectors - 1) * 254 + 252);
bool is_first_sector = true; bool is_first_sector = true;

View File

@ -98,7 +98,7 @@ void StaticAnalyser::Commodore::AddTargets(const Media &media, std::list<Target>
// General approach: increase memory size conservatively such that the largest file found will fit. // General approach: increase memory size conservatively such that the largest file found will fit.
for(File &file : files) { for(File &file : files) {
size_t file_size = file.data.size(); std::size_t file_size = file.data.size();
// bool is_basic = file.is_basic(); // bool is_basic = file.is_basic();
/*if(is_basic) /*if(is_basic)

View File

@ -16,11 +16,11 @@ struct PartialDisassembly {
std::vector<uint16_t> remaining_entry_points; std::vector<uint16_t> remaining_entry_points;
}; };
static void AddToDisassembly(PartialDisassembly &disassembly, const std::vector<uint8_t> &memory, const std::function<size_t(uint16_t)> &address_mapper, uint16_t entry_point) { static void AddToDisassembly(PartialDisassembly &disassembly, const std::vector<uint8_t> &memory, const std::function<std::size_t(uint16_t)> &address_mapper, uint16_t entry_point) {
disassembly.disassembly.internal_calls.insert(entry_point); disassembly.disassembly.internal_calls.insert(entry_point);
uint16_t address = entry_point; uint16_t address = entry_point;
while(1) { while(1) {
size_t local_address = address_mapper(address); std::size_t local_address = address_mapper(address);
if(local_address >= memory.size()) return; if(local_address >= memory.size()) return;
struct Instruction instruction; struct Instruction instruction;
@ -233,7 +233,7 @@ static void AddToDisassembly(PartialDisassembly &disassembly, const std::vector<
case Instruction::ZeroPage: case Instruction::ZeroPageX: case Instruction::ZeroPageY: case Instruction::ZeroPage: case Instruction::ZeroPageX: case Instruction::ZeroPageY:
case Instruction::IndexedIndirectX: case Instruction::IndirectIndexedY: case Instruction::IndexedIndirectX: case Instruction::IndirectIndexedY:
case Instruction::Relative: { case Instruction::Relative: {
size_t operand_address = address_mapper(address); std::size_t operand_address = address_mapper(address);
if(operand_address >= memory.size()) return; if(operand_address >= memory.size()) return;
address++; address++;
@ -244,8 +244,8 @@ static void AddToDisassembly(PartialDisassembly &disassembly, const std::vector<
// two-byte operands // two-byte operands
case Instruction::Absolute: case Instruction::AbsoluteX: case Instruction::AbsoluteY: case Instruction::Absolute: case Instruction::AbsoluteX: case Instruction::AbsoluteY:
case Instruction::Indirect: { case Instruction::Indirect: {
size_t low_operand_address = address_mapper(address); std::size_t low_operand_address = address_mapper(address);
size_t high_operand_address = address_mapper(address + 1); std::size_t high_operand_address = address_mapper(address + 1);
if(low_operand_address >= memory.size() || high_operand_address >= memory.size()) return; if(low_operand_address >= memory.size() || high_operand_address >= memory.size()) return;
address += 2; address += 2;
@ -259,7 +259,7 @@ static void AddToDisassembly(PartialDisassembly &disassembly, const std::vector<
// TODO: something wider-ranging than this // TODO: something wider-ranging than this
if(instruction.addressing_mode == Instruction::Absolute || instruction.addressing_mode == Instruction::ZeroPage) { if(instruction.addressing_mode == Instruction::Absolute || instruction.addressing_mode == Instruction::ZeroPage) {
size_t mapped_address = address_mapper(instruction.operand); std::size_t mapped_address = address_mapper(instruction.operand);
bool is_external = mapped_address >= memory.size(); bool is_external = mapped_address >= memory.size();
switch(instruction.operation) { switch(instruction.operation) {
@ -307,7 +307,7 @@ static void AddToDisassembly(PartialDisassembly &disassembly, const std::vector<
} }
} }
Disassembly StaticAnalyser::MOS6502::Disassemble(const std::vector<uint8_t> &memory, const std::function<size_t(uint16_t)> &address_mapper, std::vector<uint16_t> entry_points) { Disassembly StaticAnalyser::MOS6502::Disassemble(const std::vector<uint8_t> &memory, const std::function<std::size_t(uint16_t)> &address_mapper, std::vector<uint16_t> entry_points) {
PartialDisassembly partialDisassembly; PartialDisassembly partialDisassembly;
partialDisassembly.remaining_entry_points = entry_points; partialDisassembly.remaining_entry_points = entry_points;
@ -320,7 +320,7 @@ Disassembly StaticAnalyser::MOS6502::Disassemble(const std::vector<uint8_t> &mem
if(partialDisassembly.disassembly.instructions_by_address.find(next_entry_point) != partialDisassembly.disassembly.instructions_by_address.end()) continue; if(partialDisassembly.disassembly.instructions_by_address.find(next_entry_point) != partialDisassembly.disassembly.instructions_by_address.end()) continue;
// if it's outgoing, log it as such and forget about it; otherwise disassemble // if it's outgoing, log it as such and forget about it; otherwise disassemble
size_t mapped_entry_point = address_mapper(next_entry_point); std::size_t mapped_entry_point = address_mapper(next_entry_point);
if(mapped_entry_point >= memory.size()) if(mapped_entry_point >= memory.size())
partialDisassembly.disassembly.outward_calls.insert(next_entry_point); partialDisassembly.disassembly.outward_calls.insert(next_entry_point);
else else
@ -330,8 +330,8 @@ Disassembly StaticAnalyser::MOS6502::Disassemble(const std::vector<uint8_t> &mem
return std::move(partialDisassembly.disassembly); return std::move(partialDisassembly.disassembly);
} }
std::function<size_t(uint16_t)> StaticAnalyser::MOS6502::OffsetMapper(uint16_t start_address) { std::function<std::size_t(uint16_t)> StaticAnalyser::MOS6502::OffsetMapper(uint16_t start_address) {
return [start_address](uint16_t argument) { return [start_address](uint16_t argument) {
return static_cast<size_t>(argument - start_address); return static_cast<std::size_t>(argument - start_address);
}; };
} }

View File

@ -70,8 +70,8 @@ struct Disassembly {
std::set<uint16_t> internal_stores, internal_loads, internal_modifies; std::set<uint16_t> internal_stores, internal_loads, internal_modifies;
}; };
Disassembly Disassemble(const std::vector<uint8_t> &memory, const std::function<size_t(uint16_t)> &address_mapper, std::vector<uint16_t> entry_points); Disassembly Disassemble(const std::vector<uint8_t> &memory, const std::function<std::size_t(uint16_t)> &address_mapper, std::vector<uint16_t> entry_points);
std::function<size_t(uint16_t)> OffsetMapper(uint16_t start_address); std::function<std::size_t(uint16_t)> OffsetMapper(uint16_t start_address);
} }
} }

View File

@ -69,9 +69,9 @@ std::list<File> StaticAnalyser::Oric::GetFiles(const std::shared_ptr<Storage::Ta
new_file.name = file_name; new_file.name = file_name;
// read body // read body
size_t body_length = new_file.ending_address - new_file.starting_address + 1; std::size_t body_length = new_file.ending_address - new_file.starting_address + 1;
new_file.data.reserve(body_length); new_file.data.reserve(body_length);
for(size_t c = 0; c < body_length; c++) { for(std::size_t c = 0; c < body_length; c++) {
new_file.data.push_back(static_cast<uint8_t>(parser.get_next_byte(tape, is_fast))); new_file.data.push_back(static_cast<uint8_t>(parser.get_next_byte(tape, is_fast)));
} }

View File

@ -73,7 +73,7 @@ static Media GetMediaAndPlatforms(const char *file_name, TargetPlatform::IntType
} catch(...) {} } catch(...) {}
#define Format(extension, list, class, platforms) \ #define Format(extension, list, class, platforms) \
if(!strcmp(lowercase_extension, extension)) { \ if(!std::strcmp(lowercase_extension, extension)) { \
TryInsert(list, class, platforms) \ TryInsert(list, class, platforms) \
} }
@ -96,7 +96,7 @@ static Media GetMediaAndPlatforms(const char *file_name, TargetPlatform::IntType
Format("p81", result.tapes, Tape::ZX80O81P, TargetPlatform::ZX8081) // P81 Format("p81", result.tapes, Tape::ZX80O81P, TargetPlatform::ZX8081) // P81
// PRG // PRG
if(!strcmp(lowercase_extension, "prg")) { if(!std::strcmp(lowercase_extension, "prg")) {
// try instantiating as a ROM; failing that accept as a tape // try instantiating as a ROM; failing that accept as a tape
try { try {
Insert(result.cartridges, Cartridge::PRG, TargetPlatform::Commodore) Insert(result.cartridges, Cartridge::PRG, TargetPlatform::Commodore)

View File

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

View File

@ -28,11 +28,11 @@ PRG::PRG(const char *file_name) {
int loading_address = fgetc(file); int loading_address = fgetc(file);
loading_address |= fgetc(file) << 8; loading_address |= fgetc(file) << 8;
size_t data_length = static_cast<size_t>(file_stats.st_size) - 2; std::size_t data_length = static_cast<std::size_t>(file_stats.st_size) - 2;
size_t padded_data_length = 1; std::size_t padded_data_length = 1;
while(padded_data_length < data_length) padded_data_length <<= 1; while(padded_data_length < data_length) padded_data_length <<= 1;
std::vector<uint8_t> contents(padded_data_length); std::vector<uint8_t> contents(padded_data_length);
fread(&contents[0], 1, static_cast<size_t>(data_length), file); fread(&contents[0], 1, static_cast<std::size_t>(data_length), file);
fclose(file); fclose(file);
// accept only files intended to load at 0xa000 // accept only files intended to load at 0xa000

View File

@ -10,7 +10,7 @@
using namespace Storage::Data::ZX8081; using namespace Storage::Data::ZX8081;
static uint16_t short_at(size_t address, const std::vector<uint8_t> &data) { static uint16_t short_at(std::size_t address, const std::vector<uint8_t> &data) {
return static_cast<uint16_t>(data[address] | (data[address + 1] << 8)); return static_cast<uint16_t>(data[address] | (data[address + 1] << 8));
} }
@ -49,9 +49,9 @@ static std::shared_ptr<File> ZX81FileFromData(const std::vector<uint8_t> &data)
// Does this look like a ZX81 file? // Does this look like a ZX81 file?
// Look for a file name. // Look for a file name.
size_t data_pointer = 0; std::size_t data_pointer = 0;
std::vector<uint8_t> name_data; std::vector<uint8_t> name_data;
size_t c = 11; std::size_t c = 11;
while(c < data.size() && c--) { while(c < data.size() && c--) {
name_data.push_back(data[data_pointer] & 0x3f); name_data.push_back(data[data_pointer] & 0x3f);
if(data[data_pointer] & 0x80) break; if(data[data_pointer] & 0x80) break;

View File

@ -12,7 +12,7 @@
using namespace Storage; using namespace Storage;
DigitalPhaseLockedLoop::DigitalPhaseLockedLoop(int clocks_per_bit, size_t length_of_history) : DigitalPhaseLockedLoop::DigitalPhaseLockedLoop(int clocks_per_bit, std::size_t length_of_history) :
offset_history_(length_of_history, 0), offset_history_(length_of_history, 0),
window_length_(clocks_per_bit), window_length_(clocks_per_bit),
clocks_per_bit_(clocks_per_bit) {} clocks_per_bit_(clocks_per_bit) {}

View File

@ -24,7 +24,7 @@ class DigitalPhaseLockedLoop {
@param clocks_per_bit The expected number of cycles between each bit of input. @param clocks_per_bit The expected number of cycles between each bit of input.
@param length_of_history The number of historic pulses to consider in locking to phase. @param length_of_history The number of historic pulses to consider in locking to phase.
*/ */
DigitalPhaseLockedLoop(int clocks_per_bit, size_t length_of_history); DigitalPhaseLockedLoop(int clocks_per_bit, std::size_t length_of_history);
/*! /*!
Runs the loop, impliedly posting no pulses during that period. Runs the loop, impliedly posting no pulses during that period.
@ -55,7 +55,7 @@ class DigitalPhaseLockedLoop {
void post_phase_offset(int phase, int offset); void post_phase_offset(int phase, int offset);
std::vector<int> offset_history_; std::vector<int> offset_history_;
size_t offset_history_pointer_ = 0; std::size_t offset_history_pointer_ = 0;
int offset_ = 0; int offset_ = 0;
int phase_ = 0; int phase_ = 0;

View File

@ -39,20 +39,20 @@ CPCDSK::CPCDSK(const char *file_name) :
long size_of_a_track = 0; long size_of_a_track = 0;
// Used only for extended disks. // Used only for extended disks.
std::vector<size_t> track_sizes; std::vector<std::size_t> track_sizes;
if(is_extended_) { if(is_extended_) {
// Skip two unused bytes and grab the track size table. // Skip two unused bytes and grab the track size table.
file.seek(2, SEEK_CUR); file.seek(2, SEEK_CUR);
for(int c = 0; c < head_position_count_ * head_count_; c++) { for(int c = 0; c < head_position_count_ * head_count_; c++) {
track_sizes.push_back(static_cast<size_t>(file.get8()) << 8); track_sizes.push_back(static_cast<std::size_t>(file.get8()) << 8);
} }
} else { } else {
size_of_a_track = file.get16le(); size_of_a_track = file.get16le();
} }
long file_offset = 0x100; long file_offset = 0x100;
for(size_t c = 0; c < static_cast<size_t>(head_position_count_ * head_count_); c++) { for(std::size_t c = 0; c < static_cast<std::size_t>(head_position_count_ * head_count_); c++) {
if(!is_extended_ || (track_sizes[c] > 0)) { if(!is_extended_ || (track_sizes[c] > 0)) {
// Skip the introductory text, 'Track-Info\r\n' and its unused bytes. // Skip the introductory text, 'Track-Info\r\n' and its unused bytes.
file.seek(file_offset + 16, SEEK_SET); file.seek(file_offset + 16, SEEK_SET);
@ -87,7 +87,7 @@ CPCDSK::CPCDSK(const char *file_name) :
// Sector size, number of sectors, gap 3 length and the filler byte are then common // Sector size, number of sectors, gap 3 length and the filler byte are then common
// between both variants of DSK. // between both variants of DSK.
track->sector_length = file.get8(); track->sector_length = file.get8();
size_t number_of_sectors = file.get8(); std::size_t number_of_sectors = file.get8();
track->gap3_length = file.get8(); track->gap3_length = file.get8();
track->filler_byte = file.get8(); track->filler_byte = file.get8();
@ -126,9 +126,9 @@ CPCDSK::CPCDSK(const char *file_name) :
} }
// Figuring out the actual data size is a little more work... // Figuring out the actual data size is a little more work...
size_t data_size = static_cast<size_t>(128 << sector.size); std::size_t data_size = static_cast<std::size_t>(128 << sector.size);
size_t stored_data_size = data_size; std::size_t stored_data_size = data_size;
size_t number_of_samplings = 1; std::size_t number_of_samplings = 1;
if(is_extended_) { if(is_extended_) {
// In an extended DSK, oblige two Simon Owen extensions: // In an extended DSK, oblige two Simon Owen extensions:
@ -140,7 +140,7 @@ CPCDSK::CPCDSK(const char *file_name) :
// sector was weak or fuzzy and that multiple samplings are provided. If the greater size // sector was weak or fuzzy and that multiple samplings are provided. If the greater size
// is not an exact multiple then my reading of the documentation is that this is an invalid // is not an exact multiple then my reading of the documentation is that this is an invalid
// disk image. // disk image.
size_t declared_data_size = file.get16le(); std::size_t declared_data_size = file.get16le();
if(declared_data_size != stored_data_size) { if(declared_data_size != stored_data_size) {
if(declared_data_size > data_size) { if(declared_data_size > data_size) {
number_of_samplings = declared_data_size / data_size; number_of_samplings = declared_data_size / data_size;
@ -194,13 +194,13 @@ int CPCDSK::get_head_count() {
return head_count_; return head_count_;
} }
size_t CPCDSK::index_for_track(::Storage::Disk::Track::Address address) { std::size_t CPCDSK::index_for_track(::Storage::Disk::Track::Address address) {
return static_cast<size_t>((address.position * head_count_) + address.head); return static_cast<std::size_t>((address.position * head_count_) + address.head);
} }
std::shared_ptr<Track> CPCDSK::get_track_at_position(::Storage::Disk::Track::Address address) { std::shared_ptr<Track> CPCDSK::get_track_at_position(::Storage::Disk::Track::Address address) {
// Given that thesea are interleaved images, determine which track, chronologically, is being requested. // Given that thesea are interleaved images, determine which track, chronologically, is being requested.
size_t chronological_track = index_for_track(address); std::size_t chronological_track = index_for_track(address);
// Return a nullptr if out of range or not provided. // Return a nullptr if out of range or not provided.
if(chronological_track >= tracks_.size()) return nullptr; if(chronological_track >= tracks_.size()) return nullptr;
@ -222,13 +222,13 @@ void CPCDSK::set_tracks(const std::map<::Storage::Disk::Track::Address, std::sha
for(auto &pair: tracks) { for(auto &pair: tracks) {
// Assume MFM for now; with extensions DSK can contain FM tracks. // Assume MFM for now; with extensions DSK can contain FM tracks.
const bool is_double_density = true; const bool is_double_density = true;
std::map<size_t, Storage::Encodings::MFM::Sector> sectors = std::map<std::size_t, Storage::Encodings::MFM::Sector> sectors =
Storage::Encodings::MFM::sectors_from_segment( Storage::Encodings::MFM::sectors_from_segment(
Storage::Disk::track_serialisation(*pair.second, is_double_density ? Storage::Encodings::MFM::MFMBitLength : Storage::Encodings::MFM::FMBitLength), Storage::Disk::track_serialisation(*pair.second, is_double_density ? Storage::Encodings::MFM::MFMBitLength : Storage::Encodings::MFM::FMBitLength),
is_double_density); is_double_density);
// Find slot for track, making it if neccessary. // Find slot for track, making it if neccessary.
size_t chronological_track = index_for_track(pair.first); std::size_t chronological_track = index_for_track(pair.first);
if(chronological_track >= tracks_.size()) { if(chronological_track >= tracks_.size()) {
tracks_.resize(chronological_track+1); tracks_.resize(chronological_track+1);
head_position_count_ = pair.first.position; head_position_count_ = pair.first.position;
@ -280,7 +280,7 @@ void CPCDSK::set_tracks(const std::map<::Storage::Disk::Track::Address, std::sha
output.putn(2, 0); output.putn(2, 0);
// Output size table. // Output size table.
for(size_t index = 0; index < static_cast<size_t>(head_position_count_ * head_count_); ++index) { for(std::size_t index = 0; index < static_cast<std::size_t>(head_position_count_ * head_count_); ++index) {
if(index >= tracks_.size()) { if(index >= tracks_.size()) {
output.put8(0); output.put8(0);
continue; continue;
@ -292,7 +292,7 @@ void CPCDSK::set_tracks(const std::map<::Storage::Disk::Track::Address, std::sha
} }
// Calculate size of track. // Calculate size of track.
size_t track_size = 256; std::size_t track_size = 256;
for(auto &sector: track->sectors) { for(auto &sector: track->sectors) {
for(auto &sample: sector.samples) { for(auto &sample: sector.samples) {
track_size += sample.size(); track_size += sample.size();
@ -305,10 +305,10 @@ void CPCDSK::set_tracks(const std::map<::Storage::Disk::Track::Address, std::sha
} }
// Advance to offset 256. // Advance to offset 256.
output.putn(static_cast<size_t>(256 - output.tell()), 0); output.putn(static_cast<std::size_t>(256 - output.tell()), 0);
// Output each track. // Output each track.
for(size_t index = 0; index < static_cast<size_t>(head_position_count_ * head_count_); ++index) { for(std::size_t index = 0; index < static_cast<std::size_t>(head_position_count_ * head_count_); ++index) {
if(index >= tracks_.size()) continue; if(index >= tracks_.size()) continue;
Track *track = tracks_[index].get(); Track *track = tracks_[index].get();
if(!track) continue; if(!track) continue;
@ -357,7 +357,7 @@ void CPCDSK::set_tracks(const std::map<::Storage::Disk::Track::Address, std::sha
output.put8(sector.fdc_status1); output.put8(sector.fdc_status1);
output.put8(sector.fdc_status2); output.put8(sector.fdc_status2);
size_t data_size = 0; std::size_t data_size = 0;
for(auto &sample: sector.samples) { for(auto &sample: sector.samples) {
data_size += sample.size(); data_size += sample.size();
} }
@ -366,7 +366,7 @@ void CPCDSK::set_tracks(const std::map<::Storage::Disk::Track::Address, std::sha
// Move to next 256-byte boundary. // Move to next 256-byte boundary.
long distance = (256 - output.tell()&255)&255; long distance = (256 - output.tell()&255)&255;
output.putn(static_cast<size_t>(distance), 0); output.putn(static_cast<std::size_t>(distance), 0);
// Output sector contents. // Output sector contents.
for(auto &sector: track->sectors) { for(auto &sector: track->sectors) {
@ -377,7 +377,7 @@ void CPCDSK::set_tracks(const std::map<::Storage::Disk::Track::Address, std::sha
// Move to next 256-byte boundary. // Move to next 256-byte boundary.
distance = (256 - output.tell()&255)&255; distance = (256 - output.tell()&255)&255;
output.putn(static_cast<size_t>(distance), 0); output.putn(static_cast<std::size_t>(distance), 0);
} }
} }

View File

@ -66,7 +66,7 @@ class CPCDSK: public DiskImage {
}; };
std::string file_name_; std::string file_name_;
std::vector<std::unique_ptr<Track>> tracks_; std::vector<std::unique_ptr<Track>> tracks_;
size_t index_for_track(::Storage::Disk::Track::Address address); std::size_t index_for_track(::Storage::Disk::Track::Address address);
int head_count_; int head_count_;
int head_position_count_; int head_position_count_;

View File

@ -85,7 +85,7 @@ std::shared_ptr<Track> D64::get_track_at_position(Track::Address address) {
// = 349 GCR bytes per sector // = 349 GCR bytes per sector
PCMSegment track; PCMSegment track;
size_t track_bytes = 349 * static_cast<size_t>(sectors_by_zone[zone]); std::size_t track_bytes = 349 * static_cast<std::size_t>(sectors_by_zone[zone]);
track.number_of_bits = static_cast<unsigned int>(track_bytes) * 8; track.number_of_bits = static_cast<unsigned int>(track_bytes) * 8;
track.data.resize(track_bytes); track.data.resize(track_bytes);
uint8_t *data = &track.data[0]; uint8_t *data = &track.data[0];

View File

@ -96,7 +96,7 @@ std::shared_ptr<Track> G64::get_track_at_position(Track::Address address) {
segment.number_of_bits = number_of_bytes * 8; segment.number_of_bits = number_of_bytes * 8;
segment.length_of_a_bit = Encodings::CommodoreGCR::length_of_a_bit_in_time_zone(current_speed); segment.length_of_a_bit = Encodings::CommodoreGCR::length_of_a_bit_in_time_zone(current_speed);
segment.data.resize(number_of_bytes); segment.data.resize(number_of_bytes);
memcpy(&segment.data[0], &track_contents[start_byte_in_current_speed], number_of_bytes); std::memcpy(&segment.data[0], &track_contents[start_byte_in_current_speed], number_of_bytes);
segments.push_back(std::move(segment)); segments.push_back(std::move(segment));
current_speed = byte_speed; current_speed = byte_speed;

View File

@ -58,7 +58,7 @@ std::shared_ptr<Track> OricMFMDSK::get_track_at_position(Track::Address address)
// The file format omits clock bits. So it's not a genuine MFM capture. // The file format omits clock bits. So it's not a genuine MFM capture.
// A consumer must contextually guess when an FB, FC, etc is meant to be a control mark. // A consumer must contextually guess when an FB, FC, etc is meant to be a control mark.
size_t track_offset = 0; std::size_t track_offset = 0;
uint8_t last_header[6] = {0, 0, 0, 0, 0, 0}; uint8_t last_header[6] = {0, 0, 0, 0, 0, 0};
std::unique_ptr<Encodings::MFM::Encoder> encoder = Encodings::MFM::GetMFMEncoder(segment.data); std::unique_ptr<Encodings::MFM::Encoder> encoder = Encodings::MFM::GetMFMEncoder(segment.data);
bool did_sync = false; bool did_sync = false;
@ -158,7 +158,7 @@ void OricMFMDSK::set_tracks(const std::map<Track::Address, std::shared_ptr<Track
std::lock_guard<std::mutex> lock_guard(file_.get_file_access_mutex()); std::lock_guard<std::mutex> lock_guard(file_.get_file_access_mutex());
file_.seek(file_offset, SEEK_SET); file_.seek(file_offset, SEEK_SET);
size_t track_size = std::min(static_cast<size_t>(6400), parsed_track.size()); std::size_t track_size = std::min(static_cast<std::size_t>(6400), parsed_track.size());
file_.write(parsed_track.data(), track_size); file_.write(parsed_track.data(), track_size);
} }
} }

View File

@ -28,7 +28,7 @@ SSD::SSD(const char *file_name) : MFMSectorDump(file_name) {
if(file_.stats().st_size > 800*256) throw ErrorNotSSD; if(file_.stats().st_size > 800*256) throw ErrorNotSSD;
// this has two heads if the suffix is .dsd, one if it's .ssd // this has two heads if the suffix is .dsd, one if it's .ssd
head_count_ = (tolower(file_name[strlen(file_name) - 3]) == 'd') ? 2 : 1; head_count_ = (tolower(file_name[std::strlen(file_name) - 3]) == 'd') ? 2 : 1;
track_count_ = static_cast<int>(file_.stats().st_size / (256 * 10)); track_count_ = static_cast<int>(file_.stats().st_size / (256 * 10));
if(track_count_ < 40) track_count_ = 40; if(track_count_ < 40) track_count_ = 40;
else if(track_count_ < 80) track_count_ = 80; else if(track_count_ < 80) track_count_ = 80;

View File

@ -46,17 +46,17 @@ std::shared_ptr<Track> Storage::Disk::track_for_sectors(uint8_t *const source, u
} }
void Storage::Disk::decode_sectors(Track &track, uint8_t *const destination, uint8_t first_sector, uint8_t last_sector, uint8_t sector_size, bool is_double_density) { void Storage::Disk::decode_sectors(Track &track, uint8_t *const destination, uint8_t first_sector, uint8_t last_sector, uint8_t sector_size, bool is_double_density) {
std::map<size_t, Storage::Encodings::MFM::Sector> sectors = std::map<std::size_t, Storage::Encodings::MFM::Sector> sectors =
Storage::Encodings::MFM::sectors_from_segment( Storage::Encodings::MFM::sectors_from_segment(
Storage::Disk::track_serialisation(track, is_double_density ? Storage::Encodings::MFM::MFMBitLength : Storage::Encodings::MFM::FMBitLength), Storage::Disk::track_serialisation(track, is_double_density ? Storage::Encodings::MFM::MFMBitLength : Storage::Encodings::MFM::FMBitLength),
is_double_density); is_double_density);
size_t byte_size = static_cast<size_t>(128 << sector_size); std::size_t byte_size = static_cast<std::size_t>(128 << sector_size);
for(auto &pair : sectors) { for(auto &pair : sectors) {
if(pair.second.address.sector > last_sector) continue; if(pair.second.address.sector > last_sector) continue;
if(pair.second.address.sector < first_sector) continue; if(pair.second.address.sector < first_sector) continue;
if(pair.second.size != sector_size) continue; if(pair.second.size != sector_size) continue;
if(pair.second.samples.empty()) continue; if(pair.second.samples.empty()) continue;
memcpy(&destination[pair.second.address.sector * byte_size], pair.second.samples[0].data(), std::min(pair.second.samples[0].size(), byte_size)); std::memcpy(&destination[pair.second.address.sector * byte_size], pair.second.samples[0].data(), std::min(pair.second.samples[0].size(), byte_size));
} }
} }

View File

@ -120,12 +120,12 @@ class FMEncoder: public Encoder {
template<class T> std::shared_ptr<Storage::Disk::Track> template<class T> std::shared_ptr<Storage::Disk::Track>
GetTrackWithSectors( GetTrackWithSectors(
const std::vector<const Sector *> &sectors, const std::vector<const Sector *> &sectors,
size_t post_index_address_mark_bytes, uint8_t post_index_address_mark_value, std::size_t post_index_address_mark_bytes, uint8_t post_index_address_mark_value,
size_t pre_address_mark_bytes, std::size_t pre_address_mark_bytes,
size_t post_address_mark_bytes, uint8_t post_address_mark_value, std::size_t post_address_mark_bytes, uint8_t post_address_mark_value,
size_t pre_data_mark_bytes, std::size_t pre_data_mark_bytes,
size_t post_data_bytes, uint8_t post_data_value, std::size_t post_data_bytes, uint8_t post_data_value,
size_t expected_track_bytes) { std::size_t expected_track_bytes) {
Storage::Disk::PCMSegment segment; Storage::Disk::PCMSegment segment;
segment.data.reserve(expected_track_bytes); segment.data.reserve(expected_track_bytes);
T shifter(segment.data); T shifter(segment.data);
@ -134,12 +134,12 @@ template<class T> std::shared_ptr<Storage::Disk::Track>
shifter.add_index_address_mark(); shifter.add_index_address_mark();
// add the post-index mark // add the post-index mark
for(size_t c = 0; c < post_index_address_mark_bytes; c++) shifter.add_byte(post_index_address_mark_value); for(std::size_t c = 0; c < post_index_address_mark_bytes; c++) shifter.add_byte(post_index_address_mark_value);
// add sectors // add sectors
for(const Sector *sector : sectors) { for(const Sector *sector : sectors) {
// gap // gap
for(size_t c = 0; c < pre_address_mark_bytes; c++) shifter.add_byte(0x00); for(std::size_t c = 0; c < pre_address_mark_bytes; c++) shifter.add_byte(0x00);
// sector header // sector header
shifter.add_ID_address_mark(); shifter.add_ID_address_mark();
@ -150,8 +150,8 @@ template<class T> std::shared_ptr<Storage::Disk::Track>
shifter.add_crc(sector->has_header_crc_error); shifter.add_crc(sector->has_header_crc_error);
// gap // gap
for(size_t c = 0; c < post_address_mark_bytes; c++) shifter.add_byte(post_address_mark_value); for(std::size_t c = 0; c < post_address_mark_bytes; c++) shifter.add_byte(post_address_mark_value);
for(size_t c = 0; c < pre_data_mark_bytes; c++) shifter.add_byte(0x00); for(std::size_t c = 0; c < pre_data_mark_bytes; c++) shifter.add_byte(0x00);
// data, if attached // data, if attached
// TODO: allow for weak/fuzzy data. // TODO: allow for weak/fuzzy data.
@ -161,8 +161,8 @@ template<class T> std::shared_ptr<Storage::Disk::Track>
else else
shifter.add_data_address_mark(); shifter.add_data_address_mark();
size_t c = 0; std::size_t c = 0;
size_t declared_length = static_cast<size_t>(128 << sector->size); std::size_t declared_length = static_cast<std::size_t>(128 << sector->size);
for(c = 0; c < sector->samples[0].size() && c < declared_length; c++) { for(c = 0; c < sector->samples[0].size() && c < declared_length; c++) {
shifter.add_byte(sector->samples[0][c]); shifter.add_byte(sector->samples[0][c]);
} }
@ -173,13 +173,13 @@ template<class T> std::shared_ptr<Storage::Disk::Track>
} }
// gap // gap
for(size_t c = 0; c < post_data_bytes; c++) shifter.add_byte(post_data_value); for(std::size_t c = 0; c < post_data_bytes; c++) shifter.add_byte(post_data_value);
} }
while(segment.data.size() < expected_track_bytes) shifter.add_byte(0x00); while(segment.data.size() < expected_track_bytes) shifter.add_byte(0x00);
// Allow the amount of data written to be up to 10% more than the expected size. Which is generous. // Allow the amount of data written to be up to 10% more than the expected size. Which is generous.
size_t max_size = expected_track_bytes + (expected_track_bytes / 10); std::size_t max_size = expected_track_bytes + (expected_track_bytes / 10);
if(segment.data.size() > max_size) segment.data.resize(max_size); if(segment.data.size() > max_size) segment.data.resize(max_size);
segment.number_of_bits = static_cast<unsigned int>(segment.data.size() * 8); segment.number_of_bits = static_cast<unsigned int>(segment.data.size() * 8);
@ -201,7 +201,7 @@ void Encoder::add_crc(bool incorrectly) {
add_byte((crc_value & 0xff) ^ (incorrectly ? 1 : 0)); add_byte((crc_value & 0xff) ^ (incorrectly ? 1 : 0));
} }
const size_t Storage::Encodings::MFM::DefaultSectorGapLength = std::numeric_limits<size_t>::max(); const std::size_t Storage::Encodings::MFM::DefaultSectorGapLength = std::numeric_limits<std::size_t>::max();
static std::vector<const Sector *> sector_pointers(const std::vector<Sector> &sectors) { static std::vector<const Sector *> sector_pointers(const std::vector<Sector> &sectors) {
std::vector<const Sector *> pointers; std::vector<const Sector *> pointers;
@ -211,7 +211,7 @@ static std::vector<const Sector *> sector_pointers(const std::vector<Sector> &se
return pointers; return pointers;
} }
std::shared_ptr<Storage::Disk::Track> Storage::Encodings::MFM::GetFMTrackWithSectors(const std::vector<Sector> &sectors, size_t sector_gap_length, uint8_t sector_gap_filler_byte) { std::shared_ptr<Storage::Disk::Track> Storage::Encodings::MFM::GetFMTrackWithSectors(const std::vector<Sector> &sectors, std::size_t sector_gap_length, uint8_t sector_gap_filler_byte) {
return GetTrackWithSectors<FMEncoder>( return GetTrackWithSectors<FMEncoder>(
sector_pointers(sectors), sector_pointers(sectors),
26, 0xff, 26, 0xff,
@ -222,7 +222,7 @@ std::shared_ptr<Storage::Disk::Track> Storage::Encodings::MFM::GetFMTrackWithSec
6250); // i.e. 250kbps (including clocks) * 60 = 15000kpm, at 300 rpm => 50 kbits/rotation => 6250 bytes/rotation 6250); // i.e. 250kbps (including clocks) * 60 = 15000kpm, at 300 rpm => 50 kbits/rotation => 6250 bytes/rotation
} }
std::shared_ptr<Storage::Disk::Track> Storage::Encodings::MFM::GetFMTrackWithSectors(const std::vector<const Sector *> &sectors, size_t sector_gap_length, uint8_t sector_gap_filler_byte) { std::shared_ptr<Storage::Disk::Track> Storage::Encodings::MFM::GetFMTrackWithSectors(const std::vector<const Sector *> &sectors, std::size_t sector_gap_length, uint8_t sector_gap_filler_byte) {
return GetTrackWithSectors<FMEncoder>( return GetTrackWithSectors<FMEncoder>(
sectors, sectors,
26, 0xff, 26, 0xff,
@ -233,7 +233,7 @@ std::shared_ptr<Storage::Disk::Track> Storage::Encodings::MFM::GetFMTrackWithSec
6250); // i.e. 250kbps (including clocks) * 60 = 15000kpm, at 300 rpm => 50 kbits/rotation => 6250 bytes/rotation 6250); // i.e. 250kbps (including clocks) * 60 = 15000kpm, at 300 rpm => 50 kbits/rotation => 6250 bytes/rotation
} }
std::shared_ptr<Storage::Disk::Track> Storage::Encodings::MFM::GetMFMTrackWithSectors(const std::vector<Sector> &sectors, size_t sector_gap_length, uint8_t sector_gap_filler_byte) { std::shared_ptr<Storage::Disk::Track> Storage::Encodings::MFM::GetMFMTrackWithSectors(const std::vector<Sector> &sectors, std::size_t sector_gap_length, uint8_t sector_gap_filler_byte) {
return GetTrackWithSectors<MFMEncoder>( return GetTrackWithSectors<MFMEncoder>(
sector_pointers(sectors), sector_pointers(sectors),
50, 0x4e, 50, 0x4e,
@ -244,7 +244,7 @@ std::shared_ptr<Storage::Disk::Track> Storage::Encodings::MFM::GetMFMTrackWithSe
12500); // unintelligently: double the single-density bytes/rotation (or: 500kbps @ 300 rpm) 12500); // unintelligently: double the single-density bytes/rotation (or: 500kbps @ 300 rpm)
} }
std::shared_ptr<Storage::Disk::Track> Storage::Encodings::MFM::GetMFMTrackWithSectors(const std::vector<const Sector *> &sectors, size_t sector_gap_length, uint8_t sector_gap_filler_byte) { std::shared_ptr<Storage::Disk::Track> Storage::Encodings::MFM::GetMFMTrackWithSectors(const std::vector<const Sector *> &sectors, std::size_t sector_gap_length, uint8_t sector_gap_filler_byte) {
return GetTrackWithSectors<MFMEncoder>( return GetTrackWithSectors<MFMEncoder>(
sectors, sectors,
50, 0x4e, 50, 0x4e,

View File

@ -21,7 +21,7 @@ namespace Storage {
namespace Encodings { namespace Encodings {
namespace MFM { namespace MFM {
extern const size_t DefaultSectorGapLength; extern const std::size_t DefaultSectorGapLength;
/*! /*!
Converts a vector of sectors into a properly-encoded MFM track. Converts a vector of sectors into a properly-encoded MFM track.
@ -29,8 +29,8 @@ extern const size_t DefaultSectorGapLength;
@param sector_gap_length If specified, sets the distance in whole bytes between each ID and its data. @param sector_gap_length If specified, sets the distance in whole bytes between each ID and its data.
@param sector_gap_filler_byte If specified, sets the value (unencoded) that is used to populate the gap between each ID and its data. @param sector_gap_filler_byte If specified, sets the value (unencoded) that is used to populate the gap between each ID and its data.
*/ */
std::shared_ptr<Storage::Disk::Track> GetMFMTrackWithSectors(const std::vector<Sector> &sectors, size_t sector_gap_length = DefaultSectorGapLength, uint8_t sector_gap_filler_byte = 0x4e); std::shared_ptr<Storage::Disk::Track> GetMFMTrackWithSectors(const std::vector<Sector> &sectors, std::size_t sector_gap_length = DefaultSectorGapLength, uint8_t sector_gap_filler_byte = 0x4e);
std::shared_ptr<Storage::Disk::Track> GetMFMTrackWithSectors(const std::vector<const Sector *> &sectors, size_t sector_gap_length = DefaultSectorGapLength, uint8_t sector_gap_filler_byte = 0x4e); std::shared_ptr<Storage::Disk::Track> GetMFMTrackWithSectors(const std::vector<const Sector *> &sectors, std::size_t sector_gap_length = DefaultSectorGapLength, uint8_t sector_gap_filler_byte = 0x4e);
/*! /*!
Converts a vector of sectors into a properly-encoded FM track. Converts a vector of sectors into a properly-encoded FM track.
@ -39,8 +39,8 @@ std::shared_ptr<Storage::Disk::Track> GetMFMTrackWithSectors(const std::vector<c
@param sector_gap_length If specified, sets the distance in whole bytes between each ID and its data. @param sector_gap_length If specified, sets the distance in whole bytes between each ID and its data.
@param sector_gap_filler_byte If specified, sets the value (unencoded) that is used to populate the gap between each ID and its data. @param sector_gap_filler_byte If specified, sets the value (unencoded) that is used to populate the gap between each ID and its data.
*/ */
std::shared_ptr<Storage::Disk::Track> GetFMTrackWithSectors(const std::vector<Sector> &sectors, size_t sector_gap_length = DefaultSectorGapLength, uint8_t sector_gap_filler_byte = 0x4e); std::shared_ptr<Storage::Disk::Track> GetFMTrackWithSectors(const std::vector<Sector> &sectors, std::size_t sector_gap_length = DefaultSectorGapLength, uint8_t sector_gap_filler_byte = 0x4e);
std::shared_ptr<Storage::Disk::Track> GetFMTrackWithSectors(const std::vector<const Sector *> &sectors, size_t sector_gap_length = DefaultSectorGapLength, uint8_t sector_gap_filler_byte = 0x4e); std::shared_ptr<Storage::Disk::Track> GetFMTrackWithSectors(const std::vector<const Sector *> &sectors, std::size_t sector_gap_length = DefaultSectorGapLength, uint8_t sector_gap_filler_byte = 0x4e);
class Encoder { class Encoder {
public: public:

View File

@ -27,7 +27,7 @@ void Parser::install_sectors_from_track(const Storage::Disk::Track::Address &add
return; return;
} }
std::map<size_t, Sector> sectors = sectors_from_segment( std::map<std::size_t, Sector> sectors = sectors_from_segment(
Storage::Disk::track_serialisation(*track, is_mfm_ ? MFMBitLength : FMBitLength), Storage::Disk::track_serialisation(*track, is_mfm_ ? MFMBitLength : FMBitLength),
is_mfm_); is_mfm_);

View File

@ -11,17 +11,17 @@
using namespace Storage::Encodings::MFM; using namespace Storage::Encodings::MFM;
std::map<size_t, Storage::Encodings::MFM::Sector> Storage::Encodings::MFM::sectors_from_segment(const Storage::Disk::PCMSegment &&segment, bool is_double_density) { std::map<std::size_t, Storage::Encodings::MFM::Sector> Storage::Encodings::MFM::sectors_from_segment(const Storage::Disk::PCMSegment &&segment, bool is_double_density) {
std::map<size_t, Sector> result; std::map<std::size_t, Sector> result;
Shifter shifter; Shifter shifter;
shifter.set_is_double_density(is_double_density); shifter.set_is_double_density(is_double_density);
shifter.set_should_obey_syncs(true); shifter.set_should_obey_syncs(true);
std::unique_ptr<Storage::Encodings::MFM::Sector> new_sector; std::unique_ptr<Storage::Encodings::MFM::Sector> new_sector;
bool is_reading = false; bool is_reading = false;
size_t position = 0; std::size_t position = 0;
size_t size = 0; std::size_t size = 0;
size_t start_location = 0; std::size_t start_location = 0;
for(unsigned int bit = 0; bit < segment.number_of_bits; ++bit) { for(unsigned int bit = 0; bit < segment.number_of_bits; ++bit) {
shifter.add_input_bit(segment.bit(bit)); shifter.add_input_bit(segment.bit(bit));
@ -56,7 +56,7 @@ std::map<size_t, Storage::Encodings::MFM::Sector> Storage::Encodings::MFM::secto
case 2: new_sector->address.sector = shifter.get_byte(); ++position; break; case 2: new_sector->address.sector = shifter.get_byte(); ++position; break;
case 3: case 3:
new_sector->size = shifter.get_byte(); new_sector->size = shifter.get_byte();
size = static_cast<size_t>(128 << new_sector->size); size = static_cast<std::size_t>(128 << new_sector->size);
++position; ++position;
is_reading = false; is_reading = false;
shifter.set_should_obey_syncs(true); shifter.set_should_obey_syncs(true);

View File

@ -21,7 +21,7 @@ namespace MFM {
Scans @c segment for all included sectors, returning a set that maps from location within Scans @c segment for all included sectors, returning a set that maps from location within
the segment (counted in bits from the beginning) to sector. the segment (counted in bits from the beginning) to sector.
*/ */
std::map<size_t, Sector> sectors_from_segment(const Disk::PCMSegment &&segment, bool is_double_density); std::map<std::size_t, Sector> sectors_from_segment(const Disk::PCMSegment &&segment, bool is_double_density);
} }
} }

View File

@ -20,14 +20,14 @@ std::unique_ptr<Storage::Disk::CPM::Catalogue> Storage::Disk::CPM::GetCatalogue(
// Assemble the actual bytes of the catalogue. // Assemble the actual bytes of the catalogue.
std::vector<uint8_t> catalogue; std::vector<uint8_t> catalogue;
size_t sector_size = 1; std::size_t sector_size = 1;
uint16_t catalogue_allocation_bitmap = parameters.catalogue_allocation_bitmap; uint16_t catalogue_allocation_bitmap = parameters.catalogue_allocation_bitmap;
if(!catalogue_allocation_bitmap) return nullptr; if(!catalogue_allocation_bitmap) return nullptr;
int sector = 0; int sector = 0;
int track = parameters.reserved_tracks; int track = parameters.reserved_tracks;
while(catalogue_allocation_bitmap) { while(catalogue_allocation_bitmap) {
if(catalogue_allocation_bitmap & 0x8000) { if(catalogue_allocation_bitmap & 0x8000) {
size_t size_read = 0; std::size_t size_read = 0;
do { do {
Storage::Encodings::MFM::Sector *sector_contents = parser.get_sector(0, static_cast<uint8_t>(track), static_cast<uint8_t>(parameters.first_sector + sector)); Storage::Encodings::MFM::Sector *sector_contents = parser.get_sector(0, static_cast<uint8_t>(track), static_cast<uint8_t>(parameters.first_sector + sector));
if(!sector_contents || sector_contents->samples.empty()) { if(!sector_contents || sector_contents->samples.empty()) {
@ -43,7 +43,7 @@ std::unique_ptr<Storage::Disk::CPM::Catalogue> Storage::Disk::CPM::GetCatalogue(
sector = 0; sector = 0;
track++; track++;
} }
} while(size_read < static_cast<size_t>(parameters.block_size)); } while(size_read < static_cast<std::size_t>(parameters.block_size));
} }
catalogue_allocation_bitmap <<= 1; catalogue_allocation_bitmap <<= 1;
@ -55,9 +55,9 @@ std::unique_ptr<Storage::Disk::CPM::Catalogue> Storage::Disk::CPM::GetCatalogue(
std::string type; std::string type;
bool read_only; bool read_only;
bool system; bool system;
size_t extent; std::size_t extent;
uint8_t number_of_records; uint8_t number_of_records;
size_t catalogue_index; std::size_t catalogue_index;
bool operator < (const CatalogueEntry &rhs) const { bool operator < (const CatalogueEntry &rhs) const {
return std::tie(user_number, name, type, extent) < std::tie(rhs.user_number, rhs.name, rhs.type, rhs.extent); return std::tie(user_number, name, type, extent) < std::tie(rhs.user_number, rhs.name, rhs.type, rhs.extent);
@ -69,7 +69,7 @@ std::unique_ptr<Storage::Disk::CPM::Catalogue> Storage::Disk::CPM::GetCatalogue(
// From the catalogue, get catalogue entries. // From the catalogue, get catalogue entries.
std::vector<CatalogueEntry> catalogue_entries; std::vector<CatalogueEntry> catalogue_entries;
for(size_t c = 0; c < catalogue.size(); c += 32) { for(std::size_t c = 0; c < catalogue.size(); c += 32) {
// Skip this file if it's deleted; this is marked by it having 0xe5 as its user number // Skip this file if it's deleted; this is marked by it having 0xe5 as its user number
if(catalogue[c] == 0xe5) continue; if(catalogue[c] == 0xe5) continue;
@ -77,10 +77,10 @@ std::unique_ptr<Storage::Disk::CPM::Catalogue> Storage::Disk::CPM::GetCatalogue(
CatalogueEntry &entry = catalogue_entries.back(); CatalogueEntry &entry = catalogue_entries.back();
entry.user_number = catalogue[c]; entry.user_number = catalogue[c];
entry.name.insert(entry.name.begin(), &catalogue[c+1], &catalogue[c+9]); entry.name.insert(entry.name.begin(), &catalogue[c+1], &catalogue[c+9]);
for(size_t s = 0; s < 3; s++) entry.type.push_back((char)catalogue[c + s + 9] & 0x7f); for(std::size_t s = 0; s < 3; s++) entry.type.push_back((char)catalogue[c + s + 9] & 0x7f);
entry.read_only = catalogue[c + 9] & 0x80; entry.read_only = catalogue[c + 9] & 0x80;
entry.system = catalogue[c + 10] & 0x80; entry.system = catalogue[c + 10] & 0x80;
entry.extent = static_cast<size_t>(catalogue[c + 12] + (catalogue[c + 14] << 5)); entry.extent = static_cast<std::size_t>(catalogue[c + 12] + (catalogue[c + 14] << 5));
entry.number_of_records = catalogue[c + 15]; entry.number_of_records = catalogue[c + 15];
entry.catalogue_index = c; entry.catalogue_index = c;
} }
@ -91,7 +91,7 @@ std::unique_ptr<Storage::Disk::CPM::Catalogue> Storage::Disk::CPM::GetCatalogue(
std::unique_ptr<Catalogue> result(new Catalogue); std::unique_ptr<Catalogue> result(new Catalogue);
bool has_long_allocation_units = (parameters.tracks * parameters.sectors_per_track * static_cast<int>(sector_size) / parameters.block_size) >= 256; bool has_long_allocation_units = (parameters.tracks * parameters.sectors_per_track * static_cast<int>(sector_size) / parameters.block_size) >= 256;
size_t bytes_per_catalogue_entry = (has_long_allocation_units ? 8 : 16) * static_cast<size_t>(parameters.block_size); std::size_t bytes_per_catalogue_entry = (has_long_allocation_units ? 8 : 16) * static_cast<std::size_t>(parameters.block_size);
int sectors_per_block = parameters.block_size / static_cast<int>(sector_size); int sectors_per_block = parameters.block_size / static_cast<int>(sector_size);
int records_per_sector = static_cast<int>(sector_size) / 128; int records_per_sector = static_cast<int>(sector_size) / 128;
@ -114,14 +114,14 @@ std::unique_ptr<Storage::Disk::CPM::Catalogue> Storage::Disk::CPM::GetCatalogue(
new_file.system = entry->system; new_file.system = entry->system;
// Create storage for data. // Create storage for data.
size_t required_size = final_entry->extent * bytes_per_catalogue_entry + static_cast<size_t>(final_entry->number_of_records) * 128; std::size_t required_size = final_entry->extent * bytes_per_catalogue_entry + static_cast<std::size_t>(final_entry->number_of_records) * 128;
new_file.data.resize(required_size); new_file.data.resize(required_size);
// Accumulate all data. // Accumulate all data.
while(entry <= final_entry) { while(entry <= final_entry) {
int record = 0; int record = 0;
int number_of_records = (entry->number_of_records != 0x80) ? entry->number_of_records : (has_long_allocation_units ? 8 : 16); int number_of_records = (entry->number_of_records != 0x80) ? entry->number_of_records : (has_long_allocation_units ? 8 : 16);
for(size_t block = 0; block < (has_long_allocation_units ? 8 : 16) && record < number_of_records; block++) { for(std::size_t block = 0; block < (has_long_allocation_units ? 8 : 16) && record < number_of_records; block++) {
int block_number; int block_number;
if(has_long_allocation_units) { if(has_long_allocation_units) {
block_number = catalogue[entry->catalogue_index + 16 + (block << 1)] + (catalogue[entry->catalogue_index + 16 + (block << 1) + 1] << 8); block_number = catalogue[entry->catalogue_index + 16 + (block << 1)] + (catalogue[entry->catalogue_index + 16 + (block << 1) + 1] << 8);
@ -147,7 +147,7 @@ std::unique_ptr<Storage::Disk::CPM::Catalogue> Storage::Disk::CPM::GetCatalogue(
} }
int records_to_copy = std::min(entry->number_of_records - record, records_per_sector); int records_to_copy = std::min(entry->number_of_records - record, records_per_sector);
memcpy(&new_file.data[entry->extent * bytes_per_catalogue_entry + static_cast<size_t>(record) * 128], sector_contents->samples[0].data(), static_cast<size_t>(records_to_copy) * 128); std::memcpy(&new_file.data[entry->extent * bytes_per_catalogue_entry + static_cast<std::size_t>(record) * 128], sector_contents->samples[0].data(), static_cast<std::size_t>(records_to_copy) * 128);
record += records_to_copy; record += records_to_copy;
} }
} }

View File

@ -46,7 +46,7 @@ void PCMSegmentEventSource::reset() {
Storage::Disk::Track::Event PCMSegmentEventSource::get_next_event() { Storage::Disk::Track::Event PCMSegmentEventSource::get_next_event() {
// track the initial bit pointer for potentially considering whether this was an // track the initial bit pointer for potentially considering whether this was an
// initial index hole or a subsequent one later on // initial index hole or a subsequent one later on
size_t initial_bit_pointer = bit_pointer_; std::size_t initial_bit_pointer = bit_pointer_;
// if starting from the beginning, pull half a bit backward, as if the initial bit // if starting from the beginning, pull half a bit backward, as if the initial bit
// is set, it should be in the centre of its window // is set, it should be in the centre of its window

View File

@ -33,7 +33,7 @@ struct PCMSegment {
: length_of_a_bit(length_of_a_bit), number_of_bits(number_of_bits), data(data) {} : length_of_a_bit(length_of_a_bit), number_of_bits(number_of_bits), data(data) {}
PCMSegment() {} PCMSegment() {}
int bit(size_t index) const { int bit(std::size_t index) const {
return (data[index >> 3] >> (7 ^ (index & 7)))&1; return (data[index >> 3] >> (7 ^ (index & 7)))&1;
} }
}; };
@ -81,7 +81,7 @@ class PCMSegmentEventSource {
private: private:
std::shared_ptr<PCMSegment> segment_; std::shared_ptr<PCMSegment> segment_;
size_t bit_pointer_; std::size_t bit_pointer_;
Track::Event next_event_; Track::Event next_event_;
}; };

View File

@ -51,7 +51,7 @@ class PCMTrack: public Track {
std::vector<PCMSegmentEventSource> segment_event_sources_; std::vector<PCMSegmentEventSource> segment_event_sources_;
// a pointer to the first bit to consider as the next event // a pointer to the first bit to consider as the next event
size_t segment_pointer_; std::size_t segment_pointer_;
PCMTrack(); PCMTrack();
}; };

View File

@ -107,25 +107,25 @@ void FileHolder::put8(uint8_t value) {
fputc(value, file_); fputc(value, file_);
} }
void FileHolder::putn(size_t repeats, uint8_t value) { void FileHolder::putn(std::size_t repeats, uint8_t value) {
while(repeats--) put8(value); while(repeats--) put8(value);
} }
std::vector<uint8_t> FileHolder::read(size_t size) { std::vector<uint8_t> FileHolder::read(std::size_t size) {
std::vector<uint8_t> result(size); std::vector<uint8_t> result(size);
fread(result.data(), 1, size, file_); fread(result.data(), 1, size, file_);
return result; return result;
} }
size_t FileHolder::read(uint8_t *buffer, size_t size) { std::size_t FileHolder::read(uint8_t *buffer, std::size_t size) {
return fread(buffer, 1, size, file_); return fread(buffer, 1, size, file_);
} }
size_t FileHolder::write(const std::vector<uint8_t> &buffer) { std::size_t FileHolder::write(const std::vector<uint8_t> &buffer) {
return fwrite(buffer.data(), 1, buffer.size(), file_); return fwrite(buffer.data(), 1, buffer.size(), file_);
} }
size_t FileHolder::write(const uint8_t *buffer, size_t size) { std::size_t FileHolder::write(const uint8_t *buffer, std::size_t size) {
return fwrite(buffer, 1, size, file_); return fwrite(buffer, 1, size, file_);
} }
@ -149,8 +149,8 @@ FileHolder::BitStream FileHolder::get_bitstream(bool lsb_first) {
return BitStream(file_, lsb_first); return BitStream(file_, lsb_first);
} }
bool FileHolder::check_signature(const char *signature, size_t length) { bool FileHolder::check_signature(const char *signature, std::size_t length) {
if(!length) length = strlen(signature); if(!length) length = std::strlen(signature);
// read and check the file signature // read and check the file signature
std::vector<uint8_t> stored_signature = read(length); std::vector<uint8_t> stored_signature = read(length);
@ -160,7 +160,7 @@ bool FileHolder::check_signature(const char *signature, size_t length) {
} }
std::string FileHolder::extension() { std::string FileHolder::extension() {
size_t pointer = name_.size() - 1; std::size_t pointer = name_.size() - 1;
while(pointer > 0 && name_[pointer] != '.') pointer--; while(pointer > 0 && name_[pointer] != '.') pointer--;
if(name_[pointer] == '.') pointer++; if(name_[pointer] == '.') pointer++;
@ -173,9 +173,9 @@ void FileHolder::ensure_is_at_least_length(long length) {
fseek(file_, 0, SEEK_END); fseek(file_, 0, SEEK_END);
long bytes_to_write = length - ftell(file_); long bytes_to_write = length - ftell(file_);
if(bytes_to_write > 0) { if(bytes_to_write > 0) {
uint8_t *empty = new uint8_t[static_cast<size_t>(bytes_to_write)]; uint8_t *empty = new uint8_t[static_cast<std::size_t>(bytes_to_write)];
memset(empty, 0, static_cast<size_t>(bytes_to_write)); memset(empty, 0, static_cast<std::size_t>(bytes_to_write));
fwrite(empty, sizeof(uint8_t), static_cast<size_t>(bytes_to_write), file_); fwrite(empty, sizeof(uint8_t), static_cast<std::size_t>(bytes_to_write), file_);
delete[] empty; delete[] empty;
} }
} }

View File

@ -99,19 +99,19 @@ class FileHolder final {
void put8(uint8_t value); void put8(uint8_t value);
/*! Writes @c value a total of @c repeats times. */ /*! Writes @c value a total of @c repeats times. */
void putn(size_t repeats, uint8_t value); void putn(std::size_t repeats, uint8_t value);
/*! Reads @c size bytes and returns them as a vector. */ /*! Reads @c size bytes and returns them as a vector. */
std::vector<uint8_t> read(size_t size); std::vector<uint8_t> read(std::size_t size);
/*! Reads @c size bytes and writes them to @c buffer. */ /*! Reads @c size bytes and writes them to @c buffer. */
size_t read(uint8_t *buffer, size_t size); std::size_t read(uint8_t *buffer, std::size_t size);
/*! Writes @c buffer one byte at a time in order. */ /*! Writes @c buffer one byte at a time in order. */
size_t write(const std::vector<uint8_t> &buffer); std::size_t write(const std::vector<uint8_t> &buffer);
/*! Writes @c buffer one byte at a time in order, writing @c size bytes in total. */ /*! Writes @c buffer one byte at a time in order, writing @c size bytes in total. */
size_t write(const uint8_t *buffer, size_t size); std::size_t write(const uint8_t *buffer, std::size_t size);
/*! Moves @c bytes from the anchor indicated by @c whence — SEEK_SET, SEEK_CUR or SEEK_END. */ /*! Moves @c bytes from the anchor indicated by @c whence — SEEK_SET, SEEK_CUR or SEEK_END. */
void seek(long offset, int whence); void seek(long offset, int whence);
@ -181,7 +181,7 @@ class FileHolder final {
@returns @c true if the bytes read match the signature; @c false otherwise. @returns @c true if the bytes read match the signature; @c false otherwise.
*/ */
bool check_signature(const char *signature, size_t length = 0); bool check_signature(const char *signature, std::size_t length = 0);
/*! /*!
Determines and returns the file extension everything from the final character Determines and returns the file extension everything from the final character

View File

@ -61,10 +61,10 @@ CSW::CSW(const char *file_name) :
// The only clue given by CSW as to the output size in bytes is that there will be // 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 // number_of_waves waves. Waves are usually one byte, but may be five. So this code
// is pessimistic. // is pessimistic.
source_data_.resize(static_cast<size_t>(number_of_waves) * 5); source_data_.resize(static_cast<std::size_t>(number_of_waves) * 5);
std::vector<uint8_t> file_data; std::vector<uint8_t> file_data;
size_t remaining_data = static_cast<size_t>(file_.stats().st_size) - static_cast<size_t>(file_.tell()); std::size_t remaining_data = static_cast<std::size_t>(file_.stats().st_size) - static_cast<std::size_t>(file_.tell());
file_data.resize(remaining_data); file_data.resize(remaining_data);
file_.read(file_data.data(), remaining_data); file_.read(file_data.data(), remaining_data);
@ -73,7 +73,7 @@ CSW::CSW(const char *file_name) :
// needed. // needed.
uLongf output_length = static_cast<uLongf>(number_of_waves * 5); uLongf output_length = static_cast<uLongf>(number_of_waves * 5);
uncompress(source_data_.data(), &output_length, file_data.data(), file_data.size()); uncompress(source_data_.data(), &output_length, file_data.data(), file_data.size());
source_data_.resize(static_cast<size_t>(output_length)); source_data_.resize(static_cast<std::size_t>(output_length));
} else { } else {
rle_start_ = file_.tell(); rle_start_ = file_.tell();
} }

View File

@ -54,7 +54,7 @@ class CSW: public Tape {
void invert_pulse(); void invert_pulse();
std::vector<uint8_t> source_data_; std::vector<uint8_t> source_data_;
size_t source_data_pointer_; std::size_t source_data_pointer_;
long rle_start_; long rle_start_;
}; };

View File

@ -133,7 +133,7 @@ void TZX::get_generalised_segment(uint32_t output_symbols, uint8_t max_pulses_pe
base <<= 1; base <<= 1;
bits++; bits++;
} }
for(size_t c = 0; c < output_symbols; c++) { for(std::size_t c = 0; c < output_symbols; c++) {
uint8_t symbol_value; uint8_t symbol_value;
int count; int count;
if(is_data) { if(is_data) {

View File

@ -73,7 +73,7 @@ UEF::UEF(const char *file_name) {
char identifier[10]; char identifier[10];
int bytes_read = gzread(file_, identifier, 10); int bytes_read = gzread(file_, identifier, 10);
if(bytes_read < 10 || strcmp(identifier, "UEF File!")) { if(bytes_read < 10 || std::strcmp(identifier, "UEF File!")) {
throw ErrorNotUEF; throw ErrorNotUEF;
} }
@ -170,9 +170,9 @@ void UEF::queue_implicit_bit_pattern(uint32_t length) {
} }
void UEF::queue_explicit_bit_pattern(uint32_t length) { void UEF::queue_explicit_bit_pattern(uint32_t length) {
size_t length_in_bits = (length << 3) - static_cast<size_t>(gzget8(file_)); std::size_t length_in_bits = (length << 3) - static_cast<std::size_t>(gzget8(file_));
uint8_t current_byte = 0; uint8_t current_byte = 0;
for(size_t bit = 0; bit < length_in_bits; bit++) { for(std::size_t bit = 0; bit < length_in_bits; bit++) {
if(!(bit&7)) current_byte = gzget8(file_); if(!(bit&7)) current_byte = gzget8(file_);
queue_bit(current_byte&1); queue_bit(current_byte&1);
current_byte >>= 1; current_byte >>= 1;

View File

@ -15,8 +15,8 @@ ZX80O81P::ZX80O81P(const char *file_name) {
Storage::FileHolder file(file_name); Storage::FileHolder file(file_name);
// Grab the actual file contents // Grab the actual file contents
data_.resize(static_cast<size_t>(file.stats().st_size)); data_.resize(static_cast<std::size_t>(file.stats().st_size));
file.read(data_.data(), static_cast<size_t>(file.stats().st_size)); file.read(data_.data(), static_cast<std::size_t>(file.stats().st_size));
// If it's a ZX81 file, prepend a file name. // If it's a ZX81 file, prepend a file name.
std::string type = file.extension(); std::string type = file.extension();

View File

@ -55,7 +55,7 @@ class ZX80O81P: public Tape, public TargetPlatform::TypeDistinguisher {
bool is_high_; bool is_high_;
std::vector<uint8_t> data_; std::vector<uint8_t> data_;
size_t data_pointer_; std::size_t data_pointer_;
}; };
} }

View File

@ -93,7 +93,7 @@ std::unique_ptr<Header> Parser::get_next_header_body(const std::shared_ptr<Stora
// grab rest of data // grab rest of data
header->data.reserve(191); header->data.reserve(191);
for(size_t c = 0; c < 191; c++) for(std::size_t c = 0; c < 191; c++)
{ {
header->data.push_back(get_next_byte(tape)); header->data.push_back(get_next_byte(tape));
} }
@ -107,7 +107,7 @@ std::unique_ptr<Header> Parser::get_next_header_body(const std::shared_ptr<Stora
header->starting_address = static_cast<uint16_t>(header->data[0] | (header->data[1] << 8)); header->starting_address = static_cast<uint16_t>(header->data[0] | (header->data[1] << 8));
header->ending_address = static_cast<uint16_t>(header->data[2] | (header->data[3] << 8)); header->ending_address = static_cast<uint16_t>(header->data[2] | (header->data[3] << 8));
for(size_t c = 0; c < 16; c++) for(std::size_t c = 0; c < 16; c++)
{ {
header->raw_name.push_back(header->data[4 + c]); header->raw_name.push_back(header->data[4 + c]);
} }
@ -129,7 +129,7 @@ void Header::serialise(uint8_t *target, uint16_t length) {
case Header::EndOfTape: target[0] = 0x05; break; case Header::EndOfTape: target[0] = 0x05; break;
} }
memcpy(&target[1], data.data(), 191); std::memcpy(&target[1], data.data(), 191);
} }
std::unique_ptr<Data> Parser::get_next_data_body(const std::shared_ptr<Storage::Tape::Tape> &tape, bool is_original) std::unique_ptr<Data> Parser::get_next_data_body(const std::shared_ptr<Storage::Tape::Tape> &tape, bool is_original)

View File

@ -105,7 +105,7 @@ void Parser::inspect_waves(const std::vector<WaveType> &waves)
#define CHECK_RUN(length, type, symbol) \ #define CHECK_RUN(length, type, symbol) \
if(waves.size() >= length)\ if(waves.size() >= length)\
{\ {\
size_t c;\ std::size_t c;\
for(c = 0; c < length; c++) if(waves[c] != type) break;\ for(c = 0; c < length; c++) if(waves[c] != type) break;\
if(c == length)\ if(c == length)\
{\ {\
@ -144,8 +144,8 @@ void Parser::inspect_waves(const std::vector<WaveType> &waves)
{WaveType::Unrecognised} {WaveType::Unrecognised}
}; };
size_t slow_sync_matching_depth = pattern_matching_depth(waves, slow_sync); std::size_t slow_sync_matching_depth = pattern_matching_depth(waves, slow_sync);
size_t fast_sync_matching_depth = pattern_matching_depth(waves, fast_sync); std::size_t fast_sync_matching_depth = pattern_matching_depth(waves, fast_sync);
if(slow_sync_matching_depth == 52) if(slow_sync_matching_depth == 52)
{ {
@ -171,9 +171,9 @@ void Parser::inspect_waves(const std::vector<WaveType> &waves)
remove_waves(1); remove_waves(1);
} }
size_t Parser::pattern_matching_depth(const std::vector<WaveType> &waves, Pattern *pattern) std::size_t Parser::pattern_matching_depth(const std::vector<WaveType> &waves, Pattern *pattern)
{ {
size_t depth = 0; std::size_t depth = 0;
int pattern_depth = 0; int pattern_depth = 0;
while(depth < waves.size() && pattern->type != WaveType::Unrecognised) while(depth < waves.size() && pattern->type != WaveType::Unrecognised)
{ {

View File

@ -50,7 +50,7 @@ class Parser: public Storage::Tape::PulseClassificationParser<WaveType, SymbolTy
WaveType type; WaveType type;
int count; int count;
}; };
size_t pattern_matching_depth(const std::vector<WaveType> &waves, Pattern *pattern); std::size_t pattern_matching_depth(const std::vector<WaveType> &waves, Pattern *pattern);
}; };

View File

@ -11,9 +11,9 @@
#include "../Tape.hpp" #include "../Tape.hpp"
#include <cassert>
#include <memory> #include <memory>
#include <vector> #include <vector>
#include <assert.h>
namespace Storage { namespace Storage {
namespace Tape { namespace Tape {

View File

@ -62,14 +62,14 @@ void Parser::inspect_waves(const std::vector<WaveType> &waves) {
} }
if(waves.size() >= 4) { if(waves.size() >= 4) {
size_t wave_offset = 0; std::size_t wave_offset = 0;
// If the very first thing is a gap, swallow it. // If the very first thing is a gap, swallow it.
if(waves[0] == WaveType::Gap) { if(waves[0] == WaveType::Gap) {
wave_offset = 1; wave_offset = 1;
} }
// Count the number of pulses at the start of this vector // Count the number of pulses at the start of this vector
size_t number_of_pulses = 0; std::size_t number_of_pulses = 0;
while(number_of_pulses + wave_offset < waves.size() && waves[number_of_pulses + wave_offset] == WaveType::Pulse) { while(number_of_pulses + wave_offset < waves.size() && waves[number_of_pulses + wave_offset] == WaveType::Pulse) {
number_of_pulses++; number_of_pulses++;
} }
@ -79,7 +79,7 @@ void Parser::inspect_waves(const std::vector<WaveType> &waves) {
// A 1 is 9 waves, a 0 is 4. Counting upward zero transitions, the first in either group will // A 1 is 9 waves, a 0 is 4. Counting upward zero transitions, the first in either group will
// act simply to terminate the gap beforehand and won't be logged as a pulse. So counts to // act simply to terminate the gap beforehand and won't be logged as a pulse. So counts to
// check are 8 and 3. // check are 8 and 3.
size_t gaps_to_swallow = wave_offset + ((waves[number_of_pulses + wave_offset] == WaveType::Gap) ? 1 : 0); std::size_t gaps_to_swallow = wave_offset + ((waves[number_of_pulses + wave_offset] == WaveType::Gap) ? 1 : 0);
switch(number_of_pulses) { switch(number_of_pulses) {
case 8: push_symbol(SymbolType::One, static_cast<int>(number_of_pulses + gaps_to_swallow)); break; case 8: push_symbol(SymbolType::One, static_cast<int>(number_of_pulses + gaps_to_swallow)); break;
case 3: push_symbol(SymbolType::Zero, static_cast<int>(number_of_pulses + gaps_to_swallow)); break; case 3: push_symbol(SymbolType::Zero, static_cast<int>(number_of_pulses + gaps_to_swallow)); break;

View File

@ -55,7 +55,7 @@ Tape::Pulse PulseQueuedTape::virtual_get_next_pulse() {
} }
} }
size_t read_pointer = pulse_pointer_; std::size_t read_pointer = pulse_pointer_;
pulse_pointer_++; pulse_pointer_++;
return queued_pulses_[read_pointer]; return queued_pulses_[read_pointer];
} }

View File

@ -43,7 +43,7 @@ class PulseQueuedTape: public Tape {
Pulse silence(); Pulse silence();
std::vector<Pulse> queued_pulses_; std::vector<Pulse> queued_pulses_;
size_t pulse_pointer_; std::size_t pulse_pointer_;
bool is_at_end_; bool is_at_end_;
}; };