FANDOM


Redpower-logo1 Forth language contains information about the RedPower mod.

The Forth language is the programming language used by Computers within the Redpower mod. In the game it is found in the form of the FORTH boot disc .

Numbers in this programing language is used like a Stack. To simply explain what a Stack is, think of a single tall stack of boxes. You both enter (put in) and use (take out) numbers at the bottom of the stack. If you put in more than one number, the new ones will push the old ones up the stack. That means the last number you entered will get used first. If you use a number, the rest of the numbers will fall down the stack ready to be used.

A lot of commands need you to enter a number before using them. So remember how numbers are used when you use commands that need more than one number. The stacking of numbers also let you do something crazy like this: 4 2 1 IOXSET IOXSET IOXSET. Try it if you want to find out what that does.

The above can also be accomplished by the single command: 7 IOXSET. This is because the signal output from Redpower computers operates in binary. The colored wires are hardcoded with set byte-codes in binary. White is 1, orange is 2, magenta is twice orange with 4, cyan twice of magenta with 8, and so on. The sequence of increasing byte-codes for the colors is the order in which the colors appear on NEI.

Example Redpower Computer Setup

Example of Redpower Computer setup.

Here is an example of Redpower computer setup for learning and testing purpose. To the far left is the Disk Drive where you can put the Forth Boot disc into. Next to the right is the CPU and Monitor on top of it. Behind the CPU is the Backplane and 8k RAM, which is needed if you want to read and write to the Disk Drive for storing your programs. Just booting the disc won't need the 8k Ram. To the right of the CPU is the IO Expander which is connected to Bundled Cable and Insulated Wire going to Lamps. In this example, they are White (1), Orange (2), Magenta (4), Light Blue (8), and Yellow (16).

Your CPU, Disk Drive and Monitor do not need to be directly next to each other. They can also be connected by Ribbon Cable.

After you set all that up, put the Forth boot disc into your hotbar and right click it into the Disk Drive. Right-click the CPU and press Reset before anything to avoid any confusion. Then you can Start the boot up. The console will indicate it has booted with FORTH, allowing you to begin programming.

Progamming using ForthEdit

