gbadev.org forum archive

This is a read-only mirror of the content originally found on forum.gbadev.org (now offline), salvaged from Wayback machine copies. A new forum can be found here.

Beginners > messed text :S

#63751 - ghost Leinad - Fri Dec 16, 2005 2:30 am

I have a problem with text too.

Id managed to make my own text function. It works fine but it has a little problem.

when I declare a variable like this: const char *texto="smt,smt"; it works fine but if I add const char *texto="smt,smt???"; the text looks like

http://img513.imageshack.us/img513/9409/error0pr.png (looks nice eh!! lol)

well, why my tiles are all messed up???

this happen only when I used symbols like ??()?!. all those variables are declared as const. But now I have like 30 different texts, with diferrent names (should I use just one variable, and keep it changing it on the road???)

Ah, and before I forgot, how do I handle the " symbol???

Tanx in advance, hope you can help me
_________________
All human wisdom is summed up in these two words, - 'Wait and hope"
****************************************
My site www.myth-world.net and www.bmrpg.com :)

#63755 - tepples - Fri Dec 16, 2005 2:43 am

ghost Leinad wrote:
Id managed to make my own text function. It works fine but it has a little problem.

when I declare a variable like this: const char *texto="smt,smt"; it works fine but if I add const char *texto="smt,smt???"; the text looks like

http://img513.imageshack.us/img513/9409/error0pr.png (looks nice eh!! lol)

well, why my tiles are all messed up???

this happen only when I used symbols like ??()?!.

Are you sure those symbols are in your font?

Quote:
Ah, and before I forgot, how do I handle the " symbol???

"an \"easy\" problem"
_________________
-- Where is he?
-- Who?
-- You know, the human.
-- I think he moved to Tilwick.

#63758 - ghost Leinad - Fri Dec 16, 2005 3:11 am

yes tiles 183 and 184 :P

in fact I can use those symbols like 3 or 4 times, but when I overused them the screen shows up like that

+++++++

an easy problem??? what do you mean by that???

I'll check your agbtty :D, but try it to explain it...

how do I handle letters with accents???when I try to compile a text like "L?pez" says something like ? is not a single letter character.

I guess I should use some grammar to handle that, or am I wrong??
_________________
All human wisdom is summed up in these two words, - 'Wait and hope"
****************************************
My site www.myth-world.net and www.bmrpg.com :)

#63774 - gauauu - Fri Dec 16, 2005 5:47 am

notice his use of the backslash before the quotes. So if you want to include a quote mark in your string, just use a backslash to escape it:

Code:
const char * myString = "this string has \"quotes\" around the word quotes";

#63791 - Cearn - Fri Dec 16, 2005 9:34 am

It might help if we got to see some of the code your using to produce this.

On accented characters, '?' is part of the ascii/unicode character set, number 243 (although old dos had it as 162). How you want to use that depends on what your code currently looks like.

#64049 - ghost Leinad - Sun Dec 18, 2005 11:00 pm

well, look at my variables
Code:

const char *textojugar01="HOLA, MI NOMBRE ES JUGAR BIENVENIDO AL SISTEMA DE ENSEムANZA DEL COCITECH, ESPERO QUE TE DIVIERTAS_";
const char *textojugar02="EL CUADRADO MAGICO ELEGIRAS SI TU LOGICA QUIERES MEJORAR. HAZ QUE LOS NUMEROS SUMEN IGUAL_";
const char *textojugar03="SI TE SIENTES CREATIVO, PRUEBA USAR EL TANGRAMA. USA TU IMAGINACION PARA CREAR MILES DE FIGURAS DIFERENTES_";
const char *textojugar04="TORRES DE HANOI_";
const char *textojugar05="ACOMODA LA FIGURA EN SU LUGAR_";
const char *textojugar06="SUMA LOS NUMEROS_";
const char *textojugar07="APAGA LOS BOTONES_";
const char *textojugar08="ソQUIERES CONOCER EL OBJETIVO DEL JUEGO?_";
const char *textojugar09="EL OBJETIVO DEL CUADRADO MAGICO ES HACER QUE TODAS LAS SUMAS SEAN IGUALES A 15, SI LO CONSIGUES, GANAS_";
const char *textojugar10="FELICIDADES, GANASTE                                DESEAS JUGAR DE NUEVO_";
const char *textojugar11="LO SIENTO, PERDISTE                                 DESEAS JUGAR DE NUEVO_";


you call the text funcion like this

Code:

textomargen(textojugar11,0,112,0);

as you asked it, here's my code for my text function

Code:

