Skip to content

Commit

Permalink
[melonDS] Redo porting, waterbox style now (#2945)
Browse files Browse the repository at this point in the history
Co-authored-by: nattthebear <[email protected]>
  • Loading branch information
CasualPokePlayer and nattthebear authored Oct 24, 2021
1 parent f14b057 commit 41128ab
Show file tree
Hide file tree
Showing 56 changed files with 16,726 additions and 1,479 deletions.
9 changes: 6 additions & 3 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@
path = submodules/mgba
url = https://github.com/TASEmulators/mgba.git
branch = bizhawk-0.9
[submodule "melonds"]
path = melonds
[submodule "waterbox/melon/melonDS"]
path = waterbox/melon/melonDS
url = https://github.com/TASEmulators/melonDS.git
branch = SuuperW_DSHawk
branch = melonbiz
[submodule "waterbox/musl"]
path = waterbox/musl
url = https://github.com/nattthebear/musl.git
Expand All @@ -37,3 +37,6 @@
[submodule "submodules/libdarm"]
path = submodules/libdarm
url = https://github.com/jbremer/darm.git
[submodule "submodules/libfwunpack"]
path = submodules/libfwunpack
url = https://github.com/TASEmulators/fwunpack
57 changes: 44 additions & 13 deletions Assets/Lua/NDS/StylusInputDisplay.lua
Original file line number Diff line number Diff line change
@@ -1,20 +1,39 @@
-- Gives a cross hair UI for the stylus for DS games

local upColor = 'white'
local downColor = 'green'
local dotColor = 'red'
local upColor = 'lime'
local downColor = 'red'
local dotColor = 'blue'

client.setwindowsize(client.getwindowsize()) -- assert a sane resolution

invert = false
-- FIXME: No idea how to get lua to detect inverted screens, set this to true if inverted screens are active
-- (typing "invert = true" without the quotes in the console works)

function Draw(x, y, maxX, maxY, isDown)
color = upColor
if isDown then
color = downColor
end

gui.drawLine(0, y - 1, maxX, y - 1, color)
gui.drawLine(0, y, maxX, y, color)
gui.drawLine(0, y + 1, maxX, y + 1, color)

gui.drawLine(x - 1, 0, x - 1, maxY, color)
gui.drawLine(x, 0, x, maxY, color)
gui.drawLine(x + 1, 0, x + 1, maxY, color)

if isDown then
gui.drawPixel(x - 1, y - 1, dotColor)
gui.drawPixel(x, y - 1, dotColor)
gui.drawPixel(x + 1, y - 1, dotColor)
gui.drawPixel(x - 1, y, dotColor)
gui.drawPixel(x, y, dotColor)
gui.drawPixel(x + 1, y, dotColor)
gui.drawPixel(x - 1, y + 1, dotColor)
gui.drawPixel(x, y + 1, dotColor)
gui.drawPixel(x + 1, y + 1, dotColor)
end
end

Expand All @@ -30,21 +49,33 @@ while true do
btns = movie.getinput(emu.framecount() - 1)
end

local x = btns['TouchX']
local y = btns['TouchY']
local isDown = btns['Touch']
local wsz = client.getwindowsize()
local w = client.screenwidth() / wsz
local xo = 0
local yo = 0

-- A bit of a hack to ensure it is not drawing while mouse moving
-- on the top screen
if y == 0 then
x = 0
if w == 512 then -- horizontal
if invert then
xo = xo - 256
else
error("Non-inverted horizontal screens are unsupported")
end
else -- vertical
if invert then
yo = yo - 192
else
-- don't need to do anything here
end
end

local x = btns['Touch X'] + xo
local y = btns['Touch Y'] + yo
local isDown = btns['Touch']

pts = client.transformPoint(x, y)
local tx = pts["x"];
local ty = pts["y"];
gui.DrawNew("native")
Draw(tx, ty, 10000, 10000, isDown)
Draw(tx / wsz, ty / wsz, 10000, 10000, isDown)

emu.frameadvance()
emu.yield()
end
4 changes: 2 additions & 2 deletions Assets/defctrl.json
Original file line number Diff line number Diff line change
Expand Up @@ -1117,12 +1117,12 @@
}
},
"NDS Controller": {
"TouchX": {
"Touch X": {
"Value": "WMouse X",
"Mult": 1.0,
"Deadzone": 0.0
},
"TouchY": {
"Touch Y": {
"Value": "WMouse Y",
"Mult": 1.0,
"Deadzone": 0.0
Expand Down
Binary file added Assets/dll/libfwunpack.dll
Binary file not shown.
Binary file added Assets/dll/libfwunpack.so
Binary file not shown.
Binary file removed Assets/dll/libmelonDS.dll
Binary file not shown.
Binary file modified Assets/dll/libwaterboxhost.so
Binary file not shown.
Binary file added Assets/dll/melonDS.wbx.gz
Binary file not shown.
Binary file modified Assets/dll/waterboxhost.dll
Binary file not shown.
1 change: 1 addition & 0 deletions Assets/gamedb/gamedb.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
;#include gamedb_msx1-L.txt (legacy?)
;#include gamedb_msx2-L.txt (legacy?)
#include gamedb_n64.txt
#include gamedb_nds.txt
#include gamedb_nes.txt
#include gamedb_Odyssey2.txt
#include gamedb_pce_cd.txt
Expand Down
14,627 changes: 14,627 additions & 0 deletions Assets/gamedb/gamedb_nds.txt

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion ExternalToolProjects/DATParser/DATParserBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,7 @@ public enum SystemType
GB3x,
GB4x,
O2,
MSX
MSX,
NDS
}
}
1 change: 0 additions & 1 deletion melonds
Submodule melonds deleted from cbd9ad
Original file line number Diff line number Diff line change
Expand Up @@ -488,7 +488,7 @@ public void UpdateSource(IVideoProvider videoProvider)

private BaseFilter CreateCoreScreenControl()
{
if (GlobalEmulator is MelonDS nds)
if (GlobalEmulator is NDS nds)
{
//TODO: need to pipe layout settings into here now
var filter = new ScreenControlNDS(nds);
Expand Down
46 changes: 26 additions & 20 deletions src/BizHawk.Client.Common/DisplayManager/Filters/Gui.cs
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ public class ScreenControlNDS : BaseFilter
public IGL GL;
public IGuiRenderer GuiRenderer;

private readonly MelonDS nds;
private readonly NDS nds;

//TODO: actually use this
private bool nop = false;
Expand All @@ -195,7 +195,7 @@ private static Vector2 Transform(Matrix4 m, Vector2 v)
return new Vector2(r.X, r.Y);
}

public ScreenControlNDS(MelonDS nds)
public ScreenControlNDS(NDS nds)
{
//not sure if we actually need this nds instance yet
this.nds = nds;
Expand All @@ -218,27 +218,27 @@ private void CrunchNumbers()
var settings = nds.GetSettings();

//gap only applies to vertical, I guess
if (settings.ScreenLayout == MelonDS.ScreenLayoutKind.Vertical)
if (settings.ScreenLayout == NDS.ScreenLayoutKind.Vertical)
{
bot.Translate(0, 192);
bot.Translate(0, settings.ScreenGap);
}
else if (settings.ScreenLayout == MelonDS.ScreenLayoutKind.Horizontal)
else if (settings.ScreenLayout == NDS.ScreenLayoutKind.Horizontal)
{
bot.Translate(256, 0);
}
else if (settings.ScreenLayout == MelonDS.ScreenLayoutKind.Top)
else if (settings.ScreenLayout == NDS.ScreenLayoutKind.Top)
{
//do nothing here, we'll discard bottom screen
}

//this doesn't make any sense, it's likely to be too much for a monitor to gracefully handle too
if (settings.ScreenLayout != MelonDS.ScreenLayoutKind.Horizontal)
if (settings.ScreenLayout != NDS.ScreenLayoutKind.Horizontal)
{
int rot = 0;
if (settings.ScreenRotation == MelonDS.ScreenRotationKind.Rotate90) rot = 90;
if (settings.ScreenRotation == MelonDS.ScreenRotationKind.Rotate180) rot = 180;
if (settings.ScreenRotation == MelonDS.ScreenRotationKind.Rotate270) rot = 270;
if (settings.ScreenRotation == NDS.ScreenRotationKind.Rotate90) rot = 90;
if (settings.ScreenRotation == NDS.ScreenRotationKind.Rotate180) rot = 180;
if (settings.ScreenRotation == NDS.ScreenRotationKind.Rotate270) rot = 270;
top.RotateZ(rot);
bot.RotateZ(rot);
}
Expand Down Expand Up @@ -283,14 +283,14 @@ private void CrunchNumbers()

//the size can now be determined in a kind of fluffily magical way by transforming edges and checking the bounds
float fxmin = 100000, fymin = 100000, fxmax = -100000, fymax = -100000;
if (settings.ScreenLayout != MelonDS.ScreenLayoutKind.Bottom)
if (settings.ScreenLayout != NDS.ScreenLayoutKind.Bottom)
{
fxmin = Math.Min(Math.Min(Math.Min(Math.Min(top_TL.X, top_TR.X), top_BL.X), top_BR.X), fxmin);
fymin = Math.Min(Math.Min(Math.Min(Math.Min(top_TL.Y, top_TR.Y), top_BL.Y), top_BR.Y), fymin);
fxmax = Math.Max(Math.Max(Math.Max(Math.Max(top_TL.X, top_TR.X), top_BL.X), top_BR.X), fxmax);
fymax = Math.Max(Math.Max(Math.Max(Math.Max(top_TL.Y, top_TR.Y), top_BL.Y), top_BR.Y), fymax);
}
if (settings.ScreenLayout != MelonDS.ScreenLayoutKind.Top)
if (settings.ScreenLayout != NDS.ScreenLayoutKind.Top)
{
fxmin = Math.Min(Math.Min(Math.Min(Math.Min(bot_TL.X, bot_TR.X), bot_BL.X), bot_BR.X), fxmin);
fymin = Math.Min(Math.Min(Math.Min(Math.Min(bot_TL.Y, bot_TR.Y), bot_BL.Y), bot_BR.Y), fymin);
Expand Down Expand Up @@ -339,7 +339,12 @@ public override void SetInputFormat(string channel, SurfaceState state)

public override Vector2 UntransformPoint(string channel, Vector2 point)
{
point = Transform(matBotInvert, point);
var settings = nds.GetSettings();
bool invert = settings.ScreenInvert
&& settings.ScreenLayout != NDS.ScreenLayoutKind.Top
&& settings.ScreenLayout != NDS.ScreenLayoutKind.Bottom;

point = Transform(invert ? matTopInvert : matBotInvert, point);

//hack to accomodate input tracking system's float-point sense (based on the core's VideoBuffer height)
//actually, this is needed for a reason similar to the "TouchScreenStart" that I removed.
Expand All @@ -348,8 +353,7 @@ public override Vector2 UntransformPoint(string channel, Vector2 point)
point.Y *= 2;

//in case we're in this layout, we get confused, so fix it
var settings = nds.GetSettings();
if (settings.ScreenLayout == MelonDS.ScreenLayoutKind.Top) point = new(0.0f, 0.0f);
if (settings.ScreenLayout == NDS.ScreenLayoutKind.Top) point = new(0.0f, 0.0f);

//TODO: we probably need more subtle logic here.
//some capability to return -1,-1 perhaps in case the cursor is nowhere.
Expand Down Expand Up @@ -385,23 +389,25 @@ public override void Run()
bool renderTop = false;
bool renderBottom = false;
var settings = nds.GetSettings();
if (settings.ScreenLayout == MelonDS.ScreenLayoutKind.Bottom) renderBottom = true;
if (settings.ScreenLayout == MelonDS.ScreenLayoutKind.Top) renderTop = true;
if (settings.ScreenLayout == MelonDS.ScreenLayoutKind.Vertical) renderTop = renderBottom = true;
if (settings.ScreenLayout == MelonDS.ScreenLayoutKind.Horizontal) renderTop = renderBottom = true;
if (settings.ScreenLayout == NDS.ScreenLayoutKind.Bottom) renderBottom = true;
if (settings.ScreenLayout == NDS.ScreenLayoutKind.Top) renderTop = true;
if (settings.ScreenLayout == NDS.ScreenLayoutKind.Vertical) renderTop = renderBottom = true;
if (settings.ScreenLayout == NDS.ScreenLayoutKind.Horizontal) renderTop = renderBottom = true;

bool invert = settings.ScreenInvert && renderTop && renderBottom;

if (renderTop)
{
GuiRenderer.Modelview.Push();
GuiRenderer.Modelview.PreMultiplyMatrix(matTop);
GuiRenderer.Modelview.PreMultiplyMatrix(invert ? matBot : matTop);
GuiRenderer.DrawSubrect(InputTexture, 0, 0, 256, 192, 0.0f, 0.0f, 1.0f, 0.5f);
GuiRenderer.Modelview.Pop();
}

if (renderBottom)
{
GuiRenderer.Modelview.Push();
GuiRenderer.Modelview.PreMultiplyMatrix(matBot);
GuiRenderer.Modelview.PreMultiplyMatrix(invert ? matTop : matBot);
GuiRenderer.DrawSubrect(InputTexture, 0, 0, 256, 192, 0.0f, 0.5f, 1.0f, 1.0f);
GuiRenderer.Modelview.Pop();
}
Expand Down
8 changes: 5 additions & 3 deletions src/BizHawk.Client.Common/fwmanager/FirmwareManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -208,9 +208,11 @@ public void DoScanAndResolve(PathEntryCollection pathEntries, IDictionary<string

// compute its hash
// NDS's firmware file contains user settings; these are over-written by sync settings, so we shouldn't allow them to impact the hash
var rff = reader.Read(fr.ID == NDS_FIRMWARE
? new FileInfo(Emulation.Cores.Consoles.Nintendo.NDS.MelonDS.CreateModifiedFirmware(userSpec))
: fi);
// fixme: there's way more stuff in nds firmware which can affect the hash. rtc fuckery, mac address, wifi settings, etc etc. a proper way to clear these out needs to come
/*var rff = reader.Read(fr.ID == NDS_FIRMWARE
? new FileInfo(Emulation.Cores.Consoles.Nintendo.NDS.NDS.CreateModifiedFirmware(userSpec))
: fi);*/
var rff = reader.Read(fi);
ri.Size = fi.Length;
ri.Hash = rff.Hash;

Expand Down
1 change: 1 addition & 0 deletions src/BizHawk.Client.Common/movie/PlatformFrameRates.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ public static class PlatformFrameRates
// It probably should be moved to a separate place.
["GB_Clock"] = 2097152.0,
["GBA"] = 262144.0 / 4389.0, // 59.7275005696
["NDS"] = 33513982.0 / 560190.0, // 59.8260982881
["GEN"] = 53693175 / (3420.0 * 262),
["GEN_PAL"] = 53203424 / (3420.0 * 313),

Expand Down
Loading

0 comments on commit 41128ab

Please sign in to comment.