CPUSim64 Software Interrupts

The CPUSim64 comes with many functions defined as part of its operating system. These functions are accessed via software interrupts. To access the defines that give symbolic names to the interrupt values you must include the appropriate system include file.

Input to interrupt functions is passed through known registers. Output is usually in either r0 or f0 if the function returns a value.

When invoking interrupts, there is no guarantee that the operands will not be modified or that registers r0 or f0 will not be modified.

<system/io.def>

InterruptPneumonicInput RegistersOperation
200iPUT_NLr0: output portOutputs the newline character(s) to the output port.
201iPUT_INTr0: output port
r1: output value
r2: base
Converts the output value to a string using the specified base and outputs it to the specified port.
202iPUT_DECr0: output port
r1: output value
Converts the output value to a string using base 10 and outputs it to the specified port.
203iPUT_HEXr0: output port
r1: output value
Converts the output value to a string using base 16 and outputs it to the specified port.
204iPUT_FPr0: output port
f0: output value
Converts the output value to a string and outputs it to the specified port.
205iPUTSr0: output port
r1: output string address
Outputs a string to the specified port.
206iGET_INTr0: input port
r1: base
Gets string from the specified port and converts it to an integer using base.
207iGET_DECr0: input portGets string from the specified port and converts it to an integer using base 10.
208iGET_HEXr0: input portGets string from the specified port and converts it to an integer using base 16.
209iGET_FPr0: input portGets string from the specified port and converts it to floating point.
210iGETSr0: input port
r1: buffer to hold string
Gets string from the specified port. r1 will change if buffer is realloced to a larger size.
211iPRINTFArg1: port
Arg2: format string address
Arg3: first value
Arg4: second value
...
Stack-based interrupt that implements C-style printf(). Arguments are pushed in reverse order onto the stack. Return address and stack frame are expected to be pushed last which means this interrupt should only be used inside a called function like fprintf().
220iOPEN_FILE_READr0: port (3-15)
r1: filepath string
Opens the file for text reading.
221iOPEN_FILE_WRITEr0: port (3-15)
r1: filepath string
Opens the file for test writing.
222iOPEN_FILE_APPENDr0: port (3-15)
r1: filepath string
Opens the file for text append.
223iOPEN_RAW_FILE_READr0: port (3-15)
r1: filepath string
Opens the file for raw read.
224iOPEN_RAW_FILE_WRITEr0: port (3-15)
r1: filepath string
Opens the file for raw write.
225iOPEN_RAW_FILE_APPENDr0: port (3-15)
r1: filepath string
Opens the file for raw append.
226iCLOSE_FILEr0: portCloses the file on port.
227iFLUSHr0: portFlushes output to the file on port.
228iDELETE_FILEr0: filepath stringDeletes the file specified. Returns TRUE if successful./td>
229iMAKE_DIRr0: path stringCreates the specified directory. Returns TRUE if successful./td>
230iDELETE_DIRr0: path stringDeletes the specified directory. Must be empty. Returns TRUE if successful./td>
231iIS_DIRr0: filepath stringReturns true if the specified filepath belongs to a directory.
232iIS_FILEr0: filepath stringReturns true if the specified filepath belongs to a file.
233iFILE_EXISTSr0: filepath stringReturns true if the specified filepath exists as a file or directory.
234iFILESr0: path stringReturns an array of strings containing the files/dirs residing in the path specified.
235iTEMP_DIRr0: prefix stringReturns an heap allocated string containing the name of a randomly generated tempory directory. Returns null on error.
236iTEMP_FILEr0: prefix string
r1: extension string
Returns an heap allocated string containing the name of a randomly generated tempory filepath. Returns null on error.

<system/math.def>

InterruptPneumonicInput RegistersOperation
100iPInoneReturns the floating point constant π.
101iEnoneReturns the floating point constant base of the natural logarithm.
102iABS_FPf0: valueReturns the absolute value of the floating point value.
103iABSr0: valueReturns the absolute value of the integer value.
104iCEILf0: valueReturns the smallest whole number greater than or equal to value.
105iFLOORf0: valueReturns the largest whole number less than or equal to value.
106iROUNDf0: valueReturns the nearest whole number to value.
107iSQRTf0: valueReturns the square root of value.
108iEXPf0: valueReturns evalue.
109iLOGf0: valueReturns the natural logarithm of value.
110iPOWf0: base
f1: exponent
Returns baseexponent
111iREMAINDERf0: num
f1: denom
Returns the fractional portion of num / denom.
112iMAX_FPf0: value
f1: value
Returns the larger of the two floating point values.
113iMIN_FPf0: value
f1: value
Returns the smaller of the two floating point values.
114iMAXr0: value
r1: value
Returns the larger of the two integer values.
115iMINr0: value
r1: value
Returns the larger of the two integer values.
116iRANDOMnoneReturns a pseudorandom floating point greater than or equal to 0.0 and less than 1.0.
117iRANDr0: lower
r1: upper
Returns a uniformly distributed random integer on the interval [lower,upper]
118iTO_DEGREESf0: valueReturns value converted from radians to degrees.
119iTO_RADIANSf0: valueReturns value converted from degrees to radians.
120iSINf0: value in radiansReturns sin(value).
121iCOSf0: value in radiansReturns cos(value).
122iTANf0: value in radiansReturns tan(value).
123iASINf0: valueReturns arcsin(value) in radians.
124iACOSf0: valueReturns arccos(value) in radians.
126iATANf0: valueReturns arctan(value) in radians.
125iATAN2f0: num
f1: denom
Returns arctan(num/denom) in radians even if denom is 0.