void textomargen(const char *a, int postextox, int postextoy, int numeropallete)
{

   int j=0;
   int k=0;
   int m=0;
   int filas=4;
   int longitud=0;
   int cuentaletras=0;
   int c=0;
   int flagletrasdespacio=0;
   int pallete=0x0000;
   
   j=0;
   k=0;
   m=0;
   filas=4;
   longitud=0;
   cuentaletras=0;
   c=0;
   flagletrasdespacio=0;
   pallete=0x0000;

   iniciaTypewriter();
      
   switch(numeropallete)
   {
      case 0: pallete=PALLETE00;break;
      case 1: pallete=PALLETE01;break;
      case 2: pallete=PALLETE02;break;
      case 3: pallete=PALLETE03;break;
      case 4: pallete=PALLETE04;break;
      case 5: pallete=PALLETE05;break;
      case 6: pallete=PALLETE06;break;
      case 7: pallete=PALLETE07;break;
      case 8: pallete=PALLETE08;break;
      case 9: pallete=PALLETE09;break;
      case 10: pallete=PALLETE10;break;
      case 11: pallete=PALLETE11;break;
      case 12: pallete=PALLETE12;break;
      case 13: pallete=PALLETE13;break;
      case 14: pallete=PALLETE14;break;
      case 15: pallete=PALLETE15;break;

   }

   for(m=1;m<5;m++)
   {

      for(i=2;i<28;i++)
      {
         vramMap1[i+(m*32)]=97 | pallete;
      }
   }

   vramMap1[1]=186 | pallete;
   vramMap1[28]=190 | pallete;
   vramMap1[1+(5*32)]=188 | pallete;
   vramMap1[28+(5*32)]=192 | pallete;
   for(i=2;i<28;i++)
   {
      vramMap1[i]=189 | pallete;
      vramMap1[i+(5*32)]=193 | pallete;
   }
   for(i=1;i<5;i++)
   {
      vramMap1[1+(i*32)]=187 | pallete;
      vramMap1[28+(i*32)]=191 | pallete;
   }
   

while(a[j]!='_')
{
   switch(a[j])
   {
      case ' ':textback[j]=97;break;
      case 'A':textback[j]=98;break;
      case 'B':textback[j]=99;break;
      case 'C':textback[j]=100;break;
      case 'D':textback[j]=101;break;
      case 'E':textback[j]=102;break;
      case 'F':textback[j]=103;break;
      case 'G':textback[j]=104;break;
      case 'H':textback[j]=105;break;
      case 'I':textback[j]=106;break;
      case 'J':textback[j]=107;break;
      case 'K':textback[j]=108;break;
      case 'L':textback[j]=109;break;
      case 'M':textback[j]=110;break;
      case 'N':textback[j]=111;break;
      case 'ム':textback[j]=112;break;
      case 'O':textback[j]=113;break;
      case 'P':textback[j]=114;break;
      case 'Q':textback[j]=115;break;
      case 'R':textback[j]=116;break;
      case 'S':textback[j]=117;break;
      case 'T':textback[j]=118;break;
      case 'U':textback[j]=119;break;
      case 'V':textback[j]=120;break;
      case 'W':textback[j]=121;break;
      case 'X':textback[j]=122;break;
      case 'Y':textback[j]=123;break;
      case 'Z':textback[j]=124;break;
      case 'a':textback[j]=125;break;
      case 'b':textback[j]=126;break;
      case 'c':textback[j]=127;break;
      case 'd':textback[j]=128;break;
      case 'e':textback[j]=129;break;
      case 'f':textback[j]=130;break;
      case 'g':textback[j]=131;break;
      case 'h':textback[j]=132;break;
      case 'i':textback[j]=133;break;
      case 'j':textback[j]=134;break;
      case 'k':textback[j]=135;break;
      case 'l':textback[j]=136;break;
      case 'm':textback[j]=137;break;
      case 'n':textback[j]=138;break;
      case '・:textback[j]=139;break;
      case 'o':textback[j]=140;break;
      case 'p':textback[j]=141;break;
      case 'q':textback[j]=142;break;
      case 'r':textback[j]=143;break;
      case 's':textback[j]=144;break;
      case 't':textback[j]=145;break;
      case 'u':textback[j]=146;break;
      case 'v':textback[j]=147;break;
      case 'w':textback[j]=148;break;
      case 'x':textback[j]=149;break;
      case 'y':textback[j]=150;break;
      case 'z':textback[j]=151;break;
      case '0':textback[j]=152;break;
      case '1':textback[j]=153;break;
      case '2':textback[j]=154;break;
      case '3':textback[j]=155;break;
      case '4':textback[j]=156;break;
      case '5':textback[j]=157;break;
      case '6':textback[j]=158;break;
      case '7':textback[j]=159;break;
      case '8':textback[j]=160;break;
      case '9':textback[j]=161;break;
      case '!':textback[j]=162;break;
      case '。':textback[j]=163;break;
      case '#':textback[j]=166;break;
      case '$':textback[j]=167;break;
      case '%':textback[j]=168;break;
      case '&':textback[j]=169;break;
      case '|':textback[j]=170;break;      //simbolo ' (apostrofe)
      case '(':textback[j]=171;break;
      case ')':textback[j]=172;break;
      case '*':textback[j]=173;break;
      case '+':textback[j]=174;break;
      case ',':textback[j]=175;break;
      case '-':textback[j]=176;break;
      case '.':textback[j]=177;break;
      case '/':textback[j]=178;break;
      case ':':textback[j]=179;break;
      case ';':textback[j]=180;break;
      case '<':textback[j]=181;break;
      case '>':textback[j]=182;break;
      case '=':textback[j]=183;break;
      case '?':textback[j]=184;break;
      case 'ソ':textback[j]=185;break;
      case '{':textback[j]=195;break;
      case '}':textback[j]=196;break;
      case '[':textback[j]=197;break;
      case ']':textback[j]=198;break;
      case '~':textback[j]=199;break;
      default:break;
   }
   j++;
   longitud++;
}

REG_BG0HOFS=256-postextox;
REG_BG0VOFS=256-postextoy;

flagsinglepress=1;

      for(k=1;k<=filas;k++)
      {
         for(i=2;i<28;i++)
         {
            if(flagletrasdespacio==0)
            {
               while(m<2)
               {
                  if(keyDown(KEY_A))
                  {
                     flagsinglepress++;
                     if(flagsinglepress<2)
                     {
                        flagletrasdespacio=1;
                     }
                  
                  }
                  else
                  {
                     flagsinglepress=0;
                     flagletrasdespacio=0;
                  }
                  if(textback[cuentaletras]==0 || textback[cuentaletras]==97)
                  {
                     m=3;
                  }

                  m++;
                  c++;
               }
            }
         
            if(cuentaletras<longitud)
            {
               switch(numeropallete)
               {
                  case 0: vramMap1[i+(k*32)]=textback[cuentaletras] | PALLETE00;
                     cuentaletras++;
                     if(textback[cuentaletras]!=0 && textback[cuentaletras]!=97)
                     {
                        Sonido_TypeWriter();
                     };break;
                  case 1: vramMap1[i+(k*32)]=textback[cuentaletras] | PALLETE01;
                     cuentaletras++;
                     if(textback[cuentaletras]!=0 && textback[cuentaletras]!=97)
                     {
                        Sonido_TypeWriter();
                     };break;
                  case 2: vramMap1[i+(k*32)]=textback[cuentaletras] | PALLETE02;
                     cuentaletras++;
                     if(textback[cuentaletras]!=0 && textback[cuentaletras]!=97)
                     {
                        Sonido_TypeWriter();
                     };break;
                  case 3: vramMap1[i+(k*32)]=textback[cuentaletras] | PALLETE03;
                     cuentaletras++;
                     if(textback[cuentaletras]!=0 && textback[cuentaletras]!=97)
                     {
                        Sonido_TypeWriter();
                     };break;
                  case 4: vramMap1[i+(k*32)]=textback[cuentaletras] | PALLETE04;
                     cuentaletras++;
                     if(textback[cuentaletras]!=0 && textback[cuentaletras]!=97)
                     {
                        Sonido_TypeWriter();
                     };break;
                  case 5: vramMap1[i+(k*32)]=textback[cuentaletras] | PALLETE05;
                     cuentaletras++;
                     if(textback[cuentaletras]!=0 && textback[cuentaletras]!=97)
                     {
                        Sonido_TypeWriter();
                     };break;
                  case 6: vramMap1[i+(k*32)]=textback[cuentaletras] | PALLETE06;
                     cuentaletras++;
                     if(textback[cuentaletras]!=0 && textback[cuentaletras]!=97)
                     {
                        Sonido_TypeWriter();
                     };break;
                  case 7: vramMap1[i+(k*32)]=textback[cuentaletras] | PALLETE07;
                     cuentaletras++;
                     if(textback[cuentaletras]!=0 && textback[cuentaletras]!=97)
                     {
                        Sonido_TypeWriter();
                     };break;
                  case 8: vramMap1[i+(k*32)]=textback[cuentaletras] | PALLETE08;
                     cuentaletras++;
                     if(textback[cuentaletras]!=0 && textback[cuentaletras]!=97)
                     {
                     Sonido_TypeWriter();
                     };break;
                  case 9: vramMap1[i+(k*32)]=textback[cuentaletras] | PALLETE09;
                     cuentaletras++;
                     if(textback[cuentaletras]!=0 && textback[cuentaletras]!=97)
                     {
                        Sonido_TypeWriter();
                     };break;
                  case 10: vramMap1[i+(k*32)]=textback[cuentaletras] | PALLETE10;
                     cuentaletras++;
                     if(textback[cuentaletras]!=0 && textback[cuentaletras]!=97)
                     {
                        Sonido_TypeWriter();
                     };break;
                  case 11: vramMap1[i+(k*32)]=textback[cuentaletras] | PALLETE11;
                     cuentaletras++;
                     if(textback[cuentaletras]!=0 && textback[cuentaletras]!=97)
                     {
                        Sonido_TypeWriter();
                     };break;
                  case 12: vramMap1[i+(k*32)]=textback[cuentaletras] | PALLETE12;
                     cuentaletras++;
                     if(textback[cuentaletras]!=0 && textback[cuentaletras]!=97)
                     {
                        Sonido_TypeWriter();
                     };break;
                  case 13: vramMap1[i+(k*32)]=textback[cuentaletras] | PALLETE13;
                     cuentaletras++;
                     if(textback[cuentaletras]!=0 && textback[cuentaletras]!=97)
                     {
                        Sonido_TypeWriter();
                     };break;
                  case 14: vramMap1[i+(k*32)]=textback[cuentaletras] | PALLETE14;
                     cuentaletras++;
                     if(textback[cuentaletras]!=0 && textback[cuentaletras]!=97)
                     {
                        Sonido_TypeWriter();
                     };break;
                  case 15: vramMap1[i+(k*32)]=textback[cuentaletras] | PALLETE15;
                     cuentaletras++;
                     if(textback[cuentaletras]!=0 && textback[cuentaletras]!=97)
                     {
                        Sonido_TypeWriter();
                     };break;
                  default: vramMap1[i+(k*32)]=textback[cuentaletras] | PALLETE00;
                     cuentaletras++;
                     if(textback[cuentaletras]!=0 && textback[cuentaletras]!=97)
                     {
                        Sonido_TypeWriter();
                     };break;
               }
               m=0;
            }
            c=0;

            if(cuentaletras>=longitud)
            {
               break;
            }

         }
      }

   
}


