?
  1. Just finish it already!

    41.7%
  2. Keep redshift and rtcom only, rest goes to DS side

    8.3%
  3. Just make the exe patcher work on the 3DS, the rest is fine DS-side

    50.0%
  1. Sono

    OP Sono Modern slave; tsundere
    Member

    Joined:
    Oct 16, 2015
    Messages:
    1,971
    Country:
    Hungary
    Based on the 3 filters (1x (START+SELECT), 1.25x (default), and 1.5x (used only in GBA mode)) found inside TWL_FIRM, I reverse engineered most of the image matrix processor hardware, and made my own filters to show that sharp upscaling can be done.

    Edit: since the initial patch, I have been completely nuking DS mode, and have made a lot of discoveries since; including, but not limited to
    • scale matrix patching for a sharper image
    • CTR_Redshift support (blue light filtering in both DS and GBA mode)
    • screen swap for DS mode (the GBA only has a single screen, so it's not swappable)
    • widescreen patching for both DS (256x192 --> 384x240) and GBA (240x160 --> 400x240) mode
    • button remapping (emulated)
    • ARM11 <--> ARM7 communication with rtcom (discovered by @Gericom)


    [​IMG]
    [​IMG]
    [​IMG]
    [​IMG]
    [​IMG]
    [​IMG]
    [​IMG]
    [​IMG]
    [​IMG]
    [​IMG]
    [​IMG]
    [​IMG]

    Edit: the 1.5x patch is not useful anymore (other than for GBARunner2), so I have hidden it in a spoiler below.
    While intensely digging everything TWL_FIRM, I also noticed some inaccessible code (no condition makes it ever jump to the code without patches) which looked to be a scrapped 1.5x upscale mode. And sure enough, hacking the code to always load this secret mode, it does indeed work... sort of. Other than the wonky touchscreen and the weird offsetting, this unused mode seems to be fully functional.


    I can't babysit you thru' this process, so use some Google/Bing/DuckDuckGo to find the resources you need to do this.

    1. mount TWL_FIRM using Godmode9 (SYSNAND CTRNAND /title/00040138/?0000102/content/????????.app (select the one with the biggest number))
    2. go back to the main menu, browse to NCCH GAME IAMGE /exefs/.firm, select it, and copy it to /gm9/out/
    3. copy /gm9/out/.firm to your PC, and rename it to TWL.firm
    4. get firmtool, and unpack the FIRM with firmtool extract TWL.firm
    5. extract section0.bin (it's a cxi)
    6. open exefs/code.bin in a hex editor, and set two bytes at 0xC44 to 02 21
    7. repack exefs.bin with 3dstool -czvtf exefs exefs.bin --exefs-dir exefs --header exefsheader.bin
    8. repack TwlBg.cxi with 3dstool -cvtf cxi TwlBg.cxi --header nccheader.bin --exh exheader.bin --exefs exefs.bin --not-encrypt
    9. put TwlBg.cxi to /luma/sysmodules/TwlBg.cxi
    10. enable game patching and module loading in Luma settings
    11. ??? profit ???

    If you want to try these out without the patcher then you have to manually patch it yourself, because it's illegal to upload copyrighted material (and TWL_FIRM sure does contain copyrighted materials).

    Copypasted from the above spoiler, so sorry if I forgot to edit something.

    I can't babysit you thru' this process, so use some Google/Bing/DuckDuckGo to find the resources you need to do this.

    1. mount TWL_FIRM using Godmode9 (SYSNAND CTRNAND /title/00040138/?0000102/content/????????.app (select the one with the biggest number))
    2. go back to the main menu, browse to NCCH GAME IAMGE /exefs/.firm, select it, and copy it to /gm9/out/
    3. copy /gm9/out/.firm to your PC, and rename it to TWL.firm
    4. get firmtool, and unpack the FIRM with firmtool extract TWL.firm
    5. extract section0.bin (it's a cxi)
    6. open exefs/code.bin in a hex editor, goto 0x4A7F4, and with your eyes search for the pattern 00 00 00 00 00 00 00 40 00 00 00 00
    7. locate your cursor at the end of the pattern (0x4A800 if the pattern was at the above mentioned address), and paste overwrite (CTRL-B in HxD) this pattern
      • 000000000000000000000000000000000000000000000000000000000020004000400040004000200000000000000000000000000000000000000000
    8. repack exefs.bin with 3dstool -czvtf exefs exefs.bin --exefs-dir exefs --header exefsheader.bin
    9. repack TwlBg.cxi with 3dstool -cvtf cxi TwlBg.cxi --header nccheader.bin --exh exheader.bin --exefs exefs.bin --not-encrypt
    10. put TwlBg.cxi to /luma/sysmodules/TwlBg.cxi
    11. enable game patching and module loading in Luma settings
    12. ??? profit ???
    If it hardlocks then you didn't find the right pattern, or your TwlBg version is not good.

    If you want to see all scale matrixes, @Halvorsen has used a capture card to capture how it looks like on real hardware.
    [​IMG]

    [Download]
    [Widescreen patches]

     
    Last edited by Sono, Mar 14, 2020
    SuperDan, ber71, Jowah and 64 others like this.
  2. Dartz150

    Dartz150 Hat Gurl Official Fan™
    Member

    Joined:
    May 5, 2010
    Messages:
    1,902
    Country:
    Mexico
    What makes this different that the current scale method? Does it look better than the blurry and washed out filter that TWL_FIRM normally applies?
     
  3. Sono

    OP Sono Modern slave; tsundere
    Member

    Joined:
    Oct 16, 2015
    Messages:
    1,971
    Country:
    Hungary
    As you can see, the bottom-right of the screen is cut off, because 384x288 is bigger than 320x240. But since that resolution is double of the DS, the image doesn't look blurry.

    Upon closer inspection, there is sadly still interpolation, but because the scaling is integer, the image looks REALLY crisp.
     
    Dartz150 likes this.
  4. Dartz150

    Dartz150 Hat Gurl Official Fan™
    Member

    Joined:
    May 5, 2010
    Messages:
    1,902
    Country:
    Mexico
    I see, and yeah, the main reason behind the blurriness in the standard scaling method is because the scale is not integer and is difficult to get accurate pixel draw with that setup alone.

    The thing is that this opens the possibility of (maybe) implementation or different scaling methods, I remember back in 2015 that someone asked if it was possible to hack different filtering methods and custom frames for native resolution to TWL_FIRM or something like that. Do you think it could be possible?
     
  5. Sono

    OP Sono Modern slave; tsundere
    Member

    Joined:
    Oct 16, 2015
    Messages:
    1,971
    Country:
    Hungary
    I think it should be possible if my observations are correct.

    But even if I could get the scaling removed, the scaling would look absolutely horrible due to how the PICA upscales textures.
     
    Dartz150 likes this.
  6. Sono

    OP Sono Modern slave; tsundere
    Member

    Joined:
    Oct 16, 2015
    Messages:
    1,971
    Country:
    Hungary
    It turns out that LgyFb is actually a matrix unit for scaling images. I found the 3 kernels associated with each upscale mode (1x, 1.25x (default), and 1.5x)

    [​IMG]

    Just by looking at the image, I think you can already see why 1.25x scaling (the default scaling without pressing START+SELECT) looks so horrible. I have no idea what these matrixes are, but it's pretty clear that the 1.25x scaling matrix is doing something weird.
     
    Tarmfot, Dartz150 and Ryccardo like this.
  7. Rahkeesh

    Rahkeesh GBAtemp Maniac
    Member

    Joined:
    Apr 3, 2018
    Messages:
    1,461
    Country:
    United States
    Isn't 1.5x used by AGB_FIRM?

    Awesome that you are digging this stuff up. :yay:
     
    StrayGuitarist and Sono like this.
  8. Sono

    OP Sono Modern slave; tsundere
    Member

    Joined:
    Oct 16, 2015
    Messages:
    1,971
    Country:
    Hungary
    Yeah, I heard that 1.5x is used by AGB_FIRM, but I didn't find any mention of GBA in the binary.
     
  9. SomeGamer

    SomeGamer GBAtemp Guru
    Member

    Joined:
    Dec 19, 2014
    Messages:
    6,776
    Country:
    Antarctica
    No idea why anyone would use this (and why Nintendo left the code in) but can't deny it looks much better than the original.
     
    Sono likes this.
  10. Extrasklep

    Extrasklep gbaTemp Fan
    Member

    Joined:
    Aug 24, 2017
    Messages:
    838
    Country:
    Poland
    is this the secret project?
     
  11. Sono

    OP Sono Modern slave; tsundere
    Member

    Joined:
    Oct 16, 2015
    Messages:
    1,971
    Country:
    Hungary
    According to almost everyone, it might be indeed a leftover from AGB_FIRM. But it's weird, because 3dbrew said somewhere that TwlBg is the same on both TWL_FIRM and AGB_FIRM :/

    Nope, this is "the experiment". The secret project is very far away.
     
    Tarmfot, Dartz150 and SomeGamer like this.
  12. Robz8

    Robz8 Coolest of TWL
    Developer

    Joined:
    Oct 1, 2010
    Messages:
    12,436
    Country:
    United States
    To users following the guide for 1.5x upscaling:
    Depending on what code.bin you have, the original 2 bytes' offset is either 0xC44 or 0xC46.
    The original bytes are "01 29".
     
    Last edited by Robz8, Jul 6, 2019
    Tarmfot, BOBdotEXE, zfreeman and 2 others like this.
  13. Dartz150

    Dartz150 Hat Gurl Official Fan™
    Member

    Joined:
    May 5, 2010
    Messages:
    1,902
    Country:
    Mexico
    Thank you for you explanation, looking forward to your research and what advantages/improvements flourish from it. I Wonder what that secret project may be. I suppose is big, hence it being secret :ninja:
     
    Sono likes this.
  14. LoganK93

    LoganK93 GBAtemp Advanced Fan
    Member

    Joined:
    Dec 5, 2012
    Messages:
    670
    Country:
    United States
    I'm an idiot. Could this ever lead to widescreen on 3DS with DS games? Even if stretched I'd love to finally kill those black bars.
     
  15. Rahkeesh

    Rahkeesh GBAtemp Maniac
    Member

    Joined:
    Apr 3, 2018
    Messages:
    1,461
    Country:
    United States
    At a minimum I'd guess you could swap which is the default and which start/select activates? For people who would prefer the default to be no scaling, for instance.
     
  16. Sono

    OP Sono Modern slave; tsundere
    Member

    Joined:
    Oct 16, 2015
    Messages:
    1,971
    Country:
    Hungary
    Sadly not yet, because the aspect ratio has to match. Once I reverse engineer the image matrix hardware more, it might be possible, but it would require extreme patching due to space limitations, and for that I would have to disable the other scaling modes.

    I'm pretty sure that's a simple one or two byte patch. I'll look into it later.
     
    Robz8, ahezard and zfreeman like this.
  17. Sono

    OP Sono Modern slave; tsundere
    Member

    Joined:
    Oct 16, 2015
    Messages:
    1,971
    Country:
    Hungary
    Aaaaaaaaaaaaaand, I did it! Crispy upscale filter :D

    [​IMG]
    [​IMG]

    It turns out that I was an idiot, and was writing invalid filters into the file which hardlocked everything. That's what I get for manually entering the bytes into a hex editor without a tool autogenerating them for me ¯\_(ツ)_/¯
     
    KoalaBoy, Pickle_Rick, Seriel and 8 others like this.
  18. SomeGamer

    SomeGamer GBAtemp Guru
    Member

    Joined:
    Dec 19, 2014
    Messages:
    6,776
    Country:
    Antarctica
    Nice! You can finally go and actually play the thing... right?
     
  19. Sono

    OP Sono Modern slave; tsundere
    Member

    Joined:
    Oct 16, 2015
    Messages:
    1,971
    Country:
    Hungary
    Yeah uh... I would release the patch, but there is a small problem: TwlBg contains copyrighted material, and it's impossible to patch compressed code without unpacking and repacking it completely.

    My idea is to include a patcher homebrew which dumps TwlBg, unpacks it, patches it, then places it in /luma/sysmodules/TwlBg.cxi, and that way you can even specify your own filters.
    You can do gaussian filters and double vision with this image processing matrix hardware :blink:
     
  20. SomeGamer

    SomeGamer GBAtemp Guru
    Member

    Joined:
    Dec 19, 2014
    Messages:
    6,776
    Country:
    Antarctica
    That'd be the most user-friendly way. IMO you could release some manual patching instructions in the meantime if it isn't a ton of values but it's your call ultimately.
     
Draft saved Draft deleted
Loading...

Hide similar threads Similar threads with keywords - TWPatcher, filters, patches