Click on the pencil icon (or press F2) to write your program's source code.
Code has three sub-pages, one where you can write the source code (this one), the [Visual Editor], where you can do the same using structograms, and your program's machine code can be seen in the [debugger].
Code Editor
Here the entire area (1) is one big input field for the source code. At the bottom (2), you can see the status bar, with the current row and coloumn, the UNICODE codepoint of the character under the cursor, and if you're standing in an API's argument list, a quick help on that API function's parameters (suitable for all programming languages).
The program must start with a special line, with the characters #!
followed by the language you want to use. By default,
it uses MEG-4 C (a subset of ANSI C), but you can choose others as well. See the list under "Programming" in the table of
contents on the left.
Regardless to the scripting language you choose, there are two functions that you should implement. They have no arguments and they return no value.
setup
function is optional and runs only once when your program gets loaded.loop
function is mandatory, and runs every time a frame is generated. At 60 FPS this means a 16.6 msecs timeframe, but the
MEG-4 "hardware" itself takes about 2-3 msecs, which leaves you a 12-13 msecs for your function to fill. You can query this
value from the performance counter MMIO register, see [memory map]. If it takes longer to run the loop
function, then the
screen might became laggy, and the emulator will be less responsive than usual.In addition to standard keyboard shortcuts and input methods, the code editor has lot more text editing related shortcuts.
From the menu, you can also access Find, Replace, Go to, Undo, Redo as well as the list of bookmarks and the defined functions.