From 6432e18a79c6b8d3167252c478b6c930cb26d571 Mon Sep 17 00:00:00 2001 From: retro-wertz Date: Mon, 10 Dec 2018 05:04:07 +0800 Subject: [PATCH 1/8] gtk:fix audio going on/off when entering Sound Config option Adds check if sound was already enabled and only then only call InitSound() when it was not enabled. This seems to be a better option than calling KillSound() which causes unnecessary audio pop when you are just entering the menu and not adjusting stuff yet. --- src/drivers/sdl/gui.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/drivers/sdl/gui.cpp b/src/drivers/sdl/gui.cpp index 13ab12b9..837eb6d1 100644 --- a/src/drivers/sdl/gui.cpp +++ b/src/drivers/sdl/gui.cpp @@ -1330,8 +1330,10 @@ void toggleSound(GtkWidget* check, gpointer data) { if(gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(check))) { + int last_soundopt; + g_config->getOption("SDL.Sound", &last_soundopt); g_config->setOption("SDL.Sound", 1); - if(GameInfo) + if(GameInfo && !last_soundopt) InitSound(); } else From bc41bc80ee6d5f10f359f2f5d27670a5a22327fd Mon Sep 17 00:00:00 2001 From: Brad Smith Date: Mon, 21 Jan 2019 20:29:23 -0500 Subject: [PATCH 2/8] LUA script for sprite debugging (#35) Useful script adapted from one created by tokumaru (with permission) --- output/luaScripts/Sprites.lua | 110 ++++++++++++++---------- output/luaScripts/SpritesSimple.lua | 45 ++++++++++ web/help/OverviewofIncludedScripts.html | 1 + 3 files changed, 111 insertions(+), 45 deletions(-) create mode 100644 output/luaScripts/SpritesSimple.lua diff --git a/output/luaScripts/Sprites.lua b/output/luaScripts/Sprites.lua index 2f309134..87a4a16f 100644 --- a/output/luaScripts/Sprites.lua +++ b/output/luaScripts/Sprites.lua @@ -1,45 +1,65 @@ --- Simple sprite visualizer --- Draws a box around all sprites on screen. --- rainwarrior 8/23/2016 - -sprite_color = "#FF00FF" -- change to customize color - -sprite_height_last = 8 -sprite_height = 8 - -function oam_dma(a,s,v) - local oam = v * 256 - for i=1,64 do - local is = (i-1) * 4 - local x0 = memory.readbyte(oam + is + 3) - local x1 = x0 + 7 - local y0 = memory.readbyte(oam + is + 0) + 1 - local y1 = y0 + (sprite_height_last - 1) - gui.box(x0,y0,x1,y1,"",sprite_color) - end -end - -function ppu_ctrl(a,s,v) - if AND(v,0x20) == 0 then - sprite_height = 8 - else - sprite_height = 16 - end -end - -function frame_end() - -- information about sprite height will be behind by 1 frame - -- (or potentially wrong if changed before the end of the frame) - -- in most games this doesn't change from frame to frame, though - sprite_height_last = sprite_height -end - --- main - -memory.registerwrite(0x4014,1,oam_dma) -memory.registerwrite(0x2000,1,ppu_ctrl) -emu.registerafter(frame_end) - -while (true) do - emu.frameadvance() -end +-- Sprite visualizer +-- +-- Draws a box around all sprites on screen, +-- hover with the mouse to inspect data. +-- +-- Original by tokumaru 2016-10-08: +-- https://forums.nesdev.com/viewtopic.php?p=181008#p181008 + +numSpriteHeight = 8 +strFillColor = "#ffffff3f" +strOutlineColor = "#ff0000bf" +strHighlightColor = "#ffffffbf" + +function readSpriteAttributes(a,s,v) + local numAddress = v * 256 + tabSpriteAttributes = {} + for numIndex = 0, 255 do + table.insert(tabSpriteAttributes, memory.readbyte(numAddress + numIndex)) + end +end + +function setSpriteHeight(a,s,v) + if AND(a, 7) == 0 then + numSpriteHeight = AND((v / 4), 8) + 8 + end +end + +function drawBoxes() + local tabInput, numSpriteX, numSpriteY, numDetailsBase, numTextY = input.read() + if tabSpriteAttributes ~= nill then + for numBase = 252, 0, -4 do + numSpriteX0 = tabSpriteAttributes[numBase + 4] + numSpriteY0 = tabSpriteAttributes[numBase + 1] + 1 + numSpriteX1 = numSpriteX0 + 7 + numSpriteY1 = numSpriteY0 + numSpriteHeight - 1 + if (tabInput.xmouse >= numSpriteX0) and (tabInput.xmouse <= numSpriteX1) and (tabInput.ymouse >= numSpriteY0) and (tabInput.ymouse <= numSpriteY1) then + gui.box(numSpriteX0, numSpriteY0, numSpriteX1, numSpriteY1, strHighlightColor, strOutlineColor) + numDetailsBase = numBase + else + gui.box(numSpriteX0, numSpriteY0, numSpriteX1, numSpriteY1, strFillColor, strOutlineColor) + end + end + end + if numDetailsBase ~= nil then + numTextY = (1 - math.floor(tabInput.ymouse / 120)) * 127 + 16 + gui.text(16, numTextY, string.format("OAM Slot: %d", numDetailsBase / 4)); numTextY = numTextY + 9 + gui.text(16, numTextY, string.format("OAM Offset: $%02X", numDetailsBase)); numTextY = numTextY + 9 + gui.text(16, numTextY, string.format("Sprite X: $%02X", tabSpriteAttributes[numDetailsBase + 4])); numTextY = numTextY + 9 + gui.text(16, numTextY, string.format("Sprite Y: $%02X", tabSpriteAttributes[numDetailsBase + 1])); numTextY = numTextY + 9 + gui.text(16, numTextY, string.format("Tile ID: $%02X", tabSpriteAttributes[numDetailsBase + 2])); numTextY = numTextY + 9 + gui.text(16, numTextY, string.format("Palette: %d", AND(tabSpriteAttributes[numDetailsBase + 3], 0x03))); numTextY = numTextY + 9 + gui.text(16, numTextY, string.format("Behind Background: %d", AND(tabSpriteAttributes[numDetailsBase + 3], 0x20) / 0x20)); numTextY = numTextY + 9 + gui.text(16, numTextY, string.format("Flip X: %d", AND(tabSpriteAttributes[numDetailsBase + 3], 0x40) / 0x40)); numTextY = numTextY + 9 + gui.text(16, numTextY, string.format("Flip Y: %d", AND(tabSpriteAttributes[numDetailsBase + 3], 0x80) / 0x80)); numTextY = numTextY + 9 + end + gui.box(tabInput.xmouse - 2, tabInput.ymouse - 2, tabInput.xmouse + 2, tabInput.ymouse + 2, strHighlightColor, strOutlineColor) +end + +memory.registerwrite(0x4014, 0x0001, readSpriteAttributes) +memory.registerwrite(0x2000, 0x2000, setSpriteHeight) +gui.register(drawBoxes) + +while (true) do + emu.frameadvance() +end diff --git a/output/luaScripts/SpritesSimple.lua b/output/luaScripts/SpritesSimple.lua new file mode 100644 index 00000000..db1c2226 --- /dev/null +++ b/output/luaScripts/SpritesSimple.lua @@ -0,0 +1,45 @@ +-- Simple sprite visualizer +-- Draws a box around all sprites on screen. +-- rainwarrior 8/23/2016 + +sprite_color = "#FF00FF" -- change to customize color + +sprite_height_last = 8 +sprite_height = 8 + +function oam_dma(a,s,v) + local oam = v * 256 + for i=1,64 do + local is = (i-1) * 4 + local x0 = memory.readbyte(oam + is + 3) + local x1 = x0 + 7 + local y0 = memory.readbyte(oam + is + 0) + 1 + local y1 = y0 + (sprite_height_last - 1) + gui.box(x0,y0,x1,y1,"",sprite_color) + end +end + +function ppu_ctrl(a,s,v) + if AND(v,0x20) == 0 then + sprite_height = 8 + else + sprite_height = 16 + end +end + +function frame_end() + -- information about sprite height will be behind by 1 frame + -- (or potentially wrong if changed before the end of the frame) + -- in most games this doesn't change from frame to frame, though + sprite_height_last = sprite_height +end + +-- main + +memory.registerwrite(0x4014,1,oam_dma) +memory.registerwrite(0x2000,1,ppu_ctrl) +emu.registerafter(frame_end) + +while (true) do + emu.frameadvance() +end diff --git a/web/help/OverviewofIncludedScripts.html b/web/help/OverviewofIncludedScripts.html index f58bf0f6..f8587344 100644 --- a/web/help/OverviewofIncludedScripts.html +++ b/web/help/OverviewofIncludedScripts.html @@ -74,6 +74,7 @@
  • Mutlitrack2.lua        -        Tracks future input that FCEUX promptly loses on state-load, for TAS
  • Subtitler.lua                -        For easier use of FCEUX's built-in subtitles for .fm2 files
  • Rewinder.lua        -        A way to rewind backwards by pressing a button
  • +
  • Sprites.lua        -        Sprite debugging highlights all sprites on screen, with mouse hover to inspect.


  • From cddb8af1a25fc56ea03c71f7187e6125b6aa15ab Mon Sep 17 00:00:00 2001 From: feos Date: Tue, 22 Jan 2019 23:58:58 +0300 Subject: [PATCH 3/8] SoundDisplay2.lua tweaks --- output/luaScripts/SoundDisplay2.lua | 45 +++++++++++++++++++---------- 1 file changed, 29 insertions(+), 16 deletions(-) diff --git a/output/luaScripts/SoundDisplay2.lua b/output/luaScripts/SoundDisplay2.lua index 6402ed76..a399603a 100644 --- a/output/luaScripts/SoundDisplay2.lua +++ b/output/luaScripts/SoundDisplay2.lua @@ -1,4 +1,4 @@ --- feos, 2012 +-- feos, r57shell, 2012-2018 -- gui.box frame simulates transparency print("Hi-hat and keys may glitch if you produce sound effects.") @@ -23,12 +23,18 @@ function Draw() snd = sound.get() keys = input.get() + if iterator == 1 then + kb.y = 30 + else + kb.y = 154 + end + -- do only at the first frame if #volumes.S1V == 1 then channels = { - Square1 = {x=1, y=9, vol=volumes.S1V, color=volumes.S1C, duty=0, midi=0, semitone=0, octave=0, prev_semitone=0, float = {}}, - Square2 = {x=1+45*1, y=9, vol=volumes.S2V, color=volumes.S2C, duty=0, midi=0, semitone=0, octave=0, prev_semitone=0, float = {}}, - Triangle = {x=1+45*2, y=9, vol=volumes.TV, midi=0, semitone=0, octave=0, prev_semitone=0, float = {}}, + Square1 = {x=1, y=9, vol=volumes.S1V, color=volumes.S1C, duty=0, midi=0, semitone=0, octave=0, prev_semitone=0, float = {}, floaty = {}, floatz = {}}, + Square2 = {x=1+45*1, y=9, vol=volumes.S2V, color=volumes.S2C, duty=0, midi=0, semitone=0, octave=0, prev_semitone=0, float = {}, floaty = {}, floatz = {}}, + Triangle = {x=1+45*2, y=9, vol=volumes.TV, midi=0, semitone=0, octave=0, prev_semitone=0, float = {}, floaty = {}, floatz = {}}, Noise = {x=1+45*3, y=9, vol=volumes.NV, midi=0, semitone=0, octave=0}, DPCM = {x=1+45*4, y=9, vol=volumes.DPCMV} } @@ -120,7 +126,7 @@ function Draw() if (kb.on) then -- capture leftclicks - if keys.xmouse <= 256 and keys.xmouse >= 205 and keys.ymouse >= 154 and keys.ymouse <= 181 then + if keys.xmouse <= 256 and keys.xmouse >= 205 and keys.ymouse >= kb.y and keys.ymouse <= kb.y+27 then if keys["leftclick"] and not prev_keys["leftclick"] then kb.on = false end end -- draw the kayboard @@ -185,7 +191,7 @@ function Draw() gui.line(kb.x+200, kb.y, kb.x+200, kb.y+16, "#00000088") else -- capture leftclicks - if keys.xmouse <= 256 and keys.xmouse >= 205 and keys.ymouse >= 154 and keys.ymouse <= 181 then + if keys.xmouse <= 256 and keys.xmouse >= 205 and keys.ymouse >= kb.y and keys.ymouse <= kb.y+27 then if keys["leftclick"] and not prev_keys["leftclick"] then kb.on = true end end end @@ -199,6 +205,7 @@ function Draw() if name == "Square1" or name == "Square2" or name == "Triangle" then if chan.prev_semitone ~= chan.semitone then + local len_prev = #chan.float if chan.semitone == "C" then table.insert(chan.float, 1, kb.x+1 +28*(chan.octave-1)) elseif chan.semitone == "D" then table.insert(chan.float, 1, kb.x+5 +28*(chan.octave-1)) elseif chan.semitone == "E" then table.insert(chan.float, 1, kb.x+9 +28*(chan.octave-1)) @@ -212,6 +219,9 @@ function Draw() elseif chan.semitone == "G#" then table.insert(chan.float, 1, kb.x+19+28*(chan.octave-1)) elseif chan.semitone == "A#" then table.insert(chan.float, 1, kb.x+23+28*(chan.octave-1)) end + if len_prev ~= #chan.float then table.insert(chan.floaty, 1, 0) table.insert(chan.floatz, 1, 0) end + elseif chan.semitone ~= '--' then + chan.floaty[1] = 0 end if name == "Triangle" then color = "#00aaffff" @@ -219,17 +229,20 @@ function Draw() else color = "#aa00ccff" end - if #chan.float < 13 then - for i = 2, #chan.float do - if movie.framecount()%2 == 0 then gui.box(chan.float[i]-1, 161+i*5, chan.float[i]+3, 165+i*5, "#eedd2200") end - gui.box(chan.float[i], 162+i*5, chan.float[i]+2, 164+i*5, color) + for i = 1, #chan.float do + local y = kb.y+chan.floaty[i] + local z = kb.y+chan.floatz[i] + chan.floaty[i] = chan.floaty[i] + 1 + chan.floatz[i] = chan.floatz[i] + 1 + if y+17<=z+15 then + if movie.framecount()%2 == 0 then gui.box(chan.float[i]-1, y+16, chan.float[i]+3, z+16, "#eedd2200") end + gui.box(chan.float[i], y+17, chan.float[i]+2, z+15, color) end - else - for i = 2, 13 do - if movie.framecount()%2 == 0 then gui.box(chan.float[i]-1, 161+i*5, chan.float[i]+3, 165+i*5, "#eedd2200") end - gui.box(chan.float[i], 162+i*5, chan.float[i]+2, 164+i*5, color) - end - table.remove(chan.float, 14) + end + while #chan.float ~= 0 and chan.floaty[#chan.float] > 224 do + table.remove(chan.float, #chan.float) + table.remove(chan.floaty, #chan.floaty) + table.remove(chan.floatz, #chan.floatz) end end end From 01c3f40f1d1deb0050452ce79c5ce64df5040c57 Mon Sep 17 00:00:00 2001 From: Brad Smith Date: Sat, 26 Jan 2019 20:46:58 -0500 Subject: [PATCH 4/8] windows mouse left/right buttons should be independent, not XOR --- src/drivers/win/window.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/drivers/win/window.cpp b/src/drivers/win/window.cpp index 37291a21..6ab81e43 100644 --- a/src/drivers/win/window.cpp +++ b/src/drivers/win/window.cpp @@ -1224,7 +1224,7 @@ void GetMouseData(uint32 (&md)[3]) } md[0] += VNSCLIP; md[1] += FSettings.FirstSLine; - md[2] = ((mouseb == MK_LBUTTON) ? 1 : 0) | (( mouseb == MK_RBUTTON ) ? 2 : 0); + md[2] = ((mouseb & MK_LBUTTON) ? 1 : 0) | (( mouseb & MK_RBUTTON ) ? 2 : 0); } void GetMouseRelative(int32 (&md)[3]) @@ -3234,4 +3234,4 @@ void SaveSnapshotAs() if(GetSaveFileName(&ofn)) FCEUI_SetSnapshotAsName(nameo); FCEUI_SaveSnapshotAs(); -} \ No newline at end of file +} From 20f0783a96851273c510a762886f2db2ad88ae70 Mon Sep 17 00:00:00 2001 From: Brad Smith Date: Sat, 26 Jan 2019 21:04:07 -0500 Subject: [PATCH 5/8] windows mouse left/right buttons should be independent, not XOR (forgot the additional "relative" mouse implementation with last commit) --- src/drivers/win/window.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/drivers/win/window.cpp b/src/drivers/win/window.cpp index 6ab81e43..089b5ed8 100644 --- a/src/drivers/win/window.cpp +++ b/src/drivers/win/window.cpp @@ -1264,7 +1264,7 @@ void GetMouseRelative(int32 (&md)[3]) md[0] = dx; md[1] = dy; - md[2] = ((mouseb == MK_LBUTTON) ? 1 : 0) | (( mouseb == MK_RBUTTON ) ? 2 : 0); + md[2] = ((mouseb & MK_LBUTTON) ? 1 : 0) | (( mouseb & MK_RBUTTON ) ? 2 : 0); } void DumpSubtitles(HWND hWnd) From adc9efec5635f4806eb7e9bb238209a3daaf497e Mon Sep 17 00:00:00 2001 From: zeromus Date: Sun, 27 Jan 2019 20:45:23 -0500 Subject: [PATCH 6/8] run 1st frame of lua scripts after the lua console is hooked up, rather than before (fixes #33) --- src/lua-engine.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/lua-engine.cpp b/src/lua-engine.cpp index 033aabb8..6748dca9 100644 --- a/src/lua-engine.cpp +++ b/src/lua-engine.cpp @@ -6185,8 +6185,6 @@ int FCEU_LoadLuaCode(const char *filename, const char *arg) { //wasPaused = FCEUI_EmulationPaused(); //if (wasPaused) FCEUI_ToggleEmulationPause(); - // And run it right now. :) - FCEU_LuaFrameBoundary(); // Set up our protection hook to be executed once every 10,000 bytecode instructions. //lua_sethook(thread, FCEU_LuaHookFunction, LUA_MASKCOUNT, 10000); @@ -6206,6 +6204,9 @@ int FCEU_LoadLuaCode(const char *filename, const char *arg) { if (info_onstart) info_onstart(info_uid); + // And run it right now. :) + FCEU_LuaFrameBoundary(); + // We're done. return 1; } From f8d5a9136324ceb736da556f4c2f08b9a83f1350 Mon Sep 17 00:00:00 2001 From: zeromus Date: Sun, 27 Jan 2019 21:32:22 -0500 Subject: [PATCH 7/8] lua: make emu.speedmode nothrottle and maximum set to 100% frameskip, as originally intended (fixes #34) --- src/drivers/win/main.cpp | 3 +++ src/lua-engine.cpp | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/src/drivers/win/main.cpp b/src/drivers/win/main.cpp index 1190e2a7..1ba2fdf9 100644 --- a/src/drivers/win/main.cpp +++ b/src/drivers/win/main.cpp @@ -901,6 +901,9 @@ doloopy: } else skippy = 0; + if(FCEU_LuaFrameskip()) + skippy = true; + FCEUI_Emulate(&gfx, &sound, &ssize, skippy); //emulate a single frame FCEUD_Update(gfx, sound, ssize); //update displays and debug tools diff --git a/src/lua-engine.cpp b/src/lua-engine.cpp index 6748dca9..6002780d 100644 --- a/src/lua-engine.cpp +++ b/src/lua-engine.cpp @@ -327,7 +327,7 @@ int FCEU_LuaSpeed() { * Asks Lua if it wants control whether this frame is skipped. * Returns 0 if no, 1 if frame should be skipped, -1 if it should not be. */ -int FCEU_LuaFrameSkip() { +int FCEU_LuaFrameskip() { if (!L || !luaRunning) return 0; From 9f7147c42aacbc6008fcd2c5b8abaa878f434fab Mon Sep 17 00:00:00 2001 From: zeromus Date: Sat, 2 Feb 2019 03:53:10 -0500 Subject: [PATCH 8/8] fix overflow in RTS trace logging (maybe) (fixes #30) --- src/drivers/win/tracer.cpp | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/src/drivers/win/tracer.cpp b/src/drivers/win/tracer.cpp index 47cec2ad..a24ca6a8 100644 --- a/src/drivers/win/tracer.cpp +++ b/src/drivers/win/tracer.cpp @@ -859,11 +859,8 @@ void FCEUD_TraceInstruction(uint8 *opcode, int size) { // special case: an RTS opcode // add "----------" to emphasize the end of subroutine - strcat(str_disassembly, " "); - int i = strlen(str_disassembly); - for (; i < (LOG_DISASSEMBLY_MAX_LEN - 2); ++i) - str_disassembly[i] = '-'; - str_disassembly[i] = 0; + static const char* emphasize = " -------------------------------------------------------------------------------------------------------------------------"; + strncat(str_disassembly, emphasize, LOG_DISASSEMBLY_MAX_LEN - strlen(str_disassembly) - 1); } // stretch the disassembly string out if we have to output other stuff. if ((logging_options & (LOG_REGISTERS|LOG_PROCESSOR_STATUS)) && !(logging_options & LOG_TO_THE_LEFT))