PatchFileFromARM(ARM_Instructions, filename): This global function is a little helper for a very specific job. The first argument is a string with ARM assembler instructions, usually starting with org address to define the position in the binary. The second argument is the the file path and name of an ARM binary, usually the NewtonOS ROM file. Calling PatchFileFromARM will assemble and link the ARM code into ARM commends and then overwrite the code in the ROM file with the new ARM code at the given addresses.
MakeBinaryFromARM(ARM_Instructions): Create the binary part of a BinCFunction from ARM assembly code. Here, nativeMath and newtonScriptMath are both functions that can be called from anywhere in a script:
nativeMath: {
class : 'BinCFunction,
numArgs: 2,
offset: 0,
code: MakeBinaryFromARM("
ldr r1, [r1] @ Unref the first argument
ldr r1, [r1] @ Get the integer object
mov r1, r1, lsr #2 @ convert it into an integer
ldr r2, [r2]
ldr r2, [r2] @ do the same with the second arg
mov r2, r2, lsr #2
add r0, r1, r2 @ add both integers
mov r0, r0, lsl #2 @ convert the result into an integer object
mov pc, lr @ return to the interpreter
")
}
// The same in Newton Script
newtonScriptMath: func(a, b) begin
return a+b;
end
MakeBinaryFromARMFile(ARM_Assembler_Filename): Same as above, but instead of as string with ARM instructions, this call takes a file path and name of an ARM assembler code file.
AddStepForm(theParentView, myView): This is an original NTK function. It ensures that the parent view has a frame named "StepChildren", and then adds myView to that frame. This is needed to ensure that a new view will appear as a child of the parent view when an app is opened.
StepDeclare(theParentView, myView, 'myView): This is an original NTK function. It ensures that the parent view has an array named "StepAllocateContext", and the appends myView and the symbol 'myView to the array.
_STDERR_:
_STDOUT_:
fltk:choice(message, cancel_button, ok_button, opt_button): Open a user choice dialog box and return the selected button id.
fltk:filechooser(message, pattern, filename, relative): Open a file chooser dialog. Returns filename or NIL.
file:open(filename, mode): Open a file, mode is 'read|'write|'readwrite|'append.
file:isOpen(): Returns nil or true.
file:size(): Returns file size in bytes.
file:read(size): Read up to size bytes and return a binary object with the data.
file:write(binaryObject): Write the content of a binary object to a file.
file:seek(pos, mode): Set read position, mode is 'set|'cur|'end.
file:tell(): Return the current read position in the file.
file:close(): Closes a file, returns exception or true.