From da9e8392e5d4d57fe8287f554aae8fc6c3384f5a Mon Sep 17 00:00:00 2001 From: Jason Carr Date: Thu, 19 Feb 2026 23:26:03 -0500 Subject: [PATCH 1/2] Fix USCF Chess and Land Battle: enable D000-D3FF RAM 8 USCF Chess (1981) and Land Battle (1982) both use load method 4, which requires 8-bit RAM at \-\. writeMem() was silently discarding all writes to this range, causing the game's CPU to be unable to store piece positions, BACKTAB data, or working variables. This produced completely garbled graphics (GROM character garbage instead of chess pieces/board tiles). Fix: - Add d000_ram flag to memory.h/memory.c - writeMem: allow 8-bit writes to \-\ when d000_ram is set - readMem: mask reads from \-\ to 8 bits when d000_ram is set - d000_ram is reset at start of MemoryInit() (on each cart load) - load4() in cart.c now sets d000_ram = 1 instead of the TODO comment Also fix C89 compliance in stic.c: replace // comments with /* */ Fixes: https://github.com/libretro/FreeIntv/issues/96 --- src/cart.c | 2 +- src/memory.c | 18 +++++++++++++++--- src/memory.h | 2 ++ src/stic.c | 4 ++-- 4 files changed, 20 insertions(+), 6 deletions(-) diff --git a/src/cart.c b/src/cart.c index 70ae658..9b42e62 100644 --- a/src/cart.c +++ b/src/cart.c @@ -209,7 +209,7 @@ void load3() void load4() { loadRange(0x5000, 0x6FFF); - // [memattr] $D000 - $D3FF = RAM 8 // automatic + d000_ram = 1; /* $D000-$D3FF = RAM 8 */ } void load5() diff --git a/src/memory.c b/src/memory.c index 0b08118..864f27e 100644 --- a/src/memory.c +++ b/src/memory.c @@ -25,6 +25,8 @@ unsigned int Memory[0x10000]; +int d000_ram = 0; /* 1 = $D000-$D3FF is 8-bit RAM (e.g. USCF Chess) */ + int stic_and[64] = { 0x07ff, 0x07ff, 0x07ff, 0x07ff, 0x07ff, 0x07ff, 0x07ff, 0x07ff, 0x0fff, 0x0fff, 0x0fff, 0x0fff, 0x0fff, 0x0fff, 0x0fff, 0x0fff, @@ -66,6 +68,10 @@ void writeMem(int adr, int val) // Write (should handle hooks/alias) case 0x15: /* A800-AFFF */ case 0x16: /* B000-B7FF */ case 0x1a: /* D000-D7FF */ + if (d000_ram && adr <= 0xD3FF) { + Memory[adr] = val & 0xFF; /* RAM 8 */ + } + return; case 0x1b: /* D800-DFFF */ case 0x1c: /* E000-E7FF */ case 0x1d: /* E800-EFFF */ @@ -146,13 +152,19 @@ int readMem(int adr) // Read (should handle hooks/alias) val = val & 0xFF; } + if(d000_ram && adr>=0xD000 && adr<=0xD3FF) + { + val = val & 0xFF; /* RAM 8 */ + } + return val; } void MemoryInit() { int i; - for(i=0x0000; i<=0x0007; i++) { Memory[i] = 0x3800; } // STIC Registers + d000_ram = 0; /* reset per-cart flags before loading new cart */ + for(i=0x0000; i<=0x0007; i++) { Memory[i] = 0x3800; } /* STIC Registers */ for(i=0x0008; i<=0x000F; i++) { Memory[i] = 0x3000; } for(i=0x0010; i<=0x0017; i++) { Memory[i] = 0x0000; } for(i=0x0018; i<=0x001F; i++) { Memory[i] = 0x3C00; } @@ -171,6 +183,6 @@ void MemoryInit() for(i=0x4000; i<=0x4FFF; i++) { Memory[i] = 0xFFFF; } for(i=0x5000; i<=0x5FFF; i++) { Memory[i] = 0x0000; } for(i=0x6000; i<=0xFFFF; i++) { Memory[i] = 0xFFFF; } - Memory[0x1FE] = 0xFF; // Controller R - Memory[0x1FF] = 0xFF; // Controller L + Memory[0x1FE] = 0xFF; /* Controller R */ + Memory[0x1FF] = 0xFF; /* Controller L */ } diff --git a/src/memory.h b/src/memory.h index 27e2c08..d9ab6a9 100644 --- a/src/memory.h +++ b/src/memory.h @@ -20,6 +20,8 @@ extern unsigned int Memory[0x10000]; +extern int d000_ram; /* 1 = $D000-$D3FF is 8-bit RAM (e.g. USCF Chess) */ + void MemoryInit(void); int readMem(int adr); diff --git a/src/stic.c b/src/stic.c index c90b761..b2e9e64 100644 --- a/src/stic.c +++ b/src/stic.c @@ -361,9 +361,9 @@ void drawBackgroundColorStack(int scanline) fgcolor = fgcard[col]; bgcolor = bgcard[col]; - if (((card >> 11) & 0x01) != 0) // Limit GRAM to 64 cards + if (((card >> 11) & 0x01) != 0) /* Card is from GRAM - limit to 64 cards */ gaddress = 0x3000 + (card & 0x09f8); - else + else /* Card is from GROM */ gaddress = 0x3000 + (card & 0x0ff8); gdata = Memory[gaddress + cardrow]; // fetch current line of current card graphic From c2cf609dbd112a40fb63a223adc9cc1565a09690 Mon Sep 17 00:00:00 2001 From: Jason Carr Date: Fri, 20 Feb 2026 00:19:22 -0500 Subject: [PATCH 2/2] Add screenshots/Thumbs.db to .gitignore --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 64de59a..f127d4e 100644 --- a/.gitignore +++ b/.gitignore @@ -39,3 +39,4 @@ build-test.ps1 *.temp *.log Assets/Thumbs.db +screenshots/Thumbs.db