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 > devkitpro example with dualis

#157413 - gauauu - Fri May 23, 2008 10:07 pm

So I'm finally diving into the world of DS dev, instead of just GBA. I'm playing with the devkitPro examples, but when I try to run the Sprite_Bitmap example in the dualis emulator, I get a message:
Quote:
r15 unaligned
and dualis crashes.

Is this a problem with the emulator, or with the example? And as a follow-up:
If it's the example, what causes this issue?
If it's the dualis emulator: is there a better emulator that is recommended?

Thanks!

#157421 - silent_code - Sat May 24, 2008 1:43 am

i'm not saying it's better or not, but i *also* use no$gba a lot! i'm pressing f3 a lot, while doing so. ;^)
_________________
July 5th 08: "Volumetric Shadow Demo" 1.6.0 (final) source released
June 5th 08: "Zombie NDS" WIP released!
It's all on my page, just click WWW below.

#157433 - gauauu - Sat May 24, 2008 10:27 am

Thanks. I don't have a windows machine handy right now, but I tried this example on DeSMumE for linux, and it worked fine. Still not sure what dualis hated so much from that example, but oh well.

Side note: I almost posted a long post asking for help getting devkitARM working on linux, until I realized that for some odd reason, gnome had stopped extracting the zipped files halfway through, so I only had half the devkit installed ;-)

#157436 - M3d10n - Sat May 24, 2008 1:32 pm

Linux? You could try iDeaS: http://www.ideasemu.org/index.php?act=downloads

iDeaS and No$GBA are the only emulators that can run the 3D project I'm working on properly.

#157437 - gauauu - Sat May 24, 2008 1:42 pm

Good to know...I saw that both existing, but nowhere I read had any recommendations about which was better....Thanks!

#157443 - silent_code - Sat May 24, 2008 5:03 pm

you really have to give it a try and look for yourself.
i find dualis handy because of it's viewers, but i mostly rely on the accuracy of no$gba (and of course the hw for any major changes or additions to the code.)

just in case you wonder aboout it: i have also seen people fooling around with what i think is big n's emulator, but i woundn't recommend bothering with it: as far as i can tell from what i have seen and read about it, that emu does nothing more than no$gba, which does a pretty good job for *free* and after all, using tools illegally sucks big time! don't bother with it. ;^)
_________________
July 5th 08: "Volumetric Shadow Demo" 1.6.0 (final) source released
June 5th 08: "Zombie NDS" WIP released!
It's all on my page, just click WWW below.

#157448 - gauauu - Sat May 24, 2008 5:49 pm

Yeah, I have no desire to use illegal tools...gotta stay on the up-and-up ;-)

Unfortunately, I can't do much testing on actual hardware...I don't have a DS, and don't have the budget for one at the moment. So it's code for emulators, then recruit volunteers for hardware testing. And I'll probably end up doing most of it in linux...trying to switch away from windows at the moment. (I've always preferred open source stuff, and after years and years, I think linux might finally hit my standard of "good enough" for desktop use)

#157451 - tepples - Sat May 24, 2008 10:37 pm

gauauu wrote:
Unfortunately, I can't do much testing on actual hardware...I don't have a DS, and don't have the budget for one at the moment.

While I was in your situation, I developed for Allegro and the GBA.
_________________
-- Where is he?
-- Who?
-- You know, the human.
-- I think he moved to Tilwick.

#157455 - gauauu - Sat May 24, 2008 11:00 pm

tepples wrote:
While I was in your situation, I developed for Allegro and the GBA.


Yeah, that's what I have been doing. But I've had a number of requests to port Anguna to the DS. So I'm giving it a whirl....

#157456 - Lazy1 - Sat May 24, 2008 11:41 pm

Has the no$gba guy re-appeared or what?
I need to know if I have to re-buy it or if he can give me another key.

Moral of the story:
You will always forget something when it's time to backup your files.
Make sure it's not an activation key.

#157636 - gauauu - Tue May 27, 2008 3:17 pm

M3d10n wrote:
Linux? You could try iDeaS: http://www.ideasemu.org/index.php?act=downloads

iDeaS and No$GBA are the only emulators that can run the 3D project I'm working on properly.


Interestingly enough, I couldn't get iDeaS for linux to display anything that wasn't 3d at all...just blank screens. BUT, using iDeaS for windows under wine on linux worked just fine ;-)

#157643 - sverx - Tue May 27, 2008 5:04 pm

silent_code wrote:
i'm not saying it's better or not, but i *also* use no$gba a lot! i'm pressing f3 a lot, while doing so. ;^)


