CEMETECH
Leading The Way To The Future
Login [Register]
Username:
Password:
Autologin:

Don't have an account? Register now to chat, post, use our tools, and much more.
Latest Headlines
Online Users
There are 136 users online: 7 members, 96 guests and 33 bots.
Members: charlessprinkle, DudeGuy, shkaboinka.
Bots: VoilaBot (3), Magpie Crawler (3), VoilaBot (9), Googlebot (18).
RSS & Social Media
SAX
You must log in to view the SAX chat widget
Author Message
KermMartian


Site Admin


Joined: 14 Mar 2005
Posts: 55881
Location: Earth, Sol, Milky Way

Posted: 22 May 2011 06:04:05 pm    Post subject:

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
_________________


Back to top
calcman


Advanced Member


Joined: 21 Mar 2011
Posts: 283

Posted: 22 May 2011 06:11:23 pm    Post subject:

Are these examples in C? Because I don't understand them.
_________________




-Calcman
Back to top
souvik1997


Guru-in-Training


Joined: 19 Apr 2010
Posts: 2870

Posted: 22 May 2011 06:11:58 pm    Post subject:

Yes, they are in C and SH3 asm.
_________________
CALCnet Tournament-38%


deviantArt
Back to top
Ashbad


I am governor Jerry Brown


Joined: 01 Dec 2010
Posts: 2423
Location: There lived a certain man in Russia long ago

Posted: 22 May 2011 06:23:27 pm    Post subject:

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);
     }
}

_________________
-Ashbad


Last edited by Ashbad on 11 Jun 2011 10:18:46 am; edited 1 time in total
Back to top
Qwerty.55


Expert


Joined: 08 Dec 2010
Posts: 613

Posted: 22 May 2011 06:28:49 pm    Post subject:

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.
_________________
∂²Ψ -(2m(V(x)-E)Ψ
----- = -------------
∂x² ℏ²Ψ
Back to top
Ashbad


I am governor Jerry Brown


Joined: 01 Dec 2010
Posts: 2423
Location: There lived a certain man in Russia long ago

Posted: 22 May 2011 08:32:03 pm    Post subject:

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);
  }
}

_________________
-Ashbad
Back to top
z80man


New Member


Joined: 01 May 2011
Posts: 77
Location: City 17

Posted: 23 May 2011 01:51:19 am    Post subject:

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
Back to top
Ashbad


I am governor Jerry Brown


Joined: 01 Dec 2010
Posts: 2423
Location: There lived a certain man in Russia long ago

Posted: 23 May 2011 08:47:49 am    Post subject:

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
Back to top
KermMartian


Site Admin


Joined: 14 Mar 2005
Posts: 55881
Location: Earth, Sol, Milky Way

Posted: 23 May 2011 12:36:15 pm    Post subject:

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);
  }
}

_________________


Back to top
Ashbad


I am governor Jerry Brown


Joined: 01 Dec 2010
Posts: 2423
Location: There lived a certain man in Russia long ago

Posted: 23 May 2011 01:55:19 pm    Post subject:

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
Back to top
KermMartian


Site Admin


Joined: 14 Mar 2005
Posts: 55881
Location: Earth, Sol, Milky Way

Posted: 23 May 2011 01:56:58 pm    Post subject:

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
_________________


Back to top
Ashbad


I am governor Jerry Brown


Joined: 01 Dec 2010
Posts: 2423
Location: There lived a certain man in Russia long ago

Posted: 23 May 2011 02:28:50 pm    Post subject:

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


Last edited by Ashbad on 23 May 2011 04:02:24 pm; edited 1 time in total
Back to top
KermMartian


Site Admin


Joined: 14 Mar 2005
Posts: 55881
Location: Earth, Sol, Milky Way

Posted: 23 May 2011 03:57:01 pm    Post subject:

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
_________________


Back to top
Ashbad


I am governor Jerry Brown


Joined: 01 Dec 2010
Posts: 2423
Location: There lived a certain man in Russia long ago

Posted: 23 May 2011 04:01:16 pm    Post subject:

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;
}

_________________
-Ashbad
Back to top
Qwerty.55


Expert


Joined: 08 Dec 2010
Posts: 613

Posted: 12 Jun 2011 02:21:31 pm    Post subject:

So nice to spend all the time ripping the circle routine from wikipedia then find it already on here Razz
_________________
∂²Ψ -(2m(V(x)-E)Ψ
----- = -------------
∂x² ℏ²Ψ
Back to top
TheStorm


NOU!


Joined: 26 Mar 2007
Posts: 2375

Posted: 12 Jun 2011 02:27:09 pm    Post subject:

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.
_________________

"Always code as if the person who will maintain your code is a maniac serial killer that knows where you live" -Unknown

"If you've done something right no one will know that you've done anything at all" -Futurama

"Have a nice day, or not, the choice is yours." Tom Steiner

<Michael_V> or create a Borg collective and call it The 83+
<Michael_V> Lower your slide cases and prepare to be silent linked. Memory clears are futile.
Back to top
z80man


New Member


Joined: 01 May 2011
Posts: 77
Location: City 17

Posted: 12 Jun 2011 03:48:55 pm    Post subject:

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.
Back to top
TheStorm


NOU!


Joined: 26 Mar 2007
Posts: 2375

Posted: 12 Jun 2011 03:52:14 pm    Post subject:

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
_________________

"Always code as if the person who will maintain your code is a maniac serial killer that knows where you live" -Unknown

"If you've done something right no one will know that you've done anything at all" -Futurama

"Have a nice day, or not, the choice is yours." Tom Steiner

<Michael_V> or create a Borg collective and call it The 83+
<Michael_V> Lower your slide cases and prepare to be silent linked. Memory clears are futile.
Back to top
Qwerty.55


Expert


Joined: 08 Dec 2010
Posts: 613

Posted: 12 Jun 2011 04:08:38 pm    Post subject:

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
_________________
∂²Ψ -(2m(V(x)-E)Ψ
----- = -------------
∂x² ℏ²Ψ
Back to top
TheStorm


NOU!


Joined: 26 Mar 2007
Posts: 2375

Posted: 12 Jun 2011 04:09:34 pm    Post subject:

Qwerty newlib is a libc implementation. You give it a base set of syscalls and it it provides the rest of the libc routines.
_________________

"Always code as if the person who will maintain your code is a maniac serial killer that knows where you live" -Unknown

"If you've done something right no one will know that you've done anything at all" -Futurama

"Have a nice day, or not, the choice is yours." Tom Steiner

<Michael_V> or create a Borg collective and call it The 83+
<Michael_V> Lower your slide cases and prepare to be silent linked. Memory clears are futile.
Back to top
Display posts from previous:   
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 ... 9, 10, 11  Next
» View previous topic :: View next topic  
Page 4 of 11 » All times are GMT - 5 Hours

 
Jump to:  
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

© Copyright 2000-2013 Cemetech & Kerm Martian :: Page Execution Time: 0.044680 seconds.