Super Mario In Sed, Sort Of

We definitely needed to reach for a sed reference guide for this one, but looking at the animated GIF of the script running, it is recognizably Super Mario Bros. albeit with minimal gameplay beyond jumping obstacles and avoiding or destroying koopas et al. Creator [Ivan Chebykin] is for certain a master of the dark arts.

Digging in a bit deeper, it’s not strictly speaking 100% sed. A wrapper shell script is required to interface to the shell and grab the keyboard input to pass along. This is simply because sed is a stream processor, and as such it requires text to be fed into it, and it produces a text output. It has no way of reading the terminal input directly, hence the wrapper script. However, all the game logic and ‘graphics’ rendering is pure sed, so that’s perfectly reasonable.

Such programming demos are a great way to hone the finer points of various tools we use every day, whilst not being serious enough to matter if we fail. Pushing the boundaries of what can be done with these basic nuts and bolts we take for granted, is for us the very essence of software hacking, and bravo we say.

Reckon you could top this? Show us! In the meantime, here’s a guide to hacking the recently released Game and Watch, and then doing the decent thing and running DOOM on it. Finally, sed is notoriously tricky to work with, so to help here’s a graphical debugger to make things a little clearer.

Debugging For Sed — No Kidding

If you do much Linux shell scripting, you’ve probably encountered sed — the stream editor — in an example. Maybe you’ve even used it yourself. If all you want to do is substitute text, it is easy and efficient. But if you try to do really elaborate editing, it is often difficult to get things right. The syntax is cryptic and the documentation is lacking. But thanks to [SoptikHa2] you can now debug sed scripts with a text-based GUI debugger. Seriously.

According to the author, the program has several notable features:

  • Preview variable values, both of them!
  • See how will a substitute command affect pattern space before it runs
  • Step through sed script – both forward and backward!
  • Place breakpoints and examine program state
  • Hot reload and see what changes as you edit source code
  • Its name is a palindrome

There’s only one word for that last feature: wow.

Continue reading “Debugging For Sed — No Kidding”

Sweet Streams Are Made Of These: Creating Music On The Command Line

There are countless ways to create music. In the simplest form, it won’t even require any equipment, as evidenced by beatboxing or a capella. If we move to the computer, it’s pretty much the same situation: audio programming languages have been around for as long as general-purpose high-level languages, and sound synthesis software along with them. And just as with physical equipment, none of that is particularly necessary thanks to sed. Yes, the sed, the good old stream editor, as [laserbat] shows in her music generating script.

Providing both a minified and fully commented version of Bach’s Prelude 1 in C major as example, [laserbat] uses a string representation of the sheet music as the script’s starting point, along with a look-up table of each transformed note’s wavelength. From here, she generates fixed length PCM square wave signals of each of the notes, to be piped as-is to the sound card via ALSA’s aplay or SoX’s play. To keep things simple enough, she stays within the region of printable characters here, using space and tilde as low and high values respectively, providing highest possible volume at the same time this way.

The concept itself is of course nothing new, it’s how .au and .wav files work, as well as these little C lines. And while the fixed note duration takes away some of the smoothness in [laserbat]’s version, adding variable duration might just be a hint too much for a sed implementation, although we’ve certainly seen some more complex scripts in the past.

[via r/programming]

Maze Solving Via Text Editing

Linux scripters usually know about sed — the stream editor. It has a simple job: transform text as it whizzes from input to output. So if you wanted to solve a maze, this wouldn’t be the tool you’d think to use, right? Well, if you were [xsot], you’d disagree.

You build a maze using spaces for empty space and # for walls. There’s an S to mark the start position and an E to mark the end. Of course, the maze can also contain newlines. The sed script does an amazing job of solving the problem.

Continue reading “Maze Solving Via Text Editing”