From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on inbox.vuxu.org X-Spam-Level: X-Spam-Status: No, score=0.2 required=5.0 tests=DKIM_INVALID,DKIM_SIGNED, T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.4 Received: (qmail 22242 invoked from network); 9 Feb 2022 01:18:01 -0000 Received: from 4ess.inri.net (216.126.196.42) by inbox.vuxu.org with ESMTPUTF8; 9 Feb 2022 01:18:01 -0000 Received: from wopr.sciops.net ([216.126.196.60]) by 4ess; Tue Feb 8 20:12:03 -0500 2022 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sciops.net; s=20210706; t=1644369117; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=ivuPnn4S0e6tQtkCaVUkvsOOQ++DXBK1KTWO/yAwJWE=; b=WRKAqjH8sO4+xPZxPnvEVb71F0sJTAh9obgr9xRWJEvkXROcYI2o8/ZjZkoJ3x6ypSe+U+ PkIMCAlpnvc8PdplgAOMKafxMzd75nW8To1VjcuXRmUPYZZPgV8jR4agsTYxSBHiCkv7bC xb6eP+LQURRx6+Is8kgyZgWNkWrXpRA= Received: by wopr.sciops.net (OpenSMTPD) with ESMTPSA id c399615b (TLSv1.2:ECDHE-RSA-CHACHA20-POLY1305:256:NO) for <9front@9front.org>; Tue, 8 Feb 2022 17:11:56 -0800 (PST) Message-ID: Date: Wed, 09 Feb 2022 02:11:53 +0100 From: qwx@sciops.net To: 9front@9front.org MIME-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 8bit List-ID: <9front.9front.org> List-Help: X-Glyph: ➈ X-Bullshit: deep-learning HTTP over YAML rails-scale NoSQL enhancement Subject: [9front] gba: fix flash chip id for 128k and add setting Reply-To: 9front@9front.org Precedence: bulk Hello, Some gba cartridges use flash chips produced by a few different manufacturers for backup memory. A game rom may then try to read the device id for its flash chip and break if it's the wrong one. There's no way for us to know which chip is supposed to be there, save for looking it up in some database. These chips are either 64k or 128k big. gba(1) hardcodes the id for the SST 64k chip, but games like the Pokémon ones use a 128k Macronix chip and expect a different id, completely breaking them. This patch sets a different default for 128k flash backups, and gives the ability to set the exact type when creating the save file if it's really necessary. This new default fixes the Pokémons. The type is saved in the save file, but this will *not* break existing ones. It may be that we don't need to worry about the type and just have an id that corresponds to the right chip size, which is why these defaults make sense, but I haven't tested more than a dozen roms, mostly since I don't really know which games use 128k flash. Thoughts/comments? Thanks, qwx diff 4ab2d149d46c6762c9b8d9fd24d0bf92b10704f6 uncommitted --- a//sys/man/1/nintendo +++ b//sys/man/1/nintendo @@ -112,6 +112,10 @@ .TP .B -s Save format used by the original game. Valid formats are: eeprom4, eeprom64, sram256, flash512, flash1024. The number corresponds to the size, in kilobits, of the save file. By default, the emulator attempts to automatically detect the save format, but does not always succeed. +Some roms require a specific flash device id which may need to be set manually for them to work. +Valid formats and corresponding ids are: +flash512 (SST), flash512mx (Macronix 64K), flash512pan (Panasonic), flash512atm (Atmel), +flash1024 (Macronix 128K), flash1024san (Sanyo). .PP .B nes options: --- a/sys/src/games/gba/dat.h +++ b/sys/src/games/gba/dat.h @@ -9,6 +9,7 @@ extern u16int reg[]; extern uchar *rom, *back; extern int nrom, nback, backup; +extern int flashid; extern int hblank, ppuy; --- a/sys/src/games/gba/gba.c +++ b/sys/src/games/gba/gba.c @@ -15,6 +15,15 @@ char *biosfile = "/sys/games/lib/gbabios.bin"; +enum { + IDSST = 0xd4bf, + IDMacronix64 = 0x1cc2, + IDPanasonic = 0x1b32, + IDAtmel = 0x3d1f, + IDSanyo = 0x1362, + IDMacronix128 = 0x09c2, +}; + void writeback(void) { @@ -65,10 +74,12 @@ if(v == s3.u){ if(memcmp(p - 1, "FLASH_V", 7) == 0 || memcmp(p - 1, "FLASH512_V", 10) == 0){ *size = 64*KB; + flashid = IDSST; return FLASH; } if(memcmp(p - 1, "FLASH1M_V", 9) == 0){ *size = 128*KB; + flashid = IDMacronix128; return FLASH; } } @@ -90,10 +101,28 @@ return SRAM; }else if(strcmp(s, "flash512") == 0){ *size = 64*KB; + flashid = IDSST; return FLASH; + }else if(strcmp(s, "flash512mx") == 0){ + *size = 64*KB; + flashid = IDMacronix64; + return FLASH; + }else if(strcmp(s, "flash512pan") == 0){ + *size = 64*KB; + flashid = IDPanasonic; + return FLASH; + }else if(strcmp(s, "flash512atm") == 0){ + *size = 64*KB; + flashid = IDAtmel; + return FLASH; }else if(strcmp(s, "flash1024") == 0){ *size = 128*KB; + flashid = IDMacronix128; return FLASH; + }else if(strcmp(s, "flash1024san") == 0){ + *size = 128*KB; + flashid = IDSanyo; + return FLASH; }else return NOBACK; } @@ -101,7 +130,8 @@ void typename(char *s, int type, int size) { - char *st; + char *st, *id; + id = ""; switch(type){ case EEPROM: st = "eeprom"; @@ -108,6 +138,12 @@ break; case FLASH: st = "flash"; + switch(flashid){ + case IDMacronix64: id = "mx"; break; + case IDPanasonic: id = "pan"; break; + case IDAtmel: id = "atm"; break; + case IDSanyo: id = "san"; break; + } break; case SRAM: st = "sram"; @@ -116,7 +152,7 @@ sysfatal("typestr: unknown type %d -- shouldn't happen", type); return; } - snprint(s, BACKTYPELEN, "%s%d", st, size/128); + snprint(s, BACKTYPELEN, "%s%d%s", st, size/128, id); } void --- a/sys/src/games/gba/mem.c +++ b/sys/src/games/gba/mem.c @@ -572,7 +572,7 @@ } } -int flashstate, flashmode, flashbank; +int flashstate, flashmode, flashbank, flashid; enum { FLASHCMD0, @@ -589,7 +589,7 @@ flashread(u16int a) { if((flashmode & FLASHID) != 0) - return (a & 1) != 0 ? 0xd4 : 0xbf; + return (a & 1) != 0 ? flashid >> 8 : flashid; return back[(flashbank << 16) + a]; }