I've recently been working on a library of routines for the Prizm. I intend these to eventually form the basis of an on-calc language similar to Axe, but the routines are for the moment being written so that Assembly programmers can use them. At the moment, I am working on multiple libraries, of which the math library is the farthest along. Here are a few routines in case anyone wants to use them.
Code:
Code:
Code:
Code:
Let me know if you have any routines you'd like to submit, optimizations to make or bugs to report.
Code:
/* Mod */
Info:
Performs the operation R1 Mod R2
12 bytes
7 cycles
Unsigned
Can operate in both processing modes
Inline function
Registers Destroyed:
R1
R2
R3
MACH
SH3 Hex:
6133321432150009010A3138
Code:
/* Arbitrary precision addition (unsigned) */
Info:
Performs the unsigned operation R1+R2
30 bytes
12*(# of bytes in operands)+4 cycles
Inline function
Registers Destroyed:
R0
R1
R2
R3
R4
R5
R6
R7
SR
SH3 Hex:
E000400455106620365E070233008D05246441104210470EAFF406292460
Code:
/* Arbitrary precision subtraction (unsigned) */
Info:
Performs the unsigned operation R1-R2
28 bytes
13*((# of bytes in operands)-1)+9 cycles
Inline function
Registers Destroyed:
R0
R1
R2
R3
R4
R5
R6
R7
SR
Other notes:
Don't let R2 be greater than R1!
R1 and R2 are pointers to the locations of the least significant bytes (highest addresses) of the operands in memory.
R3 hold the number of bytes of the operands. If the operands differ in size, zero extend the shorter one. Must be greater than 0.
R4 holds a pointer to the least significant byte (highest address) of the output location.
The output location must have at most R3+1 bytes available for the answer.
SH3 Hex:
E000400465106620365A070233008D05246441104210470EAFF47001
Code:
/* Linear Congruential Random Number Generator */
R1 == R4*R1 mod R3
Info:
40 bytes
Subroutine, not an inline function.
Other info:
The routine automatically loads a constant seed.
If you would like to seed it yourself, then set the least significant bit of R0 and put the seed in R1. The output is returned in R5.
If you call this routine multiple times, then you are responsible for seeding the RNG in R1 with the results of the previous computation from R5.
SH3 Hex:
40058F0D73173415D304010A6513335433550009050A3518000B000905F5E101AFF1D10002D63A86
Let me know if you have any routines you'd like to submit, optimizations to make or bugs to report.