• HomeBoards
  • RulesRules
  • HelpHelp
  • WikiWiki
  • Donate

Author Topic: Adding rom shortcuts to the homescreen  (Read 15797 times)

raygan (OP)

  • Posts: 158
    • I'm on Twitter and stuff...
Adding rom shortcuts to the homescreen
« on: August 21, 2014, 10:56:16 pm »
I've long wanted a way to add individual games to the GMenu2x home screen, so that I can select and jump directly into my favorite emulated titles without having to first launch an emulator, scroll through a roms list, and choose the rom I am looking for.

I finally realized that at least in some cases, I could use a shell script and the opkrun command to achieve this. I thought I'd share what I did in case someone has any ideas on how I could improve the process.



I've just created a quick one-liner shell script on my Zero that looks like this:

Quote
#!/bin/sh

opkrun /media/data/apps/PocketSNES-20140821.opk /media/data/local/home/roms/SNES/Earthbound.smc

and then used the standard gmenu2x controls to add a home screen section and add a short cut to that script. When I run it it launches directly in to the game.

So far I have only had success with this with SNES roms. I also tried it with FCEUX for NES games, and while I can run the shell script from telnet with gmenu2x disabled and it works fine, if I run it from a gmenu2x homescreen shortcut it seems to crash on launch. I haven't tried with any other emulators yet.

My shell script and linux knowledge is pretty minimal, so I hoped that perhaps someone else here would be able to improve on this idea. Eventually I'd love to see a system-wide standardized way to add rom links to the home screen, but I'd imageine that's a non-trivial feature addition for gmenu2x.


Edit: This should work with any emulator that either uses the gMenu2x file selector or accepts roms as command line arguments. If an emulator uses its own file browser it may or may not work with this method. For example, ohBoy can not launch roms in this way.
« Last Edit: August 22, 2014, 09:31:14 pm by raygan »

CSX

  • Posts: 59
Re: Adding rom shortcuts to the homescreen
« Reply #1 on: August 22, 2014, 04:57:45 pm »
Thank you! Very clever, I feel ashamed, that I didn't know about opkrun. I will give it a try after holidays (25th) and will try to find a way to run NES games from shell script.

Whilst I'm without laptop, could you try to take path to rom in double quotes?
Code: [Select]
opkrun /media/data/apps/PocketSNES-20140821.opk "/media/data/local/home/roms/SNES/Earthbound.smc"
Maybe it will help?

CSX

  • Posts: 59
Re: Adding rom shortcuts to the homescreen
« Reply #2 on: August 22, 2014, 05:06:54 pm »
Well, I had chance to check it. It doesn't work. Looks like the application with new file selectors can use it, applications with their own fileselectors can't.

raygan (OP)

  • Posts: 158
    • I'm on Twitter and stuff...
Re: Adding rom shortcuts to the homescreen
« Reply #3 on: August 22, 2014, 05:36:56 pm »
The strange thing is that Fceux does work with this if you start by launching Terminal and then run the script from telnet. For example this script:

Code: [Select]
#! /bin/sh

opkrun /media/data/apps/fceux.opk /media/data/home/roms/NES/Mega\ Man\ 2.nes

exit

Works fine and launches right into Mega Man 2 if I run it from telnet after first selecting Terminal on the Zero. But if I run it while GMenu2x is running it doesn't work, no matter if I run it from a shortcut or from telnet. It seems to be getting hung up on the "Initializing Video" step. I think if I could add something to the script to stop gmenu2x and THEN run the emulator, it would probably work, but I don't know how to do this. "killall gmenu2x" just relaunches gmenu2x, I assume because it's set to restart in the event of a crash.

Surkow

  • * Administrator
  • Posts: 690
Re: Adding rom shortcuts to the homescreen
« Reply #4 on: August 22, 2014, 06:00:45 pm »
Some applications feature a built in file selector _and_ a commandline option to load roms. While others only offer one or the other. The GMenu2x file selector simply makes use of the commandline option to load roms.

pcercuei

  • Posts: 1708
    • My devblog
Re: Adding rom shortcuts to the homescreen
« Reply #5 on: August 22, 2014, 06:27:44 pm »
@raygan, only one application can use the screen at a time. So if you want to run a graphical app from telnet or SSH, use the Terminal link first. In your case, your script does not launch from gmenu2x because it's broken. You have a space after the #! that's why it won't work.

CSX

  • Posts: 59
Re: Adding rom shortcuts to the homescreen
« Reply #6 on: August 22, 2014, 06:46:41 pm »
@pcercuei

Ahhh!!! Only one application can use screen! I've been testing it from SSH =)

Now it works and now it's awesome! Thank you! What is the requirements for menu icons?

ruffnutts

  • Posts: 2654
Re: Adding rom shortcuts to the homescreen
« Reply #7 on: August 22, 2014, 08:07:05 pm »
I do like the idea of launching the roms from Gmenu2x home screen ;D

pcercuei

  • Posts: 1708
    • My devblog
Re: Adding rom shortcuts to the homescreen
« Reply #8 on: August 22, 2014, 08:56:10 pm »


What is the requirements for menu icons?
32x32 PNG

raygan (OP)

  • Posts: 158
    • I'm on Twitter and stuff...
Re: Adding rom shortcuts to the homescreen
« Reply #9 on: August 22, 2014, 09:16:23 pm »
@raygan In your case, your script does not launch from gmenu2x because it's broken. You have a space after the #! that's why it won't work.

