GBA toolchain & debugging

category: code [glöplog]
In dug out my old GBA project and am now finally in the need to debug it.

Atm I use Programmer Notepad included in DevKitPro and a custom Makefile that has a run/debug command that builds a gba rom and starts a VBA-M SVN-version. All dandy, but I can't get it to communicate with GDB without crashing. Also ARM-GDB seems to be confused by the GBA file and VBA-M crashes when loading the elf file.
Basically: No cigar.

Also the GDB/Insight GUI sucks in comparison to Visual Studio or Eclipse. What should I use? How do I run all that shit from the Makefile?
Oh, yeah. I run Windows 7.
added on the 2012-01-08 20:52:50 by raer raer
I don't know what you are trying to do, but do you really need a debugger for it? I know my GBA demos are not the 1337est ever made, but I seem to remember getting along OK without a debugger. Would have been really nice at times, of course, but I don't think I'd have gotten much better/faster results at times anyway.
doh. There's actually a Insight version in the devKitPro dir...
With that one making a remote connection to VBA-M seems to work too. Then when stepping through the code Insight just blocks. Well...

Graga: What I'm trying to do is have a function called in fixed intervals based on TIMER3. I do:
Code: #define TIMER_INCREMENT 256 static int current = 0; void timerTick() { current += TIMER_INCREMENT; //REG_IF = IRQ_TIMER3; } void start() { irqInit(); irqSet(IRQ_TIMER3, timerTick); irqEnable(IRQ_TIMER3); REG_TM3CNT_L = -TIMER_INCREMENT; //also tried 0 and TIMER_INCREMENT REG_TM3CNT_H = TIMER_START | TIMER_IRQ | TIMER_DIVIDERBITS; }

Why is timerTick never called? Like uhm. never. I tried compiling in -marm mode, but that didn't change anything.

Do I need "REG_IF = IRQ_TIMER3" btw or does libgba do that for me?
added on the 2012-01-09 00:31:09 by raer raer
OK, so my GBA skills are quite rusty, but after looking a bit in GBATEK these are my thoughts:

1. Have you tried other types of IRQ (such as Hblank) and confirmed that they work? Vblank and Hblank are easy to check (pick your favourite tile-mode with no BG's enabled and increment palette entry 0 at every interrupt).

2. I'm not sure about what exactly you mean by having a negative TIMER_INCREMENT variable, and what the TIMER_DIVIDERBITS does. It shouldn't matter though, the interrupt should eventually happen anyway.
It shouldn't matter though, the interrupt should eventually happen anyway.

That's what I thought too...

The negative TIMER_INCREMENT is from a TONC tutorial I found. I'm pretty clueless about what the problem is.

MaxMod is running in the background, but that's only using TIMER0/1 for DMA afair. Vblank is happening, otherwise maxmod wouldn't play.
added on the 2012-01-09 11:59:54 by raer raer
raer: Read GBATek. You should use a negative value for TMnCNT_L if, and only if bit 2 of TMnCNT_H is zero. And this looks like it's the case in your example. But in that case the prescaler (which is what I suspect TIMER_DIVIDERBITS is supposed to set) is ignored.

Where did you get your definition of TIMER_DIVIDERBITS from? I can't find it, neither in libgba nor libtonc...

By the way, REG_TMnCNT_L doesn't get reloaded unless the counter overflows or bit 7 of REG_TMnCNT_H changes from 0 to 1. So if a timer is already started on timer 3, your timer won't trigger until that timer itself is finished. So you might want to write 0 into REG_TM3CNT_H to force the timer to stop first.

Anyway, if timer 3 isn't already started, your timer-interrupt should trigger every 256 cycles. But this might actually be too rapid to service, causing the interrupt to be missed. I doubt that's the cause, but it might be worth looking into. One interrupt every 256 cycles is quite a lot.
added on the 2012-01-09 12:24:18 by kusma kusma
Fark. Seems you're right. I didn't want to used connected timers.

I originally wanted a timer resolution of ~5ms (84000 cycles) because if find the Vblank-"timer" resolution of 16,7ms a bit much. The interrupt routine isn't doing much either, or is that really too expensive?

Code: #define TIMER_DIVIDERBITS 2 //Timer frequency = 16,7MHz/256=65536kHz -> Register is 16Bit, timer would overflow once every second. I want it to overflow every ~5ms #define TIMER_L 65536-328 //so I need to let it overflow every 328 timer increases (328*1/65536=0.005004s). static int current = 0; void timerTick() { current += 328; //current is actually a fixed-point 16:16 number, so increase it 65536/1000*5 = ~5ms //REG_IF = IRQ_TIMER3; } void start() { irqInit(); irqSet(IRQ_TIMER3, timerTick); irqEnable(IRQ_TIMER3); REG_TM3CNT_L = 0; REG_TM3CNT_H = TIMER_START | TIMER_COUNT | TIMER_IRQ | TIMER_DIVIDERBITS; }

Looks better. I'll try when I get home today...
added on the 2012-01-09 15:04:53 by raer raer
added on the 2012-01-09 15:08:04 by raer raer
in the 8 bit chips i worked with, a negative value for registers would be its 2s-complement, that is unsigned 256-abs(value). elsehow a negative value for a timer doesnt seem to make sense to me.
kusma: why would the value for TMnCNT_L matter anyhow, if bit 2 of TMnCNT_H (TIMER_COUNT) is zero? afaict from gbatek, the timer reload value is completely ignored in that case. great site btw, instant bookmark.
gba seems to be an interesting, i know there is a thread about cables already, but i ask anyway is a cable for programming the gba easy to make at home?
added on the 2012-01-09 19:16:36 by vectory vectory
*interesting platform
added on the 2012-01-09 19:17:01 by vectory vectory
REG_IF = IRQ_TIMER3; is not needed.

@vectory: You're right about the twos complement. You could start with using an emulator (no$gba, VisualBoyAdvance, VBA-M) or buy a flash cart or an SD-flashcart. Not all stuff runs on the SD-cart, because they usually need more wait states.
You COULD use a cable to load small binaries, but found it to complicated to use and wouldn't recommend it.
added on the 2012-01-09 19:48:14 by raer raer
BB Image
no$gba is a pretty decent debugger. I've heard some bad things about the accuracy of the emulation, though. Good luck finding a copy, though (legal or illegal.)
added on the 2012-01-09 21:42:58 by nitro2k01 nitro2k01
I was willing to buy it yesterday (the $15 home version), but the site was down...
added on the 2012-01-09 22:15:35 by raer raer
Dows it show the source along with the asm?
added on the 2012-01-09 22:16:05 by raer raer
You have a bigger problem than the site being down. That's just scheduled maintenance by the host. See link me beautiful. But Martin, the author of the emulator seems to be almost gone from the surface of the earth. He disappeared, made a post on an Amstrad CPC forum somewhere a year ago or something and then no one heard from him yet again.

Source: As far as I understand, it won't show your c(++) source inline, but will load an elf and give you symbolic labels in the disassembly.
added on the 2012-01-09 23:21:50 by nitro2k01 nitro2k01
raer: Do not buy it. Martin has disappeared, so if you wire money to his PayPal, you won't the product nor your money back.
added on the 2012-01-09 23:27:12 by kusma kusma
added on the 2012-01-10 09:32:38 by raer raer
Sounds a bit scary somehow. That, or he's just pulling a _why.
added on the 2012-01-10 09:32:59 by skrebbel skrebbel
Nah, I just think he got a proper job and stopped caring about emulation as all that brought him was people pirating his software, kids asking questions about pokemon and moms complaining about kids using their credit card to pay for the license. (That would be for the non-debug version, obviously.) It's an unrewarding job writing a Gameboy emulator, is what I'm saying.

In case you know nothing about Martin, he goes under the alias nocash (same as the no$ in his no$* series emulators.) Nocash doesn't stand for the emulators being free, despite popular belief. It's a reference to his own non-consumerist lifestyle, and one has to assume, relative poverty. Long ago, he used to have a message on the frontpage saying "Germany - where people can't afford to smoke filter cigarettes" in the style of a health warning with a black border. He had a "nightmare FAQ" with all the crap that people sent him about no$gmb. He used to talk about super-fast computers with HUNDREDS of megahertz. That was like 2000, but still.

My analysis is that he started out with a dream about making super efficient emulators and debuggers and maybe making a little bit of money from it. Instead, computers got faster and asm became largely redundant fo general purpose use and he just got ingratitude in return. So yeah, that's a basic insight in the psychology of Martin Korth. A bitter man. Wouldn't really compare it to _why. _why was more like the V of awesomeness coming to strike and then leaving amidst the night.

Anyway, for the more practical issues. Again, the homepage being down is just emubase.de doing maintenance. It should come back soon enough. His PayPal account has been closed down for a couple of years now, so no chance of paying by mistake. If you really want to give no$gba a try, you could try sending him a private message here: link me beautiful or by deciphering the e-mail address here link me beautiful and trying to contact him and asking him politely if you can buy a home license.

Or you could just try to make VBA work with GDB. :p
added on the 2012-01-10 10:59:32 by nitro2k01 nitro2k01
Hint: if you set up your periphery wrong, debuggers won't help. Reading data sheets (that is, gbatek) does.

Yes, now it would be nice if VBA worked with Insight/GDB, but I've never gotten this to work, either.

But you always have tons of possibilities: you can output stuff to the VBA console using swi 0xff (don't leave that in ROMs intended to run on a real GBA), or last time I really wanted to debug ARM assembly code the code in question happened to be totally OS/Hardware independent (it was a depacker, so all it did was memory access), so I could actually run it on GDB's built in ARM emulator, and so forth. Be creative =)
added on the 2012-01-10 11:19:54 by Moerder Moerder
Thanks. I'll try dropping him an Email.
I can imagine the pokemon-question-induced frustration and had already figured some time ago that he was probably not doing so well money-wise. But there's probably not a lot of money to be made off an GBA emulator/debugger...

VBA-M works ok, but the debug connection doesn't weem to work properly. Other than that I would be perfectly happy with it.
It is still using wxWidgets (why does that exist anyway) or MFC (YUCK!) btw...
added on the 2012-01-10 11:23:02 by raer raer
Didn't know about "swi 0xff". Thanks!
added on the 2012-01-10 11:24:21 by raer raer
Nitro, yeah I heard some of those stories. Nice to have it spelled out anyway. That said, to me no$ struck out with just about as much awesomeness as _why, but maybe that's just my filter bubble talking to me.
added on the 2012-01-10 13:20:40 by skrebbel skrebbel
Oh, don't get me wrong. Martin is awesome too, but in a different way. But because of the anonymity of _why you really only see his art and writings, and nothing of his personal life, and he comes across almost as some sort of renaissance man. Martin on the other hand is the mad but misunderstood scientist. While I look up to what he's doing in asm, I feel 50% amazed and 50% sorry for his situation. With a little appreciation from people, he could've done more. I don't know. I'm just rambling.
added on the 2012-01-11 00:13:19 by nitro2k01 nitro2k01