tmux – The UNIX Screen Multiplexer

tmux is an extremely useful command line utility. It’s a screen multiplexer much like the screen utility. It basically allows you to have as many command line sessions as you like. This is useful for processes and programs that run for a long time rather than using the CNTRL-Z/bg/fg commands to shunt a process into the background. The problem with this is that whilst your process or program might still be running in the background, once you disconnect from your logged in session, the process is inaccessible, meaning that you cannot pull that process back into the foreground with it’s process number (PID). bg/fg commands use a separate number system linked to your current user session. If you log out of that session, even if the process belongs to your user, you cannot pull it back into the foreground. This is whee I’ve found tmux to be most useful because it allows many sessions and as long as these sessions belong to your user, you can retrieve them from any SSH/command line session.

I’m not going to go into everything tmux can do, simply the easy stuff that I find makes it so useful.

1. Install tmux.

To install tmux on Ubuntu/Debian based Linux systems, use: –

sudo apt-get install tmux

If you’re using a Red-Hat based system use: –

yum install tmux

2. Create a tmux session.

To create a tmux session from the command line use: –

tmux new -s session_name

..where session_name is the string name you want to name the session. You don’t have to use named sessions, tmux will automatically number them which you can use to access a detached session, but I find named sessions easier and clearer to work with.
Once you’re in a session, you’ll find it looks very much like a typical SSH/command line session aside from a green bar menu at the bottom of the screen. If you want to quit this session, you can simply use “exit” like you would in any typical command line session. However, if you have something running in this session and you want to logout and come back to it later, you should detach the session and leave it running in the background.

3. Detach a running tmux session.

To detach a running session, hold down CNTRL-B and then press ‘d’. The CNTRL-B key combination is known as the prefix shortcut and you’ll need to use this key combination to access commands in tmux without disturbing the shell session you’re in. The D key in this instance detaches the session and leaves it running in the background. If your process isn’t doing anything and you have access to the session command line you can also use: –

tmux detach

4. List active tmux sessions.

From the command line, you can see how many tmux sessions you have running by simply running:-

tmux ls

or…

tmux list-sessions

This will list the running tmux sessions in the shell. From the below, you can see I have one session active which I have called simply “session1”.

session1: 1 windows (created Tue Jan 16 11:28:36 2018) [130x33]

5. Reattaching to a deteached tmux session.

To reattach to this tmux session, you simply have to use: –

tmux attach -t session_name

So if I wanted to attach to the “session1” session above, I would use: –

tmux attach -t session1

…and you’re back in the tmux session shell you created earlier.

6. Switching tmux sessions.

You can also switch from one tmux session to another by using the following command from within a tmux session. So if I had two tmux sessions, I could switch from one shell to the other by using: –

tmux switch -t session_name

7. tmux Windows within sessions.

You can also create multiple shell windows within one session. From within a tmux session, you can use: –

tmux new-window

or you can use CNTRL-B + c.

To switch between session windows, simply use CNTRL-B [0-9] where the number is the sequential number of the window or the following if you want to do it from the session command line: –

tmux select-window -t [0-9]

I’ve found this utility extremely useful when it wasn’t practical to use nohup

, , ,

Enable Start + Select Quit of N64 Emulators Under RetroPie

After getting the N64 emulator running on RetroPie, you may be having trouble actually quitting the N64 emulator in the usual RetroPie manner by pressing Start and Select at the same time on a generic gamepad as originally, the N64 didn’t have a select button. Plus, the mupen64plus emulator isn’t part of RetroPie’s retroarch and doesn’t share it’s general controller configuration. So you’ll need to define the button mapping yourself.

First, list the contents of “/opt/retropie/configs/all/retroarch-joypads”. You’ll get something like the following. I’m using an 8bitdo NES30 Pro gamepad. The values for your controller will be different!