Thanks, you were absolutely right. I also found that I should have omitted the "exit" at the end, at least in the case of fceux. So an updated working example is like this:
Code: [Select]
#!/bin/sh

opkrun /media/data/apps/fceux.opk /media/data/local/home/roms/NES/Mega\ Man\ 2.nes

A few tips: If you don't want to spend all day making little 32x32 pngs for your favorite games, I've found it's usually pretty easy to do a google image search for the game's name and use their search tools to restrict to exactly 32x32. Giving it the same name as your script makes GMenu2x automatically discover it and saves you a step. Also, for some reason, I've found GMenu2x doesn't like script files with spaces in the name.

Yertle

  • !
  • Posts: 395
Re: Adding rom shortcuts to the homescreen
« Reply #10 on: August 22, 2014, 09:21:58 pm »
Very cool! I was wondering if this was possible. Thank you for sharing!

ruffnutts

  • Posts: 2654
Re: Adding rom shortcuts to the homescreen
« Reply #11 on: August 26, 2014, 08:42:39 am »
So does this work for all emulators now? ;D

raygan (OP)

  • Posts: 158
    • I'm on Twitter and stuff...
Re: Adding rom shortcuts to the homescreen
« Reply #12 on: August 26, 2014, 03:44:15 pm »
I haven't tested with everything but theoretically it should work with all emulators that use the gMenu2x file browser, and may also work with others if they support launching roms from the command line.

Anubis

  • Posts: 35
Re: Adding rom shortcuts to the homescreen
« Reply #13 on: August 28, 2014, 05:28:03 pm »
I can't seem to get a single script to run. If I ssh into the GCW and copy paste the exact command line on the script it runs just fine (although I have to ctrl + c before it does, which I find weird).

Here's the script I'm using:

Quote
#!/bin/sh

opkrun /media/data/apps/regba-1.45.5.opk "/media/GCW/roms/gba/Boktai - The Sun Is in Your Hand (Hack).zip"

Both paths are correct.

raygan (OP)

  • Posts: 158
    • I'm on Twitter and stuff...
Re: Adding rom shortcuts to the homescreen
« Reply #14 on: August 28, 2014, 06:23:11 pm »
Try again without the quotes around the path to the rom, and instead using \ to escape the space characters. For example, this works for me:

Code: [Select]
#!/bin/sh

opkrun /media/data/apps/regba-1.45.5.opk /media/data/local/home/roms/GBA/Astro\ Boy\ -\ Omega\ Factor.gba

Also, make sure you don't put any spaces at all in the filename for your script. I'm not sure why, but gMenu2x won't launch a script for me if it has a space in the name.

Anubis

  • Posts: 35
Re: Adding rom shortcuts to the homescreen
« Reply #15 on: August 28, 2014, 06:46:44 pm »
Try again without the quotes around the path to the rom, and instead using \ to escape the space characters. For example, this works for me:

Code: [Select]
#!/bin/sh

opkrun /media/data/apps/regba-1.45.5.opk /media/data/local/home/roms/GBA/Astro\ Boy\ -\ Omega\ Factor.gba

Also, make sure you don't put any spaces at all in the filename for your script. I'm not sure why, but gMenu2x won't launch a script for me if it has a space in the name.

I tried that earlier today, and it didn't work either, just flashed the screen.

EDIT: It's not a problem with the script placement because it doesn't work neither on the sd or the internal, and it's not a problem with the rom file name since I just renamed it to boktai.zip and it still doesn't load.

EDIT 2: Not even a script as simple as "opkrun /media/data/apps/race.opk" works, I don't get it.

EDIT 3: Booting terminal on the GCW and running the script through ssh works just fine, I do however have to call "sh ./script.sh" instead of just calling the script name, is that normal?
« Last Edit: August 29, 2014, 01:33:00 am by Anubis »

CSX

  • Posts: 59
Re: Adding rom shortcuts to the homescreen
« Reply #16 on: August 29, 2014, 09:38:23 am »
You need to make the script executable:

chmod +x /path/to/the/script.sh

Anubis

  • Posts: 35
Re: Adding rom shortcuts to the homescreen
« Reply #17 on: August 29, 2014, 01:08:37 pm »
You need to make the script executable:

chmod +x /path/to/the/script.sh

Still doesn't work:

https://www.dropbox.com/s/fp4ofvgpjq956us/Screenshot%202014-08-29%2014.07.34.png?dl=0

Anubis

  • Posts: 35
Re: Adding rom shortcuts to the homescreen
« Reply #18 on: October 20, 2014, 10:13:23 pm »
If anyone ever has the same problem I had, removing the #!/bin/sh line fixed it for me somehow. So... yeah...

zear

  • * Moderator
  • Posts: 2381
Re: Adding rom shortcuts to the homescreen
« Reply #19 on: October 20, 2014, 10:28:24 pm »
If anyone ever has the same problem I had, removing the #!/bin/sh line fixed it for me somehow. So... yeah...
You're never supposed to do that. You just turned a script into a useless text file. It works on older firmwares by an accident due to launching every OPK via /bin/sh anyway. This has changed in newer firmwares and it won't work anymore without a proper script header.

If the header line didn't work for you, it hints me to a conclusion you edited the file on Windows and saved with Windows style line breaks, essencially turning it into a single long line when opened on Linux (GCW0). Save this file with Unix line breaks (ie. using Notepad++).

 

Post a new topic
Post a new topic