Author Topic: PrizmLib  (Read 3787 times)

0 Members and 3 Guests are viewing this topic.

Offline AngelFish

  • Is this my custom title?
  • Administrator
  • LV12 Extreme Poster (Next: 5000)
  • ************
  • Posts: 3242
  • Rating: +270/-27
  • I'm a Fishbot
    • View Profile
PrizmLib
« on: February 11, 2011, 01:18:53 am »
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: [Select]
/* 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: [Select]
/* 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

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:
E000400455106620365E070233008D05246441104210470EAFF406292460

Code: [Select]
/* 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: [Select]
/* 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.
« Last Edit: February 11, 2011, 01:23:04 am by Qwerty.55 »
∂²Ψ    -(2m(V(x)-E)Ψ
---  = -------------
∂x²        ℏ²Ψ

Offline z80man

  • Casio Traitor
  • LV8 Addict (Next: 1000)
  • ********
  • Posts: 977
  • Rating: +85/-3
    • View Profile
Re: PrizmLib
« Reply #1 on: February 11, 2011, 03:00:01 am »
Alright I decided to get things going and made an 8x8 sprite draw command. It will not work yet as we do not know where the screen is located in ram yet.  :P
Code: [Select]
Info:
                Takes R1, R2, and R3 as arguments[
                R1 is y coordinate. R2 is x coordinate
                $B4000000 is the current pointer to PlotScreen
                R3 is pointer to location of the sprite
                50 bytes
                Too many cycles to count by hand

Registers Destroyed:
                R0
                R1
                R2
                R3
                R4
                R5
                R6
                R7
                R8

Memory Destroyed:
PlotScreen

SH3 Hex:
D0080017302CD409304CE503E6076736207645108BFBD506308CE50346108BF6000B00090000030000000000B4000000000002FC

SH3 ASM:

00000000: MOV.L @($08*4+PC),R0 = #00000300
00000002: MUL.L R1,R0
00000004: ADD R2,R0
00000006: MOV.L @($09*4+PC),R4 = #B4000000
00000008: ADD R4,R0
0000000A: MOV $03, R5
0000000C: MOV $07, R6
0000000E: MOV.L @R3+,R7
00000010: MOV.L R7,@-R0
00000012: DT R5
00000014: BF $E
00000016: MOV.L @($06*4+PC),R5 = #000002FC
00000018: ADD R8,R0
0000001A: MOV $03, R5
0000001C: DT R6
0000001E: BF $E
00000020: RTS
00000022: NOP
00000024: .data 00000300 dword ref:0
00000028: 0000 ?
0000002A: 0000 ?
0000002C: .data b4000000 dword ref:6
00000030: .data 000002fc dword ref:16/code]
« Last Edit: February 11, 2011, 03:00:18 am by z80man »

List of stuff I need to do before September:
1. Finish the Emulator of the Casio Prizm (in active development)
2. Finish the the SH3 asm IDE/assembler/linker program (in active development)
3. Create a partial Java virtual machine  for the Prizm (not started)
4. Create Axe for the Prizm with an Axe legacy mode (in planning phase)
5. Develop a large set of C and asm libraries for the Prizm (some progress)
6. Create an emulator of the 83+ for the Prizm (not started)
7. Create a well polished game that showcases the ability of the Casio Prizm (not started)

Offline AngelFish

  • Is this my custom title?
  • Administrator
  • LV12 Extreme Poster (Next: 5000)
  • ************
  • Posts: 3242
  • Rating: +270/-27
  • I'm a Fishbot
    • View Profile
Re: PrizmLib
« Reply #2 on: February 11, 2011, 03:11:50 am »
Multiplication instructions store to the the MACL and MACH registers, not Rn. Fixed a bug with that and made a minor optimizations/rearrangements so that the branches would execute properly. The way it was originally would have thrown illegal branch instruction errors when the loop tried to iterate from the RTS instruction in the pipeline.  :)
Code: [Select]
Hex:
D008
0017
D409
000A
302C
304C
E503
E607
6736
2075
4510
8B0E
D506
E503
8B0E
308C
000B
4610
SH3 ASM:

MOV.L @($08*4+PC),R0 = #00000300
MUL.L R1,R0
MOV.L @($09*4+PC),R4 = #B4000000
STS MACL, R0
ADD R2,R0
ADD R4,R0
MOV $03, R5
MOV $07, R6
MOV.L @R3+,R7
MOV.L R7,@-R0
DT R5
BF $E
MOV.L @($06*4+PC),R5 = #000002FC
MOV $03, R5
BF $E
ADD R8,R0
RTS
DT R6
.data 00000300 dword ref:0
.data b4000000 dword ref:6
.data 000002fc dword ref:16
« Last Edit: February 11, 2011, 03:29:47 am by Qwerty.55 »
∂²Ψ    -(2m(V(x)-E)Ψ
---  = -------------
∂x²        ℏ²Ψ

Offline z80man

  • Casio Traitor
  • LV8 Addict (Next: 1000)
  • ********
  • Posts: 977
  • Rating: +85/-3
    • View Profile
Re: PrizmLib
« Reply #3 on: February 11, 2011, 03:16:21 am »
Yeah I'm still kinda of an SH3 noob. Plus this stuff is 10 times harder than z80 asm. In addition this coding is in hex further complicating matters. I think I will stick to C or the Prizm Axe when that comes out. Or maybe just a decent assembler. Not hex.
« Last Edit: February 11, 2011, 03:16:33 am by z80man »

List of stuff I need to do before September:
1. Finish the Emulator of the Casio Prizm (in active development)
2. Finish the the SH3 asm IDE/assembler/linker program (in active development)
3. Create a partial Java virtual machine  for the Prizm (not started)
4. Create Axe for the Prizm with an Axe legacy mode (in planning phase)
5. Develop a large set of C and asm libraries for the Prizm (some progress)
6. Create an emulator of the 83+ for the Prizm (not started)
7. Create a well polished game that showcases the ability of the Casio Prizm (not started)

Offline AngelFish

  • Is this my custom title?
  • Administrator
  • LV12 Extreme Poster (Next: 5000)
  • ************
  • Posts: 3242
  • Rating: +270/-27
  • I'm a Fishbot
    • View Profile
Re: PrizmLib
« Reply #4 on: February 11, 2011, 03:18:19 am »
Lol, I find this easier than many parts of z80. C makes even less sense to me than either of those.

Code: (C code) [Select]
for(;P("\n"),R-;P("|"))for(e=C;e-;P("_"+(*u++/8)%2))P("| "+(*u/4)%2);

I rest my case  :P
« Last Edit: February 11, 2011, 03:19:21 am by Qwerty.55 »
∂²Ψ    -(2m(V(x)-E)Ψ
---  = -------------
∂x²        ℏ²Ψ

Offline z80man

  • Casio Traitor
  • LV8 Addict (Next: 1000)
  • ********
  • Posts: 977
  • Rating: +85/-3
    • View Profile
Re: PrizmLib
« Reply #5 on: February 11, 2011, 03:28:46 am »
That kind of reminds me of malbolge in a way :P, and one part I do not like about C is that it is often to difficult to manage the memory and how variables and data is distributed throughout the code. So maybe I will stick with asm as long as my assembler takes care of the labels and branch statements.

List of stuff I need to do before September:
1. Finish the Emulator of the Casio Prizm (in active development)
2. Finish the the SH3 asm IDE/assembler/linker program (in active development)
3. Create a partial Java virtual machine  for the Prizm (not started)
4. Create Axe for the Prizm with an Axe legacy mode (in planning phase)
5. Develop a large set of C and asm libraries for the Prizm (some progress)
6. Create an emulator of the 83+ for the Prizm (not started)
7. Create a well polished game that showcases the ability of the Casio Prizm (not started)

Offline DJ Omnimaga

  • Clacualters are teh gr33t
  • CoT Emeritus
  • LV15 Omnimagician (Next: --)
  • *
  • Posts: 55943
  • Rating: +3154/-232
  • CodeWalrus founder & retired Omnimaga founder
    • View Profile
    • Dream of Omnimaga Music
Re: PrizmLib
« Reply #6 on: February 16, 2011, 04:40:24 pm »
Yeah personally I could never get used to C, but again I don't know ASM either, aside from a few concepts I could easily remember if I checked a tutorial again.

Some routines for BASIC coders would be cool, assuming they won't take ages to execute like non-partser-hook-based 83+ ASM libs ran with the Asm(prgmNAME) syntax (due to searching the entire VAT for the program)