32mbit blog
6-Button Controller Fix Patches

6-Button Controller Fix Patches

~1 minute read

These are IPS patches for various Genesis games that fix them to make them compatible with a 6 button controller. They do not add any functionality (except in one case*), but allow you to play the games without having to mode switch the controller. Intended for use with flash carts on real hardware.

These apply to the following ROMs in the No-Intro set:

Alien 3 (USA, Europe) (Rev A)
DEcapAttack (USA, Europe)
Forgotten Worlds (World) (v1.1)
Golden Axe II (World)
King of the Monsters (USA)
Phantom 2040 (USA)

6-Button Controller Fix Patches

*Phantom 2040 can already use the extra buttons of a 6 button controller, but the patch fixes a bug where some (many?) 6 button controllers cause the player to not be able to do a full-height jump.

Cleaning up old 80s/90s cartoons

Cleaning up old 80s/90s cartoons

9 minutes read

Get Ready to learn FFmpeg, Buddy

This is my general starting point for encoding 80s and 90s cartoons to HEVC to get decent (and usually, improved over the source) quality and small file sizes. Note that I specifically am referring to Western cartoons; a lot of this will apply to anime too but I have found that anime tends to be released in better shape than the stuff that was made mostly as 23 minute long ads to sell us action figures as kids.

ffmpeg \
      -i "$input" \
        -init_hw_device vulkan=vk:0 \
        -filter_hw_device vk \
        -vf "bwdif=mode=send_frame:parity=auto:deint=all,\
hwupload,\
nlmeans_vulkan=s=3:p=3:r=7,\
hwdownload,\
format=yuv420p" \
        -c:v libx265 \
        -crf 22 \
        -preset medium \
        -x265-params "tune=animation:deblock=-1\\,-1" \
        -c:a aac \
        -b:a 128k \
        -c:s copy \
        -map 0:V \
        -map 0:a:0 \
        -map 0:s? \
        -map_metadata 0 \
        -map_chapters 0 \
      -ignore_unknown \
       $output"

