Debugger: Lua - Added more scripts, updated Game Boy mode script

This commit is contained in:
Sour 2018-05-07 23:06:51 -04:00
parent add52c64be
commit da91d36c8f
5 changed files with 206 additions and 59 deletions

View file

@ -30,7 +30,7 @@ namespace Mesen.GUI.Debugger
{
InitializeComponent();
List<string> builtInScripts = new List<string> { "DmcCapture.lua", "DrawMode.lua", "GameBoyMode.lua", "Grid.lua", "ReverseMode.lua", "SpriteBox.lua" };
List<string> builtInScripts = new List<string> { "DmcCapture.lua", "DrawMode.lua", "Example.lua", "GameBoyMode.lua", "Grid.lua", "LogParallax.lua", "ModifyScreen.lua", "ReverseMode.lua", "SpriteBox.lua" };
foreach(string script in builtInScripts) {
ToolStripItem item = mnuBuiltInScripts.DropDownItems.Add(script);
item.Click += (s, e) => {

View file

@ -23,76 +23,86 @@ function Main()
holdLeft = true
stencil = true
window_X = mouse.x - 80
window_Y = mouse.y - 72
end
end
window_Y = mouse.y - 72
end
end
else
holdLeft = false
end
if mouse.right then
if not holdRight then
holdRight = true
colorB = color1
color1 = color2
color2 = color3
color3 = color4
color4 = colorB
cycleP = cycleP + 1
if cycleP == 4 then
cycleP = 0
colorB = color5
color5 = color6
color6 = color7
color7 = color8
color8 = colorB
end
end
else
holdRight = false
holdLeft = false
end
if stencil then
if window_X > 0 then
emu.drawRectangle(0, window_Y, window_X, 144, 0x000000, true)
if window_X > 0 then
emu.drawRectangle(0, window_Y, window_X, 144, 0x000000, true)
end
if window_X < 96 then
emu.drawRectangle(window_X + 160, window_Y, 96 - window_X, 144, 0x000000, true)
if window_X < 96 then
emu.drawRectangle(window_X + 160, window_Y, 96 - window_X, 144, 0x000000, true)
end
if window_Y > 0 then
emu.drawRectangle(0, 0, 256, window_Y, 0x000000, true)
emu.drawRectangle(0, 0, 256, window_Y, 0x000000, true)
end
if window_Y < 96 then
emu.drawRectangle(0, window_Y + 144, 256, 96 - window_Y, 0x000000, true)
if window_Y < 96 then
emu.drawRectangle(0, window_Y + 144, 256, 96 - window_Y, 0x000000, true)
end
end
for x = 0,0x0f,4 do
emu.write(x, color1, emu.memType.palette)
emu.write(x + 1, color2, emu.memType.palette)
emu.write(x + 2, color3, emu.memType.palette)
emu.write(x + 3, color4, emu.memType.palette)
emu.write(x + 16, color1, emu.memType.palette)
emu.write(x + 17, color6, emu.memType.palette)
emu.write(x + 18, color7, emu.memType.palette)
emu.write(x + 19, color8, emu.memType.palette)
if mouse.right then
if not holdRight then
holdRight = true
UI_X = mouse.x - selectX
UI_Y = mouse.y - selectY
end
emu.drawRectangle(UI_X+16, UI_Y, 128, 16, 0x808080, true)
emu.drawRectangle(UI_X, UI_Y+16, 16, 128, 0x808080, true)
for x = UI_X+16, UI_X+128, 16 do
emu.drawRectangle(x, UI_Y, 17, 17, 0x404040)
end
for y = UI_Y+16, UI_Y+128, 16 do
emu.drawRectangle(UI_X, y, 17, 17, 0x404040)
end
if mouse.x > UI_X + 16 and mouse.x < UI_X + 145 and mouse.y > UI_Y + 16 and mouse.y < UI_Y + 145 then
paletteBg = (mouse.x - 1 - UI_X) >> 4
paletteSpr = (mouse.y - 1 - UI_Y) >> 4
offsetX = (UI_X & 0x0f) + 1
offsetY = (UI_Y & 0x0f) + 1
emu.drawRectangle(((mouse.x - offsetX) & 0xf0) + offsetX, UI_Y+1, 15, 15, 0xff0000, true)
emu.drawRectangle( UI_X+1, ((mouse.y - offsetY) & 0xf0) + offsetY, 15, 15, 0xff0000, true)
emu.drawLine(UI_X+17, mouse.y, mouse.x, mouse.y, 0xff0000)
emu.drawLine(mouse.x, UI_Y+17, mouse.x, mouse.y, 0xff0000)
selectX = mouse.x - UI_X
selectY = mouse.y - UI_Y
end
for i = 1,#text,3 do
emu.drawString(UI_X + text[i], UI_Y + text[i+1], text[i+2], 0xffffff, 0xff000000)
end
else
holdRight = false
end
end
for palAddr = 0,0x0f,4 do
emu.write(palAddr, color[paletteBg][1], emu.memType.palette)
emu.write(palAddr + 1, color[paletteBg][2], emu.memType.palette)
emu.write(palAddr + 2, color[paletteBg][3], emu.memType.palette)
emu.write(palAddr + 3, color[paletteBg][4], emu.memType.palette)
emu.write(palAddr + 16, color[paletteBg][1], emu.memType.palette)
emu.write(palAddr + 17, color[paletteSpr][1], emu.memType.palette)
emu.write(palAddr + 18, color[paletteSpr][2], emu.memType.palette)
emu.write(palAddr + 19, color[paletteSpr][3], emu.memType.palette)
end
end
window_X = 48
window_Y = 48
cycleP = 0
colorB = 0
color1 = 0x38
color2 = 0x28
color3 = 0x18
color4 = 0x08
color5 = 0x38
color6 = 0x28
color7 = 0x18
color8 = 0x08
stencil = true
stencil = false
holdLeft = false
holdRight = false
window_X = 48
window_Y = 48
selectX = 72
selectY = 72
paletteSpr = 4
paletteBg = 4
color = {{0x38,0x28,0x18,0x08},{0x28,0x18,0x08,0x38},{0x18,0x08,0x38,0x28},{0x08,0x38,0x28,0x18},
{0x08,0x18,0x28,0x38},{0x18,0x28,0x38,0x08},{0x28,0x38,0x08,0x18},{0x38,0x08,0x18,0x28}}
text = {48,-9,"Background",22,5,"1",38,5,"2",54,5,"3",70,5,"4",86,5,"5",102,5,"6",
118,5,"7",134,5,"8",-6,51,"S",-6,57,"p",-6,64,"r",-6,72,"i",-7,80,"t",-7,86,"e",
6,21,"1",6,37,"2",6,53,"3",6,69,"4",6,85,"5",6,101,"6",6,117,"7",6,133,"8"}
emu.addEventCallback(Main, emu.eventType.startFrame)
emu.displayMessage("Script", "GameBoy mode")
emu.displayMessage("Script", "Game Boy mode")

View file

@ -0,0 +1,19 @@
-----------------------
-- Name: Log Parallax
-- Author: spiiin
-----------------------
-- Draws a red line over each scanline that CPU writes to $2005 or $2006 occurred
-----------------------
PPUSCROLL = 0x2005;
colorCode = 0x4000FF00;
function onScroll(address, value)
local state = emu.getState();
emu.log("Scrolling change. Scanline: "..state.ppu.scanline.." Value:"..value);
local color = colorCode + state.ppu.scanline;
emu.drawLine(0, state.ppu.scanline, 256, state.ppu.scanline, color, 1)
end;
emu.addMemoryCallback(onScroll, emu.memCallbackType.cpuWrite, PPUSCROLL, PPUSCROLL+1);
emu.displayMessage("Script", "Log Parallax")

View file

@ -0,0 +1,112 @@
-----------------------
-- Name: Modify Screen
-- Author: spiiin
-----------------------
-- Alters the screen buffer to create various video filters
-- Press 0 to 4 to select a filter
-----------------------
shaderType = 0
function getCurrentFrame()
return emu.getState().ppu.frameCount
end
function makeRed()
local buffer = emu.getScreenBuffer()
for i, p in pairs(buffer) do
buffer[i] = buffer[i] & 0xFFFF0000
end
emu.setScreenBuffer(buffer)
end
function onlyOddLines()
local width = 256
local buffer = emu.getScreenBuffer()
for i, p in pairs(buffer) do
local x = i % width
local y = i // width
if y % 2 == 0 then
buffer[i] = 0x00000000
end
end
emu.setScreenBuffer(buffer)
end
function blink()
local buffer = emu.getScreenBuffer()
local frame = getCurrentFrame()
local blinkPeriod = 24*5
local blinkTime = 10
if frame % blinkPeriod < blinkTime then
for i, p in pairs(buffer) do
buffer[i] = 0x0000FF00
end
end
emu.setScreenBuffer(buffer)
end
function waves()
local frame = getCurrentFrame()
local maxWave = 40
local waveSpeed = 4
local anim = (frame // waveSpeed % maxWave)
local animTable = {
-10,-9,-8,-7,-6,-5,-4,-3,-2,-1,
0, 1, 2, 3, 4, 5, 6, 7, 8, 9,
10, 9, 8, 7, 6, 5, 4, 3, 2, 1,
0,-1,-2,-3,-4,-5,-6,-7,-8,-9,
}
anim = animTable[anim+1]
local width = 256
local buffer = emu.getScreenBuffer()
local buffer2 = emu.getScreenBuffer()
for i, p in pairs(buffer) do
local x = i % width
local y = i // width
if y % 2 == 0 then
buffer[i] = buffer2[i+anim]
else
buffer[i] = buffer2[i-anim]
end
end
emu.setScreenBuffer(buffer)
end
function endFrame()
if shaderType == 1 then
makeRed()
elseif shaderType == 2 then
onlyOddLines()
elseif shaderType == 3 then
blink()
elseif shaderType == 4 then
waves()
end
end
function checkKeys()
if emu.isKeyPressed("0") and shaderType ~= 0 then
shaderType = 0
emu.displayMessage("Info", "No shader selected")
elseif emu.isKeyPressed("1") and shaderType ~= 1 then
shaderType = 1
emu.displayMessage("Info", "Shader Red selected")
elseif emu.isKeyPressed("2") and shaderType ~= 2 then
shaderType = 2
emu.displayMessage("Info", "Shader OddLines selected")
elseif emu.isKeyPressed("3") and shaderType ~= 3 then
shaderType = 3
emu.displayMessage("Info", "Shader Blink selected")
elseif emu.isKeyPressed("4") and shaderType ~= 4 then
shaderType = 4
emu.displayMessage("Info", "Shader Waves selected")
end
end
emu.addEventCallback(endFrame, emu.eventType.endFrame);
emu.addEventCallback(checkKeys, emu.eventType.inputPolled);
local infoStr = "Press keys from 0 to 4 to change shaders"
emu.displayMessage("Info", infoStr)
emu.log(infoStr)

View file

@ -1180,6 +1180,12 @@
<None Include="Dependencies\LuaScripts\Grid.lua">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Include="Dependencies\LuaScripts\LogParallax.lua">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Include="Dependencies\LuaScripts\ModifyScreen.lua">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Include="Dependencies\LuaScripts\ReverseMode.lua">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>