From 80032f8f841ce255ba830c9d8525843611f6165b Mon Sep 17 00:00:00 2001 From: Alexey 'Cluster' Avdyukhin Date: Tue, 7 Sep 2021 20:39:13 +0300 Subject: [PATCH] NES 2.0 exponent-multiplier notation support --- src/ines.cpp | 40 ++++++++++++++++++++++++++++++---------- 1 file changed, 30 insertions(+), 10 deletions(-) diff --git a/src/ines.cpp b/src/ines.cpp index 35123667..5c1dffe3 100644 --- a/src/ines.cpp +++ b/src/ines.cpp @@ -766,8 +766,18 @@ int iNESLoad(const char *name, FCEUFILE *fp, int OverwriteVidMode) { } else Mirroring = (head.ROM_type & 1); - int not_round_size = head.ROM_size; - if(iNES2) not_round_size |= ((head.Upper_ROM_VROM_size & 0x0F) << 8); + int not_round_size; + if (!iNES2) { + not_round_size = head.ROM_size; + } + else { + if ((head.Upper_ROM_VROM_size & 0x0F) != 0x0F) + // simple notation + not_round_size = head.ROM_size | ((head.Upper_ROM_VROM_size & 0x0F) << 8); + else + // exponent-multiplier notation + not_round_size = ((1 << (head.ROM_size >> 2)) * ((head.ROM_size & 0b11) * 2 + 1)) >> 14; + } if (!head.ROM_size && !iNES2) ROM_size = 256; @@ -775,6 +785,16 @@ int iNESLoad(const char *name, FCEUFILE *fp, int OverwriteVidMode) { ROM_size = uppow2(not_round_size); VROM_size = uppow2(head.VROM_size | (iNES2?((head.Upper_ROM_VROM_size & 0xF0)<<4):0)); + if (!iNES2) { + VROM_size = head.VROM_size; + } + else { + if ((head.Upper_ROM_VROM_size & 0xF0) != 0xF0) + // simple notation + VROM_size = uppow2(head.VROM_size | ((head.Upper_ROM_VROM_size & 0xF0) << 4)); + else + VROM_size = ((1 << (head.VROM_size >> 2)) * ((head.VROM_size & 0b11) * 2 + 1)) >> 13; + } int round = true; for (int i = 0; i != sizeof(not_power2) / sizeof(not_power2[0]); ++i) { @@ -832,9 +852,9 @@ int iNESLoad(const char *name, FCEUFILE *fp, int OverwriteVidMode) { iNESCart.CRC32 = iNESGameCRC32; - FCEU_printf(" PRG ROM: %3d x 16KiB\n", (round) ? ROM_size: not_round_size); - FCEU_printf(" CHR ROM: %3d x 8KiB\n", head.VROM_size); - FCEU_printf(" ROM CRC32: 0x%08lx\n", iNESGameCRC32); + FCEU_printf(" PRG ROM: %d x 16KiB = %d KiB\n", round ? ROM_size : not_round_size, (round ? ROM_size : not_round_size) * 16); + FCEU_printf(" CHR ROM: %d x 8KiB = %d KiB\n", VROM_size, VROM_size * 8); + FCEU_printf(" ROM CRC32: 0x%08lx\n", iNESGameCRC32); { int x; FCEU_printf(" ROM MD5: 0x"); @@ -852,7 +872,7 @@ int iNESLoad(const char *name, FCEUFILE *fp, int OverwriteVidMode) { } } - FCEU_printf(" Mapper #: %d\n", MapperNo); + FCEU_printf(" Mapper #: %d\n", MapperNo); FCEU_printf(" Mapper name: %s\n", mappername); FCEU_printf(" Mirroring: %s\n", Mirroring == 2 ? "None (Four-screen)" : Mirroring ? "Vertical" : "Horizontal"); FCEU_printf(" Battery-backed: %s\n", (head.ROM_type & 2) ? "Yes" : "No"); @@ -861,12 +881,12 @@ int iNESLoad(const char *name, FCEUFILE *fp, int OverwriteVidMode) { { FCEU_printf(" NES2.0 Extensions\n"); FCEU_printf(" Sub Mapper #: %d\n", iNESCart.submapper); - FCEU_printf(" Total WRAM size: %d\n", iNESCart.wram_size + iNESCart.battery_wram_size); - FCEU_printf(" Total VRAM size: %d\n", iNESCart.vram_size + iNESCart.battery_vram_size); + FCEU_printf(" Total WRAM size: %d KiB\n", (iNESCart.wram_size + iNESCart.battery_wram_size) / 1024); + FCEU_printf(" Total VRAM size: %d KiB\n", (iNESCart.vram_size + iNESCart.battery_vram_size) / 1024); if(head.ROM_type & 2) { - FCEU_printf(" WRAM backed by battery: %d\n", iNESCart.battery_wram_size); - FCEU_printf(" VRAM backed by battery: %d\n", iNESCart.battery_vram_size); + FCEU_printf(" WRAM backed by battery: %d KiB\n", iNESCart.battery_wram_size / 1024); + FCEU_printf(" VRAM backed by battery: %d KiB\n", iNESCart.battery_vram_size / 1024); } }