Omnimaga: The Coders Of Tomorrow
Welcome, Guest. Please login or register.
 
Omnimaga: The Coders Of Tomorrow
20 June, 2013, 10:25:09 *
Welcome, Guest. Please login or register.

Login with username, password and session length
 
   home   news downloads projects tutorials misc forums rules new posts irc about Login Register  
+-OmnomIRC

You must Register, be logged in and have at least 40 posts to use this shout-box! If it still doesn't show up afterward, it might be that OmnomIRC is disabled for your group or under maintenance.

Note: You can also use an IRC client like mIRC, X-Chat or Mibbit to connect to an EFnet server and #omnimaga.

Pages: [1] 2 3 ... 5   Go Down
  Print  
Author Topic: Prizm Useful Routines -- post here! -  (Read 4070 times) Bookmark and Share
0 Members and 1 Guest are viewing this topic.
Ashbad
Guest
« on: 23 May, 2011, 16:26:31 »
0

Since Cemetech has one, I think we need one as well.  This section is where you can post any routines for the casio Prizm you make in C or SH4 assembly.  I don't think I have the liberty to post others' routines over here, but I'll be glad to start with some of my own, and I'm sure Qwerty will soon post some of his very well done SH4 routines [nice and optimized, too!] such as his LRNG.  Here are a few in C, all written by me, and decently optimized:



Routine: Draw Alpha-coded sprite

inputs: pointer to data, x pos, y pos, width, height, alpha degree 1-255 (0 denotes no alpha value and normal drawing)


1
2
3
4
5
6
7
8
9
10
11
12
void AlphaSprite(short* data, int x, int y, int width, int height, char alpha) {
   short* VRAM = (short*)0xA8000000;
   int CurColor = 0;
   VRAM += (LCD_WIDTH_PX*y)+x;
   for(int j=y; j<y+height; j++) {
      for(int i=x; i<x+width;  i++) {
        CurColor = (*(VRAM) + (alpha*(*(data++))/256))/2;
        *(VRAM++) = CurColor % (65536);
      }
      VRAM += (LCD_WIDTH_PX-width);
   }
}



Generate pseudo-random number

input - 32bit integer for upper and lower bounds

this is based on the famous '128bit shifting' technique, and is considered highly random enough.


1
2
3
4
5
6
7
8
9
10
11
12
13
int Rand32(int lower, int upper) {
  static int a = 123456789;
  static int b = 362436069;
  static int c = 521288629;
  static int d = 88675123;
  int t;
 
  t = a ^ (a << 11);
  a = b;
  b = c;
  c = d;
  return (d = d ^ (d >> 19) ^ (t ^ (t >> 8)))%upper + lower;
}




Test a pixel of CURRENTLY rendered VRAM image (tari and Ashbad optimized)

inputs: X and Y position
outputs: short holding color value



1
2
3
4
short getpixel(short x, short y) {
    short *VRAM = (short *)0xA8000000;
    return *(VRAM + (y * LCD_WIDTH_PX) + x);
}




Invert Colors in Rectangular Area

inputs: shorts for x position, y position, length, and width
outputs: look at your screen!  Cool (if you actually render it)


1
2
3
4
5
6
7
8
void InvArea(short x, short y, short height, short width)
   unsigned short *VRAM = (unsigned short *)0xA8000000;
   for(short a = 1; a>width; a++) {
      for(short b = 1; b>height; b++) {
         *(b + y * LCD_WIDTH_PX + a + x + (VRAM++)) ^= 0xFFFF;
      }
   }
}



Print Custom Character (improved)

inputs: an x position, a y position, a bit mapped image of the character, color to draw the character, if it is to draw a backcolor in non-mapped spaces, a short to specify backcolor (put 0 if DrawBackColor is false) , and the dimensions of the character
  EXAMPLE BIT MAPPED CHARACTER (the letter A):
          [0,0,1,0,0]
          [0,1,0,1,0]
          [0,1,1,1,0]
          [0,1,0,1,0]
          [0,1,0,1,0]
outputs: look at your screen Smiley (unless you don't render it)
       
       
       

1
2
3
4
5
6
7
8
9
10
11
12
void PutCustC(*bool map, short x, short y, short width, short height, short color, bool DrawBackColor, short backcolor) {
     short* VRAM = (short*)0xA8000000;
     VRAM += (LCD_WIDTH_PX * y) + x;
     for(short a = 0; a>width; a++) {
               for(short b = 0; b>height; b++) {
                         if(*(y + b * width + x + a + map)) { *(VRAM++) = color; }
                         elseif(DrawWhite) { *(VRAM++) = backcolor; }
                         else { VRAM++; }
               }
               VRAM += (LCD_WIDTH_PX-width);
     }
}



Draw Circle Routine

inputs: x, y, draw color and radius
outputs: look at your screen Smiley (that is, if you render it)

NOTE: uses a SetPoint routine in display_syscalls.h


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
void DrawCircle(short x0, short y0, short radius, short color)
{
  short f = 1 - radius;
  short ddF_x = 1;
  short ddF_y = -2 * radius;
  short x = 0;
  short y = radius;
 
  Bdisp_SetPoint_VRAM(x0, y0 + radius, color);
  Bdisp_SetPoint_VRAM(x0, y0 - radius, color);
  Bdisp_SetPoint_VRAM(x0 + radius, y0, color);
  Bdisp_SetPoint_VRAM(x0 - radius, y0, color);
 
  while(x < y)
  {
    // ddF_x == 2 * x + 1;
    // ddF_y == -2 * y;
    // f == x*x + y*y - radius*radius + 2*x - y + 1;
    if(f >= 0)
    {
      y--;
      ddF_y += 2;
      f += ddF_y;
    }
    x++;
    ddF_x += 2;
    f += ddF_x;   
    Bdisp_SetPoint_VRAM(x0 + x, y0 + y, color);
    Bdisp_SetPoint_VRAM(x0 - x, y0 + y, color);
    Bdisp_SetPoint_VRAM(x0 + x, y0 - y, color);
    Bdisp_SetPoint_VRAM(x0 - x, y0 - y, color);
    Bdisp_SetPoint_VRAM(x0 + y, y0 + x, color);
    Bdisp_SetPoint_VRAM(x0 - y, y0 + x, color);
    Bdisp_SetPoint_VRAM(x0 + y, y0 - x, color);
    Bdisp_SetPoint_VRAM(x0 - y, y0 - x, color);
  }
}

EDIT: and I'm not sure where to put this, but here's a small yet useful update on the BFILE_syscalls.h header, with defines that more easily stand in place of a number for 'mode' in the Bfile_OpenFile_OS function.


1
2
3
4
5
6
7
8
9
10
11
12
13
14
#define O_READ 0x01
#define O_READ_SHARE 0x80
#define O_WRITE 0x02
#define O_READWRITE 0x03
#define O_READWRITE_SHARE 0x83

int Bfile_OpenFile_OS( const unsigned short*filename, int mode );
int Bfile_CloseFile_OS( int HANDLE );
int Bfile_ReadFile_OS( int HANDLE, void *buf, int size, int readpos );
int Bfile_CreateEntry_OS( const unsigned short*filename, int mode, int*size );
int Bfile_WriteFile_OS( int HANDLE, const void *buf, int size );
int Bfile_DeleteEntry( const unsigned short *filename );
void Bfile_StrToName_ncpy( unsigned short*dest, const unsigned char*source, int n );
« Last Edit: 23 May, 2011, 23:02:55 by Ashbad » Logged
fxdev
LV4 Regular (Next: 200)
****
Offline Offline

Last Login: 19 March, 2013, 20:52:08
Date Registered: 18 January, 2011, 16:21:14
Posts: 177

Total Post Ratings: +28

View Profile
« Reply #1 on: 23 May, 2011, 21:44:55 »
0

Please, use Syscall 0x01E6 to obtain the VRAM address.
Interface: void *GetVRAMAddress(void);
Logged
DJ Omnimaga
Retired Omnimaga founder (Site issues must be PM'ed to Netham45, Eeems, Shmibs, Deep Thought and AngelFish, not me.)
Editor
LV15 Omnimagician (Next: --)
*
Online Online

Gender: Male
Last Login: Today at 10:22:11
Date Registered: 25 August, 2008, 07:00:21
Location: Québec (Canada)
Posts: 50665


Total Post Ratings: +2640

View Profile WWW
« Reply #2 on: 23 May, 2011, 21:54:11 »
0

Thanks Ashbad for those routines. Hopefully they might be useful for some people here too. Some other people should post routines here too if they have any.
Logged

Retired 83+ coder, Omnimaga/TIMGUL founder. Now doing power metal music (formerly did electronica)

Follow me on Bandcamp|Facebook|Reverbnation|Youtube|Twitter|Myspace
Ashbad
Guest
« Reply #3 on: 23 May, 2011, 22:12:59 »
0

Please, use Syscall 0x01E6 to obtain the VRAM address.
Interface: void *GetVRAMAddress(void);

I could, but since the address is known, it's a whole lot easier in many cases just to remember the magic number 0xA8000000 Wink however, good point brought up.

I just updated the first post at the bottom with an updated BFILE_syscalls.h header, which will prove to be very useful if you're opening any files at all.
Logged
DJ Omnimaga
Retired Omnimaga founder (Site issues must be PM'ed to Netham45, Eeems, Shmibs, Deep Thought and AngelFish, not me.)
Editor
LV15 Omnimagician (Next: --)
*
Online Online

Gender: Male
Last Login: Today at 10:22:11
Date Registered: 25 August, 2008, 07:00:21
Location: Québec (Canada)
Posts: 50665


Total Post Ratings: +2640

View Profile WWW
« Reply #4 on: 23 May, 2011, 22:13:46 »
0

Could the address possibly change in future OS versions? I hope not....
Logged

Retired 83+ coder, Omnimaga/TIMGUL founder. Now doing power metal music (formerly did electronica)

Follow me on Bandcamp|Facebook|Reverbnation|Youtube|Twitter|Myspace
Ashbad
Guest
« Reply #5 on: 23 May, 2011, 22:19:51 »
0

Could the address possibly change in future OS versions? I hope not....

From what I know, I don't think it would, then many other things would also get moved around, so I think for now we're safe Smiley
Logged
AngelFish
This is my custom title
Administrator
LV12 Extreme Poster (Next: 5000)
*
Offline Offline

Gender: Male
Last Login: Today at 00:16:41
Date Registered: 15 August, 2010, 09:18:54
Posts: 3192


Total Post Ratings: +222

View Profile
« Reply #6 on: 23 May, 2011, 22:41:05 »
0

I see no reason why they couldn't change it, to be honest. All it would take is a change in the TLB code to move it. A few hundred bytes right or left isn't that much stuff to rearrange. They did that to make the Prizm OS, if anyone remembers.
« Last Edit: 23 May, 2011, 22:41:42 by Qwerty.55 » Logged

∂²Ψ    -(2m(V(x)-E)Ψ
---  = -------------
∂x²        ℏ²Ψ
DJ Omnimaga
Retired Omnimaga founder (Site issues must be PM'ed to Netham45, Eeems, Shmibs, Deep Thought and AngelFish, not me.)
Editor
LV15 Omnimagician (Next: --)
*
Online Online

Gender: Male
Last Login: Today at 10:22:11
Date Registered: 25 August, 2008, 07:00:21
Location: Québec (Canada)
Posts: 50665


Total Post Ratings: +2640

View Profile WWW
« Reply #7 on: 23 May, 2011, 22:56:20 »
0

Yeah true. I just hope it won't change too much from an OS to another. Remember the mess when OS 2.53MP got released
Logged

Retired 83+ coder, Omnimaga/TIMGUL founder. Now doing power metal music (formerly did electronica)

Follow me on Bandcamp|Facebook|Reverbnation|Youtube|Twitter|Myspace
Ashbad
Guest
« Reply #8 on: 23 May, 2011, 23:27:02 »
0

a few new routines, obviously ripped from somebody else and not by me, but however, I shall give full credit to the genius author of these awesome routines, prizmized by me.  EDIT: I was not able to easily convert a generic polygon-filling C routine to a decent Prizm-like format, so feel free to find/make your own Smiley

See if point is within bounds of a polygon

inputs:
int    polySides  =  how many corners the polygon has
float  polyX[]    =  horizontal coordinates of corners
float  polyY[]    =  vertical coordinates of corners
float  x, y       =  point to be tested

outputs:
returns if the point is within the bounds of the polygon.

Credit: many thanks to Darel Rex Finley, http://alienryderflex.com/polygon/




1
2
3
4
5
6
7
8
9
10
11
12
13
14
bool pointInPolygon(int polySides, float polyX[], float polyY[], float x, float y) {

  int      i, j=polySides-1 ;
  boolean  oddNodes=0      ;

  for (i=0; i<polySides; i++) {
    if (polyY[i]<y && polyY[j]>=y
    ||  polyY[j]<y && polyY[i]>=y) {
      if (polyX[i]+(y-polyY[i])/(polyY[j]-polyY[i])*(polyX[j]-polyX[i])<x) {
        oddNodes=!oddNodes; }}
    j=i; }

  return oddNodes;
}
Logged
fxdev
LV4 Regular (Next: 200)
****
Offline Offline

Last Login: 19 March, 2013, 20:52:08
Date Registered: 18 January, 2011, 16:21:14
Posts: 177

Total Post Ratings: +28

View Profile
« Reply #9 on: 23 May, 2011, 23:43:16 »
0

Quote
I could, but since the address is known, it's a whole lot easier in many cases just to remember the magic number 0xA8000000.

Quote
Could the address possibly change in future OS versions? I hope not....

They did this with OS 2.00 for the fx-9860G/GII back in 2009 and broke several hard-coded add-ins. So, do not rely on 0xA8000000.
« Last Edit: 23 May, 2011, 23:45:54 by cfxm » Logged
DJ Omnimaga
Retired Omnimaga founder (Site issues must be PM'ed to Netham45, Eeems, Shmibs, Deep Thought and AngelFish, not me.)
Editor
LV15 Omnimagician (Next: --)
*
Online Online

Gender: Male
Last Login: Today at 10:22:11
Date Registered: 25 August, 2008, 07:00:21
Location: Québec (Canada)
Posts: 50665


Total Post Ratings: +2640

View Profile WWW
« Reply #10 on: 23 May, 2011, 23:47:20 »
0

Ouch this sucks. I think it would be best to avoid direct address usage then. I think this is what we do on some 83+ stuff.
Logged

Retired 83+ coder, Omnimaga/TIMGUL founder. Now doing power metal music (formerly did electronica)

Follow me on Bandcamp|Facebook|Reverbnation|Youtube|Twitter|Myspace
z80man
Casio Traitor
LV8 Addict (Next: 1000)
********
Offline Offline

Gender: Male
Last Login: 10 June, 2013, 08:37:04
Date Registered: 26 December, 2010, 10:02:50
Location: City 17
Posts: 966


Total Post Ratings: +83

View Profile
« Reply #11 on: 25 May, 2011, 10:54:08 »
0

Please, use Syscall 0x01E6 to obtain the VRAM address.
Interface: void *GetVRAMAddress(void);
Due to my dislike of any syscalls I will just write a routine that does the exact same thing and polls the same address from ROM. It sounds foolish, but that is just the way I roll  Cool

Note: I will go as far as file systems and text routines when it comes to avoiding syscalls.
Logged


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)
fxdev
LV4 Regular (Next: 200)
****
Offline Offline

Last Login: 19 March, 2013, 20:52:08
Date Registered: 18 January, 2011, 16:21:14
Posts: 177

Total Post Ratings: +28

View Profile
« Reply #12 on: 25 May, 2011, 13:00:16 »
0

Okay, your decision but as long as a Prizm routine isn't buggy and fits my needs, I won't rewrite the whole thing.
Logged
z80man
Casio Traitor
LV8 Addict (Next: 1000)
********
Offline Offline

Gender: Male
Last Login: 10 June, 2013, 08:37:04
Date Registered: 26 December, 2010, 10:02:50
Location: City 17
Posts: 966


Total Post Ratings: +83

View Profile
« Reply #13 on: 26 May, 2011, 16:36:58 »
0

Alright I have a conversion from C to asm. It is get pixel and is as fast as possible and can be no more optimized. Unless gcc automatically handles the zero extension which I'll have to check.


Test a pixel of CURRENTLY rendered VRAM image (z80man optimized)


1
2
3
4
5
6
7
8
9
10
11
12
13
14
short GetPixel(short x, short y)
{
    MOV.W (width),R2
    MOV.L (VRAM),R3
    MULU.W r2,R5
    ADD R4,R3
    STS MACL,R2
    ADD R3,R2
    MOV.W @R2,R0
    RTS
    EXTU.W R0
    align.4
    width: word 384
    VRAM: long VRAM_address

Logged


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)
Ashbad
Guest
« Reply #14 on: 27 May, 2011, 00:48:36 »
0

this is awesome Cheesy I would suggest putting it into .s format so C coders can use it.
Logged
Pages: [1] 2 3 ... 5   Go Up
  Print  
 
Jump to:  

Powered by EzPortal
Powered by MySQL Powered by SMF 1.1.18 | SMF © 2013, Simple Machines Powered by PHP
Page created in 0.437 seconds with 30 queries.
Skin by DJ Omnimaga edited from SMF default theme with the help of tr1p1ea.
All programs, games and songs avaliable on this website are property of their respective owners.
Best viewed in Opera, Firefox, Chrome and Safari with a resolution of 1024x768 or above.