#ls -lah
total 32K
drwxr-xr-x  2 pi pi 4.0K Jan 11 09:59 .
drwxr-xr-x 16 pi pi 4.0K Jul 29 21:09 ..
-rw-r--r--  1 pi pi  859 Nov 11 20:57 8Bitdo NES30 Pro.cfg  < --- This is the config I'm using.
-rw-r--r--  1 pi pi  769 Nov 11 20:55 8Bitdo NES30 Pro.cfg.bak
-rw-r--r--  1 pi pi  870 Jan  3  2017 MY-POWERCO.,LTD.USBJoystick.cfg
-rw-r--r--  1 pi pi  870 Dec 13  2016 MY-POWERCO.,LTD.USBJoystick.cfg.bak
-rw-r--r--  1 pi pi  536 Jan  3  2017 USBGamepad.cfg
-rw-r--r--  1 pi pi  536 Jan  3  2017 USBGamepad.cfg.bak

If you open this file, you’ll see the values attached to all the controls.

input_device = "8Bitdo NES30 Pro"
input_driver = "sdl"
input_r_y_plus_axis = "+3"
input_l3_btn = "13"
input_r_x_minus_axis = "-2"
input_l_btn = "6"
input_load_state_btn = "6"
input_start_btn = "11"
input_exit_emulator_btn = "11"
input_l_y_minus_axis = "-1"
input_up_btn = "h0up"
input_r_y_minus_axis = "-3"
input_a_btn = "1"
input_b_btn = "0"
input_reset_btn = "0"
input_enable_hotkey_btn = "10"
input_down_btn = "h0down"
input_l_x_plus_axis = "+0"
input_l_y_plus_axis = "+1"
input_r_btn = "7"
input_save_state_btn = "7"
input_r2_btn = "9"
input_r3_btn = "14"
input_right_btn = "h0right"
input_state_slot_increase_btn = "h0right"
input_x_btn = "4"
input_menu_toggle_btn = "4"
input_select_btn = "10"
input_l_x_minus_axis = "-0"
input_y_btn = "3"
input_left_btn = "h0left"
input_state_slot_decrease_btn = "h0left"
input_r_x_plus_axis = "+2"
input_l2_btn = "8"

We’re interested in the “start” and “select” button values as these are the ones we’re going to need to define the quit button combination. From the above, you can see they are 11 and 10 respectively.

input_start_btn = "11"
input_select_btn = "10"

So next, open the mupen64plus configuration file: –

sudo vi /opt/retropie/configs/n64/mupen64plus.cfg

The event you want to capture is both start and select buttons pressed at once. This signals the “Stop” action. So look for the line beginning “Joy Mapping Stop”. From the below, you can see that J0 (Joystick or controller 0 or player 1) as just select set for quitting the emulator. This doesn’t work for me, so I’ve changed it to both start and select “B10/B11”. This should allow you to quit the N64 emulator in the usual manner for RetroPie. Save this file.

# Joy Mapping Stop = "J0B10/B0"
Joy Mapping Stop = "J0B10/B11"

One more thing you need to do due to what to me looks like a bug is With the setting mupen64plus_hotkeys = “1” the mupen64plus.cfg gets overwritten each boot. This file will reset itself to ‘Joy Mapping Stop = “J0B10/B0″‘. To fix this, you need to edit the following file: –

sudo vi /opt/retropie/configs/all/autoconf.cfg

Change the following: –

mupen64plus_hotkeys = "1"

to…

mupen64plus_hotkeys = "0"

Save this, reboot your RetroPie and you should be able to quit the N64 emulator normally :-)

, , , , , , ,
[Top]

Overclocking a Raspberry Pi 3 for Acceptable RetroPie N64 Performance

Whilst I’ve written about speeding up RetroPie before in order to get the SNES emulator’s sound to stop lagging, a little more of an extreme speed boost is required to get the N64 emulator working at a decent rate to make the games playable. For this, I’m going to use overclocking to run the Raspberry Pi’s ARM CPU at a higher frequency rate. Keep in mind that overclocking your Pi can have it freeze up if the overclocking frequency is too severe and you can potentially damage the CPU of the Pi. Still, the settings I’ve chosen aren’t too much and I’ve been able to play Super Mario Kart 64 on the N64 at playable speeds.

So, without further ado, here are the overclocking settings I’ve chosen. These settings also work well for the Sega Dreamcast emulator too.

In order to change the speed of your CPU, you need to edit the following file on your RetroPie installation: –

sudo vi /boot/config.txt

Add the following settings: –

arm_freq=900
gpu_freq=525
core_freq=525
sdram_freq=500
over_voltage=6
v3d_freq=525
force_turbo=1
avoid_pwm_pll=1
disable_splash=1

Save this and reboot your Pi. Once back into RetroPie, try the N64 emulator and you should have a good speed boost that allows you to play N64 games acceptably. To play it safe, I’m using some adhesive heat sinks for the Raspberry Pi 3 from Amazon and at full load, the CPU temp is around 65 degrees C, which is fine under load.

, , , ,
[Top]

Integrating the PICO-8 Fantasy Console Into RetroPie/Emulation Station on the Raspberry Pi

Note – I did not write the original tutorial for this, I simply duplicated it and added suggestions and fixes from other PICO-8 users, specifically dddaaannn and ltpitt. Many thanks to them for all their hard work!

RetroPie is a great weekend project to turn your Raspberry Pi into an all-singing, all-dancing retro emulator station. Whilst it’s integrated with many old consoles, like N64, Sega MegaDrive and NES, there’s really nothing stopping you from adding retro consoles that never actually existed like the excellent PICO-8 “fantasy console” (for more on fantasy consoles and retro-style programming, see my article here).
First, you need to download the latest Raspberry Pi edition of the PICO-8 developer environment from the Lexaoffle website. At the time of writing, this is version v0.1.11f. Copy the zip file pico-8_0.1.11f_raspi.zip (or whatever version named file you have) to the “/home/pi” home directory on your RetroPie installation and unzip it. You can either SSH into your Pi remotely or quit out of Emulation Station directly with (Menu button, Quit, Quit Emulation Station) to get a shell prompt.

unzip pico-8_0.1.11f_raspi.zip

This will create the ~/pico-8 directory (~ being shortcut for /home/pi). Test that PICO-8 works correctly on the Pi with: –

~/pico-8/pico8 -splore

Controls, fullscreen graphics, sound, and Splore over the Internet should all just work as usual.

Once you can run PICO-8 on the Pi correctly and get to the Splore cartridge explorer, you’ll want to integrate this into the RetroPie main menu with all the other consoles/computer emulators you have installed.

I have two versions of the PICO-8 logo, one with light text and one with dark text, based on the one for the PICO-8 wiki (which in turn is heavily based on the official logos). They can be downloaded straight onto the Pi using wget (sudo apt-get install wget if you don’t have it): –

wget https://joshua14.homelinux.org/downloads/p8logo.png
wget https://joshua14.homelinux.org/downloads/p8logo_dark.png

On the Pi, create a new pico8 theme directory for Emulation Station:-

cd /etc/emulationstation
sudo mkdir themes/carbon/pico8

Copy the logo files to this location using the “mv” command. You also need to create a “theme.xml” file in this directory. Copy the one from …/themes/carbon/amiga/theme.xml, then edit it (such as with the “nano” or “vi” editor): –

sudo cp themes/carbon/amiga/theme.xml themes/carbon/pico8/theme.xml
sudo nano -w themes/carbon/pico8/theme.xml

Make these changes:-

– Replace all instances of “./art/controller.svg” with “./../amiga/art/controller.svg”.
Change the logo for the main system screen, using the dark text version:-

<view name="system">
  ...
  <image name="logo">
    <path>./p8logo_dark.png</path>
  </image>
</view>

Next, change the logo for the system detail screen, using the light text version:-

<view name="basic, detailed">
  ...
  <image name="logo">
    <path>./p8logo.png</path>
    ...
  </image>
  ...
</view>

Now you need to add pico8 to the list of systems. Edit the system config file:-

sudo vi /etc/emulationstation/es_systems.cfg

This config file lists all the systems on RetroPie. Inside tags, add these lines:-

