Sunday, January 22, 2012

One Font to Rule Them All

Way back in the olden times (9 months ago?) I tried to use weechat on z2lite.  I lasted about a minute before my eyes squealed in agony.  It was setup by default to use a microscopic font in order to squeeze as much information onto the tiny zipit screen as possible.  Now I understand.  I've been fiddling with various IRC and IM text apps for a week or so now, trying to see which, if any, I can cram into the jffs.  In order to provide more utility than the basic pmirc script they all seem to need the box drawing characters and plenty of screen real estate.
IZ2S 2.05 (enhanced) comes with a really nice 6x10 font that gives you 24 lines and 53 columns on the zipit screen.  It's not quite a full xterm, but it's a nice readable compromise.  Unfortunately it only comes with the basic ASCII char set.  No frills.  All the rest of the glyphs in the 256 char font are hideous useless squiggles.  A while ago fellow IZ2S zipit user dronz dug up some nice 8 wide fonts complete with box drawing characters and a full set of Western European glyphs to go along with his European keymap for the zipit keyboard.  I've used these a bit (mostly for the box chars) and they work well enough for the alsamixer, but 8 wide glyphs only give you 40 columns across the zipit screen.  Not quite enough room for chatting and a buddy list.

The microscopic font has the box drawing characters, but again, my eyes!  I searched the internet, far and wide, for the perfect linux console font.  And I found some candidates, but nothing that truely satisfied.  Ok, in the dark and distant past, I've been known to roll my own homebrew font to squeeze as much as possible onto the tiny screens of yesteryear.  So I dug around for some sort of console font editor.  What I found was also a blast from the past.  The nafe font editor dumps the font to a text file with the glyphs drawn in Xs and spaces.  Then you edit the glyphs with a text editor (emacs) and a lot of squinting.  I also discovered the cse font editor (which I haven't tried yet, but I did try his nethack font) and gbdfed, which I used to import my partially finished psf font file and display the glyphs at actual size.  I could've used it to edit the glyphs, but I'm pretty comfortable with emacs.  However, I did also use gbdfed to display the 8x10 font from dronz as something of a guide for my new 6x10 glyphs.  When the new glyphs were complete I used psfgettable to fetch the unicode mapping table from the Western European font and psfaddtable to paste it onto my new font.  So it should support all the same unicode chars, including the box bits.  The results are simply fabulous!
I finally got the rhapsody IRC client to fit ok on the zipit screen.  It's about 140K, which is not too shabby for the additional features it gives you over the no frills pmirc script.  The new font should also do wonders for the naim IM and IRC client, if it works.  I built the new experimental code with lua scripting and OSCAR protocol support, but I still have some config details to work out.
Meanwhile on the #zipit IRC channel dronz pointed out some online gateways for IM and email that appear to work with retawq.  Good idea.  I dug up my old mobile links homepage that I created for netsurf and reworked it as the default homepage for retawq on the jffs, including a link the the retawq help pages.  Reading the help documentation made me realize that retawq can be scripted to substitute for wget or curl.   So I quickly dashed off a one line "wget" script that seems to work well enough for simple downloads.  You still need the busybox upgrade to download and unzip things.  Gotta remember to make better use of the goodies I've already loaded onto the jffs.

It may take a day or two to release all the goodies for this post.  Just as I finished the photography portion of this post, dronz sent me a bunch of new scripts, fonts, and config files that I need to sort out and merge into my stuff.  To get the ball rolling, here's nethack, rhapsody IRC, and the new font for IZ2S.

nethack-iz2s.zip
rhapsody-irc-iz2s.zip
iz2slat-font.zip

And here's a pic of nethack with the new IZ2S font loaded and the DEC character set selected from the nethack option menu.  Check out those nice smooth walls...
 I'm still working on the code for the really fancy nethack font.

Tuesday, January 17, 2012

Diminishing Returns

After eliminating the ALSA bloatware I'd set my sights on the big fat static loadkeys program from IZ2S.  I was originally forced to keep it on the jffs because the keyboard is pretty much useless without a keymap, but a 300K executable is a bit excessive for that.  Now the IZ2S busybox upgrade comes with the loadkmap utility, which is much smaller because it only loads a binary version of the keymap file.  This seemed to work well enough so I compiled a tiny 4K standalone version for the base jffs system.  Unfortunately you need a recent version of the loadkeys program to convert any new keymaps you might make to the binary kmap file format, and the IZ2S loadkeys is a bit too old, so I has to use my Mint linux box to convert the keymaps.  Eventually I guess I'll build an updated loadkeys for IZ2S.  For now I just included a bunch of premade kmap files.

That took care of most of the remaining bloat on the base jffs.  None of the other executables in the /mnt/jffs/bin directory were significantly over 100K, so any further savings generated by replacing them would be relatively small. So, armed with the space saved by eliminating loadkeys I decided to try and replicate some more of the core IZ2S functionality on the jffs.  Two obvious gaps were the 600K Screen utility and the 4.5 Meg Centerim instant messenger client included in IZ2S.