Sorry for the OT: I've seen with no$gba that window (pressing F3) that tells me, for instance:
Quote:
Errors per second -- 0
Total Errors -- 0

what does they mean? Because sometimes it happens that some 'errors' got counted when I'm running my programs but I can't find mistakes in my code and everything goes on regularily... so I really don't know if I should care about it at all or if I should take it seriously...

#157645 - kusma - Tue May 27, 2008 5:17 pm

sverx wrote:
what does they mean? Because sometimes it happens that some 'errors' got counted when I'm running my programs but I can't find mistakes in my code and everything goes on regularily... so I really don't know if I should care about it at all or if I should take it seriously...

They can be anything from unaligned reads to reads of undefined memory. In general they are worth looking into, but in some special cases they are just annoying (like byte-writes to VRAM on the gba -- it can be used for good things) ;)

#157648 - sverx - Tue May 27, 2008 5:32 pm

kusma wrote:
They can be anything from unaligned reads to reads of undefined memory.


an unaligned read is a mistake? :shock:

#157653 - silent_code - Tue May 27, 2008 5:50 pm

i just want to add, that most of the time, if not every time, my own roms will have one error at the very beginning of the code. so, even if i stop execution in the first line of main(), i get the error. until now, i couldn't identify it.

but, if you get massive amounts of errors on a per frame base, you should seriously ( ;^D ) check your code, though.

well, in fact, even commercial roms are reported to yield enormous amounts of errors in no$gba, but that might just be related to what kusma posted. :^)
_________________
July 5th 08: "Volumetric Shadow Demo" 1.6.0 (final) source released
June 5th 08: "Zombie NDS" WIP released!
It's all on my page, just click WWW below.

#157656 - sverx - Tue May 27, 2008 6:03 pm

silent_code wrote:
i just want to add, that most of the time, if not every time, my own roms will have one error at the very beginning of the code. so, even if i stop execution in the first line of main(), i get the error. until now, i couldn't identify it.


fortunatly, that still never happened me ;)

silent_code wrote:
but, if you get massive amounts of errors on a per frame base, you should seriously ( ;^D ) check your code, though.


I agree, but anyway it's 'funny' that with the MODplayer I'm writing I get ZERO errors when playing some tunes and a lot of errors when playing some others... but they play just fine! (here and example, after some 30 seconds...)
Quote:
Errors per second -- 1,557
Total Errors -- 77,872

#157659 - kusma - Tue May 27, 2008 6:13 pm

sverx wrote:
an unaligned read is a mistake? :shock:

It sure is. The ARM CPUs doesn't support it; the result from such an operation is undefined.

#157661 - sverx - Tue May 27, 2008 6:20 pm

kusma wrote:
sverx wrote:
an unaligned read is a mistake? :shock:

It sure is. The ARM CPUs doesn't support it; the result from such an operation is undefined.


mmm... but is it possibile (I mean with the GCC compiler 'shipped' with devKitPro) to produce code with unaligned reads? Or should I give up using u8 & s8 types? Sorry, I need an explanation, this can make a mess in my mind...

#157663 - silent_code - Tue May 27, 2008 6:33 pm

you can still use u8's and u16's, the compiler will just pad and align them for you as needed (so, effectively you might loose some bytes for each unpacked structure.)

i hope that's not bogus i just wrote. ;^)

EDIT: corrected it a bit and made it more general.
_________________
July 5th 08: "Volumetric Shadow Demo" 1.6.0 (final) source released
June 5th 08: "Zombie NDS" WIP released!
It's all on my page, just click WWW below.


Last edited by silent_code on Tue May 27, 2008 6:50 pm; edited 1 time in total

#157664 - Maxxie - Tue May 27, 2008 6:38 pm

Byte reads can not be unaligned.

If you however read hwords or words from unaligned addresses (2/4 byte aligned) then you will observe problems.

Let's say you have at address 0 the 6 bytes 0,1,2,3,4,5 are stored.
A word read from address 2, could result 0x03020100 if the lower address bits are ignored, 0x01000203 if the 2nd lower bit selects the halfword to be filled in first or 0x05040302 if the read was executed as you intended it.
(Under little endian)

Since this might depend on the buswidth the memory is connected with, the behavious is defined as undefined.

Bit 0 set in address on 32/16 bit reads are completely ignored on the DS afaik.

#157702 - Cydrak - Tue May 27, 2008 10:03 pm

kusma wrote:
sverx wrote:

an unaligned read is a mistake? :shock:

It sure is. The ARM CPUs doesn't support it; the result from such an operation is undefined.

