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

  • Thread starter Sono
  • Start date
  • Views 748,546
  • 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 .

Rahkeesh

Well-Known Member
Member
Joined
Apr 3, 2018
Messages
2,178
Trophies
1
Age
42
XP
3,261
Country
United States
Been playing around more with those outer rows in AGB and it seems like there's just plain numeric limits, which is odd if its the hex editor or repackers fault but I can believe your patching method can circumvent these limits. Its hard to nail down an exact range because it seems to vary by pixel, but if 3x and 4x are the center which actually have values in the default matrix, 2x / 5x seem to be limited to around +/- just under x1000, while 1x / 6x is somewhere under x400. So that would rather limit what you can use these rows for.
 

Sono

cripple piss
OP
Developer
Joined
Oct 16, 2015
Messages
2,821
Trophies
2
Location
home
XP
9,320
Country
Hungary
Been playing around more with those outer rows in AGB and it seems like there's just plain numeric limits, which is odd if its the hex editor or repackers fault but I can believe your patching method can circumvent these limits. Its hard to nail down an exact range because it seems to vary by pixel, but if 3x and 4x are the center which actually have values in the default matrix, 2x / 5x seem to be limited to around +/- just under x1000, while 1x / 6x is somewhere under x400. So that would rather limit what you can use these rows for.

I have never encountered any limits using the patcher, but I had the same issues when doing hex editing. I still have no idea why manually patching bytes crashes, but the patcher patching the exact same bytes works somehow...
 

Alex658

Well-Known Member
Member
Joined
Jun 4, 2010
Messages
1,206
Trophies
1
Age
29
Location
Colombia
XP
1,194
Country
Colombia
Just checked the first post and i am amazed to see how much this has grown, is there an updated version of the first patcher Sono? Or is this all included within TWL menu++?
 
  • Like
Reactions: RocketRobz

Sono

cripple piss
OP
Developer
Joined
Oct 16, 2015
Messages
2,821
Trophies
2
Location
home
XP
9,320
Country
Hungary
Just checked the first post and i am amazed to see how much this has grown, is there an updated version of the first patcher Sono? Or is this all included within TWL menu++?

There will be a new patcher whose only purpose will be to patch an rtcom "bootloader" into TwlBg. This approach should fix the issue where sleep mode isn't working, and also this will allow the patch maker to bundle a custom rtcom version with more flexibility because at that point you wouldn't be limited by the amonut of code space left in TwlBg.cxi to put anything sensible in it.

