Skip to content

Instantly share code, notes, and snippets.

@psmay
Last active January 18, 2019 09:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save psmay/7f45a867c1ae8f88ec36 to your computer and use it in GitHub Desktop.
Save psmay/7f45a867c1ae8f88ec36 to your computer and use it in GitHub Desktop.
SextetStreamStdinTest to demonstrate that my StepMania SextetStream driver is functioning
#! /usr/bin/perl
use warnings;
use strict;
use 5.010;
use Carp;
# 1: Use arrow display (dance/techno)
# 0: Use generic display (other games)
my $use_dance_display = 1;
# As with anything perl, there's more than one way to do this.
sub sextet_values {
my $value = shift;
return (
(($value & 0x01) and 1),
(($value & 0x02) and 1),
(($value & 0x04) and 1),
(($value & 0x08) and 1),
(($value & 0x10) and 1),
(($value & 0x20) and 1),
);
}
sub lit {
my $condition = shift;
my $symbol = shift;
if(not $condition) {
$symbol =~ s/./ /g;
}
return $symbol;
}
sub get_cabinet_symbol {
my $cabinet_bits = shift;
my($marquee_ul, $marquee_ur, $marquee_ll, $marquee_lr,
$bass_l, $bass_r) = sextet_values($cabinet_bits);
return "[" .
lit($bass_l, 'O') .
lit($marquee_ll, '_') .
lit($marquee_ul, '^') .
lit($marquee_ur, '^') .
lit($marquee_lr, '_') .
lit($bass_r, 'O') .
"]";
}
# For any game
sub get_generic_buttons_symbol {
my @buttons = @_;
my @button_indicators = ('1' .. '9', 'X', '1' .. '9');
my $sym = "";
my $i = 0;
for $i(0 .. $#button_indicators) {
$sym .= lit($buttons[$i], $button_indicators[$i]);
}
return $sym;
}
# For dance or techno
sub get_dance_buttons_symbol {
my($l, $r, $u, $d, $ul, $ur, $c, $dl, $dr) = @_;
return
lit($dl, '/') .
lit($l, '<') .
lit($ul, '\\') .
lit($d, 'v') .
lit($c, '#') .
lit($u, '^') .
lit($ur, '/') .
lit($r, '>') .
lit($dr, '\\')
;
}
sub get_controller_symbol {
my @b1 = sextet_values(shift);
my @b2 = sextet_values(shift);
my @b3 = sextet_values(shift);
my @b4 = sextet_values(shift);
my @b5 = sextet_values(shift);
my @b6 = sextet_values(shift);
my($menu_l, $menu_r, $menu_u, $menu_d, $start, $select) = @b1;
my($back, $coin, $operator, $effect_u, $effect_d, undef) = @b2;
my @buttons = (@b3, @b4, @b5, @b6);
my $current_buttons =
$use_dance_display ?
get_dance_buttons_symbol(@buttons) :
get_generic_buttons_symbol(@buttons);
return ' [' .
lit($menu_l, '<') .
lit($menu_d, 'v') .
lit($menu_u, '^') .
lit($menu_r, '>') .
lit($start, 'S') .
lit($select, 's') .
lit($back, '!') .
lit($coin, '$') .
lit($operator, '?') .
lit($effect_d, '-') .
lit($effect_u, '+') .
'|' .
$current_buttons .
']';
}
sub compose_line {
my $line = "";
$line .= get_cabinet_symbol(shift);
while(@_ >= 6) {
my @controller_values = splice(@_, 0, 6);
$line .= get_controller_symbol(@controller_values);
}
return $line;
}
while(<>) {
chomp;
say compose_line(unpack('C*', $_));
$| = 1;
}
<job id="Job1">
<script language="JScript">
// true: Use arrow display (dance/techno)
// false: Use generic display (other games)
var useDanceDisplay = true;
var stdin = WScript.StdIn;
var stdout = WScript.StdOut;
function sextetValues(sextet) {
return [
(sextet & 0x01) != 0,
(sextet & 0x02) != 0,
(sextet & 0x04) != 0,
(sextet & 0x08) != 0,
(sextet & 0x10) != 0,
(sextet & 0x20) != 0
];
}
function blanked(str) {
return str.replace(/./g, ' ');
}
function lit(condition, symbol) {
return condition ? symbol : blanked(symbol);
}
function getCabinetSymbol(sextet) {
var sv = sextetValues(sextet);
var marquee_ul = sv[0],
marquee_ur = sv[1],
marquee_ll = sv[2],
marquee_lr = sv[3],
bass_l = sv[4],
bass_r = sv[5];
return "[" +
lit(bass_l, 'O') +
lit(marquee_ll, '_') +
lit(marquee_ul, '^') +
lit(marquee_ur, '^') +
lit(marquee_lr, '_') +
lit(bass_r, 'O') +
"]";
}
// For any game
function getGenericButtonsSymbol(buttons) {
var button_indicators = [
'1','2','3','4','5','6','7','8','9','X',
'1','2','3','4','5','6','7','8','9'
];
var sym = "";
for(var i = 0; i < button_indicators.length; ++i) {
sym += lit(buttons[i], button_indicators[i]);
}
return sym;
}
// For dance or techno
function getDanceButtonsSymbol(buttons) {
var l = buttons[0],
r = buttons[1],
u = buttons[2],
d = buttons[3],
ul = buttons[4],
ur = buttons[5],
c = buttons[6],
dl = buttons[7],
dr = buttons[8];
return (
lit(dl, '/') +
lit(l, '<') +
lit(ul, '\\') +
lit(d, 'v') +
lit(c, '#') +
lit(u, '^') +
lit(ur, '/') +
lit(r, '>') +
lit(dr, '\\')
);
}
function getControllerSymbol(s1,s2,s3,s4,s5,s6) {
var b1 = sextetValues(s1),
b2 = sextetValues(s2),
b3 = sextetValues(s3),
b4 = sextetValues(s4),
b5 = sextetValues(s5),
b6 = sextetValues(s6);
var menu_l = b1[0],
menu_r = b1[1],
menu_u = b1[2],
menu_d = b1[3],
start = b1[4],
select = b1[5],
back = b2[0],
coin = b2[1],
operator = b2[2],
effect_u = b2[3],
effect_d = b2[4];
// b2[5] not used
var buttons = b3.concat(b4, b5, b6);
var currentButtons =
useDanceDisplay ?
getDanceButtonsSymbol(buttons) :
getGenericButtonsSymbol(buttons);
return ' [' +
lit(menu_l, '<') +
lit(menu_d, 'v') +
lit(menu_u, '^') +
lit(menu_r, '>') +
lit(start, 'S') +
lit(select, 's') +
lit(back, '!') +
lit(coin, '') +
lit(operator, '?') +
lit(effect_d, '-') +
lit(effect_u, '+') +
'|' +
currentButtons +
']';
}
function composeLine(sextets) {
var line = "";
var controllerValues;
line += getCabinetSymbol(sextets.shift());
while(sextets.length >= 6) {
controllerValues = sextets.splice(0, 6);
line += getControllerSymbol.apply(null, controllerValues);
}
return line;
}
function unpackChars(str) {
var values = [];
for(var i = 0; i < str.length; ++i) {
values[i] = str.charCodeAt(i);
}
return values;
}
while(!stdin.AtEndOfStream)
{
stdout.WriteLine(composeLine(unpackChars(stdin.ReadLine())));
}
</script>
</job>
@psmay
Copy link
Author

psmay commented Oct 8, 2014

These are test programs to demonstrate that my StepMania SextetStream driver is functioning.

One is a perl script to be used with Linux or similar. To run it on data from a FIFO called "$SM/Data/StepMania-Lights-SextetStream.out", do

./SextetStreamStdinTest.pl < "$SM/Data/StepMania-Lights-SextetStream.out"

The other is a Windows Script Host script for use with a Windows command line (cmd.exe). To create a named pipe with the path \\.\pipe\StepMania-Lights-SextetStream and run this script on the incoming data, acquire createAndReadPipe and pipe its output into this script:

createAndReadPipe StepMania-Lights-SextetStream | cscript //nologo SextetStreamStdinTest.wsf

By default, these scripts are configured to display the sensors for the dance and techno game modes. To use a generic display of all available buttons:

  • For the perl version, set the $use_dance_display variable at the top to 0.
  • For the WSH version, set the useDanceDisplay variable at the top to false.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment