Homebrew TWPatcher - DS(i) mode screen filters and patches

  • Thread starter Sono
  • Start date
  • Views 744,342
  • Replies 2,428
  • Likes 101

Are you interested in a complete replacement of TwlBg which includes all patches?

  • Yes, I don't care how broken it will be!

    Votes: 188 79.3%
  • No, I don't want to use even more broken stuff

    Votes: 20 8.4%
  • Yes, but only in GBA mode, because I play DSi exclusives

    Votes: 12 5.1%
  • No, because I only use DS and DSi mode

    Votes: 17 7.2%

  • Total voters
    237
  • Poll closed .

Sono

cripple piss
OP
Developer
Joined
Oct 16, 2015
Messages
2,820
Trophies
2
Location
home
XP
9,289
Country
Hungary
damn @Sono got it wrking finally I renamed section0.bin to agbg0.bin and the percentage of bytes used were 91 so it should be fine

I just checked the patcher's source, and I'm really sorry, but I forgot I change the filename so I don't need to keep backing up and renaming the file each time I want to work with TwlBg or AgbBg.

Yeah, you need to name it agbg0.bin instead of section0.bin, my apologies.
 

selcuk

Well-Known Member
Newcomer
Joined
Oct 3, 2015
Messages
83
Trophies
0
Age
33
XP
256
Country
If you want to just tweak the GBA crispiness/smoothness, just replace in code.bin of agbbg.cxi:

Code:
 0000 0020 0040 0000 0020 0040 0040 0020 0000 0040 0020 0000

with

Code:
 00XX 0020 00YY 00XX 0020 00YY 00YY 0020 00XX 00YY 0020 00XX

Where XX is between x0 and x20 and YY is betweeen x20 and x40, and together these should also add up to x40.

X=0 Y=40 is the default super crisp, often chunky scaling
X=10 Y=30 gives you a smooth effect like bilinear interpolation
X=20 Y=20 makes everything flat and super blurry

X=07 Y=39 is my current go-to. Its about the minimum crispness that keeps high-contrast text distinct and easy to read. Something closer to this should've been the Nintendo default considering what they picked for DS scaling..

I'm SO much happier using AGB_FIRM now with these settings. Big thanks again to Sono for doing the heavy lifting of finding this stuff, now I got something to hold me over until he gets his patcher finished!
It seems I can't find
Code:
 0000 0020 0040 0000 0020 0040 0040 0020 0000 0040 0020 0000
in HxD... can you help?
 

Rahkeesh

Well-Known Member
Member
Joined
Apr 3, 2018
Messages
2,178
Trophies
1
Age
42
XP
3,259
Country
United States
Either you are doing a search in decimal mode (default) instead of hex, or you might have the wrong .cxi file.

Depending on how you got the .cxi file, it may need to be unpacked/decrypted, and will need repacking/encrypting before use. You won't be able to find that string in an encrypted file.
 
Last edited by Rahkeesh,

selcuk

Well-Known Member
Newcomer
Joined
Oct 3, 2015
Messages
83
Trophies
0
Age
33
XP
256
Country
Either you are doing a search in decimal mode (default) instead of hex, or you might have the wrong .cxi file.

Depending on how you got the .cxi file, it may need to be unpacked/decrypted, and will need repacking/encrypting before use. You won't be able to find that string in an encrypted file.
How do I know if its rncrypted or not.?
I got the file from the patcher. AgbBg.cxi
 

Rahkeesh

Well-Known Member
Member
Joined
Apr 3, 2018
Messages
2,178
Trophies
1
Age
42
XP
3,259
Country
United States
So you can't directly hex edit the cxi file, at least I don't think so. I actually edit code.bin which gets put in the exefs folder after unpacking the contents of agbbg.cxi with ctrtool or 3DStool, can't remember which. I wrote a bat file to pack the results of editing into the .cxi file, maybe you can figure out the rest from taking a look at that and finding the tutorial that you probably need to follow to even get agbbg.xci out in the first place. (its basically the same process as has been laid out in this thread for twlbg.xci, you just need to pick the title for GBA instead when extracting with GM9)

Code:
3dstool -czvtf exefs exefs.bin --exefs-dir exefs --header exefsheader.bin
3dstool -cvtf cxi AgbBg.cxi --header ncchheader.bin --exh exheader.bin --exefs exefs.bin --not-encrypt
 

selcuk

Well-Known Member
Newcomer
Joined
Oct 3, 2015
Messages
83
Trophies
0
Age
33
XP
256
Country
So you can't directly hex edit the cxi file, at least I don't think so. I actually edit code.bin which gets put in the exefs folder after unpacking the contents of agbbg.cxi with ctrtool or 3DStool, can't remember which. I wrote a bat file to pack the results of editing into the .cxi file, maybe you can figure out the rest from taking a look at that and finding the tutorial that you probably need to follow to even get agbbg.xci out in the first place. (its basically the same process as has been laid out in this thread for twlbg.xci, you just need to pick the title for GBA instead when extracting with GM9)

