Skip to content

3DS Port - #275

Open
Anh302kay wants to merge 2 commits into
SAT-R:mainfrom
Anh302kay:main
Open

Anh302kay wants to merge 2 commits into
SAT-R:mainfrom
Anh302kay:main

Conversation

@Anh302kay

Copy link
Copy Markdown

3DS Port using citro2d for video, and SDL2 for audio. idk if I was supposed put my name in the credits so I didn't do it.

  • Uses a software renderer
  • Compiles into a CIA
  • Banner logos were taken from Google, but it would nice for it to use the logo in the graphics folder, but I didn't know how to convert it into a PNG
  • Sonic Advance 2 tested and works on real hardware
  • Sonic Advance 1 runs, but crashes when it shows stage results during a memcpy on line 608 of stage_results.c
_26 08 26_00 02 54 838 _25 08 26_23 04 34 118 _25 08 26_23 05 04 608 Sonic Advance_26 08 26_00 50 50 575 Sonic Advance_26 08 26_00 50 55 809 Sonic Advance_26 08 26_00 51 02 998

Comment thread src/platform/3ds/3ds.c Outdated
REG_VCOUNT = DISPLAY_HEIGHT + 1; // prep for being in VBlank period
}

static const u16 posToTex[]

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey. Sorry I've not got round to looking at this (and TBH ports are not a priority for this project)

Some questions:

  • Did you use AI for this?
  • What is this array? Why is it needed? You are mapping gba pixels to 3ds pixels, but why do you need a precomputed array for this? (smells of AI)
  • Why does this need to use SDL for sound output? You'd think you could just output audio directly.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hello, apologies for the poor quality of the port.

  • I did not use any AI for this. I was very tempted to for the banner logos to make imagemagick scripts to convert the ones in the graphic folders but it is not allowed.
  • The 3DS stores its textures in a way that requires all textures to be swizzled, and they are not in a simple 1d array. I got the original algorithm for this from here. The array maps pixels so they can be viewed properly on the 3DS. It was originally a function, but I precomputed it into a table with a small separate program to try and improve performance, as the performance was 5-25 fps. I think it had a minimal effect, but when I saw the precomputed table, I realised that the swizzled texture kept pixels together in pairs, so I could map pixels and copy them to the texture in pairs also, which was what ultimately improved performance the most. I can see if there is any noticeable change in performance, and rework the port to reuse the function instead of the precomputed table.
  • I cannot lie, it was just because I was extremely lazy and did not want to touch 3DS audio, because I haven't learnt it(I normally use SDL for audio in my 3DS projects). I can try to learn it, and implement it directly.

I cannot upload the program I made to precompute it so I will just paste it here.

#include <iostream>

static size_t posToTex(size_t index)
{
    const int width = 512;
    const int x = index % 400;
    const int y = index / 400;

    // printf("%i , %i \n", x, y);

    return ((((y >> 3) * (width >> 3) + (x >> 3)) << 6)
            + ((x & 1) | ((y & 1) << 1) | ((x & 2) << 1) | ((y & 2) << 2) | ((x & 4) << 2) | ((y & 4) << 3)));
}

int main(){

for(int i = 0; i < 400*240; i++) {
if(i % 2 == 0)
std::cout << posToTex(i)/2 << ", ";
if(i % 16 == 0) std::cout << "\n";
}


}

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the info. You could just pre-compute this table at start-up if it does have a performance improvement. Having a static array compiled like this is just way to long to keep in source.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just updated it to be computed at start-up. I didn't see any noticeable change in performance, but I measured the speed of the table and the speed of the function using the 3DS' built-in tick counter, and the table was faster by roughly 350 microseconds.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants