Petit Computer Wiki

More notes about internal stuff. This is once again not a complete page, but may still be useful.

All of the following information is for a USA copy of Petit Computer 2.2.

Evaluation[]

There is a function at 0x01ff9a54. This seems to be the "evaluate one expression" function. It accepts a pointer to the "main/DIRECT DU" and returns an error code if necessary (or 0 for success).

There is a function at 0x01ff9d90. This seems to skip spaces, as far as I can tell, with some sort of unclear extra logic relating to how much can be read? This also takes a pointer to the main DU, and returns a value indicating whether or not the last character was a space (maybe?) that seems to usually be ignored?

Commands[]

There is a function at 0x01ffa160 that takes 3 arguments. This seems to evaluate the arguments of a PTC command and write the results to the stack directly.

in r0 Pointer to data within "DIRECT mode/various things" data unit (often or always 0x0217ff50?)
in r1 Pointer to stack (with space allocated for result) (sub sp,sp,#size)
in r2 Expected number of arguments
out r0 Error code/0 if no error.

Note that for commands that output multiple values, 0x01ffa23c seems to be used for the arguments, and the variables are handled differently.

There is a function at 0x01ffbd5c that takes 3 arguments. This seems to get a pointer to an entry in the variable table, or null if the variable doesn't exist.

The first argument is the pointer to the variable table itself; the other two are currently unknown.

There is a function at 0x0203dc6c that takes 2 arguments. This seems to get an entry into the array table.

The first argument is the pointer to the array table, the second is the index of the array to obtain (this is obtained from the variable table entry, usually)

Functions[]

There is a function at 0x01ffa23c that takes 3 arguments. This seems to evaluate the arguments of a PTC function and write the results to the stack directly.

in r0 Pointer to data within "DIRECT mode/various things" data unit (often or always 0x0217ff50?)
in r1 Pointer to stack (with space allocated for result) (sub sp,sp,#size)
in r2 Expected number of arguments
out r0 Error code/0 if no error.

There is a similar function at 0x01ffbb3c, which takes 2 arguments. This seems to evaluate a variable number of arguments for a PTC function.

in r0 Pointer to data within "various things" data unit (as above)
in r1 Pointer to stack (with space allocated)
out r0 Error code/0 if no error
out top of stack Number of arguments processed

The "evaluation stack" is located at 0x02fe04dc. The first value is the size of the stack. The values after are of the form [numeric type, variable value]. For numbers, the value is stored directly as 20.12 fixed point; for strings the value is stored as an index into the string DU. When using the varargs function above, you must read the results manually from the evaluation stack.

To return a value from a function, write to the top of evaluation stack the type and value. To return a string that doesn't already exist requires more research - there are functions that allocate new strings, but I have not figured out the format yet.