Skip to content

Commit a311b3b

Browse files
Change up AppleII's "main ram" domain, add aux ram domain
The main ram previously seemed to just be a slice of the system bus between 0 - 0xbfff. this posed two problems: that area is banked, and that area could represent main ram or aux ram. main ram now represents all of the ram main ram can possible represent, ordered like how the core orders it (which the way it does it happens to be very natural in any case), and a new aux ram domain does the same thing but with aux ram Also some other changes put in so Rider wouldn't error on building Virtu
1 parent 333fd6d commit a311b3b

File tree

6 files changed

+107
-11
lines changed

6 files changed

+107
-11
lines changed

ExternalCoreProjects/Virtu/DiskDsk.cs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
namespace Jellyfish.Virtu
44
{
55
// ReSharper disable once UnusedMember.Global
6-
internal enum SectorSkew { None = 0, Dos, ProDos };
6+
internal enum SectorSkew { None = 0, Dos, ProDos }
77

88
internal sealed class DiskDsk : Disk525
99
{
@@ -314,6 +314,8 @@ private void WriteDataNibbles(int sectorOffset)
314314
0xED, 0xEE, 0xEF, 0xF2, 0xF3, 0xF4, 0xF5, 0xF6, 0xF7, 0xF9, 0xFA, 0xFB, 0xFC, 0xFD, 0xFE, 0xFF
315315
};
316316

317+
#pragma warning disable SA1137
318+
317319
private static readonly byte[] NibbleToByte =
318320
{
319321
// padding for offset (not used)
@@ -329,13 +331,15 @@ private void WriteDataNibbles(int sectorOffset)
329331
0x90, 0x91, 0x92, 0x93, 0x94, 0x95,
330332

331333
// nibble translate table
332-
0x00, 0x01, 0x98, 0x99, 0x02, 0x03, 0x9C, 0x04, 0x05, 0x06,
334+
0x00, 0x01, 0x98, 0x99, 0x02, 0x03, 0x9C, 0x04, 0x05, 0x06,
333335
0xA0, 0xA1, 0xA2, 0xA3, 0xA4, 0xA5, 0x07, 0x08, 0xA8, 0xA9, 0xAA, 0x09, 0x0A, 0x0B, 0x0C, 0x0D,
334336
0xB0, 0xB1, 0x0E, 0x0F, 0x10, 0x11, 0x12, 0x13, 0xB8, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1A,
335337
0xC0, 0xC1, 0xC2, 0xC3, 0xC4, 0xC5, 0xC6, 0xC7, 0xC8, 0xC9, 0xCA, 0x1B, 0xCC, 0x1C, 0x1D, 0x1E,
336338
0xD0, 0xD1, 0xD2, 0x1F, 0xD4, 0xD5, 0x20, 0x21, 0xD8, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28,
337339
0xE0, 0xE1, 0xE2, 0xE3, 0xE4, 0x29, 0x2A, 0x2B, 0xE8, 0x2C, 0x2D, 0x2E, 0x2F, 0x30, 0x31, 0x32,
338340
0xF0, 0xF1, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0xF8, 0x39, 0x3A, 0x3B, 0x3C, 0x3D, 0x3E, 0x3F
339341
};
342+
343+
#pragma warning restore SA1137
340344
}
341345
}

