GP32 Need File-loader-help In C ;\


Joined
Jan 16, 2004
Messages
297
Location
hell
Website
diab0l.pdroms.de
i'm really stuck because my sucking C-knowledge with this atm,
i need a file-loader for my 3d-engine so you can dynamically load an object (the file-format is not really complete yet, but nevermind ^^) and one for my basic-interpreter
using mirko's sdk, i can load the whole file into ram and ouput it, looks like this:

Code:
void load(char *file)
{
..GPFILE *file2; 
..int size;
..char *filebuf;
..file2=smc_fopen(file,"r"); 
..size=smc_filesize(file2); 
..smc_fread(filebuf, size, 1, file2); 
..gp_drawString(10,164,35,filebuf,0xFFFF,fb[0]);
...//outputs the first 35 chars, i know

..while(1);
...//stops the thing here, i know
}

an example-file to load would look like this:
d(1,1,1);
f(3,3,3)(6,6,6)(9,9,9);
f(3,3,3)(6,6,6)(12,12,12);

no comments on the file-format please, i'm working at it and no i won't use any standard-format
so, for a file-loader i'd go like 
1) loading first line into another variable
2) split it up and interpret it
3) next line..

now my problem is that i can't figure how to find the 1. line-end (character 13 as far as i can remember)
neither do i know how to directly put chr13 into a char (in basic it would be a$=chr$(13)) for a comparision

so, anyone could help me improve this and not just moan to read a darn C-tutorial what i have done, trying string.h-functions without success?
would appreciate it :D

Edit: .. instead of spaces -_-
 
the_Diabologic posted on Jul 7 2004 at 12:38 AM said:
neither do i know how to directly put chr13 into a char (in basic it would be a$=chr$(13)) for a comparision
Just cast it to a char.

c=(char)13;
 
Last edited by a moderator:
thanks for that info..
fck, i'm really damn fucked now

i'd be very thankful for a full code that copies a part of the first into the second string.. (like the first string being "this is a test" then copy "is is a te" into another string)

btw, the following code doesnt work for some stupid reason:
char *a;
char b;
a="muh";
b=a[0];

sorry, but this is really frustrating :\
 
the_Diabologic posted on Jul 7 2004 at 01:37 AM said:
How are you testing it to find it does not work?

If you are using gp_drawString() for example you would have to pass it &b and length of 1.

like this:
gp_drawString(110, 10, 1, &b, BLACK, FRAMEBUFFER);
 
Last edited by a moderator:
btw, the following code doesnt work for some stupid reason:
char *a;
char b;
a="muh";
b=a[0];

'a' is pointing to a string in the string constant table, so that could be a problem. Below is a strcpy command I made which copies a specific region of a string. I haven't compiled it, but it should work.

char strmid(char* source, unsigned long slength, unsigned long cstart, unsigned long cend, char* dest)
{
if (cstart >= slength || cend >= slength) return -1; /* error */

for (int x = cstart; x <= cend, x++)
dest[x] = source[x];

return (0);
}
 
Concerning line endings in general: it depends on which system you edit the text.
- a C64 uses 13 ('\r')
- a WinDOS machine uses carriage return / line feed also knows as CRLF ("\r\n")
- a Linux/Unix machine uses just linefeed ('\n')

Could it be, that you can't find an end of line, because you're looking for the wrong thing?

Greetings,
SvOlli
 
char *a;
char b;
a="muh";
b=a[0];

sorry, but this is really frustrating :
You are thinking too much in a Pascal way.
Try the following:
Code:
char *a;
a="muh";
printf("%x\n", *a);
This one should print out:
6d
(the ascii value of "m").

to get the next letter you do
Code:
a++;
printf("%x\n", *a);

Another tip: since these experiments are rather platform independend, run those tests on your host machine first. It'll save you a lot of time.

Greetings,
SvOlli
 
Last edited by a moderator:
ok, i see this leads to nothing;
after some cooling-down with finally getting a kernel-module for 3d-accleration on my linux-box to work (took some hours, but 0wnz y00 a11 XD) i'll do some testing with strings, and if i finally get this tupid @"§!&§!!! to work, i'll implement that into my else very clearly code that's not supposed to be seen by anybody

thanks anyway for the friendly resposes, this forum rules ^-^
 
now *this* really really really extremely super- uber suxxors (i'm pathetic, i know :p)
gp_drawText wont print normal chars, just pointers -_-
that was just the first issue *gotta continue my research that intrests noone expect my-selfish-self*

cheers :D
 
ok, now could anyone test the following code and tell me why that happens what happens?
Code:
#include "gp32.h"

u16 *fb;

char *a;
char *b;
char *c;

void main()
{
  fb=(u16*)FRAMEBUFFER1;
  gp_setCpuspeed(14);

  gp_initFramebuffer(fb,16,65);
  gp_clearFramebuffer16(fb,0x0000);

  a="muh";
  b=a;
  c[0]=a[0];
  c[1]=a[1];
  c[2]=a[2];
  c[3]=a[3];
  while(1)
    {
      gp_drawString(100,108,3,a,0xF800,fb);
      gp_drawString(100,116,3,b,0xF800,fb);
      gp_drawString(100,124,3,c,0xF800,fb);
    }
}
 
the_Diabologic posted on Jul 9 2004 at 02:36 PM said:
ok at now could anyone test the following code and tell me why that happens what happens?
Code:
#include "gp32.h"

u16 *fb;

char *a;
char *b;
char *c;

void main()
{
  fb=(u16*)FRAMEBUFFER1;
  gp_setCpuspeed(14);

  gp_initFramebuffer(fb,16,65);
  gp_clearFramebuffer16(fb,0x0000);

  a="muh";
  b=a;
  c[0]=a[0];
  c[1]=a[1];
  c[2]=a[2];
  c[3]=a[3];
  while(1)
    {
      gp_drawString(100,108,3,a,0xF800,fb);
      gp_drawString(100,116,3,b,0xF800,fb);
      gp_drawString(100,124,3,c,0xF800,fb);
    }
}
Hmm...ok...here's the thing.

a points to muh\0 in the string table
you then assign b to a which just makes them the same. i.e. they both point to the same section of the string table.

You then try to copy the the thing that a is pointing to(muh\0 in the string table) to c.

However, you haven't allocated any memory for c. Which means you are just writing to whatever random section of memory c happens to be point to. This is bad.

However, if you put c=(char*)malloc(4); before the assignment, this example should work I think.
 
Last edited by a moderator:
had a look at mirko's hello world,
Code:
char a[3];
a[3]="muh";
works fine

i really gotta get a good tut about arays and strings in C..
(the one i have sucks at deeper detail)
 
ha!
i found some problem now ' is not the same as ""
'a' means a, "a" means 'a','\0' (nul, not NULL)
found a good tutorial at http://pweb.netcom.com/~tjensen/ptr
recommended :)

btw, the b[0]=a[0]; b[1]=a[1]; - problem is still left open, but i'm not finished reading, muah i love google

Edit: for some stupid reason it *does* solve the problem ^-^
deving goes on, be prepared for file-selector, some more objects and rotation; all fast and real-time
*lucky*
 
Last edited by a moderator:
Back
Top