Kyle Rose

Last modified: 2014-Sep-21

Kyle Rose: Projects

Projects

Seasoning a Cast Iron Skillet

I've written up a how-to on seasoning a cast iron skillet using lard and a grill.

OS X tweaks to play nicely with Linux

I use a MacBook Pro at my new job, but unfortunately Terminal doesn't really play nicely by default with Linux, especially with Emacs. The first step is obviously to activate the "Delete sends ^H" option, but beyond that it took a bit of experimentation with showkey -a to figure out what Terminal should be sending for each keystroke, as well as some magic with KeyRemap4MacBook to add keystrokes that aren't by default recognized by OS X.

First, to get C-/ to send undo, go through the pain of installing KeyRemap4MacBook. Then, you'll want to merge the following into your Library/Application Support/KeyRemap4MacBook:

<?xml version="1.0"?>
<root>
  <item>
    <name>Send Ctrl-Underscore for Ctrl-Slash</name>
    <identifier>private.send_ctrl_underscore_for_ctrl_slash</identifier>
    <autogen>--KeyToKey-- KeyCode::SLASH, ModifierFlag::CONTROL_L,
			  KeyCode::MINUS, ModifierFlag::SHIFT_L
					| ModifierFlag::CONTROL_L
    </autogen>
  </item>
</root>

Next, import my krose-osx-terminal profile into Terminal. (This profile was based on Pro.) This will map the keys to the proper xterm control codes, with Option as meta. Note that, like typical X terminals on Linux, paging in the scrollback buffer of Terminal is now accomplished via <Shift-PgUp> rather than simply <PgUp>.

For Emacs: depending on your preferences and on which version of Emacs you're using, you might want to add some of my keybindings to your .emacs to make things work as expected. I long ago remapped help to M-h because C-h caused problems with Emacs in an xterm from the moment I started using it in 1994.

(global-set-key (read-kbd-macro "C-h") 'delete-backward-char)
(global-set-key (read-kbd-macro "M-k") 'kill-region)
(global-set-key (read-kbd-macro "<M-delete>") 'kill-word)

(global-set-key (read-kbd-macro "M-h") 'help)
(global-set-key (read-kbd-macro "<M-left>") 'backward-sexp)
(global-set-key (read-kbd-macro "<M-right>") 'forward-sexp)

(defun backward-five-lines () "Move up five lines" (interactive) (forward-line -5))
(global-set-key (read-kbd-macro "<C-up>") 'backward-five-lines)

(defun forward-five-lines () "Move down five lines" (interactive) (forward-line 5))
(global-set-key (read-kbd-macro "<C-down>") 'forward-five-lines)

(global-set-key (read-kbd-macro "<M-up>") 'backward-paragraph)
(global-set-key (read-kbd-macro "<M-down>") 'forward-paragraph)

For zsh: I have a few things set up differently from the defaults to more closely mimic Emacs:

bindkey -e
bindkey '^[b' emacs-backward-word
bindkey '^[f' emacs-forward-word
bindkey '^w' kill-region
bindkey '^[w' copy-region-as-kill
bindkey '^[[1;3D' emacs-backward-word
bindkey '^[[1;5D' emacs-backward-word
bindkey '^[[1;3C' emacs-forward-word
bindkey '^[[1;5C' emacs-forward-word

Like Emacs, I use <M-backspace> (or Option-Delete on Mac) to kill the previous word.

imlibsetroot

For several years, I used this great utility written by Jonathan Koren called "imlibsetroot" that allows one to set the root window ("wallpaper") in interesting ways on Xinerama setups; typically, I use it to aspect-scale an image for each Xinerama screen. Well, it turns out there was a long-standing bug with this particular feature that resulted in the tops and bottoms of some images being cropped on landscape displays, and the image bleeding over to the adjoining displays on portrait displays. The fix was very simple, and so I produced a 1.0.1 with this fix.

Recently, Mr. Koren sent along a new version of his utility with additional fixes. I no longer use this utility as I'm happy with what XFCE has to offer, but I preserve the link here for others who are interested.

pcHDTV bttv megablocks

I ran into a problem in which I was getting frequent blockiness in the image and frequent audio cut-outs in MPEG from the HD-2000 while also recording from PVR's or HD-3000's in the same machine. This was due at least in part to buffer overruns in the relatively short (256K) buffer allowed by the driver distributed by the pcHDTV folks.

In response to this, I did two things:

The first is easy; search for "pci latency" and "setpci" and you'll find plenty of instructions on how to tweak PCI latency.

The second is more interesting because it involves a gross hack to get around limitations in the Bt878 RISC engine. I wanted to try a longer buffer in the bttv driver, so I grabbed the data sheet from Conexant's site and had a look. Unfortunately, they don't make it easy: it appears that 256K is as long a buffer as one can determinstically support with the given microcode, because there are only 4 bits for the status field in communication from the RISC processor to the interrupt handler, and each block is limited to 16384 bytes due to other field limitations in the audio DMA status words. (As pfile noted in a posting to me, the HD-2000 uses the audio DMA system in the Bt878 to transfer digital video to main memory.)

Well, it turns out one can *kind* of support larger buffers by estimating where the RISC processor is currently writing: you can do this by reading the RISC processor's program counter. I wrote a first pass at a patch (above) that does just this: buffers above 256K will be divided into "megablocks" of 16 blocks of 16K each. At a high level, the irq handler will attempt to make a guess as to the current megablock based on the PC, and adjust dma_block to be that megablock * 16 + the block reported in the status field.

Unfortunately, there is another more critical problem: the relatively short hardware FIFO (O(1KB)) in the Bt878, due to the HD-2000 using the Bt878's audio DMA to transfer digital video to RAM. Some drivers may have top halves (synchronous interrupt handlers) that consume too much time, effectively resulting in the FIFO overrunning. If you are using the megablocks driver and still are losing data, I recommend first trying a newer kernel; and if that doesn't work, try eliminating drivers and devices until you see the problem go away, which might help pinpoint the driver with the problematic top half.

It would be helpful to know if the megablocks driver helps others seeing the same symptoms I encountered. Email me either way.