Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding Stella as A2600 emulation core #3911

Merged
merged 52 commits into from
Sep 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
52 commits
Select commit Hold shift + click to select a range
f4911ad
Adding initial version of the core
SergioMartin86 Apr 29, 2024
b173b8d
Adding base files
SergioMartin86 Apr 29, 2024
2522994
Had to remove a lot of stuff but at least it's building now
SergioMartin86 Apr 29, 2024
ad4ce9f
Now not crashing. Ready to start the real work
SergioMartin86 Apr 29, 2024
cbd2ec8
Trying to load waterbox now
SergioMartin86 Apr 30, 2024
4f48295
Adding stella
SergioMartin86 Apr 30, 2024
e9ec8eb
Resync with upstream
SergioMartin86 Apr 30, 2024
dbac187
Merge branch 'stella' of github.com:SergioMartin86/BizHawk into stella
SergioMartin86 Apr 30, 2024
881960a
Adding bk class
SergioMartin86 Apr 30, 2024
62afcc9
Compiling bk interface to stella core
SergioMartin86 Apr 30, 2024
2972737
Now compiling against Stella + SDL2-based BK backend
SergioMartin86 May 1, 2024
2a58b12
Progress
SergioMartin86 May 2, 2024
d3644d9
More progress
SergioMartin86 May 3, 2024
5506e33
Frame advancing (no render)
SergioMartin86 May 3, 2024
97e12e8
Calling video update but crashing on zero div
SergioMartin86 May 4, 2024
2f2b0b3
Now rendering to screen with correct palette
SergioMartin86 May 4, 2024
2d81327
Now rendering appropriately and with correct palette based on region
SergioMartin86 May 5, 2024
2aa2939
Now reading controls
SergioMartin86 May 5, 2024
15c9069
Trying to capture audio
SergioMartin86 May 6, 2024
a47543a
Now adding audio
SergioMartin86 May 7, 2024
9a5ffe9
Now polling inputs
SergioMartin86 May 7, 2024
c5c5175
Now polling inputs
SergioMartin86 May 7, 2024
d8b04cb
Now reporting memory regions
SergioMartin86 May 9, 2024
59e6817
Added memory regions
SergioMartin86 May 9, 2024
449ede0
Removing debug prints
SergioMartin86 May 9, 2024
57a9673
Updating to upstream
SergioMartin86 May 9, 2024
0daff4a
Merge branch 'master' into stella
SergioMartin86 Aug 11, 2024
445f32b
Fixing indent
SergioMartin86 Aug 11, 2024
052091d
Adding stella core
SergioMartin86 Aug 11, 2024
f54375b
Updating readme and make all cores
SergioMartin86 Aug 11, 2024
24e49dc
Fixing warnings
SergioMartin86 Aug 11, 2024
1d2159e
Fixing warnings
SergioMartin86 Aug 11, 2024
3c711c4
Fixing warnings
SergioMartin86 Aug 11, 2024
387f181
Fixing warnings
SergioMartin86 Aug 11, 2024
715104a
Updating CI
SergioMartin86 Aug 11, 2024
cdbeaaf
Recovering ending comma
SergioMartin86 Aug 11, 2024
c11bcb0
Merge branch 'stella' of github.com:SergioMartin86/BizHawk into stella
SergioMartin86 Aug 11, 2024
505b772
Merge branch 'master' into stella
vadosnaprimer Sep 8, 2024
58eefcf
Merge branch 'master' into stella
SergioMartin86 Sep 8, 2024
d109ae1
Using heap alloc for sound buffer
SergioMartin86 Sep 8, 2024
101cf02
Merge branch 'master' into stella
SergioMartin86 Sep 8, 2024
ddb63e5
Removing unnecessary files
SergioMartin86 Sep 8, 2024
f9610ed
Update src/BizHawk.Emulation.Cores/Consoles/Atari/Stella/Stella.IMemo…
SergioMartin86 Sep 8, 2024
fc3498a
Update src/BizHawk.Emulation.Cores/Consoles/Atari/Stella/Stella.IMemo…
SergioMartin86 Sep 8, 2024
aa9b190
Fix
SergioMartin86 Sep 9, 2024
086ce8a
Restoring vscode
SergioMartin86 Sep 9, 2024
7ff2995
Removing warning
SergioMartin86 Sep 9, 2024
0bfac50
Update waterbox readme
Morilli Sep 10, 2024
359a60f
Fix Stella's `[Core]` attr
YoshiRulz Sep 10, 2024
6c87303
Increased sound buffer size to 1Mb, as some games need more than 4K
SergioMartin86 Sep 10, 2024
8c10a0c
Merge branch 'stella' of github.com:SergioMartin86/BizHawk into stella
SergioMartin86 Sep 10, 2024
1e831e8
Merge branch 'master' into stella
SergioMartin86 Sep 10, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .github/workflows/make.yml
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ jobs:
git submodule update --init gpgx/Genesis-Plus-GX;
git submodule update --init ../submodules/sameboy/libsameboy;
git submodule update --init uae/libretro-uae;
git submodule update --init stella/core;
- name: Download compiled waterbox
uses: actions/download-artifact@v4
with:
Expand Down Expand Up @@ -100,6 +101,7 @@ jobs:
Assets/dll/turbo.wbx.zst
Assets/dll/uzem.wbx.zst
Assets/dll/vb.wbx.zst
Assets/dll/stella.wbx.zst
Assets/dll/virtualjaguar.wbx.zst