This is actually a huge deal, because the current rtcom is very limited due to the abysmally small code space available, and also is very slow due to it being tied to the ARM11 framerate (which is VSynced, so it's locked to ~60Hz).

This new approach of being able to override rtcom is a dealbreaker, because the patch maker (or even TWiLightMenu++) can upload a custom rtcom blob at the start which can run on a separate thread, and the communication latency is reduced from 17ms to 1-7ms, and also the graphics shouldn't softlock while ARM11 code is running.

Oh also, because we have more space at runtime than we have in the binary, TWiLightMenu++ could upload an rtcom blob at the start which has a Rosalina-like trainer in it, from where you could apply scale filters (on both axes! screw DMPGL :grog:), patches (screen centering?), and even apply a blue light filter!
And let's not even talk about the other possibilities like button remapping, screen swapping, color-correction LUTs[1], limited SD access[2], or generally just access to the ARM11 hardware[3].

[1] = sadly it's only a LUT, indexed as
color.component = LUT.component[color.component]

[2] = the DS-side code must have support for communicating File IO via rtcom
[3] = some hardware MUST be accessed via functions already existing in TwlBg, or else an undefined behavior caused by race conditions could cause hardware damage (like how I had to hard reset my new3DSXL via MCU after I accidently disabled the gyro because I was writing to it too fast)
 

Rahkeesh

Well-Known Member
Member
Joined
Apr 3, 2018
Messages
2,178
Trophies
1
Age
42
XP
3,261
Country
United States
At Sono's prompting and working within the hex editing limitations I updated my spreadsheet to use the full matrix. This allows for an "unsharp masking" style effect (negative gaussian blur) which might reduce sharpening artifacts. I'm not sure which I like more so I made it optional, you should change it from zero to a value equal to edge sharpening for something close to "normal" guassian blur at theta = 1 but you can fine tune the effect if you want. (So with .5 edge sharpening, use .5 for unsharp masking as a default) In my code.bin I need to paste over 4A19C- 4A1E3, it might be different for you so you can again search for the full default matrix by copying the hex values with everything set to 0.

Google Sheets

Edit: updated the unsharp masking to allow more user control, read above for details.
 

Attachments

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

selcuk

Well-Known Member
Newcomer
Joined
Oct 3, 2015
Messages
83
Trophies
0
Age
33
XP
256
Country
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
wow. just wow. that is awesome. I can't try it tho since I want to use the widescreened agb more than the filtered agb but still pretty cool

--------------------- MERGED ---------------------------

At Sono's prompting and working within the hex editing limitations I updated my spreadsheet to use the full matrix. This allows for an "unsharp masking" style effect (negative gaussian blur) which might reduce sharpening artifacts. I'm not sure which I like more so I made it optional, you should change it from zero to a value equal to edge sharpening for something close to "normal" guassian blur at theta = 1 but you can fine tune the effect if you want. (So with .5 edge sharpening, use .5 for unsharp masking as a default) In my code.bin I need to paste over 4A19C- 4A1E3, it might be different for you so you can again search for the full default matrix by copying the hex values with everything set to 0.

Google Sheets

Edit: updated the unsharp masking to allow more user control, read above for details.
will this work with widescreened agb as well?
 
  • Like
Reactions: Sono

Rahkeesh

Well-Known Member
Member
Joined
Apr 3, 2018
Messages
2,178
Trophies
1
Age
42
XP
3,261
Country
United States
With Sono's widescreen I think filtering does apply but only in one direction. (Vertical?) If you extract code.bin from his agbbg.cxi, or else feed his widescreen patcher a modified agbbg.xci, you might be able to search for the default matrix and overwrite it with stuff from my sheet. Not sure if he coded to disregard the default matrix locations or not.
 

Sono

cripple piss
OP
Developer
Joined
Oct 16, 2015
Messages
2,821
Trophies
2
Location
home
XP
9,320
Country
Hungary
With Sono's widescreen I think filtering does apply but only in one direction. (Vertical?) If you extract code.bin from his agbbg.cxi, or else feed his widescreen patcher a modified agbbg.xci, you might be able to search for the default matrix and overwrite it with stuff from my sheet. Not sure if he coded to disregard the default matrix locations or not.

Yeah, my widescreen patch can only apply on the Y axis, because I didn't do the patches to load the X axis separately (changing the scaling requires entirely new scale kernels).

The widescreen patch initializes the X axis to default values, and duplicates pixels instead of doing "Sono's crisp" due to space limitations.
 

Sono

cripple piss
OP
Developer
Joined
Oct 16, 2015
Messages
2,821
Trophies
2
Location
home
XP
9,320
Country
Hungary
We did it again!

@Gericom has already done WarioWare: Twisted support for GBARunner2 a loooong time ago, but we were missing the proper gyroscope drivers to be able to play it normally.

Well, if you've been following the Rtc3DS repo, you should've noticed that I pushed a few gyro-related commits. I managed to get gyro working on the 2DS and new3DS! It's also possible to use old3DS, but the drivers for that are still work in progress.

I recorded myself playing on my 2DS. I also tried on my new3DSXL, but the 2DS' small weight, and lack of foldability makes this game not only less frustrating to play, but also a lot more fun!

Sorry for the audio issues, but I don't have a microphone input (stupid combo jack :angry:), so you have to put up with the quiet and noisy audio. At least the footage is 1080p60 this time, not 480p24...



If you notice something off about how the gyro works in-game, please quote this post, because while it feels good with the current settings, it might be off from the original game.
 

iGom

Well-Known Member
Newcomer
Joined
Jul 5, 2019
Messages
57
Trophies
0
XP
313
Country
United Kingdom
We did it again!

@Gericom has already done WarioWare: Twisted support for GBARunner2 a loooong time ago, but we were missing the proper gyroscope drivers to be able to play it normally.

Well, if you've been following the Rtc3DS repo, you should've noticed that I pushed a few gyro-related commits. I managed to get gyro working on the 2DS and new3DS! It's also possible to use old3DS, but the drivers for that are still work in progress.

I recorded myself playing on my 2DS. I also tried on my new3DSXL, but the 2DS' small weight, and lack of foldability makes this game not only less frustrating to play, but also a lot more fun!

Sorry for the audio issues, but I don't have a microphone input (stupid combo jack :angry:), so you have to put up with the quiet and noisy audio. At least the footage is 1080p60 this time, not 480p24...



If you notice something off about how the gyro works in-game, please quote this post, because while it feels good with the current settings, it might be off from the original game.
Where can I find patcher for gyro?

Sent from my SM-N960F using Tapatalk
 

Sono

cripple piss
OP
Developer
Joined
Oct 16, 2015
Messages
2,821
Trophies
2
Location
home
XP
9,320
Country
Hungary
Where can I find patcher for gyro?

I think the latest patcher contains the improved rtcom, so you might not need to re-patch TwlBg for now.

Gyro support is uploaded from the DS side, rtcom is only the communication between DS ARM7 and 3DS ARM11.
 

iGom

Well-Known Member
Newcomer
Joined
Jul 5, 2019
Messages
57
Trophies
0
XP
313
Country
United Kingdom
I think the latest patcher contains the improved rtcom, so you might not need to re-patch TwlBg for now.

Gyro support is uploaded from the DS side, rtcom is only the communication between DS ARM7 and 3DS ARM11.
So I used this patcher https://gbatemp.net/index.php?posts/8809166 , the last pre-release of GbaRunner2 https://github.com/Gericom/GBARunner2/releases/tag/v20191228-021638_ee7f6a0 and gyro still doesn't work in Warioware Twisted

Sent from my SM-N960F using Tapatalk


Edit

OK my bad, I didn't notice that it only works on 2DS and N3DSXL, I can confirm that it doesn't work on N2DSXL, but perfectly on O2DS, thanks for your hard work @Sono @Gericom
 
Last edited by iGom,

Sono

cripple piss
OP
Developer
Joined
Oct 16, 2015
Messages
2,821
Trophies
2
Location
home
XP
9,320
Country
Hungary
So I used this patcher https://gbatemp.net/index.php?posts/8809166 , the last pre-release of GbaRunner2 https://github.com/Gericom/GBARunner2/releases/tag/v20191228-021638_ee7f6a0 and gyro still doesn't work in Warioware Twisted

Sent from my SM-N960F using Tapatalk


Edit

OK my bad, I didn't notice that it only works on 2DS and N3DSXL, I can confirm that it doesn't work on N2DSXL, but perfectly on O2DS, thanks for your hard work @Sono @Gericom

Yeah, we had problems with new2DSXL, but I tested on 2DS, new3DSXL, and old3DS, and it works on all 3, except I need to do the drivers for old3DS. No idea why new2DSXL is so broken :/
 

Gericom

Well-Known Member
Member
Joined
Jun 30, 2011
Messages
1,382
Trophies
2
Age
25
XP
4,691
Country
Netherlands
So I used this patcher https://gbatemp.net/index.php?posts/8809166 , the last pre-release of GbaRunner2 https://github.com/Gericom/GBARunner2/releases/tag/v20191228-021638_ee7f6a0 and gyro still doesn't work in Warioware Twisted

Sent from my SM-N960F using Tapatalk


Edit

OK my bad, I didn't notice that it only works on 2DS and N3DSXL, I can confirm that it doesn't work on N2DSXL, but perfectly on O2DS, thanks for your hard work @Sono @Gericom
For me it eventually worked fine on n2dsxl. So not sure what is going on.
 
  • Like
Reactions: Sono

CaioHenrique360

New Member
Newbie
Joined
Dec 30, 2019
Messages
4
Trophies
0
Age
24
XP
55
Country
Brazil
[QUOTE = "Flame, post: 8904268, membro: 130770"] você pode postar em inglês please.we é um fórum de língua inglesa. Existe alguma maneira de automatizar esse processo?Any .cia or a program?
 

Site & Scene News

Popular threads in this forum

General chit-chat
Help Users
    Psionic Roshambo @ Psionic Roshambo: https://www.youtube.com/watch?v=pkYA4rALqEE