If you are encoding from an interlaced source like DVD, you need to deinterlace it. The bwdif filter in my opinion is the best at this generally. The parity and deint options there are the defaults I think, but parity can be set to tff or bff to manually specify top or bottom field first, and deint can be set to all or interlaced frames only. Still, these defaults are good. The bwdif=mode setting can be changed to send_field if you want to double up the framerate. The result is similar to "bob" deinterlacing, but cleaner, which is what you may want for a lot of TV cartoons of the era that were edited on video. Back then, it was common to sometimes fix animation errors in editing by adjusting playback speed or using a frame store to hold on a frame for longer. It was also common to use character generators to insert graphics elements or titles and credits over the edited video. This is not to mention editing cuts that occur between fields; a decimating deinterlacer will just blend those frames together and your encoding algorithm will hate it. Historically this type of video has been thought of as mixed telecine/video content, but you will drive yourself insane trying to detelecine these (and the results won't be fully correct anyway), so truly it's better to just encode them at 60p or at least 30p. In short, nobody should really be trying to IVTC any Western cartoon from the SDTV era from the 80s to the early 2000s. Fortunately, modern encoding like HEVC doesn't really care much about the increased frame rate--a higher frame rate won't make your files significantly larger. Of course, if your source is already progressive, you can just omit the bwdif filter altogether.

The nlmeans parameters can be adjusted up a bit for stuff that's really noisy, but the tradeoff with nlmeans is stronger denoising will start to smear areas of lower contrast and can be seen in things like fades to and from black, or shading on characters and objects beginning to disappear. If you need slightly heavier denoising I have found

nlmeans_vulkan=s=7:p=5:r=15

works pretty well without getting too smeary.

Note that you really need to use a hardware accelerated nlmeans. I've found the vulkan version to be faster than opencl at least on my AMD card and on linux. Other platforms may have other options, but running nlmeans as a regular CPU filter will net you single digit framerates for the conversions more likely than not.

The CRF value for x265 is personal preference, but 22 is almost completely transparent to me. Using a slower preset (ironically, -preset slower is the most effective time/compression tradeoff) will make your files smaller at the same quality if you have the time. Cartoons cleaned up with nlmeans and the x265 animation tune compress really well, expect 200mb for a half hour. I've found most 23 minute cartoons come in around 150mb or even less per episode.

The other options are related to preserving metadata which is handy if you are outputting to MKV if your source is a DVD, or an MKV file with metadata. There is also a neat trick you can do with ffmpeg to encode directly from DVD titles and chapters. The below example is for a DVD ISO but you can also specify a real drive (at least on Linux with libdvdread set up).

ffmpeg -f dvdvideo -title 1 -chapter_start 1 -chapter_end 2 -i /path/to/dvd.iso

Converting PAL to NTSC

A lot of sources I find online, especially the Internet Archive, tend to be in PAL format because for some reason PAL territories are where obscure old cartoons got full DVD releases. The vast majority of these, if you're lucky, can be deinterlaced to frames (bwdif=mode=send_frame) and then slowed down to 24.000 fps to get a perfect "film" cartoon.


ffmpeg \
       -i "$input" \
-init_hw_device vulkan=vk:0 \
-filter_hw_device vk \
-vf "bwdif=mode=send_frame:parity=auto:deint=all,\
hwupload,\
nlmeans_vulkan=s=7:p=5:r=15,\
hwdownload,format=yuv420p,\
crop=iw*0.92:ih*0.92:iw*0.04:ih*0.04,\
setpts=PTS*(25/24)"\
-r 24 \
-af "asetrate=48000*(24/25),\
aresample=48000"\
-c:v libx265 \
-pix_fmt yuv420p10le \
-preset slower -crf 23 \
-x265-params "tune=animation:deblock=-1,-1" -c:a aac -b:a 128k \
"$output"

The filters of interest here are the video filters setpts=PTS*(25/24) and crop, and the audio filter asetrate=<input sample rate>*(24/25). The setpts filter changes the frame rate by extending the length of time between frames. The crop filter is optional, but I have found that PAL versions of cartoons usually have some dead space around them that will eat up your encoding bitrate. My guess here is that PAL versions probably include all of the NTSC safe area and a little more on top of that to make up for PAL's taller vertical resolution. Anyway, the crop filter takes 4% off the corners which solves this problem nicely. The asetrate filter should be set to whatever your current audio sample rate is, times the 24/25 factor (note that this is the other way around from the setpts filter, as a longer PTS equals a slower framerate). This just slows the audio down by setting its sample rate lower, and the following aresample resamples it back to the original output rate. The resulting audio remains nicely in sync with the slowed down video and pitch corrected too.

The other option is that you are NOT lucky and the video was converted to PAL by some other process. I've noticed this is more likely with late 90s/early 2000s stuff were the NTSC to PAL conversion was likely done digitally. Cartoon Network DVDs tend to suffer from this the most. I'm not sure of the exact method but instead of conforming the video to 25fps, the conversion is temporal and causes awful frame ghosting. The lone upside is that typically on these the audio will already be at the correct pitch and the runtime will be about the same as NTSC. These probably aren't worth trying to fix--get another source, or just deal with it. That said, there are some conversions that introduce a duplicate frame every 24 frames and you might be able to do something with the shuffleframes filter to drop those duplicate frames. (Though, this filter is more useful to restore PAL material that was badly converted to NTSC, but that is a different article.)

What now?

Go watch some of those old Biker Mice from Mars episodes and marvel about how they... don't hold up as well as you remember. You think you liked Street Sharks better anyway...

Rocket Knight Adventures Unofficial OSV

Rocket Knight Adventures Unofficial OSV

2 minutes read

Rocket Knight Adventures
Unofficial Original Sound Version
by 32mbit

01 - Konami Logo
02 - Interlude
03 - Stage Intro
04 - Stage 1-1 - Kingdom of Zephyrus
05 - Stage 1-2 - Across the Sea
06 - Stage 2-1 - Mountain Range
07 - Stage 2-2 - Minecart
08 - Stage 3 - Going Underground
09 - Stage 4 - Flying Battleship
10 - Stage 5-1 - Kingdom of Devotindos
11 - Stage 5-2 - Traps
12 - Stage 6 - Outer Space
13 - Stage 7 - The Pig Star
14 - Stage Clear
15 - Miniboss
16 - Boss
17 - Final Boss Intro
18 - Final Boss 1
19 - Final Boss 2
20 - Continue
21 - Ending
22 - Congratulations!
23 - Staff Roll
24 - Game Over

Music by Konami Kukeiha Club:
Masanori Oouchi, Masanori Adachi, Aki Hata,
Hiroshi Kobayashi, Michiru Yamane

Download
LAME MP3 VBR V0 CD Quality

Recorded via Tascam US-1x2 Line In @ 24/96 from Sega Genesis Model 2 rev VA2.3 w/discrete YM2612 & custom Model 1 VA3 Stereo Replica mod
Trimmed, normalized and resampled to CD format via Audacity

Animaniacs Enhanced Edition [Sega Genesis ROM Hack]

Animaniacs Enhanced Edition [Sega Genesis ROM Hack]

~1 minute read

  • 6 Button controller support: Press X to Yakko (and Y to Wakko, and Z to Dot).
  • Character switching speed made much faster
  • Wakko's hammer attack sped up
  • VERY HARD difficulty unlocked from code
  • Sound test restored (taken from my old hack)
  • Ported extra languages (German & French) from PAL version
  • Region protection removed

Download IPS patch HERE

Apply this IPS to No-Intro ROM:

sha256sum
31fbf9d442d578c43788a024336639648d5c7dab4502636e127190c991ff3604
Animaniacs (USA).md
MiSTer FPGA passive video cable you can build yourself

MiSTer FPGA passive video cable you can build yourself

4 minutes read

Here's a passive S-Video to VGA cable I made for my MiSTer FPGA so that I could use it with a composite only TV. You'll need some inductors, some ceramic capacitors, a 414x diode and resistor.

I built it directly in the connector:

Cut the end off of a cheap composite video cable and wire it up with a screw-together shell and now I have a decent cable to play my games on my little tube.

So why do you need this if the MiSTer can output composite video already? Because the MiSTer's digitally created composite really sucks! It works in a pinch but it's a rainbow colored mess because the totally unfiltered luma signal is so high frequency. So you need something like this; the circuit creates a notch filter in the output that helps keep the luma signal from interfering with the chroma and creating that nasty rainbowing.

Note that you can omit the sync combining part (the diode and resistor) if you are using an I/O board set up to use sync-on-green, but I found that the sync signal this generates wasn't great for my TV. Also, constructing the cable the way I did also lets you use it with an HDMI to VGA adapter in direct video mode without having to modify it, which is nice.

This cable works by taking the MiSTer's native S-Video and filtering it and combining it down to composite, so you need to set up your MiSTer.ini for this. Note that this is for NTSC. You could build a PAL video cable by changing the capacitor and inductor values to scale the filter cutoff; some quick figuring, I think substituting the inductors for 3.3uH parts would probably get you close enough.

vga_mode=svideo
composite_sync=1
ntsc_mode=0

The results are not too bad at all. If you want to get rid of rainbowing entirely, move up to a 6.8uH inductor. Your image will get overall softer, though. Them's the breaks! You can also try turning on the composite video filter in cores that have it (like the MegaDrive core) and this will also take care of it by pre-filtering the image. Neat!

Here's what it looks like straight up: