Qwerty, it's actually much easier to "force" the programmer to remember types and let the compiler figure out all the annoying math details associated with each type in the long run than expose the lowest-level stuff. Tari is absolutely right; there's no reason for me to be accessing the VRAM as a char* instead of a short* other that what I think was an initial fear of using shorts on the sh4a in case the non-GCC compiler would handle the type differently than I would expect. Smile
Are these examples in C? Because I don't understand them.
Yes, they are in C and SH3 asm.
Qwerty's is in SH4 asm, and all the others are in C Smile

and, improvement on my last routine.

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 Smile (unless you don't render it)




Code:
void PutCustC(char*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);
     }
}
calcman wrote:
Are these examples in C? Because I don't understand them.


Anything by z80man or I is probably in [optimized] ASM and everything else is almost certainly C, as Ashbad said.
Draw Circle Routine

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

NOTE: uses a SetPoint routine in display_syscalls.h


Code:
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);
  }
}
Qwerty.55 wrote:
calcman wrote:
Are these examples in C? Because I don't understand them.


Anything by z80man or I is probably in [optimized] ASM and everything else is almost certainly C, as Ashbad said.
Well I will do C and asm depending on what is needed. Complex stuff that is not speed dependent I will write in C while most math and data based operations will be done in asm using inline functions. An example of something that I'd do in asm is floating point math because I don't trust gcc with my floats Wink
GCC is extremely optimizing with Math functions -- and if you want to inline things, all you have to do is go through the trouble of calling a function as 'inline' as of C99 -- maybe GCC will add maybe an extra byte or so, but it's not like it's gonna kill your performance whatsoever. Your choice though.
Ashbad, now you're just stealing routines directly from Obliterate. Razz You renamed my RasterCircle function:


Code:
void rasterCircle(int x0, int y0, int radius, int color) {
  int f = 1 - radius;
  int ddF_x = 1;
  int ddF_y = -2 * radius;
  int x = 0;
  int y = radius;
 
  plot(x0, y0 + radius, color);
  plot(x0, y0 - radius, color);
  plot(x0 + radius, y0, color);
  plot(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;   
    plot(x0 + x, y0 + y, color);
    plot(x0 - x, y0 + y, color);
    plot(x0 + x, y0 - y, color);
    plot(x0 - x, y0 - y, color);
    plot(x0 + y, y0 + x, color);
    plot(x0 - y, y0 + x, color);
    plot(x0 + y, y0 - x, color);
    plot(x0 - y, y0 - x, color);
  }
}
KermMartian wrote:
Ashbad, now you're just stealing routines directly from Obliterate. Razz You renamed my RasterCircle function


which we both stole from this. I would prefer it if I wasn't accused of stealing your algorithms when I haven't even looked at the obliterate source code before.
Ashbad wrote:
KermMartian wrote:
Ashbad, now you're just stealing routines directly from Obliterate. Razz You renamed my RasterCircle function


which we both stole from this. I would prefer it if I wasn't accused of stealing your algorithms when I haven't even looked at the obliterate source code before.
Hehe, it was a joke; I know I got it straight from the internet after some searching. Wink
okay, whatever Razz I just take great offense when someone accuses me of stealing code from another project, I try my best to not take code unless it only accomplish able in one way and everyone uses it anyways, like that raster circle. And, making routines is quite the new favorite pastime of mine lately Smile

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.


Code:
#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 );
Ashbad wrote:
okay, whatever Razz I just take great offense when someone accuses me of stealing code from another project, I try my best to not take code unless it only accomplish able in one way and everyone uses it anyways, like that raster circle.
I'd say we did both steal that routine, but that's neither here nor there. I vote you rename those macros for the standard C open symbol names:

http://www.delorie.com/gnu/docs/glibc/libc_261.html
I can make them more similar, like _OPENMODE_READ to O_READ, but that's the farthest I can go -- the function with these seem too different to give them other names. I'll fix them now though, good idea Smile

also,

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 Smile



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/




Code:
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;
}
So nice to spend all the time ripping the circle routine from wikipedia then find it already on here Razz
Kerm, on the libc me and qwerty are working on seeing if we can get newlib built for the prizm, but it may require rebuilding gcc and binutils so I want to make sure I have it right first.
TheStorm wrote:
Kerm, on the libc me and qwerty are working on seeing if we can get newlib built for the prizm, but it may require rebuilding gcc and binutils so I want to make sure I have it right first.
Sounds fun, anyway I can help out with routines. I just checked newlib's documentation and it seems very feasible to port.
z80man wrote:
TheStorm wrote:
Kerm, on the libc me and qwerty are working on seeing if we can get newlib built for the prizm, but it may require rebuilding gcc and binutils so I want to make sure I have it right first.
Sounds fun, anyway I can help out with routines. I just checked newlib's documentation and it seems very feasible to port.
Feasible yes, easy to pull off by people to haven't done it before, eh we'll see. Razz
TheStorm wrote:
...easy to pull off by people to haven't done it before, eh we'll see. Razz


*One of whom still isn't entirely clear on exactly what newlib does Razz
Qwerty newlib is a libc implementation. You give it a base set of syscalls and it it provides the rest of the libc routines.
  
Register to Join the Conversation
Have your own thoughts to add to this or any other topic? Want to ask a question, offer a suggestion, share your own programs and projects, upload a file to the file archives, get help with calculator and computer programming, or simply chat with like-minded coders and tech and calculator enthusiasts via the site-wide AJAX SAX widget? Registration for a free Cemetech account only takes a minute.

» Go to Registration page
» Goto page Previous  1, 2, 3, 4, 5 ... 10, 11, 12  Next
» View previous topic :: View next topic  
Page 4 of 12
» All times are UTC - 5 Hours
 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

 

Advertisement