From b815f5e326990b8bd242e37acc165feb4e4e52a3 Mon Sep 17 00:00:00 2001 From: nexus4880 <38168516+nexus4880@users.noreply.github.com> Date: Wed, 26 Feb 2025 18:59:50 -0700 Subject: [PATCH 1/3] Added check for null terminated string in title --- src/DMG/MBC.cs | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/src/DMG/MBC.cs b/src/DMG/MBC.cs index bcde34b..24caeb7 100644 --- a/src/DMG/MBC.cs +++ b/src/DMG/MBC.cs @@ -1,3 +1,5 @@ +using System.Text; + class MBC { //MBC is currently only experimental //MBC0/ROM Only should be good @@ -106,17 +108,17 @@ private int CalculateRomSize(byte headerValue) { } public string GetTitle() { - byte[] titleBytes = new byte[16]; - Array.Copy(rom, 0x0134, titleBytes, 0, 16); - - string title = System.Text.Encoding.ASCII.GetString(titleBytes).TrimEnd(null); - - if (title.Length > 16) + int titleStart = 0x0134; + int titleLength; + for (titleLength = 0; titleLength < 16; titleLength++) { - title = title.Substring(0, 16); + if (rom[titleStart + titleLength] == 0) + { + break; + } } - - return "Title: " + title; + string title = Encoding.ASCII.GetString(rom, titleStart, titleLength); + return title; } public string GetCartridgeType() { From 43dd8bbcc353096b562cf52683ee4d9b0560005d Mon Sep 17 00:00:00 2001 From: nexus4880 <38168516+nexus4880@users.noreply.github.com> Date: Wed, 26 Feb 2025 19:01:26 -0700 Subject: [PATCH 2/3] Updated braces to match your style --- src/DMG/MBC.cs | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/DMG/MBC.cs b/src/DMG/MBC.cs index 24caeb7..82f50e0 100644 --- a/src/DMG/MBC.cs +++ b/src/DMG/MBC.cs @@ -110,10 +110,8 @@ private int CalculateRomSize(byte headerValue) { public string GetTitle() { int titleStart = 0x0134; int titleLength; - for (titleLength = 0; titleLength < 16; titleLength++) - { - if (rom[titleStart + titleLength] == 0) - { + for (titleLength = 0; titleLength < 16; titleLength++) { + if (rom[titleStart + titleLength] == 0) { break; } } From 831fc8ca52dccbc895b229780052f79307a0db06 Mon Sep 17 00:00:00 2001 From: nexus4880 <38168516+nexus4880@users.noreply.github.com> Date: Wed, 26 Feb 2025 19:12:17 -0700 Subject: [PATCH 3/3] I had forgotten to prefix the title with "Title: " --- src/DMG/MBC.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/DMG/MBC.cs b/src/DMG/MBC.cs index 82f50e0..7acc2bd 100644 --- a/src/DMG/MBC.cs +++ b/src/DMG/MBC.cs @@ -116,7 +116,7 @@ public string GetTitle() { } } string title = Encoding.ASCII.GetString(rom, titleStart, titleLength); - return title; + return $"Title: {title}"; } public string GetCartridgeType() {