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.

DS development > Problems including the WIFI-LIB into my project...

#75305 - qw3rty - Sun Mar 12, 2006 1:21 am

I tried the last few days to implement the WiFi Lib into my project.
Everything seems to work all right in my small test app, but as soon as I include it into my main program, I get unexplainable crashs.

I got it almost working in my main program, but it's very unstable.
The most confusing issue is, that a few absolutely unrelated changes in the code can result in instant crash on bootup.
(even if the changed function wasn't called once :O )

Maybe someone has has similar problems and could give me a hint ?

P.S. I have tried every source I could get my hands on - I started with trexec, thought the unstability came from some extra stuff of trexec, started from scratch with the wifi-lib-test-source, and had a look at the recently released source of wifichat...

#75336 - knight0fdragon - Sun Mar 12, 2006 7:00 am

what problems are u having??? I just used the stripped down version available on the forums and had no problems with it
_________________
http://www.myspace.com/knight0fdragonds

MK DS FC: Dragon 330772 075464
AC WW FC: Anthony SamsClub 1933-3433-9458
MPFH: Dragon 0215 4231 1206

#75346 - qw3rty - Sun Mar 12, 2006 9:52 am

If I had found a stripped down version I would have used it ;)
Could you give me a hint were to find it ?

EDIT :
Never mind, I found it... I have a look on the source... I really hope, this time it'll work ;)

#75397 - qw3rty - Sun Mar 12, 2006 6:22 pm

ARGH !
I can't get it to work AGAIN !!!

I will give you an example, of the unexplainable errors :

changing following line in the code :

sprintf(printbuf,"Status: %s", assocstatus_strings[Wifi_AssocStatus()]);

into

sprintf(printbuf,"Status: %14s", assocstatus_strings[Wifi_AssocStatus()]);

results in instant crash on the NDS, even BEFORE that line gets called.
There are no compiler errors, (besides the "useless storage class" error, I get in socket.h (I suppose that's normal, because wifichat compiled and worked fine)

Is there something to avoid when using the wifi-lib ?

#75453 - knight0fdragon - Mon Mar 13, 2006 1:27 am

email me ur code so that i may check it out dragondolez@yahoo.com
_________________
http://www.myspace.com/knight0fdragonds

MK DS FC: Dragon 330772 075464
AC WW FC: Anthony SamsClub 1933-3433-9458
MPFH: Dragon 0215 4231 1206

#75498 - qw3rty - Mon Mar 13, 2006 3:31 pm

I quickly put together parts of my code, and it's working.
But when I include the rest of my code, it still crashes.

You can download the source here :
http://qwerty.servebeer.com/dspaint.rar
Maybe someone can identify a problem in my spaghetti-code ;)

It's a little paint program, with a PC-Server, that saves the pictures.

Usage :

L / R : switch between tools / draw - screen
X/Y : UNDO / REDO
START : Connect to AP
SELECT : Transfer the current image to the PC. (you can abort the transfer with "B", if you forgot to connect FIRST)

The PC-Adresse can't be changed in the program, but in the source ("paint.h, search for "transfer(IP_ADRESS(192,168,0,2),......")

The touch recognition isn't too good right now, because I disabled my additional touchscreen-code - it could be a source of problems (it's adding entries into IPC.h, not sure if that's OK to do).

P.S. : I won't take responsibility, if your PC crashes, your router explodes, your NDS bricks or your house burns down - this is an early part of my game (the game won't include a paint program, but a communication a-la Pictochat)

P.P.S. : There's a bug in the Fill-routine, that makes it crash with too complex graphics (lots of edges etc.) - maybe it's a stack overflow (the routine is recursive)...

#75500 - knight0fdragon - Mon Mar 13, 2006 4:11 pm

what problem are u getting?????? it works fine for me, the only thing is be sure to declare lcdMainOnBottom(), because with my version of libnds, it reverses the screens for some reason
_________________
http://www.myspace.com/knight0fdragonds

MK DS FC: Dragon 330772 075464
AC WW FC: Anthony SamsClub 1933-3433-9458
MPFH: Dragon 0215 4231 1206

#75519 - qw3rty - Mon Mar 13, 2006 7:01 pm

As I said, this is only a little part of my program - as soon I try to integrate the whole source, it crashes.

I can send you the whole source, but it's huge aprox. - 600KB code.
And it's not easily readable - I was "learning while doing" :)
(I started this project with only a little basic and pascal practice ;)

