Blog

Getting the Damn STB TV Tuner Working in RedHat 9

My computer came with a PCI TV tuner card from STB. The manufacturer provided drivers for Windows 98, but of course, shortly thereafter, the manufacturer disappeared from the face of the earth. Obtaining a suitable driver for Windows XP was nearly impossible until the recent development of open-source WDM drivers for all BT848-based tuner cards. However, although getting the card to work under Linux was a bit tricky, it was not at all impossible. This is a brief log of the steps I took to get the damn thing to work under RedHat 9.

At first I tried to use xawtv just to see if I could get a picture. And in fact, it actually showed Channel 3, which got me excited. However, there was no sound, and I couldn’t change the channel. I knew that the configuration of bttv was somehow wrong. After poring over the BTTV HOWTO document, I came up with the following lines to add to /etc/modules.conf:

# TV settings
alias char-major-81 bttv
pre-install bttv /sbin/modprobe -k tuner; /sbin/modprobe -k msp3400
options bttv radio=1 card=3
options tuner type=2

The parameters specified above correctly identify the STB TV PCI card, and even enable FM radio functionality, which the card supports.

After a reboot, xawtv worked wonderfully. However, there was soon a new problem: I installed an updated accelerated video driver from NVIDIA, which made xawtv crash with a segmentation fault. After searching the web for answers, I found the following solution: simply start xawtv with the command line xawtv -device /dev/video0. That’s it!

One more minor issue was getting the program called tvtime to work. This program is vastly superior to xawtv, but it had a slight problem where it automatically turned up the tuner volume all the way, and let the user control the volume through the mixer. This wasn’t good because the STB card clips the audio if it’s above 50% volume, so it sounded really distorted and rectified. All I needed to do to fix this was find the line of code where tvtime sets the tuner volume, and change the default number. The number that it was setting the volume to was 60000 (presumably the maximum is 65535). So I changed it to 32000 and recompiled. It now runs marvelously.
(Update 10-24-04: I submitted a bug report to tvtime, and the author added a preference to control the audio gain on the tuner card itself. Thanks!)

Getting the Damn Aureal Sound Card Working in RedHat 9

This is a brief how-to on getting my Aureal-based sound card (Turtle Beach Montego) to work under RedHat Linux 9. I’m sure I’m not the only one who owns such a card, so this might be useful for someone in the future.

RedHat did not recognize my sound card upon installation, so naturally I thought it wasn’t supported. This was until I stumbled upon a driver at SourceForge that purported to provide support for Aureal-based cards.

I downloaded the project’s distribution files, and tried to compile it… but the compiler couldn’t get past 10 lines of code before it choked. The source files were obviously written for an earlier version of the kernel.

However, all hope was not lost. I downloaded a CVS snapshot of the project (instead of the distribution), and tried to compile that. Miraculously, that only gave one or two errors. Then, all I did was comment out the two offending lines of code, and it compiled successfully. The output was a kernel module called au8830.o.

Installing it was a different issue altogether.

This driver uses a combination of open- and closed-source code. The closed-source portion that came with the driver was compiled with a much earlier version of gcc. Because of this, insmod would not allow me to load the module. It gave an error that the module needs to be compiled with gcc version greater than 3. Fortunately, insmod can be forced to load the module anyway by issuing the -f option.

With the -f option, insmod tried to load it, but reported a few unresolved externals. I realized that I needed to load the soundcore module first. After loading soundcore, I tried loading my module again, and what do you know? It loaded successfully!

/dev/dsp was working like a charm, but sound in KDE (aRts?) wasn’t loading properly. I went into the KDE Control Center, into the Sound Server tab, and changed the server startup setting from “autodetect” to “Threaded OSS.” That seemed to do the trick, and it’s been working fine ever since.

To automate the process of loading the module at boot time, I edited my /etc/modules.conf file and added the following lines:

# Sound configuration
post-install sound-slot-0 /bin/aumix-minimal -f /etc/.aumixrc -L >/dev/null 2>&1 || :
pre-remove sound-slot-0 /bin/aumix-minimal -f /etc/.aumixrc -S >/dev/null 2>&1 || :
pre-install au8830 /sbin/modprobe soundcore; /sbin/insmod -f au8830
alias char-major-14 sound
alias sound-slot-0 sound
alias sound au8830
alias midi au8830

This will ensure that the au8830 module will be loaded after the soundcore module, and that the au8830 module will be force-loaded with the -f option.

Viewing Various Image Formats with VB 6