look, at that point everithing is right, my tile map for the text is shown like this:



[Images not permitted - Click here to view it]

and the text looks like this:

[Images not permitted - Click here to view it]

I'm using the textojugar01.


as you can see all the weird spanish symbols are in there :P

I just can't understand WHY when I add some (?!#) symbols, my tile map (And I mean my actual tile map, not just the text) is all scrambled :'(
_________________
All human wisdom is summed up in these two words, - 'Wait and hope"
****************************************
My site www.myth-world.net and www.bmrpg.com :)

#64052 - Cearn - Sun Dec 18, 2005 11:23 pm

ghost Leinad wrote:

Code:

void textomargen(const char *a, int postextox, int postextoy, int numeropallete)
{

<snipped a few hundreds of lines of code>

}


I'll try to find out where things go wrong later.

For now, let me introduce you to a dear friend of mine, the look-up table. The look-up table (LUT for short) is a technique that's been used since, well, forever I recon. As the name implies, it allows you to look things up. A LUT can be used to store pre-calculated numbers for, say, math table, which would otherwise be costly.
It can also be used for mappings. for example, when you have a a variable which needs to get a different, non-sequential value based on a numerical key, you don't use a switch, you use a LUT. Dump the values in an array and simply look them up when you need to. For example, instead of
Code:
   switch(numeropallete)
   {
      case 0: pallete=PALLETE00;break;
      case 1: pallete=PALLETE01;break;
      case 2: pallete=PALLETE02;break;
      case 3: pallete=PALLETE03;break;
      case 4: pallete=PALLETE04;break;
      case 5: pallete=PALLETE05;break;
      case 6: pallete=PALLETE06;break;
      case 7: pallete=PALLETE07;break;
      case 8: pallete=PALLETE08;break;
      case 9: pallete=PALLETE09;break;
      case 10: pallete=PALLETE10;break;
      case 11: pallete=PALLETE11;break;
      case 12: pallete=PALLETE12;break;
      case 13: pallete=PALLETE13;break;
      case 14: pallete=PALLETE14;break;
      case 15: pallete=PALLETE15;break;
   }


you have
Code:

int pal_array[16]= { PALLETE00, ... };

pallete= pal_array[numeropallete];

Which is shorter, faster, and more maintainable. Do the same with the letter mapping. Please. For your own sanity, please!

I'm working on a text-system page for tonc now, and I think I'm doing what you're trying to do here (it's really hard to tell how my function is functionally different, because of the avalanche of code you have). Only my function isn't 330 lines long, it's only 10.

Oh, also, it's palette. One 'l', two 't's.

#64054 - ghost Leinad - Sun Dec 18, 2005 11:34 pm

yes I know is palette :P in fact I discover that on your TONC tutorial :D:D:D but not when I did that function as you can see.