Apparently source code development on the screen utility has ground to a halt lately, so I took a quick peek at the newer tmux screen multiplexor.  Unfortunately my build of tmux segfaults, so that'll have to wait a bit.  Instead, I recompiled the current release of screen to make a smaller executable, and while I was at it I threw in the vertical screen split patch.  As with emacs, I remain unconvinced as to how useful that'll ultimately be on the tiny zipit screen.  But it certainly can't hurt.  Well, actually the new upxed screen program is still almost 200K so I suppose it still hurts a little.
Thats my cheesy ANSI escape wifitest program in the right split, and the retawq browser on the left.

Centerim is huge so that's a no go for the jffs.  I examined quite a few alternatives and most of them seem to pull in openssl, or glib, or some other bloatware that pushes the exe size up over 2 Megs.  Too big for the jffs.  I had really high hopes for bitlbee because it's just a daemon that lets you use your IRC client (think pmirc) as a front end to various instant messanger services.  But it was also huge.  Oh well.

I decided to try the divide and conquer strategy.  Instead of one monster "do it all" program, I started looking for a group of smaller single protocol programs.  Even so, many of these were also bloatware.  So far I've got naim (pictured above) at 250K, bsflite (seen below) at 28K, and a shell script for jabber that (like pmirc) uses sed, grep, and ncat with ssl.  Apparently naim really wants to run with screen. It spews garbage unless I run screen first.  Weird, but ok I guess.  Unfortunately I don't IM myself, so I don't really know if it works.  Actually I think the TOC protocol used by the official naim release has been retired, so I may have to build an experimental version with the OSCAR protocol.  I did however manage to have someone to try bsflite on the zipit and confirmed that it was able to access an AIM account.

IZ2S version 2.04 comes with ncat, but I think it's built without ssl support.  The openssl program itself is about 1 Meg, so I had pretty low expectations when I built an new ncat.  Yep its huge.  But a search led me to snetcat aka.spipe with the embedded matrixssl library. At about 100K snetcat is a strong contender for the jffs.  I just need to redo the jabber script like I did with pmirc.  Then I need to figure out how to test it...

BTW, this post was actually composed on the road using e3em, which I ran on top of the screen utility so I could check the zipit battery level every so often with the EZ2S batlvl command line utility.

Here's the stuff.

bitlbee-iz2s.zip
loadkmap-iz2jffs.zip
screen-im-ssl-iz2jffs.zip

Thursday, January 12, 2012

Small, but Spicy

To save space on the zipit jffs, I made some small (but spicy) SALSA builds of amixer and alsamixer to replace the bloated static full ALSA build of alsactl from IZ2S.  That change freed up 200K on the jffs and eliminated a second or 2 from the ALSA setup part of the boot process.  Apparently the lean and nimble amixer program enables the sound much quicker than the fat old alsactl beastie.  The salsa version of alsamixer forces you scroll off to the right through the controls for quite a few screens before you get to the good stuff, but other than that it works pretty well.  As you can see in this screenshot of me, preparing to turn down the zipit speaker from it's ear blasting default of 100%.

While I was at it, I also compiled a shared lib version of the own-tty program for a 150K savings over the static IZ2S build.   The new one is only 4K.  Nice!