Here’s some ancient code of mine written in Visual Basic 6 to view different image formats not natively supported (at the time) by VB. Enjoy.

  • PNG Viewer — An ambitious effort to support a major portion of the PNG (Portable Network Graphics) specification using nothing but VB6 code. This program will display most PNG files (interlaced, alpha channels, etc). It may have some trouble with the most obscure instances of PNG formats, but otherwise it’s flawless. Sadly, I’ve stopped development on it a long time ago (what with the existence of libpng and all…) but it could still be useful for some minor applications.
  • JPG Viewer — A JPEG viewer written entirely in VB6.
  • TGA Viewer — This offers pretty complete support for the TGA (Truevision Targa) format.
  • PCX Viewer — Full support for the ZSoft PCX format. Apparently this format is still actually used in some commercial applications (namely Lotus Notes).
  • RAS Viewer — Full support for the Sun Rasterfile format.
  • PPM Viewer — Supports the Portable Pixel Map format (ASCII and Binary). PPM files are usually true-color pictures, unlike the PGM and PBM formats below.
  • PGM Viewer — Supports the Portable Grey (Gray?) Map format (ASCII and Binary).
  • PBM Viewer — Supports the Portable Bit Map format (ASCII and Binary).
  • FLI Animation Viewer — This simple program actually plays a FLI animation by dumping it frame by frame. It doesn’t really support variable timing, and it doesn’t have controls for playback. It just dumps.
  • PSD Viewer — Moderate support for Photoshop PSD files.
  • SGI Viewer — Supports the SGI formats .RGB and .BW.
  • CUT Viewer — Supports the Dr. Halo CUT format.
  • BSV Viewer — This is a viewer for images that were saved using QBasic’s BSAVE command. Only BSAVEs done in SCREEN 13 are supported.

Assembler and Linker for SIC/XE

The SIC/XE architecture is the brainchild of Leland L. Beck, who is the author of System Software: An Introduction to Systems Programming [1]. This book is used in many university courses that deal with language processors. The SIC (Simplified Instructional Computer) architecture itself is completely made-up and has never been implemented for any practical application. All of its functions are entirely conceptual and will never serve a purpose in the real world. So, of course, in my Language Processors class in college, one of the assignments was to write an assembler for the SIC/XE instruction set, and a linker/loader for compiled SIC/XE object code. Let’s just say that, by the end of this assignment, I really started to hate the name “SIC/XE,” and so will you.

To begin with, here is the assembler for the SIC/XE assembly language: download source code and executable. There is no documentation included, since you should already know what you’re doing if you’re actually downloading this. However, here are some quick facts about the assembler.

  • The assembler is for SIC/XE only, not SIC
  • It does support literals
  • It does not support macros
  • It does not support external references or definitions
  • It does create relocatable programs with Modification records

And now, here is the linker/loader for programs compiled with the assembler: download source code and executable. There is also no documentation for the linker/loader, but here are some quick facts:

  • The linker is only for SIC/XE programs, not SIC
  • It supports external references
  • It only supports modification records with import reference numbers, e.g. M00002405+02
  • It outputs a file called outfile, which is simply a dump of the SIC/XE’s memory as it would appear if the program were completely loaded. The file also includes a dump of all external references and their addresses.

This code is freeware, but please give me credit where appropriate if you’re actually going to use it. These programs come as-is, and with no warranty whatsoever.

Reference:

1. Beck, Leland L. System Software: An Introduction to Systems Programming, 3rd ed. 1997, Addison Wesley Longman, Inc.

Top-down Parser with Backtracking in C++

Another assignment in my Foundations of Computing class in college was to create a top-down parser that also supports backtracking. My implementation works for any arbitrary context-free grammar. Here’s the program with source code.

The program accepts any arbitrary context-free grammar as an input file, as well as a file that contains the input string to be parsed. When the program starts, it looks for a file called grammar.txt in the program’s directory. The grammar should have the following form:
<L> -> <L>;<A>|<A>
<A> -> <I>=<E>

<E> -> <E>-<T> | <E>+<T> | <T>
<T> -> <T>/<F> | <T>*<F> | <F>
<F> -> <P>^<F> | <P>
<P> -> (<E>) | <I>
<I> -> w|x|y|z

The example grammar above defines a language where any mathematical expression can be formed with the variables w, x, y, z, and the operators +, -, *, /, ^, and =. Multiple expressions can also be separated by a semicolon.

Symbols enclosed in brackets “<…>” are non-terminals. The arrow symbol “->” separates the two sides of the given rewrite rule (production). The “or” symbol “|” is used to separate different choices for a single rewrite rule. Any other symbol is a terminal. The special symbol “<epsilon>” represents a null or empty terminal symbol (sometimes referred to as lambda). Comments can be written in the grammar file by placing a # symbol at the beginning of the line.

Notice that the parser supports left-recursion in the grammar. The program will automatically eliminate all left-recursion from the grammar before parsing any data. After eliminating left-recursion, the program will output a file called grammar_after_left_recursion.txt (for debugging purposes), then another file called grammar_after_unit.txt (after eliminating unit productions), and a file called grammar_after_epsilon.txt (after eliminating any empty productions).

After loading and massaging the grammar, the program will ask you to type in the string to be parsed. Alternatively, you can create a file that contains the string, and pass it as a command line parameter to the program. The program will then state whether or not the data was parsed successfully. If the parsing was successful, the program will display a graphical window with a tree that depicts the parsing performed by the program.