I will try the LUT, that's for sure.

Also I will like to ask you, May if you lend me some codes and some Images from your TONC???

I'm making a spanish tutorial for the GBA development and I found some of your explanations very useful :D please! Of course, I will give you credit.

You can find my tutorial here

www.gbadevmx.wikispaces.com
_________________
All human wisdom is summed up in these two words, - 'Wait and hope"
****************************************
My site www.myth-world.net and www.bmrpg.com :)

#64079 - thegamefreak0134 - Mon Dec 19, 2005 6:01 am

Wow, I'm getting practice for Spanish III just trying to decipher your code...

Well, honestly I can't say where the code seems to be messed up. Did you add anything yourself? (you said you borrowed an engine) Like, did you add some symbols to the map, or add some characters to the code?

The reason I say this is if you did, and the memory locations stuff is being put is close together, you may be having some overflow of one thing into another, which would rightly explain yur wierd tiles. However, if you didnt, I'm totally baffled.

If you did add stuff, can you go back and add comments to the previous code post to show us where?

Also, what Mode are you currently using for graphics?
_________________
What if the hokey-pokey really is what it's all about?

[url=http:/www.darknovagames.com/index.php?action=recruit&clanid=1]Support Zeta on DarkNova![/url]

#64085 - gauauu - Mon Dec 19, 2005 8:17 am

Crazy thought: I don't know how C officially handles these things, but one thing to check might be the text encoding of your source file.

Working in China, we ran into a problem once where somebody's text editor was set up to use some slightly-different-than-normal text encoding. It was mostly normal except for a few weird characters here and there, which really introduced some hard-to-pin-down bugs in our programs.

Using a hex editor, we could find the culprit...it might be worth adding the weird characters, opening your source file in a hex editor, and make sure they are producing the ascii values you think they should be.

Of course, there's a very real chance I'm talking nonsense.

#64125 - Cearn - Mon Dec 19, 2005 6:43 pm

ghost Leinad wrote:
I will try the LUT, that's for sure.

Please do. and watch the code shrink down in size. As a general rule, if you're case&pasting, there's often the oppurtunity to use tables or arithmetic instead of pages of case statements.

ghost Leinad wrote:
Also I will like to ask you, May if you lend me some codes and some Images from your TONC???
I think something got lost in editing in terms of sentence structure, but I reckon the answer would be along the line of "feel free".

thegamefreak0134 wrote:
Also, what Mode are you currently using for graphics?
Tiles + palette swapping = regular backgrounds.

gauauu wrote:
Crazy thought: I don't know how C officially handles these things, but one thing to check might be the text encoding of your source file.

Using a hex editor, we could find the culprit...it might be worth adding the weird characters, opening your source file in a hex editor, and make sure they are producing the ascii values you think they should be.

Of course, there's a very real chance I'm talking nonsense.

As I'm always a little weary of characters not in the 32-128 range, especially since the special characters in the code appear as Japanese in both IE and Firefox, I'd have to agree here: check the character mapping.

#64129 - DekuTree64 - Mon Dec 19, 2005 7:14 pm

Also, use
Code:
default:
    ASSERT(0);

in your switch statements, rather than continuing as if nothing was wrong, and possibly using an uninitialized variable. That will let you catch problems like bad text encoding right away.

The most basic ASSERT macro would be
Code:
#define ASSERT(condition) \
    if(!(condition)) \
    { \
        while(1) {} \
    }

but preferrably you would want to print some info to VBA's debug output too, like what line of what file the assert was on. You can use the automatic __FILE__ and __LINE__ macros for that.

Or if you don't feel like setting up a nice printing system, just write the filename and line number to some specific address in memory, and use VBA's memory viewer to read them :)
_________________
___________
The best optimization is to do nothing at all.
Therefore a fully optimized program doesn't exist.
-Deku

#64140 - Quirky - Mon Dec 19, 2005 8:25 pm

How does gcc handle the spanish 'enye' and tilde-accented letters? Those don't fit in 7 bit ASCII and you may find that your switch statements and signed char indices are messing up. A signed char of 0x80 could turn into -1 when cast (or 0xffffffff in hex/debugger speak). I'd check that after you sort out your tables - it may just require an &0xff to properly conver to unsigned int. These non-ascii issues are tricky.

#64164 - ghost Leinad - Mon Dec 19, 2005 10:54 pm

I already used the LUTs :D:D:D, my code is now 1/3 long :O:O:O


I let you know how my code look like later today...

With the using of LUTs now I can handle the ? ? , letters with accents ????? and the symbols ?? without problem.

I found that is not a symbol problem in fact I don't know what can be :S

look if you declare this variable:
Code:
const char text01="Hello_"

everything is OK

but if you change the same variable as

Code:
const char text01="Hello _"


I just add ONE space at the end of the string! My text is then messed up.

This not happens always, its just when I use long string, like 30 letters or so.

I will add the pics for the tiles and maps later, I have to leave now :D
_________________
All human wisdom is summed up in these two words, - 'Wait and hope"
****************************************
My site www.myth-world.net and www.bmrpg.com :)

#64186 - ghost Leinad - Tue Dec 20, 2005 2:00 am

ok, now my text function looks like this

Code:

LUTs

int paletaausar[]={PALLETE00, PALLETE01, PALLETE02, PALLETE03, PALLETE04, PALLETE05, PALLETE06,
         PALLETE07, PALLETE08, PALLETE09, PALLETE10, PALLETE11, PALLETE12, PALLETE13,
         PALLETE14, PALLETE15};

      //0   1   2   3   4   5   6   7   8   9   10  11  12  13  14  15  16  17  18  19
int letraausar[]={0  ,0  ,0  ,0  ,0  ,0  ,0  ,0  ,0  ,0  ,0  ,0  ,0  ,0  ,0  ,0  ,0  ,0  ,0  ,0  ,  //20
        0  ,0  ,0  ,0  ,0  ,0  ,0  ,0  ,0  ,0  ,0  ,0  ,97 ,162,0  ,166,167,168,169,170,  //40
        171,172,173,174,175,176,177,178,152,153,154,155,156,157,158,159,160,161,179,180,  //60
        181,183,182,184,97 ,98 ,99 ,100,101,102,103,104,105,106,107,108,109,110,111,113,  //80
        114,115,116,117,118,119,120,121,122,123,124,0  ,0  ,0  ,0  ,0  ,195,125,126,127,  //100
        128,129,130,131,132,133,134,135,136,137,138,140,141,142,143,144,145,146,147,148,  //120
        149,150,151,0  ,0  ,0  ,0  ,0  ,0  ,0  ,0  ,0  ,0  ,0  ,0  ,0  ,0  ,0  ,0  ,0  ,  //140
        0  ,0  ,0  ,0  ,0  ,0  ,0  ,0  ,0  ,0  ,0  ,0  ,0  ,0  ,0  ,0  ,0  ,0  ,0  ,0  ,  //160
        0  ,163,0  ,0  ,0  ,0  ,0  ,0  ,0  ,0  ,0  ,0  ,0  ,0  ,0  ,0  ,0  ,0  ,0  ,0  ,  //180
        0  ,0  ,0  ,0  ,0  ,0  ,0  ,0  ,0  ,0  ,0  ,185,0  ,0  ,0  ,0  ,0  ,0  ,0  ,0  ,  //200
        0  ,0  ,0  ,0  ,0  ,0  ,0  ,0  ,0  ,112,0  ,0  ,0  ,0  ,0  ,0  ,0  ,0  ,0  ,0  ,  //220
        0  ,0  ,0  ,0  ,0  ,195,0  ,0  ,0  ,0  ,0  ,0  ,0  ,196,0  ,0  ,0  ,197,0  ,0  ,  //240
        0  ,139,0  ,198,0  ,0  ,0  ,0  ,0  ,0  ,199,0  ,0  ,0  ,0  ,0  ,0  ,0  ,0  ,0  ,}; //260



Code:


void textomargen(const char *a, int postextox, int postextoy, int numeropallete)
{

   int j=0;
   int k=0;
   int m=0;
   int filas=4;
   int longitud=0;
   int cuentaletras=0;
   int c=0;
   int flagletrasdespacio=0;
   int pallete=0x0000;
   
   j=0;
   k=0;
   m=0;
   filas=4;
   longitud=0;
   cuentaletras=0;
   c=0;
   flagletrasdespacio=0;
   pallete=0x0000;

   iniciaTypewriter();

   pallete=paletaausar[numeropallete];
      
   for(m=1;m<5;m++)
   {

      for(i=2;i<28;i++)
      {
         vramMap1[i+(m*32)]=97 | pallete;
      }
   }

   vramMap1[1]=186 | pallete;
   vramMap1[28]=190 | pallete;
   vramMap1[1+(5*32)]=188 | pallete;
   vramMap1[28+(5*32)]=192 | pallete;
   for(i=2;i<28;i++)
   {
      vramMap1[i]=189 | pallete;
      vramMap1[i+(5*32)]=193 | pallete;
   }
   for(i=1;i<5;i++)
   {
      vramMap1[1+(i*32)]=187 | pallete;
      vramMap1[28+(i*32)]=191 | pallete;
   }

while(a[j]!='_')
{
   textback[j]=letraausar[a[j]];
   j++;
   longitud++;
}   

REG_BG0HOFS=256-postextox;
REG_BG0VOFS=256-postextoy;

flagsinglepress=1;

      for(k=1;k<=filas;k++)
      {
         for(i=2;i<28;i++)
         {
            if(flagletrasdespacio==0)
            {
               while(m<2)
               {
                  if(keyDown(KEY_A))
                  {
                     flagsinglepress++;
                     if(flagsinglepress<2)
                     {
                        flagletrasdespacio=1;
                     }
                  
                  }
                  else
                  {
                     flagsinglepress=0;
                     flagletrasdespacio=0;
                  }
                  if(textback[cuentaletras]==0 || textback[cuentaletras]==97)
                  {
                     m=3;
                  }

                  m++;
                  c++;
               }
            }
         
            if(cuentaletras<longitud)
            {
               switch(numeropallete)
               {
                  case 0: vramMap1[i+(k*32)]=textback[cuentaletras] | PALLETE00;
                     cuentaletras++;
                     if(textback[cuentaletras]!=0 && textback[cuentaletras]!=97)
                     {
                        Sonido_TypeWriter();
                     };break;
                  case 1: vramMap1[i+(k*32)]=textback[cuentaletras] | PALLETE01;
                     cuentaletras++;
                     if(textback[cuentaletras]!=0 && textback[cuentaletras]!=97)
                     {
                        Sonido_TypeWriter();
                     };break;
                  case 2: vramMap1[i+(k*32)]=textback[cuentaletras] | PALLETE02;
                     cuentaletras++;
                     if(textback[cuentaletras]!=0 && textback[cuentaletras]!=97)
                     {
                        Sonido_TypeWriter();
                     };break;
                  case 3: vramMap1[i+(k*32)]=textback[cuentaletras] | PALLETE03;
                     cuentaletras++;
                     if(textback[cuentaletras]!=0 && textback[cuentaletras]!=97)
                     {
                        Sonido_TypeWriter();
                     };break;
                  case 4: vramMap1[i+(k*32)]=textback[cuentaletras] | PALLETE04;
                     cuentaletras++;
                     if(textback[cuentaletras]!=0 && textback[cuentaletras]!=97)
                     {
                        Sonido_TypeWriter();
                     };break;
                  case 5: vramMap1[i+(k*32)]=textback[cuentaletras] | PALLETE05;
                     cuentaletras++;
                     if(textback[cuentaletras]!=0 && textback[cuentaletras]!=97)
                     {
                        Sonido_TypeWriter();
                     };break;
                  case 6: vramMap1[i+(k*32)]=textback[cuentaletras] | PALLETE06;
                     cuentaletras++;
                     if(textback[cuentaletras]!=0 && textback[cuentaletras]!=97)
                     {
                        Sonido_TypeWriter();
                     };break;
                  case 7: vramMap1[i+(k*32)]=textback[cuentaletras] | PALLETE07;
                     cuentaletras++;
                     if(textback[cuentaletras]!=0 && textback[cuentaletras]!=97)
                     {
                        Sonido_TypeWriter();
                     };break;
                  case 8: vramMap1[i+(k*32)]=textback[cuentaletras] | PALLETE08;
                     cuentaletras++;
                     if(textback[cuentaletras]!=0 && textback[cuentaletras]!=97)
                     {
                     Sonido_TypeWriter();
                     };break;
                  case 9: vramMap1[i+(k*32)]=textback[cuentaletras] | PALLETE09;
                     cuentaletras++;
                     if(textback[cuentaletras]!=0 && textback[cuentaletras]!=97)
                     {
                        Sonido_TypeWriter();
                     };break;
                  case 10: vramMap1[i+(k*32)]=textback[cuentaletras] | PALLETE10;
                     cuentaletras++;
                     if(textback[cuentaletras]!=0 && textback[cuentaletras]!=97)
                     {
                        Sonido_TypeWriter();
                     };break;
                  case 11: vramMap1[i+(k*32)]=textback[cuentaletras] | PALLETE11;
                     cuentaletras++;
                     if(textback[cuentaletras]!=0 && textback[cuentaletras]!=97)
                     {
                        Sonido_TypeWriter();
                     };break;
                  case 12: vramMap1[i+(k*32)]=textback[cuentaletras] | PALLETE12;
                     cuentaletras++;
                     if(textback[cuentaletras]!=0 && textback[cuentaletras]!=97)
                     {
                        Sonido_TypeWriter();
                     };break;
                  case 13: vramMap1[i+(k*32)]=textback[cuentaletras] | PALLETE13;
                     cuentaletras++;
                     if(textback[cuentaletras]!=0 && textback[cuentaletras]!=97)
                     {
                        Sonido_TypeWriter();
                     };break;
                  case 14: vramMap1[i+(k*32)]=textback[cuentaletras] | PALLETE14;
                     cuentaletras++;
                     if(textback[cuentaletras]!=0 && textback[cuentaletras]!=97)
                     {
                        Sonido_TypeWriter();
                     };break;
                  case 15: vramMap1[i+(k*32)]=textback[cuentaletras] | PALLETE15;
                     cuentaletras++;
                     if(textback[cuentaletras]!=0 && textback[cuentaletras]!=97)
                     {
                        Sonido_TypeWriter();
                     };break;
                  default: vramMap1[i+(k*32)]=textback[cuentaletras] | PALLETE00;
                     cuentaletras++;
                     if(textback[cuentaletras]!=0 && textback[cuentaletras]!=97)
                     {
                        Sonido_TypeWriter();
                     };break;
               }
               m=0;
            }
            c=0;

            if(cuentaletras>=longitud)
            {
               break;
            }

         }
      }

   
}