Meanwhile, upon further testing I discovered the pmirc script from last week had quite a few runtime requirements for utility programs only available in the busybox upgrade from the IZ2S.  Oops.  So I set about hacking the script to eliminate some unneeded utilities, and building the others.  After some time relearning sed and regular expressions, I managed to replace tr, cut, and clear with sed and ANSI escape codes.  I built a much smaller 11K shared lib version of nc to replace the big static build from IZ2S.  To make things easier for me I adjusted the help messages to fit the zipit screen, and tossed in a tiny telnet wrapper script.  (I also built a small 7K copy of NetKitty but haven't done anything with it yet.)  I've been searching for a while, and finally found a tiny 5K non-busybox version of the date program on the internet.  I modified it a teeny bit to add /etc/TZ file handling for local timezone formatting.  This lets pmirc timestamp it's log files with the local time.  I still gotta make a setup script with well known city name hints so it's easier to get the right setting into the /mnt/ffs/etc/TZ file.  Here you can see annonymous zipit_user_20645 using the 5K new pmirc utility on the jffs to join the #zipit chat group.  Probably just gonna lurk for a while...
While I was working on the date program I also built a tiny 5K cal program so I can now run the entire wifitest demo dialog script off the stock busybox.  Plus, someday when I get the gmu sqeezed into the jffs I hope to be able to set aside a zipit to be used as a dedicated alarm clock (internet) radio gizmo.

Anyhow, with both rockbox and the IZ2S busybox upgrade installed, I now have nearly 600K free on the jffs for other goodies.  I'd really like to have the zipit16.mp3 file I rescued from the resources.arl file play the "ZZZZipit!" sound on boot up.  But it's 80K and I've only been able to prune mpg123 down to about 230K, so that's unlikely for the time being.  I'm considering upxing the 600K wpa_supplicant program from the stock jffs to see if I can squeeze 100K out of it.  And the loadkeys program is also a heavy load.  Wejp went with the much leaner loadkmap on his zipit userland.  It only loads binary keymap files that must be created with loadkeys on a full linux system, but hey, that's another tradeoff I'm willing to make for 200K or so.

New stuff:
mixer-irc.tar.bz2

Sunday, January 8, 2012

A New Low

The original point of cramming tiny things into the jffs on the zipit was to replace the obsolete (and possibly broken) stock firmware with something useful.  I recently broke out of my "shrinking things" mindset for a while and had a few useful thoughts on this.  It turns out I haven't done much of anything with the tiny /mnt/ffs/Zipit2 script.  I only made that script to fool the init system in the ram disk so it wouldn't initiate the infinite "update of doom" loop.  However, I realized it's actually a nice safe place to add some customization to the boot process because it's the very last bit of script that gets run on boot up.  Currently it just prints a short message and drops into a shell.  But it could just as well launch right into rockbox, or gmu, or check if the SD card has some extra goodies to beef up the system via softlinks.

In order to customize the Zipit2 script without an SD card I felt a simple (but tiny) text editor was required for the jffs.  Now I admit the stock busybox comes with vi, which I can usually remember enough about to get the job done (barely).  But think of the children!  And so I was back to "shrinking things".  To fit on the jffs the programs must be tiny.  At only 14K the e3 editor weighs in at just about the right size.  Plus, depending on the name you run it as, it can emulate the basic commands of wordstar, nedit, pico/nano, vi, or emacs.  Wooo, emacs FTW!  Here's a picture of me using e3 in emacs mode, editing the Zipit2 script to run Rockbox on boot up.
 While I was searching for tiny editors, I just happened to stumble upon the pmirc script (for the busybox ash shell no less) in the puppy linux forums.  I'd already built a 37K version of tinyirc, but at about 2K compressed pmirc was simply too small to pass up.  Plus its got lots of good ideas I can borrow to pimp up the other scripts I've been whipping up.  I modified it a bit to work better with the stock zipit busybox, and tweaked the key input make things a bit easier on the tiny zipit keyboard.  I might have to scour the old software archives to see in there's any similar scripty gems in the floppy linux distributions.  So far most of the potential goodies I've seen are riddled with bashisms, but if I dig deep enough I know I'll find some nuggets.  I'm pretty sure I've got a box of 5 inch floppies somewhere with the ancient simtel archives...

Here's an e3 package with all the softlinks and wrapper scripts.  I also threw in the modified pmirc and Zipit2 script.  You can also use e3 with iz2s, but you'll have to create the softlinks at runtime like in the iz2s busybox.sh script.

iz2jffs-e3.tar.bz2

Monday, January 2, 2012

New Years Resolution

I often find myself booting the zipit off in a dark corner somewhere, so I thought maybe I should let the iz2jffs startup script dimly light the keyboard LEDs, just before the wifi setup, and then turn them off again after. That way I can see the keys well enough to type a password when I need to.  So I made a tiny script called kbledsdim to run the kbbrightness utility from EZ2S.  I also converted kbledson and kbledsoff to similar scripts instead of full executables, so the jffs disk space useage remains about the same.
Now you can't see the keyboard in that picture, but perhaps you can see that I've started making some progress with the ANSI escape sequences.  I polished up the wifi startup scripts with some more color and better default hints.  Combined with the dim keyboard lighting, the wifi config is now bearable.  Maybe I don't need the ANSI escape based dialog boxes after all.
However I also finally got the ANSI escape based dialogs working at a reasonable speed by substituting the echo command for all of the printf calls in the demo script.  Since echo is a builtin function in the busybox sh, it runs about 10 times faster than external printf commands.  This was quite a challenge though since printf has way more formatting capabilities, and the builtin echo command doesn't accept the "no linefeed" switch so moving the cursor gets tricky.  Also the scripts are now tied to the specific busybox sh in the stock zipit initramfs.  Bash and the newer iz2s busybox sh require the -e command for echo to process the escape sequences.  Maybe I can fix that with a test and an alias for echo at the top of the script.  Yeah, maybe someday...

Of course now that I've got the desired speed, I need still to convert the demo into a reasonable set of working dialogs.  So far I've just added a little bit of code to manipulate a highlighted selection bar with the arrow keys, and then launch the currently selected option with the enter button.  I find that handy because even with the keyboard lit up like a Christmas tree it's still hard to find the number buttons, as they're printed in tiny red letters that don't light up.  If anyone wants to play, here's the work in progress on the scripts pictured above.  Some parts still require the iz2s busybox, so be careful with these scripts if you haven't loaded that on your jffs.

iz2jffs-scripts.zip

Turns out stty is crucial to the arrow key parsing and it's not available in the base system, only in the iz2s busybox which I currently have upxed on the jffs of my zipit.  That makes it way too slow to capture the multi-character arrow (and function) key sequences reliably.  I can make it better by only calling stty once, but it's still not an optimal solution, especially since the base jffs has no stty command.  I think I may have to try building a stripped down standalone version of stty...