All the commands you enter will be case sensitive. Most of the default commands are CAPS only. Here are a few common commands, add more if you can.

  • WORDS - List default commands.
  • PAGE - Clears the screen.
  • IOXSET - Set to ON certain wires connected to bundle cable linked to the computer through IO Expander. Example: 1 IOXSET will turn ON the white wire. (Input/Output eXpander Set)
  • IOXRST - Set to OFF above wires. Example: 1 IOXRST will turn OFF the white wire. (Input/Output eXpander ReSeT)
  • IOX! - Set ON/OFF multi wires. Example: 3 IOX! will turn ON white and orange wires, and every other wires OFF. 0 IOX! will turn every wire OFF. You can also turn on one lamp with standard binary numbers: 1 IOX! would turn on white.
  • IOX@ - read the IO bus, OR(adding together) every wire state. If you want to know whether one wire is active or not, you have to do something like this: IOX@ 1 AND this will check if the white wire is active or not.
  • TICKS - Wait number of ticks. Example: 10 TICKS will wait for 10 ticks. 1 IOXSET 10 TICKS 1 IOXRST will turn white wire ON for 10 ticks, then turn white wire OFF.
  •  : CustomCommand commands list ; - Lets you make custom command words that speed up the commands a lot. Example - : AllOff 0 IOX! ; that will turn all the wires OFF with just AllOff command.
  • FORGET - delete custom commands created at or after this. Example: FORGET AllOff will erase all custom commands made after AllOff, including that. Also possible: ERASE AllOff
  • .S - prints the numbers on the stack without affecting them.
  • . - prints the bottom number on the stack and removes it from the stack.
  • CR - Carriage Return, advance to next line for printing.
  • ." " - prints text on the screen, only works inside custom words. Example - : Hello CR ." Hello World" CR ; will advance to next line, print out Hello World, then advance the line again when you use the Hello command. Make sure there is a space after ." since it is sort of like a print command.
  • VARIABLE - makes a custom name for storing changeable numbers, and you should use a different form from custom words so you can find them easier, since they are shown in the same WORDS list. Example: VARIABLE $test will reserve a 2 byte location for storing your numbers in $test. Also, you can shorten most commands with custom words like this - : var VARIABLE ; then you just need to type - var $test2 for later ones.
  •  ! - set a variable. Example: 10 $test ! will put the number 10 into $test. The ! explicitly means "write".
  • @ - reads a variable. Example: $test @ will put the above number 10 into the stack. Just using $test by itself will just put the memory location of the variable into the stack.
  • IF ELSE THEN - conditional statement. Usage: (condition) IF (do true stuff) ELSE (do false stuff) THEN. You can omit the ELSE parts if not needed. Example: 10 $test ! will put number 10 into $test, 20 $test2 ! will put number 20 into $test2, $test @ $test2 @ = will put the numbers in them onto the stack then check if they are equal, IF ." Equal" ELSE ." Not Equal" THEN CR will print Not Equal since we used different numbers. For arithmetic and comparisons, just move whatever sign left one number, and you will know what it does. To program them, move the sign one number to the right.
  • TIMES - repeat a command certain number of times, only works outside of custom commands. Example: 10 TIMES GoLeft will repeat the GoLeft command 10 times.
  • DO LOOP - the FOR NEXT loop of Forth. Usage: (MaxNumberPlusOne) (StartNumber) DO (things to do) LOOP. Example: 11 1 DO GoLeft LOOP will do the same thing as above, except you can use this in custom words. 10 0 DO GoLeft LOOP is exactly the same thing. Basically this adds 10 and 0 to the stack. Each time the loop runs, the 10 decrements by 1, then checks if it and the second number (0) are equal. If they are, the loop exits.
  • BEGIN UNTIL - Condition at end loop. Usage: BEGIN (do this first) (condition) UNTIL. Example - if we have the custom command : FlashOrange 2 IOXSET 10 TICKS 2 IOXRST 10 TICKS ; and : ActTill BEGIN FlashOrange IOX@ 1 AND UNTIL ; will make the ActTill command flash the Orange wire till the White wire is turned on.
  • BEGIN WHILE REPEAT - Condition in middle loop. Usage: BEGIN (do this first) (condition) WHILE (do this if true) REPEAT. Example - : ActWhile BEGIN IOX@ 1 AND WHILE FlashOrange REPEAT ; will flash the Orange wire as long as the White wire remains on.

Disk CommandsEdit

You need a Blank Floppy plus the Backplane and 8K RAM Module in order to read/write to the Disk Drive (RedPower). After you boot up with the Forth boot disk, you can right click Disk Drive to eject it out. Then you can right click a Blank Floppy into the Disk Drive for read/write. Since playing with custom words inside the computer memory can make big mess and hard to correct stuff, using Disk is easier once you know that your custom words work.

  • DISKNAME" - Let you name your blank floppy. Example: DISKNAME" Quarry" will name your disk with the item name Quarry.
  • LIST - Display the disk sector and also to work on it. Example: 1 LIST will display the content of sector 1, and let you work on it. Each sector has 16 tracks that you can put things into, usually custom command definitions.
  • WIPE - Delete the whole current working sector. A Blank Floppy has a lot of junk at the start, so using a WIPE command on it before working with it is a good idea. The deletion will not happen till you use the FLUSH command below.
  • FLUSH - Saves the current working sector to disk.
  • PP - Writes a track. Example: 0 PP : GoLeft 1 IOXSET 10 TICKS 1 IOXRST 10 TICKS ; will put everything after the PP onto track 0 of the current working sector. Remember to FLUSH later to actually save the work to the disk.
  • LOAD - Loads a sector into computer memory. Example: 1 LOAD will load sector 1 from the disk. Please note that this can take a long time if you have a lot of custom commmands defined, since it need to convert them into machine language.
  • SAVE" - Saves all the words in the computer memory into a blank floppy, you can later use it to boot the computer instead of the Forth boot disk. Example: SAVE" QuarryBoot" will save all your computer words to the disk with the item name QuarryBoot. It is a lot faster than loading a sector of the disk into the computer.

NotesEdit

  • If you want to stop your computer while it is running a program for any reason, the only way I know is to remove all disks from the Disk Drive and do a soft reset. You do this with a right click on the CPU, then click RESET button. Wait a second or two, then click the START button. You will now have your cursor back at the monitor, with all your custom words intact.