still long, but is better :D ..same functionality.

well, now...I have declared all this text until now:

Code:


const char *texto9="TORRES DE HANOI!!                                   ACOMODA LA FIGURA!!_";   
const char *texto3="    CUADRADO MAGICO!!_:";
const char *texto4="    CUADRADO MAGICO!!_";
const char *texto5="   CUADRADO MAGICO!!_";
const char *texto18="    CUADRADO MAGICO!!                                                                                                              MENU_";
const char *texto10="    CUADRADO MAGICO!!                                                                                                                                                                                                                                                                                                                                                                                                                                                                             ___";

const char *texto11="      INSTRUCCIONES                                 USA LAS TECLAS DE DIRECCI-ON PARA SELECCIONAR LA PO-SICION EN LA QUE QUIERAS  EL NUMERO.                                          DESPUES PRESIONA  LA TECLA Z.                                                 EL OBJETIVO DEL JUEGO ES  HACER QUE LAS SUMAS DE LASFILAS, LAS COLUMNAS Y LOS DIAGONALES SEAN SIEMPRE 15                          SI PRESIONAS LA TECLA RE- TROCESO EL JUEGO SE REINI-CIARA___";
const char *texto="T A N G R A M A ! !___";
const char *texto1="   T A N G R A M A ! !                                                                                                        MENU                                                                                                                                                                                                                                                                                              PUEDES MOVER LA PIEZA SE- LECCIONADA...         _____";
const char *texto2="   T A N G R A M A ! !                                                                                                        MENU                                                                                                                                                                                                                                                                                              SELECCIONA LA FIGURA A    MOVER...              ____";

const char *texto12="      INSTRUCCIONES                                 USA LAS TECLAS DE DIRECCI-ON IZQUIERDA Y DERECHA PA-RA SELECCIONAR LA PIEZA   QUE QUIERAS MOVER.                                  CUANDO HAYAS DECIDIDO ESTOPRESIONA Z PARA PODER MO- VERLA.                                              LA PIEZA SE MUEVE CON LAS TECLAS DE DIRECCION Y CON LA TECLA X PUEDES ROTARLA PARA ASI PODER CREAR  MAS FIGURAS.                  PRESIONA RETROCESO PARA   REINICIAR EL JUEGO___";
const char *texto6="    TORRES DE HANOI!!                               MENU                MOV=                                                                                                                                                                                                                                                                                                                              SELECCIONA EL DISCO _";
const char *texto7="    TORRES DE HANOI!!                               MENU                MOV=                                                                                                                                                                                                                                                                                                                            SELECCIONA LA POSICION__";
const char *texto8="    TORRES DE HANOI!!_";
const char *texto13="      INSTRUCCIONES                                 USA LAS TECLAS DE DIRECCI-ON IZQUIERDA Y DERECHA PA-RA SELECCIONAR LA PIEZA   QUE QUIERAS MOVER.                                  CUANDO HAYAS DECIDIDO ESTOPRESIONA Z PARA PODER ELE-GIR LA TORRE A LA QUE DES-SEES MOVERLA. EL OBJETIVO DEL JUEGO ES PASAR TODOS  LOS DISCOS DE UNA TORRE A OTRA, CON LA CONDICION DE NO PONER UN DISCO MAS GRA-NDE ENCIMA DE UNO MAS CHI-CO. PRESIONA RETROCESO PA-RA REINICIAR EL JUEGO.__";
const char *texto14="    COLOCA LA FIGURA!!_";
const char *texto15="    COLOCA LA FIGURA!!                                                                                                                                                                TIEMPO                    RESTANTE:                                                                                                                                                   GANASTE!!                                           PRESIONA                  RETROCESO_";
const char *texto16="    COLOCA LA FIGURA!!                                                                                                                                                                TIEMPO                    RESTANTE:                                                                                                                                                   PERDISTE!!                                          PRESIONA                  RETROCESO_";
const char *texto17="    COLOCA LA FIGURA!!                                                                                                                                                                TIEMPO                    RESTANTE:_";
const char *textosdn01="TIEMPO                META                                    SCORE                                                                                                                                                                                                                                                             SUMA ACTUAL_";
const char *textojugar01="HOLA, MI NOMBRE ES JUGAR BIENVENIDO AL SISTEMA DE ENSEムANZA DEL COCITECH, ESPERO QUE TE DIVIERTAS_";
const char *textojugar02="EL CUADRADO MAGICO ELEGIRAS SI TU LOGICA QUIERES MEJORAR. HAZ QUE LOS NUMEROS SUMEN IGUAL_";
const char *textojugar03="SI TE SIENTES CREATIVO, PRUEBA USAR EL TANGRAMA. USA TU IMAGINACION PARA CREAR MILES DE FIGURAS DIFERENTES_";
const char *textojugar04="TORRES DE HANOI_";
const char *textojugar05="ACOMODA LA FIGURA EN SU LUGAR_";
const char *textojugar06="SUMA LOS NUMEROS_";
const char *textojugar07="APAGA LOS BOTONES_";
const char *textojugar08=""QUIERES CONOCER EL OBJETIVO DEL JUEGO?_";
const char *textojugar09="EL OBJETIVO DEL CUADRADO MAGICO ES HACER QUE TODAS LAS SUMAS SEAN IGUALES A 15, SI LO CONSIGUES, GANAS_";
const char *textojugar10="?GANASTE!                                           ?DESEAS JUGAR DE NUEVO?_";
const char *textojugar11="PERDISTE                       ?DESEAS JUGAR DE NUEVO?_";