Actually it's more fun than that. It is defined; the ARM Arch Ref Manual (would that be "ARM ARM?" :b *groan*) says, in many scattered footnotes:
- LD/STRH, LD/STRD, LD/STR (THUMB): "Unpredictable".
- LD/STM, STR (ARM), SWP (write): Address masked; low bits ignored.
- LDR (ARM), SWP (read): Address masked; data ROR'd by 8 * low bits (even written out in the pseudocode!).

This makes the LDR (mildly) useful in loops. The data will already be shifted, needing just a couple bitmasks and an OR on the results. I used that in a blitter somewhere, so presumably the DS follows the standard. Heh, I suppose that's more than anyone cared to know... >_>

#157729 - sverx - Wed May 28, 2008 9:26 am

Thank you all, it's really interesting :)

BTW I guess it's impossible -at least for me- to do an unaligned read if I'm just writing C code and not even using pointer math... I mean, I'm just writing 'plain' C code, without anything particular... do you think that is it possible to code an unaligned read without even knowing?

(mmm... does malloc() always return pointers to aligned memory locations, right? ... )

#157731 - kusma - Wed May 28, 2008 9:40 am

Cydrak wrote:
Actually it's more fun than that. It is defined; the ARM Arch Ref Manual (would that be "ARM ARM?" :b *groan*)

Indeed it's called the ARM ARM :). We absolutely HAVE to call it "The ARM ARM" at work to avoid confusion ;)

Cydrak wrote:
says, in many scattered footnotes:
- LD/STRH, LD/STRD, LD/STR (THUMB): "Unpredictable".
- LD/STM, STR (ARM), SWP (write): Address masked; low bits ignored.
- LDR (ARM), SWP (read): Address masked; data ROR'd by 8 * low bits (even written out in the pseudocode!).

Hehe, yeah. This just makes it all even harder to deal with (like the fact that LDR and STR in ARM mode isn't symmetrical)! My guess would be that some old important legacy code depended on an implementation detail that gave these results, so we can't get rid of it or something ;)

#157732 - kusma - Wed May 28, 2008 9:42 am

sverx wrote:
Thank you all, it's really interesting :)

BTW I guess it's impossible -at least for me- to do an unaligned read if I'm just writing C code and not even using pointer math... I mean, I'm just writing 'plain' C code, without anything particular... do you think that is it possible to code an unaligned read without even knowing?

(mmm... does malloc() always return pointers to aligned memory locations, right? ... )

You're absolutely right, without pointer-trickery, you can't generate unaligned reads/writes in C/C++. malloc() is required to return a pointer aligned to the strictest alignment required by the platform.

#157733 - Maxxie - Wed May 28, 2008 9:42 am

malloc here is allways word (32bit) aligned.

The compiler will align elements in structs for you compatible with the ARM (except if you specify it to do different via the packed attribute) so you will be OK if you are not doing pointermaths/casts by yourself.

#157734 - sverx - Wed May 28, 2008 9:50 am

kusma wrote:
You're absolutely right, without pointer-trickery, you can't generate unaligned reads/writes in C/C++. malloc() is required to return a pointer aligned to the strictest alignment required by the platform.


That's good. What's bad now is that if
Quote:
Errors per second -- 1,557
Total Errors -- 77,872

aren't misaligned reads, what can they be? :shock:

(and it's funny it happens only with some MODs, and from a specific point on...)

#157735 - kusma - Wed May 28, 2008 9:53 am

sverx wrote:
That's good. What's bad now is that if
Quote:
Errors per second -- 1,557
Total Errors -- 77,872

aren't misaligned reads, what can they be? :shock:

Buy the debug-version of NO$GBA, it will tell you.

#157736 - simonjhall - Wed May 28, 2008 9:56 am

sverx wrote:
(mmm... does malloc() always return pointers to aligned memory locations, right? ... )
Yes, it will return pointers aligned to the word size of the machine.

With regards to the question about can you get C to do unaligned loads, yes you can. One way will be where you're sharing data with a machine whose architecture packs its data differently to your machine.

For instance if you've got a structure like
Code:
struct fred
{
   char a, b, c;
   int d;
};
And machine X outputs data to disk/network and is picked up by machine Y running the *same C code* then you need to ensure that the packing of the structure is the same when you're reading it in. If machine X has no problems with unaligned data and there's no padding byte between element C and element D then when this code is built on machine Y which does require (say) 32-bit alignment then a padding byte will be inserted into the gap in order to align D. When you go to read D you'll get the wrong data as it'll be reading from the wrong address. You won't generate an unaligned load though.

In order to read from the right location you need to tell the compiler that there's no padding like this:
Code:
#pragma pack (1)
struct fred2
{
   char a, b, c;
   int d;
};
#pragma pack ()
...but this means that when you pull your data out of D the address will be unaligned (assuming that the structure IS aligned) causing an unaligned exception. Sha-zam.

(yeah I know, pragmas aren't quite virgin C - can anyone provide a better example that doesn't require casting pointers from smaller to larger types?)
_________________
Big thanks to everyone who donated for Quake2

#157737 - sverx - Wed May 28, 2008 10:09 am

kusma wrote:
Buy the debug-version of NO$GBA, it will tell you.


That's another good reason for buying the no$gba debug ver, then :)
(mmm... does Martin finally gave news about him lately?)

#157738 - sverx - Wed May 28, 2008 10:12 am

simonjhall wrote:
With regards to the question about can you get C to do unaligned loads, yes you can. One way will be where you're sharing data with a machine whose architecture packs its data differently to your machine.


You're right. Fortunaly -at least this- shouldn't affect me ;)

