mirror of
https://github.com/TomHarte/CLK.git
synced 2025-01-24 02:30:54 +00:00
Permitted ROM-style PRGs that are not a power-of-two in size, and added extra safety checks on loading data from a tape.
This commit is contained in:
parent
cb66c7e2dc
commit
5d91a2600d
@ -147,10 +147,13 @@ unsigned int Machine::perform_bus_operation(CPU6502::BusOperation operation, uin
|
||||
|
||||
// perform a via-processor_write_memory_map_ memcpy
|
||||
uint8_t *data_ptr = data->data.data();
|
||||
while(start_address != end_address) {
|
||||
processor_write_memory_map_[start_address >> 10][start_address & 0x3ff] = *data_ptr;
|
||||
size_t data_left = data->data.size();
|
||||
while(data_left && start_address != end_address) {
|
||||
uint8_t *page = processor_write_memory_map_[start_address >> 10];
|
||||
if(page) page[start_address & 0x3ff] = *data_ptr;
|
||||
data_ptr++;
|
||||
start_address++;
|
||||
data_left--;
|
||||
}
|
||||
|
||||
// set tape status, carry and flag
|
||||
|
@ -18,12 +18,8 @@ PRG::PRG(const char *file_name) {
|
||||
struct stat file_stats;
|
||||
stat(file_name, &file_stats);
|
||||
|
||||
// accept only files sized 1, 2, 4 or 8kb
|
||||
if(
|
||||
file_stats.st_size != 0x400 + 2 &&
|
||||
file_stats.st_size != 0x800 + 2 &&
|
||||
file_stats.st_size != 0x1000 + 2 &&
|
||||
file_stats.st_size != 0x2000 + 2)
|
||||
// accept only files sized less than 8kb
|
||||
if(file_stats.st_size > 0x2000 + 2)
|
||||
throw ErrorNotROM;
|
||||
|
||||
// get the loading address, and the rest of the contents
|
||||
@ -33,7 +29,9 @@ PRG::PRG(const char *file_name) {
|
||||
loading_address |= fgetc(file) << 8;
|
||||
|
||||
size_t data_length = (size_t)file_stats.st_size - 2;
|
||||
std::vector<uint8_t> contents(data_length);
|
||||
size_t padded_data_length = 1;
|
||||
while(padded_data_length < data_length) padded_data_length <<= 1;
|
||||
std::vector<uint8_t> contents(padded_data_length);
|
||||
fread(&contents[0], 1, (size_t)(data_length), file);
|
||||
fclose(file);
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user