<system>
    <name>pico8</name>
    <fullname>PICO-8</fullname>
    <path>/home/pi/pico-8</path>
    <extension>.sh .SH</extension>
    <command>/opt/retropie/supplementary/runcommand/runcommand.sh 0 %ROM%</command>
    <platform>pico8</platform>
    <theme>pico8</theme>
</system>

This says to search for any files ending with the *.sh or *.SH file extension defined by in the directory defined by , in this case, the PICO-8 base directory under /home/pi/pico-8 where you unzipped the PICO-8 installation directory.

NOTE: As of January 2018, PICO-8 cannot be exited back to Emulation Station from within a game launched like so: –

/home/pi/pico-8/pico8 -run somegame.p8

If you try and press the gamepad button assigned to ESC in PICO-8, you’ll only get options to “Continue”, “Favourite” or “Reset Cart”. This is a problem. Fortunately, PICO-8 version 0.1.11 (the current version is 0.1.11g for reference) you can exit Splore via the options area – “Shutdown PICO-8”. So you can only really use PICO-8 rather than defining your p8 games separately. I’ll show you how to do this too if PICO-8 is ever updated to allow the menu from within any game cartridge to shutdown PICO-8.

So the only cartridge we can define for PICO-8 is a shell script that starts the Splore cartridge manager. Create a new shell script for this called, say, “Cartridge-Explorer.sh”. Remember RetroPie expects all “games” to be files with the shell script .sh extension under /home/pi/pico-8 so create this file with: –

vi /home/pi/pico-8-Cartridge-Explorer.sh

Add the following lines: –

#!/bin/bash
pushd "/home/pi/pico-8"
./pico8 -splore
popd

Save this. You can also create a specific game cartridge in this manner, but remember! You can’t currently quit PICO-8 back to Emulation Station menu. But if you *did*, you’d create a shell script called “SomeGame.sh” and have the contents be: –

#!/bin/bash
pushd "/home/pi/pico-8"
./pico8 -run somegame.p8
popd

You can run your own games through Splore anyway, you just can’t have separate Emulation Station menu entries for them and quit back out without a keyboard plugged in. The default location for your own downloaded or created PICO-8 carts is “/home/pi/.lexoffle/pico-8/carts”. Drop your own games in there and use Splore to tab along to the local directory and load your games from there. Splore can be quit using the gamepad under “Options” and then choosing “Shutdown PICO-8”.

Before rebooting, make sure the “Cartridge-Explorer.sh” file has correct execute access.

chmod a+x /home/pi/pico-8/Cartridge-Explorer.sh

Reboot (“sudo shutdown -r now”) and you should now have PICO-8 in your list of systems under RetroPie. Selecting it will show you only one “game”, the Cartridge-Explorer entry you created earlier. This will load PICO-8 in Splore mode. You can now play any of the PICO-8 games available via Splore (Internet connection needed, natch) and also you can tab along to access your p8 cartridges locally.

, , ,
[Top]

Retro Programming With “Fantasy Consoles”

You may be wondering what I’ve been doing this year since there’s been no posts. Readers, it’s because I’ve found something wonderful. I’ve found fantasy consoles. What is this, you may ask? I’ll tell you. Basically it’s a full game development environment, a bit like a retro emulator. The difference between a retro emulator and a fantasy console is that crucially, the fantasy console replicates the programming constrictions of something that never actually existed. Typically, a fantasy console game development environment also includes in one complete package everything you need to create games – a text editor to write your code, a sprite and map editor to create your graphics and maps/levels, a sound effects editor and a music editor.
Importantly, because these things emulate the hardware restrictions of some old piece of hardware there are various limitations to what you can do. Each fantasy console product (which we’ll get to in a minute) has a standard set of artificially imposed development constraints, such as restricted graphical resolutions, color palettes, RAM usage, or storage space. Often, sprites can only be a certain size with certain colours, you can only have so many lines of code before the memory is “full”, things like that.

And it’s fantastic.

Part of the allure of these things is that, due to the limitations each system imposes, your games can only be so big or complex. This not only forces you to think about what you really want to do but it also means that projects become completable….there’s literally no feature creep because there’s no room in the tiny runtime for it. It also means that, like the good old days of C64 and ZX Spectrum, games developed with each system tend to end up sharing the same aesthetic. All fantasy consoles seek to emulate the aesthetics and community of 1980s home computing for a modern audience.