#157742 - kusma - Wed May 28, 2008 10:58 am

simonjhall wrote:
And machine X outputs data to disk/network and is picked up by machine Y

Doing so is something I'd say qualifies as "pointer trickery" (and in general - bad code) :)
simonjhall wrote:
...but this means that when you pull your data out of D the address will be unaligned (assuming that the structure IS aligned) causing an unaligned exception. Sha-zam.

Not neccecarily an exception - gcc generates byte-reads and re-assembles the variables in these cases, at least for ARM cpus. In fact, unaliged reads doesn't generate exceptions on ARM cpus unless you have the system control coprocessor (or whatever it's called) and unaligned exceptions enabled.

#157769 - tepples - Thu May 29, 2008 1:33 am

kusma wrote:
Buy the debug-version of NO$GBA, it will tell you.

His PayPal account is gone.

simonjhall wrote:
With regards to the question about can you get C to do unaligned loads, yes you can. One way will be where you're sharing data with a machine whose architecture packs its data differently to your machine.

For instance if you've got a structure like
Code:
struct fred
{
   char a, b, c;
   int d;
};
And machine X outputs data to disk/network and is picked up by machine Y running the *same C code* then you need to ensure that the packing of the structure is the same when you're reading it in.

Endianness may bite you before alignment. As I understand it, this generation's consoles all have big-endian PowerPC CPUs, while the handhelds have little-endian MIPS (PSP) or ARM (DS, Windows Mobile, GP2X, Pandora).

Quote:
(yeah I know, pragmas aren't quite virgin C - can anyone provide a better example that doesn't require casting pointers from smaller to larger types?)

Something that would involve union?
_________________
-- Where is he?
-- Who?
-- You know, the human.
-- I think he moved to Tilwick.

#157803 - silent_code - Thu May 29, 2008 5:04 pm

yeah, just check libnds' sprite entry / rotation structs for an example. they also use bitfields. ;^D
_________________
July 5th 08: "Volumetric Shadow Demo" 1.6.0 (final) source released
June 5th 08: "Zombie NDS" WIP released!
It's all on my page, just click WWW below.

#157805 - kusma - Thu May 29, 2008 5:13 pm

tepples wrote:

Quote:
(yeah I know, pragmas aren't quite virgin C - can anyone provide a better example that doesn't require casting pointers from smaller to larger types?)

Something that would involve union?

reading from a different union-member than you last wrote gives undefined results in C/C++, if that's what you were thinking of. And I don't think it would break alignment either.

#157808 - simonjhall - Thu May 29, 2008 6:47 pm

Barely related to this, one thing that's starting to bug me about C/C++ is that people programmers often assign NULL (aka address zero) to pointers in order to say "there's nothing at the end of this pointer".
This is annoying me because,
a) if you use a target that doesn't have memory protection turned on by default (eg the DS), reading from your pointer is not going to get caught like on the PC
b) with the target that I program, legal memory begins at address zero so doing stuff with NULL pointers is ok!
c) asserts to check for NULL can be good or bad depending on whether or not NULL is a valid address
d) if a pointer to a structure is assigned NULL, only access to the first member will give yield address zero, other members may be at 0x4, 0x8 etc.

Really what I want is to have NULL work something like NaN - whenever you try to read from it you'll always get an error and if you have the struct example above , NULL + 0x4 wouldn't equal address 0x4, it'd still equal the magic code associated with NULL.

(can you tell that I've been fighting NULL pointers all day?! I also can't use references)
_________________
Big thanks to everyone who donated for Quake2

#157809 - Maxxie - Thu May 29, 2008 6:59 pm

If you are under C++, you can use one of those "smart pointer" templates.