d88_dsk.cpp, dsk_dsk.cpp: Mitigate against rot in legacy floppy code

This commit is contained in:
AJR 2023-02-12 19:49:31 -05:00
parent 0341f8ee4c
commit 17080d3d93
2 changed files with 20 additions and 12 deletions

View File

@ -37,6 +37,8 @@
#define D88_HEADER_LEN 0x2b0
#define SPOT_DUPLICATES 0
struct d88_tag
{
uint32_t image_size;
@ -280,14 +282,15 @@ static void d88_get_header(floppy_image_legacy* floppy,uint32_t* size, uint8_t*
floppy_image_read(floppy,header,0,D88_HEADER_LEN);
#ifdef SPOT_DUPLICATES
if(SPOT_DUPLICATES)
{
// there exist many .d88 files with same data and different headers and
// this allows to spot duplicates, making easier to debug softlists.
uint32_t temp_size = floppy_image_size(floppy);
uint8_t tmp_copy[temp_size - D88_HEADER_LEN];
floppy_image_read(floppy,tmp_copy,D88_HEADER_LEN,temp_size - D88_HEADER_LEN);
printf("CRC16: %d\n", ccitt_crc16(0xffff, tmp_copy, temp_size - D88_HEADER_LEN));
#endif
auto tmp_copy = std::make_unique<uint8_t[]>(temp_size - D88_HEADER_LEN);
floppy_image_read(floppy,tmp_copy.get(),D88_HEADER_LEN,temp_size - D88_HEADER_LEN);
printf("CRC16: %d\n", ccitt_crc16(0xffff, tmp_copy.get(), temp_size - D88_HEADER_LEN));
}
if(prot)
*prot = header[0x1a];

View File

@ -14,11 +14,15 @@
#include "ioprocs.h"
#include "osdcore.h" // osd_printf_*
#include <cstring>
#define MV_CPC "MV - CPC"
#define EXTENDED "EXTENDED"
#define SPOT_DUPLICATES 0
struct dskdsk_tag
{
int disk_image_type; /* image type: standard or extended */
@ -220,13 +224,14 @@ FLOPPY_CONSTRUCT( dsk_dsk_construct )
}
floppy_image_read(floppy, header, 0, 0x100);
#ifdef SPOT_DUPLICATES
// this allow to spot .dsk files with same data and different headers, making easier to debug softlists.
uint32_t temp_size = floppy_image_size(floppy);
uint8_t tmp_copy[temp_size - 0x100];
floppy_image_read(floppy,tmp_copy,0x100,temp_size - 0x100);
printf("CRC16: %d\n", ccitt_crc16(0xffff, tmp_copy, temp_size - 0x100));
#endif
if(SPOT_DUPLICATES)
{
// this allow to spot .dsk files with same data and different headers, making easier to debug softlists.
uint32_t temp_size = floppy_image_size(floppy);
auto tmp_copy = std::make_unique<uint8_t[]>(temp_size - 0x100);
floppy_image_read(floppy,tmp_copy.get(),0x100,temp_size - 0x100);
printf("CRC16: %d\n", ccitt_crc16(0xffff, tmp_copy.get(), temp_size - 0x100));
}
tag = (struct dskdsk_tag *) floppy_create_tag(floppy, sizeof(struct dskdsk_tag));
if (!tag)