So if you want to recreate the simple games of your youth, just enjoy the chunky pixel aesthetic or are simply short on time or knowledge and want to create your own little video games, here is a list of the most popular fantasy console environments available at the time of writing.

PICO-8
The PICO-8, first released in 2014 by Voxatron developer and creator Joseph “zep” White, is for “for making, sharing and playing tiny games and other computer programs.” This was the first “fantasy console” and is arguably the most famous. It comes with a (cut down) Lua interpreter for the code, a sprite and map editor, sound effects editor and music editor. The programs you create on PICO-8 can – ingeniously – be stored in a PNG image which PICO-8 will load happily that looks like an old video game cartridge with your game’s screenshot as the label. They can also be saved and distributed at *.p8 files. There is also an export feature for a Phaser-based HTML5 application so anyone can play what you’ve created. Native platform export binaries functionality is planned for the next release. PICO-8 has a token limit (the amount of code you can write) that is quite harsh but it keeps your ideas small-scale and it’s fun to see how much stuff you can squeeze into each game.

Key Features

Cost: $14.99 USD.
Proprietary?: Yes.
Video Resolution: 128×128.
Palette: Fixed, 16-colour.
Language: Lua.
Export formats: HTML5/JS (browser), *.p8/*.p8.png cartridges (PICO-8 files). Native standalone binaries planned for 1.0 release (Win/Mac/Linux).
Built-in features: Code editor, Sprite Editor, Tilemap Editor, SFX Editor, Music Editor, Screenshot tool, GIF Recorder, and SPLORE (internet connected cartridge browser connected to the PICO-8 BBS where you can upload your creations)
Platforms: Windows, Mac, Linux, Raspberry Pi, PocketC.H.I.P.

TIC-80
The TIC-80 is a worthy adversary to the PICO-8 — with a wider, higher resolution display, a customizable 16-colour palette, 64k code (token) limit and up to 256 8×8 foreground sprites and 256 8×8 background tiles. The TIC-80 is a powerful fantasy console, although I would describe this as a fantasy computer to PICO-8’s fantasy console. It also works on Android! This would be my personal second choice after PICO-8.

Key Features

Cost: Pay what you want.
Proprietary?: Yes.
Video Resolution: 240×136.
Palette: Customizable during development but fixed at runtime. 16-colour.
Language: Lua/Moonscript.
Export formats: HTML/JS (browser), *.tic cartridges (TIC-80 files). Native binaries (Win/Mac/Linux).
Built-in features: Code editor, Sprite Editor, Tilemap Editor, SFX Editor.
Platforms: HTML5/JS (browser), Windows (UWP), Mac, Linux, Android.

LIKO-12
LIKO-12 is built on top of the rather awesome LOVE2D game engine which itself runs on Lua. This is basically an open source clone inspired by PICO-8 but without some of the limitations. It comes with a wider display, no token limits, more graphic memory and a different API…so while some code may be superficially similar to PICO-8, it’s different. But since it’s open source, it’s free baby!

Key Features

Cost: Free.
Proprietary?: No, Open-Source.
Video Resolution: 192×128.
Palette: Fixed at runtime, 16-colour.
Language: Lua.
Export formats: *.lk12 cartridges (LIKO-12 files).
Built-in features: Code editor, Sprite Editor, Tilemap Editor, GIF Recorder.
Platforms: Windows, Linux, Mac, Android, iOS & Raspberry Pi through LÖVE2D.

PixelVision8

PixelVision8 attempts to be all things really. Rather than defining itself as a fantasy console with specific, fixed limitations, the PixelVision 8 lets developers define the limitations they want to work within.
The PixelVision 8 currently offers a choice of four templates, each based on an existing 8-bit console like Sega Master System and NES. However, users aren’t restricted to these templates and they can change and expand the limitations as needed using the built-in development tools, which is a neat idea. The Pixel Vision 8 is still in early development right now, but it’s definitely one to watch.

Cost: $10.00 USD during early access. Will have free and pro versions after beta release.
Proprietary?: Open-Source API, proprietary official tools.
Video Resolution: Various, depending on settings & templates used.
Palette: Customizable during development, fixed at runtime .
Language: Lua.
Export formats: *.pv* files (Pixel Vision 8 files), other formats coming soon.
Built-in features: System Templates (NES/Famicom, Sega Master System, Game Boy, Sega Game Gear), Graphical File Browser, Display Configuration Tool, Sprite Editor, Tilemap Editor, SFX Editor, Music Editor.
Platforms: Windows, Mac, Linux.

So get crackin’. Choose your comfy development environment and start cranking out those games. You can play my first efforts here and here.

I’ll get back to Linux stuff soon :-D I’m hoping the next version of PICO-8 has native binary support so I can create Linux versions for everybody.

, , , , , , , , , ,
[Top]

Speeding Up Performance on a RetroPie Setup

I was desperately trying to get hold of a NES Mini Classic console before Christmas but because Nintendo are hopeless they were out of stock except from third-party sellers on Amazon and eBay selling with with 1000% markup on price. I kinda wanted one because it would look neat next to my TV and also I could introduce the “good old days” to my little boy. But no, they were sold out everywhere, naturally.
Then I thought, “what the hell am I doing?” and bought a Raspberry Pi 3 from Amazon and downloaded RetroPie to an SD card. RetroPie is the regular Raspbian/Pixel Linux OS for Raspberry Pi with a huge number of retro emulators built in, all wrapped in a nice GUI. All you have to do is setup your USB controller mappings and point it at some game ROM files and presto…your very own retro games console.
The benefits were obvious to me – you can play nearly every game from for any system prior to 1995, including NES, arcades, Sega Megadrive (Genesis in the colonies), Master-System, PC Engine, Neo Geo, SNES etc, you can choose your controller (I went for PS3-alike controllers) myself) and it’s very customisable with menus and themes and such. You can even (with a little programming magic) add things like background music to the menus and things like that.
There are *plenty* of guides on how to setup RetroPie on a Raspberry Pi, like here, here and here so I won’t repeat the information here. Suffice to say, it’s pretty easy once you’ve imaged the SD card properly.
The problem I was having is that even on a Raspberry Pi 3, some of the emulators (like the SNES one for some reason) would be very slow with lagging sound and sinking frame-rates. Some emulators, of course, like the Sega Dreamcast and N64 emulators won’t run well on even a Pi 3 – they simply require too much power to run well on any Pi – but the SNES one should run fine.
I investigated overclocking as a potential solution, but the Pi 3 doesn’t officially support overclocking yet although it can be done (use a heatsink!). The menu option which used to be there to do so for the Pi 1 & 2 is missing on the Pi 3. The most likely cause is a configuration issue. So I tried various things in the /opt/retropie/configs/all/retroarch.cfg config file like trying various fixes for sound issues and a few other tips and tricks to try to speed up emulation with varying degrees of success depending on the emulator.
The problem ended up being the “scaling governor” for the CPU on the Pi which is somehow stuck to powersave mode meaning that it was taking too long to process. The fix is to set each CPU core scaling governor to “ondemand” rather than “powersave”. You can do this by adding the following lines to your “/etc/rc.local” file which (if you know your Linux) is run at startup.

echo ondemand > /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor
echo ondemand > /sys/devices/system/cpu/cpu1/cpufreq/scaling_governor
echo ondemand > /sys/devices/system/cpu/cpu2/cpufreq/scaling_governor
echo ondemand > /sys/devices/system/cpu/cpu3/cpufreq/scaling_governor

This fixed all my Raspberry Pi 3 emulation performance issues, at least with emulators that technically should run well on the Raspberry Pi 3. I hope you found this useful. If you are still experiencing performance issues, especially on a Pi3, try some of the other fixes above. Overclocking is an option but should probably be a last resort.

, , ,
[Top]

The Node is now HTTPS only

, ,
[Top]