RetroPie forum home
    • Recent
    • Tags
    • Popular
    • Home
    • Docs
    • Register
    • Login

    Would you like to play Nokia (J2ME) games on Retropie?

    Scheduled Pinned Locked Moved Ideas and Development
    sdlemulatorawesome
    304 Posts 22 Posters 146.5k Views
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • recompileR
      recompile @Hex
      last edited by

      @hex said in Would you like to play Nokia (J2ME) games on Retropie?:

      I downloaded a game with landscape resolution and it still displays as portrait

      I have a few games like that. Rotating the image, however, won't make any difference. From the games perspective, nothing has changed.

      The only way to tell the game that the device is on its side is to change the resolution. J2ME doesn't have a concept of 'orientation'. As I explained above, games that want to watch for orientation changes must override the Displayable sizeChanged method and infer orientation based on changes to the display resolution.

      If you're running a game in 240x320, and the game expects landscape, the only way to change that is to change the resolution to 320x240.

      I appreciate that it's easy to add rotation, but it's not going to add any value. Remember, the game has no idea that the image is being rotated. You can see this for yourself by rotating frames from J 90 degrees. If the game was in portrait, it will still be in portrait, just rotated 90 degrees. Running a landscape game in 240x320 rotated 90 degrees will still look the same, it'll just be on its side.

      1 Reply Last reply Reply Quote 0
      • HexH
        Hex
        last edited by Hex

        @recompile I have got all events to be binary now including the joysticks. I will tidy up the code and let you know once it is ready.

        I will be testing the rotation too. Now that i have a sample if it works then its in as a feature else i will just discard that code.

        Sent from 20,000 leagues under the sea.

        Powersaver Emulation station : https://github.com/hex007/EmulationStation
        ES dev script : https://github.com/hex007/es-dev/blob/master/es-tests.sh

        recompileR 1 Reply Last reply Reply Quote 0
        • recompileR
          recompile @Hex
          last edited by

          @hex Out of curiosity, what is the game you want rotated?

          1 Reply Last reply Reply Quote 0
          • HexH
            Hex
            last edited by Hex

            @recompile Asphalt6 (480x800)

            Rotation is proving to be much difficult that anticipated. Working on this till I get controller back

            Also I lost the Xbox controller. Cant have it back till the little bro finishes playing Minecraft :|

            Sent from 20,000 leagues under the sea.

            Powersaver Emulation station : https://github.com/hex007/EmulationStation
            ES dev script : https://github.com/hex007/es-dev/blob/master/es-tests.sh

            recompileR 1 Reply Last reply Reply Quote 0
            • recompileR
              recompile @Hex
              last edited by

              @hex I see what you mean now. Rotation makes sense for those cases.

              1 Reply Last reply Reply Quote 0
              • HexH
                Hex
                last edited by

                @recompile Can we change the parameter to not need the file:// part ?

                So you could have -f ./Asphalt6.jar
                else -u http://.....

                Sent from 20,000 leagues under the sea.

                Powersaver Emulation station : https://github.com/hex007/EmulationStation
                ES dev script : https://github.com/hex007/es-dev/blob/master/es-tests.sh

                recompileR 1 Reply Last reply Reply Quote 0
                • recompileR
                  recompile @Hex
                  last edited by

                  @hex Probably, but the only people who will see it are you and I. Everyone else will launch games from ES. Are you just looking to use relative paths, or are you just sick of typing the whole path every time?

                  1 Reply Last reply Reply Quote 0
                  • HexH
                    Hex
                    last edited by

                    @recompile Sick of typing. File:// does not auto complete so while trying different games for testing i have to copy paste or type very carefully. defeats the purpose of running it from terminal.

                    suggested changes would be much better. Very few will leverage "-u" option anyways so it will make testing easier.

                    Sent from 20,000 leagues under the sea.

                    Powersaver Emulation station : https://github.com/hex007/EmulationStation
                    ES dev script : https://github.com/hex007/es-dev/blob/master/es-tests.sh

                    recompileR 1 Reply Last reply Reply Quote 0
                    • recompileR
                      recompile @Hex
                      last edited by

                      @hex I just use a shell script:

                      #!/bin/sh
                      java -jar freej2me-rpi.jar file:/home/pi/RetroPie/roms/j2me/ShadoWalker.jar 240 320
                      

                      I have nine or so named like test.sh, test2.sh, nokia.sh, etc. for whatever I'm looking to check at the moment. It saves a lot of time and typing.

                      Also, pressing up on the command line will scroll through previous commands. Very handy.

                      I like simple.

                      1 Reply Last reply Reply Quote 0
                      • HexH
                        Hex
                        last edited by

                        Can it be please modified to take shell paths like /home/hex/a.jar or ./a.jar or a.jar

                        Syntax wise I am thinking this

                        java -jar freej2me.jar file/url W H [-r 90] [-i interpolation]

                        Sent from 20,000 leagues under the sea.

                        Powersaver Emulation station : https://github.com/hex007/EmulationStation
                        ES dev script : https://github.com/hex007/es-dev/blob/master/es-tests.sh

                        recompileR 1 Reply Last reply Reply Quote 0
                        • recompileR
                          recompile @Hex
                          last edited by

                          @hex Yes, but it adds a lot of unnecessary complexity, can be very fragile, and still ambiguous. Is the path intended to be relative to the current working directory or the location of the jar file?

                          I like simple. I see this as adding complexity without adding any value.

                          Simplicity is actually the reason why it takes a url instead of a 'normal' path. It was simpler to implement and required less code.

                          To your specific problem: It looks like you just want to reference a file in the current directory. Here's how you do that:

                          java -jar freej2me.jar file:./a.jar
                          

                          @hex said in Would you like to play Nokia (J2ME) games on Retropie?:

                          Syntax wise I am thinking this

                          That's fine. How do you want to receive it on the C side? Just W H R I?

                          1 Reply Last reply Reply Quote 0
                          • HexH
                            Hex
                            last edited by Hex

                            @recompile Got xbox controller back. Updated C sources. Check it out and let me know if it works as expected or creates any unexpected errors.

                            Sent from 20,000 leagues under the sea.

                            Powersaver Emulation station : https://github.com/hex007/EmulationStation
                            ES dev script : https://github.com/hex007/es-dev/blob/master/es-tests.sh

                            1 Reply Last reply Reply Quote 0
                            • HexH
                              Hex
                              last edited by Hex

                              @recompile said in Would you like to play Nokia (J2ME) games on Retropie?:

                              That's fine. How do you want to receive it on the C side? Just W H R I?

                              W H I [R]

                              R is optional

                              @recompile said in Would you like to play Nokia (J2ME) games on Retropie?:

                              Is the path intended to be relative to the current working directory or the location of the jar file?

                              Always relative to working directory

                              ~/ > ls
                              --> jsdl/    games/    music/    videos/     roms/
                              
                              ~/ > java -jar jsdl/freej2me.jar games/Asphalt.jar W H 
                              

                              Sent from 20,000 leagues under the sea.

                              Powersaver Emulation station : https://github.com/hex007/EmulationStation
                              ES dev script : https://github.com/hex007/es-dev/blob/master/es-tests.sh

                              1 Reply Last reply Reply Quote 0
                              • recompileR
                                recompile
                                last edited by recompile

                                @Hex A couple things:

                                Most importantly, it doesn't compile on my pi3.

                                sdl_interface.cpp: In function ‘void removeJoystick(SDL_JoystickID)’:
                                sdl_interface.cpp:60:10: error: ‘axisIt’ does not name a type
                                    auto axisIt = mPrevAxisValues.find(joyId);
                                         ^
                                sdl_interface.cpp:61:14: error: ‘axisIt’ was not declared in this scope
                                    delete[] axisIt->second;
                                             ^
                                sdl_interface.cpp:65:10: error: ‘joyIt’ does not name a type
                                    auto joyIt = mJoysticks.find(joyId);
                                         ^
                                sdl_interface.cpp:66:8: error: ‘joyIt’ was not declared in this scope
                                    if(joyIt != mJoysticks.end())
                                       ^
                                

                                Still important, it's over-complicated. You've made things more difficult for yourself.

                                Why are you storing the previous axis value and not the previous normalized value? It makes things much more complicated than they need to be. By storing the normalized value, you won't need 'deadzone' at all. Try something like this:

                                // Normalize
                                normValue = 0; 
                                if(event.jaxis.value > 0)
                                {
                                   normValue = 1;
                                }
                                else if (event.jaxis.value < 0)
                                {
                                     normValue = -1;
                                }
                                

                                Next, you can compare your normalized values to the ones previously stored. How you store them is up to you, but it will affect how you compare them later.

                                Keeping things similar to how you're doing things already, let's assume you'll store them like this after the compare:

                                mPrevAxisValues[event.jaxis.which][event.jaxis.axis] = normValue; 
                                

                                Comparing the old value to the new value to send pressed and released events:

                                // Remember that the UD axis is 0, LR is 1 
                                // axisShift will let us pack UDLR neatly in to the event key value
                                // resulting i: UP - 8, Down - 4, Left - 2, Right - 1
                                axisShift = event.jaxis.axis * 2;
                                
                                oldValue = mPrevAxisValues[event.jaxis.which][event.jaxis.axis];
                                if(oldValue != normValue)
                                {
                                    // DPad Button Released
                                    if(oldValue ==   1) { sendKey(4, 2<<axisShift); } // Up, Left
                                    if(oldValue ==  -1) { sendKey(4, 1<<axisShift); } // Down, Right
                                    // DPad Button Pressed
                                    if(normValue ==  1) { sendKey(5, 2<<axisShift); } // Up, Left
                                    if(normValue == -1) { sendKey(5, 1<<axisShift); } // Down, Right
                                }
                                

                                My example uses a simplified Send Key:

                                void sendKey(int eventType, int key)
                                {
                                 unsigned char bytes [5];
                                 bytes[0] = (char) eventType;
                                 bytes[1] = (char) (key >> 24);
                                 bytes[2] = (char) (key >> 16);
                                 bytes[3] = (char) (key >> 8);
                                 bytes[4] = (char) (key);
                                 fwrite(&bytes, sizeof(char), 5, stdout);
                                }
                                

                                Smaller is not always better. I tend to put readability over compactness. I've never regretted those decisions, but I have lots of regrets related to those times when I put compactness over readability.

                                HexH 1 Reply Last reply Reply Quote 0
                                • HexH
                                  Hex
                                  last edited by Hex

                                  @recompile You can use this flag while compiling -std=c++11. My gcc supports is automatically. On pi you might need to add that flag.

                                  I copied code from ES. Even if i changed it later the output would remain same hence i did not optimize then (2am)

                                  void sendKey(int key, bool pressed, bool joystick)
                                  {
                                  	unsigned char bytes [5];
                                  	bytes[0] = (char) 2 * joystick + pressed;
                                  

                                  Is quite self explanatory

                                  Byte shifting is not easily visualisable for me.

                                  I shall make the changes but I will keep the send key. I am thinking of changing the following line

                                  bytes[0] = (char) 2 * joystick + pressed;
                                  to
                                  bytes[0] = (char) (joystick << 16) + pressed;

                                  so we have
                                  00,01,10,11

                                  Should that be ok?

                                  Sent from 20,000 leagues under the sea.

                                  Powersaver Emulation station : https://github.com/hex007/EmulationStation
                                  ES dev script : https://github.com/hex007/es-dev/blob/master/es-tests.sh

                                  1 Reply Last reply Reply Quote 0
                                  • HexH
                                    Hex
                                    last edited by

                                    @recompile said in Would you like to play Nokia (J2ME) games on Retropie?:

                                    Why are you storing the previous axis value and not the previous normalized value? It makes things much more complicated than they need to be. By storing the normalized value, you won't need 'deadzone' at all. Try something like this:

                                    deadzone will always be needed as it is a cutoff threshold. If we dont have a cutoff even slight movement of analog stick will spew unnecessary events.

                                    Sent from 20,000 leagues under the sea.

                                    Powersaver Emulation station : https://github.com/hex007/EmulationStation
                                    ES dev script : https://github.com/hex007/es-dev/blob/master/es-tests.sh

                                    recompileR 1 Reply Last reply Reply Quote 0
                                    • HexH
                                      Hex @recompile
                                      last edited by

                                      @recompile said in Would you like to play Nokia (J2ME) games on Retropie?:

                                      // DPad Button Released
                                      if(oldValue ==   1) { sendKey(4, 2<<axisShift); } // Up, Left
                                      if(oldValue ==  -1) { sendKey(4, 1<<axisShift); } // Down, Right
                                      // DPad Button Pressed
                                      if(normValue ==  1) { sendKey(5, 2<<axisShift); } // Up, Left
                                      if(normValue == -1) { sendKey(5, 1<<axisShift); } // Down, Right
                                      

                                      I dont understand why you are ending 4 and 5

                                      Sent from 20,000 leagues under the sea.

                                      Powersaver Emulation station : https://github.com/hex007/EmulationStation
                                      ES dev script : https://github.com/hex007/es-dev/blob/master/es-tests.sh

                                      1 Reply Last reply Reply Quote 0
                                      • HexH
                                        Hex
                                        last edited by

                                        @recompile I have updated the source. Can you update it.

                                        To compile :
                                        g++ -std=c++11 -lSDL2 -lpthread -o sdl_interface sdl_interface.cpp

                                        Sent from 20,000 leagues under the sea.

                                        Powersaver Emulation station : https://github.com/hex007/EmulationStation
                                        ES dev script : https://github.com/hex007/es-dev/blob/master/es-tests.sh

                                        1 Reply Last reply Reply Quote 0
                                        • recompileR
                                          recompile @Hex
                                          last edited by

                                          @hex said in Would you like to play Nokia (J2ME) games on Retropie?:

                                          deadzone will always be needed as it is a cutoff threshold. If we dont have a cutoff even slight movement of analog stick will spew unnecessary events.

                                          Take a second look at what I've sent. By comparing the normalized values, and sending events only on change, we won't send needless events on, for example, a change of -29087 to -18542 (which is what you're deadzone is trying to avoid) as we'll instead be comparing -1 to -1 and seeing no change.

                                          @hex said in Would you like to play Nokia (J2ME) games on Retropie?:

                                          I dont understand why you are ending 4 and 5

                                          We had used 1 and 0 as the event type for key pressed/released, 3 and 2 for gamepad button pressed/released. 5 and 4 for dpad pressed/released seemed to follow.

                                          @hex said in Would you like to play Nokia (J2ME) games on Retropie?:

                                          I shall make the changes but I will keep the send key. I am thinking of changing the following line
                                          bytes[0] = (char) 2 * joystick + pressed;
                                          to
                                          bytes[0] = (char) (joystick << 16) + pressed;
                                          so we have
                                          00,01,10,11

                                          That doesn't make any sense to me as (char) (joystick << 16) + pressed is identical to (char) pressed . It also won't result in the values you suggest. you'll get on 0 or 1.

                                          1 Reply Last reply Reply Quote 0
                                          • HexH
                                            Hex
                                            last edited by Hex

                                            @recompile said in Would you like to play Nokia (J2ME) games on Retropie?:

                                            // Normalize
                                            normValue = 0;
                                            if(event.jaxis.value > 0)
                                            {
                                            normValue = 1;
                                            }
                                            else if (event.jaxis.value < 0)
                                            {
                                            normValue = -1;
                                            }

                                            This is flawed. At rest my event.jaxis.value is 0. Which is okay. When analog stick is moved slightly event.jaxis.value will not be 0 and trigger an event as it transitions from 0 to 1 or -1 (normalized). We dont want that. It should be a lot of movement before event gets registered. else you will end up with over sensitive response. Get it?


                                            @recompile said in Would you like to play Nokia (J2ME) games on Retropie?:

                                            We had used 1 and 0 as the event type for key pressed/released, 3 and 2 for gamepad button pressed/released. 5 and 4 for dpad pressed/released seemed to follow.

                                            What i wanted here was to have a separate joystick(gamepad) or keyboard and pressed or released. Dpad is a pard of game controller. So in byte form we can either have
                                            00, 01, 02, 03 for combination of 2 bools or
                                            00, 01, 10, 11 either of them is fine.


                                            @recompile said in Would you like to play Nokia (J2ME) games on Retropie?:

                                            That doesn't make any sense to me as (char) (joystick << 16) + pressed is identical to (char) pressed

                                            From above if I have two{a,b} bools {0,1} and I want to get {00, 01, 02, 03} I am doing
                                            2 * a + b

                                            What should i do with bit shifting if I want {00,01,10,11} ? probably 4 rather than 16 :|
                                            (a << 4) + b

                                            Edit : Here is the hexadecimal o/p

                                            00000000: 0140 0000 4f  .@..O   // keyboard Press
                                            00000005: 0040 0000 4f  .@..O   // Kb release
                                            0000000a: 1100 0000 c7  .....   // Joystick press
                                            0000000f: 1000 0000 c8  .....   // Js release
                                            

                                            Sent from 20,000 leagues under the sea.

                                            Powersaver Emulation station : https://github.com/hex007/EmulationStation
                                            ES dev script : https://github.com/hex007/es-dev/blob/master/es-tests.sh

                                            recompileR 1 Reply Last reply Reply Quote 0
                                            • First post
                                              Last post

                                            Contributions to the project are always appreciated, so if you would like to support us with a donation you can do so here.

                                            Hosting provided by Mythic-Beasts. See the Hosting Information page for more information.