everything is fine as it :D, the tiles and the text looks like:

[Images not permitted - Click here to view it]

[Images not permitted - Click here to view it]

BUT when I change the last text to:

Code:
const char *textojugar11="PERDISTE                        ?DESEAS JUGAR DE NUEVO?_";


as you can see, I just add ONE space to the text, and now the text looks like this: (I mean ALL the text)

[Images not permitted - Click here to view it]

[Images not permitted - Click here to view it]

I really can tell where's the problem :S
_________________
All human wisdom is summed up in these two words, - 'Wait and hope"
****************************************
My site www.myth-world.net and www.bmrpg.com :)

#64198 - tepples - Tue Dec 20, 2005 4:41 am

It looks like it could be an alignment error on your font data. Font data, or any other data to be copied directly into VRAM, should always be aligned to a 4-byte (32-bit) boundary. What happens when you add four spaces instead of one? If that fixes it, then you need to fix your font data's alignment.

If you store your font in ASCII order, then you can remove a lookup table.
_________________
-- Where is he?
-- Who?
-- You know, the human.
-- I think he moved to Tilwick.

#64238 - Cearn - Tue Dec 20, 2005 2:45 pm

Quote:
Code:
             switch(numeropallete)
               {
                  case 0: vramMap1[i+(k*32)]=textback[cuentaletras] | PALLETE00;
                     cuentaletras++;
                     if(textback[cuentaletras]!=0 && textback[cuentaletras]!=97)
                     {
                        Sonido_TypeWriter();
                     };break;
// etc

Also superfluous, you can use the same lut as before. In fact, as you already did that once, you can just use that variable. Like I said, if you find yourself case&pasting, you're probably missing something.

Re: tepples' data alignment suggestion: if you flick between images, it does look like they're all shifted a bit, plus some extra bogosity thrown in. What is the declaration/definition of the font, and how do you copy it?

#64298 - ghost Leinad - Wed Dec 21, 2005 2:08 am

well, I will compile the code changing the spaces at the last text


with 0 spaces: good
with 1 spaces: bad
with 2 spaces: bad
with 3 spaces: good
with 4 spaces: good
with 5 spaces: bad
with 6 spaces: bad
with 7 spaces: good
with 8 spaces: good
with 9 spaces: bad
with 10 spaces: bad

at this point, I realized that Tepples is right

tepples wrote:
It looks like it could be an alignment error on your font data. Font data, or any other data to be copied directly into VRAM, should always be aligned to a 4-byte (32-bit) boundary.


Cearn wrote:
What is the declaration/definition of the font, and how do you copy it?


I don't know what do you mean by this, but let me show you the C file where's my font

Code:
const unsigned short alfab1Data[3104]=
{
   0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
   0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
   0x9900, 0x0009, 0x0090, 0x0090, 0x0090, 0x0090, 0x0090, 0x0090,
   0x9990, 0x0099, 0x0090, 0x0090, 0x0090, 0x0090, 0x0000, 0x0000,
   0x9990, 0x0009, 0x0090, 0x0090, 0x0090, 0x0090, 0x9990, 0x0009,
   0x0090, 0x0090, 0x0090, 0x0090, 0x9990, 0x0009, 0x0000, 0x0000,
   0x9900, 0x0009, 0x0090, 0x0090, 0x0090, 0x0000, 0x0090, 0x0000,
   0x0090, 0x0000, 0x0090, 0x0090, 0x9900, 0x0009, 0x0000, 0x0000,
....
...
...
}


I will try exporting the font as a 32 bits array, let's see what happen.

PD. I finally learn how to quote :D[/quote]
_________________
All human wisdom is summed up in these two words, - 'Wait and hope"
****************************************
My site www.myth-world.net and www.bmrpg.com :)

#64300 - ghost Leinad - Wed Dec 21, 2005 2:32 am

:O:O:O well, it's seems to work fine now...(for now, I let you know if something goes wrong again)

same test:

with 0 spaces: good
with 1 spaces: good
with 2 spaces: good
with 3 spaces: good
with 4 spaces: good
with 5 spaces: good
with 6 spaces: good
with 7 spaces: good
with 8 spaces: good
with 9 spaces: good
with 10 spaces: good

now, Why the problem??? why it has to be a 32-bit aligned font???

thank you everybody for the help :D:D

my new question is...how do I handle the " symbol?
_________________
All human wisdom is summed up in these two words, - 'Wait and hope"
****************************************
My site www.myth-world.net and www.bmrpg.com :)

#64315 - tepples - Wed Dec 21, 2005 5:54 am

ghost Leinad wrote:
now, Why the problem??? why it has to be a 32-bit aligned font???

