User File #12369529797861350

Upload All User Files

#12369529797861350 - Helper script for TASEditor (FCEUX): Tap keys to toggle input.

TASEditor_XORmix_v2.lua
934 downloads
Uploaded 1/31/2014 1:07 AM by FatRatKnight (see all 245)
Run FCEUX. Engage TASEditor. Make sure readonly mode is on. Tap a key you've set for player 1. Note it updates TASEditor with the key you just tapped. If Recorder "All" option is selected in TASEditor, the script will use controls you set for all four players. If an individual player is selected for the Recorder, only player 1 controls are checked, but will toggle button presses of the selected player.
May seem odd, but the script requires readonly mode active in order to work properly. If, for some reason, you set the "Recording" check box, be sure to either stop the script or clear the "Auto function" check box. I have not defined a behavior for the script to follow when readonly mode is off.
It is very similar to a script I posted a while back. The only real updates are that it reports what input changed in the history box, and that there are comments indicating where to stick your own code if you need something more. If, by some chance, the script picks up multiple pressed keys at the same time, it will report all pressed buttons in the history without problems.
Intended to reduce reliance on the mouse for precision edits of the input movie. I suppose you could TAS backwards with it if you really wanted to...
--[[  Leeland Kirwan (FatRatKnight), 2014
Allows user input to "mix" with TAS Editor using XOR logic.
If Recording is checked, this script will do its intended job.

Tap a P1 key to toggle input. If "All" is selected, will use other player keys
for related player. If an individual player is selected, uses P1 controls. You
can hold down a key to affect multiple frames, toggling the key on each frame.

For reference, Superimpose uses OR logic, and does not allow user input to
clear stored input. A great inconvience for those wishing to use the keyboard
to toggle individual input rather than mouse.
]]--

local btnstr= {A = "A", B   = "B", select= "S", start= "T",
               up= "U", down= "D", left  = "L", right= "R"}
local btnval= {A = 0x01, B   = 0x02, select= 0x04, start= 0x08,
               up= 0x10, down= 0x20, left  = 0x40, right= 0x80}
local plval= {["1P"]= 1, ["2P"]= 2, ["3P"]= 3, ["4P"]= 4}
local OldJoy= {{},{},{},{}}
--*****************************************************************************
local function InputToggle()
--*****************************************************************************
--Needs readonly mode to work, but won't interfere too much otherwise.
--Toggles inputs recorded in TAS Editor.

    if not taseditor.engaged() then return end  -- Escape

    taseditor.clearinputchanges() -- Guessing something horrible w/o this.

    local frame= emu.framecount()

    local plSel= plval[taseditor.getrecordermode()]
    local plLow = plSel or 1   -- Get the for loop range!
    local plHigh= plSel or 4   -- Hardcoded 4 doesn't appear harmful...

    local P1joy= nil                                -- If one player, get P1.
    if plSel then P1joy= joypad.getimmediate(1) end -- Otherwise, get all.

    local changed= false  -- Flag, so I don't interfere too much
    local History= ""     -- Information for TASer in History list

    for pl= plLow, plHigh do
        local pad= taseditor.getinput(frame,pl)
        local joy= P1joy or joypad.getimmediate(pl) -- Pick out the joypad

        local mask= 0                     -- Convert messy table to numbers
        for btn,pressed in pairs(joy) do
            if pressed and not OldJoy[pl][btn] then
                mask= bit.bor(mask,btnval[btn])
                History= History .. pl .. btnstr[btn]
            end
        end

        taseditor.submitinputchange(frame,pl,bit.bxor(pad,mask))
        OldJoy[pl]= joy  -- To avoid repeated triggers
        changed= changed or (mask ~= 0) -- If the bitmask did something, apply!
    end

    if changed then taseditor.applyinputchanges(History) end
end
taseditor.registerauto(InputToggle)

--#############################################################################
--#############################################################################
--If you need some other code and other registers, I recommend them here.
--If you need the "while true do" loop, that's down below.



--#############################################################################
--#############################################################################
-- Ugh, need this loop on the very bottom...

--*****************************************************************************
while true do
--*****************************************************************************
-- Exists to detect frame advances, and thus clear the OldJoy array.
    for i= 1, 4 do OldJoy[i]= {} end -- Retrigger keys

-- Any code that needs this loop can go here.

    emu.frameadvance()
end