From fcfc3cead39d06f5efed5cb480a8b963463d18e3 Mon Sep 17 00:00:00 2001 From: Fabio Cavallo Date: Wed, 3 Jan 2024 10:18:04 +0100 Subject: [PATCH 01/10] Fixed VBV buffer size. --- src/core/recording.c | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/src/core/recording.c b/src/core/recording.c index 016616fe4..fc6c5f554 100644 --- a/src/core/recording.c +++ b/src/core/recording.c @@ -878,7 +878,7 @@ static BYTE ffmpeg_video_add_stream_format_mpeg1(void) { AVCPBProperties *props = NULL; props = (AVCPBProperties *)av_stream_new_side_data(video->avs, AV_PKT_DATA_CPB_PROPERTIES, sizeof(*props)); - props->buffer_size = 224 * 1024; + props->buffer_size = 1835 * 1024; props->max_bitrate = 0; props->min_bitrate = 0; props->avg_bitrate = 0; @@ -905,7 +905,7 @@ static BYTE ffmpeg_video_add_stream_format_mpeg1(void) { sd = av_packet_side_data_new(&video->avs->codecpar->coded_side_data, &video->avs->codecpar->nb_coded_side_data, AV_PKT_DATA_CPB_PROPERTIES, sizeof(*props), 0); props = (AVCPBProperties *)sd->data; - props->buffer_size = 224 * 1024; + props->buffer_size = 1835 * 1024; props->max_bitrate = 0; props->min_bitrate = 0; props->avg_bitrate = 0; @@ -913,7 +913,7 @@ static BYTE ffmpeg_video_add_stream_format_mpeg1(void) { } else { props = (AVCPBProperties *)sd->data; if (!props->buffer_size) { - props->buffer_size = 224 * 1024; + props->buffer_size = 1835 * 1024; } } } @@ -939,7 +939,7 @@ static BYTE ffmpeg_video_add_stream_format_mpeg2(void) { AVCPBProperties *props = NULL; props = (AVCPBProperties *)av_stream_new_side_data(video->avs, AV_PKT_DATA_CPB_PROPERTIES, sizeof(*props)); - props->buffer_size = 224 * 1024; + props->buffer_size = 1835 * 1024; props->max_bitrate = 0; props->min_bitrate = 0; props->avg_bitrate = 0; @@ -964,9 +964,8 @@ static BYTE ffmpeg_video_add_stream_format_mpeg2(void) { if (!sd) { sd = av_packet_side_data_new(&video->avs->codecpar->coded_side_data, &video->avs->codecpar->nb_coded_side_data, AV_PKT_DATA_CPB_PROPERTIES, sizeof(*props), 0); - props = (AVCPBProperties *)sd->data; - props->buffer_size = 224 * 1024; + props->buffer_size = 1835 * 1024; props->max_bitrate = 0; props->min_bitrate = 0; props->avg_bitrate = 0; @@ -974,7 +973,7 @@ static BYTE ffmpeg_video_add_stream_format_mpeg2(void) { } else { props = (AVCPBProperties *)sd->data; if (!props->buffer_size) { - props->buffer_size = 224 * 1024; + props->buffer_size = 1835 * 1024; } } } From 6b8a1dd3467d916a88c15b5ac204a77af0c02a10 Mon Sep 17 00:00:00 2001 From: Fabio Cavallo Date: Wed, 3 Jan 2024 14:41:02 +0100 Subject: [PATCH 02/10] Fixed 8bit delay timing. --- src/core/fds.c | 149 ++++++++++++++++++++++++---------- src/core/fds.h | 21 +++-- src/core/mappers/mapper_FDS.c | 2 +- 3 files changed, 120 insertions(+), 52 deletions(-) diff --git a/src/core/fds.c b/src/core/fds.c index eb64b9696..f0b409402 100644 --- a/src/core/fds.c +++ b/src/core/fds.c @@ -37,6 +37,8 @@ typedef struct _fds_sinfo { WORD gversion; WORD snumber; WORD dnumber; + BYTE manufacturing[3]; + BYTE rewritten[3]; } block1; struct _fds_side_block2 { uint32_t position; @@ -78,7 +80,6 @@ typedef struct _fds_info_block { WORD flength_ppu; BYTE ftype; BYTE files; - BYTE bl1; BYTE stop; int count2000; BYTE magic_card_trainer; @@ -88,6 +89,7 @@ typedef struct _fds_info_block { } _fds_info_block; BYTE fds_to_image(_fds_info *finfo); +uTCHAR *fds_bcd_data(BYTE *bcd); void fds_free_fds_info(void); BYTE fds_examine_block(const BYTE *src, uint32_t position, _fds_info_block *fb); void fds_control_autoinsert(_fds_sinfo *sinfo); @@ -197,12 +199,12 @@ BYTE fds_load_rom(BYTE format) { if ((rom.data[rom.position++] == 'F') && (rom.data[rom.position++] == 'D') && (rom.data[rom.position++] == 'S') && - (rom.data[rom.position++] == '\32')) { - fds.info.type = FDS_FORMAT_FDS; + (rom.data[rom.position++] == 0x1A)) { + fds.info.type = FDS_TYPE_FDS; // il numero di disk sides fds.info.total_sides = rom.data[rom.position++]; } else { - fds.info.type = FDS_FORMAT_RAW; + fds.info.type = FDS_TYPE_RAW; // il numero di disk sides fds.info.total_sides = fds.info.total_size / fds_disk_side_size(format); if (!fds.info.total_sides) { @@ -325,8 +327,39 @@ BYTE fds_load_bios(void) { return (EXIT_OK); } -BYTE fds_change_disk(uTCHAR *path) { - uTCHAR file[LENGTH_FILE_NAME_LONG], *ext = NULL; +BYTE fds_create_empty_disk(BYTE format, BYTE type, BYTE double_side, uTCHAR *file) { + BYTE total_sides = double_side ? 2 : 1, *mfds = NULL; + size_t size = (type == FDS_TYPE_FDS ? 16 : 0) + (fds_disk_side_size(format) * total_sides); + FILE *fp = NULL; + BYTE rc = EXIT_OK; + + fp = ufopen(file, uL("w+b")); + if (!fp) { + return (EXIT_ERROR); + } + + mfds = (BYTE *)malloc(size); + if (!mfds) { + fclose(fp); + return (EXIT_ERROR); + } + memset(mfds, 0x00, size); + + if (type == FDS_TYPE_FDS) { + memcpy(&mfds[0], "FDS", 3); + mfds[3] = 0x1A; + mfds[4] = 0x01; + } + + if (fwrite(mfds, size, 1, fp) < 1) { + rc = EXIT_ERROR; + } + fclose(fp); + free(mfds); + return (rc); +} +BYTE fds_change_disk(uTCHAR *file) { + uTCHAR path[LENGTH_FILE_NAME_LONG], *ext = NULL; _uncompress_archive *archive = NULL; BYTE found = FALSE, rc = 0; size_t position = 0; @@ -334,17 +367,17 @@ BYTE fds_change_disk(uTCHAR *path) { FILE *fp = NULL; memset(&finfo, 0x00, sizeof(_fds_info)); - umemset(&file[0], 0x00, usizeof(file)); - ustrncpy(file, path, usizeof(file) - 1); + umemset(&path[0], 0x00, usizeof(path)); + ustrncpy(path, file, usizeof(path) - 1); - archive = uncompress_archive_alloc(file, &rc); + archive = uncompress_archive_alloc(path, &rc); if (rc == UNCOMPRESS_EXIT_OK) { if (archive->floppy_disk.count > 0) { switch ((rc = uncompress_archive_extract_file(archive, UNCOMPRESS_TYPE_FLOPPY_DISK))) { case UNCOMPRESS_EXIT_OK: - umemset(&file[0], 0x00, usizeof(file)); - ustrncpy(file, uncompress_archive_extracted_file_name(archive, UNCOMPRESS_TYPE_FLOPPY_DISK), usizeof(file) - 1); + umemset(&path[0], 0x00, usizeof(path)); + ustrncpy(path, uncompress_archive_extracted_file_name(archive, UNCOMPRESS_TYPE_FLOPPY_DISK), usizeof(path) - 1); found = TRUE; break; default: @@ -361,7 +394,7 @@ BYTE fds_change_disk(uTCHAR *path) { return (EXIT_ERROR); } - ext = emu_ctrl_rom_ext(file); + ext = emu_ctrl_rom_ext(path); if (!ustrcasecmp(ext, uL(".fds"))) { finfo.format = FDS_FORMAT; @@ -371,7 +404,7 @@ BYTE fds_change_disk(uTCHAR *path) { return (EXIT_ERROR); } - fp = ufopen(file, uL("rb")); + fp = ufopen(path, uL("rb")); if (!fp) { return (EXIT_ERROR); } @@ -395,12 +428,12 @@ BYTE fds_change_disk(uTCHAR *path) { if ((finfo.data[position++] == 'F') && (finfo.data[position++] == 'D') && (finfo.data[position++] == 'S') && - (finfo.data[position++] == '\32')) { - finfo.type = FDS_FORMAT_FDS; + (finfo.data[position++] == 0x1A)) { + finfo.type = FDS_TYPE_FDS; // il numero di disk sides finfo.total_sides = finfo.data[position++]; } else { - finfo.type = FDS_FORMAT_RAW; + finfo.type = FDS_TYPE_RAW; // il numero di disk sides finfo.total_sides = finfo.total_size / fds_disk_side_size(finfo.format); if (!finfo.total_sides) { @@ -428,7 +461,7 @@ BYTE fds_change_disk(uTCHAR *path) { finfo.frame_insert = nes[0].p.ppu.frames; info.format = finfo.format; - ustrncpy(info.rom.file, file, usizeof(info.rom.file)); + ustrncpy(info.rom.file, path, usizeof(info.rom.file)); fds_free_fds_info(); memcpy(&fds.info, &finfo, sizeof(_fds_info)); @@ -446,7 +479,7 @@ void fds_info(void) { log_info_open(uL("bios;")); umemset(buffer, 0x00, usizeof(buffer)); gui_utf_basename((uTCHAR *)fds.bios.file, buffer, usizeof(buffer) - 1); - log_close(uL("" uPs("") ", crc32 : 0x%08X"), buffer, fds.bios.crc32); + log_close(uL("" uPs("") ", crc : 0x%08X"), buffer, fds.bios.crc32); log_info_box_open(uL("folder;")); umemset(buffer, 0x00, usizeof(buffer)); @@ -463,11 +496,17 @@ void fds_info(void) { _fds_sinfo sinfo = { 0 }; fds_image_sinfo(side, &sinfo); - log_info_box(uL("FDS side %d;prg crc32 0x%08X, vrt size %d, files %3d, counted %3d"), side, - sinfo.crc32prg, - fds.info.sides[side].size, + log_info(uL("FDS side %d;disk %d, side %X, name %3s, version %d, files %d, counted %d"), side, + sinfo.block1.dnumber, + sinfo.block1.snumber + 0x0A, + sinfo.block1.name, + sinfo.block1.gversion, sinfo.block2.files, sinfo.counted_files); + log_info_box(uL(";@ " uPs("") ", written " uPs("") ", crc 0x%08X"), + fds_bcd_data(&sinfo.block1.manufacturing[0]), + fds_bcd_data(&sinfo.block1.rewritten[0]), + sinfo.crc32prg); // controllo se disabilitare l'autoinsert fds_control_autoinsert(&sinfo); #if !defined (RELEASE) @@ -479,12 +518,15 @@ void fds_info_side(BYTE side) { _fds_sinfo sinfo = { 0 }; fds_image_sinfo(side, &sinfo); - log_info(uL("FDS side %d;disk %d, side %X, name %3s, version %d, vsize %d, prg crc32 0x%08X"), side, + log_info(uL("FDS side %d;disk %d, side %X, name %3s, version %d, vsize %d"), side, sinfo.block1.dnumber, sinfo.block1.snumber + 0x0A, sinfo.block1.name, sinfo.block1.gversion, - fds.info.sides[side].size, + fds.info.sides[side].size); + log_info_box(uL("info;@ " uPs("") ", written " uPs("") ", crc 0x%08X"), + fds_bcd_data(&sinfo.block1.manufacturing[0]), + fds_bcd_data(&sinfo.block1.rewritten[0]), sinfo.crc32prg); log_info_box(uL("block 1;pos %5d"), sinfo.block1.position); log_info_box(uL("block 2;pos %5d, files %d, counted %d"), @@ -492,7 +534,7 @@ void fds_info_side(BYTE side) { sinfo.block2.files, sinfo.counted_files); for (uint32_t i = 0; i < sinfo.counted_files; i++) { - log_info_box(uL("file %d;name %8s, size %5d, crc32 0x%08X, 0x%04X (b3 : %5d) (b4 : %5d)"), i, + log_info_box(uL("file %d;name %8s, size %5d, crc 0x%08X, 0x%04X (b3 : %5d) (b4 : %5d)"), i, sinfo.file[i].block3.name, sinfo.file[i].block3.length, sinfo.file[i].block4.crc32, @@ -553,7 +595,7 @@ void fds_disk_op(WORD type, BYTE side_to_insert, BYTE quiet) { break; } - if ((info.reset != CHANGE_ROM) && (type >= FDS_DISK_SELECT)) { + if (((info.reset != CHANGE_ROM) || fds.info.total_sides == 1) && (type >= FDS_DISK_SELECT)) { if (fds.info.frame_insert != nes[0].p.ppu.frames) { fds.info.frame_insert = nes[0].p.ppu.frames; fds_info_side(side_to_insert); @@ -590,7 +632,7 @@ BYTE fds_from_image_to_file(uTCHAR *file, BYTE format, BYTE type) { if (fp) { // lo chiudo fclose(fp); - // lo riapro in modalita' rb+ + // lo riapro in modalita' w+b fp = ufopen(file, uL("w+b")); } else { free(mfds); @@ -683,7 +725,7 @@ BYTE fds_to_image(_fds_info *finfo) { BYTE *dst = NULL; uint32_t header = 0; - if (finfo->type == FDS_FORMAT_FDS) { + if (finfo->type == FDS_TYPE_FDS) { header = 16; } @@ -809,17 +851,6 @@ BYTE fds_to_image(_fds_info *finfo) { position += (fib.blength + (finfo->format == QD_FORMAT ? 2 : 0)); } - if (!fib.bl1) { - finfo->total_sides = side; - if (!finfo->total_sides) { - free(finfo->image); - finfo->image = NULL; - } else { - finfo->image = realloc((void *)finfo->image, finfo->total_sides * fds_image_side_size()); - } - continue; - } - is->side = side; if (size < fds_image_side_size()) { @@ -838,6 +869,30 @@ BYTE fds_to_image(_fds_info *finfo) { } return (EXIT_OK); } +uTCHAR *fds_bcd_data(BYTE *bcd) { + static uTCHAR date[13]; + + if ((!bcd[0] && !bcd[1] && !bcd[2]) || ((bcd[0] == 0xFF) && (bcd[1] == 0xFF) && (bcd[2] == 0xFF))) { + usnprintf(&date[0], usizeof(date), uL("__-__-____")); + } else { + int year = ((bcd[0] >> 4) * 10) + (bcd[0] & 0x0F); + int month = ((bcd[1] >> 4) * 10) + (bcd[1] & 0x0F); + int day = ((bcd[2] >> 4) * 10) + (bcd[2] & 0x0F); + + if (year < 55) { + // Heisei period + year += 1988; + } else if (year >= 80) { + // Western calendar + year += 1900; + } else { + // Showa period + year += 1925; + } + usnprintf(&date[0], usizeof(date), uL("%02d-%02d-%04d"), day, month, year); + } + return (&date[0]); +} void fds_free_fds_info(void) { if (fds.info.image) { // se richiesto, sovrascrivo il file originale @@ -875,7 +930,6 @@ BYTE fds_examine_block(const BYTE *src, uint32_t position, _fds_info_block *fib) fib->magic_card_trainer = FALSE; fib->count2000 = 0; fib->blength = 56; - fib->bl1 = TRUE; return (TRUE); case BL_FILE_AMOUNT: // il numero dei file nel disco @@ -1036,9 +1090,8 @@ void fds_image_sinfo(BYTE side, _fds_sinfo *sinfo) { memset(sinfo, 0x00, sizeof(_fds_sinfo)); for (position = 0; position < fds_disk_side_size(fds.info.format);) { - BYTE block = src[position]; + BYTE block = src[position], stop = FALSE;; uint32_t blength = 1; - BYTE stop = FALSE; switch (block) { case BL_DISK_INFO: @@ -1086,6 +1139,14 @@ void fds_image_sinfo(BYTE side, _fds_sinfo *sinfo) { sinfo->block1.snumber = src[position + 0x15]; // disk number sinfo->block1.dnumber = src[position + 0x16]; + // manufacturing date + sinfo->block1.manufacturing[0] = src[position + 0x1F]; + sinfo->block1.manufacturing[1] = src[position + 0x20]; + sinfo->block1.manufacturing[2] = src[position + 0x21]; + // rewritten disk date + sinfo->block1.rewritten[0] = src[position + 0x2C]; + sinfo->block1.rewritten[1] = src[position + 0x2D]; + sinfo->block1.rewritten[2] = src[position + 0x2E]; break; case 2: sinfo->block2.position = size; @@ -1152,7 +1213,7 @@ WORD fds_crc_block(const BYTE *src, uint32_t lenght) { BYTE *fds_from_image_to_mem(BYTE format, BYTE type, size_t *size) { BYTE *mfds = NULL; - (*size) = (type == FDS_FORMAT_FDS ? 16 : 0) + fds_disk_side_size(format) * fds.info.total_sides; + (*size) = (type == FDS_TYPE_FDS ? 16 : 0) + fds_disk_side_size(format) * fds.info.total_sides; // alloco la zona di memoria mfds = malloc((*size)); @@ -1162,7 +1223,7 @@ BYTE *fds_from_image_to_mem(BYTE format, BYTE type, size_t *size) { } memset(mfds, 0x00, (*size)); - if (type == FDS_FORMAT_FDS) { + if (type == FDS_TYPE_FDS) { memcpy(&mfds[0], "FDS", 3); mfds[3] = 0x1A; mfds[4] = fds.info.total_sides; @@ -1175,7 +1236,7 @@ BYTE *fds_from_image_to_mem(BYTE format, BYTE type, size_t *size) { _fds_info_block fib = { 0 }; WORD crc = 0; - length = (type == FDS_FORMAT_FDS ? 16 : 0) + (fds_disk_side_size(format) * side); + length = (type == FDS_TYPE_FDS ? 16 : 0) + (fds_disk_side_size(format) * side); for (position = 0; position < fds_image_side_size();) { if ((src[position] == FDS_DISK_GAP) || (src[position] == FDS_DISK_BLOCK_MARK)) { diff --git a/src/core/fds.h b/src/core/fds.h index 6107990cd..1d54340a2 100644 --- a/src/core/fds.h +++ b/src/core/fds.h @@ -21,7 +21,7 @@ #include "common.h" -enum fds_formats { FDS_FORMAT_RAW, FDS_FORMAT_FDS }; +enum fds_formats { FDS_TYPE_RAW, FDS_TYPE_FDS }; enum fds_write_mode { FDS_WR_DIFF_FILE, FDS_WR_ORIGINAL_FILE }; enum fds_operations { FDS_OP_NONE, FDS_OP_READ, FDS_OP_WRITE }; enum fds_disk_operations { @@ -46,9 +46,6 @@ enum fds_block_type { enum fds_misc { FDS_DISK_GAP = 0x00, FDS_DISK_BLOCK_MARK = 0x80, - // Aspic (1988)(Bothtec)(J) necessita di almeno 1500 ms - // Pulsar no Hikari - Space Wars Simulation (Japan) di almeno 1600 ms - FDS_OP_SIDE_MS_DELAY = 1600, FDS_AUTOINSERT_R4032_MAX_CHECKS = 7, FDS_MIN_LAG_FRAMES = 20, FDS_IMAGE_SIDE_SIZE = 75500, @@ -56,8 +53,17 @@ enum fds_misc { DISK_QD_SIDE_SIZE = 65536 }; -// 147 cicli (secondo vari test รจ questo il numero preciso) -#define FDS_8BIT_MS_DELAY 0.0825f +// https://www.chrismcovell.com/fds-lister.html +// The theoretical ideal data rate for FDS disks is said to be 96400 bits per second, or 12050 bytes/sec. +// Inverted, that's 1 byte every 82.988 microseconds. With the Famicom CPU having a clock period of 559 ns/cycle, +// there should be a new byte coming in to the FDS RAM adaptor every 148.46 (~hex $94) CPU clock cycles. +// At an average of 1 byte every 147-150 CPU cycles that I get on my newly-"calibrated" disk drive, that comes pretty +// close to the ideal data rate of 148 listed above. +#define FDS_8BIT_MS_DELAY 0.082988f +// Aspic (1988)(Bothtec)(J) necessita di almeno 1500 ms +// Pulsar no Hikari - Space Wars Simulation (Japan) di almeno 1600 ms +#define FDS_OP_SIDE_MS_DELAY 1600.0f + #define fds_auto_insert_enabled() (cfg->fds_switch_side_automatically & !fds.auto_insert.disabled & !fds.bios.first_run) #define fds_reset_envelope_counter(env) (fds.snd.envelope.speed << 3) * (fds.snd.env.speed + 1) #define fds_sweep_bias(val) (SBYTE)((val & 0x7F) << 1) / 2; @@ -228,7 +234,8 @@ EXTERNC void fds_init(void); EXTERNC void fds_quit(void); EXTERNC BYTE fds_load_rom(BYTE format); EXTERNC BYTE fds_load_bios(void); -EXTERNC BYTE fds_change_disk(uTCHAR *path); +EXTERNC BYTE fds_create_empty_disk(BYTE format, BYTE type, BYTE double_side, uTCHAR *file); +EXTERNC BYTE fds_change_disk(uTCHAR *file); EXTERNC void fds_info(void); EXTERNC void fds_info_side(BYTE side); EXTERNC void fds_disk_op(WORD type, BYTE side_to_insert, BYTE quiet); diff --git a/src/core/mappers/mapper_FDS.c b/src/core/mappers/mapper_FDS.c index bc7ee34ba..786303797 100644 --- a/src/core/mappers/mapper_FDS.c +++ b/src/core/mappers/mapper_FDS.c @@ -108,7 +108,7 @@ BYTE extcl_cpu_rd_mem_FDS(BYTE nidx, WORD address, UNUSED(BYTE openbus)) { BYTE finded = TRUE; position = (a * fds_disk_side_size(fds.info.format)); - if (fds.info.type == FDS_FORMAT_FDS) { + if (fds.info.type == FDS_TYPE_FDS) { position += 16; } if ((position + fds_disk_side_size(fds.info.format)) > fds.info.total_size) { From e6878b4f7191fe2283aa85f7ae4b114551a4c17a Mon Sep 17 00:00:00 2001 From: Fabio Cavallo Date: Wed, 3 Jan 2024 14:48:57 +0100 Subject: [PATCH 03/10] Ops! --- src/gui/mainWindow.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/gui/mainWindow.cpp b/src/gui/mainWindow.cpp index 859c2e0aa..8bd4de858 100644 --- a/src/gui/mainWindow.cpp +++ b/src/gui/mainWindow.cpp @@ -1669,7 +1669,7 @@ void mainWindow::s_export_fds_image(void) { if (format < 3) { rc = fds_from_image_to_file(uQStringCD(fileinfo.absoluteFilePath()), format == 2 ? QD_FORMAT : FDS_FORMAT, - format == 0 ? FDS_FORMAT_FDS : FDS_FORMAT_RAW); + format == 0 ? FDS_TYPE_FDS : FDS_TYPE_RAW); } else { rc = fds_image_to_file(uQStringCD(fileinfo.absoluteFilePath())); } From 111941e3ad5abff8316cc85c0c62955bcfca1ea7 Mon Sep 17 00:00:00 2001 From: Fabio Cavallo Date: Wed, 3 Jan 2024 15:27:02 +0100 Subject: [PATCH 04/10] Fixed initialization of the "fds.auto_insert" structure when a reset is performed. --- src/core/mappers/mapper_FDS.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/core/mappers/mapper_FDS.c b/src/core/mappers/mapper_FDS.c index 786303797..83c115574 100644 --- a/src/core/mappers/mapper_FDS.c +++ b/src/core/mappers/mapper_FDS.c @@ -37,7 +37,12 @@ void map_init_FDS(void) { EXTCL_CPU_EVERY_CYCLE(FDS); EXTCL_APU_TICK(FDS); - memset (&fds.auto_insert, 0x00, sizeof(fds.auto_insert)); + fds.auto_insert.r4032.checks = 0; + fds.auto_insert.r4032.frames = 0; + fds.auto_insert.delay.dummy = 0; + fds.auto_insert.rE445.in_run = FALSE; + fds.auto_insert.in_game = FALSE; + fds.drive.transfer_reset = 0x02; fds.drive.io_mode = 0x04; fds.drive.drive_ready = 0x40; From 635811660ec04104dfa8ce216668b6b0943b4c63 Mon Sep 17 00:00:00 2001 From: Fabio Cavallo Date: Wed, 3 Jan 2024 18:20:13 +0100 Subject: [PATCH 05/10] Fixed the initialization of save slots and rewind when the disk is changed. I also disabled the 0xF46E routine skipping. --- src/core/fds.c | 8 ++++++++ src/core/mappers/mapper_FDS.c | 14 +++++++------- 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/src/core/fds.c b/src/core/fds.c index f0b409402..9a8ef9014 100644 --- a/src/core/fds.c +++ b/src/core/fds.c @@ -26,6 +26,8 @@ #include "patcher.h" #include "conf.h" #include "emu.h" +#include "rewind.h" +#include "save_slot.h" #include "../../c++/crc/crc.h" #define BIOSFILE "disksys.rom" @@ -467,6 +469,12 @@ BYTE fds_change_disk(uTCHAR *file) { memcpy(&fds.info, &finfo, sizeof(_fds_info)); fds_info(); + if (rewind_init()) { + return (EXIT_ERROR); + } + + save_slot_count_load(); + fds.side.change.new_side = 0; fds.side.change.delay = fds.info.cycles_dummy_delay; fds_disk_op(FDS_DISK_EJECT, 0, FALSE); diff --git a/src/core/mappers/mapper_FDS.c b/src/core/mappers/mapper_FDS.c index 83c115574..88e26ed89 100644 --- a/src/core/mappers/mapper_FDS.c +++ b/src/core/mappers/mapper_FDS.c @@ -179,13 +179,13 @@ BYTE extcl_cpu_rd_mem_FDS(BYTE nidx, WORD address, UNUSED(BYTE openbus)) { address = nes[nidx].c.cpu.PC.w - 1; } break; - case 0xF46E: - // License check - if (cfg->fds_fast_forward) { - nes[nidx].c.cpu.PC.w += 2; - address = nes[nidx].c.cpu.PC.w - 1; - } - break; +// case 0xF46E: +// // License check +// if (cfg->fds_fast_forward) { +// nes[nidx].c.cpu.PC.w += 2; +// address = nes[nidx].c.cpu.PC.w - 1; +// } +// break; } return (prgrom_rd(nidx, address)); } From 9e530749ae4a7cc914d4b4cfceabd084c5c449c1 Mon Sep 17 00:00:00 2001 From: Fabio Cavallo Date: Wed, 3 Jan 2024 20:39:44 +0100 Subject: [PATCH 06/10] Disable auto insert for "Puzzle Boys". --- src/core/fds.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/core/fds.c b/src/core/fds.c index 9a8ef9014..87132a3a3 100644 --- a/src/core/fds.c +++ b/src/core/fds.c @@ -1007,6 +1007,10 @@ void fds_control_autoinsert(_fds_sinfo *sinfo) { { "KOM", { 0xE9A457BF, 0x7791A2DD, 0x00, 0x00 }, TRUE, TRUE, TRUE }, // Koneko Monogatari - The Adventures of Chatran (Japan) (Sample) (1986-07-03) { "KOM", { 0x8C457E04, 0xCB25E05C, 0x00, 0x00 }, TRUE, TRUE, TRUE }, + // Puzzle Boys (Japan) (Disk Writer) + { "PUZ", { 0x2385D83D, 0x64488AFD, 0x00, 0x00 }, TRUE, TRUE, TRUE }, + // Puzzle Boys (Japan) (Disk Writer) [T-En by DvD Translations Rev A] + { "PUZ", { 0x876DD60C, 0xD487A70E, 0x00, 0x00 }, TRUE, TRUE, TRUE }, // Samurai Sword (Japan) { "SMU", { 0xD0B342F5, 0xE46A6E3E, 0x00, 0x00 }, TRUE, TRUE, TRUE }, // Samurai Sword (Japan) [T-En by Mute v1.0] @@ -1025,10 +1029,6 @@ void fds_control_autoinsert(_fds_sinfo *sinfo) { { "EGL", { 0xBB887262, 0xC9915867, 0x00, 0x00 }, FALSE, TRUE, FALSE }, // Igo - Kyuu Roban Taikyoku (Japan) { "IGO", { 0x1E8B0151, 0xF7130E20, 0x00, 0x00 }, FALSE, TRUE, FALSE }, - // Puzzle Boys (Japan) (Disk Writer) - { "PUZ", { 0x2385D83D, 0x64488AFD, 0x00, 0x00 }, FALSE, TRUE, FALSE }, - // Puzzle Boys (Japan) (Disk Writer) [T-En by DvD Translations Rev A] - { "PUZ", { 0x876DD60C, 0xD487A70E, 0x00, 0x00 }, FALSE, TRUE, FALSE }, // Time Twist - Rekishi no Katasumi de (1991)(Nintendo)(J) { "TT1", { 0x6D6014C1, 0x145A90B2, 0xBFB019B9, 0x636083C1 }, FALSE, TRUE, FALSE }, }; From 2ce45cf17d2421c6238a1e44ac8e41c916305568 Mon Sep 17 00:00:00 2001 From: Fabio Cavallo Date: Wed, 3 Jan 2024 21:05:36 +0100 Subject: [PATCH 07/10] Added a warning for "Souseiki Fammy - ROM-QD for 256K+64K (Japan) (Unl)". --- src/core/fds.c | 7 +++++++ src/gui/mainWindow.cpp | 6 ++++++ src/gui/mainWindow.hpp | 1 + src/gui/qt.cpp | 4 ++++ src/gui/qt.h | 2 ++ 5 files changed, 20 insertions(+) diff --git a/src/core/fds.c b/src/core/fds.c index 87132a3a3..f62bd16a2 100644 --- a/src/core/fds.c +++ b/src/core/fds.c @@ -1036,6 +1036,13 @@ void fds_control_autoinsert(_fds_sinfo *sinfo) { fds.auto_insert.r4032.disabled = FALSE; fds.auto_insert.end_of_head.disabled = TRUE; + // Souseiki Fammy - ROM-QD for 256K+64K (Japan) (Unl) + if (!strncmp((char *)&sinfo->block1.name[0], "ILE", 3) && + ((sinfo->crc32prg == 0x01218B9D) || (sinfo->crc32prg == 0xF1BCA55D))) { + fds.auto_insert.disabled = TRUE; + gui_unsupported_hardware(); + return; + } if (fds.info.total_sides == 1) { // auto insert disabilitato fds.auto_insert.disabled = TRUE; diff --git a/src/gui/mainWindow.cpp b/src/gui/mainWindow.cpp index 8bd4de858..8a9926df1 100644 --- a/src/gui/mainWindow.cpp +++ b/src/gui/mainWindow.cpp @@ -856,6 +856,12 @@ void mainWindow::open_dkeyb(BYTE mode) { dlgkeyb->switch_mode(mode); dlgkeyb->show(); } +void mainWindow::unsupported_hardware(void) { + QMessageBox::warning(this, + tr("Warning"), + tr("This rom requires unsupported hardware to function correctly."), + QMessageBox::Ok); +} void mainWindow::connect_menu_signals(void) { // File diff --git a/src/gui/mainWindow.hpp b/src/gui/mainWindow.hpp index 5ec4ac3af..72dea535f 100644 --- a/src/gui/mainWindow.hpp +++ b/src/gui/mainWindow.hpp @@ -240,6 +240,7 @@ class mainWindow : public QMainWindow, public Ui::mainWindow { void shout_into_mic(BYTE mode); void hold_fast_forward(BYTE mode); void open_dkeyb(BYTE mode); + void unsupported_hardware(void); private: void connect_menu_signals(void); diff --git a/src/gui/qt.cpp b/src/gui/qt.cpp index dfdc440fd..29f50b044 100644 --- a/src/gui/qt.cpp +++ b/src/gui/qt.cpp @@ -809,6 +809,10 @@ void gui_detach_barcode_change_rom(void) { qt.dbarcode->change_rom(); } +void gui_unsupported_hardware(void) { + qt.mwin->unsupported_hardware(); +} + #if defined (WITH_OPENGL) void gui_wdgopengl_make_current(void) { if (gui.start) { diff --git a/src/gui/qt.h b/src/gui/qt.h index 171a14c04..31e5c184f 100644 --- a/src/gui/qt.h +++ b/src/gui/qt.h @@ -297,6 +297,8 @@ EXTERNC void gui_vs_system_insert_coin(void); EXTERNC void gui_detach_barcode_change_rom(void); +EXTERNC void gui_unsupported_hardware(void); + EXTERNC void gui_nes_keyboard(void); EXTERNC void gui_nes_keyboard_paste_event(void); EXTERNC void gui_nes_keyboard_frame_finished(void); From 56f4ddd79afc84713992fa2ff07eb2bd89ee4d60 Mon Sep 17 00:00:00 2001 From: Fabio Cavallo Date: Thu, 4 Jan 2024 12:02:28 +0100 Subject: [PATCH 08/10] Fixed Meta button recognition on some keyboard layouts (#359). --- src/gui/objSettings.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/gui/objSettings.cpp b/src/gui/objSettings.cpp index add56ee28..fcfa0f218 100644 --- a/src/gui/objSettings.cpp +++ b/src/gui/objSettings.cpp @@ -83,6 +83,8 @@ static const struct _kv_specials { { 0, Qt::AltModifier, Qt::Key_Alt, "Alt", 273 }, { 0, Qt::NoModifier, Qt::Key_AltGr, "AltGr", 274 }, { 0, Qt::MetaModifier, Qt::Key_Meta, "Meta", 275 }, + { 0, Qt::MetaModifier, Qt::Key_Super_L, "Meta", 275 }, + { 0, Qt::MetaModifier, Qt::Key_Super_R, "Meta", 275 }, { 0, Qt::ShiftModifier, Qt::Key_Shift, "LShift", 276 }, { 0, Qt::ShiftModifier, Qt::Key_Shift, "RShift", 277 }, { 0, Qt::ControlModifier, Qt::Key_Control, "LCtrl", 278 }, @@ -91,6 +93,8 @@ static const struct _kv_specials { { 0, Qt::NoModifier, Qt::Key_Alt, "Alt", 273 }, { 0, Qt::NoModifier, Qt::Key_AltGr, "AltGr", 274 }, { 0, Qt::NoModifier, Qt::Key_Meta, "Meta", 275 }, + { 0, Qt::NoModifier, Qt::Key_Super_L, "Meta", 275 }, + { 0, Qt::NoModifier, Qt::Key_Super_R, "Meta", 275 }, { XK_Shift_L, {}, Qt::Key_Shift, "LShift", 276 }, { XK_Shift_R, {}, Qt::Key_Shift, "RShift", 277 }, { XK_Control_L, {}, Qt::Key_Control, "LCtrl", 278 }, From 8e4c4918654def6d2e2e0569a70f8a281e71d70f Mon Sep 17 00:00:00 2001 From: Fabio Cavallo Date: Thu, 4 Jan 2024 13:58:12 +0100 Subject: [PATCH 09/10] Disabled auto insert also for the FDS that contains "Disk 1" and "Disk 2" in the name. --- src/core/fds.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/core/fds.c b/src/core/fds.c index f62bd16a2..4db15fce7 100644 --- a/src/core/fds.c +++ b/src/core/fds.c @@ -1055,7 +1055,8 @@ void fds_control_autoinsert(_fds_sinfo *sinfo) { gui_overlay_info_append_msg_precompiled(39, NULL); return; } - if (ustrstr(info.rom.file, uL(" Zenpen ")) || ustrstr(info.rom.file, uL(" Kouhen "))) { + if (ustrstr(info.rom.file, uL("Zenpen")) || ustrstr(info.rom.file, uL("Kouhen")) || + ustrstr(info.rom.file, uL("Disk 1")) || ustrstr(info.rom.file, uL("Disk 2"))) { // auto insert disabilitato fds.auto_insert.disabled = TRUE; gui_overlay_info_append_msg_precompiled(39, NULL); From 48a1ad2c1a756ee103af9f58b730686ea903781b Mon Sep 17 00:00:00 2001 From: Fabio Cavallo Date: Thu, 4 Jan 2024 16:57:40 +0100 Subject: [PATCH 10/10] Fixed zip file handling on BSD systems. --- src/core/uncompress.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/core/uncompress.c b/src/core/uncompress.c index 75b6a4a03..ebf5e0d1a 100644 --- a/src/core/uncompress.c +++ b/src/core/uncompress.c @@ -43,7 +43,7 @@ static uTCHAR *(*uncompress_item_file_name)(_uncompress_archive *archive, uint32 // zip static BYTE mz_zip_examine_archive(_uncompress_archive *archive); static BYTE mz_zip_extract_from_archive(_uncompress_archive *archive, uint32_t selected, BYTE type); -static uTCHAR *mz_zip_item_file_name(_uncompress_archive *archive, uint32_t selected, BYTE type); +static char *mz_zip_item_file_name(_uncompress_archive *archive, uint32_t selected, BYTE type); #endif _uncompress_storage uncstorage; @@ -360,7 +360,7 @@ static BYTE mz_zip_examine_archive(_uncompress_archive *archive) { } static BYTE mz_zip_extract_from_archive(_uncompress_archive *archive, uint32_t selected, BYTE type) { mz_zip_archive mzarchive; - uTCHAR file[LENGTH_FILE_NAME_LONG]; + char file[LENGTH_FILE_NAME_LONG], basename[255]; _uncompress_archive_item *aitem = NULL; aitem = uncompress_archive_find_item(archive, selected, type); @@ -377,7 +377,8 @@ static BYTE mz_zip_extract_from_archive(_uncompress_archive *archive, uint32_t s mz_zip_reader_get_filename(&mzarchive, aitem->index, file, sizeof(file)); - snprintf(file, sizeof(file), "%s/%s", gui_temp_folder(), basename(file)); + gui_utf_basename(&file[0], basename, sizeof(basename)); + snprintf(file, sizeof(file), "%s/%s", gui_temp_folder(), basename); if (!mz_zip_reader_extract_to_file(&mzarchive, aitem->index, file, 0)) { log_error(uL("uncompress;unzip file failed!")); @@ -409,8 +410,8 @@ static BYTE mz_zip_extract_from_archive(_uncompress_archive *archive, uint32_t s return (UNCOMPRESS_EXIT_OK); } -static uTCHAR *mz_zip_item_file_name(_uncompress_archive *archive, uint32_t selected, BYTE type) { - static uTCHAR file[LENGTH_FILE_NAME_LONG]; +static char *mz_zip_item_file_name(_uncompress_archive *archive, uint32_t selected, BYTE type) { + static char file[LENGTH_FILE_NAME_LONG]; mz_zip_archive mzarchive; _uncompress_archive_item *aitem = NULL;