ExternalCoreProjects/Virtu/MachineEvents.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,10 @@ public void Sync(IComponentSerializer ser)
3737
{
3838
if (ser.IsReader)
3939
{
40-
int[] usedDelta = new int[0];
41-
int[] usedType = new int[0];
42-
int[] freeDelta = new int[0];
43-
int[] freeType = new int[0];
40+
int[] usedDelta = Array.Empty<int>();
41+
int[] usedType = Array.Empty<int>();
42+
int[] freeDelta = Array.Empty<int>();
43+
int[] freeType = Array.Empty<int>();
4444

4545
ser.Sync("UsedDelta", ref usedDelta, false);
4646
ser.Sync("UsedType", ref usedType, false);

ExternalCoreProjects/Virtu/Memory.cs

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -334,6 +334,80 @@ public void WriteZeroPage(int address, int data)
334334
_zeroPage[address] = (byte)data;
335335
}
336336

337+
public byte PeekMainRam(int address)
338+
{
339+
return address switch
340+
{
341+
> 0 and < 0x0200 => _ramMainRegion0001[address - 0],
342+
> 0x0200 and < 0xC000 => _ramMainRegion02BF[address - 0x0200],
343+
> 0xC000 and < 0xD000 => _ramMainBank1RegionD0DF[address - 0xC000],
344+
> 0xD000 and < 0xE000 => _ramMainBank2RegionD0DF[address - 0xD000],
345+
> 0xE000 and < 0x10000 => _ramMainRegionE0FF[address - 0xE000],
346+
_ => throw new InvalidOperationException()
347+
};
348+
}
349+
350+
public void PokeMainRam(int address, byte value)
351+
{
352+
switch (address)
353+
{
354+
case > 0 and < 0x0200:
355+
_ramMainRegion0001[address - 0] = value;
356+
break;
357+
case > 0x0200 and < 0xC000:
358+
_ramMainRegion02BF[address - 0x0200] = value;
359+
break;
360+
case > 0xC000 and < 0xD000:
361+
_ramMainBank1RegionD0DF[address - 0xC000] = value;
362+
break;
363+
case > 0xD000 and < 0xE000:
364+
_ramMainBank2RegionD0DF[address - 0xD000] = value;
365+
break;
366+
case > 0xE000 and < 0x10000:
367+
_ramMainRegionE0FF[address - 0xE000] = value;
368+
break;
369+
default:
370+
throw new InvalidOperationException();
371+
}
372+
}
373+
374+
public byte PeekAuxRam(int address)
375+
{
376+
return address switch
377+
{
378+
> 0 and < 0x0200 => _ramAuxRegion0001[address - 0],
379+
> 0x0200 and < 0xC000 => _ramAuxRegion02BF[address - 0x0200],
380+
> 0xC000 and < 0xD000 => _ramAuxBank1RegionD0DF[address - 0xC000],
381+
> 0xD000 and < 0xE000 => _ramAuxBank2RegionD0DF[address - 0xD000],
382+
> 0xE000 and < 0x10000 => _ramAuxRegionE0FF[address - 0xE000],
383+
_ => throw new InvalidOperationException()
384+
};
385+
}
386+
387+
public void PokeAuxRam(int address, byte value)
388+
{
389+
switch (address)
390+
{
391+
case > 0 and < 0x0200:
392+
_ramAuxRegion0001[address - 0] = value;
393+
break;
394+
case > 0x0200 and < 0xC000:
395+
_ramAuxRegion02BF[address - 0x0200] = value;
396+
break;
397+
case > 0xC000 and < 0xD000:
398+
_ramAuxBank1RegionD0DF[address - 0xC000] = value;
399+
break;
400+
case > 0xD000 and < 0xE000:
401+
_ramAuxBank2RegionD0DF[address - 0xD000] = value;
402+
break;
403+
case > 0xE000 and < 0x10000:
404+
_ramAuxRegionE0FF[address - 0xE000] = value;
405+
break;
406+
default:
407+
throw new InvalidOperationException();
408+
}
409+
}
410+
337411
private int ReadIoRegionC0CF(int address)
338412
{
339413
switch (address & 0xFF00)

References/Virtu.dll

512 Bytes
Binary file not shown.

src/BizHawk.Client.EmuHawk/RetroAchievements/RetroAchievements.Memory.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -507,6 +507,10 @@ void TryAddDomain(string domain, int? size = null, int addressMangler = 0)
507507
// todo: make this MainMemory
508508
mfs.Add(new(domains["RAM"], 0, domains["RAM"].Size));
509509
break;
510+
case ConsoleID.AppleII:
511+
mfs.Add(new(domains["Main RAM"], 0, domains["Main RAM"].Size));
512+
mfs.Add(new(domains["Auxiliary RAM"], 0, domains["Auxiliary RAM"].Size));
513+
break;
510514
case ConsoleID.Saturn:
511515
// todo: add System Bus so this isn't needed
512516
mfs.Add(new(domains["Work Ram Low"], 0, domains["Work Ram Low"].Size));

src/BizHawk.Emulation.Cores/Computers/AppleII/AppleII.IMemoryDomains.cs

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,20 +11,34 @@ private void SetupMemoryDomains()
1111
{
1212
var domains = new List<MemoryDomain>();
1313

14-
var mainRamDomain = new MemoryDomainDelegate("Main Ram", 0xC000, MemoryDomain.Endian.Little,
14+
var mainRamDomain = new MemoryDomainDelegate("Main RAM", 0x10000, MemoryDomain.Endian.Little,
1515
addr =>
1616
{
17-
if (addr is < 0 or > 0xBFFF) throw new ArgumentOutOfRangeException(paramName: nameof(addr), addr, message: "address out of range");
18-
return (byte)_machine.Memory.Peek((int)addr);
17+
if (addr is < 0 or > 0x10000) throw new ArgumentOutOfRangeException(paramName: nameof(addr), addr, message: "address out of range");
18+
return (byte)_machine.Memory.PeekMainRam((int)addr);
1919
},
2020
(addr, value) =>
2121
{
22-
if (addr is < 0 or > 0xBFFF) throw new ArgumentOutOfRangeException(paramName: nameof(addr), addr, message: "address out of range");
23-
_machine.Memory.Write((int)addr, value);
22+
if (addr is < 0 or > 0x10000) throw new ArgumentOutOfRangeException(paramName: nameof(addr), addr, message: "address out of range");
23+
_machine.Memory.PokeMainRam((int)addr, value);
2424
}, 1);
2525

2626
domains.Add(mainRamDomain);
2727

28+
var auxRamDomain = new MemoryDomainDelegate("Auxiliary RAM", 0x10000, MemoryDomain.Endian.Little,
29+
addr =>
30+
{
31+
if (addr is < 0 or > 0x10000) throw new ArgumentOutOfRangeException(paramName: nameof(addr), addr, message: "address out of range");
32+
return (byte)_machine.Memory.PeekAuxRam((int)addr);
33+
},
34+
(addr, value) =>
35+
{
36+
if (addr is < 0 or > 0x10000) throw new ArgumentOutOfRangeException(paramName: nameof(addr), addr, message: "address out of range");
37+
_machine.Memory.PokeAuxRam((int)addr, value);
38+
}, 1);
39+
40+
domains.Add(auxRamDomain);
41+
2842
var systemBusDomain = new MemoryDomainDelegate("System Bus", 0x10000, MemoryDomain.Endian.Little,
2943
addr =>
3044
{

0 commit comments

Comments
 (0)