Code:
3dstool -czvtf exefs exefs.bin --exefs-dir exefs --header exefsheader.bin
3dstool -cvtf cxi AgbBg.cxi --header ncchheader.bin --exh exheader.bin --exefs exefs.bin --not-encrypt
I made agbbg.cxi correctly and unpacked it using 3dstool and firm tool. But I still can't find the hex code.
 

Rahkeesh

Well-Known Member
Member
Joined
Apr 3, 2018
Messages
2,178
Trophies
1
Age
42
XP
3,259
Country
United States
If it helps, I found that hex string around address 4A1B0 in code.bin. I understand these addresses can differ. Mine came from fairly recent firmware (1.13?)

If you're using an agbbg.xci edited by Sono's command line patcher then I doubt any of my suggested edits will work. I extracted this stuff straight from my 3DS NAND via GM9.
 
Last edited by Rahkeesh,
  • Like
Reactions: selcuk

Rahkeesh

Well-Known Member
Member
Joined
Apr 3, 2018
Messages
2,178
Trophies
1
Age
42
XP
3,259
Country
United States
So I'm revisiting agbbg.cxi and trying to work on sharpening. It seems like you can't go past F100 for negative numbers, I always get black screen/no sound if I do, which limits how much you can sharpen. I'm assuming negative numbers in the matrix work like typical integers, i.e. two's complement encoding so FFFF = 1, 8000 = -32,768, etc, and of course is encoded in little endian (so really 00F1, etc). Wondering if there is any theory to explain this limitation or any workaround past it.
 

Rahkeesh

Well-Known Member
Member
Joined
Apr 3, 2018
Messages
2,178
Trophies
1
Age
42
XP
3,259
Country
United States
Here's a Christmas "gift": an excel / google sheet that calculates AGB matrices, to be copied into a hex editor editing code.bin extracted from agbbg.cxi. It allows you to fine tune increases to smoothing and sharpening, yielding results closer to how DS scaling is done by default on 3DS, although with much better results as 2->3 is an easier scale than 4->5. It has two values to be edited in the upper left, taking a decimal between 0 and 1 inclusive, with 0s entered in to match the default state of unmodified agbbg.cxi.

First ensure you know where the matrix code is in your code.bin. Because the sheet starts off with the default values (from 0 in both linear smoothing and edge sharpening), you can copy the lower line that has all the hex codes and search for that with an editor like HxD. On mine it starts at address 4A1A8 and goes to 4A1D7. Go ahead and select this space because that is what we will be replacing.

The first factor is "linear smoothing." The default of 0 makes it semi-"crisp" and pixelly, but can also distort shapes, like the outlines of the comic cutscenes in Zero Mission. This is because pixels from the original image are not factored into the scaled one equally. A value of 1 eliminates pixelness and perfectly weights all pixels in the final image, but makes things extremely smooth/blurred.

To combat added blur by turning up linear smoothing, you can use the edge sharpening factor. This is a simple sharpening algorithm as you might see on TVs or monitors, it tends to enhance strong contrasts of neighboring colors, but can produce unwanted ringing/halo artifacts. 0 is no sharpening, while a value of 1 is the max sharpening allowed. (which isn't *that* sharp, so don't be afraid to try it.)

Once you've set your values, copy the code line at the bottom to the appropriate place in code.bin we highlighted earlier. Then save and rebuild agbbg.xci as normal and drop in luma/sysmodules on your SD card. I kind of like smoothing .5 and sharpening .7 but feel free to try other values.

If you've played with these hex edits before, give my excel file a try. You can also read some boring technical details below.

As to why I've been working on this: the default AGB scaling does not treat every pixel evenly. The basic job that has to be done is to turn 4 GBA pixels into 9 on the 3DS. As far as I can tell, the original matrix accomplishes this by creating little cubes of 4 original pixels and fills out the edge with 5 interpolated ones that evenly blend the nearest pixels. While somewhat sharp this distorts the original shapes because in the scaled image there is zero space between some original pixels while others have an interpolated pixel placed between them. Spacing every pixel evenly actually means not directly copying any source pixels though, instead its always a blend of like 75% one and 25% another at best, which means to represent shapes and space accurately you are left with blur at a 2->3 upscale. However we can use traditional sharpening to help combat this, and with some compromise we something we can get something that is more accurate and still sharp or sharp enough.

Because I can't figure out how to go over -F00 in any one pixel, a factor of "1" gives you the maximum possible sharpening while keeping everything proportional. I find 1 is already borderline on making annoying artifacts so it isn't too much a loss that you can't push further. Note that the overall strength of sharpening increases slightly as linear smoothing increases, because while the maximum pixel value is fixed at F00 the minimum values will be higher to remain in proportion with the smoother minimum (x10 instead of x0)

Google Sheets link
 

Attachments

  • agb matrix calculator.zip
    8.2 KB · Views: 110
Last edited by Rahkeesh,

Rahkeesh

Well-Known Member
Member
Joined
Apr 3, 2018
Messages
2,178
Trophies
1
Age
42
XP
3,259
Country
United States
Its using a bunch of formulas so a screenshot is not that helpful. I thought openoffice could open this for free on basically any machine? I can try to lay out the formulas here otherwise, there aren't that many, but its probably easier to play with it if you can.

