Skip to content

Commit bf8758e

Browse files
SergioMartin86YoshiRulzMorilli
authored
Adding Stella as A2600 emulation core (#3911)
* Adding initial version of the core * Adding base files * Trying to load waterbox now * Adding stella * Adding bk class * Compiling bk interface to stella core * Now compiling against Stella + SDL2-based BK backend * Progress * More progress * Frame advancing (no render) * Calling video update but crashing on zero div * Now rendering to screen with correct palette * Now rendering appropriately and with correct palette based on region * Now reading controls * Trying to capture audio * Now adding audio * Now polling inputs * Now polling inputs * Now reporting memory regions * Added memory regions * Removing debug prints * Fixing indent * Adding stella core * Updating readme and make all cores * Recovering ending comma * Using heap alloc for sound buffer * Removing unnecessary files * Update src/BizHawk.Emulation.Cores/Consoles/Atari/Stella/Stella.IMemoryDomains.cs Co-authored-by: James Groom <OSSYoshiRulz+GitHub@gmail.com> * Update src/BizHawk.Emulation.Cores/Consoles/Atari/Stella/Stella.IMemoryDomains.cs Co-authored-by: James Groom <OSSYoshiRulz+GitHub@gmail.com> * Fix * Restoring vscode * Removing warning * Update waterbox readme * Fix Stella's `[Core]` attr * Increased sound buffer size to 1Mb, as some games need more than 4K --------- Co-authored-by: James Groom <OSSYoshiRulz+GitHub@gmail.com> Co-authored-by: Morilli <35152647+Morilli@users.noreply.github.com> Co-authored-by: YoshiRulz <OSSYoshiRulz+git@gmail.com>
1 parent a080086 commit bf8758e

36 files changed

+3203
-2
lines changed

.github/workflows/make.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ jobs:
6060
git submodule update --init gpgx/Genesis-Plus-GX;
6161
git submodule update --init ../submodules/sameboy/libsameboy;
6262
git submodule update --init uae/libretro-uae;
63+
git submodule update --init stella/core;
6364
- name: Download compiled waterbox
6465
uses: actions/download-artifact@v4
6566
with:
@@ -100,6 +101,7 @@ jobs:
100101
Assets/dll/turbo.wbx.zst
101102
Assets/dll/uzem.wbx.zst
102103
Assets/dll/vb.wbx.zst
104+
Assets/dll/stella.wbx.zst
103105
Assets/dll/virtualjaguar.wbx.zst
104106
105107
build-mame:

.gitmodules

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,10 @@
7474
path = waterbox/gpgx/Genesis-Plus-GX
7575
url = https://github.com/TASEmulators/Genesis-Plus-GX.git
7676
branch = tasvideos-2.2
77+
[submodule "waterbox/stella/core"]
78+
path = waterbox/stella/core
79+
url = https://github.com/TASEmulators/stella.git
80+
branch = tasvideos-1
7781
[submodule "waterbox/uae/libretro-uae"]
7882
path = waterbox/uae/libretro-uae
7983
url = https://github.com/TASEmulators/libretro-uae.git

Assets/dll/stella.wbx.zst

1.38 MB
Binary file not shown.

src/BizHawk.Client.Common/config/Config.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ public class Config
2525
/// </remarks>
2626
public static readonly IReadOnlyList<(string[] AppliesTo, string[] CoreNames)> CorePickerUIData = new List<(string[], string[])>
2727
{
28+
([ VSystemID.Raw.A26 ],
29+
[ CoreNames.Stella, CoreNames.Atari2600Hawk ]),
2830
([ VSystemID.Raw.Satellaview ],
2931
[ CoreNames.Bsnes115, CoreNames.SubBsnes115 ]),
3032
([ VSystemID.Raw.GB, VSystemID.Raw.GBC ],
@@ -49,6 +51,7 @@ public class Config
4951
[ CoreNames.Snes9X, CoreNames.Bsnes115, CoreNames.SubBsnes115, CoreNames.Faust, CoreNames.Bsnes ]),
5052
([ VSystemID.Raw.TI83 ],
5153
[ CoreNames.Emu83, CoreNames.TI83Hawk ]),
54+
5255
};
5356

5457
public static Dictionary<string, string> GenDefaultCorePreferences()

src/BizHawk.Emulation.Common/Enums.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ public enum DisplayType
77
{
88
NTSC,
99
PAL,
10-
Dendy
10+
Dendy,
11+
SECAM
1112
}
1213

1314
/// <summary>
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
using System.Runtime.InteropServices;
2+
3+
using BizHawk.BizInvoke;
4+
5+
namespace BizHawk.Emulation.Cores.Consoles.Atari.Stella
6+
{
7+
public abstract class CInterface
8+
{
9+
10+
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
11+
public delegate int load_archive_cb(string filename, IntPtr buffer, int maxsize);
12+
13+
[StructLayout(LayoutKind.Sequential)]
14+
public class InitSettings
15+
{
16+
public uint dummy;
17+
}
18+
19+
[BizImport(CallingConvention.Cdecl)]
20+
public abstract void stella_get_audio(ref int n, ref IntPtr buffer);
21+
22+
[BizImport(CallingConvention.Cdecl)]
23+
public abstract int stella_get_region();
24+
25+
[BizImport(CallingConvention.Cdecl)]
26+
public abstract bool stella_init(
27+
string fileName,
28+
load_archive_cb feload_archive_cb,
29+
[In]InitSettings settings);
30+
31+
[BizImport(CallingConvention.Cdecl)]
32+
public abstract void stella_frame_advance(int port1, int port2, bool reset, bool power, bool leftDiffToggled, bool rightDiffToggled);
33+
34+
[BizImport(CallingConvention.Cdecl)]
35+
public abstract void stella_get_video(out int w, out int h, out int pitch, ref IntPtr buffer);
36+
37+
[BizImport(CallingConvention.Cdecl)]
38+
public abstract void stella_get_frame_rate(out int fps);
39+
40+
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
41+
public delegate void input_cb();
42+
43+
[BizImport(CallingConvention.Cdecl)]
44+
public abstract void stella_set_input_callback(input_cb cb);
45+
46+
[BizImport(CallingConvention.Cdecl)]
47+
public abstract byte stella_peek_tia(uint addr);
48+
49+
[BizImport(CallingConvention.Cdecl)]
50+
public abstract void stella_poke_tia(uint addr, byte value);
51+
52+
[BizImport(CallingConvention.Cdecl)]
53+
public abstract byte stella_peek_m6532(uint addr);
54+
55+
[BizImport(CallingConvention.Cdecl)]
56+
public abstract void stella_poke_m6532(uint addr, byte value);
57+
58+
[BizImport(CallingConvention.Cdecl)]
59+
public abstract byte stella_peek_systembus(uint addr);
60+
61+
[BizImport(CallingConvention.Cdecl)]
62+
public abstract void stella_poke_systembus(uint addr, byte value);
63+
64+
[BizImport(CallingConvention.Cdecl)]
65+
public abstract uint stella_get_cartram_size();
66+
67+
[BizImport(CallingConvention.Cdecl)]
68+
public abstract byte stella_peek_cartram(uint addr);
69+
70+
[BizImport(CallingConvention.Cdecl)]
71+
public abstract void stella_poke_cartram(uint addr, byte value);
72+
73+
[BizImport(CallingConvention.Cdecl)]
74+
public abstract void stella_get_mainram_ptr(ref IntPtr addr);
75+
76+
[BizImport(CallingConvention.Cdecl)]
77+
public abstract IntPtr stella_get_cart_type();
78+
79+
}
80+
}
Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
using BizHawk.Emulation.Cores.Components.M6502;
2+
using System.Runtime.CompilerServices;
3+
4+
namespace BizHawk.Emulation.Cores.Atari.Stella
5+
{
6+
public partial class Stella
7+
{
8+
internal struct CpuLink : IMOS6502XLink
9+
{
10+
public byte DummyReadMemory(ushort address) { return 0; }
11+
12+
public void OnExecFetch(ushort address) { }
13+
14+
public byte PeekMemory(ushort address) { return 0; }
15+
16+
public byte ReadMemory(ushort address) { return 0; }
17+
18+
public void WriteMemory(ushort address, byte value) { }
19+
}
20+
21+
internal byte BaseReadMemory(ushort addr)
22+
{
23+
return 0;
24+
}
25+
26+
internal byte BasePeekMemory(ushort addr)
27+
{
28+
29+
return 0;
30+
}
31+
32+
internal void BaseWriteMemory(ushort addr, byte value)
33+
{
34+
}
35+
36+
internal void BasePokeMemory(ushort addr, byte value)
37+
{
38+
}
39+
40+
[MethodImpl(MethodImplOptions.AggressiveInlining)]
41+
private byte ReadMemory(ushort addr)
42+
{
43+
return 0;
44+
}
45+
46+
[MethodImpl(MethodImplOptions.AggressiveInlining)]
47+
private void WriteMemory(ushort addr, byte value)
48+
{
49+
}
50+
51+
internal void PokeMemory(ushort addr, byte value)
52+
{
53+
}
54+
55+
[MethodImpl(MethodImplOptions.AggressiveInlining)]
56+
private void ExecFetch(ushort addr)
57+
{
58+
}
59+
60+
private void RebootCore()
61+
{
62+
}
63+
64+
private void HardReset()
65+
{
66+
}
67+
68+
private void Cycle()
69+
{
70+
}
71+
72+
[MethodImpl(MethodImplOptions.AggressiveInlining)]
73+
internal byte ReadControls1(bool peek)
74+
{
75+
return 0;
76+
}
77+
78+
[MethodImpl(MethodImplOptions.AggressiveInlining)]
79+
internal byte ReadControls2(bool peek)
80+
{
81+
return 0;
82+
}
83+
84+
internal int ReadPot1(int pot)
85+
{
86+
return 0;
87+
}
88+
89+
internal int ReadPot2(int pot)
90+
{
91+
return 0;
92+
}
93+
94+
internal byte ReadConsoleSwitches(bool peek)
95+
{
96+
return 0;
97+
}
98+
}
99+
}
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
using BizHawk.Emulation.Common;
2+
3+
namespace BizHawk.Emulation.Cores.Atari.Stella
4+
{
5+
public partial class Stella : IEmulator
6+
{
7+
public IEmulatorServiceProvider ServiceProvider { get; }
8+
9+
public ControllerDefinition ControllerDefinition => _controllerDeck.Definition;
10+
11+
private bool _leftDifficultyToggled = false;
12+
private bool _rightDifficultyToggled = false;
13+
14+
public bool FrameAdvance(IController controller, bool render, bool renderSound)
15+
{
16+
17+
int port1 = _controllerDeck.ReadPort1(controller);
18+
int port2 = _controllerDeck.ReadPort2(controller);
19+
20+
// Handle all the console controls here
21+
bool powerPressed = false;
22+
bool resetPressed = false;
23+
if (controller.IsPressed("Power")) powerPressed = true;
24+
if (controller.IsPressed("Reset")) resetPressed = true;
25+
if (controller.IsPressed("Toggle Left Difficulty")) _leftDifficultyToggled = !_leftDifficultyToggled;
26+
if (controller.IsPressed("Toggle Right Difficulty")) _rightDifficultyToggled = !_rightDifficultyToggled;
27+
28+
IsLagFrame = true;
29+
30+
Core.stella_frame_advance(port1, port2, resetPressed, powerPressed, _leftDifficultyToggled, _rightDifficultyToggled);
31+
32+
if (IsLagFrame)
33+
LagCount++;
34+
35+
if (render)
36+
UpdateVideo();
37+
38+
if (renderSound)
39+
update_audio();
40+
41+
_frame++;
42+
43+
return true;
44+
}
45+
46+
public int _frame;
47+
48+
public int Frame => _frame;
49+
50+
public string SystemId => VSystemID.Raw.A26;
51+
52+
public bool DeterministicEmulation => true;
53+
54+
public void ResetCounters()
55+
{
56+
_frame = 0;
57+
LagCount = 0;
58+
IsLagFrame = false;
59+
}
60+
61+
public void Dispose()
62+
{
63+
}
64+
}
65+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
using BizHawk.Emulation.Common;
2+
using BizHawk.Emulation.Cores.Consoles.Atari.Stella;
3+
4+
namespace BizHawk.Emulation.Cores.Atari.Stella
5+
{
6+
public partial class Stella : IInputPollable
7+
{
8+
public int LagCount { get; set; }
9+
10+
public bool IsLagFrame { get; set; }
11+
12+
public IInputCallbackSystem InputCallbacks => _inputCallbacks;
13+
14+
private readonly CInterface.input_cb _inputCallback;
15+
16+
private readonly InputCallbackSystem _inputCallbacks = new InputCallbackSystem();
17+
18+
private void input_callback()
19+
{
20+
InputCallbacks.Call();
21+
IsLagFrame = false;
22+
}
23+
}
24+
}
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
using System.Collections.Generic;
2+
3+
using BizHawk.Emulation.Common;
4+
5+
namespace BizHawk.Emulation.Cores.Atari.Stella
6+
{
7+
public partial class Stella
8+
{
9+
internal IMemoryDomains MemoryDomains;
10+
private uint _cartMemSize;
11+
12+
private void SetupMemoryDomains()
13+
{
14+
_cartMemSize = Core.stella_get_cartram_size();
15+
var mainRamAddress = IntPtr.Zero;
16+
var cartDPCRamAddress = IntPtr.Zero;
17+
Core.stella_get_mainram_ptr(ref mainRamAddress);
18+
19+
var domains = new List<MemoryDomain>
20+
{
21+
new MemoryDomainDelegate(
22+
"TIA",
23+
16,
24+
MemoryDomain.Endian.Little,
25+
addr => Core.stella_peek_tia((uint)addr),
26+
(addr, value) => Core.stella_poke_tia((uint)addr, value),
27+
1),
28+
29+
new MemoryDomainDelegate(
30+
"PIA",
31+
1024,
32+
MemoryDomain.Endian.Little,
33+
addr => Core.stella_peek_m6532((uint)addr),
34+
(addr, value) => Core.stella_poke_m6532((uint)addr, value),
35+
1),
36+
37+
new MemoryDomainDelegate(
38+
"System Bus",
39+
65536,
40+
MemoryDomain.Endian.Little,
41+
addr => Core.stella_peek_systembus((uint) addr),
42+
(addr, value) => Core.stella_poke_systembus((uint) addr, value),
43+
1)
44+
};
45+
46+
if (_cartMemSize > 0)
47+
{
48+
domains.Add(new MemoryDomainDelegate(
49+
"Cart Ram",
50+
_cartMemSize,
51+
MemoryDomain.Endian.Little,
52+
addr => Core.stella_peek_cartram((uint)addr),
53+
(addr, value) => Core.stella_poke_cartram((uint)addr, value),
54+
1));
55+
}
56+
57+
MemoryDomainIntPtrMonitor mainRAM = new("Main RAM", MemoryDomain.Endian.Little, mainRamAddress, 128, true, 1, _elf);
58+
domains.Add(mainRAM);
59+
60+
MemoryDomains = new MemoryDomainList(domains) { MainMemory = mainRAM };
61+
((BasicServiceProvider)ServiceProvider).Register(MemoryDomains);
62+
}
63+
}
64+
}

0 commit comments

Comments
 (0)