Skip to content

Commit da9e839

Browse files
committed
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: #96
1 parent df5a531 commit da9e839

File tree

4 files changed

+20
-6
lines changed

4 files changed

+20
-6
lines changed

src/cart.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ void load3()
209209
void load4()
210210
{
211211
loadRange(0x5000, 0x6FFF);
212-
// [memattr] $D000 - $D3FF = RAM 8 // automatic
212+
d000_ram = 1; /* $D000-$D3FF = RAM 8 */
213213
}
214214

215215
void load5()

src/memory.c

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@
2525

2626
unsigned int Memory[0x10000];
2727

28+
int d000_ram = 0; /* 1 = $D000-$D3FF is 8-bit RAM (e.g. USCF Chess) */
29+
2830
int stic_and[64] = {
2931
0x07ff, 0x07ff, 0x07ff, 0x07ff, 0x07ff, 0x07ff, 0x07ff, 0x07ff,
3032
0x0fff, 0x0fff, 0x0fff, 0x0fff, 0x0fff, 0x0fff, 0x0fff, 0x0fff,
@@ -66,6 +68,10 @@ void writeMem(int adr, int val) // Write (should handle hooks/alias)
6668
case 0x15: /* A800-AFFF */
6769
case 0x16: /* B000-B7FF */
6870
case 0x1a: /* D000-D7FF */
71+
if (d000_ram && adr <= 0xD3FF) {
72+
Memory[adr] = val & 0xFF; /* RAM 8 */
73+
}
74+
return;
6975
case 0x1b: /* D800-DFFF */
7076
case 0x1c: /* E000-E7FF */
7177
case 0x1d: /* E800-EFFF */
@@ -146,13 +152,19 @@ int readMem(int adr) // Read (should handle hooks/alias)
146152
val = val & 0xFF;
147153
}
148154

155+
if(d000_ram && adr>=0xD000 && adr<=0xD3FF)
156+
{
157+
val = val & 0xFF; /* RAM 8 */
158+
}
159+
149160
return val;
150161
}
151162

152163
void MemoryInit()
153164
{
154165
int i;
155-
for(i=0x0000; i<=0x0007; i++) { Memory[i] = 0x3800; } // STIC Registers
166+
d000_ram = 0; /* reset per-cart flags before loading new cart */
167+
for(i=0x0000; i<=0x0007; i++) { Memory[i] = 0x3800; } /* STIC Registers */
156168
for(i=0x0008; i<=0x000F; i++) { Memory[i] = 0x3000; }
157169
for(i=0x0010; i<=0x0017; i++) { Memory[i] = 0x0000; }
158170
for(i=0x0018; i<=0x001F; i++) { Memory[i] = 0x3C00; }
@@ -171,6 +183,6 @@ void MemoryInit()
171183
for(i=0x4000; i<=0x4FFF; i++) { Memory[i] = 0xFFFF; }
172184
for(i=0x5000; i<=0x5FFF; i++) { Memory[i] = 0x0000; }
173185
for(i=0x6000; i<=0xFFFF; i++) { Memory[i] = 0xFFFF; }
174-
Memory[0x1FE] = 0xFF; // Controller R
175-
Memory[0x1FF] = 0xFF; // Controller L
186+
Memory[0x1FE] = 0xFF; /* Controller R */
187+
Memory[0x1FF] = 0xFF; /* Controller L */
176188
}

src/memory.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020

2121
extern unsigned int Memory[0x10000];
2222

23+
extern int d000_ram; /* 1 = $D000-$D3FF is 8-bit RAM (e.g. USCF Chess) */
24+
2325
void MemoryInit(void);
2426

2527
int readMem(int adr);

src/stic.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -361,9 +361,9 @@ void drawBackgroundColorStack(int scanline)
361361
fgcolor = fgcard[col];
362362
bgcolor = bgcard[col];
363363

364-
if (((card >> 11) & 0x01) != 0) // Limit GRAM to 64 cards
364+
if (((card >> 11) & 0x01) != 0) /* Card is from GRAM - limit to 64 cards */
365365
gaddress = 0x3000 + (card & 0x09f8);
366-
else
366+
else /* Card is from GROM */
367367
gaddress = 0x3000 + (card & 0x0ff8);
368368

369369
gdata = Memory[gaddress + cardrow]; // fetch current line of current card graphic

0 commit comments

Comments
 (0)