The GBA memory bus is 32 bits wide. When you do a 32-bit-wide copy using DMA or BIOS CpuFastSet, the CPU reads a 32-bit chunk from ROM or EWRAM and then writes a 32-bit chunk to VRAM. The wrinkle is that you only get the "expected" results on a 32-bit read if the address is aligned to 32 bits; if the read address is not aligned to a 32-bit boundary, then invalid data is read each time. Even if Intel and official MIPS have hardware to handle unaligned reads "properly", ARM doesn't.
_________________
-- Where is he?
-- Who?
-- You know, the human.
-- I think he moved to Tilwick.

#64329 - keldon - Wed Dec 21, 2005 10:55 am

ghost Leinad wrote:
my new question is...how do I handle the " symbol?

Code:
char *c = "And Dr Jake Said, \"I'm afraid I only have 10 seconds in which I can ...\"";

#64330 - Cearn - Wed Dec 21, 2005 11:01 am

It's not a matter of bus size, it's inherent to ARM (and other RISC) systems. Loads always happen in 32 bit chunks, aligned to 4-byte boundaries; the lower 2 bits in the address are simply ignored. The word is then rotated to match the alignment of the source address, and upper bits are cut off for types other than ints. Stores just happen in the alignment of the type: words always on 4byte boundaries (last 2 bits ignored), halfwords on 2byte boundaries (last bit ignored).

Code:
// Something like this
// T is a variable type, Tmask the bitmask for that type, Talign the bitmask to align addresses to.

// memory loads (unsigned):
u32 word= *(u32*)(address&~3);    // load word
word= ROR( word, (address&3)*8 ); // rotate for alignment
T var= word&Tmask;     // zero out bits for non-word types

// memory stores
T *vardst= (T*)(address&~Talign);
*vardst= (T)var;

So in this case, what would happen is that the strings are put before the font in memory, and depending on how long the strings are, the font will be on merely halfword boundaries, or if you're lucky on word boundaries as well. If it's non-word aligned and you try word copies ( (u32*)cast + array copy, CpuFastSet, DMA32, memcpy) you get screwed. And since the compiler trust you know what you are doing, it just assumes that's what you wanted and is more than willing to oblige.

ghost Leinad wrote:
my new question is...how do I handle the " symbol?

tepples wrote wrote:
"an \"easy\" problem"
:P

#64388 - ghost Leinad - Wed Dec 21, 2005 10:16 pm

Ok, there you have, my ultimate supreme text function :D

Code:

void textomargen(const char *a, int postextox, int postextoy, int numeropallete)
{
   int j=0,k=0,m=0,filas=4,longitud=0,cuentaletras=0,c=0,flagletrasdespacio=0,pallete;
   
   iniciaTypewriter();

   pallete=paletaausar[numeropallete];
      
   marcotexto(pallete);
   REG_BG0HOFS=256-postextox;
   REG_BG0VOFS=256-postextoy;

   while(a[j]!='_')
   {
      textback[j]=letraausar[a[j]];
      j++;
      longitud++;
   }   

   flagsinglepress=1;

   for(k=1;k<=filas;k++)
   {
      for(i=2;i<28;i++)
      {
         if(cuentaletras<longitud)
         {
            vramMap1[i+(k*32)]=textback[cuentaletras] | pallete;
            cuentaletras++;
            if(textback[cuentaletras]!=0 && textback[cuentaletras]!=97)
            {
               Sonido_TypeWriter();
            }
            m=0;
         }
         if(cuentaletras>=longitud)
         {
            break;
         }
      }
   }
}


What do you think of it??? :D
_________________
All human wisdom is summed up in these two words, - 'Wait and hope"
****************************************
My site www.myth-world.net and www.bmrpg.com :)

#64389 - Cearn - Wed Dec 21, 2005 10:27 pm

From 300+ lines to 42...

^_^

And you see that it's actually readable this way? I take it you're going to do something with the unused variables later, huh. A number of variables don't do very much at the moment.

Just out of curiosity, what did you use to copy the font?

#64400 - ghost Leinad - Thu Dec 22, 2005 1:02 am

Cearn wrote:
what did you use to copy the font?


:D:D:D:D

I use the almighty Usenti...thanks Cearn, the tool rocks!!!

Cearn wrote:
A number of variables don't do very much at the moment.


I'll check that :D
_________________
All human wisdom is summed up in these two words, - 'Wait and hope"
****************************************
My site www.myth-world.net and www.bmrpg.com :)

#64449 - Cearn - Thu Dec 22, 2005 1:18 pm

ghost Leinad wrote:
Cearn wrote:
what did you use to copy the font?
:D:D:D:D
I use the almighty Usenti...thanks Cearn, the tool rocks!!!

Well yes, I suppose it does ^_^. But I asked about copying, not exporting. memcpy I presume?

#64482 - ghost Leinad - Thu Dec 22, 2005 8:19 pm

oh, yes, memcpy(); is just plain easy :D

is there a better way???
_________________
All human wisdom is summed up in these two words, - 'Wait and hope"
****************************************
My site www.myth-world.net and www.bmrpg.com :)

#64509 - gauauu - Fri Dec 23, 2005 2:37 am

memcpy() works great.

For my projects, I often set up a couple simple and generic DMA transfer functions, which will work like memcpy. A little bit faster in most cases.

Sure, you don't want to spend too much time optimizing too early, but to write the function once (or copy/paste it from my last project) is easy enough to have a working "faster-than-memcpy" function.

#64538 - Cearn - Fri Dec 23, 2005 10:34 am

memcpy() does work great, it's easy to work with and fairly quick too. Except when the copy-count is too small or when source or destination are not word aligned. In those cases it'll copy by the byte, and we all know what that means for things like VRAM.

There are 'better' ways, yes. I have my own memcpy16 and memcpy32 for these things (basically CpuFastSet with some extras for the head/tail end), which are alignment safe and twice as fast too. But usually things like these can be kept for when you're really optimising.

You could also try to just make sure your data is alignment safe, and there are plenty of ways of doing that.
One method would be to export as u32, which is guaranteed word aligned.
Another would be to add __attribute__(( aligned(4) )) to the definition (or declaration? Maybe both, I dunno), that would ensure alignment.
A third method would be to have separate files for all the data, since files are automatically word aligned. Unless you #include them, of course.
Finally, you could use assembly or a file system like GBFS, which don't need language extensions to get data aligned. It's easier on compilers too, as you don't actually have to compile them.