#75525 - bafio - Mon Mar 13, 2006 8:28 pm

qw3rty wrote:
As I said, this is only a little part of my program - as soon I try to integrate the whole source, it crashes.

I can send you the whole source, but it's huge aprox. - 600KB code.
And it's not easily readable - I was "learning while doing" :)
(I started this project with only a little basic and pascal practice ;)


Hi, for what I can tell you are using stonebone's modifications to the wifi lib, taken from my DSChat (the readme2.txt is the same I wrote) but you are not properly setting up IPC, that is done differently from Sgstair's version.
If you look at the thread on the forum or at the source code of DSChat, you will see the ARM7 init is different, and ARM9 (wifiMain method) too.

Also, I am running into the same problem when doing fill, it seems that you get a stack overflow. If you find a method that works, I'll be happy to know and implement it in dsChat. And, I'm happy if you find any of the code of dschat useful, but if so I'd appriciate being cited when you release :)

Cheers

Bafio

#75533 - qw3rty - Mon Mar 13, 2006 11:02 pm

Hi Bafio :)

Yes, I use the modified LIB, it was the only one I found on the net.
When I release it (I hope, I get it done this time - this game was already started on the GBA ;) ) I try to mention everyone who helped me :)

Now to the fill-routine :

My routine initializes 10 variables, it is called with 5 parameters (if I don't include the text-bg struct my funtion uses) plus an array with 256 bytes.(one byte per pixel of a line)

thats 256+30 bytes.

If you don't use text-backgrounds the variables could be reduced even further.

Have a look at my fill-routine (found in /arm9/include/paint/fill.h) - the weird shifts and &'s were my try to optimize the speed....afterwards I noticed, that the compiler does it anyways....resulting in absolutely unreadable code.

It seems, that I can't produce too complex situations anymore, BUT i have only running the paint procedure (plus the wifi code) - I don't know if that is much of a help in such a situation...

#75537 - bafio - Mon Mar 13, 2006 11:43 pm

qw3rty wrote:
Hi Bafio :)

Yes, I use the modified LIB, it was the only one I found on the net.
When I release it (I hope, I get it done this time - this game was already started on the GBA ;) ) I try to mention everyone who helped me :)

Now to the fill-routine :

