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

    Commander X16 emulator Install Script

    Scheduled Pinned Locked Moved Ideas and Development
    commanderx16x16emulator
    21 Posts 4 Posters 2.8k 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.
    • F
      fadingrose @JimmyDansbo
      last edited by

      @JimmyDansbo That's brilliant thank you

      I did add to the script for the emulator process to be killed with a key combination and chose ctrl and x as a test at first so i could kill it whilst the emulator is running but my Proxmox vm decided using ctrl is a no no so i switched the keys to a and delete but still no change and no killing of emulator and just not got round to testing it on a pi though.

      Just for clarification here was my change

      #!/usr/bin/env bash
      
      rp_module_id="x16"
      rp_module_desc="Commander X16 Emulator"
      rp_module_help="ROM Extensions: .prg .bin .x16\n\nCopy your Commander X16 programs to \$romdir/x16"
      rp_module_licence="https://github.com/X16Community/x16-emulator/blob/master/LICENSE"
      rp_module_repo="git https://github.com/X16Community/x16-emulator.git"
      rp_module_section="exp"
      rp_module_flags="dispmanx"
      
      function depends_x16() {
          local depends=(build-essential libsdl2-dev libreadline-dev libpng-dev zlib1g-dev)
          getDepends "${depends[@]}"
      }
      
      function sources_x16() {
          gitPullOrClone
      }
      
      function build_x16() {
          make clean
          make -j$(nproc) || error "Build failed"
      
          if [[ ! -f "$md_build/x16emu" ]]; then
              error "x16emu binary not found, build might have failed"
          fi
      
          md_ret_require="$md_build/x16emu"
      }
      
      function install_x16() {
          md_ret_files=(
              'x16emu'
              'LICENSE'
              'README.md'
          )
      
          cat > "$md_inst/x16-launch.sh" << '_EOF_'
      #!/bin/bash
      
      # Get PRG file (first argument passed to the script)
      PRG_FILE="$1"
      
      DIRNAME=$(dirname "$PRG_FILE")
      SUFFIX=$(basename "$PRG_FILE" | rev | tr '.' ' ' | awk '{print $1}' | rev)
      
      # BIOS path resolved using the current user's home
      BIOS_PATH="$HOME/RetroPie/BIOS/x16/rom.bin"
      
      # Check for PRG and ROM existence
      if [[ -z "$PRG_FILE" ]]; then
          echo "Usage: $0 path_to_game.prg" >&2
          exit 1
      fi
      
      if [[ ! -f "$BIOS_PATH" ]]; then
          echo "Missing rom.bin at $BIOS_PATH" >&2
          exit 1
      fi
      
      # Find x16emu binary relative to this script
      SCRIPT_DIR="$(dirname "$0")"
      
      # Launch emulator in background
      if [ "$SUFFIX" = "img" ]; then
          "$SCRIPT_DIR/x16emu" -joy1 -joy2 -fullscreen -rom "$BIOS_PATH" -sdcard "$PRG_FILE" -bas "$SCRIPT_DIR/sdlaunch.txt" &
      else
          "$SCRIPT_DIR/x16emu" -joy1 -joy2 -fullscreen -rom "$BIOS_PATH" -fsroot "$DIRNAME" -prg "$PRG_FILE" -run &
      fi
      
      EMU_PID=$!
      
      (
          stty -echo -icanon time 0 min 0
          trap "kill $EMU_PID; reset; exit" INT TERM
      
          a_pressed=false
      
          while true; do
              read -rsn1 key1
              if [[ "$key1" == 'a' ]]; then
                  a_pressed=true
              elif [[ "$key1" == $'\x7F' && "$a_pressed" == true ]]; then
                  kill "$EMU_PID"
                  break
              fi
              sleep 0.1
          done
          reset
      ) &
      
      wait $EMU_PID
      reset
      exit 0
      _EOF_
      
          cat > "$md_inst/sdlaunch.txt" << '_EOF_'
      LOAD"*",8
      RUN
      _EOF_
      
          chmod +x "$md_inst/x16-launch.sh"
      }
      
      function configure_x16() {
          mkRomDir "x16"
      
          local launch_prefix
          isPlatform "kms" && launch_prefix=""
      
          # Create BIOS path if needed
          if [[ ! -d "$biosdir/x16" ]]; then
              mkdir -p "$biosdir/x16"
          fi
          chown -R $user:$user "$biosdir/x16"
      
          if [[ "$md_mode" == "install" ]]; then
              mkUserDir "$md_conf_root/x16"
              mkUserDir "$md_conf_root/x16/$md_id"
              moveConfigFile "$home/.$md_id" "$md_conf_root/x16/$md_id"
          fi
      
          addEmulator 1 "$md_id" "x16" "$launch_prefix$md_inst/x16-launch.sh %ROM%"
          addSystem "x16" "Commander X16" ".prg .bas .basl .img"
      }
      
      

      I will give your repo a test though when i get the chance and if people actually want it that would be great, if not i am sure i will eventually work out the solution for killing it.

      Much appreciated

      J 1 Reply Last reply Reply Quote 0
      • J
        JimmyDansbo @fadingrose
        last edited by

        @fadingrose We were talking on the Commander X16 discord and it seems that there is consensus to let the emulator handle ALT+F4.
        On normal use, that key combination will never reach the emulator, but when running under emulation station, that combination will reach the emulator and I have created a new branch that handles that.

        I am not sure how familiar you are with git, but you just do

        git clone https://github.com/JimmyDansbo/x16-emulator.git
        git checkout alt_f4
        
        F 1 Reply Last reply Reply Quote 0
        • F
          fadingrose @JimmyDansbo
          last edited by

          @JimmyDansbo I have used git briefly for adding minetest maps i created but need to familiarize myself properly with it. Been a bit busy and hectic here so on the weekend i will get back to this and can focus and test.

          That's good though and hopefully if ALT+ F4 are using that will be great for Retropie as users can just exit the emulator with that unless i map the keys to pad buttons and get Retropie to use this.

          ExarKunIvE 1 Reply Last reply Reply Quote 0
          • ExarKunIvE
            ExarKunIv @fadingrose
            last edited by

            @fadingrose

            if memory serves me right all you need to do is change the repo line to this

            rp_module_repo="git https://github.com/X16Community/x16-emulator.git alt_f4"

            i will have to double check that im still half asleep

            RPi3B+ / 200GB/ RetroPie v4.5.14, RPi4 Model B 4gb / 256gb / RetroPie 4.8.2
            RPi5 4gb / 512gb / RetroPie 4.8.9 -Basic
            Maintainer of RetroPie-Extra .

            J 1 Reply Last reply Reply Quote 0
            • J
              JimmyDansbo @ExarKunIv
              last edited by JimmyDansbo

              @ExarKunIv
              I just tried it on the command line and I think that just clones the repository into a different directory name.
              The command line is: git clone -b alt_f4 https://github.com/jimmydansbo/x16-emulator.git

              I am not sure how to add that -b option to the repo line.

              @fadingrose do let me know how you get along during the weekend. If it works with ALT+F4, I will do the pull request against the official emulator and hopefully the rest of the gang will accept it.

              mituM F 3 Replies Last reply Reply Quote 0
              • mituM
                mitu Global Moderator @JimmyDansbo
                last edited by

                @JimmyDansbo said in Commander X16 emulator Install Script:

                I just tried it on the command line and I think that just clones the repository into a different directory name.

                That's ok, but if you put it in the rp_module_repo variable in the scriptmodule, RetroPie will do the right thing (and not literally execute the contents as a command) and clone from the repo then switch to the branch provided in the last parameter. You can even add a 4th parameter to indicate the commit from which the source is built.

                1 Reply Last reply Reply Quote 0
                • F
                  fadingrose @JimmyDansbo
                  last edited by

                  @JimmyDansbo Been rather busy but i had chance to test it. I gave it a test on my Raspberry Pi model 4 and sadly it doesn't do anything under Retropie. I am in the process of re installing and will test again. I did go to test under my proxmox VM but i couldn't figure out how to get Proxmox to let me use alt & f4 to test so i just switched straight to my Pi.

                  Once it finishes i'll re install and do another test

                  1 Reply Last reply Reply Quote 0
                  • F
                    fadingrose @JimmyDansbo
                    last edited by fadingrose

                    @JimmyDansbo A re install and tested and ALT + F4 takes me straight back to the Retropie menu so that works like a charm cheers. Hopefully it will make it into the emulator permanent if the X16 team agree but we can at least know it worked.

                    I'll get working on some documentation soon so anyone using the script will know how to install, run and even use the emulator.

                    1 Reply Last reply Reply Quote 0
                    • F
                      fadingrose
                      last edited by

                      I have updated the description and the script after some testing, it will need further testing by other people and hopefully someone with a Pi5 can give it a test and report back on performance. I will do some further testing on the PI4 using the official Retropie image instead of Retropie through the Debian OS desktop which i'm sure the desktop will take some performance away and see if there is any tricks or anything to squeeze some extra performance.

                      So far though it seems to run ok even if a little sluggish but it's perfectly usable and there isn't any show stopping issues that would consider it broken or anything.

                      J 1 Reply Last reply Reply Quote 0
                      • J
                        JimmyDansbo @fadingrose
                        last edited by

                        @fadingrose In my point of view, Commander X16 on Raspberry Pi 4 and 400 is more or less unusable.
                        A lot of games a depending on the exact speed of the Commander X16 and when it is only running at something lik 60-70% of correct speed, things just don't work as expected, even sound will likely be weird :(
                        Hopefully some performance can be found so we can get closer to 95-100% even on pi4/400.

                        J 1 Reply Last reply Reply Quote 0
                        • J
                          JimmyDansbo @JimmyDansbo
                          last edited by JimmyDansbo

                          I am happy to report that my PR to add handling ALT+F4 to the emulator has just been merged into the official repository.

                          F 1 Reply Last reply Reply Quote 1
                          • F
                            fadingrose @JimmyDansbo
                            last edited by

                            @JimmyDansbo After testing with the official repo i updated the script to point to it and it exits the emulator fine with ALT + F4 so that's perfect. Just need to work out how to squeeze better performance out of the Pi as i only tested a handful of games getting them in game and then closing the emulator.

                            I would say it's on par so far with the Sega Dreamcast, Sega Saturn which means it can be used but it's certainly not ideal and it also depends on a per game basis. I ran a text based adventure on the Pi and it ran ok and completely usable but one of the space games it was sluggish both in game play and sound and was a little distracting from the enjoyment.

                            I'm wracking my brain to figure out what could be done to squeeze a little more performance out of i, even if we got 5/10% extra it would be something although ideal if we can get closer to 95-100%. I'll report back when i find a solution or something.

                            1 Reply Last reply Reply Quote 1
                            • 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.