build-mame:
Expand Down
4 changes: 4 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,10 @@
path = waterbox/gpgx/Genesis-Plus-GX
url = https://github.com/TASEmulators/Genesis-Plus-GX.git
branch = tasvideos-2.2
[submodule "waterbox/stella/core"]
path = waterbox/stella/core
url = https://github.com/TASEmulators/stella.git
branch = tasvideos-1
[submodule "waterbox/uae/libretro-uae"]
path = waterbox/uae/libretro-uae
url = https://github.com/TASEmulators/libretro-uae.git
Expand Down
Binary file added Assets/dll/stella.wbx.zst
Binary file not shown.
3 changes: 3 additions & 0 deletions src/BizHawk.Client.Common/config/Config.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ public class Config
/// </remarks>
public static readonly IReadOnlyList<(string[] AppliesTo, string[] CoreNames)> CorePickerUIData = new List<(string[], string[])>
{
([ VSystemID.Raw.A26 ],
[ CoreNames.Stella, CoreNames.Atari2600Hawk ]),
([ VSystemID.Raw.Satellaview ],
[ CoreNames.Bsnes115, CoreNames.SubBsnes115 ]),
([ VSystemID.Raw.GB, VSystemID.Raw.GBC ],
Expand All @@ -49,6 +51,7 @@ public class Config
[ CoreNames.Snes9X, CoreNames.Bsnes115, CoreNames.SubBsnes115, CoreNames.Faust, CoreNames.Bsnes ]),
([ VSystemID.Raw.TI83 ],
[ CoreNames.Emu83, CoreNames.TI83Hawk ]),

};

public static Dictionary<string, string> GenDefaultCorePreferences()
Expand Down
3 changes: 2 additions & 1 deletion src/BizHawk.Emulation.Common/Enums.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ public enum DisplayType
{
NTSC,
PAL,
Dendy
Dendy,
SECAM
}

/// <summary>
Expand Down
80 changes: 80 additions & 0 deletions src/BizHawk.Emulation.Cores/Consoles/Atari/Stella/LibStella.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
using System.Runtime.InteropServices;

using BizHawk.BizInvoke;