My routine initializes 10 variables, it is called with 5 parameters (if I don't include the text-bg struct my funtion uses) plus an array with 256 bytes.(one byte per pixel of a line)

thats 256+30 bytes.

If you don't use text-backgrounds the variables could be reduced even further.

Have a look at my fill-routine (found in /arm9/include/paint/fill.h) - the weird shifts and &'s were my try to optimize the speed....afterwards I noticed, that the compiler does it anyways....resulting in absolutely unreadable code.

It seems, that I can't produce too complex situations anymore, BUT i have only running the paint procedure (plus the wifi code) - I don't know if that is much of a help in such a situation...


Hi, thanks, I'll take a look at you routine, actually I have a really simple one (10 lines of code) since I work in balck and white, it's included in the source code, but that works only for small areas (it's recursive).

Didi you try to replace the inti of wifi in both arm 7 and 9 code? I really think your proble may be there, since the inti phase is different, and anyway it's better to do the proper initialization for IPC...

Cheers
bafio

#75541 - qw3rty - Tue Mar 14, 2006 1:06 am

I was too quick - my routine still crashes with areas too complicated (I doubt you could produce an CLOSED area, thats comlicated enough, but if you draw mindless lines on the screen and fill try to fill it, it will crash eventually.

irqSet(IRQ_IPC_SYNC, Wifi_Update);
irqEnable(IRQ_IPC_SYNC);
REG_IPC_SYNC = IPC_SYNC_IRQ_ENABLE;

And yes, I included the code above into arm7-wifi-init and arm9 init. Is this all I had to do ? It seems to work much better - now I can transfer many images (before the DS didn't receive any messages after a few images - ok, my transfer routine may be not the best (it's my first bit of network code....)
but there is one strange thing - I have to connect two times, or the PC won't receive my packets...hmmm...

P.S. : 10 lines of code ?! I nearly grew gray hairs on my fill- routine (one complete day :)
But it was rewarding anyways, I did it without taking someone else's code or ideas :)

P.P.S. : I just noticed : when the NDS stopped receiving messages(yes, it still stops working after a certain amount of time), after reconnecting to the AP it worked again...

#75549 - bafio - Tue Mar 14, 2006 2:19 am

qw3rty wrote:
I was too quick - my routine still crashes with areas too complicated (I doubt you could produce an CLOSED area, thats comlicated enough, but if you draw mindless lines on the screen and fill try to fill it, it will crash eventually.

irqSet(IRQ_IPC_SYNC, Wifi_Update);
irqEnable(IRQ_IPC_SYNC);
REG_IPC_SYNC = IPC_SYNC_IRQ_ENABLE;

And yes, I included the code above into arm7-wifi-init and arm9 init. Is this all I had to do ? It seems to work much better - now I can transfer many images (before the DS didn't receive any messages after a few images - ok, my transfer routine may be not the best (it's my first bit of network code....)
but there is one strange thing - I have to connect two times, or the PC won't receive my packets...hmmm...

P.S. : 10 lines of code ?! I nearly grew gray hairs on my fill- routine (one complete day :)
But it was rewarding anyways, I did it without taking someone else's code or ideas :)

P.P.S. : I just noticed : when the NDS stopped receiving messages(yes, it still stops working after a certain amount of time), after reconnecting to the AP it worked again...


Hi again, the reply I was writing to you went lost :(

but well, what is your program exactly about, I'm curious :) ?
As for you problem look carefully in the init of arm9 in wifi.c:
there is also this part (the arp timer)
Code:

extern void sgIP_ARP_Timer100ms();
extern void Wifi_Update();

...

TIMER3_CR = 0;
irqSet(IRQ_TIMER3, sgIP_ARP_Timer100ms);
irqEnable(IRQ_TIMER3);
TIMER3_DATA = (u16)-13106;
TIMER3_CR = TIMER_IRQ_REQ | TIMER_DIV_256;

maybe that's what is missing,

Cheers

Bafio

#75570 - tepples - Tue Mar 14, 2006 3:49 am

Does your fill routine use run-length filling (seek to the left, then seek to the right, then fill a horizontal line, then look above and below that line), or does it make a separate function call for every single pixel?
_________________
-- Where is he?
-- Who?
-- You know, the human.
-- I think he moved to Tilwick.

#75583 - qw3rty - Tue Mar 14, 2006 10:47 am

My funtions gets as parameter the "last filled-line's length" (last_left_x to last_right_x ; last_left_x = last_right_x = clicked x-pos for the first call), then it checks the line above (or below, depending on the direction) from left_x to right_x, filling every pixel with the original color (if the line below was completely filled from left_x to right_x without gap, it's ok to fill every pixel with the original clor above that line too.)
Then it checks further left / right.

if the current_left_x or the current_right_x border differ for more than one pixel, I have to check the line below (or above - the opposite scanning direction) from current_left_x to last_left_x - hence I call the same funtion with these parameters current_left x, last_left_x and current_line (+-1).

If I find at least one gap in the current_line, I call my fill function again, for every gap.

To make it short - I suppose I use "run-length" filling. :)
P.S. : As you see, it's not as worse as calling my funtion for every pixel, but it gets called for each and every "unsteadiness" / "discontinuity".

@Bafio : It's name is "Blubb", it's a clone of a relatively unknown game I loved on the dreamcast.
It's basically battle-ships mixed with minesweeper...But it's not as boring as battleships ;)

As soon as I get the WiFi-Lib integrated and the first online-alpha, I'll put it on the net(I'll need testers then anyways).
I hope this will be in about two weeks (I have to learn for exams this week - ARGH :)

EDIT :

SUCCESS !! It seems, that I have succesfully integrated the WiFi-Lib into my project....At least the WiFi-Init stage and also the Connection phase are working now.
It was a pretty dumb bug :
I found a global variable "u8 end;", but I initialized "end" again as u16 in functions....it compiled fine, but with "u8 end" declared as global variable, the Arm7 never finished initializing, or eventually it resulted in an instant crash.
I'm baffled, that the "u8 end", that never got called before the crash, seemed to have caused it :-/

P.S. : I updated the RAR on my website.
The litte Paint program should now be quite stable...The interface could be better...it could come handy for someone who needs 16color graphics for NDS....I'm going to use it to create graphics for my game - i hope it won't look too bad ;)

P.P.S. : There seems to be some instability in the connection - sometimes the NDS stops receiveing messages - but after a reconnect to the AP, it's working again...any hints ? (keep-alive packets every now and then ?!)