News for hackers. Stuff that matters.
Re:The Infinite Loop That Wasn't by techdragon on Sunday January 26, 2020 @05:34AM (#22151428)
I love reading these kinds of reverse engineering discovery tales, I find them technically educative, and overall enlightening... they help put my own struggles debugging thorny things into sharp perspective, making me even more appreciative of the level of control I have over my own code and it’s runtime environments.

The level of effort put into reverse engineering for emulating classic hardware of all kinds is just remarkable. The Dolphin EMU team has a long history of these kind of blog posts for people looking for more of this kind of writing https://dolphin-emu.org/blog/

Re:The Infinite Loop That Wasn't by hyperman1 on Sunday January 26, 2020 @06:03AM (#22151513)
I've always had the attitude that if can reproduce a bug consistently, I can debug it, and I can fix it. Now here's a nail in the coffin of that theory.
Re:The Infinite Loop That Wasn't by umvi on Sunday January 26, 2020 @01:42PM (#22153795)
Only if the problem is purely software. I've had reproducible problems that were impossible to solve by myself. The process went like this:

- Huh, getting USB disconnects randomly, need to fix this

- Hmm, device driver seems to be fine

- Hmm usbnet driver seems fine

- Hmm xhci driver seem fine

- $5000 and one USB 3.0 protocol analyzer later...

- What the heck is this host controller doing?

At this point it was looking like a hardware problem but seeing as I didn't have the schematics or verilog of the host controller I could go no further (nor did I want too... I never imagined USB could be such a deep rabbit hole).

Re:The Infinite Loop That Wasn't by rgoulter on Sunday January 26, 2020 @07:17AM (#22151720)
Most of the bugs I've dealt with, the problem was usually down to something simple that can be explained quickly. (e.g. syntactically valid typo, config error, simple logic error etc.).

Seems like "Holy grail" bugs like this happen to need a thorough understanding of complex systems (which I usually like to hide under layers of abstraction).

Re:The Infinite Loop That Wasn't by masswerk on Sunday January 26, 2020 @08:38AM (#22151997)
In defense of the coffin, I'd say this is not so much about a bug, but about reverse engineering real world effects of undefined behavior (as caused by a bug in software).
Re:The Infinite Loop That Wasn't by aidenn0 on Sunday January 26, 2020 @06:30PM (#22155618)
If the goal of mgba is to reproduce the GBA hardware faithfully, then this is a pure software bug in mgba.
Re:The Infinite Loop That Wasn't by pingyong on Monday January 27, 2020 @06:37AM (#22158408)
That is not the goal of mGBA (or any GBA emulator for that matter), btw. If you wanted to reproduce it faithfully, the emulator would be unusably slow.

https://emulation.gametechwiki.com/index.php/Emulation_Accur...

Re:The Infinite Loop That Wasn't by aidenn0 on Monday January 27, 2020 @12:36PM (#22161685)
s/faithfully/faithfully enough/ Prior to the bug being fixed this was clearly not faithfully enough for at least 2 games.
Re:The Infinite Loop That Wasn't by NieDzejkob on Sunday January 26, 2020 @07:23PM (#22155887)
You are trying to argue about the meaning of the words being used. This is not productive, as what matters is what the author of the argument meant when they used that word.
Re:The Infinite Loop That Wasn't by aidenn0 on Monday January 27, 2020 @12:29AM (#22157040)
I don't think that's the case. When talking about emulation and virtualization and such, it is easy to get terms backwards.

For example, a bug in the implementation of a virtualized device looks like a hardware bug to the client and like a software bug to the host.

Re:The Infinite Loop That Wasn't by masswerk on Monday January 27, 2020 @06:37AM (#22158414)
To be honest, I think it's about crossing the lines of emulation and simulation. In emulation, we mostly consider instruction level behavior as good enough, but here, we'll have to venture below cycle level and integrated hardware effects to copy the behavior.
Re:The Infinite Loop That Wasn't by aidenn0 on Sunday January 26, 2020 @06:29PM (#22155614)
A rule of thumb I use is that if I can reproduce a bug in approximately 0 time, I can fix it within 1 hour 95% of the time.
Re:The Infinite Loop That Wasn't by matheusmoreira on Sunday January 26, 2020 @03:25PM (#22154520)
These test ROMs are interesting. Since they are designed to run on real hardware that lacks debugging capabilities, the user must be able to operate the test suite and check the results manually. They aren't like modern software test suites.

According to the nesdev wiki, automation consists of playing back controller input, waiting for the tests to run, taking a screen shot of the results screen, hashing it and comparing the result to the hash of the expected results screen. This method also allows testing real games to check for reproducible bugs.

https://wiki.nesdev.com/w/index.php/Emulator_tests#Automated...

Pretty nice. I expected the test ROM to write the results to some special location in memory and have the emulator report those results.

Re:The Infinite Loop That Wasn't by unwind on Sunday January 26, 2020 @06:19AM (#22151566)
So uh I didn't see it mentioned, but the question of why this code is in the games arises.

Is it buggy code, or something intentional like anti-emulator sneakery?

Re:The Infinite Loop That Wasn't by hrydgard on Sunday January 26, 2020 @06:36AM (#22151603)
It's pretty likely that it's just buggy code that happened to work on hardware.
Re:The Infinite Loop That Wasn't by near on Sunday January 26, 2020 @10:35AM (#22152518)
Definitely just working by chance in this case. This comes up a lot, unfortunately. Small budgets, tight deadlines, games not validated for correctness under software emulation for detecting these types of edge cases prior to shipping.

Another example: there are several GBA games that dereference null pointers, but it works because there is no memory protection fault hardware in the GBA. Since the BIOS is mapped to address 0 and yet locked out from reading post-boot (in a failed anti-copying mechanism), you have to emulate the open bus behavior to run these games correctly as a result.

There are also several anti-emulator routines in the GBA library, such as lying about the type of save memory (flash, EEPROM, or SRAM) that a given game actually has (by including strings in the ROM from the Nintendo SDK used to access them.)

Re:The Infinite Loop That Wasn't by Wowfunhappy on Sunday January 26, 2020 @01:23PM (#22153670)
Still, in the case of Hello Kitty, there's got to be a reason the developer added that loop at startup, right? They might have not understood the intricacies of how or why it worked, but presumably they were trying to do something.
Re:The Infinite Loop That Wasn't by Izkata on Sunday January 26, 2020 @04:31PM (#22154944)
> Then I noticed a difference between my test ROM and Pokémon Emerald when they hang. There was music playing in Pokémon. There was also music playing in Sonic Pinball Party. There wasn’t music playing in Hello Kitty, but this gave me an idea.

Maybe there was supposed to be music playing, this was for timing it, and it was removed, broken, or just forgotten about?

Re:The Infinite Loop That Wasn't by Thorrez on Monday January 27, 2020 @12:43AM (#22157093)
>games not validated for correctness under software emulation for detecting these types of edge cases prior to shipping.

Did they have software emulation for that hardware at the time the game was written?

Re:The Infinite Loop That Wasn't by near on Monday January 27, 2020 @03:31AM (#22157732)
For the Game Boy Advance, yes. There was both a secretive internal Nintendo GBA emulation kit, and the public emulator development community had devkit games emulated before the system even officially launched.

I understand it was less practical to do this for say, the NES or SNES. But it should have been done for the GBA. It's not just important for future hardware to be able to easily emulate GBA games, it also protects against product refreshes breaking games, something that plagued quite a few classic Game Boy games as newer models came out and fixed bugs in the older models.

Re:The Infinite Loop That Wasn't by vardump on Sunday January 26, 2020 @09:48AM (#22152294)
Could be original authors knew that the DMA fetched value is on the bus and waited until certain kind of value was visible.

Perhaps to "fix" some weird DMA related bug.

Re:The Infinite Loop That Wasn't by DubiousPusher on Sunday January 26, 2020 @12:59PM (#22153508)
Interesting story. Goes to show you the falacy of writing fault tolerant systems as opposed to writing noisy systems.

Had the GBA architects made the device halt on invalid memory rather than return the last thing on the bus and hope everything would be ok this entire class of bug wouldn't exist and the authors of that code likely would've found that bug during production.

Re:The Infinite Loop That Wasn't by Wowfunhappy on Sunday January 26, 2020 @01:13PM (#22153598)
> Had the GBA architects made the device halt on invalid memory rather than return the last thing on the bus and hope everything would be ok this entire class of bug wouldn't exist and the authors of that code likely would've found that bug during production.

Of course, would it matter if these bugs were found? The games ran fine on real hardware.

There’s no maintenance burden either, because updating a gba game is literally impossible.

Re:The Infinite Loop That Wasn't by ranger207 on Sunday January 26, 2020 @02:25PM (#22154111)
>updating a gba game is literally impossible.

Not quite. The Pokémon Ruby/Sapphire Berry Glitch bug was fixed by connecting to games that had a patch program, such as Pokémon Emerald, the 3rd in the Ruby/Sapphire/Emerald series.

https://bulbapedia.bulbagarden.net/wiki/Berry_glitch

Re:The Infinite Loop That Wasn't by Wowfunhappy on Sunday January 26, 2020 @02:33PM (#22154166)
Huh, cool. Does anyone know how this worked? I know the carts themselves are mostly write-once so the bug and patch must have been related to the save portion or some hardware specific to this cartridge, right?
Re:The Infinite Loop That Wasn't by wizzwizz4 on Sunday January 26, 2020 @02:46PM (#22154260)
I think it just used an arbitrary code execution thing to change the system clock, so that the faulty code was still there, but never failed.
Re:The Infinite Loop That Wasn't by capableweb on Sunday January 26, 2020 @01:51PM (#22153871)
> because updating a gba game is literally impossible

Hey now, I'm sure it's not "impossible", you could probably overwrite specific sectors with laser or whatever, but probably had more to do with the distribution, where the economy and environment impact wouldn't make sense.

Re:The Infinite Loop That Wasn't by Wowfunhappy on Monday January 27, 2020 @10:07AM (#22159920)
I’m pretty sure the carts were quite literally write-once. Lasers would just damage the cart.
Re:The Infinite Loop That Wasn't by zodiac on Sunday January 26, 2020 @01:35PM (#22153744)
Are they "bugs" from the point of view of the gba designers or the game programmers? I was u der the impression that the game programmers purposely read invalid memory this way in order to prevent emulation
Re:The Infinite Loop That Wasn't by Narishma on Sunday January 26, 2020 @01:59PM (#22153924)
I don't think game developers care about emulation all that much.
Re:The Infinite Loop That Wasn't by Out_of_Characte on Sunday January 26, 2020 @06:06AM (#22151529)
Amazing story. Just shows you how complex hardware can truly be.
Re:The Infinite Loop That Wasn't by wkearney99 on Sunday January 26, 2020 @08:54AM (#22152068)
Correct. When you're coding really close to the metal you discover (and perhaps depend upon) all kinds of shenanigans that a higher level language compiler might work around.

The graphics on Atari 2600 had to be fed line-by-line during the vertical blanking interval. Made for some really tricky assembly coding, trying to get enough done to make the interval without wasting VERY limited ROM resources (aka can't cheap with NOP instructions).

Re:The Infinite Loop That Wasn't by abbeyj on Sunday January 26, 2020 @11:43AM (#22152995)
I'm assuming you meant "horizontal blanking interval" instead of "vertical blanking interval". But I don't think that's entirely correct either. Some games will change the registers while the beam is actively drawing so that, e.g., the left half of the line will be drawn with one set of settings and the right half drawn with another.
Re:The Infinite Loop That Wasn't by libraryofbabel on Sunday January 26, 2020 @12:45PM (#22153429)
This reminds me of the wonderful novel "The Bug" by Ellen Ullman. A beautifully-written fictionalized account of the quest for a "Holy Grail" bug.
Re:The Infinite Loop That Wasn't by brailsafe on Sunday January 26, 2020 @06:53AM (#22151644)
Mental.