namespace BizHawk.Emulation.Cores.Consoles.Atari.Stella
{
public abstract class CInterface
{

[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
public delegate int load_archive_cb(string filename, IntPtr buffer, int maxsize);

[StructLayout(LayoutKind.Sequential)]
public class InitSettings
{
public uint dummy;
}

[BizImport(CallingConvention.Cdecl)]
public abstract void stella_get_audio(ref int n, ref IntPtr buffer);

[BizImport(CallingConvention.Cdecl)]
public abstract int stella_get_region();

[BizImport(CallingConvention.Cdecl)]
public abstract bool stella_init(
string fileName,
load_archive_cb feload_archive_cb,
[In]InitSettings settings);

[BizImport(CallingConvention.Cdecl)]
public abstract void stella_frame_advance(int port1, int port2, bool reset, bool power, bool leftDiffToggled, bool rightDiffToggled);

[BizImport(CallingConvention.Cdecl)]
public abstract void stella_get_video(out int w, out int h, out int pitch, ref IntPtr buffer);

[BizImport(CallingConvention.Cdecl)]
public abstract void stella_get_frame_rate(out int fps);

[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
public delegate void input_cb();

[BizImport(CallingConvention.Cdecl)]
public abstract void stella_set_input_callback(input_cb cb);

[BizImport(CallingConvention.Cdecl)]
public abstract byte stella_peek_tia(uint addr);

[BizImport(CallingConvention.Cdecl)]
public abstract void stella_poke_tia(uint addr, byte value);

[BizImport(CallingConvention.Cdecl)]
public abstract byte stella_peek_m6532(uint addr);

[BizImport(CallingConvention.Cdecl)]
public abstract void stella_poke_m6532(uint addr, byte value);

[BizImport(CallingConvention.Cdecl)]
public abstract byte stella_peek_systembus(uint addr);

[BizImport(CallingConvention.Cdecl)]
public abstract void stella_poke_systembus(uint addr, byte value);

[BizImport(CallingConvention.Cdecl)]
public abstract uint stella_get_cartram_size();

[BizImport(CallingConvention.Cdecl)]
public abstract byte stella_peek_cartram(uint addr);

[BizImport(CallingConvention.Cdecl)]
public abstract void stella_poke_cartram(uint addr, byte value);

[BizImport(CallingConvention.Cdecl)]
public abstract void stella_get_mainram_ptr(ref IntPtr addr);

[BizImport(CallingConvention.Cdecl)]
public abstract IntPtr stella_get_cart_type();

}
}
99 changes: 99 additions & 0 deletions src/BizHawk.Emulation.Cores/Consoles/Atari/Stella/Stella.Core.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
using BizHawk.Emulation.Cores.Components.M6502;
using System.Runtime.CompilerServices;

namespace BizHawk.Emulation.Cores.Atari.Stella
{
public partial class Stella
{
internal struct CpuLink : IMOS6502XLink
{
public byte DummyReadMemory(ushort address) { return 0; }

public void OnExecFetch(ushort address) { }

public byte PeekMemory(ushort address) { return 0; }

public byte ReadMemory(ushort address) { return 0; }

public void WriteMemory(ushort address, byte value) { }
}

internal byte BaseReadMemory(ushort addr)
{
return 0;
}

internal byte BasePeekMemory(ushort addr)
{

return 0;
}

internal void BaseWriteMemory(ushort addr, byte value)
{
}

internal void BasePokeMemory(ushort addr, byte value)
{
}

[MethodImpl(MethodImplOptions.AggressiveInlining)]
private byte ReadMemory(ushort addr)
{
return 0;
}

[MethodImpl(MethodImplOptions.AggressiveInlining)]
private void WriteMemory(ushort addr, byte value)
{
}

internal void PokeMemory(ushort addr, byte value)
{
}

[MethodImpl(MethodImplOptions.AggressiveInlining)]
private void ExecFetch(ushort addr)
{
}

private void RebootCore()
{
}

private void HardReset()
{
}

private void Cycle()
{
}

[MethodImpl(MethodImplOptions.AggressiveInlining)]
internal byte ReadControls1(bool peek)
{
return 0;
}

[MethodImpl(MethodImplOptions.AggressiveInlining)]
internal byte ReadControls2(bool peek)
{
return 0;
}

internal int ReadPot1(int pot)
{
return 0;
}

internal int ReadPot2(int pot)
{
return 0;
}

internal byte ReadConsoleSwitches(bool peek)
{
return 0;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
using BizHawk.Emulation.Common;

namespace BizHawk.Emulation.Cores.Atari.Stella
{
public partial class Stella : IEmulator
{
public IEmulatorServiceProvider ServiceProvider { get; }

public ControllerDefinition ControllerDefinition => _controllerDeck.Definition;

private bool _leftDifficultyToggled = false;
private bool _rightDifficultyToggled = false;

public bool FrameAdvance(IController controller, bool render, bool renderSound)
{

int port1 = _controllerDeck.ReadPort1(controller);
int port2 = _controllerDeck.ReadPort2(controller);

// Handle all the console controls here
bool powerPressed = false;
bool resetPressed = false;
if (controller.IsPressed("Power")) powerPressed = true;
if (controller.IsPressed("Reset")) resetPressed = true;
if (controller.IsPressed("Toggle Left Difficulty")) _leftDifficultyToggled = !_leftDifficultyToggled;
if (controller.IsPressed("Toggle Right Difficulty")) _rightDifficultyToggled = !_rightDifficultyToggled;

IsLagFrame = true;

Core.stella_frame_advance(port1, port2, resetPressed, powerPressed, _leftDifficultyToggled, _rightDifficultyToggled);

if (IsLagFrame)
LagCount++;

if (render)
UpdateVideo();

if (renderSound)
update_audio();

_frame++;

return true;
}

public int _frame;

public int Frame => _frame;

public string SystemId => VSystemID.Raw.A26;

public bool DeterministicEmulation => true;

public void ResetCounters()
{
_frame = 0;
LagCount = 0;
IsLagFrame = false;
}

public void Dispose()
{
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
using BizHawk.Emulation.Common;
using BizHawk.Emulation.Cores.Consoles.Atari.Stella;

namespace BizHawk.Emulation.Cores.Atari.Stella
{
public partial class Stella : IInputPollable
{
public int LagCount { get; set; }

public bool IsLagFrame { get; set; }

public IInputCallbackSystem InputCallbacks => _inputCallbacks;

private readonly CInterface.input_cb _inputCallback;

private readonly InputCallbackSystem _inputCallbacks = new InputCallbackSystem();

private void input_callback()
{
InputCallbacks.Call();
IsLagFrame = false;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
using System.Collections.Generic;

using BizHawk.Emulation.Common;

namespace BizHawk.Emulation.Cores.Atari.Stella
{
public partial class Stella
{
internal IMemoryDomains MemoryDomains;
private uint _cartMemSize;

private void SetupMemoryDomains()
{
_cartMemSize = Core.stella_get_cartram_size();
var mainRamAddress = IntPtr.Zero;
var cartDPCRamAddress = IntPtr.Zero;
Core.stella_get_mainram_ptr(ref mainRamAddress);

var domains = new List<MemoryDomain>
{
new MemoryDomainDelegate(
"TIA",
16,
MemoryDomain.Endian.Little,
addr => Core.stella_peek_tia((uint)addr),
(addr, value) => Core.stella_poke_tia((uint)addr, value),
1),

new MemoryDomainDelegate(
"PIA",
1024,
MemoryDomain.Endian.Little,
addr => Core.stella_peek_m6532((uint)addr),
(addr, value) => Core.stella_poke_m6532((uint)addr, value),
1),

new MemoryDomainDelegate(
"System Bus",
65536,
MemoryDomain.Endian.Little,
addr => Core.stella_peek_systembus((uint) addr),
(addr, value) => Core.stella_poke_systembus((uint) addr, value),
1)
};

if (_cartMemSize > 0)
{
domains.Add(new MemoryDomainDelegate(
"Cart Ram",
_cartMemSize,
MemoryDomain.Endian.Little,
addr => Core.stella_peek_cartram((uint)addr),
(addr, value) => Core.stella_poke_cartram((uint)addr, value),
1));
}

MemoryDomainIntPtrMonitor mainRAM = new("Main RAM", MemoryDomain.Endian.Little, mainRamAddress, 128, true, 1, _elf);
domains.Add(mainRAM);

MemoryDomains = new MemoryDomainList(domains) { MainMemory = mainRAM };
((BasicServiceProvider)ServiceProvider).Register(MemoryDomains);
}
}
}
Loading