pixelpedant Posted June 3, 2020 Share Posted June 3, 2020 Here's a simple AutoHotKey script that I'm now using, which others here may have use for here (or might find improvements for), which I'm presently using to automate XB code entry (but potentially, any text entry) into MAME via the Windows clipboard. For most purposes, making programs available in MAME by saving them in TI Image Tool has been a great solution, for me. And just entering a program via Classic99, then using it in MAME is an option. But lately I've been working on a speech program for which accurate speech emulation is naturally at a premium (hence MAME), which is a lot of test/modify/test/modify/test/modify in mid-size batches, and for which assembly routines are being stored along with the program via HMLOADER (so I need to modify it in place). So I really needed a more efficient way to update 30 lines of code (or whatever) in MAME. The basic idea is to read the clipboard one character at a time, and 1) Enter each character in a way hospitable to the MAME/TI keyboard layout (e.g., ALT+R signifying Fctn+R for "[") and the machine's tolerances with respect to keystroke timing. 2) For newlines, ignore CR, but on LF, press Enter, then wait a little bit for control to return to the user before typing the next line. There's no realistic way to know (from the script's standpoint) how long it will actually take for new keystrokes to be accepted after a line is submitted, so that could be tweaked in the one direction or the other. The SetKeyDelay timing and the newline Sleep are the major timing decisions. But for the present, this serves as a simple but convenient solution for me, for automating XB program entry (or more like small to mid-size updates) in MAME. Typing out the contents of the clipboard in MAME while using machine-appropriate keys where necessary and handling newlines. Maybe someone else will have a use for it. #IfWinActive ahk_exe Mame64.exe { Insert:: SetKeyDelay 25,65 Loop, parse, clipboard { switch A_LoopField { case Chr(34): Send !p case "#": Send +{3} case "_": Send !{u} case "?": Send !{i} case "'": Send !{o} case "~": Send !{w} case "|": Send !{a} case "\": Send !{z} case "-": Send +{/} case "[": Send !{r} case "]": Send !{t} case Chr(96): Send !{c} case "{": Send !{f} case "}": Send !{g} case Chr(13): Sleep 0 case Chr(10): { Send {Enter} Sleep, 550 } default: Send %A_Loopfield% } } return } So for example, this is some code typing itself in MAME, via the clipboard (and the timings in the script above). Initiated by pressing the Insert key: f7cdCFsNOJ.mp4 3 Quote Link to comment Share on other sites More sharing options...
+mizapf Posted June 3, 2020 Share Posted June 3, 2020 Looks good, but you have to be careful when the program gets longer. In TI BASIC, entering a line in a long program takes a lot of time; Extended Basic is much faster, of course. 1 Quote Link to comment Share on other sites More sharing options...
pixelpedant Posted June 5, 2020 Author Share Posted June 5, 2020 (edited) An updated, longer version of this script with some basic inspection mainly for the sake of "have I screwed up my offline code entry or code copying" type concerns. So I can know that once it starts copying, it's going to be copying what at least looks like correctly numbered XB, and if I accidentally initiate copying with inappropriate clipboard contents, it will indicate this and prompt for confirmation. Basically, if there's a fundamental, transparent problem with structure of the clipboard contents from the point of view of pasting as XB, I get this sort of thing: #IfWinActive ahk_exe Mame64.exe { Insert:: lines:=[] prev:=0 Loop, parse, clipboard,`n,`r ; split on LF, omit CR if present { content:=StrSplit(A_LoopField,A_Space,,2) num:=content[1] if (num="") { continue } else if num is not digit ; if no valid line number { mess:="No valid line number for line " A_Index ". in text. Line reads `n`n" Trim(A_Loopfield) "`n`nEnter anyway?" MsgBox, 4, , %mess% IfMsgBox No { return } continue } else if (lines[num]) ; if line number duplicated { mess:="Line number " num " used here:`n`n" num A_Space lines[num] "`n`nAlso found here:`n`n " num A_Space content[2] "`n`nEnter anyway?" MsgBox, 4, , %mess% ifMsgBox No { return } } else if (num<prev) ; if line numbers out of sequence { mess:="Line number " prev " precedes line number " num " as follows:`n`n" prev A_Space lines[prev] "`n" num A_Space content[2] "`n`nEnter anyway?" MsgBox, 4, , %mess% ifMsgBox No { return } } lines[num]:=content[2] prev:=num } SetKeyDelay, 25,65 ; pre-press delay and press duration in ms Sleep, 300 Loop, parse, clipboard,,`r { switch A_LoopField { case Chr(34): Send !p case "#": Send +{3} case "_": Send !{u} case "?": Send !{i} case "'": Send !{o} case "~": Send !{w} case "|": Send !{a} case "\": Send !{z} case "-": Send +{/} case "[": Send !{r} case "]": Send !{t} case Chr(96): Send !{c} case "{": Send !{f} case "}": Send !{g} case Chr(10): { Send {Enter} Sleep, 550 ; newline delay in ms } default: Send %A_Loopfield% } } Send {Enter} ; optionally, always enter final line even when newline absent return } Edited June 5, 2020 by pixelpedant 1 Quote Link to comment Share on other sites More sharing options...
+jedimatt42 Posted June 23, 2020 Share Posted June 23, 2020 Is this, this: https://www.autohotkey.com/ ? I hadn't heard of this thing... this is a pretty cool usage... Quote Link to comment Share on other sites More sharing options...
RXB Posted June 23, 2020 Share Posted June 23, 2020 On 6/2/2020 at 5:27 PM, pixelpedant said: Here's a simple AutoHotKey script that I'm now using, which others here may have use for here (or might find improvements for), which I'm presently using to automate XB code entry (but potentially, any text entry) into MAME via the Windows clipboard. For most purposes, making programs available in MAME by saving them in TI Image Tool has been a great solution, for me. And just entering a program via Classic99, then using it in MAME is an option. But lately I've been working on a speech program for which accurate speech emulation is naturally at a premium (hence MAME), which is a lot of test/modify/test/modify/test/modify in mid-size batches, and for which assembly routines are being stored along with the program via HMLOADER (so I need to modify it in place). So I really needed a more efficient way to update 30 lines of code (or whatever) in MAME. The basic idea is to read the clipboard one character at a time, and 1) Enter each character in a way hospitable to the MAME/TI keyboard layout (e.g., ALT+R signifying Fctn+R for "[") and the machine's tolerances with respect to keystroke timing. 2) For newlines, ignore CR, but on LF, press Enter, then wait a little bit for control to return to the user before typing the next line. There's no realistic way to know (from the script's standpoint) how long it will actually take for new keystrokes to be accepted after a line is submitted, so that could be tweaked in the one direction or the other. The SetKeyDelay timing and the newline Sleep are the major timing decisions. But for the present, this serves as a simple but convenient solution for me, for automating XB program entry (or more like small to mid-size updates) in MAME. Typing out the contents of the clipboard in MAME while using machine-appropriate keys where necessary and handling newlines. Maybe someone else will have a use for it. #IfWinActive ahk_exe Mame64.exe { Insert:: SetKeyDelay 25,65 Loop, parse, clipboard { switch A_LoopField { case Chr(34): Send !p case "#": Send +{3} case "_": Send !{u} case "?": Send !{i} case "'": Send !{o} case "~": Send !{w} case "|": Send !{a} case "\": Send !{z} case "-": Send +{/} case "[": Send !{r} case "]": Send !{t} case Chr(96): Send !{c} case "{": Send !{f} case "}": Send !{g} case Chr(13): Sleep 0 case Chr(10): { Send {Enter} Sleep, 550 } default: Send %A_Loopfield% } } return } So for example, this is some code typing itself in MAME, via the clipboard (and the timings in the script above). Initiated by pressing the Insert key: f7cdCFsNOJ.mp4 251.3 kB · 3 downloads Hmmm you are doing what RXB has built in since RXB2001 was introduced and is faster: Quote Link to comment Share on other sites More sharing options...
+jedimatt42 Posted June 23, 2020 Share Posted June 23, 2020 43 minutes ago, RXB said: Hmmm you are doing what RXB has built in since RXB2001 was introduced and is faster: I don't see it that way.. How does RXB allow host machine clipboard paste from MAME? 1 Quote Link to comment Share on other sites More sharing options...
pixelpedant Posted June 23, 2020 Author Share Posted June 23, 2020 (edited) 11 hours ago, jedimatt42 said: Is this, this: https://www.autohotkey.com/ ? I hadn't heard of this thing... this is a pretty cool usage... Yeah, that's the one. Quite powerful Windows macroing solution, with support for variables and loops and pretty deep access to the Windows API. Another script I've been using lately takes a list of either space or comma delimited values (e.g., "250,40,50,76,12,90,81") copied to the clipboard and "pastes" them as equivalent byte values by using the ALT+000 entry method (arbitrarily using ScrollLock for this special paste function). This will only work in an environment like Notepad++, which will accept and display all control characters. But it happens to work well for me there when putting together a program containing allophone speech, as I don't (coincidentally) use either CHR$(13) or CHR$(10) (which is to say CR or LF), so it lets me dump allophone strings into a program as raw string data rather than equivalent decimal values. i.e., like this: Note that CHR$(34) is sent as "" instead of " so that it is parsed correctly when used inside a quoted string within a program. Also note that the resulting program content cannot at this point (once it contains raw string data including control characters) be pasted into Classic99 or MAME, and must be entered, say, via TI Image Tool. #IfWinActive ahk_exe notepad++.exe { ScrollLock:: { Clipboard=%Clipboard% Loop, parse, Clipboard,`,` ,`r`n { text:=A_Loopfield Sleep, 10 if (text="252") { charcode:=chr(252) Send, {%charcode%} } else if (text="34") { Send, `"`" } else { Sleep, 5 Send, {Alt down} count:=3-strlen(text) Loop, %count% { text="0"%text% } Loop, parse, text, { Send, {Numpad%A_Loopfield%} } Sleep, 5 Send, {Alt up} } } return } } Edited June 23, 2020 by pixelpedant 1 Quote Link to comment Share on other sites More sharing options...
pixelpedant Posted June 23, 2020 Author Share Posted June 23, 2020 (edited) So using that looks like this: paste string.mp4 Edited June 23, 2020 by pixelpedant 1 Quote Link to comment Share on other sites More sharing options...
mr_gw454 Posted June 23, 2020 Share Posted June 23, 2020 MAME has a incredibly powerful scripting language built in (LUA) that can allow for various interactions with the running machine driver. I recently started using it and find it very capable (perhaps a bit overkill for what you need it for). More information about LUA in MAME can be found here: https://docs.mamedev.org/techspecs/luaengine.html Command syntax can be found in the built-in help: https://github.com/mamedev/mame/blob/master/src/frontend/mame/luaengine.cpp Here's a video of an emulated Color Computer (in MAME) auto-playing a game called Timber Man: ... and the LUA code for it: https://gist.github.com/tlindner/0199ee5ee64ab6fb1e3340856bfdece9 Here's sample LUA code that presses keys for a Coco in a MOD Tracker program by Sockmaster: rint("registering callback"); emu.register_start(function() coroutine.resume(co) end) co = coroutine.create(function () print("waiting to LOAD program") emu.wait(3); print("sending RUN\"MOD13.BAS\"\n") emu.keypost("RUN\"MOD13.BAS\"\n") print("waiting to select DRIVE 1") emu.wait(15); print("selecting DRIVE 1") emu.keypost("1"); print("waiting to select MOD file A") emu.wait(10); print("selecting MOD file A") emu.keypost("A"); resetcounter = 1 end) if resetcounter == nil then print(coroutine.resume(co)) else print("Clear already done") end 1 Quote Link to comment Share on other sites More sharing options...
RXB Posted June 24, 2020 Share Posted June 24, 2020 6 hours ago, jedimatt42 said: I don't see it that way.. How does RXB allow host machine clipboard paste from MAME? Sorry I watched the Demo you showed and you can do exactly the same demo with RXB easy. I guess some other demo would be more to your point. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.