<system/string.def>

InterruptPneumonicInput RegistersOperation
301iFMT_DECr0: valueFormats the integer value in decimal as a heap allocated string.
302iFMT_HEXr0: valueFormats the integer value in hexdecimal as a heap allocated string.
303iFMT_FLOATf0: valueFormats the floating point value as a heap allocated string.
304iPARSE_INTr0: string addressParses a string as decimal, hexadecimal (0x or # prefix) or octal (0 prefix) integer.
305iPARSE_DECr0: string addressParses a string as a decimal integer.
306iPARSE_HEXr0: string addressParses a string as a hexadecimal integer.
307iPARSE_FLOATr0: string addressParses a string as a floating point value.
308iSPRINTFArg1: port
Arg2: format string address
Arg3: first value
Arg4: second value
...
Stack-based interrupt that implements C-style printf(). Arguments are pushed in reverse order onto the stack. Return address and stack frame are expected to be pushed last which means this interrupt should only be used inside a called function like sprintf().
309iTO_LOWERr0: characterReturns the lowercase version of the character.
310iTO_UPPERr0: characterReturns the uppercase version of the character.
311iTO_LOWER_STRr0: string addressReturns lowercase version of string as a heap allocated string.
312iTO_UPPER_STRr0: string addressReturns uppercase version of string as a heap allocated string.
313iSUBSTRING_SEARCHr0: string to search
r1: string to find
Searches a string for the specified substring and returns the index into the string if found or -1 if not found.
314iLAST_SUBSTRING_SEARCHr0: string to search
r1: string to find
Searches a string from the end for the specified substring and returns the index into the string if found or -1 if not found.
315iMATCHESr0: string to search
r1: regex to find
Searches a string for the specified regular expression and returns TRUE if found or FALSE if not found.
316iREPLACE_FIRSTr0: string to search
r1: regex to find
r2: replacement string
Searches a string for the specified regular expression and returns the heap allocated string that has the first occurance replaced by the replacement string.
317iREPLACE_ALLr0: string to search
r1: regex to find
r2: replacement string
Searches a string for the specified regular expression and returns the heap allocated string that has all the occurances replaced by the replacement string.
318iSPLITr0: string to split
r1: split regex
r2: limit
Splits the string using the regex returning an array of strings capped with maximum elements specified by limit. If limit is -1 the splitting is not capped.

<system/system.def>

InterruptPneumonicInput RegistersOperation
1iINT_MINnoneReturns largest negative integer.
2iINT_MAXnoneReturns largest negative positive integer.
3iFLOAT_MINnoneReturns smallest floating point value greater than 0.
4iFLOAT_MAXnoneReturns largest floating point value.
5iNEGATIVE_INFINITYnoneReturns negative infinity.
6iPOSITIVE_INFINITYnoneReturns positive infinity.
7iNANnoneReturns Not A Number.
10iCYCLESnoneReturns user CPU time in cycles.
11iCLOCKnoneReturns current execution time in ns.
12iSAVEnoneSaves r0-r28 on the stack.
13iSAVE_FPnoneSaves f0-f31 on the stack.
14iRESTOREnoneRestores r0-r28 from the stack.
15iRESTORE_FPnoneRestores f0-f31 from the stack.
16iPrintCPUStatenonePrints a diagram of the current CPU state and stack.
20iALLOCr0: allocation sizeReturns a heap allocated block address.
21iREALLOCr0: allocation address
r1: new allocation size
Returns a new heap allocated block with data copied from the passed allocation address. The original allocation address is freed if it is in the heap.
22iFREEr0: allocation addressReturns the heap allocated block address to the free list.
23iARGCnoneReturns the number of command line arguments.
24iARGSr0: argument indexReturns address of of the command line argument specified by index or null. Index 0 returns the program name.
25iMEMMOVEr0: dest address
r1: src address
r3: length
Moves contents of memory from src to dest. Can handle overlapping memory blocks.
30iEXITr0: exit codeExits process with specified code.
31iSYSTEMr0: string addressExecutes the system command contained in the string. Returns the exit code of the command.
32iFORK
33iWAIT
34iWAIT_PID
35iTHREAD
36iWAIT_THREAD
37iSLEEPr0: delay in msPauses execution for the specified milliseconds.