Taming Forth with AutoIt for Windows

  • The FTB Forum is now read-only, and is here as an archive. To participate in our community discussions, please join our Discord! https://ftb.team/discord

PhilHibbs

Forum Addict
Trusted User
Jan 15, 2013
3,174
1,128
183
Birmingham, United Kingdom
RedPower computers are pretty unforgiving. If you make a mistake in Forth, it remembers that mistake and keeps punishing you for it. If you define a series of words and there's a bug in one of them, then you have to delete all the words since that word and re-enter them. There are tools to read Forth programs from text files, but I've solved the problem in my own particular way.

I use a Windows tool called AutoIt, which is quite wonderful. It automates Windows programs. It can click the mouse, stuff into the keyboard buffer, and read pixels on the screen.

All I use it for in this context is stuffing the keyboard. I have a script that reads a file, and every time you press a specific key (I use the backtick ` key) it stuffs a single line from the file into the Minecraft keyboard buffer at 10 characters per second. This delay is programmable in case your RedPower computers are more or less responsive than mine.

So, you create your code in a file, edit the AutoIt script to contain the file name, and run the AutoIt script. It should automatically move focus to the Minecraft window as long as the script has the right window name, I've hard coded it to "Direwolf20" as it only needs a substring of the window title. Once you're in the game and at the MineOS > prompt, just keep hitting ` every time MineOS has processed a line. Compiling a complex line of commands can take a few seconds, so wait for it, as MineOS only has a small typeahead buffer.

When it has pasted the last line, the script exits. You can exit it early via the tray icon.

Here's my script.
Code:
#Include <Misc.au3>
#include <file.au3>
#Include <Array.au3>
$log = FileOpen("mclog.txt", 1)
WriteLog( "Start " & @ScriptName )
Dim $Code
If Not _FileReadToArray("Programs\signal.txt",$Code) Then
  MsgBox(4096,"Error", " Error reading code to Array    error:" & @error)
  Exit
EndIf
Dim $Line = 1
WriteLog( "Index0 " & $Code[0] )
Opt( "SendKeyDelay",100 )
HotKeySet("`","PasteLine")
$win = "Direwolf20"
$handle = WinActivate($win)
While 1
  sleep(250)
  If $Line > $Code[0] Then ExitLoop
WEnd
Func PasteLine()
  Send( $Code[$Line], 1)
  Send( "{ENTER}")
  WriteLog( $Line & ":" & $Code[$Line] )
  $Line = $Line + 1
EndFunc
Func WriteLog($text)
  FileWriteLine($log, @HOUR & ":" & @MIN & ":" & @SEC & "." & @MSEC & " " & $text )
EndFunc

There are three hard coded strings that you might want to change - the activation key, the file name, and the window title. If you can't find them, then what are you doing trying to write Forth programs?
smile.png


Beware that some of the AutoIt forum folks are utterly against all forms of game automation, so if you go to their site to discuss this, then prepare for some hostility. Other than that caveat, the forum is fantastic and really helpful.

Here's an example file that defines a few simple words. Actually it's my entire project so far! It waits for one of three signals coming in on an IO Expander and displays which signal it received and then exits. Pretty soon I'll hook it up to another Sortron and get it to actually process the contents of an Enderchest in the appropriate way. I've already got the IO Expander hooked up to a line of Wireless Receivers, so I can send commands with my Wireless Remote.
Code:
: colWhite    1 ;
: colOrange    2 ;
: colMagenta  4 ;
: colLightBlue 8 ;
: colYellow    16 ;
: colLime      32 ;
: colPink      64 ;
: colGray      128 ;
: colLightGray 256 ;
: colCyan      512 ;
: colPurple    1024 ;
: colBlue      2048 ;
: colBrown    4096 ;
: colGreen    8192 ;
: colRed      16384 ;
: colBlack    32768 ;
: signalMacerate colRed ;
: signalFurnace  colOrange ;
: signalRecycle  colYellow ;
: signal
0
BEGIN
1
IOX@ signalMacerate = IF DROP ." Macerate" THEN
IOX@ signalFurnace  = IF DROP ." Furnace"  THEN
IOX@ signalRecycle  = IF DROP ." Recycle"  THEN
0= UNTIL ;

*EDIT* Fixed a bug where a ! character would not be sent, had to split the Send() call into two calls, one for a literal string and one for the {ENTER} special command.
 

Aeronica

New Member
Jul 29, 2019
27
0
0
I've been searching for a forum to discuss and exchange ideas about Redpower Controller usage. The FTB forums will do. Thanks for the AutoIt link and script. I'll give them a try. I've been able to use Win32Forth to test some of the Forth I use, but when it comes to working in the controller, the pain of the entry and forget sequence is somewhat a pain. I have looked at other tools referenced on the official redpower wiki but none are ideal. An IDE block in Minecraft would be a nice thing to have... add Pastebin functionality.. heh heh I dream.
 

PhilHibbs

Forum Addict
Trusted User
Jan 15, 2013
3,174
1,128
183
Birmingham, United Kingdom
Welcome! I think I've only seen one or two people mention that they've used Forth, but I promise to check on your threads and I hope we can help each other. If you search for "sortron" you should find my other thread easily where I have a working version of the prototype code in the post above. IDE... Pastebin... that would make it easy, but that's not what CPUs and Sortrons are about. Easy is an exclusive feature of ComputerCraft, like rectangles are Apple's trademark.
 

Mad_FrEsC

New Member
Jul 29, 2019
1
0
0
I changed the code of the emulator which is available here: http://bigfootinformatika.hu/65el02/
now there is an additional option to read the input from textfiles as if they would come from keyboard (which is great for reading in forth files).
the read process is synched with the cpu so it's really fast.
the line endings of the input file should be CR only (Mac line endings) and the format should be ANSI.
it's working so far, but I implemented it quick and dirty and did not much testing. so expect bugs.
 

Attachments

  • emu65el02_v0.12_src.zip
    240.5 KB · Views: 115