GP32 Ascii Painting


Tobriand

Well-Known Member
Joined
Dec 27, 2002
Messages
4,071
Age
38
Location
Croydon (UK)
Website
Visit site
Right... I've finally managd to get Mr Mirko's SDK compiling in Windows, so then I thought I'd have a bash at the tutorials. Which went well for the first one (what I could be bothred to do to start with), before I decided to try and write something pretty basic of my own - a paint program for ASCII characters.

I've got moving of the character working fairly well, but I'm having trouble using a variable character (it always comes out as something other than what brush tries to make it - though I can replace brush with a "<character>" and it'll work in the gp_SetFont8 bits) and changing colours.

I've pasted the entire souce in, and I'm sorry that most of it is riddled with left-overs from previous experiements and thus is somewhat incomprehensible. As you can see, its based on the first of Synkro's tutorials, primarily because I couldn't be bothered to type out my own Framebuffer et al.

Any help would be appreciated. Bar the tutorial, this is my first GP32 project, and my second in C (the first didn't work though lol), so forgive me any blatant blunders I've made.
Code:
// Based on a heavily heavily modified version of Synkro's "Hello World" tutorial

#include <gp32.h>            // Includes the SDK header with all definitions

unsigned short *framebuffer; // A framebuffer pointer


void main(void)
{
  framebuffer = (unsigned short*) FRAMEBUFFER;

  gp_SetScreen(framebuffer, 16);

  int i;
  for (i=0; i<320*240; i++) framebuffer[i]=0xFFFF;

  gp_SetCpuSpeed(66);

  
  int x_pos   = 150;     // This int stores the x-position of the text
  int y_pos   = 110;
  int length  = 1;     // length of the char[] to be drawn
  int color   = 0x0000; // RGB (RRRRRGGGGGBBBBB0 = 16 bit)
  char brushbank[10]  = "^*OoE#~+=-5";
  int brushnumb = 0;
  int brush = brushbank[brushnumb];
  int colorchange = 0;
  int breaker = 0;
  
  while(breaker == 0)
  {
  int stopper;
  gp_SetFont8(x_pos, y_pos, length, brush, 0xF000, framebuffer);
  
  gp_ButtonInit();

  //The next bit of code is for directional movement. No diagonals yet, though.

  while (gp_ButtonResult()&BUP)
   {
    gp_SetFont8(x_pos, y_pos, length, brush, color, framebuffer);
    y_pos = y_pos - 8;
    gp_SetFont8(x_pos, y_pos, length, brush, 0xF000, framebuffer);
    for (stopper = 0; stopper < 1000000; stopper ++) {stopper=stopper;};
   };
  while (gp_ButtonResult()&BDOWN)
   {
    gp_SetFont8(x_pos, y_pos, length, brush, color, framebuffer);
    y_pos = y_pos + 8;
    gp_SetFont8(x_pos, y_pos, length, brush, 0xF000, framebuffer);
    for (stopper = 0; stopper < 1000000; stopper ++) {stopper=stopper;};
   };
  while (gp_ButtonResult()&BLEFT)
   {
    gp_SetFont8(x_pos, y_pos, length, brush, color, framebuffer);
    x_pos = x_pos - 8;
    gp_SetFont8(x_pos, y_pos, length, brush, 0xF000, framebuffer);
    for (stopper = 0; stopper < 1000000; stopper ++) {stopper=stopper;};
   };
  while (gp_ButtonResult()&BRIGHT)
   {
    gp_SetFont8(x_pos, y_pos, length, brush, color, framebuffer);
    x_pos = x_pos + 8;
    gp_SetFont8(x_pos, y_pos, length, brush, 0xF000, framebuffer);
    for (stopper = 0; stopper < 1000000; stopper ++) {stopper=stopper;};
   };

  //Now we're onto colour changing, which is proving damn hard.
  while (gp_ButtonResult()&BA)
   {
    brushnumb ++;
    if (brushnumb = 11) brushnumb = 0;
    gp_SetFont8(10, 10, 1, brush, color, framebuffer);
    for (stopper = 0; stopper < 1000000; stopper ++) {stopper=stopper;};
   }

  //So instead we're going to skip to channging ASCII symbols

  while (gp_ButtonResult()&BB)
   {
    brushnumb ++;
    if (brushnumb = 11) brushnumb = 0;
    gp_SetFont8(10, 10, 1, brush, color, framebuffer);
    for (stopper = 0; stopper < 1000000; stopper ++) {stopper=stopper;};
   }

  if (brushnumb == 0) brush = "^";
  if (brushnumb == 1) brush = "A";
  
  // Lets just add some clearing bits quickly
  if (gp_ButtonResult()&BSTART)
   {
    breaker = 1;
   }
  if (breaker == 1) break;
  };
} // End of the "main" function
 
//So instead we're going to skip to channging ASCII symbols

while (gp_ButtonResult()&BB)
{
brushnumb ++;
if (brushnumb = 11) brushnumb = 0;
gp_SetFont8(10, 10, 1, brush, color, framebuffer);
for (stopper = 0; stopper < 1000000; stopper ++) {stopper=stopper;};
}

Note that line " if (brushnumb = 11) brushnumb = 0;"? It should be == instead of =. Code is behaving very strange when you forget this. ;)
 
Oh, and I forgot: your delay-routine sucks :D
I know, Mirko used them for his examples... He's not a role model with that. ;)
Instead try something like this:

Code:
void Delay(int ticks)
{
        int i=0;
        gp_ResetRTC();
        while(i!=ticks)
        {
                i=gp_GetRTC();
        }
}

which basically waits ticks * 1/128 second.
 
Ah, the old == / = trick that even I have fallen into. There must a compiler warning for this, I've seen it... but how do you enable it?
 
Thanks all!
Got it working now (at last) for both colour and brushes :D

Now all I need to work out how to do is save a framebuffer as a bmp, but that can come in future versions.
 
Back
Top