Edit: here's a shot anyway

agb calc.png

Edit2: I can probably make a google document version, that would be more accessible

Edit3: here's a viewable google sheets link, hopefully you can make a copy into your own drive for editing, let me know if not.

Google Sheets
 
Last edited by Rahkeesh,
  • Like
Reactions: Sono

Sono

cripple piss
OP
Developer
Joined
Oct 16, 2015
Messages
2,820
Trophies
2
Location
home
XP
9,289
Country
Hungary
Edit3: here's a viewable google sheets link, hopefully you can make a copy into your own drive for editing, let me know if not.

Google Sheets

Hmm... it's an interesting concept :unsure: But it seems to be invalid, because you're only printing 6 * 4 values, when you need 6 * 6 values for GBA upscaling, and 6 * 5 values for bottom-screen-fitting DS scaling. 6 * 4 values can be used for the 1x "upscaling", but why would anyone apply a filter to a pixel-perfect image?
 

Rahkeesh

Well-Known Member
Member
Joined
Apr 3, 2018
Messages
2,178
Trophies
1
Age
42
XP
3,259
Country
United States
When I tried filling the furthest areas to treat it like 6x (4A19C-4A1A7 for example) I got crashes. Maybe there's some valid values to put there but I didn't play with it further for now. So according to your account this is generating an incomplete matrix but it works fine when pasted over the default in the right position (i.e. the center), with these leftmost and rightmost slots occupied by the default 0s. I don't need those slots for the current simple formula but it could open up more effects to play with.
 
Last edited by Rahkeesh,

Sono

cripple piss
OP
Developer
Joined
Oct 16, 2015
Messages
2,820
Trophies
2
Location
home
XP
9,289
Country
Hungary
When I tried filling the 6x area (4A19C-4A1A7 for example) I got crashes. Maybe there's some valid values to put there but I didn't play with it further for now. So according to your account this is generating an incomplete matrix but it works fine when pasted over the default in the right position (i.e. the center.) I also don't need those slots for the current simple formula but it could open up more effects to play with.

I never had luck with HxD either, hence I made the patcher.

Also, I didn't realize you're not replacing the entire matrix, sorry for that. But sadly for most scaling you have to replace the entire matrix :/

Now that you reminded me, I promised a scale matrix editor for when I'll figure out how to use matrixes. I guess it's time for me to do it? :wacko:

Edit: This is turning out much easier and better than I expected... screw Javascript libraries, VanillaJS is the shit!
759bb927da.png
 
Last edited by Sono,

Site & Scene News

Popular threads in this forum

General chit-chat
Help Users
  • I @ I-need-help-with-wup-wiiu:
    WII U error 105-4069
  • I @ I-need-help-with-wup-wiiu:
    i know this isn't the place but does/did anybody have the same issue as me?
  • AncientBoi @ AncientBoi:
    [louder cricket sounds]
  • SugoiEndeavor @ SugoiEndeavor:
    What's up bakaz
  • RedColoredStars @ RedColoredStars:
    Imagine that. Leo is still active on site.
  • RedColoredStars @ RedColoredStars:
    Sorry, not sorry. But the guy creates his own chaos and I don't believe most everything he has to say about his situations. He has a criminal record and its common for people with those to play the victim to everyone.
    +1
  • RedColoredStars @ RedColoredStars:
    Constantly on web forums complaining about how wronged they have been, instead of taking action and finding actual solutions. Comfortable chaos.
    +2
  • AncientBoi @ AncientBoi:
    As He himself even stated.
  • LeoTCK @ LeoTCK:
    I don't care what you think is "common". I *have* been genuinly wronged.
  • LeoTCK @ LeoTCK:
    @AncientBoi I'm going to outright block you now.
  • AncientBoi @ AncientBoi:
    Pffffft sending me a PM stating we're all a bunch a mean azzholes :creep:. Same here DUDE :angry:
  • AncientBoi @ AncientBoi:
    How SAD you are. So SAD you'll stay ☹️
  • LeoTCK @ LeoTCK:
    butthurt aren't ya? can't stand the truth
  • RedColoredStars @ RedColoredStars:
    Leo, please seek professional mental health help. its not a knock on you. I suffer from mental illness too. You need some help, man.
    +2
  • DinohScene @ DinohScene:
    ^ that's some honest internet advise
    +1
  • LeoTCK @ LeoTCK:
    No...I need help to resolve this situation. MOTHERFUCKER
  • LeoTCK @ LeoTCK:
    putting me into a shrink is not going to help anyone but *THEM*
  • RedColoredStars @ RedColoredStars:
    Poor Leo. Everyone out to harm you.
  • LeoTCK @ LeoTCK:
    yes see? the fault is within you
  • SylverReZ @ SylverReZ:
    @RedColoredStars, Same here, I struggle too. Its highly suggested to maybe take a break from the site just to calm down.
  • LeoTCK @ LeoTCK:
    and ones like yuou
  • LeoTCK @ LeoTCK:
    so leave me alone and stop sending me pms
  • LeoTCK @ LeoTCK:
    you started
    LeoTCK @ LeoTCK: you started