Reflections on Typhoon Hagibis

Japan was recently hit by Typhoon Hagibis, which was equivalent to a category 4 hurricane once it hit landfall. It was said to be the worst storm to hit Japan since 1958.

Being a direct hit to lower Tokyo, Chiba prefecture was hit the hardest. The storm brought in dozens of deaths, localized flooding, and damage to single-family homes. Hundreds of thousands lost power.

Being in Tokyo, the storm hit me as well, so I thought I'd share what the experience was like.

Prior to the storm on Friday, everyone prepared by stocking up on water and essential foods. Most interestingly, I found it completely impossible to find any bread in the city. Every convenience store and grocery store was picked clean. However, I noticed that the tortillas were left untouched, and so I stocked up on those.

Japan's homes are tightly sealed from the outside for power efficiency, and so homes have indoor vents to allow outside air to come in. I'm told that it's best to close these during storms. …

bsnes Frame Advance Input Latency

I wrote an article recently about optimizing input latency in emulators, available here.
This led to a comment about the perceived input latency in Mega Man X using the frame advance functionality in bsnes. In investigating this issue on my Twitch channel yesterday, I discovered there were two separate issues. These issues only affected frame advance, and not latency in standard gameplay, but all the same, I'd like to do a post-mortem on these here today.
Steps to Reproduce Load Mega Man X and get in-game. Pause the emulator. Now hold down the fire key, and keep tapping frame advance. See how many frames it takes Mega Man to shoot.

This was taking four frames, whereas in Snes9X it was taking two.
Issue 1: pause to frame advance transitioning The first issue is that when bsnes was paused and the frame advance key was pressed, the emulator transitioned from pause mode to frame advance mode, but did not actually run a frame. So in effect, nothing happened at all. The user would ordin…

Fibers are still useful for some things

I wanted to comment a bit on this article by Raymond Chen, which states that fibers aren't useful for much anymore, with an example where I feel they still are.

I've found cooperative multi-(threading|tasking) (eg fibers) very useful in writing emulators. I wrote an article on this with code examples here.

One C++ thread on its own is inherently serial. When you have to do multiple discrete things at a time with very coarse synchronization, eg video encoding, then preemptive multi-threading makes sense (eg threads.) And when you have really simple functions to sync/wait or run/yield, then stackless coroutines are very elegant.

But when you want to model three CPU interpreters, a video renderer, and an audio generator, each of which needs to stay synchronized with the other when they communicate tens of millions of times a second, the overhead of using critical sections / semaphores / mutexes / atomic locks / etc grossly outweighs the cost of just doing everything on one thread…

Fall is here, which means warm vending machine drinks

It's likely well known that in Japan, drink vending machines are incredibly commonplace, and they're great. With exotic beverages like the energy drink Pocari Sweat and plenty of healthy green tea choices, drinks are always readily available.

An interesting cultural difference is that, in Japan, you're not supposed to eat or drink while walking, so you'll often find people hanging around the vending machines to drink their recently purchased beverages. And conveniently, they're the only places you'll find to dispose of the drink bottle after, so I suppose it works out.

Anyway, what really makes the vending machine experience memorable here is that, at least during fall and winter, vending machines contain warm drinks, marked あったか〜い (warm)

For usually a single 100 yen coin, you have access to your own personal mini-Starbucks, complete with no human interaction required, within a one-minute walk from just about any location.

I understand that during spring and s…

Summers and Bug-Catching

If you've ever played through The Legend of Zelda: A Link to the Past, or Pokemon Red and Blue, you may've come across the eponymous bug-catching net.

I recall this didn't make a lot of sense to me, but I mostly just went with it.

Having experienced a summer in Japan, it has suddenly made sense to me. In Japan, the telltale sign that summer has officially begun is hearing the annual cries of cicadas. You can hear the sounds in just about any anime series as well. It's extremely loud and constant for several weeks into summer. To Japan, the sound is endearing.

Cicadas, once above ground, have a very short 1-2 week lifespan, and a favorite passtime here is catching these bugs in nets to place inside jars.

Certainly, this isn't nearly as much of a thing in in the west. But I suppose there was no easy way to translate this concept, and so it was just kept in the games as-is.

Hello, I'm byuu

I am the author of the bsnes and higan emulators. These are solo projects that comprise over half a million lines of code.

bsnes started in 2004 as a Super Nintendo emulator with the goal of being as perfect as humanly possible, and over time grew to emulate many more systems. The name no longer fitting, it was renamed to higan in 2013.

higan currently emulates the NES, Famicom Disk System, SNES, Super Game Boy, Game Boy + Color, Game Boy Advance + Player, SG-1000, SC-3000, Master System, Game Gear, Genesis, Sega CD, Turbografx-16, Supergrafx, MSX, MSX2, ColecoVision, Neo Geo Pocket + Color, and the WonderSwan + Color. PC Engine CD support is currently underway.

The goal of higan is different from other emulators: rather than focusing on playing games, it is meant to document the functionality and edge cases of the original hardware, with code that is as clean and easy-to-read as possible. I believe I've pioneered several methods for this, including the use of cooperat…